Developing Central Pivot Range (DCPR) For ThinkOrSwim

bigboss

Active member
I've been studying the Central Pivot Range (CPR) quite a bit lately and have seen some interest in the "Developing Central Pivot Range (DCPR)" here on usethinkscript, so I went ahead and coded up an indicator that displays the Developing CPR. I created this indicator a while ago and didn't really know what to make of it, but after studying it quite a bit and zooming out on the chart, I think it's really useful, especially when combined with regular CPR.

Typically, CPR is calculated from yesterday's high, low, and close and projected onto today's chart. DCPR shows how the high, low, and close that develop throughout the day end up creating tomorrow's CPR. It provides a visualization of sentiment shift throughout the day and can be effective in knowing when you're likely looking at a pullback versus a trend change. I think it can be useful for intraday trading, including scalping and day swinging.


First, a few notes on the Central Pivot Range that are applicable to the Developing Central Pivot Range as well.

The Central Pivot Range consists of three lines - the Central Pivot (CP), the Bottom Central (BC), and the Top Central (TC). Mathematically,
  • CP = (high + low + close) / 3 (think of this as the HLC3 price of the daily candle)
  • BC = (high + low) / 2 (think of this as the HL2 price of the daily candle)
  • TC = (CP - BC) + CP (this is the difference between HL2 and HLC3, mirrored across HLC3)
The result is 3 lines, with CP in the center and TC and BC equidistant from CP. Despite their names, Top Central is not always on the top. The way the math works, a candle that closes above the midpoint (BC) for the day will have TC on top and BC on bottom. A candle that closes below the midpoint will have TC on bottom and BC on top. Some influential experts on the CPR always call the top line TC and the bottom line BC - and that's fine, I often do too - but for the remainder of this discussion I will refer to them by their mathematical definitions because it's important when using the DCPR to do so. From here on out when I reference CP, TC and BC I'll be referring to the developing lines in this indicator, not the daily values in the traditional CPR.

This indicator plots CP, TC, and BC as the high, low and close for the session develop throughout the day. You'll notice that two of them - TC and CP - are very responsive to price; this is because the close price of the current bar influences 33% of the calculation. BC only changes when new daily highs or new daily lows are made. I've coded this so that when TC is above BC the lines and cloud are green, and when TC is below BC, the lines and cloud are red.


Another important concept with the CPR is the two day relationship - the traditional CPR acts as excellent support and resistance, and when the traditional CPR is higher than the previous period it is an indicator of bullish sentiment; when it is lower than the previous period it is a bearish indicator. When the CPR engulfs the prior day and is wide, you're in for some sideways movement, and when the CPR is narrow, you likely printed a doji on the daily and you're in for a ride.

I mentioned early on that this indicator is best paired with a traditional CPR indicator. This is because it gives you context into the two day relationship that is forming. If the DCPR is above the traditional CPR, you're setting up a bullish two day relationship for the following trading session. If it is below, a bearish two day relationship.

Thus, the DCPR provides excellent visual context for where you are in a trend.

Consider that if you have a Green DCPR trading above the traditional CPR, you are likely in a bullish trend continuation. A Red DCPR trading above the traditional CPR is likely just a pullback - don't go full-on bear mode yet ;-)


The inverse is true when trading below the traditional CPR - a red DCPR is bearish trend continuation, and a green DCPR is probably just a pullback. Until it isn't, of course.


After having studied this, I can think of a few ways to effectively trade it. For day swings, you could enter on pullbacks - red clouds above the traditional CPR, or green clouds below the traditional CPR. The traditional CPR is excellent support and resistance, and with an appropriately sized trade you could use it as your stop loss.

The BC line is also very tradeable. It is HL2 - the midpoint for the day - the 50% retracement from high to low at any point throughout the session. As you study this indicator, you'll find that price interacts with it often, and offers excellent opportunities for entries.

I'd love to hear if you have any thoughts on the DCPR, if you've found it useful, and if there are other good ways to trade it I haven't thought of yet.

Code:
# Developing CPR (CPR)
# by bigboss
# Version 1.0

input showTcBcLines = yes;
input showCloud = yes;

def o = open;
def h = high;
def l = low;
def c = close;
def na = Double.NaN;

def today = GetYYYYMMDD();

def rollover = today <> today[1];

def dh = if rollover or h > dh[1] then h else dh[1];
def dl = if rollover or l < dl[1] then l else dl[1];

