From d239d9c580d1a21e838f7a0d74b18f05f1dcfe59 Mon Sep 17 00:00:00 2001 From: Hadi Khazaee Asl Date: Mon, 11 Nov 2024 14:06:29 -0800 Subject: [PATCH] cleanup and backup old styles and try toimplement new POI Detector ... --- Classes/x-saherelm.base.class.mq5 | 10 +- ...ass.mq5 => x-saherelm.x-account.class.mq5} | 14 +- ...class.mq5 => x-saherelm.x-alert.class.mq5} | 30 +- Classes/x-saherelm.x-app-dialog.class.mq5 | 7 +- Classes/x-saherelm.x-cobject.class.mq5 | 489 + ...lass.mq5 => x-saherelm.x-expert.class.mq5} | 18 +- ...lass.mq5 => x-saherelm.x-helper.class.mq5} | 12 +- ....class.mq5 => x-saherelm.x-http.class.mq5} | 16 +- ...5.class.mq5 => x-saherelm.x-md5.class.mq5} | 16 +- Classes/x-saherelm.x-poi.class.mq5 | 7890 ++--------------- Classes/x-saherelm.x-poi.drawer.class.mq5 | 885 +- ...class.mq5 => x-saherelm.x-trade.class.mq5} | 2786 +----- Documents/BKP/tmp | 60 + .../BKP}/x-saherelm.x-chart-objects.class.mq5 | 0 Documents/BKP/x-saherelm.x-poi.class.mq5 | 7778 ++++++++++++++++ .../BKP/x-saherelm.x-poi.drawer.class.mq5 | 2452 +++++ Experts/x-saherelm.x-121.smc.ea.mq5 | 26 +- Helpers/x-saherelm.xcc.helper.mq5 | 8 +- Helpers/x-saherelm.xct.helper.mq5 | 8 +- Libraries/x-saherelm.common.lib.mq5 | 4 +- Libraries/x-saherelm.draw.lib.mq5 | 2620 ++++++ Libraries/x-saherelm.x-poi.lib.mq5 | 190 +- ...ade.lib.mq5 => x-saherelm.x-trade.lib.mq5} | 376 - .../Classes/x-121.smc.xtradehandler.class.mq5 | 15 +- X121SMCEA/Experts/x-121.poi.expert.class.mq5 | 830 ++ X121SMCEA/Helpers/x-saherelm.x3ma.helper.mq5 | 752 -- .../Helpers/x-saherelm.x3vwap.helper.mq5 | 1144 --- X121SMCEA/Helpers/x-saherelm.xcc.helper.mq5 | 245 - X121SMCEA/Helpers/x-saherelm.xct.helper.mq5 | 220 - X121SMCEA/Indicators/x-saherelm.x3ma.mq5 | 394 - X121SMCEA/Indicators/x-saherelm.x3vwap.mq5 | 564 -- X121SMCEA/Indicators/x-saherelm.xcc.mq5 | 437 - X121SMCEA/Indicators/x-saherelm.xct.mq5 | 270 - X121SMCEA/Libraries/x-121.smc.lib.mq5 | 856 -- .../x-121.smc.test.strategy.class.mq5 | Bin 153514 -> 0 bytes 35 files changed, 15195 insertions(+), 16227 deletions(-) rename Classes/{x-saherelm.xaccount.class.mq5 => x-saherelm.x-account.class.mq5} (98%) rename Classes/{x-saherelm.xalert.class.mq5 => x-saherelm.x-alert.class.mq5} (99%) create mode 100644 Classes/x-saherelm.x-cobject.class.mq5 rename Classes/{x-saherelm.xexpert.class.mq5 => x-saherelm.x-expert.class.mq5} (97%) rename Classes/{x-saherelm.xhelper.class.mq5 => x-saherelm.x-helper.class.mq5} (95%) rename Classes/{x-saherelm.xhttp.class.mq5 => x-saherelm.x-http.class.mq5} (97%) rename Classes/{x-saherelm.xmd5.class.mq5 => x-saherelm.x-md5.class.mq5} (99%) rename Classes/{x-saherelm.xtrade.class.mq5 => x-saherelm.x-trade.class.mq5} (56%) create mode 100644 Documents/BKP/tmp rename {Classes => Documents/BKP}/x-saherelm.x-chart-objects.class.mq5 (100%) create mode 100644 Documents/BKP/x-saherelm.x-poi.class.mq5 create mode 100644 Documents/BKP/x-saherelm.x-poi.drawer.class.mq5 create mode 100644 Libraries/x-saherelm.draw.lib.mq5 rename Libraries/{x-saherelm.xtrade.lib.mq5 => x-saherelm.x-trade.lib.mq5} (93%) create mode 100644 X121SMCEA/Experts/x-121.poi.expert.class.mq5 delete mode 100644 X121SMCEA/Helpers/x-saherelm.x3ma.helper.mq5 delete mode 100644 X121SMCEA/Helpers/x-saherelm.x3vwap.helper.mq5 delete mode 100644 X121SMCEA/Helpers/x-saherelm.xcc.helper.mq5 delete mode 100644 X121SMCEA/Helpers/x-saherelm.xct.helper.mq5 delete mode 100644 X121SMCEA/Indicators/x-saherelm.x3ma.mq5 delete mode 100644 X121SMCEA/Indicators/x-saherelm.x3vwap.mq5 delete mode 100644 X121SMCEA/Indicators/x-saherelm.xcc.mq5 delete mode 100644 X121SMCEA/Indicators/x-saherelm.xct.mq5 delete mode 100644 X121SMCEA/Libraries/x-121.smc.lib.mq5 delete mode 100644 X121SMCEA/Strategy/x-121.smc.test.strategy.class.mq5 diff --git a/Classes/x-saherelm.base.class.mq5 b/Classes/x-saherelm.base.class.mq5 index a9771d1b..b367dbec 100644 --- a/Classes/x-saherelm.base.class.mq5 +++ b/Classes/x-saherelm.base.class.mq5 @@ -24,11 +24,11 @@ // // XBase Class ... -class XSCBase +class XCBase { // // Public ... -public: + public: // // Protected ... @@ -42,10 +42,10 @@ public: // // Protected -protected: + protected: // // Private ... -private: + private: }; // @@ -84,7 +84,7 @@ string GenerateSpecifiedCommonSummary( "---------------" + separator + "Bullish: " + ToString(bullishScore) + separator + "Bearish: " + ToString(bearishScore) + separator + - "---------------" + separator + "---------------" + separator : "") + "" // diff --git a/Classes/x-saherelm.xaccount.class.mq5 b/Classes/x-saherelm.x-account.class.mq5 similarity index 98% rename from Classes/x-saherelm.xaccount.class.mq5 rename to Classes/x-saherelm.x-account.class.mq5 index 66169f54..c451091d 100644 --- a/Classes/x-saherelm.xaccount.class.mq5 +++ b/Classes/x-saherelm.x-account.class.mq5 @@ -33,8 +33,8 @@ // // Includes ... -#include #include "../Classes/x-saherelm.base.class.mq5" +#include // // END Import and Inclused requirements ... @@ -50,14 +50,14 @@ // // a Class for Manage Account ... -class XSCAccount : public XSCBase +class XCAccount : public XCBase { // // Public ... -public: + public: // // Constructor ... - void XSCAccount() + void XCAccount() { // mAccountInfo = new CAccountInfo(); @@ -65,7 +65,7 @@ public: // // Deconstructor ... - void ~XSCAccount() + void ~XCAccount() { } @@ -380,10 +380,10 @@ public: // // Protected ... -protected: + protected: // // Private ... -private: + private: // // Account Info ... CAccountInfo mAccountInfo; diff --git a/Classes/x-saherelm.xalert.class.mq5 b/Classes/x-saherelm.x-alert.class.mq5 similarity index 99% rename from Classes/x-saherelm.xalert.class.mq5 rename to Classes/x-saherelm.x-alert.class.mq5 index 7f15e326..2c7ef5e0 100644 --- a/Classes/x-saherelm.xalert.class.mq5 +++ b/Classes/x-saherelm.x-alert.class.mq5 @@ -26,17 +26,17 @@ // // Class Definition ... -class XSCAlert : public XSCBase +class XCAlert : public XCBase { // // Public ... -public: + public: // // Props ... // // Constructor ... - XSCAlert( + XCAlert( string prefix = "X-Alert", // Alerts Prefixe bool enableAlerts = true, // Enable Alerts bool logAlerts = true, // Log Alerts @@ -63,7 +63,9 @@ public: // // Deconstructor ... - ~XSCAlert() {} + ~XCAlert() + { + } // // Override ... @@ -1282,7 +1284,7 @@ public: // // Protected ... -protected: + protected: // // Private ... @@ -1332,7 +1334,7 @@ protected: return result; } -private: + private: // // Props ... string mPrefix; // Alerts Prefixe @@ -1363,26 +1365,26 @@ private: // // a Base Class by Support Alert ... -class XSCBaseAlert : public XSCBase +class XCBaseAlert : public XCBase { // // Public ... -public: + public: // // Props ... // // Constructor(s) ... - void XSCBaseAlert() + void XCBaseAlert() { // // Instance Alert ... - mAlert = new XSCAlert(); + mAlert = new XCAlert(); } // // Deconstructors ... - void ~XSCBaseAlert() + void ~XCBaseAlert() { // delete mAlert; @@ -1562,14 +1564,14 @@ public: // // Protected ... -protected: + protected: // // Alert ... - XSCAlert *mAlert; + XCAlert *mAlert; // // Private ... -private: + private: }; // \ No newline at end of file diff --git a/Classes/x-saherelm.x-app-dialog.class.mq5 b/Classes/x-saherelm.x-app-dialog.class.mq5 index 0cf36c86..6bfa4d9c 100644 --- a/Classes/x-saherelm.x-app-dialog.class.mq5 +++ b/Classes/x-saherelm.x-app-dialog.class.mq5 @@ -223,9 +223,9 @@ class XCAppDialog : public CAppDialog /** * Create and Run Confirm Dialog ... - * + * * @param message: message for Message Box ... - * + * * @return ( bool ) */ bool ConfirmDialog(string message = NULL) @@ -234,7 +234,8 @@ class XCAppDialog : public CAppDialog bool result = false; // - if (!IsValid(message)) { + if (!IsValid(message)) + { message = "Confirm ?"; } diff --git a/Classes/x-saherelm.x-cobject.class.mq5 b/Classes/x-saherelm.x-cobject.class.mq5 new file mode 100644 index 00000000..93123e82 --- /dev/null +++ b/Classes/x-saherelm.x-cobject.class.mq5 @@ -0,0 +1,489 @@ +/////////////////////////////////////////////////////// +// +// SaherElm IT Center MQL5 Class Library +// -------------------------------------- +// Name: XChartObjects +// Description: provides all require Chart Objects ... +// +// +// Maintainer: +// ------------ +// Hadi Khazaee Asl (hadi_khazaee_asl@yahoo.com) +// +////////////////////////////////////////////////////// +// +// Global Properties ... +#property library +#property copyright "Copyright 2023, SaherElm IT Center" +#property link "https://www.saherelm.ir" +#property version "1.00" +#property strict + +// +#include "../Libraries/x-saherelm.x-poi.lib.mq5" +#include "../Libraries/x-saherelm.x-trade.lib.mq5" + +// +#include +#include +#include +#include + +// +// Definitions ... + +enum ENUM_XCHARTOBJECTS +{ + // + // Global ... + X_ZONE_OBJ = 7860, + X_FROM_TO_OBJ = 7861, + X_BAR_ARROW_OBJ = 7862, + // + X_SIGNAL_OBJ = 8860, + X_TREND_OBJ = 8861, + // + // Structured ... + X_TRADE_DAY_OBJ = 9860, + X_MARKET_SESSION_OBJ = 9861, + X_SWING_HIGH_OBJ = 9862, + X_SWING_LOW_OBJ = 9863, + X_BULLISH_MOMENTUM_BAR_OBJ = 9864, + X_BEARISH_MOMENTUM_BAR_OBJ = 9865, + X_BULLISH_REJECTION_BAR_OBJ = 9866, + X_BEARISH_REJECTION_BAR_OBJ = 9867, + X_SUPPORT_ZONE_OBJ = 9868, + X_RESISTANCE_ZONE_OBJ = 9869, + X_SUPPLY_ZONE_OBJ = 9870, + X_DEMAND_ZONE_OBJ = 9871, + X_BULLISH_ORDERBLOCK_OBJ = 9872, + X_BEARISH_ORDERBLOCK_OBJ = 9873, + X_BULLISH_FVG_OBJ = 9874, + X_BEARISH_FVG_OBJ = 9875, +}; + +enum ENUM_X_CHART_IDS +{ + X_TO, + X_FROM, + X_UPPER, + X_LOWER, + X_ENTRY, + X_SL, + X_TP +}; + +// +// Implementation ... + +// +// Global Chart Objects ... + +// +// Bas Chart Object ... +class XCBaseObject : public CChartObject +{ + // + public: + // + + // + // Getter(s) / Setter(s) ... + + /** + * Get Object Specified Name ... + * + * @return ( string ) + */ + string ObjName() + { + return mObjName; + } + + /** + * Set Object Specified Name ... + * + * @param value: String ... + */ + void ObjName(string value) + { + mObjName = value; + } + + // + private: + // + + // + // Props ... + string mObjName; // Object Specified Name ... + + // +}; + +// +// Swing ... +class XCSwingObject : public XCBaseObject +{ + // + public: + // + + /** + * Creator ... + * + * @param chart_id: Long, Specified Chart ID ... + * @param window: Integer, Specified Chart Window ID ... + * @param swing: XCSwing instance ... + * + * @return ( bool ) + */ + bool CreateBySwing( + long chart_id, + int window, + int arrow, + XCSwing &swing // + ) + { + // + bool result = false; + + // + result = + // + swing.IsValid() + // + ; + if (!result) + { + return result; + } + + // + string name = swing.GetTag(); + + // + XOHCL bar; + result = swing.FillBar(bar); + if (!result) + { + return result; + } + + // + datetime time = bar.time; + double price = swing.IsSwingHigh() + ? bar.high + : bar.low; + + // + result = mArrow.Create( + chart_id, + name, + window, + time, + price, + (char)arrow // + ); + + // + if (result) + { + ObjName(name); + } + + // + return result; + } + + // + // Virtual ... + + // + // Setter(s) ... + + /** + * Set Arrow Anchor ... + * + * @param value: ENUM_ARROW_ANCHOR member ... + */ + void ArrowAnchor(ENUM_ARROW_ANCHOR value) + { + mArrow.Anchor(value); + } + + /** + * Set Arrow Color ... + * + * @param value: Color ... + */ + void ArrowColor(color value) + { + mArrow.Color(value); + } + + /** + * Set Arrow Width ... + * + * @param value: Integer ... + */ + void ArrowWidth(int value) + { + mArrow.Width(value); + } + + // + private: + // + CChartObjectArrow mArrow; + + // +}; + +// +// Swing High ... +class XCSwingHighObject : public XCSwingObject +{ + // + public: + // + + /** + * Creator ... + * + * @param chart_id: Long, Specified Chart ID ... + * @param window: Integer, Specified Chart Window ID ... + * @param swing: XCSwing instance ... + * + * @return ( bool ) + */ + bool Create( + long chart_id, + int window, + int arrow, + XCSwing &swing // + ) + { + // + bool result = false; + + // + result = swing.IsValid() && + swing.IsSwingHigh(); + if (!result) + { + return result; + } + + // + result = CreateBySwing( + chart_id, + window, + arrow, + swing // + ); + + // + return result; + } + + /** + * Retrieve Object Type ... + * + * @return ( ENUM_XCHARTOBJECTS ) + */ + virtual ENUM_XCHARTOBJECTS Type() + { + return X_SWING_HIGH_OBJ; + } + + // +}; + +// +// Swing Low ... +class XCSwingLowObject : public XCSwingObject +{ + // + public: + // + + /** + * Creator ... + * + * @param chart_id: Long, Specified Chart ID ... + * @param window: Integer, Specified Chart Window ID ... + * @param swing: XCSwing instance ... + * + * @return ( bool ) + */ + bool Create( + long chart_id, + int window, + int arrow, + XCSwing &swing // + ) + { + // + bool result = false; + + // + result = swing.IsValid() && + swing.IsSwingLow(); + if (!result) + { + return result; + } + + // + result = CreateBySwing( + chart_id, + window, + arrow, + swing // + ); + + // + return result; + } + + /** + * Retrieve Object Type ... + * + * @return ( ENUM_XCHARTOBJECTS ) + */ + virtual ENUM_XCHARTOBJECTS Type() + { + return X_SWING_LOW_OBJ; + } + + // +}; + +// +// XCZoneObject ... +class XCZoneObject : public XCBaseObject +{ + // + public: + // + + /** + * Creator ... + * + * @param chart_id: Long, Specified Chart ID ... + * @param name: String, Specified Object Identifier on Chart ... + * @param window: Integer, Specified Chart Window ID ... + * @param zone: XCZone instance ... + * + * @return ( bool ) + */ + bool CreateByZone( + long chart_id, + string name, + int window, + XCZone &zone // + ) + { + // + bool result = false; + + // + result = + // + IsValid(name) && + zone.IsValidFrom() && + zone.IsValidBoundary() + // + ; + if (!result) + { + return result; + } + + // + datetime to = NormalizeTime(zone.To()); + + // + result = mRect.Create( + chart_id, + name, + window, + zone.From(), + zone.Upper(), + to, + zone.Lower() // + ); + + // + if (result) + { + ObjName(name); + } + + // + return result; + } + + // + // Virtual ... + + /** + * Retrieve Object Type ... + * + * @return ( ENUM_XCHARTOBJECTS ) + */ + virtual ENUM_XCHARTOBJECTS Type() + { + return X_ZONE_OBJ; + } + + // + // Setter(s) ... + + /** + * Set Zone Width ... + * + * @param value: Integer ... + */ + void ZoneWidth(int value) + { + // + if (value < 1) + { + value = 1; + } + + // + mRect.Width(value); + } + + /** + * Set Zone Color ... + * + * @param value: Color ... + */ + void ZoneColor(color value) + { + mRect.Color(value); + } + + /** + * Set Zone Style ... + * + * @param value: ENUM_LINE_STYLE member ... + */ + void ZoneStyle(ENUM_LINE_STYLE value) + { + mRect.Style(value); + } + + // + private: + // + CChartObjectRectangle mRect; + + // +}; + +// \ No newline at end of file diff --git a/Classes/x-saherelm.xexpert.class.mq5 b/Classes/x-saherelm.x-expert.class.mq5 similarity index 97% rename from Classes/x-saherelm.xexpert.class.mq5 rename to Classes/x-saherelm.x-expert.class.mq5 index 652e9e62..db538a7d 100644 --- a/Classes/x-saherelm.xexpert.class.mq5 +++ b/Classes/x-saherelm.x-expert.class.mq5 @@ -21,8 +21,8 @@ // // Imports ... -#include "../Classes/x-saherelm.xalert.class.mq5" -#include "../Classes/x-saherelm.xtrade.class.mq5" +#include "../Classes/x-saherelm.x-alert.class.mq5" +#include "../Classes/x-saherelm.x-trade.class.mq5" #include "../Helpers/x-saherelm.xcc.helper.mq5" #include "../Helpers/x-saherelm.xct.helper.mq5" @@ -35,14 +35,14 @@ string XCBaseExpertToken = "XCBaseEA"; // // Implementations ... -class XCBaseExpert : public XSCBaseAlert +class XCBaseExpert : public XCBaseAlert { // public: // // - XSCTrade *mTrader; // Trader of Expert Adviser ... + XCTrade *mTrader; // Trader of Expert Adviser ... // // Constructur(s) ... @@ -577,7 +577,7 @@ class XCBaseExpert : public XSCBaseAlert // Bar Timer ... XCTInputs ctInputs; ctInputs.Default(); // Default Configurations ... - mCTHelper = new XSCXCTHelper(); + mCTHelper = new XCXCTHelper(); result = mCTHelper.Init( _Symbol, _Period, @@ -592,7 +592,7 @@ class XCBaseExpert : public XSCBaseAlert // Bar Styles ... XCCInputs ccInputs; ccInputs.Default(); // Default Configurations ... - mCCHelper = new XSCXCCHelper(); + mCCHelper = new XCXCCHelper(); result = mCCHelper.Init( _Symbol, _Period, @@ -605,7 +605,7 @@ class XCBaseExpert : public XSCBaseAlert // // Create Trader Instance and Configure it ... - mTrader = new XSCTrade( + mTrader = new XCTrade( mSlippage, mMagicNumber // ); @@ -788,8 +788,8 @@ class XCBaseExpert : public XSCBaseAlert // XTimeTracker mTimeTracker; // Time Tracker for Providing Reports ... - XSCXCTHelper *mCTHelper; // Bar Timer Indicator Helper class ... - XSCXCCHelper *mCCHelper; // Chart Styler Indicator Helper Class ... + XCXCTHelper *mCTHelper; // Bar Timer Indicator Helper class ... + XCXCCHelper *mCCHelper; // Chart Styler Indicator Helper Class ... // // Actions ... diff --git a/Classes/x-saherelm.xhelper.class.mq5 b/Classes/x-saherelm.x-helper.class.mq5 similarity index 95% rename from Classes/x-saherelm.xhelper.class.mq5 rename to Classes/x-saherelm.x-helper.class.mq5 index 966eb8d9..8aa63e8c 100644 --- a/Classes/x-saherelm.xhelper.class.mq5 +++ b/Classes/x-saherelm.x-helper.class.mq5 @@ -30,14 +30,14 @@ // // a Class for Handle base requirements ... // for indicators ... -class XSCBaseHelper : public XSCBase +class XCBaseHelper : public XCBase { // // Public ... -public: + public: // // Constructor ... - void XSCBaseHelper( + void XCBaseHelper( string symbol, // Trading Symbol ENUM_TIMEFRAMES period // Trading Time Frame ) @@ -49,7 +49,7 @@ public: // // Deconstructor ... - void ~XSCBaseHelper() + void ~XCBaseHelper() { // IndicatorRelease(mHandler); @@ -122,7 +122,7 @@ public: // // Protected ... -protected: + protected: // // Props ... @@ -140,7 +140,7 @@ protected: // // Private ... -private: + private: // }; diff --git a/Classes/x-saherelm.xhttp.class.mq5 b/Classes/x-saherelm.x-http.class.mq5 similarity index 97% rename from Classes/x-saherelm.xhttp.class.mq5 rename to Classes/x-saherelm.x-http.class.mq5 index 82adadb6..631532f2 100644 --- a/Classes/x-saherelm.xhttp.class.mq5 +++ b/Classes/x-saherelm.x-http.class.mq5 @@ -39,18 +39,18 @@ enum X_HTTP_METHOD // // a Class for Manage Account ... -class XSCHttp : public XSCBase +class XCHttp : public XCBase { // // Public ... -public: + public: // // Constructor ... - void XSCHttp() + void XCHttp() { - XSCHttp("", 10000); + XCHttp("", 10000); } - void XSCHttp( + void XCHttp( string path, // Base Folder to Store Data int timeout // base timeout for Requests ) @@ -62,7 +62,7 @@ public: // // Deconstructor ... - void ~XSCHttp() + void ~XCHttp() { } @@ -292,7 +292,7 @@ public: // // Protected ... -protected: + protected: // // Destintion Folder Path ... string mPath; @@ -311,7 +311,7 @@ protected: // // Private ... -private: + private: // // Reset Errors State ... void ResetState() diff --git a/Classes/x-saherelm.xmd5.class.mq5 b/Classes/x-saherelm.x-md5.class.mq5 similarity index 99% rename from Classes/x-saherelm.xmd5.class.mq5 rename to Classes/x-saherelm.x-md5.class.mq5 index 3311aa5a..e5cc2016 100644 --- a/Classes/x-saherelm.xmd5.class.mq5 +++ b/Classes/x-saherelm.x-md5.class.mq5 @@ -110,21 +110,25 @@ static uchar _md5_PADDING[64] = // // XCMD5 a library for Hashing ... -class XSCMD5 +class XCMD5 { // // Public Provides ... -public: + public: // // Protected Provides ... // // Constructor ... - XSCMD5(void) {} + XCMD5(void) + { + } // // Deconstructor ... - ~XSCMD5(void) {} + ~XCMD5(void) + { + } // // Hash Specified Char Array ... @@ -198,10 +202,10 @@ public: return result; } -protected: + protected: // // Private Provides ... -private: + private: // uint m_lMD5[4]; uint m_nCount[2]; diff --git a/Classes/x-saherelm.x-poi.class.mq5 b/Classes/x-saherelm.x-poi.class.mq5 index 13928bb8..0442e2c2 100644 --- a/Classes/x-saherelm.x-poi.class.mq5 +++ b/Classes/x-saherelm.x-poi.class.mq5 @@ -24,8 +24,9 @@ // Imports ... // +#include "../Classes/x-saherelm.x-alert.class.mq5" #include "../Classes/x-saherelm.x-poi.drawer.class.mq5" -#include "../Classes/x-saherelm.xalert.class.mq5" +#include "../Libraries/x-saherelm.x-poi.lib.mq5" // #include @@ -34,11 +35,13 @@ // Implementation ... // -class XCPOI : public XSCBaseAlert +// POI Detector Class ... +class XCPOIDetector : public XCBaseAlert { // public: // + XCPOIDrawer mDrawer; // // Constructors ... @@ -48,7 +51,7 @@ class XCPOI : public XSCBaseAlert * @param symbol: String ... * @param period: ENUM_TIMEFRAMES member ... */ - void XCPOI( + void XCPOIDetector( string symbol, ENUM_TIMEFRAMES period // ) @@ -65,9 +68,6 @@ class XCPOI : public XSCBaseAlert mPeriod // ); - // - mDrawer = new XCPOIDrawer(); - // // Apply Default Configurations ... ApplyDefaultConfig(); @@ -75,81 +75,32 @@ class XCPOI : public XSCBaseAlert // // Deconstructor ... - void ~XCPOI() + void ~XCPOIDetector() { - // - DestroyPOIs(); - DestroyObjects(); - DestroySessions(); - DestroyEventListeners(); - - // - delete mDrawer; + Destroy(); } // // Getter(s) / Setter(s) ... /** - * Get Chart ID ... + * Retrieve Detector Symbol ... * - * @return ( long ) + * @return ( string ) */ - long ChartIdentification() + string GetSymbol() { - return mChartIdentification; + return mSymbol; } /** - * Set Chart ID ... + * Retrieve Detector Period ... * - * @param value: Long + * @return ( ENUM_TIMEFRAMES ) */ - void ChartIdentification(long value) + ENUM_TIMEFRAMES GetPeriod() { - // - if (value < 0) - { - value = 0; - } - - // - mChartIdentification = value; - if (mDrawer != NULL) - { - mDrawer.ChartIdentification(value); - } - } - - /** - * Get Sub SubWindowIdentification Number ... - * - * @return ( int ) - */ - int SubWindowIdentification() - { - return mSubWindowIdentification; - } - - /** - * Get Sub SubWindowIdentification Number ... - * - * @param value: Integer ... - */ - void SubWindowIdentification(int value) - { - // - if (value < 0) - { - value = 0; - } - - // - mSubWindowIdentification = value; - if (mDrawer != NULL) - { - mDrawer.SubWindowIdentification(value); - } + return mPeriod; } /** @@ -222,257 +173,24 @@ class XCPOI : public XSCBaseAlert // POI(s) Configs ... // - // Trading Days ... + // Swings ... /** - * Get Detect Trading Days State ... - * - * @return ( bool ) - */ - bool AllowTradingDays() - { - return mAllowTradingDays; - } - - /** - * Set Detect Trading Days State ... - * - * @param value: Boolean ... - */ - void AllowTradingDays(bool value) - { - mAllowTradingDays = value; - } - - /** - * Get Draw Trading Days State ... - * - * @return ( bool ) - */ - bool AllowDrawTradingDays() - { - return mAllowDrawTradingDays; - } - - /** - * Set Draw Trading Days State ... - * - * @param value: Boolean ... - */ - void AllowDrawTradingDays(bool value) - { - mAllowDrawTradingDays = value; - } - - /** - * Get Trading Days Start Color ... - * - * @return ( color ) - */ - color TradingDaysStartColor() - { - return mTradingDaysStartColor; - } - - /** - * Set Trading Days Start Color ... - * - * @param value: Argument 1 - */ - void TradingDaysStartColor(color value) - { - mTradingDaysStartColor = value; - } - - /** - * Get Trading Days Start Style ... - * - * @return ( ENUM_LINE_STYLE ) - */ - ENUM_LINE_STYLE TradingDaysStartStyle() - { - return mTradingDaysStartStyle; - } - - /** - * Set Trading Days Start Style ... - * - * @param value: ENUM_LINE_STYLE member ... - */ - void TradingDaysStartStyle(ENUM_LINE_STYLE value) - { - mTradingDaysStartStyle = value; - } - - /** - * Get Trading Days End Color ... - * - * @return ( color ) - */ - color TradingDaysEndColor() - { - return mTradingDaysEndColor; - } - - /** - * Set Trading Days End Color ... - * - * @param value: Argument 1 - */ - void TradingDaysEndColor(color value) - { - mTradingDaysEndColor = value; - } - - /** - * Get Trading Days End Style ... - * - * @return ( ENUM_LINE_STYLE ) - */ - ENUM_LINE_STYLE TradingDaysEndStyle() - { - return mTradingDaysEndStyle; - } - - /** - * Set Trading Days End Style ... - * - * @param value: ENUM_LINE_STYLE member ... - */ - void TradingDaysEndStyle(ENUM_LINE_STYLE value) - { - mTradingDaysEndStyle = value; - } - - // - // Sessions ... - - /** - * Get Detect Market Sessions State ... - * - * @return ( bool ) - */ - bool AllowMarketSessions() - { - return mAllowMarketSessions; - } - - /** - * Set Detect Market Sessions State ... - * - * @param value: Boolean ... - */ - void AllowMarketSessions(bool value) - { - mAllowMarketSessions = value; - } - - /** - * Get Draw Market Sessions State ... - * - * @return ( bool ) - */ - bool AllowDrawMarketSessions() - { - return mAllowDrawMarketSessions; - } - - /** - * Set Draw Market Sessions State ... - * - * @param value: Boolean ... - */ - void AllowDrawMarketSessions(bool value) - { - mAllowDrawMarketSessions = value; - } - - /** - * Get Session Working Hors ... + * Get Swing Verification Range Length ... * * @return ( int ) */ - int SessionOpenHours() + int SwingRange() { - return mSessionOpenHours; + return mSwingRange; } /** - * Set Session Working Hors ... + * Set Swing Verification Range Length ... * * @param value: Integer ... */ - void SessionOpenHours(int value) - { - // - if (value <= 0) - { - value = 9; - } - - // - mSessionOpenHours = value; - } - - // - // Swing High ... - - /** - * Get Detect Swing Highs State ... - * - * @return ( bool ) - */ - bool AllowSwingHighs() - { - return mAllowSwingHighs; - } - - /** - * Set Detect Swing Highs State ... - * - * @param value: Boolean - */ - void AllowSwingHighs(bool value) - { - mAllowSwingHighs = value; - } - - /** - * Get Draw Swing Highs State ... - * - * @return ( bool ) - */ - bool AllowDrawSwingHighs() - { - return mAllowDrawSwingHighs; - } - - /** - * Set Draw Swing Highs State ... - * - * @param value: Boolean - */ - void AllowDrawSwingHighs(bool value) - { - mAllowDrawSwingHighs = value; - } - - /** - * Get Threshold Required for Swing High Detection ... - * - * @return ( double ) - */ - double SwingHighThreshold() - { - return mSwingHighThreshold; - } - - /** - * Set Threshold Required for Swing High Detection ... - * - * @param value: Double ... - */ - void SwingHighThreshold(double value) + void SwingRange(int value) { // if (value < 0) @@ -481,922 +199,7 @@ class XCPOI : public XSCBaseAlert } // - mSwingHighThreshold = value; - } - - // - // Swing Low ... - - /** - * Get Detect Swing Lows State ... - * - * @return ( bool ) - */ - bool AllowSwingLows() - { - return mAllowSwingLows; - } - - /** - * Set Detect Swing Lows State ... - * - * @param value: Boolean ... - */ - void AllowSwingLows(bool value) - { - mAllowSwingLows = value; - } - - /** - * Get Draw Swing Lows State ... - * - * @return ( bool ) - */ - bool AllowDrawSwingLows() - { - return mAllowDrawSwingLows; - } - - /** - * Set Draw Swing Lows State ... - * - * @param value: Boolean - */ - void AllowDrawSwingLows(bool value) - { - mAllowDrawSwingLows = value; - } - - /** - * Get Threshold Required for Swing Low Detection ... - * - * @return ( double ) - */ - double SwingLowThreshold() - { - return mSwingLowThreshold; - } - - /** - * Set Threshold Required for Swing Low Detection ... - * - * @param value: Double ... - */ - void SwingLowThreshold(double value) - { - // - if (value < 0) - { - value = 0; - } - - // - mSwingLowThreshold = value; - } - - // - // Momentum Bars ... - - /** - * Get Detect Momentum Bars State ... - * - * @return ( bool ) - */ - bool AllowMomentumBars() - { - return mAllowMomentumBars; - } - - /** - * Set Detect Momentum Bars State ... - * - * @param value: Boolean ... - */ - void AllowMomentumBars(bool value) - { - mAllowMomentumBars = value; - } - - /** - * Get Draw Momentum Bars State ... - * - * @return ( bool ) - */ - bool AllowDrawMomentumBars() - { - return mAllowDrawMomentumBars; - } - - /** - * Set Draw Momentum Bars State ... - * - * @param value: Boolean - */ - void AllowDrawMomentumBars(bool value) - { - mAllowDrawMomentumBars = value; - } - - /** - * Get Momentum Bar Percent ... - * - * @return ( int ) - */ - int MomentumBarPercent() - { - return mMomentumBarPercent; - } - - /** - * Set Momentum Bar Percent ... - * - * @param value: Integer - */ - void MomentumBarPercent(int value) - { - // - if (value < 0) - { - value = 0; - } - - // - mMomentumBarPercent = value; - } - - /** - * Get Momentum Bar Sharp Ratio ... - * - * @return ( double ) - */ - double MomentumBarSharpRatio() - { - return mMomentumBarSharpRatio; - } - - /** - * Set Momentum Bar Sharp Ratio ... - * - * @param value: Double ... - */ - void MomentumBarSharpRatio(double value) - { - // - if (value < 0) - { - value = 0; - } - - // - mMomentumBarSharpRatio = value; - } - - /** - * Get Momentum Bar Loopback ... - * - * @return ( int ) - */ - int MomentumBarLoopBack() - { - return mMomentumBarLoopBack; - } - - /** - * Set Momentum Bar Loopback ... - * - * @param value: Integer ... - */ - void MomentumBarLoopBack(int value) - { - // - if (value < 0) - { - value = 0; - } - - // - mMomentumBarLoopBack = value; - } - - // - // Rejection Bars ... - - /** - * Get Detect Rejection Bars State ... - * - * @return ( bool ) - */ - bool AllowRejectionBars() - { - return mAllowRejectionBars; - } - - /** - * Set Detect Rejection Bars State ... - * - * @param value: Boolean ... - */ - void AllowRejectionBars(bool value) - { - mAllowRejectionBars = value; - } - - /** - * Get Draw Rejection Bars State ... - * - * @return ( bool ) - */ - bool AllowDrawRejectionBars() - { - return mAllowDrawRejectionBars; - } - - /** - * Set Draw Rejection Bars State ... - * - * @param value: Boolean ... - */ - void AllowDrawRejectionBars(bool value) - { - mAllowDrawRejectionBars = value; - } - - /** - * Get Rejection Bar Percent ... - * - * @return ( int ) - */ - int RejectionBarPercent() - { - return mRejectionBarPercent; - } - - /** - * Set Rejection Bar Percent ... - * - * @param value: Integer - */ - void RejectionBarPercent(int value) - { - mRejectionBarPercent = value; - } - - /** - * Get Rejection Bar Sharp Ratio ... - * - * @return ( double ) - */ - double RejectionBarSharpRatio() - { - return mRejectionBarSharpRatio; - } - - /** - * Set Rejection Bar Sharp Ratio ... - * - * @param value: Double ... - */ - void RejectionBarSharpRatio(double value) - { - mRejectionBarSharpRatio = value; - } - - /** - * Get Rejection Bar Loopback ... - * - * @return ( int ) - */ - int RejectionBarLoopBack() - { - return mRejectionBarLoopBack; - } - - /** - * Set Rejection Bar Loopback ... - * - * @param value: Integer ... - */ - void RejectionBarLoopBack(int value) - { - mRejectionBarLoopBack = value; - } - - // - // Support Zone ... - - /** - * Get Detect Support Zone State ... - * - * @return ( bool ) - */ - bool AllowSupportZones() - { - return mAllowSupportZones; - } - - /** - * Set Detect Support Zone State ... - * - * @param value: Boolean ... - */ - void AllowSupportZones(bool value) - { - mAllowSupportZones = value; - } - - /** - * Get Draw Support Zone State ... - * - * @return ( bool ) - */ - bool AllowDrawSupportZones() - { - return mAllowDrawSupportZones; - } - - /** - * Set Draw Support Zone State ... - * - * @param value: Boolean ... - */ - void AllowDrawSupportZones(bool value) - { - mAllowDrawSupportZones = value; - } - - /** - * Get Support Zone Loopback ... - * - * @return ( int ) - */ - int SupportZoneLoopBack() - { - return mSupportZoneLoopBack; - } - - /** - * Set Support Zone Loopback ... - * - * @param value: Integer ... - */ - void SupportZoneLoopBack(int value) - { - // - if (value < 10) - { - value = 10; - } - - // - mSupportZoneLoopBack = value; - } - - /** - * Get Support Zone Price Type ... - * - * @return ( ENUM_LINE_STYLE ) - */ - ENUM_X_PRICE SupportZonePriceType() - { - return mSupportZonePriceType; - } - - /** - * Set Support Zone Price Type ... - * - * @param value: ENUM_X_PRICE member ... - */ - void SupportZonePriceType(ENUM_X_PRICE value) - { - mSupportZonePriceType = value; - } - - // - // Resistance Zone ... - - /** - * Get Detect Resistance Zone State ... - * - * @return ( bool ) - */ - bool AllowResistanceZones() - { - return mAllowResistanceZones; - } - - /** - * Set Detect Resistance Zone State ... - * - * @param value: Boolean ... - */ - void AllowResistanceZones(bool value) - { - mAllowResistanceZones = value; - } - - /** - * Get Draw Resistance Zone State ... - * - * @return ( bool ) - */ - bool AllowDrawResistanceZones() - { - return mAllowDrawResistanceZones; - } - - /** - * Set Draw Resistance Zone State ... - * - * @param value: Boolean ... - */ - void AllowDrawResistanceZones(bool value) - { - mAllowDrawResistanceZones = value; - } - - /** - * Get Resistance Zone Loopback ... - * - * @return ( int ) - */ - int ResistanceZoneLoopBack() - { - return mResistanceZoneLoopBack; - } - - /** - * Set Resistance Zone Loopback ... - * - * @param value: Integer ... - */ - void ResistanceZoneLoopBack(int value) - { - // - if (value < 10) - { - value = 10; - } - - // - mResistanceZoneLoopBack = value; - } - - /** - * Get Resistance Zone Price Type ... - * - * @return ( ENUM_LINE_STYLE ) - */ - ENUM_X_PRICE ResistanceZonePriceType() - { - return mResistanceZonePriceType; - } - - /** - * Set Resistance Zone Price Type ... - * - * @param value: ENUM_X_PRICE member ... - */ - void ResistanceZonePriceType(ENUM_X_PRICE value) - { - mResistanceZonePriceType = value; - } - - // - // Supply Zone ... - - /** - * Get Detect Supply Zone State ... - * - * @return ( bool ) - */ - bool AllowSupplyZones() - { - return mAllowSupplyZones; - } - - /** - * Set Detect Supply Zone State ... - * - * @param value: Boolean ... - */ - void AllowSupplyZones(bool value) - { - mAllowSupplyZones = value; - } - - /** - * Get Draw Supply Zone State ... - * - * @return ( bool ) - */ - bool AllowDrawSupplyZones() - { - return mAllowDrawSupplyZones; - } - - /** - * Set Draw Supply Zone State ... - * - * @param value: Boolean ... - */ - void AllowDrawSupplyZones(bool value) - { - mAllowDrawSupplyZones = value; - } - - /** - * Get Supply Zone Detecting Period ... - * - * @return ( ENUM_TIMEFRAMES ) ... - */ - ENUM_TIMEFRAMES SupplyZonePeriod() - { - return mSupplyZonePeriod; - } - - /** - * Set Supply Zone Detecting Period ... - * - * @param value: ENUM_TIMEFRAMES member ... - */ - void SupplyZonePeriod(ENUM_TIMEFRAMES value) - { - mSupplyZonePeriod = value; - } - - // - // Demand Zone ... - - /** - * Get Detect Demand Zone State ... - * - * @return ( bool ) - */ - bool AllowDemandZones() - { - return mAllowDemandZones; - } - - /** - * Set Detect Demand Zone State ... - * - * @param value: Boolean ... - */ - void AllowDemandZones(bool value) - { - mAllowDemandZones = value; - } - - /** - * Get Draw Demand Zone State ... - * - * @return ( bool ) - */ - bool AllowDrawDemandZones() - { - return mAllowDrawDemandZones; - } - - /** - * Set Draw Demand Zone State ... - * - * @param value: Boolean ... - */ - void AllowDrawDemandZones(bool value) - { - mAllowDrawDemandZones = value; - } - - /** - * Get Demand Zone Detecting Period ... - * - * @return ( ENUM_TIMEFRAMES ) ... - */ - ENUM_TIMEFRAMES DemandZonePeriod() - { - return mDemandZonePeriod; - } - - /** - * Set Demand Zone Detecting Period ... - * - * @param value: ENUM_TIMEFRAMES member ... - */ - void DemandZonePeriod(ENUM_TIMEFRAMES value) - { - mDemandZonePeriod = value; - } - - // - // Order Blocks ... - - // - // Bullish Order Blocks ... - - /** - * Get Detect Bullish Order Blocks State ... - * - * @return ( bool ) - */ - bool AllowBullishOrderBlocks() - { - return mAllowBullishOrderBlocks; - } - - /** - * Set Detect Bullish Order Blocks State ... - * - * @param value: Boolean ... - */ - void AllowBullishOrderBlocks(bool value) - { - mAllowBullishOrderBlocks = value; - } - - /** - * Get Draw Bullish Order Blocks State ... - * - * @return ( bool ) - */ - bool AllowDrawBullishOrderBlocks() - { - return mAllowDrawBullishOrderBlocks; - } - - /** - * Set Draw Bullish Order Blocks State ... - * - * @param value: Boolean ... - */ - void AllowDrawBullishOrderBlocks(bool value) - { - mAllowDrawBullishOrderBlocks = value; - } - - /** - * Get Minimum Required Same Bars for Bullish Order Blocks ... - * - * @return ( int ) - */ - int RequiredBarsForBullishOrderBlock() - { - return mRequiredBarsForBullishOrderBlock; - } - - /** - * Set Minimum Required Same Bars for Bullish Order Blocks ... - * - * @param value: Integer ... - */ - void RequiredBarsForBullishOrderBlock(int value) - { - // - if (value < 3) - { - value = 3; - } - - // - mRequiredBarsForBullishOrderBlock = value; - } - - // - // Bearish Order Blocks ... - - /** - * Get Detect Bearish Order Blocks State ... - * - * @return ( bool ) - */ - bool AllowBearishOrderBlocks() - { - return mAllowBearishOrderBlocks; - } - - /** - * Set Detect Bearish Order Blocks State ... - * - * @param value: Boolean ... - */ - void AllowBearishOrderBlocks(bool value) - { - mAllowBearishOrderBlocks = value; - } - - /** - * Get Draw Bearish Order Blocks State ... - * - * @return ( bool ) - */ - bool AllowDrawBearishOrderBlocks() - { - return mAllowDrawBearishOrderBlocks; - } - - /** - * Set Draw Bearish Order Blocks State ... - * - * @param value: Boolean ... - */ - void AllowDrawBearishOrderBlocks(bool value) - { - mAllowDrawBearishOrderBlocks = value; - } - - /** - * Get Minimum Required Same Bars for Bearish Order Blocks ... - * - * @return ( int ) - */ - int RequiredBarsForBearishOrderBlock() - { - return mRequiredBarsForBearishOrderBlock; - } - - /** - * Set Minimum Required Same Bars for Bearish Order Blocks ... - * - * @param value: Integer ... - */ - void RequiredBarsForBearishOrderBlock(int value) - { - // - if (value < 3) - { - value = 3; - } - - // - mRequiredBarsForBearishOrderBlock = value; - } - - // - // Fair Value Gaps ... - - // - // Bullis FVGs ... - - /** - * Get Detect Bullish Fair Value Gaps State ... - * - * @return ( bool ) - */ - bool AllowBullishFVGs() - { - return mAllowBullishFVGs; - } - - /** - * Set Detect Bullish Fair Value Gaps State ... - * - * @param value: Boolean ... - */ - void AllowBullishFVGs(bool value) - { - mAllowBullishFVGs = value; - } - - /** - * Get Draw Bullish Fair Value Gaps ... - * - * @return ( bool ) - */ - bool AllowDrawBullishFVGs() - { - return mAllowDrawBullishFVGs; - } - - /** - * Set Draw Bullish Fair Value Gaps ... - * - * @param value: Boolean ... - */ - void AllowDrawBullishFVGs(bool value) - { - mAllowDrawBullishFVGs = value; - } - - /** - * Get Bullish FVG Force Middle Bar Check ... - * - * @return ( bool ) - */ - bool BullishFVGForceMiddleBarCheck() - { - return mBullishFVGForceMiddleBarCheck; - } - - /** - * Set Bullish FVG Force Middle Bar Check ... - * - * @param value: Boolean ... - */ - void BullishFVGForceMiddleBarCheck(bool value) - { - mBullishFVGForceMiddleBarCheck = value; - } - - /** - * Get Bullish FVG Force Check Last Bar Direction ... - * - * @return ( bool ) - */ - bool BullishFVGForceCheckLastBarDirection() - { - return mBullishFVGForceCheckLastBarDirection; - } - - /** - * Set Bullish FVG Force Check Last Bar Direction ... - * - * @param value: Boolean ... - */ - void BullishFVGForceCheckLastBarDirection(bool value) - { - mBullishFVGForceCheckLastBarDirection = value; - } - - // - // Bearish FVGs ... - - /** - * Get Detect Bearish Fair Value Gaps State ... - * - * @return ( bool ) - */ - bool AllowBearishFVGs() - { - return mAllowBearishFVGs; - } - - /** - * Set Detect Bearish Fair Value Gaps State ... - * - * @param value: Boolean ... - */ - void AllowBearishFVGs(bool value) - { - mAllowBearishFVGs = value; - } - - /** - * Get Draw Bearish Fair Value Gaps ... - * - * @return ( bool ) - */ - bool AllowDrawBearishFVGs() - { - return mAllowDrawBearishFVGs; - } - - /** - * Set Draw Bearish Fair Value Gaps ... - * - * @param value: Boolean ... - */ - void AllowDrawBearishFVGs(bool value) - { - mAllowDrawBearishFVGs = value; - } - - /** - * Get Bearish FVG Force Middle Bar Check ... - * - * @return ( bool ) - */ - bool BearishFVGForceMiddleBarCheck() - { - return mBearishFVGForceMiddleBarCheck; - } - - /** - * Set Bearish FVG Force Middle Bar Check ... - * - * @param value: Boolean ... - */ - void BearishFVGForceMiddleBarCheck(bool value) - { - mBearishFVGForceMiddleBarCheck = value; - } - - /** - * Get Bearish FVG Force Check Last Bar Direction ... - * - * @return ( bool ) - */ - bool BearishFVGForceCheckLastBarDirection() - { - return mBearishFVGForceCheckLastBarDirection; - } - - /** - * Set Bearish FVG Force Check Last Bar Direction ... - * - * @param value: Boolean ... - */ - void BearishFVGForceCheckLastBarDirection(bool value) - { - mBearishFVGForceCheckLastBarDirection = value; + mSwingRange = value; } // @@ -1407,8 +210,6 @@ class XCPOI : public XSCBaseAlert */ void Init() { - // - // Detect Previous POI(s) ... DetectRequiredPOIs(); } @@ -1438,6 +239,7 @@ class XCPOI : public XSCBaseAlert int zIndex = 0; int cIndex = zIndex + 1; int pIndex = cIndex + 1; + int ppIndex = pIndex + 1; // datetime cTime = TimeCurrent(); @@ -1478,6 +280,18 @@ class XCPOI : public XSCBaseAlert return result; } + // + XOHCL ppBar; + isInited = ppBar.Init( + mSymbol, + mPeriod, + ppIndex // + ); + if (!isInited) + { + return result; + } + // XOHCL zDayBar; isInited = zDayBar.Init( @@ -1490,906 +304,6 @@ class XCPOI : public XSCBaseAlert return result; } - // - // Trading Days ... - - // - bool allowTradingDays = AllowTradingDays(); - int tradingDaysCount = ArraySize(mTradingDays); - if (allowTradingDays) - { - // - int tradingDayIDX = HasTradeDay(zDayBar.time); - if (IsValidIndex(tradingDayIDX)) - { - // - if (zBar.time == mTradingDays[tradingDayIDX].to) - { - // - ENUM_XPOI_EVENTS event = X_TRADE_DAY_LAST_BAR; - Add( - event, - state // - ); - OnTradingDayEvent(event); - NotifyTradingDayEventListeners(event); - } - } - else - { - // - // there isn't any Trading Day ... - // create one ... - - // - XTradeDay tradeDay; - tradeDay.from = zDayBar.time; - tradeDay.to = zDayBar.GetLastBarTimeOfPeriod(mPeriod); - - // - AddRef( - tradeDay, - mTradingDays // - ); - - // - DrawTradingDays(); - - // - // Notfy Day Started ... - if (zBar.time == zDayBar.time) - { - // - Add( - X_TRADE_DAY_FIRST_BAR, - state // - ); - OnTradingDayEvent(X_TRADE_DAY_FIRST_BAR); - NotifyTradingDayEventListeners(X_TRADE_DAY_FIRST_BAR); - } - } - } - - // - // Market Session ... - - // - bool allowMarketSessions = AllowMarketSessions(); - int marketSessionsCount = ArraySize(mMarketSessions); - if (allowMarketSessions) - { - // - int sessionsCount = ArraySize(mSessions); - bool isSessionFound = false; - if (IsValidSize(sessionsCount)) - { - // - for (int i = 0; i < sessionsCount; i++) - { - // - XSession iSession = mSessions[i]; - int marketSessionIDX = HasMarketSessionByStartTime( - iSession.session, - zBar.time // - ); - - // - if (!IsValidIndex(marketSessionIDX)) - { - // - datetime zTimeGMT = GetUTCTime(zBar.time); - string zTimeString = GetTimeString(zTimeGMT); - - // - bool isStarted = iSession.start == zTimeString; - - // - if (isStarted) - { - // - XMarketSession iMarketSession; - iMarketSession.session = iSession.session; - iMarketSession.from = zBar.time; - - // - int iSessionWorkingHoure = SessionOpenHours(); - int iSessionWorkingSeconds = iSessionWorkingHoure * 60 * 60; - iMarketSession.to = (datetime)((int)zBar.time + iSessionWorkingSeconds); - - // - isSessionFound = AddRef( - iMarketSession, - mMarketSessions // - ); - - // - marketSessionsCount = ArraySize(mMarketSessions); - - // - DrawMarketSessions(); - - // - Add( - X_SESSION_FIRST_BAR, - state // - ); - OnMarketSessionEvent( - iMarketSession.session, - X_SESSION_FIRST_BAR // - ); - NotifyMarketSessionEventListeners( - iMarketSession.session, - X_SESSION_FIRST_BAR // - ); - } - } - - // - // Check End Time for Last Bar ... - for (int i = 0; i < marketSessionsCount; i++) - { - // - XMarketSession iMarketSession = mMarketSessions[i]; - - // - // Calculate Last Bar Time ... - datetime endTime = iMarketSession.to; - datetime lastBarTime = (datetime)((int)endTime - PeriodSeconds(mPeriod)); - if (zBar.time == lastBarTime) - { - // - ENUM_XPOI_EVENTS event = X_SESSION_LAST_BAR; - Add( - event, - state // - ); - OnMarketSessionEvent( - iMarketSession.session, - event // - ); - NotifyMarketSessionEventListeners( - iMarketSession.session, - event // - ); - } - } - } - } - } - - // - // Swing Highs and Lows ... - - // - // Swing Highs ... - - // - bool allowSwingHighs = AllowSwingHighs(); - int swingHighsCount = ArraySize(mSwingHighs); - if (allowSwingHighs) - { - // - bool isSingHigh = pBar.IsSimpleSwingHigh(SwingHighThreshold()); - if (isSingHigh) - { - // - bool isAdded = AddBar( - X_POI_SWING_HIGH, - pBar, - mSwingHighs // - ); - - // - if (isAdded) - { - // - swingHighsCount = ArraySize(mSwingHighs); - DrawSwingHighs(); - - // - ENUM_XPOI_EVENTS event = X_SWING_HIGH_DETECTED; - Add( - event, - state // - ); - OnSwingHighEvent(event, pBar); - NotifySwingHighEventListeners(event, pBar); - } - } - } - - // - // Swing Lows ... - - // - bool allowSwingLows = AllowSwingLows(); - int swingLowsCount = ArraySize(mSwingLows); - if (allowSwingLows) - { - // - bool isSingLow = pBar.IsSimpleSwingLow(SwingLowThreshold()); - if (isSingLow) - { - // - bool isAdded = AddBar( - X_POI_SWING_LOW, - pBar, - mSwingLows // - ); - - // - if (isAdded) - { - // - swingLowsCount = ArraySize(mSwingLows); - DrawSwingLows(); - - // - ENUM_XPOI_EVENTS event = X_SWING_LOW_DETECTED; - Add( - event, - state // - ); - OnSwingLowEvent(event, pBar); - NotifySwingLowEventListeners(event, pBar); - } - } - } - - // - // Momentum Bars ... - - // - bool allowMomentumBars = AllowMomentumBars(); - int momentumBarsCount = ArraySize(mMomentumBars); - if (allowMomentumBars) - { - // - bool isStrongBar = cBar.IsStrong(MomentumBarPercent()); - bool isSharpBullish = cBar.IsSharpBullish( - MomentumBarLoopBack(), - MomentumBarSharpRatio() // - ); - bool isSharpBearish = cBar.IsSharpBearish( - MomentumBarLoopBack(), - MomentumBarSharpRatio() // - ); - bool isMomentumBar = - isStrongBar && - (isSharpBearish || - isSharpBullish); - if (isMomentumBar) - { - // - bool isAdded = AddBar( - X_POI_MOMENTUM_BAR, - cBar, - mMomentumBars // - ); - - // - if (isAdded) - { - // - momentumBarsCount = ArraySize(mMomentumBars); - DrawMomentumBars(); - - // - ENUM_XPOI_EVENTS event = X_MOMENTUM_BAR_DETECTED; - Add( - event, - state // - ); - OnMomentumBarEvent(event, cBar); - NotifyMomentumBarEventListeners(event, cBar); - } - } - } - - // - // Rejection Bars ... - - // - bool allowRejectionBars = AllowRejectionBars(); - int rejectionBarsCount = ArraySize(mRejectionBars); - if (allowRejectionBars) - { - // - int rejectionBarLoopBackBarIndex = RejectionBarLoopBack() + 1; - XOHCL iRBar; - bool isIRBarInited = iRBar.Init( - mSymbol, - mPeriod, - rejectionBarLoopBackBarIndex // - ); - if (isIRBarInited) - { - // - bool isRejectionBar = - iRBar.HasStrongLowShadow( - RejectionBarPercent(), - RejectionBarLoopBack(), - RejectionBarSharpRatio() // - ) || - iRBar.HasStrongHighShadow( - RejectionBarPercent(), - RejectionBarLoopBack(), - RejectionBarSharpRatio() // - ); - if (isRejectionBar) - { - // - bool isAdded = AddBar( - X_POI_REJECTION_BAR, - iRBar, - mRejectionBars // - ); - - // - if (isAdded) - { - // - rejectionBarsCount = ArraySize(mRejectionBars); - DrawRejectionBars(); - - // - ENUM_XPOI_EVENTS event = X_REJECTION_BAR_DETECTED; - Add( - event, - state // - ); - OnRejectionBarEvent(event, iRBar); - NotifyRejectionBarEventListeners(event, iRBar); - } - } - } - } - - // - // Support and Resistance Zones ... - - // - // Support Zones ... - - // - bool allowSupportZones = AllowSupportZones(); - int supportZonesCount = ArraySize(mSupportZones); - if (allowSupportZones) - { - // - XOHCL support; - bool hasSupport = cBar.HasSupport( - support, - SupportZonePriceType(), - SupportZoneLoopBack() // - ); - if (hasSupport) - { - // - bool isAdded = AddBar( - X_POI_SUPPORT_ZONE, - support, - mSupportZones // - ); - - // - if (isAdded) - { - // - supportZonesCount = ArraySize(mSupportZones); - DrawSupportZones(); - - // - ENUM_XPOI_EVENTS event = X_SUPPORT_ZONE_DETECTED; - Add( - event, - state // - ); - OnSupportZoneEvent(event, support); - NotifySupportZoneEventListeners(event, support); - } - } - } - - // - // Resistance Zone ... - - // - bool allowResistanceZones = AllowResistanceZones(); - int resistanceZonesCount = ArraySize(mResistanceZones); - if (allowResistanceZones) - { - // - XOHCL resistance; - bool hasResistance = cBar.HasResistance( - resistance, - ResistanceZonePriceType(), - ResistanceZoneLoopBack() // - ); - if (hasResistance) - { - // - bool isAdded = AddBar( - X_POI_RESISTANCE_ZONE, - resistance, - mResistanceZones // - ); - - // - if (isAdded) - { - // - resistanceZonesCount = ArraySize(mResistanceZones); - DrawResistanceZones(); - - // - ENUM_XPOI_EVENTS event = X_RESISTANCE_ZONE_DETECTED; - Add( - event, - state // - ); - OnResistanceZoneEvent(event, resistance); - NotifyResistanceZoneEventListeners(event, resistance); - } - } - } - - // - // Supply and Demand Zones ... - - // - // Supply Zones ... - - // - bool allowSupplyZones = AllowSupplyZones(); - int supplyZonesCount = ArraySize(mSupplyZones); - if (allowSupplyZones) - { - // - datetime endTime = cBar.time; - XOHCL cSupplyBar; - bool isSupplyBarInited = cSupplyBar.Init( - mSymbol, - SupplyZonePeriod(), - 0 // - ); - if (isSupplyBarInited) - { - // - datetime lastSupplyBarTime = cSupplyBar - .GetLastBarTimeOfPeriod(mPeriod); - if (zBar.time == lastSupplyBarTime) - { - // - datetime startTime = cSupplyBar.time; - int cSupplyZonePeriodIndex = iBarShift( - mSymbol, - mPeriod, - cSupplyBar.time // - ); - - // - // Find Swings ... - XOHCL swings[]; - for (int i = 0; i < cSupplyZonePeriodIndex; i++) - { - // - XOHCL iBar; - bool isIBarInited = iBar.Init( - mSymbol, - mPeriod, - i // - ); - if (!isIBarInited) - { - continue; - } - - // - // Check is Bar Swing or not ... - bool isSwing = iBar.IsSimpleSwingHigh(); - if (!isSwing) - { - continue; - } - - // - AddRef( - iBar, - swings // - ); - } - - // - // Select Max Swing for Supply Zone ... - XOHCL selectedSwing; - int swingsCount = ArraySize(swings); - if (IsValidSize(swingsCount)) - { - // - for (int i = 0; i < swingsCount; i++) - { - // - XOHCL iSwing = swings[i]; - if (!selectedSwing.IsValid() || - selectedSwing.high < iSwing.high) - { - selectedSwing = iSwing; - } - } - } - - // - // Check Swing ... - if (selectedSwing.IsValid()) - { - // - XZone zone; - bool isInited = zone.Init( - selectedSwing.high, - selectedSwing.low, - ToString(X_POI_SUPPLY_ZONE) + "_" + ToString(SupplyZonePeriod()), - startTime, - endTime // - ); - if (isInited) - { - // - int zoneIDX = FindZoneIndex( - zone, - mSupplyZones // - ); - - // - if (!IsValidIndex(zoneIDX)) - { - // - AddRef( - zone, - mSupplyZones // - ); - - // - supplyZonesCount = ArraySize(mSupplyZones); - DrawSupplyZones(); - - // - ENUM_XPOI_EVENTS event = X_SUPPLY_ZONE_DETECTED; - Add( - event, - state // - ); - OnSupplyZoneEvent(event, zone); - NotifySupplyZoneEventListeners(event, zone); - } - } - } - } - } - } - - // - // Demand Zones ... - - // - bool allowDemandZones = AllowDemandZones(); - int demandZonesCount = ArraySize(mDemandZones); - if (allowDemandZones) - { - // - datetime endTime = cBar.time; - XOHCL cDemandBar; - bool isDemandBarInited = cDemandBar.Init( - mSymbol, - DemandZonePeriod(), - 0 // - ); - if (isDemandBarInited) - { - // - datetime lastDemandBarTime = cDemandBar - .GetLastBarTimeOfPeriod(mPeriod); - if (zBar.time == lastDemandBarTime) - { - // - datetime startTime = cDemandBar.time; - int cDemandZonePeriodIndex = iBarShift( - mSymbol, - mPeriod, - cDemandBar.time // - ); - - // - // Find Swings ... - XOHCL swings[]; - for (int i = 0; i < cDemandZonePeriodIndex; i++) - { - // - XOHCL iBar; - bool isIBarInited = iBar.Init( - mSymbol, - mPeriod, - i // - ); - if (!isIBarInited) - { - continue; - } - - // - // Check is Bar Swing or not ... - bool isSwing = iBar.IsSimpleSwingLow(); - if (!isSwing) - { - continue; - } - - // - AddRef( - iBar, - swings // - ); - } - - // - // Select Max Swing for Supply Zone ... - XOHCL selectedSwing; - int swingsCount = ArraySize(swings); - if (IsValidSize(swingsCount)) - { - // - for (int i = 0; i < swingsCount; i++) - { - // - XOHCL iSwing = swings[i]; - if (!selectedSwing.IsValid() || - selectedSwing.low > iSwing.low) - { - selectedSwing = iSwing; - } - } - } - - // - // Check Swing ... - if (selectedSwing.IsValid()) - { - // - XZone zone; - bool isInited = zone.Init( - selectedSwing.high, - selectedSwing.low, - ToString(X_POI_DEMAND_ZONE) + "_" + ToString(SupplyZonePeriod()), - startTime, - endTime // - ); - if (isInited) - { - // - int zoneIDX = FindZoneIndex( - zone, - mDemandZones // - ); - - // - if (!IsValidIndex(zoneIDX)) - { - // - AddRef( - zone, - mDemandZones // - ); - - // - demandZonesCount = ArraySize(mDemandZones); - DrawDemandZones(); - - // - ENUM_XPOI_EVENTS event = X_DEMAND_ZONE_DETECTED; - Add( - event, - state // - ); - OnDemandZoneEvent(event, zone); - NotifyDemandZoneEventListeners(event, zone); - } - } - } - } - } - } - - // - // Order Blocks ... - - // - // Bullish Order Blocks ... - - // - bool allowBullishOrderBlocks = AllowBullishOrderBlocks(); - int bullishOrderBlocksCount = ArraySize(mBullishOrderBlocks); - if (allowBullishOrderBlocks) - { - // - XOHCL bullOB; - bool hasBullOB = cBar.HasBullishOrderBlock( - bullOB, - RequiredBarsForBullishOrderBlock() // - ); - if (hasBullOB) - { - // - XZone obZone; - bool isAdded = AddZone( - obZone, // Dest ... - bullOB, - cBar.time, - X_POI_BULLISH_ORDERBLOCK, - mBullishOrderBlocks // - ); - if (isAdded) - { - // - bullishOrderBlocksCount = ArraySize(mBullishOrderBlocks); - DrawBullishOrderBlocks(); - - // - ENUM_XPOI_EVENTS event = X_BULLISH_ORDERBLOCK_DETECTED; - Add( - event, - state // - ); - OnBullishOrderBlockEvent(event, obZone); - NotifyBullishOrderBlockEventListeners(event, obZone); - } - } - } - - // - // Bearish Order Blocks ... - - // - bool allowBearishOrderBlocks = AllowBearishOrderBlocks(); - int bearishOrderBlocksCount = ArraySize(mBearishOrderBlocks); - if (allowBearishOrderBlocks) - { - // - XOHCL bearOB; - bool hasBearOB = cBar.HasBearishOrderBlock( - bearOB, - RequiredBarsForBearishOrderBlock() // - ); - if (hasBearOB) - { - // - XZone zone; - bool isAdded = AddZone( - zone, // - bearOB, - cBar.time, - X_POI_BEARISH_ORDERBLOCK, - mBearishOrderBlocks // - ); - if (isAdded) - { - // - bullishOrderBlocksCount = ArraySize(mBearishOrderBlocks); - DrawBearishOrderBlocks(); - - // - ENUM_XPOI_EVENTS event = X_BEARISH_ORDERBLOCK_DETECTED; - Add( - event, - state // - ); - OnBullishOrderBlockEvent(event, zone); - NotifyBullishOrderBlockEventListeners(event, zone); - } - } - } - - // - // Fair Value Gaps ... - double upper; - double lower; - datetime start; - datetime end; - - // - // Bullish FVGs ... - bool allowBullishFVGs = AllowBullishFVGs(); - int bullishFVGsCount = ArraySize(mBullishFVGs); - if (allowBullishFVGs) - { - // - bool hasBullishFVG = cBar.HasBullishFVG( - upper, - lower, - start, - end, - BullishFVGForceMiddleBarCheck(), - BullishFVGForceCheckLastBarDirection() // - ); - if (hasBullishFVG) - { - // - XZone zone; - bool isAdded = AddZone( - zone, - upper, - lower, - start, - end, - X_POI_BULLISH_FVG, - mBullishFVGs // - ); - if (isAdded) - { - // - bullishFVGsCount = ArraySize(mBullishFVGs); - DrawBullishFVGs(); - - // - ENUM_XPOI_EVENTS event = X_BULLISH_FVG_DETECTED; - Add( - event, - state // - ); - OnBullishFVGEvent(event, zone); - NotifyBullishFVGEventListeners(event, zone); - } - } - } - - // - // Bearish FVGs ... - bool allowBearishFVGs = AllowBearishFVGs(); - int bearishFVGsCount = ArraySize(mBearishFVGs); - if (allowBearishFVGs) - { - // - bool hasBearishFVG = cBar.HasBearishFVG( - upper, - lower, - start, - end, - BearishFVGForceMiddleBarCheck(), - BearishFVGForceCheckLastBarDirection() // - ); - if (hasBearishFVG) - { - // - XZone zone; - bool isAdded = AddZone( - zone, - upper, - lower, - start, - end, - X_POI_BEARISH_FVG, - mBearishFVGs // - ); - if (isAdded) - { - // - bearishFVGsCount = ArraySize(mBearishFVGs); - DrawBearishFVGs(); - - // - ENUM_XPOI_EVENTS event = X_BEARISH_FVG_DETECTED; - Add( - event, - state // - ); - OnBearishFVGEvent(event, zone); - NotifyBearishFVGEventListeners(event, zone); - } - } - } - - // - // ... - // CleanupUnusedPOIs(); @@ -2404,96 +318,14 @@ class XCPOI : public XSCBaseAlert } /** - * Enable All POIs Detection ... + * Destroy Class ... */ - void EnablePOIs() - { - ChangePOIsState(true); - } - - /** - * Disable All POIs Detection ... - */ - void DisablePOIs() - { - ChangePOIsState(false); - } - - /** - * Set All POIs Detection States ... - * - * @param state: Argument 1 - */ - void ChangePOIsState(bool state) + void Destroy() { // - AllowSwingLows(state); - AllowSwingHighs(state); - AllowTradingDays(state); - AllowSupplyZones(state); - AllowDemandZones(state); - AllowBullishFVGs(state); - AllowBearishFVGs(state); - AllowMomentumBars(state); - AllowSupportZones(state); - AllowRejectionBars(state); - AllowMarketSessions(state); - AllowResistanceZones(state); - AllowBullishOrderBlocks(state); - AllowBearishOrderBlocks(state); - } - - /** - * Enable Draw All POI(s) ... - */ - void EnableDrawPOIs() - { - ChangePOIsDrawState(true); - } - - /** - * Disable Draw All POI(s) ... - */ - void DisableDrawPOIs() - { - ChangePOIsDrawState(false); - } - - /** - * Set Drawing State of all POIs ... - * - * @param state: Boolean ... - */ - void ChangePOIsDrawState(bool state) - { - // - AllowDrawSwingLows(state); - AllowDrawSwingHighs(state); - AllowDrawTradingDays(state); - AllowDrawSupplyZones(state); - AllowDrawBullishFVGs(state); - AllowDrawBearishFVGs(state); - AllowDrawDemandZones(state); - AllowDrawSupportZones(state); - AllowDrawMomentumBars(state); - AllowDrawRejectionBars(state); - AllowDrawMarketSessions(state); - AllowDrawResistanceZones(state); - AllowDrawBullishOrderBlocks(state); - AllowDrawBearishOrderBlocks(state); - - // - // Sessions ... - int sessionsCount = ArraySize(mSessions); - if (IsValidSize(sessionsCount)) - { - // - for (int i = 0; i < sessionsCount; i++) - { - // - mSessions[i].allowDraw = state; - } - } + DestroyPOIs(); + DestroySessions(); + DestroyEventListeners(); } // @@ -2517,32 +349,34 @@ class XCPOI : public XSCBaseAlert state.reportedAt = TimeCurrent(); // - state.FillTradingDays(mTradingDays); - state.FillMarketSessions(mMarketSessions); + // TODO: Fill State ... + } - // - state.FillMomentumBars(mMomentumBars); - state.FillRejectionBars(mRejectionBars); + // + // Event Listeners ... - // - state.FillSwingHighs(mSwingHighs); - state.FillSwingLows(mSwingLows); + // + // Destroy ... - // - state.FillSupportZones(mSupportZones); - state.FillResistanceZones(mResistanceZones); + /** + * Destroy Detected POI(s) ... + */ + void DestroyPOIs() + { + } - // - state.FillSupplyZones(mSupplyZones); - state.FillDemandZones(mDemandZones); + /** + * Destroy Added Sessions ... + */ + void DestroySessions() + { + } - // - state.FillBullishOrderBlocks(mBullishOrderBlocks); - state.FillBearishOrderBlocks(mBearishOrderBlocks); - - // - state.FillBullishFVGs(mBullishFVGs); - state.FillBearishFVGs(mBearishFVGs); + /** + * Destroy Rejistered Event Handlers ... + */ + void DestroyEventListeners() + { } // @@ -2556,666 +390,14 @@ class XCPOI : public XSCBaseAlert // // Common ... - // - ChartIdentification(0); - SubWindowIdentification(0); - mDrawer.ChartIdentification(0); - mDrawer.SubWindowIdentification(0); - // MaxNumberOfPOIs(10); MaxNumberOfRequiredPOIs(2); // - EnablePOIs(); - EnableDrawPOIs(); + SwingRange(2); // - // Trading Days ... - TradingDaysStartColor(clrYellow); - TradingDaysStartStyle(STYLE_DASHDOT); - TradingDaysEndColor(clrGray); - TradingDaysEndStyle(STYLE_DASHDOT); - - // - // Sessions ... - - // - // SYDNEY ... - // Start: (UTC) 21:00 - // End: (UTC) 06:00 - XSession mSyndeySession; - mSyndeySession.Init( - X_SYDNEY, - "20:00", // Start ... - "05:00" // End Next Day ... - ); - mSyndeySession.startColor = clrFireBrick; - mSyndeySession.endColor = clrFireBrick; - mSyndeySession.allowDraw = true; - AddSession(mSyndeySession); - - // - // TOKYO ... - // Start: (UTC) 12:00 - // End: (UTC) 09:00 - XSession mTokyoSession; - mTokyoSession.Init( - X_TOKYO, - "00:00", // Start ... - "09:00" // End Next Day ... - ); - mTokyoSession.startColor = clrBlueViolet; - mTokyoSession.endColor = clrBlueViolet; - mTokyoSession.allowDraw = true; - AddSession(mTokyoSession); - - // - // LONDON ... - // Start: (UTC) 07:00 - // End: (UTC) 16:00 - XSession mLondonSession; - mLondonSession.Init( - X_LONDON, - "07:00", // Start ... - "16:00" // End ... - ); - mLondonSession.startColor = clrLime; - mLondonSession.endColor = clrLime; - mLondonSession.allowDraw = true; - AddSession(mLondonSession); - - // - // NEWYORK ... - // Start: (UTC) 13:00 - // End: (UTC) 22:00 - XSession mNewYorkSession; - mNewYorkSession.Init( - X_NEW_YORK, - "12:00", // Start ... - "21:00" // End ... - ); - mNewYorkSession.startColor = clrAqua; - mNewYorkSession.endColor = clrAqua; - mNewYorkSession.allowDraw = true; - AddSession(mNewYorkSession); - - // - SessionOpenHours(9); - - // - // Swing High and Low (s) ... - - // - // Swing Highs ... - SwingHighThreshold(3); - mDrawer.SwingHighWidth(5); - mDrawer.SwingHighArrow(108); - mDrawer.SwingHighColor(clrMagenta); - - // - // Swing Lows ... - SwingLowThreshold(3); - mDrawer.SwingLowWidth(5); - mDrawer.SwingLowArrow(108); - mDrawer.SwingLowColor(clrAqua); - - // - // Momentum Bars ... - MomentumBarPercent(55); - MomentumBarLoopBack(3); - MomentumBarSharpRatio(1.2); - mDrawer.BullishMomentumBarWidth(5); - mDrawer.BearishMomentumBarWidth(5); - mDrawer.BullishMomentumBarArrow(225); - mDrawer.BearishMomentumBarArrow(226); - mDrawer.BullishMomentumBarColor(clrAqua); - mDrawer.BearishMomentumBarColor(clrMagenta); - - // - // Rejection Bars ... - RejectionBarPercent(55); - RejectionBarLoopBack(5); - RejectionBarSharpRatio(1.5); - mDrawer.BullishRejectionBarWidth(5); - mDrawer.BearishRejectionBarWidth(5); - mDrawer.BullishRejectionBarArrow(217); - mDrawer.BearishRejectionBarArrow(218); - mDrawer.BullishRejectionBarColor(clrAqua); - mDrawer.BearishRejectionBarColor(clrMagenta); - - // - // Support and Resistance Zones ... - - // - // Support Zones ... - SupportZoneLoopBack(52); - SupportZonePriceType(X_PRICE_CLOSE); - mDrawer.SupportZoneWidth(1); - mDrawer.SupportZoneColor(clrLime); - mDrawer.SupportZoneStyle(STYLE_DOT); - - // - // Resistance Zones ... - ResistanceZoneLoopBack(52); - ResistanceZonePriceType(X_PRICE_CLOSE); - mDrawer.ResistanceZoneWidth(1); - mDrawer.ResistanceZoneColor(clrRed); - mDrawer.ResistanceZoneStyle(STYLE_DOT); - - // - // Supply and Deman Zones ... - - // - // Supply Zones ... - SupplyZonePeriod(GetHindMostPeriod(mPeriod)); - mDrawer.SupplyZoneWidth(1); - mDrawer.SupplyZoneColor(clrDarkRed); - mDrawer.SupplyZoneStyle(STYLE_DASH); - - // - // Demand Zones ... - DemandZonePeriod(GetHindMostPeriod(mPeriod)); - mDrawer.DemandZoneWidth(1); - mDrawer.DemandZoneColor(clrDarkGreen); - mDrawer.DemandZoneStyle(STYLE_DASH); - - // - // Order Blocks ... - - // - // Bullish Order Block ... - RequiredBarsForBullishOrderBlock(3); - mDrawer.BullishOrderBlockWidth(1); - mDrawer.BullishOrderBlockColor(clrAqua); - mDrawer.BullishOrderBlockStyle(STYLE_DASHDOT); - - // - // Bearish Order Block ... - RequiredBarsForBearishOrderBlock(3); - mDrawer.BearishOrderBlockWidth(1); - mDrawer.BearishOrderBlockColor(clrMagenta); - mDrawer.BearishOrderBlockStyle(STYLE_DASHDOT); - - // - // Fair Value Gaps ... - - // - // Bullish FVGs ... - BullishFVGForceMiddleBarCheck(true); - BullishFVGForceCheckLastBarDirection(true); - mDrawer.BullishFVGWidth(1); - mDrawer.BullishFVGColor(clrAqua); - mDrawer.BullishFVGStyle(STYLE_DASHDOTDOT); - - // - // Bearish FVGs ... - BearishFVGForceMiddleBarCheck(true); - BearishFVGForceCheckLastBarDirection(true); - mDrawer.BearishFVGWidth(1); - mDrawer.BearishFVGColor(clrMagenta); - mDrawer.BearishFVGStyle(STYLE_DASHDOTDOT); - - // - } - - // - // Session Configurations ... - - /** - * Add Sepcific Session to Supported Sessions ... - * - * @param session: XSession instance ... - */ - void AddSession(XSession &session) - { - // - if (!session.IsValid()) - { - return; - } - - // - AddRef( - session, - mSessions // - ); - } - - // - // Event Listeners ... - - // - // Trading Days ... - - /** - * Calls When new Trading Day Event Happens ... - * - * @param event: ENUM_XPOI_EVENTS member ... - */ - virtual void OnTradingDayEvent( - ENUM_XPOI_EVENTS event // - ) - { - } - - /** - * Register an Event Listener for New Trading Day Events ... - * - * @param listener: TXPOIEventHandler instance ... - */ - void AddTradingDayEventListener(TXPOIEventHandler listener) - { - // - Add( - listener, - mTradingDayEventListeners // - ); - } - - // - // Market Sessions ... - - /** - * Calls When new Market Session Event Happens ... - * - * @param session: ENUM_XSESSION member ... - * @param event: ENUM_XPOI_EVENTS member ... - */ - virtual void OnMarketSessionEvent( - ENUM_XSESSION session, - ENUM_XPOI_EVENTS event // - ) - { - } - - /** - * Register an Event Listener for New Market Session Events ... - * - * @param listener: TXSessionEventHandler instance ... - */ - void AddMarketSessionEventListener(TXSessionEventHandler listener) - { - // - Add( - listener, - mMarketSessionEventListeners // - ); - } - - // - // Swings ... - - // - // Swing Highs ... - - /** - * Calls When new Swing High Event ... - * - * @param event: ENUM_XPOI_EVENTS member ... - * @param bar: XOHCL instance ... - */ - virtual void OnSwingHighEvent( - ENUM_XPOI_EVENTS event, - XOHCL &bar // - ) - { - } - - /** - * Register an Event Listener for New Swing High Event ... - * - * @param listener: TXOHCLEventHandler instance ... - */ - void AddSwingHighEventListener(TXOHCLEventHandler listener) - { - // - Add( - listener, - mSwingHighEventListeners // - ); - } - - // - // Swing Lows ... - - /** - * Calls When new Swing Low Detected ... - * - * @param event: ENUM_XPOI_EVENTS member ... - * @param bar: XOHCL instance ... - */ - virtual void OnSwingLowEvent( - ENUM_XPOI_EVENTS event, - XOHCL &bar // - ) - { - } - - /** - * Register an Event Listener for New Swing Low Event ... - * - * @param listener: TXOHCLEventHandler instance ... - */ - void AddSwingLowEventListener(TXOHCLEventHandler listener) - { - // - Add( - listener, - mSwingLowEventListeners // - ); - } - - // - // Momentum Bar ... - - /** - * Calls When new Momentum Bar Event ... - * - * @param event: ENUM_XPOI_EVENTS member ... - * @param bar: XOHCL instance ... - */ - virtual void OnMomentumBarEvent( - ENUM_XPOI_EVENTS event, - XOHCL &bar // - ) - { - } - - /** - * Register an Event Listener for New Momentum Bar Event ... - * - * @param listener: TXOHCLEventHandler instance ... - */ - void AddMomentumBarEventListener(TXOHCLEventHandler listener) - { - // - Add( - listener, - mMomentumBarEventListeners // - ); - } - - // - // Rejection Bar ... - - /** - * Calls When new Rejection Bar Event ... - * - * @param event: ENUM_XPOI_EVENTS member ... - * @param bar: XOHCL instance ... - */ - virtual void OnRejectionBarEvent( - ENUM_XPOI_EVENTS event, - XOHCL &bar // - ) - { - } - - /** - * Register an Event Listener for New Rejection Bar Event ... - * - * @param listener: TXOHCLEventHandler instance ... - */ - void AddRejectionBarEventListener(TXOHCLEventHandler listener) - { - // - Add( - listener, - mRejectionBarEventListeners // - ); - } - - // - // Support and Resistance Zones ... - - // - // Support Zones ... - - /** - * Calls When new Support Zone Event ... - * - * @param event: ENUM_XPOI_EVENTS member ... - * @param bar: XOHCL instance ... - */ - virtual void OnSupportZoneEvent( - ENUM_XPOI_EVENTS event, - XOHCL &bar // - ) - { - } - - /** - * Register an Event Listener for New Support Zone Event ... - * - * @param listener: TXOHCLEventHandler instance ... - */ - void AddSupportZoneEventListener(TXOHCLEventHandler listener) - { - // - Add( - listener, - mSupportZoneEventListeners // - ); - } - - // - // Resistance Zones ... - - /** - * Calls When new Resistance Zone Event ... - * - * @param event: ENUM_XPOI_EVENTS member ... - * @param bar: XOHCL instance ... - */ - virtual void OnResistanceZoneEvent( - ENUM_XPOI_EVENTS event, - XOHCL &bar // - ) - { - } - - /** - * Register an Event Listener for New Resistance Zone Event ... - * - * @param listener: TXOHCLEventHandler instance ... - */ - void AddResistanceZoneEventListener(TXOHCLEventHandler listener) - { - // - Add( - listener, - mResistanceZoneEventListeners // - ); - } - - // - // Supply and Demand Zones ... - - // - // Supply Zones ... - - /** - * Calls When new Supply Zone Event ... - * - * @param event: ENUM_XPOI_EVENTS member ... - * @param zone: XZone instance ... - */ - virtual void OnSupplyZoneEvent( - ENUM_XPOI_EVENTS event, - XZone &zone // - ) - { - } - - /** - * Register an Event Listener for New Supply Zone Event ... - * - * @param listener: TXZoneEventHandler instance ... - */ - void AddSupplyZoneEventListener(TXZoneEventHandler listener) - { - // - Add( - listener, - mSupplyZoneEventListeners // - ); - } - - // - // Demand Zones ... - - /** - * Calls When new Demand Zone Event ... - * - * @param event: ENUM_XPOI_EVENTS member ... - * @param zone: XZone instance ... - */ - virtual void OnDemandZoneEvent( - ENUM_XPOI_EVENTS event, - XZone &zone // - ) - { - } - - /** - * Register an Event Listener for New Demand Zone Event ... - * - * @param listener: TXZoneEventHandler instance ... - */ - void AddDemandZoneEventListener(TXZoneEventHandler listener) - { - // - Add( - listener, - mDemandZoneEventListeners // - ); - } - - // - // Order Blocks ... - - // - // Bullish Order Blocks ... - - /** - * Calls When new Bullish Order Block Event ... - * - * @param event: ENUM_XPOI_EVENTS member ... - * @param zone: XZone instance ... - */ - virtual void OnBullishOrderBlockEvent( - ENUM_XPOI_EVENTS event, - XZone &zone // - ) - { - } - - /** - * Register an Event Listener for New Bullish Order Block Event ... - * - * @param listener: TXZoneEventHandler instance ... - */ - void AddBullishOrderBlockEventListener(TXZoneEventHandler listener) - { - // - Add( - listener, - mBullishOrderBlockEventListeners // - ); - } - - // - // Bearish Order Blocks ... - - /** - * Calls When new Bearish Order Block Event ... - * - * @param event: ENUM_XPOI_EVENTS member ... - * @param zone: XZone instance ... - */ - virtual void OnBearishOrderBlockEvent( - ENUM_XPOI_EVENTS event, - XZone &zone // - ) - { - } - - /** - * Register an Event Listener for New Bearish Order Block Event ... - * - * @param listener: TXZoneEventHandler instance ... - */ - void AddBearishOrderBlockEventListener(TXZoneEventHandler listener) - { - // - Add( - listener, - mBearishOrderBlockEventListeners // - ); - } - - // - // Fai Value Gaps ... - - // - // Bullish FVGs ... - - /** - * Calls When new Bullish FVG Event ... - * - * @param event: ENUM_XPOI_EVENTS member ... - * @param zone: XZone instance ... - */ - virtual void OnBullishFVGEvent( - ENUM_XPOI_EVENTS event, - XZone &zone // - ) - { - } - - /** - * Register an Event Listener for New Bullish FVG Event ... - * - * @param listener: TXZoneEventHandler instance ... - */ - void AddBullishFVGEventListener(TXZoneEventHandler listener) - { - // - Add( - listener, - mBullishFVGEventListeners // - ); - } - - // - // Bearish FVGs ... - - /** - * Calls When new Bearish FVG Event ... - * - * @param event: ENUM_XPOI_EVENTS member ... - * @param zone: XZone instance ... - */ - virtual void OnBearishFVGEvent( - ENUM_XPOI_EVENTS event, - XZone &zone // - ) - { - } - - /** - * Register an Event Listener for New Bearish FVG Event ... - * - * @param listener: TXZoneEventHandler instance ... - */ - void AddBearishFVGEventListener(TXZoneEventHandler listener) - { - // - Add( - listener, - mBearishFVGEventListeners // - ); } // @@ -3258,6 +440,7 @@ class XCPOI : public XSCBaseAlert } // + // Locking Detector ... Lock(); // @@ -3267,773 +450,34 @@ class XCPOI : public XSCBaseAlert barIndex = 0; } + // + int swingLowsCount = 0; + int swingHighsCount = 0; + // bool canContinue = true; + + // while (canContinue) { - // - // Define Index of Bars ... - int zIndex = barIndex; - int cIndex = zIndex + 1; - - // - datetime cTime = TimeCurrent(); - - // - XOHCL zBar; - bool isRetrieved = mBarTracker.GetBar(zBar, zIndex); - if (!isRetrieved) - { - break; - } - - // - XOHCL cBar; - isRetrieved = mBarTracker.GetBar(cBar, cIndex); - if (!isRetrieved) - { - break; - } - - // - // Detect POI(s) based On Current Bar ... - - // - // Trade Days ... - bool allowTradingDays = AllowTradingDays(); - int daysCount = ArraySize(mTradingDays); - if (allowTradingDays && - daysCount < requiredPOIs) - { - // - XOHCL zDayBar; - isRetrieved = zDayBar.Init( - mSymbol, - PERIOD_D1, - zIndex // - ); - if (!isRetrieved) - { - break; - } - - // - XOHCL cDayBar; - isRetrieved = cDayBar.Init( - mSymbol, - PERIOD_D1, - cIndex // - ); - if (!isRetrieved) - { - break; - } - - // - XTradeDay tradeDay; - tradeDay.from = zDayBar.time; - - // - datetime lastBarTime = zDayBar.GetLastBarTimeOfPeriod(mPeriod); - tradeDay.to = lastBarTime; - - // - int idx = HasTradeDay(tradeDay.from); - if (!IsValidIndex(idx)) - { - // - AddRef( - tradeDay, - mTradingDays // - ); - - // - daysCount = ArraySize(mTradingDays); - } - } - - // - // Market Sessions ... - int sessionsCount = ArraySize(mSessions); - bool allowMarketSessions = AllowMarketSessions(); - int marketSessionsCount = ArraySize(mMarketSessions); - if (allowMarketSessions && - IsValidSize(sessionsCount) && - marketSessionsCount < sessionsCount * requiredPOIs) - { - // - for (int i = 0; i < sessionsCount; i++) - { - // - XSession iSession = mSessions[i]; - int iCount = CountMarketSessions(iSession.session); - if (iCount >= requiredPOIs) - { - continue; - } - - // - datetime zTimeGMT = GetUTCTime(zBar.time); - string zTimeString = GetTimeString(zTimeGMT); - - // - bool isStarted = iSession.start == zTimeString; - bool isEnded = iSession.end == zTimeString; - - // - // Detect Sessions Based on Time ... - // Since All Session Close Times Related to Current Date and - // in Required POIs we Moving Back from Current Date ... - if (isEnded && iCount < requiredPOIs) - { - // - // Check Market Session Doesnt Exists by End Time ... - int iIDX = HasMarketSessionByEndTime( - iSession.session, - zBar.time // - ); - if (!IsValidIndex(iIDX)) - { - // - XMarketSession iMarketSession; - iMarketSession.session = iSession.session; - iMarketSession.to = zBar.time; - - // - int iSessionWorkingHoure = SessionOpenHours(); - int iSessionWorkingSeconds = iSessionWorkingHoure * 60 * 60; - iMarketSession.from = (datetime)((int)zBar.time - iSessionWorkingSeconds); - - // - AddRef( - iMarketSession, - mMarketSessions // - ); - - // - marketSessionsCount = ArraySize(mMarketSessions); - } - } - - // - } - } - - // - // Swning Highs and Lows ... - // // Swing Highs ... - bool allowSwingHighs = AllowSwingHighs(); - int swingHighsCount = ArraySize(mSwingHighs); - if (allowSwingHighs && - swingHighsCount < requiredPOIs) - { - // - bool isSwingHigh = cBar.IsSimpleSwingHigh(SwingHighThreshold()); - if (isSwingHigh) - { - // - bool isAdded = AddBar( - X_POI_SWING_HIGH, - cBar, - mSwingHighs // - ); - - // - if (isAdded) - { - swingHighsCount = ArraySize(mSwingHighs); - } - } - } + swingHighsCount = DetectRequiredSwingHighs(barIndex); // // Swing Lows ... - bool allowSwingLows = AllowSwingLows(); - int swingLowsCount = ArraySize(mSwingLows); - if (allowSwingLows && - swingLowsCount < requiredPOIs) - { - // - bool isSwingLow = cBar.IsSimpleSwingLow(SwingLowThreshold()); - if (isSwingLow) - { - // - bool isAdded = AddBar( - X_POI_SWING_LOW, - cBar, - mSwingLows // - ); - - // - if (isAdded) - { - swingLowsCount = ArraySize(mSwingLows); - } - } - } + swingLowsCount = DetectRequiredSwingLows(barIndex); // - // Momentum Bars ... - bool allowMomentumBars = AllowMomentumBars(); - int momentumBarsCount = ArraySize(mMomentumBars); - if (allowMomentumBars && - momentumBarsCount < requiredPOIs) - { - // - bool isStrongBar = cBar.IsStrong(MomentumBarPercent()); - - // - // Bullish ... - bool isSharpBullish = cBar.IsSharpBullish( - MomentumBarLoopBack(), - MomentumBarSharpRatio() // - ); - - // - // Bearish ... - bool isSharpBearish = cBar.IsSharpBearish( - MomentumBarLoopBack(), - MomentumBarSharpRatio() // - ); - - // - bool isMomentumBar = - isStrongBar && - (isSharpBearish || - isSharpBullish); - if (isMomentumBar) - { - // - bool isAdded = AddBar( - X_POI_MOMENTUM_BAR, - cBar, - mMomentumBars // - ); - - // - if (isAdded) - { - momentumBarsCount = ArraySize(mMomentumBars); - } - } - } - - // - // Rejection Bars ... - bool allowRejectionBars = AllowRejectionBars(); - int rejectionBarsCount = ArraySize(mRejectionBars); - if (allowRejectionBars && - rejectionBarsCount < requiredPOIs) - { - // - bool isRejectionBar = - cBar.HasStrongLowShadow( - RejectionBarPercent(), - RejectionBarLoopBack(), - RejectionBarSharpRatio() // - ) || - cBar.HasStrongHighShadow( - RejectionBarPercent(), - RejectionBarLoopBack(), - RejectionBarSharpRatio() // - ); - - // - if (isRejectionBar) - { - // - bool isAdded = AddBar( - X_POI_REJECTION_BAR, - cBar, - mRejectionBars // - ); - - // - if (isAdded) - { - rejectionBarsCount = ArraySize(mRejectionBars); - } - } - } - - // - // Support nad Resistance Zones ... - - // - // Support Zones ... - bool allowSupportZones = AllowSupportZones(); - int supportZonesCount = ArraySize(mSupportZones); - if (allowSupportZones && - supportZonesCount < requiredPOIs) - { - // - XOHCL support; - bool hasSupport = cBar.HasSupport( - support, - SupportZonePriceType(), - SupportZoneLoopBack() // - ); - - // - if (hasSupport) - { - // - bool isAdded = AddBar( - X_POI_SUPPORT_ZONE, - support, - mSupportZones // - ); - - // - if (isAdded) - { - supportZonesCount = ArraySize(mSupportZones); - } - } - } - - // - // Resistance Zones ... - bool allowResistanceZones = AllowResistanceZones(); - int resistanceZonesCount = ArraySize(mResistanceZones); - if (allowResistanceZones && - resistanceZonesCount < requiredPOIs) - { - // - XOHCL resistance; - bool hasResistance = cBar.HasResistance( - resistance, - ResistanceZonePriceType(), - ResistanceZoneLoopBack() // - ); - - // - if (hasResistance) - { - // - bool isAdded = AddBar( - X_POI_RESISTANCE_ZONE, - resistance, - mResistanceZones // - ); - - // - if (isAdded) - { - resistanceZonesCount = ArraySize(mResistanceZones); - } - } - } - - // - // Supply and Demand Zones ... - - // - // Supply Zones ... - bool allowSupplyZones = AllowSupplyZones(); - int supplyZonesCount = ArraySize(mSupplyZones); - if (allowSupplyZones && - supplyZonesCount < requiredPOIs) - { - // - datetime endTime = cBar.time; - - // - datetime cSupplyZoneStartTime = iTime( - mSymbol, - SupplyZonePeriod(), - supplyZonesCount + 1 // - ); - datetime startTime = cSupplyZoneStartTime; - - // - int cSupplyZoneStartIndex = iBarShift( - mSymbol, - mPeriod, - cSupplyZoneStartTime // - ); - - // - XOHCL swings[]; - for (int i = 0; i < cSupplyZoneStartIndex; i++) - { - // - XOHCL iBar; - bool isIBarInited = iBar.Init( - mSymbol, - mPeriod, - i // - ); - if (!isIBarInited) - { - continue; - } - - // - // Check is Bar Swing or not ... - bool isSwing = iBar.IsSimpleSwingHigh(); - if (!isSwing) - { - continue; - } - - // - AddRef( - iBar, - swings // - ); - } - - // - XOHCL selectedSwing; - int swingsCount = ArraySize(swings); - if (IsValidSize(swingsCount)) - { - // - for (int i = 0; i < swingsCount; i++) - { - // - XOHCL iSwing = swings[i]; - if (!selectedSwing.IsValid() || - selectedSwing.high < iSwing.high) - { - selectedSwing = iSwing; - } - } - } - - // - if (selectedSwing.IsValid()) - { - // - XZone zone; - bool isInited = zone.Init( - selectedSwing.high, - selectedSwing.low, - ToString(X_POI_SUPPLY_ZONE) + "_" + ToString(SupplyZonePeriod()), - startTime, - endTime // - ); - if (isInited) - { - // - AddRef( - zone, - mSupplyZones // - ); - - // - supplyZonesCount = ArraySize(mSupplyZones); - } - } - } - - // - // Demand Zones ... - bool allowDemandZones = AllowDemandZones(); - int demandZonesCount = ArraySize(mDemandZones); - if (allowDemandZones && - demandZonesCount < requiredPOIs) - { - // - datetime endTime = cBar.time; - - // - datetime cDemandZoneStartTime = iTime( - mSymbol, - DemandZonePeriod(), - demandZonesCount + 1 // - ); - datetime startTime = cDemandZoneStartTime; - - // - int cDemandZoneStartIndex = iBarShift( - mSymbol, - mPeriod, - cDemandZoneStartTime // - ); - - // - XOHCL swings[]; - for (int i = 0; i < cDemandZoneStartIndex; i++) - { - // - XOHCL iBar; - bool isIBarInited = iBar.Init( - mSymbol, - mPeriod, - i // - ); - if (!isIBarInited) - { - continue; - } - - // - // Check is Bar Swing or not ... - bool isSwing = iBar.IsSimpleSwingLow(); - if (!isSwing) - { - continue; - } - - // - AddRef( - iBar, - swings // - ); - } - - // - XOHCL selectedSwing; - int swingsCount = ArraySize(swings); - if (IsValidSize(swingsCount)) - { - // - for (int i = 0; i < swingsCount; i++) - { - // - XOHCL iSwing = swings[i]; - if (!selectedSwing.IsValid() || - selectedSwing.low > iSwing.low) - { - selectedSwing = iSwing; - } - } - } - - // - if (selectedSwing.IsValid()) - { - // - XZone zone; - bool isInited = zone.Init( - selectedSwing.high, - selectedSwing.low, - ToString(X_POI_DEMAND_ZONE) + "_" + ToString(DemandZonePeriod()), - startTime, - endTime // - ); - if (isInited) - { - // - AddRef( - zone, - mDemandZones // - ); - - // - demandZonesCount = ArraySize(mDemandZones); - } - } - } - - // - // Order Blocks ... - - // - // Bullish Order Blocks ... - bool allowBullishOrderBlocks = AllowBullishOrderBlocks(); - int bullishOrderBlocksCount = ArraySize(mBullishOrderBlocks); - if (allowBullishOrderBlocks && - bullishOrderBlocksCount < requiredPOIs) - { - // - XOHCL ob; - bool hasOB = cBar.HasBullishOrderBlock( - ob, - RequiredBarsForBullishOrderBlock() // - ); - if (hasOB) - { - // - XZone zone; - bool isAdded = AddZone( - zone, // - ob, - cBar.time, - X_POI_BULLISH_ORDERBLOCK, - mBullishOrderBlocks // - ); - if (isAdded) - { - bullishOrderBlocksCount = ArraySize(mBullishOrderBlocks); - } - } - } - - // - // Bearish Order Blocks ... - bool allowBearishOrderBlocks = AllowBearishOrderBlocks(); - int bearishOrderBlocksCount = ArraySize(mBearishOrderBlocks); - if (allowBearishOrderBlocks && - bearishOrderBlocksCount < requiredPOIs) - { - // - XOHCL ob; - bool hasOB = cBar.HasBearishOrderBlock( - ob, - RequiredBarsForBearishOrderBlock() // - ); - if (hasOB) - { - // - XZone zone; - bool isAdded = AddZone( - zone, // - ob, - cBar.time, - X_POI_BEARISH_ORDERBLOCK, - mBearishOrderBlocks // - ); - if (isAdded) - { - bullishOrderBlocksCount = ArraySize(mBearishOrderBlocks); - } - } - } - - // - // Fair Value Gaps ... - - // - // Bullish FVGs ... - bool allowBullishFVGs = AllowBullishFVGs(); - int bullishFVGsCount = ArraySize(mBullishFVGs); - if (allowBullishFVGs && - bullishFVGsCount < requiredPOIs) - { - // - double upper; - double lower; - datetime start; - datetime end; - bool hasBullishFVG = cBar.HasBullishFVG( - upper, - lower, - start, - end, - BullishFVGForceMiddleBarCheck(), - BullishFVGForceCheckLastBarDirection() // - ); - if (hasBullishFVG) - { - // - XZone zone; - bool isAdded = AddZone( - zone, - upper, - lower, - start, - end, - X_POI_BULLISH_FVG, - mBullishFVGs // - ); - if (isAdded) - { - bullishFVGsCount = ArraySize(mBullishFVGs); - } - } - } - - // - // Bearish FVGs ... - bool allowBearishFVGs = AllowBearishFVGs(); - int bearishFVGsCount = ArraySize(mBearishFVGs); - if (allowBearishFVGs && - bearishFVGsCount < requiredPOIs) - { - // - double upper; - double lower; - datetime start; - datetime end; - bool hasBearishFVG = cBar.HasBearishFVG( - upper, - lower, - start, - end, - BearishFVGForceMiddleBarCheck(), - BearishFVGForceCheckLastBarDirection() // - ); - if (hasBearishFVG) - { - // - XZone zone; - bool isAdded = AddZone( - zone, - upper, - lower, - start, - end, - X_POI_BEARISH_FVG, - mBearishFVGs // - ); - if (isAdded) - { - bearishFVGsCount = ArraySize(mBearishFVGs); - } - } - } - - // - // Detect Required Conditions for Loop ... - // - - // - // Market Sessions Requirements ... - bool isNeedMoreMarketSessions = (!IsValidSize(sessionsCount) - ? true - : marketSessionsCount < (sessionsCount * requiredPOIs)); canContinue = // - // Trade Days ... - (allowTradingDays && - daysCount < requiredPOIs) || + // Swing Highs ... + swingHighsCount < requiredPOIs // - // Market Sessions ... - (allowMarketSessions && - isNeedMoreMarketSessions) || + || // - // Swing High and Low (s) ... - (allowSwingHighs && - swingHighsCount < requiredPOIs) || - (allowSwingLows && - swingLowsCount < requiredPOIs) || - // - // Momentum Bars ... - (allowMomentumBars && - momentumBarsCount < requiredPOIs) || - // - // Rejection Bars ... - (allowRejectionBars && - rejectionBarsCount < requiredPOIs) || - // - // Support and Resistance Zones ... - (allowSupportZones && - supportZonesCount < requiredPOIs) || - (allowResistanceZones && - resistanceZonesCount < requiredPOIs) || - // - // Supply and Demand Zones ... - (allowSupplyZones && - supplyZonesCount < requiredPOIs) || - (allowDemandZones && - demandZonesCount < requiredPOIs) || - // - // Order Blocks ... - (allowBullishOrderBlocks && - bullishOrderBlocksCount < requiredPOIs) || - (allowBearishOrderBlocks && - bearishOrderBlocksCount < requiredPOIs) || - // - // Fair Value Gaps ... - (allowBullishFVGs && - bullishFVGsCount < requiredPOIs) || - (allowBearishFVGs && - bearishFVGsCount < requiredPOIs) + // Swing Lows ... + swingLowsCount < requiredPOIs // ; if (canContinue) @@ -4043,3126 +487,12 @@ class XCPOI : public XSCBaseAlert } // - // int errorArr[]; - // if (canContinue) - // { - // // - // int t = errorArr[5]; - // } - - // - // Complete Calculations ... - - // - // Reverse Trading Days ... - XTradeDay tmpDays[]; - Copy( - mTradingDays, - tmpDays // - ); - Clean(mTradingDays); - ArrayReverse(tmpDays); - Copy( - tmpDays, - mTradingDays // - ); - Clean(tmpDays); - - // - // Reverse Market Sessions ... - XMarketSession tmpSessions[]; - Copy( - mMarketSessions, - tmpSessions // - ); - Clean(mMarketSessions); - ArrayReverse(tmpSessions); - Copy( - tmpSessions, - mMarketSessions // - ); - - // - XOHCL tmpBars[]; - - // - // Reverse Swing Highs ... - Copy( - mSwingHighs, - tmpBars // - ); - Clean(mSwingHighs); - ArrayReverse(tmpBars); - Copy( - tmpBars, - mSwingHighs // - ); - Clean(tmpBars); - - // - // Reverse Swing Lows ... - Copy( - mSwingLows, - tmpBars // - ); - Clean(mSwingLows); - ArrayReverse(tmpBars); - Copy( - tmpBars, - mSwingLows // - ); - Clean(tmpBars); - - // - // Reverse Momentum Bars ... - Copy( - mMomentumBars, - tmpBars // - ); - Clean(mMomentumBars); - ArrayReverse(tmpBars); - Copy( - tmpBars, - mMomentumBars // - ); - Clean(tmpBars); - - // - // Reverse Rejection Bars ... - Copy( - mRejectionBars, - tmpBars // - ); - Clean(mRejectionBars); - ArrayReverse(tmpBars); - Copy( - tmpBars, - mRejectionBars // - ); - Clean(tmpBars); - - // - // Reverse Support Zones ... - Copy( - mSupportZones, - tmpBars // - ); - Clean(mSupportZones); - ArrayReverse(tmpBars); - Copy( - tmpBars, - mSupportZones // - ); - Clean(tmpBars); - - // - // Reverse Resistance Zones ... - Copy( - mResistanceZones, - tmpBars // - ); - Clean(mResistanceZones); - ArrayReverse(tmpBars); - Copy( - tmpBars, - mResistanceZones // - ); - Clean(tmpBars); - - // - XZone tmpZones[]; - - // - // Supply and Demand Zones ... - - // - Copy( - mSupplyZones, - tmpZones // - ); - Clean(mSupplyZones); - ArrayReverse(tmpZones); - Copy( - tmpZones, - mSupplyZones // - ); - Clean(tmpZones); - - // - Copy( - mDemandZones, - tmpZones // - ); - Clean(mDemandZones); - ArrayReverse(tmpZones); - Copy( - tmpZones, - mDemandZones // - ); - Clean(tmpZones); - - // - // Order Blocks ... - - // - Copy( - mBullishOrderBlocks, - tmpZones // - ); - Clean(mBullishOrderBlocks); - ArrayReverse(tmpZones); - Copy( - tmpZones, - mBullishOrderBlocks // - ); - Clean(tmpZones); - - // - Copy( - mBearishOrderBlocks, - tmpZones // - ); - Clean(mBearishOrderBlocks); - ArrayReverse(tmpZones); - Copy( - tmpZones, - mBearishOrderBlocks // - ); - Clean(tmpZones); - - // - // Fair Value Gaps ... - - // - Copy( - mBullishFVGs, - tmpZones // - ); - Clean(mBullishFVGs); - ArrayReverse(tmpZones); - Copy( - tmpZones, - mBullishFVGs // - ); - Clean(tmpZones); - - // - Copy( - mBearishFVGs, - tmpZones // - ); - Clean(mBearishFVGs); - ArrayReverse(tmpZones); - Copy( - tmpZones, - mBearishFVGs // - ); - Clean(tmpZones); - - // - // ... + swingHighsCount = ArraySize(mSwingHighs); + swingLowsCount = ArraySize(mSwingLows); // + // Unlocking Detector ... Unlock(); - DrawPOIs(); - } - - // - // Destroy POIs ... - - /** - * Destroy All POI(s) ... - */ - void DestroyPOIs() - { - // - // Trading Days ... - DestroyTradingDays(); - - // - // Market Sessions ... - DestroyMarketSessions(); - - // - // Momentum Bars ... - DestroyMomentumBars(); - - // - // Rejection Bars ... - DestroyRejectionBars(); - - // - // Swing High and Zone (s) ... - DestroySwingHighs(); - DestroySwingLows(); - - // - // Support and Resistance Zones ... - DestroySupportZones(); - DestroyResistanceZones(); - - // - // Supply and Demand Zones ... - DestroySupplyZones(); - DestroyDemandZones(); - - // - // Order Blocks ... - DestroyBullishOrderBlocks(); - DestroyBearishOrderBlocks(); - - // - // Fai Value Gaps ... - DestroyBullishFVGs(); - DestroyBearishFVGs(); - } - - /** - * Destroy Trading Days ... - */ - void DestroyTradingDays() - { - Clean(mTradingDays); - } - - /** - * Destroy Swing Highs ... - */ - void DestroySwingHighs() - { - Clean(mSwingHighs); - } - - /** - * Destroy Swing Lows ... - */ - void DestroySwingLows() - { - Clean(mSwingLows); - } - - /** - * Destroy Momentum Bars ... - */ - void DestroyMomentumBars() - { - Clean(mMomentumBars); - } - - /** - * Destroy Rejection Bars ... - */ - void DestroyRejectionBars() - { - Clean(mRejectionBars); - } - - /** - * Destroy Market Sessions ... - */ - void DestroyMarketSessions() - { - Clean(mMarketSessions); - } - - /** - * Destroy Support Zones ... - */ - void DestroySupportZones() - { - Clean(mSupportZones); - } - - /** - * Destroy Resistance Zones ... - */ - void DestroyResistanceZones() - { - Clean(mResistanceZones); - } - - /** - * Destroy Supply Zones ... - */ - void DestroySupplyZones() - { - Clean(mSupplyZones); - } - - /** - * Destroy Demand Zones ... - */ - void DestroyDemandZones() - { - Clean(mDemandZones); - } - - /** - * Destroy Bullish Order Blocks ... - */ - void DestroyBullishOrderBlocks() - { - Clean(mBullishOrderBlocks); - } - - /** - * Destroy Bearish Order Blocks ... - */ - void DestroyBearishOrderBlocks() - { - Clean(mBearishOrderBlocks); - } - - /** - * Destroy Bullish FVGs ... - */ - void DestroyBullishFVGs() - { - Clean(mBullishFVGs); - } - - /** - * Destroy Bearish FVGs ... - */ - void DestroyBearishFVGs() - { - Clean(mBearishFVGs); - } - - // - // Draw Actions ... - - /** - * Draw All POI(s) ... - */ - void DrawPOIs() - { - // - // Trading Days ... - DrawTradingDays(); - - // - // Market Sessions ... - DrawMarketSessions(); - - // - // Momentum Bars ... - DrawMomentumBars(); - - // - // Rejection Bars ... - DrawRejectionBars(); - - // - // Swing High and Low (s) ... - DrawSwingHighs(); - DrawSwingLows(); - - // - // Support and Resistance (s) ... - DrawSupportZones(); - DrawResistanceZones(); - - // - // Supply and Demand Zones ... - DrawSupplyZones(); - DrawDemandZones(); - - // - // Order Blocks ... - DrawBullishOrderBlocks(); - DrawBearishOrderBlocks(); - - // - // Fair Value Gaps ... - DrawBullishFVGs(); - DrawBearishFVGs(); - } - - /** - * Draw Trading Days ... - */ - void DrawTradingDays() - { - // - bool allow = AllowDrawTradingDays(); - if (!allow) - { - return; - } - - // - int count = ArraySize(mTradingDays); - if (!IsValidSize(count)) - { - return; - } - - // - for (int i = 0; i < count; i++) - { - // - XTradeDay iDay = mTradingDays[i]; - - // - string iName = iDay.GetTag(); - int iIDX = HasTradingDayObject( - iName // - ); - if (IsValidIndex(iIDX)) - { - continue; - } - - // - CreateTradingDayObject(iDay, iName); - } - } - - /** - * Check a Trading Day is Drawn Before or not ... - * - * @param name: String ... - * - * @return ( int ) - */ - int HasTradingDayObject( - string name // - ) - { - // - int result = -1; - - // - if (!IsValid(name)) - { - return result; - } - - // - int count = mTradingDayObjects.Total(); - if (!IsValidSize(count)) - { - return result; - } - - // - for (int i = 0; i < count; i++) - { - // - string objName = ((XCBaseObject *)mTradingDayObjects.At(i)).ObjName(); - if (objName == name) - { - // - result = i; - break; - } - } - - // - return result; - } - - /** - * Draw Swing Highs ... - */ - void DrawSwingHighs() - { - // - bool allow = AllowDrawSwingHighs(); - if (!allow) - { - return; - } - - // - int count = ArraySize(mSwingHighs); - if (!IsValidSize(count)) - { - return; - } - - // - for (int i = 0; i < count; i++) - { - // - XOHCL iSwing = mSwingHighs[i]; - - // - string iName = iSwing.GetTag(ToString(X_POI_SWING_HIGH)); - int iIDX = HasSwingHighObject( - iName // - ); - if (IsValidIndex(iIDX)) - { - continue; - } - - // - bool allow = AllowDrawSwingHighs(); - if (allow) - { - // - XCSwingHighObject *iObj; - bool isCreated = mDrawer.CreateSwingHigh(iSwing, iObj); - if (isCreated) - { - mSwingHighObjects.Add(iObj); - } - } - } - } - - /** - * Check a Swing High is Drawn Before or not ... - * - * @param name: String ... - * - * @return ( int ) - */ - int HasSwingHighObject( - string name // - ) - { - // - int result = -1; - - // - if (!IsValid(name)) - { - return result; - } - - // - int count = mSwingHighObjects.Total(); - if (!IsValidSize(count)) - { - return result; - } - - // - for (int i = 0; i < count; i++) - { - // - string objName = ((CChartObjectArrow *)mSwingHighObjects.At(i)).Name(); - if (objName == name) - { - // - result = i; - break; - } - } - - // - return result; - } - - /** - * Draw Swing Lows ... - */ - void DrawSwingLows() - { - // - bool allow = AllowDrawSwingLows(); - if (!allow) - { - return; - } - - // - int count = ArraySize(mSwingLows); - if (!IsValidSize(count)) - { - return; - } - - // - for (int i = 0; i < count; i++) - { - // - XOHCL iSwing = mSwingLows[i]; - - // - string iName = iSwing.GetTag(ToString(X_POI_SWING_LOW)); - int iIDX = HasSwingLowObject( - iName // - ); - if (IsValidIndex(iIDX)) - { - continue; - } - - // - bool allow = AllowDrawSwingLows(); - if (allow) - { - // - XCSwingLowObject *iObj; - bool isCreated = mDrawer.CreateSwingLow(iSwing, iObj); - if (isCreated) - { - mSwingLowObjects.Add(iObj); - } - } - } - } - - /** - * Check a Swing Low is Drawn Before or not ... - * - * @param name: String ... - * - * @return ( int ) - */ - int HasSwingLowObject( - string name // - ) - { - // - int result = -1; - - // - if (!IsValid(name)) - { - return result; - } - - // - int count = mSwingLowObjects.Total(); - if (!IsValidSize(count)) - { - return result; - } - - // - for (int i = 0; i < count; i++) - { - // - string objName = ((CChartObjectArrow *)mSwingLowObjects.At(i)).Name(); - if (objName == name) - { - // - result = i; - break; - } - } - - // - return result; - } - - /** - * Draw Momentum Bars ... - */ - void DrawMomentumBars() - { - // - bool allow = AllowDrawMomentumBars(); - if (!allow) - { - return; - } - - // - int count = ArraySize(mMomentumBars); - if (!IsValidSize(count)) - { - return; - } - - // - for (int i = 0; i < count; i++) - { - // - XOHCL iBar = mMomentumBars[i]; - - // - string iName = iBar.GetTag(ToString(X_POI_MOMENTUM_BAR)); - int iIDX = HasMomentumBarObject( - iName // - ); - if (IsValidIndex(iIDX)) - { - continue; - } - - // - bool allow = AllowDrawMomentumBars(); - if (allow) - { - // - bool isBullish = iBar.IsBullish(); - if (isBullish) - { - // - XCBullishMomentumBarObject *iObj; - bool isCreated = mDrawer.CreateBullishMomentumBar(iBar, iObj); - if (isCreated) - { - mMomentumBarObjects.Add(iObj); - } - } - else - { - // - XCBearishMomentumBarObject *iObj; - bool isCreated = mDrawer.CreateBearishMomentumBar(iBar, iObj); - if (isCreated) - { - mMomentumBarObjects.Add(iObj); - } - } - } - } - } - - /** - * Check a Momentum Bar is Drawn Before or not ... - * - * @param name: String ... - * - * @return ( int ) - */ - int HasMomentumBarObject( - string name // - ) - { - // - int result = -1; - - // - if (!IsValid(name)) - { - return result; - } - - // - int count = mMomentumBarObjects.Total(); - if (!IsValidSize(count)) - { - return result; - } - - // - for (int i = 0; i < count; i++) - { - // - string objName = ((CChartObjectArrow *)mMomentumBarObjects.At(i)).Name(); - if (objName == name) - { - // - result = i; - break; - } - } - - // - return result; - } - - /** - * Draw Rejection Bars ... - */ - void DrawRejectionBars() - { - // - bool allow = AllowDrawRejectionBars(); - if (!allow) - { - return; - } - - // - int count = ArraySize(mRejectionBars); - if (!IsValidSize(count)) - { - return; - } - - // - for (int i = 0; i < count; i++) - { - // - XOHCL iBar = mRejectionBars[i]; - - // - string iName = iBar.GetTag(ToString(X_POI_REJECTION_BAR)); - int iIDX = HasRejectionBarObject( - iName // - ); - if (IsValidIndex(iIDX)) - { - continue; - } - - // - bool allow = AllowDrawRejectionBars(); - if (allow) - { - // - bool isBullish = iBar.GetLowShadow() > iBar.GetHighShadow(); - if (isBullish) - { - // - XCBullishRejectionBarObject *iObj; - bool isCreated = mDrawer.CreateBullishRejectionBar(iBar, iObj); - if (isCreated) - { - mRejectionBarObjects.Add(iObj); - } - } - else - { - // - XCBearishRejectionBarObject *iObj; - bool isCreated = mDrawer.CreateBearishRejectionBar(iBar, iObj); - if (isCreated) - { - mRejectionBarObjects.Add(iObj); - } - } - } - } - } - - /** - * Check a Rejection Bar is Drawn Before or not ... - * - * @param name: String ... - * - * @return ( int ) - */ - int HasRejectionBarObject( - string name // - ) - { - // - int result = -1; - - // - if (!IsValid(name)) - { - return result; - } - - // - int count = mRejectionBarObjects.Total(); - if (!IsValidSize(count)) - { - return result; - } - - // - for (int i = 0; i < count; i++) - { - // - string objName = ((CChartObjectArrow *)mRejectionBarObjects.At(i)).Name(); - if (objName == name) - { - // - result = i; - break; - } - } - - // - return result; - } - - /** - * Draw Market Sessions ... - */ - void DrawMarketSessions() - { - // - bool allow = AllowDrawMarketSessions(); - if (!allow) - { - return; - } - - // - int count = ArraySize(mMarketSessions); - if (!IsValidSize(count)) - { - return; - } - - // - for (int i = 0; i < count; i++) - { - // - XMarketSession iMarketSession = mMarketSessions[i]; - - // - string iName = iMarketSession.GetTag(); - int iIDX = HasMarketessionObject( - iName // - ); - if (IsValidIndex(iIDX)) - { - continue; - } - - // - // CreateMarketSessionObject(iMarketSession, iName); - } - } - - /** - * Check a Market Session is Drawn Before or not ... - * - * @param name: String ... - * - * @return ( int ) - */ - int HasMarketessionObject( - string name // - ) - { - // - int result = -1; - - // - if (!IsValid(name)) - { - return result; - } - - // - int count = mMarketSessionObjects.Total(); - if (!IsValidSize(count)) - { - return result; - } - - // - for (int i = 0; i < count; i++) - { - // - string objName = ((XCMarketSessionObject *)mMarketSessionObjects.At(i)).ObjName(); - if (objName == name) - { - // - result = i; - break; - } - } - - // - return result; - } - - /** - * Draw Support Zones ... - */ - void DrawSupportZones() - { - // - bool allow = AllowDrawSupportZones(); - if (!allow) - { - return; - } - - // - int count = ArraySize(mSupportZones); - if (!IsValidSize(count)) - { - return; - } - - // - for (int i = 0; i < count; i++) - { - // - XOHCL iSupportZone = mSupportZones[i]; - - // - string iName = iSupportZone.GetTag(ToString(X_POI_SUPPORT_ZONE)); - int iIDX = HasSupportZoneObject( - iName // - ); - if (IsValidIndex(iIDX)) - { - continue; - } - - // - bool allow = AllowDrawSupportZones(); - if (allow) - { - // - XCSupportZoneObject *iObj; - bool isCreated = mDrawer.CreateSupportZone(iSupportZone, iObj); - if (isCreated) - { - mSupportZoneObjects.Add(iObj); - } - } - } - } - - /** - * Check a Suport Zone is Drawn Before or not ... - * - * @param name: String ... - * - * @return ( int ) - */ - int HasSupportZoneObject( - string name // - ) - { - // - int result = -1; - - // - if (!IsValid(name)) - { - return result; - } - - // - int count = mSupportZoneObjects.Total(); - if (!IsValidSize(count)) - { - return result; - } - - // - for (int i = 0; i < count; i++) - { - // - string objName = ((XCSupportZoneObject *)mSupportZoneObjects.At(i)).ObjName(); - if (objName == name) - { - // - result = i; - break; - } - } - - // - return result; - } - - /** - * Draw Resistance Zones ... - */ - void DrawResistanceZones() - { - // - bool allow = AllowDrawResistanceZones(); - if (!allow) - { - return; - } - - // - int count = ArraySize(mResistanceZones); - if (!IsValidSize(count)) - { - return; - } - - // - for (int i = 0; i < count; i++) - { - // - XOHCL iResistanceZone = mResistanceZones[i]; - - // - string iName = iResistanceZone.GetTag(ToString(X_POI_RESISTANCE_ZONE)); - int iIDX = HasResistanceZoneObject( - iName // - ); - if (IsValidIndex(iIDX)) - { - continue; - } - - // - bool allow = AllowDrawResistanceZones(); - if (allow) - { - // - XCResistanceZoneObject *iObj; - bool isCreated = mDrawer.CreateResistanceZone(iResistanceZone, iObj); - if (isCreated) - { - mResistanceZoneObjects.Add(iObj); - } - } - } - } - - /** - * Check a Resistance Zone is Drawn Before or not ... - * - * @param name: String ... - * - * @return ( int ) - */ - int HasResistanceZoneObject( - string name // - ) - { - // - int result = -1; - - // - if (!IsValid(name)) - { - return result; - } - - // - int count = mResistanceZoneObjects.Total(); - if (!IsValidSize(count)) - { - return result; - } - - // - for (int i = 0; i < count; i++) - { - // - string objName = ((XCResistanceZoneObject *)mResistanceZoneObjects.At(i)).ObjName(); - if (objName == name) - { - // - result = i; - break; - } - } - - // - return result; - } - - /** - * Draw Supply Zones ... - */ - void DrawSupplyZones() - { - // - bool allow = AllowDrawSupplyZones(); - if (!allow) - { - return; - } - - // - int count = ArraySize(mSupplyZones); - if (!IsValidSize(count)) - { - return; - } - - // - for (int i = 0; i < count; i++) - { - // - XZone iSupplyZone = mSupplyZones[i]; - - // - string iName = iSupplyZone.GetTag(); - int iIDX = HasSupplyZoneObject( - iName // - ); - if (IsValidIndex(iIDX)) - { - continue; - } - - // - bool allow = AllowDrawSupplyZones(); - if (allow) - { - // - XCSupplyZoneObject *iObj; - bool isCreated = mDrawer.CreateSupplyZone(iSupplyZone, iObj); - if (isCreated) - { - mSupplyZoneObjects.Add(iObj); - } - } - } - } - - /** - * Check a Supply Zone is Drawn Before or not ... - * - * @param name: String ... - * - * @return ( int ) - */ - int HasSupplyZoneObject( - string name // - ) - { - // - int result = -1; - - // - if (!IsValid(name)) - { - return result; - } - - // - int count = mSupplyZoneObjects.Total(); - if (!IsValidSize(count)) - { - return result; - } - - // - for (int i = 0; i < count; i++) - { - // - string objName = ((XCSupplyZoneObject *)mSupplyZoneObjects.At(i)).ObjName(); - if (objName == name) - { - // - result = i; - break; - } - } - - // - return result; - } - - /** - * Draw Demand Zones ... - */ - void DrawDemandZones() - { - // - bool allow = AllowDrawDemandZones(); - if (!allow) - { - return; - } - - // - int count = ArraySize(mDemandZones); - if (!IsValidSize(count)) - { - return; - } - - // - for (int i = 0; i < count; i++) - { - // - XZone iDemandZone = mDemandZones[i]; - - // - string iName = iDemandZone.GetTag(); - int iIDX = HasDemandZoneObject( - iName // - ); - if (IsValidIndex(iIDX)) - { - continue; - } - - // - bool allow = AllowDrawDemandZones(); - if (allow) - { - // - XCDemandZoneObject *iObj; - bool isCreated = mDrawer.CreateDemandZone(iDemandZone, iObj); - if (isCreated) - { - mDemandZoneObjects.Add(iObj); - } - } - } - } - - /** - * Check a Demand Zone is Drawn Before or not ... - * - * @param name: String ... - * - * @return ( int ) - */ - int HasDemandZoneObject( - string name // - ) - { - // - int result = -1; - - // - if (!IsValid(name)) - { - return result; - } - - // - int count = mDemandZoneObjects.Total(); - if (!IsValidSize(count)) - { - return result; - } - - // - for (int i = 0; i < count; i++) - { - // - string objName = ((XCDemandZoneObject *)mDemandZoneObjects.At(i)).ObjName(); - if (objName == name) - { - // - result = i; - break; - } - } - - // - return result; - } - - /** - * Draw Bullish Order Blocks ... - */ - void DrawBullishOrderBlocks() - { - // - bool allow = AllowDrawBullishOrderBlocks(); - if (!allow) - { - return; - } - - // - int count = ArraySize(mBullishOrderBlocks); - if (!IsValidSize(count)) - { - return; - } - - // - for (int i = 0; i < count; i++) - { - // - XZone iBullishOB = mBullishOrderBlocks[i]; - - // - string iName = iBullishOB.GetTag(); - int iIDX = HasBullishOrderBlockObject( - iName // - ); - if (IsValidIndex(iIDX)) - { - continue; - } - - // - bool allow = AllowDrawBullishOrderBlocks(); - if (allow) - { - // - XCBullishOrderBlockObject *iObj; - bool isCreated = mDrawer.CreateBullishOrderBlock(iBullishOB, iObj); - if (isCreated) - { - mBullishOrderBlockObjects.Add(iObj); - } - } - } - } - - /** - * Check a Bullish Order Block is Drawn Before or not ... - * - * @param name: String ... - * - * @return ( int ) - */ - int HasBullishOrderBlockObject( - string name // - ) - { - // - int result = -1; - - // - if (!IsValid(name)) - { - return result; - } - - // - int count = mBullishOrderBlockObjects.Total(); - if (!IsValidSize(count)) - { - return result; - } - - // - for (int i = 0; i < count; i++) - { - // - string objName = ((XCBullishOrderBlockObject *)mBullishOrderBlockObjects.At(i)).ObjName(); - if (objName == name) - { - // - result = i; - break; - } - } - - // - return result; - } - - /** - * Draw Bearish Order Blocks ... - */ - void DrawBearishOrderBlocks() - { - // - bool allow = AllowDrawBearishOrderBlocks(); - if (!allow) - { - return; - } - - // - int count = ArraySize(mBearishOrderBlocks); - if (!IsValidSize(count)) - { - return; - } - - // - for (int i = 0; i < count; i++) - { - // - XZone iBearishOB = mBearishOrderBlocks[i]; - - // - string iName = iBearishOB.GetTag(); - int iIDX = HasBearishOrderBlockObject( - iName // - ); - if (IsValidIndex(iIDX)) - { - continue; - } - - // - bool allow = AllowDrawBearishOrderBlocks(); - if (allow) - { - // - XCBearishOrderBlockObject *iObj; - bool isCreated = mDrawer.CreateBearishOrderBlock(iBearishOB, iObj); - if (isCreated) - { - mBearishOrderBlockObjects.Add(iObj); - } - } - } - } - - /** - * Check a Bearish Order Block is Drawn Before or not ... - * - * @param name: String ... - * - * @return ( int ) - */ - int HasBearishOrderBlockObject( - string name // - ) - { - // - int result = -1; - - // - if (!IsValid(name)) - { - return result; - } - - // - int count = mBearishOrderBlockObjects.Total(); - if (!IsValidSize(count)) - { - return result; - } - - // - for (int i = 0; i < count; i++) - { - // - string objName = ((XCBearishOrderBlockObject *)mBearishOrderBlockObjects.At(i)).ObjName(); - if (objName == name) - { - // - result = i; - break; - } - } - - // - return result; - } - - /** - * Draw Bullish FVGs ... - */ - void DrawBullishFVGs() - { - // - bool allow = AllowDrawBullishFVGs(); - if (!allow) - { - return; - } - - // - int count = ArraySize(mBullishFVGs); - if (!IsValidSize(count)) - { - return; - } - - // - for (int i = 0; i < count; i++) - { - // - XZone iFVG = mBullishFVGs[i]; - - // - string iName = iFVG.GetTag(); - int iIDX = HasBullishFVGObject( - iName // - ); - if (IsValidIndex(iIDX)) - { - continue; - } - - // - bool allow = AllowDrawBullishFVGs(); - if (allow) - { - // - XCBullishFVGObject *iObj; - bool isCreated = mDrawer.CreateBullishFVG(iFVG, iObj); - if (isCreated) - { - mBullishFVGObjects.Add(iObj); - } - } - } - } - - /** - * Check a Bullish FVG is Drawn Before or not ... - * - * @param name: String ... - * - * @return ( int ) - */ - int HasBullishFVGObject( - string name // - ) - { - // - int result = -1; - - // - if (!IsValid(name)) - { - return result; - } - - // - int count = mBullishFVGObjects.Total(); - if (!IsValidSize(count)) - { - return result; - } - - // - for (int i = 0; i < count; i++) - { - // - string objName = ((XCBullishFVGObject *)mBullishFVGObjects.At(i)).ObjName(); - if (objName == name) - { - // - result = i; - break; - } - } - - // - return result; - } - - /** - * Draw Bearish FVGs ... - */ - void DrawBearishFVGs() - { - // - bool allow = AllowDrawBearishFVGs(); - if (!allow) - { - return; - } - - // - int count = ArraySize(mBearishFVGs); - if (!IsValidSize(count)) - { - return; - } - - // - for (int i = 0; i < count; i++) - { - // - XZone iFVG = mBearishFVGs[i]; - - // - string iName = iFVG.GetTag(); - int iIDX = HasBearishFVGObject( - iName // - ); - if (IsValidIndex(iIDX)) - { - continue; - } - - // - bool allow = AllowDrawBearishFVGs(); - if (allow) - { - // - XCBearishFVGObject *iObj; - bool isCreated = mDrawer.CreateBearishFVG(iFVG, iObj); - if (isCreated) - { - mBearishFVGObjects.Add(iObj); - } - } - } - } - - /** - * Check a Bearish FVG is Drawn Before or not ... - * - * @param name: String ... - * - * @return ( int ) - */ - int HasBearishFVGObject( - string name // - ) - { - // - int result = -1; - - // - if (!IsValid(name)) - { - return result; - } - - // - int count = mBearishFVGObjects.Total(); - if (!IsValidSize(count)) - { - return result; - } - - // - for (int i = 0; i < count; i++) - { - // - string objName = ((XCBearishFVGObject *)mBearishFVGObjects.At(i)).ObjName(); - if (objName == name) - { - // - result = i; - break; - } - } - - // - return result; - } - - // - - /** - * Clean All Drawn Objects ... - */ - void DestroyObjects() - { - // - // Trading Days ... - DestroyTradingTradingDayObjects(); - - // - // Market Sessions ... - DestroyMarketSessionObjects(); - - // - // Momentum Bars ... - DestroyMomentumBarObjects(); - - // - // Rejection Bars ... - DestroyRejectionBarObjects(); - - // - // Swing High and Low (s) ... - DestroySwingLowObjects(); - DestroySwingHighObjects(); - - // - // Support and Resistanc (s) ... - DestroySupportZoneObjects(); - DestroyResistanceZoneObjects(); - - // - // Supply and Demand Zones .. - DestroySupplyZoneObjects(); - DestroyDemandZoneObjects(); - - // - // Order Blocks ... - DestroyBullishOrderBlockObjects(); - DestroyBearishOrderBlockObjects(); - - // - // Fair Value Gaps ... - DestroyBullishFVGObjects(); - DestroyBearishFVGObjects(); - } - - /** - * Clean Swing Highs Drawn Objects ... - */ - void DestroySwingHighObjects() - { - mSwingHighObjects.Clear(); - } - - /** - * Clean Swing Lows Drawn Objects ... - */ - void DestroySwingLowObjects() - { - mSwingLowObjects.Clear(); - } - - /** - * Clean Momentum Bars Drawn Objects ... - */ - void DestroyMomentumBarObjects() - { - mMomentumBarObjects.Clear(); - } - - /** - * Clean Rejection Bars Drawn Objects ... - */ - void DestroyRejectionBarObjects() - { - mRejectionBarObjects.Clear(); - } - - /** - * Clean Trading Day Drawn Objects ... - */ - void DestroyTradingTradingDayObjects() - { - mTradingDayObjects.Clear(); - } - - /** - * Destroy Market Sessions Drawn Objects ... - */ - void DestroyMarketSessionObjects() - { - mMarketSessionObjects.Clear(); - } - - /** - * Destroy Support Zone Drawn Objects ... - */ - void DestroySupportZoneObjects() - { - mSupportZoneObjects.Clear(); - } - - /** - * Destroy Resistance Zone Drawn Objects ... - */ - void DestroyResistanceZoneObjects() - { - mResistanceZoneObjects.Clear(); - } - - /** - * Destroy Supply Zone Drawn Objects ... - */ - void DestroySupplyZoneObjects() - { - mSupplyZoneObjects.Clear(); - } - - /** - * Destroy Demand Zone Drawn Objects ... - */ - void DestroyDemandZoneObjects() - { - mDemandZoneObjects.Clear(); - } - - /** - * Destroy Bullish Order Block Drawn Objects ... - */ - void DestroyBullishOrderBlockObjects() - { - mBullishOrderBlockObjects.Clear(); - } - - /** - * Destroy Bearish Order Block Drawn Objects ... - */ - void DestroyBearishOrderBlockObjects() - { - mBearishOrderBlockObjects.Clear(); - } - - /** - * Destroy Bullish FVG Drawn Objects ... - */ - void DestroyBullishFVGObjects() - { - mBullishFVGObjects.Clear(); - } - - /** - * Destroy Bearish FVG Drawn Objects ... - */ - void DestroyBearishFVGObjects() - { - mBearishFVGObjects.Clear(); - } - - // - // ... - - /** - * Detect an Object Exists in Array or not ... - * - * @param name: String ... - * @param array: CArrayObj instance ... - * - * @return ( int ): index of Object ... - */ - int HasObject( - string name, - CArrayObj &array // - ) - { - // - int result = -1; - - // - if (!IsValid(name)) - { - return result; - } - - // - int count = array.Total(); - if (!IsValidSize(count)) - { - return result; - } - - // - for (int i = 0; i < count; i++) - { - // - // XCBaseObject *iObj = ((XCBaseObject *)array.At(i)); - // string objName = iObj.ObjName(); - // if (objName == name) - // { - // // - // result = i; - // break; - // } - } - - // - return result; - } - - // - // Event Handler Notifiers ... - - // - // Trading Days ... - - /** - * Notify New Trading Day Event Handlers ... - * - * @param event: ENUM_XPOI_EVENTS member ... - */ - void NotifyTradingDayEventListeners( - ENUM_XPOI_EVENTS event // - ) - { - // - int count = ArraySize(mTradingDayEventListeners); - if (!IsValidSize(count)) - { - return; - } - - // - for (int i = 0; i < count; i++) - { - // - TXPOIEventHandler iListener = mTradingDayEventListeners[i]; - iListener(event); - } - } - - // - // Market Sessions ... - - /** - * Notify New Market Session Event Handlers ... - * - * @param session: ENUM_XSESSION member ... - * @param event: ENUM_XPOI_EVENTS member ... - */ - void NotifyMarketSessionEventListeners( - ENUM_XSESSION session, - ENUM_XPOI_EVENTS event // - ) - { - // - int count = ArraySize(mMarketSessionEventListeners); - if (!IsValidSize(count)) - { - return; - } - - // - for (int i = 0; i < count; i++) - { - // - TXSessionEventHandler iListener = mMarketSessionEventListeners[i]; - iListener(session, event); - } - } - - // - // Swings ... - - // - // Swing Highs ... - - /** - * Notify New Swing High Point Event Handlers ... - * - * @param event: ENUM_XPOI_EVENTS member ... - * @param bar: XOHCL instance ... - */ - void NotifySwingHighEventListeners( - ENUM_XPOI_EVENTS event, - XOHCL &bar // - ) - { - // - if (!bar.IsValid()) - { - return; - } - - // - int count = ArraySize(mSwingHighEventListeners); - if (!IsValidSize(count)) - { - return; - } - - // - for (int i = 0; i < count; i++) - { - // - TXOHCLEventHandler iListener = mSwingHighEventListeners[i]; - iListener(event, bar); - } - } - - // - // Swing Lows ... - - /** - * Notify New Swing Low Point Event Handlers ... - * - * @param event: ENUM_XPOI_EVENTS member ... - * @param bar: XOHCL instance ... - */ - void NotifySwingLowEventListeners( - ENUM_XPOI_EVENTS event, - XOHCL &bar // - ) - { - // - if (!bar.IsValid()) - { - return; - } - - // - int count = ArraySize(mSwingLowEventListeners); - if (!IsValidSize(count)) - { - return; - } - - // - for (int i = 0; i < count; i++) - { - // - TXOHCLEventHandler iListener = mSwingLowEventListeners[i]; - iListener(event, bar); - } - } - - // - // Momentum Bars ... - - /** - * Notify New Momentum Bar Event Handlers ... - * - * @param event: ENUM_XPOI_EVENTS member ... - * @param bar: XOHCL instance ... - */ - void NotifyMomentumBarEventListeners( - ENUM_XPOI_EVENTS event, - XOHCL &bar // - ) - { - // - if (!bar.IsValid()) - { - return; - } - - // - int count = ArraySize(mMomentumBarEventListeners); - if (!IsValidSize(count)) - { - return; - } - - // - for (int i = 0; i < count; i++) - { - // - TXOHCLEventHandler iListener = mMomentumBarEventListeners[i]; - iListener(event, bar); - } - } - - // - // Rejection Bars ... - - /** - * Notify New Rejection Bar Event Handlers ... - * - * @param event: ENUM_XPOI_EVENTS member ... - * @param bar: XOHCL instance ... - */ - void NotifyRejectionBarEventListeners( - ENUM_XPOI_EVENTS event, - XOHCL &bar // - ) - { - // - if (!bar.IsValid()) - { - return; - } - - // - int count = ArraySize(mRejectionBarEventListeners); - if (!IsValidSize(count)) - { - return; - } - - // - for (int i = 0; i < count; i++) - { - // - TXOHCLEventHandler iListener = mRejectionBarEventListeners[i]; - iListener(event, bar); - } - } - - // - // Support and Resistance Zones ... - - // - // Support Zones ... - - /** - * Notify New Support Zone Event Handlers ... - * - * @param event: ENUM_XPOI_EVENTS member ... - * @param bar: XOHCL instance ... - */ - void NotifySupportZoneEventListeners( - ENUM_XPOI_EVENTS event, - XOHCL &bar // - ) - { - // - if (!bar.IsValid()) - { - return; - } - - // - int count = ArraySize(mSupportZoneEventListeners); - if (!IsValidSize(count)) - { - return; - } - - // - for (int i = 0; i < count; i++) - { - // - TXOHCLEventHandler iListener = mSupportZoneEventListeners[i]; - iListener(event, bar); - } - } - - // - // Resistance Zones ... - - /** - * Notify New Resistance Zone Event Handlers ... - * - * @param event: ENUM_XPOI_EVENTS member ... - * @param bar: XOHCL instance ... - */ - void NotifyResistanceZoneEventListeners( - ENUM_XPOI_EVENTS event, - XOHCL &bar // - ) - { - // - if (!bar.IsValid()) - { - return; - } - - // - int count = ArraySize(mResistanceZoneEventListeners); - if (!IsValidSize(count)) - { - return; - } - - // - for (int i = 0; i < count; i++) - { - // - TXOHCLEventHandler iListener = mResistanceZoneEventListeners[i]; - iListener(event, bar); - } - } - - // - // Supply and Demand Zones ... - - // - // Supply Zones ... - - /** - * Notify New Supply Zone Event Handlers ... - * - * @param event: ENUM_XPOI_EVENTS member ... - * @param bar: XZone instance ... - */ - void NotifySupplyZoneEventListeners( - ENUM_XPOI_EVENTS event, - XZone &zone // - ) - { - // - if (!zone.IsValid()) - { - return; - } - - // - int count = ArraySize(mSupplyZoneEventListeners); - if (!IsValidSize(count)) - { - return; - } - - // - for (int i = 0; i < count; i++) - { - // - TXZoneEventHandler iListener = mSupplyZoneEventListeners[i]; - iListener(event, zone); - } - } - - // - // Demand Zones ... - - /** - * Notify New Demand Zone Event Handlers ... - * - * @param event: ENUM_XPOI_EVENTS member ... - * @param bar: XZone instance ... - */ - void NotifyDemandZoneEventListeners( - ENUM_XPOI_EVENTS event, - XZone &zone // - ) - { - // - if (!zone.IsValid()) - { - return; - } - - // - int count = ArraySize(mDemandZoneEventListeners); - if (!IsValidSize(count)) - { - return; - } - - // - for (int i = 0; i < count; i++) - { - // - TXZoneEventHandler iListener = mDemandZoneEventListeners[i]; - iListener(event, zone); - } - } - - // - // Order Blocks ... - - // - // Bullish Order Blocks ... - - /** - * Notify New Bullish Order Block Event Handlers ... - * - * @param event: ENUM_XPOI_EVENTS member ... - * @param bar: XZone instance ... - */ - void NotifyBullishOrderBlockEventListeners( - ENUM_XPOI_EVENTS event, - XZone &zone // - ) - { - // - if (!zone.IsValid()) - { - return; - } - - // - int count = ArraySize(mBullishOrderBlockEventListeners); - if (!IsValidSize(count)) - { - return; - } - - // - for (int i = 0; i < count; i++) - { - // - TXZoneEventHandler iListener = mBullishOrderBlockEventListeners[i]; - iListener(event, zone); - } - } - - // - // Bearish Order Blocks ... - - /** - * Notify New Bearish Order Block Event Handlers ... - * - * @param event: ENUM_XPOI_EVENTS member ... - * @param bar: XZone instance ... - */ - void NotifyBearishOrderBlockEventListeners( - ENUM_XPOI_EVENTS event, - XZone &zone // - ) - { - // - if (!zone.IsValid()) - { - return; - } - - // - int count = ArraySize(mBearishOrderBlockEventListeners); - if (!IsValidSize(count)) - { - return; - } - - // - for (int i = 0; i < count; i++) - { - // - TXZoneEventHandler iListener = mBearishOrderBlockEventListeners[i]; - iListener(event, zone); - } - } - - // - // Fair Value Gaps ... - - /** - * Notify New Bullish FVG Event Handlers ... - * - * @param event: ENUM_XPOI_EVENTS member ... - * @param bar: XZone instance ... - */ - void NotifyBullishFVGEventListeners( - ENUM_XPOI_EVENTS event, - XZone &zone // - ) - { - // - if (!zone.IsValid()) - { - return; - } - - // - int count = ArraySize(mBullishFVGEventListeners); - if (!IsValidSize(count)) - { - return; - } - - // - for (int i = 0; i < count; i++) - { - // - TXZoneEventHandler iListener = mBullishFVGEventListeners[i]; - iListener(event, zone); - } - } - - /** - * Notify New Bearish FVG Event Handlers ... - * - * @param event: ENUM_XPOI_EVENTS member ... - * @param bar: XZone instance ... - */ - void NotifyBearishFVGEventListeners( - ENUM_XPOI_EVENTS event, - XZone &zone // - ) - { - // - if (!zone.IsValid()) - { - return; - } - - // - int count = ArraySize(mBearishFVGEventListeners); - if (!IsValidSize(count)) - { - return; - } - - // - for (int i = 0; i < count; i++) - { - // - TXZoneEventHandler iListener = mBearishFVGEventListeners[i]; - iListener(event, zone); - } - } - - /** - * Destroy all Registered Event Listeners ... - */ - void DestroyEventListeners() - { - // - // Trading Days ... - Clean(mTradingDayEventListeners); - - // - // Market Sessions ... - Clean(mMarketSessionEventListeners); - - // - // Momentum Bars ... - Clean(mMomentumBarEventListeners); - - // - // Rejection Bars ... - Clean(mRejectionBarEventListeners); - - // - // Swing High and Low (s) ... - Clean(mSwingLowEventListeners); - Clean(mSwingHighEventListeners); - - // - // Support and Resistance Zones ... - Clean(mSupportZoneEventListeners); - Clean(mResistanceZoneEventListeners); - - // - // Supply and Demand Zones ... - Clean(mSupplyZoneEventListeners); - Clean(mDemandZoneEventListeners); - - // - // Order Blocks ... - Clean(mBullishOrderBlockEventListeners); - Clean(mBearishOrderBlockEventListeners); - - // - // Fair Value Gaps ... - Clean(mBullishFVGEventListeners); - Clean(mBearishFVGEventListeners); - } - - // - // ... - // - - // - // Session ... - - /** - * Find Specific Session Index ... - * - * @param session: ENUM_XSESSION member ... - * - * @return ( int ) - */ - int FindSession(ENUM_XSESSION session) - { - // - int result = -1; - - // - int count = ArraySize(mSessions); - if (!IsValidSize(count)) - { - return result; - } - - // - for (int i = 0; i < count; i++) - { - // - XSession iSession = mSessions[i]; - - // - if (iSession.session == session) - { - // - result = i; - break; - } - } - - // - return result; - } - - /** - * Destroy Sessions ... - */ - void DestroySessions() - { - Clean(mSessions); - } - - /** - * Find Specified Trade Day based on Start Time ... - * - * @param start: DateTime ... - * - * @return ( int ) - */ - int HasTradeDay(datetime start) - { - // - int result = -1; - - // - if (!IsValid(start)) - { - return result; - } - - // - int count = ArraySize(mTradingDays); - if (!IsValidSize(count)) - { - return result; - } - - // - for (int i = 0; i < count; i++) - { - // - XTradeDay iDay = mTradingDays[i]; - - // - if (iDay.from == start) - { - // - result = i; - break; - } - } - - // - return result; - } - - /** - * Find Specified Trade Day based on End Time ... - * - * @param start: DateTime ... - * - * @return ( int ) - */ - int HasTradeDayBayEndTime(datetime end) - { - // - int result = -1; - - // - if (!IsValid(end)) - { - return result; - } - - // - int count = ArraySize(mTradingDays); - if (!IsValidSize(count)) - { - return result; - } - - // - for (int i = 0; i < count; i++) - { - // - XTradeDay iDay = mTradingDays[i]; - - // - if (iDay.to == end) - { - // - result = i; - break; - } - } - - // - return result; - } - - // - - /** - * Find Market Session by Providing Start Time ... - * - * @param session: ENUM_XSESSION member ... - * @param start: DateTime ... - * - * @return ( int ) - */ - int HasMarketSessionByStartTime( - ENUM_XSESSION session, - 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]; - - // - if (iMarketSession.session == session && - iMarketSession.from == start) - { - // - result = i; - break; - } - } - - // - return result; - } - - /** - * Find Market Session by Providing Start Time ... - * - * @param session: ENUM_XSESSION member ... - * @param end: DateTime ... - * - * @return ( int ) - */ - int HasMarketSessionByEndTime( - ENUM_XSESSION session, - datetime end // - ) - { - // - int result = -1; - - // - if (!IsValid(end)) - { - return result; - } - - // - int count = ArraySize(mMarketSessions); - if (!IsValidSize(count)) - { - return result; - } - - // - for (int i = 0; i < count; i++) - { - // - XMarketSession iMarketSession = mMarketSessions[i]; - - // - if (iMarketSession.session == session && - iMarketSession.to == end) - { - // - result = i; - break; - } - } - - // - return result; - } - - /** - * Count Specified Market Sessions ... - * - * @param session: ENUM_XSESSION member ... - * - * @return ( int ) - */ - int CountMarketSessions(ENUM_XSESSION session) - { - // - int result = 0; - - // - int count = ArraySize(mMarketSessions); - if (!IsValidSize(count)) - { - return result; - } - - // - for (int i = 0; i < count; i++) - { - // - XMarketSession iMarketSession = mMarketSessions[i]; - - // - if (iMarketSession.session == session) - { - result++; - } - } - - // - return result; - } - - // - int FindBarIndex( - ENUM_XPOIS type, - XOHCL &bar, - XOHCL &list[] // - ) - { - // - int result = -1; - - // - bool isValidType = - type == X_POI_SWING_LOW || - type == X_POI_SWING_HIGH || - type == X_POI_SUPPORT_ZONE || - type == X_POI_MOMENTUM_BAR || - type == X_POI_REJECTION_BAR || - type == X_POI_RESISTANCE_ZONE; - if (!isValidType) - { - return result; - } - - // - int count = ArraySize(list); - if (!IsValidSize(count)) - { - return result; - } - - // - for (int i = 0; i < count; i++) - { - // - XOHCL iBar = list[i]; - - // - bool isSameLow = - bar.low == iBar.low; - - // - bool isSameHigh = - bar.high == iBar.high; - - // - bool isSameUp = - bar.GetUp() == iBar.GetUp(); - - // - bool isSameDown = - bar.GetDown() == iBar.GetDown(); - - // - // Check Conditions Based On Type ... - bool canBreak = false; - if (type == X_POI_SWING_LOW || - type == X_POI_SWING_HIGH || - type == X_POI_MOMENTUM_BAR || - type == X_POI_REJECTION_BAR) - { - // - canBreak = - isSameUp && - isSameLow && - isSameHigh && - isSameDown; - } - else if (type == X_POI_SUPPORT_ZONE) - { - // - canBreak = - isSameLow && - isSameDown; - } - else if (type == X_POI_RESISTANCE_ZONE) - { - // - canBreak = - isSameUp && - isSameHigh; - } - - // - if (canBreak) - { - // - result = i; - break; - } - } - - // - return result; - } - - // - bool AddBar( - ENUM_XPOIS type, - XOHCL &bar, - XOHCL &list[] // - ) - { - // - bool result = false; - - // - result = bar.IsValid(); - if (!result) - { - return result; - } - - // - result = - type == X_POI_SWING_LOW || - type == X_POI_SWING_HIGH || - type == X_POI_SUPPORT_ZONE || - type == X_POI_MOMENTUM_BAR || - type == X_POI_REJECTION_BAR || - type == X_POI_RESISTANCE_ZONE; - if (!result) - { - return result; - } - - // - int idx = FindBarIndex( - type, - bar, - list // - ); - result = !IsValidIndex(idx); - if (!result) - { - return result; - } - - // - AddRef( - bar, - list // - ); - - // - return result; - } - - // - - /** - * Find Specified Zone Index ... - * - * @param zone: XZone instance - * @param list: XZone Collection ... - * - * @return ( int ) - */ - int FindZoneIndex( - XZone &zone, - XZone &list[] // - ) - { - // - int result = -1; - - // - int count = ArraySize(list); - if (!IsValidSize(count)) - { - return result; - } - - // - for (int i = 0; i < count; i++) - { - // - XZone iZone = list[i]; - - // - if (iZone.upper == zone.upper && - iZone.lower == zone.lower) - { - // - result = i; - break; - } - } - - // - return result; - } - - /** - * Add Specific Zone to List ... - * - * @param ob: XOHCL ... - * @param endTime: Datetime ... - * @param type: ENUM_X_POI member ... - * @param list: XZone instance Collection ... - * - * @return ( bool ) - */ - bool AddZone( - XZone &zone, - XOHCL &ob, - datetime endTime, - ENUM_XPOIS type, - XZone &list[] // - ) - { - // - bool result = false; - - // - result = type == X_POI_SUPPORT_ZONE || - type == X_POI_RESISTANCE_ZONE || - type == X_POI_BULLISH_ORDERBLOCK || - type == X_POI_BEARISH_ORDERBLOCK; - if (!result) - { - return result; - } - - // - NormalizeTime(endTime); - - // - datetime startTime = (datetime)((int)ob.time - (PeriodSeconds(mPeriod) * 2)); - - // - result = zone.Init( - ob.high, - ob.low, - ToString(type), - startTime, - endTime // - ); - if (!result) - { - return result; - } - - // - int idx = FindZoneIndex( - zone, - list // - ); - result = !IsValidIndex(idx); - if (!result) - { - return result; - } - - // - AddRef( - zone, - list // - ); - - // - return result; - } - - /** - * Initiate and Add Specific Zone to List ... - * - * @param zone: XZone instance ... - * @param upper: Double ... - * @param lower: Double ... - * @param start: DateTime ... - * @param end: DateTime ... - * @param type: ENUM_XPOIS member ... - * @param list: XZone instance Collection ... - * - * @return ( bool ) - */ - bool AddZone( - XZone &zone, - double upper, - double lower, - datetime start, - datetime end, - ENUM_XPOIS type, - XZone &list[] // - ) - { - // - bool result = false; - - // - result = zone.Init( - upper, - lower, - ToString(type), - start, - end // - ); - if (!result) - { - return result; - } - - // - int idx = FindZoneIndex( - zone, - list // - ); - result = !IsValidIndex(idx); - if (!result) - { - return result; - } - - // - AddRef( - zone, - list // - ); - - // - return result; } /** @@ -7177,296 +507,329 @@ class XCPOI : public XSCBaseAlert return; } - // - int tradingDaysCount = ArraySize(mTradingDays); - int marketSessionsCount = ArraySize(mMarketSessions); - int swingHighsCount = ArraySize(mSwingHighs); - int swingLowsCount = ArraySize(mSwingLows); - int momentumBarsCount = ArraySize(mMomentumBars); - int rejectionBarsCount = ArraySize(mRejectionBars); - int supportZonesCount = ArraySize(mSupportZones); - int resistanceZonesCount = ArraySize(mResistanceZones); - int supplyZonesCount = ArraySize(mSupplyZones); - int demandZonesCount = ArraySize(mDemandZones); - int bullishOBsCount = ArraySize(mBullishOrderBlocks); - int bearishOBsCount = ArraySize(mBearishOrderBlocks); - int bullishFVGsCount = ArraySize(mBullishFVGs); - int bearishFVGsCount = ArraySize(mBearishFVGs); + // // + // int tradingDaysCount = ArraySize(mTradingDays); + // int marketSessionsCount = ArraySize(mMarketSessions); + // int swingHighsCount = ArraySize(mSwingHighs); + // int swingLowsCount = ArraySize(mSwingLows); + // int momentumBarsCount = ArraySize(mMomentumBars); + // int rejectionBarsCount = ArraySize(mRejectionBars); + // int supportZonesCount = ArraySize(mSupportZones); + // int resistanceZonesCount = ArraySize(mResistanceZones); + // int supplyZonesCount = ArraySize(mSupplyZones); + // int demandZonesCount = ArraySize(mDemandZones); + // int bullishOBsCount = ArraySize(mBullishOrderBlocks); + // int bearishOBsCount = ArraySize(mBearishOrderBlocks); + // int bullishFVGsCount = ArraySize(mBullishFVGs); + // int bearishFVGsCount = ArraySize(mBearishFVGs); + + // // + // int from = 0; + // int requiredPOIs = MaxNumberOfRequiredPOIs(); + // int count = maxAllowed - requiredPOIs; + // int to = count - 1; + + // // + // // Trading Days ... + // if (tradingDaysCount >= maxAllowed) + // { + // // + // ArrayRemove( + // mTradingDays, + // from, + // count // + // ); + + // // + // mTradingDayObjects.DeleteRange( + // from, + // to // + // ); + // } + + // // + // // Market Sessions ... + // if (marketSessionsCount >= maxAllowed) + // { + // // + // ArrayRemove( + // mMarketSessions, + // from, + // count // + // ); + + // // + // mMarketSessionObjects.DeleteRange( + // from, + // to // + // ); + // } + + // // + // // Momentum Bars ... + // if (momentumBarsCount >= maxAllowed) + // { + // // + // ArrayRemove( + // mMomentumBars, + // from, + // count // + // ); + + // // + // mMomentumBarObjects.DeleteRange( + // from, + // to // + // ); + // } + + // // + // // Rejection Bars ... + // if (rejectionBarsCount >= maxAllowed) + // { + // // + // ArrayRemove( + // mRejectionBars, + // from, + // count // + // ); + + // // + // mRejectionBarObjects.DeleteRange( + // from, + // to // + // ); + // } + + // // + // // Swing High and Low (s) ... + + // // + // // Swing Highs ... + // if (swingHighsCount >= maxAllowed) + // { + // // + // ArrayRemove( + // mSwingHighs, + // from, + // count // + // ); + + // // + // mSwingHighObjects.DeleteRange( + // from, + // to // + // ); + // } + + // // + // // Swing Lows ... + // if (swingLowsCount >= maxAllowed) + // { + // // + // ArrayRemove( + // mSwingLows, + // from, + // count // + // ); + + // // + // mSwingLowObjects.DeleteRange( + // from, + // to // + // ); + // } + + // // + // // Support and Resistance Zones ... + + // // + // // Support Zones ... + // if (supportZonesCount >= maxAllowed) + // { + // // + // ArrayRemove( + // mSupportZones, + // from, + // count // + // ); + + // // + // mSupportZoneObjects.DeleteRange( + // from, + // to // + // ); + // } + + // // + // // Resistance Zones ... + // if (resistanceZonesCount >= maxAllowed) + // { + // // + // ArrayRemove( + // mResistanceZones, + // from, + // count // + // ); + + // // + // mResistanceZoneObjects.DeleteRange( + // from, + // to // + // ); + // } + + // // + // // Supply and Demand Zones ... + + // // + // // Supply Zones ... + // if (supplyZonesCount >= maxAllowed) + // { + // // + // ArrayRemove( + // mSupplyZones, + // from, + // count // + // ); + + // // + // mSupplyZoneObjects.DeleteRange( + // from, + // to // + // ); + // } + + // // + // // Demand Zones ... + // if (demandZonesCount >= maxAllowed) + // { + // // + // ArrayRemove( + // mDemandZones, + // from, + // count // + // ); + + // // + // mDemandZoneObjects.DeleteRange( + // from, + // to // + // ); + // } + + // // + // // Order Blocks ... + + // // + // // Bullish Order Blocks ... + // if (bullishOBsCount >= maxAllowed) + // { + // // + // ArrayRemove( + // mBullishOrderBlocks, + // from, + // count // + // ); + + // // + // mBullishOrderBlockObjects.DeleteRange( + // from, + // to // + // ); + // } + + // // + // // Bearish Order Blocks ... + // if (bearishOBsCount >= maxAllowed) + // { + // // + // ArrayRemove( + // mBearishOrderBlocks, + // from, + // count // + // ); + + // // + // mBearishOrderBlockObjects.DeleteRange( + // from, + // to // + // ); + // } + + // // + // // Fair Vakue Gaps ... + + // // + // // Bullish FVGs ... + // if (bullishFVGsCount >= maxAllowed) + // { + // // + // ArrayRemove( + // mBullishFVGs, + // from, + // count // + // ); + + // // + // mBullishFVGObjects.DeleteRange( + // from, + // to // + // ); + // } + + // // + // // Bearish FVGs ... + // if (bearishFVGsCount >= maxAllowed) + // { + // // + // ArrayRemove( + // mBearishFVGs, + // from, + // count // + // ); + + // // + // mBearishFVGObjects.DeleteRange( + // from, + // to // + // ); + // } // - int from = 0; - int requiredPOIs = MaxNumberOfRequiredPOIs(); - int count = maxAllowed - requiredPOIs; - int to = count - 1; + } + + void AddObjectIfNotExists(XCBaseObject *object) + { + // + string name = object.ObjName(); // - // Trading Days ... - if (tradingDaysCount >= maxAllowed) + bool canAdd = true; + int count = mDrawnObjects.Total(); + if (IsValidSize(count)) { // - ArrayRemove( - mTradingDays, - from, - count // - ); + for (int i = 0; i < count; i++) + { + // + string iName = ((XCBaseObject *)mDrawnObjects.At(i)).ObjName(); - // - mTradingDayObjects.DeleteRange( - from, - to // - ); + // + if (name == iName) + { + // + canAdd = false; + break; + } + } } // - // Market Sessions ... - if (marketSessionsCount >= maxAllowed) + if (canAdd) { - // - ArrayRemove( - mMarketSessions, - from, - count // - ); - - // - mMarketSessionObjects.DeleteRange( - from, - to // - ); + mDrawnObjects.Add(object); } - - // - // Momentum Bars ... - if (momentumBarsCount >= maxAllowed) - { - // - ArrayRemove( - mMomentumBars, - from, - count // - ); - - // - mMomentumBarObjects.DeleteRange( - from, - to // - ); - } - - // - // Rejection Bars ... - if (rejectionBarsCount >= maxAllowed) - { - // - ArrayRemove( - mRejectionBars, - from, - count // - ); - - // - mRejectionBarObjects.DeleteRange( - from, - to // - ); - } - - // - // Swing High and Low (s) ... - - // - // Swing Highs ... - if (swingHighsCount >= maxAllowed) - { - // - ArrayRemove( - mSwingHighs, - from, - count // - ); - - // - mSwingHighObjects.DeleteRange( - from, - to // - ); - } - - // - // Swing Lows ... - if (swingLowsCount >= maxAllowed) - { - // - ArrayRemove( - mSwingLows, - from, - count // - ); - - // - mSwingLowObjects.DeleteRange( - from, - to // - ); - } - - // - // Support and Resistance Zones ... - - // - // Support Zones ... - if (supportZonesCount >= maxAllowed) - { - // - ArrayRemove( - mSupportZones, - from, - count // - ); - - // - mSupportZoneObjects.DeleteRange( - from, - to // - ); - } - - // - // Resistance Zones ... - if (resistanceZonesCount >= maxAllowed) - { - // - ArrayRemove( - mResistanceZones, - from, - count // - ); - - // - mResistanceZoneObjects.DeleteRange( - from, - to // - ); - } - - // - // Supply and Demand Zones ... - - // - // Supply Zones ... - if (supplyZonesCount >= maxAllowed) - { - // - ArrayRemove( - mSupplyZones, - from, - count // - ); - - // - mSupplyZoneObjects.DeleteRange( - from, - to // - ); - } - - // - // Demand Zones ... - if (demandZonesCount >= maxAllowed) - { - // - ArrayRemove( - mDemandZones, - from, - count // - ); - - // - mDemandZoneObjects.DeleteRange( - from, - to // - ); - } - - // - // Order Blocks ... - - // - // Bullish Order Blocks ... - if (bullishOBsCount >= maxAllowed) - { - // - ArrayRemove( - mBullishOrderBlocks, - from, - count // - ); - - // - mBullishOrderBlockObjects.DeleteRange( - from, - to // - ); - } - - // - // Bearish Order Blocks ... - if (bearishOBsCount >= maxAllowed) - { - // - ArrayRemove( - mBearishOrderBlocks, - from, - count // - ); - - // - mBearishOrderBlockObjects.DeleteRange( - from, - to // - ); - } - - // - // Fair Vakue Gaps ... - - // - // Bullish FVGs ... - if (bullishFVGsCount >= maxAllowed) - { - // - ArrayRemove( - mBullishFVGs, - from, - count // - ); - - // - mBullishFVGObjects.DeleteRange( - from, - to // - ); - } - - // - // Bearish FVGs ... - if (bearishFVGsCount >= maxAllowed) - { - // - ArrayRemove( - mBearishFVGs, - from, - count // - ); - - // - mBearishFVGObjects.DeleteRange( - from, - to // - ); - } - - // } // @@ -7480,297 +843,360 @@ class XCPOI : public XSCBaseAlert bool mLock; // Lock State ... string mSymbol; // Market Symbol ... ENUM_TIMEFRAMES mPeriod; // Market Period ... - long mChartIdentification; // Chart ID ... - int mSubWindowIdentification; // SubWindowIdentification ID ... int mMaxNumberOfPOIs; // Max Allowed Number of POI(s) which Can Holds ... int mMaxNumberOfRequiredPOIs; // Max Allowed Number of POI(s) which Must Find at Initializion Time ... // + CArrayObj mDrawnObjects; // Drawn Objects ... XBarTracker mBarTracker; // Market Bar Tracker ... - // - XCPOIDrawer *mDrawer; // POI Drawer ... - // // POI Props ... // - // Trading Days ... + // XDay ... // - bool mAllowTradingDays; // Detect Trading Days ... - bool mAllowDrawTradingDays; // Draw Trading Days ... - color mTradingDaysStartColor; // Trading Days Start Color ... - ENUM_LINE_STYLE mTradingDaysStartStyle; // Trading Days Start Style ... - color mTradingDaysEndColor; // Trading Days End Color ... - ENUM_LINE_STYLE mTradingDaysEndStyle; // Trading Days End Style ... - XTradeDay mTradingDays[]; // Trading Days ... - CArrayObj mTradingDayObjects; // Trading Day Chart Objects ... - TXPOIEventHandler mTradingDayEventListeners[]; // Trading Day Event Listeners ... + // XSession ... + + // + // XSwing ... + int mSwingRange; // Swing Verification Range Length ... + + // + // Swing High ... + XCSwing *mSwingHighs[]; // Holds Founded Swing Highs ... /** - * Create an Object to Represent Trading Day on Chart ... + * Detect Required Swing Highs ... * - * @param day: XTradeDay instance ... - * @param name: String ... + * @param barIndex: Integer Start bar index ... + * 0 is Default ... + * + * @return ( int ) */ - void CreateTradingDayObject( - XTradeDay &day, - string name // - ) + int DetectRequiredSwingHighs(int barIndex = 0) { // - if (!day.IsValid() || - !IsValid(name)) + int result = 0; + + // + if (barIndex < 0) { - return; + barIndex = 0; } // - XCTardeDayObject *iObj; - iObj = new XCTardeDayObject(); - bool isCreated = iObj.CreateByDay( - ChartIdentification(), - name, - SubWindowIdentification(), - day // + int required = MaxNumberOfRequiredPOIs(); + if (required <= 0) + { + return result; + } + + // + int count = ArraySize(mSwingHighs); + if (count >= required) + { + // + result = count; + return result; + } + + // + int range = SwingRange(); + if (range < 0 || barIndex < range) + { + return result; + } + + // + string symbol = GetSymbol(); + ENUM_TIMEFRAMES period = GetPeriod(); + + // + XOHCL bar; + bool isInited = bar.Init( + symbol, + period, + barIndex // ); - if (!isCreated) + if (!isInited) { - return; + return result; } // - iObj.FromColor(TradingDaysStartColor()); - iObj.FromStyle(TradingDaysStartStyle()); + bool isSwing = true; + for (int i = 1; i <= range; i++) + { + // + // Prev Bar ... + XOHCL iPrevBar; + isInited = iPrevBar.Init( + symbol, + period, + barIndex + i // + ); + if (!isInited) + { + // + isSwing = false; + break; + } + + // + // Next Bar ... + XOHCL iNextBar; + isInited = iNextBar.Init( + symbol, + period, + barIndex - i // + ); + if (!isInited) + { + // + isSwing = false; + break; + } + + // + isSwing = bar.high >= iPrevBar.high && + bar.high >= iNextBar.high; + if (!isSwing) + { + break; + } + } // - iObj.ToColor(TradingDaysEndColor()); - iObj.ToStyle(TradingDaysEndStyle()); + if (isSwing) + { + // + XCSwing *swing; + swing = new XCSwing(); + isInited = swing.Init( + bar, + X_POI_SWING_HIGH // + ); + + // + if (isInited) + { + // + Add( + swing, + mSwingHighs // + ); + + // + XCSwingHighObject *iObj; + bool isCreated = mDrawer.CreateSwingHigh( + swing, + iObj // + ); + if (isCreated) + { + AddObjectIfNotExists(iObj); + } + } + } // - mTradingDayObjects.Add(iObj); + result = ArraySize(mSwingHighs); + + // + return result; } // - // Market Sessions ... - - // - bool mAllowMarketSessions; // Detect Market Sessions ... - bool mAllowDrawMarketSessions; // Draw Market Sessions ... - int mSessionOpenHours; // How many Hours a Session is Open - XSession mSessions[]; // Forex Sessions - XMarketSession mMarketSessions[]; // Founded Market Sessions ... - CArrayObj mMarketSessionObjects; // Founded Market Session Chart Ojects ... - TXSessionEventHandler mMarketSessionEventListeners[]; // Market Sessions Event Listeners ... + // Swing Low ... + XCSwing *mSwingLows[]; // Holds Founded Swing Lows ... /** - * Create an Object to Represent Market Session on Chart ... + * Detect Required Swing Lows ... * - * @param session: XMarketSession instance ... - * @param name: String ... + * @param barIndex: Integer Start bar index ... + * 0 is Default ... + * + * @return ( int ) */ - void CreateMarketSessionObject( - XMarketSession &session, - string name // - ) + int DetectRequiredSwingLows(int barIndex = 0) { // - if (!session.IsValid() || - !IsValid(name)) + int result = 0; + + // + if (barIndex < 0) { - return; + barIndex = 0; } // - // Find XSession Instance ... - int sessionIDX = FindSession(session.session); - if (!IsValidIndex(sessionIDX) || - !mSessions[sessionIDX].allowDraw) + int required = MaxNumberOfRequiredPOIs(); + if (required <= 0) { - return; + return result; } // - XCMarketSessionObject *iObj; - iObj = new XCMarketSessionObject(); - bool isCreated = iObj.CreateByMarketSession( - ChartIdentification(), - name, - SubWindowIdentification(), - session // + int count = ArraySize(mSwingLows); + if (count >= required) + { + // + result = count; + return result; + } + + // + int range = SwingRange(); + if (range < 0 || barIndex < range) + { + return result; + } + + // + string symbol = GetSymbol(); + ENUM_TIMEFRAMES period = GetPeriod(); + + // + XOHCL bar; + bool isInited = bar.Init( + symbol, + period, + barIndex // ); - if (!isCreated) + if (!isInited) { - return; + return result; } // - iObj.FromColor(mSessions[sessionIDX].startColor); - iObj.FromStyle(mSessions[sessionIDX].startStyle); + bool isSwing = true; + for (int i = 1; i <= range; i++) + { + // + // Prev Bar ... + XOHCL iPrevBar; + isInited = iPrevBar.Init( + symbol, + period, + barIndex + i // + ); + if (!isInited) + { + // + isSwing = false; + break; + } + + // + // Next Bar ... + XOHCL iNextBar; + isInited = iNextBar.Init( + symbol, + period, + barIndex - i // + ); + if (!isInited) + { + // + isSwing = false; + break; + } + + // + isSwing = bar.low <= iPrevBar.low && + bar.low <= iNextBar.low; + if (!isSwing) + { + break; + } + } // - iObj.ToColor(mSessions[sessionIDX].endColor); - iObj.ToStyle(mSessions[sessionIDX].endStyle); + if (isSwing) + { + // + XCSwing *swing; + swing = new XCSwing(); + isInited = swing.Init( + bar, + X_POI_SWING_LOW // + ); + + // + if (isInited) + { + // + Add( + swing, + mSwingLows // + ); + + // + XCSwingLowObject *iObj; + bool isCreated = mDrawer.CreateSwingLow( + swing, + iObj // + ); + if (isCreated) + { + AddObjectIfNotExists(iObj); + } + } + } // - mMarketSessionObjects.Add(iObj); + result = ArraySize(mSwingHighs); + + // + return result; } - // - // Swing High and Low(s) ... - - // - // Swing Highs ... - - // - bool mAllowSwingHighs; // Detect Swing Highs ... - bool mAllowDrawSwingHighs; // Draw Swing Highs ... - double mSwingHighThreshold; // Threshold Required for Swing High Detection ... - XOHCL mSwingHighs[]; // Swing Highs ... - CArrayObj mSwingHighObjects; // Swing High Chart Objects ... - TXOHCLEventHandler mSwingHighEventListeners[]; // Swing High Event Listeners ... - - // - // Swing Lows ... - - // - bool mAllowSwingLows; // Detect Swing Lows ... - bool mAllowDrawSwingLows; // Draw Swing Lows ... - double mSwingLowThreshold; // Threshold Required for Swing Low Detection ... - XOHCL mSwingLows[]; // Swing Lows ... - CArrayObj mSwingLowObjects; // Swing Low Chart Objects ... - TXOHCLEventHandler mSwingLowEventListeners[]; // Swing Low Event Listeners ... - // // Momentum Bars ... // - bool mAllowMomentumBars; // Detect Momentum Bars ... - bool mAllowDrawMomentumBars; // Draw Momentum Bars ... - int mMomentumBarPercent; // Momentum Bar Percent ... - double mMomentumBarSharpRatio; // Momentum Bar Sharp Ratio ... - int mMomentumBarLoopBack; // Momentum Bar Loopback ... - XOHCL mMomentumBars[]; // Momentum Bars ... - CArrayObj mMomentumBarObjects; // Momentm Bar Chart Objects ... - TXOHCLEventHandler mMomentumBarEventListeners[]; // Momentum Bars Event Listeners ... + // Rejection Bars ... // - // Rejection Bars .... + // Support Zone(s) ... // - bool mAllowRejectionBars; // Detect Rejection Bars ... - bool mAllowDrawRejectionBars; // Draw Rejection Bars ... - int mRejectionBarPercent; // Rejection Bar Percent ... - double mRejectionBarSharpRatio; // Rejection Bar Sharp Ratio ... - int mRejectionBarLoopBack; // Rejection Bar Loopback ... - XOHCL mRejectionBars[]; // Rejection Bars ... - CArrayObj mRejectionBarObjects; // Rejection Bar Chart Objects ... - TXOHCLEventHandler mRejectionBarEventListeners[]; // Rejection Bars Event Listeners ... + // Resistance Zone(s) ... // - // Support and Resistance Zones ... + // Supply Zone(s) ... // - // Support Zones ... - - // - bool mAllowSupportZones; // Detect Support Zone ... - bool mAllowDrawSupportZones; // Draw Support Zone ... - int mSupportZoneLoopBack; // Support Zone Loopback ... - ENUM_X_PRICE mSupportZonePriceType; // Support Zone Price Type ... - XOHCL mSupportZones[]; // Support Zones ... - CArrayObj mSupportZoneObjects; // Support Zone Chart Objects ... - TXOHCLEventHandler mSupportZoneEventListeners[]; // Support Zone Event Listeners ... - - // - // Resistance Zones ... - - // - bool mAllowResistanceZones; // Detect Resistance Zone ... - bool mAllowDrawResistanceZones; // Draw Resistance Zone ... - int mResistanceZoneLoopBack; // Resistance Zone Loopback ... - ENUM_X_PRICE mResistanceZonePriceType; // Resistance Zone Price Type ... - XOHCL mResistanceZones[]; // Resistance Zones ... - CArrayObj mResistanceZoneObjects; // Resistance Zone Chart Objects ... - TXOHCLEventHandler mResistanceZoneEventListeners[]; // Resistance Zone Event Listeners ... - - // - // Supply and Demand Zones ... - - // - // Supply Zones ... - - // - bool mAllowSupplyZones; // Detect Supply Zone ... - bool mAllowDrawSupplyZones; // Draw Supply Zone ... - ENUM_TIMEFRAMES mSupplyZonePeriod; // Supply Zone Detection Period ... - XZone mSupplyZones[]; // Supply Zones ... - CArrayObj mSupplyZoneObjects; // Supply Zone Chart Objects ... - TXZoneEventHandler mSupplyZoneEventListeners[]; // Supply Zone Event Listeners ... - - // - // Demand Zones ... - - // - bool mAllowDemandZones; // Detect Demand Zone ... - bool mAllowDrawDemandZones; // Draw Demand Zone ... - ENUM_TIMEFRAMES mDemandZonePeriod; // Demand Zone Detection Period ... - XZone mDemandZones[]; // Demand Zones ... - CArrayObj mDemandZoneObjects; // Demand Zone Chart Objects ... - TXZoneEventHandler mDemandZoneEventListeners[]; // Demand Zone Event Listeners ... + // Demand Zone(s) ... // // Order Blocks ... // - // Bullish Order Blocks ... + // Bullish OB ... // - bool mAllowBullishOrderBlocks; // Detect Bullish Order Blocks ... - bool mAllowDrawBullishOrderBlocks; // Draw Bullish Order Blocks ... - int mRequiredBarsForBullishOrderBlock; // Minimum Required Same Bars for Bullish Order Blocks ... - XZone mBullishOrderBlocks[]; // Bullish Order Blocks ... - CArrayObj mBullishOrderBlockObjects; // Bullish Order Block Objects ... - TXZoneEventHandler mBullishOrderBlockEventListeners[]; // Bullish Order Block Event Listeners ... - - // - // Bearish Order Blocks ... - - // - bool mAllowBearishOrderBlocks; // Detect Bearish Order Blocks ... - bool mAllowDrawBearishOrderBlocks; // Draw Bearish Order Blocks ... - int mRequiredBarsForBearishOrderBlock; // Minimum Required Same Bars for Bearish Order Blocks ... - XZone mBearishOrderBlocks[]; // Bearish Order Blocks ... - CArrayObj mBearishOrderBlockObjects; // Bearish Order Block Objects ... - TXZoneEventHandler mBearishOrderBlockEventListeners[]; // Bearish Order Block Event Listeners ... + // Bearish OB ... // // Fair Value Gaps ... // - // Bullish Fair Value Gaps ... + // Bullish FVG ... // - bool mAllowBullishFVGs; // Detect Bullish Fair Value Gaps ... - bool mAllowDrawBullishFVGs; // Draw Bullish Fair Value Gaps ... - bool mBullishFVGForceMiddleBarCheck; // Bullish FVG Force Middle Bar Check ... - bool mBullishFVGForceCheckLastBarDirection; // Bullish FVG Check Last Bar Direction ... - XZone mBullishFVGs[]; // Bullish FVGs ... - CArrayObj mBullishFVGObjects; // Bullish FVG Objects ... - TXZoneEventHandler mBullishFVGEventListeners[]; // Bullish FVG Event Listeners ... + // Bearish FVG ... // - // Bearish Fair Value Gaps ... + // Liquidity Zones ... // - bool mAllowBearishFVGs; // Detect Bearish Fair Value Gaps ... - bool mAllowDrawBearishFVGs; // Draw Bearish Fair Value Gaps ... - bool mBearishFVGForceMiddleBarCheck; // Bearish FVG Force Middle Bar Check ... - bool mBearishFVGForceCheckLastBarDirection; // Bearish FVG Check Last Bar Direction ... - XZone mBearishFVGs[]; // Bearish FVGs ... - CArrayObj mBearishFVGObjects; // Bearish FVG Objects ... - TXZoneEventHandler mBearishFVGEventListeners[]; // Bearish FVG Event Listeners ... + // Sell Side ... + + // + // Buy Side ... // }; diff --git a/Classes/x-saherelm.x-poi.drawer.class.mq5 b/Classes/x-saherelm.x-poi.drawer.class.mq5 index 550fa934..46c720b6 100644 --- a/Classes/x-saherelm.x-poi.drawer.class.mq5 +++ b/Classes/x-saherelm.x-poi.drawer.class.mq5 @@ -22,11 +22,11 @@ // // Imports ... #include "../Classes/x-saherelm.base.class.mq5" -#include "../Classes/x-saherelm.x-chart-objects.class.mq5" +#include "../Classes/x-saherelm.x-cobject.class.mq5" // // Definitions ... -class XCPOIDrawer : public XSCBase +class XCPOIDrawer : public XCBase { // public: @@ -1283,7 +1283,7 @@ class XCPOIDrawer : public XSCBase * @return ( bool ) */ bool CreateSwingHigh( - XOHCL &swing, + XCSwing &swing, XCSwingHighObject *&object // ) { @@ -1294,7 +1294,9 @@ class XCPOIDrawer : public XSCBase object = NULL; // - result = swing.IsValid(); + result = + swing.IsValid() && + swing.IsSwingHigh(); if (!result) { return result; @@ -1304,9 +1306,6 @@ class XCPOIDrawer : public XSCBase long chartID = ChartIdentification(); int window = SubWindowIdentification(); - // - string name = swing.GetTag(ToString(X_POI_SWING_HIGH)); - // int arrow = SwingHighArrow(); int width = SwingHighWidth(); @@ -1314,12 +1313,11 @@ class XCPOIDrawer : public XSCBase // object = new XCSwingHighObject(); - result = object.CreateBySwing( + result = object.Create( chartID, - name, window, - swing, - (char)arrow // + arrow, + swing // ); // @@ -1345,7 +1343,7 @@ class XCPOIDrawer : public XSCBase * @return ( bool ) */ bool CreateSwingLow( - XOHCL &swing, + XCSwing &swing, XCSwingLowObject *&object // ) { @@ -1356,7 +1354,9 @@ class XCPOIDrawer : public XSCBase object = NULL; // - result = swing.IsValid(); + result = + swing.IsValid() && + swing.IsSwingLow(); if (!result) { return result; @@ -1366,9 +1366,6 @@ class XCPOIDrawer : public XSCBase long chartID = ChartIdentification(); int window = SubWindowIdentification(); - // - string name = swing.GetTag(ToString(X_POI_SWING_LOW)); - // int arrow = SwingLowArrow(); int width = SwingLowWidth(); @@ -1376,12 +1373,11 @@ class XCPOIDrawer : public XSCBase // object = new XCSwingLowObject(); - result = object.CreateBySwing( + result = object.Create( chartID, - name, window, - swing, - (char)arrow // + arrow, + swing // ); // @@ -1399,855 +1395,6 @@ class XCPOIDrawer : public XSCBase return result; } - // - // Momentum Bars ... - - /** - * Create Bullish Momentum Bar Object ... - * - * @param bar: XOHCL instance ... - * - * @return ( bool ) - */ - bool CreateBullishMomentumBar( - XOHCL &bar, - XCBullishMomentumBarObject *&object // - ) - { - // - bool result = false; - - // - object = NULL; - - // - result = bar.IsValid(); - if (!result) - { - return result; - } - - // - long chartID = ChartIdentification(); - int window = SubWindowIdentification(); - - // - string name = bar.GetTag(ToString(X_POI_MOMENTUM_BAR)); - - // - int arrow = BullishMomentumBarArrow(); - int width = BullishMomentumBarWidth(); - color crl = BullishMomentumBarColor(); - - // - object = new XCBullishMomentumBarObject(); - result = object.CreateByBar( - chartID, - name, - window, - bar, - (char)arrow // - ); - - // - if (!result) - { - return result; - } - - // - object.ArrowColor(crl); - object.ArrowWidth(width); - object.ArrowAnchor(ANCHOR_TOP); - - // - return result; - } - - /** - * Create Bearish Momentum Bar Object ... - * - * @param bar: XOHCL instance ... - * - * @return ( bool ) - */ - bool CreateBearishMomentumBar( - XOHCL &bar, - XCBearishMomentumBarObject *&object // - ) - { - // - bool result = false; - - // - object = NULL; - - // - result = bar.IsValid(); - if (!result) - { - return result; - } - - // - long chartID = ChartIdentification(); - int window = SubWindowIdentification(); - - // - string name = bar.GetTag(ToString(X_POI_MOMENTUM_BAR)); - - // - int arrow = BearishMomentumBarArrow(); - int width = BearishMomentumBarWidth(); - color crl = BearishMomentumBarColor(); - - // - object = new XCBearishMomentumBarObject(); - result = object.CreateByBar( - chartID, - name, - window, - bar, - (char)arrow // - ); - - // - if (!result) - { - return result; - } - - // - object.ArrowColor(crl); - object.ArrowWidth(width); - object.ArrowAnchor(ANCHOR_TOP); - - // - return result; - } - - // - // Rejection Bars ... - - /** - * Create Bullish Rejection Bar Object ... - * - * @param bar: XOHCL instance ... - * - * @return ( bool ) - */ - bool CreateBullishRejectionBar( - XOHCL &bar, - XCBullishRejectionBarObject *&object // - ) - { - // - bool result = false; - - // - object = NULL; - - // - result = bar.IsValid(); - if (!result) - { - return result; - } - - // - long chartID = ChartIdentification(); - int window = SubWindowIdentification(); - - // - string name = bar.GetTag(ToString(X_POI_REJECTION_BAR)); - - // - int arrow = BullishRejectionBarArrow(); - int width = BullishRejectionBarWidth(); - color crl = BullishRejectionBarColor(); - - // - object = new XCBullishRejectionBarObject(); - result = object.CreateByBar( - chartID, - name, - window, - bar, - (char)arrow // - ); - - // - if (!result) - { - return result; - } - - // - object.ArrowColor(crl); - object.ArrowWidth(width); - object.ArrowAnchor(ANCHOR_TOP); - - // - return result; - } - - /** - * Create Bearish Rejection Bar Object ... - * - * @param bar: XOHCL instance ... - * - * @return ( bool ) - */ - bool CreateBearishRejectionBar( - XOHCL &bar, - XCBearishRejectionBarObject *&object // - ) - { - // - bool result = false; - - // - object = NULL; - - // - result = bar.IsValid(); - if (!result) - { - return result; - } - - // - long chartID = ChartIdentification(); - int window = SubWindowIdentification(); - - // - string name = bar.GetTag(ToString(X_POI_REJECTION_BAR)); - - // - int arrow = BearishRejectionBarArrow(); - int width = BearishRejectionBarWidth(); - color crl = BearishRejectionBarColor(); - - // - object = new XCBearishRejectionBarObject(); - result = object.CreateByBar( - chartID, - name, - window, - bar, - (char)arrow // - ); - - // - if (!result) - { - return result; - } - - // - object.ArrowColor(crl); - object.ArrowWidth(width); - object.ArrowAnchor(ANCHOR_TOP); - - // - return result; - } - - // - // Support and Resistance Zones ... - - /** - * Create Support Zone Object ... - * - * @param bar: XOHCL instance ... - * @param destTime: DateTime ... - * - * @return ( bool ) - */ - bool CreateSupportZone( - XOHCL &bar, - XCSupportZoneObject *&object, - datetime destTime = NULL // - ) - { - // - bool result = false; - - // - object = NULL; - - // - result = bar.IsValid(); - if (!result) - { - return result; - } - - // - long chartID = ChartIdentification(); - int window = SubWindowIdentification(); - - // - string name = bar.GetTag(ToString(X_POI_SUPPORT_ZONE)); - - // - datetime time2 = - IsValid(destTime) - ? destTime - : (datetime)((int)bar.time + (PeriodSeconds(bar.period) * 5)); - - // - bool fill = SupportZoneFill(); - int width = SupportZoneWidth(); - color crl = SupportZoneColor(); - ENUM_LINE_STYLE style = SupportZoneStyle(); - - // - object = new XCSupportZoneObject(); - result = object.CreateBySupport( - chartID, - name, - window, - bar, - time2, - true // - ); - - // - if (!result) - { - return result; - } - - // - object.ZoneFill(fill); - object.ZoneColor(crl); - object.ZoneWidth(width); - object.ZoneStyle(style); - - // - return result; - } - - /** - * Create Resistance Zone Object ... - * - * @param bar: XOHCL instance ... - * - * @return ( bool ) - */ - bool CreateResistanceZone( - XOHCL &bar, - XCResistanceZoneObject *&object, - datetime destTime = NULL // - ) - { - // - bool result = false; - - // - object = NULL; - - // - result = bar.IsValid(); - if (!result) - { - return result; - } - - // - long chartID = ChartIdentification(); - int window = SubWindowIdentification(); - - // - string name = bar.GetTag(ToString(X_POI_RESISTANCE_ZONE)); - - // - datetime time2 = - IsValid(destTime) - ? destTime - : (datetime)((int)bar.time + (PeriodSeconds(bar.period) * 5)); - - // - bool fill = ResistanceZoneFill(); - int width = ResistanceZoneWidth(); - color crl = ResistanceZoneColor(); - ENUM_LINE_STYLE style = ResistanceZoneStyle(); - - // - object = new XCResistanceZoneObject(); - result = object.CreateByResistance( - chartID, - name, - window, - bar, - time2, - true // - ); - - // - if (!result) - { - return result; - } - - // - object.ZoneFill(fill); - object.ZoneColor(crl); - object.ZoneWidth(width); - object.ZoneStyle(style); - - // - return result; - } - - // - // Supply and Demand Zones ... - - /** - * Create Supply Zone Object ... - * - * @param zone: XZone instance ... - * - * @return ( bool ) - */ - bool CreateSupplyZone( - XZone &zone, - XCSupplyZoneObject *&object // - ) - { - // - bool result = false; - - // - object = NULL; - - // - result = zone.IsValid(); - if (!result) - { - return result; - } - - // - long chartID = ChartIdentification(); - int window = SubWindowIdentification(); - - // - string name = zone.GetTag(); - result = Contains( - ToString(X_POI_SUPPLY_ZONE), - name // - ); - if (!result) - { - return result; - } - - // - bool fill = SupplyZoneFill(); - int width = SupplyZoneWidth(); - color crl = SupplyZoneColor(); - ENUM_LINE_STYLE style = SupplyZoneStyle(); - - // - object = new XCSupplyZoneObject(); - result = object.CreateByZone( - chartID, - name, - window, - zone, - NULL, - true // - ); - - // - if (!result) - { - return result; - } - - // - object.ZoneFill(fill); - object.ZoneColor(crl); - object.ZoneWidth(width); - object.ZoneStyle(style); - - // - return result; - } - - /** - * Create Demand Zone Object ... - * - * @param zone: XZone instance ... - * - * @return ( bool ) - */ - bool CreateDemandZone( - XZone &zone, - XCDemandZoneObject *&object // - ) - { - // - bool result = false; - - // - object = NULL; - - // - result = zone.IsValid(); - if (!result) - { - return result; - } - - // - long chartID = ChartIdentification(); - int window = SubWindowIdentification(); - - // - string name = zone.GetTag(); - result = Contains( - ToString(X_POI_DEMAND_ZONE), - name // - ); - if (!result) - { - return result; - } - - // - bool fill = DemandZoneFill(); - int width = DemandZoneWidth(); - color crl = DemandZoneColor(); - ENUM_LINE_STYLE style = DemandZoneStyle(); - - // - object = new XCDemandZoneObject(); - result = object.CreateByZone( - chartID, - name, - window, - zone, - NULL, - true // - ); - - // - if (!result) - { - return result; - } - - // - object.ZoneFill(fill); - object.ZoneColor(crl); - object.ZoneWidth(width); - object.ZoneStyle(style); - - // - return result; - } - - // - // Order Blocks ... - - /** - * Create Bullish Order Block Object ... - * - * @param zone: XZone instance ... - * - * @return ( bool ) - */ - bool CreateBullishOrderBlock( - XZone &zone, - XCBullishOrderBlockObject *&object // - ) - { - // - bool result = false; - - // - object = NULL; - - // - result = zone.IsValid(); - if (!result) - { - return result; - } - - // - long chartID = ChartIdentification(); - int window = SubWindowIdentification(); - - // - string name = zone.GetTag(); - result = Contains( - ToString(X_POI_BULLISH_ORDERBLOCK), - name // - ); - if (!result) - { - return result; - } - - // - bool fill = BullishOrderBlockFill(); - int width = BullishOrderBlockWidth(); - color crl = BullishOrderBlockColor(); - ENUM_LINE_STYLE style = BullishOrderBlockStyle(); - - // - object = new XCBullishOrderBlockObject(); - result = object.CreateByZone( - chartID, - name, - window, - zone, - NULL, - true // - ); - - // - if (!result) - { - return result; - } - - // - object.ZoneFill(fill); - object.ZoneColor(crl); - object.ZoneWidth(width); - object.ZoneStyle(style); - - // - return result; - } - - /** - * Create Bearish Order Block Object ... - * - * @param zone: XZone instance ... - * - * @return ( bool ) - */ - bool CreateBearishOrderBlock( - XZone &zone, - XCBearishOrderBlockObject *&object // - ) - { - // - bool result = false; - - // - object = NULL; - - // - result = zone.IsValid(); - if (!result) - { - return result; - } - - // - long chartID = ChartIdentification(); - int window = SubWindowIdentification(); - - // - string name = zone.GetTag(); - result = Contains( - ToString(X_POI_BEARISH_ORDERBLOCK), - name // - ); - if (!result) - { - return result; - } - - // - bool fill = BearishOrderBlockFill(); - int width = BearishOrderBlockWidth(); - color crl = BearishOrderBlockColor(); - ENUM_LINE_STYLE style = BearishOrderBlockStyle(); - - // - object = new XCBearishOrderBlockObject(); - result = object.CreateByZone( - chartID, - name, - window, - zone, - NULL, - true // - ); - - // - if (!result) - { - return result; - } - - // - object.ZoneFill(fill); - object.ZoneColor(crl); - object.ZoneWidth(width); - object.ZoneStyle(style); - - // - return result; - } - - // - // Order Blocks ... - - /** - * Create Bullish FVG Object ... - * - * @param zone: XZone instance ... - * - * @return ( bool ) - */ - bool CreateBullishFVG( - XZone &zone, - XCBullishFVGObject *&object // - ) - { - // - bool result = false; - - // - object = NULL; - - // - result = zone.IsValid(); - if (!result) - { - return result; - } - - // - long chartID = ChartIdentification(); - int window = SubWindowIdentification(); - - // - string name = zone.GetTag(); - result = Contains( - ToString(X_POI_BULLISH_FVG), - name // - ); - if (!result) - { - return result; - } - - // - bool fill = BullishFVGFill(); - int width = BullishFVGWidth(); - color crl = BullishFVGColor(); - ENUM_LINE_STYLE style = BullishFVGStyle(); - - // - object = new XCBullishFVGObject(); - result = object.CreateByZone( - chartID, - name, - window, - zone, - NULL, - true // - ); - - // - if (!result) - { - return result; - } - - // - object.ZoneFill(fill); - object.ZoneColor(crl); - object.ZoneWidth(width); - object.ZoneStyle(style); - - // - return result; - } - - /** - * Create Bearish FVG Object ... - * - * @param zone: XZone instance ... - * - * @return ( bool ) - */ - bool CreateBearishFVG( - XZone &zone, - XCBearishFVGObject *&object // - ) - { - // - bool result = false; - - // - object = NULL; - - // - result = zone.IsValid(); - if (!result) - { - return result; - } - - // - long chartID = ChartIdentification(); - int window = SubWindowIdentification(); - - // - string name = zone.GetTag(); - result = Contains( - ToString(X_POI_BEARISH_FVG), - name // - ); - if (!result) - { - return result; - } - - // - bool fill = BearishFVGFill(); - int width = BearishFVGWidth(); - color crl = BearishFVGColor(); - ENUM_LINE_STYLE style = BearishFVGStyle(); - - // - object = new XCBearishFVGObject(); - result = object.CreateByZone( - chartID, - name, - window, - zone, - NULL, - true // - ); - - // - if (!result) - { - return result; - } - - // - object.ZoneFill(fill); - object.ZoneColor(crl); - object.ZoneWidth(width); - object.ZoneStyle(style); - - // - return result; - } - // protected: // diff --git a/Classes/x-saherelm.xtrade.class.mq5 b/Classes/x-saherelm.x-trade.class.mq5 similarity index 56% rename from Classes/x-saherelm.xtrade.class.mq5 rename to Classes/x-saherelm.x-trade.class.mq5 index b9adec5c..ae894f85 100644 --- a/Classes/x-saherelm.xtrade.class.mq5 +++ b/Classes/x-saherelm.x-trade.class.mq5 @@ -22,10 +22,9 @@ // // Imports ... #include "../Classes/x-saherelm.base.class.mq5" -#include "../Libraries/x-saherelm.tools.lib.mq5" -#include "../Classes/x-saherelm.xalert.class.mq5" -#include "../Libraries/x-saherelm.xtrade.lib.mq5" -#include "../Classes/x-saherelm.xaccount.class.mq5" +#include "../Classes/x-saherelm.x-account.class.mq5" +#include "../Classes/x-saherelm.x-alert.class.mq5" +#include "../Libraries/x-saherelm.x-trade.lib.mq5" // // Definitions ... @@ -35,9 +34,9 @@ // // XCTrade Base Class ... -class XSCTradeBase : public CTrade +class XCTradeBase : public CTrade { -public: + public: // // Modify Specific Position, by Specific Comment ... bool PositionModify( @@ -518,18 +517,18 @@ public: // // a Class For Manage Trades and Handle Trading Actions ... -class XSCTrade : public XSCBase +class XCTrade : public XCBase { // // Public ... -public: + public: // // Props ... - XSCAccount *mAccount; // Account Info Provider + XCAccount *mAccount; // Account Info Provider // // Constructors ... - void XSCTrade( + void XCTrade( int slippage, // Specify Slippage ulong magicNumber, // Specify Magic Number double maxAllowedSpread = 0, // Max Allowed Spred for Opening Trades @@ -548,11 +547,11 @@ public: mMaxAllowedDrawdownFactor = maxAllowedDrawdownFactor; // - mAccount = new XSCAccount(); + mAccount = new XCAccount(); // // Instance Base Trader Class ... - mTrader = new XSCTradeBase(); + mTrader = new XCTradeBase(); // // Configuring Base Trader Class ... @@ -582,7 +581,7 @@ public: // // Deconstructor ... - ~XSCTrade() + ~XCTrade() { // // Remove Pointer ... @@ -3332,7 +3331,7 @@ public: // // Protected ... -protected: + protected: // // Props ... @@ -3637,7 +3636,7 @@ protected: // // Private ... -private: + private: // // Props ... @@ -3651,7 +3650,7 @@ private: double mMaxAllowedDrawdownFactor; // Max Allowed Drawdown Factor // - XSCTradeBase *mTrader; // Base CTrade Manipulated Instance ... + XCTradeBase *mTrader; // Base CTrade Manipulated Instance ... // CDealInfo mDealInfo; // Deals Info ... @@ -3868,2759 +3867,4 @@ private: } }; -// -// a Class For Read and Write Trade Info Data in Files ... -class XTradeCollector -{ - // - // Public ... -public: - // - // Props ... - - // - // Constructor(s) ... - void XTradeCollector( - string _path = NULL // Base Path - ) - { - // - mAccount = new XSCAccount(); - - // - if (IsValid(_path)) - { - mPath = _path; - } - else - { - mPath = "XTradeData" + "\\" + mAccount.GetCompany(); - } - } - - // - // Deconstructor ... - void ~XTradeCollector() {} - - // - bool IsExists(XTradeData &item) - { - // - bool result = false; - - // - int mHandler = GetFileHandlerForRead(item); - result = mHandler != INVALID_HANDLE; - FileClose(mHandler); - - // - return result; - } - - // - bool Save(XTradeData &item) - { - // - bool result = false; - - // - // Check info is Valid ... - result = item.IsValid(); - if (!result) - { - return result; - } - - // - string content = item.ToString(); - content += "\n" + "-----------" + "\n" + "Signal: " + "\n" + "-----------" + "\n" + item.ToString(true); - - // - result = IsValid(content); - if (!result) - { - return result; - } - - // - int mHandler = GetFileHandlerForWrite(item); - result = mHandler != INVALID_HANDLE; - if (!result) - { - return result; - } - - // - FileWrite(mHandler, content); - FileFlush(mHandler); - FileClose(mHandler); - - // - return result; - } - - // - bool SaveSignal(XTradeData &item) - { - // - bool result = false; - - // - string content = item.ToString(true); - result = IsValid(content); - if (!result) - { - return result; - } - - // - int mHandler = GetSignalFileHandlerForWrite(item); - result = mHandler != INVALID_HANDLE; - if (!result) - { - return result; - } - - // - FileWrite(mHandler, content); - FileFlush(mHandler); - FileClose(mHandler); - - // - return result; - } - - // - // Conditions only save for Loss Signals ... - // this means the profit must be Lower than Zero ... - // ans also message Contains SL ... - bool SaveConditions(XTradeData &item) - { - // - bool result = false; - - // - // Validate Item ... - result = - // - item.profit < 0 && - Contains("SL", item.message) - // - ; - if (!result) - { - return result; - } - - // - string content = item.signal.conditions; - result = IsValid(content); - if (!result) - { - return result; - } - - // - int mHandler = GetConditionsFileHandlerForWrite(item); - result = mHandler != INVALID_HANDLE; - if (!result) - { - return result; - } - - // - FileSeek(mHandler, 0, SEEK_END); - FileWrite(mHandler, content); - FileFlush(mHandler); - FileClose(mHandler); - - // - return result; - } - - // - // Protected ... -protected: - // - // Private ... -private: - // - // Props ... - - // - string mPath; // Base Path ... - - // - XSCAccount *mAccount; - - // - string GetFilePath(XTradeData &item) - { - // - string fileName = item.GetFileName(); - - // - return GetFilePath(fileName); - } - string GetFilePath(string fileName) - { - // - string result = ""; - - // - result = - // - mPath + "\\" + "Trades" + "\\" + fileName + ".x121.log" - // - ; - - // - return result; - } - - // - string GetSignalFilePath(XTradeData &item) - { - // - string fileName = item.GetSignalFileName(); - - // - return GetSignalFilePath(fileName); - } - string GetSignalFilePath(string fileName) - { - // - string result = ""; - - // - result = - // - mPath + "\\" + "Signals" + "\\" + fileName + ".x121.log" - // - ; - - // - return result; - } - - // - string GetConditionsFilePath(XTradeData &item) - { - // - bool isLong = IsLong(item.type); - - // - string fileName = - item.symbol + "\\" + - (isLong - ? "Longs" - : "Shorts"); - - // - return GetConditionsFilePath(fileName); - } - string GetConditionsFilePath(string fileName) - { - // - string result = ""; - - // - result = - // - mPath + "\\" + "Conditions" + "\\" + fileName + ".x121.log" - // - ; - - // - return result; - } - - // - int GetFileHandlerForRead(XTradeData &item) - { - // - int result = INVALID_HANDLE; - - // - string filePath = GetFilePath(item); - if (!IsValid(filePath)) - { - return result; - } - - // - result = FileOpen( - filePath, - FILE_READ | FILE_TXT // - ); - - // - return result; - } - int GetFileHandlerForWrite(XTradeData &item) - { - // - int result = INVALID_HANDLE; - - // - string filePath = GetFilePath(item); - if (!IsValid(filePath)) - { - return result; - } - - // - result = FileOpen( - filePath, - FILE_READ | FILE_WRITE | FILE_TXT // - ); - - // - return result; - } - - // - int GetSignalFileHandlerForRead(XTradeData &item) - { - // - int result = INVALID_HANDLE; - - // - string filePath = GetSignalFilePath(item); - if (!IsValid(filePath)) - { - return result; - } - - // - result = FileOpen( - filePath, - FILE_READ | FILE_TXT // - ); - - // - return result; - } - int GetSignalFileHandlerForWrite(XTradeData &item) - { - // - int result = INVALID_HANDLE; - - // - string filePath = GetSignalFilePath(item); - if (!IsValid(filePath)) - { - return result; - } - - // - result = FileOpen( - filePath, - FILE_READ | FILE_WRITE | FILE_TXT // - ); - - // - return result; - } - - // - int GetConditionsFileHandlerForRead(XTradeData &item) - { - // - int result = INVALID_HANDLE; - - // - string filePath = GetConditionsFilePath(item); - if (!IsValid(filePath)) - { - return result; - } - - // - result = FileOpen( - filePath, - FILE_READ | FILE_TXT // - ); - - // - return result; - } - int GetConditionsFileHandlerForWrite(XTradeData &item) - { - // - int result = INVALID_HANDLE; - - // - string filePath = GetConditionsFilePath(item); - if (!IsValid(filePath)) - { - return result; - } - - // - result = FileOpen( - filePath, - FILE_READ | FILE_WRITE | FILE_TXT // - ); - - // - return result; - } -}; - -// -// Trade Handler Class ... -class XSCXTradeHandler : public XSCBaseAlert -{ - // - // Public ... -public: - // - - // - // Constructor(s) ... - void XSCXTradeHandler(XSCTrade *trader) - { - // - mTrader = trader; - mCollector = new XTradeCollector(); - } - - // - // Deconstructor ... - void ~XSCXTradeHandler() - { - // - delete mTrader; - delete mCollector; - } - - // - // Getter(s) / Setter(s) ... - - // - bool SaveSignals() - { - return mSaveSignals; - } - - // - void SaveSignals(bool value) - { - mSaveSignals = value; - } - - // - bool SaveTrades() - { - return mSaveTrades; - } - - // - void SaveTrades(bool value) - { - mSaveTrades = value; - } - - // - bool SaveConditions() - { - return mSaveConditions; - } - - // - void SaveConditions(bool value) - { - mSaveConditions = value; - } - - // - int MaxSameTimeTrades() - { - return maxSameTimeTrades; - } - - // - bool AllowLong() - { - return mAllowLong; - } - - // - void AllowLong(bool value) - { - mAllowLong = value; - } - - // - bool AllowShort() - { - return mAllowShort; - } - - // - void AllowShort(bool value) - { - mAllowShort = value; - } - - // - int MaxAllowedLongs() - { - return mMaxAllowedLongs; - } - - // - void MaxAllowedLongs(int value) - { - // - if (value < 0) - { - value = 0; - } - - // - mMaxAllowedLongs = value; - } - - // - int MaxAllowedShorts() - { - return mMaxAllowedShorts; - } - - // - void MaxAllowedShorts(int value) - { - // - if (value < 0) - { - value = 0; - } - - // - mMaxAllowedShorts = value; - } - - // - bool UseMaxAllowedTradesPerSymbol() - { - return mUseMaxAllowedTradesPerSymbol; - } - - // - void UseMaxAllowedTradesPerSymbol(bool value) - { - mUseMaxAllowedTradesPerSymbol = value; - } - - // - double MaxDrawdownPercentForOpenTrades() - { - return mMaxDrawdownPercentForOpenTrades; - } - - // - void MaxDrawdownPercentForOpenTrades(double value) - { - // - if (value < 0) - { - value = 0; - } - - // - mMaxDrawdownPercentForOpenTrades = value; - } - - // - // Trailling ... - - // - bool AllowTrailStops() - { - return mAllowTrailStops; - } - - // - void AllowTrailStops(bool value) - { - mAllowTrailStops = value; - } - - // - bool IgnoreTPOnTrail() - { - return mIgnoreTPOnTrail; - } - - // - void IgnoreTPOnTrail(bool value) - { - mIgnoreTPOnTrail = value; - } - - // - double TrailStartInPoint() - { - return mTrailStartInPoint; - } - - // - void TrailStartInPoint(double value) - { - // - if (value < 0) - { - value = 0; - } - - // - mTrailStartInPoint = value; - } - - // - double TrailStepInPoint() - { - return mTrailStepInPoint; - } - - // - void TrailStepInPoint(double value) - { - // - if (value < 0) - { - value = 0; - } - - // - mTrailStepInPoint = value; - } - - // - bool TrailBasedOnProfit() - { - return mTrailBasedOnProfit; - } - - // - void TrailBasedOnProfit(bool value) - { - mTrailBasedOnProfit = value; - } - - // - // Recovery ... - - // - bool AllowRecover() - { - return mAllowRecover; - } - - // - void AllowRecover(bool value) - { - mAllowRecover = value; - } - - // - double RecoveryTPPoint() - { - return mRecoveryTPPoint; - } - - // - void RecoveryTPPoint(double value) - { - // - if (value < 0) - { - value = 0; - } - - // - mRecoveryTPPoint = value; - } - - // - double RecoverySLPoint() - { - return mRecoverySLPoint; - } - - // - void RecoverySLPoint(double value) - { - // - if (value < 0) - { - value = 0; - } - - // - mRecoverySLPoint = value; - } - - // - int MaxAllowedRecover() - { - return mMaxAllowedRecover; - } - - // - void MaxAllowedRecover(int value) - { - // - if (value < 0) - { - value = 0; - } - - // - mMaxAllowedRecover = value; - } - - // - double MaxAllowedRecoveryVolume() - { - return mMaxAllowedRecoveryVolume; - } - - // - void MaxAllowedRecoveryVolume(double value) - { - // - if (value < 0) - { - value = 0; - } - - // - mMaxAllowedRecoveryVolume = value; - } - - // - double RecoveryVolumeMultiplier() - { - return mRecoveryVolumeMultiplier; - } - - // - void RecoveryVolumeMultiplier(double value) - { - // - if (value < 0) - { - value = 0; - } - - // - mRecoveryVolumeMultiplier = value; - } - - // - bool ForcePressuresInRecovery() - { - return mForcePressuresInRecovery; - } - - // - void ForcePressuresInRecovery(bool value) - { - mForcePressuresInRecovery = value; - } - - // - // Hedging ... - - // - bool AllowHedging() - { - return mAllowHedging; - } - - // - void AllowHedging(bool value) - { - mAllowHedging = value; - } - - // - double HedgeVolumeFactor() - { - return mHedgeVolumeFactor; - } - - // - void HedgeVolumeFactor(double value) - { - // - if (value < 0) - { - value = 0; - } - - // - mHedgeVolumeFactor = value; - } - - // - int MinTradesForHedge() - { - return mMinTradesForHedge; - } - - // - void MinTradesForHedge(int value) - { - // - if (value < 0) - { - value = 0; - } - - // - mMinTradesForHedge = value; - } - - // - double HedgeMinProfitPerVolumeFactor() - { - return mHedgeMinProfitPerVolumeFactor; - } - - // - void HedgeMinProfitPerVolumeFactor(double value) - { - // - if (value < 0) - { - value = 0; - } - - // - mHedgeMinProfitPerVolumeFactor = value; - } - - // - // Position Protecting ... - - // - bool AllowProtectPositions() - { - return mAllowProtectPositions; - } - - // - void AllowProtectPositions(bool value) - { - mAllowProtectPositions = value; - } - - // - // Tools ... - - // - // Calculate Max Drawdown and it's Percent ... - double GetMaxDrawdown() - { - // - XPosition positions[]; - int positionsCount = mTrader.GetPositions(positions); - if (IsValidSize(positionsCount)) - { - double mEquity = mTrader.mAccount.GetEquity(); - if (mEquity > maxDrawdown) - { - maxDrawdown = mEquity; - } - - // - drawdownPercent = (maxDrawdown - mEquity) / (staticBalanceForCalculateDrawdown > 0 ? staticBalanceForCalculateDrawdown : maxDrawdown) * 100; - drawdownPercent = NormalizeDouble(drawdownPercent, 3); - } - else - { - // - maxDrawdown = 0.0; - drawdownPercent = 0.0; - } - - // - return drawdownPercent; - } - - // - // Trade Handling Functions ... - - // - // First Step of Trade Handling ... - // Since Must Call when a Signal Executed ... - void AddData( - XSignal &signal, // Executed Signal - double commission = 0, // Commission - bool forceTrail = false, // Force Signal Trailling Stop - bool forceRecover = false // Force Signal Recovery - ) - { - // - // Check Signal Valid ... - if (!signal.IsValid()) - { - return; - } - - // - // Check Signal Support or Recovery ... - bool isSupport = IsSupport(signal.comment); - bool isRecovery = ExtractRecoveredTicket(signal.comment) > 0; - - // - XTradeData item; - bool isFilled = item.Fill(signal); - if (!isFilled) - { - return; - } - - // - item.commission = commission; - - // - // Trailling Configuration ... - - // - // Force Trail used to implement Trailing for - // Custom Positions ... - if (mAllowTrailStops || forceTrail) - { - // - if (!isSupport && !isRecovery) - { - item.allowTrailStop = true; - } - - // - item.ignoreTPOnTrail = mIgnoreTPOnTrail; - item.trailStepInPoint = mTrailStepInPoint; - item.trailStartInPoint = mTrailStartInPoint; - item.trailBasedOnProfit = mTrailBasedOnProfit; - } - - // - // Recovery Configuration ... - - // - // Force Recovery used to implement Recovery for - // Custom Positions ... - if (mAllowRecover || forceRecover) - { - // - if (!isSupport && !isRecovery) - { - item.allowRecover = true; - } - - // - item.recoveryTPPoint = mRecoveryTPPoint; - item.recoverySLPoint = mRecoverySLPoint; - item.maxAllowedRecover = mMaxAllowedRecover; - item.recoveryVolumeMultiplier = mRecoveryVolumeMultiplier; - - // - ENUM_POSITION_TYPE _type; - bool isConverted = ToPositionType( - _type, - item.type // - ); - if (isConverted) - { - item.recoveryLookingType = GetOppositPositionType(_type); - } - } - - // - Add(item); - - // - SaveSignal(item); - } - - // - void Finish(const XDeal &deal) - { - // - int idx = -1; - bool hasItem = HasItem( - deal.positionId, - idx // - ); - if (!hasItem) - { - return; - } - - // - // Update Item Info ... - mData[idx].swap = deal.swap; - mData[idx].endTime = deal.time; - mData[idx].profit = deal.profit; - - // - mData[idx].message = - deal.reason == DEAL_REASON_TP - ? "TP" - : "SL"; - - // - Save(idx); - } - - // - void Finish( - const ulong ticket, - const XPosition &position, - const string comment // - ) - { - // - int idx = -1; - bool hasItem = HasItem( - ticket, - idx // - ); - if (!hasItem) - { - return; - } - - // - // Update Item Info ... - mData[idx].swap = position.swap; - mData[idx].endTime = TimeCurrent(); - mData[idx].profit = position.profit; - - // - mData[idx].message = comment; - - // - Save(idx); - } - - // - // this Method call's by a Timer, - // or in OnTick for Update Positions, - // Data ... - void UpdateData() - { - // - XPosition positions[]; - int count = mTrader.GetPositions(positions); - if (!IsValidSize(count)) - { - return; - } - - // - for (int i = 0; i < count; i++) - { - // - XPosition iPosition = positions[i]; - - // - int idx = -1; - bool isExists = HasItem( - iPosition.ticket, - idx // - ); - if (!isExists) - { - // - // Add New Data ... - - // - // Find Executed Signal Deal History ... - XDeal deals[]; - double commission = 0; - int dealsCount = mTrader.GetDeals( - deals, - iPosition.symbol, - iPosition.provider, - iPosition.period, - NULL, - DEAL_ENTRY_IN // - ); - if (IsValidSize(dealsCount)) - { - // - for (int i = 0; i < dealsCount; i++) - { - // - XDeal iDeal = deals[i]; - if (iDeal.positionId == iPosition.ticket) - { - // - commission = iDeal.commission; - break; - } - } - } - - // - XTradeData iData; - iData.Fill( - iPosition // - ); - - // - iData.ticket = iPosition.ticket; - - // - Add(iData); - } - else - { - // - // Update Exists ... - mData[idx].Update(iPosition); - } - } - - // - count = Count(); - if (count > maxSameTimeTrades) - { - maxSameTimeTrades = count; - } - - // - GetMaxDrawdown(); - } - - // - void UpdateSignal(XSignal &signal) - { - // - if (!signal.IsValid()) - { - return; - } - - // - int count = Count(); - if (!IsValidSize(count)) - { - return; - } - - // - for (int i = 0; i < count; i++) - { - // - bool isOwn = mData[i].IsOwn( - signal.symbol, - signal.provider, - signal.period, - ToPositionType(signal.type) // - ); - if (isOwn) - { - mData[i].Fill(signal); - } - } - } - - // - void RemoveSignal(XSignal &signal) - { - // - if (!signal.IsValid()) - { - return; - } - - // - int signalIDX = -1; - ENUM_X_POSITION_TYPES xType = ToPositionType(signal.type); - bool hasSignal = HasItem( - signal.symbol, - signal.provider, - signal.period, - xType, - signalIDX // - ); - if (!hasSignal || !IsValidIndex(signalIDX)) - { - return; - } - - // - // Remove Item From List ... - ArrayRemove( - mData, - signalIDX, - 1 // - ); - } - - // - // Do all Protections ... - void HandleProtection() - { - // - int count = Count(); - if (!IsValidSize(count)) - { - return; - } - - // - // Do Hedging ... - if (mAllowHedging) - { - // - // Retrieve Positions ... - XPosition positions[]; - int positionsCount = mTrader.GetPositions( - positions // - ); - - // - bool isParamsValid = - mHedgeVolumeFactor > 0 && - mHedgeMinProfitPerVolumeFactor > 0; - - // - bool isCountValid = mMinTradesForHedge <= 0 - ? positionsCount >= 1 - : positionsCount >= mMinTradesForHedge; - - // - // Validate State ... - if (isParamsValid && isCountValid) - { - // - double swaps = 0; - double profits = 0; - double volumes = 0; - double commissions = 0; - double requiredProfitsForHedge = 0; - CalculateHedgeData( - positions, - swaps, - profits, - volumes, - commissions, - requiredProfitsForHedge // - ); - - // - bool canHedge = profits >= requiredProfitsForHedge; - if (canHedge) - { - // - string comment = "Hedging ..."; - - // - if (IsValidSize(positionsCount)) - { - // - int closeds = mTrader.Close( - positions, - comment // - ); - if (IsValidSize(closeds)) - { - // - string msg = ToString(positionsCount) + " Closed Due Hedge Action in: " + ToString(profits) + " ..."; - Alert(msg); - - // - return; - } - } - } - } - } - - // - // Do Force Closing ... - - // - // Loop through Data ... - for (int i = 0; i < count; i++) - { - // - ulong ticket = mData[i].ticket; - double profit = mData[i].profit; - double volume = mData[i].volume; - string symbol = mData[i].symbol; - string provider = mData[i].provider; - bool isLong = IsLong(mData[i].type); - ENUM_TIMEFRAMES period = mData[i].period; - double points = GetPoints(mData[i].symbol); - bool ignoreTPOnTrail = mData[i].ignoreTPOnTrail; - double recoveryTPPoint = mData[i].recoveryTPPoint; - double recoverySLPoint = mData[i].recoverySLPoint; - int maxAllowedRecover = mData[i].maxAllowedRecover; - double trailStepInPoints = mData[i].trailStepInPoint; - double trailStartInPoint = mData[i].trailStartInPoint; - bool trailBasedOnProfit = mData[i].trailBasedOnProfit; - double recoveryVolumeMultiplier = mData[i].recoveryVolumeMultiplier; - - // - XPosition iPosition; - bool hasPosition = mTrader.GetPosition( - ticket, - iPosition // - ); - if (!hasPosition) - { - continue; - } - - // - // Allow Trail Only for Positions Which - // doesnt Have Any Support ... - bool iHasSupport = mTrader.HasSupport( - ticket // - ); - if (iHasSupport) - { - continue; - } - - // - // Try to Detect Recovered Positions ... - - // - XPosition positions[]; - XPosition recoveries[]; - int recoveriesCount = 0; - int positionsCount = mTrader.GetPositions( - positions, - symbol, - provider, - period // - ); - if (positionsCount > 0) - { - // - recoveriesCount = ExtractRecoveries( - ticket, - positions, - recoveries // - ); - } - - // - // Handle Recovery Break Event if Hedging is Disabled ... - if (mData[i].allowRecover) - { - // - if (mData[i].recoveryLevel <= 0) - { - // - if (profit > 0 && iPosition.tp == 0) - { - // - double proftiInPoints = profit / volume; - bool canClose = proftiInPoints >= recoveryTPPoint; - if (canClose) - { - // - string comment = "Recovery TP ..."; - bool isClosed = mTrader.Close( - ticket, - comment // - ); - if (isClosed) - { - // - string msg = "Position (" + ToString(ticket) + ") Hit's Recovery TP ..."; - Alert(msg); - break; - } - } - } - } - else - { - // - if (recoveriesCount > 0 && !mAllowHedging) - { - // - XPosition mustClose[]; - AddRef( - iPosition, - mustClose // - ); - - // - // Summary Calculations ... - double rVolume = volume; - double rProfit = profit; - bool hasMaxVolume = false; - double rSwap = mData[i].swap; - double rCommission = mData[i].commission; - for (int j = 0; j < recoveriesCount; j++) - { - // - rSwap += recoveries[j].swap; - rProfit += recoveries[j].profit; - rVolume += recoveries[j].volume; - rCommission += mTrader.GetPositionCommission(recoveries[j].ticket); - - // - if (!hasMaxVolume && - mMaxAllowedRecoveryVolume > 0 && - recoveries[j].volume >= mMaxAllowedRecoveryVolume) - { - hasMaxVolume = true; - } - - // - AddRef( - recoveries[j], - mustClose // - ); - } - double profitSummary = - rProfit + (-1 * rSwap) - MathAbs(rCommission); - - // - double requiredProfitPoints = recoveriesCount * recoveryTPPoint; - // if (mData[i].recoveryLevel >= 2) - // { - // // - // requiredProfitPoints /= mData[i].recoveryLevel; - // if (requiredProfitPoints < recoveryTPPoint) - // { - // requiredProfitPoints = recoveryTPPoint; - // } - // } - - // - if (profitSummary > 0) - { - // - double rProfitInPoints = profitSummary / volume; - - // - bool canFinishRecovery = rProfitInPoints >= requiredProfitPoints; - if (canFinishRecovery) - { - // - // Here we Have to close All Recoveries - // and Position it Self ... - - // - string comment = "Recovery Done ..."; - - // - int closeds = mTrader.Close( - mustClose, - comment // - ); - if (closeds > 0) - { - // - string msg = "EQM Done Recovery (" + ToString(closeds) + ") Positions ..."; - Alert(msg); - - // - break; - } - } - } - - // - Clean(mustClose); - Clean(positions); - Clean(recoveries); - } - } - } - - // - // Retriece CIndex Bar ... - XOHCL cBar; - bool isBarInited = cBar.Init( - symbol, - period, - 1 // - ); - if (!isBarInited) - { - continue; - } - - // - // For Trend ... - XOHCL tmpHSW[]; - XOHCL tmpLSW[]; - - // - // Detect Bullish/Bearish Patterns and Trends ... - - // - // Bullish ... - bool hasBullishPower = cBar.HasBullishPower(); - bool hasBullishPattern = HasBullishPattern(cBar); - bool hasBullishPressure = cBar.HasBullishPressure(); - bool isBullishTrend = cBar.HasBullishTrend( - tmpHSW, - tmpLSW, - true // - ); - bool hasBullishSigns = - // - // isBullishTrend && - cBar.IsBullish() && - hasBullishPattern && - (hasBullishPower && - hasBullishPressure) - // - ; - - // - // Bearish ... - bool hasBearishPower = cBar.HasBearishPower(); - bool hasBearishPattern = HasBearishPattern(cBar); - bool hasBearishPressure = cBar.HasBearishPressure(); - bool isBearishTrend = cBar.HasBearishTrend( - tmpHSW, - tmpLSW, - true // - ); - bool hasBearishSigns = - // - // isBearishTrend && - cBar.IsBearish() && - hasBearishPressure && - (hasBearishPower && - hasBearishPattern) - // - ; - - // - // Trail ... - if (mData[i].allowTrailStop) - { - // - // Do Trail ... - - // - // Only Can Trail if Position In Profit ... - if (profit > 0) - { - // - // Current Profit ... - double profitInPoints = (profit / volume); - - // - // Check Trailling Method ... - if (trailBasedOnProfit) - { - // - // if Trailling Method is Based on Profits Growing - // these Values must Greater than 0 ... - if (trailStartInPoint > 0 && trailStepInPoints > 0) - { - // - double requiredProfit = trailStartInPoint + (mData[i].trailLevel * trailStepInPoints); - bool isProfitPassed = profitInPoints >= requiredProfit; - if (isProfitPassed) - { - // - // Calculate new Level SL ... - double sl = - isLong - ? iPosition.entry + (mData[i].trailLevel * (trailStepInPoints * points)) - : iPosition.entry - (mData[i].trailLevel * (trailStepInPoints * points)); - sl = NormalizePrice( - sl, - symbol // - ); - - // - // Calculate TP ... - double tp = - ignoreTPOnTrail - ? 0 - : iPosition.tp; - - // - if (sl != iPosition.sl) - { - // - bool isModified = mTrader.Modify( - ticket, - sl, - tp // - ); - if (isModified) - { - // - // Increase Trail Level ... - mData[i].trailLevel++; - - // - string msg = "Position (" + ToString(ticket) + ") Stops in Level: " + ToString(mData[i].trailLevel) + " Trailed Successfully ..."; - Alert(msg); - } - } - } - } - } - else - { - // - // Handle Trailling Based On Bars ... - - // - bool canTrail = true; - if (trailStartInPoint > 0) - { - // - // Check Profit ... - canTrail = profitInPoints >= trailStartInPoint; - } - - // - if (canTrail) - { - // - // Zero Index Bar ... - XOHCL zBar; - bool isInited = zBar.Init( - symbol, - period, - 0 // - ); - if (isInited) - { - // - // Get Previous Bar ... - XOHCL cBar; - isInited = zBar.GetPreviousBar(cBar); - if (isInited) - { - // - // Get Prev of Previous Bar ... - XOHCL pBar; - isInited = cBar.GetPreviousBar(pBar); - if (isInited) - { - // - // Here we have to Check Bar Closes for - // Trailling Stops ... - canTrail = - // - isLong - ? cBar.IsBullish() && - cBar.close > pBar.open - : cBar.IsBearish() && - cBar.close < pBar.open - // - ; - if (canTrail) - { - // - // Calculate new Level SL ... - double sl = - isLong - ? cBar.low - : cBar.high; - sl = NormalizePrice( - sl, - symbol // - ); - - // - // Calculate TP ... - double tp = - ignoreTPOnTrail - ? 0 - : iPosition.tp; - - // - if (sl != iPosition.sl) - { - // - bool isModified = mTrader.Modify( - ticket, - sl, - tp // - ); - if (isModified) - { - // - // Increase Trail Level ... - mData[i].trailLevel++; - - // - string msg = "Position (" + ToString(ticket) + ") Stops in Level: " + ToString(mData[i].trailLevel) + " Trailed Successfully ..."; - Alert(msg); - } - } - } - } - } - } - } - } - } - } - - // - // Recovery ... - if (mData[i].allowRecover) - { - // - // Do Recovery ... - - // - // Check Looking for Direction ... - ENUM_X_POSITION_TYPES recoveryLookingType = mData[i].recoveryLookingType; - if (recoveryLookingType == X_POSITION_TYPE_ALL || - recoveryLookingType == X_POSITION_TYPE_NONE) - { - continue; - } - - // - bool isDirectional = recoveryLookingType == mData[i].type; - - // - bool hasPressure = - !mForcePressuresInRecovery - ? true - : isDirectional - // - // Looking For Directional Pressure ... - ? isLong - ? hasBullishSigns - : hasBearishSigns - // - // Looking For InDirectional Pressure ... - : isLong - ? hasBearishSigns - : hasBullishSigns; - - // - // Check Required Properties Validation ... - if ( - recoveryTPPoint > 0 && - recoverySLPoint > 0 && - (maxAllowedRecover <= 0 - ? true - : mData[i].recoveryLevel < maxAllowedRecover)) - { - // - // Calculate requirements ... - double distanceInPoints = (MathAbs(profit) / volume); - // double _volumeMultiplier = ((mData[i].recoveryLevel + 1) * recoveryVolumeMultiplier); - // double _volume = - // volume * (_volumeMultiplier <= 0 ? 1 : _volumeMultiplier); - double _volume = - mData[i].recoveryVolume <= 0 - ? volume * recoveryVolumeMultiplier - : mData[i].recoveryVolume; - if (mMaxAllowedRecoveryVolume > 0 && _volume > mMaxAllowedRecoveryVolume) - { - _volume = mMaxAllowedRecoveryVolume; - } - - // - string _comment = GenerateRecoveryTag(ticket); - - // - XSignal rSignal; - bool isPrepared = false; - - // - if (profit < 0 && - hasPressure && - !isDirectional && - distanceInPoints >= recoverySLPoint) - { - // - FixRecoveredPositionTPSL(iPosition); - - // - ENUM_POSITION_TYPE _type = - isLong - ? POSITION_TYPE_SELL - : POSITION_TYPE_BUY; - double _entry = GetEntry(symbol, _type); - - // - isPrepared = rSignal.Prepare( - symbol, - provider, - period, - _type, - X_ORDER_MODE_MARKET, - _entry, - _volume, - 0, - 0 // - ); - } - else if (profit >= 0 && - hasPressure && - isDirectional) - { - // - FixRecoveredPositionTPSL(iPosition); - - // - ENUM_POSITION_TYPE _type = - isLong - ? POSITION_TYPE_BUY - : POSITION_TYPE_SELL; - double _entry = GetEntry(symbol, _type); - - // - isPrepared = rSignal.Prepare( - symbol, - provider, - period, - _type, - X_ORDER_MODE_MARKET, - _entry, - _volume, - 0, - 0 // - ); - } - - // - if (isPrepared && rSignal.IsValid()) - { - // - // Attach Recovery Tag ... - rSignal.comment = _comment; - - // - // Execute Recovery Signal ... - bool isExecuted = ExecuteRecoverySignal(rSignal); - if (isExecuted) - { - // - // Increase Recovery Level ... - mData[i].recoveryLevel++; - mData[i].recoveryVolume = _volume * recoveryVolumeMultiplier; - - // - // Try to Reverse Looking for Next Recovery - // Position Type ... - ENUM_POSITION_TYPE _type; - bool isConverted = ToPositionType( - _type, - recoveryLookingType // - ); - if (isConverted) - { - mData[i].recoveryLookingType = GetOppositPositionType(_type); - } - } - } - } - } - } - } - - // - // Do Position Protecting ... - void HandlePositionProtecting() - { - // - if (!mAllowProtectPositions) - { - return; - } - - // - XPosition mainPositions[]; - - // - XPosition positions[]; - int positionsCount = mTrader.GetPositions( - positions, - NULL, // All Symbols ... - NULL, // All Providers ... - NULL, // All Periods ... - NULL, // All Types ... - true // Filter By Magic ... - ); - if (!IsValidSize(positions)) - { - return; - } - - // - // Filter Main Positions ... - for (int i = 0; i < positionsCount; i++) - { - // - XPosition iPosition = positions[i]; - if (!iPosition.IsValid()) - { - continue; - } - - // - // Check Support or Recovery ... - bool isSupport = IsSupport(iPosition.comment); - bool isRecovery = ExtractRecoveredTicket(iPosition.comment) > 0; - if (isSupport || isRecovery) - { - continue; - } - - // - AddRef( - iPosition, - mainPositions // - ); - } - - // - int mainPositionsCount = ArraySize(mainPositions); - if (!IsValidSize(mainPositionsCount)) - { - return; - } - - // - // Loop Through Main Positions ... - for (int i = 0; i < mainPositionsCount; i++) - { - // - XPosition iPosition = mainPositions[i]; - if (!iPosition.IsValid()) - { - continue; - } - - // - // Find iPosition Related TradeData ... - int idx = -1; - bool hasItem = HasItem( - iPosition.ticket, - idx // - ); - if (!hasItem) - { - continue; - } - - // - XTradeData iData = mData[idx]; - if (!iData.IsValid()) - { - continue; - } - - // - // Now we Have a Main Positions and - // we Make Sure this Position has a TradeData Model ... - // Next things is Extract it's Support Positions ... - XPosition supports[]; - for (int j = 0; j < positionsCount; j++) - { - // - XPosition jPosition = positions[j]; - - // - bool isSupport = IsSupport(jPosition.comment); - if (!isSupport) - { - continue; - } - - // - ulong parentTicket = ExtractSupportedTicket(jPosition.comment); - if (parentTicket != iPosition.ticket) - { - continue; - } - - // - AddRef( - jPosition, - supports // - ); - } - - // - int supportsCount = ArraySize(supports); - - // - // Collect Main Position Related Data ... - - // - // Hold a Position and All of it's Supports ... - XPosition iPack[]; - - // - // Fill Pack ... - AddRef( - iPosition, - iPack // - ); - - // - if (IsValidSize(supportsCount)) - { - // - Copy( - supports, - iPack // - ); - } - - // - int iPackCount = ArraySize(iPack); - if (!IsValidSize(iPackCount)) - { - continue; - } - - // - double volume = 0; - double profit = 0; - double commission = 0; - - // - // Calculate Required Datas ... - for (int j = 0; j < iPackCount; j++) - { - // - XPosition jPosition = iPack[j]; - if (!jPosition.IsValid()) - { - continue; - } - - // - XPosition uPosition; - bool hasPosition = mTrader.GetPosition( - jPosition.ticket, - uPosition // - ); - if (!hasPosition) - { - continue; - } - - // - volume += uPosition.volume; - profit += uPosition.profit; - - // - double jCommission = mTrader.GetPositionCommission(jPosition.ticket); - commission += jCommission; - } - - // - // here we have to Check Protection Conditions ... - - // - // Check Position State ... - bool isInProfit = profit > 0; - - // - // Based On Single Position ... - if (iPackCount == 1) - { - // - // Based on Profit ... - if (isInProfit) - { - } - // - // Based On DrawDown ... - else - { - } - } - // - // Multiple Protected Positions ... - else - { - // - // Based on Profit ... - if (isInProfit) - { - } - // - // Based On DrawDown ... - else - { - } - } - } - } - - // - // Validate Signal For Execution ... - bool CanExecute(XSignal &signal) - { - // - bool result = false; - - // - // Validate Signal ... - result = signal.IsValid(); - if (!result) - { - return result; - } - - // - // TODO: - // Here we can apply Same type or Opposit Type - // Signals behaviour ... - // also check For Market Open ... - - // - // Check Market ... - // TODO: Fix this ... - // result = mSymbolSession.CanTrade(signal.symbol); - // if (!result) { - // return result; - // } - - // - return result; - } - - // - bool ExecuteSignal( - XSignal &signal, // Signal for Execution - ENUM_X_SIGNAL_EXECUTION_RESULT &state, // Execution State - bool ignorePolicies = false // Ignore Execution Policies - ) - { - // - bool result = false; - - // - // Check Signal Validation ... - result = signal.IsValid(); - if (!result) - { - return result; - } - - // - // Filter Signals if Necessary ... - result = CanExecute(signal); - if (!result) - { - // - state = X_SIGNAL_EXECUTION_FAILED_INVALID_PARAMS; - return result; - } - - // - // Check Policies ... - if (!ignorePolicies) - { - // - bool isLong = IsLong(signal.type); - - // - // Check Allow Trade Type ... - result = - isLong - ? mAllowLong - : mAllowShort; - if (!result) - { - // - state = X_SIGNAL_EXECUTION_FAILED_NOT_ALLOWED; - return result; - } - - // - // Check Trades Count ... - if (mMaxAllowedLongs > 0 || mMaxAllowedShorts > 0) - { - // - XPosition longs[]; - XPosition shorts[]; - - // - // Counting Positions ... - if (mUseMaxAllowedTradesPerSymbol) - { - // - mTrader.GetPositions( - longs, - shorts, - signal.symbol // - ); - } - else - { - // - mTrader.GetPositions( - longs, - shorts, - NULL // All Symbols ... - ); - } - - // - int longsCount = ArraySize(longs); - int shortsCount = ArraySize(shorts); - - // - result = - // - // Long ... - isLong - ? mMaxAllowedLongs <= 0 - ? true - : longsCount < mMaxAllowedLongs - // - // Short ... - : mMaxAllowedShorts <= 0 - ? true - : shortsCount < mMaxAllowedShorts - // - ; - if (!result) - { - // - state = X_SIGNAL_EXECUTION_FAILED_MAX_REACHED; - return result; - } - } - - // - // Check Drawdown ... - if (mMaxDrawdownPercentForOpenTrades > 0) - { - // - drawdownPercent = GetMaxDrawdown(); - - // - result = - drawdownPercent <= 0 - ? true - : drawdownPercent < mMaxDrawdownPercentForOpenTrades; - if (!result) - { - // - state = X_SIGNAL_EXECUTION_FAILED_NO_EQUITY; - return result; - } - } - } - - // - // Execute Signal ... - result = mTrader.ExecuteSignal( - signal, - state // - ); - if (result) - { - // - double commission = mTrader.GetPositionCommission(signal.positionId); - - // - // Add Signal to Trade Handler ... - AddData( - signal, - commission // - ); - - // - string msg = (signal.type == POSITION_TYPE_BUY ? "Long" : "Short") + - " Signal Provided by: " + signal.provider + - (signal.pushers > 1 ? " Pushers: " + ToString(signal.pushers) : "") + - " on: " + signal.symbol + - " in: " + ToString(signal.period) + - " Executed Successfully ..."; - Alert(msg); - } - - // - return result; - } - - // - // Protected ... -protected: - // - // Props ... - - // - bool mSaveSignals; // Save Signals - bool mSaveTrades; // Save Trades - bool mSaveConditions; // Save SL Conditions - - // - XSymbolSessionParser mSymbolSession; // Check Symbol Session - - // - bool mAllowLong; // Allow Long/Buy Trade Type - bool mAllowShort; // Allow Short/Sell Trade Type - int mMaxAllowedLongs; // Max Allowe Long/Buy Trades - int mMaxAllowedShorts; // Max Allowe Short/Sell Trades - bool mUseMaxAllowedTradesPerSymbol; // Use Max Allowed Trades Per Symbol - double mMaxDrawdownPercentForOpenTrades; // Max Drawdown Percent for Open Trades - - // - XSCTrade *mTrader; // Instance of Trader Class - XTradeCollector *mCollector; // Instance of Trade Collector Class - - // - // Trailling ... - bool mAllowTrailStops; // Trail All Trades Stops - bool mIgnoreTPOnTrail; // Ignore SL Trailed TP - bool mTrailBasedOnProfit; // Do Trail Based on Profit Points - double mTrailStartInPoint; // Trail Starts in Points of Profit - double mTrailStepInPoint; // Profit Must Grows Point to do Trailling - - // - // Recovery ... - bool mAllowRecover; // Allow Signal Recovery - int mMaxAllowedRecover; // Max Allowed Recovery - double mRecoveryTPPoint; // Recovery TP in Points - double mRecoverySLPoint; // Recovery SL in Points - bool mForcePressuresInRecovery; // Use Direction Pressures In Recovery - double mRecoveryVolumeMultiplier; // Recovery Volume Multiplier - double mMaxAllowedRecoveryVolume; // Max Allowed Recovery Volume - - // - // Hedging ... - bool mAllowHedging; // Hedge Trades - int mMinTradesForHedge; // Minimum Open Trades for Do Hedge - double mHedgeVolumeFactor; // Hedging Volume Factor - double mHedgeMinProfitPerVolumeFactor; // Hedging Min Required Profit Per Volume Factor - - // - // Position Protecting ... - - // - bool mAllowProtectPositions; // Allow Protect Positions - - // - XTradeData mData[]; // Hold Trade Data - - // - // Private ... -private: - // - // Props ... - int maxSameTimeTrades; // Max Same Time Trades - double maxDrawdown; // Max Drawdown - double drawdownPercent; // Drawdown Percent - double staticBalanceForCalculateDrawdown; // Static Balance for Max Drawdown Calculation - - // - // Count Data ... - int Count() - { - return ArraySize(mData); - } - - // - // Add Item ... - bool Add(XTradeData &item) - { - // - bool result = false; - - // - result = item.IsValid(); - if (!result) - { - return result; - } - - // - int index = -1; - if (item.ticket > 0) - { - // - result = !HasItem( - item.ticket, - index // - ); - } - else - { - // - result = !HasItem( - item.symbol, - item.provider, - item.period, - item.type, - index // - ); - } - if (!result || IsValidIndex(index)) - { - // - result = false; - return result; - } - - // - AddRef( - item, - mData // - ); - - // - return result; - } - - // - // Find Item Index ... - bool HasItem( - ulong ticket, - int &index // - ) - { - // - bool result = false; - - // - index = -1; - - // - int count = Count(); - result = IsValidSize(count); - if (!result) - { - return result; - } - - // - for (int i = 0; i < count; i++) - { - // - result = mData[i].IsOwn(ticket); - if (result) - { - // - index = i; - break; - } - } - - // - return result; - } - - // - // Find Item Index ... - bool HasItem( - string symbol, - string provider, - ENUM_TIMEFRAMES period, - ENUM_X_POSITION_TYPES type, - int &index // - ) - { - // - bool result = false; - - // - index = -1; - - // - // Validate ... - result = - // - IsValid(symbol) && - IsValid(period) && - IsValid(provider) && - type != X_POSITION_TYPE_ALL && - type != X_POSITION_TYPE_NONE - // - ; - if (!result) - { - return result; - } - - // - int count = Count(); - result = IsValidSize(count); - if (!result) - { - return result; - } - - // - for (int i = 0; i < count; i++) - { - // - result = mData[i].IsOwn( - symbol, - provider, - period, - type // - ); - if (result) - { - // - index = i; - break; - } - } - - // - return result; - } - - // - void Save(int index) - { - // - int count = Count(); - if (!IsValidIndex(index) || index > count - 1) - { - return; - } - - // - // Save Trade ... - if (mSaveTrades) - { - mCollector.Save(mData[index]); - } - - // - if (mSaveConditions) - { - mCollector.SaveConditions(mData[index]); - } - - // - // Remove Item From List ... - ArrayRemove( - mData, - index, - 1 // - ); - } - - // - void SaveSignal(XTradeData &item) - { - // - if (!mSaveSignals) - { - return; - } - - // - // Save Signal ... - mCollector.SaveSignal(item); - } - - // - // Calculate Required Data for Hedging ... - void CalculateHedgeData( - double &profits, - double &commissions, - double &requiredProfitsForHedge // - ) - { - // - // Reset Values ... - profits = 0; - commissions = 0; - requiredProfitsForHedge = 0; - - // - // Validate Configurations ... - if (mHedgeVolumeFactor <= 0 || - mHedgeMinProfitPerVolumeFactor <= 0) - { - return; - } - - // - // Check Positions Exists For Hedging ... - int count = Count(); - if (!IsValidSize(count)) - { - return; - } - - // - double swaps = 0; - double volumes = 0; - for (int i = 0; i < count; i++) - { - // - swaps += mData[i].swap; - profits += mData[i].profit; - volumes += mData[i].volume; - commissions += mData[i].commission; - } - - // - // Calculate required Profits for Hedging ... - requiredProfitsForHedge = ((volumes / mHedgeVolumeFactor) * mHedgeMinProfitPerVolumeFactor); - requiredProfitsForHedge += -1 * (swaps); - requiredProfitsForHedge -= commissions; - } - - // - // Calculate Required Data for Hedging ... - void CalculateHedgeData( - XPosition &positions[], - double &swaps, - double &profits, - double &volumes, - double &commissions, - double &requiredProfitsForHedge // - ) - { - // - // Reset Values ... - swaps = 0; - profits = 0; - volumes = 0; - commissions = 0; - requiredProfitsForHedge = 0; - - // - // Validate Configurations ... - if (mHedgeVolumeFactor <= 0 || - mHedgeMinProfitPerVolumeFactor <= 0) - { - return; - } - - // - // Check Positions Exists For Hedging ... - int count = ArraySize(positions); - if (!IsValidSize(count)) - { - return; - } - - // - for (int i = 0; i < count; i++) - { - // - XPosition iPosition = positions[i]; - double iCommission = mTrader.GetPositionCommission(iPosition.ticket); - - // - swaps += iPosition.swap; - profits += iPosition.profit; - volumes += iPosition.volume; - commissions += MathAbs(iCommission); - } - - // - // Calculate required Profits for Hedging ... - requiredProfitsForHedge = ((volumes / mHedgeVolumeFactor) * mHedgeMinProfitPerVolumeFactor); - requiredProfitsForHedge += commissions; - requiredProfitsForHedge += -1 * (swaps); - } - - // - bool FixRecoveredPositionTPSL(XPosition &position) - { - // - bool result = false; - - // - result = position.IsValid(); - if (!result) - { - return result; - } - - // - double points = GetPoints(position.symbol); - - // // - // // Try to Remove SL and TP of Recovery Signals ... - // if (position.sl > 0 || position.tp > 0) - // { - // // - // string comment = "EQM Recover Remove TP/SL"; - // result = mTrader.Modify( - // position.ticket, - // 0, - // 0, - // comment // - // ); - // } - - // - // Try to Remove TP of Recovery Signals ... - if (position.tp > 0) - { - // - double tp = 0; - bool isLong = IsLong(position.type); - double reward = MathAbs(position.tp - position.entry) / points; - if (reward <= mRecoveryTPPoint) - { - // - reward = (mRecoveryTPPoint * 2 * points); - tp = - isLong - ? position.entry + reward - : position.entry - reward; - tp = NormalizePrice(tp, position.symbol); - } - - // - string comment = "EQM Recover Fix TP/SL"; - result = mTrader.Modify( - position.ticket, - position.sl, - tp, - comment // - ); - } - - // - return result; - } - - // - bool ExecuteRecoverySignal(XSignal &signal) - { - // - bool result = false; - - // - ENUM_X_SIGNAL_EXECUTION_RESULT state; - result = mTrader.ExecuteSignal( - signal, - state, - ORDER_TIME_GTC, - NULL, - false // - ); - - // - return result; - } - - // -}; - // \ No newline at end of file diff --git a/Documents/BKP/tmp b/Documents/BKP/tmp new file mode 100644 index 00000000..6ee437bd --- /dev/null +++ b/Documents/BKP/tmp @@ -0,0 +1,60 @@ + + // + string symbol = GetSymbol(); + ENUM_TIMEFRAMES period = GetPeriod(); + + // + int zIndex = barIndex; + int cIndex = zIndex + 1; + int pIndex = cIndex + 1; + int ppIndex = pIndex + 1; + + // + bool isInited = false; + // + XOHCL zBar; + isInited = zBar.Init( + symbol, + period, + zIndex // + ); + if (!isInited) + { + return result; + } + + // + XOHCL cBar; + isInited = cBar.Init( + symbol, + period, + cIndex // + ); + if (!isInited) + { + return result; + } + + // + XOHCL pBar; + isInited = pBar.Init( + symbol, + period, + pIndex // + ); + if (!isInited) + { + return result; + } + + // + XOHCL ppBar; + isInited = ppBar.Init( + symbol, + period, + ppIndex // + ); + if (!isInited) + { + return result; + } diff --git a/Classes/x-saherelm.x-chart-objects.class.mq5 b/Documents/BKP/x-saherelm.x-chart-objects.class.mq5 similarity index 100% rename from Classes/x-saherelm.x-chart-objects.class.mq5 rename to Documents/BKP/x-saherelm.x-chart-objects.class.mq5 diff --git a/Documents/BKP/x-saherelm.x-poi.class.mq5 b/Documents/BKP/x-saherelm.x-poi.class.mq5 new file mode 100644 index 00000000..13928bb8 --- /dev/null +++ b/Documents/BKP/x-saherelm.x-poi.class.mq5 @@ -0,0 +1,7778 @@ +/////////////////////////////////////////////////////// +// +// SaherElm IT Center MQL5 Class Library +// -------------------------------------- +// Name: XPOI +// Description: Provides Point of Interests ... +// - Swing Highs; +// - Swing Lows; +// +// Maintainer: +// ------------ +// Hadi Khazaee Asl (hadi_khazaee_asl@yahoo.com) +// +////////////////////////////////////////////////////// +// +// Global Properties ... +#property library +#property copyright "Copyright 2023, SaherElm IT Center" +#property link "https://www.saherelm.ir" +#property version "1.00" +#property strict + +// +// Imports ... + +// +#include "../Classes/x-saherelm.x-poi.drawer.class.mq5" +#include "../Classes/x-saherelm.xalert.class.mq5" + +// +#include + +// +// Implementation ... + +// +class XCPOI : public XSCBaseAlert +{ + // + public: + // + + // + // Constructors ... + /** + * Create an Instance ... + * + * @param symbol: String ... + * @param period: ENUM_TIMEFRAMES member ... + */ + void XCPOI( + string symbol, + ENUM_TIMEFRAMES period // + ) + { + // + // Attach Required Properties ... + mSymbol = symbol; + mPeriod = period; + + // + // Initialize Bar Tracker ... + mBarTracker.Init( + mSymbol, + mPeriod // + ); + + // + mDrawer = new XCPOIDrawer(); + + // + // Apply Default Configurations ... + ApplyDefaultConfig(); + } + + // + // Deconstructor ... + void ~XCPOI() + { + // + DestroyPOIs(); + DestroyObjects(); + DestroySessions(); + DestroyEventListeners(); + + // + delete mDrawer; + } + + // + // Getter(s) / Setter(s) ... + + /** + * Get Chart ID ... + * + * @return ( long ) + */ + long ChartIdentification() + { + return mChartIdentification; + } + + /** + * Set Chart ID ... + * + * @param value: Long + */ + void ChartIdentification(long value) + { + // + if (value < 0) + { + value = 0; + } + + // + mChartIdentification = value; + if (mDrawer != NULL) + { + mDrawer.ChartIdentification(value); + } + } + + /** + * Get Sub SubWindowIdentification Number ... + * + * @return ( int ) + */ + int SubWindowIdentification() + { + return mSubWindowIdentification; + } + + /** + * Get Sub SubWindowIdentification Number ... + * + * @param value: Integer ... + */ + void SubWindowIdentification(int value) + { + // + if (value < 0) + { + value = 0; + } + + // + mSubWindowIdentification = value; + if (mDrawer != NULL) + { + mDrawer.SubWindowIdentification(value); + } + } + + /** + * Get Max Number of POIs which holds ... + * + * @return ( int ) + */ + int MaxNumberOfPOIs() + { + return mMaxNumberOfPOIs; + } + + /** + * Set Max Number of POIs which holds ... + * 0 => Infinity ... + * + * @param value: Integer ... + */ + void MaxNumberOfPOIs(int value) + { + // + if (value < 0) + { + value = 0; + } + + // + mMaxNumberOfPOIs = value; + } + + /** + * Get Number of POI(s) which must Find at Initializations ... + * + * @return ( int ) + */ + int MaxNumberOfRequiredPOIs() + { + return mMaxNumberOfRequiredPOIs; + } + + /** + * Set Number of POI(s) which must Find at Initializations ... + * 2 is Default ... + * + * @param value: Integer ... + */ + void MaxNumberOfRequiredPOIs(int value) + { + // + if (value < 2) + { + value = 2; + } + + // + mMaxNumberOfRequiredPOIs = value; + } + + /** + * Check Is Locked or not ... + * + * @return ( bool ) + */ + bool IsLocked() + { + return mLock; + } + + // + // POI(s) Configs ... + + // + // Trading Days ... + + /** + * Get Detect Trading Days State ... + * + * @return ( bool ) + */ + bool AllowTradingDays() + { + return mAllowTradingDays; + } + + /** + * Set Detect Trading Days State ... + * + * @param value: Boolean ... + */ + void AllowTradingDays(bool value) + { + mAllowTradingDays = value; + } + + /** + * Get Draw Trading Days State ... + * + * @return ( bool ) + */ + bool AllowDrawTradingDays() + { + return mAllowDrawTradingDays; + } + + /** + * Set Draw Trading Days State ... + * + * @param value: Boolean ... + */ + void AllowDrawTradingDays(bool value) + { + mAllowDrawTradingDays = value; + } + + /** + * Get Trading Days Start Color ... + * + * @return ( color ) + */ + color TradingDaysStartColor() + { + return mTradingDaysStartColor; + } + + /** + * Set Trading Days Start Color ... + * + * @param value: Argument 1 + */ + void TradingDaysStartColor(color value) + { + mTradingDaysStartColor = value; + } + + /** + * Get Trading Days Start Style ... + * + * @return ( ENUM_LINE_STYLE ) + */ + ENUM_LINE_STYLE TradingDaysStartStyle() + { + return mTradingDaysStartStyle; + } + + /** + * Set Trading Days Start Style ... + * + * @param value: ENUM_LINE_STYLE member ... + */ + void TradingDaysStartStyle(ENUM_LINE_STYLE value) + { + mTradingDaysStartStyle = value; + } + + /** + * Get Trading Days End Color ... + * + * @return ( color ) + */ + color TradingDaysEndColor() + { + return mTradingDaysEndColor; + } + + /** + * Set Trading Days End Color ... + * + * @param value: Argument 1 + */ + void TradingDaysEndColor(color value) + { + mTradingDaysEndColor = value; + } + + /** + * Get Trading Days End Style ... + * + * @return ( ENUM_LINE_STYLE ) + */ + ENUM_LINE_STYLE TradingDaysEndStyle() + { + return mTradingDaysEndStyle; + } + + /** + * Set Trading Days End Style ... + * + * @param value: ENUM_LINE_STYLE member ... + */ + void TradingDaysEndStyle(ENUM_LINE_STYLE value) + { + mTradingDaysEndStyle = value; + } + + // + // Sessions ... + + /** + * Get Detect Market Sessions State ... + * + * @return ( bool ) + */ + bool AllowMarketSessions() + { + return mAllowMarketSessions; + } + + /** + * Set Detect Market Sessions State ... + * + * @param value: Boolean ... + */ + void AllowMarketSessions(bool value) + { + mAllowMarketSessions = value; + } + + /** + * Get Draw Market Sessions State ... + * + * @return ( bool ) + */ + bool AllowDrawMarketSessions() + { + return mAllowDrawMarketSessions; + } + + /** + * Set Draw Market Sessions State ... + * + * @param value: Boolean ... + */ + void AllowDrawMarketSessions(bool value) + { + mAllowDrawMarketSessions = value; + } + + /** + * Get Session Working Hors ... + * + * @return ( int ) + */ + int SessionOpenHours() + { + return mSessionOpenHours; + } + + /** + * Set Session Working Hors ... + * + * @param value: Integer ... + */ + void SessionOpenHours(int value) + { + // + if (value <= 0) + { + value = 9; + } + + // + mSessionOpenHours = value; + } + + // + // Swing High ... + + /** + * Get Detect Swing Highs State ... + * + * @return ( bool ) + */ + bool AllowSwingHighs() + { + return mAllowSwingHighs; + } + + /** + * Set Detect Swing Highs State ... + * + * @param value: Boolean + */ + void AllowSwingHighs(bool value) + { + mAllowSwingHighs = value; + } + + /** + * Get Draw Swing Highs State ... + * + * @return ( bool ) + */ + bool AllowDrawSwingHighs() + { + return mAllowDrawSwingHighs; + } + + /** + * Set Draw Swing Highs State ... + * + * @param value: Boolean + */ + void AllowDrawSwingHighs(bool value) + { + mAllowDrawSwingHighs = value; + } + + /** + * Get Threshold Required for Swing High Detection ... + * + * @return ( double ) + */ + double SwingHighThreshold() + { + return mSwingHighThreshold; + } + + /** + * Set Threshold Required for Swing High Detection ... + * + * @param value: Double ... + */ + void SwingHighThreshold(double value) + { + // + if (value < 0) + { + value = 0; + } + + // + mSwingHighThreshold = value; + } + + // + // Swing Low ... + + /** + * Get Detect Swing Lows State ... + * + * @return ( bool ) + */ + bool AllowSwingLows() + { + return mAllowSwingLows; + } + + /** + * Set Detect Swing Lows State ... + * + * @param value: Boolean ... + */ + void AllowSwingLows(bool value) + { + mAllowSwingLows = value; + } + + /** + * Get Draw Swing Lows State ... + * + * @return ( bool ) + */ + bool AllowDrawSwingLows() + { + return mAllowDrawSwingLows; + } + + /** + * Set Draw Swing Lows State ... + * + * @param value: Boolean + */ + void AllowDrawSwingLows(bool value) + { + mAllowDrawSwingLows = value; + } + + /** + * Get Threshold Required for Swing Low Detection ... + * + * @return ( double ) + */ + double SwingLowThreshold() + { + return mSwingLowThreshold; + } + + /** + * Set Threshold Required for Swing Low Detection ... + * + * @param value: Double ... + */ + void SwingLowThreshold(double value) + { + // + if (value < 0) + { + value = 0; + } + + // + mSwingLowThreshold = value; + } + + // + // Momentum Bars ... + + /** + * Get Detect Momentum Bars State ... + * + * @return ( bool ) + */ + bool AllowMomentumBars() + { + return mAllowMomentumBars; + } + + /** + * Set Detect Momentum Bars State ... + * + * @param value: Boolean ... + */ + void AllowMomentumBars(bool value) + { + mAllowMomentumBars = value; + } + + /** + * Get Draw Momentum Bars State ... + * + * @return ( bool ) + */ + bool AllowDrawMomentumBars() + { + return mAllowDrawMomentumBars; + } + + /** + * Set Draw Momentum Bars State ... + * + * @param value: Boolean + */ + void AllowDrawMomentumBars(bool value) + { + mAllowDrawMomentumBars = value; + } + + /** + * Get Momentum Bar Percent ... + * + * @return ( int ) + */ + int MomentumBarPercent() + { + return mMomentumBarPercent; + } + + /** + * Set Momentum Bar Percent ... + * + * @param value: Integer + */ + void MomentumBarPercent(int value) + { + // + if (value < 0) + { + value = 0; + } + + // + mMomentumBarPercent = value; + } + + /** + * Get Momentum Bar Sharp Ratio ... + * + * @return ( double ) + */ + double MomentumBarSharpRatio() + { + return mMomentumBarSharpRatio; + } + + /** + * Set Momentum Bar Sharp Ratio ... + * + * @param value: Double ... + */ + void MomentumBarSharpRatio(double value) + { + // + if (value < 0) + { + value = 0; + } + + // + mMomentumBarSharpRatio = value; + } + + /** + * Get Momentum Bar Loopback ... + * + * @return ( int ) + */ + int MomentumBarLoopBack() + { + return mMomentumBarLoopBack; + } + + /** + * Set Momentum Bar Loopback ... + * + * @param value: Integer ... + */ + void MomentumBarLoopBack(int value) + { + // + if (value < 0) + { + value = 0; + } + + // + mMomentumBarLoopBack = value; + } + + // + // Rejection Bars ... + + /** + * Get Detect Rejection Bars State ... + * + * @return ( bool ) + */ + bool AllowRejectionBars() + { + return mAllowRejectionBars; + } + + /** + * Set Detect Rejection Bars State ... + * + * @param value: Boolean ... + */ + void AllowRejectionBars(bool value) + { + mAllowRejectionBars = value; + } + + /** + * Get Draw Rejection Bars State ... + * + * @return ( bool ) + */ + bool AllowDrawRejectionBars() + { + return mAllowDrawRejectionBars; + } + + /** + * Set Draw Rejection Bars State ... + * + * @param value: Boolean ... + */ + void AllowDrawRejectionBars(bool value) + { + mAllowDrawRejectionBars = value; + } + + /** + * Get Rejection Bar Percent ... + * + * @return ( int ) + */ + int RejectionBarPercent() + { + return mRejectionBarPercent; + } + + /** + * Set Rejection Bar Percent ... + * + * @param value: Integer + */ + void RejectionBarPercent(int value) + { + mRejectionBarPercent = value; + } + + /** + * Get Rejection Bar Sharp Ratio ... + * + * @return ( double ) + */ + double RejectionBarSharpRatio() + { + return mRejectionBarSharpRatio; + } + + /** + * Set Rejection Bar Sharp Ratio ... + * + * @param value: Double ... + */ + void RejectionBarSharpRatio(double value) + { + mRejectionBarSharpRatio = value; + } + + /** + * Get Rejection Bar Loopback ... + * + * @return ( int ) + */ + int RejectionBarLoopBack() + { + return mRejectionBarLoopBack; + } + + /** + * Set Rejection Bar Loopback ... + * + * @param value: Integer ... + */ + void RejectionBarLoopBack(int value) + { + mRejectionBarLoopBack = value; + } + + // + // Support Zone ... + + /** + * Get Detect Support Zone State ... + * + * @return ( bool ) + */ + bool AllowSupportZones() + { + return mAllowSupportZones; + } + + /** + * Set Detect Support Zone State ... + * + * @param value: Boolean ... + */ + void AllowSupportZones(bool value) + { + mAllowSupportZones = value; + } + + /** + * Get Draw Support Zone State ... + * + * @return ( bool ) + */ + bool AllowDrawSupportZones() + { + return mAllowDrawSupportZones; + } + + /** + * Set Draw Support Zone State ... + * + * @param value: Boolean ... + */ + void AllowDrawSupportZones(bool value) + { + mAllowDrawSupportZones = value; + } + + /** + * Get Support Zone Loopback ... + * + * @return ( int ) + */ + int SupportZoneLoopBack() + { + return mSupportZoneLoopBack; + } + + /** + * Set Support Zone Loopback ... + * + * @param value: Integer ... + */ + void SupportZoneLoopBack(int value) + { + // + if (value < 10) + { + value = 10; + } + + // + mSupportZoneLoopBack = value; + } + + /** + * Get Support Zone Price Type ... + * + * @return ( ENUM_LINE_STYLE ) + */ + ENUM_X_PRICE SupportZonePriceType() + { + return mSupportZonePriceType; + } + + /** + * Set Support Zone Price Type ... + * + * @param value: ENUM_X_PRICE member ... + */ + void SupportZonePriceType(ENUM_X_PRICE value) + { + mSupportZonePriceType = value; + } + + // + // Resistance Zone ... + + /** + * Get Detect Resistance Zone State ... + * + * @return ( bool ) + */ + bool AllowResistanceZones() + { + return mAllowResistanceZones; + } + + /** + * Set Detect Resistance Zone State ... + * + * @param value: Boolean ... + */ + void AllowResistanceZones(bool value) + { + mAllowResistanceZones = value; + } + + /** + * Get Draw Resistance Zone State ... + * + * @return ( bool ) + */ + bool AllowDrawResistanceZones() + { + return mAllowDrawResistanceZones; + } + + /** + * Set Draw Resistance Zone State ... + * + * @param value: Boolean ... + */ + void AllowDrawResistanceZones(bool value) + { + mAllowDrawResistanceZones = value; + } + + /** + * Get Resistance Zone Loopback ... + * + * @return ( int ) + */ + int ResistanceZoneLoopBack() + { + return mResistanceZoneLoopBack; + } + + /** + * Set Resistance Zone Loopback ... + * + * @param value: Integer ... + */ + void ResistanceZoneLoopBack(int value) + { + // + if (value < 10) + { + value = 10; + } + + // + mResistanceZoneLoopBack = value; + } + + /** + * Get Resistance Zone Price Type ... + * + * @return ( ENUM_LINE_STYLE ) + */ + ENUM_X_PRICE ResistanceZonePriceType() + { + return mResistanceZonePriceType; + } + + /** + * Set Resistance Zone Price Type ... + * + * @param value: ENUM_X_PRICE member ... + */ + void ResistanceZonePriceType(ENUM_X_PRICE value) + { + mResistanceZonePriceType = value; + } + + // + // Supply Zone ... + + /** + * Get Detect Supply Zone State ... + * + * @return ( bool ) + */ + bool AllowSupplyZones() + { + return mAllowSupplyZones; + } + + /** + * Set Detect Supply Zone State ... + * + * @param value: Boolean ... + */ + void AllowSupplyZones(bool value) + { + mAllowSupplyZones = value; + } + + /** + * Get Draw Supply Zone State ... + * + * @return ( bool ) + */ + bool AllowDrawSupplyZones() + { + return mAllowDrawSupplyZones; + } + + /** + * Set Draw Supply Zone State ... + * + * @param value: Boolean ... + */ + void AllowDrawSupplyZones(bool value) + { + mAllowDrawSupplyZones = value; + } + + /** + * Get Supply Zone Detecting Period ... + * + * @return ( ENUM_TIMEFRAMES ) ... + */ + ENUM_TIMEFRAMES SupplyZonePeriod() + { + return mSupplyZonePeriod; + } + + /** + * Set Supply Zone Detecting Period ... + * + * @param value: ENUM_TIMEFRAMES member ... + */ + void SupplyZonePeriod(ENUM_TIMEFRAMES value) + { + mSupplyZonePeriod = value; + } + + // + // Demand Zone ... + + /** + * Get Detect Demand Zone State ... + * + * @return ( bool ) + */ + bool AllowDemandZones() + { + return mAllowDemandZones; + } + + /** + * Set Detect Demand Zone State ... + * + * @param value: Boolean ... + */ + void AllowDemandZones(bool value) + { + mAllowDemandZones = value; + } + + /** + * Get Draw Demand Zone State ... + * + * @return ( bool ) + */ + bool AllowDrawDemandZones() + { + return mAllowDrawDemandZones; + } + + /** + * Set Draw Demand Zone State ... + * + * @param value: Boolean ... + */ + void AllowDrawDemandZones(bool value) + { + mAllowDrawDemandZones = value; + } + + /** + * Get Demand Zone Detecting Period ... + * + * @return ( ENUM_TIMEFRAMES ) ... + */ + ENUM_TIMEFRAMES DemandZonePeriod() + { + return mDemandZonePeriod; + } + + /** + * Set Demand Zone Detecting Period ... + * + * @param value: ENUM_TIMEFRAMES member ... + */ + void DemandZonePeriod(ENUM_TIMEFRAMES value) + { + mDemandZonePeriod = value; + } + + // + // Order Blocks ... + + // + // Bullish Order Blocks ... + + /** + * Get Detect Bullish Order Blocks State ... + * + * @return ( bool ) + */ + bool AllowBullishOrderBlocks() + { + return mAllowBullishOrderBlocks; + } + + /** + * Set Detect Bullish Order Blocks State ... + * + * @param value: Boolean ... + */ + void AllowBullishOrderBlocks(bool value) + { + mAllowBullishOrderBlocks = value; + } + + /** + * Get Draw Bullish Order Blocks State ... + * + * @return ( bool ) + */ + bool AllowDrawBullishOrderBlocks() + { + return mAllowDrawBullishOrderBlocks; + } + + /** + * Set Draw Bullish Order Blocks State ... + * + * @param value: Boolean ... + */ + void AllowDrawBullishOrderBlocks(bool value) + { + mAllowDrawBullishOrderBlocks = value; + } + + /** + * Get Minimum Required Same Bars for Bullish Order Blocks ... + * + * @return ( int ) + */ + int RequiredBarsForBullishOrderBlock() + { + return mRequiredBarsForBullishOrderBlock; + } + + /** + * Set Minimum Required Same Bars for Bullish Order Blocks ... + * + * @param value: Integer ... + */ + void RequiredBarsForBullishOrderBlock(int value) + { + // + if (value < 3) + { + value = 3; + } + + // + mRequiredBarsForBullishOrderBlock = value; + } + + // + // Bearish Order Blocks ... + + /** + * Get Detect Bearish Order Blocks State ... + * + * @return ( bool ) + */ + bool AllowBearishOrderBlocks() + { + return mAllowBearishOrderBlocks; + } + + /** + * Set Detect Bearish Order Blocks State ... + * + * @param value: Boolean ... + */ + void AllowBearishOrderBlocks(bool value) + { + mAllowBearishOrderBlocks = value; + } + + /** + * Get Draw Bearish Order Blocks State ... + * + * @return ( bool ) + */ + bool AllowDrawBearishOrderBlocks() + { + return mAllowDrawBearishOrderBlocks; + } + + /** + * Set Draw Bearish Order Blocks State ... + * + * @param value: Boolean ... + */ + void AllowDrawBearishOrderBlocks(bool value) + { + mAllowDrawBearishOrderBlocks = value; + } + + /** + * Get Minimum Required Same Bars for Bearish Order Blocks ... + * + * @return ( int ) + */ + int RequiredBarsForBearishOrderBlock() + { + return mRequiredBarsForBearishOrderBlock; + } + + /** + * Set Minimum Required Same Bars for Bearish Order Blocks ... + * + * @param value: Integer ... + */ + void RequiredBarsForBearishOrderBlock(int value) + { + // + if (value < 3) + { + value = 3; + } + + // + mRequiredBarsForBearishOrderBlock = value; + } + + // + // Fair Value Gaps ... + + // + // Bullis FVGs ... + + /** + * Get Detect Bullish Fair Value Gaps State ... + * + * @return ( bool ) + */ + bool AllowBullishFVGs() + { + return mAllowBullishFVGs; + } + + /** + * Set Detect Bullish Fair Value Gaps State ... + * + * @param value: Boolean ... + */ + void AllowBullishFVGs(bool value) + { + mAllowBullishFVGs = value; + } + + /** + * Get Draw Bullish Fair Value Gaps ... + * + * @return ( bool ) + */ + bool AllowDrawBullishFVGs() + { + return mAllowDrawBullishFVGs; + } + + /** + * Set Draw Bullish Fair Value Gaps ... + * + * @param value: Boolean ... + */ + void AllowDrawBullishFVGs(bool value) + { + mAllowDrawBullishFVGs = value; + } + + /** + * Get Bullish FVG Force Middle Bar Check ... + * + * @return ( bool ) + */ + bool BullishFVGForceMiddleBarCheck() + { + return mBullishFVGForceMiddleBarCheck; + } + + /** + * Set Bullish FVG Force Middle Bar Check ... + * + * @param value: Boolean ... + */ + void BullishFVGForceMiddleBarCheck(bool value) + { + mBullishFVGForceMiddleBarCheck = value; + } + + /** + * Get Bullish FVG Force Check Last Bar Direction ... + * + * @return ( bool ) + */ + bool BullishFVGForceCheckLastBarDirection() + { + return mBullishFVGForceCheckLastBarDirection; + } + + /** + * Set Bullish FVG Force Check Last Bar Direction ... + * + * @param value: Boolean ... + */ + void BullishFVGForceCheckLastBarDirection(bool value) + { + mBullishFVGForceCheckLastBarDirection = value; + } + + // + // Bearish FVGs ... + + /** + * Get Detect Bearish Fair Value Gaps State ... + * + * @return ( bool ) + */ + bool AllowBearishFVGs() + { + return mAllowBearishFVGs; + } + + /** + * Set Detect Bearish Fair Value Gaps State ... + * + * @param value: Boolean ... + */ + void AllowBearishFVGs(bool value) + { + mAllowBearishFVGs = value; + } + + /** + * Get Draw Bearish Fair Value Gaps ... + * + * @return ( bool ) + */ + bool AllowDrawBearishFVGs() + { + return mAllowDrawBearishFVGs; + } + + /** + * Set Draw Bearish Fair Value Gaps ... + * + * @param value: Boolean ... + */ + void AllowDrawBearishFVGs(bool value) + { + mAllowDrawBearishFVGs = value; + } + + /** + * Get Bearish FVG Force Middle Bar Check ... + * + * @return ( bool ) + */ + bool BearishFVGForceMiddleBarCheck() + { + return mBearishFVGForceMiddleBarCheck; + } + + /** + * Set Bearish FVG Force Middle Bar Check ... + * + * @param value: Boolean ... + */ + void BearishFVGForceMiddleBarCheck(bool value) + { + mBearishFVGForceMiddleBarCheck = value; + } + + /** + * Get Bearish FVG Force Check Last Bar Direction ... + * + * @return ( bool ) + */ + bool BearishFVGForceCheckLastBarDirection() + { + return mBearishFVGForceCheckLastBarDirection; + } + + /** + * Set Bearish FVG Force Check Last Bar Direction ... + * + * @param value: Boolean ... + */ + void BearishFVGForceCheckLastBarDirection(bool value) + { + mBearishFVGForceCheckLastBarDirection = value; + } + + // + // Actions ... + + /** + * Initialize POI Detector ... + */ + void Init() + { + // + // Detect Previous POI(s) ... + DetectRequiredPOIs(); + } + + /** + * Update POI(s) ... + * + * @param state: an Array Refrence of ENUM_XPOI_EVENTS members ... + */ + int Update( + ENUM_XPOI_EVENTS &state[] // + ) + { + // + int result = 0; + + // + Clean(state); + + // + // Check Bar Tracker if Waits ... + if (!mBarTracker.IsNewBar()) + { + return result; + } + + // + int zIndex = 0; + int cIndex = zIndex + 1; + int pIndex = cIndex + 1; + + // + datetime cTime = TimeCurrent(); + + // + XOHCL zBar; + bool isInited = zBar.Init( + mSymbol, + mPeriod, + zIndex // + ); + if (!isInited) + { + return result; + } + + // + XOHCL cBar; + isInited = cBar.Init( + mSymbol, + mPeriod, + cIndex // + ); + if (!isInited) + { + return result; + } + + // + XOHCL pBar; + isInited = pBar.Init( + mSymbol, + mPeriod, + pIndex // + ); + if (!isInited) + { + return result; + } + + // + XOHCL zDayBar; + isInited = zDayBar.Init( + mSymbol, + PERIOD_D1, + zIndex // + ); + if (!isInited) + { + return result; + } + + // + // Trading Days ... + + // + bool allowTradingDays = AllowTradingDays(); + int tradingDaysCount = ArraySize(mTradingDays); + if (allowTradingDays) + { + // + int tradingDayIDX = HasTradeDay(zDayBar.time); + if (IsValidIndex(tradingDayIDX)) + { + // + if (zBar.time == mTradingDays[tradingDayIDX].to) + { + // + ENUM_XPOI_EVENTS event = X_TRADE_DAY_LAST_BAR; + Add( + event, + state // + ); + OnTradingDayEvent(event); + NotifyTradingDayEventListeners(event); + } + } + else + { + // + // there isn't any Trading Day ... + // create one ... + + // + XTradeDay tradeDay; + tradeDay.from = zDayBar.time; + tradeDay.to = zDayBar.GetLastBarTimeOfPeriod(mPeriod); + + // + AddRef( + tradeDay, + mTradingDays // + ); + + // + DrawTradingDays(); + + // + // Notfy Day Started ... + if (zBar.time == zDayBar.time) + { + // + Add( + X_TRADE_DAY_FIRST_BAR, + state // + ); + OnTradingDayEvent(X_TRADE_DAY_FIRST_BAR); + NotifyTradingDayEventListeners(X_TRADE_DAY_FIRST_BAR); + } + } + } + + // + // Market Session ... + + // + bool allowMarketSessions = AllowMarketSessions(); + int marketSessionsCount = ArraySize(mMarketSessions); + if (allowMarketSessions) + { + // + int sessionsCount = ArraySize(mSessions); + bool isSessionFound = false; + if (IsValidSize(sessionsCount)) + { + // + for (int i = 0; i < sessionsCount; i++) + { + // + XSession iSession = mSessions[i]; + int marketSessionIDX = HasMarketSessionByStartTime( + iSession.session, + zBar.time // + ); + + // + if (!IsValidIndex(marketSessionIDX)) + { + // + datetime zTimeGMT = GetUTCTime(zBar.time); + string zTimeString = GetTimeString(zTimeGMT); + + // + bool isStarted = iSession.start == zTimeString; + + // + if (isStarted) + { + // + XMarketSession iMarketSession; + iMarketSession.session = iSession.session; + iMarketSession.from = zBar.time; + + // + int iSessionWorkingHoure = SessionOpenHours(); + int iSessionWorkingSeconds = iSessionWorkingHoure * 60 * 60; + iMarketSession.to = (datetime)((int)zBar.time + iSessionWorkingSeconds); + + // + isSessionFound = AddRef( + iMarketSession, + mMarketSessions // + ); + + // + marketSessionsCount = ArraySize(mMarketSessions); + + // + DrawMarketSessions(); + + // + Add( + X_SESSION_FIRST_BAR, + state // + ); + OnMarketSessionEvent( + iMarketSession.session, + X_SESSION_FIRST_BAR // + ); + NotifyMarketSessionEventListeners( + iMarketSession.session, + X_SESSION_FIRST_BAR // + ); + } + } + + // + // Check End Time for Last Bar ... + for (int i = 0; i < marketSessionsCount; i++) + { + // + XMarketSession iMarketSession = mMarketSessions[i]; + + // + // Calculate Last Bar Time ... + datetime endTime = iMarketSession.to; + datetime lastBarTime = (datetime)((int)endTime - PeriodSeconds(mPeriod)); + if (zBar.time == lastBarTime) + { + // + ENUM_XPOI_EVENTS event = X_SESSION_LAST_BAR; + Add( + event, + state // + ); + OnMarketSessionEvent( + iMarketSession.session, + event // + ); + NotifyMarketSessionEventListeners( + iMarketSession.session, + event // + ); + } + } + } + } + } + + // + // Swing Highs and Lows ... + + // + // Swing Highs ... + + // + bool allowSwingHighs = AllowSwingHighs(); + int swingHighsCount = ArraySize(mSwingHighs); + if (allowSwingHighs) + { + // + bool isSingHigh = pBar.IsSimpleSwingHigh(SwingHighThreshold()); + if (isSingHigh) + { + // + bool isAdded = AddBar( + X_POI_SWING_HIGH, + pBar, + mSwingHighs // + ); + + // + if (isAdded) + { + // + swingHighsCount = ArraySize(mSwingHighs); + DrawSwingHighs(); + + // + ENUM_XPOI_EVENTS event = X_SWING_HIGH_DETECTED; + Add( + event, + state // + ); + OnSwingHighEvent(event, pBar); + NotifySwingHighEventListeners(event, pBar); + } + } + } + + // + // Swing Lows ... + + // + bool allowSwingLows = AllowSwingLows(); + int swingLowsCount = ArraySize(mSwingLows); + if (allowSwingLows) + { + // + bool isSingLow = pBar.IsSimpleSwingLow(SwingLowThreshold()); + if (isSingLow) + { + // + bool isAdded = AddBar( + X_POI_SWING_LOW, + pBar, + mSwingLows // + ); + + // + if (isAdded) + { + // + swingLowsCount = ArraySize(mSwingLows); + DrawSwingLows(); + + // + ENUM_XPOI_EVENTS event = X_SWING_LOW_DETECTED; + Add( + event, + state // + ); + OnSwingLowEvent(event, pBar); + NotifySwingLowEventListeners(event, pBar); + } + } + } + + // + // Momentum Bars ... + + // + bool allowMomentumBars = AllowMomentumBars(); + int momentumBarsCount = ArraySize(mMomentumBars); + if (allowMomentumBars) + { + // + bool isStrongBar = cBar.IsStrong(MomentumBarPercent()); + bool isSharpBullish = cBar.IsSharpBullish( + MomentumBarLoopBack(), + MomentumBarSharpRatio() // + ); + bool isSharpBearish = cBar.IsSharpBearish( + MomentumBarLoopBack(), + MomentumBarSharpRatio() // + ); + bool isMomentumBar = + isStrongBar && + (isSharpBearish || + isSharpBullish); + if (isMomentumBar) + { + // + bool isAdded = AddBar( + X_POI_MOMENTUM_BAR, + cBar, + mMomentumBars // + ); + + // + if (isAdded) + { + // + momentumBarsCount = ArraySize(mMomentumBars); + DrawMomentumBars(); + + // + ENUM_XPOI_EVENTS event = X_MOMENTUM_BAR_DETECTED; + Add( + event, + state // + ); + OnMomentumBarEvent(event, cBar); + NotifyMomentumBarEventListeners(event, cBar); + } + } + } + + // + // Rejection Bars ... + + // + bool allowRejectionBars = AllowRejectionBars(); + int rejectionBarsCount = ArraySize(mRejectionBars); + if (allowRejectionBars) + { + // + int rejectionBarLoopBackBarIndex = RejectionBarLoopBack() + 1; + XOHCL iRBar; + bool isIRBarInited = iRBar.Init( + mSymbol, + mPeriod, + rejectionBarLoopBackBarIndex // + ); + if (isIRBarInited) + { + // + bool isRejectionBar = + iRBar.HasStrongLowShadow( + RejectionBarPercent(), + RejectionBarLoopBack(), + RejectionBarSharpRatio() // + ) || + iRBar.HasStrongHighShadow( + RejectionBarPercent(), + RejectionBarLoopBack(), + RejectionBarSharpRatio() // + ); + if (isRejectionBar) + { + // + bool isAdded = AddBar( + X_POI_REJECTION_BAR, + iRBar, + mRejectionBars // + ); + + // + if (isAdded) + { + // + rejectionBarsCount = ArraySize(mRejectionBars); + DrawRejectionBars(); + + // + ENUM_XPOI_EVENTS event = X_REJECTION_BAR_DETECTED; + Add( + event, + state // + ); + OnRejectionBarEvent(event, iRBar); + NotifyRejectionBarEventListeners(event, iRBar); + } + } + } + } + + // + // Support and Resistance Zones ... + + // + // Support Zones ... + + // + bool allowSupportZones = AllowSupportZones(); + int supportZonesCount = ArraySize(mSupportZones); + if (allowSupportZones) + { + // + XOHCL support; + bool hasSupport = cBar.HasSupport( + support, + SupportZonePriceType(), + SupportZoneLoopBack() // + ); + if (hasSupport) + { + // + bool isAdded = AddBar( + X_POI_SUPPORT_ZONE, + support, + mSupportZones // + ); + + // + if (isAdded) + { + // + supportZonesCount = ArraySize(mSupportZones); + DrawSupportZones(); + + // + ENUM_XPOI_EVENTS event = X_SUPPORT_ZONE_DETECTED; + Add( + event, + state // + ); + OnSupportZoneEvent(event, support); + NotifySupportZoneEventListeners(event, support); + } + } + } + + // + // Resistance Zone ... + + // + bool allowResistanceZones = AllowResistanceZones(); + int resistanceZonesCount = ArraySize(mResistanceZones); + if (allowResistanceZones) + { + // + XOHCL resistance; + bool hasResistance = cBar.HasResistance( + resistance, + ResistanceZonePriceType(), + ResistanceZoneLoopBack() // + ); + if (hasResistance) + { + // + bool isAdded = AddBar( + X_POI_RESISTANCE_ZONE, + resistance, + mResistanceZones // + ); + + // + if (isAdded) + { + // + resistanceZonesCount = ArraySize(mResistanceZones); + DrawResistanceZones(); + + // + ENUM_XPOI_EVENTS event = X_RESISTANCE_ZONE_DETECTED; + Add( + event, + state // + ); + OnResistanceZoneEvent(event, resistance); + NotifyResistanceZoneEventListeners(event, resistance); + } + } + } + + // + // Supply and Demand Zones ... + + // + // Supply Zones ... + + // + bool allowSupplyZones = AllowSupplyZones(); + int supplyZonesCount = ArraySize(mSupplyZones); + if (allowSupplyZones) + { + // + datetime endTime = cBar.time; + XOHCL cSupplyBar; + bool isSupplyBarInited = cSupplyBar.Init( + mSymbol, + SupplyZonePeriod(), + 0 // + ); + if (isSupplyBarInited) + { + // + datetime lastSupplyBarTime = cSupplyBar + .GetLastBarTimeOfPeriod(mPeriod); + if (zBar.time == lastSupplyBarTime) + { + // + datetime startTime = cSupplyBar.time; + int cSupplyZonePeriodIndex = iBarShift( + mSymbol, + mPeriod, + cSupplyBar.time // + ); + + // + // Find Swings ... + XOHCL swings[]; + for (int i = 0; i < cSupplyZonePeriodIndex; i++) + { + // + XOHCL iBar; + bool isIBarInited = iBar.Init( + mSymbol, + mPeriod, + i // + ); + if (!isIBarInited) + { + continue; + } + + // + // Check is Bar Swing or not ... + bool isSwing = iBar.IsSimpleSwingHigh(); + if (!isSwing) + { + continue; + } + + // + AddRef( + iBar, + swings // + ); + } + + // + // Select Max Swing for Supply Zone ... + XOHCL selectedSwing; + int swingsCount = ArraySize(swings); + if (IsValidSize(swingsCount)) + { + // + for (int i = 0; i < swingsCount; i++) + { + // + XOHCL iSwing = swings[i]; + if (!selectedSwing.IsValid() || + selectedSwing.high < iSwing.high) + { + selectedSwing = iSwing; + } + } + } + + // + // Check Swing ... + if (selectedSwing.IsValid()) + { + // + XZone zone; + bool isInited = zone.Init( + selectedSwing.high, + selectedSwing.low, + ToString(X_POI_SUPPLY_ZONE) + "_" + ToString(SupplyZonePeriod()), + startTime, + endTime // + ); + if (isInited) + { + // + int zoneIDX = FindZoneIndex( + zone, + mSupplyZones // + ); + + // + if (!IsValidIndex(zoneIDX)) + { + // + AddRef( + zone, + mSupplyZones // + ); + + // + supplyZonesCount = ArraySize(mSupplyZones); + DrawSupplyZones(); + + // + ENUM_XPOI_EVENTS event = X_SUPPLY_ZONE_DETECTED; + Add( + event, + state // + ); + OnSupplyZoneEvent(event, zone); + NotifySupplyZoneEventListeners(event, zone); + } + } + } + } + } + } + + // + // Demand Zones ... + + // + bool allowDemandZones = AllowDemandZones(); + int demandZonesCount = ArraySize(mDemandZones); + if (allowDemandZones) + { + // + datetime endTime = cBar.time; + XOHCL cDemandBar; + bool isDemandBarInited = cDemandBar.Init( + mSymbol, + DemandZonePeriod(), + 0 // + ); + if (isDemandBarInited) + { + // + datetime lastDemandBarTime = cDemandBar + .GetLastBarTimeOfPeriod(mPeriod); + if (zBar.time == lastDemandBarTime) + { + // + datetime startTime = cDemandBar.time; + int cDemandZonePeriodIndex = iBarShift( + mSymbol, + mPeriod, + cDemandBar.time // + ); + + // + // Find Swings ... + XOHCL swings[]; + for (int i = 0; i < cDemandZonePeriodIndex; i++) + { + // + XOHCL iBar; + bool isIBarInited = iBar.Init( + mSymbol, + mPeriod, + i // + ); + if (!isIBarInited) + { + continue; + } + + // + // Check is Bar Swing or not ... + bool isSwing = iBar.IsSimpleSwingLow(); + if (!isSwing) + { + continue; + } + + // + AddRef( + iBar, + swings // + ); + } + + // + // Select Max Swing for Supply Zone ... + XOHCL selectedSwing; + int swingsCount = ArraySize(swings); + if (IsValidSize(swingsCount)) + { + // + for (int i = 0; i < swingsCount; i++) + { + // + XOHCL iSwing = swings[i]; + if (!selectedSwing.IsValid() || + selectedSwing.low > iSwing.low) + { + selectedSwing = iSwing; + } + } + } + + // + // Check Swing ... + if (selectedSwing.IsValid()) + { + // + XZone zone; + bool isInited = zone.Init( + selectedSwing.high, + selectedSwing.low, + ToString(X_POI_DEMAND_ZONE) + "_" + ToString(SupplyZonePeriod()), + startTime, + endTime // + ); + if (isInited) + { + // + int zoneIDX = FindZoneIndex( + zone, + mDemandZones // + ); + + // + if (!IsValidIndex(zoneIDX)) + { + // + AddRef( + zone, + mDemandZones // + ); + + // + demandZonesCount = ArraySize(mDemandZones); + DrawDemandZones(); + + // + ENUM_XPOI_EVENTS event = X_DEMAND_ZONE_DETECTED; + Add( + event, + state // + ); + OnDemandZoneEvent(event, zone); + NotifyDemandZoneEventListeners(event, zone); + } + } + } + } + } + } + + // + // Order Blocks ... + + // + // Bullish Order Blocks ... + + // + bool allowBullishOrderBlocks = AllowBullishOrderBlocks(); + int bullishOrderBlocksCount = ArraySize(mBullishOrderBlocks); + if (allowBullishOrderBlocks) + { + // + XOHCL bullOB; + bool hasBullOB = cBar.HasBullishOrderBlock( + bullOB, + RequiredBarsForBullishOrderBlock() // + ); + if (hasBullOB) + { + // + XZone obZone; + bool isAdded = AddZone( + obZone, // Dest ... + bullOB, + cBar.time, + X_POI_BULLISH_ORDERBLOCK, + mBullishOrderBlocks // + ); + if (isAdded) + { + // + bullishOrderBlocksCount = ArraySize(mBullishOrderBlocks); + DrawBullishOrderBlocks(); + + // + ENUM_XPOI_EVENTS event = X_BULLISH_ORDERBLOCK_DETECTED; + Add( + event, + state // + ); + OnBullishOrderBlockEvent(event, obZone); + NotifyBullishOrderBlockEventListeners(event, obZone); + } + } + } + + // + // Bearish Order Blocks ... + + // + bool allowBearishOrderBlocks = AllowBearishOrderBlocks(); + int bearishOrderBlocksCount = ArraySize(mBearishOrderBlocks); + if (allowBearishOrderBlocks) + { + // + XOHCL bearOB; + bool hasBearOB = cBar.HasBearishOrderBlock( + bearOB, + RequiredBarsForBearishOrderBlock() // + ); + if (hasBearOB) + { + // + XZone zone; + bool isAdded = AddZone( + zone, // + bearOB, + cBar.time, + X_POI_BEARISH_ORDERBLOCK, + mBearishOrderBlocks // + ); + if (isAdded) + { + // + bullishOrderBlocksCount = ArraySize(mBearishOrderBlocks); + DrawBearishOrderBlocks(); + + // + ENUM_XPOI_EVENTS event = X_BEARISH_ORDERBLOCK_DETECTED; + Add( + event, + state // + ); + OnBullishOrderBlockEvent(event, zone); + NotifyBullishOrderBlockEventListeners(event, zone); + } + } + } + + // + // Fair Value Gaps ... + double upper; + double lower; + datetime start; + datetime end; + + // + // Bullish FVGs ... + bool allowBullishFVGs = AllowBullishFVGs(); + int bullishFVGsCount = ArraySize(mBullishFVGs); + if (allowBullishFVGs) + { + // + bool hasBullishFVG = cBar.HasBullishFVG( + upper, + lower, + start, + end, + BullishFVGForceMiddleBarCheck(), + BullishFVGForceCheckLastBarDirection() // + ); + if (hasBullishFVG) + { + // + XZone zone; + bool isAdded = AddZone( + zone, + upper, + lower, + start, + end, + X_POI_BULLISH_FVG, + mBullishFVGs // + ); + if (isAdded) + { + // + bullishFVGsCount = ArraySize(mBullishFVGs); + DrawBullishFVGs(); + + // + ENUM_XPOI_EVENTS event = X_BULLISH_FVG_DETECTED; + Add( + event, + state // + ); + OnBullishFVGEvent(event, zone); + NotifyBullishFVGEventListeners(event, zone); + } + } + } + + // + // Bearish FVGs ... + bool allowBearishFVGs = AllowBearishFVGs(); + int bearishFVGsCount = ArraySize(mBearishFVGs); + if (allowBearishFVGs) + { + // + bool hasBearishFVG = cBar.HasBearishFVG( + upper, + lower, + start, + end, + BearishFVGForceMiddleBarCheck(), + BearishFVGForceCheckLastBarDirection() // + ); + if (hasBearishFVG) + { + // + XZone zone; + bool isAdded = AddZone( + zone, + upper, + lower, + start, + end, + X_POI_BEARISH_FVG, + mBearishFVGs // + ); + if (isAdded) + { + // + bearishFVGsCount = ArraySize(mBearishFVGs); + DrawBearishFVGs(); + + // + ENUM_XPOI_EVENTS event = X_BEARISH_FVG_DETECTED; + Add( + event, + state // + ); + OnBearishFVGEvent(event, zone); + NotifyBearishFVGEventListeners(event, zone); + } + } + } + + // + // ... + + // + CleanupUnusedPOIs(); + + // + mBarTracker.Waits(); + + // + result = ArraySize(state); + + // + return result; + } + + /** + * Enable All POIs Detection ... + */ + void EnablePOIs() + { + ChangePOIsState(true); + } + + /** + * Disable All POIs Detection ... + */ + void DisablePOIs() + { + ChangePOIsState(false); + } + + /** + * Set All POIs Detection States ... + * + * @param state: Argument 1 + */ + void ChangePOIsState(bool state) + { + // + AllowSwingLows(state); + AllowSwingHighs(state); + AllowTradingDays(state); + AllowSupplyZones(state); + AllowDemandZones(state); + AllowBullishFVGs(state); + AllowBearishFVGs(state); + AllowMomentumBars(state); + AllowSupportZones(state); + AllowRejectionBars(state); + AllowMarketSessions(state); + AllowResistanceZones(state); + AllowBullishOrderBlocks(state); + AllowBearishOrderBlocks(state); + } + + /** + * Enable Draw All POI(s) ... + */ + void EnableDrawPOIs() + { + ChangePOIsDrawState(true); + } + + /** + * Disable Draw All POI(s) ... + */ + void DisableDrawPOIs() + { + ChangePOIsDrawState(false); + } + + /** + * Set Drawing State of all POIs ... + * + * @param state: Boolean ... + */ + void ChangePOIsDrawState(bool state) + { + // + AllowDrawSwingLows(state); + AllowDrawSwingHighs(state); + AllowDrawTradingDays(state); + AllowDrawSupplyZones(state); + AllowDrawBullishFVGs(state); + AllowDrawBearishFVGs(state); + AllowDrawDemandZones(state); + AllowDrawSupportZones(state); + AllowDrawMomentumBars(state); + AllowDrawRejectionBars(state); + AllowDrawMarketSessions(state); + AllowDrawResistanceZones(state); + AllowDrawBullishOrderBlocks(state); + AllowDrawBearishOrderBlocks(state); + + // + // Sessions ... + int sessionsCount = ArraySize(mSessions); + if (IsValidSize(sessionsCount)) + { + // + for (int i = 0; i < sessionsCount; i++) + { + // + mSessions[i].allowDraw = state; + } + } + } + + // + // Retrievers ... + + /** + * Get Current State of POIs ... + * + * @param state: XPOIState instance ... + */ + void GetState( + XPOIState &state // + ) + { + // + state.Clean(); + + // + state.symbol = mSymbol; + state.period = mPeriod; + state.reportedAt = TimeCurrent(); + + // + state.FillTradingDays(mTradingDays); + state.FillMarketSessions(mMarketSessions); + + // + state.FillMomentumBars(mMomentumBars); + state.FillRejectionBars(mRejectionBars); + + // + state.FillSwingHighs(mSwingHighs); + state.FillSwingLows(mSwingLows); + + // + state.FillSupportZones(mSupportZones); + state.FillResistanceZones(mResistanceZones); + + // + state.FillSupplyZones(mSupplyZones); + state.FillDemandZones(mDemandZones); + + // + state.FillBullishOrderBlocks(mBullishOrderBlocks); + state.FillBearishOrderBlocks(mBearishOrderBlocks); + + // + state.FillBullishFVGs(mBullishFVGs); + state.FillBearishFVGs(mBearishFVGs); + } + + // + // Virtual Actions ... + + /** + * Apply Default Configurations ... + */ + virtual void ApplyDefaultConfig() + { + // + // Common ... + + // + ChartIdentification(0); + SubWindowIdentification(0); + mDrawer.ChartIdentification(0); + mDrawer.SubWindowIdentification(0); + + // + MaxNumberOfPOIs(10); + MaxNumberOfRequiredPOIs(2); + + // + EnablePOIs(); + EnableDrawPOIs(); + + // + // Trading Days ... + TradingDaysStartColor(clrYellow); + TradingDaysStartStyle(STYLE_DASHDOT); + TradingDaysEndColor(clrGray); + TradingDaysEndStyle(STYLE_DASHDOT); + + // + // Sessions ... + + // + // SYDNEY ... + // Start: (UTC) 21:00 + // End: (UTC) 06:00 + XSession mSyndeySession; + mSyndeySession.Init( + X_SYDNEY, + "20:00", // Start ... + "05:00" // End Next Day ... + ); + mSyndeySession.startColor = clrFireBrick; + mSyndeySession.endColor = clrFireBrick; + mSyndeySession.allowDraw = true; + AddSession(mSyndeySession); + + // + // TOKYO ... + // Start: (UTC) 12:00 + // End: (UTC) 09:00 + XSession mTokyoSession; + mTokyoSession.Init( + X_TOKYO, + "00:00", // Start ... + "09:00" // End Next Day ... + ); + mTokyoSession.startColor = clrBlueViolet; + mTokyoSession.endColor = clrBlueViolet; + mTokyoSession.allowDraw = true; + AddSession(mTokyoSession); + + // + // LONDON ... + // Start: (UTC) 07:00 + // End: (UTC) 16:00 + XSession mLondonSession; + mLondonSession.Init( + X_LONDON, + "07:00", // Start ... + "16:00" // End ... + ); + mLondonSession.startColor = clrLime; + mLondonSession.endColor = clrLime; + mLondonSession.allowDraw = true; + AddSession(mLondonSession); + + // + // NEWYORK ... + // Start: (UTC) 13:00 + // End: (UTC) 22:00 + XSession mNewYorkSession; + mNewYorkSession.Init( + X_NEW_YORK, + "12:00", // Start ... + "21:00" // End ... + ); + mNewYorkSession.startColor = clrAqua; + mNewYorkSession.endColor = clrAqua; + mNewYorkSession.allowDraw = true; + AddSession(mNewYorkSession); + + // + SessionOpenHours(9); + + // + // Swing High and Low (s) ... + + // + // Swing Highs ... + SwingHighThreshold(3); + mDrawer.SwingHighWidth(5); + mDrawer.SwingHighArrow(108); + mDrawer.SwingHighColor(clrMagenta); + + // + // Swing Lows ... + SwingLowThreshold(3); + mDrawer.SwingLowWidth(5); + mDrawer.SwingLowArrow(108); + mDrawer.SwingLowColor(clrAqua); + + // + // Momentum Bars ... + MomentumBarPercent(55); + MomentumBarLoopBack(3); + MomentumBarSharpRatio(1.2); + mDrawer.BullishMomentumBarWidth(5); + mDrawer.BearishMomentumBarWidth(5); + mDrawer.BullishMomentumBarArrow(225); + mDrawer.BearishMomentumBarArrow(226); + mDrawer.BullishMomentumBarColor(clrAqua); + mDrawer.BearishMomentumBarColor(clrMagenta); + + // + // Rejection Bars ... + RejectionBarPercent(55); + RejectionBarLoopBack(5); + RejectionBarSharpRatio(1.5); + mDrawer.BullishRejectionBarWidth(5); + mDrawer.BearishRejectionBarWidth(5); + mDrawer.BullishRejectionBarArrow(217); + mDrawer.BearishRejectionBarArrow(218); + mDrawer.BullishRejectionBarColor(clrAqua); + mDrawer.BearishRejectionBarColor(clrMagenta); + + // + // Support and Resistance Zones ... + + // + // Support Zones ... + SupportZoneLoopBack(52); + SupportZonePriceType(X_PRICE_CLOSE); + mDrawer.SupportZoneWidth(1); + mDrawer.SupportZoneColor(clrLime); + mDrawer.SupportZoneStyle(STYLE_DOT); + + // + // Resistance Zones ... + ResistanceZoneLoopBack(52); + ResistanceZonePriceType(X_PRICE_CLOSE); + mDrawer.ResistanceZoneWidth(1); + mDrawer.ResistanceZoneColor(clrRed); + mDrawer.ResistanceZoneStyle(STYLE_DOT); + + // + // Supply and Deman Zones ... + + // + // Supply Zones ... + SupplyZonePeriod(GetHindMostPeriod(mPeriod)); + mDrawer.SupplyZoneWidth(1); + mDrawer.SupplyZoneColor(clrDarkRed); + mDrawer.SupplyZoneStyle(STYLE_DASH); + + // + // Demand Zones ... + DemandZonePeriod(GetHindMostPeriod(mPeriod)); + mDrawer.DemandZoneWidth(1); + mDrawer.DemandZoneColor(clrDarkGreen); + mDrawer.DemandZoneStyle(STYLE_DASH); + + // + // Order Blocks ... + + // + // Bullish Order Block ... + RequiredBarsForBullishOrderBlock(3); + mDrawer.BullishOrderBlockWidth(1); + mDrawer.BullishOrderBlockColor(clrAqua); + mDrawer.BullishOrderBlockStyle(STYLE_DASHDOT); + + // + // Bearish Order Block ... + RequiredBarsForBearishOrderBlock(3); + mDrawer.BearishOrderBlockWidth(1); + mDrawer.BearishOrderBlockColor(clrMagenta); + mDrawer.BearishOrderBlockStyle(STYLE_DASHDOT); + + // + // Fair Value Gaps ... + + // + // Bullish FVGs ... + BullishFVGForceMiddleBarCheck(true); + BullishFVGForceCheckLastBarDirection(true); + mDrawer.BullishFVGWidth(1); + mDrawer.BullishFVGColor(clrAqua); + mDrawer.BullishFVGStyle(STYLE_DASHDOTDOT); + + // + // Bearish FVGs ... + BearishFVGForceMiddleBarCheck(true); + BearishFVGForceCheckLastBarDirection(true); + mDrawer.BearishFVGWidth(1); + mDrawer.BearishFVGColor(clrMagenta); + mDrawer.BearishFVGStyle(STYLE_DASHDOTDOT); + + // + } + + // + // Session Configurations ... + + /** + * Add Sepcific Session to Supported Sessions ... + * + * @param session: XSession instance ... + */ + void AddSession(XSession &session) + { + // + if (!session.IsValid()) + { + return; + } + + // + AddRef( + session, + mSessions // + ); + } + + // + // Event Listeners ... + + // + // Trading Days ... + + /** + * Calls When new Trading Day Event Happens ... + * + * @param event: ENUM_XPOI_EVENTS member ... + */ + virtual void OnTradingDayEvent( + ENUM_XPOI_EVENTS event // + ) + { + } + + /** + * Register an Event Listener for New Trading Day Events ... + * + * @param listener: TXPOIEventHandler instance ... + */ + void AddTradingDayEventListener(TXPOIEventHandler listener) + { + // + Add( + listener, + mTradingDayEventListeners // + ); + } + + // + // Market Sessions ... + + /** + * Calls When new Market Session Event Happens ... + * + * @param session: ENUM_XSESSION member ... + * @param event: ENUM_XPOI_EVENTS member ... + */ + virtual void OnMarketSessionEvent( + ENUM_XSESSION session, + ENUM_XPOI_EVENTS event // + ) + { + } + + /** + * Register an Event Listener for New Market Session Events ... + * + * @param listener: TXSessionEventHandler instance ... + */ + void AddMarketSessionEventListener(TXSessionEventHandler listener) + { + // + Add( + listener, + mMarketSessionEventListeners // + ); + } + + // + // Swings ... + + // + // Swing Highs ... + + /** + * Calls When new Swing High Event ... + * + * @param event: ENUM_XPOI_EVENTS member ... + * @param bar: XOHCL instance ... + */ + virtual void OnSwingHighEvent( + ENUM_XPOI_EVENTS event, + XOHCL &bar // + ) + { + } + + /** + * Register an Event Listener for New Swing High Event ... + * + * @param listener: TXOHCLEventHandler instance ... + */ + void AddSwingHighEventListener(TXOHCLEventHandler listener) + { + // + Add( + listener, + mSwingHighEventListeners // + ); + } + + // + // Swing Lows ... + + /** + * Calls When new Swing Low Detected ... + * + * @param event: ENUM_XPOI_EVENTS member ... + * @param bar: XOHCL instance ... + */ + virtual void OnSwingLowEvent( + ENUM_XPOI_EVENTS event, + XOHCL &bar // + ) + { + } + + /** + * Register an Event Listener for New Swing Low Event ... + * + * @param listener: TXOHCLEventHandler instance ... + */ + void AddSwingLowEventListener(TXOHCLEventHandler listener) + { + // + Add( + listener, + mSwingLowEventListeners // + ); + } + + // + // Momentum Bar ... + + /** + * Calls When new Momentum Bar Event ... + * + * @param event: ENUM_XPOI_EVENTS member ... + * @param bar: XOHCL instance ... + */ + virtual void OnMomentumBarEvent( + ENUM_XPOI_EVENTS event, + XOHCL &bar // + ) + { + } + + /** + * Register an Event Listener for New Momentum Bar Event ... + * + * @param listener: TXOHCLEventHandler instance ... + */ + void AddMomentumBarEventListener(TXOHCLEventHandler listener) + { + // + Add( + listener, + mMomentumBarEventListeners // + ); + } + + // + // Rejection Bar ... + + /** + * Calls When new Rejection Bar Event ... + * + * @param event: ENUM_XPOI_EVENTS member ... + * @param bar: XOHCL instance ... + */ + virtual void OnRejectionBarEvent( + ENUM_XPOI_EVENTS event, + XOHCL &bar // + ) + { + } + + /** + * Register an Event Listener for New Rejection Bar Event ... + * + * @param listener: TXOHCLEventHandler instance ... + */ + void AddRejectionBarEventListener(TXOHCLEventHandler listener) + { + // + Add( + listener, + mRejectionBarEventListeners // + ); + } + + // + // Support and Resistance Zones ... + + // + // Support Zones ... + + /** + * Calls When new Support Zone Event ... + * + * @param event: ENUM_XPOI_EVENTS member ... + * @param bar: XOHCL instance ... + */ + virtual void OnSupportZoneEvent( + ENUM_XPOI_EVENTS event, + XOHCL &bar // + ) + { + } + + /** + * Register an Event Listener for New Support Zone Event ... + * + * @param listener: TXOHCLEventHandler instance ... + */ + void AddSupportZoneEventListener(TXOHCLEventHandler listener) + { + // + Add( + listener, + mSupportZoneEventListeners // + ); + } + + // + // Resistance Zones ... + + /** + * Calls When new Resistance Zone Event ... + * + * @param event: ENUM_XPOI_EVENTS member ... + * @param bar: XOHCL instance ... + */ + virtual void OnResistanceZoneEvent( + ENUM_XPOI_EVENTS event, + XOHCL &bar // + ) + { + } + + /** + * Register an Event Listener for New Resistance Zone Event ... + * + * @param listener: TXOHCLEventHandler instance ... + */ + void AddResistanceZoneEventListener(TXOHCLEventHandler listener) + { + // + Add( + listener, + mResistanceZoneEventListeners // + ); + } + + // + // Supply and Demand Zones ... + + // + // Supply Zones ... + + /** + * Calls When new Supply Zone Event ... + * + * @param event: ENUM_XPOI_EVENTS member ... + * @param zone: XZone instance ... + */ + virtual void OnSupplyZoneEvent( + ENUM_XPOI_EVENTS event, + XZone &zone // + ) + { + } + + /** + * Register an Event Listener for New Supply Zone Event ... + * + * @param listener: TXZoneEventHandler instance ... + */ + void AddSupplyZoneEventListener(TXZoneEventHandler listener) + { + // + Add( + listener, + mSupplyZoneEventListeners // + ); + } + + // + // Demand Zones ... + + /** + * Calls When new Demand Zone Event ... + * + * @param event: ENUM_XPOI_EVENTS member ... + * @param zone: XZone instance ... + */ + virtual void OnDemandZoneEvent( + ENUM_XPOI_EVENTS event, + XZone &zone // + ) + { + } + + /** + * Register an Event Listener for New Demand Zone Event ... + * + * @param listener: TXZoneEventHandler instance ... + */ + void AddDemandZoneEventListener(TXZoneEventHandler listener) + { + // + Add( + listener, + mDemandZoneEventListeners // + ); + } + + // + // Order Blocks ... + + // + // Bullish Order Blocks ... + + /** + * Calls When new Bullish Order Block Event ... + * + * @param event: ENUM_XPOI_EVENTS member ... + * @param zone: XZone instance ... + */ + virtual void OnBullishOrderBlockEvent( + ENUM_XPOI_EVENTS event, + XZone &zone // + ) + { + } + + /** + * Register an Event Listener for New Bullish Order Block Event ... + * + * @param listener: TXZoneEventHandler instance ... + */ + void AddBullishOrderBlockEventListener(TXZoneEventHandler listener) + { + // + Add( + listener, + mBullishOrderBlockEventListeners // + ); + } + + // + // Bearish Order Blocks ... + + /** + * Calls When new Bearish Order Block Event ... + * + * @param event: ENUM_XPOI_EVENTS member ... + * @param zone: XZone instance ... + */ + virtual void OnBearishOrderBlockEvent( + ENUM_XPOI_EVENTS event, + XZone &zone // + ) + { + } + + /** + * Register an Event Listener for New Bearish Order Block Event ... + * + * @param listener: TXZoneEventHandler instance ... + */ + void AddBearishOrderBlockEventListener(TXZoneEventHandler listener) + { + // + Add( + listener, + mBearishOrderBlockEventListeners // + ); + } + + // + // Fai Value Gaps ... + + // + // Bullish FVGs ... + + /** + * Calls When new Bullish FVG Event ... + * + * @param event: ENUM_XPOI_EVENTS member ... + * @param zone: XZone instance ... + */ + virtual void OnBullishFVGEvent( + ENUM_XPOI_EVENTS event, + XZone &zone // + ) + { + } + + /** + * Register an Event Listener for New Bullish FVG Event ... + * + * @param listener: TXZoneEventHandler instance ... + */ + void AddBullishFVGEventListener(TXZoneEventHandler listener) + { + // + Add( + listener, + mBullishFVGEventListeners // + ); + } + + // + // Bearish FVGs ... + + /** + * Calls When new Bearish FVG Event ... + * + * @param event: ENUM_XPOI_EVENTS member ... + * @param zone: XZone instance ... + */ + virtual void OnBearishFVGEvent( + ENUM_XPOI_EVENTS event, + XZone &zone // + ) + { + } + + /** + * Register an Event Listener for New Bearish FVG Event ... + * + * @param listener: TXZoneEventHandler instance ... + */ + void AddBearishFVGEventListener(TXZoneEventHandler listener) + { + // + Add( + listener, + mBearishFVGEventListeners // + ); + } + + // + protected: + // + + // + // Actions ... + + /** + * Lock ... + */ + void Lock() + { + mLock = true; + } + + /** + * Unlock ... + */ + void Unlock() + { + mLock = false; + } + + /** + * Detect Required POI(s) ... + * + * @param barIndex: Integer Start bar index ... + * 0 is Default ... + */ + void DetectRequiredPOIs(int barIndex = 0) + { + // + // Validate Reuired POI(s) ... + int requiredPOIs = MaxNumberOfRequiredPOIs(); + if (requiredPOIs <= 0) + { + return; + } + + // + Lock(); + + // + // Normalize Bar Index ... + if (barIndex < 0) + { + barIndex = 0; + } + + // + bool canContinue = true; + while (canContinue) + { + // + // Define Index of Bars ... + int zIndex = barIndex; + int cIndex = zIndex + 1; + + // + datetime cTime = TimeCurrent(); + + // + XOHCL zBar; + bool isRetrieved = mBarTracker.GetBar(zBar, zIndex); + if (!isRetrieved) + { + break; + } + + // + XOHCL cBar; + isRetrieved = mBarTracker.GetBar(cBar, cIndex); + if (!isRetrieved) + { + break; + } + + // + // Detect POI(s) based On Current Bar ... + + // + // Trade Days ... + bool allowTradingDays = AllowTradingDays(); + int daysCount = ArraySize(mTradingDays); + if (allowTradingDays && + daysCount < requiredPOIs) + { + // + XOHCL zDayBar; + isRetrieved = zDayBar.Init( + mSymbol, + PERIOD_D1, + zIndex // + ); + if (!isRetrieved) + { + break; + } + + // + XOHCL cDayBar; + isRetrieved = cDayBar.Init( + mSymbol, + PERIOD_D1, + cIndex // + ); + if (!isRetrieved) + { + break; + } + + // + XTradeDay tradeDay; + tradeDay.from = zDayBar.time; + + // + datetime lastBarTime = zDayBar.GetLastBarTimeOfPeriod(mPeriod); + tradeDay.to = lastBarTime; + + // + int idx = HasTradeDay(tradeDay.from); + if (!IsValidIndex(idx)) + { + // + AddRef( + tradeDay, + mTradingDays // + ); + + // + daysCount = ArraySize(mTradingDays); + } + } + + // + // Market Sessions ... + int sessionsCount = ArraySize(mSessions); + bool allowMarketSessions = AllowMarketSessions(); + int marketSessionsCount = ArraySize(mMarketSessions); + if (allowMarketSessions && + IsValidSize(sessionsCount) && + marketSessionsCount < sessionsCount * requiredPOIs) + { + // + for (int i = 0; i < sessionsCount; i++) + { + // + XSession iSession = mSessions[i]; + int iCount = CountMarketSessions(iSession.session); + if (iCount >= requiredPOIs) + { + continue; + } + + // + datetime zTimeGMT = GetUTCTime(zBar.time); + string zTimeString = GetTimeString(zTimeGMT); + + // + bool isStarted = iSession.start == zTimeString; + bool isEnded = iSession.end == zTimeString; + + // + // Detect Sessions Based on Time ... + // Since All Session Close Times Related to Current Date and + // in Required POIs we Moving Back from Current Date ... + if (isEnded && iCount < requiredPOIs) + { + // + // Check Market Session Doesnt Exists by End Time ... + int iIDX = HasMarketSessionByEndTime( + iSession.session, + zBar.time // + ); + if (!IsValidIndex(iIDX)) + { + // + XMarketSession iMarketSession; + iMarketSession.session = iSession.session; + iMarketSession.to = zBar.time; + + // + int iSessionWorkingHoure = SessionOpenHours(); + int iSessionWorkingSeconds = iSessionWorkingHoure * 60 * 60; + iMarketSession.from = (datetime)((int)zBar.time - iSessionWorkingSeconds); + + // + AddRef( + iMarketSession, + mMarketSessions // + ); + + // + marketSessionsCount = ArraySize(mMarketSessions); + } + } + + // + } + } + + // + // Swning Highs and Lows ... + + // + // Swing Highs ... + bool allowSwingHighs = AllowSwingHighs(); + int swingHighsCount = ArraySize(mSwingHighs); + if (allowSwingHighs && + swingHighsCount < requiredPOIs) + { + // + bool isSwingHigh = cBar.IsSimpleSwingHigh(SwingHighThreshold()); + if (isSwingHigh) + { + // + bool isAdded = AddBar( + X_POI_SWING_HIGH, + cBar, + mSwingHighs // + ); + + // + if (isAdded) + { + swingHighsCount = ArraySize(mSwingHighs); + } + } + } + + // + // Swing Lows ... + bool allowSwingLows = AllowSwingLows(); + int swingLowsCount = ArraySize(mSwingLows); + if (allowSwingLows && + swingLowsCount < requiredPOIs) + { + // + bool isSwingLow = cBar.IsSimpleSwingLow(SwingLowThreshold()); + if (isSwingLow) + { + // + bool isAdded = AddBar( + X_POI_SWING_LOW, + cBar, + mSwingLows // + ); + + // + if (isAdded) + { + swingLowsCount = ArraySize(mSwingLows); + } + } + } + + // + // Momentum Bars ... + bool allowMomentumBars = AllowMomentumBars(); + int momentumBarsCount = ArraySize(mMomentumBars); + if (allowMomentumBars && + momentumBarsCount < requiredPOIs) + { + // + bool isStrongBar = cBar.IsStrong(MomentumBarPercent()); + + // + // Bullish ... + bool isSharpBullish = cBar.IsSharpBullish( + MomentumBarLoopBack(), + MomentumBarSharpRatio() // + ); + + // + // Bearish ... + bool isSharpBearish = cBar.IsSharpBearish( + MomentumBarLoopBack(), + MomentumBarSharpRatio() // + ); + + // + bool isMomentumBar = + isStrongBar && + (isSharpBearish || + isSharpBullish); + if (isMomentumBar) + { + // + bool isAdded = AddBar( + X_POI_MOMENTUM_BAR, + cBar, + mMomentumBars // + ); + + // + if (isAdded) + { + momentumBarsCount = ArraySize(mMomentumBars); + } + } + } + + // + // Rejection Bars ... + bool allowRejectionBars = AllowRejectionBars(); + int rejectionBarsCount = ArraySize(mRejectionBars); + if (allowRejectionBars && + rejectionBarsCount < requiredPOIs) + { + // + bool isRejectionBar = + cBar.HasStrongLowShadow( + RejectionBarPercent(), + RejectionBarLoopBack(), + RejectionBarSharpRatio() // + ) || + cBar.HasStrongHighShadow( + RejectionBarPercent(), + RejectionBarLoopBack(), + RejectionBarSharpRatio() // + ); + + // + if (isRejectionBar) + { + // + bool isAdded = AddBar( + X_POI_REJECTION_BAR, + cBar, + mRejectionBars // + ); + + // + if (isAdded) + { + rejectionBarsCount = ArraySize(mRejectionBars); + } + } + } + + // + // Support nad Resistance Zones ... + + // + // Support Zones ... + bool allowSupportZones = AllowSupportZones(); + int supportZonesCount = ArraySize(mSupportZones); + if (allowSupportZones && + supportZonesCount < requiredPOIs) + { + // + XOHCL support; + bool hasSupport = cBar.HasSupport( + support, + SupportZonePriceType(), + SupportZoneLoopBack() // + ); + + // + if (hasSupport) + { + // + bool isAdded = AddBar( + X_POI_SUPPORT_ZONE, + support, + mSupportZones // + ); + + // + if (isAdded) + { + supportZonesCount = ArraySize(mSupportZones); + } + } + } + + // + // Resistance Zones ... + bool allowResistanceZones = AllowResistanceZones(); + int resistanceZonesCount = ArraySize(mResistanceZones); + if (allowResistanceZones && + resistanceZonesCount < requiredPOIs) + { + // + XOHCL resistance; + bool hasResistance = cBar.HasResistance( + resistance, + ResistanceZonePriceType(), + ResistanceZoneLoopBack() // + ); + + // + if (hasResistance) + { + // + bool isAdded = AddBar( + X_POI_RESISTANCE_ZONE, + resistance, + mResistanceZones // + ); + + // + if (isAdded) + { + resistanceZonesCount = ArraySize(mResistanceZones); + } + } + } + + // + // Supply and Demand Zones ... + + // + // Supply Zones ... + bool allowSupplyZones = AllowSupplyZones(); + int supplyZonesCount = ArraySize(mSupplyZones); + if (allowSupplyZones && + supplyZonesCount < requiredPOIs) + { + // + datetime endTime = cBar.time; + + // + datetime cSupplyZoneStartTime = iTime( + mSymbol, + SupplyZonePeriod(), + supplyZonesCount + 1 // + ); + datetime startTime = cSupplyZoneStartTime; + + // + int cSupplyZoneStartIndex = iBarShift( + mSymbol, + mPeriod, + cSupplyZoneStartTime // + ); + + // + XOHCL swings[]; + for (int i = 0; i < cSupplyZoneStartIndex; i++) + { + // + XOHCL iBar; + bool isIBarInited = iBar.Init( + mSymbol, + mPeriod, + i // + ); + if (!isIBarInited) + { + continue; + } + + // + // Check is Bar Swing or not ... + bool isSwing = iBar.IsSimpleSwingHigh(); + if (!isSwing) + { + continue; + } + + // + AddRef( + iBar, + swings // + ); + } + + // + XOHCL selectedSwing; + int swingsCount = ArraySize(swings); + if (IsValidSize(swingsCount)) + { + // + for (int i = 0; i < swingsCount; i++) + { + // + XOHCL iSwing = swings[i]; + if (!selectedSwing.IsValid() || + selectedSwing.high < iSwing.high) + { + selectedSwing = iSwing; + } + } + } + + // + if (selectedSwing.IsValid()) + { + // + XZone zone; + bool isInited = zone.Init( + selectedSwing.high, + selectedSwing.low, + ToString(X_POI_SUPPLY_ZONE) + "_" + ToString(SupplyZonePeriod()), + startTime, + endTime // + ); + if (isInited) + { + // + AddRef( + zone, + mSupplyZones // + ); + + // + supplyZonesCount = ArraySize(mSupplyZones); + } + } + } + + // + // Demand Zones ... + bool allowDemandZones = AllowDemandZones(); + int demandZonesCount = ArraySize(mDemandZones); + if (allowDemandZones && + demandZonesCount < requiredPOIs) + { + // + datetime endTime = cBar.time; + + // + datetime cDemandZoneStartTime = iTime( + mSymbol, + DemandZonePeriod(), + demandZonesCount + 1 // + ); + datetime startTime = cDemandZoneStartTime; + + // + int cDemandZoneStartIndex = iBarShift( + mSymbol, + mPeriod, + cDemandZoneStartTime // + ); + + // + XOHCL swings[]; + for (int i = 0; i < cDemandZoneStartIndex; i++) + { + // + XOHCL iBar; + bool isIBarInited = iBar.Init( + mSymbol, + mPeriod, + i // + ); + if (!isIBarInited) + { + continue; + } + + // + // Check is Bar Swing or not ... + bool isSwing = iBar.IsSimpleSwingLow(); + if (!isSwing) + { + continue; + } + + // + AddRef( + iBar, + swings // + ); + } + + // + XOHCL selectedSwing; + int swingsCount = ArraySize(swings); + if (IsValidSize(swingsCount)) + { + // + for (int i = 0; i < swingsCount; i++) + { + // + XOHCL iSwing = swings[i]; + if (!selectedSwing.IsValid() || + selectedSwing.low > iSwing.low) + { + selectedSwing = iSwing; + } + } + } + + // + if (selectedSwing.IsValid()) + { + // + XZone zone; + bool isInited = zone.Init( + selectedSwing.high, + selectedSwing.low, + ToString(X_POI_DEMAND_ZONE) + "_" + ToString(DemandZonePeriod()), + startTime, + endTime // + ); + if (isInited) + { + // + AddRef( + zone, + mDemandZones // + ); + + // + demandZonesCount = ArraySize(mDemandZones); + } + } + } + + // + // Order Blocks ... + + // + // Bullish Order Blocks ... + bool allowBullishOrderBlocks = AllowBullishOrderBlocks(); + int bullishOrderBlocksCount = ArraySize(mBullishOrderBlocks); + if (allowBullishOrderBlocks && + bullishOrderBlocksCount < requiredPOIs) + { + // + XOHCL ob; + bool hasOB = cBar.HasBullishOrderBlock( + ob, + RequiredBarsForBullishOrderBlock() // + ); + if (hasOB) + { + // + XZone zone; + bool isAdded = AddZone( + zone, // + ob, + cBar.time, + X_POI_BULLISH_ORDERBLOCK, + mBullishOrderBlocks // + ); + if (isAdded) + { + bullishOrderBlocksCount = ArraySize(mBullishOrderBlocks); + } + } + } + + // + // Bearish Order Blocks ... + bool allowBearishOrderBlocks = AllowBearishOrderBlocks(); + int bearishOrderBlocksCount = ArraySize(mBearishOrderBlocks); + if (allowBearishOrderBlocks && + bearishOrderBlocksCount < requiredPOIs) + { + // + XOHCL ob; + bool hasOB = cBar.HasBearishOrderBlock( + ob, + RequiredBarsForBearishOrderBlock() // + ); + if (hasOB) + { + // + XZone zone; + bool isAdded = AddZone( + zone, // + ob, + cBar.time, + X_POI_BEARISH_ORDERBLOCK, + mBearishOrderBlocks // + ); + if (isAdded) + { + bullishOrderBlocksCount = ArraySize(mBearishOrderBlocks); + } + } + } + + // + // Fair Value Gaps ... + + // + // Bullish FVGs ... + bool allowBullishFVGs = AllowBullishFVGs(); + int bullishFVGsCount = ArraySize(mBullishFVGs); + if (allowBullishFVGs && + bullishFVGsCount < requiredPOIs) + { + // + double upper; + double lower; + datetime start; + datetime end; + bool hasBullishFVG = cBar.HasBullishFVG( + upper, + lower, + start, + end, + BullishFVGForceMiddleBarCheck(), + BullishFVGForceCheckLastBarDirection() // + ); + if (hasBullishFVG) + { + // + XZone zone; + bool isAdded = AddZone( + zone, + upper, + lower, + start, + end, + X_POI_BULLISH_FVG, + mBullishFVGs // + ); + if (isAdded) + { + bullishFVGsCount = ArraySize(mBullishFVGs); + } + } + } + + // + // Bearish FVGs ... + bool allowBearishFVGs = AllowBearishFVGs(); + int bearishFVGsCount = ArraySize(mBearishFVGs); + if (allowBearishFVGs && + bearishFVGsCount < requiredPOIs) + { + // + double upper; + double lower; + datetime start; + datetime end; + bool hasBearishFVG = cBar.HasBearishFVG( + upper, + lower, + start, + end, + BearishFVGForceMiddleBarCheck(), + BearishFVGForceCheckLastBarDirection() // + ); + if (hasBearishFVG) + { + // + XZone zone; + bool isAdded = AddZone( + zone, + upper, + lower, + start, + end, + X_POI_BEARISH_FVG, + mBearishFVGs // + ); + if (isAdded) + { + bearishFVGsCount = ArraySize(mBearishFVGs); + } + } + } + + // + // Detect Required Conditions for Loop ... + // + + // + // Market Sessions Requirements ... + bool isNeedMoreMarketSessions = (!IsValidSize(sessionsCount) + ? true + : marketSessionsCount < (sessionsCount * requiredPOIs)); + canContinue = + // + // Trade Days ... + (allowTradingDays && + daysCount < requiredPOIs) || + // + // Market Sessions ... + (allowMarketSessions && + isNeedMoreMarketSessions) || + // + // Swing High and Low (s) ... + (allowSwingHighs && + swingHighsCount < requiredPOIs) || + (allowSwingLows && + swingLowsCount < requiredPOIs) || + // + // Momentum Bars ... + (allowMomentumBars && + momentumBarsCount < requiredPOIs) || + // + // Rejection Bars ... + (allowRejectionBars && + rejectionBarsCount < requiredPOIs) || + // + // Support and Resistance Zones ... + (allowSupportZones && + supportZonesCount < requiredPOIs) || + (allowResistanceZones && + resistanceZonesCount < requiredPOIs) || + // + // Supply and Demand Zones ... + (allowSupplyZones && + supplyZonesCount < requiredPOIs) || + (allowDemandZones && + demandZonesCount < requiredPOIs) || + // + // Order Blocks ... + (allowBullishOrderBlocks && + bullishOrderBlocksCount < requiredPOIs) || + (allowBearishOrderBlocks && + bearishOrderBlocksCount < requiredPOIs) || + // + // Fair Value Gaps ... + (allowBullishFVGs && + bullishFVGsCount < requiredPOIs) || + (allowBearishFVGs && + bearishFVGsCount < requiredPOIs) + // + ; + if (canContinue) + { + barIndex++; + } + } + + // + // int errorArr[]; + // if (canContinue) + // { + // // + // int t = errorArr[5]; + // } + + // + // Complete Calculations ... + + // + // Reverse Trading Days ... + XTradeDay tmpDays[]; + Copy( + mTradingDays, + tmpDays // + ); + Clean(mTradingDays); + ArrayReverse(tmpDays); + Copy( + tmpDays, + mTradingDays // + ); + Clean(tmpDays); + + // + // Reverse Market Sessions ... + XMarketSession tmpSessions[]; + Copy( + mMarketSessions, + tmpSessions // + ); + Clean(mMarketSessions); + ArrayReverse(tmpSessions); + Copy( + tmpSessions, + mMarketSessions // + ); + + // + XOHCL tmpBars[]; + + // + // Reverse Swing Highs ... + Copy( + mSwingHighs, + tmpBars // + ); + Clean(mSwingHighs); + ArrayReverse(tmpBars); + Copy( + tmpBars, + mSwingHighs // + ); + Clean(tmpBars); + + // + // Reverse Swing Lows ... + Copy( + mSwingLows, + tmpBars // + ); + Clean(mSwingLows); + ArrayReverse(tmpBars); + Copy( + tmpBars, + mSwingLows // + ); + Clean(tmpBars); + + // + // Reverse Momentum Bars ... + Copy( + mMomentumBars, + tmpBars // + ); + Clean(mMomentumBars); + ArrayReverse(tmpBars); + Copy( + tmpBars, + mMomentumBars // + ); + Clean(tmpBars); + + // + // Reverse Rejection Bars ... + Copy( + mRejectionBars, + tmpBars // + ); + Clean(mRejectionBars); + ArrayReverse(tmpBars); + Copy( + tmpBars, + mRejectionBars // + ); + Clean(tmpBars); + + // + // Reverse Support Zones ... + Copy( + mSupportZones, + tmpBars // + ); + Clean(mSupportZones); + ArrayReverse(tmpBars); + Copy( + tmpBars, + mSupportZones // + ); + Clean(tmpBars); + + // + // Reverse Resistance Zones ... + Copy( + mResistanceZones, + tmpBars // + ); + Clean(mResistanceZones); + ArrayReverse(tmpBars); + Copy( + tmpBars, + mResistanceZones // + ); + Clean(tmpBars); + + // + XZone tmpZones[]; + + // + // Supply and Demand Zones ... + + // + Copy( + mSupplyZones, + tmpZones // + ); + Clean(mSupplyZones); + ArrayReverse(tmpZones); + Copy( + tmpZones, + mSupplyZones // + ); + Clean(tmpZones); + + // + Copy( + mDemandZones, + tmpZones // + ); + Clean(mDemandZones); + ArrayReverse(tmpZones); + Copy( + tmpZones, + mDemandZones // + ); + Clean(tmpZones); + + // + // Order Blocks ... + + // + Copy( + mBullishOrderBlocks, + tmpZones // + ); + Clean(mBullishOrderBlocks); + ArrayReverse(tmpZones); + Copy( + tmpZones, + mBullishOrderBlocks // + ); + Clean(tmpZones); + + // + Copy( + mBearishOrderBlocks, + tmpZones // + ); + Clean(mBearishOrderBlocks); + ArrayReverse(tmpZones); + Copy( + tmpZones, + mBearishOrderBlocks // + ); + Clean(tmpZones); + + // + // Fair Value Gaps ... + + // + Copy( + mBullishFVGs, + tmpZones // + ); + Clean(mBullishFVGs); + ArrayReverse(tmpZones); + Copy( + tmpZones, + mBullishFVGs // + ); + Clean(tmpZones); + + // + Copy( + mBearishFVGs, + tmpZones // + ); + Clean(mBearishFVGs); + ArrayReverse(tmpZones); + Copy( + tmpZones, + mBearishFVGs // + ); + Clean(tmpZones); + + // + // ... + + // + Unlock(); + DrawPOIs(); + } + + // + // Destroy POIs ... + + /** + * Destroy All POI(s) ... + */ + void DestroyPOIs() + { + // + // Trading Days ... + DestroyTradingDays(); + + // + // Market Sessions ... + DestroyMarketSessions(); + + // + // Momentum Bars ... + DestroyMomentumBars(); + + // + // Rejection Bars ... + DestroyRejectionBars(); + + // + // Swing High and Zone (s) ... + DestroySwingHighs(); + DestroySwingLows(); + + // + // Support and Resistance Zones ... + DestroySupportZones(); + DestroyResistanceZones(); + + // + // Supply and Demand Zones ... + DestroySupplyZones(); + DestroyDemandZones(); + + // + // Order Blocks ... + DestroyBullishOrderBlocks(); + DestroyBearishOrderBlocks(); + + // + // Fai Value Gaps ... + DestroyBullishFVGs(); + DestroyBearishFVGs(); + } + + /** + * Destroy Trading Days ... + */ + void DestroyTradingDays() + { + Clean(mTradingDays); + } + + /** + * Destroy Swing Highs ... + */ + void DestroySwingHighs() + { + Clean(mSwingHighs); + } + + /** + * Destroy Swing Lows ... + */ + void DestroySwingLows() + { + Clean(mSwingLows); + } + + /** + * Destroy Momentum Bars ... + */ + void DestroyMomentumBars() + { + Clean(mMomentumBars); + } + + /** + * Destroy Rejection Bars ... + */ + void DestroyRejectionBars() + { + Clean(mRejectionBars); + } + + /** + * Destroy Market Sessions ... + */ + void DestroyMarketSessions() + { + Clean(mMarketSessions); + } + + /** + * Destroy Support Zones ... + */ + void DestroySupportZones() + { + Clean(mSupportZones); + } + + /** + * Destroy Resistance Zones ... + */ + void DestroyResistanceZones() + { + Clean(mResistanceZones); + } + + /** + * Destroy Supply Zones ... + */ + void DestroySupplyZones() + { + Clean(mSupplyZones); + } + + /** + * Destroy Demand Zones ... + */ + void DestroyDemandZones() + { + Clean(mDemandZones); + } + + /** + * Destroy Bullish Order Blocks ... + */ + void DestroyBullishOrderBlocks() + { + Clean(mBullishOrderBlocks); + } + + /** + * Destroy Bearish Order Blocks ... + */ + void DestroyBearishOrderBlocks() + { + Clean(mBearishOrderBlocks); + } + + /** + * Destroy Bullish FVGs ... + */ + void DestroyBullishFVGs() + { + Clean(mBullishFVGs); + } + + /** + * Destroy Bearish FVGs ... + */ + void DestroyBearishFVGs() + { + Clean(mBearishFVGs); + } + + // + // Draw Actions ... + + /** + * Draw All POI(s) ... + */ + void DrawPOIs() + { + // + // Trading Days ... + DrawTradingDays(); + + // + // Market Sessions ... + DrawMarketSessions(); + + // + // Momentum Bars ... + DrawMomentumBars(); + + // + // Rejection Bars ... + DrawRejectionBars(); + + // + // Swing High and Low (s) ... + DrawSwingHighs(); + DrawSwingLows(); + + // + // Support and Resistance (s) ... + DrawSupportZones(); + DrawResistanceZones(); + + // + // Supply and Demand Zones ... + DrawSupplyZones(); + DrawDemandZones(); + + // + // Order Blocks ... + DrawBullishOrderBlocks(); + DrawBearishOrderBlocks(); + + // + // Fair Value Gaps ... + DrawBullishFVGs(); + DrawBearishFVGs(); + } + + /** + * Draw Trading Days ... + */ + void DrawTradingDays() + { + // + bool allow = AllowDrawTradingDays(); + if (!allow) + { + return; + } + + // + int count = ArraySize(mTradingDays); + if (!IsValidSize(count)) + { + return; + } + + // + for (int i = 0; i < count; i++) + { + // + XTradeDay iDay = mTradingDays[i]; + + // + string iName = iDay.GetTag(); + int iIDX = HasTradingDayObject( + iName // + ); + if (IsValidIndex(iIDX)) + { + continue; + } + + // + CreateTradingDayObject(iDay, iName); + } + } + + /** + * Check a Trading Day is Drawn Before or not ... + * + * @param name: String ... + * + * @return ( int ) + */ + int HasTradingDayObject( + string name // + ) + { + // + int result = -1; + + // + if (!IsValid(name)) + { + return result; + } + + // + int count = mTradingDayObjects.Total(); + if (!IsValidSize(count)) + { + return result; + } + + // + for (int i = 0; i < count; i++) + { + // + string objName = ((XCBaseObject *)mTradingDayObjects.At(i)).ObjName(); + if (objName == name) + { + // + result = i; + break; + } + } + + // + return result; + } + + /** + * Draw Swing Highs ... + */ + void DrawSwingHighs() + { + // + bool allow = AllowDrawSwingHighs(); + if (!allow) + { + return; + } + + // + int count = ArraySize(mSwingHighs); + if (!IsValidSize(count)) + { + return; + } + + // + for (int i = 0; i < count; i++) + { + // + XOHCL iSwing = mSwingHighs[i]; + + // + string iName = iSwing.GetTag(ToString(X_POI_SWING_HIGH)); + int iIDX = HasSwingHighObject( + iName // + ); + if (IsValidIndex(iIDX)) + { + continue; + } + + // + bool allow = AllowDrawSwingHighs(); + if (allow) + { + // + XCSwingHighObject *iObj; + bool isCreated = mDrawer.CreateSwingHigh(iSwing, iObj); + if (isCreated) + { + mSwingHighObjects.Add(iObj); + } + } + } + } + + /** + * Check a Swing High is Drawn Before or not ... + * + * @param name: String ... + * + * @return ( int ) + */ + int HasSwingHighObject( + string name // + ) + { + // + int result = -1; + + // + if (!IsValid(name)) + { + return result; + } + + // + int count = mSwingHighObjects.Total(); + if (!IsValidSize(count)) + { + return result; + } + + // + for (int i = 0; i < count; i++) + { + // + string objName = ((CChartObjectArrow *)mSwingHighObjects.At(i)).Name(); + if (objName == name) + { + // + result = i; + break; + } + } + + // + return result; + } + + /** + * Draw Swing Lows ... + */ + void DrawSwingLows() + { + // + bool allow = AllowDrawSwingLows(); + if (!allow) + { + return; + } + + // + int count = ArraySize(mSwingLows); + if (!IsValidSize(count)) + { + return; + } + + // + for (int i = 0; i < count; i++) + { + // + XOHCL iSwing = mSwingLows[i]; + + // + string iName = iSwing.GetTag(ToString(X_POI_SWING_LOW)); + int iIDX = HasSwingLowObject( + iName // + ); + if (IsValidIndex(iIDX)) + { + continue; + } + + // + bool allow = AllowDrawSwingLows(); + if (allow) + { + // + XCSwingLowObject *iObj; + bool isCreated = mDrawer.CreateSwingLow(iSwing, iObj); + if (isCreated) + { + mSwingLowObjects.Add(iObj); + } + } + } + } + + /** + * Check a Swing Low is Drawn Before or not ... + * + * @param name: String ... + * + * @return ( int ) + */ + int HasSwingLowObject( + string name // + ) + { + // + int result = -1; + + // + if (!IsValid(name)) + { + return result; + } + + // + int count = mSwingLowObjects.Total(); + if (!IsValidSize(count)) + { + return result; + } + + // + for (int i = 0; i < count; i++) + { + // + string objName = ((CChartObjectArrow *)mSwingLowObjects.At(i)).Name(); + if (objName == name) + { + // + result = i; + break; + } + } + + // + return result; + } + + /** + * Draw Momentum Bars ... + */ + void DrawMomentumBars() + { + // + bool allow = AllowDrawMomentumBars(); + if (!allow) + { + return; + } + + // + int count = ArraySize(mMomentumBars); + if (!IsValidSize(count)) + { + return; + } + + // + for (int i = 0; i < count; i++) + { + // + XOHCL iBar = mMomentumBars[i]; + + // + string iName = iBar.GetTag(ToString(X_POI_MOMENTUM_BAR)); + int iIDX = HasMomentumBarObject( + iName // + ); + if (IsValidIndex(iIDX)) + { + continue; + } + + // + bool allow = AllowDrawMomentumBars(); + if (allow) + { + // + bool isBullish = iBar.IsBullish(); + if (isBullish) + { + // + XCBullishMomentumBarObject *iObj; + bool isCreated = mDrawer.CreateBullishMomentumBar(iBar, iObj); + if (isCreated) + { + mMomentumBarObjects.Add(iObj); + } + } + else + { + // + XCBearishMomentumBarObject *iObj; + bool isCreated = mDrawer.CreateBearishMomentumBar(iBar, iObj); + if (isCreated) + { + mMomentumBarObjects.Add(iObj); + } + } + } + } + } + + /** + * Check a Momentum Bar is Drawn Before or not ... + * + * @param name: String ... + * + * @return ( int ) + */ + int HasMomentumBarObject( + string name // + ) + { + // + int result = -1; + + // + if (!IsValid(name)) + { + return result; + } + + // + int count = mMomentumBarObjects.Total(); + if (!IsValidSize(count)) + { + return result; + } + + // + for (int i = 0; i < count; i++) + { + // + string objName = ((CChartObjectArrow *)mMomentumBarObjects.At(i)).Name(); + if (objName == name) + { + // + result = i; + break; + } + } + + // + return result; + } + + /** + * Draw Rejection Bars ... + */ + void DrawRejectionBars() + { + // + bool allow = AllowDrawRejectionBars(); + if (!allow) + { + return; + } + + // + int count = ArraySize(mRejectionBars); + if (!IsValidSize(count)) + { + return; + } + + // + for (int i = 0; i < count; i++) + { + // + XOHCL iBar = mRejectionBars[i]; + + // + string iName = iBar.GetTag(ToString(X_POI_REJECTION_BAR)); + int iIDX = HasRejectionBarObject( + iName // + ); + if (IsValidIndex(iIDX)) + { + continue; + } + + // + bool allow = AllowDrawRejectionBars(); + if (allow) + { + // + bool isBullish = iBar.GetLowShadow() > iBar.GetHighShadow(); + if (isBullish) + { + // + XCBullishRejectionBarObject *iObj; + bool isCreated = mDrawer.CreateBullishRejectionBar(iBar, iObj); + if (isCreated) + { + mRejectionBarObjects.Add(iObj); + } + } + else + { + // + XCBearishRejectionBarObject *iObj; + bool isCreated = mDrawer.CreateBearishRejectionBar(iBar, iObj); + if (isCreated) + { + mRejectionBarObjects.Add(iObj); + } + } + } + } + } + + /** + * Check a Rejection Bar is Drawn Before or not ... + * + * @param name: String ... + * + * @return ( int ) + */ + int HasRejectionBarObject( + string name // + ) + { + // + int result = -1; + + // + if (!IsValid(name)) + { + return result; + } + + // + int count = mRejectionBarObjects.Total(); + if (!IsValidSize(count)) + { + return result; + } + + // + for (int i = 0; i < count; i++) + { + // + string objName = ((CChartObjectArrow *)mRejectionBarObjects.At(i)).Name(); + if (objName == name) + { + // + result = i; + break; + } + } + + // + return result; + } + + /** + * Draw Market Sessions ... + */ + void DrawMarketSessions() + { + // + bool allow = AllowDrawMarketSessions(); + if (!allow) + { + return; + } + + // + int count = ArraySize(mMarketSessions); + if (!IsValidSize(count)) + { + return; + } + + // + for (int i = 0; i < count; i++) + { + // + XMarketSession iMarketSession = mMarketSessions[i]; + + // + string iName = iMarketSession.GetTag(); + int iIDX = HasMarketessionObject( + iName // + ); + if (IsValidIndex(iIDX)) + { + continue; + } + + // + // CreateMarketSessionObject(iMarketSession, iName); + } + } + + /** + * Check a Market Session is Drawn Before or not ... + * + * @param name: String ... + * + * @return ( int ) + */ + int HasMarketessionObject( + string name // + ) + { + // + int result = -1; + + // + if (!IsValid(name)) + { + return result; + } + + // + int count = mMarketSessionObjects.Total(); + if (!IsValidSize(count)) + { + return result; + } + + // + for (int i = 0; i < count; i++) + { + // + string objName = ((XCMarketSessionObject *)mMarketSessionObjects.At(i)).ObjName(); + if (objName == name) + { + // + result = i; + break; + } + } + + // + return result; + } + + /** + * Draw Support Zones ... + */ + void DrawSupportZones() + { + // + bool allow = AllowDrawSupportZones(); + if (!allow) + { + return; + } + + // + int count = ArraySize(mSupportZones); + if (!IsValidSize(count)) + { + return; + } + + // + for (int i = 0; i < count; i++) + { + // + XOHCL iSupportZone = mSupportZones[i]; + + // + string iName = iSupportZone.GetTag(ToString(X_POI_SUPPORT_ZONE)); + int iIDX = HasSupportZoneObject( + iName // + ); + if (IsValidIndex(iIDX)) + { + continue; + } + + // + bool allow = AllowDrawSupportZones(); + if (allow) + { + // + XCSupportZoneObject *iObj; + bool isCreated = mDrawer.CreateSupportZone(iSupportZone, iObj); + if (isCreated) + { + mSupportZoneObjects.Add(iObj); + } + } + } + } + + /** + * Check a Suport Zone is Drawn Before or not ... + * + * @param name: String ... + * + * @return ( int ) + */ + int HasSupportZoneObject( + string name // + ) + { + // + int result = -1; + + // + if (!IsValid(name)) + { + return result; + } + + // + int count = mSupportZoneObjects.Total(); + if (!IsValidSize(count)) + { + return result; + } + + // + for (int i = 0; i < count; i++) + { + // + string objName = ((XCSupportZoneObject *)mSupportZoneObjects.At(i)).ObjName(); + if (objName == name) + { + // + result = i; + break; + } + } + + // + return result; + } + + /** + * Draw Resistance Zones ... + */ + void DrawResistanceZones() + { + // + bool allow = AllowDrawResistanceZones(); + if (!allow) + { + return; + } + + // + int count = ArraySize(mResistanceZones); + if (!IsValidSize(count)) + { + return; + } + + // + for (int i = 0; i < count; i++) + { + // + XOHCL iResistanceZone = mResistanceZones[i]; + + // + string iName = iResistanceZone.GetTag(ToString(X_POI_RESISTANCE_ZONE)); + int iIDX = HasResistanceZoneObject( + iName // + ); + if (IsValidIndex(iIDX)) + { + continue; + } + + // + bool allow = AllowDrawResistanceZones(); + if (allow) + { + // + XCResistanceZoneObject *iObj; + bool isCreated = mDrawer.CreateResistanceZone(iResistanceZone, iObj); + if (isCreated) + { + mResistanceZoneObjects.Add(iObj); + } + } + } + } + + /** + * Check a Resistance Zone is Drawn Before or not ... + * + * @param name: String ... + * + * @return ( int ) + */ + int HasResistanceZoneObject( + string name // + ) + { + // + int result = -1; + + // + if (!IsValid(name)) + { + return result; + } + + // + int count = mResistanceZoneObjects.Total(); + if (!IsValidSize(count)) + { + return result; + } + + // + for (int i = 0; i < count; i++) + { + // + string objName = ((XCResistanceZoneObject *)mResistanceZoneObjects.At(i)).ObjName(); + if (objName == name) + { + // + result = i; + break; + } + } + + // + return result; + } + + /** + * Draw Supply Zones ... + */ + void DrawSupplyZones() + { + // + bool allow = AllowDrawSupplyZones(); + if (!allow) + { + return; + } + + // + int count = ArraySize(mSupplyZones); + if (!IsValidSize(count)) + { + return; + } + + // + for (int i = 0; i < count; i++) + { + // + XZone iSupplyZone = mSupplyZones[i]; + + // + string iName = iSupplyZone.GetTag(); + int iIDX = HasSupplyZoneObject( + iName // + ); + if (IsValidIndex(iIDX)) + { + continue; + } + + // + bool allow = AllowDrawSupplyZones(); + if (allow) + { + // + XCSupplyZoneObject *iObj; + bool isCreated = mDrawer.CreateSupplyZone(iSupplyZone, iObj); + if (isCreated) + { + mSupplyZoneObjects.Add(iObj); + } + } + } + } + + /** + * Check a Supply Zone is Drawn Before or not ... + * + * @param name: String ... + * + * @return ( int ) + */ + int HasSupplyZoneObject( + string name // + ) + { + // + int result = -1; + + // + if (!IsValid(name)) + { + return result; + } + + // + int count = mSupplyZoneObjects.Total(); + if (!IsValidSize(count)) + { + return result; + } + + // + for (int i = 0; i < count; i++) + { + // + string objName = ((XCSupplyZoneObject *)mSupplyZoneObjects.At(i)).ObjName(); + if (objName == name) + { + // + result = i; + break; + } + } + + // + return result; + } + + /** + * Draw Demand Zones ... + */ + void DrawDemandZones() + { + // + bool allow = AllowDrawDemandZones(); + if (!allow) + { + return; + } + + // + int count = ArraySize(mDemandZones); + if (!IsValidSize(count)) + { + return; + } + + // + for (int i = 0; i < count; i++) + { + // + XZone iDemandZone = mDemandZones[i]; + + // + string iName = iDemandZone.GetTag(); + int iIDX = HasDemandZoneObject( + iName // + ); + if (IsValidIndex(iIDX)) + { + continue; + } + + // + bool allow = AllowDrawDemandZones(); + if (allow) + { + // + XCDemandZoneObject *iObj; + bool isCreated = mDrawer.CreateDemandZone(iDemandZone, iObj); + if (isCreated) + { + mDemandZoneObjects.Add(iObj); + } + } + } + } + + /** + * Check a Demand Zone is Drawn Before or not ... + * + * @param name: String ... + * + * @return ( int ) + */ + int HasDemandZoneObject( + string name // + ) + { + // + int result = -1; + + // + if (!IsValid(name)) + { + return result; + } + + // + int count = mDemandZoneObjects.Total(); + if (!IsValidSize(count)) + { + return result; + } + + // + for (int i = 0; i < count; i++) + { + // + string objName = ((XCDemandZoneObject *)mDemandZoneObjects.At(i)).ObjName(); + if (objName == name) + { + // + result = i; + break; + } + } + + // + return result; + } + + /** + * Draw Bullish Order Blocks ... + */ + void DrawBullishOrderBlocks() + { + // + bool allow = AllowDrawBullishOrderBlocks(); + if (!allow) + { + return; + } + + // + int count = ArraySize(mBullishOrderBlocks); + if (!IsValidSize(count)) + { + return; + } + + // + for (int i = 0; i < count; i++) + { + // + XZone iBullishOB = mBullishOrderBlocks[i]; + + // + string iName = iBullishOB.GetTag(); + int iIDX = HasBullishOrderBlockObject( + iName // + ); + if (IsValidIndex(iIDX)) + { + continue; + } + + // + bool allow = AllowDrawBullishOrderBlocks(); + if (allow) + { + // + XCBullishOrderBlockObject *iObj; + bool isCreated = mDrawer.CreateBullishOrderBlock(iBullishOB, iObj); + if (isCreated) + { + mBullishOrderBlockObjects.Add(iObj); + } + } + } + } + + /** + * Check a Bullish Order Block is Drawn Before or not ... + * + * @param name: String ... + * + * @return ( int ) + */ + int HasBullishOrderBlockObject( + string name // + ) + { + // + int result = -1; + + // + if (!IsValid(name)) + { + return result; + } + + // + int count = mBullishOrderBlockObjects.Total(); + if (!IsValidSize(count)) + { + return result; + } + + // + for (int i = 0; i < count; i++) + { + // + string objName = ((XCBullishOrderBlockObject *)mBullishOrderBlockObjects.At(i)).ObjName(); + if (objName == name) + { + // + result = i; + break; + } + } + + // + return result; + } + + /** + * Draw Bearish Order Blocks ... + */ + void DrawBearishOrderBlocks() + { + // + bool allow = AllowDrawBearishOrderBlocks(); + if (!allow) + { + return; + } + + // + int count = ArraySize(mBearishOrderBlocks); + if (!IsValidSize(count)) + { + return; + } + + // + for (int i = 0; i < count; i++) + { + // + XZone iBearishOB = mBearishOrderBlocks[i]; + + // + string iName = iBearishOB.GetTag(); + int iIDX = HasBearishOrderBlockObject( + iName // + ); + if (IsValidIndex(iIDX)) + { + continue; + } + + // + bool allow = AllowDrawBearishOrderBlocks(); + if (allow) + { + // + XCBearishOrderBlockObject *iObj; + bool isCreated = mDrawer.CreateBearishOrderBlock(iBearishOB, iObj); + if (isCreated) + { + mBearishOrderBlockObjects.Add(iObj); + } + } + } + } + + /** + * Check a Bearish Order Block is Drawn Before or not ... + * + * @param name: String ... + * + * @return ( int ) + */ + int HasBearishOrderBlockObject( + string name // + ) + { + // + int result = -1; + + // + if (!IsValid(name)) + { + return result; + } + + // + int count = mBearishOrderBlockObjects.Total(); + if (!IsValidSize(count)) + { + return result; + } + + // + for (int i = 0; i < count; i++) + { + // + string objName = ((XCBearishOrderBlockObject *)mBearishOrderBlockObjects.At(i)).ObjName(); + if (objName == name) + { + // + result = i; + break; + } + } + + // + return result; + } + + /** + * Draw Bullish FVGs ... + */ + void DrawBullishFVGs() + { + // + bool allow = AllowDrawBullishFVGs(); + if (!allow) + { + return; + } + + // + int count = ArraySize(mBullishFVGs); + if (!IsValidSize(count)) + { + return; + } + + // + for (int i = 0; i < count; i++) + { + // + XZone iFVG = mBullishFVGs[i]; + + // + string iName = iFVG.GetTag(); + int iIDX = HasBullishFVGObject( + iName // + ); + if (IsValidIndex(iIDX)) + { + continue; + } + + // + bool allow = AllowDrawBullishFVGs(); + if (allow) + { + // + XCBullishFVGObject *iObj; + bool isCreated = mDrawer.CreateBullishFVG(iFVG, iObj); + if (isCreated) + { + mBullishFVGObjects.Add(iObj); + } + } + } + } + + /** + * Check a Bullish FVG is Drawn Before or not ... + * + * @param name: String ... + * + * @return ( int ) + */ + int HasBullishFVGObject( + string name // + ) + { + // + int result = -1; + + // + if (!IsValid(name)) + { + return result; + } + + // + int count = mBullishFVGObjects.Total(); + if (!IsValidSize(count)) + { + return result; + } + + // + for (int i = 0; i < count; i++) + { + // + string objName = ((XCBullishFVGObject *)mBullishFVGObjects.At(i)).ObjName(); + if (objName == name) + { + // + result = i; + break; + } + } + + // + return result; + } + + /** + * Draw Bearish FVGs ... + */ + void DrawBearishFVGs() + { + // + bool allow = AllowDrawBearishFVGs(); + if (!allow) + { + return; + } + + // + int count = ArraySize(mBearishFVGs); + if (!IsValidSize(count)) + { + return; + } + + // + for (int i = 0; i < count; i++) + { + // + XZone iFVG = mBearishFVGs[i]; + + // + string iName = iFVG.GetTag(); + int iIDX = HasBearishFVGObject( + iName // + ); + if (IsValidIndex(iIDX)) + { + continue; + } + + // + bool allow = AllowDrawBearishFVGs(); + if (allow) + { + // + XCBearishFVGObject *iObj; + bool isCreated = mDrawer.CreateBearishFVG(iFVG, iObj); + if (isCreated) + { + mBearishFVGObjects.Add(iObj); + } + } + } + } + + /** + * Check a Bearish FVG is Drawn Before or not ... + * + * @param name: String ... + * + * @return ( int ) + */ + int HasBearishFVGObject( + string name // + ) + { + // + int result = -1; + + // + if (!IsValid(name)) + { + return result; + } + + // + int count = mBearishFVGObjects.Total(); + if (!IsValidSize(count)) + { + return result; + } + + // + for (int i = 0; i < count; i++) + { + // + string objName = ((XCBearishFVGObject *)mBearishFVGObjects.At(i)).ObjName(); + if (objName == name) + { + // + result = i; + break; + } + } + + // + return result; + } + + // + + /** + * Clean All Drawn Objects ... + */ + void DestroyObjects() + { + // + // Trading Days ... + DestroyTradingTradingDayObjects(); + + // + // Market Sessions ... + DestroyMarketSessionObjects(); + + // + // Momentum Bars ... + DestroyMomentumBarObjects(); + + // + // Rejection Bars ... + DestroyRejectionBarObjects(); + + // + // Swing High and Low (s) ... + DestroySwingLowObjects(); + DestroySwingHighObjects(); + + // + // Support and Resistanc (s) ... + DestroySupportZoneObjects(); + DestroyResistanceZoneObjects(); + + // + // Supply and Demand Zones .. + DestroySupplyZoneObjects(); + DestroyDemandZoneObjects(); + + // + // Order Blocks ... + DestroyBullishOrderBlockObjects(); + DestroyBearishOrderBlockObjects(); + + // + // Fair Value Gaps ... + DestroyBullishFVGObjects(); + DestroyBearishFVGObjects(); + } + + /** + * Clean Swing Highs Drawn Objects ... + */ + void DestroySwingHighObjects() + { + mSwingHighObjects.Clear(); + } + + /** + * Clean Swing Lows Drawn Objects ... + */ + void DestroySwingLowObjects() + { + mSwingLowObjects.Clear(); + } + + /** + * Clean Momentum Bars Drawn Objects ... + */ + void DestroyMomentumBarObjects() + { + mMomentumBarObjects.Clear(); + } + + /** + * Clean Rejection Bars Drawn Objects ... + */ + void DestroyRejectionBarObjects() + { + mRejectionBarObjects.Clear(); + } + + /** + * Clean Trading Day Drawn Objects ... + */ + void DestroyTradingTradingDayObjects() + { + mTradingDayObjects.Clear(); + } + + /** + * Destroy Market Sessions Drawn Objects ... + */ + void DestroyMarketSessionObjects() + { + mMarketSessionObjects.Clear(); + } + + /** + * Destroy Support Zone Drawn Objects ... + */ + void DestroySupportZoneObjects() + { + mSupportZoneObjects.Clear(); + } + + /** + * Destroy Resistance Zone Drawn Objects ... + */ + void DestroyResistanceZoneObjects() + { + mResistanceZoneObjects.Clear(); + } + + /** + * Destroy Supply Zone Drawn Objects ... + */ + void DestroySupplyZoneObjects() + { + mSupplyZoneObjects.Clear(); + } + + /** + * Destroy Demand Zone Drawn Objects ... + */ + void DestroyDemandZoneObjects() + { + mDemandZoneObjects.Clear(); + } + + /** + * Destroy Bullish Order Block Drawn Objects ... + */ + void DestroyBullishOrderBlockObjects() + { + mBullishOrderBlockObjects.Clear(); + } + + /** + * Destroy Bearish Order Block Drawn Objects ... + */ + void DestroyBearishOrderBlockObjects() + { + mBearishOrderBlockObjects.Clear(); + } + + /** + * Destroy Bullish FVG Drawn Objects ... + */ + void DestroyBullishFVGObjects() + { + mBullishFVGObjects.Clear(); + } + + /** + * Destroy Bearish FVG Drawn Objects ... + */ + void DestroyBearishFVGObjects() + { + mBearishFVGObjects.Clear(); + } + + // + // ... + + /** + * Detect an Object Exists in Array or not ... + * + * @param name: String ... + * @param array: CArrayObj instance ... + * + * @return ( int ): index of Object ... + */ + int HasObject( + string name, + CArrayObj &array // + ) + { + // + int result = -1; + + // + if (!IsValid(name)) + { + return result; + } + + // + int count = array.Total(); + if (!IsValidSize(count)) + { + return result; + } + + // + for (int i = 0; i < count; i++) + { + // + // XCBaseObject *iObj = ((XCBaseObject *)array.At(i)); + // string objName = iObj.ObjName(); + // if (objName == name) + // { + // // + // result = i; + // break; + // } + } + + // + return result; + } + + // + // Event Handler Notifiers ... + + // + // Trading Days ... + + /** + * Notify New Trading Day Event Handlers ... + * + * @param event: ENUM_XPOI_EVENTS member ... + */ + void NotifyTradingDayEventListeners( + ENUM_XPOI_EVENTS event // + ) + { + // + int count = ArraySize(mTradingDayEventListeners); + if (!IsValidSize(count)) + { + return; + } + + // + for (int i = 0; i < count; i++) + { + // + TXPOIEventHandler iListener = mTradingDayEventListeners[i]; + iListener(event); + } + } + + // + // Market Sessions ... + + /** + * Notify New Market Session Event Handlers ... + * + * @param session: ENUM_XSESSION member ... + * @param event: ENUM_XPOI_EVENTS member ... + */ + void NotifyMarketSessionEventListeners( + ENUM_XSESSION session, + ENUM_XPOI_EVENTS event // + ) + { + // + int count = ArraySize(mMarketSessionEventListeners); + if (!IsValidSize(count)) + { + return; + } + + // + for (int i = 0; i < count; i++) + { + // + TXSessionEventHandler iListener = mMarketSessionEventListeners[i]; + iListener(session, event); + } + } + + // + // Swings ... + + // + // Swing Highs ... + + /** + * Notify New Swing High Point Event Handlers ... + * + * @param event: ENUM_XPOI_EVENTS member ... + * @param bar: XOHCL instance ... + */ + void NotifySwingHighEventListeners( + ENUM_XPOI_EVENTS event, + XOHCL &bar // + ) + { + // + if (!bar.IsValid()) + { + return; + } + + // + int count = ArraySize(mSwingHighEventListeners); + if (!IsValidSize(count)) + { + return; + } + + // + for (int i = 0; i < count; i++) + { + // + TXOHCLEventHandler iListener = mSwingHighEventListeners[i]; + iListener(event, bar); + } + } + + // + // Swing Lows ... + + /** + * Notify New Swing Low Point Event Handlers ... + * + * @param event: ENUM_XPOI_EVENTS member ... + * @param bar: XOHCL instance ... + */ + void NotifySwingLowEventListeners( + ENUM_XPOI_EVENTS event, + XOHCL &bar // + ) + { + // + if (!bar.IsValid()) + { + return; + } + + // + int count = ArraySize(mSwingLowEventListeners); + if (!IsValidSize(count)) + { + return; + } + + // + for (int i = 0; i < count; i++) + { + // + TXOHCLEventHandler iListener = mSwingLowEventListeners[i]; + iListener(event, bar); + } + } + + // + // Momentum Bars ... + + /** + * Notify New Momentum Bar Event Handlers ... + * + * @param event: ENUM_XPOI_EVENTS member ... + * @param bar: XOHCL instance ... + */ + void NotifyMomentumBarEventListeners( + ENUM_XPOI_EVENTS event, + XOHCL &bar // + ) + { + // + if (!bar.IsValid()) + { + return; + } + + // + int count = ArraySize(mMomentumBarEventListeners); + if (!IsValidSize(count)) + { + return; + } + + // + for (int i = 0; i < count; i++) + { + // + TXOHCLEventHandler iListener = mMomentumBarEventListeners[i]; + iListener(event, bar); + } + } + + // + // Rejection Bars ... + + /** + * Notify New Rejection Bar Event Handlers ... + * + * @param event: ENUM_XPOI_EVENTS member ... + * @param bar: XOHCL instance ... + */ + void NotifyRejectionBarEventListeners( + ENUM_XPOI_EVENTS event, + XOHCL &bar // + ) + { + // + if (!bar.IsValid()) + { + return; + } + + // + int count = ArraySize(mRejectionBarEventListeners); + if (!IsValidSize(count)) + { + return; + } + + // + for (int i = 0; i < count; i++) + { + // + TXOHCLEventHandler iListener = mRejectionBarEventListeners[i]; + iListener(event, bar); + } + } + + // + // Support and Resistance Zones ... + + // + // Support Zones ... + + /** + * Notify New Support Zone Event Handlers ... + * + * @param event: ENUM_XPOI_EVENTS member ... + * @param bar: XOHCL instance ... + */ + void NotifySupportZoneEventListeners( + ENUM_XPOI_EVENTS event, + XOHCL &bar // + ) + { + // + if (!bar.IsValid()) + { + return; + } + + // + int count = ArraySize(mSupportZoneEventListeners); + if (!IsValidSize(count)) + { + return; + } + + // + for (int i = 0; i < count; i++) + { + // + TXOHCLEventHandler iListener = mSupportZoneEventListeners[i]; + iListener(event, bar); + } + } + + // + // Resistance Zones ... + + /** + * Notify New Resistance Zone Event Handlers ... + * + * @param event: ENUM_XPOI_EVENTS member ... + * @param bar: XOHCL instance ... + */ + void NotifyResistanceZoneEventListeners( + ENUM_XPOI_EVENTS event, + XOHCL &bar // + ) + { + // + if (!bar.IsValid()) + { + return; + } + + // + int count = ArraySize(mResistanceZoneEventListeners); + if (!IsValidSize(count)) + { + return; + } + + // + for (int i = 0; i < count; i++) + { + // + TXOHCLEventHandler iListener = mResistanceZoneEventListeners[i]; + iListener(event, bar); + } + } + + // + // Supply and Demand Zones ... + + // + // Supply Zones ... + + /** + * Notify New Supply Zone Event Handlers ... + * + * @param event: ENUM_XPOI_EVENTS member ... + * @param bar: XZone instance ... + */ + void NotifySupplyZoneEventListeners( + ENUM_XPOI_EVENTS event, + XZone &zone // + ) + { + // + if (!zone.IsValid()) + { + return; + } + + // + int count = ArraySize(mSupplyZoneEventListeners); + if (!IsValidSize(count)) + { + return; + } + + // + for (int i = 0; i < count; i++) + { + // + TXZoneEventHandler iListener = mSupplyZoneEventListeners[i]; + iListener(event, zone); + } + } + + // + // Demand Zones ... + + /** + * Notify New Demand Zone Event Handlers ... + * + * @param event: ENUM_XPOI_EVENTS member ... + * @param bar: XZone instance ... + */ + void NotifyDemandZoneEventListeners( + ENUM_XPOI_EVENTS event, + XZone &zone // + ) + { + // + if (!zone.IsValid()) + { + return; + } + + // + int count = ArraySize(mDemandZoneEventListeners); + if (!IsValidSize(count)) + { + return; + } + + // + for (int i = 0; i < count; i++) + { + // + TXZoneEventHandler iListener = mDemandZoneEventListeners[i]; + iListener(event, zone); + } + } + + // + // Order Blocks ... + + // + // Bullish Order Blocks ... + + /** + * Notify New Bullish Order Block Event Handlers ... + * + * @param event: ENUM_XPOI_EVENTS member ... + * @param bar: XZone instance ... + */ + void NotifyBullishOrderBlockEventListeners( + ENUM_XPOI_EVENTS event, + XZone &zone // + ) + { + // + if (!zone.IsValid()) + { + return; + } + + // + int count = ArraySize(mBullishOrderBlockEventListeners); + if (!IsValidSize(count)) + { + return; + } + + // + for (int i = 0; i < count; i++) + { + // + TXZoneEventHandler iListener = mBullishOrderBlockEventListeners[i]; + iListener(event, zone); + } + } + + // + // Bearish Order Blocks ... + + /** + * Notify New Bearish Order Block Event Handlers ... + * + * @param event: ENUM_XPOI_EVENTS member ... + * @param bar: XZone instance ... + */ + void NotifyBearishOrderBlockEventListeners( + ENUM_XPOI_EVENTS event, + XZone &zone // + ) + { + // + if (!zone.IsValid()) + { + return; + } + + // + int count = ArraySize(mBearishOrderBlockEventListeners); + if (!IsValidSize(count)) + { + return; + } + + // + for (int i = 0; i < count; i++) + { + // + TXZoneEventHandler iListener = mBearishOrderBlockEventListeners[i]; + iListener(event, zone); + } + } + + // + // Fair Value Gaps ... + + /** + * Notify New Bullish FVG Event Handlers ... + * + * @param event: ENUM_XPOI_EVENTS member ... + * @param bar: XZone instance ... + */ + void NotifyBullishFVGEventListeners( + ENUM_XPOI_EVENTS event, + XZone &zone // + ) + { + // + if (!zone.IsValid()) + { + return; + } + + // + int count = ArraySize(mBullishFVGEventListeners); + if (!IsValidSize(count)) + { + return; + } + + // + for (int i = 0; i < count; i++) + { + // + TXZoneEventHandler iListener = mBullishFVGEventListeners[i]; + iListener(event, zone); + } + } + + /** + * Notify New Bearish FVG Event Handlers ... + * + * @param event: ENUM_XPOI_EVENTS member ... + * @param bar: XZone instance ... + */ + void NotifyBearishFVGEventListeners( + ENUM_XPOI_EVENTS event, + XZone &zone // + ) + { + // + if (!zone.IsValid()) + { + return; + } + + // + int count = ArraySize(mBearishFVGEventListeners); + if (!IsValidSize(count)) + { + return; + } + + // + for (int i = 0; i < count; i++) + { + // + TXZoneEventHandler iListener = mBearishFVGEventListeners[i]; + iListener(event, zone); + } + } + + /** + * Destroy all Registered Event Listeners ... + */ + void DestroyEventListeners() + { + // + // Trading Days ... + Clean(mTradingDayEventListeners); + + // + // Market Sessions ... + Clean(mMarketSessionEventListeners); + + // + // Momentum Bars ... + Clean(mMomentumBarEventListeners); + + // + // Rejection Bars ... + Clean(mRejectionBarEventListeners); + + // + // Swing High and Low (s) ... + Clean(mSwingLowEventListeners); + Clean(mSwingHighEventListeners); + + // + // Support and Resistance Zones ... + Clean(mSupportZoneEventListeners); + Clean(mResistanceZoneEventListeners); + + // + // Supply and Demand Zones ... + Clean(mSupplyZoneEventListeners); + Clean(mDemandZoneEventListeners); + + // + // Order Blocks ... + Clean(mBullishOrderBlockEventListeners); + Clean(mBearishOrderBlockEventListeners); + + // + // Fair Value Gaps ... + Clean(mBullishFVGEventListeners); + Clean(mBearishFVGEventListeners); + } + + // + // ... + // + + // + // Session ... + + /** + * Find Specific Session Index ... + * + * @param session: ENUM_XSESSION member ... + * + * @return ( int ) + */ + int FindSession(ENUM_XSESSION session) + { + // + int result = -1; + + // + int count = ArraySize(mSessions); + if (!IsValidSize(count)) + { + return result; + } + + // + for (int i = 0; i < count; i++) + { + // + XSession iSession = mSessions[i]; + + // + if (iSession.session == session) + { + // + result = i; + break; + } + } + + // + return result; + } + + /** + * Destroy Sessions ... + */ + void DestroySessions() + { + Clean(mSessions); + } + + /** + * Find Specified Trade Day based on Start Time ... + * + * @param start: DateTime ... + * + * @return ( int ) + */ + int HasTradeDay(datetime start) + { + // + int result = -1; + + // + if (!IsValid(start)) + { + return result; + } + + // + int count = ArraySize(mTradingDays); + if (!IsValidSize(count)) + { + return result; + } + + // + for (int i = 0; i < count; i++) + { + // + XTradeDay iDay = mTradingDays[i]; + + // + if (iDay.from == start) + { + // + result = i; + break; + } + } + + // + return result; + } + + /** + * Find Specified Trade Day based on End Time ... + * + * @param start: DateTime ... + * + * @return ( int ) + */ + int HasTradeDayBayEndTime(datetime end) + { + // + int result = -1; + + // + if (!IsValid(end)) + { + return result; + } + + // + int count = ArraySize(mTradingDays); + if (!IsValidSize(count)) + { + return result; + } + + // + for (int i = 0; i < count; i++) + { + // + XTradeDay iDay = mTradingDays[i]; + + // + if (iDay.to == end) + { + // + result = i; + break; + } + } + + // + return result; + } + + // + + /** + * Find Market Session by Providing Start Time ... + * + * @param session: ENUM_XSESSION member ... + * @param start: DateTime ... + * + * @return ( int ) + */ + int HasMarketSessionByStartTime( + ENUM_XSESSION session, + 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]; + + // + if (iMarketSession.session == session && + iMarketSession.from == start) + { + // + result = i; + break; + } + } + + // + return result; + } + + /** + * Find Market Session by Providing Start Time ... + * + * @param session: ENUM_XSESSION member ... + * @param end: DateTime ... + * + * @return ( int ) + */ + int HasMarketSessionByEndTime( + ENUM_XSESSION session, + datetime end // + ) + { + // + int result = -1; + + // + if (!IsValid(end)) + { + return result; + } + + // + int count = ArraySize(mMarketSessions); + if (!IsValidSize(count)) + { + return result; + } + + // + for (int i = 0; i < count; i++) + { + // + XMarketSession iMarketSession = mMarketSessions[i]; + + // + if (iMarketSession.session == session && + iMarketSession.to == end) + { + // + result = i; + break; + } + } + + // + return result; + } + + /** + * Count Specified Market Sessions ... + * + * @param session: ENUM_XSESSION member ... + * + * @return ( int ) + */ + int CountMarketSessions(ENUM_XSESSION session) + { + // + int result = 0; + + // + int count = ArraySize(mMarketSessions); + if (!IsValidSize(count)) + { + return result; + } + + // + for (int i = 0; i < count; i++) + { + // + XMarketSession iMarketSession = mMarketSessions[i]; + + // + if (iMarketSession.session == session) + { + result++; + } + } + + // + return result; + } + + // + int FindBarIndex( + ENUM_XPOIS type, + XOHCL &bar, + XOHCL &list[] // + ) + { + // + int result = -1; + + // + bool isValidType = + type == X_POI_SWING_LOW || + type == X_POI_SWING_HIGH || + type == X_POI_SUPPORT_ZONE || + type == X_POI_MOMENTUM_BAR || + type == X_POI_REJECTION_BAR || + type == X_POI_RESISTANCE_ZONE; + if (!isValidType) + { + return result; + } + + // + int count = ArraySize(list); + if (!IsValidSize(count)) + { + return result; + } + + // + for (int i = 0; i < count; i++) + { + // + XOHCL iBar = list[i]; + + // + bool isSameLow = + bar.low == iBar.low; + + // + bool isSameHigh = + bar.high == iBar.high; + + // + bool isSameUp = + bar.GetUp() == iBar.GetUp(); + + // + bool isSameDown = + bar.GetDown() == iBar.GetDown(); + + // + // Check Conditions Based On Type ... + bool canBreak = false; + if (type == X_POI_SWING_LOW || + type == X_POI_SWING_HIGH || + type == X_POI_MOMENTUM_BAR || + type == X_POI_REJECTION_BAR) + { + // + canBreak = + isSameUp && + isSameLow && + isSameHigh && + isSameDown; + } + else if (type == X_POI_SUPPORT_ZONE) + { + // + canBreak = + isSameLow && + isSameDown; + } + else if (type == X_POI_RESISTANCE_ZONE) + { + // + canBreak = + isSameUp && + isSameHigh; + } + + // + if (canBreak) + { + // + result = i; + break; + } + } + + // + return result; + } + + // + bool AddBar( + ENUM_XPOIS type, + XOHCL &bar, + XOHCL &list[] // + ) + { + // + bool result = false; + + // + result = bar.IsValid(); + if (!result) + { + return result; + } + + // + result = + type == X_POI_SWING_LOW || + type == X_POI_SWING_HIGH || + type == X_POI_SUPPORT_ZONE || + type == X_POI_MOMENTUM_BAR || + type == X_POI_REJECTION_BAR || + type == X_POI_RESISTANCE_ZONE; + if (!result) + { + return result; + } + + // + int idx = FindBarIndex( + type, + bar, + list // + ); + result = !IsValidIndex(idx); + if (!result) + { + return result; + } + + // + AddRef( + bar, + list // + ); + + // + return result; + } + + // + + /** + * Find Specified Zone Index ... + * + * @param zone: XZone instance + * @param list: XZone Collection ... + * + * @return ( int ) + */ + int FindZoneIndex( + XZone &zone, + XZone &list[] // + ) + { + // + int result = -1; + + // + int count = ArraySize(list); + if (!IsValidSize(count)) + { + return result; + } + + // + for (int i = 0; i < count; i++) + { + // + XZone iZone = list[i]; + + // + if (iZone.upper == zone.upper && + iZone.lower == zone.lower) + { + // + result = i; + break; + } + } + + // + return result; + } + + /** + * Add Specific Zone to List ... + * + * @param ob: XOHCL ... + * @param endTime: Datetime ... + * @param type: ENUM_X_POI member ... + * @param list: XZone instance Collection ... + * + * @return ( bool ) + */ + bool AddZone( + XZone &zone, + XOHCL &ob, + datetime endTime, + ENUM_XPOIS type, + XZone &list[] // + ) + { + // + bool result = false; + + // + result = type == X_POI_SUPPORT_ZONE || + type == X_POI_RESISTANCE_ZONE || + type == X_POI_BULLISH_ORDERBLOCK || + type == X_POI_BEARISH_ORDERBLOCK; + if (!result) + { + return result; + } + + // + NormalizeTime(endTime); + + // + datetime startTime = (datetime)((int)ob.time - (PeriodSeconds(mPeriod) * 2)); + + // + result = zone.Init( + ob.high, + ob.low, + ToString(type), + startTime, + endTime // + ); + if (!result) + { + return result; + } + + // + int idx = FindZoneIndex( + zone, + list // + ); + result = !IsValidIndex(idx); + if (!result) + { + return result; + } + + // + AddRef( + zone, + list // + ); + + // + return result; + } + + /** + * Initiate and Add Specific Zone to List ... + * + * @param zone: XZone instance ... + * @param upper: Double ... + * @param lower: Double ... + * @param start: DateTime ... + * @param end: DateTime ... + * @param type: ENUM_XPOIS member ... + * @param list: XZone instance Collection ... + * + * @return ( bool ) + */ + bool AddZone( + XZone &zone, + double upper, + double lower, + datetime start, + datetime end, + ENUM_XPOIS type, + XZone &list[] // + ) + { + // + bool result = false; + + // + result = zone.Init( + upper, + lower, + ToString(type), + start, + end // + ); + if (!result) + { + return result; + } + + // + int idx = FindZoneIndex( + zone, + list // + ); + result = !IsValidIndex(idx); + if (!result) + { + return result; + } + + // + AddRef( + zone, + list // + ); + + // + return result; + } + + /** + * Cleanup Unused Objects ... + */ + void CleanupUnusedPOIs() + { + // + int maxAllowed = MaxNumberOfPOIs(); + if (!IsValidSize(maxAllowed)) + { + return; + } + + // + int tradingDaysCount = ArraySize(mTradingDays); + int marketSessionsCount = ArraySize(mMarketSessions); + int swingHighsCount = ArraySize(mSwingHighs); + int swingLowsCount = ArraySize(mSwingLows); + int momentumBarsCount = ArraySize(mMomentumBars); + int rejectionBarsCount = ArraySize(mRejectionBars); + int supportZonesCount = ArraySize(mSupportZones); + int resistanceZonesCount = ArraySize(mResistanceZones); + int supplyZonesCount = ArraySize(mSupplyZones); + int demandZonesCount = ArraySize(mDemandZones); + int bullishOBsCount = ArraySize(mBullishOrderBlocks); + int bearishOBsCount = ArraySize(mBearishOrderBlocks); + int bullishFVGsCount = ArraySize(mBullishFVGs); + int bearishFVGsCount = ArraySize(mBearishFVGs); + + // + int from = 0; + int requiredPOIs = MaxNumberOfRequiredPOIs(); + int count = maxAllowed - requiredPOIs; + int to = count - 1; + + // + // Trading Days ... + if (tradingDaysCount >= maxAllowed) + { + // + ArrayRemove( + mTradingDays, + from, + count // + ); + + // + mTradingDayObjects.DeleteRange( + from, + to // + ); + } + + // + // Market Sessions ... + if (marketSessionsCount >= maxAllowed) + { + // + ArrayRemove( + mMarketSessions, + from, + count // + ); + + // + mMarketSessionObjects.DeleteRange( + from, + to // + ); + } + + // + // Momentum Bars ... + if (momentumBarsCount >= maxAllowed) + { + // + ArrayRemove( + mMomentumBars, + from, + count // + ); + + // + mMomentumBarObjects.DeleteRange( + from, + to // + ); + } + + // + // Rejection Bars ... + if (rejectionBarsCount >= maxAllowed) + { + // + ArrayRemove( + mRejectionBars, + from, + count // + ); + + // + mRejectionBarObjects.DeleteRange( + from, + to // + ); + } + + // + // Swing High and Low (s) ... + + // + // Swing Highs ... + if (swingHighsCount >= maxAllowed) + { + // + ArrayRemove( + mSwingHighs, + from, + count // + ); + + // + mSwingHighObjects.DeleteRange( + from, + to // + ); + } + + // + // Swing Lows ... + if (swingLowsCount >= maxAllowed) + { + // + ArrayRemove( + mSwingLows, + from, + count // + ); + + // + mSwingLowObjects.DeleteRange( + from, + to // + ); + } + + // + // Support and Resistance Zones ... + + // + // Support Zones ... + if (supportZonesCount >= maxAllowed) + { + // + ArrayRemove( + mSupportZones, + from, + count // + ); + + // + mSupportZoneObjects.DeleteRange( + from, + to // + ); + } + + // + // Resistance Zones ... + if (resistanceZonesCount >= maxAllowed) + { + // + ArrayRemove( + mResistanceZones, + from, + count // + ); + + // + mResistanceZoneObjects.DeleteRange( + from, + to // + ); + } + + // + // Supply and Demand Zones ... + + // + // Supply Zones ... + if (supplyZonesCount >= maxAllowed) + { + // + ArrayRemove( + mSupplyZones, + from, + count // + ); + + // + mSupplyZoneObjects.DeleteRange( + from, + to // + ); + } + + // + // Demand Zones ... + if (demandZonesCount >= maxAllowed) + { + // + ArrayRemove( + mDemandZones, + from, + count // + ); + + // + mDemandZoneObjects.DeleteRange( + from, + to // + ); + } + + // + // Order Blocks ... + + // + // Bullish Order Blocks ... + if (bullishOBsCount >= maxAllowed) + { + // + ArrayRemove( + mBullishOrderBlocks, + from, + count // + ); + + // + mBullishOrderBlockObjects.DeleteRange( + from, + to // + ); + } + + // + // Bearish Order Blocks ... + if (bearishOBsCount >= maxAllowed) + { + // + ArrayRemove( + mBearishOrderBlocks, + from, + count // + ); + + // + mBearishOrderBlockObjects.DeleteRange( + from, + to // + ); + } + + // + // Fair Vakue Gaps ... + + // + // Bullish FVGs ... + if (bullishFVGsCount >= maxAllowed) + { + // + ArrayRemove( + mBullishFVGs, + from, + count // + ); + + // + mBullishFVGObjects.DeleteRange( + from, + to // + ); + } + + // + // Bearish FVGs ... + if (bearishFVGsCount >= maxAllowed) + { + // + ArrayRemove( + mBearishFVGs, + from, + count // + ); + + // + mBearishFVGObjects.DeleteRange( + from, + to // + ); + } + + // + } + + // + private: + // + + // + // Props ... + + // + bool mLock; // Lock State ... + string mSymbol; // Market Symbol ... + ENUM_TIMEFRAMES mPeriod; // Market Period ... + long mChartIdentification; // Chart ID ... + int mSubWindowIdentification; // SubWindowIdentification ID ... + int mMaxNumberOfPOIs; // Max Allowed Number of POI(s) which Can Holds ... + int mMaxNumberOfRequiredPOIs; // Max Allowed Number of POI(s) which Must Find at Initializion Time ... + + // + XBarTracker mBarTracker; // Market Bar Tracker ... + + // + XCPOIDrawer *mDrawer; // POI Drawer ... + + // + // POI Props ... + + // + // Trading Days ... + + // + bool mAllowTradingDays; // Detect Trading Days ... + bool mAllowDrawTradingDays; // Draw Trading Days ... + color mTradingDaysStartColor; // Trading Days Start Color ... + ENUM_LINE_STYLE mTradingDaysStartStyle; // Trading Days Start Style ... + color mTradingDaysEndColor; // Trading Days End Color ... + ENUM_LINE_STYLE mTradingDaysEndStyle; // Trading Days End Style ... + XTradeDay mTradingDays[]; // Trading Days ... + CArrayObj mTradingDayObjects; // Trading Day Chart Objects ... + TXPOIEventHandler mTradingDayEventListeners[]; // Trading Day Event Listeners ... + + /** + * Create an Object to Represent Trading Day on Chart ... + * + * @param day: XTradeDay instance ... + * @param name: String ... + */ + void CreateTradingDayObject( + XTradeDay &day, + string name // + ) + { + // + if (!day.IsValid() || + !IsValid(name)) + { + return; + } + + // + XCTardeDayObject *iObj; + iObj = new XCTardeDayObject(); + bool isCreated = iObj.CreateByDay( + ChartIdentification(), + name, + SubWindowIdentification(), + day // + ); + if (!isCreated) + { + return; + } + + // + iObj.FromColor(TradingDaysStartColor()); + iObj.FromStyle(TradingDaysStartStyle()); + + // + iObj.ToColor(TradingDaysEndColor()); + iObj.ToStyle(TradingDaysEndStyle()); + + // + mTradingDayObjects.Add(iObj); + } + + // + // Market Sessions ... + + // + bool mAllowMarketSessions; // Detect Market Sessions ... + bool mAllowDrawMarketSessions; // Draw Market Sessions ... + int mSessionOpenHours; // How many Hours a Session is Open + XSession mSessions[]; // Forex Sessions + XMarketSession mMarketSessions[]; // Founded Market Sessions ... + CArrayObj mMarketSessionObjects; // Founded Market Session Chart Ojects ... + TXSessionEventHandler mMarketSessionEventListeners[]; // Market Sessions Event Listeners ... + + /** + * Create an Object to Represent Market Session on Chart ... + * + * @param session: XMarketSession instance ... + * @param name: String ... + */ + void CreateMarketSessionObject( + XMarketSession &session, + string name // + ) + { + // + if (!session.IsValid() || + !IsValid(name)) + { + return; + } + + // + // Find XSession Instance ... + int sessionIDX = FindSession(session.session); + if (!IsValidIndex(sessionIDX) || + !mSessions[sessionIDX].allowDraw) + { + return; + } + + // + XCMarketSessionObject *iObj; + iObj = new XCMarketSessionObject(); + bool isCreated = iObj.CreateByMarketSession( + ChartIdentification(), + name, + SubWindowIdentification(), + session // + ); + if (!isCreated) + { + return; + } + + // + iObj.FromColor(mSessions[sessionIDX].startColor); + iObj.FromStyle(mSessions[sessionIDX].startStyle); + + // + iObj.ToColor(mSessions[sessionIDX].endColor); + iObj.ToStyle(mSessions[sessionIDX].endStyle); + + // + mMarketSessionObjects.Add(iObj); + } + + // + // Swing High and Low(s) ... + + // + // Swing Highs ... + + // + bool mAllowSwingHighs; // Detect Swing Highs ... + bool mAllowDrawSwingHighs; // Draw Swing Highs ... + double mSwingHighThreshold; // Threshold Required for Swing High Detection ... + XOHCL mSwingHighs[]; // Swing Highs ... + CArrayObj mSwingHighObjects; // Swing High Chart Objects ... + TXOHCLEventHandler mSwingHighEventListeners[]; // Swing High Event Listeners ... + + // + // Swing Lows ... + + // + bool mAllowSwingLows; // Detect Swing Lows ... + bool mAllowDrawSwingLows; // Draw Swing Lows ... + double mSwingLowThreshold; // Threshold Required for Swing Low Detection ... + XOHCL mSwingLows[]; // Swing Lows ... + CArrayObj mSwingLowObjects; // Swing Low Chart Objects ... + TXOHCLEventHandler mSwingLowEventListeners[]; // Swing Low Event Listeners ... + + // + // Momentum Bars ... + + // + bool mAllowMomentumBars; // Detect Momentum Bars ... + bool mAllowDrawMomentumBars; // Draw Momentum Bars ... + int mMomentumBarPercent; // Momentum Bar Percent ... + double mMomentumBarSharpRatio; // Momentum Bar Sharp Ratio ... + int mMomentumBarLoopBack; // Momentum Bar Loopback ... + XOHCL mMomentumBars[]; // Momentum Bars ... + CArrayObj mMomentumBarObjects; // Momentm Bar Chart Objects ... + TXOHCLEventHandler mMomentumBarEventListeners[]; // Momentum Bars Event Listeners ... + + // + // Rejection Bars .... + + // + bool mAllowRejectionBars; // Detect Rejection Bars ... + bool mAllowDrawRejectionBars; // Draw Rejection Bars ... + int mRejectionBarPercent; // Rejection Bar Percent ... + double mRejectionBarSharpRatio; // Rejection Bar Sharp Ratio ... + int mRejectionBarLoopBack; // Rejection Bar Loopback ... + XOHCL mRejectionBars[]; // Rejection Bars ... + CArrayObj mRejectionBarObjects; // Rejection Bar Chart Objects ... + TXOHCLEventHandler mRejectionBarEventListeners[]; // Rejection Bars Event Listeners ... + + // + // Support and Resistance Zones ... + + // + // Support Zones ... + + // + bool mAllowSupportZones; // Detect Support Zone ... + bool mAllowDrawSupportZones; // Draw Support Zone ... + int mSupportZoneLoopBack; // Support Zone Loopback ... + ENUM_X_PRICE mSupportZonePriceType; // Support Zone Price Type ... + XOHCL mSupportZones[]; // Support Zones ... + CArrayObj mSupportZoneObjects; // Support Zone Chart Objects ... + TXOHCLEventHandler mSupportZoneEventListeners[]; // Support Zone Event Listeners ... + + // + // Resistance Zones ... + + // + bool mAllowResistanceZones; // Detect Resistance Zone ... + bool mAllowDrawResistanceZones; // Draw Resistance Zone ... + int mResistanceZoneLoopBack; // Resistance Zone Loopback ... + ENUM_X_PRICE mResistanceZonePriceType; // Resistance Zone Price Type ... + XOHCL mResistanceZones[]; // Resistance Zones ... + CArrayObj mResistanceZoneObjects; // Resistance Zone Chart Objects ... + TXOHCLEventHandler mResistanceZoneEventListeners[]; // Resistance Zone Event Listeners ... + + // + // Supply and Demand Zones ... + + // + // Supply Zones ... + + // + bool mAllowSupplyZones; // Detect Supply Zone ... + bool mAllowDrawSupplyZones; // Draw Supply Zone ... + ENUM_TIMEFRAMES mSupplyZonePeriod; // Supply Zone Detection Period ... + XZone mSupplyZones[]; // Supply Zones ... + CArrayObj mSupplyZoneObjects; // Supply Zone Chart Objects ... + TXZoneEventHandler mSupplyZoneEventListeners[]; // Supply Zone Event Listeners ... + + // + // Demand Zones ... + + // + bool mAllowDemandZones; // Detect Demand Zone ... + bool mAllowDrawDemandZones; // Draw Demand Zone ... + ENUM_TIMEFRAMES mDemandZonePeriod; // Demand Zone Detection Period ... + XZone mDemandZones[]; // Demand Zones ... + CArrayObj mDemandZoneObjects; // Demand Zone Chart Objects ... + TXZoneEventHandler mDemandZoneEventListeners[]; // Demand Zone Event Listeners ... + + // + // Order Blocks ... + + // + // Bullish Order Blocks ... + + // + bool mAllowBullishOrderBlocks; // Detect Bullish Order Blocks ... + bool mAllowDrawBullishOrderBlocks; // Draw Bullish Order Blocks ... + int mRequiredBarsForBullishOrderBlock; // Minimum Required Same Bars for Bullish Order Blocks ... + XZone mBullishOrderBlocks[]; // Bullish Order Blocks ... + CArrayObj mBullishOrderBlockObjects; // Bullish Order Block Objects ... + TXZoneEventHandler mBullishOrderBlockEventListeners[]; // Bullish Order Block Event Listeners ... + + // + // Bearish Order Blocks ... + + // + bool mAllowBearishOrderBlocks; // Detect Bearish Order Blocks ... + bool mAllowDrawBearishOrderBlocks; // Draw Bearish Order Blocks ... + int mRequiredBarsForBearishOrderBlock; // Minimum Required Same Bars for Bearish Order Blocks ... + XZone mBearishOrderBlocks[]; // Bearish Order Blocks ... + CArrayObj mBearishOrderBlockObjects; // Bearish Order Block Objects ... + TXZoneEventHandler mBearishOrderBlockEventListeners[]; // Bearish Order Block Event Listeners ... + + // + // Fair Value Gaps ... + + // + // Bullish Fair Value Gaps ... + + // + bool mAllowBullishFVGs; // Detect Bullish Fair Value Gaps ... + bool mAllowDrawBullishFVGs; // Draw Bullish Fair Value Gaps ... + bool mBullishFVGForceMiddleBarCheck; // Bullish FVG Force Middle Bar Check ... + bool mBullishFVGForceCheckLastBarDirection; // Bullish FVG Check Last Bar Direction ... + XZone mBullishFVGs[]; // Bullish FVGs ... + CArrayObj mBullishFVGObjects; // Bullish FVG Objects ... + TXZoneEventHandler mBullishFVGEventListeners[]; // Bullish FVG Event Listeners ... + + // + // Bearish Fair Value Gaps ... + + // + bool mAllowBearishFVGs; // Detect Bearish Fair Value Gaps ... + bool mAllowDrawBearishFVGs; // Draw Bearish Fair Value Gaps ... + bool mBearishFVGForceMiddleBarCheck; // Bearish FVG Force Middle Bar Check ... + bool mBearishFVGForceCheckLastBarDirection; // Bearish FVG Check Last Bar Direction ... + XZone mBearishFVGs[]; // Bearish FVGs ... + CArrayObj mBearishFVGObjects; // Bearish FVG Objects ... + TXZoneEventHandler mBearishFVGEventListeners[]; // Bearish FVG Event Listeners ... + + // +}; + +// \ No newline at end of file diff --git a/Documents/BKP/x-saherelm.x-poi.drawer.class.mq5 b/Documents/BKP/x-saherelm.x-poi.drawer.class.mq5 new file mode 100644 index 00000000..550fa934 --- /dev/null +++ b/Documents/BKP/x-saherelm.x-poi.drawer.class.mq5 @@ -0,0 +1,2452 @@ +/////////////////////////////////////////////////////// +// +// SaherElm IT Center MQL5 Class Library +// -------------------------------------- +// Name: XPOIDrawer +// Description: Provides Point of Interests +// Drawing Tools ... +// +// Maintainer: +// ------------ +// Hadi Khazaee Asl (hadi_khazaee_asl@yahoo.com) +// +////////////////////////////////////////////////////// +// +// Global Properties ... +#property library +#property copyright "Copyright 2023, SaherElm IT Center" +#property link "https://www.saherelm.ir" +#property version "1.00" +#property strict + +// +// Imports ... +#include "../Classes/x-saherelm.base.class.mq5" +#include "../Classes/x-saherelm.x-chart-objects.class.mq5" + +// +// Definitions ... +class XCPOIDrawer : public XSCBase +{ + // + public: + // + + // + // Constructor ... + void XCPOIDrawer() + { + // + Default(); + } + + // + // Deconstructor ... + void ~XCPOIDrawer() + { + } + + // + // Setter Getter (s) ... + + /** + * Get Prefix ... + * + * @return ( string ) + */ + string Prefix() + { + return mPrefix; + } + + /** + * Set Prifx ... + * + * @param value: String ... + */ + void Prefix(string value) + { + mPrefix = value; + } + + /** + * Get Chart ID ... + * + * @return ( long ) + */ + long ChartIdentification() + { + return mChartIdentification; + } + + /** + * Set Chart ID ... + * + * @param value: Long ... + */ + void ChartIdentification(long value) + { + // + if (value < 0) + { + value = 0; + } + + // + mChartIdentification = value; + } + + /** + * Get SubWindow Id ... + * + * @return ( int ) + */ + int SubWindowIdentification() + { + return mSubWindowIdentification; + } + + /** + * Set SubWindow Id ... + * + * @param value: Integer ... + */ + void SubWindowIdentification(int value) + { + // + if (value < 0) + { + value = 0; + } + + // + mSubWindowIdentification = value; + } + + // + // Swing Low ... + + /** + * Get Swing Low Width ... + * + * @return ( int ) + */ + int SwingLowWidth() + { + return mSwingLowWidth; + } + + /** + * Set Swing Low Width ... + * + * @param value: Integer ... + */ + void SwingLowWidth(int value) + { + // + if (value < 1) + { + value = 1; + } + + // + mSwingLowWidth = value; + } + + /** + * Get Swing Low Arrow Code ... + * + * @return ( int ) + */ + int SwingLowArrow() + { + return mSwingLowArrow; + } + + /** + * Set Swing Low Arrow Code ... + * + * @param value: Integer ... + */ + void SwingLowArrow(int value) + { + // + mSwingLowArrow = value; + } + + /** + * Get Swing Low Color ... + * + * @return ( color ) + */ + color SwingLowColor() + { + return mSwingLowColor; + } + + /** + * Set Swing Low Color ... + * + * @param value: Color ... + */ + void SwingLowColor(color value) + { + mSwingLowColor = value; + } + + // + // Swing High ... + + /** + * Get Swing High Width ... + * + * @return ( int ) + */ + int SwingHighWidth() + { + return mSwingHighWidth; + } + + /** + * Set Swing High Width ... + * + * @param value: Integer ... + */ + void SwingHighWidth(int value) + { + // + if (value < 1) + { + value = 1; + } + + // + mSwingHighWidth = value; + } + + /** + * Get Swing High Arrow Code ... + * + * @return ( int ) + */ + int SwingHighArrow() + { + return mSwingHighArrow; + } + + /** + * Set Swing High Arrow Code ... + * + * @param value: Integer ... + */ + void SwingHighArrow(int value) + { + // + mSwingHighArrow = value; + } + + /** + * Get Swing High Color ... + * + * @return ( color ) + */ + color SwingHighColor() + { + return mSwingHighColor; + } + + /** + * Set Swing High Color ... + * + * @param value: Color ... + */ + void SwingHighColor(color value) + { + mSwingHighColor = value; + } + + // + // Bullish Momentum Bar ... + + /** + * Get Bullish Momentum Bar Width ... + * + * @return ( int ) + */ + int BullishMomentumBarWidth() + { + return mBullishMomentumBarWidth; + } + + /** + * Set Bullish Momentum Bar Width ... + * + * @param value: Integer ... + */ + void BullishMomentumBarWidth(int value) + { + // + if (value < 1) + { + value = 1; + } + + // + mBullishMomentumBarWidth = value; + } + + /** + * Get Bullish Momentum Bar Arrow Code ... + * + * @return ( int ) + */ + int BullishMomentumBarArrow() + { + return mBullishMomentumBarArrow; + } + + /** + * Set Bullish Momentum Bar Arrow Code ... + * + * @param value: Integer ... + */ + void BullishMomentumBarArrow(int value) + { + // + mBullishMomentumBarArrow = value; + } + + /** + * Get Bullish Momentum Bar Color ... + * + * @return ( color ) + */ + color BullishMomentumBarColor() + { + return mBullishMomentumBarColor; + } + + /** + * Set Bullish Momentum Bar Color ... + * + * @param value: Color ... + */ + void BullishMomentumBarColor(color value) + { + mBullishMomentumBarColor = value; + } + + // + // Bearish Momentum Bar ... + + /** + * Get Bearish Momentum Bar Width ... + * + * @return ( int ) + */ + int BearishMomentumBarWidth() + { + return mBearishMomentumBarWidth; + } + + /** + * Set Bearish Momentum Bar Width ... + * + * @param value: Integer ... + */ + void BearishMomentumBarWidth(int value) + { + // + if (value < 1) + { + value = 1; + } + + // + mBearishMomentumBarWidth = value; + } + + /** + * Get Bearish Momentum Bar Arrow Code ... + * + * @return ( int ) + */ + int BearishMomentumBarArrow() + { + return mBearishMomentumBarArrow; + } + + /** + * Set Bearish Momentum Bar Arrow Code ... + * + * @param value: Integer ... + */ + void BearishMomentumBarArrow(int value) + { + // + mBearishMomentumBarArrow = value; + } + + /** + * Get Bearish Momentum Bar Color ... + * + * @return ( color ) + */ + color BearishMomentumBarColor() + { + return mBearishMomentumBarColor; + } + + /** + * Set Bearish Momentum Bar Color ... + * + * @param value: Color ... + */ + void BearishMomentumBarColor(color value) + { + mBearishMomentumBarColor = value; + } + + // + // Bullish Rejection Bar ... + + /** + * Get Bullish Rejection Bar Width ... + * + * @return ( int ) + */ + int BullishRejectionBarWidth() + { + return mBullishRejectionBarWidth; + } + + /** + * Set Bullish Rejection Bar Width ... + * + * @param value: Integer ... + */ + void BullishRejectionBarWidth(int value) + { + // + if (value < 1) + { + value = 1; + } + + // + mBullishRejectionBarWidth = value; + } + + /** + * Get Bullish Rejection Bar Arrow Code ... + * + * @return ( int ) + */ + int BullishRejectionBarArrow() + { + return mBullishRejectionBarArrow; + } + + /** + * Set Bullish Rejection Bar Arrow Code ... + * + * @param value: Integer ... + */ + void BullishRejectionBarArrow(int value) + { + // + mBullishRejectionBarArrow = value; + } + + /** + * Get Bullish Rejection Bar Color ... + * + * @return ( color ) + */ + color BullishRejectionBarColor() + { + return mBullishRejectionBarColor; + } + + /** + * Set Bullish Rejection Bar Color ... + * + * @param value: Color ... + */ + void BullishRejectionBarColor(color value) + { + mBullishRejectionBarColor = value; + } + + // + // Bearish Rejection Bar ... + + /** + * Get Bearish Rejection Bar Width ... + * + * @return ( int ) + */ + int BearishRejectionBarWidth() + { + return mBearishRejectionBarWidth; + } + + /** + * Set Bearish Rejection Bar Width ... + * + * @param value: Integer ... + */ + void BearishRejectionBarWidth(int value) + { + // + if (value < 1) + { + value = 1; + } + + // + mBearishRejectionBarWidth = value; + } + + /** + * Get Bearish Rejection Bar Arrow Code ... + * + * @return ( int ) + */ + int BearishRejectionBarArrow() + { + return mBearishRejectionBarArrow; + } + + /** + * Set Bearish Rejection Bar Arrow Code ... + * + * @param value: Integer ... + */ + void BearishRejectionBarArrow(int value) + { + // + mBearishRejectionBarArrow = value; + } + + /** + * Get Bearish Rejection Bar Color ... + * + * @return ( color ) + */ + color BearishRejectionBarColor() + { + return mBearishRejectionBarColor; + } + + /** + * Set Bearish Rejection Bar Color ... + * + * @param value: Color ... + */ + void BearishRejectionBarColor(color value) + { + mBearishRejectionBarColor = value; + } + + // + // Supply Zone ... + + /** + * Get Fill Supply Zone ... + * + * @return ( bool ) + */ + bool SupplyZoneFill() + { + return mSupplyZoneFill; + } + + /** + * Set Fill Supply Zone ... + * + * @param value: Boolean ... + */ + void SupplyZoneFill(bool value) + { + mSupplyZoneFill = value; + } + + /** + * Get Supply Zone Width ... + * + * @return ( int ) + */ + int SupplyZoneWidth() + { + return mSupplyZoneWidth; + } + + /** + * Set Supply Zone Width ... + * + * @param value: Integer ... + */ + void SupplyZoneWidth(int value) + { + // + if (value < 1) + { + value = 1; + } + + // + mSupplyZoneWidth = value; + } + + /** + * Get Supply Zone Color ... + * + * @return ( color ) + */ + color SupplyZoneColor() + { + return mSupplyZoneColor; + } + + /** + * Set Supply Zone Color ... + * + * @param value: Color ... + */ + void SupplyZoneColor(color value) + { + mSupplyZoneColor = value; + } + + /** + * Get Supply Zone Style ... + * + * @return ( ENUM_LINE_STYLE ) + */ + ENUM_LINE_STYLE SupplyZoneStyle() + { + return mSupplyZoneStyle; + } + + /** + * Set Supply Zone Style ... + * + * @param value: ENUM_LINE_STYLE member ... + */ + void SupplyZoneStyle(ENUM_LINE_STYLE value) + { + mSupplyZoneStyle = value; + } + + // + // Demand Zone ... + + /** + * Get Fill Demand Zone ... + * + * @return ( bool ) + */ + bool DemandZoneFill() + { + return mDemandZoneFill; + } + + /** + * Set Fill Demand Zone ... + * + * @param value: Boolean ... + */ + void DemandZoneFill(bool value) + { + mDemandZoneFill = value; + } + + /** + * Get Demand Zone Width ... + * + * @return ( int ) + */ + int DemandZoneWidth() + { + return mDemandZoneWidth; + } + + /** + * Set Demand Zone Width ... + * + * @param value: Integer ... + */ + void DemandZoneWidth(int value) + { + // + if (value < 1) + { + value = 1; + } + + // + mDemandZoneWidth = value; + } + + /** + * Get Demand Zone Color ... + * + * @return ( color ) + */ + color DemandZoneColor() + { + return mDemandZoneColor; + } + + /** + * Set Demand Zone Color ... + * + * @param value: Color ... + */ + void DemandZoneColor(color value) + { + mDemandZoneColor = value; + } + + /** + * Get Demand Zone Style ... + * + * @return ( ENUM_LINE_STYLE ) + */ + ENUM_LINE_STYLE DemandZoneStyle() + { + return mDemandZoneStyle; + } + + /** + * Set Demand Zone Style ... + * + * @param value: ENUM_LINE_STYLE member ... + */ + void DemandZoneStyle(ENUM_LINE_STYLE value) + { + mDemandZoneStyle = value; + } + + // + // Resistance Zone ... + + /** + * Get Fill Resistance Zone ... + * + * @return ( bool ) + */ + bool ResistanceZoneFill() + { + return mResistanceZoneFill; + } + + /** + * Set Fill Resistance Zone ... + * + * @param value: Boolean ... + */ + void ResistanceZoneFill(bool value) + { + mResistanceZoneFill = value; + } + + /** + * Get Resistance Zone Width ... + * + * @return ( int ) + */ + int ResistanceZoneWidth() + { + return mResistanceZoneWidth; + } + + /** + * Set Resistance Zone Width ... + * + * @param value: Integer ... + */ + void ResistanceZoneWidth(int value) + { + // + if (value < 1) + { + value = 1; + } + + // + mResistanceZoneWidth = value; + } + + /** + * Get Resistance Zone Color ... + * + * @return ( color ) + */ + color ResistanceZoneColor() + { + return mResistanceZoneColor; + } + + /** + * Set Resistance Zone Color ... + * + * @param value: Color ... + */ + void ResistanceZoneColor(color value) + { + mResistanceZoneColor = value; + } + + /** + * Get Resistance Zone Style ... + * + * @return ( ENUM_LINE_STYLE ) + */ + ENUM_LINE_STYLE ResistanceZoneStyle() + { + return mResistanceZoneStyle; + } + + /** + * Set Resistance Zone Style ... + * + * @param value: ENUM_LINE_STYLE member ... + */ + void ResistanceZoneStyle(ENUM_LINE_STYLE value) + { + mResistanceZoneStyle = value; + } + + // + // Support Zone ... + + /** + * Get Fill Support Zone ... + * + * @return ( bool ) + */ + bool SupportZoneFill() + { + return mSupportZoneFill; + } + + /** + * Set Fill Support Zone ... + * + * @param value: Boolean ... + */ + void SupportZoneFill(bool value) + { + mSupportZoneFill = value; + } + + /** + * Get Support Zone Width ... + * + * @return ( int ) + */ + int SupportZoneWidth() + { + return mSupportZoneWidth; + } + + /** + * Set Support Zone Width ... + * + * @param value: Integer ... + */ + void SupportZoneWidth(int value) + { + // + if (value < 1) + { + value = 1; + } + + // + mSupportZoneWidth = value; + } + + /** + * Get Support Zone Color ... + * + * @return ( color ) + */ + color SupportZoneColor() + { + return mSupportZoneColor; + } + + /** + * Set Support Zone Color ... + * + * @param value: Color ... + */ + void SupportZoneColor(color value) + { + mSupportZoneColor = value; + } + + /** + * Get Support Zone Style ... + * + * @return ( ENUM_LINE_STYLE ) + */ + ENUM_LINE_STYLE SupportZoneStyle() + { + return mSupportZoneStyle; + } + + /** + * Set Support Zone Style ... + * + * @param value: ENUM_LINE_STYLE member ... + */ + void SupportZoneStyle(ENUM_LINE_STYLE value) + { + mSupportZoneStyle = value; + } + + // + // Bullish Order Block ... + + /** + * Get Fill Bullish Order Block ... + * + * @return ( bool ) + */ + bool BullishOrderBlockFill() + { + return mBullishOrderBlockFill; + } + + /** + * Set Fill Bullish Order Block ... + * + * @param value: Boolean ... + */ + void BullishOrderBlockFill(bool value) + { + mBullishOrderBlockFill = value; + } + + /** + * Get Bullish Order Block Width ... + * + * @return ( int ) + */ + int BullishOrderBlockWidth() + { + return mBullishOrderBlockWidth; + } + + /** + * Set Bullish Order Block Width ... + * + * @param value: Integer ... + */ + void BullishOrderBlockWidth(int value) + { + // + if (value < 1) + { + value = 1; + } + + // + mBullishOrderBlockWidth = value; + } + + /** + * Get Bullish Order Block Color ... + * + * @return ( color ) + */ + color BullishOrderBlockColor() + { + return mBullishOrderBlockColor; + } + + /** + * Set Bullish Order Block Color ... + * + * @param value: Color ... + */ + void BullishOrderBlockColor(color value) + { + mBullishOrderBlockColor = value; + } + + /** + * Get Bullish Order Block Style ... + * + * @return ( ENUM_LINE_STYLE ) + */ + ENUM_LINE_STYLE BullishOrderBlockStyle() + { + return mBullishOrderBlockStyle; + } + + /** + * Set Bullish Order Block Style ... + * + * @param value: ENUM_LINE_STYLE member ... + */ + void BullishOrderBlockStyle(ENUM_LINE_STYLE value) + { + mBullishOrderBlockStyle = value; + } + + // + // Bearish Order Block ... + + /** + * Get Fill Bearish Order Block ... + * + * @return ( bool ) + */ + bool BearishOrderBlockFill() + { + return mBearishOrderBlockFill; + } + + /** + * Set Fill Bearish Order Block ... + * + * @param value: Boolean ... + */ + void BearishOrderBlockFill(bool value) + { + mBearishOrderBlockFill = value; + } + + /** + * Get Bearish Order Block Width ... + * + * @return ( int ) + */ + int BearishOrderBlockWidth() + { + return mBearishOrderBlockWidth; + } + + /** + * Set Bearish Order Block Width ... + * + * @param value: Integer ... + */ + void BearishOrderBlockWidth(int value) + { + // + if (value < 1) + { + value = 1; + } + + // + mBearishOrderBlockWidth = value; + } + + /** + * Get Bearish Order Block Color ... + * + * @return ( color ) + */ + color BearishOrderBlockColor() + { + return mBearishOrderBlockColor; + } + + /** + * Set Bearish Order Block Color ... + * + * @param value: Color ... + */ + void BearishOrderBlockColor(color value) + { + mBearishOrderBlockColor = value; + } + + /** + * Get Bearish Order Block Style ... + * + * @return ( ENUM_LINE_STYLE ) + */ + ENUM_LINE_STYLE BearishOrderBlockStyle() + { + return mBearishOrderBlockStyle; + } + + /** + * Set Bearish Order Block Style ... + * + * @param value: ENUM_LINE_STYLE member ... + */ + void BearishOrderBlockStyle(ENUM_LINE_STYLE value) + { + mBearishOrderBlockStyle = value; + } + + // + // Bullish FVG ... + + /** + * Get Fill Bullish FVG ... + * + * @return ( bool ) + */ + bool BullishFVGFill() + { + return mBullishFVGFill; + } + + /** + * Set Fill Bullish FVG ... + * + * @param value: Boolean ... + */ + void BullishFVGFill(bool value) + { + mBearishFVGFill = value; + } + + /** + * Get Bullish FVG Width ... + * + * @return ( int ) + */ + int BullishFVGWidth() + { + return mBullishFVGWidth; + } + + /** + * Set Bullish FVG Width ... + * + * @param value: Integer ... + */ + void BullishFVGWidth(int value) + { + // + if (value < 1) + { + value = 1; + } + + // + mBullishFVGWidth = value; + } + + /** + * Get Bullish FVG Color ... + * + * @return ( color ) + */ + color BullishFVGColor() + { + return mBullishFVGColor; + } + + /** + * Set Bullish FVG Color ... + * + * @param value: Color ... + */ + void BullishFVGColor(color value) + { + mBullishFVGColor = value; + } + + /** + * Get Bullish FVG Style ... + * + * @return ( ENUM_LINE_STYLE ) + */ + ENUM_LINE_STYLE BullishFVGStyle() + { + return mBullishFVGStyle; + } + + /** + * Set Bullish FVG Style ... + * + * @param value: ENUM_LINE_STYLE member ... + */ + void BullishFVGStyle(ENUM_LINE_STYLE value) + { + mBullishFVGStyle = value; + } + + // + // Bearish FVG ... + + /** + * Get Fill Bearish FVG ... + * + * @return ( bool ) + */ + bool BearishFVGFill() + { + return mBearishFVGFill; + } + + /** + * Set Fill Bearish FVG ... + * + * @param value: Boolean ... + */ + void BearishFVGFill(bool value) + { + mBearishFVGFill = value; + } + + /** + * Get Bearish FVG Width ... + * + * @return ( int ) + */ + int BearishFVGWidth() + { + return mBearishFVGWidth; + } + + /** + * Set Bearish FVG Width ... + * + * @param value: Integer ... + */ + void BearishFVGWidth(int value) + { + // + if (value < 1) + { + value = 1; + } + + // + mBearishFVGWidth = value; + } + + /** + * Get Bearish FVG Color ... + * + * @return ( color ) + */ + color BearishFVGColor() + { + return mBearishFVGColor; + } + + /** + * Set Bearish FVG Color ... + * + * @param value: Color ... + */ + void BearishFVGColor(color value) + { + mBearishFVGColor = value; + } + + /** + * Get Bearish FVG Style ... + * + * @return ( ENUM_LINE_STYLE ) + */ + ENUM_LINE_STYLE BearishFVGStyle() + { + return mBearishFVGStyle; + } + + /** + * Set Bearish FVG Style ... + * + * @param value: ENUM_LINE_STYLE member ... + */ + void BearishFVGStyle(ENUM_LINE_STYLE value) + { + mBearishFVGStyle = value; + } + + // + // Object Creators ... + + // + // Swings ... + + /** + * Create Swing High Object ... + * + * @param swing: XOHCL instance ... + * + * @return ( bool ) + */ + bool CreateSwingHigh( + XOHCL &swing, + XCSwingHighObject *&object // + ) + { + // + bool result = false; + + // + object = NULL; + + // + result = swing.IsValid(); + if (!result) + { + return result; + } + + // + long chartID = ChartIdentification(); + int window = SubWindowIdentification(); + + // + string name = swing.GetTag(ToString(X_POI_SWING_HIGH)); + + // + int arrow = SwingHighArrow(); + int width = SwingHighWidth(); + color crl = SwingHighColor(); + + // + object = new XCSwingHighObject(); + result = object.CreateBySwing( + chartID, + name, + window, + swing, + (char)arrow // + ); + + // + if (!result) + { + return result; + } + + // + object.ArrowColor(crl); + object.ArrowWidth(width); + object.ArrowAnchor(ANCHOR_BOTTOM); + + // + return result; + } + + /** + * Create Swing Low Object ... + * + * @param swing: XOHCL instance ... + * + * @return ( bool ) + */ + bool CreateSwingLow( + XOHCL &swing, + XCSwingLowObject *&object // + ) + { + // + bool result = false; + + // + object = NULL; + + // + result = swing.IsValid(); + if (!result) + { + return result; + } + + // + long chartID = ChartIdentification(); + int window = SubWindowIdentification(); + + // + string name = swing.GetTag(ToString(X_POI_SWING_LOW)); + + // + int arrow = SwingLowArrow(); + int width = SwingLowWidth(); + color crl = SwingLowColor(); + + // + object = new XCSwingLowObject(); + result = object.CreateBySwing( + chartID, + name, + window, + swing, + (char)arrow // + ); + + // + if (!result) + { + return result; + } + + // + object.ArrowColor(crl); + object.ArrowWidth(width); + object.ArrowAnchor(ANCHOR_TOP); + + // + return result; + } + + // + // Momentum Bars ... + + /** + * Create Bullish Momentum Bar Object ... + * + * @param bar: XOHCL instance ... + * + * @return ( bool ) + */ + bool CreateBullishMomentumBar( + XOHCL &bar, + XCBullishMomentumBarObject *&object // + ) + { + // + bool result = false; + + // + object = NULL; + + // + result = bar.IsValid(); + if (!result) + { + return result; + } + + // + long chartID = ChartIdentification(); + int window = SubWindowIdentification(); + + // + string name = bar.GetTag(ToString(X_POI_MOMENTUM_BAR)); + + // + int arrow = BullishMomentumBarArrow(); + int width = BullishMomentumBarWidth(); + color crl = BullishMomentumBarColor(); + + // + object = new XCBullishMomentumBarObject(); + result = object.CreateByBar( + chartID, + name, + window, + bar, + (char)arrow // + ); + + // + if (!result) + { + return result; + } + + // + object.ArrowColor(crl); + object.ArrowWidth(width); + object.ArrowAnchor(ANCHOR_TOP); + + // + return result; + } + + /** + * Create Bearish Momentum Bar Object ... + * + * @param bar: XOHCL instance ... + * + * @return ( bool ) + */ + bool CreateBearishMomentumBar( + XOHCL &bar, + XCBearishMomentumBarObject *&object // + ) + { + // + bool result = false; + + // + object = NULL; + + // + result = bar.IsValid(); + if (!result) + { + return result; + } + + // + long chartID = ChartIdentification(); + int window = SubWindowIdentification(); + + // + string name = bar.GetTag(ToString(X_POI_MOMENTUM_BAR)); + + // + int arrow = BearishMomentumBarArrow(); + int width = BearishMomentumBarWidth(); + color crl = BearishMomentumBarColor(); + + // + object = new XCBearishMomentumBarObject(); + result = object.CreateByBar( + chartID, + name, + window, + bar, + (char)arrow // + ); + + // + if (!result) + { + return result; + } + + // + object.ArrowColor(crl); + object.ArrowWidth(width); + object.ArrowAnchor(ANCHOR_TOP); + + // + return result; + } + + // + // Rejection Bars ... + + /** + * Create Bullish Rejection Bar Object ... + * + * @param bar: XOHCL instance ... + * + * @return ( bool ) + */ + bool CreateBullishRejectionBar( + XOHCL &bar, + XCBullishRejectionBarObject *&object // + ) + { + // + bool result = false; + + // + object = NULL; + + // + result = bar.IsValid(); + if (!result) + { + return result; + } + + // + long chartID = ChartIdentification(); + int window = SubWindowIdentification(); + + // + string name = bar.GetTag(ToString(X_POI_REJECTION_BAR)); + + // + int arrow = BullishRejectionBarArrow(); + int width = BullishRejectionBarWidth(); + color crl = BullishRejectionBarColor(); + + // + object = new XCBullishRejectionBarObject(); + result = object.CreateByBar( + chartID, + name, + window, + bar, + (char)arrow // + ); + + // + if (!result) + { + return result; + } + + // + object.ArrowColor(crl); + object.ArrowWidth(width); + object.ArrowAnchor(ANCHOR_TOP); + + // + return result; + } + + /** + * Create Bearish Rejection Bar Object ... + * + * @param bar: XOHCL instance ... + * + * @return ( bool ) + */ + bool CreateBearishRejectionBar( + XOHCL &bar, + XCBearishRejectionBarObject *&object // + ) + { + // + bool result = false; + + // + object = NULL; + + // + result = bar.IsValid(); + if (!result) + { + return result; + } + + // + long chartID = ChartIdentification(); + int window = SubWindowIdentification(); + + // + string name = bar.GetTag(ToString(X_POI_REJECTION_BAR)); + + // + int arrow = BearishRejectionBarArrow(); + int width = BearishRejectionBarWidth(); + color crl = BearishRejectionBarColor(); + + // + object = new XCBearishRejectionBarObject(); + result = object.CreateByBar( + chartID, + name, + window, + bar, + (char)arrow // + ); + + // + if (!result) + { + return result; + } + + // + object.ArrowColor(crl); + object.ArrowWidth(width); + object.ArrowAnchor(ANCHOR_TOP); + + // + return result; + } + + // + // Support and Resistance Zones ... + + /** + * Create Support Zone Object ... + * + * @param bar: XOHCL instance ... + * @param destTime: DateTime ... + * + * @return ( bool ) + */ + bool CreateSupportZone( + XOHCL &bar, + XCSupportZoneObject *&object, + datetime destTime = NULL // + ) + { + // + bool result = false; + + // + object = NULL; + + // + result = bar.IsValid(); + if (!result) + { + return result; + } + + // + long chartID = ChartIdentification(); + int window = SubWindowIdentification(); + + // + string name = bar.GetTag(ToString(X_POI_SUPPORT_ZONE)); + + // + datetime time2 = + IsValid(destTime) + ? destTime + : (datetime)((int)bar.time + (PeriodSeconds(bar.period) * 5)); + + // + bool fill = SupportZoneFill(); + int width = SupportZoneWidth(); + color crl = SupportZoneColor(); + ENUM_LINE_STYLE style = SupportZoneStyle(); + + // + object = new XCSupportZoneObject(); + result = object.CreateBySupport( + chartID, + name, + window, + bar, + time2, + true // + ); + + // + if (!result) + { + return result; + } + + // + object.ZoneFill(fill); + object.ZoneColor(crl); + object.ZoneWidth(width); + object.ZoneStyle(style); + + // + return result; + } + + /** + * Create Resistance Zone Object ... + * + * @param bar: XOHCL instance ... + * + * @return ( bool ) + */ + bool CreateResistanceZone( + XOHCL &bar, + XCResistanceZoneObject *&object, + datetime destTime = NULL // + ) + { + // + bool result = false; + + // + object = NULL; + + // + result = bar.IsValid(); + if (!result) + { + return result; + } + + // + long chartID = ChartIdentification(); + int window = SubWindowIdentification(); + + // + string name = bar.GetTag(ToString(X_POI_RESISTANCE_ZONE)); + + // + datetime time2 = + IsValid(destTime) + ? destTime + : (datetime)((int)bar.time + (PeriodSeconds(bar.period) * 5)); + + // + bool fill = ResistanceZoneFill(); + int width = ResistanceZoneWidth(); + color crl = ResistanceZoneColor(); + ENUM_LINE_STYLE style = ResistanceZoneStyle(); + + // + object = new XCResistanceZoneObject(); + result = object.CreateByResistance( + chartID, + name, + window, + bar, + time2, + true // + ); + + // + if (!result) + { + return result; + } + + // + object.ZoneFill(fill); + object.ZoneColor(crl); + object.ZoneWidth(width); + object.ZoneStyle(style); + + // + return result; + } + + // + // Supply and Demand Zones ... + + /** + * Create Supply Zone Object ... + * + * @param zone: XZone instance ... + * + * @return ( bool ) + */ + bool CreateSupplyZone( + XZone &zone, + XCSupplyZoneObject *&object // + ) + { + // + bool result = false; + + // + object = NULL; + + // + result = zone.IsValid(); + if (!result) + { + return result; + } + + // + long chartID = ChartIdentification(); + int window = SubWindowIdentification(); + + // + string name = zone.GetTag(); + result = Contains( + ToString(X_POI_SUPPLY_ZONE), + name // + ); + if (!result) + { + return result; + } + + // + bool fill = SupplyZoneFill(); + int width = SupplyZoneWidth(); + color crl = SupplyZoneColor(); + ENUM_LINE_STYLE style = SupplyZoneStyle(); + + // + object = new XCSupplyZoneObject(); + result = object.CreateByZone( + chartID, + name, + window, + zone, + NULL, + true // + ); + + // + if (!result) + { + return result; + } + + // + object.ZoneFill(fill); + object.ZoneColor(crl); + object.ZoneWidth(width); + object.ZoneStyle(style); + + // + return result; + } + + /** + * Create Demand Zone Object ... + * + * @param zone: XZone instance ... + * + * @return ( bool ) + */ + bool CreateDemandZone( + XZone &zone, + XCDemandZoneObject *&object // + ) + { + // + bool result = false; + + // + object = NULL; + + // + result = zone.IsValid(); + if (!result) + { + return result; + } + + // + long chartID = ChartIdentification(); + int window = SubWindowIdentification(); + + // + string name = zone.GetTag(); + result = Contains( + ToString(X_POI_DEMAND_ZONE), + name // + ); + if (!result) + { + return result; + } + + // + bool fill = DemandZoneFill(); + int width = DemandZoneWidth(); + color crl = DemandZoneColor(); + ENUM_LINE_STYLE style = DemandZoneStyle(); + + // + object = new XCDemandZoneObject(); + result = object.CreateByZone( + chartID, + name, + window, + zone, + NULL, + true // + ); + + // + if (!result) + { + return result; + } + + // + object.ZoneFill(fill); + object.ZoneColor(crl); + object.ZoneWidth(width); + object.ZoneStyle(style); + + // + return result; + } + + // + // Order Blocks ... + + /** + * Create Bullish Order Block Object ... + * + * @param zone: XZone instance ... + * + * @return ( bool ) + */ + bool CreateBullishOrderBlock( + XZone &zone, + XCBullishOrderBlockObject *&object // + ) + { + // + bool result = false; + + // + object = NULL; + + // + result = zone.IsValid(); + if (!result) + { + return result; + } + + // + long chartID = ChartIdentification(); + int window = SubWindowIdentification(); + + // + string name = zone.GetTag(); + result = Contains( + ToString(X_POI_BULLISH_ORDERBLOCK), + name // + ); + if (!result) + { + return result; + } + + // + bool fill = BullishOrderBlockFill(); + int width = BullishOrderBlockWidth(); + color crl = BullishOrderBlockColor(); + ENUM_LINE_STYLE style = BullishOrderBlockStyle(); + + // + object = new XCBullishOrderBlockObject(); + result = object.CreateByZone( + chartID, + name, + window, + zone, + NULL, + true // + ); + + // + if (!result) + { + return result; + } + + // + object.ZoneFill(fill); + object.ZoneColor(crl); + object.ZoneWidth(width); + object.ZoneStyle(style); + + // + return result; + } + + /** + * Create Bearish Order Block Object ... + * + * @param zone: XZone instance ... + * + * @return ( bool ) + */ + bool CreateBearishOrderBlock( + XZone &zone, + XCBearishOrderBlockObject *&object // + ) + { + // + bool result = false; + + // + object = NULL; + + // + result = zone.IsValid(); + if (!result) + { + return result; + } + + // + long chartID = ChartIdentification(); + int window = SubWindowIdentification(); + + // + string name = zone.GetTag(); + result = Contains( + ToString(X_POI_BEARISH_ORDERBLOCK), + name // + ); + if (!result) + { + return result; + } + + // + bool fill = BearishOrderBlockFill(); + int width = BearishOrderBlockWidth(); + color crl = BearishOrderBlockColor(); + ENUM_LINE_STYLE style = BearishOrderBlockStyle(); + + // + object = new XCBearishOrderBlockObject(); + result = object.CreateByZone( + chartID, + name, + window, + zone, + NULL, + true // + ); + + // + if (!result) + { + return result; + } + + // + object.ZoneFill(fill); + object.ZoneColor(crl); + object.ZoneWidth(width); + object.ZoneStyle(style); + + // + return result; + } + + // + // Order Blocks ... + + /** + * Create Bullish FVG Object ... + * + * @param zone: XZone instance ... + * + * @return ( bool ) + */ + bool CreateBullishFVG( + XZone &zone, + XCBullishFVGObject *&object // + ) + { + // + bool result = false; + + // + object = NULL; + + // + result = zone.IsValid(); + if (!result) + { + return result; + } + + // + long chartID = ChartIdentification(); + int window = SubWindowIdentification(); + + // + string name = zone.GetTag(); + result = Contains( + ToString(X_POI_BULLISH_FVG), + name // + ); + if (!result) + { + return result; + } + + // + bool fill = BullishFVGFill(); + int width = BullishFVGWidth(); + color crl = BullishFVGColor(); + ENUM_LINE_STYLE style = BullishFVGStyle(); + + // + object = new XCBullishFVGObject(); + result = object.CreateByZone( + chartID, + name, + window, + zone, + NULL, + true // + ); + + // + if (!result) + { + return result; + } + + // + object.ZoneFill(fill); + object.ZoneColor(crl); + object.ZoneWidth(width); + object.ZoneStyle(style); + + // + return result; + } + + /** + * Create Bearish FVG Object ... + * + * @param zone: XZone instance ... + * + * @return ( bool ) + */ + bool CreateBearishFVG( + XZone &zone, + XCBearishFVGObject *&object // + ) + { + // + bool result = false; + + // + object = NULL; + + // + result = zone.IsValid(); + if (!result) + { + return result; + } + + // + long chartID = ChartIdentification(); + int window = SubWindowIdentification(); + + // + string name = zone.GetTag(); + result = Contains( + ToString(X_POI_BEARISH_FVG), + name // + ); + if (!result) + { + return result; + } + + // + bool fill = BearishFVGFill(); + int width = BearishFVGWidth(); + color crl = BearishFVGColor(); + ENUM_LINE_STYLE style = BearishFVGStyle(); + + // + object = new XCBearishFVGObject(); + result = object.CreateByZone( + chartID, + name, + window, + zone, + NULL, + true // + ); + + // + if (!result) + { + return result; + } + + // + object.ZoneFill(fill); + object.ZoneColor(crl); + object.ZoneWidth(width); + object.ZoneStyle(style); + + // + return result; + } + + // + protected: + // + + // + void Default() + { + // + // Apply Default Props ... + + // + Prefix(NULL); + ChartIdentification(0); + SubWindowIdentification(0); + + // + SwingLowWidth(1); + SwingLowArrow(108); + SwingLowColor(clrLime); + + // + SwingHighWidth(1); + SwingHighArrow(108); + SwingHighColor(clrRed); + + // + BullishMomentumBarWidth(1); + BullishMomentumBarArrow(225); + BullishMomentumBarColor(clrLime); + + // + BearishMomentumBarWidth(1); + BearishMomentumBarArrow(226); + BearishMomentumBarColor(clrRed); + + // + BullishRejectionBarWidth(1); + BullishRejectionBarArrow(217); + BullishRejectionBarColor(clrLime); + + // + BearishRejectionBarWidth(1); + BearishRejectionBarArrow(218); + BearishRejectionBarColor(clrRed); + + // + SupportZoneFill(true); + SupportZoneWidth(1); + SupportZoneStyle(STYLE_DOT); + SupportZoneColor(clrLime); + + // + ResistanceZoneFill(true); + ResistanceZoneWidth(1); + ResistanceZoneStyle(STYLE_DOT); + ResistanceZoneColor(clrRed); + + // + SupplyZoneFill(true); + SupplyZoneWidth(1); + SupplyZoneStyle(STYLE_DOT); + SupplyZoneColor(clrMagenta); + + // + DemandZoneFill(true); + DemandZoneWidth(1); + DemandZoneStyle(STYLE_DOT); + DemandZoneColor(clrAqua); + + // + BullishOrderBlockFill(true); + BullishOrderBlockWidth(1); + BullishOrderBlockStyle(STYLE_DOT); + BullishOrderBlockColor(clrLime); + + // + BearishOrderBlockFill(true); + BearishOrderBlockWidth(1); + BearishOrderBlockStyle(STYLE_DOT); + BearishOrderBlockColor(clrRed); + + // + BullishFVGFill(true); + BullishFVGWidth(1); + BullishFVGStyle(STYLE_DOT); + BullishFVGColor(clrLime); + + // + BearishFVGFill(true); + BearishFVGWidth(1); + BearishFVGStyle(STYLE_DOT); + BearishFVGColor(clrRed); + + // + } + + // + private: + // + + // + // Props ... + + // + string mPrefix; // Prefix of Created Objects ... + long mChartIdentification; // Chart Id ... + int mSubWindowIdentification; // Sub Window ... + + // + // Swing Low ... + int mSwingLowWidth; // Swing Low Width ... + int mSwingLowArrow; // Swing Low Arrow Code ... + color mSwingLowColor; // Swing Low Color ... + + // + // Swing High ... + int mSwingHighWidth; // Swing High Width ... + int mSwingHighArrow; // Swing High Arrow Code ... + color mSwingHighColor; // Swing High Color ... + + // + // Bullish Momentum Bar ... + int mBullishMomentumBarWidth; // Bullish Momentum Bar Width ... + int mBullishMomentumBarArrow; // Bullish Momentum Bar Arrow Code ... + color mBullishMomentumBarColor; // Bullish Momentum Bar Color ... + + // + // Bearish Momentum Bar ... + int mBearishMomentumBarWidth; // Bearish Momentum Bar Width ... + int mBearishMomentumBarArrow; // Bearish Momentum Bar Arrow Code ... + color mBearishMomentumBarColor; // Bearish Momentum Bar Color ... + + // + // Bullish Rejection Bar ... + int mBullishRejectionBarWidth; // Bullish Rejection Bar High Width ... + int mBullishRejectionBarArrow; // Bullish Rejection Bar High Arrow Code ... + color mBullishRejectionBarColor; // Bullish Rejection Bar High Color ... + + // + // Bearish Rejection Bar ... + int mBearishRejectionBarWidth; // Bearish Rejection Bar Width ... + int mBearishRejectionBarArrow; // Bearish Rejection Bar Arrow Code ... + color mBearishRejectionBarColor; // Bearish Rejection Bar Color ... + + // + // Supply Zone ... + bool mSupplyZoneFill; // Fill Supply Zone ... + int mSupplyZoneWidth; // Supply Zone Width ... + color mSupplyZoneColor; // Supply Zone Color ... + ENUM_LINE_STYLE mSupplyZoneStyle; // Supply Zone Style ... + + // + // Demand Zone ... + bool mDemandZoneFill; // Fill Demand Zone ... + int mDemandZoneWidth; // Demand Zone Width ... + color mDemandZoneColor; // Demand Zone Color ... + ENUM_LINE_STYLE mDemandZoneStyle; // Demand Zone Style ... + + // + // Resistance Zone ... + bool mResistanceZoneFill; // Fill Resistance Zone ... + int mResistanceZoneWidth; // Resistance Zone Width ... + color mResistanceZoneColor; // Resistance Zone Color ... + ENUM_LINE_STYLE mResistanceZoneStyle; // Resistance Zone Style ... + + // + // Support Zone ... + bool mSupportZoneFill; // Fill Support Zone ... + int mSupportZoneWidth; // Support Zone Width ... + color mSupportZoneColor; // Support Zone Color ... + ENUM_LINE_STYLE mSupportZoneStyle; // Support Zone Style ... + + // + // Bullish Order Block ... + bool mBullishOrderBlockFill; // Fill Bullish Order Block ... + int mBullishOrderBlockWidth; // Bullish Order Block Width ... + color mBullishOrderBlockColor; // Bullish Order Block Color ... + ENUM_LINE_STYLE mBullishOrderBlockStyle; // Bullish Order Block Style ... + + // + // Bearish Order Block ... + bool mBearishOrderBlockFill; // Fill Bearish Order Block ... + int mBearishOrderBlockWidth; // Bearish Order Block Width ... + color mBearishOrderBlockColor; // Bearish Order Block Color ... + ENUM_LINE_STYLE mBearishOrderBlockStyle; // Bearish Order Block Style ... + + // + // Bullish FVG ... + bool mBullishFVGFill; // Fill Bullish FVG ... + int mBullishFVGWidth; // Bullish FVG Width ... + color mBullishFVGColor; // Bullish FVG Color ... + ENUM_LINE_STYLE mBullishFVGStyle; // Bullish FVG Style ... + + // + // Bearish FVG ... + bool mBearishFVGFill; // Fill Bearish FVG ... + int mBearishFVGWidth; // Bearish FVG Width ... + color mBearishFVGColor; // Bearish FVG Color ... + ENUM_LINE_STYLE mBearishFVGStyle; // Bearish FVG Style ... + + // +}; \ No newline at end of file diff --git a/Experts/x-saherelm.x-121.smc.ea.mq5 b/Experts/x-saherelm.x-121.smc.ea.mq5 index 9e887987..16134880 100644 --- a/Experts/x-saherelm.x-121.smc.ea.mq5 +++ b/Experts/x-saherelm.x-121.smc.ea.mq5 @@ -23,7 +23,7 @@ // // Imports ... -#include "../X121SMCEA/Experts/x-121.smc.expert.class.mq5" +#include "../X121SMCEA/Experts/x-121.poi.expert.class.mq5" // // Inputs ... @@ -105,7 +105,7 @@ int OnInit() // Configure EA Expert Class ... // - eaExpert.OnSignalEventListener = OnSignalRecieved; + // eaExpert.OnSignalEventListener = OnSignalRecieved; eaExpert.OnPositionSLEventListener = OnStopLossTriggered; eaExpert.OnPositionTPEventListener = OnTakeProfitTriggered; eaExpert.OnPositionForceCloseEventListener = OnPositionForceClosed; @@ -219,17 +219,17 @@ void OnChartEvent( * @param signal: XSignal instance ... * @param conditions: XStrategyConditions instance ... */ -void OnSignalRecieved( - XSignal &signal, - X121SMCStrategyConditions &conditions // -) -{ - // - eaExpert.HandleOnSignalRecieved( - signal, - conditions // - ); -} +// void OnSignalRecieved( +// XSignal &signal, +// X121SMCStrategyConditions &conditions // +// ) +// { +// // +// eaExpert.HandleOnSignalRecieved( +// signal, +// conditions // +// ); +// } /** * Handle StopLoss Triggered Positions ... diff --git a/Helpers/x-saherelm.xcc.helper.mq5 b/Helpers/x-saherelm.xcc.helper.mq5 index 98bec867..485ce71b 100644 --- a/Helpers/x-saherelm.xcc.helper.mq5 +++ b/Helpers/x-saherelm.xcc.helper.mq5 @@ -22,7 +22,7 @@ // // Imports ... -#include "../Classes/x-saherelm.xhelper.class.mq5" +#include "../Classes/x-saherelm.x-helper.class.mq5" // // Definitions ... @@ -131,7 +131,7 @@ struct XCCInputs // // Class ... -class XSCXCCHelper : public XSCBaseHelper +class XCXCCHelper : public XCBaseHelper { // // Public ... @@ -141,13 +141,13 @@ public: // // Constructors ... - XSCXCCHelper() : XSCBaseHelper(_Symbol, _Period) + XCXCCHelper() : XCBaseHelper(_Symbol, _Period) { } // // Deconstructor ... - ~XSCXCCHelper() {} + ~XCXCCHelper() {} // // Tools ... diff --git a/Helpers/x-saherelm.xct.helper.mq5 b/Helpers/x-saherelm.xct.helper.mq5 index 315857a4..0413d267 100644 --- a/Helpers/x-saherelm.xct.helper.mq5 +++ b/Helpers/x-saherelm.xct.helper.mq5 @@ -22,7 +22,7 @@ // // Imports ... -#include "../Classes/x-saherelm.xhelper.class.mq5" +#include "../Classes/x-saherelm.x-helper.class.mq5" // // Definitions ... @@ -114,7 +114,7 @@ struct XCTInputs // // Class ... -class XSCXCTHelper : public XSCBaseHelper +class XCXCTHelper : public XCBaseHelper { // // Public ... @@ -124,13 +124,13 @@ public: // // Constructors ... - XSCXCTHelper() : XSCBaseHelper(_Symbol, _Period) + XCXCTHelper() : XCBaseHelper(_Symbol, _Period) { } // // Deconstructor ... - ~XSCXCTHelper() {} + ~XCXCTHelper() {} // // Tools ... diff --git a/Libraries/x-saherelm.common.lib.mq5 b/Libraries/x-saherelm.common.lib.mq5 index 3ca2fae4..1fa5c459 100644 --- a/Libraries/x-saherelm.common.lib.mq5 +++ b/Libraries/x-saherelm.common.lib.mq5 @@ -21,7 +21,7 @@ // // Imports ... -#include "../Classes/x-saherelm.xmd5.class.mq5" +#include "../Classes/x-saherelm.x-md5.class.mq5" // // Models ... @@ -10322,7 +10322,7 @@ string ToMD5(T content) } // - static XSCMD5 md5; + static XCMD5 md5; // result = md5.Hash(strContent); diff --git a/Libraries/x-saherelm.draw.lib.mq5 b/Libraries/x-saherelm.draw.lib.mq5 new file mode 100644 index 00000000..aeb124ee --- /dev/null +++ b/Libraries/x-saherelm.draw.lib.mq5 @@ -0,0 +1,2620 @@ +/////////////////////////////////////////////////////// +// +// SaherElm IT Center MQL5 Draw Library +// -------------------------------------- +// Name: XDraw +// Description: provides Draw abilities ... +// +// +// Maintainer: +// ------------ +// Hadi Khazaee Asl (hadi_khazaee_asl@yahoo.com) +// +////////////////////////////////////////////////////// +// +// Global Properties ... +#property library +#property copyright "Copyright 2023, SaherElm IT Center" +#property link "https://www.saherelm.ir" +#property version "1.00" +#property strict + +// +// Global Definitions: Variables, Properties and etc ... + +// +// Retrieve Chart Size in Pixel ... +struct XSize +{ + long width; + long height; + + // + int x; + int y; + int w; + int h; + + // + int wStep; + int hStep; +}; + +// +// Define a Draw Specifications ... +struct XDrawSpecifications +{ + // + // Props ... + + // + bool draw; // Draw or Not ... + + // + int width; // Draw Witdth ... + color clr; // Draw Color ... + ENUM_LINE_STYLE style; // Draw Style ... + + // + bool back; // in the background + bool fill; // fill object if supported + bool selection; // highlight to move + bool rayRight; // line's continuation to the right + bool hidden; // hidden in the object list + long zOrder; // priority for mouse click + + // + string label; // Label ... + color labelColor; // Label Color ... + double labelAngel; // Label Angle ... + string labelFont; // Label Font ... + int labelFontSize; // Label Font Size ... + ENUM_ANCHOR_POINT labelAnchor; // Label Anchor Point ... + + // + // Constructor ... + XDrawSpecifications() + { + Clean(); + } + + // + // Operator ... + void operator=(const XDrawSpecifications &value) + { + // + clr = value.clr; + draw = value.draw; + width = value.width; + style = value.style; + + // + back = value.back; + hidden = value.hidden; + zOrder = value.zOrder; + rayRight = value.rayRight; + selection = value.selection; + + // + fill = value.fill; + + // + label = value.label; + labelColor = value.labelColor; + labelAngel = value.labelAngel; + labelFont = value.labelFont; + labelFontSize = value.labelFontSize; + labelAnchor = value.labelAnchor; + } + + // + // Functions ... + + // + void Clean() + { + // + draw = false; + width = 1; + clr = CLR_NONE; + style = STYLE_SOLID; + + // + back = false; + hidden = false; + rayRight = false; + selection = false; + fill = false; + + // + zOrder = 0; + + // + label = ""; + labelColor = CLR_NONE; + labelAngel = 0; + labelFont = "Arial"; + labelFontSize = 20; + labelAnchor = ANCHOR_LEFT_UPPER; + } + + // + void Label( + string mLabel = "", // Label ... + color mLabelColor = CLR_NONE, // Label Color ... + string mLabelFont = "Arial", // Label Font ... + int mLabelFontSize = 20, // Label Font Size ... + ENUM_ANCHOR_POINT mLabelAnchor = ANCHOR_LEFT_UPPER, // Label Anchor Point ... + double mLabelAngel = 0 // Label Angle ... + ) + { + // + label = mLabel; + labelFont = mLabelFont; + labelColor = mLabelColor; + labelAngel = mLabelAngel; + labelAnchor = mLabelAnchor; + labelFontSize = mLabelFontSize; + } +}; + +// +// Candle Draw Specifications ... +struct XOHCLDrawSpecification +{ + // + // Props ... + XDrawSpecifications openStyle; + XDrawSpecifications highStyle; + XDrawSpecifications closeStyle; + XDrawSpecifications lowStyle; + + // + // Constructors ... + XOHCLDrawSpecification() + { + Clean(); + } + + // + // Operators ... + void operator=(const XOHCLDrawSpecification &value) + { + // + lowStyle = value.lowStyle; + openStyle = value.openStyle; + highStyle = value.highStyle; + closeStyle = value.closeStyle; + } + + // + // Functions ... + + // + void Clean() + { + // + lowStyle.Clean(); + openStyle.Clean(); + highStyle.Clean(); + closeStyle.Clean(); + } + + // + void Default() + { + // + // Open ... + openStyle.width = 1; + openStyle.draw = true; + openStyle.clr = clrLime; + openStyle.style = STYLE_SOLID; + openStyle.Label( + "O", + openStyle.clr); + + // + // High ... + highStyle.width = 1; + highStyle.draw = true; + highStyle.clr = clrAqua; + highStyle.style = STYLE_SOLID; + highStyle.Label( + "H", + highStyle.clr); + + // + // Close ... + closeStyle.width = 1; + closeStyle.draw = true; + closeStyle.clr = clrRed; + closeStyle.style = STYLE_SOLID; + closeStyle.Label( + "C", + closeStyle.clr); + + // + // Low ... + lowStyle.width = 1; + lowStyle.draw = true; + lowStyle.clr = clrMagenta; + lowStyle.style = STYLE_SOLID; + lowStyle.Label( + "L", + lowStyle.clr); + } + + // + void Width(int value) + { + // + lowStyle.width = value; + openStyle.width = value; + highStyle.width = value; + closeStyle.width = value; + } + + // + void Style(ENUM_LINE_STYLE value) + { + // + lowStyle.style = value; + openStyle.style = value; + highStyle.style = value; + closeStyle.style = value; + } + + // + void Color(color value) + { + // + lowStyle.clr = value; + openStyle.clr = value; + highStyle.clr = value; + closeStyle.clr = value; + } + + // + void RayRight(bool value) + { + // + lowStyle.rayRight = value; + openStyle.rayRight = value; + highStyle.rayRight = value; + closeStyle.rayRight = value; + } + + // + void Draw(bool value) + { + // + lowStyle.draw = value; + openStyle.draw = value; + highStyle.draw = value; + closeStyle.draw = value; + } + + // + void Back(bool value) + { + // + lowStyle.back = value; + openStyle.back = value; + highStyle.back = value; + closeStyle.back = value; + } + + // + void Fill(bool value) + { + // + lowStyle.fill = value; + openStyle.fill = value; + highStyle.fill = value; + closeStyle.fill = value; + } + + // + void Label(string value) + { + // + lowStyle.Label(value); + openStyle.Label(value); + highStyle.Label(value); + closeStyle.Label(value); + } + + // + void SetLabelPrefix(string value) + { + // + lowStyle.label = value + " " + lowStyle.label; + openStyle.label = value + " " + openStyle.label; + highStyle.label = value + " " + highStyle.label; + closeStyle.label = value + " " + closeStyle.label; + } +}; + +// +string drawPrefix = "X-OBJ"; + +// +// Common Draw Functions ... + +// +// remove drawn objects ... +void RemoveDraws( + string tag = NULL, + long chartId = -1, + int subWindow = -1 // +) +{ + // + // Normalize Args ... + // + if (tag == NULL) + { + tag = drawPrefix; + } + + // + if (chartId == -1) + { + chartId = 0; + } + + // + if (subWindow == -1) + { + subWindow = 0; + } + + // + for (int iObj = ObjectsTotal(chartId, subWindow) - 1; iObj >= 0; iObj--) + { + // + string on = ObjectName(chartId, iObj, subWindow); + if (StringFind(on, tag) >= 0) + { + ObjectDelete(chartId, on); + } + } + + // + // Redraw Chart ... + ChartRedraw(); +} + +// +bool RemoveDraw( + string name, + long chartId = -1, + int subWindow = -1 // +) +{ + // + bool result = false; + + // + if (chartId == -1) + { + chartId = 0; + } + + // + if (subWindow == -1) + { + subWindow = 0; + } + + // + string objName = ""; + for (int iObj = ObjectsTotal(chartId, subWindow) - 1; iObj >= 0; iObj--) + { + // + string on = ObjectName(chartId, iObj, subWindow); + if (StringFind(on, name) >= 0) + { + // + objName = on; + break; + } + } + + // + if (StringLen(objName) > 0) + { + result = ObjectDelete(chartId, objName); + } + + // + return result; +} + +// +// Deselect All Draws ... +void DeselectAllDraws() +{ + // + int objs = ObjectsTotal(ChartID(), 0); + for (int o = 0; o < objs; o++) + { + ObjectSetInteger(ChartID(), ObjectName(ChartID(), o, 0), OBJPROP_SELECTED, false); + } + + // + ChartRedraw(); +} + +// +// Check Object Exists ... +bool IsDrawExists( + string name, + long chartId = -1, + int subWindow = -1 // +) +{ + // + bool result = false; + + // + if (chartId == -1) + { + chartId = 0; + } + + // + if (subWindow == -1) + { + subWindow = 0; + } + + // + for (int iObj = ObjectsTotal(chartId, subWindow) - 1; iObj >= 0; iObj--) + { + // + string on = ObjectName(chartId, iObj, subWindow); + result = StringFind(on, name) >= 0; + if (result) + { + break; + } + } + + // + return result; +} + +// +// Find Specific Object Name ... +string FindObjectName( + string suggest, + long chartId = 0, + int subWindow = 0 // +) +{ + // + string result = NULL; + + // + int objectsCount = ObjectsTotal(chartId, subWindow); + if (objectsCount <= 0) + { + return result; + } + + // + for (int i = objectsCount - 1; i >= 0; i--) + { + // + string iObjectName = ObjectName(chartId, i, subWindow); + bool isExists = StringFind(iObjectName, suggest) >= 0; + if (isExists) + { + // + result = iObjectName; + break; + } + } + + // + return result; +} + +// +// Regular Draws ... + +// +// Arrow Functions ... + +// +// Draw an Arrow Object on Chart ... +bool DrawArrow( + const long chartID = 0, // chart's ID + const string name = "Arrow", // arrow name + const int subWindow = 0, // subwindow index + datetime time = 0, // anchor point time + double price = 0, // anchor point price + const uchar arrowCode = 252, // arrow code + const ENUM_ARROW_ANCHOR anchor = ANCHOR_BOTTOM, // anchor point position + const color clr = clrAqua, // arrow color + const ENUM_LINE_STYLE style = STYLE_SOLID, // border line style + const int width = 3, // arrow size + const bool back = false, // in the background + const bool selection = false, // highlight to move + const bool hidden = false, // hidden in the object list + const long zOrder = 0 // Order Object ... +) +{ + // + bool result = false; + + // + // set anchor point coordinates if they are not set ... + ChangeArrowEmptyPoint(time, price); + + // + // reset the error value ... + ResetLastError(); + + // + // Normalize Name ... + string objName = drawPrefix + "_" + name; + + // + // create an arrow ... + result = ObjectCreate(chartID, objName, OBJ_ARROW, subWindow, time, price); + if (!result) + { + return result; + } + + // + // set the arrow code ... + ObjectSetInteger(chartID, objName, OBJPROP_ARROWCODE, arrowCode); + + // + // set anchor type ... + ObjectSetInteger(chartID, objName, OBJPROP_ANCHOR, anchor); + + // + // set the arrow color ... + ObjectSetInteger(chartID, objName, OBJPROP_COLOR, clr); + + // + // set the border line style ... + ObjectSetInteger(chartID, objName, OBJPROP_STYLE, style); + + // + // set the arrow's size ... + ObjectSetInteger(chartID, objName, OBJPROP_WIDTH, width); + + // + // display in the foreground false or background true ... + ObjectSetInteger(chartID, objName, OBJPROP_BACK, back); + + // + // enable true or disable false the mode of moving the arrow by mouse + // when creating a graphical object using ObjectCreate function, the object cannot be + // highlighted and moved by default. Inside this method, selection parameter + // is false by default, if you want making it possible to highlight and move the object + // change it to true ... + ObjectSetInteger(chartID, objName, OBJPROP_SELECTABLE, true); + ObjectSetInteger(chartID, objName, OBJPROP_SELECTED, selection); + + // + // hide true or display false graphical object name in the object list ... + ObjectSetInteger(chartID, objName, OBJPROP_HIDDEN, hidden); + + // + // set the priority for receiving the event of a mouse click in the chart ... + ObjectSetInteger(chartID, objName, OBJPROP_ZORDER, zOrder); + + // + // successful execution ... + return result; +} + +// +// Move the anchor point of Arrow ... +bool MoveArrow( + const long chartID = 0, // chart's ID + const string name = "Arrow", // object name + datetime time = 0, // anchor point time coordinate + double price = 0 // anchor point price coordinate +) +{ + // + bool result = false; + + // + // Normalize Name ... + string objName = drawPrefix + "_" + name; + + // + // if point position is not set, move it to the current bar having Bid price ... + if (!time) + { + time = TimeCurrent(); + } + + // + if (!price) + { + price = SymbolInfoDouble(_Symbol, SYMBOL_BID); + } + + // + // move the anchor point ... + result = ObjectMove(chartID, objName, 0, time, price); + + // + return result; +} + +// +// Delete an arrow ... +bool DeleteArrow( + const long chartID = 0, // chart's ID + const string name = "Arrow" // arrow name +) +{ + // + bool result = false; + + // + // Normalize Name ... + string objName = drawPrefix + "_" + name; + + // + // delete an arrow ... + result = !ObjectDelete(chartID, objName); + + // + return result; +} + +// +// Change the arrow code ... +bool ArrowCodeChange( + const long chartID = 0, // chart's ID + const string name = "Arrow", // object name + const uchar code = 252 // arrow code +) +{ + // + bool result = false; + + // + // Normalize Name ... + string objName = drawPrefix + "_" + name; + + // + // change the arrow code ... + result = ObjectSetInteger(chartID, objName, OBJPROP_ARROWCODE, code); + + // + return result; +} + +// +// Change anchor type ... +bool ArrowAnchorChange( + const long chartID = 0, // chart's ID + const string name = "Arrow", // object name + const ENUM_ARROW_ANCHOR anchor = ANCHOR_TOP // anchor type +) +{ + // + bool result = false; + + // + // Normalize Name ... + string objName = drawPrefix + "_" + name; + + // + // change anchor type ... + result = !ObjectSetInteger(chartID, objName, OBJPROP_ANCHOR, anchor); + + // + return result; +} + +// +// Check anchor point values and set default values +// for empty ones ... +void ChangeArrowEmptyPoint( + datetime &time, + double &price // +) +{ + // + // if the point's time is not set, it will be on the current bar ... + if (!time) + { + time = TimeCurrent(); + } + + // + // if the point's price is not set, it will have Bid value ... + if (!price) + { + price = SymbolInfoDouble(_Symbol, SYMBOL_BID); + } +} + +// +// Horizontal Line Functions ... + +// +// Create, Draw the horizontal line ... +bool DrawHorizontalLine( + const long chartID = 0, // chart's ID + const string name = "HLine", // line name + const int subWindow = 0, // subwindow index + double price = 0, // line price + const color clr = clrRed, // line color + const ENUM_LINE_STYLE style = STYLE_SOLID, // line style + const int width = 1, // line width + const bool back = false, // in the background + const bool selection = false, // highlight to move + const bool hidden = false, // hidden in the object list + const long zOrder = 0 // priority for mouse click +) +{ + // + bool result = false; + + // + // if the price is not set, set it at the current Bid price level ... + if (!price) + { + price = SymbolInfoDouble(Symbol(), SYMBOL_BID); + } + + // + // Normalize Name ... + string objName = drawPrefix + "_" + name; + + // + // create a horizontal line ... + result = ObjectCreate(chartID, objName, OBJ_HLINE, subWindow, 0, price); + if (!result) + { + return result; + } + + // + // set line color ... + ObjectSetInteger(chartID, objName, OBJPROP_COLOR, clr); + + // + // set line display style ... + ObjectSetInteger(chartID, objName, OBJPROP_STYLE, style); + + // + // set line width ... + ObjectSetInteger(chartID, objName, OBJPROP_WIDTH, width); + + // + // display in the foreground false or background true ... + ObjectSetInteger(chartID, objName, OBJPROP_BACK, back); + + // + // enable true or disable false the mode of moving the line by mouse + // when creating a graphical object using ObjectCreate function, the object cannot be + // highlighted and moved by default. Inside this method, selection parameter + // is true by default making it possible to highlight and move the object + ObjectSetInteger(chartID, objName, OBJPROP_SELECTABLE, selection); + ObjectSetInteger(chartID, objName, OBJPROP_SELECTED, selection); + + // + // hide true or display false graphical object name in the object list ... + ObjectSetInteger(chartID, objName, OBJPROP_HIDDEN, hidden); + + // + // set the priority for receiving the event of a mouse click in the chart ... + ObjectSetInteger(chartID, objName, OBJPROP_ZORDER, zOrder); + + // + // successful execution ... + return result; +} + +// +// Move horizontal line ... +bool MoveHorizontalLine( + const long chartID = 0, // chart's ID + const string name = "HLine", // line name + double price = 0 // line price +) +{ + // + bool result = false; + + // + // Normalize Name ... + string objName = drawPrefix + "_" + name; + + // + // if the line price is not set, move it to the current Bid price level ... + if (!price) + { + price = SymbolInfoDouble(Symbol(), SYMBOL_BID); + } + + // + // move a horizontal line ... + result = ObjectMove(chartID, objName, 0, 0, price); + + // + return result; +} + +// +// Delete a horizontal line ... +bool DeleteHorizontalLine( + const long chartID = 0, // chart's ID + const string name = "HLine" // line name +) +{ + // + bool result = false; + + // + // Normalize Name ... + string objName = drawPrefix + "_" + name; + + // + // delete a horizontal line ... + result = ObjectDelete(chartID, objName); + + // + return result; +} + +// +// Vertical Line Functions ... + +// +// Create the vertical line ... +bool DrawVerticalLine( + const long chartID = 0, // chart's ID + const string name = "VLine", // line name + const int subWindow = 0, // subwindow index + datetime time = 0, // line time + const color clr = clrRed, // line color + const ENUM_LINE_STYLE style = STYLE_SOLID, // line style + const int width = 1, // line width + const bool back = false, // in the background + const bool selection = false, // highlight to move + const bool hidden = false, // hidden in the object list + const long zOrder = 0 // priority for mouse click +) +{ + // + bool result = false; + + // + // if the line time is not set, draw it via the last bar ... + if (!time) + { + time = TimeCurrent(); + } + + // + // Normalize Name ... + string objName = drawPrefix + "_" + name; + + // + // create a vertical line ... + result = ObjectCreate(chartID, objName, OBJ_VLINE, subWindow, time, 0); + if (!result) + { + return result; + } + + // + // set line color ... + ObjectSetInteger(chartID, objName, OBJPROP_COLOR, clr); + + // + // set line display style ... + ObjectSetInteger(chartID, objName, OBJPROP_STYLE, style); + + // + // set line width ... + ObjectSetInteger(chartID, objName, OBJPROP_WIDTH, width); + + // + // display in the foreground false or background true ... + ObjectSetInteger(chartID, objName, OBJPROP_BACK, back); + + // + // enable true or disable false the mode of moving the line by mouse + // when creating a graphical object using ObjectCreate function, the object cannot be + // highlighted and moved by default. Inside this method, selection parameter + // is true by default making it possible to highlight and move the object ... + ObjectSetInteger(chartID, objName, OBJPROP_SELECTABLE, true); + ObjectSetInteger(chartID, objName, OBJPROP_SELECTED, selection); + + // + // hide true or display false graphical object name in the object list ... + ObjectSetInteger(chartID, objName, OBJPROP_HIDDEN, hidden); + + // + // set the priority for receiving the event of a mouse click in the chart + ObjectSetInteger(chartID, objName, OBJPROP_ZORDER, zOrder); + + // + // successful execution ... + return result; +} + +// +// Move the vertical line ... +bool MoveVerticalLine( + const long chartID = 0, // chart's ID + const string name = "VLine", // line name + datetime time = 0 // line time +) +{ + // + bool result = false; + + // + // Normalize Name ... + string objName = drawPrefix + "_" + name; + + // + // if line time is not set, move the line to the last bar ... + if (!time) + { + time = TimeCurrent(); + } + + // + // move the vertical line ... + result = ObjectMove(chartID, objName, 0, time, 0); + + // + return result; +} + +// +// Delete the vertical line ... +bool DeleteVerticalLine( + const long chartID = 0, // chart's ID + const string name = "VLine" // line name +) +{ + // + bool result = false; + + // + // Normalize Name ... + string objName = drawPrefix + "_" + name; + + // + // delete the vertical line ... + result = ObjectDelete(chartID, objName); + + // + return result; +} + +// +// Rectangle Functions ... + +// +// Create rectangle by the given coordinates ... +bool DrawRectangle( + const long chartID = 0, // chart's ID + const string name = "Rectangle", // rectangle name + const int subWindow = 0, // subwindow index + datetime time1 = 0, // down first point time + double price1 = 0, // down first point price + datetime time2 = 0, // up second point time + double price2 = 0, // up second point price + const color clr = clrRed, // rectangle color + const ENUM_LINE_STYLE style = STYLE_SOLID, // style of rectangle lines + const int width = 1, // width of rectangle lines + const bool fill = false, // filling rectangle with color + const bool back = false, // in the background + const bool selection = true, // highlight to move + const bool hidden = true, // hidden in the object list + const long zOrder = 0 // priority for mouse click +) +{ + // + bool result = false; + + // + // Set anchor points' coordinates if they are not set ... + ChangeRectangleEmptyPoints(time1, price1, time2, price2); + + // + // Normalize Name ... + string objName = drawPrefix + "_" + name; + + // + // Create a rectangle by the given coordinates ... + result = ObjectCreate( + chartID, + objName, + OBJ_RECTANGLE, + subWindow, + time1, + price1, + time2, + price2 // + ); + if (!result) + { + return result; + } + + // + // Set rectangle color ... + ObjectSetInteger(chartID, objName, OBJPROP_COLOR, clr); + + // + // Set the style of rectangle lines + ObjectSetInteger(chartID, objName, OBJPROP_STYLE, style); + + // + // Set width of the rectangle lines ... + ObjectSetInteger(chartID, objName, OBJPROP_WIDTH, width); + + // + // Enable (true) or disable (false) the mode of filling the rectangle ... + ObjectSetInteger(chartID, objName, OBJPROP_FILL, fill); + + // + // Display in the foreground (false) or background (true) ... + ObjectSetInteger(chartID, objName, OBJPROP_BACK, back); + + // + // Enable (true) or disable (false) the mode of highlighting the rectangle for moving + // when creating a graphical object using ObjectCreate function, the object cannot be + // highlighted and moved by default. Inside this method, selection parameter + // is true by default making it possible to highlight and move the object + ObjectSetInteger(chartID, objName, OBJPROP_SELECTABLE, selection); + + // + ObjectSetInteger(chartID, objName, OBJPROP_SELECTED, selection); + + // + // Hide (true) or display (false) graphical object name in the object list ... + ObjectSetInteger(chartID, objName, OBJPROP_HIDDEN, hidden); + + // + // Set the priority for receiving the event of a mouse click in the chart ... + ObjectSetInteger(chartID, objName, OBJPROP_ZORDER, zOrder); + + // + // Successful execution + return result; +} + +// +// Move the rectangle anchor point ...s +bool RectanglePointChange( + const long chartID = 0, // chart's ID + const string name = "Rectangle", // rectangle name + const int pointIndex = 0, // anchor point index + datetime time = 0, // anchor point time coordinate + double price = 0 // anchor point price coordinate +) +{ + // + bool result = false; + + // + // Normalize Name ... + string objName = drawPrefix + "_" + name; + + // + // if point position is not set, move it to the current bar having Bid price ... + if (!time) + { + time = TimeCurrent(); + } + + // + if (!price) + { + price = SymbolInfoDouble(Symbol(), SYMBOL_BID); + } + + // + // Move the anchor point ... + result = ObjectMove(chartID, objName, pointIndex, time, price); + + // + return result; +} + +// +// Delete the rectangle ... +bool DeleteRectangle( + const long chartID = 0, // chart's ID + const string name = "Rectangle" // rectangle name +) +{ + // + bool result = false; + + // + // Normalize Name ... + string objName = drawPrefix + "_" + name; + + // + result = ObjectDelete(chartID, objName); + + // + return result; +} + +// +// Check the values of rectangle's anchor points and set default +// values for empty ones +void ChangeRectangleEmptyPoints( + datetime &time1, double &price1, + datetime &time2, double &price2 // +) +{ + // + // if the first point's time is not set, it will be on the current bar ... + if (!time1) + { + time1 = TimeCurrent(); + } + + // + // if the first point's price is not set, it will have Bid value ... + if (!price1) + { + price1 = SymbolInfoDouble(Symbol(), SYMBOL_BID); + } + + // + // if the second point's time is not set, it is located 9 bars left from the second one ... + if (!time2) + { + // + // array for receiving the open time of the last 10 bars ... + datetime temp[10]; + CopyTime(Symbol(), Period(), time1, 10, temp); + + // + // set the second point 9 bars left from the first one ... + time2 = temp[0]; + } + + // + // if the second point's price is not set, move it 300 points lower than the first one ... + if (!price2) + { + price2 = price1 - 300 * SymbolInfoDouble(Symbol(), SYMBOL_POINT); + } +} + +// +// RectangleLabel Functions ... + +// +// Create Rectangle Label Object ... +bool DrawRectangleLabel( + const long chartID = 0, // chart's ID + const string name = "RectLabel", // label name + const int subWindow = 0, // subwindow index + const int x = 0, // X coordinate + const int y = 0, // Y coordinate + const int width = 50, // width + const int height = 18, // height + const color bgColor = clrWhiteSmoke, // background color + const ENUM_BORDER_TYPE border = BORDER_SUNKEN, // border type + const ENUM_BASE_CORNER corner = CORNER_LEFT_UPPER, // chart corner for anchoring + const color clr = clrRed, // flat border color (Flat) + const ENUM_LINE_STYLE style = STYLE_SOLID, // flat border style + const int lineWidth = 1, // flat border width + const bool back = false, // in the background + const bool selection = false, // highlight to move + const bool hidden = false, // hidden in the object list + const long zOrder = 0 // priority for mouse click +) +{ + // + bool result = false; + + // + // Normalize Name ... + string objName = drawPrefix + "_" + name; + + // + // create a rectangle label + result = ObjectCreate(chartID, objName, OBJ_RECTANGLE_LABEL, subWindow, 0, 0); + if (!result) + { + return result; + } + + // + // set label coordinates ... + ObjectSetInteger(chartID, objName, OBJPROP_XDISTANCE, x); + ObjectSetInteger(chartID, objName, OBJPROP_YDISTANCE, y); + + // + // set label size ... + ObjectSetInteger(chartID, objName, OBJPROP_XSIZE, width); + ObjectSetInteger(chartID, objName, OBJPROP_YSIZE, height); + + // + // set background color ... + ObjectSetInteger(chartID, objName, OBJPROP_BGCOLOR, bgColor); + + // + // set border type ... + ObjectSetInteger(chartID, objName, OBJPROP_BORDER_TYPE, border); + + // + // set the chart's corner, relative to which point coordinates are defined ... + ObjectSetInteger(chartID, objName, OBJPROP_CORNER, corner); + + // + // set flat border color (in Flat mode) ... + ObjectSetInteger(chartID, objName, OBJPROP_COLOR, clr); + + // + // set flat border line style ... + ObjectSetInteger(chartID, objName, OBJPROP_STYLE, style); + + // + // set flat border width ... + ObjectSetInteger(chartID, objName, OBJPROP_WIDTH, lineWidth); + + // + // display in the foreground false or background true ... + ObjectSetInteger(chartID, objName, OBJPROP_BACK, back); + + // + // enable true or disable false the mode of moving the label by mouse ... + ObjectSetInteger(chartID, objName, OBJPROP_SELECTABLE, selection); + ObjectSetInteger(chartID, objName, OBJPROP_SELECTED, selection); + + // + // hide true or display false graphical object name in the object list ... + ObjectSetInteger(chartID, objName, OBJPROP_HIDDEN, hidden); + + // + // set the priority for receiving the event of a mouse click in the chart ... + ObjectSetInteger(chartID, objName, OBJPROP_ZORDER, zOrder); + + // + // successful execution ... + return result; +} + +// +// Move Rectangle Label .. +bool MoveRectangleLabel( + const long chartID = 0, // chart's ID + const string name = "RectLabel", // label name + const int x = 0, // X coordinate + const int y = 0 // Y coordinate +) +{ + // + bool result = false; + + // + // Normalize Name ... + string objName = drawPrefix + "_" + name; + + // + // move the rectangle label ... + result = ObjectSetInteger(chartID, objName, OBJPROP_XDISTANCE, x); + if (!result) + { + return result; + } + + // + result = ObjectSetInteger(chartID, objName, OBJPROP_YDISTANCE, y); + + // + return result; +} + +// +// Delete the rectangle label ... +bool DeleteRectangleLabel( + const long chartID = 0, // chart's ID + const string name = "RectLabel" // label name +) +{ + // + bool result = false; + + // + // Normalize Name ... + string objName = drawPrefix + "_" + name; + + // + // delete the label ... + result = ObjectDelete(chartID, objName); + + // + return result; +} + +// +// Change Rectangle Label Size ... +bool ChangeSizeRectangleLabel( + const long chartID = 0, // chart's ID + const string name = "RectLabel", // label name + const int width = 50, // label width + const int height = 18 // label height +) +{ + // + bool result = false; + + // + // Normalize Name ... + string objName = drawPrefix + "_" + name; + + // + // change label size ... + result = ObjectSetInteger(chartID, objName, OBJPROP_XSIZE, width); + if (!result) + { + return result; + } + + // + result = ObjectSetInteger(chartID, objName, OBJPROP_YSIZE, height); + + // + return result; +} + +// +// Change rectangle label border type ... +bool RectLabelChangeBorderType( + const long chartID = 0, // chart's ID + const string name = "RectLabel", // label name + const ENUM_BORDER_TYPE border = BORDER_SUNKEN // border type +) +{ + // + bool result = false; + + // + // Normalize Name ... + string objName = drawPrefix + "_" + name; + + // + // change border type ... + result = ObjectSetInteger(chartID, objName, OBJPROP_BORDER_TYPE, border); + + // + return result; +} + +// +// TrendLine Funcions ... + +// +// Create a trend line by the given coordinates ... +bool DrawTrendLine( + const long chartID = 0, // chart's ID + const string name = "TrendLine", // line name + const int subWindow = 0, // subwindow index + datetime time1 = 0, // first point time + double price1 = 0, // first point price + datetime time2 = 0, // second point time + double price2 = 0, // second point price + const color clr = clrYellow, // line color + const ENUM_LINE_STYLE style = STYLE_SOLID, // line style + const int width = 1, // line width + const bool back = false, // in the background + const bool selection = false, // highlight to move + const bool rayRight = false, // line's continuation to the right + const bool hidden = false, // hidden in the object list + const long zOrder = 0 // priority for mouse click +) +{ + // + bool result = false; + + // + // set anchor points' coordinates if they are not set ... + ChangeTrendLineEmptyPoints( + time1, + price1, + time2, + price2); + + // + // Normalize Name ... + string objName = drawPrefix + "_" + name; + + // + // create a trend line by the given coordinates ... + result = ObjectCreate(chartID, objName, OBJ_TREND, subWindow, time1, price1, time2, price2); + if (!result) + { + return result; + } + + // + // set line color ... + ObjectSetInteger(chartID, objName, OBJPROP_COLOR, clr); + + // + // set line display style ... + ObjectSetInteger(chartID, objName, OBJPROP_STYLE, style); + + // + // set line width ... + ObjectSetInteger(chartID, objName, OBJPROP_WIDTH, width); + + // + // display in the foreground false or background true ... + ObjectSetInteger(chartID, objName, OBJPROP_BACK, back); + + // + // enable true or disable false the mode of moving the line by mouse + // when creating a graphical object using ObjectCreate function, the object cannot be + // highlighted and moved by default. Inside this method, selection parameter + // is true by default making it possible to highlight and move the object ... + ObjectSetInteger(chartID, objName, OBJPROP_SELECTABLE, true); + ObjectSetInteger(chartID, objName, OBJPROP_SELECTED, selection); + + // + // enable true or disable false the mode of continuation of the line's display to the right ... + ObjectSetInteger(chartID, objName, OBJPROP_RAY_RIGHT, rayRight); + + // + // hide true or display false graphical object name in the object list ... + ObjectSetInteger(chartID, objName, OBJPROP_HIDDEN, hidden); + + // + // set the priority for receiving the event of a mouse click in the chart ... + ObjectSetInteger(chartID, objName, OBJPROP_ZORDER, zOrder); + + // + // successful execution ... + return result; +} + +// +// Move trend line anchor point ... | +bool ChangeTrendLinePoint( + const long chartID = 0, // chart's ID + const string name = "TrendLine", // line name + const int pointindex = 0, // anchor point index + datetime time = 0, // anchor point time coordinate + double price = 0 // anchor point price coordinate +) +{ + // + bool result = false; + + // + // Normalize Name ... + string objName = drawPrefix + "_" + name; + + // + // if point position is not set, move it to the current bar having Bid price ... + if (!time) + { + time = TimeCurrent(); + } + + // + if (!price) + { + price = SymbolInfoDouble(Symbol(), SYMBOL_BID); + } + + // + // move trend line's anchor point ... + result = ObjectMove(chartID, objName, pointindex, time, price); + + // + return result; +} + +// +// The function deletes the trend line from the chart ... +bool DeleteTrendLine( + const long chartID = 0, // chart's ID + const string name = "TrendLine" // line name +) +{ + // + bool result = false; + + // + // Normalize Name ... + string objName = drawPrefix + "_" + name; + + // + // delete a trend line ... + result = ObjectDelete(chartID, objName); + + // + return result; +} + +// +// Check the values of trend line's anchor points and set default ... +// values for empty ones ... +void ChangeTrendLineEmptyPoints( + datetime &time1, + double &price1, + datetime &time2, + double &price2 // +) +{ + // + // if the first point's time is not set, it will be on the current bar ... + if (!time1) + { + time1 = TimeCurrent(); + } + + // + // if the first point's price is not set, it will have Bid value ... + if (!price1) + { + price1 = SymbolInfoDouble(Symbol(), SYMBOL_BID); + } + + // + // if the second point's time is not set, it is located 9 bars left from the second one ... + if (!time2) + { + // + // array for receiving the open time of the last 10 bars ... + datetime temp[10]; + CopyTime(Symbol(), Period(), time1, 10, temp); + + // + // set the second point 9 bars left from the first one ... + time2 = temp[0]; + } + + // + // if the second point's price is not set, it is equal to the first point's one ... + if (!price2) + { + price2 = price1; + } +} + +// +// Text Functions ... + +// +// Create and Draw a Text Object ... +bool DrawText( + const long chartID = 0, // chart's ID + const string name = "Text", // object name + const int subWindow = 0, // subwindow index + datetime time = 0, // anchor point time + double price = 0, // anchor point price + const string text = "Text", // the text itself + const string font = "Arial", // font + const int fontSize = 10, // font size + const color clr = clrRed, // color + const double angle = 0.0, // text slope + const ENUM_ANCHOR_POINT anchor = ANCHOR_CENTER, // anchor type + const bool back = false, // in the background + const bool selection = false, // highlight to move + const bool hidden = true, // hidden in the object list + const long zOrder = 0 // priority for mouse click +) +{ + // + bool result = false; + + // + // set anchor point coordinates if they are not set ... + ChangeTextEmptyPoint(time, price); + + // + // Normalize Name ... + string objName = drawPrefix + "_" + name; + + // + // + // create Text object + result = ObjectCreate(chartID, objName, OBJ_TEXT, subWindow, time, price); + if (!result) + { + return result; + } + + // + // set the text ... + ObjectSetString(chartID, objName, OBJPROP_TEXT, text); + + // + // set text font ... + ObjectSetString(chartID, objName, OBJPROP_FONT, font); + + // + // set font size ... + ObjectSetInteger(chartID, objName, OBJPROP_FONTSIZE, fontSize); + + // + // set the slope angle of the text ... + ObjectSetDouble(chartID, objName, OBJPROP_ANGLE, angle); + + // + // set anchor type ... + ObjectSetInteger(chartID, objName, OBJPROP_ANCHOR, anchor); + + // + // set color ... + ObjectSetInteger(chartID, objName, OBJPROP_COLOR, clr); + + // + // display in the foreground false or background true ... + ObjectSetInteger(chartID, objName, OBJPROP_BACK, back); + + // + // enable true or disable false the mode of moving the object by mouse ... + ObjectSetInteger(chartID, objName, OBJPROP_SELECTABLE, true); + ObjectSetInteger(chartID, objName, OBJPROP_SELECTED, selection); + + // + // hide true or display false graphical object name in the object list ... + ObjectSetInteger(chartID, objName, OBJPROP_HIDDEN, hidden); + + // + // set the priority for receiving the event of a mouse click in the chart ... + ObjectSetInteger(chartID, objName, OBJPROP_ZORDER, zOrder); + + // + // successful execution ... + return result; +} + +// +// Move the anchor point ... +bool MoveText( + const long chartID = 0, // chart's ID + const string name = "Text", // object name + datetime time = 0, // anchor point time coordinate + double price = 0 // anchor point price coordinate +) +{ + // + bool result = false; + + // + // Normalize Name ... + string objName = drawPrefix + "_" + name; + + // + // + // if point position is not set, move it to the current bar having Bid price + if (!time) + { + time = TimeCurrent(); + } + + // + if (!price) + { + price = SymbolInfoDouble(_Symbol, SYMBOL_BID); + } + + // + // move the anchor point ... + result = ObjectMove(chartID, objName, 0, time, price); + + // + return result; +} + +// +// Change the object text ... +bool ChangeText( + const long chartID = 0, // chart's ID + const string name = "Text", // object name + const string text = "Text" // text +) +{ + // + bool result = false; + + // + // Normalize Name ... + string objName = drawPrefix + "_" + name; + + // + // change object text ... + result = ObjectSetString(chartID, objName, OBJPROP_TEXT, text); + + // + return result; +} + +// +// Delete Text object ... +bool DeleteText( + const long chartID = 0, // chart's ID + const string name = "Text" // object name +) +{ + // + bool result = false; + + // + // Normalize Name ... + string objName = drawPrefix + "_" + name; + + // + // delete the object ... + result = ObjectDelete(chartID, objName); + + // + return result; +} + +// +// Check anchor point values and set default values +// for empty ones ... +void ChangeTextEmptyPoint( + datetime &time, + double &price // +) +{ + // + // if the point's time is not set, it will be on the current bar ... + if (!time) + { + time = TimeCurrent(); + } + + // + // if the point's price is not set, it will have Bid value ... + if (!price) + { + price = SymbolInfoDouble(_Symbol, SYMBOL_BID); + } +} + +// +// Fibonacchi Functions ... + +// +// Create Fibonacci Retracement by the given coordinates ... +bool DrawFibonacci( + const long chartID = 0, // chart's ID + const string name = "Fibonacci", // object name + const int subWindow = 0, // subwindow index + datetime time1 = 0, // first point time + double price1 = 0, // first point price + datetime time2 = 0, // second point time + double price2 = 0, // second point price + const color clr = clrRed, // object color + const ENUM_LINE_STYLE style = STYLE_SOLID, // object line style + const int width = 1, // object line width + const bool back = false, // in the background + const bool selection = true, // highlight to move + const bool rayRight = false, // object's continuation to the right + const bool hidden = true, // hidden in the object list + const long zOrder = 0 // priority for mouse click +) +{ + // + bool result = false; + + // + // set anchor points' coordinates if they are not set ... + ChangeFibonacciEmptyPoints(time1, price1, time2, price2); + + // + // Normalize Name ... + string objName = drawPrefix + "_" + name; + + // + // Create Fibonacci Retracement by the given coordinates ... + result = ObjectCreate(chartID, objName, OBJ_FIBO, subWindow, time1, price1, time2, price2); + if (!result) + { + return result; + } + + // + // set color ... + ObjectSetInteger(chartID, objName, OBJPROP_COLOR, clr); + + // + // set line style ... + ObjectSetInteger(chartID, objName, OBJPROP_STYLE, style); + + // + // set line width ... + ObjectSetInteger(chartID, objName, OBJPROP_WIDTH, width); + + // + // display in the foreground false or background true ... + ObjectSetInteger(chartID, objName, OBJPROP_BACK, back); + + // + // enable true or disable false the mode of highlighting the channel for moving + // when creating a graphical object using ObjectCreate function, the object cannot be + // highlighted and moved by default. Inside this method, selection parameter + // is true by default making it possible to highlight and move the object ... + ObjectSetInteger(chartID, objName, OBJPROP_SELECTABLE, true); + ObjectSetInteger(chartID, objName, OBJPROP_SELECTED, selection); + + // + // enable true or disable false the mode of continuation of the object's display to the right ... + ObjectSetInteger(chartID, objName, OBJPROP_RAY_RIGHT, rayRight); + + // + // hide true or display false graphical object name in the object list ... + ObjectSetInteger(chartID, objName, OBJPROP_HIDDEN, hidden); + + // + // set the priority for receiving the event of a mouse click in the chart ... + ObjectSetInteger(chartID, objName, OBJPROP_ZORDER, zOrder); + + // + // successful execution ... + return result; +} + +// +// Create Fibonacci Retracement by the given coordinates ... +bool DrawCustomFibonacci( + // + int levels, // number of level lines + double &values[], // values of level lines + color &colors[], // color of level lines + ENUM_LINE_STYLE &styles[], // style of level lines + int &widths[], // width of level lines + string &descriptions[], // level Descriptions + // + const long chartID = 0, // chart's ID + const string name = "Fibonacci", // object name + const int subWindow = 0, // subwindow index + datetime time1 = 0, // first point time + double price1 = 0, // first point price + datetime time2 = 0, // second point time + double price2 = 0, // second point price + const color clr = clrAqua, // object color + const ENUM_LINE_STYLE style = STYLE_DOT, // object line style + const int width = 1, // object line width + const bool back = false, // in the background + const bool selection = true, // highlight to move + const bool rayRight = false, // object's continuation to the right + const bool hidden = true, // hidden in the object list + const long zOrder = 0 // priority for mouse click +) +{ + // + bool result = false; + + // + // set anchor points' coordinates if they are not set ... + ChangeFibonacciEmptyPoints(time1, price1, time2, price2); + + // + // Normalize Name ... + string objName = drawPrefix + "_" + name; + + // + // Create Fibonacci Retracement by the given coordinates ... + result = ObjectCreate(chartID, name, OBJ_FIBO, subWindow, time1, price1, time2, price2); + if (!result) + { + return result; + } + + // + // set color ... + ObjectSetInteger(chartID, objName, OBJPROP_COLOR, clr); + + // + // set line style ... + ObjectSetInteger(chartID, objName, OBJPROP_STYLE, style); + + // + // set line width ... + ObjectSetInteger(chartID, objName, OBJPROP_WIDTH, width); + + // + // display in the foreground false or background true ... + ObjectSetInteger(chartID, objName, OBJPROP_BACK, back); + + // + // enable true or disable false the mode of highlighting the channel for moving + // when creating a graphical object using ObjectCreate function, the object cannot be + // highlighted and moved by default. Inside this method, selection parameter + // is true by default making it possible to highlight and move the object ... + ObjectSetInteger(chartID, objName, OBJPROP_SELECTABLE, true); + ObjectSetInteger(chartID, objName, OBJPROP_SELECTED, selection); + + // + // enable true or disable false the mode of continuation of the object's display to the right ... + ObjectSetInteger(chartID, objName, OBJPROP_RAY_RIGHT, rayRight); + + // + // hide true or display false graphical object name in the object list ... + ObjectSetInteger(chartID, objName, OBJPROP_HIDDEN, hidden); + + // + // set the priority for receiving the event of a mouse click in the chart ... + ObjectSetInteger(chartID, objName, OBJPROP_ZORDER, zOrder); + + // + // Change Levels Of Fibonacci ... + result = FibonacciLevelsSet( + levels, + values, + colors, + styles, + widths, + descriptions, + chartID, + objName); + + // + // successful execution ... + return result; +} + +// +// Set number of levels and their parameters ... +bool FibonacciLevelsSet( + int levels, // number of level lines + double &values[], // values of level lines + color &colors[], // color of level lines + ENUM_LINE_STYLE &styles[], // style of level lines + int &widths[], // width of level lines + string &descriptions[], // level Descriptions + const long chartID = 0, // chart's ID + const string name = "Fibonacci" // object name +) +{ + // + bool result = false; + + // + // check array sizes ... + result = levels == ArraySize(colors) && + levels == ArraySize(styles) && + levels == ArraySize(widths) && + levels == ArraySize(widths); + if (!result) + { + return result; + } + + // + // Normalize Name ... + string objName = drawPrefix + "_" + name; + + // + // set the number of levels ... + ObjectSetInteger(chartID, objName, OBJPROP_LEVELS, levels); + + // + // set the properties of levels in the loop ... + for (int i = 0; i < levels; i++) + { + // + // level value ... + ObjectSetDouble(chartID, objName, OBJPROP_LEVELVALUE, i, values[i]); + + // + // level color ... + ObjectSetInteger(chartID, objName, OBJPROP_LEVELCOLOR, i, colors[i]); + + // + // level style ... + ObjectSetInteger(chartID, objName, OBJPROP_LEVELSTYLE, i, styles[i]); + + // + // level width ... + ObjectSetInteger(chartID, objName, OBJPROP_LEVELWIDTH, i, widths[i]); + + // + // level description ... + // ObjectSetString(chartID, name, OBJPROP_LEVELTEXT, i, DoubleToString(100 * values[i], 1)); + ObjectSetString(chartID, objName, OBJPROP_LEVELTEXT, i, descriptions[i]); + } + + // + // successful execution ... + return result; +} + +// +// Move Fibonacci Retracement anchor point ... +bool FibonacciPointChange( + const long chartID = 0, // chart's ID + const string name = "Fibonacci", // object name + const int pointIndex = 0, // anchor point index + datetime time = 0, // anchor point time coordinate + double price = 0 // anchor point price coordinate +) +{ + // + bool result = false; + + // + // Normalize Name ... + string objName = drawPrefix + "_" + name; + + // + // if point position is not set, move it to the current bar having Bid price ... + if (!time) + { + time = TimeCurrent(); + } + + // + if (!price) + { + price = SymbolInfoDouble(_Symbol, SYMBOL_BID); + } + + // + // move the anchor point ... + result = ObjectMove(chartID, objName, pointIndex, time, price); + + // + return result; +} + +// +// Delete Fibonacci Retracement ... +bool DeleteFibonachi( + const long chartID = 0, // chart's ID + const string name = "Fibonacci" // object name +) +{ + // + bool result = false; + + // + // Normalize Name ... + string objName = drawPrefix + "_" + name; + + // + // delete the object ... + result = ObjectDelete(chartID, objName); + + // + return result; +} + +// +// Check the values of Fibonacci Retracement anchor points and set +// default values for empty ones ... +void ChangeFibonacciEmptyPoints( + datetime &time1, + double &price1, + datetime &time2, + double &price2 // +) +{ + // + // if the second point's time is not set, it will be on the current bar ... + if (!time2) + { + time2 = TimeCurrent(); + } + + // + // if the second point's price is not set, it will have Bid value ... + if (!price2) + { + price2 = SymbolInfoDouble(_Symbol, SYMBOL_BID); + } + + // + // if the first point's time is not set, it is located 9 bars left from the second one ... + if (!time1) + { + // + // array for receiving the open time of the last 10 bars ... + datetime temp[10]; + CopyTime(Symbol(), Period(), time2, 10, temp); + + // + // set the first point 9 bars left from the second one ... + time1 = temp[0]; + } + + // + // if the first point's price is not set, move it 200 points below the second one ... + if (!price1) + { + price1 = price2 - 200 * SymbolInfoDouble(_Symbol, SYMBOL_POINT); + } +} + +// +// Event Functions ... + +// +// Create an Event ... +bool EventCreate( + const long chartID = 0, // chart's ID + const string name = "Event", // object name + const int subWindow = 0, // subwindow index + const string text = "Content", // event text + datetime time = 0, // anchor point time + const color clr = clrRed, // color + const int width = 1, // point width when highlighted + const bool back = false, // in the background + const bool selection = false, // highlight to move + const bool hidden = true, // hidden in the object list + const long zOrder = 0 // priority for mouse click +) +{ + // + bool result = false; + + // + if (!time) + { + time = TimeCurrent(); + } + + // + // Normalize Name ... + string objName = drawPrefix + "_" + name; + + // + result = ObjectCreate(chartID, objName, OBJ_EVENT, subWindow, time, 0); + if (!result) + { + return result; + } + + // + // set event text + ObjectSetString(chartID, objName, OBJPROP_TEXT, text); + + // + // set color + ObjectSetInteger(chartID, objName, OBJPROP_COLOR, clr); + + // + // set anchor point width if the object is highlighted + ObjectSetInteger(chartID, objName, OBJPROP_WIDTH, width); + + // + // display in the foreground false or background true + ObjectSetInteger(chartID, objName, OBJPROP_BACK, back); + + // + // enable true or disable false the mode of moving event by mouse + ObjectSetInteger(chartID, objName, OBJPROP_SELECTABLE, selection); + ObjectSetInteger(chartID, objName, OBJPROP_SELECTED, selection); + + // + // hide true or display false graphical object name in the object list + ObjectSetInteger(chartID, objName, OBJPROP_HIDDEN, hidden); + + // + // set the priority for receiving the event of a mouse click in the chart + ObjectSetInteger(chartID, objName, OBJPROP_ZORDER, zOrder); + + // + // successful execution + return result; +} + +// +// Change Event object text +bool EventTextChange( + const long chartID = 0, // chart's ID + const string name = "Event", // event name + const string text = "Content" // text +) +{ + // + bool result = false; + + // + // Normalize Name ... + string objName = drawPrefix + "_" + name; + + // + // change object text + result = ObjectSetString(chartID, objName, OBJPROP_TEXT, text); + + // + return result; +} + +// +// Move Event object +bool EventMove( + const long chartID = 0, // chart's ID + const string name = "Event", // event name + datetime time = 0 // time +) +{ + // + bool result = false; + + // + // Normalize Name ... + string objName = drawPrefix + "_" + name; + + // + // if time is not set, move event to the last bar + if (!time) + { + time = TimeCurrent(); + } + + // + // move the object + result = ObjectMove(chartID, objName, 0, time, 0); + + // + return result; +} + +// +// Delete Event object +bool EventDelete( + const long chartID = 0, // chart's ID + const string name = "Event" // event name +) +{ + // + bool result = false; + + // + // Normalize Name ... + string objName = drawPrefix + "_" + name; + + // + // delete the object + result = ObjectDelete(chartID, objName); + + // + return result; +} + +// +// Button Functions ... + +// +// Create the button ... +bool ButtonCreate( + const long chartID = 0, // chart's ID + const string name = "Button", // button name + const int subWindow = 0, // subwindow index + const int x = 0, // X coordinate + const int y = 0, // Y coordinate + const int width = 50, // button width + const int height = 15, // button height + const ENUM_BASE_CORNER corner = CORNER_LEFT_UPPER, // chart corner for anchoring + const string text = "Button", // text + const string font = "Arial", // font + const int fontSize = 8, // font size + const color clr = clrBlack, // text color + const color bgColor = clrLightGray, // background color + const color borderColor = clrNONE, // border color + const bool state = false, // pressed/released + const bool back = false, // in the background + const bool selection = false, // highlight to move + const bool hidden = true, // hidden in the object list + const long zOrder = 0 // priority for mouse click +) +{ + // + bool result = false; + + // + // Normalize Name ... + string objName = drawPrefix + "_" + name; + + // + // create the button + result = ObjectCreate(chartID, objName, OBJ_BUTTON, subWindow, 0, 0); + if (!result) + { + return result; + } + + // + // set button coordinates + ObjectSetInteger(chartID, objName, OBJPROP_XDISTANCE, x); + ObjectSetInteger(chartID, objName, OBJPROP_YDISTANCE, y); + + // + // set button size + ObjectSetInteger(chartID, objName, OBJPROP_XSIZE, width); + ObjectSetInteger(chartID, objName, OBJPROP_YSIZE, height); + + // + // set the chart's corner, relative to which point coordinates are defined + ObjectSetInteger(chartID, objName, OBJPROP_CORNER, corner); + + // + // set the text + ObjectSetString(chartID, objName, OBJPROP_TEXT, text); + + // + // set text font + ObjectSetString(chartID, objName, OBJPROP_FONT, font); + + // + // set font size + ObjectSetInteger(chartID, objName, OBJPROP_FONTSIZE, fontSize); + + // + // set text color + ObjectSetInteger(chartID, objName, OBJPROP_COLOR, clr); + + // + // set background color + ObjectSetInteger(chartID, objName, OBJPROP_BGCOLOR, bgColor); + + // + // set border color + ObjectSetInteger(chartID, objName, OBJPROP_BORDER_COLOR, borderColor); + + // + // display in the foreground false or background true + ObjectSetInteger(chartID, objName, OBJPROP_BACK, back); + + // + // set button state + ObjectSetInteger(chartID, objName, OBJPROP_STATE, state); + + // + // enable true or disable false the mode of moving the button by mouse + ObjectSetInteger(chartID, objName, OBJPROP_SELECTABLE, selection); + ObjectSetInteger(chartID, objName, OBJPROP_SELECTED, selection); + + // + // hide true or display false graphical object name in the object list + ObjectSetInteger(chartID, objName, OBJPROP_HIDDEN, hidden); + + // + // set the priority for receiving the event of a mouse click in the chart + ObjectSetInteger(chartID, objName, OBJPROP_ZORDER, zOrder); + + // + return result; +} + +// +// Move the button ... +bool ButtonMove( + const long chartID = 0, // chart's ID + const string name = "Button", // button name + const int x = 0, // X coordinate + const int y = 0 // Y coordinate +) +{ + // + bool result = false; + + // + // move the button + + // + // Normalize Name ... + string objName = drawPrefix + "_" + name; + + // + result = ObjectSetInteger(chartID, objName, OBJPROP_XDISTANCE, x); + if (!result) + { + return result; + } + + // + result = ObjectSetInteger(chartID, objName, OBJPROP_YDISTANCE, y); + + // + return result; +} + +// +// Change button size ... +bool ButtonChangeSize( + const long chartID = 0, // chart's ID + const string name = "Button", // button name + const int width = 50, // button width + const int height = 18 // button height +) +{ + // + bool result = false; + + // + // change the button size + + // + // Normalize Name ... + string objName = drawPrefix + "_" + name; + + // + result = ObjectSetInteger(chartID, objName, OBJPROP_XSIZE, width); + if (!result) + { + return result; + } + + // + result = ObjectSetInteger(chartID, objName, OBJPROP_YSIZE, height); + + // + return result; +} + +// +// Change corner of the chart for binding the button ... +bool ButtonChangeCorner( + const long chartID = 0, // chart's ID + const string name = "Button", // button name + const ENUM_BASE_CORNER corner = CORNER_LEFT_UPPER // chart corner for anchoring +) +{ + // + bool result = false; + + // + // Normalize Name ... + string objName = drawPrefix + "_" + name; + + // + // change anchor corner + result = ObjectSetInteger(chartID, objName, OBJPROP_CORNER, corner); + + // + return result; +} + +// +// Change button text ... +bool ButtonTextChange( + const long chartID = 0, // chart's ID + const string name = "Button", // button name + const string text = "Text" // text +) +{ + // + bool result = false; + + // + // Normalize Name ... + string objName = drawPrefix + "_" + name; + + // + // change object text + result = ObjectSetString(chartID, objName, OBJPROP_TEXT, text); + + // + return result; +} + +// +// Delete the button ... +bool ButtonDelete( + const long chartID = 0, // chart's ID + const string name = "Button" // button name +) +{ + // + bool result = false; + + // + // Normalize Name ... + string objName = drawPrefix + "_" + name; + + // + // delete the button + result = ObjectDelete(chartID, objName); + + // + return result; +} + +// +// Chart Style Drawers ... + +// +// Apply Styles On Chart ... +void ApplyChartStyle( + long mChartId = -1, // chart's ID + ENUM_CHART_MODE mMode = CHART_CANDLES, // chart's mMode + bool mShowBidLine = true, // show bid line + bool mShowAskLine = true, // show ask line + bool mShowGrid = false, // show grids on chart + bool mShowVolumes = false, // show volumes + bool mShowTradeLevels = true, // Displaying trade levels in the chart (levels of open positions, Stop Loss, Take Profit and pending orders) + bool mAutoScroll = true, // chart autoscroll + bool mQuickNavigation = true, // chart quick navigation state + color mForeGroundColor = clrWhite, // chart's foreground color + color mBackGroundColor = clrBlack, // chart's background color + color mUpColor = clrGreen, // Up Color + color mDownColor = clrRed, // Down Color + color mBullishColor = clrGreen, // Bullish color + color mBearishColor = clrRed, // Bearish color + color mGridColor = clrGray, // grid color + color mBidLineColor = clrGray, // bid line color + color mAskLineColor = clrRed, // ask line color + color mLineColor = clrLime, // line mMode and doji candlestick color + color mStopColor = clrGold, // Color of stop order levels (Stop Loss and Take Profit) + color mVolumesColor = clrGreen // volumes color +) +{ + // + // Validate Args ... + if (mChartId == -1) + { + mChartId = 0; + } + + // + ChartSetInteger(mChartId, CHART_MODE, mMode); + ChartSetInteger(mChartId, CHART_SHOW_BID_LINE, mShowBidLine); + ChartSetInteger(mChartId, CHART_SHOW_ASK_LINE, mShowAskLine); + ChartSetInteger(mChartId, CHART_SHOW_GRID, mShowGrid); + ChartSetInteger(mChartId, CHART_SHOW_VOLUMES, mShowVolumes); + ChartSetInteger(mChartId, CHART_SHOW_TRADE_LEVELS, mShowTradeLevels); + ChartSetInteger(mChartId, CHART_AUTOSCROLL, mAutoScroll); + ChartSetInteger(mChartId, CHART_QUICK_NAVIGATION, mQuickNavigation); + ChartSetInteger(mChartId, CHART_COLOR_FOREGROUND, mForeGroundColor); + ChartSetInteger(mChartId, CHART_COLOR_BACKGROUND, mBackGroundColor); + ChartSetInteger(mChartId, CHART_COLOR_CHART_UP, mUpColor); + ChartSetInteger(mChartId, CHART_COLOR_CHART_DOWN, mDownColor); + ChartSetInteger(mChartId, CHART_COLOR_CANDLE_BULL, mBullishColor); + ChartSetInteger(mChartId, CHART_COLOR_CANDLE_BEAR, mBearishColor); + ChartSetInteger(mChartId, CHART_COLOR_GRID, mGridColor); + ChartSetInteger(mChartId, CHART_COLOR_BID, mBidLineColor); + ChartSetInteger(mChartId, CHART_COLOR_ASK, mAskLineColor); + ChartSetInteger(mChartId, CHART_COLOR_STOP_LEVEL, mStopColor); + ChartSetInteger(mChartId, CHART_COLOR_CHART_LINE, mLineColor); + ChartSetInteger(mChartId, CHART_COLOR_VOLUME, mVolumesColor); +} + +// +// Tools ... + +// +// Retrieve Chart Size ... +bool GetChartSize( + XSize &result, // Holds Result ... + long chartID = 0 // Specified Chart ID ... +) +{ + // + bool mResult = false; + + // + mResult = ChartGetInteger(0, CHART_WIDTH_IN_PIXELS, 0, result.width); + if (!mResult) + { + return mResult; + } + + // + mResult = ChartGetInteger(0, CHART_HEIGHT_IN_PIXELS, 0, result.height); + + // + return mResult; +} diff --git a/Libraries/x-saherelm.x-poi.lib.mq5 b/Libraries/x-saherelm.x-poi.lib.mq5 index 284c47d0..258b30eb 100644 --- a/Libraries/x-saherelm.x-poi.lib.mq5 +++ b/Libraries/x-saherelm.x-poi.lib.mq5 @@ -125,7 +125,7 @@ enum ENUM_XSESSION // // Base POI Model Class ... -class XCBasePOI : public XSCBase +class XCBasePOI : public XCBase { // public: @@ -300,11 +300,7 @@ class XCZone : public XCBasePOI // Overrides ... // - protected: - // - // Props ... - double mUpper; // Zone Upper ... - double mLower; // Zone Lower ... + // Validators ... /** * Validate Upper and Lower of Zone ... @@ -339,6 +335,13 @@ class XCZone : public XCBasePOI return IsSpecifiedValid(From()); } + // + protected: + // + // Props ... + double mUpper; // Zone Upper ... + double mLower; // Zone Lower ... + // private: // @@ -1041,6 +1044,35 @@ class XCSwing : public XCBasePOI // // Getter(s) / Setter(s) ... + /** + * Fill Swing Bar as XOHCLstruct ... + * + * @param bar: XOHCL instance ... + * + * @return ( bool ) + */ + bool FillBar( + XOHCL &bar // + ) + { + // + bool result = false; + + // + result = IsValid(); + if (!result) + { + return result; + } + + // + bar = mBar; + result = mBar.IsValid(); + + // + return result; + } + /** * Check Swing High or not ... * @@ -1129,10 +1161,16 @@ class XCSwing : public XCBasePOI // string hash = ToMD5(mBar.GetTag()); + // + string subType = IsSwingHigh() + ? "High" + : "Low"; + // result = // TypeAsString() + mSep + + subType + mSep + ToString(mBar.period) + mSep + hash // @@ -2130,18 +2168,154 @@ class XCFVG : public XCTwoBarZone }; // -// TODO: Implement this ... +// Trading Day ... class XCDay : public XCFromToZone { + // + public: + // + + // + // Constructor ... + void XCDay() + { + } + + // + // Deconstructor ... + void ~XCDay() + { + } + + // + // Tools ... + + /** + * Initialize POI ... + * + * @return ( bool ) + */ + bool Init() + { + // + bool result = false; + + // + result = IsValid(); + + // + return result; + } + + // + // Getter(s) / Setter(s) ... + + // + // Overrides ... + + // + protected: + // + + // + private: + // + + // }; // -// TODO: Implement this ... +// Trading Session ... class XCSession : public XCFromToZone { + // + public: + // + + // + // Constructor ... + void XCSession() + { + } + + // + // Deconstructor ... + void ~XCSession() + { + } + + // + // Tools ... + + /** + * Initialize POI ... + * + * @return ( bool ) + */ + bool Init() + { + // + bool result = false; + + // + result = IsValid(); + + // + return result; + } + + // + // Getter(s) / Setter(s) ... + + // + // Overrides ... + + // + protected: + // + + // + private: + // + + // }; // +// +// Model Exists Founded POIs ... +struct XPOIState +{ + // + string symbol; + ENUM_TIMEFRAMES period; + datetime reportedAt; + + // + + // + // Constructor ... + void XPOIState() + { + Clean(); + } + + // + // Actions ... + + /** + * Cleanup all props ... + */ + void Clean() + { + // + symbol = NULL; + period = NULL; + reportedAt = NULL; + } + + // +}; // // Extensions ... diff --git a/Libraries/x-saherelm.xtrade.lib.mq5 b/Libraries/x-saherelm.x-trade.lib.mq5 similarity index 93% rename from Libraries/x-saherelm.xtrade.lib.mq5 rename to Libraries/x-saherelm.x-trade.lib.mq5 index 19ff8804..489b8877 100644 --- a/Libraries/x-saherelm.xtrade.lib.mq5 +++ b/Libraries/x-saherelm.x-trade.lib.mq5 @@ -22,7 +22,6 @@ // // Imports ... #include "../Libraries/x-saherelm.common.lib.mq5" -#include "../Libraries/x-saherelm.draw.lib.mq5" #include // @@ -1463,162 +1462,6 @@ struct XSignal return result; } - // - // Draw Signal on Chart ... - bool Draw( - long chartID, - int subWindow = 0, - string prefix = NULL, - color entryColor = clrGold, - color bullishColor = clrSpringGreen, - color bearishColor = clrTomato // - ) - { - // - bool result = false; - - // - result = IsValid(); - if (!result) - { - return result; - } - - // - bool isLong = IsLong(this.type); - - // - prefix = - // - (!IsValid(prefix) ? "" : prefix) + - this.symbol + "_" + - ToString(this.period) + "_" + - this.provider - // - ; - - // - int age = this.GetAge(); - - // - // Retrieve Time ... - datetime time0 = iTime( - this.symbol, - this.period, - age // - ); - - // - // Retrieve 3 Time ... - datetime time3 = iTime( - this.symbol, - this.period, - age + 3 // - ); - - // - color posColor = isLong - ? bullishColor - : bearishColor; - color tpColor = bullishColor; - color slColor = bearishColor; - - // - ENUM_LINE_STYLE vLineStyle = STYLE_DOT; - ENUM_LINE_STYLE tpLineStyle = STYLE_SOLID; - ENUM_LINE_STYLE slLineStyle = STYLE_SOLID; - ENUM_LINE_STYLE entryLineStyle = STYLE_SOLID; - - // - int lineWidth = 2; - - // - // Vertical Line ... - string vlName = prefix + "_" + (string)time; - - // - result = DrawVerticalLine( - chartID, - vlName, - subWindow, - time0, - posColor, - vLineStyle, - lineWidth // - ); - if (!result) - { - return result; - } - - // - // TP ... - double profit = (MathAbs(this.tp - this.entry)) * this.volume; - string tpName = prefix + "_TP_" + (string)profit; - - // - result = DrawTrendLine( - chartID, - tpName, - subWindow, - time3, - this.tp, - time0, - this.tp, - tpColor, - tpLineStyle, - lineWidth // - ); - if (!result) - { - return result; - } - - // - // SL ... - double lost = (MathAbs(this.sl - this.entry)) * this.volume; - string slName = prefix + "_SL_" + (string)lost; - - // - result = DrawTrendLine( - chartID, - slName, - subWindow, - time3, - this.sl, - time0, - this.sl, - slColor, - slLineStyle, - lineWidth // - ); - if (!result) - { - return result; - } - - // - // ENTRY ... - string entryName = prefix + "_ENTRY_" + (string)lost; - - // - result = DrawTrendLine( - chartID, - entryName, - subWindow, - time3, - this.entry, - time, - this.entry, - entryColor, - entryLineStyle, - lineWidth // - ); - - // - return result; - } - // string GetTag() { @@ -5866,223 +5709,4 @@ int ExtractSymbolPositions( return result; } -// -// Custom Drawings ... -bool DrawTrendState( - long chartId, - string _prefix, - XOHCL &_bar, - double &support, - double &resistance, - int shoulders = 10, - int subWindow = 0, - color resistanceColor = clrRed, - color supportColor = clrGreen, - color swingHighColor = clrAqua, - color swingLowColor = clrMagenta // -) -{ - // - bool result = false; - - // - result = - // - IsValid(_prefix) && - _bar.IsValid() - // - ; - if (!result) - { - return result; - } - - // - // Find Low Swings ... - - // - int firstSwingLowIndex = FindSwing( - _bar.symbol, - _bar.period, - X_SWING_LOW, - shoulders, - _bar.Index() + 1 // - ); - XOHCL firstSwingLowBar; - result = firstSwingLowBar.Init( - _bar.symbol, - _bar.period, - firstSwingLowIndex // - ); - if (!result) - { - return result; - } - - // - int secondSwingLowIndex = FindSwing( - _bar.symbol, - _bar.period, - X_SWING_LOW, - shoulders, - firstSwingLowIndex + 1 // - ); - XOHCL secondSwingLowBar; - result = secondSwingLowBar.Init( - _bar.symbol, - _bar.period, - secondSwingLowIndex // - ); - if (!result) - { - return result; - } - - // - support = secondSwingLowBar.low; - - // - string lowSwingTrendLineName = _prefix + "_Low_Swing_Trend"; - - // - result = DrawTrendLine( - chartId, - lowSwingTrendLineName, - subWindow, - secondSwingLowBar.time, - secondSwingLowBar.low, - firstSwingLowBar.time, - firstSwingLowBar.low, - swingLowColor, - STYLE_SOLID, - 2, - false, - false, - true // Ray Right ... - ); - if (!result) - { - return result; - } - - // - string lowSwingSupportLineName = _prefix + "_Low_Swing_Support"; - - // - result = DrawTrendLine( - chartId, - lowSwingSupportLineName, - subWindow, - secondSwingLowBar.time, - secondSwingLowBar.low, - firstSwingLowBar.time, - secondSwingLowBar.low, - supportColor, - STYLE_SOLID, - 2, - false, - false, - true // Ray Right ... - ); - if (!result) - { - return result; - } - - // - // Find High Swings ... - - // - int firstSwingHighIndex = FindSwing( - _bar.symbol, - _bar.period, - X_SWING_HIGH, - shoulders, - _bar.Index() + 1 // - ); - XOHCL firstSwingHighBar; - result = firstSwingHighBar.Init( - _bar.symbol, - _bar.period, - firstSwingHighIndex // - ); - if (!result) - { - return result; - } - - // - int secondSwingHighIndex = FindSwing( - _bar.symbol, - _bar.period, - X_SWING_HIGH, - shoulders, - firstSwingHighIndex + 1 // - ); - XOHCL secondSwingHighBar; - result = secondSwingHighBar.Init( - _bar.symbol, - _bar.period, - secondSwingHighIndex // - ); - if (!result) - { - return result; - } - - // - resistance = secondSwingHighBar.high; - - // - string highSwingTrendLineName = _prefix + "_High_Swing_Trend"; - - // - result = DrawTrendLine( - chartId, - highSwingTrendLineName, - subWindow, - secondSwingHighBar.time, - secondSwingHighBar.high, - firstSwingHighBar.time, - firstSwingHighBar.high, - swingHighColor, - STYLE_SOLID, - 2, - false, - false, - true // Ray Right ... - ); - if (!result) - { - return result; - } - - // - string highSwingResistanceLineName = _prefix + "_High_Swing_Resistance"; - - // - result = DrawTrendLine( - chartId, - highSwingResistanceLineName, - subWindow, - secondSwingHighBar.time, - secondSwingHighBar.high, - firstSwingHighBar.time, - secondSwingHighBar.high, - resistanceColor, - STYLE_SOLID, - 2, - false, - false, - true // Ray Right ... - ); - if (!result) - { - return result; - } - - // - return result; -} - // \ No newline at end of file diff --git a/X121SMCEA/Classes/x-121.smc.xtradehandler.class.mq5 b/X121SMCEA/Classes/x-121.smc.xtradehandler.class.mq5 index 0907a488..c97c8cb0 100644 --- a/X121SMCEA/Classes/x-121.smc.xtradehandler.class.mq5 +++ b/X121SMCEA/Classes/x-121.smc.xtradehandler.class.mq5 @@ -23,9 +23,8 @@ // Imports ... // -#include "../../Classes/x-saherelm.xalert.class.mq5" -#include "../../Classes/x-saherelm.xtrade.class.mq5" -#include "../Libraries/x-121.smc.lib.mq5" +#include "../../Classes/x-saherelm.x-alert.class.mq5" +#include "../../Classes/x-saherelm.x-trade.class.mq5" // // Definitions ... @@ -700,7 +699,7 @@ class X121SMCTradeCollector ) { // - mAccount = new XSCAccount(); + mAccount = new XCAccount(); // if (IsValid(_path)) @@ -868,7 +867,7 @@ class X121SMCTradeCollector string mPath; // Base Path ... // - XSCAccount *mAccount; + XCAccount *mAccount; // string GetFilePath(X121SMCTradeData &item) @@ -1085,7 +1084,7 @@ class X121SMCTradeCollector // // Trade Handler Class ... -class XC121SMCTradeHandler : public XSCBaseAlert +class XC121SMCTradeHandler : public XCBaseAlert { // // Public ... @@ -1094,7 +1093,7 @@ class XC121SMCTradeHandler : public XSCBaseAlert // // Constructor(s) ... - void XC121SMCTradeHandler(XSCTrade *trader) + void XC121SMCTradeHandler(XCTrade *trader) { // mTrader = trader; @@ -2743,7 +2742,7 @@ class XC121SMCTradeHandler : public XSCBaseAlert // Protected ... protected: // - XSCTrade *mTrader; // Instance of Trader Class + XCTrade *mTrader; // Instance of Trader Class X121SMCTradeCollector *mCollector; // Instance of Trade Collector Class // diff --git a/X121SMCEA/Experts/x-121.poi.expert.class.mq5 b/X121SMCEA/Experts/x-121.poi.expert.class.mq5 new file mode 100644 index 00000000..ffb094a2 --- /dev/null +++ b/X121SMCEA/Experts/x-121.poi.expert.class.mq5 @@ -0,0 +1,830 @@ +/////////////////////////////////////////////////////// +// +// SaherElm IT Center MQL5 Class Library +// -------------------------------------- +// Name: XC121SMCExpert +// Description: provides all based classes for use ... +// +// +// Maintainer: +// ------------ +// Hadi Khazaee Asl (hadi_khazaee_asl@yahoo.com) +// +////////////////////////////////////////////////////// +// +// Global Properties ... +#property library +#property copyright "Copyright 2023, SaherElm IT Center" +#property link "https://www.saherelm.ir" +#property version "1.00" +#property strict + +// +// Imports ... +#include "../../Classes/x-saherelm.x-expert.class.mq5" +#include "../../Classes/x-saherelm.x-poi.class.mq5" +// #include "../Classes/x-121.smc.xtradehandler.class.mq5" + +// +// Definitions ... +string XC121SMCExpertToken = "XC121SMCEA"; + +// +// Implementation ... + +class XC121SMCExpert : public XCBaseExpert +{ + // + public: + // + + // + // Signal Event Listener ... + TOnStopLoss OnPositionSLEventListener; + TOnTakeProfit OnPositionTPEventListener; + TOnPartialClose OnPositionPartialCloseEventListener; + TOnModify OnPositionModifiedEventListener; + TOnForceClose OnPositionForceCloseEventListener; + + // + // Getter(s) / Setter(s) ... + + /** + * Get Use Dynamic Volume State ... + * + * @return ( bool ) + */ + bool UseDynamicVolume() + { + return mUseDynamicVolume; + } + + /** + * Set Use Dynamic Volume State ... + * + * @param value: Boolean ... + */ + void UseDynamicVolume(bool value) + { + mUseDynamicVolume = value; + } + + /** + * Get Increase Volume Step ... + * + * @return ( double ) + */ + double DynamicVolumeStep() + { + return mDynamicVolumeStep; + } + + /** + * Set Increase Volume Step ... + * + * @param value: Double ... + */ + void DynamicVolumeStep(double value) + { + // + if (value < 0.01) + { + value = 0.01; + } + + // + mDynamicVolumeStep = value; + } + + /** + * Get Balance Factor for Generate Dynamic Volume ... + * + * @return ( double ) + */ + double DynamicVolumeBalanceFactor() + { + return mDynamicVolumeBalanceFactor; + } + + /** + * Set Balance Factor for Generate Dynamic Volume ... + * + * @param value: Double ... + */ + void DynamicVolumeBalanceFactor(double value) + { + // + if (value < 0) + { + value = 0; + } + + // + mDynamicVolumeBalanceFactor = value; + } + + /** + * Get Static Volume ... + * + * @return ( double ) + */ + double Volume() + { + return mVolume; + } + + /** + * Set Static Volume ... + * + * @param value: Double ... + */ + void Volume(double value) + { + // + if (value < 0.01) + { + value = 0.01; + } + + // + mVolume = value; + } + + // + // Actions ... + + // + // Override Actions ... + + /** + * Apply Default Configurations ... + */ + void DefaultConfigure() override + { + // + // Commons ... + Slippage(10); + TagPrefix(""); + MagicNumber(1694056); + + // + // Symbol ... + SetSymbol(_Symbol); + SetPeriod(_Period); + MultiSymbol(false); + Symbols("EURUSDb,GBPUSDb,USDJPYb,USDCHFb,DowJones30,XAUUSDb"); + + // + // Signalling ... + Disabled(false); + AllowLong(true); + AllowShort(true); + + // + string tag = GetTag(); + + // + // Alert ... + SetAlertPrefix(tag); + SetAlertLogAlerts(true); + SetAlertPushAlerts(true); + SetAlertMailAlerts(false); + SetAlertEnableAlerts(true); + SetAlertTerminalAlerts(false); + + // + // Reports ... + ReportNewDays(true); + ReportNewWeeks(false); + ReportNewHours(false); + ReportNewMonths(false); + + // + // Volume Default Configurations ... + Volume(0.01); + UseDynamicVolume(false); + DynamicVolumeStep(0.01); + DynamicVolumeBalanceFactor(200); + } + + /** + * Vaslidate Inputs ... + * + * @return ( bool ) + */ + bool ValidateInputs() override + { + // + bool result = false; + + // + string errMessage = ""; + + // + bool isCommonValid = ( + // + Slippage() > 0 && + MagicNumber() > 0 + // + ); + if (!isCommonValid) + { + // + errMessage += "common configurations error;" + "\n"; + } + + // + // Checking Volume ... + bool isVolumeValid = true; + if (UseDynamicVolume()) + { + // + isVolumeValid = + DynamicVolumeStep() > 0 && + DynamicVolumeBalanceFactor() > 0; + if (!isVolumeValid) + { + errMessage += "Dynamic Volume configurations error;" + "\n"; + } + } + isVolumeValid = isVolumeValid && + Volume() > 0; + if (!isVolumeValid) + { + errMessage += "Static Volume configurations error;" + "\n"; + } + + // + result = + // + // Common ... + isCommonValid && + // + // Volume Coniguration ... + isVolumeValid && + // + // Otere ... + true + // + ; + + // + if (!result) + { + // + // Since here Logger not Initiallized, we Use Raw Print Command ... + errMessage = " Errors: \n" + errMessage; + Alert(errMessage); + } + + // + return result; + } + + // + // Initializers and DeInitializers ... + + /** + * Initial EA Requirements ... + * + * @return ( bool ) + */ + bool InitEA() override + { + // + bool result = false; + + // + // Initialize Indicator Helpers ... + + // + string symbol = GetSymbol(); + ENUM_TIMEFRAMES period = GetPeriod(); + + // + mPOIDetector = new XCPOIDetector( + symbol, + period // + ); + mPOIDetector.Init(); + + // + // Bar Timer ... + XCTInputs ctInputs; + ctInputs.Default(); // Default Configurations ... + mCTHelper = new XCXCTHelper(); + result = mCTHelper.Init( + GetSymbol(), + GetPeriod(), + ctInputs // + ); + if (!result) + { + return result; + } + + // + // Bar Styles ... + XCCInputs ccInputs; + ccInputs.Default(); // Default Configurations ... + mCCHelper = new XCXCCHelper(); + result = mCCHelper.Init( + GetSymbol(), + GetPeriod(), + ccInputs // + ); + if (!result) + { + return result; + } + + // + // Create Trader Instance and Configure it ... + mTrader = new XCTrade( + Slippage(), + MagicNumber() // + ); + mTrader.AddOnStopLossEventHandler(OnPositionSLEventListener); + mTrader.AddOnTakeProfitEventHandler(OnPositionTPEventListener); + mTrader.AddOnModifyPositionEventHandler(OnPositionModifiedEventListener); + mTrader.AddOnForceClosePositionEventHandler(OnPositionForceCloseEventListener); + mTrader.AddOnPartialClosePositionEventHandler(OnPositionPartialCloseEventListener); + + // // + // // Initialize Trade Handler ... + // mTradeHandler = new XC121SMCTradeHandler(mTrader); + // mTradeHandler.SaveTrades(true); + // mTradeHandler.SaveSignals(true); + // mTradeHandler.SaveConditions(true); + + // // + // // Configure Alerts ... + // mTradeHandler.SetAlertPrefix(GetTag()); + // mTradeHandler.SetAlertEnableAlerts(GetAlertEnableAlerts()); + // mTradeHandler.SetAlertLogAlerts(GetAlertLogAlerts()); + // mTradeHandler.SetAlertMailAlerts(GetAlertMailAlerts()); + // mTradeHandler.SetAlertPushAlerts(GetAlertPushAlerts()); + // mTradeHandler.SetAlertTerminalAlerts(GetAlertTerminalAlerts()); + + // // + // // TODO: Make This Configurable Later ... + + // // + // mTradeHandler.DelayBarBetweenTwoSignal(3); + // mTradeHandler.MaxAllowedSLToPause(0); + // mTradeHandler.MaxAllowedSLReachedPauseDelay(HoursToSeconds(24)); + + // // + // // Configure Trade Management ... + // mTradeHandler.AllowLong(AllowLong()); + // mTradeHandler.AllowShort(AllowShort()); + // mTradeHandler.MaxAllowedLongs(0); + // mTradeHandler.MaxAllowedShorts(0); + // mTradeHandler.UseMaxAllowedTradesPerSymbol(true); + // mTradeHandler.MaxDrawdownPercentForOpenTrades(5); + + // // + // // Configure Position Protector ... + + // // + // mTradeHandler.UseForceMomentumsInProtection(true); + // mTradeHandler.DelayBarBetweenTwoSignal(2); + + // // + // // Configure Hedging ... + // mTradeHandler.AllowHedge(false); + // mTradeHandler.HedgeMinVolumeStep(0.01); + // mTradeHandler.MinimumOpenPositionsForHEHedge(2); + // mTradeHandler.HedgeHEMinProfitPerVolumeStep(0.2); + // mTradeHandler.HedgeBEMinProfitPerVolumeStep(0.06); + + // // + // // In Profit Position Protecting ... + + // // + // // Trail ... + // mTradeHandler.AllowTrail(false); + // mTradeHandler.TrailStep(15); + // mTradeHandler.TrailStartDistance(30); + // mTradeHandler.OnlyTrailUnprotected(true); + // mTradeHandler.RemoveTPAfterTrailedLevel(4); + + // // + // // Partial Close (In Profit) ... + // mTradeHandler.PartialCloseInProfitDistance(0); + // mTradeHandler.PartialCloseInProfitVolume(0); + + // // + // // In Drawdown Positions Protecting ... + + // // + // // Protect ... + // mTradeHandler.AllowProtect(false); + // mTradeHandler.ProtectionDelay(20); + // mTradeHandler.MaxAllowedProtection(0); + // mTradeHandler.UseEntryAsProtectionSL(true); + // mTradeHandler.ProtectOnConditions(true); + // mTradeHandler.AllowDirectionProtct(false); + // mTradeHandler.ProtectionStartDistance(50); + // mTradeHandler.ProtectionVolumeMultiplier(2); + + // // + // // Partial Close (In Profit) ... + // mTradeHandler.PartialCloseInDrawdownDistance(0); + // mTradeHandler.PartialCloseInDrawdownVolume(0); + + // + // Parsers ... + XSymbolParser _symbolParser; + + // + // Single Symbol ... + if (!MultiSymbol()) + { + // + // Register Strategy ... + + // + // Create Class Instance ... + // XCX121SMCBaseStrategy *iX121SMCStrategy; + // iX121SMCStrategy = new XCX121SMCTestStrategy( + // _Symbol, + // _Period // + // ); + + // // + // iX121SMCStrategy.AddXSignalEventHandler(OnSignalEventListener); + + // // + // ConfigureStrategy(iX121SMCStrategy); + // RegisterStrategy(iX121SMCStrategy); + } + // + // Multi Symbol ... + else + { + // + // Parse Symbols ... + string symbols[]; + int symbolsCount = SplitContent( + symbols, + Symbols() // + ); + result = IsValidSize(symbolsCount); + if (!result) + { + return result; + } + + // + for (int i = 0; i < symbolsCount; i++) + { + // + // Select Symbol ... + string iSymbol = symbols[i]; + + // + // Register Strategy Based On Symbol ... + + // + // Parse Symbol ... + bool isEURUSD = _symbolParser.IsEURUSD(_Symbol); + bool isGBPUSD = _symbolParser.IsGBPUSD(_Symbol); + bool isEURGBP = _symbolParser.IsEURGBP(_Symbol); + bool isUSDCHF = _symbolParser.IsUSDCHF(_Symbol); + bool isEURCHF = _symbolParser.IsEURCHF(_Symbol); + bool isUSDJPY = _symbolParser.IsUSDJPY(_Symbol); + bool isEURJPY = _symbolParser.IsEURJPY(_Symbol); + bool isUSDCAD = _symbolParser.IsUSDCAD(_Symbol); + bool isEURCAD = _symbolParser.IsEURCAD(_Symbol); + bool isAUDUSD = _symbolParser.IsAUDUSD(_Symbol); + bool isEURAUD = _symbolParser.IsEURAUD(_Symbol); + bool isNZDUSD = _symbolParser.IsNZDUSD(_Symbol); + bool isEURNZD = _symbolParser.IsEURNZD(_Symbol); + + // + // Check Symbol Can Register or not ... + bool canRegisterStrategy = true; + + // + if (canRegisterStrategy) + { + // // + // // Create Class Instance ... + // XCX121SMCBaseStrategy *iX121SMCStrategy; + // iX121SMCStrategy = new XCX121SMCTestStrategy( + // iSymbol, + // _Period // + // ); + + // // + // iX121SMCStrategy.AddXSignalEventHandler(OnSignalEventListener); + + // // + // // Register Strategy ... + // ConfigureStrategy(iX121SMCStrategy); + // RegisterStrategy(iX121SMCStrategy); + } + } + } + + // + return result; + } + + /** + * Destroy all Initialized EA Requirements ... + */ + void DestroyEA() override + { + // + delete mCTHelper; + delete mCCHelper; + // delete mTradeHandler; + + // + // Clean(mStrategies); + } + + /** + * Call all Registered Strategies On Tick ... + */ + void HandleStrategiesOnTick() override + { + // + ENUM_XPOI_EVENTS events[]; + mPOIDetector.Update(events); + + // + // int count = ArraySize(mStrategies); + // if (!IsValidSize(count)) + // { + // return; + // } + + // // + // for (int i = 0; i < count; i++) + // { + // // + // // Call Tick Handler Function ... + // mStrategies[i].HandleTick(); + // } + } + + // + // Event Handlers ... + + /** + * Calls When a Position's SL Triggered ... + * + * @param deal: XDeal instance ... + */ + void HandleOnStopLossTriggered(const XDeal &deal) override + { + // + // Finish ... + // mTradeHandler.Finish(deal); + + // + HandleReportBalance(); + } + + /** + * Calls When a Position's TP Triggered ... + * + * @param deal: XDeal instance ... + */ + void HandleOnTakeProfitTriggered(const XDeal &deal) override + { + // + // Finish ... + // mTradeHandler.Finish(deal); + + // + HandleReportBalance(); + } + + /** + * Handle Force Close a Position ... + * + * @param ticket: Position Ticket ... + * @param position: XPosition ... + * @param comment: Closing Comment ... + */ + void HandleOnPositionForceClosed( + const ulong ticket, + const XPosition &position, + const string comment // + ) override + { + // + // Finish ... + // mTradeHandler.Finish( + // ticket, + // position, + // comment // + // ); + + // + HandleReportBalance(); + } + + /** + * Reset All Paused Symbols on Each New Days ... + */ + void HandleOnNewDay() override + { + // mTradeHandler.ResumePausedSymbols(); + } + + /** + * Generate Identifier Tag ... + * + * @return ( string ) + */ + string GetTag() override + { + // + string result = NULL; + + // + string tagPrefix = TagPrefix(); + if (IsValid(tagPrefix)) + { + result = tagPrefix; + } + else + { + result = ""; + } + + // + result = + XCBaseExpertToken + result; + + // + return result; + } + + // + protected: + // + + // + // Props ... + + // + datetime mLastSignalOn; + + // + XCPOIDetector *mPOIDetector; + + // + // XC121SMCTradeHandler *mTradeHandler; // Trade Handler ... + // XCX121SMCBaseStrategy *mStrategies[]; // Registere Strategies in EA ... + + // + // Actions ... + + /** + * Apply Volume Based On Configurations on Signal ... + * + * @param signal: XSignal instance + */ + void ApplyVolumeOnSignal(XSignal &signal) + { + // + // Prepare Signal Dynamic Volume + // if Provided ... + if (UseDynamicVolume() && + DynamicVolumeStep() > 0 && + DynamicVolumeBalanceFactor() > 0) + { + // + double dVolume = mTrader.GetDynamicVolume( + signal.symbol, + DynamicVolumeBalanceFactor(), + DynamicVolumeStep() // + ); + + // + if (dVolume > 0) + { + signal.volume = dVolume; + } + else + { + signal.volume = Volume(); + } + } + else + { + signal.volume = Volume(); + } + + // + // mTradeHandler.UpdateSignal(signal); + } + + /** + * Configure Startegy ... + */ + // void ConfigureStrategy(XCX121SMCBaseStrategy *&strategy) + // { + // // + // if (strategy == NULL) + // { + // return; + // } + + // // + // // Configure Alerts ... + // strategy.SetAlertPrefix(GetTag()); + // strategy.SetAlertLogAlerts(GetAlertLogAlerts()); + // strategy.SetAlertMailAlerts(GetAlertMailAlerts()); + // strategy.SetAlertPushAlerts(GetAlertPushAlerts()); + // strategy.SetAlertEnableAlerts(GetAlertEnableAlerts()); + // strategy.SetAlertTerminalAlerts(GetAlertTerminalAlerts()); + + // // + // // Confiugre Signalling ... + + // // + // strategy.R2R(2); + // strategy.AllowLong(AllowLong()); + // strategy.AllowShort(AllowShort()); + + // // + // if (Disabled()) + // { + // strategy.Disable(); + // } + // else + // { + // strategy.Enable(); + // } + + // // + // } + + /** + * Register an Strategy in EA ... + * + * @param strategy: XCX121SMCBaseStrategy instance ... + */ + // void RegisterStrategy(XCX121SMCBaseStrategy *strategy) + // { + // // + // if (strategy == NULL) + // { + // return; + // } + + // // + // ArrayResize( + // mStrategies, + // ArraySize(mStrategies) + 1 // + // ); + + // // + // mStrategies[ArraySize(mStrategies) - 1] = strategy; + // } + + /** + * Re Configure All Registered Strategies ... + */ + // void ReConfigureAllStrategies() + // { + // // + // int count = ArraySize(mStrategies); + // if (!IsValidSize(count)) + // { + // return; + // } + + // // + // for (int i = 0; i < count; i++) + // { + // // + // ConfigureStrategy(mStrategies[i]); + // } + // } + + // + private: + // + + // + // Props ... + + // + // Volume Management ... + bool mUseDynamicVolume; // Use Dynamic Volume ... + double mDynamicVolumeStep; // Increase Volume Step ... + double mDynamicVolumeBalanceFactor; // Balance Factor for Generate Dynamic Volume ... + double mVolume; // Static Volume ... + + // +}; + +// \ No newline at end of file diff --git a/X121SMCEA/Helpers/x-saherelm.x3ma.helper.mq5 b/X121SMCEA/Helpers/x-saherelm.x3ma.helper.mq5 deleted file mode 100644 index b03ee756..00000000 --- a/X121SMCEA/Helpers/x-saherelm.x3ma.helper.mq5 +++ /dev/null @@ -1,752 +0,0 @@ -/////////////////////////////////////////////////////// -// -// SaherElm IT Center MQL5 Helper Class Library -// ---------------------------------------------- -// Name: XSCX3MAHelper -// Description: provides all Indicator -// Helper requirements ... -// -// -// Maintainer: -// ------------ -// Hadi Khazaee Asl (hadi_khazaee_asl@yahoo.com) -// -////////////////////////////////////////////////////// -// -// Global Properties ... -#property library -#property copyright "Copyright 2023, SaherElm IT Center" -#property link "https://www.saherelm.ir" -#property version "1.00" -#property strict - -// -// Imports ... -#include "../Classes/x-saherelm.xhelper.class.mq5" - -// -// Definitions ... - -// -enum ENUM_X3MA_BUFFERS -{ - // - X3MA_FAST_LINE = 0, - X3MA_MID_LINE = 1, - X3MA_SLOW_LINE = 2, -}; - -// -// Input Models ... -struct X3MAInputs -{ - // - // Props ... - - // - // Market ... - int fastLength; // Fast Length - int midLength; // Mid Length - int slowLength; // Slow Length - int shiftLength; // Shift - ENUM_MA_METHOD method; // Mode - ENUM_APPLIED_PRICE appliedTo; // Applied To - - // - // Presentation ... - - // - bool showFast; // Show Fast - bool showMid; // Show Mid - bool showSlow; // Show Slow - - // - // Constructor(s) ... - X3MAInputs() - { - // - Clean(); - } - - // - // Tools ... - - // - // Clean ... - void Clean() - { - // - fastLength = 0; - midLength = 0; - slowLength = 0; - shiftLength = 0; - method = MODE_SMA; - appliedTo = PRICE_CLOSE; - - // - showFast = false; - showMid = false; - showSlow = false; - } - - // - // Default ... - void Default() - { - // - fastLength = 50; - midLength = 100; - slowLength = 200; - shiftLength = 0; - method = MODE_SMA; - appliedTo = PRICE_CLOSE; - - // - showFast = true; - showMid = true; - showSlow = true; - } - - // - // Validate ... - bool IsValid() - { - // - bool result = false; - - // - result = - // - fastLength > 2 && - midLength > fastLength && - slowLength > midLength && - // - shiftLength >= 0 - // - ; - - // - return result; - } - - // - // Retrieve MAx Length ... - int Max() - { - // - int result = 0; - - // - result = MathMax(fastLength, midLength); - result = MathMax(result, slowLength); - - // - return result; - } -}; - -// -// Define Conditions ... -struct X3MAConditions -{ - // - // Common ... - string symbol; - ENUM_TIMEFRAMES period; - datetime time; - - // - // Buffers ... - - // - double fasts[]; - double mids[]; - double slows[]; - - // - // Conditions ... - - // - bool isFastOverMid; - bool isMidOverSlow; - - // - bool isFastUnderMid; - bool isMidUnderSlow; - - // - bool isBullishOrdered; - bool isBearishOrdered; - - // - bool isSwitchedToBullishOrdered; - bool isSwitchedToBearishOrdered; - - // - void Clean() - { - // - Clean(fasts); - Clean(mids); - Clean(slows); - - // - ArraySetAsSeries(fasts, true); - ArraySetAsSeries(mids, true); - ArraySetAsSeries(slows, true); - - // - isFastOverMid = false; - isMidOverSlow = false; - isFastUnderMid = false; - isMidUnderSlow = false; - isBullishOrdered = false; - isBearishOrdered = false; - isSwitchedToBullishOrdered = false; - isSwitchedToBearishOrdered = false; - } - - // - void GenerateScore( - double &bullishScore, - double &bearishScore // - ) - { - // - bullishScore = 0; - bearishScore = 0; - - // - // Since We have to Use this - // Only for Filtering Signals ... - // We Can Ignore Scoring ... - // or Complete this later ... - } - - // - string GenerateSummary( - bool onlyCommons = false, - bool onlyConditions = false, - bool includeScores = true, - bool ignoreFalseConditions = true, - string separator = "\n" // - ) - { - // - string result = NULL; - - // - double bullishScore = 0; - double bearishScore = 0; - GenerateScore( - bullishScore, - bearishScore // - ); - - // - string scoresStr = - // - "Scores: " + separator + - "---------------" + separator + - "Bullish: " + ToString(bullishScore) + separator + - "Bearish: " + ToString(bearishScore) + separator + - "" - // - ; - - // - string commonStr = GenerateSpecifiedCommonSummary( - this, - separator, - includeScores // - ); - - // - string conditionsStr = - // - "" - // - ; - - // - result = - // - "[" + GetTag() + "]" + separator + - (onlyConditions - ? "" - : commonStr) + - (!includeScores - ? "" - : scoresStr) + - " " + separator + - (onlyCommons - ? "" - : conditionsStr) + - "" - // - ; - - // - return result; - } - - // - string GetTag() - { - return "X3MA"; - } -}; - -// -// Class ... -class XSCX3MAHelper : public XSCBaseHelper -{ - // - // Public ... - public: - // - // Props ... - - // - // Constructors ... - XSCX3MAHelper() - : XSCBaseHelper(_Symbol, _Period) - { - } - - // - // Deconstructor ... - ~XSCX3MAHelper() - { - // - Clean(fastBuffer); - Clean(midBuffer); - Clean(slowBuffer); - } - - // - // Tools ... - bool Init( - string symbol, // Trading Symbol - ENUM_TIMEFRAMES period, // Trading Period - X3MAInputs &inputs // Inputs - ) - { - // - bool result = false; - - // - mSymbol = symbol; - mPeriod = period; - - // - result = inputs.IsValid(); - if (!result) - { - return result; - } - - // - mInputs = inputs; - - // - ArraySetAsSeries(fastBuffer, true); - ArraySetAsSeries(midBuffer, true); - ArraySetAsSeries(slowBuffer, true); - - // - mHandler = iCustom( - mSymbol, - mPeriod, - "x-saherelm.x3ma", - // - // Inputs ... - // - // Market ... - "", - mInputs.fastLength, - mInputs.midLength, - mInputs.slowLength, - mInputs.shiftLength, - mInputs.method, - mInputs.appliedTo, - // - // Presentation ... - "", - // - mInputs.showFast, - mInputs.showMid, - mInputs.showSlow - // - ); - result = mHandler != INVALID_HANDLE; - if (!result) - { - return result; - } - - // - return result; - } - - // - // Inputs ... - - // - X3MAInputs GetInputs() - { - return mInputs; - } - - // - bool SetInputs( - X3MAInputs &inputs // Configs - ) - { - // - return Init( - mSymbol, - mPeriod, - inputs - // - ); - } - - // - // Buffers ... - - // - double GetFast( - int barIndex // Bar Index - ) - { - // - if (barIndex < 0) - { - barIndex = 0; - } - - // - Calculate(); - - // - int count = ArraySize(fastBuffer); - if (barIndex >= count) - { - barIndex = count - 1; - } - - // - return fastBuffer[barIndex]; - } - - // - // Copy Required Items ... - int CopyFast( - int start, // Start - int count, // Number of Items for read - double &buffer[], // Dest Buffer - bool forceClean = true // Force To Clean buffer - ) - { - // - // Update Calculations ... - Calculate(); - - // - // Copy Items ... - return Copy( - start, - count, - fastBuffer, - buffer, - forceClean - // - ); - } - - // - double GetMid( - int barIndex // Bar Index - ) - { - // - if (barIndex < 0) - { - barIndex = 0; - } - - // - Calculate(); - - // - int count = ArraySize(midBuffer); - if (barIndex >= count) - { - barIndex = count - 1; - } - - // - return midBuffer[barIndex]; - } - - // - // Copy Required Items ... - int CopyMid( - int start, // Start - int count, // Number of Items for read - double &buffer[], // Dest Buffer - bool forceClean = true // Force To Clean buffer - ) - { - // - // Update Calculations ... - Calculate(); - - // - // Copy Items ... - return Copy( - start, - count, - midBuffer, - buffer, - forceClean - // - ); - } - - // - double GetSlow( - int barIndex // Bar Index - ) - { - // - if (barIndex < 0) - { - barIndex = 0; - } - - // - Calculate(); - - // - int count = ArraySize(slowBuffer); - if (barIndex >= count) - { - barIndex = count - 1; - } - - // - return slowBuffer[barIndex]; - } - - // - // Copy Required Items ... - int CopySlow( - int start, // Start - int count, // Number of Items for read - double &buffer[], // Dest Buffer - bool forceClean = true // Force To Clean buffer - ) - { - // - // Update Calculations ... - Calculate(); - - // - // Copy Items ... - return Copy( - start, - count, - slowBuffer, - buffer, - forceClean - // - ); - } - - // - // Conditions ... - - // - bool GetConditions( - X3MAConditions &conditions, // - int barIndex = 0, // - int loopback = 5 // - ) - { - // - bool result = true; - - // - if (loopback < 3) - { - loopback = 3; - } - - // - conditions.Clean(); - - // - conditions.symbol = mSymbol; - conditions.period = mPeriod; - conditions.time = TimeCurrent(); - - // - int zIndex = barIndex; - int cIndex = zIndex + 1; - int pIndex = cIndex + 1; - int ppIndex = pIndex + 1; - - // - // Buffers ... - - // - // Fast ... - CopyFast( - zIndex, - loopback, - conditions.fasts // - ); - - // - // Mid ... - CopyMid( - zIndex, - loopback, - conditions.mids // - ); - - // - // Slow ... - CopySlow( - zIndex, - loopback, - conditions.slows // - ); - - // - // Conditions ... - - // - bool isFastOverMid = - conditions.fasts[cIndex] > conditions.mids[cIndex]; - bool isFastOverMidPrev = - conditions.fasts[pIndex] > conditions.mids[pIndex]; - - // - bool isMidOverSlow = - conditions.mids[cIndex] > conditions.slows[cIndex]; - bool isMidOverSlowPrev = - conditions.mids[pIndex] > conditions.slows[pIndex]; - - // - bool isFastUnderMid = - conditions.fasts[cIndex] < conditions.mids[cIndex]; - bool isFastUnderMidPrev = - conditions.fasts[pIndex] < conditions.mids[pIndex]; - - // - bool isMidUnderSlow = - conditions.mids[cIndex] < conditions.slows[cIndex]; - bool isMidUnderSlowPrev = - conditions.mids[pIndex] < conditions.slows[pIndex]; - - // - bool isBullishOrdered = isFastOverMid && - isMidOverSlow; - bool isBullishOrderedPrev = isFastOverMidPrev && - isMidOverSlowPrev; - - // - bool isBearishOrdered = isFastUnderMid && - isMidUnderSlow; - bool isBearishOrderedPrev = isFastUnderMidPrev && - isMidUnderSlowPrev; - - // - bool isSwitchedToBullishOrdered = isBullishOrdered && - !isBullishOrderedPrev; - bool isSwitchedToBearishOrdered = isBearishOrdered && - !isBearishOrderedPrev; - - // - conditions.isFastOverMid = isFastOverMid; - conditions.isMidOverSlow = isMidOverSlow; - conditions.isFastUnderMid = isFastUnderMid; - conditions.isMidUnderSlow = isMidUnderSlow; - conditions.isBullishOrdered = isBullishOrdered; - conditions.isBearishOrdered = isBearishOrdered; - conditions.isSwitchedToBullishOrdered = isSwitchedToBullishOrdered; - conditions.isSwitchedToBearishOrdered = isSwitchedToBearishOrdered; - - // - return result; - } - - // - // Protected ... - protected: - // - // Private ... - private: - // - // Props ... - X3MAInputs mInputs; // Inputs ... - - // - // Buffers ... - double fastBuffer[]; - double midBuffer[]; - double slowBuffer[]; - - // - // Tools ... - - // - // Calculate Values Until Now ... - void Calculate() - { - // - int totalBars = CountBars(); - if (totalBars > 1000) - { - totalBars = 1000; - } - - // - // Fast ... - CopyBuffer( - mHandler, - X3MA_FAST_LINE, - 0, - totalBars, - fastBuffer - // - ); - - // - // Mid ... - CopyBuffer( - mHandler, - X3MA_MID_LINE, - 0, - totalBars, - midBuffer - // - ); - - // - // Slow ... - CopyBuffer( - mHandler, - X3MA_SLOW_LINE, - 0, - totalBars, - slowBuffer - // - ); - } -}; - -// \ No newline at end of file diff --git a/X121SMCEA/Helpers/x-saherelm.x3vwap.helper.mq5 b/X121SMCEA/Helpers/x-saherelm.x3vwap.helper.mq5 deleted file mode 100644 index 6e6ef327..00000000 --- a/X121SMCEA/Helpers/x-saherelm.x3vwap.helper.mq5 +++ /dev/null @@ -1,1144 +0,0 @@ -/////////////////////////////////////////////////////// -// -// SaherElm IT Center MQL5 Helper Class Library -// ---------------------------------------------- -// Name: XSCX3VWAPHelper -// Description: provides all Indicator -// Helper requirements ... -// -// -// Maintainer: -// ------------ -// Hadi Khazaee Asl (hadi_khazaee_asl@yahoo.com) -// -////////////////////////////////////////////////////// -// -// Global Properties ... -#property library -#property copyright "Copyright 2023, SaherElm IT Center" -#property link "https://www.saherelm.ir" -#property version "1.00" -#property strict - -// -// Imports ... -#include "../Classes/x-saherelm.xhelper.class.mq5" - -// -// Definitions ... - -// -enum ENUM_X3VWAP_BUFFERS -{ - // - X3VWAP_FAST_LINE = 0, - X3VWAP_FAST_STATE_LINE = 8, - X3VWAP_MID_LINE = 1, - X3VWAP_MID_STATE_LINE = 9, - X3VWAP_SLOW_LINE = 2, - X3VWAP_SLOW_STATE_LINE = 10, -}; - -// -enum ENUM_X3VWAP_STATES -{ - // - X3VWAP_STATE_BULLISH = 1, - X3VWAP_STATE_BEARISH = 2, - X3VWAP_STATE_NEUTURAL = 3, -}; - -// -// Input Models ... -struct X3VWAPInputs -{ - // - // Props ... - - // - // Market ... - int fastLength; // Fast Length - int midLength; // Mid Length - int slowLength; // Slow Length - ENUM_APPLIED_PRICE appliedTo; // Applied To - - // - // Presentation ... - - // - bool showFast; // Show Fast - bool showMid; // Show Mid - bool showSlow; // Show Slow - - // - // Constructor(s) ... - X3VWAPInputs() - { - // - Clean(); - } - - // - // Tools ... - - // - // Clean ... - void Clean() - { - // - fastLength = 0; - midLength = 0; - slowLength = 0; - appliedTo = PRICE_CLOSE; - - // - showFast = false; - showMid = false; - showSlow = false; - } - - // - // Default ... - void Default() - { - // - fastLength = 50; - midLength = 100; - slowLength = 200; - appliedTo = PRICE_CLOSE; - - // - showFast = true; - showMid = true; - showSlow = true; - } - - // - // Validate ... - bool IsValid() - { - // - bool result = false; - - // - result = - // - fastLength > 2 && - midLength > fastLength && - slowLength > midLength - // - ; - - // - return result; - } - - // - // Retrieve MAx Length ... - int Max() - { - // - int result = 0; - - // - result = MathMax(fastLength, midLength); - result = MathMax(result, slowLength); - - // - return result; - } -}; - -// -// Define Conditions ... -struct X3VWAPConditions -{ - // - // Common ... - string symbol; - ENUM_TIMEFRAMES period; - datetime time; - - // - // Buffers ... - - // - double fasts[]; - double fastStates[]; - double mids[]; - double midStates[]; - double slows[]; - double slowStates[]; - - // - // Conditions ... - - // - bool isFastBullish; - bool isFastBearish; - bool isFastNeutural; - - // - bool isMidBullish; - bool isMidBearish; - bool isMidNeutural; - - // - bool isSlowBullish; - bool isSlowBearish; - bool isSlowNeutural; - - // - bool isFastOverMid; - bool isMidOverSlow; - - // - bool isFastUnderMid; - bool isMidUnderSlow; - - // - bool isBullishState; - bool isBearishState; - bool isNeuturalState; - - // - bool isBullishOrdered; - bool isBearishOrdered; - - // - bool isSwitchedToBullishOrdered; - bool isSwitchedToBearishOrdered; - - // - bool isSwitchedToBullishState; - bool isSwitchedToBearishState; - bool isSwitchedToNeuturalState; - - // - void Clean() - { - // - Clean(fasts); - Clean(mids); - Clean(slows); - - // - Clean(fastStates); - Clean(midStates); - Clean(slowStates); - - // - ArraySetAsSeries(fasts, true); - ArraySetAsSeries(mids, true); - ArraySetAsSeries(slows, true); - - // - ArraySetAsSeries(fastStates, true); - ArraySetAsSeries(midStates, true); - ArraySetAsSeries(slowStates, true); - - // - isFastBullish = false; - isFastBearish = false; - isFastNeutural = false; - isMidBullish = false; - isMidBearish = false; - isMidNeutural = false; - isSlowBullish = false; - isSlowBearish = false; - isSlowNeutural = false; - isFastOverMid = false; - isMidOverSlow = false; - isFastUnderMid = false; - isMidUnderSlow = false; - isBullishState = false; - isBearishState = false; - isNeuturalState = false; - isBullishOrdered = false; - isBearishOrdered = false; - isSwitchedToBullishOrdered = false; - isSwitchedToBearishOrdered = false; - isSwitchedToBullishState = false; - isSwitchedToBearishState = false; - isSwitchedToNeuturalState = false; - } - - // - void GenerateScore( - double &bullishScore, - double &bearishScore // - ) - { - // - bullishScore = 0; - bearishScore = 0; - - // - // Since We have to Use this - // Only for Filtering Signals ... - // We Can Ignore Scoring ... - // or Complete this later ... - } - - // - string GenerateSummary( - bool onlyCommons = false, - bool onlyConditions = false, - bool includeScores = true, - bool ignoreFalseConditions = true, - string separator = "\n" // - ) - { - // - string result = NULL; - - // - double bullishScore = 0; - double bearishScore = 0; - GenerateScore( - bullishScore, - bearishScore // - ); - - // - string scoresStr = - // - "Scores: " + separator + - "---------------" + separator + - "Bullish: " + ToString(bullishScore) + separator + - "Bearish: " + ToString(bearishScore) + separator + - "" - // - ; - - // - string commonStr = GenerateSpecifiedCommonSummary( - this, - separator, - includeScores // - ); - - // - string conditionsStr = - // - "" - // - ; - - // - result = - // - "[" + GetTag() + "]" + separator + - (onlyConditions - ? "" - : commonStr) + - (!includeScores - ? "" - : scoresStr) + - " " + separator + - (onlyCommons - ? "" - : conditionsStr) + - "" - // - ; - - // - return result; - } - - // - string GetTag() - { - return "X3VWAP"; - } -}; - -// -// Class ... -class XSCX3VWAPHelper : public XSCBaseHelper -{ - // - // Public ... - public: - // - // Props ... - - // - // Constructors ... - XSCX3VWAPHelper() - : XSCBaseHelper(_Symbol, _Period) - { - } - - // - // Deconstructor ... - ~XSCX3VWAPHelper() - { - // - Clean(fastBuffer); - Clean(midBuffer); - Clean(slowBuffer); - } - - // - // Tools ... - bool Init( - string symbol, // Trading Symbol - ENUM_TIMEFRAMES period, // Trading Period - X3VWAPInputs &inputs // Inputs - ) - { - // - bool result = false; - - // - mSymbol = symbol; - mPeriod = period; - - // - result = inputs.IsValid(); - if (!result) - { - return result; - } - - // - mInputs = inputs; - - // - ArraySetAsSeries(fastBuffer, true); - ArraySetAsSeries(fastStateBuffer, true); - - // - ArraySetAsSeries(midBuffer, true); - ArraySetAsSeries(midStateBuffer, true); - - // - ArraySetAsSeries(slowBuffer, true); - ArraySetAsSeries(slowStateBuffer, true); - - // - mHandler = iCustom( - mSymbol, - mPeriod, - "x-saherelm.x3vwap", - // - // Inputs ... - // - // Market ... - "", - mInputs.fastLength, - mInputs.midLength, - mInputs.slowLength, - mInputs.appliedTo, - // - // Presentation ... - "", - // - mInputs.showFast, - mInputs.showMid, - mInputs.showSlow - // - ); - result = mHandler != INVALID_HANDLE; - if (!result) - { - return result; - } - - // - return result; - } - - // - // Inputs ... - - // - X3VWAPInputs GetInputs() - { - return mInputs; - } - - // - bool SetInputs( - X3VWAPInputs &inputs // Configs - ) - { - // - return Init( - mSymbol, - mPeriod, - inputs - // - ); - } - - // - // Buffers ... - - // - double GetFast( - int barIndex // Bar Index - ) - { - // - if (barIndex < 0) - { - barIndex = 0; - } - - // - Calculate(); - - // - int count = ArraySize(fastBuffer); - if (barIndex >= count) - { - barIndex = count - 1; - } - - // - return fastBuffer[barIndex]; - } - - // - // Copy Required Items ... - int CopyFast( - int start, // Start - int count, // Number of Items for read - double &buffer[], // Dest Buffer - bool forceClean = true // Force To Clean buffer - ) - { - // - // Update Calculations ... - Calculate(); - - // - // Copy Items ... - return Copy( - start, - count, - fastBuffer, - buffer, - forceClean - // - ); - } - - // - double GetFastState( - int barIndex // Bar Index - ) - { - // - if (barIndex < 0) - { - barIndex = 0; - } - - // - Calculate(); - - // - int count = ArraySize(fastStateBuffer); - if (barIndex >= count) - { - barIndex = count - 1; - } - - // - return fastStateBuffer[barIndex]; - } - - // - // Copy Required Items ... - int CopyFastState( - int start, // Start - int count, // Number of Items for read - double &buffer[], // Dest Buffer - bool forceClean = true // Force To Clean buffer - ) - { - // - // Update Calculations ... - Calculate(); - - // - // Copy Items ... - return Copy( - start, - count, - fastStateBuffer, - buffer, - forceClean - // - ); - } - - // - double GetMid( - int barIndex // Bar Index - ) - { - // - if (barIndex < 0) - { - barIndex = 0; - } - - // - Calculate(); - - // - int count = ArraySize(midBuffer); - if (barIndex >= count) - { - barIndex = count - 1; - } - - // - return midBuffer[barIndex]; - } - - // - // Copy Required Items ... - int CopyMid( - int start, // Start - int count, // Number of Items for read - double &buffer[], // Dest Buffer - bool forceClean = true // Force To Clean buffer - ) - { - // - // Update Calculations ... - Calculate(); - - // - // Copy Items ... - return Copy( - start, - count, - midBuffer, - buffer, - forceClean - // - ); - } - - // - double GetMidState( - int barIndex // Bar Index - ) - { - // - if (barIndex < 0) - { - barIndex = 0; - } - - // - Calculate(); - - // - int count = ArraySize(midStateBuffer); - if (barIndex >= count) - { - barIndex = count - 1; - } - - // - return midStateBuffer[barIndex]; - } - - // - // Copy Required Items ... - int CopyMidState( - int start, // Start - int count, // Number of Items for read - double &buffer[], // Dest Buffer - bool forceClean = true // Force To Clean buffer - ) - { - // - // Update Calculations ... - Calculate(); - - // - // Copy Items ... - return Copy( - start, - count, - midStateBuffer, - buffer, - forceClean - // - ); - } - - // - double GetSlow( - int barIndex // Bar Index - ) - { - // - if (barIndex < 0) - { - barIndex = 0; - } - - // - Calculate(); - - // - int count = ArraySize(slowBuffer); - if (barIndex >= count) - { - barIndex = count - 1; - } - - // - return slowBuffer[barIndex]; - } - - // - // Copy Required Items ... - int CopySlow( - int start, // Start - int count, // Number of Items for read - double &buffer[], // Dest Buffer - bool forceClean = true // Force To Clean buffer - ) - { - // - // Update Calculations ... - Calculate(); - - // - // Copy Items ... - return Copy( - start, - count, - slowBuffer, - buffer, - forceClean - // - ); - } - - // - double GetSlowState( - int barIndex // Bar Index - ) - { - // - if (barIndex < 0) - { - barIndex = 0; - } - - // - Calculate(); - - // - int count = ArraySize(slowStateBuffer); - if (barIndex >= count) - { - barIndex = count - 1; - } - - // - return slowStateBuffer[barIndex]; - } - - // - // Copy Required Items ... - int CopySlowState( - int start, // Start - int count, // Number of Items for read - double &buffer[], // Dest Buffer - bool forceClean = true // Force To Clean buffer - ) - { - // - // Update Calculations ... - Calculate(); - - // - // Copy Items ... - return Copy( - start, - count, - slowStateBuffer, - buffer, - forceClean - // - ); - } - - // - // Converts to State ... - ENUM_X3VWAP_STATES ToState(double value) - { - // - ENUM_X3VWAP_STATES result = - value == 1 - ? X3VWAP_STATE_BULLISH - : value == 2 - ? X3VWAP_STATE_BEARISH - : X3VWAP_STATE_NEUTURAL; - - // - return result; - } - - // - bool IsBullish(double value) - { - // - bool result = false; - - // - result = ToState(value) == X3VWAP_STATE_BULLISH; - - // - return result; - } - - // - bool IsBearish(double value) - { - // - bool result = false; - - // - result = ToState(value) == X3VWAP_STATE_BEARISH; - - // - return result; - } - - // - bool IsNeutural(double value) - { - // - bool result = false; - - // - result = ToState(value) == X3VWAP_STATE_NEUTURAL; - - // - return result; - } - - // - // Conditions ... - - // - bool GetConditions( - X3VWAPConditions &conditions, // - int barIndex = 0, // - int loopback = 5 // - ) - { - // - bool result = true; - - // - if (loopback < 3) - { - loopback = 3; - } - - // - conditions.Clean(); - - // - conditions.symbol = mSymbol; - conditions.period = mPeriod; - conditions.time = TimeCurrent(); - - // - int zIndex = barIndex; - int cIndex = zIndex + 1; - int pIndex = cIndex + 1; - int ppIndex = pIndex + 1; - - // - // Buffers ... - - // - // Fast ... - CopyFast( - zIndex, - loopback, - conditions.fasts // - ); - CopyFastState( - zIndex, - loopback, - conditions.fastStates // - ); - - // - // Mid ... - CopyMid( - zIndex, - loopback, - conditions.mids // - ); - CopyMidState( - zIndex, - loopback, - conditions.midStates // - ); - - // - // Slow ... - CopySlow( - zIndex, - loopback, - conditions.slows // - ); - CopySlowState( - zIndex, - loopback, - conditions.slowStates // - ); - - // - // Conditions ... - - // - bool isFastBullish = IsBullish(conditions.fastStates[cIndex]); - bool isFastBullishPrev = IsBullish(conditions.fastStates[pIndex]); - - // - bool isFastBearish = IsBearish(conditions.fastStates[cIndex]); - bool isFastBearishPrev = IsBearish(conditions.fastStates[pIndex]); - - // - bool isFastNeutural = IsNeutural(conditions.fastStates[cIndex]); - bool isFastNeuturalPrev = IsNeutural(conditions.fastStates[pIndex]); - - // - bool isMidBullish = IsBullish(conditions.midStates[cIndex]); - bool isMidBullishPrev = IsBullish(conditions.midStates[pIndex]); - - // - bool isMidBearish = IsBearish(conditions.midStates[cIndex]); - bool isMidBearishPrev = IsBearish(conditions.midStates[pIndex]); - - // - bool isMidNeutural = IsNeutural(conditions.midStates[cIndex]); - bool isMidNeuturalPrev = IsNeutural(conditions.midStates[pIndex]); - - // - bool isSlowBullish = IsBullish(conditions.slowStates[cIndex]); - bool isSlowBullishPrev = IsBullish(conditions.slowStates[pIndex]); - - // - bool isSlowBearish = IsBearish(conditions.slowStates[cIndex]); - bool isSlowBearishPrev = IsBearish(conditions.slowStates[pIndex]); - - // - bool isSlowNeutural = IsNeutural(conditions.slowStates[cIndex]); - bool isSlowNeuturalPrev = IsNeutural(conditions.slowStates[pIndex]); - - // - bool isFastOverMid = - conditions.fasts[cIndex] > conditions.mids[cIndex]; - bool isFastOverMidPrev = - conditions.fasts[pIndex] > conditions.mids[pIndex]; - - // - bool isMidOverSlow = - conditions.mids[cIndex] > conditions.slows[cIndex]; - bool isMidOverSlowPrev = - conditions.mids[pIndex] > conditions.slows[pIndex]; - - // - bool isFastUnderMid = - conditions.fasts[cIndex] < conditions.mids[cIndex]; - bool isFastUnderMidPrev = - conditions.fasts[pIndex] < conditions.mids[pIndex]; - - // - bool isMidUnderSlow = - conditions.mids[cIndex] < conditions.slows[cIndex]; - bool isMidUnderSlowPrev = - conditions.mids[pIndex] < conditions.slows[pIndex]; - - // - bool isBullishState = isFastBullish && - isMidBullish && - isSlowBullish; - bool isBullishStatePrev = isFastBullishPrev && - isMidBullishPrev && - isSlowBullishPrev; - - // - bool isBearishState = isFastBearish && - isMidBearish && - isSlowBearish; - bool isBearishStatePrev = isFastBearishPrev && - isMidBearishPrev && - isSlowBearishPrev; - - // - bool isNeuturalState = isFastNeutural && - isMidNeutural && - isSlowNeutural; - bool isNeuturalStatePrev = isFastNeuturalPrev && - isMidNeuturalPrev && - isSlowNeuturalPrev; - - // - bool isBullishOrdered = isFastOverMid && - isMidOverSlow; - bool isBullishOrderedPrev = isFastOverMidPrev && - isMidOverSlowPrev; - - // - bool isBearishOrdered = isFastUnderMid && - isMidUnderSlow; - bool isBearishOrderedPrev = isFastUnderMidPrev && - isMidUnderSlowPrev; - - // - bool isSwitchedToBullishOrdered = isBullishOrdered && - !isBullishOrderedPrev; - bool isSwitchedToBearishOrdered = isBearishOrdered && - !isBearishOrderedPrev; - - // - bool isSwitchedToBullishState = isBullishState && - !isBullishStatePrev; - bool isSwitchedToBearishState = isBearishState && - !isBearishStatePrev; - bool isSwitchedToNeuturalState = isNeuturalState && - !isNeuturalStatePrev; - - // - conditions.isFastBullish = isFastBullish; - conditions.isFastBearish = isFastBearish; - conditions.isFastNeutural = isFastNeutural; - conditions.isMidBullish = isMidBullish; - conditions.isMidBearish = isMidBearish; - conditions.isMidNeutural = isMidNeutural; - conditions.isSlowBullish = isSlowBullish; - conditions.isSlowBearish = isSlowBearish; - conditions.isSlowNeutural = isSlowNeutural; - conditions.isFastOverMid = isFastOverMid; - conditions.isMidOverSlow = isMidOverSlow; - conditions.isFastUnderMid = isFastUnderMid; - conditions.isMidUnderSlow = isMidUnderSlow; - conditions.isBullishState = isBullishState; - conditions.isBearishState = isBearishState; - conditions.isNeuturalState = isNeuturalState; - conditions.isBullishOrdered = isBullishOrdered; - conditions.isBearishOrdered = isBearishOrdered; - conditions.isSwitchedToBullishOrdered = isSwitchedToBullishOrdered; - conditions.isSwitchedToBearishOrdered = isSwitchedToBearishOrdered; - conditions.isSwitchedToBullishState = isSwitchedToBullishState; - conditions.isSwitchedToBearishState = isSwitchedToBearishState; - conditions.isSwitchedToNeuturalState = isSwitchedToNeuturalState; - - // - return result; - } - - // - // Protected ... - protected: - // - // Private ... - private: - // - // Props ... - X3VWAPInputs mInputs; // Inputs ... - - // - // Buffers ... - double fastBuffer[]; - double fastStateBuffer[]; - double midBuffer[]; - double midStateBuffer[]; - double slowBuffer[]; - double slowStateBuffer[]; - - // - // Tools ... - - // - // Calculate Values Until Now ... - void Calculate() - { - // - int totalBars = CountBars(); - if (totalBars > 1000) - { - totalBars = 1000; - } - - // - // Fast ... - CopyBuffer( - mHandler, - X3VWAP_FAST_LINE, - 0, - totalBars, - fastBuffer - // - ); - CopyBuffer( - mHandler, - X3VWAP_FAST_STATE_LINE, - 0, - totalBars, - fastStateBuffer - // - ); - - // - // Mid ... - CopyBuffer( - mHandler, - X3VWAP_MID_LINE, - 0, - totalBars, - midBuffer - // - ); - CopyBuffer( - mHandler, - X3VWAP_MID_STATE_LINE, - 0, - totalBars, - midStateBuffer - // - ); - - // - // Slow ... - CopyBuffer( - mHandler, - X3VWAP_SLOW_LINE, - 0, - totalBars, - slowBuffer - // - ); - CopyBuffer( - mHandler, - X3VWAP_SLOW_STATE_LINE, - 0, - totalBars, - slowStateBuffer - // - ); - } -}; - -// \ No newline at end of file diff --git a/X121SMCEA/Helpers/x-saherelm.xcc.helper.mq5 b/X121SMCEA/Helpers/x-saherelm.xcc.helper.mq5 deleted file mode 100644 index 98bec867..00000000 --- a/X121SMCEA/Helpers/x-saherelm.xcc.helper.mq5 +++ /dev/null @@ -1,245 +0,0 @@ -/////////////////////////////////////////////////////// -// -// SaherElm IT Center MQL5 Helper Class Library -// ---------------------------------------------- -// Name: XSCXCCHelper -// Description: provides all Indicator -// Helper requirements ... -// -// -// Maintainer: -// ------------ -// Hadi Khazaee Asl (hadi_khazaee_asl@yahoo.com) -// -////////////////////////////////////////////////////// -// -// Global Properties ... -#property library -#property copyright "Copyright 2023, SaherElm IT Center" -#property link "https://www.saherelm.ir" -#property version "1.00" -#property strict - -// -// Imports ... -#include "../Classes/x-saherelm.xhelper.class.mq5" - -// -// Definitions ... - -// -// Input Models ... -struct XCCInputs -{ - // - // Props ... - - // - // Chart Style ... - ENUM_CHART_MODE mode; // Mode - color upColor; // Up Color - color downColor; // Down Color - color lineColor; // Line mode and Doji candlestick Color - color bearishColor; // Bullish Color - color bullishColor; // Bearish Color - color volumesColor; // Volumes Color - - // - // Presentation ... - bool showCandles; // Show Candles - - // - // Constructor(s) ... - XCCInputs() - { - // - Clean(); - } - - // - // Tools ... - - // - // Clean ... - void Clean() - { - // - mode = CHART_CANDLES; - - // - upColor = CLR_NONE; - downColor = CLR_NONE; - lineColor = CLR_NONE; - bearishColor = CLR_NONE; - bullishColor = CLR_NONE; - volumesColor = CLR_NONE; - - // - showCandles = false; - } - - // - // Default ... - void Default() - { - // - mode = CHART_CANDLES; - - // - upColor = clrLime; - downColor = clrRed; - lineColor = clrLime; - bearishColor = clrRed; - bullishColor = clrLime; - volumesColor = clrGreen; - // - showCandles = true; - } - - // - // Validate ... - bool IsValid() - { - // - bool result = false; - - // - result = - // - true - // - ; - - // - return result; - } - - // - // Retrieve MAx Length ... - int Max() - { - // - int result = 0; - - // - result = MathMax(0, 0); - - // - return result; - } -}; - -// -// Class ... -class XSCXCCHelper : public XSCBaseHelper -{ - // - // Public ... -public: - // - // Props ... - - // - // Constructors ... - XSCXCCHelper() : XSCBaseHelper(_Symbol, _Period) - { - } - - // - // Deconstructor ... - ~XSCXCCHelper() {} - - // - // Tools ... - bool Init( - string symbol, // Trading Symbol - ENUM_TIMEFRAMES period, // Trading Period - XCCInputs &inputs // Inputs - ) - { - // - bool result = false; - - // - mSymbol = symbol; - mPeriod = period; - - // - result = inputs.IsValid(); - if (!result) - { - return result; - } - - // - mInputs = inputs; - - // - mHandler = iCustom( - mSymbol, - mPeriod, - "x-saherelm.xcc", - // - // Inputs ... - // - // Chart Style ... - "", - mInputs.mode, // Mode - mInputs.upColor, // Up Color - mInputs.downColor, // Down Color - mInputs.lineColor, // Line mode and Doji candlestick Color - mInputs.bearishColor, // Bullish Color - mInputs.bullishColor, // Bearish Color - mInputs.volumesColor, // Volumes Color - // - // Presentation ... - "", - mInputs.showCandles // Show Candles - // - ); - result = mHandler != INVALID_HANDLE; - if (!result) - { - return result; - } - - // - return result; - } - - // - // Inputs ... - - // - XCCInputs GetInputs() - { - return mInputs; - } - - // - bool SetInputs( - XCCInputs &inputs // Configs - ) - { - // - return Init( - mSymbol, - mPeriod, - inputs - // - ); - } - - // - // Protected ... -protected: - // - // Private ... -private: - // - // Props ... - XCCInputs mInputs; // Inputs ... -}; - -// -// Tools ... \ No newline at end of file diff --git a/X121SMCEA/Helpers/x-saherelm.xct.helper.mq5 b/X121SMCEA/Helpers/x-saherelm.xct.helper.mq5 deleted file mode 100644 index 315857a4..00000000 --- a/X121SMCEA/Helpers/x-saherelm.xct.helper.mq5 +++ /dev/null @@ -1,220 +0,0 @@ -/////////////////////////////////////////////////////// -// -// SaherElm IT Center MQL5 Helper Class Library -// ---------------------------------------------- -// Name: XSCXCTHelper -// Description: provides all Indicator -// Helper requirements ... -// -// -// Maintainer: -// ------------ -// Hadi Khazaee Asl (hadi_khazaee_asl@yahoo.com) -// -////////////////////////////////////////////////////// -// -// Global Properties ... -#property library -#property copyright "Copyright 2023, SaherElm IT Center" -#property link "https://www.saherelm.ir" -#property version "1.00" -#property strict - -// -// Imports ... -#include "../Classes/x-saherelm.xhelper.class.mq5" - -// -// Definitions ... - -// -// Input Models ... -struct XCTInputs -{ - // - // Props ... - - // - color clr; // Text Color - ENUM_BASE_CORNER corner; // Text Position - - // - // Presentation ... - bool showCandleTime; // Show Candle Time - - // - // Constructor(s) ... - XCTInputs() - { - // - Clean(); - } - - // - // Tools ... - - // - // Clean ... - void Clean() - { - // - clr = CLR_NONE; - corner = CORNER_RIGHT_LOWER; - - // - // Presentation ... - showCandleTime = false; - } - - // - // Default ... - void Default() - { - // - clr = clrYellow; - corner = CORNER_RIGHT_LOWER; - - // - // Presentation ... - showCandleTime = true; - } - - // - // Validate ... - bool IsValid() - { - // - bool result = false; - - // - result = - // - true - // - ; - - // - return result; - } - - // - // Retrieve MAx Length ... - int Max() - { - // - int result = 0; - - // - result = MathMax(0, 0); - - // - return result; - } -}; - -// -// Class ... -class XSCXCTHelper : public XSCBaseHelper -{ - // - // Public ... -public: - // - // Props ... - - // - // Constructors ... - XSCXCTHelper() : XSCBaseHelper(_Symbol, _Period) - { - } - - // - // Deconstructor ... - ~XSCXCTHelper() {} - - // - // Tools ... - bool Init( - string symbol, // Trading Symbol - ENUM_TIMEFRAMES period, // Trading Period - XCTInputs &inputs // Inputs - ) - { - // - bool result = false; - - // - mSymbol = symbol; - mPeriod = period; - - // - result = inputs.IsValid(); - if (!result) - { - return result; - } - - // - mInputs = inputs; - - // - mHandler = iCustom( - mSymbol, - mPeriod, - "x-saherelm.xct", - // - // Inputs ... - mInputs.clr, // Text Color - mInputs.corner, // Text Position - // - // Presentation ... - "", - mInputs.showCandleTime // Show Candle Time - // - ); - result = mHandler != INVALID_HANDLE; - if (!result) - { - return result; - } - - // - return result; - } - - // - // Inputs ... - - // - XCTInputs GetInputs() - { - return mInputs; - } - - // - bool SetInputs( - XCTInputs &inputs // Configs - ) - { - // - return Init( - mSymbol, - mPeriod, - inputs - // - ); - } - - // - // Protected ... -protected: - // - // Private ... -private: - // - // Props ... - XCTInputs mInputs; // Inputs ... -}; - -// -// Tools ... \ No newline at end of file diff --git a/X121SMCEA/Indicators/x-saherelm.x3ma.mq5 b/X121SMCEA/Indicators/x-saherelm.x3ma.mq5 deleted file mode 100644 index 399a9c3c..00000000 --- a/X121SMCEA/Indicators/x-saherelm.x3ma.mq5 +++ /dev/null @@ -1,394 +0,0 @@ -/////////////////////////////////////////////////////// -// SaherElm IT Center MQL5 Indicator -// ------------------------------------------- -// Name: X3MA -// Description: X3MA Trend Detector ... -// -// 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 X3MA Indicator" -#property strict - -// -#define ShortName "X3MA" - -// -// Includes Common Library ... -#include "../Libraries/x-saherelm.common.lib.mq5" - -// -// Inputs ... - -// -// Market ... -input group "Market"; -input int fastLength = 50; // Fast Length -input int midLength = 100; // Mid Length -input int slowLength = 200; // Slow Length -input int shiftLength = 0; // Shift -input ENUM_MA_METHOD method = MODE_SMA; // Mode -input ENUM_APPLIED_PRICE appliedTo = PRICE_CLOSE; // Applied To - -// -// Presentation ... -input group "Presentation"; - -// -// Parts ... -input bool showFast = true; // Show Fast -input bool showMid = true; // Show Mid -input bool showSlow = true; // Show Slow - -// -// Buffers ... - -// -#property indicator_chart_window - -// -#property indicator_buffers 3 -#property indicator_plots 3 - -// -// Current ... - -// -// Fast ... -#define fastBufferIndex 0 -double fastBuffer[]; - -// -#property indicator_label1 "X3MA F" -#property indicator_type1 DRAW_LINE -#property indicator_color1 clrAqua -#property indicator_style1 STYLE_DOT -#property indicator_width1 1 - -// -// Mid ... -#define midBufferIndex 1 -double midBuffer[]; - -// -#property indicator_label2 "X3MA M" -#property indicator_type2 DRAW_LINE -#property indicator_color2 clrOrange -#property indicator_style2 STYLE_DOT -#property indicator_width2 1 - -// -// Slow ... -#define slowBufferIndex 2 -double slowBuffer[]; - -// -#property indicator_label3 "X3MA S" -#property indicator_type3 DRAW_LINE -#property indicator_color3 clrMagenta -#property indicator_style3 STYLE_DOT -#property indicator_width3 1 - -// -// Variables ... - -// -int maxLength; - -// -// Handlers ... -int fastHandler = INVALID_HANDLE; -int midHandler = INVALID_HANDLE; -int slowHandler = INVALID_HANDLE; - -// -// EVENT Handlers ... - -// -// Initialization ... -int OnInit() -{ - // - // Validate Inputs ... - if (!ValidateInputs()) - { - return INIT_PARAMETERS_INCORRECT; - } - - // - if (!InitHandlers()) - { - return INIT_PARAMETERS_INCORRECT; - } - - // - // because in some cases we may have more than one input for - // calculation and we must prevent any calculation - // untill we pass the biggest input length, here we get max Input length - // and then wait until pass it ... - maxLength = ExtractMaxLengthOfInputs(); - - // - // Define Index Buffers ... - DefineBuffers(); - - // - // Set Indicator ShortName ... - SetIndicatorName(); - - // - // 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 - - // - // Release Handlers ... - IndicatorRelease(fastHandler); - IndicatorRelease(midHandler); - IndicatorRelease(slowHandler); -} - -// -// Calculating what we want ... -int OnCalculate( - const int rates_total, // Total Bars on Chart ... - const int prev_calculated, // Total Calculated Bars on Charts ... - const datetime &time[], // History of Open Time ... - const double &open[], // History of Open Price ... - const double &high[], // History of High Price ... - const double &low[], // History of Low Price ... - const double &close[], // History of Close Price ... - const long &tick_volume[], // History of Tick Volumes on Bar ... - const long &volume[], // History of Trade Volumes ... - const int &spread[] // History of Spread Price ... -) -{ - // - ArraySetAsSeries(low, true); - ArraySetAsSeries(open, true); - ArraySetAsSeries(high, true); - ArraySetAsSeries(close, true); - - // - // this counts Available Bars ... - int limit; - - // - // Validate Calculated Bars ... - bool isPassedRequiredCalculatedBars = - // - BarsCalculated(fastHandler) >= maxLength && - BarsCalculated(midHandler) >= maxLength && - BarsCalculated(slowHandler) >= maxLength - // - ; - if (!isPassedRequiredCalculatedBars) - { - return prev_calculated; - } - - // - limit = - (prev_calculated > rates_total || prev_calculated <= 0) - ? rates_total - : (rates_total - prev_calculated) + 1; - - // - // Buffers Copy ... - - // - int copiedFasts = CopyBuffer(fastHandler, 0, 0, limit, fastBuffer); - int copiedMids = CopyBuffer(midHandler, 0, 0, limit, midBuffer); - int copiedSlows = CopyBuffer(slowHandler, 0, 0, limit, slowBuffer); - - // - // Validate Copied Items ... - bool isPassedRequiredCopiedItems = - // - copiedFasts > 0 && - copiedMids > 0 && - copiedSlows > 0 - // - ; - if (!isPassedRequiredCopiedItems) - { - return prev_calculated; - } - - // - // Main Loop ... - for (int i = limit - 1; i >= 0 && !IsStopped(); i--) - { - // - } - - // - return rates_total; -} - -// -// CUSTOM Functions ... - -// -// Validate Input Args for Initialization ... -bool ValidateInputs() -{ - // - bool result = - // - fastLength > 2 && - midLength > fastLength && - slowLength > midLength && - // - shiftLength >= 0 - // - ; - - // - return result; -} - -// -// Retrieve all Exists Input Max Length ... -// use for Start Of Drawing ... -int ExtractMaxLengthOfInputs() -{ - // - int result = 0; - - // - // Current ... - result = MathMax(fastLength, midLength); - result = MathMax(result, slowLength); - - // - return result; -} - -// -// Set Indicator Short Name and also we can define Buffers Labels ... -void SetIndicatorName() -{ - // - IndicatorSetInteger(INDICATOR_DIGITS, _Digits); - IndicatorSetString(INDICATOR_SHORTNAME, ShortName); -} - -// -// Define Indexes and Styles ... -void DefineBuffers() -{ - // - // Fast ... - bool canShowFast = showFast; - ENUM_DRAW_TYPE fastDrawType = canShowFast ? DRAW_LINE : DRAW_NONE; - ArraySetAsSeries(fastBuffer, true); - SetIndexBuffer(fastBufferIndex, fastBuffer, INDICATOR_DATA); - PlotIndexSetDouble(fastBufferIndex, PLOT_EMPTY_VALUE, 0); - PlotIndexSetInteger(fastBufferIndex, PLOT_DRAW_BEGIN, maxLength); - PlotIndexSetInteger(fastBufferIndex, PLOT_SHOW_DATA, canShowFast); - PlotIndexSetInteger(fastBufferIndex, PLOT_DRAW_TYPE, fastDrawType); - - // - // Mid ... - bool canShowMid = showMid; - ENUM_DRAW_TYPE midDrawType = canShowMid ? DRAW_LINE : DRAW_NONE; - ArraySetAsSeries(midBuffer, true); - SetIndexBuffer(midBufferIndex, midBuffer, INDICATOR_DATA); - PlotIndexSetDouble(midBufferIndex, PLOT_EMPTY_VALUE, 0); - PlotIndexSetInteger(midBufferIndex, PLOT_DRAW_BEGIN, maxLength); - PlotIndexSetInteger(midBufferIndex, PLOT_SHOW_DATA, canShowMid); - PlotIndexSetInteger(midBufferIndex, PLOT_DRAW_TYPE, midDrawType); - - // - // Slow ... - bool canShowSlow = showSlow; - ENUM_DRAW_TYPE slowDrawType = canShowSlow ? DRAW_LINE : DRAW_NONE; - ArraySetAsSeries(slowBuffer, true); - SetIndexBuffer(slowBufferIndex, slowBuffer, INDICATOR_DATA); - PlotIndexSetDouble(slowBufferIndex, PLOT_EMPTY_VALUE, 0); - PlotIndexSetInteger(slowBufferIndex, PLOT_DRAW_BEGIN, maxLength); - PlotIndexSetInteger(slowBufferIndex, PLOT_SHOW_DATA, canShowSlow); - PlotIndexSetInteger(slowBufferIndex, PLOT_DRAW_TYPE, slowDrawType); -} - -// -// Initial Indicator Handlers ... -bool InitHandlers() -{ - // - bool result = false; - - // - // Initialize Handlers ... - - // - // Fast ... - fastHandler = iMA( - _Symbol, - _Period, - fastLength, - shiftLength, - method, - appliedTo // - ); - - // - // Mid ... - midHandler = iMA( - _Symbol, - _Period, - midLength, - shiftLength, - method, - appliedTo // - ); - - // - // Slow ... - slowHandler = iMA( - _Symbol, - _Period, - slowLength, - shiftLength, - method, - appliedTo // - ); - - // - result = - // - fastHandler != INVALID_HANDLE && - midHandler != INVALID_HANDLE && - slowHandler != INVALID_HANDLE - // - ; - - // - return result; -} - -// \ No newline at end of file diff --git a/X121SMCEA/Indicators/x-saherelm.x3vwap.mq5 b/X121SMCEA/Indicators/x-saherelm.x3vwap.mq5 deleted file mode 100644 index 8265a798..00000000 --- a/X121SMCEA/Indicators/x-saherelm.x3vwap.mq5 +++ /dev/null @@ -1,564 +0,0 @@ -/////////////////////////////////////////////////////// -// SaherElm IT Center MQL5 Indicator -// ------------------------------------------- -// Name: X3VWAP -// Description: X3VWAP Trend Detector ... -// -// 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 X3VWAP Indicator" -#property strict - -// -#define ShortName "X3VWAP" - -// -// Includes Common Library ... -#include "../Libraries/x-saherelm.common.lib.mq5" - -// -// Inputs ... - -// -// Market ... -input group "Market"; -input int fastLength = 50; // Fast Length -input int midLength = 100; // Mid Length -input int slowLength = 200; // Slow Length -input ENUM_APPLIED_PRICE appliedTo = PRICE_CLOSE; // Applied To - -// -// Presentation ... -input group "Presentation"; -input bool showFast = true; // Show Fast -input bool showMid = true; // Show Mid -input bool showSlow = true; // Show Slow - -// -// Buffers ... - -// -#property indicator_chart_window - -// -#property indicator_buffers 11 -#property indicator_plots 3 - -// -#define hideColorIDX 0 -#define bullishColorIDX 1 -#define bearishColorIDX 2 -#define neuturalColorIDX 3 - -// -// Current ... - -// -// Fast ... -#define fastBufferIndex 0 -double fastBuffer[]; - -#define fastColorBufferIndex 1 -double fastColorBuffer[]; - -// -#define fastPlotBufferIndex 0 -#property indicator_label1 "X3VWAP F" -#property indicator_type1 DRAW_COLOR_LINE -#property indicator_color1 CLR_NONE, clrGreen, clrRed, clrGray -#property indicator_style1 STYLE_DOT -#property indicator_width1 1 - -// -// Mid ... -#define midBufferIndex 2 -double midBuffer[]; - -#define midColorBufferIndex 3 -double midColorBuffer[]; - -// -#define midPlotBufferIndex 1 -#property indicator_label2 "X3VWAP M" -#property indicator_type2 DRAW_COLOR_LINE -#property indicator_color2 CLR_NONE, clrGreen, clrRed, clrGray -#property indicator_style2 STYLE_DOT -#property indicator_width2 1 - -// -// Slow ... -#define slowBufferIndex 4 -double slowBuffer[]; - -#define slowColorBufferIndex 5 -double slowColorBuffer[]; - -// -#define slowPlotBufferIndex 2 -#property indicator_label3 "X3VWAP S" -#property indicator_type3 DRAW_COLOR_LINE -#property indicator_color3 CLR_NONE, clrGreen, clrRed, clrGray -#property indicator_style3 STYLE_DOT -#property indicator_width3 1 - -// -// Data Buffers ... - -// -// Volumes ... -#define volumeBufferIndex 6 -double volumeBuffer[]; - -// -// Price ... -#define priceBufferIndex 7 -double priceBuffer[]; - -// -// Fast State ... -#define fastStateBufferIndex 8 -double fastStateBuffer[]; - -// -// Mid State ... -#define midStateBufferIndex 9 -double midStateBuffer[]; - -// -// Slow State ... -#define slowStateBufferIndex 10 -double slowStateBuffer[]; - -// -// Variables ... - -// -int maxLength; - -// -// EVENT Handlers ... - -// -// Initialization ... -int OnInit() -{ - // - // Validate Inputs ... - if (!ValidateInputs()) - { - return INIT_PARAMETERS_INCORRECT; - } - - // - // because in some cases we may have more than one input for - // calculation and we must prevent any calculation - // untill we pass the biggest input length, here we get max Input length - // and then wait until pass it ... - maxLength = ExtractMaxLengthOfInputs(); - - // - // Define Index Buffers ... - DefineBuffers(); - - // - // Set Indicator ShortName ... - SetIndicatorName(); - - // - // 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 -} - -// -// Calculating what we want ... -int OnCalculate( - const int rates_total, // Total Bars on Chart ... - const int prev_calculated, // Total Calculated Bars on Charts ... - const datetime &time[], // History of Open Time ... - const double &open[], // History of Open Price ... - const double &high[], // History of High Price ... - const double &low[], // History of Low Price ... - const double &close[], // History of Close Price ... - const long &tick_volume[], // History of Tick Volumes on Bar ... - const long &volume[], // History of Trade Volumes ... - const int &spread[] // History of Spread Price ... -) -{ - // - ArraySetAsSeries(low, true); - ArraySetAsSeries(open, true); - ArraySetAsSeries(high, true); - ArraySetAsSeries(close, true); - ArraySetAsSeries(tick_volume, true); - - // - // this counts Available Bars ... - int limit; - - // - limit = - (prev_calculated > rates_total || prev_calculated <= 0) - ? rates_total - : (rates_total - prev_calculated) + 1; - - // - // Main Loop ... - for (int i = limit - 1; i >= 0 && !IsStopped(); i--) - { - // - CalculateBuffers( - i, - prev_calculated, - rates_total, - // - open, - high, - close, - low, - tick_volume // - ); - } - - // - return rates_total; -} - -// -// CUSTOM Functions ... - -// -// Validate Input Args for Initialization ... -bool ValidateInputs() -{ - // - bool result = - // - fastLength > 2 && - midLength > fastLength && - slowLength > midLength - // - ; - - // - return result; -} - -// -// Retrieve all Exists Input Max Length ... -// use for Start Of Drawing ... -int ExtractMaxLengthOfInputs() -{ - // - int result = 0; - - // - // Current ... - result = MathMax(fastLength, midLength); - result = MathMax(result, slowLength); - - // - return result; -} - -// -// Set Indicator Short Name and also we can define Buffers Labels ... -void SetIndicatorName() -{ - // - IndicatorSetInteger(INDICATOR_DIGITS, _Digits); - IndicatorSetString(INDICATOR_SHORTNAME, ShortName); -} - -// -// Define Indexes and Styles ... -void DefineBuffers() -{ - // - // Fast ... - ArraySetAsSeries(fastBuffer, true); - ArraySetAsSeries(fastColorBuffer, true); - SetIndexBuffer(fastBufferIndex, fastBuffer, INDICATOR_DATA); - SetIndexBuffer(fastColorBufferIndex, fastColorBuffer, INDICATOR_COLOR_INDEX); - - // - // Mid ... - ArraySetAsSeries(midBuffer, true); - ArraySetAsSeries(midColorBuffer, true); - SetIndexBuffer(midBufferIndex, midBuffer, INDICATOR_DATA); - SetIndexBuffer(midColorBufferIndex, midColorBuffer, INDICATOR_COLOR_INDEX); - - // - // Slow ... - ArraySetAsSeries(slowBuffer, true); - ArraySetAsSeries(slowColorBuffer, true); - SetIndexBuffer(slowBufferIndex, slowBuffer, INDICATOR_DATA); - SetIndexBuffer(slowColorBufferIndex, slowColorBuffer, INDICATOR_COLOR_INDEX); - // - // Data Buffers ... - - // - // Volumes ... - ArraySetAsSeries(volumeBuffer, true); - SetIndexBuffer(volumeBufferIndex, volumeBuffer, INDICATOR_CALCULATIONS); - - // - // Price ... - ArraySetAsSeries(priceBuffer, true); - SetIndexBuffer(priceBufferIndex, priceBuffer, INDICATOR_CALCULATIONS); - - // - // Fast State ... - ArraySetAsSeries(fastStateBuffer, true); - SetIndexBuffer(fastStateBufferIndex, fastStateBuffer, INDICATOR_CALCULATIONS); - - // - // Mid State ... - ArraySetAsSeries(midStateBuffer, true); - SetIndexBuffer(midStateBufferIndex, midStateBuffer, INDICATOR_CALCULATIONS); - - // - // Slow State ... - ArraySetAsSeries(slowStateBuffer, true); - SetIndexBuffer(slowStateBufferIndex, slowStateBuffer, INDICATOR_CALCULATIONS); -} - -// -// Calculate Buffers ... -void CalculateBuffers( - int bar_index, // Selected Bar Index - const int prevCalculated, - const int ratesTotal, - const double &open[], - const double &high[], - const double &close[], - const double &low[], - const long &tickVolume[] // -) -{ - // - // Calculate Volumes and Price ... - - // - if (ratesTotal - bar_index <= maxLength) - { - // - CalculateDataBuffers( - bar_index, - prevCalculated, - ratesTotal, - open, - high, - close, - low, - tickVolume // - ); - return; - } - - // - CalculateDataBuffers( - bar_index, - prevCalculated, - ratesTotal, - open, - high, - close, - low, - tickVolume // - ); - - // - CalculateVWAPS( - bar_index, - prevCalculated, - ratesTotal, - open, - high, - close, - low, - tickVolume // - ); -} - -// -// Calculate Required Data Buffers ... -void CalculateDataBuffers( - int bar_index, // Selected Bar Index - const int prevCalculated, - const int ratesTotal, - const double &open[], - const double &high[], - const double &close[], - const double &low[], - const long &tickVolume[] // -) -{ - // - double price = GetAppliedPrice( - appliedTo, - open, - high, - low, - close, - bar_index // - ); - priceBuffer[bar_index] = price; - volumeBuffer[bar_index] = (double)tickVolume[bar_index]; -} - -// -// Calculate Different VWaps ... -void CalculateVWAPS( - int bar_index, // Selected Bar Index - const int prevCalculated, - const int ratesTotal, - const double &open[], - const double &high[], - const double &close[], - const double &low[], - const long &tickVolume[] // -) -{ - // - // Fast ... - CalculateVWAP( - bar_index, - prevCalculated, - ratesTotal, - open, - high, - close, - low, - tickVolume, - // - fastLength, - showFast, - fastBuffer, - fastColorBuffer, - fastStateBuffer // - ); - - // - // Mid ... - CalculateVWAP( - bar_index, - prevCalculated, - ratesTotal, - open, - high, - close, - low, - tickVolume, - // - midLength, - showMid, - midBuffer, - midColorBuffer, - midStateBuffer // - ); - - // - // Fast ... - CalculateVWAP( - bar_index, - prevCalculated, - ratesTotal, - open, - high, - close, - low, - tickVolume, - // - slowLength, - showSlow, - slowBuffer, - slowColorBuffer, - slowStateBuffer // - ); -} - -// -// Calculate VWAP ... -void CalculateVWAP( - int bar_index, // Selected Bar Index - const int prevCalculated, - const int ratesTotal, - const double &open[], - const double &high[], - const double &close[], - const double &low[], - const long &tickVolume[], - // - int _length, // Calculation Length - bool _show, - double &_buffer[], - double &_colorBuffer[], - double &_stateBuffer[] // -) -{ - // - double vSum = 0; - double pSum = 0; - double mSum = 0; - for (int x = 0; x < _length; x++) - { - // - pSum += priceBuffer[x + bar_index]; - vSum += volumeBuffer[x + bar_index]; - mSum += priceBuffer[x + bar_index] * volumeBuffer[x + bar_index]; - } - - // - double iValue = mSum / vSum; - iValue = NormalizeDouble(iValue, _Digits); - - // - _buffer[bar_index] = iValue; - - // - bool isBullish = low[bar_index] > iValue; - bool isBearish = high[bar_index] < iValue; - - // - double iColor = - isBullish - ? bullishColorIDX - : isBearish - ? bearishColorIDX - : neuturalColorIDX; - - // - _colorBuffer[bar_index] = hideColorIDX; - _stateBuffer[bar_index] = iColor; - if (_show) - { - _colorBuffer[bar_index] = iColor; - } -} - -// \ No newline at end of file diff --git a/X121SMCEA/Indicators/x-saherelm.xcc.mq5 b/X121SMCEA/Indicators/x-saherelm.xcc.mq5 deleted file mode 100644 index ebc45174..00000000 --- a/X121SMCEA/Indicators/x-saherelm.xcc.mq5 +++ /dev/null @@ -1,437 +0,0 @@ -/////////////////////////////////////////////////////// -// -// SaherElm IT Center MQL5 Candle Styles -// --------------------------------------------------- -// Name: XCC -// Description: Candle Styles ... -// -// -// 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 XCC Indicator" -#property strict - -// -// START Constants ... -// - -// -// Indicator Short Name ... -#define ShortName "XCC" - -// -// Holds an SnapShot of Charts Configuration ... -struct XChartStyle -{ - // - // chart's ID ... - long chartId; - // - // chart's mode ... - ENUM_CHART_MODE mode; - // - // show bid line ... - bool showBidLine; - // - // show ask line ... - bool showAskLine; - // - // show grids on chart ... - bool showGrid; - // - // show volumes ... - bool showVolumes; - // - // Displaying trade levels in the chart (levels of open positions, Stop Loss, Take Profit and pending orders) ... - bool showTradeLevels; - // - // chart autoscroll ... - bool autoScroll; - // - // chart quick navigation state ... - bool quickNavigation; - // - // chart's foreground color ... - color foreGroundColor; - // - // chart's background color ... - color backGroundColor; - // - // Up Color ... - color upColor; - // - // Down Color ... - color downColor; - // - // Bullish color ... - color bullishColor; - // - // Bearish color ... - color bearishColor; - // - // grid color ... - color gridColor; - // - // bid line color ... - color bidLineColor; - // - // ask line color ... - color askLineColor; - // - // line mode and doji candlestick color ... - color lineColor; - // - // Color of stop order levels (Stop Loss and Take Profit) ... - color stopColor; - // - // volumes color ... - color volumesColor; -}; - -// -// END Constants ... -// - -// -// START Inputs ... -// - -// -input group "Chart Style"; -input ENUM_CHART_MODE mode = CHART_CANDLES; // Mode -input color upColor = clrLime; // Up Color -input color downColor = clrRed; // Down Color -input color lineColor = clrLime; // Line mode and Doji candlestick Color -input color bearishColor = clrRed; // Bullish Color -input color bullishColor = clrLime; // Bearish Color -input color volumesColor = clrGreen; // Volumes Color - -// -input group "Presentation"; -input bool showCandles = true; // Show Candles - -// -// END Inputs ... -// - -// -// START Includes and Imports ... -// - -// -// Includes Draw Library ... -#include "../Libraries/x-saherelm.draw.lib.mq5" - -// -// Includes Common Library ... -#include "../Libraries/x-saherelm.common.lib.mq5" - -// -// END Includes and Imports ... -// - -// -// START Buffers ... -// - -// -#property indicator_chart_window - -// -#property indicator_buffers 0 -#property indicator_plots 0 - -// -// END Buffers ... -// - -// -// START Global Definitions: Variables, Properties and etc ... -// - -// -int maxLength; - -// -XChartStyle chartStyle; -XChartStyle clearStyle; - -// -// END Global Definitions: Variables, Properties and etc ... -// - -// -// START Event Handlers ... -// - -// -// Initialization ... -int OnInit() -{ - // - // Validate Inputs ... - if (!ValidateInputs()) - { - return INIT_PARAMETERS_INCORRECT; - } - - // - drawPrefix = ShortName; - - // - // because in some cases we may have more than one input for - // calculation and we must prevent any calculation - // untill we pass the biggest input length, here we get max Input length - // and then wait until pass it ... - maxLength = ExtractMaxLengthOfInputs(); - - // - // Define Index Buffers ... - DefineBuffers(); - - // - // Set Indicator ShortName ... - SetIndicatorName(); - - // - // Apply Chart Style ... - ApplyCustomChartStyle(); - - // - // 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 -} - -// -// Calculating what we want ... -int OnCalculate( - const int rates_total, // Total Bars on Chart ... - const int prev_calculated, // Total Calculated Bars on Charts ... - const datetime &time[], // History of Open Time ... - const double &open[], // History of Open Price ... - const double &high[], // History of High Price ... - const double &low[], // History of Low Price ... - const double &close[], // History of Close Price ... - const long &tick_volume[], // History of Tick Volumes on Bar ... - const long &volume[], // History of Trade Volumes ... - const int &spread[] // History of Spread Price ... -) -{ - // - // Prepare Buffers ... - ArraySetAsSeries(time, true); - ArraySetAsSeries(open, true); - ArraySetAsSeries(high, true); - ArraySetAsSeries(low, true); - ArraySetAsSeries(close, true); - ArraySetAsSeries(tick_volume, true); - ArraySetAsSeries(volume, true); - ArraySetAsSeries(spread, true); - - // - // this counts Available Bars ... - int limit; - - // - limit = (prev_calculated > rates_total || prev_calculated <= 0) ? rates_total : (rates_total - prev_calculated) + 1; - - // - // Main Loop ... - for (int i = limit - 1; i >= 0 && !IsStopped(); i--) - { - CalculateBuffers(i); - } - - // - return rates_total; -} - -// -// END Event Handlers ... -// - -// -// START Functions ... -// - -// -// Validate Input Args for Initialization ... -bool ValidateInputs() -{ - // - bool result = true; - - // - return result; -} - -// -// Retrieve all Exists Input Max Length ... -// use for Start Of Drawing ... -int ExtractMaxLengthOfInputs() -{ - // - int result = 0; - - // - return result; -} - -// -// Define Indexes and Styles ... -void DefineBuffers() -{ -} - -// -// Set Indicator Short Name and also we can define Buffers Labels ... -void SetIndicatorName() -{ - IndicatorSetString(INDICATOR_SHORTNAME, ShortName); -} - -// -// Calculate Buffers ... -void CalculateBuffers( - int bar_index // Selected Bar Index -) -{ -} - -// -// Apply Custom Chart Style ... -void ApplyCustomChartStyle() -{ - // - // Read Current Chart Config and Store it ... - ReadChartStyle(); - - // - // After Reading Current Chart Style ... - // we have to Save Configs and Change Styles ... - clearStyle = chartStyle; - - // - clearStyle.upColor = CLR_NONE; - clearStyle.downColor = CLR_NONE; - clearStyle.lineColor = CLR_NONE; - clearStyle.bullishColor = CLR_NONE; - clearStyle.bearishColor = CLR_NONE; - - // - // Decide to Show or not Candles based on User Input ... - if (showCandles) - { - SetChartStyle(chartStyle); - } - else - { - SetChartStyle(clearStyle); - } -} - -// -// Read Previous Chart Style ... -void ReadChartStyle() -{ - // - // Retrieve Current Chart ID ... - long chartId = ChartID(); - chartStyle.chartId = chartId; - - // - // Retrieve Chart Mode ... - chartStyle.mode = (ENUM_CHART_MODE)ChartGetInteger(chartId, CHART_MODE); - - // - chartStyle.showBidLine = (bool)ChartGetInteger(chartId, CHART_SHOW_BID_LINE); - chartStyle.showAskLine = (bool)ChartGetInteger(chartId, CHART_SHOW_ASK_LINE); - chartStyle.showGrid = (bool)ChartGetInteger(chartId, CHART_SHOW_GRID); - chartStyle.showVolumes = (bool)ChartGetInteger(chartId, CHART_SHOW_VOLUMES); - chartStyle.showTradeLevels = (bool)ChartGetInteger(chartId, CHART_SHOW_TRADE_LEVELS); - chartStyle.autoScroll = (bool)ChartGetInteger(chartId, CHART_AUTOSCROLL); - chartStyle.quickNavigation = (bool)ChartGetInteger(chartId, CHART_QUICK_NAVIGATION); - - // - chartStyle.foreGroundColor = (color)ChartGetInteger(chartId, CHART_COLOR_FOREGROUND); - chartStyle.backGroundColor = (color)ChartGetInteger(chartId, CHART_COLOR_BACKGROUND); - chartStyle.upColor = (color)ChartGetInteger(chartId, CHART_COLOR_CHART_UP); - chartStyle.downColor = (color)ChartGetInteger(chartId, CHART_COLOR_CHART_DOWN); - chartStyle.bullishColor = (color)ChartGetInteger(chartId, CHART_COLOR_CANDLE_BULL); - chartStyle.bearishColor = (color)ChartGetInteger(chartId, CHART_COLOR_CANDLE_BEAR); - chartStyle.gridColor = (color)ChartGetInteger(chartId, CHART_COLOR_GRID); - chartStyle.bidLineColor = (color)ChartGetInteger(chartId, CHART_COLOR_BID); - chartStyle.askLineColor = (color)ChartGetInteger(chartId, CHART_COLOR_ASK); - chartStyle.stopColor = (color)ChartGetInteger(chartId, CHART_COLOR_STOP_LEVEL); - chartStyle.lineColor = (color)ChartGetInteger(chartId, CHART_COLOR_CHART_LINE); - chartStyle.volumesColor = (color)ChartGetInteger(chartId, CHART_COLOR_VOLUME); - - // - chartStyle.mode = mode; - chartStyle.upColor = upColor; - chartStyle.downColor = downColor; - chartStyle.lineColor = lineColor; - chartStyle.bearishColor = bearishColor; - chartStyle.bullishColor = bullishColor; - chartStyle.volumesColor = volumesColor; -} - -// -// Set Chart Style ... -void SetChartStyle( - XChartStyle &mChartStyle // Chart Style to Apply -) -{ - // - ApplyChartStyle( - mChartStyle.chartId, - mChartStyle.mode, - mChartStyle.showBidLine, - mChartStyle.showAskLine, - mChartStyle.showGrid, - mChartStyle.showVolumes, - mChartStyle.showTradeLevels, - mChartStyle.autoScroll, - mChartStyle.quickNavigation, - mChartStyle.foreGroundColor, - mChartStyle.backGroundColor, - mChartStyle.upColor, - mChartStyle.downColor, - mChartStyle.bullishColor, - mChartStyle.bearishColor, - mChartStyle.gridColor, - mChartStyle.bidLineColor, - mChartStyle.askLineColor, - mChartStyle.lineColor, - mChartStyle.stopColor, - mChartStyle.volumesColor); -} - -// -// END Functions ... -// diff --git a/X121SMCEA/Indicators/x-saherelm.xct.mq5 b/X121SMCEA/Indicators/x-saherelm.xct.mq5 deleted file mode 100644 index 92fbb28b..00000000 --- a/X121SMCEA/Indicators/x-saherelm.xct.mq5 +++ /dev/null @@ -1,270 +0,0 @@ -/////////////////////////////////////////////////////// -// -// SaherElm IT Center MQL5 Indicator -// --------------------------------------------- -// Name: XCT -// Description: Trend Magic Indicator ... -// -// -// 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 XCT Indicator" -#property strict - -// -// START Constants ... -// - -// -#define ShortName "XCT" -#include "../Libraries/x-saherelm.common.lib.mq5" - -// -// END Constants ... -// - -// -// START Inputs ... -// - -// -input color clr = clrYellow; // Text Color -input ENUM_BASE_CORNER corner = CORNER_RIGHT_LOWER; // Text Position - -// -input group "Presentation"; -input bool showCandleTime = true; // Show Candle Time - -// -// END Inputs ... -// - -// -// START Buffers ... -// - -// -#property indicator_chart_window - -// -#property indicator_buffers 0 -#property indicator_plots 0 - -// -// END Buffers ... -// - -// -// START Global Definitions: Variables, Properties and etc ... -// - -// -// END Global Definitions: Variables, Properties and etc ... -// - -// -// START Event Handlers ... -// - -// -// Initialization ... -int OnInit() -{ - // - // Validate Inputs ... - if (showCandleTime) - { - CreateIndicatorObject(); - } - else - { - ObjectDelete(0, ShortName); - } - - // - // Set Indicator ShortName ... - SetIndicatorName(); - - // - // 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 - - // - ulong chID = FindChartID( - _Symbol, - _Period - // - ); - - // - // Delete Object ... - ObjectDelete(chID, ShortName); - - // - Comment(""); -} - -// -// Calculating what we want ... -int OnCalculate( - const int rates_total, // Total Bars on Chart ... - const int prev_calculated, // Total Calculated Bars on Charts ... - const datetime &time[], // History of Open Time ... - const double &open[], // History of Open Price ... - const double &high[], // History of High Price ... - const double &low[], // History of Low Price ... - const double &close[], // History of Close Price ... - const long &tick_volume[], // History of Tick Volumes on Bar ... - const long &volume[], // History of Trade Volumes ... - const int &spread[] // History of Spread Price ... -) -{ - // - ArraySetAsSeries(time, true); - - // - if (!showCandleTime) - { - return rates_total; - } - - // - ulong chID = FindChartID( - _Symbol, - _Period - // - ); - - // - XBarRemainsTime barRemains; - barRemains.Init( - _Symbol, - _Period - // - ); - - // - string msg = barRemains - .ToString( - "", - "", - "", - "", - "", - ":", - true - // - ); - - // - long mSpread = SymbolInfoInteger(Symbol(), SYMBOL_SPREAD); - - // - string _sp = ""; - if (mSpread < 10) - _sp = ".."; - else if (mSpread < 100) - _sp = "."; - - // - // int offset = TimeGMTOffset(); - // string timeString = - // ", Time: " + string(TimeCurrent()) + "\n" + - // ", ServerTime: " + string(TimeTradeServer()) + "\n" + - // ", GMT Offset: " + (string)offset; - // timeString = timeString; - // Comment(timeString); - - // - string objText = "Spread: " + IntegerToString(mSpread) + _sp + ", Next Bar in: " + msg; - - // - ObjectSetInteger(chID, ShortName, OBJPROP_COLOR, clr); - ObjectSetString(chID, ShortName, OBJPROP_TEXT, objText); - ObjectSetInteger(chID, ShortName, OBJPROP_FONTSIZE, 10); - ObjectSetString(chID, ShortName, OBJPROP_FONT, "Courier"); - - // - return rates_total; -} - -// -// END Event Handlers ... -// - -// -// START Functions ... -// - -// -// Set Indicator Short Name and also we can define Buffers Labels ... -void SetIndicatorName() -{ - IndicatorSetString(INDICATOR_SHORTNAME, ShortName); -} - -// -void CreateIndicatorObject() -{ - // - if (!showCandleTime) - { - return; - } - - // - ObjectCreate(0, ShortName, OBJ_LABEL, 0, 0, 0); - ObjectSetInteger(0, ShortName, OBJPROP_CORNER, corner); - ObjectSetInteger(0, ShortName, OBJPROP_XDISTANCE, 10); - ObjectSetInteger(0, ShortName, OBJPROP_YDISTANCE, 2); - - // - ENUM_ANCHOR_POINT Anchor = ANCHOR_LEFT_UPPER; - switch (corner) - { - case CORNER_LEFT_UPPER: - Anchor = ANCHOR_LEFT_UPPER; - break; - case CORNER_RIGHT_UPPER: - Anchor = ANCHOR_RIGHT_UPPER; - break; - case CORNER_LEFT_LOWER: - Anchor = ANCHOR_LEFT_LOWER; - break; - case CORNER_RIGHT_LOWER: - Anchor = ANCHOR_RIGHT_LOWER; - break; - } - - // - ObjectSetInteger(0, ShortName, OBJPROP_ANCHOR, Anchor); -} - -// -// END Functions ... -// diff --git a/X121SMCEA/Libraries/x-121.smc.lib.mq5 b/X121SMCEA/Libraries/x-121.smc.lib.mq5 deleted file mode 100644 index 4c49b373..00000000 --- a/X121SMCEA/Libraries/x-121.smc.lib.mq5 +++ /dev/null @@ -1,856 +0,0 @@ -/////////////////////////////////////////////////////// -// -// SaherElm IT Center MQL5 Seriallize Library -// --------------------------------------- -// Name: X121SMCLib -// Description: All models related to X121SMC ... -// -// -// Maintainer: -// ------------ -// Hadi Khazaee Asl (hadi_khazaee_asl@yahoo.com) -// -////////////////////////////////////////////////////// -// -// Global Properties ... -#property library -#property copyright "Copyright 2023, SaherElm IT Center" -#property link "https://www.saherelm.ir" -#property version "1.00" -#property strict - -// -// Imports ... -#include "../../Classes/x-saherelm.base.class.mq5" -#include "../../Libraries/x-saherelm.common.lib.mq5" -#include "../../Libraries/x-saherelm.x-poi.lib.mq5" -#include "../../Libraries/x-saherelm.xtrade.lib.mq5" - -// -// Definitions ... - -// -// Specific Identifier(s) of XStrategy ... -string X121SMCStrategyToken = "X121SMC"; -string X121SMCOBStrategyToken = "X121SMCOB"; -string X121SMCSUPDEMStrategyToken = "X121SMCSUPDEM"; -string X121SMCConditionsToken = "X121SMCConditions"; -string X121SMCMarketStructureToken = "X121SMCMarketStructure"; - -// -// Condition Structure ... -struct X121SMCStrategyConditions -{ - // - // Props ... - - // - // Common ... - string symbol; - ENUM_TIMEFRAMES period; - datetime time; - - // - // Conditions ... - - // - XOHCL swingHigh; - XZone supplyZone; - XZone bearishFVG; - XOHCL resistance; - XZone bearishOrderBlock; - XOHCL bullishMomentumBar; - XOHCL bullishRejectionBar; - - // - XZone demandZones[]; - XZone bearishFVGs[]; - XZone bearishOrderBlocks[]; - XOHCL swingHighs[]; - XOHCL resistances[]; - XOHCL bearishMomentumBars[]; - XOHCL bearishRejectionBars[]; - - // - XOHCL support; - XOHCL swingLow; - XZone demandZone; - XZone bullishFVG; - XZone bullishOrderBlock; - XOHCL bearishMomentumBar; - XOHCL bearishRejectionBar; - - // - XZone supplyZones[]; - XZone bullishFVGs[]; - XZone bullishOrderBlocks[]; - XOHCL supports[]; - XOHCL swingLows[]; - XOHCL bullishMomentumBars[]; - XOHCL bullishRejectionBars[]; - - // - // Constructor ... - void XStrategyConditions() - { - Clean(); - } - - // - // Tools ... - - /** - * Cleanup ... - */ - void Clean() - { - // - symbol = NULL; - period = NULL; - time = NULL; - - // - CleanDemand(); - CleanSupply(); - } - - /** - * Cleanup Demand Related ... - */ - void CleanDemand() - { - // - support.Clean(); - swingLow.Clean(); - demandZone.Clean(); - bullishFVG.Clean(); - bullishOrderBlock.Clean(); - bullishMomentumBar.Clean(); - bullishRejectionBar.Clean(); - - // - Clean(supports); - Clean(swingLows); - Clean(supplyZones); - Clean(bullishFVGs); - Clean(bullishOrderBlocks); - Clean(bullishMomentumBars); - Clean(bullishRejectionBars); - } - - /** - * Cleanup Supply Related ... - */ - void CleanSupply() - { - // - swingHigh.Clean(); - supplyZone.Clean(); - bearishFVG.Clean(); - resistance.Clean(); - bearishOrderBlock.Clean(); - bearishMomentumBar.Clean(); - bearishRejectionBar.Clean(); - - // - Clean(swingHighs); - Clean(demandZones); - Clean(bearishFVGs); - Clean(resistances); - Clean(bearishOrderBlocks); - Clean(bearishMomentumBars); - Clean(bearishRejectionBars); - } - - /** - * Validate Demand ... - * - * @return ( bool ) - */ - bool ValidateDemand() - { - // - bool result = false; - - // - result = IsValid(); - if (!result) - { - return result; - } - - // - result = - // - support.IsValid() && - swingLow.IsValid() && - demandZone.IsValid() && - bullishFVG.IsValid() && - bullishOrderBlock.IsValid() && - bullishMomentumBar.IsValid() && - bullishRejectionBar.IsValid() && - // - (ArraySize(supports) > 0 || - ArraySize(swingLows) > 0 || - ArraySize(supplyZones) > 0 || - ArraySize(bullishFVGs) > 0 || - ArraySize(bullishOrderBlocks) > 0 || - ArraySize(bullishMomentumBars) > 0 || - ArraySize(bullishRejectionBars) > 0) - // - ; - - // - return result; - } - - /** - * Validate Supply ... - * - * @return ( bool ) - */ - bool ValidateSupply() - { - // - bool result = false; - - // - result = IsValid(); - if (!result) - { - return result; - } - - // - result = - // - swingHigh.IsValid() && - supplyZone.IsValid() && - bearishFVG.IsValid() && - resistance.IsValid() && - bearishOrderBlock.IsValid() && - bearishMomentumBar.IsValid() && - bearishRejectionBar.IsValid() && - // - (ArraySize(swingHighs) > 0 || - ArraySize(demandZones) > 0 || - ArraySize(bearishFVGs) > 0 || - ArraySize(resistances) > 0 || - ArraySize(bearishOrderBlocks) > 0 || - ArraySize(bearishMomentumBars) > 0 || - ArraySize(bearishRejectionBars) > 0) - // - ; - - // - return result; - } - - // - // Validate ... - bool IsValid() - { - // - bool result = false; - - // - result = - // - IsValid(time) && - IsValid(symbol) && - IsValid(period) - // - ; - - // - return result; - } - - // - // Generate Provided Scores ... - void GenerateScore( - double &bullishScore, - double &bearishScore // - ) - { - // - bullishScore = 0; - bearishScore = 0; - - // - if (!IsValid()) - { - return; - } - - // - double bullScore = 0; - double bearScore = 0; - - // - // Generate Helpers Conitions Scores ... - } - - // - // Generate Summary ... - string GenerateSummary( - bool onlyCommons = false, - bool onlyConditions = false, - bool includeScores = true, - bool ignoreFalseConditions = true, - string separator = "\n" // - ) - { - // - string result = NULL; - - // - double bullishScore = 0; - double bearishScore = 0; - GenerateScore( - bullishScore, - bearishScore // - ); - - // - string commonStr = GenerateSpecifiedCommonSummary( - this, - separator, - includeScores, - true // - ); - - // - // Generate Helpers Conditions Strings ... - - // - // Combine Helpers Conditions Strings ... - string conditionsStr = - // - "" + separator + - "" - // - ; - - // - result = - // - "[" + GetTag() + "]" + separator + - "----------" + separator + - (onlyConditions - ? "" - : commonStr) + - " " + separator + - (onlyCommons - ? "" - : conditionsStr) + - "" - // - ; - - // - return result; - } - - // - string GetTag( - bool fullTag = false // - ) - { - // - string result = NULL; - - // - if (!IsValid()) - { - return result; - } - - // - if (fullTag) - { - // - result = - // - symbol + "," + - ToString(period) + "," + - ToFormatString(time) + "_" + - demandZone.GetTag() + "," + - supplyZone.GetTag() + "_" + - bullishOrderBlock.GetTag() + "," + - bearishOrderBlock.GetTag() - // - ; - - // - result = X121SMCConditionsToken + "_" + ToMD5(result); - } - else - { - result = X121SMCConditionsToken; - } - - // - return result; - } - - // -}; - -// -// Market Structure Models ... -struct X121SMCMarketStructure -{ - // - XZone demandZone; - XZone supplyZone; - - // - XZone bullishOrderBlock; - XZone bearishOrderBlock; - - // - XZone demandZones[]; - XZone supplyZones[]; - - // - XZone bearishOrderBlocks[]; - XZone bearishFVGs[]; - - // - XOHCL swingHighs[]; - XOHCL resistances[]; - XOHCL bearishMomentumBars[]; - XOHCL bearishRejectionBars[]; - - // - XZone bullishOrderBlocks[]; - XZone bullishFVGs[]; - - // - XOHCL supports[]; - XOHCL swingLows[]; - XOHCL bullishMomentumBars[]; - XOHCL bullishRejectionBars[]; - - // - void Clean() - { - // - demandZone.Clean(); - supplyZone.Clean(); - - // - Clean(supports); - Clean(swingLows); - Clean(swingHighs); - Clean(demandZones); - Clean(supplyZones); - Clean(bearishFVGs); - Clean(resistances); - Clean(bullishFVGs); - Clean(bearishOrderBlocks); - Clean(bullishOrderBlocks); - Clean(bearishMomentumBars); - Clean(bearishRejectionBars); - Clean(bullishMomentumBars); - Clean(bullishRejectionBars); - } - - // - string GetTag() - { - // - string result = NULL; - - // - result = - // - demandZone.GetTag() + "," + - supplyZone.GetTag() + "_" + - bullishOrderBlock.GetTag() + "," + - bearishOrderBlock.GetTag() - // - ; - result = X121SMCMarketStructureToken + "_" + ToMD5(X121SMCMarketStructureToken); - - // - return result; - } -}; - -// -// On Signal Event Handler ... -typedef void (*TOnX121SMCSignal)( - XSignal &signal, - X121SMCStrategyConditions &conditions // -); - -// -struct XRange -{ - // - string symbol; - ENUM_TIMEFRAMES period; - - // - double upper; - double lower; - - // - datetime from; - datetime to; - - // - void XRange() - { - Clean(); - } - - // - // Tools ... - - /** - * Initial ... - * - * @param _symbol: String ... - * @param _period: ENUM_TIMEFRAMES member ... - * @param _upper: Double ... - * @param _lower: Double ... - * @param _from: DateTime ... - * @param _to: DateTime ... - * - * @return ( bool ) - */ - bool Init( - string _symbol, - ENUM_TIMEFRAMES _period, - double _upper, - double _lower, - datetime _from, - datetime _to // - ) - { - // - bool result = false; - - // - result = - // - IsValid(_symbol) && - IsValid(_period) && - IsValid(_from) && - IsValid(_to) && - _upper > 0 && - _lower > 0 && - _to > _from - // - ; - - // - symbol = _symbol; - period = _period; - - // - upper = _upper; - lower = _lower; - - // - from = _from; - to = _to; - - // - result = IsValid(); - - // - return result; - } - - /** - * Cleanup ... - */ - void Clean() - { - // - symbol = NULL; - period = NULL; - - // - upper = 0; - lower = 0; - - // - from = NULL; - to = NULL; - } - - /** - * Validate ... - * - * @return ( bool ) - */ - bool IsValid() - { - // - bool result = false; - - // - result = - // - IsValid(symbol) && - IsValid(period) && - IsValid(from) && - IsValid(to) && - upper > 0 && - lower > 0 && - to > from - // - ; - - // - return result; - } - - /** - * Generate Unique Tag ... - * - * @return ( string ) - */ - string GetTag() - { - // - string result = NULL; - - // - string hash = - ToString(upper) + "," + - ToString(lower) + - ToFormatString(from); - hash = ToMD5(hash); - - // - result = - // - "XRNG_" + symbol + "_" + - ToString(period) + "_" + - hash - // - ; - - // - return result; - } - - /** - * Generate Tooltip ... - * - * @return ( string ) - */ - string GetTooltip() - { - // - string result = NULL; - - // - result = - // - "XRNG" + "\n" + - symbol + "\n" + - ToString(period) + "\n" + - ToString(from) + "\n" + - ToString(to) - // - ; - - // - return result; - } - - // -}; - -// -struct XRangeStructure -{ - // - XRange range; - - // - XZone demandZones[]; - XZone supplyZones[]; - - // - XZone bearishOrderBlocks[]; - XZone bearishFVGs[]; - - // - XOHCL swingHighs[]; - XOHCL resistances[]; - XOHCL bearishMomentumBars[]; - XOHCL bearishRejectionBars[]; - - // - XZone bullishOrderBlocks[]; - XZone bullishFVGs[]; - - // - XOHCL supports[]; - XOHCL swingLows[]; - XOHCL bullishMomentumBars[]; - XOHCL bullishRejectionBars[]; - - // - // Constructor ... - void XRangeStructure() - { - Clean(); - } - - // - // Tools ... - - /** - * Cleanup ... - */ - void Clean() - { - // - range.Clean(); - - // - Clean(supports); - Clean(swingLows); - Clean(swingHighs); - Clean(demandZones); - Clean(supplyZones); - Clean(bearishFVGs); - Clean(resistances); - Clean(bullishFVGs); - Clean(bearishOrderBlocks); - Clean(bullishOrderBlocks); - Clean(bearishMomentumBars); - Clean(bearishRejectionBars); - Clean(bullishMomentumBars); - Clean(bullishRejectionBars); - } - - /** - * Validate ... - * - * @return ( bool ) - */ - bool IsValid() - { - // - bool result = false; - - // - result = range.IsValid(); - if (!result) - { - return result; - } - - // - result = - // - ArraySize(supports) > 0 || - ArraySize(swingLows) > 0 || - ArraySize(swingHighs) > 0 || - ArraySize(demandZones) > 0 || - ArraySize(supplyZones) > 0 || - ArraySize(bearishFVGs) > 0 || - ArraySize(resistances) > 0 || - ArraySize(bullishFVGs) > 0 || - ArraySize(bearishOrderBlocks) > 0 || - ArraySize(bullishOrderBlocks) > 0 || - ArraySize(bearishMomentumBars) > 0 || - ArraySize(bearishRejectionBars) > 0 || - ArraySize(bullishMomentumBars) > 0 || - ArraySize(bullishRejectionBars) > 0 - // - ; - - // - return result; - } - - /** - * Generate Tag ... - * - * @return ( string ) - */ - string GetTag() - { - // - string result = NULL; - - // - string hash = range.GetTag(); - hash = ToMD5(hash); - - // - result = X121SMCMarketStructureToken + "_" + hash; - - // - return result; - } -}; - -/** - * Check a Zone is Between to other Zones ... - * - * @param source: XZone instance ... - * @param upper: XZone instance ... - * @param lower: XZone instance ... - * - * @return ( bool ) - */ -bool IsBetween( - XZone &source, - XRange &range // -) -{ - // - bool result = false; - - // - result = source.IsValid() && - range.IsValid(); - if (!result) - { - return result; - } - - // - result = source.upper <= range.upper && - source.lower >= range.lower; - - // - return result; -} -bool IsBetween( - XOHCL &source, - XRange &range // -) -{ - // - bool result = false; - - // - result = source.IsValid() && - range.IsValid(); - if (!result) - { - return result; - } - - // - result = source.high <= range.upper && - source.low >= range.lower; - - // - return result; -} - -// \ No newline at end of file diff --git a/X121SMCEA/Strategy/x-121.smc.test.strategy.class.mq5 b/X121SMCEA/Strategy/x-121.smc.test.strategy.class.mq5 deleted file mode 100644 index 27fb6ebbd90ab314bd40a356cae6d4245d535c59..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 153514 zcmeHw{c{vYl6L=m5%)igeGv{=-)fD07ml!Z_YMne6pIZn!d})F7X$_wv@3y562{oO z_ou(_n@{IFs;ug)?y8=i(EuF^=$W4GtgQTaGVA;Q{omg;oBaFd=AYW~cwIF6&7K?F-rhfwH_qg5A$Ja&ALPwP^6zyM zX#TdD?k`aNM#?!Bem;|u9|(UBnrqF+@^4?b+ZCPuo9yPznzXSPOG}na(@O!1bk7ph> ze~X@ZD9_@V{}h=(<1gfIN9y!KWP0_23zoGhn`C*sE}E}|#}}>KQJ=f5W=^Dzr>(|R z@(P7;r4S!M@LhBWv4y2G@US>jS@d*?JC2hi-ni{Qs8lb|iG5y)(J{ zv*1Fvem{$BkEPZ-B9rj^j@{U5(B~g?kPjHn(x}lRp$ZID6e0$8=?6Y*uy(OT z)0ZLx*!pAPxr@|av=Th%@CzCI+S=km-oqbihP(DVFu~FfSb(Qa%x{XV_Fd3Q>80Nx zHF%Qh?xob>y!C^wj7a$>`5lqNt7|SQU5WT0rL?~G{-UAWtT*xrUg_D-1=AK11I`5D zjzt?UL?6Jf^iOT)zWAp`7JYBuyk+IXw{JGzG~Y@*dni$NPp&tcFPnQ3gYap;EmwUW zm;|}_rQ8>(!4|)4OUEa#ER9VpnO8ptpoI1lzq{f{;^7jPl*hP~*a}(Zo>;}9P(Bn{ z9Yy|mCUN&_^LfPoKiY4$MyYmHD#%I@i@Fx)={eZi|2m$Px3-e{rTnqp$cca($fy>A z;fmH4pW>S5-y` zsC_9qLbkUr_n(TkU<00p;A`+U&DPGM=Y6jSa$A}oh}VYi{~B2pYZ2$ZslEF(_+V*g zY0XlJuna^TWW`p_)}DPY$x#b(ITea$g40JL-$nBW`S)WhP2|~XNwySnlcQ^8wbMqt z1EKcZ@kmlqZ;PeizgfeFX7(C^&RT0i&ZG7FXhgl9i0n1a!Rs`;hpb48wc#~>9+_oa zHlO1)eja{w)>?mg8Jb0)zJYdHR_;l>b6wv3le~3*gyjWKMH}->TKR}h$R{BC)K^&p zUemYt#TT?4;lE$wV}UlT^}1*kZN*m!hu!;m9p@;fTnC!rmps)j!sYn=d-HdZY5Z#_ z!H=tlq64(_-xGfbNE%0YYQx89{)+d{#WPMtzl(^PUozkGf9=L@KA*#G+($%3j|f_t z$h{F)AGgurk=z-I=0hd)<-=-^U$ru@8E;;%0TIgbUigdBzbmBxW8uGnevR$Nn1;5w zMjXZ%mJ{x$S#O%5Qg$h2^p08C+?A3}+MXD+=njPcxLr|0_v0mHTz@0~PFmW&J$Zb6 zvV0%c^!*xXGFty4i2l6A)Ss7>bMcjLJnp;^)A&&6T+5(5X`FOu#8k^@bg9I5ER`{` z0k)zy41J)Q8N;4G9jKdT3^-8JcbPw+bI%yjby|4E#K7$W_+imd+NQOR*alTca z5z=RP_1_F!gVVsdUss=oZMmyA#$H!LD{hU0r?~a2v}$YwJxj>5PbD`&-@z-1$3ga# z4zGMhksf*lhFp{0y|0((k9)+C8a_0F+>^JpNAsX`p2+@pbc0luZYd9m=`Qi5osps(jvo5|b|d7^c0GoP9~iY=aJ z(hIaFx#9z%1g-ow+eV68eRwZ@V@&zzDH>D0&H{-!9#{UewwJ2gp88~IK{Zsn7J9ry zq3fbO^q{;Ji$(70QDwf?y`mR9?teMxa1FblRrF`6UHZHetf4<2<@4PuD2#nK*up9l z#=gs3f9(55Qgigk#+H;r`>y18=k3YjQ{;LeBb4X?=SY4$(qoZ~vf!0(?uvBLD-@3a za^%zd)sF&QKP3%20$S^%+SBK8G1ec+l}B@|o!Yj>SQ=?xQFlfNHJ87>4R#*qJ8Iou zw0-25WpgHoa7VBnJ#Vl$%(y_r>eDJ_m7Ph1e7AhIc#5@pH&8Bf9-aUALM#+x*lEc_h!e}z;)O3)&E2&W ziva7Ct9sy~QEjfbR9~uT$@S<7RK*+%ZBfG_(H?vtIPhKbXUVJX$~O-whcYX^?Y|3b zl_~z^#YALK71PWIFaKqpHtTHnWr;eX1P4MM1NLpF`atZ`57v?NOP@_rSb_6Kk}Js z|6A+KR{Kj{U&hLEQ%Q!bl}~J!B=gy8KfhB*GWatyEg%2#ui=U+CfB?m)z)s?r!8eiVs?3SgiU*2ApyYA9`Y1?d<9Mq$+X1uAKFy<@c+4ZteJHyO1 z%%_8Wg&Z!nwp3F=ipWa?h1gQmlJbd;7kw)ehEpOJBFi?T}*^L5pF zZ;PJdv8UUu+@7{QsunT3RLbv+>AMWGv#~PbhRFDy$QU~V=&B853|NbR|8Iy7qVE8! zJ9UnES&ZJ5aq&As^VZTn*I^+$LLD9v%9_S9`f5LorA%vgA789k-K6EgMlqN4rC0}T zUf2F%?mK1_VGcjmJcZn#+^*v%Y31=<>^i|Ugc=EBln-_RjPx*%^z?1}{7@ziT#8G( z((5(lHLx+laC)H8Fcb}t zg|UWR8sre8udOZrJ6oTDt3Ii1ZeLmKOf7Ewc>Uyz{rLGJ4jt6psoTbw4>aVpZV8@11 z*$2z>yo|hA49HPf1@BUtY7w>dwCIvj+;lxHF9GRNuHt%n8pv6X;@sV>&KtSfqZ@h3 z5tB9S(g+&e6lNlN>`5-0<7HjAiIv}4+iuD0#m-Rjy3kX1Qs{4~<$QqXH0D}{EwsMr z@@&>L9WdOS_>xnxb;aNbDmq}1zCFr`47 z*<9QCGV;cL`K=3?Sn9gyA8%>iNS}={FK>CCml2VXHCwPIVu^>n(iVJgI=_jOCCK~2`O zOC{)abJ^qN<&VhYh9tT!oP+m;($`ta>812QE-vlvCB&as;d`t+S_5sw4l*VNso|I`#6^b_K0X@t-D*ha*gjU`vFTS4$b$B+d*YqmeFL4F5`4)20p#=Tvy5U{-Bq7)yE4yZ8OCf@Vu}LHQ>L){l=iAtpQBeMPwL3p{Av_~hK6ab zV(&RFhcoAZ9@d6(^y=g|9mOEWVVd=Jo?^7x0ahS*oVIA@h z$vVZqQVa7kh+Mu`BAHYpt4PMu8jp^tWGq$Rvg>U|`^;`icJj211noAGs7B@+j10kGRe)M)3#OmPXCx?Kac%wma=&lpNJH57RkJNH7mBhVr#E6 zKz%t5<;~2(hpu~~r5I1H2$uBeeVRI3FSwjKTMpJy=bX*({wg+uRU6O|B!}7UucdVp z&X_?i)E{dVlVZKcS{TCnD^gx}%}dEzMSU|wdTaeY9xh~k-0%uH@Z(d>VfWRGe$iEQ z5zcp5RU6hKFH0Mihv~FosZOg6wPgCkkloYwa;O+n%jwgz7E(kBdICtg9&Fe*!n^qu zfkU|O(YPg6>ACIm9u5E;OX9eOz|!bHS+dX%Z{T*d11u1JZm4a zslMOq^F`$`AlEd06X1lBJ)-&I* z=f!#Q;d8vk)>85Y-~12BD~8XbtD%TfSNkaLOZ(!s{P}iCzT$p_JiUD>?PpoN9nRM) z;dM26VN@v3(L<>l&j0(WchxQH$*Z1K+fNr`O*r+h@4P8Yxrerd*UQnuJR<76QEr*DSn9?sIODI57>I1`uOYA9G4V`fPBUPGmO z%CNmtL&?Tijo|TlZ#A?|WON5}z_ByD_VNO|?7cc_I1LZyY3W|`Hov$p{`pjP1ZNbd z6{pu!|2*Fjl1DolqmsEZ9aCET9@Dhv-BEt=NrO8g14u;AV^skbksIcc~{IhDP}OIXO6P{b^& zLpg5|bF8qJ8qT6b{`Iuop=YnPQ;c|^J$Tsa+-o(06089uB+Pq)J>yg{j0&H&&%pAn zwtkJiQLb@)AIND(AIraeS&OkN|9>lO44mn$r(as0?@L*KlM@N1-mt75h{nGY+w$b3J=1$qA0RW%nFuF6*t=<+ z_QjU4D?4^cv^$;SWMrNcVejkvCA^}~k^OWzp831wQ2FLQoc5O-@1$b+B>$vie=Ds6 zZ1YgOR?#4>1AHL->f3*bt;e$bjmX{J(G#j61?@k>Y#f~l`ahy)-G2^yL*WVZu|00N zeIdNT0&J~Q{*|}iNXx;NhkOGTsuV++mXe;*Yv1}cqG4-opW^)(DZ819wi)-u(=q$? zh158o5rlpq|1@B{Lg6jwEi81JXAA26P zPZ@a}&Ug7z>;!r!i`D(K6w{`lv@i7qcRsB#a&(u(aq zrZ!f>)<$!d??ujj>!(aC^~?4E@?>pl*bAs>FDv$=Fi;uo0%XNHhOw8)TM@N$an(}6 zC;@0d=2p*j@l<{En(zdhd@k2+hRE9Lvo|C^cqAx@){bU3S7glM+OjR7cluhDxoD=; z|9xdn;+FP!POdep^8y;$##&V_(9kW3Z!bmq<8^e)Xl=Y?uov^HynHMaf(4D|<=-aY z<=-aa1vsZs-pR*?6~J zDOEpb;n*a4s?Y-p39&a+rOt1;zR{W*gWu5KWwTo?>rHCK-D@K|YID%`()sJVYNVqG z@x9PPPZ{a;p}y_C;yES0p2Lb1%!S%pwm!m22flrod0Fh=Ij>>Npm*`gnK$o=M&cUA zc@m%Z^CkXj`%!&~c5^_!o8wⅆ6jl%~gAOl(zci8W5kGw9e{JeCIN?8Y5FqHgB$0 ziQ<^I@^TsNfZw_Jh8|gD@FA{Z+><%A>g}QQGT2BSo>lGFqDt<0j9t8x-rp1HLqYb! z-evRy=B+ZV>2<*?v<-A^2gXD&*2Eg^$mdW-C}BwBXyb&Hg!|&vN;#B{RS{mz`aL^m zf%M)VMe@kCvHC-EmqYnRjbg^Uo**0e_+0KB%82`i8GcB)pD#W=q~aG@=fPPrHkN6(1 zW%kRbYb2yP4Z2W^BBk6_BXHfXW1}{DU~sm#o~l7x3plysB2mByt>F+-BBy65p^Th< zsm~cHb2gy&OOeu-{*06=#o(QFc$UKfPug{q-*%+*B((iV8L!n{NUn?7lW5bTMT=eu zo%;PT6A;&~ zI@}!M+EN3`&xrd^66yN?rbpaiUCfBPF2o&@{fxLV;tt8{O+Z|mZ7$lGahO-RSoT=z z8LnSRe}SE)ypBxwODXXy$$978)<@jwk=AOS(x0()UD(={_Kc=6nsz1hCg7)y0h`88 zTQ)s-#?MXRrziaxKi7qyU1`tw8RKVHLfem@9JR+tHD=d^u_BJ!Pm^nMG*in7rOar# zDq7x=xu?7BP92BKm4<3{-pG9_eT$af{D+jc(j0hb)V-uEmR(vVpMOurJ$Ktt^mNy! z*ak6^$<7N&XTg)+&=q?W)y)*}DAv}}qe1=ev|}S!W%PUb$FZ$&cWB2!k9K-5l%+E* zZ-~TS$(S~zxM=@%Wy%yWrjn6Vc!$7%CZ%+gLv3uVn&s)w}Y5!uc@r^R)%)P5bj zTe+$yi?=yr)hPC@jB;oOxxT!G_O~M$sph3~zPg%s`)}*rT)yDj_vWmij;|q0nL2ab zoE*x%Vd^>tna0_wSNE~n>dRP5EO5?W)r+?yfAuuR9#(IUtsE|GGK|jj@(Uc-@1xC_MtLe*6DDa z7S0|-zhD3DuyAVwmuum)_w?#}iQe_RB4-hb>i49_>#y<;`$_4lQ{s5YO+2c#D-n^k z#pTSoNvhfSdroihQ`keWWb8LD|0%N*&r(u;`8~8bwXJu%9XrGh&W~h$7se68C}R5T zt!1B0`m|zD2^Xc(RWFHgTlYSVt(jgkXFu;o_S419w=Mta)^If&pEDpLpI)~$$F~_! z*9JCg<*~%Vw`p^reTg;Ln+1F3GqQy2XR4WREF+Y_wtA>nY#H&)qUXj?w|Br`ZI0 z;NI5Wj}JMI)z)%ci%?3)t}th4A+y!>oCWTJWzVJY=6G4YC|fPjo}{s8_sYhcHb`v0 zmEGxb-dNa!Fh|R~kGW@4?J~Ri{n z?=355>^tgb0NgP&$l6L_yRE`<8uYcgZ`>C7qpki-G^n`;BJ#O>zb+>=K_fw0DOy;G zK||q5%WZgydhvWKR}+m$Y-@5)b$<8bwfbpS+u@YCz!UQ=Qq&SQ@Bd%7n0QlA@s{A@ zSMq;9G6q>&4VJ#+>t`Ioq$l|8NG^!8@Q{aevo~UBXxk&RfIe_CS=jMB)Gui5GWW^$ z__0=$vtQag>&+`$AKH&=>mO%~eBRF-`71J8o}=kwUpH&!yE)E%y&Nwyh3ld*oLu)> zw1?dTcjR1x7Z)oD`u)d~WvS)D8n}j_|D6YIhOsC4#!azEoF#Xs`9|)2A?Ix3j7RM8 zeM?X)SN}IxbBdYT9w1_}br5oP>Yvv`(I{d-&`vmK(^|S_hL(E2w%3s@1+=^^TK)4I zhLu6CWmxHZqNk_rK*&%(Yd3G7pZR*379oQy`_V48hE);rreuF;r@h?>c|#(YW-ofq z8c*>Jy(NA5C1zE;lpGnk&Z2FxBah||_{^el{aNxLFXtul+8onG5XOcwc5T-MFxGTlT}| z{hry)W%|>TLv;6O#5sn zDjRFCqZ&11BV{8EmU?c?#A34FcFgIP?SS~aFL-zE%p|@MpCyGiVjA`&K3WW~q!FLp z2O2TeG8$bf@f}OWN{ZYJ$p)T0p9u)!(ORhL? zp7AlwhB+pQapb-}w32f846_JN(m9QW**yMe5Ly?{B$LPgH>58LSP|Cl`JNxF1Z%6# zWNhh{j6vZ4^;yV{P>;)+#xnY9KaHhKYj+<@|EAi*CM^#oqTQh9Mrg@jiq&u)+!yls zNqa(XJ};yd4_#^H>2s;o#cSwd8}vMc^tv`Xv~wwNDK70wuh*2-V(hTSpS0W>B`11KhxjwVQ4mAJnE3r*I827*H1@t5wkwc_T0ohu9#)W zIfd9)rJq*4batKgQ#}<=ro-*Bl1QLby7V-jVG1XdMjMiN(1Y7jHkNjDRc^c!Q zN57}l*483>p40x(#VKoR`9Y*9tF5PtoGodzNq5vJY2%jTU`o9n1yc&a?$+0iqV?)k z5zyyjUHC_Rr=_kJ`&jC_kneaPH^^CPtdE*+wJ2cs(@JF@EYI^Ya%C|fM`0DbOKGY_ z)Yj9YOG*;AAXFZB@cegrkWRG7r@{}VcYuKd`G`cCwM1Remh&m?QlQOjuI+pod1Jr))`d(gbzSt2w={30 z&&HUSw>;0wh{(trNiRoX6}(Gn#`zSv;5GCVTfV-K_=An(iVJgI=_jOCCK~2`OOC{)abJ^qN<&VhYh9tT!oP+m;($`ta z>7`_ni;G$B#2H>wyrDJ5$l7O{o=1|pVi;-Wsf@$dA!}idMQ(V_*V!Ulp4*a~a;iF8 zj)1kLb@sHb>jeN=t@tw%DcMpluGr8S*oEY+zb z)0e%#7Cd{%z0;$mO0Gf~Sdw${5mNwOY8^_;@u zt@Ui5E@JM&-1_mluoP3IyIft2k-l%Ux`QJ2P}6gVkjo6kHd3xh}%@s*hXPl;1b<|g@S2!brd##SGL!fk9JndD+N>}Ap z5ecij&NC$tGkEP{5#)O&_^cSN=6!9=1de~15b@yVEN-(X@^_G`M5);B{Js}$Ih*U!v0qJvN zcFalkgOFnG8mRAxZN6AaBiN=!d`}Z8 z#nQUb2Kw`kerdDpGO6?FQV#k216fOEeTaIvBO?f0QHcEUP_jYXQCacrp=&@YVAF2v z@rn^)oxA3l+%HS___a@Z+>M(X9PD7+_#kDF-^({Aj~rIyo~QkErB-G$q+4e@eCt@& zsB5PFe5rL^t$rq$dR?&WNsBFN54AOm+e9oez4kxl|JrR|k!sE-a380$ggoAhAk&;A zhn&6JTF6O{`k!M6b?9G9V~8*PH!Fr%J0(h=4Mc28tquor{z7W$6*0u)ZhK;g$K4!5 zQa$?L>uiTK-mMrC_t7jQYO4nayaLwzFp4D-4@v1pjrIWkeV{nt9XBCU5VGTBkL%|#|# zY7RR-cYD9)w$JZexzK)jEsspYx_Hwf({PQ-`bp{#WL#t#;&q!M(-5z7WTN-=U+e6O zwBEJIWLqzb=1UnX!OobA<*147g7}r(J(0d+j_0hS<-~F0xvfM?jIX7*S00h9<|+L* zEe3gY*q*4<eTZF6Mt?K!8%^y%`* z;z@swEU7&8d#UvKw)V7jCA>|MrOVwMS*XAM>l|4ipPWxHve?YUTR+QnczxqMq-AY& zEUhq`OlM9F&1E~5`A=MZg}t}Areuy#zIWv8A${7O$8@-qYIiPMPWm+wDxOmnk0xk| zEMND3h@a@6Ynj%nwDz><*gLwjez^j+zcrt7!5(4EhKg%5yz(lg#Tj`qo!qSJ?QGBa z+-_48wszoiJ2omSUd{9OQoFX_x1}GkWNf$;VTb|mNgv^qC}3l-Z>ifc$BGDR`Sthq zD9J#qwb;+y4BwZ@HerpGh|leeHCD&D&vX6{$>i`z{V$)C8dtGNc z=jl1S)%!WUrEitx>3R82nW=l0lJd*%A*a`qkab1ce!Dsurz^dZIr&$`e*Y-{(r392 zE`9p*cAh~A7p2lwFNt&O>7o>KfN3)To2z#HJNR9Roa!*NRI0Rr?o78FzuOd_OXNF8 zXzIA{T4!CPG`9vQiQF~x3D{gR=UeY~dmty3Z9<$9EzXFO^9FnW%|;ws6Z?7E^@CxT zfQ6i%dno5|KAU{L(wXFUSdIVGlrZ<$Tb+i_rCC*3OTd%7Z3C2Kg{2%ZzhyiMmKE%3 zTY99sylqbe=<+tBeejR`ry1=bo1C}eKK2_S5-*ytD@@;LZ*AYt*+mJYKO?XboC1`^Ep@7ZupZ|SpT_}{OCO+^9U+O{R<_qd~-Zcjw$<8qD*sdsqa z-@Uj%DRg%V9NvljM!Py0`-Wpa19ts>DtPYg7Z~>l5ATK^Ca)4TAepCbn1bnbz6GArlR$=@P{2Gk3^b88IQwQ9@L~S7yb&g zKW}#$ex8Z0T}$A*IoXEU_w1z)`irw@or_<;t2{O4A>67ot+YK_*5-yJ0o&U2ZqGs1 zVdrOUvv5U$R|ERPu*QbGAox?i4~((aoW)TOQ@7KCC1XC7-Ep^mZ{E1wSQdXhS(eS~ z=RUk;PltV;^Q{2NIG2UH6z!!{CEma?BlA|AA?-WJZ$#Izh>L-^zHTeV;s}R_+d<;-2d!*^nj^y zw-Qfend7{UR;zgs&dSA!ONg=_-LiF)LtNur13g>nsg!ltd?Ps&R^uuUAtL&c)tTS- z<(;SPZ12ybHUce;*I`tl1a_k6|AjdlsSG)G+ga%7Io^{@UeEMEq{N9;$Psk~10-0A zCzMOs^T@k@X#Ona;4CK0g`b9xetnej_D%Dxw3coc)|{<{ZO>GO?3^|jEQ~${Ej~GVZ?A>QfzaKT(`)`By1Ust zl>N=G%lBJyy(4!?-^+JMo7YlVZ7TaCU){Fva4*Q$;?JjY;uzZ13qg(Ud3%04Y`7Q1 zQugSs)*}+I@LcfrM6{^qTPW`SD78A0HqgPcm%!6%PK$vuTbJwwuxHG%t!>Np(Ys5} z+q*tbZ+hOtIZ{(`-$!vZ{^ONLcSOsGNA|3|yyWN?ymmDa?<-YDeckoylPPP&>zJDL z(Vwzzx?|RKS{kA^J@0*zq6T;!(ggPp%gbX*{{7X{`LbCHUWaN^OMm@!n^ISP?fOcX zvVLg)dn<;g(_VcEo2Xx(d})`w4%ug}hJ9tMR>v@#m^1uW(O00Rb0YJ!rsld&LX%*e9QW7*n6?# z$~+5>l1;C<-iP$LzI}4*G-2n$rKP0b!?~*S`MRlW?5Mr%5gLcEDfP=m+?1PO2W9x$ zeP5+AjJN5V?2k?F=e{$dcjJ^lYMi6fKbo9-Yf8LM%kak;>z?vybo+}*HHS{PKlXfG zYKS?P-wQf6=R&VwdK&L0b1tto;}BsA1n{^i8~Mw{6i>com@wyD^eW#ASIN0Nt;{(W z<(*!0sFprACg<`s@n+>*9%^jQiZ+kCaR{60`*IOCsZ09tRzJ>SvmR z#Z>+A&#@WV4})h}Z!$j{uIV@|nF2e8d0Q=a8`i{}$@v(wX#AYbzq?8%H>{&MugmFZ zoq1h}Uf!%MZy0U1C+8dHbsTD^mb6VMp7J*5gQ-OP@9$bZX!k^&E+4d1r_Kk5Xm2(j z9O7mivP^>{L%gk;4-V0v^FbeDHkl6&>1fUeb2?gYJ~*tGH!U9=u2I<-THV-Lsg|f^ zjJpoc*B*!3EQ8l=LUHoM>zof#68+bAEg!U}a;$bjc7HD+=ig7$FR0WuoB3HuY5C(& zV;Yp`aI%i^(ME~_&%fxJZYU)hP(pJwJ zJ~2Btr|SoaC0PB9Ig`&CrMB5jtXuwNW@24#R?Wn^6z5DVhZTO#<=+i?hps}oE>?{7 z|F3072j)mMRzLTp<+QTiOswl4XU&|6`MN081mEuVmu+7r*42L*;5_7TkdePiF54e|NQkzp0@i8DU0FEi!4l;1JPy{)}yek2%& zys12=?^W};EkojzyTfIaE<@Sw+bW}Z1uFXTRTjBXhg5d_?&CFo<+cAQ|5v^1`FzgD zaUXe`Z8=Pr*;%T-4X={f4O8E2W;e{wIDDA~PlmZG!;^e$8ZMy>bLdyY7&GK~j99g+ z*vm%MrfmK7`7;rL*VQt+VJ*#>9VMM!b10fVHzueqj5+x4YHK*w`!JGQpTL;r9RK^ zecsJycwH^eE78-O=~33{wKNYIlj)UdW^=h-89&>T?UnF54uw-I*fvy7`I|GoR3hH@ zcP-na$b);E%lJz4G-rG{ zJ*_k2E7Q#8GQKi?wkP8&;ddMgr`E7-sGRaQXMCwdyzlQ;#urWpS;+Z&hjRAiGg*Pa z-n_C|c!35fjPJQSlk)|!&h6<1H=E4ax-}Vx3{xOMmzULYv94t2yvy@{+}l*%)z!(I zW94+Rz8uTb!lv@6u9w3CO2%i`KQ`LsZ5$e=8of+(OnI4eqEsT@_jflZ(zD*iXGA*cCs!T|!&3TaL^SHP9JV-S%XF)lQY$6My4mO_yvE=Q` zfRwXw2$<^f@(?lQWX^t4iFn`Nwd}{9;#!~i*tb{d2eNcFoAua|zn9&Yp3A(qah^Yo zr+fUYngLmwb@@-((~q0`(vNp6lACAZ`&rZ~GqlcR$FURndm%e*oJ)UgZY=}nX3u+< zdAJ_#)z8FAHL$r{Db@V8^c7jYRzuC87yWeED4Oy!P1aO~qiNYSxSGD3Ly7b`ekXd= zu7KkEyw>$p@~w9(>%yFz+# zR?Eped6!`X*F2UzU4tM)h%pu+$`D~n1n_e(|L!W8nWx1$KO?56*Y)*g`Fhw?mgb?v z_KfR!+^vSJsb04OX;ZG|ysfNXm2xXXX+F*Cl&DRby!v>}UwQ3+%KtUKtKV$PDn+Vb z;W!KTT>d?l|8?c!m1G3pmt#ti+y}~vVOX(pF1;v!kbgf)Zg?a);(_e^4el(5d_PB* zyNCbM>`8u!Gm?K^QpG;v9wolph@2lce_P7u(}B7{mdM*xN8Ng*RDEebkuqUN=NJ8EHdBN4*`u~Ay+7Dv^+5D^ zF8jhWORK3d_{DC+m}$2V?q5q^9W3u?S&Oe)PWH|HP!27P*PG2Z&9}0n-$UVWPp&s* z|KfYi_4d=g&^r-YDC>n-oyth5-!=CG^_p5hpSns#Yje>2BsBe1$@O%{`elg&zMi{Y&F9g&dMz2ToZm{m|H;^+bACcgBPYDF9q?XjmFOD- zX8F