You are on page 1of 8

// This source code is subject to the terms of the Mozilla Public License 2.

0 at
https://mozilla.org/MPL/2.0/
// © KaranVeer
//@version=4

//***************GUIDE***********************************
//CPR - Applicable only for daily pivots
//CPR - All 3 lines display enabled by default
//CPR - Central Pivot line display cannot changed
//CPR - Central Pivot is a blue line by default and can be changed from settings
//CPR - Top Range & Bottom Ranage display can be changed from settings
//CPR - Top Range & Bottom Ranage are Yellow lines by default and can be chaned
from settings
//Daily pivots - Pivot line and CPR Central line are same
//Daily pivots - level 1 & 2 (S1, R1, S2 R2) display enabled by default and can be
changed from settings
//Daily pivots - level 3 (S3 & R3) is availale and can be seleted from settings
//Daily pivots - Resistance(R) lines are Red lines and can be changed from settings
//Daily pivots - Support(S) lines are Green lines and can be changed from settings
//Weekly pivots - Pivot is a blue line by default and can be changed from settings
//Weekly pivots - 3 levels (S1, R1, S2, R2, S3 & R3) availale and can be seleted
from settings
//Weekly pivots - Resistance(R) lines are crossed (+) Red lines and can be changed
from settings
//Weekly pivots - Support(S) lines are crossed (+) Green lines and can be changed
from settings
//Monthly pivots - Pivot is a blue line by default and can be changed from settings
//Monthly pivots - 3 levels (S1, R1, S2, R2, S3 & R3) availale and can be seleted
from settings
//Monthly pivots - Resistance(R) lines are circled (o) Red lines and can be changed
from settings
//Monthly pivots - Support(S) lines are circled (o) Green lines and can be changed
from settings

study("CPR_KaranVeer", overlay = true, shorttitle="KaranveerCPR",precision=1)

//******************LOGICS**************************
//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)

//3 highlows
PH = high
PL= low
DOPEN= open
dpclose= close
dprange= high - low

//3 Camarilla S3R3

h1=dpclose + dprange*(1.1/12)
h2=dpclose + dprange*(1.1/6)
h3=dpclose + dprange*(1.1/4)
h4=dpclose + dprange*(1.1/2)
h5=(high/low)*dpclose
l1=dpclose - dprange*(1.1/12)
l2=dpclose - dprange*(1.1/6)
l3=dpclose - dprange*(1.1/4)
l4=dpclose - dprange*(1.1/2)
l5=dpclose - (h5-dpclose)

//Checkbox inputs
CPRPlot = input(title = "Plot CPR?", type=input.bool, defval=true)
DayS1R1 = input(title = "Plot Daiy S1/R1?", type=input.bool, defval=true)
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 Monthly Pivot?", type=input.bool,
defval=false)
MonthlyS1R1 = input(title = "Plot Monthly S1/R1?", type=input.bool, defval=false)
DayPHPL = input(title = "Plot Daily PH/PL?", type=input.bool, defval=false)
WeeklyPHPL = input(title = "Plot weekly PH/PL?", type=input.bool, defval=true)
MonthlyPHPL = input(title = "Plot Monthly PH/PL?", type=input.bool, defval=false)
CamarillaS3R3 = input(title= "Plot Camarilla S3/R3?", type=input.bool,
defval=false)

//******************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)

//Adding linebreaks daywse for CPR


CPColour = DayPivot != DayPivot[1] ? na : color.fuchsia
BCColour = DayBC != DayBC[1] ? na : color.navy
TCColour = DayTC != DayTC[1] ? na : color.navy

//Plotting daywise CPR


plot(DayPivot, title = "CP" , color = CPColour, style = plot.style_line, linewidth
=3)
plot(CPRPlot ? DayBC : na , title = "BC" , color = BCColour, style =
plot.style_line, linewidth =2)
plot(CPRPlot ? DayTC : na , title = "TC" , color = TCColour, style =
plot.style_line, linewidth =2)
// 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.red
DayS2Color =DayS2 != DayS2[1] ? na : color.red
DayS3Color =DayS3 != DayS3[1] ? na : color.red

//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 resistance levels


DayR1Color =DayR1 != DayR1[1] ? na : color.green
DayR2Color =DayR2 != DayR2[1] ? na : color.green
DayR3Color =DayR3 != DayR3[1] ? na : color.green

//Plotting daywise Resistance levels


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

// Getting daywise PH/PL levels


DayPH = security(syminfo.tickerid, "D", PH[1], barmerge.gaps_off,
barmerge.lookahead_on)
DayPL = security(syminfo.tickerid, "D", PL[1], barmerge.gaps_off,
barmerge.lookahead_on)

//Adding linebreaks for daywise PH/PL levels


DayPHColor =DayPH != DayPH[1] ? na : color.black
DayPLColor =DayPL != DayPL[1] ? na : color.black

//Plotting daywise PH/PL levels


