Loading…

Sample Entropy Meter

Sample Entropy measures how predictable a time series is from its own recent shape: for an embedding dimension m, it counts how many length-m patterns in a trailing window recur (within a tolerance r) somewhere else in that same window, then how many of those matches still hold when extended one bar further to length m+1. SampEn is -ln(A/B), where B is the m-length match count and A is the m+1-length match count. A low value means the returns series keeps repeating its own recent shape - more structure, more predictability. A high value means yesterday's pattern gives little information about what comes next. This is the actual Richman and Moorman statistic, not Approximate Entropy (ApEn) mislabelled - the distinction matters because ApEn counts self-matches and is known to be biased on short windows; SampEn excludes them deliberately, at the cost of sometimes being undefined when a window has too few matches. When that happens (B or A comes out to zero) this indicator plots nothing for that bar rather than forcing a fake 0 or an infinite value onto the chart - a divide-by-zero glossed over would be a worse answer than an honest gap. Tolerance r is scaled to the window's own standard deviation rather than fixed in absolute price terms, so a quiet symbol and a volatile one are read on a comparable footing. Notes and limitations - Computing SampEn is O(InpWindowBars^2) per bar; a very large window combined with a long chart history can make the first load noticeably slow, which is why InpMaxBarsToProcess exists. - On a window with too few repeating patterns the indicator leaves a gap rather than plotting a misleading number - this is expected behaviour on very short or unusually quiet windows, not a bug. - This measures the entropy of RETURNS, not price itself; a strongly trending market and a purely random-walk market can both show moderate-to-high SampEn, since SampEn is blind to drift/direction and only reads self-similarity of shape. - Not a repainting indicator - each bar's value depends only on bars at or before it.

Indicator · MT5 · v1.0 · Free

About Sample Entropy Meter

Sample Entropy Meter is an indicator for MetaTrader 5. It has 4 settings, such as Window bars, Embed dimension and Tolerance factor. MQL source code included.

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

Settings

SettingDefaultWhat it does
Window bars100Trailing returns window each SampEn value is computed from
Embed dimension2Template length m (published default for financial series)
Tolerance factor0.2Tolerance r = this factor * window's own stdev of returns
Max bars to process500Cap 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