Loading…

Portfolio Drawdown Equaliser

This EA places no trades of its own. It governs a list of other strategies running on the same account, identified by their magic numbers in InpMagicList, by replaying each one's own closed-trade history into an equity curve and computing that curve's current drawdown from its own peak - not the account's overall balance, since a strategy in profit should not be cut just because a different strategy on the same account is losing. Each governed strategy gets a published multiplier, PDE_Multiplier_<magic>, that starts at 1.0 and moves toward a target set by TargetMultiplier(drawdown): 1.0 at zero drawdown, sliding linearly down to InpFloorMultiplier once drawdown reaches InpFullDrawdownPercent or worse. A strategy is never cut to zero - InpFloorMultiplier keeps it alive at reduced size, on the view that a strategy in a deep but not-yet-fatal drawdown is more useful still running small than switched off entirely, and switching off requires a human decision this EA does not make for you. The gradual part matters. A step function that snaps a multiplier straight to its floor the instant a strategy dips into drawdown, then straight back to 1.0 the moment it recovers, is itself a source of whipsaw - full size again just before the next dip. InpMaxStepPerRebalance caps how far any single rebalance pass (every InpRebalanceIntervalSec) can move a multiplier, so recovery and cutback both happen over several passes rather than in one jump. To use the published multiplier, a governed strategy's own lot-sizing code reads GlobalVariableGet("PDE_Multiplier_" + IntegerToString(itsOwnMagic)) and multiplies its normal lot size by whatever it gets back (defaulting to 1.0 if the variable does not exist yet, e.g. before this EA's first rebalance pass). Notes and limitations - Places no trades of its own - it is purely a publisher. Nothing happens unless the governed strategies' own code actually reads and applies the published multiplier. - A strategy's "drawdown" here is measured on its own replayed closed-trade equity curve starting from zero, not against account balance or floating open positions - an open position's unrealised loss is not reflected until it closes. - InpLookbackDeals bounds how far back the equity curve is rebuilt; a very active strategy with more closed trades than the lookback in its recent history will have its older trades and their effect on the peak dropped from the replay. - Global variables persist across restarts but are shared across the whole terminal, not per chart - only run one instance of this EA per terminal to avoid two instances fighting over the same published values.

Expert advisor · MT5 · v1.0 · Free

About Portfolio Drawdown Equaliser

Portfolio Drawdown Equaliser is a script for MetaTrader 5. It can alert you with a pop-up, sound, email or push message. It has 7 settings, such as Magic list, Lookback deals and Floor multiplier. MQL source code included.

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

Settings

SettingDefaultWhat it does
Magic list1001,1002,1003Comma-separated magic numbers to govern
Lookback deals500Closed deals scanned per magic to build its equity curve
Floor multiplier0.25Minimum multiplier a strategy in drawdown can be cut to
Max step per rebalance0.10Maximum change to a multiplier per rebalance pass
Full drawdown percent20.0Own-equity-curve drawdown percent that maps to the floor multiplier
Rebalance interval sec300Seconds between rebalance passes
Publish global variablestruePublish PDE_Multiplier_<magic> for each governed strategy

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 → Scripts.
  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 script onto a chart to run it once.

Download the PDF guide

Tags: Alerts · MT5 Expert Advisor · MQL5 Source Code

Expert advisors (EA) for MT4 & MT5 · PolyMaria