Professional Documents
Culture Documents
// User inputs
showTomorrowCPR = input(title="Show tomorrow's CPR", type=input.bool, defval=true)
showHistoricalCPR = input(title="Show historical CPR", type=input.bool,
defval=false)
showR3S3 = input(title="Show R3 & S3", type=input.bool, defval=false)
// Defaults
// CPR Colors
cprColor = color.purple
rColor = color.red
sColor = color.green
//Fill Transparency
fTransp = 95
// Global Functions
// TODO : Update the list of Holiday here in format YYYY, MM, DD, 09, 15
// **09, 15 are session start hour & minutes
IsHoliday(_date) =>
iff(_date == timestamp(2020, 02, 21, 09, 15), true,
iff(_date == timestamp(2020, 03, 10, 09, 15), true,
iff(_date == timestamp(2020, 04, 02, 09, 15), true,
iff(_date == timestamp(2020, 04, 06, 09, 15), true,
iff(_date == timestamp(2020, 04, 10, 09, 15), true,
iff(_date == timestamp(2020, 04, 14, 09, 15), true,
iff(_date == timestamp(2020, 05, 01, 09, 15), true,
iff(_date == timestamp(2020, 05, 25, 09, 15), true,
iff(_date == timestamp(2020, 10, 02, 09, 15), true,
iff(_date == timestamp(2020, 11, 16, 09, 15), true,
iff(_date == timestamp(2020, 11, 30, 09, 15), true,
iff(_date == timestamp(2020, 12, 25, 09, 15), true,
false))))))))))))
// Skip Weekend
SkipWeekend(_date) =>
_d = dayofweek(_date)
_mul = _d == 6 ? 3 : _d == 7 ? 2 : 1
for i = 1 to noOfHolidays
if IsHoliday(_dt)
_dt := SkipWeekend(_dt)
continue
else
break
_dt
tom_start = start
tom_end = end
// Get series
getSeries(e, timeFrame) => security(syminfo.tickerid, "D", e,
lookahead=barmerge.lookahead_on)
// Pivot Range
P = (H + L + C) / 3
TC = (H + L)/2
BC = (P - TC) + P
// Resistance Levels
R3 = H + 2*(P - L)
R2 = P + (H - L)
R1 = (P * 2) - L
// Support Levels
S1 = (P * 2) - H
S2 = P - (H - L)
S3 = L - 2*(H - P)
// Plot Today's CPR
if not(IsHoliday(start)) and not(IsWeekend(start)) and shouldPlotToday
if showR3S3
_r3 = line.new(start, R3, end, R3, xloc.bar_time, color=color.new(rColor,
lTransp))
line.delete(_r3[1])
_r2 = line.new(start, R2, end, R2, xloc.bar_time, color=color.new(rColor,
lTransp))
line.delete(_r2[1])
_r1 = line.new(start, R1, end, R1, xloc.bar_time, color=color.new(rColor,
lTransp))
line.delete(_r1[1])
// Pivot Range
tP = (tH + tL + tC) / 3
tTC = (tH + tL)/2
tBC = (tP - tTC) + tP
// Resistance Levels
tR3 = tH + 2*(tP - tL)
tR2 = tP + (tH - tL)
tR1 = (tP * 2) - tL
// Support Levels
tS1 = (tP * 2) - tH
tS2 = tP - (tH - tL)
tS3 = tL - 2*(tH - tP)