//+------------------------------------------------------------------+
//|                                             Sentiment_all_v2.mq4 |
//+------------------------------------------------------------------+

#property copyright "OnTheRoad"
#property link      "ontheroad7069@yahoo.com"

#define  MAX_CPAIRS  30
#define  MAX_SPAIRS  10

#define  EUR   0
#define  USD   1
#define  JPY   2
#define  GBP   3
#define  CAD   4
#define  CHF   5
#define  AUD   6
#define  NZD   7

#define  OIL   8
#define  GOLD  9

#property indicator_separate_window

#property indicator_buffers 8

#property indicator_color1 Red
#property indicator_color2 DarkViolet
#property indicator_color3 Chocolate
#property indicator_color4 Green
#property indicator_color5 DodgerBlue
#property indicator_color6 Aqua
#property indicator_color7 Chartreuse
#property indicator_color8 Gold

color indicator_clr1 = Red;         //EUR
color indicator_clr2 = DarkViolet;  //USD
color indicator_clr3 = Chocolate;   //JPY
color indicator_clr4 = Green;       //GBP
color indicator_clr5 = DodgerBlue;  //CAD
color indicator_clr6 = Aqua;        //CHF
color indicator_clr7 = Chartreuse;  //AUD
color indicator_clr8 = Gold;        //NZD

//---- input parameters
extern int       MA_Per       = 12;
extern int       Flt_Per      = 3;
extern int       Candle_Back  = 1;
extern int       History      = 144;
//---- buffers
double ExtMapBuffer1[];
double ExtMapBuffer2[];
double ExtMapBuffer3[];
double ExtMapBuffer4[];
double ExtMapBuffer5[];
double ExtMapBuffer6[];
double ExtMapBuffer7[];
double ExtMapBuffer8[];

static string symbols[MAX_CPAIRS]={

   "EURUSD",
   "USDJPY",
   "GBPUSD",
   "USDCAD",
   "USDCHF",
   "AUDUSD",
   "NZDUSD",
   
   "EURJPY",
   "EURGBP",
   "EURCAD",
   "EURCHF",
   "EURAUD",
   "EURNZD",
   
   "GBPJPY",
   "CADJPY",
   "CHFJPY",
   "AUDJPY",
   "NZDJPY",
   
   "GBPCAD",
   "GBPCHF",
   "GBPAUD",
   "GBPNZD",
   
   "CADCHF",
   "AUDCAD",
   "NZDCAD",
   
   "AUDCHF",
   "NZDCHF",
   
   "AUDNZD",

   "_QM",//Oil
   
   "GOLD",

   };
   
static double myarray[MAX_CPAIRS][5]; 
// 0=existance ; 1=cpp1 ; 2=cpp2 ; 3=buys_c_o_vol_cpp1 ; 4=buys_c_o_vol_cpp2 ;

static double coef_array[MAX_CPAIRS][2];

string indic_name = "Sentiment_All_v2 " ;
   
