Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Function returning the bar by its time

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

    Function returning the bar by its time

    Hi!

    Is there a function in Ninjatrader returning the bar by its time?
    In mq4 this equals to iBarShift.
    Does anyone have an idea?

    #2
    Hello Stanfillirenfro,

    Thanks for your post.

    I think GetBar() is what you are looking for.

    Reference: https://ninjatrader.com/support/help...t8/?getbar.htm

    Comment


      #3
      Many thanks PaulH for your reply!

      I think GetBar() works well when the DateTime time is known. Let's imagine that I am in a loop and I want to have bars by time. GetBar() would not work in this case right?
      Last edited by Stanfillirenfro; 06-25-2021, 08:04 AM.

      Comment


        #4
        Hello Stanfillirenfro,

        Thanks for your reply.

        Correct, you would need to know the time.

        "Let's imagine that I am in a loop and I want to have bars by time." You would need to know the time of the bar to get.

        Can you elaborate further?

        Comment


          #5
          Many Thanks PaulH for your reply.

          I have the following:

          int tt, kk;
          tt = 0;
          kk = 0;

          for(int i 30; i >= 0; i--)
          {
          tt = iBarShift(NULL, 0, kk);
          }

          the problem here is that kk is an integer.

          The DateTime would be a double while passing to the constructor of GetBar();
          Any help?
          Is there another function which could replace iBarShif od GetBar()?
          Last edited by Stanfillirenfro; 06-25-2021, 08:45 AM.

          Comment


            #6
            Hello Stanfillirenfro,

            Thanks for your reply.

            In your looping, are you simply looking at the prior 30 bars? If so then you don't need to use time as you can use barsago indexing [] of whatever price/data series you need.

            For example

            for (int j =0; j< 30; j++)
            {
            if (High[j] > myHigh)
            {
            myHigh = High[j]; //look for the high in the last 30 bars
            }
            }

            Note (There are other methods to find the high, this is just an example to demonstrate using bars ago [] indexing).

            Comment


              #7
              Many thanks PaulH for your reply.

              I am not looking for a given high or low.
              Let's imagine that in a nearest past I've obtained 75 bars fo example on the chart.. How can I have the time of each bar? If I take those bars in a loop, how can I have the time of each of these bars?

              Instead of 30 I will write CurrentBar. 30 is just a number to make it clearer.

              Comment


                #8
                Hello Stanfillirenfro,

                Thanks for your reply.

                My apologies if I am misunderstanding.

                Each bar will be time-stamped with the end of the bar date/time.

                You can access the Time series Time[] (or Times[][] in case of multi time frame)

                Reference:

                Comment


                  #9
                  Many thanjs PaulH for your help.
                  I will tr with this function.
                  I will revert to you in case I need more assistance.

                  Many thanks again.

                  Comment

                  Latest Posts

                  Collapse

                  Topics Statistics Last Post
                  Started by Geovanny Suaza, 02-11-2026, 06:32 PM
                  0 responses
                  576 views
                  0 likes
                  Last Post Geovanny Suaza  
                  Started by Geovanny Suaza, 02-11-2026, 05:51 PM
                  0 responses
                  334 views
                  1 like
                  Last Post Geovanny Suaza  
                  Started by Mindset, 02-09-2026, 11:44 AM
                  0 responses
                  101 views
                  0 likes
                  Last Post Mindset
                  by Mindset
                   
                  Started by Geovanny Suaza, 02-02-2026, 12:30 PM
                  0 responses
                  553 views
                  1 like
                  Last Post Geovanny Suaza  
                  Started by RFrosty, 01-28-2026, 06:49 PM
                  0 responses
                  551 views
                  1 like
                  Last Post RFrosty
                  by RFrosty
                   
                  Working...
                  X