DinexSpace Rollover Calendar Library
- librerie
- Versione: 1.0
DinexSpace Rollover Calendar Library is a library for MetaTrader 5 (MT5) that answers calendar questions about swap: how many nights of swap a position pays between two times, when the next rollover is, and which day counts three nights. It works from plain calendar rules, in server time, and reads no prices.
How it works
- Give two times and the day of the triple swap, and call DxRcNightsBetween. You get the number of nights a position pays if it opens at the first time and closes at the second.
- DxRcTripleDay reads the day of the triple swap of a symbol.
- DxRcNextRollover and DxRcPreviousRollover give the time of the next and of the previous rollover.
- DxRcNightsAhead adds up the nights of the next days.
What you get
- Nights between two times: the number of nights of swap from the moment a position opens to the moment it closes, over weekends and the triple-swap day.
- Triple-swap day: read from the symbol; Monday to Friday counts three nights on that day.
- Next and previous rollover: the time of each, and a flag that tells if a rollover happens at the end of a day.
- Checked in the Strategy Tester: the example EA opens and closes positions on symbols with a triple-swap day on each weekday and compares every charge of swap with the nights from the library, and the calendar with a separate calculation.
- Status codes with plain-English texts: bad day, bad range, bad time, unknown symbol.
- Light: pure calendar functions. No DLLs, no web requests, no Sleep. The library places no orders.
How to use it
- Copy DinexRolloverCalendar.ex5 to MQL5\Libraries.
- Add the import block with the functions you use (shown in the images and in the example EA).
- Call the functions with your times and the day of the triple swap.
The rule
- A rollover happens at the midnight that ends a weekday, Monday to Friday, in server time. Saturday and Sunday have none.
- It counts one night, and three nights on the triple-swap day of the symbol (Monday to Friday).
- A position is charged for the rollovers after it opened, up to and including the moment it closes.
- Dates are worked out from the number of days since 1970-01-01, so the answer does not depend on the time zone of the computer.
Example EA (included in the description images)
At start the example compares every function with a separate calculation for many times and for every triple-swap day. In the Strategy Tester it opens a buy and a sell on each symbol of a list, holds them for varied times and compares each charge of swap, and the whole swap of each position when it closes, with the nights from the library. It prints the number of checks and the number of failed checks.
Notes
- The rule is the one the Strategy Tester applies. A real broker can use another rollover time or count the weekend differently: check it for your broker before you rely on it.
- Symbols that trade on Saturday or Sunday are not covered by the rule. DxRcWeekendSeconds tells how many seconds of weekend trading a symbol has (a few minutes to an hour on Sunday evening is normal).
- The library gives numbers of nights and times. It does not give the amount of money, gives no entries or exits and does not predict any move.
Requirements
- MetaTrader 5, any symbol and timeframe.
