I think my code is written badly

Back to topics list To post a new topic, please log in or register
avatar
83
BeLikeWater 2015.08.04 18: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:    https://www.mql5.com/en/market/product/8294

- Sunday Decisions:     https://www.mql5.com/en/market/product/9521


Greetings

BeLikewater

avatar
872
eevviill 2015.08.04 18:43 #
 

????

 You compare wrong things. 

Just use this. 

bool EnoughMargin(double volumen)

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

return(true);
}

 

 

avatar
83
BeLikeWater 2015.08.05 11:16 #
 

Ok eevviill


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


Greetings

BeLikeTrader

Back to topics list  

To add comments, please log in or register