Announcement

Collapse

Looking for a User App or Add-On built by the NinjaTrader community?

Visit NinjaTrader EcoSystem and our free User App Share!

Have a question for the NinjaScript developer community? Open a new thread in our NinjaScript File Sharing Discussion Forum!
See more
See less

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.
    Paul H.NinjaTrader Customer Service

    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);
                      }
      Paul H.NinjaTrader Customer Service

      Comment

      Latest Posts

      Collapse

      Topics Statistics Last Post
      Started by swestendorf, Today, 11:14 AM
      2 responses
      5 views
      0 likes
      Last Post NinjaTrader_Kimberly  
      Started by xiinteractive, 04-09-2024, 08:08 AM
      4 responses
      12 views
      0 likes
      Last Post xiinteractive  
      Started by Mupulen, Today, 11:26 AM
      0 responses
      1 view
      0 likes
      Last Post Mupulen
      by Mupulen
       
      Started by Sparkyboy, Today, 10:57 AM
      1 response
      5 views
      0 likes
      Last Post NinjaTrader_Jesse  
      Started by TheMarlin801, 10-13-2020, 01:40 AM
      21 responses
      3,917 views
      0 likes
      Last Post Bidder
      by Bidder
       
      Working...
      X