MQL5 Tutorial – How To unvover hidden Swap Fees with MQL5

You might have noticed that sometimes your profit isn’t quite exact, and the reason might be that you don’t consider swap to be relevant.
You might maybe not even see any swap here but this is going to change.
If you do a right click here and select columns, you can enable the swap column. And now you see it.
These are only a few cents but it can add up over time and now it would be a few dollars.
Swap fees are charged when you hold a position overnight and it can quickly eat up all your profit.
It can be positive or it can be negative and it is different for every currency pair.
To find out how many swap fees you have to pay we will create a simple little Expert Advisor.
To do that please click the little button over here or hit the F4 key in the MetaTrader and that will bring up the MetaEditor.
Let’s select new Expert Advisor from template, continue. Give it a name, click on continue and finish.
Let’s remove everything above the On Tick function and the two comment lines and now we need a double variable for swap long trades.
And it will use the SymbolInfoDouble function for the current symbol to get the value of symbol_swap_long.
And for the swap fees you have to pay for short trades, we will do the same and use SymbolInfoDouble for the current symbol and this time we will use symbol_swap_short.
Let’s use the comment function to get the output right on the chart.
Let’s compile the Expert Advisor and it says no errors and no warnings.
Click this button or hit the F4 key to bring up Meta Trader, go to the Strategy Tester and select the simple account info.ex5 file.
Make sure to enable visualisation here, and now start the test. And here is our output.
You see that the swap fee, the negative value, is much higher than the positive value.
Let’s check it for another current pair, this time we are going to use Euro US dollar and for this currency pair there isn’t any positive value.
That means you will be charged a swap fee, no matter if you open a long or a short trade.
And this is something almost nobody knows, but with this little Expert Advisor you are now able to find out if your broker is charging for swap, and in which currency pairs you cannot make a swap gain.
And that might help you to avoid unnecessary swap costs.

Download “MQL5 Simple Account Info Expert Advisor from MQL5 Tutorial” SimpleAccountInfo.txt – Downloaded 33 times – 363 B