First Loss Day Stop Rule
"Stop trading for the day after the first loss" is a well-known discipline rule that is hard to actually keep in the moment - the temptation to take one more trade to win it back is exactly what the rule exists to prevent, and by definition it has to survive contact with that temptation to be worth anything. This EA enforces it mechanically. It scans closed-trade history for the day's first result below zero (day boundary configurable by server hour, so it lines up with a broker's own daily reset rather than plain UTC midnight). The instant that first loss is detected it can flatten every open position immediately, and - because MQL4 has no way to intercept or refuse another program's OrderSend before it fills - it enforces the rest of the day by watching for any position that appears afterward and was not already open at the moment the stop triggered, and closing it straight back out. That enforcement can apply to every magic number and manual trade on the account, or just the ones this EA itself is tagged to watch, controlled by input. The stop clears automatically at the next day boundary. Notes and limitations - MQL4 cannot refuse or intercept another program's OrderSend before it fills. Enforcement here is genuinely after-the-fact: a new position is allowed to open for a brief moment and is then closed again, not prevented from opening at all. Slippage, spread, and commission on that immediate close-back-out are real costs, not zero-cost prevention. - The first-loss detection depends on this EA actually being attached and running; a loss that occurs while it is removed or the terminal is closed will only be caught (and the stop applied) once it next scans history, not at the instant it happened. - Enforcement only ever closes a position at market - it does not block pending orders from being placed, only positions after they fill (a pending order becoming a position is itself detected as a new ticket and closed the same way). - Day-boundary rollover uses server time from TimeCurrent(), which follows the broker's server, not the trader's local time zone.
Expert advisor · MT4 · v1.0 · Free
About First Loss Day Stop Rule
First Loss Day Stop Rule is a script for MetaTrader 4. It can alert you with a pop-up, sound, email or push message. It has 6 settings, such as Magic filter, Day reset hour and Auto flatten on first loss. MQL source code included.
Files in the download: FirstLossDayStopRule.ex4, FirstLossDayStopRule.mq4, FirstLossDayStopRule.txt.
Settings
| Setting | Default | What it does |
|---|---|---|
| Magic filter | -1 | Only watch this magic for the day's result, -1 = every closed trade |
| Day reset hour | 0 | Server hour a new trading day begins (0-23) |
| Auto flatten on first loss | true | Close every open position the instant the first loss is detected |
| Enforce stop by closing new trades | true | After stopped, immediately close any new position opened |
| Enforce all magics | true | Enforcement applies to every magic/manual trade, not just InpMagicFilter |
| Alert on stop | true | Popup Alert() the moment the day is stopped |
How to install
- Download the ZIP from your PolyMaria library and unzip it.
- In MetaTrader 4 open File → Open Data Folder, then go to MQL4 → Scripts.
- Copy the .mq4 file(s) there. Put any .mqh files in MQL4 → Include.
- Open the .mq4 file in MetaEditor and press Compile (F7) if MetaTrader does not show it.
- Drag the script onto a chart to run it once.
Tags: Alerts · MT4 Expert Advisor · MQL4 Source Code