How do I turn something I noticed on a chart into a rule I can test?
Short answerWrite every decision down before you look at any results: the market and candle size, the entry condition measured on closed candles, the price you could actually get (the next candle's open, not the close that triggered the signal), the exit, the position size, the costs and the data period. Then compare the result with a baseline, such as simply holding, and with the plain assumption that the pattern does nothing. In the worked example below, two reasonable translations of "price bounces after three down candles" gave opposite results on the same candles: one lost 3.10% after costs and the other gained 0.17%.
The written rule is what gets tested, not the idea. Fixing it in advance stops you from rereading a vague idea to fit what already happened, and lets a test tell you plainly when a pattern is not worth trading.
Valmy noteAs specified on 25 November 2026, Valmy strategies are built through chat, evaluated on closed five-minute candles and written in a versioned rule language whose only indicator is the simple moving average. Details in the live app could differ, so check them there. Nothing in this lesson is a recommendation to trade a rule.
Why a chart observation is not yet a rule#
An observation such as "price tends to bounce after three down candles" contains at least four undefined words. Each one hides a choice that changes the result:
- "Down candle." A close below the previous close, or a close below the candle's own open? On a market that trades around the clock these are often the same, but not on a market that gaps.
- "Three." Exactly three, or at least three? A fourth lower close would trigger a second signal under one reading and not the other.
- "Bounce." One higher close? A return to a moving average? A gain of 1%? Over what time?
- "Tends to." More often than after any other candle? By how much, after costs?
A chart also shows you every past candle at once. When you scan it, the bounces that happened are easy to see and the times the pattern led nowhere are easy to forget. A written rule removes that freedom: it trades every time its conditions are met, including the times you would have liked to skip.
What a testable rule must pin down#
A rule is testable when two people given the same candles and the same written rule would produce exactly the same list of trades. That requires the decisions below, written down before the first test. The worked example later in this lesson fills in every line.
| Item | What to decide | Example answer |
|---|---|---|
| Market and candle size | Which instrument, which candle size | A token quoted in USDT, five-minute candles |
| Data period | Which candles, chosen before testing | 144 candles (12 hours), with 20 earlier candles of history for the average |
| Entry condition | A true-or-false test on closed candles only | The close is lower than the previous close for the third candle in a row |
| Fill price | The first price available after the signal | The next candle's open, plus spread and slippage |
| Exit | A condition or a time, also on closed candles | Sell at the open six candles after buying |
| Position size | How much each trade uses | The whole 1,000 USDT balance |
| Overlapping signals | What happens to a signal while a trade is open | Ignored: one position at a time |
| Costs | Fees, spread and slippage per side | 0.10% fee plus an assumed 0.05% per side |
| End of test | What happens to a trade still open | Sold at the open of the final candle |
What counts as a trade. In this lesson a trade is one round trip: a buy fill followed by a sell fill. Signals that arrive while a position is open are not trades. Counting them, or counting a buy without its sale, makes a rule look more active or more successful than it was.
Why the fill is the next open. A signal that uses a candle's close is known only once that candle has closed, so the earliest realistic fill is the next candle's open. Filling at the signal candle's own close assumes you traded at a price before you could know you wanted to. The lesson What is look-ahead bias, and how does it get into a backtest? shows how much that assumption can inflate a result.
The null hypothesis and the baseline: what the rule must beat#
A test needs something to beat. The null hypothesis is the boring explanation: the pattern tells you nothing, and price after it behaves like price after any other candle. A baseline is a simple alternative you could have chosen instead. Two baselines are useful for almost any rule:
- Holding the market over the same period, with one round trip of costs. If the rule loses less than holding in a falling market, it may simply have been out of the market more often.
- The same holding time after any candle. If the rule holds for 30 minutes after its signal, compare its average 30-minute return with the average 30-minute return after every candle in the data. The pattern adds information only if the first is clearly higher, by more than the costs.
The lesson How do I compare a strategy with simply holding? covers the holding comparison in more depth.
Worked example: one idea, two rules on the same candles (synthetic data)#
Two precise versions of one idea, tested on the same candles with the same costs, gave opposite results: Rule A lost 3.10% after costs over 11 trades, Rule B gained 0.17% over 6 trades, and simply holding lost 1.70%. The data are 144 invented five-minute candles (12 hours) for a made-up token quoted in USDT, designed for this lesson: a sideways stretch near 100, a sell-off from a close of 100.83 at candle 82 to 97.92 at candle 90 (−2.9%), then another sideways stretch near 98. Twenty earlier candles provide history for a 20-candle simple moving average, SMA(20), the average of the last 20 closes. Both rules start with 1,000 USDT, trade the whole balance, hold one position at a time and pay the same costs: a 0.10% fee per side (Binance's base Spot rate as of 26 November 2026) plus an assumed 0.05% per side for spread and slippage. One round trip therefore costs about 0.30%.
Both rules start from the same idea, "price bounces after three down candles", and use the same entry signal: three lower closes, meaning the close is lower than the previous close for three candles in a row. They differ in what "bounce" means.
Rule A: buy after three lower closes, hold for 30 minutes#
- Entry: at the close of a candle that completes three lower closes, buy at the next candle's open.
- Exit: sell at the open six candles after the buy, 30 minutes later, whatever price has done.
Rule B: buy after three lower closes below the average, sell back at the average#
- Entry: the same three lower closes, and the close is also below SMA(20). Buy at the next open.
- Exit: when a candle closes above SMA(20) after closing at or below it on the previous candle, sell at the next open.
| Result over the 144 candles | Rule A | Rule B | Holding |
|---|---|---|---|
| Round trips | 11 | 6 | 1 |
| Winning round trips after costs | 4 | 4 | — |
| Result before costs | +0.16% | +1.99% | — |
| Result after costs | −3.10% | +0.17% | −1.70% |
| Final balance (USDT) | 969.03 | 1,001.74 | — |
Rule A traded nearly twice as often, so it paid nearly twice as much in costs: its small gain before costs became a 3.10% loss. Rule B waited for price to return to its average, took fewer trades and finished slightly ahead. Holding lost 1.70% because the sell-off happened in the middle of the period.
The sell-off trade under both rules#
The sell-off shows why the exit definition matters. Candles 83, 84 and 85 each closed lower than the one before, so both rules bought at the open of candle 86: 99.83, or 99.88 after the assumed slippage. Price kept falling.
- Rule A sold six candles later, at the open of candle 92, for a loss of 1.88% after costs. It then bought again at candle 98 and caught the rebound for a gain of 1.16%, its best trade.
- Rule B waited for a close back above SMA(20). It held for 16 candles and sold at the open of candle 102 for a loss of 1.31%. Its longest trade lasted 26 candles.
Neither exit was "right". A fixed holding time cuts losses short and also cuts rebounds short. An exit at the average waits for the bounce the idea promised, which works in a range and can mean holding a falling position for a long time.
What the two results do and do not show#
The two results disagree, but neither one is evidence that the idea works. Three checks explain why.
The null check. Three lower closes occurred 24 times in the 144 candles (some overlap, because four lower closes in a row count twice). The average return over the following 30 minutes, measured from the next open, was +0.02%. After any candle in the test, the same 30-minute window returned −0.05% on average across 137 windows. The difference, 0.08 percentage points, is far smaller than the 0.30% round-trip cost and comes from only 24 cases, many of them overlapping. In these candles the pattern was not followed by a bounce worth trading.
The sample size. Six trades cannot separate skill from luck. One different trade would change Rule B's result from a small gain to a small loss. A test needs many trades, in different market conditions, before its average says much.
The choice of rule. If you had tested Rule A first, seen −3.10%, then tried Rule B and kept it, the +0.17% would be the better of two tries, not an unbiased result. Every rule you try and discard counts. The lesson Why did my backtest work when live trading didn't? Overfitting and data snooping shows how quickly that selection inflates results.
Research on trading rules has faced the same problem. Sullivan, Timmermann and White (1999) note that a widely cited study had tested 26 precisely defined moving-average and range-break rules on the Dow Jones Industrial Average. They widened the set to nearly 8,000 rule variations to measure how much of the apparent success could come from searching many rules on one dataset. They also found that the best rule's advantage did not continue in the following ten years.
Writing the rule in Valmy's v1 strategy language#
As specified on 25 November 2026, a Valmy strategy is a versioned program: the user describes entry, exit and sizing rules in chat, and the AI translates them into a small JSON rule language and explains the result. That language could express Rule B, which needs only closes, lagged closes, SMA(20) and a crossover, but its only indicator is the simple moving average, and it may not support Rule A's fixed 30-minute exit. The specification defines what the language can say:
- When it runs. One instrument, once per closed five-minute candle. A schedule can restrict evaluation to selected UTC close times.
- What it can read. Prices and volume of the current and earlier closed candles, the strategy's own holdings and, for futures, its signed position.
- What it can compute. Constants, named parameters, values from a bounded number of candles back (lag), the simple moving average (the only indicator), checked arithmetic, comparisons, cross-above and cross-below, and boolean combinations, such as requiring two conditions at once.
- What it can do. Hold, buy on Spot for a quote amount, sell on Spot a base quantity, or open or reduce a futures position by a base quantity. Risk limits sit outside the program.
- How rules combine. Rules are evaluated in order, and the first one that is true sends one order intent. Otherwise the strategy holds. Too little history gives a hold with a warm-up reason.
The specification's illustrative Spot program buys 20 USDT (a parameter that can range from 1 to 50) when SMA(5) of the close crosses above SMA(20) of the close:
{
"language_version": 1,
"product": "spot",
"interval": "5m",
"parameters": {
"spend": {"type": "quote_amount", "default": "20", "min": "1", "max": "50"}
},
"rules": [{
"when": {"cross_above": [
{"sma": {"input": "close", "bars": 5}},
{"sma": {"input": "close", "bars": 20}}
]},
"then": {"spot_buy": {"quote_amount": {"param": "spend"}}}
}],
"otherwise": "hold"
}
This lesson does not write Rule B in JSON, because the specification publishes only this example and not the exact form of every element. In words, Rule B uses only the listed building blocks. A first rule sells the held quantity when the strategy holds the token and the close crosses above SMA(20). A second rule buys when the strategy holds nothing, each of the last three closes is below the close before it (three comparisons with lagged closes, joined by and), and the close is below SMA(20). Valmy's backtests, as specified, evaluate at each candle's close and simulate the earliest execution on a later candle, with a versioned fee, spread and slippage model, which matches how this lesson filled Rule B.
What the v1 language cannot express, as specified#
Some ideas need translating, and some cannot be written at all in the version specified on 25 November 2026:
- Other indicators. RSI, the exponential moving average, Bollinger Bands, ATR and the rest of the indicators taught in this library are not in the language. A rule that needs them can only be approximated with SMAs, lags and arithmetic, and the approximation is a different rule that needs its own test.
- Time since entry and entry price. The listed inputs include holdings but not when or at what price the position was bought. Rule A's fixed 30-minute exit, or a stop 2% below the entry price, may therefore not be expressible as specified. Check in the app before relying on either.
- Anything inside a candle. Rules see closed five-minute candles only. An order that should trigger the moment price touches a level, such as a resting stop order, is not among the listed actions.
- Other markets. Each evaluation covers one instrument, so a rule such as "buy ETH when BTC rises" cannot be written.
- Long lookbacks. The suggested initial limit is 1,000 candles of lookback, about 3.5 days of five-minute candles (a proposal, not a final value). A daily idea such as "three down days" would need closes 288, 576 and 864 candles back, compared at a scheduled daily close. That fits under the suggested limit, but a ten-day pattern would not.
What could change the conclusion about a tested rule#
A single test on one stretch of data is a starting point. Several things can change its verdict:
- Another period. This example had one sell-off in 12 hours. A period with a steady downtrend would punish Rule B's long holds, and a calm range would favor it. Test across trends, ranges and sell-offs, and see Is this market trending or stuck in a range?.
- Different costs. At zero cost Rule A made +0.16%. At a higher fee or a thinner market, both rules would do worse. How much do fees and slippage change a backtest? works through this.
- Small changes to the rule. If changing three lower closes to four, or SMA(20) to SMA(30), flips the result, the result depended on luck in the parameters.
- Data you used to form the idea. If you noticed the pattern on the same chart you then tested, the test is partly circular. Keep some data aside that you never looked at, as described in What is out-of-sample testing, and how do I set one up?.
- Real execution. A backtest uses a modeled fill. Paper trading and live fills can differ, as How do I paper trade without fooling myself? explains.
Check your understanding: writing down a rule#
Question. A trader writes: "After a big red five-minute candle, the price usually recovers." They test it on three days of candles, using a 1% fall from open to close as "big red", and find 40 such candles. Over the 30 minutes after each one, price rose by 0.20% on average, against 0.05% on average after any candle. They plan to pay a 0.10% fee per side and expect 0.05% per side of spread and slippage.
- What is the average result per trade after costs, and over 40 trades (adding the percentages simply)?
- Does the 0.15-point difference from the baseline support the idea?
- Which items in the rule are still missing before it can be tested properly?
Show the answers
Answer.
- One round trip costs about 2 × (0.10% + 0.05%) = 0.30%. The average result is 0.20% − 0.30% = −0.10% per trade, or about −4.0% over 40 trades.
- Not as a trading rule. The pattern was followed by slightly higher returns than the baseline, but the 0.15-point edge is half the 0.30% cost, it comes from 40 cases in three days of one market, and it was measured on the same data that suggested the idea. It is a reason to test on other data, not a reason to trade.
- The fill price (the open after the red candle closes, not its close), the exact exit (sell after six candles, or on a condition), the position size, what happens to a second red candle during an open trade, the instrument, and a data period chosen in advance that the trader has not already looked at.
Related lessons#
- Before this lesson: Is this market trending or stuck in a range?
- Next: How much do fees and slippage change a backtest?
- Next: What is look-ahead bias, and how does it get into a backtest?
- Next: How do I compare a strategy with simply holding?
- See also: What does a moving average actually measure?
- See also: When does a breakout fail?
- See also: Do chart patterns predict anything?