Indicateur de Niveau : Optimisez vos Trades avec MetaTrader 5

Mike 2022.01.20 22:55 18 0 0
Pièce jointe

Lorsque le niveau trigLv spécifié dans les paramètres est franchi dans la déviation, l'indicateur envoie une notification push sur votre appareil mobile si le paramètre notification est activé, et joue également une alerte si le paramètre alert est activé. Le niveau de déclenchement trigLv, ainsi que les limites de déviation, sont mis en évidence par des lignes horizontales, dont le style, la couleur et l'épaisseur peuvent également être configurés dans les paramètres de l'indicateur. Ce design vous permet d'ajouter plusieurs copies de l'indicateur avec différents niveaux sur le graphique et de recevoir des signaux suite à leurs intersections.

Le niveau trigLv ne fonctionne qu'une seule fois par barre. La réactivation est possible uniquement après l'ouverture de la barre suivante. Cela permet d'éliminer des déclenchements trop fréquents à chaque tick.

Indicateur de Niveau

//+------------------------------------------------------------------+//| Indicateur de Niveau - Version 1.00 - Copyright 2022, © Cyberdev |//+------------------------------------------------------------------+#property copyright"Copyright 2022, © Cyberdev"#property link      "https://www.mql5.com/en/users/cyberdev/seller"#property version   "1.00"#property indicator_chart_window#property indicator_plots0#include <ChartObjects\ChartObjectsLines.mqh>

inputbool alert = true; // utiliser l'alerteinputbool notification = true; // utiliser les notifications pushinputdouble trigLv = 0.0; // niveau d'activationinputint deviation = 30; // déviation à partir de trigLv en pointsinputint lineWidth = 1; // largeur de ligneinputENUM_LINE_STYLE lineStyle = STYLE_SOLID; // style de ligneinputcolor lineColor = clrMediumSpringGreen; // couleur de ligneinputcolor inactivityColor = clrLightGray; // couleur d'inactivité

CChartObjectHLine lv, dvH, dvL; 

bool equal(double _v1, double _v2, double _epsilon) { returnfabs(_v1 - _v2) <= fabs(_epsilon); }

//+------------------------------------------------------------------+//| Fonction d'initialisation de l'indicateur personnalisé |//+------------------------------------------------------------------+intOnInit() {
  string name;
  double dv;
  color color_;
  name = "alert.lv-";
  dv = deviation * SymbolInfoDouble(NULL, SYMBOL_POINT);
  color_ = (alert || notification) ? lineColor : inactivityColor;
  for (int n = 0; n <= INT_MAX && !IsStopped(); n++) {
    if (ObjectFind(0, name + (string)n) != 0) {
      if (!lv.Create(0, name + (string)n, 0, trigLv))
        returnINIT_FAILED;
      lv.Width(lineWidth);
      lv.Style(lineStyle);
      lv.Color(color_);
      dvH.Create(0, "alert.dvH-" + (string)n, 0, trigLv + dv);
      dvH.Width(1);
      dvH.Style(STYLE_DOT);
      dvH.Color(color_);
      dvL.Create(0, "alert.dvL-" + (string)n, 0, trigLv - dv);
      dvL.Width(1);
      dvL.Style(STYLE_DOT);
      dvL.Color(color_);
      break;
    }
  }
  if (!alert && !notification) 
    Print("Indicateur de Niveau. Niveau ", lv.Price(0), " est inactif!");
  if (trigLv == 0.0)
    Alert("Indicateur de Niveau. Réglez le paramètre \"trigLv\" sur la valeur souhaitée!");
  return(INIT_SUCCEEDED);
}

voidOnDeinit(constint reason) {
  //lv.Delete();
  //dvH.Delete();
  //dvL.Delete();
}

intOnCalculate(constint rates_total,
                 constint prev_calculated,
                 constdatetime &time[],
                 constdouble &open[],
                 constdouble &high[],
                 constdouble &low[],
                 constdouble &close[],
                 constlong &tick_volume[],
                 constlong &volume[],
                 constint &spread[]
) {
  staticbool triggered = false;
  staticdatetime time_ = 0;
  if (!alert && !notification)
    return rates_total;
  if (equal(lv.Price(0), close[rates_total - 1], deviation * SymbolInfoDouble(NULL, SYMBOL_POINT))) { 
    if (time_ != time[rates_total - 1])
      time_ = time[rates_total - 1];
    else
      return rates_total;
    if (!triggered) {
      if (alert)
        Alert("Indicateur de Niveau. Niveau ", NormalizeDouble(lv.Price(0), (int)SymbolInfoInteger(NULL, SYMBOL_DIGITS)), " déclenché!");
      if (notification)
        SendNotification("Indicateur de Niveau. Niveau " + (string)NormalizeDouble(lv.Price(0), (int)SymbolInfoInteger(NULL, SYMBOL_DIGITS)) + " déclenché!");
    }
    triggered = true;
  }
  else
    triggered = false;
  
  return rates_total;
}

//+------------------------------------------------------------------+
    Liste
    Commentaire 0