Examples: Breakpoints in Tester: It's Possible!

 

New article Breakpoints in Tester: It's Possible! has been published:

The article deals with breakpoint emulation when passed through Tester, debug information being displayed.

The only thing I miss in MQL4 is a normal debugger for Expert Advisors. All human beings have human feelings, so we make mistakes. At normal programming, we set breakpoints, launch the program, and then, when execution reaches a breakpoint, it will be stopped. So we can have a look into the contents of variables exercising us.

Displaying of debugging data is now possible due to such functions as Print, Comment, etc. But we sometimes may want to stop the program temporarily in certain places at a certain moment in order to review the situation. There are some finer points here. The program is usually launched to trade on a demo account or on a real account. This means that we will only be able to see the results in several months… Thus, the debug mode is reasonable only in the test mode of Expert Advisors (in Tester).

Author: Christo Tsvetanov

 
Very interesting article. Unfortunately the current strategy tester only allows one to skip forward to a new date which is limited I guess to the period seperator time. What would be helpful is the have a script that allows for stopping at programmed invervals: i.e Set keyboard event to pause at a predetermined time. Or engage pause in so many minutes. Any ideas welcome.
 

Further to my last comment, I have created an advisor which allows for pauses during programming. (Pausebreak.mq attached) Cannot get it to work if dates go passed a weekend but no doubt someone will know how.

I have also inserted the code in an amended Vhands (vHandsTradepause.mq) but cannot get it to work (vHandsTradepause.mq4)

Would really be great to have the vHands working with breaks so we can check at certain intervals and when and do other stuff at the same time.

 
Here is the Pausebreak.mg
 

Hey this worked great in correcting the speed problem of Visual Mode where the last speed 32 is way too fast and speed 31 is way too slow. But the only problem was that at speed 32 it's moving so fast that by the time the keyboard event pauses the test it may be 20 to 50 bars past the even you wanted to pause at. So I added some number crunching as a sleep, since the Sleep() function doesn't work in testing.


void pause() // pauses visual mode during testing needs #include <WinUser32.mqh>
{
if(IsVisualMode())
{
keybd_event(19,0,0,0);
keybd_event(19,0,2,0);
//----crunch some numbers as sleep
int a=199999999;
int b=1;
while(a>b)
b++;
}

}

 
mql5 has debugger, pity that the language is different
 
#include <WinUser32.mqh>
#import "user32.dll"
  int    GetAncestor(int, int);
#import
void     PauseTest(){                                 #define GA_ROOT 2
   datetime now = TimeCurrent();    static datetime oncePerTick;
   if(oncePerTick != now) if(IsTesting()) if(IsVisualMode()) if(IsDllsAllowed()
   ){ oncePerTick = now;
      for(int i=0; i<200000; i++){     // Delay required for speed=32 (max)
         if(IsStopped())   break;         // http://forum.mql4.com/32837 WH-DL
         int      main = GetAncestor(WindowHandle(Symbol(), Period()), GA_ROOT);
         if(i==0) PostMessageA(main, WM_COMMAND, 0x57a, 0); // 1402. Pause
}  }  }
 

I am attempting to set some breakpoints in my MQL4 EA running in the tester

The breakpoints work, but I cannot restart the test? And any subsequent attempts at starting a test do not run (blank visual mode chart) - I have to restart the terminal.

Any thoughts on how to restart the test after a breakpoint? And why my terminal might be freezing-

Terminal is IronFx (Build 745), Windows 7

#include <WinUser32.mqh>
#import "user32.dll"
  int GetAncestor(int, int);
#import
void PauseTest(){   datetime now = TimeCurrent();   static datetime oncePerTick;
    if( oncePerTick != now  )if( IsTesting()
    )if( IsVisualMode()     )if( IsDllsAllowed()    ){  oncePerTick = now;
        for(int i=0; i<200000; i++){        // Delay required for speed=32 (max)
            if (IsStopped()) break;         // http://forum.mql4.com/32837 WH-DL
            int main = GetAncestor(WindowHandle(Symbol(), Period()), 2);//GA_ROOT
            if (i==0) PostMessageA(main, WM_COMMAND, 0x57a, 0); // 1402. Pause
    }   }
    // The PostMessage above sends the command to the main terminal. Thus it
    // only affects the active chart window. To maximize a window for example
    // must activate it first. http://forum.mql4.com/35336#538848
    // See also SetForgroundWindow(h) https://www.mql5.com/en/code/10146
}
//Breakpoint neither receive nor send back any parameters
void BreakPoint()
{
   //It is expecting, that this function should work
   //only in tester
   if (!IsVisualMode()) return(0);
   
   //Preparing a data for printing
   //Comment() function is used as 
   //it give quite clear visualisation
   string Comm="";
   Comm=Comm+"Bid="+Bid+"\n";
   Comm=Comm+"Ask="+Ask+"\n";
   
   Comment(Comm);
   
   //Press/release Pause button
   //19 is a Virtual Key code of "Pause" button
   //Sleep() is needed, because of the probability
   //to misprocess too quick pressing/releasing
   //of the button
   keybd_event(19,0,0,0);
   Sleep(10);
   keybd_event(19,0,2,0);
}
cross posted: https://www.mql5.com/en/forum/38092
Reason: