lcenovsky

COT Index by cendalc

956 14 163
Legacy and disaggregated COT index for several commodities I trade:
ZC             , ZW, ZS, ZL, ZM, HG, GC             , SI, CC             , KC, CT             , OJ, SB             , CL             , HO, NG            

Available indexes:
  • Commercials Index
  • Large traders Index
  • Producers Index
  • Managed Money Index

Data is taken from Quandl: https://www.quandl.com/data/CFTC

Default week period is 26 except for CC             , KC, CT             , OJ, SB             , CL             , HO and NG             where it is 13. You can set your own period.

Works correctly on weekly and daily data. Daily length is correctly computed from trade days in weeks.

Displays the previous cot index for the current week if COT report has not yet been published.

snapshot
Remove from Favorite Scripts Add to Favorite Scripts
//@version=2
study("COT Index by cendalc", shorttitle="COT Index", precision=1)

qticker =
     syminfo.root == "ZC" ? "C"  :
     syminfo.root == "ZW" ? "W"  :
     syminfo.root == "ZS" ? "S"  :
     syminfo.root == "ZL" ? "BO" :
     syminfo.root == "ZM" ? "SM" :
     syminfo.root == "HG" ? "HG" :
     syminfo.root == "GC" ? "GC" :
     syminfo.root == "SI" ? "SI" :
     syminfo.root == "CC" ? "CC" :
     syminfo.root == "KC" ? "KC" :
     syminfo.root == "CT" ? "CT" :
     syminfo.root == "OJ" ? "OJ" :
     syminfo.root == "SB" ? "SB" :
     syminfo.root == "CL" ? "CL" :
     syminfo.root == "HO" ? "HO" :
     syminfo.root == "NG" ? "NG" :
     ""

force_length = input(0, title="Weeks (0 = automatic)")

length =
     force_length != 0 ? force_length :
     syminfo.root == "CC" ? 13 :
     syminfo.root == "KC" ? 13 :
     syminfo.root == "CT" ? 13 :
     syminfo.root == "OJ" ? 13 :
     syminfo.root == "SB" ? 13 :
     syminfo.root == "CL" ? 13 :
     syminfo.root == "HO" ? 13 :
     syminfo.root == "NG" ? 13 :
     26

GetDailyAdjustment(weeks) =>
    weekCount = weeks
    daily_adjust = 1
    tmp = for i = 0 to (length * 5)
        weekCount := weekCount - iff(dayofweek[i] < dayofweek[i+1], 1, 0)
        if weekCount <= 0
            break
        daily_adjust := daily_adjust + 1
    daily_adjust

Highest(x, y) =>
    ret = x
    for i = 1 to y-1
        ret := max(ret, x[i])

Lowest(x, y) =>
    ret = x
    for i = 1 to y-1
        ret := min(ret, x[i])


legacy_cot = "QUANDL:CFTC/" + qticker + "_FO_L_ALL|"
cot = "QUANDL:CFTC/" + qticker + "_FO_ALL|"

oi = security(legacy_cot + "0", "W", close)

no_cot_adjst = oi == oi[1] ? 1 : 0
length_adjst = isdaily ? GetDailyAdjustment(length + no_cot_adjst) : length + no_cot_adjst

comm_lg = security(legacy_cot + "4", "W", close)
comm_sh = security(legacy_cot + "5", "W", close)
comm_net = comm_lg - comm_sh

large_lg = security(legacy_cot + "1", "W", close)
large_sh = security(legacy_cot + "2", "W", close)
large_net = large_lg - large_sh

other_lg = security(legacy_cot + "8", "W", close)
other_sh = security(legacy_cot + "9", "W", close)
other_net = other_lg - other_sh

comm_max = Highest(comm_net, length_adjst)
comm_min = Lowest(comm_net, length_adjst)
comm_idx = if (dayofweek > nz(dayofweek[1]))
    comm_idx[1]
