Hello,
You can use this function: https://docs.mql4.com/math/mathabs
Regards.

Hello Yohana, thank you!
Could you help me a little further?
I changed the code, but still histogram returns all black screen. So, I look at the de Expert Advisors tab, and I saw there is an Zero Divider error on this line
2022.10.21 11:24:06.538 Ma distance_2 EURJPY,M5: zero divide in 'Ma distance_2.mq4' (79,31)
The exact line where I make the division between variable emaprice and price, to get the percentage number of the distance I want to calculate.
Do you know how I can get rid of this Zero Divide error? I tried some solutions from other topics, but then always i get the wrong results in percentage.
double price = iClose(NULL, 0, i) - iOpen(NULL, 0, i); price = MathAbs(price); double emaprice = (iClose(NULL, 0, i) - iMA(NULL,0,MaPeriod,0,MaMethod,Price_cls,i))*100; double math1 = emaprice/price; // if(math1>0) { up[i] = math1; dn[i] = EMPTY_VALUE; } else { dn[i] = math1; up[i] = EMPTY_VALUE; } } return(0); }
Hello Yohana, thank you!
Could you help me a little further?
I changed the code, but still histogram returns all black screen. So, I look at the de Expert Advisors tab, and I saw there is an Zero Divider error on this line
2022.10.21 11:24:06.538 Ma distance_2 EURJPY,M5: zero divide in 'Ma distance_2.mq4' (79,31)
The exact line where I make the division between variable emaprice and price, to get the percentage number of the distance I want to calculate.
Do you know how I can get rid of this Zero Divide error? I tried some solutions from other topics, but then always i get the wrong results in percentage.
Hello,
Here is your code with a few fixes as necessary:
double math1, price, emaprice; for(int i=limit; i >= 0; i--) { price = MathAbs(iClose(NULL, 0, i) - iOpen(NULL, 0, i)); emaprice = (iClose(NULL, 0, i) - iMA(NULL,0,MaPeriod,0,MaMethod,Price_cls,i))*100; //-- if(price>0) math1=emaprice/price; else continue; //-- if(math1>0) { up[i] = math1; dn[i] = EMPTY_VALUE; } else { dn[i] = math1; up[i] = EMPTY_VALUE; } }
Result:
If you need further assistance, please use freelance.
You will find great programmers even better than me there.
Happy coding :)

- 2022.10.22
- www.mql5.com

- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
You agree to website policy and terms of use
Variable 4 = Variable 3 / Variable 1 // result in percentage, however when the number of variable 1 is negative, the program does not perform the division and returns the histogram all black.
I didn't write the code, as I'm very new to MQL4. I'm just trying to adapt it, to do what I want. But I'm stuck on this, for days, without finding any solution. So, if someone can give me a little help, I be very greatful.
Here is the code.