robertogozzi

Percentage Price Oscillator (PPO)

Category: Indicators By: robertogozzi Created: December 7, 2018, 1:48 PM
December 7, 2018, 1:48 PM
Indicators
18 Comments
Percentage Price Oscillator (PPO)

The percentage price oscillator (PPO) is a technical momentum indicator that shows the relationship between two moving averages. To calculate the PPO, subtract the 26-period exponential moving average (EMA) from the 12-period EMA, and then divide this difference by the 26-period EMA. The result is then multiplied by 100. The indicator tells the trader where the short-term average is relative to the longer-term average.

 

//Percentage Price Oscillator - PPO
//
//The percentage price oscillator (PPO) is a technical momentum indicator that shows the relationship between two moving averages. To calculate the PPO, subtract the 26-period exponential moving average (EMA) from the 12-period EMA, and then divide this difference by the 26-period EMA. The result is then multiplied by 100. The indicator tells the trader where the short-term average is relative to the longer-term average.
//
//  Here is the PPO calculation:    ((12-day EMA - 26-day EMA) / 26-day EMA) x 100
//
// https://www.investopedia.com/terms/p/ppo.asp
// http://www.traderpedia.it/wiki/index.php/Price_oscillator_(DOA)
//
DEFPARAM CalculateOnLastBars = 1000

SlowP      = 26                    //Periods of Slow Average
FastP      = 12                    //Periods of Fast Average
AvgType    = 1                     //Average Type (0=sma, 1=ema, 2=wma,...)
Percentage = 1                     //1=calculate Percentage    0=no percentage
//

SlowP      = max(1,min(999,SlowP))    //1 - 999
FastP      = max(1,min(999,FastP))    //1 - 999
AvgType    = max(0,min(6,AvgType))    //0 - 6
Percentage = max(0,min(1,Percentage)) //1=Percentage     0=NO Percentage
SlowAvg    = Average[SlowP,AvgType](close)
FastAvg    = Average[FastP,AvgType](close)
Difference = FastAvg - SlowAvg
IF Percentage THEN
   Difference = (Difference / SlowAvg) * 100
ENDIF
RETURN Difference,0

I am also attaching the MACD type version (it is very similar):

//Percentage Price Oscillator - PPO (with Histogram)
//
//The percentage price oscillator (PPO) is a technical momentum indicator that shows the relationship between two moving averages. To calculate the PPO, subtract the 26-period exponential moving average (EMA) from the 12-period EMA, and then divide this difference by the 26-period EMA. The result is then multiplied by 100. The indicator tells the trader where the short-term average is relative to the longer-term average.
//
//  Here is the PPO calculation:    ((12-day EMA - 26-day EMA) / 26-day EMA) x 100
//
// https://www.investopedia.com/terms/p/ppo.asp
// http://www.traderpedia.it/wiki/index.php/Price_oscillator_(DOA)
// https://stockcharts.com/school/doku.php?id=chart_school:technical_indicators:price_oscillators_ppo
// http://www.forexwiki.it/PPO
//
SlowP      = 26                    //Periods of Slow Average
FastP      = 12                    //Periods of Fast Average
AvgType    = 1                     //Average Type (0=sma, 1=ema, 2=wma,...)
Percentage = 1                     //1=calculate Percentage    0=no percentage
SignalP    = 9                     //Periods of Signal Average
//
DEFPARAM CalculateOnLastBars = 1000
SlowP      = max(1,min(999,SlowP))    //1 - 999
FastP      = max(1,min(999,FastP))    //1 - 999
AvgType    = max(0,min(6,AvgType))    //0 - 6
Percentage = max(0,min(1,Percentage)) //1=Percentage     0=NO Percentage
SignalP    = max(1,min(999,FastP))    //1 - 999
SlowAvg    = Average[SlowP,AvgType](close)
FastAvg    = Average[FastP,AvgType](close)
Ppo        = FastAvg - SlowAvg
IF Percentage THEN
   Ppo     = (Ppo / SlowAvg) * 100
ENDIF
SignalLine = Average[SignalP,AvgType](Ppo)
Histo      = Ppo - SignalLine
RETURN Ppo AS "Ppo",SignalLine AS "Signal",Histo AS "Histogram",0

Download
Filename: Price-Oscillator-PPO-Histo.itf
Downloads: 291
Download
Filename: Price-Oscillator-PPO.itf
Downloads: 264
robertogozzi
robertogozzi Legend
Roberto https://www.ots-onlinetradingsoftware.com
Author’s Profile

Comments

RubberToe
5 years ago
#

I believe there is an error in line 23 of the MACD version. It points to the FastP. Should be SignalP I think....

SB-FO
6 years ago
#

Sorry, i did forget to change the 7/22, I have run it both ways. PRT is calculating PPO and not PO, that make sense now. Thanks. Have a fantastic weekend.

robertogozzi
6 years ago
#

Firstly you need to make the correct calculation, you need to swap 22 and 7. Secondly PRT's POI uses to return a percentage, so you need to replace the calculation with: PO = (ShortAvg – LongAvg) / LongAvg * 100

SB-FO
6 years ago
#

