We present CSavGolFilter, a causal Savitzky–Golay implementation for MQL5 that evaluates a local polynomial at the most recent closed bar. It delivers smoothed price, velocity, and acceleration via precomputed convolution kernels, avoiding per-tick matrix work. The package includes an indicator, a simple EA, and a self-test that proves the non-repainting property and validates kernel identities.
Most of the momentum tools available natively in MQL5 come from finite differencing: subtract yesterday's price from today's, divide by the time step, call it velocity. Do it twice and call it acceleration. It works, but differencing amplifies noise badly — every tick of market microstructure noise gets multiplied, not averaged out, and a second difference multiplies it again. The Savitzky-Golay filter exists precisely to fix this: fit a low-degree polynomial to a local window of data by least squares, then read the value and derivatives off the fitted polynomial itself instead of off the raw, noisy samples.
The textbook Savitzky-Golay filter is centered: its fitting window uses samples from both before and after the estimated point. This is fine offline, but impossible on a live chart because the "future" bars do not exist yet. This article builds the one-sided variant instead. The fitting window is entirely trailing, made up of bars that have already closed, and the polynomial is evaluated only at the window's own rightmost point: the most recently closed bar. Nothing computed for a closed bar can ever change once that bar closes, because nothing after it was ever part of the computation. That is the non-repainting property this article sets out to prove, not just assert.
Every quantitative claim is backed by a specific check. Kernel identities are verified on a synthetic polynomial. Non-repainting extraction is checked on real history using two parameterizations of the same API. The demo EA is backtested on three instrument/timeframe combinations, and all results are reported as obtained, including failures.
Allow the use of cookies to log in to the MQL5.com website.
Please enable the necessary setting in your browser, otherwise you will not be able to log in.
You are signed in. Two-factor authentication has been disabled. Set it up again and scan a new QR code, or continue with two-factor authentication disabled.
Check out the new article: Causal Savitzky-Golay Kinematics in MQL5: Non-Repainting Velocity and Acceleration from Local Polynomial Fits.
Most of the momentum tools available natively in MQL5 come from finite differencing: subtract yesterday's price from today's, divide by the time step, call it velocity. Do it twice and call it acceleration. It works, but differencing amplifies noise badly — every tick of market microstructure noise gets multiplied, not averaged out, and a second difference multiplies it again. The Savitzky-Golay filter exists precisely to fix this: fit a low-degree polynomial to a local window of data by least squares, then read the value and derivatives off the fitted polynomial itself instead of off the raw, noisy samples.
The textbook Savitzky-Golay filter is centered: its fitting window uses samples from both before and after the estimated point. This is fine offline, but impossible on a live chart because the "future" bars do not exist yet. This article builds the one-sided variant instead. The fitting window is entirely trailing, made up of bars that have already closed, and the polynomial is evaluated only at the window's own rightmost point: the most recently closed bar. Nothing computed for a closed bar can ever change once that bar closes, because nothing after it was ever part of the computation. That is the non-repainting property this article sets out to prove, not just assert.
Every quantitative claim is backed by a specific check. Kernel identities are verified on a synthetic polynomial. Non-repainting extraction is checked on real history using two parameterizations of the same API. The demo EA is backtested on three instrument/timeframe combinations, and all results are reported as obtained, including failures.
Author: Sanmi Samuel Ojo