Chart stops processing new events and ticks. Does anyone know what might be happening?

 

If I let my chart run with all my indicators and EA, it will sometimes stop processing new events and ticks until I force it to get unstuck by changing timeframes.

1. No errors in the log

2. MT5 is still perfectly responsive (I can draw objects on the chart and change its settings while this is happening, no lag on my terminal)

3. Market Watch is normal, I can see the changing bid and ask with the time updates

4. The chart is not receiving new ticks and is not processing any of the OnChartEvent or OnTimer functions that should normally get triggered

5. If I change the timeframe, it usually unfreezes the event queue, all ticks come in, bars get printed really fast and all backlogged OnChartEvent and OnTimer events get processed instantly

What is happening? Not a single indicator processes events on the chart while this is happening so it makes me think that maybe the chart's event feed is either frozen or blocked.

I don't know where to start looking for the cause of this problem. Maybe some of you have seen this before and might know something that could help me so thank you in advance!

Documentation on MQL5: Common Functions / Print
Documentation on MQL5: Common Functions / Print
  • www.mql5.com
Print - Common Functions - MQL5 Reference - Reference on algorithmic/automated trading language for MetaTrader 5
 

All indicators on a symbol share a single thread. If any one of them freezes, then they all freeze.

Most probably one of your indicators has a bug, for example, an infinite loop, which causes it to freeze.

 
Jeepack:

If I let my chart run with all my indicators and EA, it will sometimes stop processing new events and ticks until I force it to get unstuck by changing timeframes.

2. MT5 is still perfectly responsive (I can draw objects on the chart and change its settings while this is happening, no lag on my terminal)

If the problem was with your indicator(s), you couldn't do that. The problem must be an infinite loop in your EA.

 
@William Roeder #: If the problem was with your indicator(s), you couldn't do that. The problem must be an infinite loop in your EA.

But if the EA freezes, it should not freeze the chart itself (bars & ticks) nor freeze the indicators, given that the EA is on a different thread from the chart and indicators.

I could be wrong, but I am more inclined to believe that the problem is with one of the indicators which can freeze all other indicators and the chart itself.

 
Jeepack:

If I let my chart run with all my indicators and EA, it will sometimes stop processing new events and ticks until I force it to get unstuck by changing timeframes.

1. No errors in the log

2. MT5 is still perfectly responsive (I can draw objects on the chart and change its settings while this is happening, no lag on my terminal)

3. Market Watch is normal, I can see the changing bid and ask with the time updates

4. The chart is not receiving new ticks and is not processing any of the OnChartEvent or OnTimer functions that should normally get triggered

5. If I change the timeframe, it usually unfreezes the event queue, all ticks come in, bars get printed really fast and all backlogged OnChartEvent and OnTimer events get processed instantly

What is happening? Not a single indicator processes events on the chart while this is happening so it makes me think that maybe the chart's event feed is either frozen or blocked.

I don't know where to start looking for the cause of this problem. Maybe some of you have seen this before and might know something that could help me so thank you in advance!

Remove the EA and see if it unfreezes. If not continue by removing the indicators, one by one. You should be able to isolate the culprit, unless it's a more complex issue.

Once you know which program is the cause, check the code.

 

Thanks everyone for the advice, I'll try using these tips today to see if it helps me find more clues about what is happening. The toughest part about troubleshooting this is that it's hard to reproduce the problem. Sometimes it takes an hour and other times it takes 5 minutes and when it happens I have to run the tests before it unfreezes. I literally made a flashing background color indicator just to be able to do something else while I wait for it to happen to be able to easily notice when the chart stops processing events. Hopefully I'll know more about the issue soon and will be able to share what I find.

 

I think my issue comes from the way I have an indicator and an EA working together as one single tool with both of them using OnTimer events and sharing information through objects on the chart. It's hard for me to understand but it seems like a lot of what is written in this article https://www.mql5.com/en/articles/197 talks about what is probably the root cause of my thread freezing issues. So since I don't understand most of this, and since I could not find any errors in my code and also proved with comment lines that the freezing doesn't always happen in the same place, I think the only solution I found was to combine the indicator and the EA and make them work as one single EA with only one timer. This would make the code much more efficient at the same time because otherwise I'm wasting a lot of CPU resources just passing information from the EA to the indicator and vice versa. I originally coded the tools like this because it just seemed more practical at the time and I was convinced they both worked on the same event thread but now I know this is not the case so I'm starting to think this is probably the reason why the chart freezes sometimes. I hope my solution will work because I couldn't think of anything else... 

What do you think? Does this make any sense? 

Parallel Calculations in MetaTrader 5
Parallel Calculations in MetaTrader 5
  • www.mql5.com
