From 63fbb72cd15a95766e6d819ddbae840488682771 Mon Sep 17 00:00:00 2001 From: Hadi Khazaee Asl Date: Sun, 20 Oct 2024 20:27:51 +0330 Subject: [PATCH] last ... --- Classes/x-saherelm.x-poi.class.mq5 | 215 +++++++++++++--------------- Libraries/x-saherelm.common.lib.mq5 | 41 ++++++ 2 files changed, 137 insertions(+), 119 deletions(-) diff --git a/Classes/x-saherelm.x-poi.class.mq5 b/Classes/x-saherelm.x-poi.class.mq5 index f426b1ff..24d0cf0a 100644 --- a/Classes/x-saherelm.x-poi.class.mq5 +++ b/Classes/x-saherelm.x-poi.class.mq5 @@ -63,7 +63,7 @@ enum ENUM_XPOI_EVENTS // // Trading Days ... X_TRADE_DAY_FIRST_BAR, // Trading Day Start ... - X_TRADE_DAY_LAST_BAR, // Trading Day End ... + X_TRADE_DAY_LAST_BAR, // Trading Day End ... // // Session ... X_SESSION_OPEN, // Session Open ... @@ -103,7 +103,6 @@ struct XSession ENUM_XSESSION session; // Session Identifier string start; // Start Time string end; // End Time - int offset; // Time Offset // color startColor; @@ -147,8 +146,7 @@ struct XSession // result = IsValid(start) && - IsValid(end) && - offset >= 0; + IsValid(end); // return result; @@ -166,8 +164,7 @@ struct XSession bool Init( ENUM_XSESSION _session, string _start, - string _end, - int _offset // + string _end // ) { // @@ -175,18 +172,16 @@ struct XSession // result = IsValid(_start) && - IsValid(_end) && - offset >= 0; + IsValid(_end); if (!result) { return result; } // - session = _session; - offset = _offset; - start = _start; end = _end; + start = _start; + session = _session; // result = IsValid(); @@ -195,103 +190,6 @@ struct XSession return result; } - /** - * Retrieve Session Start Time ... - * - * @return ( datetime ) - */ - datetime Start() - { - // - datetime result = NULL; - - // - if (!IsValid()) - { - return result; - } - - // - result = (datetime)((int)StringToTime(start) + offset); - - // - return result; - } - - /** - * Retrieve Session End Time ... - * - * @return ( datetime ) - */ - datetime End() - { - // - datetime result = NULL; - - // - if (!IsValid()) - { - return result; - } - - // - result = (datetime)((int)StringToTime(end) + offset); - - // - return result; - } - - /** - * Check Currently Session is Open or not ... - * - * @return ( bool ) - */ - bool IsOpen() - { - // - bool result = false; - - // - result = IsValid(); - if (!result) - { - return result; - } - - // - datetime sTime = Start(); - datetime eTime = End(); - result = IsValid(sTime) && - IsValid(eTime); - if (!result) - { - return result; - } - - // - datetime cTime = TimeCurrent(); - - // - MqlDateTime cTimeStruct; - result = TimeToStruct(cTime, cTimeStruct); - if (!result) - { - return result; - } - - // - ENUM_DAY_OF_WEEK dayOfWeek = (ENUM_DAY_OF_WEEK)cTimeStruct.day_of_week; - - // - result = cTime >= sTime && - cTime < eTime && - (dayOfWeek >= MONDAY && - dayOfWeek <= FRIDAY); - - // - return result; - } - // }; @@ -1836,9 +1734,6 @@ class XCPOI : public XSCBaseAlert // // Sessions ... - // - int offset = -10800; - // // SYDNEY ... // Start: (UTC) 21:00 @@ -1847,8 +1742,7 @@ class XCPOI : public XSCBaseAlert mSyndeySession.Init( X_SYDNEY, "21:00", // Start ... - "06:00", // End ... - offset // + "06:00" // End ... ); mSyndeySession.startColor = clrFireBrick; mSyndeySession.endColor = clrFireBrick; @@ -1864,8 +1758,7 @@ class XCPOI : public XSCBaseAlert mTokyoSession.Init( X_TOKYO, "12:00", // Start ... - "09:00", // End ... - offset // + "09:00" // End ... ); mTokyoSession.startColor = clrBlueViolet; mTokyoSession.endColor = clrBlueViolet; @@ -1881,8 +1774,7 @@ class XCPOI : public XSCBaseAlert mLondonSession.Init( X_LONDON, "07:00", // Start ... - "16:00", // End ... - offset // + "16:00" // End ... ); mLondonSession.startColor = clrLime; mLondonSession.endColor = clrLime; @@ -1898,8 +1790,7 @@ class XCPOI : public XSCBaseAlert mNewYorkSession.Init( X_LONDON, "13:00", // Start ... - "22:00", // End ... - offset // + "22:00" // End ... ); mNewYorkSession.startColor = clrAqua; mNewYorkSession.endColor = clrAqua; @@ -2251,6 +2142,39 @@ class XCPOI : public XSCBaseAlert // // Session ... + int sessionsCount = ArraySize(mSessions); + int marketSessionsCount = ArraySize(mMarketSessions); + if (IsValidSize(sessionsCount) && + marketSessionsCount < sessionsCount * requiredPOIs) + { + // + for (int i = 0; i < sessionsCount; i++) + { + // + XSession iSession = mSessions[i]; + + // + datetime iStart = iSession.Start(); + string iStartString = GetTimeString(iStart); + + // + datetime iEnd = iSession.End(); + string iEndString = GetTimeString(iEnd); + + // + string zTimeString = GetTimeString(zBar.time); + + // + if (zTimeString == iEndString) + { + Print("Session: " + ToString(iSession.session) + " Last Bar ..."); + } + else if (zTimeString == iStartString) + { + Print("Session: " + ToString(iSession.session) + " First Bar ..."); + } + } + } // // Swing Highs ... @@ -2345,6 +2269,9 @@ class XCPOI : public XSCBaseAlert // daysCount < requiredPOIs || // + (IsValidSize(sessionsCount) && + marketSessionsCount < (sessionsCount * requiredPOIs)) || + // swingHighsCount < requiredPOIs || swingLowsCount < requiredPOIs || // @@ -3146,6 +3073,56 @@ class XCPOI : public XSCBaseAlert } // + + /** + * Find Market Session by Providing Start Time ... + * + * @param start: DateTime ... + * + * @return ( int ) + */ + int HasMarketSessionByStartTime(datetime start) + { + // + int result = -1; + + // + if (!IsValid(start)) + { + return result; + } + + // + int count = ArraySize(mMarketSessions); + if (!IsValidSize(count)) + { + return result; + } + + // + for (int i = 0; i < count; i++) + { + // + XMarketSession iMarketSession = mMarketSessions[i]; + datetime iStart = iMarketSession.Start(); + } + + // + return result; + } + + /** + * Find Market Session by Providing Start Time ... + * + * @param end: DateTime ... + * + * @return ( int ) + */ + int HasMarketSessionByEndTime(datetime end) + { + } + + // private: // diff --git a/Libraries/x-saherelm.common.lib.mq5 b/Libraries/x-saherelm.common.lib.mq5 index b475e668..e9eb3a41 100644 --- a/Libraries/x-saherelm.common.lib.mq5 +++ b/Libraries/x-saherelm.common.lib.mq5 @@ -7976,6 +7976,47 @@ ulong GetCurrentTimeAsMilliSeconds() return result; } +// +// Retrieve only Hour and Minute as String ... +string GetTimeString( + datetime time = NULL +) +{ + // + NormalizeTime(time); + + // + string result = NULL; + + // + MqlDateTime tStruct; + bool isStructed = TimeToStruct(time, tStruct); + if (!isStructed) + { + return result; + } + + // + string hour = ToString(tStruct.hour); + hour = + StringLen(hour) == 1 + ? "0" + hour + : hour; + + // + string minute = ToString(tStruct.min); + minute = + StringLen(minute) == 1 + ? "0" + minute + : minute; + + // + result = hour + ":" + minute; + + // + return result; +} + // // Converts a Date time to File Format ... string ToFormatString(