//+------------------------------------------------------------------+
//|                                              TRO_Dashboard.mq4   |
//|                                        Copyright © 2008, "TRO"   |
//|                                                                  |
//+------------------------------------------------------------------+


#property copyright "Copyright © 2007, Avery T. Horton, Jr. aka TheRumpledOne"
#property link      "therumpledone@gmail.com"

//+------------------------------------------------------------------+
//|                                         MT4_DASHBOARD_V1.5.mq4   |
//|                                      Copyright © 2008, "OTCFX"   |
//|                                             Revision 1.5         |
//|                                        *Credits to"mladen"       |
//|                                       for some bits&pieces.      |
//+------------------------------------------------------------------+
//#property copyright "Copyright © 2008 OTCFX"

#property indicator_separate_window  

#property indicator_buffers 0
#property indicator_minimum 0
#property indicator_maximum 1
extern string _            = "PAIRS";
extern string pairs        = "GBPUSD;EURUSD;USDCHF;USDJPY;USDCAD;GBPJPY;EURJPY;GBPCHF;EURAUD;EURCHF;EURGBP;AUDUSD;";
extern string timeFrames   = "M1;M5;M15;H1;H4;D1;W1";
extern color  ColorUp      = Lime;
extern color  ColorNeutral = Yellow ;
extern color  ColorDown    = Red ;
extern color  ValueColor   = DodgerBlue;
extern int    ValueSize    = 10;
extern string ValueFont    = "Verdana";
extern string Ind_Name_1   ="Moving Averages";
extern string myName       ="MA";

extern double iParm3 = 5;
extern double iParm4 = 0;
extern double iParm5 = 1;
extern double iParm6 = -100;
extern double iParm7 = -100;
extern double iParm8 = -100;
extern int    iMode  = 0;

extern bool show.SCORE = true ; 

int      window;  
int      totalPairs;
int      totalTimeFrames;
int      totalLabels;
int      aTimes[];
string   aPairs[];
string   sTimes[];
color    ColorLabels  = White;
color    MA_color;
color    srsi_color;
color    cad_color;
string   MA_arrow;
string   srsi_arrow;
string   cad_arrow;
string   labelNames;
string   shortName;
int      corner;
int       INC_UP ;
int       INC_UC ;
int       INC_DN;
int       MAMode;
int       PRMode;
int       RSIMode;
string    strMAType;
string    strRSIType;
bool   ShowCount    = true;
/*
extern string __            = "Lable&Calc!";
extern string Pair0    = "EURUSD";
extern string Pair1    = "GBPUSD";
extern string Pair2    = "AUDUSD";
extern string Pair3    = "USDCHF";
extern string Pair4    = "USDCAD";
extern string Pair5    = "USDJPY";
extern string Pair6    = "GBPJPY";
extern string Pair7    = "EURJPY";
extern string Pair8    = "GBPCHF";
extern string Pair9    = "EURAUD";
extern string Pair10   = "EURCHF";
extern string Pair11   = "EURGBP";
extern string Pair12   = ""      ;
extern string Pair13   = ""      ;
extern string Pair14   = ""      ;
extern string Pair15   = ""      ;
extern string Pair16   = ""      ;
extern string Pair17   = ""      ;
extern string Pair18   = ""      ;
extern string Pair19   = ""      ;
extern string Pair20   = ""      ;
*/


string Pair0    = "EURUSD";
string Pair1    = "GBPUSD";
string Pair2    = "AUDUSD";
string Pair3    = "USDCHF";
string Pair4    = "USDCAD";
string Pair5    = "USDJPY";
string Pair6    = "GBPJPY";
string Pair7    = "EURJPY";
string Pair8    = "GBPCHF";
string Pair9    = "EURAUD";
string Pair10   = "EURCHF";
string Pair11   = "EURGBP";
string Pair12   = ""      ;
string Pair13   = ""      ;
string Pair14   = ""      ;
string Pair15   = ""      ;
string Pair16   = ""      ;
string Pair17   = ""      ;
string Pair18   = ""      ;
string Pair19   = ""      ;
string Pair20   = ""      ;

double cVal = 0, pVal = 0;

double cdayClose;
double cdayOpen;
color  ColorPrice ; 
double point  ;
int    xPoint ;

//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+

