//+------------------------------------------------------------------+
//|                                               DigitalClaster.mq4 |
//|                      Copyright © 2009, MetaQuotes Software Corp. |
//|                                        http://www.metaquotes.net |
//+------------------------------------------------------------------+
#property copyright "Copyright © 2009, MetaQuotes Software Corp."
#property link      "http://www.metaquotes.net"
#include <stderror.mqh>
#include <stdlib.mqh>
#include <WinUser32.mqh>
/*
1. EURGBP
2. EURAUD
3. EURNZD
4. EURUSD
5. EURCAD
6. EURCHF
7. EURJPY

8. GBPAUD
9. GBPNZD = GBPUSD/NZDUSD
10.GBPUSD
11.GBPCAD
12.GBPCHF
13.GBPJPY

14.AUDNZD
15.AUDUSD
16.AUDCAD
17.AUDCHF
18.AUDJPY

19.NZDUSD
20.NZDCAD
21.NZDCHF
22.NZDJPY

23.USDCAD
24.USDCHF
25.USDJPY

26.CADCHF
27.CADJPY

28.CHFJPY
*/
string S_SetL[28] =
{"EUR","EUR","EUR","EUR","EUR","EUR","EUR",  "GBP","GBP","GBP","GBP","GBP","GBP",   "AUD","AUD","AUD","AUD","AUD",
"NZD","NZD","NZD","NZD",  "USD","USD","USD",  "CAD","CAD", "CHF"};

string S_SetR[28] = 
{"GBP","AUD","NZD","USD","CAD","CHF","JPY",  "AUD","NZD","USD","CAD","CHF","JPY",   "NZD","USD","CAD","CHF","JPY",
"USD","CAD","CHF","JPY",  "CAD","CHF","JPY",  "CHF","JPY", "JPY"};

static double S_BidPrev[28];
double        S_Point  [28];  
int           S_Digits [28]; 


string Cluster_Val         [8] = {"EUR","GBP","AUD","NZD","USD","CAD","CHF","JPY"};
string TempCluster_Val     [8] = {"EUR","GBP","AUD","NZD","USD","CAD","CHF","JPY"}; 

int    Cluster_Val_Move    [8];
int    TempCluster_Val_Move[8];
string Cluster_Val_Sign[8];
int    Cluster_Val_MoveSum;

extern int      TimeFrame  = 3600;
static datetime TimeInit   = 0;     // начальное время
int             TimePassed = 0; 

int i;
int j;
int k;

