Indicator · Pine Script v5 · On the chart

Trended CVD modified

by rubystar0512· code credited to KioseffTrading

This indicator calculates directional cumulative volume delta across price swings identified by an imported ZigZag library.

View on GitHub

GitHub stars5on the repository
Pine versionv5runs as is
Lines of code192
Settings12inputs
LicenceNone statedfile: MPL-2.0
Last update2 years ago13 Sep 2024

Add It to Your TradingView Chart

  1. 1Copy the scriptPress Copy script above, or the copy button on the code below.
  2. 2Open the Pine EditorOpen a TradingView chart and choose Pine Editor at the bottom of the screen.
  3. 3Paste over the templateCreate a new indicator, select all of the template text and paste. Press Save and give it a name.
  4. 4Add it to the chartPress Add to chart, then adjust the settings with the gear icon next to its name.

Source Code

192 lines of Pine Script v5 from ThirdTask/Trended_CVD.pine, published under MPL-2.0 (file header). Keep the author's credit and licence lines when you reuse it.

Trended_CVD.pine
// This Pine Script™ code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © KioseffTrading

//@version=5
indicator("Trended CVD modified", overlay =true, max_labels_count = 500, max_lines_count = 500, max_boxes_count = 500, max_polylines_count = 100)
import TradingView/ZigZag/7 as ZigZagLib 

