Watch how to download trading robots for free
Find us on Telegram!
Join our fan page
Interesting script?
So post a link to it -
let others appraise it
You liked the script? Try it in the MetaTrader 5 terminal
Indicators

Supply Demand Zones - indicator for MetaTrader 5

Cristhian Alexander Gaibor Cuasquer
Cristhian Alexander Gaibor Cuasquer
  • Founder & Systems Engineer at  Xander Pro
  • Ecuador
  • 6851
4.9 (30)
Trader and MQL5 member since 2017.
Views:
142
Rating:
(1)
Published:
MQL5 Freelance Need a robot or indicator based on this code? Order it on Freelance Go to Freelance

Supply and demand zones on Gold (XAUUSD), EURUSD or any chart, built from confirmed swing highs and lows. Each swing high opens a supply zone and each swing low a demand zone, with a height of ATR times a factor you choose, so the zones stay in proportion on any symbol and timeframe.

Every zone keeps a count of how many times price came back into it, so the label reads fresh or tested 1x, 2x, 3x, and the color dims once it is tested. A close through the zone breaks it and removes it. Overlapping zones of the same side merge into one, and only the most recent ones per side stay on the chart.

A swing needs N closed candles on its right before it exists, so a zone shows up with that delay. The zones are rebuilt once per closed bar, not on every tick. This is a mechanical swing and ATR model: no volume, no order flow, no imbalance logic. Use it as a map of reaction areas, not as an entry signal by itself.

Supply Demand Zones indicator on a MetaTrader 5 chart with fresh and tested supply and demand zones

Settings

Zones

  • Swing length (5): candles on each side of the swing candle. Higher values keep only the major swings.
  • ATR period (14) and Zone height factor (0.5): the zone is ATR x factor tall, measured down from a swing high or up from a swing low.
  • Bars to analyze (1000): how many bars from the right are scanned.
  • Zones to keep per side (6): the most recent ones stay, older ones are dropped.
  • Merge overlapping zones (true): two zones of the same side that overlap become one wider zone.
  • Remove broken zones (true): a candle close through the zone deletes it.

Display

  • Supply untested / tested and Demand untested / tested colors: fresh zones are brighter, tested ones darker.
  • Fill the rectangles (true), Extend zones to the right (20 bars).
  • Show zone labels (true), Label font size (8), Label color (silver).

Alerts

  • Pop-up, Push notification and Sound (all false): one message when the candle that just closed entered a zone it was outside of on the candle before.
  • Sound file (alert.wav).

Indicator settings

  • Object prefix (XP_SDZ_): every rectangle and label starts with it, and only those objects are removed when you take the indicator off. Give each copy its own prefix to run two on one chart, for example H1 and H4 zones.

What it needs

  • MetaTrader 5, any symbol, any timeframe, any account type. It is an indicator, it does not trade.
  • Enough history for the ATR and the swing length: at least ATR period plus two times the swing length plus two bars.
  • For EAs, five buffers on the current bar (shift 0): 0 nearest supply high, 1 nearest supply low, 2 nearest demand high, 3 nearest demand low, 4 price in zone (1 supply, -1 demand, 0 none). Older bars hold EMPTY_VALUE, so read shift 0 only.

Make it yours

Run it on XAUUSD, EURUSD, GBPUSD, US30, NAS100 or BTCUSD and compare the zone factor that fits each one: 0.5 is tight for gold on M15, while indices often read better at 0.8 or 1.0. Put it next to my Smart Money Concepts BOS CHoCH indicator and look at where a CHoCH happens inside a fresh demand or supply zone. Then manage the trade with my Partial Close Multi TP Manager, putting the first take profit at the edge of the opposite zone. If you write EAs, buffer 4 is a ready made filter: only buy when it reads -1, only sell when it reads 1. The zone builder is one function you can copy into your own code.

About this code

Based on the idea of the Shved Supply and Demand indicator from the MQL5 Code Base, rewritten from scratch for MT5.

Open source. Use it as it is, adapt it, build your own version on top of it.

New versions and new tools are announced first on my MQL5 channel: https://www.mql5.com/en/channels/xander

Questions, suggestions and your own backtests are welcome in the Xander Lab group: https://www.mql5.com/en/messages/02eec85e4364dd01

More tools on my profile: https://www.mql5.com/en/users/09151993a

Provided as is, use at your own risk.

Related

Changelog

  • v1.0 - 2026-10-25 - Initial release
Copula: Gaussian, Student t, Clayton, Gumbel and Frank copulas with tail dependence Copula: Gaussian, Student t, Clayton, Gumbel and Frank copulas with tail dependence

Fits five bivariate copulas on ranks, with Kendall's tau, tail dependence, the probability of joint extreme days, AIC and the conditional probabilities of pairs trading.

ChangePoint: Bayesian online change point detection ChangePoint: Bayesian online change point detection

Online detection of changes in the mean or volatility (Adams-MacKay): probability of a change in the last k bars, current segment length, forecast, and an indicator.

Accelerator Oscillator (AC) Accelerator Oscillator (AC)

The Acceleration/Deceleration Indicator (AC) measures acceleration and deceleration of the current driving force.

MACD Signals MACD Signals

Indicator edition for new platform.