0
votes

I'm trying to get the lowest low of a series of candles after a condition, but it always returns the last candle of the condition. I try with min(), lowest() and a for loop but it doesn't work. Also try using blackCandle[] and min(ThreeinARow)/lowest(ThreeinARow) and sometimes it returns the last candle and other times it gives me compilation error.

blackCandle = close < open
ThreeinARow = blackCandle[3] and blackCandle[2] and blackCandle[1]
SL = ThreeinARow ? min(low[1], low[2], low[3]) : na
2

2 Answers

1
votes
//@version=4
study("Help (low after 3DownBar)", overlay=true, max_bars_back=100)

blackCandle = close < open
ThreeinARow = blackCandle[3] and blackCandle[2] and blackCandle[1]

bar_ind = barssince(ThreeinARow)
//SL = lowest(max(1, nz(bar_ind))) // the lowest low of a series of candles after the condition
SL = lowest(max(1, nz(bar_ind)+1))  // the lowest low of a series of candles since the condition
plot(SL, style=plot.style_cross, linewidth=3)
bgcolor(ThreeinARow ? color.silver : na) 

See also the second solution which is in the commented line

0
votes

It seems that I was misinterpreting it. Using min() does return the minimum of a series of candles. The detail is that I must enter the specific number of candles that I will use to calculate the minimum, which, for now, does not generate any problem for me. In the end, this is how I ended up writing it:

blackCandle = close < open

ThreeinARow = blackCandle[3] and blackCandle[2] and blackCandle[1]

Lowest_Low = if ThreeinARow
    min(low[1], low[2], low[3])

plot(Lowest_Low, color=color.red)