//+------------------------------------------------------------------+ 
//|   TRO_SPREAD                                                     | 
//|                                                                  | 
//|   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   = 450 ;
extern int myChartY   = 0 ;
extern int myCorner   = 0 ;
extern string myFont  = "Courier" ;
extern int myFontSize = 12 ;
 
//extern int myBars     = 240 ;
extern color colorHead  = Orange ;
extern int myPeriod     = 0 ;
extern string Symbols      = "AUDJPY;AUDUSD;EURGBP;EURJPY;EURUSD;GBPCHF;GBPJPY;GBPUSD;NZDUSD;USDCAD;USDCHF;USDJPY" ;

//extern string Symbols      = "USDJPY;GBPJPY;AUDJPY;CHFJPY;EURJPY;CADJPY;NZDJPY";
//extern string Symbols      = "EURUSD;EURAUD;EURCAD;EURCHF;EURGBP;EURJPY;EURNZD";

double Hi, Li, C;

double prev_high, prev_low, prev_close, D, p, value ; 
int h  ;
string lbl[15], lbl2[15];
int n, j, i, shift, stop, nHH, nLL  ;

color pColor = Blue ;

string symbol, tChartPeriod, ShortName ;  

int    digits, period, win, digits2 ; 
double  spread,  H1L0, L1H0 ;

double point, point2, open, high, low, close, mid, range, pClose, pOpen, pHigh, pLow, pMid, pRange, cRange  ;  
double xMax = - 1,  xMin = 9999999999999, xDiff, xClose, xHigh, xLow, xRunUp, xRunDn, xPain ;
double High0, Low0, Open0,  Close0, Open1,High1, Low1, Close1   ;  
 
int     ind_bufferOp[], Stats[11], StatsR[11], StatsG[11],scount;

 
bool red0, red1, green0, green1 ;
      
string cpairsh[];
 
int    cpairsLenH;
double Diff0, Diff1, Diff2 ; 
      
//+------------------------------------------------------------------+

int init()
  {
   if(myPeriod == 0 ) { period = Period() ; } else { period = myPeriod ; } 
   
   tChartPeriod =  TimeFrameToString(period) ;
   symbol       =  Symbol() ;
   digits       =  Digits ;
   point        =  Point ;

   win          =  0 ;
    

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

      setUpStrings(cpairsh,cpairsLenH,Symbols);

   ShortName    =  "STRENGTH"+symbol+period+cpairsh[0]  ;      
  
   return(0);
  }
  
//+------------------------------------------------------------------+
int deinit()
  {
 
ObjectsDeleteAll();
 
   return(0);
  }
  
//+------------------------------------------------------------------+
int start()
{
 
n       = 10;
 
j       = 0 ;

lbl[j]  = ShortName+j;
lbl2[j] = "SPREAD"  ;
DoShow(j, colorHead);



for( j = 1 ; j <= cpairsLenH ; j++ )
{
   DoWork( cpairsh[j-1] ) ;
   lbl[j]  = ShortName+j;
   lbl2[j] = cpairsh[j-1]+ "  " + DoubleToStr(spread, digits2);
 
   DoShow(j, pColor); 
}




//---------


   return(0);
  }

//+------------------------------------------------------------------+
  
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);

 

n = n+20;

   return(0);
  }

//+------------------------------------------------------------------+
  
void DoColor( double c1, double c2 )
{

if(c1 > c2 ) { pColor = Lime ; } else {
if(c1 < c2 ) { pColor = Red ; } else { pColor = Yellow ; } } 

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

//+------------------------------------------------------------------+
void drawLine(double lvl,string name, color Col,int type)
{
         if(ObjectFind(name) != 0)
         {
            ObjectCreate(name, OBJ_HLINE, 0, Time[0], lvl,Time[0],lvl);
            
            if(type == 1)
            ObjectSet(name, OBJPROP_STYLE, STYLE_SOLID);
            else
            ObjectSet(name, OBJPROP_STYLE, STYLE_DOT);
            
            ObjectSet(name, OBJPROP_COLOR, Col);
            ObjectSet(name,OBJPROP_WIDTH,1);
            
         }
         else
         {
            ObjectDelete(name);
            ObjectCreate(name, OBJ_HLINE, 0, Time[0], lvl,Time[0],lvl);
            
            if(type == 1)
            ObjectSet(name, OBJPROP_STYLE, STYLE_SOLID);
            else
            ObjectSet(name, OBJPROP_STYLE, STYLE_DOT);
            
            ObjectSet(name, OBJPROP_COLOR, Col);        
            ObjectSet(name,OBJPROP_WIDTH,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);
}

//+------------------------------------------------------------------+
void DoWork( string wSymbol)
{
      RefreshRates();
      
      spread  = MarketInfo(wSymbol,MODE_SPREAD) ; 

      digits  = MarketInfo(wSymbol,MODE_DIGITS) ; 
      point   = MarketInfo(wSymbol,MODE_POINT) ; 
      if(digits == 5 || digits == 3) { digits2 = 0 ; point = point * 10 ; } 
      else { digits2 = 0 ; }

      DoColor (spread , 0 ) ;

}

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


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

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

/*

Comment(

"ind_bufferOp[0]" , ind_bufferOp[0] , "\n" ,   
"Open0 " , DoubleToStr(Open0,Digits) , "\n" ,  
"Close0 " , DoubleToStr(Close0,Digits) , "\n" ,   
"Open1 " , DoubleToStr(Open1,Digits) , "\n" ,  
"Close1 " , DoubleToStr(Close1,Digits) , "\n" ,   

"") ; 
*/