Ratchet Flip SuperTrend EA
- 专家
- 版本: 1.1
- 激活: 5
Ratchet Flip SuperTrend EA is an Expert Advisor for MetaTrader 5 that trades flips of an ATR SuperTrend line. The line is calculated inside the EA, so you only need this one file. Signals come from closed bars only, every trade has a stop-loss, and the EA holds one position at a time per symbol and magic number. It does not use martingale, grid, averaging or hedging, and it works on netting and hedging accounts.
How the trend line works
- Wilder ATR (10) times a multiplier (3.0) is placed above and below the bar's median price.
- The lower band can only rise and the upper band can only fall (a "ratchet") until price closes through the band.
- The trend flips up when a bar closes above the previous upper band, and down when a bar closes below the previous lower band.
- The line is the lower band in an uptrend and the upper band in a downtrend. It is drawn on the chart with flip marks.
Entries
- A flip on the last closed bar of the signal timeframe (the chart timeframe by default).
- Optional higher-timeframe confirmation (on by default, D1): the last closed D1 bar's SuperTrend must point the same way. The filter switches itself off when the chart is D1 or higher.
- Optional volatility filter (on by default): ATR must be at least 0.8 times its 50-bar average, and the flip close must be at least 0.2 ATR beyond the old line.
- Direction can be set to buy and sell, buy only or sell only.
Exits
- Initial stop at the SuperTrend line plus a 0.2 ATR buffer, or a fixed ATR distance. Stops narrower than 0.5 ATR are widened; setups that need more than 6 ATR are skipped.
- Optional partial close (50% at 1R) with break-even. If the position is too small to split, only the stop is moved.
- The stop is trailed along the SuperTrend line on each closed bar.
- Exit on an opposite flip. The EA then reverses if the filters allow it. An optional final take-profit in R is available.
Risk and safety
- Fixed lot or % risk per trade (1% by default) with a maximum lot. The money at risk is calculated from the actual stop with the platform's profit calculation.
- Hard caps in every lot mode: the loss at the stop is never more than 5% of equity, and a new trade never uses more than 40% of free margin. If the broker minimum lot would break the cap, the stop is tightened to fit (not below 0.5 ATR) or the trade is skipped with a log message. On small accounts the minimum lot can still risk more than the 1% setting, up to the 5% cap.
- Daily loss limit (4% of the day-start balance by default), optional close of the open position when it is hit, and an optional maximum of trades per day.
- Maximum spread (as a fraction of ATR and/or in points), trading-hours window and a Friday cut-off hour.
- Before each order the EA checks the volume minimum, maximum and step, the symbol volume limit, free margin, stops and freeze levels, trade mode and session, and runs OrderCheck. If free margin is not enough for the minimum lot, the trade is skipped with a log message. After a failed request it waits before retrying.
- Magic number and order comment inputs, so it can run next to other EAs.
Testing performed (version 1.01, 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 (H1 and M1), GBPUSD (M30), USDJPY (H1) and XAUUSD (D1) with no errors in the journal. With a 1 USD deposit it skipped every signal with a log message and sent no orders.
Real-tick backtests from 2024-01-01 to 2026-10-30, results as obtained:
- XAUUSD H1: 116 positions, net +469.01, profit factor 1.12, maximum equity drawdown 7.06%.
- XAUUSD H4: 28 positions, net +474.49, profit factor 1.55, maximum equity drawdown 4.67%.
- EURUSD H1: 127 positions, net -210.90 (a loss), profit factor 0.95, maximum equity drawdown 8.40%.
- EURUSD H4: 27 positions, net -171.74 (a loss), profit factor 0.82, maximum equity drawdown 5.48%.
Most of the gold profit came in 2026, and both gold tests lost money in 2024. The filter defaults were chosen on 2024-2025 data, so those years are not an independent test. Shorter tests on GBPUSD M30, USDJPY H1 and XAUUSD D1 in 2025-2026 lost money. Version 1.01 was tested in both netting and hedging mode with deposits from 1 to 10,000 USD: no stop-outs, and trades opened on EURUSD H1 from 100 USD and on XAUUSD D1 from 300 USD. With 1 USD, or 100 USD on XAUUSD D1, every signal was skipped with a log message. The EA has not been forward-tested on a live account.
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 and start with low risk.
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.
supertrend, supertrend ea, trend following, atr, trailing stop, multi timeframe, risk management, xauusd, eurusd, no martingale, no grid, mt5 expert advisor
How the trend line works
- Wilder ATR (10) times a multiplier (3.0) is placed above and below the bar's median price.
- The lower band can only rise and the upper band can only fall (a "ratchet") until price closes through the band.
- The trend flips up when a bar closes above the previous upper band, and down when a bar closes below the previous lower band.
- The line is the lower band in an uptrend and the upper band in a downtrend. It is drawn on the chart with flip marks.
Entries
- A flip on the last closed bar of the signal timeframe (the chart timeframe by default).
- Optional higher-timeframe confirmation (on by default, D1): the last closed D1 bar's SuperTrend must point the same way. The filter switches itself off when the chart is D1 or higher.
- Optional volatility filter (on by default): ATR must be at least 0.8 times its 50-bar average, and the flip close must be at least 0.2 ATR beyond the old line.
- Direction can be set to buy and sell, buy only or sell only.
Exits
- Initial stop at the SuperTrend line plus a 0.2 ATR buffer, or a fixed ATR distance. Stops narrower than 0.5 ATR are widened; setups that need more than 6 ATR are skipped.
- Optional partial close (50% at 1R) with break-even. If the position is too small to split, only the stop is moved.
- The stop is trailed along the SuperTrend line on each closed bar.
- Exit on an opposite flip. The EA then reverses if the filters allow it. An optional final take-profit in R is available.
Risk and safety
- Fixed lot or % risk per trade (1% by default) with a maximum lot. The money at risk is calculated from the actual stop with the platform's profit calculation.
- Hard caps in every lot mode: the loss at the stop is never more than 5% of equity, and a new trade never uses more than 40% of free margin. If the broker minimum lot would break the cap, the stop is tightened to fit (not below 0.5 ATR) or the trade is skipped with a log message. On small accounts the minimum lot can still risk more than the 1% setting, up to the 5% cap.
- Daily loss limit (4% of the day-start balance by default), optional close of the open position when it is hit, and an optional maximum of trades per day.
- Maximum spread (as a fraction of ATR and/or in points), trading-hours window and a Friday cut-off hour.
- Before each order the EA checks the volume minimum, maximum and step, the symbol volume limit, free margin, stops and freeze levels, trade mode and session, and runs OrderCheck. If free margin is not enough for the minimum lot, the trade is skipped with a log message. After a failed request it waits before retrying.
- Magic number and order comment inputs, so it can run next to other EAs.
Testing performed (version 1.01, 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 (H1 and M1), GBPUSD (M30), USDJPY (H1) and XAUUSD (D1) with no errors in the journal. With a 1 USD deposit it skipped every signal with a log message and sent no orders.
Real-tick backtests from 2024-01-01 to 2026-10-30, results as obtained:
- XAUUSD H1: 116 positions, net +469.01, profit factor 1.12, maximum equity drawdown 7.06%.
- XAUUSD H4: 28 positions, net +474.49, profit factor 1.55, maximum equity drawdown 4.67%.
- EURUSD H1: 127 positions, net -210.90 (a loss), profit factor 0.95, maximum equity drawdown 8.40%.
- EURUSD H4: 27 positions, net -171.74 (a loss), profit factor 0.82, maximum equity drawdown 5.48%.
Most of the gold profit came in 2026, and both gold tests lost money in 2024. The filter defaults were chosen on 2024-2025 data, so those years are not an independent test. Shorter tests on GBPUSD M30, USDJPY H1 and XAUUSD D1 in 2025-2026 lost money. Version 1.01 was tested in both netting and hedging mode with deposits from 1 to 10,000 USD: no stop-outs, and trades opened on EURUSD H1 from 100 USD and on XAUUSD D1 from 300 USD. With 1 USD, or 100 USD on XAUUSD D1, every signal was skipped with a log message. The EA has not been forward-tested on a live account.
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 and start with low risk.
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.
supertrend, supertrend ea, trend following, atr, trailing stop, multi timeframe, risk management, xauusd, eurusd, no martingale, no grid, mt5 expert advisor
