MT5 - swap monitor for single currency symbol

1
Here is a swap monitoring indicator for a single currency pair. The currency symbol input defaults to GBPJPY, but simply replace that with 0 to use the current chart symbol or any other symbol. In this way, the indicator can be attached to a custom chart while drawing data from the base chart symbol. There is a known bug that stalls the swap values at 0.00 if the indicator loads before MT5 loads sufficient data at startup. Removing the indicator and reattaching it is the only workaround I've found, and I've been unable to fix the bug. I've attached source code below, in case another coder can fix it. Otherwise, the indicator updates every minute (M1 bar close) regardless of the chart timeframe to which it is attached. This ensures that the swap values are accurate up to the minute whenever the broker-dealer updates swaps.
 
Note: The swaps in the image are from the generic Metaquotes MT5 demo. Note: The swaps in the image are from the generic Metaquotes MT5 demo.
“[A]s we know, there are known knowns—there are things we know we know. We also know there are known unknowns—that is to say we know there are some things we do not know. But there are also unknown unknowns—the ones we don’t know we don’t know.”—Donald Rumsfeld, 2002


Re: MT5 - swap monitor for single currency symbol

3
Here's version 2 of this indicator. Version 1 has a hard coded Print command for diagnostic purposes but it pollutes the Experts tab which can be a nuisance. New input, ExpertsTab, defaults to false in version 2. Set it to true if you want it continue printing.

“[A]s we know, there are known knowns—there are things we know we know. We also know there are known unknowns—that is to say we know there are some things we do not know. But there are also unknown unknowns—the ones we don’t know we don’t know.”—Donald Rumsfeld, 2002

Re: MT5 - swap monitor for single currency symbol

4
I found a bug in version 2 caused by the additional input. Fixed in version 3, attached.

I'm still on an obsessive-compulsive quest to validate MQL5 class data prior to loading which will kill that annoying zero value bug at startup...

“[A]s we know, there are known knowns—there are things we know we know. We also know there are known unknowns—that is to say we know there are some things we do not know. But there are also unknown unknowns—the ones we don’t know we don’t know.”—Donald Rumsfeld, 2002

Re: MT5 - swap monitor for single currency symbol

5
And... ah ha! MQL5 reference documentation revealed that MQL5 object pointers can only be used once in any coding project. Startup bug fixed in version 4, attached.

(I'll also fix the all-inclusive Market Watch symbols swap indicator when I have time).

“[A]s we know, there are known knowns—there are things we know we know. We also know there are known unknowns—that is to say we know there are some things we do not know. But there are also unknown unknowns—the ones we don’t know we don’t know.”—Donald Rumsfeld, 2002


Who is online

Users browsing this forum: CommonCrawl [Bot] and 5 guests