From ad67a892c36fba133c042c88a233e70b940a15f7 Mon Sep 17 00:00:00 2001 From: Hadi Khazaee Asl Date: Sat, 7 Jun 2025 13:15:08 +0330 Subject: [PATCH] back up and remove all unnecessary objects ... --- Classes/x-saherelm.x-cobject.class.mq5 | 2107 +------ Classes/x-saherelm.x-poi.drawer.class.mq5 | 3564 +---------- Documents/BKP/tmp.poi.mq5 | 5385 ++++++++++++++++ Documents/BKP/x-saherelm.x-cobject.class.mq5 | 3478 +++++++++++ .../BKP/x-saherelm.x-poi.drawer.class.mq5 | 4384 ++++++++++++++ .../BKP/x-saherelm.x-poi.extensions.lib.mq5 | 3804 ++++++++++++ .../BKP}/x-saherelm.x-poi.state.lib.mq5 | 0 Libraries/x-saherelm.x-poi.extensions.lib.mq5 | 1482 ----- Libraries/x-saherelm.x-poi.lib.mq5 | 5388 +---------------- XCATBEA/Classes/xcatbea.signaller.class.mq5 | 47 +- 10 files changed, 17181 insertions(+), 12458 deletions(-) create mode 100644 Documents/BKP/tmp.poi.mq5 create mode 100644 Documents/BKP/x-saherelm.x-cobject.class.mq5 create mode 100644 Documents/BKP/x-saherelm.x-poi.drawer.class.mq5 create mode 100644 Documents/BKP/x-saherelm.x-poi.extensions.lib.mq5 rename {Libraries => Documents/BKP}/x-saherelm.x-poi.state.lib.mq5 (100%) diff --git a/Classes/x-saherelm.x-cobject.class.mq5 b/Classes/x-saherelm.x-cobject.class.mq5 index 91cc37c0..8d012cfb 100644 --- a/Classes/x-saherelm.x-cobject.class.mq5 +++ b/Classes/x-saherelm.x-cobject.class.mq5 @@ -38,36 +38,12 @@ enum ENUM_XCHARTOBJECTS { // // Global ... - X_ZONE_OBJ = 7860, X_BOX_OBJ = 7861, X_BAR_ARROW_OBJ = 7862, // X_SIGNAL_OBJ = 8860, - X_TREND_OBJ = 8861, - X_XPVPIVOT_OBJ = 8862, X_OHCL_OBJ = 8863, X_RR_OBJ = 8864, - // - // 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, - X_TICK_ZONE_OBJ = 9876, - X_TICKS_ZONE_OBJ = 9877, - X_CONSOLIDATION_ZONE_OBJ = 9878, }; enum ENUM_X_CHART_IDS @@ -155,6 +131,48 @@ string ToString(ENUM_X_CHART_IDS value) return result; } +struct XPOIStyle +{ + // + // Properties ... + int width; + color clr; + ENUM_LINE_STYLE style; + + // + // Constructor ... + XPOIStyle() + { + Default(); + } + + // + // Tools ... + + // + // Cleanup Model ... + void Clean() + { + // + width = 1; + clr = CLR_NONE; + style = STYLE_SOLID; + + // + ZeroMemory(this); + } + + // + // Default Props ... + void Default() + { + // + width = 1; + clr = CLR_NONE; + style = STYLE_SOLID; + } +}; + // // Extensions ... @@ -542,1442 +560,6 @@ class XCBarArrowObject : public XCBaseObject // }; -// -// Swing ... -class XCSwingObject : public XCBarArrowObject -{ - // - public: - // - - /** - * Creator ... - * - * @param chart_id: Long, Specified Chart ID ... - * @param window: Integer, Specified Chart Window ID ... - * @param swing: XCSwing instance ... - * @param prefix: String ... - * - * @return ( bool ) - */ - bool CreateBySwing( - long chart_id, - int window, - int arrow, - XCSwing &swing, - string prefix = NULL // - ) - { - // - bool result = false; - - // - result = - // - swing.IsValid() - // - ; - if (!result) - { - return result; - } - - // - string name = swing.GetTag(); - if (IsValid(prefix)) - { - name = prefix + "_" + name; - } - - // - XOHCL bar; - result = swing.FillBar(bar); - if (!result) - { - return result; - } - - // - ENUM_X_PRICE price = swing.IsSwingHigh() - ? X_PRICE_HIGH - : X_PRICE_LOW; - - // - result = CreateByBar( - chart_id, - name, - window, - arrow, - bar, - price // - ); - - // - if (result) - { - ObjName(name); - } - - // - return result; - } -}; - -// -// Swing High ... -class XCSwingHighObject : public XCSwingObject -{ - // - public: - // - - /** - * Creator ... - * - * @param chart_id: Long, Specified Chart ID ... - * @param window: Integer, Specified Chart Window ID ... - * @param arrow: Integer, Specified Arrow Code ... - * @param swing: XCSwing instance ... - * @param prefix: String ... - * - * @return ( bool ) - */ - bool Create( - long chart_id, - int window, - int arrow, - XCSwing &swing, - string prefix = NULL // - ) - { - // - bool result = false; - - // - result = swing.IsValid() && - swing.IsSwingHigh(); - if (!result) - { - return result; - } - - // - result = CreateBySwing( - chart_id, - window, - arrow, - swing, - prefix // - ); - - // - 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 arrow: Integer, Specified Arrow Code ... - * @param swing: XCSwing instance ... - * @param prefix: String ... - * - * @return ( bool ) - */ - bool Create( - long chart_id, - int window, - int arrow, - XCSwing &swing, - string prefix = NULL // - ) - { - // - bool result = false; - - // - result = swing.IsValid() && - swing.IsSwingLow(); - if (!result) - { - return result; - } - - // - result = CreateBySwing( - chart_id, - window, - arrow, - swing, - prefix // - ); - - // - return result; - } - - /** - * Retrieve Object Type ... - * - * @return ( ENUM_XCHARTOBJECTS ) - */ - virtual ENUM_XCHARTOBJECTS Type() - { - return X_SWING_LOW_OBJ; - } - - // -}; - -// -// Momentum ... -class XCMomentumBarObject : public XCBarArrowObject -{ - // - public: - // - - /** - * Creator ... - * - * @param chart_id: Long, Specified Chart ID ... - * @param window: Integer, Specified Chart Window ID ... - * @param momentumBar: XCMomentumBar instance ... - * @param prefix: String ... - * - * @return ( bool ) - */ - bool CreateByMomentum( - long chart_id, - int window, - int arrow, - XCMomentumBar &momentumBar, - string prefix = NULL // - ) - { - // - bool result = false; - - // - result = - // - momentumBar.IsValid() - // - ; - if (!result) - { - return result; - } - - // - string name = momentumBar.GetTag(); - if (IsValid(prefix)) - { - name = prefix + "_" + name; - } - - // - XOHCL bar; - result = momentumBar.FillBar(bar); - if (!result) - { - return result; - } - - // - ENUM_X_PRICE price = momentumBar.IsBullish() - ? X_PRICE_LOW - : X_PRICE_HIGH; - - // - result = CreateByBar( - chart_id, - name, - window, - arrow, - bar, - price // - ); - - // - if (result) - { - ObjName(name); - } - - // - return result; - } -}; - -// -// Bullish Momentum Bar ... -class XCBullishMomentumBarObject : public XCMomentumBarObject -{ - // - public: - // - - /** - * Creator ... - * - * @param chart_id: Long, Specified Chart ID ... - * @param window: Integer, Specified Chart Window ID ... - * @param arrow: Integer, Specified Arrow Code ... - * @param momentumBar: XCMomentumBar instance ... - * @param prefix: String ... - * - * @return ( bool ) - */ - bool Create( - long chart_id, - int window, - int arrow, - XCMomentumBar &momentumBar, - string prefix = NULL // - ) - { - // - bool result = false; - - // - result = momentumBar.IsValid() && - momentumBar.IsBullish(); - if (!result) - { - return result; - } - - // - result = CreateByMomentum( - chart_id, - window, - arrow, - momentumBar, - prefix // - ); - - // - return result; - } - - /** - * Retrieve Object Type ... - * - * @return ( ENUM_XCHARTOBJECTS ) - */ - virtual ENUM_XCHARTOBJECTS Type() - { - return X_BULLISH_MOMENTUM_BAR_OBJ; - } - - // -}; - -// -// Bearish Momentum Bar ... -class XCBearishMomentumBarObject : public XCMomentumBarObject -{ - // - public: - // - - /** - * Creator ... - * - * @param chart_id: Long, Specified Chart ID ... - * @param window: Integer, Specified Chart Window ID ... - * @param arrow: Integer, Specified Arrow Code ... - * @param momentumBar: XCMomentumBar instance ... - * @param prefix: String ... - * - * @return ( bool ) - */ - bool Create( - long chart_id, - int window, - int arrow, - XCMomentumBar &momentumBar, - string prefix = NULL // - ) - { - // - bool result = false; - - // - result = momentumBar.IsValid() && - momentumBar.IsBearish(); - if (!result) - { - return result; - } - - // - result = CreateByMomentum( - chart_id, - window, - arrow, - momentumBar, - prefix // - ); - - // - return result; - } - - /** - * Retrieve Object Type ... - * - * @return ( ENUM_XCHARTOBJECTS ) - */ - virtual ENUM_XCHARTOBJECTS Type() - { - return X_BEARISH_MOMENTUM_BAR_OBJ; - } - - // -}; - -// -// Rejection ... -class XCRejectionBarObject : public XCBarArrowObject -{ - // - public: - // - - /** - * Creator ... - * - * @param chart_id: Long, Specified Chart ID ... - * @param window: Integer, Specified Chart Window ID ... - * @param rejectionBar: XCRejectionBar instance ... - * @param prefix: String ... - * - * @return ( bool ) - */ - bool CreateByRejection( - long chart_id, - int window, - int arrow, - XCRejectionBar &rejectionBar, - string prefix = NULL // - ) - { - // - bool result = false; - - // - result = - // - rejectionBar.IsValid() - // - ; - if (!result) - { - return result; - } - - // - string name = rejectionBar.GetTag(); - if (IsValid(prefix)) - { - name = prefix + "_" + name; - } - - // - XOHCL bar; - result = rejectionBar.FillBar(bar); - if (!result) - { - return result; - } - - // - ENUM_X_PRICE price = rejectionBar.IsBullish() - ? X_PRICE_LOW - : X_PRICE_HIGH; - - // - result = CreateByBar( - chart_id, - name, - window, - arrow, - bar, - price // - ); - - // - if (result) - { - ObjName(name); - } - - // - return result; - } -}; - -// -// Bullish Rejection Bar ... -class XCBullishRejectionBarObject : public XCRejectionBarObject -{ - // - public: - // - - /** - * Creator ... - * - * @param chart_id: Long, Specified Chart ID ... - * @param window: Integer, Specified Chart Window ID ... - * @param arrow: Integer, Specified Arrow Code ... - * @param rejectionBar: XCRejectionBar instance ... - * @param prefix: String ... - * - * @return ( bool ) - */ - bool Create( - long chart_id, - int window, - int arrow, - XCRejectionBar &rejectionBar, - string prefix = NULL // - ) - { - // - bool result = false; - - // - result = rejectionBar.IsValid() && - rejectionBar.IsBullish(); - if (!result) - { - return result; - } - - // - result = CreateByRejection( - chart_id, - window, - arrow, - rejectionBar, - prefix // - ); - - // - return result; - } - - /** - * Retrieve Object Type ... - * - * @return ( ENUM_XCHARTOBJECTS ) - */ - virtual ENUM_XCHARTOBJECTS Type() - { - return X_BULLISH_REJECTION_BAR_OBJ; - } - - // -}; - -// -// Bearish Rejection Bar ... -class XCBearishRejectionBarObject : public XCRejectionBarObject -{ - // - public: - // - - /** - * Creator ... - * - * @param chart_id: Long, Specified Chart ID ... - * @param window: Integer, Specified Chart Window ID ... - * @param arrow: Integer, Specified Arrow Code ... - * @param rejectionBar: XCRejectionBar instance ... - * @param prefix: String ... - * - * @return ( bool ) - */ - bool Create( - long chart_id, - int window, - int arrow, - XCRejectionBar &rejectionBar, - string prefix = NULL // - ) - { - // - bool result = false; - - // - result = rejectionBar.IsValid() && - rejectionBar.IsBearish(); - if (!result) - { - return result; - } - - // - result = CreateByRejection( - chart_id, - window, - arrow, - rejectionBar, - prefix // - ); - - // - return result; - } - - /** - * Retrieve Object Type ... - * - * @return ( ENUM_XCHARTOBJECTS ) - */ - virtual ENUM_XCHARTOBJECTS Type() - { - return X_BEARISH_REJECTION_BAR_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 ... - * @param prefix: String ... - * - * @return ( bool ) - */ - bool CreateByZone( - long chart_id, - string name, - int window, - XCZone &zone, - string prefix = NULL // - ) - { - // - bool result = false; - - // - bool isValidFrom = zone.IsValidFrom(); - bool isValidBoundary = zone.IsValidBoundary(); - - // - result = - // - IsValid(name) && - isValidFrom && - isValidBoundary - // - ; - if (!result) - { - return result; - } - - // - if (IsValid(prefix)) - { - name = prefix + "_" + name; - } - - // - datetime from = zone.From(); - datetime to = NormalizeTime(zone.To()); - - // - double upper = zone.Upper(); - double lower = zone.Lower(); - - // - result = mRect.Create( - chart_id, - name, - window, - from, - upper, - to, - 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); - } - - /** - * Set Zone Fill ... - * - * @param value: Boolean ... - */ - void ZoneFill(bool value) - { - mRect.Fill(value); - } - - // - private: - // - CChartObjectRectangle mRect; - - // -}; - -// -// Support Zone ... -class XCSupportZoneObject : public XCZoneObject -{ - // - public: - // - - /** - * Creator ... - * - * @param chart_id: Long, Specified Chart ID ... - * @param window: Integer, Specified Chart Window ID ... - * @param zone: XCSupportZone instance ... - * @param prefix: String ... - * - * @return ( bool ) - */ - bool Create( - long chart_id, - int window, - XCSupportZone &zone, - string prefix = NULL // - ) - { - // - bool result = false; - - // - result = zone.IsValid(); - if (!result) - { - return result; - } - - // - string name = zone.GetTag(); - - // - result = CreateByZone( - chart_id, - name, - window, - zone, - prefix // - ); - - // - return result; - } - - // - // Virtual ... - - /** - * Retrieve Object Type ... - * - * @return ( ENUM_XCHARTOBJECTS ) - */ - virtual ENUM_XCHARTOBJECTS Type() - { - return X_SUPPORT_ZONE_OBJ; - } -}; - -// -// Resistance Zone ... -class XCResistanceZoneObject : public XCZoneObject -{ - // - public: - // - - /** - * Creator ... - * - * @param chart_id: Long, Specified Chart ID ... - * @param window: Integer, Specified Chart Window ID ... - * @param zone: XCResistanceZone instance ... - * @param prefix: String ... - * - * @return ( bool ) - */ - bool Create( - long chart_id, - int window, - XCResistanceZone &zone, - string prefix = NULL // - ) - { - // - bool result = false; - - // - result = zone.IsValid(); - if (!result) - { - return result; - } - - // - string name = zone.GetTag(); - - // - result = CreateByZone( - chart_id, - name, - window, - zone, - prefix // - ); - - // - return result; - } - - // - // Virtual ... - - /** - * Retrieve Object Type ... - * - * @return ( ENUM_XCHARTOBJECTS ) - */ - virtual ENUM_XCHARTOBJECTS Type() - { - return X_RESISTANCE_ZONE_OBJ; - } -}; - -// -// Supply Zone ... -class XCSupplyZoneObject : public XCZoneObject -{ - // - public: - // - - /** - * Creator ... - * - * @param chart_id: Long, Specified Chart ID ... - * @param window: Integer, Specified Chart Window ID ... - * @param zone: XCSupplyZone instance ... - * @param prefix: String ... - * - * @return ( bool ) - */ - bool Create( - long chart_id, - int window, - XCSupplyZone &zone, - string prefix = NULL // - ) - { - // - bool result = false; - - // - result = zone.IsValid(); - if (!result) - { - return result; - } - - // - string name = zone.GetTag(); - - // - result = CreateByZone( - chart_id, - name, - window, - zone, - prefix // - ); - - // - return result; - } - - // - // Virtual ... - - /** - * Retrieve Object Type ... - * - * @return ( ENUM_XCHARTOBJECTS ) - */ - virtual ENUM_XCHARTOBJECTS Type() - { - return X_SUPPLY_ZONE_OBJ; - } -}; - -// -// Demand Zone ... -class XCDemandZoneObject : public XCZoneObject -{ - // - public: - // - - /** - * Creator ... - * - * @param chart_id: Long, Specified Chart ID ... - * @param window: Integer, Specified Chart Window ID ... - * @param zone: XCDemandZone instance ... - * @param prefix: String ... - * - * @return ( bool ) - */ - bool Create( - long chart_id, - int window, - XCDemandZone &zone, - string prefix = NULL // - ) - { - // - bool result = false; - - // - result = zone.IsValid(); - if (!result) - { - return result; - } - - // - string name = zone.GetTag(); - - // - result = CreateByZone( - chart_id, - name, - window, - zone, - prefix // - ); - - // - return result; - } - - // - // Virtual ... - - /** - * Retrieve Object Type ... - * - * @return ( ENUM_XCHARTOBJECTS ) - */ - virtual ENUM_XCHARTOBJECTS Type() - { - return X_DEMAND_ZONE_OBJ; - } -}; - -// -// Bullish Order Block ... -class XCBullishOrderBlockObject : public XCZoneObject -{ - // - public: - // - - /** - * Creator ... - * - * @param chart_id: Long, Specified Chart ID ... - * @param window: Integer, Specified Chart Window ID ... - * @param zone: XCOrderBlock instance ... - * @param prefix: String ... - * - * @return ( bool ) - */ - bool Create( - long chart_id, - int window, - XCOrderBlock &zone, - string prefix = NULL // - ) - { - // - bool result = false; - - // - result = zone.IsValid() && - zone.IsBullish(); - if (!result) - { - return result; - } - - // - string name = zone.GetTag(); - - // - result = CreateByZone( - chart_id, - name, - window, - zone, - prefix // - ); - - // - return result; - } - - // - // Virtual ... - - /** - * Retrieve Object Type ... - * - * @return ( ENUM_XCHARTOBJECTS ) - */ - virtual ENUM_XCHARTOBJECTS Type() - { - return X_BULLISH_ORDERBLOCK_OBJ; - } -}; - -// -// Bearish Order Block ... -class XCBearishOrderBlockObject : public XCZoneObject -{ - // - public: - // - - /** - * Creator ... - * - * @param chart_id: Long, Specified Chart ID ... - * @param window: Integer, Specified Chart Window ID ... - * @param zone: XCOrderBlock instance ... - * @param prefix: String ... - * - * @return ( bool ) - */ - bool Create( - long chart_id, - int window, - XCOrderBlock &zone, - string prefix = NULL // - ) - { - // - bool result = false; - - // - result = zone.IsValid() && - zone.IsBearish(); - if (!result) - { - return result; - } - - // - string name = zone.GetTag(); - - // - result = CreateByZone( - chart_id, - name, - window, - zone, - prefix // - ); - - // - return result; - } - - // - // Virtual ... - - /** - * Retrieve Object Type ... - * - * @return ( ENUM_XCHARTOBJECTS ) - */ - virtual ENUM_XCHARTOBJECTS Type() - { - return X_BULLISH_ORDERBLOCK_OBJ; - } -}; - -// -// Bullish Fair Value Gaps ... -class XCBullishFairValueGapObject : public XCZoneObject -{ - // - public: - // - - /** - * Creator ... - * - * @param chart_id: Long, Specified Chart ID ... - * @param window: Integer, Specified Chart Window ID ... - * @param zone: XCOrderBlock instance ... - * @param prefix: String ... - * - * @return ( bool ) - */ - bool Create( - long chart_id, - int window, - XCFVG &zone, - string prefix = NULL // - ) - { - // - bool result = false; - - // - result = zone.IsValid() && - zone.IsBullish(); - if (!result) - { - return result; - } - - // - string name = zone.GetTag(); - - // - result = CreateByZone( - chart_id, - name, - window, - zone, - prefix // - ); - - // - return result; - } - - // - // Virtual ... - - /** - * Retrieve Object Type ... - * - * @return ( ENUM_XCHARTOBJECTS ) - */ - virtual ENUM_XCHARTOBJECTS Type() - { - return X_BULLISH_FVG_OBJ; - } -}; - -class XCConsolidationZoneObject : public XCBaseObject -{ - // - public: - // - - /** - * Creator ... - * - * @param chart_id: Long, Specified Chart ID ... - * @param window: Integer, Specified Chart Window ID ... - * @param zone: XConsolidationZone instance ... - * @param prefix: String ... - * - * @return ( bool ) - */ - bool Create( - long chart_id, - int window, - XConsolidationZone &zone, - string prefix = NULL // - ) - { - // - bool result = false; - - // - result = zone.IsValid(); - if (!result) - { - return result; - } - - // - string name = zone.GetTag(); - if (IsValid(prefix)) - { - name = prefix + "_" + name; - } - - // - result = mRect.Create( - chart_id, - name, - window, - zone.from, - zone.upper, - zone.to, - zone.lower // - ); - - // - if (result) - { - ObjName(name); - } - - // - return result; - } - - // - // Virtual ... - - /** - * Retrieve Object Type ... - * - * @return ( ENUM_XCHARTOBJECTS ) - */ - virtual ENUM_XCHARTOBJECTS Type() - { - return X_CONSOLIDATION_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); - } - - /** - * Set Zone Fill ... - * - * @param value: Boolean ... - */ - void ZoneFill(bool value) - { - mRect.Fill(value); - } - - // - private: - // - CChartObjectRectangle mRect; - - // -}; - -// -// Bearish Fair Value Gaps ... -class XCBearishFairValueGapObject : public XCZoneObject -{ - // - public: - // - - /** - * Creator ... - * - * @param chart_id: Long, Specified Chart ID ... - * @param window: Integer, Specified Chart Window ID ... - * @param zone: XCOrderBlock instance ... - * @param prefix: String ... - * - * @return ( bool ) - */ - bool Create( - long chart_id, - int window, - XCFVG &zone, - string prefix = NULL // - ) - { - // - bool result = false; - - // - result = zone.IsValid() && - zone.IsBearish(); - if (!result) - { - return result; - } - - // - string name = zone.GetTag(); - - // - result = CreateByZone( - chart_id, - name, - window, - zone, - prefix // - ); - - // - return result; - } - - // - // Virtual ... - - /** - * Retrieve Object Type ... - * - * @return ( ENUM_XCHARTOBJECTS ) - */ - virtual ENUM_XCHARTOBJECTS Type() - { - return X_BEARISH_FVG_OBJ; - } -}; - // // Signal ... class XCSignalObject : public XCBaseObject @@ -2870,609 +1452,4 @@ class XCBoxObject : public XCBaseObject CChartObjectRectangle mRect; }; -// -// Zone Ticks ... - -// -// Specify How to Draws Specified Levels ... -struct XTickZoneLevelSpecs -{ - // - double percent; // Max Allowed Percent of Tick Zone ... - - // - // Label Info ... - color labelColor; - string labelFont; - int labelFontSize; - double labelAngel; - - // - // Zone Info ... - bool zoneFill; - int zoneWidth; - color zoneColor; - ENUM_LINE_STYLE zoneStyle; - - // - // Constructor ... - XTickZoneLevelSpecs() - { - Default(); - } - - // - // Tools ... - - /** - * Initialize Drawing Specs ... - * - * @param _percent: Double, Max Allowed Percent ... - * @param _labelColor: Color, Specified Label Color ... - * @param _zoneColoe: Color, Specified Zone Color ... - * @param _zoneFill: Boolean, Specified Fill Zone or not ... - * @param _zoneStyle: ENUM_LINE_STYLE member, Specified Zone Style ... - * @param _labelFontSize: Integer, Specified Label Font Size ... - * @param _labelFont: String, Specified Label Font Name ... - * @param _labelAngel: Double, Specified Label Angel ... - * - * @return ( bool ) - */ - bool Init( - double _percent, - color _labelColor = clrWhite, - color _zoneColor = clrWhite, - bool _zoneFill = false, - ENUM_LINE_STYLE _zoneStyle = STYLE_DOT, - int _zoneWidth = 1, - int _labelFontSize = 12, - string _labelFont = "Arial", - double _labelAngel = 0 // - ) - { - // - bool result = false; - - // - Default(); - - // - result = _percent > 0; - if (!result) - { - return result; - } - - // - percent = _percent; - labelColor = _labelColor; - zoneColor = _zoneColor; - zoneFill = _zoneFill; - zoneStyle = _zoneStyle; - - // - if (_zoneWidth > 0) - { - zoneWidth = _zoneWidth; - } - - // - if (_labelFontSize > 0) - { - labelFontSize = _labelFontSize; - } - - // - if (IsSpecifiedValid(_labelFont)) - { - labelFont = _labelFont; - } - - // - if (_labelAngel >= 0) - { - labelAngel = _labelAngel; - } - - // - result = IsValid(); - - // - return result; - } - - /** - * Set Default Properties ... - */ - void Default() - { - // - percent = 0; - - // - // Label ... - labelAngel = 0; - labelFontSize = 13; - labelFont = "Arial"; - labelColor = clrWhite; - - // - // Zone ... - zoneWidth = 1; - zoneFill = false; - zoneColor = clrWhite; - zoneStyle = STYLE_DOT; - } - - /** - * Validate ... - * - * @return ( bool ) - */ - bool IsValid() - { - // - bool result = false; - - // - result = - // - percent > 0 && - // - // Zone ... - zoneWidth > 0 && - // - // Label ... - labelFontSize > 0 && - IsSpecifiedValid(labelFont) - // - ; - - // - return result; - } - - // -}; - -class XCTickZoneObject : public XCBaseObject -{ - // - public: - // - - /** - * Creator ... - * - * @param chart_id: Long, Specified Chart ID ... - * @param window: Integer, Specified Chart Window ID ... - * @param name: String, Specify Chart Object Identifier ... - * @param from: Datetime ... - * @param to: Datetime ... - * @param zone: XCTickZone instance ... - * @param prefix: String ... - * - * @return ( bool ) - */ - bool Create( - long chart_id, - int window, - string name, - datetime from, - datetime to, - XCTickZone *zone, - string prefix = NULL // - ) - { - // - bool result = false; - - // - result = - IsValid(name) && - zone.IsValid() && - IsValid(to) && - IsValid(from); - if (!result) - { - return result; - } - - // - double points = GetPoints(zone.symbol); - if (points <= 0) - { - points = 1; - } - double distance = 1 * points; - - // - if (IsValid(prefix)) - { - name = prefix + "_" + name; - } - - // - string rectName = "TKZ_" + name; - result = mRect.Create( - chart_id, - rectName, - window, - from, - zone.high, - to, - zone.low // - ); - if (!result) - { - return result; - } - - // - int fromToDiff = ((int)to - (int)from); - datetime labelsDate = (datetime)((int)to - (fromToDiff / 5)); - - // - string lblName = "LBLT_" + name; - result = mTLabel.Create( - chart_id, - lblName, - window, - labelsDate, - zone.high - distance // - ); - if (!result) - { - return result; - } - - // - mTLabel.Description("T: " + ToString(zone.percent) + "%"); - - // - string lblVName = "LBLV_" + name; - result = mVLabel.Create( - chart_id, - lblVName, - window, - labelsDate, - zone.low + (2.5 * distance) // - ); - if (!result) - { - return result; - } - - // - mVLabel.Description("V: " + ToString(zone.volumePercent) + "%"); - - // - ObjName(name); - - // - return result; - } - - // - // Virtual ... - - /** - * Retrieve Object Type ... - * - * @return ( ENUM_XCHARTOBJECTS ) - */ - virtual ENUM_XCHARTOBJECTS Type() - { - return X_TICK_ZONE_OBJ; - } - - // - // Getter(s) / 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); - } - - /** - * Set Zone Fill ... - * - * @param value: Boolean ... - */ - void ZoneFill(bool value) - { - mRect.Fill(value); - } - - /** - * Set Label Color ... - * - * @param value: Color ... - */ - void LabelColor(color value) - { - // - mTLabel.Color(value); - mVLabel.Color(value); - } - - /** - * Set Label Size ... - * - * @param value: Integer ... - */ - void LabelSize(int value) - { - // - mTLabel.FontSize(value); - mVLabel.FontSize(value); - } - - /** - * Set Label Font ... - * - * @param value: String ... - */ - void LabelFont(string value) - { - // - mTLabel.Font(value); - mVLabel.Font(value); - } - - /** - * Set Label Angle ... - * - * @param value: double ... - */ - void LabelAngle(double value) - { - // - mTLabel.Angle(value); - mVLabel.Angle(value); - } - - // - private: - // - // Props ... - CChartObjectRectangle mRect; - CChartObjectLabel mTLabel; - CChartObjectLabel mVLabel; - - // -}; -class XCTicksZoneObject : public XCBaseObject -{ - // - public: - // - - // - void ~XCTicksZoneObject() - { - mZones.Clear(); - } - - /** - * Creator ... - * - * @param chart_id: Long, Specified Chart ID ... - * @param window: Integer, Specified Chart Window ID ... - * @param zone: XCTicksZone instance ... - * @param prefix: String ... - * - * @return ( bool ) - */ - bool Create( - long chart_id, - int window, - XCTicksZone &zone, - XTickZoneLevelSpecs &specs[], - string prefix = NULL // - ) - { - // - bool result = false; - - // - result = zone.IsValid(); - if (!result) - { - return result; - } - - // - string name = zone.GetTag(); - int levels = zone.Levels(); - result = levels > 0; - if (!result) - { - return result; - } - - // - for (int i = 0; i < levels; i++) - { - // - XCTickZone *iZone = zone.GetZone(i); - XCTickZoneObject *iObj; - iObj = new XCTickZoneObject(); - bool isCreated = iObj.Create( - chart_id, - window, - ToString(i) + "_" + name, - zone.From(), - zone.To(), - iZone, - prefix // - ); - if (!isCreated) - { - break; - } - - // - XTickZoneLevelSpecs iSpec; - bool hasSpecs = FindSpecs( - iZone, - iSpec, - specs // - ); - if (hasSpecs) - { - // - // Label ... - iObj.LabelFont(iSpec.labelFont); - iObj.LabelAngle(iSpec.labelAngel); - iObj.LabelColor(iSpec.labelColor); - iObj.LabelSize(iSpec.labelFontSize); - - // - // Zone ... - iObj.ZoneFill(iSpec.zoneFill); - iObj.ZoneColor(iSpec.zoneColor); - iObj.ZoneWidth(iSpec.zoneWidth); - iObj.ZoneStyle(iSpec.zoneStyle); - } - - // - mZones.Add(iObj); - } - - // - if (result) - { - ObjName(name); - } - else - { - mZones.Clear(); - } - - // - return result; - } - - // - // Virtual ... - - /** - * Retrieve Object Type ... - * - * @return ( ENUM_XCHARTOBJECTS ) - */ - virtual ENUM_XCHARTOBJECTS Type() - { - return X_TICKS_ZONE_OBJ; - } - - // - // Getter(s) / Setter(s) ... - - // - // Actions ... - - /** - * Destroy Object ... - */ - void Destroy() - { - mZones.Clear(); - } - - /** - * Find Specified TickZone Drawing Specs ... - * - * @param zone: XCTickZone instance, reference to Search For it ... - * @param spec: XTickZoneLevelSpecs instance, reference to Result ... - * @param specs: XTickZoneLevelSpecs instance Collection for Search ... - * - * @return ( bool ) - */ - bool FindSpecs( - XCTickZone *zone, - XTickZoneLevelSpecs &spec, - XTickZoneLevelSpecs &specs[] // - ) - { - // - bool result = false; - - // - int count = ArraySize(specs); - result = - zone.IsValid() && - IsValidSize(count); - if (!result) - { - return result; - } - - // - for (int i = 0; i < count; i++) - { - // - XTickZoneLevelSpecs iSpecs = specs[i]; - - // - bool isSpecValidForZone = - !spec.IsValid() - ? zone.percent <= iSpecs.percent - : zone.percent <= iSpecs.percent && - spec.percent > iSpecs.percent; - if (isSpecValidForZone) - { - spec = iSpecs; - } - } - - // - result = spec.IsValid(); - - // - return result; - } - - // - private: - // - // Props ... - CArrayObj mZones; - - // -}; - // \ No newline at end of file diff --git a/Classes/x-saherelm.x-poi.drawer.class.mq5 b/Classes/x-saherelm.x-poi.drawer.class.mq5 index 2fe2d02c..5e0a8c71 100644 --- a/Classes/x-saherelm.x-poi.drawer.class.mq5 +++ b/Classes/x-saherelm.x-poi.drawer.class.mq5 @@ -24,7 +24,6 @@ #include "../Classes/x-saherelm.base.class.mq5" #include "../Classes/x-saherelm.x-cobject.class.mq5" #include "../Libraries/x-saherelm.x-poi.extensions.lib.mq5" -#include "../Libraries/x-saherelm.x-poi.state.lib.mq5" // // Definitions ... @@ -59,6 +58,15 @@ class XCPOIDrawer : public XCBase // public: // + // Props ... + + // + XPOIStyle defaultBullishStyle; + XPOIStyle defaultBearishStyle; + + // + XPOIStyle boxBullishStyle; + XPOIStyle boxBearishStyle; // // Constructor ... @@ -73,7 +81,10 @@ class XCPOIDrawer : public XCBase void ~XCPOIDrawer() { // - Clean(mTicksZoneSpecs); + boxBullishStyle.Clean(); + boxBearishStyle.Clean(); + defaultBullishStyle.Clean(); + defaultBearishStyle.Clean(); } // @@ -343,1152 +354,6 @@ class XCPOIDrawer : public XCBase mBarLowShadowStyle = 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) - { - mBullishFVGFill = 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; - } - // // Virtuals ... @@ -1517,1386 +382,23 @@ class XCPOIDrawer : public XCBase BarHighShadowStyle(STYLE_DOT); // - int arrowWidth = 1; + defaultBullishStyle.width = 1; + defaultBullishStyle.clr = clrLime; + defaultBullishStyle.style = STYLE_SOLID; // - SwingLowArrow(108); - SwingLowColor(clrAqua); - SwingLowWidth(arrowWidth); - - // - SwingHighArrow(108); - SwingHighWidth(arrowWidth); - SwingHighColor(clrMagenta); - - // - arrowWidth++; - - // - BullishMomentumBarArrow(225); - BullishMomentumBarWidth(arrowWidth); - BullishMomentumBarColor(clrAqua); - - // - BearishMomentumBarArrow(226); - BearishMomentumBarWidth(arrowWidth); - BearishMomentumBarColor(clrMagenta); - - // - arrowWidth++; - - // - BullishRejectionBarArrow(217); - BullishRejectionBarWidth(arrowWidth); - BullishRejectionBarColor(clrAqua); - - // - BearishRejectionBarArrow(218); - BearishRejectionBarWidth(arrowWidth); - BearishRejectionBarColor(clrMagenta); - - // - SupportZoneFill(false); - SupportZoneWidth(1); - SupportZoneStyle(STYLE_DOT); - SupportZoneColor(clrLime); - - // - ResistanceZoneFill(false); - ResistanceZoneWidth(1); - ResistanceZoneStyle(STYLE_DOT); - ResistanceZoneColor(clrRed); - - // - SupplyZoneFill(false); - SupplyZoneWidth(1); - SupplyZoneStyle(STYLE_DOT); - SupplyZoneColor(clrRed); - - // - DemandZoneFill(false); - DemandZoneWidth(1); - DemandZoneStyle(STYLE_DOT); - DemandZoneColor(clrGreen); - - // - BullishOrderBlockFill(false); - BullishOrderBlockWidth(1); - BullishOrderBlockStyle(STYLE_DASHDOT); - BullishOrderBlockColor(clrLime); - - // - BearishOrderBlockFill(false); - BearishOrderBlockWidth(1); - BearishOrderBlockStyle(STYLE_DASHDOT); - BearishOrderBlockColor(clrRed); - - // - BullishFVGFill(false); - BullishFVGWidth(1); - BullishFVGStyle(STYLE_DOT); - BullishFVGColor(clrLime); - - // - BearishFVGFill(false); - BearishFVGWidth(1); - BearishFVGStyle(STYLE_DOT); - BearishFVGColor(clrRed); - - // - // Add Default TickZone Specs ... - bool isSpecsInited = false; - bool fillTickZone = false; - XTickZoneLevelSpecs specs10; - isSpecsInited = specs10.Init( - 10, - clrWhite, - clrWhite, - fillTickZone // - ); - if (isSpecsInited) - { - AddTickZoneLevelSpecs(specs10); - } - - // - XTickZoneLevelSpecs specs20; - isSpecsInited = specs20.Init( - 20, - clrOrange, - clrOrange, - fillTickZone // - ); - if (isSpecsInited) - { - AddTickZoneLevelSpecs(specs20); - } - - // - XTickZoneLevelSpecs specs30; - isSpecsInited = specs30.Init( - 30, - clrOrange, - clrOrange, - fillTickZone // - ); - if (isSpecsInited) - { - AddTickZoneLevelSpecs(specs30); - } - - // - XTickZoneLevelSpecs specs40; - isSpecsInited = specs40.Init( - 40, - clrOrange, - clrOrange, - fillTickZone // - ); - if (isSpecsInited) - { - AddTickZoneLevelSpecs(specs40); - } - - // - XTickZoneLevelSpecs specs50; - isSpecsInited = specs50.Init( - 50, - clrYellow, - clrYellow, - fillTickZone // - ); - if (isSpecsInited) - { - AddTickZoneLevelSpecs(specs50); - } - - // - XTickZoneLevelSpecs specs60; - isSpecsInited = specs60.Init( - 60, - clrYellow, - clrYellow, - fillTickZone // - ); - if (isSpecsInited) - { - AddTickZoneLevelSpecs(specs60); - } - - // - XTickZoneLevelSpecs specs70; - isSpecsInited = specs70.Init( - 70, - clrYellow, - clrYellow, - fillTickZone // - ); - if (isSpecsInited) - { - AddTickZoneLevelSpecs(specs70); - } - - // - XTickZoneLevelSpecs specs80; - isSpecsInited = specs80.Init( - 80, - clrRed, - clrRed, - fillTickZone // - ); - if (isSpecsInited) - { - AddTickZoneLevelSpecs(specs80); - } - - // - XTickZoneLevelSpecs specs90; - isSpecsInited = specs90.Init( - 90, - clrRed, - clrRed, - fillTickZone // - ); - if (isSpecsInited) - { - AddTickZoneLevelSpecs(specs90); - } - - // - XTickZoneLevelSpecs specs100; - isSpecsInited = specs100.Init( - 100, - clrRed, - clrRed, - fillTickZone // - ); - if (isSpecsInited) - { - AddTickZoneLevelSpecs(specs100); - } + defaultBearishStyle.width = 1; + defaultBearishStyle.clr = clrRed; + defaultBearishStyle.style = STYLE_SOLID; // + boxBullishStyle = defaultBullishStyle; + boxBearishStyle = defaultBearishStyle; } // // Object Creators ... - // - // Swings ... - - /** - * Create Swing High Object ... - * - * @param swing: XCSwing instance ... - * @param object: XCSwingHighObject pointer ... - * - * @return ( bool ) - */ - bool CreateSwingHigh( - XCSwing &swing, - XCSwingHighObject *&object // - ) - { - // - bool result = false; - - // - object = NULL; - - // - result = - swing.IsValid() && - swing.IsSwingHigh(); - if (!result) - { - return result; - } - - // - string prefix = Prefix(); - long chartID = ChartIdentification(); - int window = SubWindowIdentification(); - - // - int arrow = SwingHighArrow(); - int width = SwingHighWidth(); - color crl = SwingHighColor(); - - // - object = new XCSwingHighObject(); - result = object.Create( - chartID, - window, - arrow, - swing, - prefix // - ); - - // - if (!result) - { - return result; - } - - // - object.ArrowColor(crl); - object.ArrowWidth(width); - object.ArrowAnchor(ANCHOR_BOTTOM); - - // - return result; - } - - /** - * Create Swing Low Object ... - * - * @param swing: XCSwing instance ... - * @param object: XCSwingLowObject pointer ... - * - * @return ( bool ) - */ - bool CreateSwingLow( - XCSwing &swing, - XCSwingLowObject *&object // - ) - { - // - bool result = false; - - // - object = NULL; - - // - result = - swing.IsValid() && - swing.IsSwingLow(); - if (!result) - { - return result; - } - - // - string prefix = Prefix(); - long chartID = ChartIdentification(); - int window = SubWindowIdentification(); - - // - int arrow = SwingLowArrow(); - int width = SwingLowWidth(); - color crl = SwingLowColor(); - - // - object = new XCSwingLowObject(); - result = object.Create( - chartID, - window, - arrow, - swing, - prefix // - ); - - // - if (!result) - { - return result; - } - - // - object.ArrowColor(crl); - object.ArrowWidth(width); - object.ArrowAnchor(ANCHOR_TOP); - - // - return result; - } - - // - // Momentum Bars ... - - /** - * Create Bullish Momentum Bar Object ... - * - * @param momentumBar: XCMomentumBar instance ... - * @param object: XCBullishMomentumObject pointer ... - * - * @return ( bool ) - */ - bool CreateBullishMomentumBar( - XCMomentumBar &momentumBar, - XCBullishMomentumBarObject *&object // - ) - { - // - bool result = false; - - // - object = NULL; - - // - result = - momentumBar.IsValid() && - momentumBar.IsBullish(); - if (!result) - { - return result; - } - - // - string prefix = Prefix(); - long chartID = ChartIdentification(); - int window = SubWindowIdentification(); - - // - int arrow = BullishMomentumBarArrow(); - int width = BullishMomentumBarWidth(); - color crl = BullishMomentumBarColor(); - - // - object = new XCBullishMomentumBarObject(); - result = object.Create( - chartID, - window, - arrow, - momentumBar, - prefix // - ); - - // - if (!result) - { - return result; - } - - // - object.ArrowColor(crl); - object.ArrowWidth(width); - object.ArrowAnchor(ANCHOR_TOP); - - // - return result; - } - - /** - * Create Bearish Momentum Bar Object ... - * - * @param momentumBar: XCMomentumBar instance ... - * @param object: XCBearishMomentumObject pointer ... - * - * @return ( bool ) - */ - bool CreateBearishMomentumBar( - XCMomentumBar &momentumBar, - XCBearishMomentumBarObject *&object // - ) - { - // - bool result = false; - - // - object = NULL; - - // - result = - momentumBar.IsValid() && - momentumBar.IsBearish(); - if (!result) - { - return result; - } - - // - string prefix = Prefix(); - long chartID = ChartIdentification(); - int window = SubWindowIdentification(); - - // - int arrow = BearishMomentumBarArrow(); - int width = BearishMomentumBarWidth(); - color crl = BearishMomentumBarColor(); - - // - object = new XCBearishMomentumBarObject(); - result = object.Create( - chartID, - window, - arrow, - momentumBar, - prefix // - ); - - // - if (!result) - { - return result; - } - - // - object.ArrowColor(crl); - object.ArrowWidth(width); - object.ArrowAnchor(ANCHOR_BOTTOM); - - // - return result; - } - - // - // Rejection Bars ... - - /** - * Create Bullish Rejection Bar Object ... - * - * @param momentumBar: XCRejectionBar instance ... - * @param object: XCBullishRejectionObject pointer ... - * - * @return ( bool ) - */ - bool CreateBullishRejectionBar( - XCRejectionBar &rejectionBar, - XCBullishRejectionBarObject *&object // - ) - { - // - bool result = false; - - // - object = NULL; - - // - result = - rejectionBar.IsValid() && - rejectionBar.IsBullish(); - if (!result) - { - return result; - } - - // - string prefix = Prefix(); - long chartID = ChartIdentification(); - int window = SubWindowIdentification(); - - // - int arrow = BullishRejectionBarArrow(); - int width = BullishRejectionBarWidth(); - color crl = BullishRejectionBarColor(); - - // - object = new XCBullishRejectionBarObject(); - result = object.Create( - chartID, - window, - arrow, - rejectionBar, - prefix // - ); - - // - if (!result) - { - return result; - } - - // - object.ArrowColor(crl); - object.ArrowWidth(width); - object.ArrowAnchor(ANCHOR_TOP); - - // - return result; - } - - /** - * Create Bearish Rejection Bar Object ... - * - * @param rejectionBar: XCRejectionBar instance ... - * @param object: XCBearishRejectionObject pointer ... - * - * @return ( bool ) - */ - bool CreateBearishRejectionBar( - XCRejectionBar &rejectionBar, - XCBearishRejectionBarObject *&object // - ) - { - // - bool result = false; - - // - object = NULL; - - // - result = - rejectionBar.IsValid() && - rejectionBar.IsBearish(); - if (!result) - { - return result; - } - - // - string prefix = Prefix(); - long chartID = ChartIdentification(); - int window = SubWindowIdentification(); - - // - int arrow = BearishRejectionBarArrow(); - int width = BearishRejectionBarWidth(); - color crl = BearishRejectionBarColor(); - - // - object = new XCBearishRejectionBarObject(); - result = object.Create( - chartID, - window, - arrow, - rejectionBar, - prefix // - ); - - // - if (!result) - { - return result; - } - - // - object.ArrowColor(crl); - object.ArrowWidth(width); - object.ArrowAnchor(ANCHOR_BOTTOM); - - // - return result; - } - - // - // Support and Resistance ... - - /** - * Create Support Object ... - * - * @param zone: XCSupportZone instance ... - * @param object: XCSupportZoneObject pointer ... - * - * @return ( bool ) - */ - bool CreateSupportZone( - XCSupportZone &zone, - XCSupportZoneObject *&object // - ) - { - // - bool result = false; - - // - object = NULL; - - // - result = - zone.IsValid(); - if (!result) - { - return result; - } - - // - string prefix = Prefix(); - long chartID = ChartIdentification(); - int window = SubWindowIdentification(); - - // - bool fill = SupportZoneFill(); - int width = SupportZoneWidth(); - color crl = SupportZoneColor(); - ENUM_LINE_STYLE style = SupportZoneStyle(); - - // - object = new XCSupportZoneObject(); - result = object.Create( - chartID, - window, - zone, - prefix // - ); - - // - if (!result) - { - return result; - } - - // - object.ZoneFill(fill); - object.ZoneColor(crl); - object.ZoneWidth(width); - object.ZoneStyle(style); - - // - return result; - } - - /** - * Create Resistance Object ... - * - * @param zone: XCResistanceZone instance ... - * @param object: XCResistanceZoneObject pointer ... - * - * @return ( bool ) - */ - bool CreateResistanceZone( - XCResistanceZone &zone, - XCResistanceZoneObject *&object // - ) - { - // - bool result = false; - - // - object = NULL; - - // - result = - zone.IsValid(); - if (!result) - { - return result; - } - - // - string prefix = Prefix(); - long chartID = ChartIdentification(); - int window = SubWindowIdentification(); - - // - bool fill = ResistanceZoneFill(); - int width = ResistanceZoneWidth(); - color crl = ResistanceZoneColor(); - ENUM_LINE_STYLE style = ResistanceZoneStyle(); - - // - object = new XCResistanceZoneObject(); - result = object.Create( - chartID, - window, - zone, - prefix // - ); - - // - if (!result) - { - return result; - } - - // - object.ZoneFill(fill); - object.ZoneColor(crl); - object.ZoneWidth(width); - object.ZoneStyle(style); - - // - return result; - } - - // - // Supply and Demand Zones ... - - /** - * Create Supply Object ... - * - * @param zone: XCSupplyZone instance ... - * @param object: XCSupplyZoneObject pointer ... - * - * @return ( bool ) - */ - bool CreateSupplyZone( - XCSupplyZone &zone, - XCSupplyZoneObject *&object // - ) - { - // - bool result = false; - - // - object = NULL; - - // - result = - zone.IsValid(); - if (!result) - { - return result; - } - - // - string prefix = Prefix(); - long chartID = ChartIdentification(); - int window = SubWindowIdentification(); - - // - bool fill = SupplyZoneFill(); - int width = SupplyZoneWidth(); - color crl = SupplyZoneColor(); - ENUM_LINE_STYLE style = SupplyZoneStyle(); - - // - object = new XCSupplyZoneObject(); - result = object.Create( - chartID, - window, - zone, - prefix // - ); - - // - if (!result) - { - return result; - } - - // - object.ZoneFill(fill); - object.ZoneColor(crl); - object.ZoneWidth(width); - object.ZoneStyle(style); - - // - return result; - } - - /** - * Create Demand Object ... - * - * @param zone: XCDemandZone instance ... - * @param object: XCDemandZoneObject pointer ... - * - * @return ( bool ) - */ - bool CreateDemandZone( - XCDemandZone &zone, - XCDemandZoneObject *&object // - ) - { - // - bool result = false; - - // - object = NULL; - - // - result = - zone.IsValid(); - if (!result) - { - return result; - } - - // - string prefix = Prefix(); - long chartID = ChartIdentification(); - int window = SubWindowIdentification(); - - // - bool fill = DemandZoneFill(); - int width = DemandZoneWidth(); - color crl = DemandZoneColor(); - ENUM_LINE_STYLE style = DemandZoneStyle(); - - // - object = new XCDemandZoneObject(); - result = object.Create( - chartID, - window, - zone, - prefix // - ); - - // - 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: XCOrderBlock instance ... - * @param object: XCBullishOrderBlockObject pointer ... - * - * @return ( bool ) - */ - bool CreateBullishOrderBlock( - XCOrderBlock &zone, - XCBullishOrderBlockObject *&object // - ) - { - // - bool result = false; - - // - object = NULL; - - // - result = - zone.IsValid() && - zone.IsBullish(); - if (!result) - { - return result; - } - - // - string prefix = Prefix(); - long chartID = ChartIdentification(); - int window = SubWindowIdentification(); - - // - bool fill = BullishOrderBlockFill(); - int width = BullishOrderBlockWidth(); - color crl = BullishOrderBlockColor(); - ENUM_LINE_STYLE style = BullishOrderBlockStyle(); - - // - object = new XCBullishOrderBlockObject(); - result = object.Create( - chartID, - window, - zone, - prefix // - ); - - // - 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: XCOrderBlock instance ... - * @param object: XCBearishOrderBlockObject pointer ... - * - * @return ( bool ) - */ - bool CreateBearishOrderBlock( - XCOrderBlock &zone, - XCBearishOrderBlockObject *&object // - ) - { - // - bool result = false; - - // - object = NULL; - - // - result = - zone.IsValid() && - zone.IsBearish(); - if (!result) - { - return result; - } - - // - string prefix = Prefix(); - long chartID = ChartIdentification(); - int window = SubWindowIdentification(); - - // - bool fill = BearishOrderBlockFill(); - int width = BearishOrderBlockWidth(); - color crl = BearishOrderBlockColor(); - ENUM_LINE_STYLE style = BearishOrderBlockStyle(); - - // - object = new XCBearishOrderBlockObject(); - result = object.Create( - chartID, - window, - zone, - prefix // - ); - - // - if (!result) - { - return result; - } - - // - object.ZoneFill(fill); - object.ZoneColor(crl); - object.ZoneWidth(width); - object.ZoneStyle(style); - - // - return result; - } - - bool CreateOrderBlock( - XCOrderBlock &zone, - XCBaseObject *&object // - ) - { - // - bool result = false; - - // - object = NULL; - - // - result = zone.IsValid(); - if (!result) - { - return result; - } - - // - bool isBullish = zone.IsBullish(); - if (isBullish) - { - // - XCBullishOrderBlockObject *iObj; - result = CreateBullishOrderBlock( - zone, - iObj // - ); - if (result) - { - object = (XCBaseObject *)iObj; - } - } - else - { - // - XCBearishOrderBlockObject *iObj; - result = CreateBearishOrderBlock( - zone, - iObj // - ); - if (result) - { - object = (XCBaseObject *)iObj; - } - } - - // - return result; - } - - // - // Fair Value Gaps ... - - /** - * Create Bullish Fair Value Gap Object ... - * - * @param zone: XCFVG instance ... - * @param object: XCBullishOrderBlockObject pointer ... - * - * @return ( bool ) - */ - bool CreateBullishFairValueGap( - XCFVG &zone, - XCBullishFairValueGapObject *&object // - ) - { - // - bool result = false; - - // - result = zone.IsValid() && - zone.IsBullish(); - if (!result) - { - return result; - } - - // - string prefix = Prefix(); - long chartID = ChartIdentification(); - int window = SubWindowIdentification(); - - // - bool fill = BullishFVGFill(); - int width = BullishFVGWidth(); - color crl = BullishFVGColor(); - ENUM_LINE_STYLE style = BullishFVGStyle(); - - // - object = new XCBullishFairValueGapObject(); - result = object.Create( - chartID, - window, - zone, - prefix // - ); - - // - if (!result) - { - return result; - } - - // - object.ZoneFill(fill); - object.ZoneColor(crl); - object.ZoneWidth(width); - object.ZoneStyle(style); - - // - return result; - } - - /** - * Create Bearish Fair Value Gap Object ... - * - * @param zone: XCFVG instance ... - * @param object: XCBearishOrderBlockObject pointer ... - * - * @return ( bool ) - */ - bool CreateBearishFairValueGap( - XCFVG &zone, - XCBearishFairValueGapObject *&object // - ) - { - // - bool result = false; - - // - result = zone.IsValid() && - zone.IsBearish(); - if (!result) - { - return result; - } - - // - string prefix = Prefix(); - long chartID = ChartIdentification(); - int window = SubWindowIdentification(); - - // - bool fill = BearishFVGFill(); - int width = BearishFVGWidth(); - color crl = BearishFVGColor(); - ENUM_LINE_STYLE style = BearishFVGStyle(); - - // - object = new XCBearishFairValueGapObject(); - result = object.Create( - chartID, - window, - zone, - prefix // - ); - - // - if (!result) - { - return result; - } - - // - object.ZoneFill(fill); - object.ZoneColor(crl); - object.ZoneWidth(width); - object.ZoneStyle(style); - - // - return result; - } - - bool CreateFairValueGap( - XCFVG &zone, - XCBaseObject *&object // - ) - { - // - bool result = false; - - // - object = NULL; - - // - result = zone.IsValid(); - if (!result) - { - return result; - } - - // - bool isBullish = zone.IsBullish(); - if (isBullish) - { - // - XCBullishFairValueGapObject *iObj; - result = CreateBullishFairValueGap( - zone, - iObj // - ); - if (result) - { - object = (XCBaseObject *)iObj; - } - } - else - { - // - XCBearishFairValueGapObject *iObj; - result = CreateBearishFairValueGap( - zone, - iObj // - ); - if (result) - { - object = (XCBaseObject *)iObj; - } - } - - // - return result; - } - - // - // Ticks Zone ... - - /** - * Add Tick Zone Draw Specifications ... - * - * @param specs: XTickZoneLevelSpecs instance ... - */ - void AddTickZoneLevelSpecs( - XTickZoneLevelSpecs &specs // - ) - { - // - if (!specs.IsValid()) - { - return; - } - - // - bool isExists = false; - int count = ArraySize(mTicksZoneSpecs); - if (IsValidSize(count)) - { - // - for (int i = 0; i < count; i++) - { - // - XTickZoneLevelSpecs iSpec = mTicksZoneSpecs[i]; - - // - isExists = specs.percent == iSpec.percent; - if (isExists) - { - break; - } - } - } - if (isExists) - { - return; - } - - // - AddRef( - specs, - mTicksZoneSpecs // - ); - } - - /** - * Draw Specified Ticker Zone ... - * - * @param zone: XCTicksZone instance Specified Ticker Zone ... - * @param object: XCTicksZoneObject pointer ... - * - * @return ( bool ) - */ - bool CreateTicksZone( - XCTicksZone &zone, - XCTicksZoneObject *&object // - ) - { - // - bool result = false; - - // - object = NULL; - - // - result = zone.IsValid(); - if (!result) - { - return result; - } - - // - string prefix = Prefix(); - long chartID = ChartIdentification(); - int window = SubWindowIdentification(); - - // - object = new XCTicksZoneObject(); - result = object.Create( - chartID, - window, - zone, - mTicksZoneSpecs, - prefix // - ); - - // - if (!result) - { - return result; - } - - // - return result; - } - - /** - * Create Consolidation Zone Object ... - * - * @param zone: XConsolidationZone instance Reference ... - * - * @return ( bool ) - */ - bool CreateConsolidationZone( - XConsolidationZone &zone, - XCConsolidationZoneObject *&object // - ) - { - // - bool result = false; - - // - object = NULL; - - // - result = zone.IsValid(); - if (!result) - { - return result; - } - - // - string prefix = Prefix(); - long chartID = ChartIdentification(); - int window = SubWindowIdentification(); - - // - color czColor = IsBullish(zone.dir) - ? BarBullishColor() - : BarBearishColor(); - - // - object = new XCConsolidationZoneObject(); - result = object.Create( - chartID, - window, - zone, - prefix // - ); - - // - if (result) - { - object.ZoneColor(czColor); - } - - // - return result; - } - /** * Create Bar Object ... * @@ -3209,8 +711,8 @@ class XCPOIDrawer : public XCBase bool fill = false; color clr = box.IsBullish() - ? BullishFVGColor() - : BearishFVGColor(); + ? defaultBullishStyle.clr + : defaultBearishStyle.clr; ENUM_LINE_STYLE style = STYLE_DASHDOTDOT; string name = box.GetTag(); @@ -3228,6 +730,28 @@ class XCPOIDrawer : public XCBase style // ); + // + if (result) + { + // + if (box.IsBullish()) + { + // + ApplyStyle( + object, + boxBullishStyle // + ); + } + else + { + // + ApplyStyle( + object, + boxBearishStyle // + ); + } + } + // return result; } @@ -3355,906 +879,24 @@ class XCPOIDrawer : public XCBase } /** - * Draw Signal Box ... - * - * @param box: XSignalBox instance Reference ... - * @param objects: XCBaseObject pointer instance Reference ... - * - * @return ( bool ) + * Apply Specified Style to Object ... */ - bool DrawSignalBox( - XSignalBox &box, - XCBaseObject *&objects[], - color clr = CLR_NONE // + void ApplyStyle( + XCBoxObject *&object, + XPOIStyle &style // ) { // - bool result = false; - - // - Clean(objects); - - // - bool has = false; - bool hasColor = clr != CLR_NONE; - - // - // Order Block ... - if (box.ob.IsValid()) + bool has = object != NULL; + if (!has) { - // - XCBoxObject *iObj; - has = DrawBox( - box.ob, - iObj // - ); - if (has) - { - // - iObj.BoxStyle(STYLE_DASH); - - // - if (hasColor) - { - iObj.BoxColor(clr); - } - - // - Add( - (XCBaseObject *)iObj, - objects // - ); - } + return; } // - // Fair Value Gap ... - if (box.fvg.IsValid()) - { - // - XCBoxObject *iObj; - has = DrawBox( - box.fvg, - iObj // - ); - if (has) - { - // - iObj.BoxStyle(STYLE_SOLID); - - // - if (hasColor) - { - iObj.BoxColor(clr); - } - - // - Add( - (XCBaseObject *)iObj, - objects // - ); - } - } - - // - // Sharp Zone ... - if (box.sharp.IsValid()) - { - // - XCBoxObject *iObj; - has = DrawBox( - box.sharp, - iObj // - ); - if (has) - { - // - iObj.BoxStyle(STYLE_DOT); - - // - if (hasColor) - { - iObj.BoxColor(clr); - } - - // - Add( - (XCBaseObject *)iObj, - objects // - ); - } - } - - // - result = HasChild(objects); - - // - return result; - } - - /** - * Draw Specified POI State ... - * - * @param state: XPOIState instance Reference ... - * @param drawnObjects: CArrayObj instance for Holding Drawn Objects ... - * @param drawTicksZone: Boolean ... - * @param ignoreSwingHighs: Boolean ... - * @param ignoreSwingLows: Boolean ... - * @param ignoreSupportZones: Boolean ... - * @param ignoreResistanceZones: Boolean ... - * @param ignoreSupplyZones: Boolean ... - * @param ignoreDemandZones: Boolean ... - * @param ignoreBullishOrderBlocks: Boolean ... - * @param ignoreBearishOrderBlocks: Boolean ... - * @param ignoreBullishFairValueGaps: Boolean ... - * @param ignoreBearishFairValueGaps: Boolean ... - * @param ignoreBullishRejectionBars: Boolean ... - * @param ignoreBearishRejectionBars: Boolean ... - * @param ignoreBullishMomentumBars: Boolean ... - * @param ignoreBearishMomentumBars: Boolean ... - */ - int DrawState( - XPOIState &state, - XCBaseObject *&drawnObjects[], - // - // Bullish ... - bool ignoreSwingLows = false, - bool ignoreDemandZones = false, - bool ignoreSupportZones = false, - bool ignoreBullishSharps = false, - bool ignoreBullishSpikes = false, - bool ignoreBullishPullbacks = false, - bool ignoreBullishMomentums = false, - bool ignoreBullishRejections = false, - bool ignoreBullishOrderBlocks = false, - bool ignoreBullishFairValueGaps = false, - bool ignoreBullishConsolidationZones = false, - // - // Bearish ... - bool ignoreSwingHighs = false, - bool ignoreSupplyZones = false, - bool ignoreResistanceZones = false, - bool ignoreBearishSharps = false, - bool ignoreBearishSpikes = false, - bool ignoreBearishPullbacks = false, - bool ignoreBearishMomentums = false, - bool ignoreBearishRejections = false, - bool ignoreBearishOrderBlocks = false, - bool ignoreBearishFairValueGaps = false, - bool ignoreBearishConsolidationZones = false // - ) - { - // - int result = 0; - - // - if (!state.IsValid() || - !state.HasChild()) - { - return result; - } - - // - Clean(drawnObjects); - - // - // Swings ... - - // - // SwingHighs ... - if (!ignoreSwingHighs) - { - // - int count = state.CountSwingHighs(); - if (IsValidSize(count)) - { - // - for (int i = 0; i < count; i++) - { - // - XCSwing *iSwing = state.swingHighs[i]; - XCSwingHighObject *iObj; - - // - bool isCreated = CreateSwingHigh( - iSwing, - iObj // - ); - if (isCreated) - { - // - Add( - (XCBaseObject *)iObj, - drawnObjects // - ); - } - } - } - } - - // - // SwingLows ... - if (!ignoreSwingLows) - { - // - int count = state.CountSwingLows(); - if (IsValidSize(count)) - { - // - for (int i = 0; i < count; i++) - { - // - XCSwing *iSwing = state.swingLows[i]; - XCSwingLowObject *iObj; - - // - bool isCreated = CreateSwingLow( - iSwing, - iObj // - ); - if (isCreated) - { - // - Add( - (XCBaseObject *)iObj, - drawnObjects // - ); - } - } - } - } - - // - // Support / Resistance ... - - // - // SupportZones ... - if (!ignoreSupportZones) - { - // - int count = state.CountSupportZones(); - if (IsValidSize(count)) - { - // - for (int i = 0; i < count; i++) - { - // - XCSupportZone *iZone = state.supportZones[i]; - XCSupportZoneObject *iObj; - - // - bool isCreated = CreateSupportZone( - iZone, - iObj // - ); - if (isCreated) - { - // - Add( - (XCBaseObject *)iObj, - drawnObjects // - ); - } - } - } - } - - // - // ResistanceZones ... - if (!ignoreResistanceZones) - { - // - int count = state.CountResistanceZones(); - if (IsValidSize(count)) - { - // - for (int i = 0; i < count; i++) - { - // - XCResistanceZone *iZone = state.resistanceZones[i]; - XCResistanceZoneObject *iObj; - - // - bool isCreated = CreateResistanceZone( - iZone, - iObj // - ); - if (isCreated) - { - // - Add( - (XCBaseObject *)iObj, - drawnObjects // - ); - } - } - } - } - - // - // Supply / Demand ... - - // - // SupplyZones ... - if (!ignoreSupplyZones) - { - // - int count = state.CountSupplyZones(); - if (IsValidSize(count)) - { - // - for (int i = 0; i < count; i++) - { - // - XCSupplyZone *iZone = state.supplyZones[i]; - XCSupplyZoneObject *iObj; - - // - bool isCreated = CreateSupplyZone( - iZone, - iObj // - ); - if (isCreated) - { - // - Add( - (XCBaseObject *)iObj, - drawnObjects // - ); - } - } - } - } - - // - // DemandZones ... - if (!ignoreDemandZones) - { - // - int count = state.CountDemandZones(); - if (IsValidSize(count)) - { - // - for (int i = 0; i < count; i++) - { - // - XCDemandZone *iZone = state.demandZones[i]; - XCDemandZoneObject *iObj; - - // - bool isCreated = CreateDemandZone( - iZone, - iObj // - ); - if (isCreated) - { - // - Add( - (XCBaseObject *)iObj, - drawnObjects // - ); - } - } - } - } - - // - // Order Blocks ... - - // - // BullishOrderBlocks ... - if (!ignoreBullishOrderBlocks) - { - // - int count = state.CountBullishOrderBlocks(); - if (IsValidSize(count)) - { - // - for (int i = 0; i < count; i++) - { - // - XCOrderBlock *iZone = state.bullishOrderBlocks[i]; - XCBullishOrderBlockObject *iObj; - - // - bool isCreated = CreateBullishOrderBlock( - iZone, - iObj // - ); - if (isCreated) - { - // - Add( - (XCBaseObject *)iObj, - drawnObjects // - ); - } - } - } - } - - // - // BearishOrderBlocks ... - if (!ignoreBearishOrderBlocks) - { - // - int count = state.CountBearishOrderBlocks(); - if (IsValidSize(count)) - { - // - for (int i = 0; i < count; i++) - { - // - XCOrderBlock *iZone = state.bearishOrderBlocks[i]; - XCBearishOrderBlockObject *iObj; - - // - bool isCreated = CreateBearishOrderBlock( - iZone, - iObj // - ); - if (isCreated) - { - // - Add( - (XCBaseObject *)iObj, - drawnObjects // - ); - } - } - } - } - - // - // Fair Value Gaps ... - - // - // BullishFairValueGaps ... - if (!ignoreBullishFairValueGaps) - { - // - int count = state.CountBullishFairValueGaps(); - if (IsValidSize(count)) - { - // - for (int i = 0; i < count; i++) - { - // - XCFVG *iZone = state.bullishFairValueGaps[i]; - XCBullishFairValueGapObject *iObj; - - // - bool isCreated = CreateBullishFairValueGap( - iZone, - iObj // - ); - if (isCreated) - { - // - Add( - (XCBaseObject *)iObj, - drawnObjects // - ); - } - } - } - } - - // - // BearishFairValueGaps ... - if (!ignoreBearishFairValueGaps) - { - // - int count = state.CountBearishFairValueGaps(); - if (IsValidSize(count)) - { - // - for (int i = 0; i < count; i++) - { - // - XCFVG *iZone = state.bearishFairValueGaps[i]; - XCBearishFairValueGapObject *iObj; - - // - bool isCreated = CreateBearishFairValueGap( - iZone, - iObj // - ); - if (isCreated) - { - // - Add( - (XCBaseObject *)iObj, - drawnObjects // - ); - } - } - } - } - - // - // Rejections ... - - // - // BullishRejectionBars ... - if (!ignoreBullishRejections) - { - // - int count = state.CountBullishRejections(); - if (IsValidSize(count)) - { - // - for (int i = 0; i < count; i++) - { - // - XCRejectionBar *iBar = state.bullishRejections[i]; - XCBullishRejectionBarObject *iObj; - - // - bool isCreated = CreateBullishRejectionBar( - iBar, - iObj // - ); - if (isCreated) - { - // - Add( - (XCBaseObject *)iObj, - drawnObjects // - ); - } - } - } - } - - // - // BearishRejectionBars ... - if (!ignoreBearishRejections) - { - // - int count = state.CountBearishRejections(); - if (IsValidSize(count)) - { - // - for (int i = 0; i < count; i++) - { - // - XCRejectionBar *iBar = state.bearishRejections[i]; - XCBearishRejectionBarObject *iObj; - - // - bool isCreated = CreateBearishRejectionBar( - iBar, - iObj // - ); - if (isCreated) - { - // - Add( - (XCBaseObject *)iObj, - drawnObjects // - ); - } - } - } - } - - // - // Momentums ... - - // - // BullishMomentumBars ... - if (!ignoreBullishMomentums) - { - // - int count = state.CountBullishMomentums(); - if (IsValidSize(count)) - { - // - for (int i = 0; i < count; i++) - { - // - XCMomentumBar *iBar = state.bullishMomentums[i]; - XCBullishMomentumBarObject *iObj; - - // - bool isCreated = CreateBullishMomentumBar( - iBar, - iObj // - ); - if (isCreated) - { - // - Add( - (XCBaseObject *)iObj, - drawnObjects // - ); - } - } - } - } - - // - // BearishMomentumBars ... - if (!ignoreBearishMomentums) - { - // - int count = state.CountBearishMomentums(); - if (IsValidSize(count)) - { - // - for (int i = 0; i < count; i++) - { - // - XCMomentumBar *iBar = state.bearishMomentums[i]; - XCBearishMomentumBarObject *iObj; - - // - bool isCreated = CreateBearishMomentumBar( - iBar, - iObj // - ); - if (isCreated) - { - // - Add( - (XCBaseObject *)iObj, - drawnObjects // - ); - } - } - } - } - - // - // Pullbacks ... - - // - // Bullish ... - if (!ignoreBullishPullbacks) - { - // - int count = state.CountBullishPullbacks(); - if (IsValidSize(count)) - { - // - for (int i = 0; i < count; i++) - { - // - XCBoxObject *iObj; - bool isCreated = DrawBox( - state.bullishPullbacks[i], - iObj // - ); - if (isCreated) - { - // - Add( - (XCBaseObject *)iObj, - drawnObjects // - ); - } - } - } - } - - // - // Bearish ... - if (!ignoreBearishPullbacks) - { - // - int count = state.CountBearishPullbacks(); - if (IsValidSize(count)) - { - // - for (int i = 0; i < count; i++) - { - // - XCBoxObject *iObj; - bool isCreated = DrawBox( - state.bearishPullbacks[i], - iObj // - ); - if (isCreated) - { - // - Add( - (XCBaseObject *)iObj, - drawnObjects // - ); - } - } - } - } - - // - // Consolidation Zones ... - - // - // Bullish Consolidation Zones ... - if (!ignoreBullishConsolidationZones) - { - // - int count = state.CountBullishConsolidationZones(); - if (IsValidSize(count)) - { - // - for (int i = 0; i < count; i++) - { - // - XCConsolidationZoneObject *iObj; - bool isCreated = CreateConsolidationZone( - state.bullishConsolidationZones[i], - iObj // - ); - if (isCreated) - { - // - Add( - (XCBaseObject *)iObj, - drawnObjects // - ); - } - } - } - } - - // - // Bearish Consolidation Zones ... - if (!ignoreBearishConsolidationZones) - { - // - int count = state.CountBearishConsolidationZones(); - if (IsValidSize(count)) - { - // - for (int i = 0; i < count; i++) - { - // - XCConsolidationZoneObject *iObj; - bool isCreated = CreateConsolidationZone( - state.bearishConsolidationZones[i], - iObj // - ); - if (isCreated) - { - // - Add( - (XCBaseObject *)iObj, - drawnObjects // - ); - } - } - } - } - - // - // Spikes ... - - // - // Bullish ... - if (!ignoreBullishSpikes) - { - // - int count = state.CountBullishSpikes(); - if (IsValidSize(count)) - { - // - for (int i = 0; i < count; i++) - { - // - XCBoxObject *iObj; - bool isCreated = DrawBox( - state.bullishSpikes[i], - iObj // - ); - if (isCreated) - { - // - Add( - (XCBaseObject *)iObj, - drawnObjects // - ); - } - } - } - } - - // - // Bearish ... - if (!ignoreBearishSpikes) - { - // - int count = state.CountBearishSpikes(); - if (IsValidSize(count)) - { - // - for (int i = 0; i < count; i++) - { - // - XCBoxObject *iObj; - bool isCreated = DrawBox( - state.bearishSpikes[i], - iObj // - ); - if (isCreated) - { - // - Add( - (XCBaseObject *)iObj, - drawnObjects // - ); - } - } - } - } - - // - // Sharps ... - - // - // Bullish ... - if (!ignoreBullishSharps) - { - // - int count = state.CountBullishSharps(); - if (IsValidSize(count)) - { - // - for (int i = 0; i < count; i++) - { - // - XCBoxObject *iObj; - bool isCreated = DrawBox( - state.bullishSharps[i], - iObj // - ); - if (isCreated) - { - // - Add( - (XCBaseObject *)iObj, - drawnObjects // - ); - } - } - } - } - - // - // Bearish ... - if (!ignoreBearishSharps) - { - // - int count = state.CountBearishSharps(); - if (IsValidSize(count)) - { - // - for (int i = 0; i < count; i++) - { - // - XCBoxObject *iObj; - bool isCreated = DrawBox( - state.bearishSharps[i], - iObj // - ); - if (isCreated) - { - // - Add( - (XCBaseObject *)iObj, - drawnObjects // - ); - } - } - } - } - - // - result = ArraySize(drawnObjects); - - // - return result; + object.BoxColor(style.clr); + object.BoxWidth(style.width); + object.BoxStyle(style.style); } // @@ -4285,101 +927,5 @@ class XCPOIDrawer : public XCBase bool mBarFillLowShadow; // Fill Bar Low Show ... ENUM_LINE_STYLE mBarLowShadowStyle; // Bar Low Shadow Style ... - // - // 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 ... - - // - // Ticks Zone ... - XTickZoneLevelSpecs mTicksZoneSpecs[]; // Zone Draw Specifications ... - // }; \ No newline at end of file diff --git a/Documents/BKP/tmp.poi.mq5 b/Documents/BKP/tmp.poi.mq5 new file mode 100644 index 00000000..919dc816 --- /dev/null +++ b/Documents/BKP/tmp.poi.mq5 @@ -0,0 +1,5385 @@ +// +// All Available POI(s) ... +enum ENUM_XPOIS +{ + // + X_POI_NONE, + // + X_POI_TICKS_ZONES, // Ticks Zone ... + // + // Trading Day ... + X_POI_TRADING_DAY, // Trading Day ... + // + // Market Session ... + X_POI_MARKET_SESSION, // Market Session ... + // + // Momentum Bar ... + X_POI_MOMENTUM_BAR, // Momentum Bar ... + // + // Rejection Bar ... + X_POI_REJECTION_BAR, // Rejection Bar ... + // + // Swings ... + X_POI_SWING_HIGH, // Simple Swing High ... + X_POI_SWING_LOW, // Simple Swing Low ... + // + // Support nad Resistance ... + X_POI_SUPPORT_ZONE, // Support Zone ... + X_POI_RESISTANCE_ZONE, // 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 ... + // + X_BULLISH_CONSOLIDATION_ZONE, + X_BEARISH_CONSOLIDATION_ZONE, + // + X_BULLISH_SHARP, + X_BEARISH_SHARP, + // + X_BULLISH_SPIKE, + X_BEARISH_SPIKE, + // + X_BULLISH_PULLBACK, + X_BEARISH_PULLBACK, +}; + +// +// Event Types ... +enum ENUM_XPOI_EVENTS +{ + // + X_POI_EVENT_NONE, + // + // Trading Days ... + X_TRADE_DAY_FIRST_BAR, // Trading Day First Bar ... + X_TRADE_DAY_LAST_BAR, // Trading Day Last Bar ... + // + // Session ... + X_SESSION_FIRST_BAR, // Session First Bar ... + X_SESSION_LAST_BAR, // Session Last Bar ... + // + // Momentum Bar ... + X_BULLISH_MOMENTUM_BAR_DETECTED, + X_BEARISH_MOMENTUM_BAR_DETECTED, + // + // Rejection Bar ... + X_BULLISH_REJECTION_BAR_DETECTED, + X_BEARISH_REJECTION_BAR_DETECTED, + // + // Swings ... + X_SWING_HIGH_DETECTED, + X_SWING_LOW_DETECTED, + // + // 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Ù‘ ... + X_BULLISH_CONSOLIDATION_ZONE_DETECTED, + X_BEARISH_CONSOLIDATION_ZONE_DETECTED, + X_BULLISH_SHARP_DETECTED, + X_BEARISH_SHARP_DETECTED, + X_BULLISH_SPIKE_DETECTED, + X_BEARISH_SPIKE_DETECTED, + X_BULLISH_PULLBACK_DETECTED, + X_BEARISH_PULLBACK_DETECTED, +}; + +// +enum ENUM_XZONE_STATE +{ + XZONE_STATE_NONE, + XZONE_STATE_PASSED, + XZONE_STATE_FAILED, + XZONE_STATE_IGNORED, +}; + +// +// Forext Sessions ... +enum ENUM_XSESSION +{ + X_TOKYO, + X_SYDNEY, + X_LONDON, + X_NEW_YORK, + X_FRANKFORT, +}; + +/** + * Converts ENUM_XPOI value to String Representation ... + * + * @param value: ENUM_XPOI member ... + * + * @return ( string ) + */ +string ToString(ENUM_XPOIS value) +{ + // + string result = NULL; + + // + switch (value) + { + // + case X_POI_TRADING_DAY: + result = "XTDAY"; + break; + + // + case X_POI_MARKET_SESSION: + result = "XMSESS"; + break; + + // + case X_POI_MOMENTUM_BAR: + result = "XMNTMB"; + break; + + // + case X_POI_REJECTION_BAR: + result = "XRJCTB"; + break; + + // + case X_POI_SWING_HIGH: + result = "XSPH"; + break; + + // + case X_POI_SWING_LOW: + result = "XSPL"; + break; + + // + case X_POI_SUPPORT_ZONE: + result = "XSUP"; + break; + + // + case X_POI_RESISTANCE_ZONE: + 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; + + // + case X_POI_TICKS_ZONES: + result = "XTKSZ"; + break; + + // + case X_BULLISH_CONSOLIDATION_ZONE: + result = "XBULLCZ"; + break; + + // + case X_BEARISH_CONSOLIDATION_ZONE: + result = "XBEARCZ"; + break; + + // + case X_BULLISH_SPIKE: + result = "XBULLSPK"; + break; + + // + case X_BEARISH_SPIKE: + result = "XBEARSPK"; + break; + } + + // + return result; +} + +/** + * Converts ENUM_XSESSION value to String Representation ... + * + * @param value: ENUM_XSESSION member ... + * + * @return ( string ) + */ +string ToString(ENUM_XSESSION value) +{ + // + string result = NULL; + + // + switch (value) + { + // + case X_SYDNEY: + result = "Sydney"; + break; + + // + case X_TOKYO: + result = "Tokyo"; + break; + + // + case X_FRANKFORT: + result = "FrankGurt"; + break; + + // + case X_LONDON: + result = "London"; + break; + + // + case X_NEW_YORK: + result = "NewYork"; + break; + } + + // + return result; +} + +/** + * Generate General Event Messages ... + * + * @param value: ENUM_XPOI_EVENTS member ... + * + * @return ( string ) + */ +string ToString(ENUM_XPOI_EVENTS value) +{ + // + string result = NULL; + + // + switch (value) + { + // + case X_TRADE_DAY_FIRST_BAR: + result = "First Bar of Day"; + break; + + // + case X_TRADE_DAY_LAST_BAR: + result = "Last Bar of Day"; + break; + + // + case X_SESSION_FIRST_BAR: + result = "First Bar of Session"; + break; + + // + case X_SESSION_LAST_BAR: + result = "Last Bar of Session"; + break; + + // + case X_BULLISH_MOMENTUM_BAR_DETECTED: + result = "Bullish Momentum Bar Detected"; + break; + + // + case X_BEARISH_MOMENTUM_BAR_DETECTED: + result = "Bearish Momentum Bar Detected"; + break; + + // + case X_BULLISH_REJECTION_BAR_DETECTED: + result = "Bullish Rejection Bar Detected"; + break; + + // + case X_BEARISH_REJECTION_BAR_DETECTED: + result = "Bearish Rejection Bar Detected"; + break; + + // + case X_SWING_HIGH_DETECTED: + result = "Swing High Detected"; + break; + + // + case X_SWING_LOW_DETECTED: + result = "Swing Low Detected"; + break; + + // + case X_SUPPORT_ZONE_DETECTED: + result = "Support Zone Detected"; + break; + + // + case X_RESISTANCE_ZONE_DETECTED: + result = "Resistance Zone Detected"; + break; + + // + case X_SUPPLY_ZONE_DETECTED: + result = "Supply Zone Detected"; + break; + + // + case X_DEMAND_ZONE_DETECTED: + result = "Demand Zone Detected"; + break; + + // + case X_BULLISH_ORDERBLOCK_DETECTED: + result = "Bullish Order Block Detected"; + break; + + // + case X_BEARISH_ORDERBLOCK_DETECTED: + result = "Bearish Orer Block Detected"; + break; + + // + case X_BULLISH_FVG_DETECTED: + result = "Bullish FVG Detected"; + break; + + // + case X_BEARISH_FVG_DETECTED: + result = "Bearish FVg Detected"; + break; + } + + // + return result; +} + +// +// Implementation ... + +// +// Base POI Model Class ... +class XCBasePOI : public XCBase +{ + // + public: + // + + // + // Constructor ... + void XCBasePOI() + { + // + Clean(); + + // + mSep = "_"; + mLineSep = "\n"; + } + + // + // Deconstructor ... + void ~XCBasePOI() + { + Clean(); + } + + // + // Virtual ... + + /** + * Cleanup ... + */ + virtual void Clean() + { + mType = X_POI_NONE; + } + + /** + * Validate ... + * + * @return ( virtual bool ) + */ + virtual bool IsValid() + { + return false; + } + + /** + * Retrieve POI Type ... + * + * @return ( virtual ENUM_XPOIS member ) + */ + virtual ENUM_XPOIS Type() + { + return mType; + } + + /** + * Retrieve POI Type ... + * + * @return ( virtual string ) + */ + virtual string TypeAsString() + { + return ToString(mType); + } + + /** + * Retrieve POI Tag ... + * + * @return ( virtual string ) + */ + virtual string GetTag() + { + return NULL; + } + + /** + * Retrieve POI Tooltip ... + * + * @return ( virtual string ) + */ + virtual string GetTooltip() + { + return NULL; + } + + // + protected: + // + // Props ... + string mSep; // Separator ... + string mLineSep; // Line Separator ... + ENUM_XPOIS mType; // Type ... + + // + private: + // +}; + +// +typedef void (*TOnPOIEvent)(ENUM_XPOI_EVENTS event, + XCBasePOI *param // +); + +// +// Zone POI Class ... +class XCZone : public XCBasePOI +{ + // + public: + // + + // + // Constructor ... + void XCZone() + { + } + + // + // Deconstructor ... + void ~XCZone() + { + } + + // + // Tools ... + + // + // Getter(s) / Setter(s) ... + + /** + * Get Zone Upper Boundary ... + * + * @return ( double ) + */ + double Upper() + { + return mUpper; + } + + /** + * Set Zone Upper Boundary ... + */ + void Upper(double value) + { + mUpper = value; + } + + /** + * Get Zone Lower Boundary ... + * + * @return ( double ) + */ + double Lower() + { + return mLower; + } + + /** + * Set Zone Lower Boundary ... + */ + void Lower(double value) + { + mLower = value; + } + + /** + * Retrieve Zone Range ... + * + * @return ( double ) + */ + double Range() + { + // + double result = 0; + + // + double upper = Upper(); + double lower = Lower(); + + // + if (upper > 0 && lower > 0 && upper > lower) + { + result = upper - lower; + } + + // + return result; + } + + double RangePercent() + { + // + double result = 0; + + // + double range = Range(); + if (range > 0) + { + result = range / 100; + } + + // + return result; + } + + // + // Virtuals ... + + /** + * Get Zone Start Date ... + * + * @return ( virtual datetime ) + */ + virtual datetime From() + { + return NULL; + } + + /** + * Get Zone End Date ... + * + * @return ( virtual datetime ) + */ + virtual datetime To() + { + return NULL; + } + + // + // Getter(s) / Setter(s) ... + + // + // Overrides ... + + // + // Validators ... + + /** + * Validate Upper and Lower of Zone ... + * + * @return ( bool ) + */ + bool IsValidBoundary() + { + // + bool result = false; + + // + result = + // + mUpper > 0 && + mLower > 0 && + mUpper >= mLower + // + ; + + // + return result; + } + + /** + * Check From Date of Zone is Valid ... + * + * @return ( bool ) + */ + bool IsValidFrom() + { + // + bool result = false; + + // + datetime from = From(); + result = IsSpecifiedValid(from); + + // + return result; + } + + // + protected: + // + // Props ... + double mUpper; // Zone Upper ... + double mLower; // Zone Lower ... + + // + private: + // + // Props ... + + // +}; + +// +// From To Zone ... +class XCFromToZone : public XCBasePOI +{ + // + public: + // + + // + // Constructor ... + void XCFromToZone() + { + } + + // + // Deconstructor ... + void ~XCFromToZone() + { + } + + // + // Tools ... + + bool InitFromTo( + ENUM_XPOIS type, + string title, + datetime from // + ) + { + // + bool result = false; + + // + result = type != X_POI_NONE && + IsSpecifiedValid(from) && + IsSpecifiedValid(title); + + // + mType = type; + mFrom = from; + mTitle = title; + mTo = TimeCurrent(); + + // + result = IsValid(); + + // + return result; + } + + bool InitFromTo( + ENUM_XPOIS type, + string title, + datetime from, + datetime to // + ) + { + // + bool result = false; + + // + result = IsValid(); + + // + result = InitFromTo( + type, + title, + from // + ); + if (!result) + { + return result; + } + + // + to = NormalizeTime(to); + mTo = to; + + // + result = IsValid(); + + // + return result; + } + + // + // Getter(s) / Setter(s) ... + + /** + * Get Zone Start Time ... + * + * @return ( datetime ) + */ + datetime From() + { + return mFrom; + } + + /** + * Set Zone Start Time ... + * + * @param value: Datetime + */ + void From(datetime value) + { + // + value = NormalizeTime(value); + + // + mFrom = value; + } + + /** + * Get Zone End Time ... + * + * @return ( datetime ) + */ + datetime To() + { + return mTo; + } + + /** + * Set Zone End Time ... + * + * @param value: Datetime + */ + void To(datetime value) + { + // + value = NormalizeTime(value); + + // + mTo = value; + } + + /** + * Get Title ... + * + * @return ( string ) + */ + string Title() + { + return mTitle; + } + + /** + * Set Title ... + * + * @param value: String ... + */ + // void Title(string value) + // { + // mTitle = value; + // } + + // + // Overrides ... + + void Clean() override + { + // + mTo = NULL; + mFrom = NULL; + mType = X_POI_NONE; + } + + bool IsValid() override + { + // + bool result = false; + + // + result = + // + mType != X_POI_NONE && + IsSpecifiedValid(mTo) && + IsSpecifiedValid(mFrom) && + IsSpecifiedValid(mTitle) + // + ; + + // + return result; + } + + string GetTag() override + { + // + string result = NULL; + + // + if (!IsValid()) + { + return result; + } + + // + string hash = TypeAsString() + mSep + ToString(From()) + mSep + Title(); + hash = ToMD5(hash); + + // + result = TypeAsString() + "[" + Title() + "]" + mSep + hash; + + // + return result; + } + + // + protected: + // + + // + private: + // + // Props ... + datetime mFrom; // Start Date + datetime mTo; // End Date + string mTitle; // Zone Title + + // +}; + +// +// Bar Zone ... +class XCBarZone : public XCZone +{ + // + public: + // + + // + // Constructor ... + void XCBarZone() + { + } + + // + // Deconstructor ... + void ~XCBarZone() + { + } + + // + // Tools ... + + /** + * Initialize POI ... + * + * @param bar: XOHCL instance ... + * @param type: ENUM_XPOIS member ... + * @param upperPrice: ENUM_X_PRICE member ... + * @param lowerPrice: ENUM_X_PRICE member ... + * + * @return ( bool ) + */ + bool InitBarZone( + XOHCL &bar, + ENUM_XPOIS type, + ENUM_X_PRICE upperPrice, + ENUM_X_PRICE lowerPrice // + ) + { + // + bool result = false; + + // + result = bar.IsValid() && + type != X_POI_NONE && + upperPrice != lowerPrice; + if (!result) + { + return result; + } + + // + mBar = bar; + mType = type; + mUpperPrice = upperPrice; + mLowerPrice = lowerPrice; + mUpper = bar.GetPrice(upperPrice); + mLower = bar.GetPrice(lowerPrice); + + // + result = IsValidBarZone(); + if (result) + { + // + From(bar.time); + To(TimeCurrent()); + } + + // + return result; + } + + // + // Getter(s) / Setter(s) ... + + /** + * Fill Bar as XOHCL struct ... + * + * @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; + } + + /** + * Set From Date ... + * + * @param value: DateTime ... + */ + void From(datetime value) + { + // + if (!IsValidBarZone()) + { + return; + } + + // + value = NormalizeTime(value); + + // + mFrom = value; + } + + /** + * Set To Date ... + * + * @param value: DateTime ... + */ + void To(datetime value) + { + // + if (!IsValidBarZone()) + { + return; + } + + // + value = NormalizeTime(value); + + // + mTo = value; + } + + /** + * Retrieve Bar Time ... + * + * @return ( datetime ) + */ + datetime BarTime() + { + return mBar.time; + } + + /** + * Get Symbol ... + * + * @return ( string ) + */ + string GetSymbol() + { + // + string result = NULL; + + // + if (!mBar.IsValid()) + { + return result; + } + + // + return mBar.symbol; + + // + return result; + } + + /** + * Get Period ... + * + * @return ( int ) + */ + ENUM_TIMEFRAMES GetPeriod() + { + // + ENUM_TIMEFRAMES result = NULL; + + // + if (!mBar.IsValid()) + { + return result; + } + + // + return mBar.period; + + // + return result; + } + + /** + * Check Zone Started or not ... + * First Exit in Direction of Zone after From ... + * + * @param forDir: exit direction ... + * @param startedBar: specified Start Bar ... + * @param isBodyOut: specified Start Bar Close is Out of Zone or not ... + * @param forPeriod: specified Period ... + * + * @return ( bool ) + */ + bool IsStarted( + ENUM_X_DIRECTION forDir, + XOHCL &startedBar, + bool &isBodyOut, + ENUM_TIMEFRAMES forPeriod = NULL // + ) + { + // + bool result = false; + + // + isBodyOut = false; + startedBar.Clean(); + + // + result = HasDirection(forDir) && + IsValidBarZone(); + if (!result) + { + return result; + } + + // + bool isBullish = IsBullish(forDir); + + // + if (!IsSpecifiedValid(forPeriod)) + { + forPeriod = GetPeriod(); + } + + // + // Detect From Bar Index ... + int fromIndex = iBarShift( + GetSymbol(), + forPeriod, + From() // + ); + + // + for (int i = fromIndex; i >= 0; i--) + { + // + XOHCL iBar; + bool isInited = iBar.Init( + GetSymbol(), + forPeriod, + i // + ); + result = isInited; + if (!result) + { + // + iBar.Clean(); + continue; + } + + // + bool isBreakedFromUpper = + // + iBar.low > Upper() || + (iBar.low <= Upper() && + iBar.high > Upper() && + iBar.close > Upper()) + // + ; + + // + bool isBreakedFromLower = + // + iBar.low < Lower() || + (iBar.high >= Lower() && + iBar.low < Lower() && + iBar.close < Lower()) + // + ; + + // + bool isBreaked = + isBreakedFromUpper || + isBreakedFromLower; + if (isBreaked) + { + // + result = isBreaked && + isBullish + ? isBreakedFromUpper + : isBreakedFromLower; + if (result) + { + // + startedBar = iBar; + iBar.Clean(); + break; + } + } + + // + iBar.Clean(); + } + + // + result = startedBar.IsValid(); + if (result) + { + // + isBodyOut = + isBullish + ? startedBar.IsBullish() && + startedBar.GetUp() > Upper() + : startedBar.IsBearish() && + startedBar.GetDown() < Lower(); + } + + // + return result; + } + + /** + * Check Zone Activated or not ... + * First Enter in Opposit Direction of Zone after Start ... + * + * @param forDir: exit direction ... + * @param activatedBar: specified Activation Bar ... + * @param isBodyIn: specified Activation Bar Close is Inside of Zone or not ... + * @param forPeriod: specified Period ... + * + * @return ( bool ) + */ + bool IsActivated( + ENUM_X_DIRECTION forDir, + XOHCL &activatedBar, + bool &isBodyIn, + bool forceBodyOutStarted = true, + ENUM_TIMEFRAMES forPeriod = NULL // + ) + { + // + bool result = false; + + // + isBodyIn = false; + activatedBar.Clean(); + + // + result = HasDirection(forDir) && + IsValidBarZone(); + if (!result) + { + return result; + } + + // + bool isBullish = IsBullish(forDir); + + // + if (!IsSpecifiedValid(forPeriod)) + { + forPeriod = GetPeriod(); + } + + // + XOHCL startedBar; + bool isBodyOut = false; + bool isStarted = IsStarted( + forDir, + startedBar, + isBodyOut, + forPeriod // + ); + result = + !forceBodyOutStarted + ? isStarted + : isStarted && + isBodyOut; + if (!result) + { + // + startedBar.Clean(); + return result; + } + + // + int fromIndex = startedBar.Index() - 1; + + // + for (int i = fromIndex; i >= 0; i--) + { + // + XOHCL iBar; + bool isInited = iBar.Init( + GetSymbol(), + forPeriod, + i // + ); + result = isInited; + if (!result) + { + // + iBar.Clean(); + continue; + } + + // + bool isInsideFromUpper = + // + iBar.high < Upper() || + (iBar.high > Upper() && + iBar.low <= Upper() && + iBar.close <= Upper()) + // + ; + + // + bool isInsideFromLower = + // + iBar.low > Lower() || + (iBar.low < Lower() && + iBar.high >= Lower() && + iBar.close >= Lower()) + // + ; + + // + bool isInside = + isInsideFromUpper || + isInsideFromLower; + if (isInside) + { + // + result = isInside && + isBullish + ? isInsideFromUpper + : isInsideFromLower; + if (result) + { + // + activatedBar = iBar; + iBar.Clean(); + startedBar.Clean(); + break; + } + } + + // + iBar.Clean(); + startedBar.Clean(); + } + + // + result = activatedBar.IsValid(); + if (result) + { + // + isBodyIn = + isBullish + ? activatedBar.IsBearish() && + activatedBar.GetDown() < Upper() + : activatedBar.IsBullish() && + activatedBar.GetUp() > Lower(); + } + + // + return result; + } + + /** + * Check Zone Breaked or not ... + * + * @param forDir: exit direction ... + * @param breakedBar: specified Breaked Bar ... + * @param isBodyOut: specified Breaked Bar Close is Out of Zone or not ... + * @param ignoreStart: Ignore Zone Start (Calculate from From()) ... + * @param startedBodyOut: Started Bar Body Close State, if use Start for Calculation ... + * @param forPeriod: specified Period ... + * + * @return ( bool ) + */ + bool IsBreaked( + ENUM_X_DIRECTION forDir, + XOHCL &breakedBar, + bool &isBodyOut, + bool ignoreStart = false, + bool startedBodyOut = false, + ENUM_TIMEFRAMES forPeriod = NULL // + ) + { + // + bool result = false; + + // + isBodyOut = false; + breakedBar.Clean(); + + // + result = HasDirection(forDir) && + IsValidBarZone(); + if (!result) + { + return result; + } + + // + bool isBullish = IsBullish(forDir); + + // + if (!IsSpecifiedValid(forPeriod)) + { + forPeriod = GetPeriod(); + } + + // + int fromIndex = -1; + if (!ignoreStart) + { + // + XOHCL startedBar; + bool isBodyOut = false; + bool isStarted = IsStarted( + forDir, + startedBar, + isBodyOut, + forPeriod // + ); + + // + bool isStartPassed = + !startedBodyOut + ? isStarted + : isStarted && + isBodyOut; + if (isStartPassed) + { + fromIndex = startedBar.Index() - 1; + } + + // + startedBar.Clean(); + } + else + { + // + fromIndex = iBarShift( + GetSymbol(), + forPeriod, + From() // + ); + } + + // + result = IsValidIndex(fromIndex); + if (!result) + { + return result; + } + + // + for (int i = fromIndex; i >= 0; i--) + { + // + XOHCL iBar; + bool isInited = iBar.Init( + GetSymbol(), + forPeriod, + i // + ); + result = isInited; + if (!result) + { + // + iBar.Clean(); + continue; + } + + // + bool isBreakedFromUpper = + // + iBar.low > Upper() || + (iBar.low <= Upper() && + iBar.high > Upper() && + iBar.close > Upper()) + // + ; + + // + bool isBreakedFromLower = + // + iBar.low < Lower() || + (iBar.high >= Lower() && + iBar.low < Lower() && + iBar.close < Lower()) + // + ; + + // + bool isBreaked = + isBreakedFromUpper || + isBreakedFromLower; + if (isBreaked) + { + // + result = isBreaked && + (isBullish + ? isBreakedFromLower + : isBreakedFromUpper); + if (result) + { + // + breakedBar = iBar; + iBar.Clean(); + break; + } + } + + // + iBar.Clean(); + } + + // + result = breakedBar.IsValid(); + if (result) + { + // + isBodyOut = + isBullish + ? breakedBar.IsBearish() && + breakedBar.GetDown() < Lower() + : breakedBar.IsBullish() && + breakedBar.GetUp() > Upper(); + } + + // + return result; + } + + /** + * Check Zone Worked or not ... + * + * @param forDir: exit direction ... + * @param workedBar: specified Worked Bar ... + * @param isBodyOut: specified Worked Bar Close is Out of Zone or not ... + * @param ignoreActivation: Ignore Zone Activation (Calculate from From()) ... + * @param activationStartedOut: Specified Zone Start Bar State ... + * @param activationBodyIn: Specified Zone Activation Bar State ... + * @param forPeriod: specified Period ... + * + * @return ( bool ) + */ + bool IsWorked( + ENUM_X_DIRECTION forDir, + XOHCL &workedBar, + bool &isBodyOut, + bool ignoreActivation = false, + bool activationStartedOut = false, + bool activationBodyIn = false, + ENUM_TIMEFRAMES forPeriod = NULL // + ) + { + // + bool result = false; + + // + isBodyOut = false; + workedBar.Clean(); + + // + result = HasDirection(forDir) && + IsValidBarZone(); + if (!result) + { + return result; + } + + // + bool isBullish = IsBullish(forDir); + + // + if (!IsSpecifiedValid(forPeriod)) + { + forPeriod = GetPeriod(); + } + + // + int fromIndex = -1; + if (!ignoreActivation) + { + // + XOHCL activatedBar; + bool isBodyIn = false; + bool isActivated = IsActivated( + forDir, + activatedBar, + isBodyIn, + activationStartedOut, + forPeriod // + ); + + // + bool isActivationPassed = + !activationBodyIn + ? isActivated + : isActivated && + isBodyIn; + if (isActivationPassed) + { + fromIndex = activatedBar.Index() - 1; + } + + // + activatedBar.Clean(); + } + else + { + // + fromIndex = iBarShift( + GetSymbol(), + forPeriod, + From() // + ); + } + + // + result = IsValidIndex(fromIndex); + if (!result) + { + return result; + } + + // + for (int i = fromIndex; i >= 0; i--) + { + // + XOHCL iBar; + bool isInited = iBar.Init( + GetSymbol(), + forPeriod, + i // + ); + result = isInited; + if (!result) + { + // + iBar.Clean(); + continue; + } + + // + bool isBreakedFromUpper = + // + iBar.low > Upper() || + (iBar.low <= Upper() && + iBar.high > Upper() && + iBar.close > Upper()) + // + ; + + // + bool isBreakedFromLower = + // + iBar.low < Lower() || + (iBar.high >= Lower() && + iBar.low < Lower() && + iBar.close < Lower()) + // + ; + + // + bool isBreaked = + isBreakedFromUpper || + isBreakedFromLower; + if (isBreaked) + { + // + result = isBreaked && + isBullish + ? isBreakedFromUpper + : isBreakedFromLower; + if (result) + { + // + workedBar = iBar; + iBar.Clean(); + break; + } + } + + // + iBar.Clean(); + } + + // + result = workedBar.IsValid(); + if (result) + { + // + isBodyOut = + isBullish + ? workedBar.IsBullish() && + workedBar.GetUp() > Upper() + : workedBar.IsBearish() && + workedBar.GetDown() < Lower(); + } + + // + return result; + } + + /** + * Check to Find Nearest Bar which Breakes Upper ... + * + * @param bar: XOHCL instance Reference, Breaker Bar ... + * @param forPeriod: ENUM_TIMEFRAMES member, Breaker Bar Detection Period, default is Zone Period ... + * + * @return ( bool ) + */ + bool FindNearestInsideBarFromUpper( + XOHCL &bar, + ENUM_TIMEFRAMES forPeriod = NULL // + ) + { + // + bool result = false; + + // + bar.Clean(); + + // + if (!IsSpecifiedValid(forPeriod)) + { + forPeriod = GetPeriod(); + } + + // + result = IsValid(); + if (!result) + { + return result; + } + + // + int from = 1; + int to = iBarShift( + GetSymbol(), + forPeriod, + From() // + ); + + // + for (int i = from; i < to; i++) + { + // + XOHCL iBar; + bool isInited = iBar.Init( + GetSymbol(), + forPeriod, + i // + ); + if (!isInited) + { + break; + } + + // + bool isInside = iBar.low < Upper(); + if (isInside) + { + // + bar = iBar; + break; + } + } + + // + result = bar.IsValid(); + + // + return result; + } + + /** + * Check to Find Nearest Bar which Breakes Lower ... + * + * @param bar: XOHCL instance Reference, Breaker Bar ... + * @param forPeriod: ENUM_TIMEFRAMES member, Breaker Bar Detection Period, default is Zone Period ... + * + * @return ( bool ) + */ + bool FindNearestInsideBarFromLower( + XOHCL &bar, + ENUM_TIMEFRAMES forPeriod = NULL // + ) + { + // + bool result = false; + + // + bar.Clean(); + + // + if (!IsSpecifiedValid(forPeriod)) + { + forPeriod = GetPeriod(); + } + + // + result = IsValid(); + if (!result) + { + return result; + } + + // + int from = 1; + int to = iBarShift( + GetSymbol(), + forPeriod, + From() // + ); + + // + for (int i = from; i < to; i++) + { + // + XOHCL iBar; + bool isInited = iBar.Init( + GetSymbol(), + forPeriod, + i // + ); + if (!isInited) + { + break; + } + + // + bool isInside = iBar.high > Lower(); + if (isInside) + { + // + bar = iBar; + break; + } + } + + // + result = bar.IsValid(); + + // + return result; + } + + // + // Overrides ... + + void Clean() override + { + // + mBar.Clean(); + mUpper = 0; + mLower = 0; + mType = X_POI_NONE; + } + + datetime From() override + { + return mFrom; + } + + datetime To() override + { + return mTo; + } + + string GetTag() override + { + // + string result = NULL; + + // + if (!IsValidBarZone()) + { + return result; + } + + // + string hash = ToMD5(mBar.GetTag()); + + // + result = + // + TypeAsString() + mSep + + ToString(mBar.period) + mSep + + hash + // + ; + + // + return result; + } + + string GetTooltip() override + { + // + string result = NULL; + + // + if (!IsValidBarZone()) + { + return result; + } + + // + return result; + } + + // + protected: + // + // Props ... + XOHCL mBar; // Bar ... + ENUM_X_PRICE mUpperPrice; // Upper Price Selection + ENUM_X_PRICE mLowerPrice; // Lower Price Selection + + /** + * Check Bar Zone Validation ... + * + * @return ( bool ) + */ + bool IsValidBarZone() + { + // + bool result = false; + + // + result = mBar.IsValid() && + mType != X_POI_NONE && + IsValidBoundary(); + + // + return result; + } + + // + private: + // + // Props ... + datetime mFrom; + datetime mTo; + + // +}; +class XCTwoBarZone : public XCZone +{ + // + public: + // + + // + // Constructor ... + void XCTwoBarZone() + { + } + + // + // Deconstructor ... + void ~XCTwoBarZone() + { + } + + // + // Tools ... + + /** + * Initialize POI ... + * + * @param bar: XOHCL instance ... + * @param type: ENUM_XPOIS member ... + * @param upperPrice: ENUM_X_PRICE member ... + * @param lowerPrice: ENUM_X_PRICE member ... + * + * @return ( bool ) + */ + bool InitTwoBarZone( + XOHCL &startBar, + XOHCL &endBar, + ENUM_XPOIS type, + ENUM_X_PRICE startPrice, + ENUM_X_PRICE endPrice // + ) + { + // + bool result = false; + + // + result = startBar.IsValid() && + endBar.IsValid() && + startBar.symbol == endBar.symbol && + startBar.period == endBar.period && + startBar.time < endBar.time && + type != X_POI_NONE; + if (!result) + { + return result; + } + + // + mType = type; + mEndBar = endBar; + mStartBar = startBar; + + // + int startIndex = startBar.Index(); + int endIndex = endBar.Index(); + + // + double mStartPrice = startBar.GetPrice(startPrice); + double mEndPrice = endBar.GetPrice(endPrice); + bool isStartOverEnd = mStartPrice > mEndPrice; + + // + if (isStartOverEnd) + { + // + mUpperPrice = startPrice; + mLowerPrice = endPrice; + } + else + { + // + mUpperPrice = endPrice; + mLowerPrice = startPrice; + } + + // + mUpper = MathMax(mStartPrice, mEndPrice); + mLower = MathMin(mStartPrice, mEndPrice); + + // + result = IsValidTwoBarZone(); + if (result) + { + // + From(startBar.time); + To(endBar.time); + } + + // + return result; + } + + // + // Getter(s) / Setter(s) ... + + /** + * Set From Date ... + * + * @param value: DateTime ... + */ + void From(datetime value) + { + // + if (!IsValidTwoBarZone()) + { + return; + } + + // + value = NormalizeTime(value); + + // + mFrom = value; + } + + /** + * Set To Date ... + * + * @param value: DateTime ... + */ + void To(datetime value) + { + // + if (!IsValidTwoBarZone()) + { + return; + } + + // + value = NormalizeTime(value); + + // + mTo = value; + } + + /** + * Fill Start Bar ... + * + * @param bar: XOHCL instance ... + * + * @return ( bool ) + */ + bool FillStartBar(XOHCL &bar) + { + // + bool result = false; + + // + result = IsValidTwoBarZone(); + if (!result) + { + return result; + } + + // + bar = mStartBar; + + // + return result; + } + + /** + * Fill End Bar ... + * + * @param bar: XOHCL instance ... + * + * @return ( bool ) + */ + bool FillEndBar(XOHCL &bar) + { + // + bool result = false; + + // + result = IsValidTwoBarZone(); + if (!result) + { + return result; + } + + // + bar = mEndBar; + + // + return result; + } + + /** + * Get Symbol ... + * + * @return ( string ) + */ + string GetSymbol() + { + // + string result = NULL; + + // + if (!mStartBar.IsValid()) + { + return result; + } + + // + return mStartBar.symbol; + + // + return result; + } + + /** + * Get Period ... + * + * @return ( int ) + */ + ENUM_TIMEFRAMES GetPeriod() + { + // + ENUM_TIMEFRAMES result = NULL; + + // + if (!mStartBar.IsValid()) + { + return result; + } + + // + return mStartBar.period; + + // + return result; + } + + /** + * Check Zone Started or not ... + * First Exit in Direction of Zone after From ... + * + * @param forDir: exit direction ... + * @param startedBar: specified Start Bar ... + * @param isBodyOut: specified Start Bar Close is Out of Zone or not ... + * @param forPeriod: specified Period ... + * + * @return ( bool ) + */ + bool IsStarted( + ENUM_X_DIRECTION forDir, + XOHCL &startedBar, + bool &isBodyOut, + ENUM_TIMEFRAMES forPeriod = NULL // + ) + { + // + bool result = false; + + // + isBodyOut = false; + startedBar.Clean(); + + // + result = HasDirection(forDir) && + IsValidTwoBarZone(); + if (!result) + { + return result; + } + + // + bool isBullish = IsBullish(forDir); + + // + if (!IsSpecifiedValid(forPeriod)) + { + forPeriod = GetPeriod(); + } + + // + // Detect From Bar Index ... + int fromIndex = iBarShift( + GetSymbol(), + forPeriod, + From() // + ); + + // + for (int i = fromIndex; i >= 0; i--) + { + // + XOHCL iBar; + bool isInited = iBar.Init( + GetSymbol(), + forPeriod, + i // + ); + result = isInited; + if (!result) + { + // + iBar.Clean(); + continue; + } + + // + bool isBreakedFromUpper = + // + iBar.low > Upper() || + (iBar.low <= Upper() && + iBar.high > Upper() && + iBar.close > Upper()) + // + ; + + // + bool isBreakedFromLower = + // + iBar.low < Lower() || + (iBar.high >= Lower() && + iBar.low < Lower() && + iBar.close < Lower()) + // + ; + + // + bool isBreaked = + isBreakedFromUpper || + isBreakedFromLower; + if (isBreaked) + { + // + result = isBreaked && + isBullish + ? isBreakedFromUpper + : isBreakedFromLower; + if (result) + { + // + startedBar = iBar; + iBar.Clean(); + break; + } + } + + // + iBar.Clean(); + } + + // + result = startedBar.IsValid(); + if (result) + { + // + isBodyOut = + isBullish + ? startedBar.IsBullish() && + startedBar.GetUp() > Upper() + : startedBar.IsBearish() && + startedBar.GetDown() < Lower(); + } + + // + return result; + } + + /** + * Check Zone Activated or not ... + * First Enter in Opposit Direction of Zone after Start ... + * + * @param forDir: exit direction ... + * @param activatedBar: specified Activation Bar ... + * @param isBodyIn: specified Activation Bar Close is Inside of Zone or not ... + * @param forPeriod: specified Period ... + * + * @return ( bool ) + */ + bool IsActivated( + ENUM_X_DIRECTION forDir, + XOHCL &activatedBar, + bool &isBodyIn, + bool forceBodyOutStarted = true, + ENUM_TIMEFRAMES forPeriod = NULL // + ) + { + // + bool result = false; + + // + isBodyIn = false; + activatedBar.Clean(); + + // + result = HasDirection(forDir) && + IsValidTwoBarZone(); + if (!result) + { + return result; + } + + // + bool isBullish = IsBullish(forDir); + + // + if (!IsSpecifiedValid(forPeriod)) + { + forPeriod = GetPeriod(); + } + + // + XOHCL startedBar; + bool isBodyOut = false; + bool isStarted = IsStarted( + forDir, + startedBar, + isBodyOut, + forPeriod // + ); + result = + !forceBodyOutStarted + ? isStarted + : isStarted && + isBodyOut; + if (!result) + { + // + startedBar.Clean(); + return result; + } + + // + int fromIndex = startedBar.Index() - 1; + + // + for (int i = fromIndex; i >= 0; i--) + { + // + XOHCL iBar; + bool isInited = iBar.Init( + GetSymbol(), + forPeriod, + i // + ); + result = isInited; + if (!result) + { + // + iBar.Clean(); + continue; + } + + // + bool isInsideFromUpper = + // + iBar.high < Upper() || + (iBar.high > Upper() && + iBar.low <= Upper() && + iBar.close <= Upper()) + // + ; + + // + bool isInsideFromLower = + // + iBar.low > Lower() || + (iBar.low < Lower() && + iBar.high >= Lower() && + iBar.close >= Lower()) + // + ; + + // + bool isInside = + isInsideFromUpper || + isInsideFromLower; + if (isInside) + { + // + result = isInside && + isBullish + ? isInsideFromUpper + : isInsideFromLower; + if (result) + { + // + activatedBar = iBar; + iBar.Clean(); + startedBar.Clean(); + break; + } + } + + // + iBar.Clean(); + startedBar.Clean(); + } + + // + result = activatedBar.IsValid(); + if (result) + { + // + isBodyIn = + isBullish + ? activatedBar.IsBearish() && + activatedBar.GetDown() < Upper() + : activatedBar.IsBullish() && + activatedBar.GetUp() > Lower(); + } + + // + return result; + } + + /** + * Check Zone reaked or not ... + * + * @param forDir: exit direction ... + * @param breakedBar: specified Breaked Bar ... + * @param isBodyOut: specified Breaked Bar Close is Out of Zone or not ... + * @param ignoreStart: Ignore Zone Start (Calculate from From()) ... + * @param startedBodyOut: Started Bar Body Close State, if use Start for Calculation ... + * @param forPeriod: specified Period ... + * + * @return ( bool ) + */ + bool IsBreaked( + ENUM_X_DIRECTION forDir, + XOHCL &breakedBar, + bool &isBodyOut, + bool ignoreStart = false, + bool startedBodyOut = false, + ENUM_TIMEFRAMES forPeriod = NULL // + ) + { + // + bool result = false; + + // + isBodyOut = false; + breakedBar.Clean(); + + // + result = HasDirection(forDir) && + IsValidTwoBarZone(); + if (!result) + { + return result; + } + + // + bool isBullish = IsBullish(forDir); + + // + if (!IsSpecifiedValid(forPeriod)) + { + forPeriod = GetPeriod(); + } + + // + int fromIndex = -1; + if (!ignoreStart) + { + // + XOHCL startedBar; + bool isBodyOut = false; + bool isStarted = IsStarted( + forDir, + startedBar, + isBodyOut, + forPeriod // + ); + + // + bool isStartPassed = + !startedBodyOut + ? isStarted + : isStarted && + isBodyOut; + if (isStartPassed) + { + fromIndex = startedBar.Index() - 1; + } + + // + startedBar.Clean(); + } + else + { + // + fromIndex = iBarShift( + GetSymbol(), + forPeriod, + From() // + ); + } + + // + result = IsValidIndex(fromIndex); + if (!result) + { + return result; + } + + // + for (int i = fromIndex; i >= 0; i--) + { + // + XOHCL iBar; + bool isInited = iBar.Init( + GetSymbol(), + forPeriod, + i // + ); + result = isInited; + if (!result) + { + // + iBar.Clean(); + continue; + } + + // + bool isBreakedFromUpper = + // + iBar.low > Upper() || + (iBar.low <= Upper() && + iBar.high > Upper() && + iBar.close > Upper()) + // + ; + + // + bool isBreakedFromLower = + // + iBar.low < Lower() || + (iBar.high >= Lower() && + iBar.low < Lower() && + iBar.close < Lower()) + // + ; + + // + bool isBreaked = + isBreakedFromUpper || + isBreakedFromLower; + if (isBreaked) + { + // + result = isBreaked && + (isBullish + ? isBreakedFromLower + : isBreakedFromUpper); + if (result) + { + // + breakedBar = iBar; + iBar.Clean(); + break; + } + } + + // + iBar.Clean(); + } + + // + result = breakedBar.IsValid(); + if (result) + { + // + isBodyOut = + isBullish + ? breakedBar.IsBearish() && + breakedBar.GetDown() < Lower() + : breakedBar.IsBullish() && + breakedBar.GetUp() > Upper(); + } + + // + return result; + } + + /** + * Check Zone Worked or not ... + * + * @param forDir: exit direction ... + * @param workedBar: specified Worked Bar ... + * @param isBodyOut: specified Worked Bar Close is Out of Zone or not ... + * @param ignoreActivation: Ignore Zone Activation (Calculate from From()) ... + * @param activationStartedOut: Specified Zone Start Bar State ... + * @param activationBodyIn: Specified Zone Activation Bar State ... + * @param forPeriod: specified Period ... + * + * @return ( bool ) + */ + bool IsWorked( + ENUM_X_DIRECTION forDir, + XOHCL &workedBar, + bool &isBodyOut, + bool ignoreActivation = false, + bool activationStartedOut = false, + bool activationBodyIn = false, + ENUM_TIMEFRAMES forPeriod = NULL // + ) + { + // + bool result = false; + + // + isBodyOut = false; + workedBar.Clean(); + + // + result = HasDirection(forDir) && + IsValidTwoBarZone(); + if (!result) + { + return result; + } + + // + bool isBullish = IsBullish(forDir); + + // + if (!IsSpecifiedValid(forPeriod)) + { + forPeriod = GetPeriod(); + } + + // + int fromIndex = -1; + if (!ignoreActivation) + { + // + XOHCL activatedBar; + bool isBodyIn = false; + bool isActivated = IsActivated( + forDir, + activatedBar, + isBodyIn, + activationStartedOut, + forPeriod // + ); + + // + bool isActivationPassed = + !activationBodyIn + ? isActivated + : isActivated && + isBodyIn; + if (isActivationPassed) + { + fromIndex = activatedBar.Index() - 1; + } + + // + activatedBar.Clean(); + } + else + { + // + fromIndex = iBarShift( + GetSymbol(), + forPeriod, + From() // + ); + } + + // + result = IsValidIndex(fromIndex); + if (!result) + { + return result; + } + + // + for (int i = fromIndex; i >= 0; i--) + { + // + XOHCL iBar; + bool isInited = iBar.Init( + GetSymbol(), + forPeriod, + i // + ); + result = isInited; + if (!result) + { + // + iBar.Clean(); + continue; + } + + // + bool isBreakedFromUpper = + // + iBar.low > Upper() || + (iBar.low <= Upper() && + iBar.high > Upper() && + iBar.close > Upper()) + // + ; + + // + bool isBreakedFromLower = + // + iBar.low < Lower() || + (iBar.high >= Lower() && + iBar.low < Lower() && + iBar.close < Lower()) + // + ; + + // + bool isBreaked = + isBreakedFromUpper || + isBreakedFromLower; + if (isBreaked) + { + // + result = isBreaked && + isBullish + ? isBreakedFromUpper + : isBreakedFromLower; + if (result) + { + // + workedBar = iBar; + iBar.Clean(); + break; + } + } + + // + iBar.Clean(); + } + + // + result = workedBar.IsValid(); + if (result) + { + // + isBodyOut = + isBullish + ? workedBar.IsBullish() && + workedBar.GetUp() > Upper() + : workedBar.IsBearish() && + workedBar.GetDown() < Lower(); + } + + // + return result; + } + + /** + * Check to Find Nearest Bar which Breakes Upper ... + * + * @param bar: XOHCL instance Reference, Breaker Bar ... + * @param forPeriod: ENUM_TIMEFRAMES member, Breaker Bar Detection Period, default is Zone Period ... + * + * @return ( bool ) + */ + bool FindNearestInsideBarFromUpper( + XOHCL &bar, + ENUM_TIMEFRAMES forPeriod = NULL // + ) + { + // + bool result = false; + + // + bar.Clean(); + + // + if (!IsSpecifiedValid(forPeriod)) + { + forPeriod = GetPeriod(); + } + + // + result = IsValid(); + if (!result) + { + return result; + } + + // + int from = 1; + int to = iBarShift( + GetSymbol(), + forPeriod, + From() // + ); + + // + for (int i = from; i < to; i++) + { + // + XOHCL iBar; + bool isInited = iBar.Init( + GetSymbol(), + forPeriod, + i // + ); + if (!isInited) + { + break; + } + + // + bool isInside = iBar.low < Upper(); + if (isInside) + { + // + bar = iBar; + break; + } + } + + // + result = bar.IsValid(); + + // + return result; + } + + /** + * Check to Find Nearest Bar which Breakes Lower ... + * + * @param bar: XOHCL instance Reference, Breaker Bar ... + * @param forPeriod: ENUM_TIMEFRAMES member, Breaker Bar Detection Period, default is Zone Period ... + * + * @return ( bool ) + */ + bool FindNearestInsideBarFromLower( + XOHCL &bar, + ENUM_TIMEFRAMES forPeriod = NULL // + ) + { + // + bool result = false; + + // + bar.Clean(); + + // + if (!IsSpecifiedValid(forPeriod)) + { + forPeriod = GetPeriod(); + } + + // + result = IsValid(); + if (!result) + { + return result; + } + + // + int from = 1; + int to = iBarShift( + GetSymbol(), + forPeriod, + From() // + ); + + // + for (int i = from; i < to; i++) + { + // + XOHCL iBar; + bool isInited = iBar.Init( + GetSymbol(), + forPeriod, + i // + ); + if (!isInited) + { + break; + } + + // + bool isInside = iBar.high > Lower(); + if (isInside) + { + // + bar = iBar; + break; + } + } + + // + result = bar.IsValid(); + + // + return result; + } + + // + // Overrides ... + + void Clean() override + { + // + mStartBar.Clean(); + mEndBar.Clean(); + mUpper = 0; + mLower = 0; + mUseStartBarForUpper = false; + mType = X_POI_NONE; + } + + datetime From() override + { + return mFrom; + } + + datetime To() override + { + return mTo; + } + + string GetTag() override + { + // + string result = NULL; + + // + if (!IsValidTwoBarZone()) + { + return result; + } + + // + string hash = ToMD5(mStartBar.GetTag() + mSep + mEndBar.GetTag()); + + // + result = + // + TypeAsString() + mSep + + ToString(mStartBar.period) + mSep + + hash + // + ; + + // + return result; + } + + string GetTooltip() override + { + // + string result = NULL; + + // + if (!IsValidTwoBarZone()) + { + return result; + } + + // + return result; + } + + // + protected: + // + // Props ... + XOHCL mStartBar; // Start (Oldest) Bar ... + XOHCL mEndBar; // End (Newest) Bar ... + bool mUseStartBarForUpper; // Use Start Bar for Upper Calculation ... + ENUM_X_PRICE mUpperPrice; // Upper Price Selection + ENUM_X_PRICE mLowerPrice; // Lower Price Selection + + /** + * Check Two Bar Zone Validation ... + * + * @return ( bool ) + */ + bool IsValidTwoBarZone() + { + // + bool result = false; + + // + result = mStartBar.IsValid() && + mEndBar.IsValid() && + mStartBar.symbol == mEndBar.symbol && + mStartBar.period == mEndBar.period && + mStartBar.time < mEndBar.time && + mType != X_POI_NONE && + IsValidBoundary(); + + // + return result; + } + + // + private: + // + // Props ... + datetime mFrom; + datetime mTo; + + // +}; + +// +// Swing Class ... +class XCSwing : public XCBasePOI +{ + // + public: + // + + // + // Constructor ... + void XCSwing() + { + } + + // + // Deconstructor ... + void ~XCSwing() + { + } + + // + // Tools ... + + /** + * Initialize POI ... + * + * @param bar: XOHCL instance ... + * @param type: ENUM_XPOIS member ... + * + * @return ( bool ) + */ + bool Init( + XOHCL &bar, + ENUM_XPOIS type // + ) + { + // + bool result = false; + + // + result = bar.IsValid() && + (type == X_POI_SWING_HIGH || + type == X_POI_SWING_LOW); + if (!result) + { + return result; + } + + // + mBar = bar; + mType = type; + + // + result = IsValid(); + + // + return result; + } + + // + // Getter(s) / Setter(s) ... + + /** + * Fill Bar as XOHCL struct ... + * + * @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; + } + + /** + * Get Time of Swing ... + * + * @return ( datetime ) + */ + datetime GetTime() + { + // + datetime result = NULL; + + // + if (!IsValid() || !mBar.IsValid()) + { + return result; + } + + // + result = mBar.time; + + // + return result; + } + + ENUM_TIMEFRAMES GetPeriod() + { + // + ENUM_TIMEFRAMES result = NULL; + + // + XOHCL bar; + bool isFilled = FillBar(bar); + if (!isFilled) + { + return result; + } + + // + result = bar.period; + + // + return result; + } + + /** + * Check Swing High or not ... + * + * @return ( bool ) + */ + bool IsSwingHigh() + { + // + bool result = false; + + // + result = IsValid(); + if (!result) + { + return result; + } + + // + result = + Type() == X_POI_SWING_HIGH; + + // + return result; + } + + /** + * Check Swing Low or not ... + * + * @return ( bool ) + */ + bool IsSwingLow() + { + // + bool result = false; + + // + result = IsValid(); + if (!result) + { + return result; + } + + // + result = + Type() == X_POI_SWING_LOW; + + // + return result; + } + + /** + * Get Swing Value ... + * + * @return ( double ) + */ + double GetValue() + { + // + double result = 0; + + // + if (!IsValid()) + { + return result; + } + + // + result = + IsSwingHigh() + ? mBar.high + : mBar.low; + + // + return result; + } + + // + // Overrides ... + + void Clean() override + { + // + mBar.Clean(); + mType = X_POI_NONE; + } + + bool IsValid() override + { + // + bool result = false; + + // + result = mBar.IsValid() && + (mType == X_POI_SWING_HIGH || + mType == X_POI_SWING_LOW); + + // + return result; + } + + string GetTag() override + { + // + string result = NULL; + + // + if (!IsValid()) + { + return result; + } + + // + string hash = ToMD5(mBar.GetTag()); + + // + string subType = IsSwingHigh() + ? "High" + : "Low"; + + // + result = + // + TypeAsString() + mSep + + subType + mSep + + ToString(mBar.period) + mSep + + hash + // + ; + + // + return result; + } + + string GetTooltip() override + { + // + string result = NULL; + + // + if (!IsValid()) + { + return result; + } + + // + return result; + } + + // + protected: + // + // Props ... + XOHCL mBar; // Swing Bar ... + + // + private: + // +}; + +// +// Supply Zone ... +class XCSupplyZone : public XCBarZone +{ + // + public: + // + + // + // Constructor ... + void XCSupplyZone() + { + } + + // + // Deconstructor ... + void ~XCSupplyZone() + { + } + + // + // Tools ... + + /** + * Initialize POI ... + * + * @param bar: XOHCL instance ... + * @param range: Integer, Detection Range ... + * + * @return ( bool ) + */ + bool Init( + XOHCL &bar, + int range = 0, + bool useRangeAsStart = false // + ) + { + // + bool result = false; + + // + result = bar.IsValid(); + if (!result) + { + return result; + } + + // + result = InitBarZone( + bar, + X_POI_SUPPLY_ZONE, + X_PRICE_HIGH, + X_PRICE_LOW // + ); + if (!result) + { + return result; + } + + // + result = IsValid(); + if (result && + range > 0) + { + // + datetime time = bar.time; + int periodSeconds = PeriodSeconds(bar.period); + + // + datetime from = + !useRangeAsStart + ? (datetime)((int)time - (range * periodSeconds)) + : time; + datetime to = (datetime)((int)time + (range * periodSeconds)); + + // + From(from); + To(to); + } + + // + return result; + } + + // + // Getter(s) / Setter(s) ... + + // + // Overrides ... + + bool IsValid() override + { + // + bool result = false; + + // + result = IsValidBarZone() && + mType == X_POI_SUPPLY_ZONE; + + // + return result; + } + + // + protected: + // + + // + private: + // + + // +}; + +// +// Demand Zone ... +class XCDemandZone : public XCBarZone +{ + // + public: + // + + // + // Constructor ... + void XCDemandZone() + { + } + + // + // Deconstructor ... + void ~XCDemandZone() + { + } + + // + // Tools ... + + /** + * Initialize POI ... + * + * @param bar: XOHCL instance ... + * @param range: Integer, Detection Range ... + * + * @return ( bool ) + */ + bool Init( + XOHCL &bar, + int range = 0, + bool useRangeAsStart = false // + ) + { + // + bool result = false; + + // + result = bar.IsValid(); + if (!result) + { + return result; + } + + // + result = InitBarZone( + bar, + X_POI_DEMAND_ZONE, + X_PRICE_HIGH, + X_PRICE_LOW // + ); + if (!result) + { + return result; + } + + // + result = IsValid(); + if (result && + range > 0) + { + // + datetime time = bar.time; + int periodSeconds = PeriodSeconds(bar.period); + + // + datetime from = + !useRangeAsStart + ? (datetime)((int)time - (range * periodSeconds)) + : time; + datetime to = (datetime)((int)time + (range * periodSeconds)); + + // + From(from); + To(to); + } + + // + return result; + } + + // + // Getter(s) / Setter(s) ... + + // + // Overrides ... + + bool IsValid() override + { + // + bool result = false; + + // + result = IsValidBarZone() && + mType == X_POI_DEMAND_ZONE; + + // + return result; + } + + // + protected: + // + + // + private: + // + + // +}; + +// +// Support Zone ... +class XCSupportZone : public XCBarZone +{ + // + public: + // + + // + // Constructor ... + void XCSupportZone() + { + } + + // + // Deconstructor ... + void ~XCSupportZone() + { + } + + // + // Tools ... + + /** + * Initialize POI ... + * + * @param bar: XOHCL instance ... + * @param range: Integer, Detection Range ... + * + * @return ( bool ) + */ + bool Init( + XOHCL &bar, + int range = 0, + bool useRangeAsStart = false // + ) + { + // + bool result = false; + + // + result = bar.IsValid(); + if (!result) + { + return result; + } + + // + result = InitBarZone( + bar, + X_POI_SUPPORT_ZONE, + X_PRICE_DOWN, + X_PRICE_LOW // + ); + if (!result) + { + return result; + } + + // + result = IsValid(); + if (result && + range > 0) + { + // + datetime time = bar.time; + int periodSeconds = PeriodSeconds(bar.period); + + // + datetime from = + !useRangeAsStart + ? (datetime)((int)time - (range * periodSeconds)) + : time; + datetime to = (datetime)((int)time + (range * periodSeconds)); + + // + From(from); + To(to); + } + + // + return result; + } + + // + // Getter(s) / Setter(s) ... + + // + // Overrides ... + + bool IsValid() override + { + // + bool result = false; + + // + result = IsValidBarZone() && + mType == X_POI_SUPPORT_ZONE; + + // + return result; + } + + // + protected: + // + + // + private: + // + + // +}; + +// +// Resistance Zone ... +class XCResistanceZone : public XCBarZone +{ + // + public: + // + + // + // Constructor ... + void XCResistanceZone() + { + } + + // + // Deconstructor ... + void ~XCResistanceZone() + { + } + + // + // Tools ... + + /** + * Initialize POI ... + * + * @param bar: XOHCL instance ... + * @param range: Integer, Detection Range ... + * + * @return ( bool ) + */ + bool Init( + XOHCL &bar, + int range = 0, + bool useRangeAsStart = false // + ) + { + // + bool result = false; + + // + result = bar.IsValid(); + if (!result) + { + return result; + } + + // + result = InitBarZone( + bar, + X_POI_RESISTANCE_ZONE, + X_PRICE_HIGH, + X_PRICE_UP // + ); + if (!result) + { + return result; + } + + // + result = IsValid(); + if (result && + range > 0) + { + // + datetime time = bar.time; + int periodSeconds = PeriodSeconds(bar.period); + + // + datetime from = + !useRangeAsStart + ? (datetime)((int)time - (range * periodSeconds)) + : time; + datetime to = (datetime)((int)time + (range * periodSeconds)); + + // + From(from); + To(to); + } + + // + return result; + } + + // + // Getter(s) / Setter(s) ... + + // + // Overrides ... + + bool IsValid() override + { + // + bool result = false; + + // + result = IsValidBarZone() && + mType == X_POI_RESISTANCE_ZONE; + + // + return result; + } + + // + protected: + // + + // + private: + // + + // +}; + +// +// Order Block ... +class XCOrderBlock : public XCBarZone +{ + // + public: + // + + // + // Constructor ... + void XCOrderBlock() + { + } + + // + // Deconstructor ... + void ~XCOrderBlock() + { + } + + // + // Tools ... + + /** + * Initialize POI ... + * + * @param bar: XOHCL instance ... + * @param dir: ENUM_X_DIRECTION member ... + * + * @return ( bool ) + */ + bool Init( + XOHCL &bar, + ENUM_X_DIRECTION dir // + ) + { + // + bool result = false; + + // + result = bar.IsValid() && + (dir == X_DIRECTION_BULLISH || + dir == X_DIRECTION_BEARISH); + if (!result) + { + return result; + } + + // + ENUM_XPOIS mTT = + IsSpecifiedBullish(dir) + ? X_POI_BULLISH_ORDERBLOCK + : X_POI_BEARISH_ORDERBLOCK; + + // + result = InitBarZone( + bar, + mTT, + X_PRICE_HIGH, + X_PRICE_LOW // + ); + if (!result) + { + return result; + } + + // + result = IsValid(); + + // + return result; + } + + // + // Getter(s) / Setter(s) ... + + /** + * Check is Bullish ... + * + * @return ( bool ) + */ + bool IsBullish() + { + // + bool result = false; + + // + result = IsValid() && + Type() == X_POI_BULLISH_ORDERBLOCK; + + // + return result; + } + + /** + * Check is Bearish ... + * + * @return ( bool ) + */ + bool IsBearish() + { + // + bool result = false; + + // + result = IsValid() && + Type() == X_POI_BEARISH_ORDERBLOCK; + + // + return result; + } + + ENUM_X_DIRECTION GetDirection() + { + // + ENUM_X_DIRECTION result = X_DIRECTION_NONE; + + // + if (!IsValid()) + { + return result; + } + + // + result = + IsBullish() + ? X_DIRECTION_BULLISH + : X_DIRECTION_BEARISH; + + // + return result; + } + + // + // Overrides ... + + bool IsValid() override + { + // + bool result = false; + + // + result = IsValidBarZone() && + (mType == X_POI_BULLISH_ORDERBLOCK || + mType == X_POI_BEARISH_ORDERBLOCK); + + // + return result; + } + + // + protected: + // + + // + private: + // + + // +}; + +// +// Rejection Bar ... +class XCRejectionBar : public XCBarZone +{ + // + public: + // + + // + // Constructor ... + void XCRejectionBar() + { + } + + // + // Deconstructor ... + void ~XCRejectionBar() + { + } + + // + // Tools ... + + /** + * Initialize POI ... + * + * @param bar: XOHCL instance ... + * + * @return ( bool ) + */ + bool Init( + XOHCL &bar // + ) + { + // + bool result = false; + + // + result = bar.IsValid(); + if (!result) + { + return result; + } + + // + bool isBullish = + bar.GetLowShadow() > bar.GetHighShadow(); + bool isBearish = + bar.GetHighShadow() > bar.GetLowShadow(); + result = isBullish || + isBearish; + if (!result) + { + return result; + } + + // + ENUM_X_PRICE upPrice = isBullish + ? X_PRICE_HIGH + : X_PRICE_DOWN; + // + ENUM_X_PRICE loPrice = isBullish + ? X_PRICE_UP + : X_PRICE_LOW; + + // + result = InitBarZone( + bar, + X_POI_REJECTION_BAR, + upPrice, + loPrice // + ); + if (!result) + { + return result; + } + + // + result = IsValid(); + + // + return result; + } + + // + // Getter(s) / Setter(s) ... + + /** + * Check is Bullish ... + * + * @return ( bool ) + */ + bool IsBullish() + { + // + bool result = false; + + // + result = IsValid() && + Type() == X_POI_REJECTION_BAR && + mBar.GetLowShadow() > mBar.GetHighShadow(); + + // + return result; + } + + /** + * Check is Bearish ... + * + * @return ( bool ) + */ + bool IsBearish() + { + // + bool result = false; + + // + result = IsValid() && + Type() == X_POI_REJECTION_BAR && + mBar.GetHighShadow() > mBar.GetLowShadow(); + + // + return result; + } + + // + // Overrides ... + + bool IsValid() override + { + // + bool result = false; + + // + result = IsValidBarZone() && + mType == X_POI_REJECTION_BAR; + + // + return result; + } + + // + protected: + // + + // + private: + // + + // +}; + +// +// Momentum Bar ... +class XCMomentumBar : public XCBarZone +{ + // + public: + // + + // + // Constructor ... + void XCMomentumBar() + { + } + + // + // Deconstructor ... + void ~XCMomentumBar() + { + } + + // + // Tools ... + + /** + * Initialize POI ... + * + * @param bar: XOHCL instance ... + * + * @return ( bool ) + */ + bool Init( + XOHCL &bar // + ) + { + // + bool result = false; + + // + result = bar.IsValid(); + if (!result) + { + return result; + } + + // + bool isBullish = bar.IsBullish(); + bool isBearish = bar.IsBearish(); + result = isBullish || + isBearish; + if (!result) + { + return result; + } + + // + result = InitBarZone( + bar, + X_POI_MOMENTUM_BAR, + X_PRICE_HIGH, + X_PRICE_LOW // + ); + if (!result) + { + return result; + } + + // + result = IsValid(); + + // + return result; + } + + // + // Getter(s) / Setter(s) ... + + /** + * Check is Bullish ... + * + * @return ( bool ) + */ + bool IsBullish() + { + // + bool result = false; + + // + result = IsValid() && + mBar.IsBullish() && + Type() == X_POI_MOMENTUM_BAR; + + // + return result; + } + + /** + * Check is Bearish ... + * + * @return ( bool ) + */ + bool IsBearish() + { + // + bool result = false; + + // + result = IsValid() && + mBar.IsBearish() && + Type() == X_POI_MOMENTUM_BAR; + + // + return result; + } + + // + // Overrides ... + + bool IsValid() override + { + // + bool result = false; + + // + result = IsValidBarZone() && + mType == X_POI_MOMENTUM_BAR; + + // + return result; + } + + // + protected: + // + + // + private: + // + + // +}; + +// +// Fair Value Gap ... +class XCFVG : public XCTwoBarZone +{ + // + public: + // + + // + // Constructor ... + void XCFVG() + { + } + + // + // Deconstructor ... + void ~XCFVG() + { + } + + // + // Tools ... + + /** + * Initialize POI ... + * + * @param startBar: XOHCL instance ... + * @param endBar: XOHCL instance ... + * @param dir: ENUM_X_DIRECTION member ... + * + * @return ( bool ) + */ + bool Init( + XOHCL &startBar, + XOHCL &endBar, + ENUM_X_DIRECTION dir // + ) + { + // + bool result = false; + + // + result = endBar.IsValid() && + startBar.IsValid() && + (dir == X_DIRECTION_BULLISH || + dir == X_DIRECTION_BEARISH); + if (!result) + { + return result; + } + + // + bool isDirBullish = IsSpecifiedBullish(dir); + ENUM_XPOIS mTT = + isDirBullish + ? X_POI_BULLISH_FVG + : X_POI_BEARISH_FVG; + + // + ENUM_X_PRICE startPrice = isDirBullish + ? X_PRICE_HIGH + : X_PRICE_LOW; + ENUM_X_PRICE endPrice = isDirBullish + ? X_PRICE_LOW + : X_PRICE_HIGH; + + // + result = InitTwoBarZone( + startBar, + endBar, + mTT, + startPrice, + endPrice // + ); + if (!result) + { + return result; + } + + // + result = IsValid(); + + // + return result; + } + + // + // Getter(s) / Setter(s) ... + + /** + * Check is Bullish ... + * + * @return ( bool ) + */ + bool IsBullish() + { + // + bool result = false; + + // + result = IsValid() && + Type() == X_POI_BULLISH_FVG; + + // + return result; + } + + /** + * Check is Bearish ... + * + * @return ( bool ) + */ + bool IsBearish() + { + // + bool result = false; + + // + result = IsValid() && + Type() == X_POI_BEARISH_FVG; + + // + return result; + } + + ENUM_X_DIRECTION GetDirection() + { + // + ENUM_X_DIRECTION result = X_DIRECTION_NONE; + + // + if (!IsValid()) + { + return result; + } + + // + result = + IsBullish() + ? X_DIRECTION_BULLISH + : X_DIRECTION_BEARISH; + + // + return result; + } + + // + // Overrides ... + + bool IsValid() override + { + // + bool result = false; + + // + result = IsValidTwoBarZone() && + (mType == X_POI_BULLISH_FVG || + mType == X_POI_BEARISH_FVG); + + // + return result; + } + + // + protected: + // + + // + private: + // + + // +}; + +// +// Ticks Zones ... + +// +class XCTickZone : public CObject +{ + // + // Public ... + public: + // + // Props ... + string symbol; + ENUM_TIMEFRAMES period; + + // + double high; + double low; + int ticks; + double percent; + + // + ulong volume; + double volumePercent; + + // + // Compare Two Zone With Each Other ... + virtual int Compare( + const CObject *node, + const int mode = 0 // + ) const + { + // + const XCTickZone *other = (XCTickZone *)node; + + // + return other.ticks - ticks; + } + + // + bool IsValid() + { + // + bool result = false; + + // + result = high > 0 && + low > 0 && + high > low && + ticks > 0 && + percent > 0; + + // + return result; + } + + // + // Protected ... + protected: + // + // Private ... + private: + // +}; + +// +class XCTicksZone : public XCTwoBarZone +{ + // + public: + // + + // + // Constructor ... + void XCTicksZone() + { + Default(); + } + + // + // Deconstructor ... + void ~XCTicksZone() + { + } + + // + // Getter(s) / Setter(s) ... + + /** + * Get Number of Ticks Levels ... + * + * @return ( int ) + */ + int Levels() + { + return mLevels; + } + + /** + * Set Number of Ticks Levels ... + * + * @return ( int ) + */ + void Levels(int value) + { + // + if (value < 2) + { + value = 2; + } + + // + mLevels = value; + } + + /** + * Apply Default Config ... + */ + virtual void Default() + { + // + Levels(10); + } + + // + // Tools ... + + /** + * Initialize POI ... + * + * @param startBar: XOHCL instance ... + * @param endBar: XOHCL instance ... + * + * @return ( bool ) + */ + bool Init( + XOHCL &startBar, + XOHCL &endBar, + ENUM_TIMEFRAMES forPeriod = NULL // + ) + { + // + bool result = false; + + // + result = endBar.IsValid() && + startBar.IsValid(); + if (!result) + { + return result; + } + + // + if (!IsSpecifiedValid(forPeriod)) + { + forPeriod = endBar.period; + } + + // + // Calculate Start and End Time ... + datetime from = startBar.time; + datetime to = endBar.time; + ulong fromM = ((ulong)to * 1000); + ulong toM = ((ulong)from * 1000); + + // + // Symbol and Period ... + string symbol = startBar.symbol; + ENUM_TIMEFRAMES period = startBar.period; + + // + // Prepare Zones Array ... + mZones.Clear(); + + // + // Retrieve Ticks between Times ... + SpecificClean(mTicks); + int res = CopyTicksRange( + symbol, + mTicks, + COPY_TICKS_ALL, + fromM, + toM // + ); + + // + // Ticks Volumes ... + int ticksVolumeCount = CopyTickVolume( + symbol, + forPeriod, + from, + to, + mTickVolumes // + ); + if (IsValidSize(ticksVolumeCount)) + { + // + mVolumes = 0; + for (int i = 0; i < ticksVolumeCount; i++) + { + mVolumes += mTickVolumes[i]; + } + } + + // + // Retrieve Highs ... + SpecificClean(mHighs); + CopyHigh( + symbol, + period, + from, + to, + mHighs // + ); + + // + // Retrieve Lows ... + SpecificClean(mLows); + CopyLow( + symbol, + period, + from, + to, + mLows // + ); + + // + // Find Highest Value in Range ... + int highIDX = ArrayMaximum(mHighs); + mRangeHigh = mHighs[highIDX]; + + // + // Find Lowest Value in Range ... + int lowIDX = ArrayMinimum(mLows); + mRangeLow = mLows[lowIDX]; + + // + datetime mTimes[]; + CopyTime( + symbol, + period, + from, + to, + mTimes // + ); + mRangeHighTime = mTimes[highIDX]; + mRangeLowTime = mTimes[lowIDX]; + + // + double mRangeSize = mRangeHigh - mRangeLow; + + // + // Create Zones ... + for (int i = 0; i < Levels(); i++) + { + // + // Instance a New Zone ... + XCTickZone *iZone = new XCTickZone(); + + // + iZone.symbol = symbol; + iZone.period = period; + + // + // Calculate Each Zones High / Low based on Range ... + double iH = mRangeHigh - mRangeSize * i / Levels(); + double iL = mRangeHigh - mRangeSize * (i + 1) / Levels(); + + // + // Set Zone High Low Properties ... + iZone.low = iL; + iZone.high = iH; + + // + // Add Zone to Zone Array Objects ... + mZones.Add(iZone); + } + + // + // Calculate Each Zone Ticks ... + int ticksCount = ArraySize(mTicks); + for (int i = 0; i < ticksCount; i++) + { + // + // Retrieve Tick ... + MqlTick iTick = mTicks[i]; + + // + // Loop through Zones ... + for (int j = 0; j < Levels(); j++) + { + // + // Rejrieve j indexed Zone Object ... + XCTickZone *jZone = mZones.At(j); + + // + bool isInRange = IsTickInZoneRange( + iTick, + jZone // + ); + if (isInRange) + { + // + jZone.ticks++; + break; + } + } + } + + // + // Calculating Zone Percents ... + for (int i = 0; i < Levels(); i++) + { + // + XCTickZone *iZone = mZones.At(i); + + // + double percent = CalculateZoneTickPercent(iZone); + iZone.percent = percent; + } + + // + // Sort Zones Based on Percents ... + mZones.Sort(); + + // + mUpper = mRangeHigh; + mLower = mRangeLow; + mType = X_POI_TICKS_ZONES; + mEndBar = endBar; + mStartBar = startBar; + From(endBar.time); + To(startBar.time); + + // + result = IsValid(); + if (!result) + { + return result; + } + + // + // Try to Find Out PERIOD_1M times in each zone ... + datetime to1M = (datetime)((int)endBar.time + PeriodSeconds(period) - 60); + int to1MIndex = iBarShift( + symbol, + forPeriod, + to1M // + ); + int from1MIndex = iBarShift( + symbol, + forPeriod, + from // + ); + for (int i = from1MIndex; i > to1MIndex; i--) + { + // + XOHCL iBar; + bool isInited = iBar.Init( + symbol, + forPeriod, + i // + ); + if (!isInited) + { + continue; + } + ulong iVolume = iTickVolume( + symbol, + forPeriod, + i // + ); + + // + // Loop through Zones ... + for (int j = 0; j < Levels(); j++) + { + // + XCTickZone *jZone = mZones.At(j); + if (!jZone.IsValid()) + { + continue; + } + + // + // Check iBar is Inside jZone ... + bool isIBarInside = + iBar.GetUp() < jZone.high && + iBar.GetDown() > jZone.low; + // iBar.low < jZone.high || + // iBar.high > jZone.low; + if (isIBarInside) + { + jZone.volume += iVolume; + } + } + } + + // + // Calculate Volume Percent ... + for (int i = 0; i < Levels(); i++) + { + // + XCTickZone *iZone = mZones.At(i); + + // + if (mVolumes > 0) + { + iZone.volumePercent = (double)(iZone.volume * 100 / mVolumes); + } + } + + // + return result; + } + + // + // Getter(s) / Setter(s) ... + + /** + * Retrieve Zones Count ... + * + * @return ( int ) + */ + int Count() + { + return mZones.Total(); + } + + /** + * Retrieve Specified Sorted Zones ... + * + * @param index: Integer ... + * + * @return ( XCTickZone * ) + */ + XCTickZone *GetZone(int index) + { + // + if (!IsValidIndex(index)) + { + return NULL; + } + + // + return mZones.At(index); + } + + /** + * Calculate Liquidity Percent for Specified Direction ... + * + * @param forDirection: ENUM_X_DIRECTION member, Specified Liquidity ... + * @param price: Double, Specified Price ... + * + * @return ( double ) + */ + double CalculateLiquidityPercent( + ENUM_X_DIRECTION forDirection, + double price // + ) + { + // + double result = 0; + + // + int count = Count(); + if (price <= 0 || + !IsValid() || + !IsValidSize(count) || + forDirection == X_DIRECTION_ALL || + forDirection == X_DIRECTION_NONE) + { + return result; + } + + // + bool isBullish = forDirection == X_DIRECTION_BULLISH; + + // + for (int i = 0; i < count; i++) + { + // + XCTickZone *iZone = GetZone(i); + + // + if (iZone.IsValid()) + { + // + result += !isBullish && + price > iZone.high + ? iZone.percent + : isBullish && + price < iZone.low + ? iZone.percent + : 0; + } + } + + // + return result; + } + + // + // Overrides ... + bool IsValid() override + { + // + bool result = false; + + // + result = + IsValidFrom() && + IsValidTwoBarZone() && + Levels() > 0 && + mZones.Total() == Levels() && + mRangeHigh > 0 && + mRangeLow > 0; + + // + return result; + } + + // + bool GetMaxTickZone(XCTickZone *&zone) + { + // + bool result = false; + + // + zone = NULL; + + // + result = IsValid(); + if (!result) + { + return result; + } + + // + int count = Count(); + for (int i = 0; i < count; i++) + { + // + XCTickZone *iZone = GetZone(i); + + // + bool canSet = + zone == NULL + ? true + : zone.ticks < iZone.ticks + ? true + : false; + if (canSet) + { + zone = iZone; + } + + // + ZeroMemory(iZone); + } + + // + result = zone != NULL && + zone.IsValid(); + + // + return result; + } + + // + bool GetMinTickZone(XCTickZone *&zone) + { + // + bool result = false; + + // + zone = NULL; + + // + result = IsValid(); + if (!result) + { + return result; + } + + // + int count = Count(); + for (int i = 0; i < count; i++) + { + // + XCTickZone *iZone = GetZone(i); + + // + bool canSet = + zone == NULL + ? true + : zone.ticks > iZone.ticks + ? true + : false; + if (canSet) + { + zone = iZone; + } + + // + ZeroMemory(iZone); + } + + // + result = zone != NULL && + zone.IsValid(); + + // + return result; + } + + // + bool GetMaxVolumeZone(XCTickZone *&zone) + { + // + bool result = false; + + // + zone = NULL; + + // + result = IsValid(); + if (!result) + { + return result; + } + + // + int count = Count(); + for (int i = 0; i < count; i++) + { + // + XCTickZone *iZone = GetZone(i); + + // + bool canSet = + zone == NULL + ? true + : zone.volume < iZone.volume + ? true + : false; + if (canSet) + { + zone = iZone; + } + + // + ZeroMemory(iZone); + } + + // + result = zone != NULL && + zone.IsValid(); + + // + return result; + } + + // + bool GetMinVolumeZone(XCTickZone *&zone) + { + // + bool result = false; + + // + zone = NULL; + + // + result = IsValid(); + if (!result) + { + return result; + } + + // + int count = Count(); + for (int i = 0; i < count; i++) + { + // + XCTickZone *iZone = GetZone(i); + + // + bool canSet = + zone == NULL + ? true + : zone.volume > iZone.volume + ? true + : false; + if (canSet) + { + zone = iZone; + } + + // + ZeroMemory(iZone); + } + + // + result = zone != NULL && + zone.IsValid(); + + // + return result; + } + + // + protected: + // + + // + private: + // + // Props ... + + // + MqlTick mTicks[]; + double mHighs[]; + double mLows[]; + ulong mVolumes; + ulong mTickVolumes[]; + double mRangeHigh; + datetime mRangeHighTime; + double mRangeLow; + datetime mRangeLowTime; + + // + int mLevels; // Number of Ticks Levels ... + + // + CArrayObj mZones; + + /** + * Check a Tick is in a Zone rage or not ... + * + * @param tick: MqlTick instance ... + * @param zone: XCTickZone instance ... + * + * @return ( bool ) + */ + bool IsTickInZoneRange( + MqlTick &tick, + XCTickZone *zone // + ) + { + // + bool result = false; + + // + result = + // + tick.bid >= zone.low && + tick.bid <= zone.high + // + ; + + // + return result; + } + + /** + * Calculate Zone Tick Percent ... + * + * @param zone: XCTickZone instance ... + * @param normalizationDigits: Integer ... + * + * @return ( double ) + */ + double CalculateZoneTickPercent( + XCTickZone *zone, + int normalizationDigits = 2 // + ) + { + // + double result = 0; + + // + if (normalizationDigits < 2 || normalizationDigits > 5) + { + normalizationDigits = 2; + } + + // + int ticksCount = ArraySize(mTicks); + if (ticksCount <= 0) + { + return result; + } + + // + result = (double)zone.ticks / ticksCount * 100; + result = NormalizeDouble(result, normalizationDigits); + + // + return result; + } + + // +}; + +// +// 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: + // + + // +}; + +// +// 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: + // + + // +}; diff --git a/Documents/BKP/x-saherelm.x-cobject.class.mq5 b/Documents/BKP/x-saherelm.x-cobject.class.mq5 new file mode 100644 index 00000000..91cc37c0 --- /dev/null +++ b/Documents/BKP/x-saherelm.x-cobject.class.mq5 @@ -0,0 +1,3478 @@ +/////////////////////////////////////////////////////// +// +// 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 +#include +#include + +// +// Definitions ... + +enum ENUM_XCHARTOBJECTS +{ + // + // Global ... + X_ZONE_OBJ = 7860, + X_BOX_OBJ = 7861, + X_BAR_ARROW_OBJ = 7862, + // + X_SIGNAL_OBJ = 8860, + X_TREND_OBJ = 8861, + X_XPVPIVOT_OBJ = 8862, + X_OHCL_OBJ = 8863, + X_RR_OBJ = 8864, + // + // 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, + X_TICK_ZONE_OBJ = 9876, + X_TICKS_ZONE_OBJ = 9877, + X_CONSOLIDATION_ZONE_OBJ = 9878, +}; + +enum ENUM_X_CHART_IDS +{ + X_TO, + X_FROM, + X_UPPER, + X_LOWER, + X_ENTRY, + X_TARGET, + X_SL, + X_TP, + X_BAR_H_SHW, + X_BAR_BDY, + X_BAR_L_SHW, +}; + +string ToString(ENUM_X_CHART_IDS value) +{ + // + string result = NULL; + + // + switch (value) + { + // + case X_TO: + result = "TO"; + break; + + // + case X_FROM: + result = "FROM"; + break; + + // + case X_UPPER: + result = "UPPER"; + break; + + // + case X_LOWER: + result = "LOWER"; + break; + + // + case X_ENTRY: + result = "ENTRY"; + break; + + // + case X_TARGET: + result = "TARGET"; + break; + + // + case X_SL: + result = "SL"; + break; + + // + case X_TP: + result = "TP"; + break; + + // + case X_BAR_H_SHW: + result = "HSHW"; + break; + + // + case X_BAR_BDY: + result = "BODY"; + break; + + // + case X_BAR_L_SHW: + result = "LSHW"; + break; + + // + } + + // + return result; +} + +// +// Extensions ... + +/** + * Converts a XBoxZone struct to XSignal instance ... + * + * @param box: XBoxZone instance reference, provide source info ... + * @param signal: XSignal instance reference, holds prepared converted signal ... + * + * @return ( bool ) + */ +bool ToSignal( + XBoxZone &box, + XSignal &signal, + double &rewardRatios[], + double additionalSL = 0 // +) +{ + // + bool result = false; + + // + signal.Clean(); + + // + result = box.IsValid() && + HasChild(rewardRatios); + if (!result) + { + return result; + } + + // + XOHCL entryBar; + int entryIDX = box.ToIndex(); + if (entryIDX > 0) + { + entryIDX--; + } + result = entryBar.Init( + box.symbol, + box.period, + entryIDX // + ); + if (!result) + { + // + entryBar.Clean(); + + // + return result; + } + + // + bool isBullish = box.IsBullish(); + bool isBearish = box.IsBearish(); + + // + ENUM_POSITION_TYPE iType = + isBullish + ? POSITION_TYPE_BUY + : POSITION_TYPE_SELL; + ENUM_X_POSITION_TYPES iXType = + isBullish + ? X_POSITION_TYPE_LONG + : X_POSITION_TYPE_SHORT; + + // + double points = GetPoints(box.symbol); + + // + double entry = + isBullish + ? box.upper + : box.lower; + entry = entryBar.open; + + // + double sl = + isBullish + ? box.lower + : box.upper; + if (additionalSL > 0) + { + // + sl = + isBullish + ? sl - additionalSL + : sl + additionalSL; + } + + // + double risk = MathAbs(entry - sl); + + // + double tp = 0; + + // + // Calculate Target ... + XTarget targets[]; + + // + double tmp[]; + int idx = -1; + XTarget iTarget; + bool has = false; + double iRatio = 0; + double iReward = 0; + double iRewardPrice = 0; + Copy( + rewardRatios, + tmp // + ); + while (HasChild(tmp)) + { + // + idx = -1; + iRatio = GetMaxWidthIndex( + tmp, + idx // + ); + + // + has = IsValidIndex(idx); + if (!has) + { + break; + } + + // + has = iRatio > 0; + + // + ArrayRemove( + tmp, + idx, + 1 // + ); + + // + bool canSetTP = tp <= 0; + + // + iReward = iRatio * risk; + + // + iRewardPrice = + isBullish + ? entry + iReward + : entry - iReward; + if (canSetTP) + { + tp = iRewardPrice; + } + else + { + // + iTarget.target = iRewardPrice; + AddRef( + iTarget, + targets // + ); + + // + iTarget.Clean(); + } + } + Clean(tmp); + + // + // Filling Signal ... + signal.tp = tp; + signal.sl = sl; + signal.type = iType; + signal.comment = ""; + signal.entry = entry; + signal.time = box.to; + signal.volume = 0.01; + signal.provider = box.type; + signal.symbol = box.symbol; + signal.period = box.period; + signal.mode = X_ORDER_MODE_MARKET; + + // + if (HasChild(targets)) + { + // + Copy( + targets, + signal.targets // + ); + } + + // + result = signal.IsValid(); + + // + // Cleanup Resources ... + + // + if (!result) + { + signal.Clean(); + } + + // + Clean(tmp); + Clean(targets); + iTarget.Clean(); + entryBar.Clean(); + + // + return result; +} + +// +// 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 ... + + // +}; + +class XCBarArrowObject : public XCBaseObject +{ + // + public: + // + + /** + * Creator ... + * + * @param chart_id: Long, Specified Chart ID ... + * @param name: String, Specified Object ID ... + * @param window: Integer, Specified Chart Window ID ... + * @param swing: XCSwing instance ... + * + * @return ( bool ) + */ + bool CreateByBar( + long chart_id, + string name, + int window, + int arrow, + XOHCL &bar, + ENUM_X_PRICE priceType, + double threshold = 5 // + ) + { + // + bool result = false; + + // + result = + // + bar.IsValid() && + IsValid(name) + // + ; + if (!result) + { + return result; + } + + // + datetime time = bar.time; + double price = bar.GetPrice(priceType); + + // + if (threshold > 0) + { + // + double thresholdPrice = threshold * GetPoints(bar.symbol); + if (priceType == X_PRICE_HIGH) + { + price += thresholdPrice; + } + else if (priceType == X_PRICE_LOW) + { + price -= thresholdPrice; + } + } + + // + 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 ... +class XCSwingObject : public XCBarArrowObject +{ + // + public: + // + + /** + * Creator ... + * + * @param chart_id: Long, Specified Chart ID ... + * @param window: Integer, Specified Chart Window ID ... + * @param swing: XCSwing instance ... + * @param prefix: String ... + * + * @return ( bool ) + */ + bool CreateBySwing( + long chart_id, + int window, + int arrow, + XCSwing &swing, + string prefix = NULL // + ) + { + // + bool result = false; + + // + result = + // + swing.IsValid() + // + ; + if (!result) + { + return result; + } + + // + string name = swing.GetTag(); + if (IsValid(prefix)) + { + name = prefix + "_" + name; + } + + // + XOHCL bar; + result = swing.FillBar(bar); + if (!result) + { + return result; + } + + // + ENUM_X_PRICE price = swing.IsSwingHigh() + ? X_PRICE_HIGH + : X_PRICE_LOW; + + // + result = CreateByBar( + chart_id, + name, + window, + arrow, + bar, + price // + ); + + // + if (result) + { + ObjName(name); + } + + // + return result; + } +}; + +// +// Swing High ... +class XCSwingHighObject : public XCSwingObject +{ + // + public: + // + + /** + * Creator ... + * + * @param chart_id: Long, Specified Chart ID ... + * @param window: Integer, Specified Chart Window ID ... + * @param arrow: Integer, Specified Arrow Code ... + * @param swing: XCSwing instance ... + * @param prefix: String ... + * + * @return ( bool ) + */ + bool Create( + long chart_id, + int window, + int arrow, + XCSwing &swing, + string prefix = NULL // + ) + { + // + bool result = false; + + // + result = swing.IsValid() && + swing.IsSwingHigh(); + if (!result) + { + return result; + } + + // + result = CreateBySwing( + chart_id, + window, + arrow, + swing, + prefix // + ); + + // + 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 arrow: Integer, Specified Arrow Code ... + * @param swing: XCSwing instance ... + * @param prefix: String ... + * + * @return ( bool ) + */ + bool Create( + long chart_id, + int window, + int arrow, + XCSwing &swing, + string prefix = NULL // + ) + { + // + bool result = false; + + // + result = swing.IsValid() && + swing.IsSwingLow(); + if (!result) + { + return result; + } + + // + result = CreateBySwing( + chart_id, + window, + arrow, + swing, + prefix // + ); + + // + return result; + } + + /** + * Retrieve Object Type ... + * + * @return ( ENUM_XCHARTOBJECTS ) + */ + virtual ENUM_XCHARTOBJECTS Type() + { + return X_SWING_LOW_OBJ; + } + + // +}; + +// +// Momentum ... +class XCMomentumBarObject : public XCBarArrowObject +{ + // + public: + // + + /** + * Creator ... + * + * @param chart_id: Long, Specified Chart ID ... + * @param window: Integer, Specified Chart Window ID ... + * @param momentumBar: XCMomentumBar instance ... + * @param prefix: String ... + * + * @return ( bool ) + */ + bool CreateByMomentum( + long chart_id, + int window, + int arrow, + XCMomentumBar &momentumBar, + string prefix = NULL // + ) + { + // + bool result = false; + + // + result = + // + momentumBar.IsValid() + // + ; + if (!result) + { + return result; + } + + // + string name = momentumBar.GetTag(); + if (IsValid(prefix)) + { + name = prefix + "_" + name; + } + + // + XOHCL bar; + result = momentumBar.FillBar(bar); + if (!result) + { + return result; + } + + // + ENUM_X_PRICE price = momentumBar.IsBullish() + ? X_PRICE_LOW + : X_PRICE_HIGH; + + // + result = CreateByBar( + chart_id, + name, + window, + arrow, + bar, + price // + ); + + // + if (result) + { + ObjName(name); + } + + // + return result; + } +}; + +// +// Bullish Momentum Bar ... +class XCBullishMomentumBarObject : public XCMomentumBarObject +{ + // + public: + // + + /** + * Creator ... + * + * @param chart_id: Long, Specified Chart ID ... + * @param window: Integer, Specified Chart Window ID ... + * @param arrow: Integer, Specified Arrow Code ... + * @param momentumBar: XCMomentumBar instance ... + * @param prefix: String ... + * + * @return ( bool ) + */ + bool Create( + long chart_id, + int window, + int arrow, + XCMomentumBar &momentumBar, + string prefix = NULL // + ) + { + // + bool result = false; + + // + result = momentumBar.IsValid() && + momentumBar.IsBullish(); + if (!result) + { + return result; + } + + // + result = CreateByMomentum( + chart_id, + window, + arrow, + momentumBar, + prefix // + ); + + // + return result; + } + + /** + * Retrieve Object Type ... + * + * @return ( ENUM_XCHARTOBJECTS ) + */ + virtual ENUM_XCHARTOBJECTS Type() + { + return X_BULLISH_MOMENTUM_BAR_OBJ; + } + + // +}; + +// +// Bearish Momentum Bar ... +class XCBearishMomentumBarObject : public XCMomentumBarObject +{ + // + public: + // + + /** + * Creator ... + * + * @param chart_id: Long, Specified Chart ID ... + * @param window: Integer, Specified Chart Window ID ... + * @param arrow: Integer, Specified Arrow Code ... + * @param momentumBar: XCMomentumBar instance ... + * @param prefix: String ... + * + * @return ( bool ) + */ + bool Create( + long chart_id, + int window, + int arrow, + XCMomentumBar &momentumBar, + string prefix = NULL // + ) + { + // + bool result = false; + + // + result = momentumBar.IsValid() && + momentumBar.IsBearish(); + if (!result) + { + return result; + } + + // + result = CreateByMomentum( + chart_id, + window, + arrow, + momentumBar, + prefix // + ); + + // + return result; + } + + /** + * Retrieve Object Type ... + * + * @return ( ENUM_XCHARTOBJECTS ) + */ + virtual ENUM_XCHARTOBJECTS Type() + { + return X_BEARISH_MOMENTUM_BAR_OBJ; + } + + // +}; + +// +// Rejection ... +class XCRejectionBarObject : public XCBarArrowObject +{ + // + public: + // + + /** + * Creator ... + * + * @param chart_id: Long, Specified Chart ID ... + * @param window: Integer, Specified Chart Window ID ... + * @param rejectionBar: XCRejectionBar instance ... + * @param prefix: String ... + * + * @return ( bool ) + */ + bool CreateByRejection( + long chart_id, + int window, + int arrow, + XCRejectionBar &rejectionBar, + string prefix = NULL // + ) + { + // + bool result = false; + + // + result = + // + rejectionBar.IsValid() + // + ; + if (!result) + { + return result; + } + + // + string name = rejectionBar.GetTag(); + if (IsValid(prefix)) + { + name = prefix + "_" + name; + } + + // + XOHCL bar; + result = rejectionBar.FillBar(bar); + if (!result) + { + return result; + } + + // + ENUM_X_PRICE price = rejectionBar.IsBullish() + ? X_PRICE_LOW + : X_PRICE_HIGH; + + // + result = CreateByBar( + chart_id, + name, + window, + arrow, + bar, + price // + ); + + // + if (result) + { + ObjName(name); + } + + // + return result; + } +}; + +// +// Bullish Rejection Bar ... +class XCBullishRejectionBarObject : public XCRejectionBarObject +{ + // + public: + // + + /** + * Creator ... + * + * @param chart_id: Long, Specified Chart ID ... + * @param window: Integer, Specified Chart Window ID ... + * @param arrow: Integer, Specified Arrow Code ... + * @param rejectionBar: XCRejectionBar instance ... + * @param prefix: String ... + * + * @return ( bool ) + */ + bool Create( + long chart_id, + int window, + int arrow, + XCRejectionBar &rejectionBar, + string prefix = NULL // + ) + { + // + bool result = false; + + // + result = rejectionBar.IsValid() && + rejectionBar.IsBullish(); + if (!result) + { + return result; + } + + // + result = CreateByRejection( + chart_id, + window, + arrow, + rejectionBar, + prefix // + ); + + // + return result; + } + + /** + * Retrieve Object Type ... + * + * @return ( ENUM_XCHARTOBJECTS ) + */ + virtual ENUM_XCHARTOBJECTS Type() + { + return X_BULLISH_REJECTION_BAR_OBJ; + } + + // +}; + +// +// Bearish Rejection Bar ... +class XCBearishRejectionBarObject : public XCRejectionBarObject +{ + // + public: + // + + /** + * Creator ... + * + * @param chart_id: Long, Specified Chart ID ... + * @param window: Integer, Specified Chart Window ID ... + * @param arrow: Integer, Specified Arrow Code ... + * @param rejectionBar: XCRejectionBar instance ... + * @param prefix: String ... + * + * @return ( bool ) + */ + bool Create( + long chart_id, + int window, + int arrow, + XCRejectionBar &rejectionBar, + string prefix = NULL // + ) + { + // + bool result = false; + + // + result = rejectionBar.IsValid() && + rejectionBar.IsBearish(); + if (!result) + { + return result; + } + + // + result = CreateByRejection( + chart_id, + window, + arrow, + rejectionBar, + prefix // + ); + + // + return result; + } + + /** + * Retrieve Object Type ... + * + * @return ( ENUM_XCHARTOBJECTS ) + */ + virtual ENUM_XCHARTOBJECTS Type() + { + return X_BEARISH_REJECTION_BAR_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 ... + * @param prefix: String ... + * + * @return ( bool ) + */ + bool CreateByZone( + long chart_id, + string name, + int window, + XCZone &zone, + string prefix = NULL // + ) + { + // + bool result = false; + + // + bool isValidFrom = zone.IsValidFrom(); + bool isValidBoundary = zone.IsValidBoundary(); + + // + result = + // + IsValid(name) && + isValidFrom && + isValidBoundary + // + ; + if (!result) + { + return result; + } + + // + if (IsValid(prefix)) + { + name = prefix + "_" + name; + } + + // + datetime from = zone.From(); + datetime to = NormalizeTime(zone.To()); + + // + double upper = zone.Upper(); + double lower = zone.Lower(); + + // + result = mRect.Create( + chart_id, + name, + window, + from, + upper, + to, + 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); + } + + /** + * Set Zone Fill ... + * + * @param value: Boolean ... + */ + void ZoneFill(bool value) + { + mRect.Fill(value); + } + + // + private: + // + CChartObjectRectangle mRect; + + // +}; + +// +// Support Zone ... +class XCSupportZoneObject : public XCZoneObject +{ + // + public: + // + + /** + * Creator ... + * + * @param chart_id: Long, Specified Chart ID ... + * @param window: Integer, Specified Chart Window ID ... + * @param zone: XCSupportZone instance ... + * @param prefix: String ... + * + * @return ( bool ) + */ + bool Create( + long chart_id, + int window, + XCSupportZone &zone, + string prefix = NULL // + ) + { + // + bool result = false; + + // + result = zone.IsValid(); + if (!result) + { + return result; + } + + // + string name = zone.GetTag(); + + // + result = CreateByZone( + chart_id, + name, + window, + zone, + prefix // + ); + + // + return result; + } + + // + // Virtual ... + + /** + * Retrieve Object Type ... + * + * @return ( ENUM_XCHARTOBJECTS ) + */ + virtual ENUM_XCHARTOBJECTS Type() + { + return X_SUPPORT_ZONE_OBJ; + } +}; + +// +// Resistance Zone ... +class XCResistanceZoneObject : public XCZoneObject +{ + // + public: + // + + /** + * Creator ... + * + * @param chart_id: Long, Specified Chart ID ... + * @param window: Integer, Specified Chart Window ID ... + * @param zone: XCResistanceZone instance ... + * @param prefix: String ... + * + * @return ( bool ) + */ + bool Create( + long chart_id, + int window, + XCResistanceZone &zone, + string prefix = NULL // + ) + { + // + bool result = false; + + // + result = zone.IsValid(); + if (!result) + { + return result; + } + + // + string name = zone.GetTag(); + + // + result = CreateByZone( + chart_id, + name, + window, + zone, + prefix // + ); + + // + return result; + } + + // + // Virtual ... + + /** + * Retrieve Object Type ... + * + * @return ( ENUM_XCHARTOBJECTS ) + */ + virtual ENUM_XCHARTOBJECTS Type() + { + return X_RESISTANCE_ZONE_OBJ; + } +}; + +// +// Supply Zone ... +class XCSupplyZoneObject : public XCZoneObject +{ + // + public: + // + + /** + * Creator ... + * + * @param chart_id: Long, Specified Chart ID ... + * @param window: Integer, Specified Chart Window ID ... + * @param zone: XCSupplyZone instance ... + * @param prefix: String ... + * + * @return ( bool ) + */ + bool Create( + long chart_id, + int window, + XCSupplyZone &zone, + string prefix = NULL // + ) + { + // + bool result = false; + + // + result = zone.IsValid(); + if (!result) + { + return result; + } + + // + string name = zone.GetTag(); + + // + result = CreateByZone( + chart_id, + name, + window, + zone, + prefix // + ); + + // + return result; + } + + // + // Virtual ... + + /** + * Retrieve Object Type ... + * + * @return ( ENUM_XCHARTOBJECTS ) + */ + virtual ENUM_XCHARTOBJECTS Type() + { + return X_SUPPLY_ZONE_OBJ; + } +}; + +// +// Demand Zone ... +class XCDemandZoneObject : public XCZoneObject +{ + // + public: + // + + /** + * Creator ... + * + * @param chart_id: Long, Specified Chart ID ... + * @param window: Integer, Specified Chart Window ID ... + * @param zone: XCDemandZone instance ... + * @param prefix: String ... + * + * @return ( bool ) + */ + bool Create( + long chart_id, + int window, + XCDemandZone &zone, + string prefix = NULL // + ) + { + // + bool result = false; + + // + result = zone.IsValid(); + if (!result) + { + return result; + } + + // + string name = zone.GetTag(); + + // + result = CreateByZone( + chart_id, + name, + window, + zone, + prefix // + ); + + // + return result; + } + + // + // Virtual ... + + /** + * Retrieve Object Type ... + * + * @return ( ENUM_XCHARTOBJECTS ) + */ + virtual ENUM_XCHARTOBJECTS Type() + { + return X_DEMAND_ZONE_OBJ; + } +}; + +// +// Bullish Order Block ... +class XCBullishOrderBlockObject : public XCZoneObject +{ + // + public: + // + + /** + * Creator ... + * + * @param chart_id: Long, Specified Chart ID ... + * @param window: Integer, Specified Chart Window ID ... + * @param zone: XCOrderBlock instance ... + * @param prefix: String ... + * + * @return ( bool ) + */ + bool Create( + long chart_id, + int window, + XCOrderBlock &zone, + string prefix = NULL // + ) + { + // + bool result = false; + + // + result = zone.IsValid() && + zone.IsBullish(); + if (!result) + { + return result; + } + + // + string name = zone.GetTag(); + + // + result = CreateByZone( + chart_id, + name, + window, + zone, + prefix // + ); + + // + return result; + } + + // + // Virtual ... + + /** + * Retrieve Object Type ... + * + * @return ( ENUM_XCHARTOBJECTS ) + */ + virtual ENUM_XCHARTOBJECTS Type() + { + return X_BULLISH_ORDERBLOCK_OBJ; + } +}; + +// +// Bearish Order Block ... +class XCBearishOrderBlockObject : public XCZoneObject +{ + // + public: + // + + /** + * Creator ... + * + * @param chart_id: Long, Specified Chart ID ... + * @param window: Integer, Specified Chart Window ID ... + * @param zone: XCOrderBlock instance ... + * @param prefix: String ... + * + * @return ( bool ) + */ + bool Create( + long chart_id, + int window, + XCOrderBlock &zone, + string prefix = NULL // + ) + { + // + bool result = false; + + // + result = zone.IsValid() && + zone.IsBearish(); + if (!result) + { + return result; + } + + // + string name = zone.GetTag(); + + // + result = CreateByZone( + chart_id, + name, + window, + zone, + prefix // + ); + + // + return result; + } + + // + // Virtual ... + + /** + * Retrieve Object Type ... + * + * @return ( ENUM_XCHARTOBJECTS ) + */ + virtual ENUM_XCHARTOBJECTS Type() + { + return X_BULLISH_ORDERBLOCK_OBJ; + } +}; + +// +// Bullish Fair Value Gaps ... +class XCBullishFairValueGapObject : public XCZoneObject +{ + // + public: + // + + /** + * Creator ... + * + * @param chart_id: Long, Specified Chart ID ... + * @param window: Integer, Specified Chart Window ID ... + * @param zone: XCOrderBlock instance ... + * @param prefix: String ... + * + * @return ( bool ) + */ + bool Create( + long chart_id, + int window, + XCFVG &zone, + string prefix = NULL // + ) + { + // + bool result = false; + + // + result = zone.IsValid() && + zone.IsBullish(); + if (!result) + { + return result; + } + + // + string name = zone.GetTag(); + + // + result = CreateByZone( + chart_id, + name, + window, + zone, + prefix // + ); + + // + return result; + } + + // + // Virtual ... + + /** + * Retrieve Object Type ... + * + * @return ( ENUM_XCHARTOBJECTS ) + */ + virtual ENUM_XCHARTOBJECTS Type() + { + return X_BULLISH_FVG_OBJ; + } +}; + +class XCConsolidationZoneObject : public XCBaseObject +{ + // + public: + // + + /** + * Creator ... + * + * @param chart_id: Long, Specified Chart ID ... + * @param window: Integer, Specified Chart Window ID ... + * @param zone: XConsolidationZone instance ... + * @param prefix: String ... + * + * @return ( bool ) + */ + bool Create( + long chart_id, + int window, + XConsolidationZone &zone, + string prefix = NULL // + ) + { + // + bool result = false; + + // + result = zone.IsValid(); + if (!result) + { + return result; + } + + // + string name = zone.GetTag(); + if (IsValid(prefix)) + { + name = prefix + "_" + name; + } + + // + result = mRect.Create( + chart_id, + name, + window, + zone.from, + zone.upper, + zone.to, + zone.lower // + ); + + // + if (result) + { + ObjName(name); + } + + // + return result; + } + + // + // Virtual ... + + /** + * Retrieve Object Type ... + * + * @return ( ENUM_XCHARTOBJECTS ) + */ + virtual ENUM_XCHARTOBJECTS Type() + { + return X_CONSOLIDATION_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); + } + + /** + * Set Zone Fill ... + * + * @param value: Boolean ... + */ + void ZoneFill(bool value) + { + mRect.Fill(value); + } + + // + private: + // + CChartObjectRectangle mRect; + + // +}; + +// +// Bearish Fair Value Gaps ... +class XCBearishFairValueGapObject : public XCZoneObject +{ + // + public: + // + + /** + * Creator ... + * + * @param chart_id: Long, Specified Chart ID ... + * @param window: Integer, Specified Chart Window ID ... + * @param zone: XCOrderBlock instance ... + * @param prefix: String ... + * + * @return ( bool ) + */ + bool Create( + long chart_id, + int window, + XCFVG &zone, + string prefix = NULL // + ) + { + // + bool result = false; + + // + result = zone.IsValid() && + zone.IsBearish(); + if (!result) + { + return result; + } + + // + string name = zone.GetTag(); + + // + result = CreateByZone( + chart_id, + name, + window, + zone, + prefix // + ); + + // + return result; + } + + // + // Virtual ... + + /** + * Retrieve Object Type ... + * + * @return ( ENUM_XCHARTOBJECTS ) + */ + virtual ENUM_XCHARTOBJECTS Type() + { + return X_BEARISH_FVG_OBJ; + } +}; + +// +// Signal ... +class XCSignalObject : public XCBaseObject +{ + // + public: + // + + // + // Constructor ... + void XCSignalObject() + { + } + + // + // Deconstructor ... + void ~XCSignalObject() + { + } + + /** + * Create a Signal Object on Chart ... + * + * @param chart_id: Long ... + * @param name: String ... + * @param window: Integer ... + * @param signal: XSignal instance ... + * @param length: int, Specified Length of Signal ... + * + * @return ( bool ) + */ + bool Create( + long chart_id, + const int window, + XSignal &signal, + int length = 3, + string prefix = NULL // + ) + { + // + bool result = false; + + // + length = NormalizeInt(length, 3); + + // + result = signal.IsValid(); + if (!result) + { + return result; + } + + // + string name = signal.GetTag(); + if (IsValid(prefix)) + { + name = prefix + "_" + name; + } + string nameMD5 = ToMD5(name); + + // + int delay = (PeriodSeconds(signal.period) * length); + datetime time1 = (datetime)((int)signal.time - delay); + datetime time2 = (datetime)((int)signal.time + delay); + + // + // TP ... + string tpName = ToString(X_TP) + "_" + nameMD5; + result = mTPTrend.Create( + chart_id, + tpName, + window, + time1, + signal.tp, + time2, + signal.tp // + ); + if (!result) + { + return result; + } + + // + // SL ... + string slName = ToString(X_SL) + "_" + nameMD5; + result = mSLTrend.Create( + chart_id, + slName, + window, + time1, + signal.sl, + time2, + signal.sl // + ); + if (!result) + { + // + mTPTrend.Delete(); + return result; + } + + // + // TARGET ... + bool hasTargets = HasChild(signal.targets); + if (hasTargets) + { + // + int targetsCount = ArraySize(signal.targets); + for (int i = 0; i < targetsCount; i++) + { + // + string targetName = ToString(X_TARGET) + "_" + ToString(i) + "_" + nameMD5; + CChartObjectTrend *mTargetTrend; + mTargetTrend = new CChartObjectTrend(); + result = mTargetTrend.Create( + chart_id, + targetName, + window, + time1, + signal.targets[i].target, + time2, + signal.targets[i].target // + ); + if (!result) + { + // + mTPTrend.Delete(); + mSLTrend.Delete(); + break; + } + + // + mTargetTrends.Add(mTargetTrend); + } + } + + // + // ENTRY ... + string entrName = ToString(X_ENTRY) + "_" + nameMD5; + result = mEntryTrend.Create( + chart_id, + entrName, + window, + time1, + signal.entry, + time2, + signal.entry // + ); + if (!result) + { + // + mTPTrend.Delete(); + mSLTrend.Delete(); + mTargetTrends.Clear(); + return result; + } + + // + // Set Object Name ... + ObjName(name); + + // + return result; + } + + // + // Setter(s) ... + + // + // TP ... + + /** + * Set TP Width ... + * + * @param value: Integer ... + */ + void TPWidth(int value) + { + // + if (value < 1) + { + value = 1; + } + + // + mTPTrend.Width(value); + } + + /** + * Set TP Color ... + * + * @param value: Color ... + */ + void TPColor(color value) + { + mTPTrend.Color(value); + } + + /** + * Set TP Style ... + * + * @param value: ENUM_LINE_STYLE ... + */ + void TPStyle(ENUM_LINE_STYLE value) + { + mTPTrend.Style(value); + } + + // + // SL ... + + /** + * Set SL Width ... + * + * @param value: Integer ... + */ + void SLWidth(int value) + { + // + if (value < 1) + { + value = 1; + } + + // + mSLTrend.Width(value); + } + + /** + * Set SL Color ... + * + * @param value: Color ... + */ + void SLColor(color value) + { + mSLTrend.Color(value); + } + + /** + * Set SL Style ... + * + * @param value: ENUM_LINE_STYLE ... + */ + void SLStyle(ENUM_LINE_STYLE value) + { + mSLTrend.Style(value); + } + + // + // TARGET ... + + /** + * Set Target Width ... + * + * @param value: Integer ... + */ + void TargetWidth(int value) + { + // + if (value < 1) + { + value = 1; + } + + // + for (int i = 0; i < mTargetTrends.Total(); i++) + { + // + CChartObjectTrend *iTrend = (CChartObjectTrend *)mTargetTrends.At(i); + iTrend.Width(value); + } + } + + /** + * Set Target Color ... + * + * @param value: Color ... + */ + void TargetColor(color value) + { + // + for (int i = 0; i < mTargetTrends.Total(); i++) + { + // + CChartObjectTrend *iTrend = (CChartObjectTrend *)mTargetTrends.At(i); + iTrend.Color(value); + } + } + + /** + * Set Target Style ... + * + * @param value: ENUM_LINE_STYLE ... + */ + void TargetStyle(ENUM_LINE_STYLE value) + { + // + for (int i = 0; i < mTargetTrends.Total(); i++) + { + // + CChartObjectTrend *iTrend = (CChartObjectTrend *)mTargetTrends.At(i); + iTrend.Style(value); + } + } + + // + // ENTRY ... + + /** + * Set Entry Width ... + * + * @param value: Integer ... + */ + void EntryWidth(int value) + { + // + if (value < 1) + { + value = 1; + } + + // + mEntryTrend.Width(value); + } + + /** + * Set Entry Color ... + * + * @param value: Color ... + */ + void EntryColor(color value) + { + mEntryTrend.Color(value); + } + + /** + * Set Entry Style ... + * + * @param value: ENUM_LINE_STYLE ... + */ + void EntryStyle(ENUM_LINE_STYLE value) + { + mEntryTrend.Style(value); + } + + /** + * Retrieve Object Type ... + * + * @return ( ENUM_XCHARTOBJECTS ) + */ + virtual ENUM_XCHARTOBJECTS Type() + { + return X_SIGNAL_OBJ; + } + + // + private: + // + + // + CChartObjectTrend mTPTrend; + CChartObjectTrend mSLTrend; + CChartObjectTrend mEntryTrend; + CArrayObj mTargetTrends; +}; + +// +// XRR Object ... +class XCRRObject : public XCSignalObject +{ + // + // Public ... + public: + // + // Constructor ... + bool CreateBoxRR( + long chart_id, + const int window, + XBoxZone &box, + double &rewardRatios[], + int length = 3, + string prefix = NULL // + ) + { + // + bool result = false; + + // + length = NormalizeInt(length, 3); + + // + result = box.IsValid(); + if (!result) + { + return result; + } + + // + XSignal signal; + result = ToSignal( + box, + signal, + rewardRatios // + ); + if (!result) + { + // + signal.Clean(); + + // + return result; + } + + // + result = Create( + chart_id, + window, + signal, + length, + prefix // + ); + + // + signal.Clean(); + + // + return result; + } +}; + +class XCOHCLObject : public XCBaseObject +{ + // + public: + // + + /** + * Creator ... + * + * @param chart_id: Long, Specified Chart ID ... + * @param window: Integer, Specified Chart Window ID ... + * @param pivot: XPVPivot instance ... + * @param prefix: String ... + * + * @return ( bool ) + */ + bool Create( + long chart_id, + int window, + XOHCL &bar, + datetime to, + string prefix = NULL // + ) + { + // + bool result = false; + + // + result = bar.IsValid() && + IsValid(to); + if (!result) + { + return result; + } + + // + string name = bar.GetTag(); + if (IsValid(prefix)) + { + name = prefix + "_" + name; + } + string nameMD5 = ToMD5(name); + + // + // High Shadow ... + string hShadowName = ToString(X_BAR_H_SHW) + "_" + nameMD5; + + // + result = mHighShadowRect.Create( + chart_id, + hShadowName, + window, + bar.time, + bar.high, + to, + bar.GetUp() // + ); + if (!result) + { + return result; + } + + // + // Body ... + string bodyName = ToString(X_BAR_BDY) + "_" + nameMD5; + + // + result = mBodyRect.Create( + chart_id, + bodyName, + window, + bar.time, + bar.GetUp(), + to, + bar.GetDown() // + ); + if (!result) + { + // + mHighShadowRect.Delete(); + mHighShadowRect.Detach(); + return result; + } + + // + // Low Shadow ... + string lShadowName = ToString(X_BAR_L_SHW) + "_" + nameMD5; + + // + result = mLowShadowRect.Create( + chart_id, + lShadowName, + window, + bar.time, + bar.GetDown(), + to, + bar.low // + ); + if (!result) + { + // + mBodyRect.Delete(); + mBodyRect.Detach(); + mHighShadowRect.Delete(); + mHighShadowRect.Detach(); + return result; + } + + // + if (result) + { + ObjName(name); + } + + // + return result; + } + + // + // Getter(s) / Setter(s) ... + + /** + * Set High Shadow Width ... + * + * @param value: Integer ... + */ + void HighShadowWidth(int value) + { + // + if (value < 1) + { + value = 1; + } + + // + mHighShadowRect.Width(value); + } + + /** + * Set High Shadow Color ... + * + * @param value: Color ... + */ + void HighShadowColor(color value) + { + mHighShadowRect.Color(value); + } + + /** + * Set High Shadow Style ... + * + * @param value: ENUM_LINE_STYLE member ... + */ + void HighShadowStyle(ENUM_LINE_STYLE value) + { + mHighShadowRect.Style(value); + } + + /** + * Set High Shadow Fill ... + * + * @param value: Boolean ... + */ + void HighShadowFill(bool value) + { + mHighShadowRect.Fill(value); + } + + /** + * Set Body Width ... + * + * @param value: Integer ... + */ + void BodyWidth(int value) + { + // + if (value < 1) + { + value = 1; + } + + // + mBodyRect.Width(value); + } + + /** + * Set Body Color ... + * + * @param value: Color ... + */ + void BodyColor(color value) + { + mBodyRect.Color(value); + } + + /** + * Set Body Style ... + * + * @param value: ENUM_LINE_STYLE member ... + */ + void BodyStyle(ENUM_LINE_STYLE value) + { + mBodyRect.Style(value); + } + + /** + * Set Body Fill ... + * + * @param value: Boolean ... + */ + void BodyFill(bool value) + { + mBodyRect.Fill(value); + } + + /** + * Set Low Shadow Width ... + * + * @param value: Integer ... + */ + void LowShadowWidth(int value) + { + // + if (value < 1) + { + value = 1; + } + + // + mLowShadowRect.Width(value); + } + + /** + * Set Low Shadow Color ... + * + * @param value: Color ... + */ + void LowShadowColor(color value) + { + mLowShadowRect.Color(value); + } + + /** + * Set Low Shadow Style ... + * + * @param value: ENUM_LINE_STYLE member ... + */ + void LowShadowStyle(ENUM_LINE_STYLE value) + { + mLowShadowRect.Style(value); + } + + /** + * Set Low Shadow Fill ... + * + * @param value: Boolean ... + */ + void LowShadowFill(bool value) + { + mLowShadowRect.Fill(value); + } + + void BarSpes( + int width = 1, + color clr = clrNONE, + ENUM_LINE_STYLE style = STYLE_SOLID, + bool fill = false // + ) + { + // + BodyWidth(width); + LowShadowWidth(width); + HighShadowWidth(width); + + // + BodyColor(clr); + LowShadowColor(clr); + HighShadowColor(clr); + + // + BodyStyle(style); + LowShadowStyle(style); + HighShadowStyle(style); + + // + BodyFill(fill); + LowShadowFill(fill); + HighShadowFill(fill); + } + + // + // Virtual ... + + /** + * Retrieve Object Type ... + * + * @return ( ENUM_XCHARTOBJECTS ) + */ + virtual ENUM_XCHARTOBJECTS Type() + { + return X_OHCL_OBJ; + } + + // + private: + // + + // + // Props ... + CChartObjectRectangle mHighShadowRect; + CChartObjectRectangle mBodyRect; + CChartObjectRectangle mLowShadowRect; +}; + +class XCBoxObject : public XCBaseObject +{ + // + public: + // + + /** + * Creator ... + * + * @param chart_id: Long, Specified Chart ID ... + * @param window: Integer, Specified Chart Window ID ... + * @param pivot: XPVPivot instance ... + * @param prefix: String ... + * + * @return ( bool ) + */ + bool Create( + long chart_id, + int window, + string name, + double upper, + double lower, + datetime from, + datetime to, + string prefix = NULL // + ) + { + // + bool result = false; + + // + result = + upper > 0 && + lower > 0 && + to > from && + IsValid(to) && + IsValid(name) && + IsValid(from) && + upper > lower; + if (!result) + { + return result; + } + + // + if (IsValid(prefix)) + { + name = prefix + "_" + name; + } + string nameMD5 = ToMD5(name); + + // + result = mRect.Create( + chart_id, + name, + window, + from, + upper, + to, + lower // + ); + if (!result) + { + return result; + } + + // + if (result) + { + ObjName(name); + } + + // + return result; + } + + // + // Getter(s) / Setter(s) ... + + /** + * Set Width ... + * + * @param value: Integer ... + */ + void BoxWidth(int value) + { + // + if (value < 1) + { + value = 1; + } + + // + mRect.Width(value); + } + + /** + * Set Color ... + * + * @param value: Color ... + */ + void BoxColor(color value) + { + mRect.Color(value); + } + + /** + * Set Style ... + * + * @param value: ENUM_LINE_STYLE member ... + */ + void BoxStyle(ENUM_LINE_STYLE value) + { + mRect.Style(value); + } + + /** + * Set Fill ... + * + * @param value: Boolean ... + */ + void BoxFill(bool value) + { + mRect.Fill(value); + } + + // + // Virtual ... + + /** + * Retrieve Object Type ... + * + * @return ( ENUM_XCHARTOBJECTS ) + */ + virtual ENUM_XCHARTOBJECTS Type() + { + return X_BOX_OBJ; + } + + // + private: + // + + // + // Props ... + CChartObjectRectangle mRect; +}; + +// +// Zone Ticks ... + +// +// Specify How to Draws Specified Levels ... +struct XTickZoneLevelSpecs +{ + // + double percent; // Max Allowed Percent of Tick Zone ... + + // + // Label Info ... + color labelColor; + string labelFont; + int labelFontSize; + double labelAngel; + + // + // Zone Info ... + bool zoneFill; + int zoneWidth; + color zoneColor; + ENUM_LINE_STYLE zoneStyle; + + // + // Constructor ... + XTickZoneLevelSpecs() + { + Default(); + } + + // + // Tools ... + + /** + * Initialize Drawing Specs ... + * + * @param _percent: Double, Max Allowed Percent ... + * @param _labelColor: Color, Specified Label Color ... + * @param _zoneColoe: Color, Specified Zone Color ... + * @param _zoneFill: Boolean, Specified Fill Zone or not ... + * @param _zoneStyle: ENUM_LINE_STYLE member, Specified Zone Style ... + * @param _labelFontSize: Integer, Specified Label Font Size ... + * @param _labelFont: String, Specified Label Font Name ... + * @param _labelAngel: Double, Specified Label Angel ... + * + * @return ( bool ) + */ + bool Init( + double _percent, + color _labelColor = clrWhite, + color _zoneColor = clrWhite, + bool _zoneFill = false, + ENUM_LINE_STYLE _zoneStyle = STYLE_DOT, + int _zoneWidth = 1, + int _labelFontSize = 12, + string _labelFont = "Arial", + double _labelAngel = 0 // + ) + { + // + bool result = false; + + // + Default(); + + // + result = _percent > 0; + if (!result) + { + return result; + } + + // + percent = _percent; + labelColor = _labelColor; + zoneColor = _zoneColor; + zoneFill = _zoneFill; + zoneStyle = _zoneStyle; + + // + if (_zoneWidth > 0) + { + zoneWidth = _zoneWidth; + } + + // + if (_labelFontSize > 0) + { + labelFontSize = _labelFontSize; + } + + // + if (IsSpecifiedValid(_labelFont)) + { + labelFont = _labelFont; + } + + // + if (_labelAngel >= 0) + { + labelAngel = _labelAngel; + } + + // + result = IsValid(); + + // + return result; + } + + /** + * Set Default Properties ... + */ + void Default() + { + // + percent = 0; + + // + // Label ... + labelAngel = 0; + labelFontSize = 13; + labelFont = "Arial"; + labelColor = clrWhite; + + // + // Zone ... + zoneWidth = 1; + zoneFill = false; + zoneColor = clrWhite; + zoneStyle = STYLE_DOT; + } + + /** + * Validate ... + * + * @return ( bool ) + */ + bool IsValid() + { + // + bool result = false; + + // + result = + // + percent > 0 && + // + // Zone ... + zoneWidth > 0 && + // + // Label ... + labelFontSize > 0 && + IsSpecifiedValid(labelFont) + // + ; + + // + return result; + } + + // +}; + +class XCTickZoneObject : public XCBaseObject +{ + // + public: + // + + /** + * Creator ... + * + * @param chart_id: Long, Specified Chart ID ... + * @param window: Integer, Specified Chart Window ID ... + * @param name: String, Specify Chart Object Identifier ... + * @param from: Datetime ... + * @param to: Datetime ... + * @param zone: XCTickZone instance ... + * @param prefix: String ... + * + * @return ( bool ) + */ + bool Create( + long chart_id, + int window, + string name, + datetime from, + datetime to, + XCTickZone *zone, + string prefix = NULL // + ) + { + // + bool result = false; + + // + result = + IsValid(name) && + zone.IsValid() && + IsValid(to) && + IsValid(from); + if (!result) + { + return result; + } + + // + double points = GetPoints(zone.symbol); + if (points <= 0) + { + points = 1; + } + double distance = 1 * points; + + // + if (IsValid(prefix)) + { + name = prefix + "_" + name; + } + + // + string rectName = "TKZ_" + name; + result = mRect.Create( + chart_id, + rectName, + window, + from, + zone.high, + to, + zone.low // + ); + if (!result) + { + return result; + } + + // + int fromToDiff = ((int)to - (int)from); + datetime labelsDate = (datetime)((int)to - (fromToDiff / 5)); + + // + string lblName = "LBLT_" + name; + result = mTLabel.Create( + chart_id, + lblName, + window, + labelsDate, + zone.high - distance // + ); + if (!result) + { + return result; + } + + // + mTLabel.Description("T: " + ToString(zone.percent) + "%"); + + // + string lblVName = "LBLV_" + name; + result = mVLabel.Create( + chart_id, + lblVName, + window, + labelsDate, + zone.low + (2.5 * distance) // + ); + if (!result) + { + return result; + } + + // + mVLabel.Description("V: " + ToString(zone.volumePercent) + "%"); + + // + ObjName(name); + + // + return result; + } + + // + // Virtual ... + + /** + * Retrieve Object Type ... + * + * @return ( ENUM_XCHARTOBJECTS ) + */ + virtual ENUM_XCHARTOBJECTS Type() + { + return X_TICK_ZONE_OBJ; + } + + // + // Getter(s) / 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); + } + + /** + * Set Zone Fill ... + * + * @param value: Boolean ... + */ + void ZoneFill(bool value) + { + mRect.Fill(value); + } + + /** + * Set Label Color ... + * + * @param value: Color ... + */ + void LabelColor(color value) + { + // + mTLabel.Color(value); + mVLabel.Color(value); + } + + /** + * Set Label Size ... + * + * @param value: Integer ... + */ + void LabelSize(int value) + { + // + mTLabel.FontSize(value); + mVLabel.FontSize(value); + } + + /** + * Set Label Font ... + * + * @param value: String ... + */ + void LabelFont(string value) + { + // + mTLabel.Font(value); + mVLabel.Font(value); + } + + /** + * Set Label Angle ... + * + * @param value: double ... + */ + void LabelAngle(double value) + { + // + mTLabel.Angle(value); + mVLabel.Angle(value); + } + + // + private: + // + // Props ... + CChartObjectRectangle mRect; + CChartObjectLabel mTLabel; + CChartObjectLabel mVLabel; + + // +}; +class XCTicksZoneObject : public XCBaseObject +{ + // + public: + // + + // + void ~XCTicksZoneObject() + { + mZones.Clear(); + } + + /** + * Creator ... + * + * @param chart_id: Long, Specified Chart ID ... + * @param window: Integer, Specified Chart Window ID ... + * @param zone: XCTicksZone instance ... + * @param prefix: String ... + * + * @return ( bool ) + */ + bool Create( + long chart_id, + int window, + XCTicksZone &zone, + XTickZoneLevelSpecs &specs[], + string prefix = NULL // + ) + { + // + bool result = false; + + // + result = zone.IsValid(); + if (!result) + { + return result; + } + + // + string name = zone.GetTag(); + int levels = zone.Levels(); + result = levels > 0; + if (!result) + { + return result; + } + + // + for (int i = 0; i < levels; i++) + { + // + XCTickZone *iZone = zone.GetZone(i); + XCTickZoneObject *iObj; + iObj = new XCTickZoneObject(); + bool isCreated = iObj.Create( + chart_id, + window, + ToString(i) + "_" + name, + zone.From(), + zone.To(), + iZone, + prefix // + ); + if (!isCreated) + { + break; + } + + // + XTickZoneLevelSpecs iSpec; + bool hasSpecs = FindSpecs( + iZone, + iSpec, + specs // + ); + if (hasSpecs) + { + // + // Label ... + iObj.LabelFont(iSpec.labelFont); + iObj.LabelAngle(iSpec.labelAngel); + iObj.LabelColor(iSpec.labelColor); + iObj.LabelSize(iSpec.labelFontSize); + + // + // Zone ... + iObj.ZoneFill(iSpec.zoneFill); + iObj.ZoneColor(iSpec.zoneColor); + iObj.ZoneWidth(iSpec.zoneWidth); + iObj.ZoneStyle(iSpec.zoneStyle); + } + + // + mZones.Add(iObj); + } + + // + if (result) + { + ObjName(name); + } + else + { + mZones.Clear(); + } + + // + return result; + } + + // + // Virtual ... + + /** + * Retrieve Object Type ... + * + * @return ( ENUM_XCHARTOBJECTS ) + */ + virtual ENUM_XCHARTOBJECTS Type() + { + return X_TICKS_ZONE_OBJ; + } + + // + // Getter(s) / Setter(s) ... + + // + // Actions ... + + /** + * Destroy Object ... + */ + void Destroy() + { + mZones.Clear(); + } + + /** + * Find Specified TickZone Drawing Specs ... + * + * @param zone: XCTickZone instance, reference to Search For it ... + * @param spec: XTickZoneLevelSpecs instance, reference to Result ... + * @param specs: XTickZoneLevelSpecs instance Collection for Search ... + * + * @return ( bool ) + */ + bool FindSpecs( + XCTickZone *zone, + XTickZoneLevelSpecs &spec, + XTickZoneLevelSpecs &specs[] // + ) + { + // + bool result = false; + + // + int count = ArraySize(specs); + result = + zone.IsValid() && + IsValidSize(count); + if (!result) + { + return result; + } + + // + for (int i = 0; i < count; i++) + { + // + XTickZoneLevelSpecs iSpecs = specs[i]; + + // + bool isSpecValidForZone = + !spec.IsValid() + ? zone.percent <= iSpecs.percent + : zone.percent <= iSpecs.percent && + spec.percent > iSpecs.percent; + if (isSpecValidForZone) + { + spec = iSpecs; + } + } + + // + result = spec.IsValid(); + + // + return result; + } + + // + private: + // + // Props ... + CArrayObj mZones; + + // +}; + +// \ 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..51e7c7c2 --- /dev/null +++ b/Documents/BKP/x-saherelm.x-poi.drawer.class.mq5 @@ -0,0 +1,4384 @@ +/////////////////////////////////////////////////////// +// +// 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-cobject.class.mq5" +#include "../Libraries/x-saherelm.x-poi.extensions.lib.mq5" + +// +// Definitions ... + +// +// Extensions ... + +void AddObjects( + CArrayObj *&source, + CArrayObj &dest // +) +{ + // + bool has = source != NULL && + source.Total() > 0; + if (!has) + { + return; + } + + // + for (int i = 0; i < source.Total(); i++) + { + dest.Add(source.At(i)); + } +} + +// +// Implementations ... +class XCPOIDrawer : public XCBase +{ + // + public: + // + + // + // Constructor ... + void XCPOIDrawer() + { + // + Default(); + } + + // + // Deconstructor ... + void ~XCPOIDrawer() + { + // + Clean(mTicksZoneSpecs); + } + + // + // 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; + } + + // + // XOHCL ... + + /** + * Get Bar Width ... + * + * @return ( int ) + */ + int BarWidth() + { + return mBarWidth; + } + + /** + * Set Bar Width ... + * + * @param value: Integer ... + */ + void BarWidth(int value) + { + // + if (value < 0) + { + value = 0; + } + + // + mBarWidth = value; + } + + /** + * Get Bar Bullish Color ... + * + * @return ( color ) + */ + color BarBullishColor() + { + return mBarBullishColor; + } + + /** + * Set Bar Bullish Color ... + * + * @param value: Color ... + */ + void BarBullishColor(color value) + { + mBarBullishColor = value; + } + + /** + * Get Bar Bearish Color ... + * + * @return ( color ) + */ + color BarBearishColor() + { + return mBarBearishColor; + } + + /** + * Set Bar Bearish Color ... + * + * @param value: Color ... + */ + void BarBearishColor(color value) + { + mBarBearishColor = value; + } + + /** + * Get Fill Bar High Shadow State ... + * + * @return ( bool ) + */ + bool BarFillHighShadow() + { + return mBarFillHighShadow; + } + + /** + * Set Fill Bar High Shadow State ... + * + * @param value: Boolean ... + */ + void BarFillHighShadow(bool value) + { + mBarFillHighShadow = value; + } + + /** + * Get Bar High Shadow Style ... + * + * @return ( ENUM_LINE_STYLE ) + */ + ENUM_LINE_STYLE BarHighShadowStyle() + { + return mBarHighShadowStyle; + } + + /** + * Set Bar High Shadow Style ... + * + * @param value: ENUM_LINE_STYLE member ... + */ + void BarHighShadowStyle(ENUM_LINE_STYLE value) + { + mBarHighShadowStyle = value; + } + + /** + * Get Fill Bar Body State ... + * + * @return ( bool ) + */ + bool BarFillBody() + { + return mBarFillBody; + } + + /** + * Set Fill Bar Body State ... + * + * @param value: Boolean ... + */ + void BarFillBody(bool value) + { + mBarFillBody = value; + } + + /** + * Get Bar Body Style ... + * + * @return ( ENUM_LINE_STYLE ) + */ + ENUM_LINE_STYLE BarBodyStyle() + { + return mBarBodyStyle; + } + + /** + * Set Bar Body Style ... + * + * @param value: ENUM_LINE_STYLE member ... + */ + void BarBodyStyle(ENUM_LINE_STYLE value) + { + mBarBodyStyle = value; + } + + /** + * Get Fill Bar Low Show State ... + * + * @return ( bool ) + */ + bool BarFillLowShadow() + { + return mBarFillLowShadow; + } + + /** + * Set Fill Bar Low Show State ... + * + * @param value: Boolean ... + */ + void BarFillLowShadow(bool value) + { + mBarFillLowShadow = value; + } + + /** + * Get Bar Low Shadow Style ... + * + * @return ( ENUM_LINE_STYLE ) + */ + ENUM_LINE_STYLE BarLowShadowStyle() + { + return mBarLowShadowStyle; + } + + /** + * Set Bar Low Shadow Style ... + * + * @param value: ENUM_LINE_STYLE member ... + */ + void BarLowShadowStyle(ENUM_LINE_STYLE value) + { + mBarLowShadowStyle = 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) + { + mBullishFVGFill = 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; + } + + // + // Virtuals ... + + /** + * Apply Default Configurations ... + */ + virtual void Default() + { + // + // Apply Default Props ... + + // + Prefix(NULL); + ChartIdentification(0); + SubWindowIdentification(0); + + // + BarWidth(1); + BarBearishColor(clrRed); + BarBullishColor(clrLime); + BarFillBody(false); + BarFillHighShadow(false); + BarFillLowShadow(false); + BarBodyStyle(STYLE_DOT); + BarLowShadowStyle(STYLE_DOT); + BarHighShadowStyle(STYLE_DOT); + + // + int arrowWidth = 1; + + // + SwingLowArrow(108); + SwingLowColor(clrAqua); + SwingLowWidth(arrowWidth); + + // + SwingHighArrow(108); + SwingHighWidth(arrowWidth); + SwingHighColor(clrMagenta); + + // + arrowWidth++; + + // + BullishMomentumBarArrow(225); + BullishMomentumBarWidth(arrowWidth); + BullishMomentumBarColor(clrAqua); + + // + BearishMomentumBarArrow(226); + BearishMomentumBarWidth(arrowWidth); + BearishMomentumBarColor(clrMagenta); + + // + arrowWidth++; + + // + BullishRejectionBarArrow(217); + BullishRejectionBarWidth(arrowWidth); + BullishRejectionBarColor(clrAqua); + + // + BearishRejectionBarArrow(218); + BearishRejectionBarWidth(arrowWidth); + BearishRejectionBarColor(clrMagenta); + + // + SupportZoneFill(false); + SupportZoneWidth(1); + SupportZoneStyle(STYLE_DOT); + SupportZoneColor(clrLime); + + // + ResistanceZoneFill(false); + ResistanceZoneWidth(1); + ResistanceZoneStyle(STYLE_DOT); + ResistanceZoneColor(clrRed); + + // + SupplyZoneFill(false); + SupplyZoneWidth(1); + SupplyZoneStyle(STYLE_DOT); + SupplyZoneColor(clrRed); + + // + DemandZoneFill(false); + DemandZoneWidth(1); + DemandZoneStyle(STYLE_DOT); + DemandZoneColor(clrGreen); + + // + BullishOrderBlockFill(false); + BullishOrderBlockWidth(1); + BullishOrderBlockStyle(STYLE_DASHDOT); + BullishOrderBlockColor(clrLime); + + // + BearishOrderBlockFill(false); + BearishOrderBlockWidth(1); + BearishOrderBlockStyle(STYLE_DASHDOT); + BearishOrderBlockColor(clrRed); + + // + BullishFVGFill(false); + BullishFVGWidth(1); + BullishFVGStyle(STYLE_DOT); + BullishFVGColor(clrLime); + + // + BearishFVGFill(false); + BearishFVGWidth(1); + BearishFVGStyle(STYLE_DOT); + BearishFVGColor(clrRed); + + // + // Add Default TickZone Specs ... + bool isSpecsInited = false; + bool fillTickZone = false; + XTickZoneLevelSpecs specs10; + isSpecsInited = specs10.Init( + 10, + clrWhite, + clrWhite, + fillTickZone // + ); + if (isSpecsInited) + { + AddTickZoneLevelSpecs(specs10); + } + + // + XTickZoneLevelSpecs specs20; + isSpecsInited = specs20.Init( + 20, + clrOrange, + clrOrange, + fillTickZone // + ); + if (isSpecsInited) + { + AddTickZoneLevelSpecs(specs20); + } + + // + XTickZoneLevelSpecs specs30; + isSpecsInited = specs30.Init( + 30, + clrOrange, + clrOrange, + fillTickZone // + ); + if (isSpecsInited) + { + AddTickZoneLevelSpecs(specs30); + } + + // + XTickZoneLevelSpecs specs40; + isSpecsInited = specs40.Init( + 40, + clrOrange, + clrOrange, + fillTickZone // + ); + if (isSpecsInited) + { + AddTickZoneLevelSpecs(specs40); + } + + // + XTickZoneLevelSpecs specs50; + isSpecsInited = specs50.Init( + 50, + clrYellow, + clrYellow, + fillTickZone // + ); + if (isSpecsInited) + { + AddTickZoneLevelSpecs(specs50); + } + + // + XTickZoneLevelSpecs specs60; + isSpecsInited = specs60.Init( + 60, + clrYellow, + clrYellow, + fillTickZone // + ); + if (isSpecsInited) + { + AddTickZoneLevelSpecs(specs60); + } + + // + XTickZoneLevelSpecs specs70; + isSpecsInited = specs70.Init( + 70, + clrYellow, + clrYellow, + fillTickZone // + ); + if (isSpecsInited) + { + AddTickZoneLevelSpecs(specs70); + } + + // + XTickZoneLevelSpecs specs80; + isSpecsInited = specs80.Init( + 80, + clrRed, + clrRed, + fillTickZone // + ); + if (isSpecsInited) + { + AddTickZoneLevelSpecs(specs80); + } + + // + XTickZoneLevelSpecs specs90; + isSpecsInited = specs90.Init( + 90, + clrRed, + clrRed, + fillTickZone // + ); + if (isSpecsInited) + { + AddTickZoneLevelSpecs(specs90); + } + + // + XTickZoneLevelSpecs specs100; + isSpecsInited = specs100.Init( + 100, + clrRed, + clrRed, + fillTickZone // + ); + if (isSpecsInited) + { + AddTickZoneLevelSpecs(specs100); + } + + // + } + + // + // Object Creators ... + + // + // Swings ... + + /** + * Create Swing High Object ... + * + * @param swing: XCSwing instance ... + * @param object: XCSwingHighObject pointer ... + * + * @return ( bool ) + */ + bool CreateSwingHigh( + XCSwing &swing, + XCSwingHighObject *&object // + ) + { + // + bool result = false; + + // + object = NULL; + + // + result = + swing.IsValid() && + swing.IsSwingHigh(); + if (!result) + { + return result; + } + + // + string prefix = Prefix(); + long chartID = ChartIdentification(); + int window = SubWindowIdentification(); + + // + int arrow = SwingHighArrow(); + int width = SwingHighWidth(); + color crl = SwingHighColor(); + + // + object = new XCSwingHighObject(); + result = object.Create( + chartID, + window, + arrow, + swing, + prefix // + ); + + // + if (!result) + { + return result; + } + + // + object.ArrowColor(crl); + object.ArrowWidth(width); + object.ArrowAnchor(ANCHOR_BOTTOM); + + // + return result; + } + + /** + * Create Swing Low Object ... + * + * @param swing: XCSwing instance ... + * @param object: XCSwingLowObject pointer ... + * + * @return ( bool ) + */ + bool CreateSwingLow( + XCSwing &swing, + XCSwingLowObject *&object // + ) + { + // + bool result = false; + + // + object = NULL; + + // + result = + swing.IsValid() && + swing.IsSwingLow(); + if (!result) + { + return result; + } + + // + string prefix = Prefix(); + long chartID = ChartIdentification(); + int window = SubWindowIdentification(); + + // + int arrow = SwingLowArrow(); + int width = SwingLowWidth(); + color crl = SwingLowColor(); + + // + object = new XCSwingLowObject(); + result = object.Create( + chartID, + window, + arrow, + swing, + prefix // + ); + + // + if (!result) + { + return result; + } + + // + object.ArrowColor(crl); + object.ArrowWidth(width); + object.ArrowAnchor(ANCHOR_TOP); + + // + return result; + } + + // + // Momentum Bars ... + + /** + * Create Bullish Momentum Bar Object ... + * + * @param momentumBar: XCMomentumBar instance ... + * @param object: XCBullishMomentumObject pointer ... + * + * @return ( bool ) + */ + bool CreateBullishMomentumBar( + XCMomentumBar &momentumBar, + XCBullishMomentumBarObject *&object // + ) + { + // + bool result = false; + + // + object = NULL; + + // + result = + momentumBar.IsValid() && + momentumBar.IsBullish(); + if (!result) + { + return result; + } + + // + string prefix = Prefix(); + long chartID = ChartIdentification(); + int window = SubWindowIdentification(); + + // + int arrow = BullishMomentumBarArrow(); + int width = BullishMomentumBarWidth(); + color crl = BullishMomentumBarColor(); + + // + object = new XCBullishMomentumBarObject(); + result = object.Create( + chartID, + window, + arrow, + momentumBar, + prefix // + ); + + // + if (!result) + { + return result; + } + + // + object.ArrowColor(crl); + object.ArrowWidth(width); + object.ArrowAnchor(ANCHOR_TOP); + + // + return result; + } + + /** + * Create Bearish Momentum Bar Object ... + * + * @param momentumBar: XCMomentumBar instance ... + * @param object: XCBearishMomentumObject pointer ... + * + * @return ( bool ) + */ + bool CreateBearishMomentumBar( + XCMomentumBar &momentumBar, + XCBearishMomentumBarObject *&object // + ) + { + // + bool result = false; + + // + object = NULL; + + // + result = + momentumBar.IsValid() && + momentumBar.IsBearish(); + if (!result) + { + return result; + } + + // + string prefix = Prefix(); + long chartID = ChartIdentification(); + int window = SubWindowIdentification(); + + // + int arrow = BearishMomentumBarArrow(); + int width = BearishMomentumBarWidth(); + color crl = BearishMomentumBarColor(); + + // + object = new XCBearishMomentumBarObject(); + result = object.Create( + chartID, + window, + arrow, + momentumBar, + prefix // + ); + + // + if (!result) + { + return result; + } + + // + object.ArrowColor(crl); + object.ArrowWidth(width); + object.ArrowAnchor(ANCHOR_BOTTOM); + + // + return result; + } + + // + // Rejection Bars ... + + /** + * Create Bullish Rejection Bar Object ... + * + * @param momentumBar: XCRejectionBar instance ... + * @param object: XCBullishRejectionObject pointer ... + * + * @return ( bool ) + */ + bool CreateBullishRejectionBar( + XCRejectionBar &rejectionBar, + XCBullishRejectionBarObject *&object // + ) + { + // + bool result = false; + + // + object = NULL; + + // + result = + rejectionBar.IsValid() && + rejectionBar.IsBullish(); + if (!result) + { + return result; + } + + // + string prefix = Prefix(); + long chartID = ChartIdentification(); + int window = SubWindowIdentification(); + + // + int arrow = BullishRejectionBarArrow(); + int width = BullishRejectionBarWidth(); + color crl = BullishRejectionBarColor(); + + // + object = new XCBullishRejectionBarObject(); + result = object.Create( + chartID, + window, + arrow, + rejectionBar, + prefix // + ); + + // + if (!result) + { + return result; + } + + // + object.ArrowColor(crl); + object.ArrowWidth(width); + object.ArrowAnchor(ANCHOR_TOP); + + // + return result; + } + + /** + * Create Bearish Rejection Bar Object ... + * + * @param rejectionBar: XCRejectionBar instance ... + * @param object: XCBearishRejectionObject pointer ... + * + * @return ( bool ) + */ + bool CreateBearishRejectionBar( + XCRejectionBar &rejectionBar, + XCBearishRejectionBarObject *&object // + ) + { + // + bool result = false; + + // + object = NULL; + + // + result = + rejectionBar.IsValid() && + rejectionBar.IsBearish(); + if (!result) + { + return result; + } + + // + string prefix = Prefix(); + long chartID = ChartIdentification(); + int window = SubWindowIdentification(); + + // + int arrow = BearishRejectionBarArrow(); + int width = BearishRejectionBarWidth(); + color crl = BearishRejectionBarColor(); + + // + object = new XCBearishRejectionBarObject(); + result = object.Create( + chartID, + window, + arrow, + rejectionBar, + prefix // + ); + + // + if (!result) + { + return result; + } + + // + object.ArrowColor(crl); + object.ArrowWidth(width); + object.ArrowAnchor(ANCHOR_BOTTOM); + + // + return result; + } + + // + // Support and Resistance ... + + /** + * Create Support Object ... + * + * @param zone: XCSupportZone instance ... + * @param object: XCSupportZoneObject pointer ... + * + * @return ( bool ) + */ + bool CreateSupportZone( + XCSupportZone &zone, + XCSupportZoneObject *&object // + ) + { + // + bool result = false; + + // + object = NULL; + + // + result = + zone.IsValid(); + if (!result) + { + return result; + } + + // + string prefix = Prefix(); + long chartID = ChartIdentification(); + int window = SubWindowIdentification(); + + // + bool fill = SupportZoneFill(); + int width = SupportZoneWidth(); + color crl = SupportZoneColor(); + ENUM_LINE_STYLE style = SupportZoneStyle(); + + // + object = new XCSupportZoneObject(); + result = object.Create( + chartID, + window, + zone, + prefix // + ); + + // + if (!result) + { + return result; + } + + // + object.ZoneFill(fill); + object.ZoneColor(crl); + object.ZoneWidth(width); + object.ZoneStyle(style); + + // + return result; + } + + /** + * Create Resistance Object ... + * + * @param zone: XCResistanceZone instance ... + * @param object: XCResistanceZoneObject pointer ... + * + * @return ( bool ) + */ + bool CreateResistanceZone( + XCResistanceZone &zone, + XCResistanceZoneObject *&object // + ) + { + // + bool result = false; + + // + object = NULL; + + // + result = + zone.IsValid(); + if (!result) + { + return result; + } + + // + string prefix = Prefix(); + long chartID = ChartIdentification(); + int window = SubWindowIdentification(); + + // + bool fill = ResistanceZoneFill(); + int width = ResistanceZoneWidth(); + color crl = ResistanceZoneColor(); + ENUM_LINE_STYLE style = ResistanceZoneStyle(); + + // + object = new XCResistanceZoneObject(); + result = object.Create( + chartID, + window, + zone, + prefix // + ); + + // + if (!result) + { + return result; + } + + // + object.ZoneFill(fill); + object.ZoneColor(crl); + object.ZoneWidth(width); + object.ZoneStyle(style); + + // + return result; + } + + // + // Supply and Demand Zones ... + + /** + * Create Supply Object ... + * + * @param zone: XCSupplyZone instance ... + * @param object: XCSupplyZoneObject pointer ... + * + * @return ( bool ) + */ + bool CreateSupplyZone( + XCSupplyZone &zone, + XCSupplyZoneObject *&object // + ) + { + // + bool result = false; + + // + object = NULL; + + // + result = + zone.IsValid(); + if (!result) + { + return result; + } + + // + string prefix = Prefix(); + long chartID = ChartIdentification(); + int window = SubWindowIdentification(); + + // + bool fill = SupplyZoneFill(); + int width = SupplyZoneWidth(); + color crl = SupplyZoneColor(); + ENUM_LINE_STYLE style = SupplyZoneStyle(); + + // + object = new XCSupplyZoneObject(); + result = object.Create( + chartID, + window, + zone, + prefix // + ); + + // + if (!result) + { + return result; + } + + // + object.ZoneFill(fill); + object.ZoneColor(crl); + object.ZoneWidth(width); + object.ZoneStyle(style); + + // + return result; + } + + /** + * Create Demand Object ... + * + * @param zone: XCDemandZone instance ... + * @param object: XCDemandZoneObject pointer ... + * + * @return ( bool ) + */ + bool CreateDemandZone( + XCDemandZone &zone, + XCDemandZoneObject *&object // + ) + { + // + bool result = false; + + // + object = NULL; + + // + result = + zone.IsValid(); + if (!result) + { + return result; + } + + // + string prefix = Prefix(); + long chartID = ChartIdentification(); + int window = SubWindowIdentification(); + + // + bool fill = DemandZoneFill(); + int width = DemandZoneWidth(); + color crl = DemandZoneColor(); + ENUM_LINE_STYLE style = DemandZoneStyle(); + + // + object = new XCDemandZoneObject(); + result = object.Create( + chartID, + window, + zone, + prefix // + ); + + // + 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: XCOrderBlock instance ... + * @param object: XCBullishOrderBlockObject pointer ... + * + * @return ( bool ) + */ + bool CreateBullishOrderBlock( + XCOrderBlock &zone, + XCBullishOrderBlockObject *&object // + ) + { + // + bool result = false; + + // + object = NULL; + + // + result = + zone.IsValid() && + zone.IsBullish(); + if (!result) + { + return result; + } + + // + string prefix = Prefix(); + long chartID = ChartIdentification(); + int window = SubWindowIdentification(); + + // + bool fill = BullishOrderBlockFill(); + int width = BullishOrderBlockWidth(); + color crl = BullishOrderBlockColor(); + ENUM_LINE_STYLE style = BullishOrderBlockStyle(); + + // + object = new XCBullishOrderBlockObject(); + result = object.Create( + chartID, + window, + zone, + prefix // + ); + + // + 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: XCOrderBlock instance ... + * @param object: XCBearishOrderBlockObject pointer ... + * + * @return ( bool ) + */ + bool CreateBearishOrderBlock( + XCOrderBlock &zone, + XCBearishOrderBlockObject *&object // + ) + { + // + bool result = false; + + // + object = NULL; + + // + result = + zone.IsValid() && + zone.IsBearish(); + if (!result) + { + return result; + } + + // + string prefix = Prefix(); + long chartID = ChartIdentification(); + int window = SubWindowIdentification(); + + // + bool fill = BearishOrderBlockFill(); + int width = BearishOrderBlockWidth(); + color crl = BearishOrderBlockColor(); + ENUM_LINE_STYLE style = BearishOrderBlockStyle(); + + // + object = new XCBearishOrderBlockObject(); + result = object.Create( + chartID, + window, + zone, + prefix // + ); + + // + if (!result) + { + return result; + } + + // + object.ZoneFill(fill); + object.ZoneColor(crl); + object.ZoneWidth(width); + object.ZoneStyle(style); + + // + return result; + } + + bool CreateOrderBlock( + XCOrderBlock &zone, + XCBaseObject *&object // + ) + { + // + bool result = false; + + // + object = NULL; + + // + result = zone.IsValid(); + if (!result) + { + return result; + } + + // + bool isBullish = zone.IsBullish(); + if (isBullish) + { + // + XCBullishOrderBlockObject *iObj; + result = CreateBullishOrderBlock( + zone, + iObj // + ); + if (result) + { + object = (XCBaseObject *)iObj; + } + } + else + { + // + XCBearishOrderBlockObject *iObj; + result = CreateBearishOrderBlock( + zone, + iObj // + ); + if (result) + { + object = (XCBaseObject *)iObj; + } + } + + // + return result; + } + + // + // Fair Value Gaps ... + + /** + * Create Bullish Fair Value Gap Object ... + * + * @param zone: XCFVG instance ... + * @param object: XCBullishOrderBlockObject pointer ... + * + * @return ( bool ) + */ + bool CreateBullishFairValueGap( + XCFVG &zone, + XCBullishFairValueGapObject *&object // + ) + { + // + bool result = false; + + // + result = zone.IsValid() && + zone.IsBullish(); + if (!result) + { + return result; + } + + // + string prefix = Prefix(); + long chartID = ChartIdentification(); + int window = SubWindowIdentification(); + + // + bool fill = BullishFVGFill(); + int width = BullishFVGWidth(); + color crl = BullishFVGColor(); + ENUM_LINE_STYLE style = BullishFVGStyle(); + + // + object = new XCBullishFairValueGapObject(); + result = object.Create( + chartID, + window, + zone, + prefix // + ); + + // + if (!result) + { + return result; + } + + // + object.ZoneFill(fill); + object.ZoneColor(crl); + object.ZoneWidth(width); + object.ZoneStyle(style); + + // + return result; + } + + /** + * Create Bearish Fair Value Gap Object ... + * + * @param zone: XCFVG instance ... + * @param object: XCBearishOrderBlockObject pointer ... + * + * @return ( bool ) + */ + bool CreateBearishFairValueGap( + XCFVG &zone, + XCBearishFairValueGapObject *&object // + ) + { + // + bool result = false; + + // + result = zone.IsValid() && + zone.IsBearish(); + if (!result) + { + return result; + } + + // + string prefix = Prefix(); + long chartID = ChartIdentification(); + int window = SubWindowIdentification(); + + // + bool fill = BearishFVGFill(); + int width = BearishFVGWidth(); + color crl = BearishFVGColor(); + ENUM_LINE_STYLE style = BearishFVGStyle(); + + // + object = new XCBearishFairValueGapObject(); + result = object.Create( + chartID, + window, + zone, + prefix // + ); + + // + if (!result) + { + return result; + } + + // + object.ZoneFill(fill); + object.ZoneColor(crl); + object.ZoneWidth(width); + object.ZoneStyle(style); + + // + return result; + } + + bool CreateFairValueGap( + XCFVG &zone, + XCBaseObject *&object // + ) + { + // + bool result = false; + + // + object = NULL; + + // + result = zone.IsValid(); + if (!result) + { + return result; + } + + // + bool isBullish = zone.IsBullish(); + if (isBullish) + { + // + XCBullishFairValueGapObject *iObj; + result = CreateBullishFairValueGap( + zone, + iObj // + ); + if (result) + { + object = (XCBaseObject *)iObj; + } + } + else + { + // + XCBearishFairValueGapObject *iObj; + result = CreateBearishFairValueGap( + zone, + iObj // + ); + if (result) + { + object = (XCBaseObject *)iObj; + } + } + + // + return result; + } + + // + // Ticks Zone ... + + /** + * Add Tick Zone Draw Specifications ... + * + * @param specs: XTickZoneLevelSpecs instance ... + */ + void AddTickZoneLevelSpecs( + XTickZoneLevelSpecs &specs // + ) + { + // + if (!specs.IsValid()) + { + return; + } + + // + bool isExists = false; + int count = ArraySize(mTicksZoneSpecs); + if (IsValidSize(count)) + { + // + for (int i = 0; i < count; i++) + { + // + XTickZoneLevelSpecs iSpec = mTicksZoneSpecs[i]; + + // + isExists = specs.percent == iSpec.percent; + if (isExists) + { + break; + } + } + } + if (isExists) + { + return; + } + + // + AddRef( + specs, + mTicksZoneSpecs // + ); + } + + /** + * Draw Specified Ticker Zone ... + * + * @param zone: XCTicksZone instance Specified Ticker Zone ... + * @param object: XCTicksZoneObject pointer ... + * + * @return ( bool ) + */ + bool CreateTicksZone( + XCTicksZone &zone, + XCTicksZoneObject *&object // + ) + { + // + bool result = false; + + // + object = NULL; + + // + result = zone.IsValid(); + if (!result) + { + return result; + } + + // + string prefix = Prefix(); + long chartID = ChartIdentification(); + int window = SubWindowIdentification(); + + // + object = new XCTicksZoneObject(); + result = object.Create( + chartID, + window, + zone, + mTicksZoneSpecs, + prefix // + ); + + // + if (!result) + { + return result; + } + + // + return result; + } + + /** + * Create Consolidation Zone Object ... + * + * @param zone: XConsolidationZone instance Reference ... + * + * @return ( bool ) + */ + bool CreateConsolidationZone( + XConsolidationZone &zone, + XCConsolidationZoneObject *&object // + ) + { + // + bool result = false; + + // + object = NULL; + + // + result = zone.IsValid(); + if (!result) + { + return result; + } + + // + string prefix = Prefix(); + long chartID = ChartIdentification(); + int window = SubWindowIdentification(); + + // + color czColor = IsBullish(zone.dir) + ? BarBullishColor() + : BarBearishColor(); + + // + object = new XCConsolidationZoneObject(); + result = object.Create( + chartID, + window, + zone, + prefix // + ); + + // + if (result) + { + object.ZoneColor(czColor); + } + + // + return result; + } + + /** + * Create Bar Object ... + * + * @param bar: XOHCL instance Reference ... + * @param object: XCOHCLObject pointer Reference .. + * @param to: Datetime ... + * + * @return ( bool ) + */ + bool CreateBar( + XOHCL &bar, + XCOHCLObject *&object, + datetime to = NULL // + ) + { + // + bool result = false; + + // + object = NULL; + + // + result = bar.IsValid(); + if (!result) + { + return result; + } + + // + to = NormalizeTime(to); + + // + string prefix = Prefix(); + long chartID = ChartIdentification(); + int window = SubWindowIdentification(); + + // + int width = BarWidth(); + + // + color mBullishColor = BarBullishColor(); + color mBearishColor = BarBearishColor(); + + // + bool fillBody = BarFillBody(); + bool fillHighShadow = BarFillHighShadow(); + bool fillLowShadow = BarFillLowShadow(); + + // + ENUM_LINE_STYLE bodyStyle = BarBodyStyle(); + ENUM_LINE_STYLE highShadowStyle = BarHighShadowStyle(); + ENUM_LINE_STYLE lowShadowStyle = BarLowShadowStyle(); + + // + object = new XCOHCLObject(); + result = object.Create( + chartID, + window, + bar, + to, + prefix // + ); + if (result) + { + // + // Apply Styling ... + + // + object.BodyWidth(width); + object.LowShadowWidth(width); + object.HighShadowWidth(width); + + // + object.BodyStyle(bodyStyle); + object.LowShadowStyle(lowShadowStyle); + object.HighShadowStyle(highShadowStyle); + + // + bool isBullish = bar.IsBullish(); + if (isBullish) + { + // + object.BodyColor(mBullishColor); + object.LowShadowColor(mBullishColor); + object.HighShadowColor(mBullishColor); + } + else + { + // + object.BodyColor(mBearishColor); + object.LowShadowColor(mBearishColor); + object.HighShadowColor(mBearishColor); + } + + // + object.BodyFill(fillBody); + object.HighShadowFill(fillHighShadow); + object.LowShadowFill(fillLowShadow); + } + + // + return result; + } + + /** + * Create Bar Arrow Object ... + * + * @param bar: XOHCL instance Reference ... + * @param priceType: ENUM_X_PRICE member ... + * @param arrow: int, Arrow Code ... + * @param clr: color, Arro Color ... + * @param width: int, Arrow Width ... + * @param anchor: ENUM_ARROW_ANCHOR, anchor of Arrow ... + * @param name: string, name of Arrow ... + * + * @return ( bool ) + */ + bool CreateBarArrow( + XOHCL &bar, + XCBarArrowObject *&object, + ENUM_X_PRICE priceType, + int arrow = 159, + color clr = clrYellow, + int width = 3, + ENUM_ARROW_ANCHOR anchor = ANCHOR_BOTTOM, + string name = NULL // + ) + { + // + bool result = false; + + // + object = NULL; + + // + result = bar.IsValid(); + if (!result) + { + return result; + } + + // + string barTag = bar.GetTag(name); + + // + string prefix = Prefix(); + long chartID = ChartIdentification(); + int window = SubWindowIdentification(); + + // + color mBullishColor = BarBullishColor(); + color mBearishColor = BarBearishColor(); + + // + prefix = + (IsValid(prefix) + ? prefix + "_" + : prefix) + + barTag; + + // + object = new XCBarArrowObject(); + result = object + .CreateByBar( + chartID, + prefix, + window, + arrow, + bar, + priceType // + ); + if (result) + { + // + object.ArrowColor(clr); + object.ArrowWidth(width); + } + + // + return result; + } + + /** + * Create Specific Box on Chart ... + * + * @param upper: Double ... + * @param lower: Double ... + * @param from: Datetime ... + * @param to: Datetime ... + * @param clr: Color ... + * @param width: Integer ... + * @param fill: Boolean ... + * @param style: ENUM_LINE_STYLE member ... + * + * @return ( bool ) + */ + bool CreateBox( + XCBoxObject *&object, + string name, + double upper, + double lower, + datetime from, + datetime to, + color clr = clrYellowGreen, + int width = 1, + bool fill = false, + ENUM_LINE_STYLE style = STYLE_SOLID // + ) + { + // + bool result = false; + + // + object = NULL; + + // + to = NormalizeTime(to); + + // + string dateStr = ToFormatString(from) + "|" + ToFormatString(to); + string dateMD5 = ToMD5(dateStr); + if (!IsValid(name)) + { + // + name = "XBox_" + + ToString(upper) + "_" + + ToString(lower) + "_" + + dateMD5; + } + + // + result = + upper > 0 && + lower > 0 && + to > from && + IsValid(to) && + IsValid(name) && + IsValid(from) && + upper > lower; + if (!result) + { + return result; + } + + // + string prefix = Prefix(); + long chartID = ChartIdentification(); + int window = SubWindowIdentification(); + + // + object = new XCBoxObject(); + result = object.Create( + chartID, + window, + name, + upper, + lower, + from, + to, + prefix // + ); + + // + if (!result) + { + return result; + } + + // + object.BoxColor(clr); + object.BoxFill(fill); + object.BoxWidth(width); + object.BoxStyle(style); + + // + return result; + } + + /** + * Create Specific Box on Chart ... + * + * @param box: XBoxZone instance Reference ... + * @param clr: Color ... + * @param width: Integer ... + * @param fill: Boolean ... + * @param style: ENUM_LINE_STYLE member ... + * + * @return ( bool ) + */ + bool DrawBox( + XBoxZone &box, + XCBoxObject *&object // + ) + { + // + bool result = false; + + // + object = NULL; + + // + result = box.IsValid(); + if (!result) + { + return result; + } + + // + int width = 1; + bool fill = false; + color clr = + box.IsBullish() + ? BullishFVGColor() + : BearishFVGColor(); + ENUM_LINE_STYLE style = STYLE_DASHDOTDOT; + string name = box.GetTag(); + + // + result = CreateBox( + object, + name, + box.upper, + box.lower, + box.from, + box.to, + clr, + width, + fill, + style // + ); + + // + return result; + } + + /** + * Create Specific Box on Chart ... + * + * @param box: XBoxZone instance Reference ... + * @param clr: Color ... + * @param width: Integer ... + * @param fill: Boolean ... + * @param style: ENUM_LINE_STYLE member ... + * + * @return ( bool ) + */ + bool CreateBox( + XBoxZone &box, + XCBoxObject *&object, + color clr = clrYellowGreen, + int width = 1, + bool fill = false, + ENUM_LINE_STYLE style = STYLE_SOLID // + ) + { + // + bool result = false; + + // + object = NULL; + + // + result = box.IsValid(); + if (!result) + { + return result; + } + + // + string name = box.GetTag(); + + // + result = CreateBox( + object, + name, + box.upper, + box.lower, + box.from, + box.to, + clr, + width, + fill, + style // + ); + + // + return result; + } + + /** + * Draw Specified Signal ... + * + * @param signal: XSignal instance ... + */ + bool DrawSignal( + XSignal &signal, + XCSignalObject *&object, + int length = 3 // + ) + { + // + bool result = false; + + // + object = NULL; + length = NormalizeInt(length, 3); + + // + result = signal.IsValid(); + if (!result) + { + return result; + } + + // + string prefix = Prefix(); + long chartID = ChartIdentification(); + int window = SubWindowIdentification(); + + // + object = new XCSignalObject(); + result = object.Create( + chartID, + window, + signal, + length, + prefix // + ); + if (!result) + { + return result; + } + + // + object.TPWidth(1); + object.TPColor(clrGreen); + object.TPWidth(STYLE_DOT); + + // + object.SLWidth(1); + object.SLColor(clrRed); + object.SLWidth(STYLE_DOT); + + // + object.TargetWidth(1); + object.TargetColor(clrLightBlue); + object.TargetWidth(STYLE_DOT); + + // + object.EntryWidth(1); + object.EntryColor(clrYellow); + object.EntryWidth(STYLE_DOT); + + // + return result; + } + + /** + * Draw Signal Box ... + * + * @param box: XSignalBox instance Reference ... + * @param objects: XCBaseObject pointer instance Reference ... + * + * @return ( bool ) + */ + bool DrawSignalBox( + XSignalBox &box, + XCBaseObject *&objects[], + color clr = CLR_NONE // + ) + { + // + bool result = false; + + // + Clean(objects); + + // + bool has = false; + bool hasColor = clr != CLR_NONE; + + // + // Order Block ... + if (box.ob.IsValid()) + { + // + XCBoxObject *iObj; + has = DrawBox( + box.ob, + iObj // + ); + if (has) + { + // + iObj.BoxStyle(STYLE_DASH); + + // + if (hasColor) + { + iObj.BoxColor(clr); + } + + // + Add( + (XCBaseObject *)iObj, + objects // + ); + } + } + + // + // Fair Value Gap ... + if (box.fvg.IsValid()) + { + // + XCBoxObject *iObj; + has = DrawBox( + box.fvg, + iObj // + ); + if (has) + { + // + iObj.BoxStyle(STYLE_SOLID); + + // + if (hasColor) + { + iObj.BoxColor(clr); + } + + // + Add( + (XCBaseObject *)iObj, + objects // + ); + } + } + + // + // Sharp Zone ... + if (box.sharp.IsValid()) + { + // + XCBoxObject *iObj; + has = DrawBox( + box.sharp, + iObj // + ); + if (has) + { + // + iObj.BoxStyle(STYLE_DOT); + + // + if (hasColor) + { + iObj.BoxColor(clr); + } + + // + Add( + (XCBaseObject *)iObj, + objects // + ); + } + } + + // + result = HasChild(objects); + + // + return result; + } + + /** + * Draw Specified POI State ... + * + * @param state: XPOIState instance Reference ... + * @param drawnObjects: CArrayObj instance for Holding Drawn Objects ... + * @param drawTicksZone: Boolean ... + * @param ignoreSwingHighs: Boolean ... + * @param ignoreSwingLows: Boolean ... + * @param ignoreSupportZones: Boolean ... + * @param ignoreResistanceZones: Boolean ... + * @param ignoreSupplyZones: Boolean ... + * @param ignoreDemandZones: Boolean ... + * @param ignoreBullishOrderBlocks: Boolean ... + * @param ignoreBearishOrderBlocks: Boolean ... + * @param ignoreBullishFairValueGaps: Boolean ... + * @param ignoreBearishFairValueGaps: Boolean ... + * @param ignoreBullishRejectionBars: Boolean ... + * @param ignoreBearishRejectionBars: Boolean ... + * @param ignoreBullishMomentumBars: Boolean ... + * @param ignoreBearishMomentumBars: Boolean ... + */ + int DrawState( + XPOIState &state, + XCBaseObject *&drawnObjects[], + // + // Bullish ... + bool ignoreSwingLows = false, + bool ignoreDemandZones = false, + bool ignoreSupportZones = false, + bool ignoreBullishSharps = false, + bool ignoreBullishSpikes = false, + bool ignoreBullishPullbacks = false, + bool ignoreBullishMomentums = false, + bool ignoreBullishRejections = false, + bool ignoreBullishOrderBlocks = false, + bool ignoreBullishFairValueGaps = false, + bool ignoreBullishConsolidationZones = false, + // + // Bearish ... + bool ignoreSwingHighs = false, + bool ignoreSupplyZones = false, + bool ignoreResistanceZones = false, + bool ignoreBearishSharps = false, + bool ignoreBearishSpikes = false, + bool ignoreBearishPullbacks = false, + bool ignoreBearishMomentums = false, + bool ignoreBearishRejections = false, + bool ignoreBearishOrderBlocks = false, + bool ignoreBearishFairValueGaps = false, + bool ignoreBearishConsolidationZones = false // + ) + { + // + int result = 0; + + // + if (!state.IsValid() || + !state.HasChild()) + { + return result; + } + + // + Clean(drawnObjects); + + // + // Swings ... + + // + // SwingHighs ... + if (!ignoreSwingHighs) + { + // + int count = state.CountSwingHighs(); + if (IsValidSize(count)) + { + // + for (int i = 0; i < count; i++) + { + // + XCSwing *iSwing = state.swingHighs[i]; + XCSwingHighObject *iObj; + + // + bool isCreated = CreateSwingHigh( + iSwing, + iObj // + ); + if (isCreated) + { + // + Add( + (XCBaseObject *)iObj, + drawnObjects // + ); + } + } + } + } + + // + // SwingLows ... + if (!ignoreSwingLows) + { + // + int count = state.CountSwingLows(); + if (IsValidSize(count)) + { + // + for (int i = 0; i < count; i++) + { + // + XCSwing *iSwing = state.swingLows[i]; + XCSwingLowObject *iObj; + + // + bool isCreated = CreateSwingLow( + iSwing, + iObj // + ); + if (isCreated) + { + // + Add( + (XCBaseObject *)iObj, + drawnObjects // + ); + } + } + } + } + + // + // Support / Resistance ... + + // + // SupportZones ... + if (!ignoreSupportZones) + { + // + int count = state.CountSupportZones(); + if (IsValidSize(count)) + { + // + for (int i = 0; i < count; i++) + { + // + XCSupportZone *iZone = state.supportZones[i]; + XCSupportZoneObject *iObj; + + // + bool isCreated = CreateSupportZone( + iZone, + iObj // + ); + if (isCreated) + { + // + Add( + (XCBaseObject *)iObj, + drawnObjects // + ); + } + } + } + } + + // + // ResistanceZones ... + if (!ignoreResistanceZones) + { + // + int count = state.CountResistanceZones(); + if (IsValidSize(count)) + { + // + for (int i = 0; i < count; i++) + { + // + XCResistanceZone *iZone = state.resistanceZones[i]; + XCResistanceZoneObject *iObj; + + // + bool isCreated = CreateResistanceZone( + iZone, + iObj // + ); + if (isCreated) + { + // + Add( + (XCBaseObject *)iObj, + drawnObjects // + ); + } + } + } + } + + // + // Supply / Demand ... + + // + // SupplyZones ... + if (!ignoreSupplyZones) + { + // + int count = state.CountSupplyZones(); + if (IsValidSize(count)) + { + // + for (int i = 0; i < count; i++) + { + // + XCSupplyZone *iZone = state.supplyZones[i]; + XCSupplyZoneObject *iObj; + + // + bool isCreated = CreateSupplyZone( + iZone, + iObj // + ); + if (isCreated) + { + // + Add( + (XCBaseObject *)iObj, + drawnObjects // + ); + } + } + } + } + + // + // DemandZones ... + if (!ignoreDemandZones) + { + // + int count = state.CountDemandZones(); + if (IsValidSize(count)) + { + // + for (int i = 0; i < count; i++) + { + // + XCDemandZone *iZone = state.demandZones[i]; + XCDemandZoneObject *iObj; + + // + bool isCreated = CreateDemandZone( + iZone, + iObj // + ); + if (isCreated) + { + // + Add( + (XCBaseObject *)iObj, + drawnObjects // + ); + } + } + } + } + + // + // Order Blocks ... + + // + // BullishOrderBlocks ... + if (!ignoreBullishOrderBlocks) + { + // + int count = state.CountBullishOrderBlocks(); + if (IsValidSize(count)) + { + // + for (int i = 0; i < count; i++) + { + // + XCOrderBlock *iZone = state.bullishOrderBlocks[i]; + XCBullishOrderBlockObject *iObj; + + // + bool isCreated = CreateBullishOrderBlock( + iZone, + iObj // + ); + if (isCreated) + { + // + Add( + (XCBaseObject *)iObj, + drawnObjects // + ); + } + } + } + } + + // + // BearishOrderBlocks ... + if (!ignoreBearishOrderBlocks) + { + // + int count = state.CountBearishOrderBlocks(); + if (IsValidSize(count)) + { + // + for (int i = 0; i < count; i++) + { + // + XCOrderBlock *iZone = state.bearishOrderBlocks[i]; + XCBearishOrderBlockObject *iObj; + + // + bool isCreated = CreateBearishOrderBlock( + iZone, + iObj // + ); + if (isCreated) + { + // + Add( + (XCBaseObject *)iObj, + drawnObjects // + ); + } + } + } + } + + // + // Fair Value Gaps ... + + // + // BullishFairValueGaps ... + if (!ignoreBullishFairValueGaps) + { + // + int count = state.CountBullishFairValueGaps(); + if (IsValidSize(count)) + { + // + for (int i = 0; i < count; i++) + { + // + XCFVG *iZone = state.bullishFairValueGaps[i]; + XCBullishFairValueGapObject *iObj; + + // + bool isCreated = CreateBullishFairValueGap( + iZone, + iObj // + ); + if (isCreated) + { + // + Add( + (XCBaseObject *)iObj, + drawnObjects // + ); + } + } + } + } + + // + // BearishFairValueGaps ... + if (!ignoreBearishFairValueGaps) + { + // + int count = state.CountBearishFairValueGaps(); + if (IsValidSize(count)) + { + // + for (int i = 0; i < count; i++) + { + // + XCFVG *iZone = state.bearishFairValueGaps[i]; + XCBearishFairValueGapObject *iObj; + + // + bool isCreated = CreateBearishFairValueGap( + iZone, + iObj // + ); + if (isCreated) + { + // + Add( + (XCBaseObject *)iObj, + drawnObjects // + ); + } + } + } + } + + // + // Rejections ... + + // + // BullishRejectionBars ... + if (!ignoreBullishRejections) + { + // + int count = state.CountBullishRejections(); + if (IsValidSize(count)) + { + // + for (int i = 0; i < count; i++) + { + // + XCRejectionBar *iBar = state.bullishRejections[i]; + XCBullishRejectionBarObject *iObj; + + // + bool isCreated = CreateBullishRejectionBar( + iBar, + iObj // + ); + if (isCreated) + { + // + Add( + (XCBaseObject *)iObj, + drawnObjects // + ); + } + } + } + } + + // + // BearishRejectionBars ... + if (!ignoreBearishRejections) + { + // + int count = state.CountBearishRejections(); + if (IsValidSize(count)) + { + // + for (int i = 0; i < count; i++) + { + // + XCRejectionBar *iBar = state.bearishRejections[i]; + XCBearishRejectionBarObject *iObj; + + // + bool isCreated = CreateBearishRejectionBar( + iBar, + iObj // + ); + if (isCreated) + { + // + Add( + (XCBaseObject *)iObj, + drawnObjects // + ); + } + } + } + } + + // + // Momentums ... + + // + // BullishMomentumBars ... + if (!ignoreBullishMomentums) + { + // + int count = state.CountBullishMomentums(); + if (IsValidSize(count)) + { + // + for (int i = 0; i < count; i++) + { + // + XCMomentumBar *iBar = state.bullishMomentums[i]; + XCBullishMomentumBarObject *iObj; + + // + bool isCreated = CreateBullishMomentumBar( + iBar, + iObj // + ); + if (isCreated) + { + // + Add( + (XCBaseObject *)iObj, + drawnObjects // + ); + } + } + } + } + + // + // BearishMomentumBars ... + if (!ignoreBearishMomentums) + { + // + int count = state.CountBearishMomentums(); + if (IsValidSize(count)) + { + // + for (int i = 0; i < count; i++) + { + // + XCMomentumBar *iBar = state.bearishMomentums[i]; + XCBearishMomentumBarObject *iObj; + + // + bool isCreated = CreateBearishMomentumBar( + iBar, + iObj // + ); + if (isCreated) + { + // + Add( + (XCBaseObject *)iObj, + drawnObjects // + ); + } + } + } + } + + // + // Pullbacks ... + + // + // Bullish ... + if (!ignoreBullishPullbacks) + { + // + int count = state.CountBullishPullbacks(); + if (IsValidSize(count)) + { + // + for (int i = 0; i < count; i++) + { + // + XCBoxObject *iObj; + bool isCreated = DrawBox( + state.bullishPullbacks[i], + iObj // + ); + if (isCreated) + { + // + Add( + (XCBaseObject *)iObj, + drawnObjects // + ); + } + } + } + } + + // + // Bearish ... + if (!ignoreBearishPullbacks) + { + // + int count = state.CountBearishPullbacks(); + if (IsValidSize(count)) + { + // + for (int i = 0; i < count; i++) + { + // + XCBoxObject *iObj; + bool isCreated = DrawBox( + state.bearishPullbacks[i], + iObj // + ); + if (isCreated) + { + // + Add( + (XCBaseObject *)iObj, + drawnObjects // + ); + } + } + } + } + + // + // Consolidation Zones ... + + // + // Bullish Consolidation Zones ... + if (!ignoreBullishConsolidationZones) + { + // + int count = state.CountBullishConsolidationZones(); + if (IsValidSize(count)) + { + // + for (int i = 0; i < count; i++) + { + // + XCConsolidationZoneObject *iObj; + bool isCreated = CreateConsolidationZone( + state.bullishConsolidationZones[i], + iObj // + ); + if (isCreated) + { + // + Add( + (XCBaseObject *)iObj, + drawnObjects // + ); + } + } + } + } + + // + // Bearish Consolidation Zones ... + if (!ignoreBearishConsolidationZones) + { + // + int count = state.CountBearishConsolidationZones(); + if (IsValidSize(count)) + { + // + for (int i = 0; i < count; i++) + { + // + XCConsolidationZoneObject *iObj; + bool isCreated = CreateConsolidationZone( + state.bearishConsolidationZones[i], + iObj // + ); + if (isCreated) + { + // + Add( + (XCBaseObject *)iObj, + drawnObjects // + ); + } + } + } + } + + // + // Spikes ... + + // + // Bullish ... + if (!ignoreBullishSpikes) + { + // + int count = state.CountBullishSpikes(); + if (IsValidSize(count)) + { + // + for (int i = 0; i < count; i++) + { + // + XCBoxObject *iObj; + bool isCreated = DrawBox( + state.bullishSpikes[i], + iObj // + ); + if (isCreated) + { + // + Add( + (XCBaseObject *)iObj, + drawnObjects // + ); + } + } + } + } + + // + // Bearish ... + if (!ignoreBearishSpikes) + { + // + int count = state.CountBearishSpikes(); + if (IsValidSize(count)) + { + // + for (int i = 0; i < count; i++) + { + // + XCBoxObject *iObj; + bool isCreated = DrawBox( + state.bearishSpikes[i], + iObj // + ); + if (isCreated) + { + // + Add( + (XCBaseObject *)iObj, + drawnObjects // + ); + } + } + } + } + + // + // Sharps ... + + // + // Bullish ... + if (!ignoreBullishSharps) + { + // + int count = state.CountBullishSharps(); + if (IsValidSize(count)) + { + // + for (int i = 0; i < count; i++) + { + // + XCBoxObject *iObj; + bool isCreated = DrawBox( + state.bullishSharps[i], + iObj // + ); + if (isCreated) + { + // + Add( + (XCBaseObject *)iObj, + drawnObjects // + ); + } + } + } + } + + // + // Bearish ... + if (!ignoreBearishSharps) + { + // + int count = state.CountBearishSharps(); + if (IsValidSize(count)) + { + // + for (int i = 0; i < count; i++) + { + // + XCBoxObject *iObj; + bool isCreated = DrawBox( + state.bearishSharps[i], + iObj // + ); + if (isCreated) + { + // + Add( + (XCBaseObject *)iObj, + drawnObjects // + ); + } + } + } + } + + // + result = ArraySize(drawnObjects); + + // + return result; + } + + // + protected: + // + + // + private: + // + + // + // Props ... + + // + string mPrefix; // Prefix of Created Objects ... + long mChartIdentification; // Chart Id ... + int mSubWindowIdentification; // Sub Window ... + + // + // XOHCL ... + int mBarWidth; // Bar Width ... + color mBarBullishColor; // Bar Bullish Color ... + color mBarBearishColor; // Bar Bearish Color ... + bool mBarFillHighShadow; // Fill Bar High Shadow ... + ENUM_LINE_STYLE mBarHighShadowStyle; // Bar High Shadow Style ... + bool mBarFillBody; // Fill Bar Body ... + ENUM_LINE_STYLE mBarBodyStyle; // Bar Body Style ... + bool mBarFillLowShadow; // Fill Bar Low Show ... + ENUM_LINE_STYLE mBarLowShadowStyle; // Bar Low Shadow Style ... + + // + // 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 ... + + // + // Ticks Zone ... + XTickZoneLevelSpecs mTicksZoneSpecs[]; // Zone Draw Specifications ... + + // +}; \ No newline at end of file diff --git a/Documents/BKP/x-saherelm.x-poi.extensions.lib.mq5 b/Documents/BKP/x-saherelm.x-poi.extensions.lib.mq5 new file mode 100644 index 00000000..7f984fa4 --- /dev/null +++ b/Documents/BKP/x-saherelm.x-poi.extensions.lib.mq5 @@ -0,0 +1,3804 @@ +/////////////////////////////////////////////////////// +// +// SaherElm IT Center MQL5 Seriallize Library +// --------------------------------------- +// Name: XPOILib +// Description: All models related to POIs ... +// +// +// Maintainer: +// ------------ +// Hadi Khazaee Asl (hadi_khazaee_asl@yahoo.com) +// +////////////////////////////////////////////////////// +// +// Global Properties ... +#property library +#property copyright "Copyright `023, SaherElm IT Center" +#property link "https://www.saherelm.ir" +#property version "1.00" +#property strict + +// +// Imports ... +#include "../Libraries/x-saherelm.x-poi.lib.mq5" + +// +// Extensions ... + +template +bool ToZone( + T *&source[], + XCZone *&dest[] // +) +{ + // + bool result = false; + + // + Clean(dest); + + // + int count = ArraySize(source); + result = IsValidSize(count); + if (!result) + { + return result; + } + + // + for (int i = 0; i < count; i++) + { + // + T *item = source[i]; + + // + if (item != NULL) + { + // + Add( + (XCZone *)item, + dest // + ); + } + } + + // + int destCount = ArraySize(dest); + result = IsValidSize(destCount); + + // + return result; +} + +template +bool ToBox( + T *&source[], + XBoxZone &dest[] // +) +{ + // + bool result = false; + + // + Clean(dest); + + // + int count = ArraySize(source); + result = IsValidSize(count); + if (!result) + { + return result; + } + + // + for (int i = 0; i < count; i++) + { + // + T *item = source[i]; + + // + if (item != NULL) + { + // + XBoxZone iBox; + bool hasBox = ToBox( + iBox, + item // + ); + + // + if (hasBox) + { + // + AddRef( + iBox, + dest // + ); + } + } + } + + // + int destCount = ArraySize(dest); + result = IsValidSize(destCount); + + // + return result; +} + +template +int GetOldest( + T *&source[] // +) +{ + // + int result = -1; + + // + int count = ArraySize(source); + if (!IsValidSize(count)) + { + return result; + } + + // + XBoxZone boxes[]; + bool isConverted = ToBox( + source, + boxes // + ); + if (!isConverted) + { + return result; + } + + // + int boxesCount = ArraySize(boxes); + + // + if (count != boxesCount) + { + return result; + } + + // + result = GetOldest(boxes); + + // + Clean(boxes); + + // + return result; +} + +template +int GetYoungest( + T *&source[] // +) +{ + // + int result = -1; + + // + int count = ArraySize(source); + if (!IsValidSize(count)) + { + return result; + } + + // + XBoxZone boxes[]; + bool isConverted = ToBox( + source, + boxes // + ); + if (!isConverted) + { + return result; + } + + // + int boxesCount = ArraySize(boxes); + + // + if (count != boxesCount) + { + return result; + } + + // + result = GetYoungest(boxes); + + // + Clean(boxes); + + // + return result; +} + +template +int GetLowest( + T *&source[] // +) +{ + // + int result = -1; + + // + int count = ArraySize(source); + if (!IsValidSize(count)) + { + return result; + } + + // + XBoxZone boxes[]; + bool isConverted = ToBox( + source, + boxes // + ); + if (!isConverted) + { + return result; + } + + // + int boxesCount = ArraySize(boxes); + + // + if (count != boxesCount) + { + return result; + } + + // + result = GetLowest(boxes); + + // + Clean(boxes); + + // + return result; +} + +template +int GetHighest( + T *&source[] // +) +{ + // + int result = -1; + + // + int count = ArraySize(source); + if (!IsValidSize(count)) + { + return result; + } + + // + XBoxZone boxes[]; + bool isConverted = ToBox( + source, + boxes // + ); + if (!isConverted) + { + return result; + } + + // + int boxesCount = ArraySize(boxes); + + // + if (count != boxesCount) + { + return result; + } + + // + result = GetHighest(boxes); + + // + Clean(boxes); + + // + return result; +} + +template +bool IsSame( + T *source, + T *dest // +) +{ + // + bool result = false; + + // + XBoxZone sourceBox; + result = ToBox( + sourceBox, + source // + ); + if (!result) + { + return result; + } + + // + XBoxZone destBox; + result = ToBox( + destBox, + dest // + ); + if (!result) + { + return result; + } + + // + result = sourceBox.IsSameAs(destBox); + + // + return result; +} + +template +bool IsSameDiff( + T *source, + F *dest // +) +{ + // + bool result = false; + + // + XBoxZone sourceBox; + result = ToBox( + sourceBox, + source // + ); + if (!result) + { + return result; + } + + // + XBoxZone destBox; + result = ToBox( + destBox, + dest // + ); + if (!result) + { + return result; + } + + // + result = sourceBox.IsSame(destBox); + + // + return result; +} + +template +bool IsBelow( + T *source, + T *dest, + bool ignoreInside = false // +) +{ + // + bool result = false; + + // + XBoxZone sourceBox; + result = ToBox( + sourceBox, + source // + ); + if (!result) + { + return result; + } + + // + XBoxZone destBox; + result = ToBox( + destBox, + dest // + ); + if (!result) + { + return result; + } + + // + result = IsBoxBelow( + sourceBox, + destBox, + ignoreInside // + ); + + // + return result; +} + +template +bool IsBelowDiff( + T *source, + F *dest, + bool ignoreInside = false // +) +{ + // + bool result = false; + + // + XBoxZone sourceBox; + result = ToBox( + sourceBox, + source // + ); + if (!result) + { + return result; + } + + // + XBoxZone destBox; + result = ToBox( + destBox, + dest // + ); + if (!result) + { + return result; + } + + // + result = IsBoxBelow( + sourceBox, + destBox, + ignoreInside // + ); + + // + return result; +} + +template +bool IsAbove( + T *source, + T *dest, + bool ignoreInside = false // +) +{ + // + bool result = false; + + // + XBoxZone sourceBox; + result = ToBox( + sourceBox, + source // + ); + if (!result) + { + return result; + } + + // + XBoxZone destBox; + result = ToBox( + destBox, + dest // + ); + if (!result) + { + return result; + } + + // + result = IsBoxAbove( + sourceBox, + destBox, + ignoreInside // + ); + + // + return result; +} + +template +bool IsAboveDiff( + T *source, + F *dest, + bool ignoreInside = false // +) +{ + // + bool result = false; + + // + XBoxZone sourceBox; + result = ToBox( + sourceBox, + source // + ); + if (!result) + { + return result; + } + + // + XBoxZone destBox; + result = ToBox( + destBox, + dest // + ); + if (!result) + { + return result; + } + + // + result = IsBoxAbove( + sourceBox, + destBox, + ignoreInside // + ); + + // + return result; +} + +template +bool IsInside( + T *source, + T *dest // +) +{ + // + bool result = false; + + // + XBoxZone sourceBox; + result = ToBox( + sourceBox, + source // + ); + if (!result) + { + return result; + } + + // + XBoxZone destBox; + result = ToBox( + destBox, + dest // + ); + if (!result) + { + return result; + } + + // + result = IsBoxInside( + sourceBox, + destBox // + ); + + // + return result; +} + +template +bool IsInsideOr( + T *source, + T *dest // +) +{ + // + bool result = false; + + // + XBoxZone sourceBox; + result = ToBox( + sourceBox, + source // + ); + if (!result) + { + return result; + } + + // + XBoxZone destBox; + result = ToBox( + destBox, + dest // + ); + if (!result) + { + return result; + } + + // + result = IsBoxInsideOr( + sourceBox, + destBox // + ); + + // + return result; +} + +template +bool IsInsideDiff( + T *source, + F *dest, + bool forceSideOut = false // +) +{ + // + bool result = false; + + // + XBoxZone sourceBox; + result = ToBox( + sourceBox, + source // + ); + if (!result) + { + return result; + } + + // + XBoxZone destBox; + result = ToBox( + destBox, + dest // + ); + if (!result) + { + return result; + } + + // + result = IsBoxInside( + sourceBox, + destBox, + forceSideOut // + ); + + // + return result; +} + +template +bool IsInsideOrDiff( + T *source, + F *dest, + bool forceSideOut = false // +) +{ + // + bool result = false; + + // + XBoxZone sourceBox; + result = ToBox( + sourceBox, + source // + ); + if (!result) + { + return result; + } + + // + XBoxZone destBox; + result = ToBox( + destBox, + dest // + ); + if (!result) + { + return result; + } + + // + result = IsBoxInsideOr( + sourceBox, + destBox // + ); + + // + return result; +} + +template +bool FindIndex( + int &index, + T *item, + T *&items[] // +) +{ + // + bool result = false; + + // + index = -1; + + // + XBoxZone itemBox; + result = ToBox( + itemBox, + item // + ); + if (!result) + { + return result; + } + + // + XBoxZone itemsBox[]; + result = ToBox( + items, + itemsBox // + ); + if (!result) + { + return result; + } + + // + result = FindBoxIndex( + index, + itemBox, + itemsBox // + ); + + // + return result; +} + +template +bool IsInside( + double value, + T *source // +) +{ + // + bool result = false; + + // + XBoxZone sourceBox; + result = ToBox( + sourceBox, + source // + ); + if (!result) + { + return result; + } + + // + result = IsInsideBox( + value, + sourceBox // + ); + + // + return result; +} + +template +bool IsAbove( + double value, + T *source // +) +{ + // + bool result = false; + + // + XBoxZone sourceBox; + result = ToBox( + sourceBox, + source // + ); + if (!result) + { + return result; + } + + // + result = IsAboveBox( + value, + sourceBox // + ); + + // + return result; +} + +template +bool IsBelow( + double value, + T *source // +) +{ + // + bool result = false; + + // + XBoxZone sourceBox; + result = ToBox( + sourceBox, + source // + ); + if (!result) + { + return result; + } + + // + result = IsBelowBox( + value, + sourceBox // + ); + + // + return result; +} + +/** + * Find Specified Box Index inside a Collection of Boxes ... + * + * @param box: XBoxZone instance Reference ... + * @param boxes: XBoxZone instance Reference Collection ... + * + * @return ( int ) + */ +bool FindBoxIndex( + int &index, + XBoxZone &box, + XBoxZone &boxes[] // +) +{ + // + bool result = false; + + // + index = -1; + + // + int count = ArraySize(boxes); + result = box.IsValid() && + IsValidSize(count); + if (!result) + { + return result; + } + + // + for (int i = 0; i < count; i++) + { + // + XBoxZone iBox = boxes[i]; + + // + bool isSame = box.IsSameAs(iBox); + if (isSame) + { + // + index = i; + break; + } + } + + // + result = IsValidIndex(index); + + // + return result; +} + +/** + * Check a BaxHas Valid Place for Specified Bar ... + * + * @param bar: XOHCL instance reference, Specified Bar ... + * #param box: XBoxZone instance reference, Specified Box ... + * + * @return ( bool ) + */ +bool IsBoxPlaceValidForBar( + XOHCL &bar, + XBoxZone &box // +) +{ + // + bool result = false; + + // + result = bar.IsValid() && + box.IsValid(); + if (!result) + { + return result; + } + + // + result = + box.IsBullish() + ? bar.low > box.upper + : bar.high < box.upper; + + // + return result; +} + +/** + * Check Source Box is Below Dest ... + * + * @param source: XBoxZone instance Reference ... + * @param dest: XBoxZone instance Reference ... + * @param ignoreInside: bool ... + * + * @return ( bool ) + */ +bool IsBoxBelow( + XBoxZone &source, + XBoxZone &dest, + bool ignoreInside = false // +) +{ + // + bool result = false; + + // + result = source.IsValid() && + dest.IsValid() && + !source.IsSameAs(dest); + if (!result) + { + return result; + } + + // + if (!ignoreInside) + { + result = source.upper < dest.lower; + } + else + { + result = (source.upper < dest.lower || + source.upper >= dest.upper) && + source.lower < dest.lower; + } + + // + return result; +} + +/** + * Check Source Box is Above Dest ... + * + * @param source: XBoxZone instance Reference ... + * @param dest: XBoxZone instance Reference ... + * @param ignoreInside: bool ... + * + * @return ( bool ) + */ +bool IsBoxAbove( + XBoxZone &source, + XBoxZone &dest, + bool ignoreInside = false // +) +{ + // + bool result = false; + + // + result = source.IsValid() && + dest.IsValid() && + !source.IsSameAs(dest); + if (!result) + { + return result; + } + + // + if (!ignoreInside) + { + result = source.lower > dest.upper; + } + else + { + result = (source.lower > dest.upper || + source.lower <= dest.upper) && + source.upper > dest.upper; + } + + // + return result; +} + +/** + * Check Source Box is Inside Dest ... + * + * @param source: XBoxZone instance Reference ... + * @param dest: XBoxZone instance Reference ... + * @param forceSideOut: bool, force check Box has One Side Out ... + * @param ignoreSideOut: bool, Accept if source Box one Side is out of Dest Box ... + * + * @return ( bool ) + */ +bool IsBoxInside( + XBoxZone &source, + XBoxZone &dest, + bool forceSideOut = false, // + bool ignoreSideOut = true // +) +{ + // + bool result = false; + + // + result = source.IsValid() && + dest.IsValid() && + !source.IsSameAs(dest); + if (!result) + { + return result; + } + + // + bool isBullish = IsBullish(dest.dir); + + // + if (!forceSideOut) + { + // + if (ignoreSideOut) + { + // + result = source.lower >= dest.lower && + source.upper <= dest.upper; + } + else + { + result = source.lower >= dest.lower || + source.upper <= dest.upper; + } + } + else + { + // + bool hasSideIn = + isBullish + ? source.lower >= dest.lower + : source.upper <= dest.upper; + bool hasSideOut = + isBullish + ? source.upper >= dest.upper + : source.lower <= dest.lower; + result = + hasSideIn && + hasSideOut; + } + + // + return result; +} + +/** + * Detect source BoX is Inside Dest Box or Have a Side Out on it ... + * + * @param source: XBoxZone instance, source box which checks by dest ... + * @param dest: XBoxZone instance, dest Box which compares source with it ... + * + * @return ( bool ) + */ +bool IsBoxInsideOr( + XBoxZone &source, + XBoxZone &dest, + bool forceInside = false // +) +{ + // + bool result = false; + + // + result = source.IsValid() && + dest.IsValid() && + !source.IsSameAs(dest); + if (!result) + { + return result; + } + + // + bool isInside = + source.upper <= dest.upper && + source.upper >= dest.lower && + source.lower >= dest.lower && + source.lower <= dest.upper; + bool isUpperInside = + source.upper <= dest.upper && + source.upper >= dest.lower; + bool isLowerInside = + source.lower >= dest.lower && + source.lower <= dest.upper; + + // + result = + forceInside + ? isInside + : (isInside || + isLowerInside || + isUpperInside); + + // + return result; +} + +/** + * Check Value is Inside Specified Box ... + * + * @param value: double ... + * @param box: XCBozZone instance Reference ... + * + * @return ( bool ) + */ +bool IsInsideBox( + double value, + XBoxZone &box // +) +{ + // + bool result = false; + + // + result = value > 0 && + box.IsValid() && + value <= box.upper && + value >= box.lower; + + // + return result; +} + +/** + * Check Bar is Inside Specified Box ... + * + * @param bar: XOHCL instance reference, Specified Bar ... + * @param box: XCBozZone instance Reference ... + * + * @return ( bool ) + */ +bool IsInsideBox( + XOHCL &bar, + XBoxZone &box // +) +{ + // + bool result = false; + + // + // Validate Args ... + result = bar.IsValid() && + box.IsValid(); + if (!result) + { + return result; + } + + // + result = + bar.close <= box.upper && + bar.close >= box.lower; + + // + return result; +} + +/** + * Check Value is Above Specified Box ... + * + * @param value: double ... + * @param box: XCBozZone instance Reference ... + * + * @return ( bool ) + */ +bool IsAboveBox( + double value, + XBoxZone &box // +) +{ + // + bool result = false; + + // + result = value > 0 && + box.IsValid() && + value > box.upper; + + // + return result; +} + +/** + * Check Value is Below Specified Box ... + * + * @param value: double ... + * @param box: XCBozZone instance Reference ... + * + * @return ( bool ) + */ +bool IsBelowBox( + double value, + XBoxZone &box // +) +{ + // + bool result = false; + + // + result = value > 0 && + box.IsValid() && + value < box.lower; + + // + return result; +} + +/** + * Check a Box is Used or not ... + * + * @param box: XBoxZone instance Reference ... + * @param fromIndex: int ... + * @param toIndex: int + * @param forPeriod: Specified Period ... + * + * @return ( bool ) + */ +bool IsBoxUsed( + XBoxZone &box, + int fromIndex, + int toIndex = 0, + ENUM_TIMEFRAMES forPeriod = NULL // +) +{ + // + bool result = false; + + // + if (toIndex < 0) + { + toIndex = 0; + } + + // + result = + // + box.IsValid() && + fromIndex > 0 && + fromIndex > toIndex + // + ; + if (!result) + { + return result; + } + + // + if (!IsValid(forPeriod)) + { + forPeriod = box.period; + } + + // + ENUM_X_DIRECTION forDir = box.dir; + bool isBullish = IsBullish(forDir); + + // + bool isTouched = false; + for (int i = fromIndex; i >= toIndex; i--) + { + // + XOHCL iBar; + bool isInited = iBar.Init( + box.symbol, + forPeriod, + i // + ); + + // + isTouched = + isInited && + (isBullish + ? iBar.low > box.upper + : iBar.high < box.lower); + if (!isTouched) + { + continue; + } + + // + iBar.Clean(); + break; + } + + // + result = isTouched; + + // + return result; +} + +/** + * Validate Box ... + * + * @param box: XBoxZone instance ... + * @param barIndex: int, Current Bar Index ... + * @param forPeriod: Testing Period ... + * + * @return ( bool ) + */ +bool IsBoxValid( + XBoxZone &box, + int barIndex = 0, + ENUM_TIMEFRAMES forPeriod = NULL // +) +{ + // + bool result = false; + + // + result = box.IsValid(); + if (!result) + { + return result; + } + + // + if (barIndex < 0) + { + barIndex = 0; + } + + // + if (!IsValid(forPeriod)) + { + forPeriod = box.period; + } + + // + int toIndex = iBarShift( + box.symbol, + forPeriod, + box.to // + ); + result = IsValidIndex(toIndex); + if (!result) + { + return result; + } + + // + XOHCL iBar; + bool isBullish = box.IsBullish(); + for (int i = barIndex; i < toIndex; i++) + { + // + result = iBar.Init( + box.symbol, + forPeriod, + i // + ); + if (!result) + { + break; + } + + // + result = + isBullish + ? iBar.low > box.upper + : iBar.high < box.lower; + if (!result) + { + break; + } + + // + iBar.Clean(); + } + + // + iBar.Clean(); + + // + return result; +} + +/** + * Check Box Breaked ... + * + * @param box: XBoxZone instance ... + * @param barIndex: int, Current Bar Index ... + * @param forPeriod: Testing Period ... + * + * @return ( bool ) + */ +bool IsBoxBreaked( + XBoxZone &box, + int barIndex = 0, + ENUM_TIMEFRAMES forPeriod = NULL // +) +{ + // + bool result = false; + + // + result = box.IsValid(); + if (!result) + { + return result; + } + + // + if (barIndex < 0) + { + barIndex = 0; + } + + // + if (!IsValid(forPeriod)) + { + forPeriod = box.period; + } + + // + int toIndex = iBarShift( + box.symbol, + forPeriod, + box.to // + ); + result = IsValidIndex(toIndex); + if (!result) + { + return result; + } + + // + XOHCL iBar; + bool isBullish = box.IsBullish(); + for (int i = barIndex; i < toIndex; i++) + { + // + result = iBar.Init( + box.symbol, + forPeriod, + i // + ); + if (!result) + { + break; + } + + // + result = + isBullish + ? iBar.high < box.lower + : iBar.low > box.upper; + if (!result) + { + break; + } + + // + iBar.Clean(); + } + + // + iBar.Clean(); + + // + return result; +} + +/** + * Check a Box is Breaked or not ... + * + * @param box: XBoxZone instance Reference ... + * @param fromIndex: int ... + * @param toIndex: int + * @param forPeriod: Specified Period ... + * + * @return ( bool ) + */ +bool IsBoxBreaked( + XBoxZone &box, + int fromIndex, + int toIndex = 0, + ENUM_TIMEFRAMES forPeriod = NULL // +) +{ + // + bool result = false; + + // + if (toIndex < 0) + { + toIndex = 0; + } + + // + result = + // + box.IsValid() && + fromIndex > 0 && + fromIndex > toIndex + // + ; + if (!result) + { + return result; + } + + // + if (!IsValid(forPeriod)) + { + forPeriod = box.period; + } + + // + ENUM_X_DIRECTION forDir = box.dir; + bool isBullish = IsBullish(forDir); + + // + bool isBreaked = false; + for (int i = fromIndex; i >= toIndex; i--) + { + // + XOHCL iBar; + bool isInited = iBar.Init( + box.symbol, + forPeriod, + i // + ); + + // + isBreaked = + isInited && + (isBullish + ? iBar.high <= box.lower + : iBar.low >= box.upper); + if (!isBreaked) + { + continue; + } + + // + iBar.Clean(); + break; + } + + // + result = isBreaked; + + // + return result; +} + +/** + * Find an Inside Box of source in a Collection ... + * + * @param index: int, Founded Index ... + * @param source: XBoxZone instance ... + * @param dest: XBoxZone instance Collection ... + * + * @return ( bool ) + */ +bool HasInsideBox( + int &index, + XBoxZone &source, + XBoxZone &dest[] // +) +{ + // + bool result = false; + + // + index = -1; + + // + result = source.IsValid() && + HasChild(dest); + + // + int count = ArraySize(dest); + for (int i = 0; i < count; i++) + { + // + XBoxZone iBox = dest[i]; + + // + bool isInside = !iBox.IsSameAs(source) && + IsBoxInsideOr( + iBox, + source // + ); + if (isInside) + { + // + index = i; + iBox.Clean(); + + // + break; + } + + // + iBox.Clean(); + } + + // + result = IsValidIndex(index); + + // + return result; +} + +/** + * Remove Specified Box from Collection ... + */ +bool RemoveBox( + XBoxZone &box, + XBoxZone &boxes[] // +) +{ + // + bool result = false; + + // + result = + box.IsValid() && + HasChild(boxes); + if (!result) + { + return result; + } + + // + int idx = -1; + result = FindBoxIndex( + idx, + box, + boxes // + ); + if (!result) + { + return result; + } + + // + result = ArrayRemove( + boxes, + idx, + 1 // + ); + + // + return result; +} + +/** + * Converts to XBoxZone ... + * + * @return ( bool ) + */ +bool ToBox( + XBoxZone &box, + XCOrderBlock *item // +) +{ + // + bool result = false; + + // + box.Clean(); + + // + result = item != NULL && + item.IsValid(); + if (!result) + { + return result; + } + + // + box.to = item.To(); + box.from = item.From(); + box.upper = item.Upper(); + box.lower = item.Lower(); + box.symbol = item.GetSymbol(); + box.period = item.GetPeriod(); + box.type = item.TypeAsString(); + box.dir = item.IsBullish() + ? X_DIRECTION_BULLISH + : X_DIRECTION_BEARISH; + + // + result = box.IsValid(); + + // + return result; +} + +/** + * Converts to XBoxZone ... + * + * @return ( bool ) + */ +bool ToBox( + XBoxZone &box, + XCFVG *item // +) +{ + // + bool result = false; + + // + box.Clean(); + + // + result = item != NULL && + item.IsValid(); + if (!result) + { + return result; + } + + // + box.to = item.To(); + box.from = item.From(); + box.upper = item.Upper(); + box.lower = item.Lower(); + box.symbol = item.GetSymbol(); + box.period = item.GetPeriod(); + box.type = item.TypeAsString(); + box.dir = item.IsBullish() + ? X_DIRECTION_BULLISH + : X_DIRECTION_BEARISH; + + // + result = box.IsValid(); + + // + return result; +} + +/** + * Converts to XBoxZone ... + * + * @return ( bool ) + */ +bool ToBox( + XBoxZone &box, + XCSupportZone *item // +) +{ + // + bool result = false; + + // + box.Clean(); + + // + result = item != NULL && + item.IsValid(); + if (!result) + { + return result; + } + + // + box.to = item.To(); + box.from = item.From(); + box.upper = item.Upper(); + box.lower = item.Lower(); + box.symbol = item.GetSymbol(); + box.period = item.GetPeriod(); + box.type = item.TypeAsString(); + box.dir = X_DIRECTION_BULLISH; + + // + result = box.IsValid(); + + // + return result; +} + +/** + * Converts to XBoxZone ... + * + * @return ( bool ) + */ +bool ToBox( + XBoxZone &box, + XCResistanceZone *item // +) +{ + // + bool result = false; + + // + box.Clean(); + + // + result = item != NULL && + item.IsValid(); + if (!result) + { + return result; + } + + // + box.to = item.To(); + box.from = item.From(); + box.upper = item.Upper(); + box.lower = item.Lower(); + box.symbol = item.GetSymbol(); + box.period = item.GetPeriod(); + box.type = item.TypeAsString(); + box.dir = X_DIRECTION_BEARISH; + + // + result = box.IsValid(); + + // + return result; +} + +/** + * Converts to XBoxZone ... + * + * @return ( bool ) + */ +bool ToBox( + XBoxZone &box, + XCSupplyZone *item // +) +{ + // + bool result = false; + + // + box.Clean(); + + // + result = item != NULL && + item.IsValid(); + if (!result) + { + return result; + } + + // + box.to = item.To(); + box.from = item.From(); + box.upper = item.Upper(); + box.lower = item.Lower(); + box.symbol = item.GetSymbol(); + box.period = item.GetPeriod(); + box.type = item.TypeAsString(); + box.dir = X_DIRECTION_BEARISH; + + // + result = box.IsValid(); + + // + return result; +} + +/** + * Converts to XBoxZone ... + * + * @return ( bool ) + */ +bool ToBox( + XBoxZone &box, + XCDemandZone *item // +) +{ + // + bool result = false; + + // + box.Clean(); + + // + result = item != NULL && + item.IsValid(); + if (!result) + { + return result; + } + + // + box.to = item.To(); + box.from = item.From(); + box.upper = item.Upper(); + box.lower = item.Lower(); + box.symbol = item.GetSymbol(); + box.period = item.GetPeriod(); + box.type = item.TypeAsString(); + box.dir = X_DIRECTION_BULLISH; + + // + result = box.IsValid(); + + // + return result; +} + +/** + * Converts to XBoxZone ... + * + * @return ( bool ) + */ +bool ToBox( + XBoxZone &box, + XConsolidationZone &item // +) +{ + // + bool result = false; + + // + box.Clean(); + + // + result = item.IsValid(); + if (!result) + { + return result; + } + + // + box.to = item.to; + box.dir = item.dir; + box.from = item.from; + box.upper = item.upper; + box.lower = item.lower; + box.symbol = item.symbol; + box.period = item.period; + box.type = IsBullish(item.dir) + ? ToString(X_BULLISH_CONSOLIDATION_ZONE) + : ToString(X_BEARISH_CONSOLIDATION_ZONE); + + // + result = box.IsValid(); + + // + return result; +} + +/** + * Converts to XBoxZone ... + * + * @return ( bool ) + */ +int ToBox( + XConsolidationZone &source[], + XBoxZone &dest[] // +) +{ + // + int result = 0; + + // + Clean(dest); + int count = ArraySize(source); + if (!IsValidSize(count)) + { + return result; + } + + // + for (int i = 0; i < count; i++) + { + // + XConsolidationZone iZone = source[i]; + + // + XBoxZone iBox; + bool hasBox = ToBox( + iBox, + iZone // + ); + + // + if (hasBox) + { + // + AddRef( + iBox, + dest // + ); + } + + // + iBox.Clean(); + iZone.Clean(); + } + + // + result = ArraySize(dest); + + // + return result; +} + +/** + * Get Oldest Box Index ... + * + * @param source: XBoxZone instance Reference Collection ... + * + * @return ( int ) + */ +int GetOldest( + XBoxZone &source[] // +) +{ + // + int result = -1; + + // + int count = ArraySize(source); + if (!IsValidSize(count)) + { + return result; + } + + // + XBoxZone selected; + for (int i = 0; i < count; i++) + { + // + XBoxZone iBox = source[i]; + + // + bool canSet = + !selected.IsValid() + ? true + : selected.from > iBox.from; + if (canSet) + { + // + result = i; + selected = iBox; + } + + // + iBox.Clean(); + } + + // + selected.Clean(); + + // + return result; +} +int GetOldest( + XOHCL &bar, + XBoxZone &source[] // +) +{ + // + int result = -1; + + // + if (!bar.IsValid()) + { + return result; + } + + // + int count = ArraySize(source); + if (!IsValidSize(count)) + { + return result; + } + + // + XBoxZone selected; + for (int i = 0; i < count; i++) + { + // + XBoxZone iBox = source[i]; + + // + bool isBoxValidForBar = IsBoxPlaceValidForBar(bar, iBox); + if (!isBoxValidForBar) + { + // + iBox.Clean(); + + // + continue; + } + + // + bool canSet = + !selected.IsValid() + ? true + : selected.from > iBox.from; + if (canSet) + { + // + result = i; + selected = iBox; + } + + // + iBox.Clean(); + } + + // + selected.Clean(); + + // + return result; +} + +/** + * Get Youngest Box Index ... + * + * @param source: XBoxZone instance Reference Collection ... + * + * @return ( int ) + */ +int GetYoungest( + XBoxZone &source[] // +) +{ + // + int result = -1; + + // + int count = ArraySize(source); + if (!IsValidSize(count)) + { + return result; + } + + // + XBoxZone selected; + for (int i = 0; i < count; i++) + { + // + XBoxZone iBox = source[i]; + + // + bool canSet = + !selected.IsValid() + ? true + : selected.from < iBox.from; + if (canSet) + { + // + result = i; + selected = iBox; + } + + // + iBox.Clean(); + } + + // + selected.Clean(); + + // + return result; +} +int GetYoungest( + XOHCL &bar, + XBoxZone &source[] // +) +{ + // + int result = -1; + + // + if (!bar.IsValid()) + { + return result; + } + + // + int count = ArraySize(source); + if (!IsValidSize(count)) + { + return result; + } + + // + XBoxZone selected; + for (int i = 0; i < count; i++) + { + // + XBoxZone iBox = source[i]; + + // + bool isBoxValidForBar = IsBoxPlaceValidForBar(bar, iBox); + if (!isBoxValidForBar) + { + // + iBox.Clean(); + + // + continue; + } + + // + bool canSet = + !selected.IsValid() + ? true + : selected.from < iBox.from; + if (canSet) + { + // + result = i; + selected = iBox; + } + + // + iBox.Clean(); + } + + // + selected.Clean(); + + // + return result; +} + +/** + * Get Highest Box Index ... + * + * @param source: XBoxZone instance Reference Collection ... + * + * @return ( int ) + */ +int GetHighest( + XBoxZone &source[] // +) +{ + // + int result = -1; + + // + int count = ArraySize(source); + if (!IsValidSize(count)) + { + return result; + } + + // + XBoxZone selected; + for (int i = 0; i < count; i++) + { + // + XBoxZone iBox = source[i]; + + // + bool canSet = + !selected.IsValid() + ? true + : selected.upper < iBox.upper; + if (canSet) + { + // + result = i; + selected = iBox; + } + + // + iBox.Clean(); + } + + // + selected.Clean(); + + // + return result; +} +int GetHighest( + XOHCL &bar, + XBoxZone &source[] // +) +{ + // + int result = -1; + + // + if (!bar.IsValid()) + { + return result; + } + + // + int count = ArraySize(source); + if (!IsValidSize(count)) + { + return result; + } + + // + XBoxZone selected; + for (int i = 0; i < count; i++) + { + // + XBoxZone iBox = source[i]; + + // + bool isBoxValidForBar = IsBoxPlaceValidForBar(bar, iBox); + if (!isBoxValidForBar) + { + // + iBox.Clean(); + + // + continue; + } + + // + bool canSet = + !selected.IsValid() + ? true + : selected.upper < iBox.upper; + if (canSet) + { + // + result = i; + selected = iBox; + } + + // + iBox.Clean(); + } + + // + selected.Clean(); + + // + return result; +} + +/** + * Get Lowest Box Index ... + * + * @param source: XBoxZone instance Reference Collection ... + * + * @return ( int ) + */ +int GetLowest( + XBoxZone &source[] // +) +{ + // + int result = -1; + + // + int count = ArraySize(source); + if (!IsValidSize(count)) + { + return result; + } + + // + XBoxZone selected; + for (int i = 0; i < count; i++) + { + // + XBoxZone iBox = source[i]; + + // + bool canSet = + !selected.IsValid() + ? true + : selected.lower > iBox.lower; + if (canSet) + { + // + result = i; + selected = iBox; + } + + // + iBox.Clean(); + } + + // + selected.Clean(); + + // + return result; +} +int GetLowest( + XOHCL &bar, + XBoxZone &source[] // +) +{ + // + int result = -1; + + // + if (!bar.IsValid()) + { + return result; + } + + // + int count = ArraySize(source); + if (!IsValidSize(count)) + { + return result; + } + + // + XBoxZone selected; + for (int i = 0; i < count; i++) + { + // + XBoxZone iBox = source[i]; + + // + bool isBoxValidForBar = IsBoxPlaceValidForBar(bar, iBox); + if (!isBoxValidForBar) + { + // + iBox.Clean(); + + // + continue; + } + + // + bool canSet = + !selected.IsValid() + ? true + : selected.lower > iBox.lower; + if (canSet) + { + // + result = i; + selected = iBox; + } + + // + iBox.Clean(); + } + + // + selected.Clean(); + + // + return result; +} + +// +// +// + +/** + * Get Oldest Index ... + * + * @param source: XConsolidationZone instance Reference Collection ... + * + * @return ( int ) + */ +int GetOldest( + XConsolidationZone &source[] // +) +{ + // + int result = -1; + + // + int count = ArraySize(source); + if (!IsValidSize(count)) + { + return result; + } + + // + XBoxZone tmpBoxes[]; + int boxesCount = ToBox( + source, + tmpBoxes // + ); + if (!IsValidSize(boxesCount)) + { + // + Clean(tmpBoxes); + return result; + } + + // + XBoxZone selected; + for (int i = 0; i < boxesCount; i++) + { + // + XBoxZone iBox = tmpBoxes[i]; + + // + bool canSet = + !selected.IsValid() + ? true + : selected.from > iBox.from; + if (canSet) + { + // + result = i; + selected = iBox; + } + } + + // + Clean(tmpBoxes); + selected.Clean(); + + // + return result; +} + +/** + * Get Youngest Index ... + * + * @param source: XConsolidationZone instance Reference Collection ... + * + * @return ( int ) + */ +int GetYoungest( + XConsolidationZone &source[] // +) +{ + // + int result = -1; + + // + int count = ArraySize(source); + if (!IsValidSize(count)) + { + return result; + } + + // + XBoxZone tmpBoxes[]; + int boxesCount = ToBox( + source, + tmpBoxes // + ); + if (!IsValidSize(boxesCount)) + { + // + Clean(tmpBoxes); + return result; + } + + // + XBoxZone selected; + for (int i = 0; i < boxesCount; i++) + { + // + XBoxZone iBox = tmpBoxes[i]; + + // + bool canSet = + !selected.IsValid() + ? true + : selected.from < iBox.from; + if (canSet) + { + // + result = i; + selected = iBox; + } + } + + // + Clean(tmpBoxes); + selected.Clean(); + + // + return result; +} + +/** + * Get Highest Index ... + * + * @param source: XConsolidationZone instance Reference Collection ... + * + * @return ( int ) + */ +int GetHighest( + XConsolidationZone &source[] // +) +{ + // + int result = -1; + + // + int count = ArraySize(source); + if (!IsValidSize(count)) + { + return result; + } + + // + XBoxZone tmpBoxes[]; + int boxesCount = ToBox( + source, + tmpBoxes // + ); + if (!IsValidSize(boxesCount)) + { + // + Clean(tmpBoxes); + return result; + } + + // + XBoxZone selected; + for (int i = 0; i < boxesCount; i++) + { + // + XBoxZone iBox = tmpBoxes[i]; + + // + bool canSet = + !selected.IsValid() + ? true + : selected.upper < iBox.upper; + if (canSet) + { + // + result = i; + selected = iBox; + } + } + + // + Clean(tmpBoxes); + selected.Clean(); + + // + return result; +} + +/** + * Get Lowest Index ... + * + * @param source: XConsolidationZone instance Reference Collection ... + * + * @return ( int ) + */ +int GetLowest( + XConsolidationZone &source[] // +) +{ + // + int result = -1; + + // + int count = ArraySize(source); + if (!IsValidSize(count)) + { + return result; + } + + // + XBoxZone tmpBoxes[]; + int boxesCount = ToBox( + source, + tmpBoxes // + ); + if (!IsValidSize(boxesCount)) + { + // + Clean(tmpBoxes); + return result; + } + + // + XBoxZone selected; + for (int i = 0; i < boxesCount; i++) + { + // + XBoxZone iBox = tmpBoxes[i]; + + // + bool canSet = + !selected.IsValid() + ? true + : selected.lower > iBox.lower; + if (canSet) + { + // + result = i; + selected = iBox; + } + } + + // + Clean(tmpBoxes); + selected.Clean(); + + // + return result; +} + +// +// +// + +// +template +void SortZones( + T *&source[], + ENUM_X_DIRECTION forDir, + bool ignoreInside = true // +) +{ + // + int idx = -1; + int count = 0; + bool has = false; + + // + has = HasDirection(forDir); + if (!has) + { + return; + } + + // + bool isBullish = IsBullish(forDir); + + // + count = ArraySize(source); + has = IsValidSize(count); + if (!has) + { + return; + } + + // + T *tmpItems[]; + T *last = NULL; + bool hasLast = false; + while (HasChild(source)) + { + // + if (!hasLast) + { + // + idx = GetOldest(source); + hasLast = IsValidIndex(idx); + if (hasLast) + { + // + last = source[idx]; + ArrayRemove( + source, + idx, + 1 // + ); + + // + Add( + last, + tmpItems // + ); + } + + // + count = ArraySize(source); + has = IsValidSize(count); + if (!has) + { + // + ZeroMemory(last); + break; + } + } + if (!hasLast) + { + // + ZeroMemory(last); + break; + } + + // + T *item = NULL; + idx = GetOldest(source); + has = IsValidIndex(idx); + if (!has) + { + // + ZeroMemory(last); + ZeroMemory(item); + break; + } + item = source[idx]; + ArrayRemove( + source, + idx, + 1 // + ); + + // + bool isAbove = IsAbove( + item, + last, + ignoreInside // + ); + + // + bool isBelow = IsBelow( + item, + last, + ignoreInside // + ); + + // + has = + isBullish + ? isAbove + : isBelow; + if (has) + { + // + Add( + item, + tmpItems // + ); + + // + last = item; + hasLast = item != NULL; + } + } + + // + Clean(source); + Copy( + tmpItems, + source // + ); + + // + Clean(tmpItems); +} + +/** + * Extract all Zones Which provided bar is Inside it ... + * + * @return ( int ) + */ +template +int ExtractInsideZones( + XOHCL &bar, // Bar ... + T *&zones[], // Source of Zones ... + T *&dest[] // Dest (all inside Zones) ... +) +{ + // + int result = 0; + + // + Clean(dest); + + // + int count = ArraySize(zones); + bool isValid = bar.IsValid() && + IsValidSize(count); + if (!isValid) + { + return result; + } + + // + for (int i = 0; i < count; i++) + { + // + T *iZone = zones[i]; + + // + bool isHighInside = IsInside( + bar.high, + iZone // + ); + + // + bool isLowInside = IsInside( + bar.low, + iZone // + ); + + // + bool isInside = + isLowInside && + isHighInside; + + // + if (isInside) + { + // + Add( + iZone, + dest // + ); + } + + // + ZeroMemory(iZone); + } + + // + result = ArraySize(dest); + + // + return result; +} + +/** + * Add Specific Item into a Collection Reference only if it's not Exists ... + * + * @return ( bool ) + */ +template +bool AddIfNotExists( + T *item, + T *&items[] // +) +{ + // + bool result = false; + + // + result = item != NULL; + if (!result) + { + return result; + } + + // + int before = ArraySize(items); + + // + int idx = FindIndex( + item, + items // + ); + bool has = IsValidIndex(idx); + result = !has; + if (!result) + { + return result; + } + + // + Add( + item, + items // + ); + + // + int after = ArraySize(items); + + // + result = after > before; + + // + return result; +} +bool AddIfNotExists( + XConsolidationZone &item, + XConsolidationZone &items[] // +) +{ + // + bool result = false; + + // + result = item.IsValid(); + if (!result) + { + return result; + } + + // + int before = ArraySize(items); + + // + int idx = FindIndex( + item, + items // + ); + bool has = IsValidIndex(idx); + result = !has; + if (!result) + { + return result; + } + + // + AddRef( + item, + items // + ); + + // + int after = ArraySize(items); + + // + result = after > before; + + // + return result; +} + +/** + * Add items Collection reference Members into source Collection only if it's not Exists ...alignas + * @return ( int ) + */ +template +int AddIfNotExists( + T *&items[], + T *&sources[] // +) +{ + // + int result = 0; + + // + bool has = HasChild(items); + if (!has) + { + return result; + } + + // + int before = ArraySize(sources); + + // + int count = ArraySize(items); + for (int i = 0; i < count; i++) + { + // + has = AddIfNotExists( + items[i], + sources // + ); + } + + // + int after = ArraySize(sources); + + // + result = after > before; + + // + return result; +} +int AddIfNotExists( + XConsolidationZone &items[], + XConsolidationZone &sources[] // +) +{ + // + int result = 0; + + // + bool has = HasChild(items); + if (!has) + { + return result; + } + + // + int before = ArraySize(sources); + + // + int count = ArraySize(items); + for (int i = 0; i < count; i++) + { + // + has = AddIfNotExists( + items[i], + sources // + ); + } + + // + int after = ArraySize(sources); + + // + result = after > before; + + // + return result; +} + +/** + * Update to Time of Specifiex Collection ... + * + * @param items: XOBFVG instance Collection ... + * @param value: datetime ... + */ +template +void SpecifiedUpdateTo( + T *&items[], + datetime value = NULL // +) +{ + // + value = NormalizeTime(value); + + // + int count = ArraySize(items); + bool has = HasChild(items); + if (!has) + { + return; + } + + // + for (int i = 0; i < count; i++) + { + items[i].To(value); + } +} + +// +template +int FilterZones( + // + T *&source[], + // + ENUM_X_DIRECTION forDir, + ENUM_TIMEFRAMES forPeriod = NULL, + datetime after = NULL, + // + // Start ... + ENUM_XZONE_STATE startState = XZONE_STATE_PASSED, + bool forceStartedBodyOut = false, + // + // Activation ... + ENUM_XZONE_STATE activeState = XZONE_STATE_FAILED, + bool forceActivatedBodyIn = false, + // + // Breaktion ... + ENUM_XZONE_STATE breakState = XZONE_STATE_FAILED, + bool forceBreakedBodyOut = false, + // + // Works ... + ENUM_XZONE_STATE workState = XZONE_STATE_FAILED, + bool forceWorkedBodyOut = false, + // + bool applySort = false, + // + bool ignoreInside = true + // +) +{ + // + int result = 0; + + // + int idx = -1; + int count = 0; + bool has = false; + + // + has = HasDirection(forDir); + if (!has) + { + return result; + } + + // + bool isBullish = IsBullish(forDir); + + // + count = ArraySize(source); + has = IsValidSize(count); + if (!has) + { + return result; + } + + // + T *tmpZones[]; + XOHCL passedBar; + bool isPassed = false; + for (int i = 0; i < count; i++) + { + // + T *iZone = source[i]; + + // + // Apply after Filter ... + isPassed = + !IsValid(after) + ? true + : iZone.From() >= after; + if (!isPassed) + { + // + ZeroMemory(iZone); + continue; + } + + // + // Check Started State ... + if (startState == XZONE_STATE_PASSED || + startState == XZONE_STATE_FAILED) + { + // + bool isBodyOut = false; + bool isStarted = iZone.IsStarted( + forDir, + passedBar, + isBodyOut, + forPeriod // + ); + + // + bool isPassed = + startState == XZONE_STATE_FAILED + ? !isStarted + : !forceStartedBodyOut + ? isStarted + : isStarted && + isBodyOut; + + // + passedBar.Clean(); + if (!isPassed) + { + continue; + } + } + + // + // Check Activation State ... + if (activeState == XZONE_STATE_PASSED || + activeState == XZONE_STATE_FAILED) + { + // + bool isBodyIn = false; + bool isActivated = iZone.IsActivated( + forDir, + passedBar, + isBodyIn, + forceStartedBodyOut, + forPeriod // + ); + + // + bool isPassed = + activeState == XZONE_STATE_FAILED + ? !isActivated + : !forceActivatedBodyIn + ? isActivated + : isActivated && + isBodyIn; + + // + passedBar.Clean(); + if (!isPassed) + { + continue; + } + } + + // + // Check Break State ... + if (breakState == XZONE_STATE_PASSED || + breakState == XZONE_STATE_FAILED) + { + // + bool isBodyOut = false; + bool isBreaked = iZone.IsBreaked( + forDir, + passedBar, + isBodyOut, + forceStartedBodyOut, + forPeriod // + ); + + // + bool isPassed = + breakState == XZONE_STATE_FAILED + ? !isBreaked + : !forceBreakedBodyOut + ? isBreaked + : isBreaked && + isBodyOut; + + // + passedBar.Clean(); + if (!isPassed) + { + continue; + } + } + + // + // Check Work State ... + if (workState == XZONE_STATE_PASSED || + workState == XZONE_STATE_FAILED) + { + // + bool ignoreActivation = activeState != XZONE_STATE_PASSED; + + // + bool isBodyOut = false; + bool isWorked = iZone.IsWorked( + forDir, + passedBar, + isBodyOut, + ignoreActivation, + forceStartedBodyOut, + forceActivatedBodyIn, + forPeriod // + ); + + // + bool isPassed = + workState == XZONE_STATE_FAILED + ? !isWorked + : !forceWorkedBodyOut + ? isWorked + : isWorked && + isBodyOut; + + // + passedBar.Clean(); + if (!isPassed) + { + continue; + } + } + + // + // Check Filtered Zone Doesn't Exists ... + has = FindIndex( + idx, + iZone, + tmpZones // + ); + if (has) + { + // + ZeroMemory(iZone); + passedBar.Clean(); + continue; + } + + // + Add( + iZone, + tmpZones // + ); + } + + // + Clean(source); + + // + has = HasChild(tmpZones); + if (!has) + { + // + Clean(tmpZones); + passedBar.Clean(); + return result; + } + + // + // Apply Sorting ... + if (applySort) + { + // + T *last = NULL; + bool hasLast = false; + while (HasChild(tmpZones)) + { + // + idx = GetYoungest(tmpZones); + hasLast = IsValidIndex(idx); + if (hasLast) + { + // + last = tmpZones[idx]; + ArrayRemove( + tmpZones, + idx, + 1 // + ); + + // + Add( + last, + source // + ); + } + + // + has = HasChild(tmpZones); + if (!has) + { + break; + } + + // + T *zone = NULL; + bool hasZone = false; + idx = GetYoungest(tmpZones); + hasZone = IsValidIndex(idx); + if (hasZone) + { + // + zone = tmpZones[idx]; + ArrayRemove( + tmpZones, + idx, + 1 // + ); + } + if (!hasZone) + { + // + ZeroMemory(zone); + continue; + } + + // + bool isAbove = IsAbove( + zone, + last, + ignoreInside // + ); + + // + bool isBelow = IsBelow( + zone, + last, + ignoreInside // + ); + + // + isPassed = + isBullish + ? isAbove + : isBelow; + if (!isPassed) + { + // + ZeroMemory(zone); + continue; + } + + // + Add( + zone, + source // + ); + } + } + else + { + // + Copy( + tmpZones, + source // + ); + } + + // + result = ArraySize(source); + + // + return result; +} + +// +// +// + +/** + * Detect Nearest Price Out of Specified Box ... + * + * @param box: XBoxZone instance Reference ... + * @param outSideBar: XOHCL instance Reference which Represents Out Side Bar if Exists ... + * @param forPeriod: ENUM_TIMEFRAMES member which provides time frame of Out Bar, if not Provides used box Period as Default ... + * @param forDir: ENUM_X_DIRECTION member which Specified outSide Direction, use Box Dir as Default ... + * @param forceBodyIn: bool value which Specifyed Body Breakes or not, Default is false ... + * @param barIndex: integer value which Specified Start Bar Index, Default is 0 ... + * + * @return ( bool ) + */ +bool DetectBoxNearestPriceOut( + XBoxZone &box, + XOHCL &outSideBar, + ENUM_TIMEFRAMES forPeriod = NULL, + ENUM_X_DIRECTION forDir = X_DIRECTION_NONE, + bool forceBodyIn = false, + int barIndex = 0 // +) +{ + // + bool result = false; + + // + outSideBar.Clean(); + + // + if (barIndex < 0) + { + barIndex = 0; + } + + // + result = box.IsValid(); + if (!result) + { + return result; + } + + // + if (!IsValid(forPeriod)) + { + forPeriod = box.period; + } + + // + if (!HasDirection(forDir)) + { + forDir = box.dir; + } + + // + bool isBullish = IsBullish(forDir); + + // + int fromIndex = iBarShift( + box.symbol, + forPeriod, + box.from // + ); + result = IsValidIndex(fromIndex); + if (!result) + { + return result; + } + + // + XOHCL iBar; + XOHCL iPBar; + bool has = false; + for (int i = barIndex; i < fromIndex; i++) + { + // + has = iBar.Init( + box.symbol, + forPeriod, + i // + ); + if (!has) + { + continue; + } + + // + has = iBar.GetPreviousBar(iPBar); + if (!has) + { + continue; + } + + // + bool isInsideFromLower = + iBar.high < box.lower && + iPBar.high > box.lower; + + // + bool isInsideFromUpper = + iBar.low > box.upper && + iPBar.low < box.upper; + + // + bool isInsideBodyFromLower = + iPBar.GetUp() > box.lower; + + // + bool isInsideBodyFromUpper = + iPBar.GetDown() < box.upper; + + // + result = + isBullish + ? (!forceBodyIn + ? isInsideFromLower + : isInsideFromLower && + isInsideBodyFromLower) + : (!forceBodyIn + ? isInsideFromUpper + : isInsideFromUpper && + isInsideBodyFromUpper); + if (result) + { + // + outSideBar = iBar; + break; + } + } + + // + iBar.Clean(); + iPBar.Clean(); + + // + return result; +} + +/** + * Count number of Box Retests ... + * + * @param box: XBoxZone instance Reference ... + * @param forDir: ENUM_X_DIRECTION member, Specified Retesting Direction ... + * @param forPeriod: ENUM_TIMEFRAMES member, Specified Retesting Period ... + * @param forceType: bool, Specified Retest Bar Direction is Same as Retesting Direction ... + * @param forcePressure: bool, Specified Retest Bar must Has Fibo Pressure or not ... + * + * @return ( int ) + */ +int CountBoxRetest( + XBoxZone &box, + ENUM_X_DIRECTION forDir = NULL, + ENUM_TIMEFRAMES forPeriod = NULL, + bool forceType = false, + bool forcePressure = false // +) +{ + // + int result = 0; + + // + if (!IsValid(forPeriod)) + { + forPeriod = box.period; + } + + // + if (!IsValid(forDir)) + { + forDir = box.dir; + } + + // + bool isValid = + box.IsValid() && + IsValid(forDir); + if (!isValid) + { + return result; + } + + // + int fromIDX = GetBarIndex( + box.symbol, + forPeriod, + box.from // + ); + + // + int toIDX = GetBarIndex( + box.symbol, + forPeriod, + box.to // + ); + + // + for (int i = fromIDX; i >= toIDX; i--) + { + // + // Initialize Indexed Bar ... + XOHCL iBar; + isValid = iBar.Init( + box.symbol, + forPeriod, + i // + ); + if (!isValid) + { + // + iBar.Clean(); + continue; + } + + // + bool isUpperBullishRejected = iBar.IsRejected( + box.upper, + X_DIRECTION_BULLISH, + forceType, + forcePressure // + ); + bool isUpperBearishRejected = iBar.IsRejected( + box.upper, + X_DIRECTION_BEARISH, + forceType, + forcePressure // + ); + + // + bool isLowerBullishRejected = iBar.IsRejected( + box.lower, + X_DIRECTION_BULLISH, + forceType, + forcePressure // + ); + bool isLowerBearishRejected = iBar.IsRejected( + box.lower, + X_DIRECTION_BEARISH, + forceType, + forcePressure // + ); + + // + if (forDir == X_DIRECTION_ALL || + forDir == X_DIRECTION_BULLISH) + { + // + if (isUpperBullishRejected || + isLowerBullishRejected) + { + result++; + } + } + + // + if (forDir == X_DIRECTION_ALL || + forDir == X_DIRECTION_BEARISH) + { + // + if (isUpperBearishRejected || + isLowerBearishRejected) + { + result++; + } + } + + // + iBar.Clean(); + } + + // + return result; +} + +// \ No newline at end of file diff --git a/Libraries/x-saherelm.x-poi.state.lib.mq5 b/Documents/BKP/x-saherelm.x-poi.state.lib.mq5 similarity index 100% rename from Libraries/x-saherelm.x-poi.state.lib.mq5 rename to Documents/BKP/x-saherelm.x-poi.state.lib.mq5 diff --git a/Libraries/x-saherelm.x-poi.extensions.lib.mq5 b/Libraries/x-saherelm.x-poi.extensions.lib.mq5 index 7f984fa4..6651461a 100644 --- a/Libraries/x-saherelm.x-poi.extensions.lib.mq5 +++ b/Libraries/x-saherelm.x-poi.extensions.lib.mq5 @@ -26,51 +26,6 @@ // // Extensions ... -template -bool ToZone( - T *&source[], - XCZone *&dest[] // -) -{ - // - bool result = false; - - // - Clean(dest); - - // - int count = ArraySize(source); - result = IsValidSize(count); - if (!result) - { - return result; - } - - // - for (int i = 0; i < count; i++) - { - // - T *item = source[i]; - - // - if (item != NULL) - { - // - Add( - (XCZone *)item, - dest // - ); - } - } - - // - int destCount = ArraySize(dest); - result = IsValidSize(destCount); - - // - return result; -} - template bool ToBox( T *&source[], @@ -345,44 +300,6 @@ bool IsSame( return result; } -template -bool IsSameDiff( - T *source, - F *dest // -) -{ - // - bool result = false; - - // - XBoxZone sourceBox; - result = ToBox( - sourceBox, - source // - ); - if (!result) - { - return result; - } - - // - XBoxZone destBox; - result = ToBox( - destBox, - dest // - ); - if (!result) - { - return result; - } - - // - result = sourceBox.IsSame(destBox); - - // - return result; -} - template bool IsBelow( T *source, @@ -426,49 +343,6 @@ bool IsBelow( return result; } -template -bool IsBelowDiff( - T *source, - F *dest, - bool ignoreInside = false // -) -{ - // - bool result = false; - - // - XBoxZone sourceBox; - result = ToBox( - sourceBox, - source // - ); - if (!result) - { - return result; - } - - // - XBoxZone destBox; - result = ToBox( - destBox, - dest // - ); - if (!result) - { - return result; - } - - // - result = IsBoxBelow( - sourceBox, - destBox, - ignoreInside // - ); - - // - return result; -} - template bool IsAbove( T *source, @@ -512,49 +386,6 @@ bool IsAbove( return result; } -template -bool IsAboveDiff( - T *source, - F *dest, - bool ignoreInside = false // -) -{ - // - bool result = false; - - // - XBoxZone sourceBox; - result = ToBox( - sourceBox, - source // - ); - if (!result) - { - return result; - } - - // - XBoxZone destBox; - result = ToBox( - destBox, - dest // - ); - if (!result) - { - return result; - } - - // - result = IsBoxAbove( - sourceBox, - destBox, - ignoreInside // - ); - - // - return result; -} - template bool IsInside( T *source, @@ -637,91 +468,6 @@ bool IsInsideOr( return result; } -template -bool IsInsideDiff( - T *source, - F *dest, - bool forceSideOut = false // -) -{ - // - bool result = false; - - // - XBoxZone sourceBox; - result = ToBox( - sourceBox, - source // - ); - if (!result) - { - return result; - } - - // - XBoxZone destBox; - result = ToBox( - destBox, - dest // - ); - if (!result) - { - return result; - } - - // - result = IsBoxInside( - sourceBox, - destBox, - forceSideOut // - ); - - // - return result; -} - -template -bool IsInsideOrDiff( - T *source, - F *dest, - bool forceSideOut = false // -) -{ - // - bool result = false; - - // - XBoxZone sourceBox; - result = ToBox( - sourceBox, - source // - ); - if (!result) - { - return result; - } - - // - XBoxZone destBox; - result = ToBox( - destBox, - dest // - ); - if (!result) - { - return result; - } - - // - result = IsBoxInsideOr( - sourceBox, - destBox // - ); - - // - return result; -} - template bool FindIndex( int &index, @@ -1701,354 +1447,6 @@ bool RemoveBox( return result; } -/** - * Converts to XBoxZone ... - * - * @return ( bool ) - */ -bool ToBox( - XBoxZone &box, - XCOrderBlock *item // -) -{ - // - bool result = false; - - // - box.Clean(); - - // - result = item != NULL && - item.IsValid(); - if (!result) - { - return result; - } - - // - box.to = item.To(); - box.from = item.From(); - box.upper = item.Upper(); - box.lower = item.Lower(); - box.symbol = item.GetSymbol(); - box.period = item.GetPeriod(); - box.type = item.TypeAsString(); - box.dir = item.IsBullish() - ? X_DIRECTION_BULLISH - : X_DIRECTION_BEARISH; - - // - result = box.IsValid(); - - // - return result; -} - -/** - * Converts to XBoxZone ... - * - * @return ( bool ) - */ -bool ToBox( - XBoxZone &box, - XCFVG *item // -) -{ - // - bool result = false; - - // - box.Clean(); - - // - result = item != NULL && - item.IsValid(); - if (!result) - { - return result; - } - - // - box.to = item.To(); - box.from = item.From(); - box.upper = item.Upper(); - box.lower = item.Lower(); - box.symbol = item.GetSymbol(); - box.period = item.GetPeriod(); - box.type = item.TypeAsString(); - box.dir = item.IsBullish() - ? X_DIRECTION_BULLISH - : X_DIRECTION_BEARISH; - - // - result = box.IsValid(); - - // - return result; -} - -/** - * Converts to XBoxZone ... - * - * @return ( bool ) - */ -bool ToBox( - XBoxZone &box, - XCSupportZone *item // -) -{ - // - bool result = false; - - // - box.Clean(); - - // - result = item != NULL && - item.IsValid(); - if (!result) - { - return result; - } - - // - box.to = item.To(); - box.from = item.From(); - box.upper = item.Upper(); - box.lower = item.Lower(); - box.symbol = item.GetSymbol(); - box.period = item.GetPeriod(); - box.type = item.TypeAsString(); - box.dir = X_DIRECTION_BULLISH; - - // - result = box.IsValid(); - - // - return result; -} - -/** - * Converts to XBoxZone ... - * - * @return ( bool ) - */ -bool ToBox( - XBoxZone &box, - XCResistanceZone *item // -) -{ - // - bool result = false; - - // - box.Clean(); - - // - result = item != NULL && - item.IsValid(); - if (!result) - { - return result; - } - - // - box.to = item.To(); - box.from = item.From(); - box.upper = item.Upper(); - box.lower = item.Lower(); - box.symbol = item.GetSymbol(); - box.period = item.GetPeriod(); - box.type = item.TypeAsString(); - box.dir = X_DIRECTION_BEARISH; - - // - result = box.IsValid(); - - // - return result; -} - -/** - * Converts to XBoxZone ... - * - * @return ( bool ) - */ -bool ToBox( - XBoxZone &box, - XCSupplyZone *item // -) -{ - // - bool result = false; - - // - box.Clean(); - - // - result = item != NULL && - item.IsValid(); - if (!result) - { - return result; - } - - // - box.to = item.To(); - box.from = item.From(); - box.upper = item.Upper(); - box.lower = item.Lower(); - box.symbol = item.GetSymbol(); - box.period = item.GetPeriod(); - box.type = item.TypeAsString(); - box.dir = X_DIRECTION_BEARISH; - - // - result = box.IsValid(); - - // - return result; -} - -/** - * Converts to XBoxZone ... - * - * @return ( bool ) - */ -bool ToBox( - XBoxZone &box, - XCDemandZone *item // -) -{ - // - bool result = false; - - // - box.Clean(); - - // - result = item != NULL && - item.IsValid(); - if (!result) - { - return result; - } - - // - box.to = item.To(); - box.from = item.From(); - box.upper = item.Upper(); - box.lower = item.Lower(); - box.symbol = item.GetSymbol(); - box.period = item.GetPeriod(); - box.type = item.TypeAsString(); - box.dir = X_DIRECTION_BULLISH; - - // - result = box.IsValid(); - - // - return result; -} - -/** - * Converts to XBoxZone ... - * - * @return ( bool ) - */ -bool ToBox( - XBoxZone &box, - XConsolidationZone &item // -) -{ - // - bool result = false; - - // - box.Clean(); - - // - result = item.IsValid(); - if (!result) - { - return result; - } - - // - box.to = item.to; - box.dir = item.dir; - box.from = item.from; - box.upper = item.upper; - box.lower = item.lower; - box.symbol = item.symbol; - box.period = item.period; - box.type = IsBullish(item.dir) - ? ToString(X_BULLISH_CONSOLIDATION_ZONE) - : ToString(X_BEARISH_CONSOLIDATION_ZONE); - - // - result = box.IsValid(); - - // - return result; -} - -/** - * Converts to XBoxZone ... - * - * @return ( bool ) - */ -int ToBox( - XConsolidationZone &source[], - XBoxZone &dest[] // -) -{ - // - int result = 0; - - // - Clean(dest); - int count = ArraySize(source); - if (!IsValidSize(count)) - { - return result; - } - - // - for (int i = 0; i < count; i++) - { - // - XConsolidationZone iZone = source[i]; - - // - XBoxZone iBox; - bool hasBox = ToBox( - iBox, - iZone // - ); - - // - if (hasBox) - { - // - AddRef( - iBox, - dest // - ); - } - - // - iBox.Clean(); - iZone.Clean(); - } - - // - result = ArraySize(dest); - - // - return result; -} - /** * Get Oldest Box Index ... * @@ -2497,257 +1895,6 @@ int GetLowest( return result; } -// -// -// - -/** - * Get Oldest Index ... - * - * @param source: XConsolidationZone instance Reference Collection ... - * - * @return ( int ) - */ -int GetOldest( - XConsolidationZone &source[] // -) -{ - // - int result = -1; - - // - int count = ArraySize(source); - if (!IsValidSize(count)) - { - return result; - } - - // - XBoxZone tmpBoxes[]; - int boxesCount = ToBox( - source, - tmpBoxes // - ); - if (!IsValidSize(boxesCount)) - { - // - Clean(tmpBoxes); - return result; - } - - // - XBoxZone selected; - for (int i = 0; i < boxesCount; i++) - { - // - XBoxZone iBox = tmpBoxes[i]; - - // - bool canSet = - !selected.IsValid() - ? true - : selected.from > iBox.from; - if (canSet) - { - // - result = i; - selected = iBox; - } - } - - // - Clean(tmpBoxes); - selected.Clean(); - - // - return result; -} - -/** - * Get Youngest Index ... - * - * @param source: XConsolidationZone instance Reference Collection ... - * - * @return ( int ) - */ -int GetYoungest( - XConsolidationZone &source[] // -) -{ - // - int result = -1; - - // - int count = ArraySize(source); - if (!IsValidSize(count)) - { - return result; - } - - // - XBoxZone tmpBoxes[]; - int boxesCount = ToBox( - source, - tmpBoxes // - ); - if (!IsValidSize(boxesCount)) - { - // - Clean(tmpBoxes); - return result; - } - - // - XBoxZone selected; - for (int i = 0; i < boxesCount; i++) - { - // - XBoxZone iBox = tmpBoxes[i]; - - // - bool canSet = - !selected.IsValid() - ? true - : selected.from < iBox.from; - if (canSet) - { - // - result = i; - selected = iBox; - } - } - - // - Clean(tmpBoxes); - selected.Clean(); - - // - return result; -} - -/** - * Get Highest Index ... - * - * @param source: XConsolidationZone instance Reference Collection ... - * - * @return ( int ) - */ -int GetHighest( - XConsolidationZone &source[] // -) -{ - // - int result = -1; - - // - int count = ArraySize(source); - if (!IsValidSize(count)) - { - return result; - } - - // - XBoxZone tmpBoxes[]; - int boxesCount = ToBox( - source, - tmpBoxes // - ); - if (!IsValidSize(boxesCount)) - { - // - Clean(tmpBoxes); - return result; - } - - // - XBoxZone selected; - for (int i = 0; i < boxesCount; i++) - { - // - XBoxZone iBox = tmpBoxes[i]; - - // - bool canSet = - !selected.IsValid() - ? true - : selected.upper < iBox.upper; - if (canSet) - { - // - result = i; - selected = iBox; - } - } - - // - Clean(tmpBoxes); - selected.Clean(); - - // - return result; -} - -/** - * Get Lowest Index ... - * - * @param source: XConsolidationZone instance Reference Collection ... - * - * @return ( int ) - */ -int GetLowest( - XConsolidationZone &source[] // -) -{ - // - int result = -1; - - // - int count = ArraySize(source); - if (!IsValidSize(count)) - { - return result; - } - - // - XBoxZone tmpBoxes[]; - int boxesCount = ToBox( - source, - tmpBoxes // - ); - if (!IsValidSize(boxesCount)) - { - // - Clean(tmpBoxes); - return result; - } - - // - XBoxZone selected; - for (int i = 0; i < boxesCount; i++) - { - // - XBoxZone iBox = tmpBoxes[i]; - - // - bool canSet = - !selected.IsValid() - ? true - : selected.lower > iBox.lower; - if (canSet) - { - // - result = i; - selected = iBox; - } - } - - // - Clean(tmpBoxes); - selected.Clean(); - - // - return result; -} // // @@ -3172,633 +2319,4 @@ void SpecifiedUpdateTo( } } -// -template -int FilterZones( - // - T *&source[], - // - ENUM_X_DIRECTION forDir, - ENUM_TIMEFRAMES forPeriod = NULL, - datetime after = NULL, - // - // Start ... - ENUM_XZONE_STATE startState = XZONE_STATE_PASSED, - bool forceStartedBodyOut = false, - // - // Activation ... - ENUM_XZONE_STATE activeState = XZONE_STATE_FAILED, - bool forceActivatedBodyIn = false, - // - // Breaktion ... - ENUM_XZONE_STATE breakState = XZONE_STATE_FAILED, - bool forceBreakedBodyOut = false, - // - // Works ... - ENUM_XZONE_STATE workState = XZONE_STATE_FAILED, - bool forceWorkedBodyOut = false, - // - bool applySort = false, - // - bool ignoreInside = true - // -) -{ - // - int result = 0; - - // - int idx = -1; - int count = 0; - bool has = false; - - // - has = HasDirection(forDir); - if (!has) - { - return result; - } - - // - bool isBullish = IsBullish(forDir); - - // - count = ArraySize(source); - has = IsValidSize(count); - if (!has) - { - return result; - } - - // - T *tmpZones[]; - XOHCL passedBar; - bool isPassed = false; - for (int i = 0; i < count; i++) - { - // - T *iZone = source[i]; - - // - // Apply after Filter ... - isPassed = - !IsValid(after) - ? true - : iZone.From() >= after; - if (!isPassed) - { - // - ZeroMemory(iZone); - continue; - } - - // - // Check Started State ... - if (startState == XZONE_STATE_PASSED || - startState == XZONE_STATE_FAILED) - { - // - bool isBodyOut = false; - bool isStarted = iZone.IsStarted( - forDir, - passedBar, - isBodyOut, - forPeriod // - ); - - // - bool isPassed = - startState == XZONE_STATE_FAILED - ? !isStarted - : !forceStartedBodyOut - ? isStarted - : isStarted && - isBodyOut; - - // - passedBar.Clean(); - if (!isPassed) - { - continue; - } - } - - // - // Check Activation State ... - if (activeState == XZONE_STATE_PASSED || - activeState == XZONE_STATE_FAILED) - { - // - bool isBodyIn = false; - bool isActivated = iZone.IsActivated( - forDir, - passedBar, - isBodyIn, - forceStartedBodyOut, - forPeriod // - ); - - // - bool isPassed = - activeState == XZONE_STATE_FAILED - ? !isActivated - : !forceActivatedBodyIn - ? isActivated - : isActivated && - isBodyIn; - - // - passedBar.Clean(); - if (!isPassed) - { - continue; - } - } - - // - // Check Break State ... - if (breakState == XZONE_STATE_PASSED || - breakState == XZONE_STATE_FAILED) - { - // - bool isBodyOut = false; - bool isBreaked = iZone.IsBreaked( - forDir, - passedBar, - isBodyOut, - forceStartedBodyOut, - forPeriod // - ); - - // - bool isPassed = - breakState == XZONE_STATE_FAILED - ? !isBreaked - : !forceBreakedBodyOut - ? isBreaked - : isBreaked && - isBodyOut; - - // - passedBar.Clean(); - if (!isPassed) - { - continue; - } - } - - // - // Check Work State ... - if (workState == XZONE_STATE_PASSED || - workState == XZONE_STATE_FAILED) - { - // - bool ignoreActivation = activeState != XZONE_STATE_PASSED; - - // - bool isBodyOut = false; - bool isWorked = iZone.IsWorked( - forDir, - passedBar, - isBodyOut, - ignoreActivation, - forceStartedBodyOut, - forceActivatedBodyIn, - forPeriod // - ); - - // - bool isPassed = - workState == XZONE_STATE_FAILED - ? !isWorked - : !forceWorkedBodyOut - ? isWorked - : isWorked && - isBodyOut; - - // - passedBar.Clean(); - if (!isPassed) - { - continue; - } - } - - // - // Check Filtered Zone Doesn't Exists ... - has = FindIndex( - idx, - iZone, - tmpZones // - ); - if (has) - { - // - ZeroMemory(iZone); - passedBar.Clean(); - continue; - } - - // - Add( - iZone, - tmpZones // - ); - } - - // - Clean(source); - - // - has = HasChild(tmpZones); - if (!has) - { - // - Clean(tmpZones); - passedBar.Clean(); - return result; - } - - // - // Apply Sorting ... - if (applySort) - { - // - T *last = NULL; - bool hasLast = false; - while (HasChild(tmpZones)) - { - // - idx = GetYoungest(tmpZones); - hasLast = IsValidIndex(idx); - if (hasLast) - { - // - last = tmpZones[idx]; - ArrayRemove( - tmpZones, - idx, - 1 // - ); - - // - Add( - last, - source // - ); - } - - // - has = HasChild(tmpZones); - if (!has) - { - break; - } - - // - T *zone = NULL; - bool hasZone = false; - idx = GetYoungest(tmpZones); - hasZone = IsValidIndex(idx); - if (hasZone) - { - // - zone = tmpZones[idx]; - ArrayRemove( - tmpZones, - idx, - 1 // - ); - } - if (!hasZone) - { - // - ZeroMemory(zone); - continue; - } - - // - bool isAbove = IsAbove( - zone, - last, - ignoreInside // - ); - - // - bool isBelow = IsBelow( - zone, - last, - ignoreInside // - ); - - // - isPassed = - isBullish - ? isAbove - : isBelow; - if (!isPassed) - { - // - ZeroMemory(zone); - continue; - } - - // - Add( - zone, - source // - ); - } - } - else - { - // - Copy( - tmpZones, - source // - ); - } - - // - result = ArraySize(source); - - // - return result; -} - -// -// -// - -/** - * Detect Nearest Price Out of Specified Box ... - * - * @param box: XBoxZone instance Reference ... - * @param outSideBar: XOHCL instance Reference which Represents Out Side Bar if Exists ... - * @param forPeriod: ENUM_TIMEFRAMES member which provides time frame of Out Bar, if not Provides used box Period as Default ... - * @param forDir: ENUM_X_DIRECTION member which Specified outSide Direction, use Box Dir as Default ... - * @param forceBodyIn: bool value which Specifyed Body Breakes or not, Default is false ... - * @param barIndex: integer value which Specified Start Bar Index, Default is 0 ... - * - * @return ( bool ) - */ -bool DetectBoxNearestPriceOut( - XBoxZone &box, - XOHCL &outSideBar, - ENUM_TIMEFRAMES forPeriod = NULL, - ENUM_X_DIRECTION forDir = X_DIRECTION_NONE, - bool forceBodyIn = false, - int barIndex = 0 // -) -{ - // - bool result = false; - - // - outSideBar.Clean(); - - // - if (barIndex < 0) - { - barIndex = 0; - } - - // - result = box.IsValid(); - if (!result) - { - return result; - } - - // - if (!IsValid(forPeriod)) - { - forPeriod = box.period; - } - - // - if (!HasDirection(forDir)) - { - forDir = box.dir; - } - - // - bool isBullish = IsBullish(forDir); - - // - int fromIndex = iBarShift( - box.symbol, - forPeriod, - box.from // - ); - result = IsValidIndex(fromIndex); - if (!result) - { - return result; - } - - // - XOHCL iBar; - XOHCL iPBar; - bool has = false; - for (int i = barIndex; i < fromIndex; i++) - { - // - has = iBar.Init( - box.symbol, - forPeriod, - i // - ); - if (!has) - { - continue; - } - - // - has = iBar.GetPreviousBar(iPBar); - if (!has) - { - continue; - } - - // - bool isInsideFromLower = - iBar.high < box.lower && - iPBar.high > box.lower; - - // - bool isInsideFromUpper = - iBar.low > box.upper && - iPBar.low < box.upper; - - // - bool isInsideBodyFromLower = - iPBar.GetUp() > box.lower; - - // - bool isInsideBodyFromUpper = - iPBar.GetDown() < box.upper; - - // - result = - isBullish - ? (!forceBodyIn - ? isInsideFromLower - : isInsideFromLower && - isInsideBodyFromLower) - : (!forceBodyIn - ? isInsideFromUpper - : isInsideFromUpper && - isInsideBodyFromUpper); - if (result) - { - // - outSideBar = iBar; - break; - } - } - - // - iBar.Clean(); - iPBar.Clean(); - - // - return result; -} - -/** - * Count number of Box Retests ... - * - * @param box: XBoxZone instance Reference ... - * @param forDir: ENUM_X_DIRECTION member, Specified Retesting Direction ... - * @param forPeriod: ENUM_TIMEFRAMES member, Specified Retesting Period ... - * @param forceType: bool, Specified Retest Bar Direction is Same as Retesting Direction ... - * @param forcePressure: bool, Specified Retest Bar must Has Fibo Pressure or not ... - * - * @return ( int ) - */ -int CountBoxRetest( - XBoxZone &box, - ENUM_X_DIRECTION forDir = NULL, - ENUM_TIMEFRAMES forPeriod = NULL, - bool forceType = false, - bool forcePressure = false // -) -{ - // - int result = 0; - - // - if (!IsValid(forPeriod)) - { - forPeriod = box.period; - } - - // - if (!IsValid(forDir)) - { - forDir = box.dir; - } - - // - bool isValid = - box.IsValid() && - IsValid(forDir); - if (!isValid) - { - return result; - } - - // - int fromIDX = GetBarIndex( - box.symbol, - forPeriod, - box.from // - ); - - // - int toIDX = GetBarIndex( - box.symbol, - forPeriod, - box.to // - ); - - // - for (int i = fromIDX; i >= toIDX; i--) - { - // - // Initialize Indexed Bar ... - XOHCL iBar; - isValid = iBar.Init( - box.symbol, - forPeriod, - i // - ); - if (!isValid) - { - // - iBar.Clean(); - continue; - } - - // - bool isUpperBullishRejected = iBar.IsRejected( - box.upper, - X_DIRECTION_BULLISH, - forceType, - forcePressure // - ); - bool isUpperBearishRejected = iBar.IsRejected( - box.upper, - X_DIRECTION_BEARISH, - forceType, - forcePressure // - ); - - // - bool isLowerBullishRejected = iBar.IsRejected( - box.lower, - X_DIRECTION_BULLISH, - forceType, - forcePressure // - ); - bool isLowerBearishRejected = iBar.IsRejected( - box.lower, - X_DIRECTION_BEARISH, - forceType, - forcePressure // - ); - - // - if (forDir == X_DIRECTION_ALL || - forDir == X_DIRECTION_BULLISH) - { - // - if (isUpperBullishRejected || - isLowerBullishRejected) - { - result++; - } - } - - // - if (forDir == X_DIRECTION_ALL || - forDir == X_DIRECTION_BEARISH) - { - // - if (isUpperBearishRejected || - isLowerBearishRejected) - { - result++; - } - } - - // - iBar.Clean(); - } - - // - return result; -} - // \ No newline at end of file diff --git a/Libraries/x-saherelm.x-poi.lib.mq5 b/Libraries/x-saherelm.x-poi.lib.mq5 index 207c81ae..35d90e79 100644 --- a/Libraries/x-saherelm.x-poi.lib.mq5 +++ b/Libraries/x-saherelm.x-poi.lib.mq5 @@ -27,5392 +27,6 @@ // // Definitions ... -// -// All Available POI(s) ... -enum ENUM_XPOIS -{ - // - X_POI_NONE, - // - X_POI_TICKS_ZONES, // Ticks Zone ... - // - // Trading Day ... - X_POI_TRADING_DAY, // Trading Day ... - // - // Market Session ... - X_POI_MARKET_SESSION, // Market Session ... - // - // Momentum Bar ... - X_POI_MOMENTUM_BAR, // Momentum Bar ... - // - // Rejection Bar ... - X_POI_REJECTION_BAR, // Rejection Bar ... - // - // Swings ... - X_POI_SWING_HIGH, // Simple Swing High ... - X_POI_SWING_LOW, // Simple Swing Low ... - // - // Support nad Resistance ... - X_POI_SUPPORT_ZONE, // Support Zone ... - X_POI_RESISTANCE_ZONE, // 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 ... - // - X_BULLISH_CONSOLIDATION_ZONE, - X_BEARISH_CONSOLIDATION_ZONE, - // - X_BULLISH_SHARP, - X_BEARISH_SHARP, - // - X_BULLISH_SPIKE, - X_BEARISH_SPIKE, - // - X_BULLISH_PULLBACK, - X_BEARISH_PULLBACK, -}; - -// -// Event Types ... -enum ENUM_XPOI_EVENTS -{ - // - X_POI_EVENT_NONE, - // - // Trading Days ... - X_TRADE_DAY_FIRST_BAR, // Trading Day First Bar ... - X_TRADE_DAY_LAST_BAR, // Trading Day Last Bar ... - // - // Session ... - X_SESSION_FIRST_BAR, // Session First Bar ... - X_SESSION_LAST_BAR, // Session Last Bar ... - // - // Momentum Bar ... - X_BULLISH_MOMENTUM_BAR_DETECTED, - X_BEARISH_MOMENTUM_BAR_DETECTED, - // - // Rejection Bar ... - X_BULLISH_REJECTION_BAR_DETECTED, - X_BEARISH_REJECTION_BAR_DETECTED, - // - // Swings ... - X_SWING_HIGH_DETECTED, - X_SWING_LOW_DETECTED, - // - // 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Ù‘ ... - X_BULLISH_CONSOLIDATION_ZONE_DETECTED, - X_BEARISH_CONSOLIDATION_ZONE_DETECTED, - X_BULLISH_SHARP_DETECTED, - X_BEARISH_SHARP_DETECTED, - X_BULLISH_SPIKE_DETECTED, - X_BEARISH_SPIKE_DETECTED, - X_BULLISH_PULLBACK_DETECTED, - X_BEARISH_PULLBACK_DETECTED, -}; - -// -enum ENUM_XZONE_STATE -{ - XZONE_STATE_NONE, - XZONE_STATE_PASSED, - XZONE_STATE_FAILED, - XZONE_STATE_IGNORED, -}; - -// -// Forext Sessions ... -enum ENUM_XSESSION -{ - X_TOKYO, - X_SYDNEY, - X_LONDON, - X_NEW_YORK, - X_FRANKFORT, -}; - -/** - * Converts ENUM_XPOI value to String Representation ... - * - * @param value: ENUM_XPOI member ... - * - * @return ( string ) - */ -string ToString(ENUM_XPOIS value) -{ - // - string result = NULL; - - // - switch (value) - { - // - case X_POI_TRADING_DAY: - result = "XTDAY"; - break; - - // - case X_POI_MARKET_SESSION: - result = "XMSESS"; - break; - - // - case X_POI_MOMENTUM_BAR: - result = "XMNTMB"; - break; - - // - case X_POI_REJECTION_BAR: - result = "XRJCTB"; - break; - - // - case X_POI_SWING_HIGH: - result = "XSPH"; - break; - - // - case X_POI_SWING_LOW: - result = "XSPL"; - break; - - // - case X_POI_SUPPORT_ZONE: - result = "XSUP"; - break; - - // - case X_POI_RESISTANCE_ZONE: - 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; - - // - case X_POI_TICKS_ZONES: - result = "XTKSZ"; - break; - - // - case X_BULLISH_CONSOLIDATION_ZONE: - result = "XBULLCZ"; - break; - - // - case X_BEARISH_CONSOLIDATION_ZONE: - result = "XBEARCZ"; - break; - - // - case X_BULLISH_SPIKE: - result = "XBULLSPK"; - break; - - // - case X_BEARISH_SPIKE: - result = "XBEARSPK"; - break; - } - - // - return result; -} - -/** - * Converts ENUM_XSESSION value to String Representation ... - * - * @param value: ENUM_XSESSION member ... - * - * @return ( string ) - */ -string ToString(ENUM_XSESSION value) -{ - // - string result = NULL; - - // - switch (value) - { - // - case X_SYDNEY: - result = "Sydney"; - break; - - // - case X_TOKYO: - result = "Tokyo"; - break; - - // - case X_FRANKFORT: - result = "FrankGurt"; - break; - - // - case X_LONDON: - result = "London"; - break; - - // - case X_NEW_YORK: - result = "NewYork"; - break; - } - - // - return result; -} - -/** - * Generate General Event Messages ... - * - * @param value: ENUM_XPOI_EVENTS member ... - * - * @return ( string ) - */ -string ToString(ENUM_XPOI_EVENTS value) -{ - // - string result = NULL; - - // - switch (value) - { - // - case X_TRADE_DAY_FIRST_BAR: - result = "First Bar of Day"; - break; - - // - case X_TRADE_DAY_LAST_BAR: - result = "Last Bar of Day"; - break; - - // - case X_SESSION_FIRST_BAR: - result = "First Bar of Session"; - break; - - // - case X_SESSION_LAST_BAR: - result = "Last Bar of Session"; - break; - - // - case X_BULLISH_MOMENTUM_BAR_DETECTED: - result = "Bullish Momentum Bar Detected"; - break; - - // - case X_BEARISH_MOMENTUM_BAR_DETECTED: - result = "Bearish Momentum Bar Detected"; - break; - - // - case X_BULLISH_REJECTION_BAR_DETECTED: - result = "Bullish Rejection Bar Detected"; - break; - - // - case X_BEARISH_REJECTION_BAR_DETECTED: - result = "Bearish Rejection Bar Detected"; - break; - - // - case X_SWING_HIGH_DETECTED: - result = "Swing High Detected"; - break; - - // - case X_SWING_LOW_DETECTED: - result = "Swing Low Detected"; - break; - - // - case X_SUPPORT_ZONE_DETECTED: - result = "Support Zone Detected"; - break; - - // - case X_RESISTANCE_ZONE_DETECTED: - result = "Resistance Zone Detected"; - break; - - // - case X_SUPPLY_ZONE_DETECTED: - result = "Supply Zone Detected"; - break; - - // - case X_DEMAND_ZONE_DETECTED: - result = "Demand Zone Detected"; - break; - - // - case X_BULLISH_ORDERBLOCK_DETECTED: - result = "Bullish Order Block Detected"; - break; - - // - case X_BEARISH_ORDERBLOCK_DETECTED: - result = "Bearish Orer Block Detected"; - break; - - // - case X_BULLISH_FVG_DETECTED: - result = "Bullish FVG Detected"; - break; - - // - case X_BEARISH_FVG_DETECTED: - result = "Bearish FVg Detected"; - break; - } - - // - return result; -} - -// -// Implementation ... - -// -// Base POI Model Class ... -class XCBasePOI : public XCBase -{ - // - public: - // - - // - // Constructor ... - void XCBasePOI() - { - // - Clean(); - - // - mSep = "_"; - mLineSep = "\n"; - } - - // - // Deconstructor ... - void ~XCBasePOI() - { - Clean(); - } - - // - // Virtual ... - - /** - * Cleanup ... - */ - virtual void Clean() - { - mType = X_POI_NONE; - } - - /** - * Validate ... - * - * @return ( virtual bool ) - */ - virtual bool IsValid() - { - return false; - } - - /** - * Retrieve POI Type ... - * - * @return ( virtual ENUM_XPOIS member ) - */ - virtual ENUM_XPOIS Type() - { - return mType; - } - - /** - * Retrieve POI Type ... - * - * @return ( virtual string ) - */ - virtual string TypeAsString() - { - return ToString(mType); - } - - /** - * Retrieve POI Tag ... - * - * @return ( virtual string ) - */ - virtual string GetTag() - { - return NULL; - } - - /** - * Retrieve POI Tooltip ... - * - * @return ( virtual string ) - */ - virtual string GetTooltip() - { - return NULL; - } - - // - protected: - // - // Props ... - string mSep; // Separator ... - string mLineSep; // Line Separator ... - ENUM_XPOIS mType; // Type ... - - // - private: - // -}; - -// -typedef void (*TOnPOIEvent)(ENUM_XPOI_EVENTS event, - XCBasePOI *param // -); - -// -// Zone POI Class ... -class XCZone : public XCBasePOI -{ - // - public: - // - - // - // Constructor ... - void XCZone() - { - } - - // - // Deconstructor ... - void ~XCZone() - { - } - - // - // Tools ... - - // - // Getter(s) / Setter(s) ... - - /** - * Get Zone Upper Boundary ... - * - * @return ( double ) - */ - double Upper() - { - return mUpper; - } - - /** - * Set Zone Upper Boundary ... - */ - void Upper(double value) - { - mUpper = value; - } - - /** - * Get Zone Lower Boundary ... - * - * @return ( double ) - */ - double Lower() - { - return mLower; - } - - /** - * Set Zone Lower Boundary ... - */ - void Lower(double value) - { - mLower = value; - } - - /** - * Retrieve Zone Range ... - * - * @return ( double ) - */ - double Range() - { - // - double result = 0; - - // - double upper = Upper(); - double lower = Lower(); - - // - if (upper > 0 && lower > 0 && upper > lower) - { - result = upper - lower; - } - - // - return result; - } - - double RangePercent() - { - // - double result = 0; - - // - double range = Range(); - if (range > 0) - { - result = range / 100; - } - - // - return result; - } - - // - // Virtuals ... - - /** - * Get Zone Start Date ... - * - * @return ( virtual datetime ) - */ - virtual datetime From() - { - return NULL; - } - - /** - * Get Zone End Date ... - * - * @return ( virtual datetime ) - */ - virtual datetime To() - { - return NULL; - } - - // - // Getter(s) / Setter(s) ... - - // - // Overrides ... - - // - // Validators ... - - /** - * Validate Upper and Lower of Zone ... - * - * @return ( bool ) - */ - bool IsValidBoundary() - { - // - bool result = false; - - // - result = - // - mUpper > 0 && - mLower > 0 && - mUpper >= mLower - // - ; - - // - return result; - } - - /** - * Check From Date of Zone is Valid ... - * - * @return ( bool ) - */ - bool IsValidFrom() - { - // - bool result = false; - - // - datetime from = From(); - result = IsSpecifiedValid(from); - - // - return result; - } - - // - protected: - // - // Props ... - double mUpper; // Zone Upper ... - double mLower; // Zone Lower ... - - // - private: - // - // Props ... - - // -}; - -// -// From To Zone ... -class XCFromToZone : public XCBasePOI -{ - // - public: - // - - // - // Constructor ... - void XCFromToZone() - { - } - - // - // Deconstructor ... - void ~XCFromToZone() - { - } - - // - // Tools ... - - bool InitFromTo( - ENUM_XPOIS type, - string title, - datetime from // - ) - { - // - bool result = false; - - // - result = type != X_POI_NONE && - IsSpecifiedValid(from) && - IsSpecifiedValid(title); - - // - mType = type; - mFrom = from; - mTitle = title; - mTo = TimeCurrent(); - - // - result = IsValid(); - - // - return result; - } - - bool InitFromTo( - ENUM_XPOIS type, - string title, - datetime from, - datetime to // - ) - { - // - bool result = false; - - // - result = IsValid(); - - // - result = InitFromTo( - type, - title, - from // - ); - if (!result) - { - return result; - } - - // - to = NormalizeTime(to); - mTo = to; - - // - result = IsValid(); - - // - return result; - } - - // - // Getter(s) / Setter(s) ... - - /** - * Get Zone Start Time ... - * - * @return ( datetime ) - */ - datetime From() - { - return mFrom; - } - - /** - * Set Zone Start Time ... - * - * @param value: Datetime - */ - void From(datetime value) - { - // - value = NormalizeTime(value); - - // - mFrom = value; - } - - /** - * Get Zone End Time ... - * - * @return ( datetime ) - */ - datetime To() - { - return mTo; - } - - /** - * Set Zone End Time ... - * - * @param value: Datetime - */ - void To(datetime value) - { - // - value = NormalizeTime(value); - - // - mTo = value; - } - - /** - * Get Title ... - * - * @return ( string ) - */ - string Title() - { - return mTitle; - } - - /** - * Set Title ... - * - * @param value: String ... - */ - // void Title(string value) - // { - // mTitle = value; - // } - - // - // Overrides ... - - void Clean() override - { - // - mTo = NULL; - mFrom = NULL; - mType = X_POI_NONE; - } - - bool IsValid() override - { - // - bool result = false; - - // - result = - // - mType != X_POI_NONE && - IsSpecifiedValid(mTo) && - IsSpecifiedValid(mFrom) && - IsSpecifiedValid(mTitle) - // - ; - - // - return result; - } - - string GetTag() override - { - // - string result = NULL; - - // - if (!IsValid()) - { - return result; - } - - // - string hash = TypeAsString() + mSep + ToString(From()) + mSep + Title(); - hash = ToMD5(hash); - - // - result = TypeAsString() + "[" + Title() + "]" + mSep + hash; - - // - return result; - } - - // - protected: - // - - // - private: - // - // Props ... - datetime mFrom; // Start Date - datetime mTo; // End Date - string mTitle; // Zone Title - - // -}; - -// -// Bar Zone ... -class XCBarZone : public XCZone -{ - // - public: - // - - // - // Constructor ... - void XCBarZone() - { - } - - // - // Deconstructor ... - void ~XCBarZone() - { - } - - // - // Tools ... - - /** - * Initialize POI ... - * - * @param bar: XOHCL instance ... - * @param type: ENUM_XPOIS member ... - * @param upperPrice: ENUM_X_PRICE member ... - * @param lowerPrice: ENUM_X_PRICE member ... - * - * @return ( bool ) - */ - bool InitBarZone( - XOHCL &bar, - ENUM_XPOIS type, - ENUM_X_PRICE upperPrice, - ENUM_X_PRICE lowerPrice // - ) - { - // - bool result = false; - - // - result = bar.IsValid() && - type != X_POI_NONE && - upperPrice != lowerPrice; - if (!result) - { - return result; - } - - // - mBar = bar; - mType = type; - mUpperPrice = upperPrice; - mLowerPrice = lowerPrice; - mUpper = bar.GetPrice(upperPrice); - mLower = bar.GetPrice(lowerPrice); - - // - result = IsValidBarZone(); - if (result) - { - // - From(bar.time); - To(TimeCurrent()); - } - - // - return result; - } - - // - // Getter(s) / Setter(s) ... - - /** - * Fill Bar as XOHCL struct ... - * - * @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; - } - - /** - * Set From Date ... - * - * @param value: DateTime ... - */ - void From(datetime value) - { - // - if (!IsValidBarZone()) - { - return; - } - - // - value = NormalizeTime(value); - - // - mFrom = value; - } - - /** - * Set To Date ... - * - * @param value: DateTime ... - */ - void To(datetime value) - { - // - if (!IsValidBarZone()) - { - return; - } - - // - value = NormalizeTime(value); - - // - mTo = value; - } - - /** - * Retrieve Bar Time ... - * - * @return ( datetime ) - */ - datetime BarTime() - { - return mBar.time; - } - - /** - * Get Symbol ... - * - * @return ( string ) - */ - string GetSymbol() - { - // - string result = NULL; - - // - if (!mBar.IsValid()) - { - return result; - } - - // - return mBar.symbol; - - // - return result; - } - - /** - * Get Period ... - * - * @return ( int ) - */ - ENUM_TIMEFRAMES GetPeriod() - { - // - ENUM_TIMEFRAMES result = NULL; - - // - if (!mBar.IsValid()) - { - return result; - } - - // - return mBar.period; - - // - return result; - } - - /** - * Check Zone Started or not ... - * First Exit in Direction of Zone after From ... - * - * @param forDir: exit direction ... - * @param startedBar: specified Start Bar ... - * @param isBodyOut: specified Start Bar Close is Out of Zone or not ... - * @param forPeriod: specified Period ... - * - * @return ( bool ) - */ - bool IsStarted( - ENUM_X_DIRECTION forDir, - XOHCL &startedBar, - bool &isBodyOut, - ENUM_TIMEFRAMES forPeriod = NULL // - ) - { - // - bool result = false; - - // - isBodyOut = false; - startedBar.Clean(); - - // - result = HasDirection(forDir) && - IsValidBarZone(); - if (!result) - { - return result; - } - - // - bool isBullish = IsBullish(forDir); - - // - if (!IsSpecifiedValid(forPeriod)) - { - forPeriod = GetPeriod(); - } - - // - // Detect From Bar Index ... - int fromIndex = iBarShift( - GetSymbol(), - forPeriod, - From() // - ); - - // - for (int i = fromIndex; i >= 0; i--) - { - // - XOHCL iBar; - bool isInited = iBar.Init( - GetSymbol(), - forPeriod, - i // - ); - result = isInited; - if (!result) - { - // - iBar.Clean(); - continue; - } - - // - bool isBreakedFromUpper = - // - iBar.low > Upper() || - (iBar.low <= Upper() && - iBar.high > Upper() && - iBar.close > Upper()) - // - ; - - // - bool isBreakedFromLower = - // - iBar.low < Lower() || - (iBar.high >= Lower() && - iBar.low < Lower() && - iBar.close < Lower()) - // - ; - - // - bool isBreaked = - isBreakedFromUpper || - isBreakedFromLower; - if (isBreaked) - { - // - result = isBreaked && - isBullish - ? isBreakedFromUpper - : isBreakedFromLower; - if (result) - { - // - startedBar = iBar; - iBar.Clean(); - break; - } - } - - // - iBar.Clean(); - } - - // - result = startedBar.IsValid(); - if (result) - { - // - isBodyOut = - isBullish - ? startedBar.IsBullish() && - startedBar.GetUp() > Upper() - : startedBar.IsBearish() && - startedBar.GetDown() < Lower(); - } - - // - return result; - } - - /** - * Check Zone Activated or not ... - * First Enter in Opposit Direction of Zone after Start ... - * - * @param forDir: exit direction ... - * @param activatedBar: specified Activation Bar ... - * @param isBodyIn: specified Activation Bar Close is Inside of Zone or not ... - * @param forPeriod: specified Period ... - * - * @return ( bool ) - */ - bool IsActivated( - ENUM_X_DIRECTION forDir, - XOHCL &activatedBar, - bool &isBodyIn, - bool forceBodyOutStarted = true, - ENUM_TIMEFRAMES forPeriod = NULL // - ) - { - // - bool result = false; - - // - isBodyIn = false; - activatedBar.Clean(); - - // - result = HasDirection(forDir) && - IsValidBarZone(); - if (!result) - { - return result; - } - - // - bool isBullish = IsBullish(forDir); - - // - if (!IsSpecifiedValid(forPeriod)) - { - forPeriod = GetPeriod(); - } - - // - XOHCL startedBar; - bool isBodyOut = false; - bool isStarted = IsStarted( - forDir, - startedBar, - isBodyOut, - forPeriod // - ); - result = - !forceBodyOutStarted - ? isStarted - : isStarted && - isBodyOut; - if (!result) - { - // - startedBar.Clean(); - return result; - } - - // - int fromIndex = startedBar.Index() - 1; - - // - for (int i = fromIndex; i >= 0; i--) - { - // - XOHCL iBar; - bool isInited = iBar.Init( - GetSymbol(), - forPeriod, - i // - ); - result = isInited; - if (!result) - { - // - iBar.Clean(); - continue; - } - - // - bool isInsideFromUpper = - // - iBar.high < Upper() || - (iBar.high > Upper() && - iBar.low <= Upper() && - iBar.close <= Upper()) - // - ; - - // - bool isInsideFromLower = - // - iBar.low > Lower() || - (iBar.low < Lower() && - iBar.high >= Lower() && - iBar.close >= Lower()) - // - ; - - // - bool isInside = - isInsideFromUpper || - isInsideFromLower; - if (isInside) - { - // - result = isInside && - isBullish - ? isInsideFromUpper - : isInsideFromLower; - if (result) - { - // - activatedBar = iBar; - iBar.Clean(); - startedBar.Clean(); - break; - } - } - - // - iBar.Clean(); - startedBar.Clean(); - } - - // - result = activatedBar.IsValid(); - if (result) - { - // - isBodyIn = - isBullish - ? activatedBar.IsBearish() && - activatedBar.GetDown() < Upper() - : activatedBar.IsBullish() && - activatedBar.GetUp() > Lower(); - } - - // - return result; - } - - /** - * Check Zone Breaked or not ... - * - * @param forDir: exit direction ... - * @param breakedBar: specified Breaked Bar ... - * @param isBodyOut: specified Breaked Bar Close is Out of Zone or not ... - * @param ignoreStart: Ignore Zone Start (Calculate from From()) ... - * @param startedBodyOut: Started Bar Body Close State, if use Start for Calculation ... - * @param forPeriod: specified Period ... - * - * @return ( bool ) - */ - bool IsBreaked( - ENUM_X_DIRECTION forDir, - XOHCL &breakedBar, - bool &isBodyOut, - bool ignoreStart = false, - bool startedBodyOut = false, - ENUM_TIMEFRAMES forPeriod = NULL // - ) - { - // - bool result = false; - - // - isBodyOut = false; - breakedBar.Clean(); - - // - result = HasDirection(forDir) && - IsValidBarZone(); - if (!result) - { - return result; - } - - // - bool isBullish = IsBullish(forDir); - - // - if (!IsSpecifiedValid(forPeriod)) - { - forPeriod = GetPeriod(); - } - - // - int fromIndex = -1; - if (!ignoreStart) - { - // - XOHCL startedBar; - bool isBodyOut = false; - bool isStarted = IsStarted( - forDir, - startedBar, - isBodyOut, - forPeriod // - ); - - // - bool isStartPassed = - !startedBodyOut - ? isStarted - : isStarted && - isBodyOut; - if (isStartPassed) - { - fromIndex = startedBar.Index() - 1; - } - - // - startedBar.Clean(); - } - else - { - // - fromIndex = iBarShift( - GetSymbol(), - forPeriod, - From() // - ); - } - - // - result = IsValidIndex(fromIndex); - if (!result) - { - return result; - } - - // - for (int i = fromIndex; i >= 0; i--) - { - // - XOHCL iBar; - bool isInited = iBar.Init( - GetSymbol(), - forPeriod, - i // - ); - result = isInited; - if (!result) - { - // - iBar.Clean(); - continue; - } - - // - bool isBreakedFromUpper = - // - iBar.low > Upper() || - (iBar.low <= Upper() && - iBar.high > Upper() && - iBar.close > Upper()) - // - ; - - // - bool isBreakedFromLower = - // - iBar.low < Lower() || - (iBar.high >= Lower() && - iBar.low < Lower() && - iBar.close < Lower()) - // - ; - - // - bool isBreaked = - isBreakedFromUpper || - isBreakedFromLower; - if (isBreaked) - { - // - result = isBreaked && - (isBullish - ? isBreakedFromLower - : isBreakedFromUpper); - if (result) - { - // - breakedBar = iBar; - iBar.Clean(); - break; - } - } - - // - iBar.Clean(); - } - - // - result = breakedBar.IsValid(); - if (result) - { - // - isBodyOut = - isBullish - ? breakedBar.IsBearish() && - breakedBar.GetDown() < Lower() - : breakedBar.IsBullish() && - breakedBar.GetUp() > Upper(); - } - - // - return result; - } - - /** - * Check Zone Worked or not ... - * - * @param forDir: exit direction ... - * @param workedBar: specified Worked Bar ... - * @param isBodyOut: specified Worked Bar Close is Out of Zone or not ... - * @param ignoreActivation: Ignore Zone Activation (Calculate from From()) ... - * @param activationStartedOut: Specified Zone Start Bar State ... - * @param activationBodyIn: Specified Zone Activation Bar State ... - * @param forPeriod: specified Period ... - * - * @return ( bool ) - */ - bool IsWorked( - ENUM_X_DIRECTION forDir, - XOHCL &workedBar, - bool &isBodyOut, - bool ignoreActivation = false, - bool activationStartedOut = false, - bool activationBodyIn = false, - ENUM_TIMEFRAMES forPeriod = NULL // - ) - { - // - bool result = false; - - // - isBodyOut = false; - workedBar.Clean(); - - // - result = HasDirection(forDir) && - IsValidBarZone(); - if (!result) - { - return result; - } - - // - bool isBullish = IsBullish(forDir); - - // - if (!IsSpecifiedValid(forPeriod)) - { - forPeriod = GetPeriod(); - } - - // - int fromIndex = -1; - if (!ignoreActivation) - { - // - XOHCL activatedBar; - bool isBodyIn = false; - bool isActivated = IsActivated( - forDir, - activatedBar, - isBodyIn, - activationStartedOut, - forPeriod // - ); - - // - bool isActivationPassed = - !activationBodyIn - ? isActivated - : isActivated && - isBodyIn; - if (isActivationPassed) - { - fromIndex = activatedBar.Index() - 1; - } - - // - activatedBar.Clean(); - } - else - { - // - fromIndex = iBarShift( - GetSymbol(), - forPeriod, - From() // - ); - } - - // - result = IsValidIndex(fromIndex); - if (!result) - { - return result; - } - - // - for (int i = fromIndex; i >= 0; i--) - { - // - XOHCL iBar; - bool isInited = iBar.Init( - GetSymbol(), - forPeriod, - i // - ); - result = isInited; - if (!result) - { - // - iBar.Clean(); - continue; - } - - // - bool isBreakedFromUpper = - // - iBar.low > Upper() || - (iBar.low <= Upper() && - iBar.high > Upper() && - iBar.close > Upper()) - // - ; - - // - bool isBreakedFromLower = - // - iBar.low < Lower() || - (iBar.high >= Lower() && - iBar.low < Lower() && - iBar.close < Lower()) - // - ; - - // - bool isBreaked = - isBreakedFromUpper || - isBreakedFromLower; - if (isBreaked) - { - // - result = isBreaked && - isBullish - ? isBreakedFromUpper - : isBreakedFromLower; - if (result) - { - // - workedBar = iBar; - iBar.Clean(); - break; - } - } - - // - iBar.Clean(); - } - - // - result = workedBar.IsValid(); - if (result) - { - // - isBodyOut = - isBullish - ? workedBar.IsBullish() && - workedBar.GetUp() > Upper() - : workedBar.IsBearish() && - workedBar.GetDown() < Lower(); - } - - // - return result; - } - - /** - * Check to Find Nearest Bar which Breakes Upper ... - * - * @param bar: XOHCL instance Reference, Breaker Bar ... - * @param forPeriod: ENUM_TIMEFRAMES member, Breaker Bar Detection Period, default is Zone Period ... - * - * @return ( bool ) - */ - bool FindNearestInsideBarFromUpper( - XOHCL &bar, - ENUM_TIMEFRAMES forPeriod = NULL // - ) - { - // - bool result = false; - - // - bar.Clean(); - - // - if (!IsSpecifiedValid(forPeriod)) - { - forPeriod = GetPeriod(); - } - - // - result = IsValid(); - if (!result) - { - return result; - } - - // - int from = 1; - int to = iBarShift( - GetSymbol(), - forPeriod, - From() // - ); - - // - for (int i = from; i < to; i++) - { - // - XOHCL iBar; - bool isInited = iBar.Init( - GetSymbol(), - forPeriod, - i // - ); - if (!isInited) - { - break; - } - - // - bool isInside = iBar.low < Upper(); - if (isInside) - { - // - bar = iBar; - break; - } - } - - // - result = bar.IsValid(); - - // - return result; - } - - /** - * Check to Find Nearest Bar which Breakes Lower ... - * - * @param bar: XOHCL instance Reference, Breaker Bar ... - * @param forPeriod: ENUM_TIMEFRAMES member, Breaker Bar Detection Period, default is Zone Period ... - * - * @return ( bool ) - */ - bool FindNearestInsideBarFromLower( - XOHCL &bar, - ENUM_TIMEFRAMES forPeriod = NULL // - ) - { - // - bool result = false; - - // - bar.Clean(); - - // - if (!IsSpecifiedValid(forPeriod)) - { - forPeriod = GetPeriod(); - } - - // - result = IsValid(); - if (!result) - { - return result; - } - - // - int from = 1; - int to = iBarShift( - GetSymbol(), - forPeriod, - From() // - ); - - // - for (int i = from; i < to; i++) - { - // - XOHCL iBar; - bool isInited = iBar.Init( - GetSymbol(), - forPeriod, - i // - ); - if (!isInited) - { - break; - } - - // - bool isInside = iBar.high > Lower(); - if (isInside) - { - // - bar = iBar; - break; - } - } - - // - result = bar.IsValid(); - - // - return result; - } - - // - // Overrides ... - - void Clean() override - { - // - mBar.Clean(); - mUpper = 0; - mLower = 0; - mType = X_POI_NONE; - } - - datetime From() override - { - return mFrom; - } - - datetime To() override - { - return mTo; - } - - string GetTag() override - { - // - string result = NULL; - - // - if (!IsValidBarZone()) - { - return result; - } - - // - string hash = ToMD5(mBar.GetTag()); - - // - result = - // - TypeAsString() + mSep + - ToString(mBar.period) + mSep + - hash - // - ; - - // - return result; - } - - string GetTooltip() override - { - // - string result = NULL; - - // - if (!IsValidBarZone()) - { - return result; - } - - // - return result; - } - - // - protected: - // - // Props ... - XOHCL mBar; // Bar ... - ENUM_X_PRICE mUpperPrice; // Upper Price Selection - ENUM_X_PRICE mLowerPrice; // Lower Price Selection - - /** - * Check Bar Zone Validation ... - * - * @return ( bool ) - */ - bool IsValidBarZone() - { - // - bool result = false; - - // - result = mBar.IsValid() && - mType != X_POI_NONE && - IsValidBoundary(); - - // - return result; - } - - // - private: - // - // Props ... - datetime mFrom; - datetime mTo; - - // -}; -class XCTwoBarZone : public XCZone -{ - // - public: - // - - // - // Constructor ... - void XCTwoBarZone() - { - } - - // - // Deconstructor ... - void ~XCTwoBarZone() - { - } - - // - // Tools ... - - /** - * Initialize POI ... - * - * @param bar: XOHCL instance ... - * @param type: ENUM_XPOIS member ... - * @param upperPrice: ENUM_X_PRICE member ... - * @param lowerPrice: ENUM_X_PRICE member ... - * - * @return ( bool ) - */ - bool InitTwoBarZone( - XOHCL &startBar, - XOHCL &endBar, - ENUM_XPOIS type, - ENUM_X_PRICE startPrice, - ENUM_X_PRICE endPrice // - ) - { - // - bool result = false; - - // - result = startBar.IsValid() && - endBar.IsValid() && - startBar.symbol == endBar.symbol && - startBar.period == endBar.period && - startBar.time < endBar.time && - type != X_POI_NONE; - if (!result) - { - return result; - } - - // - mType = type; - mEndBar = endBar; - mStartBar = startBar; - - // - int startIndex = startBar.Index(); - int endIndex = endBar.Index(); - - // - double mStartPrice = startBar.GetPrice(startPrice); - double mEndPrice = endBar.GetPrice(endPrice); - bool isStartOverEnd = mStartPrice > mEndPrice; - - // - if (isStartOverEnd) - { - // - mUpperPrice = startPrice; - mLowerPrice = endPrice; - } - else - { - // - mUpperPrice = endPrice; - mLowerPrice = startPrice; - } - - // - mUpper = MathMax(mStartPrice, mEndPrice); - mLower = MathMin(mStartPrice, mEndPrice); - - // - result = IsValidTwoBarZone(); - if (result) - { - // - From(startBar.time); - To(endBar.time); - } - - // - return result; - } - - // - // Getter(s) / Setter(s) ... - - /** - * Set From Date ... - * - * @param value: DateTime ... - */ - void From(datetime value) - { - // - if (!IsValidTwoBarZone()) - { - return; - } - - // - value = NormalizeTime(value); - - // - mFrom = value; - } - - /** - * Set To Date ... - * - * @param value: DateTime ... - */ - void To(datetime value) - { - // - if (!IsValidTwoBarZone()) - { - return; - } - - // - value = NormalizeTime(value); - - // - mTo = value; - } - - /** - * Fill Start Bar ... - * - * @param bar: XOHCL instance ... - * - * @return ( bool ) - */ - bool FillStartBar(XOHCL &bar) - { - // - bool result = false; - - // - result = IsValidTwoBarZone(); - if (!result) - { - return result; - } - - // - bar = mStartBar; - - // - return result; - } - - /** - * Fill End Bar ... - * - * @param bar: XOHCL instance ... - * - * @return ( bool ) - */ - bool FillEndBar(XOHCL &bar) - { - // - bool result = false; - - // - result = IsValidTwoBarZone(); - if (!result) - { - return result; - } - - // - bar = mEndBar; - - // - return result; - } - - /** - * Get Symbol ... - * - * @return ( string ) - */ - string GetSymbol() - { - // - string result = NULL; - - // - if (!mStartBar.IsValid()) - { - return result; - } - - // - return mStartBar.symbol; - - // - return result; - } - - /** - * Get Period ... - * - * @return ( int ) - */ - ENUM_TIMEFRAMES GetPeriod() - { - // - ENUM_TIMEFRAMES result = NULL; - - // - if (!mStartBar.IsValid()) - { - return result; - } - - // - return mStartBar.period; - - // - return result; - } - - /** - * Check Zone Started or not ... - * First Exit in Direction of Zone after From ... - * - * @param forDir: exit direction ... - * @param startedBar: specified Start Bar ... - * @param isBodyOut: specified Start Bar Close is Out of Zone or not ... - * @param forPeriod: specified Period ... - * - * @return ( bool ) - */ - bool IsStarted( - ENUM_X_DIRECTION forDir, - XOHCL &startedBar, - bool &isBodyOut, - ENUM_TIMEFRAMES forPeriod = NULL // - ) - { - // - bool result = false; - - // - isBodyOut = false; - startedBar.Clean(); - - // - result = HasDirection(forDir) && - IsValidTwoBarZone(); - if (!result) - { - return result; - } - - // - bool isBullish = IsBullish(forDir); - - // - if (!IsSpecifiedValid(forPeriod)) - { - forPeriod = GetPeriod(); - } - - // - // Detect From Bar Index ... - int fromIndex = iBarShift( - GetSymbol(), - forPeriod, - From() // - ); - - // - for (int i = fromIndex; i >= 0; i--) - { - // - XOHCL iBar; - bool isInited = iBar.Init( - GetSymbol(), - forPeriod, - i // - ); - result = isInited; - if (!result) - { - // - iBar.Clean(); - continue; - } - - // - bool isBreakedFromUpper = - // - iBar.low > Upper() || - (iBar.low <= Upper() && - iBar.high > Upper() && - iBar.close > Upper()) - // - ; - - // - bool isBreakedFromLower = - // - iBar.low < Lower() || - (iBar.high >= Lower() && - iBar.low < Lower() && - iBar.close < Lower()) - // - ; - - // - bool isBreaked = - isBreakedFromUpper || - isBreakedFromLower; - if (isBreaked) - { - // - result = isBreaked && - isBullish - ? isBreakedFromUpper - : isBreakedFromLower; - if (result) - { - // - startedBar = iBar; - iBar.Clean(); - break; - } - } - - // - iBar.Clean(); - } - - // - result = startedBar.IsValid(); - if (result) - { - // - isBodyOut = - isBullish - ? startedBar.IsBullish() && - startedBar.GetUp() > Upper() - : startedBar.IsBearish() && - startedBar.GetDown() < Lower(); - } - - // - return result; - } - - /** - * Check Zone Activated or not ... - * First Enter in Opposit Direction of Zone after Start ... - * - * @param forDir: exit direction ... - * @param activatedBar: specified Activation Bar ... - * @param isBodyIn: specified Activation Bar Close is Inside of Zone or not ... - * @param forPeriod: specified Period ... - * - * @return ( bool ) - */ - bool IsActivated( - ENUM_X_DIRECTION forDir, - XOHCL &activatedBar, - bool &isBodyIn, - bool forceBodyOutStarted = true, - ENUM_TIMEFRAMES forPeriod = NULL // - ) - { - // - bool result = false; - - // - isBodyIn = false; - activatedBar.Clean(); - - // - result = HasDirection(forDir) && - IsValidTwoBarZone(); - if (!result) - { - return result; - } - - // - bool isBullish = IsBullish(forDir); - - // - if (!IsSpecifiedValid(forPeriod)) - { - forPeriod = GetPeriod(); - } - - // - XOHCL startedBar; - bool isBodyOut = false; - bool isStarted = IsStarted( - forDir, - startedBar, - isBodyOut, - forPeriod // - ); - result = - !forceBodyOutStarted - ? isStarted - : isStarted && - isBodyOut; - if (!result) - { - // - startedBar.Clean(); - return result; - } - - // - int fromIndex = startedBar.Index() - 1; - - // - for (int i = fromIndex; i >= 0; i--) - { - // - XOHCL iBar; - bool isInited = iBar.Init( - GetSymbol(), - forPeriod, - i // - ); - result = isInited; - if (!result) - { - // - iBar.Clean(); - continue; - } - - // - bool isInsideFromUpper = - // - iBar.high < Upper() || - (iBar.high > Upper() && - iBar.low <= Upper() && - iBar.close <= Upper()) - // - ; - - // - bool isInsideFromLower = - // - iBar.low > Lower() || - (iBar.low < Lower() && - iBar.high >= Lower() && - iBar.close >= Lower()) - // - ; - - // - bool isInside = - isInsideFromUpper || - isInsideFromLower; - if (isInside) - { - // - result = isInside && - isBullish - ? isInsideFromUpper - : isInsideFromLower; - if (result) - { - // - activatedBar = iBar; - iBar.Clean(); - startedBar.Clean(); - break; - } - } - - // - iBar.Clean(); - startedBar.Clean(); - } - - // - result = activatedBar.IsValid(); - if (result) - { - // - isBodyIn = - isBullish - ? activatedBar.IsBearish() && - activatedBar.GetDown() < Upper() - : activatedBar.IsBullish() && - activatedBar.GetUp() > Lower(); - } - - // - return result; - } - - /** - * Check Zone reaked or not ... - * - * @param forDir: exit direction ... - * @param breakedBar: specified Breaked Bar ... - * @param isBodyOut: specified Breaked Bar Close is Out of Zone or not ... - * @param ignoreStart: Ignore Zone Start (Calculate from From()) ... - * @param startedBodyOut: Started Bar Body Close State, if use Start for Calculation ... - * @param forPeriod: specified Period ... - * - * @return ( bool ) - */ - bool IsBreaked( - ENUM_X_DIRECTION forDir, - XOHCL &breakedBar, - bool &isBodyOut, - bool ignoreStart = false, - bool startedBodyOut = false, - ENUM_TIMEFRAMES forPeriod = NULL // - ) - { - // - bool result = false; - - // - isBodyOut = false; - breakedBar.Clean(); - - // - result = HasDirection(forDir) && - IsValidTwoBarZone(); - if (!result) - { - return result; - } - - // - bool isBullish = IsBullish(forDir); - - // - if (!IsSpecifiedValid(forPeriod)) - { - forPeriod = GetPeriod(); - } - - // - int fromIndex = -1; - if (!ignoreStart) - { - // - XOHCL startedBar; - bool isBodyOut = false; - bool isStarted = IsStarted( - forDir, - startedBar, - isBodyOut, - forPeriod // - ); - - // - bool isStartPassed = - !startedBodyOut - ? isStarted - : isStarted && - isBodyOut; - if (isStartPassed) - { - fromIndex = startedBar.Index() - 1; - } - - // - startedBar.Clean(); - } - else - { - // - fromIndex = iBarShift( - GetSymbol(), - forPeriod, - From() // - ); - } - - // - result = IsValidIndex(fromIndex); - if (!result) - { - return result; - } - - // - for (int i = fromIndex; i >= 0; i--) - { - // - XOHCL iBar; - bool isInited = iBar.Init( - GetSymbol(), - forPeriod, - i // - ); - result = isInited; - if (!result) - { - // - iBar.Clean(); - continue; - } - - // - bool isBreakedFromUpper = - // - iBar.low > Upper() || - (iBar.low <= Upper() && - iBar.high > Upper() && - iBar.close > Upper()) - // - ; - - // - bool isBreakedFromLower = - // - iBar.low < Lower() || - (iBar.high >= Lower() && - iBar.low < Lower() && - iBar.close < Lower()) - // - ; - - // - bool isBreaked = - isBreakedFromUpper || - isBreakedFromLower; - if (isBreaked) - { - // - result = isBreaked && - (isBullish - ? isBreakedFromLower - : isBreakedFromUpper); - if (result) - { - // - breakedBar = iBar; - iBar.Clean(); - break; - } - } - - // - iBar.Clean(); - } - - // - result = breakedBar.IsValid(); - if (result) - { - // - isBodyOut = - isBullish - ? breakedBar.IsBearish() && - breakedBar.GetDown() < Lower() - : breakedBar.IsBullish() && - breakedBar.GetUp() > Upper(); - } - - // - return result; - } - - /** - * Check Zone Worked or not ... - * - * @param forDir: exit direction ... - * @param workedBar: specified Worked Bar ... - * @param isBodyOut: specified Worked Bar Close is Out of Zone or not ... - * @param ignoreActivation: Ignore Zone Activation (Calculate from From()) ... - * @param activationStartedOut: Specified Zone Start Bar State ... - * @param activationBodyIn: Specified Zone Activation Bar State ... - * @param forPeriod: specified Period ... - * - * @return ( bool ) - */ - bool IsWorked( - ENUM_X_DIRECTION forDir, - XOHCL &workedBar, - bool &isBodyOut, - bool ignoreActivation = false, - bool activationStartedOut = false, - bool activationBodyIn = false, - ENUM_TIMEFRAMES forPeriod = NULL // - ) - { - // - bool result = false; - - // - isBodyOut = false; - workedBar.Clean(); - - // - result = HasDirection(forDir) && - IsValidTwoBarZone(); - if (!result) - { - return result; - } - - // - bool isBullish = IsBullish(forDir); - - // - if (!IsSpecifiedValid(forPeriod)) - { - forPeriod = GetPeriod(); - } - - // - int fromIndex = -1; - if (!ignoreActivation) - { - // - XOHCL activatedBar; - bool isBodyIn = false; - bool isActivated = IsActivated( - forDir, - activatedBar, - isBodyIn, - activationStartedOut, - forPeriod // - ); - - // - bool isActivationPassed = - !activationBodyIn - ? isActivated - : isActivated && - isBodyIn; - if (isActivationPassed) - { - fromIndex = activatedBar.Index() - 1; - } - - // - activatedBar.Clean(); - } - else - { - // - fromIndex = iBarShift( - GetSymbol(), - forPeriod, - From() // - ); - } - - // - result = IsValidIndex(fromIndex); - if (!result) - { - return result; - } - - // - for (int i = fromIndex; i >= 0; i--) - { - // - XOHCL iBar; - bool isInited = iBar.Init( - GetSymbol(), - forPeriod, - i // - ); - result = isInited; - if (!result) - { - // - iBar.Clean(); - continue; - } - - // - bool isBreakedFromUpper = - // - iBar.low > Upper() || - (iBar.low <= Upper() && - iBar.high > Upper() && - iBar.close > Upper()) - // - ; - - // - bool isBreakedFromLower = - // - iBar.low < Lower() || - (iBar.high >= Lower() && - iBar.low < Lower() && - iBar.close < Lower()) - // - ; - - // - bool isBreaked = - isBreakedFromUpper || - isBreakedFromLower; - if (isBreaked) - { - // - result = isBreaked && - isBullish - ? isBreakedFromUpper - : isBreakedFromLower; - if (result) - { - // - workedBar = iBar; - iBar.Clean(); - break; - } - } - - // - iBar.Clean(); - } - - // - result = workedBar.IsValid(); - if (result) - { - // - isBodyOut = - isBullish - ? workedBar.IsBullish() && - workedBar.GetUp() > Upper() - : workedBar.IsBearish() && - workedBar.GetDown() < Lower(); - } - - // - return result; - } - - /** - * Check to Find Nearest Bar which Breakes Upper ... - * - * @param bar: XOHCL instance Reference, Breaker Bar ... - * @param forPeriod: ENUM_TIMEFRAMES member, Breaker Bar Detection Period, default is Zone Period ... - * - * @return ( bool ) - */ - bool FindNearestInsideBarFromUpper( - XOHCL &bar, - ENUM_TIMEFRAMES forPeriod = NULL // - ) - { - // - bool result = false; - - // - bar.Clean(); - - // - if (!IsSpecifiedValid(forPeriod)) - { - forPeriod = GetPeriod(); - } - - // - result = IsValid(); - if (!result) - { - return result; - } - - // - int from = 1; - int to = iBarShift( - GetSymbol(), - forPeriod, - From() // - ); - - // - for (int i = from; i < to; i++) - { - // - XOHCL iBar; - bool isInited = iBar.Init( - GetSymbol(), - forPeriod, - i // - ); - if (!isInited) - { - break; - } - - // - bool isInside = iBar.low < Upper(); - if (isInside) - { - // - bar = iBar; - break; - } - } - - // - result = bar.IsValid(); - - // - return result; - } - - /** - * Check to Find Nearest Bar which Breakes Lower ... - * - * @param bar: XOHCL instance Reference, Breaker Bar ... - * @param forPeriod: ENUM_TIMEFRAMES member, Breaker Bar Detection Period, default is Zone Period ... - * - * @return ( bool ) - */ - bool FindNearestInsideBarFromLower( - XOHCL &bar, - ENUM_TIMEFRAMES forPeriod = NULL // - ) - { - // - bool result = false; - - // - bar.Clean(); - - // - if (!IsSpecifiedValid(forPeriod)) - { - forPeriod = GetPeriod(); - } - - // - result = IsValid(); - if (!result) - { - return result; - } - - // - int from = 1; - int to = iBarShift( - GetSymbol(), - forPeriod, - From() // - ); - - // - for (int i = from; i < to; i++) - { - // - XOHCL iBar; - bool isInited = iBar.Init( - GetSymbol(), - forPeriod, - i // - ); - if (!isInited) - { - break; - } - - // - bool isInside = iBar.high > Lower(); - if (isInside) - { - // - bar = iBar; - break; - } - } - - // - result = bar.IsValid(); - - // - return result; - } - - // - // Overrides ... - - void Clean() override - { - // - mStartBar.Clean(); - mEndBar.Clean(); - mUpper = 0; - mLower = 0; - mUseStartBarForUpper = false; - mType = X_POI_NONE; - } - - datetime From() override - { - return mFrom; - } - - datetime To() override - { - return mTo; - } - - string GetTag() override - { - // - string result = NULL; - - // - if (!IsValidTwoBarZone()) - { - return result; - } - - // - string hash = ToMD5(mStartBar.GetTag() + mSep + mEndBar.GetTag()); - - // - result = - // - TypeAsString() + mSep + - ToString(mStartBar.period) + mSep + - hash - // - ; - - // - return result; - } - - string GetTooltip() override - { - // - string result = NULL; - - // - if (!IsValidTwoBarZone()) - { - return result; - } - - // - return result; - } - - // - protected: - // - // Props ... - XOHCL mStartBar; // Start (Oldest) Bar ... - XOHCL mEndBar; // End (Newest) Bar ... - bool mUseStartBarForUpper; // Use Start Bar for Upper Calculation ... - ENUM_X_PRICE mUpperPrice; // Upper Price Selection - ENUM_X_PRICE mLowerPrice; // Lower Price Selection - - /** - * Check Two Bar Zone Validation ... - * - * @return ( bool ) - */ - bool IsValidTwoBarZone() - { - // - bool result = false; - - // - result = mStartBar.IsValid() && - mEndBar.IsValid() && - mStartBar.symbol == mEndBar.symbol && - mStartBar.period == mEndBar.period && - mStartBar.time < mEndBar.time && - mType != X_POI_NONE && - IsValidBoundary(); - - // - return result; - } - - // - private: - // - // Props ... - datetime mFrom; - datetime mTo; - - // -}; - -// -// Swing Class ... -class XCSwing : public XCBasePOI -{ - // - public: - // - - // - // Constructor ... - void XCSwing() - { - } - - // - // Deconstructor ... - void ~XCSwing() - { - } - - // - // Tools ... - - /** - * Initialize POI ... - * - * @param bar: XOHCL instance ... - * @param type: ENUM_XPOIS member ... - * - * @return ( bool ) - */ - bool Init( - XOHCL &bar, - ENUM_XPOIS type // - ) - { - // - bool result = false; - - // - result = bar.IsValid() && - (type == X_POI_SWING_HIGH || - type == X_POI_SWING_LOW); - if (!result) - { - return result; - } - - // - mBar = bar; - mType = type; - - // - result = IsValid(); - - // - return result; - } - - // - // Getter(s) / Setter(s) ... - - /** - * Fill Bar as XOHCL struct ... - * - * @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; - } - - /** - * Get Time of Swing ... - * - * @return ( datetime ) - */ - datetime GetTime() - { - // - datetime result = NULL; - - // - if (!IsValid() || !mBar.IsValid()) - { - return result; - } - - // - result = mBar.time; - - // - return result; - } - - ENUM_TIMEFRAMES GetPeriod() - { - // - ENUM_TIMEFRAMES result = NULL; - - // - XOHCL bar; - bool isFilled = FillBar(bar); - if (!isFilled) - { - return result; - } - - // - result = bar.period; - - // - return result; - } - - /** - * Check Swing High or not ... - * - * @return ( bool ) - */ - bool IsSwingHigh() - { - // - bool result = false; - - // - result = IsValid(); - if (!result) - { - return result; - } - - // - result = - Type() == X_POI_SWING_HIGH; - - // - return result; - } - - /** - * Check Swing Low or not ... - * - * @return ( bool ) - */ - bool IsSwingLow() - { - // - bool result = false; - - // - result = IsValid(); - if (!result) - { - return result; - } - - // - result = - Type() == X_POI_SWING_LOW; - - // - return result; - } - - /** - * Get Swing Value ... - * - * @return ( double ) - */ - double GetValue() - { - // - double result = 0; - - // - if (!IsValid()) - { - return result; - } - - // - result = - IsSwingHigh() - ? mBar.high - : mBar.low; - - // - return result; - } - - // - // Overrides ... - - void Clean() override - { - // - mBar.Clean(); - mType = X_POI_NONE; - } - - bool IsValid() override - { - // - bool result = false; - - // - result = mBar.IsValid() && - (mType == X_POI_SWING_HIGH || - mType == X_POI_SWING_LOW); - - // - return result; - } - - string GetTag() override - { - // - string result = NULL; - - // - if (!IsValid()) - { - return result; - } - - // - string hash = ToMD5(mBar.GetTag()); - - // - string subType = IsSwingHigh() - ? "High" - : "Low"; - - // - result = - // - TypeAsString() + mSep + - subType + mSep + - ToString(mBar.period) + mSep + - hash - // - ; - - // - return result; - } - - string GetTooltip() override - { - // - string result = NULL; - - // - if (!IsValid()) - { - return result; - } - - // - return result; - } - - // - protected: - // - // Props ... - XOHCL mBar; // Swing Bar ... - - // - private: - // -}; - -// -// Supply Zone ... -class XCSupplyZone : public XCBarZone -{ - // - public: - // - - // - // Constructor ... - void XCSupplyZone() - { - } - - // - // Deconstructor ... - void ~XCSupplyZone() - { - } - - // - // Tools ... - - /** - * Initialize POI ... - * - * @param bar: XOHCL instance ... - * @param range: Integer, Detection Range ... - * - * @return ( bool ) - */ - bool Init( - XOHCL &bar, - int range = 0, - bool useRangeAsStart = false // - ) - { - // - bool result = false; - - // - result = bar.IsValid(); - if (!result) - { - return result; - } - - // - result = InitBarZone( - bar, - X_POI_SUPPLY_ZONE, - X_PRICE_HIGH, - X_PRICE_LOW // - ); - if (!result) - { - return result; - } - - // - result = IsValid(); - if (result && - range > 0) - { - // - datetime time = bar.time; - int periodSeconds = PeriodSeconds(bar.period); - - // - datetime from = - !useRangeAsStart - ? (datetime)((int)time - (range * periodSeconds)) - : time; - datetime to = (datetime)((int)time + (range * periodSeconds)); - - // - From(from); - To(to); - } - - // - return result; - } - - // - // Getter(s) / Setter(s) ... - - // - // Overrides ... - - bool IsValid() override - { - // - bool result = false; - - // - result = IsValidBarZone() && - mType == X_POI_SUPPLY_ZONE; - - // - return result; - } - - // - protected: - // - - // - private: - // - - // -}; - -// -// Demand Zone ... -class XCDemandZone : public XCBarZone -{ - // - public: - // - - // - // Constructor ... - void XCDemandZone() - { - } - - // - // Deconstructor ... - void ~XCDemandZone() - { - } - - // - // Tools ... - - /** - * Initialize POI ... - * - * @param bar: XOHCL instance ... - * @param range: Integer, Detection Range ... - * - * @return ( bool ) - */ - bool Init( - XOHCL &bar, - int range = 0, - bool useRangeAsStart = false // - ) - { - // - bool result = false; - - // - result = bar.IsValid(); - if (!result) - { - return result; - } - - // - result = InitBarZone( - bar, - X_POI_DEMAND_ZONE, - X_PRICE_HIGH, - X_PRICE_LOW // - ); - if (!result) - { - return result; - } - - // - result = IsValid(); - if (result && - range > 0) - { - // - datetime time = bar.time; - int periodSeconds = PeriodSeconds(bar.period); - - // - datetime from = - !useRangeAsStart - ? (datetime)((int)time - (range * periodSeconds)) - : time; - datetime to = (datetime)((int)time + (range * periodSeconds)); - - // - From(from); - To(to); - } - - // - return result; - } - - // - // Getter(s) / Setter(s) ... - - // - // Overrides ... - - bool IsValid() override - { - // - bool result = false; - - // - result = IsValidBarZone() && - mType == X_POI_DEMAND_ZONE; - - // - return result; - } - - // - protected: - // - - // - private: - // - - // -}; - -// -// Support Zone ... -class XCSupportZone : public XCBarZone -{ - // - public: - // - - // - // Constructor ... - void XCSupportZone() - { - } - - // - // Deconstructor ... - void ~XCSupportZone() - { - } - - // - // Tools ... - - /** - * Initialize POI ... - * - * @param bar: XOHCL instance ... - * @param range: Integer, Detection Range ... - * - * @return ( bool ) - */ - bool Init( - XOHCL &bar, - int range = 0, - bool useRangeAsStart = false // - ) - { - // - bool result = false; - - // - result = bar.IsValid(); - if (!result) - { - return result; - } - - // - result = InitBarZone( - bar, - X_POI_SUPPORT_ZONE, - X_PRICE_DOWN, - X_PRICE_LOW // - ); - if (!result) - { - return result; - } - - // - result = IsValid(); - if (result && - range > 0) - { - // - datetime time = bar.time; - int periodSeconds = PeriodSeconds(bar.period); - - // - datetime from = - !useRangeAsStart - ? (datetime)((int)time - (range * periodSeconds)) - : time; - datetime to = (datetime)((int)time + (range * periodSeconds)); - - // - From(from); - To(to); - } - - // - return result; - } - - // - // Getter(s) / Setter(s) ... - - // - // Overrides ... - - bool IsValid() override - { - // - bool result = false; - - // - result = IsValidBarZone() && - mType == X_POI_SUPPORT_ZONE; - - // - return result; - } - - // - protected: - // - - // - private: - // - - // -}; - -// -// Resistance Zone ... -class XCResistanceZone : public XCBarZone -{ - // - public: - // - - // - // Constructor ... - void XCResistanceZone() - { - } - - // - // Deconstructor ... - void ~XCResistanceZone() - { - } - - // - // Tools ... - - /** - * Initialize POI ... - * - * @param bar: XOHCL instance ... - * @param range: Integer, Detection Range ... - * - * @return ( bool ) - */ - bool Init( - XOHCL &bar, - int range = 0, - bool useRangeAsStart = false // - ) - { - // - bool result = false; - - // - result = bar.IsValid(); - if (!result) - { - return result; - } - - // - result = InitBarZone( - bar, - X_POI_RESISTANCE_ZONE, - X_PRICE_HIGH, - X_PRICE_UP // - ); - if (!result) - { - return result; - } - - // - result = IsValid(); - if (result && - range > 0) - { - // - datetime time = bar.time; - int periodSeconds = PeriodSeconds(bar.period); - - // - datetime from = - !useRangeAsStart - ? (datetime)((int)time - (range * periodSeconds)) - : time; - datetime to = (datetime)((int)time + (range * periodSeconds)); - - // - From(from); - To(to); - } - - // - return result; - } - - // - // Getter(s) / Setter(s) ... - - // - // Overrides ... - - bool IsValid() override - { - // - bool result = false; - - // - result = IsValidBarZone() && - mType == X_POI_RESISTANCE_ZONE; - - // - return result; - } - - // - protected: - // - - // - private: - // - - // -}; - -// -// Order Block ... -class XCOrderBlock : public XCBarZone -{ - // - public: - // - - // - // Constructor ... - void XCOrderBlock() - { - } - - // - // Deconstructor ... - void ~XCOrderBlock() - { - } - - // - // Tools ... - - /** - * Initialize POI ... - * - * @param bar: XOHCL instance ... - * @param dir: ENUM_X_DIRECTION member ... - * - * @return ( bool ) - */ - bool Init( - XOHCL &bar, - ENUM_X_DIRECTION dir // - ) - { - // - bool result = false; - - // - result = bar.IsValid() && - (dir == X_DIRECTION_BULLISH || - dir == X_DIRECTION_BEARISH); - if (!result) - { - return result; - } - - // - ENUM_XPOIS mTT = - IsSpecifiedBullish(dir) - ? X_POI_BULLISH_ORDERBLOCK - : X_POI_BEARISH_ORDERBLOCK; - - // - result = InitBarZone( - bar, - mTT, - X_PRICE_HIGH, - X_PRICE_LOW // - ); - if (!result) - { - return result; - } - - // - result = IsValid(); - - // - return result; - } - - // - // Getter(s) / Setter(s) ... - - /** - * Check is Bullish ... - * - * @return ( bool ) - */ - bool IsBullish() - { - // - bool result = false; - - // - result = IsValid() && - Type() == X_POI_BULLISH_ORDERBLOCK; - - // - return result; - } - - /** - * Check is Bearish ... - * - * @return ( bool ) - */ - bool IsBearish() - { - // - bool result = false; - - // - result = IsValid() && - Type() == X_POI_BEARISH_ORDERBLOCK; - - // - return result; - } - - ENUM_X_DIRECTION GetDirection() - { - // - ENUM_X_DIRECTION result = X_DIRECTION_NONE; - - // - if (!IsValid()) - { - return result; - } - - // - result = - IsBullish() - ? X_DIRECTION_BULLISH - : X_DIRECTION_BEARISH; - - // - return result; - } - - // - // Overrides ... - - bool IsValid() override - { - // - bool result = false; - - // - result = IsValidBarZone() && - (mType == X_POI_BULLISH_ORDERBLOCK || - mType == X_POI_BEARISH_ORDERBLOCK); - - // - return result; - } - - // - protected: - // - - // - private: - // - - // -}; - -// -// Rejection Bar ... -class XCRejectionBar : public XCBarZone -{ - // - public: - // - - // - // Constructor ... - void XCRejectionBar() - { - } - - // - // Deconstructor ... - void ~XCRejectionBar() - { - } - - // - // Tools ... - - /** - * Initialize POI ... - * - * @param bar: XOHCL instance ... - * - * @return ( bool ) - */ - bool Init( - XOHCL &bar // - ) - { - // - bool result = false; - - // - result = bar.IsValid(); - if (!result) - { - return result; - } - - // - bool isBullish = - bar.GetLowShadow() > bar.GetHighShadow(); - bool isBearish = - bar.GetHighShadow() > bar.GetLowShadow(); - result = isBullish || - isBearish; - if (!result) - { - return result; - } - - // - ENUM_X_PRICE upPrice = isBullish - ? X_PRICE_HIGH - : X_PRICE_DOWN; - // - ENUM_X_PRICE loPrice = isBullish - ? X_PRICE_UP - : X_PRICE_LOW; - - // - result = InitBarZone( - bar, - X_POI_REJECTION_BAR, - upPrice, - loPrice // - ); - if (!result) - { - return result; - } - - // - result = IsValid(); - - // - return result; - } - - // - // Getter(s) / Setter(s) ... - - /** - * Check is Bullish ... - * - * @return ( bool ) - */ - bool IsBullish() - { - // - bool result = false; - - // - result = IsValid() && - Type() == X_POI_REJECTION_BAR && - mBar.GetLowShadow() > mBar.GetHighShadow(); - - // - return result; - } - - /** - * Check is Bearish ... - * - * @return ( bool ) - */ - bool IsBearish() - { - // - bool result = false; - - // - result = IsValid() && - Type() == X_POI_REJECTION_BAR && - mBar.GetHighShadow() > mBar.GetLowShadow(); - - // - return result; - } - - // - // Overrides ... - - bool IsValid() override - { - // - bool result = false; - - // - result = IsValidBarZone() && - mType == X_POI_REJECTION_BAR; - - // - return result; - } - - // - protected: - // - - // - private: - // - - // -}; - -// -// Momentum Bar ... -class XCMomentumBar : public XCBarZone -{ - // - public: - // - - // - // Constructor ... - void XCMomentumBar() - { - } - - // - // Deconstructor ... - void ~XCMomentumBar() - { - } - - // - // Tools ... - - /** - * Initialize POI ... - * - * @param bar: XOHCL instance ... - * - * @return ( bool ) - */ - bool Init( - XOHCL &bar // - ) - { - // - bool result = false; - - // - result = bar.IsValid(); - if (!result) - { - return result; - } - - // - bool isBullish = bar.IsBullish(); - bool isBearish = bar.IsBearish(); - result = isBullish || - isBearish; - if (!result) - { - return result; - } - - // - result = InitBarZone( - bar, - X_POI_MOMENTUM_BAR, - X_PRICE_HIGH, - X_PRICE_LOW // - ); - if (!result) - { - return result; - } - - // - result = IsValid(); - - // - return result; - } - - // - // Getter(s) / Setter(s) ... - - /** - * Check is Bullish ... - * - * @return ( bool ) - */ - bool IsBullish() - { - // - bool result = false; - - // - result = IsValid() && - mBar.IsBullish() && - Type() == X_POI_MOMENTUM_BAR; - - // - return result; - } - - /** - * Check is Bearish ... - * - * @return ( bool ) - */ - bool IsBearish() - { - // - bool result = false; - - // - result = IsValid() && - mBar.IsBearish() && - Type() == X_POI_MOMENTUM_BAR; - - // - return result; - } - - // - // Overrides ... - - bool IsValid() override - { - // - bool result = false; - - // - result = IsValidBarZone() && - mType == X_POI_MOMENTUM_BAR; - - // - return result; - } - - // - protected: - // - - // - private: - // - - // -}; - -// -// Fair Value Gap ... -class XCFVG : public XCTwoBarZone -{ - // - public: - // - - // - // Constructor ... - void XCFVG() - { - } - - // - // Deconstructor ... - void ~XCFVG() - { - } - - // - // Tools ... - - /** - * Initialize POI ... - * - * @param startBar: XOHCL instance ... - * @param endBar: XOHCL instance ... - * @param dir: ENUM_X_DIRECTION member ... - * - * @return ( bool ) - */ - bool Init( - XOHCL &startBar, - XOHCL &endBar, - ENUM_X_DIRECTION dir // - ) - { - // - bool result = false; - - // - result = endBar.IsValid() && - startBar.IsValid() && - (dir == X_DIRECTION_BULLISH || - dir == X_DIRECTION_BEARISH); - if (!result) - { - return result; - } - - // - bool isDirBullish = IsSpecifiedBullish(dir); - ENUM_XPOIS mTT = - isDirBullish - ? X_POI_BULLISH_FVG - : X_POI_BEARISH_FVG; - - // - ENUM_X_PRICE startPrice = isDirBullish - ? X_PRICE_HIGH - : X_PRICE_LOW; - ENUM_X_PRICE endPrice = isDirBullish - ? X_PRICE_LOW - : X_PRICE_HIGH; - - // - result = InitTwoBarZone( - startBar, - endBar, - mTT, - startPrice, - endPrice // - ); - if (!result) - { - return result; - } - - // - result = IsValid(); - - // - return result; - } - - // - // Getter(s) / Setter(s) ... - - /** - * Check is Bullish ... - * - * @return ( bool ) - */ - bool IsBullish() - { - // - bool result = false; - - // - result = IsValid() && - Type() == X_POI_BULLISH_FVG; - - // - return result; - } - - /** - * Check is Bearish ... - * - * @return ( bool ) - */ - bool IsBearish() - { - // - bool result = false; - - // - result = IsValid() && - Type() == X_POI_BEARISH_FVG; - - // - return result; - } - - ENUM_X_DIRECTION GetDirection() - { - // - ENUM_X_DIRECTION result = X_DIRECTION_NONE; - - // - if (!IsValid()) - { - return result; - } - - // - result = - IsBullish() - ? X_DIRECTION_BULLISH - : X_DIRECTION_BEARISH; - - // - return result; - } - - // - // Overrides ... - - bool IsValid() override - { - // - bool result = false; - - // - result = IsValidTwoBarZone() && - (mType == X_POI_BULLISH_FVG || - mType == X_POI_BEARISH_FVG); - - // - return result; - } - - // - protected: - // - - // - private: - // - - // -}; - -// -// Ticks Zones ... - -// -class XCTickZone : public CObject -{ - // - // Public ... - public: - // - // Props ... - string symbol; - ENUM_TIMEFRAMES period; - - // - double high; - double low; - int ticks; - double percent; - - // - ulong volume; - double volumePercent; - - // - // Compare Two Zone With Each Other ... - virtual int Compare( - const CObject *node, - const int mode = 0 // - ) const - { - // - const XCTickZone *other = (XCTickZone *)node; - - // - return other.ticks - ticks; - } - - // - bool IsValid() - { - // - bool result = false; - - // - result = high > 0 && - low > 0 && - high > low && - ticks > 0 && - percent > 0; - - // - return result; - } - - // - // Protected ... - protected: - // - // Private ... - private: - // -}; - -// -class XCTicksZone : public XCTwoBarZone -{ - // - public: - // - - // - // Constructor ... - void XCTicksZone() - { - Default(); - } - - // - // Deconstructor ... - void ~XCTicksZone() - { - } - - // - // Getter(s) / Setter(s) ... - - /** - * Get Number of Ticks Levels ... - * - * @return ( int ) - */ - int Levels() - { - return mLevels; - } - - /** - * Set Number of Ticks Levels ... - * - * @return ( int ) - */ - void Levels(int value) - { - // - if (value < 2) - { - value = 2; - } - - // - mLevels = value; - } - - /** - * Apply Default Config ... - */ - virtual void Default() - { - // - Levels(10); - } - - // - // Tools ... - - /** - * Initialize POI ... - * - * @param startBar: XOHCL instance ... - * @param endBar: XOHCL instance ... - * - * @return ( bool ) - */ - bool Init( - XOHCL &startBar, - XOHCL &endBar, - ENUM_TIMEFRAMES forPeriod = NULL // - ) - { - // - bool result = false; - - // - result = endBar.IsValid() && - startBar.IsValid(); - if (!result) - { - return result; - } - - // - if (!IsSpecifiedValid(forPeriod)) - { - forPeriod = endBar.period; - } - - // - // Calculate Start and End Time ... - datetime from = startBar.time; - datetime to = endBar.time; - ulong fromM = ((ulong)to * 1000); - ulong toM = ((ulong)from * 1000); - - // - // Symbol and Period ... - string symbol = startBar.symbol; - ENUM_TIMEFRAMES period = startBar.period; - - // - // Prepare Zones Array ... - mZones.Clear(); - - // - // Retrieve Ticks between Times ... - SpecificClean(mTicks); - int res = CopyTicksRange( - symbol, - mTicks, - COPY_TICKS_ALL, - fromM, - toM // - ); - - // - // Ticks Volumes ... - int ticksVolumeCount = CopyTickVolume( - symbol, - forPeriod, - from, - to, - mTickVolumes // - ); - if (IsValidSize(ticksVolumeCount)) - { - // - mVolumes = 0; - for (int i = 0; i < ticksVolumeCount; i++) - { - mVolumes += mTickVolumes[i]; - } - } - - // - // Retrieve Highs ... - SpecificClean(mHighs); - CopyHigh( - symbol, - period, - from, - to, - mHighs // - ); - - // - // Retrieve Lows ... - SpecificClean(mLows); - CopyLow( - symbol, - period, - from, - to, - mLows // - ); - - // - // Find Highest Value in Range ... - int highIDX = ArrayMaximum(mHighs); - mRangeHigh = mHighs[highIDX]; - - // - // Find Lowest Value in Range ... - int lowIDX = ArrayMinimum(mLows); - mRangeLow = mLows[lowIDX]; - - // - datetime mTimes[]; - CopyTime( - symbol, - period, - from, - to, - mTimes // - ); - mRangeHighTime = mTimes[highIDX]; - mRangeLowTime = mTimes[lowIDX]; - - // - double mRangeSize = mRangeHigh - mRangeLow; - - // - // Create Zones ... - for (int i = 0; i < Levels(); i++) - { - // - // Instance a New Zone ... - XCTickZone *iZone = new XCTickZone(); - - // - iZone.symbol = symbol; - iZone.period = period; - - // - // Calculate Each Zones High / Low based on Range ... - double iH = mRangeHigh - mRangeSize * i / Levels(); - double iL = mRangeHigh - mRangeSize * (i + 1) / Levels(); - - // - // Set Zone High Low Properties ... - iZone.low = iL; - iZone.high = iH; - - // - // Add Zone to Zone Array Objects ... - mZones.Add(iZone); - } - - // - // Calculate Each Zone Ticks ... - int ticksCount = ArraySize(mTicks); - for (int i = 0; i < ticksCount; i++) - { - // - // Retrieve Tick ... - MqlTick iTick = mTicks[i]; - - // - // Loop through Zones ... - for (int j = 0; j < Levels(); j++) - { - // - // Rejrieve j indexed Zone Object ... - XCTickZone *jZone = mZones.At(j); - - // - bool isInRange = IsTickInZoneRange( - iTick, - jZone // - ); - if (isInRange) - { - // - jZone.ticks++; - break; - } - } - } - - // - // Calculating Zone Percents ... - for (int i = 0; i < Levels(); i++) - { - // - XCTickZone *iZone = mZones.At(i); - - // - double percent = CalculateZoneTickPercent(iZone); - iZone.percent = percent; - } - - // - // Sort Zones Based on Percents ... - mZones.Sort(); - - // - mUpper = mRangeHigh; - mLower = mRangeLow; - mType = X_POI_TICKS_ZONES; - mEndBar = endBar; - mStartBar = startBar; - From(endBar.time); - To(startBar.time); - - // - result = IsValid(); - if (!result) - { - return result; - } - - // - // Try to Find Out PERIOD_1M times in each zone ... - datetime to1M = (datetime)((int)endBar.time + PeriodSeconds(period) - 60); - int to1MIndex = iBarShift( - symbol, - forPeriod, - to1M // - ); - int from1MIndex = iBarShift( - symbol, - forPeriod, - from // - ); - for (int i = from1MIndex; i > to1MIndex; i--) - { - // - XOHCL iBar; - bool isInited = iBar.Init( - symbol, - forPeriod, - i // - ); - if (!isInited) - { - continue; - } - ulong iVolume = iTickVolume( - symbol, - forPeriod, - i // - ); - - // - // Loop through Zones ... - for (int j = 0; j < Levels(); j++) - { - // - XCTickZone *jZone = mZones.At(j); - if (!jZone.IsValid()) - { - continue; - } - - // - // Check iBar is Inside jZone ... - bool isIBarInside = - iBar.GetUp() < jZone.high && - iBar.GetDown() > jZone.low; - // iBar.low < jZone.high || - // iBar.high > jZone.low; - if (isIBarInside) - { - jZone.volume += iVolume; - } - } - } - - // - // Calculate Volume Percent ... - for (int i = 0; i < Levels(); i++) - { - // - XCTickZone *iZone = mZones.At(i); - - // - if (mVolumes > 0) - { - iZone.volumePercent = (double)(iZone.volume * 100 / mVolumes); - } - } - - // - return result; - } - - // - // Getter(s) / Setter(s) ... - - /** - * Retrieve Zones Count ... - * - * @return ( int ) - */ - int Count() - { - return mZones.Total(); - } - - /** - * Retrieve Specified Sorted Zones ... - * - * @param index: Integer ... - * - * @return ( XCTickZone * ) - */ - XCTickZone *GetZone(int index) - { - // - if (!IsValidIndex(index)) - { - return NULL; - } - - // - return mZones.At(index); - } - - /** - * Calculate Liquidity Percent for Specified Direction ... - * - * @param forDirection: ENUM_X_DIRECTION member, Specified Liquidity ... - * @param price: Double, Specified Price ... - * - * @return ( double ) - */ - double CalculateLiquidityPercent( - ENUM_X_DIRECTION forDirection, - double price // - ) - { - // - double result = 0; - - // - int count = Count(); - if (price <= 0 || - !IsValid() || - !IsValidSize(count) || - forDirection == X_DIRECTION_ALL || - forDirection == X_DIRECTION_NONE) - { - return result; - } - - // - bool isBullish = forDirection == X_DIRECTION_BULLISH; - - // - for (int i = 0; i < count; i++) - { - // - XCTickZone *iZone = GetZone(i); - - // - if (iZone.IsValid()) - { - // - result += !isBullish && - price > iZone.high - ? iZone.percent - : isBullish && - price < iZone.low - ? iZone.percent - : 0; - } - } - - // - return result; - } - - // - // Overrides ... - bool IsValid() override - { - // - bool result = false; - - // - result = - IsValidFrom() && - IsValidTwoBarZone() && - Levels() > 0 && - mZones.Total() == Levels() && - mRangeHigh > 0 && - mRangeLow > 0; - - // - return result; - } - - // - bool GetMaxTickZone(XCTickZone *&zone) - { - // - bool result = false; - - // - zone = NULL; - - // - result = IsValid(); - if (!result) - { - return result; - } - - // - int count = Count(); - for (int i = 0; i < count; i++) - { - // - XCTickZone *iZone = GetZone(i); - - // - bool canSet = - zone == NULL - ? true - : zone.ticks < iZone.ticks - ? true - : false; - if (canSet) - { - zone = iZone; - } - - // - ZeroMemory(iZone); - } - - // - result = zone != NULL && - zone.IsValid(); - - // - return result; - } - - // - bool GetMinTickZone(XCTickZone *&zone) - { - // - bool result = false; - - // - zone = NULL; - - // - result = IsValid(); - if (!result) - { - return result; - } - - // - int count = Count(); - for (int i = 0; i < count; i++) - { - // - XCTickZone *iZone = GetZone(i); - - // - bool canSet = - zone == NULL - ? true - : zone.ticks > iZone.ticks - ? true - : false; - if (canSet) - { - zone = iZone; - } - - // - ZeroMemory(iZone); - } - - // - result = zone != NULL && - zone.IsValid(); - - // - return result; - } - - // - bool GetMaxVolumeZone(XCTickZone *&zone) - { - // - bool result = false; - - // - zone = NULL; - - // - result = IsValid(); - if (!result) - { - return result; - } - - // - int count = Count(); - for (int i = 0; i < count; i++) - { - // - XCTickZone *iZone = GetZone(i); - - // - bool canSet = - zone == NULL - ? true - : zone.volume < iZone.volume - ? true - : false; - if (canSet) - { - zone = iZone; - } - - // - ZeroMemory(iZone); - } - - // - result = zone != NULL && - zone.IsValid(); - - // - return result; - } - - // - bool GetMinVolumeZone(XCTickZone *&zone) - { - // - bool result = false; - - // - zone = NULL; - - // - result = IsValid(); - if (!result) - { - return result; - } - - // - int count = Count(); - for (int i = 0; i < count; i++) - { - // - XCTickZone *iZone = GetZone(i); - - // - bool canSet = - zone == NULL - ? true - : zone.volume > iZone.volume - ? true - : false; - if (canSet) - { - zone = iZone; - } - - // - ZeroMemory(iZone); - } - - // - result = zone != NULL && - zone.IsValid(); - - // - return result; - } - - // - protected: - // - - // - private: - // - // Props ... - - // - MqlTick mTicks[]; - double mHighs[]; - double mLows[]; - ulong mVolumes; - ulong mTickVolumes[]; - double mRangeHigh; - datetime mRangeHighTime; - double mRangeLow; - datetime mRangeLowTime; - - // - int mLevels; // Number of Ticks Levels ... - - // - CArrayObj mZones; - - /** - * Check a Tick is in a Zone rage or not ... - * - * @param tick: MqlTick instance ... - * @param zone: XCTickZone instance ... - * - * @return ( bool ) - */ - bool IsTickInZoneRange( - MqlTick &tick, - XCTickZone *zone // - ) - { - // - bool result = false; - - // - result = - // - tick.bid >= zone.low && - tick.bid <= zone.high - // - ; - - // - return result; - } - - /** - * Calculate Zone Tick Percent ... - * - * @param zone: XCTickZone instance ... - * @param normalizationDigits: Integer ... - * - * @return ( double ) - */ - double CalculateZoneTickPercent( - XCTickZone *zone, - int normalizationDigits = 2 // - ) - { - // - double result = 0; - - // - if (normalizationDigits < 2 || normalizationDigits > 5) - { - normalizationDigits = 2; - } - - // - int ticksCount = ArraySize(mTicks); - if (ticksCount <= 0) - { - return result; - } - - // - result = (double)zone.ticks / ticksCount * 100; - result = NormalizeDouble(result, normalizationDigits); - - // - return result; - } - - // -}; - -// -// 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: - // - - // -}; - -// -// 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: - // - - // -}; - // struct XBoxZone { @@ -5426,6 +40,7 @@ struct XBoxZone double lower; // + datetime at; datetime from; datetime to; @@ -5452,6 +67,7 @@ struct XBoxZone upper = 0; lower = 0; to = NULL; + at = NULL; from = NULL; symbol = NULL; period = NULL; diff --git a/XCATBEA/Classes/xcatbea.signaller.class.mq5 b/XCATBEA/Classes/xcatbea.signaller.class.mq5 index ebeece6d..2a9138a0 100644 --- a/XCATBEA/Classes/xcatbea.signaller.class.mq5 +++ b/XCATBEA/Classes/xcatbea.signaller.class.mq5 @@ -1568,18 +1568,7 @@ class XCXCATBEASignaller : XCBase conditions.pivotZone.to = cTime; // - // Draw Box ... - XCBoxObject *iObj; - has = drawer - .drawer - .DrawBox( - conditions.pivotZone, - iObj // - ); - if (has) - { - mObjects.Add(iObj); - } + DrawPivotZone(conditions.pivotZone); // // Check atleast 3 Bars Close Outside of applied Edge ... @@ -1636,11 +1625,9 @@ class XCXCATBEASignaller : XCBase bool isMiddlePassed = isBullish ? (cConditions.bars[1].low < mid && - (cConditions.bars[1].GetDown() > mid || - cConditions.bars[1].close > mid)) + cConditions.bars[1].GetDown() > mid) : (cConditions.bars[1].high > mid && - (cConditions.bars[1].GetUp() < mid || - cConditions.bars[1].close < mid)); + cConditions.bars[1].GetUp() < mid); // result = @@ -2156,6 +2143,34 @@ class XCXCATBEASignaller : XCBase } } + /** + * Draw Pivot Zone ... + * + * @param box: XBoxZone instance Reference ... + */ + void DrawPivotZone(XBoxZone &box) + { + // + bool has = box.IsValid(); + if (!has) + { + return; + } + + // + XCBoxObject *iObj; + has = drawer + .drawer + .DrawBox( + box, + iObj // + ); + if (has) + { + mObjects.Add(iObj); + } + } + // // Private ... private: