//+------------------------------------------------------------------+
//|                                        _TRO_Dashboard_UpDn.mq4   |
//|                                        Copyright © 2008, "TRO"   |
//|                                                                  |
//+------------------------------------------------------------------+

#property copyright "Copyright © 2008, 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 __           = "Indicator;Parameters";
extern string Parms        = "_TradeWhatYouSee;7;50.6;3;0;1";
extern string _            = "PAIRS";
//extern string pairs        = "GBPUSD;";

extern string pairs        = "GBPUSD;EURUSD;USDCHF;USDJPY;USDCAD;GBPJPY;EURJPY;GBPCHF;";

extern string timeFrames   = "M1;M5;M15;H1;H4;D1;W1";
extern int    myUp         = 1;
extern int    myEq         = -1;
extern int    myDn         = 0;

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 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;



string Pair0    = ""      ;
string Pair1    = ""      ;
string Pair2    = ""      ;
string Pair3    = ""      ;
string Pair4    = ""      ;
string Pair5    = ""      ; 
string Pair6    = ""      ;
string Pair7    = ""      ;
string Pair8    = ""      ;
string Pair9    = ""      ;
string Pair10   = ""      ;
string Pair11   = ""      ;
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 ;

int      totalParms;

string   aParms[];

//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+

int init()
{

   corner     = 0;
   shortName  = MakeUniqueName("TROUD ","");
   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);
            }

      if (StringSubstr(Parms,StringLen(Parms),1) != ";")
      Parms = StringConcatenate(Parms,";");
      
           s      = 0;
           i      = StringFind(Parms,";",s);
         
            while (i > 0)
            {
               current = StringSubstr(Parms,s,i-s);
               ArrayResize(aParms,ArraySize(aParms)+1);
               aParms[ArraySize(aParms)-1] = current; 
               s = i + 1;
               i = StringFind(Parms,";",s);                                                                                                             
            }

totalParms = ArraySize(aParms) ;   

      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();
    
     
//setObject(next(),DoubleToStr(cVal,4),800, 0, White ,"Arial bold",12);               
//setObject(next(),DoubleToStr(pVal,4),800, 20, Yellow ,"Arial bold",12);               
       
     
   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 / totalTimeFrames ; // 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 UpDn © 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 = aParms[0] ;

if(totalParms >= 4) { cTitle = cTitle + "," + aParms[1] ; }
if(totalParms >= 5) { cTitle = cTitle + "," + aParms[2] ; }
if(totalParms >= 6) { cTitle = cTitle + "," + aParms[3] ; }
if(totalParms >= 7) { cTitle = cTitle + "," + aParms[4] ; }
if(totalParms >= 8) { cTitle = cTitle + "," + aParms[5] ; }
if(totalParms >= 9) { cTitle = cTitle + "," + aParms[6] ; }
if(totalParms >= 10) { cTitle = cTitle + "," + aParms[7] ; }
if(totalParms >= 11) { cTitle = cTitle + "," + aParms[8] ; }
if(totalParms >= 12) { cTitle = cTitle + "," + aParms[9] ; }
if(totalParms >= 13) { cTitle = cTitle + "," + aParms[10] ; }
if(totalParms >= 14) { cTitle = cTitle + "," + aParms[11] ; }


   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 ; } }

double xPrice, xPsycho, bid, ask, bidmod, askmod ;

   point   = MarketInfo(dpSymbol,MODE_POINT);  
   bid     = MarketInfo(dpSymbol,MODE_BID);  
   ask     = MarketInfo(dpSymbol,MODE_ASK);  

   if ( point == 0.01 ) { xPsycho = 0.25; xPoint = 2 ; } 
   else { xPsycho = 0.0025; xPoint = 4 ; }

   bidmod = MathMod(bid ,xPsycho) ;         
   askmod = MathMod(ask ,xPsycho) ;         
   xPrice = cdayClose - bidmod ; 

   if(bidmod == 0 || askmod == 0) { ColorPrice = Orange ; }

   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 == myUp) { INC_UP = INC_UP +1 ; MA_color = ColorUp;      MA_arrow = "Ù"; } else {
   if (cVal == myDn) { 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;
         if (tfs=="MN1" || 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 myShift  )  
{

int iParm = totalParms - 3 ;

while(true)
{
if(iParm==1 ) {cVal = iCustom(myPair,myPeriod,aParms[0],aParms[1],aParms[2],myShift); break ; }
if(iParm==2 ) {cVal = iCustom(myPair,myPeriod,aParms[0],aParms[1],aParms[2],aParms[3],myShift); break ; }
if(iParm==3 ) {cVal = iCustom(myPair,myPeriod,aParms[0],aParms[1],aParms[2],aParms[3],aParms[4],myShift); break ; }
if(iParm==4 ) {cVal = iCustom(myPair,myPeriod,aParms[0],aParms[1],aParms[2],aParms[3],aParms[4],aParms[5],myShift); break ; }
if(iParm==5 ) {cVal = iCustom(myPair,myPeriod,aParms[0],aParms[1],aParms[2],aParms[3],aParms[4],aParms[5],aParms[6],myShift); break ; }
if(iParm==6 ) {cVal = iCustom(myPair,myPeriod,aParms[0],aParms[1],aParms[2],aParms[3],aParms[4],aParms[5],aParms[6],aParms[7],myShift); break ; }
if(iParm==7 ) {cVal = iCustom(myPair,myPeriod,aParms[0],aParms[1],aParms[2],aParms[3],aParms[4],aParms[5],aParms[6],aParms[7],aParms[8],myShift); break ; }
if(iParm==8 ) {cVal = iCustom(myPair,myPeriod,aParms[0],aParms[1],aParms[2],aParms[3],aParms[4],aParms[5],aParms[6],aParms[7],aParms[8],aParms[9],myShift); break ; }
if(iParm==9 ) {cVal = iCustom(myPair,myPeriod,aParms[0],aParms[1],aParms[2],aParms[3],aParms[4],aParms[5],aParms[6],aParms[7],aParms[8],aParms[9],aParms[10],myShift); break ; }
if(iParm==10 ) {cVal = iCustom(myPair,myPeriod,aParms[0],aParms[1],aParms[2],aParms[3],aParms[4],aParms[5],aParms[6],aParms[7],aParms[8],aParms[9],aParms[10],aParms[11],myShift); break ; }

Comment( myPair,myPeriod,aParms[0],aParms[1],aParms[2],myShift);         
               
break ;  }
                                        
}