0% found this document useful (0 votes)
36 views8 pages

Version 5

The document is a script for a trading indicator that calculates and displays various pivot points, including daily, weekly, and monthly pivots, as well as central pivot ranges and moving averages. It allows users to customize the number of pivots shown and whether to display specific indicators such as Camarilla levels and previous highs and lows. The script is written in Pine Script for use on the TradingView platform.

Uploaded by

limoko7589
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
36 views8 pages

Version 5

The document is a script for a trading indicator that calculates and displays various pivot points, including daily, weekly, and monthly pivots, as well as central pivot ranges and moving averages. It allows users to customize the number of pivots shown and whether to display specific indicators such as Camarilla levels and previous highs and lows. The script is written in Pine Script for use on the TradingView platform.

Uploaded by

limoko7589
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 8

//@version=4

//Indicator for Daily CPR, Monthly Pivots, Weekly Pivots, Highs and Lows, Moving
averages and Camarilla pivots.
//Number of days pivots need to be shown can be set
study(title="CPR Camarilla & MA", shorttitle="CPR & MA", overlay=true)

//Inputs
daily_cpr = input (title="Number of Daily CPR to show", type= input.integer ,
defval=1, minval=0)
weekly_pivot_back = input (title="Number of Weekly pivot to show ", type =
input.integer , defval=1, minval=0)
monthly_pivot_back = input (title="Number of Monthly pivot to show ", type =
input.integer , defval=1, minval=0)

showCPR = input(true, title="Show Daily CPR")


showWeekly = input(true, title="Show Weekly Pivots")
showMonthly = input(true, title="Show Monthly Pivots")

showPrevDayHL = input(true, title="Show Prev Day HL")


showPrevWeekHL = input(true, title="Show Prev Week HL")
showPrevMonthHL = input(true, title="Show Prev Month HL")

showTomorrowCPR = input(false, title="Show Tomorrow CPR")


tomorrowCPRType = input(title="Tomorrow CPR Type", defval="D", options=["D", "W",
"M"])

showEMA = input(false, title="Show EMA")

showSMA = input(true, title="Show SMA")


showCamarilla = input(false, title="Show Camarilla levels")
showCamarillaInner = input(false, title="Show Camarilla inner levels")

new_bar(res) => change(time(res)) != 0


new_period(condition, src) =>
result = 0.0
result := condition ? src : result[1]
result

// Pivot calculation
pivot = (high + low + close) / 3.0
bc = (high + low) / 2.0
tc = (pivot - bc) + pivot
R1 = (2*pivot) - low
S1 = (2*pivot) - high
R2 = pivot + ( high - low)
S2 = pivot - ( high - low)
R3 = high + (2*(pivot - low))
S3 = low - (2*(high - pivot ))
R4 = R3 + (R2 - R1)
S4 = S3 + (S2 - S1)
PH = high
PL= low

//Daily Central Pivot Range


dpp = security( syminfo.tickerid , 'D', pivot[1], lookahead=barmerge.lookahead_on)
dbc = security( syminfo.tickerid , 'D', bc[1], lookahead=barmerge.lookahead_on)
dtc = security( syminfo.tickerid , 'D', tc[1], lookahead=barmerge.lookahead_on)
dR1 = security( syminfo.tickerid , 'D', R1[1], lookahead=barmerge.lookahead_on)
dS1 = security( syminfo.tickerid , 'D', S1[1], lookahead=barmerge.lookahead_on)
dR2 = security( syminfo.tickerid , 'D', R2[1], lookahead=barmerge.lookahead_on)
dS2 = security( syminfo.tickerid , 'D', S2[1], lookahead=barmerge.lookahead_on)
dR3 = security( syminfo.tickerid , 'D', R3[1], lookahead=barmerge.lookahead_on)
dS3 = security( syminfo.tickerid , 'D', S3[1], lookahead=barmerge.lookahead_on)
dR4 = security( syminfo.tickerid , 'D', R4[1], lookahead=barmerge.lookahead_on)
dS4 = security( syminfo.tickerid , 'D', S4[1], lookahead=barmerge.lookahead_on)
dPH = security( syminfo.tickerid , 'D', PH[1], lookahead=barmerge.lookahead_on)
dPL = security( syminfo.tickerid , 'D', PL[1], lookahead=barmerge.lookahead_on)

