Hi all,
I would like to backtest if it makes sense to add to a normal stop-loss another trailing-stop (trailing 5% below the close). However, I want the 2nd stop to be activated ONLY if a certain condition is met (eg, if Close today is 20% higher vs the close of 10 bars ago activate the 5% trailing-stop, if the condition is not met do nothing).
I do have the code for the first stop loss as well as its plotting (see below) but I am just not getting it right for the 2nd conditional stop. Its conditions would be:
- Activate only if closing price today is 10% above the close 10 bars ago
- If activated start trailing 5% below the close
- If above condition is not met do not do anything
The idea is to test if the system can benefit better from rapid / sudden price rises.
1000 thanks for your help and feedback,
Nico
ApplyStop(stopTypeLoss,stopModePoint,5*Ref(ATR(13),-1),ExitAtStop=2,Volatile=False,ReentryDelay=1);
Equity(1,0);
InTrade = Flip(Buy,Sell);
SetOption("EveryBarNullCheck",True);
Initialstopline = IIf(InTrade,valuewhen(Ref(Buy,-1),O-5*Ref(ATR(13),-1),1),Null);
PlotOHLC(open,high,low,close,Name(),colorBlueGrey,style=styleCandle,Null,null,XShift =0,ZOrder=0,width=1);
PlotShapes(Buy*shapeDownTriangle,colorbrightGreen,0,Low);
PlotShapes(Sell*shapeDownArrow,colorRed,0,High);
Plot(Initialstopline,"Initial stop line",colorRed,styleDots,0,0,0,0,1);