Length of VariableSeries

Questions about MultiCharts .NET and user contributed studies.
markwit229
Posts: 14
Joined: 23 Jan 2013
Has thanked: 4 times

Length of VariableSeries

Postby markwit229 » 04 Apr 2013

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

User avatar
Henry MultiСharts
Posts: 9165
Joined: 25 Aug 2011
Has thanked: 1264 times
Been thanked: 2957 times

Re: Length of VariableSeries

Postby Henry MultiСharts » 05 Apr 2013

Hello Mark,

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];
}

markwit229
Posts: 14
Joined: 23 Jan 2013
Has thanked: 4 times

Re: Length of VariableSeries

Postby markwit229 » 05 Apr 2013

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

User avatar
Henry MultiСharts
Posts: 9165
Joined: 25 Aug 2011
Has thanked: 1264 times
Been thanked: 2957 times

Re: Length of VariableSeries

Postby Henry MultiСharts » 08 Apr 2013

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.


Return to “MultiCharts .NET”