Reputation: 1
Right now I'm just trying to chart the days open as a horizontal line on an intraday chart.
Open = security(syminfo.tickerid, 'D', open)
plot(Open)
But for some reason it's plotting the previous days open price on the current days intraday chart. This doesn't happen on a daily chart.
Maybe there's something I'm missing, or maybe I can offset the plot by the amount of candles per day.
Upvotes: 0
Views: 245
Reputation: 8779
Your code will work in the realtime bar, but on historical bars, unless you use lookahead
as we do here for Open2
, security()
will return the value of the last completed higher TF bar.
Be very careful with the use of lookahead
; if you use it to retrieve prices other than open
, your script will be accessing future data on historical bars, which is misleading.
//@version=4
study("", "", true)
Open = security(syminfo.tickerid, 'D', open)
Open2 = security(syminfo.tickerid, 'D', open, lookahead = true)
plot(Open)
plot(Open2, "Daily Open", color.fuchsia)
See this script for a discussion on the subject.
Upvotes: 1