使用 Pine Script v5 计算前一日最高价和最低价

问题描述 投票:0回答:3

我正在尝试将 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-script trading tradingview-api pine-script-v5
3个回答
1
投票

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) 

0
投票

逻辑是错误的,因为它将 2 天绘制在新的一天上。 看看这个版本:

//@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) 
D_Low = request.security(syminfo.tickerid, 'D', low) 

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)

0
投票

代码:

//@version=5
indicator(title='PDHL', shorttitle='PDHL', overlay=true)

// Get OHLC Data
i_timeframe ='D'
i_past = 1
[high_price, low_price]  = request.security(symbol=syminfo.tickerid, timeframe=i_timeframe, expression=[high[i_past], low[i_past]], lookahead=barmerge.lookahead_on)

// Hide Historical Plots
i_showlast = false
htf_islast = i_showlast ? request.security(symbol=syminfo.tickerid, timeframe=i_timeframe, expression=barstate.islast, lookahead=barmerge.lookahead_on) : true

// Plot
high_break = high_price == high_price[1]
low_break = low_price == low_price[1]

plot(series=htf_islast and high_break ? high_price : na, title='High', color=#FF00ff, linewidth=2, style=plot.style_steplinebr, offset=-1)
plot(series=htf_islast and low_break ? low_price : na, title='Low', color=#00FFFF, linewidth=2, style=plot.style_steplinebr, offset=-1)

结果:

© www.soinside.com 2019 - 2024. All rights reserved.