Download MetaTrader 5

Trading 2 instruments @ same account. Margin problem

To add comments, please log in or register
Marcelo Coutinho
1207
Marcelo Coutinho  

Hi there !

Can someone please give "best practices" on how to solve this problem!

If I run 2 instruments @ same account, how can I inform me EA to calculate the margin per instrument

I am using the folowing code but it is halting the system because it is adding all margins to my account

   if(AccountInfoDouble(ACCOUNT_MARGIN)>(contratos*margem)) // com posição selecionada, implementa mecanismos de segurança
     {
      SendNotification("MARGEM MAXI");
      Alert("Atenção: limite de margem acionado (",AccountInfoDouble(ACCOUNT_MARGIN)," > ",(contratos*margem),")");
      Sleep(1000*60*60*8);
      return;
     }
Hector Pacheco
17559
Hector Pacheco  


You must use the function SymbolInfoDouble

For example:

 double val1 = SymbolInfoDouble ( Symbol (), SYMBOL_MARGIN_INITIAL );
 double val2 = SymbolInfoDouble ( Symbol (), SYMBOL_MARGIN_MAINTENANCE );
 double val3 = SymbolInfoDouble ( Symbol (), SYMBOL_MARGIN_LONG );
 double val4 = SymbolInfoDouble ( Symbol (), SYMBOL_MARGIN_SHORT );
Marcelo Coutinho
1207
Marcelo Coutinho  
Iwori_Fx:


You must use the function SymbolInfoDouble

For example:

Thank you !!
Romeu Bertho
3260
Romeu Bertho  

Marcelo Speaks!

or you can use the CSymbolInfo class, which provides access to all properties of the symbol you want, and CAccountInfo class , which provides access account properties.

Before creating objects of these classes, you must include the following libraries:

# Include <Trade\SymbolInfo.mqh>

# Include <Trade\AccountInfo.mqh>

For example:

CSymbolInfo symbolInfo;
CAccountInfo accountInfo;

symbolInfo.Name( Symbol ());
symbolInfo.Refresh();
symbolInfo.RefreshRates();
symbolInfo.MarginInitial();
symbolInfo.MarginMaintenance();

accountInfo.Margin();
accountInfo.FreeMargin();

Hug,

Romeu.

Marcelo Coutinho
1207
Marcelo Coutinho  
c4b3l3r4:

Fala Marcelo!

ou você pode utilizar a classe CSymbolInfo, que fornece acesso a todas as propriedades do símbolo que você desejar, e a classe CAccountInfo, que fornece acesso as propriedades da conta.

Antes de criar objetos dessas classes, você deve incluir as seguintes bibliotecas:

#include <Trade\SymbolInfo.mqh>

#include <Trade\AccountInfo.mqh>

Por exemplo:

Abraço,

Romeu.

Muito Obrigado ! [Thank you very much]
Marcelo Coutinho
1207
Marcelo Coutinho  
YouTrade:
Muito Obrigado ! [Thank you very much]

I got your point but I still cannot figure out how to solve this problem.

If I am trading 2 instruments @ same account, how can I separate its margings.

Example:

5 WINM14 (margin per contract is 500)

5 WDOM14 (margin per contract is 700)

If I am simultaneouslly positioned on both, total margin will be 5*500 + 5*700 = 6000.

Lets suppose I have I problem with WINM14 and I have 10 contracts. Margin will be 10*500 = 5000 < 6000.

If I am not positioned with the other instrument, the system will not be able to decect :(

Any idea ? 

To add comments, please log in or register