OrderCalcMargin price parameter

To add comments, please log in or register
Amir Yacoby
1219
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

Alain Verleyen
36044
Alain Verleyen  
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.

Alain Verleyen
36044
Alain Verleyen  

I created a little script to check :

void OnStart()
  {
//---
   ENUM_ORDER_TYPE types[]={ORDER_TYPE_BUY,ORDER_TYPE_SELL};
                          //,ORDER_TYPE_BUY_LIMIT,ORDER_TYPE_SELL_LIMIT,ORDER_TYPE_BUY_STOP,
                           ORDER_TYPE_SELL_STOP,ORDER_TYPE_BUY_STOP_LIMIT,ORDER_TYPE_SELL_STOP_LIMIT,ORDER_TYPE_CLOSE_BY};
   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);
        }
     }
  }
Amir Yacoby
1219
Amir Yacoby  
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.

Alain Verleyen
36044
Alain Verleyen  
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.
Amir Yacoby
1219
Amir Yacoby  
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.

Alain Verleyen
36044
Alain Verleyen  
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.
Amir Yacoby
1219
Amir Yacoby  
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.
To add comments, please log in or register