---
id: "M:cAlgo.API.ChartArea.DrawTrendLine(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/DrawTrendLine/"
---

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

# ChartArea.DrawTrendLine

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

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

Draws a trend line.

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
ChartTrendLine DrawTrendLine(string name, DateTime time1, double y1, DateTime time2, double y2, Color color)
```

Python:

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

### 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 trend line start point location on the X-axis.
- `y1` (`double`, Python `float`): The Y-axis value of the trend line start location.
- `time2` (`DateTime`, Python `DateTime`): The time value of the trend line end point location on the X-axis.
- `y2` (`double`, Python `float`): The Y-axis value of the trend line end location.
- `color` (`Color`, Python `Color`): The color of the trend line.

### Returns

`ChartTrendLine` — 

### Examples

C#:

```csharp
var trendLine = Chart.DrawTrendLine("trendLine", Bars.OpenTimes.Last(20), Bars.LowPrices.Last(20), Bars.OpenTimes.LastValue, Bars.LowPrices.LastValue, Color.Red);
Print("Trend line drawn from {0} to {1}", trendLine.Time1, trendLine.Time2);
```

Python:

```python
trendLine = api.Chart.DrawTrendLine("trendLine", api.Bars.OpenTimes.Last(20), api.Bars.LowPrices.Last(20), api.Bars.OpenTimes.LastValue, api.Bars.LowPrices.LastValue, Color.Red)
api.Print(f"Trend line drawn from {trendLine.Time1} to {trendLine.Time2}")
```

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

Draws a trend line.

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
ChartTrendLine DrawTrendLine(string name, DateTime time1, double y1, DateTime time2, double y2, Color color, int thickness)
```

Python:

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

### 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 trend line start point location on the X-axis.
- `y1` (`double`, Python `float`): The Y-axis value of the trend line start location.
- `time2` (`DateTime`, Python `DateTime`): The time value of the trend line end point location on the X-axis.
- `y2` (`double`, Python `float`): The Y-axis value of the trend line end location.
- `color` (`Color`, Python `Color`): The color of the trend line.
- `thickness` (`int`, Python `int`): The thickness of the trend line.

### Returns

`ChartTrendLine` — 

### Examples

C#:

```csharp
var trendLine = Chart.DrawTrendLine("trendLine", Bars.OpenTimes.Last(20), Bars.LowPrices.Last(20), Bars.OpenTimes.LastValue, Bars.LowPrices.LastValue, Color.Red, 2);
Print("Trend line thickness: {0}", trendLine.Thickness);
```

Python:

```python
trendLine = api.Chart.DrawTrendLine("trendLine", api.Bars.OpenTimes.Last(20), api.Bars.LowPrices.Last(20), api.Bars.OpenTimes.LastValue, api.Bars.LowPrices.LastValue, Color.Red, 2)
api.Print(f"Trend line thickness: {trendLine.Thickness}")
```

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

Draws a trend line.

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
ChartTrendLine DrawTrendLine(string name, DateTime time1, double y1, DateTime time2, double y2, Color color, int thickness, LineStyle lineStyle)
```

Python:

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

### 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 trend line start point location on the X-axis.
- `y1` (`double`, Python `float`): The Y-axis value of the trend line start location.
- `time2` (`DateTime`, Python `DateTime`): The time value of the trend line end point location on the X-axis.
- `y2` (`double`, Python `float`): The Y-axis value of the trend line end location.
- `color` (`Color`, Python `Color`): The color of the trend line.
- `thickness` (`int`, Python `int`): The thickness of the trend line.
- `lineStyle` (`LineStyle`, Python `LineStyle`): The trend line style.

### Returns

`ChartTrendLine` — 

### Examples

C#:

```csharp
var trendLine = Chart.DrawTrendLine("trendLine", Bars.OpenTimes.Last(20), Bars.LowPrices.Last(20), Bars.OpenTimes.LastValue, Bars.LowPrices.LastValue, Color.Red, 2, LineStyle.Dots);
trendLine.IsInteractive = true;
Print("Trend line style: {0}", trendLine.LineStyle);
```

Python:

```python
trendLine = api.Chart.DrawTrendLine("trendLine", api.Bars.OpenTimes.Last(20), api.Bars.LowPrices.Last(20), api.Bars.OpenTimes.LastValue, api.Bars.LowPrices.LastValue, Color.Red, 2, LineStyle.Dots)
trendLine.IsInteractive = True
api.Print(f"Trend line style: {trendLine.LineStyle}")
```

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

Draws a trend line.

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
ChartTrendLine DrawTrendLine(string name, int barIndex1, double y1, int barIndex2, double y2, Color color)
```

