I have developed this simple AFL to trade with nifty future and here is the rule first:
=========================================================
=> TimeFrame: hourly
=> Bullish Trend: if candle is above Yellow line
=> Bearish Trend: if candle is below Yellow line
=> Blue Line is for entry and exit
===> If trend is bullish and price goes above blue line then buy
and exit from buy after price goes below blue line
*** dont take short position in bullish trend
===> If trend is bearish and price goes below blue line then sell
and exit from sell after price goes above blue line
*** dont take long position in bearish trend
and here is the AFL :
=======================================================
_SECTION_BEGIN("Price");
SetChartOptions(0,chartShowArrows|chartShowDates);
SetChartBkColor(colorBlack);
_N(Title = StrFormat("{{NAME}} - {{INTERVAL}} {{DATE}} Open %g, Hi %g, Lo %g, Close %g (%.1f%%) Vol " +WriteVal( V, 1.0 ) +" {{VALUES}}", O, H, L, C, SelectedValue( ROC( C, 1 )) ));
Plot( C, "Close", ParamColor("Color", colorLightGrey ), styleNoTitle | ParamStyle("Style") | GetPriceStyle() );
_SECTION_END();
res=HHV(H,7);
sup=LLV(L,7);
tsl=IIf(ValueWhen(IIf(C>Ref(res,-1),1,IIf(C<Ref(sup,-1),-1,0))!=0,IIf(C>Ref(res,-1),1,IIf(C<Ref(sup,-1),-1,0)),1)==1,sup,res);
Plot(tsl, _DEFAULT_NAME(), colorBlue, styleStaircase);
Buy = Cross(C,res) ;
Sell = Cross(sup,C) ;
_SECTION_END();
res=HHV(H,17);
sup=LLV(L,17);
tsl=IIf(ValueWhen(IIf(C>Ref(res,-1),1,IIf(C<Ref(sup,-1),-1,0))!=0,IIf(C>Ref(res,-1),1,IIf(C<Ref(sup,-1),-1,0)),1)==1,sup,res);
Plot(tsl, _DEFAULT_NAME(), colorYellow, styleStaircase);
Buy = Cross(C,res) ;
Sell = Cross(sup,C) ;
_SECTION_END();
=========================================================
This is for study purpose only,
Seniors and others are requested to comment
=========================================================
=> TimeFrame: hourly
=> Bullish Trend: if candle is above Yellow line
=> Bearish Trend: if candle is below Yellow line
=> Blue Line is for entry and exit
===> If trend is bullish and price goes above blue line then buy
and exit from buy after price goes below blue line
*** dont take short position in bullish trend
===> If trend is bearish and price goes below blue line then sell
and exit from sell after price goes above blue line
*** dont take long position in bearish trend
and here is the AFL :
=======================================================
_SECTION_BEGIN("Price");
SetChartOptions(0,chartShowArrows|chartShowDates);
SetChartBkColor(colorBlack);
_N(Title = StrFormat("{{NAME}} - {{INTERVAL}} {{DATE}} Open %g, Hi %g, Lo %g, Close %g (%.1f%%) Vol " +WriteVal( V, 1.0 ) +" {{VALUES}}", O, H, L, C, SelectedValue( ROC( C, 1 )) ));
Plot( C, "Close", ParamColor("Color", colorLightGrey ), styleNoTitle | ParamStyle("Style") | GetPriceStyle() );
_SECTION_END();
res=HHV(H,7);
sup=LLV(L,7);
tsl=IIf(ValueWhen(IIf(C>Ref(res,-1),1,IIf(C<Ref(sup,-1),-1,0))!=0,IIf(C>Ref(res,-1),1,IIf(C<Ref(sup,-1),-1,0)),1)==1,sup,res);
Plot(tsl, _DEFAULT_NAME(), colorBlue, styleStaircase);
Buy = Cross(C,res) ;
Sell = Cross(sup,C) ;
_SECTION_END();
res=HHV(H,17);
sup=LLV(L,17);
tsl=IIf(ValueWhen(IIf(C>Ref(res,-1),1,IIf(C<Ref(sup,-1),-1,0))!=0,IIf(C>Ref(res,-1),1,IIf(C<Ref(sup,-1),-1,0)),1)==1,sup,res);
Plot(tsl, _DEFAULT_NAME(), colorYellow, styleStaircase);
Buy = Cross(C,res) ;
Sell = Cross(sup,C) ;
_SECTION_END();
=========================================================
This is for study purpose only,
Seniors and others are requested to comment