首页 > 解决方案 > Tradingview 仅显示上周 Quandl CFTC 数据

问题描述

我正在使用 pine 脚本将 CFTC COT 数据提取到我的指标中。但是,我注意到最新一行数据从未从 CFTC 中提取 - 该指标仅显示上周的数据。

CFTC 数据在美国东部标准时间每周五下午 3:30 发布。我在周六查看这些数据 - 所以我期待看到昨天报告中发布的数据。

这是我正在使用的脚本(如果我在 pine 脚本的安全功能中使用 resolution=D 或 W,结果不会改变)

//@version=4
study("COT data bug", shorttitle="Bug demo", precision=0)

qticker =
     syminfo.root == "ES" ? "13874A" :
     syminfo.root == "NQ" ? "209742" :
     syminfo.root == "RTY" ? "239742":
     syminfo.root == "YM" ? "124603" :
     syminfo.root == "ZN" ? "043602" :
     syminfo.root

cot = "QUANDL:CFTC/" + qticker + "_FO_ALL|"
oi = security(cot + "0", "W", close)
asset_mgr_lg = security(cot + "4", "W", close)
asset_mgr_sh = security(cot + "5", "W", close)

plot(oi, title="Open Interest", color=color.black)  // output=232,089, expected=230,513
plot(asset_mgr_lg, title="asset_mgr_lg", color=color.blue) // output=71,131, expected=65,170
plot(asset_mgr_sh, title="asset_mgr_sh", color=color.red) // output=29,288, expected=31,260

有没有其他人也遇到过这个问题?任何潜在的解决方案?

谢谢!

图表上显示的数据 图表上预期的数据

标签: pine-script

解决方案


要尝试的一件事是lookahead=barmerge.lookahead_on在您的security()通话中使用。这可能会解决实时柱中的问题,但 OTOH 会让您的调用使用历史柱上的未来数据,您需要使用当前使用的表格来避免前瞻偏差。

如果使用前瞻确实是解决方案,您可以使用如下代码:

oiH           = security(cot + "0", "W", close)
asset_mgr_lgH = security(cot + "4", "W", close)
asset_mgr_shH = security(cot + "5", "W", close)
oiR           = security(cot + "0", "W", close, lookahead = barmerge.lookahead_on)
asset_mgr_lgR = security(cot + "4", "W", close, lookahead = barmerge.lookahead_on)
asset_mgr_shR = security(cot + "5", "W", close, lookahead = barmerge.lookahead_on)

oi            = 0.
asset_mgr_lg  = 0.
asset_mgr_sh  = 0.
if barstate.islast
    oi            := oiR
    asset_mgr_lg  := asset_mgr_lgR
    asset_mgr_sh  := asset_mgr_shR
else
    oi            := oiH
    asset_mgr_lg  := asset_mgr_lgH
    asset_mgr_sh  := asset_mgr_shH

推荐阅读