// © unnoticed_owl //@version=5 indicator("~~Delta Volume Candles", explicit_plot_zorder = true) //---- Inputs cvdNew = input( true, "CVD New?") vol_fast_length = input( 7, "Fast Length") vol_slow_length = input( 14, "Slow Length") vol_normalization_length = input( 6, "Vol. Norm. Length") col_vpfast = color.rgb(71, 99, 224) col_vpslow = color.rgb(233, 78, 125) col_price_rising = color.rgb(177, 177, 177) col_price_falling = color.rgb(44, 44, 44) //---- Variables length = 0, vol_n = 0.0 //---- Functions vol_price(v, p) => v * p //----Normalization Function n(s,l) => hi = ta.highest(s, l) lo = ta.lowest(s, l) n = (s - lo) / (hi - lo)+1 n //// Delta calculation with normalized volume and LTF delta_ltf(vol) => vbuy=0.0, vsell=0.0, d=0.0, vvv = 0.0 v = volume if close > open vbuy := v * (close/open - 1) //vbuy := volume - vsell if close < open vsell := v * ( open/close -1 ) //vsell := volume - vbuy d := vbuy - vsell d //---- Calculations vol_fast = ta.ema(volume, vol_fast_length) price_fast = ta.ema(close, vol_fast_length) vp_fast = vol_price( vol_fast, price_fast ) ma_vp_fast = ta.sma( vp_fast, 3) vol_slow = ta.ema( volume, vol_slow_length ) price_slow = ta.ema( close, vol_slow_length) vp_slow = vol_price( vol_slow, price_slow ) ma_vp_slow = ta.sma(vp_slow, 3) vp_difference = vp_fast - vp_slow vol_normalized = n(volume, vol_normalization_length) vol_normalized := (vol_normalized -1.5) * 2 ma_vol_normalized = ta.alma(vol_normalized, 12, .7, 6) col_ma_vol = ma_vol_normalized > ma_vol_normalized[2] ? color.teal : ma_vol_normalized < ma_vol_normalized[2] ? color.maroon : color.gray vol_difference = vol_fast - vol_slow price_difference = price_fast - price_slow price_difference_max = ta.highest( price_difference, vol_slow_length) price_difference_min = ta.lowest( price_difference, vol_slow_length) price_difference_normalized = ( price_difference - price_difference_min ) / ( price_difference_max - price_difference_min ) col_price_difference = color.from_gradient( price_difference_normalized, 0, 1, col_price_falling, col_price_rising) //transparency_price_change = () //---- CVD //// CVD Fast LTF - New formula by maruf //// delta_array = array.new_float( initial_value = 0.0) cvd_new = 0.0 //length := input.int(14, "Fast CVD Length", tooltip = "Length used in Fast CVD", group = "CVD") length := input.int( 12, "New formula CVD length") //thresholdCVDNew = input(0.60, "CVD New Alert Threshold") vol_length = input(24, "New CVD Norm. Vol. Length") vol_n := n(volume, vol_length) delta_array := request.security_lower_tf( syminfo.tickerid, "1", delta_ltf(vol_n)) delta_ = array.sum(delta_array) delta_highest = array.max( delta_array ) delta_lowest = array.min( delta_array ) delta_open = array.get( delta_array, 0) last_index = array.size(delta_array) -1 //delta_close = array.get( delta_array, last_index ) //delta_candle_color = delta_open > delta_close ? color.lime : color.maroon //plotcandle( delta_open, delta_highest, delta_lowest, delta_close, color = delta_candle_color, wickcolor = delta_candle_color) //cvd_new := (n(delta_, length) - 1.5) *2 cvd_new := ta.alma( delta_, length, .6, 7) rma_cvd_new = ta.rma(cvd_new, 2) col00 = cvd_new > rma_cvd_new ? color.rgb(160, 247, 80) : color.rgb(55, 87, 26) xx1 = plot( cvdNew ? cvd_new : na, color = col00, linewidth = 1, style = plot.style_line) xx2 = plot( cvdNew ? rma_cvd_new : na, color = col00, style = plot.style_line) fill(xx1, xx2, color=col00) //---- Plots //z1 = plot( ma_vol_normalized, color=col_ma_vol, linewidth = 2) //z2 = plot( ma_vol_normalized[2], color=col_ma_vol) //fill(z1, z2, color = col_ma_vol ) //plot(ma_vp_fast, color=col_vpfast, style = plot.style_line) //plot(ma_vp_slow, color=col_vpslow, linewidth = 2) //plot( vp_difference, color=color.rgb(0, 102, 255)) bgcolor( col_price_difference )