//---------------------------------------------------------------//
//-----Pivot calculation method----------------------------------//
//---------------------------------------------------------------//
Once mode = 0
//---------------------------------------------------------------//
Once lastWeekBarIndex = 0
Once weeklyHigh = undefined
Once weeklyLow = undefined
Once weeklyPivot = undefined
Once weeklyR1 = undefined
Once weeklyS1 = undefined
Once weeklyR2 = undefined
Once weeklyS2 = undefined
Once weeklyR3 = undefined
Once weeklyS3 = undefined
//---------------------------------------------------------------//
//-----Weekly Pivot Points Calculation---------------------------//
//---------------------------------------------------------------//
If DayOfWeek<DayOfWeek[1] then
weeklyHigh = Highest[max(1,BarIndex - lastWeekBarIndex)](High)[1]
weeklyLow = Lowest[max(1,BarIndex - lastWeekBarIndex)](Low)[1]
lastWeekBarIndex = BarIndex
If mode = 0 then
weeklyPivot = (weeklyHigh + weeklyLow + Close[1]) / 3
Elsif mode = 1 then
weeklyPivot = (Open + weeklyHigh + weeklyLow + Close[1]) / 4
Elsif mode = 2 then
weeklyPivot = (weeklyHigh + weeklyLow + Close[1]*2) / 4
Else
weeklyPivot = (Open*2 + weeklyHigh + weeklyLow) / 4
Endif
weeklyR1 = 2*weeklyPivot - weeklyLow
weeklyS1 = 2*weeklyPivot - weeklyHigh
weeklyR2 = weeklyPivot + (weeklyHigh - weeklyLow)
weeklyS2 = weeklyPivot - (weeklyHigh - weeklyLow)
weeklyR3 = weeklyR1 + (weeklyHigh - weeklyLow)
weeklyS3 = weeklyS1 - (weeklyHigh - weeklyLow)
Endif
//---------------------------------------------------------------//
//-----Plot Pivot Points-----------------------------------------//
//---------------------------------------------------------------//
if islastbarupdate then
drawtext("Piv.W R3: #weeklyR3#",barindex+10,weeklyR3)coloured("red")
drawtext("Piv.W R2: #weeklyR2#",barindex+10,weeklyR2)coloured("red")
drawtext("Piv.W R1: #weeklyR1#",barindex+10,weeklyR1)coloured("red")
drawtext("Piv.W: #weeklyPivot#",barindex+10,weeklyPivot)coloured("blue")
drawtext("Piv.W S1: #weeklyS1#",barindex+10,weeklyS1)coloured("green")
drawtext("Piv.W S2: #weeklyS2#",barindex+10,weeklyS2)coloured("green")
drawtext("Piv.W S3: #weeklyS3#",barindex+10,weeklyS3)coloured("green")
endif
Return weeklyPivot as "Weekly P"coloured("blue")style(dottedline,2), weeklyR1 as "Weekly R1"coloured("red")style(dottedline,2), weeklyS1 as "Weekly S1"coloured("green")style(dottedline,2), weeklyR2 as "Weekly R2"coloured("red")style(dottedline,2), weeklyS2 as "Weekly S2"coloured("green")style(dottedline,2), weeklyR3 as "Weekly R3"coloured("red")style(dottedline,2), weeklyS3 as "Weekly S3"coloured("green")style(dottedline,2)