string SL_SR;
double S_BidCur;
int    S_Move;
string Cluster_Val_Move_D;
string Pref;
//***********************************************************************************
//***********************************************************************************
int start () 
{ 
//---
 for (i = 0; i <= 27; i++)
 {
  SL_SR    = StringConcatenate(S_SetL[i],S_SetR[i]);
  S_BidCur = NormalizeDouble(MarketInfoF(SL_SR,MODE_BID),S_Digits[i]);
  S_Move   = (S_BidCur/S_BidPrev[i]-1)/S_Point[i];
  S_BidPrev[i] = S_BidCur;
//---
  for (j = 0; j <= 7; j++)
  {
   if (S_SetL[i] == Cluster_Val[j]) Cluster_Val_Move[j] +=S_Move;
  }
//---  
  for (j = 0; j <= 7; j++)
  {
   if (S_SetR[i] == Cluster_Val[j]) Cluster_Val_Move[j] -=S_Move;
  }
//---  
 } //конец цикла for (i = 0; i <= 27; i++)
//---
 ArrayCopy(TempCluster_Val     ,Cluster_Val     );
 ArrayCopy(TempCluster_Val_Move,Cluster_Val_Move);

 for (i = 0; i <= 7; i++)
 {
  k = ArrayMaximum(TempCluster_Val_Move);
  Cluster_Val         [i] = TempCluster_Val     [k];
  Cluster_Val_Move    [i] = TempCluster_Val_Move[k];
  TempCluster_Val_Move[k] = -i-9999999999999; 
 }
 
 Cluster_Val_MoveSum = 0;
 for (i = 0; i <= 7; i++)
 {
  Cluster_Val_MoveSum += Cluster_Val_Move[i];
  if (Cluster_Val_Move[i] >= 0) Cluster_Val_Sign[i] = " + "; else  Cluster_Val_Sign[i] = " - ";
 }

 Cluster_Val_Move_D = StringConcatenate(Cluster_Val[0]," = ",Cluster_Val_Sign[0],MathAbs(Cluster_Val_Move[0]),"\n",
                                        Cluster_Val[1]," = ",Cluster_Val_Sign[1],MathAbs(Cluster_Val_Move[1]),"\n",                                                  
                                        Cluster_Val[2]," = ",Cluster_Val_Sign[2],MathAbs(Cluster_Val_Move[2]),"\n",                                                  
                                        Cluster_Val[3]," = ",Cluster_Val_Sign[3],MathAbs(Cluster_Val_Move[3]),"\n",                                                  
                                        Cluster_Val[4]," = ",Cluster_Val_Sign[4],MathAbs(Cluster_Val_Move[4]),"\n",                                                  
                                        Cluster_Val[5]," = ",Cluster_Val_Sign[5],MathAbs(Cluster_Val_Move[5]),"\n", 
                                        Cluster_Val[6]," = ",Cluster_Val_Sign[6],MathAbs(Cluster_Val_Move[6]),"\n",
                                        Cluster_Val[7]," = ",Cluster_Val_Sign[7],MathAbs(Cluster_Val_Move[7]),"\n",
                                        "Сумма = ",Cluster_Val_MoveSum);                         
 Comment(Cluster_Val_Move_D);
//---  
 return(0);
} // end  of start()
//***********************************************************************************
//***********************************************************************************
int init()
{
//--- 
 for (i = 0; i <= 27; i++)
 {
  SL_SR        = StringConcatenate(S_SetL[i],S_SetR[i]);
  S_Digits [i] =                 MarketInfoF(SL_SR,MODE_DIGITS);
  S_Point  [i] = NormalizeDouble(MarketInfoF(SL_SR,MODE_POINT ),S_Digits[i]);
  S_BidPrev[i] = NormalizeDouble(MarketInfoF(SL_SR,MODE_BID   ),S_Digits[i]); 
 }
//---
 ArrayInitialize(Cluster_Val_Move,0 );
 Pref = StringConcatenate("DigitalClaster - начал работать с ",TimeToStr(TimeCurrent(),TIME_DATE|TIME_MINUTES),"(","время Торговой Платформы",")");
 Print(Pref);
 return(0);
}
//----------------------------------------------------------------------------
int deinit()
{
 Cluster_Val_Move_D =" ";
 Comment(Cluster_Val_Move_D);
 Pref = StringConcatenate("DigitalClaster - закончил работать в ",TimeToStr(TimeCurrent(),TIME_DATE|TIME_MINUTES),"(","время Торговой Платформы",")");
 Print(Pref);
 return(0);
}
//----------------------------------------------------------------------------
double MarketInfoF(string Sym,int Mode)
{
 double MarketInfoRes;
//---
 if (Sym != "GBPNZD") {MarketInfoRes = MarketInfo(Sym,Mode);}
 else 
 {
  switch(Mode)
  {
   case MODE_DIGITS  : MarketInfoRes = 5      ; break; 
   case MODE_POINT   : MarketInfoRes = 0.00001; break;
   case MODE_BID     : MarketInfoRes = NormalizeDouble(MarketInfo("GBPUSD",MODE_BID)/MarketInfo("NZDUSD",MODE_BID),5);  break; 
  }     
 }
//--- 
 if (MarketInfoRes <= 0) 
 {
  PlaySound("alert.wav");
  Pref = StringConcatenate("MarketInfo(",Sym,",",Mode,")"," возвратила ", MarketInfoRes);
  Print(Pref);
 }
 return(MarketInfoRes);
}
//+------------------------------------------------------------------+

