Summary
Method to calculate the value(s) of indicator for given index.
Syntax
public void Calculate(int index)
Parameters
Name | Description |
---|
Example 1
Example 1 //... [Parameter("Period", DefaultValue = 14)] public int Period { get; set; } //... public override void Calculate(int index) { // Calculate value at specified index // if the index is less than Period exit if(index < Period) return; // Maximum returns the largest number in the Series in the range [Series[index-Period], Series[index]] double high = MarketSeries.High.Maximum(Period); // Minimum returns the smallest number in the Series in the range [index - Period, index] double low = MarketSeries.Low.Minimum(Period); double center = (high + low) / 2; // Display Result of Indicator Result[index] = center; } Example 2 //... [Parameter] public DataSeries Source { get; set; } [Parameter("Periods", DefaultValue = 25)] public int Periods { get; set; } //... public override void Calculate(int index) { // Simple moving average calculation double sum = 0.0; for (int i = index - Periods + 1; i <= index; i++) { sum += Source[i]; } Result[index] = sum / Periods; } //...