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
| Setting | Default | Range | What it does |
|---|---|---|---|
| atr_period | 14 | 1 to 500 | ATR length (Wilder) for every buffer. |
| gap_k | 0.1 | 0 to 5 | Smallest gap in ATRs (before the candle that completes it). |
| floor_pct | 0.02 | 0 to 10 | Smallest buffer of this detector, % of the close (each buffer is the larger of this and its ATR multiple). |
| filter | none | none, displacement | displacement = the middle candle must be a displacement candle. |
| disp_k | 1.5 | 0.1 to 10 | Displacement: smallest body in ATRs. |
| close_frac | 0.25 | 0.01 to 0.5 | Displacement: the close lies in this top (bull) or bottom (bear) fraction of the range. |
| invalid_k | 0.1 | 0 to 5 | A close this many ATRs beyond a zone's far edge ends the zone. |
| max_zones | 5 | 1 to 20 | Active zones kept (oldest dropped). |
| max_age_bars | 200 | 10 to 2000 | Candles after its birth until a zone or level expires. |
| pick_rank | 1 | 1 to 5 | Pick outputs: 1 = the nearest zone, 2 = the next one out, … |
| pick_min_visits | 0 | 0 to 50 | Pick outputs: only zones visited at least this often. |
| pick_side | any | any, bull, bear | nearest_low/high: zones of any side, or only the bull (support) or bear (resistance) side. |
What it gives
| Output | What it is |
|---|---|
| In a gap | True while the close is inside an active fair value gap. |
| In a bull gap | True while the close is inside a bull fair value gap. |
| In a bear gap | True while the close is inside a bear fair value gap. |
| Low edge of the gap above | Low edge of the nearest fair value gap wholly above the close. |
| High edge of the gap above | High edge of the nearest fair value gap wholly above the close. |
| Low edge of the gap below | Low edge of the nearest fair value gap wholly below the close. |
| High edge of the gap below | High edge of the nearest fair value gap wholly below the close. |
| Active gaps | Active fair value gaps (both sides). |
| Visits of the nearest gap | Visits 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 gap | True on the candle a bull fair value gap is born. |
| New bear gap | True on the candle a bear fair value gap is born. |
| Bull gap invalidated | True on the candle a close goes through a bull fair value gap (it ends). |
| Bear gap invalidated | True on the candle a close goes through a bear fair value gap (it ends). |
| Low edge of the gap the close is in | Low 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 in | High 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 gap | True on the candle the first visit of a bull fair value gap starts (its visits become 1). |
| First touch of a bear gap | True on the candle the first visit of a bear fair value gap starts (its visits become 1). |
| Bullish gap edge touch | True when price comes back to a bullish gap. |
| Bearish gap edge touch | True when price comes back to a bearish gap. |
| Bullish gap middle touch | True the first time price reaches a bullish gap's middle. |
| Bearish gap middle touch | True the first time price reaches a bearish gap's middle. |
| Bullish gap filled | True when a wick fills a bullish gap completely (the gap ends). |
| Bearish gap filled | True when a wick fills a bearish gap completely (the gap ends). |
| Last filled bullish gap low | Low edge of the last bullish gap a wick filled; a long's stop below the filled gap. |
| Last filled bearish gap high | High edge of the last bearish gap a wick filled; a short's stop above the filled gap. |
| Low edge of the picked gap | Low 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 gap | High 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 gap | Low 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 gap | High 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 gap | Low 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 gap | High 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 gap | Low edge of the newest active bull fair value gap, from the candle it is born (none before). |
| High edge of the newest bull gap | High edge of the newest active bull fair value gap, from the candle it is born (none before). |
| Low edge of the newest bear gap | Low edge of the newest active bear fair value gap, from the candle it is born (none before). |
| High edge of the newest bear gap | High 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