//+------------------------------------------------------------------+ 
//|   _TRO_COMPASS_EZ                                                | 
//|                                                                  | 
//|   Copyright © 2008, Avery T. Horton, Jr. aka TheRumpledOne       |
//|                                                                  |
//|   PO BOX 43575, TUCSON, AZ 85733                                 |
//|                                                                  |
//|   GIFTS AND DONATIONS ACCEPTED                                   | 
//|                                                                  |
//|   therumpldone@gmail.com                                         |  
//+------------------------------------------------------------------+ 

#property  copyright "Copyright © 2008, Avery T. Horton, Jr. aka TRO" 
#property  link      "http://www.therumpldone.com/" 

//---- indicator settings 
#property indicator_chart_window
#property indicator_buffers 0
#property indicator_minimum 0
#property indicator_maximum 1



//---- indicator parameters  
 

extern int win = 0;
extern int price.x.offset= 0 ;//250
extern int price.y.offset= -160 ;//-160


extern color N_color  = Lime;
extern color NE_color = LimeGreen;
extern color E_color  = Yellow;
extern color SE_color = Orange;
extern color S_color  = Red;


//---- indicator buffers 


double     MaxRange = 0 ; 
double     MinRange = 0 ; 
double     AvgRange = 0 ; 
double     xRange   = 0 ; 
double     tRange   = 0 ; 

 int   Chart_Period    = PERIOD_H1;


//---- buffers


double zRANGE = 0;

bool  show.info       = true;
bool  ShowChart       = true; 



string Arrow12 = "ñ"; // 12 oclock
string Arrow2  = "ö";  // 2 oclock
string Arrow3  = "ð";  // 3 oclock
string Arrow5  = "ø";  // 5 oclock
string Arrow6  = "ò";  // 6 oclock

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

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="MN1";
   }
   return(tfs);
}

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

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

