1

I would like to get the latest closing price in pinescript. I thought this is a simple thing to do, yet I face difficulty.

I tried close but this returns the closing price of the bar selected by the mouse. What I want is the closing price of the last bar in the price history.

I am using pinescript v5

FDL
  • 115
  • 8

1 Answers1

1
var float my_close = 0.
if barstate.islastconfirmedhistory
    my_close := close

plot(my_close)
Dave
  • 847
  • 1
  • 2
  • 7
  • Thank you for your answer. Upvoted. It is not exactly what I want. I asked another follow-up question clarifying what I want. https://stackoverflow.com/questions/74076838/how-to-get-the-latest-closing-price-in-pinescript – FDL Oct 16 '22 at 01:30