4.6.8Trading Strategies

Learn moving-average crossover systems

1,488 words7 min readdifficulty · medium

WHAT is a moving average?

WHY average at all? Price PtP_t = trend + noise. Averaging over nn points cancels zero-mean noise (by the law of large numbers the noise term shrinks like 1/n1/\sqrt{n}) while leaving the slow trend roughly intact. Bigger nn ⇒ smoother but laggier.

Deriving the EMA from scratch

We want a smoother that (a) reacts faster than SMA and (b) never needs to store all old prices. Ask: what if today's smoothed value is a blend of today's price and yesterday's smoothed value?

EMAt=αPt+(1α)EMAt1,0<α<1\text{EMA}_t = \alpha P_t + (1-\alpha)\,\text{EMA}_{t-1}, \qquad 0<\alpha<1

Why this step? It's a recursive one-line update — cheap and self-correcting. Unrolling it once: EMAt=αPt+α(1α)Pt1+α(1α)2Pt2+\text{EMA}_t = \alpha P_t + \alpha(1-\alpha)P_{t-1} + \alpha(1-\alpha)^2 P_{t-2}+\cdots

So weights decay geometrically — recent prices dominate. To match the "center of mass" of an nn-period SMA we choose: α=2n+1\boxed{\alpha = \frac{2}{n+1}}

Why 2n+1\frac{2}{n+1}? The weighted mean lag of the EMA is 1αα\frac{1-\alpha}{\alpha} periods. Setting this equal to the SMA's average lag n12\frac{n-1}{2} and solving: 1αα=n12    2α2=n1    α=2n+1.\frac{1-\alpha}{\alpha}=\frac{n-1}{2}\;\Rightarrow\;\frac{2}{\alpha}-2=n-1\;\Rightarrow\;\alpha=\frac{2}{n+1}.


WHAT is a crossover?

WHY the spread trick? Instead of watching two wiggly lines, watch one number SS. A crossover is simply "SS hits zero," which is trivial to code and backtest.

Figure — Learn moving-average crossover systems

HOW to run the system (step-by-step)

  1. Pick two windows: fast nfn_f and slow nsn_s with nf<nsn_f < n_s (classic: 50/200 daily; 9/21 intraday).
  2. Compute both MAs each bar.
  3. Compute S(t)S(t) and check for a sign flip.
  4. On a Golden Cross go long; on a Death Cross exit / go short.
  5. Backtest, then add risk rules (stop-loss, position size).

Common mistakes


Recall Feynman: explain to a 12-year-old

Imagine following a bumpy hiking trail in fog. Instead of looking at every rock, you look at the average direction of the last 10 steps (fast lens) and the last 200 steps (slow lens). When your short-term direction turns uphill past your long-term direction, the mountain is probably rising — start climbing (buy). When it turns downhill past it, head back (sell). The lenses can't see the future; they just clear the fog so you notice the turn a bit late but clearly.


Active recall

What is a Simple Moving Average of window n?
The arithmetic mean of the last n closing prices, 1ni=0n1Pti\frac1n\sum_{i=0}^{n-1}P_{t-i}.
Why does averaging reduce noise?
Zero-mean noise cancels across the window (shrinks ~1/n1/\sqrt n) while the slow trend survives.
Golden Cross vs Death Cross?
Golden = fast MA crosses ABOVE slow (buy); Death = fast crosses BELOW slow (sell).
Define the spread S(t).
S(t)=MAfast(t)MAslow(t)S(t)=\text{MA}_{fast}(t)-\text{MA}_{slow}(t); a crossover is a sign change of S.
EMA recursion formula?
EMAt=αPt+(1α)EMAt1\text{EMA}_t=\alpha P_t+(1-\alpha)\text{EMA}_{t-1}.
Why is EMA's alpha = 2/(n+1)?
It matches the EMA's average lag (1α)/α(1-\alpha)/\alpha to the SMA's lag (n1)/2(n-1)/2.
Compute EMA if alpha=0.2, prev EMA=50, price=55.
0.2(55)+0.8(50)=510.2(55)+0.8(50)=51.
Are MAs leading or lagging?
Lagging — built only from past prices; they confirm, not predict.
Main failure mode of crossover systems?
Whipsaws in sideways/range-bound markets (many false signals, commission bleed).
Core trade-off in choosing window n?
Lag vs noise: bigger n = smoother but slower; smaller n = faster but noisier.

Connections

Concept Map

averaging cancels noise

recursive faster variant

alpha = 2 over n+1

used as

used as

subtract

subtract

sign change up

sign change down

signal

signal

validate rule

validate rule

Noisy Price = Trend + Noise

Simple Moving Average

Exponential Moving Average

Fast MA short window

Slow MA long window

Spread S = fast - slow

Golden Cross

Death Cross

Buy / Go Long

Sell / Exit

Backtest

Hinglish (regional understanding)

Intuition Hinglish mein samjho

Dekho, stock ka price din bhar upar-neeche uchhalta rehta hai — bahut zyada "noise" hota hai. Moving average ek smoothing lens ki tarah hai: purane n dino ke close ka average lo, toh chhoti-chhoti wiggles cancel ho jaati hain aur asli trend saaf dikhta hai. Bada window (jaise 200) = zyada smooth par slow (laggy); chhota window (jaise 50) = fast par thoda noisy. Ye lag vs noise ka trade-off hi pura khel hai.

Crossover system simple hai: ek fast MA aur ek slow MA lo. Jab fast MA slow ke upar cross kare, matlab trend upar mud gaya — ye Golden Cross, BUY. Jab fast MA slow ke neeche aaye — Death Cross, SELL. Coding ke liye smart trick: sirf ek number dekho, spread S=fastslowS = \text{fast} - \text{slow}. Jab SS ka sign change ho (minus se plus ya plus se minus), tab signal banta hai. Do wiggly lines dekhne ki zaroorat nahi.

Important baat: MA future predict nahi karta, kyunki wo sirf purane prices se banta hai — isliye woh lagging hai. Signal thoda late aata hai, par confirm karta hai ki trend sach mein shuru ho gaya. EMA is lag ko kam karta hai kyunki wo recent price ko zyada weight deta hai, formula α=2/(n+1)\alpha = 2/(n+1).

Sabse bada khatra: whipsaw. Jab market sideways (range-bound) ho, tab fast MA baar-baar slow ke upar-neeche flick karta hai, har baar commission aur slippage kat-ti hai, aur paisa dheere dheere ud jaata hai. Isliye ye strategy trending market mein achhi, flat market mein bekaar. Hamesha backtest karo aur stop-loss lagao.

Test yourself — Trading Strategies

Connections