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
| Setting | Default | What it does |
|---|---|---|
| Stage plan | 1001:1:0.5,1002:2:0.75,1003:3:1.0 | magic:stage:sizeMultiplier list, stage 1 = lowest risk, re-enabled first |
| Stage delay minutes | 15 | Minutes between enabling one stage and the next |
| Use flatten detection | true | Treat "open positions count dropped to zero" as a flatten trigger |
| Use kill switch gv | true | Also watch the KILLSWITCH_ACTIVE GlobalVariable for a 1 -> 0 clear |
| Require equity above balance pct | 0.0 | 0 = no check; else stage advance pauses unless equity >= balance * this% /100 |
| Timer interval sec | 15 | How often the sequence is evaluated |
| Dry run | false | true = log stage transitions only, never publishes permission GVs |
How to install
- Download the ZIP from your PolyMaria library and unzip it.
- In MetaTrader 5 open File → Open Data Folder, then go to MQL5 → Scripts.
- Copy the .mq5 file(s) there. Put any .mqh files in MQL5 → Include.
- Open the .mq5 file in MetaEditor and press Compile (F7) if MetaTrader does not show it.
- Drag the script onto a chart to run it once.
Tags: News Trading · Alerts · MT5 Expert Advisor · MQL5 Source Code