Chapter 7 · The Mathematics of Trading

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.

⚠️ About the numbers on this page

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).

📘 Definition 7.1 — Simple moving average (SMA)

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}$.

📘 Definition 7.2 — Exponential moving average (EMA)

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.

📐 Theorem 7.1 (Formula) — The EMA is a weighted average with geometric weights

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.

✏️ Example 1 — A 5-day SMA and a 5-day EMA by hand
Alpha Bank's hypothetical closes over ten trading days are ₹500, 504, 501, 507, 512, 509, 515, 520, 516, 522. Compute the 5-day SMA and the 5-day EMA ($\alpha=\frac{2}{6}=\frac13$, started from the SMA on day 5) for days 5–10.
SMA Day 5: $(500+504+501+507+512)/5=504.80$. Day 6 drops 500 and adds 509: $504.80+(509-500)/5=506.60$. Continuing: 508.80, 512.60, 514.40, 516.40.
EMA Start $\text{EMA}_5=504.80$. Day 6: $\tfrac13(509)+\tfrac23(504.80)=506.20$. Day 7: $\tfrac13(515)+\tfrac23(506.20)=509.13$. Then 512.76, 513.84, 516.56.
day5678910
close512509515520516522
SMA₅504.80506.60508.80512.60514.40516.40
EMA₅504.80506.20509.13512.76513.84516.56
Observe Both averages sit below the price throughout: the price is rising, and an average of older, lower prices must lag behind. On day 9 (a down day) the EMA dips more than the SMA, because it puts weight $\frac13$ on today, against $\frac15$ for the SMA.
Check The EMA weights on days 10, 9, 8, … are $\frac13,\frac29,\frac4{27},\dots$; their average age is $(1-\alpha)/\alpha=2$ days — exactly the SMA's $(5-1)/2=2$ days (Theorem 7.1).

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.

📐 Theorem 7.2 (Rule) — Lag on a trend, and noise reduction

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$.

  1. 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.
  2. 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}$.
  3. 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.

✏️ Example 2 — How far behind is the average, and when does it turn?
(a) A share has been rising steadily by about ₹3 a day. How far below the price are its 20-day and 50-day SMAs? (b) A price falls by ₹2 a day to a low on day 0 and then rises by ₹2 a day (a "V"). On which day does the 10-day SMA reach its lowest value? The 20-day SMA?
(a) By Theorem 7.2(1) the gap is $bL=b\,\frac{n-1}2$: for the 20-day SMA $3\times9.5=$ ₹28.50, for the 50-day SMA $3\times24.5=$ ₹73.50. A 20-day EMA would also be ₹28.50 behind once its starting value has been forgotten.
(b) Write $P_s=c+2|s|$. The $n$-day SMA on day $t$ averages $P$ over days $t-n+1,\dots,t$; that average of $|s|$ is smallest when the window is centred on the low, i.e. when $t-\frac{n-1}2=0$. For $n=10$, $t=4.5$: days 4 and 5 tie, both with SMA $=c+5$. For $n=20$, days 9 and 10 tie at $c+10$.
Interpret The average turns about $(n-1)/2$ days after the price — the same lag as in (a). A 50-day SMA turns about 24–25 trading days, more than a calendar month, after the low. Any rule that waits for the average to turn gives up that part of the move.
✏️ Example 3 — How much noise does a 20-day average remove?
Model a share's closes as a smooth trend plus independent daily noise with standard deviation ₹6. How large is the noise left in (a) a 20-day SMA, (b) a 20-day EMA? (c) How long an SMA would leave noise of only ₹0.60, and what would its lag be?
(a) $\sigma/\sqrt n=6/\sqrt{20}\approx$ ₹1.34.
(b) $\alpha=\frac2{21}$, $\frac{\alpha}{2-\alpha}=\frac{2/21}{40/21}=\frac1{20}$: the same ₹1.34 — and the same lag, 9.5 days.
(c) We need $6/\sqrt n=0.6$, so $\sqrt n=10$ and $n=100$ days, with lag $99/2=49.5$ trading days — about ten weeks. Ten times less noise costs about ten weeks of delay.
Interactive 1 — The Moving-Average Filter Lab: Smoothness Costs Lag

Choose a test price and a length $n$. The grey line is the price, the blue line its $n$-day SMA and the green line its $n$-day EMA ($\alpha=2/(n+1)$). The small bars at the top show the weight each filter puts on each of the last days (today at the right): flat for the SMA, geometric for the EMA. The "turning point" and "step" prices have no noise at all, so you can see the lag exactly; the random walk is simulated. Press Play to sweep $n$ from 5 to 80 and back.

