Loading…

Sequential Probability Ratio Gate

A fixed rule like "stop after N losing trades in a row" cannot tell two very different situations apart. A strategy with a real, intact 55% win rate will still occasionally string together a losing run long enough to trip almost any fixed threshold - that is just variance, not a broken edge. A strategy whose true win rate has quietly fallen to 45% can wander for a long time without ever hitting a fixed threshold, especially a generous one chosen to avoid the first problem. Drawdown alone is not evidence of degradation; neither is a short losing streak. This header applies Wald's Sequential Probability Ratio Test to the trade-by-trade win/loss stream directly. Two hypotheses are named up front: p0, the null/baseline/degraded win rate that would make the strategy not worth running, and p1, the alternative win rate the strategy is expected to hold when its edge is genuinely intact (p1 must exceed p0 - this gate specifically tests "has the edge held up", not a generic two-sided difference test). Each trade outcome updates an accumulated log-likelihood ratio; two boundaries, computed from the chosen alpha (false-positive rate: wrongly concluding the edge is intact) and beta (false-negative rate: wrongly concluding it degraded), determine when there is enough evidence to stop sampling and decide. Until either boundary is crossed, the correct answer is genuinely "not enough evidence yet" - and the test says exactly that instead of forcing a premature call. Because it is sequential, SPRT typically reaches a confident decision in fewer trades than a fixed-sample-size test would need for the same alpha and beta - the whole reason Wald developed it originally for statistical quality control, where sampling less to reach the same confidence has a direct cost saving. Here the saving is trading time: a genuinely degraded strategy gets flagged sooner than a drawdown-threshold rule would catch it, without raising more false alarms on ordinary variance than the chosen alpha allows. Notes and limitations - This gate models a Bernoulli win/loss stream, not trade size or return magnitude - two strategies with the same win rate but very different average win/loss size are treated identically by this test. It answers "has the win rate held up", not "has the expectancy held up". - Trade outcomes are assumed independent and identically distributed under each hypothesis, the standard Wald SPRT assumption. Genuinely autocorrelated results (a strategy whose win probability itself drifts with market regime) will not violate the maths outright, but the boundaries' stated alpha/beta guarantees are calibrated for the i.i.d. case and become approximate under real-world correlation. - Once AddResult() returns a decision, further calls are ignored until Reset() is called explicitly - a finished test does not keep drifting on additional data, mirroring how a fixed-sample test's result is not itself revised by data collected after the sample closed. - Choosing p0 and p1 requires a genuine prior belief about the strategy's claimed edge and an honest "not worth running" threshold - the test is only as meaningful as those two inputs. A p1 set unrealistically high relative to the strategy's actual expected performance will see the gate drift toward EDGE DEGRADED even when nothing has actually changed.

Script · MT4 · v1.0 · Free

About Sequential Probability Ratio Gate

Sequential Probability Ratio Gate is a script for MetaTrader 4. It has 6 settings, such as Null win rate, Alternative win rate and Alpha. MQL source code included.

Files in the download: SprtStrategyGate.mqh, SprtStrategyGate.txt, SprtStrategyGateDemo.mq4.

Settings

SettingDefaultWhat it does
Null win rate0.50H0: the "degraded/baseline" win rate
Alternative win rate0.58H1: the win rate the strategy is expected to hold
Alpha0.05False-positive rate: wrongly declaring the edge intact
Beta0.10False-negative rate: wrongly declaring the edge degraded
Max trials per run400Safety cap so a boundary-case run cannot loop forever
Random seed20260817

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: MT4 Script · MQL4 Source Code

MQL4 & MQL5 scripts · PolyMaria