---
id: "M:cAlgo.API.ChartArea.DrawRectangle(System.String,System.DateTime,System.Double,System.DateTime,System.Double,cAlgo.API.Color)"
kind: "method"
type: "T:cAlgo.API.ChartArea"
url: "https://help.ctrader.com/ctrader-algo/references/Chart/ChartArea/DrawRectangle/"
---

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

# ChartArea.DrawRectangle

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

## DrawRectangle(string name, DateTime time1, double y1, DateTime time2, double y2, Color color)

Draws a rectangle.

Environments: Desktop supported · CLI works differently · Cloud works differently.

- CLI: The object is created and returned, but never drawn: the CLI displays no chart.
- Cloud: The object is created and returned, but never drawn: the cloud displays no chart.

C#:

```csharp
ChartRectangle DrawRectangle(string name, DateTime time1, double y1, DateTime time2, double y2, Color color)
```

Python:

```python
chartArea.DrawRectangle(name: str, time1: DateTime, y1: float, time2: DateTime, y2: float, color: Color) -> ChartRectangle
```

### Parameters

- `name` (`string`, Python `str`): The chart object name - a unique name that can be only used once for a chart area. If duplicated, the chart object will be replaced with a new one of the same name.
- `time1` (`DateTime`, Python `DateTime`): The time value of the rectangle point 1 location on the X-axis.
- `y1` (`double`, Python `float`): The Y-axis value of the rectangle point 1 location.
- `time2` (`DateTime`, Python `DateTime`): The time value of the rectangle point 2 location on the X-axis.
- `y2` (`double`, Python `float`): The Y-axis value of the rectangle point 2 location.
- `color` (`Color`, Python `Color`): The rectangle lines color.

### Returns

`ChartRectangle` — ChartRectangle.

### Examples

C#:

```csharp
var rectangle = Chart.DrawRectangle("zone", Bars.OpenTimes.Last(20), Bars.LowPrices.Last(20), Bars.OpenTimes.LastValue, Bars.HighPrices.LastValue, Color.FromArgb(80, Color.Blue));
rectangle.IsFilled = true;
Print("Zone from {0} to {1}", rectangle.Y1, rectangle.Y2);
```

Python:

```python
rectangle = api.Chart.DrawRectangle("zone", api.Bars.OpenTimes.Last(20), api.Bars.LowPrices.Last(20), api.Bars.OpenTimes.LastValue, api.Bars.HighPrices.LastValue, Color.FromArgb(80, Color.Blue))
rectangle.IsFilled = True
api.Print(f"Zone from {rectangle.Y1} to {rectangle.Y2}")
```

## DrawRectangle(string name, DateTime time1, double y1, DateTime time2, double y2, Color color, int thickness)

Draws a rectangle.

Environments: Desktop supported · CLI works differently · Cloud works differently.

- CLI: The object is created and returned, but never drawn: the CLI displays no chart.
- Cloud: The object is created and returned, but never drawn: the cloud displays no chart.

C#:

```csharp
ChartRectangle DrawRectangle(string name, DateTime time1, double y1, DateTime time2, double y2, Color color, int thickness)
```

Python:

```python
chartArea.DrawRectangle(name: str, time1: DateTime, y1: float, time2: DateTime, y2: float, color: Color, thickness: int) -> ChartRectangle
```

### Parameters

- `name` (`string`, Python `str`): The chart object name - a unique name that can be only used once for a chart area. If duplicated, the chart object will be replaced with a new one of the same name.
- `time1` (`DateTime`, Python `DateTime`): The time value of the rectangle point 1 location on the X-axis.
- `y1` (`double`, Python `float`): The Y-axis value of the rectangle point 1 location.
- `time2` (`DateTime`, Python `DateTime`): The time value of the rectangle point 2 location on the X-axis.
- `y2` (`double`, Python `float`): The Y-axis value of the rectangle point 2 location.
- `color` (`Color`, Python `Color`): The rectangle lines color.
- `thickness` (`int`, Python `int`): The rectangle lines thickness.

### Returns

`ChartRectangle` — ChartRectangle.

### Examples

C#:

```csharp
var rectangle = Chart.DrawRectangle("zone", Bars.OpenTimes.Last(20), Bars.LowPrices.Last(20), Bars.OpenTimes.LastValue, Bars.HighPrices.LastValue, Color.Blue, 2);
Print("Zone border thickness: {0}", rectangle.Thickness);
```

Python:

