Multi indicator/oscillator divergence indicator

13 September 2019, 08:58
Jan Flodin
24
9 131

The main purpose of this blog is to describe and explain the input parameters of my Multi oscillator divergence indicator (MT4 version / MT5 version) and for the free versions (the free versions don't offer all parameters below and has no support for alerts and limited buffer support for an Expert Advisor).

Please also check out my other divergence products for MT4:
Divergence scannerDouble divergence scannerDivergence dashboardDivergence Expert Advisor (free)

For MT5:
Double divergence scannerDivergence dashboardDivergence Expert Advisor (free)


Input parameters

Parameters marked with an asterisk (*) in the beginning are only available in/valid for the MT5 version and parameters marked with two asterisks (**) in the beginning are only available in the MT4 version. Parameters with green color are available in the free version.

  • Oscillator/indicator to use: Default is MACD. You can select from any of the above mentioned oscillators/indicators.
  • Draw histogram for MACD: Will draw the MACD main line as a histogram instead of a line. This is default in the native Metatrader MACD indicator.
  • Use old logic (before version x.x): True or False. Set to true to detect divergences the way it was before version 2.6 (* 2.4). The new logic will detect more divergences but it will also come with a performance cost. Something which will be more visible on slower computers. The new logic will allow divergences even if there are additional indicator extremums (top/bottoms) between the 2 already existing extremum points. If you are experiencing occasional terminal freezings then please set this value to False.
  • Alert logic: Listbox with the following selections:
    • Divergence: The alert will come after a divergences has been detected.
    • Donchian channel breakout: The alert will be sent when a bar has closed below/above the low/high of the Donchian channel.
    • Moving average cross: The alert will be sent when a bar has closed below/above the moving average.
    • Engulfing: Will only alert if the candle directly after the divergence candle is engulfing the divergence candle, hence the alert will be delayed one bar if 'Divergence candle shift' 0 is used (value 1 is not supported). The divergence lines will still be drawn on the chart though, with one bar delay, regardless if engulfing or not. Regular engulfing logic is used. So for instance at a regular bearish divergence the divergence candle must be a bullish candle and the next (engulfing) candle must be a bearish candle. Vice versa for a regular bullish divergence.
    • * Hull moving average: The alert will be sent as soon as the Hull color are aligned with the trade direction. So for instance for a bullish trade to be valid the Hull MA color must be green.
  • Engulfing pattern to scan for: Listbox with 4 selections. Only used if the Alert logic above has been set to 'Engulfing'
  • Divergence candle shift (must be 0, 1 or 2): Set to 2 for a stronger confirmation of the possible reversal/trend continuation (confirmed divergence, alert 2 candles later). This is the recommended setting which will also not repaint. 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 (repaintings). Higher values than 2 are not supported.
  • Scan for bullish divergences: True or False.
  • Scan for bearish divergences: True or False
  • Scan for hidden divergences: True or False.
  • Scan for regular divergences: True or False.
  • Bars to check (divergence depth): Bars back in time to check for a 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.
  • Max history bars: Bars back in time for which to draw divergences.
  • Strict mode: List box with 2 options. Price or Indicator level. When Price has been selected then, for regular divergences, the price of any of the candles between the both extremums is not allowed to be higher/lower than the price of the second extremum candle. For hidden divergences it is the same just that it is counted from the first extremum candle. These conditions are used in the same way when Indicator levels has been selected. The line levels in the indicator window then be used. 
  • Price type (used when Price has been selected above): List box with 2 options. Close price or High/low price. Close price basically means that wicks are allowed to cross the price of the extremum candle.
  • Min/max close percent away from high/low (0=disabled): This can be used to avoid situations where for instance the candle for a bearish divergence closes near or at its high price. The value could bet set to for instance 20 to get a wick which is at least 20% of the candle size.
  • DONCHIAN CHANNEL BREAKOUT SETTINGS
    • Donchian channel period: The default value for a Donchian channel is 20. The channel period is calculated backwards from the divergence candle.
    • Breakout period: The period in bars for how long to wait for a breakout.
  • MOVING AVERAGE (MA) CROSS SETTINGS
    • MA period
    • Breakout period: The period in bars for how long to wait for a breakout.
    • MA shift
    • MA method
    • Price type
  • * HULL MOVING AVERAGE (HMA) SETTINGS
    • PeriodMoving average period.
    • SpeedSmoothening ratio.
    • Breakout periodThe period in bars for how long to wait for a breakout.
    • Candle shiftDefault is 1. Can be set to 0 to catch the color change one candle earlier (unconfirmed signal).
  • MACD, OsMA AND AWESOME (AO) SETTINGS (in the MT 5 version the fast and slow MA values for Awesome are automatically set to 5 and 34. No need to change the 2 first parameters below)
    • Fast MA: Default is 12 (5 for Awesome).
    • Slow MA: Default is 26 (34 for Awesome).
    • Signal MA: Default is 9 (not used for Awesome).
  • CCI, RSI, RVI, ATR, MFI, MOMENTUM SETTINGS
    • Period: Default period is 10.
  • STOCHASTIC SETTINGS
    • K: Default is 10.
    • D: Default is 3.
    • Slowing: Default is 3.
    • Price type
    • Overbought/oversold filter offset (0=disabled): If you set for instance the value 10 then the signals will come only if stochastics is below 10 (0+10) or above 90 (100-10).
  • ADX SETTINGS
  • * OBV AND MFI SETTINGS
    • Volume type for calculation: List box from where you can select from Tick volume or Real volume.
  •  COMPOSITE INDEX SETTINGS
    • RSI slow period
    • RSI fast period
    • Momentum period
    • Average period 1
    • Average period 2
    • Average period 3
    • Price type
  • FILTER SETTINGS
    • Filter to use: Listbox with 3 selections. RSI, Bollinger or ATR. ATR works so that for a bullish signal to be valid the candle must close below the ATR value (close price +/- the ATR value multiplied with the ATR multiplier below) and vice versa for a bearish signal. Bollinger works so that high/low price must be above/below the upper/lower band.
    • Enable RSI for hidden divergences: True or False.
    • RSI overbought and oversold levels: The divergence candle must form above/below these levels in order to be valid.
    • ** RSI apply to price: RSI level is calculated from this setting.
    • ATR multiplier
    • * Period: Period (typically 20 for Bollinger).
    • * Bollinger shift
    • * Bollinger deviation
    • trend price type
    • Show lines even if filter out of range: True or False. When setting this to False then the lines and arrows will not be drawn on the chart if the filter has been enabled and the price is not within the levels.
    • * Show trend indicator on chart: True or False. Will draw the trend indicator on the chart.
  • LINES
    • Show RSI/Stochastics/MFI indicator window levels: True or False. Please leave this value to False if you are setting your own custom indicator levels.
    • Indicator level 1: Default is 80.
    • Indicator level 2: Default is 20.
    • Indicator max. value: Default is 100.
    • Indicator min. value: Default is 0.
    • * Draw moving average line: True or False. When True then the moving average indicator will be added to the chart with the settings you have set in the MOVING AVERAGE (MA) CROSS SETTINGS section.
    • Bullish line color: Color for bullish lines.
    • Bearish line color: Color for bearish lines.
    • Indicator level line color: Color of the level line(s) in the indicator window.
    • * Draw divergence lines on chart: True or False.
  • ALERTS: Set to True for each alert type you would like to receive. All alert types are supported.
    • Custom alert text: If you put you own additional text here it will be embedded into the regular alert text. In the beginning, after the info about symbol and time frame.


Example how to use iCustom() in an Expert Advisor

MT4 and MT5 paid versions:

You will be able to download an Expert Advisor with code examples at the end of this blog.

MT5 version (free):

First in the code header declare:

int icustom_handle;

Then in the OnInit() event:   

icustom_handle = iCustom(NULL, 0, "Market\\Multi indicator divergence MT5.ex5"
      ,3 // Stochastics
      ,false      
      ,2 // confirmed divergence      
      ,28
      ,100      
      ,"======= MACD AND OsMA SETTINGS ======="
      ,12,26,9
      ,"======= CCI, RSI, RVI, ATR, MFI, MOMENTUM SETTINGS ======="
      ,10
      ,0 // Price type CLOSE, for CCI and RSI
      ,"======= STOCHASTIC SETTINGS ======="
      ,10,3,3,0
      ,"======= ADX AND OBV/MFI (VOLUME) SETTINGS ======="
      ,10
      ,1 // MODE_PLUSDI
      ,0 // tick volume
      ,"======= COMPOSITE INDEX SETTINGS ======="
      ,14,3,9,3,13,33,0
  );

Finally in the OnTick() event something like this (the Alert will typically be replaced by additional entry logic and finally OrderSend()):

double bullBuffer[],bearBuffer[];

int bullish = CopyBuffer(icustom_handle,0,2,1,bullBuffer); // 2 = confirmed divergence

int bearish = CopyBuffer(icustom_handle,1,2,1,bearBuffer);

if(bullBuffer[0] != 0 && bullBuffer[0] != EMPTY_VALUE) Alert("Bullish divergence"); // open long trade

if(bearBuffer[0] != 0 && bearBuffer[0] != EMPTY_VALUE) Alert("Bearish divergence"); // open short trade




Share it with friends: