Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Indicator for my own DataSeries

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

    Indicator for my own DataSeries

    Hi, I would like to create my own IDataSeries, in my strategy:
    For example, a series of consecutive numbers like this, in OnBarUpdate():

    for(int i = 0; i <= 20; i++)
    ds.Set(i,i
    );

    in Initialize(): ds = new DataSeries(this);
    (where ds was defined as: private DataSeries ds)

    Now, when I try to do
    double
    f = EMA(ds, 3)[0];
    the results of 'f' seems not to hold the right EMA for those last 3 numbers.
    So how can I do such a thing, or what is wrong...
    Thanks in advance.
    Arnon.

    Last edited by Arnon_B; 03-21-2014, 01:31 AM.

    #2
    Arnon, what contents would you get printed then for your series? Looks like you only set the current bar then to 0 - which I would expect to be seen for printing DS[0] (DS[1] being 1 and so on).

    Comment


      #3
      Hi Bertrand,
      this is my code in OnBarUpdate:
      for(int i = 0; i <= 20; i++)
      ds.Set(i,i); // Create my series

      double f = EMA(ds, 3)[0]; // Takes ema for last bar
      for(int i = 20; i >= 0; i--)
      Print(ds[i] +
      ", "); // Printing series backwards
      Print(
      "f = " + f);

      And at the output window I get (for example at the last time
      20,
      19,
      18,
      17,
      16,
      15,
      14,
      13,
      12,
      11,
      10,
      9,
      8,
      7,
      6,
      5,
      4,
      3,
      2,
      1,
      0,
      f = 0


      But f (EMA) = 0 is not seems to be right.
      Thanks.

      Comment


        #4
        Arnon_B,

        This is because the EMA will use a previous value for its calculations, and since the most recent occurrence in the data series is 0, this will always return 0.
        Cal H.NinjaTrader Customer Service

        Comment


          #5
          Originally posted by Arnon_B View Post
          Hi Bertrand,
          this is my code in OnBarUpdate:
          for(int i = 0; i <= 20; i++)
          ds.Set(i,i); // Create my series

          double f = EMA(ds, 3)[0]; // Takes ema for last bar
          for(int i = 20; i >= 0; i--)
          Print(ds[i] +
          ", "); // Printing series backwards
          Print(
          "f = " + f);

          And at the output window I get (for example at the last time
          20,
          19,
          18,
          17,
          16,
          15,
          14,
          13,
          12,
          11,
          10,
          9,
          8,
          7,
          6,
          5,
          4,
          3,
          2,
          1,
          0,
          f = 0


          But f (EMA) = 0 is not seems to be right.
          Thanks.

          That is a result of NT trying to be efficient by caching the the value returned by the class and reusing it. It is generally not a good idea to be changing values of a DataSeries in the past (Plots are a slightly different kettle of fish).

          If you insist on doing what you are trying to do, you will have to dispose of the old cached class and force a new copy to be loaded.
          Code:
          for(int i = 0; i <= 20; i++)
          ds.Set(i,i); // Create my series
          [B][COLOR=Blue]EMA(ds, 3).Dispose();[/COLOR][/B]
          double f = EMA(ds, 3)[0]; // Takes ema for last bar
          Print("CurrentBar: " + CurrentBar);
          for(int i = 20; i >= 0; i--)
          Print(ds[i] + ", "); // Printing series backwards
          Print("f = " + f);

          Comment

          Latest Posts

          Collapse

          Topics Statistics Last Post
          Started by Geovanny Suaza, 02-11-2026, 06:32 PM
          0 responses
          607 views
          0 likes
          Last Post Geovanny Suaza  
          Started by Geovanny Suaza, 02-11-2026, 05:51 PM
          0 responses
          353 views
          1 like
          Last Post Geovanny Suaza  
          Started by Mindset, 02-09-2026, 11:44 AM
          0 responses
          105 views
          0 likes
          Last Post Mindset
          by Mindset
           
          Started by Geovanny Suaza, 02-02-2026, 12:30 PM
          0 responses
          560 views
          1 like
          Last Post Geovanny Suaza  
          Started by RFrosty, 01-28-2026, 06:49 PM
          0 responses
          561 views
          1 like
          Last Post RFrosty
          by RFrosty
           
          Working...
          X