Margin Rate

 

Hello,


i have a question to the Margin Rate.

In the documentation is written, to use the Margin Rate for calculation of CF, Futures and so on

even in the Symbol the margin Rate is filled out

as it staand in the documantation, if the Maintainance Margin is 0, its equal to the Initial Margin, ok, this is no problem, 

but, how i read the initial Margin?


i have the SymbolInfoDouble,

Print("Margin Initial: ",SymbolInfoDouble(_Symbol,SYMBOL_MARGIN_INITIAL));

what returns always 0, what i even understand, bcs the MQL makes here a difference between Long and Short. Even, i dont found any Symbol, where there is a difference.

than i tried to use CTrade SymbolInfo 


#include <Trade\Trade.mqh>             CTrade _trade;             // wird verwendet für die Trade Funktionen 

#include <Trade\SymbolInfo.mqh>        CSymbolInfo _sym;               // wird verwendet für die Symbol Information Funktionen


void OnStart()
  {
//---
  
    
  Print("Margin Initial SymbolInfo: ", _sym.MarginInitial());
  Print(_sym.MarginShort());
  Print(_sym.MarginLong());
   
}

what returns also 0 values.

Also i tried to enter a Short order, and see if the _sym.MarginShort() got an other value. Even with an short order on an CFD calculation instrument, i got the value 0.


Background is, i want to place an order with an defiend use of Margin. So i have 5k in my account, and want to use 20% of the margin.

Lot1 = NormalizeDouble((AccountSize / (ContractSize*Trade.Bid*SymbolInfoDouble(_Symbol,SYMBOL_MARGIN_INITIAL)))/100*risiko,2);

The calculation is right, when i use instead of instead of SymbolInfoDouble(_Symbol,SYMBOL_MARGIN_INITIAL) the value in the Symbol spezification.

On Forex, this is no problem, bcs the Margin Initial is 1.


regards

amando

 
 NO idea from anyone?
 

Hi amando,

There is a lot of confussion regarding Margin Rate informations, as they vary accross symbols and brokers.

E.g. let me demonstate on EURUSD on two brokers - same script:

   Print("SymbolInfoDouble_SYMBOL_MARGIN_INITIAL : ",SymbolInfoDouble("EURUSD",SYMBOL_MARGIN_INITIAL));
   double MarginInit;
   double MarginMaint;
   Print("Margin MarginRate: ",SymbolInfoMarginRate("EURUSD",ORDER_TYPE_BUY,MarginInit,MarginMaint));
   Print("Margin init: ",MarginInit);
   Print("Margin Maint: ",MarginInit);
   double OrdCalcMargin;
   Print("Check OrderCalcMargin ",OrderCalcMargin(ORDER_TYPE_BUY,"EURUSD",1.0,1.22551,OrdCalcMargin));
   Print("OrderCalcMargin: ", OrdCalcMargin);

For simplicity sake let's ignore that i have different leverages on the differen Brokers.

Return on broker A:


Return on broker B:


Note the following:

SymbolInfoDouble

This information is set be the broker indidvidually and can vary across symbols. Looks like you described exactly this, that on your broker, for forex you receive a non-zero value.

In my case one broker has it set and the other doesn't. A hint for that is, whether the Symbol information (as per your snip), has a dedicated field: Initial Magrin. The symbol you showed does not have this and that probaly the reason why you don't get a value back.

So now to what you circled in blue in your snip. To access this information you need to use:

SymbolInfoMarginRate

https://www.mql5.com/en/docs/marketinformation/symbolinfomarginrate

The third option, that seems personally to me to be more accurate is:


OrderCalcMargin

 https://www.mql5.com/en/docs/trading/ordercalcmargin

If return is sucessfull it will return you an already nomalized double. From my experience it does at least across symbols and brokers return the correct value (when there are not open or pending orders - see docs).

In the end, it doesn't solve your goal to calulated the lot based on margin. Not sure if there is a harmonised way to do it. Although computationally expensive, you could use  OrderCalcMargin and loop it up to the value required.

Other posts:

https://www.mql5.com/en/forum/7418

https://www.mql5.com/en/forum/305931

(bug?) SYMBOL_MARGIN_INITIAL = 0.0
(bug?) SYMBOL_MARGIN_INITIAL = 0.0
  • 2012.08.12
  • www.mql5.com
Hello MetaQuotes, I have checked SYMBOL_MARGIN_INITIAL value on several symbols and every time it returns 0.0...