SebParticipant
Average
Hello, I’m trying to get the last week’s high,low & open.
I tried it with this code, that works as an indicator, but if I use the graph functionality in ProRealCode, the levels are incorrect.
x = abs(round(count[1]))+1
highestWeek = highest[x](high)
lowestWeek = lowest[x](low)
openWeek1 = open[x-1]
if openhour[1] <> openhour then
dag = day
endif
count = count[1] + 1
if dag <> dag[1] then
nieuweDag = 1
else
nieuweDag = 0
endif
if (dayofweek = 1 and nieuweDag) or (dayofweek[1] = 5 and dayofweek <> 5 and nieuweDag) then
count = 1
highWeek = highestWeek[1]
lowWeek = lowestWeek[1]
openWeek = openWeek1
endif
return highweek,lowWeek,openWeek
how to get last week’s high,low and open in ProRealCode?
I just coded this (not tested):
If OpenDayOfWeek = 1 and OpenDayOfWeek <> OpenDayOfWeek[1] then
openWeek = open
highestWeek = 0
lowestWeek = 999999
Endif
highestWeek = max(highestWeek,high)
lowestWeek = min(lowestWeek,low)
return highweek,lowWeek,openWeek
SebParticipant
Average
For some reason ProRealCode looks at other data or something. If I use your code the same happens as with mine; the levels are different. For example the high of 2 weeks ago in crude oil is 6350.2 instead of 6335.9 if I use the graph functionality in ProRealCode.
Do you have end-0f-day data?
In this case your data is one week old.
SebParticipant
Average
No, it’s intraday data from IG’s CFD’s
I’m guessing that it is different because week candles start on from a Sunday open and not on a Monday. This is why I used this in my indicators:
if opendayofweek < opendayofweek[1] then
With this Sunday open is used but if there is no Sunday or no Monday candle then Tuesday is used. It is very unlikely that one week ends on a Friday and the next trading candle is the next Friday so this should work fine.
Roberto and I noticed recently that in a strategy opendayofweek and dayofweek for a Sunday is the value 7 whereas in an indicator it is 0. Nicolas has reported it to PRT and we wait to see if they make some changes or whether we have to code around this.
SebParticipant
Average
That is not the problem, I use this part of your code:
if opendayofweek < opendayofweek[1] then
weekindex = weekindex + 1
weekhigh = 0
weeklow = close
weekopen = open
if weekindex > 1 then
for j = 1 to barindex
if weekindex[j] = weekindex - 1 then
myweekhigh = weekhigh[j]
myweeklow = weeklow[j]
myweekopen = weekopen[j]
break
endif
next
endif
endif
weekhigh = max(weekhigh,high)
weeklow = min(weeklow,low)
graph myweeklow
graph myweekhigh
graph myweekopen
If you have a CFD account, you can look at the ‘last week’s high’, 2 weeks ago in US crude to see that it’s off
Try
If OpenDayOfWeek = 7 and OpenDayOfWeek <> OpenDayOfWeek[1] then
but as soon as at PRT they fix the issue it will change.
SebParticipant
Average
Many thanks Roberto!, that works
I just ran that code as an indicator and compared it to the weekly candles on the EURUSD (the chart I happened to have open) and the values were identical to last weeks weekly candle.
I just realised that the code you wrote was part of a strategy and not an indicator which is why Roberto’s solution fixes it. It is a 7 zero issue!