Download MetaTrader 5

Getting first digit of Account's balance

To add comments, please log in or register
hals
11
hals  

Hello,

I'm trying to do some mathematical equations within my EA , but the problem is one of equations  requires the first number of account's balance . For example if the balance is 506.60 I want to get this value "5" , if it is 432.32 I want to get "4" . So how can it be done ? 

Note : To get the current balance I use AccountBalance();

peter.MT4Web
157
peter.MT4Web  

Hi hals69!

Try

  long value = StringToInteger (StringSubstr (DoubleToString (AccountBalance ( )), 0, 1));


whroeder1
15577
whroeder1  
int d = int( AccountBalance() / 100); // 4xx.xx/100=4.xxx 5xx.xx/100=5
What if the balance is 99, do you want zero? What if the balance is 1000, do you want 10? If not then eddie's idea works. If yes, then mine.
To add comments, please log in or register