Skip to main content

The Central Pivot Range (CPR) Indicator: Transforming Intraday Trading

The Central Pivot Range (CPR) emerges as a premier indicator for intraday trading, echoing the functionality of traditional pivot points. It not only marks daily support and resistance levels but also unveils a unique three-tier pivot point system – Pivot, BC, and TC. Today, we’ll delve into the CPR AFL code with built-in exploration. With this code, traders can not only monitor CPR levels for their preferred stocks but also pinpoint stocks with narrow CPR ranges.

For an in-depth understanding of CPR’s mechanics, calculations, and uses, click the link below:

In-depth Exploration of the CPR Indicator

Comprehensive Look at CPR Exploration

The exploration code is thoughtfully crafted based on standard CPR calculation formulas:

  • TC = (Pivot – BC) + Pivot
  • Pivot = (High + Low + Close) / 3
  • BC = (High + Low) / 2

These formulas effectively use the previous day’s High, Low, and Close prices to determine current CPR levels.

Significant aspects of the exploration include:

  • Pivot – The central point of the CPR
  • TC – The top tier of the CPR
  • BC – The lower tier of the CPR
  • NarrowRange – A measure of CPR width
  • R1/R2/R3/R4 – Representing Resistance Levels
  • S1/S2/S3/S4 – Indicating Support Levels

CPR AFL Code

				
					//------------------------------------------------------
//
//  Formula Name:    CPR Exploration AFL
//  Website:         https://zerobrokerageclub.com/
//------------------------------------------------------

_SECTION_BEGIN("CPR Exploration");

PrevDay = 0; // Value should be 1 if your database is updated upto current day

PrevLow = Ref(L,-PrevDay);
PrevHigh = Ref(H,-PrevDay);
PrevClose = Ref(C,-PrevDay);

Pivot = (PrevLow+PrevHigh+PrevClose)/3;
BC = (PrevLow+PrevHigh)/2;
TC = (Pivot-BC) + Pivot;

NRThreshold = 0.2;
NarrowRangeCond = (abs(TC-BC)/PrevClose*100) < NRThreshold;
NarrowRange = WriteIF(NarrowRangeCond,"YES","NO");

NarrowRangeFGColor=IIf(NarrowRangeCond,colorWhite,colorBlack);
NarrowRangeBKColor=IIf(NarrowRangeCond,colorBrightGreen,colorWhite);

R1 = (2*Pivot) - PrevLow;
R2 = (Pivot+PrevHigh) - PrevLow;
R3 = R1 + (PrevHigh-PrevLow);
R4 = R3 + (R2-R1);

S1 = (2*Pivot) - PrevHigh;
S2 = Pivot - (PrevHigh-PrevLow);
S3 = S1 - (PrevHigh-PrevLow);
S4 = S3 - (S1-S2);
  
Filter = C>10;
 
AddColumn(PrevClose, "Close", 1.2,colorBlack,colorLightGrey,width=100);
AddColumn(PrevLow, "Low", 1.2,colorBlack,colorLightGrey,width=100);
AddColumn(PrevHigh, "High", 1.2,colorBlack,colorLightGrey,width=100);
AddColumn(Pivot, "Pivot", 1.2, colorBlack, colorLightOrange,100);
AddColumn(BC, "BC", 1.2, colorBlack, colorAqua,100);
AddColumn(TC, "TC", 1.2, colorBlack, colorPaleTurquoise,100);
AddTextColumn(NarrowRange, "NarrowRange",format=1.2,NarrowRangeFGColor,NarrowRangeBKColor);
AddColumn(R1,"R1",1.2,colorWhite,colorBlueGrey,100);
AddColumn(R2,"R2",1.2,colorWhite,colorBlueGrey,100);
AddColumn(R3,"R3",1.2,colorWhite,colorBlueGrey,100);
AddColumn(R4,"R4",1.2,colorWhite,colorBlueGrey,100);

AddColumn(S1,"S1",1.2,colorWhite,colorTeal,100);
AddColumn(S2,"S2",1.2,colorWhite,colorTeal,100);
AddColumn(S3,"S3",1.2,colorWhite,colorTeal,100);
AddColumn(S4,"S4",1.2,colorWhite,colorTeal,100);


_SECTION_END();
				
			

Tested for Amibroker version 6 and above, you can download the Amibroker trial from this link.

How to Apply the CPR Exploration Code

Implement the exploration code in Amibroker by following these steps:

  1. Open Amibroker, choose File–>New–>Formula and insert the downloaded exploration code.
  2. Select File–>New–>Analysis. Adjust the timeframe to Daily.
  3. In the “Apply to” section, pick ‘All symbols’ or specify your stock list. Choose ‘1 recent day(s)’ in the range for current day analysis. Finally, select the AFL code in the “Formula” area.

CPR-AFL-CodeNote – This exploration requires EOD data in Amibroker.

Further Reading: CPR Spreadsheet with Narrow Range Indicator

Breaking Down the CPR Code

Let’s examine the exploration code closely:

  • This code is designed for exploration, meaning it does not overlay on charts.
  • Three vital variables in the AFL code – PrevLow, PrevHigh, and PrevClose – capture the Low, High, and Close prices from the previous trading day.
    CPR-AFL-Code
  • Adjust the PrevDay variable to 0 if your database includes data up to the previous trading day. For real-time databases updated to the current day, set PrevDay to 1.
  • The formulas earlier described are used to calculate the Pivot, BC, and TC levels.
    CPR-AFL-Code
  • To determine narrow range CPR, the code compares the absolute difference between TC and BC with the previous close. If the percentage difference falls below the NRThreshold (default set at 0.2%), the criteria for a narrow range is met.
    CPR-AFL-Code
  • Support and resistance levels are derived from standard formulas.
    CPR-AFL-Code
  • All calculated variables appear in the exploration via AddColumn() or AddTextColumn() functions.
    CPR-AFL-Code
  • For ease of interpretation, the values are color-coded, and a “C>10” filter excludes penny stocks from the analysis.

One Comment

Leave a Reply