//+------------------------------------------------------------------+ //| MACD with crossing.mq4 | //| mladen | //+------------------------------------------------------------------+ #property copyright "" #property link "" //---- indicator settings #property indicator_separate_window #property indicator_buffers 5 #property indicator_color1 DimGray #property indicator_color2 DimGray #property indicator_color3 Gray #property indicator_color4 Gold #property indicator_color5 Red #property indicator_width1 2 #property indicator_width4 2 //---- indicator parameters // // // // extern int FastEMA = 12; extern int SlowEMA = 26; extern int SignalSMA = 9; extern bool ShowCrossings = true; extern color VertLineCrossUpColor = DarkSlateBlue; extern color VertLineCrossDnColor = Purple; extern int VertLineStyle = 4; extern int VertLineWdth = 1; extern int MaxLinesScreensX = 2; //---- indicator buffers // // // // double MacdBuffer[]; double SignalBuffer[]; double HistogramBufferUp[]; double HistogramBufferDo[]; double OsmaBuffer[]; string shortname; int VertLineColor; //---- globals // // // // int maxLines; //+------------------------------------------------------------------+ //| Custom indicator initialization function | //+------------------------------------------------------------------+ int init() { SetIndexBuffer(0,HistogramBufferUp); SetIndexBuffer(1,HistogramBufferDo); SetIndexBuffer(2,OsmaBuffer); SetIndexBuffer(3,MacdBuffer); SetIndexBuffer(4,SignalBuffer); SetIndexStyle(0,DRAW_HISTOGRAM); SetIndexStyle(1,DRAW_HISTOGRAM); SetIndexLabel(0,NULL); SetIndexLabel(1,NULL); SetIndexLabel(2,"Osma"); SetIndexLabel(3,"MACD"); SetIndexLabel(4,"Signal"); IndicatorDigits(Digits+1); shortname = "MACD ("+FastEMA+","+SlowEMA+","+SignalSMA+")"; IndicatorShortName(shortname); return(0); } int deinit() { DeleteLines(); return(0); } //+------------------------------------------------------------------+ //| Moving Averages Convergence/Divergence | //+------------------------------------------------------------------+ int start() { int counted_bars=IndicatorCounted(); int limit,i; double crossing; if(counted_bars>0) counted_bars--; limit=Bars-counted_bars; for(i=0; i=0; i--) { SignalBuffer[i] = iMAOnArray(MacdBuffer,Bars,SignalSMA,0,MODE_SMA,i); OsmaBuffer[i] = NormalizeDouble(MacdBuffer[i],Digits+1) - NormalizeDouble(SignalBuffer[i],Digits+1); // // // // // if (OsmaBuffer[i]>OsmaBuffer[i+1]){ HistogramBufferUp[i] = OsmaBuffer[i]; HistogramBufferDo[i] = EMPTY_VALUE; } else { HistogramBufferDo[i] = OsmaBuffer[i]; HistogramBufferUp[i] = EMPTY_VALUE; } } // // // // // DeleteLines(); if (ShowCrossings) for (i=WindowBarsPerChart()*MaxLinesScreensX; i>=0 ;i--) { crossing = (MacdBuffer[i]-SignalBuffer[i])*(MacdBuffer[i+1]-SignalBuffer[i+1]); if (crossing < 0) { maxLines += 1; ObjectCreate(shortname+" MacdCross "+ maxLines,0,0,Time[i],0); if (MacdBuffer[i] > MacdBuffer[i+1]) VertLineColor = VertLineCrossUpColor; else VertLineColor = VertLineCrossDnColor; ObjectSet(shortname+" MacdCross "+ maxLines,OBJPROP_COLOR,VertLineColor); ObjectSet(shortname+" MacdCross "+ maxLines,OBJPROP_STYLE,VertLineStyle); ObjectSet(shortname+" MacdCross "+ maxLines,OBJPROP_WIDTH,VertLineWdth); } } return(0); } //+------------------------------------------------------------------+ //| | //+------------------------------------------------------------------+ void DeleteLines() { for (int i=1;i<=maxLines;i++) ObjectDelete(shortname+" MacdCross "+i); maxLines=0; } //+------------------------------------------------------------------+