Return Line Uptrends [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('Return Line Uptrends [theEccentricTrader]', overlay = true)


//////////// return line uptrends ////////////


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

onePartReturnLineUptrend = shPrice > ta.valuewhen(shPrice, shPrice, 1)
twoPartReturnLineUptrend = onePartReturnLineUptrend and ta.valuewhen(shPrice, shPrice, 1) > ta.valuewhen(shPrice, shPrice, 2)
threePartReturnLineUptrend = twoPartReturnLineUptrend and ta.valuewhen(shPrice, shPrice, 2) > ta.valuewhen(shPrice, shPrice, 3)
fourPartReturnLineUptrend = threePartReturnLineUptrend and ta.valuewhen(shPrice, shPrice, 3) > ta.valuewhen(shPrice, shPrice, 4)
fivePartReturnLineUptrend = fourPartReturnLineUptrend and ta.valuewhen(shPrice, shPrice, 4) > ta.valuewhen(shPrice, shPrice, 5)
sixPartReturnLineUptrend = fivePartReturnLineUptrend and ta.valuewhen(shPrice, shPrice, 5) > ta.valuewhen(shPrice, shPrice, 6)
sevenPartReturnLineUptrend = sixPartReturnLineUptrend and ta.valuewhen(shPrice, shPrice, 6) > ta.valuewhen(shPrice, shPrice, 7)
eightPartReturnLineUptrend = sevenPartReturnLineUptrend and ta.valuewhen(shPrice, shPrice, 7) > ta.valuewhen(shPrice, shPrice, 8)
ninePartReturnLineUptrend = eightPartReturnLineUptrend and ta.valuewhen(shPrice, shPrice, 8) > ta.valuewhen(shPrice, shPrice, 9)
tenPartReturnLineUptrend = ninePartReturnLineUptrend and ta.valuewhen(shPrice, shPrice, 9) > ta.valuewhen(shPrice, shPrice, 10)
elevenPartReturnLineUptrend = tenPartReturnLineUptrend and ta.valuewhen(shPrice, shPrice, 10) > ta.valuewhen(shPrice, shPrice, 11)
twelvePartReturnLineUptrend = elevenPartReturnLineUptrend and ta.valuewhen(shPrice, shPrice, 11) > ta.valuewhen(shPrice, shPrice, 12)
thirteenPartReturnLineUptrend = twelvePartReturnLineUptrend and ta.valuewhen(shPrice, shPrice, 12) > ta.valuewhen(shPrice, shPrice, 13)
fourteenPartReturnLineUptrend = thirteenPartReturnLineUptrend and ta.valuewhen(shPrice, shPrice, 13) > ta.valuewhen(shPrice, shPrice, 14)
fifteenPartReturnLineUptrend = fourteenPartReturnLineUptrend and ta.valuewhen(shPrice, shPrice, 14) > ta.valuewhen(shPrice, shPrice, 15)
sixteenPartReturnLineUptrend = fifteenPartReturnLineUptrend and ta.valuewhen(shPrice, shPrice, 15) > ta.valuewhen(shPrice, shPrice, 16)
seventeenPartReturnLineUptrend = sixteenPartReturnLineUptrend and ta.valuewhen(shPrice, shPrice, 16) > ta.valuewhen(shPrice, shPrice, 17)
eighteenPartReturnLineUptrend = seventeenPartReturnLineUptrend and ta.valuewhen(shPrice, shPrice, 17) > ta.valuewhen(shPrice, shPrice, 18)
nineteenPartReturnLineUptrend = eighteenPartReturnLineUptrend and ta.valuewhen(shPrice, shPrice, 18) > ta.valuewhen(shPrice, shPrice, 19)
twentyPartReturnLineUptrend = nineteenPartReturnLineUptrend and ta.valuewhen(shPrice, shPrice, 19) > ta.valuewhen(shPrice, shPrice, 20)


//////////// plots ////////////


plotshape(shPrice and onePartReturnLineUptrend and not twoPartReturnLineUptrend and high >= high[1] and barstate.isconfirmed ? onePartReturnLineUptrend : na, 
 style = shape.triangleup, color = color.green, text = '1', textcolor = color.green)
plotshape(shPrice and twoPartReturnLineUptrend and not threePartReturnLineUptrend and high >= high[1] and barstate.isconfirmed ? twoPartReturnLineUptrend : na, 
 style = shape.triangleup, color = color.green, text = '2', textcolor = color.green)
plotshape(shPrice and threePartReturnLineUptrend and not fourPartReturnLineUptrend and high >= high[1] and barstate.isconfirmed ? threePartReturnLineUptrend : na, 
 style = shape.triangleup, color = color.green, text = '3', textcolor = color.green)
plotshape(shPrice and fourPartReturnLineUptrend and not fivePartReturnLineUptrend and high >= high[1] and barstate.isconfirmed ? fourPartReturnLineUptrend : na, 
 style = shape.triangleup, color = color.green, text = '4', textcolor = color.green)
plotshape(shPrice and fivePartReturnLineUptrend and not sixPartReturnLineUptrend and high >= high[1] and barstate.isconfirmed ? fivePartReturnLineUptrend : na, 
 style = shape.triangleup, color = color.green, text = '5', textcolor = color.green)
plotshape(shPrice and sixPartReturnLineUptrend and not sevenPartReturnLineUptrend and high >= high[1] and barstate.isconfirmed ? sixPartReturnLineUptrend : na, 
 style = shape.triangleup, color = color.green, text = '6', textcolor = color.green)
plotshape(shPrice and sevenPartReturnLineUptrend and not eightPartReturnLineUptrend and high >= high[1] and barstate.isconfirmed ? sevenPartReturnLineUptrend : na, 
 style = shape.triangleup, color = color.green, text = '7', textcolor = color.green)
plotshape(shPrice and eightPartReturnLineUptrend and not ninePartReturnLineUptrend and high >= high[1] and barstate.isconfirmed ? eightPartReturnLineUptrend : na, 
 style = shape.triangleup, color = color.green, text = '8', textcolor = color.green)
plotshape(shPrice and ninePartReturnLineUptrend and not tenPartReturnLineUptrend and high >= high[1] and barstate.isconfirmed ? ninePartReturnLineUptrend : na, 
 style = shape.triangleup, color = color.green, text = '9', textcolor = color.green)
plotshape(shPrice and tenPartReturnLineUptrend and not elevenPartReturnLineUptrend and high >= high[1] and barstate.isconfirmed ? tenPartReturnLineUptrend : na, 
 style = shape.triangleup, color = color.green, text = '10', textcolor = color.green)
plotshape(shPrice and elevenPartReturnLineUptrend and not twelvePartReturnLineUptrend and high >= high[1] and barstate.isconfirmed ? elevenPartReturnLineUptrend : na, 
 style = shape.triangleup, color = color.green, text = '11', textcolor = color.green)
plotshape(shPrice and twelvePartReturnLineUptrend and not thirteenPartReturnLineUptrend and high >= high[1] and barstate.isconfirmed ? twelvePartReturnLineUptrend : na, 
 style = shape.triangleup, color = color.green, text = '12', textcolor = color.green)
plotshape(shPrice and thirteenPartReturnLineUptrend and not fourteenPartReturnLineUptrend and high >= high[1] and barstate.isconfirmed ? thirteenPartReturnLineUptrend : na, 
 style = shape.triangleup, color = color.green, text = '13', textcolor = color.green)
plotshape(shPrice and fourteenPartReturnLineUptrend and not fifteenPartReturnLineUptrend and high >= high[1] and barstate.isconfirmed ? fourteenPartReturnLineUptrend : na, 
 style = shape.triangleup, color = color.green, text = '14', textcolor = color.green)
plotshape(shPrice and fifteenPartReturnLineUptrend and not sixteenPartReturnLineUptrend and high >= high[1] and barstate.isconfirmed ? fifteenPartReturnLineUptrend : na, 
 style = shape.triangleup, color = color.green, text = '15', textcolor = color.green)
plotshape(shPrice and sixteenPartReturnLineUptrend and not seventeenPartReturnLineUptrend and high >= high[1] and barstate.isconfirmed ? sixteenPartReturnLineUptrend : na, 
 style = shape.triangleup, color = color.green, text = '16', textcolor = color.green)
plotshape(shPrice and seventeenPartReturnLineUptrend and not eighteenPartReturnLineUptrend and high >= high[1] and barstate.isconfirmed ? seventeenPartReturnLineUptrend : na, 
 style = shape.triangleup, color = color.green, text = '17', textcolor = color.green)
plotshape(shPrice and eighteenPartReturnLineUptrend and not nineteenPartReturnLineUptrend and high >= high[1] and barstate.isconfirmed ? eighteenPartReturnLineUptrend : na, 
 style = shape.triangleup, color = color.green, text = '18', textcolor = color.green)
plotshape(shPrice and nineteenPartReturnLineUptrend and not twentyPartReturnLineUptrend and high >= high[1] and barstate.isconfirmed ? nineteenPartReturnLineUptrend : na, 
 style = shape.triangleup, color = color.green, text = '19', textcolor = color.green)
plotshape(shPrice and twentyPartReturnLineUptrend and high >= high[1] and barstate.isconfirmed ? twentyPartReturnLineUptrend : na, 
 style = shape.triangleup, color = color.green, text = '20', textcolor = color.green)

plotshape(shPrice and onePartReturnLineUptrend and not twoPartReturnLineUptrend and high < high[1] and barstate.isconfirmed ? onePartReturnLineUptrend : na, 
 style = shape.triangleup, color = color.green, text = '1', textcolor = color.green, offset = -1)
plotshape(shPrice and twoPartReturnLineUptrend and not threePartReturnLineUptrend and high < high[1] and barstate.isconfirmed ? twoPartReturnLineUptrend : na, 
 style = shape.triangleup, color = color.green, text = '2', textcolor = color.green, offset = -1)
plotshape(shPrice and threePartReturnLineUptrend and not fourPartReturnLineUptrend and high < high[1] and barstate.isconfirmed ? threePartReturnLineUptrend : na, 
 style = shape.triangleup, color = color.green, text = '3', textcolor = color.green, offset = -1)
plotshape(shPrice and fourPartReturnLineUptrend and not fivePartReturnLineUptrend and high < high[1] and barstate.isconfirmed ? fourPartReturnLineUptrend : na, 
 style = shape.triangleup, color = color.green, text = '4', textcolor = color.green, offset = -1)
plotshape(shPrice and fivePartReturnLineUptrend and not sixPartReturnLineUptrend and high < high[1] and barstate.isconfirmed ? fivePartReturnLineUptrend : na, 
 style = shape.triangleup, color = color.green, text = '5', textcolor = color.green, offset = -1)
plotshape(shPrice and sixPartReturnLineUptrend and not sevenPartReturnLineUptrend and high < high[1] and barstate.isconfirmed ? sixPartReturnLineUptrend : na, 
 style = shape.triangleup, color = color.green, text = '6', textcolor = color.green, offset = -1)
plotshape(shPrice and sevenPartReturnLineUptrend and not eightPartReturnLineUptrend and high < high[1] and barstate.isconfirmed ? sevenPartReturnLineUptrend : na, 
 style = shape.triangleup, color = color.green, text = '7', textcolor = color.green, offset = -1)
plotshape(shPrice and eightPartReturnLineUptrend and not ninePartReturnLineUptrend and high < high[1] and barstate.isconfirmed ? eightPartReturnLineUptrend : na, 
 style = shape.triangleup, color = color.green, text = '8', textcolor = color.green, offset = -1)
plotshape(shPrice and ninePartReturnLineUptrend and not tenPartReturnLineUptrend and high < high[1] and barstate.isconfirmed ? ninePartReturnLineUptrend : na, 
 style = shape.triangleup, color = color.green, text = '9', textcolor = color.green, offset = -1)
plotshape(shPrice and tenPartReturnLineUptrend and not elevenPartReturnLineUptrend and high < high[1] and barstate.isconfirmed ? tenPartReturnLineUptrend : na, 
 style = shape.triangleup, color = color.green, text = '10', textcolor = color.green, offset = -1)
plotshape(shPrice and elevenPartReturnLineUptrend and not twelvePartReturnLineUptrend and high < high[1] and barstate.isconfirmed ? elevenPartReturnLineUptrend : na, 
 style = shape.triangleup, color = color.green, text = '11', textcolor = color.green, offset = -1)
plotshape(shPrice and twelvePartReturnLineUptrend and not thirteenPartReturnLineUptrend and high < high[1] and barstate.isconfirmed ? twelvePartReturnLineUptrend : na, 
 style = shape.triangleup, color = color.green, text = '12', textcolor = color.green, offset = -1)
plotshape(shPrice and thirteenPartReturnLineUptrend and not fourteenPartReturnLineUptrend and high < high[1] and barstate.isconfirmed ? thirteenPartReturnLineUptrend : na, 
 style = shape.triangleup, color = color.green, text = '13', textcolor = color.green, offset = -1)
plotshape(shPrice and fourteenPartReturnLineUptrend and not fifteenPartReturnLineUptrend and high < high[1] and barstate.isconfirmed ? fourteenPartReturnLineUptrend : na, 
 style = shape.triangleup, color = color.green, text = '14', textcolor = color.green, offset = -1)
plotshape(shPrice and fifteenPartReturnLineUptrend and not sixteenPartReturnLineUptrend and high < high[1] and barstate.isconfirmed ? fifteenPartReturnLineUptrend : na, 
 style = shape.triangleup, color = color.green, text = '15', textcolor = color.green, offset = -1)
plotshape(shPrice and sixteenPartReturnLineUptrend and not seventeenPartReturnLineUptrend and high < high[1] and barstate.isconfirmed ? sixteenPartReturnLineUptrend : na, 
 style = shape.triangleup, color = color.green, text = '16', textcolor = color.green, offset = -1)
plotshape(shPrice and seventeenPartReturnLineUptrend and not eighteenPartReturnLineUptrend and high < high[1] and barstate.isconfirmed ? seventeenPartReturnLineUptrend : na, 
 style = shape.triangleup, color = color.green, text = '17', textcolor = color.green, offset = -1)
plotshape(shPrice and eighteenPartReturnLineUptrend and not nineteenPartReturnLineUptrend and high < high[1] and barstate.isconfirmed ? eighteenPartReturnLineUptrend : na, 
 style = shape.triangleup, color = color.green, text = '18', textcolor = color.green, offset = -1)
plotshape(shPrice and nineteenPartReturnLineUptrend and not twentyPartReturnLineUptrend and high < high[1] and barstate.isconfirmed ? nineteenPartReturnLineUptrend : na, 
 style = shape.triangleup, color = color.green, text = '19', textcolor = color.green, offset = -1)
plotshape(shPrice and twentyPartReturnLineUptrend and high < high[1] and barstate.isconfirmed ? twentyPartReturnLineUptrend : na, 
 style = shape.triangleup, color = color.green, text = '20', textcolor = color.green, offset = -1)



