Loading…

Weekend Position Closer

A weekend gap can move price through a stop-loss without a fill anywhere near it - the market is simply closed while the news that caused the gap happens. The only way to be certain a position is not exposed to that risk is to not hold it over the weekend, and remembering to do that by hand every Friday is exactly the kind of task that gets forgotten on the one week it mattered. RISK WARNING: this EA closes live positions automatically once its window opens. Test the day-of-week and time inputs against your broker's own server time before relying on it, and confirm on a demo account first that the window lines up with when you actually want to be flat. The close condition is a window, not an instant - true for the whole chosen day from the chosen time onward, not just the first moment it is reached. The scan re-runs on every timer tick while the window holds, so a position opened by hand after the first pass is still caught on the next one, and nothing needs to be "undone" if the terminal restarts mid-window. Both closing and deleting collect every matching ticket first, then act on the list - the position and order pools re-index the instant a ticket leaves them, so acting while iterating by position risks silently skipping whichever one shifted into the slot just vacated. Notes and limitations - Server time is the broker's own clock, not the trader's local time or a fixed market-close time - confirm the default window actually lines up with your broker before relying on it live. - If automated trading is switched off when the window opens, the EA reports this plainly in the chart comment and keeps checking; it cannot close anything until AutoTrading is re-enabled. - This EA only closes and deletes. It never opens a new order and never modifies a stop-loss or take-profit. - On an MQL5 netting account, InpMagicFilter selects or excludes an entire symbol's net position, not individual trades within it - see MQL4 VERSUS MQL5 DIFFERENCES above.

Expert advisor · MT4 · v1.0 · Free

About Weekend Position Closer

Weekend Position Closer is a script for MetaTrader 4. It can alert you with a pop-up, sound, email or push message. It has 10 settings, such as Close day of week, Close hour and Close minute. MQL source code included.

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

Settings

SettingDefaultWhat it does
Close day of week5Day to flatten (0=Sun 1=Mon 2=Tue 3=Wed 4=Thu 5=Fri 6=Sat), server time
Close hour21Server-time hour the close window opens (0-23)
Close minute0Server-time minute the close window opens (0-59)
Magic filter0Only close this magic number, 0 = all
Symbol onlyfalseOnly close positions on this chart's own symbol
Close pending orderstrueAlso delete matching pending orders in the window
Slippage pips5Slippage tolerance when closing, in pips
Max retries5Attempts per order before giving up
Retry wait ms500Pause between attempts, milliseconds
Scan interval sec15Seconds between checks

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

Expert advisors (EA) for MT4 & MT5 · PolyMaria