Mayank Jain
Mayank Jain

Reputation: 3205

Tradingview only shows Quandl CFTC data for last week

i'm using pine script to pull CFTC COT data into my indicator. However, I am noticing that the latest row of data is never pulled from CFTC - the indicator only shows last week's data.

CFTC data is released every Friday 3:30 PM EST. I am viewing this data on a Saturday - so am expecting to see data released in yesterday's report.

Here's the script i'm using (the outcome does not changes if I use resolution=D or W in the security function in pine script)

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

Has anyone else also faced this problem? Any potential solutions?

Thanks!

Data that shows up on the chart Data that's expected on the chart

Upvotes: 0

Views: 817

Answers (1)

PineCoders-LucF
PineCoders-LucF

Reputation: 8789

One thing to try would be to use lookahead=barmerge.lookahead_on in your security() calls. This may fix the problem in the realtime bar, but will OTOH make your calls use future data on historical bars, where you will need to use the form you are currently using to avoid the lookahead bias.

If using lookahead on is indeed the solution, you could use code like this:

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

Upvotes: 1

Related Questions