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 CarlTrading, 03-31-2026, 09:41 PM
      1 response
      156 views
      1 like
      Last Post NinjaTrader_ChelseaB  
      Started by CarlTrading, 04-01-2026, 02:41 AM
      0 responses
      90 views
      1 like
      Last Post CarlTrading  
      Started by CaptainJack, 03-31-2026, 11:44 PM
      0 responses
      140 views
      2 likes
      Last Post CaptainJack  
      Started by CarlTrading, 03-30-2026, 11:51 AM
      0 responses
      130 views
      1 like
      Last Post CarlTrading  
      Started by CarlTrading, 03-30-2026, 11:48 AM
      0 responses
      107 views
      0 likes
      Last Post CarlTrading  
      Working...
      X