Search code examples
pythonpine-scripttradingview-apita-lib

What's the difference between close and close[1] in pinescript


rsi_value = rsi(close[1],lengthMiddle)

what does the close[1] means in tradingview pinescript and how it's different from close


Solution

  • It is the close value one bar ago.

    In Pine, the close variable, or close[0] which is equivalent, holds the price at the close of the current bar. If your code is now executing on the third bar of the dataset, close will contain the price at the close of that bar, close[1] will contain the price at the close of the preceding bar (the second), and close[2], the first. close[3] will return na because no bar exists in that position, and thus its value is not available.

    https://www.tradingview.com/pine-script-docs/en/v4/language/Operators.html?highlight=history#history-reference-operator