Loading…

Basket Volatility Brake

A basket built one entry at a time can end up carrying more real risk than intended the moment volatility widens across several symbols at once - each leg was sized correctly when it was opened, but ATR moved on all of them together. This EA is a brake, not a panic flattener: it measures aggregate risk as each managed position's lot size times its own symbol's ATR times its own live tick value (never a hardcoded per-point figure, since that varies wildly between FX pairs, metals and indices), sums it across the book, and compares the total to a ceiling expressed as a percentage of account equity. When the ceiling is breached, every managed leg is reduced by the SAME proportional fraction via a partial close - a leg carrying 2 lots and a leg carrying 0.2 lots both come down by, say, 30%, preserving the book's relative shape rather than closing the largest position outright or closing everything. A leg is left alone rather than partially closed to nothing if doing so would breach the broker's minimum lot, and a cooldown period prevents the brake firing again immediately after an activation while volatility is still elevated. This EA never opens a position of its own - it only manages what is already open, filtered by magic number (or every open position, if InpMagicNumber is left at 0). Notes and limitations Risk is measured with ATR, a lagging volatility proxy - a genuinely sudden spike can still cause real slippage before the next evaluation cycle catches it. A leg the broker rejects for partial close (network error, requote) is logged and left as-is; the next evaluation cycle will attempt it again if the book is still over ceiling. This EA does not open, hedge or otherwise protect the book beyond proportional scale-down - it is not a stop-loss replacement and does not guarantee the ceiling is never exceeded intraday.

Expert advisor · MT5 · v1.0 · Free

About Basket Volatility Brake

Basket Volatility Brake is an expert advisor (trading robot) for MetaTrader 5 based on ATR. It has 8 settings, such as Magic number, Vol ceiling percent and Atr period. MQL source code included.

Files in the download: BasketVolatilityBrake.ex5, BasketVolatilityBrake.mq5, BasketVolatilityBrake.txt.

Trading robots can lose money. Check every setting and test on a demo account before using real funds.

Settings

SettingDefaultWhat it does
Magic number0Magic number to manage, 0 = manage every open position
Vol ceiling percent3.0Portfolio volatility ceiling, % of equity
Atr period14ATR period used per symbol
Atr timeframePERIOD_H1Timeframe ATR is measured on
Min scale fraction0.20Never scale a leg down below this fraction of its current lots
Check seconds30How often the brake re-evaluates
Cooldown minutes15Minimum minutes between two brake activations
Log file nameBasketVolatilityBrake.csvFile written under MQL5\Files\

How to install

  1. Download the ZIP from your PolyMaria library and unzip it.
  2. In MetaTrader 5 open File → Open Data Folder, then go to MQL5 → Experts.
  3. Copy the .mq5 file(s) there. Put any .mqh files in MQL5 → Include.
  4. Open the .mq5 file in MetaEditor and press Compile (F7) if MetaTrader does not show it.
  5. Drag the expert advisor from the Navigator onto a chart, check the settings, allow Algo/Auto Trading and press OK.
  6. Test it first on a demo account or in the Strategy Tester.

Download the PDF guide

Tags: ATR · Risk & Lot Size · MT5 Expert Advisor · MQL5 Source Code

Expert advisors (EA) for MT4 & MT5 · PolyMaria