Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Locking in HIGH & LOW values in the First Hour

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

    Locking in HIGH & LOW values in the First Hour

    Hi - I searched but didn't see a solution, could you help?
    I successfully draw HIGH and LOW lines during the 1st hour of trading, but I desire to make Fib lines, etc. based on the information. However, the DataSeries is somehow modified after the 1st hour. Here is the code...why is it losing values?

    // count the bars during the first hour
    if ((ToTime(Time[0]) >= 093000) && (ToTime(Time[0]) <= 103100)) {
    if(FirstTickOfBar) {
    yFirstHourBarCount.Set(yFirstHourBarCount[1] + 1); }
    }
    // calculate the High and Low; Draw lines
    if ((ToTime(Time[0]) >= 093000) && (ToTime(Time[0]) <= 103100)) {
    int iBarCount = (int)yFirstHourBarCount[0];
    double mHigh = MAX(High,iBarCount)[0];
    double mLow = MIN(Low,iBarCount)[0];
    yHigh1Hour.Set(mHigh);
    yLow1Hour.Set(mLow);
    DrawHorizontalLine("firstHourHigh",…); //Works OK
    DrawHorizontalLine("firstHourLow",…); // Works OK
    }
    There are 3 DataSeries here: "yFirstHourBarCount", "yHigh1Hour", and "yLow1Hour." in particular, I think it is a problem with losing the bar count value.
    Thanks in advance for your help!

    #2
    Julie, the values are not lost but you're essentially not setting them with values outside those marked ours, so there would be no values found. If you'd like to persist them just set the dataseries outside those hours with the previous series values so you can refer to them later on in the day as well for your calcs.

    Comment


      #3
      Thanks Bertrand,
      But I seem to be missing something here (again) – I tried but it doesn’t work.
      In today’s trading there were 20 tick bars in the first hour. I transferred the value in my “yHigh1Hour” DataSeries to my “yHighHold” DataSeries, and successfully held the proper value during the first 20 bars only, but immediately thereafter the value was Zero. To test what is happening, I have a print statement: Print(yHighHold[0]) which shows ZERO after the first 20 bars.
      The code I used was placed outside and below the “if(ToTime)” statement – the exact code I used was:

      yHighHold.Set(yHigh1Hour[0]);

      Still stumped, . . . Thanks,
      Jules

      Comment


        #4
        Julie, you cannot refer to index value 0 here in this call -

        yHighHold.Set(yHigh1Hour[0]);

        As this would just be the current bar for which you don't have a value set then, I would refer to index [1] here to store the last set value of the previous bars then in your 'hold' series to persist.

        Comment


          #5
          Originally posted by JulieC View Post
          Thanks Bertrand,
          But I seem to be missing something here (again) – I tried but it doesn’t work.
          In today’s trading there were 20 tick bars in the first hour. I transferred the value in my “yHigh1Hour” DataSeries to my “yHighHold” DataSeries, and successfully held the proper value during the first 20 bars only, but immediately thereafter the value was Zero. To test what is happening, I have a print statement: Print(yHighHold[0]) which shows ZERO after the first 20 bars.
          The code I used was placed outside and below the “if(ToTime)” statement – the exact code I used was:

          yHighHold.Set(yHigh1Hour[0]);

          Still stumped, . . . Thanks,
          Jules
          Hardly necessary. All that you have to do is move these lines outside the time filter block.
          Code:
          [FONT=Courier New]yHigh1Hour.Set(mHigh);[/FONT]
          [FONT=Courier New][COLOR=black]yLow1Hour.Set(mLow); [/COLOR][/FONT]
          [FONT=Courier New]DrawHorizontalLine([COLOR=maroon]"firstHourHigh"[/COLOR][/FONT][COLOR=black][FONT=Courier New],…); //Works OK [/FONT][/COLOR]
          [COLOR=black][FONT=Courier New]DrawHorizontalLine([/FONT][/COLOR][COLOR=maroon][FONT=Courier New]"firstHourLow"[/FONT][/COLOR][COLOR=black][FONT=Courier New],[/FONT][/COLOR][COLOR=blue][FONT=Courier New]…)[/FONT][/COLOR][COLOR=black][FONT=Courier New]; // Works OK [/FONT][/COLOR]

          Comment


            #6
            Thank you!
            I finally got it (i'm slow, took hours to figure it out).

            Koganam, there must be an easier way, as you suggest, but when I moved the code lines outside the time filter block, the error message was "mHigh does not exist."

            Eventually I was able to get Bertrand's recommendation to work . . . it was a case of exactly WHEN to capture and set the value.

            Thanks again,
            Jules

            Comment

            Latest Posts

            Collapse

            Topics Statistics Last Post
            Started by Geovanny Suaza, 02-11-2026, 06:32 PM
            0 responses
            603 views
            0 likes
            Last Post Geovanny Suaza  
            Started by Geovanny Suaza, 02-11-2026, 05:51 PM
            0 responses
            349 views
            1 like
            Last Post Geovanny Suaza  
            Started by Mindset, 02-09-2026, 11:44 AM
            0 responses
            104 views
            0 likes
            Last Post Mindset
            by Mindset
             
            Started by Geovanny Suaza, 02-02-2026, 12:30 PM
            0 responses
            560 views
            1 like
            Last Post Geovanny Suaza  
            Started by RFrosty, 01-28-2026, 06:49 PM
            0 responses
            560 views
            1 like
            Last Post RFrosty
            by RFrosty
             
            Working...
            X