Navigation´╝ÜHome > Content >

M_cross.mq4

Time: 2013-05-15 | Download file:M_cross.mq4

#property  indicator_separate_window
#property  indicator_buffers 3
#property  indicator_color1  Gold
#property  indicator_color2  DodgerBlue
#property  indicator_width2  2
#property  indicator_style1  2
#property  indicator_color3  CLR_NONE
#property  indicator_width1  1

int FastEMA=12;
int SlowEMA=26;
int SignalSMA=9;

double     MacdBuffer[];
double     SignalBuffer[];
double     HistogramBuffer[];

int        maxLines;
int init()
  {
   SetIndexStyle(0,DRAW_LINE);
   SetIndexStyle(1,DRAW_LINE);
   SetIndexStyle(2,DRAW_HISTOGRAM);
   //
   SetIndexBuffer(0,MacdBuffer);
   SetIndexBuffer(1,SignalBuffer);
   SetIndexBuffer(2,HistogramBuffer);
   //
   SetIndexLabel(0,"MACD");
   SetIndexLabel(1,"Signal");
   SetIndexLabel(2,"MACD-Signal");
   //
   SetIndexDrawBegin(1,SignalSMA);
   IndicatorDigits(Digits+1);
   IndicatorShortName("M_cross("+FastEMA+","+SlowEMA+","+SignalSMA+")");
   return(0);
  }
int deinit()
  {
   DeleteLines();
   return(0);
  }
int start()
  {
   double crossing;
   int limit,i;
   int counted_bars=IndicatorCounted();
//----
   if(counted_bars>0) counted_bars--;
   limit=Bars-counted_bars;
//----
   for(i=0; i0 ;i--)
     {
      crossing=(MacdBuffer[i]-SignalBuffer[i])*(MacdBuffer[i+1]-SignalBuffer[i+1]);
      if (crossing < 0)
        {
         maxLines+=1;
         ObjectCreate("MacdCross"+maxLines,0,0,Time[i],0);
         ObjectSet("MacdCross"+maxLines,OBJPROP_COLOR,C'198,168,0');
         ObjectSet("MacdCross"+maxLines,OBJPROP_STYLE,STYLE_DOT);
        }
     }
   return(0);
  }
//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
void DeleteLines()
  {
   for(int i=1;i<=maxLines;i++) ObjectDelete("MacdCross"+i); maxLines=0;
  }
//+------------------------------------------------------------------+

Recommend