20
EMA α = 2/(n + 1)—
average lag (both)—
noise SD left (both)—
half the EMA weight is in the last—
measured on this price—

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.

📘 Definition 7.3 — Crossovers

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.

📘 Definition 7.4 — MACD

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.

📐 Theorem 7.3 (Rule) — A crossover is a delayed estimate of the slope

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:

  1. 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.
  2. 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.
  3. 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".

✏️ Example 4 — MACD on a trend that turns
A hypothetical share rises by exactly ₹1.50 a day for many months and then, from day 0, falls by exactly ₹1 a day. (a) What are the MACD, signal and histogram during the rise? (b) What do they settle to during the fall? (c) A numerical computation of the EMAs shows that the histogram turns negative 1 day after the peak and the MACD line crosses zero 19 days after it. Explain the order of events.
(a) Lags: 12-day EMA $5.5$ days, 26-day EMA $12.5$ days. MACD $=1.5\times(12.5-5.5)=10.5$; the signal line, an average of a constant, is also $10.5$; histogram $0$.
(b) With slope $-1$: MACD $\to-7$, signal $\to-7$, histogram $\to0$.
(c) After the peak the short EMA starts falling first, so the MACD line starts to decrease at once; the signal line, an average of past MACD values, is still near $10.5$, so the histogram goes negative almost immediately (day 1) — it responds to the change in slope. The MACD line itself, a slope estimate, must travel from $+10.5$ to $-7$ and passes zero only on day 19; a "MACD below zero" trader learns of the turn nearly four trading weeks late.
Moral On a clean turn the histogram is quick. On real or simulated noisy prices it is quick to turn at every wiggle, too — the speed of a signal and its reliability are traded against each other, as in Theorem 7.2.
📘 Definition 7.5 — Relative strength index (RSI)

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".

📐 Theorem 7.4 (Rule) — What an RSI value means
  1. $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.
  2. $\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.
  3. 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.

✏️ Example 5 — Computing a 14-day RSI
Alpha Bank's last 14 daily changes (in ₹) were $+4,-2,+3,+5,-3,+6,+5,-4,+6,-2,-6,-3,+2,-5$. (a) Find AG, AL, RS and the 14-day RSI (simple averages). (b) Using Wilder smoothing, find the RSI after a next-day change of $+3$, and after a next-day change of $-7$ instead.
(a) Gains: $4+3+5+6+5+6+2=31$; losses: $2+3+4+2+6+3+5=25$. $\text{AG}=31/14\approx2.2143$, $\text{AL}=25/14\approx1.7857$, $\text{RS}=31/25=1.24$, $\text{RSI}=100\times\frac{31}{56}\approx55.36$.
(b) +3 $\text{AG}=\frac{13(2.2143)+3}{14}\approx2.2704$, $\text{AL}=\frac{13(1.7857)}{14}\approx1.6582$; $\ \text{RSI}=100\times\frac{2.2704}{3.9286}\approx57.79$.
(b) −7 $\text{AG}=\frac{13(2.2143)}{14}\approx2.0561$, $\text{AL}=\frac{13(1.7857)+7}{14}\approx2.1582$; $\ \text{RSI}\approx48.79$.
Interpret The price rose ₹6 in 14 days and the RSI is a little above 50; one ₹7 fall moves it by more than 6 points. The RSI says nothing about tomorrow — it is a summary of the last few weeks.

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.

📘 Definition 7.6 — Bollinger bands, %b and bandwidth

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.

📐 Theorem 7.5 (Rule) — What the bands can and cannot say
  1. 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$.
  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.
  3. 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.

✏️ Example 6 — A Bollinger band by hand
To keep the arithmetic short use a 10-day window with $k=2$. The last ten closes of a hypothetical share are ₹1,012, 1,018, 1,009, 1,003, 1,015, 1,024, 1,020, 1,011, 1,026, 1,032. Find the middle line, the bands, %b and the bandwidth for the last day. Is the share "overbought"?
Mean The sum is 10,170, so $M=1{,}017$. Deviations: $-5,1,-8,-14,-2,7,3,-6,9,15$.
SD Squares: $25+1+64+196+4+49+9+36+81+225=690$; $s=\sqrt{690/10}=\sqrt{69}\approx8.31$.
Bands Upper $1{,}017+16.61\approx$ ₹1,033.61, lower ₹1,000.39. $\%b=\frac{1{,}032-1{,}000.39}{33.23}\approx0.95$; bandwidth $\frac{33.23}{1{,}017}\approx3.27\%$.
Interpret The close is $(1{,}032-1{,}017)/8.31\approx1.8$ standard deviations above the 10-day mean — exactly what a rising price produces, since the mean lags (Theorem 7.2). "Near the upper band" describes the recent past; it is not a measurement of value and not a forecast of a fall.

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.

