//+------------------------------------------------------------------+
//|                                                Strength_Indi.mq4 |
//|                        Copyright 2015, MetaQuotes Software Corp. |
//|                                              http://www.mql5.com |
//+------------------------------------------------------------------+
#property copyright "Copyright 2015, MetaQuotes Software Corp."
#property link      "http://www.mql5.com"
#property version   "1.00"
#property strict
#property indicator_chart_window

#include <NewsInc_V1.1.mqh>

sinput string masterPreamble = "V10_strength_Bundle_";
sinput int UpdateInSeconds  = 2;

sinput int xAnchor = 600;
sinput int yAnchor = 100;

int xWidth = 50;
int yHeight = 20;
int xSpace = 10;
int ySpace = 5;
color ClrText = clrBlack;
color ClrBackground = clrBlack;
color ClrBorder = clrBlack;
int fontSize = 8;

sinput int minutesBeforeNews = 60;
sinput int minutesAfterNews = 30;



int panelWidth = 500;
int panelHeight = 400;
string panelName, labelName;



string DefaultPairs[] = {  "AUDCAD","AUDCHF","AUDJPY","AUDNZD","AUDUSD","CADCHF",
                           "CADJPY","CHFJPY","EURAUD","EURCAD","EURCHF","EURGBP","EURJPY","EURNZD","EURUSD",
                           "GBPAUD","GBPCAD","GBPCHF","GBPJPY","GBPNZD","GBPUSD","NZDCAD","NZDCHF",
                           "NZDJPY","NZDUSD","USDCAD","USDCHF","USDJPY"
                        };
                           
string Currencies[] = {"EUR", "GBP", "AUD", "NZD", "CHF", "CAD", "JPY", "USD"};

color CurrenciesColorsBG[] = {  clrLightGreen, clrAzure, clrPink, clrLightGoldenrod, clrBisque, clrLightSalmon, clrLightSkyBlue};
color CurrenciesColorsFG[] = {  clrBlack, clrBlack, clrBlack, clrBlack, clrBlack, clrBlack, clrBlack};

struct pair_Data
{
   string pairName;
   
   double MyPoint;
   double MyDigits;
   double MyMultiplier;
   
   double pBid;
   double pAsk;
   double spread;
   
   string Base;
   string Quote;

   int newsInfo;
   
   bool cross_Previous_TF1_Up;
   bool cross_Previous_TF1_Dn;
   bool cross_Previous_TF2_Up;
   bool cross_Previous_TF2_Dn;
   bool cross_Previous_TF3_Up;
   bool cross_Previous_TF3_Dn;
   bool cross_Previous_TF4_Up;
   bool cross_Previous_TF4_Dn;
   
   bool cross_TF1_Up;
   bool cross_TF1_Dn;
   bool cross_TF2_Up;
   bool cross_TF2_Dn;
   bool cross_TF3_Up;
   bool cross_TF3_Dn;
   bool cross_TF4_Up;
   bool cross_TF4_Dn;
   
   int previousCrossCounterGap;
   int crossCounterGap;
   
};

pair_Data pairData[28];

struct currency_Data
{
   string currencyName; // ("EUR", "GBP", "AUD", "NZD", "CHF", "CAD", "JPY", "USD");

   int crossUp_Counter;
   int crossDn_Counter;
   
   int previousCrossUp_Counter;
   int previousCrossDn_Counter;

};

currency_Data currencyData[8];
   
int xMultiplier = 0;
int yMultiplier = 0;
   
static datetime newM1_bar = 0;
static datetime newMinute = 0;

