Trade Volume Delta Indicator for ThinkorSwim

A

anty

New member
I found this Trade Delta indicator that works on timeframes less than 1 day.

Code:
#fl_trade_delta_timeSTUDY.ts

#

#Fil

#Creation date: 8/28/2015

#Edit Log (Date/Editor):

#

#

#

#hint: Plots the <b>ESTIMATED</b> running trade delta (uptick/downtick) per bar on <b>TIME</b> chart

#hint i_reset_aggregations_daily: Toggles whether to reset the trade delta aggregation at the start of each day

#hint i_min_lot_threshold: The threshold for "LARGE" lot bars (a seperate aggregation)



#INPUTS

input i_reset_aggregations_daily = YES;

input i_min_lot_threshold = 50;



#VARIABLES AND LOGIC

def v_reset_aggregations = if GetYYYYMMDD() <> GetYYYYMMDD()[1] then 1 else 0;

def v_trades = tick_count();



def v_uptick = if close > open then v_trades else 0;

def v_downtick = if close < open then -v_trades else 0;

def v_uptick_large = if v_trades >= i_min_lot_threshold and close > open then v_trades else 0;

def v_downtick_large = if v_trades >= i_min_lot_threshold and close < open then -v_trades else 0;



def v_trade_delta = CompoundValue(1, if (i_reset_aggregations_daily and v_reset_aggregations) then v_uptick + v_downtick else v_uptick + v_downtick + v_trade_delta[1], 0);

def v_trade_delta_large = CompoundValue(1, if (i_reset_aggregations_daily and v_reset_aggregations) then v_uptick_large + v_downtick_large else v_uptick_large + v_downtick_large + v_trade_delta_large[1], 0);



#PLOTS

plot p_zero = 0;

plot p_uptick = v_uptick;

plot p_downtick = v_downtick;

plot p_trade_delta = v_trade_delta;

plot p_uptick_large = v_uptick_large;

plot p_downtick_large = v_downtick_large;

plot p_trade_delta_large = v_trade_delta_large;



#PLOT STYLES AND SETTINGS

p_zero.SetDefaultColor(Color.GRAY);

p_uptick.SetPaintingStrategy(PaintingStrategy.SQUARED_HISTOGRAM);

p_uptick.SetDefaultColor(Color.GREEN);

p_downtick.SetPaintingStrategy(PaintingStrategy.SQUARED_HISTOGRAM);

p_downtick.SetDefaultColor(Color.RED);

p_trade_delta.SetPaintingStrategy(PaintingStrategy.LINE);

p_trade_delta.AssignValueColor(if v_trade_delta > 0 then Color.GREEN else if v_trade_delta < 0 then Color.RED else Color.GRAY);

p_uptick_large.SetPaintingStrategy(PaintingStrategy.SQUARED_HISTOGRAM);

p_uptick_large.SetDefaultColor(Color.CYAN);

p_downtick_large.SetPaintingStrategy(PaintingStrategy.SQUARED_HISTOGRAM);

p_downtick_large.SetDefaultColor(Color.MAGENTA);

p_trade_delta_large.SetPaintingStrategy(PaintingStrategy.LINE);

p_trade_delta_large.AssignValueColor(if v_trade_delta_large > 0 then Color.CYAN else if v_trade_delta_large < 0 then Color.MAGENTA else Color.GRAY);

# End Code
Putting that study with the Cumulative Volume Delta indicator is pretty neat. How would I be able to combine these two indicators so that they share the same zero line?

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
Could someone combine these so that they share the same zero line?
 
A

anycolour

Member
Does anyone have a Delta (Cumulative Delta) indicator they could share? Something like the attached image. Thank you!

 
Last edited by a moderator:
D

dolomick

Member
Where did you find these? Been looking for cumulative delta. This is really powerful stuff, someone smarter than me should maybe try and enhance these indicators as suggested (or in ways I'm not smart enough to suggest) :)
 
D

dolomick

Member
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.
 
A

anycolour

Member
Does this truly work? All I've read is that thinkorswim does not provide provide real-time accurate tick data (no historical BidVolume and AskVolume) so it is impossible to device a cumulative delta/volume delta indicator in thinkorswim.

Is this correct?
 
Last edited:
A

anycolour

Member
Also, please link to internet sites where the "Trade Delta Indicator" is explained. All I can find are Volume Delta and Cumulative Volume Delta - are these two the same thing? What is Trade Delta?
 
A

anycolour

Member
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.
 
D

dolomick

Member
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.
 
J007RMC

J007RMC

Active member
2019 Donor
VIP
Im wondering this compares to the tmo where its momentum is based off delta?
 
A

anycolour

Member
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
 
D

dolomick

Member
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:
D

dolomick

Member
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.
 
J007RMC

J007RMC

Active member
2019 Donor
VIP
I'm amazed each and every day by the really cool indicators this site kicks out....fantastic is when you know your hooked on charts lol
 
T

tomsk

Well-known member
VIP
@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
 
A

anycolour

Member
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)?
 
D

dolomick

Member
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.
 
T

tomsk

Well-known member
VIP
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.

@dolomick I've learnt by looking through thousands of code examples and helping others make code changes such as yours. By responding to user requests such as yours it helps me improve my craft. If you'd like to do a deep dive on tutorials, here is a link

 
T

tomsk

Well-known member
VIP
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
 
Top