Trendline trading: how to turn a drawn line into a testable rule
A hand-drawn trendline is a judgment, not a rule, so two traders get different signals from one chart. To test it, replace the line with a fixed definition (swing-point line, Donchian channel or linear-regression channel), write the breakout confirmation as a rule, read it at the bar close and fill on the next bar.
By Soren Huang · Published · updated · Editorial policy
Contents
- How do you draw a trendline, and why do two traders draw different ones?
- How do you tell a real trendline breakout from a false one?
- How do you replace a hand-drawn line with a rule a computer can test?
- Where do the entry, stop and exit go without hindsight?
- Can a trendline strategy be backtested automatically? What a stand-in rule showed on ES
- What are the limits of trendline rules: subjectivity and lookahead?
- Frequently asked questions
- References
How do you draw a trendline, and why do two traders draw different ones?
Trendline trading connects two or more swing lows (or swing highs) with a straight line and trades the break of that line. To backtest it, replace the hand-drawn line with a fixed definition such as a swing-point line or a channel, write the breakout confirmation as a rule, read the signal at the bar close and fill on the next bar.
A trendline is a straight line drawn through two or more swing lows in a rising market, or two or more swing highs in a falling market, and extended to the right. A swing low is a bar whose low is lower than the lows of a set number of bars on each side of it. Trendlines belong to the drawn tools of technical analysis, not the computed ones; the guide to technical analysis tools and indicators you can test explains that split. An indicator such as RSI has one value on each bar because a formula produces it, which is why RSI rules and their 70/30 levels can be tested as written. A trendline has no formula until you give it one.
The usual drawing steps are:
- Decide the direction. Rising lines go under swing lows; falling lines go over swing highs.
- Choose two anchor swings. Many traders take the lowest low of the move and the most recent higher low.
- Choose wicks or closes. A line through the lowest wicks sits lower than a line through the lowest closes.
- Extend the line to the right and wait for price to cross it.
Steps 2 and 3 are judgments. Three traders on the same chart can pick different anchor swings and different price points, and each choice moves the line. Because the line sits at a different level on each bar, the three lines are crossed on different bars, and the three traders get the signal on different days or not at all. This is the claim that runs through this article: a trendline is not a tradable rule until a computer can draw the same line from the same bars, and the human part is what makes most trendline backtests look better than they are.
How do you tell a real trendline breakout from a false one?
A breakout is only testable once its confirmation is written as a rule, and every extra condition you add removes some false breaks at the price of a later entry. A breakout is a move of price through the trendline; a false breakout is a move through the line that returns to the old side within a few bars. Nobody can tell the two apart on the bar where the line is crossed. What you can do is decide in advance how much evidence you require before you act.
| Confirmation rule | Catches false breaks? | Entry delay | Missed moves |
|---|---|---|---|
| Wick beyond line | None | 0 bars | None |
| Close beyond line | Some | 1 bar | Few |
| Close plus 1 ATR beyond line | More | 1–2 bars | Some |
| Two consecutive closes beyond line | Most | 2 bars | More |
ATR (average true range) is the average size of a bar's full range over a set number of bars, so a distance filter in ATR adapts to how much the market is moving. A filter in fixed ticks does not adapt, which makes it tight in a fast market and loose in a quiet one. A hold filter (two or more closes beyond the line) asks for persistence instead of distance. There is no rule that is right for every market: a strong confirmation is worth more where false breaks are frequent, and worth less where the first bar after the break already carries most of the move.
Hypothetical example
Suppose a rising line sits at 100 on the signal bar and the 14-bar ATR is 2 points. Rule A ("close below the line") fires on any close below 100. Rule B ("close at least half an ATR below the line") fires only on a close below 99. Over a made-up year, rule A fires 30 times and 18 of those returns above the line within three bars; rule B fires 19 times and 7 return. Rule B skipped 11 signals, and it also entered about one point lower on the ones it took. Whether that trade is worth it is the question the backtest answers, not the chart.
How do you replace a hand-drawn line with a rule a computer can test?
Three rule-based substitutes draw the trend boundary from a fixed definition, so the same bars always give the same line and the result can be repeated. This is what Lo, Mamaysky and Wang (2000) did for chart patterns: they replaced the visual pattern with an algorithmic definition so it could be tested on many series. Each substitute captures a different part of what a trendline does.
- Swing-point line. Define a swing low as a bar with a set number of higher lows on each side (the "swing strength", for example 5), take the last two confirmed swing lows, and draw the line through them. This is closest to the hand-drawn line. The same swing definition is what makes a double bottom pattern testable with exact rules.
- Donchian channel. A Donchian channel is the highest high and the lowest low of the last N bars. Its lower band works as a horizontal "trendline" that steps up as the trend makes higher lows. Brock, Lakonishok and LeBaron (1992) tested this kind of trading-range break over a fixed lookback because it has no judgment in it. The Donchian channel indicator page shows the bands, and the article on Donchian channel breakout rules and settings covers lookbacks and exits.
- Linear-regression channel. A linear-regression channel is the straight line that best fits the closes of the last N bars, with bands drawn a set number of standard deviations above and below it. It is a sloped line like a trendline, but the slope comes from all N closes, not from two chosen points. The linear regression indicator page explains how the fit is computed.
| Property | Swing-point line | Donchian channel | Linear-regression channel |
|---|---|---|---|
| Numeric settings | Swing strength | Lookback | Lookback, band width |
| Sloped? | Yes | No (steps) | Yes |
| Closest to a hand-drawn line | Yes | Less | Partly |
| Delay before the line is known | Swing strength bars | None | None |
Once the line has numeric settings, those settings become parameters that a search can vary: swing strength 3 to 10, lookback 10 to 60, band width 1 to 2 standard deviations. That is the step where a trendline idea becomes a strategy family rather than a single drawing, and it is what the rule and parameter-range settings in strategy generation of AlphaPrime (Valynox) are for.
Where do the entry, stop and exit go without hindsight?
Every decision in the rule must use only bars that were already closed when the decision was made. The order of events is fixed and the same for every substitute line:
- Bar N closes beyond the line. The rule reads the signal at this close, using a line computed from bars up to N.
- Bar N+1 opens. The entry order fills here, at the open or with the slippage you set. Filling at the close of bar N uses a price the rule could not have traded at.
- The stop sits at the last confirmed swing. For a long trade after an upside break, that is the last confirmed swing low, placed on the bar where it was confirmed, not the bar where it formed.
- The exit is a rule, not a feeling. Two common ones are a close beyond the opposite line (the trend has turned) and a time limit such as 20 bars (the breakout did not develop).
The time-limit exit deserves a word. A trendline trader on a chart rarely counts bars, but a backtest without a time exit can sit in a flat trade for months waiting for the opposite line to break. A time limit forces the question "did this breakout go anywhere?" and frees the capital for the next signal. Test it as a parameter like the others.
Can a trendline strategy be backtested automatically? What a stand-in rule showed on ES
Yes, once the line has a fixed definition, a search can vary its inputs and backtest every variant with the same costs and the same fill rule. The run behind this article did that on ES daily bars from 2019-01-02 to 2025-06-30, long and short, one contract, with $20 commission and $25 slippage charged on every trade. It tested a Record Test rule, a stand-in built from standard indicators, as the only entry and exit, with no stop, no target and no filter; it is not a hand-drawn trendline, and the result stands for what a rule-based substitute produces in a report, not for trendlines themselves.
Source: AlphaPrime product engine (CPU), run 2026-10-31. ES daily bars, 2019-01-02 to 2025-06-30, long and short, 1 contract, $20 commission and $25 slippage per trade.
| Number | Result |
|---|---|
| Net profit (closed trades) | $56,377.5 |
| Max drawdown | $30,507.5 |
| Trades | 98 |
| Win rate | 60.2% |
| Profit factor | 1.498 |
| Average trade | $575.28 |
| Time in market | 34.26% |
Read the box with two facts in mind. First, this is the one candidate the search kept out of 1,024 it tried, chosen for its return against its drawdown. Picking the best of many after the fact flatters the number: Bailey, Borwein, López de Prado and Zhu (2014) show that the top result of a large search is inflated even when none of the rules has any edge. Second, 98 trades in about six and a half years is a thin sample, so the average trade of $575.28 could move a long way if a handful of trades were different. Nothing here says the rule earned that money in any sense a reader can expect; it says what a report of a fixed-definition rule looks like after costs.

