Accueil Indicateur technique Publication

Indicateur de Niveau : Optimisez vos Trades avec MetaTrader 5

Pièce jointe
37907.zip (1.59 KB, Télécharger 0 fois)

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_plots 0

#include <ChartObjects\ChartObjectsLines.mqh>

input bool alert = true; // utiliser l'alerte
input bool notification = true; // utiliser les notifications push
input double trigLv = 0.0; // niveau d'activation
input int deviation = 30; // déviation à partir de trigLv en points
input int lineWidth = 1; // largeur de ligne
input ENUM_LINE_STYLE lineStyle = STYLE_SOLID; // style de ligne
input color lineColor = clrMediumSpringGreen; // couleur de ligne
input color inactivityColor = clrLightGray; // couleur d'inactivité

CChartObjectHLine lv, dvH, dvL; 

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

//+------------------------------------------------------------------+
//| Fonction d'initialisation de l'indicateur personnalisé |
//+------------------------------------------------------------------+
int OnInit() {
  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))
        return INIT_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);
}

void OnDeinit(const int reason) {
  //lv.Delete();
  //dvH.Delete();
  //dvL.Delete();
}

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[]
) {
  static bool triggered = false;
  static datetime 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;
}

//+------------------------------------------------------------------+

    Articles connexes

    Commentaire (0)