简体   繁体   中英

How to get current day's high, low, open price for a script in pine script?

Hi I'm pretty new to pine script. So sorry if I'm missing something very obvious. I'm trying to plot current day's open, high, low and close on a given script. For that I'm using below code.

strategy("Intraday Test Strategy", overlay=true)


dh = security(syminfo.tickerid,"D",high)
do = security(syminfo.tickerid,"D",open)
dl = security(syminfo.tickerid,"D",low)

plot(dh, title="High",color=color.red,linewidth=2,trackprice=true)
plot(do, title="Open",color=color.yellow,linewidth=2,trackprice=true)
plot(dl, title="Low",color=color.green,linewidth=2,trackprice=true)

When I execute this all I see is previous day's high, Open, Low prices and not current day's high, Open, Low prices. Its clear I'm missing something very basic. I would appreciate very much if u clarify what I'm missing here.

间谍

As we can from above pic the previous day's open, low and high prices are plotted where as i need current day's values.

Just like in the real world, Pine cannot look into the future.
So, when you're at the start of a day, there's no way to know what the high and low will be.

However, Pine does allow to look ahead on historical bars, because on those bars, the high and low points for that day are known.

//@version=4
study("Test", "Test", true)

[do,dh,dl] = security(syminfo.ticker, "D", [open,high,low], lookahead=barmerge.lookahead_on)

plot(dh, title="High", color=color.red,    linewidth=2, trackprice=true)
plot(do, title="Open", color=color.yellow, linewidth=2, trackprice=true)
plot(dl, title="Low",  color=color.green,  linewidth=2, trackprice=true)

You must be careful though, because the lookahead values will only be correct for days in the past.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM