//+------------------------------------------------------------------+
//|                                                        2MACD.mq4 |
//|                      Copyright � 2010, MetaQuotes Software Corp. |
//|                                        http://www.metaquotes.net |
//+------------------------------------------------------------------+
#property copyright "Copyright � 2010, MetaQuotes Software Corp."
#property link      "http://www.metaquotes.net"

#property indicator_chart_window
#property indicator_buffers 2
#property indicator_color1 Green
#property indicator_color2 Red
//---- buffers
double ExtMapBuffer1[];
double ExtMapBuffer2[];
//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
datetime lastbar;
double   distance;

int init()
  {
//---- indicators
   SetIndexStyle(0,DRAW_ARROW);
   SetIndexArrow(0,225);
   SetIndexBuffer(0,ExtMapBuffer1);
   SetIndexEmptyValue(0,0.0);
   SetIndexStyle(1,DRAW_ARROW);
   SetIndexArrow(1,226);
   SetIndexBuffer(1,ExtMapBuffer2);
   SetIndexEmptyValue(1,0.0);
//----
   
   distance = 0.2;
   if(StringFind(Symbol(), "JPY") == -1) distance = 0.002;
   return(0);
  }
//+------------------------------------------------------------------+
//| Custom indicator deinitialization function                       |
//+------------------------------------------------------------------+
int deinit()
  {
//----
   
//----
   return(0);
  }
//+------------------------------------------------------------------+
//| Custom indicator iteration function                              |
//+------------------------------------------------------------------+
int start()
  {
   int    counted_bars=IndicatorCounted();
   double fMacdMain, fMacdSignal, sMacdMain, sMacdSignal, fMacdMain2, fMacdSignal2, sMacdMain2, sMacdSignal2;
   

//----
   for(int i=Bars-counted_bars-1; i>=0; i--)
   {
      fMacdMain = iMACD(NULL, 0, 5, 10, 2, PRICE_CLOSE, MODE_MAIN, i);
      fMacdSignal = iMACD(NULL, 0, 5, 10, 2, PRICE_CLOSE, MODE_SIGNAL, i);
      sMacdMain = iMACD(NULL, 0, 10, 20, 5, PRICE_CLOSE, MODE_MAIN, i);
      sMacdSignal = iMACD(NULL, 0, 10, 20, 5, PRICE_CLOSE, MODE_SIGNAL, i);

      fMacdMain2 = iMACD(NULL, 0, 5, 10, 2, PRICE_CLOSE, MODE_MAIN, i+1);
      fMacdSignal2 = iMACD(NULL, 0, 5, 10, 2, PRICE_CLOSE, MODE_SIGNAL, i+1);
      sMacdMain2 = iMACD(NULL, 0, 10, 20, 5, PRICE_CLOSE, MODE_MAIN, i+1);
      sMacdSignal2 = iMACD(NULL, 0, 10, 20, 5, PRICE_CLOSE, MODE_SIGNAL, i+1);
      
      //LONG
      if(((fMacdSignal < fMacdMain && fMacdMain > 0) && (sMacdSignal < sMacdMain && sMacdMain > 0)) && ((fMacdMain2 <= 0 || fMacdMain2 < fMacdSignal2) || (sMacdMain2 <= 0 || sMacdMain2 < sMacdSignal2)))
      {
         ExtMapBuffer1[i] = Open[i] - distance;
      }
      
      //SHORT
      if(((fMacdSignal > fMacdMain && fMacdMain < 0) && (sMacdSignal > sMacdMain && sMacdMain < 0)) && ((fMacdMain2 >= 0 || fMacdMain2 > fMacdSignal2) || (sMacdMain2 >= 0 || sMacdMain2 > sMacdSignal2)))
      {
         ExtMapBuffer2[i] = Open[i] + distance;
      }

      if(lastbar != Time[0])
      {
         if(ExtMapBuffer1[1] > 0) Alert("LONG: " + Symbol());
         if(ExtMapBuffer2[1] > 0) Alert("SHORT: " + Symbol());
         lastbar = Time[0];
      }
   }
//----
   return(0);
  }
//+------------------------------------------------------------------+