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

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 andrewtrades, Today, 04:57 PM
        1 response
        8 views
        0 likes
        Last Post NinjaTrader_Manfred  
        Started by chbruno, Today, 04:10 PM
        0 responses
        6 views
        0 likes
        Last Post chbruno
        by chbruno
         
        Started by josh18955, 03-25-2023, 11:16 AM
        6 responses
        436 views
        0 likes
        Last Post Delerium  
        Started by FAQtrader, Today, 03:35 PM
        0 responses
        7 views
        0 likes
        Last Post FAQtrader  
        Started by rocketman7, Today, 09:41 AM
        5 responses
        19 views
        0 likes
        Last Post NinjaTrader_Jesse  
        Working...
        X