---
id: "M:cAlgo.API.ChartTrendLine.CalculateY(System.Int32)"
kind: "method"
type: "T:cAlgo.API.ChartTrendLine"
url: "https://help.ctrader.com/ctrader-algo/references/Chart/Drawings/ChartTrendLine/CalculateY/"
---

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

# ChartTrendLine.CalculateY

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

## CalculateY(int barIndex)

Calculates Y-axis value corresponding the specified bar index.

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

- CLI: Created and kept with all its properties, but never drawn: the CLI displays no chart.
- Cloud: Created and kept with all its properties, but never drawn: the cloud displays no chart.

C#:

```csharp
double CalculateY(int barIndex)
```

Python:

```python
chartTrendLine.CalculateY(barIndex: int) -> float
```

### Parameters

- `barIndex` (`int`, Python `int`): Index of the bar.

### Returns

`double` — Y-axis value

### Examples

C#:

```csharp
var trendLine = Chart.DrawTrendLine("support", Bars.OpenTimes.Last(20), Bars.LowPrices.Last(20), Bars.OpenTimes.Last(10), Bars.LowPrices.Last(10), Color.Red);
trendLine.ExtendToInfinity = true;
var supportValue = trendLine.CalculateY(Bars.Count - 1);
if (Bars.ClosePrices.LastValue < supportValue)
    Print("Price closed below the support trend line at {0}", supportValue);
```

Python:

```python
trendLine = api.Chart.DrawTrendLine("support", api.Bars.OpenTimes.Last(20), api.Bars.LowPrices.Last(20), api.Bars.OpenTimes.Last(10), api.Bars.LowPrices.Last(10), Color.Red)
trendLine.ExtendToInfinity = True
supportValue = trendLine.CalculateY(api.Bars.Count - 1)
if api.Bars.ClosePrices.LastValue < supportValue:
    api.Print(f"Price closed below the support trend line at {supportValue}")
```

## CalculateY(DateTime time)

Calculates Y-axis value corresponding the specified time value.

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

- CLI: Created and kept with all its properties, but never drawn: the CLI displays no chart.
- Cloud: Created and kept with all its properties, but never drawn: the cloud displays no chart.

C#:

```csharp
double CalculateY(DateTime time)
```

Python:

```python
chartTrendLine.CalculateY(time: DateTime) -> float
```

### Parameters

- `time` (`DateTime`, Python `DateTime`): The time.

### Returns

`double` — Y-axis value

### Examples

C#:

```csharp
var trendLine = Chart.DrawTrendLine("resistance", Bars.OpenTimes.Last(20), Bars.HighPrices.Last(20), Bars.OpenTimes.Last(10), Bars.HighPrices.Last(10), Color.Red);
trendLine.ExtendToInfinity = true;
var resistanceValue = trendLine.CalculateY(Server.Time);
Print("Resistance trend line value now: {0}", resistanceValue);
```

Python:

```python
trendLine = api.Chart.DrawTrendLine("resistance", api.Bars.OpenTimes.Last(20), api.Bars.HighPrices.Last(20), api.Bars.OpenTimes.Last(10), api.Bars.HighPrices.Last(10), Color.Red)
trendLine.ExtendToInfinity = True
resistanceValue = trendLine.CalculateY(api.Server.Time)
api.Print(f"Resistance trend line value now: {resistanceValue}")
```

