An indicator draws a line and waits for you to decide something; an Expert Advisor makes the decision and sends the order. That difference is the entire reason this EA is stricter than the Stochastic RSI indicator it is built on. A human watching a fast oscillator can ignore the readings that look silly. Software cannot, so the rule it follows has to be narrow enough that every signal it produces is one worth taking: this EA waits for %K to cross %D while the oscillator is still inside its oversold or overbought zone, opens a single position with a Stop Loss and Take Profit derived from current volatility, and then leaves the trade alone.
How the Strategy Works
The strategy has one signal and no trend filter. On each completed bar the EA recalculates Stochastic RSI from scratch — the raw line, the %K smoothing, and the %D signal line — then compares the last two bars for a crossover.
A crossover on its own is not enough. The EA also checks where the crossover happened. A bullish cross that occurs at a reading of 55 is the oscillator wandering around mid-range and is ignored entirely; the same cross at a reading of 12 is a turn from the bottom of RSI's own recent range, and that is the only version the EA trades. The overbought side is the exact mirror. Because Stochastic RSI pins at 0 and 100 for long stretches, this location requirement is doing a great deal of the filtering work — without it, the strategy would be taking a trade roughly every few bars.
Everything is evaluated on closed bars only. The value at shift 1 is final; the value on the forming bar is not, and an EA that acted on it would open and close positions as the candle changed its mind.
Stop Loss, Take Profit, and Position Sizing
Stop Loss distance is ATRMultiplier × ATR — by default two times the 14-period ATR — and Take Profit is RiskRewardRatio × Stop Loss distance, 2.0 by default. Both are computed at the moment of entry from the ATR of the just-closed bar, so a trade opened during a quiet Asian session gets a tighter stop than one opened into a volatile London open, and both risk the same amount of money.
That last part is the point of pairing ATR stops with risk-based sizing rather than a fixed lot. Lot size comes from RiskPercent of account balance divided by the stop distance measured in ticks and multiplied by tick value — the arithmetic taught step by step in Risk Management Basics, normalized afterwards to the broker's minimum, maximum and step constraints as described in Lot Sizes Explained. A wider ATR stop automatically produces a smaller position, so widening volatility changes the shape of the trade but not the size of the loss. UseFixedLot turns the calculation off for anyone who prefers a constant lot.
The EA does not move the stop after entry. It has no break-even step and no trail, so each trade resolves at one of the two levels set at entry — a deliberate choice that keeps the strategy's statistics clean, though anyone modifying the source will find trailing stops the most obvious first extension.
Entry Conditions
- BUY — on the just-closed bar, %K crossed above %D, and %K on the previous bar was below
OversoldLevel(default 20). - SELL — on the just-closed bar, %K crossed below %D, and %K on the previous bar was above
OverboughtLevel(default 80).
Four safety mechanics govern every trade, matching the standard used across every EA on this site. Entry logic runs once per new bar, tracked by the bar's open time, so one qualifying bar cannot fire repeatedly as ticks arrive. Only one position is open at a time, checked by counting trades filtered to this EA's symbol and magic number — there is no pyramiding and no averaging down. The current spread is compared against MaxSpreadPoints (default 30) before any order is sent, so entries are skipped during illiquid conditions where the fill would be poor. And every order is tagged with MagicNumber (default 20260911), which means the EA's counting and management logic never sees, and never touches, a position you opened by hand or one belonging to a different EA on the same account.
Parameters
- RSIPeriod (default 14) — the look-back of the underlying RSI the oscillator is built from.
- StochPeriod (default 14) — the window RSI's own high-low range is measured across. Lowering it makes extreme readings far more frequent and the EA far more active; raising it toward 21 has the opposite effect.
- SlowingPeriod (default 3) — the smoothing that turns the raw line into %K. Values above 5 make crossovers noticeably rarer and later.
- SignalPeriod (default 3) — the moving average of %K that becomes %D, and therefore the line that crossovers are measured against.
- OversoldLevel (default 20) — a BUY requires the previous bar's %K to be below this. Tightening to 10 demands a deeper extreme and cuts trade frequency sharply.
- OverboughtLevel (default 80) — the mirror condition for SELL entries.
The remaining inputs are not specific to this strategy — they belong to the risk engine shared across the whole EA collection and are documented once on the EA hub. This EA identifies its own trades with magic number 20260911.
Why the Cross Must Happen Inside the Zone
The zone requirement is the difference between a strategy and a signal generator, and it is worth understanding why rather than taking it on faith.
Stochastic RSI produces %K/%D crossovers constantly, because %K is a three-bar average of a line that swings the full 0-100 range on small moves. Most of those crossovers occur in the middle of the range and mean nothing — they are the oscillator reacting to RSI drifting a couple of points inside a quiet window. Filtering on location discards that entire category. What remains are crossovers that happen after RSI has actually reached the bottom or top of its recent range, which is at least a condition worth acting on.
There is a cost. Requiring the reading to be below 20 means the EA is systematically buying markets that have been falling and selling markets that have been rising, with no check on whether that fall or rise is likely to continue. In a sustained trend, the oscillator will pin at its extreme and produce crossover after crossover against the move, and the EA will take them. This is the known structural weakness of every unfiltered countertrend system, and it is left in place deliberately so the file reads as a clean reference implementation. Traders who want the filtered version have three straightforward routes: run it on a higher timeframe where extremes are rarer, tighten the levels to 10 and 90, or check the pair's market structure yourself and leave EnableTrading on only while the pair is genuinely ranging.
A Word of Caution
Run this on a demo account first, across several pairs and across quiet and volatile stretches, before any real money is involved — a good backtest or a good demo month is evidence about the past and nothing more. This EA will lose on individual trades, and because it trades against the immediate move with no trend filter, it will lose several consecutively during any strong directional run. That is the strategy behaving as designed, not a fault in the code. Stochastic RSI is also the fastest and noisiest oscillator on this site, so expect a materially higher trade count than a comparable RSI strategy, with the smaller average edge per trade that implies. Both the MT4 and MT5 files below are source code: read them in full, understand what each parameter does, and satisfy yourself about the logic before attaching this to any live account. Nothing on this page is personalized investment advice — it is general education about how the tool works.