Loading…

Rolling Distribution Shift Strip

A KS test answers "are these two samples drawn from the same distribution" by comparing their whole empirical CDFs rather than just their means - it catches shape changes (fatter tails, a skew flip) that two nearly-identical average returns would hide completely. This indicator turns that one-shot test into a strip: at every bar it takes a fixed REFERENCE window of returns (an older, presumably "normal" period) and a trailing RECENT window (always the most current bars), computes the exact KS D statistic between them via a merge-scan of the two sorted sample sets, and plots D as a continuous line. The critical value for the chosen significance level is drawn as a horizontal level line, so a visible crossing is the same "reject H0, distributions differ" call a one-shot KS test would make - just recomputed at every bar instead of once. The KS statistic and asymptotic critical-value table are the exact same implementation already published as DistributionShiftDetector.mq4 (Scripts category) in this catalogue, reused here unchanged so the two tools agree with each other rather than drifting apart under two independent implementations of the same test. Notes and limitations - The reference window is fixed relative to each bar (it slides along with the chart, always InpReferenceOffset bars further back than the recent window) rather than anchored to one calendar date - this differs from the one-shot DistributionShiftDetector script, which compares two operator-chosen date ranges directly. - A significant D says the two windows differ; it does not say whether that is a level shift, a volatility shift, or both. Cross-check price action directly when the line crosses the level. - Both windows must have enough bars of price history behind them (InpReferenceOffset + InpReferenceBars, plus the recent window) - on a freshly opened chart with short history the indicator will not plot until enough bars have loaded. - Not a repainting indicator - each bar's value depends only on bars at or before it.

Indicator · MT5 · v1.0 · Free

About Rolling Distribution Shift Strip

Rolling Distribution Shift Strip is an indicator for MetaTrader 5. It has 5 settings, such as Reference bars, Reference offset and Recent bars. MQL source code included.

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

Settings

SettingDefaultWhat it does
Reference bars200Fixed reference window length (older, "normal" regime)
Reference offset200Bars back from the recent window where the reference window ends
Recent bars50Trailing recent window length, recomputed at every bar
Alpha0.05Significance level whose critical value drives the level line
Max bars to process300Cap on how many bars back to (re)compute on first load

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 · MT5 Indicator · MQL5 Source Code

MetaTrader 4 & 5 indicators · PolyMaria