//+------------------------------------------------------------------+
//|                                               CrossingLevel1.mq4 |
//|                                                      Tino Wening |
//|                                                  info@prinova.de |
//+------------------------------------------------------------------+
#property copyright "Tino Wening"
#property link      "info@prinova.de"

#property indicator_chart_window
extern bool UseAlert = true;
extern bool UseEmail = false;
extern int Levels = 7;
datetime dt;
int temp;
int oldtemp;
//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int init()
  {
//---- indicators
   dt = Time[0];
   oldtemp = 0;
//----
   return(0);
  }
//+------------------------------------------------------------------+
//| Custom indicator deinitialization function                       |
//+------------------------------------------------------------------+
int deinit()
  {
//----
   
//----
   return(0);
  }
//+------------------------------------------------------------------+
//| Custom indicator iteration function                              |
//+------------------------------------------------------------------+
int start()
  {
   //if (dt == Time[0]) return(0);
   
  // temp = OrdersTotal();
  // if (oldtemp == temp) return(0);
   //if (OrdersTotal() <= 0) return(0);
   temp = 0;
   for (int i=0;i<OrdersTotal();i++)
   {
      OrderSelect(i, SELECT_BY_POS);
      if (OrderSymbol() == Symbol()) temp++;
   }
   if (oldtemp != temp)
   {
   if (temp == 0 && UseAlert) Alert(Symbol() + " All Orders Closed");
   if (temp == 7 && UseAlert) Alert(Symbol() + " Level 7 Reached");
   if (temp == Levels && UseAlert) Alert(Symbol() + "Level " + Levels + " Reached");
   
   if (temp == 0 && UseEmail) SendMail("Levelalert", Symbol() + "All Orders Closed");
   if (temp == 7 && UseEmail) SendMail("Levelalert", Symbol() + "Level 7 Reached");
   if (temp == Levels && UseEmail) SendMail("Levelalert", Symbol() + "Level " + Levels + " Reached");
   }
   oldtemp = temp;
//----
   return(0);
  }
//+------------------------------------------------------------------+