/////////////////////////////////////////////////////// // // SaherElm IT Center MQL5 Expert Advisor // ---------------------------------------- // Name: XAUUSD // Description: this is an expert controller // advisors which provides a mechanism for use them ... // // // Maintainer: // ------------ // Hadi Khazaee Asl (hadi_khazaee_asl@yahoo.com) // ////////////////////////////////////////////////////// // // Global Properties ... #property copyright "Copyright 2023, SaherElm IT Center" #property link "https://saherelm.ir" #property version "1.00" #property description "SaherElm XEMPTY5 EA" #property strict // // START Inputs ... // input group "Commons"; // // XCTIMER inputs ... input bool xEMPTY5ShowCandleTimer = true; // Show Condle Remaining Time input color xEMPTY5CandleTimerColot = clrYellow; // Candle Timer Color input ENUM_BASE_CORNER xEMPTY5CandleTimerCorner = CORNER_RIGHT_LOWER; // Where to Show Candle Timer // // END Inputs ... // // // START Including Providers ... // // // Logger Library ... #include "../Libraries/x-saherelm.log.lib.mq5" // // Common Library ... #include "../Libraries/x-saherelm.common.lib.mq5" // // Alert Library ... #include "../Libraries/x-saherelm.alert.lib.mq5" // // Draw Library ... #include "../Libraries/x-saherelm.draw.lib.mq5" // // XEMPTY5 Signal Provider ... #include "../Providers/x-saherelm.xempty5.provider.lib.mq5" // // END Including Providers ... // // // START Global Definitions: Variables, Properties and etc ... // bool isXEMPTY5NewHour; bool isXEMPTY5NewDay; bool isXEMPTY5NewWeek; bool isXEMPTY5NewMonth; // int xEMPTY5CTimerHandler = INVALID_HANDLE; // // END Global Definitions: Variables, Properties and etc ... // // // START Event Handlers ... // // // Initialization ... int OnInit() { // logTag = "XEMPTY5EA"; drawPrefix = logTag; alertPrefix = logTag; // // Apply default Chart Style for EA ... ApplyChartStyle(); // // Reset Timings ... ResetTiming(); // // Validate Inputs ... if (!ValidateInputs()) { return INIT_PARAMETERS_INCORRECT; } // // Initialize XEMPTY5 Provider ... if (!XEMPTY5InitSignalProviderLibrary()) { return INIT_PARAMETERS_INCORRECT; } // // Init XCTimer ... if (xEMPTY5ShowCandleTimer) { if (!XEMPTY5CTimerInit()) { return INIT_FAILED; } } // // Init Succeed ... return INIT_SUCCEEDED; } // // DeInitialization ... void OnDeinit(const int reason) { // // REASON_PROGRAM 0 The EA has stopped working calling the ExpertRemove() function // REASON_REMOVE 1 Program removed from a chart // REASON_RECOMPILE 2 Program recompiled // REASON_CHARTCHANGE 3 A symbol or a chart period is changed // REASON_CHARTCLOSE 4 Chart closed // REASON_PARAMETERS 5 Inputs changed by a user // REASON_ACCOUNT 6 Another account has been activated or reconnection to the trade server has occurred due to changes in the account settings // REASON_TEMPLATE 7 Another chart template applied // REASON_INITFAILED 8 The OnInit() handler returned a non-zero value // REASON_CLOSE 9 Terminal closed // // Here we can handle De Initialization Reasons ... // // De Initialize XEMPTY5 Provider ... XEMPTY5DeinitSignalProviderLibrary(reason); // // De Init XDraw Library ... // OnDeinitDrawLibrary(); // IndicatorRelease(xEMPTY5CTimerHandler); } // // On Tick Handler ... void OnTick() { // // Handle Monthly Alert ... bool isFirstMonth = xMonth == -1; isXEMPTY5NewMonth = IsNewMonth(); bool canMonthlyAlert = isXEMPTY5NewMonth && xEMPTY5EnableAlerts && xEMPTY5EnableMonthlyAlerts; bool canMonthlyReport = !isFirstMonth && canMonthlyAlert && xEMPTY5EnableMonthlyReports; if (canMonthlyAlert) { // string message = "New Month ..."; // // Prepare Monthly Report ... if (canMonthlyReport) { // string report = xEMPTY5Reporter.GenerateReportString(XREPORT_MONTHLY); // message = "Last Month Report:\n" + report; } // // Reset Report ... xEMPTY5Reporter.Reset(XREPORT_MONTHLY); // SendAlert(message); } // // Handle Weekly Alert ... bool isFirstWeek = xDayOfWeek == -1; isXEMPTY5NewWeek = IsNewWeek(); bool canWeeklyAlert = isXEMPTY5NewWeek && xEMPTY5EnableAlerts && xEMPTY5EnableWeeklyAlerts; bool canWeeklyReport = !isFirstWeek && canWeeklyAlert && xEMPTY5EnableWeeklyReports; if (canWeeklyAlert) { // string message = "New Week ..."; // // Prepare Weekly Report ... if (canWeeklyReport) { // string report = xEMPTY5Reporter.GenerateReportString(XREPORT_WEEKLY); // message = "Last Week Report:\n" + report; } // // Reset Report ... xEMPTY5Reporter.Reset(XREPORT_WEEKLY); // SendAlert(message); } // // Handle Daily Alert ... bool isFirstDay = xDay == -1; isXEMPTY5NewDay = IsNewDay(); bool canDailyAlert = isXEMPTY5NewDay && xEMPTY5EnableAlerts && xEMPTY5EnableDailyAlerts; bool canDailyReport = !isFirstDay && canDailyAlert && xEMPTY5EnableDailyReports; if (canDailyAlert) { // string message = "New Day ..."; // // Prepare Daily Report ... if (canDailyReport) { // string report = xEMPTY5Reporter.GenerateReportString(XREPORT_DAILY); // message = "Last Week Report:\n" + report; } // // Reset Report ... xEMPTY5Reporter.Reset(XREPORT_DAILY); // SendAlert(message); } // // Handle Hourly Alert ... bool isFirstHour = xHour == -1; isXEMPTY5NewHour = IsNewHour(); bool canHourlyAlert = isXEMPTY5NewHour && xEMPTY5EnableAlerts && xEMPTY5EnableHourlyAlerts; if (canHourlyAlert) { // string message = "New Hour ..."; // SendAlert(message); } // // Prevent Going Forward if user Disable it ... if (xEMPTY5EnableProvider) { // // Handle Processing on XEMPTY5 Signal Provider ... XEMPTY5SignalProviderDoControlState(); } // // Check Can Ignore Tick or not .. bool canIgnoreTick = xEMPTY5IsTestMode ? !IsNewCandle() : !IsNewCandle() && xEMPTY5WaitUntilNextCandle; if (canIgnoreTick) { return; } // xEMPTY5WaitUntilNextCandle = false; // // Prevent Going Forward if user Disable it ... if (xEMPTY5EnableProvider) { // // Handle Processing on XEMPTY5 Signal Provider ... XEMPTY5SignalProviderHandleTick(); } } // // Handle Trade Events ... void OnTrade() { // // Prevent Going Forward if user Disable it ... if (xEMPTY5EnableProvider) { // // Handle Processing Trades on XEMPTY5 Signal Provider ... XEMPTY5SignalProviderHandleTrade(); } } // // END Event Handlers ... // // // START Functions ... // // // Validate Input Args for Initialization ... bool ValidateInputs() { // bool result = false; // // Validate Args ... // // Validate XEMPTY5 Provider Inputs ... result = XEMPTY5ValidateInputs(); if (!result) { return false; } // // Logging State ... string message = "Validation of (" + logTag + ") Inputs " + (result ? "Succeeded" : "Failed") + " ..."; LogMessage(message); // return result; } bool XEMPTY5CTimerInit() { // bool result = true; // xEMPTY5CTimerHandler = iCustom( _Symbol, _Period, "x-saherelm.xctimer.indicator", // // Inputs ... xEMPTY5CandleTimerColot, xEMPTY5CandleTimerCorner); // if (xEMPTY5CTimerHandler == INVALID_HANDLE) { result = false; } // return result; } // // END Functions ... //