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

Named DataSeries

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

    Named DataSeries

    Is there a way to assign friendly names to data series added using AddDataSeries. I have over 10 data series I need to add to an indicator and using friendly names would make the code easier to read and less likely to have an error introduced. I know the following will work, but it seems like overkill just to get friendly names.

    Code:
    protected override void OnStateChange()
    {
       .
       .
       .
       else if (State == State.Configure)
       {
          AddDataSeries("AUDUSD", BarsPeriodType.Minute, 1);
          AddDataSeries("USDJPY", BarsPeriodType.Minute, 1);
       }
       else if (State == State.DataLoaded)
       {
          audusd = new Series<double>((BarsArray[1]);
          audjpy = new Series<double>((BarsArray[2]);
       }
    }
    
    protected override void OnBarUpdate()
    {
       if (BarsInProgress == 0)
       {
          // do normal stuff
       }
       else if (BarsInProgress == 1) audusd[0] = Closes[1][0];
       else if (BarsInProgress == 2) audjpy[0] = Closes[2][0];
    }
    Thanks,
    Greg
    The Trading Mantis
    NinjaTrader Ecosystem Vendor - The Trading Mantis

    #2
    Hi Greg, thanks for posting.

    You can make a public property that returns the Closes[1] array:
    Code:
    else if (State == State.Configure)
    {
        AddDataSeries("MSFT");
    }
    ...
    protected override void OnBarUpdate()
    {
    if(BarsInProgress == 1)
        {
            Print(MySecondCloseSeries[0]);
        }
    }
    
    [Browsable(false)]
    [XmlIgnore]
    public PriceSeries MySecondCloseSeries
    {
        get { return Closes[1]; }
    }
    Best regards,
    -ChrisL
    Chris L.NinjaTrader Customer Service

    Comment


      #3
      That was exactly what I was looking for! Thanks Chris!
      The Trading Mantis
      NinjaTrader Ecosystem Vendor - The Trading Mantis

      Comment

      Latest Posts

      Collapse

      Topics Statistics Last Post
      Started by Human#102, Yesterday, 09:54 AM
      2 responses
      7 views
      0 likes
      Last Post Human#102  
      Started by Patlpp, 08-16-2021, 03:10 PM
      10 responses
      498 views
      0 likes
      Last Post Joerg
      by Joerg
       
      Started by AdamDJ8, 05-07-2024, 09:18 PM
      2 responses
      17 views
      0 likes
      Last Post -=Edge=-  
      Started by StockTrader88, 03-06-2021, 08:58 AM
      46 responses
      4,101 views
      3 likes
      Last Post tradgrad  
      Started by usasugardefender, Today, 01:42 AM
      0 responses
      1 view
      0 likes
      Last Post usasugardefender  
      Working...
      X