From eab3888c8863a708b51877c616225ee5db41e9a4 Mon Sep 17 00:00:00 2001 From: Hadi Khazaee Asl Date: Tue, 22 Oct 2024 15:44:45 +0330 Subject: [PATCH] Add Support to Draw Rect on XZoneChart Object ... --- Classes/x-saherelm.x-chart-objects.class.mq5 | 200 ++++++++++++++----- Classes/x-saherelm.x-poi.class.mq5 | 6 +- Libraries/x-saherelm.x-poi.lib.mq5 | 157 ++++++++++++++- 3 files changed, 313 insertions(+), 50 deletions(-) diff --git a/Classes/x-saherelm.x-chart-objects.class.mq5 b/Classes/x-saherelm.x-chart-objects.class.mq5 index cdcd5166..044fe057 100644 --- a/Classes/x-saherelm.x-chart-objects.class.mq5 +++ b/Classes/x-saherelm.x-chart-objects.class.mq5 @@ -25,6 +25,7 @@ // #include #include +#include // // Definitions ... @@ -272,6 +273,8 @@ class XCZoneObject : public CChartObject * @param lowerPrice1: Double ... * @param lowerPrice2: Double ... * @param objprefix: String ... + * @param forceRect: Boolean ... + * * @return ( bool ) */ bool Create( @@ -284,7 +287,8 @@ class XCZoneObject : public CChartObject const double upperPrice2, const double lowerPrice1, const double lowerPrice2, - const string objprefix = NULL // + const string objprefix = NULL, + const bool forceRect = false // ) { // @@ -315,49 +319,137 @@ class XCZoneObject : public CChartObject : objprefix + "_"; // - // Upper Bound ... + // Check Params For Rectangle ... + bool canDrawRect = + forceRect && + upperPrice1 == upperPrice2 && + lowerPrice1 == lowerPrice1; // - string upperName = prefix + ToString(X_UPPER) + "_" + name; - - // - result = mUpperTrend.Create( - chart_id, - upperName, - window, - time1, - upperPrice1, - time2, - upperPrice2 // - ); - if (!result) - { - return result; - } - - // - // Lower Bound ... - - // - string lowerName = prefix + ToString(X_LOWER) + "_" + name; - - // - result = mLowerTrend.Create( - chart_id, - lowerName, - window, - time1, - lowerPrice1, - time2, - lowerPrice2 // - ); - if (!result) + // Draw Rectangle ... + if (canDrawRect) { // - mUpperTrend.Delete(); + result = mRect.Create( + chart_id, + name, + window, + time1, + upperPrice1, + time2, + lowerPrice1 // + ); + } + // + // Draw as Trend Line ... + else + { + // + // Upper Bound ... + + // + string upperName = prefix + ToString(X_UPPER) + "_" + name; + + // + result = mUpperTrend.Create( + chart_id, + upperName, + window, + time1, + upperPrice1, + time2, + upperPrice2 // + ); + if (!result) + { + return result; + } + + // + // Lower Bound ... + + // + string lowerName = prefix + ToString(X_LOWER) + "_" + name; + + // + result = mLowerTrend.Create( + chart_id, + lowerName, + window, + time1, + lowerPrice1, + time2, + lowerPrice2 // + ); + if (!result) + { + // + mUpperTrend.Delete(); + return result; + } + } + + // + return result; + } + + /** + * Create XCZoneObject by Providing a XZone ... + * + * @param chart_id: Long ... + * @param name: String ... + * @param window: Integer ... + * @param time1: DateTime ... + * @param time2: DateTime ... + * @param zone: XZone instance ... + * @param objprefix: String ... + * @param forceRect: Boolean ... + * + * @return ( bool ) + */ + bool CreateByZone( + long chart_id, + const string name, + const int window, + const datetime time1, + const datetime time2, + const XZone &zone, + const string objprefix = NULL, + const bool forceRect = false // + ) + { + // + bool result = false; + + // + NormalizeTime(time2); + + // + XZone tmpZone = zone; + result = + time1 < time2 && + IsValid(time1) && + IsValid(name) && + tmpZone.IsValid(); + if (!result) + { return result; } + // + result = Create( + chart_id, + name, + window, + time1, + time2, + zone.upper, + zone.upper, + zone.lower, + zone.lower, + objprefix // + ); + // return result; } @@ -386,6 +478,7 @@ class XCZoneObject : public CChartObject } // + mRect.Width(value); mUpperTrend.Width(value); mLowerTrend.Width(value); } @@ -398,6 +491,7 @@ class XCZoneObject : public CChartObject void ZoneColor(color value) { // + mRect.Color(value); mUpperTrend.Color(value); mLowerTrend.Color(value); } @@ -410,6 +504,7 @@ class XCZoneObject : public CChartObject void ZoneStyle(ENUM_LINE_STYLE value) { // + mRect.Style(value); mUpperTrend.Style(value); mLowerTrend.Style(value); } @@ -423,6 +518,7 @@ class XCZoneObject : public CChartObject // CChartObjectTrend mUpperTrend; CChartObjectTrend mLowerTrend; + CChartObjectRectangle mRect; // }; @@ -607,6 +703,7 @@ class XCSupportZoneObject : public XCZoneObject * @param window: Integer ... * @param support: XOHCL instance ... * @param time2: DateTime ... + * @param forceRect: Boolean ... * * @return ( bool ) */ @@ -614,22 +711,24 @@ class XCSupportZoneObject : public XCZoneObject long chart_id, const string name, const int window, - XOHCL &support, - datetime time2 // + const XOHCL &support, + const datetime time2, + const bool forceRect = false // ) { // bool result = false; // - result = support.IsValid(); + XOHCL tmpSupport = support; + result = tmpSupport.IsValid(); if (!result) { return result; } // - double bottom = support.GetDown(); + double bottom = tmpSupport.GetDown(); // result = Create( @@ -641,7 +740,9 @@ class XCSupportZoneObject : public XCZoneObject bottom, bottom, support.low, - support.low // + support.low, + NULL, + forceRect // ); // @@ -689,6 +790,7 @@ class XCResistanceZoneObject : public XCZoneObject * @param window: Integer ... * @param resistance: XOHCL instance ... * @param time2: DateTime ... + * @param forceRect: Boolean ... * * @return ( bool ) */ @@ -696,22 +798,24 @@ class XCResistanceZoneObject : public XCZoneObject long chart_id, const string name, const int window, - XOHCL &resistance, - datetime time2 // + const XOHCL &resistance, + const datetime time2, + const bool forceRect = false // ) { // bool result = false; // - result = resistance.IsValid(); + XOHCL tmpResistance = resistance; + result = tmpResistance.IsValid(); if (!result) { return result; } // - double up = resistance.GetUp(); + double up = tmpResistance.GetUp(); // result = Create( @@ -723,7 +827,9 @@ class XCResistanceZoneObject : public XCZoneObject resistance.high, resistance.high, up, - up // + up, + NULL, + forceRect // ); // diff --git a/Classes/x-saherelm.x-poi.class.mq5 b/Classes/x-saherelm.x-poi.class.mq5 index 611d2077..4f644572 100644 --- a/Classes/x-saherelm.x-poi.class.mq5 +++ b/Classes/x-saherelm.x-poi.class.mq5 @@ -4383,7 +4383,8 @@ class XCPOI : public XSCBaseAlert name, Window(), bar, - cBarTime // + cBarTime, + true // Force Draw Rect ... ); if (!isCreated) { @@ -4450,7 +4451,8 @@ class XCPOI : public XSCBaseAlert name, Window(), bar, - cBarTime // + cBarTime, + true // Force Draw Rect ... ); if (!isCreated) { diff --git a/Libraries/x-saherelm.x-poi.lib.mq5 b/Libraries/x-saherelm.x-poi.lib.mq5 index 5efa2b2c..83f627b2 100644 --- a/Libraries/x-saherelm.x-poi.lib.mq5 +++ b/Libraries/x-saherelm.x-poi.lib.mq5 @@ -47,6 +47,18 @@ enum ENUM_XPOIS // Support nad Resistance ... X_POI_SUPPORT, // Support Zone ... X_POI_RESISTANCE, // Resistance Zone ... + // + // Supply and Demand Zones ... + X_POI_SUPPLY_ZONE, // Supply Zone ... + X_POI_DEMAND_ZONE, // Demand Zone ... + // + // Order Blocks ... + X_POI_BULLISH_ORDERBLOCK, // Bullish Order Block ... + X_POI_BEARISH_ORDERBLOCK, // Bearish Order Block ... + // + // Fair Value Gaps ... + X_POI_BULLISH_FVG, // Bullish Order Block ... + X_POI_BEARISH_FVG, // Bearish Order Block ... }; // @@ -75,6 +87,18 @@ enum ENUM_XPOI_EVENTS // Support nad Resistance ... X_SUPPORT_ZONE_DETECTED, // Support Zone ... X_RESISTANCE_ZONE_DETECTED, // Resistance Zone ... + // + // Supply nad Demand ... + X_SUPPLY_ZONE_DETECTED, // Supply Zone ... + X_DEMAND_ZONE_DETECTED, // Demand Zone ... + // + // Order Blocks ... + X_BULLISH_ORDERBLOCK_DETECTED, // Bullish Order Block ... + X_BEARISH_ORDERBLOCK_DETECTED, // Bearish Order Block ... + // + // Fair Value Gaps ... + X_BULLISH_FVG_DETECTED, // Bullish Fair Value Gapّ ... + X_BEARISH_FVG_DETECTED, // Bearish Fair Value Gapّ ... }; // @@ -84,7 +108,8 @@ enum ENUM_XSESSION X_TOKYO, X_SYDNEY, X_LONDON, - X_NEW_YORK + X_NEW_YORK, + X_FRANKFORT, }; // @@ -303,6 +328,100 @@ struct XMarketSession } }; +// +// Zone Struct ... +struct XZone +{ + // + // Props ... + double upper; + double lower; + string prefix; + + // + // Constructor ... + void XZone() + { + Clean(); + } + + // + bool Init( + double _upper, + double _lower, + string _prefix // + ) + { + // + bool result = false; + + // + result = + _upper > 0 && + _lower > 0 && + _upper > _lower && + IsValid(_prefix); + if (!result) + { + return result; + } + + // + upper = _upper; + lower = _lower; + prefix = _prefix; + + // + result = IsValid(); + + // + return result; + } + + // + void Clean() + { + // + upper = 0; + lower = 0; + + // + prefix = NULL; + } + + // + bool IsValid() + { + // + bool result = false; + + // + result = upper > 0 && + lower > 0 && + upper > lower && + IsValid(prefix); + + // + return result; + } + + // + string GetTag() + { + // + string result = NULL; + + // + result = prefix + + "_XZone_" + + ToString(upper) + "_" + + ToString(lower); + + // + return result; + } +}; + // // XOHCL Event Handler ... typedef void (*TXOHCLEventHandler)( @@ -322,6 +441,12 @@ typedef void (*TXSessionEventHandler)( ENUM_XPOI_EVENTS event // ); +// +// Zone Handler ... +typedef void (*TXZoneEventHandler)( + ENUM_XPOI_EVENTS event // +); + // // Extensions ... @@ -369,6 +494,36 @@ string ToString(ENUM_XPOIS value) case X_POI_RESISTANCE: result = "XRES"; break; + + // + case X_POI_SUPPLY_ZONE: + result = "XSUPPLY"; + break; + + // + case X_POI_DEMAND_ZONE: + result = "XDEMAND"; + break; + + // + case X_POI_BULLISH_ORDERBLOCK: + result = "XBULLOB"; + break; + + // + case X_POI_BEARISH_ORDERBLOCK: + result = "XBEAROB"; + break; + + // + case X_POI_BULLISH_FVG: + result = "XBULLFVG"; + break; + + // + case X_POI_BEARISH_FVG: + result = "XBEARFVG"; + break; } //