Supply and demand zones
Tight bases that price left with a strong candle, kept as supply and demand zones.
Demand: a bull displacement candle (disp_k, close_frac) right after a base of min_base to max_base candles (the longest that fits) whose bodies are at most base_body of their range (a zero-range candle counts as body 0) and whose high-low span is at most max(floor_pct % × close, base_k × ATR), closing above the base. Zone = [base low, highest body top]. Supply is the mirror. A close beyond the far edge by invalid_k ATRs ends a zone; zones expire max_age_bars after birth; at most max_zones are kept. fresh = the nearest zone's current visit is its first (or no visit yet).
Supply and demand zones 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. |
| min_base | 1 | 1 to 20 | Fewest candles in a base. |
| max_base | 5 | 1 to 20 | Most candles in a base. |
| base_body | 0.5 | 0 to 1 | Base candles: largest body ÷ range. |
| base_k | 1 | 0.1 to 10 | Widest base (high to low) in ATRs. |
| 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. |
| floor_pct | 0.05 | 0 to 10 | Smallest buffer of this detector, % of the close (each buffer is the larger of this and its ATR multiple). |
| 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 zone | True while the close is inside an active supply/demand zone. |
| In a demand zone | True while the close is inside a demand supply/demand zone. |
| In a supply zone | True while the close is inside a supply supply/demand zone. |
| Low edge of the zone above | Low edge of the nearest supply/demand zone wholly above the close. |
| High edge of the zone above | High edge of the nearest supply/demand zone wholly above the close. |
| Low edge of the zone below | Low edge of the nearest supply/demand zone wholly below the close. |
| High edge of the zone below | High edge of the nearest supply/demand zone wholly below the close. |
| Active zones | Active supply/demand zones (both sides). |
| Visits of the nearest zone | Visits of the nearest supply/demand zone (the one holding the close, else the closer of above/below); one continuous stay is one visit. |
| New demand zone | True on the candle a demand supply/demand zone is born. |
| New supply zone | True on the candle a supply supply/demand zone is born. |
| Demand zone invalidated | True on the candle a close goes through a demand supply/demand zone (it ends). |
| Supply zone invalidated | True on the candle a close goes through a supply supply/demand zone (it ends). |
| Low edge of the zone the close is in | Low edge of the supply/demand zone 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 zone the close is in | High edge of the supply/demand zone 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 demand zone | True on the candle the first visit of a demand supply/demand zone starts (its visits become 1). |
| First touch of a supply zone | True on the candle the first visit of a supply supply/demand zone starts (its visits become 1). |
| Fresh zone | True while the nearest zone had no visit before the current one. |
| Low edge of the picked zone | Low edge of the pick_rank-th supply/demand zone (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 zone | High edge of the pick_rank-th supply/demand zone (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 demand zone | Low edge of the demand pick_rank-th supply/demand zone (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 demand zone | High edge of the demand pick_rank-th supply/demand zone (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 supply zone | Low edge of the supply pick_rank-th supply/demand zone (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 supply zone | High edge of the supply pick_rank-th supply/demand zone (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 demand zone | Low edge of the newest active demand supply/demand zone, from the candle it is born (none before). |
| High edge of the newest demand zone | High edge of the newest active demand supply/demand zone, from the candle it is born (none before). |
| Low edge of the newest supply zone | Low edge of the newest active supply supply/demand zone, from the candle it is born (none before). |
| High edge of the newest supply zone | High edge of the newest active supply supply/demand zone, 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, Supply and demand zones needs 346 closed candles before its first value. A backtest loads them before its start date, so the first trade can already use it.
Test it
Copy this sentence into the Algonney chat to backtest it:
Backtest a strategy on BTC that uses Supply and demand zones with its default settings