//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int init()
  {
//---- indicators

   IndicatorShortName(indic_name);
   
   SetIndexStyle(0,DRAW_LINE,STYLE_SOLID,2,indicator_color1);
   SetIndexBuffer(0,ExtMapBuffer1);
   SetIndexStyle(1,DRAW_LINE,STYLE_SOLID,2,indicator_color2);
   SetIndexBuffer(1,ExtMapBuffer2);
   SetIndexStyle(2,DRAW_LINE,STYLE_SOLID,2,indicator_color3);
   SetIndexBuffer(2,ExtMapBuffer3);
   SetIndexStyle(3,DRAW_LINE,STYLE_SOLID,2,indicator_color4);
   SetIndexBuffer(3,ExtMapBuffer4);
   SetIndexStyle(4,DRAW_LINE,STYLE_SOLID,2,indicator_color5);
   SetIndexBuffer(4,ExtMapBuffer5);
   SetIndexStyle(5,DRAW_LINE,STYLE_SOLID,2,indicator_color6);
   SetIndexBuffer(5,ExtMapBuffer6);
   SetIndexStyle(6,DRAW_LINE,STYLE_SOLID,2,indicator_color7);
   SetIndexBuffer(6,ExtMapBuffer7);
   SetIndexStyle(7,DRAW_LINE,STYLE_SOLID,2,indicator_color8);
   SetIndexBuffer(7,ExtMapBuffer8);
//----

   SetLevelValue( 0, 0 ) ;
   SetLevelStyle( STYLE_DOT , 1 , Silver ) ;


    //return;

   int i , j;
   
   Sleep(2000);
   
   for( i=0 ; i<MAX_CPAIRS ; i++ )
      for (j=0; j<5 ; j++ ) myarray[i][j]=0;
   // 0=existance ; 1=cpp1 ; 2=cpp2 ; 3=buys_c_o_vol_cpp1 ; 4=buys_c_o_vol_cpp2 ;
   
   RefreshRates( );
   
   for( i=0 ; i<MAX_CPAIRS ; i++ )  // CPairs existance in Broker MarketWatch list check
      if ( ( MarketInfo( symbols[i] , MODE_TRADEALLOWED )) || ( iVolume( symbols[i] , Period() , 1 ) != 0 ) || ( iVolume( symbols[i] , Period() , 2 ) != 0 )) myarray[i][0] = 1 ;
      

   for( i=0 ; i<MAX_CPAIRS ; i++ )
      {
      switch (i)
         {
         case  0:       //EURUSD
            myarray[i][1] = EUR;
            myarray[i][2] = USD;
            break;

         case  1:       //USDJPY
            myarray[i][1] = USD;
            myarray[i][2] = JPY;
            break;

         case  2:       //GBPUSD
            myarray[i][1] = GBP;
            myarray[i][2] = USD;
            break;

         case  3:       //USDCAD
            myarray[i][1] = USD;
            myarray[i][2] = CAD;
            break;

         case  4:       //USDCHF
            myarray[i][1] = USD;
            myarray[i][2] = CHF;
            break;

         case  5:       //AUDUSD
            myarray[i][1] = AUD;
            myarray[i][2] = USD;
            break;

         case  6:       //NZDUSD
            myarray[i][1] = NZD;
            myarray[i][2] = USD;
            break;

         case  7:       //EURJPY
            myarray[i][1] = EUR;
            myarray[i][2] = JPY;
            break;

         case  8:       //EURGBP
            myarray[i][1] = EUR;
            myarray[i][2] = GBP;
            break;

         case  9:       //EURCAD
            myarray[i][1] = EUR;
            myarray[i][2] = CAD;
            break;

         case  10:       //EURCHF
            myarray[i][1] = EUR;
            myarray[i][2] = CHF;
            break;

         case  11:       //EURAUD
            myarray[i][1] = EUR;
            myarray[i][2] = AUD;
            break;

         case  12:       //EURNZD
            myarray[i][1] = EUR;
            myarray[i][2] = NZD;
            break;

         case  13:       //GBPJPY
            myarray[i][1] = GBP;
            myarray[i][2] = JPY;
            break;

         case  14:       //CADJPY
            myarray[i][1] = CAD;
            myarray[i][2] = JPY;
            break;

         case  15:       //CHFJPY
            myarray[i][1] = CHF;
            myarray[i][2] = JPY;
            break;

         case  16:       //AUDJPY
            myarray[i][1] = AUD;
            myarray[i][2] = JPY;
            break;

         case  17:       //NZDJPY
            myarray[i][1] = NZD;
            myarray[i][2] = JPY;
            break;

         case  18:       //GBPCAD
            myarray[i][1] = GBP;
            myarray[i][2] = CAD;
            break;

         case  19:       //GBPCHF
            myarray[i][1] = GBP;
            myarray[i][2] = CHF;
            break;

         case  20:       //GBPAUD
            myarray[i][1] = GBP;
            myarray[i][2] = AUD;
            break;

         case  21:       //GBPNZD
            myarray[i][1] = GBP;
            myarray[i][2] = NZD;
            break;

         case  22:       //CADCHF
            myarray[i][1] = CAD;
            myarray[i][2] = CHF;
            break;

         case  23:       //AUDCAD
            myarray[i][1] = AUD;
            myarray[i][2] = CAD;
            break;

         case  24:       //NZDCAD
            myarray[i][1] = NZD;
            myarray[i][2] = CAD;
            break;

         case  25:       //AUDCHF
            myarray[i][1] = AUD;
            myarray[i][2] = CHF;
            break;

         case  26:       //NZDCHF
            myarray[i][1] = NZD;
            myarray[i][2] = CHF;
            break;

         case  27:       //AUDNZD
            myarray[i][1] = AUD;
            myarray[i][2] = NZD;
            break;

         case  28:       //OIL
            myarray[i][1] = OIL;
            myarray[i][2] = USD;
            break;

         case  29:       //GOLD
            myarray[i][1] = GOLD;
            myarray[i][2] = USD;
            break;

         }
      }

   return(0);
  }
//+------------------------------------------------------------------+
//| Custom indicator deinitialization function                       |
//+------------------------------------------------------------------+
int deinit()
  {
//----
   
//----
   return(0);
  }
