This is a system taken from BeyondTechnical Analysis by Tushar Chande.
The definition of an extraordinary opportunity as used here is simple. Use a 50-day SMA and plot a 3-percent trading band around it. Then a 7-day SMA must cross outside the upper or lower band to com-plete the identification of extraordinary markets. Thus, if the 7-day SMA. crosses above the upper 3-percent band, an upside extraordinary situation is declared. A converse definition is applicable for bearish markets. The best scenario is that the market follows through vigorously in the direction of the established trend. The worst scenario is that the market teases you for a day or two before returning into a congestion zone. Then use an initial stop to close out the trade.
I woulld like to put the system in Amibroker AFL. I tried but the Buy & Sell signals were not correct. Please help me to get the buy and sell signals correctly. The AFL I tried is as under,
_SECTION_BEGIN("Price");
SetChartOptions(0,chartShowArrows|chartShowDates);
_N(Title = StrFormat("{{NAME}} - {{INTERVAL}} {{DATE}} Open %g, Hi %g, Lo %g, Close %g (%.1f%%) {{VALUES}}", O, H, L, C, SelectedValue( ROC( C, 1 ) ) ));
Plot( C, "Close", ParamColor("Color", colorBlack ), styleNoTitle | ParamStyle("Style") | GetPriceStyle() );
_SECTION_END();
_SECTION_BEGIN("MA");
P = ParamField("Price field",-1);
Periods = Param("Periods", 50);
Plot( MA( P, 50 ), _DEFAULT_NAME(), ParamColor( "Color", colorCycle ), ParamStyle("Style") );
_SECTION_END();
_SECTION_BEGIN("Percent Bands");
P = ParamField("Price field",-1);
Periods = Param("Periods", 15, 2, 100, 1 );
Width = Param("Width%", 2, 0, 10, 0.05 );
Color = ParamColor("Color", colorCycle );
Style = ParamStyle("Style");
CenterLine = MA( P, Periods );
Plot( (1 + Width * 0.01) * CenterLine, "%EnvTop" + _PARAM_VALUES(), Color, Style );
Plot( (1 - Width * 0.01) * CenterLine, "%EnvBot" + _PARAM_VALUES(), Color, Style );
_SECTION_END();
_SECTION_BEGIN("MA1");
P = ParamField("Price field",-1);
Periods = Param("Periods", 7);
Plot( MA( P, 7 ), _DEFAULT_NAME(), ParamColor( "Color", colorCycle ), ParamStyle("Style") );
_SECTION_END();
_SECTION_BEGIN("MA2");
P = ParamField("Price field",-1);
Periods = Param("Periods", 65);
Plot( MA( P, 65 ), _DEFAULT_NAME(), ParamColor( "Color", colorCycle ), ParamStyle("Style") );
_SECTION_END();
Buy =BarsSince(Cross(MA(Close,7),((1 + width * 3)*50))) <=1;
Sell =BarsSince(Cross(MA(Close,7),((1 - Width *3)*50))) <=1;
Please help and test the system afl.
Khartik's AFL for the same
_SECTION_BEGIN("Price");
SetChartOptions(0,chartShowArrows|chartShowDates);
mYCOLOR=colorRed;
P = ParamField("Price field",-1);
Periods = Param("Periods", 50, 2, 100, 1 );
Width = Param("Width%", 3, 0, 10, 0.05 );
MaPeriods = Param("MaPeriods", 7, 2, 14, 1 );
CL = MA( P, Periods );
Plot( CL, "MA" + _PARAM_VALUES(), colorRed, styleLine );
ET=(1 + Width * 0.01) * Cl;
EB=(1 - Width * 0.01) * Cl;
S=MA(C,MAperiods);
Plot(ET , "%EnvTop" + _PARAM_VALUES(), colorBlue, styleLine );
Plot( EB, "%EnvBot" + _PARAM_VALUES(), colorBlue, styleLine );
Plot( S, "MA" + _PARAM_VALUES(), colorOrange, styleLine );
Buy=BarsSince( Cross(s,ET))<20 AND Cross(C,HHV(Ref(H,-1),10))AND C>ET;
Sell=BarsSince( Cross (EB,s))<5 AND Cross(C,LLV(Ref(L,-1),10));
MYcolor = IIf( s>ET ,colorGreen, colorRed);
PlotOHLC( Open, High, Low, Close, "", Mycolor, styleBar );
shape = Buy * shapeUpArrow + Sell * shapeDownArrow;
PlotShapes( shape, IIf( Buy, colorGreen, colorRed ),0, IIf( Buy, Low, High ) );
GraphXSpace = 5;
dist = 1.5*ATR(10);
for( i = 0; i < BarCount; i++ )
{
if( Buy
) PlotText( "Buy\n@" + C[ i ], i, L[ i ]-dist, colorGreen );
if( Sell ) PlotText( "Sell\n@" + C[ i ], i, H[ i ]+dist, colorRed);
}
_SECTION_END();
Regards
Ken