Welcome to NexusFi: the best trading community on the planet, with over 150,000 members Sign Up Now for Free
Genuine reviews from real traders, not fake reviews from stealth vendors
Quality education from leading professional traders
We are a friendly, helpful, and positive community
We do not tolerate rude behavior, trolling, or vendors advertising in posts
We are here to help, just let us know what you need
You'll need to register in order to view the content of the threads and start contributing to our community. It's free for basic access, or support us by becoming an Elite Member -- see if you qualify for a discount below.
-- Big Mike, Site Administrator
(If you already have an account, login at the top of the page)
Broker: Mirus (Broker), Continuum (Data), Dorman (Clearing)
Trading: Futures
Posts: 202 since Mar 2013
Thanks Given: 428
Thanks Received: 202
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
Can you help answer these questions from other members on NexusFi?
Broker: Mirus (Broker), Continuum (Data), Dorman (Clearing)
Trading: Futures
Posts: 202 since Mar 2013
Thanks Given: 428
Thanks Received: 202
I've been thinking about this, and maybe I could also use a DataSeries to store the barvalue numbers, but if I were to do this, I'm not sure how I would sum the barvalues from N bars ago.
But before I get to the DataSeries summing part, would this be the correct way to implement and get the barvalues to the DataSeries?
//Variables
private DataSeries series; // Creates new DataSeries
//Initialize()
series = new DataSeries;
//OnBarUpdate()
series[0] = barvalue; // Populate the current series slot with the barvalue
Yes, you will need to create a dataseries then use the sum function to get the totals.
Just a thought, but you may look at analyzing negative and positive values separately and/or calculating a ratio of the two, then each dataseries would be something like,
Broker: Mirus (Broker), Continuum (Data), Dorman (Clearing)
Trading: Futures
Posts: 202 since Mar 2013
Thanks Given: 428
Thanks Received: 202
So I got this figured out how to use a DataSeries. Here is the code I used:
//Variables
private DataSeries series;
private int sumlength = 10; // Defines how many bars I want in my sum (10 in this case)
private double seriessum; // This is the variable that will hold the sum IT HAS TO BE TYPE DOUBLE BC IT WILL BE HOLDING A DATASERIES!!!
//Initialize()
series = new DataSeries(this); // Need to initialize the DataSeries
// OnBarUpDate()
series.Set(barscore); // Use .Set(variable) to populate the DataSeries (barscore is the score value assigned to each bar)
seriessum = SUM(series, sumlength)[0]; // This is how you sum the score over sumlength bars (10 in this case) IT IS IMPORTANT TO ADD ON THE [0] AFTER THE SUM()...So Don't forget!!!!
So with the above, I am able to sum my bar scores of N bars.
My next challenge is going to be plotting these values. Do make the seriessum values publicly available, in Properties I used a:
[Browsable(false)]
[XmlIgnore()]
public double Seriessum
{
get { return seriessum; }
}
The above should make the Seriessum values available for use in another indicator.
So I created a new indicator, add referenced the IndicatorName (generic name) in the new indicator--and added in a new Plot.
//Initialize()
Add(IndicatorName(parameter1, parameter2, etc)); // Adds the IndicatorName to the new indicator so that I can grab the public values.
// OnBarUpdate()
Add(new Plot(Color.Green, "seriessum"); // From what I understand, this defines the plot for Values[0]
Okay, so I think the above is right. Next, how to I actually plot the scores in this indicator?