Repaints Doubly Smoothed PPO For ThinkOrSwim

Repaints

whoDAT

Active member
Plus
mod note:
This momentum indicator shows when momentum has turned, which side currently controls the move, and whether that pressure is strengthening or weakening.

Use it to catch shifts early and avoid entries when momentum is fading.



The PPO by Mobius, BenTen and antwerks is a modern take on the MACD oscillator function.
Read more by BenTen here: https://usethinkscript.com/threads/ppo-price-percent-oscillator-for-thinkorswim.778/

This modification allows you to select an secondary aggregation period and a type of price input (close, open, HL2, etc.)

The price data is smoothed using a fast Laguerre function. The PPO is then calculated and smoothed again - this time by a Hull Moving Average. Buy and sell indication is changed from the original crossing zero condition to the peak or trough.

Overall the goal was speed with smoothing.

Enjoy!

Doubly Smoothed PPO, top lower vs. PPO Enhanced lower, lower.
Screenshot 2026-03-26 155932.png


Trader ActionBehavior Driving the Action
Cyan arrowEvaluate long entries only if price location and structure support upward continuation.The PPO has stopped falling and begun rising after a two‑bar decline, forming a trough in momentum.
Magenta arrowEvaluate short entries only if price location and structure support downward continuation.The PPO has stopped rising and begun falling after a two‑bar rise, forming a peak in momentum.
Trend label flips to Bullish.Favor long setups and avoid counter‑trend shorts unless structure demands it.The PPO has crossed above zero, showing buyers have taken control of momentum pressure.
Trend label flips to Bearish.Favor short setups and avoid counter‑trend longs unless structure demands it.The PPO has crossed below zero, showing sellers have taken control of momentum pressure.
Indicator BehaviorTrader ActionWhy
Histogram flips color against your position.Scale out or close unless structure is holding at a key level.Momentum has crossed the zero boundary, shifting control to the opposite side.
Slope label flips against your position.Reduce size or tighten stops; continuation probability has weakened.Acceleration has reversed, showing momentum is now strengthening in the opposite direction.
Histogram stays your direction but darkens.Stop adding size and tighten risk; hold only if structure remains supportive.Momentum remains on your side but acceleration has weakened, signaling pressure loss.

Code:
# Enhanced PPO with Laguerre/Hull Smoothing and Peak/Trough Signals
# Original base by Mobius/BenTen/antwerks
# whoDAT modified to include secondary aggregation period, price type selection, Laguerre smoothing of input and HMA smoothing of output PPO. Signals are now the peak and trough. 3/2026

declare lower;

# --- Inputs ---
input agg = AggregationPeriod.FIFTEEN_MIN;
input priceType = close;
input gamma = 0.6; # Laguerre Smoothing Factor (0.0 to 1.0)
input nFast = 8;
input nSlow = 13;
input nSmooth = 5; # Hull Smoothing for PPO
input showSignals = yes;

# --- Secondary Aggregation & Price Selection ---
def rawPrice = close(period = agg);
def data = if !IsNaN(rawPrice) then rawPrice else close;

# --- Smoothing 1: Laguerre Filter (Pre-PPO) ---
# This reduces noise in the price data before the oscillator is built
def L0 = (1 - gamma) * data + gamma * L0[1];
def L1 = -gamma * L0 + L0[1] + gamma * L1[1];
def L2 = -gamma * L1 + L1[1] + gamma * L2[1];
def L3 = -gamma * L2 + L2[1] + gamma * L3[1];
def smoothedPrice = (L0 + 2 * L1 + 2 * L2 + L3) / 6;

# --- PPO Calculation ---
def fastMA = ExpAverage(smoothedPrice, nFast);
def slowMA = ExpAverage(smoothedPrice, nSlow);
def rawPPO = (fastMA - slowMA) / slowMA;

# --- Smoothing 2: Hull Moving Average (Post-PPO) ---
# This cleans the PPO line to make peak/trough detection more reliable
plot PPO = HullMovingAvg(rawPPO, nSmooth);

PPO.SetPaintingStrategy(PaintingStrategy.HISTOGRAM);
PPO.SetLineWeight(3);

# Momentum acceleration
def accel = PPO - PPO[1];

PPO.AssignValueColor(
    if PPO > 0 and accel > 0 then Color.GREEN
    else if PPO > 0 and accel < 0 then Color.DARK_GREEN
    else if PPO < 0 and accel < 0 then Color.RED
    else Color.DARK_RED
);

# --- Zero line ---
plot ZeroLine = 0;
ZeroLine.SetDefaultColor(Color.GRAY);

# --- Peak and Trough Signals ---
# Replaced Zero-Cross with Directional Change
def isTrough = PPO > PPO[1] and PPO[1] <= PPO[2];
def isPeak = PPO < PPO[1] and PPO[1] >= PPO[2];

plot BullSignal = if showSignals and isTrough then PPO else Double.NaN;
BullSignal.SetPaintingStrategy(PaintingStrategy.ARROW_UP);
BullSignal.SetDefaultColor(Color.CYAN);

plot BearSignal = if showSignals and isPeak then PPO else Double.NaN;
BearSignal.SetPaintingStrategy(PaintingStrategy.ARROW_DOWN);
BearSignal.SetDefaultColor(Color.MAGENTA);

# --- Labels ---
AddLabel(yes, if PPO > 0 then "Trend: Bullish" else "Trend: Bearish", if PPO > 0 then Color.GREEN else Color.RED);
AddLabel(yes, if accel > 0 then "Slope: Rising" else "Slope: Falling", if accel > 0 then Color.CYAN else Color.MAGENTA);
 
Last edited by a moderator:

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