Time: 2014-03-09 | Download file:Fiji_BB_Alert.mq4
//+------------------------------------------------------------------+ //| ProjectName | //| Copyright 2012, CompanyName | //| http://www.companyname.net | //+------------------------------------------------------------------+ #property indicator_chart_window #property indicator_buffers 5 #property indicator_color1 White #property indicator_color2 Lime #property indicator_color3 Red #property indicator_color4 White #property indicator_color5 Blue #property indicator_width1 1 #property indicator_width2 2 #property indicator_width3 2 #property indicator_width4 3 #property indicator_width5 3 #property indicator_style1 STYLE_DOT #property indicator_style2 STYLE_SOLID #property indicator_style3 STYLE_SOLID //---- input parameters extern int eintBandsPeriod = 20; extern double edblBandsDev = 2.0; extern int eintMAMode=MODE_SMA; extern int eintMAPrice = PRICE_CLOSE; extern int eintMAShift = 0; extern int eintBarsBack= 1; extern int SIGNAL_BAR=1; //---- indicator buffers double gadblMid[]; double gadblUpper[]; double gadblLower[]; double gadblDiv[]; double gadblDiv2[]; //+------------------------------------------------------------------+ //| init() | //+------------------------------------------------------------------+ int init() { SetIndexBuffer(0,gadblMid); SetIndexStyle(0,DRAW_LINE); SetIndexLabel(0,"BB-Mid"); SetIndexBuffer(1,gadblUpper); SetIndexStyle(1,DRAW_LINE); SetIndexLabel(1,"BB-Upper"); SetIndexBuffer(2,gadblLower); SetIndexStyle(2,DRAW_LINE); SetIndexLabel(2,"BB-Lower"); SetIndexBuffer(3,gadblDiv); SetIndexStyle(3,DRAW_ARROW); SetIndexArrow(3,108); SetIndexLabel(3,NULL); SetIndexEmptyValue(3,0.0); SetIndexBuffer(4,gadblDiv2); SetIndexStyle(4,DRAW_ARROW); SetIndexArrow(4,108); SetIndexLabel(4,NULL); SetIndexEmptyValue(4,0.0); IndicatorShortName("Fiji BB"); IndicatorDigits(Digits); return( 0 ); } //+------------------------------------------------------------------+ //| deinit() | //+------------------------------------------------------------------+ int deinit() { return( 0 ); } //+------------------------------------------------------------------+ //| start() | //+------------------------------------------------------------------+ int start() { int counted_bars=IndicatorCounted(); if(counted_bars < 0) return (-1); if(counted_bars>0) counted_bars--; int intLimit=Bars-counted_bars; int intTrueShift,inx,jnx; double dblSum,dblNewRes,dblDeviation,dblCurrMA; for(inx=intLimit-eintBandsPeriod; inx>=0; inx--) { intTrueShift=inx+eintMAShift; dblSum=0.0; dblCurrMA=iMA(Symbol(),Period(),eintBandsPeriod,0,eintMAMode,eintMAPrice,intTrueShift); for(jnx=intTrueShift+eintBandsPeriod-1; jnx>=intTrueShift; jnx--) { dblNewRes=Close[jnx]-dblCurrMA; dblSum+=(dblNewRes*dblNewRes); } dblDeviation=edblBandsDev*MathSqrt(dblSum/eintBandsPeriod); gadblMid[inx]=dblCurrMA; gadblUpper[inx] = dblCurrMA + dblDeviation; gadblLower[inx] = dblCurrMA - dblDeviation; gadblDiv[inx]=0.0; gadblDiv2[inx]=0.0; // Check for divergence of upper band if(( High[inx]>gadblUpper[inx]) && (High[inx+eintBarsBack]>gadblUpper[inx+eintBarsBack])) { if(High[inx]gadblUpper[inx+eintBarsBack]) gadblDiv[inx]=High[inx]; } } // Check for divergence of lower band if(( Low[inx] Low[inx+eintBarsBack]) { if(gadblLower[inx]