Search Framework:
IndicatorBase
Namespace: WealthLab.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.

Calculation
AssumeValuesOf
public void AssumeValuesOf(TimeSeries ts)

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.


CalculatePartialValue
public virtual bool CalculatePartialValue()

Override this method in custom indicators that support partial updates in streaming charts. Calculate the indicator's value using the source TimeSeries StreamingValue, assign the result to the indicator's StreamingValue, and return true if a partial value could be calculated. The default implementation returns false.

Example Code
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;
}

Parameters
public ParameterList Parameters

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.


Populate
public abstract void Populate()

Override this method to calculate and populate the indicator's values. WealthLab calls Populate after the indicator's parameter values have been assigned.


SetDescription
public string SetDescription(bool useOptimizable)

Generates and assigns the indicator's Description based on its Abbreviation and current parameter values. If useOptimizable is true, optimizable parameter descriptions are used.



Companions
BandCompanion
public virtual IndicatorBase BandCompanion

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.


BandCompanionAbbreviation
public virtual string BandCompanionAbbreviation

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.


CompanionAdoptsParentParameters
public virtual bool CompanionAdoptsParentParameters

Determines whether companion indicators should adopt matching Parameter values from the parent indicator. The default value is true.


Companions
public virtual List<string> Companions

Returns the abbreviations of indicators that belong to the same indicator family. For example, the Directional Movement family contains ADX, ADXR, DIPlus, and DIMinus.


CreateCompanionInstances
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.


GetBarChartCompanion
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.


GetCompanionColor
public virtual WLColor GetCompanionColor(IndicatorBase parent)

Returns a color to use when plotting this indicator as a companion of the indicator specified in parent. The default value is WLColor.Empty.


HasCompanions
public bool HasCompanions

Returns true if the indicator defines companion indicators through either the Companions property or an overridden CreateCompanionInstances method.



Descriptive Properties
Abbreviation
public abstract string Abbreviation

Returns the abbreviation used to identify the indicator, for example "RSI", "SMA", or "ADX".


Description
public override string Description

Returns a description of the indicator based on its abbreviation and parameter values. IndicatorBase generates the description dynamically when necessary.


HelpDescription
public abstract string HelpDescription

Returns descriptive text explaining the indicator.


HelpURL
public virtual string HelpURL

Optionally returns a URL containing additional information about the indicator. The default value is a blank string.


LibraryName
public string LibraryName

Returns the name of the .NET assembly that contains the indicator. This can be null for custom indicators loaded from the My Indicators folder.


Name
public abstract string Name

Returns the full name of the indicator.


NameToken
public string NameToken

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.


OptimizableDescription
public string OptimizableDescription

Returns a description of the indicator using the optimizable descriptions of its Parameters.


Tooltip
public string Tooltip

Optional tooltip text that can provide additional information when the indicator is plotted.



Functional Properties
AllowPaneTagChange
public virtual bool AllowPaneTagChange

Determines whether the indicator's pane assignment can be changed dynamically in an indicator editor. The default value is true.


Bars
public BarHistory Bars

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.


CanTargetOtherIndicators
public virtual bool CanTargetOtherIndicators

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.


HasIndicatorParameters
public bool HasIndicatorParameters

Returns true if the indicator contains one or more Parameters whose ParameterType represents another indicator.


IsCalculationLengthy
public virtual bool IsCalculationLengthy

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.


IsOscillator
public bool IsOscillator

Returns true if both OverboughtLevel and OversoldLevel contain valid values.


IsPrivate
public virtual bool IsPrivate

Returns true if the indicator should be hidden from normal indicator selection interfaces. The default value is false.


IsSmoother
public virtual bool IsSmoother

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.


MidpointLevel
public double MidpointLevel

Returns the midpoint between OverboughtLevel and OversoldLevel.


OverboughtLevel
public double OverboughtLevel

The overbought level for an oscillator. The default value is Double.NaN.


OversoldLevel
public double OversoldLevel

The oversold level for an oscillator. The default value is Double.NaN.


ParentIndicator
public IndicatorBase ParentIndicator

Contains the parent indicator when this indicator uses another indicator as its source.


PeekAheadFlag
public virtual bool PeekAheadFlag

Returns true if the indicator is known to use future information in its calculation. The default value is false.


ReverseTargetValue
public double ReverseTargetValue(double value)

Returns the corresponding reversed value within the range defined by OversoldLevel and OverboughtLevel.



Locally Cached Indicator Data
LoadDataFromCache
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.


