See 'MarginCalculate'
and 'Точный подсчет, необходимых свободных средств для открытия
позиции.' (see post from komposter)
Was discussed here https://www.mql5.com/en/forum/45970
Dollars needed to trade a lot:
double lotsize=1.0; this is number of lots you want to trade 1,2,0.5 etc.
double dollars=MarketInfo(symbol,MODE_LOTSIZE)/AccountLeverage()*lotsize;
if(AccountCurrency()!=StringSubstr(symbol,0,StringLen(AccountCurrency()))
{
if(you want to buy)
dollars*=Ask;
if(you want to sell)
dollars*=Bid;
}
of course you may slip a couple of points so it's not exact.
double lotsize=1.0; this is number of lots you want to trade 1,2,0.5 etc.
double dollars=MarketInfo(symbol,MODE_LOTSIZE)/AccountLeverage()*lotsize;
if(AccountCurrency()!=StringSubstr(symbol,0,StringLen(AccountCurrency()))
{
if(you want to buy)
dollars*=Ask;
if(you want to sell)
dollars*=Bid;
}
of course you may slip a couple of points so it's not exact.
so in the above example, i would have: (for eurusd)
dollars =100000/100*1 =1000 dollars per lot. ok, if that is correct, then 1 lot would cost 1000 usdollars..
so I take the present Ask which is 1.2687 and multiply that times 1000 = 1268. 70 which is what I must have in dollars in order to purchase a 1 lot of eurusd. .. is that correct?
if so, and I am working in eurusd only, could I say ...
if (lots * 1000 * Ask) < accountfreemargin then i can buy (1 lot * 1000 *1.2687= 1268.70 margin required)
and
if(lots*1000*Bid) < accountfreemargin then i can sell (1 lot * 1000*1. 2685=1268. 50 required
or just to simplify the whole thing, take a little chance and go on ask only.
so
if(lots*1000*Ask) < accountfreemargin... do buy or sell
dollars =100000/100*1 =1000 dollars per lot. ok, if that is correct, then 1 lot would cost 1000 usdollars..
so I take the present Ask which is 1.2687 and multiply that times 1000 = 1268. 70 which is what I must have in dollars in order to purchase a 1 lot of eurusd. .. is that correct?
if so, and I am working in eurusd only, could I say ...
if (lots * 1000 * Ask) < accountfreemargin then i can buy (1 lot * 1000 *1.2687= 1268.70 margin required)
and
if(lots*1000*Bid) < accountfreemargin then i can sell (1 lot * 1000*1. 2685=1268. 50 required
or just to simplify the whole thing, take a little chance and go on ask only.
so
if(lots*1000*Ask) < accountfreemargin... do buy or sell
You can verify that,
just go ahead and buy one lot on demo account and compare this equation to a margin actually taken from the account. You will multiply by open price.
It is also better to use mq4 variables and setup a function for required margin calculation:
double MarginRequired(double lots); // returns dollars required
This way if somehow your borker changes leverage your calculation will still be correct, or you move your account to a new broker with different leverage.
just go ahead and buy one lot on demo account and compare this equation to a margin actually taken from the account. You will multiply by open price.
It is also better to use mq4 variables and setup a function for required margin calculation:
double MarginRequired(double lots); // returns dollars required
This way if somehow your borker changes leverage your calculation will still be correct, or you move your account to a new broker with different leverage.
You are missing trading opportunities:
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
Registration
Log in
You agree to website policy and terms of use
If you do not have an account, please register
where in usa I thought if you deposit was in usd, then your purchases would be in usd.. however I must be wrong... so should I multiply my 1000*Point*Lots to calculate the cost of each lot?