Momentum Divergence MT5
- Experts
-
Mohamed Amr Mohamed Osama Abdelwahab
Software Developer, Instructor, and Technical Team Leader with over 22 years of experience across desktop, web, and financial software development. Top Rated freelancer on Upwork with 200+ completed projects, $200K+ delivered, and a 100% job success record. Specialized in algorithmic trading systems - Version: 1.0
- Activations: 5
Momentum Divergence EA
Expert Advisor for MetaTrader that trades momentum divergence on confirmed swing points.
The EA carries the full indicator logic inside it. There is no iCustom call, no DLL and no external dependency: the .ex4/.ex5 file contains everything it needs to run.
HOW IT WORKS
On each new bar the EA looks for the most recent swing point that can be confirmed by completed bars on both sides, then compares it with the previous swing of the same kind:
- Bearish divergence: price makes a HIGHER high while momentum makes a LOWER high. The EA sells, and closes an open buy if you allow it to.
- Bullish divergence: price makes a LOWER low while momentum makes a HIGHER low. The EA buys, and closes an open sell if you allow it to.
A swing point is only used once both sides of it are complete, so a signal is never taken from the bar that is still forming. When a bullish and a bearish signal appear on the same bar, neither is taken.
Stops and targets are placed from ATR, so they adapt to the current volatility of the symbol rather than using a fixed pip distance. Both distances are widened automatically to respect your broker's minimum stop level and the current spread.
INDICATOR INPUTS
- InpMomPeriod (default 14) — momentum period. Momentum is the difference between the current close and the close this many bars ago. Smaller values react faster and produce more signals; larger values are slower and more selective.
- InpSwingBars (default 5) — how many bars on each side must confirm a swing point. A larger value means fewer but more significant swings, and it also means the signal arrives later, because the EA has to wait for that many bars to complete on the right-hand side.
- InpDrawLines (default true) — draw the divergence lines on the chart. Visual only; it does not affect trading decisions.
- InpMaxSwingSearch (default 200) — how far back, in bars, to look for the previous swing point to compare against. Larger values allow divergences that develop over a longer span to be found, at the cost of more processing per bar.
TRADING INPUTS
- InpAllowBuy (default true) — allow buy entries on bullish divergence.
- InpAllowSell (default true) — allow sell entries on bearish divergence. Set one of these to false to trade in one direction only, for example to trade with a higher-timeframe trend.
- InpCloseOpposite (default true) — close an open position in the opposite direction when a new signal appears. With this off, a position is left to reach its own stop or target.
- InpLots (default 0.01) — fixed lot size, used when InpRiskPercent is 0.
- InpRiskPercent (default 0.0) — risk per trade as a percentage of account balance. When above 0, lot size is calculated from the stop distance and this value, and InpLots is ignored. Position size is always clamped to the symbol's minimum, maximum and step.
- InpATRPeriod (default 14) — ATR period used to measure current volatility for the stop and target.
- InpSLMult (default 2.0) — stop-loss distance as a multiple of ATR.
- InpTPMult (default 4.0) — take-profit distance as a multiple of ATR. Set to 0 to open positions without a take profit and manage the exit yourself.
- InpMagic (default 20250911) — magic number identifying this EA's positions. Give each chart its own value if you run more than one instance.
- InpSlippage (default 3) — maximum accepted slippage in points on entry and exit.
NOTES ON SETTINGS
The defaults are a neutral starting point, not a recommendation for any particular symbol. Instruments differ in volatility, spread and typical swing size, and settings that suit one may be unsuitable for another. A fast metal and a major currency pair will usually not want the same momentum period or the same ATR multiples.
The parameters that change behaviour the most are InpMomPeriod and InpSwingBars, which together determine how many signals you get and how selective they are, followed by InpSLMult and InpTPMult, which determine the shape of each trade. It is worth changing one at a time so you can see what each does.
BEFORE YOU TRADE IT
Test this EA yourself, on your own broker, on the symbols and timeframes you intend to trade, before committing real money.
This matters more than it may sound. Results depend on your broker's spread, commission, execution and the quality of its price history, and on the settings you choose. Two traders running this EA on the same symbol with different brokers and different inputs should expect different outcomes.
A reasonable sequence is: run it in the strategy tester over as much history as you can obtain, using every-tick modelling; then run it on a demo account for long enough to see it trade in current market conditions; then, if you are satisfied, start on a live account at the smallest size your broker allows. Keep the sample large enough to mean something — a handful of trades tells you very little about any strategy.
Also test the periods where it does badly, not only the ones where it does well. Knowing the size of the worst drawdown a setting produced, and how long it lasted, is more useful for deciding position size than knowing the best run.
RISK DISCLOSURE
Trading foreign exchange, metals, indices, cryptocurrencies and other leveraged instruments carries a high level of risk and is not suitable for every investor. You may lose some or all of your invested capital; do not trade with money you cannot afford to lose. Leverage magnifies losses as well as gains.
Past performance, whether from backtesting, forward testing, demo trading or a live account, is not a reliable indicator of future results. Backtests in particular are produced under conditions that differ from live trading: historical spreads, slippage, requotes, execution delays and gaps are approximated or absent, and an optimised set of parameters can describe past price behaviour without predicting future behaviour.
This Expert Advisor is a tool that executes a defined set of rules. It does not predict market direction, and it cannot be expected to be profitable under all market conditions or on all instruments. No representation is made that any account will or is likely to achieve any particular result.
You are solely responsible for your own trading decisions, for the settings you apply, for the risk you take on each trade, and for monitoring the EA while it is running. Automated systems can be affected by platform restarts, loss of connectivity, broker-side changes to symbol specifications or trading conditions, and periods of unusual volatility such as news releases and market gaps, during which orders may not execute at the expected price.
Nothing in this description is investment advice, a solicitation, or a recommendation to trade any instrument. If you are unsure whether trading is appropriate for you, seek advice from an independent and suitably licensed financial adviser.
COMPATIBILITY
Works on any symbol and any timeframe. No DLLs and no external dependencies. Available for both MetaTrader 4 and MetaTrader 5.
Contact me after your purchase to receive your gift!
