Hi all,
I've been trying to backtest a strategy that short gappers >5% and covers at either the end of day or with a 5% loss.
Unfortunately I've been getting a very limited number of hits.
Any idea what I could be doing wrong?
Thanks for the help.
// Define the gap threshold and stop-loss percentage
gapThreshold = 5; // Gap up more than 5%
volumeThreshold = 1000000; // Trade more than 1 million shares
priceThreshold = 1;
// Calculate the gap percentage
gapPercentage = ((Open - Ref(Close, -1)) / Ref(Close, -1)) * 100;
// Short entry condition: Gap up more than the threshold
shortEntryCondition = gapPercentage > gapThreshold AND Volume > volumeThreshold AND priceThreshold;
// Cover exit condition: 4:00 PM
coverExitCondition = TimeNum() == 160000; // Assuming market closes at 4:00 PM
Short = shortEntryCondition;
Cover = coverExitCondition;
ShortPrice = Open;
CoverPrice = Close;
SetTradeDelays( 0, 0, 0, 0);
ApplyStop(Type=0,Mode=1,Amount=5); //Stoploss of 5%
PlotShapes(IIf(Cover, shapeSquare, shapeNone),colorGreen, 0, L, Offset=-40);
PlotShapes(IIf(Cover, shapeSquare, shapeNone),colorLime, 0,L, Offset=-50);
PlotShapes(IIf(Cover, 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);