Central Pivot Range (CPR) Indicator for ThinkorSwim

BenTen

Administrative
Staff member
Staff
VIP
Lifetime
My first attempt to code something. It's Mark Fischer concept of Pivot Range from his book Logical Trader. The strategy for using it is actually from Frank Ochoa's book Secrets of a Pivot Boss. Pivot Range is the "meat of the market" and "the heart beat of the market" according to him.

Here are some interesting details I found about the Pivot Range:
The Pivot Range is a confluence area that identifies where the market is likely to find support or encounter resistance based on the prior day’s trading. The Pivot Range identifies the areas where buyers are likely to show up (which is support) and where sellers are likely to show up (which is resistance). The Pivot Range will also help you to see an area where a significant move could occur if price can break through that area.

The key point to note is that the Pivot Range should give support at this price zone enabling you to take a long position with a defined low risk stop. If price is able to break below the Pivot Range then support would be broken and you would want to exit your trade.

A close above the range is bullish and a close below is bearish • A pivot range above the market is resistance and below the market is support • If the market moves through the pivot range you could expect a significant move in that direction. Trade Against The Pivot—You can use the pivot range to establish a position. The pivot range will act as support/resistance. If a stock opens above the pivot range and sells off to the range you can establish a long at the top of the pivot range. If a stock opens below the pivot range you can establish a short at the bottom of the pivot range. Your stop would be on the other side of the pivot range.

Screen-Shot-2019-12-16-at-11-08-59-AM.png


thinkScript Code

Code:
# Logical Trader's Pivot Range
# Assembled by BenTen at useThinkScript.com
# Converted from https://www.tradingview.com/script/aaiSbWNj-Pivot-Range-Pivot-Boss/

input aggregationPeriod = AggregationPeriod.DAY;

def PH = high(period = aggregationPeriod);
def PL = low(period = aggregationPeriod);
def PC = close(period = aggregationPeriod);

def pivot = (PH + PL + PC) / 3.0;
def bc = (PH + PL) / 2.0;
def tc = (pivot - bc) + pivot;

plot l1 = pivot[1];
plot l2 = bc[1];
plot l3 = tc[1];

l1.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
l1.SetDefaultColor(Color.white);
l1.SetLineWeight(1);
l2.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
l2.SetDefaultColor(Color.CYAN);
l2.SetLineWeight(1);
l3.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
l3.SetDefaultColor(Color.MAGENTA);
l3.SetLineWeight(1);

You can read more about the Pivot Range using the links below:
 
Thank you @BenTen I'm getting the correct result for the 1D setting; however, the 3D setting is not plotting correctly--it's presenting much larger/wider (.25 or 41.97 - 40.72) than the data we're getting (.10 or 41.10 - 41.00).

