/////////////////////////////////////////////////////// // // 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-pivot.analysis.lib.mq5" #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_EMPTY_OBJ = 7860, // Empty X_BOX_OBJ = 7861, // XBox X_BAR_ARROW_OBJ = 7862, // XBarArrow X_SIGNAL_OBJ = 8860, // XSignal X_OHCL_OBJ = 8863, // XBar X_RR_OBJ = 8864, // XRR X_PIVOT_OBJ = 8865, // XPivot // // 9860 Custom Object ... }; enum ENUM_X_CHART_IDS { X_AT, // AT X_TO, // TO X_FROM, // FROM X_UPPER, // UPPER X_LOWER, // LOWER X_ENTRY, // ENTRY X_TARGET, // TARGET X_SL, // SL X_TP, // TP X_BAR_H_SHW, // HSHW X_BAR_BDY, // BODY X_BAR_L_SHW, // LSHW }; string ToString(ENUM_X_CHART_IDS value) { // string result = NULL; // result = EnumToString(value); // return result; } string ToXString(ENUM_XCHARTOBJECTS value) { // return EnumToString(value); } struct XPOIStyle { // // Properties ... int width; // Width ... color clr; // Color ... bool fill; // Fill, Use in Rectangles ... ENUM_LINE_STYLE style; // Line Style ... // // Constructor ... XPOIStyle() { Default(); } // // Tools ... // // Cleanup Model ... void Clean() { // width = 1; fill = false; clr = CLR_NONE; style = STYLE_SOLID; // ZeroMemory(this); } // // Default Props ... void Default() { // width = 1; fill = false; clr = CLR_NONE; style = STYLE_SOLID; } }; // // 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) { // Name(value); mObjName = value; } virtual string TypeString() { return ToXString(X_EMPTY_OBJ); } /** * Retrieve Object Type ... * * @return ( ENUM_XCHARTOBJECTS ) */ virtual int Type(void) const { return ((int)X_EMPTY_OBJ); } /** * Destroy ... */ void virtual Destroy() { // Detach(); Delete(); } // private: // // // Props ... string mObjName; // Object Specified Name ... // }; // // Bar Arrow Object ... 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 ... /** * Destroy ... */ void virtual Destroy() { // mArrow.Detach(); mArrow.Delete(); // Detach(); Delete(); } /** * Retrieve Object Type ... * * @return ( ENUM_XCHARTOBJECTS ) */ virtual int Type(void) { return (int)X_BAR_ARROW_OBJ; } /** * Type as String ... **/ string TypeString() override { return ToXString(X_BAR_ARROW_OBJ); } // // 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; // }; // // 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) + "_" + ToXString(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; } // // Virtual ... /** * Destroy ... */ void virtual Destroy() { // mTPTrend.Detach(); mTPTrend.Delete(); mSLTrend.Detach(); mSLTrend.Delete(); mEntryTrend.Detach(); mEntryTrend.Delete(); // mTargetTrends.Clear(); // Detach(); Delete(); } /** * Retrieve Object Type ... * * @return ( ENUM_XCHARTOBJECTS ) */ virtual int Type(void) { return (int)X_SIGNAL_OBJ; } /** * Type as String ... **/ string TypeString() override { return ToXString(X_SIGNAL_OBJ); } // // 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); } // 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; } /** * Retrieve Object Type ... * * @return ( ENUM_XCHARTOBJECTS ) */ virtual int Type(void) { return (int)X_RR_OBJ; } /** * Type as String ... **/ string TypeString() override { return ToXString(X_RR_OBJ); } }; // // OHCL, Bar Object ... 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; } // // Virtual ... /** * Destroy ... */ void virtual Destroy() { // mBodyRect.Detach(); mBodyRect.Delete(); // mLowShadowRect.Detach(); mLowShadowRect.Delete(); // mHighShadowRect.Detach(); mHighShadowRect.Delete(); // Detach(); Delete(); } /** * Retrieve Object Type ... * * @return ( ENUM_XCHARTOBJECTS ) */ virtual int Type(void) { return (int)X_OHCL_OBJ; } /** * Type as String ... **/ string TypeString() override { return ToXString(X_OHCL_OBJ); } // // 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); } // private: // // // Props ... CChartObjectRectangle mHighShadowRect; CChartObjectRectangle mBodyRect; CChartObjectRectangle mLowShadowRect; }; // // Box Object ...k 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, datetime at = NULL, 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) { // if (IsValid(at)) { // result = mAt.Create( chart_id, name + ToString(X_AT), window, at // ); } // if (!result) { // mAt.Detach(); mAt.Delete(); // mRect.Detach(); mRect.Delete(); } } // if (result) { ObjName(name); } // return result; } // // Virtual ... /** * Destroy ... */ void virtual Destroy() { // mAt.Detach(); mAt.Delete(); // mRect.Detach(); mRect.Delete(); // Detach(); Delete(); } /** * Retrieve Object Type ... * * @return ( ENUM_XCHARTOBJECTS ) */ virtual int Type(void) { return (int)X_BOX_OBJ; } /** * Type as String ... **/ string TypeString() override { return ToXString(X_BOX_OBJ); } // // Getter(s) / Setter(s) ... /** * Set Width ... * * @param value: Integer ... */ void BoxWidth(int value) { // if (value < 1) { value = 1; } // mAt.Width(value); mRect.Width(value); } /** * Set Color ... * * @param value: Color ... */ void BoxColor(color value) { // mAt.Color(value); mRect.Color(value); } /** * Set Style ... * * @param value: ENUM_LINE_STYLE member ... */ void BoxStyle(ENUM_LINE_STYLE value) { // mAt.Style(value); mRect.Style(value); } /** * Set Fill ... * * @param value: Boolean ... */ void BoxFill(bool value) { mRect.Fill(value); } // private: // // // Props ... CChartObjectVLine mAt; CChartObjectRectangle mRect; }; /** * XPivotAnalysis Chart Object ... **/ class XCPivotAnalysisObject : public XCBaseObject { // public: // /** * Create Object ... * * @param chart_id: Long, Specified Chart ID ... * @param window: Integer, Specified Chart Window ID ... * @param model: XPivotAnalysis, reference model ... * @param drawTrends: Specified to Draw Trends or not ... * @param drawZones: Specified to Draw Support and Resistance Zones or not ... * @param drawPivots: Specified to Draw Pivots or not ... * @param peakArrow: int, Specified Arrow Code for Peak Pivots ... * @param valeArrow: int, Specified Arrow Code for Vale Pivots ... * @param threshold: int, distance between price and arrow in Point ... * * @return ( bool ) */ bool Create( long chart_id, int window, XPivotAnalysis &model, bool drawTrends = true, bool drawZones = true, bool drawPivots = true, int peakArrow = 159, int valeArrow = 159, int threshold = 5 // ) { // bool result = false; // bool has = false; // // Validate ... result = model.IsValid(); if (!result) { return result; } // // Generate Object ID ... string objID = model.GetObjectID(); // // Draw Trend Lines ... mUpper = NULL; mLower = NULL; if (drawTrends) { // string upperName = model.GetUpperObjectID(); string lowerName = model.GetLowerObjectID(); // RemoveObjects(upperName, chart_id, window); RemoveObjects(lowerName, chart_id, window); // // Creating Upper ... mUpper = new CChartObjectTrend(); result = mUpper.Create( chart_id, upperName, window, model.fromTime, model.peakFrom, model.toTime, model.peakTo // ); if (!result) { // // Destroy Trending Objects ... DestroyObject(mUpper); DestroyObject(mLower); // return result; } // // Create Lower ... mLower = new CChartObjectTrend(); result = mLower.Create( chart_id, lowerName, window, model.fromTime, model.valeFrom, model.toTime, model.valeTo // ); if (!result) { // // Destroy Trending Objects ... DestroyObject(mUpper); DestroyObject(mLower); // return result; } } // // Draw Zones ... mSupportBox = NULL; mResistanceBox = NULL; if (drawZones) { // // Support ... XBoxZone tmpBox; has = model.HasSupportBox(tmpBox); if (has) { // datetime to = TimeCurrent(); string name = model.GetSupportBoxObjectID(); RemoveObjects(name, chart_id, window); mSupportBox = new XCBoxObject(); result = mSupportBox.Create( chart_id, window, name, tmpBox.upper, tmpBox.lower, tmpBox.from, to // ); if (!result) { // DestroyObject(mUpper); DestroyObject(mLower); DestroyObject(mSupportBox); // return result; } } // // Resistance ... tmpBox.Clean(); has = model.HasResistanceBox(tmpBox); if (has) { // datetime to = TimeCurrent(); string name = model.GetResistanceBoxObjectID(); RemoveObjects(name, chart_id, window); mResistanceBox = new XCBoxObject(); result = mResistanceBox.Create( chart_id, window, name, tmpBox.upper, tmpBox.lower, tmpBox.from, to // ); if (!result) { // DestroyObject(mUpper); DestroyObject(mLower); DestroyObject(mSupportBox); DestroyObject(mResistanceBox); // return result; } } } // // Draw Pivots ... if (drawPivots && model.HasPivots()) { // XOHCL iBar; int arrow = 0; string name = NULL; XCBarArrowObject *iObj; ENUM_X_PRICE type = X_PRICE_NONE; int pivotsCount = ArraySize(model.pivots); for (int i = 0; i < pivotsCount; i++) { // has = model.pivots[i].GetBar(iBar); if (!has) { continue; } // arrow = model.pivots[i].IsPeak() ? peakArrow : valeArrow; name = model.pivots[i].GetObjectID(); RemoveObjects(name, chart_id, window); type = model.pivots[i].IsPeak() ? X_PRICE_HIGH : X_PRICE_LOW; iObj = new XCBarArrowObject(); has = iObj.CreateByBar( chart_id, name, window, arrow, iBar, type, threshold // ); if (has) { // if (model.pivots[i].IsPeak()) { // if (mPeaks == NULL) { mPeaks = new CArrayObj(); } // mPeaks.Add(iObj); } else { // if (mVales == NULL) { mVales = new CArrayObj(); } // mVales.Add(iObj); } } // iBar.Clean(); ZeroMemory(iObj); } // // Cleanup Resources ... iBar.Clean(); ZeroMemory(iObj); } // // Setting Object Name ... if (result) { ObjName(objID); } // return result; } // // Virtuals ... /** * Retrieve Object Type ... * * @return ( ENUM_XCHARTOBJECTS ) */ virtual int Type(void) { return (int)X_PIVOT_OBJ; } /** * Type as String ... **/ string TypeString() override { return ToXString(X_PIVOT_OBJ); } /** * Destroy ... */ void virtual Destroy() { // DestroyObjects(mPeaks); DestroyObjects(mVales); // DestroyObject(mUpper); DestroyObject(mLower); DestroyObject(mSupportBox); DestroyObject(mResistanceBox); // delete mPeaks; delete mVales; delete mUpper; delete mLower; delete mSupportBox; delete mResistanceBox; // ZeroMemory(mPeaks); ZeroMemory(mVales); ZeroMemory(mUpper); ZeroMemory(mLower); ZeroMemory(mSupportBox); ZeroMemory(mResistanceBox); // Detach(); Delete(); } // // Styling ... /** * Set Width ... * * @param value: Integer ... */ void UpperWidth(int value) { // if (value < 1) { value = 1; } // if (mUpper == NULL) { return; } // mUpper.Width(value); } /** * Set Color ... * * @param value: Color ... */ void UpperColor(color value) { // if (mUpper == NULL) { return; } // mUpper.Color(value); } /** * Set Style ... * * @param value: ENUM_LINE_STYLE member ... */ void UpperStyle(ENUM_LINE_STYLE value) { // if (mUpper == NULL) { return; } // mUpper.Style(value); } /** * Specified Upper Ray to Left or not ... * * @param value: bool */ void UpperRayLeft(bool value) { // if (mUpper == NULL) { return; } // mUpper.RayLeft(value); } /** * Specified Upper Ray to Right or not ... * * @param value: bool */ void UpperRayRight(bool value) { // if (mUpper == NULL) { return; } // mUpper.RayRight(value); } /** * Set Width ... * * @param value: Integer ... */ void LowerWidth(int value) { // if (value < 1) { value = 1; } // if (mLower == NULL) { return; } // mLower.Width(value); } /** * Set Color ... * * @param value: Color ... */ void LowerColor(color value) { // if (mLower == NULL) { return; } // mLower.Color(value); } /** * Set Style ... * * @param value: ENUM_LINE_STYLE member ... */ void LowerStyle(ENUM_LINE_STYLE value) { // if (mLower == NULL) { return; } // mLower.Style(value); } /** * Specified Lower Ray to Left or not ... * * @param value: bool */ void LowerRayLeft(bool value) { // if (mLower == NULL) { return; } // mLower.RayLeft(value); } /** * Specified Lower Ray to Right or not ... * * @param value: bool */ void LowerRayRight(bool value) { // if (mLower == NULL) { return; } // mLower.RayRight(value); } /** * Set Width ... * * @param value: Integer ... */ void SupportWidth(int value) { // if (value < 1) { value = 1; } // if (mSupportBox == NULL) { return; } // mSupportBox.BoxWidth(value); } /** * Set Color ... * * @param value: Color ... */ void SupportColor(color value) { // if (mSupportBox == NULL) { return; } // mSupportBox.BoxColor(value); } /** * Set Style ... * * @param value: ENUM_LINE_STYLE member ... */ void SupportStyle(ENUM_LINE_STYLE value) { // if (mSupportBox == NULL) { return; } // mSupportBox.BoxStyle(value); } /** * Set Width ... * * @param value: Integer ... */ void ResistanceWidth(int value) { // if (value < 1) { value = 1; } // if (mResistanceBox == NULL) { return; } // mResistanceBox.BoxWidth(value); } /** * Set Color ... * * @param value: Color ... */ void ResistanceColor(color value) { // if (mResistanceBox == NULL) { return; } // mResistanceBox.BoxColor(value); } /** * Set Style ... * * @param value: ENUM_LINE_STYLE member ... */ void ResistanceStyle(ENUM_LINE_STYLE value) { // if (mResistanceBox == NULL) { return; } // mResistanceBox.BoxStyle(value); } /** * Set Width ... * * @param value: Integer ... */ void PeaksWidth(int value) { // if (mPeaks == NULL) { return; } // // Normalize ... value = NormalizeInt(value, 1); // // Validate ... int count = mPeaks.Total(); bool has = IsValidSize(count); if (!has) { return; } // XCBarArrowObject *iPeak; for (int i = 0; i < count; i++) { // iPeak = (XCBarArrowObject *)mPeaks.At(i); iPeak.ArrowWidth(value); ZeroMemory(iPeak); } } /** * Set Color ... * * @param value: Color ... */ void PeaksColor(color value) { // if (mPeaks == NULL) { return; } // // Validate ... int count = mPeaks.Total(); bool has = IsValidSize(count); if (!has) { return; } // XCBarArrowObject *iPeak; for (int i = 0; i < count; i++) { // iPeak = (XCBarArrowObject *)mPeaks.At(i); iPeak.ArrowColor(value); ZeroMemory(iPeak); } } /** * Set Arrow Anchor ... * * @param value: ENUM_ARROW_ANCHOR member ... */ void PeaksAnchor(ENUM_ARROW_ANCHOR value) { // if (mPeaks == NULL) { return; } // // Validate ... int count = mPeaks.Total(); bool has = IsValidSize(count); if (!has) { return; } // XCBarArrowObject *iPeak; for (int i = 0; i < count; i++) { // iPeak = (XCBarArrowObject *)mPeaks.At(i); iPeak.ArrowAnchor(value); ZeroMemory(iPeak); } } /** * Set Width ... * * @param value: Integer ... */ void ValesWidth(int value) { // if (mVales == NULL) { return; } // // Normalize ... value = NormalizeInt(value, 1); // // Validate ... int count = mVales.Total(); bool has = IsValidSize(count); if (!has) { return; } // XCBarArrowObject *iVale; for (int i = 0; i < count; i++) { // iVale = (XCBarArrowObject *)mVales.At(i); iVale.ArrowWidth(value); ZeroMemory(iVale); } } /** * Set Color ... * * @param value: Color ... */ void ValesColor(color value) { // if (mVales == NULL) { return; } // // Validate ... int count = mVales.Total(); bool has = IsValidSize(count); if (!has) { return; } // XCBarArrowObject *iVale; for (int i = 0; i < count; i++) { // iVale = (XCBarArrowObject *)mVales.At(i); iVale.ArrowColor(value); ZeroMemory(iVale); } } /** * Set Arrow Anchor ... * * @param value: ENUM_ARROW_ANCHOR member ... */ void ValesAnchor(ENUM_ARROW_ANCHOR value) { // if (mVales == NULL) { return; } // // Validate ... int count = mVales.Total(); bool has = IsValidSize(count); if (!has) { return; } // XCBarArrowObject *iVale; for (int i = 0; i < count; i++) { // iVale = (XCBarArrowObject *)mVales.At(i); iVale.ArrowAnchor(value); ZeroMemory(iVale); } } // private: // CArrayObj *mPeaks; CArrayObj *mVales; CChartObjectTrend *mUpper; CChartObjectTrend *mLower; XCBoxObject *mSupportBox; XCBoxObject *mResistanceBox; }; // // Extensions ... /** * Add all Items of Specified CArrayObj into another ... * * @param source: CArrayObj, pointer refrence Specified Data Source ... * @param dest: CArrayObj, pointer refrence Specified Destination of Adding ... */ 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)); } } /** * Destroy Object if Exists ... * * @param object: pointer refrence to Destroy ... */ void DestroyObject(XCBoxObject *&object) { // // Validate ... bool has = object != NULL; if (!has) { return; } // object.Destroy(); // object.Detach(); object.Delete(); // delete object; ZeroMemory(object); } /** * Destroy Object if Exists ... * * @param object: pointer refrence to Destroy ... */ void DestroyObject(XCPivotAnalysisObject *&object) { // // Validate ... bool has = object != NULL; if (!has) { return; } // object.Destroy(); // object.Detach(); object.Delete(); // delete object; ZeroMemory(object); } /** * Destroy Object if Exists ... * * @param object: pointer refrence to Destroy ... */ void DestroyObject(CChartObjectTrend *&object) { // // Validate ... bool has = object != NULL; if (!has) { return; } // object.Detach(); object.Delete(); // delete object; ZeroMemory(object); } /** * Completely Destroy all Chart Objects ... * * @param objects: CArrayObj, pointer refrence Specified Data Source ... */ void DestroyObjects(CArrayObj *&objects) { // // Validate Exists ... if (objects == NULL) { return; } // // Count Childs ... int count = objects.Total(); if (!IsValidSize(count)) { return; } // // Destroy all Childs ... for (int i = 0; i < count; i++) { // // Checking Types ... int iType = ((CChartObject *)objects.At(i)).Type(); // string iTypeStr = NULL; if (iType == X_EMPTY_OBJ) { // XCBaseObject *iObj = (XCBaseObject *)objects.At(i); iTypeStr = iObj.TypeString(); // if (iTypeStr == ToXString(X_BOX_OBJ)) { iType = X_BOX_OBJ; } else if (iTypeStr == ToXString(X_BAR_ARROW_OBJ)) { iType = X_BAR_ARROW_OBJ; } else if (iTypeStr == ToXString(X_SIGNAL_OBJ)) { iType = X_SIGNAL_OBJ; } else if (iTypeStr == ToXString(X_OHCL_OBJ)) { iType = X_OHCL_OBJ; } else if (iTypeStr == ToXString(X_RR_OBJ)) { iType = X_RR_OBJ; } else if (iTypeStr == ToXString(X_PIVOT_OBJ)) { iType = X_PIVOT_OBJ; } } // string iName = ((CChartObject *)objects.At(i)).Name(); if (!IsSpecifiedValid(iName)) { iName = ((XCBaseObject *)objects.At(i)).ObjName(); } // switch (iType) { // case X_RR_OBJ: { // XCRRObject *iObj = (XCRRObject *)objects.At(i); iObj.Destroy(); // delete iObj; ZeroMemory(iObj); } break; case X_BOX_OBJ: { // XCBoxObject *iObj = (XCBoxObject *)objects.At(i); iObj.Destroy(); iObj.Detach(); iObj.Delete(); // delete iObj; ZeroMemory(iObj); } break; case X_OHCL_OBJ: { // XCOHCLObject *iObj = (XCOHCLObject *)objects.At(i); iObj.Destroy(); // delete iObj; ZeroMemory(iObj); } break; case X_PIVOT_OBJ: { // XCPivotAnalysisObject *iObj = (XCPivotAnalysisObject *)objects.At(i); iObj.Destroy(); // delete iObj; ZeroMemory(iObj); } break; case X_SIGNAL_OBJ: { // XCSignalObject *iObj = (XCSignalObject *)objects.At(i); iObj.Destroy(); // delete iObj; ZeroMemory(iObj); } break; case X_BAR_ARROW_OBJ: { // XCBarArrowObject *iObj = (XCBarArrowObject *)objects.At(i); iObj.Destroy(); // delete iObj; ZeroMemory(iObj); } break; // // Default Object Types ... case OBJ_VLINE: case OBJ_HLINE: case OBJ_TREND: case OBJ_TRENDBYANGLE: case OBJ_CYCLES: case OBJ_ARROWED_LINE: case OBJ_CHANNEL: case OBJ_STDDEVCHANNEL: case OBJ_REGRESSION: case OBJ_PITCHFORK: case OBJ_GANNLINE: case OBJ_GANNFAN: case OBJ_GANNGRID: case OBJ_FIBO: case OBJ_FIBOTIMES: case OBJ_FIBOFAN: case OBJ_FIBOARC: case OBJ_FIBOCHANNEL: case OBJ_EXPANSION: case OBJ_ELLIOTWAVE5: case OBJ_ELLIOTWAVE3: case OBJ_RECTANGLE: case OBJ_TRIANGLE: case OBJ_ELLIPSE: case OBJ_ARROW_THUMB_UP: case OBJ_ARROW_THUMB_DOWN: case OBJ_ARROW_UP: case OBJ_ARROW_DOWN: case OBJ_ARROW_STOP: case OBJ_ARROW_CHECK: case OBJ_ARROW_LEFT_PRICE: case OBJ_ARROW_RIGHT_PRICE: case OBJ_ARROW_BUY: case OBJ_ARROW_SELL: case OBJ_ARROW: case OBJ_TEXT: case OBJ_LABEL: case OBJ_BUTTON: case OBJ_CHART: case OBJ_BITMAP: case OBJ_BITMAP_LABEL: case OBJ_EDIT: case OBJ_EVENT: case OBJ_RECTANGLE_LABEL: { // CChartObject *iObj = (CChartObject *)objects.At(i); // iObj.Detach(); iObj.Delete(); // delete iObj; ZeroMemory(iObj); } break; } // RemoveObjects(iName); } // // Destroy itSelf ... objects.Clear(); delete objects; ZeroMemory(objects); } /** * Remove Drawn Objects from Chart ... * * @param tag: Specified Object Name, if NULL remove all Objects ... * @param chartId: long, Specified Chart ... * @param subWindow: int Specified Sub Window ... */ void RemoveObjects( string tag = NULL, long chartId = -1, int subWindow = -1 // ) { // // Normalize Args ... // if (chartId == -1) { chartId = 0; } // if (subWindow == -1) { subWindow = 0; } // bool has = false; string iName = NULL; for (int iObj = ObjectsTotal(chartId, subWindow) - 1; iObj >= 0; iObj--) { // // Retrieve Object Name ... iName = ObjectName(chartId, iObj, subWindow); // // Check Can Delete Object or not ... has = !IsSpecifiedValid(tag) ? true : StringFind(iName, tag) >= 0; if (has) { ObjectDelete(chartId, iName); } } // // Redraw Chart ... ChartRedraw(); } //