Divergence EA MT5

The main purpose of this blog is to describe and explain the input parameters of my Divergence Expert Advisor for MT5 (free version / paid version).

Please check out my other divergence products for MT5:
Divergence indicatorDouble divergence scannerDivergence dashboard

This is an out-of-the-box product which will normally not be modified based on request from a single customer. Please therefore first read this blog to the end and/or download a demo and test the EA in the strategy tester in order to understand what it can and cannot do.

Whenever there is an available update of the EA I recommend you to wait with updating until all open positions by the EA have been closed. You can update it without removing the previous version from the chart. Before updating I also recomend to turn off AutoTrading and after the update please control that the input parameters have not changed on each chart where the EA is loaded. Then you can turn on AutoTrading again.

I strongly recommend you to do your own backtesting and fine tuning in the strategy tester before starting to trade on a live account. This is valid also if you decide to use the .set (preset) files which you can download at the end of this blog. You must use the ‘Every tick based on real ticks’ modelling option in MT5 if you are using settings where intracandle activities are involved, such as trailing stop. If not then it is enough with ‘1 minute OHLC’ modelling. Please remember that past performance is not a guarantee of future profitability and that the optimized backtest results cannot provide a realistic prediction of future profitability. Signal monitoring here.

Input parameters

Parameters marked with an asterix (*) in the beginning are only available in the free version and two asterisks (**) means available only in the paid version.

  • GENERAL SETTINGS
    • * Send alert instead of opening trade – When set to ‘true’ an alert will be sent instead of opening a trade.
    • ** EA mode – List box with the following selections:
      • Trade normally
      • Send alert instead of opening trade – Will alert about a trade oppurtunity instead of opening the trade.
      • Pause EA – Will totally pause the EA. Existing orders will not be modified in case break even, trailing stop etc. has been enabled.
    • ** Multi symbol mode – List box with the following selections:
      • Disabled – The EA will only trade the current chart symbol.
      • Market Watch – All visible symbols in the Market Watch window.
      • Symbols from input parameter – Symbols given in the ‘Symbols to trade’ input parameter below.
      • Presets from folder – Symbols from preset files selected in a dialog box. These presets must exist directly under the Files folder, or in a subfolder to Files. Each preset file must contain the name of the symbol according to how it is written in the Market Watch window. Parameters marked with blue text are parameters which will be used from preset files when you have selected this option. The other parameters vill be taken from the EA.
      • Presets by selection – Symbols from all existing preset files in a predefined folder (given in the ‘Preset files folder…’ input parameter below). These presets must exist directly under the Files folder, or in a subfolder to Files. Each preset file must contain the name of the symbol according to how it is written in the Market Watch window. Parameters marked with blue text are parameters which will be used from preset files when you have selected this option. The other parameters vill be taken from the EA.
    • ** Symbols to trade – These symbols will be used when the ‘Symbols from input parameter’ Multi symbol mode has been selected above. The symbols must be comma separated and visible in the Market Watch window.
    • ** Preset files folder (must be subfolder under Files) – All preset files in this folder will be loaded when the ‘Presets from folder’ Multi symbol mode has been selected above.
    • ADR period (days) – Average daily range over the past xx days. Default is 60.
    • ** Event handler on minute candle instead of tick –  ‘true’ or ‘false’. If set to True then the testing will be quicker in the strategy tester but less accurate in case you are using settings which involved intracandle activities. For instance trailing stop.
  • TREND FILTER SETTINGS
    • Trend filter to use – List box from where you can select RSI, Bollinger or Stochastics. The trend filter will be used with reversal logic, hence the price must have reached for example RSI 70, or the bollinger upper bands in order for a short (bearish) trade to be opened.
    • Measure trend filter on first extremum  – True or False.
    • Stochastics/RSI overbought level – The divergence candle must form above this level in order to be valid.
    • Stochastics/RSI oversold level – The divergence candle must form below this level in order to be valid.
    • Bollinger shift
    • Bollinger deviation
    • Trend period (default 20 for Bollinger)
    • ADX level
    • ADX period
    • Price type
    • Time frame – if set to ‘current’ then the chart time frame will be used. Otherwise the selected time frame will be used for calculating the the trend indicator values.
  • GENERAL DIVERGENCE SETTINGS
    • Main oscillator
    • Enable divergences – a list of 5 oscillators/indicators which you can select from if you have set Main oscillator to Multi mode.
    • Amount of concurrent divergences to look for (if Multi mode)
    • Time frame for next divergence(s) – Default is current. This setting will be used if Amount of concurrent divergences above is set to > 1. If for instance you trade on a M30 chart and change this setting from current to H1 then the next divergence(s) must occur on the H1 time frame. *** for the next version this will also apply if single mode and the value is set to something else than current. Example: the EA is setup to trade MACD divergences. The chart time frame is H1 and the value here is H4. In this case there must be a MACD divergence on H1 and H4 at the same time.
    • Divergence candle shift – Set to 2 or higher for a stronger confirmation of the possible reversal/trend continuation (confirmed divergence). By having it set to 1 you will catch the possible movement earlier (unconfirmed/pending divergence). On the other hand, the signal is less reliable. You can also set it to 0 for catching “early” divergences. This means that the alert will come directly upon candle open instead of waiting for the slope in the indicator to change direction (candle shift 1 or 2), which means that the price must show at least some sign of reversal. Please be aware though that this will lead to more false signals.
    • Bars to check (divergence depth) – Bars back in time to check for divergence.
    • Min. bars to check (0=disabled) 
    • Ignore wicks on divergence candles –  Divergence will be based on open/close price instead of high/low price.
  • REGULAR DIVERGENCE SETTINGS (trend reversal)
    • Trade regular – True or False.
    • Use trend filter – True or False.
    • Use ADX – The ADX value must be below the level you have set.
    • Use moving average filter –  When enabled then the price must be above/below the MA value for the period you have set in the input parameter under the ‘MOVING AVERAGE (MA) FILTER SETTINGS’ section.
  • HIDDEN DIVERGENCE SETTINGS (trend continuation)
    • Trade hidden – True or False.
    • Use trend filter – True or False.
    • Use ADX – The ADX value must be above the level you have set.
    • Use moving average filter – When enabled then the price must be above/below the MA value for the period you have set in the input parameter under the ‘MOVING AVERAGE (MA) FILTER SETTINGS’ section.
  • TRADING FILTERS
    • Open buy order – True or False.
    • Open sell order – True or False.
    • Maximum allowed slippage in points – Please note that not all brokers/account types support slippage control.
    • Maximum allowed open/close spread in points (0 = not used) – Can be set to avoid taking trades with high spread directly after midnight market opening or at news releases. Useful for those with variable spreads. The default settings of 50 is for currencies. 
    • Bars to wait for next trade – Default is 1 which means that the EA can trade again (if no open orders) on the bar following the bar where the last trade was closed. Setting it to 0 means that a new trade will be opened directly after the previous has been closed (if there is still a valid signal). Let us take the example that we have this setting set to 1. If we for instance had an order on a H1 chart which was closed at 13:10 then, in case there is a new divergence signal, a new order will not be opened directly at 13:10 but at 14:00. If you had it set to 2 then at 15:00 and so on. The original idea with this setting was when using the EA for scalping (small and quick profits). In this case it will very often come to the scenario that the EA will open and close (with profit) the order on the same bar. We might then like to avoid opening another order again on the same bar.
    • * Enable trade time filter (your broker’s server time) – Time filter for opening trades.
    • * Trade from/to time – Hour and minutes from/to.
    • * Stop time Friday (hh:MM, 00:00=disabled) – Hour and minut when to stop trade on a Friday.
    • ** Start hour [0-23]
    • ** Start minute [0-59]
    • ** Stop hour [0-23]
    • ** Stop minute [0-59]
    • ** Stop time Friday (-1=disabled)
    • Volume average period (0=volume filter disabled) 
    • Volume over average (percent) 
  • MONEY MANAGEMENT (levels are in points)
    • Risk in percentage (>0 = auto lot) – If set to 0 the Manual lots value will be used. If set to > 0 then the EA will use money management if combined with a stop loss. The account free margin (in the deposit currency) is used for the risk calculation. The risk calculation might not work properly with metals and indices. Please use a manual lot if you are experience problems.
    • Manual lots – Will be used if Risk above is set to 0.
    • ** Allow only one order per symbol and direction – Set to True and you will never risk that for instance that a second sell order will be opened for the chart symbol. Useful if you are trading the same symbol on several charts and with different magic numbers.  It is possible to enable this on a global level by changing it on one place only. It will then be valid for all charts in a Metatrader instance where the EA has been loaded. Hit F3 on the keyboard and change the value of the ‘TripleMA-OneOrder’ global variable from 0 to 1. In order for this to work the order comment must contain the word ‘Triple’.
    • ** Max. open positions (0=disabled) –  Set to for instance 5 and you will never risk that the EA will have more than 5 active trades. Useful if you have the EA running on several charts and would like to reduce the risk. It is possible to enable this on a global level by changing it on one place only. It will then be valid for all charts in a Metatrader instance where the EA has been loaded. Hit F3 on the keyboard and change the value of the ‘TripleMA-MaxOrders’ global variable from 0 to a hihger value. In order for this to work the order comment must contain the word ‘Triple’.
    • ** Stop trading when Equity decreased (0=disabled) – will not open any new orders if the equity is decreased by this number. If you put for instance 1000 and your current balance is 4000 then the EA will not open new trades if your equity goes below 3000.
    • ** Stop trading when Free margin below (0=disabled) –  will not open any new orders if the free margin goes below this number.
    • ** Orders with this Magic number (0=all) – With the default value (67) the EA will only check open order where the Magic number starts with 67. So if you have other EAs running with open orders then they will not be taken into consideration.
    • ** Close orders – If set to True then all orders, where the magic number starts with the value you have set above, will be closed immediately when the max value has been reached.
  • POSITION MANAGEMENT (levels are in points)
    • Type of stop loss/exit – List box with the following selections:
      • Fixed
      • At divergence candle high/low – Stop loss will be set at candle high/low + the amount of points that you have specified in the ‘ Offset in points…’ parameter.
      • ATR SL – The current (close price of divergence candle) ATR level multiplied with the value you have set below in the ‘Multiplier for stop loss’ parameter under the ATR SETTINGS section.
    • Fixed stop loss (<0 = ADR %)  When a negative (minus) value will be put here then the ADR% logic will be used.
    • Take profit method – List box with the following selections:
      • Fixed take profit
      • Trailing stop – starts to trail when profit>=0
      • ATR trailing stop
      • ATR TP
      • Risk/Reward (based on SL)
    • Fixed take profit (<0 = ADR %) – When a negative (minus) value will be put here then the ADR% logic will be used. Values which work for most pairs are -15 for H1, -25 for H4 and -40 for D1.
    • Trailing stop  (<0 = ADR %) – Will trail the stop loss constantly with the distance you have set as soon as the trade is in profit. When a negative (minus) value will be put here then the ADR% logic will be used. Traling stop will not work properly when using the Close half option.
    • Trailing step – If the trailing step is set to 0 then the trailing stop will be adjusted each 2nd second. Else the trailing stop will be adjusted every time the price has moved the amount of points you have set here.
    • Risk/Reward ratio – You need to set the “Take profit method” parameter to Risk/Reward in order for this value to have any effect. You need also to set “Type of stop loss/exit” to Fixed and a fixed stop loss value. A stop loss value of 200 points and a R/R ratio of 1.5 would mean that the take profit level would be automatically set to 300 points when an order is opened.
    • Break-even (0 = disabled)
    • Break-even trigger – The price has to reach this level (calculated from the opening price) in order for the break-even to be set.
    • Offset (<0=ADR%, >0=points, 0=disabled) – Additional distance for for the stop loss (if it has been set to ‘At divergence candle high/low’).
  • CLOSE HALF SETTINGS
    • Close half position – Combo box with the selections below. Please make sure that your account supports part close of orders before you use this option.
      • Disabled – Default value.
      • ATR – The current (close price of divergence candle) ATR level multiplied with the value you have set below in the ‘Multiplier for close half’ parameter under the ATR SETTINGS section. When you have set this option then a line showing the level will be drawn on the chart.
      • At first TP level – If you select this option you will also have to adjust the value in the ‘First TP level…’ parameter below.
    • Move to break-even after close half – True or False.
    • First TP level for Close half (<0 = ADR %)
  • ATR SETTINGS
    • Period
    • Price type – Select from High/low, Median or Close.
    • Multiplier for take profit and close half
    • Multiplier for stop loss
  • MACD AND OsMA SETTINGS
    • Fast MA – Default is 12
    • Slow MA – Default is 26
    • Signal MA – Default is 9
  • STOCHASTIC SETTINGS
    • K
    • D
    • Slowing
    • MA methodDefault is ‘Simple’ (SMA).
    • Price type
    • ** Overbought/oversold filter offset (0=disabled) – Set to for instace 10 means that the divergence must occur if the stochastics value is above 90 for sell trade or below 10 for a buy trade to be valid.
  • CCI AND RSI SETTINGS
  • MOVING AVERAGE (MA) FILTER SETTINGS
    • Slow MA 
    • Fast MA (0 = disabled)
    • Slow/fast MA method – Default is Simple (SMA).
    • Slow/fast MA price type – Default is Close.
    • MA time frame – It is recommended to set this to one time frame higher than the divergence time frame.
  • ** HULL MOVING AVERAGE (HMA) FILTER SETTINGS
    • Period – Moving average period.
    • Speed –  Smoothening ratio.
    • Candle shift –  Default is 1. Can be set to 0 to catch the color change one candle earlier (unconfirmed signal).
  • OBJECTS
    • Draw divergence lines on main chart – True or False. When set to True the EA will draw the divergence lines on the main (price) chart.
    • Draw TP1 levels on chart
    • Show divergence indicator window – True or False. When set to True the EA add the currently used divergence oscillator as an indicator window on the chart. Please note though that the divergence lines will not be drawn in this window.
    • Show info panel on chart
    • Various color settings for the information panel
    • TP1 line color
    • TP1 line thickness
    • Clear objects – True or False. When set to True the EA will delete the divergence lines on the chart each time the EA is reinitilized.
  • ALERTS (if alert instead of trade is enabled)
    • Set to ‘true’ for each alert type you would like to activate.
  • Magic number – If using the EA on the same symbol on multiple charts (typically with different time frames, or same time frame but one chart trading Hidden only and another trading Regular only) then it is important that the Magic number parameter has a different value. If not then trades on the same symbol will interfere with eachother.
  • Order comment – This parameter is not used. The comment will be set automatically. For instance “Reg [divergence indicator] M30” or “Reg [first indicator]/[second indicator]/[third indicator] M30” if you have set ‘Amount of concurrent divergences to look for’ higher than 1. The amount of characters in the order comment is by design limited to 32. So if you have set this to a value higher than for instance 4 then the text in the order comment will be cut at 32 characters. By some brokers it might even come be empty.

Source link

#Divergence #MT5