Custom Indicator Code Identifying When Data Feed is not Live

 

As humans, we can readily tell when we have live data feed and when we don't.  But just try to write a code for insertion into a custom indicator that can tell, during times when there is no live feed (weekends, holidays, etc.) that there is no live data feed!   I don't think it can be done, but if anyone knows that there is, please respond.

I know of no preassigned variable that has a unique value when the data feed is not live, such that you could test for that value and know the data feed is not live.  I know of no "condition" that might be only "true" or only "false" when the data feed is not live, such that you could test for the state of that condition  (true or false) and by the result know the data feed is not live.  I have found nothing that can be tested in coding with a specific result of the test confiming the data feed is not live. 

It seems an unbelievable oversight that the MQL4 coding language has excluded the ability to identify the state of no live data feed!  Is there a reason for wanting to do so?  Yes.

Just one example of a reason is the management of the placement of vertical lines on the chart that represent market open times.  These will depend on the time zone of the broker server and the time zones of the various market open locations.  And the difference between the required time zones is also affected by DST changeovers twice yearly, when the different locations (broker server, and the various market open locations) all do their DST changeovers at different times during a period that can be as much as a months duration from start to finish.   The key here is that when there is a live data feed, the broker server time is known.  When there is no live data feed, there is no broker server time.   And the broker server time is required in order to properly know where the broker server is in relationship to all the other locations. 

If there was a way coding could reliably identify when the data feed was not live, then a manually input variable could be substituted/used in place of the server time.  And when the code reliably identified that the feed was again live, of course the code could resume using the actual broker server time.

That such an obvious state (live feed vs no live feed) has no test  instruction in MQL4 coding is hard to believe, but I have not yet found it. 

So, again, if anyone knows of any MQL4 instruction set, or condtion test that reliably identifies if the incoming data package (when first opening a chart, or changing a chart time frame during weekends and holidays) was via live feed or not, please let me know. 

 
Custom Indicators runs on start(). If there's no live-data feed, theres no start. If you're providing false ticks, then its your responsibility to identify.
 
ubzen:
Custom Indicators runs on start(). If there's no live-data feed, theres no start. If you're providing false ticks, then its your responsibility to identify.

ubzen, you are wrong.  Yes, custom indicators run on start(), but that occurs both with live feed and with the single feed that occurs at all other times.   If this were not the case nothing would show on any chart on weekends, etc.  Custom indicators do "populate" on weekends.  They are an initial population based on a single data package arriving when you open a chart, or when you change the time frame on an opened chart, but then the custome indicators are not updated because there are no subsequent ticks bringing in new data packages since there is no live feed.

My quest would easily be solved if the broker server tagged such weekend "single tick data packages" with the actual time for the broker server.  But that is not the case.  The broker server time locks up at the final tick shutdown.  Should be an easy thing to rectify, but brokers are not interesting in going out of their way to do anything like that.

So, the initial question remains.  Is there any instruction, etc. in MQL4 coding that can be tested to accurately determine if the data that just came in on a tick was as the result of a live feed tick, or as the result of a single tick transmission such as is the case during all other times that the data feed is not live. 

 
traderathome:
  1. ubzen, you are wrong. 
  2. Yes, custom indicators run on start(), but that occurs both with live feed and with the single feed that occurs at all other times.  
  3. If this were not the case nothing would show on any chart on weekends, etc.  Custom indicators do "populate" on weekends. 
  1. No he is not
  2. There is only ONE feed (live or the strategy tester)
  3. There is NO BARS during the weekends. After 3:59pm ET Friday (FX market close) is 6pm ET Sunday (FX market open.) They do not populate on weekends, there are no bars to populate. Press control-Y. The vertical lines are the start of day.

xEnd of week

