Volume Reversal Model for ThinkorSwim


Staff member
Here's a "nice model of volume" with reversal signals in arrows and current trend painted as color candles.

Brought to you by @diazlaz



thinkScript Code

#Volume Game (vg) by RafaelZioni
#Original Port from https://www.tradingview.com/script/55gajSsI-volume-game/
# 2019.11.23 1.0 @diazlaz - Original Port
# https://usethinkscript.com/threads/volume-reversal-model-for-thinkorswim.1248/

#declare zerobase;

input RSIlength = 6; #RSI Period Length
input RSIoverSold = 50;
input RSIoverBought = 50;
input price = close;

#///////////// RSI
def vrsi = RSI(RSIlength, RSIoverBought, RSIoverSold, price);

#///////////// Bollinger Bands
input BBlength = 200; #Bollinger Period Length
input BBmult = 2; #Bollinger Bands Standard Deviation
def BBbasis = Average(price, BBlength);
def BBdev = BBmult * StDev(price, BBlength);
def BBupper = BBbasis + BBdev;
def BBlower = BBbasis - BBdev;
def source = close;
def buyEntry = Crosses(source, BBlower, CrossingDirection.ABOVE);
def sellEntry = Crosses(source, BBupper, CrossingDirection.BELOW);
input window1 = 8; #lookback window 1
input window2 = 21; #lookback window 2

def top1 = If(high >= Highest(high, window1), high, 0);
def bot1 = If(low <= Lowest(low, window1), low, 0);
def top2 = If(high >= Highest(high, window2), high, 0);
def bot2 = If(low <= Lowest(low, window2), low, 0);

input length = 9; #length
def avrg = Average(volume,length);

def vold1 = volume >= avrg * 1.5 and close < open;
def vold2 = volume >= avrg * 0.5 and volume <= avrg * 1.5 and close < open;
def vold3 = volume < avrg * 0.5 and close < open and volume >= avrg * 1.4;

def volu1 = volume >= avrg * 1.5 and close > open;
def volu2 = volume >= avrg * 0.6 and close > open;
def volu3 = volume < avrg * 0.5 and close > open;

def src = close;

#net volume of positive and negative volume
def nv = if (src - src[1]) > 0 then volume else
if (src - src[1]) < 0 then -volume else 0 * volume;

def cnv = TotalSum(nv); #cumulative net volume
def cnv_tb = cnv - Average(cnv,15); #normalized 15 bars moving average
input window_len = 28; #Window length
input v_len = 14; #V smooth length
def price_spread = stdev(high-low, window_len);

def v =  cnv - Average(cnv,15);
def smooth = Average(v, v_len);
def v_spread = stdev(v - smooth, window_len);
def shadow = (v - smooth) / v_spread * price_spread;

def out = if shadow > 0 then high + shadow else low + shadow;

def down = out < close and Crosses(out, top1, CrossingDirection.BELOW) and vold1;
def up1 = out > close and volu2 and vrsi < RSIoverSold;
def down1= out < close and vold1;
def down2= out < close;

def up = out > close and Crosses(out, bot2, CrossingDirection.ABOVE);

plot pDown = if down then high else Double.NaN;

#plot pDown1 = if down2 then high else Double.NaN;

plot pUp = if up then low else Double.NaN;

#plot pUp1 = if up1 then low else Double.NaN;

assignPriceColor(if down2 then color.red else if Up1 then color.green else color.white);

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

Really nice script! Hope to see more like this one added to Warehouse which uses volume to analyse for reversals.

Can audio alerts be added for the signals?
@zeek Add this to the end of your script:

# Alerts
Alert(pUp, " ", Alert.Bar, Sound.Chimes);
Alert(pDown, " ", Alert.Bar, Sound.Bell);

Similar threads

Not the exact question you're looking for?

Start a new thread and receive assistance from our community.

87k+ Posts
542 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.