SaveHistoryToCache
public void SaveHistoryToCache(string folder, string dataKey)

Saves the indicator's current TimeSeries data to the local indicator data cache using the specified folder and dataKey.



Members for Derived Classes
AddDataSetParameter
protected Parameter AddDataSetParameter(string name)

Adds a DataSet Parameter to the indicator's Parameters. The default value is based on the currently available DataSets and the LastDataSetSelected value.


AddEnumParameter
protected Parameter AddEnumParameter(string name, Enum enumVal)

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.


AddIndicatorParameter
protected Parameter AddIndicatorParameter(string name)
protected Parameter AddIndicatorParameter(string name, string indicatorDefault)

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.


AddParameter
protected Parameter AddParameter(string name, ParameterType type, object value)

Creates a Parameter with the specified name, type, and default value, adds it to the indicator's Parameters, and returns the newly created Parameter.


AddSmootherParameter
protected Parameter AddSmootherParameter(string name, string defaultValue)

Adds a StringChoice Parameter populated with the abbreviations of available indicators that identify themselves as smoothers. Indicators marked as lengthy calculations are excluded.


GenerateParameters
protected virtual void GenerateParameters()

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.


GetSmoothedIndicator
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.



Persistence and Utility Methods
CacheKey
public static string CacheKey(params object[] arguments)

Creates a string key from the supplied arguments that can be used to identify an indicator calculation in a cache.


CleanupBBCode
public virtual string CleanupBBCode(string s)

Allows an indicator to modify generated Building Block C# code. The default implementation returns s unchanged.


ConstructorParameterString
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.


CorrectDefaults
public void CorrectDefaults(BarHistory bh)

Corrects TimeSeries Parameter default values so that TimeSeries originating from the specified BarHistory are represented by their corresponding PriceComponent values.


CorrectSourceParameterDescription
public void CorrectSourceParameterDescription(IndicatorBase ib)

Updates the description of the indicator's TimeSeries source Parameter to reflect the description of the IndicatorBase specified in ib.


DefaultConstructorCode
public string DefaultConstructorCode

Returns generated C# code representing the default construction of the indicator.


LastDataSetSelected
public static string LastDataSetSelected

Contains the name of the most recently selected DataSet. IndicatorBase uses this value when generating DataSet Parameters.


ParameterDescriptiveString
public string ParameterDescriptiveString

Returns a descriptive string containing the indicator type and the types and names of its Parameters.


Persist
public new string Persist()

Returns a string representation of the indicator's current configuration, including its abbreviation, plotting properties, pane information, and Parameter values.


PostProcessParameters
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.


ReconcileSourceIndicator
public void ReconcileSourceIndicator()

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.



Plotting
Color
public WLColor Color

The color to use when plotting the indicator.


DefaultColor
public virtual WLColor DefaultColor

Returns the indicator's default plotting color. The default implementation returns WLColor.Black.


DefaultPlotName
public virtual string DefaultPlotName

Returns the name of the plot object that should be used to render the indicator. By default, this is based on DefaultPlotStyle.


DefaultPlotStyle
public virtual PlotStyle DefaultPlotStyle

Returns the default PlotStyle for the indicator. The default implementation returns PlotStyle.Line.


ExtendedBarsRequired
public virtual int ExtendedBarsRequired

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.


GetPaneToRenderOn
public string GetPaneToRenderOn()

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.


GlyphResource
public virtual string GlyphResource

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.


LineStyle
public LineStyle? LineStyle

Optionally specifies a line style override to use when plotting the indicator.


LineWidth
public int? LineWidth

Optionally specifies a line width override to use when plotting the indicator.


PaneTag
public abstract string PaneTag

Returns the name of the chart pane in which the indicator should normally be plotted, for example "Price", "Volume", or "RSI".


PaneTagOverride
public string PaneTagOverride

Allows the indicator's normal PaneTag to be overridden in certain plotting situations.


Plot
public object Plot

Contains the plot object currently being used to render the indicator on a chart.


PlotName
public string PlotName

The name of the plot object used to render the indicator.


PlotStyle
public PlotStyle PlotStyle

The PlotStyle used to render the indicator. Assigning this property also updates PlotName.


UserAssignedPaneTag
public string UserAssignedPaneTag

Allows a user-selected chart pane to override the indicator's normal pane assignment.


UseZeroOrigin
public virtual bool UseZeroOrigin

Determines whether the chart pane containing the indicator should always include zero on its y-axis. The default value is false.