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 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.
        BertrandNinjaTrader Customer Service

        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
            BertrandNinjaTrader Customer Service

            Comment

            Latest Posts

            Collapse

            Topics Statistics Last Post
            Started by suroot, 02-25-2017, 04:43 AM
            11 responses
            2,546 views
            0 likes
            Last Post Zilvercat  
            Started by Rogers101, 05-05-2024, 11:30 AM
            16 responses
            50 views
            0 likes
            Last Post Rogers101  
            Started by ninza33, Today, 12:31 PM
            2 responses
            9 views
            0 likes
            Last Post ninza33
            by ninza33
             
            Started by Bobin, 03-12-2024, 08:51 AM
            15 responses
            481 views
            0 likes
            Last Post fiddich
            by fiddich
             
            Started by Skifree, Today, 11:21 AM
            4 responses
            15 views
            0 likes
            Last Post Skifree
            by Skifree
             
            Working...
            X