/////////////////////////////////////////////////////// // // 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.xtrade.lib.mq5" // #include #include #include // // Definitions ... enum ENUM_XCHARTOBJECTS { // // Global ... X_ZONE = 7860, X_FROM_TO = 7861, X_BAR_ARROW = 7862, // X_SIGNAL = 8860 // // Structured ... X_TRADE_DAY = 9860, X_MARKET_SESSION = 9861, X_SUPPORT_ZONE = 9862, X_RESISTANCE_ZONE = 9863, X_SUPPLY_ZONE = 9864, X_DEMAND_ZONE = 9865, X_BULLISH_ORDERBLOCK = 9866, X_BEARISH_ORDERBLOCK = 9867, X_BULLISH_FVG = 9868, X_BEARISH_FVG = 9869, }; enum ENUM_X_CHART_IDS { X_TO, X_FROM, X_UPPER, X_LOWER, X_ENTRY, X_SL, X_TP }; // // Extensions ... /** * Convert ENUM_X_TRADE_DAY_IDS membr to String ... * * @param value: ENUM_X_TRADE_DAY_IDS member ... * * @return ( string ) */ string ToString(ENUM_X_CHART_IDS value) { // string result = NULL; // switch (value) { // case X_TO: result = "XTO"; break; // case X_FROM: result = "XFROM"; break; // case X_UPPER: result = "XUPPER"; break; // case X_LOWER: result = "XLOWER"; break; // case X_TP: result = "XTP"; break; // case X_SL: result = "XSL"; break; // case X_ENTRY: result = "XENTRY"; break; } // 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 ... // }; // // Draw Bar ... class XCBarArrow : public XCBaseObject { // public: // // // Constructors ... void XCBarArrow() { } // // Deconstructors ... void ~XCBarArrow() { } /** * Create XCBarArrow ... * * @param chart_id: Long ... * @param name: String ... * @param window: Integer ... * * @return ( bool ) */ bool Create( long chart_id, const string name, const int window, XOHCL &bar, ENUM_X_PRICE priceType, int arrow // ) { // bool result = false; // result = bar.IsValid() && IsValid(name); if (!result) { return result; } // double time = bar.time; double price = bar.GetPrice(priceType); // result = mArrow.Create( chart_id, name, window, time, price, (char)arrow // ); if (!result) { return result; } // // Set Object Name ... ObjName(name); // return result; } /** * Retrieve Object Type ... * * @return ( ENUM_XCHARTOBJECTS ) */ virtual ENUM_XCHARTOBJECTS Type() { return X_BAR_ARROW; } /** * 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); } // protected: // // private: // CChartObjectArrow mArrow; // }; // // From To Chart Object ... class XCFromToObject : public XCBaseObject { // public: // // // Constructors ... void XCFromToObject() { } // // Deconstructors ... void ~XCFromToObject() { } /** * Create XCFromToObject ... * * @param chart_id: Long ... * @param name: String ... * @param window: Integer ... * @param time1: DateTime ... * @param time2: DateTime ... * * @return ( bool ) */ bool Create( long chart_id, const string name, const int window, const datetime from, const datetime to // ) { // bool result = false; // string mFromVLineName = ToString(X_FROM) + "_" + name; result = mFromVLine.Create(chart_id, mFromVLineName, window, from); if (!result) { return result; } // string mToVLineName = ToString(X_TO) + "_" + name; result = mToVLine.Create(chart_id, mToVLineName, window, to); if (!result) { return result; } // // Set Object Name ... ObjName(name); // return result; } /** * Retrieve Object Type ... * * @return ( ENUM_XCHARTOBJECTS ) */ virtual ENUM_XCHARTOBJECTS Type() { return X_FROM_TO; } /** * Set From Date Line Color ... * * @param value: Color ... * * @return ( bool ) */ bool FromColor(color value) { return mFromVLine.Color(value); } /** * Set From Date Line Style ... * * @param value: ENUM_LINE_STYLE ... * * @return ( bool ) */ bool FromStyle(ENUM_LINE_STYLE value) { return mFromVLine.Style(value); } /** * Set To Date Line Color ... * * @param value: Color ... * * @return ( bool ) */ bool ToColor(color value) { return mToVLine.Color(value); } /** * Set To Date Line Style ... * * @param value: ENUM_LINE_STYLE ... * * @return ( bool ) */ bool ToStyle(ENUM_LINE_STYLE value) { return mToVLine.Style(value); } // protected: // // private: // CChartObjectVLine mFromVLine; CChartObjectVLine mToVLine; // }; // // Zone Chart Object ... class XCZoneObject : public XCBaseObject { // public: // // // Constructors ... void XCZoneObject() { } // // Deconstructors ... void ~XCZoneObject() { } /** * Create XCZoneObject ... * * @param chart_id: Long ... * @param name: String ... * @param window: Integer ... * @param time1: DateTime ... * @param time2: DateTime ... * @param upperPrice1: Double ... * @param upperPrice2: Double ... * @param lowerPrice1: Double ... * @param lowerPrice2: Double ... * @param objprefix: String ... * @param forceRect: Boolean ... * * @return ( bool ) */ bool Create( long chart_id, const string name, const int window, const datetime time1, const datetime time2, const double upperPrice1, const double upperPrice2, const double lowerPrice1, const double lowerPrice2, const string objprefix = NULL, const bool forceRect = false // ) { // bool result = false; // // Validate Args ... result = IsValid(name) && IsValid(time1); if (!result) { return result; } // NormalizeTime(time2); // result = time1 < time2; if (!result) { return result; } // string prefix = !IsValid(objprefix) ? "" : objprefix + "_"; // // Check Params For Rectangle ... bool canDrawRect = forceRect && upperPrice1 == upperPrice2 && lowerPrice1 == lowerPrice1; // // Draw Rectangle ... if (canDrawRect) { // result = mRect.Create( chart_id, name, window, time1, upperPrice1, time2, lowerPrice1 // ); } // // Draw as Trend Line ... else { // // Upper Bound ... // string upperName = prefix + ToString(X_UPPER) + "_" + name; // result = mUpperTrend.Create( chart_id, upperName, window, time1, upperPrice1, time2, upperPrice2 // ); if (!result) { return result; } // // Lower Bound ... // string lowerName = prefix + ToString(X_LOWER) + "_" + name; // result = mLowerTrend.Create( chart_id, lowerName, window, time1, lowerPrice1, time2, lowerPrice2 // ); if (!result) { // mUpperTrend.Delete(); return result; } } // if (result) { ObjName(name); } // return result; } /** * Create XCZoneObject by Providing a XZone ... * * @param chart_id: Long ... * @param name: String ... * @param window: Integer ... * @param time1: DateTime ... * @param time2: DateTime ... * @param zone: XZone instance ... * @param objprefix: String ... * @param forceRect: Boolean ... * * @return ( bool ) */ bool CreateByZone( long chart_id, const string name, const int window, const XZone &zone, const string objprefix = NULL, const bool forceRect = false // ) { // bool result = false; // XZone tmpZone = zone; result = IsValid(name) && tmpZone.IsValid(); if (!result) { return result; } // result = Create( chart_id, name, window, zone.from, zone.to, zone.upper, zone.upper, zone.lower, zone.lower, objprefix, forceRect // ); // return result; } /** * Retrieve Object Type ... * * @return ( ENUM_XCHARTOBJECTS ) */ virtual ENUM_XCHARTOBJECTS Type() { return X_ZONE; } /** * Set Zone Line Width ... * * @param value: Integer ... */ void ZoneWidth(int value) { // if (value < 1) { value = 1; } // mRect.Width(value); mUpperTrend.Width(value); mLowerTrend.Width(value); } /** * Set Zone Color ... * * @param value: Color ... */ void ZoneColor(color value) { // mRect.Color(value); mUpperTrend.Color(value); mLowerTrend.Color(value); } /** * Set Zone Line Style ... * * @param value: ENUM_LINE_STYLE member ... */ void ZoneStyle(ENUM_LINE_STYLE value) { // mRect.Style(value); mUpperTrend.Style(value); mLowerTrend.Style(value); } // protected: // // private: // CChartObjectTrend mUpperTrend; CChartObjectTrend mLowerTrend; CChartObjectRectangle mRect; // }; // // Structured Chart Object ... // // 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 ... * * @return ( bool ) */ bool Create( long chart_id, const string name, const int window, XSignal &signal // ) { // bool result = false; // result = IsValid(name) && signal .IsValid(); if (!result) { return result; } // int delay = (PeriodSeconds(signal.period) * 2); datetime time1 = (datetime)((int)signal.time - delay); datetime time2 = (datetime)((int)signal.time + delay); // // TP ... string tpName = ToString(X_TP) + "_" + name; result = mTPTrend.Create( chart_id, tpName, window, time1, signal.tp, time2, signal.tp // ); if (!result) { return result; } // // SL ... string slName = ToString(X_SL) + "_" + name; result = mSLTrend.Create( chart_id, slName, window, time1, signal.sl, time2, signal.sl // ); if (!result) { // mTPTrend.Delete(); return result; } // // ENTRY ... string entrName = ToString(X_ENTRY) + "_" + name; result = mEntryTrend.Create( chart_id, entrName, window, time1, signal.entry, time2, signal.entry // ); if (!result) { // mTPTrend.Delete(); mSLTrend.Delete(); return result; } // 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); } // // 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; } // private: // // CChartObjectTrend mTPTrend; CChartObjectTrend mSLTrend; CChartObjectTrend mEntryTrend; }; // // XTradeDay Object ... class XCTardeDayObject : public XCFromToObject { // public: // // // Constructors ... void XCTardeDayObject() { } // // Deconstructors ... void ~XCTardeDayObject() { } /** * Create Object Based on Given Structure ... * * @param chart_id: Long ... * @param name: String ... * @param window: Integer ... * @param day: XTradeDay instance ... * * @return ( bool ) */ bool CreateByDay( long chart_id, const string name, const int window, XTradeDay &day // ) { // bool result = false; // result = Create( chart_id, name, window, day.from, day.to // ); // return result; } /** * Retrieve Object Type ... * * @return ( ENUM_XCHARTOBJECTS ) */ virtual ENUM_XCHARTOBJECTS Type() { return X_TRADE_DAY; } // protected: // // private: // // }; // // XMarketSession Object ... class XCMarketSessionObject : public XCFromToObject { // public: // // // Constructors ... void XCMarketSessionObject() { } // // Deconstructors ... void ~XCMarketSessionObject() { } /** * Create Object Based on Given Structure ... * * @param chart_id: Long ... * @param name: String ... * @param window: Integer ... * @param session: XMarketSession instance ... * * @return ( bool ) */ bool CreateByMarketSession( long chart_id, const string name, const int window, XMarketSession &session // ) { // bool result = false; // result = Create( chart_id, name, window, session.from, session.to // ); // return result; } /** * Retrieve Object Type ... * * @return ( ENUM_XCHARTOBJECTS ) */ virtual ENUM_XCHARTOBJECTS Type() { return X_MARKET_SESSION; } // protected: // // private: // // }; // class XCSwingHighObject : public // // Support Zone ... class XCSupportZoneObject : public XCZoneObject { // public: // // // Constructors ... void XCSupportZoneObject() { } // // Deconstructors ... void ~XCSupportZoneObject() { } /** * Draw Support Zone Object by Providing Support Zone ... * * @param chart_id: Long ... * @param name: String ... * @param window: Integer ... * @param support: XOHCL instance ... * @param time2: DateTime ... * @param forceRect: Boolean ... * * @return ( bool ) */ bool CreateBySupport( long chart_id, const string name, const int window, const XOHCL &support, const datetime time2, const bool forceRect = false // ) { // bool result = false; // XOHCL tmpSupport = support; result = tmpSupport.IsValid(); if (!result) { return result; } // double bottom = tmpSupport.GetDown(); // result = Create( chart_id, name, window, support.time, time2, bottom, bottom, support.low, support.low, NULL, forceRect // ); // return result; } /** * Retrieve Object Type ... * * @return ( ENUM_XCHARTOBJECTS ) */ virtual ENUM_XCHARTOBJECTS Type() { return X_SUPPORT_ZONE; } // }; // // Resistance Zone ... class XCResistanceZoneObject : public XCZoneObject { // public: // // // Constructors ... void XCResistanceZoneObject() { } // // Deconstructors ... void ~XCResistanceZoneObject() { } /** * Draw Resistance Zone Object by Providing Resistance Zone ... * * @param chart_id: Long ... * @param name: String ... * @param window: Integer ... * @param resistance: XOHCL instance ... * @param time2: DateTime ... * @param forceRect: Boolean ... * * @return ( bool ) */ bool CreateByResistance( long chart_id, const string name, const int window, const XOHCL &resistance, const datetime time2, const bool forceRect = false // ) { // bool result = false; // XOHCL tmpResistance = resistance; result = tmpResistance.IsValid(); if (!result) { return result; } // double up = tmpResistance.GetUp(); // result = Create( chart_id, name, window, resistance.time, time2, resistance.high, resistance.high, up, up, NULL, forceRect // ); // return result; } /** * Retrieve Object Type ... * * @return ( ENUM_XCHARTOBJECTS ) */ virtual ENUM_XCHARTOBJECTS Type() { return X_RESISTANCE_ZONE; } // }; // // Supply Zone ... class XCSupplyZoneObject : public XCZoneObject { // public: // // // Constructors ... void XCSupplyZoneObject() { } // // Deconstructors ... void ~XCSupplyZoneObject() { } /** * Retrieve Object Type ... * * @return ( ENUM_XCHARTOBJECTS ) */ virtual ENUM_XCHARTOBJECTS Type() { return X_SUPPLY_ZONE; } // }; // // Demand Zone ... class XCDemandZoneObject : public XCZoneObject { // public: // // // Constructors ... void XCDemandZoneObject() { } // // Deconstructors ... void ~XCDemandZoneObject() { } /** * Retrieve Object Type ... * * @return ( ENUM_XCHARTOBJECTS ) */ virtual ENUM_XCHARTOBJECTS Type() { return X_DEMAND_ZONE; } // }; // // Bullish Order Block ... class XCBullishOrderBlockObject : public XCZoneObject { // public: // // // Constructors ... void XCBullishOrderBlockObject() { } // // Deconstructors ... void ~XCBullishOrderBlockObject() { } /** * Retrieve Object Type ... * * @return ( ENUM_XCHARTOBJECTS ) */ virtual ENUM_XCHARTOBJECTS Type() { return X_BULLISH_ORDERBLOCK; } // }; // // Bearish Order Block ... class XCBearishOrderBlockObject : public XCZoneObject { // public: // // // Constructors ... void XCBearishOrderBlockObject() { } // // Deconstructors ... void ~XCBearishOrderBlockObject() { } /** * Retrieve Object Type ... * * @return ( ENUM_XCHARTOBJECTS ) */ virtual ENUM_XCHARTOBJECTS Type() { return X_BEARISH_ORDERBLOCK; } // }; // // Bullish FVG ... class XCBullishFVGObject : public XCZoneObject { // public: // // // Constructors ... void XCBullishFVGObject() { } // // Deconstructors ... void ~XCBullishFVGObject() { } /** * Retrieve Object Type ... * * @return ( ENUM_XCHARTOBJECTS ) */ virtual ENUM_XCHARTOBJECTS Type() { return X_BULLISH_FVG; } // }; // // Bearish FVG ... class XCBearishFVGObject : public XCZoneObject { // public: // // // Constructors ... void XCBearishFVGObject() { } // // Deconstructors ... void ~XCBearishFVGObject() { } /** * Retrieve Object Type ... * * @return ( ENUM_XCHARTOBJECTS ) */ virtual ENUM_XCHARTOBJECTS Type() { return X_BEARISH_FVG; } // }; //