Loading…

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

SettingDefaultWhat it does
Magic filter-1Only watch this magic for the day's result, -1 = every closed trade
Day reset hour0Server hour a new trading day begins (0-23)
Auto flatten on first losstrueClose every open position the instant the first loss is detected
Enforce stop by closing new tradestrueAfter stopped, immediately close any new position opened
Enforce all magicstrueEnforcement applies to every magic/manual trade, not just InpMagicFilter
Alert on stoptruePopup Alert() the moment the day is stopped

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

Expert advisors (EA) for MT4 & MT5 · PolyMaria