Disclaimer:
“Sequential™” is a registered trademark of Tom Demark. This post presents an independent, educational interpretation of the components of the Sequential™ pattern as described in Tom Demark’s book, The New Science of Technical Analysis. The analysis, opinions, and code examples provided herein are solely those of the author and are intended for informational and educational purposes only. This work is not affiliated with, endorsed by, or officially connected to Tom Demark or any related entities.
Sequential™ Pattern – Setup and Countdown
This pattern is fully described in Tom Demark’s book and consists of two distinct phases. For brevity’s sake, I will just discuss the buy setup. This indicator is designed to help determine when a trend is becoming or has become exhausted. Unlike a trend following indicator that helps you get in at the genesis of the trend, Sequential indicates when to take an opposing position after trend termination. This post doesn’t concern itself with the efficacy of Sequential, but with the process of programming such a difficult pattern and all the conditions that it involves. The indicator consists of two parts or phases. The Setup phase is stringent, requiring that the same price pattern occur for at least nine consecutive days (bars). In contrast, the Countdown phase is less strict; it mandates that a different price pattern occurs over a span of 13 days (or bars), although these occurrences do not need to be consecutive. Setup is complete when an “intersection” occurs, marking the point where prices start to brake or consolidate. Countdown, on the other hand, is finished when the 13th instance of the designated price pattern is observed. Because the pattern in the Countdown phase does not have to appear on consecutive bars, this phase can take many days to complete. During Countdown, three scenarios can occur that either restarts or recycles the process.
Setup – Sequence
- close[0] > close[4]
- followed by nine consecutive Close[0] < Close[4]
Intersection- Sequence
- If nine bars fulfill the Setup then examine the following
- Bar 8 High[1] > Lowest(Low[4],5)
- Bar 9 High[0] > Lowest(Low[3],5)
Countdown – Sequence
- 13 days or bars fulfill Close[0] < Low[2] over any number of days
Sequential™ – Completion, Restart, Recycle
- Completion – once Countdown reaches 13, the Sequential pattern is completed.
- Restart – during countdown if a Close > Highest High during setup or a Sell Setup occurs – start either from scratch or start the Sell Countdown
- Recycle – a new Buy Setup occurs, then start from the Countdown phase again.
Because we have to monitor a Sell Setup during the Countdown phase, we need to run two Finite State Machines concurrently. These two state machines will duel with each other. Both searching for their own solutions and knocking each other out during the process.
Finite State Machine Structure
Years ago, I embarked on building a theoretical compiler—a challenging project I nearly finished. The initial step was to create a parser that transforms high-level code into tokens according to the language’s grammar. In doing so, I learned about Finite State Machines (FSMs) as my program processed source code one character at a time and used FSM logic to build a token table.
Sample FSM to Find Pivot Highs and Pivot Lows
From this experience, I quickly discovered that even the most complex patterns can be detected using a Finite State Machine. Below is a graphical representation of a simple FSM that identifies the following pattern that can take up to 90 days (bars) to complete.
-
A high pivot with strength 2
-
Followed by a low pivot with strength 2
-
Followed by another high pivot with strength 2
In this example, a pivot is defined such that the central (or “pivot”) bar must have a higher high (for a high pivot) or a lower low (for a low pivot) than both the two bars preceding it and the two bars following it. Additionally, I also added the high pivot requires that the two prior bars exhibit ascending highs and that the two subsequent bars exhibit descending highs, while a low pivot follows the opposite pattern.
Finite State Machines (FSMs) consist of a limited number of states that describe the various conditions of a system:
- Start State: The initial point where processing begins. Looking for the first Pivot High.
- Intermediate States: The stages the FSM progresses through as it processes input. Looking for the first Pivot Low.
- Terminal (or Accepting) States: The final state(s) indicating the system has completed its task. Locating the final Pivot High.
Transition logic (the “rules” for shifting between states) guides the FSM’s movement, and some FSMs include a timeout function that resets the machine if it stays in one state too long.
Transition from FSM State 0 to FSM State 1
Acting like Pac-Man, the FSM gobbles one bar at a time and looks for this pattern:
- high[2] >high[1] – right side
- high[1] >high[0] – right side
- high[2] > high[3] – left side
- high[3] > high[4] – left side
Transition from FSM State 1 to FSM State 2
Now we look for the specific low pivot pattern
- low[2] <low[1] – right side
- low[1] <low[0] – right side
- low[2] < low[3] – left side
- low[3] < low[4] – left side
Transition from FSM State 2 to Completion and then back to FSM State 0
The pattern is completed after the subsequent high pivot pattern is confirmed. Once completed the machine resets itself to FSM State 0.
- high[2] >high[1] – right side
- high[1] >high[0] – right side
- high[2] > high[3] – left side
- high[3] > high[4] – left side
FSM Clock Override
If the pattern is not recognized within 90 days or bars from the first pivot high, then the machine resets back to FSM State 0.
Pivot Point FSM Output

Switch Case in EasyLanguage
When I started programming in Python, the Case statement was not included which shocked me. Since Python 3.10 it has been introduced. A Switch Case structure lets a program choose among several execution paths based on a variable’s value, using distinct cases instead of long if-else chains. This results in cleaner, more efficient, and more readable code. Take a look at the syntax of the Switch Case in EasyLanguage – remember much of the following code is dedicated to painting the bars.
The syntax is straightforward: the keyword switch is used, and the variable FSMState directs the flow through different case blocks. Initially, FSMState is set to 0, and a transition occurs only when the specified criteria are met. Once met, FSMState is updated to 1. EasyLanguage follows a non-fall-through paradigm—once a state transition occurs, no other case statements are evaluated during that iteration; the program simply reaches the end of the block and awaits the next cycle. By contrast, in some languages, when the state changes (for example, from 0 to 1), the corresponding case for state 1 may be evaluated immediately within the same cycle.
Is it as Complicated as it Looks?
Not at all. Look at the different case blocks and you will see a very similar structure. As stated earlier the code to paint the bars take up 12 lines of code. The timer is located at the bottom of the code – once barCount = 90, the FSM resets to 0.
Is Sequential ™ Easy to Program with a Finite State Machine?
I wouldn’t say easy, but I wouldn’t say hard either. With a little elbow grease and knowledge of how TradeStation works, and some EasyLanguage knowledge it is not difficult. If it were easy, you would see the code all over the place. I have previously programmed parts of it in my Easing into EasyLanguage books.
You might think you could have ChatGPT generate the code for you, and for laughs, I tried asking ChatGPT to program Sequential™ using FSM and Switch/Case in EasyLanguage. While the output provided a foundation, most of the syntax was off, and the patterns weren’t defined properly. Ultimately, I discovered that simplifying the design—by using separate FSMs for the buy side and the sell side—made the implementation more manageable. To simplify the process, I focused exclusively on the buy side at first. I figured that once I had programmed the complete pattern for the buy side, adapting it to the sell side would be as simple as reversing the logic—since the overall structure remains identical.
Using “Backward Scanning” for the Setup Phase.
Setup requires analyzing at least 10 consecutive bars. When you hear “consecutive,” think of looping through each bar in sequence. A stringent consecutive pattern is best uncovered by looping back through historical data. For example, you can loop through the bars to identify a sequence of nine consecutive bars where the close of the current bar is less than the low from four bars prior. However, immediately preceding those nine bars, you must verify that the prior bar’s close is greater than the close from four days earlier. This additional condition ensures the pattern begins under the correct circumstances.
Is there a Method to this Madness?