• Memorial Day Sale! Claim the biggest discount of the year with $50 off VIP using code MEM50. Sign up here.

Price Volume Divergence Indicator for ThinkorSwim

BenTen

Administrative
Staff member
Staff
VIP
This indicator shows divergences between price and volume.
  • Bullish Volume Divergence: When the price is falling while volume continues to rises.
  • Bearish Volume Divergence: A bearish divergence signal occurs when the price is increasing while volume is decreasing.
There are two different types of signals
  • bear3 and bull3 = divergence signals within the last 3 candlesticks or bars
  • bull4 and bear4 = divergences within the last 4 candlesticks or bars
I also included alerts for these reversal signals so you can get alerted for when a new divergence is formed.

qF1Tywp.png

mSE3jZc.png


thinkScript Code

Code:
# Price Volume Divergence Indicator for ThinkorSwim
# Based on the framework of Trend Exhaustion Indicator
# Assembled by BenTen at useThinkScript.com

# 3 Bars Bearish Divergence
def bearish4 = (CLOSE > CLOSE[1] AND CLOSE [1] > CLOSE [2] AND CLOSE [2] > CLOSE [3] AND VOLUMEAVG(LENGTH = 20) < VOLUMEAVG(LENGTH = 20)[1] AND VOLUMEAVG(LENGTH = 20)[1] < VOLUMEAVG(LENGTH = 20)[2] AND VOLUMEAVG(LENGTH = 20)[2] < VOLUMEAVG(LENGTH = 20)[3]);
plot bear3 = bearish4;
bear3.AssignValueColor(Color.MAGENTA);
bear3.SetPaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_DOWN);

# 3 Bars Bullish Divergence
def bullish4 = (CLOSE < CLOSE[1] AND CLOSE [1] < CLOSE [2] AND CLOSE [2] < CLOSE [3] AND VOLUMEAVG(LENGTH = 20) > VOLUMEAVG(LENGTH = 20)[1] AND VOLUMEAVG(LENGTH = 20)[1] > VOLUMEAVG(LENGTH = 20)[2] AND VOLUMEAVG(LENGTH = 20)[2] > VOLUMEAVG(LENGTH = 20)[3]);
plot bull3 = bullish4;
bull3.AssignValueColor(Color.MAGENTA);
bull3.SetPaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_UP);

# 4 Bars Bearish Divergence
def bearish5 = (CLOSE > CLOSE[1] AND CLOSE [1] > CLOSE [2] AND CLOSE [2] > CLOSE [3] AND CLOSE [3] > CLOSE [4] AND VOLUMEAVG(LENGTH = 20) < VOLUMEAVG(LENGTH = 20)[1] AND VOLUMEAVG(LENGTH = 20)[1] < VOLUMEAVG(LENGTH = 20)[2] AND VOLUMEAVG(LENGTH = 20)[2] < VOLUMEAVG(LENGTH = 20)[3] and VOLUMEAVG(LENGTH = 20)[3] < VOLUMEAVG(LENGTH = 20)[4]);
plot bear4 = bearish5;
bear4.AssignValueColor(Color.CYAN);
bear4.SetPaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_DOWN);

# 4 Bars Bullish Divergence
def bullish5 = (CLOSE < CLOSE[1] AND CLOSE [1] < CLOSE [2] AND CLOSE [2] < CLOSE [3] AND CLOSE [3] < CLOSE [4] AND VOLUMEAVG(LENGTH = 20) > VOLUMEAVG(LENGTH = 20)[1] AND VOLUMEAVG(LENGTH = 20)[1] > VOLUMEAVG(LENGTH = 20)[2] AND VOLUMEAVG(LENGTH = 20)[2] > VOLUMEAVG(LENGTH = 20)[3] and VOLUMEAVG(LENGTH = 20)[3] > VOLUMEAVG(LENGTH = 20)[4]);
plot bull4 = bullish5;
bull4.AssignValueColor(Color.CYAN);
bull4.SetPaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_UP);

# Alerts
Alert(bull3, " ", Alert.Bar, Sound.Chimes);
Alert(bear3, " ", Alert.Bar, Sound.Chimes);
Alert(bull4, " ", Alert.Bar, Sound.Bell);
Alert(bear4, " ", Alert.Bar, Sound.Bell);

Shareable Link

https://tos.mx/uP5aTz
 
Last edited:

BenTen

Administrative
Staff member
Staff
VIP
I found this indicator, though. Give it a try.

Code:
# Price Volume Divergence
# Mobius
# Chat Room Request 09.10.2014

declare lower;

def price = close;
def vol = volume;

script Scale {
    input c = close;
    input Min = .01;
    input Max =   1;
    def hh = HighestAll(c);
    def ll   = LowestAll(c);
    plot Range = (((Max - Min) * (c - ll)) /  (hh - ll)) + Min;
}

plot NormPrice = Scale(c = price).Range;
NormPrice.SetDefaultColor(Color.Green);
plot NormVolume = Scale(c = vol).Range;
NormVolume.SetDefaultColor(Color.Red);
plot mean = if isNaN(close) then Double.NaN else .5;
mean.SetDefaultColor(Color.White);

def cond1 = normprice < mean;
def cond2 = normprice > mean;

def cond3 = normvolume < mean;
def cond4 = normvolume > mean;

addlabel(cond1, "Negative Price Convergence", color.red);
addlabel(cond2, "Positive Price Convergence", color.green);

addlabel(cond3, "Negative Volume Convergence", color.red);
addlabel(cond4, "Positive Volume Convergence", color.green);

addlabel(normprice > 0.9, "Price overbought", color.red);
addlabel(normprice < 0.1, "Price oversold", color.green);
 

Dupre

New member
VIP
There have been a couple times where I get an audible alert that divergence has occurred but no arrow. Has anyone else run into this issue?
 

charlie2598

Member
VIP
@tomsk
also when volume increasing stock can go any side up to down
can we define condition if vol increase and price increase then Green color and
Volume increasing and price going down red color
and we can scan this thing any idea how we do that.
 

MerryDay

Administrative
Staff member
Staff
VIP
Lifetime
@tomsk
also when volume increasing stock can go any side up to down
can we define condition if vol increase and price increase then Green color and
Volume increasing and price going down red color
and we can scan this thing any idea how we do that.
See the first post
 

Similar threads

Top