I'd like to make a code that won't entering the position in a situation like in the picture.
greenCandle = barstate.isconfirmed and (close > open)
sixGreenCandles = greenCandle[6] and greenCandle[5] and greenCandle[4] and greenCandle[3] and greenCandle[2] and greenCandle[1]
I don't know the code to count the candle before entering the position
(Except for the candles at the signal)
You can use the
ta.barssince()
function to figure out when the last red candle was. Then add a check whether this was less than 6 before the current bar. Use this condition together with your other buy conditions.