Central Pivot Range (CPR)
Summary
Central Pivot Range: a central pivot and two lines straddling it, computed from the previous bar's high, low and close and held for the current bar. The distance between the outer lines is the reading: an unusually narrow range tends to precede a trending bar, an unusually wide one a rangebound bar.
Chart
Chart metadata i
Outputs
outRealUpperBand:upper_limitoutRealMiddleBand:lineoutRealLowerBand:lower_limit
Formula
With , and the high, low and close of the previous bar:
Notes
- The levels come from the previous bar, so the bars fed in set the period of the range: daily bars give the daily range drawn over an intraday session, weekly bars the weekly one.
- The two outer lines are the midpoint of the previous bar's high and low, and that midpoint mirrored across the pivot. The mirrored line is the higher one when the previous close is above the midpoint and the lower one when it is below, so the outputs are ordered at every bar: the upper output is always the higher line. Ochoa labels the levels the same way.
- The first bar produces no value because it has no previous bar.
Inputs
inHigh— High price of each barinLow— Low price of each barinClose— Close price of each bar
Outputs
outRealUpperBand— The higher of the two outer linesoutRealMiddleBand— The central pivotoutRealLowerBand— The lower of the two outer lines
Properties
Numerical Stability: Start-Independent
| ✅ Overlap Input i |
| ☐ Independent Y-Axis |
| ☐ Candlestick |
| ☐ Display Shift |
| ☐ Can Output NaN or ±Inf |
| ☐ Identity at Period 1 |
| ☐ Uses Transcendental |
| ☐ Input Must Be Positive |
Example
C
#include <stdio.h>
#include <ta_libc.h>
int n = 252;
double high[252]; /* your data, oldest first */
double low[252]; /* your data, oldest first */
double close[252]; /* your data, oldest first */
double upperBand[252], middleBand[252], lowerBand[252];
int outBegIdx, outNBElement;
TA_Initialize();
TA_CPR( 0, n - 1, high, low, close, &outBegIdx, &outNBElement, upperBand, middleBand, lowerBand );
printf( "%d values from bar %d:\n", outNBElement, outBegIdx );
printf( "upperBand = [%.4f, ..., %.4f]\n", upperBand[0], upperBand[outNBElement - 1] );
printf( "middleBand = [%.4f, ..., %.4f]\n", middleBand[0], middleBand[outNBElement - 1] );
printf( "lowerBand = [%.4f, ..., %.4f]\n", lowerBand[0], lowerBand[outNBElement - 1] );Rust
use ta_lib::Core;
let high = vec![0.0; 252]; // your data, oldest first
let low = vec![0.0; 252]; // your data, oldest first
let close = vec![0.0; 252]; // your data, oldest first
let mut upper_band = vec![0.0; 252];
let mut middle_band = vec![0.0; 252];
let mut lower_band = vec![0.0; 252];
let core = Core::new();
let range = core.cpr(0, high.len() - 1, &high, &low, &close,
&mut upper_band, &mut middle_band, &mut lower_band)?;
println!("{} values from bar {}:", range.count, range.beg_idx);
println!("upper_band = [{:.4}, ..., {:.4}]", upper_band[0], upper_band[range.count - 1]);
println!("middle_band = [{:.4}, ..., {:.4}]", middle_band[0], middle_band[range.count - 1]);
println!("lower_band = [{:.4}, ..., {:.4}]", lower_band[0], lower_band[range.count - 1]);Java
import io.github.talib.Core;
import io.github.talib.OutRange;
import java.util.Locale;
double[] high = new double[252]; // your data, oldest first
double[] low = new double[252]; // your data, oldest first
double[] close = new double[252]; // your data, oldest first
double[] upperBand = new double[252];
double[] middleBand = new double[252];
double[] lowerBand = new double[252];
Core core = Core.DEFAULT;
OutRange r = core.cpr(0, high.length - 1, high, low, close, upperBand, middleBand, lowerBand);
System.out.printf(Locale.ROOT, "%d values from bar %d:%n", r.count(), r.begIdx());
System.out.printf(Locale.ROOT, "upperBand = [%.4f, ..., %.4f]%n", upperBand[0], upperBand[r.count() - 1]);
System.out.printf(Locale.ROOT, "middleBand = [%.4f, ..., %.4f]%n", middleBand[0], middleBand[r.count() - 1]);
System.out.printf(Locale.ROOT, "lowerBand = [%.4f, ..., %.4f]%n", lowerBand[0], lowerBand[r.count() - 1]);C#
using System;
using TALib;
var high = new double[252]; // your data, oldest first
var low = new double[252]; // your data, oldest first
var close = new double[252]; // your data, oldest first
var upperBand = new double[252];
var middleBand = new double[252];
var lowerBand = new double[252];
var core = Core.Default;
OutRange r = core.Cpr(0, high.Length - 1, high, low, close, upperBand, middleBand, lowerBand);
Console.WriteLine($"{r.Count} values from bar {r.BegIdx}:");
Console.WriteLine(FormattableString.Invariant($"upperBand = [{upperBand[0]:F4}, ..., {upperBand[r.Count - 1]:F4}]"));
Console.WriteLine(FormattableString.Invariant($"middleBand = [{middleBand[0]:F4}, ..., {middleBand[r.Count - 1]:F4}]"));
Console.WriteLine(FormattableString.Invariant($"lowerBand = [{lowerBand[0]:F4}, ..., {lowerBand[r.Count - 1]:F4}]"));TypeScript
import { cpr } from 'ta-lib';
const high = new Float64Array(252); // your data, oldest first
const low = new Float64Array(252); // your data, oldest first
const close = new Float64Array(252); // your data, oldest first
const {
begIdx,
outUpperBand,
outMiddleBand,
outLowerBand,
} = cpr({ high, low, close });
console.log(outUpperBand.length + ' values from bar ' + begIdx + ':');
console.log('outUpperBand = [' + outUpperBand[0]?.toFixed(4) + ', ..., ' + outUpperBand[outUpperBand.length - 1]?.toFixed(4) + ']');
console.log('outMiddleBand = [' + outMiddleBand[0]?.toFixed(4) + ', ..., ' + outMiddleBand[outMiddleBand.length - 1]?.toFixed(4) + ']');
console.log('outLowerBand = [' + outLowerBand[0]?.toFixed(4) + ', ..., ' + outLowerBand[outLowerBand.length - 1]?.toFixed(4) + ']');Go
import (
"fmt"
"log"
talib "ta-lib.github.io/go"
)
high := make([]float64, 252) // your data, oldest first
low := make([]float64, 252) // your data, oldest first
close := make([]float64, 252) // your data, oldest first
upperBand := make([]float64, 252)
middleBand := make([]float64, 252)
lowerBand := make([]float64, 252)
core := talib.NewCore()
r, err := core.CPR(0, len(high)-1, high, low, close, upperBand, middleBand, lowerBand)
if err != nil {
log.Fatal(err)
}
fmt.Printf("%d values from bar %d:\n", r.NBElement, r.BegIdx)
fmt.Printf("upperBand = [%.4f, ..., %.4f]\n", upperBand[0], upperBand[r.NBElement-1])
fmt.Printf("middleBand = [%.4f, ..., %.4f]\n", middleBand[0], middleBand[r.NBElement-1])
fmt.Printf("lowerBand = [%.4f, ..., %.4f]\n", lowerBand[0], lowerBand[r.NBElement-1])Implementation
Added in 0.8.4.
TA-Lib Definition: cpr.c · cpr.yaml
| Native | File |
|---|---|
| C | ta_CPR.c |
| Rust | cpr.rs |
| Java | Core_CPR.java |
| C# | Core_CPR.cs |
| TypeScript | cpr.ts |
| Go | cpr.go |
Python: talib.CPR, see ta-lib-python.
TA-Lib is also available for R and more using a wrapper.
Aliases
Central Pivot Range, Pivot Range
See Also
TYPPRICE · MEDPRICE · DONCHIAN
References
- A Quick Guide to the Pivot Range — Frank Ochoa, pivotboss.com
- Pivot Width Analysis (Part 1 of 3) — Frank Ochoa, pivotboss.com
- Frank O. Ochoa, Secrets of a Pivot Boss (2010, ISBN 978-0615391274)
- Mark B. Fisher, The Logical Trader (2002)