#property indicator_separate_window
#property indicator_buffers 4
#property indicator_color1 Blue
#property indicator_color2 Green
#property indicator_color3 Red
#property indicator_color4 DimGray

extern int  IPeriod = 14;
extern int  MaxBars = 500;

extern string EURUSD="EURUSDm";
extern string EURJPY="EURJPYm";
extern string EURGBP="EURGBPm";
extern string USDJPY="USDJPYm";
extern string GBPUSD="GBPUSDm";
extern string GBPJPY="GBPJPYm";

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 stochastic = iStochastic(EURUSD, NULL, IPeriod, 10, 10, MODE_SMA, 0, MODE_MAIN, shift);
      if (stochastic > 50.0) EUR[shift] += stochastic;
      else USD[shift] += (100 - stochastic);

      stochastic = iStochastic(USDJPY, NULL, IPeriod, 10, 10, MODE_SMA, 0, MODE_MAIN, shift);
      if (stochastic > 50.0) USD[shift] += stochastic;
      else JPY[shift] += (100 - stochastic);

      stochastic = iStochastic(EURJPY, NULL, IPeriod, 10, 10, MODE_SMA, 0, MODE_MAIN, shift);
      if (stochastic > 50.0) EUR[shift] += stochastic;
      else JPY[shift] += (100 - stochastic);

      stochastic = iStochastic(GBPJPY, NULL, IPeriod, 10, 10, MODE_SMA, 0, MODE_MAIN, shift);
      if (stochastic > 50.0) GBP[shift] += stochastic;
      else JPY[shift] += (100 - stochastic);

      stochastic = iStochastic(EURGBP, NULL, IPeriod, 10, 10, MODE_SMA, 0, MODE_MAIN, shift);
      if (stochastic > 50.0) EUR[shift] += stochastic;
      else GBP[shift] += (100 - stochastic);

      stochastic = iStochastic(GBPUSD, 0, IPeriod, 10, 10, MODE_SMA, 0, MODE_MAIN, shift);
      if (stochastic > 50.0) GBP[shift] += stochastic;
      else USD[shift] += (100 - stochastic);
   }
   
   return (0);
}