//+------------------------------------------------------------------+ 
//|   _TRO_Multi_Meter_MAxOver                                       | 
//|                                                                  | 
//|   Copyright � 2007, Avery T. Horton, Jr. aka TheRumpledOne       |
//|                                                                  |
//|   PO BOX 43575, TUCSON, AZ 85733                                 |
//|                                                                  |
//|   GIFT AND DONATIONS ACCEPTED                                    | 
//|                                                                  |
//|   therumpledone@gmail.com                                        |  
//+------------------------------------------------------------------+ 
//|                                                                  |
//| go to www.kreslik.com for the latest indicator updates           |  
//+------------------------------------------------------------------+ 
//|                                                                  |
//| Use www.efxgroup.com as your forex broker...                     |  
//| ...tell them therumpledone sent you!                             |  
//+------------------------------------------------------------------+ 

#property indicator_chart_window

extern bool Show_Heading = false;

 
extern string IndName = "MAX" ; // change




extern bool Corner_of_Chart_RIGHT_TOP = true;

extern int Shift_UP_DN =45; 
extern int Adjust_Side_to_side  = 20; // 20



extern int MA_Fast = 5;
extern int MA_Slow = 20;
extern int MA_MODE = 1;
extern int MA_PRICE_TYPE = 0;


extern color BarLabel_color = LightBlue;
extern color CommentLabel_color = LightBlue;

extern color N_color  = Green;
extern color NE_color = Lime;
extern color E_color  = Yellow;
extern color SE_color = Red;
extern color S_color  = Crimson;

//******************* 

bool use.pMid = false ;
//*******************

string ObjHead01,ObjHead02,ObjHead03,ObjHead04,ObjHead05,ObjHead06,ObjHead07,ObjHead08,ObjHead09,ObjHead10,ObjHead11;  

string Obj0001,Obj0002,Obj0003,Obj0004,Obj0005,Obj0006,Obj0007,Obj0008,Obj0009,Obj0010,Obj0011;  

int    MAMode;
string strMAType;
 
//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int init()
  {
   
switch (MA_MODE)
   {
      case 1: strMAType="EMA"; MAMode=MODE_EMA; break;
      case 2: strMAType="SMMA"; MAMode=MODE_SMMA; break;
      case 3: strMAType="LWMA"; MAMode=MODE_LWMA; break;
      case 4: strMAType="LSMA"; break;
      default: strMAType="SMA"; MAMode=MODE_SMA; break;
   }
   return(0);
  }

