Supply Demand Zones Base Impulse ATR
- Indicators
-
Kazuma Uezono
MQL5 / MQL4 / Pine Script v6 developer and active trader.
Seller on the MQL5 Market (indicators for MT4/MT5).
Services:
- TradingView Pine Script to MT5/MT4 conversion (bar-by-bar matching, with tester report)
- MT4 to MT5 migration - Version: 1.1
Supply & Demand Zones marks supply and demand zones on a MetaTrader 5 chart with one fixed, fully published rule: a strong bar (body at least X times ATR) that leaves a short "base" of small-body bars behind it. The base becomes a demand zone when the strong bar is bullish and closes above it, or a supply zone when the strong bar is bearish and closes below it. Each zone shows its state: fresh, touched with a count, or broken.
It is meant for traders who draw these zones by hand and want them drawn the same way every time. It is a display tool only: it gives no buy or sell signals and does not place orders. A zone is an area taken from past bars, not a forecast that price will stop or turn there.
Features
- Demand and supply zones from the rule above, judged on closed bars only. Once a zone is created its top, bottom and start never move.
- Label on each zone: "Demand fresh", "Supply touched 2", "Demand broken". Hover over a zone to see its prices, the number of base bars and the time of the first base bar.
- Colors by state: fresh, touched, broken (grey outline). Broken zones are hidden by default and can be shown.
- Unbroken zones are extended a few bars to the right of the current bar; a broken zone ends at the bar that broke it.
- Overlapping zones: the older one is filled and the newer one is drawn as an outline, so the colors stay readable.
- One optional higher timeframe (off by default). Its zones use the same rule and are drawn as thicker outlines with the timeframe in the label, for example "H4 Supply fresh".
- One optional alert (off by default): price enters a fresh zone from outside. Pop-up, sound and push notification.
- Label color follows the chart background automatically (or choose one color). Chart text and alerts in English or Japanese (Auto follows the terminal language).
- Six hidden buffers for EAs (see below).
How It Is Calculated
- True Range of a bar = higher of (high, previous close) minus lower of (low, previous close).
- ATR = simple average of the True Range of the N bars before the strong bar (the strong bar itself is not included).
- Strong bar: absolute body |close - open| >= X x ATR.
- Base: counting back from the bar just before the strong bar, the bars whose body is <= Y x ATR, one after another, up to the maximum count. If the bar just before the strong bar is not small enough, no zone is made.
- Zone top and bottom = highest high and lowest low of the base bars (or the highest and lowest open/close if "Bodies only" is chosen).
- Demand: the strong bar is bullish and closes above the zone top. Supply: the strong bar is bearish and closes below the zone bottom.
- State, from the bar after the strong bar: a demand zone is broken when a bar closes below its bottom, and touched when a bar's low reaches its top. A supply zone is broken when a bar closes above its top, and touched when a bar's high reaches its bottom.
- Touch count = number of bars that entered the zone after the previous bar was outside it. "Fresh" = no touch yet.
- Only the bars inside "Bars to scan" are used. Zones older than "Remove zones older than N bars" are removed.
Main Inputs
- Zone rules: ATR period (14), X for the strong bar (1.5), Y for base bars (0.5, must be below X), maximum base bars (3, 1-10), zone edges (wicks or bodies only), bars to scan (5000, 300-100000).
- Display: unbroken zones shown per side (5), remove zones older than N bars (1000, 0 = never), broken zones (hide or show as grey outline), broken zones shown per side (3), extend to the right (10 bars), labels on/off, font size (8), five zone colors, label color (None = automatic).
- Higher timeframe zones: timeframe (current = off), zones shown per side (3).
- Alerts: enter a fresh zone (off), pop-up, sound, push, language.
If an input is out of range the indicator does not load and writes the reason to the Experts log.
For EA and iCustom Users
- Buffers: 0 = demand zone top, 1 = demand zone bottom, 2 = demand zone touch count, 3 = supply zone top, 4 = supply zone bottom, 5 = supply zone touch count. Each bar holds the newest unbroken zone of each side as known at the close of that bar; the forming bar repeats the last closed bar. EMPTY_VALUE when there is no zone (or the newest one is older than "Remove zones older than N bars").
- The buffers contain only zones of the chart timeframe. Higher timeframe zones are not in the buffers.
- iCustom parameters: after the indicator name, pass 30 values in this order, including the 4 empty strings for the input groups:
"", ATR period, X, Y, maximum base bars, zone edges (0 wicks, 1 bodies), bars to scan,
"", unbroken zones per side, remove older than N bars, broken zones (0 hide, 1 show), broken zones per side, extend bars, show labels, font size, demand fresh color, demand touched color, supply fresh color, supply touched color, broken color, label color,
"", higher timeframe, higher timeframe zones per side,
"", alert on enter, pop-up, sound, push, language (0 auto, 1 English, 2 Japanese).
- Called through iCustom, it only fills the buffers: nothing is drawn and no alerts are raised.
- If an EA or script adds it to a chart with ChartIndicatorAdd(), MetaTrader 5 limits what it can do: the drawn zones can stay on the chart while that program still holds the handle, and on a chart other than the one the program runs on, no zones are drawn (the buffers still work).
Notes and Limits
- Zones are created only when a bar closes. The forming bar never creates a zone or changes a state; a label stays "fresh" until the bar that entered the zone has closed.
- The alert is checked on every tick against the zones as they were at the last closed bar, so it can come while the label still reads "fresh". Each zone alerts once. Right after loading, the first price is only remembered.
- After a reload (new history, reconnection, changing "Bars to scan") the calculation starts again from the first bar in range, so zones near the oldest part of the chart can differ. Recent zones are not affected.
- Results depend on the inputs and on your broker's price data: other values or another broker can give other zones.
- In ranging, quiet markets many small zones can appear; in strong trends many zones are broken soon after they form. The touch count and fresh state describe the past only and are not a probability of any outcome.
- Second and later copies on the same chart draw outlines only, so their zones do not erase the fill of the first copy.
- In visual mode of the Strategy Tester the zones are drawn as on a chart. Alerts are not raised in the tester.
- With a higher timeframe set, the tester log shows "history cache" lines. They are written by the terminal when it loads that timeframe and are not errors of the indicator.
- Large display settings (for example 50 zones per side, broken zones shown and 100000 bars on M1) make tester runs noticeably slower. The defaults are light.
- Objects whose names start with "SDZ#" belong to this indicator and are removed with it. Temporary global variables starting with "SDZ_" are used to keep copies apart. Chart settings are not changed.
Compatibility and Support
- MetaTrader 5, any symbol and timeframe. The MT4 version is a separate free product.
- Several copies on one chart (for example different X/Y values). Works with templates and after a terminal restart.
- No DLLs, no internet access, no files written.
- Support through MQL5 messages for installation, settings and bug reports. Questions about market direction or individual trades cannot be answered.
- For chart analysis only. It does not trade and does not guarantee any trading result. Past charts do not guarantee future results.
