Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Series<T> not saving values properly

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

    #16
    Hello Stanfillirenfro,

    If you need to store a value for some bars and not all bars but you need to remember the bar number it was on, one choice might be to use a Dictionary. The bar number could be the key and the value you want to store would be the value.
    Chelsea B.NinjaTrader Customer Service

    Comment


      #17
      Originally posted by Stanfillirenfro View Post
      The idea in my case is to save numbers ONLY after a condition is met. And only the number everytime the condition is met.
      Yep, I get that. I'm trying to suggest a default initial value be stored
      ahead of time, in every [0] of the Series, such that if your condition is
      not met, then that default value remains in that position.

      Because you're using MIN, I'm suggesting double.MaxValue is an ideal
      initial default value.

      Originally posted by Stanfillirenfro View Post
      After printing the expected numbers, the output window shows values even after the condition is met and also before!!!
      What values? You mean values saved from an MA or double.MaxValue?

      If a slot has an MA value, then the condition was true for that bar.
      If a slot has double.MaxValue, then the condition was false for that bar.

      Right?

      Originally posted by Stanfillirenfro View Post
      Let's say I have six consecutives last bars. The condition is met on the fifth bar from the left, that means Bar[1]. Let's say after a certain time, we have 10 MORE bars on the char and the condition is still in place. The output window shows that the numbers are still printed even for the sixth, seventh eigth... bars. But these bars are not concerned by the condition. Why is the numbers saved for them?
      Again, which values do you mean?
      Actual values from each slot in the Series<T> or the return value from MIN?

      Originally posted by Stanfillirenfro View Post
      I thought Series<T> saves values for every single bars.
      Yep, it does. One value per slot, er, I mean, bar.

      Originally posted by Stanfillirenfro View Post
      I am looking for an array able to save the values ONLY when the condition is met. So I used a
      Code:
      private ArrayList arlistLow = new ArrayList();
      and saved values inside. The problem is that every single bar is concerned.
      I'm confused. You say 'only when the condition is met', but if your logic is
      trying to gather values on per bar basis, then a Series still seems appropriate.

      I'm trying to expand your thinking -- what happens when the condition is not met?

      I'm trying to suggest a default initial value, as a just-in-case value, such that the
      default value doesn't overwhelm the return value from MIN.

      An excellent default value is some ridiculously large number, higher than anything
      any MA would reasonably return, eg, double.MaxValue. That way, when you
      use MIN to find the lowest value accumulated over the last 10 bars, MIN should
      never actually return double.MaxValue, but if it does, that means the condition
      was not met over any of those last 10 bars.



      Comment


        #18
        Many thanks bltdavid for your help.

        To be honest, I have never use double.MaxValue. For example, for Series<T>, one can declare it as followed:
        Code:
        private Series<double> BarLow;
        What could be the initilization of the bars to double.MaxValue? I made a quick research on internet, but I can not find anywhere the initialization to double.MaxValue.

        Could you please give an example?

        Comment


          #19
          Initialize each slot early inside OnBarUpdate,

          BarLow[0] = double.MaxValue;

          then, later, your 'condition is met' logic overwrites this
          value with something else.

          Finally, when you use MIN,
          if (MIN(BarLow, 10)[0] == double.MaxValue) is true,
          that means no values in the last 10 bars met the condition to have
          their BarLow[0] get re-assigned to a different value.

          Comment

          Latest Posts

          Collapse

          Topics Statistics Last Post
          Started by Geovanny Suaza, 02-11-2026, 06:32 PM
          0 responses
          557 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
          545 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