Negative Swap Rollover Guard
- Utilità
-
AL MOOSAWI ABDULLAH JAFFER BAQER
To trade successfully we need to go through the proven path that others had gone and reached!
Here are 17 quotes from such successful investors:
1- Limit your size in any position so that fear does not become the prevailing instinct guiding your judgment.
Joe Vidich - Versione: 1.0
- Attivazioni: 5
Run it free first: load Negative Swap Rollover Guard in the Strategy Tester with visual mode on. Its demo positions are held into the rollover on purpose, so you can watch the countdown run down, the check fire ten minutes before midnight, and the next morning's line that puts the estimated swap next to the swap the tester really booked.
SWAP IS THE COST YOU NEVER SEE COMING. THIS GUARD LOOKS AT IT BEFORE THE BROKER DOES.
Negative Swap Rollover Guard is a utility Expert Advisor for MetaTrader 5. It places no entries of its own on a real account. A few minutes before your broker's daily rollover it estimates the swap each open position is about to be charged, including the triple charge on the triple-swap day. When that cost is larger than you accept, it does what you chose: it warns you, it closes the position, or it closes the position only if it is still in profit after paying that swap.
In short
• One check per rollover, at a server time you set (default 23:50 for a 00:00 rollover).
• Triple-swap weekday input (Wednesday by default), checked on the panel against the day your broker sets for the chart symbol.
• Two threshold rules: a cost in account currency, and a cost as a percent of the position's current profit. Use one, or either, or both together.
• Three modes: 0 alert only, 1 close, 2 close only if still in profit after the swap.
• Filters: all symbols or the chart symbol, any magic, manual trades only, or one magic number.
• After every rollover it compares its estimate with the swap that was really booked, so you can see how close it is with your broker.
• Not a grid, no martingale, no averaging, no DLLs, no web requests, no extra files.
START HERE
Attach it to one chart, for example EURUSD H1. One copy watches all symbols of the account by default. Look up your broker's rollover time in server time and enter it, together with a check time a few minutes before it. Start with mode 0 (alert only) for a week. Each evening the panel lists every position with its estimated swap and marks the ones over your threshold. When the alerts match what you would have done yourself, switch to mode 2 or mode 1 and turn on Algo Trading.
Why a rollover guard
Swap is easy to forget. One night costs little, so it does not feel like a decision. But a position held against the carry pays it every night, three times on the triple day, and on metals, indices and exotic pairs the rate can eat a week of small gains. The usual reason it keeps being paid is not a plan, it is that nobody looked at the clock. This guard looks at the clock for you, every day, and asks one question: is keeping this position over the rollover worth what it will cost tonight?
What one evening looks like
All day. The panel counts down to the next check and keeps a live estimate for every position: tonight's swap, whether tonight is the triple day, and which positions are already over your threshold.
Check time. At your check time the guard looks at every position in scope once. A position over the threshold is handled by your mode. It is handled once per rollover, so you do not get a stream of repeated alerts.
Mode 2 in practice. A winner that would give back too much to swap is closed and keeps its profit. A loser stays open, because closing it would turn a floating loss into a booked one only to save a night's swap; you get a message instead and decide yourself.
After the rollover. Two minutes after the rollover the guard reads the swap the broker really booked on each position it estimated and prints both numbers. The panel adds them up under ESTIMATE CHECK.
How the estimate is made
It uses only what your terminal reports for the symbol: the long and short swap rates and the swap mode. Points, money per lot in base, margin, profit or deposit currency, and the two interest modes are all converted into the account currency through the symbol's tick value. On the triple day the night is counted three times. A symbol with no trading session on the check day, usually a weekend, has no rollover that night and shows NO ROLLOVER. The two reopen swap modes move the price instead of charging money, so those positions show REOPEN MODE and are never acted on.
In our Strategy Tester runs the estimate matched the booked swap on every position-night: EURUSD 15 nights, estimated -116.30, booked -116.30; XAUUSD 4 nights, -144.20 and -144.20; and two more EURUSD runs with 23 and 7 nights, equal to the cent. That is the tester using one broker's symbol settings. A real broker can apply its own markups, holiday schedules or a different triple day, and the estimate cannot know that in advance. That is exactly why the comparison is on the panel.
Inputs, every one explained
ROLLOVER
InpCheckTime = 23:50. Server time of the daily check, HH:MM. It must be between 1 minute and 12 hours before the rollover.
InpRolloverTime = 00:00. Your broker's rollover in server time. Most brokers use midnight server time; ask yours if unsure.
InpTripleDay = Wednesday. Weekday of the check on which the swap is counted three times. The panel row BROKER 3X DAY shows the day your broker reports for the chart symbol and says whether it matches.
THRESHOLD
InpMaxSwapMoney = 5.0. A position whose estimated swap cost tonight is this amount or more in account currency is over the limit. 0 turns this rule off.
InpMaxSwapPct = 25. A position whose swap cost tonight is this percent of its current profit (profit plus swap so far) or more is over the limit. A position with no profit counts as over this rule, because any cost is more than all of nothing. 0 turns this rule off.
InpRuleLogic = Either rule is enough. Both rules must be passed asks for both at once. With one rule off, only the other counts. At least one rule must be on.
InpMode = 2, close only if in profit after the swap cost. 0 alerts only and changes nothing. 1 closes every position over the threshold. 2 closes it only when its profit is larger than tonight's swap; otherwise it is kept and reported.
EXECUTION
InpSlippagePoints = 30. Maximum slippage accepted on a close.
InpFailAlertAt = 3. A refused close is retried with a growing pause up to two minutes, until the rollover. After this many failures on one position you get one alert. If the broker refuses the filling mode, the next allowed mode is tried at once.
FILTER - WHICH POSITIONS ARE CHECKED
InpSymbolScope = All symbols. Chart symbol only checks the chart symbol alone.
InpMagicFilter = Any magic. Only manual trades means magic 0. Only the magic number limits the guard to one Expert Advisor.
InpMagic = 0. The number for that last choice.
ALERTS
InpAlertPopup = true. Pop-up alert in the terminal.
InpAlertPush = false. Push notification to the MetaTrader app on your phone, which must be enabled in the terminal options.
PANEL
ShowPanel = true. Show or hide the panel. The guard works either way.
PanelX = 12, PanelY = 15. Offset from the top left corner. The MOVE button lets you drag it.
PanelFontSize = 9. Base font size.
MaxTableRows = 5, MaxHistoryRows = 4. Rows in the position table and the action history. On a short chart the panel drops its least important rows first.
STRATEGY TESTER DEMO
InpTesterDemo = true. In the Strategy Tester only: on weekday evenings one position on the chart symbol, on the side with the more expensive swap (every third day the other side, to show a credit), sized at up to 1 lot within 30 percent of free margin and checked for margin times 1.5. It is held over the rollover unless the guard closes it, and closed after 30 hours. No new demo position after a 20 percent balance loss. This code never runs on a real or demo account chart.
The panel
NEXT ROLLOVER shows the countdown to the check and a bar that fills over the day, with x3 on the triple day. SWAP PLAN (ESTIMATES) lists the next check, the triple-swap flag, the estimated swap total for all positions in scope, how many are at risk and their cost, the last action, the mode, Algo Trading on or off, the broker's triple day compared with yours, your threshold, the estimate check, failed sends, totals, the rollover time and the positions in scope. POSITIONS, COSTLIEST FIRST shows symbol, side, lots, profit, tonight's estimated swap, a state, and that position's share of the total cost at risk. States are OK, UNDER LIMIT, NO SWAP, CREDIT, AT RISK, HANDLED, NO ROLLOVER, REOPEN MODE, NO DATA, MARKET SHUT, TRADE OFF and RETRY. ACTION HISTORY keeps checks, alerts, closes and kept positions with server time. QUICK CONTROLS: ARMED or PAUSED, a mode button that cycles the three modes, and CHECK NOW, which runs the check-time action once by hand on what is over the threshold now. The right side of the chart stays clear.
What it cannot do
Every swap figure is an estimate built from the symbol settings your terminal reports. Brokers can charge differently, change rates without notice, skip or double days around holidays, or use another triple day. Compare ESTIMATE CHECK after a few nights before you trust it with closes.
Closing is real. A close books the current profit or loss and pays spread and commission. Mode 1 can close a losing position to save a night's swap, which can cost far more than the swap. Mode 2 exists for that reason.
It only works while it runs. With the terminal off, Algo Trading off, the market already closed at your check time, or a disabled symbol, nothing is sent. Pick a check time inside trading hours, and keep the terminal running, for example on a VPS.
Its memory is short. History and totals live in memory and reset on restart; only "already handled tonight" is kept per position across a restart.
What was and was not tested
Tested in the Strategy Tester on a hedging account, EURUSD H1 and XAUUSD H1, 1 to 20 June 2026, deposit 10000, leverage 100: modes 0, 1 and 2, the triple day, kept losers in mode 2, credits, weekend nights without rollover, and the estimate against the booked swap. No send failed and no journal error appeared. On a live demo chart the panel was seen on a Sunday with four positions showing NO ROLLOVER.
Not tested at the time of writing: a real close on a live or demo broker at rollover, a netting account, retries after a broker refusal, a filling mode refusal, the interest and currency swap modes on a real symbol, chart symbol scope, magic filters, pop-up and push alerts, the panel buttons and a terminal restart. These paths exist in the code and are described by design. Please try them on a demo account with your own broker first.
Try it in the Strategy Tester
Choose Negative Swap Rollover Guard, EURUSD or XAUUSD, H1, a deposit of a few thousand, visual mode, and press Start. Fast-forward to 23:50 on a Wednesday and watch the triple-swap check, then read the next morning's estimate line in the journal.
If the guard saved you a few nights of swap, or you think it should handle something better, an honest review on the product page helps other traders decide and tells me what to improve next.
