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


//////////// uptrends ////////////


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

onePartUptrend = slPrice > ta.valuewhen(slPrice, slPrice, 1)
twoPartUptrend = onePartUptrend and ta.valuewhen(slPrice, slPrice, 1) > ta.valuewhen(slPrice, slPrice, 2)
threePartUptrend = twoPartUptrend and ta.valuewhen(slPrice, slPrice, 2) > ta.valuewhen(slPrice, slPrice, 3)
fourPartUptrend = threePartUptrend and ta.valuewhen(slPrice, slPrice, 3) > ta.valuewhen(slPrice, slPrice, 4)
fivePartUptrend = fourPartUptrend and ta.valuewhen(slPrice, slPrice, 4) > ta.valuewhen(slPrice, slPrice, 5)
sixPartUptrend = fivePartUptrend and ta.valuewhen(slPrice, slPrice, 5) > ta.valuewhen(slPrice, slPrice, 6)
sevenPartUptrend = sixPartUptrend and ta.valuewhen(slPrice, slPrice, 6) > ta.valuewhen(slPrice, slPrice, 7)
eightPartUptrend = sevenPartUptrend and ta.valuewhen(slPrice, slPrice, 7) > ta.valuewhen(slPrice, slPrice, 8)
ninePartUptrend = eightPartUptrend and ta.valuewhen(slPrice, slPrice, 8) > ta.valuewhen(slPrice, slPrice, 9)
tenPartUptrend = ninePartUptrend and ta.valuewhen(slPrice, slPrice, 9) > ta.valuewhen(slPrice, slPrice, 10)
elevenPartUptrend = tenPartUptrend and ta.valuewhen(slPrice, slPrice, 10) > ta.valuewhen(slPrice, slPrice, 11)
twelvePartUptrend = elevenPartUptrend and ta.valuewhen(slPrice, slPrice, 11) > ta.valuewhen(slPrice, slPrice, 12)
thirteenPartUptrend = twelvePartUptrend and ta.valuewhen(slPrice, slPrice, 12) > ta.valuewhen(slPrice, slPrice, 13)
fourteenPartUptrend = thirteenPartUptrend and ta.valuewhen(slPrice, slPrice, 13) > ta.valuewhen(slPrice, slPrice, 14)
fifteenPartUptrend = fourteenPartUptrend and ta.valuewhen(slPrice, slPrice, 14) > ta.valuewhen(slPrice, slPrice, 15)
sixteenPartUptrend = fifteenPartUptrend and ta.valuewhen(slPrice, slPrice, 15) > ta.valuewhen(slPrice, slPrice, 16)
seventeenPartUptrend = sixteenPartUptrend and ta.valuewhen(slPrice, slPrice, 16) > ta.valuewhen(slPrice, slPrice, 17)
eighteenPartUptrend = seventeenPartUptrend and ta.valuewhen(slPrice, slPrice, 17) > ta.valuewhen(slPrice, slPrice, 18)
nineteenPartUptrend = eighteenPartUptrend and ta.valuewhen(slPrice, slPrice, 18) > ta.valuewhen(slPrice, slPrice, 19)
twentyPartUptrend = nineteenPartUptrend and ta.valuewhen(slPrice, slPrice, 19) > ta.valuewhen(slPrice, slPrice, 20)


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


plotshape(slPrice and onePartUptrend and not twoPartUptrend and low <= low[1] ? onePartUptrend : na, 
 style = shape.triangleup, color = color.green, text = '1', textcolor = color.green, location = location.belowbar)
plotshape(slPrice and twoPartUptrend and not threePartUptrend and low <= low[1] ? twoPartUptrend : na, 
 style = shape.triangleup, color = color.green, text = '2', textcolor = color.green, location = location.belowbar)
plotshape(slPrice and threePartUptrend and not fourPartUptrend and low <= low[1] ? threePartUptrend : na, 
 style = shape.triangleup, color = color.green, text = '3', textcolor = color.green, location = location.belowbar)
plotshape(slPrice and fourPartUptrend and not fivePartUptrend and low <= low[1] ? fourPartUptrend : na, 
 style = shape.triangleup, color = color.green, text = '4', textcolor = color.green, location = location.belowbar)
plotshape(slPrice and fivePartUptrend and not sixPartUptrend and low <= low[1] ? fivePartUptrend : na, 
 style = shape.triangleup, color = color.green, text = '5', textcolor = color.green, location = location.belowbar)
