Constructors |
Technical indicators typically have the following types of constructors:
Constructor without parameters: It sets default values for all input parameters.
Constructor with input parameters: As a rule, indicators are calculated on certain number values called period. Such constructors allow programmer to specify periods and other parameters for calculating indicators.
Constructor with time periods: If you want to calculate indicator values using nonperiodic data points such as ticks, you can use this constructor with a time window.
As an example, suppose we want to use a Simple Moving Average (Sma) indicator. It has the following constructors:
Sma – sets default values, for Sma the default value is 14.
Sma(Int32) – sets values for period
Sma(TimeSpan) – sets time period. This constructor is used in case you want to calculate the indicator value by time period. For instance, you can use it to calculate simple moving average of one hour.
The following expression creates a new instance. In this case period of this indicator will be set by default; for SMA default is 14:
1Sma sma = new Sma();
In the case below we set period 28 for Sma:
1Sma sma = new Sma(28);
In the next case, indicator values will be calculated as average of all values during the last minute:
1Sma sma = new Sma(new TimeSpan(0,1,0));