Difficulties faced during backtesting

Hi Everyone,

I was back-testing my own strategies with stop loss & trailing stop loss. However during back-testing I found some places Trailing Stop Loss is not been hit & instead whole trade was waiting to drop price till stop loss level. And this was happening despite having Trailing Stop Loss well in place.

In other cases, trailing stop loss is not plotted & yes in few places it is getting plotted for both Short & Long Trades.

In some places, "ShaeUpArrow" and "ShapeDownArrow" is not getting plotted & only Trailing Stop Loss is plotted. But yes, few places "ShapeUpArrow" and "ShapeDownArrow" are not getting plotted. Want to understand how to obtain uniformity in plotting "ShapeUpArrow" and "ShapeDownArrow" for each long & short trade respectively.

Wherever the protections are allocated as like stop loss or trailing stop loss, found few places those are not working. I mean trades are not getting squared off at those "Trailing Stop Loss" or "Stop Loss" levels. And few places found trades are getting squared off properly. This is what observed during Back-Testing of the strategies.

Because of the issue finding difficulty in evaluating the strategy robustness.

Please guide how to overcome above issues.

CodeBlock used for "Trailing Stop-Loss" is as follows :

StopLevel = 1 - Param("trailing sto %", 9.5, 0.1, 10, 0.1)/100;

Buy = Cross(EMA(Close,par1),EMA(Close,par2));
BuyPrice = ValueWhen(Buy,Close);
Plot(BuyPrice, "BuyPrice", colorGreen, styleLine);

Sell1 = 0;
TrailArray = Null;
TrailStop = 0;

for(i=1; i<BarCount; i++)

if(trailstop == 0 AND Buy[i])
	trailstop = High[i]*stoplevel;
else Buy[i] = 0 // Remove Excess Buy Signals

if (TrailStop > 0 AND Low[i] < TrailStop)
	Sell1[i] = 1;
	SellPrice1[i] = TrailStop;
	TrailStop = 0;

if(TrailStop > 0)
	trailstop = Max(High[i]*stoplevel, trailstop);	
	trailarray[i] = trailstop;


Plot(trailArray, "Trailing Stop Level",colorWhite);

For "StopLoss" following CodeBlock is used :

P7 = Param("SLCodeBlock %", 81.25,.01,100,.01)/100;
Sell = (L < (BuyPrice*(1-P7))) OR (Cross(Low,TrailArray));
SellPrice = ValueWhen(Sell,Close);
Plot(SellPrice, "SellPrice", colorRed, styleLine);

CodeBlock Used for plotting "ShapeUpArrow" and "ShapeDownArrow" are as follows :

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),colorBlue, 0, H, Offset=40);
PlotShapes(IIf(Short, shapeSquare, shapeNone),colorOrange, 0,H, Offset=50);
PlotShapes(IIf(Short, shapeDownArrow, shapeNone),colorWhite, 0,H, Offset=-45);

Please guide how to overcome above issues.

Thanks & Regards,
Tushar Gawankar