Fair value gaps

Three-candle price gaps (fair value gaps), with retests, fills and breaks.

Fair value gap: bull when the current low is above the high two candles back by more than max(floor_pct % × close, gap_k × ATR); the zone is [that high, current low]; bear is the mirror. filter = displacement also needs the middle candle to be a displacement (disp_k, close_frac). Known on the third candle, which never touches its own gap. Edge touch = a new visit; mid touch once per gap; filled = a wick through the whole gap (the gap ends); invalidated = a close beyond the far edge by invalid_k ATRs. Gaps expire max_age_bars after birth; at most max_zones are kept. last_filled_bull_low / last_filled_bear_high = the low / high edge of the last bull / bear gap that was filled (the newest if several fill on one candle), from the fill candle until the next fill of the same side, at most max_age_bars candles.

Fair value gaps is a structure detector: it marks price structure on the chart and counts against the plan's detector limit.

Settings

SettingDefaultRangeWhat it does
atr_period141 to 500ATR length (Wilder) for every buffer.
gap_k0.10 to 5Smallest gap in ATRs (before the candle that completes it).
floor_pct0.020 to 10Smallest buffer of this detector, % of the close (each buffer is the larger of this and its ATR multiple).
filternonenone, displacementdisplacement = the middle candle must be a displacement candle.
disp_k1.50.1 to 10Displacement: smallest body in ATRs.
close_frac0.250.01 to 0.5Displacement: the close lies in this top (bull) or bottom (bear) fraction of the range.
invalid_k0.10 to 5A close this many ATRs beyond a zone's far edge ends the zone.
max_zones51 to 20Active zones kept (oldest dropped).
max_age_bars20010 to 2000Candles after its birth until a zone or level expires.
pick_rank11 to 5Pick outputs: 1 = the nearest zone, 2 = the next one out, …
pick_min_visits00 to 50Pick outputs: only zones visited at least this often.
pick_sideanyany, bull, bearnearest_low/high: zones of any side, or only the bull (support) or bear (resistance) side.

What it gives

OutputWhat it is
In a gapTrue while the close is inside an active fair value gap.
In a bull gapTrue while the close is inside a bull fair value gap.
In a bear gapTrue while the close is inside a bear fair value gap.
Low edge of the gap aboveLow edge of the nearest fair value gap wholly above the close.
High edge of the gap aboveHigh edge of the nearest fair value gap wholly above the close.
Low edge of the gap belowLow edge of the nearest fair value gap wholly below the close.
High edge of the gap belowHigh edge of the nearest fair value gap wholly below the close.
Active gapsActive fair value gaps (both sides).
Visits of the nearest gapVisits of the nearest fair value gap (the one holding the close, else the closer of above/below); one continuous stay is one visit.
New bull gapTrue on the candle a bull fair value gap is born.
New bear gapTrue on the candle a bear fair value gap is born.
Bull gap invalidatedTrue on the candle a close goes through a bull fair value gap (it ends).
Bear gap invalidatedTrue on the candle a close goes through a bear fair value gap (it ends).
Low edge of the gap the close is inLow edge of the fair value gap the close is inside (the most recently created if several); none outside every zone. A long's stop below the zone.
High edge of the gap the close is inHigh edge of the fair value gap the close is inside (the most recently created if several); none outside every zone. A short's stop above the zone.
First touch of a bull gapTrue on the candle the first visit of a bull fair value gap starts (its visits become 1).
First touch of a bear gapTrue on the candle the first visit of a bear fair value gap starts (its visits become 1).
Bullish gap edge touchTrue when price comes back to a bullish gap.
Bearish gap edge touchTrue when price comes back to a bearish gap.
Bullish gap middle touchTrue the first time price reaches a bullish gap's middle.
Bearish gap middle touchTrue the first time price reaches a bearish gap's middle.
Bullish gap filledTrue when a wick fills a bullish gap completely (the gap ends).
Bearish gap filledTrue when a wick fills a bearish gap completely (the gap ends).
Last filled bullish gap lowLow edge of the last bullish gap a wick filled; a long's stop below the filled gap.
Last filled bearish gap highHigh edge of the last bearish gap a wick filled; a short's stop above the filled gap.
Low edge of the picked gapLow edge of the pick_rank-th fair value gap (1 = nearest: one holding the close, else the closest) with at least pick_min_visits visits, of the pick_side side; inside it or not.
High edge of the picked gapHigh edge of the pick_rank-th fair value gap (1 = nearest: one holding the close, else the closest) with at least pick_min_visits visits, of the pick_side side; inside it or not.
Low edge of the picked bull gapLow edge of the bull pick_rank-th fair value gap (1 = nearest: one holding the close, else the closest) with at least pick_min_visits visits; inside it or not.
High edge of the picked bull gapHigh edge of the bull pick_rank-th fair value gap (1 = nearest: one holding the close, else the closest) with at least pick_min_visits visits; inside it or not.
Low edge of the picked bear gapLow edge of the bear pick_rank-th fair value gap (1 = nearest: one holding the close, else the closest) with at least pick_min_visits visits; inside it or not.
High edge of the picked bear gapHigh edge of the bear pick_rank-th fair value gap (1 = nearest: one holding the close, else the closest) with at least pick_min_visits visits; inside it or not.
Low edge of the newest bull gapLow edge of the newest active bull fair value gap, from the candle it is born (none before).
High edge of the newest bull gapHigh edge of the newest active bull fair value gap, from the candle it is born (none before).
Low edge of the newest bear gapLow edge of the newest active bear fair value gap, from the candle it is born (none before).
High edge of the newest bear gapHigh edge of the newest active bear fair value gap, from the candle it is born (none before).

What it reads

It reads the whole candle (open, high, low, close and volume).

Warm-up

With its default settings, Fair value gaps needs 344 closed candles before its first value. A backtest loads them before its start date, so the first trade can already use it.

Related indicators

Used to build: ICT session setup

Test it

Copy this sentence into the Algonney chat to backtest it:

Backtest a strategy on BTC that uses Fair value gaps with its default settings