//+------------------------------------------------------------------+
//| Custom indicator iteration function                              |
//+------------------------------------------------------------------+
int start()
  {
   int    i , j , k , l , limit , counted_bars , ctr ;
   double c_o , h_l , v , med , sign ;
   double auxary[][6];

 
   // return ;

   counted_bars = IndicatorCounted() ;

   if(counted_bars<0) return(-1);
   
   if(counted_bars>0) counted_bars--;


   limit = Bars-counted_bars;
   if ( limit > History ) limit = History;
   
   //return;
   
   if ( limit < 0 ) return(0);
   
   Comment ( " RefreshRates( )...." );
   RefreshRates( );

   if ( MA_Per < 1 ) MA_Per = 1 ;
   if ( Flt_Per < 1 ) Flt_Per = 1 ; 
   if ( Candle_Back < 1 ) Candle_Back = 1;
   
   j = ArrayResize ( auxary , MA_Per+1 );
   
   if ( j < MA_Per ) { Comment ( " Error ! ArrayResize ( auxary , MA_Per+1 ) = " , j ); return ; }

   
   for ( i = limit ; i >= 0 ; i -- ) 
      {
      ExtMapBuffer1[i]=0;
      ExtMapBuffer2[i]=0;
      ExtMapBuffer3[i]=0;
      ExtMapBuffer4[i]=0;
      ExtMapBuffer5[i]=0;
      ExtMapBuffer6[i]=0;
      ExtMapBuffer7[i]=0;
      ExtMapBuffer8[i]=0;
      }
 
   string mystr = " \n";
   ctr = 0;
   
   if ( myarray[0][0] == 1 ) { mystr = mystr + "EURUSD ,"; ctr ++ ; }
   if ( myarray[1][0] == 1 ) { mystr = mystr + "USDJPY ,"; ctr ++ ; }
   if ( myarray[2][0] == 1 ) { mystr = mystr + "GBPUSD ,"; ctr ++ ; }
   if ( myarray[3][0] == 1 ) { mystr = mystr + "USDCAD ,"; ctr ++ ; }
   if ( myarray[4][0] == 1 ) { mystr = mystr + "USDCHF ,"; ctr ++ ; }
   if ( myarray[5][0] == 1 ) { mystr = mystr + "AUDUSD ,"; ctr ++ ; }
   if ( myarray[6][0] == 1 ) { mystr = mystr + "NZDUSD ,"; ctr ++ ; if ( ctr % 7 == 0 ) mystr = mystr + " \n";}
   if ( myarray[7][0] == 1 ) { mystr = mystr + "EURJPY ,"; ctr ++ ; if ( ctr % 7 == 0 ) mystr = mystr + " \n";}
   if ( myarray[8][0] == 1 ) { mystr = mystr + "EURGBP ,"; ctr ++ ; if ( ctr % 7 == 0 ) mystr = mystr + " \n";}
   if ( myarray[9][0] == 1 ) { mystr = mystr + "EURCAD ,"; ctr ++ ; if ( ctr % 7 == 0 ) mystr = mystr + " \n";}
   if ( myarray[10][0] == 1 ) { mystr = mystr + "EURCHF ,"; ctr ++ ; if ( ctr % 7 == 0 ) mystr = mystr + " \n";}
   if ( myarray[11][0] == 1 ) { mystr = mystr + "EURAUD ,"; ctr ++ ; if ( ctr % 7 == 0 ) mystr = mystr + " \n";}
   if ( myarray[12][0] == 1 ) { mystr = mystr + "EURNZD ,"; ctr ++ ; if ( ctr % 7 == 0 ) mystr = mystr + " \n";}
   if ( myarray[13][0] == 1 ) { mystr = mystr + "GBPJPY ,"; ctr ++ ; if ( ctr % 7 == 0 ) mystr = mystr + " \n";}
   if ( myarray[14][0] == 1 ) { mystr = mystr + "CADJPY ,"; ctr ++ ; if ( ctr % 7 == 0 ) mystr = mystr + " \n";}
   if ( myarray[15][0] == 1 ) { mystr = mystr + "CHFJPY ,"; ctr ++ ; if ( ctr % 7 == 0 ) mystr = mystr + " \n";}
   if ( myarray[16][0] == 1 ) { mystr = mystr + "AUDJPY ,"; ctr ++ ; if ( ctr % 7 == 0 ) mystr = mystr + " \n";}
   if ( myarray[17][0] == 1 ) { mystr = mystr + "NZDJPY ,"; ctr ++ ; if ( ctr % 7 == 0 ) mystr = mystr + " \n";}
   if ( myarray[18][0] == 1 ) { mystr = mystr + "GBPCAD ,"; ctr ++ ; if ( ctr % 7 == 0 ) mystr = mystr + " \n";}
   if ( myarray[19][0] == 1 ) { mystr = mystr + "GBPCHF ,"; ctr ++ ; if ( ctr % 7 == 0 ) mystr = mystr + " \n";}
   if ( myarray[20][0] == 1 ) { mystr = mystr + "GBPAUD ,"; ctr ++ ; if ( ctr % 7 == 0 ) mystr = mystr + " \n";}
   if ( myarray[21][0] == 1 ) { mystr = mystr + "GBPNZD ,"; ctr ++ ; if ( ctr % 7 == 0 ) mystr = mystr + " \n";}
   if ( myarray[22][0] == 1 ) { mystr = mystr + "CADCHF ,"; ctr ++ ; if ( ctr % 7 == 0 ) mystr = mystr + " \n";}
   if ( myarray[23][0] == 1 ) { mystr = mystr + "AUDCAD ,"; ctr ++ ; if ( ctr % 7 == 0 ) mystr = mystr + " \n";}
   if ( myarray[24][0] == 1 ) { mystr = mystr + "NZDCAD ,"; ctr ++ ; if ( ctr % 7 == 0 ) mystr = mystr + " \n";}
   if ( myarray[25][0] == 1 ) { mystr = mystr + "AUDCHF ,"; ctr ++ ; if ( ctr % 7 == 0 ) mystr = mystr + " \n";}
   if ( myarray[26][0] == 1 ) { mystr = mystr + "NZDCHF ,"; ctr ++ ; if ( ctr % 7 == 0 ) mystr = mystr + " \n";}
   if ( myarray[27][0] == 1 ) { mystr = mystr + "AUDNZD ,"; ctr ++ ; if ( ctr % 7 == 0 ) mystr = mystr + " \n";}
   if ( myarray[28][0] == 1 ) { mystr = mystr + "OIL ,"; ctr ++ ; if ( ctr % 7 == 0 ) mystr = mystr + " \n";}
   if ( myarray[29][0] == 1 ) { mystr = mystr + "GOLD"; ctr ++ ; }
   
   mystr = mystr + " ...total cpairs= " + DoubleToStr( ctr, 0) ; /* +
    "\n Bars= " + DoubleToStr( Bars , 0) + " ,counted_bars = " + DoubleToStr( counted_bars , 0) + " ,limit= " + DoubleToStr( limit , 0) ;*/
   

   Comment ( mystr );

 
 for ( i = limit ; i >= 0 ; i -- ) 
  {
  
  for ( j = i + MA_Per - 1 ; j >= i ; j -- )
    {

   // 0=existance ; 1=cpp1 ; 2=cpp2 ; 3=buys_c_o_vol_cpp1 ; 4=buys_c_o_vol_cpp2 ;

    coef_extract ( j + Candle_Back / 2 ) ;         

    for ( k = 0 ; k < MAX_CPAIRS ; k ++ )
      {
      myarray[k][3] = 0;
      myarray[k][4] = 0;
      if ( myarray[k][0] == 1 )
         {
         //med = ( iHigh(symbols[k] , Period() , j ) + iLow(symbols[k] , Period() , j ) + iClose(symbols[k] , Period() , j ) ) / 3 ;

         c_o = ( iClose(symbols[k] , Period() , j ) - iOpen(symbols[k] , Period() , j+Candle_Back ) ) ;
         double myHigh = iHigh(symbols[k] , Period() , iHighest(symbols[k] , Period() , MODE_HIGH , Candle_Back , j ) );
         double myLow  = iLow (symbols[k] , Period() , iLowest (symbols[k] , Period() , MODE_LOW , Candle_Back , j ) );
         //h_l = (  iHigh(symbols[k] , Period() , j ) - iLow(symbols[k] , Period() , j+Candle_Back )  ) ;
         h_l = myHigh - myLow ;
         
         sign = 1 ;
         if ( c_o < 0 ) sign = -1 ;

         // if ( h_l != 0 ) c_o /= h_l ;
                  
         //if ( sign == 1 ) c_o += h_l;
         //else c_o -= h_l;
         
         v = 0 ;
         for ( l = 0 ; l < Candle_Back ; l ++ )
         v += ( iVolume(symbols[k] , Period() , j+l ) ) ;
         
         int spreadx = MarketInfo( symbols[k] , MODE_SPREAD ) ;
         double pointx = MarketInfo( symbols[k] , MODE_POINT ) ;

         if ( h_l == 0 ) h_l = pointx ;

         if ( c_o > spreadx * pointx / 1 ) c_o = c_o - spreadx * pointx / 1 ;
         else if ( c_o < -spreadx * pointx / 1 ) c_o = c_o + spreadx * pointx / 1 ;
         else c_o = 0 ;
         
         c_o /= h_l ;
         
         myarray[k][3] =   c_o * v * coef_array[k][0] / dollar_per_hklot ( k , j + Candle_Back / 2 ) ;
         myarray[k][4] = - myarray[k][3] ;
         }
         else
         {
         myarray[k][3] = 0 ;  
         myarray[k][4] = 0 ;
         }
      }

    for ( k = 0 ; k < MAX_CPAIRS ; k ++ )
      { 
      if ( myarray[k][1] == EUR ) ExtMapBuffer1[i] += 1.0 * myarray[k][3] / MA_Per ;
      if ( myarray[k][2] == EUR ) ExtMapBuffer1[i] += 1.0 * myarray[k][4] / MA_Per ;

      if ( myarray[k][1] == USD ) ExtMapBuffer2[i] += 1.0 * myarray[k][3] / MA_Per ;
      if ( myarray[k][2] == USD ) ExtMapBuffer2[i] += 1.0 * myarray[k][4] / MA_Per ;

      if ( myarray[k][1] == JPY ) ExtMapBuffer3[i] += 1.00 * myarray[k][3] / MA_Per ;
      if ( myarray[k][2] == JPY ) ExtMapBuffer3[i] += 1.00 * myarray[k][4] / MA_Per ;

      if ( myarray[k][1] == GBP ) ExtMapBuffer4[i] += 1.0 * myarray[k][3] / MA_Per ;
      if ( myarray[k][2] == GBP ) ExtMapBuffer4[i] += 1.0 * myarray[k][4] / MA_Per ;

      if ( myarray[k][1] == CAD ) ExtMapBuffer5[i] += 1.0 * myarray[k][3] / MA_Per ;
      if ( myarray[k][2] == CAD ) ExtMapBuffer5[i] += 1.0 * myarray[k][4] / MA_Per ;
      
      if ( myarray[k][1] == CHF ) ExtMapBuffer6[i] += 1.0 * myarray[k][3] / MA_Per ;
      if ( myarray[k][2] == CHF ) ExtMapBuffer6[i] += 1.0 * myarray[k][4] / MA_Per ;

      if ( myarray[k][1] == AUD ) ExtMapBuffer7[i] += 1.0 * myarray[k][3] / MA_Per ;
      if ( myarray[k][2] == AUD ) ExtMapBuffer7[i] += 1.0 * myarray[k][4] / MA_Per ;

      if ( myarray[k][1] == NZD ) ExtMapBuffer8[i] += 1.0 * myarray[k][3] / MA_Per ;
      if ( myarray[k][2] == NZD ) ExtMapBuffer8[i] += 1.0 * myarray[k][4] / MA_Per ;
      }
      
    }  // j MA


   if ( i < limit - Flt_Per )
      for ( j = Flt_Per-1 ; j >= 0 ; j -- )
         {
         ExtMapBuffer1[i] += ExtMapBuffer1[i+j] / Flt_Per ;
         ExtMapBuffer2[i] += ExtMapBuffer2[i+j] / Flt_Per ;
         ExtMapBuffer3[i] += ExtMapBuffer3[i+j] / Flt_Per ;
         ExtMapBuffer4[i] += ExtMapBuffer4[i+j] / Flt_Per ;
         ExtMapBuffer5[i] += ExtMapBuffer5[i+j] / Flt_Per ;
         ExtMapBuffer6[i] += ExtMapBuffer6[i+j] / Flt_Per ;
         ExtMapBuffer7[i] += ExtMapBuffer7[i+j] / Flt_Per ;
         ExtMapBuffer8[i] += ExtMapBuffer8[i+j] / Flt_Per ;
         }
    
     sign = 1 ; if ( ExtMapBuffer1[i] < 0 ) sign = -1 ; ExtMapBuffer1[i] = sign * MathSqrt(sign * ExtMapBuffer1[i]) ;
     sign = 1 ; if ( ExtMapBuffer2[i] < 0 ) sign = -1 ; ExtMapBuffer2[i] = sign * MathSqrt(sign * ExtMapBuffer2[i]) ;
     sign = 1 ; if ( ExtMapBuffer3[i] < 0 ) sign = -1 ; ExtMapBuffer3[i] = sign * MathSqrt(sign * ExtMapBuffer3[i]) ;
     sign = 1 ; if ( ExtMapBuffer4[i] < 0 ) sign = -1 ; ExtMapBuffer4[i] = sign * MathSqrt(sign * ExtMapBuffer4[i]) ;
     sign = 1 ; if ( ExtMapBuffer5[i] < 0 ) sign = -1 ; ExtMapBuffer5[i] = sign * MathSqrt(sign * ExtMapBuffer5[i]) ;
     sign = 1 ; if ( ExtMapBuffer6[i] < 0 ) sign = -1 ; ExtMapBuffer6[i] = sign * MathSqrt(sign * ExtMapBuffer6[i]) ;
     sign = 1 ; if ( ExtMapBuffer7[i] < 0 ) sign = -1 ; ExtMapBuffer7[i] = sign * MathSqrt(sign * ExtMapBuffer7[i]) ;
     sign = 1 ; if ( ExtMapBuffer8[i] < 0 ) sign = -1 ; ExtMapBuffer8[i] = sign * MathSqrt(sign * ExtMapBuffer8[i]) ;

    
  } // i main indic


#define First_Loc 400

    if ( WindowFind(indic_name) != -1 )
        {
        ObjectCreate("EUR", OBJ_LABEL, WindowFind(indic_name), 0, 0);
        ObjectSetText("EUR","EUR",12, "Arial Bold");
        ObjectSet("EUR", OBJPROP_COLOR, indicator_clr1);
        ObjectSet("EUR", OBJPROP_CORNER, 0);
        ObjectSet("EUR", OBJPROP_XDISTANCE, First_Loc);
        ObjectSet("EUR", OBJPROP_YDISTANCE, 3);
        
        ObjectCreate("USD", OBJ_LABEL, WindowFind(indic_name), 0, 0);
        ObjectSetText("USD","USD",12, "Arial Bold");
        ObjectSet("USD", OBJPROP_COLOR, indicator_clr2);
        ObjectSet("USD", OBJPROP_CORNER, 0);
        ObjectSet("USD", OBJPROP_XDISTANCE, First_Loc+40);
        ObjectSet("USD", OBJPROP_YDISTANCE, 3);

        ObjectCreate("JPY", OBJ_LABEL, WindowFind(indic_name), 0, 0);
        ObjectSetText("JPY","JPY",12, "Arial Bold");
        ObjectSet("JPY", OBJPROP_COLOR, indicator_clr3);
        ObjectSet("JPY", OBJPROP_CORNER, 0);
        ObjectSet("JPY", OBJPROP_XDISTANCE, First_Loc+80);
        ObjectSet("JPY", OBJPROP_YDISTANCE, 3);
        
        ObjectCreate("GBP", OBJ_LABEL, WindowFind(indic_name), 0, 0);
        ObjectSetText("GBP","GBP",12, "Arial Bold");
        ObjectSet("GBP", OBJPROP_COLOR, indicator_clr4);
        ObjectSet("GBP", OBJPROP_CORNER, 0);
        ObjectSet("GBP", OBJPROP_XDISTANCE, First_Loc+120);
        ObjectSet("GBP", OBJPROP_YDISTANCE, 3);
        
        ObjectCreate("CAD", OBJ_LABEL, WindowFind(indic_name), 0, 0);
        ObjectSetText("CAD","CAD",12, "Arial Bold");
        ObjectSet("CAD", OBJPROP_COLOR, indicator_clr5);
        ObjectSet("CAD", OBJPROP_CORNER, 0);
        ObjectSet("CAD", OBJPROP_XDISTANCE, First_Loc+160);
        ObjectSet("CAD", OBJPROP_YDISTANCE, 3);
        
        ObjectCreate("CHF", OBJ_LABEL, WindowFind(indic_name), 0, 0);
        ObjectSetText("CHF","CHF",12, "Arial Bold");
        ObjectSet("CHF", OBJPROP_COLOR, indicator_clr6);
        ObjectSet("CHF", OBJPROP_CORNER, 0);
        ObjectSet("CHF", OBJPROP_XDISTANCE, First_Loc+200);
        ObjectSet("CHF", OBJPROP_YDISTANCE, 3);
        
        ObjectCreate("AUD", OBJ_LABEL, WindowFind(indic_name), 0, 0);
        ObjectSetText("AUD","AUD",12, "Arial Bold");
        ObjectSet("AUD", OBJPROP_COLOR, indicator_clr7);
        ObjectSet("AUD", OBJPROP_CORNER, 0);
        ObjectSet("AUD", OBJPROP_XDISTANCE, First_Loc+240);
        ObjectSet("AUD", OBJPROP_YDISTANCE, 3);
        
        ObjectCreate("NZD", OBJ_LABEL, WindowFind(indic_name), 0, 0);
        ObjectSetText("NZD","NZD",12, "Arial Bold");
        ObjectSet("NZD", OBJPROP_COLOR, indicator_clr8);
        ObjectSet("NZD", OBJPROP_CORNER, 0);
        ObjectSet("NZD", OBJPROP_XDISTANCE, First_Loc+280);
        ObjectSet("NZD", OBJPROP_YDISTANCE, 3);
    }
   
//----
   return(0);
  }
