//+------------------------------------------------------------------+
//|                                             BuySellBasketRSI.mq4 |
//|                                     Copyright © 2010, Robet Hill |
//|                                                                  |
//+------------------------------------------------------------------+
#property copyright "Copyright © 2010, Robert Hill."

#property indicator_separate_window
#property indicator_buffers 7
#property indicator_color1 Green
#property indicator_color2 Lime
#property indicator_color3 Yellow
#property indicator_color4 FireBrick
#property indicator_color5 Red
#property indicator_color6 Orange
#property indicator_color7 Aqua

//---- input parameters
extern int     DisplayBars = 500;
extern string i0 = "Indicator";
extern string i1 = " 1. RSI";
extern string i2 = " 2. CCI";
extern string i3 = " 3. DeMarker";
extern string i5 = " 4. Momentum";
extern string i6 = " 5. MFI";
extern string i9 = " 6. WPR";
extern int myIndicator = 1;

extern int     rPeriod=14;
  
extern int     AppliedPrice=0;  
extern string  note0="Applied price 0-CLOSE | 1-OPEN | 2-HIGH | 3-LOW |";
extern string  note1="            | 4-MEDIAN | 5-TYPICAL | 6-WEIGHTED |";


extern bool LongBasket = true;
extern bool    BrokerIsIBFX = false;
extern string  Broker1 = "---IBFX Inputs---";
extern string ilong_basket= "enter 7 long symbols - no m";
extern string ilong_basket1= "GBPUSD";
extern string ilong_basket2= "EURGBP";
extern string ilong_basket3= "GBPJPY";
extern string ilong_basket4= "USDCHF";
extern string ilong_basket5= "NZDUSD";
extern string ilong_basket6= "AUDJPY";
extern string ilong_basket7= "EURJPY";

extern string ishort_basket= "enter 7 short symbols - no m";
extern string ishort_basket1= "EURUSD";
extern string ishort_basket2= "USDJPY";
extern string ishort_basket3= "AUDUSD";
extern string ishort_basket4= "NZDJPY";
extern string ishort_basket5= "GBPCHF";
extern string ishort_basket6= "CHFJPY";
extern string ishort_basket7= "EURCHF";

extern string Broker2 = "---FXDD Inputs---";
extern string flong_basket= "enter 7 long symbols";
extern string flong_basket1= "AUDJPY";
extern string flong_basket2= "CHFJPY";
extern string flong_basket3= "EURGBP";
extern string flong_basket4= "EURJPY";
extern string flong_basket5= "GBPCHF";
extern string flong_basket6= "GBPUSD";
extern string flong_basket7= "USDCHF";

extern string fshort_basket= "enter 7 short symbols";
extern string fshort_basket1= "AUDUSD";
extern string fshort_basket2= "CADJPY";
extern string fshort_basket3= "EURCHF";
extern string fshort_basket4= "EURUSD";
extern string fshort_basket5= "GBPJPY";
extern string fshort_basket6= "USDCAD";
extern string fshort_basket7= "USDJPY";


string Pair1, Pair2, Pair3, Pair4, Pair5, Pair6, Pair7;

