Pine脚本代码正在重绘,有人可以帮我解决吗?

huangapple go评论97阅读模式
英文:

Pine script code is Repaiting, can someone help me resolve it?

问题

我正在尝试计算每日范围并在市场开盘时绘制水平线。代码运行正常,但在一天内,水平线往往会移动,最终要么移动到更高的水平,要么移动到更低的水平。我使用了request.security函数调用,并尝试避免重绘,但由于函数调用中的源是浮点数据系列,我无法修复脚本。

[day_adr, day_adr_high, day_adr_low] = request.security(syminfo.tickerid, 'D', adr_levels(daily_adr_length), barmerge.gaps_on, lookahead=barmerge.lookahead_on)

我尝试了下面链接中提到的不同方法,但无法解决问题。

https://www.tradingview.com/script/cyPWY96u-How-to-avoid-repainting-when-using-security-PineCoders-FAQ/

英文:

I am trying to calculate daily range and plot levels when market session opens. Code works fine but during day levels tend to move and eventually either higher level or lower level which was plotted in morning moves and come to either highest or lowest of day. I am using request.security function call and tried to avoid repainting but since source in function call is series float data I am not able to fix the script.

[day_adr, day_adr_high, day_adr_low] = request.security(syminfo.tickerid, 'D', adr_levels(daily_adr_length), barmerge.gaps_on, lookahead=barmerge.lookahead_on)

I tried to implement different ways noted in below link but not able to solve it.

https://www.tradingview.com/script/cyPWY96u-How-to-avoid-repainting-when-using-security-PineCoders-FAQ/

答案1

得分: 0

从松树参考文档中:
lookahead(简单的barmerge_lookahead)仅在历史柱上返回时间段结束之前的数据。可能的值为:barmerge.lookahead_on,barmerge.lookahead_off。对实时值没有影响。可选的。从Pine Script™ v3开始,默认值为barmerge.lookahead_off。在v1和v2中,默认值为barmerge.lookahead_on。警告:在高于图表时间框架的时间框架上使用barmerge.lookahead_on,而不对expression参数进行偏移,例如close[1],将在脚本中引入未来泄漏,因为该函数将返回当前上下文中实际上尚未知道的close价格。如用户手册中关于重绘的页面所解释的那样,这将产生误导性的结果。

因此,请使用lookahead = barmerge.lookahead_off
或通过添加[1]将表达式更改为前一个索引。
仅使用来自已关闭的柱的所有数据,这将避免重绘。

英文:

from pine reference:
lookahead (simple barmerge_lookahead) On historical bars only, returns data from the timeframe before it elapses. Possible values: barmerge.lookahead_on, barmerge.lookahead_off. Has no effect on realtime values. Optional. The default is barmerge.lookahead_off starting from Pine Script™ v3. The default is barmerge.lookahead_on in v1 and v2. WARNING: Using barmerge.lookahead_on at timeframes higher than the chart's without offsetting the expression argument like in close[1] will introduce future leak in scripts, as the function will then return the close price before it is actually known in the current context. As is explained in the User Manual's page on Repainting this will produce misleading results.

So use lookahead = barmerge.lookahead_off
or change your expression to the previous index by adding [1].
Take all data from closed bars only and it will avoid repainting.

huangapple
  • 本文由 发表于 2023年7月27日 17:10:47
  • 转载请务必保留本文链接:https://go.coder-hub.com/76778192.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定