Search code examples
minpine-script

How to get the lowest low of a series in PineScript


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

Solution

  • 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)