plotshape(slPrice and sixPartUptrend and not sevenPartUptrend and low <= low[1] ? sixPartUptrend : na, 
 style = shape.triangleup, color = color.green, text = '6', textcolor = color.green, location = location.belowbar)
plotshape(slPrice and sevenPartUptrend and not eightPartUptrend and low <= low[1] ? sevenPartUptrend : na, 
 style = shape.triangleup, color = color.green, text = '7', textcolor = color.green, location = location.belowbar)
plotshape(slPrice and eightPartUptrend and not ninePartUptrend and low <= low[1] ? eightPartUptrend : na, 
 style = shape.triangleup, color = color.green, text = '8', textcolor = color.green, location = location.belowbar)
plotshape(slPrice and ninePartUptrend and not tenPartUptrend and low <= low[1] ? ninePartUptrend : na, 
 style = shape.triangleup, color = color.green, text = '9', textcolor = color.green, location = location.belowbar)
plotshape(slPrice and tenPartUptrend and not elevenPartUptrend and low <= low[1] ? tenPartUptrend : na, 
 style = shape.triangleup, color = color.green, text = '10', textcolor = color.green, location = location.belowbar)
plotshape(slPrice and elevenPartUptrend and not twelvePartUptrend and low <= low[1] ? elevenPartUptrend : na, 
 style = shape.triangleup, color = color.green, text = '11', textcolor = color.green, location = location.belowbar)
plotshape(slPrice and twelvePartUptrend and not thirteenPartUptrend and low <= low[1] ? twelvePartUptrend : na, 
 style = shape.triangleup, color = color.green, text = '12', textcolor = color.green, location = location.belowbar)
plotshape(slPrice and thirteenPartUptrend and not fourteenPartUptrend and low <= low[1] ? thirteenPartUptrend : na, 
 style = shape.triangleup, color = color.green, text = '13', textcolor = color.green, location = location.belowbar)
plotshape(slPrice and fourteenPartUptrend and not fifteenPartUptrend and low <= low[1] ? fourteenPartUptrend : na, 
 style = shape.triangleup, color = color.green, text = '14', textcolor = color.green, location = location.belowbar)
plotshape(slPrice and fifteenPartUptrend and not sixteenPartUptrend and low <= low[1] ? fifteenPartUptrend : na, 
 style = shape.triangleup, color = color.green, text = '15', textcolor = color.green, location = location.belowbar)
plotshape(slPrice and sixteenPartUptrend and not seventeenPartUptrend and low <= low[1] ? sixteenPartUptrend : na, 
 style = shape.triangleup, color = color.green, text = '16', textcolor = color.green, location = location.belowbar)
plotshape(slPrice and seventeenPartUptrend and not eighteenPartUptrend and low <= low[1] ? seventeenPartUptrend : na, 
 style = shape.triangleup, color = color.green, text = '17', textcolor = color.green, location = location.belowbar)
plotshape(slPrice and eighteenPartUptrend and not nineteenPartUptrend and low <= low[1] ? eighteenPartUptrend : na, 
 style = shape.triangleup, color = color.green, text = '18', textcolor = color.green, location = location.belowbar)
plotshape(slPrice and nineteenPartUptrend and not twentyPartUptrend and low <= low[1] ? nineteenPartUptrend : na, 
 style = shape.triangleup, color = color.green, text = '19', textcolor = color.green, location = location.belowbar)
plotshape(slPrice and twentyPartUptrend and low <= low[1] ? twentyPartUptrend : na, 
 style = shape.triangleup, color = color.green, text = '20', textcolor = color.green, location = location.belowbar)

plotshape(slPrice and onePartUptrend and not twoPartUptrend and low > low[1] ? onePartUptrend : na, 
 style = shape.triangleup, color = color.green, text = '1', textcolor = color.green, location = location.belowbar, offset = -1)
plotshape(slPrice and twoPartUptrend and not threePartUptrend and low > low[1] ? twoPartUptrend : na, 
 style = shape.triangleup, color = color.green, text = '2', textcolor = color.green, location = location.belowbar, offset = -1)
plotshape(slPrice and threePartUptrend and not fourPartUptrend and low > low[1] ? threePartUptrend : na, 
 style = shape.triangleup, color = color.green, text = '3', textcolor = color.green, location = location.belowbar, offset = -1)