Python:

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

### 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 trend line start point location on the X-axis.
- `y1` (`double`, Python `float`): The Y-axis value of the trend line start location.
- `barIndex2` (`int`, Python `int`): The bar index of the trend line end point location on the X-axis.
- `y2` (`double`, Python `float`): The Y-axis value of the trend line end location.
- `color` (`Color`, Python `Color`): The color of the trend line.

### Returns

`ChartTrendLine` — 

### Examples

C#:

```csharp
var index = Bars.Count - 1;
var trendLine = Chart.DrawTrendLine("trendLine", index - 20, Bars.LowPrices[index - 20], index, Bars.LowPrices[index], Color.Red);
Print("Trend line drawn from {0} to {1}", trendLine.Time1, trendLine.Time2);
```

Python:

```python
index = api.Bars.Count - 1
trendLine = api.Chart.DrawTrendLine("trendLine", index - 20, api.Bars.LowPrices[index - 20], index, api.Bars.LowPrices[index], Color.Red)
api.Print(f"Trend line drawn from {trendLine.Time1} to {trendLine.Time2}")
```

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

Draws a trend line.

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
ChartTrendLine DrawTrendLine(string name, int barIndex1, double y1, int barIndex2, double y2, Color color, int thickness)
```

Python:

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

### 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 trend line start point location on the X-axis.
- `y1` (`double`, Python `float`): The Y-axis value of the trend line start location.
- `barIndex2` (`int`, Python `int`): The bar index of the trend line end point location on the X-axis.
- `y2` (`double`, Python `float`): The Y-axis value of the trend line end location.
- `color` (`Color`, Python `Color`): The color of the trend line.
- `thickness` (`int`, Python `int`): The thickness of the trend line.

### Returns

`ChartTrendLine` — 

### Examples

C#:

```csharp
var index = Bars.Count - 1;
var trendLine = Chart.DrawTrendLine("trendLine", index - 20, Bars.LowPrices[index - 20], index, Bars.LowPrices[index], Color.Red, 2);
Print("Trend line thickness: {0}", trendLine.Thickness);
```

Python:

```python
index = api.Bars.Count - 1
trendLine = api.Chart.DrawTrendLine("trendLine", index - 20, api.Bars.LowPrices[index - 20], index, api.Bars.LowPrices[index], Color.Red, 2)
api.Print(f"Trend line thickness: {trendLine.Thickness}")
```

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

Draws a trend line.

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
ChartTrendLine DrawTrendLine(string name, int barIndex1, double y1, int barIndex2, double y2, Color color, int thickness, LineStyle lineStyle)
```

Python:

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

### 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 trend line start point location on the X-axis.
- `y1` (`double`, Python `float`): The Y-axis value of the trend line start location.
- `barIndex2` (`int`, Python `int`): The bar index of the trend line end point location on the X-axis.
- `y2` (`double`, Python `float`): The Y-axis value of the trend line end location.
- `color` (`Color`, Python `Color`): The color of the trend line.
- `thickness` (`int`, Python `int`): The thickness of the trend line.
- `lineStyle` (`LineStyle`, Python `LineStyle`): The trend line style.

### Returns

`ChartTrendLine` — 

### Examples

C#:

```csharp
var index = Bars.Count - 1;
var trendLine = Chart.DrawTrendLine("trendLine", index - 20, Bars.LowPrices[index - 20], index, Bars.LowPrices[index], Color.Red, 2, LineStyle.Dots);
Print("Trend line style: {0}", trendLine.LineStyle);
```

Python:

```python
index = api.Bars.Count - 1
trendLine = api.Chart.DrawTrendLine("trendLine", index - 20, api.Bars.LowPrices[index - 20], index, api.Bars.LowPrices[index], Color.Red, 2, LineStyle.Dots)
api.Print(f"Trend line style: {trendLine.LineStyle}")
```

