Let's dive right into it. So I'm currently working on an indicator and so, I want to be able to average the closes of red candles only. Problem is, that the solution I've came to averages green candles too for some odd reason, I'll appreciate some help on this one.
averagePastRedCandles(amount) =>
currentnum = 0.0
currentreds = 0.0
for i = 0 to 99999
if currentreds == amount // end the loop if amount averaged is met
break
else
if open > close // check if the candles is red
currentreds := currentreds + 1 // basically the current
amount that's already averaged
currentnum := currentnum + close[i] // the sum of the closes of the red candles only
continue
currentnum / amount