Trend Line
// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © HPotter 15/03/2023
//@version=5
////////////////////////////////////////////////////////////
// The indicator draws a trend line indicating the trend at the current moment and show  it is resistance or support.
////////////////////////////////////////////////////////////
indicator("Trend Line", shorttitle="TL", overlay = true)
Length = input.int(25 , title="Length",tooltip="Overall length of market analysis")
var Green = color.new(color.green, 0)
var Red = color.new(color.red, 0)
var Work = false
var line lineLevel = na 
var label labelName = na
if barstate.islastconfirmedhistory or barstate.isrealtime
    Work := true
Points = ta.sma(hl2[1], Length)
clr = close[1] > Points ?  Green : Red
line.delete(lineLevel)
lineLevel := line.new(bar_index-Length*2,  Points[Length*2-1], bar_index,  Points[1],  color = clr)
label.delete(labelName)
trendLineIs = close[1] > Points ?  "Support" : "Resistance"
_x = time + math.round(ta.change(time) * 10)
labelName := label.new(x=_x, y= Points[1] , text= trendLineIs, color=color.new(#000000, 100), textcolor = clr, size=size.small, style=label.style_label_left, xloc=xloc.bar_time, yloc=yloc.price) 