IIndicatorsAccessor.GetIndicator
method · IIndicatorsAccessor · cAlgo.API.Internals
DesktopCLICloud
Initializes the custom indicator
Overloads
GetIndicator(object[] parameterValues)
Initializes the custom indicator
TIndicator GetIndicator(object[] parameterValues)
api.Indicators.GetIndicator(parameterValues: list[object]) -> TIndicator
Parameters
| Name | C# type | Python type | Description |
|---|---|---|---|
parameterValues | object[] | list[object] | The custom indicator parameter values or an anonymous object that contains custom indicator parameter values. |
Returns TIndicator — Custom indicator instance
Examples
using cAlgo.API;
namespace cAlgo
{
// SampleSMA and SampleSmaBot are separate algo projects: the config.json tab is the SampleSMA indicator's,
// and the cBot references the SampleSMA project
public partial class SampleSMA : Indicator
{
private SimpleMovingAverage _sma;
protected override void Initialize() => _sma = Indicators.SimpleMovingAverage(Source, Periods);
public override void Calculate(int index) => Result[index] = _sma.Result[index];
}
public partial class SampleSmaBot : Robot
{
protected override void OnStart()
{
// Parameter values are passed in the order the custom indicator declares them
var sampleSma = Indicators.GetIndicator<SampleSMA>(Bars.ClosePrices, 20);
Print("SampleSMA: {0}", sampleSma.Result.LastValue);
}
}
}
# The SampleSMA indicator project must be referenced by this algo; the config.json tab is SampleSMA's
sampleSma = api.GetIndicator("SampleSMA", api.Bars.ClosePrices, 20)
api.Print(f"SampleSMA: {sampleSma.Result.LastValue}")
{
"AccessRights": "None",
"Parameters": [
{
"Name": "Source",
"Type": "DataSeries"
},
{
"Name": "Periods",
"Type": "Integer",
"DefaultValue": 14
}
],
"LineOutputs": [
{
"Name": "Result",
"DisplayName": "Main"
}
]
}
GetIndicator(Bars bars, object[] parameterValues)
Initializes the custom indicator
TIndicator GetIndicator(Bars bars, object[] parameterValues)
api.Indicators.GetIndicator(bars: Bars, parameterValues: list[object]) -> TIndicator
Parameters
| Name | C# type | Python type | Description |
|---|---|---|---|
bars | Bars | Bars | The Bars that will be used by indicator, you can pass another timeframe/symbol bars |
parameterValues | object[] | list[object] | The custom indicator parameter values or an anonymous object that contains custom indicator parameter values. |
Returns TIndicator — Custom indicator instance
Examples
using cAlgo.API;
namespace cAlgo
{
// SampleSMA and DailySmaBot are separate algo projects: the config.json tab is the SampleSMA indicator's,
// and the cBot references the SampleSMA project
public partial class SampleSMA : Indicator
{
private SimpleMovingAverage _sma;
protected override void Initialize() => _sma = Indicators.SimpleMovingAverage(Bars.ClosePrices, Periods);
public override void Calculate(int index) => Result[index] = _sma.Result[index];
}
public partial class DailySmaBot : Robot
{
protected override void OnStart()
{
var dailyBars = MarketData.GetBars(TimeFrame.Daily);
// The custom indicator is calculated on the daily bars instead of the chart bars
var dailySma = Indicators.GetIndicator<SampleSMA>(dailyBars, 20);
Print("Daily SMA(20): {0}", dailySma.Result.LastValue);
}
}
}
# The SampleSMA indicator project must be referenced by this algo; the config.json tab is SampleSMA's
dailySma = api.GetIndicator("SampleSMA", api.MarketData.GetBars(TimeFrame.Daily), 20)
{
"AccessRights": "None",
"Parameters": [
{
"Name": "Periods",
"Type": "Integer",
"DefaultValue": 14
}
],
"LineOutputs": [
{
"Name": "Result",
"DisplayName": "Main"
}
]
}