What Is the De Casteljau Algorithm?
The De Casteljau algorithm, developed by Paul de Casteljau at Citroën in 1959, is a numerically stable recursive method for evaluating Bézier curves. A Bézier curve is a smooth, parametric curve defined by a set of control points — it does not pass through every control point, but is 'attracted' towards them, creating a smooth interpolated path.
For a cubic Bézier curve (the most common form in trading applications), four control points are used: P0 (start), P1 and P2 (internal control points that shape the curve), and P3 (end). The algorithm recursively applies linear interpolation between adjacent control points at parameter t (0 ≤ t ≤ 1) to find any point on the curve.
The result is a mathematically elegant, smooth curve that naturally represents the 'intended path' of a data series — ignoring short-term noise while preserving genuine directional changes.
Why Apply Bézier Curves to Financial Price Data?
Financial price series are inherently noisy. Every tick contains a mixture of genuine trend information and random noise generated by liquidity imbalances, stop-hunting, slippage, and market microstructure effects.
Simple smoothing methods — moving averages, Bollinger Bands — address this to varying degrees, but they introduce lag. A 20-period moving average, by definition, responds to a price change 10 bars after its midpoint. By the time the average signals a trend change, a significant portion of the move has already occurred.
Bézier curve projection offers a fundamentally different approach: instead of averaging the past to estimate the present trend, it models the geometric shape of the price path and projects where that path is mathematically likely to go, based on the control points derived from recent price structure. This is forward-looking by design, which is what gives it an analytical edge over pure trailing averages.
This is not prediction in the mystical sense. It is geometric projection: given the current curvature and rate of change of the price path, the algorithm estimates where the path would continue if it maintained its current mathematical properties.
Defining Control Points from Price Data
The key engineering challenge is translating real price data into meaningful control points. There are several approaches used in practice:
- ✦Swing point mapping: P0 and P3 are set to the most recent significant swing low and swing high (or vice versa). P1 and P2 are derived from intermediate price structure, such as the midpoint of the prior leg or the Kalman-filtered price at a quarter and three-quarter mark of the lookback window.
- ✦Extrema-based control: Control points are anchored to recent highest highs and lowest lows, with intermediate control points placed at the ATR-adjusted midpoint. This allows the curve to represent the range boundary rather than the midline.
- ✦Velocity-adjusted control: Using the rate of change (first derivative) of price to position control points, the curve can capture acceleration and deceleration — particularly useful for detecting the early stages of a trend exhaustion or reversal.
The String Art Visualization
One of the distinctive visual features of the De Casteljau method when applied to TradingView is the string art pattern. Because the algorithm constructs the curve by repeatedly subdividing the line segments between control points, you can visualise the intermediate construction lines — and this produces an aesthetically striking and informationally dense pattern.
Each intermediate line in the construction represents the linearly interpolated path between two successive control points at a given t value. When plotted at multiple t values simultaneously, they form a geometric 'string art' pattern — a visual representation of the curve's mathematical structure.
This is not merely decorative. The density and convergence pattern of these construction lines provides intuitive visual information about the rate of curvature change — how aggressively the projected price path is turning — which is difficult to convey with a single line.
Combining De Casteljau with Machine Learning
The Quantum DeCasteljau indicator takes the pure Bézier projection as one component of a larger ensemble. The reason: while De Casteljau projection excels at geometric smoothing and short-term projection, it makes no use of the statistical properties of the price distribution, market regime, or cross-asset context.
By feeding the Bézier projection output as one signal among eight models in an ML ensemble — alongside Hurst Exponent (regime), Monte Carlo (probability), Kalman velocity (momentum), Logistic Regression (classification), XGBoost stumps (non-linear patterns), Multi-Head Attention (context weighting), and Array Rotation (pattern library) — the system achieves both geometric elegance and statistical robustness.
The ensemble weights each model's contribution dynamically based on recent accuracy, so in a trending regime the Bézier and Hurst components receive higher weight, while in a ranging regime the Monte Carlo and Logistic Regression components dominate.
Pine Script Implementation Principles
Implementing a cubic Bézier curve in Pine Script v6 requires careful attention to performance, since the recursive nature of the De Casteljau algorithm could be expensive if naively implemented. The practical approach is to pre-compute the curve at a fixed number of t-steps (typically 10–20 points) per bar, using the four control points derived from recent price structure.
For each t in the sequence, the three levels of linear interpolation are computed:
Level 1: Q0 = lerp(P0, P1, t), Q1 = lerp(P1, P2, t), Q2 = lerp(P2, P3, t) Level 2: R0 = lerp(Q0, Q1, t), R1 = lerp(Q1, Q2, t) Level 3: B(t) = lerp(R0, R1, t)
The resulting B(t) values form the projected curve. The string art lines are drawn by connecting the Level 1 and Level 2 intermediate points with `line.new()` calls, creating the characteristic visual pattern.
On higher timeframes (1H+), increase the lookback window for control point selection to capture larger-scale curve structure. On 15M, a shorter lookback prevents the curve from 'seeing through' short-term consolidations.