Loading…

Equity Volatility Governor

Most risk controls watch the market: an indicator, a volatility filter, a news calendar. This EA watches something else entirely - the account's own equity curve - on the reasoning that whatever mix of strategies is running, if the account has started swinging harder than its own recent normal, something is off, and the right first response is to reduce size across the board rather than try to diagnose which strategy is at fault in real time. Equity is sampled every InpSampleIntervalSec and kept in a rolling window. The standard deviation of percentage equity changes over the recent InpLookbackSamples is compared against the same statistic over the longer InpBaselineSamples window - the account's own "normal". Once the ratio between them reaches InpSpikeMultiplier, the governor trips: it cuts InpReducePct of every matched open position's size, waits at least InpCooldownMinutes before it can trip again, and publishes a risk multiplier (0.1 to 1.0) to a terminal global variable that other EAs in this catalogue - or a trader's own dashboard - can read and act on cooperatively, without needing to be this EA's own position. InpDryRunAlertOnly lets the governor be observed - logging and alerting on every trip, and still publishing the risk multiplier - without it actually touching any position, useful for building confidence in the thresholds before letting it act live. Notes and limitations - Needs InpBaselineSamples worth of history before it can judge anything; until then it reports "collecting samples" and takes no action. - The equity sample buffer lives in memory only and resets on EA restart, so a freshly reloaded chart needs to rebuild its baseline from scratch. - Publishes three global variables - EquityVolatilityGovernor_RiskMultiplier, _Tripped and _LastUpdate - which any other EA on the same terminal can read; it does not itself consume any other EA's output. - Reduction is a plain partial close of each matched position by percentage, normalised to the symbol's lot step and skipped if the resulting cut or remainder would be smaller than the broker minimum lot. - This EA never opens a new position; it only reduces trades already open that match its filters, and it never resizes anything upward on its own.

Expert advisor · MT4 · v1.0 · Free

About Equity Volatility Governor

Equity Volatility Governor is a script for MetaTrader 4. It can alert you with a pop-up, sound, email or push message. It has 12 settings, such as Sample interval sec, Lookback samples and Baseline samples. MQL source code included.

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

Settings

SettingDefaultWhat it does
Sample interval sec60Seconds between equity samples
Lookback samples60Recent window used to measure current volatility
Baseline samples240Longer window used as the "normal" volatility reference
Spike multiplier2.0Recent/baseline stdev ratio that counts as a spike
Reduce pct50Percent of each matched position's lots cut when it trips
Cooldown minutes60Minimum minutes between successive reductions
Dry run alert onlyfalseTrue = log/alert only, never actually reduce positions
Magic filter-1Magic number filter (-1 = every magic)
Current symbol onlyfalseRestrict reduction to this chart's symbol
Slippage points30Slippage tolerance for a reduction close
Max retries5Attempts per action before giving up
Retry wait ms500Pause between attempts, milliseconds

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: News Trading · Alerts · MT4 Expert Advisor · MQL4 Source Code

Expert advisors (EA) for MT4 & MT5 · PolyMaria