Recognising blocked shares in mql4

 

Hi every one,

I have written an mql4 program which scans all shares and returns some statistics based on their typical price and etc.

However, there are always some shares which temporarily blocked because of some governmental policies i.e., they are not

traded for some days or weeks.

I want to determine such shares and eliminate their effects in final result. How can I do this?

That's enough if you propose a way to recognize shares which are not traded for N days (for example N=1 day).

Any help will be appreciate.

 
Check that there is a bar for the relevant day(s). If no bar exists, then you know that the instrument was not traded for that period.
 
GumRai:
Check that there is a bar for the relevant day(s). If no bar exists, then you know that the instrument was not traded for that period.

Thanks GumRai, this should work. But how can I check the existence of a bar in a specific day?

I tried iTime(symbol_name, PERIOD_D1, 0) but it does not return date of the last bar.

 
b4hr4m: But how can I check the existence of a bar in a specific day?
I tried iTime(symbol_name, PERIOD_D1, 0) but it does not return date of the last bar.
  1. Search for it.
    Not compiled, not tested
    #define HR2400 86400       // 24 * 3600
    int      TimeOfDay(datetime when){        return( when % HR2400          );   }
    datetime DateOfDay(datetime when){        return( when - TimeOfDay(when) );   }
    datetime Today(    datetime when=0){      if(when == 0)  when = TimeCurrent();
                                              return(DateOfDay( TimeCurrent() )); }
    datetime Tomorrow( datetime when=0){      if(when == 0)  when = TimeCurrent();
                                              return(Today(when) + HR2400);       }
    datetime Yesterday(datetime when=0){      if(when == 0)  when = TimeCurrent();
       int iD1 = iBarShift(NULL, PERIOD_D1, Today(when) - 1);
                                           return( iTime(NULL, PERIOD_D1, iD1) ); }
    bool wasTradedOnDate(datetime when=0, string symbol=""){
       if(when == 0)    when   = TimeCurrent();
       if(symbol == "") symbol = Symbol();
       int iD1 = iBarShift(symbol, PERIOD_D1, when);
       return( when - iTime(symbol, PERIOD_D1, iD1] < HR2400 );
    }
    Not compiled, not tested
  2. iTime(NULL, PERIOD_D1, 0) returns the date of most recent day traded. If you want the last bar of a day try
    Not compiled, not tested
    int iLastBarOfDate(datetime when=0, string symbol=""){
       if(when == 0)    when   = TimeCurrent();
       if(symbol == "") symbol = Symbol();
       return( iBarShift(symbol, 0, Tomorrow(when) - 1) );
    }
    Not compiled, not tested
 
I was using iTime() function improper. It can be used in solution. However, I solved the problem using iBarshift function and comparing its returned value with specific date.
 
WHRoeder:
  1. Search for it.
    Not compiled, not tested Not compiled, not tested
  2. iTime(NULL, PERIOD_D1, 0) returns the date of most recent day traded. If you want the last bar of a day try
    Not compiled, not tested Not compiled, not tested


Many Thanks WHRoeder. Problem solved.