/////////////////////////////////////////////////////// // // SaherElm IT Center MQL5 Expert Advisor // ---------------------------------------- // Name: XTEST // 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 XTEST EA" #property strict // // START Inputs ... // input group "Commons"; // // XCTIMER inputs ... input bool xTESTShowCandleTimer = true; // Show Condle Remaining Time input color xTESTCandleTimerColot = clrYellow; // Candle Timer Color input ENUM_BASE_CORNER xTESTCandleTimerCorner = 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" // // XTEST Signal Provider ... #include "../Providers/x-saherelm.xtest.provider.lib.mq5" // // END Including Providers ... // // // START Global Definitions: Variables, Properties and etc ... // bool isXTESTNewHour; bool isXTESTNewDay; bool isXTESTNewWeek; bool isXTESTNewMonth; // int xTESTCTimerHandler = INVALID_HANDLE; // // END Global Definitions: Variables, Properties and etc ... // // // START Event Handlers ... // // // Initialization ... int OnInit() { // logTag = "XTESTEA"; drawPrefix = logTag; alertPrefix = logTag; // // Apply default Chart Style for EA ... ApplyChartStyle(); // // Reset Timings ... ResetTiming(); // // Validate Inputs ... if (!ValidateInputs()) { return INIT_PARAMETERS_INCORRECT; } // // Initialize XTEST Provider ... if (!XTESTInitSignalProviderLibrary()) { return INIT_PARAMETERS_INCORRECT; } // // Init XCTimer ... if (xTESTShowCandleTimer) { if (!XTESTCTimerInit()) { 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 XTEST Provider ... XTESTDeinitSignalProviderLibrary(reason); // // De Init XDraw Library ... // OnDeinitDrawLibrary(); // IndicatorRelease(xTESTCTimerHandler); } // // On Tick Handler ... void OnTick() { // // Handle Monthly Alert ... bool isFirstMonth = xMonth == -1; isXTESTNewMonth = IsNewMonth(); bool canMonthlyAlert = isXTESTNewMonth && xTESTEnableAlerts && xTESTEnableMonthlyAlerts; bool canMonthlyReport = !isFirstMonth && canMonthlyAlert && xTESTEnableMonthlyReports; if (canMonthlyAlert) { // string message = "New Month ..."; // // Prepare Monthly Report ... if (canMonthlyReport) { // string report = xTESTReporter.GenerateReportString(XREPORT_MONTHLY); // message = "Last Month Report:\n" + report; } // // Reset Report ... xTESTReporter.Reset(XREPORT_MONTHLY); // SendAlert(message); } // // Handle Weekly Alert ... bool isFirstWeek = xDayOfWeek == -1; isXTESTNewWeek = IsNewWeek(); bool canWeeklyAlert = isXTESTNewWeek && xTESTEnableAlerts && xTESTEnableWeeklyAlerts; bool canWeeklyReport = !isFirstWeek && canWeeklyAlert && xTESTEnableWeeklyReports; if (canWeeklyAlert) { // string message = "New Week ..."; // // Prepare Weekly Report ... if (canWeeklyReport) { // string report = xTESTReporter.GenerateReportString(XREPORT_WEEKLY); // message = "Last Week Report:\n" + report; } // // Reset Report ... xTESTReporter.Reset(XREPORT_WEEKLY); // SendAlert(message); } // // Handle Daily Alert ... bool isFirstDay = xDay == -1; isXTESTNewDay = IsNewDay(); bool canDailyAlert = isXTESTNewDay && xTESTEnableAlerts && xTESTEnableDailyAlerts; bool canDailyReport = !isFirstDay && canDailyAlert && xTESTEnableDailyReports; if (canDailyAlert) { // string message = "New Day ..."; // // Prepare Daily Report ... if (canDailyReport) { // string report = xTESTReporter.GenerateReportString(XREPORT_DAILY); // message = "Last Week Report:\n" + report; } // // Reset Report ... xTESTReporter.Reset(XREPORT_DAILY); // SendAlert(message); } // // Handle Hourly Alert ... bool isFirstHour = xHour == -1; isXTESTNewHour = IsNewHour(); bool canHourlyAlert = isXTESTNewHour && xTESTEnableAlerts && xTESTEnableHourlyAlerts; if (canHourlyAlert) { // string message = "New Hour ..."; // SendAlert(message); } // // Prevent Going Forward if user Disable it ... if (xTESTEnableProvider) { // // Handle Processing on XTEST Signal Provider ... XTESTSignalProviderDoControlState(); } // // Check Can Ignore Tick or not .. bool canIgnoreTick = xTESTIsTestMode ? !IsNewCandle() : !IsNewCandle() && xTESTWaitUntilNextCandle; if (canIgnoreTick) { return; } // xTESTWaitUntilNextCandle = false; // // Prevent Going Forward if user Disable it ... if (xTESTEnableProvider) { // // Handle Processing on XTEST Signal Provider ... XTESTSignalProviderHandleTick(); } } // // Handle Trade Events ... void OnTrade() { // // Prevent Going Forward if user Disable it ... if (xTESTEnableProvider) { // // Handle Processing Trades on XTEST Signal Provider ... XTESTSignalProviderHandleTrade(); } } // // END Event Handlers ... // // // START Functions ... // // // Validate Input Args for Initialization ... bool ValidateInputs() { // bool result = false; // // Validate Args ... // // Validate XTEST Provider Inputs ... result = XTESTValidateInputs(); if (!result) { return false; } // // Logging State ... string message = "Validation of (" + logTag + ") Inputs " + (result ? "Succeeded" : "Failed") + " ..."; LogMessage(message); // return result; } bool XTESTCTimerInit() { // bool result = true; // xTESTCTimerHandler = iCustom( _Symbol, _Period, "x-saherelm.xctimer.indicator", // // Inputs ... xTESTCandleTimerColot, xTESTCandleTimerCorner); // if (xTESTCTimerHandler == INVALID_HANDLE) { result = false; } // return result; } // // END Functions ... //