Loading…

Regime Conditional Splitter

A strategy's edge is rarely uniform across market conditions - it is usually strong in one regime and flat or negative in another, and averaging both together into one blended statistic hides exactly the information a trader needs to decide when to run the strategy at all. This library does the split, generically: it has no opinion on what a "regime" is or how it is detected, only on accumulating the resulting per-regime statistics correctly once a tag has been assigned. RegisterSample(tag, value) feeds one observation - a trade's profit, an MFE reading, a holding time, a slippage figure, anything expressible as one number - tagged with whatever regime label the caller's own classifier produced. A new tag creates its bucket on first use; each bucket then tracks count, mean and variance via Welford's single-pass running update (never a stored array of raw values, so RegisterSample() is O(1) regardless of how many samples a regime has already accumulated), plus a running min and max. Because the regime classification itself is entirely the caller's responsibility, the same library serves a trend/range split, a volatility-bucket split, or a news/no-news split with no code changes - only the tag strings passed in change. BestRegimeByMean() and WorstRegimeByMean() answer the concrete question this library exists for directly: which regime is this metric actually best (or worst) under, by mean value across everything registered so far. Notes and limitations - Regime tags are matched by exact string comparison via a linear scan over the distinct tags seen so far - this stays cheap at realistic cardinalities (a handful to a few dozen regime labels) and is not built for an unbounded number of distinct tags. - Standard deviation is the POPULATION form (divide by n) - each bucket describes itself as a whole, it is not treated as a sample estimating some larger outside population. - BestRegimeByMean()/WorstRegimeByMean() compare by MEAN only. A regime with one lucky extreme sample and very few observations can rank ahead of a regime with a smaller but far more consistent edge - cross-check SampleCountOf() and StdDevOf() before trusting a ranking built on very few samples. - This library has no regime-detection logic of its own. It is a bookkeeping layer for whatever classification the caller already has; garbage tags in produce a meaningless split, same as any groupby.

Script · MT4 · v1.0 · Free

About Regime Conditional Splitter

Regime Conditional Splitter is a script for MetaTrader 4. It has 1 setting, such as Sample count. MQL source code included.

Files in the download: RegimeConditionalSplitter.mqh, RegimeConditionalSplitter.txt, RegimeConditionalSplitterDemo.mq4.

Settings

SettingDefaultWhat it does
Sample count300Total synthetic samples fed through the splitter

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 → Scripts.
  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 script onto a chart to run it once.

Download the PDF guide

Tags: Trend · Trading Sessions · News Trading · MT4 Script · MQL4 Source Code

MQL4 & MQL5 scripts · PolyMaria