//+------------------------------------------------------------------+ 
//|   _TRO_COMPASS_IND_MP_AB                                         | 
//|                                                                  | 
//|   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_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

extern bool show.arrow = true ;
extern bool show.value = true ;
//extern int  myDecimals = 2 ;

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



//extern int    myPrice    = 0 ;

extern color  myIndColor = DarkGray ;

extern string Ind_Name_1 ="iMA";

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

extern double iParm3 = 240;
extern double iParm4 = 0;
extern double iParm5 = 3;
extern double iParm6 = 0;
extern double iParm7 = 0;
extern double iParm8 = 0;


extern color N_color  = Green;
extern color NE_color = Green;
extern color E_color  = Goldenrod;
extern color SE_color = Red;
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   ; 

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

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

color fColor( double i)
{
color rColor ;

    if ( i == 1 ) rColor = N_color  ; else {
    if ( i == 0 ) rColor = E_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 = -1; 
    else rColor = 0; }
return ( rColor );
}


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


string fCompass( double i )
{
string rCompass ;


    if ( i == 1 ) rCompass = Arrow12  ; else {
    if ( i == 0 ) rCompass = Arrow3  ; else {      
    rCompass = Arrow6 ; } } 
    
return ( rCompass );
}


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

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



   return(0); 
  } 