//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int OnInit()
  {
//--- indicator buffers mapping
   
//---

  string s;
  string name;
    s = masterPreamble; //_symbolPair;
    //s = Symbol();
    for (int i = ObjectsTotal() - 1; i >= 0; i--)
    {
        name = ObjectName(i);
        if (StringSubstr(name, 0, StringLen(s)) == s)
        {
            ObjectDelete(name);
        }
    }
   EventSetTimer(UpdateInSeconds);
   
      // news init
   ExternalNewsInit();
   
   // make the dashboard
   // calculate with
   panelWidth = 0;
   panelWidth = panelWidth + (xWidth + xSpace) * 3;

   panelWidth = panelWidth + 3 * xSpace; // + xWidth;
   panelHeight = 9 * yHeight + 10 * ySpace;
   
   panelName = masterPreamble + "MainPanel";
   SetPanel(panelName,0,xAnchor, yAnchor - 20,panelWidth,panelHeight + 20,clrLightGray,clrWhiteSmoke,3);
   SetText(masterPreamble + "_label_indiName","Strength",xAnchor + xSpace,yAnchor - 15,clrBlack, fontSize);
   
   SetText(masterPreamble + "_label_CurrencyName","Currency",xAnchor + xSpace,yAnchor +5,clrBlack, fontSize);
   SetText(masterPreamble + "_label_ValueName","Value",xAnchor + 2*xSpace + xWidth,yAnchor +5,clrBlack, fontSize);
   SetText(masterPreamble + "_label_NewsName","News",xAnchor + 3*xSpace + 2*xWidth,yAnchor +5,clrBlack, fontSize);
   
   
   newM1_bar = 0;
   newMinute = 0;
   
   for (int g=0; g < 28; g ++)
   {
      pairData[g].pairName = DefaultPairs[g];
      pairData[g].Base = StringSubstr(pairData[g].pairName,0,3);
      pairData[g].Quote = StringSubstr(pairData[g].pairName,3,3);
   }
   for ( int gg = 0; gg < 8; gg++)
   {
      currencyData[gg].currencyName = Currencies[gg];
   }

   return(INIT_SUCCEEDED);
  }
  
//+------------------------------------------------------------------+
//| Indicator deinitialization function                                 |
//+------------------------------------------------------------------+
void OnDeinit(const int reason)
  {
//--- destroy timer
  EventKillTimer();
  string s;
  string name;
    s = masterPreamble; //_symbolPair;
    //s = Symbol();
    for (int i = ObjectsTotal() - 1; i >= 0; i--)
    {
        name = ObjectName(i);
        if (StringSubstr(name, 0, StringLen(s)) == s)
        {
            ObjectDelete(name);
        }
    }
    

      
  }
//+------------------------------------------------------------------+
//| Custom indicator iteration function                              |
//+------------------------------------------------------------------+
int OnCalculate(const int rates_total,
                const int prev_calculated,
                const datetime &time[],
                const double &open[],
                const double &high[],
                const double &low[],
                const double &close[],
                const long &tick_volume[],
                const long &volume[],
                const int &spread[])
  {
//---
   
//--- return value of prev_calculated for next call
   return(rates_total);
  }
