Seasonal Decomposition Panel
Every market has a repeating time-of-day (or, on daily+ charts, day-of-week) rhythm layered on top of its slower trend - the London/New York overlap behaves differently from the Asian session, Monday often behaves differently from Friday. A plain moving average shows the trend but throws that rhythm away with everything else it smooths out. This indicator separates the two: a trailing simple moving average extracts the trend, the DETRENDED series (price minus trend) is then averaged across the last N occurrences of the same time-of-day bucket (or weekday, on D1 and above) to build the seasonal component, and whatever is left over after removing both is the residual. HONEST SIMPLIFICATION, stated plainly: this is not full STL decomposition (Cleveland, Cleveland, McRae & Terpenning, 1990). Real STL fits the trend and seasonal components with an iterative, robust Loess smoother that re-weights outliers and lets the seasonal shape itself drift slowly over time. MQL4 has no Loess solver, and hand-rolling one would be far more machinery than a CodeBase indicator should carry. This uses a plain trailing SMA for the trend and a simple mean-of-matching-buckets for the seasonal component instead - additive, single-pass, non-robust. It captures the same core idea (trend plus a repeating pattern plus what's left over) without STL's iterative robustness, and a single wild bar can influence the seasonal average of its bucket more than it would under STL's robust weighting. MQL4 allows exactly one subwindow per indicator file, so "three panes" here means three lines stacked with a fixed vertical offset (a multiple of ATR(14)) inside that one subwindow, not three physically separate chart panels - the trend band sits on top, seasonal in the middle, residual at the bottom, each recentred to its own offset so all three are visible at a comparable scale rather than the trend line (price-scale) dwarfing the much smaller seasonal and residual deviations. Notes and limitations - Honest simplification of STL - see the FULL DESCRIPTION above. Trend is a plain trailing SMA, seasonal is a mean-of-matching-buckets, neither uses STL's iterative robust Loess smoothing. - On D1 and above, "seasonal" falls back to a weekday bucket (Monday through Friday) rather than a time-of-day bucket, since there is no intraday cycle to measure at that timeframe. - The seasonal backward scan only looks at PAST bars relative to each displayed bar, never future ones - no lookahead - but it is bounded to a maximum scan depth for performance, so on a very short history the seasonal average may be built from fewer than InpSeasonalCycles matches. - All three bands are shown as DEVIATIONS re-centred around their own pedestal offset, not in raw price terms - read the shape and relative size of each band, not its absolute on-screen level. - Recomputes its whole displayed window on every new bar; not intended to be read as a fixed permanent record the way a simple SMA line is.
Indicator · MT5 · v1.0 · Free
About Seasonal Decomposition Panel
Seasonal Decomposition Panel is an indicator for MetaTrader 5 based on ATR. It has 4 settings, such as Trend period, Seasonal cycles and Max bars. MQL source code included.
Files in the download: SeasonalDecompositionPanel.ex5, SeasonalDecompositionPanel.mq5, SeasonalDecompositionPanel.txt.
Settings
| Setting | Default | What it does |
|---|---|---|
| Trend period | 20 | Bars in the trailing SMA used to extract the trend |
| Seasonal cycles | 10 | Matching time-of-day/weekday occurrences averaged per seasonal value |
| Max bars | 300 | Bars from the current one back that the panel computes (bounds cost) |
| Pane gap atr mult | 6.0 | Vertical gap between the three bands, in ATR(14) multiples |
How to install
- Download the ZIP from your PolyMaria library and unzip it.
- In MetaTrader 5 open File → Open Data Folder, then go to MQL5 → Indicators.
- Copy the .mq5 file(s) there. Put any .mqh files in MQL5 → Include.
- Open the .mq5 file in MetaEditor and press Compile (F7) if MetaTrader does not show it.
- Drag the indicator from the Navigator onto a chart and adjust the settings.
Tags: Moving Average · Trend · Trading Sessions · Trailing Stop & Break-even · ATR · MT5 Indicator · MQL5 Source Code