Commitment of Traders (COT) in tradingview

Some theory to add background

I continue studying about market breadth, and this time I’m creating a script for the analysis of the Commitment of Traders.

The Commitment of Traders (COT) reports show futures traders’ positions at the close of (usually) Tuesday’s trading session. The report is prepared by the Commodity Futures Trading Commission (CFTC). It is an excellent trading tool and can be used as an indicator for analyzing market sentiment.

Markets are only included if 20 or more traders hold positions equal to or above the reporting levels established by the CFTC and the respective exchanges.

Traders are grouped into categories:

  • Commercial Traders,
  • Non-Commercial Traders (large speculators)
  • Non-reportable (small speculators).

COTs on tradingview

Right now there is no direct data in tradingview related to COTs. But you can work with this data accesing through Quandl. Only Legacy format is available for tradingview.

MagicEins provides on this script a code and an explanation about how to use this data, It contains all symbols available, and he provides updates.

The main codes I’m interested are:

  • Russell 2000 E-Mini (RTY) == “239742”
  • S&P 500 (SP) == “138741”
  • Dow Jones Industrial Average Index (DJIA) == “12460P”

The colours used are:

  • Commercials ==  blue
  • Large Speculators ==  red
  • Speculators net   ==  green

I added 3 inputs to enable to draw just the COTs you want:

Code example

study("Market Breadth P2 CoTs-joapen", shorttitle="Market-Breadth-P2CoTs-joapen", precision=0)

shortnegative = input(title="Show Shorts as negative numbers?", type=bool, defval=false)
showCommercials = input(title = "show Commercials?", type=bool, defval=true)
showLargeSpeculators = input(title = "show Large Speculators?", type=bool, defval=false)
showSmallSpeculators = input(title = "show Small Speculators?", type=bool, defval=false)

snn = shortnegative ? -1 : 1

quandl_futures_code =
	  syminfo.root == "ZB" ? "020601" : 
	  syminfo.root == "ZN" ? "043602" : 
	  syminfo.root == "ZS" ? "005602" : 
	  syminfo.root == "ZM" ? "026603" : 
	  syminfo.root == "ZL" ? "007601" : 
	  syminfo.root == "ZC" ? "002602" : 
	  syminfo.root == "ZW" ? "001602" : 
	  syminfo.root == "KE" ? "001612" : 
	  syminfo.root == "HE" ? "054642" : 
	  syminfo.root == "LE" ? "057642" : 
	  syminfo.root == "GC" ? "088691" : 
	  syminfo.root == "SI" ? "084691" : 
	  syminfo.root == "HG" ? "085692" : 
	  syminfo.root == "CL" ? "067651" : 
	  syminfo.root == "HO" ? "022651" : 
	  syminfo.root == "RB" ? "111659" : 
	  syminfo.root == "NG" ? "023651" : 
	  syminfo.root == "6A" ? "232741" : 
	  syminfo.root == "6B" ? "096742" : 
	  syminfo.root == "6C" ? "090741" : 
	  syminfo.root == "6E" ? "099741" : 
	  syminfo.root == "6J" ? "097741" : 
	  syminfo.root == "6S" ? "092741" : 
	  syminfo.root == "SB" ? "080732" : 
	  syminfo.root == "KC" ? "083731" : 
	  syminfo.root == "CC" ? "073732" : 
	  syminfo.root == "CT" ? "033661" : 
	  syminfo.root == "ES" ? "13874A" : 
	  syminfo.root == "RTY" ? "239742" : 
	  syminfo.root == "YM" ? "12460P" : 
	  syminfo.root == "NQ" ? "209742" : 
	  syminfo.root == "PA" ? "075651" : 
	  syminfo.root == "PL" ? "076651" : 
	  syminfo.root == "AUP" ? "191693" : 
	  syminfo.root == "HRC" ? "192651" : 
	  syminfo.root == "EH" ? "025651" : 
	  syminfo.root == "BB" ? "06765T" : 
	  syminfo.root == "ZR" ? "039601" : 
	  syminfo.root == "ZO" ? "004603" : 
	  syminfo.root == "DC" ? "052641" : 
	  syminfo.root == "OJ" ? "040701" : 
	  syminfo.root == "LBS" ? "058643" : 
	  syminfo.root == "GF" ? "061641" : 
	  syminfo.root == "SP" ? "138741" : 
	  syminfo.root == "DJIA" ? "12460P" : 
	  syminfo.root == "6N" ? "112741" : 
	  syminfo.root == "6L" ? "102741" : 
	  syminfo.root == "VX" ? "1170E1" : 
	  syminfo.root == "6M" ? "095741" : 
	  syminfo.root == "6R" ? "089741" : 
	  syminfo.root == "6Z" ? "122741" : 
	  syminfo.root == "ZT" ? "042601" : 
	  syminfo.root == "ZF" ? "044601" : 
    ""
    
quandl_code = "QUANDL:CFTC/" + quandl_futures_code + "_F_L_ALL"

comm_long = security (quandl_code + "|4", "D", close)
comm_short = security (quandl_code + "|5", "D", close)
lspecs_long = security (quandl_code + "|1", "D", close)
lspecs_short = security (quandl_code + "|2", "D", close)
sspecs_long = security (quandl_code + "|8", "D", close)
sspecs_short = security (quandl_code + "|9", "D", close)

// showCommercials  --- blue
plot (showCommercials?comm_long:na, color = blue, title = "Commercials long", style=line,linewidth=1,transp=0)
plot (showCommercials?comm_short*snn:na, color = purple, title = "Commercials short", style=line,linewidth=1,transp=0)
plot (showCommercials?comm_long - comm_short:na, color = blue, title = "Commercials net", style=line,linewidth=2,transp=50)
// showLargeSpeculators  ---   red
plot (showLargeSpeculators?lspecs_long:na, color = red, title = "Large Speculators long", style=line,linewidth=1,transp=0)
plot (showLargeSpeculators?lspecs_short*snn:na, color = orange, title = "Large Speculators short", style=line,linewidth=1,transp=0)
plot (showLargeSpeculators?lspecs_long - lspecs_short:na, color = red, title = "Large Speculators net", style=line,linewidth=2,transp=50)
// showSmallSpeculators  ---- green
plot (showSmallSpeculators?sspecs_long:na, color = green, title = "Small Speculators long", style=line,linewidth=1,transp=0)
plot (showSmallSpeculators?sspecs_short*snn:na, color = olive, title = "Small Speculators short", style=line,linewidth=1,transp=0)
plot (showSmallSpeculators?sspecs_long - sspecs_short:na, color = green, title = "Small Speculators net", style=line,linewidth=2,transp=50)
// horizontal line
hline(0, color=black, title = "Zero", linestyle=dotted,linewidth=1)

Tradingster, Commitments of Traders (COT) reports

Tradingster.com provides free COT charts and COT reports. The Commitments of Traders (COT) reports provide a breakdown of each Tuesday’s open interest for markets in which 20 or more traders hold positions equal to or above the reporting levels established by the CFTC.

The original COT report is text based and doesn’t include any charts or analytics tools. Tradingster provides you charts for COT report, which is great.