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.
Announcement
Collapse
No announcement yet.
Partner 728x90
Collapse
NinjaTrader
Series<T> not saving values properly
Collapse
X
-
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
- Likes 1
-
Yep, I get that. I'm trying to suggest a default initial value be storedOriginally posted by Stanfillirenfro View PostThe idea in my case is to save numbers ONLY after a condition is met. And only the number everytime the condition is met.
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.
What values? You mean values saved from an MA or double.MaxValue?Originally posted by Stanfillirenfro View PostAfter printing the expected numbers, the output window shows values even after the condition is met and also before!!!
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?
Again, which values do you mean?Originally posted by Stanfillirenfro View PostLet'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?
Actual values from each slot in the Series<T> or the return value from MIN?
Yep, it does. One value per slot, er, I mean, bar.Originally posted by Stanfillirenfro View PostI thought Series<T> saves values for every single bars.
I'm confused. You say 'only when the condition is met', but if your logic isOriginally posted by Stanfillirenfro View PostI am looking for an array able to save the values ONLY when the condition is met. So I used aand saved values inside. The problem is that every single bar is concerned.Code:private ArrayList arlistLow = new ArrayList();
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
-
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: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.Code:private Series<double> BarLow;
Could you please give an example?
Comment
-
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
|
||
|
Started by Geovanny Suaza, 02-11-2026, 05:51 PM
|
0 responses
324 views
1 like
|
Last Post
|
||
|
Started by Mindset, 02-09-2026, 11:44 AM
|
0 responses
101 views
0 likes
|
Last Post
by Mindset
02-09-2026, 11:44 AM
|
||
|
Started by Geovanny Suaza, 02-02-2026, 12:30 PM
|
0 responses
545 views
1 like
|
Last Post
|
||
|
Started by RFrosty, 01-28-2026, 06:49 PM
|
0 responses
547 views
1 like
|
Last Post
by RFrosty
01-28-2026, 06:49 PM
|

Comment