small problem with computing daily movement (divide problem)

wicha

Newbie
Apr 4, 2020
2
0
1
32
Hi folks,

I have a small but really frustrating problem with dividing. The Indi has many-many arrays and works well, but now I wanted to change the base of the arrays. The old one was the RSI, now i want to change into Daily % change ( or candle, because I want to see it on every TF).

So, I wanted to type in that ( Close-Open ) / Close *100 .

Till Close-Open everything works fine, the MT4 computes all the datas and arrays (however it has no sense). But right after I put a "/" mark into the line, everything goes wrong, all the arrays are empty, however the basic stuff is computed because I see the right datas on the last 15 bars. No visual as well (it has to). I don't understand. Can you help me?

Oh I tried two different methods as you see but no result...

Thank you very much for you kindness

wicha

ps. RSI here is simply =1 to get the bar's value
MQL4:
double GetSlope(string symbol, int tf, int shift)
 
{
   double close= iMA(symbol,tf,RSI,0,MODE_SMA,PRICE_CLOSE,shift);
   double close2= iClose(symbol,tf,shift);
   double open = iOpen(symbol,tf,shift);
   double range = close-open;
 
   double gadblSlope =(range/close2)*100;
 
 
   return ( gadblSlope );
 
}
 
Last edited by a moderator:

Enivid

Administrator
Staff member
Nov 30, 2008
18,530
1,355
144
Odesa
www.earnforex.com
Please don't forget to choose MQL4 or MQL5 when inserting code snippets.

As for your problem, I would add a zero division check for close2:
MQL4:
   double gadblSlope;
   if (close2 > 0) gadblSlope = range / close2 * 100;
   else gadblSlope = 0;
 
  • 👍
Reactions: wicha