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.
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.
I created a little script to check :
string msg=StringFormat("Type: %s Symbol: %s Volume: 1.0 Price: %f",EnumToString(types[t]),_Symbol,price);
printf("Margin %.2f. %s",margin,msg);
printf("Margin can't be calculated, error %i. %s",GetLastError(),msg);
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.
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 :