TradingView
twingall
Jun 18, 2022 4:33 PM

Metals:Backwardation/Contango 

Gold FuturesCOMEX

描述

METALS: Gold , Silver , Copper ( GC , SI, HG)

Quickly visualize carrying charge market vs backwardized market by comparing the price of the next 2 years of futures contracts.
Carrying charge (contract prices increasing into the future) = normal, representing the costs of carrying/storage of a commodity. When this is flipped to Backwardation (contract prices decreasing into the future): its a bullish sign: Buyers want this commodity, and they want it NOW.

Note: indicator does not map to time axis in the same way as price; it simply plots the progression of contract months out into the future; left to right; so timeframe DOESN'T MATTER for this plot
There's likely some more efficient way to write this; e.g. when plotting for Gold ( GC ); 21 of the security requests are redundant; but they are still made; and can make this slower to load
TO UPDATE(once a year will do): in REQUEST CONTRACTS section, delete old contracts (top) and add new ones (bottom). Then in PLOTTING section, Delete old contract labels (bottom); add new contract labels (top); adjust the X in 'bar_index-(X+_historical)' numbers accordingly

This is one of three similar indicators: Meats | Metals | Grains
-If you want to build from this; to work on other commodities ; be aware that Tradingview limits the number of contract calls to 40 (hence the 3 seperate indicators)

Tips:
-Right click and reset chart if you can't see the plot; or if you have trouble with the scaling.
-Right click and add to new scale if you prefer this not to overlay directly on price. Or move to new pane below.

--Added historical input: input days back in time; to see the historical shape of the Futures curve via selecting 'days back' snapshot
updated 15th June 2022
© twingall

版本注释

-updated contracts

版本注释

-added function to detect if contract is expired: Now will stop showing contracts once they expire, unless using the backtesting 'snapshot' mode
评论
SebR13
thank you for this, what do we need to change in the script to make it work on other commodities ? (don't know nothing about scripting...), or maybe can you make this indicator for softs too please ?
twingall
@THEWOLF13, so e.g. for sugar; SB
check TV for the contract codes. edit the //request contracts section with these only (remember to replace COMEX: with ICEUS:)
Then plotting section would be same shape as above, but with:
if barstate.islast and syminfo.root == 'SB'
then below that the label.new lines for each of the previously defined contracts. descending order (farthest out at top, just beneath snapshot label; nearby at bottom)

so when done you should have 11 contracts defined up top, and 11+1 label.new lines, with appropriate X+_historical numbers , and with the appropriate contract called
SebR13
@twingall, thank you very much for your answer, tried this for KC and it works !
user1928374560XYZ
can you do VX please?
twingall
更多