📐 Theorem 7.6 — No signal has an edge on a random walk

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.

📐 Theorem 7.7 (Rule) — Is a signal's record better than luck?

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$.

  1. 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}$.
  2. 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.
  3. 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).

🧭 How to test an indicator honestly
  1. 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.
  2. Compute the forward return $R_{t,h}$ after every signal, and also on every day (the baseline).
  3. Compare the mean and win rate after signals with the baseline, with standard errors (Theorem 7.7). Count signals, not stocks or years.
  4. Subtract costs: brokerage, taxes and charges, the bid–ask spread (§2.1) and slippage, for every round trip.
  5. 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).
  6. Run the same test on simulated random walks. If the "edge" appears there too, it is an artefact of the method.
✏️ Example 7 — "Our RSI calls worked 9 times out of 12"
The channel's last 12 "RSI below 30, buy" calls rose in the following week 9 times. (a) If each call were really a coin toss with $p_0=\frac12$, how likely is a record of 9 or more out of 12? (b) The channel's followers choose it from about 20 similar channels, each posting 12 calls. How likely is it that at least one of the 20 shows 9 or more out of 12 by luck? (c) What would you need to see?
(a) $P(X\ge9)=\frac{\binom{12}9+\binom{12}{10}+\binom{12}{11}+\binom{12}{12}}{2^{12}}=\frac{220+66+12+1}{4096}=\frac{299}{4096}\approx0.073$. About a 7% chance — not rare, and above the usual 5% threshold.
(b) $1-(1-0.073)^{20}\approx0.78$. With 20 channels it is likely that one of them has a record this good by luck — and that is the one people forward.
(c) A rule fixed in advance, a long record of all calls (not a selected stretch), returns compared with a random-entry baseline, costs subtracted, and a $t$-statistic well beyond 2. A dozen calls cannot separate a 55% rule from a 50% one: by Theorem 7.7(2) that takes hundreds of independent signals.
✏️ Example 8 — Four indicators on 2,000 simulated years
We simulated 400 independent five-year paths of a driftless random walk (lognormal daily returns with volatility 18% a year, 252 trading days a year) — 2,000 simulated years in all — and recorded the 10-day forward return after each signal. The results (a seeded Python simulation) were:
signalsignalsmean 10-day returnits SEshare followed by a rise
20-day SMA crosses above 50-day5,616−0.008%0.047%49.4%
RSI(14) falls below 306,656+0.006%0.044%49.1%
close falls below lower Bollinger band14,862+0.031%0.029%49.9%
MACD crosses above signal line20,423−0.009%0.025%49.1%
every day (baseline)500,000+0.006%0.005%49.2%
Interpret the table. Why is the baseline "share followed by a rise" below 50% when the mean return is zero?
Compare Each signal's mean differs from the baseline by less than about one standard error ($t$ between about $-0.6$ and $+0.9$), and the win rates agree within about one percentage point. This is what Theorem 7.6 predicts: the true difference is exactly zero and the table shows only sampling noise.
Signals feel meaningful The 10-day return after a signal has a standard deviation of about 3.6%, so individual signals are followed by large moves — some very large — in both directions. Looking at a few charts, it is easy to remember the striking successes.
Below 50% In a driftless lognormal market the mean of $P_{t+h}/P_t$ is $1$, but the median is $e^{-\sigma^2h/2}\lt1$ (the $\sigma^2/2$ correction of §3.3): rises are slightly less frequent than falls, and slightly larger on average.
Moral Thousands of signals were needed to pin each mean down to within ±0.05%. A trader with a few dozen signals has no statistical power to tell a working indicator from a random one.
Interactive 2 — Signals on Random Data: Does the Indicator Know Anything?

Every few moments the page simulates another five years of a random-walk price (volatility 18% a year) and applies the rule you choose. Top: the last year of the latest simulated path with the indicator and its buy signals (▲). Bottom: the distribution of the 10-day return after every signal so far (purple bars) against the distribution after every day (outline); the vertical lines are their means. Press Play and watch the two distributions merge as the simulated years pile up. Switch on a drift to see that a signal still only earns what a random day earns. (Simulated data only.)

simulated years—
signals—
mean 10-day return after signal—
mean 10-day return, every day—
difference in standard errors—
followed by a rise: signal · all—
⚠️ Common mistakes and myths
  1. "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.
  2. "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.
  3. "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.
  4. "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).
  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.
  6. "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).
  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).
  8. 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.
  9. "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.
