Indicator · Pine Script v4 · On the chart

My CPR V2.0

by srinivas-yarramsetti· code credited to Srini_vas

An overlay indicator that calculates and plots Central Pivot Range levels alongside standard pivot points on the price chart.

View on GitHub

Repaints

GitHub stars2on the repository
Pine versionv4older, still runs
Lines of code173
Settings14inputs
LicenceNone statedfile: MPL-2.0
Last update3 years ago30 Jun 2023

Add It to Your TradingView Chart

  1. 1Copy the scriptPress Copy script above, or the copy button on the code below.
  2. 2Open the Pine EditorOpen a TradingView chart and choose Pine Editor at the bottom of the screen.
  3. 3Paste over the templateCreate a new indicator, select all of the template text and paste. Press Save and give it a name.
  4. 4Add it to the chartPress Add to chart, then adjust the settings with the gear icon next to its name.

Source Code

173 lines of Pine Script v4 from MY_CPR_V2.pine, published under MPL-2.0 (file header). Keep the author's credit and licence lines when you reuse it.

MY_CPR_V2.pine
// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © Srini_vas

//@version=4
study("My CPR2", shorttitle="My_CPR V2.0", overlay=true)
//cenral pivot range
pivot = (high + low + close) /3 //Central Povit
BC = (high + low) / 2 //Below Central povit
TC = (pivot - BC) + pivot //Top Central povot

//3  support levels
S1 = (pivot * 2) - high
S2 = pivot - (high - low)
S3 = low - 2 * (high - pivot)

//3  resistance levels
R1 = (pivot * 2) - low
R2 = pivot + (high - low)
R3 = high + 2 * (pivot-low)

isToday = false

//Checkbox inputs
CPRPlot = input(title = "Plot CPR?", type=input.bool, defval=false)
DayS1R1 = input(title = "Plot Daiy S1/R1?", type=input.bool, defval=false)
DayS2R2 = input(title = "Plot Daiy S2/R2?", type=input.bool, defval=false)
DayS3R3 = input(title = "Plot Daiy S3/R3?", type=input.bool, defval=false)
WeeklyPivotInclude = input(title = "Plot Weekly Pivot?", type=input.bool, defval=false)
WeeklyS1R1 = input(title = "Plot weekly S1/R1?", type=input.bool, defval=false)
WeeklyS2R2 = input(title = "Plot weekly S2/R2?", type=input.bool, defval=false)
WeeklyS3R3 = input(title = "Plot weekly S3/R3?", type=input.bool, defval=false)
MonthlyPivotInclude = input(title = "Plot Montly Pivot?", type=input.bool, defval=false)
MonthlyS1R1 = input(title = "Plot Monthly S1/R1?", type=input.bool, defval=false)
MonthlyS2R2 = input(title = "Plot Monthly S2/R2?", type=input.bool, defval=false)
MonthlyS3R3 = input(title = "Plot Montly S3/R3?", type=input.bool, defval=false)
CPRAllDays = input(title = "Display CPR All Days", type=input.bool, defval=false)
PriorDays = input(title = "View Previous CPR", type=input.bool, defval=false)

if year(timenow) == year(time) and month(timenow) == month(time) and dayofmonth(timenow) == dayofmonth(time)
    isToday := true

//******************DAYWISE CPR & PIVOTS**************************
// Getting daywise CPR
DayPivot = security(syminfo.tickerid, "D", pivot[1], barmerge.gaps_off, barmerge.lookahead_on)
DayBC = security(syminfo.tickerid, "D", BC[1], barmerge.gaps_off, barmerge.lookahead_on)
DayTC = security(syminfo.tickerid, "D", TC[1], barmerge.gaps_off, barmerge.lookahead_on)
//Prev day high and low
prev_high = security(syminfo.tickerid, 'D', high[1],barmerge.gaps_off, barmerge.lookahead_on)
prev_low = security(syminfo.tickerid, 'D', low[1],barmerge.gaps_off, barmerge.lookahead_on)
plot(prev_high, title="Prev High", color=color.white,style=plot.style_circles, linewidth=1)
plot(prev_low,title="Prev low", color=color.green, style=plot.style_circles, linewidth=1)

