Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

How do I get the value of a bar at a specific time

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

    How do I get the value of a bar at a specific time

    I want to make a strategies that are based off the certain times of the trading day.

    How can I get the opening value of the 6:30am bar?

    #2
    Please use GetBar().
    Josh P.NinjaTrader Customer Service

    Comment


      #3
      thanks. i see how that works now, but i'm trying to put it all together.

      in this code sample, i'd like to get the difference between the 7:30 opening bar, and the 7:36 opening bar.

      the problem is that my openPrice and the thirtySixPrice is the same.

      for testing, i ran a backtest on a 1 minute frequency for the previous week.

      Code:
      if (ToTime(Time[0]) >= 73600 && ToTime(Time[0]) < 73700) // ToTime(7, 30, 00))
      {
         int barsAgoOpen = GetBar(new DateTime(DateTime.Now.Year, DateTime.Now.Month, DateTime.Now.Day, 7, 30, 0));
         int barsAgoThirtySix = GetBar(new DateTime(DateTime.Now.Year, DateTime.Now.Month, DateTime.Now.Day, 7, 36, 0));
                      
         double thirtySixPrice = Open[barsAgoThirtySix];
         double openPrice = Open[barsAgoOpen];
                      
        Print(Time[0].DayOfWeek+" "+openPrice+" "+thirtySixPrice);
      
      }
      my output:
      Code:
      Monday 921.5 921.5
      Tuesday 921 921
      Wednesday 901.5 901.5
      Thursday 914.5 914.5
      Friday 920.25 920.25

      Comment


        #4
        Please also print what your two int variables returning as found barnumber ago, maybe your 1 min time window for the check is too limiting on a 1 min chart.

        Comment


          #5
          you're right. my barsAgoOpen is always 0. when i increase the time window, it just prints the exact same data for the number of minutes of that window.

          are there any ninjascript examples to reference? i've imported a couple from the resource link, but none do what i'm trying to accomplish.

          i.e. calculate the difference between minute bars 7:30 and 7:36 and then execute a trade based on that. (obviously the logic wouldn't be that simple, but that would get me to the next step)

          Comment


            #6
            Unfortunately I'm not aware any sample more specific than this one - http://www.ninjatrader-support2.com/...ead.php?t=8600

            Comment

            Latest Posts

            Collapse

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