Search code examples
pine-scriptcandlestick-chartcandlesticks

How to find the value of a single candle x bar before in Pine Script


Which function schould I use to find higher high and lower low values of a single candle?

For example 30 candles before, exactly -30. Candle informations and plot them?

Thanks in advice


Solution

  • If you want to find the highest or lowest value for a given number of bars back, you can use highest() or lowest():

    h = highest(high, 30)
    l = lowest(low, 30)
    

    Or, if you want to get the value of exactly 30 bars ago, you can use the history reference operator []:

    h = high[30]
    l = low[30]