From c49034002c168b07ea99a6b28a1951405c071b0a Mon Sep 17 00:00:00 2001 From: Hadi Khazaee Asl Date: Mon, 8 Jul 2024 20:05:29 +0330 Subject: [PATCH] add alert class instance in x121ea and configure it for using tima tracker alerting ... --- Experts/x-saherelm.x121.ea.mq5 | 68 +++++++++++++++------- Experts/x-test.ea.mq5 | 87 +++++++++++++++++++++++++---- Libraries/x-saherelm.common.lib.mq5 | 25 +++++++++ 3 files changed, 147 insertions(+), 33 deletions(-) diff --git a/Experts/x-saherelm.x121.ea.mq5 b/Experts/x-saherelm.x121.ea.mq5 index aa25f1a4..d5db61e6 100644 --- a/Experts/x-saherelm.x121.ea.mq5 +++ b/Experts/x-saherelm.x121.ea.mq5 @@ -139,6 +139,7 @@ string x121EAUsedSymbols[]; XSCX121SetupEA *x121EA; // +XSCAlert *x121EAAlert; XSCXCTHelper *x121EACTHelper; XSCXCCHelper *x121EACCHelper; @@ -207,32 +208,46 @@ void OnTick() // Time Tracking ... // - if (x121EATimeTracker.IsNewHour()) - { - // - if (!is121EAInTestMode) - { - x121EA.Alert("New Hour ..."); - } - } - - // - if (x121EATimeTracker.IsNewDay()) - { - // - if (!is121EAInTestMode) - { - x121EA.Alert("New Day ..."); - } - } - - // + // Alert Month ... if (x121EATimeTracker.IsNewMonth()) { // if (!is121EAInTestMode) { - x121EA.Alert("New Mount ..."); + x121EAAlert.Alert("New Mount ..."); + } + } + + // + // Alert Week ... + if (x121EATimeTracker.IsNewWeek()) + { + // + if (!is121EAInTestMode) + { + x121EAAlert.Alert("New Week ..."); + } + } + + // + // Alert New Day ... + if (x121EATimeTracker.IsNewDay()) + { + // + if (!is121EAInTestMode) + { + x121EAAlert.Alert("New Day ..."); + } + } + + // + // Alert New Hour ... + if (x121EATimeTracker.IsNewHour()) + { + // + if (!is121EAInTestMode) + { + x121EAAlert.Alert("New Hour ..."); } } @@ -282,6 +297,17 @@ bool InitialEA() return result; } + // + // Initial Alert Class ... + x121EATimeTracker.Clean(); + x121EAAlert = new XSCAlert(); + x121EAAlert.SetPrefix(ShortName); + x121EAAlert.SetEnableAlerts(x121EAEnableAlerts); + x121EAAlert.SetLogAlerts(x121EALogAlerts); + x121EAAlert.SetMailAlerts(x121EAMailAlerts); + x121EAAlert.SetPushAlerts(x121EAPushAlerts); + x121EAAlert.SetTerminalAlerts(x121EATerminalAlerts); + // // TesterHideIndicators(true); diff --git a/Experts/x-test.ea.mq5 b/Experts/x-test.ea.mq5 index 0534aaa7..4b9dd092 100644 --- a/Experts/x-test.ea.mq5 +++ b/Experts/x-test.ea.mq5 @@ -49,6 +49,10 @@ XSCXTestSetup *iSetup; XSCXCTHelper *mCTHelper; XSCXCCHelper *mCCHelper; +// +XSCAlert *eaAlert; +XTimeTracker eaTimeTracker; + // // For Pivot Checking ... XPivot lastSupportPivot; @@ -79,6 +83,7 @@ int OnInit() } // + // Initial Bar Tracker ... bool isInited = eaBarTracker.Init( _Symbol, _Period // @@ -88,6 +93,18 @@ int OnInit() return INIT_FAILED; } + // + // Initial Alert Class ... + eaAlert = new XSCAlert( + ShortName, + true, + true, + false, + false, + true // + ); + eaTimeTracker.Clean(); + // // Init Succeed ... return INIT_SUCCEEDED; @@ -131,11 +148,15 @@ void OnTick() // // Check Pivots ... - HandleCheckPivots(); + // HandleCheckPivots(); // // Check Zones ... // HandleCheckZones(); + + // + // Check Time Tracker ... + // HandleCheckTimeTracker(); } // @@ -446,50 +467,92 @@ void HandleCheckPivots() } // -void HandleCheckZones() { +void HandleCheckZones() +{ // bool result = false; // // Find Last Support Zone ... - if (!lastSupportZone.IsValid()) { + if (!lastSupportZone.IsValid()) + { // result = lastSupportZone.FindLastSupportZone( _Symbol, _Period // ); - if (!result) { + if (!result) + { return; } // result = lastSupportZone.Draw(ChartID()); - if (result) { + if (result) + { Print("Valid Support Zone ..."); } - } else { - + } + else + { } // // Find Last Resistance Zone ... - if (!lastResistanceZone.IsValid()) { + if (!lastResistanceZone.IsValid()) + { // result = lastResistanceZone.FindLastResistanceZone( _Symbol, _Period // ); - if (!result) { + if (!result) + { return; } // result = lastResistanceZone.Draw(ChartID()); - if (result) { + if (result) + { Print("Valid Resistance Zone ..."); } - } else { + } + else + { + } +} +// +void HandleCheckTimeTracker() { + // + // Month ... + if (eaTimeTracker.IsNewMonth()) { + eaAlert.Alert("New Month ..."); + } + + // + // Week ... + if (eaTimeTracker.IsNewWeek()) { + eaAlert.Alert("New Week ..."); + } + + // + // Day ... + if (eaTimeTracker.IsNewDay()) { + eaAlert.Alert("New Day ..."); + } + + // + // Hour ... + if (eaTimeTracker.IsNewHour()) { + eaAlert.Alert("New Hour ..."); + } + + // + // Minute ... + if (eaTimeTracker.IsNewMinute()) { + eaAlert.Alert("New Minute ..."); } } @@ -630,5 +693,5 @@ void OldTests() // eaBarTracker.Waits(); // } } - + // \ No newline at end of file diff --git a/Libraries/x-saherelm.common.lib.mq5 b/Libraries/x-saherelm.common.lib.mq5 index 96437b00..1082e837 100644 --- a/Libraries/x-saherelm.common.lib.mq5 +++ b/Libraries/x-saherelm.common.lib.mq5 @@ -1862,6 +1862,7 @@ struct XTimeTracker int xForWeekDay; int xDay; int xHour; + int xMinute; // // Constructor ... @@ -1880,10 +1881,34 @@ struct XTimeTracker xDay = -1; xHour = -1; xMonth = -1; + xMinute = -1; xDayOfWeek = -1; xForWeekDay = -1; } + // + // Detecting New Minute ... + bool IsNewMinute() + { + // + bool result = false; + + // + // Retrieve Current Time as Struct ... + MqlDateTime timeStruct = GetCurrentTime(); + + // + // Check Houre ... + result = timeStruct.min != xMinute; + if (result) + { + xMinute = timeStruct.min; + } + + // + return result; + } + // // Detecting New Houre ... bool IsNewHour()