Time-based function to detect data gaps

I have a rather simple trading strategy I've been working on that consists of one BUY condition using a series of AND statements. My trades exit using two ApplyStops. Analysis is run at the end each week and any BUY / SELL will be on the Monday Open. I do not have "Pad and Align" selected.

During back-testing I noticed that one trade gave me outsized returns and appears to be an anomaly due to the missing data. For ticker "CMLS", the trade entered 11/3/17 ($0.45 USD) and exited on 8/10/18 ($19.50) (taking profit). My gap in data begins after the week of 11/30/17 until the week ending 8/3/18. I confirmed this gap across a few data sources.

Cleverly, backtest analysis recorded the duration as 184 bars. As most of this time had zero volume, I would have likely exited the position when no data was available (for whatever corporate action caused this) .

Reading https://forum.amibroker.com/t/remove-outliers-from-a-backtest/6773 I could add this ticker to an exclude watchlist, but I'd like to prevent this "buy and hold" in the future.

  • Is this something "pad and align would resolve"?
  • Is there another function I could use to exit as soon as a data gap is detected (reverting to the last known price for backtest purposes) and to indicate Sell during exploration?

Thanks in advance for any support you may be able to offer (I'm new here). I checked a few other topics to see if they would offer solutions :slight_smile:

When doing a backtest over a portfolio of stocks you should use 'Pad & Align'.

When you say "missing data", do you mean the stock was not trading?

If the stock was not trading then these are real world results - you want your backtest results to be in-line with real time trading. You can't exit a halted stock in the real world.

Yep, when doing a robust backtest it's a good idea to exclude winning outliers.

@TrendSurfer thanks for the reply. "Missing data" is probably inaccurate in that it was likely not trading (de-listed or for other reasons). To reflect a more conservative CAR in the backtest, I'll exclude this data point. I'll also try the pad and align to see how it influences my results. Your feedback is appreciated.

1 Like

As a follow-on, I'm finding that the database purify tool is essentially what I need to detect dates for which data is unavailable when compared to a reference symbol.