0 Views
0 Downloads
0 Favorites
mql_market
ÿþ//+------------------------------------------------------------------+

//|                                                   Playground.mq5 |

//|             Copyright 2020, Freie Netze UG (haftunbgsbeschränkt) |

//|                                      https://www.freie-netze.de/ |

//+------------------------------------------------------------------+







/////////////////////////////////////////

//

//  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);

  }







Comments