Stochastic Parameters Oscillator For ThinkOrSwim

Randolph_Nomad

New member
VIP
Good Day all,
I've been a member for a few years, and everytime i use something on this site it teaches me; improving my technical analysis AND learning to read signals.

I decided to give some coding a try. forgive the pseudo program mgr context, but its easier for me to manage the approach this way.

Goal: Approximate a stochastic process that:
  • Tracks near-term volatility dynamics (implied or realized).
  • Flags momentum vs. mean-reversion conditions.
  • Outputs a “probability reading” (or score) indicating the likelihood of a near-term run.
here's the code for the study: as I continue, any feedback is greatly appreciated

Code:
declare lower;

# -- 1) Declare inputs as "constant" values for lengths --
input HVLength = 20;       # Historical Volatility lookback
input RSIlength = 14;      # RSI lookback
input BollLength = 20;     # Bollinger (mean-reversion) lookback

# -- 2) Basic Price & Volatility Inputs --
def price = close;

# For HV, we can approximate with the standard deviation of log returns:
def dailyReturn = Log(price / price[1]);
def HV = StDev(dailyReturn, HVLength);
def IV = imp_volatility();  # TOS built-in implied volatility for the underlying

# -- 3) Momentum (RSI) --
# Instead of RSI(price, rsiLen), use RSI(length = RSIlength)
def rsiValue = RSI(length = RSIlength);

# -- 4) Mean-Reversion (Bollinger Z-Score) --
def avgPrice = Average(price, BollLength);
def stDevPrice = StDev(price, BollLength);
def zScore =
    if stDevPrice != 0 then
        (price - avgPrice) / stDevPrice
    else
        0;

# -- 5) Composite Probability-Like Score --
# Momentum Part: normalized RSI
def momentumPart = (rsiValue - 50) / 50;  # -1 (oversold) to +1 (overbought) scale

# Volatility Part: comparing IV and HV
def volPart =
    if IV < HV then
        1  # “Cheap” implied volatility vs realized
    else
        HV / IV;  # If IV > HV, ratio < 1

# Mean-Reversion Part: if zScore < -1, bullish snapback, if > +1, bearish
def mrPart =
    if zScore < -1 then
        1
    else if zScore > 1 then
        -1
    else
        0;

# Weight them (adjust coefficients to taste)
def stochParamRaw = (0.5 * momentumPart) + (0.3 * volPart) + (0.2 * mrPart);

# Convert raw value to 0-100 scale, just for a nicer read
def stochParamScore = Round(50 + 50 * stochParamRaw, 0);

# -- 6) Plot the "StochasticParam" Score --
plot SPScore = stochParamScore;
SPScore.SetDefaultColor(Color.CYAN);
 
Last edited by a moderator:
  • I'm watching this!
Reactions: sum

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
456 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