int init()
{

   corner     = 0;
   shortName  = MakeUniqueName("TROFXDB ","");
   labelNames = shortName;
   IndicatorShortName(shortName);

    
      pairs = StringUpperCase(StringTrimLeft(StringTrimRight(pairs)));
      if (StringSubstr(pairs,StringLen(pairs),1) != ";")
      pairs = StringConcatenate(pairs,";");
                                  

         bool isMini = IsMini();            
         int  s      = 0;
         int  i      = StringFind(pairs,";",s);
         int time;
         string current;
        
         string temp;
         
            while (i > 0)
            {
               current = StringSubstr(pairs,s,i-s);
               if (isMini) current = StringConcatenate(current,"m");
              time    = stringToTimeFrame(current);
               current = StringSubstr(pairs,s,i-s);
               if (isMini) current = StringConcatenate(current,"m");
               if (iClose(current,0,0) > 0) {
               ArrayResize(aPairs,ArraySize(aPairs)+1);
                aPairs[ArraySize(aPairs)-1] = current; }
                 s = i + 1;
                i = StringFind(pairs,";",s);
                                                                                   
                                     
            }
    

      timeFrames = StringUpperCase(StringTrimLeft(StringTrimRight(timeFrames)));
      if (StringSubstr(timeFrames,StringLen(timeFrames),1) != ";")
       timeFrames = StringConcatenate(timeFrames,";");

                                                  
         s = 0;
         i = StringFind(timeFrames,";",s);
         //int time;
          while (i > 0)
            {
           current = StringSubstr(timeFrames,s,i-s);
           time    = stringToTimeFrame(current);
           if (time > 0) {
           ArrayResize(sTimes,ArraySize(sTimes)+1);
           ArrayResize(aTimes,ArraySize(aTimes)+1);
           sTimes[ArraySize(sTimes)-1] = TimeFrameToString(time); 
           aTimes[ArraySize(aTimes)-1] = time; }
           s = i + 1;
           i = StringFind(timeFrames,";",s);
            }

   

      totalTimeFrames = ArraySize(aTimes);
      totalPairs      = ArraySize(aPairs);
      totalLabels     = 0;
      
      
Pair0    = aPairs[0];
Pair1    = aPairs[1];
Pair2    = aPairs[2];
Pair3    = aPairs[3];
Pair4    = aPairs[4];
Pair5    = aPairs[5];
Pair6    = aPairs[6];
Pair7    = aPairs[7];
Pair8    = aPairs[8];
Pair9    = aPairs[9];
Pair10   = aPairs[10];
Pair11   = aPairs[11];
Pair12   = aPairs[12];
Pair13   = aPairs[13];
Pair14   = aPairs[14];
Pair15   = aPairs[15];
Pair16   = aPairs[16];
Pair17   = aPairs[17];
Pair18   = aPairs[18];
Pair19   = aPairs[19];
Pair20   = aPairs[20];   
      
   return(0);
   
}
//+------------------------------------------------------------------+
//| Custom indicator deinitialization function                       |
//+------------------------------------------------------------------+
int deinit()
{
   while (totalLabels>0) { ObjectDelete(StringConcatenate(labelNames,totalLabels)); totalLabels--;}
     
   return(0);
}


//+------------------------------------------------------------------+
//| Custom indicator iteration function                              |
//+------------------------------------------------------------------+

int start()
{

ObjectsDeleteAll( window, 21);
ObjectsDeleteAll( window, 22);
ObjectsDeleteAll( window, 23);
int m,n;
int i,k;
   window      = WindowFind(shortName);
   totalLabels = 0;
    for (i=0,m=30; i < totalPairs;      i++, m+=25){
   INC_UP = 0;
   INC_UC = 0;
   INC_DN = 0; 
   for (k=0,n=170; k < totalTimeFrames; k++, n+=46){
   showPair(aPairs[i],aTimes[k],sTimes[k],m,n);}
   if (ShowCount)  DoShowCount(m,n); }             
   if (Pair1 == "") Pair1 = Symbol();
    
     
     
   return(0);
}


//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+


