/////////////////////////////////////////////////////// // // SaherElm IT Center MQL5 Class // ------------------------------------------------- // Name: XCXCATBEAPOIDrawer ... // Description: XCATBEA POI Drawer Class // // // Maintainer: // ------------ // Hadi Khazaee Asl (hadi_khazaee_asl@yahoo.com) // ////////////////////////////////////////////////////// // // Global Properties ... #property library #property copyright "Copyright 2023, SaherElm IT Center" #property link "https://saherelm.ir" #property version "1.00" #property description "SaherElm XCATBEA POI Drawer Class" #property strict // // Imports ... #include "../../Classes/x-saherelm.x-poi.drawer.class.mq5" #include "../Classes/xcatbea.x-poi.detector.class.mq5" // // Definitions ... struct XCATBPivotStyle { // // Properties ... int width; color clr; ENUM_LINE_STYLE style; // // Constructor ... XCATBPivotStyle() { Default(); } // // Tools ... // // Cleanup Model ... void Clean() { // width = 1; clr = CLR_NONE; style = STYLE_SOLID; // ZeroMemory(this); } // // Default Props ... void Default() { // width = 1; clr = CLR_NONE; style = STYLE_SOLID; } }; // // Implementations ... class XCXCATBEAPOIDrawer : public XCBase { // // Public ... public: // // Props ... XCPOIDrawer *drawer; // // Drawers ... bool drawPeakPivots; bool drawValePivots; bool drawMTBullishPivots; bool drawMTBearishPivots; bool drawOBBullishPivots; bool drawOBBearishPivots; // // Styling ... // XCATBPivotStyle defaultBullishStyle; XCATBPivotStyle defaultBearishStyle; // XCATBPivotStyle peakPivotStyle; XCATBPivotStyle valePivotStyle; // XCATBPivotStyle mtBullishPivotStyle; XCATBPivotStyle mtBearishPivotStyle; // XCATBPivotStyle obBullishPivotStyle; XCATBPivotStyle obBearishPivotStyle; // // Constructors ... XCXCATBEAPOIDrawer( XCXCATBEAPOIDetector *_detector // ) { // detector = _detector; drawer = new XCPOIDrawer(); // Default(); } // // De Constructors ... ~XCXCATBEAPOIDrawer() { // Clear(); // delete drawer; ZeroMemory(drawer); // ZeroMemory(detector); } // // Properties ... // // Tools ... // virtual void Default() { // // Drawing ... drawPeakPivots = false; drawValePivots = false; drawMTBullishPivots = false; drawMTBearishPivots = false; drawOBBullishPivots = false; drawOBBearishPivots = false; // // Styling ... // // Bullish ... defaultBullishStyle.width = 1; defaultBullishStyle.clr = clrLime; defaultBullishStyle.style = STYLE_SOLID; // // Bearish ... defaultBearishStyle.width = 1; defaultBearishStyle.clr = clrRed; defaultBearishStyle.style = STYLE_SOLID; // // Pivots ... // // PV ... peakPivotStyle = defaultBearishStyle; valePivotStyle = defaultBullishStyle; // // MT ... mtBullishPivotStyle = defaultBullishStyle; mtBearishPivotStyle = defaultBearishStyle; // // OB ... obBullishPivotStyle = defaultBullishStyle; obBearishPivotStyle = defaultBearishStyle; } // void Draw(datetime to = NULL) { // // PV ... DrawPeakPivots(to); DrawValePivots(to); // // MT ... DrawMTBullishPivots(to); DrawMTBearishPivots(to); // // OB ... DrawOBBullishPivots(to); DrawOBBearishPivots(to); } // void DrawPivot( XBoxZone &pivot, datetime to = NULL // ) { // DrawBox( pivot, to, false, false // ); } // void DrawBox( XBoxZone &box, datetime to = NULL, bool drawMiddle = false, bool ignoreType = false // ) { // bool has = box.IsValid(); if (!has) { return; } // bool canUpdateTo = IsValid(to); if (canUpdateTo) { box.to = to; } // // Draw Box as POI ... if (!ignoreType) { // // Detect Pivot Type ... ENUM_XCATB_PIVOTS iType = GetPivotType(box); has = IsValid(iType); if (!has) { return; } // switch (iType) { // case XCATB_PEAK: // DrawPeakPivot( box, to // ); break; // case XCATB_VALE: // DrawValePivot( box, to // ); break; // case XCATB_BULLISH_MT: // DrawMTBullishPivot( box, to // ); break; // case XCATB_BEARISH_MT: // DrawMTBearishPivot( box, to // ); break; // case XCATB_BULLISH_OB: // DrawOBBullishPivot( box, to // ); break; // case XCATB_BEARISH_OB: // DrawOBBearishPivot( box, to // ); break; } } // // Draw Regular Box ... else { // // Select Styling Config ... XCATBPivotStyle style; // if (box.IsBullish()) { style = defaultBullishStyle; } else { style = defaultBearishStyle; } // // Draw Box itself ... XCBoxObject *iBoxObj; has = drawer.DrawBox( box, iBoxObj // ); if (has) { // // Style Object ... ApplyPivotStyle( iBoxObj, style // ); // // Store Object ... mObjects.Add(iBoxObj); } // // Draw Box Middle Range ... if (drawMiddle) { // double middle = box.GetMid(); string middleName = box.GetMiddleTag(); // CChartObjectTrend *iMidObj; iMidObj = new CChartObjectTrend(); has = iMidObj.Create( drawer.ChartIdentification(), middleName, drawer.SubWindowIdentification(), box.from, middle, box.to, middle // ); if (has) { // // Styling Object ... iMidObj.Color(style.clr); iMidObj.Width(style.width); iMidObj.Style(style.style); // // Store Object ... mObjects.Add(iMidObj); } } // style.Clean(); } } // void DrawBoxes( XBoxZone &boxes[], datetime to = NULL, bool drawMiddle = false, bool ignoreType = false // ) { // bool has = HasChild(boxes); if (!has) { return; } // int count = ArraySize(boxes); for (int i = 0; i < count; i++) { // XBoxZone iBox = boxes[i]; // // Detect Pivot Type ... DrawBox( iBox, to, drawMiddle, ignoreType // ); // iBox.Clean(); } } // void Clear() { // // Cleanup Models ... defaultBullishStyle.Clean(); defaultBearishStyle.Clean(); // // Cleanup Styles ... peakPivotStyle.Clean(); valePivotStyle.Clean(); mtBullishPivotStyle.Clean(); mtBearishPivotStyle.Clean(); obBullishPivotStyle.Clean(); obBearishPivotStyle.Clean(); // // Cleanup Pivot Objects Holder ... mObjects.Clear(); mPeakPivotObjects.Clear(); mValePivotObjects.Clear(); mMTBullishPivotObjects.Clear(); mMTBearishPivotObjects.Clear(); mOBBullishPivotObjects.Clear(); mOBBearishPivotObjects.Clear(); } // // Collection Drawers ... // void DrawPeakPivots(datetime to = NULL) { // bool has = drawPeakPivots; if (!has) { return; } // has = detector.HasPeakPivots(); if (!has) { return; } // int count = detector.CountPeakPivots(); for (int i = 0; i < count; i++) { // XBoxZone iBox = detector.peakPivots[i]; // DrawPeakPivot( iBox, to // ); // iBox.Clean(); } } // void DrawValePivots(datetime to = NULL) { // bool has = drawValePivots; if (!has) { return; } // has = detector.HasValePivots(); if (!has) { return; } // int count = detector.CountValePivots(); for (int i = 0; i < count; i++) { // XBoxZone iBox = detector.valePivots[i]; // DrawValePivot( iBox, to // ); // iBox.Clean(); } } // void DrawMTBullishPivots(datetime to = NULL) { // bool has = drawMTBullishPivots; if (!has) { return; } // has = detector.HasMTBullishPivots(); if (!has) { return; } // int count = detector.CountMTBullishPivots(); for (int i = 0; i < count; i++) { // XBoxZone iBox = detector.mtBullishPivots[i]; // DrawMTBullishPivot( iBox, to // ); // iBox.Clean(); } } // void DrawMTBearishPivots(datetime to = NULL) { // bool has = drawMTBearishPivots; if (!has) { return; } // has = detector.HasMTBearishPivots(); if (!has) { return; } // int count = detector.CountMTBearishPivots(); for (int i = 0; i < count; i++) { // XBoxZone iBox = detector.mtBearishPivots[i]; // DrawMTBearishPivot( iBox, to // ); // iBox.Clean(); } } // void DrawOBBullishPivots(datetime to = NULL) { // bool has = drawOBBullishPivots; if (!has) { return; } // has = detector.HasOBBullishPivots(); if (!has) { return; } // int count = detector.CountOBBullishPivots(); for (int i = 0; i < count; i++) { // XBoxZone iBox = detector.obBullishPivots[i]; // DrawOBBullishPivot( iBox, to // ); // iBox.Clean(); } } // void DrawOBBearishPivots(datetime to = NULL) { // bool has = drawOBBearishPivots; if (!has) { return; } // has = detector.HasOBBearishPivots(); if (!has) { return; } // int count = detector.CountOBBearishPivots(); for (int i = 0; i < count; i++) { // XBoxZone iBox = detector.obBearishPivots[i]; // DrawOBBearishPivot( iBox, to // ); // iBox.Clean(); } } // // One Item Drawers ... // void DrawPeakPivot( XBoxZone &item, datetime to = NULL // ) { // bool has = drawPeakPivots; if (!has) { return; } // has = item.IsValid() && item.type == GetBoxType(XCATB_PEAK) && item.dir == GetDirection(XCATB_PEAK); if (!has) { return; } // bool canUpdateTo = IsValid(to); if (canUpdateTo) { item.to = to; } // XCBoxObject *iObj; has = drawer.DrawBox( item, iObj // ); if (has) { // // Style Object ... ApplyPivotStyle( iObj, peakPivotStyle // ); // // Store Object ... mPeakPivotObjects.Add(iObj); } // ZeroMemory(iObj); } // void DrawValePivot( XBoxZone &item, datetime to = NULL // ) { // bool has = drawValePivots; if (!has) { return; } // has = item.IsValid() && item.type == GetBoxType(XCATB_VALE) && item.dir == GetDirection(XCATB_VALE); if (!has) { return; } // bool canUpdateTo = IsValid(to); if (canUpdateTo) { item.to = to; } // XCBoxObject *iObj; has = drawer.DrawBox( item, iObj // ); if (has) { // // Style Object ... ApplyPivotStyle( iObj, valePivotStyle // ); // // Store Object ... mValePivotObjects.Add(iObj); } // ZeroMemory(iObj); } // void DrawMTBullishPivot( XBoxZone &item, datetime to = NULL // ) { // bool has = drawMTBullishPivots; if (!has) { return; } // has = item.IsValid() && item.type == GetBoxType(XCATB_BULLISH_MT) && item.dir == GetDirection(XCATB_BULLISH_MT); if (!has) { return; } // bool canUpdateTo = IsValid(to); if (canUpdateTo) { item.to = to; } // XCBoxObject *iObj; has = drawer.DrawBox( item, iObj // ); if (has) { // // Style Object ... ApplyPivotStyle( iObj, mtBullishPivotStyle // ); // // Store Object ... mMTBullishPivotObjects.Add(iObj); } // ZeroMemory(iObj); } // void DrawMTBearishPivot( XBoxZone &item, datetime to = NULL // ) { // bool has = drawMTBearishPivots; if (!has) { return; } // has = item.IsValid() && item.type == GetBoxType(XCATB_BEARISH_MT) && item.dir == GetDirection(XCATB_BEARISH_MT); if (!has) { return; } // bool canUpdateTo = IsValid(to); if (canUpdateTo) { item.to = to; } // XCBoxObject *iObj; has = drawer.DrawBox( item, iObj // ); if (has) { // // Style Object ... ApplyPivotStyle( iObj, mtBearishPivotStyle // ); // // Store Object ... mMTBearishPivotObjects.Add(iObj); } // ZeroMemory(iObj); } // void DrawOBBullishPivot( XBoxZone &item, datetime to = NULL // ) { // bool has = drawOBBullishPivots; if (!has) { return; } // has = item.IsValid() && item.type == GetBoxType(XCATB_BULLISH_OB) && item.dir == GetDirection(XCATB_BULLISH_OB); if (!has) { return; } // bool canUpdateTo = IsValid(to); if (canUpdateTo) { item.to = to; } // XCBoxObject *iObj; has = drawer.DrawBox( item, iObj // ); if (has) { // // Style Object ... ApplyPivotStyle( iObj, obBullishPivotStyle // ); // // Store Object ... mOBBullishPivotObjects.Add(iObj); } // ZeroMemory(iObj); } // void DrawOBBearishPivot( XBoxZone &item, datetime to = NULL // ) { // bool has = drawOBBearishPivots; if (!has) { return; } // has = item.IsValid() && item.type == GetBoxType(XCATB_BEARISH_OB) && item.dir == GetDirection(XCATB_BEARISH_OB); if (!has) { return; } // bool canUpdateTo = IsValid(to); if (canUpdateTo) { item.to = to; } // XCBoxObject *iObj; has = drawer.DrawBox( item, iObj // ); if (has) { // // Style Object ... ApplyPivotStyle( iObj, obBearishPivotStyle // ); // // Store Object ... mOBBearishPivotObjects.Add(iObj); } // ZeroMemory(iObj); } // // Styling Tools ... /** * Apply Default Bullish Style ... * * @param object: XCBaseObject pointer, Specified Object to Apply Styling ... */ void ApplyBullishStyle(XCBoxObject *&object) { // // Validate Args ... if (object == NULL) { return; } // ApplyPivotStyle(object, defaultBullishStyle); } /** * Apply Default Bearish Style ... * * @param object: XCBaseObject pointer, Specified Object to Apply Styling ... */ void ApplyBearishStyle(XCBoxObject *&object) { // // Validate Args ... if (object == NULL) { return; } // ApplyPivotStyle(object, defaultBearishStyle); } /** * Apply Peak Style ... * * @param object: XCBaseObject pointer, Specified Object to Apply Styling ... */ void ApplyPeakPivotStyle(XCBoxObject *&object) { // // Validate Args ... if (object == NULL) { return; } // ApplyPivotStyle(object, peakPivotStyle); } /** * Apply Vale Style ... * * @param object: XCBaseObject pointer, Specified Object to Apply Styling ... */ void ApplyValePivotStyle(XCBoxObject *&object) { // // Validate Args ... if (object == NULL) { return; } // ApplyPivotStyle(object, valePivotStyle); } /** * Apply MT Bullish Style ... * * @param object: XCBaseObject pointer, Specified Object to Apply Styling ... */ void ApplyMTBullishPivotStyle(XCBoxObject *&object) { // // Validate Args ... if (object == NULL) { return; } // ApplyPivotStyle(object, mtBullishPivotStyle); } /** * Apply MT Bearish Style ... * * @param object: XCBaseObject pointer, Specified Object to Apply Styling ... */ void ApplyMTBearishPivotStyle(XCBoxObject *&object) { // // Validate Args ... if (object == NULL) { return; } // ApplyPivotStyle(object, mtBearishPivotStyle); } /** * Apply OB Bullish Style ... * * @param object: XCBaseObject pointer, Specified Object to Apply Styling ... */ void ApplyOBBullishPivotStyle(XCBoxObject *&object) { // // Validate Args ... if (object == NULL) { return; } // ApplyPivotStyle(object, obBullishPivotStyle); } /** * Apply OB Bearish Style ... * * @param object: XCBaseObject pointer, Specified Object to Apply Styling ... */ void ApplyOBBearishPivotStyle(XCBoxObject *&object) { // // Validate Args ... if (object == NULL) { return; } // ApplyPivotStyle(object, obBearishPivotStyle); } /** * Apply Pivot Style to Specified Object ... */ void ApplyPivotStyle( XCBoxObject *&object, XCATBPivotStyle &style // ) { // if (object == NULL) { return; } // object.BoxColor(style.clr); object.BoxWidth(style.width); object.BoxStyle(style.style); } // // Protected ... protected: // // Props ... // // Prrivate ... private: // // Props ... XCXCATBEAPOIDetector *detector; // CArrayObj mObjects; // CArrayObj mPeakPivotObjects; CArrayObj mValePivotObjects; // CArrayObj mMTBullishPivotObjects; CArrayObj mMTBearishPivotObjects; // CArrayObj mOBBullishPivotObjects; CArrayObj mOBBearishPivotObjects; // }; //