Loading…

Strategy Allocation Governor

Running several EAs, or several instances of one EA on different symbols, usually means checking on each one's recent results by hand and deciding whether to trim its size or switch it off. That review happens rarely enough, and gets skipped often enough under a busy week, that a strategy which turned cold two months ago can keep trading at full size long after anyone would have chosen that if asked directly. This EA does that review automatically. Point it at a list of magic numbers and it recalculates, on a timer, each one's profit factor over its own most recent InpLookbackTrades closed trades - a genuinely rolling window, not a lifetime average that a strategy's early good months can mask forever. A strategy whose rolling profit factor rises above InpUpstepProfitFactor gets its multiplier stepped up by InpStepSize, one below InpDownstepProfitFactor gets stepped down, and one at or below InpRetireProfitFactor is retired outright to a multiplier of zero. Because the profit factor is recalculated fresh from history every time rather than remembered, a retired strategy reactivates on its own the moment its own recent trades recover past the retire threshold - restarting from InpBaseMultiplier, not resuming at whatever size it held before, so getting back in the game does not mean getting back to full size for free. The governor never places, modifies or closes a single order. It only writes a CSV: one row per governed magic number, with the current multiplier, profit factor, trade count and status. The EAs being governed must read that file themselves and multiply their own base lot size by the figure in it - this tool decides the number, it does not enforce it. Keeping it observe-only means a bug in the governor can produce a stale or wrong multiplier, never a bad trade, which is the much safer failure mode for something that decides how much size other automated strategies are allowed to run. Notes and limitations - This tool is advisory infrastructure, not an enforcement mechanism. A governed EA that never reads the CSV simply keeps trading at whatever size it always used - the multiplier only works if the governed EA is written to apply it. - Profit factor uses closed market trades only (a real fill, not a pending order deleted before triggering); on MQL4 this is enforced by filtering to OP_BUY/OP_SELL history, on MQL5 by filtering to DEAL_TYPE_BUY/SELL exit deals - either way excluded so they cannot distort the ratio. - A magic number with no losing trades in its window reports a capped profit factor of 999 rather than an undefined division by zero - this is a display convention, not a claim that the strategy cannot lose. - Multipliers persist across restarts by reading back the previous CSV, so restarting the terminal does not silently reset every strategy to the base multiplier. - The rolling window is recomputed from the full account history every recalculation; on an account with a very large history this is more work than a strategy that only reads the latest few trades, though still far cheaper than anything done on every tick.

Expert advisor · MT4 · v1.0 · Free

About Strategy Allocation Governor

Strategy Allocation Governor is a script for MetaTrader 4. It can alert you with a pop-up, sound, email or push message. It has 11 settings, such as Magic list, Lookback trades and Base multiplier. MQL source code included.

Files in the download: StrategyAllocationGovernor.ex4, StrategyAllocationGovernor.mq4, StrategyAllocationGovernor.txt.

Settings

SettingDefaultWhat it does
Magic list20260601,20260602,20260603Comma separated magic numbers to govern
Lookback trades20Rolling window of closed trades per magic number
Base multiplier1.0Starting multiplier for a magic never seen before, or reactivated
Min multiplier0.25Floor a multiplier is never stepped below (while still active)
Max multiplier2.0Ceiling a multiplier is never stepped above
Step size0.10Multiplier change per recalculation when stepping up or down
Upstep profit factor1.5Rolling profit factor at/above which the multiplier steps up
Downstep profit factor0.8Rolling profit factor at/below which the multiplier steps down
Retire profit factor0.5Rolling profit factor at/below which the multiplier is forced to zero
Output file nameStrategyAllocationGovernor.csvGovernance file, MQL4\Files
Recalc seconds300Seconds between recalculations

How to install

  1. Download the ZIP from your PolyMaria library and unzip it.
  2. In MetaTrader 4 open File → Open Data Folder, then go to MQL4 → Scripts.
  3. Copy the .mq4 file(s) there. Put any .mqh files in MQL4 → Include.
  4. Open the .mq4 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: Risk & Lot Size · Alerts · MT4 Expert Advisor · MQL4 Source Code

Expert advisors (EA) for MT4 & MT5 · PolyMaria