/////////////////////////////////////////////////////// // // SaherElm IT Center MQL5 Class Library // -------------------------------------- // Name: XChartObjects // Description: provides all require Chart Objects ... // // // Maintainer: // ------------ // Hadi Khazaee Asl (hadi_khazaee_asl@yahoo.com) // ////////////////////////////////////////////////////// // // Global Properties ... #property library #property copyright "Copyright 2023, SaherElm IT Center" #property link "https://www.saherelm.ir" #property version "1.00" #property strict // #include "../Libraries/x-saherelm.x-poi.lib.mq5" #include "../Libraries/x-saherelm.x-trade.lib.mq5" // #include #include #include #include // // Definitions ... enum ENUM_XCHARTOBJECTS { // // Global ... X_ZONE_OBJ = 7860, X_FROM_TO_OBJ = 7861, X_BAR_ARROW_OBJ = 7862, // X_SIGNAL_OBJ = 8860, X_TREND_OBJ = 8861, // // Structured ... X_TRADE_DAY_OBJ = 9860, X_MARKET_SESSION_OBJ = 9861, X_SWING_HIGH_OBJ = 9862, X_SWING_LOW_OBJ = 9863, X_BULLISH_MOMENTUM_BAR_OBJ = 9864, X_BEARISH_MOMENTUM_BAR_OBJ = 9865, X_BULLISH_REJECTION_BAR_OBJ = 9866, X_BEARISH_REJECTION_BAR_OBJ = 9867, X_SUPPORT_ZONE_OBJ = 9868, X_RESISTANCE_ZONE_OBJ = 9869, X_SUPPLY_ZONE_OBJ = 9870, X_DEMAND_ZONE_OBJ = 9871, X_BULLISH_ORDERBLOCK_OBJ = 9872, X_BEARISH_ORDERBLOCK_OBJ = 9873, X_BULLISH_FVG_OBJ = 9874, X_BEARISH_FVG_OBJ = 9875, }; enum ENUM_X_CHART_IDS { X_TO, X_FROM, X_UPPER, X_LOWER, X_ENTRY, X_SL, X_TP }; // // Implementation ... // // Global Chart Objects ... // // Bas Chart Object ... class XCBaseObject : public CChartObject { // public: // // // Getter(s) / Setter(s) ... /** * Get Object Specified Name ... * * @return ( string ) */ string ObjName() { return mObjName; } /** * Set Object Specified Name ... * * @param value: String ... */ void ObjName(string value) { mObjName = value; } // private: // // // Props ... string mObjName; // Object Specified Name ... // }; 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 // ) { // bool result = false; // result = // bar.IsValid() // ; if (!result) { return result; } // datetime time = bar.time; double price = bar.GetPrice(priceType); // 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 XCMomentumObject : 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 XCBullishMomentumObject : public XCMomentumObject { // 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 XCBearishMomentumObject : public XCMomentumObject { // 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 XCRejectionObject : 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 XCBullishRejectionObject : public XCRejectionObject { // 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 XCBearishRejectionObject : public XCRejectionObject { // 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; // result = // IsValid(name) && zone.IsValidFrom() && zone.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; } }; //