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

#property  copyright "Copyright © 2008, Avery T. Horton, Jr. aka TRO" 
#property  link      "http://www.therumpledone.com/" 
 
#property  indicator_separate_window
#property  indicator_buffers 8
#property  indicator_color1  Lime
#property  indicator_color2  Coral
//#property  indicator_color3  Black //Aqua
#property  indicator_color4  Red
#property  indicator_color7  Green
#property  indicator_color8  Maroon


#property indicator_width1 3
#property indicator_width2 3
#property indicator_width3 1
#property indicator_width4 1
#property indicator_width7 3
#property indicator_width8 3



//---- indicator parameters

extern string myPair1 = "GBPJPY" ;
extern string myPair2 = "GBPUSD" ;

extern int myDiffAvgPeriods = 50; 

extern int x.offset= 500 ;//250
extern int y.offset= 0 ;//-160

  
extern string myFont       = "Arial Bold" ;
extern int    myFontSize   = 15 ;
extern int    xStart       = 0 ;
extern int    xOffSet      = 0 ;


//---- indicator buffers
double     ind_Buffer1[];
double     ind_Buffer2[];
double     ind_buffer3a[];
double     ind_buffer3b[];
double     ind_buffer3c[];
double     ind_buffer3d[];

double     ind_buffer4[];
double     ind_buffer5[];


string   tObjName01 , tObjName02 ;
string   tTrade = "" ;   
string   shortName ;

color    tColor    = White;

int      corner;
int      window; 
int      win ;  
 
double point1, point2 ; 

//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int init()
  {
  string FastMAname, SlowMAname, myDiffAvgPeriodsname;
//---- 2 additional buffers are used for counting.
//   IndicatorBuffers(8);
//---- drawing settings

   SetIndexStyle(0,DRAW_LINE);
//   SetIndexDrawBegin(0,myDiffAvgPeriods);
   SetIndexStyle(1,DRAW_LINE);
//   SetIndexDrawBegin(1,myDiffAvgPeriods);
   
//   SetIndexStyle(4,DRAW_LINE);
//   SetIndexBuffer (4,ind_Buffer1);
//   SetIndexStyle(5,DRAW_LINE);
 //  SetIndexBuffer(5,ind_Buffer2);
   
//   SetIndexStyle(6,DRAW_HISTOGRAM);
//   SetIndexDrawBegin(6,myDiffAvgPeriods);
//   SetIndexStyle(7,DRAW_HISTOGRAM);
//   SetIndexDrawBegin(7,myDiffAvgPeriods);
     
//   IndicatorDigits(MarketInfo(Symbol(),MODE_DIGITS)+2);
   

SetIndexBuffer(0,ind_buffer4) ;
SetIndexBuffer(1,ind_buffer5) ; 


      
   shortName = "TRO_PIP_DIFF ("+ myDiffAvgPeriods+ ") " + myPair1 + " " + myPair2 + " " + Period();

   IndicatorShortName(shortName);   


   tObjName01 = shortName + "01";
   tObjName02 = shortName + "02";
      
   point1 = MarketInfo(myPair1,MODE_POINT);
   point2 = MarketInfo(myPair2,MODE_POINT); 
     
   return(0);
  }

//+------------------------------------------------------------------+  
int deinit()
  {
   ObjectsDeleteAll(win);   
   return(0);
  }  
  
//+------------------------------------------------------------------+

int start()
  {
  
   win =    WindowFind(shortName);
   
   int limit;
   int counted_bars=IndicatorCounted();
//---- check for possible errors
   if(counted_bars<0) return(-1);
//---- last counted bar will be recounted
   if(counted_bars>0) counted_bars--;
   limit=Bars-counted_bars;
//---- macd counted in the 1-st additional buffer
   for(int i=0; i<limit; i++)
      ind_buffer4[i]=iClose(myPair1,0,i) - iClose(myPair2,0,i) ;
      
//---- signal line counted in the 2-nd additional buffer
   for(i=0; i<limit; i++)
      ind_buffer5[i]=iMAOnArray(ind_buffer4,Bars,myDiffAvgPeriods,0,0,i);
//---- main loop

/*
   double value=0, pvalue=0;
   for(i=limit; i>=0; i--)
      {
         ind_buffer3a[i]=0.0;
         ind_buffer3b[i]=0.0;      
         ind_buffer3c[i]=0.0;
         ind_buffer3d[i]=0.0;             
         
         value  = ind_buffer4[i] ;
         pvalue = ind_buffer4[i+1] ;
                  
         if (value > 0 && value >= pvalue ) ind_buffer3a[i]=value;
         if (value > 0 && value < pvalue ) ind_buffer3c[i]=value;         
         if (value < 0 && value < pvalue ) ind_buffer3b[i]=value;
         if (value < 0 && value >= pvalue ) ind_buffer3d[i]=value;        
        
      }   

//   for(i=limit; i>=0; i--){ ind_buffer4[i] = 0; ind_buffer5[i] = 0; }

i=0 ;
Comment( "ind_buffer3a[i]=" , DoubleToStr(ind_buffer3a[i],Digits)  , "\n" ,
         "ind_buffer3b[i]=" ,DoubleToStr(ind_buffer3b[i],Digits)   ,  "\n" ,
         "ind_buffer3c[i]=" ,DoubleToStr(ind_buffer3c[i],Digits)   ,  "\n" ,         
         "ind_buffer3d[i]=" ,DoubleToStr(ind_buffer3d[i] ,Digits)  ,  "\n" ,
         "value=" ,DoubleToStr(value ,Digits)  ,  "\n" ,
         "pvalue=" ,DoubleToStr(pvalue ,Digits)  ,  "\n" ,
         "i=" , i         
                           
           ) ;         


if(  ind_buffer3a[0] != 0 ) { tTrade = "UpTrend " ; tColor = indicator_color1 ; }
if(  ind_buffer3b[0] != 0 ) { tTrade = "DnTrend " ; tColor = indicator_color4 ; }
if(  ind_buffer3c[0] != 0 ) { tTrade = "PullBack" ; tColor = indicator_color7 ; }
if(  ind_buffer3d[0] != 0 ) { tTrade = "Bounce  " ; tColor = indicator_color8 ; }
*/

   ObjectCreate(tObjName01, OBJ_LABEL, win, 0, 0);// 
   ObjectSetText(tObjName01, DoubleToStr(ind_buffer4[0],4) , myFontSize, myFont, indicator_color1 );
   ObjectSet(tObjName01, OBJPROP_CORNER, 0);
   ObjectSet(tObjName01, OBJPROP_XDISTANCE, 0+x.offset); // 
   ObjectSet(tObjName01, OBJPROP_YDISTANCE, 0+y.offset); //  

   ObjectCreate(tObjName02, OBJ_LABEL, win, 0, 0);// 
   ObjectSetText(tObjName02, DoubleToStr(ind_buffer5[0],4) , myFontSize, myFont, indicator_color2 );
   ObjectSet(tObjName02, OBJPROP_CORNER, 0);
   ObjectSet(tObjName02, OBJPROP_XDISTANCE, 100+x.offset); // 
   ObjectSet(tObjName02, OBJPROP_YDISTANCE, 0+y.offset); //      
       
   return(0);
  }
//+------------------------------------------------------------------+

