Absolute Price Oscillator (APO)
Summary
Absolute Price Oscillator: the difference between a fast and a slow moving average of the input, in price units. Measures short- vs long-term momentum. Positive when fast MA > slow MA (upward momentum); negative otherwise.
Chart
Chart metadata i
Outputs
outReal:line·zero·positive·negative
Formula
, both MAs of type optInMAType
The standard form is exponential — APO with EMA and periods 12/26 is the fast-minus-slow EMA construction underlying the MACD (in price units). optInMAType therefore defaults to EMA — the moving average Gerald Appel used for the original MACD; pass another type (e.g. TA_MAType_SMA) to override.
Notes
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 and the output is zero at every bar.- If the slow period is set smaller than the fast period, the two are swapped, as in
MACD.
Inputs
inReal— Source data series
Outputs
outReal— Fast MA minus slow MA
Parameters
| Parameter | Type | Default | Accepted values | Description |
|---|---|---|---|---|
optInFastPeriod | integer | 12 | 2–100000 | Period of the fast moving average |
optInSlowPeriod | integer | 26 | 2–100000 | Period of the slow moving average |
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 |
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_APO( 0, n - 1, series, 12, 26, TA_MAType_EMA, &outBegIdx, &outNBElement, out );
printf( "%d values from bar %d; last out = %f\n", outNBElement, outBegIdx, 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.apo(0, series.len() - 1, &series, 12, 26, MAType::EMA, &mut out)?;
println!("{} values from bar {}; last out = {}", range.count, range.beg_idx, out[range.count - 1]);import io.github.talib.Core;
import io.github.talib.MAType;
import io.github.talib.OutRange;
double[] series = new double[252]; // your data, oldest first
double[] out = new double[252];
Core core = Core.DEFAULT;
OutRange r = core.apo(0, series.length - 1, series, 12, 26, MAType.EMA, out);
System.out.println(r.count() + " values from bar " + r.begIdx() + "; last out = " + 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.Apo(0, series.Length - 1, series, 12, 26, MAType.EMA, outReal);
Console.WriteLine($"{r.Count} values from bar {r.BegIdx}; last outReal = {outReal[r.Count - 1]}");import { MAType, apo } from 'ta-lib';
const series = new Float64Array(252); // your data, oldest first
const { begIdx, values } = apo(series, {
fastPeriod: 12,
slowPeriod: 26,
maType: MAType.EMA,
});
console.log(values.length + ' values from bar ' + begIdx + '; last values = ' + values[values.length - 1]);Implementation
Added in 0.4.0.
TA-Lib Definition: apo.c · apo.yaml
| Native | File |
|---|---|
| C | ta_APO.c |
| Rust | apo.rs |
| Java | Core_APO.java |
| C# | Core_APO.cs |
| TypeScript | apo.ts |
Python: talib.APO, see ta-lib-python.
TA-Lib is also available for R and more using a wrapper.
Aliases
Absolute Price Oscillator
See Also
References
- Gerald Appel, creator of the MACD (introduced 1979 in his Systems and Forecasts newsletter). The APO is the same fast-minus-slow moving-average oscillator in price units; with exponential moving averages and periods 12/26 it is the oscillator underlying the MACD line. Appel's original definition uses exponential moving averages.