Tick up/down
// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © fikira

//@version=5
indicator("Tick up/down")

n = input.int(1, 'start', tooltip='start tick count x, end tick count x + 31')

pc = plot.style_circles
check(n) =>
    varip vTick  = 0
    varip vCheck = 0
    varip pClose = 0.

    if barstate.isnew
        vTick  := 0
        vCheck := 0
    else
        vTick += 1
        if vTick == n
            switch
                close  > pClose =>
                    vCheck := n
                close  < pClose =>
                    vCheck := n +1
                close == pClose =>
                    vCheck := n +2
                =>
                    vCheck := 0
    pClose := close
    vCheck

col(n) => check(n) == n ? color.lime : check(n) == n +1 ? color.red : check(n) == n +2 ? color.new(color.blue, 50) : color.new(color.blue, 100)
// series, title, color, linewidth, style
plot(check( n) != 0 ?  n : na, 'n'     , col(n), 2, pc), n += 1, plot(check( n) != 0 ?  n : na, 'n + 1' , col(n), 2, pc), n += 1, plot(check( n) != 0 ?  n : na, 'n + 2' , col(n), 2, pc), n += 1
plot(check( n) != 0 ?  n : na, 'n + 3' , col(n), 2, pc), n += 1, plot(check( n) != 0 ?  n : na, 'n + 4' , col(n), 2, pc), n += 1, plot(check( n) != 0 ?  n : na, 'n + 5' , col(n), 2, pc), n += 1
plot(check( n) != 0 ?  n : na, 'n + 6' , col(n), 2, pc), n += 1, plot(check( n) != 0 ?  n : na, 'n + 7' , col(n), 2, pc), n += 1, plot(check( n) != 0 ?  n : na, 'n + 8' , col(n), 2, pc), n += 1
plot(check( n) != 0 ?  n : na, 'n + 9' , col(n), 2, pc), n += 1, plot(check( n) != 0 ?  n : na, 'n + 10', col(n), 2, pc), n += 1, plot(check( n) != 0 ?  n : na, 'n + 11', col(n), 2, pc), n += 1
plot(check( n) != 0 ?  n : na, 'n + 12', col(n), 2, pc), n += 1, plot(check( n) != 0 ?  n : na, 'n + 13', col(n), 2, pc), n += 1, plot(check( n) != 0 ?  n : na, 'n + 14', col(n), 2, pc), n += 1
plot(check( n) != 0 ?  n : na, 'n + 15', col(n), 2, pc), n += 1, plot(check( n) != 0 ?  n : na, 'n + 16', col(n), 2, pc), n += 1, plot(check( n) != 0 ?  n : na, 'n + 17', col(n), 2, pc), n += 1
plot(check( n) != 0 ?  n : na, 'n + 18', col(n), 2, pc), n += 1, plot(check( n) != 0 ?  n : na, 'n + 19', col(n), 2, pc), n += 1, plot(check( n) != 0 ?  n : na, 'n + 20', col(n), 2, pc), n += 1
plot(check( n) != 0 ?  n : na, 'n + 21', col(n), 2, pc), n += 1, plot(check( n) != 0 ?  n : na, 'n + 22', col(n), 2, pc), n += 1, plot(check( n) != 0 ?  n : na, 'n + 23', col(n), 2, pc), n += 1
plot(check( n) != 0 ?  n : na, 'n + 24', col(n), 2, pc), n += 1, plot(check( n) != 0 ?  n : na, 'n + 25', col(n), 2, pc), n += 1, plot(check( n) != 0 ?  n : na, 'n + 26', col(n), 2, pc), n += 1
plot(check( n) != 0 ?  n : na, 'n + 27', col(n), 2, pc), n += 1, plot(check( n) != 0 ?  n : na, 'n + 28', col(n), 2, pc), n += 1, plot(check( n) != 0 ?  n : na, 'n + 29', col(n), 2, pc), n += 1
plot(check( n) != 0 ?  n : na, 'n + 30', col(n), 2, pc), n += 1, plot(check( n) != 0 ?  n : na, 'n + 31', col(n), 2, pc)

