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

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

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

        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 funk10101, Today, 09:43 PM
              0 responses
              6 views
              0 likes
              Last Post funk10101  
              Started by pkefal, 04-11-2024, 07:39 AM
              11 responses
              37 views
              0 likes
              Last Post jeronymite  
              Started by bill2023, Yesterday, 08:51 AM
              8 responses
              44 views
              0 likes
              Last Post bill2023  
              Started by yertle, Today, 08:38 AM
              6 responses
              26 views
              0 likes
              Last Post ryjoga
              by ryjoga
               
              Started by algospoke, Yesterday, 06:40 PM
              2 responses
              24 views
              0 likes
              Last Post algospoke  
              Working...
              X