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
Libraries

MQL Plus Enhanced Debugging Support - library for MetaTrader 5

Views:
1720
Rating:
votes: 17
Published:
2020.11.21 12:17
Updated:
2022.06.10 11:16
\MQL5\Include\MQLplus\
lib_debug.mqh (334.96 KB) view

Current version: 4.85

- Minor bug fixes

Added/extended features

  • Conditional breakpoints
  • Enahnced MQL4-Compatibility



Current version: 4.41

From now on this Project is part of the cloud storage shared project

"MQLplus Include Library Collection"

Download and contribute as you like.


Current version: 4.3


Change-Log 4.3

  • Added all MQL5 known data types to the macro DBG_MSG_VAR() and DBG_STR_VAR()
  • Improved output formatting
  • Added trace call depth for functions and correct indenting of debug messages
  • Bugfixes include: 
  • return-macro can now be passed function calls as return value
  • Translation of DeInit-Reason, and automatic insertion in OnDeinit call
  • Multiple output format errors

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 some of available macros. A full list and detailed description is included in the header file.

Example journal output:



Example Code:

#define LIB_DEBUG
#include <mqlplus/lib_debug.mqh>


//+------------------------------------------------------------------+
//| Expert initialization function                                   |
//+------------------------------------------------------------------+
/////////////////////////////////////
// Function debug trace code
#ifdef DBG_TRACE_ONINIT
#undef DBG_TRACE_ONINIT
#define DBG_TRACE_ONINIT(x) x
#define DBG_TRACE_ONINIT_RETURN(x) DBG_MSG_TRACE_RETURN_VAR(x)
#else
#define DBG_TRACE_ONINIT(x)
#define DBG_TRACE_ONINIT_RETURN(x) DBG_MSG_NOTRACE_RETURN_VAR(x)
#endif
/////////////////////////////////////
int OnInit()
  {
DBG_TRACE_ONINIT(
    DBG_MSG_TRACE_BEGIN;
    );
PERF_COUNTER_BEGIN;
//---
    int test = NULL;
    DBG_MSG_VAR(test);          

   
//---
   DBG_TRACE_ONINIT_RETURN(INIT_SUCCEEDED);
  }




//+------------------------------------------------------------------+
//| Expert deinitialization function                                 |
//+------------------------------------------------------------------+
/////////////////////////////////////
// Function debug trace code
#ifdef DBG_TRACE_ONDEINIT
#undef DBG_TRACE_ONDEINIT
#define DBG_TRACE_ONDEINIT(x) x
#define DBG_TRACE_ONDEINIT_RETURN DBG_MSG_TRACE_RETURN
#else
#define DBG_TRACE_ONDEINIT(x)
#define DBG_TRACE_ONDEINIT_RETURN DBG_MSG_NOTRACE_RETURN
#endif
/////////////////////////////////////
void OnDeinit(const int reason)
  {
DBG_TRACE_ONDEINIT(
    DBG_MSG_TRACE_BEGIN;
    DBG_MSG_VAR(reason);
    );
PERF_COUNTER_BEGIN;
//---

    int test = NULL;
    DBG_MSG_VAR(test);

   DBG_TRACE_ONDEINIT_RETURN;
  }



//+------------------------------------------------------------------+
//| Expert tick function                                             |
//+------------------------------------------------------------------+
void OnTick()
  {
//---

    int test = NULL;
    DBG_MSG_VAR(test);


    return;   
  }
//+------------------------------------------------------------------+
    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.