---
id: "M:cAlgo.API.Indicator.AddToChart"
kind: "method"
type: "T:cAlgo.API.Indicator"
url: "https://help.ctrader.com/ctrader-algo/references/General/Indicator/AddToChart/"
---

> Documentation index for agents: https://help.ctrader.com/ctrader-algo/llms.txt · machine index: https://help.ctrader.com/ctrader-algo/api.json

# Indicator.AddToChart

Member of [Indicator](https://help.ctrader.com/ctrader-algo/references/General/Indicator/index.md).

## AddToChart()

Adds current indicator to chart if not added yet.

Environments: Desktop supported · CLI supported · Cloud supported.

C#:

```csharp
public ChartIndicator AddToChart()
```

Python:

```python
api.AddToChart() -> ChartIndicator
```

### Returns

`ChartIndicator` — Chart Indicator

### Examples

C#:

```csharp
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);
    }
}
```

Python:

```python
# 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")
```

config.json:

```json
{
  "AccessRights": "None",
  "IsOverlay": true,
  "LineOutputs": [
    {
      "Name": "Result",
      "DisplayName": "Main"
    }
  ]
}
```

