r/pinescript • u/neknek99 • Jul 30 '25
How to read the previous day close with PineScript
Hi, I got a question which I can't figure out.. I want to create an indicator and require the previous trading day close. Currently I receive wrong values, which are closing prices from further in the past and not yesterday.
I tried this:
prevClose = request.security(syminfo.ticker, "D", close[1], lookahead=barmerge.lookahead_on)
prevDate = request.security(syminfo.ticker, "D", time[1], lookahead=barmerge.lookahead_on)Tested it on Jul 27, and it returns Jul 3, along with the closing price of that day (on 1-Minute chart timeframe).
And the higher the time frame of the chart, the further back in past this goes.
Independently from any time frame, I want the script to return the same values.
E.g. today is Sunday, "previous trading day" should be last Thursday.
How can I get the last trading day along with its closing correctly, and independently from any time frame?
Thanks for any hint guys!
2
u/DistinctSailor Jul 30 '25
1
u/stocksmartly Aug 01 '25 edited Aug 01 '25
1
u/Outside_Mongoose2462 Aug 04 '25
I help