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 charlesugo_1, 05-26-2026, 05:03 PM
        0 responses
        61 views
        0 likes
        Last Post charlesugo_1  
        Started by DannyP96, 05-18-2026, 02:38 PM
        1 response
        148 views
        0 likes
        Last Post NinjaTrader_ChelseaB  
        Started by CarlTrading, 05-11-2026, 05:56 AM
        0 responses
        162 views
        0 likes
        Last Post CarlTrading  
        Started by CarlTrading, 05-10-2026, 08:12 PM
        0 responses
        98 views
        0 likes
        Last Post CarlTrading  
        Started by Hwop38, 05-04-2026, 07:02 PM
        0 responses
        286 views
        0 likes
        Last Post Hwop38
        by Hwop38
         
        Working...
        X