// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/ // © maruful_bd_yhoo //@version=5 indicator("", overlay = false, explicit_plot_zorder = true) // Features of this script: // (*) CVD // (*) SPOT CVD // (**) CVD auto adjusts its length according to chart's timeframe. //// Constants color LIME = color.rgb(140, 255, 26) color GREEN = color.rgb(0, 230, 0) color CYAN = color.rgb(60,179,113) color RED = color.rgb(255,69,0) color CRIMSON = color.rgb(220,20,60) color MAROON = color.rgb(255, 0, 102) color BLUE = color.rgb(31,117,254) color YELLOW = color.rgb(255,255,102) color PURPLE = color.rgb(255, 15, 235) c1 = color.rgb(0, 153, 153) c2 = color.rgb(51, 102, 153) c4 = color.rgb(0,255,0) c5 = color.rgb(0,128,0) c6 = color.rgb(0,128,128) c7 = color.rgb(255,69,0) c8 = color.rgb(0,0,128) c9 = color.rgb(114, 184, 255) c11 = color.rgb(90, 90, 90) c12 = color.rgb(43, 43, 43) //// Inputs bool useManualBaseLookback = input.bool(false, "Use Manual Base Length?", tooltip = "Replaces Automatically Calculated Base Length Based On Chart Time Frame", group = "General") bardeltaComparisonLength = input.int(15, "Bar Delta Comp. Length", group = "CVD") //// Show/hide specific indicators show_cvd_fast = input(true, 'Show Fast CVD?', group = "CVD") show_cvd_normal = input(true, 'Show Normal CVD?', group = "CVD") show_rma_alert = input(true, 'Show CVD-RMA crossover alert?', group = "CVD") show_30mRotation = input(false, "Show 30m Rot. ?", group = "CVD") show_spot_cvd = input(false, "Show SPOT CVD?", group = "CVD") barcolor_delta_based = input(false, "Color bars : delta compared?", "Color bars based on comparing Delta(last bar) against CVD") showDSStoch = input.bool( true, "Show Double-smoothed Stochastic?") showSqueezeMomentum = input.bool( false, "Show Squeeze Momentum?") //// Colors bullish = input.color( color.rgb(78, 78, 78), inline = "Color scheme 1") bearish = input.color( color.rgb(8, 8, 8), inline = "Color scheme 1") bullish2 = input.color(color.rgb(53, 238, 167), inline = "Color scheme 2" ) bearish2 = input.color(color.rgb(13, 38, 63), inline = "Color scheme 2" ) bullish3 = input.color( color.rgb(51, 238, 238), inline = "Color scheme 3" ) bearish3 = input.color(color.rgb(255, 51, 133), inline = "Color scheme 3" ) bull_grad_top = input.color(color.rgb(0, 204, 153), "Bull Gradient 1") bull_grad_bottom = input.color( color.rgb(51, 153, 102), "Bull Gradient 2") bear_grad_top = input.color(color.rgb(255, 51, 0), "Bear Gradient Top") bear_grad_bottom = input.color(color.rgb(204, 0, 102), "Bear Gradient Bottom") cvd_barcolor1 = input.color(color.rgb(63,255,0), "CVD Bullish Bar") cvd_barcolor2 = input.color(color.rgb(195,33,72), "CVD Bearish Bar") //// Variables Initialization int baseLookback = 0 int l1 = 0, lenCVDFast = 0 if timeframe.multiplier==30 baseLookback := 8, lenCVDFast := 14 else if timeframe.multiplier==60 baseLookback := 4, lenCVDFast := 7 else useManualBaseLookback := true if useManualBaseLookback l1 := input( 4, "Smallest Base Lookback") else l1 := baseLookback l2 = l1 * 2 l3 = l1 * 3 l4 = int(l1 * 4.5) l5 = l1 * 5 l6 = l1 * 6 l7 = l6 * 3 l9 = l1 * 9 int length = 0 ltf_volume_ar = array.new_float(), ltf_delta = 0.0 v00 = 0.0, b00 = 0.0, s00 = 0.0 d00 = 0.0, nd00 = 0.0 bardelta = 0.0 vol_buy = 0.0, vol_sell = 0.0, vol_delta = 0.0 alertLong00 = false, alertShort00 = false, threshold00 = input(0.75, "Alert 00 Threshold", group = "CVD") //// Functions //----Normalization Function n(s,l) => hi = ta.highest(s, l) lo = ta.lowest(s, l) n = (s - lo) / (hi - lo)+1 n //// Delta calculation delta_function() => vbuy=0.0, vsell=0.0, d=0.0 if close > open vbuy := volume * math.abs( open/close -1 ) if close < open vsell := volume * math.abs( open/close -1 ) d := ta.cum(vbuy - vsell) d //// Delta calculation with normalized volume delta_function_norm(length_x) => vbuy=0.0, vsell=0.0, d=0.0 vol_n = n(volume, length_x) if close > open vbuy := vol_n * math.abs( open/close -1 ) if close < open vsell := vol_n * math.abs( open/close -1 ) d := ta.cum(vbuy - vsell) d := ( n(d, length_x) - 1.5 ) * 2 cvd = ta.alma(d, length_x, 0.85, 7) cvd //// Normal Speed CVD //// ltf_vol_ar = request.security_lower_tf(syminfo.tickerid, "1", volume, false) length := input(24, "Normal CVD length", "Length used for Normal CVD", group = "CVD") vol = ltf_vol_ar.sum() vol_n = n(vol, length) vol_buy := 0.0, vol_sell := 0.0, vol_delta := 0.0 [open_ltf_ar, close_ltf_ar] = request.security_lower_tf(syminfo.tickerid, "1", [open, close]) open_ltf = array.sum(open_ltf_ar) close_ltf = array.sum(close_ltf_ar) if close_ltf > open_ltf vol_buy := vol_n * math.abs(open_ltf / close_ltf - 1) vol_buy if close_ltf < open_ltf vol_sell := vol_n * math.abs(open_ltf / close_ltf - 1) vol_sell vol_delta := ta.cum(vol_buy-vol_sell) vol_delta := ( n(vol_delta, length) - 1.5 ) * 2 cvd_normal = ta.alma(vol_delta, length, 0.85, 7) rma_normal = ta.rma(cvd_normal, 2) //// CVD Fast //// //length := input.int(14, "Fast CVD Length", tooltip = "Length used in Fast CVD", group = "CVD") length := lenCVDFast vol_n := n(volume, length) [open_ltf_ar00, close_ltf_ar00] = request.security_lower_tf(syminfo.tickerid, "1", [open, close]) open_ltf := array.sum(open_ltf_ar00) close_ltf := array.sum(close_ltf_ar00) if close_ltf > open_ltf vol_buy := vol_n * math.abs(open_ltf / close_ltf - 1) vol_buy if close_ltf < open_ltf vol_sell := vol_n * math.abs(open_ltf / close_ltf - 1) vol_sell vol_delta := ta.cum(vol_buy - vol_sell) vol_delta := (n(vol_delta, length) -1.5)*2.0 cvd_fast = ta.alma(vol_delta,length,0.90,7) rma_fast = ta.rma(cvd_fast, 2) //// ALert : Bardelta v CVD //// bardelta := vol_delta cvd_bardelta = cvd_fast bardelta_diff = bardelta - cvd_bardelta alertLong01 = bardelta > cvd_bardelta ? true : false alertShort01 = bardelta < cvd_bardelta ? true : false //// peckerponzi original rotation //// //----Trigger Rotation lookback = l3 v00 := n(volume, lookback) if close > open b00 := v00 * math.abs(open / close - 1) b00 if close < open s00 := v00 * math.abs(open / close - 1) s00 d00 := ta.cum(b00 - s00) nd00 := (n(d00,lookback) -1.5)*2.0 nd00 := ta.alma(nd00,lookback,0.95,6) nd10 = ta.rma(nd00,2) //----Fast Rotation lookback := l9 v01 = n(volume,lookback) b01 = 0.0, s01 = 0.0 if close > open b01 := v01 * math.abs(open / close - 1) b01 if close < open s01 := v01 * math.abs(open / close - 1) s01 d01 = ta.cum(b01 - s01) nd01 = (n(d01,lookback) -1.5)*2.0 nd01 := ta.alma(nd01,lookback,0.90,6) nd11 = ta.rma(nd01,3) //----Basic Single Alert threshold = input(0.75,'Alert Threshold') long = ta.crossover(nd01,nd11) and nd01 <= - threshold and nd00 > nd10 short = ta.crossunder (nd01,nd11) and nd01 >= threshold and nd00 < nd10 cond = long or short bgcol = long ? #00BCD4 : short ? #FF5252 : na //bgcolor(vis_alert ? bgcol : na ,title='Alert Trigger') alertcondition(cond, title='Rotations X', message='Rotations X') //////////////////////////////////////////////////////////////////// /////// SPOT CVD symbol_ = str.replace(syminfo.tickerid, "PERP", "") [open77, close77, vol_spot] = request.security(symbol_, "1", [open, close, volume], ignore_invalid_symbol=false) len77 = input.int(12, "Spot CVD Length", group = "CVD") vol_n2 = n(vol_spot, len77) b77 = 0.0, s77 = 0.0, d77 = 0.0 if close > open b77 := vol_n2 * math.abs(open / close - 1) b77 if close < open s77 := vol_n * math.abs(open / close - 1) s77 d77 := ta.cum(b77-s77) d77 := ( n(d77, len77) - 1.5 ) * 2 cvd_spot = ta.alma(d77, len77, 0.80, 7) spot_rma = ta.rma(cvd_spot, 2) //____________________________________________________________________________ //=== Plots //____________________________________________________________________________ //// 30 minutes Rotation //// color1 = show_30mRotation ? nd01 > nd11 ? color.rgb(245,245,245) : color.rgb(245,245,245, 70) : color.rgb(245,245,245, 100) //rot1 = plot(show_30mRotation ? nd01 : na, '', color1) //rot2 = plot( show_30mRotation ? nd11 : na, '', color1) //fill(rot1, rot2, color = color1) // Lines & Fills //// hline_1 = hline(1,'',color.rgb(200, 100, 100, 100),linestyle=hline.style_solid) hline75 = hline(0.80, '', color.rgb(211, 211, 181, 100),linestyle=hline.style_dotted) fill( hline_1, hline75, color= long ? bullish3 : short ? bearish3 : nd00 < -0.75 and nd00 > nd10 ? color.new(bullish3, 90) : nd00 > 0.75 and nd00 < nd10 ? color.new(bearish3, 90) : na) //// ALert : based on CVD Fast //// hline_m1 = hline(-1,'',color.rgb(200, 100, 100, 100),linestyle=hline.style_solid) hline_m2 = hline(-0.80, '', color.rgb(211, 211, 181, 100),linestyle=hline.style_dotted) fill( hline_m1, hline_m2, color= alertLong00 ? bullish2 : alertShort00 ? bearish3 : na) //// CVD normal ( aka cvd_normal) //// //col_normal = cvd_normal>normal_rma ? color.from_gradient(cvd_fast, 0, 1, bull_grad_bottom, bull_grad_top) : color.from_gradient(cvd_fast, -0.1, -1, bear_grad_bottom, bear_grad_top) col_normal = cvd_normal>rma_normal ? bullish : bearish transp_normal = cvd_normal >= 0 ? 60 - cvd_normal*60 : cvd_normal < 0 ? 60-math.abs(cvd_normal*60) : 100 cvd_rising_n = cvd_normal >-0.90 and ta.rising(cvd_normal, 2) ? true : false cvd_falling_n = cvd_normal < 0.90 and ta.falling(cvd_normal, 2) ? true : false //cvd_color_n = cvd_rising_n ? color.new(bullish3, transp_normal) : cvd_falling_n ? color.new(bearish3, transp_normal) : na cvd_color_n = cvd_rising_n ? color.from_gradient(cvd_normal, -1, 1, bearish3, bullish3) : cvd_falling_n ? color.from_gradient(cvd_normal, -1, 1, bearish3, bullish3) : na plot_cvd_normal = plot( show_cvd_normal ? cvd_normal : na, title="", color = cvd_color_n, linewidth = 1, style = plot.style_line, join=true) plot_rma_normal = plot( show_cvd_normal ? rma_normal : na, title="", color = cvd_color_n, linewidth = 1, style = plot.style_line, join=true) fill( plot_cvd_normal, plot_rma_normal, color = cvd_color_n ) //// CVD fast //// transp = cvd_fast >= 0 ? 50 - cvd_fast*50 : cvd_fast < 0 ? 50-math.abs(cvd_fast*50) : 100 cvd_rising = ta.rising(cvd_fast, 2) ? true : false cvd_falling = ta.falling(cvd_fast, 2) ? true : false //cvd_color = cvd_rising ? color.new(bullish, transp) : cvd_falling ? color.new(bearish, transp) : color.new(color.rgb(255, 215, 0), 100) cvd_color = cvd_rising ? color.from_gradient(cvd_fast, -1, 1, bearish2, bullish2) : cvd_falling ? color.from_gradient(cvd_fast, -1, 1, bearish2, bullish2) : color.yellow plot_cvd_fast = plot( show_cvd_fast ? cvd_fast : na, title="", color = cvd_color, linewidth = 1, style = plot.style_line) plot_cvd_rma = plot( show_cvd_fast ? rma_fast : na, title="", color = cvd_color, linewidth = 1, style = plot.style_line) fill( plot_cvd_fast, plot_cvd_rma, color=cvd_color ) //// SPOT CVD //// col_spot_cvd = ta.rising(cvd_spot, 2) ? CYAN : ta.falling(cvd_spot, 2) ? color.rgb(255,69,0) : color.rgb(248,248,255) plot( show_spot_cvd ? 0.75 : na, "", color=col_spot_cvd, style = plot.style_circles, display = display.pane) //// RMA Alert : CVD & RMA comparison col_rma_alert = cvd_fast > rma_fast ? c4 : c7 plot( show_rma_alert ? 0 : na, 'CVD - RMA comparison', color=col_rma_alert, linewidth = 1, style = plot.style_cross, display = display.pane) //// Bardelta vs CVD Alert bgcolor( alertShort01 ? color.from_gradient(bardelta, -1, 1, c12, c11) : alertLong01 ? color.from_gradient(bardelta, -1, 1, c12, c11) : na)