Back to Community
(?) Implications surrounding bridging gaps in price data for a price action trading strategy (?)

Hello,

I am trying to build an algorithm that trades using price action trading rules (buying/shorting breakout pullbacks, fading range breakouts, etc.).
I'm currently at the stage of development where I'm just building all the little pieces of the algorithm to enable it do identify legs and larger patterns like channels.

One issue I'm not sure how to deal with is dealing with gaps between bars.
Al Brooks, author of the trading price action trilogy, says that one can treat gaps as bars and that they function similarly.
I took this and decided that it would be too much trouble to write code so as to actually insert bars where gaps exist in price data so I assumed that 'bridging' the bar that formed on the gap would be reasonable and desirable.

Attached is a notebook with examples.
The code is set so that all gaps between a current bars open and its prior bars close are set equal (bridged).
Though this affect the entire second chart, the most notable differences lie on 4/24 and 5/11.

My questions is this:

Is bridging like this reasonable?
I'm unsure of the effect this will have on a standard price action trading algorithm so my current plan is to finish the algorithm and backtest three different variations, sticking with whatever performs the best although I am concerned about how this may invite curvefitting:
1. No gap bridging whatsoever
2. Bridging gaps for bars that have gapped up/down in extremity (i.e. completely above or below its prior bar)
3. Bridging all gaps

All help is appreciated, thanks in advance

EDIT: Took out the -1 from len() while using range to setup the adjusted price data

Loading notebook preview...
Notebook previews are currently unavailable.
5 responses

You need to avoid introducing forward looking bias into the data.

Imagine you were standing at that point in time when there is a gap in the data. You don't know what the price of the next bar will be. In real trading you can't predict what the next price will be so you can't do it in backtesting either. If you need to fill in gaps in the data use the last traded price.

Hey Chris,

I'm unable to locate any forward looking bias in the code at the moment; could you point it out?
To my knowledge, when a bar closes after it gaps up or down, the code bridges the gap based on the previous bars close.

I don't know much about programming, I can't help with the coding, sorry. Just an issue you need to consider.

Ah, had me worried there.
Will definitely keep that in mind as I continue building the pieces.
More concerned about the validity of bridging a gap based on the idea that the gap itself can be treated as a bar.

Looks good so far but I can't imagine it is this simple, or maybe it is haha

Bump for curiosity