plot(DayPHPL ? DayPH : na, title = "PDH" , color = DayPHColor, style =
plot.style_line, linewidth =3)
plot(DayPHPL ? DayPL : na, title = "PDL" , color = DayPLColor, style =
plot.style_line, linewidth =3)

// Getting daywise Camarilla S3/R3 levels


Dayh3 = security(syminfo.tickerid, "D", h3[1], barmerge.gaps_off,
barmerge.lookahead_on)
Dayl3 = security(syminfo.tickerid, "D", l3[1], barmerge.gaps_off,
barmerge.lookahead_on)

//Adding linebreaks for daywise Camarilla S3/R3 level


Dayh3Color =Dayh3 != Dayh3[1] ? na : color.orange
Dayl3Color =Dayl3 != Dayl3[1] ? na : color.orange

//Plotting daywise Camarilla S3/R3 level


plot(CamarillaS3R3 ? Dayh3 : na, title = "D-h3" , color = Dayh3Color, style =
plot.style_line, linewidth =2)
plot(CamarillaS3R3 ? Dayl3 : na, title = "D-l3" , color = Dayl3Color, style =
plot.style_line, linewidth =2)

//******************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.fuchsia

//Plotting Weely Pivot


plot(WeeklyPivotInclude ? WPivot:na, title = "W-P" , color = WeeklyPivotColor,
style = plot.style_line, linewidth =3)

// 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)

//Adding linebreaks for weekly Support levels


WS1Color =WS1 != WS1[1] ? na : color.yellow
WS2Color =WS2 != WS2[1] ? na : color.yellow

//Plotting Weely Support levels


plot(WeeklyS1R1 ? WS1 : na, title = "W-S1" , color = WS1Color, style =
plot.style_line, linewidth =2)
plot(WeeklyS2R2 ? WS2 : na, title = "W-S2" , color = WS2Color, style =
plot.style_line, linewidth =2)

// 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)
//Adding linebreaks for weekly Resistance levels
WR1Color = WR1 != WR1[1] ? na : color.yellow
WR2Color = WR2 != WR2[1] ? na : color.yellow

//Plotting Weely Resistance levels


plot(WeeklyS1R1 ? WR1 : na , title = "W-R1" , color = WR1Color, style =
plot.style_line, linewidth =2)
plot(WeeklyS2R2 ? WR2 : na , title = "W-R2" , color = WR2Color, style =
plot.style_line, linewidth =2)

// Getting Weely PH/PL levels


WPH = security(syminfo.tickerid, "W", PH[1], barmerge.gaps_off,
barmerge.lookahead_on)
WPL = security(syminfo.tickerid, "W", PL[1], barmerge.gaps_off,
barmerge.lookahead_on)

//Adding linebreaks for weekly PH/PL levels


WPHColor = WPH != WPH[1] ? na : color.black
WPLColor = WPL != WPL[1] ? na : color.black

//Plotting Weely PH/PL levels


plot(WeeklyPHPL ? WPH : na , title = "PWH" , color = WPHColor, style =
plot.style_line, linewidth =3)
plot(WeeklyPHPL ? WPL : na , title = "PWL" , color = WPLColor, style =
plot.style_line, linewidth =3)

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

// Getting Monhly Pivot


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

//Adding linebreaks for Monthly pivot levels


MonthlyPivotColor =MPivot != MPivot[1] ? na : color.fuchsia

//Plotting Monhly Pivot


plot(MonthlyPivotInclude? MPivot:na, title = " M-P" , color = MonthlyPivotColor,
style = plot.style_line, linewidth =3)

// Getting Monhly Support levels


MS1 = security(syminfo.tickerid, "M", S1[1],barmerge.gaps_off,
barmerge.lookahead_on)

//Adding linebreaks for Monthly Support levels


MS1Color =MS1 != MS1[1] ? na : color.teal

//Plotting Monhly Support levels


plot(MonthlyS1R1 ? MS1 : na, title = "M-S1" , color = MS1Color, style =
plot.style_line, linewidth =2)

// Getting Monhly Resistance levels


MR1 = security(syminfo.tickerid, "M", R1[1],barmerge.gaps_off,
barmerge.lookahead_on)

MR1Color =MR1 != MR1[1] ? na : color.teal

//Plotting Monhly Resistance levels


plot(MonthlyS1R1 ? MR1 : na , title = "M-R1", color = MR1Color, style =
plot.style_line , linewidth =2)

// Getting Monhly PH/PL levels


MPH = security(syminfo.tickerid, "M", PH[1],barmerge.gaps_off,
barmerge.lookahead_on)
MPL = security(syminfo.tickerid, "M", PL[1],barmerge.gaps_off,
barmerge.lookahead_on)

MPHColor =MPH != MPH[1] ? na : color.black


MPLColor =MPL != MPL[1] ? na : color.black

//Plotting Monhly PH/PL levels


plot(MonthlyPHPL ? MPH : na , title = "PMH", color = MPHColor, style =
plot.style_line , linewidth =3)
plot(MonthlyPHPL ? MPL : na , title = "PML" , color = MPLColor, style =
plot.style_line, linewidth =3)

