# What is moving-average curvature? Formula, meaning and a backtest

Canonical URL: https://marketheist.io/portfolio/learn/moving-average-curvature
By Jeffrey Lin · Published 2026-11-25 · Updated 2026-11-25 · Data through Sep 2026
Category: Indicators

## Key takeaways

- Curvature asks whether a moving average is bending upward or downward: whether its rise is speeding up, or its fall slowing down.
- It reacts earlier than the direction of the average itself, because a turn in a trend shows up first as a change in its pace. The price paid is many false alarms.
- Dividing by the reading's own typical size puts every fund and every period on one scale, but it never changes whether the reading is above or below zero.
- On daily bars with the default settings it flips often, so a rule built on it trades many times a year and trading costs matter.
- The default settings were sized for weekly charts; on daily bars they look at a much shorter stretch of history.

## Definition

Moving-average curvature measures whether a moving average's rate of change is speeding up or slowing down: it is the change in the average's percentage change, a discrete second derivative. MarketHeist divides that second difference by its own standard deviation over a long trailing window, so the reading is in units of its typical size and is positive while the average is bending upward.

Also known as: MA curvature, moving average acceleration, second derivative of a moving average, trend acceleration, rate of change of momentum, moving average convexity.

## How it works

Think of the price's moving average as a path. Its level says where the trend is, its rate of change says how fast the trend is moving, and the change in that rate says whether the trend is gathering pace or losing it. Curvature is the third of these. A steady rise at a constant pace has no curvature at all; a rise that is speeding up has positive curvature; a rise that is slowing, or a fall that is getting steeper, has negative curvature; and a fall that is easing has positive curvature even while prices are still going down.

MarketHeist builds it in three steps. First, a moving average of the close, simple or exponential, 52 bars by default. Second, the average's percentage change over a lag of 4 bars, its speed. Third, the change in that speed over another 4 bars, its acceleration. The acceleration is then divided by its own sample standard deviation over a trailing window four times as long as the average, which turns it into a z-score-like reading: it says how large today's acceleration is compared with its usual size over that trailing window.

Curvature is like a car's accelerometer: a car still moving forward can already be braking, and the accelerometer shows the braking before the speedometer shows the car slowing down.

That early warning is the appeal and the problem. Each difference amplifies short-term noise, and taking two of them amplifies it twice; the moving average underneath is there to damp that. With a short average and a short lag, the sign of the curvature flips whenever the pace of the trend wobbles, which in a calm market happens constantly. A longer average and lag give a steadier reading that turns later.

Dividing by the standard deviation changes the scale, not the sign. A rule that holds while curvature is above zero takes exactly the same positions with or without the normalization; the normalization matters for thresholds other than zero, and for comparing readings across funds and decades.

## Formula

**Moving average, its speed and its acceleration**

```
\begin{pmatrix} M_t = \frac{1}{w} \sum_{k = 0}^{w - 1} C_{t - k} (or an exponential average of span w) \\ g_t = \frac{M_t}{M_{t - L}} - 1, κ_t = g_t - g_{t - L} \end{pmatrix}
```

where:

- Cₜ: the dividend-adjusted close of day t
- Mₜ: the moving average of the close
- w: the averaging window: 52 bars by default
- L: the lag used for both differences: 4 bars by default
- gₜ: the average's percentage change over L bars (its speed)
- κₜ: the change in that speed over L bars (its acceleration, the curvature)

The exponential version uses the span convention, a weight of 2 / (w + 1) on the newest bar, normalised over the bars seen so far.

**Normalized curvature and the rule**

```
z_t = \frac{κ_t}{sd_{4 w} (κ)_t}, s_t = {\begin{pmatrix} 1 & z_t > \theta \\ 0 & otherwise \end{pmatrix}, r_{t + 1}^{rule} = s_t \cdot r_{t + 1}
```

where:

- sd₄w(κ)ₜ: sample standard deviation (divides by n − 1) of the curvature over the last 4w bars, day t included
- zₜ: normalized curvature, the indicator's signal
- θ: the threshold: 0 by default
- sₜ: the position decided at the close of day t: 1 = hold, 0 = cash
- rₜ₊₁: the fund's total return on the next day

With θ = 0 the rule's positions depend only on the sign of κ, because the standard deviation is positive.

## Worked example

SPY daily bars from Oct 2006 to Sep 2026, about 20 years. Rule: hold SPY for the next day while the curvature of its 52-day simple moving average, measured over 4-day steps, closed above zero; otherwise cash; no trading costs.

The curvature was above zero on 49.4% of days: SPY's average spent roughly as much time bending up as bending down, even across a rising market, because a steady rise has no curvature and small changes of pace decide the sign.

