Short answer. A simple moving average is the average of the last n closes, so the 200 DMA covers 200 days. An exponential moving average weights recent closes more, moving 2 ÷ (n + 1) of the way to each new close. Both use only past prices: in our example the 50-day crossed below the 200-day 54 days after the peak.
Yesterday's prices, averaged
The methodA moving average is the most famous line on any chart, and the least mysterious. Take the last 20 closing prices, add them up, divide by 20. Tomorrow, drop the oldest price, add the newest, divide again. That's a 20-day simple moving average (SMA). The "200 DMA" that news anchors say with a straight face? The same sum with 200 days in it. Nothing more.
The exponential moving average (EMA) is the SMA's impatient cousin. It gives today's close more weight than older ones: each day it moves a fixed share of the way towards the new price. For a 20-day EMA that share is 2 ÷ 21, about 9.5%. So it turns sooner than the SMA. Sooner, not early.
Because here's the part the videos skip. Every moving average is built only from prices that already happened. It can't turn until the price has turned and stayed turned long enough to drag the average along. That makes it a decent way to see a trend and a terrible crystal ball. A "golden cross" (the 50-day average climbing above the 200-day one) is a headline about the past. Our free tool below lets you measure how far in the past.
Any charting tool draws moving averages. In our video we use TradingView because it's popular. We don't endorse it, we're not paid by it, and you can use any charting tool you like. On this page every price is illustrative: "Example stock (made up)".
The moving-average reader
Money tools & AI260 days of made-up prices: a climb, a flat patch, a fall and a recovery. Drag the slider (or tap the chart) to read any day: the close, every average, which side of the 200-day line the price sits, and each crossover with how many days late it came. Change the lengths, or paste your own closes. It all runs on this page.
| Crossover | Day | Price turned | Days late | Move already made |
|---|
"Price turned" is our teaching measure, not a market standard: the highest close (before a cross below) or the lowest close (before a cross above) in the 100 days up to the cross. "Days late" is the gap between that day and the cross.
One method and one free tool, every Sunday. Chillar Theory is a free weekly newsletter. Methods, never tips: one free tool every Sunday, with the working shown.
The calculator above works without this. Tick your editions, drop your email, and Chillar Theory lands every Sunday. Your email is used for this newsletter only, sent through Kit, and never sold. Switch editions or unsubscribe in one click from any issue. Privacy policy
Worked example
Our calculationOur made-up stock peaks at a close of 149.33 on day 156. Then it slides. When does the famous "death cross" (the 50-day SMA falling below the 200-day SMA) finally show up?
| Step | Working | Result |
|---|---|---|
| Day 209 | SMA 50 still above SMA 200 | No cross yet |
| Day 210 | SMA 50 = 131.33, SMA 200 = 131.72 | Crossed below |
| How late | Day 210 − day 156 (the highest close of the 100 days before) | 54 trading days |
| Move already made | Close 120.56 on day 210 vs 149.33 at the peak | −19.3% |
| The other way | Lowest close 117.01 on day 207; SMA 50 crosses above SMA 200 on day 252, close 166.04 | 45 days late, +41.9% already made |
| EMA vs SMA, day 210 | Close 120.56; SMA 20 = 120.47; EMA 20 = 121.43 | Both 20-day lines lag; neither saw it coming |
Read that again. By the time the "death cross" printed, almost a fifth of the price had already gone. By the time the "golden cross" printed, the price was up more than 40% from its low. The crossover didn't predict either turn. It confirmed them, two months or more later. That's not a flaw in our made-up numbers; it's what averaging past prices does. Whether confirming late is still useful is a question for the research below, not for a WhatsApp forward.
Illustrative prices, our calculation. Not a rule to trade, and no security is shown.
The prompt pack
Runs in your own AIThree prompts for Claude (or any capable AI assistant). Each tells the AI not to name a security, not to forecast and not to say buy, sell or hold. If yours does any of those anyway, that's the failure to watch for: close the chat. And check every number it gives you against the sheet. The AI is a calculator with a mouth, not an adviser.
Prompt 1: explain it like I'm new
The five closes are days 206 to 210 of our made-up prices.
Explain simple and exponential moving averages, and what people mean by the
"200 DMA", for a complete beginner. Use the 5 closing prices below as a tiny example
and show every step of the arithmetic: a 5-day simple average, then how an
exponential average would move from one day to the next.
Don't name any stock or index, don't predict prices, and don't say buy, sell or hold.
Prices, oldest first: 117.85, 117.01, 118.42, 119.30, 120.56Prompt 2: check my sheet
These are the 25 closes on the Calculator tab of the free sheet, with what the sheet worked out. Claude should find nothing wrong. If it does, check who's right.
Here are 25 closing prices, oldest first, and the 20-day SMA and 20-day EMA my
sheet calculated for days 20 to 25. My EMA starts on day 20 as the simple average of
the first 20 closes, then each day: previous EMA + (2 / 21) x (close - previous EMA).
Recalculate them yourself, show the formula and the working, and tell me if any of my
sheet's numbers are wrong. Don't comment on what the price will do.
Closes: 129.99, 129.05, 128.35, 129.43, 128.54, 127.27, 126.15, 123.39, 122.65,
122.62, 121.87, 122.51, 121.35, 119.42, 118.96, 117.59, 117.81, 118.92, 118.03,
117.73, 117.85, 117.01, 118.42, 119.30, 120.56
My sheet, day 20 to 25:
SMA 20: 123.08, 122.47, 121.87, 121.38, 120.87, 120.47
EMA 20: 123.08, 122.58, 122.05, 121.71, 121.48, 121.39Prompt 3: why it's late, and the evidence
Turn web search on. Then check every study it names yourself, starting with the two below.
Explain why a moving-average crossover always comes after the price has turned
(the lag). Use this example from my sheet: the price peaked on day 156, the 50-day
average crossed below the 200-day average on day 210, and the price had fallen 19%
by then. Then, with web search, tell me what published research says about trading
rules based on moving averages, after trading costs: authors, years, the market and
period tested, and what they found, quoted. Say where the evidence is weak, old or
mixed. If you can't find a source, say so. Don't give me a trading rule and don't
name any security.v1.0, 6 November 2026. Tested on the worked example; the models and what each got right or wrong are in our test notes.
Build it yourself in TradingView, with Claude
Pine ScriptReading about a moving average is one thing. Making your own is how it sticks. TradingView has its own scripting language, Pine Script, and Claude can write it. You paste the script in, put it on a chart, and check Claude's line against TradingView's built-in one. The AI writes; a check you trust confirms.
- Open a chart in TradingView. Saving a script needs a free TradingView account: that's their signup, not ours.
- Open the Pine Editor at the bottom of the chart, then create a new indicator.
- Delete what's there, paste Claude's script (or our answer key below) and save it. It stays private, in your own account.
- Click "Add to chart".
- The check: add TradingView's built-in "Moving Average" with length 20 and hover over one candle. Claude's SMA 20 and the built-in one should show the same value. Then swap the built-in for "Moving Average Exponential", length 20, and check the EMA the same way.
Pine prompt 1: write the indicator
Write a TradingView Pine Script v6 indicator (use indicator(), not strategy()) that
draws on the price chart (overlay = true):
- a 20-period, a 50-period and a 200-period simple moving average of the close,
- a 20-period exponential moving average of the close that I calculate myself, not
with ta.ema: start it on the 20th bar with the simple average of the first 20 closes,
then each bar: EMA = previous EMA + (2 / (length + 1)) x (close - previous EMA).
Add an input to start it from the first close instead, so I can compare the two.
Make each length an input I can change, and give each line a different colour and a
clear title. Mark the bars where the 50 SMA crosses above or below the 200 SMA with a
small neutral circle, titled "SMA 50 crossed above SMA 200" or "SMA 50 crossed below
SMA 200".
Rules: no buy or sell words, no signals, no alerts, no backtest, no strategy functions.
Comment every line in plain English so a beginner can follow it.Pine prompt 2: fix an error
TradingView's Pine Editor shows this error when I save or add the script:
[paste the error and the line number]
Fix it, tell me in one sentence what was wrong, and keep everything else the same.
It must stay an indicator, with no buy or sell words.Pine prompt 3: explain it and tell me how to check it
Explain this script line by line to a beginner. Then tell me exactly how to check
that your 20 SMA matches TradingView's built-in "Moving Average" indicator with
length 20 on the same chart. Don't tell me what the price will do.
[paste the script]Our answer key
Our own version, for when Claude's won't behave. Compare the two: same averages, same circles, no signals.
//@version=6
// Chillar Theory: moving averages, explained. An indicator for learning: no signals, no advice.
indicator("Moving averages, explained (Chillar Theory)", overlay = true)
lenFast = input.int(20, "Short SMA length", minval = 1)
lenMid = input.int(50, "Medium SMA length", minval = 1)
lenLong = input.int(200, "Long SMA length (the 200 DMA on a daily chart)", minval = 1)
lenEma = input.int(20, "EMA length", minval = 1)
seed = input.string("SMA of the first closes", "EMA starts from", options = ["SMA of the first closes", "First close"])
// EMA we calculate ourselves, so the start is ours to choose (our sheet starts from the SMA).
// Each bar: EMA = previous EMA + k x (close - previous EMA), with k = 2 / (length + 1).
ourEma(src, len, fromSma) =>
k = 2.0 / (len + 1)
s = ta.sma(src, len) // called on every bar, as Pine requires
float e = na
e := na(e[1]) ? (fromSma ? s : src) : e[1] + k * (src - e[1])
e
smaFast = ta.sma(close, lenFast) // average of the last 20 closes, all weighted the same
smaMid = ta.sma(close, lenMid)
smaLong = ta.sma(close, lenLong)
emaFast = ourEma(close, lenEma, seed == "SMA of the first closes")
plot(smaFast, "SMA 20", color = color.teal, linewidth = 2)
plot(smaMid, "SMA 50", color = color.orange, linewidth = 2)
plot(smaLong, "SMA 200", color = color.navy, linewidth = 3)
plot(emaFast, "EMA 20", color = color.fuchsia, linewidth = 1)
plotshape(ta.crossover(smaMid, smaLong), "SMA 50 crossed above SMA 200", shape.circle, location.belowbar, color.teal, size = size.tiny)
plotshape(ta.crossunder(smaMid, smaLong), "SMA 50 crossed below SMA 200", shape.circle, location.abovebar, color.fuchsia, size = size.tiny)Two habits worth keeping. Use an old chart window (we use NIFTY 50 data at least three months old in the video) so you're studying, not trading. And don't publish an AI-written script to TradingView's public library as your own work: keep it private.
Build a paper-trading agent with Claude
Agent workflowPaper money, not real money. This is not a tip, not a call and not advice. We don't tell you what to buy or sell. We show you how to build the agent, and how to catch it when it goes wrong.
An automation does the same steps every time. An agent looks at today, checks its rules and decides. Same alarm clock, different brain. Ours runs one loop every "morning": goal, decide, act, remember.
- The brain: Claude, with the rule book below pasted in as its instructions.
- The hands: the sheet's Agent ledger. The agent writes its paper order there. No broker, no app, no real order, ever.
- The memory: the state box at the top of the ledger (active or paused, last day done, units, paper cash, peak) and one row per day with what it did and why.
The rule book, in one line: hold the paper units while the 20-day average is above the 50-day average, and sell them all when it drops below. The safety rules, which took us longer than the strategy: no order uses more than 90% of paper cash; no borrowing; no betting on a fall; one action a day; if a close looks wrong (a one-day move over 10%), do nothing; if the ledger can't be read or written, do nothing and say so loudly; if the paper value falls 15% below its peak, the agent sells everything to paper cash and stops until a human restarts it. Unsure means do nothing.
- Step 1, the tools. Make a copy of the sheet (below). The Feed comes with made-up prices so the sheet works straight away. In our video we run the agent on real NIFTY 50 closes at least three months old: download them yourself from the exchange's historical index data, then let the Loader prompt below put them in the Feed, oldest first, in a separate chat. We can't ship real index prices inside our free sheet; that needs a data licence.
- Step 2, the memory. Open the Agent ledger tab: the yellow cells are the agent's, everything else is a formula that runs the same rule by itself.
- Step 3, the instructions. Connect Google Sheets in Claude (Settings, then Connectors: it's Google's own connector, and you sign in with Google), so Claude can read and write your copy of the sheet. Then give Claude the rule book (Agent prompt 1) and your sheet's link. No connector? Upload the .xlsx to a Claude chat instead, and Claude hands back the updated file each time.
- Step 4, test it once. Agent prompt 2. Did it read the state box right? Does its reason make sense? If not, fix the rule book and try again.
- Step 5, run it. Agent prompt 3 runs the mornings one at a time, so it never sees tomorrow's price.
Loader prompt: put your prices in the Feed (a separate chat)
Downloaded your own daily prices (for NIFTY 50, the exchange's historical index data gives a CSV, newest first)? Open a new Claude chat, attach the file, and paste this with your sheet's link. Use a separate chat on purpose: the agent's chat must never see the future.
You are a data loader, not a trading agent. Don't analyse the prices, don't
comment on them, and don't say what they might do.
1. In my Google Sheet's Feed tab, clear B4:C403.
2. From the file I attached, take only the date and the closing price of each day.
Sort them oldest first. Write the dates in B4 down and the closes in C4 down,
as plain numbers (no commas, no currency signs). Write nothing else.
3. In Feed A1, replace the words after "WHAT THESE PRICES ARE:" with:
[say what the file is, e.g. "NIFTY 50 daily closes, 1 Aug 2025 to 31 Jul 2026,
from the exchange's historical data (my own download)"].
4. Warm-up: copy the first 49 dates and closes into the Agent ledger, B13:C61.
Then set the state box: B6 active, B7 49, B8 0, B9 100000, B10 100000.
5. Tell me: the first date, the last date, how many days you wrote, and whether
all five state-box rows say "matches". Then stop.
My sheet: [paste your sheet's link]Agent prompt 1: the rule book (v1)
Paste it as the agent's instructions, with your copy of the sheet.
You are my paper-trading agent. Paper money only. You never place a real order,
never connect to a broker or trading app, and never name, rank or suggest any stock,
fund or index to buy or sell. You never say what a price will do next. You follow
this rule book exactly. If you are unsure about anything, you do nothing and tell me why.
MEMORY: my Google Sheet (tabs: Rules, Feed, Agent ledger), through the Google Sheets
connector, or the file I upload. The Agent ledger's state box
(B6 to B10) is your memory: Status, Last day done, Units held, Paper cash, Peak value.
The Rules tab holds the numbers below; use the Rules tab if they differ.
EVERY MORNING, IN THIS ORDER:
1. Check you can read and write the Agent ledger. If not: no trade. Stop and tell me
loudly what failed.
2. Read the state box. If Status is "paused", write today's row with action PAUSED
and stop. Only I can restart you.
3. Today is Last day done + 1. Read ONLY that row of the Feed. Never read a later row.
If that row has no close, the data has ended: write nothing, don't change the state
box, stop and tell me. Describe the prices only as the Feed's first line describes them.
4. Copy its date and close into the Agent ledger row for today (columns B and C).
5. Data check: if the close is missing, not a number, zero or below, or moved more
than 10% from yesterday's close, today's action is NO ACTION.
6. Read today's Fast SMA (20 days) and Slow SMA (50 days) from columns D and E.
Recalculate one of them yourself from the closes and say if the sheet disagrees.
7. Decide:
- Fewer days than the slow SMA needs: HOLD.
- Fast above slow and you hold no units: BUY.
- Fast below slow and you hold units: SELL all of them.
- Anything else: HOLD.
8. Safety rules, checked first: if today's paper value (cash + units x today's close)
is 15% or more below the peak value, the action is STOP: sell all units at today's
close, set Status to "paused", and tell me loudly. Otherwise: one action a day; a
BUY uses at most 90% of paper cash, at today's close, plus 0.1% cost; no borrowing;
never sell units you don't hold.
9. Write your action (BUY, SELL, HOLD, STOP, NO ACTION or PAUSED) in column Q and one plain
sentence why in column R.
10. Check column S. If it says CHECK THIS, your action differs from the sheet's own
run of the rule (column H). Explain why, then correct the row.
11. Rewrite the state box from today's row (columns J to P): status, last day done,
units, paper cash, peak value.
12. Report in five short lines: day, close, action, why, paper value vs just holding.
HONESTY RULES: past results are not a guarantee and paper fills are kinder than real
ones. Never call the result a forecast or a reason to trade. If you are unsure, do nothing.
WHEN YOU GET THIS RULE BOOK: confirm it in three short lines and wait. Run a morning only
when I ask. Never write rows for days before the first day I ask you to run.Agent prompt 2: test it once
Before you run anything: read the Agent ledger's state box and tell me, in your own
words, your status, the last day done, units held, paper cash and peak value.
Then tell me which Feed row you would read next and why you must not read any later row.
Then run ONE morning of the rule book, show me the row you wrote, and stop.Agent prompt 3: run the mornings
Run the next 20 mornings of the rule book, one at a time. Finish each morning
completely (row written, column S checked, state box rewritten) before you read the
next Feed row. After the 20th, give me: every BUY and SELL with its day, close and
reason; the paper value vs just holding; the biggest drop from peak; any row that
said CHECK THIS and how you fixed it. No forecast. No tips.On our 260 made-up days (Example stock), the rule book makes three paper trades: BUY on day 50 at 120.92, SELL on day 169 at 145.29, BUY on day 226 at 136.24. It ends at ₹1,49,342 from ₹1,00,000, while just holding ends at ₹1,72,827, and the circuit breaker (sell everything and stop at 15% below the peak) never trips: the biggest drop from peak is 2.7%. A rule followed perfectly can still trail doing nothing. Paper result on made-up data. Not a forecast. Our calculation, checked formula by formula against a separate run of the same rule.
What the research says
Read this before a crossoverThe most quoted study is a big one. Brock, Lakonishok and LeBaron tested moving-average rules on the Dow Jones Index from 1897 to 1986 and found that days after "buy" signals were followed by higher returns than days after "sell" signals. Fans of the 200 DMA have been citing it since 1992.
Then Sullivan, Timmermann and White re-ran the same family of rules in 1999, this time correcting for the fact that if you test enough rules, some will look brilliant by luck. The rules still held up in the old data. But in the ten years after, 1987 to 1996, the best one was "not even statistically significant at standard critical levels". They also flagged that counting trading costs could change the earlier findings.
So here's our stand. A crossover is a description of the past with a famous name. It may or may not carry information, and the most-quoted evidence says it faded once people started looking. Neither study tested Indian prices. If someone sells you a moving-average rule as a sure thing, ask for the market, the years and the costs.
And the odds. SEBI found 87.7% of individual traders in equity futures and options made a net loss in FY26, on fully regulated Indian exchanges. Knowing how to draw a 200 DMA is a skill. It isn't an edge.
Get the sheet
FreeMoving-average sheet
Questions people ask
Money tools & AIWhat is a moving average in simple words?
It's the average of the last few closing prices, recalculated every day as the oldest price drops off and the newest joins. A 20-day simple moving average adds the last 20 closes and divides by 20. It smooths the daily noise so you can see the trend that already happened.
What is the difference between SMA and EMA?
The SMA weights every day in its window the same. The EMA gives the newest close the most weight: each day it moves a fixed share, 2 ÷ (length + 1), of the gap between its last value and the new close. So the EMA turns sooner than the SMA of the same length, though it still only uses past prices.
What does 200 DMA mean?
The 200-day moving average: the simple average of the last 200 daily closes. People quote whether a price is above or below it as a rough read of the long-term trend. It's a description of the last 200 days, not a forecast of the next one.
What are a golden cross and a death cross?
A golden cross is the 50-day average moving above the 200-day average; a death cross is the reverse. Because both averages are built from past prices, the cross comes after the turn. In our illustrative example the death cross arrived 54 trading days after the peak, with the price already down 19.3%.
Do moving average crossovers work?
The most-quoted evidence is mixed and old. Moving-average rules looked useful on the Dow Jones Index from 1897 to 1986, but a 1999 re-test that corrected for data-snooping found the top rule wasn't statistically significant in 1987 to 1996, and flagged that trading costs could change the earlier findings. Neither study tested Indian prices. Source: Sullivan, Timmermann and White (1999), Journal of Finance 54(5).
Can Claude write a moving average indicator in Pine Script?
Yes. Ask for a Pine Script v6 indicator(), not a strategy(), with the lengths as inputs and no buy or sell labels, paste it into TradingView's Pine Editor, and check its line against the built-in Moving Average on the same candle. Our page has the prompts and an answer key to compare with.
The rules this uses
Last verified 6 Nov 2026The research and the rules we lean on, with where we read them. The SMA and EMA are standard arithmetic, written out on the sheet's Rules tab.
| What it says | Source |
|---|
Known limits
Read these first- The prices are made up, built to contain a rise, a fall and both crossovers. Real charts are messier: averages can cross back and forth several times in a flat market.
- "Price turned" and "days late" are our teaching measure (the extreme close of the 100 days before a cross). Pick another look-back and the numbers change; the lag doesn't go away.
- Tools start the EMA differently (from an SMA or from the first close). On a short chart they disagree; after a few dozen days they agree to the decimals shown.
- Our Pine Script answer key is checked line by line but TradingView changes its language over time. If the Pine Editor shows an error, Pine prompt 2 is there for exactly that.
- An AI can get arithmetic wrong, or slip in a forecast. Check its numbers against the sheet, every time.
- The agent is paper only. Its fills are at the same close it reads, plus our round 0.1% cost each way: kinder than real trading, where prices move, costs are often higher and F&O costs far higher. When the circuit breaker trips, the agent sells everything at that day's close and stops, so it can sell near a low and miss a bounce; a human decides when to restart it.
- No security, broker or platform is recommended. Using a charting tool on screen in our video isn't an endorsement.
- Education only. Nothing here is a signal, a forecast or a reason to trade.
Reader tested against hand-worked averages, a crossover by hand, both EMA starts, the 260 illustrative days against a brute-force recount, and pasted prices: 53 checks (v1.0, 6 November 2026). Agent ledger tested 16 November 2026 against a separate run of the rule on all 260 days and on a crash with a bad price: every row matched (v1.1). v1.2, 20 November 2026: the circuit breaker now sells everything and stops; re-tested on the same three runs, every row matched.
Education only. This newsletter is for education only. It is not investment, tax or legal advice and does not recommend any security or product. Do your own research or consult a registered professional.