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

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 usazencort, Today, 01:16 AM
              0 responses
              1 view
              0 likes
              Last Post usazencort  
              Started by kaywai, 09-01-2023, 08:44 PM
              5 responses
              602 views
              0 likes
              Last Post NinjaTrader_Jason  
              Started by xiinteractive, 04-09-2024, 08:08 AM
              6 responses
              22 views
              0 likes
              Last Post xiinteractive  
              Started by Pattontje, Yesterday, 02:10 PM
              2 responses
              20 views
              0 likes
              Last Post Pattontje  
              Started by flybuzz, 04-21-2024, 04:07 PM
              17 responses
              230 views
              0 likes
              Last Post TradingLoss  
              Working...
              X