plot dcp = (dh + dl + c) / 3;
plot dbc = (dh + dl) / 2;
plot dtc = (dcp - dbc) + dcp;

dcp.AssignValueColor(if dtc > dbc then Color.GREEN else Color.RED);
dtc.AssignValueColor(if dtc > dbc then Color.LIGHT_GREEN else Color.LIGHT_RED);
dbc.AssignValueColor(if dtc > dbc then Color.DARK_GREEN else Color.DARK_RED);

AddCloud(if showCloud then dtc else na,if showCloud then dbc else na,Color.LIGHT_GREEN,Color.LIGHT_RED);

dbc.SetHiding(!showTcBcLines);
dtc.SetHiding(!showTcBcLines);

dbc.SetLineWeight(2);
 

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

Super coding BigBoss. Maybe adding a few more lines will help stay in trades. Ochoa 'shoke has eight support and resistance levels developed from the beginnings of your code. Trying coding the whole indicator. What do you think?



def Pivot = (high + low + close)/3

def BC = ( high +low ) / 2
def TC = ( pivot - BC ) + Pivot

def S1 = 2 x pivot - high
def S2 = pivot -( high - low )
def S3 = S1 - ( high - low )
def S4 = S3 - ( S1 - S2 )


def R1 = 2 x pivot - low
def R2 = pivot + (high - low )
def R3 = R1 + ( high - low )
def R4 = R3 + ( R2 - R1 )
 
Last edited:
I've been studying the Central Pivot Range (CPR) quite a bit lately and have seen some interest in the "Developing Central Pivot Range (DCPR)" here on usethinkscript, so I went ahead and coded up an indicator that displays the Developing CPR. I created this indicator a while ago and didn't really know what to make of it, but after studying it quite a bit and zooming out on the chart, I think it's really useful, especially when combined with regular CPR.

Typically, CPR is calculated from yesterday's high, low, and close and projected onto today's chart. DCPR shows how the high, low, and close that develop throughout the day end up creating tomorrow's CPR. It provides a visualization of sentiment shift throughout the day and can be effective in knowing when you're likely looking at a pullback versus a trend change. I think it can be useful for intraday trading, including scalping and day swinging.


First, a few notes on the Central Pivot Range that are applicable to the Developing Central Pivot Range as well.

The Central Pivot Range consists of three lines - the Central Pivot (CP), the Bottom Central (BC), and the Top Central (TC). Mathematically,
  • CP = (high + low + close) / 3 (think of this as the HLC3 price of the daily candle)
  • BC = (high + low) / 2 (think of this as the HL2 price of the daily candle)
  • TC = (CP - BC) + CP (this is the difference between HL2 and HLC3, mirrored across HLC3)
The result is 3 lines, with CP in the center and TC and BC equidistant from CP. Despite their names, Top Central is not always on the top. The way the math works, a candle that closes above the midpoint (BC) for the day will have TC on top and BC on bottom. A candle that closes below the midpoint will have TC on bottom and BC on top. Some influential experts on the CPR always call the top line TC and the bottom line BC - and that's fine, I often do too - but for the remainder of this discussion I will refer to them by their mathematical definitions because it's important when using the DCPR to do so. From here on out when I reference CP, TC and BC I'll be referring to the developing lines in this indicator, not the daily values in the traditional CPR.

This indicator plots CP, TC, and BC as the high, low and close for the session develop throughout the day. You'll notice that two of them - TC and CP - are very responsive to price; this is because the close price of the current bar influences 33% of the calculation. BC only changes when new daily highs or new daily lows are made. I've coded this so that when TC is above BC the lines and cloud are green, and when TC is below BC, the lines and cloud are red.


Another important concept with the CPR is the two day relationship - the traditional CPR acts as excellent support and resistance, and when the traditional CPR is higher than the previous period it is an indicator of bullish sentiment; when it is lower than the previous period it is a bearish indicator. When the CPR engulfs the prior day and is wide, you're in for some sideways movement, and when the CPR is narrow, you likely printed a doji on the daily and you're in for a ride.

I mentioned early on that this indicator is best paired with a traditional CPR indicator. This is because it gives you context into the two day relationship that is forming. If the DCPR is above the traditional CPR, you're setting up a bullish two day relationship for the following trading session. If it is below, a bearish two day relationship.

Thus, the DCPR provides excellent visual context for where you are in a trend.

Consider that if you have a Green DCPR trading above the traditional CPR, you are likely in a bullish trend continuation. A Red DCPR trading above the traditional CPR is likely just a pullback - don't go full-on bear mode yet ;-)


The inverse is true when trading below the traditional CPR - a red DCPR is bearish trend continuation, and a green DCPR is probably just a pullback. Until it isn't, of course.


After having studied this, I can think of a few ways to effectively trade it. For day swings, you could enter on pullbacks - red clouds above the traditional CPR, or green clouds below the traditional CPR. The traditional CPR is excellent support and resistance, and with an appropriately sized trade you could use it as your stop loss.

The BC line is also very tradeable. It is HL2 - the midpoint for the day - the 50% retracement from high to low at any point throughout the session. As you study this indicator, you'll find that price interacts with it often, and offers excellent opportunities for entries.

I'd love to hear if you have any thoughts on the DCPR, if you've found it useful, and if there are other good ways to trade it I haven't thought of yet.

Code:
# Developing CPR (CPR)
# by bigboss
# Version 1.0

input showTcBcLines = yes;
input showCloud = yes;

def o = open;
def h = high;
def l = low;
def c = close;
def na = Double.NaN;

def today = GetYYYYMMDD();

def rollover = today <> today[1];

def dh = if rollover or h > dh[1] then h else dh[1];
def dl = if rollover or l < dl[1] then l else dl[1];

plot dcp = (dh + dl + c) / 3;
plot dbc = (dh + dl) / 2;
plot dtc = (dcp - dbc) + dcp;

dcp.AssignValueColor(if dtc > dbc then Color.GREEN else Color.RED);
dtc.AssignValueColor(if dtc > dbc then Color.LIGHT_GREEN else Color.LIGHT_RED);
dbc.AssignValueColor(if dtc > dbc then Color.DARK_GREEN else Color.DARK_RED);

AddCloud(if showCloud then dtc else na,if showCloud then dbc else na,Color.LIGHT_GREEN,Color.LIGHT_RED);

dbc.SetHiding(!showTcBcLines);
dtc.SetHiding(!showTcBcLines);

dbc.SetLineWeight(2);
excelent job!, do you know how to extend the previous day like on your chart?
 
I've been studying the Central Pivot Range (CPR) quite a bit lately and have seen some interest in the "Developing Central Pivot Range (DCPR)" here on usethinkscript, so I went ahead and coded up an indicator that displays the Developing CPR. I created this indicator a while ago and didn't really know what to make of it, but after studying it quite a bit and zooming out on the chart, I think it's really useful, especially when combined with regular CPR.

Typically, CPR is calculated from yesterday's high, low, and close and projected onto today's chart. DCPR shows how the high, low, and close that develop throughout the day end up creating tomorrow's CPR. It provides a visualization of sentiment shift throughout the day and can be effective in knowing when you're likely looking at a pullback versus a trend change. I think it can be useful for intraday trading, including scalping and day swinging.


First, a few notes on the Central Pivot Range that are applicable to the Developing Central Pivot Range as well.

The Central Pivot Range consists of three lines - the Central Pivot (CP), the Bottom Central (BC), and the Top Central (TC). Mathematically,
  • CP = (high + low + close) / 3 (think of this as the HLC3 price of the daily candle)
  • BC = (high + low) / 2 (think of this as the HL2 price of the daily candle)
  • TC = (CP - BC) + CP (this is the difference between HL2 and HLC3, mirrored across HLC3)
The result is 3 lines, with CP in the center and TC and BC equidistant from CP. Despite their names, Top Central is not always on the top. The way the math works, a candle that closes above the midpoint (BC) for the day will have TC on top and BC on bottom. A candle that closes below the midpoint will have TC on bottom and BC on top. Some influential experts on the CPR always call the top line TC and the bottom line BC - and that's fine, I often do too - but for the remainder of this discussion I will refer to them by their mathematical definitions because it's important when using the DCPR to do so. From here on out when I reference CP, TC and BC I'll be referring to the developing lines in this indicator, not the daily values in the traditional CPR.

This indicator plots CP, TC, and BC as the high, low and close for the session develop throughout the day. You'll notice that two of them - TC and CP - are very responsive to price; this is because the close price of the current bar influences 33% of the calculation. BC only changes when new daily highs or new daily lows are made. I've coded this so that when TC is above BC the lines and cloud are green, and when TC is below BC, the lines and cloud are red.


