Download MetaTrader 5

Function for returning a positive number

To add comments, please log in or register
Mark Falzon
140
Mark Falzon 2015.06.11 02:18 

Hi all.

 

Does anyone know whether there is a function available in MQL4 that converts negative numbers into positive?

 

I want to measure the length of a candle's body in pips and to do this, I subtract the open from the close. So for bullish candles where the close is higher, the length is a positive number but for bearish candles where the close is lower than the open, the length is a negative number. So I need my function to work for both instances but to result in a positive number.

 

I could set up an If/ELSE function to determine  whether the close is higher or lower than the open, which would then direct it to the appropriate method of subtraction but I was hoping that there was a function already available just to drop the negative symbol from the result.

 

Mark 

Alain Verleyen
Moderator
31153
Alain Verleyen 2015.06.11 08:52  
MathAbs().
Mark Falzon
140
Mark Falzon 2015.06.11 16:28  
Thanks Alain. Perfect.
To add comments, please log in or register