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)
//
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
//
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
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