2
  • 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?

e2e4
  • 3,428
  • 6
  • 18
  • 30
Juanan
  • 23
  • 5

2 Answers2

1

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

e2e4
  • 3,428
  • 6
  • 18
  • 30
0

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”.

Marcus Cazzola
  • 313
  • 1
  • 9
  • Thanks a lot Marcus. Also, it is possible to declare a global variable and assign/evaluate it for each candle? – Juanan Feb 10 '22 at 07:57
  • @juanan If you type "var" before the variable, then it becomes global and you can assign a value and access it on the next bar. – Marcus Cazzola Feb 10 '22 at 17:00