PolynomialInterpolation
Background
Polynomial interpolation fits a smooth curve of a chosen degree through a window of recent data and reads off its value at the most recent point. A degree-2 polynomial is a parabola, degree-3 adds an inflection, and so on — higher degrees follow finer wiggles. Because the fit uses a least-squares approach, the result is a smoothed, low-lag estimate of where the series "really" is, less jumpy than the raw data.
Traders use it as a smoothing and fitting tool — for example to smooth a noisy indicator, to estimate the current slope or curvature of price, or as a responsive alternative to a moving average. It uses an orthogonal-polynomial method internally, which keeps the fit numerically stable even at higher degrees.
Included formula
The toolbox ships a ready-made Polynomial Interpolation indicator, so you can use it without writing any code. In AmiBroker open the Charts window, expand the WiseTraderToolbox group and drag Polynomial Interpolation onto a price chart.
It plots the fitted, smoothed curve over price; you set the number of periods, the polynomial degree and an extra smoothing length from its parameters. A companion Polynomial Bands formula plots an upper and lower band around the same curve.
The exported function
If you would rather build your own formula, the toolbox exports the calculation as a single AFL function you can call directly — it is the engine inside that indicator.
PolynomialInterpolation(DataArray, Periods, Degree)
| Parameter | Description |
|---|---|
| DataArray | The array the polynomial is fitted to. It must not contain empty/null values at the left edge of the data. |
| Periods | The look-back window — how many bars the polynomial is fitted through at each
bar. It must be at least as large as Degree. |
| Degree | The degree of the polynomial. Must be 2 or greater (2 = a parabola, 3 = a cubic, and so on). Higher degrees track finer detail but can be less smooth. |
Returns a per-bar array holding the fitted polynomial's value at the current bar.
Usage
// Fit a degree-3 polynomial through the last 20 bars of Close.
smooth = PolynomialInterpolation( Close, 20, 3 );
Plot( Close, "Price", colorDefault, styleCandle );
Plot( smooth, "Poly fit", colorRed );
Keep Degree low (2–4) for a smooth, stable curve. A large
Periods with a low degree behaves like a gentle moving average; a smaller
window with a higher degree hugs price more closely.
Degree must be at least 2 and Periods must be at least equal
to Degree, or the indicator returns an empty result.