//+------------------------------------------------------------------+
//| Custom indicator iteration function                              |
//+------------------------------------------------------------------+
int start()
  {    
   //***********************************************************************************************************************

string LabelTime="";

if (LabelTime=="") {LabelTime=TimeToStr(TimeLocal(),TIME_SECONDS); }

   int    counted_bars=IndicatorCounted();
   
string MAPeriod = " "+MA_Fast + "x" + MA_Slow ;   

   ObjHead01 = "IND2ColHead01" + LabelTime  + MAPeriod ;  
   ObjHead02 = "IND2ColHead02" + LabelTime  + MAPeriod ;  
   ObjHead03 = "IND2ColHead03" + LabelTime  + MAPeriod ; 
   ObjHead04 = "IND2ColHead04" + LabelTime  + MAPeriod ;  
   ObjHead05 = "IND2ColHead05" + LabelTime  + MAPeriod ;  
   ObjHead06 = "IND2ColHead06" + LabelTime  + MAPeriod ; 
   ObjHead07 = "IND2ColHead07" + LabelTime  + MAPeriod ;  
   ObjHead08 = "IND2ColHead08" + LabelTime  + MAPeriod ;  
   ObjHead09 = "IND2ColHead09" + LabelTime  + MAPeriod ; 
         
   string IND2_ObjHead01 ="M1 " ;
   string IND2_ObjHead02 ="M5  " ;     
   string IND2_ObjHead03 ="M15 " ;
   string IND2_ObjHead04 =" M30 " ;
   string IND2_ObjHead05 ="H1  " ;     
   string IND2_ObjHead06 ="H4  " ;
   string IND2_ObjHead07 ="D1  " ;
   string IND2_ObjHead08 ="W1  " ;
   string IND2_ObjHead09 ="MN1" ;   
   
   
        
    if (Corner_of_Chart_RIGHT_TOP == true)
    { int Col01x = 170+Adjust_Side_to_side ;                 
      int Col01y = 28+Shift_UP_DN ;
    }
    if (Corner_of_Chart_RIGHT_TOP == false)
   { Col01x = 159+Adjust_Side_to_side ;       
     Col01y = 24+Shift_UP_DN ;
    } 
    
   int ColAdj = -20 ; 
   int Col02x = Col01x + ColAdj ;   
   int Col03x = Col01x + ColAdj*2 ; 
   int Col04x = Col01x + ColAdj*3 ; 
   int Col05x = Col01x + ColAdj*4 ; 
   int Col06x = Col01x + ColAdj*5 ; 
   int Col07x = Col01x + ColAdj*6 ;    
   int Col08x = Col01x + ColAdj*7 ; 
   int Col09x = Col01x + ColAdj*8 ;     
   
   if ( Show_Heading) {        
   ObjectCreate(ObjHead01, OBJ_LABEL, 0, 0, 0);
   ObjectSetText(ObjHead01,IND2_ObjHead01 , 7, "Tahoma Narrow", BarLabel_color);
   ObjectSet(ObjHead01, OBJPROP_CORNER, Corner_of_Chart_RIGHT_TOP);
   ObjectSet(ObjHead01, OBJPROP_XDISTANCE, Col01x);
   ObjectSet(ObjHead01, OBJPROP_YDISTANCE, Col01y); 

   ObjectCreate(ObjHead02, OBJ_LABEL, 0, 0, 0);
   ObjectSetText(ObjHead02,IND2_ObjHead02 , 7, "Tahoma Narrow", BarLabel_color);
   ObjectSet(ObjHead02, OBJPROP_CORNER, Corner_of_Chart_RIGHT_TOP);
   ObjectSet(ObjHead02, OBJPROP_XDISTANCE, Col02x);
   ObjectSet(ObjHead02, OBJPROP_YDISTANCE, Col01y);   
       
   ObjectCreate(ObjHead03, OBJ_LABEL, 0, 0, 0);
   ObjectSetText(ObjHead03,IND2_ObjHead03 , 7, "Tahoma Narrow", BarLabel_color);
   ObjectSet(ObjHead03, OBJPROP_CORNER, Corner_of_Chart_RIGHT_TOP);
   ObjectSet(ObjHead03, OBJPROP_XDISTANCE, Col03x);
   ObjectSet(ObjHead03, OBJPROP_YDISTANCE, Col01y); 
 
   ObjectCreate(ObjHead04, OBJ_LABEL, 0, 0, 0);
   ObjectSetText(ObjHead04,IND2_ObjHead04 , 7, "Tahoma Narrow", BarLabel_color);
   ObjectSet(ObjHead04, OBJPROP_CORNER, Corner_of_Chart_RIGHT_TOP);
   ObjectSet(ObjHead04, OBJPROP_XDISTANCE, Col04x);
   ObjectSet(ObjHead04, OBJPROP_YDISTANCE, Col01y); 
   
   ObjectCreate(ObjHead05, OBJ_LABEL, 0, 0, 0);
   ObjectSetText(ObjHead05,IND2_ObjHead05 , 7, "Tahoma Narrow", BarLabel_color);
   ObjectSet(ObjHead05, OBJPROP_CORNER, Corner_of_Chart_RIGHT_TOP);
   ObjectSet(ObjHead05, OBJPROP_XDISTANCE, Col05x);
   ObjectSet(ObjHead05, OBJPROP_YDISTANCE, Col01y); 
            
   ObjectCreate(ObjHead06, OBJ_LABEL, 0, 0, 0);
   ObjectSetText(ObjHead06,IND2_ObjHead06 , 7, "Tahoma Narrow", BarLabel_color);
   ObjectSet(ObjHead06, OBJPROP_CORNER, Corner_of_Chart_RIGHT_TOP);
   ObjectSet(ObjHead06, OBJPROP_XDISTANCE, Col06x);
   ObjectSet(ObjHead06, OBJPROP_YDISTANCE, Col01y); 

   ObjectCreate(ObjHead07, OBJ_LABEL, 0, 0, 0);
   ObjectSetText(ObjHead07,IND2_ObjHead07 , 7, "Tahoma Narrow", BarLabel_color);
   ObjectSet(ObjHead07, OBJPROP_CORNER, Corner_of_Chart_RIGHT_TOP);
   ObjectSet(ObjHead07, OBJPROP_XDISTANCE, Col07x);
   ObjectSet(ObjHead07, OBJPROP_YDISTANCE, Col01y); 
         
   ObjectCreate(ObjHead08, OBJ_LABEL, 0, 0, 0);
   ObjectSetText(ObjHead08,IND2_ObjHead08 , 7, "Tahoma Narrow", BarLabel_color);
   ObjectSet(ObjHead08, OBJPROP_CORNER, Corner_of_Chart_RIGHT_TOP);
   ObjectSet(ObjHead08, OBJPROP_XDISTANCE, Col08x);
   ObjectSet(ObjHead08, OBJPROP_YDISTANCE, Col01y); 

   ObjectCreate(ObjHead09, OBJ_LABEL, 0, 0, 0);
   ObjectSetText(ObjHead09,IND2_ObjHead09 , 7, "Tahoma Narrow", BarLabel_color);
   ObjectSet(ObjHead09, OBJPROP_CORNER, Corner_of_Chart_RIGHT_TOP);
   ObjectSet(ObjHead09, OBJPROP_XDISTANCE, Col09x);
   ObjectSet(ObjHead09, OBJPROP_YDISTANCE, Col01y); 
       
} // Show_Heading

 //*******************   change for  your indicator ********************
 
    
    string M1_IND2= "-",M5_IND2= "-", M15_IND2= "-", M30_IND2= "-", H1_IND2= "-", H4_IND2= "-", D1_IND2= "-",PRC1, W1_IND2= "-", MN1_IND2= "-";

    color  color_IND2m1,color_IND2m5,color_IND2m15,color_IND2m30,color_IND2H1,color_IND2H4,color_IND2D1,color_IND2W1,color_IND2MN1;     
         

   //IND2 Signals

string symbol = Symbol() ;

 color_IND2m1  = ColorIND2( symbol, PERIOD_M1  ) ;
 color_IND2m5  = ColorIND2( symbol, PERIOD_M5  ) ;
 color_IND2m15 = ColorIND2( symbol, PERIOD_M15 ) ;
 color_IND2m30 = ColorIND2( symbol, PERIOD_M30 ) ;
 color_IND2H1  = ColorIND2( symbol, PERIOD_H1  ) ;
 color_IND2H4  = ColorIND2( symbol, PERIOD_H4  ) ;
 color_IND2D1  = ColorIND2( symbol, PERIOD_D1  ) ;
 color_IND2W1  = ColorIND2( symbol, PERIOD_W1  ) ;
 color_IND2MN1 = ColorIND2( symbol, PERIOD_MN1 ) ;

               
    
 //*******************          
    
    int Col00x = Col01x + 20 ;
    int Col00y = 50+Shift_UP_DN ;
    
    Col01y = 20+Shift_UP_DN ;
    
   Obj0002 = IndName+"SignalM1t" + LabelTime + MAPeriod ; 
           
           ObjectCreate(Obj0002, OBJ_LABEL, 0, 0, 0);
   ObjectSetText(Obj0002,IndName+"("+MAPeriod+")", 7, "Tahoma Narrow",  BarLabel_color);  
   ObjectSet(Obj0002, OBJPROP_CORNER, Corner_of_Chart_RIGHT_TOP);
   ObjectSet(Obj0002, OBJPROP_XDISTANCE, Col00x);
   ObjectSet(Obj0002, OBJPROP_YDISTANCE, Col00y);  // 50+Shift_UP_DN

   Obj0003 = IndName+"SignalM1" + LabelTime + MAPeriod ;        
           ObjectCreate(Obj0003, OBJ_LABEL, 0, 0, 0);
   ObjectSetText(Obj0003, M1_IND2, 40, "Tahoma Narrow",  color_IND2m1);
   ObjectSet(Obj0003, OBJPROP_CORNER, Corner_of_Chart_RIGHT_TOP);
   ObjectSet(Obj0003, OBJPROP_XDISTANCE, Col01x);
   ObjectSet(Obj0003, OBJPROP_YDISTANCE, Col01y); 

   Obj0004 = IndName+"SignalM5" + LabelTime + MAPeriod ;         
           ObjectCreate(Obj0004, OBJ_LABEL, 0, 0, 0);
   ObjectSetText(Obj0004, M5_IND2, 40, "Tahoma Narrow",  color_IND2m5);
   ObjectSet(Obj0004, OBJPROP_CORNER, Corner_of_Chart_RIGHT_TOP);
   ObjectSet(Obj0004, OBJPROP_XDISTANCE, Col02x);
   ObjectSet(Obj0004, OBJPROP_YDISTANCE, Col01y); 
      
   Obj0005 = IndName+"SignalM15" + LabelTime + MAPeriod ; 
   ObjectCreate(Obj0005, OBJ_LABEL, 0, 0, 0);
   ObjectSetText(Obj0005, M15_IND2, 40, "Tahoma Narrow",  color_IND2m15);
   ObjectSet(Obj0005, OBJPROP_CORNER, Corner_of_Chart_RIGHT_TOP);
   ObjectSet(Obj0005, OBJPROP_XDISTANCE, Col03x);
   ObjectSet(Obj0005, OBJPROP_YDISTANCE, Col01y); 
      
   Obj0006 = IndName+"SignalM30" + LabelTime + MAPeriod ;
   ObjectCreate(Obj0006, OBJ_LABEL, 0, 0, 0);
   ObjectSetText(Obj0006, M30_IND2, 40, "Tahoma Narrow",  color_IND2m30);
   ObjectSet(Obj0006, OBJPROP_CORNER, Corner_of_Chart_RIGHT_TOP);
   ObjectSet(Obj0006, OBJPROP_XDISTANCE, Col04x);
   ObjectSet(Obj0006, OBJPROP_YDISTANCE, Col01y); 

   Obj0007 = IndName+"SignalM60" + LabelTime + MAPeriod ;      
           ObjectCreate(Obj0007, OBJ_LABEL, 0, 0, 0);
   ObjectSetText(Obj0007, H1_IND2, 40, "Tahoma Narrow",  color_IND2H1);
   ObjectSet(Obj0007, OBJPROP_CORNER, Corner_of_Chart_RIGHT_TOP);
   ObjectSet(Obj0007, OBJPROP_XDISTANCE, Col05x);
   ObjectSet(Obj0007, OBJPROP_YDISTANCE, Col01y); 

   Obj0008 = IndName+"SignalM240" + LabelTime + MAPeriod ;          
           ObjectCreate(Obj0008, OBJ_LABEL, 0, 0, 0);
   ObjectSetText(Obj0008, H4_IND2, 40, "Tahoma Narrow",  color_IND2H4);
   ObjectSet(Obj0008, OBJPROP_CORNER, Corner_of_Chart_RIGHT_TOP);
   ObjectSet(Obj0008, OBJPROP_XDISTANCE, Col06x);
   ObjectSet(Obj0008, OBJPROP_YDISTANCE, Col01y);

   Obj0009 = IndName+"SignalM1440" + LabelTime + MAPeriod ;    
           ObjectCreate(Obj0009, OBJ_LABEL, 0, 0, 0);
   ObjectSetText(Obj0009, D1_IND2, 40, "Tahoma Narrow",  color_IND2D1);
   ObjectSet(Obj0009, OBJPROP_CORNER, Corner_of_Chart_RIGHT_TOP);
   ObjectSet(Obj0009, OBJPROP_XDISTANCE, Col07x);
   ObjectSet(Obj0009, OBJPROP_YDISTANCE, Col01y);
   
   Obj0010 = IndName+"SignalW1" + LabelTime + MAPeriod ;    
           ObjectCreate(Obj0010, OBJ_LABEL, 0, 0, 0);
   ObjectSetText(Obj0010, W1_IND2, 40, "Tahoma Narrow",  color_IND2W1);
   ObjectSet(Obj0010, OBJPROP_CORNER, Corner_of_Chart_RIGHT_TOP);
   ObjectSet(Obj0010, OBJPROP_XDISTANCE, Col08x);
   ObjectSet(Obj0010, OBJPROP_YDISTANCE, Col01y);   
   
   Obj0011 = IndName+"SignalMN1" + LabelTime + MAPeriod ;    
           ObjectCreate(Obj0011, OBJ_LABEL, 0, 0, 0);
   ObjectSetText(Obj0011, MN1_IND2, 40, "Tahoma Narrow",  color_IND2MN1);
   ObjectSet(Obj0011, OBJPROP_CORNER, Corner_of_Chart_RIGHT_TOP);
   ObjectSet(Obj0011, OBJPROP_XDISTANCE, Col09x);
   ObjectSet(Obj0011, OBJPROP_YDISTANCE, Col01y); 
     
 //----

   return(0);
  }
