Risk Per Trade Enforcer
A stop-loss that was sized correctly when a position opened does not stay that way on its own - a trader can widen it by hand under stress, a signal provider's copy trade can arrive with no stop at all, or the position can simply have been opened without one. Nothing in the terminal's normal display enforces a ceiling on how much of the account a single trade can lose; this EA does, mechanically, on every scan. RISK WARNING: this EA modifies live stop-losses automatically, including adding one to a position that currently has none. Confirm the cap and the InpApplyMissingStopLoss setting match your intent on a demo account before running it live - it will move a stop it judges too wide, even one you set deliberately wider than the default cap. The cap is enforced as a ceiling, not a target: an existing stop is only ever tightened toward price, never loosened, even on a position whose current risk sits comfortably under the cap. This EA enforces a maximum, it does not manage the trade or try to improve its risk-reward - that remains the trader's or another EA's job. Risk money is computed from MODE_TICKVALUE, MODE_TICKSIZE and the position's own OrderLots(), never a hardcoded contract size. A hardcoded 100000-unit assumption misprices risk on gold, indices and any instrument that is not a textbook 100k-lot FX pair - precisely the instruments where a wrong risk figure is most likely to matter. Notes and limitations - When the broker's minimum stop distance (MODE_STOPLEVEL/FREEZELEVEL) is wider than the cap-derived distance, the stop is placed at the broker's minimum instead, which leaves the position very slightly over the configured cap. This is disclosed in the Experts log rather than sending a price the broker would reject outright. - Risk percentage depends on the broker reporting MODE_TICKVALUE and MODE_TICKSIZE correctly; if either reads back as zero the ticket is skipped and logged rather than acted on with a wrong number. - This EA never opens a new position and never touches take-profit. It only ever moves a stop-loss inward or adds one where none exists.
Expert advisor · MT5 · v1.0 · Free
About Risk Per Trade Enforcer
Risk Per Trade Enforcer is an expert advisor (trading robot) for MetaTrader 5. It can size trades from your balance and risk percent and has a news filter. It has 8 settings, such as Max risk percent per trade, Apply missing stop loss and Min adjust pips. MQL source code included.
Files in the download: RiskEnforcer.ex5, RiskEnforcer.mq5, RiskEnforcer.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 |
|---|---|---|
| Max risk percent per trade | 2.0 | Cap risk per position to this % of account balance |
| Apply missing stop loss | true | Add an emergency stop, sized to the cap, to a stopless position |
| Min adjust pips | 2 | Only modify a stop if the change is at least this many pips (avoids chatter) |
| Magic filter | 0 | Only enforce on this magic number, 0 = all |
| Symbol only | false | Only enforce on this chart's own symbol |
| Max retries | 5 | Attempts per modify before giving up |
| Retry wait ms | 500 | Pause between attempts, milliseconds |
| Scan interval sec | 20 | Seconds between scans |
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: Buy/Sell Arrows · Risk & Lot Size · Trade Copier · News Trading · MT5 Expert Advisor · MQL5 Source Code