Level Indicator: Een Handige Indicator voor MetaTrader 5

Mike 2022.01.20 22:55 12 0 0
Bijlage

De Level Indicator is een krachtige tool voor traders die gebruik maken van MetaTrader 5. Wanneer het trigLv niveau, dat je in de instellingen kunt aangeven, wordt overschreden binnen de deviatie, ontvangt je direct een pushmelding op je mobiele apparaat, mits de optie notificatie is ingeschakeld. Daarnaast wordt er ook een alert afgespeeld als je de optie alert hebt geactiveerd. Het triggerniveau van trigLv en de deviatie worden gemarkeerd met horizontale lijnen die je kunt personaliseren qua stijl, kleur en dikte in de indicatorinstellingen. Dit maakt het mogelijk om meerdere versies van de indicator met verschillende niveaus aan je grafiek toe te voegen en signalen te ontvangen op basis van hun kruising.

Belangrijk om te weten is dat het aangegeven trigLv niveau slechts één keer per kaar werkt. Heractivering is pas mogelijk na de opening van de volgende kaar. Op deze manier voorkom je dat je te vaak triggers ontvangt bij elke tick.

Level Indicator

//+------------------------------------------------------------------+//|                                              Level Indicator.mq5 |//|                                       Copyright 2022, © Cyberdev |//|                                              https://www.mql5.com/en/users/cyberdev/seller |//+------------------------------------------------------------------+#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; // gebruik alertinputbool notification = true; // gebruik push notificatiesinputdouble trigLv = 0.0; // activeringsniveauinputint deviation = 30; // afwijking van trigLv in punteninputint lineWidth = 1; // lijnbreedteinputENUM_LINE_STYLE lineStyle = STYLE_SOLID; // lijnstijlinputcolor lineColor = clrMediumSpringGreen; // lijnkleurinputcolor inactivityColor = clrLightGray; // inactiviteitskleur

CChartObjectHLine lv, dvH, dvL; 

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

//+------------------------------------------------------------------+//| Custom indicator initialisatie functie                         |//+------------------------------------------------------------------+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("Level Indicator. Niveau ", lv.Price(0), " is inactief!");
  if (trigLv == 0.0)
    Alert("Level Indicator. Stel parameter \"trigLv\" in op de gewenste waarde!");
  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("Level Indicator. Niveau ", NormalizeDouble(lv.Price(0), (int)SymbolInfoInteger(NULL, SYMBOL_DIGITS)), " geactiveerd!");
      if (notification)
        SendNotification("Level Indicator. Niveau " + (string)NormalizeDouble(lv.Price(0), (int)SymbolInfoInteger(NULL, SYMBOL_DIGITS)) + " geactiveerd!");
    }
    triggered = true;
  }
  else
    triggered = false;
  
  return rates_total;
}

//+------------------------------------------------------------------+
    Lijst
    Reactie 0