//+------------------------------------------------------------------+ //| MultiLevelPriceAlert.mq4 | //| Hiachiever | //| http://www.The4xTrader.com | //+------------------------------------------------------------------+ #property copyright "Hiachiever" #property link "http://www.The4xTrader.com" extern string Note1 = " -- Levels to set Alerts at --"; extern double Upper1Price = 0; extern double Lower1Price = 0; extern double Upper2Price = 0; extern double Lower2Price = 0; extern string Note2 = " -- Options to Turn On/Off Levels --"; extern bool UseUpper1Alert = True; extern bool UseLower1Alert = True; extern bool UseUpper2Alert = False; extern bool UseLower2Alert = False; extern string Note2 = " -- General Options --"; extern bool RayLine = true; extern int LineLength = 15; extern bool AlertOnBarclose = false; extern string Note2 = " -- Colors for each Level --"; extern color Upper1Color = Lime; extern color Lower1Color = Magenta; extern color Upper2Color = LawnGreen; extern color Lower2Color = MediumOrchid; extern color TouchedColor = Red; extern string Note2 = " -- Notes to include in Alerts --"; extern string Upper1Note = "."; extern string Lower1Note = "."; extern string Upper2Note = "."; extern string Lower2Note = "."; extern string Note2 = " -- Alert Options --"; extern bool AlertOnCross = true; extern string soundfile = "alert.wav"; extern bool MsgAlerts= true; extern bool SoundAlerts= true; extern bool eMailAlerts= false; double Upper1bid = 0; double Upper2bid = 0; double Lower1bid = 0; double Lower2bid = 0; int Space1 = 0; int Space2 = 0; bool Upper1Touched = false; bool Upper2Touched = false; bool Lower1Touched = false; bool Lower2Touched = false; #property indicator_chart_window //+------------------------------------------------------------------+ //| Custom indicator initialization function | //+------------------------------------------------------------------+ int init() { ObjectDelete("PriceLine"+Upper1Price); if(UseUpper1Alert == 0) { Upper1Price = Bid + (30 * Point); } ObjectDelete("PriceLine"+Upper2Price); if(UseUpper2Alert == 0) { Upper2Price = Bid + (15 * Point); } ObjectDelete("PriceLine"+Lower2Price); if(UseLower2Alert == 0) { Lower2Price = Bid - (15 * Point); } ObjectDelete("PriceLine"+Lower1Price); if(UseLower1Alert == 0) { Lower1Price = Bid - (30 * Point); } Upper1Touched = false; Upper2Touched = false; Lower1Touched = false; Lower2Touched = false; return(0); } //+------------------------------------------------------------------+ //| Custom indicator deinitialization function | //+------------------------------------------------------------------+ int deinit() { //---- ObjectDelete("PriceLine"+Upper1Price); ObjectDelete("PriceLine"+Upper2Price); ObjectDelete("PriceLine"+Lower1Price); ObjectDelete("PriceLine"+Lower2Price); //---- return(0); } //+------------------------------------------------------------------+ //| Custom indicator iteration function | //+------------------------------------------------------------------+ int start() { string msg; int BarRef; BarRef = 0; if (AlertOnBarclose) BarRef = 1; Print(Space2 + ", " + Space1); //if(price == 0) return(0); if(!Upper1Touched && UseUpper1Alert) drawLine("PriceLine"+Upper1Price,Time[LineLength], Time[0], Upper1Price, Upper1Price, 2,Upper1Color); if(!Upper2Touched && UseUpper2Alert) drawLine("PriceLine"+Upper2Price,Time[LineLength], Time[0], Upper2Price, Upper2Price, 2,Upper2Color); if(!Lower1Touched && UseLower1Alert) drawLine("PriceLine"+Lower1Price,Time[LineLength], Time[0], Lower1Price, Lower1Price, 2,Lower1Color); if(!Lower2Touched && UseLower2Alert) drawLine("PriceLine"+Lower2Price,Time[LineLength], Time[0], Lower2Price, Lower2Price, 2,Lower2Color); if(UseUpper1Alert && Upper1bid !=0 && ((Close[BarRef] >= Upper1Price && Upper1bid < Upper1Price) || (Close[BarRef] <= Upper1Price && Upper1bid > Upper1Price))) { drawLine("PriceLine"+Upper1Price,Time[LineLength], Time[0], Upper1Price, Upper1Price, 2,TouchedColor); if(!Upper1Touched) { msg = "Upper Price 1 Alert @ "+Upper1Price+" for "+Symbol()+" on time frame "+Period(); if (AlertOnCross) DoAlerts(msg + ". NOTE: " + Upper1Note,""); Upper1Touched = true; } } if(UseUpper2Alert && Upper2bid !=0 && ((Close[BarRef] >= Upper2Price && Upper2bid < Upper2Price) || (Close[BarRef] <= Upper2Price && Upper2bid > Upper2Price))) { drawLine("PriceLine"+Upper2Price,Time[LineLength], Time[0], Upper2Price, Upper2Price, 2,TouchedColor); if(!Upper2Touched) { msg = "Upper Price 2 Alert @ "+Upper2Price+" for "+Symbol()+" on time frame "+Period(); if (AlertOnCross) DoAlerts(msg + ". NOTE: " + Upper2Note,""); Upper2Touched = true; } } if(UseLower1Alert && Lower1bid !=0 && ((Close[BarRef] >= Lower1Price && Lower1bid < Lower1Price) || (Close[BarRef] <= Lower1Price && Lower1bid > Lower1Price))) { drawLine("PriceLine"+Lower1Price,Time[LineLength], Time[0], Lower1Price, Lower1Price, 2,TouchedColor); if(!Lower1Touched) { msg = "Lower Price 1 Alert @ "+Lower1Price+" for "+Symbol()+" on time frame "+Period(); if (AlertOnCross) DoAlerts(msg + ". NOTE: " + Lower1Note,""); Lower1Touched = true; } } if(UseLower2Alert && Lower2bid !=0 && ((Close[BarRef] >= Lower2Price && Lower2bid < Lower2Price) || (Close[BarRef] <= Lower2Price && Lower2bid > Lower2Price))) { drawLine("PriceLine"+Lower2Price,Time[LineLength], Time[0], Lower2Price, Lower2Price, 2,TouchedColor); if(!Lower2Touched) { msg = "Lower Price 2 Alert @ "+Lower2Price+" for "+Symbol()+" on time frame "+Period(); if (AlertOnCross) DoAlerts(msg + ". NOTE: " + Lower2Note,""); Lower2Touched = true; } } Upper1bid = Close[BarRef]; Upper2bid = Close[BarRef]; Lower1bid = Close[BarRef]; Lower2bid = Close[BarRef]; return(0); } //+------------------------------------------------------------------+ void drawLine(string name,datetime tfrom, datetime tto, double pfrom, double pto, int width, color Col) { if(ObjectFind(name) != 0) { ObjectCreate(name, OBJ_TREND, 0, tfrom, pfrom,tto,pto); ObjectSet(name, OBJPROP_STYLE, STYLE_SOLID); ObjectSet(name, OBJPROP_COLOR, Col); ObjectSet(name,OBJPROP_WIDTH,width); ObjectSet(name,OBJPROP_RAY,RayLine); } else { ObjectDelete(name); ObjectCreate(name, OBJ_TREND, 0, tfrom, pfrom,tto,pto); ObjectSet(name, OBJPROP_STYLE, STYLE_SOLID); ObjectSet(name, OBJPROP_COLOR, Col); ObjectSet(name,OBJPROP_WIDTH,width); ObjectSet(name,OBJPROP_RAY,RayLine); } } void DoAlerts(string MsgText, string emailsub) { if (MsgAlerts) Alert(MsgText); if (SoundAlerts) PlaySound(soundfile); if (eMailAlerts) SendMail(emailsub, MsgText); }
Sample
Analysis
Market Information Used:
Series array that contains open time of each bar
Series array that contains close prices for each bar
Indicator Curves created:
Indicators Used:
Custom Indicators Used:
Order Management characteristics:
Other Features:
It issuies visual alerts to the screen
It plays sound alerts
It sends emails