Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Multi-Instrument Strategy OnBarUpdate Sequence

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

    Multi-Instrument Strategy OnBarUpdate Sequence

    I have a Strategy and a StrategyPlot as follows:
    Primary Instrument: 'MSFT'
    Secondary Instrument: '^SP500'
    Period: Daily
    BarsBack: 4

    Initialize()
    {
    CalculateOnBarClose =
    true;
    BarsRequired =
    0;
    Add("^SP500", PeriodType.Day, 1);

    Add(StrategyPlot(0));
    StrategyPlot(0).PanelUI = 1;
    }


    To investigate data availability for all instruments for a particular bar I placed this debug code in OnBarUpdate:
    OnBarUpdate()
    {
    string logText = "";
    logText += String.Format("BarsInProgress:{0} Instrument:{1} CurrentBar:{2} Date:{3}", BarsInProgress, Instruments[BarsInProgress], CurrentBar, Time[0]);
    Log(logText, LogLevel.Information);
    }

    It produced the following output (from newest to oldest)
    BarsInProgress: 1 Instrument:^SP500 CurrentBar:2 Date:6/29/2009
    BarsInProgress: 0 Instrument:MSFT CurrentBar:2 Date:6/29/2009
    BarsInProgress: 1 Instrument:^SP500 CurrentBar:1 Date:6/26/2009
    BarsInProgress: 0 Instrument:MSFT CurrentBar:1 Date:6/26/2009
    BarsInProgress: 1 Instrument:^SP500 CurrentBar:0 Date:6/25/2009
    BarsInProgress: 0 Instrument:MSFT CurrentBar:0 Date:6/25/2009

    Since I want to do a calculation involving values from both DataSeries it seemed I should add the following condition to ensure both DataSeries values for the CurrentBar were available:
    OnBarUpdate()
    if (BarsInProgress == 1)
    {
    //do some calculation and assign it to the plot
    StrategyPlot(0).Value.Set(Closes[0][0] + Closes[1][0]);
    }

    However, no plot lines were drawn. If I changed the condition to:
    if (BarsInProgress == 0)
    the plot worked fine.

    1) What's the timing relationship between 'OnBarUpdate' and 'Plot.Value.Set'?

    2) What is the best 'BarsInProgress' practice for performance and stability when using multiple instruments in the same timeframe?

    Thanks
    - Fred

    #2
    StrategyPlot was developed as a temporary solution, so to make a long story short, we recommend you only use it with Primary Bars when BarsInProgress == 0.

    NinjaTrader 7 will include the capability to develop multi-instrument indicators and that will make what you're trying to do much easier.
    AustinNinjaTrader Customer Service

    Comment


      #3
      Ok, the short story is clear.
      I'll stay within recommendations for 6.5, and hold my other questions until I've re-created this and other functionality in 7.0

      Keep up the great work.

      - Fred

      Comment

      Latest Posts

      Collapse

      Topics Statistics Last Post
      Started by Geovanny Suaza, 02-11-2026, 06:32 PM
      0 responses
      647 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