VWAP Volume Breakout Indicator for ThinkorSwim

BenTen

BenTen

Administrative
Staff
VIP
This breakout indicator identifies bullish and bearish trend when a candle crosses VWAP with abnormal volume. The way it defines high volume breakout is by using the Volume Average indicator with the length of 20 simple moving average. You can adjust this settings to your liking once you have the indicator added.

You will see a buy or sell signal when the breakout is detected.




thinkScript Code

Code:
# VWAP Breakout Above Average Volume
# Assembled by BenTen at useThinkScript.com

# You are free to use this code for personal use, and make derivative works from it.
# You are NOT GRANTED permission to use this code (or derivative works) for commercial
# purposes which includes and is not limited to selling, reselling, or packaging with
# other commercial indicators. Headers and attribution in this code should remain as provided,
# and any derivative works should extend the existing headers.

# Start VWAP
input numDevDn = -2.0;
input numDevUp = 2.0;
input timeFrame = {default DAY, WEEK, MONTH};

def cap = getAggregationPeriod();
def errorInAggregation =
    timeFrame == timeFrame.DAY and cap >= AggregationPeriod.WEEK or
    timeFrame == timeFrame.WEEK and cap >= AggregationPeriod.MONTH;
assert(!errorInAggregation, "timeFrame should be not less than current chart aggregation period");

def yyyyMmDd = getYyyyMmDd();
def periodIndx;
switch (timeFrame) {
case DAY:
    periodIndx = yyyyMmDd;
case WEEK:
    periodIndx = Floor((daysFromDate(first(yyyyMmDd)) + getDayOfWeek(first(yyyyMmDd))) / 7);
case MONTH:
    periodIndx = roundDown(yyyyMmDd / 100, 0);
}
def isPeriodRolled = compoundValue(1, periodIndx != periodIndx[1], yes);

def volumeSum;
def volumeVwapSum;
def volumeVwap2Sum;

if (isPeriodRolled) {
    volumeSum = volume;
    volumeVwapSum = volume * vwap;
    volumeVwap2Sum = volume * Sqr(vwap);
} else {
    volumeSum = compoundValue(1, volumeSum[1] + volume, volume);
    volumeVwapSum = compoundValue(1, volumeVwapSum[1] + volume * vwap, volume * vwap);
    volumeVwap2Sum = compoundValue(1, volumeVwap2Sum[1] + volume * Sqr(vwap), volume * Sqr(vwap));
}
def price = volumeVwapSum / volumeSum;
def deviation = Sqrt(Max(volumeVwap2Sum / volumeSum - Sqr(price), 0));

plot VWAP = price;
#plot UpperBand = price + numDevUp * deviation;
#plot LowerBand = price + numDevDn * deviation;

VWAP.setDefaultColor(getColor(0));

# Start Volume
input length = 20;
def Vol = volume;
def VolAvg = Average(volume, length);

def above_volume = Vol crosses above VolAvg;
def bullish_vwap = close crosses above VWAP;

plot bull = above_volume and bullish_vwap;
bull.AssignValueColor(Color.CYAN);
bull.SetPaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_UP);

def bearish_vwap = close crosses below VWAP;
plot bear = above_volume and bearish_vwap;
bear.AssignValueColor(Color.CYAN);
bear.SetPaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_DOWN);

Shareable Link

 
S

stockminion

New member
VIP
has any body testing this and showing good results ? Kindly let me know.
 
M

mohitdas

New member
VIP
Hey Ben thanks for scripting this, do you think adding the below code to your existing code, will alert me when that blue arrow shows up for Buy/Sell. Thank You
# End Study
# Added Alerts 2020-03-11
Alert(Vol crosses above VolAvg and close crosses above VWAP, text = "Buy", sound = Sound.Bell, "alert type" = Alert.BAR);
Alert(close crosses below VWAP, text = "Sell", sound = sound.Bell, "alert type" = Alert.BAR );
 
BenTen

BenTen

Administrative
Staff
VIP
@mohitdas This should do it:

Code:
# Alerts
Alert(bull, " ", Alert.Bar, Sound.Chimes);
Alert(bear, " ", Alert.Bar, Sound.Bell);
 
J

Jayrutty

New member
Ben,

would i just at this code to the end of the original? have very limited TOS coding experience
 
BenTen

BenTen

Administrative
Staff
VIP
@Brad This indicator does not produce any late signals. If anything, it's the issue with the alert or the alert may be going off before the candle is closed for confirmation.
 
D

Diana

New member
Hi, thank you for sharing but it doesn't work for me. I get errors:
No such function: first at 27:38
No such function: first at 27:38
No such function: first at 27:70
No such function: first at 27:70
No such function: compoundValue at 31:22
No such function: compoundValue at 31:22
No such function: compoundValue at 42:17
No such function: compoundValue at 42:17
No such function: compoundValue at 43:21
No such function: compoundValue at 43:21
No such function: compoundValue at 44:22
No such function: compoundValue at 44:22
No such function: first at 27:38
Incompatible parameter: yyyyMmDd at 27:5
No such function: first at 27:70
Incompatible parameter: yyyyMmDd at 27:5
No such function: compoundValue at 31:22
Incompatible parameter: 1 at 31:5
No such function: compoundValue at 31:22
Incompatible parameter: periodIndx at 31:5

Please advise,
thank you
 
BenTen

BenTen

Administrative
Staff
VIP
@Diana Are you sure you inserted the right script into ToS? I don't recognize some of the values in your error log.
 
D

Diana

New member
Yes Ben. The compoundValue is not recognized. And a few other issues. Are you saying it works for you on Thikorswim today?
 
F

fatulexus

New member
Also does this work on everything thats on my watchlist or only active charts that i am looking at?
 
BenTen

BenTen

Administrative
Staff
VIP
@fatulexus Only for charts you're currently viewing.
 
F

fatulexus

New member
@fatulexus Only for charts you're currently viewing.
Is there anyway to extend it to all watchlist alert or add it as a study?

Also is it possible to build a script to search through TOS news for keyword?

Thanks for your response!!!
 
BenTen

BenTen

Administrative
Staff
VIP
You can build a scanner first, then save it as a watchlist and get alerted for new changes within that watchlist.



Regarding the second question, answer is no.
 
Top