All indicators

Savitzky-Golay Filter (SGF)

A smoothing line built from a polynomial fitting kernel, which at the default order keeps the height of a swing better than a plain moving average of the same length.

BTCUSD1h
Fixed data to Oct 6, 2026, UTC
Loading the chart

The SGF is a smoother that weights a fixed window of past prices with a kernel taken from a closed-form polynomial weighting. A plain average gives every bar in its window the same weight, which flattens peaks and troughs. At the default order of 2 the kernel gives the middle of the window the most weight and lets the weights fall away, and turn negative, toward both ends, so a swing keeps more of its height.

The window is always an odd number of bars: an even setting is rounded down by one. For a polynomial order of 2 the weight of the tap k places from the centre is 3 * (3 * N * N - 7 - 20 * k * k), where N is the window size; for order 4 it is 15 + k * k * (6 * k * k - 20), which is positive everywhere and grows quickly toward the ends of the window. Any other order uses a simple triangle. The weights are normalised to sum to one and then applied with the newest bar taking the first tap, so the line is computed from past bars only.

On the first bars, before a full window exists, the taps that would reach before the first bar are skipped and the remaining weights are renormalised, so the line answers from the first bar. If the polynomial order is not smaller than the window, the line is not drawn.

How to read Savitzky-Golay Filter (SGF)

At the default order, read the SGF as a smoothed price that keeps peaks and troughs sharper than a simple moving average of the same window. Because the kernel is symmetric and is applied to past bars only, its centre sits about half a window back, so its turns arrive roughly as late as the moving average's. When price crosses it or it changes direction, that is the filter's view of a change in short-term direction. Because the weights at both ends of the window are negative, a sharp move first nudges the line the wrong way for a bar or two and later makes it overshoot before it settles.

A longer window removes more noise and responds later. The line is computed only from bars that have closed, so it never repaints, but it still lags price; it is a picture of where price has been, not a forecast of where it goes next.

Settings

Window Size
How many bars the kernel spans. An even number is rounded down to the odd number below it. Larger windows smooth more and lag more.
Polynomial Order
The order of the closed-form weighting, 2 or 4. Order 2 favours the middle of the window; order 4 gives its largest weights to the newest and oldest bars of the window. Any other value falls back to a triangular weighting.
Source
The price series the filter smooths, the close by default.

Frequently asked questions

Why does an even window size behave like the odd number below it?

The kernel needs a single middle tap, so the window is always odd. A setting of 20 runs as 19.

Why does the line sometimes dip against a sharp move and then overshoot it?

At order 2 the weights at both ends of the window are negative, which is how the filter preserves peaks. A jump first meets the negative weights at the newest end, which pull the line briefly the wrong way; while the oldest taps still hold the earlier price, their negative weights push the line past the new level, until the jump has crossed the whole window.

Why is the line missing entirely?

If the polynomial order is equal to or larger than the window size, the fit is undefined and nothing is drawn. Raise the window size above the order.

Write your own in OpenScript

Every study here is plain OpenScript. Change a setting, combine two, or turn one into a strategy, then backtest it in /trading and run it in sandbox trading (analyzer mode in OpenAlgo) before going further.