Trades executing in visual mode but not in optimisation?

 
Any idea why my EA is clearly executing around 300 trades a year in visual mode on 3 symbols simultaneously but when I try to optimise, many iterations have 0 trades, and most are 0-10 trades with the odd one at 20ish. This is weird since the code is the same and it works fine in visual mode. Parameters are very much within the normal range.
 

Check for

#property tester_everytick_calculate
 
Alain Verleyen #:

Check for

Added it, still the same. Checked the code too, everything looks normal and seems like it should work as intended.

 
@Jack White #:Added it, still the same. Checked the code too, everything looks normal and seems like it should work as intended.

It may be that your code logic is dependant on graphical objects, which are rendered in visual mode, but they are not rendered in optimisations.

Make sure your trade code logic does not depend on graphical objects.

 
Fernando Carreiro #:

It may be that your code logic is dependant on graphical objects, which are rendered in visual mode, but they are not rendered in optimisations.

Make sure your trade code logic does not depend on graphical objects.

It doesn't. Just the standard iMA handlers, nothing too fancy. I just find it odd that there are always some iterations that are non-zero in trades. It would make more sense that they're all 0 trades or non-zero. I've had it happen with an EA I was having developed earlier too but I attributed that to not knowing the source code. This EA however is my own and I've seen it function normally. Is it possible there's a bug in MT5? There have been times in the past where I've seen MT5 show >>100% DD.

 
Jack White #: It doesn't. Just the standard iMA handlers, nothing too fancy. I just find it odd that there are always some iterations that are non-zero in trades. It would make more sense that they're all 0 trades or non-zero. I've had it happen with an EA I was having developed earlier too but I attributed that to not knowing the source code. This EA however is my own and I've seen it function normally. Is it possible there's a bug in MT5? There have been times in the past where I've seen MT5 show >>100% DD.

You will have to provide some code example that can reproduce the issue, otherwise we will just have to assume the bug is in your own code and not in MetaTrader.

At the moment, you have only vaguely described the issue. We will require code, logs and reports, to be able to test ourselves and compare, to be able to either point you to a solution or to present to MetaQuotes.

However, most of the time, the issue is normally a bug in the EA code. Only on lesser occasions can it be traced to a bug in MetaTrader.

So, if you need further advice, you will need to provide some kind of example code that can reproduce the issue, with accompanying log files tester reports.

 
Jack White #:

It doesn't. Just the standard iMA handlers, nothing too fancy. I just find it odd that there are always some iterations that are non-zero in trades. It would make more sense that they're all 0 trades or non-zero. I've had it happen with an EA I was having developed earlier too but I attributed that to not knowing the source code. This EA however is my own and I've seen it function normally. Is it possible there's a bug in MT5? There have been times in the past where I've seen MT5 show >>100% DD.

How could we know ? All is possible until proved it's not.

If you post all what is necessary someone could reproduce it and help. Otherwise you will have to find by yourself.

 
I had the same problem, strategy was working with visual mode on, then getting no trades when it was off. For me, it was because I was inputting incorrect variables into the parameters of a custom indicator. I was passing a period and a buffer size, into the handle and copy buffer respectively, but this indicator only needed a period. So it was still working in the visual tester and was displaying a trend, but causing no trades due to being inherently wrong when using optimisation. 
 

I had similar issues time ago with some  RSI Divergence and MACD Divergence indicator, founding two different problems.

In one of them (RSI divergence) buffers were assigned only if "ChartWindowFind()" returned a value different than WRONG_VALUE, which probably not happened into a non visual backtest.

In another one (MACD divergence) there were some bugs into the buffers filling based on MA handles initiliazed which prevented the indicator to calculate correctly during the time and also the total indicator calculations are skipped within the same bar, leaving strange values into the buffer due to not clearing them correctly.

Overall, without your indicator code we can't imagine why this happen, what is almost sure is that the problem is in your indicator and not into the tester itself.