I am trying to code a very simple exponential average (60) of a calculated candle value, it sometimes stops calculating and flatlines which is strange. There has to be an error in my code as the candle value still calculates. To see it better I have scaled the values up
Does anyone have any idea as to why this is happening I have tried a few things to no success.
//Flow
// Works out the candle value and to see result is scaled up by * 200
//Zero Line
DRAWHLINE(0)coloured(0,0,0)
CandleValue = (close - open) / (high - low)
CV = CandleValue * 200
// Exponential average of scaled up Candle Value and this is scaled up * 50 to see result
MVC = Average[60,1](CV)
MVC1 = MVC * 50
Return MVC1 as "MVC", CandleValue as "CV", CV as "Scale Up CV", 0 as "0"
It’s quite weird, I tested it on DAX, different TF’s, even replacing AVERAGE with EXPONENTIALAVERAGE, but it still plots flat lines almost everyday.
It occurs mainly on Indices (Dax, Ftse, Nikkei, Cac40, Russel, Nasdaq, S&P500 and Dow Jones ). As to FX pairs I experienced the same issue on NZD/CHF, GBP/CAD and GBP/CHF (I did only test it on about 15 pairs).
I have no idea why.
I suggest that you open a ticket for assistamce (press Ctrl+M from the platform).
Yeah same Robertogozzi I also tried EXPONENTIALAVERAGE and same issue I shall raise a ticket and update with the feedback. Thanks for looking into this
You divide by (high-low) in line 8, which creates undefined values when high=low because of division by 0, and propagates the undefined through the averages. You can try to surround your line 8 by “if high<>low then … endif” and see if it achieves what you expect.
Well spotted Noobywan!
You can replace line 8 with this one:
CandleValue = (close - open) / max(0.00001,(high - low))
Maybe this a better solution, replace lines 8-9 with:
IF (high - low) >0 THEN
CandleValue = (close - open) / (high - low)
CV = CandleValue * 200
ENDIF
Great spot Noobywan, Robertogozzi that last code works great as expected thanks guys.