Skip to content

Indicator.AddToChart

method · Indicator · cAlgo.API

DesktopCLICloud

Adds current indicator to chart if not added yet.

Definition

public ChartIndicator AddToChart()
api.AddToChart() -> ChartIndicator

Returns ChartIndicator — Chart Indicator

Examples

using cAlgo.API;

namespace cAlgo;

// HighLowMiddle and HighLowMiddleBot are separate algo projects: the config.json tab is the HighLowMiddle
// indicator's, and the cBot references the HighLowMiddle project
public partial class HighLowMiddle : Indicator
{
    public override void Calculate(int index)
    {
        Result[index] = (Bars.HighPrices[index] + Bars.LowPrices[index]) / 2;
    }
}

public partial class HighLowMiddleBot : Robot
{
    protected override void OnStart()
    {
        var indicator = Indicators.GetIndicator<HighLowMiddle>();
        var chartIndicator = indicator.AddToChart();
        if (chartIndicator != null)
            Print("Added {0} to the chart", chartIndicator.Name);
    }
}
# The HighLowMiddle indicator project must be referenced by this cBot; the config.json tab is HighLowMiddle's
indicator = api.GetIndicator("HighLowMiddle")
chartIndicator = indicator.AddToChart()
if chartIndicator is not None:
    api.Print(f"Added {chartIndicator.Name} to the chart")
{
  "AccessRights": "None",
  "IsOverlay": true,
  "LineOutputs": [
    {
      "Name": "Result",
      "DisplayName": "Main"
    }
  ]
}