Another important concept with the CPR is the two day relationship - the traditional CPR acts as excellent support and resistance, and when the traditional CPR is higher than the previous period it is an indicator of bullish sentiment; when it is lower than the previous period it is a bearish indicator. When the CPR engulfs the prior day and is wide, you're in for some sideways movement, and when the CPR is narrow, you likely printed a doji on the daily and you're in for a ride.

I mentioned early on that this indicator is best paired with a traditional CPR indicator. This is because it gives you context into the two day relationship that is forming. If the DCPR is above the traditional CPR, you're setting up a bullish two day relationship for the following trading session. If it is below, a bearish two day relationship.

Thus, the DCPR provides excellent visual context for where you are in a trend.

Consider that if you have a Green DCPR trading above the traditional CPR, you are likely in a bullish trend continuation. A Red DCPR trading above the traditional CPR is likely just a pullback - don't go full-on bear mode yet ;-)


The inverse is true when trading below the traditional CPR - a red DCPR is bearish trend continuation, and a green DCPR is probably just a pullback. Until it isn't, of course.


After having studied this, I can think of a few ways to effectively trade it. For day swings, you could enter on pullbacks - red clouds above the traditional CPR, or green clouds below the traditional CPR. The traditional CPR is excellent support and resistance, and with an appropriately sized trade you could use it as your stop loss.

The BC line is also very tradeable. It is HL2 - the midpoint for the day - the 50% retracement from high to low at any point throughout the session. As you study this indicator, you'll find that price interacts with it often, and offers excellent opportunities for entries.

I'd love to hear if you have any thoughts on the DCPR, if you've found it useful, and if there are other good ways to trade it I haven't thought of yet.

Code:
# Developing CPR (CPR)
# by bigboss
# Version 1.0

input showTcBcLines = yes;
input showCloud = yes;

def o = open;
def h = high;
def l = low;
def c = close;
def na = Double.NaN;

def today = GetYYYYMMDD();

def rollover = today <> today[1];

def dh = if rollover or h > dh[1] then h else dh[1];
def dl = if rollover or l < dl[1] then l else dl[1];

plot dcp = (dh + dl + c) / 3;
plot dbc = (dh + dl) / 2;
plot dtc = (dcp - dbc) + dcp;

dcp.AssignValueColor(if dtc > dbc then Color.GREEN else Color.RED);
dtc.AssignValueColor(if dtc > dbc then Color.LIGHT_GREEN else Color.LIGHT_RED);
dbc.AssignValueColor(if dtc > dbc then Color.DARK_GREEN else Color.DARK_RED);

AddCloud(if showCloud then dtc else na,if showCloud then dbc else na,Color.LIGHT_GREEN,Color.LIGHT_RED);

dbc.SetHiding(!showTcBcLines);
dtc.SetHiding(!showTcBcLines);

dbc.SetLineWeight(2);

Thank you for sharing your script! I'm trying to figure out why it doesn't prioject the pivot (purple shadow + red line) to the next day on mine? Thanks!!
 
Thank you for sharing your script! I'm trying to figure out why it doesn't prioject the pivot (purple shadow + red line) to the next day on mine? Thanks!!
I am having the same issue. (Did you get an answer?) I get the Green and Red cloud but not the purple cloud area. @bigboss , Is there a different code for the purple? If so, I cannot find it.
 
I am having the same issue. (Did you get an answer?) I get the Green and Red cloud but not the purple cloud area. @bigboss , Is there a different code for the purple? If so, I cannot find it.
here we go. Enjoy :

CSS:
# Combined and mod  by Sam4COK @ samer800 - 08/2022
# Request from https://usethinkscript.com
# Logical Trader's Pivot Range
# Assembled by BenTen at useThinkScript.com
# Converted from https://www.tradingview.com/script/aaiSbWNj-Pivot-Range-Pivot-Boss/

input timeFrame = {default DAY, WEEK, MONTH};
input showCPRLines = yes;
input showCPRCloud = yes;

def na = Double.NaN;

def PH = high(period = timeFrame);
def PL = low(period = timeFrame);
def PC = close(period = timeFrame);
#def PH = If(GetAggregationPeriod() <= AggregationPeriod.FIFTEEN_MIN, high(period = timeFrame), na);
#def PL = If(GetAggregationPeriod() <= AggregationPeriod.FIFTEEN_MIN, low(period = timeFrame), na);
#def PC = If(GetAggregationPeriod() <= AggregationPeriod.FIFTEEN_MIN, close(period = timeFrame), na);

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

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

