Loading…

Post Flat Recovery Sequencer

Whatever caused an account to go flat - a kill switch, a broker fault, a news shock, an equity plunge - may still be settling in the minutes right after. Letting every strategy pile back into the market at once, the instant positions hit zero, treats "flat" as a clean reset when it is usually the middle of an event, not the end of one. This sequencer does not place a single trade itself. It publishes a staged permission convention - a GlobalVariable per magic number, RECOVERY_STAGE_MAGIC_<n>, holding 0 while blocked or a permitted lot multiplier once enabled - and expects the account's own trading EAs to check it before opening. A user-defined plan assigns each magic number to a risk stage; stage 1 (lowest risk) is re-enabled immediately, later stages only after a configurable delay, and only if nothing has flattened the account again in the meantime and, optionally, only once equity has recovered to a configured fraction of balance. Detection is dual-channel: an observed drop from having open orders to zero triggers the sequence on its own, and it also watches the same KILLSWITCH_ACTIVE GlobalVariable name published by this catalogue's KillSwitchProtocol convention (mirrored locally, not included as source, per the house rule that every submission stands alone) for a 1 -> 0 clear. Either channel restarts the whole sequence from stage 1 if it fires while an earlier sequence is still in progress - a second flatten mid-recovery means the account is not actually stable yet. Notes and limitations - This EA never trades on its own - the staged permission only works if the strategies sharing those magic numbers are written to check the published GlobalVariable before opening. - A malformed InpStagePlan entry is skipped and logged rather than aborting the whole plan. - The equity gate compares current equity to current balance, not to the balance at the moment the flatten happened - a later deposit or withdrawal changes the comparison. - Restarting the terminal or the EA loses the in-progress sequence timer; it re-seeds from the current open-order count and switch state on OnInit rather than assuming a fresh flatten just occurred.

Expert advisor · MT5 · v1.0 · Free

About Post Flat Recovery Sequencer

Post Flat Recovery Sequencer 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 Stage plan, Stage delay minutes and Use flatten detection. MQL source code included.

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

Settings

SettingDefaultWhat it does
Stage plan1001:1:0.5,1002:2:0.75,1003:3:1.0magic:stage:sizeMultiplier list, stage 1 = lowest risk, re-enabled first
Stage delay minutes15Minutes between enabling one stage and the next
Use flatten detectiontrueTreat "open positions count dropped to zero" as a flatten trigger
Use kill switch gvtrueAlso watch the KILLSWITCH_ACTIVE GlobalVariable for a 1 -> 0 clear
Require equity above balance pct0.00 = no check; else stage advance pauses unless equity >= balance * this% /100
Timer interval sec15How often the sequence is evaluated
Dry runfalsetrue = log stage transitions only, never publishes permission GVs

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

Expert advisors (EA) for MT4 & MT5 · PolyMaria