My Nifty Trading AFL

bjj9126

Active Member
#1
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

:cool:
 
#2
this is really great ... i have seen that there are very few stop losses... !! and u can be in trend for a longer period of time .. similar afl i have seen software where they are using some 7 period and 34 period swing trading to decide the trend line...
 

XRAY27

Well-Known Member
#3
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

:cool:
Good afl you have shared and it is performing fine but stoploss are little bit on higher side
 
#6
WITH BUY SELL SIGNAL.
CONSIDER BLUE LINE AS STOP LOSS





_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();

_SECTION_END();
y=Param("YELLOW",17,1,100,1);
res=HHV(H,y);
sup=LLV(L,y);
tsl3=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(tsl3, _DEFAULT_NAME(), colorYellow, styleStaircase);
_SECTION_END();



b=Param("BLUE",7,1,100,1);//10;
res=HHV(H,b);
sup=LLV(L,b);
avd=IIf(C>Ref(res,-1),1,IIf(C<Ref(sup,-1),-1,0));avn=ValueWhen(avd!=0,avd,1);s5d=IIf(avn==1,sup,res);

exitlong = Cross(s5d, C);
exitshort = Cross(C, s5d);
Plot(s5d, _DEFAULT_NAME(), colorBlue, styleStaircase);

Buy = exitshort;
Sell = exitlong;
Short = Sell;
Cover = Buy;
Buy = ExRem(Buy,Sell);
Sell = ExRem(Sell,Buy);
Short = ExRem(Short, Cover);
Cover = ExRem(Cover, Short);

PlotShapes(shapeDownArrow*exitlong, colorRed, 0, H, -12) ;
PlotShapes(shapeUpArrow*exitshort,colorGreen , 0, L, -12) ;


_SECTION_END();
 

KelvinHand

Well-Known Member
#7
this is really great ... i have seen that there are very few stop losses... !! and u can be in trend for a longer period of time .. similar afl i have seen software where they are using some 7 period and 34 period swing trading to decide the trend line...

Does it repaint ?
How to prove it is above 95% accuracy ?
 
Last edited:

Similar threads