7.1 Technical Indicators as Mathematics
Moving averages, RSI, MACD and Bollinger bands are formulas applied to past prices — weighted averages, ratios and standard deviations. Learn exactly what each one computes, why every smoother lags, what a crossover really measures, and what happens when you test the signals honestly on simulated random-walk prices.
📍 The situation
Karan, 26, a software tester in Indore, has started swing trading a hypothetical share, "Alpha Bank Ltd". His trading app draws five lines over the price chart: a 50-day simple moving average, a 20-day exponential moving average, Bollinger bands, and, in panels underneath, the RSI and the MACD. A Telegram channel he follows has simple rules: "Golden cross = buy. RSI below 30 = oversold, it will bounce. Touch the lower Bollinger band = cheap. Our RSI calls worked 9 times out of the last 12."
Karan's questions are the questions of this section. What does each line actually compute? Why does the moving average always seem to turn after the price has already turned — and is the "faster" EMA really faster? What is a crossover a sign of? What does "RSI = 28" or "outside the band" mean as a number? And the big one: can any of these signals predict the next move, and how would you check a claim like "9 out of 12"? The answers use weighted averages and geometric series, a derivative in disguise, the standard deviation of §3.1, and the random walk of §3.3 — and the most important result is an honest negative one: on a random walk, no indicator can have an edge.
Every price on this page is either a small hypothetical data set chosen to make the arithmetic clear or simulated (a seeded random walk, generated in your browser or in a Python check) — none of it is the history of a real share or index, and no result here is a statement about how any indicator has performed in real markets. Transaction costs are illustrative; brokerage, STT, exchange charges, stamp duty and taxes change, so check your broker's current charges and the SEBI/NSE circulars. People, companies and channels are hypothetical. Nothing here is investment advice or a trading recommendation.
Moving Averages: Weighted Averages and Filters
Daily closing prices jump around. A moving average replaces each day's price by an average of the recent past, so the day-to-day jitter partly cancels and a smoother line remains. In engineering language a moving average is a filter: it lets slow movements through and damps fast ones. Throughout this section $P_t$ is the closing price on trading day $t$ (days counted in trading days, not calendar days).
The $n$-day simple moving average on day $t$ is the plain average of the last $n$ closes, today included: $$\text{SMA}_n(t)=\frac{P_t+P_{t-1}+\cdots+P_{t-n+1}}{n}.$$ Each of the last $n$ closes gets weight $1/n$; older closes get weight $0$. Moving one day forward, the newest close enters and the oldest leaves: $\text{SMA}_n(t)=\text{SMA}_n(t-1)+\dfrac{P_t-P_{t-n}}{n}$.
Choose a smoothing constant $\alpha$ with $0\lt\alpha\le1$. The exponential moving average is defined recursively by $$\text{EMA}_t=\alpha P_t+(1-\alpha)\,\text{EMA}_{t-1},$$ started from some initial value $\text{EMA}_0$ (usually the first close, or the SMA of the first $n$ closes). Charting software calls it an "$n$-day EMA" when $$\alpha=\frac{2}{n+1}\qquad(\text{so }n=9,19,39\text{ give }\alpha=0.2,\ 0.1,\ 0.05).$$
A weighted moving average in general is $M_t=\sum_{k\ge0}w_kP_{t-k}$ with weights $w_k\ge0$ adding up to $1$; $w_k$ is the weight on the close $k$ days ago. The SMA has $w_k=1/n$ for $k\lt n$; the "linearly weighted" WMA has $w_k\propto n-k$ for $k\lt n$. The lag (average age) of the filter is $L=\sum_k k\,w_k$, measured in days.
For $0\lt\alpha\lt1$ and every $t\ge1$, $$\text{EMA}_t=\sum_{k=0}^{t-1}\alpha(1-\alpha)^k\,P_{t-k}+(1-\alpha)^t\,\text{EMA}_0 .$$ The weights $\alpha,\ \alpha(1-\alpha),\ \alpha(1-\alpha)^2,\dots$ form a geometric progression and, together with the weight $(1-\alpha)^t$ on the starting value, add up to $1$. Once the start is far in the past (so $(1-\alpha)^t\approx0$), the average age of the data is $$L_{\text{EMA}}=\sum_{k=0}^{\infty}k\,\alpha(1-\alpha)^k=\frac{1-\alpha}{\alpha},$$ while an $n$-day SMA has $L_{\text{SMA}}=\dfrac{n-1}{2}$. With $\alpha=\frac{2}{n+1}$ the two lags are equal: that is where the convention $\alpha=2/(n+1)$ comes from.
Derivation. Substitute the recursion into itself: since $\text{EMA}_{t-1}=\alpha P_{t-1}+(1-\alpha)\text{EMA}_{t-2}$, $$\text{EMA}_t=\alpha P_t+\alpha(1-\alpha)P_{t-1}+(1-\alpha)^2\,\text{EMA}_{t-2},$$ and after $t$ steps the formula appears (formally, by induction). The weights sum to $\alpha\dfrac{1-(1-\alpha)^t}{1-(1-\alpha)}+(1-\alpha)^t=1$ by the geometric-series formula of §1.2. For the lag, differentiate the geometric series $\sum_{k\ge0}x^k=\frac1{1-x}$ to get $\sum_{k\ge1}kx^{k-1}=\frac1{(1-x)^2}$, so $\sum_k kx^k=\frac{x}{(1-x)^2}$; with $x=1-\alpha$, $\ \alpha\sum_k k(1-\alpha)^k=\alpha\cdot\frac{1-\alpha}{\alpha^2}=\frac{1-\alpha}{\alpha}$. For the SMA, $\frac1n(0+1+\cdots+(n-1))=\frac{n-1}{2}$. Finally, with $\alpha=\frac{2}{n+1}$, $\ \frac{1-\alpha}{\alpha}=\frac{(n-1)/(n+1)}{2/(n+1)}=\frac{n-1}{2}$. ∎
So an EMA never "forgets" a close completely — every past price keeps a small, geometrically shrinking weight — whereas an SMA forgets each close abruptly after $n$ days, which makes it jump when a large old move drops out of the window. The calculus link is explicit: the lag of the EMA is computed by differentiating a geometric series.
| day | 5 | 6 | 7 | 8 | 9 | 10 |
|---|---|---|---|---|---|---|
| close | 512 | 509 | 515 | 520 | 516 | 522 |
| SMA₅ | 504.80 | 506.60 | 508.80 | 512.60 | 514.40 | 516.40 |
| EMA₅ | 504.80 | 506.20 | 509.13 | 512.76 | 513.84 | 516.56 |
Lag and smoothness are two sides of one coin. Two simple models of a price make the trade-off precise: a straight-line trend, and a smooth level plus independent day-to-day noise.
Let $M_t=\sum_k w_kP_{t-k}$ be a weighted moving average (weights $w_k\ge0$, $\sum_kw_k=1$) with lag $L=\sum_kk\,w_k$.
- Trend. If the price is a straight line, $P_t=a+bt$, then $M_t=P_t-bL$: the average runs parallel to the price, $bL$ rupees behind it — below a rising price, above a falling one. Equivalently, it shows where the price was $L$ days ago.
- Noise. If $P_t=m_t+\varepsilon_t$, where the noise terms $\varepsilon_t$ are independent with mean $0$ and variance $\sigma^2$, then the noise left in $M_t$ has variance $\sigma^2\sum_kw_k^2$. For the $n$-day SMA this is $\sigma^2/n$; for the EMA it is $\sigma^2\,\frac{\alpha}{2-\alpha}$, which equals $\sigma^2/n$ when $\alpha=\frac2{n+1}$.
- Best $n$-day smoother. Among all weightings of the last $n$ closes, the SMA leaves the least noise: $\sum_{k\lt n}w_k^2\ge\frac1n$.
So halving the noise standard deviation requires four times the window, $n\to4n$, which roughly quadruples the lag $(n-1)/2$. No choice of weights escapes this trade-off for long.
Why. (1) $\sum_kw_k(a+b(t-k))$ $=(a+bt)\sum_kw_k-b\sum_kkw_k$ $=P_t-bL$. (2) The noise part of $M_t$ is $\sum_kw_k\varepsilon_{t-k}$, and the variance of a sum of independent terms is the sum of the variances: $\sum_kw_k^2\sigma^2$. For the SMA, $n\cdot\frac{1}{n^2}=\frac1n$. For the EMA, $\sum_k\alpha^2(1-\alpha)^{2k}=\frac{\alpha^2}{1-(1-\alpha)^2}=\frac{\alpha}{2-\alpha}$, and with $\alpha=\frac2{n+1}$ this is $\frac{2/(n+1)}{2n/(n+1)}=\frac1n$. (3) By the Cauchy–Schwarz inequality, $1=\left(\sum_{k\lt n}w_k\cdot1\right)^2\le n\sum_{k\lt n}w_k^2$. ∎
The conventional EMA therefore has the same average lag and the same noise reduction as the SMA of the same "length". What differs is the shape of the response: the EMA reacts more on the first day of a move (weight $\alpha=\frac2{n+1}$ on today, against $\frac1n$) but approaches a new level only gradually, while the SMA arrives at a new level exactly $n$ days after a jump. Interactive 1 shows both.
Crossovers and Momentum Oscillators: MACD and RSI
Most indicator "signals" are built from two ingredients: the difference between a faster and a slower average (crossovers, MACD), and the balance between up-moves and down-moves (RSI). Both turn out to be estimates of the recent slope of the price — its rate of change.
Let $F_t$ and $S_t$ be a fast and a slow moving average (shorter and longer lag), and $D_t=F_t-S_t$. A bullish crossover occurs on day $t$ if $D_{t-1}\le0\lt D_t$ (the fast average moves above the slow one); a bearish crossover if $D_{t-1}\ge0\gt D_t$. Taking the price itself as the "fast average" ($n=1$) gives the price–MA crossover.
A bullish crossover of the 50-day SMA above the 200-day SMA is commonly called a golden cross, and the bearish one a death cross. Some traders use other pairs, such as 20/50 days; the mathematics is the same.
With $\text{EMA}^{(n)}$ the $n$-day EMA of the closes, the MACD line (moving-average convergence–divergence) is $\text{MACD}_t=\text{EMA}^{(12)}_t-\text{EMA}^{(26)}_t$; the signal line is the 9-day EMA of the MACD line; and the MACD histogram is MACD minus signal. "MACD crossing above its signal line" is a crossover in the sense of Definition 7.3 applied to the MACD series. The parameters (12, 26, 9) are a convention, not a law.
On a straight-line trend $P_t=a+bt$ (after start-up effects have died out), by Theorem 7.2(1), $$D_t=F_t-S_t=b\,(L_S-L_F),$$ a positive multiple of the slope $b$. For two SMAs, $D_t=b\,\frac{n_S-n_F}{2}$; for the standard MACD, $\text{MACD}_t=b\,\frac{26-12}{2}=7b$, and the signal line is also $7b$, so the histogram is $0$. Hence:
- The sign of $D_t$ (or of the MACD) estimates the sign of the recent slope, and $\text{MACD}/7$ estimates the slope itself in rupees per day — a smoothed derivative of the price.
- A crossover says "the estimated slope has just changed sign". Because both averages lag, it arrives after the turn has happened, typically by a large fraction of the slow average's lag.
- The MACD histogram is the difference between the slope estimate and its own smoothed value, so it reacts to a change in slope — a smoothed second derivative. It turns first, and on noisy prices it also flips most often.
Nothing here says that a change in the past slope predicts the future slope. That is an empirical question about the price process, and §4 of this page shows what happens when the answer is "it doesn't".
Let $\Delta_t=P_t-P_{t-1}$ be the daily change, with gain $g_t=\max(\Delta_t,0)$ and loss $\ell_t=\max(-\Delta_t,0)$ (both $\ge0$). Over a window of $n$ days (usually $n=14$) let $\text{AG}_t$ and $\text{AL}_t$ be the average gain and average loss. The relative strength is $\text{RS}_t=\text{AG}_t/\text{AL}_t$ and $$\text{RSI}_t=100-\frac{100}{1+\text{RS}_t}=100\,\frac{\text{AG}_t}{\text{AG}_t+\text{AL}_t}.$$
The first averages are simple averages over $n$ days; after that, the standard (Wilder) method smooths them as $\text{AG}_t=\frac{(n-1)\text{AG}_{t-1}+g_t}{n}$, and likewise for $\text{AL}_t$ — an EMA with $\alpha=\frac1n$ (equivalent, by Theorem 7.1, to an EMA of "length" $2n-1=27$ days for $n=14$). Readings above 70 are conventionally called "overbought" and below 30 "oversold".
- $0\le\text{RSI}\le100$, and RSI is simply the percentage of the recent total movement ($\text{AG}+\text{AL}$) that was upward. $\text{RSI}=50$ exactly when average gain equals average loss.
- $\text{RSI}\ge70\iff\text{AG}\ge\frac73\text{AL}$, and $\text{RSI}\le30\iff\text{AL}\ge\frac73\text{AG}$: "oversold" means only that recent losses averaged at least $2\tfrac13$ times recent gains.
- On a driftless random walk with symmetric steps, $\text{AG}$ and $\text{AL}$ have the same mean, the RSI fluctuates around 50, and it still spends a definite fraction of days below 30 and above 70 — in our simulated market (daily volatility $18\%/\sqrt{252}$) the 14-day Wilder RSI was below 30 on about 4.6% of days. Such readings are produced by chance alone.
Why. Write $\text{RS}=x\ge0$: $100-\frac{100}{1+x}=\frac{100x}{1+x}=100\frac{\text{AG}}{\text{AG}+\text{AL}}$ after multiplying through by $\text{AL}$, which lies in $[0,100]$. For (2), $\frac{\text{AG}}{\text{AG}+\text{AL}}\ge0.7$ $\iff0.3\,\text{AG}\ge0.7\,\text{AL}$ $\iff\text{AG}\ge\frac73\text{AL}$. For (3), with symmetric steps a gain of size $x$ is exactly as likely as a loss of size $x$. ∎ The RSI is a momentum measure normalised to a 0–100 scale: like the MACD it describes the recent balance of up and down moves, which on a trend is again a slope estimate.
Volatility Bands, Support and Resistance
Bollinger bands put the standard deviation of §3.1 directly on the price chart. The middle line is a moving average; the bands are drawn a fixed number of standard deviations above and below it, so they widen when prices swing more and narrow when they are calm.
With window $n$ (usually 20) and multiplier $k$ (usually 2), let $M_t=\text{SMA}_n(t)$ and let $$s_t=\sqrt{\frac1n\sum_{j=0}^{n-1}\left(P_{t-j}-M_t\right)^2}$$ be the (population) standard deviation of the last $n$ closes. The upper and lower bands are $M_t\pm k\,s_t$.
The position of the close inside the bands is $\%b_t=\dfrac{P_t-(M_t-ks_t)}{2ks_t}$ ($0$ at the lower band, $1$ at the upper band, outside $[0,1]$ beyond them), and the bandwidth is $\dfrac{2ks_t}{M_t}$, the width of the band as a fraction of the price.
- A guarantee for any data (Chebyshev). Within the window itself, at most $n/k^2$ of the $n$ closes lie $k$ or more standard deviations from $M_t$ — at most 5 of 20 for $k=2$.
- No "95% rule" for prices. If closes were independent normal draws around a fixed level, a new close would fall outside $\pm2$ standard deviations only about 4.6% of the time. Prices are not like that: they wander, so the window's own mean is a moving target. In our simulated random-walk market the close was above the upper band on about 6.1% of days and below the lower band on about 5.7% — roughly one day in eight outside the bands, by pure chance.
- Bandwidth measures volatility. For a driftless random walk with daily price changes of standard deviation $\sigma_P$ rupees, the average of $s_t^2$ over many windows is $$E[s_t^2]=\sigma_P^2\,\frac{n^2-1}{6n},$$ so for $n=20$ the typical $s_t$ is about $\sqrt{3.325}\approx1.82$ daily standard deviations.
Why. (1) If $m$ of the $n$ closes are at distance at least $ks_t$, they alone contribute at least $m\,k^2s_t^2$ to the sum $\sum_j(P_{t-j}-M_t)^2=ns_t^2$, so $m\le n/k^2$. (2) $P(|Z|\gt2)=2(1-\Phi(2))\approx0.0455$ for a standard normal $Z$; the random-walk figures are from a seeded simulation of 2,000 years of daily prices. (3) Write the window's closes as $Y_j=Y_0+X_1+\cdots+X_j$ ($j=1,\dots,n$) with independent steps of variance $\sigma_P^2$. Then $E\left[\frac1n\sum_jY_j^2-\bar Y^2\right]$ (the shift $Y_0$ cancels) equals $$\frac{\sigma_P^2}{n}\sum_j j-\frac{\sigma_P^2}{n^2}\sum_{i,j}\min(i,j),$$ and with $\sum_jj=\frac{n(n+1)}2$ and $\sum_{i,j}\min(i,j)=\frac{n(n+1)(2n+1)}{6}$ this is $$\sigma_P^2\left[\frac{n+1}{2}-\frac{(n+1)(2n+1)}{6n}\right]=\sigma_P^2\,\frac{n^2-1}{6n}.$$ ∎
So the bands are a useful volatility gauge — a narrow band ("squeeze") means the last month was calm, a wide one that it was wild, which matters for where to put a stop-loss and how much to buy (§7.2). What they are not is a probability statement about the next close.
Support and resistance (descriptive). Chartists draw horizontal lines at price levels where a share previously stopped falling (support) or stopped rising (resistance) — earlier lows and highs, round numbers such as ₹1,000, the level of a big past gap. Mathematically these are just past local minima and maxima. They may matter in practice because many traders place orders near the same visible levels and round numbers. But they also appear in data that have no memory at all: a driftless random walk keeps returning close to levels it has visited before, so every simulated chart shows "tested support" and "rejected resistance". A line on a chart is a description; whether price behaviour near it differs from behaviour elsewhere is a statistical question, answered with the method of the next subsection.
What Indicators Can and Cannot Do: Signals on Random Data
Every indicator above is a function of past prices only. That single fact settles what they can do in a market where the future is independent of the past — and tells us exactly what must be true of a real market for an indicator to have an edge.
Suppose the price changes after day $t$ (or the log returns, for a lognormal random walk as in §3.3) are independent of all prices up to day $t$, with the same distribution every day. Let a signal be any rule that decides whether it fires on day $t$ using only $P_0,\dots,P_t$ — an MA crossover, an RSI level, a band touch, a chart pattern, or any combination. Then for every horizon $h$, the forward return $R_{t,h}=P_{t+h}/P_t-1$ has the same distribution on days when the signal fires as on any day. In particular $$E[R_{t,h}\mid\text{signal on day }t]=E[R_{t,h}],$$ which is $0$ in a driftless market and $e^{\mu h}-1$ under geometric Brownian motion with drift $\mu$ per day — the same as buying on a random day.
Proof. $R_{t,h}=\prod_{j=1}^h(1+r_{t+j})-1$ depends only on the returns $r_{t+1},\dots,r_{t+h}$ after day $t$, while the event "the signal fires on day $t$" depends only on prices up to day $t$. By assumption these are independent, and conditioning a random variable on an event independent of it does not change its distribution. ∎
The consequences are blunt. On a random walk every indicator — however clever — produces signals whose forward returns are indistinguishable from those of a coin-toss entry; any edge seen in a test on such data is either chance or a mistake (for example using a closing price that was not yet known when the signal fired, called look-ahead bias). Turned around: an indicator can only work if real returns are not independent of their past — for instance if trends persist (momentum) or overreactions reverse (mean reversion). Such effects have been studied extensively and, where they exist, tend to be small relative to noise and trading costs; whether one exists in your market, after costs, is a question for data and statistics, not for the shape of a chart.
What indicators can do. They describe the recent past compactly — a smoothed level (MA), a smoothed slope (MACD, crossovers, RSI) and the recent volatility (band width). Volatility, unlike direction, does tend to persist in real markets (calm and turbulent periods cluster), so volatility measures are genuinely useful for sizing positions and placing stops (§7.2). Indicators also turn a vague view into a precise, testable rule — which is exactly what makes the next box possible.
Suppose a signal has fired $N$ times, with forward returns that may be treated as independent, and the forward return on a random day has mean $m_0$ and "win" (rise) probability $p_0\approx\frac12$.
- Win rate. With no edge, the number of wins is $\text{Binomial}(N,p_0)$; the chance of $w$ or more wins by luck is $P(X\ge w)=\sum_{j\ge w}\binom Nj p_0^j(1-p_0)^{N-j}$.
- Average return. With sample mean $\bar R$ and standard deviation $s$, the statistic $t=\dfrac{\bar R-m_0}{s/\sqrt N}$ should be roughly beyond $\pm2$ before the difference is taken seriously. Detecting a true edge $\delta$ per signal therefore needs about $N\approx(2s/\delta)^2$ signals.
- Many tries. If $K$ unrelated rules (or stocks, or parameter settings) are each tested at significance level $a$, the chance that at least one passes by luck is $1-(1-a)^K$ — for $K=20$ and $a=5\%$ about $64\%$.
Forward windows that overlap (two signals within $h$ days of each other) share returns, so the effective $N$ is smaller than the count of signals and the evidence weaker than the formulas suggest.
These are the binomial and $t$-test ideas of school and college statistics, applied to trading records; §7.3 develops them for whole strategies (bootstrap, in-sample vs out-of-sample, data snooping).
- Write the rule down before looking at results: indicator, parameters, exactly when it fires, holding period $h$. Use only information available at the moment of the signal.
- Compute the forward return $R_{t,h}$ after every signal, and also on every day (the baseline).
- Compare the mean and win rate after signals with the baseline, with standard errors (Theorem 7.7). Count signals, not stocks or years.
- Subtract costs: brokerage, taxes and charges, the bid–ask spread (§2.1) and slippage, for every round trip.
- Count your tries. If you tried many rules or parameters, adjust for it — or, better, confirm the chosen rule on data you did not use to choose it (§7.3).
- Run the same test on simulated random walks. If the "edge" appears there too, it is an artefact of the method.
| signal | signals | mean 10-day return | its SE | share followed by a rise |
|---|---|---|---|---|
| 20-day SMA crosses above 50-day | 5,616 | −0.008% | 0.047% | 49.4% |
| RSI(14) falls below 30 | 6,656 | +0.006% | 0.044% | 49.1% |
| close falls below lower Bollinger band | 14,862 | +0.031% | 0.029% | 49.9% |
| MACD crosses above signal line | 20,423 | −0.009% | 0.025% | 49.1% |
| every day (baseline) | 500,000 | +0.006% | 0.005% | 49.2% |
- "A golden cross means the price will rise." It means the average slope over the past months has turned positive. It is a delayed description of the past (Theorem 7.3); whether it predicts anything must be tested.
- "RSI above 70 means overbought — it must fall." It means recent gains averaged at least $2\tfrac13$ times recent losses. Strong trends can keep the RSI above 70 for weeks, and on a random walk such readings carry no information at all.
- "The EMA has less lag than the SMA." With the standard $\alpha=2/(n+1)$ both have the same average lag $(n-1)/2$ and the same noise reduction (Theorems 7.1–7.2). The EMA reacts more on day one — so at a sharp peak it turns sooner (Interactive 1) — but approaches a new level more slowly; it is a different shape of the same trade-off, not a free lunch.
- "A close outside the Bollinger band is a 5% event, so it will snap back." The 95% figure assumes independent normal data around a fixed level. Wandering prices close outside 2-SD bands on roughly one day in eight even in a pure random walk (Theorem 7.5).
- "Look how well the signals line up with the turns." Signals are drawn on a chart you already know. Because every indicator lags, the impressive-looking ones are judged with hindsight; the honest test is the forward return after each signal versus the baseline.
- "9 out of 12 is 75% accuracy." A coin produces 9 or more out of 12 about 7% of the time, and among 20 channels one will almost surely do so (Example 7).
- "Tune the parameters until the backtest works." Trying many settings and keeping the best is the multiple-testing trap of Theorem 7.7(3); the best setting on past data is usually just the luckiest (§7.3).
- Ignoring costs. A rule that trades often pays costs on every round trip, while its edge (if any) is small; a zero-edge rule always loses after costs.
- "Charts show trends and support levels, so prices can't be random." Simulated random walks show trends, double tops, support and resistance too. Patterns on a chart are not evidence of predictability.
Karan decides to test the channel's favourite rule properly, on simulated data first: "Buy when the 20-day SMA crosses above the 50-day SMA; sell when it crosses back below; otherwise stay in cash." He uses the 2,000-year random-walk simulation of Example 8 (no drift, volatility 18% a year) and an illustrative total cost of 0.2% of the trade value per round trip (brokerage, taxes and charges, spread and slippage together — check your own broker's charges).
- Trading frequency. The rule completed 5,848 round trips in 2,000 simulated years: about 2.9 trades a year.
- Win rate and payoff. Only 35.2% of the trades made money — most crossovers on a random walk are quickly reversed ("whipsaws") — but the winners were larger than the losers. The average trade returned −0.05%, indistinguishable from the zero that Theorem 7.6 requires.
- Costs. At 0.2% per round trip and 2.9 trades a year, costs take about $2.9\times0.2\%\approx0.58\%$ of capital a year. A rule with zero edge before costs is a rule with a certain loss after costs.
- How much real data would be needed? Suppose the rule had a genuine edge of 0.3% per 10-day signal in a real market. With a per-signal standard deviation of about 3.55%, Theorem 7.7(2) says detecting it needs about $(2\times3.55/0.3)^2\approx560$ signals; at 2.8 signals a year on one share that is about 200 years of data. Testing many shares at once helps, but their returns are correlated (§3.2), so they are not independent evidence.
- What Karan concludes. On data with no memory the rule has no edge, a low win rate and a steady cost drag. On real data he must look for an edge well above costs, confirmed on data not used to choose the rule (§7.3). Meanwhile, whatever rule he uses, the size of each position decides whether he survives its losing streaks (§7.2).
The general lesson. An indicator is a precise way to describe the recent past and to state a trading rule. Whether the rule makes money is a separate, statistical question — and the honest default answer, until the data say otherwise, is "no better than chance, minus costs".
Exercises
All prices are hypothetical or simulated; "day" means trading day. Give rupee answers to two decimals where needed.
- 1 Closes: ₹240, 244, 239, 247, 250, 246. Find the 3-day SMA on days 3–6.
- 2 Find $\alpha$ for the conventional 10-, 20-, 50- and 200-day EMAs.
- 3 Yesterday's 19-day EMA was ₹1,250 and today's close is ₹1,280. Find today's EMA.
- 4 For the 9-day EMA ($\alpha=0.2$), list the weights on today and the four previous days, and the total weight on the last five days.
- 5 How many of the most recent days carry half of the total weight of a 20-day EMA?
- 6 A share rises steadily by ₹1.20 a day. How far below the price is its 50-day SMA?
- 7 Show that the linearly weighted average with weights proportional to $n,n-1,\dots,1$ (today first) has lag $(n-1)/3$. Evaluate for $n=10$ and compare with the 10-day SMA.
- 8 Closes are a trend plus independent noise with SD ₹8. What noise SD is left in a 25-day SMA? What SMA length leaves ₹1, and with what lag?
- 1 Over 14 days the average gain is ₹1.80 and the average loss ₹1.20. Find RS and RSI.
- 2 What ratio AG/AL corresponds to RSI = 30? To RSI = 80?
- 3 Yesterday AG = 2.0 and AL = 1.5 (14-day Wilder). Today the price falls by ₹3.20. Find the new AG, AL and RSI.
- 4 A share rises steadily by ₹2.50 a day. What value does the standard MACD settle to? A MACD built from 5- and 35-day EMAs?
- 5 A price falls by ₹1 a day to a low on day 0 and then rises by ₹1 a day. On which day does the 10-day SMA first close above the 30-day SMA? (Compute the two averages on days 12 and 13.)
- 6 A share has been falling by ₹0.80 a day. Find the gap "20-day SMA minus 50-day SMA" and its sign.
- 7 Explain in two sentences why an RSI of 85 does not, by itself, imply that the price is likely to fall.
- 1 The 20-day SMA is ₹1,000 and the 20-day SD is ₹15. Find the 2-SD bands, %b for a close of ₹1,021, and the bandwidth.
- 2 If closes really were independent normal draws around a fixed level, on how many of 252 days would you expect a close outside 2-SD bands?
- 3 Using Chebyshev's argument, at most how many of the 20 closes in a window can be 2 or more SDs from the mean? 3 or more SDs?
- 4 A share at ₹800 has daily price changes with SD about 1.5% of the price. Using Theorem 7.5(3), estimate the typical 20-day SD $s_t$ and the width of the 2-SD band in rupees.
- 5 The band width halves over a month. What does that tell you about the share, and what does it not tell you?
- 6 A channel says "touching the lower band is a buy". Describe precisely how you would test this rule on 10 years of one share's daily closes.
- 1 A rule's last 20 signals produced 14 rises. With $p_0=\frac12$, find the chance of 14 or more by luck.
- 2 Over 36 signals the mean 10-day return was 0.4% with SD 3%, against a baseline of 0%. Compute $t$. Is this convincing?
- 3 How many independent signals are needed to detect a true edge of 0.2% per signal when the SD per signal is 3%?
- 4 A trader tests 30 unrelated indicator settings at the 5% level. Find the chance that at least one looks "significant" by luck.
- 5 A rule makes 24 round trips a year at an illustrative cost of 0.15% per round trip. What is the annual cost drag?
- 6 Why do overlapping forward-return windows make a signal's record look more convincing than it is?
E1. NISM-style Using the convention $\alpha=2/(n+1)$, the smoothing constant of a 19-day exponential moving average is (A) 0.05 (B) 0.0526 (C) 0.10 (D) 0.19.
E2. NISM-style Over the RSI window the average gain is ₹1.50 and the average loss ₹0.50. The RSI is (A) 25 (B) 66.7 (C) 75 (D) 300.
E3. NISM-style A share's 20-day SMA is ₹2,400 and the standard deviation of its last 20 closes is ₹30. With the usual settings its upper Bollinger band is (A) ₹2,430 (B) ₹2,460 (C) ₹2,490 (D) ₹3,000.
E4. Case study Six closes of a hypothetical share are ₹100, 104, 108, 106, 101, 97. (a) Compute the 3-day SMA on days 3–6. (b) Compute an EMA with $\alpha=0.5$ started at $\text{EMA}_1=100$. (c) On which day does the price first close below its 3-day SMA, and on which day does the EMA first fall? (d) Relate the delays to the lags of the two averages.
E5. Case study A strategy vendor shows a backtest of "buy when RSI(14) falls below 30, sell 10 days later" on one share: 40 trades, average return per trade 0.9%, SD 4.5%, 26 winners. Costs are an illustrative 0.2% per round trip. (a) Compute $t$ for the average return before and after costs (baseline 0). (b) Compute the chance of 26 or more winners out of 40 for a coin. (c) The vendor tried 15 indicator–share combinations and showed you the best. Re-assess. (d) What would you ask for?
E6. Interview "Why is an $n$-day EMA conventionally given $\alpha=2/(n+1)$, and not $1/n$?"
Suggested plan — 2 lectures × 60 min.
- Indicators are formulas. Open with Karan's app screen and ask what each line computes. SMA and EMA (Definitions 7.1–7.2), Example 1 on the board, then Theorem 7.1 with the geometric-series derivation of the lag — the "why $2/(n+1)$" moment. Theorem 7.2 with Examples 2–3. Project Interactive 1 on "turning point" and sweep $n$: students predict the delay before it appears; then switch to "step" to contrast the SMA's straight ramp with the EMA's curve. Crossovers and MACD as slope estimates (Theorem 7.3, Example 4).
- Oscillators, bands and the honest test. RSI (Definition 7.5, Theorem 7.4, Example 5) and Bollinger bands (Definition 7.6, Theorem 7.5, Example 6). Then the core: Theorem 7.6 and its one-line proof. Project Interactive 2 and let it run for a few hundred simulated years with each rule; ask why the purple and outlined histograms merge. Example 7 ("9 out of 12") and Theorem 7.7; finish with the 📈 Market case and Practice corner E5.
Class activity. Each student tosses a coin 60 times to build a "price" (+₹1 for heads, −₹1 for tails), computes a 5-day SMA and marks every price–SMA crossover, then records the next 5 tosses after each crossover. Pool the class's results on the board: the share of rises after crossovers comes out close to 50%.
Discussion questions. (1) If indicators cannot predict a random walk, why are they on every trading screen? (2) What property of real returns would an indicator need in order to work, and how could you test for it? (3) Is a volatility measure useful even if direction is unpredictable?
Misconceptions to watch for. "EMA has no lag"; reading "overbought/oversold" as forecasts; treating Bollinger bands as 95% intervals; judging signals by looking at a chart; trusting small win-rate records; forgetting costs and the number of rules tried.
Suggested homework. I(3, 5, 7, 8), II(3, 4, 5), III(1, 4, 6), IV(1, 2, 3, 4); Practice corner E4, E5.
Project. Build an "indicator lab" sheet: simulate a random-walk price, compute SMA, EMA, RSI and Bollinger bands with ordinary formulas, generate signals, and measure the forward returns after them against every day.
Why it matters. Once you have computed an indicator yourself it stops being a mysterious line on a screen. And testing on data you know to be random is the quickest way to learn how convincing pure chance can look.
What to do.
- Price. In A2:A1001 put days 1–1000. B2:
1000; B3 (copy down):=B2*EXP(0.0113*NORM.S.INV(RAND()))— daily volatility $0.18/\sqrt{252}\approx1.13\%$. Paste as values to freeze one path (or keep it live to redraw). - Averages. C21:
=AVERAGE(B2:B21)(20-day SMA), copy down; D51:=AVERAGE(B2:B51)(50-day). EMA in E2:=B2, E3:=2/21*B3+(1-2/21)*E2. - RSI. F3:
=MAX(B3-B2,0), G3:=MAX(B2-B3,0). H16:=AVERAGE(F3:F16), I16:=AVERAGE(G3:G16); H17:=(13*H16+F17)/14, I17 likewise; RSI in J16:=100*H16/(H16+I16). - Bands. K21:
=C21-2*STDEV.P(B2:B21), L21:=C21+2*STDEV.P(B2:B21). - Signals and forward returns. Golden cross in M52:
=AND(C52>D52,C51<=D51); 10-day forward return in N2:=B12/B2-1. Compare=AVERAGEIF(M52:M990,TRUE,N52:N990)with=AVERAGE(N52:N990), and count signals with=COUNTIF(M52:M990,TRUE). Do the same for RSI and band signals. - Press F9 (recalculate) twenty times and record the signal mean each time. How much does it jump around? How does that compare with the SE $s/\sqrt N$?
Python version: p = 1000*np.exp(np.cumsum(0.0113*rng.standard_normal(n))); s = pd.Series(p); sma20 = s.rolling(20).mean(); ema20 = s.ewm(span=20, adjust=False).mean() (span $n$ means $\alpha=2/(n+1)$); fwd = s.shift(-10)/s - 1; sig = (sma20 > sma50) & (sma20.shift() <= sma50.shift()); compare fwd[sig].mean() with fwd.mean().
Hand in: a chart of price, SMAs and bands with the signals marked; a table of signal count, mean forward return, its SE and win rate for each rule versus every day; and one paragraph on what the table shows.
Going further. Replace the simulated price by the daily closes of a broad index downloaded from the exchange's website, rerun the table, and decide whether any difference is larger than two standard errors — and whether it would survive realistic costs.
🧪 Self-check quiz
Q1. With the convention $\alpha=2/(n+1)$, a 39-day EMA has smoothing constant
Q2. A price rises steadily by ₹4 a day. Its 20-day SMA lies below the price by
Q3. The RSI equals exactly 50 when
Q4. In a simulated driftless random walk, the expected 10-day return after a golden cross is
Q5. The 20-day SMA is ₹500 and the 20-day standard deviation ₹12. The lower Bollinger band (k = 2) is