//+------------------------------------------------------------------+
//|                                                           SR.mq4 |
//|                      Copyright © 2004, MetaQuotes Software Corp. |
//|                                       http://www.metaquotes.net/ |
//+------------------------------------------------------------------+
#property  copyright "Copyright © 2004, MetaQuotes Software Corp."
#property  link      "http://www.metaquotes.net/"
//---- indicator settings
#property  indicator_separate_window
#property  indicator_buffers 5
#property  indicator_color1  MediumBlue
#property  indicator_color2  Red
#property  indicator_color3  Yellow
#property  indicator_color4  Brown
#property  indicator_color5  Brown
#property  indicator_width1  2
//---- indicator parameters



extern string FXPair1 = "EURUSD";
extern string FXPair2 = "GBPUSD";
extern int SignalMethod = MODE_SMA;
extern int SignalSMA=20;
extern int SignalSMA2=100;
extern int BandsPeriod=20;
extern int BandsDeviation=2;


int SignalSMA3=0;
int SignalSMA4=0;


//---- indicator buffers
double     SDCDBuffer[];
double     SignalBuffer[];
double     SignalBuffer2[];
double     SignalBuffer3[];
double     SignalBuffer4[];


//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int init()
  {
//---- drawing settings
   SetIndexStyle(0,DRAW_LINE, STYLE_SOLID,2);
   SetIndexStyle(1,DRAW_LINE);
   SetIndexStyle(2,DRAW_LINE);
   SetIndexStyle(3,DRAW_LINE);
   SetIndexStyle(4,DRAW_LINE);
   SetIndexDrawBegin(1,SignalSMA);
   SetIndexDrawBegin(2,SignalSMA2);
   SetIndexDrawBegin(3,SignalSMA3);
   SetIndexDrawBegin(4,SignalSMA3);
   IndicatorDigits(Digits+1);
//---- indicator buffers mapping
   SetIndexBuffer(0,SDCDBuffer);
   SetIndexBuffer(1,SignalBuffer);
   SetIndexBuffer(2,SignalBuffer2);
   SetIndexBuffer(3,SignalBuffer3);
   SetIndexBuffer(4,SignalBuffer4);
//---- name for DataWindow and indicator subwindow label
   IndicatorShortName("SR("+BandsPeriod+","+SignalSMA+")");
   SetIndexLabel(0,"SDCD");
   SetIndexLabel(1,"Signal");
   SetIndexLabel(2,"Signal2");
   SetIndexLabel(3,"Signal3");
   SetIndexLabel(4,"Signal4");
//---- initialization done
   return(0);
  }
//+------------------------------------------------------------------+
//| Moving Averages Convergence/Divergence                           |
//+------------------------------------------------------------------+
int start()
  {
   double limit;
   int counted_bars=IndicatorCounted();
//---- last counted bar will be recounted
   if(counted_bars>0) counted_bars--;
   limit=Bars-counted_bars;

RefreshRates();
   
//---- counted in the 1-st buffer
   for(int i=0; i<limit; i++)    
       SDCDBuffer[i]=iMA("AUDUSD",0,1,0,MODE_SMA,PRICE_OPEN,i) / iMA("NZDUSD",0,1,0,MODE_SMA,PRICE_OPEN,i);      
             
//---- signal line counted in the 2-nd buffer
RefreshRates();
   for(i=0; i<limit; i++)
      SignalBuffer[i]=iMAOnArray(SDCDBuffer,Bars,SignalSMA,0,SignalMethod,i);

//---- signal line counted in the 3rd buffer
RefreshRates();
   for(i=0; i<limit; i++)
      SignalBuffer2[i]=iMAOnArray(SDCDBuffer,Bars,SignalSMA2,0,SignalMethod,i);

//double Envelopebuffer = SignalBuffer2;

//---- signal line counted in the 4rth buffer
RefreshRates();
  for(i=0; i<limit; i++)        
      SignalBuffer3[i]=iBandsOnArray (SDCDBuffer, 0, BandsPeriod, BandsDeviation, 0, MODE_LOWER,i);
      
      
RefreshRates();
  for(i=0; i<limit; i++)  
      SignalBuffer4[i]=iBandsOnArray (SDCDBuffer, 0, BandsPeriod, BandsDeviation, 0, MODE_UPPER,i);
      
       
      
      
      
//---- done
   return(0);
  }
//+------------------------------------------------------------------+