//+------------------------------------------------------------------+
//|                                       TRO_Dashboard_SR_RR.mq4    |
//|                                                                  |
//|   Copyright © 2008, Avery T. Horton, Jr. aka TheRumpledOne       |
//|                                                                  |
//|   PO BOX 43575, TUCSON, AZ 85733                                 |
//|                                                                  |
//|   GIFTS AND DONATIONS ACCEPTED                                   | 
//|                                                                  |
//|   therumpledone@gmail.com                                        |  
//+------------------------------------------------------------------+ 

#property copyright "Copyright © 2008, Avery T. Horton, Jr. aka TheRumpledOne"
#property link      "therumpledone@gmail.com"
 

#property indicator_separate_window  

#property indicator_buffers 0
#property indicator_minimum 0
#property indicator_maximum 1

extern bool   Sound.Alert    = TRUE ;

extern int  myBiasPeroid      = 1440 ;  

extern string noteTimeNY = " 14:00 server time = 05:00 am pst" ; 
extern string noteTimeAU = " 23:00 server time = 14:00 am pst" ; 

extern string myOpenHHMM = "14:00"; // 05:00 am pst = 14:00 server time 

extern int       myBars       = 21 ; 
  
string  note_TimeFrames = "M1;5,15,30,60H1;240H4;1440D1;10080W1;43200MN|0-CurrentTF";

extern string _              = "PAIRS";
//extern string pairs        = "GBPUSD;";

extern string pairs        = "USDJPY;GBPJPY;EURUSD;USDCHF;GBPUSD;";

//extern string pairs        = "GBPUSD;EURUSD;USDCHF;USDJPY;USDCAD;GBPJPY;EURJPY;GBPCHF;";
extern string timeFrames   = "M5;M15";
//extern string timeFrames   = "M5;M15;H1;D1";
//extern string timeFrames   = "M1;M5;M15;H1;H4;D1;W1";



extern color UpS_color = Lime;
extern color UpW_color = Green;
extern color Eq_color  = Yellow;
extern color DnW_color = Maroon;
extern color DnS_color = Red;

extern color  ValueColor   = DodgerBlue;
extern int    ValueSize    = 10;
extern string ValueFont    = "Verdana";



bool show.SCORE = false ; 

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 ;



//---- buffers 
string ArrowHeadUp =  "Ù" ; // 217 up arrow head
string ArrowHeadDn =  "Ú" ; // 218 up arrow head

string Arrow12 = "ñ"; // 12 oclock
string Arrow2  = "ö";  // 2 oclock
string Arrow3  = "ð";  // 3 oclock
string Arrow5  = "ø";  // 5 oclock
string Arrow6  = "ò";  // 6 oclock
 

 
int    digits  ; 

color  ColorBias = Yellow ;  

double Bias_Open, Bias_Close, Bias_High, Bias_Low, Bias_Diff, Bias_Mid, Bias_Pivot, Bias_Value = -999 ;

string BiasMsg, tBiasPeroid, BiasArrow ;

bool long = false , short = false ;

bool Bias_Long = false , Bias_Short = false ;


bool OKtoLong   = false ;
bool OKtoShort  = false ; 
 

int OldBars = -1 ;

bool Trigger[21][9];

string tAlert, sAlert ;



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

int init()
{

   corner     = 0;
   shortName  = MakeUniqueName("SRRRDB ","");
   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];   
 
 
tBiasPeroid = TimeFrameToString(myBiasPeroid) ;     

   return(0);
   
}

//+------------------------------------------------------------------+
int deinit()
{
//   while (totalLabels>0) { ObjectDelete(StringConcatenate(labelNames,totalLabels)); totalLabels--;}
   ObjectsDeleteAll(window);     
   return(0);
}


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

int start()
{


ObjectsDeleteAll(window);

int m,n;
int i,k;

/*
if( Bars != OldBars )
{ 

}
*/

   for( m = 0, n = 0 ; m < 21 ; m++, n+=9) {Trigger[m][n] = True ; } 

   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)
      {   
          tAlert = "" ;  
          showPair(aPairs[i],aTimes[k],sTimes[k],m,n);
//          if ( Trigger[i][k] &&  Sound.Alert ) 
          if ( Sound.Alert ) 
          {
            if( tAlert != "" ) 
            { 
               Trigger[i][k] = False ; 
               sAlert = aPairs[i]+ "  "+ sTimes[k]+ " " + tAlert ;
               Alert(sAlert);  
               setObject(next(),sAlert,500,3, ValueColor ,"Verdana Bold",ValueSize);
            }
          }
          
          
      } // for k

      if (ShowCount)  DoShowCount(m,n); 
      
    } // for i  
               
      if (Pair1 == "") Pair1 = Symbol();
      
   OldBars = Bars ;   
          
   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 SR RR © 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 = tBiasPeroid + " Bias " ;

if( Sound.Alert  ) 
{    
     cTitle = cTitle +  " ALERT ON"  ;
}

   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,0) ;      

   if( Bias_Value == 3 )  {tAlert = "GO LONG"  ; MA_color = UpS_color; MA_arrow = ArrowHeadUp ; } else {
   if( Bias_Value == 2 )  {tAlert = "" ; MA_color = UpS_color; MA_arrow = Arrow12 ; } else {
   if( Bias_Value == 1 )  {tAlert = ""  ; MA_color = UpW_color; MA_arrow = Arrow2 ; } else {
   if( Bias_Value == -1 ) {tAlert = "" ; MA_color = DnW_color; MA_arrow = Arrow5 ; } else {    
   if( Bias_Value == -2 ) {tAlert = "" ; MA_color = DnS_color; MA_arrow = Arrow6 ; } else { 
   if( Bias_Value == -3 ) {tAlert = "GO SHORT" ; MA_color = DnS_color; MA_arrow = ArrowHeadDn ; } else {    
                                                MA_color = Eq_color; MA_arrow = Arrow3 ; }}}}}}
                                               
   setLabel(" "  ,xdistance+10,ydistance+30," ",MA_color,MA_arrow);


       
  }

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

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); //"Wingdings"
      
}              
             

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

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="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);
}

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

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 TimeFrame , int myShift  )  
{

   datetime TimeArray[];
   int    i,limit,y=0,counted_bars=IndicatorCounted();
 
// Plot defined time frame on to current time frame

   ArrayCopySeries(TimeArray,MODE_TIME,Symbol(),TimeFrame);  
   
   limit=1;     
   
   for(i=0,y=0;i<limit;i++)
   {
 
      if (Time[i]<TimeArray[y]) y++;   

      Bias_Value = iCustom(myPair,TimeFrame,"TRO_SR_RR_X",myBiasPeroid,myOpenHHMM,myBars,0,y);
 


   } // for                       
}

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

Comment(



"pair = ",pair, "\n",
"timeFrame = ",timeFrame, "\n",
"Bias_Value = ",Bias_Value, "\n",
//"SignalBuffer[0] = ", DoubleToStr( SignalBuffer[0], 4), "\n",

"") ; 
*/