//+------------------------------------------------------------------+
//|                                        iB_nn_Email_And_Alert.mq4 |
//|                      Copyright © 2008, MetaQuotes Software Corp. |
//|                                                                  |
//+------------------------------------------------------------------+
#property copyright "Copyright © 2008, MetaQuotes Software Corp."
#property link      ""

#property indicator_chart_window
extern bool email_enabled = true;
extern bool alert_enabled = true;

bool emailsent,alertsent;
//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int init()
  {
//---- indicators
//----
   return(0);
  }
//+------------------------------------------------------------------+
//| Custom indicator deinitialization function                       |
//+------------------------------------------------------------------+
int deinit()
  {
//----
   
//----
   return(0);
  }
//+------------------------------------------------------------------+
//| Custom indicator iteration function                              |
//+------------------------------------------------------------------+
int start()
  {
   int    counted_bars=IndicatorCounted();
//----
   double ibvalue1 = iCustom(NULL,0,"iB_nn",0,1);
   double ibvalue2 = iCustom(NULL,0,"iB_nn",1,1);
   if(ibvalue1!=0.0 && alert_enabled && !alertsent)
      {
      Alert(Symbol() + " Inside Bar Has Been Detected");
      alertsent=true;
      }
   if(ibvalue1!=0.0 && email_enabled && !emailsent)
      {
      SendMail(Symbol() + " Inside Bar Detected","There has been an inside bar detected");
      emailsent=true;
      }
   if(ibvalue1==0.0)
      {
      alertsent=false;
      emailsent=false;
      }   
    
//----
   return(0);
  }
//+------------------------------------------------------------------+