Schau, wie man Roboter kostenlos herunterladen kann
Finden Sie uns auf Facebook!
und werden Sie Mitglied unserer Fangruppe
Interessantes Skript?
Veröffentliche einen Link auf das Skript, damit die anderen ihn auch nutzen können
Hat Ihnen das Skript gefallen?
Bewerten Sie es im Terminal MetaTrader 5
Bibliotheken

MQL Plus Enhanced Error Handler Support - Bibliothek für den MetaTrader 5

Ansichten:
1821
Rating:
(7)
Veröffentlicht:
2020.11.22 11:45
Aktualisiert:
2022.03.20 15:59
\MQL5\Include\MQLplus\
lib_error.mqh (93.61 KB) ansehen
\MQL5\Include\MQLplus\lib_error\
Benötigen Sie einen Roboter oder Indikator, der auf diesem Code basiert? Bestellen Sie ihn im Freelance-Bereich Zum Freelance

Change-Log 3.12

  • Massive improvements to all aspects of the errror code generation and handling
  • Compatibility with MQL4 integrated
  • Support for user supplied OnError() function definition, see beginning of lib_error.mql-file
  • Overwrite Built-In function SetUserError()
  • Translation of error messages to almost all supported languages by MQL

Current Version 3.12


Encapsulates error code and text handling.

Supported features:

  • User defined error codes
  • Error code groups
  • Customizable output string
  • Seemless integration


Error code handling and error code resolving to text messages is a pain. This include file will solve some of the daily issues of handling error codes.


Example output:

This output was produced by ObjectGetInteger() in exaple code below.


Example code:

/////////////////////////////////////////
//
//  Handle user specified warning codes 
//  as errors.
//
#define LIB_ERR_LEVEL_WARNING_AS_ERROR
#include <mqlplus/lib_error.mqh>


/*
*********************************************************************************************************
*  Provider return codes                                                                                *
*********************************************************************************************************
*/

// Define error group id
#define EA_ERRGROUP_CODE_EA_CORE            0x01

// Defined return codes
#define CORE_SUCCESS                            LIB_ERROR_CODE(EA_ERRGROUP_CODE_EA_CORE, 0x00)
#define CORE_INFO_CORE_READY                    LIB_ERROR_CODE_HANDLED(EA_ERRGROUP_CODE_EA_CORE, 0x01)
#define CORE_WARN_PENDING_OPERATION             LIB_ERROR_CODE_WARNING(EA_ERRGROUP_CODE_EA_CORE, 0x01)

// Define message resolver
LIB_ERR_REGISTER_RESOLVER_BEGIN(EA_ERRGROUP_CODE_EA_CORE)
    LIB_ERR_REGISTER_RESOLVER_MSGCODE(CORE_SUCCESS,                     "CORE_SUCCESS",                     "Operation success. An order has been processed.")
    LIB_ERR_REGISTER_RESOLVER_MSGCODE(CORE_INFO_CORE_READY,             "CORE_INFO_CORE_READY",             "Expert advisor: Core ready.")
    LIB_ERR_REGISTER_RESOLVER_MSGCODE(CORE_WARN_PENDING_OPERATION,      "CORE_WARN_PENDING_OPERATION",      "A pending operation is awaiting confirmation.")
LIB_ERR_REGISTER_RESOLVER_END(EA_ERRGROUP_CODE_EA_CORE)








//+------------------------------------------------------------------+
//| Expert initialization function                                   |
//+------------------------------------------------------------------+
int OnInit()
  {
//---

    // Set a user defined error code
    SetUserError(CORE_INFO_CORE_READY);

   
//---
   return(INIT_SUCCEEDED);
  }




//+------------------------------------------------------------------+
//| Expert deinitialization function                                 |
//+------------------------------------------------------------------+
void OnDeinit(const int reason)
  {
//---

    // Perform some check    
    check_for_pending_orders();

    // Retrieve error code and display its text
    OnError();
    



//---
   return;
  }



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

    // Retrieve the error code
    int err_code = NULL;

    // Update some state by function
    if( (some_function())
     && (OnError(err_code)) )   // Display error message in journal and retrieve its corresponding error number
    {
        // Last error code is saved in err_code

        return;
    }


    // Continue processing


//---
    return;   
  }
//+------------------------------------------------------------------+




//+------------------------------------------------------------------+
//| check_for_pending_orders()                                       |
//+------------------------------------------------------------------+
void check_for_pending_orders()
  {
//---

    // Set a user defined error code
    SetUserError(CORE_WARN_PENDING_OPERATION);


//---
   return;
  }



//+------------------------------------------------------------------+
//| some_function()                                                  |
//+------------------------------------------------------------------+
bool some_function()
  {
//---
    // Error status
    bool err = false;


    // Perform some eventually failing operation
    err |= (!err) && !ObjectGetInteger(ChartID(), "", OBJPROP_COLOR) && OnError(__LINE__);


    // Set a user defined error code
    err |= (!err) && SetUserError(CORE_SUCCESS);

//---
   return(!err);
  }




    MQL Plus Enhanced Debugging Support MQL Plus Enhanced Debugging Support

    An (optional) include file to enhance debugging experience.

    Order - Deals - Position - Histroy Order - Deals - Position - Histroy

    Get all your Deal, Positions and order Information to .csv Files. Ready for Excel import History is splitted in 3 files, Positions, Deals and Orders

    HEX (Heikin Ashi Extended) HEX (Heikin Ashi Extended)

    Extended version of the original Heikin Ashi indicator

    AlgoX MA Channel AlgoX MA Channel

    Version: 1.0