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

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

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



//---- indicator parameters  
 

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

string mytfs = "time frames to use" ;
extern int    myTimeFrame_Col1  = 0 ;
extern int    myTimeFrame_Col2  = 0 ;
extern int    myTimeFrame_Col3  = 0 ;
extern int    myTimeFrame_Col4  = 0 ;
extern int    myTimeFrame_Col5  = 0 ;
extern int    myTimeFrame_Col6  = 0 ;
extern int    myTimeFrame_Col7  = 0 ;
extern int    myTimeFrame_Col8  = 0 ;


string mypers = "bars ago for time frame" ;
extern int    myBarsAgo_Col1  = 5 ;
extern int    myBarsAgo_Col2  = 8 ;
extern int    myBarsAgo_Col3  = 13 ;
extern int    myBarsAgo_Col4  = 21 ;
extern int    myBarsAgo_Col5  = 34 ;
extern int    myBarsAgo_Col6  = 55 ;
extern int    myBarsAgo_Col7  = 89 ;
extern int    myBarsAgo_Col8  = 144 ;


extern bool show.arrow = true ;
extern bool show.value = true ;
 

extern string myFont       = "Arial Bold" ;
extern int    myFontSize   = 20 ;
extern int    myArrowSize  = 40 ;
extern int    myDigitSize  = 20 ;
extern int    xStart       = -800 ;
extern int    xOffSet      = 100 ;



extern string myName     ="Jacko Trend";
extern color  myIndColor = DarkGray ;

//extern double iParm1 = 0;
//extern double iParm2 = 0;


extern bool   UseValue = false;
extern double N_value  = -999;
extern double NE_value = 2;
extern double E_value  = 3;
extern double SE_value = 1;
extern double S_value  = -999;

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

//---- 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 , symbol  ; 

double cVal, pVal ;

//+------------------------------------------------------------------+
int      totalLabels;
string   labelNames;
int      corner;
int      window; 
string   shortName ;
int      win ;
//+------------------------------------------------------------------+

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

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

