Loading…

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

SettingDefaultWhat it does
Trend ma period100Trend filter MA period (price vs this MA sets direction)
K period5Stochastic %K period
D period3Stochastic %D period
Slowing3Stochastic slowing
Oversold level20.0%K level below which a buy cross is valid
Overbought level80.0%K level above which a sell cross is valid
Stop loss pips50Stop loss distance, in pips
Take profit pips100Take profit distance, in pips (0 = none)
Use risk sizingfalseSize by percent risk instead of a fixed lot
Risk percent1.0Percent of equity risked per trade, when risk sizing is on
Fixed lots0.10Lot size when risk sizing is off, or as a fallback
Magic number20260804Magic number for orders opened by this EA
Slippage pips3Slippage tolerance, in pips
Max retries5Attempts per trade action before giving up
Retry wait ms500Pause between attempts, milliseconds

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 → Experts.
  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 expert advisor from the Navigator onto a chart, check the settings, allow Algo/Auto Trading and press OK.
  6. Test it first on a demo account or in the Strategy Tester.

Download the PDF guide

Tags: Stochastic · Moving Average · Buy/Sell Arrows · Trend · Risk & Lot Size · MT4 Expert Advisor · MQL4 Source Code

Expert advisors (EA) for MT4 & MT5 · PolyMaria