//+------------------------------------------------------------------+ 
//|   TRO_PipsToOpen                                                 | 
//|                                                                  | 
//|   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   = 600 ;
extern int myChartY   = 0 ;
extern int myCorner   = 0 ;
extern string myFont  = "Courier" ;
extern int myFontSize = 12 ;

extern string Symbols      = "AUDJPY;AUDUSD;EURGBP;EURJPY;EURUSD;GBPCHF;GBPJPY;GBPUSD;NZDUSD;USDCAD;USDCHF;USDJPY" ;

extern int myPeriod  = 0 ;
extern int BarsAgo = 0 ;


string symbol, tChartPeriod, ShortName ;  

int     digits, period, win, digits2, n, j, i; 
 

double point, point2, value ;
string lbl[15], lbl2[15];
color pColor = Blue ;

 
 
//---- PipsToOpen
string Indicator_Name = "PTO:" ;
int Objs = 0;

//+------------------------------------------------------------------+ 
int     ind_bufferOp[] ;
string shortName ;
int    cpairsLenH;
int    cpairsLenV;
int    shortLength;
int    ctimesLen;
string cpairsh[];
string cpairsv[];
int    aTimes[];
string addition  = "";
string FontToUse = "Terminal";
 
//+------------------------------------------------------------------+
int init()
  {
  
   if(Symbols == "") { Symbols = Symbol() ; }

   if(myPeriod == 0) { period = Period() ; } else { period = myPeriod ; }  
 
   tChartPeriod =  TimeFrameToString(period) ;
   symbol       =  Symbol() ;
   digits       =  Digits ;
   point        =  Point ;
   ShortName    =  tChartPeriod + " Pips(" + BarsAgo + ")" ;
   win          =  0 ;

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

   setUpStrings(cpairsh,cpairsLenH,Symbols);

   if (IsMini())   addition="m";
   if (IsDoubleDotted()) addition="..";
   else 
      if (IsDotted()) addition=".";
      shortName   = ShortName ;
      shortLength = StringLen(shortName);
      IndicatorShortName(shortName);

   return(0);
  }
 
//+------------------------------------------------------------------+
int deinit()
  {
//----
   for(int i = 0; i < Objs; i++)
     {
      if(!ObjectDelete(Indicator_Name + i))
          Print("error: code #", GetLastError());
     }
     
ObjectsDeleteAll();     
//----
   return(0);
  }
 
//+------------------------------------------------------------------+
int start()
{
 
n       = 10;
 
j       = 0 ;

lbl[j]  = ShortName+j;
lbl2[j] = tChartPeriod + " Pips To Open[" + BarsAgo + "]"  ;
DoShow(j, Orange);

//----    

for (i = 0; i < cpairsLenH; i++)
{
string symbol = cpairsh[i]+addition;
      
digits = MarketInfo(symbol,MODE_DIGITS) ; 
point  = MarketInfo(symbol,MODE_POINT) ;       
      
if(digits == 5 || digits == 3) { digits2 = 0 ; point = point * 10 ; } else { digits2 = 0 ; }
         
double value = (iClose(symbol, period ,0) - iOpen(symbol, period , BarsAgo) )/ point ;
 
j       = j + 1 ;
lbl[j]  = ShortName+j;
lbl2[j] = symbol+ "   " + DoubleToStr(value ,0)  ;
DoColor( value, 0 ) ; 
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);
    }
}

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

bool   IsMini()         { return(StringFind(Symbol(),"m")  > -1); }

bool   IsDoubleDotted() { return(StringFind(Symbol(),"..") > -1); }

bool   IsDotted()       { return(StringFind(Symbol(),".")  > -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);
}


//+------------------------------------------------------------------+
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(
"arrNZD[0] " , DoubleToStr(arrNZD[0],Digits) , "\n" ,   
"arrNZD[1] " , DoubleToStr(arrNZD[1],Digits) , "\n" ,    
"arrNZD[Bars] " , DoubleToStr(arrNZD[Bars],Digits) , "\n" ,   

"") ; 

*/