What this means if you use AlphaPrime: the rule-based substitutes from the previous section can go into the same kind of search, AlphaPrime evaluates each variant with commission, slippage and next-bar execution, and the kept candidates land in the Performance Report with their equity curve and drawdown. The judgment that remains is yours: whether the drawdown stretch in the figure is one you could sit through.
What are the limits of trendline rules: subjectivity and lookahead?
Two failures quietly inflate a trendline backtest: a line that still depends on a human choice, and a swing point that is only known several bars after it formed. Lookahead bias is the use of information in a backtest decision that was not available at the time of that decision. Both failures are caught by the same test, described at the end of this section.
The first failure is leftover subjectivity. "Connect the two most important lows" is still a judgment even after you write it down. A test is only repeatable when every word in the rule is a number: swing strength 5, the last two confirmed swings, closes not wicks. If you cannot hand the rule to someone else and get the same line back, the backtest is testing your eye, not the rule.
The second failure is the swing-point delay. A swing low with strength 5 forms on bar 10, but it is not confirmed until bar 15, when the fifth higher low has closed. A line drawn through that swing on bar 10 knows the future: it knows that bars 11 to 15 will stay above it. Charting software that draws the swing marker at bar 10 makes this mistake invisible, because the marker sits in the past while the information that placed it comes from the future. The general version of this leak, and a one-bar check for it, is covered in look-ahead bias in backtests.
The check for both failures is a delay shift. Take every input the rule uses, move it forward by the confirmation delay (five bars for swing strength 5), and re-run the backtest. A rule that was free of lookahead changes little, because its line was already built from confirmed swings. A rule that leaked will lose a large part of its result, often most of it, because the early signals it took were the ones that used unknown future bars. Run this on your own trendline rule before any other validation: if the delay-shifted result still looks acceptable, the line is one you could actually have drawn on the day.
Frequently asked questions
Do trendlines work?
As a drawn tool, the question cannot be answered, because two traders draw different lines and so test different things. As a fixed rule (swing-point line, Donchian channel or linear-regression channel) it can be tested on your market with costs included. A survey of technical-analysis studies by Park and Irwin (2007) found that results vary a great deal by market and period and depend on costs and on how many rules were tried, so the answer is specific to the rule, the market and the test.
Should a trendline be drawn on wicks or on closes?
Either is acceptable, but the choice must be written down before the test and kept fixed. A line through wicks sits lower in an uptrend and is broken later; a line through closes is broken earlier and more often. Many systematic traders use closes for the signal because the close of a bar is the price that confirms the bar is finished, while a wick can be a single print.
How many touches does a trendline need to be valid?
Two points define a line; a third touch is often taken as confirmation that the market respects it. In a rule-based test, "touches" become the swing definition: the line is drawn through the last two confirmed swing lows and redrawn each time a new swing is confirmed. Requiring a third touch can be tested as a parameter, but it also delays every signal.
What is the best confirmation for a trendline breakout?
There is no single best one. A close beyond the line removes some false breaks for a one-bar delay; a close plus a distance in ATR removes more for a later and lower-quality entry; two consecutive closes remove most but miss moves that run on the first bar. Test two or three of them on the same data with the same costs and choose by the result after costs, not by how the chart looks.
References
- Lo, A. W., Mamaysky, H., & Wang, J. (2000). Foundations of Technical Analysis: Computational Algorithms, Statistical Inference, and Empirical Implementation. The Journal of Finance, 55(4), 1705–1765.
- Brock, W., Lakonishok, J., & LeBaron, B. (1992). Simple Technical Trading Rules and the Stochastic Properties of Stock Returns. The Journal of Finance, 47(5), 1731–1764.
- Bailey, D. H., Borwein, J., López de Prado, M., & Zhu, Q. J. (2014). Pseudo-Mathematics and Financial Charlatanism: The Effects of Backtest Overfitting on Out-of-Sample Performance. Notices of the American Mathematical Society, 61(5), 458–471.
- Park, C.-H., & Irwin, S. H. (2007). What Do We Know About the Profitability of Technical Analysis? Journal of Economic Surveys, 21(4), 786–826.

