This simple indicator that just calculates an average of the closing position as a percentage of range returns flat spots on the indicator where the average is clearly not being calculated correctly and the value does not change over many candles.
The attached images are of DJI daily.
p = 3
closeperc = ((close-low)/(high-low))*100
avg = average[p,1](closeperc)
return avg
Congratulations for being able to successfully recode a stochastic from scratch! 😆 (no offense)
sto = Stochastic[1,1]
avg = average[p,1](sto)
EDIT: topic is not in the right section! 😉
Vonasi, you’ll have to move it yourself to the correct support forum!
Congratulations for being able to successfully recode a stochastic from scratch!
I actually hadn’t twigged that it was the same calculation!
Interestingly if you put the two calculations on in the same indicator the stochastic one calculates just fine but my version doesn’t.
p = 3
closeperc = ((close-low)/(high-low))*100
avg = average[p,1](closeperc)
sto = Stochastic[1,1]
avg2 = average[p,1](sto)
return avg,avg2
I actually think this is the right place for this topic as it is clearly a data or calculation error which is a platform issue.
I’ve done a little more testing and the variable closeperc calculates correctly. The issue is with the exponential average calculation. If I use a simple average then it calculates correctly.
More worrying revelations?
Your code works fine for me, both lines overlap.
Your code works fine for me, both lines overlap.
Really? That is very odd. On the DJI daily?
I feel a switch it off and back on again happening if so.
DJI daily.
The one below is your original code.
The one above is this one (with modifications to avoid division by 0):
p = 3
x = max(pipsize,range)
//closeperc = ((close-low)/(high-low))*100
closeperc = ((close-low)/x)*100
avg = average[p,1](closeperc)
sto = Stochastic[1,1]
avg2 = average[p,1](sto)
return avg AS "Avg",avg2 AS "Stoch"
Apart from a few candles, both blue and red lines overlap.