//+------------------------------------------------------------------+
//|                                                  RelStrength.mq4 |
//|                                                         by Matsu |
//+------------------------------------------------------------------+

#property indicator_separate_window
#property indicator_buffers 7
#property indicator_color1 Aqua
#property indicator_color2 Silver
#property indicator_color3 Yellow
#property indicator_color4 DodgerBlue
#property indicator_color5 Red
#property indicator_color6 HotPink
#property indicator_color7 MediumOrchid

#property indicator_level1 0

extern int CountBars=50;
extern bool Reverse=false;
extern int Line_Thickness = 3;

//---- buffers
double val1[];
double val2[];
double val3[];
double val4[];
double val5[];
double val6[];
double val7[];


int deinit()
  {

  return(0);
  }

//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int init()
  {

//---- indicator line
   IndicatorBuffers(7);
   
   int width = 0;
   if(0 > StringFind(Symbol(), "EUR", 0))
       width = 1;
   else 
       width = Line_Thickness;
   
   SetIndexStyle(0,DRAW_LINE,0,width);
   
   if(0 > StringFind(Symbol(), "GBP", 0))
       width = 1;
   else 
       width = Line_Thickness;
   SetIndexStyle(1,DRAW_LINE,0,width);
   if(0 > StringFind(Symbol(), "JPY", 0))
       width = 1;
   else 
       width = Line_Thickness;
   SetIndexStyle(2,DRAW_LINE,0,width);
   if(0 > StringFind(Symbol(), "AUD", 0))
       width = 1;
   else 
       width = Line_Thickness;
   SetIndexStyle(3,DRAW_LINE,0,width);
   if(0 > StringFind(Symbol(), "CAD", 0))
       width = 1;
   else 
       width = Line_Thickness;
   SetIndexStyle(4,DRAW_LINE,0,width);
   if(0 > StringFind(Symbol(), "CHF", 0))
       width = 1;
   else 
       width = Line_Thickness;
   SetIndexStyle(5,DRAW_LINE,0,width);
   if(0 > StringFind(Symbol(), "NZD", 0))
       width = 1;
   else 
       width = Line_Thickness;
   SetIndexStyle(6,DRAW_LINE,0,width);
   SetIndexBuffer(0,val1);
   SetIndexBuffer(1,val2);
   SetIndexBuffer(2,val3);
   SetIndexBuffer(3,val4);
   SetIndexBuffer(4,val5);
   SetIndexBuffer(5,val6);
   SetIndexBuffer(6,val7);
   
   SetIndexLabel(0,"EUR");
   SetIndexLabel(1,"GBP");
   SetIndexLabel(2,"JPY");
   SetIndexLabel(3,"AUD");
   SetIndexLabel(4,"CAD");
   SetIndexLabel(5,"CHF");
   SetIndexLabel(6,"NZD");

   IndicatorShortName("RS(EUR,GBP,JPY,AUD,CAD,CHF,NZD vs USD)");
   IndicatorDigits(2);



//----
   return(0);
  }
//+------------------------------------------------------------------+

//+------------------------------------------------------------------+
int start()
  {   
   if (CountBars>=Bars) CountBars=Bars;
   int i,shift,counted_bars=IndicatorCounted();
   double price1,price2,price3,price4,price5,price6,price7;
//----
   if(Bars<=1) return(0);


price1=iMA("EURUSD",0,1,0,MODE_SMA,PRICE_CLOSE,CountBars);
price2=iMA("GBPUSD",0,1,0,MODE_SMA,PRICE_CLOSE,CountBars);
price3=iMA("USDJPY",0,1,0,MODE_SMA,PRICE_CLOSE,CountBars);
price4=iMA("AUDUSD",0,1,0,MODE_SMA,PRICE_CLOSE,CountBars);
price5=iMA("USDCAD",0,1,0,MODE_SMA,PRICE_CLOSE,CountBars);
price6=iMA("USDCHF",0,1,0,MODE_SMA,PRICE_CLOSE,CountBars);
price7=iMA("NZDUSD",0,1,0,MODE_SMA,PRICE_CLOSE,CountBars);

if (Reverse)
{

   for (shift = CountBars; shift>=0; shift--) 
   { 
   	val1[shift]= (1-iMA("EURUSD",0,1,0,MODE_SMA,PRICE_CLOSE,shift)/price1) *100;
		val2[shift]= (1-iMA("GBPUSD",0,1,0,MODE_SMA,PRICE_CLOSE,shift)/price2) *100;
		val3[shift]= (iMA("USDJPY",0,1,0,MODE_SMA,PRICE_CLOSE,shift)/price3 -1) *100;
		val4[shift]= (1-iMA("AUDUSD",0,1,0,MODE_SMA,PRICE_CLOSE,shift)/price4) *100;
		val5[shift]= (iMA("USDCAD",0,1,0,MODE_SMA,PRICE_CLOSE,shift)/price5 -1) *100;
		val6[shift]= (iMA("USDCHF",0,1,0,MODE_SMA,PRICE_CLOSE,shift)/price6 -1) *100;	
		val7[shift]= (1-iMA("NZDUSD",0,1,0,MODE_SMA,PRICE_CLOSE,shift)/price7) *100;
   }
   
   
   
   
}
else
{

   for (shift = CountBars; shift>=0; shift--) 
   { 
		val1[shift]= (iMA("EURUSD",0,1,0,MODE_SMA,PRICE_CLOSE,shift)/price1 -1) *100;
		val2[shift]= (iMA("GBPUSD",0,1,0,MODE_SMA,PRICE_CLOSE,shift)/price2 -1) *100;
		val3[shift]= (1-iMA("USDJPY",0,1,0,MODE_SMA,PRICE_CLOSE,shift)/price3) *100;
		val4[shift]= (iMA("AUDUSD",0,1,0,MODE_SMA,PRICE_CLOSE,shift)/price4 -1) *100;
		val5[shift]= (1-iMA("USDCAD",0,1,0,MODE_SMA,PRICE_CLOSE,shift)/price5) *100;
		val6[shift]= (1-iMA("USDCHF",0,1,0,MODE_SMA,PRICE_CLOSE,shift)/price6) *100;
		val7[shift]= (iMA("NZDUSD",0,1,0,MODE_SMA,PRICE_CLOSE,shift)/price7 -1) *100;
   }
   
}
   return(0);
  }
//+------------------------------------------------------------------+