Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Strategy: OnBarUpdate not fired for last plotted bar

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

    Strategy: OnBarUpdate not fired for last plotted bar

    I have a strategy which does not fire OnBarUpdate for the last daily bar.
    It is now Sunday 6/28, but still Friday 6/26 session bar event is not fired, even though it is drawn on the StrategyPlot.

    Example:

    Create new chart, instrument = "MSFT", Period = Daily, BarsBack = 2

    Strategy code:
    protected override void Initialize()
    {
    CalculateOnBarClose = true;
    BarsRequired = 0;
    }
    protectedoverridevoid OnBarUpdate()
    {
    string logText = "";
    logText = String.Format(
    "Instrument:{0} CurrentBar:{1} Date:{2}", Instruments[BarsInProgress], CurrentBar, Time[0]);
    Log(logText, LogLevel.Information);
    }


    Output:
    Category Message
    Default Instrument:MSFT Default CurrentBar:0 Date:6/25/2009 00:00:00

    Changing the BarsBack property results in the OnBarUpdate event firing for all bars except the last one.
    If BarsBack is set to 1, this error occurs:
    Error on plotting last value for indicator 'StrategyPlot'. Please check the 'OnBarUpdate' method: Index was out of range. Must be non-negative and less than the size of the collection.

    Should not OnBarUpdate fire for the last completed bar?

    #2
    Hello,

    The line of code below is stopping it from calculating again until the bar closes. The data provider has not sent the bar close/ bar open event yet, so NT does not calculate the bar yet:
    CalculateOnBarClose = true;
    DenNinjaTrader Customer Service

    Comment


      #3
      The odd part to me is that the last bar was drawn on the chart with the correct OHLC values, it just didn't pass through the Strategy's OnBarUpdate event.

      Is the DataSeries for a Chart within a Strategy a different object than the DataSeries for the Strategy itself?

      Comment


        #4
        fwalton,

        A bar is not considered closed until the opening of the next bar.
        Josh P.NinjaTrader Customer Service

        Comment

        Latest Posts

        Collapse

        Topics Statistics Last Post
        Started by Geovanny Suaza, 02-11-2026, 06:32 PM
        0 responses
        648 views
        0 likes
        Last Post Geovanny Suaza  
        Started by Geovanny Suaza, 02-11-2026, 05:51 PM
        0 responses
        369 views
        1 like
        Last Post Geovanny Suaza  
        Started by Mindset, 02-09-2026, 11:44 AM
        0 responses
        108 views
        0 likes
        Last Post Mindset
        by Mindset
         
        Started by Geovanny Suaza, 02-02-2026, 12:30 PM
        0 responses
        572 views
        1 like
        Last Post Geovanny Suaza  
        Started by RFrosty, 01-28-2026, 06:49 PM
        0 responses
        573 views
        1 like
        Last Post RFrosty
        by RFrosty
         
        Working...
        X