Indicator · Pine Script v5 · On the chart

Tom DeMark 9 and 13 Buy/Sell Signals

by mikeyhu70· code credited to congacindy

A Pine Script v5 indicator that approximates a Tom DeMark style count on the price chart.

View on GitHub

GitHub stars1on the repository
Pine versionv5runs as is
Lines of code51
Settings1inputs
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

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

TD Sequential.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("Tom DeMark 9 and 13 Buy/Sell Signals", overlay=true)

// Input parameters
lookback = input.int(50, "Lookback Period", minval=1)

// Function to calculate the TD Sequential count
td_sequential(source, lookback) =>
    var count = 0
    var signal = ""
    
    for i = 0 to lookback - 1
        if source[i] > source[i + 4]
            count := count == 0 ? 1 : count + 1
            if count == 9
                signal := "Buy"
            else if count == 13
                signal := "Sell"
        else
            count := 0
            signal := ""
    
    [count, signal]

// Calculate TD Sequential counts for high and low
[td_high_count, td_high_signal] = td_sequential(high, lookback)
[td_low_count, td_low_signal] = td_sequential(low, lookback)

// Plot signals and counts
plotshape(td_high_signal == "Buy", title="TD Buy", location=location.abovebar, style=shape.triangleup, size=size.small, color=color.green)
plotshape(td_high_signal == "Sell", title="TD Sell", location=location.abovebar, style=shape.triangledown, size=size.small, color=color.red)

plotshape(td_low_signal == "Buy", title="TD Buy", location=location.belowbar, style=shape.triangleup, size=size.small, color=color.green)
plotshape(td_low_signal == "Sell", title="TD Sell", location=location.belowbar, style=shape.triangledown, size=size.small, color=color.red)

// Print current counts if no signal
var label td_high_label = na
var label td_low_label = na

if barstate.islast and td_high_signal == ""
    td_high_label := label.new(bar_index, high, str.tostring(td_high_count), style=label.style_none, textcolor=color.gray, size=size.small)
else
    label.delete(td_high_label)

if barstate.islast and td_low_signal == ""
    td_low_label := label.new(bar_index, low, str.tostring(td_low_count), style=label.style_none, textcolor=color.gray, size=size.small)
else
    label.delete(td_low_label)

Overview

Tom DeMark 9 and 13 Buy/Sell Signals compares each bar with the one four bars earlier, keeps a running count over a lookback window, and plots a green up triangle at nine and a red down triangle at thirteen, for both highs and lows. A grey label shows the current count on the last bar. The count is a simplified version and does not follow the full TD Sequential rules.

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.

Settings

The inputs you can change from the gear icon on the chart. Defaults are the author's.

SettingTypeDefaultVariable
Lookback Periodint50lookback
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 11 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