Loading…

Return Distribution Histogram

Traders read volatility from ATR or Bollinger width, but rarely see the actual shape of the return distribution behind those numbers - whether recent bars have been clustering tightly with a few sharp outliers, or spread fairly evenly. This indicator computes the percent return of every bar over the last InpLookback closed bars, bins those returns into InpBuckets equal-width buckets, and draws the bucket counts as a histogram in a subwindow, with the mean bucket marked by a diamond and the +/-1 sigma buckets marked by dots. Buckets whose centre sits more than two standard deviations from the mean are drawn in red instead of blue, flagging them as statistical outliers within the sampled window. The one non-obvious design decision here is how a distribution - which has no natural time axis - gets drawn inside a standard MT4 subwindow, whose x axis is always time. This indicator reuses the rightmost InpBuckets bar slots on the chart as fixed histogram bins: the lowest-return bucket occupies the leftmost of those slots, the highest-return bucket the rightmost. Their horizontal position does not correspond to when anything happened - it is a coordinate hack that lets a real MT4 histogram buffer draw a genuine distribution shape without a custom canvas. This is explained so a user is not confused about why moving along the time axis inside those bars does not correspond to specific historical dates. Outlier recolouring uses a second histogram buffer rather than a per-bar colour override, because MQL4 has no DRAW_COLOR_HISTOGRAM - unlike MQL5, a single MQL4 buffer cannot carry a different colour per bar. Splitting outlier buckets into their own buffer is the standard MQL4 workaround for that gap. Notes and limitations - The histogram occupies the rightmost InpBuckets bars on the chart's time axis purely as a drawing surface; that region of the chart no longer shows a meaningful time-price relationship for those bars, only the distribution shape. See the full description for why. - Recomputes once per new closed bar, not every tick, since it summarises already-closed bars only and is non-repainting by construction. - Bucket boundaries are evenly spaced across the sampled min/max return, not fixed sigma widths, so bucket count and mean/sigma marker position can shift slightly as InpLookback rolls forward. - Requires at least InpBuckets + 3 bars of chart history to produce a reading, and a meaningful sample needs InpLookback comfortably larger than InpBuckets.

Indicator · MT5 · v1.0 · Free

About Return Distribution Histogram

Return Distribution Histogram is an indicator for MetaTrader 5. It draws buy and sell arrows on the chart. It has 2 settings, such as Lookback and Buckets. MQL source code included.

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

Settings

SettingDefaultWhat it does
Lookback200Number of completed bar returns sampled
Buckets20Number of histogram bins, also the chart slots used to draw them

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: Bollinger Bands · ATR · Buy/Sell Arrows · MT5 Indicator · MQL5 Source Code

MetaTrader 4 & 5 indicators · PolyMaria