// 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 // (**) 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") barcolor_delta_based = input(false, "Color bars : delta compared?", "Color bars based on comparing Delta(last bar) against CVD") //// 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 = 4, lenCVDFast = 0 if timeframe.multiplier==30 baseLookback := 8, lenCVDFast := 14 else if timeframe.multiplier==60 baseLookback := 4, lenCVDFast := 7 else useManualBaseLookback := true int length = 0 vol_n = 0.0 v00 = 0.0, b00 = 0.0, s00 = 0.0 d00 = 0.0, nd00 = 0.0 vol_buy = 0.0, vol_sell = 0.0, vol_delta = 0.0 bardelta = 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 //// CVD Fast //// //length := input.int(14, "Fast CVD Length", tooltip = "Length used in Fast CVD", group = "CVD") length := lenCVDFast vol_n := n(volume, length) if close > open vol_buy := vol_n * math.abs(open / close - 1) vol_buy if close < open vol_sell := vol_n * math.abs(open / close - 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 = l1 * 3 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 := l1 * 9 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 //____________________________________________________________________________ //=== 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 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 //// //// 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)