DEV Community

Jack
Jack

Posted on Originally published at td-sequential.hashnode.dev Fully Autonomous

TD Sequential Explained for Developers: Counting the 9 in JavaScript

I build a crypto scanner around TD Sequential, and the first thing you learn is that the rules look simple until two tools disagree. Here is the setup phase as code, with the edge cases that cause those disagreements. The disclosure is at the end.

TD Sequential is a bar-counting method created by Tom DeMark. It has a setup that counts to 9 and a countdown that counts to 13. A completed count flags possible trend exhaustion. It does not forecast a price.

The setup rule

A buy setup is nine closes in a row, each below the close four bars earlier. A sell setup is nine closes in a row, each above it. One bar that breaks the run resets the count.

// Returns the setup count per bar: negative for buy setups, positive for sell setups.
function setupCounts(closes) {
  const counts = new Array(closes.length).fill(0);
  for (let i = 4; i < closes.length; i++) {
    const prev = counts[i - 1];
    if (closes[i] < closes[i - 4]) {
      counts[i] = prev < 0 ? (prev === -9 ? -1 : prev - 1) : -1;
    } else if (closes[i] > closes[i - 4]) {
      counts[i] = prev > 0 ? (prev === 9 ? 1 : prev + 1) : 1;
    }
  }
  return counts;
}
Enter fullscreen mode Exit fullscreen mode

A value of -9 is a completed buy setup, and 9 is a completed sell setup.

Where implementations disagree

  • The price flip. DeMark's description puts a flip before bar 1. The code above starts from the first qualifying close and does not wait for a flip, so it can start a count earlier than a flip-based tool.
  • After bar 9. Some tools stop at 9, and others keep counting past it. The code above starts again at 1.
  • Equal closes. The code treats an equal close as breaking the run. Check what your reference tool does.
  • The forming bar. Only pass closed bars. If you feed in the forming bar, a 9 can appear and then vanish before the bar closes.

The countdown is a different shape

The countdown starts after a completed setup. A buy countdown counts bars that close at or below the low two bars earlier, and the bars do not have to be consecutive. That means you need highs and lows as well as closes, and state that survives across bars that do not qualify. Many descriptions also test bar 13 against countdown bar 8, which is why you will see non-qualified 13s.

Test it against something real

Do not trust your count until you have compared it with a known chart, bar by bar. The full rules are written up here, including where published sources differ, and the free TD Sequential Counter shows the current count for a crypto pair with no account.

Moolish Scan Events screen: a daily scan for Buy Setup 9 or Sell Setup 9

Scan results table listing crypto pairs with a matching TD Setup 9

Sequencer 9-13 signals with chart examples: setups, countdowns, support and resistance

Disclosure: I'm Jack, the founder of Moolish, a crypto market scanner. Moolish is not affiliated with Tom DeMark or DeMARK Analytics. This is education, not financial advice.

Top comments (0)