//---- buffers
double Pair1Buffer[];
double Pair2Buffer[];
double Pair3Buffer[];
double Pair4Buffer[];
double Pair5Buffer[];
double Pair6Buffer[];
double Pair7Buffer[];
//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int init()
  {
   string short_name, ap_name, ma_name;
//---- 2 additional buffers are used for counting.
//   IndicatorBuffers(3);
//---- indicator line
   SetIndexStyle(0,DRAW_LINE);
   SetIndexBuffer(0,Pair1Buffer);
   SetIndexStyle(1,DRAW_LINE);
   SetIndexBuffer(1,Pair2Buffer);
   SetIndexStyle(2,DRAW_LINE);
   SetIndexBuffer(2,Pair3Buffer);
   SetIndexStyle(3,DRAW_LINE);
   SetIndexBuffer(3,Pair4Buffer);
   SetIndexStyle(4,DRAW_LINE);
   SetIndexBuffer(4,Pair5Buffer);
   SetIndexStyle(5,DRAW_LINE);
   SetIndexBuffer(5,Pair6Buffer);
   SetIndexStyle(6,DRAW_LINE);
   SetIndexBuffer(6,Pair7Buffer);
   
   GetCorrectPairs();
   
//---- name for DataWindow and indicator subwindow label
   switch(AppliedPrice){
      case 1 : ap_name=" | OPEN "; break; 
      case 2 : ap_name=" | HIGH "; break;  
      case 3 : ap_name=" | LOW "; break;  
      case 4 : ap_name=" | MEDIAN "; break;    
      case 5 : ap_name=" | TYPICAL "; break;    
      case 6 : ap_name=" | WEIGHTED "; break;     
      default :
         AppliedPrice=PRICE_CLOSE; ap_name=" | CLOSE "; break; 
   }

   short_name="BuySellBasket ";
   switch (myIndicator)
   {
      case 1 : short_name = short_name + "RSI(" + rPeriod + ")" + ap_name;
               break;
      case 2 : short_name = short_name + "CCI(" + rPeriod + ")" + ap_name;
               break;
      case 3 : short_name = short_name + "DeMark(" + rPeriod + ")";
               break;
      case 4 : short_name = short_name + "Mom(" + rPeriod + ")" + ap_name;
               break;
      case 5 : short_name = short_name + "MFI(" + rPeriod + ")";
               break;
      case 6 : short_name = short_name + "WPR(" + rPeriod + ")";
               break;
     default :
               myIndicator = 1;
               short_name = short_name + "RSI(" + rPeriod + ")" + ap_name;
   }
   IndicatorShortName(short_name);
   SetIndexLabel(0,Pair1);
   SetIndexLabel(1,Pair2);
   SetIndexLabel(2,Pair3);
   SetIndexLabel(3,Pair4);
   SetIndexLabel(4,Pair5);
   SetIndexLabel(5,Pair6);
   SetIndexLabel(6,Pair7);

//----
   return(0);
  }
//+------------------------------------------------------------------+
//| BuySellBasket RSI                                              |
//+------------------------------------------------------------------+
int start()
  {
   int    i, limit, counted_bars=IndicatorCounted();
   double val1, val2,val3,val4,val5,val6,val7;
//----
//----
  if(counted_bars<0) return(-1);
  //---- the last counted bar will be recounted
  if(counted_bars>0) counted_bars--;

  limit=Bars-counted_bars;
   
   for(i=0; i<= limit; i++)
   {
      switch (myIndicator)
      {
      case 1 : val1=iRSI(Pair1,0,rPeriod,AppliedPrice,i);
               val2=iRSI(Pair2,0,rPeriod,AppliedPrice,i);
               val3=iRSI(Pair3,0,rPeriod,AppliedPrice,i);
               val4=iRSI(Pair4,0,rPeriod,AppliedPrice,i);
               val5=iRSI(Pair5,0,rPeriod,AppliedPrice,i);
               val6=iRSI(Pair6,0,rPeriod,AppliedPrice,i);
               val7=iRSI(Pair7,0,rPeriod,AppliedPrice,i);
               break;
      case 2 : val1=iCCI(Pair1,0,rPeriod,AppliedPrice,i);
               val2=iCCI(Pair2,0,rPeriod,AppliedPrice,i);
               val3=iCCI(Pair3,0,rPeriod,AppliedPrice,i);
               val4=iCCI(Pair4,0,rPeriod,AppliedPrice,i);
               val5=iCCI(Pair5,0,rPeriod,AppliedPrice,i);
               val6=iCCI(Pair6,0,rPeriod,AppliedPrice,i);
               val7=iCCI(Pair7,0,rPeriod,AppliedPrice,i);
               break;
      case 3 : val1=iDeMarker(Pair1,0,rPeriod,i);
               val2=iDeMarker(Pair2,0,rPeriod,i);
               val3=iDeMarker(Pair3,0,rPeriod,i);
               val4=iDeMarker(Pair4,0,rPeriod,i);
               val5=iDeMarker(Pair5,0,rPeriod,i);
               val6=iDeMarker(Pair6,0,rPeriod,i);
               val7=iDeMarker(Pair7,0,rPeriod,i);
               break;
      case 4 : val1=iMomentum(Pair1,0,rPeriod,AppliedPrice,i);
               val2=iMomentum(Pair2,0,rPeriod,AppliedPrice,i);
               val3=iMomentum(Pair3,0,rPeriod,AppliedPrice,i);
               val4=iMomentum(Pair4,0,rPeriod,AppliedPrice,i);
               val5=iMomentum(Pair5,0,rPeriod,AppliedPrice,i);
               val6=iMomentum(Pair6,0,rPeriod,AppliedPrice,i);
               val7=iMomentum(Pair7,0,rPeriod,AppliedPrice,i);
               break;
      case 5 : val1=iMFI(Pair1,0,rPeriod,i);
               val2=iMFI(Pair2,0,rPeriod,i);
               val3=iMFI(Pair3,0,rPeriod,i);
               val4=iMFI(Pair4,0,rPeriod,i);
               val5=iMFI(Pair5,0,rPeriod,i);
               val6=iMFI(Pair6,0,rPeriod,i);
               val7=iMFI(Pair7,0,rPeriod,i);
               break;
      case 6 : val1=iWPR(Pair1,0,rPeriod,i);
               val2=iWPR(Pair2,0,rPeriod,i);
               val3=iWPR(Pair3,0,rPeriod,i);
               val4=iWPR(Pair4,0,rPeriod,i);
               val5=iWPR(Pair5,0,rPeriod,i);
               val6=iWPR(Pair6,0,rPeriod,i);
               val7=iWPR(Pair7,0,rPeriod,i);
               break;
      }
      Pair1Buffer[i]=val1;
      Pair2Buffer[i]=val2;
      Pair3Buffer[i]=val3;
      Pair4Buffer[i]=val4;
      Pair5Buffer[i]=val5;
      Pair6Buffer[i]=val6;
      Pair7Buffer[i]=val7;
   
   }
//----
   return(0);
  }



