//+------------------------------------------------------------------+ //| Bands.mq4 | //| // // Copyright © 2005, MetaQuotes Software Corp. | //| http://www.metaquotes.net/ | //+------------------------------------------------------------------+ #property copyright "Copyright © 2005, MetaQuotes Software Corp." #property link "http://www.metaquotes.net/" //+------------------------------------------------------------------+ //| | //| 2008 Speech. Speech.tpl Rev.2a 2008 ( itemsdepot@hotmail.com)| //| | //+------------------------------------------------------------------+ #property indicator_chart_window #property indicator_buffers 3 #property indicator_color1 Gray #property indicator_color2 OliveDrab #property indicator_color3 Brown #property indicator_width1 1 #property indicator_width2 3 #property indicator_width3 3 //// //---- indicator parameters extern bool BBDrawBands=True; extern int BandsDrawRange=100; extern int BandsShift=0; extern double BandsDeviations=2.0; extern bool BandsAlertBoxOn=False; extern bool BandSoundAlertHighOn=True; extern bool BandSoundAlertLowOn=True; extern string WaveBandName="bandup.wav"; extern string WaveBandName2="banddown.wav"; extern double BBAlarmDelay=22; extern int BBCandleAlertRange=2; extern int BandsMAPeriod=7; extern int BBMovingAverage=0; extern string BBMovingAverageSettings="0-SMA,1-EMA,2-SMMA,3-LWMA"; // simple, exponential, smoothed , linear extern int BBAppliedPrice=0; extern string BBAppliedPriceSettings1="0-Close,1-Open,2-High,3-Low"; extern string BBAppliedPriceSettings2="4-Median,5-Typical,6-Weighted"; extern double BBTime; //----------------- buffers double MovingBuffer[]; double UpperBuffer[]; double LowerBuffer[]; double BBBreachLog[]; //+------------------------------------------------------------------+ //| Custom indicator initialization function | //+------------------------------------------------------------------+ int init() { //---- indicators ------------------------------------------------ IndicatorShortName("Bands R2"); if (BBDrawBands) SetIndexStyle(0,0,0,indicator_width1,indicator_color1); else SetIndexStyle(0,12,0,indicator_width1,indicator_color1); SetIndexBuffer(0,MovingBuffer); SetIndexDrawBegin(0,BandsDrawRange); if (BBDrawBands) SetIndexStyle(1,0,0,indicator_width2,indicator_color2); else SetIndexStyle(1,12,0,indicator_width2,indicator_color2); SetIndexBuffer(1,UpperBuffer); SetIndexDrawBegin(1,BandsDrawRange); if (BBDrawBands) SetIndexStyle(2,0,0,indicator_width3,indicator_color3); else SetIndexStyle(2,12,0,indicator_width3,indicator_color3); SetIndexBuffer(2,LowerBuffer); SetIndexDrawBegin(2,BandsDrawRange); BBTime=TimeLocal(); return(0); } //+------------------------------------------------------------------+ //| Bollinger Bands | //+------------------------------------------------------------------+ int start() { int i,k; bool BBSpeak=False; double deviation; double sum,oldval,newres; double BBFinishTime=TimeCurrent(); //---- if(Bars<=BandsDrawRange) return(0); //------------------------------------------------------------ Draw for(i=BandsDrawRange; i>=0; i--) { if (BBMovingAverage>3 && BBMovingAverage<0) BBMovingAverage=0; if (BBAppliedPrice>6 && BBAppliedPrice<6 ) BBAppliedPrice=0; MovingBuffer[i]=iMA(NULL,0,BandsMAPeriod,BandsShift,BBMovingAverage,BBAppliedPrice,i); //--------------------- sum=0.0; k=i+BandsMAPeriod-1; oldval=MovingBuffer[i]; while(k>=i) { newres=Close[k]-oldval; sum+=newres*newres; k--; } deviation=BandsDeviations*MathSqrt(sum/BandsMAPeriod); if (oldval>0) UpperBuffer[i]=oldval+deviation; if (oldval>0) LowerBuffer[i]=oldval-deviation; } // ----------------------------------------- End Draw //-------------------------------------------- Start Speak BBSpeak=False; BBFinishTime=TimeLocal(); if ((BBFinishTime - BBTime) >= BBAlarmDelay ) // && pos==0) { BBFinishTime=TimeLocal(); BBTime=TimeLocal(); BBSpeak=True; } while (BBSpeak==True) { for(i=0; i<=BBCandleAlertRange; i++) { //-------------------------- if (High[i] > UpperBuffer[i]) { if (BandsAlertBoxOn==True) Alert("Bands R2: Candle:"+i+" High Band Cross: "+High[i]); if (BandSoundAlertHighOn==True) PlaySound(WaveBandName); BBSpeak=False; } if (Low[i] < LowerBuffer[i]) { if (BandsAlertBoxOn==True) Alert("Bands R2: Candle:"+i+" Low Band Cross: "+Low[i]); if (BandSoundAlertLowOn==True) PlaySound(WaveBandName2); BBSpeak=False; } if (i >= BBCandleAlertRange) BBSpeak=False; } } //--------------------------------------------- End Speak return(0); } //+------------------------------------------------- End initStart()