//+------------------------------------------------------------------+
//|                                          CHO Different pairs.mq4 |
//|                      Copyright © 2012, MetaQuotes Software Corp. |
//|                                        http://www.metaquotes.net |
//| Created by user666, 08-03-2012, www.esbmonetary.com              |
//| CHAIKIN OSCILATOR FOR DIFFERENT PAIRS                            |
//+------------------------------------------------------------------+
#property copyright "Copyright © 2012, MetaQuotes Software Corp., ESB MONETARY S.A."
#property link      "http://www.metaquotes.net    www.esbmonetary.com"

#property indicator_separate_window
//#property indicator_minimum 0
//#property indicator_maximum 100
//#property indicator_level1 20
//#property indicator_level2 80
//#property indicator_level3 50
#property indicator_buffers 3
/*
extern int K = 350;
extern int D = 1;
extern int S = 1;
*/
extern int       SlowPeriod=350;
extern int       FastPeriod=115;
extern int       TypeSmooth=0;// 0 - SMA, 1 - EMA

extern string  FirstSymbol = "EURUSD";
extern string  SecondSymbol = "USDCHF";

extern int     FontSize = 8;
extern color   FirstColor = DodgerBlue;
extern color   SecondColor = Red;
extern color   DiffColor = Yellow;
extern int     FirstX_Coordinate = 0;
extern int     FirstY_Coordinate = 15;
extern int     SecondX_Coordinate = 340;
extern int     SecondY_Coordinate = 15;
extern int     DiffX_Coordinate = 110;
extern int     DiffY_Coordinate = 15;
extern bool    InvertFirstSymbol = false;
extern bool    InvertSecondSymbol = false;


double buffer1[], buffer2[],buffer3[];
string m="";
int    win;
string Text1,Text2,Text3;
//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int init()
  {
      m = StringSubstr(Symbol(),6,StringLen(Symbol())-6);
      SecondSymbol = SecondSymbol+m;
      if (FirstSymbol == "" )
         FirstSymbol = Symbol();
      else
         FirstSymbol = FirstSymbol+m;
      
      string name,char4;
      
      
            int obj = ObjectsTotal();
            for ( int n=obj;n > 0 ;n--)
               {
                  name = ObjectName(n);
                  char4 = StringSubstr(name,0,4);
                  if ( char4 == "Diff" )
                    ObjectDelete(name);   
               }
               
       IndicatorShortName("CHOdiffPairs ("+SlowPeriod+","+FastPeriod+","+TypeSmooth+") "+FirstSymbol+"|"+SecondSymbol);
//       win = WindowFind("CHOdiffPairs ("+SlowPeriod+","+FastPeriod+","+TypeSmooth+") "+FirstSymbol+"|"+SecondSymbol);        
win=WindowsTotal();      
                      
//---- indicators
      SetIndexBuffer(0,buffer1);
      SetIndexStyle(0,DRAW_LINE,STYLE_SOLID,NULL,FirstColor);
      SetIndexLabel(0,FirstSymbol);

      SetIndexBuffer(1,buffer2);
      SetIndexStyle(1,DRAW_LINE,STYLE_SOLID,NULL,SecondColor);
      SetIndexLabel(1,SecondSymbol);    

      SetIndexBuffer(2,buffer3);
      SetIndexStyle(2,DRAW_LINE,STYLE_DOT,NULL,DiffColor);
      SetIndexLabel(2,"Difference");    

IndicatorDigits(2);

//----
   return(0);
  }
//+------------------------------------------------------------------+
//| Custom indicator deinitialization function                       |
//+------------------------------------------------------------------+
int deinit()
  {
//----
   
   string name,char4;
      
      
            int obj = ObjectsTotal();
            for ( int n=obj;n > 0 ;n--)
               {
                  name = ObjectName(n);
                  char4 = StringSubstr(name,0,4);
                  if ( char4 == "Diff" )
                    ObjectDelete(name);   
               }
              
//----
   return(0);
  }
//+------------------------------------------------------------------+
//| Custom indicator iteration function                              |
//+------------------------------------------------------------------+
int start()
  {
   
   
   int    i,counted_bars=IndicatorCounted();
   if(counted_bars>0) counted_bars--;
      int limit=Bars-counted_bars;
      
      for(i=limit; i>=0; i--)
         {
         /*
            if ( InvertFirstSymbol)
               buffer1[i] = 100-iStochastic(FirstSymbol,0,K,D,S,0,0,0,i);
            else
               buffer1[i] = iStochastic(FirstSymbol,0,K,D,S,0,0,0,i);   
            if ( InvertSecondSymbol )
               buffer2[i] = 100-iStochastic(SecondSymbol,0,K,D,S,0,0,0,i);
            else
               buffer2[i] = iStochastic(SecondSymbol,0,K,D,S,0,0,0,i);
        */       
 buffer1[i]=iCustom(FirstSymbol, 0, "CHO", SlowPeriod,FastPeriod,0,  0,i);  
 buffer2[i]=iCustom(SecondSymbol, 0, "CHO", SlowPeriod,FastPeriod,0,  0,i);          
               
            buffer3[i] = MathAbs(buffer1[i]-buffer2[i]);
                                                
         }   
      
      Text1 = StringSubstr(FirstSymbol,0,6);
      Text2 = StringSubstr(SecondSymbol,0,6);

      ObjectDelete("Diff1"+FirstSymbol+SecondSymbol);
      ObjectDelete("Diff2"+FirstSymbol+SecondSymbol);

      ObjectCreate("Diff1"+FirstSymbol+SecondSymbol,OBJ_LABEL,win,0,0);
      ObjectSet("Diff1"+FirstSymbol+SecondSymbol,OBJPROP_XDISTANCE, FirstX_Coordinate);
      ObjectSet("Diff1"+FirstSymbol+SecondSymbol,OBJPROP_YDISTANCE, FirstY_Coordinate); 
      ObjectSetText("Diff1"+FirstSymbol+SecondSymbol,Text1, FontSize,"Arial",FirstColor);
      
      ObjectCreate("Diff2"+FirstSymbol+SecondSymbol,OBJ_LABEL,win,0,0);
      ObjectSet("Diff2"+FirstSymbol+SecondSymbol,OBJPROP_XDISTANCE, SecondX_Coordinate);
      ObjectSet("Diff2"+FirstSymbol+SecondSymbol,OBJPROP_YDISTANCE, SecondY_Coordinate); 
      ObjectSetText("Diff2"+FirstSymbol+SecondSymbol,Text2, FontSize,"Arial",SecondColor);      
      
      Text3 = "Diff "+DoubleToStr(buffer3[0], 0)+"% Coincides with ";
                
      ObjectDelete("Diff3"+FirstSymbol+SecondSymbol);      
      ObjectCreate("Diff3"+FirstSymbol+SecondSymbol,OBJ_LABEL,win,0,0);
      ObjectSet("Diff3"+FirstSymbol+SecondSymbol,OBJPROP_XDISTANCE, DiffX_Coordinate);
      ObjectSet("Diff3"+FirstSymbol+SecondSymbol,OBJPROP_YDISTANCE, DiffY_Coordinate); 
      ObjectSetText("Diff3"+FirstSymbol+SecondSymbol,Text3, FontSize,"Arial",DiffColor);
      
//----

//----
   return(0);
  }
//+------------------------------------------------------------------+