//+------------------------------------------------------------------+ 
//|   TRO_MPMM_CandleColor                                           | 
//|                                                                  | 
//|   Copyright � 2008, 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                               |  
//+------------------------------------------------------------------+  
 

//----
#property indicator_chart_window

extern int myChartX   = 500 ;
extern int myChartY   = 0 ;
extern int myCorner   = 0 ;
extern string myFont  = "Courier" ;
extern int myFontSize = 12 ;
extern color colorHead  = DarkGray ;
 

extern string noteTimeNY   = " 14:00 server time = 05:00 mst" ; 
extern string noteTimeAU   = " 23:00 server time = 14:00 mst" ; 
extern string noteTimeLD   = " 09:00 server time = 00:00 mst" ; 
extern string myHHMM       = "13:00" ; // 05:00 am pst = 14:00 server time 
extern string myMessage    = "NY" ; 

extern string Symbols      = "AUDJPY;AUDUSD;EURGBP;EURJPY;EURUSD;GBPCHF;GBPJPY;GBPUSD;NZDUSD;USDCAD;USDCHF;USDJPY" ;

extern int myPeriod  = 0 ;
extern int BarsAgo = 0 ;

extern bool Arrows.On = true ;



string symbol, tChartPeriod, ShortName ;  

int     digits, period, win, digits2, n, j, i, k; 
 

double point, point2, value ;
string lbl[15], lbl2[15];

 
//---- PipsToOpen
string Indicator_Name = "MPMMCC:" ;
int Objs = 0;

//+------------------------------------------------------------------+ 
int     ind_bufferOp[] ;
string shortName ;
int    cpairsLenH;
int    cpairsLenV;
int    shortLength;
int    ctimesLen;
string cpairsh[];
string cpairsv[];
int    aTimes[];
string addition  = "";
string pArrow[5] ;
color  pColor[5] ;
 
string ArrowHeadRt =  "�" ; // 216 up arrow head
string ArrowHeadUp =  "�" ; // 217 up arrow head
string ArrowHeadDn =  "�" ; // 218 up arrow head 
 

string ArrowN  = "�"; // NORTH
string ArrowNE = "�";  // NORTHEAST
string ArrowE  = "�";  // EAST
string ArrowSE = "�";  // SOUTHEAST
string ArrowS  = "�";  // SOUTH
 
string D1Arrow ; 
color  D1Color ; 


int ArrowNumber[5]; 
 
double open, close, diff, spread, DailyOpen ; 
 
color colorPair ; 
 
 
 
//+------------------------------------------------------------------+
int init()
  {
  
   if(Symbols == "") { Symbols = Symbol() ; }

   if(myPeriod == 0) { period = Period() ; } else { period = myPeriod ; }  
   
   tChartPeriod =  TimeFrameToString(period) ;
   symbol       =  Symbol() ;
   digits       =  Digits ;
   point        =  Point ;
   ShortName    =  tChartPeriod + " MPCC(" + BarsAgo + ")" ;
   win          =  0 ;

   if(digits == 5 || digits == 3) { digits2 = 0 ; point = point * 10 ; } else { digits2 = 0 ; }

   setUpStrings(cpairsh,cpairsLenH,Symbols);

   if (IsMini())   addition="m";
   if (IsDoubleDotted()) addition="..";
   else 
      if (IsDotted()) addition=".";
      shortName   = ShortName ;
      shortLength = StringLen(shortName);
      IndicatorShortName(shortName);
/*
ArrowNumber[0]= "�"; // 139
ArrowNumber[1]= "�";
ArrowNumber[2]= "?";
ArrowNumber[3]= "�";
ArrowNumber[4]= "?";
*/

ArrowNumber[0]= 139; // 139
ArrowNumber[1]= 140;
ArrowNumber[2]= 141;
ArrowNumber[3]= 142;
ArrowNumber[4]= 237;
   return(0);
  }
 
//+------------------------------------------------------------------+
int deinit()
  {
//----
   for(int i = 0; i < Objs; i++)
     {
      if(!ObjectDelete(Indicator_Name + i))
          Print("error: code #", GetLastError());
     }
     
ObjectsDeleteAll();     
//----
   return(0);
  }
 
//+------------------------------------------------------------------+
int start()
{

RefreshRates();

n       = 10;
 
j       = 0 ;

lbl[j]  = ShortName+j;
lbl2[j] = tChartPeriod + " Color   3.2.1.0  +/-"   ;
DoShowHead(j, colorHead);

//----    

for (k = 0; k < cpairsLenH; k++)
{
string symbol = cpairsh[k]+addition;
  
      
digits = MarketInfo(symbol,MODE_DIGITS) ; 
point  = MarketInfo(symbol,MODE_POINT) ;       
spread = MarketInfo(symbol,MODE_SPREAD) ; 
            
if(digits == 5 || digits == 3) { digits2 = 0 ; point = point * 10 ; } else { digits2 = 0 ; }
         
double value = (iClose(symbol, myPeriod ,0) - iOpen(symbol, myPeriod , BarsAgo) )/ point ;
 
j       = j + 1 ;
lbl[j]  = ShortName+j;
lbl2[j] = symbol ;
DoColor( symbol ) ; 
DoShow(j, colorPair); 
  
} // FOR


j       = j + 1 ;
lbl[j]  = ShortName+j;
lbl2[j] = "D1 started " + myHHMM ;
if(j == 2) { lbl2[j] = lbl2[j] + " " + DoubleToStr(DailyOpen,Digits) ; }
DoShowHead(j, colorHead);

WindowRedraw() ;   

   return(0);
}
//+------------------------------------------------------------------+
  