int deinit() 
{ 
   while (totalLabels>0) { ObjectDelete(StringConcatenate(labelNames,totalLabels)); totalLabels--;}
  
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() 
  { 


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

IndHead =  "Price vs. " + Ind_Name_1 + "("+DoubleToStr(iParm3,0)+")"  ;

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

DoHead(IndHead );

WindowRedraw();    
 


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

void DoWork( int myPeriod  )  
{

double cX, pX ;

while(true)
{

if ( Ind_Name_1=="tMid"  ) { cVal = (iHigh(NULL, myPeriod, 0 ) + iLow(NULL, myPeriod, 0 ) ) * 0.5  ; 
                             pVal = (iHigh(NULL, myPeriod, 1 ) + iLow(NULL, myPeriod, 1 ) ) * 0.5  ;  break;}

if ( Ind_Name_1=="tPrMid"  ) { cVal = (iHigh(NULL, myPeriod, 1 ) + iLow(NULL, myPeriod, 1 ) ) * 0.5  ; 
                             pVal = (iHigh(NULL, myPeriod, 2 ) + iLow(NULL, myPeriod, 2 ) ) * 0.5  ;  break;}


if ( Ind_Name_1=="iOpen"  ) { cVal = iOpen(NULL, myPeriod, iParm3 ); pVal = iOpen(NULL, myPeriod, iParm3+1 ); break;}

if ( Ind_Name_1=="iClose"  ) { cVal = iClose(NULL, myPeriod, iParm3 ); pVal = iClose(NULL, myPeriod, iParm3+1 ); break;}

if ( Ind_Name_1=="iHigh"  ) { cVal = iHigh(NULL, myPeriod, iParm3 ); pVal = iHigh(NULL, myPeriod, iParm3+1 ); break;}

if ( Ind_Name_1=="iLow"  )  { cVal = iLow(NULL, myPeriod, iParm3 );  pVal = iLow(NULL, myPeriod, iParm3+1 ); break;}

if ( Ind_Name_1=="iHighest"  ) { cX = iHighest(NULL, myPeriod, iParm3, iParm4, iParm5 );    cVal = iHigh(NULL, myPeriod, cX ) ;
                                 pX = iHighest(NULL, myPeriod, iParm3, iParm4, iParm5+1 );  pVal = iHigh(NULL, myPeriod, pX );  break;}
                                 
if ( Ind_Name_1=="iLowest"  )  { cX = iLowest(NULL, myPeriod, iParm3, iParm4, iParm5);    cVal = iLow(NULL, myPeriod, cX ) ;
                                 pX = iLowest(NULL, myPeriod, iParm3, iParm4, iParm5+1 ); pVal = iLow(NULL, myPeriod, pX ) ; break;}



if ( Ind_Name_1=="iAC"  ) { cVal = iAC(NULL, myPeriod, 0 ); pVal = iAC(NULL, myPeriod, 1 ); break;}
                            
if ( Ind_Name_1=="iAD"  ) { cVal = iAD(NULL, myPeriod, 0 ); pVal = iAD(NULL, myPeriod, 1 ); break;}
 
if ( Ind_Name_1=="iADX" ) { cVal = iADX(NULL,myPeriod, iParm3, iParm4, iParm5, 0 ) ;  
                            pVal = iADX(NULL,myPeriod, iParm3, iParm4, iParm5, 1 ) ; break;}

if ( Ind_Name_1=="iATR" ) { cVal = iATR(NULL,myPeriod, iParm3,  0 ) ;  
                            pVal = iATR(NULL,myPeriod, iParm3,  1 ) ; break;} 
                            
if ( Ind_Name_1=="iAO" )  { cVal = iAO(NULL,myPeriod, 0 ) ;  
                            pVal = iAO(NULL,myPeriod,  1 ) ; break;} 
                            
if ( Ind_Name_1=="iBearsPower" ) { cVal = iBearsPower(NULL,myPeriod, iParm3, iParm4,  0 ) ;  
                                   pVal = iBearsPower(NULL,myPeriod, iParm3, iParm4,  1 ) ; break;}  

if ( Ind_Name_1=="iBullsPower" ) { cVal = iBullsPower(NULL,myPeriod, iParm3, iParm4,  0 ) ;  
                                   pVal = iBullsPower(NULL,myPeriod, iParm3, iParm4,  1 ) ; break;}  

if ( Ind_Name_1=="iCCI" ) { cVal = iCCI(NULL,myPeriod, iParm3, iParm4,  0 ) ;  
                            pVal = iCCI(NULL,myPeriod, iParm3, iParm4,  1 ) ; break;}  

if ( Ind_Name_1=="iDeMarker" ) { cVal = iDeMarker(NULL,myPeriod, iParm3,  0 ) ;  
                                 pVal = iDeMarker(NULL,myPeriod, iParm3,  1 ) ; break;}  

if ( Ind_Name_1=="iRSI" ) { cVal = iRSI(NULL,myPeriod, iParm3, iParm4,  0 ) ;  
                            pVal = iRSI(NULL,myPeriod, iParm3, iParm4,  1 ) ; break;}  

if ( Ind_Name_1=="iForce" ) { cVal = iForce(NULL,myPeriod, iParm3, iParm4, iParm5, 0 ) ;  
                              pVal = iForce(NULL,myPeriod, iParm3, iParm4, iParm5, 1 ) ; break;}

if ( Ind_Name_1=="iFractals" ) { cVal = iFractals(NULL,myPeriod, iParm3,  0 ) ;  
                                 pVal = iFractals(NULL,myPeriod, iParm3,  1 ) ; break;} 

if ( Ind_Name_1=="iBWMFI" )  { cVal = iBWMFI(NULL,myPeriod, 0 ) ;  
                               pVal = iBWMFI(NULL,myPeriod,  1 ) ; break;} 
                               
if ( Ind_Name_1=="iMomentum" ) { cVal = iMomentum(NULL,myPeriod, iParm3, iParm4,  0 ) ;  
                                 pVal = iMomentum(NULL,myPeriod, iParm3, iParm4,  1 ) ; break;}                                 
                               

if ( Ind_Name_1=="iMFI" ) { cVal = iMFI(NULL,myPeriod, iParm3,  0 ) ;  
                            pVal = iMFI(NULL,myPeriod, iParm3,  1 ) ; break;}                                
                               
if ( Ind_Name_1=="iMA" ) { cVal = iMA(NULL,myPeriod, iParm3, iParm4, iParm5, iParm6, 0 ) ;  
                           pVal = iMA(NULL,myPeriod, iParm3, iParm4, iParm5, iParm6, 1 ) ; break;}
                              
                              
if ( Ind_Name_1=="iOsMA" ) { cVal = iOsMA(NULL,myPeriod, iParm3, iParm4, iParm5, iParm6, 0 ) ;  
                             pVal = iOsMA(NULL,myPeriod, iParm3, iParm4, iParm5, iParm6, 1 ) ; break;}   
                             
                             
if ( Ind_Name_1=="iMACD" ) { cVal = iMACD(NULL,myPeriod, iParm3, iParm4, iParm5, iParm6, iParm7, 0 ) ;  
                             pVal = iMACD(NULL,myPeriod, iParm3, iParm4, iParm5, iParm6, iParm7, 1 ) ; break;}                               
                                                             

if ( Ind_Name_1=="iOBV" ) { cVal = iOBV(NULL,myPeriod, iParm3,  0 ) ;  
                            pVal = iOBV(NULL,myPeriod, iParm3,  1 ) ; break;} 


if ( Ind_Name_1=="iSAR" ) { cVal = iSAR(NULL,myPeriod, iParm3, iParm4,  0 ) ;  
                            pVal = iSAR(NULL,myPeriod, iParm3, iParm4,  1 ) ; break;} 

if ( Ind_Name_1=="iRVI" ) { cVal = iRVI(NULL,myPeriod, iParm3, iParm4,  0 ) ;  
                            pVal = iRVI(NULL,myPeriod, iParm3, iParm4,  1 ) ; break;} 

if ( Ind_Name_1=="iStdDev" ) { cVal = iStdDev(NULL,myPeriod, iParm3, iParm4, iParm5, iParm6, 0 ) ;  
                               pVal = iStdDev(NULL,myPeriod, iParm3, iParm4, iParm5, iParm6, 1 ) ; break;} 
                                                              

if ( Ind_Name_1=="iStochastic" ) { cVal = iStochastic(NULL,myPeriod, iParm3, iParm4, iParm5, iParm6, iParm7, iParm8, 0 ) ;  
                                   pVal = iStochastic(NULL,myPeriod, iParm3, iParm4, iParm5, iParm6, iParm7, iParm8, 1 ) ; break;}                               
                                                             
if ( Ind_Name_1=="iWPR" ) { cVal = iWPR(NULL,myPeriod, iParm3,  0 ) ;  
                            pVal = iWPR(NULL,myPeriod, iParm3,  1 ) ; break;} 
                                
IndHead = "ERROR! NO SUCH INDICATOR"; cVal = -999.99;  break;
}                                
                                                                                                                      
pCount  = fDirection( Close[0] , cVal ) ;

CloseColor = fColor( pCount ) ;

PriceDir = fCompass( pCount ) ;

}

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

tObjName01 = labelNames +lPeriod +  "CIN030" ;
tObjName02 = labelNames +lPeriod +  "CIN031" ;
tObjName03 = labelNames +lPeriod +  "CIN032" ;
//tObjName04 = labelNames +  "CIN000" ;
tObjName05 = labelNames +lPeriod +  "CIN035" ;

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

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

tObjName01 = labelNames +lPeriod +  "CIN030" ;
tObjName02 = labelNames +lPeriod +  "CIN031" ;
tObjName03 = labelNames +lPeriod +  "CIN032" ;
tObjName05 = labelNames +lPeriod +  "CIN035" ;


tPeriod  = TimeFrameToString( lPeriod ) ;

   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){
    
   ObjectCreate(tObjName05, OBJ_LABEL, win, 0, 0);//HiLow LABEL
   ObjectSetText(tObjName05, DoubleToStr(cVal,Digits) ,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 +  "CIN000" ;

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

/*

val=High[iHighest(NULL,0,MODE_HIGH,20,4)];

Constant	Value	Description
MODE_OPEN	0	Open price.
MODE_LOW	   1	Low price.
MODE_HIGH	2	High price.
MODE_CLOSE	3	Close price.
MODE_VOLUME	4	Volume, used in iLowest() and iHighest() functions.
MODE_TIME	5	Bar open time, used in ArrayCopySeries() function.

*/