Pine script: ist it possible to evaluate next candle values? to get relative lowest

Viewed 333
  • I'm trying to detect the if each candle is the lowest value, checking 5 previous candles lows and 5 next candles lows

  • I found no problem with previous: if ta.lowest(low, 5) == low line.new(bar_index - 1, low, bar_index + 1, low, color = color.red, width = 1)

To evaluate if current canle is lower than next ones, I've tried to use negative value on "ta.lowest(low, -5)" but it does not work. Can you give me a hand?

2 Answers

It is not possible in PineScript to “look into the future”. PineScript is designed to make trading strategies and it would become a bit broken, if it was possible to look into the future. That is why you can’t look at the “next candle”.

I'm trying to detect the if each candle is the lowest value, checking 5 previous candles lows and 5 next candles lows

What you have described is implemented in the built-in ta.pivotlow() function, it searches for a pattern and finds the lowest value in the given range to the left (leftbars= argument) and to the right (rightbars=).

As was mentioned, you can't look into the future bars, so the result of the pivot function lags to the amount of bars declared with the rightbars= argument. Note that the plotshape() function uses the same offset as the rightbars= argument.

//@version=5
indicator("pivotlow", overlay = true)
leftbars = 5
rightbars = 5
pivLow = ta.pivotlow(leftbars, rightbars)
plotshape(pivLow, style = shape.labelup, location = location.belowbar, offset = - rightbars)

enter image description here

Related