Diabolicus

Volume Weighted Market Mean [Dia]

Calculate a volume weighted market mean price across various exchanges.
Indicator shows mean values of high, low and ohcl/4, weighted by corresponding volume .
- Optional: display of simple arithmetic mean of prices
- Optional: additional price lines for single exchanges.
- EMA smoothing of results
Remove from Favorite Scripts Add to Favorite Scripts
study(title="Volume Weighted Market Mean [Dia]", shorttitle="VWMM_Dia", overlay=true)
// 141113 v1.0
// https://www.tradingview.com/script/dVXD7lus-Exchange-Comparison-Diabolicus/
// 150907 v2.0 (now volume weighted)
// Calculate a volume weighted market mean price across various exchanges.
// Indicator shows mean values of high, low and ohcl/4, weighted by corresponding volume.
// - Optional: display of simple arithmetic mean of prices
// - Optional: additional price lines for single exchanges.
// - EMA smoothing of results
//
mean_ema = input(2,title="Mean Values EMA Smoothing")
s_pm = input(1, title="Show simple arithmetic mean?")
sing = input(0, title="Show Single Exchanges?")
s_okcs = input(1, title="Show OKCoin Spot?")
s_okc1 = input(1, title="Show OKCoin 1W Future?")
s_okc2 = input(1, title="Show OKCoin 2W Future?")
s_okc3 = input(1, title="Show OKCoin 3M Future?")
s_stamp = input(1, title="Show Bitstamp?")
s_bfx = input(1, title="Show Bitfinex?")
s_btce = input(1, title="Show BTC-E?")
s_kraken = input(1, title="Show Kraken?")

sym_hl4(s)=>security(s,period,ohlc4)
sym_h(s)=>security(s,period,high)
sym_l(s)=>security(s,period,low)
sym_v(s)=>security(s,period,volume)

// load exchange rates
eurusd = sym_hl4("FX:EURUSD")
usdcnh = sym_hl4("FX:USDCNH")

// adjust for base currency other than USD
base = ticker == "XBTEUR" ? 2 : ticker == "BTCEUR" ? 2 : ticker == "BTCCNY" ? 3 : 1

basefactor = base==2 ? 1/eurusd : base==3 ? usdcnh : 1


// s = spot
// p = price
// 1 = 1W future
// 1 = 2W future
// 1 = 3M future
// v = volume
// Exchange pairs must be normalized to USD, so multiply by EURUSD or divide by USDCNH respectively
okc_sp = sym_hl4("OKCOIN:BTCUSD") * basefactor
okc_sh = sym_h("OKCOIN:BTCUSD") * basefactor
okc_sl = sym_l("OKCOIN:BTCUSD") * basefactor
okc_sv = sym_v("OKCOIN:BTCUSD") * basefactor
okc_1p = sym_hl4("OKCOIN:BTCUSD1W") * basefactor
okc_1h = sym_h("OKCOIN:BTCUSD1W") * basefactor
okc_1l = sym_l("OKCOIN:BTCUSD1W") * basefactor
okc_1v = sym_v("OKCOIN:BTCUSD1W") * basefactor
okc_2p = sym_hl4("OKCOIN:BTCUSD2W") * basefactor
okc_2h = sym_h("OKCOIN:BTCUSD2W") * basefactor
okc_2l = sym_l("OKCOIN:BTCUSD2W") * basefactor
okc_2v = sym_v("OKCOIN:BTCUSD2W") * basefactor
okc_3p = sym_hl4("OKCOIN:BTCUSD3M") * basefactor
okc_3h = sym_h("OKCOIN:BTCUSD3M") * basefactor
okc_3l = sym_l("OKCOIN:BTCUSD3M") * basefactor
okc_3v = sym_v("OKCOIN:BTCUSD3M") * basefactor
stamp_sp = sym_hl4("BITSTAMP:BTCUSD") * basefactor
stamp_sh = sym_h("BITSTAMP:BTCUSD") * basefactor
stamp_sl = sym_l("BITSTAMP:BTCUSD") * basefactor
stamp_sv = sym_v("BITSTAMP:BTCUSD") * basefactor
bfx_sp = sym_hl4("BITFINEX:BTCUSD") * basefactor
bfx_sh = sym_h("BITFINEX:BTCUSD") * basefactor
bfx_sl = sym_l("BITFINEX:BTCUSD") * basefactor
bfx_sv = sym_v("BITFINEX:BTCUSD") * basefactor
btce_sp = sym_hl4("BTCE:BTCUSD") * basefactor
btce_sh = sym_h("BTCE:BTCUSD") * basefactor
btce_sl = sym_l("BTCE:BTCUSD") * basefactor
btce_sv = sym_v("BTCE:BTCUSD") * basefactor
kraken_sp = sym_hl4("KRAKEN:XBTEUR") * eurusd * basefactor
kraken_sh = sym_h("KRAKEN:XBTEUR") * eurusd * basefactor
kraken_sl = sym_l("KRAKEN:XBTEUR") * eurusd * basefactor
kraken_sv = sym_v("KRAKEN:XBTEUR") * eurusd * basefactor

//calculate cumulative volume
cum_v =(okc_sv+okc_1v+okc_2v+okc_3v+stamp_sv+bfx_sv+btce_sv+kraken_sv)

// calculate volume weighted mean
mean = (okc_sp*okc_sv+okc_1p*okc_1v+okc_2p*okc_2v+okc_3p*okc_3v+stamp_sp*stamp_sv+bfx_sp*bfx_sv+btce_sp*btce_sv+kraken_sp*kraken_sv)/cum_v
mean_h = (okc_sh*okc_sv+okc_1h*okc_1v+okc_2h*okc_2v+okc_3h*okc_3v+stamp_sh*stamp_sv+bfx_sh*bfx_sv+btce_sh*btce_sv+kraken_sh*kraken_sv)/cum_v
mean_l = (okc_sl*okc_sv+okc_1l*okc_1v+okc_2l*okc_2v+okc_3l*okc_3v+stamp_sl*stamp_sv+bfx_sl*bfx_sv+btce_sl*btce_sv+kraken_sl*kraken_sv)/cum_v

// calculate price weighted mean for comparison
mean_2 = (okc_sp+okc_1p+okc_2p+okc_3p+stamp_sp+bfx_sp+btce_sp+kraken_sp) / 8

// plot single exchanges
plot(sing and s_okcs ? okc_sp : na,color=#0000BB)
plot(sing and s_okc1 ? okc_1p : na,color=#3333BB)
plot(sing and s_okc2 ? okc_2p : na,color=#6666BB)
plot(sing and s_okc3 ? okc_3p : na,color=#9999BB)
plot(sing and s_stamp ? stamp_sp : na,color=#00BB00)
plot(sing and s_bfx ? bfx_sp : na,color=#BB6600)
plot(sing and s_btce ? btce_sp : na,color=#66BB00)
plot(sing and s_kraken ? kraken_sp : na,color=#00FF66)

// plot mean values
mean_vw = plot(ema(mean,mean_ema),color=red,linewidth=2)
mean_high = plot(ema(mean_h,mean_ema),color=red)
mean_low = plot(ema(mean_l,mean_ema),color=red)
fill(mean_high, mean_low, color=red, transp=80)
mean_pw = plot(s_pm ? ema(mean_2,mean_ema) : na,color=yellow,linewidth=2)
Diabolicus
a year ago
Update here:
Volume Weighted Market Mean 3.0 [Dia]
Reply
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