Time has been a great value throughout the history of mankind, and we strive not to waste it unnecessarily. This article will tell you how to accelerate the work of your Expert Advisor if your computer has a multi-core processor. Moreover, the implementation of the proposed method does not require the knowledge of any other languages besides MQL5.
 
Jeepack #: I was once told not to worry about efficiency in the code unless it becomes an issue.

To be honest, I've never really applied that advice.

I started programming in my teens, in the early 80's, writing a lot of assembler code for Z-80 (a 8-bit processor) and with very little RAM (I think it was 16KB at the time), I always strived for the most efficient and compact code.

So, that mentality has stuck with me ever since. I still code with efficiency in mind. I'm not radical about it, but it's always at the forefront of code logic.

 
Fernando Carreiro #:

To be honest, I've never really applied that advice.

I started programming in my teens, in the early 80's, writing a lot of assembler code for Z-80 (a 8-bit processor) and with very little RAM (I think it was 16KB at the time), I always strived for the most efficient and compact code.

So, that mentality has stuck with me ever since. I still code with efficiency in mind. I'm not radical about it, but it's always at the forefront of code logic.

Sorry I edited my comment before you submitted your reply so just to add context, before I edited it, I started my previous comment with a line that read like this: "I was once told not to worry about efficiency unless it became an issue. Applying this idea helped me get more work done in the last few months but I think I'm finally starting to reach the point where it's causing problems in my system." ... or something like that

Thanks for the comment Fernando. I'm like you but after I was given this advice I figured I should give the alternative a try. I told myself I'll stop focussing on that so much until I reach a point where it proves to be important. I guess I reached the limit with my last code lol. I know it sounds like the most inneficient code you could ever think of (passing values between an indicator and an EA through hidden objects, doing this multiple times per seconds with multiple objects) and I would have never done this before but I was really trying to "not give a F***" about efficiency until it proved to be a problem and I think that this was the last straw that broke the camel's back in a way. Now I think I know what to do and I'm hopeful that when I rewrite this correctly the freezing will stop, at least I hope!

The thing is I didn't realize it but I have so much code working in the background for my chart that MT5 was probably using more than one core to process everything and since EA's don't work on the same thread as indicators I think everything just got to a point where it was a matter of time before random glitches started occuring from the overwhelming amount of operations trying to take place in parallel.

 
Jeepack #:

Sorry I edited my comment before you submitted your reply so just to add context, before I edited it, I started my previous comment with a line that read like this: "I was once told not to worry about efficiency unless it became an issue. Applying this idea helped me get more work done in the last few months but I think I'm finally starting to reach the point where it's causing problems in my system." ... or something like that

Thanks for the comment Fernando. I'm like you but after I was given this advice I figured I should give the alternative a try. I told myself I'll stop focussing on that so much until I reach a point where it proves to be important. I guess I reached the limit with my last code lol. I know it sounds like the most inneficient code you could ever think of (passing values between an indicator and an EA through hidden objects, doing this multiple times per seconds with multiple objects) and I would have never done this before but I was really trying to "not give a F***" about efficiency until it proved to be a problem and I think that this was the last straw that broke the camel's back in a way. Now I think I know what to do and I'm hopeful that when I rewrite this correctly the freezing will stop, at least I hope!

The thing is I didn't realize it but I have so much code working in the background for my chart that MT5 was probably using more than one core to process everything and since EA's don't work on the same thread as indicators I think everything just got to a point where it was a matter of time before random glitches started occuring from the overwhelming amount of operations trying to take place in parallel.

On MT4, passing data via the Graphical Objects worked well because it was synchronous.

On MT5, it's not really a good solution because of the asynchronous way Graphical Objects are processed. It has also been reported by another user that overloading its use can in fact cause things to freeze.

Overloaded the use of Custom Chart Events can also cause the chart to freeze (also reported by the same user).

The only other options are Global Terminal Variables, Files or DLL calls. Unfortunately, MQL just does not offer any good solutions for Interprocess Communication or Shared Data.

 
Fernando Carreiro #:

On MT4, passing data via the Graphical Objects worked well because it was synchronous.

On MT5, it's not really a good solution because of the asynchronous way Graphical Objects are processed. It has also been reported by another user that overloading its use can in fact cause things to freeze.

Overloaded the use of Custom Chart Events can also cause the chart to freeze (also reported by the same user).

The only other options are Global Terminal Variables, Files or DLL calls. Unfortunately, MQL just does not offer any good solutions for Interprocess Communication or Shared Data.

Yeah that seems to confirm what I was thinking. I couldn't find any other reason why my charts would freeze. I'm rewriting everything to remove most of the object queries by placing all the code in one EA instead of an EA and an indicator. This should also result in all events being on the same thread. I don't know if this will help but I'm pretty optimistic since I know my code could be much more efficient if I coded it this way.

Reason: