HoppyQuant
中文

Lesson 2

Turn the Nine-Beat Count into Exact Rules

Define comparisons, count states, missing-data treatment, and confirmation timing so a chart label becomes an executable rule.

The five-part research route is spread across the table.

Hoppy thinks the first step should be easy.

He opens his AI assistant and types:

Please find every completed falling Nine-Beat Count in the stock data.

The AI does not begin. It asks a question instead:

Which version of the nine-beat rule would you like me to use?

Hoppy pauses.

“Doesn’t it just count from 1 to 9? Do we really need a meeting before that?”

Dr. Hop leans over to read the screen.

“The AI isn’t stalling. You gave it a destination called ‘nine-beat count,’ but you never told it which road to take. It can guess, but what it finds may not be what we meant to study.”

Different market apps may display a 1-to-9 sequence on price charts, but their implementation details are not always identical. In this course, Nine-Beat Count is our name for the fixed teaching rule defined below.

We do not need a tour of every counting method.

This lesson has one job: help us understand the simplified version used in this course.

The same name can hide different nine-beat rules, so the definition must come first.
Figure 1 | The same name can hide different rules, so define them first.

Understand the falling Nine-Beat Count in thirty seconds

Dr. Hop lays several candlestick cards on the table.

“When we ask whether a stock rose today, we normally compare today with yesterday.”

“That sounds perfectly reasonable,” says Hoppy.

“It is. But that is not what this nine-beat count asks.”

For the course version, the current candle looks farther back and compares with the fourth earlier valid candle.

Candle 5 compares with candle 1
Candle 6 compares with candle 2
Candle 7 compares with candle 3
…

The first four candles do not have enough earlier history, so they cannot receive a count yet.

Beginning with candle 5:

  • if the current close is below the close of the fourth earlier candle, it meets the down condition;
  • if that condition keeps appearing, the count advances from 1;
  • when it reaches 9, we have one completed falling Nine-Beat Count.
The current candle compares with the fourth earlier valid candle.
Figure 2 | Compare the current valid candle with the fourth earlier one.

If you simply want to continue the research, those three sentences are enough.

It does not mean “the stock fell every day for nine straight days.” It means:

Nine consecutive valid candles each closed below their own fourth earlier valid candle.

It can rise today and still meet the down condition

Hoppy brings over one fictional stock:

Fourth earlier candle's close: 10.2
Yesterday's close:              9.6
Today's close:                  9.8

The stock rose from 9.6 to 9.8 today. That is clearly an up day.

But the nine-beat count compares today with the fourth earlier candle:

9.8 < 10.2

Today still meets the falling Nine-Beat Count condition.

“How can it count as down when it rose today?” Hoppy asks.

“Because ‘down’ here does not mean ‘below yesterday.’ It means ‘still below four candles earlier.’”

A stock can rise today and still satisfy the nine-beat down condition.
Figure 3 | An up day can still satisfy the falling-count condition.

This is the easiest part to misunderstand.

If we treat a falling Nine-Beat Count as “nine daily losses in a row,” our study will be wrong before it begins.

When can we act after number 9 appears?

The central rule now makes sense, so Hoppy immediately asks:

“If number 9 appears today, we buy at today’s close, right?”

Dr. Hop answers with another question:

“When do you actually know that today is number 9?”

The rule needs today’s final closing price.

Before the close, the price is still changing and number 9 is not confirmed.

The only honest timeline is:

Day 9 closes
→ The final close confirms the completed count
→ The next valid candle opens
→ This is the earliest possible action

Using the close to confirm the signal while pretending we could already trade at that same close would require a time machine.

Time machines work beautifully in backtests.

Unfortunately, nobody sells them in real life.

Number 9 is confirmed only after the close, so the earliest action is the next valid candle's open.
Figure 4 | Number 9 is confirmed at the close; action starts next candle.
Lesson focus

If a signal needs information that becomes known at a certain moment, we can act only after that moment. Fast code cannot send future information into the past.

Put the rulers on the table before the study

We can now state a clearer idea:

After a stock completes a falling Nine-Beat Count, it may be more likely to rebound.

But does “after” mean three days, ten days, or six months?

If we inspect every possible result first and then choose the prettiest window, we may simply be choosing luck.

Before calculating returns, we will therefore freeze two things.

First, we divide the data into two periods:

  • January 4, 2021 through December 30, 2022: rule-development period;
  • January 3, 2023 through December 29, 2023: final holdout period.