one_day = 1000 * 60 * 60 * 24

//Daily pivots based on number of pivots back selection


new_day = daily_cpr > 0 and timenow - time < one_day * daily_cpr and new_bar("D")
dpp_ = new_period(new_day, dpp)
dtc_ = new_period(new_day, dtc)
dbc_ = new_period(new_day, dbc)
dR1_ = new_period(new_day, dR1)
dS1_ = new_period(new_day, dS1)
dR2_ = new_period(new_day, dR2)
dS2_ = new_period(new_day, dS2)
dR3_ = new_period(new_day, dR3)
dS3_ = new_period(new_day, dS3)
dR4_ = new_period(new_day, dR4)
dS4_ = new_period(new_day, dS4)
dPH_ = new_period(new_day, dPH)
dPL_ = new_period(new_day, dPL)

plot( (timeframe.isintraday and showCPR) ? (dtc_ >= dbc_ ? dtc_ : dbc_) : na,
title="Daily TC", style= plot.style_circles , color=#2196f3, linewidth=2)
plot( (timeframe.isintraday and showCPR) ? dpp_ : na, title="Daily PP", style=
plot.style_circles, color=#9C27B0, linewidth=2)
plot( (timeframe.isintraday and showCPR) ? (dtc_ >= dbc_ ? dbc_ : dtc_) : na,
title="Daily BC", style= plot.style_circles, color=#2196f3, linewidth=2)

plot(showCPR ? dR1_ : na, title='R1', title="Daily R1", style= plot.style_circles ,


color=#ff0000, linewidth=3)
plot(showCPR ? dR2_ : na, title='R2', title="Daily R2", style= plot.style_circles ,
color=#ff0000, linewidth=2)
plot(showCPR ? dR3_ : na, title='R3', title="Daily R3", style= plot.style_circles ,
color=#ff0000, linewidth=2)
plot(showCPR ? dR4_ : na, title='R4', title="Daily R4", style= plot.style_circles ,
color=#ff0000, linewidth=2)
plot(showCPR ? dS1_ : na, title='S1', title="Daily S1", style= plot.style_circles ,
color=#008000, linewidth=3)
plot(showCPR ? dS2_ : na, title='S2', title="Daily S2", style= plot.style_circles ,
color=#008000, linewidth=2)
plot(showCPR ? dS3_ : na, title='S3', title="Daily S3", style= plot.style_circles ,
color=#008000, linewidth=2)
plot(showCPR ? dS4_ : na, title='S4', title="Daily S4", style= plot.style_circles ,
color=#008000, linewidth=2)
plot(showPrevDayHL ? dPH_ : na, title='PDH', title="Previous Day High", style=
plot.style_circles , color=#ff9800, linewidth=2)
plot(showPrevDayHL ? dPL_ : na, title='PDL', title="Previous Day Low", style=
plot.style_circles , color=#ff9800, linewidth=2)
//Weekly

wtime_pvt = security(syminfo.tickerid, 'W', pivot[1],


lookahead=barmerge.lookahead_on)
wtime_R1 = security(syminfo.tickerid, 'W', R1[1], lookahead=barmerge.lookahead_on)
wtime_S1 = security(syminfo.tickerid, 'W', S1[1], lookahead=barmerge.lookahead_on)
wtime_R2 = security(syminfo.tickerid, 'W', R2[1], lookahead=barmerge.lookahead_on)
wtime_S2 = security(syminfo.tickerid, 'W', S2[1], lookahead=barmerge.lookahead_on)
wtime_R3 = security(syminfo.tickerid, 'W', R3[1], lookahead=barmerge.lookahead_on)
wtime_S3 = security(syminfo.tickerid, 'W', S3[1], lookahead=barmerge.lookahead_on)
wtime_R4 = security(syminfo.tickerid, 'W', R4[1], lookahead=barmerge.lookahead_on)
wtime_S4 = security(syminfo.tickerid, 'W', S4[1], lookahead=barmerge.lookahead_on)
whigh = security(syminfo.tickerid, "W", high[1], lookahead=barmerge.lookahead_on)
wlow = security(syminfo.tickerid, "W", low[1], lookahead=barmerge.lookahead_on)

//Weekly pivots based on number of pivots back selection


one_week = one_day * 7
new_week = weekly_pivot_back > 0 and timenow - time < one_week * weekly_pivot_back
and new_bar("W")

wtime_pvt_ = new_period(new_week, wtime_pvt)


wtime_R1_ = new_period(new_week, wtime_R1)
wtime_S1_ = new_period(new_week, wtime_S1)
wtime_R2_ = new_period(new_week, wtime_R2)
wtime_S2_ = new_period(new_week, wtime_S2)
wtime_R3_ = new_period(new_week, wtime_R3)
wtime_S3_ = new_period(new_week, wtime_S3)
wtime_R4_ = new_period(new_week, wtime_R4)
wtime_S4_ = new_period(new_week, wtime_S4)

//week high low


whigh_ = new_period(new_week, whigh)
wlow_ = new_period(new_week, wlow)

//Plotting weekly pivots


plot(showWeekly and wtime_pvt_ ? wtime_pvt_ : na, title="Weekly
pvt",style=plot.style_circles, color=#ffffff,linewidth=2)
plot(showWeekly and wtime_R1_ ? wtime_R1_ : na, title="Weekly
R1",style=plot.style_circles, color=#a5d6a7,linewidth=2)
plot(showWeekly and wtime_S1_ ? wtime_S1_ : na, title="Weekly
S1",style=plot.style_circles, color=#ef9a9a,linewidth=2)
plot(showWeekly and wtime_R2_ ? wtime_R2_ : na, title="Weekly
R2",style=plot.style_circles, color=#a5d6a7,linewidth=2)
plot(showWeekly and wtime_S2_ ? wtime_S2_ : na, title="Weekly
S2",style=plot.style_circles, color=#ef9a9a,linewidth=2)
plot(showWeekly and wtime_R3_ ? wtime_R3_ : na, title="Weekly
R3",style=plot.style_circles, color=#a5d6a7,linewidth=2)
plot(showWeekly and wtime_S3_ ? wtime_S3_ : na, title="Weekly
S3",style=plot.style_circles, color=#ef9a9a,linewidth=2)
plot(showWeekly and wtime_R4_ ? wtime_R4_ : na, title="Weekly
R4",style=plot.style_circles, color=#a5d6a7,linewidth=2)
plot(showWeekly and wtime_S4_ ? wtime_S4_ : na, title="Weekly
S4",style=plot.style_circles, color=#ef9a9a,linewidth=2)
//plotting weekly high lows
plot(showPrevWeekHL and whigh_ ? whigh_ : na, title="Prev Week
High",style=plot.style_cross, color=#ffffff,linewidth=2)
plot(showPrevWeekHL and wlow_ ? wlow_ : na, title="Prev Week
Low",style=plot.style_cross, color=#ffffff,linewidth=2)

//Monthly pvts

mtime_pvt = security(syminfo.tickerid, 'M', pivot[1],


lookahead=barmerge.lookahead_on)
mtime_R1 = security(syminfo.tickerid, 'M', R1[1], lookahead=barmerge.lookahead_on)
mtime_S1 = security(syminfo.tickerid, 'M', S1[1], lookahead=barmerge.lookahead_on)
mtime_R2 = security(syminfo.tickerid, 'M', R2[1], lookahead=barmerge.lookahead_on)
mtime_S2 = security(syminfo.tickerid, 'M', S2[1], lookahead=barmerge.lookahead_on)
mtime_R3 = security(syminfo.tickerid, 'M', R3[1], lookahead=barmerge.lookahead_on)
mtime_S3 = security(syminfo.tickerid, 'M', S3[1], lookahead=barmerge.lookahead_on)
//mtime_R4 = security(syminfo.tickerid, 'M', R4[1],
lookahead=barmerge.lookahead_on)
//mtime_S4 = security(syminfo.tickerid, 'M', S4[1],
lookahead=barmerge.lookahead_on)

//Prev Month High Low


mhigh = security(syminfo.tickerid, "M", high[1], lookahead=barmerge.lookahead_on)
mlow = security(syminfo.tickerid, "M", low[1], lookahead=barmerge.lookahead_on)

//Monthly pivots based on number of pivots back selection


one_month = one_day * 30
new_month = monthly_pivot_back > 0 and timenow - time < one_month *
monthly_pivot_back and new_bar("M")

mtime_pvt_ = new_period(new_month, mtime_pvt)


mtime_R1_ = new_period(new_month, mtime_R1)
mtime_S1_ = new_period(new_month, mtime_S1)
mtime_R2_ = new_period(new_month, mtime_R2)
mtime_S2_ = new_period(new_month, mtime_S2)
mtime_R3_ = new_period(new_month, mtime_R3)
mtime_S3_ = new_period(new_month, mtime_S3)
//mtime_R4_ = new_period(new_month, mtime_R4)
//mtime_S4_ = new_period(new_month, mtime_S4)
mhigh_ = new_period(new_month, mhigh)
mlow_ = new_period(new_month, mlow)

//Plotting monthly pivots


plot(showMonthly and mtime_pvt_ ? mtime_pvt_ : na, title="Monthly
pvt",style=plot.style_circles, color=#f8bbd0,linewidth=2)
plot(showMonthly and mtime_R1_ ? mtime_R1_ : na, title="Monthly
R1",style=plot.style_circles, color=#26a69a,linewidth=2)
plot(showMonthly and mtime_S1_ ? mtime_S1_ : na, title="Monthly
S1",style=plot.style_circles, color=#26a69a,linewidth=2)
plot(showMonthly and mtime_R2_ ? mtime_R2_ : na, title="Monthly
R2",style=plot.style_circles, color=#26a69a,linewidth=2)
plot(showMonthly and mtime_S2_ ? mtime_S2_ : na, title="Monthly
S2",style=plot.style_circles, color=#26a69a,linewidth=2)
plot(showMonthly and mtime_R3_ ? mtime_R3_ : na, title="Monthly
R3",style=plot.style_circles, color=#26a69a,linewidth=2)
plot(showMonthly and mtime_S3_ ? mtime_S3_ : na, title="Monthly
S3",style=plot.style_circles, color=#26a69a,linewidth=2)
//plot(showMonthly and mtime_R4_ ? mtime_R4_ : na, title="Monthly
R4",style=plot.style_circles, color=#26a69a,linewidth=2)
//plot(showMonthly and mtime_S4_ ? mtime_S4_ : na, title="Monthly
S4",style=plot.style_circles, color=#26a69a,linewidth=2)

//plotting Monthly high lows


plot(showPrevMonthHL and mhigh_ ? mhigh_ : na, title="Prev Month
High",style=plot.style_cross, color=#f8bbd0,linewidth=2)
plot(showPrevMonthHL and mlow_ ? mlow_ : na, title="Prev Month
Low",style=plot.style_cross, color=#f8bbd0,linewidth=2)

//Tomorrow CPR

//Tomorrow's Pivot Calculation


tpopen = security(syminfo.tickerid, tomorrowCPRType, open, barmerge.gaps_off,
barmerge.lookahead_on)
tphigh = security(syminfo.tickerid, tomorrowCPRType, high, barmerge.gaps_off,
barmerge.lookahead_on)
tplow = security(syminfo.tickerid, tomorrowCPRType, low, barmerge.gaps_off,
barmerge.lookahead_on)
tpclose = security(syminfo.tickerid, tomorrowCPRType, close, barmerge.gaps_off,
barmerge.lookahead_on)
tprange = tphigh - tplow

tppivot = (tphigh + tplow + tpclose) / 3.0


tpbc = (tphigh + tplow) / 2.0
tptc = tppivot - tpbc + tppivot
tpr1 = tppivot * 2 - tplow
tps1 = tppivot * 2 - tphigh

//Tommorow Pivots plotting and labels


plot(showTomorrowCPR and tppivot ? tppivot : na, title="Tomrrow Pivot",
color=#2196f3, style=plot.style_circles, transp=0, linewidth=2)
plot(showTomorrowCPR and tpbc ? tpbc : na, title="Tomrrow BC", color=#2196f3,
style=plot.style_circles, transp=0, linewidth=2)
plot(showTomorrowCPR and tptc ? tptc : na, title="Tomrrow TC", color=#2196f3,
style=plot.style_circles, transp=0, linewidth=2)
plot(showTomorrowCPR and tpr1 ? tpr1 : na, title="Tomrrow R1", color=#ff0000,
style=plot.style_circles, transp=0, linewidth=2)
plot(showTomorrowCPR and tps1 ? tps1 : na, title="Tomrrow S1", color=#008000,
style=plot.style_circles, transp=0, linewidth=2)

////// Moving Aaverages

//EMA

//EMA 1
lenE1 = input(9, minval=1, title="EMA 1 Length")
srcE1 = input(close, title="Source")
outE1 = ema(srcE1, lenE1)
plot(showEMA ? outE1 : na, color=#fb41ff, title="EMA 1", linewidth=2)

//EMA 2
lenE2 = input(20, minval=1, title="EMA 2 Length")
srcE2 = input(close, title="Source")
outE2 = ema(srcE2, lenE2)
plot(showEMA ? outE2 : na, color=#fb41ff, title="EMA 2", linewidth=2)

//EMA 3
lenE3 = input(50, minval=1, title="EMA 3 Length")
srcE3 = input(close, title="Source")
outE3 = ema(srcE3, lenE3)
plot(showEMA ? outE3 : na, color=#fb41ff, title="EMA 3", linewidth=2)

//EMA 4
lenE4 = input(100, minval=1, title="EMA 4 Length")
srcE4 = input(close, title="Source")
outE4 = ema(srcE4, lenE4)
plot(showEMA ? outE4 : na, color=#fb41ff, title="EMA 4", linewidth=2)

//EMA 5
lenE5 = input(200, minval=1, title="EMA 5 Length")
srcE5 = input(close, title="Source")
outE5 = ema(srcE5, lenE5)
plot(showEMA ? outE5 : na, color=#fb41ff, title="EMA 5", linewidth=2)

//SMA

//SMA 1
lenS1 = input(9, minval=1, title="SMA 1 Length")
srcS1 = input(close, title="Source")
outS1 = sma(srcS1, lenS1)
plot(showSMA ? outS1 : na, color=#ffeb3b, title="SMA 1", linewidth=2)

//SMA 2
lenS2 = input(20, minval=1, title="SMA 2 Length")
srcS2 = input(close, title="Source")
outS2 = sma(srcS2, lenS2)
plot(showSMA ? outS2 : na, color=#008000, title="SMA 2", linewidth=2)

//SMA 3
lenS3 = input(50, minval=1, title="SMA 3 Length")
srcS3 = input(close, title="Source")
outS3 = sma(srcS3, lenS3)
plot(showSMA ? outS3 : na, color=#ff0000, title="SMA 3", linewidth=2)

//SMA 4
lenS4 = input(100, minval=1, title="SMA 4 Length")
srcS4 = input(close, title="Source")
outS4 = sma(srcS4, lenS4)
plot(showSMA ? outS4 : na, color=#00bcd4, title="SMA 4", linewidth=2)

//SMA 5
lenS5 = input(200, minval=1, title="SMA 5 Length")
srcS5 = input(close, title="Source")
outS5 = sma(srcS5, lenS5)
plot(showSMA ? outS5 : na, color=#ffffff, title="SMA 5", linewidth=2)

//// Camarilla Pivots ////

//Get previous day/week bar and avoiding realtime calculation by taking the
previous to current bar

sopen = security(syminfo.tickerid, "D", open[1], barmerge.gaps_off,


barmerge.lookahead_on)
shigh = security(syminfo.tickerid, "D", high[1], barmerge.gaps_off,
barmerge.lookahead_on)
slow = security(syminfo.tickerid, "D", low[1], barmerge.gaps_off,
barmerge.lookahead_on)
sclose = security(syminfo.tickerid, "D", close[1], barmerge.gaps_off,
barmerge.lookahead_on)
r = shigh-slow

// //Calculate pivots
//center=(sclose)
h1=sclose + r*(1.1/12)
h2=sclose + r*(1.1/6)
h3=sclose + r*(1.1/4)
h4=sclose + r*(1.1/2)
//h5=(shigh/slow)*sclose
l1=sclose - r*(1.1/12)
l2=sclose - r*(1.1/6)
l3=sclose - r*(1.1/4)
l4=sclose - r*(1.1/2)
//l5=sclose - (h5-sclose)

// //Showing camarilla based on daily pivots back count


h1_ = new_period(new_day, h1)
h2_ = new_period(new_day, h2)
h3_ = new_period(new_day, h3)
h4_ = new_period(new_day, h4)
l1_ = new_period(new_day, l1)
l2_ = new_period(new_day, l2)
l3_ = new_period(new_day, l3)
l4_ = new_period(new_day, l4)

// //Colors (<ternary conditional operator> expression prevents continuous lines on


history)
// //c5=sopen != sopen[1] ? na : color.red
c4=sopen != sopen[1] ? na : color.fuchsia
c3=sopen != sopen[1] ? na : color.green
c2=sopen != sopen[1] ? na : color.blue
c1=sopen != sopen[1] ? na : color.gray
//cc=sopen != sopen[1] ? na : color.black

//Plotting

//plot(center, title="Central",color=cc, linewidth=2)


//plot(h5, title="H5",color=c5, linewidth=1)

// //Camarilla levels
plot(showCamarilla ? h4_ : na, title="H4",color = (sopen != sopen[1] ? na :
#bcae2d), style=plot.style_cross, linewidth=2)
plot(showCamarilla ? h3_ : na, title="H3",color = (sopen != sopen[1] ? na :
#f0da19), style=plot.style_cross, linewidth=2)
plot(showCamarilla ? l3_ : na, title="L3",color = (sopen != sopen[1] ? na :
#00ff0e), style=plot.style_cross, linewidth=2)
plot(showCamarilla ? l4_ : na, title="L4",color = (sopen != sopen[1] ? na :
#389d3d), style=plot.style_cross, linewidth=2)

// //Inner Camarilla levels


plot(showCamarillaInner ? h2_ : na, title="H2",color = (sopen != sopen[1] ? na :
#fff176), style=plot.style_cross, linewidth=1)
plot(showCamarillaInner ? h1_ : na, title="H1",color = (sopen != sopen[1] ? na :
#fff176), style=plot.style_cross, linewidth=1)
plot(showCamarillaInner ? l1_ : na, title="L1",color = (sopen != sopen[1] ? na :
#66bb6a), style=plot.style_cross, linewidth=1)
plot(showCamarillaInner ? l2_ : na, title="L2",color = (sopen != sopen[1] ? na :
#66bb6a), style=plot.style_cross, linewidth=1)

// //plot(l5, title="L5",color=c5, linewidth=1)

You might also like