//+------------------------------------------------------------------+ 
//|   _TRO_COMPASS_MP                                                | 
//|                                                                  | 
//|   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  myIndColor = DarkGray ;
extern int      myPeriod = PERIOD_H1;

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


//---- indicator buffers 



// int   Chart_Period    = PERIOD_H1;


//---- buffers






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


string tObjName01   ;
string tObjName02   ;
string tObjName03   ;
string tObjName04 , tObjName05, IndHead ;

double open    ;  
double close    ; 
double close1   ;  
double high    ;    
double high1    ;   
double low     ;    
double low1     ; 

double mid      ; 
double mid1    ; 


double pCount   ;

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

string PriceDir   ;

string tPeriod   ; 

string   labelNames;

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

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(tObjName04);
DoDelObj( PERIOD_M1 ) ;
DoDelObj( PERIOD_M5 ) ;
DoDelObj( PERIOD_M15 ) ;  
DoDelObj( PERIOD_H1 ) ;
DoDelObj( PERIOD_H4 ) ;
DoDelObj( PERIOD_D1 ) ;
DoDelObj( PERIOD_W1 ) ;
DoDelObj( PERIOD_MN1 ) ;

   
}  

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

bool sFirst = true ;

if ( sFirst ) {
sFirst = false ;
ObjectDelete(tObjName04);

ObjectsDeleteAll( win, 21);
ObjectsDeleteAll( win, 22);
ObjectsDeleteAll( win, 23);
}


DoHead("PRICE" );

int xStart  = -600 ;
int xOffSet = 100 ;
int xStart2 = xStart + xOffSet ;
int xStart3 = xStart + xOffSet*2 ;
int xStart4 = xStart + xOffSet*3 ;
int xStart5 = xStart + xOffSet*4 ;
int xStart6 = xStart + xOffSet*5 ;
int xStart7 = xStart + xOffSet*6 ;
int xStart8 = xStart + xOffSet*7 ;

DoWork( PERIOD_M1 ) ;
DoShow( PERIOD_M1, xStart ) ;

DoWork( PERIOD_M5 ) ;
DoShow( PERIOD_M5, xStart2 ) ;

DoWork( PERIOD_M15 ) ;
DoShow( PERIOD_M15, xStart3 ) ;                      

DoWork( PERIOD_H1 ) ;
DoShow( PERIOD_H1, xStart4 ) ;

DoWork( PERIOD_H4 ) ;
DoShow( PERIOD_H4, xStart5 ) ;

DoWork( PERIOD_D1 ) ;
DoShow( PERIOD_D1, xStart6 ) ;

DoWork( PERIOD_W1 ) ;
DoShow( PERIOD_W1, xStart7 ) ;

DoWork( PERIOD_MN1 ) ;
DoShow( PERIOD_MN1, xStart8 ) ;

WindowRedraw();    
 


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

void DoWork( int myPeriod  )  
{

open   = iOpen( NULL , myPeriod , 0 ) ;  
close  = iClose( NULL , myPeriod , 0 ) ; 
close1 = iClose( NULL , myPeriod , 1 ) ;  
high   = iHigh( NULL , myPeriod , 0 ) ;    
high1  = iHigh( NULL , myPeriod , 1 ) ;   
low    = iLow( NULL , myPeriod , 0 ) ;    
low1   = iLow( NULL , myPeriod , 1 ) ; 

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


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 ) ;


PriceDir = fCompass( pCount ) ;

// tPeriod  = TimeFrameToString( myPeriod ) ;

}

//+------------------------------------------------------------------+ 
void DoDelObj( int lPeriod  )  
{

tObjName01 = lPeriod +  "COM030" ;
tObjName02 = lPeriod +  "COM031" ;
tObjName03 = lPeriod +  "COM032" ;

ObjectDelete(tObjName01);
ObjectDelete(tObjName02);
ObjectDelete(tObjName03);
}

//+------------------------------------------------------------------+ 
void DoShow( int lPeriod , int xInc )  
{

tObjName01 = lPeriod +  "COM030" ;
tObjName02 = lPeriod +  "COM031" ;
tObjName03 = lPeriod +  "COM032" ;

tPeriod  = TimeFrameToString( lPeriod ) ;

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

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

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

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

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

}

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

void DoHead( string dHead  )  
{

tObjName04 = labelNames +  "COM000" ;

   ObjectCreate(tObjName04, OBJ_LABEL, win, 0, 0);//HiLow LABEL
   ObjectSetText(tObjName04, dHead, 30, "Arial Bold", myIndColor );
   ObjectSet(tObjName04, OBJPROP_CORNER, 0);
   ObjectSet(tObjName04, OBJPROP_XDISTANCE,  00+price.x.offset); // 760
   ObjectSet(tObjName04, OBJPROP_YDISTANCE, 210+price.y.offset); // 160
}

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

