//+----------------------------------------------------------------------+ //| MTF_Fractals_with_Alerts.mq4 | //| | //| Modified by Bluto of Forex Autotrader's World (FXAW) on 05/03/2010 | //| to add alerts and perform general code cleanup. | //+----------------------------------------------------------------------+ #property copyright "" #property link "http://www.forex-tsd.com" #property indicator_chart_window #property indicator_buffers 2 #property indicator_color1 Red #property indicator_color2 Blue //---- input parameters /************************************************************************* PERIOD_M1 1 PERIOD_M5 5 PERIOD_M15 15 PERIOD_M30 30 PERIOD_H1 60 PERIOD_H4 240 PERIOD_D1 1440 PERIOD_W1 10080 PERIOD_MN1 43200 You must use the numeric value of the timeframe that you want to use when you set the TimeFrame' value with the indicator inputs. --------------------------------------- **************************************************************************/ extern int TimeFrame=0; extern bool Enable_Popup_Alerts = true; extern bool Enable_Sound = true; extern bool Enable_Email_Alerts = false; double ExtMapBuffer1[]; double ExtMapBuffer2[]; datetime Prior_Time; datetime last_hi_fractal, last_lo_fractal; //+------------------------------------------------------------------+ //| Custom indicator initialization function | //+------------------------------------------------------------------+ int init() { //---- indicator line SetIndexBuffer(0,ExtMapBuffer1); SetIndexStyle(0,DRAW_ARROW); SetIndexArrow(0,119); SetIndexBuffer(1,ExtMapBuffer2); SetIndexStyle(1,DRAW_ARROW); SetIndexArrow(1,119); //---- name for DataWindow and indicator subwindow label switch(TimeFrame) { case 1 : string TimeFrameStr="Period_M1"; break; case 5 : TimeFrameStr="Period_M5"; break; case 15 : TimeFrameStr="Period_M15"; break; case 30 : TimeFrameStr="Period_M30"; break; case 60 : TimeFrameStr="Period_H1"; break; case 240 : TimeFrameStr="Period_H4"; break; case 1440 : TimeFrameStr="Period_D1"; break; case 10080 : TimeFrameStr="Period_W1"; break; case 43200 : TimeFrameStr="Period_MN1"; break; default : TimeFrameStr="Current Timeframe"; } IndicatorShortName("Fractals "+TimeFrameStr); if (TimeFrame == 0) {TimeFrame = Period();} return(0); } //---- //+------------------------------------------------------------------+ //| MTF Fractals | //+------------------------------------------------------------------+ int start() { if (iTime(Symbol(),TimeFrame,1) == Prior_Time) {return;} // Going Green...Bluto sez only execute mainline once per TF cycle Prior_Time = iTime(Symbol(),TimeFrame,1); datetime TimeArray[]; int i,shift,limit,y=0,counted_bars=IndicatorCounted(); // Plot defined timeframe on to current timeframe ArrayCopySeries(TimeArray,MODE_TIME,Symbol(),TimeFrame); limit=Bars-counted_bars+TimeFrame/Period(); for(i=0,y=0;i 0 && ExtMapBuffer1[1] != EMPTY_VALUE && iTime(Symbol(),TimeFrame,1) > last_hi_fractal) { is_fractal = true; fractal_val = ExtMapBuffer1[1]; last_hi_fractal = iTime(Symbol(),TimeFrame,1); } else if (ExtMapBuffer1[2] > 0 && ExtMapBuffer1[2] != EMPTY_VALUE && iTime(Symbol(),TimeFrame,2) > last_hi_fractal) { is_fractal = true; fractal_val = ExtMapBuffer1[2]; last_hi_fractal = iTime(Symbol(),TimeFrame,2); } else if (ExtMapBuffer1[3] > 0 && ExtMapBuffer1[3] != EMPTY_VALUE && iTime(Symbol(),TimeFrame,3) > last_hi_fractal) { is_fractal = true; fractal_val = ExtMapBuffer1[3]; last_hi_fractal = iTime(Symbol(),TimeFrame,3); } if (is_fractal == true) { alert_msg = "A Fractal High of " + DoubleToStr(fractal_val,Digits) + " has occured on timeframe " + tf2txt(TimeFrame) + " for price bar closing @ " + TimeToStr(last_hi_fractal,TIME_DATE) + " " + TimeHour(last_hi_fractal) + ":" + TimeMinute(last_hi_fractal); } if (is_fractal == false) { if (ExtMapBuffer2[1] > 0 && ExtMapBuffer2[1] != EMPTY_VALUE && iTime(Symbol(),TimeFrame,1) > last_lo_fractal) { is_fractal = true; fractal_val = ExtMapBuffer2[1]; last_lo_fractal = iTime(Symbol(),TimeFrame,1); } else if (ExtMapBuffer2[2] > 0 && ExtMapBuffer2[2] != EMPTY_VALUE && iTime(Symbol(),TimeFrame,2) > last_lo_fractal) { is_fractal = true; fractal_val = ExtMapBuffer2[2]; last_lo_fractal = iTime(Symbol(),TimeFrame,2); } else if (ExtMapBuffer2[3] > 0 && ExtMapBuffer2[3] != EMPTY_VALUE && iTime(Symbol(),TimeFrame,3) > last_lo_fractal) { is_fractal = true; fractal_val = ExtMapBuffer2[3]; last_lo_fractal = iTime(Symbol(),TimeFrame,3); } if (is_fractal == true) { alert_msg = "A Fractal Low of " + DoubleToStr(fractal_val,Digits) + " has occured on timeframe " + tf2txt(TimeFrame) + " for price bar closing @ " + TimeToStr(last_lo_fractal,TIME_DATE) + " " + TimeHour(last_lo_fractal) + ":" + TimeMinute(last_lo_fractal); } } if (is_fractal == true) { if (Enable_Popup_Alerts == true) { Alert(Symbol()+": "+ alert_msg); if (Enable_Sound == true) { PlaySound("alert2.wav"); } } if (Enable_Email_Alerts == true) { SendMail("Fractal Signal Alert",Symbol()+": "+ alert_msg); } } return(0); } string tf2txt(int tf) { if (tf == PERIOD_M1) return("M1"); if (tf == PERIOD_M5) return("M5"); if (tf == PERIOD_M15) return("M15"); if (tf == PERIOD_M30) return("M30"); if (tf == PERIOD_H1) return("H1"); if (tf == PERIOD_H4) return("H4"); if (tf == PERIOD_D1) return("D1"); if (tf == PERIOD_W1) return("W1"); if (tf == PERIOD_MN1) return("MN1"); return("??"); }