Trade Volume Delta Indicator for ThinkorSwim

anycolour

Member
Cumulative Delta Volume Indicator
Ruby:
# Cumulative Volume Delta
#
# The length of the accumulation is user controlled. The cumulative bar
# is the sum of the deltas for the past 10 bars. Change that length to
# 252 (a year in days) then plot something like AAPL. Very interesting.
#
# LongShort
# 5.7.2019

declare lower;

input length = 10;

def O = open;
def H = high;
def C = close;
def L = low;
def V = volume;
def Buying = V * (C - L) / (H - L);
def Selling = V * (H - C) / (H - L);
def Delt = buying - selling;

plot Delta = Delt;
Delta.AssignValueColor(if Delta > 0 then Color.GREEN else Color.RED);
Delta.SetPaintingStrategy(PaintingStrategy.HISTOGRAM);
Delta.hide();

plot zero = 0;
zero.setDefaultColor(Color.BLUE);

plot CumulativeVolumeDelta = sum(Delta,length);
CumulativeVolumeDelta.AssignValueColor(if CumulativeVolumeDelta > 0 then Color.GREEN else Color.RED);
CumulativeVolumeDelta.SetPaintingStrategy(PaintingStrategy.HISTOGRAM);

# End Code
 
Last edited by a moderator:
Cumulative delta is the one I undertand better, google can explain it better than I can, but it is very good for showing strength of trend and reversals when coupled with price action and support resistance. When you see red don't be long because aggressive selling is happening. Vice versa for green. If trending sideways and the red is getting smaller, going into green, the move will be up most likely.
 
And what is the best way to set up these indicators? Place them on the lower box in the chart by themselves? Use with a bar chart template, or line, or something else? I'll post a pic when I get back from work.
 
Yes it is working well for me, even though I have also read TOS doesn't do real-time tick data. I have found it super useful.

I am only using one of these though, the other I didn't find helpful. I think it was the trade delta.
 
Yes it is working well for me, even though I have also read TOS doesn't do real-time tick data. I have found it super useful.

I am only using one of these though, the other I didn't find helpful. I think it was the trade delta.

Could you please share in what way it is being useful to you? What signals are you getting from it? From what time frames, etc.

If you are using the trade delta indicator, are you using it with the default setting or did you turn the "reset aggregation daily" to NO?

Thank you
 
Useful on all timeframes including tick charts. Helps predict end of trend, or future direction of next move when in consolidation. Axia futures has a good youtube video on it. Rising green above the zero line signals strength. If it is declining and also above the zero line, the up move is likely over soon. Reverse that for below the zero line and when red. Pair with other indicators as always to confirm.
 
Could someone please adjust the scaling so I can use the Chaikin Money Flow, Chaikin Osc (both standard TOS studies), with the following cumulative delta study into one lower indicator? I would really be very grateful, as these are very useful indicators and it would save me space.
 
Last edited by a moderator:
@dolomick Per your request I have combined the Cumulative Volume Delta with Chaikin Money Flow as well as CHaikin Oscillator, with the scales normalized. You might like to adjust the colors of the plots to suit your preferences.

Code:
# Cumulative Volume Delta with Chaikin Money Flow + Chaikin Osc
# tomsk
# 1.6.2020

# Cumulative Volume Delta
#
# The length of the accumulation is user controlled. The cumulative bar
# is the sum of the deltas for the past 10 bars. Change that length to
# 252 (a year in days) then plot something like AAPL. Very interesting.
#
# LongShort
# 5.7.2019

declare lower;

script normalizePlot {
    input data = close;
    input newRngMin =  -1;
    input newRngMax = 1;
    def hhData = HighestAll( data );
    def llData = LowestAll( data );
    plot nr = ((( newRngMax - newRngMin ) * ( data - llData )) / ( hhData - llData )) + newRngMin;
}

input CVDlength = 10;
input CMFlength = 21;

def O = open;
def H = high;
def C = close;
def L = low;
def V = volume;
def Buying = V * (C - L) / (H - L);
def Selling = V * (H - C) / (H - L);
def Delt = buying - selling;

