NewsReader
Miscellaneous
Uses files from the file systemIt reads information from a fileIt issuies visual alerts to the screenIt plays sound alerts
0 Views
0 Downloads
0 Favorites
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();
   }
}

Comments

Markdown supported. Formatting help

Markdown Formatting Guide

Element Markdown Syntax
Heading # H1
## H2
### H3
Bold **bold text**
Italic *italicized text*
Link [title](https://www.example.com)
Image ![alt text](image.jpg)
Code `code`
Code Block ```
code block
```
Quote > blockquote
Unordered List - Item 1
- Item 2
Ordered List 1. First item
2. Second item
Horizontal Rule ---