I came across an issue calculating the Margin Required for GBPUSD. MT4 says I need $26.42 to open 0.01 Lots, but when I open that position it uses $66.06.
I got in touch with Oanda, and they informed me that after Brexit the maximum leverage on GBPUSD for an account in the USA is 20:1, which would explain the margin difference.
That's all well and good, but if my Account Leverage is 50:1, how do I automatically determine if the leverage on a given pair is different in MQL4?
I can hard code this into my calculation now, but ideally it can be calculated automatically so I don't have to be kept abreast of any changes my broker or US regulators make.
Can anyone help me solve this one?
All the best,Fred
Your broker will have a list of the margin requirements. Basically the calculation goes like this : take how much you would like to trade in your account currency and convert it to the currency on the left hand side of the symbol, multiply that by the margin percent required, that is how much you'll have to tie up from your balance to hold the trade open. I don't know where you're seeing MT4 tell you how much you'll need to open a 0.01 lot trade, I'm assuming you have a custom indicator that isn't working.
0.01 lots = 1000 units.1000 GBP is currently 1320.48 USDmargin requirement of 5% aka 20:1 leverage1320.48 * 0.05 = 66.024 USD required for margin at the current GBPUSD exchange rate.
https://docs.mql4.com/constants/environment_state/marketinfoconstants has information on getting margin requirements from mql code, but it gives them to you in amounts for 1 lot traded. I've attached a script that pulls the relevant lines from the example for you. You'd just multiply the relevant number by your lot size to get the info you want.
Thank you for the reply. I understand the margin calculation very well. I also know my broker has a list of the margin requirements. What I am looking for is a way in MQL4 to determine the actual leverage for a pair.
Even the script you provided says $26.41 required, instead of the $66.06 it actually uses.
Is there something built into MQL4, like AccountLeverage(), that will give me the leverage for the pair?