EA no longer trading

 
I have been testing new code on one of my EAs and I believe it created some kind of bug. I changed the name of the EA while it was still attached to a chart. When I turn the new EA on it doesn't open any trades. I did try manual trading and it opens fine, but closes the manual trading as if the EA was active. It seems as if the EA is working in the backend somehow... has anyone had issues like this?
 

I found the problem and of course it was something in the code... HOWEVER, it was not a change I made.

The function below returns whether is safe to trade. Exposure = whatever percentage you want to trade at. I was using 5 but the calculation (5/100) was returning 0 rather than 0.05...

bool exposureSafe()
{
   if(AccountProfit()< -AccountBalance()*(exposure/100)){
      return(false);
   } else {
      return(true);
   }
}

 I had to change the code to 

bool exposureSafe()
{
   if(AccountProfit()< -AccountBalance()*(exposure*0.01)){
      return(false);
   } else {
      return(true);
   }
}

 where 5*0.01 returns 0.05... No idea how my MT4 now is not calculating that properly

 
agu2a:

I found the problem and of course it was something in the code... HOWEVER, it was not a change I made.

The function below returns whether is safe to trade. Exposure = whatever percentage you want to trade at. I was using 5 but the calculation (5/100) was returning 0 rather than 0.05...

bool exposureSafe()
{
   if(AccountProfit()< -AccountBalance()*(exposure/100)){
      return(false);
   } else {
      return(true);
   }
}

 I had to change the code to 

bool exposureSafe()
{
   if(AccountProfit()< -AccountBalance()*(exposure*0.01)){
      return(false);
   } else {
      return(true);
   }
}

 where 5*0.01 returns 0.05... No idea how my MT4 now is not calculating that properly

Because your "exposure" variable is declared as an int.
 

You mean and Integer couldn't do a division like :

(exposure/100)
 
agu2a:

You mean and Integer couldn't do a division like :

(exposure/100)

If "exposure" is declared as an "int" then the above expression will result in an integer result. So, if you change the order (with parenthesis) in which operations are carried out (causing implicit typecasting), you will end up with the correct result:

bool exposureSafe()
{
   return( AccountProfit() >= ( -AccountBalance() * exposure ) / 100.0 );
}

Alternatively you could also explicitly typecast the variable before using it, but in this case, the above method is sufficient.

However, multiplication is usually faster than division, so it is more efficient to use the following:

bool exposureSafe()
{
   return( AccountProfit() >= -AccountBalance() * exposure * 0.01 );
}
 
Fernando Carreiro:

If "exposure" is declared as an "int" then the above expression will result in an integer result. So, if you change the order (with parenthesis) in which operations are carried out (causing implicit typecasting), you will end up with the correct result:

bool exposureSafe()
{
   return( AccountProfit() >= ( -AccountBalance() * exposure ) / 100.0 );
}

Alternatively you could also explicitly typecast the variable before using it, but in this case, the above method is sufficient.

However, multiplication is usually faster than division, so it is more efficient to use the following:

bool exposureSafe()
{
   return( AccountProfit() >= -AccountBalance() * exposure * 0.01 );
}
Thank you Fernando, this input is exactly what I needed. Thank you!!