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 Half Trend Rail Reversal strategy is a trend-following, regime-flip system built around the HalfTrend indicator — a noise-reduced trailing trend line popularised by Alex Orekhov (also known as "everget"). Unlike a classic moving-average crossover, HalfTrend draws a "rail" that only changes direction when the balance of control genuinely hands over from buyers to sellers or vice versa. The strategy trades that handover: it goes long when the rail flips from a down-regime to an up-regime, and short when the rail flips the other way.
What makes the HalfTrend rail distinctive is how it decides to flip. It is deliberately not a Supertrend, Chandelier, Chande-Kroll, or Donchian-midline clone. Those tools trail an ATR band off a mid-price or off an N-bar high/low. HalfTrend instead flips bearish only when the simple moving average (SMA) of recent highs drops beneath a ratcheting max-low anchor, and flips bullish only when the SMA of recent lows climbs above a ratcheting min-high anchor. Each flip is further confirmed by the closing price piercing the previous bar's low or high. That double gate makes the rail "sticky" — it ignores shallow noise and turns only on a structural change of trend.
As a learning tool, this strategy suits traders who want to study how a regime-detection filter behaves in trending versus choppy markets. It is best understood as a study in trade selectivity: because it acts only on the single transition bar of each regime change, it enters once per trend rather than on every bar. That makes it a clean example for analysing how signal frequency, confirmation logic, and ATR-based risk sizing interact. Frame it as an analysis exercise, not a shortcut to returns.
How It Works
The Half Trend Rail Reversal engine processes only closed bars, acting once each time a new bar forms. On every new bar it rebuilds the HalfTrend rail across a rolling window of history and compares the regime of the most recently closed bar with the bar before it. A change between those two states is a genuine, non-repainting flip.
Here is how the logic unfolds:
- Building the rail: Over a lookback window set by the Amplitude parameter, the strategy computes the SMA of highs, the SMA of lows, the highest high, and the lowest low. It tracks a ratcheting
maxLowPrice(a max-low anchor that never retreats while the up-regime holds) and a ratchetingminHighPrice(a min-high anchor for the down-regime). - Bullish flip (DOWN → UP): The rail turns up when the SMA of lows rises above the ratcheting min-high anchor and the current close finishes above the prior bar's high. Control has handed to the bulls.
- Bearish flip (UP → DOWN): The rail turns down when the SMA of highs falls below the ratcheting max-low anchor and the current close finishes below the prior bar's low. Control has handed to the bears.
- Long entry: When the just-closed bar produces a fresh DOWN → UP flip, the strategy signals a long. It first closes any open short (a protective exit), then opens a new buy at the ask — unless a long is already open.
- Short entry: When the just-closed bar produces a fresh UP → DOWN flip, the strategy signals a short. It closes any open long, then opens a new sell at the bid — unless a short is already open.
- One trade per regime: Because the two bar states are compared directly, only the transition bar trades. The strategy does not re-enter on every bar of an ongoing trend.
- Stop-loss logic: The stop is placed a distance of SlAtrMult × ATR beyond the entry price, using the Average True Range (ATR — a volatility gauge) over the AtrPeriod window. Wider volatility produces a wider stop, adapting the risk to current conditions.
- Take-profit logic: The target is set at RewardRatio multiples of the stop distance. With the defaults, that means the target sits twice as far from entry as the stop, so a winning trade aims to earn more than each losing trade risks.
- Reversal as an exit: If the rail flips the opposite way before either stop or target is hit, the open position is closed and reversed. That opposite flip is itself a built-in protective exit.
An ATR channel (governed by ChannelDeviation) is drawn around the rail for context, but it is informational — it does not itself trigger trades.

Strategy Parameters
| Parameter | Default | Min | Max | Description |
|---|---|---|---|---|
| Amplitude | 2 | 1 | 8 | Lookback length for the high/low anchors and the SMA(high)/SMA(low) trigger lines. Larger values make the rail slower and stickier. |
| ChannelDeviation | 2.00 | 0.50 | 4.00 | Width of the ATR channel drawn around the rail (a multiple of ATR). Informational context only; it does not trigger trades. |
| AtrPeriod | 100 | 20 | 200 | Number of bars in the ATR calculation used for the channel and for stop-loss sizing. |
| SlAtrMult | 2.00 | 0.50 | 5.00 | Stop-loss distance as a multiple of ATR beyond the entry price. |
| RewardRatio | 2.00 | 0.50 | 6.00 | Take-profit distance expressed as a multiple of the stop distance (the reward-to-risk ratio). |
| Lots | 0.10 | 0.01 | 1.00 | Fixed order volume in lots for each trade. |
| Magic | 6413 | 0 | 9,999,999 | Unique magic number that tags this EA's trades so it manages only its own positions. |

Recommended Chart Settings
The Half Trend Rail Reversal was designed with a trending FX major or metal in mind — for example GBPUSD or XAUUSD (gold) — on the H1 or H4 timeframe, where trends tend to persist long enough for a regime-flip system to capture them. That said, the strategy is timeframe-agnostic: it runs on whatever single primary timeframe is selected at backtest time.
Because the logic depends on genuine trend handovers, it historically behaves best in directional conditions and less well in tight ranges. Results will vary considerably across different symbols, timeframes, and market regimes, so treat the recommended settings as a starting point for study rather than a fixed prescription.
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 main strength of this approach is selectivity. By requiring both a moving-average trigger and a close-through-prior-bar confirmation, the HalfTrend rail filters out much of the shallow noise that whipsaws simpler crossover systems. Trading only the transition bar means the strategy commits capital sparingly and lets the ATR-based target run for more than it risks when a trend does develop.
Those same design choices carry trade-offs worth studying:
- Range-bound underperformance: Like most trend-following tools, the strategy can suffer a string of small losses when a market chops sideways, because flips occur without a follow-through trend. The sticky rail reduces but does not eliminate this.
- Lag at turning points: The confirmation gate means the rail flips after a trend change is underway, so entries arrive somewhat late and the earliest part of a move is missed.
- Sensitivity to Amplitude and ATR: A very short Amplitude flips more often (more signals, more noise); a longer one flips rarely (fewer, later signals). The AtrPeriod and SlAtrMult together determine how much room a trade is given before the stop is hit — too tight and normal volatility ejects you, too wide and losses grow.
- Fixed lot sizing: The default uses a fixed lot size, which does not scale risk to account equity. This is something to review before any serious testing.
Study these behaviours on historical data and a demo account before drawing any conclusions. No indicator anticipates the market; HalfTrend simply reacts to structure in a disciplined way.
Risk Management Tips
Sound risk management matters more than any single indicator. Consider these general principles as you study this or any strategy:
- Risk a small, fixed fraction per trade — many educators suggest no more than 1–2% of account equity on any single position — so that a losing streak does not deplete your capital.
- Size positions to the stop distance, not the other way around. Since this strategy sets an ATR-based stop, you can calculate the lot size that keeps each trade within your chosen risk budget.
- Test on a demo account first, across several market conditions, so you understand how the strategy behaves in trends, ranges, and volatile news periods before committing real capital.
- Understand drawdown. Even a well-designed trend system will endure losing runs. Know the maximum historical drawdown you are prepared to tolerate, and stop if live behaviour diverges sharply from your expectations.
- Keep leverage modest. Leverage magnifies losses as readily as gains, and it is a leading cause of blown accounts among new traders.
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: HalfTrendRailReversal.ex5 (40 downloads)
- Source Code: HalfTrendRailReversal.mq5 (43 downloads)
- Documentation: HalfTrendRailReversal.pdf (50 downloads)