How to set breakpoints in the tester

WinUser32.mqh file included in a standard edition of MetaTrader (in experts\include) contains a lot of interesting functions. In this entry we will have a look at one of them, keybd_event. keybd_event, as its name indicates, simulates keyboard events so we are able to simulate pressing keys on the keyboard. In this way we can use a funny trick, which allows us to suspend the tester in visual mode by simulating the “pause” buttom being pressed. breakpoint() function code looks like this:

#include <WinUser32.mqh>

void breakpoint() {
   if(IsVisualMode()) {

We put the breakpoint function invocation in any place, where we want to suspend the tester. A few comments:

  • We have to check if the tester is running in the visual mode, otherwise it won’t work
  • keybd_event function is called two times, because we press the button at first time and “release” it at the second time
  • Sleep is necessary, because the button needs to be in the “pressed” state for a while
  • Such breakpoint is not perfect – if the tester is run in its fastest mode and our EA is simple, it is possible that the tester will stop even several bars after the point, where we wanted to have a breakpoint – we can do nothing but slower down the tester – then the breakpoint will work quite well

Share with your friends:

Send us your comments

Name (required)

Email (required)


  • Facebook