Loading…

Swap Cost To Chosen Date

Estimating carry cost by multiplying the nightly swap figure by the number of calendar nights between now and a target date overstates the true cost, on a standard forex account, by two nights every single week. Brokers do not charge swap on Saturday and Sunday nights separately - they fold all three weekend nights (Friday, Saturday, Sunday) into one triple-sized charge on a single weekday, reported by the platform as the symbol's rollover-3-days property. A projection that skips this detail can be thirty or forty percent wrong over a month-long hold. This script reads that weekday directly from the terminal rather than assuming Wednesday, because not every broker uses Wednesday, and applies the triple multiplier only on the correct night while skipping Saturday and Sunday entirely. Symbols that genuinely trade and swap every day of the week - some crypto and index CFDs - can switch this off and have every night charged at the plain rate instead. The raw swap figure is also unit-aware. MT4 publishes swap in points, in money, or as an annual interest percentage depending on the symbol, and the three are not comparable without conversion. This script decodes the unit and turns whichever one applies into a plain money-per-night figure before doing any date arithmetic. Notes and limitations - Swap rates published by the broker can and do change without notice. This is a projection using today's published rate held constant, not a guarantee. - Base-currency and margin-currency swap types are used as-is, in the symbol's own currency. If that currency differs from the account currency, the total is approximate - the log says so when it applies. - The 360-day convention is used to annualise an interest-percent swap type, matching what most broker calculators use; a few use 365 instead, which moves the answer by less than half a percent. - Does not account for a position closing early, partial closes, or lot size changes mid-hold - it projects one fixed volume held to the target date. - MQL5 only: a symbol whose SYMBOL_SWAP_MODE is one of the two "reopen" modes has no plain per-night charge to project at all - the script says so explicitly rather than printing a number that does not mean anything for that symbol.

Script · MT5 · v1.0 · Free

About Swap Cost To Chosen Date

Swap Cost To Chosen Date is a script for MetaTrader 5. It can alert you with a pop-up, sound, email or push message. It has 5 settings, such as Symbol, Side and Volume. MQL source code included.

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

Settings

SettingDefaultWhat it does
SymbolSymbol ("" = this chart's symbol)
SideCarryBuyDirection to project
Volume1.0Volume, lots
Target date0Target date (0 = 30 calendar days from now)
Charge every nightfalseTrue for symbols that swap every night, no weekend fold-in

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: Volume · Alerts · MT5 Script · MQL5 Source Code

MQL4 & MQL5 scripts · PolyMaria