Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Want to consider only the most recent OnBarUpdate bar event?

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

    Want to consider only the most recent OnBarUpdate bar event?

    I placed a lot of prints and logs command in my ninja script and I noticed that the OnBarUpdate event is called lots of times when the strategy is first enabled (initiated). It looks like it looks at historical data, because I placed a print showing date and time, and it loads several bars until it gets to the most recent one.

    1st Question: My strategy is running on 30 minutes bars, how many times is the OnBarUpdate called upon initiation (enabling) of my strategy? Whats it the logic behind that, does it call OnBarUpdate for as many historical bars as it can read?

    2nd Question: Since OnBarUpdate is called a lot of time upon initiation of the strategy, it might end up entering in one of my conditions and entering the market, how can I make sure my conditions are only executed for recent bars updates in my OnBarUpdate method (for example last minute), knowing that it will be called several times during initiation?

    Thank you all,

    Rodrigo

    #2
    Use the Historical builtin variable.

    It's ok to do all your processing on Historical bars, just don't enter the orders if Historical is true.

    When you first open a chart, Ninja has to grab all the data necessary to draw all the bars in your chart. That's obvious, right? While it does this Historical is set to true. As soon as all these bars are drawn and the chart has caught up to the data from the live feed driving the candlesticks, Historical is set to false.

    So, essentially, you're seeing real-time data only when Historical is false.

    Comment


      #3
      Rodrigo, what David outline is exatly what's happening, to see better how the calls work just print the Time[0] timestamp alongside with your CurrentBar count and the Historical property. You will see the CurrentBar count showing you exaclty what bar currently is processed by OnBarUpdate().

      Comment


        #4
        Thank you both David and Bertrand.

        Comment

        Latest Posts

        Collapse

        Topics Statistics Last Post
        Started by Geovanny Suaza, 02-11-2026, 06:32 PM
        0 responses
        656 views
        0 likes
        Last Post Geovanny Suaza  
        Started by Geovanny Suaza, 02-11-2026, 05:51 PM
        0 responses
        371 views
        1 like
        Last Post Geovanny Suaza  
        Started by Mindset, 02-09-2026, 11:44 AM
        0 responses
        109 views
        0 likes
        Last Post Mindset
        by Mindset
         
        Started by Geovanny Suaza, 02-02-2026, 12:30 PM
        0 responses
        574 views
        1 like
        Last Post Geovanny Suaza  
        Started by RFrosty, 01-28-2026, 06:49 PM
        0 responses
        579 views
        1 like
        Last Post RFrosty
        by RFrosty
         
        Working...
        X