void DoShowCount( int xdistance, int ydistance )
{

int x_Pair, y_Pair , y_Inc ;

x_Pair = 10;
y_Pair = 40;
y_Inc  = 25;


double PERp,PERC,PER;
int yInc = -125;

  PER=INC_UP; 
  PERC=PER*100;
  PERp=PERC/7;
  string PER_Str =DoubleToStr(PERp,Point);
   
color xColor = Yellow ;
 
if( PERp > 50) { xColor = LimeGreen ; }
else if( PERp < 50 ) { xColor = Crimson ; }


 if(ValueSize>12) ValueSize=12;
 
 setObject(next(),"TRO FX DASHBOARD INDICATOR © 2008 ",70,5, Gray ,ValueFont,7,0);

  if(show.SCORE){  
  setObject(next(),PER_Str,525,xdistance+10, xColor ,"Arial bold",10,0);}
  
  
  setObject(next(),Pair0,x_Pair,40, ValueColor ,ValueFont,ValueSize);
  setObject(next(),Pair1,x_Pair,65, ValueColor ,ValueFont,ValueSize);
  setObject(next(),Pair2,x_Pair,90, ValueColor ,ValueFont,ValueSize);
  setObject(next(),Pair3,x_Pair,115, ValueColor ,ValueFont,ValueSize);
  setObject(next(),Pair4,x_Pair,140, ValueColor ,ValueFont,ValueSize);
  setObject(next(),Pair5,x_Pair,165, ValueColor ,ValueFont,ValueSize);
  setObject(next(),Pair6,x_Pair,190, ValueColor ,ValueFont,ValueSize);
  setObject(next(),Pair7,x_Pair,215, ValueColor ,ValueFont,ValueSize);
  setObject(next(),Pair8,x_Pair,240, ValueColor ,ValueFont,ValueSize);
  setObject(next(),Pair9,x_Pair,265, ValueColor ,ValueFont,ValueSize);
  setObject(next(),Pair10,x_Pair,290, ValueColor ,ValueFont,ValueSize);
  setObject(next(),Pair11,x_Pair,315, ValueColor ,ValueFont,ValueSize);
  setObject(next(),Pair12,x_Pair,340, ValueColor ,ValueFont,ValueSize);
  setObject(next(),Pair13,x_Pair,365, ValueColor ,ValueFont,ValueSize);
  setObject(next(),Pair14,x_Pair,390, ValueColor ,ValueFont,ValueSize);
  setObject(next(),Pair15,x_Pair,415, ValueColor ,ValueFont,ValueSize);
  setObject(next(),Pair16,x_Pair,440, ValueColor ,ValueFont,ValueSize);
  setObject(next(),Pair17,x_Pair,465, ValueColor ,ValueFont,ValueSize);
  setObject(next(),Pair18,x_Pair,490, ValueColor ,ValueFont,ValueSize);
  setObject(next(),Pair19,x_Pair,515, ValueColor ,ValueFont,ValueSize);

string cTitle = myName ;

if(iParm3 != -100) { cTitle = cTitle + "," + DoubleToStr(iParm3,0) ; }
if(iParm4 != -100) { cTitle = cTitle + "," + DoubleToStr(iParm4,0) ; }
if(iParm5 != -100) { cTitle = cTitle + "," + DoubleToStr(iParm5,0) ; }
if(iParm6 != -100) { cTitle = cTitle + "," + DoubleToStr(iParm6,0) ; }
if(iParm7 != -100) { cTitle = cTitle + "," + DoubleToStr(iParm7,0) ; }
if(iParm8 != -100) { cTitle = cTitle + "," + DoubleToStr(iParm8,0) ; }
cTitle = cTitle + " Mode=" + iMode  ; 

   setObject(next(),cTitle,340,3, ValueColor ,"Verdana Bold",ValueSize);
   setObject(next(),"PAIR",x_Pair,18, ValueColor ,ValueFont,ValueSize);
   setObject(next(),sTimes[0],200,18, ValueColor ,ValueFont,ValueSize);
   setObject(next(),sTimes[1],245,18, ValueColor ,ValueFont,ValueSize);
   setObject(next(),sTimes[2],290,18, ValueColor ,ValueFont,ValueSize);
   setObject(next(),sTimes[3],340,18, ValueColor ,ValueFont,ValueSize);
   setObject(next(),sTimes[4],385,18, ValueColor ,ValueFont,ValueSize);
   setObject(next(),sTimes[5],430,18, ValueColor ,ValueFont,ValueSize);
   setObject(next(),sTimes[6],475,18, ValueColor ,ValueFont,ValueSize);

   setObject(next(),"%",525,18, ValueColor ,ValueFont,ValueSize);
     

x_Pair = x_Pair + 70 ;

setObject(next(),"Price",x_Pair,18, ValueColor ,ValueFont,ValueSize);
   
if( Pair0 != "" ) { DoPrice( Pair0, x_Pair  , y_Pair ) ; }
if( Pair1 != "" ) { y_Pair = y_Pair + y_Inc ; DoPrice( Pair1, x_Pair  , y_Pair ) ; }
if( Pair2 != "" ) { y_Pair = y_Pair + y_Inc ; DoPrice( Pair2, x_Pair  , y_Pair ) ; }
if( Pair3 != "" ) { y_Pair = y_Pair + y_Inc ; DoPrice( Pair3, x_Pair  , y_Pair ) ; }
if( Pair4 != "" ) { y_Pair = y_Pair + y_Inc ; DoPrice( Pair4, x_Pair  , y_Pair ) ; }
if( Pair5 != "" ) { y_Pair = y_Pair + y_Inc ; DoPrice( Pair5, x_Pair  , y_Pair ) ; }
if( Pair6 != "" ) { y_Pair = y_Pair + y_Inc ; DoPrice( Pair6, x_Pair  , y_Pair ) ; }
if( Pair7 != "" ) { y_Pair = y_Pair + y_Inc ; DoPrice( Pair7, x_Pair  , y_Pair ) ; }
if( Pair8 != "" ) { y_Pair = y_Pair + y_Inc ; DoPrice( Pair8, x_Pair  , y_Pair ) ; }
if( Pair9 != "" ) { y_Pair = y_Pair + y_Inc ; DoPrice( Pair9, x_Pair  , y_Pair ) ; }     
if( Pair10 != "" ) { y_Pair = y_Pair + y_Inc ; DoPrice( Pair10, x_Pair  , y_Pair ) ; }
if( Pair11 != "" ) { y_Pair = y_Pair + y_Inc ; DoPrice( Pair11, x_Pair  , y_Pair ) ; }
if( Pair12 != "" ) { y_Pair = y_Pair + y_Inc ; DoPrice( Pair12, x_Pair  , y_Pair ) ; }
if( Pair13 != "" ) { y_Pair = y_Pair + y_Inc ; DoPrice( Pair13, x_Pair  , y_Pair ) ; }
if( Pair14 != "" ) { y_Pair = y_Pair + y_Inc ; DoPrice( Pair14, x_Pair  , y_Pair ) ; }
if( Pair15 != "" ) { y_Pair = y_Pair + y_Inc ; DoPrice( Pair15, x_Pair  , y_Pair ) ; }
if( Pair16 != "" ) { y_Pair = y_Pair + y_Inc ; DoPrice( Pair16, x_Pair  , y_Pair ) ; }
if( Pair17 != "" ) { y_Pair = y_Pair + y_Inc ; DoPrice( Pair17, x_Pair  , y_Pair ) ; }
if( Pair18 != "" ) { y_Pair = y_Pair + y_Inc ; DoPrice( Pair18, x_Pair  , y_Pair ) ; }
if( Pair19 != "" ) { y_Pair = y_Pair + y_Inc ; DoPrice( Pair19, x_Pair  , y_Pair ) ; }         
}