wid   =  input.int (defval = 1, minval = 1, title = "CVD Line Width" , group = "CVD Settings")
style  = input.string (defval = "Dotted", title = "CVD Line Style"   , group = "CVD Settings", options = ["Dotted", "Dashed", "Solid"])
upCol  = input.color (defval = #14D990, title = "+ CVD Color"    , group = "CVD Settings")
dnCol  = input.color (defval = #F24968, title = "- CVD Color"    , group = "CVD Settings")

var sty = switch style
    "Dotted" => line.style_dotted 
    "Dashed" => line.style_dashed 
    "Solid" => line.style_solid

// Create Zig Zag instance from user settings.
var zigZag = ZigZagLib.newInstance(
    ZigZagLib.Settings.new(
        input.float (0.00001, "Price deviation for reversals (%)", 0.00001, 100.0, 0.5, "0.00001 - 100", group = "Zig Zag Settings"),
        input.int  (50, "Pivot legs", 2, group = "Zig Zag Settings"),
        input    (color.new(#6929F2, 90), "Line color", group = "Zig Zag Settings"),
        input    (false, "Extend to last bar", group = "Zig Zag Settings"),
        input    (false, "Display reversal price", group = "Zig Zag Settings"),
        input    (false, "Display cumulative volume", group = "Zig Zag Settings"),
        input    (false, "Display reversal price change", inline = "priceRev", group = "Zig Zag Settings"),
        input.string ("Absolute", "", ["Absolute", "Percent"], inline = "priceRev", group = "Zig Zag Settings"),
        true
    )
)

zigZag.update()

type zigZagData
    int         start 
    int         end 
    array <int>     indexArr
    array <float>    volArr
    array <chart.point> cvdCoords
    float        vol 
    int         index
    float        max = 0
    float        min = 1e8

var zzd = zigZagData.new(0, 0, indexArr = array.new_int(), volArr = array.new_float())

volumeConfig() =>
    switch math.sign(close - open)
        -1 => -volume
        1 => volume
        =>   0

method updateData(array<float> id, float value) => 
    id.unshift(value)

zzd.indexArr.updateData(time)
zzd.volArr .updateData (volumeConfig())
zzd.max   := math.max(zzd.max, high)
zzd.min   := math.min(zzd.min, low)

method drawHistoricalCVD(array<float> id) =>
    atrZ = ta.atr(14) * 2

    if line.all.size() != line.all.size()[1]
        if line.all.size() > 2 
            getX1   = line.all.last().get_x1(),  getX2 = line.all.get(line.all.size() - 2).get_x1() 

            if getX2 != zzd.start and getX1 != zzd.end

        zzd.start := getX2, zzd.end  := getX1 
        zzd.max  := 0  , zzd.min  := 1e8

        getY1   = line.all.last().get_y1()
        getY2   = line.all.get(line.all.size() - 2).get_y1() 
        priceRange = getY1 - getY2 

        startIndex = zzd.indexArr.indexof(zzd.start)
        endIndex  = zzd.indexArr.indexof(zzd.end)
        slicedVol = id.slice(endIndex, startIndex + 1)
        slicedTime = zzd.indexArr.slice(endIndex, startIndex + 1)
        direction = atrZ * math.sign(priceRange) 

        signDir = math.sign(slicedVol.sum())  

        [col, beginTxt, lineCol] = switch signDir  

          -1 => [color.new(dnCol, 50), "" , dnCol]
          1 => [color.new(upCol, 50), "+", upCol] 

        addDivTxt = "" 
          
        sign = math.sign(slicedVol.sum())

        if getY1 < getY2 and sign > 0 or getY1 > getY2 and sign < 0

          addDivTxt := "\nDivergence"

        label.new(zzd.end, line.all.last().get_y1() + direction, beginTxt + str.tostring(slicedVol.sum(), format.volume) + addDivTxt, xloc = xloc.bar_time, 
          style = label.style_none, textcolor = col, size = size.small) 

        cvd = zigZagData.new(cvdCoords = array.new<chart.point>()) 

        normVol = slicedVol.copy() 

        if normVol.size() > 1

          for i = normVol.size() - 2 to 0
            normVol.set(i, normVol.get(i + 1) + normVol.get(i)) 

          lowDelta = normVol.min(), deltaRange = normVol.range(), priceMin = math.min(getY1, getY2)  

          absRange = math.abs(priceRange), upper = priceMin + absRange * .75, lower = priceMin + absRange * .25  
          
          for i = normVol.size() - 1 to 0 

            normed = lower + ((normVol.get(i) - lowDelta) * (upper - lower)) / deltaRange  

            cvd.cvdCoords.push(chart.point.from_time(slicedTime.get(i), normed)) 

          polyline.new(cvd.cvdCoords, line_color = lineCol, xloc = xloc.bar_time, line_style = sty, 
             curved = true, line_width = wid)



method drawLiveCVD(array<float> id) => 

  atrZ= ta.atr(14) * 2

  if barstate.islast

    var polyline livePoly = na
    var label  liveLabel = na

    getX1   = line.all.last().get_x1()
    getX2   = line.all.last().get_x2()
    getY1   = line.all.last().get_y1()
    getY2   = line.all.last().get_y2()
    startIndex = zzd.indexArr.indexof(getX1)

    priceRange = math.max(getY1, getY2, zzd.max) - math.min(getY1, getY2, zzd.min)

    slicedVol = id .slice(0, startIndex + 1)
    direction = atrZ * math.sign(priceRange) 

    signDir = math.sign(slicedVol.sum())  

    [col, beginTxt, lineCol] = switch signDir  

      -1 => [color.new(dnCol, 50), "" , dnCol]
      1 => [color.new(upCol, 50), "+", upCol]  

    if na(liveLabel) 

      liveLabel := label.new(bar_index + 5, line.all.last().get_y1() + direction, 
              beginTxt + str.tostring(slicedVol.sum(), format.volume),
      style = label.style_none, textcolor = col, size = size.small)

    else 

      liveLabel.set_xy(bar_index + 5, line.all.last().get_y1() + direction)
      liveLabel.set_text(beginTxt + str.tostring(slicedVol.sum(), format.volume))
      liveLabel.set_color(col)

    cvd = zigZagData.new(cvdCoords = array.new<chart.point>()) 

    normVol = slicedVol.copy() 

    if normVol.size() > 1

      for i = normVol.size() - 2 to 0
        normVol.set(i, normVol.get(i + 1) + normVol.get(i)) 
  
      lowDelta = normVol.min(), deltaRange = normVol.range(), priceMin = math.min(getY1, getY2, zzd.min)  

      absRange = math.abs(priceRange), upper = priceMin + absRange * .75, lower = priceMin + absRange * .25  

      for i = normVol.size() - 1 to 0

        normed = lower + ((normVol.get(i) - lowDelta) * (upper - lower)) / deltaRange  

        cvd.cvdCoords.push(chart.point.from_time(zzd.indexArr.get(i), normed)) 

        livePoly.delete()
        livePoly := polyline.new(cvd.cvdCoords, line_color = lineCol, xloc = xloc.bar_time, curved = true, line_style = sty, 
                          line_width = wid
                          )
      
 

zzd.volArr.drawHistoricalCVD()
zzd.volArr.drawLiveCVD   ()

Overview

Trended CVD modified tracks bar-by-bar volume signs based on price direction and evaluates net volume across individual price legs directly on the price chart. Users can customize pivot leg length, reversal deviation percentages, line widths, styles, and colors for positive and negative volume swings. The script functions as an analytical charting overlay without automated entry or exit signals.

Details

Published by

rubystar0512 on GitHub

Code credit

KioseffTrading, as written in the script's header

Type

Indicator, Pine Script v5

Draws

On the price chart

Category

Volume, Trend

Markets

Any symbol

Timeframes

Any timeframe

Risk Notes

No repainting, lookahead or stacked entries were found in its code or README. That says nothing about how well it works: test it first.

Settings

The inputs you can change from the gear icon on the chart. Defaults are the author's.

SettingTypeDefaultVariable
CVD Line Widthint1wid
CVD Line StylestringDottedstyle
+ CVD Colorcolor#14D990upCol
- CVD Colorcolor#F24968dnCol
Price deviation for reversals (%)float0.00001Price deviation for reversals (%)
Pivot legsint50Pivot legs
Line colorcolorcolor.new(#6929F2, 90)Line color
Extend to last barboolfalseExtend to last bar
Display reversal priceboolfalseDisplay reversal price
Display cumulative volumeboolfalseDisplay cumulative volume
Display reversal price changeboolfalseDisplay reversal price change
stringAbsolute
Third-party code. ForexR did not write, test or endorse this script, and the summary above was generated automatically from its code and README. Indicators describe the past, and a strategy's backtest can look better than live trading, especially when a script repaints. Check it in the Strategy Tester and on a demo account before you rely on it.

Similar Pine Scripts

The Momentum Setup is a multi-indicator visual tool designed for trend and momentum analysis directly on the price chart. It combines Relative Strength Index (RSI), Money Flow Index (MFI), Commodity Channel Index (CCI), Supertrend, and a 250-bar percentage cha

Indicator v5 Oscillators & momentumTrend
Updated 1 year ago · MPL-2.0 GitHub repository of Momentum Setup - Ankush Bajaj Momentum Investing Setup

Adaptive MA Slope

by capissimo
114 stars

This indicator calculates Kaufman's Adaptive Moving Average (KAMA) on a chosen price source and determines trend direction based on the slope across a configurable lookback window. Signals can be filtered by short-term volatility expansion using ATR comparison

Indicator v4 Moving averagesTrend
Updated 1 year ago · None stated GitHub repository of Adaptive MA Slope
92 stars

This indicator plots a volume-weighted average price of the typical price on the chart and colors that line by ADX strength. It draws a standard-deviation envelope around VWAP and tints the fill green when plus DI leads and red when minus DI leads. Triangle ma

Indicator v5 TrendOscillators & momentum
Updated 8 weeks ago · Custom licence GitHub repository of Moon Dev VWAP x ADX Explosion

Signal Strategy 15m

by tripolskypetr
72 stars

This indicator generates trend-following trade signals on the price chart by combining moving average crossovers with multi-factor filters. It triggers entry alerts when fast and slow EMAs cross in the direction of a baseline trend EMA, confirmed by non-extrem

Indicator v5 TrendMoving averages
Updated 3 days ago · MIT GitHub repository of Signal Strategy 15m

Copilot

by milocaetano
48 stars

Copilot is an order flow range-reversal indicator designed to overlay trading setups directly on the price chart. It evaluates four criteria: market context (sideways vs trending regime based on ATR height), structure (double top or double bottom retests), abs

Indicator v5 SMC / ICT / price actionSupport & resistance
Updated yesterday · MIT GitHub repository of Copilot
46 stars

This overlay indicator plots a SuperTrend using a 10-period ATR with a multiplier of 3, drawing up and down stop lines and a faint trend fill on the price chart. It compares a 9-period EMA with an 18-period EMA and a 12/26/9 MACD against its signal, and it req

Indicator v5 TrendOscillators & momentum
Updated 3 years ago · None stated GitHub repository of SuperTrend + MACD + EMA

More indicators

Trade Your Charts With a Regulated Broker

Compare brokers that connect to TradingView, with spreads, minimum deposits and leverage side by side.

Compare brokers