```python
rectangle = api.Chart.DrawRectangle("zone", api.Bars.OpenTimes.Last(20), api.Bars.LowPrices.Last(20), api.Bars.OpenTimes.LastValue, api.Bars.HighPrices.LastValue, Color.Blue, 2)
api.Print(f"Zone border thickness: {rectangle.Thickness}")
```

## DrawRectangle(string name, DateTime time1, double y1, DateTime time2, double y2, Color color, int thickness, LineStyle lineStyle)

Draws a rectangle.

Environments: Desktop supported · CLI works differently · Cloud works differently.

- CLI: The object is created and returned, but never drawn: the CLI displays no chart.
- Cloud: The object is created and returned, but never drawn: the cloud displays no chart.

C#:

```csharp
ChartRectangle DrawRectangle(string name, DateTime time1, double y1, DateTime time2, double y2, Color color, int thickness, LineStyle lineStyle)
```

Python:

```python
chartArea.DrawRectangle(name: str, time1: DateTime, y1: float, time2: DateTime, y2: float, color: Color, thickness: int, lineStyle: LineStyle) -> ChartRectangle
```

### Parameters

- `name` (`string`, Python `str`): The chart object name - a unique name that can be only used once for a chart area. If duplicated, the chart object will be replaced with a new one of the same name.
- `time1` (`DateTime`, Python `DateTime`): The time value of the rectangle point 1 location on the X-axis.
- `y1` (`double`, Python `float`): The Y-axis value of the rectangle point 1 location.
- `time2` (`DateTime`, Python `DateTime`): The time value of the rectangle point 2 location on the X-axis.
- `y2` (`double`, Python `float`): The Y-axis value of the rectangle point 2 location.
- `color` (`Color`, Python `Color`): The rectangle lines color.
- `thickness` (`int`, Python `int`): The rectangle lines thickness.
- `lineStyle` (`LineStyle`, Python `LineStyle`): The rectangle lines style.

### Returns

`ChartRectangle` — ChartRectangle.

### Examples

C#:

```csharp
var rectangle = Chart.DrawRectangle("zone", Bars.OpenTimes.Last(20), Bars.LowPrices.Last(20), Bars.OpenTimes.LastValue, Bars.HighPrices.LastValue, Color.Blue, 2, LineStyle.Dots);
Print("Zone border style: {0}", rectangle.LineStyle);
```

Python:

```python
rectangle = api.Chart.DrawRectangle("zone", api.Bars.OpenTimes.Last(20), api.Bars.LowPrices.Last(20), api.Bars.OpenTimes.LastValue, api.Bars.HighPrices.LastValue, Color.Blue, 2, LineStyle.Dots)
api.Print(f"Zone border style: {rectangle.LineStyle}")
```

## DrawRectangle(string name, int barIndex1, double y1, int barIndex2, double y2, Color color)

Draws a rectangle.

Environments: Desktop supported · CLI works differently · Cloud works differently.

- CLI: The object is created and returned, but never drawn: the CLI displays no chart.
- Cloud: The object is created and returned, but never drawn: the cloud displays no chart.

C#:

```csharp
ChartRectangle DrawRectangle(string name, int barIndex1, double y1, int barIndex2, double y2, Color color)
```

Python:

```python
chartArea.DrawRectangle(name: str, barIndex1: int, y1: float, barIndex2: int, y2: float, color: Color) -> ChartRectangle
```

### Parameters

- `name` (`string`, Python `str`): The chart object name - a unique name that can be only used once for a chart area. If duplicated, the chart object will be replaced with a new one of the same name.
- `barIndex1` (`int`, Python `int`): The bar index of the rectangle point 1 location on the X-axis.
- `y1` (`double`, Python `float`): The Y-axis value of the rectangle point 1 location.
- `barIndex2` (`int`, Python `int`): The bar index of the rectangle point 2 location on the X-axis.
- `y2` (`double`, Python `float`): The Y-axis value of the rectangle point 2 location.
- `color` (`Color`, Python `Color`): The rectangle lines color.

### Returns

`ChartRectangle` — ChartRectangle.

### Examples

C#:

```csharp
var index = Bars.Count - 1;
var rectangle = Chart.DrawRectangle("zone", index - 20, Bars.LowPrices[index - 20], index, Bars.HighPrices[index], Color.FromArgb(80, Color.Blue));
rectangle.IsFilled = true;
Print("Zone from {0} to {1}", rectangle.Y1, rectangle.Y2);
```

Python:

```python
index = api.Bars.Count - 1
rectangle = api.Chart.DrawRectangle("zone", index - 20, api.Bars.LowPrices[index - 20], index, api.Bars.HighPrices[index], Color.FromArgb(80, Color.Blue))
rectangle.IsFilled = True
api.Print(f"Zone from {rectangle.Y1} to {rectangle.Y2}")
```

