Weekly High Low Open

Viewing 13 posts - 1 through 13 (of 13 total)
  • Author
    Posts
  • #97115 quote
    Seb
    Participant
    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?

    #97116 quote
    Vonasi
    Moderator
    Master
    #97117 quote
    robertogozzi
    Moderator
    Master

    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
    #97125 quote
    Seb
    Participant
    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.

    #97129 quote
    robertogozzi
    Moderator
    Master

    Do you have end-0f-day data?

    In this case your data is one week old.

    #97130 quote
    Seb
    Participant
    Average

    No, it’s intraday data from IG’s CFD’s

    #97133 quote
    Vonasi
    Moderator
    Master

    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.

    #97134 quote
    Vonasi
    Moderator
    Master

    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.

    #97135 quote
    Seb
    Participant
    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

    #97136 quote
    robertogozzi
    Moderator
    Master

    Try

    If OpenDayOfWeek = 7 and OpenDayOfWeek <> OpenDayOfWeek[1] then

    but as soon as at PRT they fix the issue it will change.

    #97137 quote
    Seb
    Participant
    Average

    Many thanks Roberto!, that works

    #97138 quote
    Vonasi
    Moderator
    Master

    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.

    #97139 quote
    Vonasi
    Moderator
    Master

    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!

Viewing 13 posts - 1 through 13 (of 13 total)
  • You must be logged in to reply to this topic.

Weekly High Low Open


ProOrder: Automated Strategies & Backtesting

New Reply
Author
author-avatar
Seb @seb Participant
Summary

This topic contains 12 replies,
has 3 voices, and was last updated by Vonasi
6 years, 10 months ago.

Topic Details
Forum: ProOrder: Automated Strategies & Backtesting
Language: English
Started: 04/25/2019
Status: Active
Attachments: No files
Logo Logo
Loading...