4.1 Technical analysis as statistical hypotheses
Motivation
Technical analysis is the study of price and volume history to time trades. Most of it is stated in pictures and folklore. A researcher's first job is to turn each picture into a function of data and each piece of folklore into a hypothesis that data can reject. Once you do this, two things become obvious: most indicators are reweightings of past returns, and an indicator "works" only if returns are autocorrelated or if the signal sorts assets with different mean returns.
4.1.1Setup#
Let be the close of a stock or index on trading day , adjusted for splits, bonuses and dividends (a corporate-action adjustment rescales past prices so that returns across the event are correct). Write and the log return . Each day also has an open , high , low and traded volume (shares). Let be the information available after the close of day : all bars up to and including .
Definition 4.1signal
A signal is a process that is -measurable: its value on day is a function of bars dated only. A position rule maps the signal to a target weight (fraction of equity), which is first held from the open of day .
Definition 4.2trading hypothesis
For horizon let be the forward return. A rule built on a binary signal has predictive content if
It is economically useful only if exceeds the round-trip cost of acting on the signal (4.4.4). The null hypothesis of the weak-form efficient market (prices follow a martingale with constant drift; see M13 · 13.1) implies for every signal.
Two points follow at once. First, the conditioning must be on , never on anything dated later; the most common bug in retail backtests is to compute with the close of day and also earn the return of day . Second, the hypothesis is about a conditional mean. A chart pattern that "looks bullish" is not a hypothesis until it says which mean, over which horizon, compared with what.
4.1.2Indicators as functions of the price series#
Definition 4.3core indicators
For a series and window :
- Simple moving average: .
- Exponential moving average: with .
- Trend: the sign of a smoothed slope. Common choices are (time-series momentum), , or for .
- Resistance and support (Donchian channel): and . A resistance level is a price where selling has previously stopped advances; the Donchian channel is the simplest objective version. Note that the window excludes day .
- Breakout: , the close exceeds the highest high of the previous days.
- Relative volume: . Again the average excludes today.
- Relative strength (RS) against a benchmark index (for example Nifty 500): . The Mansfield version is , positive when the stock is outperforming its own recent relative trend. A cross-sectional RS rank is the percentile of a stock's trailing 12-month return within a universe; IBD's proprietary "RS rating" is of this type.
Swing traders also use pivot support and resistance: a swing high at day is a bar with for . A swing high at is only known at day . Code that marks it at is using the future. This is the single most common source of look-ahead in pattern-recognition code.
Definition 4.4Wilder's RSI
The relative strength index (unrelated to relative strength above) with period (usually 14) is built from price changes . Let denote Wilder's smoother: , then , an EMA with . Define , with , , and
4.1.3What moving averages and RSI really are#
Proposition 4.1moving-average rules are momentum rules
Apply moving averages to log prices. For ,
with . The weights rise linearly for , peak at , and fall linearly to zero at . The rule "price above its -day average" is the case , with linearly declining weights .
Proof
Write . Then
The same with gives . Subtract: cancels and (4.1) follows. For , , increasing in . For , , decreasing. Finally , and likewise , so .∎
So the 50/200-day "golden cross" is a bet on a triangular-weighted average of the last 199 daily returns, with peak weight on the return 49 days ago. Every moving-average rule (SMA, EMA, MACD) is a linear filter of past returns followed by a nonlinearity (the sign). Its value depends entirely on the autocorrelation structure of returns.
Proposition 4.2expected return of a linear trend rule
Let be covariance-stationary with mean and autocovariances . Take the position , held over day . Then
Proof
. Sum with weights.∎
The first term is not timing skill: if , a rule with positive weights is long on average and collects part of the drift. The second term is the only source of timing profit, and it is a weighted sum of autocovariances at lags . Under a random walk () every MA rule earns only a diluted buy-and-hold return, before costs. The sign function in practical rules changes the constants but not the conclusion; Problem 4.3 asks you to show that for Gaussian returns the sign rule's timing term is still a linear combination of the .
Worked example 4.1a one-day momentum rule on an index
Suppose Nifty 50 daily returns have , and first-order autocorrelation , with for . These are illustrative numbers of the right order, not estimates; M02 shows how to estimate them. Use the unit-volatility position (in multiples of capital). By (4.2) with , :
Its daily volatility is about , so the gross daily Sharpe ratio is , about annualised. Now the cost. The position changes each day by with iid standard normal, whose mean is times capital. Delivery-equity costs at a discount broker are about 11.9 bp per side (4.4.4). Daily cost bp, against a gross edge of 5.25 bp. The net expected return is about bp a day. The predictability is real in this example and the strategy still loses money. Index futures are cheaper (M01), which is why fast trend rules are run on futures, not on delivery equity.
Proposition 4.3RSI is a normalised momentum oscillator
With Wilder's smoother,
Proof
is linear, and . So and . Then .∎
RSI is therefore an exponentially weighted mean price change divided by an exponentially weighted mean absolute change, mapped to . "RSI above 70 is overbought, sell" is a short-term reversal hypothesis: it says that a large normalised recent gain predicts a negative return. "RSI above 50 and rising" is a momentum hypothesis. The same indicator supports opposite rules, and both cannot be right on the same horizon. The data must decide, and 4.3 summarises what the data say. The code checks (4.3) to machine precision.
4.1.4Testing one rule honestly#
The simplest test of Definition 4.2 is an event study (M12 builds this in full). Collect the days with , compute forward returns in excess of the index, and form . Two traps make this -statistic too large.
Proposition 4.4overlapping horizons inflate -statistics
Let daily excess returns be iid with variance , and let be sampled on consecutive days (). Then
The naive standard error is too small by a factor .
Proof
for and zero otherwise, since the two windows share days. Hence , using .∎
Use non-overlapping events, or Newey–West (heteroskedasticity- and autocorrelation-consistent) standard errors with at least lags. The second trap is cross-sectional: breakouts cluster in time (many stocks break out in the same strong week), so events are not independent across stocks. Cluster standard errors by date, or test the rule as a calendar-time portfolio.
Worked example 4.2a 20-day breakout in Nifty 500 stocks
Suppose a screen finds 60 non-overlapping 20-day breakouts on above-average volume, with mean 20-day return in excess of the Nifty 500 of 1.2% and standard deviation 8%. Then . The evidence is consistent with no edge. To reach at the same mean and dispersion you need independent events. If the 60 events had come from overlapping daily samples, the naive could easily exceed 3, which would be spurious.
Practitioner notes
- The canonical academic test of chart rules is Brock, Lakonishok and LeBaron (1992). They tested moving-average and trading-range-break rules on the Dow Jones index from 1897 to 1986, reported strong support for the rules, and found returns after buy signals higher and less volatile than after sell signals. They used bootstraps under random-walk, AR(1), GARCH-M and EGARCH nulls. Case study 4.7.3 discusses what happened when Sullivan, Timmermann and White (1999) asked how many rules had been tried before those 26 were chosen.
- Indicator parameters (14 for RSI, 20/50/200 for moving averages) are conventions, not optimal values. Every parameter you vary is another trial, and 4.6 charges for it.
- Prefer rules on log prices or returns. A rule on price levels (a fixed ₹ stop, "round number" resistance at ₹1,000) changes meaning when the series is back-adjusted for a later bonus issue. That is a look-ahead in disguise (4.4.2).