Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

On The Last Bar Update

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

    On The Last Bar Update

    I'm working on an indicator and if I set the date range of the chart and then only put this:
    Code:
    protected override void OnBarUpdate()
    {
    Print(Time[0].ToShortDateString());
    }
    The output window shows every date in the range (minus weekends and holidays) up to the day before my end date but does not show my end date. However if I look on the chart the end date is there as expected.

    How can I execute code on the last bar update?

    #2
    Thanks for the post LorneCash, this will completely depend on the CalculateOnBarClose setting set for the script - http://www.ninjatrader.com/support/h...onbarclose.htm

    With the default true setting your outcome would be expected, as the bar has not yet fully closed in the sense that the opening of the next was not seen (event based approach here).

    Comment


      #3
      OK so I understand why it's behaving the way it does but my questions still remains...

      How can I execute code only after the last bar update? We have a nice method OnBarUpdate but that gets executed after EVERY bar... I want to execute code only after the LAST bar. I'm guessing I will need to put some sort of IF condition inside the OnBarUpdate method but I'm not sure what that should be.

      I also tried looking for another method to override but there didn't seem to be one that was appropriate.

      Comment


        #4
        The reason I want to do this is that I want to draw stuff on the chart and I really don't need or want to draw it after every bar update... that would be wasted processing power. I use OnBarUpdate to gather data and then at the very end I want to draw a bunch of stuff.

        Comment


          #5
          I see, there's not really an event for the end of the chart, but you can detect via comparing CurrentBar and Count - http://www.ninjatrader.com/support/h.../nt7/count.htm

          Comment


            #6
            Thank you that works.

            Comment


              #7
              This is the exact code I was looking for just in case anyone else finds this useful. This allows me to simulate what might be called OnLastBarUpdate or OnBarUpdateComplete event.

              Code:
              if (CurrentBar >= Count - 1 - Convert.ToInt32(CalculateOnBarClose))

              Comment

              Latest Posts

              Collapse

              Topics Statistics Last Post
              Started by Geovanny Suaza, 02-11-2026, 06:32 PM
              0 responses
              563 views
              0 likes
              Last Post Geovanny Suaza  
              Started by Geovanny Suaza, 02-11-2026, 05:51 PM
              0 responses
              329 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
              547 views
              1 like
              Last Post Geovanny Suaza  
              Started by RFrosty, 01-28-2026, 06:49 PM
              0 responses
              547 views
              1 like
              Last Post RFrosty
              by RFrosty
               
              Working...
              X