//Adding linebreaks daywse for CPR
CPColour = DayPivot != DayPivot[1] ? na : color.fuchsia
BCColour = DayBC != DayBC[1] ? na : color.blue
TCColour = DayTC != DayTC[1] ? na : color.blue

//Plotting daywise CPR
plot(isToday or PriorDays ? DayPivot : na, title = "CP" , color = CPColour, style = plot.style_circles, linewidth =1)
plot((isToday or PriorDays) and CPRPlot ? DayBC : na , title = "BC" , color = BCColour, style = plot.style_circles, linewidth =1)
plot((isToday or PriorDays) and CPRPlot ? DayTC : na , title = "TC" , color = TCColour, style = plot.style_circles, linewidth =1)

// Getting daywise Support levels
DayS1 = security(syminfo.tickerid, "D", S1[1], barmerge.gaps_off, barmerge.lookahead_on)
DayS2 = security(syminfo.tickerid, "D", S2[1], barmerge.gaps_off, barmerge.lookahead_on)
DayS3 = security(syminfo.tickerid, "D", S3[1], barmerge.gaps_off, barmerge.lookahead_on)

//Adding linebreaks for daywise Support levels 
DayS1Color =DayS1 != DayS1[1] ? na : color.orange
DayS2Color =DayS2 != DayS2[1] ? na : color.orange
DayS3Color =DayS3 != DayS3[1] ? na : color.orange

//Plotting daywise Support levels
plot(DayS1R1 ? DayS1 : na, title = "D-S1" , color = DayS1Color, style = plot.style_line, linewidth =2)
plot(DayS2R2 ? DayS2 : na, title = "D-S2" , color = DayS2Color, style = plot.style_line, linewidth =2)
plot(DayS3R3 ? DayS3 : na, title = "D-S3" , color = DayS3Color, style = plot.style_line, linewidth =2)

// Getting daywise Resistance levels
DayR1 = security(syminfo.tickerid, "D", R1[1], barmerge.gaps_off, barmerge.lookahead_on)
DayR2 = security(syminfo.tickerid, "D", R2[1], barmerge.gaps_off, barmerge.lookahead_on)
DayR3 = security(syminfo.tickerid, "D", R3[1], barmerge.gaps_off, barmerge.lookahead_on)

//Adding linebreaks for daywise Support levels
DayR1Color =DayR1 != DayR1[1] ? na : color.orange
DayR2Color =DayR2 != DayR2[1] ? na : color.orange
DayR3Color =DayR3 != DayR3[1] ? na : color.orange

//Plotting daywise Resistance levels
plot(DayS1R1 ? DayR1 : na, title = "D-R1" , color = DayR1Color, style = plot.style_line, linewidth =1)
plot(DayS2R2 ? DayR2 : na, title = "D-R2" , color = DayR2Color, style = plot.style_line, linewidth =1)
plot(DayS3R3 ? DayR3 : na, title = "D-R3" , color = DayR3Color, style = plot.style_line, linewidth =1)

//******************WEEKLY PIVOTS**************************

// Getting Weely Pivot
WPivot = security(syminfo.tickerid, "W", pivot[1], barmerge.gaps_off, barmerge.lookahead_on)

//Adding linebreaks for Weely Pivot 
WeeklyPivotColor =WPivot != WPivot[1] ? na : color.orange

//Plotting Weely Pivot
plot(WeeklyPivotInclude ? WPivot:na, title = "W-P" , color = WeeklyPivotColor, style = plot.style_circles, linewidth =1)


// Getting Weely Support levels
WS1 = security(syminfo.tickerid, "W", S1[1],barmerge.gaps_off, barmerge.lookahead_on)
WS2 = security(syminfo.tickerid, "W", S2[1],barmerge.gaps_off, barmerge.lookahead_on)
WS3 = security(syminfo.tickerid, "W", S3[1],barmerge.gaps_off, barmerge.lookahead_on)

//Adding linebreaks for weekly Support levels
WS1Color =WS1 != WS1[1] ? na : color.green
WS2Color =WS2 != WS2[1] ? na : color.green
WS3Color =WS3 != WS3[1] ? na : color.green

//Plotting Weely Support levels
plot(WeeklyS1R1 ? WS1 : na, title = "W-S1" , color = WS1Color, style = plot.style_cross, linewidth =1)
plot(WeeklyS2R2 ? WS2 : na, title = "W-S2" , color = WS2Color, style = plot.style_cross, linewidth =1)
plot(WeeklyS3R3 ? WS3 : na, title = "W-S3" , color = WS3Color, style = plot.style_cross, linewidth =1)

