Als je de trigLv niveau instelt in de configuratie, ontvang je een pushmelding op je mobiele apparaat zodra dit niveau wordt overschreden binnen de deviatie. Dit gebeurt alleen als de invoerparameter notification is ingeschakeld. Daarnaast wordt er een alert afgespeeld als de invoerparameter alert is geactiveerd. De triggerlevels van trigLv en de deviatie worden gemarkeerd met horizontale lijnen, waarvan je de stijl, kleur en dikte kunt aanpassen in de instellingen van de indicator. Dit stelt je in staat om meerdere kopieën van de indicator met verschillende niveaus op je grafiek te plaatsen en zo signalen te ontvangen bij hun kruising.
Het opgegeven trigLv niveau wordt slechts één keer geactiveerd per kaar. Heractivatie kan pas plaatsvinden na de opening van de volgende kaar. Hierdoor voorkom je te frequente triggers bij iedere tick.

//+------------------------------------------------------------------+ //| LevelIndicator.mq4 | //| 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 strict #property indicator_chart_window #property indicator_plots 0 #include <ChartObjects\ChartObjectsLines.mqh> input bool alert = true; // gebruik alert input bool notification = true; // gebruik push notificaties input double trigLv = 0.0; // activeringsniveau input int deviation = 30; // afwijking van trigLv in punten input int lineWidth = 1; // lijnbreedte input ENUM_LINE_STYLE lineStyle = STYLE_SOLID; // lijnstijl input color lineColor = clrMediumSpringGreen; // lijnkleur input color inactivityColor = clrLightGray; // inactiviteitskleur CChartObjectHLine lv, dvH, dvL; bool equal(double _v1, double _v2, double _epsilon) { return fabs(_v1 - _v2) <= fabs(_epsilon); } //+------------------------------------------------------------------+ //| Custom indicator initialisatiefunctie | //+------------------------------------------------------------------+ 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("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); } void OnDeinit(const int reason) { //lv.Delete(); //dvH.Delete(); //dvL.Delete(); } //+------------------------------------------------------------------+ //| Custom indicator iteratiefunctie | //+------------------------------------------------------------------+ 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[0], deviation * SymbolInfoDouble(NULL, SYMBOL_POINT))) { if (time_ != time[0]) time_ = time[0]; 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); } //+------------------------------------------------------------------+
Reactie 0