//+------------------------------------------------------------------+ 
//|   TRO_Multi_Meter_STARC                                          | 
//|                                                                  | 
//|   Copyright © 2008, 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 mbtrading as your forex broker...                            |  
//| http://therumpledone.mbtrading.com/fx/demo.asp                   |  
//+------------------------------------------------------------------+ 

#property indicator_chart_window

extern bool Show_Heading = true;

 
extern string IndName = "STARC" ; // change

extern bool Corner_of_Chart_RIGHT_TOP = true;

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

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

extern int    MA_Period  = 4; //6;
extern int    ATR_Period = 4; //15;
extern double KATR       = 1; //2;
extern int    Shift      = 0; //1;


extern color colorBull    =  Green ;
extern color colorBear    =  Red ;
extern color colorRanging =  Blue  ;
 


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, LabelTime ;

string symbol, tChartPeriod,  tShortName ;  
int    digits, period , i ; 
 
   string MKT_ObjHead01 ="M1 " ;
   string MKT_ObjHead02 ="M5  " ;     
   string MKT_ObjHead03 ="M15 " ;
   string MKT_ObjHead04 =" M30 " ;
   string MKT_ObjHead05 ="H1  " ;     
   string MKT_ObjHead06 ="H4  " ;
   string MKT_ObjHead07 ="D1  " ;
   string MKT_ObjHead08 ="W1  " ;
   string MKT_ObjHead09 ="MN1" ;   
   
int nHH, nLL, nXA, nXB,   j, min, max, start, end , xBars ; 
   
double    MA_Cur, MA_Prev, cClose;  

double Hi, Li, C;

double prev_high, prev_low, prev_close, D, p, value ;
 

color pColor = Blue, ColorMarket = Yellow  ;

string  tMarket  ;  



double point,  open, high, low, close, mid, range, pClose, pOpen, pHigh, pLow, pMid, pRange, cRange  ;  
double xMax = - 1,  xMin = 9999999999999, xDiff, xClose, xHigh, xLow, xRunUp, xRunDn, xPain ;
double High0, Low0, Open0,  Close0, Open1,High1, Low1, Close1   ;  

bool xUp, xDn, bull, bear, ranging ;  
   
//+------------------------------------------------------------------+

int init()
  {
  

   period       = Period() ;   
   tChartPeriod = TimeFrameToString(period) ;
   symbol       = Symbol() ;
   LabelTime    = symbol + tChartPeriod  ;  
 
   ObjHead01 = "MKTColHead01" ; 
   ObjHead02 = "MKTColHead02" ; 
   ObjHead03 = "MKTColHead03" ; 
   ObjHead04 = "MKTColHead04" ; 
   ObjHead05 = "MKTColHead05" ; 
   ObjHead06 = "MKTColHead06" ; 
   ObjHead07 = "MKTColHead07" ; 
   ObjHead08 = "MKTColHead08" ; 
   ObjHead09 = "MKTColHead09" ; 
         
   Obj0002 = "MKTSignalM1t" ; 
   Obj0003 = "MKTSignalM1" ;  
   Obj0004 = "MKTSignalM5" ;  
   Obj0005 = "MKTSignalM15" ;    
   Obj0006 = "MKTSignalM30" ;    
   Obj0007 = "MKTSignalM60" ;     
   Obj0008 = "MKTSignalM240" ;   
   Obj0009 = "MKTSignalM1440" ;   
   Obj0010 = "MKTSignalW1" ;  
   Obj0011 = "MKTSignalMN1" ;   
   
   return(0);
  }

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


        
    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,MKT_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,MKT_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,MKT_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,MKT_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,MKT_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,MKT_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,MKT_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,MKT_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,MKT_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_MKT= "-",M5_MKT= "-", M15_MKT= "-", M30_MKT= "-", H1_MKT= "-", H4_MKT= "-", D1_MKT= "-",PRC1, W1_MKT= "-", MN1_MKT= "-";

    color  color_MKTm1,color_MKTm5,color_MKTm15,color_MKTm30,color_MKTH1,color_MKTH4,color_MKTD1,color_MKTW1,color_MKTMN1;     
         

   //MKT Signals

string symbol = Symbol() ;

 color_MKTm1  = ColorMKT( symbol, PERIOD_M1  ) ;
 color_MKTm5  = ColorMKT( symbol, PERIOD_M5  ) ;

// Comment("M5 Pivot =", DoubleToStr(cPivot,Digits) ); 
 
 color_MKTm15 = ColorMKT( symbol, PERIOD_M15  ) ;
 

 
 color_MKTm30 = ColorMKT( symbol, PERIOD_M30  ) ;
 color_MKTH1  = ColorMKT( symbol, PERIOD_H1  ) ;
 color_MKTH4  = ColorMKT( symbol, PERIOD_H4  ) ;
 color_MKTD1  = ColorMKT( symbol, PERIOD_D1  ) ;
 color_MKTW1  = ColorMKT( symbol, PERIOD_W1  ) ;
 color_MKTMN1 = ColorMKT( symbol, PERIOD_MN1  ) ;

               
    
 //*******************          
    
    int Col00x = Col01x + 20 ;
    int Col00y = 50+Shift_UP_DN ;
    
    Col01y = 20+Shift_UP_DN ;
    

           ObjectCreate(Obj0002, OBJ_LABEL, 0, 0, 0);
   ObjectSetText(Obj0002,IndName, 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

      
           ObjectCreate(Obj0003, OBJ_LABEL, 0, 0, 0);
   ObjectSetText(Obj0003, M1_MKT, 40, "Tahoma Narrow",  color_MKTm1);
   ObjectSet(Obj0003, OBJPROP_CORNER, Corner_of_Chart_RIGHT_TOP);
   ObjectSet(Obj0003, OBJPROP_XDISTANCE, Col01x);
   ObjectSet(Obj0003, OBJPROP_YDISTANCE, Col01y); 

          
           ObjectCreate(Obj0004, OBJ_LABEL, 0, 0, 0);
   ObjectSetText(Obj0004, M5_MKT, 40, "Tahoma Narrow",  color_MKTm5);
   ObjectSet(Obj0004, OBJPROP_CORNER, Corner_of_Chart_RIGHT_TOP);
   ObjectSet(Obj0004, OBJPROP_XDISTANCE, Col02x);
   ObjectSet(Obj0004, OBJPROP_YDISTANCE, Col01y); 
      

   ObjectCreate(Obj0005, OBJ_LABEL, 0, 0, 0);
   ObjectSetText(Obj0005, M15_MKT, 40, "Tahoma Narrow",  color_MKTm15);
   ObjectSet(Obj0005, OBJPROP_CORNER, Corner_of_Chart_RIGHT_TOP);
   ObjectSet(Obj0005, OBJPROP_XDISTANCE, Col03x);
   ObjectSet(Obj0005, OBJPROP_YDISTANCE, Col01y); 
      

   ObjectCreate(Obj0006, OBJ_LABEL, 0, 0, 0);
   ObjectSetText(Obj0006, M30_MKT, 40, "Tahoma Narrow",  color_MKTm30);
   ObjectSet(Obj0006, OBJPROP_CORNER, Corner_of_Chart_RIGHT_TOP);
   ObjectSet(Obj0006, OBJPROP_XDISTANCE, Col04x);
   ObjectSet(Obj0006, OBJPROP_YDISTANCE, Col01y); 

    
           ObjectCreate(Obj0007, OBJ_LABEL, 0, 0, 0);
   ObjectSetText(Obj0007, H1_MKT, 40, "Tahoma Narrow",  color_MKTH1);
   ObjectSet(Obj0007, OBJPROP_CORNER, Corner_of_Chart_RIGHT_TOP);
   ObjectSet(Obj0007, OBJPROP_XDISTANCE, Col05x);
   ObjectSet(Obj0007, OBJPROP_YDISTANCE, Col01y); 

          
           ObjectCreate(Obj0008, OBJ_LABEL, 0, 0, 0);
   ObjectSetText(Obj0008, H4_MKT, 40, "Tahoma Narrow",  color_MKTH4);
   ObjectSet(Obj0008, OBJPROP_CORNER, Corner_of_Chart_RIGHT_TOP);
   ObjectSet(Obj0008, OBJPROP_XDISTANCE, Col06x);
   ObjectSet(Obj0008, OBJPROP_YDISTANCE, Col01y);

    
           ObjectCreate(Obj0009, OBJ_LABEL, 0, 0, 0);
   ObjectSetText(Obj0009, D1_MKT, 40, "Tahoma Narrow",  color_MKTD1);
   ObjectSet(Obj0009, OBJPROP_CORNER, Corner_of_Chart_RIGHT_TOP);
   ObjectSet(Obj0009, OBJPROP_XDISTANCE, Col07x);
   ObjectSet(Obj0009, OBJPROP_YDISTANCE, Col01y);
   
    
           ObjectCreate(Obj0010, OBJ_LABEL, 0, 0, 0);
   ObjectSetText(Obj0010, W1_MKT, 40, "Tahoma Narrow",  color_MKTW1);
   ObjectSet(Obj0010, OBJPROP_CORNER, Corner_of_Chart_RIGHT_TOP);
   ObjectSet(Obj0010, OBJPROP_XDISTANCE, Col08x);
   ObjectSet(Obj0010, OBJPROP_YDISTANCE, Col01y);   
   
   
           ObjectCreate(Obj0011, OBJ_LABEL, 0, 0, 0);
   ObjectSetText(Obj0011, MN1_MKT, 40, "Tahoma Narrow",  color_MKTMN1);
   ObjectSet(Obj0011, OBJPROP_CORNER, Corner_of_Chart_RIGHT_TOP);
   ObjectSet(Obj0011, OBJPROP_XDISTANCE, Col09x);
   ObjectSet(Obj0011, OBJPROP_YDISTANCE, Col01y); 
     
   WindowRedraw() ;   
     
     
 //----
   return(0);
  }
