How to make an EA in mq5 to trade only one hour before high impact news, and one hour after?

To add comments, please log in or register
Marco vd Heijden
Moderator
12775
Marco vd Heijden  
By coding the datetime filters.
Sabil Yudifera
14084
Sabil Yudifera  
by coding with xml from web and time filter
rod777
188
rod777  
give some examples please
rod777
188
rod777  
thank you you are very helpfull
rod777
188
rod777  
//+------------------------------------------------------------------+
//|                                                PinkEventDate.mq5 |
//|                        Copyright 2019, MetaQuotes Software Corp. |
//|                                             https://www.mql5.com |
//+------------------------------------------------------------------+
#property copyright "Copyright 2019, MetaQuotes Software Corp."
#property link      "https://www.mql5.com"
#property version   "1.00"

int minAfter,minBefore;
//+------------------------------------------------------------------+
//| Script program start function                                    |
//+------------------------------------------------------------------+
void OnStart()
  {
   datetime date1=last_pink_event_date();
   datetime date2=next_pink_event_date();
   string text="";

   if(date1>0)text+="LastPinkEventDate = "+string(date1)
      +"\n"+"minAfter = "+(string)minAfter;
   else text += "\n"+"No 'LastPink Event' available.";
   
   if(date2>0) text+="\n"+"NextPinkEventDate = "+string(date2)
      +"\n"+"minBefore = "+(string)minBefore;
   else text += "\n"+"No 'NextPink Event' available.";

   MessageBox(text,"Information",0);


  }
//+------------------------------------------------------------------+
datetime last_pink_event_date()
  {
   string  name="";
   long date=0;
   int total=ObjectsTotal(0)-1;

   for(int i=total; i>=0; i --)
     {
      name=ObjectName(0,i);

      if(ObjectGetInteger(0,name,OBJPROP_TYPE,0) !=OBJ_EVENT) continue; 
      if(ObjectGetInteger(0,name,OBJPROP_COLOR,0) != clrPink) continue; 

      Print(ObjectGetString(0,name,OBJPROP_TEXT,0));

      date=(long)ObjectGetInteger(0,name,OBJPROP_TIME);

      minAfter=(int)(date -(long)TimeCurrent())/60;
      return(datetime)date;

     }

   return 0;
  }
//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
datetime next_pink_event_date()
  {
   string  name="";
   long date=0;
   int total=ObjectsTotal(0)-1;

   for(int i=0; i<ObjectsTotal(0); i++)
     {
      name=ObjectName(0,i);

      if(ObjectGetInteger(0,name,OBJPROP_TYPE,0)==OBJ_EVENT)
         if(ObjectGetInteger(0,name,OBJPROP_COLOR,0)==clrPink)
           {

            date=(long)ObjectGetInteger(0,name,OBJPROP_TIME);

            if(date>TimeCurrent())
              {
               minBefore=(int)(date -(long)TimeCurrent())/60;
               Print(minBefore);
               Print((string)ObjectGetInteger(0,name,OBJPROP_COLOR,0));
               return(datetime)date;
              }

           }

     }

   return 0;

  }
//+------------------------------------------------------------------+
rod777
188
rod777  
I solve it my self,thanks
To add comments, please log in or register