Loading…

Ergodicity Gap Panel

Two different, equally valid ways to average the same set of returns give different answers, and the gap between them is not a bug - it is the mathematical content behind what ergodicity economics calls the ergodicity problem (Peters, 2019). The ENSEMBLE average is the plain arithmetic mean of the returns in the window - what you would get if you ran many independent copies of the same bet and averaged their one-period outcomes. The TIME-AVERAGE growth rate is the geometric mean of (1+return) minus one - the actual compounded rate a single position, held through the whole window, would have realised. By the AM-GM inequality the ensemble average is always greater than or equal to the time-average growth whenever the returns vary at all, and the two coincide only when every return in the window is identical. The gap is driven purely by variance: it is a direct, computable expression of volatility drag, the reason a symmetric 50/50 bet with positive expected value can still ruin a sequence of leveraged bets over time even though its arithmetic average return is positive. This indicator computes both measures over the same rolling window of simple returns and plots the gap as a histogram, so the size of the volatility-drag effect is visible directly rather than left implicit. Notes and limitations - The geometric mean is computed via a log-sum (mean of ln(1+return), then exponentiated) rather than a direct running product, for numerical stability over longer windows. - A single-bar loss of 100% or more (growth factor <= 0) makes compounding undefined and is guarded against, though it does not occur on ordinary price data. - Uses simple bar-to-bar returns, not log returns, for the arithmetic ("ensemble") side, to keep it a plain, literal arithmetic mean; the geometric side compounds those same simple returns correctly via the log-sum method above. - Does not repaint - each bar's value only ever uses bars at or before it.

Indicator · MT4 · v1.0 · Free

About Ergodicity Gap Panel

Ergodicity Gap Panel is an indicator for MetaTrader 4. It has 1 setting, such as Lookback. MQL source code included.

Files in the download: ErgodicityGapPanel.ex4, ErgodicityGapPanel.mq4, ErgodicityGapPanel.txt.

Settings

SettingDefaultWhat it does
Lookback30Bars of returns in the rolling window (both measures use the same window)

How to install

  1. Download the ZIP from your PolyMaria library and unzip it.
  2. In MetaTrader 4 open File → Open Data Folder, then go to MQL4 → Indicators.
  3. Copy the .mq4 file(s) there. Put any .mqh files in MQL4 → Include.
  4. Open the .mq4 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: MT4 Indicator · MQL4 Source Code

MetaTrader 4 & 5 indicators · PolyMaria