Capture yesterday high low

Viewing 14 posts - 1 through 14 (of 14 total)
  • Author
    Posts
  • #97279 quote
    BC
    Participant
    Master

    I want to capture yesterday (9:15 – 16:30) high low and show on today chart, but my code didn’t show correctly, what I did wrong?

     

    Once StartTime = 91500
    Once EndTime = 163000
    
    
    If Time >= StartTime and Time <= EndTime then
    
    If Time = StartTime then
    DailyHigh = High
    DailyLow = Low
    Endif
    
    If High > DailyHigh then
    DailyHigh = High
    Endif
    
    If Low < DailyLow then
    DailyLow = Low
    Endif
    
    Endif
    
    
    return DailyHigh[1], DailyLow[1]
    Picture1.png Picture1.png Yesterday-High-Low-9_15-16_30.itf
    #97283 quote
    Vonasi
    Moderator
    Master

    You need to store yesterdays value before resetting and looking for todays value.

    Once StartTime = 91500
    Once EndTime = 163000
     
     
    If Time >= StartTime and Time <= EndTime then
     
    If Time = StartTime then
    YesterdaysHigh = DailyHigh
    YesterdaysLow = DailyLow
    DailyHigh = High
    DailyLow = Low
    Endif
     
    If High > DailyHigh then
    DailyHigh = High
    Endif
     
    If Low < DailyLow then
    DailyLow = Low
    Endif
     
    Endif
     
    return YesterdaysHigh, YesterdaysLow

    You could also use MAX and MIN instead of all the IF  and THEN’s.

    Once StartTime = 91500
    Once EndTime = 163000
     
     
    If Time >= StartTime and Time <= EndTime then
     
    If Time = StartTime then
    YesterdaysHigh = DailyHigh
    YesterdaysLow = DailyLow
    DailyHigh = High
    DailyLow = Low
    Endif
     
    DailyHigh = max(high,DailyHigh)
    DailyLow = min(low,Dailylow)
     
    Endif
     
    return YesterdaysHigh, YesterdaysLow
    #97286 quote
    BC
    Participant
    Master

    Vonasi

    It works! Thanks a lot.

    #110619 quote
    BC
    Participant
    Master

    Hi PRT Master

     

    I stuck again on how to capture last week (9:15 – 16:30) high low, anyone can help?

     

    Thanks

    #110623 quote
    Vonasi
    Moderator
    Master

    Try this:

    StartTime = 091500
    EndTime = 163000
    
    once LastWeeksHigh = undefined
    once LastWeeksLow = undefined
     
    if opendayofweek < opendayofweek[1] then
    LastWeeksHigh = DailyHigh
    LastWeeksLow = DailyLow
    firsttime = 0
    endif
    
    If not firsttime and Time = StartTime then
    DailyHigh = High
    DailyLow = Low
    firsttime = 1
    endif
    
    if firsttime and Time >= StartTime and Time <= EndTime then
    DailyHigh = max(high,DailyHigh)
    DailyLow = min(low,Dailylow)
    Endif
     
    return LastWeeksHigh, LastWeeksLow
    

    EDIT : Code corrected 20191021

    BC thanked this post
    Screenshot_10.png Screenshot_10.png
    #110635 quote
    BC
    Participant
    Master

    Million Thanks, Vonasi.

    #110719 quote
    BC
    Participant
    Master

    Hi Vonasi

     

    I just test the code, but the output not same as your screen cap.

     

    BC

    Test10-21-A.png Test10-21-A.png
    #110721 quote
    BC
    Participant
    Master

    Hi Vonasi

     

    I found where is the problem, should use OpenDayOfWeek command instead of OpenDay.

     

    Thanks

    #110731 quote
    Vonasi
    Moderator
    Master

    Sorry about that – not sure how that typo got in there! I’ll edit the code in my post to correct it.

    #111245 quote
    BC
    Participant
    Master

    Hi Vonasi

     

    I stuck again on capture last X week high low within 9:15-16:00, can you help?

     

    Thanks

    #111256 quote
    Vonasi
    Moderator
    Master

    By X do you mean you want the high and low between 0915 and 1600 for the week X weeks ago or do you mean you want them for the last X weeks all included?

    #111257 quote
    BC
    Participant
    Master

    High and low between 0915 and 1600 for the week X weeks ago, eg: 10 weeks ago.

     

    Thanks

    #111261 quote
    Vonasi
    Moderator
    Master

    This code will do that – but be warned it is very slow to draw due to the loop.

    StartTime = 091500
    EndTime = 160000
    
    once myWeeksHigh = undefined
    once myWeeksLow = undefined
     
    if opendayofweek < opendayofweek[1] then
    firsttime = 0
    endif
    
    If not firsttime and Time = StartTime then
    myWeeksHigh = DailyHigh
    myWeeksLow = DailyLow
    weekindex = weekindex + 1
    DailyHigh = High
    DailyLow = Low
    firsttime = 1
    endif
    
    if firsttime and openTime >= StartTime and opentime < EndTime then
    DailyHigh = max(high,DailyHigh)
    DailyLow = min(low,Dailylow)
    endif
    
    if weekindex > lookback then
    for j = 1 to barindex
    if WeekIndex[j] = WeekIndex - lookback then
    myweekshigh = Dailyhigh[j]
    myweekslow = Dailylow[j]
    break
    endif
    next
    endif
     
    return myWeeksHigh, MyWeeksLow
    robertogozzi thanked this post
    #111305 quote
    BC
    Participant
    Master

    Thanks Vonasi.

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

Stuck on this ProBuilder code?

Describe what this topic is trying to build, in plain English, and ProRealAI writes the ProRealTime™ indicator, screener or system for you.

Available in 7 languages
Try ProRealAI

Capture yesterday high low


ProBuilder: Indicators & Custom Tools

New Reply
Author
author-avatar
BC @robin_chan Participant
Summary

This topic contains 13 replies,
has 2 voices, and was last updated by BC
6 years, 10 months ago.

Topic Details
Forum: ProBuilder: Indicators & Custom Tools
Language: English
Started: 04/28/2019
Status: Active
Attachments: 4 files
Logo Logo
Loading...