//+------------------------------------------------------------------+
//|                                          High-lows dashboard.mq4 |
//|                                                           mladen |
//+------------------------------------------------------------------+
#property copyright "www.forex-tsd.com"
#property link      "www.forex-tsd.com"
#property indicator_separate_window
#property indicator_buffers 0
#property indicator_minimum 0
#property indicator_maximum 1


//
//
//
//
//

extern string _                = "pairs and timeframes";
extern string symbols          = "EURUSD;EURJPY;GBPUSD;GBPJPY;USDCHF;USDCAD;USDJPY";
extern string timeFrames       = "M1;M5;M15;M30;H1;H4;D1;W1;MN";
extern string uniqueID         = "NL ZigZag dashboard";
extern int    ZigZagPeriod     = 100;
extern int    ZigZagPrice      = PRICE_CLOSE;
extern double ZigZagPctFilter  = 1.0;
extern string __               = "colors";
extern color  ColorUp          = DeepSkyBlue;
extern color  ColorNeutral     = Gray;
extern color  ColorDown        = PaleVioletRed;
extern color  ColorPrice       = CornflowerBlue;
extern color  ColorLabels      = Gray;

//
//
//
//
//

int    window;  
int    totalSymbols;
int    totalTimeFrames;
int    totalLabels;
int    aTimes[];
string aSymbol[];
string sTimes[];
string labelNames;
string shortName;
int    corner;


//+------------------------------------------------------------------
//|
//+------------------------------------------------------------------
//
//
//
//
//

int init()
{
   corner     = 0;
   shortName  = uniqueID+" :";
   labelNames = shortName;
      IndicatorShortName(shortName);

   //
   //
   //
   //
   //
   
      symbols = stringUpperCase(StringTrimLeft(StringTrimRight(symbols)));
      if (symbols=="") symbols=Symbol();
      if (StringSubstr(symbols,StringLen(symbols),1) != ";")
                       symbols = StringConcatenate(symbols,";");

         //
         //
         //
         //
         //                                   

         int  s      = 0;
         int  i      = StringFind(symbols,";",s);
         string current;
            while (i > 0)
            {
               current = StringSubstr(symbols,s,i-s);
               if (iClose(current,0,0) > 0) {
                     ArrayResize(aSymbol,ArraySize(aSymbol)+1);
                                 aSymbol[ArraySize(aSymbol)-1] = current; }
                                 s = i + 1;
                                     i = StringFind(symbols,";",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);
      totalSymbols    = ArraySize(aSymbol);
   return(0);
}

//
//
//
//
//

int deinit()
{
   string lookFor       = labelNames;
   int    lookForLength = StringLen(lookFor);
   for (int i=ObjectsTotal()-1; i>=0; i--)
   {
      string objectName = ObjectName(i);
         if (StringSubstr(objectName,0,lookForLength) == lookFor) ObjectDelete(objectName);
   }
   return(0);
}


//+------------------------------------------------------------------
//|
//+------------------------------------------------------------------

int start()
{
   int m,n;
   int i,k;

   //
   //
   //
   //
   //

   window      = WindowFind(shortName);
   totalLabels = 0;
         for (i=0,m=40; i < totalSymbols;    i++, m+=100)
         for (k=0,n=40; k < totalTimeFrames; k++, n+=13)
               showSymbol(aSymbol[i],aTimes[k],sTimes[k],m,n);
   return(0);
}


//+------------------------------------------------------------------
//|
//+------------------------------------------------------------------
//
//
//
//
//

void showSymbol(string symbol, int timeFrame, string label, int xdistance, int ydistance)
{
   double price = iClose(symbol,0,0);
      if (ydistance==40)
      {
         setObject(next(),symbol                                           ,xdistance-1 ,40,ColorLabels,"Arial Bold",12,270);
         setObject(next(),DoubleToStr(price,MarketInfo(symbol,MODE_DIGITS)),xdistance-16,20,ColorPrice ,"Arial Bold",12);
      }            

      //
      //
      //
      //
      //

      double trend = iCustom(symbol,timeFrame,"nonlagzigzag_v2.02",ZigZagPrice,ZigZagPeriod,ZigZagPctFilter,2,0);
      color theColor = ColorNeutral;
         if (trend<0) theColor = ColorUp;
         if (trend>0) theColor = ColorDown;
         setLabel(label,xdistance   ,ydistance,theColor);
}

//
//
//
//
//

string next() { totalLabels++; return(totalLabels); }  
void setLabel(string text,int x,int y, color theColor)
{
   if (theColor == ColorNeutral)
         string arrow = "¡";
   else         arrow = "l";    
   if (text!=" ") setObject(next(),text ,x+2 ,y,ColorLabels);
                  setObject(next(),arrow,x+35,y,theColor,"Wingdings",9);
}

//
//
//
//
//

void setObject(string name,string text,int x,int y,color theColor, string font = "Arial",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);
}

//+-------------------------------------------------------------------
//|                                                                  
//+-------------------------------------------------------------------
//
//
//
//
//

string sTfTable[] = {"M1","M5","M15","M30","H1","H4","D1","W1","MN"};
int    iTfTable[] = {1,5,15,30,60,240,1440,10080,43200};

//
//
//
//
//

int stringToTimeFrame(string tfs)
{
   tfs = stringUpperCase(tfs);
   for (int i=ArraySize(iTfTable)-1; i>=0; i--)
         if (tfs==sTfTable[i] || tfs==""+iTfTable[i]) return(iTfTable[i]);
}
string timeFrameToString(int tf)
{
   for (int i=ArraySize(iTfTable)-1; i>=0; i--) 
         if (tf==iTfTable[i]) return(sTfTable[i]);
                              return("");
}

//
//
//
//
//

string stringUpperCase(string str)
{
   string   s = str;

   for (int length=StringLen(str)-1; length>=0; length--)
   {
      int char = StringGetChar(s, length);
         if((char > 96 && char < 123) || (char > 223 && char < 256))
                     s = StringSetChar(s, length, char - 32);
         else if(char > -33 && char < 0)
                     s = StringSetChar(s, length, char + 224);
   }
   return(s);
}