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

Reference a bar from a specific time of day?

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

    Reference a bar from a specific time of day?

    Hello,

    How would I get a reference to a specific candle at a specific time of day? For instance say I wanted to reference the 11:35 am candle of an intra-day 5 minute chart - how would I do that?

    Thank you,

    -Alli

    #2
    Allistah, there is a built-in method that will return the bar number of the specified bar. It is called GetBar().
    AustinNinjaTrader Customer Service

    Comment


      #3
      I looked at that but I wasn't sure which function to use inside of it so that it would always be "today" at the specific time of 11:35 am. Got any pointers on that?

      Thank you,

      -Alli

      Comment


        #4
        For today's values, you could put Time[0].Day into the day portion of the DateTime value you pass to GetBar(). That would make GetBar use today's information every time.
        AustinNinjaTrader Customer Service

        Comment


          #5
          Ok, thank you.. I'll take a look at that and see what I can come up with.

          -Alli

          Comment


            #6
            Follow up question - can you use the GetBar command to reference a different time series? For example, I would like to get the 5 minute 6:30am bar and do something with it that plots on my trading chart, a 500volume.

            Comment


              #7
              Hello jmflukeiii,

              Thank you for your post.

              You will need to use Times and BarsInProgress as in the following example to pull the 9 AM bar:
              Code:
              			if(BarsInProgress == 1)
              			{
              				if(ToTime(Times[1][0]) >= ToTime(9,00,00))
              				{
              					int myBarsAgo = CurrentBar - Bars.GetBar(new DateTime(2013, 4, 21, 9, 00, 00));
              					Print("BarsAgo: " + myBarsAgo);
              				}
              			}
              For information on Times please visit the following link: http://www.ninjatrader.com/support/h.../nt7/times.htm

              For information on BarsInProgress please visit the following link: http://www.ninjatrader.com/support/h...inprogress.htm

              For information on using multiple instruments and/or time frames in your code please visit the following link: http://www.ninjatrader.com/support/h...nstruments.htm

              Please let me know if I may be of further assistance.

              Comment


                #8
                if (BarsInProgress == 1)
                {
                if (ToTime(Times[1][0])>=ToTime(6,30,0))
                {
                int myBarsAgo = CurrentBar - Bars.GetBar(new DateTime(2013,4,30,6,30,00));
                double ESOpen = Opens[1][myBarsAgo];
                }
                double ESCurrent = Closes[1][0];
                double ESChange = (ESCurrent-ESOpen)/ESOpen;
                ESPlot.Set(ESChange);
                }
                What am I doing wrong here - "The Name ESOpen does not exist in the current context" is the error. I've run into this problem a few times, and I don't understand how to make that double in the area surrounded by { } apply to the rest of the script.
                Last edited by jmflukeiii; 04-30-2013, 11:06 AM.

                Comment


                  #9
                  Originally posted by jmflukeiii View Post
                  What am I doing wrong here - "The Name ESOpen does not exist in the current context" is the error. I've run into this problem a few times, and I don't understand how to make that double in the area surrounded by { } apply to the rest of the script.
                  Declare the variable as a class variable (i.e., in the Variables region).
                  Assign it a value wherever.

                  Comment


                    #10
                    Thank you -
                    Last edited by jmflukeiii; 04-30-2013, 11:24 AM.

                    Comment


                      #11
                      Code:
                      DateTime myDateTime = new DateTime(Time[0].Year, Time[0].Month, Time[0].Day, 9, 29, 0);
                      			
                      int myBarsAgo = GetBar(myDateTime);
                      im usually using the code to reference a specific bar. How can i access yesterday's bar at the same time?

                      I did try to use Time[1].Day instead of Time[0].Day , but im only getting one trade.

                      Comment


                        #12
                        Hello markus1000,

                        Thank you for your post.

                        If you Print() the myBarsAgo after pulling the Time[1].Day do you see the correct date pulled?

                        The Print() will output to the Output window (Tools > Output Window).

                        For information on Print() please visit the following link: http://www.ninjatrader.com/support/h.../nt7/print.htm

                        Please let me know if I may be of further assistance.

                        Comment

                        Latest Posts

                        Collapse

                        Topics Statistics Last Post
                        Started by DJ888, 04-16-2024, 06:09 PM
                        6 responses
                        18 views
                        0 likes
                        Last Post DJ888
                        by DJ888
                         
                        Started by Jon17, Today, 04:33 PM
                        0 responses
                        1 view
                        0 likes
                        Last Post Jon17
                        by Jon17
                         
                        Started by Javierw.ok, Today, 04:12 PM
                        0 responses
                        6 views
                        0 likes
                        Last Post Javierw.ok  
                        Started by timmbbo, Today, 08:59 AM
                        2 responses
                        10 views
                        0 likes
                        Last Post bltdavid  
                        Started by alifarahani, Today, 09:40 AM
                        6 responses
                        41 views
                        0 likes
                        Last Post alifarahani  
                        Working...
                        X