Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Dataseries caching problem

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

    Dataseries caching problem

    Hi,
    I am developing EMA predictor. I need to obtain value of EMA 34 (204) when I change Close[0] by 1 tick, 2 ticks, 3 ticks.....30ticks
    I have this code:

    DataSeries data = new DataSeries(this);
    .
    .
    .
    // **** fill dataseries *****
    for(int i = 204; i >= 0; i--){
    data.Set(i + 1, Close
    ); // position 0 is now not filled
    }
    data.Set(0, 0) // fill data[0] by some default value
    .
    .
    .
    // *** count EMA values ******
    for(int i = 0; i <= 30; i++){
    double value = Close[0] - i*TickSize;
    data.Set(0, value);
    Print("Data[0] value = " + data[0]);
    Print("EMA value = " + Math.Round(EMA(data, 34)[0], 2));
    Print("");
    }


    The result is:

    Data[0] value = 1598
    EMA value = 1596.53

    Data[0] value = 1597.75
    EMA value = 1596.53
    .
    .
    .
    Data[0] value = 1590.75
    EMA value = 1596.53

    Data[0] value = 1590.5
    EMA value = 1596.53


    The problem is that if I changed last value in dataseries, EMA(data, 34)[0] is not recalculated. It seems that result is somewhere cached from the first calculation (the result from the first calculate is correct)

    I have found one possibility when it is working well:

    for(int i = 0; i <= 30; i++){
    data = new DataSeries(this);
    // fill dataseries again
    for(int i = 204; i >= 0; i--){
    data.Set(i + 1, Close
    ); // position 0 is now not filled
    }
    data.Set(0, 0) // fill data[0] by some default value
    .
    .
    .
    }


    In this case results are correct. But it is unacceptable because of long duration of operation - it is counted for every bar in the chart.....

    So how to resolve this problem?

    Thank you
    maitreja

    #2
    maitreja,

    Why are you trying to backfill your data series after its already been all set? You should set it on every single OnBarUpdate() and not tamper with its historical values.
    Josh P.NinjaTrader Customer Service

    Comment


      #3
      I have developed one indicator based on difference between Ema 34 and 204. This indicator draws rising or falling plot.
      So e.g. I have current Close[0] = 1600 and my indicator is rising. I need count what will happen with my indicator, when next Close will be 1599.75. Still rising? So what about price 1599.50? ..... at 1598.00 is my indicator falling? Perfect, I will draw line on this price.
      I have found two possibilities to count this - manually count EMA 34 and 204 or use EMA(dataseries data, 34)[0] and EMA(dataseries data, 204)[0] to know potential value of EMAs, if close of next bar will be changed. And the second possibility means I need to change last value in dataseries object and recount EMAs
      I hope I have explained it intelligible.
      maitreja

      Comment


        #4
        Sorry not following.

        Why would you need to replace the data set in your series with Close prices? If you just store the values in the first place you don't need to go back and replace them. It is because you are going back and changing the values of your data series that is why your EMA does not work. The EMA does not go back and recalculate itself just because the data series' data has changed.
        Josh P.NinjaTrader Customer Service

        Comment


          #5
          OK. This way seems be bad.
          So from other side
          I have Close[0] = 1600
          How can I predict value of EMA34 on the future bar if I expect Close of next bar e.g. 1595?

          Comment


            #6
            maitreja,

            I suggest you duplicate the EMA logic into your indicator/strategy directly. To extrapolate DataSeries data makes it difficult to work with.
            Josh P.NinjaTrader Customer Service

            Comment


              #7
              Thank you, Josh. I have supposed it will happen this way.
              Have a nice day
              maitreja

              Comment

              Latest Posts

              Collapse

              Topics Statistics Last Post
              Started by Geovanny Suaza, 02-11-2026, 06:32 PM
              0 responses
              571 views
              0 likes
              Last Post Geovanny Suaza  
              Started by Geovanny Suaza, 02-11-2026, 05:51 PM
              0 responses
              330 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
              548 views
              1 like
              Last Post Geovanny Suaza  
              Started by RFrosty, 01-28-2026, 06:49 PM
              0 responses
              549 views
              1 like
              Last Post RFrosty
              by RFrosty
               
              Working...
              X