前一天的高和低使用Pine脚本V5

发布于 2025-01-23 07:33:45 字数 1340 浏览 0 评论 0原文

我正在尝试将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) 

输出:

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

I am trying to convert a pinescript from v1 to 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) 

Output:
enter image description here

v1 is working fine.

I am trying to convert 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) 

Output:
enter image description here

But its showing wrong. Any Idea?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

我很坚强 2025-01-30 07:33:45

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) 

Pine v1-v2's security() function is using the lookahead parameter by default, which could be modified in v3-v5 with the lookahead= argument. To match the result declare the 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) 
孤凫 2025-01-30 07:33:45

Code:

//@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)

Result:

Code:

//@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)

Result:
enter image description here

-柠檬树下少年和吉他 2025-01-30 07:33:45

逻辑是错误的,因为它是在新的一天中绘制的两天。
查看此版本:

//@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)

The logic was wrong because it was plotting the 2 days back on a new day.
Check out this version:

//@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)
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文