Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Using a DataSeries within another DataSeries

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

    Using a DataSeries within another DataSeries

    I'm porting code over from Wealthlab and ran into a syntax issue. I want to use one data series within another data series as per this Wealthlab statement.

    DataSeries linregLL = LinearReg.Series( High + Low - (Low + (High-Low)/2), 9);

    How is this done with using Ninja 8? I having problems declaring this correctly.

    #2
    Hello Boreland, and thank you for your question.

    In NinjaTrader 7, DataSeries objects were useful for storing various types of values. In NinjaTrader 8, Series<T> objects are useful for the same purpose.

    When we search through the NinjaTrader 7 help guide, we notice the closest built in indicator to LinearReg is called LinReg. This is the one I will be using here. We find its help guide page here,



    The built-in LinReg indicator does not take two doubles as an argument, so I will need to ignore this code, unless you could explain its function,

    High + Low - (Low + (High-Low)/2)

    When we try to compile code in NinjaTrader 7, we also find that Indicators, including LinReg, do not have a Series member. Instead, when we look at the Help Guide pages for Indicators, we find this section on the supported Values array,

    Originally posted by http://ninjatrader.com/support/helpGuides/nt7/values.htm
    Values is a collection holding DataSeries objects that hold the indicator's underlying calculated values. DataSeries objects held by this collection are added by calling the Add() method.
    In addition, we find in the documentation for Value, that it stores the primary Indicator's Value series, and is equivalent to Values[0].

    Thus, our NinjaTrader 7 code now looks like

    protected override void Initialize()
    {
    Add(LinReg(9));
    }

    protected override void OnBarUpdate()
    {
    DataSeries linregLL = Values[1];
    }

    In NinjaTrader 8, that becomes

    protected override void OnStateChange()
    {
    if (State == State.SetDefaults)
    {
    // ...
    }
    else if (State == State.Configure)
    {
    AddChartIndicator(LinReg(9));
    }
    }

    protected override void OnBarUpdate()
    {
    Series<double> linregLL = LinReg(9);
    }

    Please let us know if there is any other way we can help.
    Jessica P.NinjaTrader Customer Service

    Comment

    Latest Posts

    Collapse

    Topics Statistics Last Post
    Started by argusthome, 03-08-2026, 10:06 AM
    0 responses
    106 views
    0 likes
    Last Post argusthome  
    Started by NabilKhattabi, 03-06-2026, 11:18 AM
    0 responses
    54 views
    0 likes
    Last Post NabilKhattabi  
    Started by Deep42, 03-06-2026, 12:28 AM
    0 responses
    36 views
    0 likes
    Last Post Deep42
    by Deep42
     
    Started by TheRealMorford, 03-05-2026, 06:15 PM
    0 responses
    38 views
    0 likes
    Last Post TheRealMorford  
    Started by Mindset, 02-28-2026, 06:16 AM
    0 responses
    74 views
    0 likes
    Last Post Mindset
    by Mindset
     
    Working...
    X