The previous 3 days' (AMD) data: PH = 42.95; PL = 39.04; and PC = 41.15
For the 3D setting my chart is showing 3days (the Script didn't present 3D when the chart is only 1D--logical, right?), the chart is NOT showing

Extended-Hours and it is set to start aggregation at OPEN. Suggestions/Thoughts? I use both the 1D and the 3D during the day. Without knowing Script would this be correct according to the formula where abs = absolute value?

Code:
def pivot1 = (PH + PL + PC) / 3.0;
def pivot2 = (PH + PL) / 2.0;
def pivotT = pivot1 + (abs(pivot2-pivot1))
def pivotB = pivot1 - (abs(pivot2-pivot1))
 
@BuzzKill Here is the formula from the original script:

Code:
def pivot = (PH + PL + PC) / 3.0;
def bc = (PH + PL) / 2.0;
def tc = (pivot - bc) + pivot;
 
Can anyone convert the Pinescript of TradingView to TOS below. Thanks.

Here is the actual 3 day rolling pivot range indicator as detailed in Mark Fisher's book The Logical Trader.

Code:
study(title="Rolling Pivot Indicator", shorttitle="RPR", overlay = true)
width = input(3, minval=1)
xHigh  = security(tickerid,"D", high[1])
xHigh2  = security(tickerid,"D", high[2])
xHigh3  = security(tickerid,"D", high[3])
xLow   = security(tickerid,"D", low[1])
xLow2   = security(tickerid,"D", low[2])
xLow3   = security(tickerid,"D", low[3])
xClose = security(tickerid,"D", close[1])

mh = if xHigh >= xHigh2 and xHigh>=xHigh3
    xHigh
else
    if xHigh2 >= xHigh and xHigh2>=xHigh3
        xHigh2
    else
        xHigh3
 
ml = if xLow <= xLow2 and xLow<=xLow3
    xLow
else
    if xLow2 <= xLow and xLow2<=xLow3
        xLow2
    else
        xLow3


cpp1 = (xClose + mh +ml)/3
cpp2 = (mh + ml)/2
diff = cpp1 -cpp2

PH = (cpp1 + diff)
PL = (cpp1 - diff)

plot(PH, color=yellow, title="PH", style = line, linewidth = width)
plot(PL, color=black, title="PL", style = line, linewidth = width)

positive = low>PL ? green : na
negative = high<PL ? red : na
bgcolor(positive, transp=75, offset=0)
bgcolor(negative, transp=75, offset=0)

//pos = low<PH and low>=PL ? olive : na
//neg = high<PL and high>=PH ? maroon : na
//bgcolor(pos, transp=75, offset=0)
//bgcolor(neg, transp=75, offset=0)
 
Last edited by a moderator:
@Danthaman Here you go:

Code:
# True Rolling Pivot Range Indicator
# Assembled by BenTen at useThinkScript.com
# Converted from https://www.tradingview.com/script/AAzaP2Rn-True-Rolling-Pivot-Range-Indicator/

input aggregationPeriod = AggregationPeriod.DAY;
def d_high = high(period = aggregationPeriod);
def d_low = low(period = aggregationPeriod);
def d_close = close(period = aggregationPeriod);

def xHigh = d_high[1];
def xHigh2 = d_high[2];
def xHigh3 = d_high[3];
def xLow = d_low[1];
def xLow2 = d_low[2];
def xLow3 = d_low[3];
def xClose = d_close[1];

def mh = if xHigh >= xHigh2 and xHigh>=xHigh3 then

    xHigh
else
    if xHigh2 >= xHigh and xHigh2>=xHigh3 then

        xHigh2
    else
        xHigh3;

def ml = if xLow <= xLow2 and xLow<=xLow3 then

    xLow
else
    if xLow2 <= xLow and xLow2<=xLow3 then

        xLow2
    else
        xLow3;


def cpp1 = (xClose + mh + ml) / 3;
def cpp2 = (mh + ml) / 2;
def diff = cpp1 - cpp2;

def PH = (cpp1 + diff);
def PL = (cpp1 - diff);

plot line_h = PH;
plot line_l = PL;

line_h.SetDefaultColor(GetColor(1));
line_l.SetDefaultColor(GetColor(0));
 
Last edited:
Hi All, I use pivot points in the definition of pivot boss as my support and resistance levels. Central Pivot Range is the core of this script. I just wanted to share this layman code. Feel free to tweak or improvize it to your likings if you find this useful. Plots
1. Daily S/R (White levels) - Daily High/ Lows (White dotted levels).
2. Weekly S/R (Green levels) - Weekly High/ Lows (Green dotted levels).
3. Monthly S/R (Red levels) - Monthly High/ Lows (Red dotted levels).

Need to enable atleast 30 days of chart to be able to view both weekly and monthly levels.

Code:
#CPR thinkscript by earthian. Draws pivot points or support/resistance price levels with a central pivot zone based on formulae used by pivot boss for seven different time periods.
# White lines are daily levels
# Red lines are weekly levels
# Green lines are monthly levels
# Dotted lines are high or low of the selected aggregationPeriod
# pink zone and dotted lines represents the central pivot range and pivot point

input firstaggregationPeriod = AggregationPeriod.DAY;
input firstaggregationvalue = 1;

def firstPH = high(period = firstaggregationPeriod)[firstaggregationvalue];
def firstPL = low(period = firstaggregationPeriod)[firstaggregationvalue];
def firstPC = close(period = firstaggregationPeriod)[firstaggregationvalue];


plot firstR5;
plot firstR4;
plot firstR3;
plot firstR2;
plot firstR1;
plot firstHH;
plot firstPP;
plot firstLPP;
plot firstUPP;
plot firstLL;
plot firstS1;
plot firstS2;
plot firstS3;
plot firstS4;
plot firstS5;

firstHH = firstPH;
firstLL = firstPL;
firstPP = (firstPH + firstPL + firstPC) / 3;
firstLPP = (firstPH + firstPL) / 2;
firstUPP = (firstPP - firstLPP) + firstPP;
firstR1 = 2 * firstPP - firstPL;
firstR2 = firstPP + (firstPH - firstPL);
firstR3 = 2 * firstPP + (firstPH - 2 * firstPL);
firstR4 = 3 * firstPP + (firstPH - 3 * firstPL);
firstR5 = 4 * firstPP + (firstPH - 4 * firstPL);
firstS1 = 2 * firstPP - firstPH;
firstS2 = firstPP - (firstPH - firstPL);
firstS3 = 2 * firstPP - (2 * firstPH - firstPL);
firstS4 = 3 * firstPP - (3 * firstPH - firstPL);
firstS5 = 4 * firstPP - (4 * firstPH - firstPL);

firstR5.SetDefaultColor(GetColor(6));
firstR4.SetDefaultColor(GetColor(9));
firstR3.SetDefaultColor(GetColor(9));
firstR2.SetDefaultColor(GetColor(9));
firstR1.SetDefaultColor(GetColor(9));
firstHH.SetDefaultColor(GetColor(9));
firstLL.SetDefaultColor(GetColor(9));
firstPP.SetDefaultColor(GetColor(0));
firstLPP.SetDefaultColor(GetColor(0));
firstUPP.SetDefaultColor(GetColor(0));
firstS1.SetDefaultColor(GetColor(9));
firstS2.SetDefaultColor(GetColor(9));
firstS3.SetDefaultColor(GetColor(9));
firstS4.SetDefaultColor(GetColor(9));
firstS5.SetDefaultColor(GetColor(9));

AddCloud(firstUPP, firstLPP, Color.PINK, Color.PINK);

firstR5.SetPaintingStrategy(PaintingStrategy.LINE);
firstR4.SetPaintingStrategy(PaintingStrategy.LINE);
firstR3.SetPaintingStrategy(PaintingStrategy.LINE);
firstR2.SetPaintingStrategy(PaintingStrategy.LINE);
firstR1.SetPaintingStrategy(PaintingStrategy.LINE);
firstHH.SetPaintingStrategy(PaintingStrategy.POINTS);
firstPP.SetPaintingStrategy(PaintingStrategy.POINTS);
firstLL.SetPaintingStrategy(PaintingStrategy.POINTS);
firstS1.SetPaintingStrategy(PaintingStrategy.LINE);
firstS2.SetPaintingStrategy(PaintingStrategy.LINE);
firstS3.SetPaintingStrategy(PaintingStrategy.LINE);
firstS4.SetPaintingStrategy(PaintingStrategy.LINE);
firstS5.SetPaintingStrategy(PaintingStrategy.LINE);

firstPP.SetDefaultColor(color.magenta);
firstPP.SetStyle(Curve.POINTS);
firstLPP.Hide();
firstUPP.Hide();

#second period

input secondaggregationPeriod = AggregationPeriod.DAY;
input secondaggregationvalue = 1;

def secondPH = high(period = secondaggregationPeriod)[secondaggregationvalue];
def secondPL = low(period = secondaggregationPeriod)[secondaggregationvalue];
def secondPC = close(period = secondaggregationPeriod)[secondaggregationvalue];

plot secondR5;
plot secondR4;
plot secondR3;
plot secondR2;
plot secondR1;
plot secondHH;
plot secondPP;
plot secondLPP;
plot secondUPP;
plot secondLL;
plot secondS1;
plot secondS2;
plot secondS3;
plot secondS4;
plot secondS5;

secondHH = secondPH;
secondLL = secondPL;
secondPP = (secondPH + secondPL + secondPC) / 3;
secondLPP = (secondPH + secondPL) / 2;
secondUPP = (secondPP - secondLPP) + secondPP;
secondR1 = 2 * secondPP - secondPL;
secondR2 = secondPP + (secondPH - secondPL);
secondR3 = 2 * secondPP + (secondPH - 2 * secondPL);
secondR4 = 3 * secondPP + (secondPH - 3 * secondPL);
secondR5 = 4 * secondPP + (secondPH - 4 * secondPL);
secondS1 = 2 * secondPP - secondPH;
secondS2 = secondPP - (secondPH - secondPL);
secondS3 = 2 * secondPP - (2 * secondPH - secondPL);
secondS4 = 3 * secondPP - (3 * secondPH - secondPL);
secondS5 = 4 * secondPP - (4 * secondPH - secondPL);

secondR5.SetDefaultColor(GetColor(9));
secondR4.SetDefaultColor(GetColor(9));
secondR3.SetDefaultColor(GetColor(9));
secondR2.SetDefaultColor(GetColor(9));
secondR1.SetDefaultColor(GetColor(9));
secondHH.SetDefaultColor(GetColor(9));
secondLL.SetDefaultColor(GetColor(9));
secondPP.SetDefaultColor(GetColor(0));
secondLPP.SetDefaultColor(GetColor(0));
secondUPP.SetDefaultColor(GetColor(0));
secondS1.SetDefaultColor(GetColor(9));
secondS2.SetDefaultColor(GetColor(9));
secondS3.SetDefaultColor(GetColor(9));
secondS4.SetDefaultColor(GetColor(9));
secondS5.SetDefaultColor(GetColor(9));

secondR5.SetPaintingStrategy(PaintingStrategy.DASHES);
secondR4.SetPaintingStrategy(PaintingStrategy.DASHES);
secondR3.SetPaintingStrategy(PaintingStrategy.DASHES);
secondR2.SetPaintingStrategy(PaintingStrategy.DASHES);
secondR1.SetPaintingStrategy(PaintingStrategy.DASHES);
secondHH.SetPaintingStrategy(PaintingStrategy.POINTS);
secondPP.SetPaintingStrategy(PaintingStrategy.POINTS);
secondLL.SetPaintingStrategy(PaintingStrategy.POINTS);
secondS1.SetPaintingStrategy(PaintingStrategy.DASHES);
secondS2.SetPaintingStrategy(PaintingStrategy.DASHES);
secondS3.SetPaintingStrategy(PaintingStrategy.DASHES);
secondS4.SetPaintingStrategy(PaintingStrategy.DASHES);
secondS5.SetPaintingStrategy(PaintingStrategy.DASHES);

secondR5.SetStyle(Curve.LONG_DASH);
secondR4.SetStyle(Curve.LONG_DASH);
secondR3.SetStyle(Curve.LONG_DASH);
secondR2.SetStyle(Curve.LONG_DASH);
secondR1.SetStyle(Curve.LONG_DASH);
secondHH.SetStyle(Curve.LONG_DASH);
secondLL.SetStyle(Curve.LONG_DASH);
secondS1.SetStyle(Curve.LONG_DASH);
secondS2.SetStyle(Curve.LONG_DASH);
secondS3.SetStyle(Curve.LONG_DASH);
secondS4.SetStyle(Curve.LONG_DASH);
secondS5.SetStyle(Curve.LONG_DASH);

secondPP.Hide();
secondLPP.Hide();
secondUPP.Hide();

#third period

input thirdaggregationPeriod = AggregationPeriod.DAY;
input thirdaggregationvalue = 1;

def thirdPH = high(period = thirdaggregationPeriod)[thirdaggregationvalue];
def thirdPL = low(period = thirdaggregationPeriod)[thirdaggregationvalue];
def thirdPC = close(period = thirdaggregationPeriod)[thirdaggregationvalue];

plot thirdR5;
plot thirdR4;
plot thirdR3;
plot thirdR2;
plot thirdR1;
plot thirdHH;
plot thirdPP;
plot thirdLPP;
plot thirdUPP;
plot thirdLL;
plot thirdS1;
plot thirdS2;
plot thirdS3;
plot thirdS4;
plot thirdS5;

thirdHH = thirdPH;
thirdLL = thirdPL;
thirdPP = (thirdPH + thirdPL + thirdPC) / 3;
thirdLPP = (thirdPH + thirdPL) / 2;
thirdUPP = (thirdPP - thirdLPP) + thirdPP;
thirdR1 = 2 * thirdPP - thirdPL;
thirdR2 = thirdPP + (thirdPH - thirdPL);
thirdR3 = 2 * thirdPP + (thirdPH - 2 * thirdPL);
thirdR4 = 3 * thirdPP + (thirdPH - 3 * thirdPL);
thirdR5 = 4 * thirdPP + (thirdPH - 4 * thirdPL);
thirdS1 = 2 * thirdPP - thirdPH;
thirdS2 = thirdPP - (thirdPH - thirdPL);
thirdS3 = 2 * thirdPP - (2 * thirdPH - thirdPL);
thirdS4 = 3 * thirdPP - (3 * thirdPH - thirdPL);
thirdS5 = 4 * thirdPP - (4 * thirdPH - thirdPL);

thirdR5.SetDefaultColor(GetColor(9));
thirdR4.SetDefaultColor(GetColor(9));
thirdR3.SetDefaultColor(GetColor(9));
thirdR2.SetDefaultColor(GetColor(9));
thirdR1.SetDefaultColor(GetColor(9));
thirdHH.SetDefaultColor(GetColor(9));
thirdLL.SetDefaultColor(GetColor(9));
thirdPP.SetDefaultColor(GetColor(0));
thirdLPP.SetDefaultColor(GetColor(0));
thirdUPP.SetDefaultColor(GetColor(0));
thirdS1.SetDefaultColor(GetColor(9));
thirdS2.SetDefaultColor(GetColor(9));
thirdS3.SetDefaultColor(GetColor(9));
thirdS4.SetDefaultColor(GetColor(9));
thirdS5.SetDefaultColor(GetColor(9));

thirdR5.SetPaintingStrategy(PaintingStrategy.DASHES);
thirdR4.SetPaintingStrategy(PaintingStrategy.DASHES);
thirdR3.SetPaintingStrategy(PaintingStrategy.DASHES);
thirdR2.SetPaintingStrategy(PaintingStrategy.DASHES);
thirdR1.SetPaintingStrategy(PaintingStrategy.DASHES);
thirdHH.SetPaintingStrategy(PaintingStrategy.POINTS);
thirdPP.SetPaintingStrategy(PaintingStrategy.POINTS);
thirdLL.SetPaintingStrategy(PaintingStrategy.POINTS);
thirdS1.SetPaintingStrategy(PaintingStrategy.DASHES);
thirdS2.SetPaintingStrategy(PaintingStrategy.DASHES);
thirdS3.SetPaintingStrategy(PaintingStrategy.DASHES);
thirdS4.SetPaintingStrategy(PaintingStrategy.DASHES);
thirdS5.SetPaintingStrategy(PaintingStrategy.DASHES);

thirdR5.SetStyle(Curve.LONG_DASH);
thirdR4.SetStyle(Curve.LONG_DASH);
thirdR3.SetStyle(Curve.LONG_DASH);
thirdR2.SetStyle(Curve.LONG_DASH);
thirdR1.SetStyle(Curve.LONG_DASH);
thirdHH.SetStyle(Curve.LONG_DASH);
thirdLL.SetStyle(Curve.LONG_DASH);
thirdS1.SetStyle(Curve.LONG_DASH);
thirdS2.SetStyle(Curve.LONG_DASH);
thirdS3.SetStyle(Curve.LONG_DASH);
thirdS4.SetStyle(Curve.LONG_DASH);
thirdS5.SetStyle(Curve.LONG_DASH);

thirdPP.Hide();
thirdLPP.Hide();
thirdUPP.Hide();

#fourth day
input fourthaggregationPeriod = AggregationPeriod.DAY;
input fourthaggregationvalue = 1;

def fourthPH = high(period = fourthaggregationPeriod)[fourthaggregationvalue];
def fourthPL = low(period = fourthaggregationPeriod)[fourthaggregationvalue];
def fourthPC = close(period = fourthaggregationPeriod)[fourthaggregationvalue];

plot fourthR5;
plot fourthR4;
plot fourthR3;
plot fourthR2;
plot fourthR1;
plot fourthHH;
plot fourthPP;
plot fourthLPP;
plot fourthUPP;
plot fourthLL;
plot fourthS1;
plot fourthS2;
plot fourthS3;
plot fourthS4;
plot fourthS5;

fourthHH = fourthPH;
fourthLL = fourthPL;
fourthPP = (fourthPH + fourthPL + fourthPC) / 3;
fourthLPP = (fourthPH + fourthPL) / 2;
fourthUPP = (fourthPP - fourthLPP) + fourthPP;
fourthR1 = 2 * fourthPP - fourthPL;
fourthR2 = fourthPP + (fourthPH - fourthPL);
fourthR3 = 2 * fourthPP + (fourthPH - 2 * fourthPL);
fourthR4 = 3 * fourthPP + (fourthPH - 3 * fourthPL);
fourthR5 = 4 * fourthPP + (fourthPH - 4 * fourthPL);
fourthS1 = 2 * fourthPP - fourthPH;
fourthS2 = fourthPP - (fourthPH - fourthPL);
fourthS3 = 2 * fourthPP - (2 * fourthPH - fourthPL);
fourthS4 = 3 * fourthPP - (3 * fourthPH - fourthPL);
fourthS5 = 4 * fourthPP - (4 * fourthPH - fourthPL);

fourthR5.SetDefaultColor(GetColor(9));
fourthR4.SetDefaultColor(GetColor(9));
fourthR3.SetDefaultColor(GetColor(9));
fourthR2.SetDefaultColor(GetColor(9));
fourthR1.SetDefaultColor(GetColor(9));
fourthHH.SetDefaultColor(GetColor(9));
fourthLL.SetDefaultColor(GetColor(9));
fourthPP.SetDefaultColor(GetColor(0));
fourthLPP.SetDefaultColor(GetColor(0));
fourthUPP.SetDefaultColor(GetColor(0));
fourthS1.SetDefaultColor(GetColor(9));
fourthS2.SetDefaultColor(GetColor(9));
fourthS3.SetDefaultColor(GetColor(9));
fourthS4.SetDefaultColor(GetColor(9));
fourthS5.SetDefaultColor(GetColor(9));

fourthR5.SetPaintingStrategy(PaintingStrategy.DASHES);
fourthR4.SetPaintingStrategy(PaintingStrategy.DASHES);
fourthR3.SetPaintingStrategy(PaintingStrategy.DASHES);
fourthR2.SetPaintingStrategy(PaintingStrategy.DASHES);
fourthR1.SetPaintingStrategy(PaintingStrategy.DASHES);
fourthHH.SetPaintingStrategy(PaintingStrategy.POINTS);
fourthPP.SetPaintingStrategy(PaintingStrategy.POINTS);
fourthLL.SetPaintingStrategy(PaintingStrategy.POINTS);
fourthS1.SetPaintingStrategy(PaintingStrategy.DASHES);
fourthS2.SetPaintingStrategy(PaintingStrategy.DASHES);
fourthS3.SetPaintingStrategy(PaintingStrategy.DASHES);
fourthS4.SetPaintingStrategy(PaintingStrategy.DASHES);
fourthS5.SetPaintingStrategy(PaintingStrategy.DASHES);

fourthR5.SetStyle(Curve.LONG_DASH);
fourthR4.SetStyle(Curve.LONG_DASH);
fourthR3.SetStyle(Curve.LONG_DASH);
fourthR2.SetStyle(Curve.LONG_DASH);
fourthR1.SetStyle(Curve.LONG_DASH);
fourthHH.SetStyle(Curve.LONG_DASH);
fourthLL.SetStyle(Curve.LONG_DASH);
fourthS1.SetStyle(Curve.LONG_DASH);
fourthS2.SetStyle(Curve.LONG_DASH);
fourthS3.SetStyle(Curve.LONG_DASH);
fourthS4.SetStyle(Curve.LONG_DASH);
fourthS5.SetStyle(Curve.LONG_DASH);

fourthPP.Hide();
fourthLPP.Hide();
fourthUPP.Hide();

#fifth day
input fifthaggregationPeriod = AggregationPeriod.DAY;
input fifthaggregationvalue = 1;

def fifthPH = high(period = fifthaggregationPeriod)[fifthaggregationvalue];
def fifthPL = low(period = fifthaggregationPeriod)[fifthaggregationvalue];
def fifthPC = close(period = fifthaggregationPeriod)[fifthaggregationvalue];

plot fifthR5;
plot fifthR4;
plot fifthR3;
plot fifthR2;
plot fifthR1;
plot fifthHH;
plot fifthPP;
plot fifthLPP;
plot fifthUPP;
plot fifthLL;
plot fifthS1;
plot fifthS2;
plot fifthS3;
plot fifthS4;
plot fifthS5;

fifthHH = fifthPH;
fifthLL = fifthPL;
fifthPP = (fifthPH + fifthPL + fifthPC) / 3;
fifthLPP = (fifthPH + fifthPL) / 2;
fifthUPP = (fifthPP - fifthLPP) + fifthPP;
fifthR1 = 2 * fifthPP - fifthPL;
fifthR2 = fifthPP + (fifthPH - fifthPL);
fifthR3 = 2 * fifthPP + (fifthPH - 2 * fifthPL);
fifthR4 = 3 * fifthPP + (fifthPH - 3 * fifthPL);
fifthR5 = 4 * fifthPP + (fifthPH - 4 * fifthPL);
fifthS1 = 2 * fifthPP - fifthPH;
fifthS2 = fifthPP - (fifthPH - fifthPL);
fifthS3 = 2 * fifthPP - (2 * fifthPH - fifthPL);
fifthS4 = 3 * fifthPP - (3 * fifthPH - fifthPL);
fifthS5 = 4 * fifthPP - (4 * fifthPH - fifthPL);

fifthR5.SetDefaultColor(GetColor(9));
fifthR4.SetDefaultColor(GetColor(9));
fifthR3.SetDefaultColor(GetColor(9));
fifthR2.SetDefaultColor(GetColor(9));
fifthR1.SetDefaultColor(GetColor(9));
fifthHH.SetDefaultColor(GetColor(9));
fifthLL.SetDefaultColor(GetColor(9));
fifthPP.SetDefaultColor(GetColor(0));
fifthLPP.SetDefaultColor(GetColor(0));
fifthUPP.SetDefaultColor(GetColor(0));
fifthS1.SetDefaultColor(GetColor(9));
fifthS2.SetDefaultColor(GetColor(9));
fifthS3.SetDefaultColor(GetColor(9));
fifthS4.SetDefaultColor(GetColor(9));
fifthS5.SetDefaultColor(GetColor(9));

fifthR5.SetPaintingStrategy(PaintingStrategy.DASHES);
fifthR4.SetPaintingStrategy(PaintingStrategy.DASHES);
fifthR3.SetPaintingStrategy(PaintingStrategy.DASHES);
fifthR2.SetPaintingStrategy(PaintingStrategy.DASHES);
fifthR1.SetPaintingStrategy(PaintingStrategy.DASHES);
fifthHH.SetPaintingStrategy(PaintingStrategy.POINTS);
fifthPP.SetPaintingStrategy(PaintingStrategy.POINTS);
fifthLL.SetPaintingStrategy(PaintingStrategy.POINTS);
fifthS1.SetPaintingStrategy(PaintingStrategy.DASHES);
fifthS2.SetPaintingStrategy(PaintingStrategy.DASHES);
fifthS3.SetPaintingStrategy(PaintingStrategy.DASHES);
fifthS4.SetPaintingStrategy(PaintingStrategy.DASHES);
fifthS5.SetPaintingStrategy(PaintingStrategy.DASHES);

fifthR5.SetStyle(Curve.LONG_DASH);
fifthR4.SetStyle(Curve.LONG_DASH);
fifthR3.SetStyle(Curve.LONG_DASH);
fifthR2.SetStyle(Curve.LONG_DASH);
fifthR1.SetStyle(Curve.LONG_DASH);
fifthHH.SetStyle(Curve.LONG_DASH);
fifthLL.SetStyle(Curve.LONG_DASH);
fifthS1.SetStyle(Curve.LONG_DASH);
fifthS2.SetStyle(Curve.LONG_DASH);
fifthS3.SetStyle(Curve.LONG_DASH);
fifthS4.SetStyle(Curve.LONG_DASH);
fifthS5.SetStyle(Curve.LONG_DASH);

fifthPP.Hide();
fifthLPP.Hide();
fifthUPP.Hide();

#sixth day
input sixthaggregationPeriod = AggregationPeriod.WEEK;
input sixthaggregationvalue = 1;

def sixthPH = high(period = sixthaggregationPeriod)[sixthaggregationvalue];
def sixthPL = low(period = sixthaggregationPeriod)[sixthaggregationvalue];
def sixthPC = close(period = sixthaggregationPeriod)[sixthaggregationvalue];

plot sixthR5;
plot sixthR4;
plot sixthR3;
plot sixthR2;
plot sixthR1;
plot sixthHH;
plot sixthPP;
plot sixthLPP;
plot sixthUPP;
plot sixthLL;
plot sixthS1;
plot sixthS2;
plot sixthS3;
plot sixthS4;
plot sixthS5;

sixthHH = sixthPH;
sixthLL = sixthPL;
sixthPP = (sixthPH + sixthPL + sixthPC) / 3;
sixthLPP = (sixthPH + sixthPL) / 2;
sixthUPP = (sixthPP - sixthLPP) + sixthPP;
sixthR1 = 2 * sixthPP - sixthPL;
sixthR2 = sixthPP + (sixthPH - sixthPL);
sixthR3 = 2 * sixthPP + (sixthPH - 2 * sixthPL);
sixthR4 = 3 * sixthPP + (sixthPH - 3 * sixthPL);
sixthR5 = 4 * sixthPP + (sixthPH - 4 * sixthPL);
sixthS1 = 2 * sixthPP - sixthPH;
sixthS2 = sixthPP - (sixthPH - sixthPL);
sixthS3 = 2 * sixthPP - (2 * sixthPH - sixthPL);
sixthS4 = 3 * sixthPP - (3 * sixthPH - sixthPL);
sixthS5 = 4 * sixthPP - (4 * sixthPH - sixthPL);

sixthR5.SetDefaultColor(color.green);
sixthR4.SetDefaultColor(color.green);
sixthR3.SetDefaultColor(color.green);
sixthR2.SetDefaultColor(color.green);
sixthR1.SetDefaultColor(color.green);
sixthHH.SetDefaultColor(color.green);
sixthLL.SetDefaultColor(color.green);
sixthPP.SetDefaultColor(GetColor(0));
sixthLPP.SetDefaultColor(GetColor(0));
sixthUPP.SetDefaultColor(GetColor(0));
sixthS1.SetDefaultColor(color.green);
sixthS2.SetDefaultColor(color.green);
sixthS3.SetDefaultColor(color.green);
sixthS4.SetDefaultColor(color.green);
sixthS5.SetDefaultColor(color.green);

sixthR5.SetPaintingStrategy(PaintingStrategy. LINE);
sixthR4.SetPaintingStrategy(PaintingStrategy. LINE);
sixthR3.SetPaintingStrategy(PaintingStrategy. LINE);
sixthR2.SetPaintingStrategy(PaintingStrategy. LINE);
sixthR1.SetPaintingStrategy(PaintingStrategy. LINE);
sixthHH.SetPaintingStrategy(PaintingStrategy.POINTS);
sixthPP.SetPaintingStrategy(PaintingStrategy.POINTS);
sixthLL.SetPaintingStrategy(PaintingStrategy.POINTS);
sixthS1.SetPaintingStrategy(PaintingStrategy. LINE);
sixthS2.SetPaintingStrategy(PaintingStrategy. LINE);
sixthS3.SetPaintingStrategy(PaintingStrategy. LINE);
sixthS4.SetPaintingStrategy(PaintingStrategy. LINE);
sixthS5.SetPaintingStrategy(PaintingStrategy. LINE);


sixthPP.Hide();
sixthLPP.Hide();
sixthUPP.Hide();

#seventh day
input seventhaggregationPeriod = AggregationPeriod.MONTH;
input seventhaggregationvalue = 1;

def seventhPH = high(period = seventhaggregationPeriod)[seventhaggregationvalue];
def seventhPL = low(period = seventhaggregationPeriod)[seventhaggregationvalue];
def seventhPC = close(period = seventhaggregationPeriod)[seventhaggregationvalue];

plot seventhR5;
plot seventhR4;
plot seventhR3;
plot seventhR2;
plot seventhR1;
plot seventhHH;
plot seventhPP;
plot seventhLPP;
plot seventhUPP;
plot seventhLL;
plot seventhS1;
plot seventhS2;
plot seventhS3;
plot seventhS4;
plot seventhS5;

seventhHH = seventhPH;
seventhLL = seventhPL;
seventhPP = (seventhPH + seventhPL + seventhPC) / 3;
seventhLPP = (seventhPH + seventhPL) / 2;
seventhUPP = (seventhPP - seventhLPP) + seventhPP;
seventhR1 = 2 * seventhPP - seventhPL;
seventhR2 = seventhPP + (seventhPH - seventhPL);
seventhR3 = 2 * seventhPP + (seventhPH - 2 * seventhPL);
seventhR4 = 3 * seventhPP + (seventhPH - 3 * seventhPL);
seventhR5 = 4 * seventhPP + (seventhPH - 4 * seventhPL);
seventhS1 = 2 * seventhPP - seventhPH;
seventhS2 = seventhPP - (seventhPH - seventhPL);
seventhS3 = 2 * seventhPP - (2 * seventhPH - seventhPL);
seventhS4 = 3 * seventhPP - (3 * seventhPH - seventhPL);
seventhS5 = 4 * seventhPP - (4 * seventhPH - seventhPL);

seventhR5.SetDefaultColor(color.red);
seventhR4.SetDefaultColor(color.red);
seventhR3.SetDefaultColor(color.red);
seventhR2.SetDefaultColor(color.red);
seventhR1.SetDefaultColor(color.red);
seventhHH.SetDefaultColor(color.red);
seventhLL.SetDefaultColor(color.red);
seventhPP.SetDefaultColor(GetColor(0));
seventhLPP.SetDefaultColor(GetColor(0));
seventhUPP.SetDefaultColor(GetColor(0));
seventhS1.SetDefaultColor(color.red);
seventhS2.SetDefaultColor(color.red);
seventhS3.SetDefaultColor(color.red);
seventhS4.SetDefaultColor(color.red);
seventhS5.SetDefaultColor(color.red);

seventhR5.SetPaintingStrategy(PaintingStrategy. LINE);
seventhR4.SetPaintingStrategy(PaintingStrategy. LINE);
seventhR3.SetPaintingStrategy(PaintingStrategy. LINE);
seventhR2.SetPaintingStrategy(PaintingStrategy. LINE);
seventhR1.SetPaintingStrategy(PaintingStrategy. LINE);
seventhHH.SetPaintingStrategy(PaintingStrategy.POINTS);
seventhPP.SetPaintingStrategy(PaintingStrategy.POINTS);
seventhLL.SetPaintingStrategy(PaintingStrategy.POINTS);
seventhS1.SetPaintingStrategy(PaintingStrategy. LINE);
seventhS2.SetPaintingStrategy(PaintingStrategy. LINE);
seventhS3.SetPaintingStrategy(PaintingStrategy. LINE);
seventhS4.SetPaintingStrategy(PaintingStrategy. LINE);
seventhS5.SetPaintingStrategy(PaintingStrategy. LINE);

seventhPP.Hide();
seventhLPP.Hide();
seventhUPP.Hide();


NNT2wTu.png
 
Last edited:
I love the CPR and this was basically what I was looking for after using charts from TV. TY @BenTen Question, so I see that you have script that plot the daily pervious highs and pervious daily lows pivots, but is there a script that plots the just weekly highs and low pivots?
 
Hello Ben,

Thanks for the CPR study , can you please help me in creating a scan to find stocks in narrow CPR range.
Narrow CPR Formula is cpr = ( tc-bc ) < (close*0.001) . We should identify stocks which meets that condition.

Unfortunately I don't have coding experience.

thanks a lot,
Kitcha
 
Last edited by a moderator:
Hello Ben,

Thanks for the CPR study , can you please help me in creating a scan to find stocks in narrow CPR range.
Narrow CPR Formula is cpr = ( tc-bc ) < (close*0.001) . We should identify stocks which meets that condition.

Unfortunately I don't have coding experience.

thanks a lot,
Kitcha

@Kitchasap Thinkscript isn't really a programming language. It is plain English scripting. Given that you have an excellent grasp of the logic, you could be an expert contributor in no time. See the below code? 95% is your logic w/ 5% syntax.
Code:
plot cpr = ( tc-bc ) < (close*0.0001);
####################
#when adding a scan plot to a study the following line is necessary so the scan doesn't plot on your chart:
cpr.hide();
Add the above code snippet to the bottom of your study.
Scan would be set to: cpr is true

Measuring pivot width gives you a significant edge in determining the potential behavior for the upcoming session, but like any form of technical analysis this method is not always correct and should be used as a guideline not an entry point.
 
Last edited:
BTW, this youtube show how Mark Fisher, the original guys which came up with the Opening range and CPR show how he uses it during 2016 session. In fact, the set up was so good that day he place a real trade directly
Trading Fisher Bars with ACD and Pivot Ranges with Mark Fisher

But although Mark still stand by his method after more than 40 yrs, there's this russia guys which decided to tested out he's method and there's a lot that meet the eyes. This guys is really a good programmer and the testing methodology is also very solid so there's a lot of great gems to be found in those testing result.
 
Last edited by a moderator:
Hi, sorry for the question I am new to this. Can this indicator also be used with a tick chart?
 
Last edited:
I am looking custom Code to Scan for Narrow CPR for Next Day. Let me know if some one can help code this scanner.

Narrow central pivot range indicates the market traded sideways or consolidated in the prior period of time (from which the high, low, and close were derived to calculate the pivots). As such, this price behavior usually leads to breakout or trending behavior in the following session.
 
Last edited by a moderator:

Join useThinkScript to post your question to a community of 21,000+ developers and traders.

Similar threads

Not the exact question you're looking for?

Start a new thread and receive assistance from our community.

87k+ Posts
251 Online
Create Post

Similar threads

Similar threads

The Market Trading Game Changer

Join 2,500+ subscribers inside the useThinkScript VIP Membership Club
  • Exclusive indicators
  • Proven strategies & setups
  • Private Discord community
  • ‘Buy The Dip’ signal alerts
  • Exclusive members-only content
  • Add-ons and resources
  • 1 full year of unlimited support

Frequently Asked Questions

What is useThinkScript?

useThinkScript is the #1 community of stock market investors using indicators and other tools to power their trading strategies. Traders of all skill levels use our forums to learn about scripting and indicators, help each other, and discover new ways to gain an edge in the markets.

How do I get started?

We get it. Our forum can be intimidating, if not overwhelming. With thousands of topics, tens of thousands of posts, our community has created an incredibly deep knowledge base for stock traders. No one can ever exhaust every resource provided on our site.

If you are new, or just looking for guidance, here are some helpful links to get you started.

What are the benefits of VIP Membership?
VIP members get exclusive access to these proven and tested premium indicators: Buy the Dip, Advanced Market Moves 2.0, Take Profit, and Volatility Trading Range. In addition, VIP members get access to over 50 VIP-only custom indicators, add-ons, and strategies, private VIP-only forums, private Discord channel to discuss trades and strategies in real-time, customer support, trade alerts, and much more. Learn all about VIP membership here.
How can I access the premium indicators?
To access the premium indicators, which are plug and play ready, sign up for VIP membership here.
Back
Top