Skip to content

Free MT5 indicator

Z-Score Oscillator

Price z-score oscillator for MT5 measuring distance from the SMA in standard deviations, with coloured plus/minus 2 zones and alerts.

Mean reversionv1.0MetaTrader 5 (MQL5) Compiles with 0 errors Non-repainting signals Alerts

What it does

A z-score tells you how far a value is from its average in units of standard deviation. This oscillator applies that to price: a reading of +2 means price is two standard deviations above its recent moving average, and -2 means two below. The line turns red above the upper level and green below the lower level, so stretched conditions are easy to spot.

How it works

  • Moving average (SMA) = average of the applied price over the lookback.
  • Standard deviation = population standard deviation of the applied price over the same bars.
  • Z-score = (price - SMA) / standard deviation. If the standard deviation is zero, the z-score is 0.
  • Levels are drawn at +level, 0 and -level.
  • Alerts check the last closed bar. "Beyond" alerts fire when the z-score crosses outside a level; "return" alerts fire when it crosses back inside.

Example (illustrative): with a 20-bar SMA of 1.0850, a standard deviation of 0.0020 and a close of 1.0890, the z-score is (1.0890 - 1.0850) / 0.0020 = 2.0.

The z-score is essentially the position of price within Bollinger Bands expressed as a number, which makes it easy to compare across symbols and timeframes.

How to use it

Mean-reversion traders watch for readings beyond plus or minus 2, which show price is stretched relative to its recent average, and then look for signs that the stretch is ending, such as the z-score returning inside the level. Trend traders read the same numbers differently: a market that holds above +1 for many bars is showing persistent strength.

Combine it with structure, for example a stretched reading into a known resistance area, and plan exits with the Risk Reward Calculator. Ranges and slower timeframes (H1 to D1) usually suit mean-reversion use better than fast trending markets.

Settings

InputDefaultWhat it changes
Lookback20Longer lookbacks give a slower, smoother oscillator
Applied priceCloseClose, open, high, low, median, typical or weighted price
Extreme level2.0Position of the outer levels and colour changes
Alert on move beyond leveltrueAlerts when the z-score leaves the band
Alert on return inside levelfalseAlerts when the z-score comes back inside
Popup alerts / Push notificationsfalseDelivery of the alerts above, once per bar

Limitations

  • Prices are not normally distributed, so readings beyond 2 or 3 happen more often than textbook statistics suggest.
  • In strong trends the z-score can stay extreme for a long time; fading it can be costly.
  • The SMA and standard deviation both move with price, so the z-score is relative to a moving baseline.
  • The live bar's value changes until the bar closes.

Key inputs

Key inputs of Z-Score Oscillator
InputDefaultDescription
Lookback (SMA and standard deviation)20Bars used for the average and the standard deviation.
Applied priceClosePrice series used for the calculation.
Extreme level (+/-)2.0Z-score level drawn above and below zero and used for colouring.
Alert when z-score moves beyond a leveltrueAlert type: z-score moves outside the extreme levels.
Alert when z-score returns inside a levelfalseAlert type: z-score moves back inside the extreme levels.
Popup alertsfalseMaster switch for popup alerts, sent once per bar on closed bars.

Educational tools, not advice. Indicators and Expert Advisors describe price; they do not predict it, and past behaviour does not guarantee future results. Test everything on a demo account first and never risk money you cannot afford to lose. See our disclaimer.

Keep exploring

Related mt5 indicators