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.
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.
I tried iTime(symbol_name, PERIOD_D1, 0) but it does not return date of the last bar.
- 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 - iTime(NULL, PERIOD_D1, 0) returns the date of most recent day traded. If you want the last bar of a day tryNot 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
WHRoeder:
Many Thanks WHRoeder. Problem solved.- Search for it.Not compiled, not tested Not compiled, not tested
- iTime(NULL, PERIOD_D1, 0) returns the date of most recent day traded. If you want the last bar of a day tryNot compiled, not tested Not compiled, not tested
![MQL5 - Language of trade strategies built-in the MetaTrader 5 client terminal](https://c.mql5.com/i/registerlandings/logo-2.png)
You are missing trading opportunities:
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
Registration
Log in
You agree to website policy and terms of use
If you do not have an account, please register
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.