Loading…

Spread Guard

Spread widens around news, at session opens and closes, and during thin liquidity, and entering a position through a wide spread pays that cost the instant the order fills. This EA watches the chart symbol's spread every tick and reports plainly whether it is past a threshold you set, so a manual trader or another EA's entry logic can check before sending an order. It deliberately never closes anything, and that is not an oversight. A wide spread makes entering expensive, but forcing an exit through that same wide spread locks the extra cost in immediately and permanently, whereas simply waiting usually lets the spread normalise before the position needs to leave anyway on its own terms. Guarding entries and guarding exits are different problems with different correct answers; bolting an exit rule onto an entry guard is exactly how a tool meant to be defensive ends up being the thing that costs the account money. The threshold is entered in pips, because that is how traders think about spread, and converted to points per-symbol from the broker's own digit count - never a hardcoded multiplier of ten - because that conversion is correctly ten only on a 3 or 5 digit quote and one everywhere else. The spread reading itself, MODE_SPREAD, is already reported in points by the broker and needs no conversion; only the typed threshold does. Notes and limitations - This EA never places or closes an order. It is a reporting tool only - a manual trader has to check the Comment before clicking, and another EA would need to read its own MODE_SPREAD the same way this one does, since no shared signal is written to disk or a global variable. - Watches one symbol: the chart it is attached to. Attach a separate instance per symbol you want covered. - Spread can change between any two ticks - a broker widening around a data release does not wait for a new bar - so the read-and-compare runs every tick. Only the repeated journal logging is throttled by InpStatusLogSeconds, and even that always fires, so you can calibrate the threshold against what the symbol actually does over a session. - MODE_SPREAD reflects the broker's own quoted spread. On an account with variable/floating spread this figure moves constantly by design, not due to any fault in the guard.

Expert advisor · MT5 · v1.0 · Free

About Spread Guard

Spread Guard is a script for MetaTrader 5. It can alert you with a pop-up, sound, email or push message. It has 2 settings, such as Max spread pips and Status log seconds. MQL source code included.

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

Settings

SettingDefaultWhat it does
Max spread pips3.0Spread threshold that blocks new orders, in pips
Status log seconds60How often the spread reading repeats in the journal

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

Expert advisors (EA) for MT4 & MT5 · PolyMaria