//+------------------------------------------------------------------+
//| Timer function                                                   |
//+------------------------------------------------------------------+
void OnTimer()
  {
//---


// display several gaps
   
   string tmpString;
   string tmpTF = "TF2";
   double value_1, value_2, value_3, value_4, value_5, value_6;
   
   if (newMinute != iTime("EURUSD",PERIOD_M1,0))
   {
      for (int g=0; g < 28; g ++)
      {
         pairData[g].previousCrossCounterGap = pairData[g].crossCounterGap;
      }
      for ( int gg = 0; gg < 8; gg++)
      {
         currencyData[gg].previousCrossUp_Counter = currencyData[gg].crossUp_Counter;
      }
      newMinute = iTime("EURUSD", PERIOD_M1,0);
   }
   
   //string tmpString;
   tmpTF = "TF2";
   for (int y=0; y < 28; y++)
   {
      tmpString = "Power_" + pairData[y].Base + "_PrePrevious_Gap_" + tmpTF;
      value_1 = GlobalVariableGet(tmpString);
      tmpString = "Power_" + pairData[y].Quote + "_PrePrevious_Gap_" + tmpTF;
      value_2 = GlobalVariableGet(tmpString);
      value_3 = value_1 - value_2;
      tmpString = "Power_" + pairData[y].Base + "_Previous_Gap_" + tmpTF;
      value_1 = GlobalVariableGet(tmpString);
      tmpString = "Power_" + pairData[y].Quote + "_Previous_Gap_" + tmpTF;
      value_2 = GlobalVariableGet(tmpString);
      value_4 = value_1 - value_2;
      if ((value_4 > 0) && (value_3 < 0))
      {
         pairData[y].cross_Previous_TF1_Up = true;
         pairData[y].cross_Previous_TF1_Dn = false;
      }
      else if ((value_4 < 0) && (value_3 > 0))
      {
         pairData[y].cross_Previous_TF1_Up = false;
         pairData[y].cross_Previous_TF1_Dn = true;
      }
      else
      {
         pairData[y].cross_Previous_TF1_Up = false;
         pairData[y].cross_Previous_TF1_Dn = false;
      }
      
      tmpString = "Power_" + pairData[y].Base + "_Gap_" + tmpTF;
      value_5 = GlobalVariableGet(tmpString);
      tmpString = "Power_" + pairData[y].Quote + "_Gap_" + tmpTF;
      value_6 = GlobalVariableGet(tmpString);
      value_3 = value_5 - value_6;
      if ((value_3 > 0) && (value_4 < 0))
      {
         pairData[y].cross_TF1_Up = true;
         pairData[y].cross_TF1_Dn = false;
      }
      else if ((value_3 < 0) && (value_4 > 0))
      {
         pairData[y].cross_TF1_Up = false;
         pairData[y].cross_TF1_Dn = true;
      }
      else
      {
         pairData[y].cross_TF1_Up = false;
         pairData[y].cross_TF1_Dn = false;
      }
      //// TF3
      tmpTF = "TF3";
      tmpString = "Power_" + pairData[y].Base + "_PrePrevious_Gap_" + tmpTF;
      value_1 = GlobalVariableGet(tmpString);
      tmpString = "Power_" + pairData[y].Quote + "_PrePrevious_Gap_" + tmpTF;
      value_2 = GlobalVariableGet(tmpString);
      value_3 = value_1 - value_2;
      tmpString = "Power_" + pairData[y].Base + "_Previous_Gap_" + tmpTF;
      value_1 = GlobalVariableGet(tmpString);
      tmpString = "Power_" + pairData[y].Quote + "_Previous_Gap_" + tmpTF;
      value_2 = GlobalVariableGet(tmpString);
      value_4 = value_1 - value_2;
      if ((value_4 > 0) && (value_3 < 0))
      {
         pairData[y].cross_Previous_TF2_Up = true;
         pairData[y].cross_Previous_TF2_Dn = false;
      }
      else if ((value_4 < 0) && (value_3 > 0))
      {
         pairData[y].cross_Previous_TF2_Up = false;
         pairData[y].cross_Previous_TF2_Dn = true;
      }
      else
      {
         pairData[y].cross_Previous_TF2_Up = false;
         pairData[y].cross_Previous_TF2_Dn = false;
      }
      
      tmpString = "Power_" + pairData[y].Base + "_Gap_" + tmpTF;
      value_5 = GlobalVariableGet(tmpString);
      tmpString = "Power_" + pairData[y].Quote + "_Gap_" + tmpTF;
      value_6 = GlobalVariableGet(tmpString);
      value_3 = value_5 - value_6;
      if ((value_3 > 0) && (value_4 < 0))
      {
         pairData[y].cross_TF2_Up = true;
         pairData[y].cross_TF2_Dn = false;
      }
      else if ((value_3 < 0) && (value_4 > 0))
      {
         pairData[y].cross_TF2_Up = false;
         pairData[y].cross_TF2_Dn = true;
      }
      else
      {
         pairData[y].cross_TF2_Up = false;
         pairData[y].cross_TF2_Dn = false;
      }
      
      //// TF4
      tmpTF = "TF4";
      tmpString = "Power_" + pairData[y].Base + "_PrePrevious_Gap_" + tmpTF;
      value_1 = GlobalVariableGet(tmpString);
      tmpString = "Power_" + pairData[y].Quote + "_PrePrevious_Gap_" + tmpTF;
      value_2 = GlobalVariableGet(tmpString);
      value_3 = value_1 - value_2;
      tmpString = "Power_" + pairData[y].Base + "_Previous_Gap_" + tmpTF;
      value_1 = GlobalVariableGet(tmpString);
      tmpString = "Power_" + pairData[y].Quote + "_Previous_Gap_" + tmpTF;
      value_2 = GlobalVariableGet(tmpString);
      value_4 = value_1 - value_2;
      if ((value_4 > 0) && (value_3 < 0))
      {
         pairData[y].cross_Previous_TF3_Up = true;
         pairData[y].cross_Previous_TF3_Dn = false;
      }
      else if ((value_4 < 0) && (value_3 > 0))
      {
         pairData[y].cross_Previous_TF3_Up = false;
         pairData[y].cross_Previous_TF3_Dn = true;
      }
      else
      {
         pairData[y].cross_Previous_TF3_Up = false;
         pairData[y].cross_Previous_TF3_Dn = false;
      }
      
      tmpString = "Power_" + pairData[y].Base + "_Gap_" + tmpTF;
      value_5 = GlobalVariableGet(tmpString);
      tmpString = "Power_" + pairData[y].Quote + "_Gap_" + tmpTF;
      value_6 = GlobalVariableGet(tmpString);
      value_3 = value_5 - value_6;
      if ((value_3 > 0) && (value_4 < 0))
      {
         pairData[y].cross_TF3_Up = true;
         pairData[y].cross_TF3_Dn = false;
      }
      else if ((value_3 < 0) && (value_4 > 0))
      {
         pairData[y].cross_TF3_Up = false;
         pairData[y].cross_TF3_Dn = true;
      }
      else
      {
         pairData[y].cross_TF3_Up = false;
         pairData[y].cross_TF3_Dn = false;
      }
      
      //// TF5
      tmpTF = "TF5";
      tmpString = "Power_" + pairData[y].Base + "_PrePrevious_Gap_" + tmpTF;
      value_1 = GlobalVariableGet(tmpString);
      tmpString = "Power_" + pairData[y].Quote + "_PrePrevious_Gap_" + tmpTF;
      value_2 = GlobalVariableGet(tmpString);
      value_3 = value_1 - value_2;
      tmpString = "Power_" + pairData[y].Base + "_Previous_Gap_" + tmpTF;
      value_1 = GlobalVariableGet(tmpString);
      tmpString = "Power_" + pairData[y].Quote + "_Previous_Gap_" + tmpTF;
      value_2 = GlobalVariableGet(tmpString);
      value_4 = value_1 - value_2;
      if ((value_4 > 0) && (value_3 < 0))
      {
         pairData[y].cross_Previous_TF4_Up = true;
         pairData[y].cross_Previous_TF4_Dn = false;
      }
      else if ((value_4 < 0) && (value_3 > 0))
      {
         pairData[y].cross_Previous_TF4_Up = false;
         pairData[y].cross_Previous_TF4_Dn = true;
      }
      else
      {
         pairData[y].cross_Previous_TF4_Up = false;
         pairData[y].cross_Previous_TF4_Dn = false;
      }
      
      tmpString = "Power_" + pairData[y].Base + "_Gap_" + tmpTF;
      value_5 = GlobalVariableGet(tmpString);
      tmpString = "Power_" + pairData[y].Quote + "_Gap_" + tmpTF;
      value_6 = GlobalVariableGet(tmpString);
      value_3 = value_5 - value_6;
      if ((value_3 > 0) && (value_4 < 0))
      {
         pairData[y].cross_TF4_Up = true;
         pairData[y].cross_TF4_Dn = false;
      }
      else if ((value_3 < 0) && (value_4 > 0))
      {
         pairData[y].cross_TF4_Up = false;
         pairData[y].cross_TF4_Dn = true;
      }
      else
      {
         pairData[y].cross_TF4_Up = false;
         pairData[y].cross_TF4_Dn = false;
      }
   }
   
   for (int z = 0; z < 8; z++)
   {
      currencyData[z].crossUp_Counter = 0;
      currencyData[z].crossDn_Counter = 0;
   }
  
   for (int h=0; h < 28; h++)
   {
      for (int hh = 0; hh < 8; hh++)
      {
         if (pairData[h].Base == currencyData[hh].currencyName)
         {
            if (pairData[h].cross_Previous_TF1_Up)
            {
               currencyData[hh].crossUp_Counter++;
            }
            if (pairData[h].cross_Previous_TF2_Up)
            {
               currencyData[hh].crossUp_Counter++; // + 1.1;
            }
            if (pairData[h].cross_Previous_TF3_Up)
            {
               currencyData[hh].crossUp_Counter++; // + 1.2;
            }
            if (pairData[h].cross_Previous_TF4_Up)
            {
               currencyData[hh].crossUp_Counter++; // + 1.3;
            }
            ///////////
            if (pairData[h].cross_Previous_TF1_Dn)
            {
               currencyData[hh].crossUp_Counter--;
            }
            if (pairData[h].cross_Previous_TF2_Dn)
            {
               currencyData[hh].crossUp_Counter--; // - 1.1;
            }
            if (pairData[h].cross_Previous_TF3_Dn)
            {
               currencyData[hh].crossUp_Counter--; // - 1.2;
            }
            if (pairData[h].cross_Previous_TF4_Dn)
            {
               currencyData[hh].crossUp_Counter--; // - 1.3;
            }
            ///////////
            if (pairData[h].cross_TF1_Up)
            {
               currencyData[hh].crossUp_Counter++;
            }
            if (pairData[h].cross_TF2_Up)
            {
               currencyData[hh].crossUp_Counter++; // + 1.1;
            }
            if (pairData[h].cross_TF3_Up)
            {
               currencyData[hh].crossUp_Counter++; // + 1.2;
            }
            if (pairData[h].cross_TF4_Up)
            {
               currencyData[hh].crossUp_Counter++; //+ 1.3;
            }
            ///////////
            if (pairData[h].cross_TF1_Dn)
            {
               currencyData[hh].crossUp_Counter--;
            }
            if (pairData[h].cross_TF2_Dn)
            {
               currencyData[hh].crossUp_Counter--; // - 1.1;
            }
            if (pairData[h].cross_TF3_Dn)
            {
               currencyData[hh].crossUp_Counter--; // - 1.2;
            }
            if (pairData[h].cross_TF4_Dn)
            {
               currencyData[hh].crossUp_Counter--; // - 1.3;
            }
         }
         
         if (pairData[h].Quote == currencyData[hh].currencyName)
         {
            if (pairData[h].cross_Previous_TF1_Up)
            {
               currencyData[hh].crossUp_Counter--;
            }
            if (pairData[h].cross_Previous_TF2_Up)
            {
               currencyData[hh].crossUp_Counter--; // - 1.1;
            }
            if (pairData[h].cross_Previous_TF3_Up)
            {
               currencyData[hh].crossUp_Counter--; // - 1.2;
            }
            if (pairData[h].cross_Previous_TF4_Up)
            {
               currencyData[hh].crossUp_Counter--; // - 1.3;
            }
            ///////////
            if (pairData[h].cross_Previous_TF1_Dn)
            {
               currencyData[hh].crossUp_Counter++;
            }
            if (pairData[h].cross_Previous_TF2_Dn)
            {
               currencyData[hh].crossUp_Counter++; // + 1.1;
            }
            if (pairData[h].cross_Previous_TF3_Dn)
            {
               currencyData[hh].crossUp_Counter++; // + 1.2;
            }
            if (pairData[h].cross_Previous_TF4_Dn)
            {
               currencyData[hh].crossUp_Counter++; // + 1.3;
            }
            ///////////
            if (pairData[h].cross_TF1_Up)
            {
               currencyData[hh].crossUp_Counter--;
            }
            if (pairData[h].cross_TF2_Up)
            {
               currencyData[hh].crossUp_Counter--;// 1.1;
            }
            if (pairData[h].cross_TF3_Up)
            {
               currencyData[hh].crossUp_Counter--; // 1.2;
            }
            if (pairData[h].cross_TF4_Up)
            {
               currencyData[hh].crossUp_Counter--; // - 1.0;
            }
            ///////////
            if (pairData[h].cross_TF1_Dn)
            {
               currencyData[hh].crossUp_Counter++;
            }
            if (pairData[h].cross_TF2_Dn)
            {
               currencyData[hh].crossUp_Counter++; //1.0;
            }
            if (pairData[h].cross_TF3_Dn)
            {
               currencyData[hh].crossUp_Counter++; //1.0;
            }
            if (pairData[h].cross_TF4_Dn)
            {
               currencyData[hh].crossUp_Counter ++; // 1.0;
            }
         }
      }
   }

   int xMultiplier = 0;
   for (int ii = 0; ii < 8; ii++)
   {
      //Alert(tmpArray[ii]);
      panelName = masterPreamble + "_CurrencyPanel_" + currencyData[ii].currencyName;
      labelName = masterPreamble + "_CurrencyLabel_" + currencyData[ii].currencyName;
      //Alert(panelName);
      SetPanel(panelName,0,xAnchor + xSpace + xMultiplier * (xWidth + xSpace), yAnchor + (ii + 1) * (yHeight + ySpace),xWidth, yHeight,ClrBackground,ClrBorder,1);

      if (currencyData[ii].crossUp_Counter > 0)
      {
         ObjectSetInteger(0,panelName,OBJPROP_BGCOLOR,clrLime);
         SetText(labelName,currencyData[ii].currencyName,xAnchor + xSpace + xMultiplier * (xWidth + xSpace) + 5, yAnchor + (ii + 1) * (yHeight + ySpace) + 2, clrBlack, fontSize);
      }
      else if (currencyData[ii].crossUp_Counter < 0)
      {
         ObjectSetInteger(0,panelName,OBJPROP_BGCOLOR,clrRed);
         SetText(labelName,currencyData[ii].currencyName,xAnchor + xSpace + xMultiplier * (xWidth + xSpace) + 5, yAnchor + (ii + 1) * (yHeight + ySpace) + 2, clrWhiteSmoke, fontSize);
      }
      else
      {
         ObjectSetInteger(0,panelName,OBJPROP_BGCOLOR,clrLightGray);
         SetText(labelName,currencyData[ii].currencyName,xAnchor + xSpace + xMultiplier * (xWidth + xSpace) + 5, yAnchor + (ii + 1) * (yHeight + ySpace) + 2, clrBlack, fontSize);
      }
   }
   xMultiplier++;
   int counterDiff;
   
   for (int ii = 0; ii < 8; ii++)
   {
      //Alert(tmpArray[ii]);
      panelName = masterPreamble + "_ValuePanel_" + currencyData[ii].currencyName;
      labelName = masterPreamble + "_ValueLabel_" + currencyData[ii].currencyName;
      //Alert(panelName);
      SetPanel(panelName,0,xAnchor + xSpace + xMultiplier * (xWidth + xSpace), yAnchor + (ii + 1) * (yHeight + ySpace),xWidth, yHeight,clrLightGray,ClrBorder,1);

      //if (currencyData[ii].crossUp_Counter > 0)
      //{
         //ObjectSetInteger(0,panelName,OBJPROP_BGCOLOR,clrLime);
         SetText(labelName,IntegerToString(currencyData[ii].crossUp_Counter,1),xAnchor + xSpace + xMultiplier * (xWidth + xSpace) + 5, yAnchor + (ii + 1) * (yHeight + ySpace) + 2, clrBlack, fontSize);
         counterDiff = currencyData[ii].crossUp_Counter - currencyData[ii].previousCrossUp_Counter;
         labelName = masterPreamble + "_ValueLabelDiff_" + currencyData[ii].currencyName;
         if (counterDiff > 0)
         {
            SetText(labelName,IntegerToString(counterDiff,1),xAnchor + xSpace + xMultiplier * (xWidth + xSpace) + 30, yAnchor + (ii + 1) * (yHeight + ySpace) + 2, clrGreen, fontSize);
         }
         else if (counterDiff < 0)
         {
            SetText(labelName,IntegerToString(counterDiff,1),xAnchor + xSpace + xMultiplier * (xWidth + xSpace) + 30, yAnchor + (ii + 1) * (yHeight + ySpace) + 2, clrRed, fontSize);
         }
         else
         {
            SetText(labelName,IntegerToString(counterDiff,1),xAnchor + xSpace + xMultiplier * (xWidth + xSpace) + 30, yAnchor + (ii + 1) * (yHeight + ySpace) + 2, clrBlack, fontSize);
         }
         
         
      //}
      /*
      else if (currencyData[ii].crossUp_Counter < 0)
      {
         //ObjectSetInteger(0,panelName,OBJPROP_BGCOLOR,clrRed);
         SetText(labelName,Currencies[ii],xAnchor + xSpace + xMultiplier * (xWidth + xSpace) + 5, yAnchor + (ii + 1) * (yHeight + ySpace) + 2, clrBlack, fontSize);
      }
      else
      {
         //ObjectSetInteger(0,panelName,OBJPROP_BGCOLOR,clrOrange);
         SetText(labelName,Currencies[ii],xAnchor + xSpace + xMultiplier * (xWidth + xSpace) + 5, yAnchor + (ii + 1) * (yHeight + ySpace) + 2, clrBlack, fontSize);
      }
      */
   }
   xMultiplier++;
   for (int u = 0; u < 8; u++)
   {
      panelName = masterPreamble + "panel_News_" + IntegerToString(u);
      SetPanel(panelName,0,xAnchor + xSpace + xMultiplier * (xWidth + xSpace), yAnchor + (u + 1) * (yHeight + ySpace),xWidth + 2 * xSpace , yHeight,ClrBackground,ClrBorder,1);
      
      // get news
      int tmpInt = getNewsInfoCurrency(currencyData[u].currencyName, minutesBeforeNews, minutesAfterNews);
      if (tmpInt == 0)
      {
         ObjectSetInteger(0,panelName,OBJPROP_BGCOLOR,clrLime);
         labelName = masterPreamble + "label_News_" + IntegerToString(u);
         SetText(labelName,currencyData[u].currencyName + "(nn)",xAnchor + xSpace + xMultiplier * (xWidth + xSpace) + 5, yAnchor + (u + 1) * (yHeight + ySpace) + 3, clrBlack, fontSize);
      }
      else if (tmpInt == 1)
      {
         ObjectSetInteger(0,panelName,OBJPROP_BGCOLOR,clrRed);
         labelName = masterPreamble + "label_News_" + IntegerToString(u);
         SetText(labelName,currencyData[u].currencyName + "(hi)",xAnchor + xSpace + xMultiplier * (xWidth + xSpace) + 5, yAnchor + (u + 1) * (yHeight + ySpace) + 3, clrBlack, fontSize);
      }
      else if (tmpInt == 2)
      {
         ObjectSetInteger(0,panelName,OBJPROP_BGCOLOR,clrOrange);
         labelName = masterPreamble + "label_News_" + IntegerToString(u);
         SetText(labelName,currencyData[u].currencyName + "(mi)",xAnchor + xSpace + xMultiplier * (xWidth + xSpace) + 5, yAnchor + (u + 1) * (yHeight + ySpace) + 3, clrBlack, fontSize);
      }
      else if (tmpInt == 3)
      {
         ObjectSetInteger(0,panelName,OBJPROP_BGCOLOR,clrYellow);
         labelName = masterPreamble + "label_News_" + IntegerToString(u);
         SetText(labelName,currencyData[u].currencyName  + "(li)",xAnchor + xSpace + xMultiplier * (xWidth + xSpace) + 5, yAnchor + (u + 1) * (yHeight + ySpace) + 3, clrBlack, fontSize);
      }
   }
   
  }
//+------------------------------------------------------------------+
//+------------------------------------------------------------------+

void SetText(string name,string text,int x,int y,color colour,int fontsize=12)
  {
   if (ObjectFind(0,name)<0)
      ObjectCreate(0,name,OBJ_LABEL,0,0,0);

    ObjectSetInteger(0,name,OBJPROP_XDISTANCE,x);
    ObjectSetInteger(0,name,OBJPROP_YDISTANCE,y);
    ObjectSetInteger(0,name,OBJPROP_COLOR,colour);
    ObjectSetInteger(0,name,OBJPROP_FONTSIZE,fontsize);
    ObjectSetInteger(0,name,OBJPROP_CORNER,CORNER_LEFT_UPPER);
    ObjectSetString(0,name,OBJPROP_TEXT,text);
  }

//+------------------------------------------------------------------+

void SetObjText(string name,string CharToStr,int x,int y,color colour,int fontsize=12)
  {
   if(ObjectFind(0,name)<0)
      ObjectCreate(0,name,OBJ_LABEL,0,0,0);

   ObjectSetInteger(0,name,OBJPROP_FONTSIZE,fontsize);
   ObjectSetInteger(0,name,OBJPROP_COLOR,colour);
   ObjectSetInteger(0,name,OBJPROP_BACK,false);
   ObjectSetInteger(0,name,OBJPROP_XDISTANCE,x);
   ObjectSetInteger(0,name,OBJPROP_YDISTANCE,y);
   ObjectSetString(0,name,OBJPROP_TEXT,CharToStr);
   ObjectSetString(0,name,OBJPROP_FONT,"Wingdings");
  }