//+------------------------------------------------------------------+



   double median_extract ( int symbolx , int per , int shift )
      {
      return ( ( iHigh( symbolx ,  per , shift ) + iLow( symbolx ,  per , shift ) + iClose( symbolx ,  per , shift ) ) / 3 ) ;
      }

//+------------------------------------------------------------------+

   void  coef_extract ( int shift )
   {
   int i ;
   for( i = 0 ; i < MAX_CPAIRS ; i ++ )
      {
      switch (i)
         {

         case  0:       //EURUSD
            coef_array[i][0] = median_extract ( "EURUSD" , Period() , shift ) ; // EUR
            coef_array[i][1] = median_extract ( "EURUSD" , Period() , shift ) ; // USD;
            break;

         case  1:       //USDJPY
            coef_array[i][0] = 1 ; // USD;
            coef_array[i][1] = 0.01 * median_extract ( "USDJPY" , Period() , shift ) ; // JPY;
            break;

         case  2:       //GBPUSD
            coef_array[i][0] = median_extract ( "GBPUSD" , Period() , shift ) ; // GBP;
            coef_array[i][1] = median_extract ( "GBPUSD" , Period() , shift ) ; // USD;
            break;

         case  3:       //USDCAD
            coef_array[i][0] = 1 ; // USD;
            coef_array[i][1] = median_extract ( "USDCAD" , Period() , shift ) ; // CAD;
            break;

         case  4:       //USDCHF
            coef_array[i][0] = 1 ; // USD;
            coef_array[i][1] = median_extract ( "USDCHF" , Period() , shift ) ; // CHF;
            break;

         case  5:       //AUDUSD
            coef_array[i][0] = median_extract ( "AUDUSD" , Period() , shift ) ; // AUD;
            coef_array[i][1] = median_extract ( "AUDUSD" , Period() , shift ) ; // USD;
            break;

         case  6:       //NZDUSD
            coef_array[i][0] = median_extract ( "NZDUSD" , Period() , shift ) ; // NZD;
            coef_array[i][1] = median_extract ( "NZDUSD" , Period() , shift ) ; // USD;
            break;

         case  7:       //EURJPY
            coef_array[i][0] = median_extract ( "EURUSD" , Period() , shift ) ; // EUR;
            coef_array[i][1] = median_extract ( "EURUSD" , Period() , shift ) ; // JPY;
            break;

         case  8:       //EURGBP
            coef_array[i][0] = median_extract ( "EURUSD" , Period() , shift ) ; // EUR;
            coef_array[i][1] = median_extract ( "EURUSD" , Period() , shift ) ; // GBP;
            break;

         case  9:       //EURCAD
            coef_array[i][0] = median_extract ( "EURUSD" , Period() , shift ) ; // EUR;
            coef_array[i][1] = median_extract ( "EURUSD" , Period() , shift ) ; // CAD;
            break;

         case  10:       //EURCHF
            coef_array[i][0] = median_extract ( "EURUSD" , Period() , shift ) ; // EUR;
            coef_array[i][1] = median_extract ( "EURUSD" , Period() , shift ) ; // CHF;
            break;

         case  11:       //EURAUD
            coef_array[i][0] = median_extract ( "EURUSD" , Period() , shift ) ; // EUR;
            coef_array[i][1] = median_extract ( "EURUSD" , Period() , shift ) ; // AUD;
            break;

         case  12:       //EURNZD
            coef_array[i][0] = median_extract ( "EURUSD" , Period() , shift ) ; // EUR;
            coef_array[i][1] = median_extract ( "EURUSD" , Period() , shift ) ; // NZD;
            break;

         case  13:       //GBPJPY
            coef_array[i][0] = median_extract ( "GBPUSD" , Period() , shift ) ; // GBP;
            coef_array[i][1] = median_extract ( "GBPUSD" , Period() , shift ) ; // JPY;
            break;

         case  14:       //CADJPY
            coef_array[i][0] = 1 / median_extract ( "USDCAD" , Period() , shift ) ; // CAD;
            coef_array[i][1] = 1 / median_extract ( "USDCAD" , Period() , shift ) ; // JPY;
            break;

         case  15:       //CHFJPY
            coef_array[i][0] = 1 / median_extract ( "USDCHF" , Period() , shift ) ; // CHF;
            coef_array[i][1] = 1 / median_extract ( "USDCHF" , Period() , shift ) ; // JPY;
            break;

         case  16:       //AUDJPY
            coef_array[i][0] = median_extract ( "AUDUSD" , Period() , shift ) ; // AUD;
            coef_array[i][1] = median_extract ( "AUDUSD" , Period() , shift ) ; // JPY;
            break;

         case  17:       //NZDJPY
            coef_array[i][0] = median_extract ( "NZDUSD" , Period() , shift ) ; // NZD;
            coef_array[i][1] = median_extract ( "NZDUSD" , Period() , shift ) ; // JPY;
            break;

         case  18:       //GBPCAD
            coef_array[i][0] = median_extract ( "GBPUSD" , Period() , shift ) ; // GBP;
            coef_array[i][1] = median_extract ( "GBPUSD" , Period() , shift ) ; // CAD;
            break;

         case  19:       //GBPCHF
            coef_array[i][0] = median_extract ( "GBPUSD" , Period() , shift ) ; // GBP;
            coef_array[i][1] = median_extract ( "GBPUSD" , Period() , shift ) ; // CHF;
            break;

         case  20:       //GBPAUD
            coef_array[i][0] = median_extract ( "GBPUSD" , Period() , shift ) ; // GBP;
            coef_array[i][1] = median_extract ( "GBPUSD" , Period() , shift ) ; // AUD;
            break;

         case  21:       //GBPNZD
            coef_array[i][0] = median_extract ( "GBPUSD" , Period() , shift ) ; // GBP;
            coef_array[i][1] = median_extract ( "GBPUSD" , Period() , shift ) ; // NZD;
            break;

         case  22:       //CADCHF
            coef_array[i][0] = 1 / median_extract ( "USDCAD" , Period() , shift ) ; // CAD;
            coef_array[i][1] = 1 / median_extract ( "USDCAD" , Period() , shift ) ; // CHF;
            break;

         case  23:       //AUDCAD
            coef_array[i][0] = median_extract ( "AUDUSD" , Period() , shift ) ; // AUD;
            coef_array[i][1] = median_extract ( "AUDUSD" , Period() , shift ) ; // CAD;
            break;

         case  24:       //NZDCAD
            coef_array[i][0] = median_extract ( "NZDUSD" , Period() , shift ) ; // NZD;
            coef_array[i][1] = median_extract ( "NZDUSD" , Period() , shift ) ; // CAD;
            break;

         case  25:       //AUDCHF
            coef_array[i][0] = median_extract ( "AUDUSD" , Period() , shift ) ; // AUD;
            coef_array[i][1] = median_extract ( "AUDUSD" , Period() , shift ) ; // CHF;
            break;

         case  26:       //NZDCHF
            coef_array[i][0] = median_extract ( "NZDUSD" , Period() , shift ) ; // NZD;
            coef_array[i][1] = median_extract ( "NZDUSD" , Period() , shift ) ; // CHF;
            break;

         case  27:       //AUDNZD
            coef_array[i][0] = median_extract ( "AUDUSD" , Period() , shift ) ; // AUD;
            coef_array[i][1] = median_extract ( "AUDUSD" , Period() , shift ) ; // NZD;
            break;

         case  28:       //OIL
            coef_array[i][0] = median_extract ( "_QM" , Period() , shift ) ; // OIL;
            coef_array[i][1] = 1 ; // USD;
            break;

         case  29:       //GOLD
            coef_array[i][0] = median_extract ( "GOLD" , Period() , shift ) ; // GOLD;
            coef_array[i][1] = 1 ; // USD;
            break;

         }
      }
   return;
   }
   
