How To Use Oscillators To Find Reversals?

djgLXXII

New member
Plus
Hey guys,

I’m looking for help refining my script and “strategy” (or lack thereof). I’m trying to trade reversals on SPY and QQQ, aiming to move into 0DTE options. The script is simple — I wait for at least three periods of stochRSI under 20, then a pop above it for longs, and the reverse (over 80) for shorts. A signal arrow is placed on the chart along with an audible alert.

On a SPY/QQQ chart, this often nails reversals, but in strong trends it can fail as price keeps going. I want to pair it with something that confirms entries, but I haven’t found anything useful. Moving averages and other lagging indicators feel pointless, and nothing lines up.

Any feedback, recommendations, or ideas would be great. This setup has at least kept me from taking losses, but without confidence in the reversal I often exit too early.

Code:
declare upper;

# StochRSI
def fullK = StochRSI().FullK;
def fullD = StochRSI().FullD;         

def bullCond = fullK[0] > 20
           AND fullK[1] <= 20
           AND fullK[2] <= 20
           AND fullK[3] <= 20
;

def bearCond = fullK[0] < 80
           AND fullK[1] >= 80
           AND fullK[2] >= 80
           AND fullK[3] >= 80
;

def mySignal = bullCond OR bearCond;
 
plot MyBullArrow = bullCond;

MyBullArrow.SetPaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_UP);
MyBullArrow.SetDefaultColor(Color.GREEN);
MyBullArrow.SetLineWeight(2);

plot MyBearArrow = bearCond;
MyBearArrow.SetPaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_DOWN);
MyBearArrow.SetDefaultColor(Color.RED);
MyBearArrow.SetLineWeight(2);

Alert(mySignal, "Signal Alert", Alert.BAR, Sound.Ring);
example_chart.png
 
Solution
Both, preferably, as I am aware that my script, as it is, is simplistic. I am sure I am not the first to have created something like this, although I have not personally come across anything exactly like it. (There are reversal indicators that repaint, which are useless. This one operates in real time.)

I'd love to hear from someone who trades reversals to understand what they use for confirmation. I am open to any help at this point.

When attempting to improve your existing script, you should try to avoid adding similar "indicators" into it, because they share almost the same data. It's like duplicating it.

This post by @antwerks is a good place to start as you try to build upon what you already have.

Two...
Are you looking to finetune the script or are you looking for another indicator to accompany the signals?
Both, preferably, as I am aware that my script, as it is, is simplistic. I am sure I am not the first to have created something like this, although I have not personally come across anything exactly like it. (There are reversal indicators that repaint, which are useless. This one operates in real time.)

I'd love to hear from someone who trades reversals to understand what they use for confirmation. I am open to any help at this point.
 
Both, preferably, as I am aware that my script, as it is, is simplistic. I am sure I am not the first to have created something like this, although I have not personally come across anything exactly like it. (There are reversal indicators that repaint, which are useless. This one operates in real time.)

I'd love to hear from someone who trades reversals to understand what they use for confirmation. I am open to any help at this point.

When attempting to improve your existing script, you should try to avoid adding similar "indicators" into it, because they share almost the same data. It's like duplicating it.

This post by @antwerks is a good place to start as you try to build upon what you already have.

Two indicators that are derived from the same data should not increase the win rate or your confidence in the signal. Something to think about.
 
Solution
here is a variation that allows you to pick how many past bars to look at

Code:
#stoch_rsi_rev_tweak
#https://usethinkscript.com/threads/need-help-fine-tuning-stochrsi-reversal.21419/

declare upper;

# StochRSI
def fullK = StochRSI().FullK;
#def fullD = StochRSI().FullD;        

input bull_level = 20;
input bear_level = 80;
input qty_back_bars = 3;
def bull_past = sum((fullK[1] <= bull_level),qty_back_bars) == qty_back_bars;
def bear_past = sum((fullK[1] >= bear_level),qty_back_bars) == qty_back_bars;

#def bullCond = fullK[0] > 20
#           AND fullK[1] <= 20
#           AND fullK[2] <= 20
#           AND fullK[3] <= 20;

#def bearCond = fullK[0] < 80
#           AND fullK[1] >= 80
#           AND fullK[2] >= 80
#           AND fullK[3] >= 80;

def bullCond = (fullK[0] > 20) and bull_past;
def bearCond = (fullK[0] < 80) and bear_past;

def mySignal = bullCond OR bearCond;
 
plot MyBullArrow = bullCond;

MyBullArrow.SetPaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_UP);
MyBullArrow.SetDefaultColor(Color.GREEN);
MyBullArrow.SetLineWeight(2);

plot MyBearArrow = bearCond;
MyBearArrow.SetPaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_DOWN);
MyBearArrow.SetDefaultColor(Color.RED);
MyBearArrow.SetLineWeight(2);

Alert(mySignal, "Signal Alert", Alert.BAR, Sound.Ring);
#
 
I've been tweaking my indicator and incorporating some changes based on suggestions. The primary goal of this indicator is to detect "V" reversals and provide some confidence that a reversal is occurring in real time. The aim is to enter a trade at the moment the signal fires (although one should wait a bit, as the signal may "disappear" if momentum continues in the same direction). I am now using the CCI indicator instead of StochRSI.

Code:
# ----------------------------------------------
# Volume-Weighted CCI Reversal Signal
#
# This study calculates a volume-weighted Commodity Channel Index (VWCCI),
# which emphasizes price moves that occur with higher trading volume.
# It then looks for potential reversal points by detecting when VWCCI
# exits an oversold or overbought zone after remaining there for a
# specified number of bars.
#
# Key Inputs:
# - bull_level: Oversold threshold to exit from (default -100)
# - bear_level: Overbought threshold to exit from (default +100)
# - qty_back_bars: Number of consecutive prior bars that must be inside
#   the oversold/overbought zone before a reversal is considered valid
#
# Intended Purpose:
# - To highlight potential bullish reversals after exhaustion selling
#   (VWCCI rises back above oversold level)
# - To highlight potential bearish reversals after exhaustion buying
#   (VWCCI falls back below overbought level)
#
# Signals:
# - Green Up Arrow = Bullish reversal candidate
# - Red Down Arrow = Bearish reversal candidate
#
# This script is designed for traders who want to filter out low-volume
# noise and focus on reversals supported by stronger market participation.
# ----------------------------------------------

declare upper;

input length         = 14;
input bull_level     = -100;   # oversold threshold to exit from
input bear_level     = 100;    # overbought threshold to exit from
input qty_back_bars  = 3;      # how many prior bars must be inside the zone

# Typical Price
def typicalPrice = (high + low + close) / 3;

# Volume-Weighted Typical Price
def vwTypicalPrice = typicalPrice * volume;

# Volume-Weighted Moving Average of Typical Price
def sumVWTP    = Sum(vwTypicalPrice, length);
def sumVolume  = Sum(volume, length);
def vwMean     = if sumVolume != 0 then sumVWTP / sumVolume else 0;

# Mean Deviation (weighted)
def deviation  = AbsValue(typicalPrice - vwMean);
def vwDev      = Average(deviation, length);

# Volume-Weighted CCI Calculation
def vwCCI = if vwDev != 0 then (typicalPrice - vwMean) / (0.015 * vwDev) else 0;

# Require prior qty_back_bars to be strictly beyond the threshold,
# then fire when the current bar crosses back through it.
def bull_past = Sum(vwCCI[1] <  bull_level, qty_back_bars) == qty_back_bars;
def bear_past = Sum(vwCCI[1] >  bear_level, qty_back_bars) == qty_back_bars;

def bullCond  = (vwCCI >= bull_level) and bull_past;  # exit from oversold
def bearCond  = (vwCCI <= bear_level) and bear_past;  # exit from overbought

def mySignal = bullCond or bearCond;

plot MyBullArrow = bullCond;
MyBullArrow.SetPaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_UP);
MyBullArrow.SetDefaultColor(Color.GREEN);
MyBullArrow.SetLineWeight(2);

plot MyBearArrow = bearCond;
MyBearArrow.SetPaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_DOWN);
MyBearArrow.SetDefaultColor(Color.RED);
MyBearArrow.SetLineWeight(2);

Alert(mySignal, "VWCCI reversal signal.", Alert.BAR, Sound.Ring);
 

Attachments

  • reversal_example.png
    reversal_example.png
    16.6 KB · Views: 324

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

Similar threads

Not the exact question you're looking for?

Start a new thread and receive assistance from our community.

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