Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

unexpected result from LowestBar method

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

    unexpected result from LowestBar method

    My indicator is working with 5-minute 24/7 chart and I am trying to get the lowest low of the bars during regular trading hours only. I've tried LowestBar method but the result wasn't correct. It returns a bar that clearly doesn't have the lowest low among all the bars since the start of regular trading hours (6:35 AM bar in my time).

    My code is something like this:
    Code:
    if (IsFirstTickOfBar)
    {
          DateTime startDateTime = new DateTime(Time[0].Year, Time[0].Month, Time[0].Day, 6, 35, 0);
          int barsAgo = CurrentBar - Bars.GetBar(startDateTime);
          int lowestBarsAgo = LowestBar(Low, barsAgo);
          Print(Low[lowestBarsAgo].ToString());
    }
    I've tried similar code with HighestBar method to find the highest high and the result has always been correct. I have also tried writing my own code to get the lowest low by using a loop simply going over the Low[] for barsAgo elements and the result was correct.

    I'm wondering if there is any error with the LowestBar method.
    Thanks.

    Emilie.

    #2
    Hello emilien,

    Thanks for your post.

    We will investigate and update this thread when we have further information.

    Comment


      #3
      Hello emilien,

      The issue appears to be that the GetBar() method is returning a bar number in the future and then you are subtracting CurrentBar from a larger bar number (from the future) resulting in a negative bars ago. You then apply the negative bars ago when looking for the lowest low.

      For example when the code executes the first bar at midnight, the code gets the bar that matches that next day and the time of 6:35 AM which is 78 bars in the future. Your code then checks for the LowestBar(low, barsAgo) which in this example would be LowestBar(Low, - 78).

      Here is a modification to your code to help illustrate the issue. Blue dots will show the correct level and red dots will show the incorrect values.
      Code:
                        DateTime startDateTime = new DateTime(Time[0].Year, Time[0].Month, Time[0].Day, 6, 35, 0);
                        int barsAgo = CurrentBar - Bars.GetBar(startDateTime);                
                        int lowestBarsAgo = LowestBar(Low, barsAgo);
                      
                      if (barsAgo < 0)
                      {
                          Draw.Dot(this, "testA"+CurrentBar, true, lowestBarsAgo, Low[lowestBarsAgo], Brushes.Red);
                      }
                      else
                      {
                          Draw.Dot(this, "test"+CurrentBar, true, 0, Low[lowestBarsAgo], Brushes.Blue);
                      }

      Comment

      Latest Posts

      Collapse

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