//------------------------------ Styling ------------------------------

var DEFAULT_COLOR = color.black


var DEFAULT_TRANSP = 0

var day_color = DEFAULT_COLOR


var day_linewidth = 1
var day_transparency = DEFAULT_TRANSP
var day_style = plot.style_circles

var week_color = DEFAULT_COLOR


var week_linewidth = 1
var week_transparency = DEFAULT_TRANSP
var week_style = plot.style_cross

//------------------------------ Logic -------------------------------

// get highs, lows and timestamps from D1 and W1 timeframes


currentday_start = security(syminfo.tickerid, 'D', open, lookahead =
barmerge.lookahead_on)
currentday_high = security(syminfo.tickerid, 'D', high, lookahead =
barmerge.lookahead_on)
currentday_low = security(syminfo.tickerid, 'D', low, lookahead =
barmerge.lookahead_on)
currentweek_high = security(syminfo.tickerid, 'W', high, lookahead =
barmerge.lookahead_on)
currentweek_low = security(syminfo.tickerid, 'W', low, lookahead =
barmerge.lookahead_on)

//------------------------- Plotting ---------------------------------


plot(currentday_start ? currentday_start : na, title = "CurrentDay OPEN", linewidth
= day_linewidth, color = color.purple, transp = day_transparency, style =
day_style)
plot(currentday_high ? currentday_high : na, title = "CurrentDay Highs", linewidth
= day_linewidth, color = color.lime, transp = day_transparency, style = day_style)
plot(currentday_low ? currentday_low : na, title = "CurrentDay Lows", linewidth =
day_linewidth, color = color.lime, transp = day_transparency, style = day_style)
plot(currentweek_high ? currentweek_high : na, title = "CurrentWeek Highs",
linewidth = week_linewidth, color = color.lime, transp = week_transparency, style =
week_style)
plot(currentweek_low ? currentweek_low : na, title = "CurrentWeek Lows", linewidth
= week_linewidth, color = color.lime, transp = week_transparency, style =
week_style)

//*****************************INDICATORs**************************

//SMA
PlotSMA = input(title = "Plot SMA?", type=input.bool, defval=true)
SMALength = input(title="SMA Length", type=input.integer, defval=20)
SMASource = input(title="SMA Source", type=input.source, defval=close)
SMAAvg = sma (SMASource, SMALength)
plot(PlotSMA ? SMAAvg : na, color= color.aqua,linewidth = 2, title="SMA")

//SMA
PlotSMA2 = input(title = "Plot SMA2?", type=input.bool, defval=true)
SMA2Length = input(title="SMA2 Length", type=input.integer, defval=50)
SMA2Source = input(title="SMA2 Source", type=input.source, defval=close)
SMA2Avg = sma (SMA2Source, SMA2Length)
plot(PlotSMA2 ? SMA2Avg : na, color= color.orange,linewidth = 2, title="SMA2")

//EMA
PlotEMA = input(title = "Plot EMA?", type=input.bool, defval=true)
EMALength = input(title="EMA Length", type=input.integer, defval=20)
EMASource = input(title="EMA Source", type=input.source, defval=close)
EMAvg = ema (EMASource, EMALength)
plot(PlotEMA ? EMAvg : na, color= color.black, linewidth = 2, title="EMA")

//SuperTrend
PlotSTrend = input(title = "Plot Super Trend?", type=input.bool, defval=true)
InputFactor=input(3, minval=1,maxval = 100, title="Factor")
InputLength=input(7, minval=1,maxval = 100, title="Lenght")
BasicUpperBand=hl2-(InputFactor*atr(InputLength))
BasicLowerBand=hl2+(InputFactor*atr(InputLength))
FinalUpperBand=1.0
FinalLowerBand=1.0
FinalUpperBand:=close[1]>FinalUpperBand[1]? max(BasicUpperBand,FinalUpperBand[1]) :
BasicUpperBand
FinalLowerBand:=close[1]<FinalLowerBand[1]? min(BasicLowerBand,FinalLowerBand[1]) :
BasicLowerBand
IsTrend=0.0
IsTrend:= close > FinalLowerBand[1] ? 1: close< FinalUpperBand[1]? -1:
nz(IsTrend[1],1)
STrendline = IsTrend==1? FinalUpperBand: FinalLowerBand
linecolor = IsTrend == 1 ? color.green : color.red
Plotline = (PlotSTrend? STrendline: na)
plot(Plotline, color = linecolor , style = plot.style_line , linewidth = 2,title =
"SuperTrend")
PlotShapeUp = cross(close,STrendline) and close>STrendline
PlotShapeDown = cross(STrendline,close) and close<STrendline
plotshape(PlotSTrend? PlotShapeUp: na, "Up Arrow",
shape.triangleup,location.belowbar,color.green,0,0)
plotshape(PlotSTrend? PlotShapeDown: na , "Down Arrow", shape.triangledown ,
location.abovebar, color.red,0,0)

You might also like