Hi, in the enclosed afl code I want the code to exit trade at given atr level using Applystop function. However my code does not work. Thanks for advise.
Buy = Cross( C, MA( C, 50 ) ); // some trading rules
Sell = Cross( MA( C, 20 ), C );
BuyPrice = SellPrice = C;
Buy = ExRem(Buy,Sell);
Sell = ExRem(Sell,Buy);
StopLevel = ValueWhen(Buy, O) - Valuewhen(Buy, 0.1*Ref(ATR(14),-1));
ApplyStop(stopTypeLoss, stopModePoint, StopLevel, 1);
Plot(StopLevel,"StopLevel",colorWhite,styleDashed);
SetChartOptions(1,chartShowDates);
PlotOHLC( open, high, low, close, Name(), colorBlack,styleCandle,Null,null, XShift =0, ZOrder = 0, width = 1 );
PlotShapes(IIf(Buy,shapeUpArrow,shapeNone),colorBlue,layer = 0, yposition = L, offset = - (2*(H+L)/4), XShift = 0 );
PlotShapes(IIf(Sell,shapeDownArrow,shapeNone),colorOrange,layer = 0, yposition = H, offset = - (2*(H+L)/4), XShift = 0 );
Filter = Buy;
AddColumn(Close, "Close");