//+------------------------------------------------------------------+

//+------------------------------------------------------------------+
//| Custom indicator deinitialization function                       |
//+------------------------------------------------------------------+
int deinit()
  {
//----

ObjectsDeleteAll(0,OBJ_HLINE);
ObjectsDeleteAll(0,OBJ_TEXT);
ObjectsDeleteAll(0,OBJ_LABEL);
deleteObject(); 

//----
   return(0);
  }
  
void deleteObject()
  { 
//ObjectDelete(Obj0001);  
ObjectDelete(Obj0002); 
ObjectDelete(Obj0003); 
ObjectDelete(Obj0004); 
ObjectDelete(Obj0005); 
ObjectDelete(Obj0006); 
ObjectDelete(Obj0007); 
ObjectDelete(Obj0008); 
ObjectDelete(Obj0009); 
ObjectDelete(Obj0010); 
ObjectDelete(Obj0011); 

ObjectDelete(ObjHead01);  
ObjectDelete(ObjHead02); 
ObjectDelete(ObjHead03); 
ObjectDelete(ObjHead04); 
ObjectDelete(ObjHead05); 
ObjectDelete(ObjHead06); 
ObjectDelete(ObjHead07); 
ObjectDelete(ObjHead08); 
ObjectDelete(ObjHead09); 
 
  }
//+------------------------------------------------------------------+

color ColorIND2( string myPair, int myPeriod   )  
{


      color MA_color;

//      int BarShift = iBarShift(myPair,myPeriod,Time[0],true); 

      double price = iClose(myPair,myPeriod,0);
      double close = iClose(myPair,myPeriod,1);
  

double  fastval  = iMA(NULL,myPeriod,MA_Fast,0,MAMode,MA_PRICE_TYPE,0);
double  fastval1  = iMA(NULL,myPeriod,MA_Fast,0,MAMode,MA_PRICE_TYPE,1);

double  slowval  = iMA(NULL,myPeriod,MA_Slow,0,MAMode,MA_PRICE_TYPE,0);
double  slowval1  = iMA(NULL,myPeriod,MA_Slow,0,MAMode,MA_PRICE_TYPE,1);

 Print( myPeriod, "_fastval " , DoubleToStr(fastval,Digits),  " " , "_slowval " , DoubleToStr(slowval,Digits) ) ;


while(true)
{

if (fastval >  slowval && fastval1 < slowval1 ){  MA_color = NE_color; break ;} 
if (fastval <  slowval && fastval1 > slowval1) {  MA_color = SE_color; break ;}
if (fastval >  slowval)                        {  MA_color = N_color; break ;}
if (fastval <  slowval)                        {  MA_color = S_color; break ;}
 
break ;


}   
    
return( MA_color ) ;   
                                    
} // end DoWork