Hello,
I’m currently building a strategy based on different kind of pivot points. In my testing I’m using a modified version of this indicator; http://www.prorealcode.com/prorealtime-indicators/daily-weekly-monthly-pivot-points/#comment-1059 . I though run into problems using the monthly pivot points in different ways. I’ll give you an example bellow;
DEFPARAM CUMULATEORDERS = FALSE
//
Once lastMonthBarIndex = 0
Once monthlyHigh = undefined
Once monthlyLow = undefined
Once monthlyPivot = undefined
If Month<>Month[1] then
monthlyHigh = Highest[BarIndex - lastMonthBarIndex](High)[1]
monthlyLow = Lowest[BarIndex - lastMonthBarIndex](Low)[1]
lastMonthBarIndex = BarIndex
monthlyPivot = (close[1] + monthlyHigh + monthlyLow) / 3
Endif
MM1 = AVERAGE[7](CLOSE)
//
C1 = MM1 CROSSES OVER MONTHLYPIVOT
IF NOT LONGONMARKET AND C1 THEN
BUY 1 CONTRACTS AT MARKET
SET STOP %LOSS 2
SET TARGET %PROFIT 5
ENDIF
This is just an example of what kind of strategy I’m trying to achieve. I can’t though see what I’m doing wrong here?
Help much appreciated!
What is the problem you encountered with this trading strategy? No trades are initiated?
Obs sorry, forgot to mention the problem. Exactly, no trades were initiated and i can’t seem to understand why. Any clue?
Try to change the line 23 with this (not tested) :
C1 = MM1 CROSSES OVER MONTHLYPIVOT[1]
Did not work unfortunetly, no trades initiated.
I’ve also tried other approaches with the monthly pivot code. But nothing seems to work. For example; when the weekly pivot < monthly pivot and bla bla bla, then buy 1 contracts at market. Doesn’t work.
This is the fixed code:
DEFPARAM CUMULATEORDERS = FALSE
defparam preloadbars = 20000
Once lastMonthBarIndex = 0
If Month <> Month[1] then
monthlyHigh = Highest[BarIndex - lastMonthBarIndex](DHigh(1))
monthlyLow = Lowest[BarIndex - lastMonthBarIndex](DLow(1))
lastMonthBarIndex = BarIndex
monthlyPivot = (Dclose(1) + monthlyHigh + monthlyLow) / 3
ENDIF
MM1 = AVERAGE[7](CLOSE)
GRAPH monthlypivot
GRAPH lastmonthBarIndex
C1 = MM1 CROSSES OVER MONTHLYPIVOT
IF NOT LONGONMARKET AND C1 THEN
BUY 1 CONTRACTS AT MARKET
SET STOP %LOSS 2
SET TARGET %PROFIT 5
ENDIF
Your calculation of the monthly pivot were not good because you took the actual timeframe OHLC, which should be the Daily one that you can retrieve with DOPEN/DHIGH/DLOW/DCLOSE. I also add some bars to be preloaded in case it is needed.
Thank you Nicolas, i appreciate this! 🙂
Hi Guys
I’m struggling with my monthly and weekly pivots. This is my code (PS – I’m not really following the logic. Just copying and trying to adjust here and there):
Once lastMonthBarIndex = 0
If Month <> Month[1] then
monthlyHigh = Highest[BarIndex - lastMonthBarIndex](DHigh(1))
monthlyLow = Lowest[BarIndex - lastMonthBarIndex](DLow(1))
lastMonthBarIndex = BarIndex
monthlyPivot = (Dclose(1) + monthlyHigh + monthlyLow) / 3
ENDIF
return monthlyPivot as "MPivot"
However, my last month data is as follows:
MHigh = 47144
MLow = 44802
MClose = 46201
MOpen = 46201
If I use the classic pivot calculation of (last month high + last month low + last month close) / 3 I get 46049. However the system shows a pivot of 46253? Why would it differ? How can I fix it please?
Thanks and regards
Maybe you can try first to see what values are returned by the calculation of the code and find how and why they are the ones actually calculated by it.
return monthlyPivot as "MPivot", monthlyHigh as "high", monthlylow as "low", Dclose(1) as "monthly close"