# OrderCalcMargin price parameter

1490

The OrderCalcMargin function returns required margin for opening a position.

While the volume and type of order are understandable (sell or buy may have different margin requirements?), why is the open price needed and how does it affect the margin required.

Edit: Thinking about it,maybe to calculate the margin requires the rate while opening the trade in order to know how much is the position volume to open in account currency. And also for pending orders.

Thanks

42232

Amir Yacoby:

The OrderCalcMargin function returns required margin for opening a position.

While the volume and type of order are understandable (sell or buy may have different margin requirements?), why is the open price needed and how does it affect the margin required.

Edit: Thinking about it,maybe to calculate the margin requires the rate while opening the trade in order to know how much is the position volume to open in account currency. And also for pending orders.

Thanks

Yes, margin is in account currency, so depending of the symbol, the price may matters to calculate it.

If your account is in USD, and you trade USDCAD, margin is fixed, but if you trade EURUSD a conversion is needed which depends of EURUSD quotation.

42232

I created a little script to check :

```void OnStart()
{
//---
MqlTick tick;
if(!SymbolInfoTick(_Symbol,tick)) return;
double lowerlimit=tick.bid-500*_Point;
double upperlimit=tick.bid+500*_Point;

for(int t=0;t<ArraySize(types);t++)
{
double margin;

for(double price=lowerlimit;price<upperlimit;price+=10*_Point)
{
string msg=StringFormat("Type: %s Symbol: %s Volume: 1.0 Price: %f",EnumToString(types[t]),_Symbol,price);

if(OrderCalcMargin(types[t],_Symbol,1.0,price,margin))
printf("Margin %.2f. %s",margin,msg);
else
printf("Margin can't be calculated, error %i. %s",GetLastError(),msg);
}
}
}
```
1490

Alain Verleyen:

I created a little script to check :

Thank you Alain for your effort.
In my case account currency is USD and I ran the script on EURNZD I get both buy and sell order types the same margin for all open prices.

42232

Amir Yacoby:

Thank you Alain for your effort.
In my case account currency is USD and I ran the script on EURNZD I get both buy and sell order types the same margin for all open prices.

Yes as the margin in USD doesn't depend of EURNZD price, but only of EURUSD. So, at a given moment, same margin for all open prices, but different margin at different times.
1490

Alain Verleyen:
Yes as the margin in USD doesn't depend of EURNZD price, but only of EURUSD. So, at a given moment, same margin for all open prices, but different margin at different times.

So, to my initial question, why should we supply the open price of EURNZD if what matters is the price of EURUSD on time of execution?

Edit: the standard case I guess is I want to check how much of margin I will need to open a EURNZD position. It does not depend on EURNZD price as you say, and the EURUSD price is known so it's silly to ask it from me, and in case of future pending order on EURNZD, I can't predict the EURUSD price.. So, I am left without an answer.

42232

Amir Yacoby:

So, to my initial question, why should we supply the open price of EURNZD if what matters is the price of EURUSD on time of execution?

Edit: the standard case I guess is I want to check how much of margin I will need to open a EURNZD position. It does not depend on EURNZD price as you say, and the EURUSD price is known so it's silly to ask it from me, and in case of future pending order on EURNZD, I can't predict the EURUSD price.. So, I am left without an answer.

It's a generic function, so seems normal to me to have a price as parameter (which will not always be used).

Example USD account, 3 cases :

1. USDxxx doesn't need a price (margin is directly in USD).
2. xxxyyy (no USD implied), doesn't use a price but only xxxUSD (or USDxxx), seems the current market watch price is used, which is in contradiction to case 3 below.
3. xxxUSD, need the price to be able to convert xxx margin in USD, and you need to provide it as it's not necessarily current price.
But I agree with you it's not clear, as case 2 should also depends of cross price which is not the current price but is unknown. Either it's a bug or a feature.
1490

Alain Verleyen:

It's a generic function, so seems normal to me to have a price as parameter (which will not always be used).

Example USD account, 3 cases :

1. USDxxx doesn't need a price (margin is directly in USD).
2. xxxyyy (no USD implied), doesn't use a price but only xxxUSD (or USDxxx), seems the current market watch price is used, which is in contradiction to case 3 below.
3. xxxUSD, need the price to be able to convert xxx margin in USD, and you need to provide it as it's not necessarily current price.
But I agree with you it's not clear, as case 2 should also depends of cross price which is not the current price. Either it's a bug or a feature.
Ok, that's the answer. I wouldn't guess.
It started off by me trying to find out how to calculate the margin without the function, so now I am not sure about case 2.

Thank you.