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
Comment