// This Pine Script® code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © julzen2

//@version=5
indicator("TD Sequential", overlay=true)

var int numDown = 0
var int numUp = 0

pointSize = syminfo.mintick

// Recalculate TD counts
if close[1] < close[5]
    numDown += 1
else
    numDown := 0

if close[1] > close[5]
    numUp += 1
else
    numUp := 0

// Display Sell Setup (Down Count)
if (numDown > 0 and numDown < 10)
    label.new(bar_index[1], low[1] - 5 * pointSize, text=str.tostring(numDown), style=label.style_label_down, textcolor=color.red, size=size.small)
else if (numDown == 9)
    label.new(bar_index[1], low[1] - 5 * pointSize, text="9", style=label.style_label_down, textcolor=color.red, size=size.normal)
else if (close[1] < close[5] and numDown >= 10)
    label.new(bar_index[1], low[1] - 5 * pointSize, text=str.tostring(numDown), style=label.style_label_down, textcolor=color.orange, size=size.small)

// Display Buy Setup (Up Count)
if (numUp > 0 and numUp < 10)
    label.new(bar_index[1], high[1] + 10 * pointSize, text=str.tostring(numUp), style=label.style_label_up, textcolor=color.blue, size=size.small)
else if (numUp == 9)
    label.new(bar_index[1], high[1] + 10 * pointSize, text="9", style=label.style_label_up, textcolor=color.blue, size=size.normal)
else if (close[1] > close[5] and numUp >= 10)
    label.new(bar_index[1], high[1] + 10 * pointSize, text=str.tostring(numUp), style=label.style_label_up, textcolor=color.aqua, size=size.small)
