Skip to content

Free MT5 Expert Advisor

Stochastic Pullback EA

MT5 Expert Advisor that buys stochastic crosses out of oversold in an uptrend and sells crosses out of overbought in a downtrend.

Trendv1.0MetaTrader 5 (MQL5) Compiles with 0 errors Stop-loss on every trade
Strategy
When EMA 50 is above EMA 200 and price is above EMA 200, it buys a stochastic %K cross above %D from the oversold zone; in a downtrend it sells the mirror cross from overbought.
Risk model
1% of balance per trade (configurable), ATR-based stop-loss on every order, one position at a time

What it does

Stochastic Pullback EA joins an existing trend after a pullback. Two EMAs decide the trend direction, and the stochastic oscillator times the entry when a dip in an uptrend (or a rally in a downtrend) starts to turn.

How it works

The stochastic uses %K 14, %D 3, slowing 3, calculated on the low/high range. On every new bar the EA reads the last two closed bars:

  • Uptrend: EMA 50 above EMA 200 and the last close above EMA 200.
  • Downtrend: EMA 50 below EMA 200 and the last close below EMA 200.
  • Buy: in an uptrend, %K was at or below %D on the older bar and above %D on the last bar, and either line was at or below 20 on the older bar.
  • Sell: in a downtrend, %K was at or above %D and then crossed below it, with either line at or above 80 on the older bar.
  • Stop-loss: 1.5 × ATR(14) from the entry price. Take-profit: 1.5 × the stop distance.

Signals against the trend are logged and skipped, so the log shows how often the filter blocks a trade. The moving averages lesson covers how the 50/200 pair is commonly used.

How to use it

Use it on instruments that trend for weeks at a time. On H1 the 200 EMA covers roughly eight trading days; on H4 it covers several weeks, which gives a steadier trend read. If you want fewer but deeper pullbacks, lower the oversold level to 10 and raise the overbought level to 90. Combine it with the Risk Reward Calculator to compare target settings.

Settings

InputDefaultWhat it changes
Stochastic %K / %D / slowing14 / 3 / 3Oscillator shape
Oversold / Overbought20 / 80Zones a cross must start from
Fast / Slow trend EMA50 / 200Trend filter
ATR period / Stop-loss (x ATR)14 / 1.5Stop size
Reward:risk target1.5Take-profit, 0 disables it
Risk per trade / Fixed lots1.0% / 0Position sizing
Max spread (points)30Spread filter
Trading start / end hour7 / 20Server-time window
Break-even / Trailingon / offStop management

Limitations

The EMA filter lags, so the EA keeps buying pullbacks for a while after a trend has actually ended. In sideways markets the EMAs cross back and forth and the stochastic gives many crosses that go nowhere. The stochastic can stay in the oversold zone during sharp selloffs, producing early entries.

Before you run it live

Backtest it in the Strategy Tester on several years and symbols, including periods with no clear trend, then trade it on a demo account. Make sure the trading window is set in your broker's server time and that the spread limit suits the symbol. Keep risk per trade small. Past behavior does not guarantee future results.

Key inputs

Key inputs of Stochastic Pullback EA
InputDefaultDescription
Stochastic %K period14Lookback for the stochastic high-low range.
Stochastic %D period3Smoothing of the signal line.
Oversold level20Zone a buy cross must start from.
Overbought level80Zone a sell cross must start from.
Fast trend EMA50Fast EMA of the trend filter.
Slow trend EMA200Slow EMA of the trend filter.
Stop-loss distance (x ATR)1.5Stop size as a multiple of ATR(14).
Take-profit as a multiple of the stop (0 = none)1.5Reward-to-risk target.

Educational tools, not advice. Automated trading can lose money quickly. Indicators and Expert Advisors describe price; they do not predict it, and past behaviour does not guarantee future results. Test everything on a demo account first and never risk money you cannot afford to lose. See our disclaimer.

Keep exploring

Related mt5 expert advisors