//+------------------------------------------------------------------+
//|                                                 NewsCalAddOn.mq4 |
//|                                     Copyright 2015, Forex Taurus |
//|                                  http://ForexTaurus.blogspot.com |
//+------------------------------------------------------------------+
//
// This is an example how to read NewsCalv1.07 Labels to use in your code.
// NewsCal-V1.07 Copyright(C) Tim Morris

#property copyright "Copyright 2015, Forex Taurus"
#property link      "http://ForexTaurus.blogspot.com"
#property version   "1.10"
#property strict
#property indicator_chart_window

extern int objFontSize=12;
extern string objFont="Arial";
extern color objCol=clrRed;
extern int objCorner=0;
extern int XCor=100;
extern int YCor=10;
//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int OnInit()
  {
//--- indicator buffers mapping

//---
   return(INIT_SUCCEEDED);
  }
//+------------------------------------------------------------------+
//| 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[])
  {
//---

   string strTime,strCurrency,strEvent;
   string strResult="";
   
   long currChart,prevChart=ChartFirst();
   int charts=0,limit=100;
//Print("ChartFirst =",ChartSymbol(prevChart)," ID =",prevChart);
   while(charts<limit)// We have certainly not more than 100 open charts
     {
      currChart=ChartNext(prevChart); // Get the new chart ID by using the previous chart ID
      if(currChart<0) break;          // Have reached the end of the chart list


      if(ObjectFind(currChart,"zNews LB Calendar¬~F1")==0)
        {
        
           
         for(int i=0; i<24; i++)
           {
            //if(ObjectFind("zNews LB Calendar¬~T1")!=0) strResult="NewsCal Indicator Missing";
            strTime=ObjectGetString(currChart,"zNews LB Calendar¬~T"+IntegerToString(i,0),OBJPROP_TEXT);
            strCurrency=ObjectGetString(currChart,"zNews LB Calendar¬~C"+IntegerToString(i,0),OBJPROP_TEXT);
            strEvent=ObjectGetString(currChart,"zNews LB Calendar¬~N"+IntegerToString(i,0),OBJPROP_TEXT);
            if(StringFind(strEvent,"NFP",0)>=0) strResult=strResult+" NFP ";
            if(StringFind(strEvent,"Non-Farm",0)>=0) strResult=strResult+" NFP";
            if(StringFind(strEvent,"FOMC",0)>= 0) strResult=strResult+"  "+strTime+" FOMC ";
            if(StringFind(strEvent,"ECB",0) >= 0) strResult=strResult+"  "+strTime+" ECB ";
           }


            string objName="strImportantNews";
         
            if(strResult=="") strResult="No Important News";
         
            if(ObjectFind(objName)<0) ObjectCreate(objName,OBJ_LABEL,0,0,0);
            ObjectSetText(objName,strResult,objFontSize,objFont,objCol);
            ObjectSet(objName,OBJPROP_CORNER,objCorner);
            ObjectSet(objName,OBJPROP_XDISTANCE,XCor);
            ObjectSet(objName,OBJPROP_YDISTANCE,YCor);
            
            
         //--- return value of prev_calculated for next call
            return(rates_total);
            
            }
         
               prevChart=currChart;// let's save the current chart ID for the ChartNext()
               charts++;// Do not forget to increase the counter

     }
   return(rates_total);
  }
  
//+------------------------------------------------------------------+
