Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

How to reference a bar by time?

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

    How to reference a bar by time?

    Is there a way to reference a bar by its time, not by bars ago?

    For instance, how would I reference the Open of the one minute bar that closed at 9:31 am?

    Problem:
    I wish to plot the 9:30 Open a horizontal line on a 1 minute chart on YM, but I am running a premarket session and CurrentOpen[0] plots the first opening price that appears on my chart and not the opening price of the regular session and I it is important to keep the premarket session.

    This is what I have now:

    DrawHorizontalLine("CurrentOpen", CurrentDayOHL().CurrentOpen[0], Color.White, DashStyle.Dot, 2);

    Any solutions?

    #2
    See GetBar()

    RayNinjaTrader Customer Service

    Comment


      #3
      Thanks Ray, I'm still new at this. This is what I came up with and works just the way I intended:

      if (ToTime(Time[0]) > 093000 &&
      ToTime(Time[
      0]) < 160000)
      {
      //set the time of 9:30 bar
      int barsAgo = CurrentBar - Bars.GetBar(new DateTime(DateTime.Now.Year, DateTime.Now.Month, DateTime.Now.Day, 9, 30, 0, 0));
      DrawHorizontalLine(
      "CurrentOpen", Open[barsAgo], Color.Magenta, DashStyle.Dot, 2);DrawText("TodaysOpen", "Today's Open", 2, Open[barsAgo]+1, Color.Magenta);}

      Comment


        #4
        Great. Glad you got it working Billy. If you have further questions feel free to ask them.
        Josh P.NinjaTrader Customer Service

        Comment

        Latest Posts

        Collapse

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