// Getting Weely Resistance levels
WR1 = security(syminfo.tickerid, "W", R1[1], barmerge.gaps_off, barmerge.lookahead_on)
WR2 = security(syminfo.tickerid, "W", R2[1], barmerge.gaps_off, barmerge.lookahead_on)
WR3 = security(syminfo.tickerid, "W", R3[1], barmerge.gaps_off, barmerge.lookahead_on)

//Adding linebreaks for weekly Resistance levels
WR1Color = WR1 != WR1[1] ? na : color.red
WR2Color = WR2 != WR2[1] ? na : color.red
WR3Color = WR3 != WR3[1] ? na : color.red

//Plotting Weely Resistance levels
plot(WeeklyS1R1 ? WR1 : na , title = "W-R1" , color = WR1Color, style = plot.style_cross, linewidth =1)
plot(WeeklyS2R2 ? WR2 : na , title = "W-R2" , color = WR2Color, style = plot.style_cross, linewidth =1)
plot(WeeklyS3R3 ? WR3 : na , title = "W-R3" , color = WR3Color, style = plot.style_cross, linewidth =1)

//******************MONTHLY PIVOTS**************************

// Getting Monhly Pivot
MPivot = security(syminfo.tickerid, "M", pivot[1],barmerge.gaps_off, barmerge.lookahead_on)

//Adding linebreaks for Monthly Support levels 
MonthlyPivotColor =MPivot != MPivot[1] ? na : color.blue

//Plotting  Monhly Pivot
plot(MonthlyPivotInclude? MPivot:na, title = " M-P" , color = MonthlyPivotColor, style = plot.style_line, linewidth =1)

// Getting  Monhly Support levels
MS1 = security(syminfo.tickerid, "M", S1[1],barmerge.gaps_off, barmerge.lookahead_on)
MS2 = security(syminfo.tickerid, "M", S2[1],barmerge.gaps_off, barmerge.lookahead_on)
MS3 = security(syminfo.tickerid, "M", S3[1],barmerge.gaps_off, barmerge.lookahead_on)

//Adding linebreaks for Montly Support levels
MS1Color =MS1 != MS1[1] ? na : color.green
MS2Color =MS2 != MS2[1] ? na : color.green
MS3Color =MS3 != MS3[1] ? na : color.green

//Plotting  Monhly Support levels
plot(MonthlyS1R1 ? MS1 : na, title = "M-S1" , color = MS1Color, style = plot.style_circles, linewidth =1)
plot(MonthlyS2R2 ? MS2 : na, title = "M-S2" , color = MS2Color, style = plot.style_circles, linewidth =1)
plot(MonthlyS3R3 ? MS3 : na, title = "M-S3" , color = MS3Color, style = plot.style_circles, linewidth =1)

// Getting  Monhly Resistance levels
MR1 = security(syminfo.tickerid, "M", R1[1],barmerge.gaps_off, barmerge.lookahead_on)
MR2 = security(syminfo.tickerid, "M", R2[1],barmerge.gaps_off, barmerge.lookahead_on)
MR3 = security(syminfo.tickerid, "M", R3[1],barmerge.gaps_off, barmerge.lookahead_on)

MR1Color =MR1 != MR1[1] ? na : color.red
MR2Color =MR2 != MR2[1] ? na : color.red
MR3Color =MR3 != MR3[1] ? na : color.red

//Plotting  Monhly Resistance levels
plot(MonthlyS1R1 ? MR1 : na , title = "M-R1", color = MR1Color, style = plot.style_circles , linewidth =1)
plot(MonthlyS2R2 ? MR2 : na , title = "M-R2" , color = MR2Color, style = plot.style_circles, linewidth =1)
plot(MonthlyS3R3 ? MR3 : na, title = "M-R3" , color = MR3Color, style = plot.style_circles, linewidth =1)

Overview

My CPR V2.0 computes daily, weekly, and monthly pivot lines including Central Pivot, Top Central, and Bottom Central, as well as three tiers of support and resistance levels. Settings allow traders to individually toggle daily, weekly, and monthly levels, view previous day high and low lines, or filter display to current or prior days. Higher timeframe data is retrieved using security lookahead.

