Skip to content

ChartIndicators.Add

method · ChartIndicators · cAlgo.API

DesktopCLICloud

Adds a new indicator to a chart.

Environment behaviour

Cloud — not supported. Always empty: Count is 0, Add returns null, Remove returns false, and the events never fire.

Overloads

Add(string name, object[] parameterValues)

Adds a new indicator to a chart.

ChartIndicator Add(string name, object[] parameterValues)
api.ChartIndicators.Add(name: str, parameterValues: list[object]) -> ChartIndicator

Parameters

Name C# type Python type Description
name string str The name of an indicator.
parameterValues object[] list[object] The indicator parameter values or an anonymous object that contains indicator parameter values.

Returns ChartIndicator — An ChartIndicator representing the added indicator instance.

Examples

var sma = ChartIndicators.Add("Simple Moving Average", Bars.ClosePrices, 12);
var ema = ChartIndicators.Add("Exponential Moving Average", new { Source = Bars.ClosePrices, Periods = 26 });
Print("Added {0} and {1}", sma.Name, ema.Name);
sma = api.ChartIndicators.Add("Simple Moving Average", api.Bars.ClosePrices, 12)
ema = api.ChartIndicators.Add("Exponential Moving Average", api.Bars.ClosePrices, 26)
api.Print(f"Added {sma.Name} and {ema.Name}")

Add(IndicatorType type, object[] parameterValues)

Adds a new indicator to a chart.

ChartIndicator Add(IndicatorType type, object[] parameterValues)
api.ChartIndicators.Add(type: IndicatorType, parameterValues: list[object]) -> ChartIndicator

Parameters

Name C# type Python type Description
type IndicatorType IndicatorType The type of Indicator, you can get IndicatorType from AlgoRegistry.
parameterValues object[] list[object] The indicator parameter values or an anonymous object that contains indicator parameter values.

Returns ChartIndicator — An ChartIndicator representing the added indicator instance.

Examples

if (AlgoRegistry.Get("Simple Moving Average", AlgoKind.StandardIndicator) is IndicatorType smaType)
{
    var sma = ChartIndicators.Add(smaType, new { Source = Bars.ClosePrices, Periods = 12 });
    Print("Added indicator: {0}", sma.Name);
}
smaType = api.AlgoRegistry.Get("Simple Moving Average", AlgoKind.StandardIndicator)
if smaType is not None:
    sma = api.ChartIndicators.Add(smaType, api.Bars.ClosePrices, 12)
    api.Print(f"Added indicator: {sma.Name}")

See also