'How to define the low of the igniting bar?

i'm making a code that looks for a red bar in an uptrend, I've defined the first green bar and the first red bar that i'm looking for , but i want to add this condition to the redCandle , i want the high of previous bar minus close to be smaller than close minus the low of the first green bar like so:

(high[1]-close) < (close-"the low of the firstGreen").

as you can see i have no idea how to define the low of firstGreen. what should i put there? thanks and here is the code

//@version=4
study(title="Red Bar", overlay=true)

// Calculate moving averages
fastMA = sma(close, 20)
slowMA = sma(close, 200)

//RBI
FirstGreen= barstate.isconfirmed and (open < close) and (close[1] < open[1])
redCandle = barstate.isconfirmed and (close < open) and (fastMA < open) and (slowMA < close) 

//Plots
plotshape(series=redCandle, style=shape.circle, color=#ff00ff, location=location.abovebar)

// ALERTAS
alertcondition(redCandle,  title='RBI', message="Red Alert")


Solution 1:[1]

You can use the valuewhen() for that.

Returns the value of the source series on the bar where the condition was true on the nth most recent occurrence.

firstGreenLow = valuewhen(FirstGreen, low, 0)

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 vitruvius