Loading…

Rollover Avoidance Manager

Most brokers widen the spread and charge overnight swap in a short window around their daily rollover, and charge triple swap on one specific day to account for the weekend. MQL4 has no function that returns this window - it is broker-specific and sometimes symbol-specific - so this EA takes it as an explicit input rather than guessing, and the trader is expected to fill it in from their own broker's specification. RISK WARNING: with InpFlattenBeforeRollover on, this EA closes live positions automatically ahead of the window you configure. Confirm the window against your broker's actual server-time schedule on a demo account before relying on it live - a wrong window either does nothing useful or closes positions at the wrong time. Two things happen around the window, independently of each other. First, if InpFlattenBeforeRollover is on, matching positions are closed a configurable number of minutes before the window opens - optionally restricted to just the triple-swap day, for a trader who is happy to carry normal daily swap but not the triple charge. Second, the EA snapshots OrderSwap() on every matching position the instant the window opens, and reports the delta per ticket when the window closes - a real record of what was charged that trade, rather than trusting the broker's published schedule sheet, which is not always precisely what shows up on the statement. Both the rollover window itself and the pre-flatten lead window are allowed to cross midnight, since a window starting at 23:55 with a 15 minute length ends at 00:10 the next calendar day - a case that trips up a naive "start < end" comparison. Notes and limitations - The rollover window is exactly what you configure, not something the EA detects - an incorrect window silently does the wrong thing at the wrong time. Verify it on a demo account first. - The swap report only covers positions that were open and matched the filter at the moment the window opened; a position opened mid-window has no snapshot to compare against and is not reported. - The flatten runs at most once per calendar day even if the lead window is re-entered, so a position reopened right after being flattened is not closed again the same day - it gets a fresh check the following day.

Expert advisor · MT5 · v1.0 · Free

About Rollover Avoidance Manager

Rollover Avoidance Manager is an expert advisor (trading robot) for MetaTrader 5. It trades only in the hours you set (time filter). It has 13 settings, such as Rollover start hour, Rollover start minute and Rollover window minutes. MQL source code included.

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

Trading robots can lose money. Check every setting and test on a demo account before using real funds.

Settings

SettingDefaultWhat it does
Rollover start hour23Server-time hour the rollover window starts
Rollover start minute55Server-time minute the rollover window starts
Rollover window minutes15Length of the rollover window, minutes
Flatten before rolloverfalseClose matching positions before the window opens
Flatten lead minutes5How long before the window to close, minutes
Triple swap day onlyfalseOnly flatten on InpTripleSwapDayOfWeek, not every day
Triple swap day of week3Day the broker charges triple swap (0=Sun..6=Sat), used only if above is true
Magic filter0Only manage this magic number, 0 = all
Symbol onlyfalseOnly manage positions on this chart's own symbol
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 5 open File → Open Data Folder, then go to MQL5 → Experts.
  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 expert advisor from the Navigator onto a chart, check the settings, allow Algo/Auto Trading and press OK.
  6. Test it first on a demo account or in the Strategy Tester.

Download the PDF guide

Tags: Time Filter · MT5 Expert Advisor · MQL5 Source Code

Expert advisors (EA) for MT4 & MT5 · PolyMaria