PPO (Price Percent Oscillator) for ThinkorSwim

Hi BenTen: As you know ToS "canned" indicators based on a type of average require a period "length" defined as a number of "bars". Chart bars are specified in "timeframe". As the user changes the chart timeframe, the moving averages change.
I prefer to chart a fixed time duration(s) for all indicators so the average remains a similar "filter bandwidth" and use different timeframes to zoom across various time periods. For example fix exponential moving average "length" with the following statement
expaverage (close (period=aggregationperiod.day), length=XXX) where xxx is specified to be 21, 50, 200.

I would like to modify PPO script to utilize fixed aggregation periods such as PPO(5,21,3) for nfast = 5 days, nslow=21days, and nsmooth=3days. I will also create PPO studies for (21,50,9) and PPO(120,200,50).

Does this make sense?
Thanks!

Try this and let me know if this is what you're looking for.

The timeframe is set to Hourly but you can change it to whatever timeframe you want from the indicator's settings.

Code:
# PPO
# Mobius
# V01.03.2014

declare lower;

input Period = aggregationPeriod.HOUR;
input c = close;
input AvgType = AverageType.Simple;
input nFast = 8;
input nSlow = 13;
input nSmooth = 5;

plot PPO = ((MovingAverage(AverageType = AvgType, close(period = Period), nFast) -
             MovingAverage(AverageType = AvgType, close(period = Period), nSlow)) /
             MovingAverage(AverageType = AvgType, close(period = Period), nSlow));
PPO.SetPaintingStrategy(PaintingStrategy.Histogram);
PPO.AssignValueColor(if PPO > 0
                     then color.green
                     else color.red);

plot smooth = MovingAverage(AverageType = AvgType, PPO, nSmooth);
smooth.SetPaintingStrategy(PaintingStrategy.Line);
smooth.SetDefaultColor(Color.Cyan);
# End Code PPO
 

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

Try this and let me know if this is what you're looking for.

The timeframe is set to Hourly but you can change it to whatever timeframe you want from the indicator's settings.

Code:
# PPO
# Mobius
# V01.03.2014

declare lower;

input Period = aggregationPeriod.HOUR;
input c = close;
input AvgType = AverageType.Simple;
input nFast = 8;
input nSlow = 13;
input nSmooth = 5;

plot PPO = ((MovingAverage(AverageType = AvgType, close(period = Period), nFast) -
             MovingAverage(AverageType = AvgType, close(period = Period), nSlow)) /
             MovingAverage(AverageType = AvgType, close(period = Period), nSlow));
PPO.SetPaintingStrategy(PaintingStrategy.Histogram);
PPO.AssignValueColor(if PPO > 0
                     then color.green
                     else color.red);

plot smooth = MovingAverage(AverageType = AvgType, PPO, nSmooth);
smooth.SetPaintingStrategy(PaintingStrategy.Line);
smooth.SetDefaultColor(Color.Cyan);
# End Code PPO
Wow, thank you BenTen!!! I will test this and revert with feedback. All the best!
Marcus Crahan
 
@BenTen and I have worked on this one before - he has done a bang-up job with this one. I made some changes (sorry BenTen if I messed it up) that goes along with my other indicators. I don't like my Oscillators to be contradicting price action trend unless it is predicting. I added some color changes on the bars to denote momentum changes and arrows for ICT style "break of structures or change of character in a way. Plus, the time frame changes as the chart changes, so you won't have to go into the set-up page and alter the timeframe every time. https://tos.mx/!57rZ0Bjk
 
@BenTen thank you for your constant aggregation period version of PPO indicator. It works! Histogram gets a best messy with short time period candles. The maths are correct, display is a function of "time zoom effect".

@antwerks, thanks for your effort also. I noticed your edits in the basic PPO and had intended to integrate @BenTen's constant aggregation period version into your version. Looks like you "beat me to the punch". I will try this today and revert with feedback!
Thank you both very much (very green to ToS script use).
Marcus Crahan
 

Similar threads

Not the exact question you're looking for?

Start a new thread and receive assistance from our community.

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