Visual testing in MQL5

 

Is is possible? And if yes, how? Or, can we debug EA's on history data? Or over the weekend? I tried last weekend but as market was closed, no ticks coming, the breakpoint in OnTick() is never hit :D If we could use debugging on history data, then the "visual testing" problem is somehow solved. Anyhow there is a "step by step" button (F12) there, in debugger, what is used for? :D let's give some meaning to it! :P

thanks a lot


later edit: How it could be done: Add few items in the MetaEditor/Tools/Options/Debugger tab (this tab is anyhow quite empty hehe) and use F12 to get incoming ticks from the history when debugging

This would solve the problem for debugging during the weekend and also the visual testing story. All the logic behind debugging is anyhow written, it would be just a matter of "where to take the ticks from" (well, is not so easy, but we hope... the hope dies last).

Visualize a Strategy in the MetaTrader 5 Tester
  • 2012.06.11
  • MetaQuotes Software Corp.
  • www.mql5.com
We all know the saying "Better to see once than hear a hundred times". You can read various books about Paris or Venice, but based on the mental images you wouldn't have the same feelings as on the evening walk in these fabulous cities. The advantage of visualization can easily be projected on any aspect of our lives, including work in the market, for example, the analysis of price on charts using indicators, and of course, the visualization of strategy testing. This article contains descriptions of all the visualization features of the MetaTrader 5 Strategy Tester.
 

I agree this would be really useful.

Often there isnt really any easy way to figure out exactly what is going on inside your system over a large number of bars. I know you can create logs and csv files to debug, but itd be very convenient to be able to have breakpoints in the buy/sell routines, and then backtrack to find exactly what triggered the trade. This combined with Mt4 style visual mode would be amazing.

Documentation on MQL5: Timeseries and Indicators Access / Bars
  • www.mql5.com
Timeseries and Indicators Access / Bars - Documentation on MQL5
 
stitch:

Is is possible? And if yes, how? Or, can we debug EA's on history data? Or over the weekend? I tried last weekend but as market was closed, no ticks coming, the breakpoint in OnTick() is never hit :D If we could use debugging on history data, then the "visual testing" problem is somehow solved. Anyhow there is a "step by step" button (F12) there, in debugger, what is used for? :D let's give some meaning to it! :P

thanks a lot


later edit: How it could be done: Add few items in the MetaEditor/Tools/Options/Debugger tab (this tab is anyhow quite empty hehe) and use F12 to get incoming ticks from the history when debugging

This would solve the problem for debugging during the weekend and also the visual testing story. All the logic behind debugging is anyhow written, it would be just a matter of "where to take the ticks from" (well, is not so easy, but we hope... the hope dies last).


Metal10k:

I agree this would be really useful.

Often there isnt really any easy way to figure out exactly what is going on inside your system over a large number of bars. I know you can create logs and csv files to debug, but itd be very convenient to be able to have breakpoints in the buy/sell routines, and then backtrack to find exactly what triggered the trade. This combined with Mt4 style visual mode would be amazing.

Mode visual testing will be added later.


 
Metal10k:

I agree this would be really useful.

Often there isnt really any easy way to figure out exactly what is going on inside your system over a large number of bars. I know you can create logs and csv files to debug, but itd be very convenient to be able to have breakpoints in the buy/sell routines, and then backtrack to find exactly what triggered the trade. This combined with Mt4 style visual mode would be amazing.

Setting breakpoints and all the stuff is already possible and it is working fine. The real problem is that you can trigger the breakpoint in only two ways: one is if the breakpoint is in OnInit() function, it will be triggered when you put the expert on the chart (click the debug button), and then from there, you can call your function that you want to debug, directly from the OnInit() function, then go step by step. Other is to have a breakpoint in OnTick function, or anywhere in the program, it will be triggered when the respective function is called. But the function can only be called when a tick arives, and you have NO possibility to emulate a new tick if the market is closed. Of course, you can use an OnTimer() event to periodically call your function, but this makes everything quite complicate. All this issues would be solved if MQ would allow us to emulate a new tick by pressing F12, eventually taking this tick from the history, as I described above, or making a "fake" tick with last price. Of course the second could not be used to debug the strategy, but only to debug the function, so taking the tick from the history would be more useful.

