User does not understand his own code, was: Exrem not working

Hello All,

I am getting multiple buy sell signals despite using exrem , i am trying to code a Bolinger Band squeeze break out strategy. Could this be an issue with my data or is it a coding error?

_N(Title = StrFormat("{{NAME}} - {{INTERVAL}} {{DATE}} Open %g, Hi %g, Lo %g, Close %g (%.1f%%) {{VALUES}}", O, H, L, C, SelectedValue( ROC( C, 1 ) ) ));
Plot( C, "Close", ParamColor("Color", colorDefault ), styleNoTitle | ParamStyle("Style") | GetPriceStyle() ); 

_SECTION_BEGIN("Bollinger Bands");
P = ParamField("Price field",-1);
Periods = Param("Periods", 20, 2, 300, 1 );
Width = Param("Width", 2, 0, 10, 0.05 );
Color = ParamColor("Color", colorCycle );
Style = ParamStyle("Style");
Plot( BBandTop( P, Periods, Width ), "BBTop" + _PARAM_VALUES(), Color, Style ); 
Plot( BBandBot( P, Periods, Width ), "BBBot" + _PARAM_VALUES(), Color, Style ); 

P = ParamField("Price field",-1);
Periods = Param("Periods", 20, 2, 300, 1, 10 );
Plot( MA( P, Periods ), _DEFAULT_NAME(), ParamColor( "Color", colorCycle ), ParamStyle("Style") ); 

diff = (BBandTop(Close,20)-BBandBot(Close,20))/MA(Close,20)*100;
persen = PercentRank(diff,100);
loww = LLV(persen,8);
Filter =1;

Buy = High >= HHV(High,16) AND LLV(persen,8)< 10 AND High>BBandTop(Close,20);
Sell = Low <= MA(Close,20);
Buy = ExRem(Buy,Sell);
Sell = ExRem(Sell,Buy);

Short = Low <= LLV(Low,16) AND LLV(persen,8)< 10 AND Low < BBandBot(Close,20);
Cover= High >= MA(Close,20);
Short = ExRem(Short,Cover);
Cover = ExRem(Cover,short);

PlotShapes(IIf(Buy, shapeSquare, shapeNone),colorGreen, 0, L, Offset=-40);

PlotShapes(IIf(Buy, shapeSquare, shapeNone),colorLime, 0,L, Offset=-50);                      

PlotShapes(IIf(Buy, shapeUpArrow, shapeNone),colorWhite, 0,L, Offset=-45); 

PlotShapes(IIf(Short, shapeSquare, shapeNone),colorRed, 0, H, Offset=40);

PlotShapes(IIf(Short, shapeSquare, shapeNone),colorOrange, 0,H, Offset=50);                      

PlotShapes(IIf(Short, shapeDownArrow, shapeNone),colorWhite, 0,H, Offset=-45);

PlotShapes(IIf(Cover, shapeStar, shapeNone),colorRed, 0,L, Offset=-45); 

PlotShapes(IIf(Sell, shapeStar, shapeNone),colorGreen, 0, H, Offset=40);


Are you saying about backtest report?
In setting of backtest report disable Reverse Signal force exit. Backtest Setting


you can check the issue from the pic i have shared. The issue was that the buy and sell signal got triggered on the same bar, hence this issue occurred, is there a way around it? for now i have changed my sell signal to lower band but there can be a candle which touches both the bands.

ExRem works perfectly fine.

It is YOU who does not understand your own code, use this: