//+------------------------------------------------------------------+ //| Moving Average Cross Alert.mq4 | //| Copyright © 2010, Jeremy Whittaker | //| http://www.JeremyWhittaker.com | //+------------------------------------------------------------------+ #property copyright "Copyright © 2010, Jeremy Whittaker" #property link "http://www.JeremyWhittaker.com" #property indicator_chart_window #property indicator_buffers 4 #property indicator_color1 Red #property indicator_color2 Aqua #property indicator_color3 Red #property indicator_color4 Aqua //---- External Variables extern int Period1 = 20; extern int Period2 = 100; extern bool Email = True; //---- Indicators int nShift, digit, digits; int i,j,limit,counted_bars; //---- Buffers double ExtMapBuffer1[]; double ExtMapBuffer2[]; double ExtMapBuffer3[]; double ExtMapBuffer4[]; //+------------------------------------------------------------------+ //| Custom indicator initialization function | //+------------------------------------------------------------------+ int init() { //---- Draw Lines SetIndexStyle(0,DRAW_LINE); SetIndexBuffer(0,ExtMapBuffer1); SetIndexStyle(1,DRAW_LINE); SetIndexBuffer(1,ExtMapBuffer2); //---- Draw Arrows SetIndexStyle(2, DRAW_ARROW, 0, 1); // Fleche vers le haut SetIndexArrow(2, 233); SetIndexBuffer(2, ExtMapBuffer3); SetIndexStyle(3, DRAW_ARROW, 0, 1); // Fleche vers le bas SetIndexArrow(3, 234); SetIndexBuffer(3, ExtMapBuffer4); //---- watermark(); //---- return(0); } //+------------------------------------------------------------------+ //| Custom indicator deinitialization function | //+------------------------------------------------------------------+ int deinit() { //---- //---- return(0); } //+------------------------------------------------------------------+ //| Custom indicator iteration function | //+------------------------------------------------------------------+ int start() { double Ma1,Ma2, Ma1Previous, Ma2Previous; counted_bars=IndicatorCounted(); //---- if(counted_bars<0) return(-1); if(counted_bars>0) counted_bars--; limit=Bars-counted_bars; for(i=0; iMa2 && Ma1PreviousMa2Previous) { if(NewBar()==true) { ExtMapBuffer4[0] = High[0] + iATR(Symbol(),0,10,0)*0.25; Alert("Short Trade setup coming ",Period1, " has just crossed below ",Period2,". The current Price ",Close[1]," for ", Symbol(),"-",Period()); PlaySound("alert.wav"); if (Email) { SendMail("Short Trade setup confirmed", "Trade setup confirmed "+DoubleToStr(Ma1, digits)+" has just crossed below "+DoubleToStr(Ma2, digits)+" for "+Symbol()+"-"+Period()); } } } //---- return(0); } //+------------------------------------------------------------------+ void watermark() { ObjectCreate("JeremyWhittaker", OBJ_LABEL, 0, 0, 0); ObjectSetText("JeremyWhittaker", "JeremyWhittaker.com", 8, "Arial", RoyalBlue); ObjectSet("JeremyWhittaker", OBJPROP_CORNER, 2); ObjectSet("JeremyWhittaker", OBJPROP_XDISTANCE, 5); ObjectSet("JeremyWhittaker", OBJPROP_YDISTANCE, 10); return(0); } bool NewBar() { static datetime lastbar; datetime curbar = Time[0]; if(lastbar!=curbar) { lastbar=curbar; return (true); } else { return(false); } }