Plot Apply Stop on Chart (Short /Cover)

Hi Guys,
I am new to the AFL and still in the learning process. I watched Dave's online YouTube video on how to plot Apply Stop on a chart (https://www.youtube.com/watch?v=TaWlJ6X4Om4&t=302s). I was able to follow and plot the Apply Stop signals, however; when I used the same logic for the Short and Cover nothing got plotted. Please see the following code. I already spent a few hours and gave up on this. I would really appreciate your help.

//SetPositionSize(5, spsPercentOfEquity);
SetOption("MaxOpenPositions", 2000);




ShortTrade = Cross(70, RSI(14));
CoverTrade = Cross(RSI(14), 50);

Stoplength = 4;
Short = ShortTrade;
Cover = CoverTrade; 
 
 ApplyStop(stopTypeLoss,stopModePoint,Stoplength,1, False);
 Equity(1,0);
 
 inTrade = Flip(Short,Cover);
 SetOption ("EveryBarNullCheck", True);
 
 



Stopline =IIf(inTrade, ValueWhen(Short,ShortPrice+Stoplength,1), Null);

 
Plot (Stopline, "StopLine", colorRed, styleline,0,0,0,0); 

PlotShapes(IIf(Short, shapeUpArrow, shapeNone),colorRed, 0, L, Offset=-40);


PlotShapes(IIf(Cover, shapestar, shapeNone),colorRed, 0, H, Offset=20);

@smm329, if you run an exploration, you will see that while you are still getting the cross signals, all the Shorts/Covers corresponding values are set to zero.

Try performing the same exploration by commenting out the Equity(1, 0); line.
(It appears that in this short/cover setup the call to Equity removes all the signals in the short/cover arrays)

I don't know why this happens (maybe there is some other setting to use to get the desired result).

I think it might be a good question for @Tomasz or some other very knowledgeable user!

1 Like

Equity(1, 0 ) uses most recent BACKTEST settings.

You have to:

  1. change the Analysis SETTINGS to allow short trades
  2. run BACKTEST
  3. then use the formula

Otherwise you are using old settings that don't allow Short trades.

3 Likes

Hooray! This is great; now the code works beppe. Tomasz, you are the bossman. Thank you for helping me.

1 Like