## DrawRectangle(string name, int barIndex1, double y1, int barIndex2, double y2, Color color, int thickness)

Draws a rectangle.

Environments: Desktop supported · CLI works differently · Cloud works differently.

- CLI: The object is created and returned, but never drawn: the CLI displays no chart.
- Cloud: The object is created and returned, but never drawn: the cloud displays no chart.

C#:

```csharp
ChartRectangle DrawRectangle(string name, int barIndex1, double y1, int barIndex2, double y2, Color color, int thickness)
```

Python:

```python
chartArea.DrawRectangle(name: str, barIndex1: int, y1: float, barIndex2: int, y2: float, color: Color, thickness: int) -> ChartRectangle
```

### Parameters

- `name` (`string`, Python `str`): The chart object name - a unique name that can be only used once for a chart area. If duplicated, the chart object will be replaced with a new one of the same name.
- `barIndex1` (`int`, Python `int`): The bar index of the rectangle point 1 location on the X-axis.
- `y1` (`double`, Python `float`): The Y-axis value of the rectangle point 1 location.
- `barIndex2` (`int`, Python `int`): The bar index of the rectangle point 2 location on the X-axis.
- `y2` (`double`, Python `float`): The Y-axis value of the rectangle point 2 location.
- `color` (`Color`, Python `Color`): The rectangle lines color.
- `thickness` (`int`, Python `int`): The rectangle lines thickness.

### Returns

`ChartRectangle` — ChartRectangle.

### Examples

C#:

```csharp
var index = Bars.Count - 1;
var rectangle = Chart.DrawRectangle("zone", index - 20, Bars.LowPrices[index - 20], index, Bars.HighPrices[index], Color.Blue, 2);
Print("Zone border thickness: {0}", rectangle.Thickness);
```

Python:

```python
index = api.Bars.Count - 1
rectangle = api.Chart.DrawRectangle("zone", index - 20, api.Bars.LowPrices[index - 20], index, api.Bars.HighPrices[index], Color.Blue, 2)
api.Print(f"Zone border thickness: {rectangle.Thickness}")
```

## DrawRectangle(string name, int barIndex1, double y1, int barIndex2, double y2, Color color, int thickness, LineStyle lineStyle)

Draws a rectangle.

Environments: Desktop supported · CLI works differently · Cloud works differently.

- CLI: The object is created and returned, but never drawn: the CLI displays no chart.
- Cloud: The object is created and returned, but never drawn: the cloud displays no chart.

C#:

```csharp
ChartRectangle DrawRectangle(string name, int barIndex1, double y1, int barIndex2, double y2, Color color, int thickness, LineStyle lineStyle)
```

Python:

```python
chartArea.DrawRectangle(name: str, barIndex1: int, y1: float, barIndex2: int, y2: float, color: Color, thickness: int, lineStyle: LineStyle) -> ChartRectangle
```

### Parameters

- `name` (`string`, Python `str`): The chart object name - a unique name that can be only used once for a chart area. If duplicated, the chart object will be replaced with a new one of the same name.
- `barIndex1` (`int`, Python `int`): The bar index of the rectangle point 1 location on the X-axis.
- `y1` (`double`, Python `float`): The Y-axis value of the rectangle point 1 location.
- `barIndex2` (`int`, Python `int`): The bar index of the rectangle point 2 location on the X-axis.
- `y2` (`double`, Python `float`): The Y-axis value of the rectangle point 2 location.
- `color` (`Color`, Python `Color`): The rectangle lines color.
- `thickness` (`int`, Python `int`): The rectangle lines thickness.
- `lineStyle` (`LineStyle`, Python `LineStyle`): The rectangle lines style.

### Returns

`ChartRectangle` — ChartRectangle.

### Examples

C#:

```csharp
var index = Bars.Count - 1;
var rectangle = Chart.DrawRectangle("zone", index - 20, Bars.LowPrices[index - 20], index, Bars.HighPrices[index], Color.Blue, 2, LineStyle.Dots);
Print("Zone border style: {0}", rectangle.LineStyle);
```

Python:

```python
index = api.Bars.Count - 1
rectangle = api.Chart.DrawRectangle("zone", index - 20, api.Bars.LowPrices[index - 20], index, api.Bars.HighPrices[index], Color.Blue, 2, LineStyle.Dots)
api.Print(f"Zone border style: {rectangle.LineStyle}")
```