Details

Published by

srinivas-yarramsetti on GitHub

Code credit

Srini_vas, as written in the script's header

Type

Indicator, Pine Script v4

Draws

On the price chart

Category

Support & resistance

Markets

Any symbol

Timeframes

M1-M5, M15-H1

Risk Notes

  • Reads higher-timeframe data with lookahead on, so the history can show signals that were not there in real time

Settings

The inputs you can change from the gear icon on the chart. Defaults are the author's.

SettingTypeDefaultVariable
Plot CPR?boolfalseCPRPlot
Plot Daiy S1/R1?boolfalseDayS1R1
Plot Daiy S2/R2?boolfalseDayS2R2
Plot Daiy S3/R3?boolfalseDayS3R3
Plot Weekly Pivot?boolfalseWeeklyPivotInclude
Plot weekly S1/R1?boolfalseWeeklyS1R1
Plot weekly S2/R2?boolfalseWeeklyS2R2
Plot weekly S3/R3?boolfalseWeeklyS3R3
Plot Montly Pivot?boolfalseMonthlyPivotInclude
Plot Monthly S1/R1?boolfalseMonthlyS1R1
Plot Monthly S2/R2?boolfalseMonthlyS2R2
Plot Montly S3/R3?boolfalseMonthlyS3R3
Show all 14 settings
SettingTypeDefaultVariable
Display CPR All DaysboolfalseCPRAllDays
View Previous CPRboolfalsePriorDays
Third-party code. ForexR did not write, test or endorse this script, and the summary above was generated automatically from its code and README. Indicators describe the past, and a strategy's backtest can look better than live trading, especially when a script repaints. Check it in the Strategy Tester and on a demo account before you rely on it.

Similar Pine Scripts

948 stars

Moving Average Channel plots separate simple moving averages for upper and lower bands on the price chart. It fills the space between bands with semi-transparent color and colors bars green above the upper band, red below the lower band, or gray in between. Us

Indicator v4 Moving averagesSupport & resistance
Updated 10 days ago · GPL-3.0 GitHub repository of Moving Average Channel

ICT Equal Highs and Lows

by ArunKBhaskar
575 stars

This overlay indicator finds pivot highs and lows on the price chart and compares the last two highs and the last two lows. When the percentage difference between a pair is below the Equal HL threshold, it treats them as equal levels and draws a box. Left and

Indicator v5 SMC / ICT / price actionSupport & resistance
Updated 1 year ago · MPL-2.0 GitHub repository of ICT Equal Highs and Lows
330 stars

This indicator monitors multiple cryptocurrency symbols for trading signals. It calculates and plots entry prices, take profit, and stop loss levels for each symbol including BTCUSDT, ETHUSDT, BNBUSDT and others. Price crossovers trigger buy, sell or close ale

Indicator v5 Support & resistanceScreeners & dashboards
Updated 2 months ago · None stated GitHub repository of Multi Alert Long/Short [Alorse]

This overlay indicator draws a fixed-range volume profile on the price chart, splitting traded activity into up and down volume at each price level. It also plots a sentiment profile, a developing point of control, and value-area high and low around a configur

Indicator v5 VolumeSupport & resistance
Updated 2 months ago · MIT GitHub repository of Volume Profile and Indicator by DGT

BZ-tracker

by Allen1212
303 stars

The BZ-tracker indicator marks ARK Invest buy and sell transactions on stock charts with labels. It plots green labels for purchases and red labels for sales, each annotated with a multiplier such as X1 or X2 to show the number of ARK ETFs trading the stock on

Indicator v4 Support & resistanceScreeners & dashboards
Updated 2 years ago · None stated GitHub repository of BZ-tracker

Function - Linear Regression

by ricardosantos79
261 stars

This indicator fits a linear regression through stored pivot highs and lows and draws the resulting channel on the price chart. A function returns predicted values, maximum and minimum deviations, and the average absolute deviation. Confirmed two-bar pivots up

Indicator v5 TrendSupport & resistance
Updated 4 years ago · None stated GitHub repository of Function - Linear Regression

More indicators

Trade Your Charts With a Regulated Broker

Compare brokers that connect to TradingView, with spreads, minimum deposits and leverage side by side.

Compare brokers