📈 Market case — Karan tests the golden-cross rule before risking money

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).

  1. Trading frequency. The rule completed 5,848 round trips in 2,000 simulated years: about 2.9 trades a year.
  2. 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.
  3. 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.
  4. 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.
  5. 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.

I
Moving averages, weights and lag.
  • 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 Day 3: $(240+244+239)/3=241.00$; day 4: $243.33$; day 5: $245.33$; day 6: $247.67$.
2 $2/11\approx0.1818$, $2/21\approx0.0952$, $2/51\approx0.0392$, $2/201\approx0.00995$.
3 $\alpha=2/20=0.1$: $0.1(1{,}280)+0.9(1{,}250)=$ ₹1,253.
4 $0.2,\ 0.16,\ 0.128,\ 0.1024,\ 0.08192$; together $1-0.8^5=0.67232$, about two-thirds.
5 Solve $(1-\alpha)^k=\frac12$ with $\alpha=\frac2{21}$: $k=\frac{\log0.5}{\log(19/21)}\approx6.93$, so the last 7 days carry just over half the weight, although the average age is 9.5 days — the long tail of old weights pulls the average up.
6 $1.20\times\frac{49}{2}=$ ₹29.40.
7 Weights $w_k=\frac{n-k}{n(n+1)/2}$, $k=0,\dots,n-1$. $\sum_kk(n-k)=n\frac{n(n-1)}2-\frac{(n-1)n(2n-1)}6=\frac{n(n-1)(n+1)}6$, so $L=\frac{n(n-1)(n+1)/6}{n(n+1)/2}=\frac{n-1}3$. For $n=10$: 3 days, against 4.5 days for the SMA — but by Theorem 7.2(3) it leaves more noise ($\sum w_k^2=\frac{2(2n+1)}{3n(n+1)}=\frac{14}{110}\approx0.127\gt0.1$).
8 $8/\sqrt{25}=$ ₹1.60. For ₹1: $8/\sqrt n=1$, $n=64$ days, lag $31.5$ days.
II
Crossovers, MACD and RSI.
  • 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 $\text{RS}=1.5$, $\text{RSI}=100\times1.8/3.0=60$.
2 $\text{AG}/(\text{AG}+\text{AL})=0.3\iff\text{AG}/\text{AL}=3/7\approx0.43$; for 80, $\text{AG}/\text{AL}=4$.
3 $\text{AG}=13(2.0)/14\approx1.857$, $\text{AL}=(13(1.5)+3.2)/14\approx1.621$, $\text{RSI}=100\times1.857/3.479\approx53.39$.
4 $7\times2.50=17.50$. With 5 and 35: lags 2 and 17, so $15\times2.50=37.50$ — the size of a MACD depends on its parameters and on the price level, so MACD values of different shares are not comparable.
5 With $P_s=c+|s|$: day 12 — SMA₁₀ averages $|s|$ over $s=3,\dots,12$: $7.5$; SMA₃₀ over $s=-17,\dots,12$: $(153+78)/30=7.7$, still above. Day 13 — SMA₁₀: $8.5$; SMA₃₀: $(136+91)/30\approx7.57$. The crossover comes on day 13, 13 days after the low (and after a ₹13 rise).
6 $D=b\frac{n_S-n_F}{2}$ with $b=-0.8$: $-0.8\times\frac{30}{2}=-$₹12. Negative: the fast average is below the slow one, as it should be in a downtrend.
7 An RSI of 85 says that over the last few weeks gains averaged more than five times the losses — a description of past momentum. Whether high momentum is followed by falls, rises or nothing in particular is an empirical question; on a random walk it is followed by exactly the same distribution of returns as any other reading (Theorem 7.6).
III
Bollinger bands and volatility.
  • 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 Bands ₹970 and ₹1,030; $\%b=(1{,}021-970)/60=0.85$; bandwidth $60/1{,}000=6\%$.
2 $252\times0.0455\approx11.5$ days. (In our random-walk simulation the actual rate was about 11.8% of days, i.e. about 30 days a year.)
3 $20/2^2=5$ closes; $20/3^2\approx2.2$, so at most 2.
4 $\sigma_P\approx0.015\times800=$ ₹12; $s_t\approx1.82\times12\approx$ ₹21.8, so the band is about $4\times21.8\approx$ ₹87 wide (about ±5.5% of the price).
5 The last month's price swings were about half as large as before — a fact about recent volatility. It does not say which way the price will move next; a "squeeze" is followed by moves in either direction.
6 Fix the rule (e.g. "close crosses below the 20-day, 2-SD lower band; buy at the next day's open; hold 10 days"). For every signal record the 10-day forward return from the entry price; record the same for every day as the baseline. Compare means and win rates with standard errors, noting overlapping signals; subtract costs per trade; and repeat on simulated random walks with the same volatility to see what chance alone produces.
IV
Signals and statistics.
  • 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?
