bjbuckley

_CM_COT Commercial Net Interest_V2 1

cot
73 0 8
cot
Minor Code changes to clean things up a bit
Remove from Favorite Scripts Add to Favorite Scripts
//Created by ChrisMoody on 3-30-2015
//Modified by BJBuckley on 8-22-2015
//Shows Net Commercials
//Full Credit goes to Greeny fo rcreating original code.  Chris only made slight modifications.
//Chris's Modifications include - Taking away Net Longs and Shorts, Adding Background Highlighting when Commercials go from Long to Short
//My Modifications include - increasing the instrument force codes to the commodities set from just the currencies
//Methodology Is from Jake Bernstein at www.Trade-Futures.com and www.2Chimps.net

study("_CM_COT Commercial Net Interest_V2", shorttitle="_CM_COT Commercial Net Int_V2", precision=0)
force_root = input("", title="Override Product")
is_includeoptions = input(false, type=bool, title="Include Options")
si = input(false, type=bool, title="Show Inverse")
sbc = input(false, type=bool, title="Color Price Bars?")
sbg = input(true, type=bool, title="Show Background Highlight when Commercials Change From Buying to Selling?")
sa1 = input(true, type=bool, title="Alert If Commercials Change From Buying to Selling?")
sa2 = input(true, type=bool, title="Alert If Commercials Change From Selling to Buying?")

fxroot =
	  ticker == "USDCAD" ? "CD" : 
	  ticker == "USDCAD" ? "CD" : 
	  ticker == "USDCHF" ? "SF" : 
	  ticker == "USDCZK" ? "CZ" : 
	  ticker == "USDHUF" ? "FR" : 
	  ticker == "USDILS" ? "IS" : 
	  ticker == "USDJPY" ? "JY" : 
	  ticker == "USDMXN" ? "MP" : 
	  ticker == "USDNOK" ? "UN" : 
	  ticker == "USDPLN" ? "PZ" : 
	  ticker == "USDRUB" ? "RU" : 
	  ticker == "USDSEK" ? "SE" : 
	  ticker == "USDZAR" ? "RA" : 
	  ticker == "EURUSD" ? "EC" :
	  ticker == "E61!" ? "EC" :
	  ticker == "S61!" ? "SF" :
	  ticker == "J61!" ? "JY" :
	  ticker == "D61!" ? "CD" :
	  ticker == "A61!" ? "AD" :
	  ticker == "N61!" ? "NE" :
	  ticker == "B61!" ? "BP" :
	  ticker == "M61!" ? "MP" :
	  ticker == "AUDUSD" ? "AD" : 
	  ticker == "GBPUSD" ? "BP" : 
	  ticker == "NZDUSD" ? "NE" : 
	  ticker == "BRLUSD" ? "BR" : 
	  ticker == "COPPER" ? "HG" :
	  ticker == "LE1!" ? "LC" : 
	  ticker == "GF1!" ? "FC" : 
	  ticker == "HE1!" ? "LH" : 
	  ticker == "ZN1!" ? "TY" : 
	  ticker == "ZB1!" ? "US" : 
	  ticker == "ES1!" ? "SP" : 
	  ticker == "NY1!" ? "NK" :
	  ticker == "USOIL" ? "CL" :
	  ticker == "ZC1!" ? "C" :
	  ticker == "ZS1!" ? "S" :
	  ticker == "ZM1!" ? "SM" :
	  ticker == "ZL1!" ? "BO" :
	  ticker == "ZW1!" ? "W" :
	  ticker == "KE1!" ? "KW" :
	  ticker == "ZO1!" ? "O" :
	  ticker == "ZR1!" ? "RR" :
	  ""
root = force_root == "" ? fxroot == "" ? syminfo.root : fxroot : force_root
code = root + (is_includeoptions ? "_FO_L_ALL" : "_F_L_ALL")

is_inversed = 
	  ticker == "USDCAD" ? true : 
	  ticker == "USDCAD" ? true : 
	  ticker == "USDCHF" ? true : 
	  ticker == "USDCZK" ? true : 
	  ticker == "USDHUF" ? true : 
	  ticker == "USDILS" ? true : 
	  ticker == "USDJPY" ? true : 
	  ticker == "USDMXN" ? true : 
	  ticker == "USDNOK" ? true : 
	  ticker == "USDPLN" ? true : 
	  ticker == "USDRUB" ? true : 
	  ticker == "USDSEK" ? true : 
	  ticker == "USDZAR" ? true : 
	  false

long_total = security("QUANDL:CFTC/"+code+"|4", "W", close)
short_total = security("QUANDL:CFTC/"+code+"|5", "W", close)
//Code for Commercials Net Totals
long = is_inversed ? short_total : long_total
short = is_inversed ? long_total : short_total
net = long - short

//Alert criteria
alert1 = net[1] > 0 and net < 0 ? 1 : 0
alert2 = net[1] < 0 and net > 0 ? 1 : 0

//Code for Histogram Color
col = net > net[1] ? green : red

plot(si and long-short ? (long-short)*-1 : long-short, color = col, title="Net", style=columns)
hline(0, color=black, linestyle=dashed)
barcolor(sbc and (net[1] > 0 and net < 0) ? orange : na)
bgcolor(sbg and (net[1] > 0 and net < 0) ? lime : na, transp=20)
bgcolor(sbg and (net[1] < 0 and net > 0) ? orange : na, transp=20)

plot(sa1 and alert1 ? alert1 : 0, title="Alert If Commercials Go From Net Buy to Sell", style=line, linewidth=1, color=lime)
plot(sa2 and alert2 ? alert2 : 0, title="Alert If Commercials Go From Net Sell to Buy", style=line, linewidth=1, color=orange)
Ideas Scripts Chart
United States
United Kingdom
India
España
Italia
Brasil
Россия
Türkiye
日本
한국
Home Stock Screener Economic Calendar How It Works Chart Features House Rules Moderators For the WEB Widgets Stock Charting Library Priority Support Feature Request Blog & News FAQ Help & Wiki Twitter
Private Messages Chat Ideas Published Followers Following Priority Support Public Profile Profile Settings Billing Sign Out