Role Order Type Parameter in OrderCalcMargin

 

Hi,

I'm wondering about the role of the order type parameter in the function OrderCalcMargin (FOREX mode).

Please see the following script:

void OnStart() {
  const double vol    = 1.00;
  const double price  = SymbolInfoDouble(Symbol(),SYMBOL_BID);
  ENUM_ORDER_TYPE type;
  double margin;
  // first try with ORDER_TYPE_BUY
  type = ORDER_TYPE_BUY;
  if (!OrderCalcMargin (type, Symbol(), vol, price, margin)) {
    PrintFormat ("%s ERROR", EnumToString (type));
  } else {
    PrintFormat ("%20s vol = %8.2f price = %8.3f Margin = %8.2f", EnumToString (type), vol,price,margin);
  }
  // second try with ORDER_TYPE_SELL
  type = ORDER_TYPE_SELL;
  if (!OrderCalcMargin (type, Symbol(), vol, price, margin)) {
    PrintFormat ("%s ERROR", EnumToString (type));
  } else 

    PrintFormat ("%20s vol = %8.2f price = %8.3f Margin = %8.2f", EnumToString (type), vol,price,margin);
  }
}

If I run this script on a broker with hedging account (here RoboForex, leverage 500) I get the following output (for USDJPY):

2025.04.29 11:10:08.702 RoleOfOrderType (USDJPY,H4)           ORDER_TYPE_BUY vol =     1.00 price =  142.647 Margin =   200.00
2025.04.29 11:10:08.702 RoleOfOrderType (USDJPY,H4)          ORDER_TYPE_SELL vol =     1.00 price =  142.647 Margin =   200.00

Does that mean that the order type does not matter?

But if I run the script on a netting account (here  MetaQuotes-Demo, leverage 100) I get:

2025.04.29 11:12:06.464 RoleOfOrderType (USDJPY,H4)           ORDER_TYPE_BUY vol =     1.00 price =  142.640 Margin =  1000.00
2025.04.29 11:12:06.464 RoleOfOrderType (USDJPY,H4)          ORDER_TYPE_SELL vol =     1.00 price =  142.640 Margin =     0.00

You see margin 0.00 with ORDER_TYPE_SELL. Can someone explain this??

Thanks

Matthias

 

i got the margin for both


 
The function calculates the margin required for the specified order type, on thet,. in the current market environment not taking into account ...
Input parameters for indicators SMA, EMA, ATR  and trading  Spacebar clicker  operations are declared. Enums and constants for price movement and magic numbers ... SymbolInfoInteger. Returns a value of an integer type  long, date time, int or bool) of a specified symbol for the corresponding property. The function calculates the margin required for the specified order type, on the current account, in the current market environment not taking into account ...Calculates the margin required for the specified order type, in the deposit currency. Order Calc Profit. Calculates the profit based on the ...
Spacebar Clicker | Space bar Clicker - spacebar-clicker.org
  • https://www.spacebar-clicker.org
  • spacebar-clicker.org
Spacebar Clicker is a very interesting game. This helps you improve the speed of hitting the spacebar.
 
Lorentzos Roussos #:

i got the margin for both


Thanks for your answer. 
I get margin for both only in the hedging account,  but not in the netting account. 
Which kind of account do you use?
 
Dr Matthias Hammelsbeck #:
Thanks for your answer. 
I get margin for both only in the hedging account,  but not in the netting account. 
Which kind of account do you use?

Hedging 

 
Lorentzos Roussos #:

Hedging 

Ok, in this case I also have margin for both types like you.

But my problem/question is about netting account, where I only get margin for ORDER_TYPE_BUY and not for ORDER_YPE_SELL????

Strange, isn't it?