Percentage Price Oscillator (PPO)
Summary
Percentage Price Oscillator: the difference between a fast and slow moving average expressed as a percentage of the slow MA. A normalized (scale-invariant) variant of APO. Positive when the fast MA is above the slow MA (upward momentum), negative otherwise; magnitude is the % deviation.
Chart
Chart metadata i
Outputs
outReal:line·zero·positive·negative
Formula
PPO = ((fastMA(inReal) - slowMA(inReal)) / slowMA(inReal)) * 100, both MAs of type optInMAType; output = 0 when slowMA == 0
The standard form is exponential with periods 12 and 26 — ((12-day EMA - 26-day EMA) / 26-day EMA) * 100, i.e. the MACD oscillator expressed as a percentage. optInMAType therefore defaults to EMA — the moving average Gerald Appel used for the original PPO/MACD; pass another type (e.g. TA_MAType_SMA) to override.
Notes
- The input is assumed positive. The slow moving average is the divisor. Near zero the divisor is small and the output very large; no error is returned. A series that reaches or crosses zero, such as an oscillator or a spread, has no meaningful result here.
optInMATypeapplies to both the fast and slow moving average.TA_MAType_MAMAignores its period argument, so withoptInMAType = TA_MAType_MAMAthe fast and slow MAs are identical, making the numerator — and therefore the output — zero at every bar.- If the slow period is set smaller than the fast period, the two are swapped, as in
MACD.
Inputs
inReal— Input data series
Outputs
outReal— PPO value in percent
Parameters
| Parameter | Type | Default | Accepted values | Description |
|---|---|---|---|---|
optInFastPeriod | integer | 12 | 2–100000 | Period of the fast MA |
optInSlowPeriod | integer | 26 | 2–100000 | Period of the slow MA |
optInMAType | MAType | EMA (1) | any MAType | Moving average type used for both MAs |
MAType values: 0 SMA · 1 EMA · 2 WMA · 3 DEMA · 4 TEMA · 5 TRIMA · 6 KAMA · 7 MAMA · 8 T3 · 9 HMA · 10 DISABLED · 11 DEFAULT · 12 ZLEMA · 13 RMA · 14 VIDYA · 15 ALMA
Properties
Numerical Stability: Depends on MA Type — This function's default, EMA, has an initial unstable period.
| ☐ Overlap Input |
| ✅ Independent Y-Axis i |
| ☐ Candlestick |
| ☐ Display Shift |
| ☐ Can Output NaN or ±Inf |
| ☐ Identity at Period 1 |
| ☐ Uses Transcendental |
| ✅ Input Must Be Positive i |
Example
#include <stdio.h>
#include <ta_libc.h>
int n = 252;
double series[252]; /* your data, oldest first */
double out[252];
int outBegIdx, outNBElement;
TA_Initialize();
TA_PPO( 0, n - 1, series, 12, 26, TA_MAType_EMA, &outBegIdx, &outNBElement, out );
printf( "%d values from bar %d: [%.4f, ..., %.4f]\n", outNBElement, outBegIdx, out[0], out[outNBElement - 1] );use ta_lib::{Core, MAType};
let series = vec![0.0; 252]; // your data, oldest first
let mut out = vec![0.0; 252];
let core = Core::new();
let range = core.ppo(0, series.len() - 1, &series, 12, 26, MAType::EMA, &mut out)?;
println!("{} values from bar {}: [{:.4}, ..., {:.4}]", range.count, range.beg_idx, out[0], out[range.count - 1]);import io.github.talib.Core;
import io.github.talib.MAType;
import io.github.talib.OutRange;
import java.util.Locale;
double[] series = new double[252]; // your data, oldest first
double[] out = new double[252];
Core core = Core.DEFAULT;
OutRange r = core.ppo(0, series.length - 1, series, 12, 26, MAType.EMA, out);
System.out.printf(Locale.ROOT, "%d values from bar %d: [%.4f, ..., %.4f]%n", r.count(), r.begIdx(), out[0], out[r.count() - 1]);using System;
using TALib;
var series = new double[252]; // your data, oldest first
var outReal = new double[252];
var core = Core.Default;
OutRange r = core.Ppo(0, series.Length - 1, series, 12, 26, MAType.EMA, outReal);
Console.WriteLine(FormattableString.Invariant($"{r.Count} values from bar {r.BegIdx}: [{outReal[0]:F4}, ..., {outReal[r.Count - 1]:F4}]"));import { MAType, ppo } from 'ta-lib';
const series = new Float64Array(252); // your data, oldest first
const { begIdx, values } = ppo(series, {
fastPeriod: 12,
slowPeriod: 26,
maType: MAType.EMA,
});
console.log(values.length + ' values from bar ' + begIdx + ': [' + values[0].toFixed(4) + ', ..., ' + values[values.length - 1].toFixed(4) + ']');import (
"fmt"
"log"
talib "ta-lib.github.io/go"
)
series := make([]float64, 252) // your data, oldest first
out := make([]float64, 252)
core := talib.NewCore()
r, err := core.PPO(0, len(series)-1, series, 12, 26, talib.MATypeEMA, out)
if err != nil {
log.Fatal(err)
}
fmt.Printf("%d values from bar %d: [%.4f, ..., %.4f]\n", r.NBElement, r.BegIdx, out[0], out[r.NBElement-1])Implementation
Added in 0.4.0.
TA-Lib Definition: ppo.c · ppo.yaml
| Native | File |
|---|---|
| C | ta_PPO.c |
| Rust | ppo.rs |
| Java | Core_PPO.java |
| C# | Core_PPO.cs |
| TypeScript | ppo.ts |
| Go | ppo.go |
Python: talib.PPO, see ta-lib-python.
TA-Lib is also available for R and more using a wrapper.
Aliases
Percentage Price Oscillator
See Also
References
- Gerald Appel, creator of the PPO and MACD (MACD introduced 1979 in his Systems and Forecasts newsletter). The PPO is the MACD expressed as a percentage of the slow moving average. Appel's original definition uses exponential moving averages (periods 12, 26).