//+------------------------------------------------------------------+ //| MTF_MA_Cross_Alert_Notif_V3.mq4 | //| Added Send_Notification by transmat | //+------------------------------------------------------------------+ //+------------------------------------------------------------------+ //+------------------------------------------------------------------+ #property copyright "www.forex-tsd.com" #property link "www.forex-tsd.com" #property indicator_chart_window #property indicator_buffers 2 #property indicator_color1 clrRed #property indicator_color2 clrLimeGreen extern string TimeFrame = "current time frame"; extern int FasterMA = 12; extern int FasterShift = 0; extern int FasterMode = MODE_EMA; extern int SlowerMA = 26; extern int SlowerShift = 0; extern int SlowerMode = MODE_EMA; extern int MAPrice = PRICE_CLOSE; extern bool alertsOn = false; extern bool alertsOnCurrent = true; extern bool alertsMessage = true; extern bool alertsSound = false; extern bool alertsEmail = false; extern bool Send_Notification = true; extern string Notif_up = "GBPUSD_Daily_EMA_cross_UP"; extern string Notif_down = "GBPUSD_H1_EMA_cross_DOWN"; double CrossUp[]; double CrossDown[]; double State[]; int timeFrame; string indicatorFileName; bool returnBars; //+------------------------------------------------------------------+ //| | //+------------------------------------------------------------------+ // int init() { IndicatorBuffers(3); SetIndexBuffer(0, CrossUp); SetIndexStyle(0, DRAW_ARROW); SetIndexArrow(0, 233); SetIndexBuffer(1, CrossDown); SetIndexStyle(1, DRAW_ARROW); SetIndexArrow(1, 234); SetIndexBuffer(2, State); indicatorFileName = WindowExpertName(); returnBars = (TimeFrame=="returnBars"); if (returnBars) return(0); timeFrame = stringToTimeFrame(TimeFrame); return(0); } int deinit() { return(0); } int start() { int counted_bars=IndicatorCounted(); int i,limit; if(counted_bars<0) return(-1); if(counted_bars>0) counted_bars--; limit = MathMin(Bars-counted_bars,Bars-1); if (returnBars) { CrossUp[0] = limit+1; return(0); } if (timeFrame!=Period()) limit = MathMax(limit,MathMin(Bars,iCustom(NULL,timeFrame,indicatorFileName,"returnBars",0,0)*timeFrame/Period())); for(i=limit; i>=0; i--) { CrossUp[i] = EMPTY_VALUE; CrossDown[i] = EMPTY_VALUE; State[i] = State[i+1]; int y = iBarShift(NULL,timeFrame,Time[i]); int x = iBarShift(NULL,timeFrame,Time[i+1]); if (x==y) continue; double range = iATR(NULL,0,10,i); double maFast = iMA(NULL,timeFrame,FasterMA,FasterShift,FasterMode,MAPrice,y); double maSlow = iMA(NULL,timeFrame,SlowerMA,SlowerShift,SlowerMode,MAPrice,y); if (maFast>maSlow) State[i] = 1; if (maFast=0; i--) if (tfs==sTfTable[i] || tfs==""+iTfTable[i]) return(MathMax(iTfTable[i],Period())); return(Period()); } string timeFrameToString(int tf) { for (int i=ArraySize(iTfTable)-1; i>=0; i--) if (tf==iTfTable[i]) return(sTfTable[i]); return(""); } string stringUpperCase(string str) { string s = str; for (int length=StringLen(str)-1; length>=0; length--) { int character = StringGetChar(s, length); if((character > 96 && character < 123) || (character > 223 && character < 256)) s = StringSetChar(s, length, character - 32); else if(character > -33 && character < 0) s = StringSetChar(s, length, character + 224); } return(s); } //------------------------------------------------------------------ // //------------------------------------------------------------------ // void doAlert(int forBar, string doWhat) { int i; int y = iBarShift(NULL,timeFrame,Time[i]); double maFast = iMA(NULL,timeFrame,FasterMA,FasterShift,FasterMode,MAPrice,y); double maSlow = iMA(NULL,timeFrame,SlowerMA,SlowerShift,SlowerMode,MAPrice,y); static string previousAlert="nothing"; static datetime previousTime; string message; if (previousAlert != doWhat || previousTime != Time[forBar]) { previousAlert = doWhat; previousTime = Time[forBar]; // message = StringConcatenate(timeFrameToString(timeFrame)," ",Symbol()," at ",TimeToStr(TimeLocal(),TIME_SECONDS)," fast ma crossed slow ma ",doWhat); if (alertsMessage) Alert(message); if (alertsEmail) SendMail(StringConcatenate(Symbol(),"MA line cross"),message); if (alertsSound) PlaySound("alert2.wav"); //if (maFast