// Downloaded From https://www.WiseStockTrader.com
_SECTION_BEGIN("Cumulative Volume Delta");
upper_wick = IIf(C>O, H-C, H-O); 
lower_wick = IIf(C>O, O-L, C-L);
spread = (H-L);

body_length = (spread - (upper_wick-lower_wick));
percent_upper_wick = (upper_wick/spread);
percent_lower_wick = (lower_wick/spread);
percent_body_length = (body_length/spread);

x= (percent_body_length+(percent_upper_wick+percent_lower_wick)/2*Volume);
y= ((percent_upper_wick+percent_lower_wick)/2*Volume);
 
buying_volume = IIf(C>O, x, y);
selling_volume = IIf(C<O, x, y);

cumulation_length = Param("Cumulative Length", 14, 10, 100);
cumulative_buying_volume= EMA(buying_volume, cumulation_length);
cumulative_selling_volume = EMA(selling_volume, cumulation_length); 
cumulative_volume_delta = cumulative_buying_volume - cumulative_selling_volume;

cvd_color = IIf(cumulative_volume_delta > 0, colorGreen, colorRed);

PlotGrid(0, colorBlue, pattern=9, width=2, label=True);
Plot(cumulative_volume_delta, "Cumulative Volme Delta", color=cvd_color, styleHistogram | styleThick, width=3);
_SECTION_END();