Open Book Volatility Rebalancer
A position sized once at entry carries whatever risk the market's volatility happened to imply at that moment. If volatility later expands, the same lot size against the same nominal stop distance now risks more than intended; if it contracts, the position is carrying less risk than it could productively take. This EA keeps dollar risk close to InpTargetRiskUsd by recalculating an ATR-based stop distance each bar and resizing the position - a partial close to shrink it, or adding lots alongside it to grow it - so risk tracks the target instead of drifting with volatility. This is the one EA in this catalogue's stop-management family that deliberately moves a stop BOTH ways. Every other tool here treats a stop as something that should only ever tighten; this one exists specifically to retune the stop to current ATR distance in both directions, because that is the whole mechanism the constant-risk sizing depends on - the file header says this plainly so nobody mistakes it for a widening bug. Resizing is gated behind InpRebalanceThreshPct so the EA does not chase every small ATR wobble with a partial close or add and pay commission on noise; it only acts once the target lot size has drifted meaningfully from what is currently held. Adding to a position uses the same magic number and a plain market order - on the always-hedging MQL4 order model this simply grows the exposure already on the book, with no netting ambiguity to consider. Notes and limitations - This EA's stop can widen as well as tighten, by design - see the full description. It is not compatible with running a separate never-widen trailing tool on the same tickets without the two fighting over the stop. - Adding to a position opens a genuinely new order under the same magic number to grow existing exposure; it is not this EA generating its own entry signal, and it never opens a first position on a symbol that has none. - Partial closes and adds are both normalised to the symbol's lot step, minimum and maximum, and skipped if the resulting adjustment would be smaller than the broker's minimum lot. - A stop or trade action that would land inside the broker's stop or freeze level, or fail on a permanent error, is skipped and logged rather than retried indefinitely. - Point value per lot is read live from MODE_TICKVALUE/MODE_TICKSIZE, never a hardcoded contract size, so this works correctly on gold, indices and JPY crosses as well as standard forex pairs.
Expert advisor · MT5 · v1.0 · Free
About Open Book Volatility Rebalancer
Open Book Volatility Rebalancer is an expert advisor (trading robot) for MetaTrader 5 based on ATR. It increases the lot size after a losing trade (martingale) and has a news filter. It has 13 settings, such as Target risk usd, Atr period and Atr timeframe min. MQL source code included.
Files in the download: OpenBookVolRebalancer.ex5, OpenBookVolRebalancer.mq5, OpenBookVolRebalancer.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 |
|---|---|---|
| Target risk usd | 100.0 | Target dollar risk to maintain per matched position |
| Atr period | 14 | ATR period used as the volatility yardstick |
| Atr timeframe min | 60 | ATR timeframe in minutes (60 = H1, 240 = H4, ...) |
| Atr multiplier | 2.0 | Stop distance = ATR x this multiplier |
| Allow partial close | true | Shrink a position when target lots fall below current |
| Allow adding | true | Grow a position when target lots exceed current |
| Rebalance thresh pct | 15.0 | Minimum lot deviation, percent, before acting (avoids churn) |
| Once per bar only | true | Recalculate only on a new bar of InpAtrTimeframeMin |
| Magic filter | -1 | Magic number filter (-1 = every magic) |
| Current symbol only | true | Restrict to this chart's symbol |
| Slippage points | 30 | Slippage tolerance for resizing trades |
| Max retries | 5 | Attempts per 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: ATR · Risk & Lot Size · Martingale · News Trading · MT5 Expert Advisor · MQL5 Source Code