Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Time of the Last Bar

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

    Time of the Last Bar

    Hello! I am making an indicator and I need two passes of the history. But to run the second pass on the last bar I need to know the time of the last bar on the real chart from any position on the chart in OnBarUpdate().
    How can I get the time of the last bar?

    Thanks.

    #2
    k69evil, welcome to our forums - I might not be fully following what you wish to do, but the current most bar always has the index 0, thus Time[0] would give you the current bars timestamp.

    Comment


      #3
      Thank for participation and sorry about my bad english.

      We have chart with history of many bars. OnBarUpdate() is running on each bar, but values of future bars, which already is existing, is inaccessible. My indicator output on each bar depend from statistic of all bars of chart. Thus I want known, where OnBarUpdate() is running on last bar.

      I find not nice method for this, but it doesn't work in days off, when exchange is stopped.

      Code:
      protected bool FullChart = false;
      protected override void OnMarketData(MarketDataEventArgs e)
      {
          if (!FullChart)
          {
              FullChart = true;
              OnBarUpdate(); // Update() don't work
          }
      }
      
      protected override void OnBarUpdate()
      {
          // rude, but for example
          if (FullChart)
          {
              // 1 pass
              for (int i = CurrentBar - 1; i >= 0; i--)
              {
                  // Do Something
              }
              // 2 pass
              for (int i = CurrentBar - 1; i >= 0; i--)
              {
                  // Do Something
              }
          }
      }

      Comment


        #4
        k69Evil, the 2 supported properties we have in this area would be -

        1. CurrentBar - where the OnBarUpdate() is currently processed

        2. Count - the total # of bars - http://www.ninjatrader.com/support/h.../nt7/count.htm

        Comment


          #5
          Thank you very much! Count is what i need.

          Comment


            #6
            Originally posted by NinjaTrader_Bertrand View Post
            ...the current most bar always has the index 0, thus Time[0] would give you the current bars timestamp.
            When "Calculate on Bar Close" is set to FALSE, it seems the most recent bar is actually -1 (instead of 0), correct?

            Daniel

            Comment


              #7
              Neoikon,

              The numbers don't change, the bar that the index value is assigned to changes.

              When COBC is true, the current bar is the second bar to the left from the price axis, AKA BarIndex[0]

              When COBC is false the current bar becomes the bar being built or one to the left of the price axis. Still, has the BarIndex value of [0].
              Cal H.NinjaTrader Customer Service

              Comment

              Latest Posts

              Collapse

              Topics Statistics Last Post
              Started by Geovanny Suaza, 02-11-2026, 06:32 PM
              0 responses
              602 views
              0 likes
              Last Post Geovanny Suaza  
              Started by Geovanny Suaza, 02-11-2026, 05:51 PM
              0 responses
              347 views
              1 like
              Last Post Geovanny Suaza  
              Started by Mindset, 02-09-2026, 11:44 AM
              0 responses
              103 views
              0 likes
              Last Post Mindset
              by Mindset
               
              Started by Geovanny Suaza, 02-02-2026, 12:30 PM
              0 responses
              560 views
              1 like
              Last Post Geovanny Suaza  
              Started by RFrosty, 01-28-2026, 06:49 PM
              0 responses
              559 views
              1 like
              Last Post RFrosty
              by RFrosty
               
              Working...
              X