how to send email?

 

I have the following indicator code. It shows an arrow on the screen when a certain condition exists.

I want to have it send an email when the condition exists AFTER I attach it to the chart.  The problem is that it currently tries to send emails for each occurrence when I attach it.

Can anyone help please ?

Price Bar number 1 is an Inside Bar
Price Bar number 2 is an Inside Bar in relation to Price Bars 3 & 4
The high of Bar 2 is below the high of Bar 3
The low of Bar 2 is above the low of Bar 4


*/   

#property indicator_chart_window
#property indicator_buffers 1
#property indicator_color1 Yellow

double CrossUp[];


int init()
  {
   SetIndexStyle(0, DRAW_ARROW, EMPTY);
   SetIndexArrow(0, 233);
   SetIndexBuffer(0, CrossUp);
   return(0);
  }


int deinit()
  {
   return(0);
  }


int start() {
   int limit, i, counter;
   double Range, AvgRange;
   int counted_bars=IndicatorCounted();

   //---- check for possible errors
   if(counted_bars<0) return(-1);

   //---- last counted bar will be recounted
   if(counted_bars>0) counted_bars--;

   limit=Bars-counted_bars;

   for(i = 0; i < limit; i++)
   {
      counter=i;
      Range=0;
      AvgRange=0;
      for (counter=i ;counter<=i+9;counter++)
      {
         AvgRange=AvgRange+MathAbs(High[counter]-Low[counter]);
      }
      Range=AvgRange/10;
      
           //bar 1 is an inside bar
           if (High[i+1] < High[i+2] && Low[i+1] > Low[i+2])
           {
                   //bar 2 is inside relative to bars 3 & 4
                        //high of bar 2 is below that of bar 3 && low of bar 2 is above low of bar 4
                        if (High[i+2] < High[i+3] && Low[i+2] > Low[i+4])
         {
            CrossUp[i+1] = Low[i+1] - Range*0.5;
            SendMail("Inside Bar "+Symbol()+":"+Period()+"min","");   // <----------------------------------------------------------------------------------*****
         }
                        // OR high of bar 2 is below that of bar 4 && low of bar 2 is above low of bar 3
                        if (High[i+2] < High[i+4] && Low[i+2] > Low[i+3])
         {
            CrossUp[i+1] = Low[i+1] - Range*0.5;
            SendMail("Inside Bar "+Symbol()+":"+Period()+"min","");  //  <----------------------------------------------------------------------------------*****
         }
           }
   }
   return(0);
}
 
No one knows how to accomplish this?  or is it so simple that I'm just missing it?
 
   static datetime alert_bar_time=0;
   //
   //
   if(i==0 && Condition && alert_bar_time!=Time[0])
      {
      alert_bar_time=Time[0];
      Alert("...");
      }

 

 

Use variable names that describe what they are.

Calling your buffer "CrossUp" makes no sense when you are checking for an inside bar 

 

      for (counter=i ;counter<=i+9;counter++)
      {
         AvgRange=AvgRange+MathAbs(High[counter]-Low[counter]);
      }
      Range=AvgRange/10;

 Here you call the sum of the range "AvgRange" and call the average "Range".

It may not matter for simple code, but can be confusing when it gets more complicated.