//+------------------------------------------------------------------+ //| SpielersHedge MACD.mq4 | //| © 2008.07.15 SwingMan | //| | //+------------------------------------------------------------------+ #property copyright "© 2008.07.15 SwingMan" #property link "" //---- indicator settings #property indicator_separate_window #property indicator_buffers 5 #property indicator_color1 Turquoise #property indicator_color2 Red #property indicator_color3 Gray #property indicator_color4 Green #property indicator_color5 Green #property indicator_level1 0.0 #property indicator_levelstyle STYLE_SOLID #property indicator_levelcolor Gray //---- extern parameters --------------------------------------------- extern string MACD_Symbol = ""; extern int Period_FastMACD = 5; extern int Period_SlowMACD = 34; extern string ____MovingAverage____ = "0=SMA, 1=EMA, 2=SMMA, 3=LWMA"; extern int Mode_FastMavg = 3; // extern string ____Price____ = "0=Close, 4=Median, 5=Typical, 6=Weighted"; extern int Price_FastMavg = 5; // extern int Period_SmoothMACD = 55; extern double Factor_TriggerLine = 1.0; //-------------------------------------------------------------------- //---- indicator buffers double MacdBuffer[]; double absMACDBuffer[]; double avgMACDBuffer[]; double MacdBufferUp[]; double MacdBufferDown[]; double SignalMacdLineUp[]; double SignalMacdLineDown[]; //---- variables string sWindowsName; //+------------------------------------------------------------------+ //| Custom indicator initialization function | //+------------------------------------------------------------------+ int init() { if (MACD_Symbol == "") { MACD_Symbol = Symbol(); color colorUp = indicator_color1; color colorDn = indicator_color2; } else { colorUp = DodgerBlue; colorDn = FireBrick; } ArraySetAsSeries(absMACDBuffer, true); ArraySetAsSeries(avgMACDBuffer, true); //---- indicator buffers mapping SetIndexBuffer(0,MacdBufferUp); SetIndexBuffer(1,MacdBufferDown); SetIndexBuffer(2,MacdBuffer); SetIndexBuffer(3,SignalMacdLineUp); SetIndexBuffer(4,SignalMacdLineDown); //---- drawing settings SetIndexStyle(0,DRAW_HISTOGRAM, 0, 2, colorUp); SetIndexStyle(1,DRAW_HISTOGRAM, 0, 2, colorDn); SetIndexStyle(2,DRAW_LINE, 0, 1); SetIndexStyle(3,DRAW_LINE, 0, 1); SetIndexStyle(4,DRAW_LINE, 0, 1); SetIndexDrawBegin(0,Period_SlowMACD); SetIndexDrawBegin(1,Period_SlowMACD); SetIndexDrawBegin(2,Period_SlowMACD); SetIndexDrawBegin(3,Period_SlowMACD); SetIndexDrawBegin(4,Period_SlowMACD); IndicatorDigits(Digits); //---- name for DataWindow and indicator subwindow label sWindowsName = "SpielersHedge MACD ("+MACD_Symbol+", "+Period_FastMACD+","+Period_SlowMACD+")"; IndicatorShortName(sWindowsName); SetIndexLabel(0,"MACD up"); SetIndexLabel(1,"MACD down"); SetIndexLabel(2,NULL); SetIndexLabel(3,"avgMACD"); SetIndexLabel(4,NULL); //---- initialization done return(0); } //+------------------------------------------------------------------+ //| Moving Averages Convergence/Divergence | //+------------------------------------------------------------------+ int start() { ArrayResize(absMACDBuffer, Bars); ArrayResize(avgMACDBuffer, Bars); int i,limit; int counted_bars=IndicatorCounted(); double current, prev, Diff; //---- last counted bar will be recounted if(counted_bars>0) counted_bars--; limit=Bars - counted_bars; //---- Upper TimeFrame ............................................ for(i=0; iprev) up=true; if(current