color fColor( double i)
{
color rColor ;

    if ( i == 6 ) rColor = N_color ; else {
    if ( i >= 4 ) rColor = NE_color  ; else {
    if ( i == 3 ) rColor = E_color  ; else {    
    if ( i >= 1 ) rColor = SE_color  ; else {    
    rColor = S_color ; } } } }

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

int fDirection( double i, double j)
{
int rColor ;

    if ( i > j ) rColor = 1; 
    else {
    if ( i < j )  rColor = 0; 
    else rColor = 0; }
return ( rColor );
}


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


string fCompass( double i )
{
string rCompass ;

    if ( i == 6 ) rCompass = Arrow12 ; else {
    if ( i >= 4 ) rCompass = Arrow2  ; else {
    if ( i == 3 ) rCompass = Arrow3  ; else {    
    if ( i >= 1 ) rCompass = Arrow5  ; else {    
    rCompass = Arrow6 ; } } } }
    
    
return ( rCompass );
}


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


//+------------------------------------------------------------------+ 
//| Custom indicator initialization function                         | 
//+------------------------------------------------------------------+ 
int init() 
  { 

   return(0); 
  } 

int deinit() 
{ 

   
   ObjectDelete("CMP030");
   ObjectDelete("CMP029");
   ObjectDelete("CMP029B");
   ObjectDelete("CMP031");
   ObjectDelete("CMP032");
   ObjectDelete("CMP034");   
   
   ObjectDelete("CMP130");
   ObjectDelete("CMP129");
   ObjectDelete("CMP129B");
   ObjectDelete("CMP131");
   ObjectDelete("CMP132");
   ObjectDelete("CMP134");   
}  

//+------------------------------------------------------------------+ 
//| Range                                                            | 
//+------------------------------------------------------------------+ 
int start() 
  { 

double open   = Open[0] ; 
double close  = Close[0] ; 
double close1 = Close[1] ; 
double high   = High[0] ; 
double high1  = High[1] ;
double low    = Low[0] ; 
double low1   = Low[1] ;

double mid    = ( high + low )   * 0.50 ; 
double mid1   = ( high1 + low1 ) * 0.50 ; 


double pCount = 0 ;

int   HighDir, LowDir, MidDir, Mid1Dir, CloseDir, ClOpDir ;
color HighColor, LowColor, MidColor, Mid1Color, CloseColor ;

HighDir  = fDirection( high, high1 ) ;
LowDir   = fDirection( low, low1 ) ;
MidDir   = fDirection( close, mid ) ;
Mid1Dir  = fDirection( close, mid1 ) ;
CloseDir = fDirection( close, close1 ) ;
ClOpDir  = fDirection( close, open ) ;

pCount   =  HighDir + LowDir + MidDir + Mid1Dir + CloseDir + ClOpDir  ;

CloseColor = fColor( pCount ) ;


string PriceDir = fCompass( pCount ) ;

string tPeriod  = TimeFrameToString( Period() ) ;


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

   ObjectCreate("CMP030", OBJ_LABEL, win, 0, 0);//HiLow LABEL
   ObjectSetText("CMP030",tPeriod + " PRICE", 30, "Arial Bold", CloseColor );
   ObjectSet("CMP030", OBJPROP_CORNER, 0);
   ObjectSet("CMP030", OBJPROP_XDISTANCE, 780+price.x.offset); // 760
   ObjectSet("CMP030", OBJPROP_YDISTANCE, 160+price.y.offset); // 160
   

//+------------------------------------------------------------------+ 
/*                     
   ObjectCreate("CMP029", OBJ_LABEL, win, 0, 0);//HiLow LABEL
   ObjectSetText("CMP029",DoubleToStr(high, Digits ), 15, "Arial Bold", HighColor );
   ObjectSet("CMP029", OBJPROP_CORNER, 0);
   ObjectSet("CMP029", OBJPROP_XDISTANCE, 770+price.x.offset);
   ObjectSet("CMP029", OBJPROP_YDISTANCE, 197+price.y.offset);
 
   ObjectCreate("CMP129", OBJ_LABEL, win, 0, 0);//HiLow LABEL
   ObjectSetText("CMP129",HighDir, 15, "Wingdings" , HighColor );
   ObjectSet("CMP129", OBJPROP_CORNER, 0);
   ObjectSet("CMP129", OBJPROP_XDISTANCE, 835+price.x.offset);
   ObjectSet("CMP129", OBJPROP_YDISTANCE, 197+price.y.offset);   

//+------------------------------------------------------------------+ 
 
   
   ObjectCreate("CMP029b", OBJ_LABEL, win, 0, 0);//HiLow LABEL
   ObjectSetText("CMP029b",DoubleToStr( low ,  Digits ), 15, "Arial Bold", LowColor );
   ObjectSet("CMP029b", OBJPROP_CORNER, 0);
   ObjectSet("CMP029b", OBJPROP_XDISTANCE, 770+price.x.offset);
   ObjectSet("CMP029b", OBJPROP_YDISTANCE, 260+price.y.offset);                                      
   
   ObjectCreate("CMP129b", OBJ_LABEL, win, 0, 0);//HiLow LABEL
   ObjectSetText("CMP129b",LowDir , 15, "Wingdings" , LowColor );
   ObjectSet("CMP129b", OBJPROP_CORNER, 0);
   ObjectSet("CMP129b", OBJPROP_XDISTANCE, 835+price.x.offset);
   ObjectSet("CMP129b", OBJPROP_YDISTANCE, 260+price.y.offset);                 
*/
//+------------------------------------------------------------------+ 
                     
   ObjectCreate("CMP031", OBJ_LABEL, win, 0, 0);//HiLow LABEL
   ObjectSetText("CMP031",DoubleToStr(close, Digits ), 40, "Arial Bold", CloseColor );
   ObjectSet("CMP031", OBJPROP_CORNER, 0);
   ObjectSet("CMP031", OBJPROP_XDISTANCE, 765+price.x.offset); // 765
   ObjectSet("CMP031", OBJPROP_YDISTANCE, 210+price.y.offset); 

   ObjectCreate("CMP131", OBJ_LABEL, win, 0, 0);//HiLow LABEL
   ObjectSetText("CMP131", PriceDir , 40 , "Wingdings" , CloseColor );
   ObjectSet("CMP131", OBJPROP_CORNER, 0);
   ObjectSet("CMP131", OBJPROP_XDISTANCE, 930+price.x.offset); // 765
   ObjectSet("CMP131", OBJPROP_YDISTANCE, 210+price.y.offset); 

//+------------------------------------------------------------------+           
/* 
   ObjectCreate("CMP032", OBJ_LABEL, win, 0, 0);   // 
   ObjectSetText("CMP032",DoubleToStr( mid ,  Digits ), 15, "Arial Bold", MidColor ); // RANGEBuffer2[0] buf0[0]
   ObjectSet("CMP032", OBJPROP_CORNER, 0);
   ObjectSet("CMP032", OBJPROP_XDISTANCE, 860+price.x.offset);
   ObjectSet("CMP032", OBJPROP_YDISTANCE, 197+price.y.offset);
   
   ObjectCreate("CMP132", OBJ_LABEL, win, 0, 0);   // 
   ObjectSetText("CMP132", MidDir , 15, "Wingdings"  , MidColor ); // RANGEBuffer2[0] buf0[0]
   ObjectSet("CMP132", OBJPROP_CORNER, 0);
   ObjectSet("CMP132", OBJPROP_XDISTANCE, 925+price.x.offset);
   ObjectSet("CMP132", OBJPROP_YDISTANCE, 197+price.y.offset);

//+------------------------------------------------------------------+ 
                                      
   ObjectCreate("CMP034", OBJ_LABEL, win, 0, 0);
   ObjectSetText("CMP034",DoubleToStr( mid1 , Digits ), 15, "Arial Bold", Mid1Color );
   ObjectSet("CMP034", OBJPROP_CORNER, 0);
   ObjectSet("CMP034", OBJPROP_XDISTANCE, 860+price.x.offset);
   ObjectSet("CMP034", OBJPROP_YDISTANCE, 260+price.y.offset); 
      
   ObjectCreate("CMP134", OBJ_LABEL, win, 0, 0);
   ObjectSetText("CMP134", Mid1Dir , 15,  "Wingdings" , Mid1Color );
   ObjectSet("CMP134", OBJPROP_CORNER, 0);
   ObjectSet("CMP134", OBJPROP_XDISTANCE, 925+price.x.offset);
   ObjectSet("CMP134", OBJPROP_YDISTANCE, 260+price.y.offset);  
//+------------------------------------------------------------------+ 
*/                        

   WindowRedraw();    
 
//} 

   return(0); 
} 
 