Trend Counter [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=4


study("Trend Counter [theEccentricTrader]", overlay = true)


//////////// sample period filter ////////////


showSamplePeriod = input(defval = true, title = 'Show Sample Period', group = 'Sample Period')

start = input(defval = timestamp('2 Jan 1800 00:00'), title = 'Start Date', type = input.time, group = 'Sample Period')
end = input(defval = timestamp('1 Jan 3000 00:00'), title = 'End Date', type = input.time, group = 'Sample Period')
samplePeriodFilter = time >= start and time <= end

var barOneDate = time

f_timeToString(_t) =>
    tostring(dayofmonth(_t), '00') + '.' + tostring(month(_t), '00') + '.' + tostring(year(_t), '0000')

startDateText = barOneDate > start ? f_timeToString(barOneDate) : f_timeToString(start)
endDateText = time >= end ? '-' + f_timeToString(end) : '-' + f_timeToString(time)


//////////// trend counters //////////// 


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
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

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

onePartDowntrend = shPrice < valuewhen(shPrice, shPrice, 1) and samplePeriodFilter
twoPartDowntrend = onePartDowntrend and valuewhen(shPrice, shPrice, 1) < valuewhen(shPrice, shPrice, 2) and samplePeriodFilter 
threePartDowntrend = twoPartDowntrend and valuewhen(shPrice, shPrice, 2) < valuewhen(shPrice, shPrice, 3) and samplePeriodFilter
fourPartDowntrend = threePartDowntrend and valuewhen(shPrice, shPrice, 3) < valuewhen(shPrice, shPrice, 4) and samplePeriodFilter
fivePartDowntrend = fourPartDowntrend and valuewhen(shPrice, shPrice, 4) < valuewhen(shPrice, shPrice, 5) and samplePeriodFilter
sixPartDowntrend = fivePartDowntrend and valuewhen(shPrice, shPrice, 5) < valuewhen(shPrice, shPrice, 6) and samplePeriodFilter
sevenPartDowntrend = sixPartDowntrend and valuewhen(shPrice, shPrice, 6) < valuewhen(shPrice, shPrice, 7) and samplePeriodFilter
eightPartDowntrend = sevenPartDowntrend and valuewhen(shPrice, shPrice, 7) < valuewhen(shPrice, shPrice, 8) and samplePeriodFilter
ninePartDowntrend = eightPartDowntrend and valuewhen(shPrice, shPrice, 8) < valuewhen(shPrice, shPrice, 9) and samplePeriodFilter
tenPartDowntrend = ninePartDowntrend and valuewhen(shPrice, shPrice, 9) < valuewhen(shPrice, shPrice, 10) and samplePeriodFilter
elevenPartDowntrend = tenPartDowntrend and valuewhen(shPrice, shPrice, 10) < valuewhen(shPrice, shPrice, 11) and samplePeriodFilter
twelvePartDowntrend = elevenPartDowntrend and valuewhen(shPrice, shPrice, 11) < valuewhen(shPrice, shPrice, 12) and samplePeriodFilter
thirteenPartDowntrend = twelvePartDowntrend and valuewhen(shPrice, shPrice, 12) < valuewhen(shPrice, shPrice, 13) and samplePeriodFilter
fourteenPartDowntrend = thirteenPartDowntrend and valuewhen(shPrice, shPrice, 13) < valuewhen(shPrice, shPrice, 14) and samplePeriodFilter
fifteenPartDowntrend = fourteenPartDowntrend and valuewhen(shPrice, shPrice, 14) < valuewhen(shPrice, shPrice, 15) and samplePeriodFilter
sixteenPartDowntrend = fifteenPartDowntrend and valuewhen(shPrice, shPrice, 15) < valuewhen(shPrice, shPrice, 16) and samplePeriodFilter
seventeenPartDowntrend = sixteenPartDowntrend and valuewhen(shPrice, shPrice, 16) < valuewhen(shPrice, shPrice, 17) and samplePeriodFilter
eighteenPartDowntrend = seventeenPartDowntrend and valuewhen(shPrice, shPrice, 17) < valuewhen(shPrice, shPrice, 18) and samplePeriodFilter
nineteenPartDowntrend = eighteenPartDowntrend and valuewhen(shPrice, shPrice, 18) < valuewhen(shPrice, shPrice, 19) and samplePeriodFilter
twentyPartDowntrend = nineteenPartDowntrend and valuewhen(shPrice, shPrice, 19) < valuewhen(shPrice, shPrice, 20) and samplePeriodFilter

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

onePartReturnLineDowntrend = slPrice  < valuewhen(slPrice, slPrice, 1) and samplePeriodFilter
twoPartReturnLineDowntrend = onePartReturnLineDowntrend and valuewhen(slPrice, slPrice, 1) < valuewhen(slPrice, slPrice, 2) and samplePeriodFilter
threePartReturnLineDowntrend = twoPartReturnLineDowntrend and valuewhen(slPrice, slPrice, 2) < valuewhen(slPrice, slPrice, 3) and samplePeriodFilter
fourPartReturnLineDowntrend = threePartReturnLineDowntrend and valuewhen(slPrice, slPrice, 3) < valuewhen(slPrice, slPrice, 4) and samplePeriodFilter
fivePartReturnLineDowntrend = fourPartReturnLineDowntrend and valuewhen(slPrice, slPrice, 4) < valuewhen(slPrice, slPrice, 5) and samplePeriodFilter
sixPartReturnLineDowntrend = fivePartReturnLineDowntrend and valuewhen(slPrice, slPrice, 5) < valuewhen(slPrice, slPrice, 6) and samplePeriodFilter
sevenPartReturnLineDowntrend = sixPartReturnLineDowntrend and valuewhen(slPrice, slPrice, 6) < valuewhen(slPrice, slPrice, 7) and samplePeriodFilter
eightPartReturnLineDowntrend = sevenPartReturnLineDowntrend and valuewhen(slPrice, slPrice, 7) < valuewhen(slPrice, slPrice, 8) and samplePeriodFilter
ninePartReturnLineDowntrend = eightPartReturnLineDowntrend and valuewhen(slPrice, slPrice, 8) < valuewhen(slPrice, slPrice, 9) and samplePeriodFilter
tenPartReturnLineDowntrend = ninePartReturnLineDowntrend and valuewhen(slPrice, slPrice, 9) < valuewhen(slPrice, slPrice, 10) and samplePeriodFilter
elevenPartReturnLineDowntrend = tenPartReturnLineDowntrend and valuewhen(slPrice, slPrice, 10) < valuewhen(slPrice, slPrice, 11) and samplePeriodFilter
twelvePartReturnLineDowntrend = elevenPartReturnLineDowntrend and valuewhen(slPrice, slPrice, 11) < valuewhen(slPrice, slPrice, 12) and samplePeriodFilter
thirteenPartReturnLineDowntrend = twelvePartReturnLineDowntrend and valuewhen(slPrice, slPrice, 12) < valuewhen(slPrice, slPrice, 13) and samplePeriodFilter
fourteenPartReturnLineDowntrend = thirteenPartReturnLineDowntrend and valuewhen(slPrice, slPrice, 13) < valuewhen(slPrice, slPrice, 14) and samplePeriodFilter
fifteenPartReturnLineDowntrend = fourteenPartReturnLineDowntrend and valuewhen(slPrice, slPrice, 14) < valuewhen(slPrice, slPrice, 15) and samplePeriodFilter
sixteenPartReturnLineDowntrend = fifteenPartReturnLineDowntrend and valuewhen(slPrice, slPrice, 15) < valuewhen(slPrice, slPrice, 16) and samplePeriodFilter
seventeenPartReturnLineDowntrend = sixteenPartReturnLineDowntrend and valuewhen(slPrice, slPrice, 16) < valuewhen(slPrice, slPrice, 17) and samplePeriodFilter
eighteenPartReturnLineDowntrend = seventeenPartReturnLineDowntrend and valuewhen(slPrice, slPrice, 17) < valuewhen(slPrice, slPrice, 18) and samplePeriodFilter
nineteenPartReturnLineDowntrend = eighteenPartReturnLineDowntrend and valuewhen(slPrice, slPrice, 18) < valuewhen(slPrice, slPrice, 19) and samplePeriodFilter
twentyPartReturnLineDowntrend = nineteenPartReturnLineDowntrend and valuewhen(slPrice, slPrice, 19) < valuewhen(slPrice, slPrice, 20) and samplePeriodFilter

var onePartReturnLineUptrendCounter = 0 
var twoPartReturnLineUptrendCounter = 0
var threePartReturnLineUptrendCounter = 0
var fourPartReturnLineUptrendCounter = 0
var fivePartReturnLineUptrendCounter = 0
var sixPartReturnLineUptrendCounter = 0
var sevenPartReturnLineUptrendCounter = 0
var eightPartReturnLineUptrendCounter = 0
var ninePartReturnLineUptrendCounter = 0
var tenPartReturnLineUptrendCounter = 0
var elevenPartReturnLineUptrendCounter = 0
var twelvePartReturnLineUptrendCounter = 0
var thirteenPartReturnLineUptrendCounter = 0
var fourteenPartReturnLineUptrendCounter = 0
var fifteenPartReturnLineUptrendCounter = 0
var sixteenPartReturnLineUptrendCounter = 0
var seventeenPartReturnLineUptrendCounter = 0
var eighteenPartReturnLineUptrendCounter = 0
var nineteenPartReturnLineUptrendCounter = 0
var twentyPartReturnLineUptrendCounter = 0

var onePartDowntrendCounter = 0 
var twoPartDowntrendCounter = 0
var threePartDowntrendCounter = 0
var fourPartDowntrendCounter = 0
var fivePartDowntrendCounter = 0
var sixPartDowntrendCounter = 0
var sevenPartDowntrendCounter = 0
var eightPartDowntrendCounter = 0
var ninePartDowntrendCounter = 0
var tenPartDowntrendCounter = 0
var elevenPartDowntrendCounter = 0
var twelvePartDowntrendCounter = 0
var thirteenPartDowntrendCounter = 0
var fourteenPartDowntrendCounter = 0
var fifteenPartDowntrendCounter = 0
var sixteenPartDowntrendCounter = 0
var seventeenPartDowntrendCounter = 0
var eighteenPartDowntrendCounter = 0
var nineteenPartDowntrendCounter = 0
var twentyPartDowntrendCounter = 0

var onePartUptrendCounter = 0 
var twoPartUptrendCounter = 0
var threePartUptrendCounter = 0
var fourPartUptrendCounter = 0
var fivePartUptrendCounter = 0
var sixPartUptrendCounter = 0
var sevenPartUptrendCounter = 0
var eightPartUptrendCounter = 0
var ninePartUptrendCounter = 0
var tenPartUptrendCounter = 0
var elevenPartUptrendCounter = 0
var twelvePartUptrendCounter = 0
var thirteenPartUptrendCounter = 0
var fourteenPartUptrendCounter = 0
var fifteenPartUptrendCounter = 0
var sixteenPartUptrendCounter = 0
var seventeenPartUptrendCounter = 0
var eighteenPartUptrendCounter = 0
var nineteenPartUptrendCounter = 0
var twentyPartUptrendCounter = 0

var onePartReturnLineDowntrendCounter = 0 
var twoPartReturnLineDowntrendCounter = 0
var threePartReturnLineDowntrendCounter = 0
var fourPartReturnLineDowntrendCounter = 0
var fivePartReturnLineDowntrendCounter = 0
var sixPartReturnLineDowntrendCounter = 0
var sevenPartReturnLineDowntrendCounter = 0
var eightPartReturnLineDowntrendCounter = 0
var ninePartReturnLineDowntrendCounter = 0
var tenPartReturnLineDowntrendCounter = 0
var elevenPartReturnLineDowntrendCounter = 0
var twelvePartReturnLineDowntrendCounter = 0
var thirteenPartReturnLineDowntrendCounter = 0
var fourteenPartReturnLineDowntrendCounter = 0
var fifteenPartReturnLineDowntrendCounter = 0
var sixteenPartReturnLineDowntrendCounter = 0
var seventeenPartReturnLineDowntrendCounter = 0
var eighteenPartReturnLineDowntrendCounter = 0
var nineteenPartReturnLineDowntrendCounter = 0
var twentyPartReturnLineDowntrendCounter = 0

if onePartReturnLineUptrend and not twoPartReturnLineUptrend
    onePartReturnLineUptrendCounter += 1
if twoPartReturnLineUptrend and not threePartReturnLineUptrend
    twoPartReturnLineUptrendCounter += 1
if threePartReturnLineUptrend and not fourPartReturnLineUptrend
    threePartReturnLineUptrendCounter += 1
if fourPartReturnLineUptrend and not fivePartReturnLineUptrend
    fourPartReturnLineUptrendCounter += 1 
if fivePartReturnLineUptrend and not sixPartReturnLineUptrend
    fivePartReturnLineUptrendCounter += 1
if sixPartReturnLineUptrend and not sevenPartReturnLineUptrend
    sixPartReturnLineUptrendCounter += 1
if sevenPartReturnLineUptrend and not eightPartReturnLineUptrend
    sevenPartReturnLineUptrendCounter += 1
if eightPartReturnLineUptrend and not ninePartReturnLineUptrend
    eightPartReturnLineUptrendCounter += 1
if ninePartReturnLineUptrend and not tenPartReturnLineUptrend
    ninePartReturnLineUptrendCounter += 1
if tenPartReturnLineUptrend and not elevenPartReturnLineUptrend
    tenPartReturnLineUptrendCounter += 1
if elevenPartReturnLineUptrend and not twelvePartReturnLineUptrend
    elevenPartReturnLineUptrendCounter += 1
if twelvePartReturnLineUptrend and not thirteenPartReturnLineUptrend
    twelvePartReturnLineUptrendCounter += 1
if thirteenPartReturnLineUptrend and not fourteenPartReturnLineUptrend
    thirteenPartReturnLineUptrendCounter += 1
if fourteenPartReturnLineUptrend and not fifteenPartReturnLineUptrend
    fourteenPartReturnLineUptrendCounter += 1 
if fifteenPartReturnLineUptrend and not sixteenPartReturnLineUptrend
    fifteenPartReturnLineUptrendCounter += 1
if sixteenPartReturnLineUptrend and not seventeenPartReturnLineUptrend
    sixteenPartReturnLineUptrendCounter += 1
if seventeenPartReturnLineUptrend and not eighteenPartReturnLineUptrend
    seventeenPartReturnLineUptrendCounter += 1
if eighteenPartReturnLineUptrend and not nineteenPartReturnLineUptrend
    eighteenPartReturnLineUptrendCounter += 1  
if nineteenPartReturnLineUptrend and not twentyPartReturnLineUptrend
    nineteenPartReturnLineUptrendCounter += 1
if twentyPartReturnLineUptrend 
    twentyPartReturnLineUptrendCounter += 1

if onePartDowntrend and not twoPartDowntrend    
    onePartDowntrendCounter += 1
if twoPartDowntrend and not threePartDowntrend
    twoPartDowntrendCounter += 1
if threePartDowntrend and not fourPartDowntrend
    threePartDowntrendCounter += 1
if fourPartDowntrend and not fivePartDowntrend
    fourPartDowntrendCounter += 1   
if fivePartDowntrend and not sixPartDowntrend
    fivePartDowntrendCounter += 1
if sixPartDowntrend and not sevenPartDowntrend
    sixPartDowntrendCounter += 1
if sevenPartDowntrend and not eightPartDowntrend
    sevenPartDowntrendCounter += 1
if eightPartDowntrend and not ninePartDowntrend
    eightPartDowntrendCounter += 1
if ninePartDowntrend and not tenPartDowntrend
    ninePartDowntrendCounter += 1
if tenPartDowntrend and not elevenPartDowntrend
    tenPartDowntrendCounter += 1
if elevenPartDowntrend and not twelvePartDowntrend
    elevenPartDowntrendCounter += 1
if twelvePartDowntrend and not thirteenPartDowntrend
    twelvePartDowntrendCounter += 1  
if thirteenPartDowntrend and not fourteenPartDowntrend
    thirteenPartDowntrendCounter += 1
if fourteenPartDowntrend and not fifteenPartDowntrend
    fourteenPartDowntrendCounter += 1 
if fifteenPartDowntrend and not sixteenPartDowntrend
    fifteenPartDowntrendCounter += 1
if sixteenPartDowntrend and not seventeenPartDowntrend
    sixteenPartDowntrendCounter += 1
if seventeenPartDowntrend and not eighteenPartDowntrend
    seventeenPartDowntrendCounter += 1
if eighteenPartDowntrend and not nineteenPartDowntrend
    eighteenPartDowntrendCounter += 1
if nineteenPartDowntrend and not twentyPartDowntrend
    nineteenPartDowntrendCounter += 1
if twentyPartDowntrend
    twentyPartDowntrendCounter += 1

if onePartUptrend and not twoPartUptrend
    onePartUptrendCounter += 1
if twoPartUptrend and not threePartUptrend
    twoPartUptrendCounter += 1
if threePartUptrend and not fourPartUptrend
    threePartUptrendCounter += 1
if fourPartUptrend and not fivePartUptrend
    fourPartUptrendCounter += 1
if fivePartUptrend and not sixPartUptrend
    fivePartUptrendCounter += 1
if sixPartUptrend and not sevenPartUptrend
    sixPartUptrendCounter += 1
if sevenPartUptrend and not eightPartUptrend
    sevenPartUptrendCounter += 1
if eightPartUptrend and not ninePartUptrend
    eightPartUptrendCounter += 1  
if ninePartUptrend and not tenPartUptrend
    ninePartUptrendCounter += 1
if tenPartUptrend and not elevenPartUptrend
    tenPartUptrendCounter += 1
if elevenPartUptrend and not twelvePartUptrend
    elevenPartUptrendCounter += 1
if twelvePartUptrend and not thirteenPartUptrend
    twelvePartUptrendCounter += 1
if thirteenPartUptrend and not fourteenPartUptrend
    thirteenPartUptrendCounter += 1
if fourteenPartUptrend and not fifteenPartUptrend
    fourteenPartUptrendCounter += 1
if fifteenPartUptrend and not sixteenPartUptrend
    fifteenPartUptrendCounter += 1
if sixteenPartUptrend and not seventeenPartUptrend
    sixteenPartUptrendCounter += 1
if seventeenPartUptrend and not eighteenPartUptrend
    seventeenPartUptrendCounter += 1    
if eighteenPartUptrend and not nineteenPartUptrend
    eighteenPartUptrendCounter += 1    
if nineteenPartUptrend and not twentyPartUptrend
    nineteenPartUptrendCounter += 1
if twentyPartUptrend 
    twentyPartUptrendCounter += 1

if onePartReturnLineDowntrend and not twoPartReturnLineDowntrend
    onePartReturnLineDowntrendCounter += 1
if twoPartReturnLineDowntrend and not threePartReturnLineDowntrend
    twoPartReturnLineDowntrendCounter += 1
if threePartReturnLineDowntrend and not fourPartReturnLineDowntrend
    threePartReturnLineDowntrendCounter += 1
if fourPartReturnLineDowntrend and not fivePartReturnLineDowntrend
    fourPartReturnLineDowntrendCounter += 1
if fivePartReturnLineDowntrend and not sixPartReturnLineDowntrend
    fivePartReturnLineDowntrendCounter += 1
if sixPartReturnLineDowntrend and not sevenPartReturnLineDowntrend
    sixPartReturnLineDowntrendCounter += 1
if sevenPartReturnLineDowntrend and not eightPartReturnLineDowntrend
    sevenPartReturnLineDowntrendCounter += 1
if eightPartReturnLineDowntrend and not ninePartReturnLineDowntrend
    eightPartReturnLineDowntrendCounter += 1
if ninePartReturnLineDowntrend and not tenPartReturnLineDowntrend
    ninePartReturnLineDowntrendCounter += 1
if tenPartReturnLineDowntrend and not elevenPartReturnLineDowntrend
    tenPartReturnLineDowntrendCounter += 1
if elevenPartReturnLineDowntrend and not twelvePartReturnLineDowntrend
    elevenPartReturnLineDowntrendCounter += 1
if twelvePartReturnLineDowntrend and not thirteenPartReturnLineDowntrend
    twelvePartReturnLineDowntrendCounter += 1
if thirteenPartReturnLineDowntrend and not fourteenPartReturnLineDowntrend
    thirteenPartReturnLineDowntrendCounter += 1
if fourteenPartReturnLineDowntrend and not fifteenPartReturnLineDowntrend
    fourteenPartReturnLineDowntrendCounter += 1
if fifteenPartReturnLineDowntrend and not sixteenPartReturnLineDowntrend
    fifteenPartReturnLineDowntrendCounter += 1
if sixteenPartReturnLineDowntrend and not seventeenPartReturnLineDowntrend
    sixteenPartReturnLineDowntrendCounter += 1 
if seventeenPartReturnLineDowntrend and not eighteenPartReturnLineDowntrend
    seventeenPartReturnLineDowntrendCounter += 1  
if eighteenPartReturnLineDowntrend and not nineteenPartReturnLineDowntrend
    eighteenPartReturnLineDowntrendCounter += 1 
if nineteenPartReturnLineDowntrend and not twentyPartReturnLineDowntrend
    eighteenPartReturnLineDowntrendCounter += 1  
if twentyPartReturnLineDowntrend 
    twentyPartReturnLineDowntrendCounter += 1


//////////// table //////////// 


trendTablePositionInput = input(title = 'Position', defval = 'Top Right', options = ['Top Right', 'Top Center', 'Top Left', 'Bottom Right', 'Bottom Center', 'Bottom Left', 
 'Middle Right', 'Middle Center', 'Middle Left'], group = 'Table Positioning')
trendTablePosition = trendTablePositionInput == 'Top Right' ? position.top_right : trendTablePositionInput == 'Top Center' ? position.top_center : 
 trendTablePositionInput == 'Top Left' ? position.top_left : trendTablePositionInput == 'Bottom Right' ? position.bottom_right : 
 trendTablePositionInput == 'Bottom Center' ? position.bottom_center : trendTablePositionInput == 'Bottom Left' ? position.bottom_left : 
 trendTablePositionInput == 'Middle Right' ? position.middle_right : trendTablePositionInput == 'Middle Center' ? position.middle_center : 
 trendTablePositionInput == 'Middle Left' ? position.middle_left : na

textSizeInput = input(title = 'Text Size', defval = 'Normal', options = ['Tiny', 'Small', 'Normal', 'Large'], group = 'Table Text Sizing')
textSize = textSizeInput == 'Tiny' ? size.tiny : textSizeInput == 'Small' ? size.small : textSizeInput == 'Normal' ? size.normal : textSizeInput == 'Large' ? size.large : na

var trendTable = table.new(trendTablePosition, 100, 100, border_width = 1)

table.cell(trendTable, 2, 0, text = "Return Line Uptrends", bgcolor = color.green, text_color = color.white, text_size = textSize)
table.cell(trendTable, 3, 0, text = "% Total", bgcolor = color.green, text_color = color.white, text_size = textSize)
table.cell(trendTable, 4, 0, text = "% Last", bgcolor = color.green, text_color = color.white, text_size = textSize)
table.cell(trendTable, 5, 0, text = "Downtrends", bgcolor = color.red, text_color = color.white, text_size = textSize)
table.cell(trendTable, 6, 0, text = "% Total", bgcolor = color.red, text_color = color.white, text_size = textSize)
table.cell(trendTable, 7, 0, text = "% Last", bgcolor = color.red, text_color = color.white, text_size = textSize)

table.cell(trendTable, 1, 1, text = "1-Part", bgcolor = color.blue, text_color = color.white, text_size = textSize)
table.cell(trendTable, 2, 1, text = tostring(onePartReturnLineUptrendCounter), bgcolor = color.green, text_color = color.white, text_size = textSize)
table.cell(trendTable, 3, 1, text = "-", bgcolor = color.green, text_color = color.white, text_size = textSize)
table.cell(trendTable, 4, 1, text = "-", bgcolor = color.green, text_color = color.white, text_size = textSize)
table.cell(trendTable, 5, 1, text = tostring(onePartDowntrendCounter), bgcolor = color.red, text_color = color.white, text_size = textSize)
table.cell(trendTable, 6, 1, text = "-", bgcolor = color.red, text_color = color.white, text_size = textSize)
table.cell(trendTable, 7, 1, text = "-", bgcolor = color.red, text_color = color.white, text_size = textSize)

table.cell(trendTable, 2, 21, text = "Uptrends", bgcolor = color.green, text_color = color.white, text_size = textSize)
table.cell(trendTable, 3, 21, text = "% Total", bgcolor = color.green, text_color = color.white, text_size = textSize)
table.cell(trendTable, 4, 21, text = "% Last", bgcolor = color.green, text_color = color.white, text_size = textSize)
table.cell(trendTable, 5, 21, text = "Return Line Downtrends", bgcolor = color.red, text_color = color.white, text_size = textSize)
table.cell(trendTable, 6, 21, text = "% Total", bgcolor = color.red, text_color = color.white, text_size = textSize)
table.cell(trendTable, 7, 21, text = "% Last", bgcolor = color.red, text_color = color.white, text_size = textSize)

table.cell(trendTable, 1, 22, text = "1-Part", bgcolor = color.blue, text_color = color.white, text_size = textSize)
table.cell(trendTable, 2, 22, text = tostring(onePartUptrendCounter), bgcolor = color.green, text_color = color.white, text_size = textSize)
table.cell(trendTable, 3, 22, text = "-", bgcolor = color.green, text_color = color.white, text_size = textSize)
table.cell(trendTable, 4, 22, text = "-", bgcolor = color.green, text_color = color.white, text_size = textSize)
table.cell(trendTable, 5, 22, text = tostring(onePartReturnLineDowntrendCounter), bgcolor = color.red, text_color = color.white, text_size = textSize)
table.cell(trendTable, 6, 22, text = "-", bgcolor = color.red, text_color = color.white, text_size = textSize)
table.cell(trendTable, 7, 22, text = "-", bgcolor = color.red, text_color = color.white, text_size = textSize)

if (twoPartReturnLineUptrendCounter >= 1 or twoPartDowntrendCounter >= 1)       
    table.cell(trendTable, 1, 2, text = "2-Part", bgcolor = color.blue, text_color = color.white, text_size = textSize)
    table.cell(trendTable, 2, 2, text = tostring(twoPartReturnLineUptrendCounter), bgcolor = color.green, text_color = color.white, text_size = textSize)
    table.cell(trendTable, 3, 2, text = tostring(round(twoPartReturnLineUptrendCounter / onePartReturnLineUptrendCounter * 100, 2)), bgcolor = color.green, text_color = color.white, text_size = textSize)
    table.cell(trendTable, 4, 2, text = "-", bgcolor = color.green, text_color = color.white, text_size = textSize)
    table.cell(trendTable, 5, 2, text = tostring(twoPartDowntrendCounter), bgcolor = color.red, text_color = color.white, text_size = textSize)
    table.cell(trendTable, 6, 2, text = tostring(round(twoPartDowntrendCounter / onePartDowntrendCounter * 100, 2)), bgcolor = color.red, text_color = color.white, text_size = textSize)
    table.cell(trendTable, 7, 2, text = "-", bgcolor = color.red, text_color = color.white, text_size = textSize)  

if (threePartReturnLineUptrendCounter >= 1 or threePartDowntrendCounter >= 1)          
    table.cell(trendTable, 1, 3, text = "3-Part", bgcolor = color.blue, text_color = color.white, text_size = textSize)
    table.cell(trendTable, 2, 3, text = tostring(threePartReturnLineUptrendCounter), bgcolor = color.green, text_color = color.white, text_size = textSize)
    table.cell(trendTable, 3, 3, text = tostring(round(threePartReturnLineUptrendCounter / onePartReturnLineUptrendCounter * 100, 2)), bgcolor = color.green, text_color = color.white, text_size = textSize)
    table.cell(trendTable, 4, 3, text = tostring(round(threePartReturnLineUptrendCounter / twoPartReturnLineUptrendCounter * 100, 2)), bgcolor = color.green, text_color = color.white, text_size = textSize)
    table.cell(trendTable, 5, 3, text = tostring(threePartDowntrendCounter), bgcolor = color.red, text_color = color.white, text_size = textSize)
    table.cell(trendTable, 6, 3, text = tostring(round(threePartDowntrendCounter / onePartDowntrendCounter * 100, 2)), bgcolor = color.red, text_color = color.white, text_size = textSize)
    table.cell(trendTable, 7, 3, text = tostring(round(threePartDowntrendCounter / twoPartDowntrendCounter * 100, 2)), bgcolor = color.red, text_color = color.white, text_size = textSize)

if (fourPartReturnLineUptrendCounter >= 1 or fourPartDowntrendCounter >= 1)       
    table.cell(trendTable, 1, 4, text = "4-Part", bgcolor = color.blue, text_color = color.white, text_size = textSize)
    table.cell(trendTable, 2, 4, text = tostring(fourPartReturnLineUptrendCounter), bgcolor = color.green, text_color = color.white, text_size = textSize)
    table.cell(trendTable, 3, 4, text = tostring(round(fourPartReturnLineUptrendCounter / onePartReturnLineUptrendCounter * 100, 2)), bgcolor = color.green, text_color = color.white, text_size = textSize)
    table.cell(trendTable, 4, 4, text = tostring(round(fourPartReturnLineUptrendCounter / threePartReturnLineUptrendCounter * 100, 2)), bgcolor = color.green, text_color = color.white, text_size = textSize)
    table.cell(trendTable, 5, 4, text = tostring(fourPartDowntrendCounter), bgcolor = color.red, text_color = color.white, text_size = textSize)
    table.cell(trendTable, 6, 4, text = tostring(round(fourPartDowntrendCounter / onePartDowntrendCounter * 100, 2)), bgcolor = color.red, text_color = color.white, text_size = textSize)
    table.cell(trendTable, 7, 4, text = tostring(round(fourPartDowntrendCounter / threePartDowntrendCounter * 100, 2)), bgcolor = color.red, text_color = color.white, text_size = textSize)  

if (fivePartReturnLineUptrendCounter >= 1 or fivePartDowntrendCounter >= 1)       
    table.cell(trendTable, 1, 5, text = "5-Part", bgcolor = color.blue, text_color = color.white, text_size = textSize)
    table.cell(trendTable, 2, 5, text = tostring(fivePartReturnLineUptrendCounter), bgcolor = color.green, text_color = color.white, text_size = textSize)
    table.cell(trendTable, 3, 5, text = tostring(round(fivePartReturnLineUptrendCounter / onePartReturnLineUptrendCounter * 100, 2)), bgcolor = color.green, text_color = color.white, text_size = textSize)
    table.cell(trendTable, 4, 5, text = tostring(round(fivePartReturnLineUptrendCounter / fourPartReturnLineUptrendCounter * 100, 2)), bgcolor = color.green, text_color = color.white, text_size = textSize)
    table.cell(trendTable, 5, 5, text = tostring(fivePartDowntrendCounter), bgcolor = color.red, text_color = color.white, text_size = textSize)
    table.cell(trendTable, 6, 5, text = tostring(round(fivePartDowntrendCounter / onePartDowntrendCounter * 100, 2)), bgcolor = color.red, text_color = color.white, text_size = textSize)
    table.cell(trendTable, 7, 5, text = tostring(round(fivePartDowntrendCounter / fourPartDowntrendCounter * 100, 2)), bgcolor = color.red, text_color = color.white, text_size = textSize)

if (sixPartReturnLineUptrendCounter >= 1 or sixPartDowntrendCounter >= 1)       
    table.cell(trendTable, 1, 6, text = "6-Part", bgcolor = color.blue, text_color = color.white, text_size = textSize)
    table.cell(trendTable, 2, 6, text = tostring(sixPartReturnLineUptrendCounter), bgcolor = color.green, text_color = color.white, text_size = textSize)
    table.cell(trendTable, 3, 6, text = tostring(round(sixPartReturnLineUptrendCounter / onePartReturnLineUptrendCounter * 100, 2)), bgcolor = color.green, text_color = color.white, text_size = textSize)
    table.cell(trendTable, 4, 6, text = tostring(round(sixPartReturnLineUptrendCounter / fivePartReturnLineUptrendCounter * 100, 2)), bgcolor = color.green, text_color = color.white, text_size = textSize)
    table.cell(trendTable, 5, 6, text = tostring(sixPartDowntrendCounter), bgcolor = color.red, text_color = color.white, text_size = textSize)
    table.cell(trendTable, 6, 6, text = tostring(round(sixPartDowntrendCounter / onePartDowntrendCounter * 100, 2)), bgcolor = color.red, text_color = color.white, text_size = textSize)
    table.cell(trendTable, 7, 6, text = tostring(round(sixPartDowntrendCounter / fivePartDowntrendCounter * 100, 2)), bgcolor = color.red, text_color = color.white, text_size = textSize)

if (sevenPartReturnLineUptrendCounter >= 1 or sevenPartDowntrendCounter >= 1)       
    table.cell(trendTable, 1, 7, text = "7-Part", bgcolor = color.blue, text_color = color.white, text_size = textSize)
    table.cell(trendTable, 2, 7, text = tostring(sevenPartReturnLineUptrendCounter), bgcolor = color.green, text_color = color.white, text_size = textSize)
    table.cell(trendTable, 3, 7, text = tostring(round(sevenPartReturnLineUptrendCounter / onePartReturnLineUptrendCounter * 100, 2)), bgcolor = color.green, text_color = color.white, text_size = textSize)
    table.cell(trendTable, 4, 7, text = tostring(round(sevenPartReturnLineUptrendCounter / sixPartReturnLineUptrendCounter * 100, 2)), bgcolor = color.green, text_color = color.white, text_size = textSize)
    table.cell(trendTable, 5, 7, text = tostring(sevenPartDowntrendCounter), bgcolor = color.red, text_color = color.white, text_size = textSize)
    table.cell(trendTable, 6, 7, text = tostring(round(sevenPartDowntrendCounter / onePartDowntrendCounter * 100, 2)), bgcolor = color.red, text_color = color.white, text_size = textSize)
    table.cell(trendTable, 7, 7, text = tostring(round(sevenPartDowntrendCounter / sixPartDowntrendCounter * 100, 2)), bgcolor = color.red, text_color = color.white, text_size = textSize)

if (eightPartReturnLineUptrendCounter >= 1 or eightPartDowntrendCounter >= 1)       
    table.cell(trendTable, 1, 8, text = "8-Part", bgcolor = color.blue, text_color = color.white, text_size = textSize)
    table.cell(trendTable, 2, 8, text = tostring(eightPartReturnLineUptrendCounter), bgcolor = color.green, text_color = color.white, text_size = textSize)
    table.cell(trendTable, 3, 8, text = tostring(round(eightPartReturnLineUptrendCounter / onePartReturnLineUptrendCounter * 100, 2)), bgcolor = color.green, text_color = color.white, text_size = textSize)
    table.cell(trendTable, 4, 8, text = tostring(round(eightPartReturnLineUptrendCounter / sevenPartReturnLineUptrendCounter * 100, 2)), bgcolor = color.green, text_color = color.white, text_size = textSize)
    table.cell(trendTable, 5, 8, text = tostring(eightPartDowntrendCounter), bgcolor = color.red, text_color = color.white, text_size = textSize)
    table.cell(trendTable, 6, 8, text = tostring(round(eightPartDowntrendCounter / onePartDowntrendCounter * 100, 2)), bgcolor = color.red, text_color = color.white, text_size = textSize)
    table.cell(trendTable, 7, 8, text = tostring(round(eightPartDowntrendCounter / sevenPartDowntrendCounter * 100, 2)), bgcolor = color.red, text_color = color.white, text_size = textSize)

if (ninePartReturnLineUptrendCounter >= 1 or ninePartDowntrendCounter >= 1)       
    table.cell(trendTable, 1, 9, text = "9-Part", bgcolor = color.blue, text_color = color.white, text_size = textSize)
    table.cell(trendTable, 2, 9, text = tostring(ninePartReturnLineUptrendCounter), bgcolor = color.green, text_color = color.white, text_size = textSize)
    table.cell(trendTable, 3, 9, text = tostring(round(ninePartReturnLineUptrendCounter / onePartReturnLineUptrendCounter * 100, 2)), bgcolor = color.green, text_color = color.white, text_size = textSize)
    table.cell(trendTable, 4, 9, text = tostring(round(ninePartReturnLineUptrendCounter / eightPartReturnLineUptrendCounter * 100, 2)), bgcolor = color.green, text_color = color.white, text_size = textSize)
    table.cell(trendTable, 5, 9, text = tostring(ninePartDowntrendCounter), bgcolor = color.red, text_color = color.white, text_size = textSize)
    table.cell(trendTable, 6, 9, text = tostring(round(ninePartDowntrendCounter / onePartDowntrendCounter * 100, 2)), bgcolor = color.red, text_color = color.white, text_size = textSize)
    table.cell(trendTable, 7, 9, text = tostring(round(ninePartDowntrendCounter / eightPartDowntrendCounter * 100, 2)), bgcolor = color.red, text_color = color.white, text_size = textSize)

if (tenPartReturnLineUptrendCounter >= 1 or tenPartDowntrendCounter >= 1)       
    table.cell(trendTable, 1, 10, text = "10-Part", bgcolor = color.blue, text_color = color.white, text_size = textSize)
    table.cell(trendTable, 2, 10, text = tostring(tenPartReturnLineUptrendCounter), bgcolor = color.green, text_color = color.white, text_size = textSize)
    table.cell(trendTable, 3, 10, text = tostring(round(tenPartReturnLineUptrendCounter / onePartReturnLineUptrendCounter * 100, 2)), bgcolor = color.green, text_color = color.white, text_size = textSize)
    table.cell(trendTable, 4, 10, text = tostring(round(tenPartReturnLineUptrendCounter / ninePartReturnLineUptrendCounter * 100, 2)), bgcolor = color.green, text_color = color.white, text_size = textSize)
    table.cell(trendTable, 5, 10, text = tostring(tenPartDowntrendCounter), bgcolor = color.red, text_color = color.white, text_size = textSize)
    table.cell(trendTable, 6, 10, text = tostring(round(tenPartDowntrendCounter / onePartDowntrendCounter * 100, 2)), bgcolor = color.red, text_color = color.white, text_size = textSize)
    table.cell(trendTable, 7, 10, text = tostring(round(tenPartDowntrendCounter / ninePartDowntrendCounter * 100, 2)), bgcolor = color.red, text_color = color.white, text_size = textSize)

if (elevenPartReturnLineUptrendCounter >= 1 or elevenPartDowntrendCounter >= 1)      
    table.cell(trendTable, 1, 11, text = "11-Part", bgcolor = color.blue, text_color = color.white, text_size = textSize)
    table.cell(trendTable, 2, 11, text = tostring(elevenPartReturnLineUptrendCounter), bgcolor = color.green, text_color = color.white, text_size = textSize)
    table.cell(trendTable, 3, 11, text = tostring(round(elevenPartReturnLineUptrendCounter / onePartReturnLineUptrendCounter * 100, 2)), bgcolor = color.green, text_color = color.white, text_size = textSize)
    table.cell(trendTable, 4, 11, text = tostring(round(elevenPartReturnLineUptrendCounter / tenPartReturnLineUptrendCounter * 100, 2)), bgcolor = color.green, text_color = color.white, text_size = textSize)
    table.cell(trendTable, 5, 11, text = tostring(elevenPartDowntrendCounter), bgcolor = color.red, text_color = color.white, text_size = textSize)
    table.cell(trendTable, 6, 11, text = tostring(round(elevenPartDowntrendCounter / onePartDowntrendCounter * 100, 2)), bgcolor = color.red, text_color = color.white, text_size = textSize)
    table.cell(trendTable, 7, 11, text = tostring(round(elevenPartDowntrendCounter / tenPartDowntrendCounter * 100, 2)), bgcolor = color.red, text_color = color.white, text_size = textSize)

if (twelvePartReturnLineUptrendCounter >= 1 or twelvePartDowntrendCounter >= 1)       
    table.cell(trendTable, 1, 12, text = "12-Part", bgcolor = color.blue, text_color = color.white, text_size = textSize)
    table.cell(trendTable, 2, 12, text = tostring(twelvePartReturnLineUptrendCounter), bgcolor = color.green, text_color = color.white, text_size = textSize)
    table.cell(trendTable, 3, 12, text = tostring(round(twelvePartReturnLineUptrendCounter / onePartReturnLineUptrendCounter * 100, 2)), bgcolor = color.green, text_color = color.white, text_size = textSize)
    table.cell(trendTable, 4, 12, text = tostring(round(twelvePartReturnLineUptrendCounter / elevenPartReturnLineUptrendCounter * 100, 2)), bgcolor = color.green, text_color = color.white, text_size = textSize)
    table.cell(trendTable, 5, 12, text = tostring(twelvePartDowntrendCounter), bgcolor = color.red, text_color = color.white, text_size = textSize)
    table.cell(trendTable, 6, 12, text = tostring(round(twelvePartDowntrendCounter / onePartDowntrendCounter * 100, 2)), bgcolor = color.red, text_color = color.white, text_size = textSize)
    table.cell(trendTable, 7, 12, text = tostring(round(twelvePartDowntrendCounter / elevenPartDowntrendCounter * 100, 2)), bgcolor = color.red, text_color = color.white, text_size = textSize)

if (thirteenPartReturnLineUptrendCounter >= 1 or thirteenPartDowntrendCounter >= 1)       
    table.cell(trendTable, 1, 13, text = "13-Part", bgcolor = color.blue, text_color = color.white, text_size = textSize)
    table.cell(trendTable, 2, 13, text = tostring(thirteenPartReturnLineUptrendCounter), bgcolor = color.green, text_color = color.white, text_size = textSize)
    table.cell(trendTable, 3, 13, text = tostring(round(thirteenPartReturnLineUptrendCounter / onePartReturnLineUptrendCounter * 100, 2)), bgcolor = color.green, text_color = color.white, text_size = textSize)
    table.cell(trendTable, 4, 13, text = tostring(round(thirteenPartReturnLineUptrendCounter / twelvePartReturnLineUptrendCounter * 100, 2)), bgcolor = color.green, text_color = color.white, text_size = textSize)
    table.cell(trendTable, 5, 13, text = tostring(thirteenPartDowntrendCounter), bgcolor = color.red, text_color = color.white, text_size = textSize)
    table.cell(trendTable, 6, 13, text = tostring(round(thirteenPartDowntrendCounter / onePartDowntrendCounter * 100, 2)), bgcolor = color.red, text_color = color.white, text_size = textSize)
    table.cell(trendTable, 7, 13, text = tostring(round(thirteenPartDowntrendCounter / twelvePartDowntrendCounter * 100, 2)), bgcolor = color.red, text_color = color.white, text_size = textSize)

if (fourteenPartReturnLineUptrendCounter >= 1 or fourteenPartDowntrendCounter >= 1)       
    table.cell(trendTable, 1, 14, text = "14-Part", bgcolor = color.blue, text_color = color.white, text_size = textSize)
    table.cell(trendTable, 2, 14, text = tostring(fourteenPartReturnLineUptrendCounter), bgcolor = color.green, text_color = color.white, text_size = textSize)
    table.cell(trendTable, 3, 14, text = tostring(round(fourteenPartReturnLineUptrendCounter / onePartReturnLineUptrendCounter * 100, 2)), bgcolor = color.green, text_color = color.white, text_size = textSize)
    table.cell(trendTable, 4, 14, text = tostring(round(fourteenPartReturnLineUptrendCounter / thirteenPartReturnLineUptrendCounter * 100, 2)), bgcolor = color.green, text_color = color.white, text_size = textSize)
    table.cell(trendTable, 5, 14, text = tostring(fourteenPartDowntrendCounter), bgcolor = color.red, text_color = color.white, text_size = textSize)
    table.cell(trendTable, 6, 14, text = tostring(round(fourteenPartDowntrendCounter / onePartDowntrendCounter * 100, 2)), bgcolor = color.red, text_color = color.white, text_size = textSize)
    table.cell(trendTable, 7, 14, text = tostring(round(fourteenPartDowntrendCounter / thirteenPartDowntrendCounter * 100, 2)), bgcolor = color.red, text_color = color.white, text_size = textSize)

if (fifteenPartReturnLineUptrendCounter >= 1 or fifteenPartDowntrendCounter >= 1)       
    table.cell(trendTable, 1, 15, text = "15-Part", bgcolor = color.blue, text_color = color.white, text_size = textSize)
    table.cell(trendTable, 2, 15, text = tostring(fifteenPartReturnLineUptrendCounter), bgcolor = color.green, text_color = color.white, text_size = textSize)
    table.cell(trendTable, 3, 15, text = tostring(round(fifteenPartReturnLineUptrendCounter / onePartReturnLineUptrendCounter * 100, 2)), bgcolor = color.green, text_color = color.white, text_size = textSize)
    table.cell(trendTable, 4, 15, text = tostring(round(fifteenPartReturnLineUptrendCounter / fourteenPartReturnLineUptrendCounter * 100, 2)), bgcolor = color.green, text_color = color.white, text_size = textSize)
    table.cell(trendTable, 5, 15, text = tostring(fifteenPartDowntrendCounter), bgcolor = color.red, text_color = color.white, text_size = textSize)
    table.cell(trendTable, 6, 15, text = tostring(round(fifteenPartDowntrendCounter / onePartDowntrendCounter * 100, 2)), bgcolor = color.red, text_color = color.white, text_size = textSize)
    table.cell(trendTable, 7, 15, text = tostring(round(fifteenPartDowntrendCounter / fourteenPartDowntrendCounter * 100, 2)), bgcolor = color.red, text_color = color.white, text_size = textSize)

if (sixteenPartReturnLineUptrendCounter >= 1 or sixteenPartDowntrendCounter >= 1)       
    table.cell(trendTable, 1, 16, text = "16-Part", bgcolor = color.blue, text_color = color.white, text_size = textSize)
    table.cell(trendTable, 2, 16, text = tostring(sixteenPartReturnLineUptrendCounter), bgcolor = color.green, text_color = color.white, text_size = textSize)
    table.cell(trendTable, 3, 16, text = tostring(round(sixteenPartReturnLineUptrendCounter / onePartReturnLineUptrendCounter * 100, 2)) , bgcolor = color.green, text_color = color.white, text_size = textSize)
    table.cell(trendTable, 4, 16, text = tostring(round(sixteenPartReturnLineUptrendCounter / fifteenPartReturnLineUptrendCounter * 100, 2)), bgcolor = color.green, text_color = color.white, text_size = textSize)
    table.cell(trendTable, 5, 16, text = tostring(sixteenPartDowntrendCounter), bgcolor = color.red, text_color = color.white, text_size = textSize)
    table.cell(trendTable, 6, 16, text = tostring(round(sixteenPartDowntrendCounter / onePartDowntrendCounter * 100, 2)) , bgcolor = color.red, text_color = color.white, text_size = textSize)
    table.cell(trendTable, 7, 16, text = tostring(round(sixteenPartDowntrendCounter / fifteenPartDowntrendCounter * 100, 2)), bgcolor = color.red, text_color = color.white, text_size = textSize)

if (seventeenPartReturnLineUptrendCounter >= 1 or seventeenPartDowntrendCounter >= 1)       
    table.cell(trendTable, 1, 17, text = "17-Part", bgcolor = color.blue, text_color = color.white, text_size = textSize)
    table.cell(trendTable, 2, 17, text = tostring(seventeenPartReturnLineUptrendCounter), bgcolor = color.green, text_color = color.white, text_size = textSize)
    table.cell(trendTable, 3, 17, text = tostring(round(seventeenPartReturnLineUptrendCounter / onePartReturnLineUptrendCounter * 100, 2)), bgcolor = color.green, text_color = color.white, text_size = textSize)
    table.cell(trendTable, 4, 17, text = tostring(round(seventeenPartReturnLineUptrendCounter / sixteenPartReturnLineUptrendCounter * 100, 2)), bgcolor = color.green, text_color = color.white, text_size = textSize)
    table.cell(trendTable, 5, 17, text = tostring(seventeenPartDowntrendCounter), bgcolor = color.red, text_color = color.white, text_size = textSize)
    table.cell(trendTable, 6, 17, text = tostring(round(seventeenPartDowntrendCounter / onePartDowntrendCounter * 100, 2)), bgcolor = color.red, text_color = color.white, text_size = textSize)
    table.cell(trendTable, 7, 17, text = tostring(round(seventeenPartDowntrendCounter / sixteenPartDowntrendCounter * 100, 2)), bgcolor = color.red, text_color = color.white, text_size = textSize)

if (eighteenPartReturnLineUptrendCounter >= 1 or eighteenPartDowntrendCounter >= 1)    
    table.cell(trendTable, 1, 18, text = "18-Part", bgcolor = color.blue, text_color = color.white, text_size = textSize)
    table.cell(trendTable, 2, 18, text = tostring(eighteenPartReturnLineUptrendCounter), bgcolor = color.green, text_color = color.white, text_size = textSize)
    table.cell(trendTable, 3, 18, text = tostring(round(eighteenPartReturnLineUptrendCounter / onePartReturnLineUptrendCounter * 100, 2)), bgcolor = color.green, text_color = color.white, text_size = textSize)
    table.cell(trendTable, 4, 18, text = tostring(round(eighteenPartReturnLineUptrendCounter / seventeenPartReturnLineUptrendCounter * 100, 2)), bgcolor = color.green, text_color = color.white, text_size = textSize)
    table.cell(trendTable, 5, 18, text = tostring(eighteenPartDowntrendCounter), bgcolor = color.red, text_color = color.white, text_size = textSize)
    table.cell(trendTable, 6, 18, text = tostring(round(eighteenPartDowntrendCounter / onePartDowntrendCounter * 100, 2)), bgcolor = color.red, text_color = color.white, text_size = textSize)
    table.cell(trendTable, 7, 18, text = tostring(round(eighteenPartDowntrendCounter / seventeenPartDowntrendCounter * 100, 2)), bgcolor = color.red, text_color = color.white, text_size = textSize)

if (nineteenPartReturnLineUptrendCounter >= 1 or nineteenPartDowntrendCounter >= 1)       
    table.cell(trendTable, 1, 19, text = "19-Part", bgcolor = color.blue, text_color = color.white, text_size = textSize)
    table.cell(trendTable, 2, 19, text = tostring(nineteenPartReturnLineUptrendCounter), bgcolor = color.green, text_color = color.white, text_size = textSize)
    table.cell(trendTable, 3, 19, text = tostring(round(nineteenPartReturnLineUptrendCounter / onePartReturnLineUptrendCounter * 100, 2)), bgcolor = color.green, text_color = color.white, text_size = textSize)
    table.cell(trendTable, 4, 19, text = tostring(round(nineteenPartReturnLineUptrendCounter / eighteenPartReturnLineUptrendCounter * 100, 2)), bgcolor = color.green, text_color = color.white, text_size = textSize)
    table.cell(trendTable, 5, 19, text = tostring(nineteenPartDowntrendCounter), bgcolor = color.red, text_color = color.white, text_size = textSize)
    table.cell(trendTable, 6, 19, text = tostring(round(nineteenPartDowntrendCounter / onePartDowntrendCounter * 100, 2)), bgcolor = color.red, text_color = color.white, text_size = textSize)
    table.cell(trendTable, 7, 19, text = tostring(round(nineteenPartDowntrendCounter / eighteenPartDowntrendCounter * 100, 2)), bgcolor = color.red, text_color = color.white, text_size = textSize)

if (twentyPartReturnLineUptrendCounter >= 1 or twentyPartDowntrendCounter >= 1)       
    table.cell(trendTable, 1, 20, text = "20-Part", bgcolor = color.blue, text_color = color.white, text_size = textSize)
    table.cell(trendTable, 2, 20, text = tostring(twentyPartReturnLineUptrendCounter), bgcolor = color.green, text_color = color.white, text_size = textSize)
    table.cell(trendTable, 3, 20, text = tostring(round(twentyPartReturnLineUptrendCounter / onePartReturnLineUptrendCounter * 100, 2)), bgcolor = color.green, text_color = color.white, text_size = textSize)
    table.cell(trendTable, 4, 20, text = tostring(round(twentyPartReturnLineUptrendCounter / nineteenPartReturnLineUptrendCounter * 100, 2)), bgcolor = color.green, text_color = color.white, text_size = textSize)
    table.cell(trendTable, 5, 20, text = tostring(twentyPartDowntrendCounter), bgcolor = color.red, text_color = color.white, text_size = textSize)
    table.cell(trendTable, 6, 20, text = tostring(round(twentyPartDowntrendCounter / onePartDowntrendCounter * 100, 2)), bgcolor = color.red,text_color = color.white, text_size=textSize)
    table.cell(trendTable, 7, 20, text = tostring(round(twentyPartDowntrendCounter / nineteenPartDowntrendCounter * 100, 2)), bgcolor = color.red, text_color = color.white, text_size = textSize)

if (twoPartUptrendCounter >= 1 or twoPartReturnLineDowntrendCounter >= 1)       
    table.cell(trendTable, 1, 23, text = "2-Part", bgcolor = color.blue, text_color = color.white, text_size = textSize)
    table.cell(trendTable, 2, 23, text = tostring(twoPartUptrendCounter), bgcolor = color.green, text_color = color.white, text_size = textSize)
    table.cell(trendTable, 3, 23, text = tostring(round(twoPartUptrendCounter / onePartUptrendCounter * 100, 2)), bgcolor = color.green, text_color = color.white, text_size = textSize)
    table.cell(trendTable, 4, 23, text = "-", bgcolor = color.green, text_color = color.white, text_size = textSize)
    table.cell(trendTable, 5, 23, text = tostring(twoPartReturnLineDowntrendCounter), bgcolor = color.red, text_color = color.white, text_size = textSize)
    table.cell(trendTable, 6, 23, text = tostring(round(twoPartReturnLineDowntrendCounter / onePartReturnLineDowntrendCounter * 100, 2)), bgcolor = color.red, text_color = color.white, text_size = textSize)
    table.cell(trendTable, 7, 23, text = "-", bgcolor = color.red, text_color = color.white, text_size = textSize)  

if (threePartUptrendCounter >= 1 or threePartReturnLineDowntrendCounter >= 1)          
    table.cell(trendTable, 1, 24, text = "3-Part", bgcolor = color.blue, text_color = color.white, text_size = textSize)
    table.cell(trendTable, 2, 24, text = tostring(threePartUptrendCounter), bgcolor = color.green, text_color = color.white, text_size = textSize)
    table.cell(trendTable, 3, 24, text = tostring(round(threePartUptrendCounter / onePartUptrendCounter * 100, 2)), bgcolor = color.green, text_color = color.white, text_size = textSize)
    table.cell(trendTable, 4, 24, text = tostring(round(threePartUptrendCounter / twoPartUptrendCounter * 100, 2)), bgcolor = color.green, text_color = color.white, text_size = textSize)
    table.cell(trendTable, 5, 24, text = tostring(threePartReturnLineDowntrendCounter), bgcolor = color.red, text_color = color.white, text_size = textSize)
    table.cell(trendTable, 6, 24, text = tostring(round(threePartReturnLineDowntrendCounter / onePartReturnLineDowntrendCounter * 100, 2)), bgcolor = color.red, text_color = color.white, text_size = textSize)
    table.cell(trendTable, 7, 24, text = tostring(round(threePartReturnLineDowntrendCounter / twoPartReturnLineDowntrendCounter * 100, 2)), bgcolor = color.red, text_color = color.white, text_size = textSize)

if (fourPartUptrendCounter >= 1 or fourPartReturnLineDowntrendCounter >= 1)       
    table.cell(trendTable, 1, 25, text = "4-Part", bgcolor = color.blue, text_color = color.white, text_size = textSize)
    table.cell(trendTable, 2, 25, text = tostring(fourPartUptrendCounter), bgcolor = color.green, text_color = color.white, text_size = textSize)
    table.cell(trendTable, 3, 25, text = tostring(round(fourPartUptrendCounter / onePartUptrendCounter * 100, 2)), bgcolor = color.green, text_color = color.white, text_size = textSize)
    table.cell(trendTable, 4, 25, text = tostring(round(fourPartUptrendCounter / threePartUptrendCounter * 100, 2)), bgcolor = color.green, text_color = color.white, text_size = textSize)
    table.cell(trendTable, 5, 25, text = tostring(fourPartReturnLineDowntrendCounter), bgcolor = color.red, text_color = color.white, text_size = textSize)
    table.cell(trendTable, 6, 25, text = tostring(round(fourPartReturnLineDowntrendCounter / onePartReturnLineDowntrendCounter * 100, 2)), bgcolor = color.red, text_color = color.white, text_size = textSize)
    table.cell(trendTable, 7, 25, text = tostring(round(fourPartReturnLineDowntrendCounter / threePartReturnLineDowntrendCounter * 100, 2)), bgcolor = color.red, text_color = color.white, text_size = textSize)  

if (fivePartUptrendCounter >= 1 or fivePartReturnLineDowntrendCounter >= 1)       
    table.cell(trendTable, 1, 26, text = "5-Part", bgcolor = color.blue, text_color = color.white, text_size = textSize)
    table.cell(trendTable, 2, 26, text = tostring(fivePartUptrendCounter), bgcolor = color.green, text_color = color.white, text_size = textSize)
    table.cell(trendTable, 3, 26, text = tostring(round(fivePartUptrendCounter / onePartUptrendCounter * 100, 2)), bgcolor = color.green, text_color = color.white, text_size = textSize)
    table.cell(trendTable, 4, 26, text = tostring(round(fivePartUptrendCounter / fourPartUptrendCounter * 100, 2)), bgcolor = color.green, text_color = color.white, text_size = textSize)
    table.cell(trendTable, 5, 26, text = tostring(fivePartReturnLineDowntrendCounter), bgcolor = color.red, text_color = color.white, text_size = textSize)
    table.cell(trendTable, 6, 26, text = tostring(round(fivePartReturnLineDowntrendCounter / onePartReturnLineDowntrendCounter * 100, 2)), bgcolor = color.red, text_color = color.white, text_size = textSize)
    table.cell(trendTable, 7, 26, text = tostring(round(fivePartReturnLineDowntrendCounter / fourPartReturnLineDowntrendCounter * 100, 2)), bgcolor = color.red, text_color = color.white, text_size = textSize)

if (sixPartUptrendCounter >= 1 or sixPartReturnLineDowntrendCounter >= 1)       
    table.cell(trendTable, 1, 27, text = "6-Part", bgcolor = color.blue, text_color = color.white, text_size = textSize)
    table.cell(trendTable, 2, 27, text = tostring(sixPartUptrendCounter), bgcolor = color.green, text_color = color.white, text_size = textSize)
    table.cell(trendTable, 3, 27, text = tostring(round(sixPartUptrendCounter / onePartUptrendCounter * 100, 2)), bgcolor = color.green, text_color = color.white, text_size = textSize)
    table.cell(trendTable, 4, 27, text = tostring(round(sixPartUptrendCounter / fivePartUptrendCounter * 100, 2)), bgcolor = color.green, text_color = color.white, text_size = textSize)
    table.cell(trendTable, 5, 27, text = tostring(sixPartReturnLineDowntrendCounter), bgcolor = color.red, text_color = color.white, text_size = textSize)
    table.cell(trendTable, 6, 27, text = tostring(round(sixPartReturnLineDowntrendCounter / onePartReturnLineDowntrendCounter * 100, 2)), bgcolor = color.red, text_color = color.white, text_size = textSize)
    table.cell(trendTable, 7, 27, text = tostring(round(sixPartReturnLineDowntrendCounter / fivePartReturnLineDowntrendCounter * 100, 2)), bgcolor = color.red, text_color = color.white, text_size = textSize)

if (sevenPartUptrendCounter >= 1 or sevenPartReturnLineDowntrendCounter >= 1)       
    table.cell(trendTable, 1, 28, text = "7-Part", bgcolor = color.blue, text_color = color.white, text_size = textSize)
    table.cell(trendTable, 2, 28, text = tostring(sevenPartUptrendCounter), bgcolor = color.green, text_color = color.white, text_size = textSize)
    table.cell(trendTable, 3, 28, text = tostring(round(sevenPartUptrendCounter / onePartUptrendCounter * 100, 2)), bgcolor = color.green, text_color = color.white, text_size = textSize)
    table.cell(trendTable, 4, 28, text = tostring(round(sevenPartUptrendCounter / sixPartUptrendCounter * 100, 2)), bgcolor = color.green, text_color = color.white, text_size = textSize)
    table.cell(trendTable, 5, 28, text = tostring(sevenPartReturnLineDowntrendCounter), bgcolor = color.red, text_color = color.white, text_size = textSize)
    table.cell(trendTable, 6, 28, text = tostring(round(sevenPartReturnLineDowntrendCounter / onePartReturnLineDowntrendCounter * 100, 2)), bgcolor = color.red, text_color = color.white, text_size = textSize)
    table.cell(trendTable, 7, 28, text = tostring(round(sevenPartReturnLineDowntrendCounter / sixPartReturnLineDowntrendCounter * 100, 2)), bgcolor = color.red, text_color = color.white, text_size = textSize)

if (eightPartUptrendCounter >= 1 or eightPartReturnLineDowntrendCounter >= 1)       
    table.cell(trendTable, 1, 29, text = "8-Part", bgcolor = color.blue, text_color = color.white, text_size = textSize)
    table.cell(trendTable, 2, 29, text = tostring(eightPartUptrendCounter), bgcolor = color.green, text_color = color.white, text_size = textSize)
    table.cell(trendTable, 3, 29, text = tostring(round(eightPartUptrendCounter / onePartUptrendCounter * 100, 2)), bgcolor = color.green, text_color = color.white, text_size = textSize)
    table.cell(trendTable, 4, 29, text = tostring(round(eightPartUptrendCounter / sevenPartUptrendCounter * 100, 2)), bgcolor = color.green, text_color = color.white, text_size = textSize)
    table.cell(trendTable, 5, 29, text = tostring(eightPartReturnLineDowntrendCounter), bgcolor = color.red, text_color = color.white, text_size = textSize)
    table.cell(trendTable, 6, 29, text = tostring(round(eightPartReturnLineDowntrendCounter / onePartReturnLineDowntrendCounter * 100, 2)), bgcolor = color.red, text_color = color.white, text_size = textSize)
    table.cell(trendTable, 7, 29, text = tostring(round(eightPartReturnLineDowntrendCounter / sevenPartReturnLineDowntrendCounter * 100, 2)), bgcolor = color.red, text_color = color.white, text_size = textSize)

if (ninePartUptrendCounter >= 1 or ninePartReturnLineDowntrendCounter >= 1)       
    table.cell(trendTable, 1, 30, text = "9-Part", bgcolor = color.blue, text_color = color.white, text_size = textSize)
    table.cell(trendTable, 2, 30, text = tostring(ninePartUptrendCounter), bgcolor = color.green, text_color = color.white, text_size = textSize)
    table.cell(trendTable, 3, 30, text = tostring(round(ninePartUptrendCounter / onePartUptrendCounter * 100, 2)), bgcolor = color.green, text_color = color.white, text_size = textSize)
    table.cell(trendTable, 4, 30, text = tostring(round(ninePartUptrendCounter / eightPartUptrendCounter * 100, 2)), bgcolor = color.green, text_color = color.white, text_size = textSize)
    table.cell(trendTable, 5, 30, text = tostring(ninePartReturnLineDowntrendCounter), bgcolor = color.red, text_color = color.white, text_size = textSize)
    table.cell(trendTable, 6, 30, text = tostring(round(ninePartReturnLineDowntrendCounter / onePartReturnLineDowntrendCounter * 100, 2)), bgcolor = color.red, text_color = color.white, text_size = textSize)
    table.cell(trendTable, 7, 30, text = tostring(round(ninePartReturnLineDowntrendCounter / eightPartReturnLineDowntrendCounter * 100, 2)), bgcolor = color.red, text_color = color.white, text_size = textSize)

if (tenPartUptrendCounter >= 1 or tenPartReturnLineDowntrendCounter >= 1)       
    table.cell(trendTable, 1, 31, text = "10-Part", bgcolor = color.blue, text_color = color.white, text_size = textSize)
    table.cell(trendTable, 2, 31, text = tostring(tenPartUptrendCounter), bgcolor = color.green, text_color = color.white, text_size = textSize)
    table.cell(trendTable, 3, 31, text = tostring(round(tenPartUptrendCounter / onePartUptrendCounter * 100, 2)), bgcolor = color.green, text_color = color.white, text_size = textSize)
    table.cell(trendTable, 4, 31, text = tostring(round(tenPartUptrendCounter / ninePartUptrendCounter * 100, 2)), bgcolor = color.green, text_color = color.white, text_size = textSize)
    table.cell(trendTable, 5, 31, text = tostring(tenPartReturnLineDowntrendCounter), bgcolor = color.red, text_color = color.white, text_size = textSize)
    table.cell(trendTable, 6, 31, text = tostring(round(tenPartReturnLineDowntrendCounter / onePartReturnLineDowntrendCounter * 100, 2)), bgcolor = color.red, text_color = color.white, text_size = textSize)
    table.cell(trendTable, 7, 31, text = tostring(round(tenPartReturnLineDowntrendCounter / ninePartReturnLineDowntrendCounter * 100, 2)), bgcolor = color.red, text_color = color.white, text_size = textSize)

if (elevenPartUptrendCounter >= 1 or elevenPartReturnLineDowntrendCounter >= 1)      
    table.cell(trendTable, 1, 32, text = "11-Part", bgcolor = color.blue, text_color = color.white, text_size = textSize)
    table.cell(trendTable, 2, 32, text = tostring(elevenPartUptrendCounter), bgcolor = color.green, text_color = color.white, text_size = textSize)
    table.cell(trendTable, 3, 32, text = tostring(round(elevenPartUptrendCounter / onePartUptrendCounter * 100, 2)), bgcolor = color.green, text_color = color.white, text_size = textSize)
    table.cell(trendTable, 4, 32, text = tostring(round(elevenPartUptrendCounter / tenPartUptrendCounter * 100, 2)), bgcolor = color.green, text_color = color.white, text_size = textSize)
    table.cell(trendTable, 5, 32, text = tostring(elevenPartReturnLineDowntrendCounter), bgcolor = color.red, text_color = color.white, text_size = textSize)
    table.cell(trendTable, 6, 32, text = tostring(round(elevenPartReturnLineDowntrendCounter / onePartReturnLineDowntrendCounter * 100, 2)), bgcolor = color.red, text_color = color.white, text_size = textSize)
    table.cell(trendTable, 7, 32, text = tostring(round(elevenPartReturnLineDowntrendCounter / tenPartReturnLineDowntrendCounter * 100, 2)), bgcolor = color.red, text_color = color.white, text_size = textSize)

if (twelvePartUptrendCounter >= 1 or twelvePartReturnLineDowntrendCounter >= 1)       
    table.cell(trendTable, 1, 33, text = "12-Part", bgcolor = color.blue, text_color = color.white, text_size = textSize)
    table.cell(trendTable, 2, 33, text = tostring(twelvePartUptrendCounter), bgcolor = color.green, text_color = color.white, text_size = textSize)
    table.cell(trendTable, 3, 33, text = tostring(round(twelvePartUptrendCounter / onePartUptrendCounter * 100, 2)), bgcolor = color.green, text_color = color.white, text_size = textSize)
    table.cell(trendTable, 4, 33, text = tostring(round(twelvePartUptrendCounter / elevenPartUptrendCounter * 100, 2)), bgcolor = color.green, text_color = color.white, text_size = textSize)
    table.cell(trendTable, 5, 33, text = tostring(twelvePartReturnLineDowntrendCounter), bgcolor = color.red, text_color = color.white, text_size = textSize)
    table.cell(trendTable, 6, 33, text = tostring(round(twelvePartReturnLineDowntrendCounter / onePartReturnLineDowntrendCounter * 100, 2)), bgcolor = color.red, text_color = color.white, text_size = textSize)
    table.cell(trendTable, 7, 33, text = tostring(round(twelvePartReturnLineDowntrendCounter / elevenPartReturnLineDowntrendCounter * 100, 2)), bgcolor = color.red, text_color = color.white, text_size = textSize)

if (thirteenPartUptrendCounter >= 1 or thirteenPartReturnLineDowntrendCounter >= 1)       
    table.cell(trendTable, 1, 34, text = "13-Part", bgcolor = color.blue, text_color = color.white, text_size = textSize)
    table.cell(trendTable, 2, 34, text = tostring(thirteenPartUptrendCounter), bgcolor = color.green, text_color = color.white, text_size = textSize)
    table.cell(trendTable, 3, 34, text = tostring(round(thirteenPartUptrendCounter / onePartUptrendCounter * 100, 2)), bgcolor = color.green, text_color = color.white, text_size = textSize)
    table.cell(trendTable, 4, 34, text = tostring(round(thirteenPartUptrendCounter / twelvePartUptrendCounter * 100, 2)), bgcolor = color.green, text_color = color.white, text_size = textSize)
    table.cell(trendTable, 5, 34, text = tostring(thirteenPartReturnLineDowntrendCounter), bgcolor = color.red, text_color = color.white, text_size = textSize)
    table.cell(trendTable, 6, 34, text = tostring(round(thirteenPartReturnLineDowntrendCounter / onePartReturnLineDowntrendCounter * 100, 2)), bgcolor = color.red, text_color = color.white, text_size = textSize)
    table.cell(trendTable, 7, 34, text = tostring(round(thirteenPartReturnLineDowntrendCounter / twelvePartReturnLineDowntrendCounter * 100, 2)), bgcolor = color.red, text_color = color.white, text_size = textSize)

if (fourteenPartUptrendCounter >= 1 or fourteenPartReturnLineDowntrendCounter >= 1)       
    table.cell(trendTable, 1, 35, text = "14-Part", bgcolor = color.blue, text_color = color.white, text_size = textSize)
    table.cell(trendTable, 2, 35, text = tostring(fourteenPartUptrendCounter), bgcolor = color.green, text_color = color.white, text_size = textSize)
    table.cell(trendTable, 3, 35, text = tostring(round(fourteenPartUptrendCounter / onePartUptrendCounter * 100, 2)), bgcolor = color.green, text_color = color.white, text_size = textSize)
    table.cell(trendTable, 4, 35, text = tostring(round(fourteenPartUptrendCounter / thirteenPartUptrendCounter * 100, 2)), bgcolor = color.green, text_color = color.white, text_size = textSize)
    table.cell(trendTable, 5, 35, text = tostring(fourteenPartReturnLineDowntrendCounter), bgcolor = color.red, text_color = color.white, text_size = textSize)
    table.cell(trendTable, 6, 35, text = tostring(round(fourteenPartReturnLineDowntrendCounter / onePartReturnLineDowntrendCounter * 100, 2)), bgcolor = color.red, text_color = color.white, text_size = textSize)
    table.cell(trendTable, 7, 35, text = tostring(round(fourteenPartReturnLineDowntrendCounter / thirteenPartReturnLineDowntrendCounter * 100, 2)), bgcolor = color.red, text_color = color.white, text_size = textSize)

if (fifteenPartUptrendCounter >= 1 or fifteenPartReturnLineDowntrendCounter >= 1)       
    table.cell(trendTable, 1, 36, text = "15-Part", bgcolor = color.blue, text_color = color.white, text_size = textSize)
    table.cell(trendTable, 2, 36, text = tostring(fifteenPartUptrendCounter), bgcolor = color.green, text_color = color.white, text_size = textSize)
    table.cell(trendTable, 3, 36, text = tostring(round(fifteenPartUptrendCounter / onePartUptrendCounter * 100, 2)), bgcolor = color.green, text_color = color.white, text_size = textSize)
    table.cell(trendTable, 4, 36, text = tostring(round(fifteenPartUptrendCounter / fourteenPartUptrendCounter * 100, 2)), bgcolor = color.green, text_color = color.white, text_size = textSize)
    table.cell(trendTable, 5, 36, text = tostring(fifteenPartReturnLineDowntrendCounter), bgcolor = color.red, text_color = color.white, text_size = textSize)
    table.cell(trendTable, 6, 36, text = tostring(round(fifteenPartReturnLineDowntrendCounter / onePartReturnLineDowntrendCounter * 100, 2)), bgcolor = color.red, text_color = color.white, text_size = textSize)
    table.cell(trendTable, 7, 36, text = tostring(round(fifteenPartReturnLineDowntrendCounter / fourteenPartReturnLineDowntrendCounter * 100, 2)), bgcolor = color.red, text_color = color.white, text_size = textSize)

if (sixteenPartUptrendCounter >= 1 or sixteenPartReturnLineDowntrendCounter >= 1)       
    table.cell(trendTable, 1, 37, text = "16-Part", bgcolor = color.blue, text_color = color.white, text_size = textSize)
    table.cell(trendTable, 2, 37, text = tostring(sixteenPartUptrendCounter), bgcolor = color.green, text_color = color.white, text_size = textSize)
    table.cell(trendTable, 3, 37, text = tostring(round(sixteenPartUptrendCounter / onePartUptrendCounter * 100, 2)) , bgcolor = color.green, text_color = color.white, text_size = textSize)
    table.cell(trendTable, 4, 37, text = tostring(round(sixteenPartUptrendCounter / fifteenPartUptrendCounter * 100, 2)), bgcolor = color.green, text_color = color.white, text_size = textSize)
    table.cell(trendTable, 5, 37, text = tostring(sixteenPartReturnLineDowntrendCounter), bgcolor = color.red, text_color = color.white, text_size = textSize)
    table.cell(trendTable, 6, 37, text = tostring(round(sixteenPartReturnLineDowntrendCounter / onePartReturnLineDowntrendCounter * 100, 2)) , bgcolor = color.red, text_color = color.white, text_size = textSize)
    table.cell(trendTable, 7, 37, text = tostring(round(sixteenPartReturnLineDowntrendCounter / fifteenPartReturnLineDowntrendCounter * 100, 2)), bgcolor = color.red, text_color = color.white, text_size = textSize)

if (seventeenPartUptrendCounter >= 1 or seventeenPartReturnLineDowntrendCounter >= 1)       
    table.cell(trendTable, 1, 38, text = "17-Part", bgcolor = color.blue, text_color = color.white, text_size = textSize)
    table.cell(trendTable, 2, 38, text = tostring(seventeenPartUptrendCounter), bgcolor = color.green, text_color = color.white, text_size = textSize)
    table.cell(trendTable, 3, 38, text = tostring(round(seventeenPartUptrendCounter / onePartUptrendCounter * 100, 2)), bgcolor = color.green, text_color = color.white, text_size = textSize)
    table.cell(trendTable, 4, 38, text = tostring(round(seventeenPartUptrendCounter / sixteenPartUptrendCounter * 100, 2)), bgcolor = color.green, text_color = color.white, text_size = textSize)
    table.cell(trendTable, 5, 38, text = tostring(seventeenPartReturnLineDowntrendCounter), bgcolor = color.red, text_color = color.white, text_size = textSize)
    table.cell(trendTable, 6, 38, text = tostring(round(seventeenPartReturnLineDowntrendCounter / onePartReturnLineDowntrendCounter * 100, 2)), bgcolor = color.red, text_color = color.white, text_size = textSize)
    table.cell(trendTable, 7, 38, text = tostring(round(seventeenPartReturnLineDowntrendCounter / sixteenPartReturnLineDowntrendCounter * 100, 2)), bgcolor = color.red, text_color = color.white, text_size = textSize)

if (eighteenPartUptrendCounter >= 1 or eighteenPartReturnLineDowntrendCounter >= 1)    
    table.cell(trendTable, 1, 39, text = "18-Part", bgcolor = color.blue, text_color = color.white, text_size = textSize)
    table.cell(trendTable, 2, 39, text = tostring(eighteenPartUptrendCounter), bgcolor = color.green, text_color = color.white, text_size = textSize)
    table.cell(trendTable, 3, 39, text = tostring(round(eighteenPartUptrendCounter / onePartUptrendCounter * 100, 2)), bgcolor = color.green, text_color = color.white, text_size = textSize)
    table.cell(trendTable, 4, 39, text = tostring(round(eighteenPartUptrendCounter / seventeenPartUptrendCounter * 100, 2)), bgcolor = color.green, text_color = color.white, text_size = textSize)
    table.cell(trendTable, 5, 39, text = tostring(eighteenPartReturnLineDowntrendCounter), bgcolor = color.red, text_color = color.white, text_size = textSize)
    table.cell(trendTable, 6, 39, text = tostring(round(eighteenPartReturnLineDowntrendCounter / onePartReturnLineDowntrendCounter * 100, 2)), bgcolor = color.red, text_color = color.white, text_size = textSize)
    table.cell(trendTable, 7, 39, text = tostring(round(eighteenPartReturnLineDowntrendCounter / seventeenPartReturnLineDowntrendCounter * 100, 2)), bgcolor = color.red, text_color = color.white, text_size = textSize)

if (nineteenPartUptrendCounter >= 1 or nineteenPartReturnLineDowntrendCounter >= 1)       
    table.cell(trendTable, 1, 40, text = "19-Part", bgcolor = color.blue, text_color = color.white, text_size = textSize)
    table.cell(trendTable, 2, 40, text = tostring(nineteenPartUptrendCounter), bgcolor = color.green, text_color = color.white, text_size = textSize)
    table.cell(trendTable, 3, 40, text = tostring(round(nineteenPartUptrendCounter / onePartUptrendCounter * 100, 2)), bgcolor = color.green, text_color = color.white, text_size = textSize)
    table.cell(trendTable, 4, 40, text = tostring(round(nineteenPartUptrendCounter / eighteenPartUptrendCounter * 100, 2)), bgcolor = color.green, text_color = color.white, text_size = textSize)
    table.cell(trendTable, 5, 40, text = tostring(nineteenPartReturnLineDowntrendCounter), bgcolor = color.red, text_color = color.white, text_size = textSize)
    table.cell(trendTable, 6, 40, text = tostring(round(nineteenPartReturnLineDowntrendCounter / onePartReturnLineDowntrendCounter * 100, 2)), bgcolor = color.red, text_color = color.white, text_size = textSize)
    table.cell(trendTable, 7, 40, text = tostring(round(nineteenPartReturnLineDowntrendCounter / eighteenPartReturnLineDowntrendCounter * 100, 2)), bgcolor = color.red, text_color = color.white, text_size = textSize)

if (twentyPartUptrendCounter >= 1 or twentyPartReturnLineDowntrendCounter >= 1)       
    table.cell(trendTable, 1, 41, text = "20-Part", bgcolor = color.blue, text_color = color.white, text_size = textSize)
    table.cell(trendTable, 2, 41, text = tostring(twentyPartUptrendCounter), bgcolor = color.green, text_color = color.white, text_size = textSize)
    table.cell(trendTable, 3, 41, text = tostring(round(twentyPartUptrendCounter / onePartUptrendCounter * 100, 2)), bgcolor = color.green, text_color = color.white, text_size = textSize)
    table.cell(trendTable, 4, 41, text = tostring(round(twentyPartUptrendCounter / nineteenPartUptrendCounter * 100, 2)), bgcolor = color.green, text_color = color.white, text_size = textSize)
    table.cell(trendTable, 5, 41, text = tostring(twentyPartReturnLineDowntrendCounter), bgcolor = color.red, text_color = color.white, text_size = textSize)
    table.cell(trendTable, 6, 41, text = tostring(round(twentyPartReturnLineDowntrendCounter / onePartReturnLineDowntrendCounter * 100, 2)), bgcolor = color.red,text_color = color.white, text_size=textSize)
    table.cell(trendTable, 7, 41, text = tostring(round(twentyPartReturnLineDowntrendCounter / nineteenPartReturnLineDowntrendCounter * 100, 2)), bgcolor = color.red, text_color = color.white, text_size = textSize)
    
if showSamplePeriod 
    table.cell(trendTable, 1, 42, text = startDateText + endDateText, bgcolor = color.black, text_color = color.white, text_size = textSize)


