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