The second period goes into a sealed envelope. Until the complete trading rules are frozen, we will not inspect its price direction, nine-beat signals, or returns.

Second, we place four observation rulers:

  • after the count is confirmed, the next valid candle’s open becomes the observation starting point;
  • count the entry candle as candle 1, then observe the result at the closes of valid candles 3, 5, 10, and 20.

We choose ten valid daily candles as the primary window. The other three help us see what happens over shorter or longer periods. “Ten days” here means ten valid daily candles, not ten calendar days. We agree on that before seeing the results.

These windows help us ask whether a rebound tends to appear early, late, or not consistently at all. They are not final exit rules.

Freeze the development period, holdout period, and observation windows before viewing returns.
Figure 5 | Freeze the study, holdout, and observation windows first.

You already know enough to continue

If you do not want to explore the technical details of the count, skip the extension below and continue at “Next, let the AI find the actual counts.”

You only need four ideas:

  1. The Nine-Beat Count is a fixed teaching rule for this study, not a claim about any ready-made indicator in a market app.
  2. The current close compares with the fourth earlier valid candle’s close.
  3. Nine consecutive down conditions are required to complete a falling Nine-Beat Count.
  4. Number 9 is confirmed only after that day closes, so the earliest action is the next valid candle’s open.

The next lesson will give the complete specification directly to the AI. Skipping the extension below will not leave you behind.


Extension: what other details does the program need?

Optional

The following sections explain interrupted counts, completion locks, and missing data. The program needs these details to run accurately, but you do not need them in order to enter the next lesson.

Same direction, opposite direction, and equality

The current close can have three relationships with the fourth earlier valid candle:

  • strictly below: down condition;
  • strictly above: up condition;
  • exactly equal: no direction.

If the new candle continues the direction of an unfinished sequence, the count advances.

If the condition flips to the opposite direction, the unfinished sequence ends. That same day becomes number 1 of the new direction.

If the two closes are exactly equal, the unfinished sequence also ends, but that day is neither up 1 nor down 1. The program waits for a new direction.

Same direction, opposite direction, and equality send the count toward three different outcomes.
Figure 6 | Same, opposite, and equal comparisons change the count differently.

Lock the sequence after 9

A completed count ends at 9. It does not continue to 10, 11, or 12.

If later candles keep meeting the same condition, the program stays locked. It does not immediately begin another count in the same direction.

The original direction must be interrupted at least once before a new sequence can begin:

  • equality unlocks the sequence and returns it to waiting;
  • the opposite direction unlocks it, and that day becomes number 1 of the new direction.

This prevents one long move from being chopped into many overlapping nine-beat counts.

After a completed count reaches 9, it locks instead of continuing to 10 or 11.
Figure 7 | The count locks at 9 instead of continuing to 10 or 11.

Never invent a candle that does not exist

In this course, “the Nth candle” means the Nth valid candle in that stock’s own sequence.

If the stock has no daily candle on a market trading day:

  • that day does not enter the count;
  • we do not create a placeholder candle;
  • one missing day does not automatically interrupt an existing sequence;
  • when data resumes, the stock continues by comparing with its own fourth earlier valid candle.

An occasional missing day is different from disappearing for a long stretch.

To prevent severe gaps from distorting the study, we freeze one course boundary in advance: if a continuous gap is strictly longer than 15 market trading days, we exclude the entire stock before the study.

Exactly 15 missing days does not trigger the rule. Day 16 does.

There is nothing magical about 15. It is simply a course boundary chosen before seeing the results.

An occasional missing candle is skipped, while a continuous gap longer than 15 trading days removes the stock from the study.
Figure 8 | Missing candles are skipped, but long gaps exclude the stock.

Next, let the AI find the actual counts

Hoppy opens the AI assistant again.

This time, he does not immediately send “find the nine-beat counts.”

In the next lesson, we will start a fresh conversation, give the AI a complete specification that does not depend on old chat memory, and ask it to work in stages:

Inspect the teaching data
→ Validate the counting method
→ Find completed signals in historical candles
→ Draw samples and check that the counts are correct
→ Then compare them with ordinary dates

You do not need to memorize the full specification or hand-write a state machine.

The important idea is simpler: a market claim must become a clear rule before data can test it.

Takeaway

A falling Nine-Beat Count is not nine straight daily losses. It is nine consecutive valid candles whose closes are each below their own fourth earlier valid candle. Number 9 is confirmed only after that day’s close, so the earliest action is the next valid candle’s open.

Lesson discussion

Share a question, insight, or different view—and see how other learners are thinking.