Announcement
Collapse
No announcement yet.
Partner 728x90
Collapse
NinjaTrader
Bar Score Over N Bars
Collapse
X
-
Hello Aventeren,
Correct, on each OnBarUpdate() the Set() method will set the current value based on what is detailed in the Set() method, in this case barvalue.
-
Right on; so series.Set(barvalue) would populate the series[0] position?Originally posted by NinjaTrader_PatrickH View PostHello Aventeren,
Thank you for your response.
The correct way to assign the DataSeries in the OnBarUpdate() method is to use the following:
Please let me know if you have any questions.Code:series.Set(barvalue);
Leave a comment:
-
Hello Aventeren,
Thank you for your response.
The correct way to assign the DataSeries in the OnBarUpdate() method is to use the following:
Please let me know if you have any questions.Code:series.Set(barvalue);
Leave a comment:
-
Thanks, Danny; I had looked at a DataSeries, but I wasn't sure about what the best way would be to sum N bar scores. But before I get to the DataSeries sum piece, if I were to do a DataSeries instead of an Array approach, here is what I would do:Originally posted by eDanny View PostIt seems to me you are constantly changing the value in the [0] array element only and the [1] element and so on never have anything added into them. Two ways to address this is:
- Check for FirstTickOfBar and then use a loop to move all the values down, [50] = [49], [49] = [48], etc. Then assign [0] the correct value once it is calculated. Sum with loop described in 2.
- More efficiently would be to use a DataSeries which has one element per bar and are always in sync. Just simply poke the right value into DataSeriesName[0] and it will stick with that bar forever. Then use a loop to sum up the values you want by using a counter equal to your number of bars parameter.
Dan
//Variables
private DataSeries series; // Define a new DataSeries with name "series"
//Initialize()
series = new DataSeries(this); // Is this the correct way to initialize a DataSeries?
//OnBarUpdate()
series[0] = barvalue; // Would this be the correct way to assign the barvalue to the DataSeries?
So before I move to the summing part, can you please confirm that the above would be the correct way to shift to a DataSeries approach?
Thanks!
Aventeren
Leave a comment:
-
Hello Aventeren,
Thank you for your post.
Why not use a custom DataSeries to store the values for each bar? This will allow you to access the values just as you would the bar data ([0], [1], [2], etc.).
For information on the DataSeries Class in NinjaScript please visit the following link: http://www.ninjatrader.com/support/h...ries_class.htm
And an IntSeries may be more desirable for this scenario: http://www.ninjatrader.com/support/h...ries_class.htm
For a reference sample on storing information in a DataSeries please visit the following link: http://www.ninjatrader.com/support/f...ead.php?t=7299
Please let me know if I may be of further assistance.
Leave a comment:
-
Array value
It seems to me you are constantly changing the value in the [0] array element only and the [1] element and so on never have anything added into them. Two ways to address this is:
- Check for FirstTickOfBar and then use a loop to move all the values down, [50] = [49], [49] = [48], etc. Then assign [0] the correct value once it is calculated. Sum with loop described in 2.
- More efficiently would be to use a DataSeries which has one element per bar and are always in sync. Just simply poke the right value into DataSeriesName[0] and it will stick with that bar forever. Then use a loop to sum up the values you want by using a counter equal to your number of bars parameter.
Dan
Leave a comment:
-
Bar Score Over N Bars
Howdy--
I have created an indicator that assigns each bar a unique 0, 1 or 2 "score" based on a series of logic conditions. This piece is working fine.
I then wanted to create a running "score" of the unique bar "scores" over the previous n bars. To do this, I figured that creating an array to hold each bar's score would be best, as the size of the array could be limited with a parameter (ie, 10 bars, 50 bars, 100 bars, etc). I then wanted to sum this array values to create the score. But before I could get to summing the array values, I ran into a challenge associated with how to add and keep array values. Here is what I have so far:
//Variables
private int[] array; // creates int array of undefined size and without values
private int arraysize = 50; // variable to define how many values the array will hold (50 bars in this case)
//Initialize()
array = new int[arraysize]; // I initialized my int type array with a size of arraysize (50 in this case)
//OnBarUpdate()
array[0] = barvalue; // barvalue is the generic name I'm using to populate the array's current [0] value with either a 0, 1 or 2
I then used DrawText printed above the current bar to confirm that the barvalue and array[0] values were correct (they were). So what that meant to me is that I was correctly assigning the barvalue into the array's top position.
I then used DrawText to confirm that the array was correctly storing the array[1] values, too--but the array[1] value is always 0.
What am I missing about arrays that will not allow my array to keep values that I assigned to it on the previous bar? Why can't I access the array[1] values that had previously been assigned? Why is the array[1] value being reset to 0?
After I get the array to properly hold values, I'll then need to figure out how to sum the values in the array.
Thanks for your help!
Aventeren
Latest Posts
Collapse
| Topics | Statistics | Last Post | ||
|---|---|---|---|---|
|
Started by CarlTrading, 03-31-2026, 09:41 PM
|
1 response
152 views
1 like
|
Last Post
|
||
|
Started by CarlTrading, 04-01-2026, 02:41 AM
|
0 responses
89 views
1 like
|
Last Post
by CarlTrading
04-01-2026, 02:41 AM
|
||
|
Started by CaptainJack, 03-31-2026, 11:44 PM
|
0 responses
133 views
2 likes
|
Last Post
by CaptainJack
03-31-2026, 11:44 PM
|
||
|
Started by CarlTrading, 03-30-2026, 11:51 AM
|
0 responses
127 views
1 like
|
Last Post
by CarlTrading
03-30-2026, 11:51 AM
|
||
|
Started by CarlTrading, 03-30-2026, 11:48 AM
|
0 responses
107 views
0 likes
|
Last Post
by CarlTrading
03-30-2026, 11:48 AM
|

Leave a comment: