Short gappers (intra-day)

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);

You don't say what timeframe (periodicity) you're using to execute your AFL, but I assume something intraday since you're checking TimeNum(). If you're running on 1min bars, for example, then OHLCV are all 1min values as well. I think you likely wanted your gap check to be based on daily bars, which is not what you've implemented. The volume check is suspect as well, but again, you didn't say what logic you're trying to implement. For example, do you require 1M shares of cumulative volume for the day before entering a trade? The current code just checks the volume of the current intraday (1min? 5min? 1hr?) bar.

You will want to investigate the various TimeFrame functions described in the AB Help files.


Thanks @mradtke

Basically the gap would be observed on a daily timeframe. So the strategy would enter on the daily open and sell the position on the daily close.

Understood re:volume, makes sense. I'll leave the volume code out for now.