Code below. Comparison is to PRT standard PO which is // out. DEFPARAM CumulateOrders = False // Cumulating positions deactivated DEFPARAM FLATBEFORE = 093000 DEFPARAM FlatAfter = 154500 capital = 100000 + strategyprofit Equity = capital / close myCurrentProfit = STRATEGYPROFIT ShortAvg = Average[22] (close) LongAvg = Average[7] (close) PO = (ShortAvg - LongAvg) //PO = PriceOscillator[22,7](Close) Trigger = Average[2](PO) // Draw indicator Graph PO COLOURED(34,139,3) AS "SBFO PO" Graph Trigger COLOURED(225,0,0) AS "Trigger" // Conditions to enter long positions IF NOT LongOnMarket AND PO Crosses Over Trigger THEN BUY Equity SHARES AT MARKET ENDIF // Conditions to exit long positions If LongOnMarket AND PO Crosses Under Trigger THEN SELL AT MARKET ENDIF // //Conditions to enter short positions IF NOT ShortOnMarket AND PO Crosses Under Trigger THEN Sellshort Equity SHARES AT MARKET ENDIF

robertogozzi
6 years ago
#

Please post the full working code, otherwiose I can't replicate it. Tellme what you compared it to.

SB-FO
6 years ago
#

Robertogozzi, I have backtested the two following PriceOscillator code, which I thought would result in the same returns, alas they do not. Do you have any insights? I will say that using WeightedAverage is closer to the built in PriceOscillator, yet still not the same. Of course using the same parameters and time period. Do you have any insights as to why this would happen? ShortAvg = WeightedAverage[A] (Close) LongAvg = WeightedAverage[B] (Close) PO = ShortAvg - LongAvg PO = PriceOscillator[A,B](Close) Trigger = Average[C](PO)

SB-FO
6 years ago
#

Ah ha. I will check that and report back. Thank you.

SB-FO
6 years ago
#

Do you mind looking at my code to see if i ma doing something wrong? xClose = Close AvgType = Average Fastp = A Slowp = B ShortAvg = Average[Fastp,AvgType](xClose) LongAvg = Average[Slowp,AvgType](xClose) PO = ShortAvg – LongAvg When I code this, i get a different back test than using the standard PO from PRT.

robertogozzi
6 years ago
#

AvgType = 1 //0 to 8, but is usually o=sma or 1=ema This is the only thing that may cause an error.

SB-FO
6 years ago
#

Look up Price Oscillator, that is the prebuilt in am referring to, PO not PPO.

robertogozzi
6 years ago
#

I have plotted 4 similar indicators on mty chart: PPO, PO (built-in), MACD (built-in) and APO, all with a 12-period fast MA and a 26-period slow MA, all with the same type of moving average, EMA, applied to CLOSE. They all show the same result. It can't be any different since it's the same expression in all of them! The only difference can only be spotted when using different types of Moving Averages. If you still have issues I suggest that you start a new topic in the ProBuilder support so that we can attach pics.

SB-FO
6 years ago
#

Robertogozzi, I agree with it being the difference of the two MA's, however when i compare that to "PriceOscillator[A,B](Xclose)" in PRT it get different backrest results. Thus my question is, what is the code for "PriceOscillator[A,B](Xclose)" so that i can compare why the results are different. Thanks for your help.

robertogozzi
6 years ago
#

Sorry, I can't find any built-in PPO in PRT, so I cannot tell.

SB-FO
6 years ago
#

Nicolas, I am trying to replicate Price Oscillator of PRC (PO NOT PPO) using manual programing to make sure i have it correct. I thought I had it correct but a comparison backtest of the two has very different results. Can you please define the calculation for PRC PriceOscillator as i clearly have something wrong below and PRC does not specify the calculation. xClose = Close AvgType = Average // weightedAverage //ExponentialAverage // Fastp = A Slowp = B TriggerAve = C ShortAvg = Average[Fastp,AvgType](xClose) LongAvg = Average[Slowp,AvgType](xClose) PPO = ShortAvg - LongAvg PPO = PriceOscillator[A,B](Xclose) Trigger = Average[C](PPO)

robertogozzi
6 years ago
#

It’s just the difference of two averages: PO = Fast Moving Average - Slow Moving Average

robertogozzi
6 years ago
#

Hi, I am not Nicolas. Where is the formula of the Oscillator you want to code?

robertogozzi
8 years ago
#

Welcome back Juanji, why don’t you post your strategy in the ProOrder support, it’s a better place to talk about strategies and improve them. Thank you.

juanj
8 years ago
#

Haven't been on this forum for ages! Just logged in to see what is happening and since this caught my eye I decided to quickly write it into a strategy :) For some reason, the Add PRT Code doesn't work so here is the unformatted code: //EURUSD 1Hr Defparam cumulateorders = False possize = 1 SlowP = 26 //Periods of Slow Average FastP = 12 //Periods of Fast Average AvgType = 1 //Average Type (0=sma, 1=ema, 2=wma,...) Percentage = 1 //1=calculate Percentage 0=no percentage SignalP = 9 //Periods of Signal Average // SlowP = max(1,min(999,SlowP)) //1 - 999 FastP = max(1,min(999,FastP)) //1 - 999 AvgType = max(0,min(6,AvgType)) //0 - 6 Percentage = max(0,min(1,Percentage)) //1=Percentage 0=NO Percentage SignalP = max(1,min(999,FastP)) //1 - 999 SlowAvg = Average[SlowP,AvgType](close) FastAvg = Average[FastP,AvgType](close) ppo = FastAvg - SlowAvg IF Percentage THEN ppo = (ppo / SlowAvg) * 100 ENDIF SignalLine = Average[SignalP,AvgType](ppo) Histo = Ppo - SignalLine If longonmarket and histo < 0 or ppo 0 or ppo > SignalLine Then Exitshort at market EndIf If ppo > 0 and signalLine SignalLine Then If shortonmarket Then Exitshort at market EndIf Buy possize contract at market ElsIf ppo 0 and ppo < SignalLine Then If longonmarket Then Sell at market EndIf Sellshort possize contract at market EndIf

ProRealCode ProRealCode
Loading...