The Math Behind the Trend

Every Pretrend market resolves through ordinary least squares — a regression technique with 220 years of history and a precise definition of "best." This page shows what it computes, why it is hard to fool, and why nothing simpler does the job.

Thirty prices, one number

A 30-minute BTC market produces 30 one-minute closes. Resolution has to compress them into a single number: how much did the series move, and in which direction? The shortcut everyone reaches for first — compare the close to the open — uses exactly 2 of the 30 points. In the July 7 market on our Examples page, close-versus-open reads +0.212%, which would resolve the market as Moon. The line fitted through all 30 points says +0.064% — Bull. Two points told a story the other twenty-eight don't support.

OLS asks a better question: of every straight line you could draw through the data, which one has the smallest total error? Error is measured as the vertical gap between each price and the line — a residual — and OLS minimizes the sum of the squared residuals. Squaring does two jobs: it treats overshoot and undershoot symmetrically, and it makes large misses count for more than small ones.

Try to beat it

Below are the 30 real closes from the June 3 market — the one that crashed. Drag the slider to tilt the line and watch the residuals and their total cost. Every candidate line pivots through the mean point, because the best line provably passes through it.

mean point (x̄, ȳ)0 min30 minJune 3, 2026 market · 30 one-minute BTC closes
minimumresidual cost SSE(slope)
Your line
+0.000% · SSE 719,065
OLS solution
-0.535% · SSE 388,071
Verdict
330,994 above the minimum

The curve under the slider is the total residual cost of every possible slope — a parabola with exactly one minimum. OLS doesn't search for it; it solves for it in closed form. No iteration, no starting guess, no parameters to tune.

The whole method is three lines

With time steps x₁…xₙ and prices y₁…yₙ, the slope is the covariance of price with time divided by the variance of time:

slope  b = Σ(xᵢ − x̄)(yᵢ − ȳ) / Σ(xᵢ − x̄)²
intercept  a = ȳ − b·x̄
trend% = (ŷₙ − ŷ₁) / ŷ₁ × 100

Pretrend's trend is the percentage change along the fitted line from the start of the market to the end — not between any two raw prices. A worked example with five points, small enough to check by hand:

x (min)y (price)x − x̄y − ȳ(x − x̄)(y − ȳ)(x − x̄)²
0100.0−2−1.02.04
1101.0−10.00.01
2100.50−0.50.00
3102.011.01.01
4101.520.51.04
x̄ = 2, ȳ = 101Σ = 4.0Σ = 10

So b = 4 / 10 = 0.4 per minute, a = 101 − 0.4·2 = 100.2. The fitted line runs from 100.2 to 101.8, and the trend is 1.6 / 100.2 = +1.60%. That's the entire computation — a handful of multiplications and one division, which is why it fits in a blockchain precompile and returns the same answer on every node.

Proven for 220 years

Least squares was published by Legendre in 1805; Gauss — who claimed he had been using it since 1795 — built its probabilistic foundations and used its machinery in the celebrated recovery of the dwarf planet Ceres, lost behind the sun after five weeks of observations. The Gauss–Markov theorem later made "best" precise: among all linear unbiased estimators, OLS has the minimum variance. Under its assumptions, no other straight-line estimate is systematically closer to the truth. It has been the standard measure of trend ever since:

  • The beta shown on every stock terminal is an OLS slope.
  • The °C-per-decade warming figures in IPCC reports are OLS slopes.
  • Trend GDP growth, unemployment trajectories, and inflation momentum in central bank papers: OLS slopes.
  • Dose-response curves, sensor drift calibration, Moore's law charts: OLS.

Market noise is not perfectly Gaussian, and OLS does not require it to be — the Gauss–Markov result needs only uncorrelated, equal-variance errors. Where reality deviates, Pretrend's design absorbs it: thresholds are calibrated from each data source's own history, and every fit ships with its own quality score.

Hard to fool

Because every point carries equal weight, moving the trend requires moving the market — not the price. A rule that only reads the close can be flipped by a single trade timed to the bell. Try it on the July 7 market:

OLS fit (all 30 points)July 7, 2026 market · 30 one-minute BTC closes
Close vs open (2 points)
+0.212% Moon
OLS trend (30 points)
+0.064% Bull

A +0.3% spoofed final price more than doubles the two-point reading and would hand the market to Moon. The OLS trend moves a few hundredths of a percent and stays in Bull. To shift a regression you must hold the price away from its path for many observations against real order flow — an attack that costs real money and is visible in the data. This is the manipulation model behind the whitepaper's oracle design.

The fit grades itself

OLS ships with its own confidence measure. R² is the share of price variance the fitted line explains: 1.0 is a perfect straight march, 0 is structureless noise. Two series with the same slope are not the same signal:

Quiet series: R² = 0.99
Noisy series: R² = 0.54

The Trend precompile returns R² alongside every slope, so anything built on Pretrend can distinguish conviction from coincidence — and void markets whose data never carried a signal at all.

What about the alternatives?

MethodWhat it usesWhere it breaks
Close minus open2 of n pointsOne trade at the bell decides the market
High minus low2 extreme pricesA single wick sets the outcome; says nothing about direction
Moving-average deltaSmoothed endpointsLags the data; the window length changes the answer
Theil–Sen median slopeAll point pairsRobust, but O(n²) work for marginal gain on already-averaged closes
Kalman filter / EMARecursive stateTuning parameters become a governance attack surface
OLSEvery point, equallyClosed form, O(n), provably minimum-variance, self-grading via R²

On Vitruveo the entire computation — slope, R², and volatility — is a single precompile call at 0x…DC, deterministic on every node. See it run against live chain data on the Examples page, or read the resolution spec in the whitepaper.