- My Code Compiled correctly but I have a problem with it
- Experts: Multi Pair Closer
- Question for connoisseurs
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...
{
if(AccountProfit()< -AccountBalance()*(exposure/100)){
return(false);
} else {
return(true);
}
}
I had to change the code to
{
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
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...
{
if(AccountProfit()< -AccountBalance()*(exposure/100)){
return(false);
} else {
return(true);
}
}
I had to change the code to
{
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
You mean and Integer couldn't do a division like :
You mean and Integer couldn't do a division like :
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 );
}
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 );
}
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
You agree to website policy and terms of use