Swing Structure Pullback
- Experts
- Version: 1.0
- Activations: 5
Swing Structure Pullback is an Expert Advisor for MetaTrader 5 that holds trades for several days. It trades pullbacks in the direction of the higher-timeframe trend. Signals come from closed bars only, every trade has a stop-loss, and it holds one position at a time per symbol and magic number. It does not use martingale, grid, averaging or hedging.
How a signal is formed
- Trend filter (D1 by default): the 50 EMA must slope in the trade direction over the last 5 daily bars, and the last daily close must be on the same side of the EMA.
- Swing structure (H4 by default): the 21 EMA must be above the 55 EMA for buys, or below it for sells.
- Pullback: within the last 8 closed H4 bars, price came back to the 21 EMA zone (within 0.3 ATR), RSI(14) cooled to 50 or lower (50 or higher for sells), and no bar closed more than 1.5 ATR beyond the 55 EMA.
- Trigger: a closed H4 bar in the trend direction breaks the high (or low) of the previous 2 bars and closes on the trend side of the 21 EMA.
Signals are computed on the fixed signal timeframe, so the EA behaves the same on any chart timeframe. Signals do not repaint and do not look ahead.
Trade management
- Initial stop beyond the pullback extreme plus 0.3 ATR. The minimum stop is 1 ATR. Setups that need more than 3.5 ATR are skipped.
- Partial take-profit: 50% is closed at 1R and the stop moves to break-even. If the position is too small to split, only the stop is moved.
- ATR trailing stop (2.5 ATR from the best price since entry) from 1R. Final take-profit at 4R (can be switched off).
- Time exit after 90 H4 bars. Optional exit when the daily trend turns against the position.
Risk and safety
- Fixed lot, or % risk of balance per trade (1% by default) with a maximum lot.
- Daily loss limit (% of the day-start balance, measured on equity) and a maximum number of new trades per day.
- Maximum spread (as a fraction of ATR or in points), trading-hours window, no new trades late on Friday or in the first hours of the week.
- High-impact news pause using the built-in MetaTrader 5 economic calendar for the symbol's currencies. The calendar is not available in the Strategy Tester, so this filter only works on live and demo charts.
- Before each order the EA checks free margin, volume minimum, maximum, step and symbol volume limit, stops and freeze levels, the symbol trade mode and whether the session is open. It also runs OrderCheck. If free margin is not enough for the minimum lot, the trade is skipped and a message is written to the log. After a failed request it waits before trying again.
Recommendations
- Test it in the Strategy Tester on your broker's data with "every tick based on real ticks", then on a demo account, before trading real money.
- Use a separate magic number for each chart.
- Start with low risk. If "use the minimum lot" is on, a small account or a wide stop can risk more than the set % on a trade. The log says when this happens.
Testing performed (version 1.00, JustMarkets demo data, 10,000 USD, 1:100, default inputs)
The program compiles with no errors or warnings. In the Strategy Tester it opened and managed trades on EURUSD (M1 and H1 charts), GBPUSD (M30), XAUUSD (D1) and USDJPY (H1) with no errors in the journal. With a 1 USD deposit it skipped every trade with a "not enough free margin" message and sent no orders.
Backtests from 2024-01-01 to 2026-10-29, results as obtained:
- XAUUSD H4, real ticks: 62 positions, net +1,781.59, profit factor 1.71, maximum equity drawdown 4.47%. Most trades were buys during a strong rise in gold.
- EURUSD H4, real ticks: 72 positions, net -705.72 (a loss), profit factor 0.82, maximum equity drawdown 10.51%.
- GBPUSD H4 (1-minute OHLC): net -593.46, profit factor 0.86. USDJPY H4 (1-minute OHLC): net -84.29, profit factor 0.98.
The forex pairs did not show a profitable edge with the default settings. The gold result comes from one market period and may not repeat. The EA has not been forward-tested on a live account and has not been tested on a netting account.
Risk disclosure
Trading leveraged products such as forex and CFDs carries a high level of risk and can result in the loss of all invested capital. This Expert Advisor opens and closes positions automatically. Backtest results depend on data quality, spreads, swaps and execution, and past results do not predict future results. The product does not promise or imply any profit. Test it on a demo account and use only money you can afford to lose.
swing trading, trend pullback, multi-timeframe, daily trend filter, H4, ATR stop, partial take profit, break-even, trailing stop, risk percent, news filter, spread filter, no martingale, no grid, XAUUSD, EURUSD, MT5 expert advisor
How a signal is formed
- Trend filter (D1 by default): the 50 EMA must slope in the trade direction over the last 5 daily bars, and the last daily close must be on the same side of the EMA.
- Swing structure (H4 by default): the 21 EMA must be above the 55 EMA for buys, or below it for sells.
- Pullback: within the last 8 closed H4 bars, price came back to the 21 EMA zone (within 0.3 ATR), RSI(14) cooled to 50 or lower (50 or higher for sells), and no bar closed more than 1.5 ATR beyond the 55 EMA.
- Trigger: a closed H4 bar in the trend direction breaks the high (or low) of the previous 2 bars and closes on the trend side of the 21 EMA.
Signals are computed on the fixed signal timeframe, so the EA behaves the same on any chart timeframe. Signals do not repaint and do not look ahead.
Trade management
- Initial stop beyond the pullback extreme plus 0.3 ATR. The minimum stop is 1 ATR. Setups that need more than 3.5 ATR are skipped.
- Partial take-profit: 50% is closed at 1R and the stop moves to break-even. If the position is too small to split, only the stop is moved.
- ATR trailing stop (2.5 ATR from the best price since entry) from 1R. Final take-profit at 4R (can be switched off).
- Time exit after 90 H4 bars. Optional exit when the daily trend turns against the position.
Risk and safety
- Fixed lot, or % risk of balance per trade (1% by default) with a maximum lot.
- Daily loss limit (% of the day-start balance, measured on equity) and a maximum number of new trades per day.
- Maximum spread (as a fraction of ATR or in points), trading-hours window, no new trades late on Friday or in the first hours of the week.
- High-impact news pause using the built-in MetaTrader 5 economic calendar for the symbol's currencies. The calendar is not available in the Strategy Tester, so this filter only works on live and demo charts.
- Before each order the EA checks free margin, volume minimum, maximum, step and symbol volume limit, stops and freeze levels, the symbol trade mode and whether the session is open. It also runs OrderCheck. If free margin is not enough for the minimum lot, the trade is skipped and a message is written to the log. After a failed request it waits before trying again.
Recommendations
- Test it in the Strategy Tester on your broker's data with "every tick based on real ticks", then on a demo account, before trading real money.
- Use a separate magic number for each chart.
- Start with low risk. If "use the minimum lot" is on, a small account or a wide stop can risk more than the set % on a trade. The log says when this happens.
Testing performed (version 1.00, JustMarkets demo data, 10,000 USD, 1:100, default inputs)
The program compiles with no errors or warnings. In the Strategy Tester it opened and managed trades on EURUSD (M1 and H1 charts), GBPUSD (M30), XAUUSD (D1) and USDJPY (H1) with no errors in the journal. With a 1 USD deposit it skipped every trade with a "not enough free margin" message and sent no orders.
Backtests from 2024-01-01 to 2026-10-29, results as obtained:
- XAUUSD H4, real ticks: 62 positions, net +1,781.59, profit factor 1.71, maximum equity drawdown 4.47%. Most trades were buys during a strong rise in gold.
- EURUSD H4, real ticks: 72 positions, net -705.72 (a loss), profit factor 0.82, maximum equity drawdown 10.51%.
- GBPUSD H4 (1-minute OHLC): net -593.46, profit factor 0.86. USDJPY H4 (1-minute OHLC): net -84.29, profit factor 0.98.
The forex pairs did not show a profitable edge with the default settings. The gold result comes from one market period and may not repeat. The EA has not been forward-tested on a live account and has not been tested on a netting account.
Risk disclosure
Trading leveraged products such as forex and CFDs carries a high level of risk and can result in the loss of all invested capital. This Expert Advisor opens and closes positions automatically. Backtest results depend on data quality, spreads, swaps and execution, and past results do not predict future results. The product does not promise or imply any profit. Test it on a demo account and use only money you can afford to lose.
swing trading, trend pullback, multi-timeframe, daily trend filter, H4, ATR stop, partial take profit, break-even, trailing stop, risk percent, news filter, spread filter, no martingale, no grid, XAUUSD, EURUSD, MT5 expert advisor
