Disclaimer: This article is for educational and informational purposes only. It does not constitute financial or investment advice. Trading forex and CFDs carries significant risk of loss. Past performance of any strategy — including backtests — does not guarantee future results. Never trade with money you cannot afford to lose.
What Is This Strategy?
The Ulcer Index Trend Pullback is a trend-continuation strategy — a "buy the dip in an uptrend" (and "sell the rally in a downtrend") system — built around a quality filter that few retail traders ever use: Peter Martin's Ulcer Index. The Ulcer Index is a volatility measure that only counts downside pain. Instead of treating all price movement as risk, it measures the root-mean-square of the percentage drawdowns from a running peak, so it captures how smooth or how jagged a trend has been rather than simply how far price has travelled.
Most trend filters answer a single question: is price above a moving average and is that average rising? They say nothing about how price got there. A market can rise two percent by gliding calmly higher, or rise two percent through a violent saw-tooth that stops out every pullback trader along the way. The Ulcer Index Trend Pullback strategy adds this missing dimension. It only takes a pullback entry when the preceding trend has been orderly — a low Ulcer Index reading — because retracements tend to continue far more reliably inside a calm advance than inside a whipsawing one.
As a learning tool, this strategy is well suited to traders who already understand moving averages and want to explore a more nuanced idea of trend quality. It combines several classic building blocks — a baseline Simple Moving Average (SMA) for direction, a fast Exponential Moving Average (EMA) for the pullback, an Average True Range (ATR) for risk, and the Ulcer Index as a texture gate. Studying how these pieces interact is a useful exercise in thinking about market conditions rather than chasing signals in isolation.
How It Works
The strategy evaluates its rules only on closed bars, so signals do not repaint intrabar. On each newly closed bar it checks a symmetric set of conditions for longs and shorts.
Trend direction (the baseline filter):
- The strategy calculates a Simple Moving Average over
TrendPeriodbars and compares it to its own valueSlopeLookbackbars earlier. - For a long, price must be above the SMA and the SMA must be rising.
- For a short, price must be below the SMA and the SMA must be falling.
Trend quality (the Ulcer Index gate):
- For uptrends, the strategy measures the "drawdown texture" — the root-mean-square of percentage dips from the running peak close over
UlcerPeriodbars. - For downtrends, it uses the mirror image, an "upside ulcer" measuring draw-ups from the running trough.
- The setup is only allowed when this reading is below the
UlcerThreshold, meaning the trend has been smooth enough to trade.
The pullback and resume (timing the entry):
- A fast EMA over
PullbackPeriodbars acts as the dynamic level price pulls back to. - Long signal: the prior closed bar dipped to or below the EMA, and the current closed bar has closed back above it — the dip touched the mean and price is resuming higher.
- Short signal: the prior closed bar rallied to or above the EMA, and the current closed bar has closed back below it — the rally rolled over.
Stop-loss and take-profit logic:
- Risk is defined by the Average True Range. The stop is placed
AtrStopMult× ATR away from entry — below entry for longs, above for shorts. - The take-profit is a
RewardRiskmultiple of that stop distance, so the reward-to-risk ratio stays consistent as volatility changes. - Because the stop and target scale with ATR and the Ulcer Index is unit-free (a percentage), the same defaults are designed to travel across different symbols.
Trade management:
- The strategy holds only one position per magic number at a time. Once a trade is open, the fixed ATR stop and reward:risk target manage the exit — there is no additional trailing or averaging.
- New entries are skipped whenever the current spread is wider than
MaxSpreadPoints, which helps avoid trading in poor liquidity conditions.

