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.
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)