Indicator · Pine Script v5 · On the chart

TD Sequential V2

by mikeyhu70· code credited to congacindy

A Pine Script v5 indicator on the price chart that counts consecutive closes against the close four bars earlier, separately for falling and rising markets, and adds a bonus count that compares closes with two bars earlier once the setup passes nine.

View on GitHub

GitHub stars1on the repository
Pine versionv5runs as is
Lines of code118
Settings0inputs
LicenceNone statedfile: MPL-2.0
Last update6 months ago15 Apr 2026

Add It to Your TradingView Chart

  1. 1Copy the scriptPress Copy script above, or the copy button on the code below.
  2. 2Open the Pine EditorOpen a TradingView chart and choose Pine Editor at the bottom of the screen.
  3. 3Paste over the templateCreate a new indicator, select all of the template text and paste. Press Save and give it a name.
  4. 4Add it to the chartPress Add to chart, then adjust the settings with the gear icon next to its name.

Source Code

118 lines of Pine Script v5 from Levels and Targets/TD Sequential V2.ps, published under MPL-2.0 (file header). Keep the author's credit and licence lines when you reuse it.

TD Sequential V2.ps
// This Pine Script™ code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © congacindy

//@version=5
indicator('TD Sequential V2', shorttitle='913sig', overlay=true)

// Define the lookback periods
lookbackSetup = 4
lookbackBonusSetup = 2

// Initialize counters
var int setupCountF = na
var int setupCountR = na
var int bonusCountF = na
var int bonusCountR = na

// Define the setup and bonus phases
setupPhaseF = close < close[lookbackSetup]
setupPhaseR = close > close[lookbackSetup]
bonusPhaseF = close < close[lookbackBonusSetup]
bonusPhaseR = close > close[lookbackBonusSetup]

// Increment the setup counter when the setup phase is triggered and price is falling
if setupPhaseF
    setupCountF := na(setupCountF) ? 1 : setupCountF + 1
    setupCountF
else
    setupCountF := na
    setupCountF

// Bonus increment to the bonus counter when the phase is triggered and price is falling
if setupCountF > 9 and bonusPhaseF
    bonusCountF := na(bonusCountF) ? 1 : bonusCountF + 1
    bonusCountF
else
    bonusCountF := na
    bonusCountF



// Increment the setup counter when setup phase is triggered and price is rising
if setupPhaseR
    setupCountR := na(setupCountR) ? 1 : setupCountR + 1
    setupCountR
else
    setupCountR := na
    setupCountR

// Bonus increment to the bonus counter when the phase is triggered and price is rising
if setupCountR > 9 and bonusPhaseR
    bonusCountR := na(bonusCountR) ? 1 : bonusCountR + 1
    bonusCountR
else
    bonusCountR := na
    bonusCountR




// Plot the '7' on the chart when the setup phase is triggered 8 times in a row
if not na(setupCountF) and setupCountF == 7
    label.new(x=bar_index, y=low - syminfo.mintick * 2, text='7', color=color.rgb(33, 149, 243, 57), style=label.style_label_up, size=size.tiny)

// Plot the '8' on the chart when the setup phase is triggered 8 times in a row
if not na(setupCountF) and setupCountF == 8
    label.new(x=bar_index, y=low - syminfo.mintick * 2, text='8', color=color.rgb(33, 149, 243, 23), style=label.style_label_up, size=size.tiny)

// Plot the '9' on the chart when the setup phase is triggered 9 times in a row
if not na(setupCountF) and setupCountF == 9
    label.new(x=bar_index, y=low - syminfo.mintick * 2, text='9', color=color.rgb(76, 175, 79, 18), style=label.style_label_up, size=size.small)


// Bonus Plots when price is falling

// Plot the '11' on the chart when the bonus setup phase is triggered 
if not na(bonusCountF) and bonusCountF == 2
    label.new(x=bar_index, y=low - syminfo.mintick * 2, text='11', color=color.rgb(33, 243, 243, 70), style=label.style_label_up, size=size.tiny)

// Plot the '12' on the chart when the bonus setup phase is triggered
if not na(bonusCountF) and bonusCountF == 3
    label.new(x=bar_index, y=low - syminfo.mintick * 2, text='12', color=color.rgb(33, 243, 233, 54), style=label.style_label_up, size=size.tiny)

// Plot the '13' on the chart when the bonus setup phase is triggered 
if not na(bonusCountF) and bonusCountF == 4
    label.new(x=bar_index, y=low - syminfo.mintick * 2, text='13', color=color.rgb(235, 247, 247, 47), style=label.style_label_up, size=size.small)






