Download MetaTrader 5
To add comments, please log in or register
Publish your article. We will translate it into other languages!
Luis 2015.08.04 16:05 

This is the part of my coding in my EAs that is giving me some headaches.

This will check if there is free margin to open the position, but seems is failing in some brokers that are using Stopoutmode==1.

This is the only part of the coding that I didnt make it, seems that checking free margin was easy and I folloed this code somewhere I dont remember. Normally works ok. But some brokers like FXCM that has a AccountStopOutLevel() of 100 are failing with any positions, because the function will return false everytime.

"int command" is the direction of the trade. 0=OP_BUY, etc...

bool EnoughMargin(int command, double volumen)

   Alert("Acc. Free margin: ", AccountFreeMarginCheck(Symbol(),command, volumen));
   Alert("Acc. Equity ", AccountEquity());
   Alert("Acc. Stoplevel ",AccountStopoutLevel());
   Alert("Esto mayor que Stop Level: ", (AccountFreeMarginCheck(Symbol(),command, volumen)/AccountEquity()) * 100);
   if (AccountStopoutMode() == 1)
      if(AccountFreeMarginCheck(Symbol(),command, volumen) > AccountStopoutLevel())
         return true;
   if (AccountStopoutMode() == 0)
      if (((AccountFreeMarginCheck(Symbol(),command, volumen)/AccountEquity()) * 100) > AccountStopoutLevel())
         return true;
   return false;

Can anyone to help me with this code that check if there is enough margin before opening a position? Im using this code for this EAs, so I need them to be perfect:

- BeLikewater:

- Sunday Decisions:



Vasyl Nosal
Vasyl Nosal 2015.08.04 16:43  


 You compare wrong things. 

Just use this. 

bool EnoughMargin(double volumen)

if(AccountFreeMargin()<MarketInfo(Symbol(),MODE_MARGINREQUIRED)*volumen) return(false);

Luis 2015.08.05 09:16  

Ok eevviill

Thank you very much. My brain is no longer willing to learn new things lately it seems.



To add comments, please log in or register