Loading…

Antialiased Downsampler

Downsampling by simply keeping every Nth point is a classic signal-processing mistake. Any short-period wobble in the source series that happens to line up with the sampling interval does not disappear - it folds down into a slow, entirely fake pattern in the coarse series, one that looks exactly like a real low-frequency trend even though nothing like it exists in the original data. This is aliasing, and it shows up any time a chart, indicator, or analysis pipeline needs to build a lower-resolution view of a series (a weekly view from daily bars computed by hand, a coarse overlay for a long lookback, a reduced-resolution export). This header applies a triangular (Bartlett) low-pass filter centred on each kept sample before decimating, suppressing exactly the high-frequency content that would otherwise fold down and masquerade as trend. It also exposes the naive, unfiltered decimation directly (AdsNaiveDecimate) so the difference is visible side by side rather than asserted - the demo prints both coarse series from the same source and compares a roughness proxy between them. Notes and limitations A triangular window is a real but modest low-pass filter, not a brick-wall anti-alias filter - it substantially reduces, but does not perfectly eliminate, aliasing for content very close to the new Nyquist frequency (roughly half the decimation factor). For most price-series coarsening this is a large, honest improvement over no filtering at all, which is exactly the naive baseline the demo compares against. The output length is floor(n / factor); any remaining source samples that don't fill a final full window are dropped rather than folded into a short final point. The filter window shrinks near the start and end of the array (fewer real samples averaged, renormalised by the actual weight sum used) rather than reading out of bounds or padding with zeros.

Script · MT4 · v1.0 · Free

About Antialiased Downsampler

Antialiased Downsampler is a script for MetaTrader 4. It has 2 settings, such as Sample count and Factor. MQL source code included.

Files in the download: AntialiasedDownsampler.mqh, AntialiasedDownsampler.txt, AntialiasedDownsamplerDemo.mq4.

Settings

SettingDefaultWhat it does
Sample count90length of the synthetic source series
Factor6decimation factor (keep 1 sample per InpFactor)

How to install

  1. Download the ZIP from your PolyMaria library and unzip it.
  2. In MetaTrader 4 open File → Open Data Folder, then go to MQL4 → Scripts.
  3. Copy the .mq4 file(s) there. Put any .mqh files in MQL4 → Include.
  4. Open the .mq4 file in MetaEditor and press Compile (F7) if MetaTrader does not show it.
  5. Drag the script onto a chart to run it once.

Download the PDF guide

Tags: Buy/Sell Arrows · Trend · MT4 Script · MQL4 Source Code

MQL4 & MQL5 scripts · PolyMaria