one e-mail per direction - please help

 

Hi I am trying to develop a program where I get notified when the price closes above or below the 48SMA.
The code works well by the "SendMail" function sends an e-mail at every tick.
How do I make it so that I get an e-mail in the following way:
When the close of the last bar is aboe the 48SMA I get an e-mail once.
The next e-mail that I get is when the last close is below the SMA48.

In other words, the e-mail messages will alternate between a cross-over and cross-under.

The code that I have so far is listed below.

Thanks

#property indicator_chart_window
#property indicator_buffers 2
#property indicator_color1 Aqua
#property indicator_color2 Orange

extern int MA_Type = MODE_SMA;

extern int Period_MA_1 = 12; //p.203
extern int Period_MA_2 = 24;
extern int Period_MA_3 = 48;

double ma12,
ma24,
ma48;

double Bull[];
double Bear[];

int init()
{
//---- indicators
SetIndexStyle(0, DRAW_ARROW, EMPTY);
SetIndexArrow(0, 225);
SetIndexBuffer(0, Bull);

SetIndexStyle(1, DRAW_ARROW, EMPTY);
SetIndexArrow(1, 226);
SetIndexBuffer(1, Bear);

return(0);
}

int start()
{

int counted_bars = IndicatorCounted();
int i;
int limit;
if(counted_bars < 0)
return(-1);
if(counted_bars > 0)
counted_bars--;
limit = Bars - counted_bars;
for(i=0; i<=limit; i++)
{


ma12 = iMA(Symbol(),0,Period_MA_1,0,MA_Type,Close[i+1],i);
ma24 = iMA(Symbol(),0,Period_MA_2,0,MA_Type,Close[i+1],i);
ma48 = iMA(Symbol(),0,Period_MA_3,0,MA_Type,Close[i+1],i);

if ( Close[i+1] > ma48 )
{
Bull[i] = Low[i] - 0.0005;
SendMail("EUR up", "test");
}

if (Close[i+1] < ma48 )
{
Bear[i] = High[i] + 0.0005;
SendMail("EUR down", "test");
}

}
return(0);
}

 

Hi, try follow, i in office, don't have mt4 to test it now

if ( Close[i+1] > ma48 &&  Close[i+2] < ma48 )
{
Bull[i] = Low[i] - 0.0005;
SendMail("EUR up", "test");
} 

if (Close[i+1] < ma48 &&  Close[i+2] > ma48 )
{
Bear[i] = High[i] + 0.0005;
SendMail("EUR down", "test"); 
}

}
return(0);
}


the && is AND (meaning ), don't have mt4 here, so can't really remember the right code

Thanks,

erekit

http://100k2.blogspot.com/

Reason: