#property indicator_chart_window
#property indicator_buffers 2
#property indicator_color1 Lime
#property indicator_color2 Red
#property indicator_width1 1
#property indicator_width2 1

extern int FasterMode = 1;
extern int FasterMA = 3;
extern int SlowerMode = 1;
extern int SlowerMA = 5;

extern string _Alerts_;
extern bool _Signal_ = true;
extern bool _SignalMail_ = false;
extern int _SignalBar_ = 1;
bool SoundBuy = false;
bool SoundSell = false;

double CrossUp[];
double CrossDown[];

int init()
{
SetIndexBuffer(0,CrossUp);
SetIndexBuffer(1,CrossDown);
SetIndexStyle(0,DRAW_ARROW);
SetIndexStyle(1,DRAW_ARROW);
SetIndexArrow(0,233);
SetIndexArrow(1,234);
return(0);
}

int start()
{
int limit, i, counter;
double fasterMAnow, slowerMAnow, fasterMAprevious, slowerMAprevious, 
fasterMAafter, slowerMAafter;
double Range, AvgRange;
int counted_bars=IndicatorCounted();

if(counted_bars<0) return(-1);

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;

fasterMAnow = iMA(NULL,0,FasterMA,0,FasterMode,PRICE_CLOSE, i);
fasterMAprevious = iMA(NULL,0,FasterMA,0,FasterMode,PRICE_CLOSE, i+1);
fasterMAafter = iMA(NULL,0,FasterMA,0,FasterMode,PRICE_CLOSE,i-1);

slowerMAnow = iMA(NULL,0,SlowerMA,0,SlowerMode,PRICE_CLOSE,i);
slowerMAprevious = iMA(NULL,0,SlowerMA,0,SlowerMode,PRICE_CLOSE,i+1);
slowerMAafter = iMA(NULL,0,SlowerMA,0,SlowerMode,PRICE_CLOSE,i-1);

if ( (fasterMAnow > slowerMAnow) && (fasterMAprevious < 
slowerMAprevious) && (fasterMAafter > slowerMAafter)) {
CrossUp[i] = Low[i] - Range*0.5;
}
else
if ((fasterMAnow < slowerMAnow) && (fasterMAprevious > 
slowerMAprevious) && (fasterMAafter < slowerMAafter)) {
CrossDown[i] = High[i] + Range*0.5;
}
}
//
string message1 = StringConcatenate(WindowExpertName() +" ","-"," ","BUY"," ","-"," ",Symbol()," ","-"," ",Period()," ","-"," ",TimeToStr(TimeLocal(),TIME_DATE|TIME_MINUTES|TIME_SECONDS)," ","-"," ",DoubleToStr(Ask,4));
string message2 = StringConcatenate(WindowExpertName() +" ","-"," ","SELL"," ","-"," ",Symbol()," ","-"," ",Period()," ","-"," ",TimeToStr(TimeLocal(),TIME_DATE|TIME_MINUTES|TIME_SECONDS)," ","-"," ",DoubleToStr(Ask,4));
//
if (CrossUp[_SignalBar_] != EMPTY_VALUE && CrossUp[_SignalBar_] != 0 && SoundBuy)
{
SoundBuy = False;
if(_Signal_)
{
Alert(message1);
if (_SignalMail_) SendMail(Symbol(),message1);
}
}
if (!SoundBuy && (CrossUp[_SignalBar_] == EMPTY_VALUE || CrossUp[_SignalBar_] == 0)) SoundBuy = True;
//
if (CrossDown[_SignalBar_] != EMPTY_VALUE && CrossDown[_SignalBar_] != 0 && SoundSell)
{
SoundSell = False;
if(_Signal_)
{
Alert(message2);
if (_SignalMail_) SendMail(Symbol(),message2);
}
}
if (!SoundSell && (CrossDown[_SignalBar_] == EMPTY_VALUE || CrossDown[_SignalBar_] == 0)) SoundSell = True;
//
   return(0);
}       