//+------------------------------------------------------------------+ 
//|   TRO_MM_PAD                                                     | 
//|                                                                  | 
//|   Copyright © 2009, Avery T. Horton, Jr. aka TheRumpledOne       |
//|                                                                  |
//|   PO BOX 43575, TUCSON, AZ 85733                                 |
//|                                                                  |
//|   GIFTS AND DONATIONS ACCEPTED                                   | 
//|   All my indicators should be considered donationware. That is   |
//|   you are free to use them for your personal use, and are        |
//|   under no obligation to pay for them. However, if you do find   |
//|   this or any of my other indicators help you with your trading  |
//|   then any Gift or Donation as a show of appreciation is         |
//|   gratefully accepted.                                           |
//|                                                                  |
//|   Gifts or Donations also keep me motivated in producing more    |
//|   great free indicators. :-)                                     |
//|                                                                  |
//|   PayPal - THERUMPLEDONE@GMAIL.COM                               |  
//+------------------------------------------------------------------+ 
//| Use http://therumpledone.mbtrading.com/fx/ as your forex broker  |  
//| ...tell them therumpledone sent you!                             |  
//+------------------------------------------------------------------+ 


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

#property indicator_chart_window
  
extern bool  Show.Heading = true ;
extern bool  Show.CandleColor   = true ;
extern bool  Show.BuyersSellers = true ;
extern bool  Show.CloseClose1   = true ;

 
extern int  Corner = 1; 
extern int  xAxis  = 0 ;  
extern int  yAxis  = 1 ;


extern color UpColor   = Lime;
extern color DownColor = Red;
extern color FlatColor = Yellow;
extern color TextColor = DodgerBlue;





int tframe[]={1,5,15,30,60,240,1440,10080,43200};

string tf[]={"M1","M5","M15","M30","H1","H4","D1","W1","MN","TOT"};

int tfnumber=9,columns=10 ;  

double cValue, pValue, buyers, sellers, H,C,O,L, candle, DiffCC ;

string TimeFrameStr;
double IndValC[9],IndValD[9],IndVal[9];

int xpos[10], ypos[10];
int w , j , xposTAG, CAN, BS, CC;

string TAG = "PAD"   ;

string ArrowHeadRt =  "Ø" ; // 216 up arrow head
string ArrowHeadUp =  "Ù" ; // 217 up arrow head
string ArrowHeadDn =  "Ú" ; // 218 up arrow head 

string theArrowC[10],theArrowD[10],theArrow[10];
color   theColorC[10], theColorD[10],theColor[10];

