//+------------------------------------------------------------------+
//|                                                 DiffDesvEnv.mq4  |
//|                                         Ronaldo Araújo de Farias |
//|                                                                  |
//+------------------------------------------------------------------+
#property copyright "Ronaldo Araújo de Farias"
#property link      ""

#property indicator_separate_window
#property indicator_buffers 3


#property indicator_color1 Red
#property indicator_style1 STYLE_DOT

#property indicator_color2 Blue
#property indicator_style2 STYLE_DOT

#property indicator_color3 Magenta
#property indicator_width3 2
//--- input parameters
extern int       Period_=200;
extern string    Second_Pair="GBPUSD";

//--- buffers
double ExtMapBuffer1[];    //Pair 1
double ExtMapBuffer2[];    //Pair 2
double ExtMapBuffer3[];    //Diff 
//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+

int Mult;


int init()
  {
//---- indicators
   SetIndexStyle(0,DRAW_LINE);
   SetIndexBuffer(0,ExtMapBuffer1);
   SetIndexLabel(0,"Pair 1"); 
   
   SetIndexStyle(1,DRAW_LINE);
   SetIndexBuffer(1,ExtMapBuffer2);
   SetIndexLabel(1,"Pair 2"); 
   
   SetIndexStyle(2,DRAW_LINE);
   SetIndexBuffer(2,ExtMapBuffer3);
   SetIndexLabel(2,"Difference");
   
   SetLevelStyle(STYLE_DOT,EMPTY,DarkGreen);
   SetLevelValue(0,0.0);   
   SetLevelStyle(STYLE_DOT,EMPTY,DarkGreen);
   SetLevelValue(1,-10.0);   
   SetLevelStyle(STYLE_DOT,EMPTY,DarkGreen);
   SetLevelValue(2,10.0);
   
   

   
   
//----
   return(0);
  }
//+------------------------------------------------------------------+
//| Custom indicator deinitialization function                       |
//+------------------------------------------------------------------+
int deinit()
  {
//----
   
//----
   return(0);
  }
  
  
  
 double Desv_1pair(int shift){
     return (((iClose(Symbol(),0,shift)- iMA(Symbol(),0,Period_,0,MODE_EMA,MODE_CLOSE,shift)))/(10*Mult*MarketInfo(Symbol(),MODE_POINT)));
 }
 
 double Desv_2pair(int shift){
     return (((iClose(Second_Pair,0,shift)- iMA(Second_Pair,0,Period_,0,MODE_EMA,MODE_CLOSE,shift)))/(10*Mult*MarketInfo(Second_Pair,MODE_POINT)));
 }  
//+------------------------------------------------------------------+
//| Custom indicator iteration function                              |
//+------------------------------------------------------------------+
int start(){
   int digits = MarketInfo ("EURUSD", MODE_DIGITS);
   if (digits == 5) {Mult = 10;} else {Mult = 1;}

   for(int i=0;i<Bars;i++){
      ExtMapBuffer1[i]=Desv_1pair(i);
      ExtMapBuffer2[i]=Desv_2pair(i);
      ExtMapBuffer3[i]=ExtMapBuffer1[i]-ExtMapBuffer2[i];
   }
   
   return(0);
  }
//+------------------------------------------------------------------+