| / | Forum |
|
whitebloodcell
2010.08.18 17:59
I am trying to create an indicator that paints the area between two defined standard deviation bands. E.g. The area between the 2nd and 3rd deviations from the central MA. How can I do this? My code is below. //+------------------------------------------------------------------+ //WBC_BollingerBand_Zone | //+------------------------------------------------------------------+ #property copyright "whitebloodcell" #property link "" #property indicator_chart_window #property indicator_buffers 7 #property indicator_color1 DimGray #property indicator_color2 DarkGreen #property indicator_color3 Red #property indicator_color4 Green #property indicator_color5 Maroon #property indicator_color6 Red #property indicator_color7 Green #property indicator_width1 1 #property indicator_width2 1 #property indicator_width3 1 #property indicator_width4 1 #property indicator_width5 1 #property indicator_width6 2 #property indicator_width7 2 #property indicator_style1 STYLE_SOLID #property indicator_style2 STYLE_SOLID #property indicator_style3 STYLE_SOLID #property indicator_style4 STYLE_SOLID #property indicator_style5 STYLE_SOLID extern int BandsLength = 20; extern int BandsMethod = MODE_EMA; extern int BandsPrice = PRICE_CLOSE; extern double BandsDeviation1 = 2; extern double BandsDeviation2 = 3; double MaBuffer[]; double UpperBand1[]; double LowerBand1[]; double UpperBand2[]; double LowerBand2[]; double buffer5[]; double buffer6[]; //+------------------------------------------------------------------+ //| | //+------------------------------------------------------------------+ int init() { SetIndexBuffer(0,MaBuffer); SetIndexBuffer(1,UpperBand1); SetIndexBuffer(2,LowerBand1); SetIndexBuffer(3,UpperBand2); SetIndexBuffer(4,LowerBand2); SetIndexBuffer(5,buffer5); SetIndexStyle(5,DRAW_HISTOGRAM); SetIndexBuffer(6,buffer6); SetIndexStyle(6,DRAW_HISTOGRAM); SetIndexLabel(0,"Bands ma"); SetIndexLabel(1,"Bands upper band 1"); SetIndexLabel(2,"Bands lower band 1"); SetIndexLabel(3,"Bands upper band 2"); SetIndexLabel(4,"Bands lower band 2"); SetIndexLabel(5,"Zone Upper Bound"); SetIndexLabel(6,"Zone Lower Bound"); return(0); } int deinit() { return(0); } //+------------------------------------------------------------------+ //| | //+------------------------------------------------------------------+ int start() { double sum,ma; int counted_bars = IndicatorCounted(); int limit,i,k; if(counted_bars < 0) {return(-1);} if(counted_bars>0) {counted_bars--;} limit = Bars-counted_bars; for (i=limit;i>=0;i--) { ma = iMA(NULL,0,BandsLength,0,BandsMethod,BandsPrice,i); for (sum = 0.0, k = 0; k < BandsLength; k++) { sum += ((Close[k+i]-ma)*(Close[k+i]-ma)); } // // // // // MaBuffer[i] = ma; if (BandsDeviation1!=0) { UpperBand1[i] = ma+BandsDeviation1*MathSqrt(sum/BandsLength); LowerBand1[i] = ma-BandsDeviation1*MathSqrt(sum/BandsLength); } if (BandsDeviation2!=0) { UpperBand2[i] = ma+BandsDeviation2*MathSqrt(sum/BandsLength); LowerBand2[i] = ma-BandsDeviation2*MathSqrt(sum/BandsLength); } //Red //buffer6[i] = MaBuffer[i]; //buffer5[i] = UpperBand2[i]; //buffer5[i] = MaBuffer[i]; //buffer6[i] = LowerBand2[i]; } return(0); } |