Strategy Parameters
| Parameter | Default | Min | Max | Description |
|---|---|---|---|---|
| UlcerPeriod | 14 | 5 | 40 | Window (bars) for the Ulcer Index drawdown/draw-up measurement. |
| TrendPeriod | 50 | 20 | 200 | Length of the baseline SMA that defines trend direction. |
| SlopeLookback | 5 | 1 | 20 | How many bars back to measure the baseline SMA slope (rising or falling). |
| PullbackPeriod | 10 | 3 | 30 | Length of the fast EMA that price pulls back to before resuming with the trend. |
| UlcerThreshold | 1.5 | 0.2 | 6.0 | Maximum Ulcer Index (percent) for the trend to count as "smooth" enough to trade. |
| AtrPeriod | 14 | 5 | 30 | ATR lookback used to size the stop distance. |
| AtrStopMult | 2.0 | 0.5 | 5.0 | Stop distance as a multiple of ATR beyond the entry. |
| RewardRisk | 1.8 | 0.5 | 5.0 | Take-profit as a reward:risk multiple of the ATR stop distance. |
| MaxSpreadPoints | 80 | 5 | 300 | Skip new entries when the current spread (points) is wider than this. |
| Lots | 0.10 | 0.01 | 1.0 | Fixed trade volume in lots. |
| Magic | 5182 | 0 | 9,999,999 | Magic number identifying this EA's trades. |

Recommended Chart Settings
The Ulcer Index Trend Pullback was designed with trending instruments in mind — a trending FX major or an index such as EURUSD, GBPUSD, or US500 — on swing-style timeframes between H1 and H4. These markets tend to produce the sustained, orderly moves that the Ulcer Index gate is built to reward, and the higher timeframes reduce the noise that triggers false pullback signals.
That said, the strategy reads only the primary timeframe of the chart it is attached to, so it will run on whatever symbol and timeframe you select at backtest or live time. Behaviour can change meaningfully across instruments and market regimes, and results will vary across different market conditions. Test any combination thoroughly on historical data and a demo account before drawing conclusions.
How to Install on MetaTrader 5
- Download the .ex5 file from the link below
- Copy it to your MT5
MQL5\Expertsfolder - Restart MetaTrader 5 or refresh the Navigator panel
- Drag the EA onto a chart matching the recommended symbol and timeframe
- Configure the input parameters and enable Algo Trading
What to Consider Before Using This EA
The strongest idea in this strategy is its use of trend quality, not just trend direction. By screening for smooth advances, the Ulcer Index filter is designed to avoid pullback entries in jagged, whipsawing markets where retracements are more likely to fail. Combining an ATR-based stop with a fixed reward:risk target also keeps risk self-scaling and consistent across volatility regimes, which is good practice to study.
There are real limitations to keep in mind. Trend-continuation systems, by nature, struggle in ranging or choppy markets — the Ulcer Index gate reduces but does not eliminate this exposure, and a market can transition from smooth to jagged after an entry is already open. A low Ulcer Index reading is backward-looking: it describes the trend that has happened, not what will happen next. Sharp reversals and news-driven spikes can still trigger the ATR stop. The strategy also takes a single position at a time with no trailing exit, so it may give back open profit if a move stalls before reaching the target. Finally, moving-average and pullback logic inherently lags, meaning the entry arrives after the resume rather than at the turn.
None of this makes the approach good or bad — it makes it a specific tool for a specific condition. The goal of studying it is to understand when that condition is present and when it is not.
Risk Management Tips
- Size positions deliberately. A common educational guideline is to risk no more than 1–2% of account equity on any single trade. Use the ATR stop distance to work backwards to an appropriate lot size rather than trading a fixed volume blindly.
- Understand drawdown. Even a well-designed strategy experiences losing streaks. Know the maximum historical drawdown of any configuration before committing capital, and ask whether you could tolerate it emotionally as well as financially.
- Start on a demo account. Run the EA on a demo or very small live account first to confirm it behaves as expected on your broker's spreads, execution, and symbol specifications.
- Respect the spread filter. The
MaxSpreadPointsinput exists to avoid poor-liquidity conditions; tune it to your broker rather than disabling it. - Never over-leverage. Leverage magnifies losses as much as gains. Only trade with capital you can afford to lose.
Risk Warning
Trading foreign exchange, CFDs, and other leveraged financial instruments involves substantial risk of loss and is not suitable for all investors. The strategies and tools discussed on this page are provided for educational purposes only and do not constitute financial advice, investment recommendations, or solicitation to trade. Always consult a qualified financial adviser before making trading decisions. Past backtest performance is not indicative of future results.
Downloads
- Expert Advisor: UlcerIndexTrendPullback.ex5 (30 downloads)
- Source Code: UlcerIndexTrendPullback.mq5 (30 downloads)
- Documentation: UlcerIndexTrendPullback.pdf (36 downloads)