Greeny

CFTC: COT (Legacy)

Commitment of Traders based on legacy format taken from quandl.com. In this version you need to select product when applying the indicator. In future version there might be some kind of auto mapping based on current symbol.
Open-source script

In true TradingView spirit, the author of this script has published it open-source, so traders can understand and verify it. Cheers to the author! You may use it for free, but reuse of this code in a publication is governed by House Rules. You can favorite it to use it on a chart.

Disclaimer

The information and publications are not meant to be, and do not constitute, financial, investment, trading, or other types of advice or recommendations supplied or endorsed by TradingView. Read more in the Terms of Use.

Want to use this script on a chart?
study("CFTC: COT (Legacy)", shorttitle="COT", precision=0)
root = input("EC", title="Product", confirm=true)
is_includeoptions = input(false, type=bool, title="Include Options")
code = root + (is_includeoptions ? "_FO_L_ALL" : "_F_L_ALL")
oi = security("QUANDL:CFTC/"+code+"|0", "D", close)

//commercials
long_noncom = security("QUANDL:CFTC/"+code+"|1", "D", close) 
short_noncom = security("QUANDL:CFTC/"+code+"|2", "D", close) 
spread_noncom = security("QUANDL:CFTC/"+code+"|3", "D", close) 

long_com = security("QUANDL:CFTC/"+code+"|4", "D", close) 
short_con = security("QUANDL:CFTC/"+code+"|5", "D", close) 

long_total = security("QUANDL:CFTC/"+code+"|6", "D", close) 
short_total = security("QUANDL:CFTC/"+code+"|7", "D", close) 

long_totalnonrep = security("QUANDL:CFTC/"+code+"|8", "D", close) 
short_totalnonrep = security("QUANDL:CFTC/"+code+"|9", "D", close) 

plot(oi, color = gray, title="Open Interest")
plot(long_noncom, color = green, title="Long Positions")
plot(short_noncom, color = red, title="Short Positions")
plot(spread_noncom, color = olive, title="Spread Positions")
plot(long_noncom-short_noncom, color = yellow, title="Net Positions")
hline(0, color=yellow, linestyle=dashed)
// total = long_noncom+short_noncom
// diff = long_noncom-short_noncom
// pcnt = diff/total
// plot(pcnt, color = red)