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
| Setting | Default | What it does |
|---|---|---|
| Close day of week | 5 | Day to flatten (0=Sun 1=Mon 2=Tue 3=Wed 4=Thu 5=Fri 6=Sat), server time |
| Close hour | 21 | Server-time hour the close window opens (0-23) |
| Close minute | 0 | Server-time minute the close window opens (0-59) |
| Magic filter | 0 | Only close this magic number, 0 = all |
| Symbol only | false | Only close positions on this chart's own symbol |
| Close pending orders | true | Also delete matching pending orders in the window |
| Slippage pips | 5 | Slippage tolerance when closing, in pips |
| Max retries | 5 | Attempts per order before giving up |
| Retry wait ms | 500 | Pause between attempts, milliseconds |
| Scan interval sec | 15 | Seconds between checks |
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: News Trading · Pending Orders · Alerts · MT4 Expert Advisor · MQL4 Source Code