MACD Divergences on price and indicator

Category: Indicators By: Jose7674 Created: June 14, 2018, 10:22 AM
June 14, 2018, 10:22 AM
Indicators
27 Comments

Here you are an indicator that shows divergences on price and MACD at the same time.

Indeed, you need to put 1 indicator on the price chart and another as a new indicator.

Divergences are drawn automatically and it does not repaint.

 

///////////////////////////////////////////////////////////

// MACD divergences on price
//by Jose Callao
// twitter @jose7674
// attach this indicator to the chart

N=40///N is the number of bars to look back for a divergence. Normal values are 20-40. Must be the same in both indicators

//using any other indicator is as easy as changing the values
miMACD = exponentialAverage[12](close) - exponentialAverage[26](close)

IF (BarIndex > 10+1+N) THEN

 //we look for bearish divergences
 IF (miMACD[1]>miMACD AND miMACD[1]>miMACD[2]) THEN
  extremum2=miMACD[1]
  extremum1=highest[N](miMACD)

  preciomax2=close[1]
  preciomax=Highest[N](close)
  IF(extremum2<extremum1 AND preciomax2>preciomax[1]) THEN
   for i=1 to N
    if close[i]=preciomax[1] then
     zz=i

     drawsegment (barindex[1], close[1], barindex[zz], close[zz]) coloured(200,0,0)
    endif
   next

  endif
 endif

 //we look for bullish divergences
 IF (miMACD[1]<miMACD AND miMACD[1]<miMACD[2]) THEN
  extremum22=miMACD[1]
  extremum11=lowest[N](miMACD)

  preciomin2=close[1]
  preciomin=lowest[N](close)

  IF(extremum22>extremum11 AND preciomin2<preciomin[1]) THEN
   for i2=1 to N
    if close[i2]=preciomin[1] then
     zz2=i2

     drawsegment(barindex[1], close[1], barindex[zz2], close[zz2]) coloured(0,200,0)
    endif
   next
  endif
 endif
endif
return

//////////////////////////////////////////////

 

/////////////////////////////////////////////

// MACD divergences on MACD
// by Jose Callao
// twitter @jose7674
// Use this indicator in a new window

N=40///N is the number of bars to look back for a divergence. Normal values are 20-40. Must be the same in both indicators

miMACD = exponentialAverage[12](close) - exponentialAverage[26](close)

IF (BarIndex > 10+1+N) THEN

 ///divergencia bajista
 IF (miMACD[1]>miMACD AND miMACD[1]>miMACD[2]) THEN
  extremum2=miMACD[1]
  extremum1=highest[N](miMACD)

  preciomax2=close[1]
  preciomax=Highest[N](close)

  IF(extremum2<extremum1 AND preciomax2>preciomax[1]) THEN
   for i=1 to N
    if mimacd[i]=extremum1 then
     zz=i

     drawsegment (barindex[1], mimacd[1], barindex[zz], mimacd[zz]) coloured(200,0,0)
    endif
   next

  endif
 endif

 ///divergencia alcista
 IF (miMACD[1]<miMACD AND miMACD[1]<miMACD[2]) THEN
  extremum22=miMACD[1]
  extremum11=lowest[N](miMACD)

  preciomin2=close[1]
  preciomin=lowest[N](close)

  IF(extremum22>extremum11 AND preciomin2<preciomin[1]) THEN
   for i2=1 to N
    if mimacd[i2]=extremum11[1] then
     zz2=i2

     drawsegment(barindex[1], mimacd[1], barindex[zz2], mimacd[zz2]) coloured(0,200,0)
    endif
   next
  ENDIF

 ENDIF
endif

return mimacd as "MACD", 0 as "0"

 

Download
Filename: MACD-divergences-on-MACD.itf
Downloads: 1036
Download
Filename: MACD-divergences-on-Price.itf
Downloads: 1010
Download
Filename: Divergencias-USDJPY.png
Downloads: 282
Jose7674 Junior
I usually let my code do the talking, which explains why my bio is as empty as a newly created file. Bio to be initialized...
Author’s Profile

Comments

Logo Logo
Loading...