Candle 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=5

indicator('Candle Trend Counter [theEccentricTrader]', overlay = true)

///////////////////////////
//  SAMPLE PERIOD FILTER //
///////////////////////////

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

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

var barOneDate = time

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

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

///////////////////////////
// CANDLE TREND COUNTERS // 
///////////////////////////

oneGC = close[1] < open[1] and close >= open and samplePeriodFilter and barstate.isconfirmed
twoGC = oneGC[1] and close >= open and samplePeriodFilter and barstate.isconfirmed
threeGC = twoGC[1] and close >= open and samplePeriodFilter and barstate.isconfirmed
fourGC = threeGC[1] and close >= open and samplePeriodFilter and barstate.isconfirmed
fiveGC = fourGC[1] and close >= open and samplePeriodFilter and barstate.isconfirmed
sixGC = fiveGC[1] and close >= open and samplePeriodFilter and barstate.isconfirmed
sevenGC = sixGC[1] and close >= open and samplePeriodFilter and barstate.isconfirmed
eightGC = sevenGC[1] and close >= open and samplePeriodFilter and barstate.isconfirmed
nineGC = eightGC[1] and close >= open and samplePeriodFilter and barstate.isconfirmed
tenGC = nineGC[1] and close >= open and samplePeriodFilter and barstate.isconfirmed
elevenGC = tenGC[1] and close >= open and samplePeriodFilter and barstate.isconfirmed
twelveGC = elevenGC[1] and close >= open and samplePeriodFilter and barstate.isconfirmed
thirteenGC = twelveGC[1] and close >= open and samplePeriodFilter and barstate.isconfirmed
fourteenGC = thirteenGC[1] and close >= open and samplePeriodFilter and barstate.isconfirmed
fifteenGC = fourteenGC[1] and close >= open and samplePeriodFilter and barstate.isconfirmed
sixteenGC = fifteenGC[1] and close >= open and samplePeriodFilter and barstate.isconfirmed
seventeenGC = sixteenGC[1] and close >= open and samplePeriodFilter and barstate.isconfirmed
eighteenGC = seventeenGC[1] and close >= open and samplePeriodFilter and barstate.isconfirmed
nineteenGC = eighteenGC[1] and close >= open and samplePeriodFilter and barstate.isconfirmed
twentyGC = nineteenGC[1] and close >= open and samplePeriodFilter and barstate.isconfirmed
twentyoneGC = twentyGC[1] and close >= open and samplePeriodFilter and barstate.isconfirmed
twentytwoGC = twentyoneGC[1] and close >= open and samplePeriodFilter and barstate.isconfirmed
twentythreeGC = twentytwoGC[1] and close >= open and samplePeriodFilter and barstate.isconfirmed
twentyfourGC = twentythreeGC[1] and close >= open and samplePeriodFilter and barstate.isconfirmed
twentyfiveGC = twentyfourGC[1] and close >= open and samplePeriodFilter and barstate.isconfirmed
twentysixGC = twentyfiveGC[1] and close >= open and samplePeriodFilter and barstate.isconfirmed
twentysevenGC = twentysixGC[1] and close >= open and samplePeriodFilter and barstate.isconfirmed
twentyeightGC = twentysevenGC[1] and close >= open and samplePeriodFilter and barstate.isconfirmed
twentynineGC = twentyeightGC[1] and close >= open and samplePeriodFilter and barstate.isconfirmed
thirtyGC = twentynineGC[1] and close >= open and samplePeriodFilter and barstate.isconfirmed

oneRC = close[1] >= open[1] and close < open and samplePeriodFilter and barstate.isconfirmed
twoRC = oneRC[1] and close < open and samplePeriodFilter and barstate.isconfirmed
threeRC = twoRC[1] and close < open and samplePeriodFilter and barstate.isconfirmed
fourRC = threeRC[1] and close < open and samplePeriodFilter and barstate.isconfirmed
fiveRC = fourRC[1] and close < open and samplePeriodFilter and barstate.isconfirmed
sixRC = fiveRC[1] and close < open and samplePeriodFilter and barstate.isconfirmed
sevenRC = sixRC[1] and close < open and samplePeriodFilter and barstate.isconfirmed
eightRC = sevenRC[1] and close < open and samplePeriodFilter and barstate.isconfirmed
nineRC = eightRC[1] and close < open and samplePeriodFilter and barstate.isconfirmed
tenRC = nineRC[1] and close < open and samplePeriodFilter and barstate.isconfirmed
elevenRC = tenRC[1] and close < open and samplePeriodFilter and barstate.isconfirmed
twelveRC = elevenRC[1] and close < open and samplePeriodFilter and barstate.isconfirmed
thirteenRC = twelveRC[1] and close < open and samplePeriodFilter and barstate.isconfirmed
fourteenRC = thirteenRC[1] and close < open and samplePeriodFilter and barstate.isconfirmed
fifteenRC = fourteenRC[1] and close < open and samplePeriodFilter and barstate.isconfirmed
sixteenRC = fifteenRC[1] and close < open and samplePeriodFilter and barstate.isconfirmed
seventeenRC = sixteenRC[1] and close < open and samplePeriodFilter and barstate.isconfirmed
eighteenRC = seventeenRC[1] and close < open and samplePeriodFilter and barstate.isconfirmed
nineteenRC = eighteenRC[1] and close < open and samplePeriodFilter and barstate.isconfirmed
twentyRC = nineteenRC[1] and close < open and samplePeriodFilter and barstate.isconfirmed
twentyoneRC = twentyRC[1] and close < open and samplePeriodFilter and barstate.isconfirmed
twentytwoRC = twentyoneRC[1] and close < open and samplePeriodFilter and barstate.isconfirmed
twentythreeRC = twentytwoRC[1] and close < open and samplePeriodFilter and barstate.isconfirmed
twentyfourRC = twentythreeRC[1] and close < open and samplePeriodFilter and barstate.isconfirmed
twentyfiveRC = twentyfourRC[1] and close < open and samplePeriodFilter and barstate.isconfirmed
twentysixRC = twentyfiveRC[1] and close < open and samplePeriodFilter and barstate.isconfirmed
twentysevenRC = twentysixRC[1] and close < open and samplePeriodFilter and barstate.isconfirmed
twentyeightRC = twentysevenRC[1] and close < open and samplePeriodFilter and barstate.isconfirmed
twentynineRC = twentyeightRC[1] and close < open and samplePeriodFilter and barstate.isconfirmed
thirtyRC = twentynineRC[1] and close < open and samplePeriodFilter and barstate.isconfirmed

var oneGCcounter = 0
var twoGCcounter = 0
var threeGCcounter = 0
var fourGCcounter = 0
var fiveGCcounter = 0
var sixGCcounter = 0
var sevenGCcounter = 0
var eightGCcounter = 0
var nineGCcounter = 0
var tenGCcounter = 0
var elevenGCcounter = 0
var twelveGCcounter = 0
var thirteenGCcounter = 0
var fourteenGCcounter = 0
var fifteenGCcounter = 0
var sixteenGCcounter = 0
var seventeenGCcounter = 0
var eighteenGCcounter = 0
var nineteenGCcounter = 0
var twentyGCcounter = 0
var twentyoneGCcounter = 0
var twentytwoGCcounter = 0
var twentythreeGCcounter = 0
var twentyfourGCcounter = 0
var twentyfiveGCcounter = 0
var twentysixGCcounter = 0
var twentysevenGCcounter = 0
var twentyeightGCcounter = 0
var twentynineGCcounter = 0
var thirtyGCcounter = 0 

var oneRCcounter = 0
var twoRCcounter = 0
var threeRCcounter = 0
var fourRCcounter = 0
var fiveRCcounter = 0
var sixRCcounter = 0
var sevenRCcounter = 0
var eightRCcounter = 0
var nineRCcounter = 0
var tenRCcounter = 0
var elevenRCcounter = 0
var twelveRCcounter = 0
var thirteenRCcounter = 0
var fourteenRCcounter = 0
var fifteenRCcounter = 0
var sixteenRCcounter = 0
var seventeenRCcounter = 0
var eighteenRCcounter = 0
var nineteenRCcounter = 0
var twentyRCcounter = 0
var twentyoneRCcounter = 0
var twentytwoRCcounter = 0
var twentythreeRCcounter = 0
var twentyfourRCcounter = 0
var twentyfiveRCcounter = 0
var twentysixRCcounter = 0
var twentysevenRCcounter = 0
var twentyeightRCcounter = 0
var twentynineRCcounter = 0
var thirtyRCcounter = 0

if oneGC
    oneGCcounter += 1
if twoGC
    twoGCcounter += 1
if threeGC
    threeGCcounter += 1
if fourGC
    fourGCcounter += 1
if fiveGC
    fiveGCcounter += 1
if sixGC
    sixGCcounter += 1
if sevenGC
    sevenGCcounter += 1
if eightGC
    eightGCcounter += 1
if nineGC
    nineGCcounter += 1
if tenGC
    tenGCcounter += 1
if elevenGC
    elevenGCcounter += 1
if twelveGC
    twelveGCcounter += 1
if thirteenGC
    thirteenGCcounter += 1
if fourteenGC
    fourteenGCcounter += 1
if fifteenGC
    fifteenGCcounter += 1
if sixteenGC
    sixteenGCcounter += 1