plot Delta = normalizePlot(Delt, -0.4, 0.4);
Delta.AssignValueColor(if Delta > 0 then Color.GREEN else Color.RED);
Delta.SetPaintingStrategy(PaintingStrategy.HISTOGRAM);
Delta.hide();

plot zero = 0;
Zero.SetDefaultColor(GetColor(5));

plot CumulativeVolumeDelta = normalizePlot(sum(Delta,CVDlength), -0.4, 0.4);
CumulativeVolumeDelta.AssignValueColor(if CumulativeVolumeDelta > 0 then Color.GREEN else Color.RED);
CumulativeVolumeDelta.SetPaintingStrategy(PaintingStrategy.HISTOGRAM);

# TOS Chaikin Money Flow

#
# TD Ameritrade IP Company, Inc. (c) 2007-2019
#

def tmp_var =
if high == low then
  volume
else
  (close - low - (high - close)) / (high - low) * volume
;

def sum_close = sum(tmp_var, CMFlength);
def total = sum(volume, CMFlength);

plot CMF =
if total == 0 then
  0
else
  sum_close / total
;
CMF.SetDefaultColor(Color.PINK);
CMF.SetLineWeight(2);

# Chaikin Oscillator

#
# TD Ameritrade IP Company, Inc. (c) 2007-2019
#

input colorNormLength = 14;
input fastLength = 3;
input slowLength = 10;

def acc = AccumDist(high, close, low, open, volume);
def shortXAvg = ExpAverage(acc, fastLength);
def longXAvg = ExpAverage(acc, slowLength);

plot ChaikinOsc = normalizePlot(shortXAvg - longXAvg, -0.4, 0.4);
ChaikinOsc.DefineColor("Highest", Color.YELLOW);
ChaikinOsc.DefineColor("Lowest", Color.LIGHT_RED);
ChaikinOsc.AssignNormGradientColor(colorNormLength, ChaikinOsc.color("Lowest"), ChaikinOsc.color("Highest"));
ChaikinOsc.SetLineWeight(2);

# End Cumulative Volume Delta with Chaikin Money Flow + Chaikin Osc
 
Thank so much Tomsk! Is there a tutorial or any tips you can give so I can do it myself going forward? I appreciate you doing this for me.
 
Thanks. Is there another indicator which would pair best with the cum vol delta? That you could pair it up with in code? As opposed to the Chaikin (not liking it)?
 
@anycolour There are literally thousands of indicators out there. Suggest you experiment with different indicators to see which particular one resonates with you, I was just helping @dolomick code what he was looking for
 
@tomsk unfortunately the Cumulative delta portion is not displaying the same way as it does on the original indicator... looking at TSLA on a one minute chart today there are periods of red negative bars on the original indicator, but on the new one there are no red, negative bars showing. I tested on MU as well and found similar discrepancy. Thanks for any help...
 
@tomsk unfortunately the Cumulative delta portion is not displaying the same way as it does on the original indicator... looking at TSLA on a one minute chart today there are periods of red negative bars on the original indicator, but on the new one there are no red, negative bars showing. I tested on MU as well and found similar discrepancy. Thanks for any help...


Looking through the notes that the original author of the CVD supplied in the header, it appears that this is designed for use on a daily chart rather than intraday. When I assembled the CSA for you yesterday I retained the code logic and all's I did was to normalize the plots to co-incide with other two Chaikin studies.

Since there are way too many variables here, as a test I removed the two Chaikin components so that we are just left with the CVD. I then normalized this CVD study on a daily aggregation. The result? It looks exactly the same on a daily aggregation.

Here is the original CVD study. Load that on your charts and name that study "CVDOne".

Code:
# Cumulative Volume Delta
#
# The length of the accumulation is user controlled. The cumulative bar
# is the sum of the deltas for the past 10 bars. Change that length to
# 252 (a year in days) then plot something like AAPL. Very interesting.
#
# LongShort
# 5.7.2019

declare lower;

input length = 10;

def O = open;
def H = high;
def C = close;
def L = low;
def V = volume;
def Buying = V * (C - L) / (H - L);
def Selling = V * (H - C) / (H - L);
def Delt = buying - selling;

