Permutation Entropy Regime
Most complexity measures available to MetaTrader users look at the size of price moves. Permutation entropy looks at their order instead. Every overlapping run of InpOrder consecutive closes is reduced to its rank pattern - which position in the run is highest, which is second highest, and so on - and every run in the rolling window is classified into one of InpOrder-factorial possible patterns. The Shannon entropy of how often each pattern occurs, normalised to 0..1, is the reading. A market cycling through orderings close to uniformly - every pattern about equally likely - reads near 1, close to what a genuinely random sequence would produce. A market that keeps repeating a small subset of orderings reads low: something is structuring the sequence, whether that is a strong trend, a tight range, or some other regularity the entropy measure does not itself distinguish. That is the honest limitation of the method - it detects structure, not what kind. This complements existing choppiness and randomness tools rather than duplicating them: those typically look at magnitude or at pass/fail run-length tests, while this looks purely at the ordinal shape of short sequences. Notes and limitations - Patterns are built directly from close prices with ties broken by bar position, the standard convention - on instruments with very coarse tick sizes, genuine ties become more common and slightly understate the entropy. - Higher InpOrder values need a larger InpLookback to keep the pattern histogram from being dominated by sampling noise; the input validation only enforces a loose four-times-order floor. - This flags a statistical regime property, not a trade signal, and says nothing about direction. - Entropy is recomputed independently every bar from the trailing window; it does not smooth between readings.
Indicator · MT4 · v1.0 · Free
About Permutation Entropy Regime
Permutation Entropy Regime is an indicator for MetaTrader 4. It can alert you with a pop-up, sound, email or push message. It has 4 settings, such as Order, Lookback and Low threshold. MQL source code included.
Files in the download: PermutationEntropyRegime.ex4, PermutationEntropyRegime.mq4, PermutationEntropyRegime.txt.
Settings
| Setting | Default | What it does |
|---|---|---|
| Order | 4 | Pattern length (embedding order), 3 to 5 |
| Lookback | 60 | Bars of overlapping patterns tallied into the frequency histogram |
| Low threshold | 0.65 | Entropy at or below this = alert-worthy structured regime |
| Alerts | true | Alert once per closed bar on crossing below the threshold |
How to install
- Download the ZIP from your PolyMaria library and unzip it.
- In MetaTrader 4 open File → Open Data Folder, then go to MQL4 → Indicators.
- Copy the .mq4 file(s) there. Put any .mqh files in MQL4 → Include.
- Open the .mq4 file in MetaEditor and press Compile (F7) if MetaTrader does not show it.
- Drag the indicator from the Navigator onto a chart and adjust the settings.
Tags: Alerts · MT4 Indicator · MQL4 Source Code