// 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) // 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) //// Inputs //// Show/hide specific indicators show_cvd_fast = input(true, 'Show Fast CVD?', group = "CVD") //showTriggerRotation = input(true, "Show 30 minutes Trigger rotation?", group = "CVD") showFastRotation = input(true, "Show Pecker Fast rotation?", 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" ) //// Variables Initialization length = 0 int baseLookback = 0 int l1 = 4, lenCVDFast = 0 tf30 = false, tf60 = false, tf240 = false if timeframe.isminutes and timeframe.multiplier==30 baseLookback := 8, lenCVDFast := 14, tf30 := true else if timeframe.isminutes and timeframe.multiplier==60 baseLookback := 4, lenCVDFast := 7, tf60 := true else lenCVDFast := 7 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 := input(7, "Fast CVD length", group = "CVD") 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, .7, 6) rma_fast = ta.rma(cvd_fast, 2) bgcolor( barcolor_delta_based ? vol_delta > cvd_fast ? color.rgb(48, 48, 48) : color.rgb(0, 0, 0) : na) //// Delta calculation with normalized volume and LTF delta_ltf(length_x, vol) => vbuy=0.0, vsell=0.0, d=0.0 vol_n = volume if close > open vsell := vol_n * (close/open - 1) vbuy := vol_n - vsell if close < open vbuy := vol_n * ( open/close -1 ) vsell := vol_n - vbuy delta = vbuy - vsell delta //// CVD Fast LTF - New formula by maruf //// //length := input.int(14, "Fast CVD Length", tooltip = "Length used in Fast CVD", group = "CVD") length := input.int(7, "New formula CVD Fast length") vol_n := n(volume, 24) cvd = request.security_lower_tf( syminfo.tickerid, "15", delta_ltf(length, vol_n)) cvd_total = array.sum(cvd) cvd_total := (n(cvd_total, length) - 1.5) *2 cvd00 = ta.alma(cvd_total, 7, .6, 7) rma_cvd00 = ta.rma(cvd00, 2) col00 = cvd00 > rma_cvd00 ? color.rgb(84, 81, 248) : color.rgb(196, 4, 138) q1 = plot(cvd00, color = col00) //q2 = plot(rma_cvd00, color=col00) //fill(q1, q2, color=col00) barcolor( barcolor_delta_based ? cvd_total > cvd00 ? color.white : color.rgb(250, 21, 21) : na) //____________________________________________________________________________ //=== Plots //____________________________________________________________________________ // Lines & Fills //// //// ALert : based on CVD Fast //// hline_p = hline(0.80, '', color.rgb(211, 211, 181, 50),linestyle=hline.style_dotted) hline_n = hline(-0.80, '', color.rgb(211, 211, 181, 50),linestyle=hline.style_dotted) //// 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 cvd_color00 = cvd_fast > rma_fast? color.rgb(220,220,220) : color.rgb(128,128,128) plot( show_cvd_fast ? cvd_fast : na, title="", color = cvd_color00, linewidth = 2, style = plot.style_line) //plot_cvd_rma = plot( show_cvd_fast ? rma_fast : na, title="", color = cvd_color00, linewidth = 1, style = plot.style_line) //fill( plot_cvd_fast, plot_cvd_rma, color=cvd_color00 ) //plot(cvd_fast_hma, color = cvd_fast_hma>cvd_fast_hma[2]?color.white : color.gray) //// RMA Alert : CVD & RMA comparison //col_rma_alert = vol_delta > cvd_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)