Reply To: รบกวนขอสูตรทั้งหมดสำหรับ Amibroker ครับ

#24359
dreamscat
Keymaster

CDC Action Zone Basic.afl

///////////////////////////
// CDC Action ZOne Basic //
// 21st April 2017 //
///////////////////////////

// Basic Parameter Setup //

PlotStyle = ParamToggle(“Plot Style”,”Price Chart|MACD”,0);
PlotLine = ParamList(“Plot MA Lines”,”Plot Lines|Plot Bullish and Bearish Trend|Plot Lines and Trend|Do not Plot”,0);
Price = ParamField(“Price”,3);

FastPrd = Param(“Fast MA Period”,12);
SlowPrd = Param(“Slow MA Period”,26);

// Un-comment these to enable optimization //
// Do not forget to set your own lower and upper limits //
// Do not forget to comment the FastPrd and SlowPrd lines above //
/*
SlowPrd = Optimize(“Slow MA Period”,26,12,125,2);
FastPrd = round(Optimize(“Fast MA Period”,0.1,0.1,0.6,0.05)*SlowPrd);
*/

// Main functions //
Fast = EMA(Price,FastPrd);
Slow = EMA(Price,SlowPrd);

Bullish = Fast > Slow;
Bearish = Fast < Slow;

// Bar Colors //
Green = Bullish AND Price > Fast;
Yellow = Bullish AND Price < Fast AND Price > Slow;
Brown = Bullish AND Price < Slow;

Red = Bearish AND Price < Fast;
Aqua = Bearish AND Price > Fast AND Price < Slow;
Blue = Bearish AND Price > Slow;

BarColor = IIf(Green,colorGreen,IIf(Yellow,colorYellow,IIf(Brown,colorOrange,IIf(Red,colorRed,IIf(Aqua,colorAqua,IIf(Blue,colorBlue,colorDefault))))));

// Buy & Sell //
// Amibroker recognize these functions and use them in system tests and scans //
Buy = Bullish AND Ref(Bearish,-1);
Sell = Bearish AND Ref(Bullish,-1);

// Explorer //
// A more detailed report //

Filter = 1; // Basically means we don’t filter anything

// This part here is also mainly cosmetics //
// The codes are mostly about how the exploration should be displayed //

pctchange = ((C-Ref(C,-1))/C)*100;
buyp = ValueWhen(Ref(Buy,-1),O,1);
sellp = ValueWhen(Ref(Sell,-1),O,1);

longpct = IIf(BarsSince(Buy) < BarsSince(Sell),(C-buyp)/buyp,Null);
longcolor = iif (SelectedValue(longpct) > 0,IIf(SelectedValue(longpct) < 1, SelectedValue(longpct), 1),IIf(SelectedValue(longpct) > -1, abs(SelectedValue(longpct)) , 1));

shortpct = IIf(BarsSince(Sell) < BarsSince(Buy),(buyp-C)/buyp,Null);
shortcolor = iif (SelectedValue(shortpct) > 0,IIf(SelectedValue(shortpct) < 1, SelectedValue(shortpct), 1),IIf(SelectedValue(shortpct) > -1, abs(SelectedValue(shortpct)) , 1));

colorGV = ColorBlend(GetChartBkColor(),colorGreen,longcolor);
colorRV = ColorBlend(GetChartBkColor(),colorRed,shortcolor);

AddColumn(C,”Last Price”,1.4);
AddColumn(pctchange,”% Change”,1.2,IIf(pctchange>0,colorGreen,colorRed));
AddColumn(Buy,”Buy Order”,1.0,colorDefault,IIf(Buy==1,colorLime,colorDefault));
AddColumn(Sell,”Sell Order”,1.0,colorDefault,IIf(Sell==1,colorRed,colorDefault));

AddColumn(IIf(BarsSince(Buy) < BarsSince(Sell),BarsSince(Buy),Null),”Buy Since (Bars)”,1.0);
AddColumn(longpct*100,”Long %”,1.2,colorDefault,IIf(SelectedValue(longpct) > 0,ColorBlend(colorDefault,colorGreen,longcolor),ColorBlend(colorDefault,colorRed,longcolor)));

AddColumn(IIf(BarsSince(Sell) < BarsSince(Buy),BarsSince(Sell),Null),”Sell Since (Bars)”,1.0);
AddColumn(shortpct*100,”Short %”,1.2,colorDefault,IIf(SelectedValue(shortpct) > 0,ColorBlend(colorDefault,colorGreen,shortcolor),ColorBlend(colorDefault,colorRed,shortcolor)));

// Plots //
// This part does not have to be complicated at all //
// What you see here is mostly for cosmetic purpose //

if(PlotStyle == 0)
{
if(PlotLine == “Plot Lines”)
{
Plot(Fast,”Fast MA”,colorRed,styleLine);
Plot(Slow,”Slow MA”,colorBlue,styleLine | styleThick);
}
if(PlotLine == “Plot Bullish and Bearish Trend”)
{
GraphZOrder = 1;
PlotOHLC(Fast,Fast,Slow,Slow,”Action Zone Trend Cloud”,IIf(Bullish,ColorBlend(colorGreen,GetChartBkColor()),ColorBlend(colorRed,GetChartBkColor())),styleCloud);
}
if(PlotLine == “Plot Lines and Trend”)
{
GraphZOrder = 1;
PlotOHLC(Fast,Fast,Slow,Slow,”Action Zone Trend Cloud”,IIf(Bullish,ColorBlend(colorGreen,GetChartBkColor()),ColorBlend(colorRed,GetChartBkColor())),styleCloud);
Plot(Fast,”Fast MA”,colorRed,styleLine);
Plot(Slow,”Slow MA”,colorBlue,styleLine | styleThick);
}
if(PlotLine == “Do not Plot”)
{
}
Plot(Close,”Price”,BarColor,GetPriceStyle());
}
else
{
macdline = Fast – Slow;
signalline = MA(macdline,9);
Plot(signalline,”Signal Line”,colorBlack,styleLine | styleThick);
Plot(macdline,”Action Zone Basic | MACD”,BarColor,styleArea);

}

// Modify Jan 2018
Maxpos = 50;
SetPositionSize(100/Maxpos,spsPercentOfEquity); // 1 % of Equity
//