About the "large number of bars", well, you can set breakpoints everywhere you like, go step by step from there, etc. This seems to be already working, and the large log files won't be necessary. You can set a breakpoint in the OnTrade(), if you have one, for example, that solves you problem. But to call the OnTrade() function during Sundays, well... this could be a little more... frustrating, hehe...

I also found out some bug in ST5, when I use genetic optimization some steps won't take any trade and return equity 10k. As it is impossible for my EA to take no trades in one year, I tested that steps one by one using rightclick on them and "run single test". All of them worked normally, taking hundreds of deals in the testing year (with profits or loses depending of the parameters). But during optimization, they return zero transactions and equity 10k. Not always, but sometimes. This is for sure a bug in ST5, and the problem is that such steps are considered "good" by the genetic algorithm, because they did not lose any money, drawback is zero, equity of 10k is better then other steps that traded normally and made 9k or 8k, etc., and they are paired forward, kicking out all the optimization process.

So I had to write an "OnTester()" function like that (just an example, my function is more complicated, trying to avoid other ST bugs too):

//dealing with strategy tester's bugs....
double OnTester()
{
   if (MathAbs(AccountInfoDouble(ACCOUNT_BALANCE)-10000)<0.1) return 0;
   return AccountInfoDouble(ACCOUNT_BALANCE);
}

and then making the optimization on Custom Max instead of Balance Max. This raised the efficiency (final balance) with more then 30%, as all the wrong steps are discarded for future genetic pairing.



 
stitch:

Setting breakpoints and all the stuff is already possible and it is working fine. The real problem is that you can trigger the breakpoint in only two ways: one is if the breakpoint is in OnInit() function, it will be triggered when you put the expert on the chart (click the debug button), and then from there, you can call your function that you want to debug, directly from the OnInit() function, then go step by step. Other is to have a breakpoint in OnTick function, or anywhere in the program, it will be triggered when the respective function is called. But the function can only be called when a tick arives, and you have NO possibility to emulate a new tick if the market is closed. Of course, you can use an OnTimer() event to periodically call your function, but this makes everything quite complicate. All this issues would be solved if MQ would allow us to emulate a new tick by pressing F12, eventually taking this tick from the history, as I described above, or making a "fake" tick with last price. Of course the second could not be used to debug the strategy, but only to debug the function, so taking the tick from the history would be more useful.

About the "large number of bars", well, you can set breakpoints everywhere you like, go step by step from there, etc. This seems to be already working, and the large log files won't be necessary. You can set a breakpoint in the OnTrade(), if you have one, for example, that solves you problem. But to call the OnTrade() function during Sundays, well... this could be a little more... frustrating, hehe...

I also found out some bug in ST5, when I use genetic optimization some steps won't take any trade and return equity 10k. As it is impossible for my EA to take no trades in one year, I tested that steps one by one using rightclick on them and "run single test". All of them worked normally, taking hundreds of deals in the testing year (with profits or loses depending of the parameters). But during optimization, they return zero transactions and equity 10k. Not always, but sometimes. This is for sure a bug in ST5, and the problem is that such steps are considered "good" by the genetic algorithm, because they did not lose any money, drawback is zero, equity of 10k is better then other steps that traded normally and made 9k or 8k, etc., and they are paired forward, kicking out all the optimization process.

So I had to write an "OnTester()" function like that (just an example, my function is more complicated, trying to avoid other ST bugs too):

and then making the optimization on Custom Max instead of Balance Max. This raised the efficiency (final balance) with more then 30%, as all the wrong steps are discarded for future genetic pairing.



very useful . thank you.
Reason: