Watch how to download trading robots for free
Find us on Twitter!
Join our fan page
Interesting script?
So post a link to it -
let others appraise it
You liked the script? Try it in the MetaTrader 5 terminal
Indicators

Level Indicator - indicator for MetaTrader 5

Views:
8652
Rating:
(29)
Published:
2022.01.20 13:55
Updated:
2022.01.20 18:47
Need a robot or indicator based on this code? Order it on Freelance Go to Freelance

When the trigLv level specified in the settings is crossed within the deviation, the indicator sends a push notification to the mobile device if the input parameter notification is enabled, and also plays an alert if the input parameter alert  is enabled. The trigger level of trigLv, as well as the deviation limits, are highlighted with horizontal lines, the style, color and thickness of which can also be set in the indicator settings. This design allows you to add several copies of the indicator with different levels to the chart and receive signals as a result of their intersection.

The given trigLv level works only once on one bar. Re-actuation is possible only after the opening of the next bar. Thus, it was possible to eliminate too frequent triggers on each 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_plots 0

#include <ChartObjects\ChartObjectsLines.mqh>

input bool alert = true; // use alert
input bool notification = true; // use push notifications
input double trigLv = 0.0; // actuation level
input int deviation = 30; // deviation from trigLv in points
input int lineWidth = 1; // line width
input ENUM_LINE_STYLE lineStyle = STYLE_SOLID; // line style
input color lineColor = clrMediumSpringGreen; // line color
input color inactivityColor = clrLightGray; // inactivity color

CChartObjectHLine lv, dvH, dvL; 

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

//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
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. Level ", lv.Price(0), " is inactive!");
  if (trigLv == 0.0)
    Alert("Level Indicator. Set parameter \"trigLv\" to the desired value!");
  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("Level Indicator. Level ", NormalizeDouble(lv.Price(0), (int)SymbolInfoInteger(NULL, SYMBOL_DIGITS)), " triggered!");
      if (notification)
        SendNotification("Level Indicator. Level " + (string)NormalizeDouble(lv.Price(0), (int)SymbolInfoInteger(NULL, SYMBOL_DIGITS)) + " triggered!");
    }
    triggered = true;
  }
  else
    triggered = false;
  
  return rates_total;
}

//+------------------------------------------------------------------+
    Hotkeys_CycleTimeFrames_v1.0 Hotkeys_CycleTimeFrames_v1.0

    cycle timeframes using hotkeys 'N','M' prev,next timeframe

    Elegant oscillator Elegant oscillator

    Elegant oscillator

    The Laguerre Filter Indicator The Laguerre Filter Indicator

    The Laguerre Filter was created by John Ehlers ("Cybernetic Analysis For Stocks And Futures", pg 216)

    Support Resistance Line Alert Support Resistance Line Alert

    Add Popup or Push Alert notification on manually placed horizontal lines, The lines are deleted and reset itself as soon as price touches these lines