Watch how to download trading robots for free
Interesting script?
So post a link to it -
let others appraise it
You liked the script? Try it in the MetaTrader 5 terminal

MQL Plus Enhanced Debugging Support - library for MetaTrader 5

Dominik Egert

votes: 8
2020.11.21 12:17
2020.11.30 20:08

Current version: 1.06

Change-Log 1.06

  • Fix for VarDump macro
  • Minor fixes, typos...
  • Updated code style format

Defines macros for supporting debugging code.

Supports following features:

  • Debug string comments
  • VarDump variables and arrays
  • Different assert types
  • Trace
  • Conditional Breakpoints
  • Performance counters

All addons are freely configurable. All code inclusions have been done in preprocessor macros.

There is one known caveat within the definition of macros. The macro NULL does not work on preprocessor level, so it needs to be replaced. To work around the issue, you should cast the NULL makro like this: (double)NULL - Depending on the type being in use... string, int and so on...

Of course, the code is not fully complete and an assert usually includes a "try catch" but as they are not available, other techniques needed to be found to achieve at about a comparable result. Breakpoints will halt the code at that line, while you are debugging, pressing the F9-Key will make the debugger break into this exact location within the code. As close as possible, not the original.

All needed documentation is included in the header file.

All macros are optional, so the code below shows most of available macros. A full list is included.

Example journal output:

Example trace output

Example Code:

// Function debug trace code
// We define function specific macros
// This makes tracing on/off switchable
// Return value macros need to be adjusted
// to reflect the actual return value of 
// the function. If performance counters 
// are used, include the functions performance
// counter here.

        #define DBG_TRACE_SOME_FUNCTION(x) x
        #define DBG_TRACE_SOME_FUNCTION(x)
//| some_function()                                                  |
double some_function(const int index = NULL)
        DBG_TRACE_SOME_FUNCTION(DBG_MSG_TRACE_BEGIN);                                                                           // Begin tracing of function
        DBG_TRACE_SOME_FUNCTION(DBG_MSG_INT(index));                                                                            // Output the functions parameter
        PERF_COUNTER_BEGIN                                                                                                      // Initialize function performance counter

        DBG_TRACE_SOME_FUNCTION(DBG_TRACE_LOOP_BEGIN);                                                                          // Initialize loop tracing
        for(int cnt = (int)some_periods; ((cnt > NULL) && (!_StopFlag)); cnt--)
                DBG_TRACE_SOME_FUNCTION(DBG_TRACE_LOOP_START);                                                                  // Update loop enter counter 

                // Basic calculations
                a += a * cnt;

                DBG_MSG_DBL(a);                                                                                                 // Print out variable "a" when in debug mode

                // Some check
                { continue; }

                DBG_TRACE_SOME_FUNCTION(DBG_TRACE_LOOP_FINISH);                                                                 // Update second loop counter 
        DBG_TRACE_SOME_FUNCTION(DBG_TRACE_LOOP_END);                                                                            // Close loop counter
        // Assert value is greater than NULL
        DBG_ASSERT((some_testing_value > NULL), DBG_MSG_DBL(some_testing_value));                                               // Perform assert on value

        // Return
        DBG_TRACE_SOME_FUNCTION_RETURN(some_double_value);                                                                      // Return value

	// ... OR ...

	// Return
	DBG_TRACE_SOME_FUNCTION_RETURN((double)NULL);										// Return >cast to double< NULL
    observer (pull model) - behavioral design pattern observer (pull model) - behavioral design pattern

    define a one-to-many dependency between objects so that when one object changes state, all its dependents are notified and updated automatically

    The 2 Pole Butterworth Filter The 2 Pole Butterworth Filter

    Indicator "The 2 Pole Butterworth Filter". was created by John Ehlers ("Cybernetic Analysis For Stocks And Futures", p. 192)

    Camarilla Points Camarilla Points

    Indicator Camarilla Points "Stocks & Commodities V. 31:3 (pg. 10-15)"

    MQL Plus Enhanced Error Handler Support MQL Plus Enhanced Error Handler Support

    An (optional) include file to enhance error code handling experience.