//+------------------------------------------------------------------+


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 ColorMKT( string myPair, int myPeriod )  
{


color MA_color;

double MovingBuffer;
double UpperBuffer;
double LowerBuffer;
      
 xUp      = false ; 
 xDn      = false ;   
 bull     = false ;
 bear     = false ;
 ranging  = false ;      
  
    close         = iClose(myPair,myPeriod,0) ;

    MovingBuffer  = iMA(myPair,myPair,MA_Period,Shift,MODE_EMA,PRICE_CLOSE,0);
    UpperBuffer   = MovingBuffer  + (KATR * iATR(myPair,myPair,ATR_Period, Shift));
    LowerBuffer   = MovingBuffer  - (KATR * iATR(myPair,myPair,ATR_Period, Shift));
   
 if( close <= UpperBuffer && close >= LowerBuffer ) { ColorMarket = Blue  ; ranging = true ; tMarket = "Ranging " ; } else
 if( close >  UpperBuffer                         ) { ColorMarket = Green ; bull    = true ; tMarket = "Bull   " ; } else
 if( close <  LowerBuffer                         ) { ColorMarket = Red   ; bear    = true ; tMarket = "Bear   " ; }  
 
 
    
return( ColorMarket ) ;   
                                    
} //  

 
//+------------------------------------------------------------------+
 
string TimeFrameToString(int tf)
{
   string tfs;
   switch(tf) {
      case PERIOD_M1:  tfs="M1"  ; break;
      case PERIOD_M5:  tfs="M5"  ; break;
      case PERIOD_M15: tfs="M15" ; break;
      case PERIOD_M30: tfs="M30" ; break;
      case PERIOD_H1:  tfs="H1"  ; break;
      case PERIOD_H4:  tfs="H4"  ; break;
      case PERIOD_D1:  tfs="D1"  ; break;
      case PERIOD_W1:  tfs="W1"  ; break;
      case PERIOD_MN1: tfs="MN";
   }
   return(tfs);
}

//+------------------------------------------------------------------+

/*
  
while(true)
{    
   
   if( cMKT >= 0 ) 
   {

      if( cMKT > pMKT   && cMKT > cSignal ) { MA_color = colorUpA ; break ; }
      if( cMKT < pMKT   && cMKT > cSignal ) { MA_color = colorDnA ; break ; }
      if( cMKT > cSignal && pMKT < pSignal ) { MA_color = colorXaA ; break ; }  
      if( cMKT < cSignal && pMKT > pSignal ) { MA_color = colorXbA ; break ; } 
      MA_color = DarkGreen ; break ;         
   } else 
   {

      if( cMKT > pMKT   && cMKT > cSignal ) { MA_color = colorUpB ; break ; }
      if( cMKT < pMKT   && cMKT > cSignal ) { MA_color = colorDnB ; break ; }
      if( cMKT > cSignal && pMKT < pSignal ) { MA_color = colorXaB ; break ; }  
      if( cMKT < cSignal && pMKT > pSignal ) { MA_color = colorXbB ; break ; } 
      MA_color = Maroon ; break ; 
               
   }   
   
       break ;
  
} 

*/