From 64cfece3eb6c8e7042c292651ee680f7b281879c Mon Sep 17 00:00:00 2001 From: Hadi Khazaee Asl Date: Tue, 22 Oct 2024 14:19:36 +0330 Subject: [PATCH] add Resistance POI Mechanism ... --- Classes/x-saherelm.x-chart-objects.class.mq5 | 383 +++++++- Classes/x-saherelm.x-poi.class.mq5 | 958 ++++++++++++++++++- Libraries/x-saherelm.x-poi.lib.mq5 | 4 +- 3 files changed, 1335 insertions(+), 10 deletions(-) diff --git a/Classes/x-saherelm.x-chart-objects.class.mq5 b/Classes/x-saherelm.x-chart-objects.class.mq5 index c9c60019..cdcd5166 100644 --- a/Classes/x-saherelm.x-chart-objects.class.mq5 +++ b/Classes/x-saherelm.x-chart-objects.class.mq5 @@ -31,15 +31,24 @@ enum ENUM_XCHARTOBJECTS { + // + // Global ... + X_ZONE, X_FROM_TO, + // + // Structured ... X_TRADE_DAY, X_MARKET_SESSION, + X_SUPPORT_ZONE, + X_RESISTANCE_ZONE, }; enum ENUM_X_CHART_IDS { + X_TO, X_FROM, - X_TO + X_UPPER, + X_LOWER, }; // @@ -60,14 +69,24 @@ string ToString(ENUM_X_CHART_IDS value) // switch (value) { + // + case X_TO: + result = "XTO"; + break; + // case X_FROM: result = "XFROM"; break; // - case X_TO: - result = "XTO"; + case X_UPPER: + result = "XUPPER"; + break; + + // + case X_LOWER: + result = "XLOWER"; break; } @@ -78,6 +97,9 @@ string ToString(ENUM_X_CHART_IDS value) // // Implementation ... +// +// Global Chart Objects ... + // // From To Chart Object ... class XCFromToObject : public CChartObject @@ -217,6 +239,197 @@ class XCFromToObject : public CChartObject // }; +// +// Zone Chart Object ... +class XCZoneObject : public CChartObject +{ + // + public: + // + + // + // Constructors ... + void XCZoneObject() + { + } + + // + // Deconstructors ... + void ~XCZoneObject() + { + } + + /** + * Create XCZoneObject ... + * + * @param chart_id: Long ... + * @param name: String ... + * @param window: Integer ... + * @param time1: DateTime ... + * @param time2: DateTime ... + * @param upperPrice1: Double ... + * @param upperPrice2: Double ... + * @param lowerPrice1: Double ... + * @param lowerPrice2: Double ... + * @param objprefix: String ... + * @return ( bool ) + */ + bool Create( + long chart_id, + const string name, + const int window, + const datetime time1, + const datetime time2, + const double upperPrice1, + const double upperPrice2, + const double lowerPrice1, + const double lowerPrice2, + const string objprefix = NULL // + ) + { + // + bool result = false; + + // + // Validate Args ... + result = IsValid(name) && IsValid(time1); + if (!result) + { + return result; + } + + // + NormalizeTime(time2); + + // + result = time1 < time2; + if (!result) + { + return result; + } + + // + string prefix = + !IsValid(objprefix) + ? "" + : objprefix + "_"; + + // + // 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; + } + + /** + * Retrieve Object Type ... + * + * @return ( ENUM_XCHARTOBJECTS ) + */ + virtual ENUM_XCHARTOBJECTS Type() + { + return X_ZONE; + } + + /** + * Set Zone Line Width ... + * + * @param value: Integer ... + */ + void ZoneWidth(int value) + { + // + if (value < 1) + { + value = 1; + } + + // + mUpperTrend.Width(value); + mLowerTrend.Width(value); + } + + /** + * Set Zone Color ... + * + * @param value: Color ... + */ + void ZoneColor(color value) + { + // + mUpperTrend.Color(value); + mLowerTrend.Color(value); + } + + /** + * Set Zone Line Style ... + * + * @param value: ENUM_LINE_STYLE member ... + */ + void ZoneStyle(ENUM_LINE_STYLE value) + { + // + mUpperTrend.Style(value); + mLowerTrend.Style(value); + } + + // + protected: + // + + // + private: + // + CChartObjectTrend mUpperTrend; + CChartObjectTrend mLowerTrend; + + // +}; + +// +// Structured Chart Object ... + // // XTradeDay Object ... class XCTardeDayObject : public XCFromToObject @@ -367,3 +580,167 @@ class XCMarketSessionObject : public XCFromToObject }; // +// Support Zone ... +class XCSupportZoneObject : public XCZoneObject +{ + // + public: + // + + // + // Constructors ... + void XCSupportZoneObject() + { + } + + // + // Deconstructors ... + void ~XCSupportZoneObject() + { + } + + /** + * Draw Support Zone Object by Providing Support Zone ... + * + * @param chart_id: Long ... + * @param name: String ... + * @param window: Integer ... + * @param support: XOHCL instance ... + * @param time2: DateTime ... + * + * @return ( bool ) + */ + bool CreateBySupport( + long chart_id, + const string name, + const int window, + XOHCL &support, + datetime time2 // + ) + { + // + bool result = false; + + // + result = support.IsValid(); + if (!result) + { + return result; + } + + // + double bottom = support.GetDown(); + + // + result = Create( + chart_id, + name, + window, + support.time, + time2, + bottom, + bottom, + support.low, + support.low // + ); + + // + return result; + } + + /** + * Retrieve Object Type ... + * + * @return ( ENUM_XCHARTOBJECTS ) + */ + virtual ENUM_XCHARTOBJECTS Type() + { + return X_SUPPORT_ZONE; + } + + // +}; + +// +// Resistance Zone ... +class XCResistanceZoneObject : public XCZoneObject +{ + // + public: + // + + // + // Constructors ... + void XCResistanceZoneObject() + { + } + + // + // Deconstructors ... + void ~XCResistanceZoneObject() + { + } + + /** + * Draw Resistance Zone Object by Providing Resistance Zone ... + * + * @param chart_id: Long ... + * @param name: String ... + * @param window: Integer ... + * @param resistance: XOHCL instance ... + * @param time2: DateTime ... + * + * @return ( bool ) + */ + bool CreateByResistance( + long chart_id, + const string name, + const int window, + XOHCL &resistance, + datetime time2 // + ) + { + // + bool result = false; + + // + result = resistance.IsValid(); + if (!result) + { + return result; + } + + // + double up = resistance.GetUp(); + + // + result = Create( + chart_id, + name, + window, + resistance.time, + time2, + resistance.high, + resistance.high, + up, + up // + ); + + // + return result; + } + + /** + * Retrieve Object Type ... + * + * @return ( ENUM_XCHARTOBJECTS ) + */ + virtual ENUM_XCHARTOBJECTS Type() + { + return X_RESISTANCE_ZONE; + } + + // +}; + +// diff --git a/Classes/x-saherelm.x-poi.class.mq5 b/Classes/x-saherelm.x-poi.class.mq5 index 71cd35f9..2abc3af7 100644 --- a/Classes/x-saherelm.x-poi.class.mq5 +++ b/Classes/x-saherelm.x-poi.class.mq5 @@ -984,6 +984,280 @@ class XCPOI : public XSCBaseAlert mRejectionBarBearishColor = value; } + // + // Support Zone ... + + /** + * 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 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; + } + + /** + * 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 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 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; + } + + /** + * 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; + } + // // Actions ... @@ -1359,6 +1633,68 @@ class XCPOI : public XSCBaseAlert } } + // + // Support Zone ... + int supportZonesCount = ArraySize(mSupportZones); + XOHCL support; + bool hasSupport = cBar.HasSupport( + support, + SupportZonePriceType(), + SupportZoneLoopBack() // + ); + if (hasSupport) + { + // + bool isAdded = AddSupportZone(support); + if (isAdded) + { + // + supportZonesCount = ArraySize(mSupportZones); + + // + DrawSupportZones(); + + // + Add( + X_SUPPORT_ZONE_DETECTED, + state // + ); + OnSupportZoneDetected(support); + NotifySupportZoneEventListeners(support); + } + } + + // + // Resistance Zone ... + int resistanceZonesCount = ArraySize(mResistanceZones); + XOHCL resistance; + bool hasResistance = cBar.HasResistance( + resistance, + ResistanceZonePriceType(), + ResistanceZoneLoopBack() // + ); + if (hasResistance) + { + // + bool isAdded = AddResistanceZone(resistance); + if (isAdded) + { + // + resistanceZonesCount = ArraySize(mResistanceZones); + + // + DrawResistanceZones(); + + // + Add( + X_RESISTANCE_ZONE_DETECTED, + state // + ); + OnResistanceZoneDetected(resistance); + NotifyResistanceZoneEventListeners(resistance); + } + } + // // ... @@ -1384,9 +1720,11 @@ class XCPOI : public XSCBaseAlert AllowDrawSwingLows(state); AllowDrawSwingHighs(state); AllowDrawTradingDays(state); + AllowDrawSupportZones(state); AllowDrawMomentumBars(state); AllowDrawRejectionBars(state); AllowDrawMarketSessions(state); + AllowDrawResistanceZones(state); // // Sessions ... @@ -1414,9 +1752,11 @@ class XCPOI : public XSCBaseAlert AllowDrawSwingLows(state); AllowDrawSwingHighs(state); AllowDrawTradingDays(state); + AllowDrawSupportZones(state); AllowDrawMomentumBars(state); AllowDrawRejectionBars(state); AllowDrawMarketSessions(state); + AllowDrawResistanceZones(state); // // Sessions ... @@ -1553,6 +1893,20 @@ class XCPOI : public XSCBaseAlert RejectionBarBullishColor(clrAqua); RejectionBarBearishColor(clrMagenta); + // + SupportZoneLoopBack(21); + SupportZoneWidth(1); + SupportZoneColor(clrLime); + SupportZoneStyle(STYLE_DOT); + SupportZonePriceType(X_PRICE_CLOSE); + + // + ResistanceZoneLoopBack(21); + ResistanceZoneWidth(1); + ResistanceZoneColor(clrRed); + ResistanceZoneStyle(STYLE_DOT); + ResistanceZonePriceType(X_PRICE_CLOSE); + // } @@ -1715,7 +2069,7 @@ class XCPOI : public XSCBaseAlert /** * Register an Event Listener for New Rejection Bar Detected ... * - * @param listener: XOHCL instance ... + * @param listener: TXOHCLEventHandler instance ... */ void AddRejectionBarEventListener(TXOHCLEventHandler listener) { @@ -1726,6 +2080,52 @@ class XCPOI : public XSCBaseAlert ); } + /** + * Calls When new Support Zone Detected ... + * + * @param bar: XOHCL instance ... + */ + virtual void OnSupportZoneDetected(XOHCL &bar) + { + } + + /** + * Register an Event Listener for New Support Zone Detected ... + * + * @param listener: TXOHCLEventHandler instance ... + */ + void AddSupportZoneEventListener(TXOHCLEventHandler listener) + { + // + Add( + listener, + mSupportZoneEventListeners // + ); + } + + /** + * Calls When new Resistance Zone Detected ... + * + * @param bar: XOHCL instance ... + */ + virtual void OnResistanceZoneDetected(XOHCL &bar) + { + } + + /** + * Register an Event Listener for New Resistance Zone Detected ... + * + * @param listener: TXOHCLEventHandler instance ... + */ + void AddResistanceZoneEventListener(TXOHCLEventHandler listener) + { + // + Add( + listener, + mResistanceZoneEventListeners // + ); + } + // protected: // @@ -2035,6 +2435,56 @@ class XCPOI : public XSCBaseAlert } } + // + // Support Zone ... + int supportZonesCount = ArraySize(mSupportZones); + if (supportZonesCount < requiredPOIs) + { + // + XOHCL support; + bool hasSupport = cBar.HasSupport( + support, + SupportZonePriceType(), + SupportZoneLoopBack() // + ); + + // + if (hasSupport) + { + // + bool isAdded = AddSupportZone(support); + if (isAdded) + { + supportZonesCount = ArraySize(mSupportZones); + } + } + } + + // + // Resistance Zone ... + int resistanceZonesCount = ArraySize(mResistanceZones); + if (resistanceZonesCount < requiredPOIs) + { + // + XOHCL resistance; + bool hasResistance = cBar.HasResistance( + resistance, + ResistanceZonePriceType(), + ResistanceZoneLoopBack() // + ); + + // + if (hasResistance) + { + // + bool isAdded = AddResistanceZone(resistance); + if (isAdded) + { + resistanceZonesCount = ArraySize(mResistanceZones); + } + } + } + // // Detect Required Conditions for Loop ... // @@ -2054,7 +2504,10 @@ class XCPOI : public XSCBaseAlert // momentumBarsCount < requiredPOIs || // - rejectionBarsCount < requiredPOIs + rejectionBarsCount < requiredPOIs || + // + supportZonesCount < requiredPOIs || + resistanceZonesCount < requiredPOIs // ; if (canContinue) @@ -2162,6 +2615,34 @@ class XCPOI : public XSCBaseAlert ); 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); + // // ... @@ -2193,6 +2674,10 @@ class XCPOI : public XSCBaseAlert // DestroyRejectionBars(); + + // + DestroySupportZones(); + DestroyResistanceZones(); } /** @@ -2243,6 +2728,22 @@ class XCPOI : public XSCBaseAlert Clean(mMarketSessions); } + /** + * Destroy Support Zones ... + */ + void DestroySupportZones() + { + Clean(mSupportZones); + } + + /** + * Destroy Resistance Zones ... + */ + void DestroyResistanceZones() + { + Clean(mResistanceZones); + } + // // Draw Actions ... @@ -2266,6 +2767,10 @@ class XCPOI : public XSCBaseAlert // DrawRejectionBars(); + + // + DrawSupportZones(); + DrawResistanceZones(); } /** @@ -2514,6 +3019,88 @@ class XCPOI : public XSCBaseAlert } } + /** + * 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)); + int iIDX = HasObject( + iName, + mSupportZoneObjects // + ); + if (IsValidIndex(iIDX)) + { + continue; + } + + // + CreateSupportZoneObject(iSupportZone, iName); + } + } + + /** + * 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)); + int iIDX = HasObject( + iName, + mResistanceZoneObjects // + ); + if (IsValidIndex(iIDX)) + { + continue; + } + + // + CreateResistanceZoneObject(iResistanceZone, iName); + } + } + // /** @@ -2524,10 +3111,12 @@ class XCPOI : public XSCBaseAlert // DestroySwingLowObjects(); DestroySwingHighObjects(); - DestroyTradingTradingDayObjects(); DestroyMomentumBarObjects(); + DestroySupportZoneObjects(); DestroyRejectionBarObjects(); DestroyMarketSessionObjects(); + DestroyResistanceZoneObjects(); + DestroyTradingTradingDayObjects(); } /** @@ -2578,7 +3167,24 @@ class XCPOI : public XSCBaseAlert mMarketSessionObjects.Clear(); } + /** + * Destroy Support Zone Drawn Objects ... + */ + void DestroySupportZoneObjects() + { + mSupportZoneObjects.Clear(); + } + + /** + * Destroy Resistance Zone Drawn Objects ... + */ + void DestroyResistanceZoneObjects() + { + mResistanceZoneObjects.Clear(); + } + // + // ... /** * Detect an Object Exists in Array or not ... @@ -2799,6 +3405,64 @@ class XCPOI : public XSCBaseAlert } } + /** + * Notify New Support Zone Event Handlers ... + * + * @param bar: XOHCL instance ... + */ + void NotifySupportZoneEventListeners(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(bar); + } + } + + /** + * Notify New Resistance Zone Event Handlers ... + * + * @param bar: XOHCL instance ... + */ + void NotifyResistanceZoneEventListeners(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(bar); + } + } + /** * Destroy all Registered Event Listeners ... */ @@ -2809,10 +3473,16 @@ class XCPOI : public XSCBaseAlert Clean(mSwingHighEventListeners); Clean(mTradingDayEventListeners); Clean(mMomentumBarEventListeners); + Clean(mSupportZoneEventListeners); Clean(mRejectionBarEventListeners); Clean(mMarketSessionEventListeners); + Clean(mResistanceZoneEventListeners); } + // + // ... + // + // // Session ... @@ -2862,8 +3532,6 @@ class XCPOI : public XSCBaseAlert Clean(mSessions); } - // - /** * Find Specified Trade Day based on Start Time ... * @@ -3089,6 +3757,176 @@ class XCPOI : public XSCBaseAlert } // + + /** + * Add Specific Support Zone if it's Not Exists ... + * + * @param support: XOHCL instance ... + */ + bool AddSupportZone(XOHCL &support) + { + // + bool result = false; + + // + result = support.IsValid(); + if (!result) + { + return result; + } + + // + int idx = FindSupportZoneIndex(support); + result = !IsValidIndex(idx); + if (!result) + { + return result; + } + + // + int before = ArraySize(mSupportZones); + int after = AddRef( + support, + mSupportZones // + ); + + // + result = before == after - 1; + + // + return result; + } + + /** + * Find Specific Support Zone Index ... + * + * @param support: XOHCL instance ... + * + * @return ( int ) + */ + int FindSupportZoneIndex(XOHCL &support) + { + // + int result = -1; + + // + if (!support.IsValid()) + { + return result; + } + + // + int count = ArraySize(mSupportZones); + if (!IsValidSize(count)) + { + return result; + } + + // + for (int i = 0; i < count; i++) + { + // + XOHCL iSupport = mSupportZones[i]; + + // + if (iSupport.low == support.low && + iSupport.GetDown() == support.GetDown()) + { + // + result = i; + break; + } + } + + // + return result; + } + + /** + * Add Specific Resistance Zone if it's Not Exists ... + * + * @param resistance: XOHCL instance ... + */ + bool AddResistanceZone(XOHCL &resistance) + { + // + bool result = false; + + // + result = resistance.IsValid(); + if (!result) + { + return result; + } + + // + int idx = FindResistanceZoneIndex(resistance); + result = !IsValidIndex(idx); + if (!result) + { + return result; + } + + // + int before = ArraySize(mResistanceZones); + int after = AddRef( + resistance, + mResistanceZones // + ); + + // + result = before == after - 1; + + // + return result; + } + + /** + * Find Specific Resistance Zone Index ... + * + * @param resistance: XOHCL instance ... + * + * @return ( int ) + */ + int FindResistanceZoneIndex(XOHCL &resistance) + { + // + int result = -1; + + // + if (!resistance.IsValid()) + { + return result; + } + + // + int count = ArraySize(mResistanceZones); + if (!IsValidSize(count)) + { + return result; + } + + // + for (int i = 0; i < count; i++) + { + // + XOHCL iResistance = mResistanceZones[i]; + + // + if (iResistance.high == resistance.high && + iResistance.GetUp() == resistance.GetUp()) + { + // + result = i; + break; + } + } + + // + return result; + } + + // private: // @@ -3495,6 +4333,116 @@ class XCPOI : public XSCBaseAlert mRejectionBarObjects.Add(iObj); } + // + // Support Zone ... + bool mAllowDrawSupportZones; // Draw Support Zone ... + int mSupportZoneLoopBack; // Support Zone Loopback ... + int mSupportZoneWidth; // Support Zone Width ... + color mSupportZoneColor; // Support Zone Color ... + ENUM_LINE_STYLE mSupportZoneStyle; // Support Zone Style ... + ENUM_X_PRICE mSupportZonePriceType; // Support Zone Price Type ... + XOHCL mSupportZones[]; // Support Zones ... + CArrayObj mSupportZoneObjects; // Support Zone Chart Objects ... + TXOHCLEventHandler mSupportZoneEventListeners[]; // Support Zone Event Listeners ... + + /** + * Create an Object to Represent Support Zones on Chart ... + + * @param bar: XOHCL instance ... + * @param name: String ... + */ + void CreateSupportZoneObject( + XOHCL &bar, + string name // + ) + { + // + if (!bar.IsValid() || + !IsValid(name)) + { + return; + } + + // + XCSupportZoneObject *iObj; + iObj = new XCSupportZoneObject(); + bool isCreated = iObj.CreateBySupport( + ChartID(), + name, + Window(), + bar, + TimeCurrent() // + ); + if (!isCreated) + { + return; + } + + // + // Configure Object ... + iObj.ZoneColor(SupportZoneColor()); + iObj.ZoneStyle(SupportZoneStyle()); + iObj.ZoneWidth(SupportZoneWidth()); + + // + mSupportZoneObjects.Add(iObj); + } + + // + // Resistance Zone ... + bool mAllowDrawResistanceZones; // Draw Resistance Zone ... + int mResistanceZoneLoopBack; // Resistance Zone Loopback ... + int mResistanceZoneWidth; // Resistance Zone Width ... + color mResistanceZoneColor; // Resistance Zone Color ... + ENUM_LINE_STYLE mResistanceZoneStyle; // Resistance Zone Style ... + ENUM_X_PRICE mResistanceZonePriceType; // Resistance Zone Price Type ... + XOHCL mResistanceZones[]; // Resistance Zones ... + CArrayObj mResistanceZoneObjects; // Resistance Zone Chart Objects ... + TXOHCLEventHandler mResistanceZoneEventListeners[]; // Resistance Zone Event Listeners ... + + /** + * Create an Object to Represent Resistance Zones on Chart ... + + * @param bar: XOHCL instance ... + * @param name: String ... + */ + void CreateResistanceZoneObject( + XOHCL &bar, + string name // + ) + { + // + if (!bar.IsValid() || + !IsValid(name)) + { + return; + } + + // + XCResistanceZoneObject *iObj; + iObj = new XCResistanceZoneObject(); + bool isCreated = iObj.CreateByResistance( + ChartID(), + name, + Window(), + bar, + TimeCurrent() // + ); + if (!isCreated) + { + return; + } + + // + // Configure Object ... + iObj.ZoneColor(ResistanceZoneColor()); + iObj.ZoneStyle(ResistanceZoneStyle()); + iObj.ZoneWidth(ResistanceZoneWidth()); + + // + mResistanceZoneObjects.Add(iObj); + } + // }; diff --git a/Libraries/x-saherelm.x-poi.lib.mq5 b/Libraries/x-saherelm.x-poi.lib.mq5 index 385b7382..5efa2b2c 100644 --- a/Libraries/x-saherelm.x-poi.lib.mq5 +++ b/Libraries/x-saherelm.x-poi.lib.mq5 @@ -73,8 +73,8 @@ enum ENUM_XPOI_EVENTS X_SWING_LOW_DETECTED, // // Support nad Resistance ... - X_SUPPORT_DETECTED, - X_RESISTANCE_DETECTED, + X_SUPPORT_ZONE_DETECTED, // Support Zone ... + X_RESISTANCE_ZONE_DETECTED, // Resistance Zone ... }; //