That makes a busy rule: 356 round trips, 17.8 a year, holding for 7.0 days on average, with 51.7% of trades closing at a gain. It was invested 49.4% of the time. It grew 2.4% a year, less than the 11.1% of holding SPY throughout. Its worst decline from a peak was -40.4% against -55.2%.

A slower setting trades less. With a 100-day average and 10-day steps the rule made 7.4 round trips a year and grew 4.9% a year, with a worst decline of -37.1%. The exponential average in place of the simple one gave 3.0% a year.

None of these settings was chosen in advance for this window, and the rule has four of them: the window, the type of average, the step length and the threshold. The more combinations a test tries, the more likely the one that looks strongest was fitted to noise; the parameter robustness guide shows how to check.

Data through Sep 2026. Reproduce id: e95a1a6bb1d15658 (this guide, its lab setup and the data month).

## How MarketHeist computes it

- **Data**: Daily bars (open, high, low, close, volume) of the fund as the MarketHeist data service serves them to the backtester: prices adjusted for splits and dividends, so a dividend counts as reinvested. They come from a snapshot taken each month and cut at the data month of this page, and are not rounded. The fund's own history, not an extension: a fund younger than the window is measured over the years it has.
- **Window**: The worked example and the lab measure the last 20 years of trading days, Oct 2006 to Sep 2026 (5030 days), ending at the data month of this page. Every setup, and buy and hold, is measured over exactly these days; an indicator is warmed up on the days before them, so changing a setting never moves the window, and a setting that needs more history than exists before the window is refused rather than measured over fewer days.
- **Backtest**: The backtester's own engine, in the order it runs it: the indicator, the position rule (or entry and exit triggers) and the optional regime filter produce a position for every day of the fund's whole history; the position is then shifted forward by the execution delay and applied to each day's return over the window. Cash earns 0, there is no leverage, and a one-way cost in basis points is charged on the size of every change of position. Round trips are the closed entries of the trade log (a trade still open on the last day is not counted); the win rate is the share of them with a gain; the payoff ratio is the average win over the size of the average loss; expectancy is the average return per trade; the per-trade profit factor is the sum of the winning trades' returns over the size of the sum of the losing ones, while the per-day profit factor sums days.
- **Years and volatility**: A year is 252 trading days, the engine's convention: trades per year is round trips over days divided by 252, the CAGR is the growth multiple to the power 252 over the days, and volatility is the sample standard deviation of the daily returns times the square root of 252.
- **Indicator statistics**: The indicator's main output over the window: its last value, its 10th, 50th and 90th percentile (linear interpolation between ranks), and the share of days the rule alone says long, before the delay and any regime filter. Every output of the indicator is also summarized by its median and the share of days below 0.
- **Buy and hold**: The fund held every day of the window with dividends reinvested. The largest one-day gain and loss are the highest and lowest daily returns; the CAGR without the 10 or 30 largest gains (or losses) replaces those days' returns with 0 and recompounds.
- **Moving average**: Simple moving average of the close over ma_window bars (default 52, from 4 to 400), or, with ma_type EMA, an exponential average with weight 2 / (window + 1) on the newest bar, normalised over the bars seen so far (pandas ewm with span and adjust=True). (`ema` in packages/shared/engine/utils.ts)
- **Speed**: The average's percentage change over diff_lag bars: M[t] / M[t − lag] − 1 (default lag 4, from 1 to 52). (`pctChangeLag` in packages/shared/engine/utils.ts)
- **Acceleration**: The difference of that speed over the same lag: g[t] − g[t − lag]. (`diff` in packages/shared/engine/utils.ts)
- **Normalization (the signal)**: The acceleration divided by its rolling sample standard deviation (divides by n − 1) over 4 × ma_window bars, today included; no value while that window is incomplete or the deviation is 0. This is the primary output the rule reads; the average and its speed are returned alongside it. (`compute` in packages/shared/engine/indicators/curvature.ts)
- **Warm-up**: A first value needs roughly ma_window + 2 × lag + 4 × ma_window bars of history (about 270 bars with the defaults, about 520 for a 100-day average with 10-day steps). The lab takes the warm-up from bars before the test window.
- **Default rule**: Long while the normalized curvature is strictly above 0, otherwise flat. (`SPEC` in packages/shared/engine/indicators/curvature.ts)
- **Timing, costs and cash**: The position decided at a bar's close is applied to the next bar's return (execution delay 1); no trading costs unless set; cash earns 0. (`runBacktest` in packages/shared/engine/backtest.ts)
- **Engine functions**: `computePosition` (packages/shared/engine/run_basic.ts), `generatePosition` (packages/shared/engine/positions.ts), `applyRegimeFilter` (packages/shared/engine/regime_filter.ts), `generateTriggeredPosition` (packages/shared/engine/triggered_position.ts), `runBacktest` (packages/shared/engine/backtest.ts), `getIndicator` (packages/shared/engine/indicators/registry.ts)