plotshape(slPrice and fourPartUptrend and not fivePartUptrend and low > low[1] ? fourPartUptrend : na, 
 style = shape.triangleup, color = color.green, text = '4', textcolor = color.green, location = location.belowbar, offset = -1)
plotshape(slPrice and fivePartUptrend and not sixPartUptrend and low > low[1] ? fivePartUptrend : na, 
 style = shape.triangleup, color = color.green, text = '5', textcolor = color.green, location = location.belowbar, offset = -1)
plotshape(slPrice and sixPartUptrend and not sevenPartUptrend and low > low[1] ? sixPartUptrend : na, 
 style = shape.triangleup, color = color.green, text = '6', textcolor = color.green, location = location.belowbar, offset = -1)
plotshape(slPrice and sevenPartUptrend and not eightPartUptrend and low > low[1] ? sevenPartUptrend : na, 
 style = shape.triangleup, color = color.green, text = '7', textcolor = color.green, location = location.belowbar, offset = -1)
plotshape(slPrice and eightPartUptrend and not ninePartUptrend and low > low[1] ? eightPartUptrend : na, 
 style = shape.triangleup, color = color.green, text = '8', textcolor = color.green, location = location.belowbar, offset = -1)
plotshape(slPrice and ninePartUptrend and not tenPartUptrend and low > low[1] ? ninePartUptrend : na, 
 style = shape.triangleup, color = color.green, text = '9', textcolor = color.green, location = location.belowbar, offset = -1)
plotshape(slPrice and tenPartUptrend and not elevenPartUptrend and low > low[1] ? tenPartUptrend : na, 
 style = shape.triangleup, color = color.green, text = '10', textcolor = color.green, location = location.belowbar, offset = -1)
plotshape(slPrice and elevenPartUptrend and not twelvePartUptrend and low > low[1] ? elevenPartUptrend : na, 
 style = shape.triangleup, color = color.green, text = '11', textcolor = color.green, location = location.belowbar, offset = -1)
plotshape(slPrice and twelvePartUptrend and not thirteenPartUptrend and low > low[1] ? twelvePartUptrend : na, 
 style = shape.triangleup, color = color.green, text = '12', textcolor = color.green, location = location.belowbar, offset = -1)
plotshape(slPrice and thirteenPartUptrend and not fourteenPartUptrend and low > low[1] ? thirteenPartUptrend : na, 
 style = shape.triangleup, color = color.green, text = '13', textcolor = color.green, location = location.belowbar, offset = -1)
plotshape(slPrice and fourteenPartUptrend and not fifteenPartUptrend and low > low[1] ? fourteenPartUptrend : na, 
 style = shape.triangleup, color = color.green, text = '14', textcolor = color.green, location = location.belowbar, offset = -1)
plotshape(slPrice and fifteenPartUptrend and not sixteenPartUptrend and low > low[1] ? fifteenPartUptrend : na, 
 style = shape.triangleup, color = color.green, text = '15', textcolor = color.green, location = location.belowbar, offset = -1)
plotshape(slPrice and sixteenPartUptrend and not seventeenPartUptrend and low > low[1] ? sixteenPartUptrend : na, 
 style = shape.triangleup, color = color.green, text = '16', textcolor = color.green, location = location.belowbar, offset = -1)
plotshape(slPrice and seventeenPartUptrend and not eighteenPartUptrend and low > low[1] ? seventeenPartUptrend : na, 
 style = shape.triangleup, color = color.green, text = '17', textcolor = color.green, location = location.belowbar, offset = -1)
plotshape(slPrice and eighteenPartUptrend and not nineteenPartUptrend and low > low[1] ? eighteenPartUptrend : na, 
 style = shape.triangleup, color = color.green, text = '18', textcolor = color.green, location = location.belowbar, offset = -1)
plotshape(slPrice and nineteenPartUptrend and not twentyPartUptrend and low > low[1] ? nineteenPartUptrend : na, 
 style = shape.triangleup, color = color.green, text = '19', textcolor = color.green, location = location.belowbar, offset = -1)
plotshape(slPrice and twentyPartUptrend and low > low[1] ? twentyPartUptrend : na, 
 style = shape.triangleup, color = color.green, text = '20', textcolor = color.green, location = location.belowbar, offset = -1)




