Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Multiple Data series setup in initialize method

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

    Multiple Data series setup in initialize method

    Can I set different data series right from the initialize method based on a if statement.

    Here is what I am trying to do :

    I have a user defined property called dataCollectionType which return an enumeration. The user have a choice between BidAsk, Tick, File and None.

    In my initialize method I have inserted the following if statement :

    if(dataCollectionType == DataCollection.BidAsk)
    {
    Add(Instrument.FullName,PeriodType.Tick,1, MarketDataType.Last);
    Add(Instrument.FullName,PeriodType.Tick,1, MarketDataType.Ask);
    Add(Instrument.FullName,PeriodType.Tick,1, MarketDataType.Bid);
    }
    else
    if(dataCollectionType == DataCollection.Tick)
    Add(PeriodType.Tick,1);
    I get an error Index was outside the bounds of the array.
    at NinjaTrader.Indicator.IndicatorBase.set_BarsArray( Bars[] value)

    What could be wrong ?

    Thanks

    #2
    Hello blar58,

    The only supported technique for adding additional series is hard coding everything. This is due to the timing on Initialize() and that it is called for all scripts when you run one. Unfortunately, adding conditionally or dynamically adding is not supported.
    Ryan M.NinjaTrader Customer Service

    Comment


      #3
      It's possible to add series that aren't known until after the user sets the parameters, It's not hard if you always add the same number/type of series, but if you don't know how many series there will be until the user sets the parameters, you have to prevent the Adds until after the parameters are set. Otherwise NT7 will give you an error when it detects that the number of series has changed from when it called Initialize() before the parameters were set. I've had success with the following technique:

      Code:
      in Initialize():
      
      //Add Plots
      Add(new Plot(Color.FromKnownColor(KnownColor.ForestGreen), PlotStyle.Line, "IndicatorName"));
      
      if ((ChartControl != null) && (Instruments != null))
      	{
      		// Add instruments
      		if(dataCollectionType == DataCollection.BidAsk)
                      { 
                          Add(Instrument.FullName,PeriodType.Tick,1, MarketDataType.Last);
                          Add(Instrument.FullName,PeriodType.Tick,1, MarketDataType.Ask);
                          Add(Instrument.FullName,PeriodType.Tick,1, MarketDataType.Bid);
                       }
                       else
                           if(dataCollectionType == DataCollection.Tick)
                                Add(PeriodType.Tick,1);
      	}

      Comment


        #4
        Thanks for sharing this, kdoren.
        Ryan M.NinjaTrader Customer Service

        Comment

        Latest Posts

        Collapse

        Topics Statistics Last Post
        Started by Geovanny Suaza, 02-11-2026, 06:32 PM
        0 responses
        599 views
        0 likes
        Last Post Geovanny Suaza  
        Started by Geovanny Suaza, 02-11-2026, 05:51 PM
        0 responses
        344 views
        1 like
        Last Post Geovanny Suaza  
        Started by Mindset, 02-09-2026, 11:44 AM
        0 responses
        103 views
        0 likes
        Last Post Mindset
        by Mindset
         
        Started by Geovanny Suaza, 02-02-2026, 12:30 PM
        0 responses
        558 views
        1 like
        Last Post Geovanny Suaza  
        Started by RFrosty, 01-28-2026, 06:49 PM
        0 responses
        557 views
        1 like
        Last Post RFrosty
        by RFrosty
         
        Working...
        X