Trendlines [theEccentricTrader]
// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © theEccentricTrader
//@version=5


indicator('Trendlines [theEccentricTrader]', overlay = true)


//////////// shsl //////////// 


shPrice = close[1] >= open[1] and close < open and high >= high[1] and barstate.isconfirmed ? high : 
 close[1] >= open[1] and close < open and high <= high[1] and barstate.isconfirmed ? high[1] : na
shPriceBarIndex = close[1] >= open[1] and close < open and high >= high[1] and barstate.isconfirmed ? bar_index : 
 close[1] >= open[1] and close < open and high <= high[1] and barstate.isconfirmed ? bar_index - 1 : na
shPriceOne = ta.valuewhen(shPrice, shPrice, 1)
shPriceBarIndexOne = ta.valuewhen(shPriceBarIndex, shPriceBarIndex, 1)
shPriceTwo = ta.valuewhen(shPrice, shPrice, 2)
shPriceBarIndexTwo = ta.valuewhen(shPriceBarIndex, shPriceBarIndex, 2)

slPrice = close[1] < open[1] and close >= open and low <= low[1] and barstate.isconfirmed ? low : 
 close[1] < open[1] and close >= open and low >= low[1] and barstate.isconfirmed ? low[1] : na
slPriceBarIndex = close[1] < open[1] and close >= open and low <= low[1] and barstate.isconfirmed ? bar_index : 
 close[1] < open[1] and close >= open and low >= low[1] and barstate.isconfirmed ? bar_index - 1 : na
slPriceOne = ta.valuewhen(slPrice, slPrice, 1)
slPriceBarIndexOne = ta.valuewhen(slPriceBarIndex, slPriceBarIndex, 1)
slPriceTwo = ta.valuewhen(slPrice, slPrice, 2)
slPriceBarIndexTwo = ta.valuewhen(slPriceBarIndex, slPriceBarIndex, 2)


//////////// lines //////////// 


resistanceLineColor = input(defval = color.blue, title = 'Resistance Line Color', group = "Line Coloring")
supportLineColor = input(defval = color.blue, title = 'Support Line Color', group = "Line Coloring")
previousLines = input(defval = false, title = 'Previous Lines', group = "Lines")

var resistanceLine = line.new(na, na, na, na, color = resistanceLineColor, extend = extend.right)
var supportLine = line.new(na, na, na, na, color = supportLineColor, extend = extend.right)
var resistanceLineOne = line.new(na, na, na, na, color = resistanceLineColor, extend = extend.right)
var supportLineOne = line.new(na, na, na, na, color = supportLineColor, extend = extend.right)

if shPrice
    line.set_xy1(resistanceLine, shPriceBarIndexOne, shPriceOne)
    line.set_xy2(resistanceLine, shPriceBarIndex, shPrice)

if slPrice
    line.set_xy1(supportLine, slPriceBarIndexOne, slPriceOne)
    line.set_xy2(supportLine, slPriceBarIndex, slPrice)