//////////////////////////////////////////////////////

double dollar_per_hklot ( int cpair , int shift )
   {
      switch (cpair)
         {

         case  0:       //EURUSD
            return ( median_extract ( "EURUSD" , Period() , shift ) ) ;
            break;

         case  1:       //USDJPY
            return ( 1 ) ;
            break;

         case  2:       //GBPUSD
            return ( median_extract ( "GBPUSD" , Period() , shift ) ) ;
            break;

         case  3:       //USDCAD
            return ( 1 ) ;
            break;

         case  4:       //USDCHF
            return ( 1 ) ;
            break;

         case  5:       //AUDUSD
            return ( median_extract ( "AUDUSD" , Period() , shift ) ) ;
            break;

         case  6:       //NZDUSD
            return ( median_extract ( "NZDUSD" , Period() , shift ) ) ;
            break;

         case  7:       //EURJPY
            return ( median_extract ( "EURUSD" , Period() , shift ) ) ;
            break;

         case  8:       //EURGBP
            return ( median_extract ( "EURUSD" , Period() , shift ) ) ;
            break;

         case  9:       //EURCAD
            return ( median_extract ( "EURUSD" , Period() , shift ) ) ;
            break;

         case  10:       //EURCHF
            return ( median_extract ( "EURUSD" , Period() , shift ) ) ;
            break;

         case  11:       //EURAUD
            return ( median_extract ( "EURUSD" , Period() , shift ) ) ;
            break;

         case  12:       //EURNZD
            return ( median_extract ( "EURUSD" , Period() , shift ) ) ;
            break;

         case  13:       //GBPJPY
            return ( median_extract ( "GBPUSD" , Period() , shift ) ) ;
            break;

         case  14:       //CADJPY
            return ( 1 / median_extract ( "USDCAD" , Period() , shift ) ) ;
            break;

         case  15:       //CHFJPY
            return ( 1 / median_extract ( "USDCHF" , Period() , shift ) ) ;
            break;

         case  16:       //AUDJPY
            return ( median_extract ( "AUDUSD" , Period() , shift ) ) ;
            break;

         case  17:       //NZDJPY
            return ( median_extract ( "NZDUSD" , Period() , shift ) ) ;
            break;

         case  18:       //GBPCAD
            return ( median_extract ( "GBPUSD" , Period() , shift ) ) ;
            break;

         case  19:       //GBPCHF
            return ( median_extract ( "GBPUSD" , Period() , shift ) ) ;
            break;

         case  20:       //GBPAUD
            return ( median_extract ( "GBPUSD" , Period() , shift ) ) ;
            break;

         case  21:       //GBPNZD
            return ( median_extract ( "GBPUSD" , Period() , shift ) ) ;
            break;

         case  22:       //CADCHF
            return ( 1 / median_extract ( "USDCAD" , Period() , shift ) ) ;
            break;

         case  23:       //AUDCAD
            return ( median_extract ( "AUDUSD" , Period() , shift ) ) ;
            break;

         case  24:       //NZDCAD
            return ( median_extract ( "NZDUSD" , Period() , shift ) ) ;
            break;

         case  25:       //AUDCHF
            return ( median_extract ( "AUDUSD" , Period() , shift ) ) ;
            break;

         case  26:       //NZDCHF
            return ( median_extract ( "NZDUSD" , Period() , shift ) ) ;
            break;

         case  27:       //AUDNZD
            return ( median_extract ( "AUDUSD" , Period() , shift ) ) ;
            break;

         case  28:       //OIL
            return ( 5000 * median_extract( "_QM" , Period() , shift ) / 100000 ) ;
            break;

         case  29:       //GOLD
            return ( 100 * median_extract( "GOLD" , Period() , shift ) / 100000 ) ;
            break;

         }
      return ( 1 ) ;
   }   