Hi -
Is there a way to determine the length of a variable of type VariableSeries<>? If I am looping through each bar in Bars, I can know when to stop with Bars.CurrentBar. How can I ensure that I do not go "out of bounds" when looping through values of a VariableSeries<> variable?
Thanks,
Mark
Length of VariableSeries
- Henry MultiСharts
- Posts: 9165
- Joined: 25 Aug 2011
- Has thanked: 1264 times
- Been thanked: 2957 times
Re: Length of VariableSeries
Hello Mark,
You need to use MaxBarsBack to avoid going "out of bounds" (constantly increasing MaxBarsBack value). For example:
You need to use MaxBarsBack to avoid going "out of bounds" (constantly increasing MaxBarsBack value). For example:
Code: Select all
for(int i = 0; i < ExecInfo.MaxBarsBack; i++)
{
double a = Bars.Close[i];
}
-
- Posts: 14
- Joined: 23 Jan 2013
- Has thanked: 4 times
Re: Length of VariableSeries
Thanks, Henry. What if I had a static method (inside a static class) which took VariableSeries<> myVariable as a parameter and returned, for example, the average of the latest 5 values of myVariable? As far as I know, ExecInfo would not be available to this function. I suppose I could pass MaxBarsBack as an additional parameter, but is there a way do determine if there are at least 5 values within myVariable in my example above?
Thanks,
Mark
Thanks,
Mark
- Henry MultiСharts
- Posts: 9165
- Joined: 25 Aug 2011
- Has thanked: 1264 times
- Been thanked: 2957 times
Re: Length of VariableSeries
MaxBarsBack is your min and max amount of bars that are required for calculation. If you do not have enough bars specified by MaxBarsBack then your study will not be calculated.