void GetCorrectPairs()
{
   if (BrokerIsIBFX)
   {
     if (LongBasket)
     {
       Pair1 = GetCorrectSymbol(ilong_basket1);
       Pair2 = GetCorrectSymbol(ilong_basket2);
       Pair3 = GetCorrectSymbol(ilong_basket3);
       Pair4 = GetCorrectSymbol(ilong_basket4);
       Pair5 = GetCorrectSymbol(ilong_basket5);
       Pair6 = GetCorrectSymbol(ilong_basket6);
       Pair7 = GetCorrectSymbol(ilong_basket7);
     }
     else
     {
   
       Pair1 = GetCorrectSymbol(ishort_basket1);
       Pair2 = GetCorrectSymbol(ishort_basket2);
       Pair3 = GetCorrectSymbol(ishort_basket3);
       Pair4 = GetCorrectSymbol(ishort_basket4);
       Pair5 = GetCorrectSymbol(ishort_basket5);
       Pair6 = GetCorrectSymbol(ishort_basket6);
       Pair7 = GetCorrectSymbol(ishort_basket7);
     }
   }
   else
   {
     if (LongBasket)
     {
       Pair1 = GetCorrectSymbol(flong_basket1);
       Pair2 = GetCorrectSymbol(flong_basket2);
       Pair3 = GetCorrectSymbol(flong_basket3);
       Pair4 = GetCorrectSymbol(flong_basket4);
       Pair5 = GetCorrectSymbol(flong_basket5);
       Pair6 = GetCorrectSymbol(flong_basket6);
       Pair7 = GetCorrectSymbol(flong_basket7);
     }
     else
     {
       Pair1 = GetCorrectSymbol(fshort_basket1);
       Pair2 = GetCorrectSymbol(fshort_basket2);
       Pair3 = GetCorrectSymbol(fshort_basket3);
       Pair4 = GetCorrectSymbol(fshort_basket4);
       Pair5 = GetCorrectSymbol(fshort_basket5);
       Pair6 = GetCorrectSymbol(fshort_basket6);
       Pair7 = GetCorrectSymbol(fshort_basket7);
     }
   }
}

string GetCorrectSymbol(string pair)
{
   string AddChar, myPair;
   
   myPair = pair;
   if (StringLen(pair) > 0)
   {
   if (StringLen(Symbol()) == 7)
     {
      AddChar = StringSubstr(Symbol(), 6, 1);
      myPair = pair + AddChar;
     }
   }
   return(myPair);
   
}

//+------------------------------------------------------------------+