//+------------------------------------------------------------------+ //| MyBOLsAlertV32.mq5 (Origin from BB.mq5)| //| Copyright 2009, MetaQuotes Software Corp. | //| SearchSurf-RmDj (The-How)| //+------------------------------------------------------------------+ #property copyright "2009, MetaQuotes Software Corp." #property link "http://www.mql5.com" #property description "Bollinger Bands" #property description "------------------------- 2015 SearchSurf's Version 3.2 (RmDj)" #include //--- #property indicator_chart_window #property indicator_buffers 6 #property indicator_plots 5 #property indicator_type1 DRAW_LINE #property indicator_color1 LightSeaGreen #property indicator_type2 DRAW_LINE #property indicator_color2 LightSeaGreen #property indicator_type3 DRAW_LINE #property indicator_color3 LightSeaGreen #property indicator_type4 DRAW_ARROW #property indicator_color4 Blue #property indicator_type5 DRAW_ARROW #property indicator_color5 Red #property indicator_label1 "Bands middle" #property indicator_label2 "Bands upper" #property indicator_label3 "Bands lower" //--- input parametrs input int InpBandsPeriod=20; // Period input int InpBandsShift=0; // Shift input double InpBandsDeviations=0.5; // Deviation input bool Play_sound=true; // Enable wav play. input bool Emailing=false; // Enable Email Alert. input bool OuterBandArrow=true; // Enable Arrow Indicator input bool BandLineOnly=false; // Arrow on BandLine Only //--- global variables int ExtBandsPeriod,ExtBandsShift; double ExtBandsDeviations; int ExtPlotBegin=0; //---- indicator buffer double ExtMLBuffer[]; double ExtTLBuffer[]; double ExtBLBuffer[]; double ExtUpBuffer[]; double ExtLoBuffer[]; double ExtStdDevBuffer[]; //--- Other Variable; double UpperBOL; double LowerBOL; double MidBOL; string InSeconds; // The string string sec[]; // result ushort usec; // code of seperator long seconds; bool play=1; long delay_sec; double mailcon=true; //mail condition (true = Allow / false = Don't queue); //+------------------------------------------------------------------+ //| Custom indicator initialization function | //+------------------------------------------------------------------+ void OnInit() { //--- check for input values if(InpBandsPeriod<2) { ExtBandsPeriod=20; printf("Incorrect value for input variable InpBandsPeriod=%d. Indicator will use value=%d for calculations.",InpBandsPeriod,ExtBandsPeriod); } else ExtBandsPeriod=InpBandsPeriod; if(InpBandsShift<0) { ExtBandsShift=0; printf("Incorrect value for input variable InpBandsShift=%d. Indicator will use value=%d for calculations.",InpBandsShift,ExtBandsShift); } else ExtBandsShift=InpBandsShift; if(InpBandsDeviations==0.0) { ExtBandsDeviations=2.0; printf("Incorrect value for input variable InpBandsDeviations=%f. Indicator will use value=%f for calculations.",InpBandsDeviations,ExtBandsDeviations); } else ExtBandsDeviations=InpBandsDeviations; //--- define buffers SetIndexBuffer(0,ExtMLBuffer); SetIndexBuffer(1,ExtTLBuffer); SetIndexBuffer(2,ExtBLBuffer); SetIndexBuffer(3,ExtUpBuffer,INDICATOR_DATA); SetIndexBuffer(4,ExtLoBuffer,INDICATOR_DATA); SetIndexBuffer(5,ExtStdDevBuffer,INDICATOR_CALCULATIONS); //--- set index labels PlotIndexSetString(0,PLOT_LABEL,"Bands("+string(ExtBandsPeriod)+") Middle"); PlotIndexSetString(1,PLOT_LABEL,"Bands("+string(ExtBandsPeriod)+") Upper"); PlotIndexSetString(2,PLOT_LABEL,"Bands("+string(ExtBandsPeriod)+") Lower"); //--- indicator name IndicatorSetString(INDICATOR_SHORTNAME,"Bollinger Bands"); //--- indexes draw begin settings ExtPlotBegin=ExtBandsPeriod-1; PlotIndexSetInteger(0,PLOT_DRAW_BEGIN,ExtBandsPeriod); PlotIndexSetInteger(1,PLOT_DRAW_BEGIN,ExtBandsPeriod); PlotIndexSetInteger(2,PLOT_DRAW_BEGIN,ExtBandsPeriod); PlotIndexSetInteger(3,PLOT_ARROW,217); PlotIndexSetInteger(4,PLOT_ARROW,218); //--- indexes shift settings PlotIndexSetInteger(0,PLOT_SHIFT,ExtBandsShift); PlotIndexSetInteger(1,PLOT_SHIFT,ExtBandsShift); PlotIndexSetInteger(2,PLOT_SHIFT,ExtBandsShift); PlotIndexSetInteger(3,PLOT_ARROW_SHIFT,ExtBandsShift); PlotIndexSetInteger(4,PLOT_ARROW_SHIFT,ExtBandsShift); PlotIndexSetDouble(3,PLOT_EMPTY_VALUE,EMPTY_VALUE); PlotIndexSetDouble(4,PLOT_EMPTY_VALUE,EMPTY_VALUE); //--- number of digits of indicator value IndicatorSetInteger(INDICATOR_DIGITS,_Digits+1); //---- OnInit done } //+------------------------------------------------------------------+ //| | //+------------------------------------------------------------------+ void OnDeinit(const int reason) { //--- } //+------------------------------------------------------------------+ //| Custom indicator iteration function | //+------------------------------------------------------------------+ int OnCalculate(const int rates_total, const int prev_calculated, const int begin, const double &price[]) { //--- variables int pos; int i; string Ptrimmed; double the_price; //--- indexes draw begin settings, when we've recieved previous begin if(ExtPlotBegin!=ExtBandsPeriod+begin) { ExtPlotBegin=ExtBandsPeriod+begin; PlotIndexSetInteger(0,PLOT_DRAW_BEGIN,ExtPlotBegin); PlotIndexSetInteger(1,PLOT_DRAW_BEGIN,ExtPlotBegin); PlotIndexSetInteger(2,PLOT_DRAW_BEGIN,ExtPlotBegin); } //--- check for bars count if(rates_total1) pos=prev_calculated-1; else pos=0; //--- This serves the calculated bars candle details. MqlRates crates[]; if(CopyRates(_Symbol,_Period,0,rates_total,crates)<0) { Alert("Unable to get total rates bars --- ",GetLastError()); return(rates_total); } //--- main cycle for(i=pos;iUpperBOL) ExtUpBuffer[i]=UpperBOL; else ExtUpBuffer[i]=0; if(crates[i].high>LowerBOL && crates[i].lowUpperBOL) || (crates[i].low>UpperBOL && crates[i].high>UpperBOL)) ExtUpBuffer[i]=UpperBOL; else ExtUpBuffer[i]=0; if((crates[i].high>LowerBOL && crates[i].lowUpperBOL || mrates[0].closeUpperBOL) { if(Play_sound && play) { PlaySound("UpperBandAlert.wav"); play=false; } if(mailcon && Emailing) { mailcon=false; //--- usec=StringGetCharacter("_",0); StringSplit(EnumToString(_Period),usec,sec); Ptrimmed=sec[1]; //--- if(!SendMail(Ptrimmed+"UpB_"+_Symbol,Ptrimmed+_Symbol+" detected ABOVE Bollinger's Upper Band: "+DoubleToString(the_price,8)+" This is an Alert Message.")) { Alert("Mail queue failed."); return(rates_total); } } } //--- else if(mrates[0].close