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 cmoran13, 04-16-2026, 01:02 PM
        0 responses
        43 views
        0 likes
        Last Post cmoran13  
        Started by PaulMohn, 04-10-2026, 11:11 AM
        0 responses
        25 views
        0 likes
        Last Post PaulMohn  
        Started by CarlTrading, 03-31-2026, 09:41 PM
        1 response
        163 views
        1 like
        Last Post NinjaTrader_ChelseaB  
        Started by CarlTrading, 04-01-2026, 02:41 AM
        0 responses
        98 views
        1 like
        Last Post CarlTrading  
        Started by CaptainJack, 03-31-2026, 11:44 PM
        0 responses
        158 views
        2 likes
        Last Post CaptainJack  
        Working...
        X