if seventeenGC
    seventeenGCcounter += 1
if eighteenGC
    eighteenGCcounter += 1
if nineteenGC
    nineteenGCcounter += 1
if twentyGC
    twentyGCcounter += 1
if twentyoneGC
    twentyoneGCcounter += 1
if twentytwoGC
    twentytwoGCcounter += 1
if twentythreeGC
    twentythreeGCcounter += 1
if twentyfourGC
    twentyfourGCcounter += 1
if twentyfiveGC
    twentyfiveGCcounter += 1
if twentysixGC
    twentysixGCcounter += 1
if twentysevenGC
    twentysevenGCcounter += 1
if twentyeightGC
    twentyeightGCcounter += 1
if twentynineGC
    twentynineGCcounter += 1
if thirtyGC
    thirtyGCcounter += 1

if oneRC
    oneRCcounter += 1
if twoRC
    twoRCcounter += 1
if threeRC
    threeRCcounter += 1
if fourRC
    fourRCcounter += 1
if fiveRC
    fiveRCcounter += 1
if sixRC
    sixRCcounter += 1
if sevenRC
    sevenRCcounter += 1
if eightRC
    eightRCcounter += 1
if nineRC
    nineRCcounter += 1
if tenRC
    tenRCcounter += 1
if elevenRC
    elevenRCcounter += 1
if twelveRC
    twelveRCcounter += 1
if thirteenRC
    thirteenRCcounter += 1 
if fourteenRC
    fourteenRCcounter += 1
if fifteenRC
    fifteenRCcounter += 1
if sixteenRC
    sixteenRCcounter += 1
if seventeenRC
    seventeenRCcounter += 1
if eighteenRC
    eighteenRCcounter += 1
if nineteenRC
    nineteenRCcounter += 1
if twentyRC
    twentyRCcounter += 1
if twentyoneRC
    twentyoneRCcounter += 1
if twentytwoRC
    twentytwoRCcounter += 1
if twentythreeRC
    twentythreeRCcounter += 1
if twentyfourRC
    twentyfourRCcounter += 1
if twentyfiveRC
    twentyfiveRCcounter += 1
if twentysixRC
    twentysixRCcounter += 1
if twentysevenRC
    twentysevenRCcounter += 1
if twentyeightRC
    twentyeightRCcounter += 1
if twentynineRC
    twentynineRCcounter += 1
if thirtyRC
    thirtyRCcounter += 1

/////////// 
// TABLE //
///////////

