使用 Pine Script v5 的前一天最高价和最低价

Previous Day High and Low using Pine Script v5

我正在尝试将 pinescript 从 v1 转换为 v5。

v1

study(title="Previous Day High and Low", shorttitle="Previous Day High and Low", overlay=true)
D_High = security(tickerid, 'D', high[1]) 
D_Low = security(tickerid, 'D', low[1]) 
D_Close =  security(tickerid, 'D', close[1]) 
D_Open =  security(tickerid, 'D', open[1]) 

plot(isintraday ? D_High : na, title="Daily High",style=line, color=blue,linewidth=1) 
plot(isintraday ? D_Low : na, title="Daily Low",style=line, color=blue,linewidth=1) 

输出:

v1 工作正常。

我正在尝试转换 v5

//@version=5
indicator(title="Previous Day High and Low New", shorttitle="Previous Day High and Low New", overlay=true)

D_High = request.security(syminfo.tickerid, 'D', high[1]) 
D_Low = request.security(syminfo.tickerid, 'D', low[1]) 

plot(timeframe.isintraday ? D_High : na, title="Daily High", color=color.green,linewidth=2)
plot(timeframe.isintraday ? D_Low : na, title="Daily Low", color=color.red,linewidth=2) 

输出:

但是显示错误。有什么想法吗?

Pine v1-v2 的 security() 函数默认使用 lookahead 参数,可以在 v3-v5 中使用 lookahead= 参数进行修改。为了匹配结果声明 barmerge.lookahead_on:

//@version=5
indicator(title="Previous Day High and Low New", shorttitle="Previous Day High and Low New", overlay=true)

D_High = request.security(syminfo.tickerid, 'D', high[1], lookahead = barmerge.lookahead_on) 
D_Low = request.security(syminfo.tickerid, 'D', low[1], lookahead = barmerge.lookahead_on) 

plot(timeframe.isintraday ? D_High : na, title="Daily High", color=color.green,linewidth=2)
plot(timeframe.isintraday ? D_Low : na, title="Daily Low", color=color.red,linewidth=2)