// Plot the '7' on the chart when the setup phase is triggered 8 times in a row when prices are rising
if not na(setupCountR) and setupCountR == 7
    label.new(x=bar_index, y=high - syminfo.mintick * 2, text='7', color=color.rgb(238, 255, 0, 73), style=label.style_label_down, size=size.tiny)

// Plot the '8' on the chart when the setup phase is triggered 8 times in a row when prices are rising
if not na(setupCountR) and setupCountR == 8
    label.new(x=bar_index, y=high - syminfo.mintick * 2, text='8', color=color.rgb(255, 153, 0, 51), style=label.style_label_down, size=size.tiny)

// Plot the '9' on the chart when the setup phase is triggered 9 times in a row when prices are rising
if not na(setupCountR) and setupCountR == 9
    label.new(x=bar_index, y=high - syminfo.mintick * 2, text='9', color=color.rgb(255, 82, 82, 44), style=label.style_label_down, size=size.small)



// Bonus Plots when price is rising

// Plot the '11' on the chart when the bonus setup phase is triggered 
if not na(bonusCountR) and bonusCountR == 2
    label.new(x=bar_index, y=high - syminfo.mintick * 2, text='11', color=color.rgb(33, 243, 243, 70), style=label.style_label_down, size=size.tiny)

// Plot the '12' on the chart when the bonus setup phase is triggered
if not na(bonusCountR) and bonusCountR == 3
    label.new(x=bar_index, y=high - syminfo.mintick * 2, text='12', color=color.rgb(33, 243, 233, 54), style=label.style_label_down, size=size.tiny)

// Plot the '13' on the chart when the bonus setup phase is triggered 
if not na(bonusCountR) and bonusCountR == 4
    label.new(x=bar_index, y=high - syminfo.mintick * 2, text='13', color=color.rgb(235, 247, 247, 47), style=label.style_label_down, size=size.small)

Overview

The counters reset when the condition breaks. This is a simplified take on the TD Sequential idea and is not a full implementation. The visible code does not show the plotting section.

Details

Published by

mikeyhu70 on GitHub

Code credit

congacindy, as written in the script's header

Draws

On the price chart

Markets

Any symbol

Timeframes

Any timeframe

Risk Notes

No repainting, lookahead or stacked entries were found in its code or README. That says nothing about how well it works: test it first.

Third-party code. ForexR did not write, test or endorse this script, and the summary above was generated automatically from its code and README. Indicators describe the past, and a strategy's backtest can look better than live trading, especially when a script repaints. Check it in the Strategy Tester and on a demo account before you rely on it.

Similar Pine Scripts

947 stars

The Adaptive RSI Moving Average (ARSIMA) is an overlay indicator that dynamically adjusts its smoothing factor based on the Relative Strength Index (RSI). When the RSI moves toward extreme overbought or oversold conditions, the smoothing factor increases to ma

Indicator v4 Moving averagesOscillators & momentum
Updated 12 days ago · GPL-3.0 GitHub repository of Adaptive RSI Moving Average

This overlay indicator screens a pasted list of up to forty symbols and draws a table on the price chart. It classifies bullish or bearish setups from the percent change between the current candle and the candle 250 bars back, then shows RSI with a simple movi

Indicator v5 Oscillators & momentumVolume
Updated 1 year ago · MPL-2.0 GitHub repository of Momentum Setup - Ankush Bajaj Momentum Investing Setup

This indicator plots trade entry and exit signals on the price chart by combining Bollinger Bands with optional filter conditions. It calculates standard Bollinger Bands along with RSI, Aroon, and moving average filters. Reversal signals trigger when price bre

Indicator v4 Volatility & bandsOscillators & momentum
Updated 2 months ago · None stated GitHub repository of Bollinger Bands Winner IND [Alorse]
318 stars

This indicator plots three moving averages on the price chart alongside colored fills between the lines to visualize trend structure. Internally, it calculates a Stochastic RSI oscillator to detect oversold reversals. When the Stochastic %K line rises above 10

Indicator v5 Moving averagesOscillators & momentum
Updated 2 months ago · MIT GitHub repository of TVT 3X Scale In Out
285 stars

Mean Reversion Study is an indicator that identifies trade setups combining exponential moving averages, RSI extremes, and engulfing candlestick patterns. It highlights bullish setups when a bullish engulfing candle forms below the EMA while RSI is oversold, a

Indicator v4 Mean reversionCandlestick patterns
Updated 3 years ago · None stated GitHub repository of Mean Reversion Study

More Oscillators & momentum scripts

Related on ForexR

Trade Your Charts With a Regulated Broker

Compare brokers that connect to TradingView, with spreads, minimum deposits and leverage side by side.

Compare brokers