API documentation, members, signatures, and C# examples.
Search the framework
Find classes, members, and documentation.
NamespaceWealthLab.Indicators
Parent
TimeSeries
IndicatorBase is the base class for technical indicators in WealthLab. It derives from TimeSeries and implements the INamed interface. In addition to the DateTimes and Values inherited from TimeSeries, IndicatorBase provides the metadata, parameters, plotting information, companion indicators, and calculation methods used by the WealthLab indicator subsystem.
Developers creating custom indicators derive their classes from IndicatorBase and implement the required descriptive properties, parameters, and calculation logic.
Causes the indicator to assume the values of the TimeSeries specified in ts. The indicator's Values are cleared and replaced with the source values. Its DateTimes are also synchronized with the source when necessary.
Override this method in custom indicators that support partial updates in streaming charts.
Calculate the indicator's value using the source TimeSeriesStreamingValue, assign the result to the indicator's StreamingValue, and return true if a partial value could be calculated. The default implementation returns false.
C# example
public override bool CalculatePartialValue()
{
StreamingValue = Double.NaN;
TimeSeries source = Parameters[0].AsTimeSeries;
if (Double.IsNaN(source.StreamingValue))
return false;
int period = Parameters[1].AsInt;
if (period >= source.Count)
return false;
double sum = 0;
for (int n = 0; n < period - 1; n++)
{
int idx = source.Count - 1 - n;
sum += source[idx];
}
sum += source.StreamingValue;
StreamingValue = sum / period;
return true;
}
Contains the Parameter instances that define the indicator's inputs and settings. Typical parameters include a source TimeSeries, period, smoothing method, or other values required to calculate the indicator.
Override this method to calculate and populate the indicator's values. WealthLab calls Populate after the indicator's parameter values have been assigned.
Generates and assigns the indicator's Description based on its Abbreviation and current parameter values. If useOptimizable is true, optimizable parameter descriptions are used.
Returns the companion indicator used when rendering an indicator with a bands plot style. For example, an upper band indicator can return the corresponding lower band indicator.
Returns the abbreviation of the indicator's band companion. The default implementation attempts to match indicator abbreviations ending in "Upper" with the corresponding "Lower" indicator, and vice versa. If no such match exists, the first entry in Companions is used when available.
Returns the abbreviations of indicators that belong to the same indicator family. For example, the Directional Movement family contains ADX, ADXR, DIPlus, and DIMinus.
public virtual List<IndicatorBase> CreateCompanionInstances()
Creates and returns the indicator's companion instances. Override this method when companion indicators require special construction or use parameter values that differ from those of the parent indicator.
When using this approach, you will typically also override CompanionAdoptsParentParameters to return false.
public virtual IndicatorBase GetBarChartCompanion(PriceComponent pc)
Override this method for indicators that represent Open, High, Low, and Close components and are intended to be rendered using a bar-chart style.
The pc parameter indicates which PriceComponent is being requested. An implementation can return the current indicator for PriceComponent.Close and corresponding companion indicators for Open, High, and Low.
Returns a description of the indicator based on its abbreviation and parameter values. IndicatorBase generates the description dynamically when necessary.
Returns a token derived from the first word of the indicator's Name, used internally for Strategy AI matching. For names beginning with certain common words, the indicator's Abbreviation is used instead.
Returns the BarHistory associated with the indicator. If no BarHistory has been explicitly assigned, IndicatorBase attempts to obtain it from the first Parameter when that Parameter is of type BarHistory.
Returns true if the indicator can use another indicator as its source. The default implementation returns true when the first Parameter is a TimeSeries parameter.
Returns true if calculation of the indicator is considered lengthy. Tools such as the Indicator Profiler can use this information when working with indicators. The default value is false.
Returns true if the indicator is considered a smoother. Smoothers typically accept a TimeSeries as their first Parameter and smooth that source in some manner. Examples include SMA and EMA. The default value is false.
Determines whether the indicator is eligible to be exposed as a Position Metric. The default value is the indicator�s IsOscillator value, so oscillators are considered Position Metric candidates by default.
Override this property to explicitly include or exclude an indicator:
C# example
public override bool PositionMetricCandidate => true;
public bool LoadDataFromCache(string folder, string dataKey, DateTime startDate, DateTime endDate, int maxBars)
Loads locally cached indicator data from the specified folder and dataKey.
Returns true when the data needs to be obtained or updated. Returns false when suitable cached data is available. When cached data is available, the indicator assumes its values using AssumeValuesOf.
This method is useful for indicators that rely on externally obtained data that can be persisted locally, such as economic or interest-rate data.
Adds a DataSetParameter to the indicator's Parameters. The default value is based on the currently available DataSets and the LastDataSetSelected value.
Adds a StringChoice Parameter whose choices correspond to the values of the enumerated type represented by enumVal. The default value is the current value of enumVal.
Adds an indicator Parameter to the indicator's Parameters.
The first overload creates an Indicator Parameter whose default indicator is RSI. The second overload lets you specify the default indicator abbreviation in indicatorDefault.
Adds a StringChoice Parameter populated with the abbreviations of available indicators that identify themselves as smoothers. Indicators marked as lengthy calculations are excluded.
Override this method to create the Parameters required by your custom indicator. It is called by the IndicatorBase constructor.
Use methods such as AddParameter, AddIndicatorParameter, AddDataSetParameter, AddSmootherParameter, and AddEnumParameter to populate the ParameterList.
protected IndicatorBase GetSmoothedIndicator(string name, TimeSeries source, int period)
Creates and calculates a smoother indicator with the specified name, source, and period.
Returns the resulting IndicatorBase instance, or null if the smoother cannot be created or calculated.
public string ConstructorParameterString(bool parametersOnly = false)
Returns a string representing the indicator's current Parameter values in a form suitable for constructing the indicator in generated C# code.
If parametersOnly is false, the indicator class name and parentheses are included.
Corrects TimeSeriesParameter default values so that TimeSeries originating from the specified BarHistory are represented by their corresponding PriceComponent values.
Returns a string representation of the indicator's current configuration, including its abbreviation, plotting properties, pane information, and Parameter values.
public virtual void PostProcessParameters(ParameterList p)
Called after Parameters are loaded or assigned, allowing an indicator to perform additional processing on the ParameterList. The default implementation performs no processing.
Reconciles Parameters that use another indicator as their TimeSeries source. When a ParentIndicator exists, the source Parameter is converted to an IndicatorSource Parameter and assigned the parent indicator's description.
Returns the number of extended bars the indicator requires to the right of the chart data. Extended bars allow an indicator to project values into the future. The default value is zero.
Returns the pane tag that should ultimately be used to render the indicator. This method considers UserAssignedPaneTag, PaneTagOverride, the indicator's PaneTag, and whether the source TimeSeries represents Volume.
Optionally returns the name of an embedded image resource that should be used to represent the indicator in the user interface. The default value is null.