VWAP Retest Indicator for ThinkorSwim

desiben

Member
I am looking for a retest script where the indicator tells me that it successfully retested a resistance, this resistance could be a EMA or a VWAP or anything.

Here is an example showing a VWAP retest

image.png


1. Breaks Down
2. Breaks up
3. Retesting VWAP
4. Bounced succesfully
 

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

Is there any indicator that show breakout and retest and give a alert about it . ?! For example breakout for point ( 1 ) and retest ( 2 ) , then will go up. It is hard to check all the stocks .

ZsuLxUu.png
 
@iSultan Your question is similar to @desiben. These patterns are way too subjective to be incorporated into a scanner unless you can come up with a clear condition to define "breakout" and "retest."
 
I've got a vwap bounce upper study.

Code:
# VWAP Bounce
# and a bunch of other things
# @Mashume
# 2021-02-03 V0.1
# Released to UseThinkScript Community
declare upper;

input timeFrame = {default DAY, WEEK, MONTH};
input display_bubbles = {default "yes", "no"};

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 entry = if (close[1] > VWAP[1] and close[2] > VWAP[2] )within 15 bars 
and low < VWAP 
and close > VWAP
and VWAP > VWAP[3]
and low[1] > VWAP[1] then low else double.nan;

entry.setPaintingStrategy(PaintingStrategy.ARROW_UP);
entry.SetDefaultColor(COLOR.DARK_ORANGE);
entry.setLineWeight(3);

AddChartBubble("time condition" = entry and display_bubbles, "price location" = low * 0.995, text = "VWAP BOUNCE", color = Color.LIME, up = No);  

plot exit = if (close[1] < VWAP[1] and close[2] < VWAP[2]) within 15 bars
and high > VWAP
and Close < VWAP
and VWAP < VWAP[3]
and high[1] < VWAP[1] then high else double.nan;
exit.setPaintingStrategy(PaintingStrategy.ARROW_DOWN);
exit.SetDefaultColor(COLOR.DARK_ORANGE);
exit.setLineWeight(3);
AddChartBubble("time condition" = exit and display_bubbles, "price location" = high * 1.005, text = "VWAP BOUNCE", color = Color.PINK);  

plot brokenbull = if ((close[1] > VWAP[1] and close[2] > VWAP[2] )within 15 bars 
and low < VWAP 
and Close > VWAP
and VWAP > VWAP[3]
and low[1] > VWAP[1]) within 4 bars
    and (max(close, open) < VWAP and max(close[1], open[1]) < VWAP[1]) 
then low else double.nan;

brokenbull.setPaintingStrategy(PaintingStrategy.ARROW_DOWN);
brokenbull.SetDefaultColor(COLOR.RED);
brokenbull.setlineWeight(3);
# AddChartBubble("time condition" = brokenbull, "price location" = low * 0.995, text = "BROKEN BULL", up = No, color = Color.YELLOW);  

plot brokenbear =  if ((close[1] < VWAP[1] and close[2] < VWAP[2]) within 15 bars
and high > VWAP
and CLOSE < VWAP
and VWAP < VWAP[3]
and high[1] < VWAP[1] ) within 4 bars
    and (min(close, open) > VWAP and min(close[1], open[1]) > VWAP[1]) 
then low else double.nan;
brokenbear.setPaintingStrategy(PaintingStrategy.ARROW_UP);
brokenbear.SetDefaultColor(COLOR.GREEN);
brokenbear.setlineWeight(3);
# AddChartBubble("time condition" = brokenbear, "price location" = high * 1.005, text = "BROKEN BEAR", up = Yes, color = Color.YELLOW);  
AssignPriceColor(if brokenbear or brokenbull then color.orange else color.current);
 
I've got a vwap bounce upper study.

Code:
# VWAP Bounce
# and a bunch of other things
# @Mashume
# 2021-02-03 V0.1
# Released to UseThinkScript Community
declare upper;

