Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Is there a way to assign an ISeries<> to a secondary data series?

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

    Is there a way to assign an ISeries<> to a secondary data series?

    Is there a way to assign a secondary data series to an ISeries<>? I need to use an SMA and it will only accept an ISeries<>

    Currently my understanding is that I can only assign a secondary data series to Series<> as below:



    private Series<double> signal ;


    protected override void OnStateChange()
    {
    if (State == State.Configure)
    {
    AddDataSeries(SecondaryDataSeriesBarType, SecondaryDataSeriesPeriod);

    }
    else if (State == State.DataLoaded)
    {
    signal = new Series<double>(BarsArray[1], MaximumBarsLookBack.Infinite);
    }
    }


    The SMA function requires an ISeries.

    #2
    Hello kenconcannon,

    Thank you for your inquiry.

    Are you just looking to supply a secondary data series as an input to the SMA? You can just use BarsArray and supply that to the SMA directly.

    The Help Guide page below demonstrates supplying the added data series as an input to the SMA using BarsArray:



    Please let me know if you have any further questions.

    Comment


      #3
      Thx Gaby,

      I was trying to add this to the data loaded state but I would get an error because signal is a Series<> not an ISeries<>:

      signal = SMA(ROC(BarsArray[1], rocPeriod), maPeriod);

      If I change the signal to ISeries<> like below:


      private ISeries<double> signal ;

      protected override void OnStateChange()
      {
      if (State == State.Configure)
      {
      AddDataSeries(SecondaryDataSeriesBarType, SecondaryDataSeriesPeriod);

      }
      else if (State == State.DataLoaded)
      {
      signal = new ISeries<double>(BarsArray[1], MaximumBarsLookBack.Infinite); <<<----- this is not valid

      signal = SMA(ROC(BarsArray[1], rocPeriod), maPeriod);
      }
      }​


      then I cannot specify the specific bar array.


      I know I can get the values in the OnBarUpdate event and just assign to the signal Series<>. I was just wondering if I can specify in the OnStateChange event instead like I can if I am just using a primary data series

      Comment


        #4
        Hello,

        Can you please clarify what are you trying to achieve with this line?

        Code:
        signal = new ISeries<double>(BarsArray[1], MaximumBarsLookBack.Infinite);
        If you are trying to assign the SMA to "signal", signal needs to be of type SMA, not an ISeries<double>.

        Code:
        private SMA signal;
        
        .
        .
        .
        
        else if (State == State.DataLoaded)
        {
        signal = SMA(ROC(BarsArray[1], rocPeriod), maPeriod);
        }
        For a working example you can take a look at SampleMultiInstrument in the NinjaScript Editor.

        Please let us know if you have any further questions.

        Comment

        Latest Posts

        Collapse

        Topics Statistics Last Post
        Started by CarlTrading, 03-31-2026, 09:41 PM
        1 response
        47 views
        0 likes
        Last Post NinjaTrader_ChelseaB  
        Started by CarlTrading, 04-01-2026, 02:41 AM
        0 responses
        23 views
        0 likes
        Last Post CarlTrading  
        Started by CaptainJack, 03-31-2026, 11:44 PM
        0 responses
        33 views
        1 like
        Last Post CaptainJack  
        Started by CarlTrading, 03-30-2026, 11:51 AM
        0 responses
        50 views
        0 likes
        Last Post CarlTrading  
        Started by CarlTrading, 03-30-2026, 11:48 AM
        0 responses
        42 views
        0 likes
        Last Post CarlTrading  
        Working...
        X