Indicateur MACD pour MT4 : Barres Colorées au-dessus et en-dessous de Zéro

Mike 2019.02.07 00:26 17 0 0
Pièce jointe

Découvrez comment utiliser l'indicateur MACD avec des barres colorées qui s'affichent au-dessus ou en dessous du niveau zéro. Un outil essentiel pour tous les traders souhaitant affiner leur analyse technique.

Paramètres Configurables :

  • Niveaux MACD
  • Alerte par Email
  • Alerte sonore
  • Notification Push

Ce système de trading est parfait pour visualiser rapidement les signaux d'achat et de vente. Voici un aperçu de son fonctionnement :

#property copyright   "MACD Above Below Zero Color Bars"                   
#property copyright   "ckart1.simplesite.com"  
                           
#property copyright "Copyright 2015, MetaQuotes Software Corp."
#property link      "https://www.mql5.com"
#property version   "1.00"
#property strict

#include <stdlib.mqh>
#include <stderror.mqh>

//--- paramètres de l'indicateur
#property indicator_chart_window
#property indicator_buffers 8

#property indicator_type1 DRAW_HISTOGRAM
#property indicator_style1 STYLE_SOLID
#property indicator_width1 3
#property indicator_color1 0xFF2600
#property indicator_label1 "MACD au-dessus de Zéro"

#property indicator_type2 DRAW_HISTOGRAM
#property indicator_style2 STYLE_SOLID
#property indicator_width2 3
#property indicator_color2 0xFF0303
#property indicator_label2 "MACD au-dessus de Zéro"

#property indicator_type3 DRAW_HISTOGRAM
#property indicator_style3 STYLE_SOLID
#property indicator_width3 1
#property indicator_color3 0xFF0033
#property indicator_label3 "MACD au-dessus de Zéro"

#property indicator_type4 DRAW_HISTOGRAM
#property indicator_style4 STYLE_SOLID
#property indicator_width4 1
#property indicator_color4 0xFF0059
#property indicator_label4 "MACD au-dessus de Zéro"

#property indicator_type5 DRAW_HISTOGRAM
#property indicator_style5 STYLE_SOLID
#property indicator_width5 3
#property indicator_color5 0x0000FF
#property indicator_label5 "MACD en-dessous de Zéro"

#property indicator_type6 DRAW_HISTOGRAM
#property indicator_style6 STYLE_SOLID
#property indicator_width6 3
#property indicator_color6 0x0000FF
#property indicator_label6 "MACD en-dessous de Zéro"

#property indicator_type7 DRAW_HISTOGRAM
#property indicator_style7 STYLE_SOLID
#property indicator_width7 1
#property indicator_color7 0x0000FF
#property indicator_label7 "MACD en-dessous de Zéro"

#property indicator_type8 DRAW_HISTOGRAM
#property indicator_style8 STYLE_SOLID
#property indicator_width8 1
#property indicator_color8 0x0000FF
#property indicator_label8 "MACD en-dessous de Zéro"

//--- tampons de l'indicateur
double Buffer1[];
double Buffer2[];
double Buffer3[];
double Buffer4[];
double Buffer5[];
double Buffer6[];
double Buffer7[];
double Buffer8[];

extern int Fast_EMA = 12;
extern int Slow_EMA2 = 26;
extern int MACD_SMA3 = 9;
datetime time_alert; // utilisé lors de l'envoi d'alerte
extern bool Send_Email = false;
extern bool Audible_Alerts = true;
extern bool Push_Notifications = false;
double myPoint; // initialisé dans OnInit

void myAlert(string type, string message)
  {
   if(type == "print")
      Print(message);
   else if(type == "error")
     {
      Print(type+" | MACD Above Below Zero @ "+Symbol()+","+Period()+" | "+message);
     }
   else if(type == "order")
     {
     }
   else if(type == "modify")
     {
     }
   else if(type == "indicator")
     {
      Print(type+" | MACD Above Below Zero @ "+Symbol()+","+Period()+" | "+message);
      if(Audible_Alerts) Alert(type+" | MACD Above Below Zero @ "+Symbol()+","+Period()+" | "+message);
      if(Send_Email) SendMail("MACD Above Below Bars", type+" | Gann Arrow @ "+Symbol()+","+Period()+" | "+message);
      if(Push_Notifications) SendNotification(type+" | MACD Above Below Zero @ "+Symbol()+","+Period()+" | "+message);
     }
  }

