Loading…

Robust Outlier Bar Flagger

A standard-deviation-based outlier detector has a built-in blind spot: the outlier it is trying to catch is itself included in the stdev calculation, so one genuinely extreme bar inflates the very threshold meant to catch extreme bars, making the next spike look comparatively tame. This indicator uses the median absolute deviation instead - a dispersion measure built from medians rather than means and squared distances, which barely moves when a single bar in the window is extreme, so a second spike is still judged against a threshold the first one did not distort. Each closed bar's return (close minus the previous close) is scored as a robust z-score, 0.6745 * (return - median) / MAD - the constant 0.6745 is the standard scaling that makes MAD comparable to a normal distribution's standard deviation. A bar whose absolute robust z-score clears the input threshold is marked with an arrow above or below the bar, on the side matching the direction of that bar's abnormal move. Notes and limitations If a window's MAD is exactly zero (every return in the baseline window identical, which is rare but possible on an illiquid symbol with long flat stretches), that bar is skipped rather than flagged, since a robust z-score is undefined when there is no dispersion to compare against. This indicator flags statistically unusual bar-to-bar moves; it makes no claim about why a bar was unusual (news, a spread spike, low liquidity) or what happens next. It does not repaint already-flagged historical bars, but does recompute the baseline for currently plotted bars each time a new bar closes, within the InpMaxPlotBars window.

Indicator · MT5 · v1.0 · Free

About Robust Outlier Bar Flagger

Robust Outlier Bar Flagger is an indicator for MetaTrader 5. It draws buy and sell arrows on the chart. It has 3 settings, such as Lookback, Mad multiplier and Max plot bars. MQL source code included.

Files in the download: RobustOutlierFlagger.ex5, RobustOutlierFlagger.mq5, RobustOutlierFlagger.txt.

Settings

SettingDefaultWhat it does
Lookback50Trailing bars used to compute median/MAD (10-200)
Mad multiplier3.5Robust z-score threshold that marks a bar as an outlier
Max plot bars500History bars kept recomputed (performance cap)

How to install

  1. Download the ZIP from your PolyMaria library and unzip it.
  2. In MetaTrader 5 open File → Open Data Folder, then go to MQL5 → Indicators.
  3. Copy the .mq5 file(s) there. Put any .mqh files in MQL5 → Include.
  4. Open the .mq5 file in MetaEditor and press Compile (F7) if MetaTrader does not show it.
  5. Drag the indicator from the Navigator onto a chart and adjust the settings.

Download the PDF guide

Tags: Trailing Stop & Break-even · Buy/Sell Arrows · MT5 Indicator · MQL5 Source Code

MetaTrader 4 & 5 indicators · PolyMaria