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 cmoran13, Yesterday, 01:02 PM
      0 responses
      29 views
      0 likes
      Last Post cmoran13  
      Started by PaulMohn, 04-10-2026, 11:11 AM
      0 responses
      21 views
      0 likes
      Last Post PaulMohn  
      Started by CarlTrading, 03-31-2026, 09:41 PM
      1 response
      160 views
      1 like
      Last Post NinjaTrader_ChelseaB  
      Started by CarlTrading, 04-01-2026, 02:41 AM
      0 responses
      95 views
      1 like
      Last Post CarlTrading  
      Started by CaptainJack, 03-31-2026, 11:44 PM
      0 responses
      148 views
      2 likes
      Last Post CaptainJack  
      Working...
      X