Skip to content

ChartArea.DrawTrendLine

method · ChartArea · cAlgo.API

DesktopCLICloud

Draws a trend line.

Environment behaviour

CLI — works differently. The object is created and returned, but never drawn: the CLI displays no chart.

Cloud — works differently. The object is created and returned, but never drawn: the cloud displays no chart.

Overloads

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

Draws a trend line.

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

Parameters

Name C# type Python type Description
name string 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 DateTime The time value of the trend line start point location on the X-axis.
y1 double float The Y-axis value of the trend line start location.
time2 DateTime DateTime The time value of the trend line end point location on the X-axis.
y2 double float The Y-axis value of the trend line end location.
color Color Color The color of the trend line.

Returns ChartTrendLine

Examples

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);
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.

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

Parameters

Name C# type Python type Description
name string 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 DateTime The time value of the trend line start point location on the X-axis.
y1 double float The Y-axis value of the trend line start location.
time2 DateTime DateTime The time value of the trend line end point location on the X-axis.
y2 double float The Y-axis value of the trend line end location.
color Color Color The color of the trend line.
thickness int int The thickness of the trend line.

Returns ChartTrendLine

Examples

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);
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.

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

Parameters

Name C# type Python type Description
name string 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 DateTime The time value of the trend line start point location on the X-axis.
y1 double float The Y-axis value of the trend line start location.
time2 DateTime DateTime The time value of the trend line end point location on the X-axis.
y2 double float The Y-axis value of the trend line end location.
color Color Color The color of the trend line.
thickness int int The thickness of the trend line.
lineStyle LineStyle LineStyle The trend line style.

Returns ChartTrendLine

Examples

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);
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.

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

Parameters

Name C# type Python type Description
name string 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 int The bar index of the trend line start point location on the X-axis.
y1 double float The Y-axis value of the trend line start location.
barIndex2 int int The bar index of the trend line end point location on the X-axis.
y2 double float The Y-axis value of the trend line end location.
color Color Color The color of the trend line.

Returns ChartTrendLine

Examples

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);
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.

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

Parameters

Name C# type Python type Description
name string 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 int The bar index of the trend line start point location on the X-axis.
y1 double float The Y-axis value of the trend line start location.
barIndex2 int int The bar index of the trend line end point location on the X-axis.
y2 double float The Y-axis value of the trend line end location.
color Color Color The color of the trend line.
thickness int int The thickness of the trend line.

Returns ChartTrendLine

Examples

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);
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.

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

Parameters

Name C# type Python type Description
name string 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 int The bar index of the trend line start point location on the X-axis.
y1 double float The Y-axis value of the trend line start location.
barIndex2 int int The bar index of the trend line end point location on the X-axis.
y2 double float The Y-axis value of the trend line end location.
color Color Color The color of the trend line.
thickness int int The thickness of the trend line.
lineStyle LineStyle LineStyle The trend line style.

Returns ChartTrendLine

Examples

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);
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}")