input timeFrame = {default DAY, WEEK, MONTH};
input display_bubbles = {default "yes", "no"};

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 entry = if (close[1] > VWAP[1] and close[2] > VWAP[2] )within 15 bars
and low < VWAP
and close > VWAP
and VWAP > VWAP[3]
and low[1] > VWAP[1] then low else double.nan;

entry.setPaintingStrategy(PaintingStrategy.ARROW_UP);
entry.SetDefaultColor(COLOR.DARK_ORANGE);
entry.setLineWeight(3);

AddChartBubble("time condition" = entry and display_bubbles, "price location" = low * 0.995, text = "VWAP BOUNCE", color = Color.LIME, up = No);

plot exit = if (close[1] < VWAP[1] and close[2] < VWAP[2]) within 15 bars
and high > VWAP
and Close < VWAP
and VWAP < VWAP[3]
and high[1] < VWAP[1] then high else double.nan;
exit.setPaintingStrategy(PaintingStrategy.ARROW_DOWN);
exit.SetDefaultColor(COLOR.DARK_ORANGE);
exit.setLineWeight(3);
AddChartBubble("time condition" = exit and display_bubbles, "price location" = high * 1.005, text = "VWAP BOUNCE", color = Color.PINK);

plot brokenbull = if ((close[1] > VWAP[1] and close[2] > VWAP[2] )within 15 bars
and low < VWAP
and Close > VWAP
and VWAP > VWAP[3]
and low[1] > VWAP[1]) within 4 bars
    and (max(close, open) < VWAP and max(close[1], open[1]) < VWAP[1])
then low else double.nan;

brokenbull.setPaintingStrategy(PaintingStrategy.ARROW_DOWN);
brokenbull.SetDefaultColor(COLOR.RED);
brokenbull.setlineWeight(3);
# AddChartBubble("time condition" = brokenbull, "price location" = low * 0.995, text = "BROKEN BULL", up = No, color = Color.YELLOW);

plot brokenbear =  if ((close[1] < VWAP[1] and close[2] < VWAP[2]) within 15 bars
and high > VWAP
and CLOSE < VWAP
and VWAP < VWAP[3]
and high[1] < VWAP[1] ) within 4 bars
    and (min(close, open) > VWAP and min(close[1], open[1]) > VWAP[1])
then low else double.nan;
brokenbear.setPaintingStrategy(PaintingStrategy.ARROW_UP);
brokenbear.SetDefaultColor(COLOR.GREEN);
brokenbear.setlineWeight(3);
# AddChartBubble("time condition" = brokenbear, "price location" = high * 1.005, text = "BROKEN BEAR", up = Yes, color = Color.YELLOW);
AssignPriceColor(if brokenbear or brokenbull then color.orange else color.current);
Great one. Thank you. Is there a way we can scan for this? Can you help me with scan for vwap bounce?
Also it would be great if you can help me create similar for EMA bounce. Thanks in advance.
 
Last edited by a moderator:
Great one. Thank you. Is there a way we can scan for this? Can you help me with scan for vwap bounce?
Also it would be great if you can help me create similar for EMA bounce. Thanks in advance.
Unfortunately, no. THIS script cannot be used in the Scan Hacker.
The ToS platform does not support the use of scripts that contain the MTF (multi-timeframe) Aggregation.Period function in the Scan Hacker
 
Last edited:
@CodeBee. try this. Remove the hashtag for entry or exit. Not expert, hope it works with you.
def periodIndx = getYyyyMmDd();

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));

def VWAP = price;

plot entry = if (close[1] > VWAP[1] and close[2] > VWAP[2])within 15 bars and low < VWAP and close > VWAP and VWAP > VWAP[3] and low[1] > VWAP[1] then low else double.nan;


#plot exit = if (close[1] < VWAP[1] and close[2] < VWAP[2]) within 15 bars and high > VWAP and Close < VWAP and VWAP < VWAP[3] and high[1] < VWAP[1] then high else double.nan;
 

Similar threads

Not the exact question you're looking for?

Start a new thread and receive assistance from our community.

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