NewsReader





//+------------------------------------------------------------------+
//|                                                   NewsReader.mq4 |
//+------------------------------------------------------------------+

// Modified by mqldev - www.mqldev.com

#property indicator_chart_window

extern   string   FileName          = "news.csv";
extern   bool     DoAlerts          = true;
extern   int      AlertTime         = 10;
extern   int      StampFontSize     = 10;
extern   string   StampFontName     = "arial";
extern   color    StampFontColor    = Orange;

int FileHandle;

int      eventCount;
string   eventNames[10];
datetime eventTimes[10];

//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int init()
{
//---- indicators
   DeleteStamp();

   FileHandle = FileOpen(FileName, FILE_CSV|FILE_READ,';');

   if(FileHandle==0)
      Print("File "+FileName+" not found.");

   for(eventCount = 0; !FileIsEnding(FileHandle); eventCount++)
   {
      eventTimes[eventCount] = StrToTime(FileReadString(FileHandle));
      eventNames[eventCount] = FileReadString(FileHandle);
   }

//----
   return(0);
}


//+------------------------------------------------------------------+
//| Custom indicator deinitialization function                       |
//+------------------------------------------------------------------+
int deinit()
{
   DeleteStamp();
//----
   FileClose(FileHandle);
//----
   return(0);
}

//+------------------------------------------------------------------+
//| Custom indicator iteration function                              |
//+------------------------------------------------------------------+
int start()
{
//----
   int next = 0;

   while(eventTimes[next] < TimeCurrent())
   {
      next++;
      if(next >= eventCount)
      {
         //Comment(eventCount+" news releases over."+" No more news today!");
         Stamp(eventCount+" news releases over."+" No more news today!",5,20);
         return(0);
      }
   }
   
   Stamp("Next news event: "+TimeToStr(eventTimes[next])+" "+eventNames[next],5,20);

   //Comment("Next news event: "+TimeToStr(eventTimes[next])+" "+eventNames[next]);

   if(DoAlerts && TimeMinute(eventTimes[next]-TimeCurrent())==DoAlerts)
   {
      Alert("News Event Imminent: "+TimeMinute(eventTimes[next]-TimeCurrent())+" minutes to "+eventNames[next]+"!");
      PlaySound("alert.wav");
   }

//----
   return(0);
}

void Stamp(string message , int x , int y)
{
   string Obj="Stamp_" + message;
   int objs = ObjectsTotal();
   string name;
  
   for(int cnt=0;cnt<ObjectsTotal();cnt++)
   {
      name=ObjectName(cnt);
      if (StringFind(name,Obj,0)>-1) 
      {
         ObjectSet(Obj,OBJPROP_XDISTANCE,x);
         ObjectSet(Obj,OBJPROP_YDISTANCE,y);
         ObjectsRedraw();
      }
      else
      {
         ObjectCreate(Obj,OBJ_LABEL,0,0,0);
         ObjectSetText(Obj,message,StampFontSize,StampFontName,StampFontColor);
         ObjectSet(Obj,OBJPROP_XDISTANCE,x);
         ObjectSet(Obj,OBJPROP_YDISTANCE,y);
         ObjectsRedraw();
      }
   }
   if (ObjectsTotal() == 0)
   {
         ObjectCreate(Obj,OBJ_LABEL,0,0,0);
         ObjectSetText(Obj,message,StampFontSize,StampFontName,StampFontColor);
         ObjectSet(Obj,OBJPROP_XDISTANCE,x);
         ObjectSet(Obj,OBJPROP_YDISTANCE,y);
         ObjectsRedraw();

   }
   
   return(0);
}
void DeleteStamp()
{
   int objs = ObjectsTotal();
   string name;
   for(int cnt=ObjectsTotal()-1;cnt>=0;cnt--)
   {
      name=ObjectName(cnt);
      if (StringFind(name,"Stamp",0)>-1) ObjectDelete(name);
      ObjectsRedraw();
   }
}





Sample





Analysis



Market Information Used:



Indicator Curves created:


Indicators Used:



Custom Indicators Used:

Order Management characteristics:

Other Features:

Uses files from the file system

It reads information from a file
It issuies visual alerts to the screen
It plays sound alerts