Retrieve highs and lows for a time period

Viewing 3 posts - 1 through 3 (of 3 total)
  • Author
    Posts
  • #15984 quote
    rvee
    Participant
    New

    G’day,

    I am looking for a way to retrieve the highs and lows that occur between a period of time. There are few theories that I would like to test using this data.

    My broker offers only PRT 10.2 – I’ve read through the documentation and am unable find a way that would allow me to

    1.  Cycle through a time period, say 9 to 5 and on 5 minute chart and retrieve the OHLC value just for this period
    2. Optionally return a pivot line of some sort with the midpoint calculated using data in #1
    3. Calculate standard deviations, moving averages etc only using data from this period.

    In essence, I would like to be able to segregate price movements that occur over different time periods and apply standard indicators to test strategies.

    Any help or nudge in the right direction would be much appreciated. Thank you!

    #16023 quote
    Wing
    Participant
    Veteran

    You can do this I think. If not by changing your chart time settings, by code.

    1. To cycle through only a set time period on the intraday chart, to find the day’s current high for example, after 9 am before 5 pm.
      once DailyHigh=0
      
      if time=090000 then
      dailyhigh=high
      endif
      
      if time>=090000 and time<=170000 and high>dailyhigh then
      dailyhigh=high
      endif
      
      return high
      
    2.  Midpoint would just be average, between high point as explained above and low point retrieved through same method.
    3.  To calculate moving averages etc., you are in a more tricky situation. You will need to write code that alters the return of the standard indicators. A serious problem with PRT is that you cannot make your own arrays, you can only use built in arrays. However, you can make this work. I took your question as a challenge and made a simple moving average that takes into account what happened only upto 170000 yesterday when showing the morning’s moving average. From 170000 to 090000 it just shows normal moving average, not using custom time. Try it out:
    myperiod=20
    
    
    once dailybardiff=1
    period=myperiod
    once currperiod=1
    once lastrealbar=0
    once startbar=0
    final=average[myperiod]
    
    if currperiod<=period and currperiod>=0 then
    mm=summation[dailybardiff](close)
    mm2=summation[dailybardiff+(period-currperiod-1)](close)
    endif
    
    if time=090000 then
    startbar=intradaybarindex
    dailybardiff=barindex-lastrealbar
    endif
    
    
    if time>=090000 and time<=1700000 then
    currperiod=intradaybarindex-startbar
    if currperiod>period then
    currperiod=period
    endif
    if currperiod<period and currperiod>0 then
    firstadd=summation[currperiod](close)
    final=(mm2-mm+firstadd)/(period)
    endif
    endif
    
    if time=170000 then
    lastrealbar=barindex
    endif
    
    return final
    

    Note that this was done in a hurry, but I hope it answers your questions.

    dakaodo thanked this post
    #32815 quote
    dakaodo
    Participant
    Junior

    Hello, Wing!

    Thank you for the initial bit of code to delimit times within a day. B/c of that, I was able to quickly replicate it 6 times to mark session highs and lows for NYC, London, and Tokyo. The user will have to set his own colors/line styles to differentiate them, but this was the fastest (15 mins) I’ve ever conceptualized and finished an indicator! 😀

    I have two observations/questions:

    I had to kludge the Tokyo session with two separate IF statements for each of high and low, where NYC and London only need one for high and one for low, to account for daily rollover at my local midnight. You can see the commented-out prior attempt with an OR condition to account for the daily rollover (didn’t work). Other users will have to enter in their local times for the three market sessions, and adjust accordingly. Is there a more elegant way to do this?

    This indicator freaks out and does not display correctly when I switch to tick charts. I had a similar problem for a previous indicator. Is there a way to account for the difference in ??? timestamp data, duration of bars, I don’t know what, etc.?

    The indicator works well enough for any minute/hour chart, so I am putting this open question out for the sake of learning better scripting/coding.

    once NYCHi=0
    once TOKHi=0
    once LONHi=0
    once NYClo=0
    once TOKlo=0
    once LONlo=0
    
    if time=070000 then
    NYChi=high
    NYClo=low
    endif
    
    if time>=070000 and time<=160000 and high>NYChi then
    NYChi=high
    endif
    
    if time>=070000 and time<=160000 and low<NYClo then
    NYClo=low
    endif
    
    if time=010000 then
    LONhi=high
    LONlo=low
    endif
    
    if time>=010000 and time<=070000 and high>LONhi then
    LONhi=high
    endif
    
    if time>=010000 and time<=070000 and low<LONlo then
    LONlo=low
    endif
    
    if time=180000 then
    TOKhi=high
    TOKlo=low
    endif
    
    if time>=180000 and time <=235959 and high>TOKhi then
    //if time>=180000 or time <=010000 and high>TOKhi then
    TOKhi=high
    endif
    
    if time>=000000 and time <=010000 and high>TOKhi then
    //if time>=180000 or time <=010000 and high>TOKhi then
    TOKhi=high
    endif
    
    if time>=180000 and time <=235959 and low<TOKlo then
    //if time>=180000 or time <=010000 and low<TOKlo then
    TOKlo=low
    endif
    
    if time>=000000 and time <=010000 and low<TOKlo then
    //if time>=180000 or time <=010000 and low<TOKlo then
    TOKlo=low
    endif
    
    return NYChi as "NYC high", LONhi as "LON high", TOKhi as "TOK high", NYClo as "NYC low", LONlo as "LON low", TOKlo as "TOK low"
Viewing 3 posts - 1 through 3 (of 3 total)
  • You must be logged in to reply to this topic.

Retrieve highs and lows for a time period


ProScreener: Market Scanners & Detection

New Reply
Author
author-avatar
rvee @rvee Participant
Summary

This topic contains 2 replies,
has 3 voices, and was last updated by dakaodo
8 years, 10 months ago.

Topic Details
Forum: ProScreener: Market Scanners & Detection
Language: English
Started: 11/05/2016
Status: Active
Attachments: No files
Logo Logo
Loading...