AddCloud(if showCPRCloud then l2 else na, l3, Color.GRAY, Color.DARK_GRAY, no);
PivotLine.SetPaintingStrategy(PaintingStrategy.DASHES);
PivotLine.SetDefaultColor(Color.WHITE);
PivotLine.SetLineWeight(1);
l2.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
l2.SetDefaultColor(Color.GRAY);
l2.SetLineWeight(1);
l3.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
l3.SetDefaultColor(Color.GRAY);
l3.SetLineWeight(1);

l2.SetHiding(!showCPRLines);
l3.SetHiding(!showCPRLines);

# Developing CPR (CPR)
# by bigboss
# Version 1.0

input showTcBcLines = no;
input showCloud = yes;

def o = open;
def h = high;
def l = Low;
def c = Close;

def today = GetYYYYMMDD();

def rollover = today <> today[1];

def dh = if rollover or h > dh[1] then h else dh[1];
def dl = if rollover or l < dl[1] then l else dl[1];

plot dcp = (dh + dl + c) / 3;
plot dbc = (dh + dl) / 2;
plot dtc = (dcp - dbc) + dcp;

dcp.AssignValueColor(if dtc > dbc then Color.GREEN else Color.RED);
dtc.AssignValueColor(if dtc > dbc then Color.LIGHT_GREEN else Color.LIGHT_RED);
dbc.AssignValueColor(if dtc > dbc then Color.DARK_GREEN else Color.DARK_RED);

AddCloud(if showCloud then dtc else na,if showCloud then dbc else na,Color.DARK_GREEN,Color.DARK_RED, no);

dbc.SetHiding(!showTcBcLines);
dtc.SetHiding(!showTcBcLines);

dbc.SetLineWeight(2);

# End
 
I've been studying the Central Pivot Range (CPR) quite a bit lately and have seen some interest in the "Developing Central Pivot Range (DCPR)" here on usethinkscript, so I went ahead and coded up an indicator that displays the Developing CPR. I created this indicator a while ago and didn't really know what to make of it, but after studying it quite a bit and zooming out on the chart, I think it's really useful, especially when combined with regular CPR.

Typically, CPR is calculated from yesterday's high, low, and close and projected onto today's chart. DCPR shows how the high, low, and close that develop throughout the day end up creating tomorrow's CPR. It provides a visualization of sentiment shift throughout the day and can be effective in knowing when you're likely looking at a pullback versus a trend change. I think it can be useful for intraday trading, including scalping and day swinging.


First, a few notes on the Central Pivot Range that are applicable to the Developing Central Pivot Range as well.

The Central Pivot Range consists of three lines - the Central Pivot (CP), the Bottom Central (BC), and the Top Central (TC). Mathematically,
  • CP = (high + low + close) / 3 (think of this as the HLC3 price of the daily candle)
  • BC = (high + low) / 2 (think of this as the HL2 price of the daily candle)
  • TC = (CP - BC) + CP (this is the difference between HL2 and HLC3, mirrored across HLC3)
The result is 3 lines, with CP in the center and TC and BC equidistant from CP. Despite their names, Top Central is not always on the top. The way the math works, a candle that closes above the midpoint (BC) for the day will have TC on top and BC on bottom. A candle that closes below the midpoint will have TC on bottom and BC on top. Some influential experts on the CPR always call the top line TC and the bottom line BC - and that's fine, I often do too - but for the remainder of this discussion I will refer to them by their mathematical definitions because it's important when using the DCPR to do so. From here on out when I reference CP, TC and BC I'll be referring to the developing lines in this indicator, not the daily values in the traditional CPR.

This indicator plots CP, TC, and BC as the high, low and close for the session develop throughout the day. You'll notice that two of them - TC and CP - are very responsive to price; this is because the close price of the current bar influences 33% of the calculation. BC only changes when new daily highs or new daily lows are made. I've coded this so that when TC is above BC the lines and cloud are green, and when TC is below BC, the lines and cloud are red.


Another important concept with the CPR is the two day relationship - the traditional CPR acts as excellent support and resistance, and when the traditional CPR is higher than the previous period it is an indicator of bullish sentiment; when it is lower than the previous period it is a bearish indicator. When the CPR engulfs the prior day and is wide, you're in for some sideways movement, and when the CPR is narrow, you likely printed a doji on the daily and you're in for a ride.