//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
void DoPrice( string dpSymbol, int dp_xAxis, int dp_yAxis )
{
   cdayClose      = iClose(dpSymbol,PERIOD_D1,0);
   cdayOpen       = iOpen(dpSymbol,PERIOD_D1,0);
   
   if(cdayClose > cdayOpen) { ColorPrice = LimeGreen ; } else {
   if(cdayClose < cdayOpen) { ColorPrice = Red ; } else {ColorPrice = Yellow ; } }

   point = MarketInfo(dpSymbol,MODE_POINT);  
   
   if ( point == 0.01 )  {xPoint = 2 ; } else { xPoint = 4 ;  } 

   setObject(next(),DoubleToStr(cdayClose,xPoint),dp_xAxis, dp_yAxis, ColorPrice ,ValueFont,ValueSize);   
}


//+------------------------------------------------------------------+

void showPair(string pair, int timeFrame,string label, int xdistance, int ydistance)
{

   DoWork(pair,timeFrame,1) ;
   
   pVal = cVal ;   
   
   DoWork(pair,timeFrame,0) ;    
   
   if (cVal > pVal) { INC_UP = INC_UP +1 ; MA_color = ColorUp;      MA_arrow = "Ù"; } else {
   if (cVal < pVal) { INC_DN = INC_DN +1 ; MA_color = ColorDown;    MA_arrow = "Ú"; } else {
                      INC_UC = INC_UC +1 ; MA_color = ColorNeutral; MA_arrow = "Ø"; } }
   
   setLabel(" "  ,xdistance+10,ydistance+30," ",MA_color,MA_arrow);
       
  }

