Chapter 8. Trend and Moving Averages
A moving average predicts nothing, yet everyone expects exactly that from it. What it is made of, what it pays for smoothness and why the “perfect” setting rarely stays so.
Someone else’s setting
How many times a month a ready-made pair changes position and what it costs.
A video says: take EMA 8 and 20 and trade the crossovers on the hourly chart. How many times a month will this pair flip you, and what will it cost?
Ready-made settings are passed around as knowledge: 9/21 for scalping, 50/200 for the investor, 20 for everything else. None of these numbers was derived from data. They stuck because they are round and convenient to talk about. The test result is inconvenient for the seller of settings, and we will run it ourselves. But first the simplest thing: what someone else’s setting costs before we even ask whether it is profitable.
How many times a month does the EMA 8 and 20 pair change direction on hourly gold candles?
On our gold history about 25 changes a month. On 4-hour candles the same pair gives about 5.8, on daily about 1.1. This is a property of the setting and the timeframe, not of the market.
Choose an instrument, a timeframe and any pair of periods from a grid of 61 pairs. You set the cost of a position change yourself.
Why can the video’s author not know what this pair will cost you personally?
- The number of crossovers and the cost depend on the instrument, the timeframe and your spread
- He hides the data
- This pair is outdated
That is what makes a setting “someone else’s”: the numbers in the video are counted for his instrument and his horizon.
Mini-quiz
What does every crossover of two averages mean for your account?
- A free signal
- Higher profit
- A change of position: a new spread and commission
The cost arises before the question of profitability.
Where did the ready-made settings 9/21, 50/200 and 20 come from?
- None of these numbers was derived from data: they stuck as round and convenient
- They were derived from data
- The Fed calculates them
They are passed on as knowledge but not tested.
What an average is made of
The weights of bars in SMA and EMA and the rule: an average knows no more than the price.
A moving average is a weighted sum of past closing prices. In the simple one (SMA) every bar in the window weighs the same and everything older weighs nothing. In the exponential one (EMA) the weight falls smoothly: a new bar enters with the factor k = 2 / (period + 1), and each earlier one is multiplied by (1 − k). Move the period and switch the type to see the weights.
Gold, daily candles. The solid part of the columns: the bars that give the first half of the weight.
Does EMA 50 show more than the prices of the last 50 bars themselves?
- No: it is the same prices, added with weights
- Yes: it removes noise and shows a hidden trend
- Only on daily candles
It removes detail rather than adding information. A “hidden” trend that is not in the prices cannot be in it.
Mini-quiz
How are bar weights distributed in a simple average (SMA)?
- Equal within the window, zero beyond it
- They decay smoothly
- They grow toward older bars
In an EMA the weight decays smoothly.
What is the rule for the whole chapter about the average?
- The average adds new information
- The average predicts price
- The average knows no more than the price does
It is a transformation of numbers already known.
Lag
Noise and delay at every period: only a point on the scale can be chosen.
Any smoothing pays with delay. The longer the period, the fewer false crossings and the later the average reacts to a real reversal. This is not “a flaw of EMA fixed in other indicators” but a property of averaging itself. It cannot be avoided, only a point on the scale can be chosen. Move the period and watch two numbers: how many times the price crossed the average (noise) and how many bars later the average turned after a reversal of the price.
Reversals are found mechanically: a bar above or below five neighbours on each side. The same logic as the swings in chapter 7, but without eyes and without fitting.
Which period fits which task?
- A long period
- A short period
- No such thing
Mini-quiz
What does any smoothing pay with?
- Volume
- Lag
- Spread
This is a property of averaging itself.
Is there a “best” moving-average period at all?
- Yes, 200
- No: there is a period suited to your holding time
- Yes, 20
Someone holding for hours tolerates noise and gets a short lag.
The overfitting lab
Fitting on the first half, a test on the closed second.
Now the main experiment. The history of the instrument is cut in half. The first half is open: fit any pair of periods on it, or press “Fit the best pair” so the lab goes through all 61 pairs. The second half is closed. When you have decided, press “Check” and see what became of your pair on data it has not seen.
The result is counted in ATR: the price move in the direction of the position minus a cost of 0.03 ATR for each change. This is a teaching model of overfitting, not a trading system, and we recommend no parameters here.
You found a pair with an excellent result on history. What does that say about the future?
- The settings work
- Almost nothing: a best pair exists on any stretch by definition
- The fitting should be repeated on the same history
The best combination is always found. The question is whether it stays the best on new data.
Mini-quiz
How does the overfitting lab work?
- All history is open
- The first half of history is open for fitting, the second is closed for testing
- Only the second half is open
The lab tries all 61 pairs.
What is fitting parameters to a specific stretch of the past called?
- Hedging
- Overfitting
- Diversification
You looked for a number describing the past in order to apply it to the future.
Searching empty data
The best of many variants looks wonderful even on random prices.
Why does the pair that is best on history so rarely stay the best? Because we pick the maximum of many. Even if there is nothing at all in the prices, among dozens of variants one will certainly turn out lucky. Let us check this on prices that certainly hold no signal: a random walk. Move the number of pairs tried.
One hundred and twenty independent random walks. The upper curve is the beauty of the find, the lower one is what you get on new data.
You tried 61 pairs and found the best. What do you need to know to believe it?
- Only its result on history
- How many pairs you tried and how it behaves on data it has not seen
- Its result on a second instrument
The number of variants tried determines how beautiful a find must be by chance alone.
Mini-quiz
Why does the pair that was best in history so rarely stay the best?
- The broker changes the spread
- The market changes its rules
- We pick the maximum of many: even on random prices someone will look lucky
A random walk has no signal at all.
Who gave the formal statement of the “data snooping” problem in 2000?
- Carol Osler
- Homma
- Halbert White
Sullivan, Timmermann and White applied the approach to technical trading in 1999.
What 75 cells showed
The best pair of the first half on the second: from almost the best to almost the worst, a median of 31 of 61.
You checked one instrument. We checked everything we have: 25 instruments on three timeframes, 75 cells, a grid of 61 pairs. The method was fixed before counting. The history of each cell is cut in half. On the first half the best pair is selected by total move net of cost. Then the same pair, and only it, is run on the second half, and its rank among all 61 pairs on the second half is recorded.
The pair that is best on the first half. What rank out of 61 does it take on the second, in the median? The middle of the ranking is 31.
The median is 31 of 61, exactly the middle. If fitting carried over to the future, the median would be near the top. But two tails hide behind it, visible below.
Each cell is an instrument on one timeframe. Data: H1 four to six months, H4 about a year, D1 five to seven years.
First. The rank of the best pair on the second half is smeared across the whole ranking and leans to the edges. It landed in the top ten of 61 in 19 cells of 75 (about 12 expected by chance), in the bottom third (42–61) in 29, and in the middle, places 21–40, in only 19. Half of the cases lie between roughly 16% and 79% of the ranking. The same fitting procedure gave now an almost best result, now an almost worst one, and it cannot be told in advance which will come up. The median of 31 of 61 is the sum of two tails, not “everything sits in the middle, always”.
Second. The size of the loss. On the first half the best pair gives a median of 20.9 ATR, on the second the same pair gives 1.5 ATR. In profit on the test are 39 cells of 75, that is 52%. Of all pairs in all cells 52% are in profit on the second half (interval 50–53%): the mechanical rule of crossing two averages, with our cost, is a coin, not a source of income. If the cost is set to zero, the median rank stays 32.
Third. Long periods are not unambiguously better than short ones. Pairs with a slow EMA of 100 and above (33 cells) took a median rank of 29, the short ones (42 cells) 38.5 (lower is better). But in profit on the second half the long ones are in 13 cases of 33 (39%), the short ones in 26 of 42 (62%). Two honest criteria gave different answers, so there is no conclusion of “take a longer one”. The link between the halves inside a cell is weak: the rank correlation over pairs has a median of 0.11, positive in 42 cells of 75. Neighbouring pairs resemble each other, but that does not make the best pair of the first half the best of the second.
The boundary between fitting and test is also a choice. Move it and see how the “best” pair changes.
The best pair is fragile not only on new data but also when the boundary shifts. The best pair when fitting on the first 30% of history matched the best when fitting on 70% in only 16 cells of 75. If your “perfect” pair changes depending on where you drew the line, that is not a property of the market but of your line.
Mini-quiz
How many cells were tested in this step's study?
- 25
- 610
- 75 (25 instruments on three timeframes)
A grid of 61 pairs.
Where did the best pair of the first half end up in the second half of history?
- Spread across the ranking, median 31 of 61
- Always last
- Always first
It tends to the edges: both the top ten and the bottom third.
What it is good for
A definition, a description of the regime, a shared language, and why an average is not support.
If an average does not predict, what is it for? Three honest things. Switch the modes and move the marker along the chart to see each of them.
Gold and other instruments, daily candles, the last 120 bars. In the first mode the shading shows whether the price closed above or below the average.
- A definition. “Trend up” is vague and depends on mood. “Price above the N-bar average” is arithmetic, the same yesterday and today. An average does not let you argue with yourself after the fact: it is discipline, not a forecast.
- A description of the regime. The distance of the price from the average and the slope of the average tell what state the instrument is in now: far gone or wobbling around it. It is context for everything else, a description of the present.
- A shared language. When two people say “price is under the two-hundred”, they understand each other unambiguously. This is the only reason to know about 50 and 200: the numbers are not special, many people simply look at them.
Does a moving average do this or not?
- It does
- It does not
The most persistent claim: “price bounces off a moving average as off support”. First guess on real touches, then look at the measurement.
Sixteen real touches of EMA 50 on daily and 4-hour candles. The answer is scored on the fact: what happened first within the next ten bars.
What it shows. On 25 instruments, after touching the EMA the price went back in 51–54% of cases across all nine combinations of timeframe and period. In a world where the order of bars is shuffled and there is no structure, you get 50–52%. The average is not a wall: sometimes the price bounces off it, sometimes it goes through, and on average it is almost a coin. A bounce always looks like support in hindsight because we do not remember the breaks.
Mini-quiz
What is a moving average good for, according to the step?
- Guaranteeing support
- Definition, describing the regime, and a common language
- Forecasting a reversal
Three honest things instead of prediction.
What does “price above the N-bar average” give you compared to a vague “uptrend”?
- A forecast of growth
- Arithmetic that is the same yesterday and today
- An entry signal
It is discipline, not a forecast.
Summary and a test forward
What to do instead of chasing a perfect setting.
The only honest test of a setting is a test forward. It needs two things: a chart set up by you and a record of what you decided, made before it was known how things would end. A test on the past, as you saw, is a test on what has already happened.
- Take the period from your holding time, not from optimisation. If you hold a position for a day or two, look at short ones, if for weeks, at long ones.
- Count the cost first. How many times a month the pair changes position on your instrument and what it costs at your spread.
- If you fit, cut the history and look at the second half once. Remember how many variants you tried.
- Write the decision down before the result. Only such a record separates a forward test from a story told afterwards.
What you know now
- Ready-made moving-average settings are not derived from data, and each has a price: the number of position changes a month depends on the instrument, the timeframe and the pair.
- A moving average is a weighted sum of prices that are already known. It holds no information that is not in the price.
- Smoothness is paid for with lag. There is no best period at all, there is a period for your holding time.
- The best pair of the first half took a median rank of 31 of 61 on the second, that is, the middle. 52% of cells are in profit on the test.
- Searching empty data gives beautiful finds. The more variants you tried, the less the find is worth.
- Price bounces off an EMA in roughly 51–54% of touches, little different from a shuffled world. An average is good for a definition, a description of the regime and a shared language.
Check yourself
You fitted a pair of periods with an excellent result on history. What does that say about the future?
- That the settings work
- Almost nothing: a best pair exists on any stretch by definition
- That the fitting should be repeated on the same history
The best combination is always found, the question is whether it stays the best on new data.
You trade crossovers on the hourly chart. What grows with the number of signals?
- Accuracy
- The total cost: spread and commission on every change of position
- Nothing
Every change of position costs money whether it is right or not.
Why is a long period not necessarily more robust than a short one on our data?
- Because a long average is always more precise
- Different criteria gave different answers: by rank the long ones are better, by share in profit they are worse
- Because more people trade by it
The data give no single answer of “longer is better”. What saves you is not the length of the period but a test forward.
Price touched EMA 50. What did our measurement show?
- A bounce in the overwhelming majority of cases
- A bounce in about half of the cases, close to a world with shuffled bars
- A break almost always
An average is not a wall: bounces and breaks come mixed.
What really tests a setting?
- Fitting on all the available history
- A test forward with the decision recorded before the result
- A nice chart with crossovers
Only a record made before the outcome separates a test from a story told afterwards.
Sources
- Exponential moving average: the smoothing factor k = 2 / (n + 1), the starting value from the simple average of the first n bars.
- White H. A Reality Check for Data Snooping. Econometrica 68(5), 2000, pp. 1097–1126.
- Sullivan R., Timmermann A., White H. Data-Snooping, Technical Trading Rule Performance, and the Bootstrap. Journal of Finance 54(5), 1999, pp. 1647–1691.
- Bailey D., Borwein J., López de Prado M., Zhu Q. Pseudo-Mathematics and Financial Charlatanism: The Effects of Backtest Overfitting on Out-of-Sample Performance. Notices of the AMS 61(5), 2014, pp. 458–471.
- SBF own measurements: 25 instruments (currencies, gold, silver, oil, gas, indices, cryptocurrencies), H1, H4 and D1 candles, 2019-02-21 to 2026-11-06. A grid of 61 EMA pairs (fast 5–50, slow 20–200). The rule: position by the sign of the EMA difference on the previous bar, the bar’s move in units of the previous bar’s ATR(14), a cost of 0.03 ATR per change of position. The history of each cell is cut in half, the best pair of the first half is run on the second. EMA touch: a bar tags the average after three closes on one side, the outcome within ten bars with a threshold of 0.5 ATR; control: the same bars randomly reordered (three reorderings per cell), a 95% Wilson interval. Searching empty data: 120 random walks in the browser.