I mentioned early on that this indicator is best paired with a traditional CPR indicator. This is because it gives you context into the two day relationship that is forming. If the DCPR is above the traditional CPR, you're setting up a bullish two day relationship for the following trading session. If it is below, a bearish two day relationship.

Thus, the DCPR provides excellent visual context for where you are in a trend.

Consider that if you have a Green DCPR trading above the traditional CPR, you are likely in a bullish trend continuation. A Red DCPR trading above the traditional CPR is likely just a pullback - don't go full-on bear mode yet ;-)


The inverse is true when trading below the traditional CPR - a red DCPR is bearish trend continuation, and a green DCPR is probably just a pullback. Until it isn't, of course.


After having studied this, I can think of a few ways to effectively trade it. For day swings, you could enter on pullbacks - red clouds above the traditional CPR, or green clouds below the traditional CPR. The traditional CPR is excellent support and resistance, and with an appropriately sized trade you could use it as your stop loss.

The BC line is also very tradeable. It is HL2 - the midpoint for the day - the 50% retracement from high to low at any point throughout the session. As you study this indicator, you'll find that price interacts with it often, and offers excellent opportunities for entries.

I'd love to hear if you have any thoughts on the DCPR, if you've found it useful, and if there are other good ways to trade it I haven't thought of yet.

Code:
# Developing CPR (CPR)
# by bigboss
# Version 1.0

input showTcBcLines = yes;
input showCloud = yes;

def o = open;
def h = high;
def l = low;
def c = close;
def na = Double.NaN;

def today = GetYYYYMMDD();

def rollover = today <> today[1];

def dh = if rollover or h > dh[1] then h else dh[1];
def dl = if rollover or l < dl[1] then l else dl[1];

plot dcp = (dh + dl + c) / 3;
plot dbc = (dh + dl) / 2;
plot dtc = (dcp - dbc) + dcp;

dcp.AssignValueColor(if dtc > dbc then Color.GREEN else Color.RED);
dtc.AssignValueColor(if dtc > dbc then Color.LIGHT_GREEN else Color.LIGHT_RED);
dbc.AssignValueColor(if dtc > dbc then Color.DARK_GREEN else Color.DARK_RED);

AddCloud(if showCloud then dtc else na,if showCloud then dbc else na,Color.LIGHT_GREEN,Color.LIGHT_RED);

dbc.SetHiding(!showTcBcLines);
dtc.SetHiding(!showTcBcLines);

dbc.SetLineWeight(2);
Working my way thru Ochoa's book. Thanks for creating this script - it's been really helpful!
 
has anyone thought to create a scanner with this. PB mentions a histogram which he uses to effectively anticipate trending days

I'll use the example as provided by the book. Pivot Boss says you can predict a potential breakout but measuring the width of the pivot range. He uses a histogram to demonstrate this. I tried using the scanner to do the search already but I'm unable to set parameters for the difference between top/central/bottom pivots. Is there a way to do it without requesting someone code it? I've attached examples from the book.

thanks for the info and feedback in advance
 

Attachments

  • image_2023-09-11_154513267.png
    image_2023-09-11_154513267.png
    23.5 KB · Views: 108
  • histogram.jpg
    histogram.jpg
    46.2 KB · Views: 101
  • histogram code.jpg
    histogram code.jpg
    58.8 KB · Views: 97
Last edited by a moderator:
@bigboss Thanks for the DCPR and the excellent DCPR tutorial...

@samer800 Thanks for addition of the Logical Trader's Pivot Range...

@Adeodatus Thanks for suggesting the incorporation of Support/Resistance Levels...

Based on Adeodatus' suggestion, I added the S/R Levels to the existing code...

Code:
# Combined and mod  by Sam4COK @ samer800 - 08/2022
# Request from https://usethinkscript.com
# Logical Trader's Pivot Range
# Assembled by BenTen at useThinkScript.com
# Converted from https://www.tradingview.com/script/aaiSbWNj-Pivot-Range-Pivot-Boss/

input timeFrame = {default DAY, WEEK, MONTH, QUARTER, YEAR};
input showCPRLines = yes;
input showCPRCloud = yes;
input showSupportLines = yes;
input showResistanceLines = yes;

