PPO (Price Percent Oscillator) for ThinkorSwim

BenTen

Administrative
Staff
VIP
PPO is similar to MACD. The oscillator is displayed as a percentage so is consistent between all equities.

This script for ToS was created by Mobius.

neok9UZ.png


thinkScript Code

Code:
# PPO
# Mobius
# V01.03.2014

declare lower;

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

plot PPO = ((MovingAverage(AverageType = AvgType, c, nFast) -
             MovingAverage(AverageType = AvgType, c, nSlow)) /
             MovingAverage(AverageType = AvgType, c, 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

Shareable Link

https://tos.mx/hv8hVf
 

horserider

Well-known member
VIP
The Mobius version BenTen put up is a SMA version of the PPO. The original PPO formula I believe uses the EMA.
skynetgen uses the EMA PPO formula with interesting additions.

If want a simple PPO displayed https://tos.mx/NCheJqs
If want a daily/weekly PPO it is a ToS study. Search studies for it.

I Believe the Ultimate MACD will give equivalent signals plus more info.
 

Baller2356

New member
Can someone give the PPO indicator like the one on Stock charts.com? I know that there is one on this website already. However, it only shows one line. Is there any way you could make it show two lines? Thanks so much!
 

wpwright

New member
Does anyone have PPO that plots, histogram, fast and slow lines? This one has histogram but only plots (1) line. I need the line crossover.
 

wpwright

New member
PPO Indicator is missing (1) plot. Indicator has histogram and (1) plot, there is supposed to be a fast line and a slow line (2) line plots. I need the cross over of the line plots for signal generation.
 

grasshopper123

New member
I 2nd, 3rd, and 4th a request for PPO indicator like the one on Stock charts.com or freestockcharts.com :)
Of course I could be doing something wrong but the ones I've tried from here (and yes I adjust the settings as appropriate so they match) give results that differ from each other and the MACD included in TOS.
Thanks in advance
 

MerryDay

Well-known member
VIP
@grasshopper123 A 2nd, 3rd, and 4th request will probably not yield any further results. If you tried what is on this site, what are you expecting?

@wpwright I did was a simple google search, I am assuming that you did also and already saw this Easycator PPO w/ fast and slow lines and it wasn't what you wanted.

However here it is for anyone in the future that has this request:

Code:
#
# TD Ameritrade IP Company, Inc. (c) 2007-2016
#
## created by North Vanhooser

declare lower;

input fastPeriod   = 12;
input slowPeriod   = 26;
input signalPeriod = 9;
input price        = close;

def fastEma   = ExpAverage( price, fastPeriod );
def slowEma   = ExpAverage( price, slowPeriod );
def periodOK  = fastPeriod < slowPeriod;
AddLabel( !periodOK, "ERROR: fastPeriod MUST be less than slowPeriod" );
def _ppo      = if periodOK then ((fastEma - slowEma) / slowEma) * 100 else 0;
def _signal   = ExpAverage( _ppo, signalPeriod );

plot Ppo      = _ppo;
Ppo.SetDefaultColor( Color.BLUE );
Ppo.HideBubble();

plot PpoEma   = _signal;
PpoEma.SetDefaultColor( Color.CYAN );
PpoEma.HideBubble();

plot zeroLine = 0;
zeroLine.HideBubble();
zeroLine.AssignValueColor( Color.BLACK );

plot PpoH1    = _ppo - _signal;
PpoH1.SetPaintingStrategy( PaintingStrategy.HISTOGRAM );
PpoH1.DefineColor("Up", Color.UPTICK);
PpoH1.DefineColor("Down", Color.DOWNTICK);
PpoH1.DefineColor("Flat", Color.GRAY);
PpoH1.AssignValueColor( if PpoH1 > PpoH1[1] then
                           PpoH1.Color("Up")
                       else
                         if PpoH1 < PpoH1[1] then
                           PpoH1.Color("Down")
                       else
                           PpoH1.Color("Flat"));
PpoH1.HideBubble();
PpoH1.SetLineWeight( 3 );


Here is the shared link: http://tos.mx/zQ6P90
 
Last edited:

Geisman

New member
VIP
Ohh since you brought it up. Here is PPO version with divergence and pivot indicators
https://tos.mx/VmatfLU
Is this your indicator? Do you happen to have this in a scan that alerts to stocks triggering the up or down arrow to setup a watchlist? I love this indicator and find the signals are quite accurate but I'm too ignorant to know how to setup a scan so it shows me the stocks triggering those arrows.

This is the code in case I'm getting your's confused with this one.

Code:
#converted from mobisu macd to ppo
# this is actually macd and sqz indicator in one
# added pivots

declare lower;

input fastPeriod   = 12; #9/18/6 for 5m
input slowPeriod   = 26;
input signalPeriod = 9;
input price        = close;
input show = yes;

def fastEma   = ExpAverage( price, fastPeriod );
def slowEma   = ExpAverage( price, slowPeriod );
def periodOK  = fastPeriod < slowPeriod;
AddLabel( !periodOK, "ERROR: fastPeriod MUST be less than slowPeriod" );
def _ppo      = if periodOK then ((fastEma - slowEma) / slowEma) * 100 else 0;
def _signal   = ExpAverage( _ppo, signalPeriod );

# generic plots wiht colors
plot pmain   = _ppo;
pmain.SetDefaultColor( Color.BLUE );
pmain.SetLineWeight(2);
pmain.AssignValueColor(if pmain < 0 and pmain < pmain[1]  then Color.RED
                       else if pmain < 0 and  pmain > pmain[1] then Color.DARK_GREEN
                       else if pmain > 0 and pmain > pmain[1] then Color.GREEN
                       else Color.DARK_RED);
pmain.HideBubble();

plot mainEma   = _signal;
mainEma.SetDefaultColor( Color.RED );
mainEma.HideBubble();
AddCloud(pmain, mainEma, Color.GREEN, Color.RED);

#diff as histogram
plot diff    = _ppo - _signal;
diff.SetDefaultColor(GetColor(5));
diff.SetPaintingStrategy(PaintingStrategy.HISTOGRAM);
diff.SetLineWeight(3);
diff.DefineColor("Positive and Up", Color.GREEN);
diff.DefineColor("Positive and Down", Color.DARK_GREEN);
diff.DefineColor("Negative and Down", Color.RED);
diff.DefineColor("Negative and Up", Color.DARK_RED);
diff.AssignValueColor(if diff >= 0 then if diff > diff[1] then diff.Color("Positive and Up") else diff.Color("Positive and Down") else if diff < diff[1] then diff.Color("Negative and Down") else diff.Color("Negative and Up"));

#mobius divergence calc
def pmainh = CompoundValue(1, 
            if pmain < 0 then Double.NaN
            else if pmain crosses above 0  then pmain
            else if pmain > 0 and  pmain > pmainh[1]
            then pmain else pmainh[1], 0);

def Valueh = CompoundValue(1, 
             if pmain < 0 then Double.NaN
             else if pmain crosses above 0  then high
             else if pmain > 0 and high > Valueh[1] then high
             else Valueh[1], 0);

plot divLowSignal = if pmain > 0 and  high > Valueh[1] and pmain < pmainh[1] then 0
                 else Double.NaN;
divLowSignal.SetPaintingStrategy(PaintingStrategy.SQUARES);
divLowSignal.SetLineWeight(5);
divLowSignal.SetDefaultColor(Color.dark_orange);

def pmainL = CompoundValue(1, if pmain > 0 then Double.NaN
                             else if pmain crosses below 0  then pmain
                             else if pmain < 0 and pmain < pmainl[1] then pmain
                             else pmainl[1], 0);

def ValueL = CompoundValue(1, if pmain > 0  then Double.NaN
                              else if pmain crosses below 0 then low
                              else if pmain < 0 and low < Valuel[1] then low
                              else Valuel[1], 0);

plot divUpSignall = if pmain < 0 and   low < Valuel[1] and pmain > pmainl[1] then 0
                 else Double.NaN;
divupSignall.SetPaintingStrategy(PaintingStrategy.SQUARES);
divUpSignall.SetLineWeight(5);
divUPSignall.SetDefaultColor(Color.blue);

#zeroline
plot zeroLine = 0;
zeroLine.SetPaintingStrategy(PaintingStrategy.LINE);
zeroLine.SetLineWeight(1);
zeroLine.SetDefaultColor(Color.BLACK);

#pivots

def ptrend = pmain;
def prange = 2;
def pivotHigh = if IsNaN(ptrend[-1]) then 0  else Lowest(ptrend, prange)[1] > ptrend and Lowest(ptrend, prange)[-prange] > ptrend ;
def pivotLow =  if  IsNaN(ptrend[-1]) then 0  else Highest(ptrend, prange)[1] < ptrend and Highest(ptrend, prange)[-prange] < ptrend ;
#study
plot plotPH = if pivotHigh and show then ptrend else Double.NaN;
plotPH.SetPaintingStrategy(PaintingStrategy.ARROW_UP);
plotPH.SetDefaultColor(Color.GREEN);

plot phline = if pivotHigh then pmain else Double.NaN;
phline.SetDefaultColor(Color.DARK_GREEN);
phline.EnableApproximation();phline.Hide();
#
plot plotPL = if pivotLow and show then ptrend else Double.NaN;
plotPL.SetPaintingStrategy(PaintingStrategy.ARROW_DOWN);
plotPL.SetDefaultColor(Color.RED);

plot plline = if pivotLow then pmain else Double.NaN;
plline.SetDefaultColor(Color.RED);
plline.EnableApproximation(); plline.hide();
 

MerryDay

Well-known member
VIP
@Geisman
Setting Up The Scanner
qD04qMH.png

Copy the code from the forum
In TOS, in studies, click on Create
Paste the code from the forum
Save the study with the name: PPO_divergence
uQy5Xii.png

Click on scan.
Click on +Add filter
Click on the pencil icon next to the filter you just added
Click edit
Click on pull-down window, click add study
Type in PPO_divergence
In the Plot pull-down window, click on PlotPH
In the middle column, choose True
Save

If you have trouble, post a screenshot of where you are hung up. HTH
 

rad14733

Well-known member
VIP
@Geisman Not knowing means you have a prime opportunity to learn... @MerryDay has been kind enough to get you started... Learning is an expectation here, not just expecting others to do your work for you... You're managing your own trading account without our help right...??? Learn to make yourself more money then... You'll be glad you did... 💰💰💰
 

Geisman

New member
VIP
@Geisman

If you have trouble, post a screenshot of where you are hung up. HTH
You are an amazing person. Seriously. Thank you. I'll work on it and see if I can do it. Covid has mucked up my ability to think clearly. Brain fog is crazy bad now and it's been 4 weeks since I got over it.
 

MerryDay

Well-known member
VIP
@Geisman I had a death in the family. Can totally relate to swimming through the brain fog. Hang in there. And play with the scanner. It won't break. :) I didn't find TOS intuitive but this forum is amazing w/ people who selflessly give their knowledge and their time.
 

Geisman

New member
VIP
@Geisman I had a death in the family. Can totally relate to swimming through the brain fog. Hang in there. And play with the scanner. It won't break. :) I didn't find TOS intuitive but this forum is amazing w/ people who selflessly give their knowledge and their time.
I've gone through the scanner tutorials in the past and used it for a while but I always get stuck trying to customize it more to do more specific things. I think the the UI for the TOS scanner is quite shite. Some areas of TOS are really logical and others seem like an entirely different coding team developed it which is probably the case with the scanner section. In this case with the PPO study, when I add the custom study I don't get the Plot drop down menu. Once I click PPO from the custom study list, it's completely blank under it instead of the Plot drop down menu populating. This is where I always get stuck trying to figure out how to get the plot arrows to trigger on the scan.
 

Similar threads

Top