Stochastic Crossover EA for MT5 — No Code
Can I build a Stochastic crossover EA for MT5 without coding?
Yes. Add Stochastic on Step 3 — Entry rules in AlfaTactix Strategy Builder. Buy rule: Stoch crosses above Stoch %D ( %K crosses above %D ). Sell rule: crosses below (or switch on Sell mirrors Buy). Keep %K length 14, %K smoothing 3, %D length 3, Overbought level 80, Oversold level 20. Add a Stop loss in Step 5, press Save strategy in Step 7, then Get the code, compile once, backtest H1 EURUSD with Every tick in the Strategy Tester.
Disclosure: Educational build guide — not financial advice. Backtest and Demo do not guarantee live profits.
Related guides: Stochastic Indicator (academy) · RSI Overbought/Oversold EA — No Code · Build EA Without Coding · Backtest in Strategy Tester · EA Strategy Library
What Is a Stochastic Crossover EA?
A Stochastic crossover Expert Advisor automates entries when the %K and %D lines interact:
| Signal | Rule (this guide) |
|---|---|
| Buy | %K crosses above %D — Stoch crosses above Stoch %D |
| Sell | %K crosses below %D — Stoch crosses below Stoch %D |
Alternative: cross out of the oversold or overbought zone (the Level tab: Oversold level / Overbought level) — shown below.
The EA runs on OnTick() [1]. Strategy Builder exports iStochastic [2] logic — you do not hand-write CopyBuffer calls.
Classic Settings and When It Works
| Setting | Starter | Notes |
|---|---|---|
| %K length | 14 | %K lookback |
| %K smoothing | 3 | Extra %K smoothing |
| %D length | 3 | %D smoothing |
| Overbought level | 80 | Zone cap |
| Oversold level | 20 | Zone floor |
| Trading timeframe (Step 2) | H1 | M15 = more signals; H4 = fewer |
| Symbol | EURUSD | Tight spread helps |
Works best: Range-bound or pullback markets after a move into oversold/overbought.
Struggles in: Strong trends — Stochastic can stay pegged high/low. Combine with trend filter (MA Crossover EA) or session filter.
Theory: Stochastic Indicator guide.
Stochastic Parameters in Strategy Builder
| Setting | Range | Default |
|---|---|---|
| %K length | 1 – 200 | 14 |
| %K smoothing | 1 – 50 | 3 |
| %D length | 1 – 50 | 3 |
| Overbought level | 50 – 100 | 80 |
| Oversold level | 0 – 50 | 20 |
The indicator is added from the picker in Step 3. The timeframe it reads is the one you set in Step 2 (Timeframes): pick H1 there as the trading timeframe.
Stochastic Condition Types Explained
Step 3 has a Buy rule and a Sell rule. Each line reads like a sentence: Buy when [What to watch] [How they compare] [Compare with]. The Stochastic lines are Stoch (%K) and Stoch %D.
1. Crosses (recommended for this guide)
| Part of the line | Choice |
|---|---|
| What to watch | Stoch |
| How they compare | crosses above / crosses below |
| Compare with | Stoch %D (Indicator tab), or a level (Level tab), or a number (Number tab) |
Starter recipe: Buy when Stoch crosses above Stoch %D; Sell when Stoch crosses below Stoch %D.
Zone exit variant: Buy when Stoch crosses above its Oversold level (20); Sell when Stoch crosses below its Overbought level (80). Pick the level in the Level tab.
2. Is above / is below
How they compare also offers is above, is below, is at or above and is at or below, with a number in Compare with (Number tab).
Use case: “Only trade when Stoch is above 50” as a trend filter, added as a second line in an All of these group.
3. Divergence
How they compare: diverges from price. The form asks for the divergence type (regular or hidden, bullish or bearish), the swing points (left and right bars, 5 and 5 to start) and the distance between swings (5 to 60 bars to start).
4. Rising / falling
is rising / is falling, with Over how many bars and Minimum change.
5. Time window
On a line, Time window offers Happened within the last N bars and Has been true for N bars in a row. The second is not offered with crosses.
Build the Stochastic EA Step by Step
Step 1 — Information and platform
Name: Stochastic K/D H1 EURUSD
Step 2 — Timeframes
Add H1 as the trading timeframe.
Step 3 — Entry rules
- Buy rule → under What to watch, pick Stochastic (Indicator tab).
- Settings: %K length 14, %K smoothing 3, %D length 3, Overbought level 80, Oversold level 20.
- Line: Stoch crosses above Stoch %D.
- Sell rule → switch on Sell mirrors Buy, or write Stoch crosses below Stoch %D yourself.
Optional AND: add a line in an All of these group: Stoch is above 20 (already left the oversold zone).
Step 4 — Filters
Session or spread — Advanced EA MTF & Filters.
Steps 5 and 6 — Exits, risk and money management
Step 5: Stop loss, optional Take profit. Step 6: Position size. EA Risk Management.
Step 7 — Review and save
Fix anything in the Check list, then Save strategy and Get the code.
Stochastic and MA Confluence: Add a Trend Filter
A Stochastic-only EA buys the moment %K crosses %D, even while price is still below the slow average; an MA-only EA enters late and whipsaws in chop. Confluence means two independent rules must both be true before the EA opens a trade: Stochastic times the momentum, a moving-average cross confirms the trend.
| Signal | Buy rule / Sell rule in Step 3 (group: All of these) |
|---|---|
| Buy | Stoch crosses above Stoch %D, and SMA(10) crosses above SMA(20) |
| Sell | Stoch crosses below Stoch %D, and SMA(10) crosses below SMA(20) — or switch on Sell mirrors Buy |
How to build it: in the Buy rule, add a group set to All of these. Keep the Stochastic line from the step-by-step above. For the second line, pick a moving average with Average type SMA and Length 10 under What to watch, crosses above, and in Compare with a second moving average, SMA with Length 20. There is no single "cross period" setting: the cross is two averages compared.
| Choice | Effect |
|---|---|
| SMA(10) crosses above SMA(20) | Fires on the cross itself — fewer entries; the starting point |
| Close is above SMA(200) | Stays true while price is above the average — more entries; use it only if the cross proves too rare |
| Happened within the last N bars on the Stochastic line | Lets the two crosses land a few bars apart instead of on the same bar |
Exit: many confluence EAs leave on the opposite cross — in Step 5 use Exit by signal and build the condition like an entry rule.
Keep it to two rules. Each extra AND condition cuts trades and makes the result easier to curve-fit. If you need three OR branches to justify a trade, simplify before you optimize. Run the confluence version and the Stochastic-only version over the same dates in the Strategy Tester [3]: confluence should reduce the trade count. In hand-written MQL5 the trend line is one iMA [4] handle per average, read on closed bars like the iStochastic lines. The same AND pattern with other indicators: MACD + RSI Confluence.
Export, Compile, and Backtest
- Step 7 → Get the code → MetaTrader 5 code →
.mq5. - MetaEditor F7.
- Strategy Tester: Every tick, 6–12 months.
- Demo before live.
10016: Invalid Stops.
Improvements: Filters and Risk
| Problem | Lever |
|---|---|
| Over-trading in trend | AND with MA trend filter |
| Late entries | Tighter zones (75/25) or Happened within the last N bars on the cross line |
| Whipsaw in range | A session filter in Step 4 (Market sessions) or an All of these rule with a second line |
The stochastic %K/%D cross: history and rules
Who and when: George C. Lane, in the late 1950s.
George C. Lane developed the stochastic oscillator in the late 1950s. It shows where the latest close sits inside the high-low range of the last bars, 14 by default, on a scale from 0 to 100. The main line is called %K; %D is a short average of it. Readings above 80 are called overbought and readings below 20 oversold.
The classic signal joins the two ideas: a buy when %K crosses above %D in the oversold area, and a sell when %K crosses below %D in the overbought area. The cross shows the turn; the area says that the turn starts from a stretched level.
The rule as the source states it
A buy signal when a rising %K crosses above %D in the oversold region (below 20); a sell signal when a falling %K crosses below %D in the overbought region (above 80). [5] [6]
Our version
Stochastic (14, 3, 3) on 1-hour bars of a currency pair. Buy when %K crosses above %D while %K is below 20. Sell short when %K crosses below %D while %K is above 80. An opposite signal closes the trade and reverses it.
How ours differs
- "In the oversold region" is read as "%K is below 20 on the bar of the cross".
- Like every library file, ours also adds the builder's default stop, position size and account limits (Steps 5 and 6). You can change them in the form.
Can be built on the Free plan. Open in the builder →
Being well known says nothing about how a strategy will do. Test it on your own data.
Next Steps
- RSI EA — No Code — similar oscillator workflow
- MACD + RSI Confluence
- MA Crossover EA — No Code — the trend half of the confluence rule
- Build EA Without Coding
Whipsaw test: Backtest Stochastic-only for three months, then add your planned session filter in the live demo and compare trade count — if trades drop by half and drawdown improves, keep the filter; if trades vanish, tune OB/OS before giving up on the indicator.
References: MQL5 iStochastic [2] · MetaTrader 5 Strategy Tester [3] · MQL5 iMA [4].