def na = Double.NaN;

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

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

plot S1 = 2 * pivot - PH;
plot S2 = pivot -( PH - PL );
plot S3 = S1 - ( PH - PL );
plot S4 = S3 - ( S1 - S2 );

plot R1 = 2 * pivot - PL;
plot R2 = pivot + (PH - PL );
plot R3 = R1 + ( PH - PL );
plot R4 = R3 + ( R2 - R1 );
 
plot PivotLine = pivot[1];
plot l2 = bc[1];
plot l3 = tc[1];

AddCloud(if showCPRCloud then l2 else na, l3, CreateColor(127, 129, 207), CreateColor(127, 129, 207), no);
PivotLine.SetPaintingStrategy(PaintingStrategy.DASHES);
PivotLine.SetDefaultColor(CreateColor(161, 65, 196));
PivotLine.SetLineWeight(1);
l2.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
l2.SetDefaultColor(CreateColor(127, 129, 207));
l2.SetLineWeight(1);
l3.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
l3.SetDefaultColor(CreateColor(127, 129, 207));
l3.SetLineWeight(1);

PivotLine.SetHiding(!showCPRLines);
l2.SetHiding(!showCPRLines);
l3.SetHiding(!showCPRLines);

S1.SetPaintingStrategy(PaintingStrategy.DASHES);
S1.SetDefaultColor(Color.DARK_GREEN);
S1.SetLineWeight(1);

S2.SetPaintingStrategy(PaintingStrategy.DASHES);
S2.SetDefaultColor(Color.DARK_GREEN);
S2.SetLineWeight(1);

S3.SetPaintingStrategy(PaintingStrategy.DASHES);
S3.SetDefaultColor(Color.DARK_GREEN);
S3.SetLineWeight(1);

S4.SetPaintingStrategy(PaintingStrategy.DASHES);
S4.SetDefaultColor(Color.DARK_GREEN);
S4.SetLineWeight(1);

S1.SetHiding(!showSupportLines);
S2.SetHiding(!showSupportLines);
S3.SetHiding(!showSupportLines);
S4.SetHiding(!showSupportLines);

R1.SetPaintingStrategy(PaintingStrategy.DASHES);
R1.SetDefaultColor(Color.DARK_RED);
R1.SetLineWeight(1);

R2.SetPaintingStrategy(PaintingStrategy.DASHES);
R2.SetDefaultColor(Color.DARK_RED);
R2.SetLineWeight(1);

R3.SetPaintingStrategy(PaintingStrategy.DASHES);
R3.SetDefaultColor(Color.DARK_RED);
R3.SetLineWeight(1);

R4.SetPaintingStrategy(PaintingStrategy.DASHES);
R4.SetDefaultColor(Color.DARK_RED);
R4.SetLineWeight(1);

R1.SetHiding(!showResistanceLines);
R2.SetHiding(!showResistanceLines);
R3.SetHiding(!showResistanceLines);
R4.SetHiding(!showResistanceLines);


# Developing CPR (CPR)
# by bigboss
# Version 1.0

input showDcpLine = yes;
input showTcBcLines = yes; #no;
input showCloud = yes;

def o = open;
def h = high;
def l = Low;
def c = Close;

def today = GetYYYYMMDD();

def rollover = today <> today[1];

def dh = if rollover or h > dh[1] then h else dh[1];
def dl = if rollover or l < dl[1] then l else dl[1];

plot dcp = (dh + dl + c) / 3;
plot dbc = (dh + dl) / 2;
plot dtc = (dcp - dbc) + dcp;

dcp.AssignValueColor(if dtc > dbc then Color.GREEN else Color.RED);
dtc.AssignValueColor(if dtc > dbc then Color.LIGHT_GREEN else Color.PINK); #Color.LIGHT_RED);
dbc.AssignValueColor(if dtc > dbc then Color.DARK_GREEN else Color.DARK_RED);

AddCloud(if showCloud then dtc else na,if showCloud then dbc else na,Color.DARK_GREEN,Color.DARK_RED, no);

dcp.SetHiding(!showDcpLine);
dbc.SetHiding(!showTcBcLines);
dtc.SetHiding(!showTcBcLines);

dbc.SetLineWeight(2);

Good Luck and Good Trading to all :cool:
 

Similar threads

Not the exact question you're looking for?

Start a new thread and receive assistance from our community.

87k+ Posts
358 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