else
    100 * (comm_net - comm_min) / (comm_max - comm_min)

large_max = Highest(large_net, length_adjst)
large_min = Lowest(large_net, length_adjst)
large_idx = if (dayofweek > nz(dayofweek[1]))
    large_idx[1]
else
    100 * (large_net - large_min) / (large_max - large_min)

prod_lg = security(cot + "1", "W", close)
prod_sh = security(cot + "2", "W", close)
prod_net = prod_lg - prod_sh

manag_lg = security(cot + "6", "W", close)
manag_sh = security(cot + "7", "W", close)
manag_net = manag_lg - manag_sh

prod_max = Highest(prod_net, length_adjst)
prod_min = Lowest(prod_net, length_adjst)
prod_idx = if (isdaily and (dayofweek > nz(dayofweek[1])))
    prod_idx[1]
else
    100 * (prod_net - prod_min) / (prod_max - prod_min)

manag_max = Highest(manag_net, length_adjst)
manag_min = Lowest(manag_net, length_adjst)
manag_idx = if (dayofweek > nz(dayofweek[1]))
    manag_idx[1]
else
    100 * (manag_net - manag_min) / (manag_max - manag_min)

plot(comm_idx, color=blue, title="Commercials Index", style=line, linewidth=2)
plot(large_idx, color=green, title="Large traders Index", style=line, linewidth=1)
plot(prod_idx, color=aqua, title="Producers Index", style=line, linewidth=2)
plot(manag_idx, color=lime, title="Managed Money Index", style=line, linewidth=1)
Hi,
great job, this is exactly what I was looking for. The only thing I miss is meats(Hogs/Cattle). Is it possible to add it?
I tried to add syminfo.root == "LE" ? "LE" : but it did not work. I am not a programmer, I just tried :-)
Can you help mo with this, please?
+1 Reply
@godi13, I cannot edit the script anymore - no idea why.
You need to add correct quandl mapping:

syminfo.root == "LE" ? "LC" :
syminfo.root == "GF" ? "FC" :
syminfo.root == "HE" ? "LN" :
Reply
godi13 lcenovsky
@lcenovsky, yes, that was the trick, different symbols LE/LC etc.
Thanks a lot
Reply
yarimedici lcenovsky
@lcenovsky, Hi! I can't get it to work with Gold
Can you tell me how to add it?
Reply
lcenovsky yarimedici
@yarimedici, gold is there already (GC)
Reply
yarimedici lcenovsky
@lcenovsky, Im sorry, just noticed!
Thanks for the reply!
+1 Reply
Zoran83 PRO lcenovsky
@lcenovsky, Oats, Corn and Rough Rice also not work with the standard symbols

Oats ZO?
Corn QBC?
Rough Rice QRR?

Do you know the right ones?
Thanks in advance
Reply
lcenovsky Zoran83
@Zoran83, search quandl - e.g. Oats is O: https://www.quandl.com/search?query=oats
Reply
Zoran83 PRO lcenovsky
@lcenovsky, Thanks!
Reply
Zoran83 PRO lcenovsky
@lcenovsky, if i want to see the small spreculators (non reportable) aslso, can i add this code after row 88? And which group these are?

non_lg = security(legacy_cot + "?", "W", close)
non_sh = security(legacy_cot + "?", "W", close)
non_net = other_lg - other_sh
Reply
United States
United Kingdom
India
Deutschland
France
España
Italia
Polska
Türkiye
Россия
Brasil
Indonesia
Malaysia
Việt Nam
日本
한국
简体
繁體
Home Stock Screener Forex Signal Finder Cryptocurrency Signal Finder Economic Calendar How It Works Chart Features House Rules Moderators Website & Broker Solutions Widgets Stock Charting Library Feature Request Blog & News FAQ Help & Wiki Twitter
Profile Profile Settings Account and Billing My Support Tickets Priority Support Contact Support Ideas Published Followers Following Private Messages Chat Sign Out