And now we are at 3.0. Cleaned up the code, made the colors friendly to those on white stylesheets. The Index is the same as the OKCoin.com settlement index, and it tracks the FX:USDCNY exchange pair. All exchanges have 1\6th weight. This is the closest we will get here on TV.
Now, I do understand there is a bug (I believe it is with TV); where if you compare two symbols with the / marker, not as much price history loads than if you just load a normal symbol. I do not have a workaround for this at the moment so we will just have to deal with incomplete data. It'll be fine.
// Spot price vs futures - Tradingview.com // @author lastbattle, lowstrife, Godmode 3.1, Legion, Carbon study(title="Index Vs Futures", shorttitle="Index Vs Futures 3.0") // Rcommend 3M futures for best signal // Futures: OKCOIN:BTCUSD1W, 796:BTCUSD1W, OKCOIN:BTCUSD2W, OKCOIN:BTCUSD3M, BITMEX:XBTH2016 //Security - can comment between line 12 and 13 to change between spot and index src_futures = security("OKCOIN:BTCUSD3M", period, hlc3) src_index = ((security("BITFINEX:BTCUSD", period, hlc3)+security("BITSTAMP:BTCUSD", period, hlc3)+security("OKCOIN:BTCUSD", period, hlc3)+security("OKCOIN:BTCCNY/FX_IDC:USDCNY", period, hlc3)+security("BTCCHINA:BTCCNY/FX_IDC:USDCNY", period, hlc3)++security("HUOBI:BTCCNY/FX_IDC:USDCNY", period, hlc3))/6) //src_index = security("OKCOIN:BTCCNY", period, hlc3) // Values difference = nz(nz(src_futures) - nz(src_index)) percent = nz(nz(difference) / nz(src_index)*100) len = input(21, minval=1, title="Length") length = input(21, minval=1) out = ema(percent, len) // Functions - The dots signal = out<-0 ? out+0.25 : out>4.5 ? out-0.25 : na // Plots plot(percent, style=line, linewidth=1, color=teal) plot(out, title="EMA", color=red) plot(signal, title="Caution!", color=yellow, style=circles, linewidth=1) band1 = hline(6) band0 = hline(-0.5)