WHY average at all? Price Pt = trend + noise. Averaging over n points cancels zero-mean noise (by the law of large numbers the noise term shrinks like 1/n) while leaving the slow trend roughly intact. Bigger n ⇒ smoother but laggier.
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−α)EMAt−1,0<α<1
Why this step? It's a recursive one-line update — cheap and self-correcting. Unrolling it once:
EMAt=αPt+α(1−α)Pt−1+α(1−α)2Pt−2+⋯
So weights decay geometrically — recent prices dominate. To match the "center of mass" of an n-period SMA we choose:
α=n+12
Why n+12? The weighted mean lag of the EMA is α1−α periods. Setting this equal to the SMA's average lag 2n−1 and solving:
α1−α=2n−1⇒α2−2=n−1⇒α=n+12.
WHY the spread trick? Instead of watching two wiggly lines, watch one numberS. A crossover is simply "S hits zero," which is trivial to code and backtest.
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.
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=fast−slow. Jab S 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).
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.