Jose7674

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
MACD Divergences on price and indicator

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: 1056
Download
Filename: MACD-divergences-on-Price.itf
Downloads: 1028
Download
Filename: Divergencias-USDJPY.png
Downloads: 285
Jose7674
Jose7674 Junior
As an architect of digital worlds, my own description remains a mystery. Think of me as an undeclared variable, existing somewhere in the code.
Author’s Profile

Comments

julien1978
5 years ago
#

hello to all, i recently discovered this indicator. would it be possible to add the detection of hidden divergences on it? that would be awesome!

GUCCI ONE
5 years ago
#

Bonjour, Nicolas. Pourriez-vous m'aider à transformer cet indicateur en screener, svp ? Merci

Nicolas
5 years ago
#

disponible ici: https://www.prorealcode.com/topic/divergences-screener/

Lily Rios
6 years ago
#

Excelente trabajo Jose, existe algún screener para este indicador?

Jose7674
6 years ago
#

Intentaré poner el screener está semana

pacorapvalle
6 years ago
#

Gracias por el indicador y me uno a los que han preguntado si hay algun screener.

Bertone
6 years ago
#

Great job. It really works, especially on the weekly chart.Awesome!! Can it be used as a Screener??

Psg91450
7 years ago
#

Good evening José7674, First of all thank you for sharing on the macd. I would like to put an alert on the green and red color changes but I can't do it. Can you help me and give me the code please. Thank you in advance.

tradingthelife
8 years ago
#

Hi friends, any help with a screener for this indicator? Best regards.

FrancoisB
8 years ago
#

Nice, does anyone know how to show the hidden divergence as well?

thomas2004ch
8 years ago
#

I use the break to get off after the first divergency line is drawn. But this seems not work.

thomas2004ch
8 years ago
#

How can I just draw the latest divergency line? I try the following but no line is drawn. 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 break next

tradingthelife
8 years ago
#

Hay alguna manera de hacer un proscreener para este indicador? Lo he intentado pero no lo consigo. Saludos y gracias.

franciscojbritop
8 years ago
#

Hola Jose7674, Utilizas algun screener para encontrar candidatos que esten mostrando estas MACD divergences mostradas en tu codigo? Saludos

franciscojbritop
8 years ago
#

Hola tradingthelife, has tenido suerte encontrando un screener para este indicador? He estado un tiempo largo buscandolo y no logro conseguirlo tampoco. Saludos

abhay
8 years ago
#

divergence lines on MACD indicator are not showing. It shows only on Price chart

Nicolas
8 years ago
#

Because you have to apply it on the price chart too.

tradingthelife
8 years ago
#

@jose7674 este indicador es una auténtica joya, muchas gracias por compartirlo. Uno de los inconvenientes es la visibilidad, como comentaba @supertiti. Lo he tuneado un poco y después del drawsegment he añadido DRAWARROWDOWN(barindex[1], miRSI[1]) COLOURED(200,0,0) para las bajistas, y DRAWARROWUP(barindex[1], miRSI[1]) COLOURED(0,200,0) para las alcistas. Lo de las divergencias ocultas sería un plus. No tengo nivel para esto, pero @Francesco hizo también un gran trabajo con este indicador que sí las incluye: https://www.prorealcode.com/prorealtime-indicators/rsi-classical-hidden-divergences-indicator/ Saludos y gracias de nuevo por tu aporte.

cc
cc
8 years ago
#

Excelente indicador @jose7674 Seria ideal que pudiera detectar las divergencias reales como lo hace y ademas las escondidas (hidden). Gracias

TAC Bolsa
8 years ago
#

Muy Buen trabajo Jose... no lo he podido mirar hasta ahora... y me parece muy bueno...... sobre todo en otros indicadores, con tu permiso lo adaptare para otros indicadores como HPI.. la versión mejorada..

Jose7674
8 years ago
#

Claro, es muy sencillo de adaptar! Ya pondrás algún resultado o idea que saques. La idea surgió al ver tu indicador modificado. Creía que también dibujaba las divergencias ... y ya empecé a pensar como hacerlo

Inertia
8 years ago
#

Well done !

JohnScher
8 years ago
#

ty fine work I've been looking for this for a long time.

juanj
8 years ago
#

Neat! You should do the same for RSI and MFI. I usually validate divergence on all three.

Jose7674
8 years ago
#

It’s quite simple. Just change mimacd=rsi[14](close) On both and it’s done You can use any other indicator this way

Jose7674
8 years ago
#

De nada, un placer. Adaptarlo a cualquier otro indicador es sencillo. Si el indicador es rapido (estocastico, rsi), N deberia ser 20. En indicadores mas "lentos" como un MACD estandar se puede subir el valor de N a 40

supertiti
8 years ago
#

@ Jose Gracias por estos indicadores que parecen muy buenos ! @Nicolas Puedes preguntar a PRT para tener los segmentos mas gruesos ? gracias

ProRealCode ProRealCode
Loading...