I need to create an array of object with two variables, an integer and a double, which will change dynamically. So, the logic steps should be:
1. Set a class variable with the two variables, I've created one called Trendline
2. Set a simple constructor where variables are assigned with default values.
3. Create an array for that Class above, in the sample is called: Uptrend
4. Declare the size of that array, using the value of the constant ARRAY_SIZE
5. Initialize that array of object in the program
Here a little code, that I'd like you to see and confirm that it'd work fine.
{ // This is the class to use as object public class Trendline { private double Rate; private int Position; public Trendline() { Position=0; Rate=0.00; } } public class XXX : Strategy { private int ARRAY_SIZE; //This is the array of the class Trendline[] Uptrend; // Array of uptrends protected override void OnStateChange() { if (State == State.SetDefaults) { Description = @"xxxxxxx"; Name = "XXX"; Calculate = Calculate.OnPriceChange; } else if (State == State.Configure) { ARRAY_SIZE = 20000; Trendline[] Uptrend = new Trendline[ARRAY_SIZE]; } } protected override void OnBarUpdate() { if ( CurrentBar < 2 ) { for (int i = 0; i <ARRAY_SIZE; i++) { Uptrend[i]= new Trendline(); } return; } // Rest of code } #region Properties } }
Comment