Modular Signal Filter Framework
A signal that fires correctly is only half the problem; whether it fires into a session with no liquidity, against the prevailing trend, during a spread spike, or on a day you have already decided to sit out is the other half, and most published EAs bury that logic inline where it cannot be turned on and off independently. This template pulls it out into five separate filter functions, each with its own enable switch and its own inputs, called in a fixed pipeline that reports every filter's individual verdict. MQL4 has no function pointers or delegates, so "modular" here means each filter has the identical shape - read its own inputs, judge the current state or the signal direction, return pass or block - and knows nothing about the others. Adding a sixth filter means writing one more function in that shape and adding one line to PassesAllFilters(); no filter needs to change when another is added, removed or reordered. When a signal is blocked, the on-chart panel and the Experts log both show the full per-filter breakdown - pass, block, or skipped if that filter is disabled - so tuning which filter is too strict does not require guesswork. The fast/slow moving average cross wired up as DetectRawSignal() is a placeholder only; the filter pipeline is the reusable part and works identically regardless of what raw condition feeds it. Notes and limitations - The pipeline short-circuits its final pass/fail verdict on the first block for the trading decision, but the report always evaluates and shows every filter's individual result, so a blocked signal never hides which other filters would also have blocked it. - All five filters are placeholders in the sense that their thresholds are generic; the trend and volatility filters in particular should be tuned to the instrument and timeframe actually traded before relying on them. - The day-of-week filter blocks unconditionally on a weekend, since no session exists to evaluate. - On MQL5 with a netting account, a demo order is refused (not queued or retried) whenever the chart's symbol already carries a foreign-magic position - see MQL4 VERSUS MQL5 DIFFERENCES above.
Expert advisor · MT4 · v1.0 · Free
About Modular Signal Filter Framework
Modular Signal Filter Framework is an expert advisor (trading robot) for MetaTrader 4 based on Moving Average and ATR. It trades only in the hours you set (time filter). It has 25 settings, such as Fast ma period, Slow ma period and Use session filter. MQL source code included.
Files in the download: SignalFilterFramework.ex4, SignalFilterFramework.mq4, SignalFilterFramework.txt.
Trading robots can lose money. Check every setting and test on a demo account before using real funds.
Settings
| Setting | Default | What it does |
|---|---|---|
| Fast ma period | 10 | Fast MA period for the placeholder signal |
| Slow ma period | 30 | Slow MA period for the placeholder signal |
| Use session filter | true | Only allow signals inside a server-time hour window |
| Session start hour | 7 | Session start, server time, 0-23 |
| Session end hour | 20 | Session end, server time, 0-23 (exclusive) |
| Use spread filter | true | Block signals when the spread is too wide |
| Max spread pips | 3.0 | Maximum acceptable spread, pips |
| Use trend filter | true | Only allow signals that agree with the longer trend |
| Trend ma period | 100 | MA period defining the longer trend |
| Use volatility filter | true | Block signals when volatility is outside a sane range |
| Atr period | 14 | ATR period for the volatility filter |
| Min atr pips | 3.0 | Below this ATR, the market is judged too quiet to trade |
| Max atr pips | 60.0 | Above this ATR, the market is judged too wild to trade |
| Use day filter | false | Block signals on specific weekdays |
| Allow monday | true | |
| Allow tuesday | true | |
| Allow wednesday | true | |
| Allow thursday | true | |
| Allow friday | true | |
| Enable trading | false | Off by default - place a demo order when a signal clears every filter |
| Lots | 0.01 | Lot size for the demo entry |
| Stop loss pips | 30 | Stop loss distance, in pips |
| Slippage pips | 3 | Slippage tolerance, in pips |
| Max retries | 5 | OrderSend attempts before giving up |
| Magic | 20261303 | Magic number this EA tags its own orders with |
How to install
- Download the ZIP from your PolyMaria library and unzip it.
- In MetaTrader 4 open File → Open Data Folder, then go to MQL4 → Experts.
- Copy the .mq4 file(s) there. Put any .mqh files in MQL4 → Include.
- Open the .mq4 file in MetaEditor and press Compile (F7) if MetaTrader does not show it.
- Drag the expert advisor from the Navigator onto a chart, check the settings, allow Algo/Auto Trading and press OK.
- Test it first on a demo account or in the Strategy Tester.
Tags: Buy/Sell Arrows · Trend · Trading Sessions · Time Filter · Moving Average · ATR · MT4 Expert Advisor · MQL4 Source Code