---
id: "M:cAlgo.API.ChartArea.AddControl(cAlgo.API.ControlBase)"
kind: "method"
type: "T:cAlgo.API.ChartArea"
url: "https://help.ctrader.com/ctrader-algo/references/Chart/ChartArea/AddControl/"
---

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

# ChartArea.AddControl

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

## AddControl(ControlBase control)

Adds a chart control from the Control Base to the main chart area or to the indicator area.

Environments: Desktop supported · CLI not supported · Cloud not supported.

- CLI: The control is accepted but never displayed: the CLI displays no chart.
- Cloud: The control is accepted but never displayed: the cloud displays no chart.

C#:

```csharp
void AddControl(ControlBase control)
```

Python:

```python
chartArea.AddControl(control: ControlBase) -> None
```

### Parameters

- `control` (`ControlBase`, Python `ControlBase`): The control that will be added

### Examples

C#:

```csharp
var button = new Button { Text = "Buy", HorizontalAlignment = HorizontalAlignment.Right, VerticalAlignment = VerticalAlignment.Top };
button.Click += args => ExecuteMarketOrder(TradeType.Buy, SymbolName, Symbol.VolumeInUnitsMin);
Chart.AddControl(button);
```

Python:

```python
button = Button()
button.Text = "Buy"
button.HorizontalAlignment = HorizontalAlignment.Right
button.VerticalAlignment = VerticalAlignment.Top
button.Click += lambda args: api.ExecuteMarketOrder(TradeType.Buy, api.SymbolName, api.Symbol.VolumeInUnitsMin)
api.Chart.AddControl(button)
```

## AddControl(ControlBase control, int barIndex, double y)

Adds a chart control to chart / indicator area on absolute bar index and price (x,y) coordinates.

Environments: Desktop supported · CLI not supported · Cloud not supported.

- CLI: The control is accepted but never displayed: the CLI displays no chart.
- Cloud: The control is accepted but never displayed: the cloud displays no chart.

C#:

```csharp
void AddControl(ControlBase control, int barIndex, double y)
```

Python:

```python
chartArea.AddControl(control: ControlBase, barIndex: int, y: float) -> None
```

### Parameters

- `control` (`ControlBase`, Python `ControlBase`): The control that will be added
- `barIndex` (`int`, Python `int`): Bar Index
- `y` (`double`, Python `float`): Price

### Examples

C#:

```csharp
var label = new TextBlock { Text = "High", ForegroundColor = Color.Yellow };
Chart.AddControl(label, Bars.Count - 1, Bars.HighPrices.LastValue);
```

Python:

```python
label = TextBlock()
label.Text = "High"
label.ForegroundColor = Color.Yellow
api.Chart.AddControl(label, api.Bars.Count - 1, api.Bars.HighPrices.LastValue)
```

## AddControl(ControlBase control, DateTime time, double y)

Adds a chart control to chart / indicator area on absolute time and price (x,y) coordinates.

Environments: Desktop supported · CLI not supported · Cloud not supported.

- CLI: The control is accepted but never displayed: the CLI displays no chart.
- Cloud: The control is accepted but never displayed: the cloud displays no chart.

C#:

```csharp
void AddControl(ControlBase control, DateTime time, double y)
```

Python:

```python
chartArea.AddControl(control: ControlBase, time: DateTime, y: float) -> None
```

### Parameters

- `control` (`ControlBase`, Python `ControlBase`): The control that will be added
- `time` (`DateTime`, Python `DateTime`): Time
- `y` (`double`, Python `float`): Price

### Examples

C#:

```csharp
var label = new TextBlock { Text = "Low", ForegroundColor = Color.Orange };
Chart.AddControl(label, Bars.OpenTimes.LastValue, Bars.LowPrices.LastValue);
```

Python:

```python
label = TextBlock()
label.Text = "Low"
label.ForegroundColor = Color.Orange
api.Chart.AddControl(label, api.Bars.OpenTimes.LastValue, api.Bars.LowPrices.LastValue)
```

## AddControl(ControlBase control, DateTime time)

Adds a chart control to chart / indicator area on absolute time (x) coordinate.

Environments: Desktop supported · CLI not supported · Cloud not supported.

- CLI: The control is accepted but never displayed: the CLI displays no chart.
- Cloud: The control is accepted but never displayed: the cloud displays no chart.

C#:

```csharp
void AddControl(ControlBase control, DateTime time)
```

Python:

```python
chartArea.AddControl(control: ControlBase, time: DateTime) -> None
```

### Parameters

- `control` (`ControlBase`, Python `ControlBase`): The control that will be added
- `time` (`DateTime`, Python `DateTime`): Time

### Examples

C#:

```csharp
var label = new TextBlock { Text = "Session open", VerticalAlignment = VerticalAlignment.Top };
Chart.AddControl(label, Server.Time.Date);
```

Python:

```python
label = TextBlock()
label.Text = "Session open"
label.VerticalAlignment = VerticalAlignment.Top
api.Chart.AddControl(label, api.Server.Time.Date)
```

## AddControl(ControlBase control, int barIndex)

Adds a chart control to chart / indicator area on absolute bar index (x) coordinate.

Environments: Desktop supported · CLI not supported · Cloud not supported.

- CLI: The control is accepted but never displayed: the CLI displays no chart.
- Cloud: The control is accepted but never displayed: the cloud displays no chart.

C#:

```csharp
void AddControl(ControlBase control, int barIndex)
```

Python:

```python
chartArea.AddControl(control: ControlBase, barIndex: int) -> None
```

### Parameters

- `control` (`ControlBase`, Python `ControlBase`): The control that will be added
- `barIndex` (`int`, Python `int`): Bar Index

### Examples

C#:

```csharp
var label = new TextBlock { Text = "Last bar", VerticalAlignment = VerticalAlignment.Bottom };
Chart.AddControl(label, Bars.Count - 1);
```

Python:

```python
label = TextBlock()
label.Text = "Last bar"
label.VerticalAlignment = VerticalAlignment.Bottom
api.Chart.AddControl(label, api.Bars.Count - 1)
```

## AddControl(ControlBase control, double y)

Adds a chart control to chart / indicator area on absolute price (y) coordinate.

Environments: Desktop supported · CLI not supported · Cloud not supported.

- CLI: The control is accepted but never displayed: the CLI displays no chart.
- Cloud: The control is accepted but never displayed: the cloud displays no chart.

C#:

```csharp
void AddControl(ControlBase control, double y)
```

Python:

```python
chartArea.AddControl(control: ControlBase, y: float) -> None
```

### Parameters

- `control` (`ControlBase`, Python `ControlBase`): The control that will be added
- `y` (`double`, Python `float`): Price

### Examples

C#:

```csharp
var label = new TextBlock { Text = "Bid", HorizontalAlignment = HorizontalAlignment.Right };
Chart.AddControl(label, Symbol.Bid);
```

Python:

```python
label = TextBlock()
label.Text = "Bid"
label.HorizontalAlignment = HorizontalAlignment.Right
api.Chart.AddControl(label, api.Symbol.Bid)
```