1 $P(X\ge14)=\sum_{j=14}^{20}\binom{20}{j}/2^{20}=60{,}460/1{,}048{,}576\approx0.058$ — about 6%, not significant at 5%.
2 $t=0.4/(3/\sqrt{36})=0.4/0.5=0.8$. Far from 2: the record is well within the range of luck.
3 $N\approx(2\times3/0.2)^2=900$ signals.
4 $1-0.95^{30}\approx0.785$ — more likely than not.
5 $24\times0.15\%=3.6\%$ of capital a year — larger than most plausible edges of a simple rule.
6 Two signals 3 days apart with 10-day horizons share 7 days of returns, so their outcomes are strongly correlated. Counting them as two independent pieces of evidence overstates $N$ and understates the standard error; the true evidence is closer to one signal.
🎯 Practice corner NISM-styleCase studyInterview

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.

Compute $2/(19+1)=0.10$. (B) is $1/19$, the SMA weight; (A) is $1/20$.
Answer (C).

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.

Compute $\text{RS}=3$, $\text{RSI}=100-100/4=75$. (D) is $100\times\text{RS}$; (A) is $100\,\text{AL}/(\text{AG}+\text{AL})$.
Answer (C).

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.

Compute $2{,}400+2\times30=2{,}460$. (A) uses one SD, (C) three.
Answer (B).

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.

(a) Day 3: $104$; day 4: $106$; day 5: $105$; day 6: $101.33$.
(b) $100,\ 102,\ 105,\ 105.5,\ 103.25,\ 100.125$.
(c) Day 4: close 106 = SMA 106 (not below). Day 5: close 101 below SMA 105 — the first price–MA crossover, two days after the peak on day 3. The EMA rises on day 4 (to 105.5) and first falls on day 5.
(d) The 3-day SMA has lag 1 day, and the EMA with $\alpha=\frac12$ has lag $(1-\alpha)/\alpha=1$ day (it is the "3-day EMA", $\alpha=2/4$). Both register the turn 1–2 days after it happened: the signal is a delayed description of the peak.

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?

(a) SE $=4.5/\sqrt{40}\approx0.712\%$. Before costs $t=0.9/0.712\approx1.26$; after costs $t=0.7/0.712\approx0.98$. Neither is near 2.
(b) $P(X\ge26\mid N=40,\ p=\tfrac12)\approx0.040$.
(c) The best of 15 tries: even if each combination had only a 4% chance of such a win record by luck, the chance that at least one of 15 does is $1-0.96^{15}\approx0.46$. The record is entirely consistent with no edge.
(d) All 15 results, not just the best; the rule's performance on a later period it was not chosen on; a comparison with random entry dates; and the count of overlapping trades. Until then, treat the edge as zero.

E6. Interview "Why is an $n$-day EMA conventionally given $\alpha=2/(n+1)$, and not $1/n$?"

Idea Match the average age of the data. The EMA's weights $\alpha(1-\alpha)^k$ have mean age $(1-\alpha)/\alpha$ (differentiate the geometric series); the $n$-day SMA's equal weights have mean age $(n-1)/2$.
Solve $(1-\alpha)/\alpha=(n-1)/2\iff2-2\alpha=n\alpha-\alpha\iff\alpha=2/(n+1)$.
Bonus The same $\alpha$ also gives the same noise variance, $\alpha/(2-\alpha)=1/n$. With $\alpha=1/n$ the EMA would have lag $n-1$, twice the SMA's — which is why Wilder's RSI smoothing with $\alpha=1/14$ behaves like a 27-day EMA.
🧑‍🏫 For the teacher

Suggested plan — 2 lectures × 60 min.

  1. 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).
  2. 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.

🛠️ Do it yourselfSpreadsheet or Python mini-project · about 60 minutes

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.

  1. 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).
  2. 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.
  3. 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).
  4. Bands. K21: =C21-2*STDEV.P(B2:B21), L21: =C21+2*STDEV.P(B2:B21).
  5. 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.
  6. 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.

Instructor note: with 1,000 simulated days a 20/50 crossover fires only about 10 times, so the signal means swing by several percent between recalculations while their expected value is exactly the baseline — the most useful single lesson of the project. Expect students' tables to show "significant" results now and then; ask how many rules and recalculations each student tried.

🧪 Self-check quiz

0/5 correct

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