Stochastic With Trend Filter EA
Trading every stochastic %K/%D cross on its own means taking oversold buy signals in a falling market and overbought sell signals in a rising one - exactly the counter-trend trades that lose most often. Adding a slow trend MA as a direction filter is the standard fix: price above the trend MA allows buys only, price below allows sells only, and the stochastic is reduced to timing the entry within whichever direction the trend already permits. The filter is asymmetric, the same shape used elsewhere in this catalogue for indicator-filtered systems: it only gates new entries. An existing position is always closed the moment the opposite %K/%D cross appears, regardless of where price sits relative to the trend MA at that instant - that exit is the stochastic itself turning, not the trend changing, so re-applying the entry filter before letting the EA leave would trap the position past the point the signal already fired. Stop loss and take profit are fixed pip distances, converted to points per-symbol from the broker's own digit count. Position sizing can run as a fixed lot or, with InpUseRiskSizing on, as a percentage of equity risked to the stop distance, using MODE_TICKVALUE and MODE_TICKSIZE rather than a hardcoded contract size so it prices correctly on gold, indices and JPY crosses as well as plain FX pairs. Notes and limitations - Both the trend filter and the stochastic zone must agree before an entry is taken, so signals are less frequent than a bare stochastic cross - by design, not by accident. - Signals are evaluated once per closed bar, not on every tick. - One position at a time, tracked by InpMagicNumber. It will not manage or interfere with trades opened manually or by another EA. - Requires AutoTrading enabled; if trading is disabled the EA logs it and skips the entry. - On the MQL5 build, entries refuse on a netting account if the chart symbol already carries a position under a different magic number - see MQL4 VERSUS MQL5 DIFFERENCES above.
Expert advisor · MT4 · v1.0 · Free
About Stochastic With Trend Filter EA
Stochastic With Trend Filter EA is an expert advisor (trading robot) for MetaTrader 4 based on Stochastic and Moving Average. It can size trades from your balance and risk percent. It has 15 settings, such as Trend ma period, K period and D period. MQL source code included.
Files in the download: StochasticTrendEa.ex4, StochasticTrendEa.mq4, StochasticTrendEa.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 |
|---|---|---|
| Trend ma period | 100 | Trend filter MA period (price vs this MA sets direction) |
| K period | 5 | Stochastic %K period |
| D period | 3 | Stochastic %D period |
| Slowing | 3 | Stochastic slowing |
| Oversold level | 20.0 | %K level below which a buy cross is valid |
| Overbought level | 80.0 | %K level above which a sell cross is valid |
| Stop loss pips | 50 | Stop loss distance, in pips |
| Take profit pips | 100 | Take profit distance, in pips (0 = none) |
| Use risk sizing | false | Size by percent risk instead of a fixed lot |
| Risk percent | 1.0 | Percent of equity risked per trade, when risk sizing is on |
| Fixed lots | 0.10 | Lot size when risk sizing is off, or as a fallback |
| Magic number | 20260804 | Magic number for orders opened by this EA |
| Slippage pips | 3 | Slippage tolerance, in pips |
| Max retries | 5 | Attempts per trade action before giving up |
| Retry wait ms | 500 | Pause between attempts, milliseconds |
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: Stochastic · Moving Average · Buy/Sell Arrows · Trend · Risk & Lot Size · MT4 Expert Advisor · MQL4 Source Code