Search code examples
pine-scriptpine-script-v5

Can I get the current price in a Pine Script indicator as it processes historical bars


I am writing an indicator for TradingView using Pine script. Indicators run the script over all of the bars in the displayed chart but I want to have a variable that has the current price so that I can calculate the support and resistance at the current price as I process through all of the historical charts. Is there a way to do this.ie when processing a historical bar if I wanted to know how far that bar is from the current price I might have something like:

var float currentPrice = ????
distance_toNow = currentPrice - close

I've looked at the reference info and google and only found reference to using close/high etc which obviously relate to the bar being processed but not the current price (unless you are processing the last bar of the chart)


Solution

  • No, this is not possible.

    Your script will be executed starting from the very first available bar. And you can only access to what is available on your chart.