//+------------------------------------------------------------------+
//|                                             !Strength Trader.mq4 |
//|                                  Copyright © 2011, John Wustrack |
//|                                        john_wustrack@hotmail.com |
//+------------------------------------------------------------------+
#property copyright "Copyright © 2011, John Wustrack"
#property link      "john_wustrack@hotmail.com"

#property show_inputs

extern double USD_ ;
extern double CAD_ ;
extern double EUR_ ;
extern double GBP_ ;
extern double CHF_ ;
extern double JPY_ ;
extern double AUD_ ;
extern double NZD_ ;

extern string PairsToTrade = "AUDCAD,AUDCHF,AUDJPY,AUDNZD,AUDUSD,CADCHF,CADJPY,CHFJPY,EURAUD,EURCAD,EURCHF,EURGBP,EURJPY,EURNZD,EURUSD,GBPCHF,GBPJPY,GBPUSD,NZDJPY,NZDUSD,USDCAD,USDCHF,USDJPY";

extern double LotSize = 0.1;

int NoOfPairs;
string TradePair[];
string TradePairAction[];

string Majors[8] = {"USD","CAD","EUR","GBP","CHF","JPY","AUD","NZD"};
double MajorStrength[8];

//+------------------------------------------------------------------+
//| script program start function                                    |
//+------------------------------------------------------------------+
int start()
  {
//----
	//Extract the pairs traded by the user
	NoOfPairs = StringFindCount(PairsToTrade,",")+1;
	ArrayResize(TradePair, NoOfPairs);
	ArrayResize(TradePairAction, NoOfPairs);
	string AddChar = StringSubstr(Symbol(),6,4);
	StrPairToStringArray(PairsToTrade, TradePair, AddChar);
	
	MajorStrength[0] = USD_;
	MajorStrength[1] = CAD_;
	MajorStrength[2] = EUR_;
	MajorStrength[3] = GBP_;
	MajorStrength[4] = CHF_;
	MajorStrength[5] = JPY_;
	MajorStrength[6] = AUD_;
	MajorStrength[7] = NZD_;
	
	GetTheTradeAction();
	int y = 10;
	
	// Display the trade actions
   for (int i=0; i<=NoOfPairs; i++)
      {
      Object_Create("Pair"+i,10,y,TradePair[i],10,"Arial",White);
      Object_Create("PairAction"+i,100,y,TradePairAction[i],10,"Arial",White);
      y+=15;
      }
         
	
   
//----
   return(0);
  }
//+------------------------------------------------------------------+
void StrPairToStringArray(string str, string &a[], string p_suffix, string delim=",")
//+------------------------------------------------------------------+
{
	int z1=-1, z2=0;
	for (int i=0; i<ArraySize(a); i++)
	{
		z2 = StringFind(str,delim,z1+1);
		a[i] = StringSubstr(str,z1+1,z2-z1-1) + p_suffix;
		if (z2 >= StringLen(str)-1)   break;
		z1 = z2;
	}
	return(0);
}
//+------------------------------------------------------------------+
int StringFindCount(string str, string str2)
//+------------------------------------------------------------------+
// Returns the number of occurrences of STR2 in STR
// Usage:   int x = StringFindCount("ABCDEFGHIJKABACABB","AB")   returns x = 3
{
   int c = 0;
   for (int i=0; i<StringLen(str); i++)
     if (StringSubstr(str,i,StringLen(str2)) == str2)  c++;
   return(c);
} // End int StringFindCount(string str, string str2)
//+------------------------------------------------------------------+
void GetTheTradeAction()
//+------------------------------------------------------------------+
{
   int BaseIdx, QuoteIdx;
   
   // Loop through each pair
   for (int i=0; i<=NoOfPairs; i++)
      {
      
      // Get the Base & Quote Index
      BaseIdx = GetIndex(StringSubstr(TradePair[i],0,3));
      QuoteIdx = GetIndex(StringSubstr(TradePair[i],3,3));
      
      // Check what direction we are going
      TradePairAction[i] = "No trade";
      if (MajorStrength[BaseIdx] > MajorStrength[QuoteIdx]) TradePairAction[i] = "BUY";
      if (MajorStrength[BaseIdx] < MajorStrength[QuoteIdx]) TradePairAction[i] = "SELL";
      
      }
  
	return(0);
}
//+------------------------------------------------------------------+
int GetIndex(string currency)
//+------------------------------------------------------------------+
{
   int pi_Idx;
   
   if (currency == "USD") pi_Idx = 0;
   if (currency == "CAD") pi_Idx = 1;
   if (currency == "EUR") pi_Idx = 2;
   if (currency == "GBP") pi_Idx = 3;
   if (currency == "CHF") pi_Idx = 4;
   if (currency == "JPY") pi_Idx = 5;
   if (currency == "AUD") pi_Idx = 6;
   if (currency == "NZD") pi_Idx = 7;
   
	return(pi_Idx);
}
//+------------------------------------------------------------------+
//| create screen objects                                            |
//+------------------------------------------------------------------+
void Object_Create(string ps_name,int pi_x,int pi_y,string ps_text=" ",int pi_size=12,
                  string ps_font="Arial",color pc_colour=CLR_NONE)
  {
//----
   
   ObjectCreate(ps_name,OBJ_LABEL,0,0,0,0,0);
   ObjectSet(ps_name,OBJPROP_CORNER,0);
   ObjectSet(ps_name,OBJPROP_COLOR,pc_colour);
   ObjectSet(ps_name,OBJPROP_XDISTANCE,pi_x);
   ObjectSet(ps_name,OBJPROP_YDISTANCE,pi_y);
   
   ObjectSetText(ps_name,ps_text,pi_size,ps_font,pc_colour);

//----
   return(0);
  }
//+------------------------------------------------------------------+