void DoShowHead( int u, color dsColor  )
{

ObjectCreate(lbl[u],23,0,Time[0],PRICE_CLOSE);
ObjectSet(lbl[u], OBJPROP_CORNER, myCorner );
ObjectSet(lbl[u],OBJPROP_XDISTANCE, myChartX);
ObjectSet(lbl[u],OBJPROP_YDISTANCE,n+myChartY);
ObjectSetText(lbl[u],lbl2[u],myFontSize,myFont,dsColor);


n = n+20;


  }  

//+------------------------------------------------------------------+
  
void DoShow( int u, color dsColor  )
{

ObjectCreate(lbl[u],23,0,Time[0],PRICE_CLOSE);
ObjectSet(lbl[u], OBJPROP_CORNER, myCorner );
ObjectSet(lbl[u],OBJPROP_XDISTANCE, myChartX);
ObjectSet(lbl[u],OBJPROP_YDISTANCE,n+myChartY);
ObjectSetText(lbl[u],lbl2[u],myFontSize,myFont,dsColor);

if(u > 0)
{

string sSpread = DoubleToStr( spread , 0 ) ;
         
ObjectCreate(lbl[u]+"SPR",23,0,Time[0],PRICE_CLOSE);
ObjectSet(lbl[u]+"SPR", OBJPROP_CORNER, myCorner );
ObjectSet(lbl[u]+"SPR",OBJPROP_XDISTANCE,80+ myChartX);
ObjectSet(lbl[u]+"SPR",OBJPROP_YDISTANCE,n+myChartY);
ObjectSetText(lbl[u]+"SPR",sSpread,myFontSize,myFont,dsColor);      

for( int d=3; d>=0; d--)
{  
   string Lname = lbl[u]+u+d ;
   ObjectDelete(Lname);
   ObjectCreate(Lname, 23,0,Time[0],PRICE_CLOSE);
   ObjectSetText(Lname, pArrow[d], 12, "WingDings",  pColor[d]);
   ObjectSet(Lname, OBJPROP_CORNER, myCorner);
   ObjectSet(Lname, OBJPROP_XDISTANCE, myChartX+150-(d*15) );
   ObjectSet(Lname, OBJPROP_YDISTANCE, n+myChartY); 
}    

     Lname = lbl[u]+"D1" ;
   ObjectDelete(Lname);
   ObjectCreate(Lname, 23,0,Time[0],PRICE_CLOSE);
   ObjectSetText(Lname, D1Arrow, 12, "WingDings", D1Color );
   ObjectSet(Lname, OBJPROP_CORNER, myCorner);
   ObjectSet(Lname, OBJPROP_XDISTANCE, 60+myChartX );
   ObjectSet(Lname, OBJPROP_YDISTANCE, n+myChartY);   
  

string sDiff = DoubleToStr( diff , 0 ) ;
         
ObjectCreate(lbl[u]+"DIF",23,0,Time[0],PRICE_CLOSE);
ObjectSet(lbl[u]+"DIF", OBJPROP_CORNER, myCorner );
ObjectSet(lbl[u]+"DIF",OBJPROP_XDISTANCE,180+ myChartX);
ObjectSet(lbl[u]+"DIF",OBJPROP_YDISTANCE,n+myChartY);
ObjectSetText(lbl[u]+"DIF",sDiff,myFontSize,myFont,pColor[0]);       
   
}


n = n+20;


  }  
//+------------------------------------------------------------------+
  
void DoColor( string dsSymbol )
{

   DoDailyOpen(dsSymbol) ;
   
   close = iClose(dsSymbol,0,0);   
   diff  = (close - DailyOpen ) / point ;

   if(close > DailyOpen ) { D1Color = Lime ;   D1Arrow = ArrowN ;} else {
   if(close < DailyOpen ) { D1Color = Red ;    D1Arrow = ArrowS ;} else { 
                            D1Color = Yellow ; D1Arrow = ArrowE ;} } 

for( int d=4; d>=0; d--)
{

   open  = iOpen(dsSymbol,myPeriod,d);
   close = iClose(dsSymbol,myPeriod,d);   
   diff  = (close - open) / point ;

if(Arrows.On)
{
   if(close > open ) { pColor[d] = Lime ;   pArrow[d] = ArrowHeadUp ; } else {
   if(close < open ) { pColor[d] = Red ;    pArrow[d] = ArrowHeadDn ;} else { 
                       pColor[d] = Yellow ; pArrow[d] = ArrowHeadRt ;} } 
}

else
{
   if(close > open ) { pColor[d] = Lime ;   } else {
   if(close < open ) { pColor[d] = Red ;    } else { 
                       pColor[d] = Yellow ; } } 
                 
   pArrow[d] =  CharToStr(ArrowNumber[d]) ; 
}

} // for



if( pColor[1] == pColor[2] && pColor[2] == pColor[3] ) {colorPair = pColor[3] ; } else  {colorPair = colorHead ; }

} // void 

