//compile// //+------------------------------------------------------------------+ //| EMA_58_Crossover_Alert.mq4 | //| Copyright © 2006, Robert Hill | //| | //| Written Robert Hill for use with AIME for the EMA 5/8 cross to | //| draw arrows and popup alert or send email | //+------------------------------------------------------------------+ #property copyright "Copyright © 2006, Robert Hill" #property indicator_chart_window #property indicator_buffers 4 #property indicator_color1 LawnGreen #property indicator_color2 Red #property indicator_color3 Aqua #property indicator_color4 Red #property indicator_width1 2 #property indicator_width2 2 #property indicator_width3 2 #property indicator_width4 2 extern int LSMA_FastPeriod = 7; extern int LSMA_SlowPeriod = 16; extern bool SoundON=true; extern bool EmailON=false; double CrossUp[]; double CrossDown[]; double lsma7[]; double lsma16[]; int flagval1 = 0; int flagval2 = 0; double myPoint; //+------------------------------------------------------------------+ //| Custom indicator initialization function | //+------------------------------------------------------------------+ int init() { //---- indicators SetIndexStyle(0, DRAW_ARROW, EMPTY); SetIndexArrow(0, 233); SetIndexBuffer(0, CrossUp); SetIndexStyle(1, DRAW_ARROW, EMPTY); SetIndexArrow(1, 234); SetIndexBuffer(1, CrossDown); SetIndexStyle(2, DRAW_LINE, STYLE_SOLID); SetIndexBuffer(2, lsma7); SetIndexStyle(3, DRAW_LINE, STYLE_SOLID); SetIndexBuffer(3, lsma16); myPoint = SetPoint(); //---- return(0); } //+------------------------------------------------------------------+ //| Custom indicator deinitialization function | //+------------------------------------------------------------------+ int deinit() { //---- //---- return(0); } double iLsma(int LSMAPeriod,int shift) { double wt; double ma1=iMA(NULL,0,LSMAPeriod,0,MODE_SMA ,PRICE_CLOSE,shift); double ma2=iMA(NULL,0,LSMAPeriod,0,MODE_LWMA,PRICE_CLOSE,shift); wt = MathFloor((3.0*ma2-2.0*ma1)/myPoint)*myPoint; return(wt); } double SetPoint() { double mPoint; if (Digits < 4) mPoint = 0.01; else mPoint = 0.0001; return(mPoint); } //+------------------------------------------------------------------+ //| Custom indicator iteration function | //+------------------------------------------------------------------+ int start() { int limit, i, counter; double tmp=0; double fastMAnow, slowMAnow, fastMAprevious, slowMAprevious; 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 = 1; 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; fastMAnow = iLsma(LSMA_FastPeriod, i); fastMAprevious = iLsma(LSMA_FastPeriod, i+1); slowMAnow = iLsma(LSMA_SlowPeriod, i); slowMAprevious = iLsma(LSMA_SlowPeriod, i + 1); lsma7[i] = fastMAnow; lsma16[i] = slowMAnow; CrossUp[i] = 0; CrossDown[i] = 0; if ((fastMAnow > slowMAnow) && (fastMAprevious < slowMAprevious)) { if (i == 1 && flagval1==0) { flagval1=1; flagval2=0; if (SoundON) Alert("BUY signal at Ask=",Ask,"\n Bid=",Bid,"\n Time=",TimeToStr(CurTime(),TIME_DATE)," ",TimeHour(CurTime()),":",TimeMinute(CurTime()),"\n Symbol=",Symbol()," Period=",Period()); if (EmailON) SendMail("BUY signal alert","BUY signal at Ask="+DoubleToStr(Ask,4)+", Bid="+DoubleToStr(Bid,4)+", Date="+TimeToStr(CurTime(),TIME_DATE)+" "+TimeHour(CurTime())+":"+TimeMinute(CurTime())+" Symbol="+Symbol()+" Period="+Period()); } CrossUp[i] = Low[i] - Range*0.75; } else if ((fastMAnow < slowMAnow) && (fastMAprevious > slowMAprevious)) { if (i == 1 && flagval2==0) { flagval2=1; flagval1=0; if (SoundON) Alert("SELL signal at Ask=",Ask,"\n Bid=",Bid,"\n Date=",TimeToStr(CurTime(),TIME_DATE)," ",TimeHour(CurTime()),":",TimeMinute(CurTime()),"\n Symbol=",Symbol()," Period=",Period()); if (EmailON) SendMail("SELL signal alert","SELL signal at Ask="+DoubleToStr(Ask,4)+", Bid="+DoubleToStr(Bid,4)+", Date="+TimeToStr(CurTime(),TIME_DATE)+" "+TimeHour(CurTime())+":"+TimeMinute(CurTime())+" Symbol="+Symbol()+" Period="+Period()); } CrossDown[i] = High[i] + Range*0.75; } } return(0); }