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 sjsj2732, Yesterday, 04:31 AM
        0 responses
        35 views
        0 likes
        Last Post sjsj2732  
        Started by NullPointStrategies, 03-13-2026, 05:17 AM
        0 responses
        287 views
        0 likes
        Last Post NullPointStrategies  
        Started by argusthome, 03-08-2026, 10:06 AM
        0 responses
        286 views
        0 likes
        Last Post argusthome  
        Started by NabilKhattabi, 03-06-2026, 11:18 AM
        0 responses
        133 views
        1 like
        Last Post NabilKhattabi  
        Started by Deep42, 03-06-2026, 12:28 AM
        0 responses
        95 views
        0 likes
        Last Post Deep42
        by Deep42
         
        Working...
        X