Time: 2010-03-26 | Download file:MA_in_Color_st2050_v2.1.mq4
//+---------------------------------------------------------------------------- //| MA_In_Color.mq4 | //| Copyright © 2004, MetaQuotes Software Corp. | //| Modified from LSMA_In_Color to use any MA by Robert Hill | //+---------------------------------------------------------------------------- // // Modified by st2050 // v1: Changed MAprice from integer to ENUM_APPLIED_PRICE // Can't add ENUM_MA_METHOD for sMAtype due to LSMA support // Added MaxBars parameter // Added ShowOnLineModeOnly parameter // // v2: Added "Do not draw current candle" property // // v2.1 Added missed "if (limit= 1 ; i--) { lengthvar = length + 1; lengthvar /= 3; tmp = 0; tmp = ( i - lengthvar)*Close[length-i+shift]; sum+=tmp; } wt = sum*6/(length*(length+1)); return(wt); } void HideShowIndicator() { ChartMode = ChartGetInteger(0,CHART_MODE); if (ChartMode!=PrevChartMode) { if (ShowOnLineModeOnly) { if (ChartMode==CHART_LINE) ShowIndicator(); else HideIndicator(); } else ShowIndicator(); } } void HideIndicator() { SetIndexStyle(2,DRAW_NONE); SetIndexStyle(1,DRAW_NONE); SetIndexStyle(0,DRAW_NONE); } void ShowIndicator() { SetIndexStyle(2,DRAW_LINE); SetIndexStyle(1,DRAW_LINE); SetIndexStyle(0,DRAW_LINE); NeedRedraw=true; } int start() { HideShowIndicator(); double MA_Cur, MA_Prev; int limit; 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; if ((limit>MaxBars) || NeedRedraw) limit=MaxBars; if (limit =_StartBar; i--) { if (MAType == 4) { MA_Cur = LSMA(MAPeriod,i); MA_Prev = LSMA(MAPeriod,i+1); } else { MA_Cur = iMA(NULL,0,MAPeriod,0,MAMode,MAprice,i); MA_Prev = iMA(NULL,0,MAPeriod,0,MAMode,MAprice,i+1); } //========== COLOR CODING =========================================== ExtMapBuffer3[i] = MA_Cur; //red ExtMapBuffer2[i] = MA_Cur; //green ExtMapBuffer1[i] = MA_Cur; //yellow if (MA_Prev > MA_Cur) { ExtMapBuffer2[i] = EMPTY_VALUE; } else if (MA_Prev < MA_Cur) { ExtMapBuffer1[i] = EMPTY_VALUE; //-1 red/greem tight } else { ExtMapBuffer1[i]=EMPTY_VALUE;//EMPTY_VALUE; ExtMapBuffer2[i]=EMPTY_VALUE;//EMPTY_VALUE; } } NeedRedraw=false; return(0); } //+------------------------------------------------------------------+