Hi all, I am trying to set the stoptypenbar to be 17 bars from entry and try to exit on the 17th bar's close price. However, base on the following code's generated result, I found the program always exit the position on 17th bars' high price, which I am not sure where did I write wrongly. Could anyone point me to that error? I suspect it is related to the coverprice variable but I am not sure how it might have caused the problem.
//Backtesting Only Code will not plot any signals _SECTION_BEGIN("Simple RSI Momentum Long Only Strategy"); SetTradeDelays(0,0,0,0); //Trading Logic Short = RSI(5) < 40 and Ref(RSI(5),-1) > 40; SL_above_previous_high = Ref(High,-1) * 1.02; Cover = H > SL_above_previous_high; CoverPrice = Max(0, Ref(High,-1)*1.02); ApplyStop(stopTypeLoss, stopModePercent, Optimize( "max. loss stop level", 3, 2, 30, 1 ), 1); ApplyStop( stopTypeNBar, stopModeBars,Optimize( "num of days to stop",17,5,30,1 ),1); //ApplyStop( stopTypeTrailing, stopModePercent, SL_above_previous_high ,1); ApplyStop( stopTypeProfit, stopModePercent, Optimize("profit stop",20,1,30,1),1); Equity(1,-1); SetStopPrecedence( stopTypeNBar, stopTypeTrailing, stopTypeLoss, stopTypeProfit ); //Position Size //PositionSize = MarginDeposit = 1; _SECTION_END(); PlotShapes(Cover*shapeUpArrow,colorGreen,0,Low); PlotShapes(Short*shapeDownArrow,colorRed,0,High); Plot( Close,"Price",colorBlack,styleBar); Plot(SL_above_previous_high , "trailing stop line", colorRed );