plot Delta = Delt;
Delta.AssignValueColor(if Delta > 0 then Color.GREEN else Color.RED);
Delta.SetPaintingStrategy(PaintingStrategy.HISTOGRAM);
Delta.hide();

plot zero = 0;
zero.setDefaultColor(Color.BLUE);

plot CumulativeVolumeDelta = sum(Delta,length);
CumulativeVolumeDelta.AssignValueColor(if CumulativeVolumeDelta > 0 then Color.GREEN else Color.RED);
CumulativeVolumeDelta.SetPaintingStrategy(PaintingStrategy.HISTOGRAM);

# End Code


Next load the following study which essentially is the CVD but with the normalized code built in. Call this study "CVDTwo"

Code:
# Cumulative Volume Delta with Normalized Code
# tomsk
# 1.7.2020

# Cumulative Volume Delta
#
# The length of the accumulation is user controlled. The cumulative bar
# is the sum of the deltas for the past 10 bars. Change that length to
# 252 (a year in days) then plot something like AAPL. Very interesting.
#
# LongShort
# 5.7.2019

declare lower;

script normalizePlot {
    input data = close;
    input newRngMin =  -1;
    input newRngMax = 1;
    def hhData = HighestAll( data );
    def llData = LowestAll( data );
    plot nr = ((( newRngMax - newRngMin ) * ( data - llData )) / ( hhData - llData )) + newRngMin;
}

input length = 10;

def O = open;
def H = high;
def C = close;
def L = low;
def V = volume;
def Buying = V * (C - L) / (H - L);
def Selling = V * (H - C) / (H - L);
def Delt = buying - selling;

plot CumulativeVolumeDelta = normalizePlot(sum(Delt,length), -40, 40);
CumulativeVolumeDelta.AssignValueColor(if CumulativeVolumeDelta > 0 then Color.GREEN else Color.RED);
CumulativeVolumeDelta.SetPaintingStrategy(PaintingStrategy.HISTOGRAM);

plot zero = 0;
Zero.SetDefaultColor(GetColor(5));
# End Cumulative Volume Delta with Normalized Code


Now after loading both studies, compare this on a DAILY aggregation. It looks exactly the same. If you'd still like to use this on a 1 minute chart, that is entirely up to you, in which case just use the original CVD code from LongShort. However as noted earlier, my understanding is that this was designed to be used on a daily chart. All the best out there
 
Last edited:

Join useThinkScript to post your question to a community of 21,000+ developers and traders.

Similar threads

Not the exact question you're looking for?

Start a new thread and receive assistance from our community.

87k+ Posts
557 Online
Create Post

Similar threads

Similar threads

The Market Trading Game Changer

Join 2,500+ subscribers inside the useThinkScript VIP Membership Club
  • Exclusive indicators
  • Proven strategies & setups
  • Private Discord community
  • ‘Buy The Dip’ signal alerts
  • Exclusive members-only content
  • Add-ons and resources
  • 1 full year of unlimited support

Frequently Asked Questions

What is useThinkScript?

useThinkScript is the #1 community of stock market investors using indicators and other tools to power their trading strategies. Traders of all skill levels use our forums to learn about scripting and indicators, help each other, and discover new ways to gain an edge in the markets.

How do I get started?

We get it. Our forum can be intimidating, if not overwhelming. With thousands of topics, tens of thousands of posts, our community has created an incredibly deep knowledge base for stock traders. No one can ever exhaust every resource provided on our site.

If you are new, or just looking for guidance, here are some helpful links to get you started.

What are the benefits of VIP Membership?
VIP members get exclusive access to these proven and tested premium indicators: Buy the Dip, Advanced Market Moves 2.0, Take Profit, and Volatility Trading Range. In addition, VIP members get access to over 50 VIP-only custom indicators, add-ons, and strategies, private VIP-only forums, private Discord channel to discuss trades and strategies in real-time, customer support, trade alerts, and much more. Learn all about VIP membership here.
How can I access the premium indicators?
To access the premium indicators, which are plug and play ready, sign up for VIP membership here.
Back
Top