Announcement

Collapse

Looking for a User App or Add-On built by the NinjaTrader community?

Visit NinjaTrader EcoSystem and our free User App Share!

Have a question for the NinjaScript developer community? Open a new thread in our NinjaScript File Sharing Discussion Forum!
See more
See less

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 maybeimnotrader, Today, 05:46 PM
        0 responses
        6 views
        0 likes
        Last Post maybeimnotrader  
        Started by quantismo, Today, 05:13 PM
        0 responses
        6 views
        0 likes
        Last Post quantismo  
        Started by AttiM, 02-14-2024, 05:20 PM
        8 responses
        166 views
        0 likes
        Last Post jeronymite  
        Started by cre8able, Today, 04:22 PM
        0 responses
        8 views
        0 likes
        Last Post cre8able  
        Started by RichStudent, Today, 04:21 PM
        0 responses
        5 views
        0 likes
        Last Post RichStudent  
        Working...
        X