//+------------------------------------------------------------------+
//|          HAS_MultiPair_Direction_Indie-USDJPY(Combo)_Pairs.mq4   |
//|                                  Copyright © 2011, John Wustrack |
//|              Modified by Tywford Lamai Saturday, 08/June/2013    |
//+------------------------------------------------------------------+



#property copyright "Copyright © 2011, John Wustrack"
#property link      ""

#property indicator_chart_window

#define TitleY 10
#define PairX 10
#define SignalX 100
#define BarsX 160

#define LineStartY 60
#define LineOffY 20

#define Font "ArialBlack"
#define FontSize 7
#define TextColor Silver
#define BullColor Blue
#define BearColor Red

#define ObjPfx "MP_HAS"

extern string HAS   = "----USDJPY(Combo) HAS SETTINGS----";
extern int MaMetod  = 2;
extern int MaPeriod = 9;
extern int MaMetod2  = 2;
extern int MaPeriod2 = 12;
extern bool       AlertOn = true;
extern int        MinimumSignalPairs = 9;

string TradePair[11] = {"GBPUSD","AUDUSD","NZDUSD","EURUSD","USDCHF","GBPJPY","CHFJPY","AUDJPY","EURJPY","USDJPY","NZDJPY"};
int NoOfPairs = 11;

datetime LastAlert;

//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int init()
  {
//---- 
      
   Create_Title_Line();
      
//----
   return(0);
  }
//+------------------------------------------------------------------+
//| Custom indicator deinitialization function                       |
//+------------------------------------------------------------------+
int deinit()
  {
//----
   Delete_Objects();   
//----
   return(0);
  }
//+------------------------------------------------------------------+
//| Custom indicator iteration function                              |
//+------------------------------------------------------------------+
int start()
  {
//----
   int ld_Signal,li_BullSignal,li_BearSignal;
   
   int OffsetY = LineStartY;
   
   color lc_color;
   string ls_arrow;
   
   
      // For each pair in the array 
      for (int i=0; i<NoOfPairs; i++)
         {
         ld_Signal=0;
         li_BullSignal=0;
         li_BearSignal=0;
        {
                  
            
            
         double HA00=iCustom(TradePair[i], 0, "Heiken_Ashi_Smoothed",MaMetod,MaPeriod,MaMetod2,MaPeriod2,0,1);
         double HA10=iCustom(TradePair[i], 0, "Heiken_Ashi_Smoothed",MaMetod,MaPeriod,MaMetod2,MaPeriod2,1,1);
         double HA20=iCustom(TradePair[i], 0, "Heiken_Ashi_Smoothed",MaMetod,MaPeriod,MaMetod2,MaPeriod2,2,1);
         double HA30=iCustom(TradePair[i], 0, "Heiken_Ashi_Smoothed",MaMetod,MaPeriod,MaMetod2,MaPeriod,3,1);
         
            
          if (HA00 < HA10 && HA20 < HA30)  ld_Signal=1;
          if (HA00 > HA10 && HA20 > HA30)  ld_Signal=-1;
          
        
            }
         
         // Create the pair on the screen
         Object_Create(ObjPfx+"Pair"+i,PairX,OffsetY,TradePair[i],FontSize,Font,TextColor);
         
         
            {
            
            if (ld_Signal == 1)
               {
               ls_arrow = CharToStr(233);
               lc_color = BullColor; 
               li_BullSignal++;              
               }
            if (ld_Signal == -1)
               {
               ls_arrow = CharToStr(234);
               lc_color = BearColor; 
               li_BearSignal++;             
               }
                           
            Object_Create(ObjPfx+"Signal"+i,SignalX,OffsetY,ls_arrow,FontSize,"Wingdings",lc_color);
           
            }
         
         

         OffsetY += LineOffY;

         }  //end of pairs loop
         
      // Alerts
      if ( li_BullSignal >= MinimumSignalPairs  && LastAlert != Time[0])
         {
         Alert("BUY SIGNAL at ",TimeToStr(Time[0],TIME_DATE|TIME_MINUTES));
         LastAlert = Time[0];
         }
         
      if ( li_BearSignal >= MinimumSignalPairs && LastAlert != Time[0])
         {
         Alert("SELL SIGNAL at ",TimeToStr(Time[0],TIME_DATE|TIME_MINUTES));
         LastAlert = Time[0];
         }
      
         
//----
   return(0);
  }
//+------------------------------------------------------------------+
//| create the title line                                            |
//+------------------------------------------------------------------+
int Create_Title_Line()
  {
//----
   Object_Create(ObjPfx+"USDJPY(Combo)",PairX,TitleY,"USDJPY(Combo)",FontSize,Font,TextColor);
   Object_Create(ObjPfx+"Signal",SignalX,TitleY,"Has-Signal",FontSize,Font,TextColor);
 
   return(0);
  }
//+------------------------------------------------------------------+
//| create screen objects                                            |
//+------------------------------------------------------------------+
void Object_Create(string ps_name,int pi_x,int pi_y,string ps_text=" ",int pi_size=12,
                  string ps_font="Arial",color pc_colour=CLR_NONE)
  {
//----
   
   ObjectCreate(ps_name,OBJ_LABEL,0,0,0,0,0);
   ObjectSet(ps_name,OBJPROP_CORNER,0);
   ObjectSet(ps_name,OBJPROP_COLOR,pc_colour);
   ObjectSet(ps_name,OBJPROP_XDISTANCE,pi_x);
   ObjectSet(ps_name,OBJPROP_YDISTANCE,pi_y);
   
   ObjectSetText(ps_name,ps_text,pi_size,ps_font,pc_colour);

//----
   return(0);
  }
//+------------------------------------------------------------------+
//| Delete the objects                                               |
//+------------------------------------------------------------------+
void Delete_Objects() 
  {
//----
   string ls_Obj.Name;
   for (int i=ObjectsTotal()-1; i>=0; i--)
      {
      ls_Obj.Name=ObjectName(i);
      if (StringFind(ls_Obj.Name,ObjPfx)>-1) ObjectDelete(ls_Obj.Name);
      }
   ObjectsRedraw();
//----
   return(0);
  }
//+------------------------------------------------------------------+