[go: up one dir, main page]

0% found this document useful (0 votes)
688 views4 pages

CPR

This Pine script calculates and plots daily, weekly, and monthly central pivot ranges based on a security's historical data. It takes the daily central pivot, resistance and support levels from the last N days as defined by the user and plots them. It also conditionally plots the weekly and monthly central pivot ranges based on user inputs.

Uploaded by

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

CPR

This Pine script calculates and plots daily, weekly, and monthly central pivot ranges based on a security's historical data. It takes the daily central pivot, resistance and support levels from the last N days as defined by the user and plots them. It also conditionally plots the weekly and monthly central pivot ranges based on user inputs.

Uploaded by

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

//@version=4

study(title="SD - Central Pivot Range - Daily ", shorttitle="Nkommala-CPR", overlay=true)

daily_cpr = input (title="Number of Daily CPR Back", type= input.integer , defval=7, minval=0)

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

new_period(condition, src) =>

result = 0.0

result := condition ? src : result[1]

result

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

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


one_day = 1000 * 60 * 60 * 24

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)

plot( timeframe.isintraday ? (dtc_ >= dbc_ ? dtc_ : dbc_) : na, title="Daily TC", style=
plot.style_circles , color=#787B86, linewidth=2)

plot( timeframe.isintraday ? dpp_ : na, title="Daily PP", style= plot.style_circles, color=#9C27B0,


linewidth=2)

plot( timeframe.isintraday ? (dtc_ >= dbc_ ? dbc_ : dtc_) : na, title="Daily BC", style=
plot.style_circles, color=#2196F3, linewidth=2)

plot(dR1_ , title='R1', title="Daily TC", style= plot.style_circles , color=#FF5252, linewidth=2)

plot(dR2_ , title='R2', title="Daily TC", style= plot.style_circles , color=#FF5252, linewidth=2)

plot(dR3_ , title='R3', title="Daily TC", style= plot.style_circles , color=#FF5252, linewidth=2)

plot(dS1_ , title='S1', title="Daily TC", style= plot.style_circles , color=#4CAF50, linewidth=2)

plot(dS2_ , title='S2', title="Daily TC", style= plot.style_circles , color=#4CAF50, linewidth=2)

plot(dS3_ , title='S3', title="Daily TC", style= plot.style_circles , color=#4CAF50, linewidth=2)

//Weekly

sw = input(false, title="Show Weekly Pivots?")

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)

plot(sw and wtime_pvt ? wtime_pvt : na, title="Weekly pvt",style=plot.style_circles,


color=color.fuchsia,linewidth=3)

plot(sw and wtime_R1 ? wtime_R1 : na, title="Weekly R1",style=plot.style_circles,


color=color.fuchsia,linewidth=3)

plot(sw and wtime_S1 ? wtime_S1 : na, title="Weekly S1",style=plot.style_circles,


color=color.fuchsia,linewidth=3)

plot(sw and wtime_R2 ? wtime_R2 : na, title="Weekly R2",style=plot.style_circles,


color=color.fuchsia,linewidth=3)

plot(sw and wtime_S2 ? wtime_S2 : na, title="Weekly S2",style=plot.style_circles,


color=color.fuchsia,linewidth=3)

//Monthly pvts

sm = input(true, title="Show Monthly Pivots?")

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)

plot(sm and mtime_pvt ? mtime_pvt : na, title="Monthly pvt",style=plot.style_circles,


color=color.lime,linewidth=3)

plot(sm and mtime_R1 ? mtime_R1 : na, title="Monthly R1",style=plot.style_circles,


color=color.lime,linewidth=3)

plot(sm and mtime_S1 ? mtime_S1 : na, title="Monthly S1",style=plot.style_circles,


color=color.lime,linewidth=3)

plot(sm and mtime_R2 ? mtime_R2 : na, title="Monthly R2",style=plot.style_circles,


color=color.lime,linewidth=3)
plot(sm and mtime_S2 ? mtime_S2 : na, title="Monthly S2",style=plot.style_circles,
color=color.lime,linewidth=3)

You might also like