//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
void SetPanel(string name,int sub_window,int x,int y,int width,int height,color bg_color,color border_clr,int border_width)
  {
   if(ObjectCreate(0,name,OBJ_RECTANGLE_LABEL,sub_window,0,0))
     {
      ObjectSetInteger(0,name,OBJPROP_XDISTANCE,x);
      ObjectSetInteger(0,name,OBJPROP_YDISTANCE,y);
      ObjectSetInteger(0,name,OBJPROP_XSIZE,width);
      ObjectSetInteger(0,name,OBJPROP_YSIZE,height);
      ObjectSetInteger(0,name,OBJPROP_BGCOLOR,bg_color);
      ObjectSetInteger(0,name,OBJPROP_BORDER_TYPE,BORDER_FLAT);
      ObjectSetInteger(0,name,OBJPROP_WIDTH,border_width);
      ObjectSetInteger(0,name,OBJPROP_CORNER,CORNER_LEFT_UPPER);
      //ObjectSetInteger(0,name,OBJPROP_STYLE,STYLE_SOLID);
      ObjectSetInteger(0,name,OBJPROP_BACK,true);
      ObjectSetInteger(0,name,OBJPROP_SELECTABLE,0);
      ObjectSetInteger(0,name,OBJPROP_SELECTED,0);
      //ObjectSetInteger(0,name,OBJPROP_HIDDEN,true);
      ObjectSetInteger(0,name,OBJPROP_ZORDER,0);
     }
   ObjectSetInteger(0,name,OBJPROP_BGCOLOR,bg_color);
  }