candleTrendTablePositionInput = input.string(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')
candleTrendTablePosition = candleTrendTablePositionInput == 'Top Right' ? position.top_right : candleTrendTablePositionInput == 'Top Center' ? position.top_center : 
 candleTrendTablePositionInput == 'Top Left' ? position.top_left : candleTrendTablePositionInput == 'Bottom Right' ? position.bottom_right : 
 candleTrendTablePositionInput == 'Bottom Center' ? position.bottom_center : candleTrendTablePositionInput == 'Bottom Left' ? position.bottom_left : 
 candleTrendTablePositionInput == 'Middle Right' ? position.middle_right : candleTrendTablePositionInput == 'Middle Center' ? position.middle_center : 
 candleTrendTablePositionInput == 'Middle Left' ? position.middle_left : na

textSizeInput = input.string(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 candleTrendTable = table.new(candleTrendTablePosition, 100, 100, border_width = 1)

table.cell(candleTrendTable, 1, 0, text = 'Green Swings', bgcolor = color.green, text_color = color.white, text_size = textSize)
table.cell(candleTrendTable, 2, 0, text = '% Total', bgcolor = color.green, text_color = color.white, text_size = textSize)
table.cell(candleTrendTable, 3, 0, text = '% Last', bgcolor = color.green, text_color = color.white, text_size = textSize)
table.cell(candleTrendTable, 0, 1, text = '1-Candle', bgcolor = color.blue, text_color = color.white, text_size = textSize)
table.cell(candleTrendTable, 1, 1, text = str.tostring(oneGCcounter), bgcolor = color.green, text_color = color.white, text_size = textSize)
table.cell(candleTrendTable, 2, 1, text = '-', bgcolor = color.green, text_color = color.white, text_size = textSize)
table.cell(candleTrendTable, 3, 1, text = '-', bgcolor = color.green, text_color = color.white, text_size = textSize)
table.cell(candleTrendTable, 4, 0, text = 'Red Swings', bgcolor = color.red, text_color = color.white, text_size = textSize)
table.cell(candleTrendTable, 5, 0, text = '% Total', bgcolor = color.red, text_color = color.white, text_size = textSize)
table.cell(candleTrendTable, 6, 0, text = '% Last', bgcolor = color.red, text_color = color.white, text_size = textSize)
table.cell(candleTrendTable, 4, 1, text = str.tostring(oneRCcounter), bgcolor = color.red, text_color = color.white, text_size = textSize)
table.cell(candleTrendTable, 5, 1, text = '-', bgcolor = color.red, text_color = color.white, text_size = textSize)
table.cell(candleTrendTable, 6, 1, text = '-', bgcolor = color.red, text_color = color.white, text_size = textSize)

if (twoGCcounter >= 1 or twoRCcounter >= 1)
    table.cell(candleTrendTable, 0, 2, text = '2-Candle', bgcolor = color.blue, text_color = color.white, text_size = textSize)
    table.cell(candleTrendTable, 1, 2, text = str.tostring(twoGCcounter), bgcolor = color.green, text_color = color.white, text_size = textSize)
    table.cell(candleTrendTable, 2, 2, text = str.tostring(math.round(twoGCcounter / oneGCcounter * 100, 2)), bgcolor = color.green, text_color = color.white, text_size = textSize)
    table.cell(candleTrendTable, 3, 2, text = '-', bgcolor = color.green, text_color = color.white, text_size = textSize)
    table.cell(candleTrendTable, 4, 2, text = str.tostring(twoRCcounter), bgcolor = color.red, text_color = color.white, text_size = textSize)
    table.cell(candleTrendTable, 5, 2, text = str.tostring(math.round(twoRCcounter / oneRCcounter * 100, 2)), bgcolor = color.red, text_color = color.white, text_size = textSize)
    table.cell(candleTrendTable, 6, 2, text = '-', bgcolor = color.red, text_color = color.white, text_size = textSize)

if (threeGCcounter >= 1 or threeRCcounter >= 1)
    table.cell(candleTrendTable, 0, 3, text = '3-Candle', bgcolor = color.blue, text_color = color.white, text_size = textSize)
    table.cell(candleTrendTable, 1, 3, text = str.tostring(threeGCcounter), bgcolor = color.green, text_color = color.white, text_size = textSize)
    table.cell(candleTrendTable, 2, 3, text = str.tostring(math.round(threeGCcounter / oneGCcounter * 100, 2)), bgcolor = color.green, text_color = color.white, text_size = textSize)
    table.cell(candleTrendTable, 3, 3, text = str.tostring(math.round(threeGCcounter / twoGCcounter * 100, 2)), bgcolor = color.green, text_color = color.white, text_size = textSize)
    table.cell(candleTrendTable, 4, 3, text = str.tostring(threeRCcounter), bgcolor = color.red, text_color = color.white, text_size = textSize)
    table.cell(candleTrendTable, 5, 3, text = str.tostring(math.round(threeRCcounter / oneRCcounter * 100, 2)), bgcolor = color.red, text_color = color.white, text_size = textSize)
    table.cell(candleTrendTable, 6, 3, text = str.tostring(math.round(threeRCcounter / twoRCcounter * 100, 2)), bgcolor = color.red, text_color = color.white, text_size = textSize)

if (fourGCcounter >= 1 or fourRCcounter >= 1)
    table.cell(candleTrendTable, 0, 4, text = '4-Candle', bgcolor = color.blue, text_color = color.white, text_size = textSize)
    table.cell(candleTrendTable, 1, 4, text = str.tostring(fourGCcounter), bgcolor = color.green, text_color = color.white, text_size = textSize)
    table.cell(candleTrendTable, 2, 4, text = str.tostring(math.round(fourGCcounter / oneGCcounter * 100, 2)), bgcolor = color.green, text_color = color.white, text_size = textSize)
    table.cell(candleTrendTable, 3, 4, text = str.tostring(math.round(fourGCcounter / threeGCcounter * 100, 2)), bgcolor = color.green, text_color = color.white, text_size = textSize)
    table.cell(candleTrendTable, 4, 4, text = str.tostring(fourRCcounter), bgcolor = color.red, text_color = color.white, text_size = textSize)
    table.cell(candleTrendTable, 5, 4, text = str.tostring(math.round(fourRCcounter / oneRCcounter * 100, 2)), bgcolor = color.red, text_color = color.white, text_size = textSize)
    table.cell(candleTrendTable, 6, 4, text = str.tostring(math.round(fourRCcounter / threeRCcounter * 100, 2)), bgcolor = color.red, text_color = color.white, text_size = textSize)

if (fiveGCcounter >= 1 or fiveRCcounter >= 1)
    table.cell(candleTrendTable, 0, 5, text = '5-Candle', bgcolor = color.blue, text_color = color.white, text_size = textSize)
    table.cell(candleTrendTable, 1, 5, text = str.tostring(fiveGCcounter), bgcolor = color.green, text_color = color.white, text_size = textSize)
    table.cell(candleTrendTable, 2, 5, text = str.tostring(math.round(fiveGCcounter / oneGCcounter * 100, 2)), bgcolor = color.green, text_color = color.white, text_size = textSize)
    table.cell(candleTrendTable, 3, 5, text = str.tostring(math.round(fiveGCcounter / fourGCcounter * 100, 2)), bgcolor = color.green, text_color = color.white, text_size = textSize)
    table.cell(candleTrendTable, 4, 5, text = str.tostring(fiveRCcounter), bgcolor = color.red, text_color = color.white, text_size = textSize)
    table.cell(candleTrendTable, 5, 5, text = str.tostring(math.round(fiveRCcounter / oneRCcounter * 100, 2)), bgcolor = color.red, text_color = color.white, text_size = textSize)
    table.cell(candleTrendTable, 6, 5, text = str.tostring(math.round(fiveRCcounter / fourRCcounter * 100, 2)), bgcolor = color.red, text_color = color.white, text_size = textSize)

if (sixGCcounter >= 1 or sixRCcounter >= 1)
    table.cell(candleTrendTable, 0, 6, text = '6-Candle', bgcolor = color.blue, text_color = color.white, text_size = textSize)
    table.cell(candleTrendTable, 1, 6, text = str.tostring(sixGCcounter), bgcolor = color.green, text_color = color.white, text_size = textSize)
    table.cell(candleTrendTable, 2, 6, text = str.tostring(math.round(sixGCcounter / oneGCcounter * 100, 2)), bgcolor = color.green, text_color = color.white, text_size = textSize)
    table.cell(candleTrendTable, 3, 6, text = str.tostring(math.round(sixGCcounter / fiveGCcounter * 100, 2)), bgcolor = color.green, text_color = color.white, text_size = textSize)
    table.cell(candleTrendTable, 4, 6, text = str.tostring(sixRCcounter), bgcolor = color.red, text_color = color.white, text_size = textSize)
    table.cell(candleTrendTable, 5, 6, text = str.tostring(math.round(sixRCcounter / oneRCcounter * 100, 2)), bgcolor = color.red, text_color = color.white, text_size = textSize)
    table.cell(candleTrendTable, 6, 6, text = str.tostring(math.round(sixRCcounter / fiveRCcounter * 100, 2)), bgcolor = color.red, text_color = color.white, text_size = textSize)

if (sevenGCcounter >= 1 or sevenRCcounter >= 1)
    table.cell(candleTrendTable, 0, 7, text = '7-Candle', bgcolor = color.blue, text_color = color.white, text_size = textSize)
    table.cell(candleTrendTable, 1, 7, text = str.tostring(sevenGCcounter), bgcolor = color.green, text_color = color.white, text_size = textSize)
    table.cell(candleTrendTable, 2, 7, text = str.tostring(math.round(sevenGCcounter / oneGCcounter * 100, 2)), bgcolor = color.green, text_color = color.white, text_size = textSize)
    table.cell(candleTrendTable, 3, 7, text = str.tostring(math.round(sevenGCcounter / sixGCcounter * 100, 2)), bgcolor = color.green, text_color = color.white, text_size = textSize)
    table.cell(candleTrendTable, 4, 7, text = str.tostring(sevenRCcounter), bgcolor = color.red, text_color = color.white, text_size = textSize)
    table.cell(candleTrendTable, 5, 7, text = str.tostring(math.round(sevenRCcounter / oneRCcounter * 100, 2)), bgcolor = color.red, text_color = color.white, text_size = textSize)
    table.cell(candleTrendTable, 6, 7, text = str.tostring(math.round(sevenRCcounter / sixRCcounter * 100, 2)), bgcolor = color.red, text_color = color.white, text_size = textSize)

if (eightGCcounter >= 1 or eightRCcounter >= 1)
    table.cell(candleTrendTable, 0, 8, text = '8-Candle', bgcolor = color.blue, text_color = color.white, text_size = textSize)
    table.cell(candleTrendTable, 1, 8, text = str.tostring(eightGCcounter), bgcolor = color.green, text_color = color.white, text_size = textSize)
    table.cell(candleTrendTable, 2, 8, text = str.tostring(math.round(eightGCcounter / oneGCcounter * 100, 2)), bgcolor = color.green, text_color = color.white, text_size = textSize)
    table.cell(candleTrendTable, 3, 8, text = str.tostring(math.round(eightGCcounter / sevenGCcounter * 100, 2)), bgcolor = color.green, text_color = color.white, text_size = textSize)
    table.cell(candleTrendTable, 4, 8, text = str.tostring(eightRCcounter), bgcolor = color.red, text_color = color.white, text_size = textSize)
    table.cell(candleTrendTable, 5, 8, text = str.tostring(math.round(eightRCcounter / oneRCcounter * 100, 2)), bgcolor = color.red, text_color = color.white, text_size = textSize)
    table.cell(candleTrendTable, 6, 8, text = str.tostring(math.round(eightRCcounter / sevenRCcounter * 100, 2)), bgcolor = color.red, text_color = color.white, text_size = textSize)

if (nineGCcounter >= 1 or nineRCcounter >= 1)
    table.cell(candleTrendTable, 0, 9, text = '9-Candle', bgcolor = color.blue, text_color = color.white, text_size = textSize)
    table.cell(candleTrendTable, 1, 9, text = str.tostring(nineGCcounter), bgcolor = color.green, text_color = color.white, text_size = textSize)
    table.cell(candleTrendTable, 2, 9, text = str.tostring(math.round(nineGCcounter / oneGCcounter * 100, 2)), bgcolor = color.green, text_color = color.white, text_size = textSize)
    table.cell(candleTrendTable, 3, 9, text = str.tostring(math.round(nineGCcounter / eightGCcounter * 100, 2)), bgcolor = color.green, text_color = color.white, text_size = textSize)
    table.cell(candleTrendTable, 4, 9, text = str.tostring(nineRCcounter), bgcolor = color.red, text_color = color.white, text_size = textSize)
    table.cell(candleTrendTable, 5, 9, text = str.tostring(math.round(nineRCcounter / oneRCcounter * 100, 2)), bgcolor = color.red, text_color = color.white, text_size = textSize)
    table.cell(candleTrendTable, 6, 9, text = str.tostring(math.round(nineRCcounter / eightRCcounter * 100, 2)), bgcolor = color.red, text_color = color.white, text_size = textSize)

if (tenGCcounter >= 1 or tenRCcounter >= 1)
    table.cell(candleTrendTable, 0, 10, text = '10-Candle', bgcolor = color.blue, text_color = color.white, text_size = textSize)
    table.cell(candleTrendTable, 1, 10, text = str.tostring(tenGCcounter), bgcolor = color.green, text_color = color.white, text_size = textSize)
    table.cell(candleTrendTable, 2, 10, text = str.tostring(math.round(tenGCcounter / oneGCcounter * 100, 2)), bgcolor = color.green, text_color = color.white, text_size = textSize)
    table.cell(candleTrendTable, 3, 10, text = str.tostring(math.round(tenGCcounter / nineGCcounter * 100, 2)), bgcolor = color.green, text_color = color.white, text_size = textSize)
    table.cell(candleTrendTable, 4, 10, text = str.tostring(tenRCcounter), bgcolor = color.red, text_color = color.white, text_size = textSize)
    table.cell(candleTrendTable, 5, 10, text = str.tostring(math.round(tenRCcounter / oneRCcounter * 100, 2)), bgcolor = color.red, text_color = color.white, text_size = textSize)
    table.cell(candleTrendTable, 6, 10, text = str.tostring(math.round(tenRCcounter / nineRCcounter * 100, 2)), bgcolor = color.red, text_color = color.white, text_size = textSize)

if (elevenGCcounter >= 1 or elevenRCcounter >= 1)
    table.cell(candleTrendTable, 0, 11, text = '11-Candle', bgcolor = color.blue, text_color = color.white, text_size = textSize)
    table.cell(candleTrendTable, 1, 11, text = str.tostring(elevenGCcounter), bgcolor = color.green, text_color = color.white, text_size = textSize)
    table.cell(candleTrendTable, 2, 11, text = str.tostring(math.round(elevenGCcounter / oneGCcounter * 100, 2)), bgcolor = color.green, text_color = color.white, text_size = textSize)
    table.cell(candleTrendTable, 3, 11, text = str.tostring(math.round(elevenGCcounter / tenGCcounter * 100, 2)), bgcolor = color.green, text_color = color.white, text_size = textSize)
    table.cell(candleTrendTable, 4, 11, text = str.tostring(elevenRCcounter), bgcolor = color.red, text_color = color.white, text_size = textSize)
    table.cell(candleTrendTable, 5, 11, text = str.tostring(math.round(elevenRCcounter / oneRCcounter * 100, 2)), bgcolor = color.red, text_color = color.white, text_size = textSize)
    table.cell(candleTrendTable, 6, 11, text = str.tostring(math.round(elevenRCcounter / tenRCcounter * 100, 2)), bgcolor = color.red, text_color = color.white, text_size = textSize)

if (twelveGCcounter >= 1 or twelveRCcounter >= 1)
    table.cell(candleTrendTable, 0, 12, text = '12-Candle', bgcolor = color.blue, text_color = color.white, text_size = textSize)
    table.cell(candleTrendTable, 1, 12, text = str.tostring(twelveGCcounter), bgcolor = color.green, text_color = color.white, text_size = textSize)
    table.cell(candleTrendTable, 2, 12, text = str.tostring(math.round(twelveGCcounter / oneGCcounter * 100, 2)), bgcolor = color.green, text_color = color.white, text_size = textSize)
    table.cell(candleTrendTable, 3, 12, text = str.tostring(math.round(twelveGCcounter / elevenGCcounter * 100, 2)), bgcolor = color.green, text_color = color.white, text_size = textSize)
    table.cell(candleTrendTable, 4, 12, text = str.tostring(twelveRCcounter), bgcolor = color.red, text_color = color.white, text_size = textSize)
    table.cell(candleTrendTable, 5, 12, text = str.tostring(math.round(twelveRCcounter / oneRCcounter * 100, 2)), bgcolor = color.red, text_color = color.white, text_size = textSize)
    table.cell(candleTrendTable, 6, 12, text = str.tostring(math.round(twelveRCcounter / elevenRCcounter * 100, 2)), bgcolor = color.red, text_color = color.white, text_size = textSize)

if (thirteenGCcounter >= 1 or thirteenRCcounter >= 1)
    table.cell(candleTrendTable, 0, 13, text = '13-Candle', bgcolor = color.blue, text_color = color.white, text_size = textSize)
    table.cell(candleTrendTable, 1, 13, text = str.tostring(thirteenGCcounter), bgcolor = color.green, text_color = color.white, text_size = textSize)
    table.cell(candleTrendTable, 2, 13, text = str.tostring(math.round(thirteenGCcounter / oneGCcounter * 100, 2)), bgcolor = color.green, text_color = color.white, text_size = textSize)
    table.cell(candleTrendTable, 3, 13, text = str.tostring(math.round(thirteenGCcounter / twelveGCcounter * 100, 2)), bgcolor = color.green, text_color = color.white, text_size = textSize)
    table.cell(candleTrendTable, 4, 13, text = str.tostring(thirteenRCcounter), bgcolor = color.red, text_color = color.white, text_size = textSize)
    table.cell(candleTrendTable, 5, 13, text = str.tostring(math.round(thirteenRCcounter / oneRCcounter * 100, 2)), bgcolor = color.red, text_color = color.white, text_size = textSize)
    table.cell(candleTrendTable, 6, 13, text = str.tostring(math.round(thirteenRCcounter / twelveRCcounter * 100, 2)), bgcolor = color.red, text_color = color.white, text_size = textSize)

if (fourteenGCcounter >= 1 or fourteenRCcounter >= 1)
    table.cell(candleTrendTable, 0, 14, text = '14-Candle', bgcolor = color.blue, text_color = color.white, text_size = textSize)
    table.cell(candleTrendTable, 1, 14, text = str.tostring(fourteenGCcounter), bgcolor = color.green, text_color = color.white, text_size = textSize)
    table.cell(candleTrendTable, 2, 14, text = str.tostring(math.round(fourteenGCcounter / oneGCcounter * 100, 2)), bgcolor = color.green, text_color = color.white, text_size = textSize)
    table.cell(candleTrendTable, 3, 14, text = str.tostring(math.round(fourteenGCcounter / thirteenGCcounter * 100, 2)), bgcolor = color.green, text_color = color.white, text_size = textSize)
    table.cell(candleTrendTable, 4, 14, text = str.tostring(fourteenRCcounter), bgcolor = color.red, text_color = color.white, text_size = textSize)
    table.cell(candleTrendTable, 5, 14, text = str.tostring(math.round(fourteenRCcounter / oneRCcounter * 100, 2)), bgcolor = color.red, text_color = color.white, text_size = textSize)
    table.cell(candleTrendTable, 6, 14, text = str.tostring(math.round(fourteenRCcounter / thirteenRCcounter * 100, 2)), bgcolor = color.red, text_color = color.white, text_size = textSize)

if (fifteenGCcounter >= 1 or fifteenRCcounter >= 1)
    table.cell(candleTrendTable, 0, 15, text = '15-Candle', bgcolor = color.blue, text_color = color.white, text_size = textSize)
    table.cell(candleTrendTable, 1, 15, text = str.tostring(fifteenGCcounter), bgcolor = color.green, text_color = color.white, text_size = textSize)
    table.cell(candleTrendTable, 2, 15, text = str.tostring(math.round(fifteenGCcounter / oneGCcounter * 100, 2)), bgcolor = color.green, text_color = color.white, text_size = textSize)
    table.cell(candleTrendTable, 3, 15, text = str.tostring(math.round(fifteenGCcounter / fourteenGCcounter * 100, 2)), bgcolor = color.green, text_color = color.white, text_size = textSize)
    table.cell(candleTrendTable, 4, 15, text = str.tostring(fifteenRCcounter), bgcolor = color.red, text_color = color.white, text_size = textSize)
    table.cell(candleTrendTable, 5, 15, text = str.tostring(math.round(fifteenRCcounter / oneRCcounter * 100, 2)), bgcolor = color.red, text_color = color.white, text_size = textSize)
    table.cell(candleTrendTable, 6, 15, text = str.tostring(math.round(fifteenRCcounter / fourteenRCcounter * 100, 2)), bgcolor = color.red, text_color = color.white, text_size = textSize)

if (sixteenGCcounter >= 1 or sixteenRCcounter >= 1)
    table.cell(candleTrendTable, 0, 16, text = '16-Candle', bgcolor = color.blue, text_color = color.white, text_size = textSize)
    table.cell(candleTrendTable, 1, 16, text = str.tostring(sixteenGCcounter), bgcolor = color.green, text_color = color.white, text_size = textSize)
    table.cell(candleTrendTable, 2, 16, text = str.tostring(math.round(sixteenGCcounter / oneGCcounter * 100, 2)), bgcolor = color.green, text_color = color.white, text_size = textSize)
    table.cell(candleTrendTable, 3, 16, text = str.tostring(math.round(sixteenGCcounter / fifteenGCcounter * 100, 2)), bgcolor = color.green, text_color = color.white, text_size = textSize)
    table.cell(candleTrendTable, 4, 16, text = str.tostring(sixteenRCcounter), bgcolor = color.red, text_color = color.white, text_size = textSize)
    table.cell(candleTrendTable, 5, 16, text = str.tostring(math.round(sixteenRCcounter / oneRCcounter * 100, 2)), bgcolor = color.red, text_color = color.white, text_size = textSize)
    table.cell(candleTrendTable, 6, 16, text = str.tostring(math.round(sixteenRCcounter / fifteenRCcounter * 100, 2)), bgcolor = color.red, text_color = color.white, text_size = textSize)

if (seventeenGCcounter >= 1 or seventeenRCcounter >= 1)
    table.cell(candleTrendTable, 0, 17, text = '17-Candle', bgcolor = color.blue, text_color = color.white, text_size = textSize)
    table.cell(candleTrendTable, 1, 17, text = str.tostring(seventeenGCcounter), bgcolor = color.green, text_color = color.white, text_size = textSize)
    table.cell(candleTrendTable, 2, 17, text = str.tostring(math.round(seventeenGCcounter / oneGCcounter * 100, 2)), bgcolor = color.green, text_color = color.white, text_size = textSize)
    table.cell(candleTrendTable, 3, 17, text = str.tostring(math.round(seventeenGCcounter / sixteenGCcounter * 100, 2)), bgcolor = color.green, text_color = color.white, text_size = textSize)
    table.cell(candleTrendTable, 4, 17, text = str.tostring(seventeenRCcounter), bgcolor = color.red, text_color = color.white, text_size = textSize)
    table.cell(candleTrendTable, 5, 17, text = str.tostring(math.round(seventeenRCcounter / oneRCcounter * 100, 2)), bgcolor = color.red, text_color = color.white, text_size = textSize)
    table.cell(candleTrendTable, 6, 17, text = str.tostring(math.round(seventeenRCcounter / sixteenRCcounter * 100, 2)), bgcolor = color.red, text_color = color.white, text_size = textSize)

if (eighteenGCcounter >= 1 or eighteenRCcounter >= 1)
    table.cell(candleTrendTable, 0, 18, text = '18-Candle', bgcolor = color.blue, text_color = color.white, text_size = textSize)
    table.cell(candleTrendTable, 1, 18, text = str.tostring(eighteenGCcounter), bgcolor = color.green, text_color = color.white, text_size = textSize)
    table.cell(candleTrendTable, 2, 18, text = str.tostring(math.round(eighteenGCcounter / oneGCcounter * 100, 2)), bgcolor = color.green, text_color = color.white, text_size = textSize)
    table.cell(candleTrendTable, 3, 18, text = str.tostring(math.round(eighteenGCcounter / seventeenGCcounter * 100, 2)), bgcolor = color.green, text_color = color.white, text_size = textSize)
    table.cell(candleTrendTable, 4, 18, text = str.tostring(eighteenRCcounter), bgcolor = color.red, text_color = color.white, text_size = textSize)
    table.cell(candleTrendTable, 5, 18, text = str.tostring(math.round(eighteenRCcounter / oneRCcounter * 100, 2)), bgcolor = color.red, text_color = color.white, text_size = textSize)
    table.cell(candleTrendTable, 6, 18, text = str.tostring(math.round(eighteenRCcounter / seventeenRCcounter * 100, 2)), bgcolor = color.red, text_color = color.white, text_size = textSize)

if (nineteenGCcounter >= 1 or nineteenRCcounter >= 1)
    table.cell(candleTrendTable, 0, 19, text = '19-Candle', bgcolor = color.blue, text_color = color.white, text_size = textSize)
    table.cell(candleTrendTable, 1, 19, text = str.tostring(nineteenGCcounter), bgcolor = color.green, text_color = color.white, text_size = textSize)
    table.cell(candleTrendTable, 2, 19, text = str.tostring(math.round(nineteenGCcounter / oneGCcounter * 100, 2)), bgcolor = color.green, text_color = color.white, text_size = textSize)
    table.cell(candleTrendTable, 3, 19, text = str.tostring(math.round(nineteenGCcounter / eighteenGCcounter * 100, 2)), bgcolor = color.green, text_color = color.white, text_size = textSize)
    table.cell(candleTrendTable, 4, 19, text = str.tostring(nineteenRCcounter), bgcolor = color.red, text_color = color.white, text_size = textSize)
    table.cell(candleTrendTable, 5, 19, text = str.tostring(math.round(nineteenRCcounter / oneRCcounter * 100, 2)), bgcolor = color.red, text_color = color.white, text_size = textSize)
    table.cell(candleTrendTable, 6, 19, text = str.tostring(math.round(nineteenRCcounter / eighteenRCcounter * 100, 2)), bgcolor = color.red, text_color = color.white, text_size = textSize)

if (twentyGCcounter >= 1 or twentyRCcounter >= 1)
    table.cell(candleTrendTable, 0, 20, text = '20-Candle', bgcolor = color.blue, text_color = color.white, text_size = textSize)
    table.cell(candleTrendTable, 1, 20, text = str.tostring(twentyGCcounter), bgcolor = color.green, text_color = color.white, text_size = textSize)
    table.cell(candleTrendTable, 2, 20, text = str.tostring(math.round(twentyGCcounter / oneGCcounter * 100, 2)), bgcolor = color.green, text_color = color.white, text_size = textSize)
    table.cell(candleTrendTable, 3, 20, text = str.tostring(math.round(twentyGCcounter / nineteenGCcounter * 100, 2)), bgcolor = color.green, text_color = color.white, text_size = textSize)
    table.cell(candleTrendTable, 4, 20, text = str.tostring(twentyRCcounter), bgcolor = color.red, text_color = color.white, text_size = textSize)
    table.cell(candleTrendTable, 5, 20, text = str.tostring(math.round(twentyRCcounter / oneRCcounter * 100, 2)), bgcolor = color.red, text_color = color.white, text_size = textSize)
    table.cell(candleTrendTable, 6, 20, text = str.tostring(math.round(twentyRCcounter / nineteenRCcounter * 100, 2)), bgcolor = color.red, text_color = color.white, text_size = textSize)

if (twentyoneGCcounter >= 1 or twentyoneRCcounter >= 1)
    table.cell(candleTrendTable, 0, 21, text = '21-Candle', bgcolor = color.blue, text_color = color.white, text_size = textSize)
    table.cell(candleTrendTable, 1, 21, text = str.tostring(twentyoneGCcounter), bgcolor = color.green, text_color = color.white, text_size = textSize)
    table.cell(candleTrendTable, 2, 21, text = str.tostring(math.round(twentyoneGCcounter / oneGCcounter * 100, 2)), bgcolor = color.green, text_color = color.white, text_size = textSize)
    table.cell(candleTrendTable, 3, 21, text = str.tostring(math.round(twentyoneGCcounter / twentyGCcounter * 100, 2)), bgcolor = color.green, text_color = color.white, text_size = textSize)
    table.cell(candleTrendTable, 4, 21, text = str.tostring(twentyoneRCcounter), bgcolor = color.red, text_color = color.white, text_size = textSize)
    table.cell(candleTrendTable, 5, 21, text = str.tostring(math.round(twentyoneRCcounter / oneRCcounter * 100, 2)), bgcolor = color.red, text_color = color.white, text_size = textSize)
    table.cell(candleTrendTable, 6, 21, text = str.tostring(math.round(twentyoneRCcounter / twentyRCcounter * 100, 2)), bgcolor = color.red, text_color = color.white, text_size = textSize)

if (twentytwoGCcounter >= 1 or twentytwoRCcounter >= 1)
    table.cell(candleTrendTable, 0, 22, text = '22-Candle', bgcolor = color.blue, text_color = color.white, text_size = textSize)
    table.cell(candleTrendTable, 1, 22, text = str.tostring(twentytwoGCcounter), bgcolor = color.green, text_color = color.white, text_size = textSize)
    table.cell(candleTrendTable, 2, 22, text = str.tostring(math.round(twentytwoGCcounter / oneGCcounter * 100, 2)), bgcolor = color.green, text_color = color.white, text_size = textSize)
    table.cell(candleTrendTable, 3, 22, text = str.tostring(math.round(twentytwoGCcounter / twentyoneGCcounter * 100, 2)), bgcolor = color.green, text_color = color.white, text_size = textSize)
    table.cell(candleTrendTable, 4, 22, text = str.tostring(twentytwoRCcounter), bgcolor = color.red, text_color = color.white, text_size = textSize)
    table.cell(candleTrendTable, 5, 22, text = str.tostring(math.round(twentytwoRCcounter / oneRCcounter * 100, 2)), bgcolor = color.red, text_color = color.white, text_size = textSize)
    table.cell(candleTrendTable, 6, 22, text = str.tostring(math.round(twentytwoRCcounter / twentyoneRCcounter * 100, 2)), bgcolor = color.red, text_color = color.white, text_size = textSize)

if (twentythreeGCcounter >= 1 or twentythreeRCcounter >= 1)
    table.cell(candleTrendTable, 0, 23, text = '23-Candle', bgcolor = color.blue, text_color = color.white, text_size = textSize)
    table.cell(candleTrendTable, 1, 23, text = str.tostring(twentythreeGCcounter), bgcolor = color.green, text_color = color.white, text_size = textSize)
    table.cell(candleTrendTable, 2, 23, text = str.tostring(math.round(twentythreeGCcounter / oneGCcounter * 100, 2)), bgcolor = color.green, text_color = color.white, text_size = textSize)
    table.cell(candleTrendTable, 3, 23, text = str.tostring(math.round(twentythreeGCcounter / twentytwoGCcounter * 100, 2)), bgcolor = color.green, text_color = color.white, text_size = textSize)
    table.cell(candleTrendTable, 4, 23, text = str.tostring(twentythreeRCcounter), bgcolor = color.red, text_color = color.white, text_size = textSize)
    table.cell(candleTrendTable, 5, 23, text = str.tostring(math.round(twentythreeRCcounter / oneRCcounter * 100, 2)), bgcolor = color.red, text_color = color.white, text_size = textSize)
    table.cell(candleTrendTable, 6, 23, text = str.tostring(math.round(twentythreeRCcounter / twentytwoRCcounter * 100, 2)), bgcolor = color.red, text_color = color.white, text_size = textSize)

if (twentyfourGCcounter >= 1 or twentyfourRCcounter >= 1)
    table.cell(candleTrendTable, 0, 24, text = '24-Candle', bgcolor = color.blue, text_color = color.white, text_size = textSize)
    table.cell(candleTrendTable, 1, 24, text = str.tostring(twentyfourGCcounter), bgcolor = color.green, text_color = color.white, text_size = textSize)
    table.cell(candleTrendTable, 2, 24, text = str.tostring(math.round(twentyfourGCcounter / oneGCcounter * 100, 2)), bgcolor = color.green, text_color = color.white, text_size = textSize)
    table.cell(candleTrendTable, 3, 24, text = str.tostring(math.round(twentyfourGCcounter / twentythreeGCcounter * 100, 2)), bgcolor = color.green, text_color = color.white, text_size = textSize)
    table.cell(candleTrendTable, 4, 24, text = str.tostring(twentyfourRCcounter), bgcolor = color.red, text_color = color.white, text_size = textSize)
    table.cell(candleTrendTable, 5, 24, text = str.tostring(math.round(twentyfourRCcounter / oneRCcounter * 100, 2)), bgcolor = color.red, text_color = color.white, text_size = textSize)
    table.cell(candleTrendTable, 6, 24, text = str.tostring(math.round(twentyfourRCcounter / twentythreeRCcounter * 100, 2)), bgcolor = color.red, text_color = color.white, text_size = textSize)

if (twentyfiveGCcounter >= 1 or twentyfiveRCcounter >= 1)
    table.cell(candleTrendTable, 0, 25, text = '25-Candle', bgcolor = color.blue, text_color = color.white, text_size = textSize)
    table.cell(candleTrendTable, 1, 25, text = str.tostring(twentyfiveGCcounter), bgcolor = color.green, text_color = color.white, text_size = textSize)
    table.cell(candleTrendTable, 2, 25, text = str.tostring(math.round(twentyfiveGCcounter / oneGCcounter * 100, 2)), bgcolor = color.green, text_color = color.white, text_size = textSize)
    table.cell(candleTrendTable, 3, 25, text = str.tostring(math.round(twentyfiveGCcounter / twentyfourGCcounter * 100, 2)), bgcolor = color.green, text_color = color.white, text_size = textSize)
    table.cell(candleTrendTable, 4, 25, text = str.tostring(twentyfiveRCcounter), bgcolor = color.red, text_color = color.white, text_size = textSize)
    table.cell(candleTrendTable, 5, 25, text = str.tostring(math.round(twentyfiveRCcounter / oneRCcounter * 100, 2)), bgcolor = color.red, text_color = color.white, text_size = textSize)
    table.cell(candleTrendTable, 6, 25, text = str.tostring(math.round(twentyfiveRCcounter / twentyfourRCcounter * 100, 2)), bgcolor = color.red, text_color = color.white, text_size = textSize)

if (twentysixGCcounter >= 1 or twentysixRCcounter >= 1)
    table.cell(candleTrendTable, 0, 26, text = '26-Candle', bgcolor = color.blue, text_color = color.white, text_size = textSize)
    table.cell(candleTrendTable, 1, 26, text = str.tostring(twentysixGCcounter), bgcolor = color.green, text_color = color.white, text_size = textSize)
    table.cell(candleTrendTable, 2, 26, text = str.tostring(math.round(twentysixGCcounter / oneGCcounter * 100, 2)), bgcolor = color.green, text_color = color.white, text_size = textSize)
    table.cell(candleTrendTable, 3, 26, text = str.tostring(math.round(twentysixGCcounter / twentyfiveGCcounter * 100, 2)), bgcolor = color.green, text_color = color.white, text_size = textSize)
    table.cell(candleTrendTable, 4, 26, text = str.tostring(twentysixRCcounter), bgcolor = color.red, text_color = color.white, text_size = textSize)
    table.cell(candleTrendTable, 5, 26, text = str.tostring(math.round(twentysixRCcounter / oneRCcounter * 100, 2)), bgcolor = color.red, text_color = color.white, text_size = textSize)
    table.cell(candleTrendTable, 6, 26, text = str.tostring(math.round(twentysixRCcounter / twentyfiveRCcounter * 100, 2)), bgcolor = color.red, text_color = color.white, text_size = textSize)

if (twentysevenGCcounter >= 1 or twentysevenRCcounter >= 1)
    table.cell(candleTrendTable, 0, 27, text = '27-Candle', bgcolor = color.blue, text_color = color.white, text_size = textSize)
    table.cell(candleTrendTable, 1, 27, text = str.tostring(twentysevenGCcounter), bgcolor = color.green, text_color = color.white, text_size = textSize)
    table.cell(candleTrendTable, 2, 27, text = str.tostring(math.round(twentysevenGCcounter / oneGCcounter * 100, 2)), bgcolor = color.green, text_color = color.white, text_size = textSize)
    table.cell(candleTrendTable, 3, 27, text = str.tostring(math.round(twentysevenGCcounter / twentysixGCcounter * 100, 2)), bgcolor = color.green, text_color = color.white, text_size = textSize)
    table.cell(candleTrendTable, 4, 27, text = str.tostring(twentysevenRCcounter), bgcolor = color.red, text_color = color.white, text_size = textSize)
    table.cell(candleTrendTable, 5, 27, text = str.tostring(math.round(twentysevenRCcounter / oneRCcounter * 100, 2)), bgcolor = color.red, text_color = color.white, text_size = textSize)
    table.cell(candleTrendTable, 6, 27, text = str.tostring(math.round(twentysevenRCcounter / twentysixRCcounter * 100, 2)), bgcolor = color.red, text_color = color.white, text_size = textSize)

if (twentyeightGCcounter >= 1 or twentyeightRCcounter >= 1)
    table.cell(candleTrendTable, 0, 28, text = '28-Candle', bgcolor = color.blue, text_color = color.white, text_size = textSize)
    table.cell(candleTrendTable, 1, 28, text = str.tostring(twentyeightGCcounter), bgcolor = color.green, text_color = color.white, text_size = textSize)
    table.cell(candleTrendTable, 2, 28, text = str.tostring(math.round(twentyeightGCcounter / oneGCcounter * 100, 2)), bgcolor = color.green, text_color = color.white, text_size = textSize)
    table.cell(candleTrendTable, 3, 28, text = str.tostring(math.round(twentyeightGCcounter / twentysevenGCcounter * 100, 2)), bgcolor = color.green, text_color = color.white, text_size = textSize)
    table.cell(candleTrendTable, 4, 28, text = str.tostring(twentyeightRCcounter), bgcolor = color.red, text_color = color.white, text_size = textSize)
    table.cell(candleTrendTable, 5, 28, text = str.tostring(math.round(twentyeightRCcounter / oneRCcounter * 100, 2)), bgcolor = color.red, text_color = color.white, text_size = textSize)
    table.cell(candleTrendTable, 6, 28, text = str.tostring(math.round(twentyeightRCcounter / twentysevenRCcounter * 100, 2)), bgcolor = color.red, text_color = color.white, text_size = textSize)

if (twentynineGCcounter >= 1 or twentynineRCcounter >= 1)
    table.cell(candleTrendTable, 0, 29, text = '29-Candle', bgcolor = color.blue, text_color = color.white, text_size = textSize)
    table.cell(candleTrendTable, 1, 29, text = str.tostring(twentynineGCcounter), bgcolor = color.green, text_color = color.white, text_size = textSize)
    table.cell(candleTrendTable, 2, 29, text = str.tostring(math.round(twentynineGCcounter / oneGCcounter * 100, 2)), bgcolor = color.green, text_color = color.white, text_size = textSize)
    table.cell(candleTrendTable, 3, 29, text = str.tostring(math.round(twentynineGCcounter / twentyeightGCcounter * 100, 2)), bgcolor = color.green, text_color = color.white, text_size = textSize)
    table.cell(candleTrendTable, 4, 29, text = str.tostring(twentynineRCcounter), bgcolor = color.red, text_color = color.white, text_size = textSize)
    table.cell(candleTrendTable, 5, 29, text = str.tostring(math.round(twentynineRCcounter / oneRCcounter * 100, 2)), bgcolor = color.red, text_color = color.white, text_size = textSize)
    table.cell(candleTrendTable, 6, 29, text = str.tostring(math.round(twentynineRCcounter / twentyeightRCcounter * 100, 2)), bgcolor = color.red, text_color = color.white, text_size = textSize)

if (thirtyGCcounter >= 1 or thirtyRCcounter >= 1)
    table.cell(candleTrendTable, 0, 30, text = '30-Candle', bgcolor = color.blue, text_color = color.white, text_size = textSize)
    table.cell(candleTrendTable, 1, 30, text = str.tostring(thirtyGCcounter), bgcolor = color.green, text_color = color.white, text_size = textSize)
    table.cell(candleTrendTable, 2, 30, text = str.tostring(math.round(thirtyGCcounter / oneGCcounter * 100, 2)), bgcolor = color.green, text_color = color.white, text_size = textSize)
    table.cell(candleTrendTable, 3, 30, text = str.tostring(math.round(thirtyGCcounter / twentynineGCcounter * 100, 2)), bgcolor = color.green, text_color = color.white, text_size = textSize)
    table.cell(candleTrendTable, 4, 30, text = str.tostring(thirtyRCcounter), bgcolor = color.red, text_color = color.white, text_size = textSize)
    table.cell(candleTrendTable, 5, 30, text = str.tostring(math.round(thirtyRCcounter / oneRCcounter * 100, 2)), bgcolor = color.red, text_color = color.white, text_size = textSize)
    table.cell(candleTrendTable, 6, 30, text = str.tostring(math.round(thirtyRCcounter / twentynineRCcounter * 100, 2)), bgcolor = color.red, text_color = color.white, text_size = textSize)

if showSamplePeriod 
    table.cell(candleTrendTable, 0, 31, text = startDateText + endDateText, bgcolor = color.black, text_color = color.white, text_size = textSize)

/////////// 
// PLOTS //
///////////

showPlots = input(defval = true, title = "Show Plots", group = 'Plots')

plotshape(oneGC and showPlots, style = shape.triangleup, color = color.green, text = '1', textcolor = color.green, location = location.belowbar) 
plotshape(twoGC and showPlots, style = shape.triangleup, color = color.green, text = '2', textcolor = color.green, location = location.belowbar) 
plotshape(threeGC and showPlots, style = shape.triangleup, color = color.green, text = '3', textcolor = color.green, location = location.belowbar)
plotshape(fourGC and showPlots, style = shape.triangleup, color = color.green, text = '4', textcolor = color.green, location = location.belowbar)
plotshape(fiveGC and showPlots, style = shape.triangleup, color = color.green, text = '5', textcolor = color.green, location = location.belowbar)
plotshape(sixGC and showPlots, style = shape.triangleup, color = color.green, text = '6', textcolor = color.green, location = location.belowbar)
plotshape(sevenGC and showPlots, style = shape.triangleup, color = color.green, text = '7', textcolor = color.green, location = location.belowbar)
plotshape(eightGC and showPlots, style = shape.triangleup, color = color.green, text = '8', textcolor = color.green, location = location.belowbar)
plotshape(nineGC and showPlots, style = shape.triangleup, color = color.green, text = '9', textcolor = color.green, location = location.belowbar)
plotshape(tenGC and showPlots, style = shape.triangleup, color = color.green, text = '10', textcolor = color.green, location = location.belowbar)
plotshape(elevenGC and showPlots, style = shape.triangleup, color = color.green, text = '11', textcolor = color.green, location = location.belowbar)
plotshape(twelveGC and showPlots, style = shape.triangleup, color = color.green, text = '12', textcolor = color.green, location = location.belowbar)
plotshape(thirteenGC and showPlots, style = shape.triangleup, color = color.green, text = '13', textcolor = color.green, location = location.belowbar)
plotshape(fourteenGC and showPlots, style = shape.triangleup, color = color.green, text = '14', textcolor = color.green, location = location.belowbar)
plotshape(fifteenGC and showPlots, style = shape.triangleup, color = color.green, text = '15', textcolor = color.green, location = location.belowbar)
plotshape(sixteenGC and showPlots, style = shape.triangleup, color = color.green, text = '16', textcolor = color.green, location = location.belowbar)
plotshape(seventeenGC and showPlots, style = shape.triangleup, color = color.green, text = '17', textcolor = color.green, location = location.belowbar)
plotshape(eighteenGC and showPlots, style = shape.triangleup, color = color.green, text = '18', textcolor = color.green, location = location.belowbar)
plotshape(nineteenGC and showPlots, style = shape.triangleup, color = color.green, text = '19', textcolor = color.green, location = location.belowbar)
plotshape(twentyGC and showPlots, style = shape.triangleup, color = color.green, text = '20', textcolor = color.green, location = location.belowbar)
plotshape(twentyoneGC and showPlots, style = shape.triangleup, color = color.green, text = '21', textcolor = color.green, location = location.belowbar)
plotshape(twentytwoGC and showPlots, style = shape.triangleup, color = color.green, text = '22', textcolor = color.green, location = location.belowbar)
plotshape(twentythreeGC and showPlots, style = shape.triangleup, color = color.green, text = '23', textcolor = color.green, location = location.belowbar)
plotshape(twentyfourGC and showPlots, style = shape.triangleup, color = color.green, text = '24', textcolor = color.green, location = location.belowbar)
plotshape(twentyfiveGC and showPlots, style = shape.triangleup, color = color.green, text = '25', textcolor = color.green, location = location.belowbar)
plotshape(twentysixGC and showPlots, style = shape.triangleup, color = color.green, text = '26', textcolor = color.green, location = location.belowbar)
plotshape(twentysevenGC and showPlots, style = shape.triangleup, color = color.green, text = '27', textcolor = color.green, location = location.belowbar)
plotshape(twentyeightGC and showPlots, style = shape.triangleup, color = color.green, text = '28', textcolor = color.green, location = location.belowbar)
plotshape(twentynineGC and showPlots, style = shape.triangleup, color = color.green, text = '29', textcolor = color.green, location = location.belowbar)
plotshape(thirtyGC and showPlots, style = shape.triangleup, color = color.green, text = '30', textcolor = color.green, location = location.belowbar)

plotshape(oneRC and showPlots, style = shape.triangledown, color = color.red, text = '1', textcolor = color.red) 
plotshape(twoRC and showPlots, style = shape.triangledown, color = color.red, text = '2', textcolor = color.red) 
plotshape(threeRC and showPlots, style = shape.triangledown, color = color.red, text = '3', textcolor = color.red)
plotshape(fourRC and showPlots, style = shape.triangledown, color = color.red, text = '4', textcolor = color.red)
plotshape(fiveRC and showPlots, style = shape.triangledown, color = color.red, text = '5', textcolor = color.red)
plotshape(sixRC and showPlots, style = shape.triangledown, color = color.red, text = '6', textcolor = color.red)
plotshape(sevenRC and showPlots, style = shape.triangledown, color = color.red, text = '7', textcolor = color.red)
plotshape(eightRC and showPlots, style = shape.triangledown, color = color.red, text = '8', textcolor = color.red)
plotshape(nineRC and showPlots, style = shape.triangledown, color = color.red, text = '9', textcolor = color.red)
plotshape(tenRC and showPlots, style = shape.triangledown, color = color.red, text = '10', textcolor = color.red)
plotshape(elevenRC and showPlots, style = shape.triangledown, color = color.red, text = '11', textcolor = color.red)
plotshape(twelveRC and showPlots, style = shape.triangledown, color = color.red, text = '12', textcolor = color.red)
plotshape(thirteenRC and showPlots, style = shape.triangledown, color = color.red, text = '13', textcolor = color.red)
plotshape(fourteenRC and showPlots, style = shape.triangledown, color = color.red, text = '14', textcolor = color.red)
plotshape(fifteenRC and showPlots, style = shape.triangledown, color = color.red, text = '15', textcolor = color.red)
plotshape(sixteenRC and showPlots, style = shape.triangledown, color = color.red, text = '16', textcolor = color.red)
plotshape(seventeenRC and showPlots, style = shape.triangledown, color = color.red, text = '17', textcolor = color.red)
plotshape(eighteenRC and showPlots, style = shape.triangledown, color = color.red, text = '18', textcolor = color.red)
plotshape(nineteenRC and showPlots, style = shape.triangledown, color = color.red, text = '19', textcolor = color.red)
plotshape(twentyRC and showPlots, style = shape.triangledown, color = color.red, text = '20', textcolor = color.red)
plotshape(twentyoneRC and showPlots, style = shape.triangledown, color = color.red, text = '21', textcolor = color.red)
plotshape(twentytwoRC and showPlots, style = shape.triangledown, color = color.red, text = '22', textcolor = color.red)
plotshape(twentythreeRC and showPlots, style = shape.triangledown, color = color.red, text = '23', textcolor = color.red)
plotshape(twentyfourRC and showPlots, style = shape.triangledown, color = color.red, text = '24', textcolor = color.red)
plotshape(twentyfiveRC and showPlots, style = shape.triangledown, color = color.red, text = '25', textcolor = color.red)
plotshape(twentysixRC and showPlots, style = shape.triangledown, color = color.red, text = '26', textcolor = color.red)
plotshape(twentysevenRC and showPlots, style = shape.triangledown, color = color.red, text = '27', textcolor = color.red)
plotshape(twentyeightRC and showPlots, style = shape.triangledown, color = color.red, text = '28', textcolor = color.red)
plotshape(twentynineRC and showPlots, style = shape.triangledown, color = color.red, text = '29', textcolor = color.red)
plotshape(thirtyRC and showPlots, style = shape.triangledown, color = color.red, text = '30', textcolor = color.red)

////////////
// ALERTS //
////////////

addOneGreenAlert = input(defval = true, title = 'One Green Alert', group = 'Green Candle Trend Alerts')
addTwoGreenAlert = input(defval = false, title = 'Two Green Alert', group = 'Green Candle Trend Alerts')
addThreeGreenAlert = input(defval = false, title = 'Three Green Alert', group = 'Green Candle Trend Alerts')
addFourGreenAlert = input(defval = false, title = 'Four Green Alert', group = 'Green Candle Trend Alerts')
addFiveGreenAlert = input(defval = false, title = 'Five Green Alert', group = 'Green Candle Trend Alerts')
addSixGreenAlert = input(defval = false, title = 'Six Green Alert', group = 'Green Candle Trend Alerts')
addSevenGreenAlert = input(defval = false, title = 'Seven Green Alert', group = 'Green Candle Trend Alerts')
addEightGreenAlert = input(defval = false, title = 'Eight Green Alert', group = 'Green Candle Trend Alerts')
addNineGreenAlert = input(defval = false, title = 'Nine Green Alert', group = 'Green Candle Trend Alerts')
addTenGreenAlert = input(defval = false, title = 'Ten Green Alert', group = 'Green Candle Trend Alerts')
addElevenGreenAlert = input(defval = false, title = 'Eleven Green Alert', group = 'Green Candle Trend Alerts')
addTwelveGreenAlert = input(defval = false, title = 'Twelve Green Alert', group = 'Green Candle Trend Alerts')
addThirteenGreenAlert = input(defval = false, title = 'Thirteen Green Alert', group = 'Green Candle Trend Alerts')
addFourteenGreenAlert = input(defval = false, title = 'Fourteen Green Alert', group = 'Green Candle Trend Alerts')
addFifteenGreenAlert = input(defval = false, title = 'Fifteen Green Alert', group = 'Green Candle Trend Alerts')
addSixteenGreenAlert = input(defval = false, title = 'Sixteen Green Alert', group = 'Green Candle Trend Alerts')
addSeventeenGreenAlert = input(defval = false, title = 'Seventeen Green Alert', group = 'Green Candle Trend Alerts')
addEighteenGreenAlert = input(defval = false, title = 'Eighteen Green Alert', group = 'Green Candle Trend Alerts')
addNineteenGreenAlert = input(defval = false, title = 'Nineteen Green Alert', group = 'Green Candle Trend Alerts')
addTwentyGreenAlert = input(defval = false, title = 'Twenty Green Alert', group = 'Green Candle Trend Alerts')
addTwentyOneGreenAlert = input(defval = false, title = 'Twenty-One Green Alert', group = 'Green Candle Trend Alerts')
addTwentyTwoGreenAlert = input(defval = false, title = 'Twenty-Two Green Alert', group = 'Green Candle Trend Alerts')
addTwentyThreeGreenAlert = input(defval = false, title = 'Twenty-Three Green Alert', group = 'Green Candle Trend Alerts')
addTwentyFourGreenAlert = input(defval = false, title = 'Twenty-Four Green Alert', group = 'Green Candle Trend Alerts')
addTwentyFiveGreenAlert = input(defval = false, title = 'Twenty-Five Green Alert', group = 'Green Candle Trend Alerts')
addTwentySixGreenAlert = input(defval = false, title = 'Twenty-Six Green Alert', group = 'Green Candle Trend Alerts')
addTwentySevenGreenAlert = input(defval = false, title = 'Twenty-Seven Green Alert', group = 'Green Candle Trend Alerts')
addTwentyEightGreenAlert = input(defval = false, title = 'Twenty-Eight Green Alert', group = 'Green Candle Trend Alerts')
addTwentyNineGreenAlert = input(defval = false, title = 'Twenty-Nine Green Alert', group = 'Green Candle Trend Alerts')
addThirtyGreenAlert = input(defval = false, title = 'Thirty Green Alert', group = 'Green Candle Trend Alerts')

addOneRedAlert = input(defval = true, title = 'One Red Alert', group = 'Red Candle Trend Alerts')
addTwoRedAlert = input(defval = false, title = 'Two Red Alert', group = 'Red Candle Trend Alerts')
addThreeRedAlert = input(defval = false, title = 'Three Red Alert', group = 'Red Candle Trend Alerts')
addFourRedAlert = input(defval = false, title = 'Four Red Alert', group = 'Red Candle Trend Alerts')
addFiveRedAlert = input(defval = false, title = 'Five Red Alert', group = 'Red Candle Trend Alerts')
addSixRedAlert = input(defval = false, title = 'Six Red Alert', group = 'Red Candle Trend Alerts')
addSevenRedAlert = input(defval = false, title = 'Seven Red Alert', group = 'Red Candle Trend Alerts')
addEightRedAlert = input(defval = false, title = 'Eight Red Alert', group = 'Red Candle Trend Alerts')
addNineRedAlert = input(defval = false, title = 'Nine Red Alert', group = 'Red Candle Trend Alerts')
addTenRedAlert = input(defval = false, title = 'Ten Red Alert', group = 'Red Candle Trend Alerts')
addElevenRedAlert = input(defval = false, title = 'Eleven Red Alert', group = 'Red Candle Trend Alerts')
addTwelveRedAlert = input(defval = false, title = 'Twelve Red Alert', group = 'Red Candle Trend Alerts')
addThirteenRedAlert = input(defval = false, title = 'Thirteen Red Alert', group = 'Red Candle Trend Alerts')
addFourteenRedAlert = input(defval = false, title = 'Fourteen Red Alert', group = 'Red Candle Trend Alerts')
addFifteenRedAlert = input(defval = false, title = 'Fifteen Red Alert', group = 'Red Candle Trend Alerts')
addSixteenRedAlert = input(defval = false, title = 'Sixteen Red Alert', group = 'Red Candle Trend Alerts')
addSeventeenRedAlert = input(defval = false, title = 'Seventeen Red Alert', group = 'Red Candle Trend Alerts')
addEighteenRedAlert = input(defval = false, title = 'Eighteen Red Alert', group = 'Red Candle Trend Alerts')
addNineteenRedAlert = input(defval = false, title = 'Nineteen Red Alert', group = 'Red Candle Trend Alerts')
addTwentyRedAlert = input(defval = false, title = 'Twenty Red Alert', group = 'Red Candle Trend Alerts')
addTwentyOneRedAlert = input(defval = false, title = 'Twenty-One Red Alert', group = 'Red Candle Trend Alerts')
addTwentyTwoRedAlert = input(defval = false, title = 'Twenty-Two Red Alert', group = 'Red Candle Trend Alerts')
addTwentyThreeRedAlert = input(defval = false, title = 'Twenty-Three Red Alert', group = 'Red Candle Trend Alerts')
addTwentyFourRedAlert = input(defval = false, title = 'Twenty-Four Red Alert', group = 'Red Candle Trend Alerts')
addTwentyFiveRedAlert = input(defval = false, title = 'Twenty-Five Red Alert', group = 'Red Candle Trend Alerts')
addTwentySixRedAlert = input(defval = false, title = 'Twenty-Six Red Alert', group = 'Red Candle Trend Alerts')
addTwentySevenRedAlert = input(defval = false, title = 'Twenty-Seven Red Alert', group = 'Red Candle Trend Alerts')
addTwentyEightRedAlert = input(defval = false, title = 'Twenty-Eight Red Alert', group = 'Red Candle Trend Alerts')
addTwentyNineRedAlert = input(defval = false, title = 'Twenty-Nine Red Alert', group = 'Red Candle Trend Alerts')
addThirtyRedAlert = input(defval = false, title = 'Thirty Red Alert', group = 'Red Candle Trend Alerts')

if oneGC and addOneGreenAlert
    alert('One Green')
if twoGC and addTwoGreenAlert
    alert('Two Green')
if threeGC and addThreeGreenAlert
    alert('Three Green')
if fourGC and addFourGreenAlert
    alert('Four Green')
if fiveGC and addFiveGreenAlert
    alert('Five Green')
if sixGC and addSixGreenAlert
    alert('Six Green')
if sevenGC and addSevenGreenAlert
    alert('Seven Green')
if eightGC and addEightGreenAlert
    alert('Eight Green')
if nineGC and addNineGreenAlert
    alert('Nine Green')
if tenGC and addTenGreenAlert
    alert('Ten Green')
if elevenGC and addElevenGreenAlert
    alert('Eleven Green')
if twelveGC and addTwelveGreenAlert
    alert('Twleve Green')
if thirteenGC and addThirteenGreenAlert
    alert('Thirteen Green')
if fourteenGC and addFourteenGreenAlert
    alert('Fourteen Green')
if fifteenGC and addFifteenGreenAlert
    alert('Fifteen Green')
if sixteenGC and addSixteenGreenAlert
    alert('Sixteen Green')
if seventeenGC and addSeventeenGreenAlert
    alert('Seventeen Green')
if eighteenGC and addEighteenGreenAlert
    alert('Eighteen Green')
if nineteenGC and addNineteenGreenAlert
    alert('Nineteen Green')
if twentyGC and addTwentyGreenAlert
    alert('Twenty Green')
if twentyoneGC and addTwentyOneGreenAlert
    alert('Twenty-One Green')
if twentytwoGC and addTwentyTwoGreenAlert
    alert('Twenty-Two Green')
if twentythreeGC and addTwentyThreeGreenAlert
    alert('Twenty-Three Green')
if twentyfourGC and addTwentyFourGreenAlert
    alert('Twenty-Four Green')
if twentyfiveGC and addTwentyFiveGreenAlert
    alert('Twenty-Five Green')
if twentysixGC and addTwentySixGreenAlert
    alert('Twenty-Six Green')
if twentysevenGC and addTwentySevenGreenAlert
    alert('Twenty-Seven Green')
if twentyeightGC and addTwentyEightGreenAlert
    alert('Twenty-Eight Green')
if twentynineGC and addTwentyNineGreenAlert
    alert('Twenty-Nine Green')
if thirtyGC and addThirtyGreenAlert
    alert('Thirty Green')

if oneRC and addOneRedAlert
    alert('One Red')
if twoRC and addTwoRedAlert
    alert('Two Red')
if threeRC and addThreeRedAlert
    alert('Three Red')
if fourRC and addFourRedAlert
    alert('Four Red')
if fiveRC and addFiveRedAlert
    alert('Five Red')
if sixRC and addSixRedAlert
    alert('Six Red')
if sevenRC and addSevenRedAlert
    alert('Seven Red')
if eightRC and addEightRedAlert
    alert('Eight Red')
if nineRC and addNineRedAlert
    alert('Nine Red')
if tenRC and addTenRedAlert
    alert('Ten Red')
if elevenRC and addElevenRedAlert
    alert('Eleven Red')
if twelveRC and addTwelveRedAlert
    alert('Twleve Red')
if thirteenRC and addThirteenRedAlert
    alert('Thirteen Red')
if fourteenRC and addFourteenRedAlert
    alert('Fourteen Red')
if fifteenRC and addFifteenRedAlert
    alert('Fifteen Red')
if sixteenRC and addSixteenRedAlert
    alert('Sixteen Red')
if seventeenRC and addSeventeenRedAlert
    alert('Seventeen Red')
if eighteenRC and addEighteenRedAlert
    alert('Eighteen Red')
if nineteenRC and addNineteenRedAlert
    alert('Nineteen Red')
if twentyRC and addTwentyRedAlert
    alert('Twenty Red')
if twentyoneRC and addTwentyOneRedAlert
    alert('Twenty-One Red')
if twentytwoRC and addTwentyTwoRedAlert
    alert('Twenty-Two Red')
if twentythreeRC and addTwentyThreeRedAlert
    alert('Twenty-Three Red')
if twentyfourRC and addTwentyFourRedAlert
    alert('Twenty-Four Red')
if twentyfiveRC and addTwentyFiveRedAlert
    alert('Twenty-Five Red')
if twentysixRC and addTwentySixRedAlert
    alert('Twenty-Six Red')
if twentysevenRC and addTwentySevenRedAlert
    alert('Twenty-Seven Red')
if twentyeightRC and addTwentyEightRedAlert
    alert('Twenty-Eight Red')
if twentynineRC and addTwentyNineRedAlert
    alert('Twenty-Nine Red')
if thirtyRC and addThirtyRedAlert
    alert('Thirty Red')