//+------------------------------------------------------------------+
int init()
{

deinit();

if(Corner == 1 || Corner == 3)
{ 
   for( w = 0 ; w < columns ; w++) { xpos[w] = 15 + ((10 - w)*23) ; } 
   xposTAG = 270 ;
} 
else
{
   for( w=0;w<columns;w++) { xpos[w] = w*23 + 50 ; }
   xposTAG = 10 ;
}

   if(Show.CandleColor)
   {
         ObjectCreate(TAG+"HD1",OBJ_LABEL,0,0,0,0,0);
         ObjectSet(TAG+"HD1",OBJPROP_CORNER,Corner);
         ObjectSet(TAG+"HD1",OBJPROP_XDISTANCE,xAxis+xposTAG);
         ObjectSet(TAG+"HD1",OBJPROP_YDISTANCE,yAxis+30);
         ObjectSetText(TAG+"HD1","CAN",8,"Tahoma",TextColor);
   } // if
   
   
   if(Show.BuyersSellers)
   {   
         ObjectCreate(TAG+"HD",OBJ_LABEL,0,0,0,0,0);
         ObjectSet(TAG+"HD",OBJPROP_CORNER,Corner);
         ObjectSet(TAG+"HD",OBJPROP_XDISTANCE,xAxis+xposTAG);
         ObjectSet(TAG+"HD",OBJPROP_YDISTANCE,yAxis+50);
         ObjectSetText(TAG+"HD","B/S",8,"Tahoma",TextColor);
   } // if
   
 
   if(Show.CloseClose1)
   {            
         ObjectCreate(TAG+"HD2",OBJ_LABEL,0,0,0,0,0);
         ObjectSet(TAG+"HD2",OBJPROP_CORNER,Corner);
         ObjectSet(TAG+"HD2",OBJPROP_XDISTANCE,xAxis+xposTAG);
         ObjectSet(TAG+"HD2",OBJPROP_YDISTANCE,yAxis+70);
         ObjectSetText(TAG+"HD2","C-C",8,"Tahoma",TextColor);         
   } // if
   
   
   if(Show.Heading)
   {
   for( w=0;w<columns;w++)
      {
         ObjectCreate(TAG+tf[w],OBJ_LABEL,0,0,0,0,0);
         ObjectSet(TAG+tf[w],OBJPROP_CORNER,Corner);
         ObjectSet(TAG+tf[w],OBJPROP_XDISTANCE,xAxis+xpos[w]);
         ObjectSet(TAG+tf[w],OBJPROP_YDISTANCE,yAxis+15);
         ObjectSetText(TAG+tf[w],tf[w],8,"Tahoma",TextColor);                     
      } // for
   } // if

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

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

void ObDeleteObjectsByPrefix(string Prefix)
  {
   int L = StringLen(Prefix);
   int i = 0; 
   while(i < ObjectsTotal())
     {
       string ObjName = ObjectName(i);
       if(StringSubstr(ObjName, 0, L) != Prefix) 
         { 
           i++; 
           continue;
         }
       ObjectDelete(ObjName);
     }
  }
    
//+------------------------------------------------------------------+
int deinit()
  {
        
   ObDeleteObjectsByPrefix(TAG);  
   TRO() ;
   return(0);
  }
  
//+------------------------------------------------------------------+
int start()
  {
   
//----
   

   for( j=0;j<columns ;j++)
   {
      if (ObjectFind(TAG+j) != 0)
      {
   if(Show.CandleColor)
   {      
         ObjectCreate(TAG+j+"C",OBJ_LABEL,0,0,0,0,0);        
         ObjectSet(TAG+j+"C",OBJPROP_CORNER,Corner);
         ObjectSet(TAG+j+"C",OBJPROP_XDISTANCE,xAxis+xpos[j]);
         ObjectSet(TAG+j+"C",OBJPROP_YDISTANCE,yAxis+30);
         ObjectSetText(TAG+j+"C",CharToStr(110),12,"Tahoma",White);
   } // if
   
   
   if(Show.BuyersSellers)
   {                
         ObjectCreate(TAG+j,OBJ_LABEL,0,0,0,0,0);
         ObjectSet(TAG+j,OBJPROP_CORNER,Corner);
         ObjectSet(TAG+j,OBJPROP_XDISTANCE,xAxis+xpos[j]);
         ObjectSet(TAG+j,OBJPROP_YDISTANCE,yAxis+50);
         ObjectSetText(TAG+j,CharToStr(110),12,"Wingdings",White);
         
   } // if
   
 
   if(Show.CloseClose1)
   {          
         ObjectCreate(TAG+j+"D",OBJ_LABEL,0,0,0,0,0);         
         ObjectSet(TAG+j+"D",OBJPROP_CORNER,Corner);
         ObjectSet(TAG+j+"D",OBJPROP_XDISTANCE,xAxis+xpos[j]);
         ObjectSet(TAG+j+"D",OBJPROP_YDISTANCE,yAxis+70);
         ObjectSetText(TAG+j+"D",CharToStr(110),12,"Tahoma",White);              
   } // if         
         
   }// if
   } // for

     CAN = 0;
     BS  = 0;
     CC  = 0;
           
   for(int x=0;x<tfnumber;x++)
   {
         
        O = iOpen(NULL, tframe[x], 0 ) ;
        H = iHigh(NULL, tframe[x], 0 ) ;
        L = iLow(NULL, tframe[x], 0 ) ;
        C = iClose(NULL, tframe[x], 0 ) ;
        
        candle  = C - O ;
        
        DiffCC  = C - iClose(NULL, tframe[x], 1 ) ;
            
        buyers  = C - L ;
        sellers = H - C ;    
            
        if (buyers > sellers)
        {
         IndVal[x]   = 1;
         theArrow[x] = ArrowHeadUp ;
         theColor[x] = UpColor ;
        }
        else if (buyers < sellers)
        {
         IndVal[x]   = -1;
         theArrow[x] = ArrowHeadDn ;
         theColor[x] = DownColor ;         
        }
        else 
        {
         IndVal[x]   = 0;
         theArrow[x] = ArrowHeadRt ;
         theColor[x] = FlatColor ;
        }
        
        
       if (candle > 0)
        {
         IndValC[x]   = 1;
         theArrowC[x] = ArrowHeadUp ;
         theColorC[x] = UpColor ;
        }
        else if (candle < 0)
        {
         IndValC[x]   = -1;
         theArrowC[x] = ArrowHeadDn ;
         theColorC[x] = DownColor ;         
        }
        else 
        {
         IndValC[x]   = 0;
         theArrowC[x] = ArrowHeadRt ;
         theColorC[x] = FlatColor ;
        }        
        
        if (DiffCC > 0)
        {
         IndValD[x]   = 1;
         theArrowD[x] = ArrowHeadUp ;
         theColorD[x] = UpColor ;
        }
        else if (DiffCC < 0)
        {
         IndValD[x]   = -1;
         theArrowD[x] = ArrowHeadDn ;
         theColorD[x] = DownColor ;         
        }
        else 
        {
         IndValD[x]   = 0;
         theArrowD[x] = ArrowHeadRt ;
         theColorD[x] = FlatColor ;
        }        
           
           CAN = CAN + IndValC[x] ;
           BS  = BS  + IndVal[x]  ;
           CC  = CC  + IndValD[x] ;      
                  
   } // for


 
        if (BS > 0 )
        {
         theArrow[9] = ArrowHeadUp ;
         theColor[9] = UpColor ;
        }
        else if (BS <  0 )
        {
         theArrow[9] = ArrowHeadDn ;
         theColor[9] = DownColor ;         
        }
        else 
        {
         theArrow[9] = ArrowHeadRt ;
         theColor[9] = FlatColor ;
        } 
 
 
        if (CC > 0 )
        {
         theArrowD[9] = ArrowHeadUp ;
         theColorD[9] = UpColor ;
        }
        else if (CC <  0 )
        {
         theArrowD[9] = ArrowHeadDn ;
         theColorD[9] = DownColor ;         
        }
        else 
        {
         theArrowD[9] = ArrowHeadRt ;
         theColorD[9] = FlatColor ;
        } 

        if (CAN > 0 )
        {
         theArrowC[9] = ArrowHeadUp ;
         theColorC[9] = UpColor ;
        }
        else if (CAN <  0 )
        {
         theArrowC[9] = ArrowHeadDn ;
         theColorC[9] = DownColor ;         
        }
        else 
        {
         theArrowC[9] = ArrowHeadRt ;
         theColorC[9] = FlatColor ;
        }         
           
      for(int  y=0;y<columns;y++)
      { 
         if(Show.BuyersSellers) {ObjectSetText(TAG+y,theArrow[y],12,"Wingdings",theColor[y]);}
         if(Show.CandleColor)   {ObjectSetText(TAG+y+"C",theArrowC[y],12,"Wingdings",theColorC[y]);}
         if(Show.CloseClose1)   {ObjectSetText(TAG+y+"D",theArrowD[y],12,"Wingdings",theColorD[y]);}
      }  


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

//+------------------------------------------------------------------+  
void TRO()
{   
   
   string tObjName03    = "TROTAG"  ;  
   ObjectCreate(tObjName03, OBJ_LABEL, 0, 0, 0);//HiLow LABEL
   ObjectSetText(tObjName03, CharToStr(78) , 12 ,  "Wingdings",  DimGray );
   ObjectSet(tObjName03, OBJPROP_CORNER, 3);
   ObjectSet(tObjName03, OBJPROP_XDISTANCE,xAxis+ 5 );
   ObjectSet(tObjName03, OBJPROP_YDISTANCE, 5 );  
}


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

/*
Comment(
"CC " , CC , "\n" ,
"BS " , BS , "\n" ,
"CAN " , CAN , "\n" ,
 


"") ; 

Comment(
"buyers " , DoubleToStr(buyers,Digits) , "\n" ,
"sellers " , DoubleToStr(sellers,Digits) , "\n" ,
"candle " , DoubleToStr(candle,Digits) , "\n" ,
"DiffCC " , DoubleToStr(DiffCC,Digits) , "\n" ,


"") ; 

*/