The image shows 50 hours (29 mar 2000z - 31 mar 2200z) on either side of the line. You do NOT see 50*60=3000 M1 bars do you?

 
WHRoeder, if MT4 is downloaded and installed on the weekend (no live feed) and then a chart is opened up, population of the chart occurs.  Hence, a one time feed of data was provided, bringing the data up-to-date so a chart can be populated.  That is proof.  Also, if it is the weekend and an "invalid account" situation arises, the population of charts ceased when the account became invalid, perhaps weeks ago, and leaving the last bar shown as a bar weeks ago.  However, by opening a new account, charts will populate to the current last tick before shutdown for the weekend, bringing the last bar shown as an up-to-date (shutdown) bar.  This is also proof that a one time feed of data was provided to bring in the data necessary to bring charts up-to-date.
 

That is proof of nothing.

Disable your connection or specify an invalid account. Now wait some time and undo. The missing history (up to ~65K bars depending on broker and your history settings ~45 days of M1 bars) are downloaded from history. That has nothing to do with live data. That is history.

Now download history. Disconnect, Create a new installation or delete your history files, and then import into mq4. You were never on line, yet you get a chart. That is history.

There is no live feed, start is not called, until you get a live tick.

 

I have an indicator that once "start()" is executed gets clock times around the world and populates the clock on the chart.  On weekends, when the feed is not live, there is nevertheless a single tick that comes in when opening a chart, or changing the chart timeframe.  This single tick, causes the "start()" to execute, which causes the times in the various time zones to be obtained, and causes the clock to populate with these times.  The times will not update unless the chart TF is changed.  If the chart TF is changed, the clock repopulates with updated time.  Therefore, "start()" is called when there is not live tick, but only once if a chart is opened or if the chart TF is changed.  And this is the same with all indicators.  They do populate a chart, which is something that would be impossible for them to do on weekend if "start()" were not called at least once when a chart was opened, or when the chart TF changed.  Think about it.

The point is, when an indicator executes "start()" on weekends when a chart is opened or the chart TF is changed, is there any way to distinguish that single call of "start()" from the call of "start()"  during a live feed?   That is the question!  

 
traderathome:

ubzen, you are wrong.  Yes, custom indicators run on start(), but that occurs both with live feed and with the single feed that occurs at all other times.   If this were not the case nothing would show on any chart on weekends, etc.  Custom indicators do "populate" on weekends.  They are an initial population based on a single data package arriving when you open a chart, or when you change the time frame on an opened chart, but then the custome indicators are not updated because there are no subsequent ticks bringing in new data packages since there is no live feed.

My quest would easily be solved if the broker server tagged such weekend "single tick data packages" with the actual time for the broker server.  But that is not the case.  The broker server time locks up at the final tick shutdown.  Should be an easy thing to rectify, but brokers are not interesting in going out of their way to do anything like that.

So, the initial question remains.  Is there any instruction, etc. in MQL4 coding that can be tested to accurately determine if the data that just came in on a tick was as the result of a live feed tick, or as the result of a single tick transmission such as is the case during all other times that the data feed is not live. 

traderathome,

the reason why indicators do populate charts on weekend is described in Documentation:

All new quotes income while the program was being executed are skipped by the program until the current execution of the start() function has been completed. After that, the start() function will be run only when a successive new quote incomes.

For custom indicators, the start() function will be launched for recalculation after the current chart symbol or timeframe has been changed independently on new quotes incoming.

https://docs.mql4.com/runtime/start

Therefore you are wrong in your assumption that the start() function on weekends in indicators is caused by "single tick data packages" .

There is no tick data coming from the broker-server on weekends.


Expert Advisors are different. Their start() function is not launched when the EA is attached to a chart (or when timeframe is switched).

The only way to force an EA to launch the start() function on weekends is with fake ticks, created by scripts or another EA or a dll  which

is using the Windows OS to "tick" the chart.  There are free tools available for this (example: Mt4TickSender by fx1.net).


Your question remains: How to detect the weekend ?

Maybe by comparing the Computer time TimeLocal( )   to the broker-server-time  TimeCurrent( ) .

Local time doesn´t stop. Broker server time stops when market closes and starts again when market opens.

For this you need a fake tick tool because EAs and indicators only work with ticks sent from the broker.

There will be no ticks after market closes.

 
traderathome:

To solve your problem, maybe you can just return||do-nothing on the Initialized_Run. :)

Other things that could help you: https://docs.mql4.com/check/UninitializeReason

Reason: