Loading…

Revenge Trade Blocker

A revenge trade has a recognisable shape: it appears shortly after a loss, and it is either bigger than the trade that just lost, or fired straight back in the opposite direction to "get it back". Neither trait alone proves tilt, but together, inside a short cooldown window after a loss, they are the pattern that quietly wrecks otherwise disciplined accounts. This EA watches its chart's symbol for exactly that pattern. It tracks the most recent closed losing trade in its magic/symbol scope and, on every tick, checks every open position against it: if the position opened after the loss and within the configured cooldown window, and its lot size is at least a configurable multiple of the losing trade's size, or its direction is the opposite of the losing trade's, it is flagged and closed. It cannot prevent the trade from being placed - nothing running alongside another program or a manual click in the same terminal can reach into that OrderSend call - so the protection is reactive: the position is allowed to exist for the time it takes this EA's next tick to notice it, then it is closed at market and the reason is written to the journal and raised as an alert. The cooldown window is measured from the OPEN time of the new position against the CLOSE time of the loss, not the current clock, so a position that was already inside the window when the EA was attached is still caught correctly. A dry-run mode is included: with it on, the EA alerts on everything it would have closed but closes nothing, which is the recommended way to first observe how the rule fires against a trader's own real habits before switching on enforcement. Notes and limitations This only sees trades on the symbol of the chart it is attached to, and only within its magic filter - it does not aggregate across symbols or the whole account. A legitimate, planned re-entry that happens to be larger or opposite in direction within the cooldown window will also be closed; the EA has no way to distinguish deliberate strategy from tilt, only the statistical shape both can share. Widen the cooldown or the size multiplier, or narrow the magic filter, if a specific strategy trips this EA on legitimate signals.

Expert advisor · MT4 · v1.0 · Free

About Revenge Trade Blocker

Revenge Trade Blocker is a script for MetaTrader 4. It can alert you with a pop-up, sound, email or push message. It has 7 settings, such as Cooldown minutes, Size multiplier threshold and Block reversal. MQL source code included.

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

Settings

SettingDefaultWhat it does
Cooldown minutes30Minutes after a loss during which a new entry is scrutinised
Size multiplier threshold1.5Flag if the new lot size is at least this many times the losing trade's size
Block reversaltrueAlso flag an entry in the opposite direction of the losing trade
Magic filter-1Magic number filter, -1 = every magic number on this symbol
Dry runfalsetrue = alert only, never closes - use to observe before enforcing
Max retries5Attempts per close 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: Risk & Lot Size · Alerts · MT4 Expert Advisor · MQL4 Source Code

Expert advisors (EA) for MT4 & MT5 · PolyMaria