Hello, anyone able to provide the code for the pivot point “standard” indicator for the several timeframes? (daily, weekly, monthly and yearly?)
I got only the daily version:
Ht = DHigh(1)
Bs = DLow(1)
C = DClose(1)
IF dayofweek = 1 THEN
Ht = DHigh(2)
Bs = DLow(2)
C = DClose(2)
ENDIF
Pivot = (Ht + Bs + C) / 3
Res3 = Ht + ((Pivot - Bs)*2)
Res2 = Pivot + Ht - Bs
Res1 = (2 * Pivot) - Bs
Sup1 = (2 * Pivot) - Ht
Sup2 = Pivot - (Ht - Bs)
Sup3 = Bs - ((Ht-Pivot)*2)
return Pivot as "Point Pivot", Res1 as "R1", Res2 as "R2", Res3 as "R3", Sup1 as "S1", Sup2 as "S2", Sup3 as "S3"
thanks in advance for your support
JSParticipant
Senior
//Pivot calculation method
Once mode = 1
Once dailyPivot = undefined
Once dailyR1 = undefined
Once dailyS1 = undefined
Once dailyR2 = undefined
Once dailyS2 = undefined
Once dailyR3 = undefined
Once dailyS3 = undefined
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
Once lastMonthBarIndex = 0
Once monthlyHigh = undefined
Once monthlyLow = undefined
Once monthlyPivot = undefined
Once monthlyR1 = undefined
Once monthlyS1 = undefined
Once monthlyR2 = undefined
Once monthlyS2 = undefined
Once monthlyR3 = undefined
Once monthlyS3 = undefined
If Day>Day[1] then
If mode = 0 then
dailyPivot = (DHigh(1) + DLow(1) + Close[1]) / 3
Elsif mode = 1 then
dailyPivot = (Open + DHigh(1) + DLow(1) + Close[1]) / 4
Elsif mode = 2 then
dailyPivot = (DHigh(1) + DLow(1) + Close[1]*2) / 4
Else
dailyPivot = (Open*2 + DHigh(1) + DLow(1)) / 4
Endif
dailyR1 = 2*dailyPivot - DLow(1)
dailyS1 = 2*dailyPivot - DHigh(1)
dailyR2 = dailyPivot + (DHigh(1) - DLow(1))
dailyS2 = dailyPivot - (DHigh(1) - DLow(1))
dailyR3 = dailyR1 + (DHigh(1) - DLow(1))
dailyS3 = dailyS1 - (DHigh(1) - DLow(1))
Endif
If DayOfWeek<DayOfWeek[1] then
weeklyHigh = Highest[BarIndex - lastWeekBarIndex](High)[1]
weeklyLow = Lowest[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
If Month<>Month[1] then
monthlyHigh = Highest[BarIndex - lastMonthBarIndex](High)[1]
monthlyLow = Lowest[BarIndex - lastMonthBarIndex](Low)[1]
lastMonthBarIndex = BarIndex
If mode = 0 then
monthlyPivot = (monthlyHigh + monthlyLow + Close[1]) / 3
Elsif mode = 1 then
monthlyPivot = (Open + monthlyHigh + monthlyLow + Close[1]) / 4
Elsif mode = 2 then
monthlyPivot = (monthlyHigh + monthlyLow + Close[1]*2) / 4
Else
monthlyPivot = (Open*2 + monthlyHigh + monthlyLow) / 4
Endif
monthlyR1 = 2*monthlyPivot - monthlyLow
monthlyS1 = 2*monthlyPivot - monthlyHigh
monthlyR2 = monthlyPivot + (monthlyHigh - monthlyLow)
monthlyS2 = monthlyPivot - (monthlyHigh - monthlyLow)
monthlyR3 = monthlyR1 + (monthlyHigh - monthlyLow)
monthlyS3 = monthlyS1 - (monthlyHigh - monthlyLow)
Endif
JSParticipant
Senior
The above code comes from the forum by Henry.
Thank you very much JS! Unfortunately as soon as I try to draw it I got the following message:
“A positive integer field is expected with Highest”
Any suggestion?
JSParticipant
Senior
Hi @abel1986
The code is from the library and I am not familiar with Pivot’s.
I am sure @Nicolas or @Roberto will know the answer.
Solved, I should have I included: DEFPARAM CalculateOnLastBars = something…
thanks again JS
add barindex
if barindex>0 then
If Month<>Month[1] then
monthlyHigh = Highest[BarIndex - lastMonthBarIndex](High)[1]
monthlyLow = Lowest[BarIndex - lastMonthBarIndex](Low)[1]
lastMonthBarIndex = BarIndex
If mode = 0 then
monthlyPivot = (monthlyHigh + monthlyLow + Close[1]) / 3
Elsif mode = 1 then
monthlyPivot = (Open + monthlyHigh + monthlyLow + Close[1]) / 4
Elsif mode = 2 then
monthlyPivot = (monthlyHigh + monthlyLow + Close[1]*2) / 4
Else
monthlyPivot = (Open*2 + monthlyHigh + monthlyLow) / 4
Endif
monthlyR1 = 2*monthlyPivot - monthlyLow
monthlyS1 = 2*monthlyPivot - monthlyHigh
monthlyR2 = monthlyPivot + (monthlyHigh - monthlyLow)
monthlyS2 = monthlyPivot - (monthlyHigh - monthlyLow)
monthlyR3 = monthlyR1 + (monthlyHigh - monthlyLow)
monthlyS3 = monthlyS1 - (monthlyHigh - monthlyLow)
Endif
endif