From bb2aff17a9c01de807f275a5a88b1f57ccf8900e Mon Sep 17 00:00:00 2001 From: Hadi Khazaee Asl Date: Tue, 23 Sep 2025 01:35:39 +0330 Subject: [PATCH] Add Support for Drawing, Styling also Refactor POI Drawer and etc ... --- Classes/x-saherelm.x-cobject.class.mq5 | 9 +- Classes/x-saherelm.x-poi.drawer.class.mq5 | 914 ++++++------- Documents/BKP/tmp.poi.drawer.codes.mq5 | 336 +++++ .../x-saherelm.x-poi.drawer.class copy.mq5 | 1195 +++++++++++++++++ .../BKP}/x-saherelm.x121.xcatb.v1.mq5 | 0 Libraries/x-saherelm.x-poi.lib.mq5 | 42 + 6 files changed, 2005 insertions(+), 491 deletions(-) create mode 100644 Documents/BKP/tmp.poi.drawer.codes.mq5 create mode 100644 Documents/BKP/x-saherelm.x-poi.drawer.class copy.mq5 rename {Indicators => Documents/BKP}/x-saherelm.x121.xcatb.v1.mq5 (100%) diff --git a/Classes/x-saherelm.x-cobject.class.mq5 b/Classes/x-saherelm.x-cobject.class.mq5 index 3fcd7b53..2ac7d50d 100644 --- a/Classes/x-saherelm.x-cobject.class.mq5 +++ b/Classes/x-saherelm.x-cobject.class.mq5 @@ -82,9 +82,10 @@ struct XPOIStyle { // // Properties ... - int width; - color clr; - ENUM_LINE_STYLE style; + int width; // Width ... + color clr; // Color ... + bool fill; // Fill, Use in Rectangles ... + ENUM_LINE_STYLE style; // Line Style ... // // Constructor ... @@ -102,6 +103,7 @@ struct XPOIStyle { // width = 1; + fill = false; clr = CLR_NONE; style = STYLE_SOLID; @@ -115,6 +117,7 @@ struct XPOIStyle { // width = 1; + fill = false; clr = CLR_NONE; style = STYLE_SOLID; } diff --git a/Classes/x-saherelm.x-poi.drawer.class.mq5 b/Classes/x-saherelm.x-poi.drawer.class.mq5 index 2c9391b4..f96c4619 100644 --- a/Classes/x-saherelm.x-poi.drawer.class.mq5 +++ b/Classes/x-saherelm.x-poi.drawer.class.mq5 @@ -23,6 +23,7 @@ // Imports ... #include "../Classes/x-saherelm.base.class.mq5" #include "../Classes/x-saherelm.x-cobject.class.mq5" +#include "../Libraries/x-saherelm.x-pivot.analysis.lib.mq5" #include "../Libraries/x-saherelm.x-poi.extensions.lib.mq5" // @@ -31,6 +32,12 @@ // // 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 // @@ -164,196 +171,6 @@ class XCPOIDrawer : public XCBase 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; - } - // // Virtuals ... @@ -370,17 +187,6 @@ class XCPOIDrawer : public XCBase 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); - // defaultBullishStyle.width = 1; defaultBullishStyle.clr = clrLime; @@ -397,18 +203,18 @@ class XCPOIDrawer : public XCBase } // - // Object Creators ... + // Drawers ... /** - * Create Bar Object ... + * Draw Specified Bar ... * - * @param bar: XOHCL instance Reference ... - * @param object: XCOHCLObject pointer Reference .. - * @param to: Datetime ... + * @param bar: XOHCL, refrence to Specified Bar ... + * @param object: XCOHCLObject, pointer reference for Drawn Object ... + * @param to: datetime, Specified To Time ... * * @return ( bool ) */ - bool CreateBar( + bool DrawBar( XOHCL &bar, XCOHCLObject *&object, datetime to = NULL // @@ -418,44 +224,28 @@ class XCPOIDrawer : public XCBase bool result = false; // + // Prepare ... object = NULL; // + // Validate ... result = bar.IsValid(); if (!result) { return result; } - // - to = NormalizeTime(to); - // string prefix = Prefix(); - long chartID = ChartIdentification(); + ulong 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(); - - // + to = + IsSpecifedValid(to) + ? to + : ((datetime)((int)bar.time) + (PeriodSeconds(bar.period) - 1)); object = new XCOHCLObject(); result = object.Create( - chartID, + chartId, window, bar, to, @@ -464,39 +254,10 @@ class XCPOIDrawer : public XCBase 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); + ApplyBarStyle( + object, + bar // + ); } // @@ -504,140 +265,141 @@ class XCPOIDrawer : public XCBase } /** - * Create Bar Arrow Object ... + * Dar Specified Pivot ... * - * @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 ... + * @param pivot: XPivot, Specified Pivot ... + * @param object: XCBarArrowObject, pointer reference for Drawn Object ... + * @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 CreateBarArrow( - XOHCL &bar, + bool DrawPivot( + XPivot &pivot, XCBarArrowObject *&object, - ENUM_X_PRICE priceType, - int arrow = 159, - color clr = clrYellow, - int width = 3, - ENUM_ARROW_ANCHOR anchor = ANCHOR_BOTTOM, - string name = NULL // + int peakArrow = 159, + int valeArrow = 159, + int threshold = 5 // ) { // bool result = false; // + // Prepare ... object = NULL; // - result = bar.IsValid(); + // Normalize ... + threshold = NormalizeInt(threshold, 5); + peakArrow = NormalizeInt(peakArrow, 159); + valeArrow = NormalizeInt(valeArrow, 159); + + // + // Validate ... + result = pivot.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; + // Get Pivot's Bar ... + XOHCL bar; + result = pivot.GetBar(bar); + if (!result) + { + return result; + } // + int arrow = pivot.IsPeak() + ? peakArrow + : valeArrow; + string name = pivot.GetObjectID(); + ENUM_X_PRICE type = pivot.IsPeak() + ? X_PRICE_HIGH + : X_PRICE_LOW; + XPOIStyle style = pivot.IsPeak() + ? defaultBullishStyle + : defaultBearishStyle; + ENUM_ARROW_ANCHOR anchor = pivot.IsPeak() + ? ANCHOR_BOTTOM + : ANCHOR_TOP; object = new XCBarArrowObject(); - result = object - .CreateByBar( - chartID, - prefix, - window, - arrow, - bar, - priceType // - ); + result = object.CreateByBar( + ChartIdentification(), + name, + SubWindowIdentification(), + arrow, + bar, + type, + threshold // + ); if (result) { // - object.ArrowColor(clr); - object.ArrowWidth(width); + // Apply Styles ... + object.ArrowAnchor(anchor); + ApplyBarArrowStyle( + object, + style // + ); } + // + // Cleanup Resources ... + bar.Clean(); + // return result; } /** - * Create Specific Box on Chart ... + * Draw Specified Box ... * - * @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 ... + * @param object: XCBoxObject, pointer reference for Drawn Object ... + * @param name: Box Name ... + * @param upper: double, Box Upper ... + * @param lower: double, Box Lower ... + * @param from: datetime, From Time ... + * @param to: datetime, To Time ... + * @param at: datetime, Specified At Time ... * * @return ( bool ) */ - bool CreateBox( + bool DrawBox( XCBoxObject *&object, string name, double upper, double lower, datetime from, datetime to, - datetime at, - color clr = clrYellowGreen, - int width = 1, - bool fill = false, - ENUM_LINE_STYLE style = STYLE_SOLID // + datetime at // ) { // bool result = false; // + // Prepare ... object = NULL; // + // Normalize ... to = NormalizeTime(to); + from = NormalizeTime(from); // - string dateStr = ToFormatString(from) + "|" + ToFormatString(to); - string dateMD5 = ToMD5(dateStr); - if (!IsValid(name)) - { - // - name = "XBox_" + - ToXString(upper) + "_" + - ToXString(lower) + "_" + - dateMD5; - } - - // + // Validate ... result = upper > 0 && lower > 0 && to > from && - IsValid(to) && - IsValid(name) && - IsValid(from) && + IsSpecifiedValid(to) && + IsSpecifiedValid(name) && + IsSpecifiedValid(from) && upper > lower; if (!result) { @@ -663,30 +425,16 @@ class XCPOIDrawer : public XCBase prefix // ); - // - if (!result) - { - return result; - } - - // - object.BoxColor(clr); - object.BoxFill(fill); - object.BoxWidth(width); - object.BoxStyle(style); - // return result; } /** - * Create Specific Box on Chart ... + * Draw Specific Box ... * - * @param box: XBoxZone instance Reference ... - * @param clr: Color ... - * @param width: Integer ... - * @param fill: Boolean ... - * @param style: ENUM_LINE_STYLE member ... + * @param box: XBoxZone, Specified Box ... + * @param object: XCBarArrowObject, pointer reference for Drawn Object ... + * @param ignoreAt: bool, Ignore Box at or not ... * * @return ( bool ) */ @@ -700,9 +448,11 @@ class XCPOIDrawer : public XCBase bool result = false; // + // Prepare ... object = NULL; // + // Validate ... result = box.IsValid(); if (!result) { @@ -710,121 +460,53 @@ class XCPOIDrawer : public XCBase } // + datetime at = box.at; if (ignoreAt) { - box.at = NULL; + at = NULL; } // - int width = 1; - bool fill = false; - color clr = - box.IsBullish() - ? defaultBullishStyle.clr - : defaultBearishStyle.clr; - ENUM_LINE_STYLE style = STYLE_DASHDOTDOT; string name = box.GetTag(); - - // - result = CreateBox( + result = DrawBox( object, name, box.upper, box.lower, box.from, box.to, - box.at, - clr, - width, - fill, - style // + at // ); - - // if (result) { // - if (box.IsBullish()) - { - // - ApplyBoxStyle( - object, - boxBullishStyle // - ); - } - else - { - // - ApplyBoxStyle( - object, - boxBearishStyle // - ); - } + // Apply Style ... + XPOIStyle style; + GetBoxStyle( + style, + box.dir // + ); + + // + ApplyBoxStyle( + object, + style // + ); + + // + style.Clean(); } // 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, - box.at, - clr, - width, - fill, - style // - ); - - // - return result; - } - /** * Draw Specified Signal ... * - * @param signal: XSignal instance ... + * @param signal: XSignal, Specified Signal ... + * @param object: XCSignalObject, pointer reference for Drawn Object ... + * @param length: int, Signal Length ... */ bool DrawSignal( XSignal &signal, @@ -896,6 +578,7 @@ class XCPOIDrawer : public XCBase * @param fromTime: datetime, from Time ... * @param toPrice: double, to Price ... * @param toTime: datetime, to Time ... + * @param object: CChartObjectTrend, pointer reference for Drawn Object ... * @param name: Object Name ... * @param rayRight: bool, ray to Right ... * @param rayLeft: boo, ray to Left ... @@ -944,7 +627,20 @@ class XCPOIDrawer : public XCBase toTime, toPrice // ); - if (result) { + if (result) + { + // + ENUM_X_DIRECTION dir = + fromPrice < toPrice + ? X_DIRECTION_BULLISH + : fromPrice > toPrice + ? X_DIRECTION_BEARISH + : X_DIRECTION_NONE; + ApplyTrendLineStyle( + object, + dir // + ); + // object.RayLeft(rayLeft); object.RayRight(rayRight); @@ -959,6 +655,7 @@ class XCPOIDrawer : public XCBase * * @param swings: XOHCL, Specified Swings ... * @param dir: ENUM_X_DIRECTION, Specified Trend Direction ... + * @param object: CChartObjectTrend, pointer reference for Drawn Object ... * @param rayRight: Ray to Right ... * @param rayLeft: Ray to Left ... * @@ -1021,22 +718,14 @@ class XCPOIDrawer : public XCBase if (result) { // - ApplyStyle( + ApplyTrendLineStyle( object, dir // ); // - if (rayRight) - { - object.RayRight(true); - } - - // - if (rayLeft) - { - object.RayLeft(true); - } + object.RayLeft(rayLeft); + object.RayRight(rayRight); } // @@ -1044,7 +733,171 @@ class XCPOIDrawer : public XCBase } /** - * Apply Specified Style to Object ... + * Draw Pivot Analysis ... + * + * @param analysis: XPivotAnalysis, referece Specified Pivot Analysis ... + * + * @return ( bool ) + */ + bool DrawXPivotAnalysis( + XPivotAnalysis &analysis, + XCPivotAnalysisObject *&object // + ) + { + // + bool result = false; + + // + // Prepare ... + object = NULL; + + // + // Normalize ... + + // + // Validate ... + result = analysis.IsValid() && + analysis.IsAnalysed(); + if (!result) + { + return result; + } + + // + object = new XCPivotAnalysisObject(); + result = object.Create( + ChartIdentification(), + SubWindowIdentification(), + analysis // + ); + if (result) + { + // + ApplyPivotAnalysisStyle( + object, + analysis // + ); + } + + // + return result; + } + + // + // Stylers ... + + /** + * Get Specified Style for Specified Direction ... + * + * @param style: XPOIStyle, reference to hold result ... + * @param forDir: ENUM_X_DIRECTION, Specified Direction ... + */ + void GetStyle( + XPOIStyle &style, + ENUM_X_DIRECTION forDir // + ) + { + // + // Prepare ... + style.Clean(); + + // + // Validate ... + if (!HasDirection(forDir)) + { + return; + } + + // + if (IsSpecifiedBullish(forDir)) + { + style = defaultBullishStyle; + } + else + { + style = defaultBearishStyle; + } + } + + /** + * Get Specified Box Style for Specified Direction ... + * + * @param style: XPOIStyle, reference to hold result ... + * @param forDir: ENUM_X_DIRECTION, Specified Direction ... + */ + void GetBoxStyle( + XPOIStyle &style, + ENUM_X_DIRECTION forDir // + ) + { + // + // Prepare ... + style.Clean(); + + // + // Validate ... + if (!HasDirection(forDir)) + { + return; + } + + // + if (IsSpecifiedBullish(forDir)) + { + style = boxBullishStyle; + } + else + { + style = boxBearishStyle; + } + } + + /** + * Apply Specified Style to Specified Object ... + * + * @param object: XCBoxObject, pointer reference of Object ... + * @param bar: XOHCL, Specified Bar ... + * @param fill: boolean, Fill Bar's Body or not ... + */ + void ApplyBarStyle( + XCOHCLObject *&object, + XOHCL &bar, + bool fill = false // + ) + { + // + // Validate ... + bool has = bar.IsValid() && + object != NULL; + if (!has) + { + return result; + } + + // + XPOIStyle style; + GetStyle( + style, + bar.GetDirection() // + ); + + // + object.BarSpes( + style.width, + style.clr, + style.style, + fill // + ); + + // + style.Clean(); + } + + /** + * Apply Specified Style to Specified Object ... + * + * @param object: XCBoxObject, pointer reference of Object ... + * @param style: XPOIStyle, Specifed Style to Apply ... */ void ApplyBoxStyle( XCBoxObject *&object, @@ -1059,13 +912,17 @@ class XCPOIDrawer : public XCBase } // + object.BoxFill(style.fill); object.BoxColor(style.clr); object.BoxWidth(style.width); object.BoxStyle(style.style); } /** - * Apply Specified Style to Object ... + * Apply Specified Style to Specified Object ... + * + * @param object: XCBarArrowObject, pointer reference of Object ... + * @param style: XPOIStyle, Specifed Style to Apply ... */ void ApplyBarArrowStyle( XCBarArrowObject *&object, @@ -1085,37 +942,130 @@ class XCPOIDrawer : public XCBase } /** - * Apply Style to Specified Chart Object ... + * Apply Specified Style to Specified Object ... * - * @param dir: Argument 2 + * @param object: CChartObject, pointer reference of Object ... + * @param forDir: ENUM_X_DIRECTION, Specified Direction ... */ - void ApplyStyle( - CChartObject *object, - ENUM_X_DIRECTION dir // + void ApplyTrendLineStyle( + CChartObjectTrend *&object, + ENUM_X_DIRECTION forDir // ) { // - if (!HasDirection(dir)) + bool has = object != NULL; + if (!has) { return; } // - bool isBullish = IsSpecifiedBullish(dir); - if (isBullish) + if (!HasDirection(forDir)) + { + return; + } + + // + XPOIStyle style; + GetStyle(style, forDir); + + // + object.Color(style.clr); + object.Style(style.style); + object.Width(style.width); + + // + style.Clean(); + } + + /** + * Apply Specified Style to Specified Object ... + * + * @param object: CChartObject, pointer reference of Object ... + * @param model: XPivotAnalysis, referece to access requirements ... + */ + void ApplyPivotAnalysisStyle( + XCPivotAnalysisObject *&object, + XPivotAnalysis &model // + ) + { + // + // Validate ... + bool has = model.IsValid() && + model.IsAnalysed() && + object != NULL; + if (!has) + { + return; + } + + // + XPOIStyle style; + + // + // Support ... + style = defaultBullishStyle; + object.SupportColor(style.clr); + object.SupportWidth(style.width); + object.SupportStyle(style.style); + + // + // Resistance ... + style = defaultBearishStyle; + object.ResistanceColor(style.clr); + object.ResistanceWidth(style.width); + object.ResistanceStyle(style.style); + + // + // Upper ... + if (model.IsPeakAnalysed()) { // - object.Color(boxBullishStyle.clr); - object.Style(boxBullishStyle.style); - object.Width(boxBullishStyle.width); + GetStyle( + style, + model.peakDir // + ); + if (!HasDirection(model.peakDir)) + { + // + style.Default(); + style.clr = clrGray; + } + + // + object.UpperColor(style.clr); + object.UpperWidth(style.width); + object.UpperStyle(style.style); + object.UpperRayLeft(false); + object.UpperRayRight(true); } - else + + // + // Lower ... + if (model.IsValeAnalysed()) { // - object.Color(boxBearishStyle.clr); - object.Style(boxBearishStyle.style); - object.Width(boxBearishStyle.width); + GetStyle( + style, + model.valeDir // + ); + if (!HasDirection(model.valeDir)) + { + // + style.Default(); + style.clr = clrGray; + } + + // + object.LowerColor(style.clr); + object.LowerWidth(style.width); + object.LowerStyle(style.style); + object.UpperRayLeft(false); + object.LowerRayRight(true); } + + // + style.Clean(); } // @@ -1134,17 +1084,5 @@ class XCPOIDrawer : public XCBase 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 ... - // }; \ No newline at end of file diff --git a/Documents/BKP/tmp.poi.drawer.codes.mq5 b/Documents/BKP/tmp.poi.drawer.codes.mq5 new file mode 100644 index 00000000..b6be4fe6 --- /dev/null +++ b/Documents/BKP/tmp.poi.drawer.codes.mq5 @@ -0,0 +1,336 @@ + + /** + * 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, + datetime at, + 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_" + + ToXString(upper) + "_" + + ToXString(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, + at, + 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 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, + box.at, + clr, + width, + fill, + style // + ); + + // + return result; + } diff --git a/Documents/BKP/x-saherelm.x-poi.drawer.class copy.mq5 b/Documents/BKP/x-saherelm.x-poi.drawer.class copy.mq5 new file mode 100644 index 00000000..21fbd78c --- /dev/null +++ b/Documents/BKP/x-saherelm.x-poi.drawer.class copy.mq5 @@ -0,0 +1,1195 @@ +/////////////////////////////////////////////////////// +// +// 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-pivot.analysis.lib.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: + // + // Props ... + + // + XPOIStyle defaultBullishStyle; + XPOIStyle defaultBearishStyle; + + // + XPOIStyle boxBullishStyle; + XPOIStyle boxBearishStyle; + + // + // Constructor ... + void XCPOIDrawer() + { + // + Default(); + } + + // + // Deconstructor ... + void ~XCPOIDrawer() + { + // + boxBullishStyle.Clean(); + boxBearishStyle.Clean(); + defaultBullishStyle.Clean(); + defaultBearishStyle.Clean(); + } + + // + // 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; + } + + // + // 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); + + // + defaultBullishStyle.width = 1; + defaultBullishStyle.clr = clrLime; + defaultBullishStyle.style = STYLE_SOLID; + + // + defaultBearishStyle.width = 1; + defaultBearishStyle.clr = clrRed; + defaultBearishStyle.style = STYLE_SOLID; + + // + boxBullishStyle = defaultBullishStyle; + boxBearishStyle = defaultBearishStyle; + } + + // + // Drawers ... + + /** + * Dar Specified Pivot ... + * + * @param pivot: XPivot, Specified Pivot ... + * @param object: XCBarArrowObject, pointer reference for Drawn Object ... + * @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 DrawPivot( + XPivot &pivot, + XCBarArrowObject *&object, + int peakArrow = 159, + int valeArrow = 159, + int threshold = 5 // + ) + { + // + bool result = false; + + // + // Prepare ... + object = NULL; + + // + // Normalize ... + threshold = NormalizeInt(threshold, 5); + peakArrow = NormalizeInt(peakArrow, 159); + valeArrow = NormalizeInt(valeArrow, 159); + + // + // Validate ... + result = pivot.IsValid(); + if (!result) + { + return result; + } + + // + // Get Pivot's Bar ... + XOHCL bar; + result = pivot.GetBar(bar); + if (!result) + { + return result; + } + + // + int arrow = pivot.IsPeak() + ? peakArrow + : valeArrow; + string name = pivot.GetObjectID(); + ENUM_X_PRICE type = pivot.IsPeak() + ? X_PRICE_HIGH + : X_PRICE_LOW; + XPOIStyle style = pivot.IsPeak() + ? defaultBullishStyle + : defaultBearishStyle; + ENUM_ARROW_ANCHOR anchor = pivot.IsPeak() + ? ANCHOR_BOTTOM + : ANCHOR_TOP; + object = new XCBarArrowObject(); + result = object.CreateByBar( + ChartIdentification(), + name, + SubWindowIdentification(), + arrow, + bar, + type, + threshold // + ); + if (result) + { + // + // Apply Styles ... + object.ArrowAnchor(anchor); + ApplyBarArrowStyle( + object, + style // + ); + } + + // + // Cleanup Resources ... + bar.Clean(); + + // + return result; + } + + /** + * Draw Specified Box ... + * + * @param object: XCBoxObject, pointer reference for Drawn Object ... + * @param name: Box Name ... + * @param upper: double, Box Upper ... + * @param lower: double, Box Lower ... + * @param from: datetime, From Time ... + * @param to: datetime, To Time ... + * @param at: datetime, Specified At Time ... + * + * @return ( bool ) + */ + bool DrawBox( + XCBoxObject *&object, + string name, + double upper, + double lower, + datetime from, + datetime to, + datetime at // + ) + { + // + bool result = false; + + // + // Prepare ... + object = NULL; + + // + // Normalize ... + to = NormalizeTime(to); + from = NormalizeTime(from); + + // + // Validate ... + result = + upper > 0 && + lower > 0 && + to > from && + IsSpecifiedValid(to) && + IsSpecifiedValid(name) && + IsSpecifiedValid(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, + at, + prefix // + ); + + // + return result; + } + + /** + * Draw Specific Box ... + * + * @param box: XBoxZone, Specified Box ... + * @param object: XCBarArrowObject, pointer reference for Drawn Object ... + * @param ignoreAt: bool, Ignore Box at or not ... + * + * @return ( bool ) + */ + bool DrawBox( + XBoxZone &box, + XCBoxObject *&object, + bool ignoreAt = true // + ) + { + // + bool result = false; + + // + // Prepare ... + object = NULL; + + // + // Validate ... + result = box.IsValid(); + if (!result) + { + return result; + } + + // + datetime at = box.at; + if (ignoreAt) + { + at = NULL; + } + + // + string name = box.GetTag(); + result = DrawBox( + object, + name, + box.upper, + box.lower, + box.from, + box.to, + at // + ); + if (result) + { + // + // Apply Style ... + XPOIStyle style; + GetBoxStyle( + style, + box.dir // + ); + + // + ApplyBoxStyle( + object, + style // + ); + + // + style.Clean(); + } + + // + return result; + } + + /** + * Draw Specified Signal ... + * + * @param signal: XSignal, Specified Signal ... + * @param object: XCSignalObject, pointer reference for Drawn Object ... + * @param length: int, Signal Length ... + */ + 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 Specified Trend Line ... + * + * @param fromPrice: double, from Price ... + * @param fromTime: datetime, from Time ... + * @param toPrice: double, to Price ... + * @param toTime: datetime, to Time ... + * @param object: CChartObjectTrend, pointer reference for Drawn Object ... + * @param name: Object Name ... + * @param rayRight: bool, ray to Right ... + * @param rayLeft: boo, ray to Left ... + * + * @return ( bool ) + */ + bool DrawTrendLine( + double fromPrice, + datetime fromTime, + double toPrice, + datetime toTime, + CChartObjectTrend *&object, + string name, + bool rayRight = false, + bool rayLeft = false // + ) + { + // + bool result = false; + + // + // Prepare ... + object = new CChartObjectTrend(); + + // + // Validate ... + result = + toPrice > 0 && + fromPrice > 0 && + IsSpecifiedValid(toTime) && + IsSpecifiedValid(fromTime) && + toTime > fromTime; + if (!result) + { + return result; + } + + // + // Create Object ... + result = object.Create( + ChartIdentification(), + name, + SubWindowIdentification(), + fromTime, + fromPrice, + toTime, + toPrice // + ); + if (result) + { + // + ENUM_X_DIRECTION dir = + fromPrice < toPrice + ? X_DIRECTION_BULLISH + : fromPrice > toPrice + ? X_DIRECTION_BEARISH + : X_DIRECTION_NONE; + ApplyTrendLineStyle( + object, + dir // + ); + + // + object.RayLeft(rayLeft); + object.RayRight(rayRight); + } + + // + return result; + } + + /** + * Draw Trend Line based on Swings Points ... + * + * @param swings: XOHCL, Specified Swings ... + * @param dir: ENUM_X_DIRECTION, Specified Trend Direction ... + * @param object: CChartObjectTrend, pointer reference for Drawn Object ... + * @param rayRight: Ray to Right ... + * @param rayLeft: Ray to Left ... + * + * @return ( bool ) + */ + bool DrawSwingTrend( + XOHCL &swings[], + ENUM_X_DIRECTION dir, + CChartObjectTrend *&object, + bool rayRight = false, + bool rayLeft = false // + ) + { + // + bool result = false; + + // + int count = ArraySize(swings); + result = HasChild(swings) && + count >= 2 && + HasDirection(dir); + if (!result) + { + return result; + } + + // + bool isBullish = IsSpecifiedBullish(dir); + + // + double price1 = + isBullish + ? swings[0].low + : swings[0].high; + datetime time1 = swings[0].time; + + // + double price2 = + isBullish + ? swings[count - 1].low + : swings[count - 1].high; + datetime time2 = swings[count - 1].time; + + // + ulong chartId = ChartIdentification(); + int subWindow = SubWindowIdentification(); + string name = ToXString(dir) + "_Trend_" + ToXString(price1) + "_" + ToXString(price2); + + // + object = new CChartObjectTrend(); + result = object.Create( + chartId, + name, + subWindow, + time1, + price1, + time2, + price2 // + ); + if (result) + { + // + ApplyTrendLineStyle( + object, + dir // + ); + + // + object.RayLeft(rayLeft); + object.RayRight(rayRight); + } + + // + return result; + } + + /** + * Draw Pivot Analysis ... + * + * @param analysis: XPivotAnalysis, referece Specified Pivot Analysis ... + * + * @return ( bool ) + */ + bool DrawXPivotAnalysis( + XPivotAnalysis &analysis, + XCPivotAnalysisObject *&object // + ) + { + // + bool result = false; + + // + // Prepare ... + object = NULL; + + // + // Normalize ... + + // + // Validate ... + result = analysis.IsValid() && + analysis.IsAnalysed(); + if (!result) + { + return result; + } + + // + object = new XCPivotAnalysisObject(); + result = object.Create( + ChartIdentification(), + SubWindowIdentification(), + analysis // + ); + if (result) + { + // + ApplyPivotAnalysisStyle( + object, + analysis // + ); + } + + // + return result; + } + + // + // Stylers ... + + /** + * Get Specified Style for Specified Direction ... + * + * @param style: XPOIStyle, reference to hold result ... + * @param forDir: ENUM_X_DIRECTION, Specified Direction ... + */ + void GetStyle( + XPOIStyle &style, + ENUM_X_DIRECTION forDir // + ) + { + // + // Prepare ... + style.Clean(); + + // + // Validate ... + if (!HasDirection(forDir)) + { + return; + } + + // + if (IsSpecifiedBullish(forDir)) + { + style = defaultBullishStyle; + } + else + { + style = defaultBearishStyle; + } + } + + /** + * Get Specified Box Style for Specified Direction ... + * + * @param style: XPOIStyle, reference to hold result ... + * @param forDir: ENUM_X_DIRECTION, Specified Direction ... + */ + void GetBoxStyle( + XPOIStyle &style, + ENUM_X_DIRECTION forDir // + ) + { + // + // Prepare ... + style.Clean(); + + // + // Validate ... + if (!HasDirection(forDir)) + { + return; + } + + // + if (IsSpecifiedBullish(forDir)) + { + style = boxBullishStyle; + } + else + { + style = boxBearishStyle; + } + } + + /** + * Apply Specified Style to Specified Object ... + * + * @param object: XCBoxObject, pointer reference of Object ... + * @param style: XPOIStyle, Specifed Style to Apply ... + */ + void ApplyBoxStyle( + XCBoxObject *&object, + XPOIStyle &style // + ) + { + // + bool has = object != NULL; + if (!has) + { + return; + } + + // + object.BoxFill(style.fill); + object.BoxColor(style.clr); + object.BoxWidth(style.width); + object.BoxStyle(style.style); + } + + /** + * Apply Specified Style to Specified Object ... + * + * @param object: XCBarArrowObject, pointer reference of Object ... + * @param style: XPOIStyle, Specifed Style to Apply ... + */ + void ApplyBarArrowStyle( + XCBarArrowObject *&object, + XPOIStyle &style // + ) + { + // + bool has = object != NULL; + if (!has) + { + return; + } + + // + object.ArrowColor(style.clr); + object.ArrowWidth(style.width); + } + + /** + * Apply Specified Style to Specified Object ... + * + * @param object: CChartObject, pointer reference of Object ... + * @param forDir: ENUM_X_DIRECTION, Specified Direction ... + */ + void ApplyTrendLineStyle( + CChartObjectTrend *&object, + ENUM_X_DIRECTION forDir // + ) + { + // + bool has = object != NULL; + if (!has) + { + return; + } + + // + if (!HasDirection(forDir)) + { + return; + } + + // + XPOIStyle style; + GetStyle(style, forDir); + + // + object.Color(style.clr); + object.Style(style.style); + object.Width(style.width); + + // + style.Clean(); + } + + /** + * Apply Specified Style to Specified Object ... + * + * @param object: CChartObject, pointer reference of Object ... + * @param model: XPivotAnalysis, referece to access requirements ... + */ + void ApplyPivotAnalysisStyle( + XCPivotAnalysisObject *&object, + XPivotAnalysis &model // + ) + { + // + // Validate ... + bool has = model.IsValid() && + model.IsAnalysed() && + object != NULL; + if (!has) + { + return; + } + + // + XPOIStyle style; + + // + // Support ... + style = defaultBullishStyle; + object.SupportColor(style.clr); + object.SupportWidth(style.width); + object.SupportStyle(style.style); + + // + // Resistance ... + style = defaultBearishStyle; + object.ResistanceColor(style.clr); + object.ResistanceWidth(style.width); + object.ResistanceStyle(style.style); + + // + // Upper ... + if (model.IsPeakAnalysed()) + { + // + GetStyle( + style, + model.peakDir // + ); + if (!HasDirection(model.peakDir)) + { + // + style.Default(); + style.clr = clrGray; + } + + // + object.UpperColor(style.clr); + object.UpperWidth(style.width); + object.UpperStyle(style.style); + object.UpperRayLeft(false); + object.UpperRayRight(true); + } + + // + // Lower ... + if (model.IsValeAnalysed()) + { + // + GetStyle( + style, + model.valeDir // + ); + if (!HasDirection(model.valeDir)) + { + // + style.Default(); + style.clr = clrGray; + } + + // + object.LowerColor(style.clr); + object.LowerWidth(style.width); + object.LowerStyle(style.style); + object.UpperRayLeft(false); + object.LowerRayRight(true); + } + + // + style.Clean(); + } + + // + 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 ... + + // +}; \ No newline at end of file diff --git a/Indicators/x-saherelm.x121.xcatb.v1.mq5 b/Documents/BKP/x-saherelm.x121.xcatb.v1.mq5 similarity index 100% rename from Indicators/x-saherelm.x121.xcatb.v1.mq5 rename to Documents/BKP/x-saherelm.x121.xcatb.v1.mq5 diff --git a/Libraries/x-saherelm.x-poi.lib.mq5 b/Libraries/x-saherelm.x-poi.lib.mq5 index 3bd30193..dd84c9f0 100644 --- a/Libraries/x-saherelm.x-poi.lib.mq5 +++ b/Libraries/x-saherelm.x-poi.lib.mq5 @@ -361,6 +361,48 @@ struct XPivot return result; } + /** + * Get Pivot Time Bar ... + * + * @param bar: XOHCL, reference to hold result ... + * + * @return ( bool ) + */ + bool GetBar(XOHCL &bar) + { + // + bool result = false; + + // + // Prepare ... + bar.Clean(); + + // + // Validate ... + result = IsValid(); + if (!result) + { + return result; + } + + // + // Initial Bar ... + result = bar.Init( + symbol, + period, + time // + ); + + // + if (!result) + { + bar.Clean(); + } + + // + return result; + } + /** * Check to model Has Same Symbol ... *