//+------------------------------------------------------------------+
//| Custom functions and procedures                                  |
//+------------------------------------------------------------------+

string next() { totalLabels++; return(totalLabels); }  


void setLabel(string text,int x,int y,string sarv, color theColor, string arrow, bool isADX=true)
{
    
  setObject(next(),arrow                  ,y,x,theColor,"Wingdings",14,0);
      
 }              
             

void setObject(string name,string text,int x,int y,color theColor, string font = "Verdana",int size=10,int angle=0)
{
   string labelName = StringConcatenate(labelNames,name);

  
      if (ObjectFind(labelName) == -1)
          {
             ObjectCreate(labelName,OBJ_LABEL,window,0,0);
             ObjectSet(labelName,OBJPROP_CORNER,corner);
             if (angle != 0)
             ObjectSet(labelName,OBJPROP_ANGLE,angle);
          }               
       ObjectSet(labelName,OBJPROP_XDISTANCE,x);
       ObjectSet(labelName,OBJPROP_YDISTANCE,y);
       ObjectSetText(labelName,text,size,font,theColor);
}


int stringToTimeFrame(string tfs)
{
   int tf=0;
       tfs = StringTrimLeft(StringTrimRight(StringUpperCase(tfs)));
         if (tfs=="M1" || tfs=="1")     tf=PERIOD_M1;
         if (tfs=="M5" || tfs=="5")     tf=PERIOD_M5;
         if (tfs=="M15"|| tfs=="15")    tf=PERIOD_M15;
         if (tfs=="M30"|| tfs=="30")    tf=PERIOD_M30;
         if (tfs=="H1" || tfs=="60")    tf=PERIOD_H1;
         if (tfs=="H4" || tfs=="240")   tf=PERIOD_H4;
         if (tfs=="D1" || tfs=="1440")  tf=PERIOD_D1;
         if (tfs=="W1" || tfs=="10080") tf=PERIOD_W1;
         if (tfs=="MN" || tfs=="43200") tf=PERIOD_MN1;
  return(tf);
}
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);
}

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);
}

string MakeUniqueName(string first, string rest)
{
   string result = first+(MathRand()%1001)+rest;

   while (WindowFind(result)> 0)
          result = first+(MathRand()%1001)+rest;
   return(result);
}
bool IsMini()
{
   if (StringFind(Symbol(),"m") > -1)
         return(true);
   else  return(false);    
}


  
//+------------------------------------------------------------------+

void DoWork( string myPair, int myPeriod , int p )  
{
while(true)
{
if(iParm3==-100 ) {
               cVal = iCustom(myPair,myPeriod,Ind_Name_1,iParm3,iMode,p);
               break ; }
                         
if(iParm3!=-100 && iParm4==-100 && iParm5==-100 && iParm6==-100 && iParm7==-100) {
               cVal = iCustom(myPair,myPeriod,Ind_Name_1,iParm3,iMode,p);          
               break ; }
               
if(iParm3!=-100 && iParm4!=-100 && iParm5==-100 && iParm6==-100 && iParm7==-100) {
               cVal = iCustom(myPair,myPeriod,Ind_Name_1,iParm3,iParm4,iMode,p);         
               break ; }
            
if(iParm3!=-100 && iParm4!=-100 && iParm5!=-100 && iParm6==-100 && iParm7==-100) {
               cVal = iCustom(myPair,myPeriod,Ind_Name_1,iParm3,iParm4,iParm5,iMode,p);
               break ; }                        
            
            
if(iParm3!=-100 && iParm4!=-100 && iParm5!=-100 && iParm6!=-100 && iParm7==-100) {
               cVal = iCustom(myPair,myPeriod,Ind_Name_1,iParm3,iParm4,iParm5,iParm6,iMode,p);
               break ; }                          
            
            
if(iParm3!=-100 && iParm4!=-100 && iParm5!=-100 && iParm6!=-100 && iParm7!=-100) {
               cVal = iCustom(myPair,myPeriod,Ind_Name_1,iParm3,iParm4,iParm5,iParm6,iParm7,iMode,p);
               break ; }
                       
break ;  }
                                        
}