//+------------------------------------------------------------------+ 140 - 144
void drawLabel(string name,double lvl,color Color)
{
    if(ObjectFind(name) != 0)
    {
        ObjectCreate(name, OBJ_TEXT, 0, Time[10], lvl);
        ObjectSetText(name, name, myFontSize, myFont , EMPTY);
        ObjectSet(name, OBJPROP_COLOR, Color);
    }
    else
    {
        ObjectMove(name, 0, Time[10], lvl);
    }
}

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

bool   IsMini()         { return(StringFind(Symbol(),"m")  > -1); }

bool   IsDoubleDotted() { return(StringFind(Symbol(),"..") > -1); }

bool   IsDotted()       { return(StringFind(Symbol(),".")  > -1); }
  
//+------------------------------------------------------------------+
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);
}


//+------------------------------------------------------------------+
string StringUpperCase(string str)
{
   string   s = str;
   int      lenght = StringLen(str) - 1;
   int      char;
   
   while(lenght >= 0)
      {
         char = StringGetChar(s, lenght);
         
         //
         //
         //
         //
         //
         
         if((char > 96 && char < 123) || (char > 223 && char < 256))
                  s = StringSetChar(s, lenght, char - 32);
         else 
              if(char > -33 && char < 0)
                  s = StringSetChar(s, lenght, char + 224);
         lenght--;
   }
   return(s);
}

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

void setUpStrings(string& array[],int& length, string source)
{
   source = StringUpperCase(StringTrimLeft(StringTrimRight(source)));
   if (StringSubstr(source,StringLen(source)-1,1) != ";")
                    source = StringConcatenate(source,";");

   //
   //
   //
   //
   //
   
   int  s = 0;
   int  i = StringFind(source,";",s);
   string current;
      while (i > 0)
      {
         current = StringSubstr(source,s,i-s);
         ArrayResize(array,ArraySize(array)+1);
                     array[ArraySize(array)-1] = current;
                     s = i + 1;
                     i = StringFind(source,";",s);
      }
   length = ArraySize(array);
}
 
 
//+------------------------------------------------------------------+

void DoDailyOpen(string doSymbol) 
{

int   yy = TimeYear(Time[0]);
int   mm = TimeMonth(Time[0]);
int   dd = TimeDay(Time[0]);  
   
string yymmddms = yy+"."+mm+"."+dd+" " + myHHMM ;
         
datetime var1 = StrToTime(yymmddms);  
   
datetime day=24*60*60;
datetime r= var1 ;

//datetime r=(TimeCurrent()/day)*day;
//datetime r=(var1/day)*day;

int      cd=iBarShift(NULL,0,r,FALSE);
datetime r2=r-day;


if(TimeDayOfWeek(r2)==0) r2=r2-day-day;
int cd2=iBarShift(NULL,0,r2,FALSE);

if( var1 > Time[0] ) { r = r2 ;cd = cd2 ;} // if date/time is greater than current date/time go back 1 day


DailyOpen = iOpen(doSymbol,0,cd);    


}

//+------------------------------------------------------------------+ 
/*

Comment(

"pair " , doSymbol , "\n" , 
"DailyOpen " , DoubleToStr(DailyOpen,Digits) , "\n" ,
 

"") ; 


   if(close > open ) { pColor[d] = Lime ;   } else {
   if(close < open ) { pColor[d] = Red ;    } else { 
                       pColor[d] = Yellow ; } } 
                 
   pArrow[d] = ArrowNumber[d] ; 

Comment(
"arrNZD[0] " , DoubleToStr(arrNZD[0],Digits) , "\n" ,   
"arrNZD[1] " , DoubleToStr(arrNZD[1],Digits) , "\n" ,    
"arrNZD[Bars] " , DoubleToStr(arrNZD[Bars],Digits) , "\n" ,   

"") ; 


   string Lname = lbl[u]+u+d ;
   ObjectDelete(Lname);
   ObjectCreate(Lname, OBJ_ARROW,0,Time[0],PRICE_CLOSE);
//   ObjectSetText(Lname, pArrow[d], 12, "WingDings",  pColor[d]);
   ObjectSet(Lname, OBJPROP_CORNER, myCorner);
   ObjectSet(Lname, OBJPROP_XDISTANCE, myChartX+150-(d*15) );
   ObjectSet(Lname, OBJPROP_YDISTANCE, n+myChartY); 
   ObjectSet(Lname, OBJPROP_ARROWCODE, pArrow[d] );    // pArrow[d]
   ObjectSet(Lname, OBJPROP_COLOR, pColor[d] ); 

*/