color fColor( double i)
{
color rColor ;

    if ( i == 1 ) rColor = NE_color  ; else {
    if ( i == 0 ) rColor = E_color  ; else {     
    rColor = SE_color ; } } 

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

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

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


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


string fCompass( double i )
{
string rCompass ;


    if ( i == 1 ) rCompass = Arrow2  ; else {
    if ( i == 0 ) rCompass = Arrow3  ; else {      
    rCompass = Arrow5 ; } } 
    
return ( rCompass );
}


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

int init() 
  { 
   shortName  = MakeUniqueName("JT ","");
   labelNames = shortName;
   IndicatorShortName(shortName);
   totalLabels     = 0;

   symbol = Symbol() ;
   
   if( myTimeFrame_Col1 == 0 ) {myTimeFrame_Col1 = Period() ; }
   if( myTimeFrame_Col2 == 0 ) {myTimeFrame_Col2 = Period() ; }  
   if( myTimeFrame_Col3 == 0 ) {myTimeFrame_Col3 = Period() ; }
   if( myTimeFrame_Col4 == 0 ) {myTimeFrame_Col4 = Period() ; } 
   if( myTimeFrame_Col5 == 0 ) {myTimeFrame_Col5 = Period() ; }
   if( myTimeFrame_Col6 == 0 ) {myTimeFrame_Col6 = Period() ; }  
   if( myTimeFrame_Col7 == 0 ) {myTimeFrame_Col7 = Period() ; }
   if( myTimeFrame_Col8 == 0 ) {myTimeFrame_Col8 = Period() ; }    
      
   return(0); 
  } 

int deinit() 
{ 
   while (totalLabels>0) { ObjectDelete(StringConcatenate(labelNames,totalLabels)); totalLabels--;}
  

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

   
}  

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

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 ;

win =    WindowFind(shortName);

bool sFirst = true ;

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

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


DoHead( myName );

DoWork( symbol, myTimeFrame_Col1, myBarsAgo_Col1 ) ;
DoShow( myTimeFrame_Col1, xStart, myBarsAgo_Col1  ) ;

DoWork( symbol, myTimeFrame_Col2, myBarsAgo_Col2 ) ;
DoShow( myTimeFrame_Col2, xStart2, myBarsAgo_Col2  ) ;
 
DoWork( symbol, myTimeFrame_Col3, myBarsAgo_Col3 ) ;
DoShow( myTimeFrame_Col3, xStart3, myBarsAgo_Col3 ) ;
 
DoWork( symbol, myTimeFrame_Col4, myBarsAgo_Col4) ;
DoShow( myTimeFrame_Col4, xStart4, myBarsAgo_Col4) ;

DoWork( symbol, myTimeFrame_Col5, myBarsAgo_Col5 ) ;
DoShow( myTimeFrame_Col5, xStart5, myBarsAgo_Col5  ) ;

DoWork( symbol, myTimeFrame_Col6, myBarsAgo_Col6 ) ;
DoShow( myTimeFrame_Col6, xStart6, myBarsAgo_Col6 ) ;

DoWork( symbol, myTimeFrame_Col7, myBarsAgo_Col7 ) ;
DoShow( myTimeFrame_Col7, xStart7, myBarsAgo_Col7 ) ;

DoWork( symbol, myTimeFrame_Col8, myBarsAgo_Col8 ) ;
DoShow( myTimeFrame_Col8, xStart8, myBarsAgo_Col8  ) ;

 
WindowRedraw();    
 


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

void DoWork( string myPair, int myPeriod, int mybarsago  )  
{

//      double price = iClose(myPair,myPeriod,0);
      
cVal  = iOpen(myPair,myPeriod,mybarsago);
 
                                                                                                                     
pCount  = fDirection( Close[0] , cVal ) ;

CloseColor = fColor( pCount ) ;


PriceDir = fCompass( pCount ) ;


}


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

tObjName01 = labelNames +lPeriod +  "XTN950" + mybarsago ;
tObjName02 = labelNames +lPeriod +  "XTN951" + mybarsago ;
tObjName03 = labelNames +lPeriod +  "XTN952" + mybarsago ;
tObjName05 = labelNames +lPeriod +  "XTN955" + mybarsago ;


tPeriod  =  TimeFrameToString(lPeriod )+ "("+ mybarsago +")" ;

   ObjectCreate(tObjName01, OBJ_LABEL, win, 0, 0);//HiLow LABEL
   ObjectSetText(tObjName01, tPeriod, myFontSize, myFont, CloseColor );
   ObjectSet(tObjName01, OBJPROP_CORNER, 0);
   ObjectSet(tObjName01, OBJPROP_XDISTANCE,  xInc+980+price.x.offset); // 760
   ObjectSet(tObjName01, OBJPROP_YDISTANCE, 175+price.y.offset); // 160

int sInc = 0 ;

if(show.arrow){

sInc = 50 ;
   
   ObjectCreate(tObjName03, OBJ_LABEL, win, 0, 0);//HiLow LABEL
   ObjectSetText(tObjName03, PriceDir , myArrowSize , "Wingdings" , CloseColor );
   ObjectSet(tObjName03, OBJPROP_CORNER, 0);
   ObjectSet(tObjName03, OBJPROP_XDISTANCE, xInc+980+price.x.offset); // 765
   ObjectSet(tObjName03, OBJPROP_YDISTANCE, 210+price.y.offset); 
   
} //if(show.arrow)


if(show.value){
    
double sVal = (Close[0] - cVal) / Point ;
    
   ObjectCreate(tObjName05, OBJ_LABEL, win, 0, 0);//HiLow LABEL
   ObjectSetText(tObjName05, DoubleToStr(sVal,0) ,myDigitSize, myFont , CloseColor );
   ObjectSet(tObjName05, OBJPROP_CORNER, 0);
   ObjectSet(tObjName05, OBJPROP_XDISTANCE, xInc+980+price.x.offset); // 765
   ObjectSet(tObjName05, OBJPROP_YDISTANCE, sInc+210+price.y.offset); 
} //if(show.value)



}

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

void DoHead( string dHead  )  
{

tObjName04 = labelNames +  "XIN900" ;

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

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


// string next() { totalLabels++; return(totalLabels); }  

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

 
string MakeUniqueName(string first, string rest)
{
   string result = first+(MathRand()%1001)+rest;

   while (WindowFind(result)> 0)
          result = first+(MathRand()%1001)+rest;
   return(result);
}