Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

DataSeries that are nested

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

    DataSeries that are nested

    I am a newbie to NinjaScript. In the documentation it is given that

    "Note: By default NinjaTrader limits the number of values stored for DateTimeSeries objects to 256. This drastically improves memory performance by not holding onto old values that are generally not needed."

    Consider a situation where I have say 3000 periods loaded on a chart (e.g. 1-min bars) and I have a code that has 3 DataSeries x1, x2, x3 and does the following:

    protected override void Initialize()
    {
    ....
    x1 = new DataSeries(this);
    x2 = new DataSeries(this);
    x3 = new DataSeries(this);
    ....
    }

    protected override void OnBarUpdate()
    {
    ....
    x1.Set(EMA(Close[0]-High[0], Period1)[0])

    x2.Set(EMA(High[0]-Open[0], Period2)[0])

    x3.Set( EMA( x1[0]*x2[0], Period3)[0])
    ....
    }

    In the code above, when the EMA is calculated for x3, does the EMA use only 256 bars from x1 and x2 to calculate the results for x3?

    #2
    Hello uday12,

    Using EMA(Close[0]-High[0], Period1)[0] is not valid.

    Close[0]-High[0] would be a double.

    The following overloads are possible with EMA:
    EMA(int period)
    EMA(IDataSeries input, int period)

    So you do:
    EMA(Close, Period1)[0]

    Or:
    EMA(Close, Period1)[0] - EMA(High, Period1)[0]

    http://ninjatrader.com/support/helpG...onential_e.htm

    In either case, the number of bars used for the EMA calculation will be the period. Whatever you have Period1 set to.

    If Period1 is set to 5 it will use 5 bars.

    When MaximumBarsLookBack is set to MaximumBarsLookBack.TwoHundredFiftySix, then the maximum size Period1 can be set to is 256. At that point if you supply 300, it will only use 256.
    So its up to 256.

    When MaximumBarsLookBack is Set to MaximumBarsLookBack.Infinite then it will use as many bars as you have specified with Period1.

    http://ninjatrader.com/support/helpG...rslookback.htm
    Chelsea B.NinjaTrader Customer Service

    Comment


      #3
      Chelsea, thanks.

      One more question: would this be correct syntax:

      EMA(x1*x2, Period)

      where x1 and x2 are both IDataSeries / DataSeries ?

      Comment


        #4
        Hello uday12,

        No, Dataseries cannot be multiplied together.

        This would be like multiplying an array with an array. These are not numbers they are a collection of values for each bar.

        Below is a link to the help guide on DataSeries.
        http://ninjatrader.com/support/helpG...ries_class.htm
        Chelsea B.NinjaTrader Customer Service

        Comment

        Latest Posts

        Collapse

        Topics Statistics Last Post
        Started by Geovanny Suaza, 02-11-2026, 06:32 PM
        0 responses
        558 views
        0 likes
        Last Post Geovanny Suaza  
        Started by Geovanny Suaza, 02-11-2026, 05:51 PM
        0 responses
        324 views
        1 like
        Last Post Geovanny Suaza  
        Started by Mindset, 02-09-2026, 11:44 AM
        0 responses
        101 views
        0 likes
        Last Post Mindset
        by Mindset
         
        Started by Geovanny Suaza, 02-02-2026, 12:30 PM
        0 responses
        546 views
        1 like
        Last Post Geovanny Suaza  
        Started by RFrosty, 01-28-2026, 06:49 PM
        0 responses
        547 views
        1 like
        Last Post RFrosty
        by RFrosty
         
        Working...
        X