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 Hwop38, 05-04-2026, 07:02 PM
      0 responses
      161 views
      0 likes
      Last Post Hwop38
      by Hwop38
       
      Started by CaptainJack, 04-24-2026, 11:07 PM
      0 responses
      308 views
      0 likes
      Last Post CaptainJack  
      Started by Mindset, 04-21-2026, 06:46 AM
      0 responses
      245 views
      0 likes
      Last Post Mindset
      by Mindset
       
      Started by M4ndoo, 04-20-2026, 05:21 PM
      0 responses
      349 views
      0 likes
      Last Post M4ndoo
      by M4ndoo
       
      Started by M4ndoo, 04-19-2026, 05:54 PM
      0 responses
      179 views
      0 likes
      Last Post M4ndoo
      by M4ndoo
       
      Working...
      X