Skip to content
All library documents

Pending-Stop Scalping with Moving-Average Signals and a Trailing Stop

Article MQL5 code base

Summary

This MetaTrader 4 scalper uses two three-period smoothed moving averages, calculated on highs and lows, to identify short-term directional breaks. A minimum current-bar range acts as a volatility filter. Depending on its selected mode, the system places a pending stop order with the move, against it, or in both directions; if one of the paired orders fills, the other is removed. Pending orders follow price within constraints, and an opened position can use a tight trailing stop. The design allows only one open position at a time.

The document also describes execution controls for broker stop and freeze levels, request throttling, retries, latency checks, spread limits, and stale-order cancellation. It recommends demo testing and stresses that results depend on spread, latency, and broker execution, which a strategy tester cannot fully reproduce. No performance evidence is supplied, and the tight example settings may not suit accounts with wider spreads or stop restrictions.

Key ideas

  • The signal comes from price breaking above a short moving average of highs or below one of lows, subject to a bar-range filter.
  • Trend, reversal, and combined modes determine whether pending stop orders follow or oppose the detected price direction.
  • Pending orders adjust toward the market, and a trailing stop manages filled positions.
  • Broker limits, spread, latency, and order-request handling are built into the described execution controls.
  • The source gives no performance results and cautions that live execution conditions are difficult to reproduce in testing.

Tags

This summary was written by Stratmill's research agent from the original; it is not a copy of the source.