//+------------------------------------------------------------------+
//| Fonction d'initialisation de l'indicateur                         |
//+------------------------------------------------------------------+
int OnInit()
  {   
   IndicatorBuffers(8);
   SetIndexBuffer(0, Buffer1);
   SetIndexEmptyValue(0, 0);
   SetIndexBuffer(1, Buffer2);
   SetIndexEmptyValue(1, 0);
   SetIndexBuffer(2, Buffer3);
   SetIndexEmptyValue(2, 0);
   SetIndexBuffer(3, Buffer4);
   SetIndexEmptyValue(3, 0);
   SetIndexBuffer(4, Buffer5);
   SetIndexEmptyValue(4, 0);
   SetIndexBuffer(5, Buffer6);
   SetIndexEmptyValue(5, 0);
   SetIndexBuffer(6, Buffer7);
   SetIndexEmptyValue(6, 0);
   SetIndexBuffer(7, Buffer8);
   SetIndexEmptyValue(7, 0);
   // initialisation de myPoint
   myPoint = Point();
   if(Digits() == 5 || Digits() == 3)
     {
      myPoint *= 10;
     }
   return(INIT_SUCCEEDED);
  }

//+------------------------------------------------------------------+
//| Fonction de calcul de l'indicateur                               |
//+------------------------------------------------------------------+
int OnCalculate(const int rates_total,
                const int prev_calculated,
                const datetime& time[],
                const double& open[],
                const double& high[],
                const double& low[],
                const double& close[],
                const long& tick_volume[],
                const long& volume[],
                const int& spread[])
  {
   int limit = rates_total - prev_calculated;
   //--- comptage de 0 à rates_total
   ArraySetAsSeries(Buffer1, true);
   ArraySetAsSeries(Buffer2, true);
   ArraySetAsSeries(Buffer3, true);
   ArraySetAsSeries(Buffer4, true);
   ArraySetAsSeries(Buffer5, true);
   ArraySetAsSeries(Buffer6, true);
   ArraySetAsSeries(Buffer7, true);
   ArraySetAsSeries(Buffer8, true);
   //--- zéro initial
   if(prev_calculated < 1)
     {
      ArrayInitialize(Buffer1, 0);
      ArrayInitialize(Buffer2, 0);
      ArrayInitialize(Buffer3, 0);
      ArrayInitialize(Buffer4, 0);
      ArrayInitialize(Buffer5, 0);
      ArrayInitialize(Buffer6, 0);
      ArrayInitialize(Buffer7, 0);
      ArrayInitialize(Buffer8, 0);
     }
   else
      limit++;
   
   //--- boucle principale
   for(int i = limit-1; i >= 0; i--)
     {
      if (i >= MathMin(1000-1, rates_total-1-50)) continue; // omettre certaines anciennes cotations pour éviter "Array out of range" ou un calcul lent   
      // Tampon de l'indicateur 1
      if(iMACD(NULL, PERIOD_CURRENT, Fast_EMA, Slow_EMA2, MACD_SMA3, PRICE_CLOSE, MODE_MAIN, i) > 0 // MACD > valeur fixe
      )
        {
         Buffer1[i] = Open[i]; // Définir la valeur de l'indicateur à l'ouverture des bougies
         if(i == 0 && Time[0] != time_alert) { myAlert("indicator", "MACD au-dessus de Zéro"); time_alert = Time[0]; } // Alerte instantanée, seulement une fois par bougie
        }
      else
        {
         Buffer1[i] = 0;
        }
      // Tampon de l'indicateur 2
      if(iMACD(NULL, PERIOD_CURRENT, Fast_EMA, Slow_EMA2, MACD_SMA3, PRICE_CLOSE, MODE_MAIN, i) > 0 // MACD > valeur fixe
      )
        {
         Buffer2[i] = Close[i]; // Définir la valeur de l'indicateur à la fermeture des bougies
         if(i == 0 && Time[0] != time_alert) { myAlert("indicator", "MACD au-dessus de Zéro"); time_alert = Time[0]; } // Alerte instantanée, seulement une fois par bougie
        }
      else
        {
         Buffer2[i] = 0;
        }
      // Tampon de l'indicateur 3
      if(iMACD(NULL, PERIOD_CURRENT, Fast_EMA, Slow_EMA2, MACD_SMA3, PRICE_CLOSE, MODE_MAIN, i) > 0 // MACD > valeur fixe
      )
        {
         Buffer3[i] = High[i]; // Définir la valeur de l'indicateur au plus haut des bougies
         if(i == 0 && Time[0] != time_alert) { myAlert("indicator", "MACD au-dessus de Zéro"); time_alert = Time[0]; } // Alerte instantanée, seulement une fois par bougie
        }
      else
        {
         Buffer3[i] = 0;
        }
      // Tampon de l'indicateur 4
      if(iMACD(NULL, PERIOD_CURRENT, Fast_EMA, Slow_EMA2, MACD_SMA3, PRICE_CLOSE, MODE_MAIN, i) > 0 // MACD > valeur fixe
      )
        {
         Buffer4[i] = Low[i]; // Définir la valeur de l'indicateur au plus bas des bougies
         if(i == 0 && Time[0] != time_alert) { myAlert("indicator", "MACD au-dessus de Zéro"); time_alert = Time[0]; } // Alerte instantanée, seulement une fois par bougie
        }
      else
        {
         Buffer4[i] = 0;
        }
      // Tampon de l'indicateur 5
      if(iMACD(NULL, PERIOD_CURRENT, Fast_EMA, Slow_EMA2, MACD_SMA3, PRICE_CLOSE, MODE_MAIN, i) < 0 // MACD < valeur fixe
      )
        {
         Buffer5[i] = Open[i]; // Définir la valeur de l'indicateur à l'ouverture des bougies
         if(i == 0 && Time[0] != time_alert) { myAlert("indicator", "MACD en-dessous de Zéro"); time_alert = Time[0]; } // Alerte instantanée, seulement une fois par bougie
        }
      else
        {
         Buffer5[i] = 0;
        }
      // Tampon de l'indicateur 6
      if(iMACD(NULL, PERIOD_CURRENT, Fast_EMA, Slow_EMA2, MACD_SMA3, PRICE_CLOSE, MODE_MAIN, i) < 0 // MACD < valeur fixe
      )
        {
         Buffer6[i] = Close[i]; // Définir la valeur de l'indicateur à la fermeture des bougies
         if(i == 0 && Time[0] != time_alert) { myAlert("indicator", "MACD en-dessous de Zéro"); time_alert = Time[0]; } // Alerte instantanée, seulement une fois par bougie
        }
      else
        {
         Buffer6[i] = 0;
        }
      // Tampon de l'indicateur 7
      if(iMACD(NULL, PERIOD_CURRENT, Fast_EMA, Slow_EMA2, MACD_SMA3, PRICE_CLOSE, MODE_MAIN, i) < 0 // MACD < valeur fixe
      )
        {
         Buffer7[i] = High[i]; // Définir la valeur de l'indicateur au plus haut des bougies
         if(i == 0 && Time[0] != time_alert) { myAlert("indicator", "MACD en-dessous de Zéro"); time_alert = Time[0]; } // Alerte instantanée, seulement une fois par bougie
        }
      else
        {
         Buffer7[i] = 0;
        }
      // Tampon de l'indicateur 8
      if(iMACD(NULL, PERIOD_CURRENT, Fast_EMA, Slow_EMA2, MACD_SMA3, PRICE_CLOSE, MODE_MAIN, i) < 0 // MACD < valeur fixe
      )
        {
         Buffer8[i] = Low[i]; // Définir la valeur de l'indicateur au plus bas des bougies
         if(i == 0 && Time[0] != time_alert) { myAlert("indicator", "MACD en-dessous de Zéro"); time_alert = Time[0]; } // Alerte instantanée, seulement une fois par bougie
        }
      else
        {
         Buffer8[i] = 0;
        }
     }
   return(rates_total);
  }
//+------------------------------------------------------------------+

Avec cet indicateur, vous serez en mesure de prendre des décisions éclairées basées sur les signaux MACD. N'oubliez pas d'ajuster les paramètres selon votre style de trading pour en tirer le meilleur parti !

Liste
Commentaire 0