Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

When to call AfterBarUpdate();

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

    When to call AfterBarUpdate();

    Hello everyone,

    From time to time, I need to do calculations after OnBarUpdate is finished (mostly additional graphics, database updates, …)

    So far, I’m using two ways to detect when OnBarUpdate is finished. One is within OnBarUpdate testing for the last CurrentBar. The other way is to wait until the state is set to Transition (see the attached indicator. Easy to understand).

    I see both advantage and disadvantage of the two approaches.

    Testing for the last CurrentBar seems to very “safe”. Using State = Transition is the most elegant, but code must be written to handle multiple calls, which can happen.

    If anyone has any comments about this, or if the support team has any NinjaScript Best Practices, I am happy to read about it.

    Regards, AndBro
    Attached Files

    #2
    Hello AndBro,

    Specifically, you need to trigger an action after the last historical bar has processed, is this correct?

    (Or are you trying to trigger something after every pass of OnBarUpdate which will trigger for every bar?)

    Using State == State.Realtime in OnStateChange() would trigger after the last historical bar has closed.

    Using (State == State.Historical && CurrentBar == Count - 2) in OnBarUpdate() would trigger after the last historical bar has closed.
    (The last historical bar is left open and will close in real-time so Count - 1 would be the first real-time bar)

    Trying printing either approach. They are basically the same.
    Chelsea B.NinjaTrader Customer Service

    Comment


      #3
      Hello Chelsea,

      Thank you for your answers. One is learning new stuff every day …

      It is so much written about “when and what” to do before OnBarUpdate, but very little about when OnBarUpdate is finished. That is way I raised my question.

      Thank you, AndBro

      Comment

      Latest Posts

      Collapse

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