From 0459bf2ac4003d64e80f970d4dbf3ba8f25ed11d Mon Sep 17 00:00:00 2001 From: Hadi Khazaee Asl Date: Fri, 21 Mar 2025 06:51:15 +0330 Subject: [PATCH] last ... --- Classes/x-saherelm.x-poi.drawer.class.mq5 | 217 --- Documents/BKP/x-ob.fvg.tmp.mq5 | 1386 +++++++++++++++++ Libraries/x-saherelm.x-poi.state.lib.mq5 | 1081 +------------ .../x-121.smc.market.cycle.helper.class.mq5 | 411 +++++ .../Signals/x-121.smc.xwz.signal.class.mq5 | 37 +- .../Signals/x-121.smc.xwz.signal.lib.mq5 | 511 ++++-- 6 files changed, 2250 insertions(+), 1393 deletions(-) create mode 100644 Documents/BKP/x-ob.fvg.tmp.mq5 diff --git a/Classes/x-saherelm.x-poi.drawer.class.mq5 b/Classes/x-saherelm.x-poi.drawer.class.mq5 index b785ea71..5e76fcbd 100644 --- a/Classes/x-saherelm.x-poi.drawer.class.mq5 +++ b/Classes/x-saherelm.x-poi.drawer.class.mq5 @@ -4630,223 +4630,6 @@ class XCPOIDrawer : public XCBase return result; } - // - int DrawOBFVG( - // - XOBFVG &item, - XCBaseObject *&objects[], - // - bool drawOrderBlock = true, - bool drawFairValueGaps = true, - bool drawAllFVGs = true, - // - bool drawOBStartedBar = true, - bool drawOBActivatedBar = true, - bool drawOBBreakedBar = true, - bool drawOBWorkedBar = true, - // - bool drawFVGStartedBar = true, - bool drawFVGActivatedBar = true, - bool drawFVGBreakedBar = true, - bool drawFVGWorkedBar = true, - // - // Order Block Specs ... - // - int widthOBStartedBar = 1, - color clrOBStartedBar = clrYellow, - ENUM_LINE_STYLE styleOBStartedBar = STYLE_SOLID, - // - int widthOBActivatedBar = 1, - color clrOBActivatedBar = clrLime, - ENUM_LINE_STYLE styleOBActivatedBar = STYLE_SOLID, - // - int widthOBBreakedBar = 1, - color clrOBBreakedBar = clrRed, - ENUM_LINE_STYLE styleOBBreakedBar = STYLE_SOLID, - // - int widthOBWorkedBar = 1, - color clrOBWorkedBar = clrAqua, - ENUM_LINE_STYLE styleOBWorkedBar = STYLE_SOLID, - // - // Fair Value Gap Specs ... - // - int widthFVGStartedBar = 1, - color clrFVGStartedBar = clrYellow, - ENUM_LINE_STYLE styleFVGStartedBar = STYLE_SOLID, - // - int widthFVGActivatedBar = 1, - color clrFVGActivatedBar = clrLime, - ENUM_LINE_STYLE styleFVGActivatedBar = STYLE_SOLID, - // - int widthFVGBreakedBar = 1, - color clrFVGBreakedBar = clrRed, - ENUM_LINE_STYLE styleFVGBreakedBar = STYLE_SOLID, - // - int widthFVGWorkedBar = 1, - color clrFVGWorkedBar = clrAqua, - ENUM_LINE_STYLE styleFVGWorkedBar = STYLE_SOLID - // - ) - { - // - int result = 0; - - // - Clean(objects); - - // - bool isValid = item.IsValid(); - if (!isValid) - { - return result; - } - - // - int count = 0; - bool has = false; - bool isCreated = false; - XCBaseObject *tmpObjects[]; - - // - // Order Block ... - has = item.HasOB(); - if (has && - drawOrderBlock) - { - // - Clean(tmpObjects); - count = DrawOrderBlock( - item.ob, - tmpObjects, - drawOBStartedBar, - drawOBActivatedBar, - drawOBBreakedBar, - drawOBWorkedBar, - widthOBStartedBar, - clrOBStartedBar, - styleOBStartedBar, - widthOBActivatedBar, - clrOBActivatedBar, - styleOBActivatedBar, - widthOBBreakedBar, - clrOBBreakedBar, - styleOBBreakedBar, - widthOBWorkedBar, - clrOBWorkedBar, - styleOBWorkedBar // - ); - has = IsValidSize(count); - if (has) - { - // - Copy( - tmpObjects, - objects, - false // - ); - } - } - - // - // Fair Value Gap ... - if (!drawAllFVGs) - { - XCFVG *fvg; - has = item.GetMainFVG(fvg); - if (has && - drawFairValueGaps) - { - // - Clean(tmpObjects); - int fvgsCount = DrawFairValueGap( - fvg, - tmpObjects, - drawFVGStartedBar, - drawFVGActivatedBar, - drawFVGBreakedBar, - drawFVGWorkedBar, - widthFVGStartedBar, - clrFVGStartedBar, - styleFVGStartedBar, - widthFVGActivatedBar, - clrFVGActivatedBar, - styleFVGActivatedBar, - widthFVGBreakedBar, - clrFVGBreakedBar, - styleFVGBreakedBar, - widthFVGWorkedBar, - clrFVGWorkedBar, - styleFVGWorkedBar // - ); - has = IsValidSize(fvgsCount); - if (has) - { - // - Copy( - tmpObjects, - objects, - false // - ); - } - } - } - else - { - // - has = item.HasFVGs(); - if (has && - drawFairValueGaps) - { - // - count = item.CountFVGs(); - for (int i = 0; i < count; i++) - { - // - Clean(tmpObjects); - int fvgsCount = DrawFairValueGap( - item.fvgs[i], - tmpObjects, - drawFVGStartedBar, - drawFVGActivatedBar, - drawFVGBreakedBar, - drawFVGWorkedBar, - widthFVGStartedBar, - clrFVGStartedBar, - styleFVGStartedBar, - widthFVGActivatedBar, - clrFVGActivatedBar, - styleFVGActivatedBar, - widthFVGBreakedBar, - clrFVGBreakedBar, - styleFVGBreakedBar, - widthFVGWorkedBar, - clrFVGWorkedBar, - styleFVGWorkedBar // - ); - has = IsValidSize(fvgsCount); - if (has) - { - // - Copy( - tmpObjects, - objects, - false // - ); - } - } - } - } - - // - Clean(tmpObjects); - - // - result = ArraySize(objects); - - // - return result; - } - // protected: // diff --git a/Documents/BKP/x-ob.fvg.tmp.mq5 b/Documents/BKP/x-ob.fvg.tmp.mq5 new file mode 100644 index 00000000..50186129 --- /dev/null +++ b/Documents/BKP/x-ob.fvg.tmp.mq5 @@ -0,0 +1,1386 @@ + +// +struct XOBFVGPivot +{ + // + // Props ... + double value; + datetime at; + + // + // Constructor ... + XOBFVGPivot() + { + Clean(); + } + + // + // Tools ... + + // + void Clean() + { + // + value = 0; + at = NULL; + + // + ZeroMemory(this); + } + + // + bool IsValid() + { + // + bool result = false; + + // + result = + value > 0 && + IsValid(at); + + // + return result; + } +}; + +// +struct XOBFVG +{ + // + // Props ... + XCFVG *fvgs[]; + XCOrderBlock *ob; + + // + // Constructor ... + XOBFVG() + { + Clean(); + } + + // + // Tools ... + + // + void Clean() + { + // + Clean(fvgs); + ZeroMemory(ob); + + // + ZeroMemory(this); + } + + // + bool IsValid() + { + // + bool result = false; + + // + result = HasOB() && + HasFVGs(); + if (!result) + { + return result; + } + + // + XOHCL passedBar; + bool isBodyOut; + bool isOBStarted = ob.IsStarted( + ob.GetDirection(), + passedBar, + isBodyOut // + ); + + // + int idx = GetOldest(fvgs); + result = IsValidIndex(idx); + if (!result) + { + // + passedBar.Clean(); + return result; + } + + // + bool isFVGStarted = fvgs[idx].IsStarted( + ob.GetDirection(), + passedBar, + isBodyOut // + ); + + // + result = isOBStarted && + isFVGStarted; + + // + passedBar.Clean(); + + // + return result; + } + + // + bool HasOB() + { + return ob != NULL && + ob.IsValid(); + } + + // + bool HasFVGs() + { + return HasChild(fvgs); + } + + // + int CountFVGs() + { + return ArraySize(fvgs); + } + + // + ENUM_X_DIRECTION GetDirection() + { + // + ENUM_X_DIRECTION result = X_DIRECTION_NONE; + + // + bool isValid = IsValid(); + if (!isValid) + { + return result; + } + + // + result = ob.GetDirection(); + + // + return result; + } + + // + bool IsBullish() + { + return IsBullish(GetDirection()); + } + + // + bool IsBearish() + { + return IsBearish(GetDirection()); + } + + // + int GetSwings( + XOBFVGPivot &pivots[] // + ) + { + // + int result = 0; + + // + Clean(pivots); + + // + if (!IsValid()) + { + return result; + } + + // + ENUM_X_DIRECTION forDir = GetDirection(); + bool isBullish = IsBullish(forDir); + + // + XOHCL passedBar; + XOBFVGPivot iPivot; + bool isPassed = false; + double appliedPrice = 0; + bool isBodyState = false; + + // + // Start ... + isPassed = ob.IsStarted( + forDir, + passedBar, + isBodyState // + ); + if (isPassed) + { + // + appliedPrice = + isBullish + ? passedBar.low + : passedBar.high; + + // + iPivot.Clean(); + iPivot.value = appliedPrice; + iPivot.at = passedBar.time; + + // + AddRef( + iPivot, + pivots // + ); + + // + iPivot.Clean(); + } + + // + // Activation ... + isPassed = ob.IsActivated( + forDir, + passedBar, + isBodyState // + ); + if (isPassed) + { + // + appliedPrice = + isBullish + ? passedBar.low + : passedBar.high; + + // + iPivot.Clean(); + iPivot.value = appliedPrice; + iPivot.at = passedBar.time; + + // + AddRef( + iPivot, + pivots // + ); + + // + iPivot.Clean(); + } + + // + // Worked ... + isPassed = ob.IsWorked( + forDir, + passedBar, + isBodyState // + ); + if (isPassed) + { + // + appliedPrice = + isBullish + ? passedBar.low + : passedBar.high; + + // + iPivot.Clean(); + iPivot.value = appliedPrice; + iPivot.at = passedBar.time; + + // + AddRef( + iPivot, + pivots // + ); + + // + iPivot.Clean(); + } + + // + passedBar.Clean(); + + // + result = ArraySize(pivots); + + // + return result; + } + + // + bool GetMainFVG( + XCFVG *&fvg // + ) + { + // + bool result = false; + + // + fvg = NULL; + + // + result = IsValid(); + if (!result) + { + return result; + } + + // + int idx = GetOldest(fvgs); + result = IsValidIndex(idx); + if (!result) + { + // + ZeroMemory(fvg); + return result; + } + + // + fvg = fvgs[idx]; + result = fvg != NULL && + fvg.IsValid(); + + // + return result; + } + + // + bool IsValidZone( + int barIndex = 0 // + ) + { + // + bool result = false; + + // + if (barIndex < 0) + { + barIndex = 0; + } + + // + result = IsValid(); + if (!result) + { + return result; + } + + // + XCFVG *tmpFVGs[]; + Copy( + fvgs, + tmpFVGs // + ); + int count = CountFVGs(); + for (int i = 0; i < count; i++) + { + // + XCFVG *iFVG = tmpFVGs[i]; + + // + XOHCL startedBar; + bool isBodyOut = false; + result = iFVG.IsStarted( + iFVG.GetDirection(), + startedBar, + isBodyOut // + ); + if (!result) + { + // + ZeroMemory(iFVG); + startedBar.Clean(); + ArrayRemove( + fvgs, + i, + 1 // + ); + + // + continue; + } + + // + XOHCL bar; + bool isBullish = iFVG.IsBullish(); + datetime fromTime = startedBar.NextAt(); + + // + int fromIndex = iBarShift( + iFVG.GetSymbol(), + iFVG.GetPeriod(), + fromTime // + ); + result = IsValidIndex(fromIndex); + if (!result) + { + // + bar.Clean(); + ZeroMemory(iFVG); + startedBar.Clean(); + ArrayRemove( + fvgs, + i, + 1 // + ); + + // + continue; + } + + // + bool isInited = false; + bool isValidFVG = false; + for (int j = barIndex; j < fromIndex; j++) + { + // + isInited = bar.Init( + iFVG.GetSymbol(), + iFVG.GetPeriod(), + j // + ); + if (!isInited) + { + // + bar.Clean(); + continue; + } + + // + // bool isBarAbove = + // bar.low > iFVG.Upper(); + // bool isBarBelow = + // bar.high < iFVG.Lower(); + + // + bool isBarAbove = + bar.GetDown() > iFVG.Upper(); + bool isBarBelow = + bar.GetUp() < iFVG.Lower(); + + // + isValidFVG = + isBullish + ? isBarAbove + : isBarBelow; + if (!isValidFVG) + { + // + bar.Clean(); + + // + break; + } + + // + bar.Clean(); + } + + // + if (!isValidFVG) + { + // + ArrayRemove( + fvgs, + i, + 1 // + ); + } + + // + bar.Clean(); + ZeroMemory(iFVG); + startedBar.Clean(); + } + + // + Clean(tmpFVGs); + + // + result = HasFVGs(); + + // + return result; + } + + // + bool ToZone(XBoxZone &box) + { + // + bool result = false; + + // + result = ToZoneBox( + box, + this // + ); + + // + return result; + } + + // + void AddFVG(XCFVG *fvg) + { + // + int idx = -1; + bool has = false; + + // + has = + HasOB() && + fvg != NULL && + fvg.IsValid() && + ob.GetDirection() == fvg.GetDirection(); + if (!has) + { + return; + } + + // + idx = FindIndex( + fvg, + fvgs // + ); + has = !IsValidIndex(idx); + if (!has) + { + return; + } + + // + Add( + fvg, + fvgs // + ); + } + + // + bool IsSameAs(XOBFVG &item) + { + // + bool result = false; + + // + result = IsValid() && + IsSame(ob, item.ob); + + // + return result; + } + + // + void UpdateTo(datetime value = NULL) + { + // + value = NormalizeTime(value); + + // + int count = 0; + bool has = false; + + // + has = HasOB(); + if (has) + { + ob.To(value); + } + + // + has = HasFVGs(); + if (has) + { + // + count = CountFVGs(); + for (int i = 0; i < count; i++) + { + fvgs[i].To(value); + } + } + } +}; + +/** + * Update to Time of Specifiex Collection ... + * + * @param items: XOBFVG instance Collection ... + * @param value: datetime ... + */ +void SpecifiedUpdateTo( + XOBFVG &items[], + datetime value = NULL // +) +{ + // + value = NormalizeTime(value); + + // + int count = ArraySize(items); + bool has = HasChild(items); + if (!has) + { + return; + } + + // + for (int i = 0; i < count; i++) + { + items[i].UpdateTo(value); + } +} + +/** + * Extract Box Zone's of Specified OBFVG ... + * + * @param box: XBoxZone instance, represent result ... + * @param obfvg: XOBFVG instance, specified Model ... + * + * @return ( bool ) + */ +bool ToZoneBox( + XBoxZone &box, + XOBFVG &obfvg // +) +{ + // + bool result = false; + + // + box.Clean(); + + // + // Check Model Validation ... + result = obfvg.IsValid(); + if (!result) + { + return result; + } + + // + // Retrieve Model Main Fair Value Gap ... + XCFVG *fvg; + result = obfvg.GetMainFVG(fvg); + if (!result) + { + // + box.Clean(); + ZeroMemory(fvg); + + // + return result; + } + + // + bool isBullish = fvg.IsBullish(); + + // + // Retrieve Main Fair Value Gap's Started Bar ... + XOHCL startedBar; + bool isBodyOut = false; + bool isStarted = fvg.IsStarted( + fvg.GetDirection(), + startedBar, + isBodyOut // + ); + result = isStarted; + if (!result) + { + // + box.Clean(); + ZeroMemory(fvg); + startedBar.Clean(); + + // + return result; + } + + // + // Converts Main Fair Value Gaps to Box ... + result = ToBox( + box, + fvg // + ); + if (!result) + { + // + box.Clean(); + ZeroMemory(fvg); + startedBar.Clean(); + + // + return result; + } + + // + // Validate Start Bar ... + result = + isBullish + ? startedBar.high >= fvg.Upper() && + startedBar.low < fvg.Upper() + : startedBar.low <= fvg.Lower() && + startedBar.high > fvg.Lower(); + if (!result) + { + // + box.Clean(); + ZeroMemory(fvg); + startedBar.Clean(); + + // + return result; + } + + // + // Update Box using Started Bar ... + box.lower = isBullish + ? box.lower + : startedBar.low; + box.upper = + isBullish + ? startedBar.high + : box.upper; + + // + box.from = startedBar.NextAt(); + + // + // Check Box Validation ... + result = box.IsValid(); + if (!result) + { + box.Clean(); + } + + // + // Cleanup Resources ... + ZeroMemory(fvg); + startedBar.Clean(); + + // + return result; +} + +/** + * Converts to XBoxZone ... + * + * @return ( bool ) + */ +bool ToBox( + XBoxZone &box, + XOBFVG &item // +) +{ + // + bool result = false; + + // + result = ToBox( + box, + item.ob // + ); + + // + return result; +} + +/** + * Converts to XBoxZone ... + * + * @return ( bool ) + */ +int ToBox( + XOBFVG &source[], + XBoxZone &dest[] // +) +{ + // + int result = 0; + + // + Clean(dest); + int count = ArraySize(source); + if (!IsValidSize(count)) + { + return result; + } + + // + for (int i = 0; i < count; i++) + { + // + XOBFVG iZone = source[i]; + + // + XBoxZone iBox; + bool hasBox = ToBox( + iBox, + iZone // + ); + + // + if (hasBox) + { + // + AddRef( + iBox, + dest // + ); + } + + // + iBox.Clean(); + iZone.Clean(); + } + + // + result = ArraySize(dest); + + // + return result; +} + +/** + * Get Oldest Index ... + * + * @param source: XOBFVG instance Reference Collection ... + * + * @return ( int ) + */ +int GetOldest( + XOBFVG &source[] // +) +{ + // + int result = -1; + + // + int count = ArraySize(source); + if (!IsValidSize(count)) + { + return result; + } + + // + XBoxZone tmpBoxes[]; + int boxesCount = ToBox( + source, + tmpBoxes // + ); + if (!IsValidSize(boxesCount)) + { + // + Clean(tmpBoxes); + return result; + } + + // + XBoxZone selected; + for (int i = 0; i < boxesCount; i++) + { + // + XBoxZone iBox = tmpBoxes[i]; + + // + bool canSet = + !selected.IsValid() + ? true + : selected.from > iBox.from; + if (canSet) + { + // + result = i; + selected = iBox; + } + } + + // + Clean(tmpBoxes); + selected.Clean(); + + // + return result; +} + +/** + * Get Youngest Index ... + * + * @param source: XOBFVG instance Reference Collection ... + * + * @return ( int ) + */ +int GetYoungest( + XOBFVG &source[] // +) +{ + // + int result = -1; + + // + int count = ArraySize(source); + if (!IsValidSize(count)) + { + return result; + } + + // + XBoxZone tmpBoxes[]; + int boxesCount = ToBox( + source, + tmpBoxes // + ); + if (!IsValidSize(boxesCount)) + { + // + Clean(tmpBoxes); + return result; + } + + // + XBoxZone selected; + for (int i = 0; i < boxesCount; i++) + { + // + XBoxZone iBox = tmpBoxes[i]; + + // + bool canSet = + !selected.IsValid() + ? true + : selected.from < iBox.from; + if (canSet) + { + // + result = i; + selected = iBox; + } + } + + // + Clean(tmpBoxes); + selected.Clean(); + + // + return result; +} + +/** + * Get Highest Index ... + * + * @param source: XOBFVG instance Reference Collection ... + * + * @return ( int ) + */ +int GetHighest( + XOBFVG &source[] // +) +{ + // + int result = -1; + + // + int count = ArraySize(source); + if (!IsValidSize(count)) + { + return result; + } + + // + XBoxZone tmpBoxes[]; + int boxesCount = ToBox( + source, + tmpBoxes // + ); + if (!IsValidSize(boxesCount)) + { + // + Clean(tmpBoxes); + return result; + } + + // + XBoxZone selected; + for (int i = 0; i < boxesCount; i++) + { + // + XBoxZone iBox = tmpBoxes[i]; + + // + bool canSet = + !selected.IsValid() + ? true + : selected.upper < iBox.upper; + if (canSet) + { + // + result = i; + selected = iBox; + } + } + + // + Clean(tmpBoxes); + selected.Clean(); + + // + return result; +} + +/** + * Get Lowest Index ... + * + * @param source: XOBFVG instance Reference Collection ... + * + * @return ( int ) + */ +int GetLowest( + XOBFVG &source[] // +) +{ + // + int result = -1; + + // + int count = ArraySize(source); + if (!IsValidSize(count)) + { + return result; + } + + // + XBoxZone tmpBoxes[]; + int boxesCount = ToBox( + source, + tmpBoxes // + ); + if (!IsValidSize(boxesCount)) + { + // + Clean(tmpBoxes); + return result; + } + + // + XBoxZone selected; + for (int i = 0; i < boxesCount; i++) + { + // + XBoxZone iBox = tmpBoxes[i]; + + // + bool canSet = + !selected.IsValid() + ? true + : selected.lower > iBox.lower; + if (canSet) + { + // + result = i; + selected = iBox; + } + } + + // + Clean(tmpBoxes); + selected.Clean(); + + // + return result; +} + +bool AddIfNotExists( + XOBFVG &item, + XOBFVG &items[] // +) +{ + // + bool result = false; + + // + result = item.IsValid(); + if (!result) + { + return result; + } + + // + int before = ArraySize(items); + + // + int idx = FindIndex( + item, + items // + ); + bool has = IsValidIndex(idx); + result = !has; + if (!result) + { + return result; + } + + // + AddRef( + item, + items // + ); + + // + int after = ArraySize(items); + + // + result = after > before; + + // + return result; +} + +int AddIfNotExists( + XOBFVG &items[], + XOBFVG &sources[] // +) +{ + // + int result = 0; + + // + bool has = HasChild(items); + if (!has) + { + return result; + } + + // + int before = ArraySize(sources); + + // + int count = ArraySize(items); + for (int i = 0; i < count; i++) + { + // + has = AddIfNotExists( + items[i], + sources // + ); + } + + // + int after = ArraySize(sources); + + // + result = after > before; + + // + return result; +} + +// +int DrawOBFVG( + // + XOBFVG &item, + XCBaseObject *&objects[], + // + bool drawOrderBlock = true, + bool drawFairValueGaps = true, + bool drawAllFVGs = true, + // + bool drawOBStartedBar = true, + bool drawOBActivatedBar = true, + bool drawOBBreakedBar = true, + bool drawOBWorkedBar = true, + // + bool drawFVGStartedBar = true, + bool drawFVGActivatedBar = true, + bool drawFVGBreakedBar = true, + bool drawFVGWorkedBar = true, + // + // Order Block Specs ... + // + int widthOBStartedBar = 1, + color clrOBStartedBar = clrYellow, + ENUM_LINE_STYLE styleOBStartedBar = STYLE_SOLID, + // + int widthOBActivatedBar = 1, + color clrOBActivatedBar = clrLime, + ENUM_LINE_STYLE styleOBActivatedBar = STYLE_SOLID, + // + int widthOBBreakedBar = 1, + color clrOBBreakedBar = clrRed, + ENUM_LINE_STYLE styleOBBreakedBar = STYLE_SOLID, + // + int widthOBWorkedBar = 1, + color clrOBWorkedBar = clrAqua, + ENUM_LINE_STYLE styleOBWorkedBar = STYLE_SOLID, + // + // Fair Value Gap Specs ... + // + int widthFVGStartedBar = 1, + color clrFVGStartedBar = clrYellow, + ENUM_LINE_STYLE styleFVGStartedBar = STYLE_SOLID, + // + int widthFVGActivatedBar = 1, + color clrFVGActivatedBar = clrLime, + ENUM_LINE_STYLE styleFVGActivatedBar = STYLE_SOLID, + // + int widthFVGBreakedBar = 1, + color clrFVGBreakedBar = clrRed, + ENUM_LINE_STYLE styleFVGBreakedBar = STYLE_SOLID, + // + int widthFVGWorkedBar = 1, + color clrFVGWorkedBar = clrAqua, + ENUM_LINE_STYLE styleFVGWorkedBar = STYLE_SOLID + // +) +{ + // + int result = 0; + + // + Clean(objects); + + // + bool isValid = item.IsValid(); + if (!isValid) + { + return result; + } + + // + int count = 0; + bool has = false; + bool isCreated = false; + XCBaseObject *tmpObjects[]; + + // + // Order Block ... + has = item.HasOB(); + if (has && + drawOrderBlock) + { + // + Clean(tmpObjects); + count = DrawOrderBlock( + item.ob, + tmpObjects, + drawOBStartedBar, + drawOBActivatedBar, + drawOBBreakedBar, + drawOBWorkedBar, + widthOBStartedBar, + clrOBStartedBar, + styleOBStartedBar, + widthOBActivatedBar, + clrOBActivatedBar, + styleOBActivatedBar, + widthOBBreakedBar, + clrOBBreakedBar, + styleOBBreakedBar, + widthOBWorkedBar, + clrOBWorkedBar, + styleOBWorkedBar // + ); + has = IsValidSize(count); + if (has) + { + // + Copy( + tmpObjects, + objects, + false // + ); + } + } + + // + // Fair Value Gap ... + if (!drawAllFVGs) + { + XCFVG *fvg; + has = item.GetMainFVG(fvg); + if (has && + drawFairValueGaps) + { + // + Clean(tmpObjects); + int fvgsCount = DrawFairValueGap( + fvg, + tmpObjects, + drawFVGStartedBar, + drawFVGActivatedBar, + drawFVGBreakedBar, + drawFVGWorkedBar, + widthFVGStartedBar, + clrFVGStartedBar, + styleFVGStartedBar, + widthFVGActivatedBar, + clrFVGActivatedBar, + styleFVGActivatedBar, + widthFVGBreakedBar, + clrFVGBreakedBar, + styleFVGBreakedBar, + widthFVGWorkedBar, + clrFVGWorkedBar, + styleFVGWorkedBar // + ); + has = IsValidSize(fvgsCount); + if (has) + { + // + Copy( + tmpObjects, + objects, + false // + ); + } + } + } + else + { + // + has = item.HasFVGs(); + if (has && + drawFairValueGaps) + { + // + count = item.CountFVGs(); + for (int i = 0; i < count; i++) + { + // + Clean(tmpObjects); + int fvgsCount = DrawFairValueGap( + item.fvgs[i], + tmpObjects, + drawFVGStartedBar, + drawFVGActivatedBar, + drawFVGBreakedBar, + drawFVGWorkedBar, + widthFVGStartedBar, + clrFVGStartedBar, + styleFVGStartedBar, + widthFVGActivatedBar, + clrFVGActivatedBar, + styleFVGActivatedBar, + widthFVGBreakedBar, + clrFVGBreakedBar, + styleFVGBreakedBar, + widthFVGWorkedBar, + clrFVGWorkedBar, + styleFVGWorkedBar // + ); + has = IsValidSize(fvgsCount); + if (has) + { + // + Copy( + tmpObjects, + objects, + false // + ); + } + } + } + } + + // + Clean(tmpObjects); + + // + result = ArraySize(objects); + + // + return result; +} diff --git a/Libraries/x-saherelm.x-poi.state.lib.mq5 b/Libraries/x-saherelm.x-poi.state.lib.mq5 index 2ff8799a..a694916e 100644 --- a/Libraries/x-saherelm.x-poi.state.lib.mq5 +++ b/Libraries/x-saherelm.x-poi.state.lib.mq5 @@ -45,603 +45,6 @@ enum ENUM_X_OBFVG_FVG_SELECTION X_OBFVG_FVG_SELECT_LOWEST_HIGHEST, }; -// -struct XOBFVGPivot -{ - // - // Props ... - double value; - datetime at; - - // - // Constructor ... - XOBFVGPivot() - { - Clean(); - } - - // - // Tools ... - - // - void Clean() - { - // - value = 0; - at = NULL; - - // - ZeroMemory(this); - } - - // - bool IsValid() - { - // - bool result = false; - - // - result = - value > 0 && - IsValid(at); - - // - return result; - } -}; - -// -struct XOBFVG -{ - // - // Props ... - XCFVG *fvgs[]; - XCOrderBlock *ob; - - // - // Constructor ... - XOBFVG() - { - Clean(); - } - - // - // Tools ... - - // - void Clean() - { - // - Clean(fvgs); - ZeroMemory(ob); - - // - ZeroMemory(this); - } - - // - bool IsValid() - { - // - bool result = false; - - // - result = HasOB() && - HasFVGs(); - if (!result) - { - return result; - } - - // - XOHCL passedBar; - bool isBodyOut; - bool isOBStarted = ob.IsStarted( - ob.GetDirection(), - passedBar, - isBodyOut // - ); - - // - int idx = GetOldest(fvgs); - result = IsValidIndex(idx); - if (!result) - { - // - passedBar.Clean(); - return result; - } - - // - bool isFVGStarted = fvgs[idx].IsStarted( - ob.GetDirection(), - passedBar, - isBodyOut // - ); - - // - result = isOBStarted && - isFVGStarted; - - // - passedBar.Clean(); - - // - return result; - } - - // - bool HasOB() - { - return ob != NULL && - ob.IsValid(); - } - - // - bool HasFVGs() - { - return HasChild(fvgs); - } - - // - int CountFVGs() - { - return ArraySize(fvgs); - } - - // - ENUM_X_DIRECTION GetDirection() - { - // - ENUM_X_DIRECTION result = X_DIRECTION_NONE; - - // - bool isValid = IsValid(); - if (!isValid) - { - return result; - } - - // - result = ob.GetDirection(); - - // - return result; - } - - // - bool IsBullish() - { - return IsBullish(GetDirection()); - } - - // - bool IsBearish() - { - return IsBearish(GetDirection()); - } - - // - int GetSwings( - XOBFVGPivot &pivots[] // - ) - { - // - int result = 0; - - // - Clean(pivots); - - // - if (!IsValid()) - { - return result; - } - - // - ENUM_X_DIRECTION forDir = GetDirection(); - bool isBullish = IsBullish(forDir); - - // - XOHCL passedBar; - XOBFVGPivot iPivot; - bool isPassed = false; - double appliedPrice = 0; - bool isBodyState = false; - - // - // Start ... - isPassed = ob.IsStarted( - forDir, - passedBar, - isBodyState // - ); - if (isPassed) - { - // - appliedPrice = - isBullish - ? passedBar.low - : passedBar.high; - - // - iPivot.Clean(); - iPivot.value = appliedPrice; - iPivot.at = passedBar.time; - - // - AddRef( - iPivot, - pivots // - ); - - // - iPivot.Clean(); - } - - // - // Activation ... - isPassed = ob.IsActivated( - forDir, - passedBar, - isBodyState // - ); - if (isPassed) - { - // - appliedPrice = - isBullish - ? passedBar.low - : passedBar.high; - - // - iPivot.Clean(); - iPivot.value = appliedPrice; - iPivot.at = passedBar.time; - - // - AddRef( - iPivot, - pivots // - ); - - // - iPivot.Clean(); - } - - // - // Worked ... - isPassed = ob.IsWorked( - forDir, - passedBar, - isBodyState // - ); - if (isPassed) - { - // - appliedPrice = - isBullish - ? passedBar.low - : passedBar.high; - - // - iPivot.Clean(); - iPivot.value = appliedPrice; - iPivot.at = passedBar.time; - - // - AddRef( - iPivot, - pivots // - ); - - // - iPivot.Clean(); - } - - // - passedBar.Clean(); - - // - result = ArraySize(pivots); - - // - return result; - } - - // - bool GetMainFVG( - XCFVG *&fvg // - ) - { - // - bool result = false; - - // - fvg = NULL; - - // - result = IsValid(); - if (!result) - { - return result; - } - - // - int idx = GetOldest(fvgs); - result = IsValidIndex(idx); - if (!result) - { - // - ZeroMemory(fvg); - return result; - } - - // - fvg = fvgs[idx]; - result = fvg != NULL && - fvg.IsValid(); - - // - return result; - } - - // - bool IsValidZone( - int barIndex = 0 // - ) - { - // - bool result = false; - - // - if (barIndex < 0) - { - barIndex = 0; - } - - // - result = IsValid(); - if (!result) - { - return result; - } - - // - XCFVG *tmpFVGs[]; - Copy( - fvgs, - tmpFVGs // - ); - int count = CountFVGs(); - for (int i = 0; i < count; i++) - { - // - XCFVG *iFVG = tmpFVGs[i]; - - // - XOHCL startedBar; - bool isBodyOut = false; - result = iFVG.IsStarted( - iFVG.GetDirection(), - startedBar, - isBodyOut // - ); - if (!result) - { - // - ZeroMemory(iFVG); - startedBar.Clean(); - ArrayRemove( - fvgs, - i, - 1 // - ); - - // - continue; - } - - // - XOHCL bar; - bool isBullish = iFVG.IsBullish(); - datetime fromTime = startedBar.NextAt(); - - // - int fromIndex = iBarShift( - iFVG.GetSymbol(), - iFVG.GetPeriod(), - fromTime // - ); - result = IsValidIndex(fromIndex); - if (!result) - { - // - bar.Clean(); - ZeroMemory(iFVG); - startedBar.Clean(); - ArrayRemove( - fvgs, - i, - 1 // - ); - - // - continue; - } - - // - bool isInited = false; - bool isValidFVG = false; - for (int j = barIndex; j < fromIndex; j++) - { - // - isInited = bar.Init( - iFVG.GetSymbol(), - iFVG.GetPeriod(), - j // - ); - if (!isInited) - { - // - bar.Clean(); - continue; - } - - // - // bool isBarAbove = - // bar.low > iFVG.Upper(); - // bool isBarBelow = - // bar.high < iFVG.Lower(); - - // - bool isBarAbove = - bar.GetDown() > iFVG.Upper(); - bool isBarBelow = - bar.GetUp() < iFVG.Lower(); - - // - isValidFVG = - isBullish - ? isBarAbove - : isBarBelow; - if (!isValidFVG) - { - // - bar.Clean(); - - // - break; - } - - // - bar.Clean(); - } - - // - if (!isValidFVG) - { - // - ArrayRemove( - fvgs, - i, - 1 // - ); - } - - // - bar.Clean(); - ZeroMemory(iFVG); - startedBar.Clean(); - } - - // - Clean(tmpFVGs); - - // - result = HasFVGs(); - - // - return result; - } - - // - bool ToZone(XBoxZone &box) - { - // - bool result = false; - - // - result = ToZoneBox( - box, - this // - ); - - // - return result; - } - - // - void AddFVG(XCFVG *fvg) - { - // - int idx = -1; - bool has = false; - - // - has = - HasOB() && - fvg != NULL && - fvg.IsValid() && - ob.GetDirection() == fvg.GetDirection(); - if (!has) - { - return; - } - - // - idx = FindIndex( - fvg, - fvgs // - ); - has = !IsValidIndex(idx); - if (!has) - { - return; - } - - // - Add( - fvg, - fvgs // - ); - } - - // - bool IsSameAs(XOBFVG &item) - { - // - bool result = false; - - // - result = IsValid() && - IsSame(ob, item.ob); - - // - return result; - } - - // - void UpdateTo(datetime value = NULL) - { - // - value = NormalizeTime(value); - - // - int count = 0; - bool has = false; - - // - has = HasOB(); - if (has) - { - ob.To(value); - } - - // - has = HasFVGs(); - if (has) - { - // - count = CountFVGs(); - for (int i = 0; i < count; i++) - { - fvgs[i].To(value); - } - } - } -}; - // struct XSignalBox { @@ -4341,258 +3744,15 @@ struct XPOIState // Extensions Functions ... // -/** - * Update to Time of Specifiex Collection ... - * - * @param items: XOBFVG instance Collection ... - * @param value: datetime ... - */ -void SpecifiedUpdateTo( - XOBFVG &items[], - datetime value = NULL // -) -{ - // - value = NormalizeTime(value); - - // - int count = ArraySize(items); - bool has = HasChild(items); - if (!has) - { - return; - } - - // - for (int i = 0; i < count; i++) - { - items[i].UpdateTo(value); - } -} - -/** - * Extract Box Zone's of Specified OBFVG ... - * - * @param box: XBoxZone instance, represent result ... - * @param obfvg: XOBFVG instance, specified Model ... - * - * @return ( bool ) - */ -bool ToZoneBox( - XBoxZone &box, - XOBFVG &obfvg // -) -{ - // - bool result = false; - - // - box.Clean(); - - // - // Check Model Validation ... - result = obfvg.IsValid(); - if (!result) - { - return result; - } - - // - // Retrieve Model Main Fair Value Gap ... - XCFVG *fvg; - result = obfvg.GetMainFVG(fvg); - if (!result) - { - // - box.Clean(); - ZeroMemory(fvg); - - // - return result; - } - - // - bool isBullish = fvg.IsBullish(); - - // - // Retrieve Main Fair Value Gap's Started Bar ... - XOHCL startedBar; - bool isBodyOut = false; - bool isStarted = fvg.IsStarted( - fvg.GetDirection(), - startedBar, - isBodyOut // - ); - result = isStarted; - if (!result) - { - // - box.Clean(); - ZeroMemory(fvg); - startedBar.Clean(); - - // - return result; - } - - // - // Converts Main Fair Value Gaps to Box ... - result = ToBox( - box, - fvg // - ); - if (!result) - { - // - box.Clean(); - ZeroMemory(fvg); - startedBar.Clean(); - - // - return result; - } - - // - // Validate Start Bar ... - result = - isBullish - ? startedBar.high >= fvg.Upper() && - startedBar.low < fvg.Upper() - : startedBar.low <= fvg.Lower() && - startedBar.high > fvg.Lower(); - if (!result) - { - // - box.Clean(); - ZeroMemory(fvg); - startedBar.Clean(); - - // - return result; - } - - // - // Update Box using Started Bar ... - box.lower = isBullish - ? box.lower - : startedBar.low; - box.upper = - isBullish - ? startedBar.high - : box.upper; - - // - box.from = startedBar.NextAt(); - - // - // Check Box Validation ... - result = box.IsValid(); - if (!result) - { - box.Clean(); - } - - // - // Cleanup Resources ... - ZeroMemory(fvg); - startedBar.Clean(); - - // - return result; -} - -/** - * Converts to XBoxZone ... - * - * @return ( bool ) - */ -bool ToBox( - XBoxZone &box, - XOBFVG &item // -) -{ - // - bool result = false; - - // - result = ToBox( - box, - item.ob // - ); - - // - return result; -} - -/** - * Converts to XBoxZone ... - * - * @return ( bool ) - */ -int ToBox( - XOBFVG &source[], - XBoxZone &dest[] // -) -{ - // - int result = 0; - - // - Clean(dest); - int count = ArraySize(source); - if (!IsValidSize(count)) - { - return result; - } - - // - for (int i = 0; i < count; i++) - { - // - XOBFVG iZone = source[i]; - - // - XBoxZone iBox; - bool hasBox = ToBox( - iBox, - iZone // - ); - - // - if (hasBox) - { - // - AddRef( - iBox, - dest // - ); - } - - // - iBox.Clean(); - iZone.Clean(); - } - - // - result = ArraySize(dest); - - // - return result; -} - -// -// -// - /** * Get Oldest Index ... * - * @param source: XOBFVG instance Reference Collection ... + * @param source: XSignalBox instance Reference Collection ... * * @return ( int ) */ int GetOldest( - XOBFVG &source[] // + XSignalBox &source[] // ) { // @@ -4606,30 +3766,29 @@ int GetOldest( } // - XBoxZone tmpBoxes[]; - int boxesCount = ToBox( - source, - tmpBoxes // - ); - if (!IsValidSize(boxesCount)) + XSignalBox selected; + for (int i = 0; i < count; i++) { // - Clean(tmpBoxes); - return result; - } - - // - XBoxZone selected; - for (int i = 0; i < boxesCount; i++) - { - // - XBoxZone iBox = tmpBoxes[i]; + XSignalBox iBox = source[i]; // bool canSet = !selected.IsValid() ? true - : selected.from > iBox.from; + : selected.fvg.IsValid() && + iBox.fvg.IsValid() + ? selected.fvg.from > iBox.fvg.from + : selected.fvg.IsValid() && + !iBox.fvg.IsValid() + ? selected.fvg.from > iBox.ob.from + : !selected.fvg.IsValid() && + iBox.fvg.IsValid() + ? selected.ob.from > iBox.fvg.from + : !selected.fvg.IsValid() && + !iBox.fvg.IsValid() + ? selected.ob.from > iBox.ob.from + : false; if (canSet) { // @@ -4639,7 +3798,6 @@ int GetOldest( } // - Clean(tmpBoxes); selected.Clean(); // @@ -4649,12 +3807,12 @@ int GetOldest( /** * Get Youngest Index ... * - * @param source: XOBFVG instance Reference Collection ... + * @param source: XSignalBox instance Reference Collection ... * * @return ( int ) */ int GetYoungest( - XOBFVG &source[] // + XSignalBox &source[] // ) { // @@ -4668,30 +3826,29 @@ int GetYoungest( } // - XBoxZone tmpBoxes[]; - int boxesCount = ToBox( - source, - tmpBoxes // - ); - if (!IsValidSize(boxesCount)) + XSignalBox selected; + for (int i = 0; i < count; i++) { // - Clean(tmpBoxes); - return result; - } - - // - XBoxZone selected; - for (int i = 0; i < boxesCount; i++) - { - // - XBoxZone iBox = tmpBoxes[i]; + XSignalBox iBox = source[i]; // bool canSet = !selected.IsValid() ? true - : selected.from < iBox.from; + : selected.fvg.IsValid() && + iBox.fvg.IsValid() + ? selected.fvg.from < iBox.fvg.from + : selected.fvg.IsValid() && + !iBox.fvg.IsValid() + ? selected.fvg.from < iBox.ob.from + : !selected.fvg.IsValid() && + iBox.fvg.IsValid() + ? selected.ob.from < iBox.fvg.from + : !selected.fvg.IsValid() && + !iBox.fvg.IsValid() + ? selected.ob.from < iBox.ob.from + : false; if (canSet) { // @@ -4701,7 +3858,6 @@ int GetYoungest( } // - Clean(tmpBoxes); selected.Clean(); // @@ -4711,12 +3867,12 @@ int GetYoungest( /** * Get Highest Index ... * - * @param source: XOBFVG instance Reference Collection ... + * @param source: XSignalBox instance Reference Collection ... * * @return ( int ) */ int GetHighest( - XOBFVG &source[] // + XSignalBox &source[] // ) { // @@ -4730,30 +3886,29 @@ int GetHighest( } // - XBoxZone tmpBoxes[]; - int boxesCount = ToBox( - source, - tmpBoxes // - ); - if (!IsValidSize(boxesCount)) + XSignalBox selected; + for (int i = 0; i < count; i++) { // - Clean(tmpBoxes); - return result; - } - - // - XBoxZone selected; - for (int i = 0; i < boxesCount; i++) - { - // - XBoxZone iBox = tmpBoxes[i]; + XSignalBox iBox = source[i]; // bool canSet = !selected.IsValid() ? true - : selected.upper < iBox.upper; + : selected.fvg.IsValid() && + iBox.fvg.IsValid() + ? selected.fvg.upper < iBox.fvg.upper + : selected.fvg.IsValid() && + !iBox.fvg.IsValid() + ? selected.fvg.upper < iBox.ob.upper + : !selected.fvg.IsValid() && + iBox.fvg.IsValid() + ? selected.ob.upper < iBox.fvg.upper + : !selected.fvg.IsValid() && + !iBox.fvg.IsValid() + ? selected.ob.upper < iBox.ob.upper + : false; if (canSet) { // @@ -4763,7 +3918,6 @@ int GetHighest( } // - Clean(tmpBoxes); selected.Clean(); // @@ -4773,12 +3927,12 @@ int GetHighest( /** * Get Lowest Index ... * - * @param source: XOBFVG instance Reference Collection ... + * @param source: XSignalBox instance Reference Collection ... * * @return ( int ) */ int GetLowest( - XOBFVG &source[] // + XSignalBox &source[] // ) { // @@ -4792,30 +3946,29 @@ int GetLowest( } // - XBoxZone tmpBoxes[]; - int boxesCount = ToBox( - source, - tmpBoxes // - ); - if (!IsValidSize(boxesCount)) + XSignalBox selected; + for (int i = 0; i < count; i++) { // - Clean(tmpBoxes); - return result; - } - - // - XBoxZone selected; - for (int i = 0; i < boxesCount; i++) - { - // - XBoxZone iBox = tmpBoxes[i]; + XSignalBox iBox = source[i]; // bool canSet = !selected.IsValid() ? true - : selected.lower > iBox.lower; + : selected.fvg.IsValid() && + iBox.fvg.IsValid() + ? selected.fvg.lower > iBox.fvg.lower + : selected.fvg.IsValid() && + !iBox.fvg.IsValid() + ? selected.fvg.lower > iBox.ob.lower + : !selected.fvg.IsValid() && + iBox.fvg.IsValid() + ? selected.ob.lower > iBox.fvg.lower + : !selected.fvg.IsValid() && + !iBox.fvg.IsValid() + ? selected.ob.lower > iBox.ob.lower + : false; if (canSet) { // @@ -4825,102 +3978,12 @@ int GetLowest( } // - Clean(tmpBoxes); selected.Clean(); // return result; } -bool AddIfNotExists( - XOBFVG &item, - XOBFVG &items[] // -) -{ - // - bool result = false; - - // - result = item.IsValid(); - if (!result) - { - return result; - } - - // - int before = ArraySize(items); - - // - int idx = FindIndex( - item, - items // - ); - bool has = IsValidIndex(idx); - result = !has; - if (!result) - { - return result; - } - - // - AddRef( - item, - items // - ); - - // - int after = ArraySize(items); - - // - result = after > before; - - // - return result; -} - -int AddIfNotExists( - XOBFVG &items[], - XOBFVG &sources[] // -) -{ - // - int result = 0; - - // - bool has = HasChild(items); - if (!has) - { - return result; - } - - // - int before = ArraySize(sources); - - // - int count = ArraySize(items); - for (int i = 0; i < count; i++) - { - // - has = AddIfNotExists( - items[i], - sources // - ); - } - - // - int after = ArraySize(sources); - - // - result = after > before; - - // - return result; -} - -// -// -// - /** * Find Index of a Signal Box on another ... * diff --git a/X121SMCEA/Classes/x-121.smc.market.cycle.helper.class.mq5 b/X121SMCEA/Classes/x-121.smc.market.cycle.helper.class.mq5 index f695bc80..8ea6cd62 100644 --- a/X121SMCEA/Classes/x-121.smc.market.cycle.helper.class.mq5 +++ b/X121SMCEA/Classes/x-121.smc.market.cycle.helper.class.mq5 @@ -4134,5 +4134,416 @@ struct X121SMCStrategyConditionParser return result; } + // + // XHKMA ... + bool HasSenario4Conditions( + ENUM_X_CYCLES cycle, + ENUM_X_DIRECTION trend, + XBoxZone &box, + XBoxZone &holderBox, + ENUM_X_DIRECTION &dir, + XSignalBox &waitingBoxes[], + X121SMCStrategySignalProviderData &provider, + int barIndex = 0 // + ) + { + // + bool result = false; + + // + int idx = -1; + int count = 0; + bool has = false; + + // + // Normalize Args ... + + // + box.Clean(); + holderBox.Clean(); + dir = X_DIRECTION_NONE; + + // + if (barIndex < 0) + { + barIndex = 0; + } + + // + // Check Trend Exists ... + result = HasDirection(trend); + if (!result) + { + return result; + } + + // + // Extrand Trend Direction ... + bool hasBullishTrend = IsBullish(trend); + bool hasBearishTrend = IsBearish(trend); + + // + // Checking Waiting Baoxes Exists ... + result = HasChild(waitingBoxes); + if (!result) + { + return result; + } + + // + // Check Current Waiting Box is Directional To Trend ... + XSignalBox iSignalBox; + idx = GetYoungest(waitingBoxes); + result = IsValidIndex(idx); + if (!result) + { + // + iSignalBox.Clean(); + return result; + } + iSignalBox = waitingBoxes[idx]; + result = iSignalBox.IsValid() && + iSignalBox.ob.dir == trend; + if (!result) + { + // + iSignalBox.Clean(); + return result; + } + + // + bool hasBullishSignalBox = iSignalBox.IsValid() && + iSignalBox.ob.IsBullish(); + + // + bool hasBearishSignalBox = iSignalBox.IsValid() && + iSignalBox.ob.IsBearish(); + + // + // Fil Selected Data ... + XPOIState cState; + X121Conditions cXConditions; + XPOIStateEvents cStateEvents; + XC121SMCCycleHelper *cHelper; + X121SMCCycleConditions cConditions; + result = provider.SelectCycle( + cycle, + cState, + cStateEvents, + cXConditions, + cHelper, + cConditions // + ); + if (!result) + { + // + cState.Clean(); + ZeroMemory(cHelper); + cConditions.Clean(); + cXConditions.Clean(); + cStateEvents.Clean(); + + // + return result; + } + Parse(cXConditions); + + // + int zIDX = barIndex; + int cIDX = zIDX + 1; + int pIDX = cIDX + 1; + int ppIDX = pIDX + 1; + + // + bool isBullish = false; + bool isBearish = false; + + // + XOHCL zBar; + XOHCL cBar; + XOHCL pBar; + XOHCL pPBar; + + // + // Initial Bars ... + result = zBar.Init( + cState.symbol, + cState.period, + barIndex // + ); + result = + result && + zBar.GetPreviousBar(cBar); + result = + result && + cBar.GetPreviousBar(pBar); + result = + result && + pBar.GetPreviousBar(pPBar); + if (!result) + { + // + zBar.Clean(); + cBar.Clean(); + pBar.Clean(); + pPBar.Clean(); + cState.Clean(); + ZeroMemory(cHelper); + cConditions.Clean(); + cXConditions.Clean(); + + // + return result; + } + + // + ENUM_X_DIRECTION iBarPosDir; + bool isBarValidForDir = cHelper + .mBarAnalyser + .IsValidForPosition( + cBar, + iBarPosDir // + ); + bool isBarValidForBullish = + isBarValidForDir && + IsBullish(iBarPosDir); + bool isBarValidForBearish = + isBarValidForDir && + IsBearish(iBarPosDir); + + // + // Check Bar Validation for Trend Based Directions ... + result = + isBarValidForDir && + iBarPosDir == trend && + HasDirection(iBarPosDir); + if (!result) + { + // + // Cleanup Resources ... + zBar.Clean(); + cBar.Clean(); + pBar.Clean(); + pPBar.Clean(); + cState.Clean(); + iSignalBox.Clean(); + ZeroMemory(cHelper); + cConditions.Clean(); + cStateEvents.Clean(); + cXConditions.Clean(); + + // + return result; + } + + // + // Here we Have to Check Other Consitions Based On Current + // Stuffs ... + XBoxZone zoneBox; + + // + // Select Boxes for Zones ... + XBoxZone tmpBoxes[]; + if (hasBullishTrend) + { + // + XBoxZone tmp[]; + + // + // Order Blocks ... + // ToBox( + // cState.bullishOrderBlocks, + // tmp // + // ); + // Copy( + // tmp, + // tmpBoxes // + // ); + // Clean(tmp); + + // + // Fair Value Gaps ... + ToBox( + cState.bullishFairValueGaps, + tmp // + ); + Copy( + tmp, + tmpBoxes, + false // Ignore Clean ... + ); + Clean(tmp); + } + else if (hasBearishTrend) + { + // + XBoxZone tmp[]; + + // + // Order Blocks ... + // ToBox( + // cState.bearishOrderBlocks, + // tmp // + // ); + // Copy( + // tmp, + // tmpBoxes // + // ); + // Clean(tmp); + + // + // Fair Value Gaps ... + ToBox( + cState.bearishFairValueGaps, + tmp // + ); + Copy( + tmp, + tmpBoxes, + false // Ignore Clean ... + ); + Clean(tmp); + } + has = HasChild(tmpBoxes); + if (has) + { + // + while (HasChild(tmpBoxes)) + { + // + // Select Box based on Trend ... + idx = hasBullishTrend + ? GetLowest(tmpBoxes) + : hasBearishTrend + ? GetHighest(tmpBoxes) + : -1; + has = IsValidIndex(idx); + if (!has) + { + break; + } + + // + XBoxZone iBox = tmpBoxes[idx]; + ArrayRemove( + tmpBoxes, + idx, + 1 // + ); + + // + // Validate Selected Box ... + bool isDirPassed = iBox.dir == trend; + bool isFromPassed = + iSignalBox.fvg.IsValid() + ? iBox.from > iSignalBox.fvg.from + : iBox.from > iSignalBox.ob.from; + bool isPriceInsidePassed = + hasBullishTrend + ? cBar.low < iBox.upper && + cBar.low > iBox.lower + : hasBearishTrend + ? cBar.high > iBox.lower && + cBar.high < iBox.upper + : false; + has = isDirPassed && + isFromPassed && + isPriceInsidePassed; + if (has) + { + // + zoneBox = iBox; + iBox.Clean(); + break; + } + } + } + Clean(tmpBoxes); + + // + bool hasBullishZoneBox = zoneBox.IsValid() && + zoneBox.IsBullish(); + + // + bool hasBearishZoneBox = zoneBox.IsValid() && + zoneBox.IsBearish(); + + // + // Summarize Conditions ... + + // + // Bullish ... + isBullish = + // + // Base Bullish Conditions ... + hasBullishTrend && + hasBullishZoneBox && + hasBullishSignalBox && + isBarValidForBullish && + // + // Other Additional Conditions ... + true + // + ; + + // + // Bearish ... + isBearish = + // + // Base Bearish Conditions ... + hasBearishTrend && + hasBearishZoneBox && + hasBearishSignalBox && + isBarValidForBearish && + // + // Other Additional Conditions ... + true + // + ; + + // + // Filling Requirements ... + result = + isBullish || + isBearish; + if (result) + { + // + dir = + isBullish + ? X_DIRECTION_BULLISH + : X_DIRECTION_BEARISH; + + // + box = zoneBox; + + // + box.to = TimeCurrent(); + + // + if (result) + { + // + Print("Found ..."); + } + } + + // + // Cleanup Resources ... + zBar.Clean(); + cBar.Clean(); + pBar.Clean(); + pPBar.Clean(); + cState.Clean(); + iSignalBox.Clean(); + ZeroMemory(cHelper); + cConditions.Clean(); + cStateEvents.Clean(); + cXConditions.Clean(); + + // + return result; + } + // }; diff --git a/X121SMCEA/Signals/x-121.smc.xwz.signal.class.mq5 b/X121SMCEA/Signals/x-121.smc.xwz.signal.class.mq5 index 405b2984..653e542e 100644 --- a/X121SMCEA/Signals/x-121.smc.xwz.signal.class.mq5 +++ b/X121SMCEA/Signals/x-121.smc.xwz.signal.class.mq5 @@ -173,14 +173,14 @@ class XCX121SMCXWZSignalDetector : public XCBase double targets[]; double reward = 0; XBoxZone signalBox; + bool hasTrend = false; XBoxZone signalHolderBox; bool hasPriority = false; double amountPercent = -1; bool hasSignalBox = false; bool hasWaitingBoxes = false; bool hasRewardAmount = false; - bool hasWorkingZoneOveralDirection = false; - ENUM_X_DIRECTION wzOveralDir = X_DIRECTION_NONE; + ENUM_X_DIRECTION trend = X_DIRECTION_NONE; ENUM_X_DIRECTION signalBoxDir = X_DIRECTION_NONE; ENUM_X121SMC_XWZ_PRIORITY priority = X121SMC_XWZ_PRIORITY_NONE; ENUM_X121SMC_XWZ_PROVIDERS signalProvider = X121SMC_XWZ_PROVIDER_NONE; @@ -216,14 +216,19 @@ class XCX121SMCXWZSignalDetector : public XCBase provider.MaxAllowedLoopbackForInit(578); // - // Check Working Zone Overal Direction ... - hasWorkingZoneOveralDirection = workingZone - .DetectOveralDirection(wzOveralDir); + // Check Working Zone Has Trend ... + hasTrend = workingZone.DetectTreand( + X_CYCLE_CONSOLIDATION, + trend, + provider, + zIndex // + ); // // Detectiong Signal Boxes ... hasWaitingBoxes = workingZone .DetectWaitingBoxes( + X_CYCLE_CONSOLIDATION, X_CYCLE_ANALYSE, provider, zIndex // @@ -282,8 +287,8 @@ class XCX121SMCXWZSignalDetector : public XCBase // true, // Draw Supply Zone ... true, // Draw Demand Zone ... - true // Draw Waiting Zones ... - // + true, // Draw Waiting Zones ... + true // Draw Trend ... ); } @@ -471,6 +476,18 @@ class XCX121SMCXWZSignalDetector : public XCBase // iAtr = provider.decisionXConditions.atrBuffer[1]; iAtr *= 0; + + // + // Prepare Box fro SL ... + iSL = pivot; + Add( + iSL, + sls // + ); + + // + // Fix rf Reward ... + rfRewar = 2; } else if (signalProvider == X121SMC_XWZ_PROVIDER_XREJECTED_BOX) { @@ -491,7 +508,7 @@ class XCX121SMCXWZSignalDetector : public XCBase // // Fix rf Reward ... - rfRewar = 1; + rfRewar = 2; } else if (signalProvider == X121SMC_XWZ_PROVIDER_XACTIVATED_BOX) { @@ -512,7 +529,7 @@ class XCX121SMCXWZSignalDetector : public XCBase // // Fix rf Reward ... - rfRewar = 1; + rfRewar = 2; } else if (signalProvider == X121SMC_XWZ_PROVIDER_XBREAKED_BOX) { @@ -533,7 +550,7 @@ class XCX121SMCXWZSignalDetector : public XCBase // // Fix rf Reward ... - rfRewar = 1; + rfRewar = 2; } // diff --git a/X121SMCEA/Signals/x-121.smc.xwz.signal.lib.mq5 b/X121SMCEA/Signals/x-121.smc.xwz.signal.lib.mq5 index 5664bc4d..3c8557ce 100644 --- a/X121SMCEA/Signals/x-121.smc.xwz.signal.lib.mq5 +++ b/X121SMCEA/Signals/x-121.smc.xwz.signal.lib.mq5 @@ -73,6 +73,11 @@ struct X121SMCStrategyXWZWorkingZone XCSupplyZone *supplyZone; XCDemandZone *demandZone; + // + XBoxZone support; + XBoxZone resistance; + ENUM_X_DIRECTION trend; + // XSignalBox waitingBoxes[]; XSignalBox breakedBoxes[]; @@ -470,7 +475,8 @@ struct X121SMCStrategyXWZWorkingZone * @return ( bool ) */ bool DetectWaitingBoxes( - ENUM_X_CYCLES cycle, + ENUM_X_CYCLES obCycle, + ENUM_X_CYCLES fvgCycle, X121SMCStrategySignalProviderData &provider, int barIndex = 0 // ) @@ -490,28 +496,63 @@ struct X121SMCStrategyXWZWorkingZone } // - // Select Cycle ... - XPOIState cState; - XPOIStateEvents cStateEvents; - X121Conditions cXConditions; - XC121SMCCycleHelper *cHelper; - X121SMCCycleConditions cConditions; + // Select OB Cycle ... + XPOIState obState; + XPOIStateEvents obStateEvents; + X121Conditions obXConditions; + XC121SMCCycleHelper *obHelper; + X121SMCCycleConditions obConditions; result = provider.SelectCycle( - cycle, - cState, - cStateEvents, - cXConditions, - cHelper, - cConditions // + obCycle, + obState, + obStateEvents, + obXConditions, + obHelper, + obConditions // ); if (!result) { // - cState.Clean(); - ZeroMemory(cHelper); - cConditions.Clean(); - cStateEvents.Clean(); - cXConditions.Clean(); + obState.Clean(); + ZeroMemory(obHelper); + obConditions.Clean(); + obStateEvents.Clean(); + obXConditions.Clean(); + + // + return result; + } + + // + // Select FVG Cycle ... + XPOIState fvgState; + XPOIStateEvents fvgStateEvents; + X121Conditions fvgXConditions; + XC121SMCCycleHelper *fvgHelper; + X121SMCCycleConditions fvgConditions; + result = provider.SelectCycle( + fvgCycle, + fvgState, + fvgStateEvents, + fvgXConditions, + fvgHelper, + fvgConditions // + ); + if (!result) + { + // + obState.Clean(); + ZeroMemory(obHelper); + obConditions.Clean(); + obStateEvents.Clean(); + obXConditions.Clean(); + + // + fvgState.Clean(); + ZeroMemory(fvgHelper); + fvgConditions.Clean(); + fvgStateEvents.Clean(); + fvgXConditions.Clean(); // return result; @@ -519,30 +560,30 @@ struct X121SMCStrategyXWZWorkingZone // // Select Order Blocks ... - if (cStateEvents.hasNewOrderBlock) + if (obStateEvents.hasNewOrderBlock) { // - idx = GetYoungest(cState.orderBlocks); + idx = GetYoungest(obState.orderBlocks); has = IsValidIndex(idx); if (has) { // XCFVG *iFVG = NULL; - XCOrderBlock *iOB = cState.orderBlocks[idx]; + XCOrderBlock *iOB = obState.orderBlocks[idx]; bool isBullish = iOB.IsBullish(); // // Detecting Inside FVG ... - has = cState.HasFairValueGaps(); + has = fvgState.HasFairValueGaps(); if (has) { // XCFVG *tmpFVGs[]; - count = cState.CountFairValueGaps(); + count = fvgState.CountFairValueGaps(); for (int i = 0; i < count; i++) { // - XCFVG *jFVG = cState.fairValueGaps[i]; + XCFVG *jFVG = fvgState.fairValueGaps[i]; // bool isDirPassed = jFVG.GetDirection() == iOB.GetDirection(); @@ -610,7 +651,8 @@ struct X121SMCStrategyXWZWorkingZone ); // - has = iOBBox.IsValid(); + has = iOBBox.IsValid() && + iFVGBox.IsValid(); if (has) { // @@ -646,11 +688,18 @@ struct X121SMCStrategyXWZWorkingZone // Cleanup Resources ... // - cState.Clean(); - ZeroMemory(cHelper); - cConditions.Clean(); - cXConditions.Clean(); - cStateEvents.Clean(); + obState.Clean(); + ZeroMemory(obHelper); + obConditions.Clean(); + obStateEvents.Clean(); + obXConditions.Clean(); + + // + fvgState.Clean(); + ZeroMemory(fvgHelper); + fvgConditions.Clean(); + fvgStateEvents.Clean(); + fvgXConditions.Clean(); // return result; @@ -766,118 +815,6 @@ struct X121SMCStrategyXWZWorkingZone return result; } - /** - * Detect Overal Trend of Working Zone ... - * - * @param dir: ENUM_X_DIRECTION member ... - * - * @return ( bool ) - */ - bool DetectOveralDirection( - ENUM_X_DIRECTION &dir // - ) - { - // - bool result = false; - - // - dir = X_DIRECTION_NONE; - - // - result = IsValid() && - HasSupplyZone() && - HasDemandZone(); - if (!result) - { - return result; - } - - // - XBoxZone demBox; - XBoxZone supBox; - result = ToBox( - demBox, - demandZone // - ); - if (!result) - { - // - supBox.Clean(); - demBox.Clean(); - - // - return result; - } - result = ToBox( - supBox, - supplyZone // - ); - if (!result) - { - // - supBox.Clean(); - demBox.Clean(); - - // - return result; - } - - // - XOHCL supPriceOutBar; - bool hasSupPriceOutBar = false; - result = DetectBoxNearestPriceOut( - supBox, - supPriceOutBar, - supBox.period // - ); - - // - XOHCL demPriceOutBar; - bool hasDemPriceOutBar = false; - result = DetectBoxNearestPriceOut( - demBox, - demPriceOutBar, - demBox.period // - ); - - // - hasSupPriceOutBar = supPriceOutBar.IsValid(); - hasDemPriceOutBar = demPriceOutBar.IsValid(); - - // - // Specified Direction ... - dir = - (hasSupPriceOutBar && - hasDemPriceOutBar) - ? supPriceOutBar.time > demPriceOutBar.time - ? X_DIRECTION_BEARISH - : demPriceOutBar.time > supPriceOutBar.time - ? X_DIRECTION_BULLISH - : X_DIRECTION_NONE - : (hasSupPriceOutBar && - !hasDemPriceOutBar) - ? X_DIRECTION_BEARISH - : (!hasSupPriceOutBar && - hasDemPriceOutBar) - ? X_DIRECTION_BULLISH - : X_DIRECTION_NONE; - - // - result = HasDirection(dir); - - // - // Clean Up Resources ... - - // - demBox.Clean(); - supBox.Clean(); - supPriceOutBar.Clean(); - demPriceOutBar.Clean(); - - // - return result; - } - /** * Detect Trend Based On Boxes ... * @@ -886,24 +823,218 @@ struct X121SMCStrategyXWZWorkingZone * @return ( bool ) */ bool DetectTreand( - ENUM_X_DIRECTION &dir // + ENUM_X_CYCLES cycle, + ENUM_X_DIRECTION &dir, + X121SMCStrategySignalProviderData &provider, + int barIndex = 0 // ) { // bool result = false; // + support.Clean(); + resistance.Clean(); dir = X_DIRECTION_NONE; + trend = X_DIRECTION_NONE; // - // Overal ... - ENUM_X_DIRECTION overal; - bool hasOveral = DetectOveralDirection(overal); + if (barIndex < 0) + { + barIndex = 0; + } // - // Waiting Boxes ... + result = IsValid(cycle); + if (!result) + { + return result; + } // + // Select Cycle ... + XPOIState cState; + XPOIStateEvents cStateEvents; + X121Conditions cXConditions; + XC121SMCCycleHelper *cHelper; + X121SMCCycleConditions cConditions; + result = provider.SelectCycle( + cycle, + cState, + cStateEvents, + cXConditions, + cHelper, + cConditions // + ); + if (!result) + { + // + cState.Clean(); + ZeroMemory(cHelper); + cConditions.Clean(); + cStateEvents.Clean(); + cXConditions.Clean(); + + // + return result; + } + + // + // Detect Trend ... + + // + int idx = -1; + bool has = false; + + // + XBoxZone tmp[]; + XBoxZone tmpBoxes[]; + + // + // Select Supports ... + ToBox( + cState.supportZones, + tmp // + ); + Copy( + tmp, + tmpBoxes, + false // + ); + Clean(tmp); + + // + // Select Resistances ... + ToBox( + cState.resistanceZones, + tmp // + ); + Copy( + tmp, + tmpBoxes, + false // + ); + Clean(tmp); + + // + result = HasChild(tmpBoxes); + if (!result) + { + // + Clean(tmpBoxes); + + // + cState.Clean(); + ZeroMemory(cHelper); + cConditions.Clean(); + cStateEvents.Clean(); + cXConditions.Clean(); + + // + return result; + } + + // + // Select Youngest Valid Zone ... + while (HasChild(tmpBoxes) || + !(support.IsValid() && + resistance.IsValid())) + { + // + // Check Yongest Zone ... + idx = GetYoungest(tmpBoxes); + has = IsValidIndex(idx); + if (!has) + { + break; + } + + // + // Remove Extracted Box ... + XBoxZone iBox = tmpBoxes[idx]; + ArrayRemove( + tmpBoxes, + idx, + 1 // + ); + + // + // Check Validation of Box ... + has = IsBoxValid( + iBox, + barIndex, + period // + ); + if (!has) + { + // + iBox.Clean(); + continue; + } + + // + // Assign Support or Resistance ... + bool isBullish = iBox.IsBullish(); + if (isBullish && + !support.IsValid()) + { + support = iBox; + } + else if (!isBullish && + !resistance.IsValid()) + { + resistance = iBox; + } + + // + // Validate Support and Resistance ... + has = + support.IsValid() && + resistance.IsValid(); + if (!has) + { + // + iBox.Clean(); + continue; + } + + // + iBox.Clean(); + } + + // + // Checking Result ... + bool isBullish = + support.from > resistance.from; + bool isBearish = + support.from < resistance.from; + result = isBullish || + isBearish; + if (result) + { + // + dir = + isBullish + ? X_DIRECTION_BULLISH + : X_DIRECTION_BEARISH; + trend = dir; + + // + support.to = TimeCurrent(); + resistance.to = TimeCurrent(); + } + + // + // Cleanup Resources ... + + // + Clean(tmp); + cState.Clean(); + Clean(tmpBoxes); + ZeroMemory(cHelper); + cConditions.Clean(); + cStateEvents.Clean(); + cXConditions.Clean(); // return result; @@ -1117,7 +1248,7 @@ struct X121SMCStrategyXWZWorkingZone // --------------------------------------------- // Rejected Box ... // --------------------------------------------- - bool useSenario1 = true; + bool useSenario1 = false; bool isSenario1Happend = false; bool isSenario1Bullish = false; bool isSenario1Bearish = false; @@ -1156,7 +1287,7 @@ struct X121SMCStrategyXWZWorkingZone // --------------------------------------------------- // Activated Box ... // --------------------------------------------------- - bool useSenario2 = true; + bool useSenario2 = false; bool isSenario2Happend = false; bool isSenario2Bullish = false; bool isSenario2Bearish = false; @@ -1196,7 +1327,7 @@ struct X121SMCStrategyXWZWorkingZone // --------------------------------------------------- // Breaked Box ... // --------------------------------------------------- - bool useSenario3 = true; + bool useSenario3 = false; bool isSenario3Happend = false; bool isSenario3Bullish = false; bool isSenario3Bearish = false; @@ -1234,10 +1365,10 @@ struct X121SMCStrategyXWZWorkingZone // // Senario 4: - // --------------------------------------------- - // Detect Signal Box Based On Conditions ... - // --------------------------------------------- - bool useSenario4 = false; + // ----------------------------------------------- + // Detect Signal Box Based On XHKMA Conditions ... + // ----------------------------------------------- + bool useSenario4 = true; bool isSenario4Happend = false; bool isSenario4Bullish = false; bool isSenario4Bearish = false; @@ -1246,6 +1377,33 @@ struct X121SMCStrategyXWZWorkingZone !isSenario3Happend && useSenario4) { + // + isSenario4Happend = cParser.HasSenario4Conditions( + X_CYCLE_DECISION, + trend, + box, + holderBox, + dir, + waitingBoxes, + provider, + barIndex // + ); + + // + isSenario4Bullish = + isSenario4Happend && + IsBullish(dir); + + // + isSenario4Bearish = + isSenario4Happend && + IsBearish(dir); + + // + if (isSenario4Happend) + { + signalProvider = X121SMC_XWZ_PROVIDER_XHKMA; + } } // @@ -1274,7 +1432,7 @@ struct X121SMCStrategyXWZWorkingZone isSenario2Bullish || isSenario3Bullish || isSenario4Bullish || - isSenario5Bullish + isSenario5Bullish // ; @@ -1285,7 +1443,7 @@ struct X121SMCStrategyXWZWorkingZone isSenario2Bearish || isSenario3Bearish || isSenario4Bearish || - isSenario5Bearish + isSenario5Bearish // ; @@ -1448,7 +1606,8 @@ struct X121SMCStrategyXWZWorkingZone XCPOIDrawer *drawer, bool drawSupplyZone = false, bool drawDemandZone = false, - bool drawWaitingZones = false // + bool drawWaitingZones = false, + bool drawTrend = false // ) { // @@ -1724,6 +1883,44 @@ struct X121SMCStrategyXWZWorkingZone } } + // + // Draw Trend if Exists ... + if (drawTrend) + { + // + // Check Trend Exists ... + has = + support.IsValid() && + HasDirection(trend) && + resistance.IsValid(); + if (has) + { + // + // Draw Support ... + XCBoxObject *supportObject; + has = drawer.DrawBox( + support, + supportObject // + ); + if (has) + { + mWorkingZoneObjects.Add(supportObject); + } + + // + // Draw Resistance ... + XCBoxObject *resistanceObject; + has = drawer.DrawBox( + resistance, + resistanceObject // + ); + if (has) + { + mWorkingZoneObjects.Add(resistanceObject); + } + } + } + // }