I have a script that finds the percent change of the current candle in relation to the closing price of the previous candle. The main thing I use it for is Daily comparison to see how far each currency pair has moved during the day. I'd like to use it on smaller timeframes, but I'm running into an issue with dividing by zero. I can only assume it is because either the price has not changed or because the change is so small, the double integers ("gj" in the example below) do not have enough decimal places.
Example:
The smallest I intend to use it on is M15 and I intend to run it during the last 30 seconds of each 15-minute candle. So... it *should* always have a different closing price from the previous candle unless it's just a coincidence that the script runs while at the closing price of the previous candle. I can also run it on M30 but I'd like to have it on M15. Right now, H4 seems to work and H1 seems to work. But I really would love to have it working consistently on M30 or 15.
When I test it, I get a "divide by zero" error consistently on M30 and M15. I don't know if it's because one of the pairs (this compares all pairs my broker offers at the same time in the same script to get a whole market snapshot) is at the same price as the closing price of the last candle. Or if it's because the percent change in the price is so small that the double value is not specific enough and I need to use a floating value...? Or it could be a combination of the two :\
Can anyone tell me how to make this work reliably?
Thank you...
Example:
Inserted Code
gj = (((MarketInfo("GBPJPY",MODE_BID))-(iClose("GBPJPY",PERIOD_M15,1)))/(iOpen("GBPJPY",PERIOD_M15,0))*100);
The smallest I intend to use it on is M15 and I intend to run it during the last 30 seconds of each 15-minute candle. So... it *should* always have a different closing price from the previous candle unless it's just a coincidence that the script runs while at the closing price of the previous candle. I can also run it on M30 but I'd like to have it on M15. Right now, H4 seems to work and H1 seems to work. But I really would love to have it working consistently on M30 or 15.
When I test it, I get a "divide by zero" error consistently on M30 and M15. I don't know if it's because one of the pairs (this compares all pairs my broker offers at the same time in the same script to get a whole market snapshot) is at the same price as the closing price of the last candle. Or if it's because the percent change in the price is so small that the double value is not specific enough and I need to use a floating value...? Or it could be a combination of the two :\
Can anyone tell me how to make this work reliably?
Thank you...