[HELP-resolved] SymbolInfoDouble Margin Initial returns zero?

 

Hi all.

I am trying to workout how can I get this "3" that I see on the symbol specs on my broker.

XAU initial margin = 3


But SymbolInfoDouble Symbol Magrin Initial returns 0.0

SymbolInfoDouble(par,SYMBOL_MARGIN_INITIAL)

So I ran them all and displayed as comment to debug:

   Hints +="\nMargin Hedged : "+SymbolInfoDouble(par,SYMBOL_MARGIN_HEDGED);
   Hints +="\nMargin Limit : "+SymbolInfoDouble(par,SYMBOL_MARGIN_LIMIT);
   Hints +="\nMargin Long : "+SymbolInfoDouble(par,SYMBOL_MARGIN_LONG);
   Hints +="\nMargin Maint : "+SymbolInfoDouble(par,SYMBOL_MARGIN_MAINTENANCE);
   Hints +="\nMargin Short : "+SymbolInfoDouble(par,SYMBOL_MARGIN_SHORT);
   Hints +="\nMargin Stop : "+SymbolInfoDouble(par,SYMBOL_MARGIN_STOP);
   Hints +="\nMargin StopLimit : "+SymbolInfoDouble(par,SYMBOL_MARGIN_STOPLIMIT);
   Comment(Hints);

To my surprise... all came as 0.0


How can I get that 3?

Thank you

Nuno

 

Don't make it difficult for yourself. Just use OrderCalcMargin ...

OrderCalcMargin

Calculates the margin required for the specified order type, in the deposit currency

Documentation on MQL5: Trade Functions / OrderCalcMargin
Documentation on MQL5: Trade Functions / OrderCalcMargin
  • www.mql5.com
OrderCalcMargin - Trade Functions - MQL5 Reference - Reference on algorithmic/automated trading language for MetaTrader 5
 
Fernando Carreiro #:

Don't make it difficult for yourself. Just use OrderCalcMargin ...

OrderCalcMargin

Calculates the margin required for the specified order type, in the deposit currency

I already check that before an OrderSend, inside this funcion:

bool CheckMoneyForTrade(string symb,double lots,ENUM_ORDER_TYPE type)
  {
//--- Getting the opening price
   MqlTick mqltick;
   SymbolInfoTick(symb,mqltick);
   double price=mqltick.ask;
   if(type==ORDER_TYPE_SELL)
      price=mqltick.bid;
//--- values of the required and free margin
   double margin,free_margin=AccountInfoDouble(ACCOUNT_MARGIN_FREE);
   //--- call of the checking function
   if(!OrderCalcMargin(type,symb,lots,price,margin))
     {
      //--- something went wrong, report and return false
      Print("Error in ",__FUNCTION__," code=",GetLastError());
      return(false);
     }
   //--- if there are insufficient funds to perform the operation
   if(margin>free_margin)
     {
      //--- report the error and return false
      Print("Not enough money for ",EnumToString(type)," ",lots," ",symb," Error code=",GetLastError());
      return(false);
     }
//--- checking successful
   return(true);
  }

My intent now is, when the result of this check is negative, I can retry with a new lower volume that fits the margin.

How can I go that?

Maybe if I make that "margin" a global double variable, and retry with

new volume = Free MArgin * Old Volume / margin?
 
Nuno Madeira Amaro Pire Costa #: How can I go that? ... retry with new volume = Free MArgin * Old Volume / margin?

Yes, by simple maths and by also checking the amount of available free margin (and if you need, also used margin from other open positions) ...

AccountInfoDouble

Returns a value of double type of the corresponding account property

ENUM_ACCOUNT_INFO_DOUBLE

ACCOUNT_MARGIN

Account margin used in the deposit currency

double

ACCOUNT_MARGIN_FREE

Free margin of an account in the deposit currency

double

ACCOUNT_MARGIN_LEVEL

Account margin level in percents

double

ACCOUNT_MARGIN_SO_CALL

Margin call level. Depending on the set ACCOUNT_MARGIN_SO_MODE is expressed in percents or in the deposit currency

double

ACCOUNT_MARGIN_SO_SO

Margin stop out level. Depending on the set ACCOUNT_MARGIN_SO_MODE is expressed in percents or in the deposit currency

double

ACCOUNT_MARGIN_INITIAL

Initial margin. The amount reserved on an account to cover the margin of all pending orders

double

ACCOUNT_MARGIN_MAINTENANCE

Maintenance margin. The minimum equity reserved on an account to cover the minimum amount of all open positions

double


Documentation on MQL5: Account Information / AccountInfoDouble
Documentation on MQL5: Account Information / AccountInfoDouble
  • www.mql5.com
AccountInfoDouble - Account Information - MQL5 Reference - Reference on algorithmic/automated trading language for MetaTrader 5
 
Thank you for your collaboration! Its solved now. 
Reason: