#property indicator_separate_window
#property indicator_buffers 4
#property indicator_color1 Blue
#property indicator_color2 Red
#property indicator_color3 Green
#property indicator_color4 Yellow

#property indicator_width1 2
#property indicator_width2 2
#property indicator_width3 2
#property indicator_width4 2

extern int  IPeriod = 14;
extern int  MaxBars = 500;

extern string EURUSD="EURUSD";
extern string EURJPY="EURJPY";
extern string EURGBP="EURGBP";
extern string USDJPY="USDJPY";
extern string GBPUSD="GBPUSD";
extern string GBPJPY="GBPJPY";

double EUR[];
double USD[];
double GBP[];
double JPY[];

int init() {
   SetIndexStyle (0, DRAW_LINE);
   SetIndexBuffer(0, EUR);
   SetIndexLabel (0, "EUR");

   SetIndexStyle(1, DRAW_LINE);
   SetIndexBuffer(1, USD);
   SetIndexLabel(1, "USD");

   SetIndexStyle(2, DRAW_LINE);
   SetIndexBuffer(2, GBP);
   SetIndexLabel(2, "GBP");

   SetIndexStyle(3, DRAW_LINE);
   SetIndexBuffer(3, JPY);
   SetIndexLabel(3, "JPY");

   IndicatorShortName(StringConcatenate("CurrencyPower(",IPeriod,")"));
   return (0);
}

int deinit() {
   return (0);
}

int start() {

   int counted=IndicatorCounted(),limit;
   if(counted==0)limit=Bars; // Cope with reloaded history
   else limit=Bars-counted;
   
   if(MaxBars>0) limit=MathMin(limit,MaxBars);
   
   for (int shift = 0; shift <= limit; shift++) {
      EUR[shift] = 0;
      USD[shift] = 0;
      JPY[shift] = 0;
      GBP[shift] = 0;
      double rsi = iRSI(EURUSD,NULL,10,PRICE_CLOSE,shift);
      if (rsi > 50.0) EUR[shift] += rsi;
      else USD[shift] += (100 - rsi);

      rsi = iRSI(USDJPY,NULL,10,PRICE_CLOSE,shift);
      if (rsi > 50.0) USD[shift] += rsi;
      else JPY[shift] += (100 - rsi);

      rsi = iRSI(EURJPY,NULL,10,PRICE_CLOSE,shift);
      if (rsi > 50.0) EUR[shift] += rsi;
      else JPY[shift] += (100 - rsi);

      rsi = iRSI(GBPJPY,NULL,10,PRICE_CLOSE,shift);
      if (rsi > 50.0) GBP[shift] += rsi;
      else JPY[shift] += (100 - rsi);

      rsi = iRSI(EURGBP,NULL,10,PRICE_CLOSE,shift);
      if (rsi > 50.0) EUR[shift] += rsi;
      else GBP[shift] += (100 - rsi);

      rsi = iRSI(GBPUSD,NULL,10,PRICE_CLOSE,shift);
      if (rsi > 50.0) GBP[shift] += rsi;
      else USD[shift] += (100 - rsi);
   }
   
   return (0);
}