VWAP Reversal/ Bounce Strategy

Kala123

New member
Here's a summary of its main components:

  1. VWAP and Bands Calculation:
    • The script calculates the Volume Weighted Average Price (VWAP) and its standard deviation-based upper and lower bands.
    • Two levels of bands are created: one set is 1 standard deviation above/below VWAP, and the other is 2 standard deviations.
  2. Volume Analysis:
    • The script checks for high-volume breakout conditions or low-volume pullback conditions to confirm significant price moves.
  3. Bullish Sentiment Analysis:
    • It analyzes candle patterns over a specified lookback period to confirm a bullish trend (e.g., most candles closing above their open).
  4. Momentum Confirmation:
    • Positive and sustained momentum conditions are checked to ensure the price move has strength.
  5. Overextension Check:
    • The Average True Range (ATR) is used to identify if the price is overextended (too far above VWAP).
  6. RSI Momentum:
    • The Relative Strength Index (RSI) is evaluated to confirm bullish momentum (RSI above 50).
  7. Consolidation Detection:
    • Detects periods when the price is stuck near VWAP, which might indicate consolidation and avoids generating signals during such periods.
  8. Breakout and Recovery Conditions:
    • Signals are generated only when the price is sufficiently far from VWAP and exhibits breakout characteristics.
  9. Buy Signal Logic:
    • Combines all the above conditions into a refined buy signal. It includes checks for:
      • Price being slightly above VWAP or bands (with tolerance).
      • Volume, sentiment, momentum, and RSI confirmation.
      • Avoiding overextension and consolidation.


Code:
# Inputs
 input numDevUp1 = 1.0;          # Upper Band 1 multiplier
input numDevDn1 = -1.0;         # Lower Band 1 multiplier
input numDevUp2 = 2.0;          # Upper Band 2 multiplier
input numDevDn2 = -2.0;         # Lower Band 2 multiplier
input volumeLookback = 30;      # Lookback period for average volume
input sentimentLookback = 5;    # Lookback period for bullish sentiment
input tolerancePercent = 1.0;   # Tolerance for recovery signals (in percentage)
input atrMultiplier = 3.0;      # Threshold for overextension
input rsiLength = 14;           # RSI Length

# VWAP Calculation
def totalVolume = TotalSum(volume);
def totalPriceVolume = TotalSum(volume * close);
def VWAP = totalPriceVolume / totalVolume;

# VWAP Line
plot VWAPLine = VWAP;
VWAPLine.SetDefaultColor(Color.CYAN);

# VWAP Bands
def sumSquaredDiff = TotalSum(volume * Sqr(close - VWAP));
def stdDev = Sqrt(sumSquaredDiff / totalVolume);

plot UpperBand1 = VWAP + numDevUp1 * stdDev;
UpperBand1.SetDefaultColor(Color.RED);

plot UpperBand2 = VWAP + numDevUp2 * stdDev;
UpperBand2.SetDefaultColor(Color.DARK_RED);

plot LowerBand1 = VWAP + numDevDn1 * stdDev;
LowerBand1.SetDefaultColor(Color.GREEN);

plot LowerBand2 = VWAP + numDevDn2 * stdDev;
LowerBand2.SetDefaultColor(Color.DARK_GREEN);

# Volume Confirmation
def avgVolume = Average(volume, volumeLookback);
def recentHighVolume = Sum(volume > avgVolume * 1.5, 5) > 0;  # High volume breakout in last 5 bars
def isPullbackVolume = volume < avgVolume;  # Pullback on low/average volume
def isVolumeConditionMet = recentHighVolume or isPullbackVolume;

# Bullish Sentiment Confirmation
def bullishSentiment = close > open and close > close[1];
def bullishCount = Sum(bullishSentiment, sentimentLookback);
def isBullishSentiment = bullishCount >= sentimentLookback * 0.6; # At least 60% bullish candles in lookback

# Momentum Confirmation
def momentum = close - close[1];
def strongMomentum = momentum > 0 and momentum > momentum[1];  # Strong positive momentum
def sustainedMomentum = close > close[1] and close[1] > close[2];  # Follow-through momentum

# ATR for Overextension
def atr = Average(TrueRange(high, low, close), 14);
def isOverextended = close > VWAP + atr * atrMultiplier;  # Price too far above VWAP

# RSI Confirmation
def rsi = reference RSI(length = rsiLength);
def isRSIStrong = rsi > 50;  # RSI indicates bullish momentum

# Consolidation Detection
def isConsolidating = AbsValue(close - VWAP) < (VWAP * 0.005);  # Price within 0.5% of VWAP
def isStuckNearVWAP = Sum(isConsolidating, 10) > 8;  # Consolidation over 8 of last 10 bars

# Breakout Momentum Detection
def breakoutMomentum = close > Max(high[1], high[2]) and volume > avgVolume * 1.5;

# Minimum Distance from VWAP
def isFarEnoughFromVWAP = AbsValue(close - VWAP) > (VWAP * 0.003);  # Price at least 0.3% from VWAP

# Recovery Detection Above VWAP or Bands
def isAboveVWAP = close > VWAP;
def isAboveUpperBand1 = close > UpperBand1;
def isAboveUpperBand2 = close > UpperBand2;
def isAboveLowerBand1 = close > LowerBand1;
def isAboveLowerBand2 = close > LowerBand2;

# Slightly Above Detection with Tolerance
def tolerance = tolerancePercent / 100;
def isSlightlyAboveVWAP = close > VWAP * (1 + tolerance);
def isSlightlyAboveBands = close > VWAP and (isAboveLowerBand1 or isAboveLowerBand2 or isAboveUpperBand1 or isAboveUpperBand2);

# Refined Buy Signal Logic
def BuySignalCondition = (isSlightlyAboveVWAP or isSlightlyAboveBands)
                          and isVolumeConditionMet
                          and isBullishSentiment
                          and strongMomentum
                          and sustainedMomentum
                          and !isOverextended
                          and isRSIStrong
                          and !isStuckNearVWAP  # Avoid consolidation
                          and breakoutMomentum  # Require breakout
                          and isFarEnoughFromVWAP;  # Avoid signals too close to VWAP

# Plot Buy Signal
plot BuySignalArrow = if BuySignalCondition then low - (low * 0.01) else Double.NaN;
BuySignalArrow.SetDefaultColor(Color.GREEN);
BuySignalArrow.SetPaintingStrategy(PaintingStrategy.ARROW_UP);

# Add Labels for Visual Feedback
AddLabel(yes, "VWAP & Bands Active", Color.YELLOW);
AddLabel(yes, "Volume Condition Met: " + isVolumeConditionMet, if isVolumeConditionMet then Color.GREEN else Color.RED);
AddLabel(yes, "Bullish Sentiment: " + isBullishSentiment, if isBullishSentiment then Color.GREEN else Color.RED);
AddLabel(yes, "Above VWAP or Bands: " + (isAboveVWAP or isSlightlyAboveBands), if isAboveVWAP or isSlightlyAboveBands then Color.GREEN else Color.RED);
AddLabel(yes, "Buy Signal: " + BuySignalCondition, if BuySignalCondition then Color.GREEN else Color.RED);


Let me know your thoughts and if you know anyways for it to be improved
 

Similar threads

Not the exact question you're looking for?

Start a new thread and receive assistance from our community.

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