Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Supported Feature?

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

    Supported Feature?

    Hi,

    Is this code supported; it works but I cannot find any documentation on it and I always try to avoid undocumented features where possible?

    IBar bar = Bars.Get(20);

    I need the timestamp of a given bar during a backtest where I only know a bar number, nothing else.

    If this isn't documented or there is a better way to do it, please let me know.

    Best Regards,
    Scott

    #2
    Hello Scott,

    I'm not sure about Bars.Get(20) unless you mean Bars.GetBar(20)

    Yes, this is a supported method of retrieving that information.

    Bars.GetBar(20) will give you the Bar Number, while just using GetBar(20) will give you the BarsAgo value.

    Please see our Forum Post on Referencing the correct bar for more examples and other methods:

    MatthewNinjaTrader Product Management

    Comment


      #3
      Matthew, thanks for getting back to me.

      I need information about the N bar; the same information I could get if I wrote something like

      if (CurrentBar == 100) Time, etc. Since this is in a back test, all the information is already known. Bars.Count will give you the number of bars on the chart. I want the equivalent of Bars[150] (however it would be coded) to give me information about the absolute 150th bar on the chart, not 150 bars ago from my current position.

      This code is in OnStartUp so CurrentBar will likely be something like BarsRequired. I hope this is clear.

      The code I posted does work but since you are not familiar with it, I am guessing it isn't supported.

      Best Regards,
      Scott

      Comment


        #4
        Scott,

        No, that would not be supported.

        Can you clarify why you cannot use Time[20]; to get the value?
        MatthewNinjaTrader Product Management

        Comment


          #5
          Matthew,

          Thanks; I guessed as much. Wouldn't Time[20] give me the time from 20 bars ago? I want Time[101] to give me the time from BarNumber 101.

          Comment


            #6
            Scott,

            Gotcha - in that case, you'd use something like the following:

            Code:
            if(CurrentBar == 20)
               {
               DateTime myDateTime = Time[0];
               }
            Last edited by NinjaTrader_Matthew; 08-24-2011, 10:35 AM.
            MatthewNinjaTrader Product Management

            Comment


              #7
              Matthew,

              That is the conclusion I came to but given I am willing to take the chance a future release will cause an issue, the other method I posted does work.

              Best Regards,
              Scott

              Comment


                #8
                I guessed as much. Wouldn't Time[20] give me the time from 20 bars ago? I want Time[101] to give me the time from BarNumber 101.
                Lets see. If we are on bar nr. 141, then Time[101] will give the time of bar 141-101=40.
                Now you want the time of bar 101. How can you manipulate the equation to get it? Very complicated question. Need advise of a PhD. Mathematician.

                Comment


                  #9
                  Baruch, I am not your man then.

                  The issue is I want this in OnStartUp for optimizations. In a back test or an optimization (which is kind of technically only a bunch of back tests) I already have all the bars (Bars.Count or maybe Bars.Count -1 I forget) is the last bar on the chart and will give the last bar your back test is over.

                  I just want to get the dates associated with various bars in between without having to wait for an iteration (or a back test). I got it to work, I just wasn't sure if it was supported or not.

                  Best Regards,
                  Scott

                  Comment


                    #10
                    Originally posted by ScottB View Post
                    Matthew,

                    Thanks; I guessed as much. Wouldn't Time[20] give me the time from 20 bars ago? I want Time[101] to give me the time from BarNumber 101.
                    Code:
                     
                    Time[CurrentBar - 101];
                    or whatever the barIndex that you want to deal with instead of "101"

                    Comment


                      #11
                      koganam, I have used that as well.

                      Comment

                      Latest Posts

                      Collapse

                      Topics Statistics Last Post
                      Started by sjsj2732, Yesterday, 04:31 AM
                      0 responses
                      31 views
                      0 likes
                      Last Post sjsj2732  
                      Started by NullPointStrategies, 03-13-2026, 05:17 AM
                      0 responses
                      286 views
                      0 likes
                      Last Post NullPointStrategies  
                      Started by argusthome, 03-08-2026, 10:06 AM
                      0 responses
                      283 views
                      0 likes
                      Last Post argusthome  
                      Started by NabilKhattabi, 03-06-2026, 11:18 AM
                      0 responses
                      133 views
                      1 like
                      Last Post NabilKhattabi  
                      Started by Deep42, 03-06-2026, 12:28 AM
                      0 responses
                      91 views
                      0 likes
                      Last Post Deep42
                      by Deep42
                       
                      Working...
                      X