Want to understand the strategy behind this afl

Hello everyone. I found this afl on the internet and don’t know who is the author of this. I have done paper trading with this AFL. In 5 minute time frame its a good profit giving strategy. though it’s a repainting in nature and if I only follow the Buy or Sell signal when the lower band is Green or Red then it will make the profit otherwise it hit the stop loss. I cant understand the logic or strategy in this AFL. Please help me to understand it. And I want to do some modification in this afl like a bye signal generate only the lower band is green otherwise no bye call generate. and also same about sell signal.

TimeFrameSet(inDaily);
DayHigh = LastValue(H);
DayLow = LastValue(L);
… snip … improperly formatted code follows…truncated

You may want to put your code in between the ``` tag for better view:

TimeFrameSet(inDaily);
 DayHigh = LastValue(H);
 DayLow = LastValue(L);
 TimeFrameRestore();
 Title = Date() + “, Op=” + Open + “, Hi=” + High + “, Lo=” + Low + “, LTP=” + Close + “, Change= " + SelectedValue( ROC( C, 1 ) ) + “%” + “\n Todays High=" + DayHigh + ", Todays Low=” + DayLow + " © PRIME SYSTEM” ;
prev=AMA2(C,1,0);
 d=IIf(C>Ref(Max(Max(H,Ref(H,-20)),Max(Ref(H,-10),Ref(H,-15))),-1),Min(Min(L,Ref(L,-20)),Min(Ref(L,-10),Ref(L,-15))),
 IIf(C<Ref(Min(Min(L,Ref(L,-20)),Min(Ref(L,-10),Ref(L,-15))),-1),Max(Max(H,Ref(H,-20)),Max(Ref(H,-10),Ref(H,-15))),PREV));
 a=Cross(Close,d);
 b=Cross(d,Close);
 state=IIf(BarsSince(a)<BarsSince(b),1,0);
 s=state>Ref(state,-1);
 ss=state<Ref(state,-1);
 sss=state==Ref(state,-1);
 col=IIf(state == 1 ,51,IIf(state ==0,4,1));
 Plot(C,"",Col,64);
 Buy = s;
 Sell = ss;
 shape = Buy * shapeUpArrow + Sell * shapeDownArrow;
 PlotShapes(shape, IIf(Buy,colorGreen,colorRed), 0, IIf(Buy,Low,High));
 PlotShapes(IIf(Buy, shapeSquare, shapeNone),colorGreen, 0, L, Offset=-10);
 PlotShapes(IIf(Buy, shapeSquare, shapeNone),colorLime, 0,L, Offset=-20);
 PlotShapes(IIf(Buy, shapeUpArrow, shapeNone),colorWhite, 0,L, Offset=-15);
 PlotShapes(IIf(Sell, shapeSquare, shapeNone),colorRed, 0, H, Offset=20);
 PlotShapes(IIf(Sell, shapeSquare, shapeNone),colorOrange, 0,H, Offset=30);
 PlotShapes(IIf(Sell, shapeDownArrow, shapeNone),colorWhite, 0,H, Offset=-25);
 WriteIf(s,“EXIT all Short positions\nif trading long positions, enter long Now-\nOR at the market price on tomorrow’s Open with stop=”+EncodeColor(4)+WriteVal(L+.75ATR(5),1.4)+" ,","");
 WriteIf(ss,“exit all long positions today with a Market On Close (MOC) order\nOR at the market price on tomorrow’s Open with stop=”+EncodeColor(4)+WriteVal(Ref(H+.75ATR(5), -1),1.4)+",","");
 WriteIf( sss ,“No trading signals today.”,"") ;
dist = 0.8ATR(10);
 dist1 = 2ATR(10);
 for( i = 0; i < BarCount; i++ )
 {
 if( Buy[i] )
 {
 PlotText( “\nBuy:” + L[ i ] + "\nT= " + (L[i]*1.005) + "\nSL= " + (L[i]*0.9975), i, L[ i ]-dist[i], colorGreen, colorWhite );
 }
 if( Sell[i] )
 {
 PlotText( “Sell:” + H[ i ] + "\nT= " + (H[i]*0.995) + "\nSL= " + (H[i]1.0025), i, H[ i ]+dist1[i], colorRed, colorWhite );
 }
 }
 Filter = s OR sss OR sss ;
 AddColumn(C,“close”,1.2);
 AddColumn( IIf( s, 66,1 ), “buy”, formatChar, 1, bkcolor =IIf (s,colorYellow, colorPink ));
 AddColumn( IIf( Ss, 83,1 ), “sell”, formatChar, 1, bkcolor =IIf (Ss,colorPink, colorWhite ));
 AddColumn( IIf( sss, 87,1 ), “wait”, formatChar, 1, bkcolor =IIf (sss,colorYellow, colorRed ));
 _SECTION_BEGIN(“swing1”);
no=20;
 res=HHV(H,no);
 sup=LLV(L,no);
 avd=IIf(C>Ref(res,-1),1,IIf(C<Ref(sup,-1),-1,0));
 avn=ValueWhen(avd!=0,avd,1);
 supres=IIf(avn==1,sup,res);
 a=Cross(C,supres);
 b=Cross(supres,C);
 style = a * styleStaircase + b * styleStaircase;
 PlotShapes(a,style, IIf(a,colorGreen,colorRed), 0, IIf(a,Low,High));
 Plot(supres,“Swing”,colorYellow,styleStaircase);
 _SECTION_END();
 _SECTION_BEGIN(“trend”);
uptrend=PDI(20)>MDI(10)AND Signal(29)<MACD(13);
 downtrend=MDI(10)>PDI(20)AND Signal(29)>MACD(13);
 Plot( 2, / defines the height of the ribbon in percent of pane width /“ribbon”,
IIf( uptrend, colorGreen, IIf( downtrend, colorRed, 0 )), / choose color */
 styleOwnScale|styleArea|styleNoLabel, -0.5, 100 );
 _SECTION_END();
 Buy = s AND a AND uptrend ;
 Short = ss AND b AND downtrend ;
 Sell = ss AND b AND downtrend ;
 Cover = s AND a AND uptrend ;
 Buy=ExRem(Buy,Sell);
 Sell=ExRem(Sell,Buy);
 Cover=ExRem(Cover,Short);
 Short=ExRem(Short,Cover);
 Filter=Buy OR Sell;
 Filter= Cover OR Short;
 AddColumn( Buy, “Buy”, 1);
 AddColumn(Sell, “Sell”, 1);
 AddColumn(Close,“Close”,1.2);
 AddColumn(Volume,“Volume”,1.0);
 // Plot the Buy and Sell arrows.
 shape = Buy * shapeUpArrow + Sell * shapeDownArrow;
 PlotShapes(IIf(Buy, shapeSquare, shapeNone),colorGreen, 0, L, Offset=-10);
 PlotShapes(IIf(Buy, shapeSquare, shapeNone),colorLime, 0,L, Offset=-20);
 PlotShapes(IIf(Buy, shapeUpArrow, shapeNone),colorWhite, 0,L, Offset=-15);
 PlotShapes(IIf(Sell, shapeSquare, shapeNone),colorRed, 0, H, Offset=20);
 PlotShapes(IIf(Sell, shapeSquare, shapeNone),colorOrange, 0,H, Offset=30);
 PlotShapes(IIf(Sell, shapeDownArrow, shapeNone),colorWhite, 0,H, Offset=-25);
 //plot volume graph
 // set background gradient colours
 SetChartBkGradientFill( ParamColor(“BgTop”, ColorRGB( 172,172,172 )),ParamColor(“BgBottom”, ColorRGB( 102,136,187 )),ParamColor(“titleblock”,ColorRGB( 255,255,255 )));
 GraphXSpace = 5;
2 Likes

Thank you. How do I edit it.?

@suvoge read this carefully, How to use this site

  1. And your question mentions, you do not know what the logic of the strategy is?
  2. You do not know who the author of the code is?
  3. You are not familiar enough with AmiBroker to understand the code?

You want to trade this strategy, with real money.

Seriously?

If I may offer some advice, please master the first three points before trading this.

2 Likes

I am always surprised to see people who took time and effort to put their cat’s photo into their profile but failed to read forum rules.

4 Likes

I fully agree with @portfoliobuilder!

In any case, if you are really interested in learning more about this strategy (before committing any real money) you should spend more time researching and reading both this forum and the one/ones where you found this formula (that, as pasted, by the way, does not work due to some syntax errors - learn how to fix them is a must).

For instance, with a simple search in Google l found that the swing part (you know what is a swing trading strategy?) is basically known as KPL Swing (a breakout strategy) originally posted by its author Kamalesh Langote here or here (with a better-documented header).

From there, many other authors (mainly in India) posted variation over variation (usually adding - sometimes just doing copy&paste - more indications, oscillators, rules) to make it more complex…

Try to find one that you are able to fully understand (simpler is better IMHO), then backtest it in different markets, timeframes, etc. and only when you are fully aware of how it works and what to expect from it, reevaluate if is worthwhile for trading or it is better to discard it.

7 Likes

It is a trend following strategy. He used PDI and MDI to predict the market trend. At the same time, he used C,H,L to predict whether it is a trend. However, he doesn’t want to buy at the top and sell at the bottom, so he coded: Exrem.

1 Like