Z Score Stepped Entry System
Stepping into more size as price moves further against a reversion trade improves average entry price when the move does turn, and is exactly how martingale-style systems destroy an account when it doesn't. This system publishes three configurable |z-score| thresholds (against a moving mean/standard-deviation of Close) and adds one step each time price reaches the next threshold that hasn't been taken yet, each step sized to risk a fixed percent of equity to its own ATR-based stop. The part that makes this safe to publish is the gate, not the entry logic: before ANY step is sent - including the first - the EA sums the actual money risk already committed by its own open tickets, read fresh from each order's own OpenPrice/StopLoss/Lots fields (never a remembered running total that could drift from what the broker actually holds), and compares that sum plus the candidate step's risk against InpMaxTotalRiskPercent of current equity. If the step would breach the cap, it is refused outright with a loud Alert() and Print() - the step is never silently resized down to fit, because a silently-resized step is a silently-changed strategy, which is worse than one that visibly refused to trade. The whole basket exits together once price reverts back to InpZExit. Notes and limitations - Steps only ever build in one direction at a time; a threshold breach on the opposite side is ignored while steps are already open on the other side, rather than opening a hedge against the existing basket. - If InpMaxTotalRiskPercent is set smaller than InpRiskPerStepPercent, OnInit refuses to start - a cap that couldn't even fit the first step is a configuration error, not a valid conservative setting. - An open order found with no stop loss set (for example, modified manually) is treated as consuming the ENTIRE risk cap for its lifetime, blocking further steps until it is corrected - the EA has no way to bound an unmeasured risk, so it assumes the worst rather than ignoring it. - This is still a reversion system: a genuine regime change rather than a temporary extreme can keep pushing z further out, and the hard cap limits maximum loss per basket but does not guarantee a profitable outcome. - Lot sizing uses MODE_TICKVALUE/MODE_TICKSIZE, not a hardcoded contract size.
Expert advisor · MT5 · v1.0 · Free
About Z Score Stepped Entry System
Z Score Stepped Entry System is an expert advisor (trading robot) for MetaTrader 5 based on ATR. It can size trades from your balance and risk percent. It has 13 settings, such as Z period, Z step1 and Z step2. MQL source code included.
Files in the download: ZScoreSteppedEntry.ex5, ZScoreSteppedEntry.mq5, ZScoreSteppedEntry.txt.
Trading robots can lose money. Check every setting and test on a demo account before using real funds.
Settings
| Setting | Default | What it does |
|---|---|---|
| Z period | 20 | Lookback for the mean/standard-deviation used to compute the z-score |
| Z step1 | 2.0 | |z| threshold that triggers the FIRST step |
| Z step2 | 2.75 | |z| threshold that triggers the SECOND step (must exceed step 1) |
| Z step3 | 3.5 | |z| threshold that triggers the THIRD step (must exceed step 2) |
| Z exit | 0.25 | Close the whole basket once |z| falls back to this level |
| Stop atr multiple | 3.0 | Per-step stop distance as a multiple of ATR, from that step's own entry |
| Atr period | 14 | ATR period used for the per-step stop distance |
| Risk per step percent | 0.5 | Money risk of ONE step, as percent of equity (used to size that step) |
| Max total risk percent | 2.0 | HARD CAP: total open risk across ALL steps combined, percent of equity |
| Magic number | 35401 | Magic number for orders opened by this EA |
| Slippage pips | 3 | Slippage tolerance, in pips |
| Max retries | 5 | Attempts per trade action before giving up |
| Retry wait ms | 500 | Pause between attempts, milliseconds |
How to install
- Download the ZIP from your PolyMaria library and unzip it.
- In MetaTrader 5 open File → Open Data Folder, then go to MQL5 → Experts.
- Copy the .mq5 file(s) there. Put any .mqh files in MQL5 → Include.
- Open the .mq5 file in MetaEditor and press Compile (F7) if MetaTrader does not show it.
- Drag the expert advisor from the Navigator onto a chart, check the settings, allow Algo/Auto Trading and press OK.
- Test it first on a demo account or in the Strategy Tester.
Tags: Martingale · Risk & Lot Size · ATR · MT5 Expert Advisor · MQL5 Source Code