//+------------------------------------------------------------------+ //| MaChannel.mq4 | //| 2 mas, one widthFactor above High, one widthFactor below Low | //| line buffers show: ma type & price | //| extra buffers show: channel width, slopes | //+------------------------------------------------------------------+ #property indicator_chart_window #property indicator_buffers 4 #property indicator_color1 Black #property indicator_color2 SkyBlue #property indicator_color3 SkyBlue extern int MAPeriod = 7 ; extern string type = "--- Type: 0=sma, 1=ema, 2=smma, 3=lwma " ; extern int MAType = 1; extern string price = "--- Price: 0=c, 1=o, 2=h, 3=l, 4=(h+l)/2, 5=(h+l+c)/3, 6=(h+l+c+c)/4 " ; // extern int MAPrice = 4; extern int PriceHi = 2; extern int PriceLo = 3; // extern string width = "--- Channel width " ; extern double widthFactor = 0.6 ; double Width, AvgWidth; double WidthBuffer[], BufferHi[], BufferLo[], SlopesBuffer[] ; int init() { IndicatorBuffers(4); string widthFac = DoubleToStr(widthFactor,2) ; IndicatorShortName( "MaChannel " +MAPeriod + " - " +widthFac ); IndicatorDigits(MarketInfo(Symbol(),MODE_DIGITS)); SetIndexBuffer(0,WidthBuffer); // chan width SetIndexStyle(0,DRAW_NONE); SetIndexLabel(0,"MaChannel " +MAPeriod +" h-l"); SetIndexBuffer(1,BufferHi); // hi line SetIndexStyle(1,DRAW_LINE,STYLE_SOLID,1); SetIndexLabel(1," ma " +MAPeriod + " " + MAType + " " +PriceHi + " + " +widthFac ); SetIndexDrawBegin(1,MAPeriod); SetIndexBuffer(2,BufferLo); // lo line SetIndexStyle(2,DRAW_LINE,STYLE_SOLID,1); SetIndexLabel(2," ma " +MAPeriod + " " + MAType + " " +PriceLo + " - " +widthFac ); SetIndexDrawBegin(2,MAPeriod); SetIndexBuffer(3,SlopesBuffer); // slopes SetIndexStyle(3,DRAW_NONE); SetIndexLabel(3," slopes"); return(0); } int start() { int limit, counter; double MaHigh, MaLow, MaWidth ; int counted_bars = IndicatorCounted(); //---- check for possible errors if (counted_bars<0) return(-1); //---- last counted bar will be recounted if (counted_bars>0) counted_bars--; limit = Bars - counted_bars; for(int i=limit; i>=0; i--) { counter=i; Width=0; AvgWidth=0; for (counter=i; counter<=i+9;counter++) { AvgWidth=AvgWidth+MathAbs(High[counter]-Low[counter]); } Width=AvgWidth/10 ; MaHigh = iMA(NULL,0,MAPeriod,0,MAType, PriceHi,i); MaLow = iMA(NULL,0,MAPeriod,0,MAType, PriceLo,i); MaWidth = MaHigh - MaLow ; WidthBuffer[i] = MaWidth ; BufferHi[i] = MaHigh + Width * widthFactor ; BufferLo[i] = MaLow - Width * widthFactor ; SlopesBuffer[i] = (BufferHi[i] - BufferHi[i+1]) + ( BufferLo[i] - BufferLo[i+1] ) ; } return(0); } // start()