Check if account is hedge

 

Does it have a command to check if the account is hedge?

Thanks. 

 
Pablo Rego:

Does it have a command to check if the account is hedge?

Thanks. 

You need to get a property of enumeration ENUM_ACCOUNT_MARGIN_MODE:

ENUM_ACCOUNT_MARGIN_MODE

Identifier

Description

ACCOUNT_MARGIN_MODE_RETAIL_NETTING

Used for the OTC markets to interpret positions in the "netting" mode (only one position can exist for one symbol). The margin is calculated based on the symbol type (SYMBOL_TRADE_CALC_MODE).

ACCOUNT_MARGIN_MODE_EXCHANGE

Used for the exchange markets. Margin is calculated based on the discounts specified in symbol settings. Discounts are set by the broker, but not less than the values set by the exchange.

ACCOUNT_MARGIN_MODE_RETAIL_HEDGING

Used for the exchange markets where individual positions are possible (hedging, multiple positions can exist for one symbol). The margin is calculated based on the symbol type (SYMBOL_TRADE_CALC_MODE) taking into account the hedged margin (SYMBOL_MARGIN_HEDGED).

 
Pablo Rego:

Does it have a command to check if the account is hedge?

Thanks. 

You can use this simple script:

//+------------------------------------------------------------------+
//|                                                  Margin Mode.mq5 |
//|                                                       Robertomar |
//|         http://www.tradingunited.es/foro/members/robertomar.html |
//|                                                robertoma@ono.com |
//|                                       robertomartrader@gmail.com |
//+------------------------------------------------------------------+
#property copyright "Robertomar"
#property link      "http://www.tradingunited.es/foro/members/robertomar.html"
#property version   "1.00"
//+------------------------------------------------------------------+
//| Script program start function                                    |
//+------------------------------------------------------------------+
void OnStart()
  {
//---
    ENUM_ACCOUNT_MARGIN_MODE margin_mode;
    string hedge = IsHedging(margin_mode) ? "allowed" : "not allowed";
    
    PrintFormat("Margin Mode: %s.  Hedging %s", EnumToString(margin_mode), hedge);
  
  }
  
//+------------------------------------------------------------------+

bool IsHedging(ENUM_ACCOUNT_MARGIN_MODE &margmod)
{
  
  margmod = (ENUM_ACCOUNT_MARGIN_MODE)AccountInfoInteger(ACCOUNT_MARGIN_MODE);
  return(margmod==ACCOUNT_MARGIN_MODE_RETAIL_HEDGING);

}

//+------------------------------------------------------------------+



Regards.

Files:
 
I know I may sound stupid but what is "hedging" in forex, sorry but nobody is a monopoly of knowledge.
 
Kanu Nkechi Sonia:
I know I may sound stupid but what is "hedging" in forex, sorry but nobody is a monopoly of knowledge.
It means the possibility to open several positions on a same symbol, including opposite positions. It was not possible previously in MT5, but now it's possible. Regards.
 
pvrego:

Does it have a command to check if the account is hedge?

Thanks. 

Or use my simpler version. Returns true or false.

bool IsHedgingAllowed()
{
  ENUM_ACCOUNT_MARGIN_MODE res = (ENUM_ACCOUNT_MARGIN_MODE)AccountInfoInteger(ACCOUNT_MARGIN_MODE);
  return(res==ACCOUNT_MARGIN_MODE_RETAIL_HEDGING);
}
 
Arturo Lopez Perez:

Or use my simpler version. Returns true or false.

bool IsHedgingAllowed()
{
  ENUM_ACCOUNT_MARGIN_MODE res = (ENUM_ACCOUNT_MARGIN_MODE)AccountInfoInteger(ACCOUNT_MARGIN_MODE);
  return(res==ACCOUNT_MARGIN_MODE_RETAIL_HEDGING);
}

Thanks Pz !