## Moving-average curvature compared with its neighbours

Level, speed and acceleration of a trend

| Measure | What it reads | Turns | Noise |
| --- | --- | --- | --- |
| Price above its moving average | Level against trend | When the price crosses the average | Moderate |
| Moving-average crossover | Short trend against long trend | When the short average crosses the long one | Low |
| Rate of change of the average | Speed of the trend | When the average stops rising | Moderate |
| Moving-average curvature | Acceleration of the trend | When the pace of the trend stops increasing | High |
| MACD histogram | Gap between MACD and its signal line, a similar acceleration idea | When MACD's own rise slows | High |

## Limitations

- Two differences amplify noise. With short settings on daily bars the sign flips often, and many of the switches reverse within days.
- The rule trades often; the zero-cost test overstates what a trader would have kept after spreads and fees.
- Four settings give many combinations. A setting chosen because it looked good on one history tends to do worse on the next; neighbouring settings are the check.
- The long normalization window needs a year or more of daily history before the first reading, so young funds have short tests.
- The test ignores taxes, earns nothing on cash, trades at the close of the signal day and describes one historical path of one fund.

## Frequently asked questions

**What is the second derivative of a moving average?**

The change in its rate of change. The first difference says how fast the average is rising or falling; the second says whether that pace is increasing or decreasing. On daily data both are taken over a lag of a few bars rather than one, to keep the noise down.

**Why normalize the curvature?**

So that readings are comparable. Raw curvature is tiny and its size depends on the fund's volatility; dividing by its own standard deviation expresses it as a multiple of its typical size. It does not change whether the reading is above or below zero.

**Is curvature the same as the MACD histogram?**

They share an idea. The MACD histogram is MACD, the difference between a fast and a slow exponential average, minus its own moving average (the signal line); it rises while momentum is building. Curvature takes the change in an average's speed directly. Both turn earlier than trend-level signals and both are noisier.

**Why does a curvature rule trade so often?**

Because the pace of a trend changes much more often than its direction. Every wobble in the speed of the average flips the sign, so a rule that holds only while the trend is accelerating moves in and out many times a year.

## References

1. Appel, G. (2005) Technical Analysis: Power Tools for Active Investors. FT Prentice Hall. MACD and the histogram as a measure of changing momentum.
2. Kaufman, P. J. (2013) Trading Systems and Methods. Wiley, fifth edition. Rate of change, acceleration and the noise of differenced trends.
3. Lo, A. W., Mamaysky, H. and Wang, J. (2000) Foundations of Technical Analysis: Computational Algorithms, Statistical Inference, and Empirical Implementation. Journal of Finance 55(4). Smoothing prices before reading patterns from them.
4. Brock, W., Lakonishok, J. and LeBaron, B. (1992) Simple Technical Trading Rules and the Stochastic Properties of Stock Returns. Journal of Finance 47(5).

## Try it

App: https://marketheist.io/backtest/?c=eyJ0aWNrZXIiOiJTUFkiLCJmcmVxdWVuY3kiOiIxZCIsImluZGljYXRvcl9pZCI6ImN1cnZhdHVyZSIsImluZGljYXRvcl9wYXJhbXMiOnsibWFfd2luZG93Ijo1MiwiZGlmZl9sYWciOjQsIm1hX3R5cGUiOiJTTUEifSwicG9zaXRpb25fcnVsZSI6eyJ0eXBlIjoidGhyZXNob2xkIiwidGhyZXNob2xkIjowLCJkaXJlY3Rpb24iOiJhYm92ZSJ9LCJleGVjdXRpb25fZGVsYXkiOjEsInRyYW5zYWN0aW9uX2Nvc3RzX2JwcyI6MCwibGV2ZXJhZ2UiOnsibW9kZSI6Im5vbmUifX0

MCP prompt (MarketHeist MCP server, https://marketheist.io/mcp):

```
Using MarketHeist.io, backtest SPY on daily bars with MA curvature (52-bar simple average, lag 4): hold SPY while the curvature is above 0, otherwise cash, one-bar delay, no costs, over the last 20 years. Report trades per year and compare CAGR and maximum drawdown with buy-and-hold.
```

Historical simulation, not advice.
