diff --git a/Classes/x-saherelm.x-poi.drawer.class.mq5 b/Classes/x-saherelm.x-poi.drawer.class.mq5 index 5e76fcbd..5a31af80 100644 --- a/Classes/x-saherelm.x-poi.drawer.class.mq5 +++ b/Classes/x-saherelm.x-poi.drawer.class.mq5 @@ -23,8 +23,8 @@ // Imports ... #include "../Classes/x-saherelm.base.class.mq5" #include "../Classes/x-saherelm.x-cobject.class.mq5" -#include "../Libraries/x-saherelm.x-poi.state.lib.mq5" #include "../Libraries/x-saherelm.x-poi.extensions.lib.mq5" +#include "../Libraries/x-saherelm.x-poi.state.lib.mq5" // // Definitions ... @@ -3325,6 +3325,124 @@ class XCPOIDrawer : public XCBase return result; } + /** + * Draw Signal Box ... + * + * @param box: XSignalBox instance Reference ... + * @param objects: XCBaseObject pointer instance Reference ... + * + * @return ( bool ) + */ + bool DrawSignalBox( + XSignalBox &box, + XCBaseObject *&objects[], + color clr = CLR_NONE // + ) + { + // + bool result = false; + + // + Clean(objects); + + // + bool has = false; + bool hasColor = clr != CLR_NONE; + + // + // Order Block ... + if (box.ob.IsValid()) + { + // + XCBoxObject *iObj; + has = DrawBox( + box.ob, + iObj // + ); + if (has) + { + // + iObj.BoxStyle(STYLE_DASH); + + // + if (hasColor) + { + iObj.BoxColor(clr); + } + + // + Add( + (XCBaseObject *)iObj, + objects // + ); + } + } + + // + // Fair Value Gap ... + if (box.fvg.IsValid()) + { + // + XCBoxObject *iObj; + has = DrawBox( + box.fvg, + iObj // + ); + if (has) + { + // + iObj.BoxStyle(STYLE_SOLID); + + // + if (hasColor) + { + iObj.BoxColor(clr); + } + + // + Add( + (XCBaseObject *)iObj, + objects // + ); + } + } + + // + // Sharp Zone ... + if (box.sharp.IsValid()) + { + // + XCBoxObject *iObj; + has = DrawBox( + box.sharp, + iObj // + ); + if (has) + { + // + iObj.BoxStyle(STYLE_DOT); + + // + if (hasColor) + { + iObj.BoxColor(clr); + } + + // + Add( + (XCBaseObject *)iObj, + objects // + ); + } + } + + // + result = HasChild(objects); + + // + return result; + } + /** * Draw Specified POI State ... * @@ -4110,526 +4228,6 @@ class XCPOIDrawer : public XCBase return result; } - // - int DrawOrderBlock( - XCOrderBlock *zone, - XCBaseObject *&objects[], - // - bool drawStartedBar = true, - bool drawActivatedBar = true, - bool drawBreakedBar = true, - bool drawWorkedBar = true, - // - int widthStartedBar = 1, - color clrStartedBar = clrYellow, - ENUM_LINE_STYLE styleStartedBar = STYLE_SOLID, - // - int widthActivatedBar = 1, - color clrActivatedBar = clrLime, - ENUM_LINE_STYLE styleActivatedBar = STYLE_SOLID, - // - int widthBreakedBar = 1, - color clrBreakedBar = clrRed, - ENUM_LINE_STYLE styleBreakedBar = STYLE_SOLID, - // - int widthWorkedBar = 1, - color clrWorkedBar = clrAqua, - ENUM_LINE_STYLE styleWorkedBar = STYLE_SOLID - // - ) - { - // - int result = 0; - - // - Clean(objects); - - // - if (zone == NULL || - !zone.IsValid()) - { - return result; - } - - // - ENUM_X_DIRECTION zoneDir = zone.GetDirection(); - - // - // Started Bar ... - XOHCL startedBar; - bool isBodyOut = false; - bool isStarted = zone - .IsStarted( - zoneDir, - startedBar, - isBodyOut // - ); - if (isStarted) - { - // - datetime iBarTo = startedBar.NextAt(); - - // - XCOHCLObject *iBarObj; - bool isCreated = CreateBar( - startedBar, - iBarObj, - iBarTo // - ); - if (isCreated) - { - // - iBarObj.BodyWidth(widthStartedBar); - iBarObj.LowShadowWidth(widthStartedBar); - iBarObj.HighShadowWidth(widthStartedBar); - - // - iBarObj.BodyStyle(styleStartedBar); - iBarObj.LowShadowStyle(styleStartedBar); - iBarObj.HighShadowStyle(styleStartedBar); - - // - iBarObj.BodyColor(clrStartedBar); - iBarObj.LowShadowColor(clrStartedBar); - iBarObj.HighShadowColor(clrStartedBar); - - // - Add( - (XCBaseObject *)iBarObj, - objects // - ); - } - } - - // - // Activated Bar ... - XOHCL activatedBar; - bool isBodyIn = false; - bool isActivated = zone - .IsActivated( - zoneDir, - activatedBar, - isBodyIn, - false // Force Body Out Started ... - ); - if (isActivated) - { - // - datetime iBarTo = activatedBar.NextAt(); - - // - XCOHCLObject *iBarObj; - bool isCreated = CreateBar( - activatedBar, - iBarObj, - iBarTo // - ); - if (isCreated) - { - // - iBarObj.BodyWidth(widthActivatedBar); - iBarObj.LowShadowWidth(widthActivatedBar); - iBarObj.HighShadowWidth(widthActivatedBar); - - // - iBarObj.BodyStyle(styleActivatedBar); - iBarObj.LowShadowStyle(styleActivatedBar); - iBarObj.HighShadowStyle(styleActivatedBar); - - // - iBarObj.BodyColor(clrActivatedBar); - iBarObj.LowShadowColor(clrActivatedBar); - iBarObj.HighShadowColor(clrActivatedBar); - - // - Add( - (XCBaseObject *)iBarObj, - objects // - ); - } - } - - // - // Breaked Bar ... - XOHCL breakedBar; - isBodyOut = false; - bool isBreaked = zone - .IsBreaked( - zoneDir, - breakedBar, - isBodyOut, - false, // Ignore Start ... - false // Force Body Out Started ... - ); - if (isBreaked) - { - // - datetime iBarTo = breakedBar.NextAt(); - - // - XCOHCLObject *iBarObj; - bool isCreated = CreateBar( - breakedBar, - iBarObj, - iBarTo // - ); - if (isCreated) - { - // - iBarObj.BodyWidth(widthBreakedBar); - iBarObj.LowShadowWidth(widthBreakedBar); - iBarObj.HighShadowWidth(widthBreakedBar); - - // - iBarObj.BodyStyle(styleBreakedBar); - iBarObj.LowShadowStyle(styleBreakedBar); - iBarObj.HighShadowStyle(styleBreakedBar); - - // - iBarObj.BodyColor(clrBreakedBar); - iBarObj.LowShadowColor(clrBreakedBar); - iBarObj.HighShadowColor(clrBreakedBar); - - // - Add( - (XCBaseObject *)iBarObj, - objects // - ); - } - } - - // - // Worked Bar ... - XOHCL workedBar; - isBodyOut = false; - bool isWorked = zone - .IsWorked( - zoneDir, - workedBar, - isBodyOut, - false, // Ignore Activation ... - false, // Force Body Out Started ... - false // Force Body In Activated ... - ); - if (isWorked) - { - // - datetime iBarTo = workedBar.NextAt(); - - // - XCOHCLObject *iBarObj; - bool isCreated = CreateBar( - workedBar, - iBarObj, - iBarTo // - ); - if (isCreated) - { - // - iBarObj.BodyWidth(widthWorkedBar); - iBarObj.LowShadowWidth(widthWorkedBar); - iBarObj.HighShadowWidth(widthWorkedBar); - - // - iBarObj.BodyStyle(styleWorkedBar); - iBarObj.LowShadowStyle(styleWorkedBar); - iBarObj.HighShadowStyle(styleWorkedBar); - - // - iBarObj.BodyColor(clrWorkedBar); - iBarObj.LowShadowColor(clrWorkedBar); - iBarObj.HighShadowColor(clrWorkedBar); - - // - Add( - (XCBaseObject *)iBarObj, - objects // - ); - } - } - - // - XCBaseObject *iObj; - bool isCreated = CreateOrderBlock( - zone, - iObj // - ); - if (isCreated) - { - // - Add( - (XCBaseObject *)iObj, - objects // - ); - } - - // - result = ArraySize(objects); - - // - return result; - } - - // - int DrawFairValueGap( - XCFVG *zone, - XCBaseObject *&objects[], - // - bool drawStartedBar = true, - bool drawActivatedBar = true, - bool drawBreakedBar = true, - bool drawWorkedBar = true, - // - int widthStartedBar = 1, - color clrStartedBar = clrYellow, - ENUM_LINE_STYLE styleStartedBar = STYLE_SOLID, - // - int widthActivatedBar = 1, - color clrActivatedBar = clrLime, - ENUM_LINE_STYLE styleActivatedBar = STYLE_SOLID, - // - int widthBreakedBar = 1, - color clrBreakedBar = clrRed, - ENUM_LINE_STYLE styleBreakedBar = STYLE_SOLID, - // - int widthWorkedBar = 1, - color clrWorkedBar = clrAqua, - ENUM_LINE_STYLE styleWorkedBar = STYLE_SOLID - // - ) - { - // - int result = 0; - - // - Clean(objects); - - // - if (zone == NULL || - !zone.IsValid()) - { - return result; - } - - // - ENUM_X_DIRECTION zoneDir = zone.GetDirection(); - - // - // Started Bar ... - XOHCL startedBar; - bool isBodyOut = false; - bool isStarted = zone - .IsStarted( - zoneDir, - startedBar, - isBodyOut // - ); - if (isStarted) - { - // - datetime iBarTo = startedBar.NextAt(); - - // - XCOHCLObject *iBarObj; - bool isCreated = CreateBar( - startedBar, - iBarObj, - iBarTo // - ); - if (isCreated) - { - // - iBarObj.BodyWidth(widthStartedBar); - iBarObj.LowShadowWidth(widthStartedBar); - iBarObj.HighShadowWidth(widthStartedBar); - - // - iBarObj.BodyStyle(styleStartedBar); - iBarObj.LowShadowStyle(styleStartedBar); - iBarObj.HighShadowStyle(styleStartedBar); - - // - iBarObj.BodyColor(clrStartedBar); - iBarObj.LowShadowColor(clrStartedBar); - iBarObj.HighShadowColor(clrStartedBar); - - // - Add( - (XCBaseObject *)iBarObj, - objects // - ); - } - } - - // - // Activated Bar ... - XOHCL activatedBar; - bool isBodyIn = false; - bool isActivated = zone - .IsActivated( - zoneDir, - activatedBar, - isBodyIn, - false // Force Body Out Started ... - ); - if (isActivated) - { - // - datetime iBarTo = activatedBar.NextAt(); - - // - XCOHCLObject *iBarObj; - bool isCreated = CreateBar( - activatedBar, - iBarObj, - iBarTo // - ); - if (isCreated) - { - // - iBarObj.BodyWidth(widthActivatedBar); - iBarObj.LowShadowWidth(widthActivatedBar); - iBarObj.HighShadowWidth(widthActivatedBar); - - // - iBarObj.BodyStyle(styleActivatedBar); - iBarObj.LowShadowStyle(styleActivatedBar); - iBarObj.HighShadowStyle(styleActivatedBar); - - // - iBarObj.BodyColor(clrActivatedBar); - iBarObj.LowShadowColor(clrActivatedBar); - iBarObj.HighShadowColor(clrActivatedBar); - - // - Add( - (XCBaseObject *)iBarObj, - objects // - ); - } - } - - // - // Breaked Bar ... - XOHCL breakedBar; - isBodyOut = false; - bool isBreaked = zone - .IsBreaked( - zoneDir, - breakedBar, - isBodyOut, - false, // Ignore Start ... - false // Force Body Out Started ... - ); - if (isBreaked) - { - // - datetime iBarTo = breakedBar.NextAt(); - - // - XCOHCLObject *iBarObj; - bool isCreated = CreateBar( - breakedBar, - iBarObj, - iBarTo // - ); - if (isCreated) - { - // - iBarObj.BodyWidth(widthBreakedBar); - iBarObj.LowShadowWidth(widthBreakedBar); - iBarObj.HighShadowWidth(widthBreakedBar); - - // - iBarObj.BodyStyle(styleBreakedBar); - iBarObj.LowShadowStyle(styleBreakedBar); - iBarObj.HighShadowStyle(styleBreakedBar); - - // - iBarObj.BodyColor(clrBreakedBar); - iBarObj.LowShadowColor(clrBreakedBar); - iBarObj.HighShadowColor(clrBreakedBar); - - // - Add( - (XCBaseObject *)iBarObj, - objects // - ); - } - } - - // - // Worked Bar ... - XOHCL workedBar; - isBodyOut = false; - bool isWorked = zone - .IsWorked( - zoneDir, - workedBar, - isBodyOut, - false, // Ignore Activation ... - false, // Force Body Out Started ... - false // Force Body In Activated ... - ); - if (isWorked) - { - // - datetime iBarTo = workedBar.NextAt(); - - // - XCOHCLObject *iBarObj; - bool isCreated = CreateBar( - workedBar, - iBarObj, - iBarTo // - ); - if (isCreated) - { - // - iBarObj.BodyWidth(widthWorkedBar); - iBarObj.LowShadowWidth(widthWorkedBar); - iBarObj.HighShadowWidth(widthWorkedBar); - - // - iBarObj.BodyStyle(styleWorkedBar); - iBarObj.LowShadowStyle(styleWorkedBar); - iBarObj.HighShadowStyle(styleWorkedBar); - - // - iBarObj.BodyColor(clrWorkedBar); - iBarObj.LowShadowColor(clrWorkedBar); - iBarObj.HighShadowColor(clrWorkedBar); - - // - Add( - (XCBaseObject *)iBarObj, - objects // - ); - } - } - - // - XCBaseObject *iObj; - bool isCreated = CreateFairValueGap( - zone, - iObj // - ); - if (isCreated) - { - // - Add( - (XCBaseObject *)iObj, - objects // - ); - } - - // - result = ArraySize(objects); - - // - return result; - } - // protected: // diff --git a/Documents/BKP/test.waiting.boxes.mq5 b/Documents/BKP/test.waiting.boxes.mq5 new file mode 100644 index 00000000..90410de4 --- /dev/null +++ b/Documents/BKP/test.waiting.boxes.mq5 @@ -0,0 +1,584 @@ + + // + // Configurations ... + bool useSharpChange = false; + bool useOrderBlockFVG = false; + + // + // Select Order Blocks ... + if (useOrderBlockFVG) + { + // + if (obStateEvents.hasNewOrderBlock) + { + // + idx = GetYoungest(obState.orderBlocks); + has = IsValidIndex(idx); + if (has) + { + // + XCFVG *iFVG = NULL; + XCOrderBlock *iOB = obState.orderBlocks[idx]; + bool isBullish = iOB.IsBullish(); + + // + // Detecting Inside FVG ... + has = fvgState.HasFairValueGaps(); + if (has) + { + // + XCFVG *tmpFVGs[]; + count = fvgState.CountFairValueGaps(); + for (int i = 0; i < count; i++) + { + // + XCFVG *jFVG = fvgState.fairValueGaps[i]; + + // + bool isDirPassed = jFVG.GetDirection() == iOB.GetDirection(); + bool isFromPassed = jFVG.From() >= iOB.From(); + bool isPlacePassed = IsInsideOrDiff( + jFVG, + iOB, + false // + ); + + // + has = isDirPassed && + isFromPassed && + isPlacePassed; + if (has) + { + // + Add( + jFVG, + tmpFVGs // + ); + } + + // + ZeroMemory(jFVG); + } + + // + // Selecting iFVG Based on Direction of OB ... + has = HasChild(tmpFVGs); + if (has) + { + // + idx = + isBullish + ? GetLowest(tmpFVGs) + : GetHighest(tmpFVGs); + has = IsValidIndex(idx); + if (has) + { + iFVG = tmpFVGs[idx]; + } + } + + // + Clean(tmpFVGs); + } + + // + XBoxZone iOBBox; + XBoxZone iFVGBox; + if (iFVG != NULL) + { + // + has = ToBox( + iFVGBox, + iFVG // + ); + } + + // + has = ToBox( + iOBBox, + iOB // + ); + + // + has = iOBBox.IsValid() && + iFVGBox.IsValid(); + if (has) + { + // + XSignalBox iSignalBox; + + // + iSignalBox.ob = iOBBox; + iSignalBox.fvg = iFVGBox; + + // + // Here We Check Waiting Box Contains Other Zones ... + // Like Support/Resistances ... + bool forceVerification = false; + if (forceVerification) + { + // + XBoxZone iVerificationBox; + XBoxZone tmpBoxes[]; + if (isBullish) + { + // + ToBox( + provider.decisionState.supportZones, + tmpBoxes // + ); + } + else + { + // + ToBox( + provider.decisionState.resistanceZones, + tmpBoxes // + ); + } + has = HasChild(tmpBoxes); + if (has) + { + // + while (HasChild(tmpBoxes)) + { + // + idx = GetYoungest(tmpBoxes); + has = IsValidIndex(idx); + if (!has) + { + break; + } + + // + // Select Box ... + XBoxZone iBox = tmpBoxes[idx]; + ArrayRemove( + tmpBoxes, + idx, + 1 // + ); + + // + // Validate Box ... + bool isValidPassed = !IsBoxValid( + iBox, + barIndex // + ); + bool isDirPassed = iBox.dir == iOBBox.dir; + bool isPlacePassed = + IsBoxInside( + iBox, + iOBBox // + ) + // + && + // + (!iFVGBox.IsValid() + ? true + : IsBoxInsideOr( + iBox, + iFVGBox // + )); + + // + has = + isDirPassed && + isValidPassed && + isPlacePassed; + if (has) + { + // + iVerificationBox = iBox; + iBox.Clean(); + break; + } + + // + iBox.Clean(); + } + } + has = iVerificationBox.IsValid(); + Clean(tmpBoxes); + iVerificationBox.Clean(); + } + + // + if (has) + { + // + AddRef( + iSignalBox, + waitingBoxes // + ); + } + + // + iSignalBox.Clean(); + } + + // + iOBBox.Clean(); + iFVGBox.Clean(); + ZeroMemory(iOB); + ZeroMemory(iFVG); + } + } + } + + // + // Checking Other Senario for Waiting Boxes ... + if (useSharpChange) + { + // + if (obStateEvents.hasNewSharp) + { + // + XBoxZone currSharp; + XBoxZone prevSharp; + XBoxZone sharpConsolidation; + + // + // Retrieve Current Sharp ... + XCPOIDrawer *drawer = provider.visionCycleHelper.mPOIDrawer; + XBoxZone tmpBoxes[]; + Copy( + obState.sharps, + tmpBoxes // + ); + idx = GetYoungest(tmpBoxes); + has = IsValidIndex(idx); + if (has) + { + // + currSharp = tmpBoxes[idx]; + bool isBullish = currSharp.IsBullish(); + + // + ArrayRemove( + tmpBoxes, + idx, + 1 // + ); + + // + while (HasChild(tmpBoxes)) + { + // + idx = GetYoungest(tmpBoxes); + has = IsValidIndex(idx); + + // + if (!has) + { + break; + } + + // + XBoxZone iBox = tmpBoxes[idx]; + ArrayRemove( + tmpBoxes, + idx, + 1 // + ); + + // + if (iBox.dir == currSharp.dir) + { + // + prevSharp = iBox; + iBox.Clean(); + break; + } + + // + iBox.Clean(); + } + + // + Clean(tmpBoxes); + } + Clean(tmpBoxes); + + // + // Preparing Sharp Consolidation Box ... + has = currSharp.IsValid() && + prevSharp.IsValid() && + prevSharp.lower < currSharp.upper; + if (has) + { + // + sharpConsolidation.type = "XSHCNZ"; + sharpConsolidation.dir = currSharp.dir; + sharpConsolidation.symbol = currSharp.symbol; + sharpConsolidation.period = currSharp.period; + + // + sharpConsolidation.from = prevSharp.to; + sharpConsolidation.to = currSharp.from; + + // + int toIDX = GetBarIndex( + currSharp.symbol, + currSharp.period, + sharpConsolidation.to // + ); + int fromIDX = GetBarIndex( + currSharp.symbol, + currSharp.period, + sharpConsolidation.from // + ); + int length = fromIDX - toIDX; + + // + XOHCL toBar; + has = toBar.Init( + sharpConsolidation.symbol, + sharpConsolidation.period, + toIDX // + ); + + // + if (has) + { + // + double upper = toBar.FindHighest( + length, + MODE_HIGH // + ); + + // + double lower = toBar.FindLowest( + length, + MODE_LOW // + ); + + // + sharpConsolidation.upper = upper; + sharpConsolidation.lower = lower; + } + + // + has = sharpConsolidation.IsValid(); + if (has) + { + // + XSignalBox iBox; + + // + iBox.ob = sharpConsolidation; + + // + AddRef( + iBox, + waitingBoxes // + ); + + // + iBox.Clean(); + + // // + // XCBoxObject *iCBoxObj; + // XCBoxObject *iPBoxObj; + // provider.visionCycleHelper.mPOIDrawer.DrawBox( + // currSharp, + // iCBoxObj // + // ); + // provider.visionCycleHelper.mPOIDrawer.DrawBox( + // prevSharp, + // iPBoxObj // + // ); + } + + // + currSharp.Clean(); + prevSharp.Clean(); + sharpConsolidation.Clean(); + } + } + + // + // Update Exists Box ... + // XBoxZone fvgs[]; + // count = ArraySize(waitingBoxes); + // has = IsValidSize(count); + // if (has) + // { + // // + // for (int i = 0; i < count; i++) + // { + // // + // bool isSharpBox = waitingBoxes[i].ob.type == "XSHCNZ"; + // if (!isSharpBox) + // { + // continue; + // } + + // // + // bool isBullish = waitingBoxes[i].ob.IsBullish(); + + // // + // // Extract Inside FVGS ... + // if (isBullish) + // { + // // + // ToBox( + // fvgState.bullishFairValueGaps, + // fvgs // + // ); + // } + // else + // { + // // + // ToBox( + // fvgState.bearishFairValueGaps, + // fvgs // + // ); + // } + // has = HasChild(fvgs); + // if (has) + // { + // // + // int removeds[]; + // int iFVGsCount = ArraySize(fvgs); + // for (int j = 0; j < iFVGsCount; j++) + // { + // // + // XBoxZone iFVGBox = fvgs[j]; + // bool isFromPassed = iFVGBox.from >= waitingBoxes[i].ob.from; + // bool isBoundaryPassed = + // isBullish + // ? iFVGBox.lower < waitingBoxes[i].ob.upper + // : iFVGBox.upper > waitingBoxes[i].ob.lower; + + // // + // has = isFromPassed && + // isBoundaryPassed; + // if (!has) + // { + // // + // Add( + // j, + // removeds // + // ); + // } + // } + + // // + // CleanupArray( + // removeds, + // fvgs // + // ); + // Clean(removeds); + // } + + // // + // // Select FVG ... + // has = HasChild(fvgs); + // if (has) + // { + // // + // idx = isBullish + // ? GetLowest(fvgs) + // : GetHighest(fvgs); + // has = IsValidIndex(idx); + // if (has) + // { + // waitingBoxes[i].fvg = fvgs[idx]; + // } + // } + // else + // { + // waitingBoxes[i].fvg.Clean(); + // } + // } + // } + + // + // Clean(fvgs); + } + + +///////////////////////////////////////////////////////////////////////////////////// + +if (signalProvider == X121SMC_XWZ_PROVIDER_XHKMA) +{ + // + 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) +{ + // + iAtr = provider.decisionXConditions.atrBuffer[1]; + iAtr *= 0; + + // + Clean(sls); + + // + // Prepare Box fro SL ... + iSL = signalBox.lower + ((signalBox.upper - signalBox.lower) / 2); + Add( + iSL, + sls // + ); + + // + // Fix rf Reward ... + rfRewar = 2; +} +else if (signalProvider == X121SMC_XWZ_PROVIDER_XACTIVATED_BOX) +{ + // + iAtr = provider.decisionXConditions.atrBuffer[1]; + iAtr *= 0; + + // + Clean(sls); + + // + // Prepare Box fro SL ... + iSL = pivot; + Add( + iSL, + sls // + ); + + // + // Fix rf Reward ... + rfRewar = 2; +} +else if (signalProvider == X121SMC_XWZ_PROVIDER_XBREAKED_BOX) +{ + // + iAtr = provider.decisionXConditions.atrBuffer[1]; + iAtr *= 0; + + // + Clean(sls); + + // + // Prepare Box fro SL ... + iSL = pivot; + Add( + iSL, + sls // + ); + + // + // Fix rf Reward ... + rfRewar = 2; +} diff --git a/Documents/BKP/tmp.drawer.mq5 b/Documents/BKP/tmp.drawer.mq5 new file mode 100644 index 00000000..0d035cd5 --- /dev/null +++ b/Documents/BKP/tmp.drawer.mq5 @@ -0,0 +1,520 @@ + + // + int DrawOrderBlock( + XCOrderBlock *zone, + XCBaseObject *&objects[], + // + bool drawStartedBar = true, + bool drawActivatedBar = true, + bool drawBreakedBar = true, + bool drawWorkedBar = true, + // + int widthStartedBar = 1, + color clrStartedBar = clrYellow, + ENUM_LINE_STYLE styleStartedBar = STYLE_SOLID, + // + int widthActivatedBar = 1, + color clrActivatedBar = clrLime, + ENUM_LINE_STYLE styleActivatedBar = STYLE_SOLID, + // + int widthBreakedBar = 1, + color clrBreakedBar = clrRed, + ENUM_LINE_STYLE styleBreakedBar = STYLE_SOLID, + // + int widthWorkedBar = 1, + color clrWorkedBar = clrAqua, + ENUM_LINE_STYLE styleWorkedBar = STYLE_SOLID + // + ) + { + // + int result = 0; + + // + Clean(objects); + + // + if (zone == NULL || + !zone.IsValid()) + { + return result; + } + + // + ENUM_X_DIRECTION zoneDir = zone.GetDirection(); + + // + // Started Bar ... + XOHCL startedBar; + bool isBodyOut = false; + bool isStarted = zone + .IsStarted( + zoneDir, + startedBar, + isBodyOut // + ); + if (isStarted) + { + // + datetime iBarTo = startedBar.NextAt(); + + // + XCOHCLObject *iBarObj; + bool isCreated = CreateBar( + startedBar, + iBarObj, + iBarTo // + ); + if (isCreated) + { + // + iBarObj.BodyWidth(widthStartedBar); + iBarObj.LowShadowWidth(widthStartedBar); + iBarObj.HighShadowWidth(widthStartedBar); + + // + iBarObj.BodyStyle(styleStartedBar); + iBarObj.LowShadowStyle(styleStartedBar); + iBarObj.HighShadowStyle(styleStartedBar); + + // + iBarObj.BodyColor(clrStartedBar); + iBarObj.LowShadowColor(clrStartedBar); + iBarObj.HighShadowColor(clrStartedBar); + + // + Add( + (XCBaseObject *)iBarObj, + objects // + ); + } + } + + // + // Activated Bar ... + XOHCL activatedBar; + bool isBodyIn = false; + bool isActivated = zone + .IsActivated( + zoneDir, + activatedBar, + isBodyIn, + false // Force Body Out Started ... + ); + if (isActivated) + { + // + datetime iBarTo = activatedBar.NextAt(); + + // + XCOHCLObject *iBarObj; + bool isCreated = CreateBar( + activatedBar, + iBarObj, + iBarTo // + ); + if (isCreated) + { + // + iBarObj.BodyWidth(widthActivatedBar); + iBarObj.LowShadowWidth(widthActivatedBar); + iBarObj.HighShadowWidth(widthActivatedBar); + + // + iBarObj.BodyStyle(styleActivatedBar); + iBarObj.LowShadowStyle(styleActivatedBar); + iBarObj.HighShadowStyle(styleActivatedBar); + + // + iBarObj.BodyColor(clrActivatedBar); + iBarObj.LowShadowColor(clrActivatedBar); + iBarObj.HighShadowColor(clrActivatedBar); + + // + Add( + (XCBaseObject *)iBarObj, + objects // + ); + } + } + + // + // Breaked Bar ... + XOHCL breakedBar; + isBodyOut = false; + bool isBreaked = zone + .IsBreaked( + zoneDir, + breakedBar, + isBodyOut, + false, // Ignore Start ... + false // Force Body Out Started ... + ); + if (isBreaked) + { + // + datetime iBarTo = breakedBar.NextAt(); + + // + XCOHCLObject *iBarObj; + bool isCreated = CreateBar( + breakedBar, + iBarObj, + iBarTo // + ); + if (isCreated) + { + // + iBarObj.BodyWidth(widthBreakedBar); + iBarObj.LowShadowWidth(widthBreakedBar); + iBarObj.HighShadowWidth(widthBreakedBar); + + // + iBarObj.BodyStyle(styleBreakedBar); + iBarObj.LowShadowStyle(styleBreakedBar); + iBarObj.HighShadowStyle(styleBreakedBar); + + // + iBarObj.BodyColor(clrBreakedBar); + iBarObj.LowShadowColor(clrBreakedBar); + iBarObj.HighShadowColor(clrBreakedBar); + + // + Add( + (XCBaseObject *)iBarObj, + objects // + ); + } + } + + // + // Worked Bar ... + XOHCL workedBar; + isBodyOut = false; + bool isWorked = zone + .IsWorked( + zoneDir, + workedBar, + isBodyOut, + false, // Ignore Activation ... + false, // Force Body Out Started ... + false // Force Body In Activated ... + ); + if (isWorked) + { + // + datetime iBarTo = workedBar.NextAt(); + + // + XCOHCLObject *iBarObj; + bool isCreated = CreateBar( + workedBar, + iBarObj, + iBarTo // + ); + if (isCreated) + { + // + iBarObj.BodyWidth(widthWorkedBar); + iBarObj.LowShadowWidth(widthWorkedBar); + iBarObj.HighShadowWidth(widthWorkedBar); + + // + iBarObj.BodyStyle(styleWorkedBar); + iBarObj.LowShadowStyle(styleWorkedBar); + iBarObj.HighShadowStyle(styleWorkedBar); + + // + iBarObj.BodyColor(clrWorkedBar); + iBarObj.LowShadowColor(clrWorkedBar); + iBarObj.HighShadowColor(clrWorkedBar); + + // + Add( + (XCBaseObject *)iBarObj, + objects // + ); + } + } + + // + XCBaseObject *iObj; + bool isCreated = CreateOrderBlock( + zone, + iObj // + ); + if (isCreated) + { + // + Add( + (XCBaseObject *)iObj, + objects // + ); + } + + // + result = ArraySize(objects); + + // + return result; + } + + // + int DrawFairValueGap( + XCFVG *zone, + XCBaseObject *&objects[], + // + bool drawStartedBar = true, + bool drawActivatedBar = true, + bool drawBreakedBar = true, + bool drawWorkedBar = true, + // + int widthStartedBar = 1, + color clrStartedBar = clrYellow, + ENUM_LINE_STYLE styleStartedBar = STYLE_SOLID, + // + int widthActivatedBar = 1, + color clrActivatedBar = clrLime, + ENUM_LINE_STYLE styleActivatedBar = STYLE_SOLID, + // + int widthBreakedBar = 1, + color clrBreakedBar = clrRed, + ENUM_LINE_STYLE styleBreakedBar = STYLE_SOLID, + // + int widthWorkedBar = 1, + color clrWorkedBar = clrAqua, + ENUM_LINE_STYLE styleWorkedBar = STYLE_SOLID + // + ) + { + // + int result = 0; + + // + Clean(objects); + + // + if (zone == NULL || + !zone.IsValid()) + { + return result; + } + + // + ENUM_X_DIRECTION zoneDir = zone.GetDirection(); + + // + // Started Bar ... + XOHCL startedBar; + bool isBodyOut = false; + bool isStarted = zone + .IsStarted( + zoneDir, + startedBar, + isBodyOut // + ); + if (isStarted) + { + // + datetime iBarTo = startedBar.NextAt(); + + // + XCOHCLObject *iBarObj; + bool isCreated = CreateBar( + startedBar, + iBarObj, + iBarTo // + ); + if (isCreated) + { + // + iBarObj.BodyWidth(widthStartedBar); + iBarObj.LowShadowWidth(widthStartedBar); + iBarObj.HighShadowWidth(widthStartedBar); + + // + iBarObj.BodyStyle(styleStartedBar); + iBarObj.LowShadowStyle(styleStartedBar); + iBarObj.HighShadowStyle(styleStartedBar); + + // + iBarObj.BodyColor(clrStartedBar); + iBarObj.LowShadowColor(clrStartedBar); + iBarObj.HighShadowColor(clrStartedBar); + + // + Add( + (XCBaseObject *)iBarObj, + objects // + ); + } + } + + // + // Activated Bar ... + XOHCL activatedBar; + bool isBodyIn = false; + bool isActivated = zone + .IsActivated( + zoneDir, + activatedBar, + isBodyIn, + false // Force Body Out Started ... + ); + if (isActivated) + { + // + datetime iBarTo = activatedBar.NextAt(); + + // + XCOHCLObject *iBarObj; + bool isCreated = CreateBar( + activatedBar, + iBarObj, + iBarTo // + ); + if (isCreated) + { + // + iBarObj.BodyWidth(widthActivatedBar); + iBarObj.LowShadowWidth(widthActivatedBar); + iBarObj.HighShadowWidth(widthActivatedBar); + + // + iBarObj.BodyStyle(styleActivatedBar); + iBarObj.LowShadowStyle(styleActivatedBar); + iBarObj.HighShadowStyle(styleActivatedBar); + + // + iBarObj.BodyColor(clrActivatedBar); + iBarObj.LowShadowColor(clrActivatedBar); + iBarObj.HighShadowColor(clrActivatedBar); + + // + Add( + (XCBaseObject *)iBarObj, + objects // + ); + } + } + + // + // Breaked Bar ... + XOHCL breakedBar; + isBodyOut = false; + bool isBreaked = zone + .IsBreaked( + zoneDir, + breakedBar, + isBodyOut, + false, // Ignore Start ... + false // Force Body Out Started ... + ); + if (isBreaked) + { + // + datetime iBarTo = breakedBar.NextAt(); + + // + XCOHCLObject *iBarObj; + bool isCreated = CreateBar( + breakedBar, + iBarObj, + iBarTo // + ); + if (isCreated) + { + // + iBarObj.BodyWidth(widthBreakedBar); + iBarObj.LowShadowWidth(widthBreakedBar); + iBarObj.HighShadowWidth(widthBreakedBar); + + // + iBarObj.BodyStyle(styleBreakedBar); + iBarObj.LowShadowStyle(styleBreakedBar); + iBarObj.HighShadowStyle(styleBreakedBar); + + // + iBarObj.BodyColor(clrBreakedBar); + iBarObj.LowShadowColor(clrBreakedBar); + iBarObj.HighShadowColor(clrBreakedBar); + + // + Add( + (XCBaseObject *)iBarObj, + objects // + ); + } + } + + // + // Worked Bar ... + XOHCL workedBar; + isBodyOut = false; + bool isWorked = zone + .IsWorked( + zoneDir, + workedBar, + isBodyOut, + false, // Ignore Activation ... + false, // Force Body Out Started ... + false // Force Body In Activated ... + ); + if (isWorked) + { + // + datetime iBarTo = workedBar.NextAt(); + + // + XCOHCLObject *iBarObj; + bool isCreated = CreateBar( + workedBar, + iBarObj, + iBarTo // + ); + if (isCreated) + { + // + iBarObj.BodyWidth(widthWorkedBar); + iBarObj.LowShadowWidth(widthWorkedBar); + iBarObj.HighShadowWidth(widthWorkedBar); + + // + iBarObj.BodyStyle(styleWorkedBar); + iBarObj.LowShadowStyle(styleWorkedBar); + iBarObj.HighShadowStyle(styleWorkedBar); + + // + iBarObj.BodyColor(clrWorkedBar); + iBarObj.LowShadowColor(clrWorkedBar); + iBarObj.HighShadowColor(clrWorkedBar); + + // + Add( + (XCBaseObject *)iBarObj, + objects // + ); + } + } + + // + XCBaseObject *iObj; + bool isCreated = CreateFairValueGap( + zone, + iObj // + ); + if (isCreated) + { + // + Add( + (XCBaseObject *)iObj, + objects // + ); + } + + // + result = ArraySize(objects); + + // + return result; + } diff --git a/Documents/BKP/x.tmp.signals.xwz.sharp.ob.fvg.mq5 b/Documents/BKP/x.tmp.signals.xwz.sharp.ob.fvg.mq5 new file mode 100644 index 00000000..ec14a0d5 --- /dev/null +++ b/Documents/BKP/x.tmp.signals.xwz.sharp.ob.fvg.mq5 @@ -0,0 +1,2621 @@ +// +// Provided Signals Enumeration ... +enum ENUM_X121SMC_XWZ_PROVIDERS +{ + X121SMC_XWZ_PROVIDER_NONE, + X121SMC_XWZ_PROVIDER_XHKMA, + X121SMC_XWZ_PROVIDER_XSHCNZ, + X121SMC_XWZ_PROVIDER_XBREAKED_BOX, + X121SMC_XWZ_PROVIDER_XREJECTED_BOX, + X121SMC_XWZ_PROVIDER_XACTIVATED_BOX, +}; + +///////////////////////////////////////////////////////////////////// + +// +// Rejected Box ... +bool HasRejectedBoxConditions( + ENUM_X_CYCLES cycle, + XBoxZone &box, + XBoxZone &holderBox, + ENUM_X_DIRECTION &dir, + XSignalBox &waitingBoxes[], + X121SMCStrategySignalProviderData &provider, + int barIndex = 0 // +) +{ + // + bool result = false; + + // + // Configure ... + bool forceRetestBox = false; + bool forceHolderBox = false; + bool forceConsolidationZone = false; + + // + // 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); + + // + // Checking Waiting Baoxes Exists ... + result = HasChild(waitingBoxes); + if (!result) + { + return result; + } + + // + // Normalize Args ... + + // + box.Clean(); + holderBox.Clean(); + dir = X_DIRECTION_NONE; + + // + if (barIndex < 0) + { + barIndex = 0; + } + + // + int idx = -1; + int count = 0; + bool has = false; + + // + 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; + + // + // Initial Bars ... + result = zBar.Init( + cState.symbol, + cState.period, + barIndex // + ); + result = + result && + zBar.GetPreviousBar(cBar); + result = + result && + cBar.GetPreviousBar(pBar); + if (!result) + { + // + zBar.Clean(); + cBar.Clean(); + pBar.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); + + // + XBoxZone selectedBox; + XSignalBox iSignalBox; + count = ArraySize(waitingBoxes); + has = IsValidSize(count); + if (has) + { + // + for (int i = 0; i < count; i++) + { + // + XSignalBox iBox = waitingBoxes[i]; + + // + bool isBullish = iBox.ob.IsBullish(); + bool hasFVG = iBox.fvg.IsValid(); + + // + bool isFVGBullishRejected = + // + hasFVG && + cBar.low < iBox.fvg.upper && + cBar.GetDown() > iBox.fvg.upper + // + ; + + // + bool isFVGBearishRejected = + // + hasFVG && + cBar.high > iBox.fvg.lower && + cBar.GetUp() < iBox.fvg.lower + // + ; + + // + bool isOBBullishRejected = + // + cBar.low < iBox.ob.upper && + cBar.GetDown() > iBox.ob.upper + // + ; + + // + bool isOBBearishRejected = + // + cBar.high > iBox.ob.lower && + cBar.GetUp() < iBox.ob.lower + // + ; + + // + has = + isBullish + ? (hasFVG + ? isFVGBullishRejected + : isOBBullishRejected) + : (hasFVG + ? isFVGBearishRejected + : isOBBearishRejected); + + // + // Force Using OB ... + if (!has && hasFVG) + { + // + has = isBullish + ? isOBBullishRejected + : isOBBearishRejected; + + // + selectedBox = iBox.ob; + } + if (has) + { + // + iSignalBox = iBox; + if (!selectedBox.IsValid()) + { + // + if (hasFVG) + { + selectedBox = iBox.fvg; + } + else + { + selectedBox = iBox.ob; + } + } + iBox.Clean(); + break; + } + + // + iBox.Clean(); + } + } + has = + iSignalBox.IsValid() && + selectedBox.IsValid(); + + // + // Retest Signal ... + int retests = 0; + if (has) + { + // + int iFromIDX = GetBarIndex( + cBar.symbol, + cBar.period, + selectedBox.from // + ); + has = IsValidIndex(iFromIDX); + if (has) + { + // + // Counting Retests ... + for (int i = iFromIDX; i >= barIndex; i--) + { + // + XOHCL iBar; + has = iBar.Init( + cBar.symbol, + cBar.period, + i // + ); + + // + bool isBullishRetested = + // + iBar.low < selectedBox.upper && + iBar.GetDown() > selectedBox.upper + // + ; + + // + bool isBearishRetested = + // + iBar.high > selectedBox.lower && + iBar.GetUp() < selectedBox.lower + // + ; + + // + has = selectedBox.IsBullish() + ? isBullishRetested + : isBearishRetested; + if (has) + { + retests++; + } + + // + iBar.Clean(); + } + } + } + + // + bool isSignalBoxRetested = + !forceRetestBox + ? retests >= 1 + : retests >= 2; + bool hasSignalBox = iSignalBox.IsValid(); + bool isSignalBoxBullish = IsBullish(iSignalBox.ob.dir); + + // + // Check Consolidation Zone ... + bool hasBullishCZone = true; + bool hasBearishCZone = true; + if (forceConsolidationZone) + { + // + XBoxZone cZone; + XBoxZone tmpBoxes[]; + if (isSignalBoxBullish) + { + // + ToBox( + cState.bullishConsolidationZones, + tmpBoxes // + ); + } + else + { + // + ToBox( + cState.bearishConsolidationZones, + tmpBoxes // + ); + } + has = HasChild(tmpBoxes); + if (has) + { + // + XBoxZone selectedBox; + if (iSignalBox.fvg.IsValid()) + { + selectedBox = iSignalBox.fvg; + } + else + { + selectedBox = iSignalBox.ob; + } + + // + idx = GetYoungest(tmpBoxes); + has = IsValidIndex(idx); + if (has) + { + // + cZone = tmpBoxes[idx]; + + // + // Check Consolidation Zone Place ... + has = + // + ( + // + IsBoxInsideOr( + cZone, + selectedBox // + ) + // + && + // + cZone.from >= selectedBox.from + // + ) + // + || + // + ( + // + IsBoxInsideOr( + selectedBox, + cZone // + ) + // + && + // + selectedBox.from >= cZone.from + // + ) + // + ; + if (!has) + { + cZone.Clean(); + } + } + + // + selectedBox.Clean(); + } + Clean(tmpBoxes); + + // + hasBullishCZone = cZone.IsValid() && + cZone.IsBullish(); + + // + hasBearishCZone = cZone.IsValid() && + cZone.IsBearish(); + + // + cZone.Clean(); + } + + // + // Bullish Conditions ... + isBullish = + // + // Base Condition ... + ( + // + hasSignalBox && + hasBullishCZone && + isSignalBoxBullish && + isSignalBoxRetested && + isBarValidForBullish + // + ) + // + ; + + // + // Bearish Conditions ... + isBearish = + // + // Base Condition ... + ( + // + hasSignalBox && + hasBearishCZone && + !isSignalBoxBullish && + isSignalBoxRetested && + isBarValidForBearish + // + ) + // + ; + + // + // Filling Requirements ... + result = + isBullish || + isBearish; + if (result) + { + // + dir = + isBullish + ? X_DIRECTION_BULLISH + : X_DIRECTION_BEARISH; + + // + box = selectedBox; + box.to = TimeCurrent(); + + // + // Detect Holder Box ... + if (forceHolderBox) + { + // + XBoxZone tmpBoxes[]; + if (isBullish) + { + // + // Order Blocks ... + XBoxZone tmp[]; + ToBox( + cState.bullishOrderBlocks, + tmp // + ); + Copy( + tmp, + tmpBoxes // + ); + Clean(tmp); + + // + // Fair Value Gaps ... + ToBox( + cState.bullishFairValueGaps, + tmp // + ); + Copy( + tmp, + tmpBoxes, + false // Ignore Clean ... + ); + Clean(tmp); + + // + // Support Zones ... + ToBox( + cState.supportZones, + tmp // + ); + Copy( + tmp, + tmpBoxes, + false // Ignore Clean ... + ); + Clean(tmp); + } + else + { + // + // Order Blocks ... + XBoxZone tmp[]; + ToBox( + cState.bearishOrderBlocks, + tmp // + ); + Copy( + tmp, + tmpBoxes // + ); + Clean(tmp); + + // + // Fair Value Gaps ... + ToBox( + cState.bearishFairValueGaps, + tmp // + ); + Copy( + tmp, + tmpBoxes, + false // Ignore Clean ... + ); + Clean(tmp); + + // + // Resistance Zones ... + ToBox( + cState.resistanceZones, + tmp // + ); + Copy( + tmp, + tmpBoxes, + false // Ignore Clean ... + ); + Clean(tmp); + } + + // + count = ArraySize(tmpBoxes); + has = IsValidSize(count); + if (has) + { + // + while (HasChild(tmpBoxes)) + { + // + idx = GetOldest(tmpBoxes); + has = IsValidIndex(idx); + if (!has) + { + break; + } + + // + XBoxZone iBox = tmpBoxes[idx]; + ArrayRemove( + tmpBoxes, + idx, + 1 // + ); + + // + has = IsBoxInside( + iBox, + box // + ); + if (has) + { + // + holderBox = iBox; + holderBox.to = TimeCurrent(); + iBox.Clean(); + break; + } + + // + iBox.Clean(); + } + } + + // + Clean(tmpBoxes); + + // + result = + result && + holderBox.IsValid() && + holderBox.dir == dir; + if (!result) + { + // + box.Clean(); + isBullish = false; + isBearish = false; + holderBox.Clean(); + } + } + } + + // + // Check All Conditions ... + result = + box.IsValid() && + HasDirection(dir) && + (isBullish || + isBearish); + + // + // Cleanup Resources ... + zBar.Clean(); + cBar.Clean(); + pBar.Clean(); + cState.Clean(); + iSignalBox.Clean(); + selectedBox.Clean(); + ZeroMemory(cHelper); + cConditions.Clean(); + cStateEvents.Clean(); + cXConditions.Clean(); + + // + return result; +} + +// +// Activated Box +bool HasActivatedBoxConditions( + ENUM_X_CYCLES cycle, + XBoxZone &box, + XBoxZone &holderBox, + ENUM_X_DIRECTION &dir, + XSignalBox &waitingBoxes[], + X121SMCStrategySignalProviderData &provider, + int barIndex = 0 // +) +{ + // + bool result = false; + + // + // 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); + + // + // Checking Waiting Baoxes Exists ... + result = HasChild(waitingBoxes); + if (!result) + { + return result; + } + + // + // Normalize Args ... + + // + box.Clean(); + holderBox.Clean(); + dir = X_DIRECTION_NONE; + + // + if (barIndex < 0) + { + barIndex = 0; + } + + // + int idx = -1; + int count = 0; + bool has = false; + + // + 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); + + // + XSignalBox iSignalBox; + count = ArraySize(waitingBoxes); + has = IsValidSize(count); + if (has) + { + // + for (int i = 0; i < count; i++) + { + // + XSignalBox iBox = waitingBoxes[i]; + + // + bool isBullish = iBox.ob.IsBullish(); + bool hasFVG = iBox.fvg.IsValid(); + + // + // Checking Inside ... + + // + bool isBullishInsideFVG = + // + hasFVG && + pBar.high < iBox.fvg.upper && + pPBar.high < iBox.fvg.upper + // + ; + + // + bool isBearishInsideFVG = + // + hasFVG && + pBar.low > iBox.fvg.lower && + pPBar.low > iBox.fvg.lower + // + ; + + // + bool isBullishInsideOB = + // + pBar.high < iBox.ob.upper && + pPBar.high < iBox.ob.upper + // + ; + + // + bool isBearishInsideOB = + // + pBar.low > iBox.ob.lower && + pPBar.low > iBox.ob.lower + // + ; + + // + // Checking Breakes Box ... + + // + bool isFVGBullishBreaked = + // + hasFVG && + isBullishInsideFVG && + // + cBar.high > iBox.fvg.upper && + cBar.close > iBox.fvg.upper && + // + zBar.open > iBox.fvg.upper + // + ; + + // + bool isFVGBearishBreaked = + // + hasFVG && + isBearishInsideFVG && + // + cBar.low < iBox.fvg.lower && + cBar.close < iBox.fvg.lower && + // + zBar.open > iBox.fvg.lower + // + ; + + // + bool isOBBullishBreaked = + // + isBullishInsideOB && + // + cBar.high > iBox.ob.upper && + cBar.close > iBox.ob.upper && + // + zBar.open > iBox.ob.upper + // + ; + + // + bool isOBBearishBreaked = + // + isBearishInsideOB && + // + cBar.low < iBox.ob.lower && + cBar.close < iBox.ob.lower && + // + zBar.open > iBox.ob.lower + // + ; + + // + // Summarise ... + + // + bool isBullishBreaked = + isBarValidForBullish && + (hasFVG + ? isFVGBullishBreaked + : isOBBullishBreaked); + + // + bool isBearishBreaked = + isBarValidForBearish && + (hasFVG + ? isFVGBearishBreaked + : isOBBearishBreaked); + + // + has = isBullishBreaked || + isBearishBreaked; + // + if (has) + { + // + iSignalBox = iBox; + iBox.Clean(); + + // + dir = + isBullishBreaked + ? X_DIRECTION_BULLISH + : isBearishBreaked + ? X_DIRECTION_BEARISH + : X_DIRECTION_NONE; + + // + break; + } + + // + iBox.Clean(); + } + } + + // + bool hasSignalBox = HasDirection(dir) && + iSignalBox.IsValid(); + bool isSignalBoxBullish = IsBullish(dir); + + // + // Bullish Conditions ... + isBullish = + // + // Base Condition ... + ( + // + hasSignalBox && + isSignalBoxBullish && + isBarValidForBullish + // + ) + // + ; + + // + // Bearish Conditions ... + isBearish = + // + // Base Condition ... + ( + // + hasSignalBox && + !isSignalBoxBullish && + isBarValidForBearish + // + ) + // + ; + + // + // Filling Requirements ... + result = + isBullish || + isBearish; + if (result) + { + // + dir = + isBullish + ? X_DIRECTION_BULLISH + : X_DIRECTION_BEARISH; + + // + if (iSignalBox.fvg.IsValid()) + { + box = iSignalBox.fvg; + } + else + { + box = iSignalBox.ob; + } + + // + box.to = TimeCurrent(); + + // + // Detect Holder Box ... + XBoxZone tmpBoxes[]; + if (isBullish) + { + // + // Order Blocks ... + XBoxZone tmp[]; + ToBox( + cState.bullishOrderBlocks, + tmp // + ); + Copy( + tmp, + tmpBoxes // + ); + Clean(tmp); + + // + // Fair Value Gaps ... + ToBox( + cState.bullishFairValueGaps, + tmp // + ); + Copy( + tmp, + tmpBoxes, + false // Ignore Clean ... + ); + Clean(tmp); + + // + // Support Zones ... + ToBox( + cState.supportZones, + tmp // + ); + Copy( + tmp, + tmpBoxes, + false // Ignore Clean ... + ); + Clean(tmp); + } + else + { + // + // Order Blocks ... + XBoxZone tmp[]; + ToBox( + cState.bearishOrderBlocks, + tmp // + ); + Copy( + tmp, + tmpBoxes // + ); + Clean(tmp); + + // + // Fair Value Gaps ... + ToBox( + cState.bearishFairValueGaps, + tmp // + ); + Copy( + tmp, + tmpBoxes, + false // Ignore Clean ... + ); + Clean(tmp); + + // + // Resistance Zones ... + ToBox( + cState.resistanceZones, + tmp // + ); + Copy( + tmp, + tmpBoxes, + false // Ignore Clean ... + ); + Clean(tmp); + } + + // + count = ArraySize(tmpBoxes); + has = IsValidSize(count); + if (has) + { + // + while (HasChild(tmpBoxes)) + { + // + idx = GetOldest(tmpBoxes); + has = IsValidIndex(idx); + if (!has) + { + break; + } + + // + XBoxZone iBox = tmpBoxes[idx]; + ArrayRemove( + tmpBoxes, + idx, + 1 // + ); + + // + has = IsBoxInside( + iBox, + box // + ); + if (has) + { + // + holderBox = iBox; + holderBox.to = TimeCurrent(); + iBox.Clean(); + break; + } + + // + iBox.Clean(); + } + } + + // + Clean(tmpBoxes); + + // + result = + result && + holderBox.IsValid() && + holderBox.dir == dir; + if (!result) + { + // + box.Clean(); + isBullish = false; + isBearish = false; + holderBox.Clean(); + } + } + + // + // Check All Conditions ... + result = + box.IsValid() && + HasDirection(dir) && + (isBullish || + isBearish); + + // + // Cleanup Resources ... + zBar.Clean(); + cBar.Clean(); + pBar.Clean(); + pPBar.Clean(); + cState.Clean(); + iSignalBox.Clean(); + ZeroMemory(cHelper); + cConditions.Clean(); + cStateEvents.Clean(); + cXConditions.Clean(); + + // + return result; +} + +// +// Breaked Box +bool HasBreakedBoxConditions( + ENUM_X_CYCLES cycle, + XBoxZone &box, + XBoxZone &holderBox, + ENUM_X_DIRECTION &dir, + XSignalBox &waitingBoxes[], + X121SMCStrategySignalProviderData &provider, + int barIndex = 0 // +) +{ + // + bool result = false; + + // + // 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); + + // + // Checking Waiting Baoxes Exists ... + result = HasChild(waitingBoxes); + if (!result) + { + return result; + } + + // + // Normalize Args ... + + // + box.Clean(); + holderBox.Clean(); + dir = X_DIRECTION_NONE; + + // + if (barIndex < 0) + { + barIndex = 0; + } + + // + int idx = -1; + int count = 0; + bool has = false; + + // + 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); + + // + XSignalBox iSignalBox; + count = ArraySize(waitingBoxes); + has = IsValidSize(count); + if (has) + { + // + for (int i = 0; i < count; i++) + { + // + XSignalBox iBox = waitingBoxes[i]; + + // + bool isBullish = iBox.ob.IsBullish(); + bool hasFVG = iBox.fvg.IsValid(); + + // + // Checking Breakes Box ... + + // + bool isFVGBullishBreaked = + // + hasFVG && + // + pBar.low < iBox.fvg.upper && + // + cBar.high > iBox.fvg.upper && + cBar.close > iBox.fvg.upper && + // + zBar.open > iBox.fvg.upper + // + ; + + // + bool isFVGBearishBreaked = + // + hasFVG && + // + pBar.high > iBox.fvg.lower && + // + cBar.low < iBox.fvg.lower && + cBar.close < iBox.fvg.lower && + // + zBar.open > iBox.fvg.lower + // + ; + + // + bool isOBBullishBreaked = + // + pBar.low < iBox.ob.upper && + // + cBar.high > iBox.ob.upper && + cBar.close > iBox.ob.upper && + // + zBar.open > iBox.ob.upper + // + ; + + // + bool isOBBearishBreaked = + // + pBar.high > iBox.ob.lower && + // + cBar.low < iBox.ob.lower && + cBar.close < iBox.ob.lower && + // + zBar.open > iBox.ob.lower + // + ; + + // + // Summarise ... + + // + bool isBullishBreaked = + isBarValidForBullish && + (hasFVG + ? isFVGBullishBreaked + : isOBBullishBreaked); + + // + bool isBearishBreaked = + isBarValidForBearish && + (hasFVG + ? isFVGBearishBreaked + : isOBBearishBreaked); + + // + has = isBullishBreaked || + isBearishBreaked; + // + if (has) + { + // + iSignalBox = iBox; + iBox.Clean(); + + // + dir = + isBullishBreaked + ? X_DIRECTION_BULLISH + : isBearishBreaked + ? X_DIRECTION_BEARISH + : X_DIRECTION_NONE; + + // + break; + } + + // + iBox.Clean(); + } + } + + // + bool hasSignalBox = HasDirection(dir) && + iSignalBox.IsValid(); + bool isSignalBoxBullish = IsBullish(dir); + + // + // Bullish Conditions ... + isBullish = + // + // Base Condition ... + ( + // + hasSignalBox && + isSignalBoxBullish && + isBarValidForBullish + // + ) + // + ; + + // + // Bearish Conditions ... + isBearish = + // + // Base Condition ... + ( + // + hasSignalBox && + !isSignalBoxBullish && + isBarValidForBearish + // + ) + // + ; + + // + // Filling Requirements ... + result = + isBullish || + isBearish; + if (result) + { + // + dir = + isBullish + ? X_DIRECTION_BULLISH + : X_DIRECTION_BEARISH; + + // + if (iSignalBox.fvg.IsValid()) + { + box = iSignalBox.fvg; + } + else + { + box = iSignalBox.ob; + } + + // + box.to = TimeCurrent(); + + // + // Detect Holder Box ... + XBoxZone tmpBoxes[]; + if (isBullish) + { + // + // Order Blocks ... + XBoxZone tmp[]; + ToBox( + cState.bullishOrderBlocks, + tmp // + ); + Copy( + tmp, + tmpBoxes // + ); + Clean(tmp); + + // + // Fair Value Gaps ... + ToBox( + cState.bullishFairValueGaps, + tmp // + ); + Copy( + tmp, + tmpBoxes, + false // Ignore Clean ... + ); + Clean(tmp); + + // + // Support Zones ... + ToBox( + cState.supportZones, + tmp // + ); + Copy( + tmp, + tmpBoxes, + false // Ignore Clean ... + ); + Clean(tmp); + } + else + { + // + // Order Blocks ... + XBoxZone tmp[]; + ToBox( + cState.bearishOrderBlocks, + tmp // + ); + Copy( + tmp, + tmpBoxes // + ); + Clean(tmp); + + // + // Fair Value Gaps ... + ToBox( + cState.bearishFairValueGaps, + tmp // + ); + Copy( + tmp, + tmpBoxes, + false // Ignore Clean ... + ); + Clean(tmp); + + // + // Resistance Zones ... + ToBox( + cState.resistanceZones, + tmp // + ); + Copy( + tmp, + tmpBoxes, + false // Ignore Clean ... + ); + Clean(tmp); + } + + // + count = ArraySize(tmpBoxes); + has = IsValidSize(count); + if (has) + { + // + while (HasChild(tmpBoxes)) + { + // + idx = GetOldest(tmpBoxes); + has = IsValidIndex(idx); + if (!has) + { + break; + } + + // + XBoxZone iBox = tmpBoxes[idx]; + ArrayRemove( + tmpBoxes, + idx, + 1 // + ); + + // + has = IsBoxInside( + iBox, + box // + ); + if (has) + { + // + holderBox = iBox; + holderBox.to = TimeCurrent(); + iBox.Clean(); + break; + } + + // + iBox.Clean(); + } + } + + // + Clean(tmpBoxes); + + // + result = + result && + holderBox.IsValid() && + holderBox.dir == dir; + if (!result) + { + // + box.Clean(); + isBullish = false; + isBearish = false; + holderBox.Clean(); + } + } + + // + // Check All Conditions ... + result = + box.IsValid() && + HasDirection(dir) && + (isBullish || + isBearish); + + // + // Cleanup Resources ... + zBar.Clean(); + cBar.Clean(); + pBar.Clean(); + pPBar.Clean(); + cState.Clean(); + iSignalBox.Clean(); + ZeroMemory(cHelper); + cConditions.Clean(); + cStateEvents.Clean(); + cXConditions.Clean(); + + // + return result; +} + +// +// XHKMA ... +bool HasXHKMAConditions( + 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(); + + // + // Detecting Consolidation Zone ... + XBoxZone cZone; + if (hasBullishTrend) + { + // + ToBox( + cState.bullishConsolidationZones, + tmpBoxes // + ); + } + else if (hasBearishTrend) + { + // + ToBox( + cState.bearishConsolidationZones, + tmpBoxes // + ); + } + has = HasChild(tmpBoxes); + if (has) + { + // + idx = GetYoungest(tmpBoxes); + has = IsValidIndex(idx); + if (has) + { + // + cZone = tmpBoxes[idx]; + + // + // Check Consolidation Zone Place ... + has = + // + ( + // + IsBoxInsideOr( + cZone, + zoneBox // + ) + // + && + // + cZone.from >= zoneBox.from + // + ) + // + || + // + ( + // + IsBoxInsideOr( + zoneBox, + cZone // + ) + // + && + // + zoneBox.from >= cZone.from + // + ) + // + ; + if (!has) + { + cZone.Clean(); + } + } + } + Clean(tmpBoxes); + + // + bool hasBullishCZone = cZone.IsValid() && + cZone.IsBullish(); + + // + bool hasBearishCZone = cZone.IsValid() && + cZone.IsBearish(); + + // + // Summarize Conditions ... + + // + // Bullish ... + isBullish = + // + // Base Bullish Conditions ... + hasBullishTrend && + hasBullishCZone && + hasBullishZoneBox && + hasBullishSignalBox && + isBarValidForBullish && + // + // Other Additional Conditions ... + true + // + ; + + // + // Bearish ... + isBearish = + // + // Base Bearish Conditions ... + hasBearishTrend && + hasBearishCZone && + 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(); + cZone.to = TimeCurrent(); + + // + if (result) + { + // + XCPOIDrawer *drawer = provider.visionCycleHelper.mPOIDrawer; + + // + XCBoxObject *iObj; + has = drawer.DrawBox( + box, + iObj // + ); + + // + XCBoxObject *iCObject; + has = drawer.DrawBox( + cZone, + iCObject // + ); + if (has) + { + // + iCObject.BoxColor(clrLime); + iCObject.BoxStyle(STYLE_SOLID); + } + + // + Print("Found ..."); + + // + ZeroMemory(drawer); + } + } + + // + // Cleanup Resources ... + zBar.Clean(); + cBar.Clean(); + pBar.Clean(); + pPBar.Clean(); + cZone.Clean(); + cState.Clean(); + zoneBox.Clean(); + iSignalBox.Clean(); + ZeroMemory(cHelper); + cConditions.Clean(); + cStateEvents.Clean(); + cXConditions.Clean(); + + // + return result; +} + +// +// XSHCNZ ... +bool HasXSHCNZConditions( + ENUM_X_CYCLES cycle, + ENUM_X_DIRECTION trend, + XBoxZone &box, + ENUM_X_DIRECTION &dir, + XSignalBox &waitingBoxes[], + X121SMCStrategySignalProviderData &provider, + int barIndex = 0 // +) +{ + // + bool result = false; + + // + box.Clean(); + dir = X_DIRECTION_NONE; + + // + if (barIndex < 0) + { + barIndex = 0; + } + + // + // Validate Args ... + result = IsValid(cycle) && + HasDirection(trend) && + HasChild(waitingBoxes); + if (!result) + { + return result; + } + + // + // 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 idx = -1; + int count = 0; + bool has = false; + + // + 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; + + // + // Initial Bars ... + result = zBar.Init( + cState.symbol, + cState.period, + barIndex // + ); + result = + result && + zBar.GetPreviousBar(cBar); + result = + result && + cBar.GetPreviousBar(pBar); + if (!result) + { + // + zBar.Clean(); + cBar.Clean(); + pBar.Clean(); + cState.Clean(); + ZeroMemory(cHelper); + cConditions.Clean(); + cXConditions.Clean(); + + // + return result; + } + + // + // Extract XSHCNZ Boxes ... + XBoxZone sharpBox; + XBoxZone sharpBoxes[]; + count = ArraySize(waitingBoxes); + for (int i = 0; i < count; i++) + { + // + has = waitingBoxes[i].ob.type == "XSHCNZ"; + if (has) + { + // + AddRef( + waitingBoxes[i].ob, + sharpBoxes // + ); + } + } + count = ArraySize(sharpBoxes); + has = IsValidSize(count); + result = has; + if (!result) + { + // + zBar.Clean(); + cBar.Clean(); + pBar.Clean(); + cState.Clean(); + Clean(sharpBoxes); + ZeroMemory(cHelper); + cConditions.Clean(); + cXConditions.Clean(); + cStateEvents.Clean(); + + // + return result; + } + + // + // Detect Price Inside Sharp Box ... + if (has) + { + // + for (int i = 0; i < count; i++) + { + // + XBoxZone iBox = sharpBoxes[i]; + + // + bool isInside = cBar.close > iBox.lower && + cBar.close < iBox.upper; + if (isInside) + { + // + sharpBox = iBox; + iBox.Clean(); + break; + } + + // + iBox.Clean(); + } + } + + // + // Validate Sharp Box Exists ... + has = sharpBox.IsValid(); + result = has; + if (!result) + { + // + zBar.Clean(); + cBar.Clean(); + pBar.Clean(); + cState.Clean(); + sharpBox.Clean(); + Clean(sharpBoxes); + ZeroMemory(cHelper); + cConditions.Clean(); + cXConditions.Clean(); + cStateEvents.Clean(); + + // + return result; + } + + // + XCPOIDrawer *drawer = provider.visionCycleHelper.mPOIDrawer; + XCBoxObject *iSharpObj; + has = drawer.DrawBox( + sharpBox, + iSharpObj // + ); + if (has) + { + // + iSharpObj.BoxColor(clrYellow); + + // + Print("Sharp Box Selected ..."); + } + + // + // Validate Bar for Specified Position Type ... + ENUM_X_DIRECTION iBarPosDir; + bool isBarValidForDir = cHelper + .mBarAnalyser + .IsValidForPosition( + cBar, + iBarPosDir // + ); + bool isBarValidForBullish = + isBarValidForDir && + IsBullish(iBarPosDir); + bool isBarValidForBearish = + isBarValidForDir && + IsBearish(iBarPosDir); + + // + // Cleanup Resources ... + + // + zBar.Clean(); + cBar.Clean(); + pBar.Clean(); + cState.Clean(); + sharpBox.Clean(); + Clean(sharpBoxes); + ZeroMemory(cHelper); + cConditions.Clean(); + cXConditions.Clean(); + cStateEvents.Clean(); + + // + return result; +} + +/////////////////////////////////////////////////////////////// + +// +// Senario 1: +// --------------------------------------------- +// Rejected Box ... +// --------------------------------------------- +bool useSenario1 = false; +bool isSenario1Happend = false; +bool isSenario1Bullish = false; +bool isSenario1Bearish = false; +if (useSenario1) +{ + // + isSenario1Happend = cParser.HasRejectedBoxConditions( + X_CYCLE_DECISION, + box, + holderBox, + dir, + waitingBoxes, + provider, + barIndex // + ); + + // + isSenario1Bullish = + isSenario1Happend && + IsBullish(dir); + + // + isSenario1Bearish = + isSenario1Happend && + IsBearish(dir); + + // + if (isSenario1Happend) + { + signalProvider = X121SMC_XWZ_PROVIDER_XREJECTED_BOX; + } +} + +// +// Senario 2: +// --------------------------------------------------- +// Activated Box ... +// --------------------------------------------------- +bool useSenario2 = false; +bool isSenario2Happend = false; +bool isSenario2Bullish = false; +bool isSenario2Bearish = false; +if (!isSenario1Happend && + useSenario2) +{ + // + isSenario2Happend = cParser.HasActivatedBoxConditions( + X_CYCLE_DECISION, + box, + holderBox, + dir, + waitingBoxes, + provider, + barIndex // + ); + + // + isSenario2Bullish = + isSenario2Happend && + IsBullish(dir); + + // + isSenario2Bearish = + isSenario2Happend && + IsBearish(dir); + + // + if (isSenario2Happend) + { + signalProvider = X121SMC_XWZ_PROVIDER_XACTIVATED_BOX; + } +} + +// +// Senario 3: +// --------------------------------------------------- +// Breaked Box ... +// --------------------------------------------------- +bool useSenario3 = false; +bool isSenario3Happend = false; +bool isSenario3Bullish = false; +bool isSenario3Bearish = false; +if (!isSenario1Happend && + !isSenario2Happend && + useSenario3) +{ + // + isSenario3Happend = cParser.HasBreakedBoxConditions( + X_CYCLE_DECISION, + box, + holderBox, + dir, + waitingBoxes, + provider, + barIndex // + ); + + // + isSenario3Bullish = + isSenario3Happend && + IsBullish(dir); + + // + isSenario3Bearish = + isSenario3Happend && + IsBearish(dir); + + // + if (isSenario3Happend) + { + signalProvider = X121SMC_XWZ_PROVIDER_XBREAKED_BOX; + } +} + +// +// Senario 4: +// ----------------------------------------------- +// Detect Signal Box Based On XHKMA Conditions ... +// ----------------------------------------------- +bool useSenario4 = false; +bool isSenario4Happend = false; +bool isSenario4Bullish = false; +bool isSenario4Bearish = false; +if (!isSenario1Happend && + !isSenario2Happend && + !isSenario3Happend && + useSenario4) +{ + // + isSenario4Happend = cParser.HasXHKMAConditions( + 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; + } +} + +// +// Senario 5: +// --------------------------------------------- +// XSHCNZ Signal Box Detection Conditions ... +// --------------------------------------------- +bool useSenario5 = true; +bool isSenario5Happend = false; +bool isSenario5Bullish = false; +bool isSenario5Bearish = false; +if (!isSenario1Happend && + !isSenario2Happend && + !isSenario3Happend && + !isSenario4Happend && + useSenario5) +{ + // + isSenario5Happend = cParser.HasXSHCNZConditions( + X_CYCLE_DECISION, + trend, + box, + dir, + waitingBoxes, + provider, + barIndex // + ); + + // + isSenario5Bullish = + isSenario5Happend && + IsBullish(dir); + + // + isSenario5Bearish = + isSenario5Happend && + IsBearish(dir); + + // + if (isSenario5Happend) + { + signalProvider = X121SMC_XWZ_PROVIDER_XSHCNZ; + } +} diff --git a/Libraries/x-saherelm.x-poi.lib.mq5 b/Libraries/x-saherelm.x-poi.lib.mq5 index 9e0ba169..e84d89c2 100644 --- a/Libraries/x-saherelm.x-poi.lib.mq5 +++ b/Libraries/x-saherelm.x-poi.lib.mq5 @@ -5327,43 +5327,6 @@ struct XBoxZone period == item.period; } - // /** - // * Check Box is Same as another ... - // * - // * @param box: XBoxZone instance Reference ... - // * - // * @return ( bool ) - // */ - // bool IsSame(XBoxZone &box) - // { - // // - // bool result = false; - - // // - // result = IsValid() && - // box.IsValid(); - // if (!result) - // { - // return result; - // } - - // // - // result = - // // - // dir == box.dir && - // from == box.from && - // type == box.type && - // upper == box.upper && - // lower == box.lower && - // symbol == box.symbol && - // period == box.period - // // - // ; - - // // - // return result; - // } - /** * Retrieve Box Age ... * @@ -5409,9 +5372,12 @@ struct XBoxZone string GetTag() { // + string typeStr = IsValid(type) + ? type + : "XBOX"; string result = // - "XBOX" + "_" + + typeStr + "_" + ToString(dir) + "_" + symbol + "_" + ToString(period) + "_" + diff --git a/Libraries/x-saherelm.x-poi.state.lib.mq5 b/Libraries/x-saherelm.x-poi.state.lib.mq5 index a694916e..681afe7b 100644 --- a/Libraries/x-saherelm.x-poi.state.lib.mq5 +++ b/Libraries/x-saherelm.x-poi.state.lib.mq5 @@ -51,6 +51,7 @@ struct XSignalBox // XBoxZone ob; XBoxZone fvg; + XBoxZone sharp; // // Constructor ... @@ -70,6 +71,7 @@ struct XSignalBox // ob.Clean(); fvg.Clean(); + sharp.Clean(); } /** @@ -84,12 +86,43 @@ struct XSignalBox // result = - ob.IsValid(); + ob.IsValid() && + fvg.IsValid() && + sharp.IsValid(); // return result; } + /** + * Update Structure Models To Date ... + * + * @param value: datetime ... + */ + void UpdateTo(datetime value = NULL) + { + // + value = NormalizeTime(value); + + // + if (ob.IsValid()) + { + ob.to = value; + } + + // + if (fvg.IsValid()) + { + fvg.to = value; + } + + // + if (sharp.IsValid()) + { + sharp.to = value; + } + } + // }; 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 0f74a03c..cc5c4bbb 100644 --- a/X121SMCEA/Classes/x-121.smc.market.cycle.helper.class.mq5 +++ b/X121SMCEA/Classes/x-121.smc.market.cycle.helper.class.mq5 @@ -2627,10 +2627,9 @@ struct X121SMCStrategyConditionParser // // Rejected Box ... - bool HasSenario1Conditions( + bool HasRejectedBoxConditions( ENUM_X_CYCLES cycle, XBoxZone &box, - XBoxZone &holderBox, ENUM_X_DIRECTION &dir, XSignalBox &waitingBoxes[], X121SMCStrategySignalProviderData &provider, @@ -2641,10 +2640,16 @@ struct X121SMCStrategyConditionParser bool result = false; // - // Configure ... - bool forceRetestBox = false; - bool forceHolderBox = false; - bool forceConsolidationZone = false; + box.Clean(); + dir = X_DIRECTION_NONE; + + // + // Checking Waiting Baoxes Exists ... + result = HasChild(waitingBoxes); + if (!result) + { + return result; + } // // Fil Selected Data ... @@ -2675,22 +2680,9 @@ struct X121SMCStrategyConditionParser } Parse(cXConditions); - // - // Checking Waiting Baoxes Exists ... - result = HasChild(waitingBoxes); - if (!result) - { - return result; - } - // // Normalize Args ... - // - box.Clean(); - holderBox.Clean(); - dir = X_DIRECTION_NONE; - // if (barIndex < 0) { @@ -2746,6 +2738,7 @@ struct X121SMCStrategyConditionParser } // + // Checking Bar Based on Positions State ... ENUM_X_DIRECTION iBarPosDir; bool isBarValidForDir = cHelper .mBarAnalyser @@ -2761,6 +2754,7 @@ struct X121SMCStrategyConditionParser IsBearish(iBarPosDir); // + // Extract Selected Boxes ... XBoxZone selectedBox; XSignalBox iSignalBox; count = ArraySize(waitingBoxes); @@ -2775,25 +2769,6 @@ struct X121SMCStrategyConditionParser // bool isBullish = iBox.ob.IsBullish(); - bool hasFVG = iBox.fvg.IsValid(); - - // - bool isFVGBullishRejected = - // - hasFVG && - cBar.low < iBox.fvg.upper && - cBar.GetDown() > iBox.fvg.upper - // - ; - - // - bool isFVGBearishRejected = - // - hasFVG && - cBar.high > iBox.fvg.lower && - cBar.GetUp() < iBox.fvg.lower - // - ; // bool isOBBullishRejected = @@ -2814,40 +2789,18 @@ struct X121SMCStrategyConditionParser // has = isBullish - ? (hasFVG - ? isFVGBullishRejected - : isOBBullishRejected) - : (hasFVG - ? isFVGBearishRejected - : isOBBearishRejected); + ? isOBBullishRejected + : isOBBearishRejected; // // Force Using OB ... - if (!has && hasFVG) - { - // - has = isBullish - ? isOBBullishRejected - : isOBBearishRejected; - - // - selectedBox = iBox.ob; - } if (has) { // iSignalBox = iBox; if (!selectedBox.IsValid()) { - // - if (hasFVG) - { - selectedBox = iBox.fvg; - } - else - { - selectedBox = iBox.ob; - } + selectedBox = iBox.ob; } iBox.Clean(); break; @@ -2857,178 +2810,30 @@ struct X121SMCStrategyConditionParser iBox.Clean(); } } - has = + result = iSignalBox.IsValid() && selectedBox.IsValid(); - - // - // Retest Signal ... - int retests = 0; - if (has) + if (!result) { // - int iFromIDX = GetBarIndex( - cBar.symbol, - cBar.period, - selectedBox.from // - ); - has = IsValidIndex(iFromIDX); - if (has) - { - // - // Counting Retests ... - for (int i = iFromIDX; i >= barIndex; i--) - { - // - XOHCL iBar; - has = iBar.Init( - cBar.symbol, - cBar.period, - i // - ); + zBar.Clean(); + cBar.Clean(); + pBar.Clean(); + cState.Clean(); + iSignalBox.Clean(); + selectedBox.Clean(); + ZeroMemory(cHelper); + cConditions.Clean(); + cXConditions.Clean(); - // - bool isBullishRetested = - // - iBar.low < selectedBox.upper && - iBar.GetDown() > selectedBox.upper - // - ; - - // - bool isBearishRetested = - // - iBar.high > selectedBox.lower && - iBar.GetUp() < selectedBox.lower - // - ; - - // - has = selectedBox.IsBullish() - ? isBullishRetested - : isBearishRetested; - if (has) - { - retests++; - } - - // - iBar.Clean(); - } - } + // + return result; } // - bool isSignalBoxRetested = - !forceRetestBox - ? retests >= 1 - : retests >= 2; bool hasSignalBox = iSignalBox.IsValid(); bool isSignalBoxBullish = IsBullish(iSignalBox.ob.dir); - // - // Check Consolidation Zone ... - bool hasBullishCZone = true; - bool hasBearishCZone = true; - if (forceConsolidationZone) - { - // - XBoxZone cZone; - XBoxZone tmpBoxes[]; - if (isSignalBoxBullish) - { - // - ToBox( - cState.bullishConsolidationZones, - tmpBoxes // - ); - } - else - { - // - ToBox( - cState.bearishConsolidationZones, - tmpBoxes // - ); - } - has = HasChild(tmpBoxes); - if (has) - { - // - XBoxZone selectedBox; - if (iSignalBox.fvg.IsValid()) - { - selectedBox = iSignalBox.fvg; - } - else - { - selectedBox = iSignalBox.ob; - } - - // - idx = GetYoungest(tmpBoxes); - has = IsValidIndex(idx); - if (has) - { - // - cZone = tmpBoxes[idx]; - - // - // Check Consolidation Zone Place ... - has = - // - ( - // - IsBoxInsideOr( - cZone, - selectedBox // - ) - // - && - // - cZone.from >= selectedBox.from - // - ) - // - || - // - ( - // - IsBoxInsideOr( - selectedBox, - cZone // - ) - // - && - // - selectedBox.from >= cZone.from - // - ) - // - ; - if (!has) - { - cZone.Clean(); - } - } - - // - selectedBox.Clean(); - } - Clean(tmpBoxes); - - // - hasBullishCZone = cZone.IsValid() && - cZone.IsBullish(); - - // - hasBearishCZone = cZone.IsValid() && - cZone.IsBearish(); - - // - cZone.Clean(); - } - // // Bullish Conditions ... isBullish = @@ -3037,9 +2842,7 @@ struct X121SMCStrategyConditionParser ( // hasSignalBox && - hasBullishCZone && isSignalBoxBullish && - isSignalBoxRetested && isBarValidForBullish // ) @@ -3054,9 +2857,7 @@ struct X121SMCStrategyConditionParser ( // hasSignalBox && - hasBearishCZone && !isSignalBoxBullish && - isSignalBoxRetested && isBarValidForBearish // ) @@ -3079,156 +2880,6 @@ struct X121SMCStrategyConditionParser // box = selectedBox; box.to = TimeCurrent(); - - // - // Detect Holder Box ... - if (forceHolderBox) - { - // - XBoxZone tmpBoxes[]; - if (isBullish) - { - // - // Order Blocks ... - XBoxZone tmp[]; - ToBox( - cState.bullishOrderBlocks, - tmp // - ); - Copy( - tmp, - tmpBoxes // - ); - Clean(tmp); - - // - // Fair Value Gaps ... - ToBox( - cState.bullishFairValueGaps, - tmp // - ); - Copy( - tmp, - tmpBoxes, - false // Ignore Clean ... - ); - Clean(tmp); - - // - // Support Zones ... - ToBox( - cState.supportZones, - tmp // - ); - Copy( - tmp, - tmpBoxes, - false // Ignore Clean ... - ); - Clean(tmp); - } - else - { - // - // Order Blocks ... - XBoxZone tmp[]; - ToBox( - cState.bearishOrderBlocks, - tmp // - ); - Copy( - tmp, - tmpBoxes // - ); - Clean(tmp); - - // - // Fair Value Gaps ... - ToBox( - cState.bearishFairValueGaps, - tmp // - ); - Copy( - tmp, - tmpBoxes, - false // Ignore Clean ... - ); - Clean(tmp); - - // - // Resistance Zones ... - ToBox( - cState.resistanceZones, - tmp // - ); - Copy( - tmp, - tmpBoxes, - false // Ignore Clean ... - ); - Clean(tmp); - } - - // - count = ArraySize(tmpBoxes); - has = IsValidSize(count); - if (has) - { - // - while (HasChild(tmpBoxes)) - { - // - idx = GetOldest(tmpBoxes); - has = IsValidIndex(idx); - if (!has) - { - break; - } - - // - XBoxZone iBox = tmpBoxes[idx]; - ArrayRemove( - tmpBoxes, - idx, - 1 // - ); - - // - has = IsBoxInside( - iBox, - box // - ); - if (has) - { - // - holderBox = iBox; - holderBox.to = TimeCurrent(); - iBox.Clean(); - break; - } - - // - iBox.Clean(); - } - } - - // - Clean(tmpBoxes); - - // - result = - result && - holderBox.IsValid() && - holderBox.dir == dir; - if (!result) - { - // - box.Clean(); - isBullish = false; - isBearish = false; - holderBox.Clean(); - } - } } // @@ -3256,1525 +2907,5 @@ struct X121SMCStrategyConditionParser return result; } - // - // Activated Box - bool HasSenario2Conditions( - ENUM_X_CYCLES cycle, - XBoxZone &box, - XBoxZone &holderBox, - ENUM_X_DIRECTION &dir, - XSignalBox &waitingBoxes[], - X121SMCStrategySignalProviderData &provider, - int barIndex = 0 // - ) - { - // - bool result = false; - - // - // 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); - - // - // Checking Waiting Baoxes Exists ... - result = HasChild(waitingBoxes); - if (!result) - { - return result; - } - - // - // Normalize Args ... - - // - box.Clean(); - holderBox.Clean(); - dir = X_DIRECTION_NONE; - - // - if (barIndex < 0) - { - barIndex = 0; - } - - // - int idx = -1; - int count = 0; - bool has = false; - - // - 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); - - // - XSignalBox iSignalBox; - count = ArraySize(waitingBoxes); - has = IsValidSize(count); - if (has) - { - // - for (int i = 0; i < count; i++) - { - // - XSignalBox iBox = waitingBoxes[i]; - - // - bool isBullish = iBox.ob.IsBullish(); - bool hasFVG = iBox.fvg.IsValid(); - - // - // Checking Inside ... - - // - bool isBullishInsideFVG = - // - hasFVG && - pBar.high < iBox.fvg.upper && - pPBar.high < iBox.fvg.upper - // - ; - - // - bool isBearishInsideFVG = - // - hasFVG && - pBar.low > iBox.fvg.lower && - pPBar.low > iBox.fvg.lower - // - ; - - // - bool isBullishInsideOB = - // - pBar.high < iBox.ob.upper && - pPBar.high < iBox.ob.upper - // - ; - - // - bool isBearishInsideOB = - // - pBar.low > iBox.ob.lower && - pPBar.low > iBox.ob.lower - // - ; - - // - // Checking Breakes Box ... - - // - bool isFVGBullishBreaked = - // - hasFVG && - isBullishInsideFVG && - // - cBar.high > iBox.fvg.upper && - cBar.close > iBox.fvg.upper && - // - zBar.open > iBox.fvg.upper - // - ; - - // - bool isFVGBearishBreaked = - // - hasFVG && - isBearishInsideFVG && - // - cBar.low < iBox.fvg.lower && - cBar.close < iBox.fvg.lower && - // - zBar.open > iBox.fvg.lower - // - ; - - // - bool isOBBullishBreaked = - // - isBullishInsideOB && - // - cBar.high > iBox.ob.upper && - cBar.close > iBox.ob.upper && - // - zBar.open > iBox.ob.upper - // - ; - - // - bool isOBBearishBreaked = - // - isBearishInsideOB && - // - cBar.low < iBox.ob.lower && - cBar.close < iBox.ob.lower && - // - zBar.open > iBox.ob.lower - // - ; - - // - // Summarise ... - - // - bool isBullishBreaked = - isBarValidForBullish && - (hasFVG - ? isFVGBullishBreaked - : isOBBullishBreaked); - - // - bool isBearishBreaked = - isBarValidForBearish && - (hasFVG - ? isFVGBearishBreaked - : isOBBearishBreaked); - - // - has = isBullishBreaked || - isBearishBreaked; - // - if (has) - { - // - iSignalBox = iBox; - iBox.Clean(); - - // - dir = - isBullishBreaked - ? X_DIRECTION_BULLISH - : isBearishBreaked - ? X_DIRECTION_BEARISH - : X_DIRECTION_NONE; - - // - break; - } - - // - iBox.Clean(); - } - } - - // - bool hasSignalBox = HasDirection(dir) && - iSignalBox.IsValid(); - bool isSignalBoxBullish = IsBullish(dir); - - // - // Bullish Conditions ... - isBullish = - // - // Base Condition ... - ( - // - hasSignalBox && - isSignalBoxBullish && - isBarValidForBullish - // - ) - // - ; - - // - // Bearish Conditions ... - isBearish = - // - // Base Condition ... - ( - // - hasSignalBox && - !isSignalBoxBullish && - isBarValidForBearish - // - ) - // - ; - - // - // Filling Requirements ... - result = - isBullish || - isBearish; - if (result) - { - // - dir = - isBullish - ? X_DIRECTION_BULLISH - : X_DIRECTION_BEARISH; - - // - if (iSignalBox.fvg.IsValid()) - { - box = iSignalBox.fvg; - } - else - { - box = iSignalBox.ob; - } - - // - box.to = TimeCurrent(); - - // - // Detect Holder Box ... - XBoxZone tmpBoxes[]; - if (isBullish) - { - // - // Order Blocks ... - XBoxZone tmp[]; - ToBox( - cState.bullishOrderBlocks, - tmp // - ); - Copy( - tmp, - tmpBoxes // - ); - Clean(tmp); - - // - // Fair Value Gaps ... - ToBox( - cState.bullishFairValueGaps, - tmp // - ); - Copy( - tmp, - tmpBoxes, - false // Ignore Clean ... - ); - Clean(tmp); - - // - // Support Zones ... - ToBox( - cState.supportZones, - tmp // - ); - Copy( - tmp, - tmpBoxes, - false // Ignore Clean ... - ); - Clean(tmp); - } - else - { - // - // Order Blocks ... - XBoxZone tmp[]; - ToBox( - cState.bearishOrderBlocks, - tmp // - ); - Copy( - tmp, - tmpBoxes // - ); - Clean(tmp); - - // - // Fair Value Gaps ... - ToBox( - cState.bearishFairValueGaps, - tmp // - ); - Copy( - tmp, - tmpBoxes, - false // Ignore Clean ... - ); - Clean(tmp); - - // - // Resistance Zones ... - ToBox( - cState.resistanceZones, - tmp // - ); - Copy( - tmp, - tmpBoxes, - false // Ignore Clean ... - ); - Clean(tmp); - } - - // - count = ArraySize(tmpBoxes); - has = IsValidSize(count); - if (has) - { - // - while (HasChild(tmpBoxes)) - { - // - idx = GetOldest(tmpBoxes); - has = IsValidIndex(idx); - if (!has) - { - break; - } - - // - XBoxZone iBox = tmpBoxes[idx]; - ArrayRemove( - tmpBoxes, - idx, - 1 // - ); - - // - has = IsBoxInside( - iBox, - box // - ); - if (has) - { - // - holderBox = iBox; - holderBox.to = TimeCurrent(); - iBox.Clean(); - break; - } - - // - iBox.Clean(); - } - } - - // - Clean(tmpBoxes); - - // - result = - result && - holderBox.IsValid() && - holderBox.dir == dir; - if (!result) - { - // - box.Clean(); - isBullish = false; - isBearish = false; - holderBox.Clean(); - } - } - - // - // Check All Conditions ... - result = - box.IsValid() && - HasDirection(dir) && - (isBullish || - isBearish); - - // - // Cleanup Resources ... - zBar.Clean(); - cBar.Clean(); - pBar.Clean(); - pPBar.Clean(); - cState.Clean(); - iSignalBox.Clean(); - ZeroMemory(cHelper); - cConditions.Clean(); - cStateEvents.Clean(); - cXConditions.Clean(); - - // - return result; - } - - // - // Breaked Box - bool HasSenario3Conditions( - ENUM_X_CYCLES cycle, - XBoxZone &box, - XBoxZone &holderBox, - ENUM_X_DIRECTION &dir, - XSignalBox &waitingBoxes[], - X121SMCStrategySignalProviderData &provider, - int barIndex = 0 // - ) - { - // - bool result = false; - - // - // 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); - - // - // Checking Waiting Baoxes Exists ... - result = HasChild(waitingBoxes); - if (!result) - { - return result; - } - - // - // Normalize Args ... - - // - box.Clean(); - holderBox.Clean(); - dir = X_DIRECTION_NONE; - - // - if (barIndex < 0) - { - barIndex = 0; - } - - // - int idx = -1; - int count = 0; - bool has = false; - - // - 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); - - // - XSignalBox iSignalBox; - count = ArraySize(waitingBoxes); - has = IsValidSize(count); - if (has) - { - // - for (int i = 0; i < count; i++) - { - // - XSignalBox iBox = waitingBoxes[i]; - - // - bool isBullish = iBox.ob.IsBullish(); - bool hasFVG = iBox.fvg.IsValid(); - - // - // Checking Breakes Box ... - - // - bool isFVGBullishBreaked = - // - hasFVG && - // - pBar.low < iBox.fvg.upper && - // - cBar.high > iBox.fvg.upper && - cBar.close > iBox.fvg.upper && - // - zBar.open > iBox.fvg.upper - // - ; - - // - bool isFVGBearishBreaked = - // - hasFVG && - // - pBar.high > iBox.fvg.lower && - // - cBar.low < iBox.fvg.lower && - cBar.close < iBox.fvg.lower && - // - zBar.open > iBox.fvg.lower - // - ; - - // - bool isOBBullishBreaked = - // - pBar.low < iBox.ob.upper && - // - cBar.high > iBox.ob.upper && - cBar.close > iBox.ob.upper && - // - zBar.open > iBox.ob.upper - // - ; - - // - bool isOBBearishBreaked = - // - pBar.high > iBox.ob.lower && - // - cBar.low < iBox.ob.lower && - cBar.close < iBox.ob.lower && - // - zBar.open > iBox.ob.lower - // - ; - - // - // Summarise ... - - // - bool isBullishBreaked = - isBarValidForBullish && - (hasFVG - ? isFVGBullishBreaked - : isOBBullishBreaked); - - // - bool isBearishBreaked = - isBarValidForBearish && - (hasFVG - ? isFVGBearishBreaked - : isOBBearishBreaked); - - // - has = isBullishBreaked || - isBearishBreaked; - // - if (has) - { - // - iSignalBox = iBox; - iBox.Clean(); - - // - dir = - isBullishBreaked - ? X_DIRECTION_BULLISH - : isBearishBreaked - ? X_DIRECTION_BEARISH - : X_DIRECTION_NONE; - - // - break; - } - - // - iBox.Clean(); - } - } - - // - bool hasSignalBox = HasDirection(dir) && - iSignalBox.IsValid(); - bool isSignalBoxBullish = IsBullish(dir); - - // - // Bullish Conditions ... - isBullish = - // - // Base Condition ... - ( - // - hasSignalBox && - isSignalBoxBullish && - isBarValidForBullish - // - ) - // - ; - - // - // Bearish Conditions ... - isBearish = - // - // Base Condition ... - ( - // - hasSignalBox && - !isSignalBoxBullish && - isBarValidForBearish - // - ) - // - ; - - // - // Filling Requirements ... - result = - isBullish || - isBearish; - if (result) - { - // - dir = - isBullish - ? X_DIRECTION_BULLISH - : X_DIRECTION_BEARISH; - - // - if (iSignalBox.fvg.IsValid()) - { - box = iSignalBox.fvg; - } - else - { - box = iSignalBox.ob; - } - - // - box.to = TimeCurrent(); - - // - // Detect Holder Box ... - XBoxZone tmpBoxes[]; - if (isBullish) - { - // - // Order Blocks ... - XBoxZone tmp[]; - ToBox( - cState.bullishOrderBlocks, - tmp // - ); - Copy( - tmp, - tmpBoxes // - ); - Clean(tmp); - - // - // Fair Value Gaps ... - ToBox( - cState.bullishFairValueGaps, - tmp // - ); - Copy( - tmp, - tmpBoxes, - false // Ignore Clean ... - ); - Clean(tmp); - - // - // Support Zones ... - ToBox( - cState.supportZones, - tmp // - ); - Copy( - tmp, - tmpBoxes, - false // Ignore Clean ... - ); - Clean(tmp); - } - else - { - // - // Order Blocks ... - XBoxZone tmp[]; - ToBox( - cState.bearishOrderBlocks, - tmp // - ); - Copy( - tmp, - tmpBoxes // - ); - Clean(tmp); - - // - // Fair Value Gaps ... - ToBox( - cState.bearishFairValueGaps, - tmp // - ); - Copy( - tmp, - tmpBoxes, - false // Ignore Clean ... - ); - Clean(tmp); - - // - // Resistance Zones ... - ToBox( - cState.resistanceZones, - tmp // - ); - Copy( - tmp, - tmpBoxes, - false // Ignore Clean ... - ); - Clean(tmp); - } - - // - count = ArraySize(tmpBoxes); - has = IsValidSize(count); - if (has) - { - // - while (HasChild(tmpBoxes)) - { - // - idx = GetOldest(tmpBoxes); - has = IsValidIndex(idx); - if (!has) - { - break; - } - - // - XBoxZone iBox = tmpBoxes[idx]; - ArrayRemove( - tmpBoxes, - idx, - 1 // - ); - - // - has = IsBoxInside( - iBox, - box // - ); - if (has) - { - // - holderBox = iBox; - holderBox.to = TimeCurrent(); - iBox.Clean(); - break; - } - - // - iBox.Clean(); - } - } - - // - Clean(tmpBoxes); - - // - result = - result && - holderBox.IsValid() && - holderBox.dir == dir; - if (!result) - { - // - box.Clean(); - isBullish = false; - isBearish = false; - holderBox.Clean(); - } - } - - // - // Check All Conditions ... - result = - box.IsValid() && - HasDirection(dir) && - (isBullish || - isBearish); - - // - // Cleanup Resources ... - zBar.Clean(); - cBar.Clean(); - pBar.Clean(); - pPBar.Clean(); - cState.Clean(); - iSignalBox.Clean(); - ZeroMemory(cHelper); - cConditions.Clean(); - cStateEvents.Clean(); - cXConditions.Clean(); - - // - 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(); - - // - // Detecting Consolidation Zone ... - XBoxZone cZone; - if (hasBullishTrend) - { - // - ToBox( - cState.bullishConsolidationZones, - tmpBoxes // - ); - } - else if (hasBearishTrend) - { - // - ToBox( - cState.bearishConsolidationZones, - tmpBoxes // - ); - } - has = HasChild(tmpBoxes); - if (has) - { - // - idx = GetYoungest(tmpBoxes); - has = IsValidIndex(idx); - if (has) - { - // - cZone = tmpBoxes[idx]; - - // - // Check Consolidation Zone Place ... - has = - // - ( - // - IsBoxInsideOr( - cZone, - zoneBox // - ) - // - && - // - cZone.from >= zoneBox.from - // - ) - // - || - // - ( - // - IsBoxInsideOr( - zoneBox, - cZone // - ) - // - && - // - zoneBox.from >= cZone.from - // - ) - // - ; - if (!has) - { - cZone.Clean(); - } - } - } - Clean(tmpBoxes); - - // - bool hasBullishCZone = cZone.IsValid() && - cZone.IsBullish(); - - // - bool hasBearishCZone = cZone.IsValid() && - cZone.IsBearish(); - - // - // Summarize Conditions ... - - // - // Bullish ... - isBullish = - // - // Base Bullish Conditions ... - hasBullishTrend && - hasBullishCZone && - hasBullishZoneBox && - hasBullishSignalBox && - isBarValidForBullish && - // - // Other Additional Conditions ... - true - // - ; - - // - // Bearish ... - isBearish = - // - // Base Bearish Conditions ... - hasBearishTrend && - hasBearishCZone && - 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(); - cZone.to = TimeCurrent(); - - // - if (result) - { - // - XCPOIDrawer *drawer = provider.visionCycleHelper.mPOIDrawer; - - // - XCBoxObject *iObj; - has = drawer.DrawBox( - box, - iObj // - ); - - // - XCBoxObject *iCObject; - has = drawer.DrawBox( - cZone, - iCObject // - ); - if (has) - { - // - iCObject.BoxColor(clrLime); - iCObject.BoxStyle(STYLE_SOLID); - } - - // - Print("Found ..."); - - // - ZeroMemory(drawer); - } - } - - // - // Cleanup Resources ... - zBar.Clean(); - cBar.Clean(); - pBar.Clean(); - pPBar.Clean(); - cZone.Clean(); - cState.Clean(); - zoneBox.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 cc614a73..2f6b4edf 100644 --- a/X121SMCEA/Signals/x-121.smc.xwz.signal.class.mq5 +++ b/X121SMCEA/Signals/x-121.smc.xwz.signal.class.mq5 @@ -172,9 +172,8 @@ class XCX121SMCXWZSignalDetector : public XCBase double point = 0; double targets[]; double reward = 0; - XBoxZone signalBox; + XSignalBox signalBox; bool hasTrend = false; - XBoxZone signalHolderBox; bool hasPriority = false; double amountPercent = -1; bool hasSignalBox = false; @@ -279,18 +278,14 @@ class XCX121SMCXWZSignalDetector : public XCBase // // Draw Working Zone ... - if (hasWorkingZone) - { + workingZone.Draw( + drawer, // - workingZone.Draw( - drawer, - // - true, // Draw Supply Zone ... - true, // Draw Demand Zone ... - true, // Draw Waiting Zones ... - true // Draw Trend ... - ); - } + false, // Draw Supply Zone ... + false, // Draw Demand Zone ... + true, // Draw Waiting Zones ... + false // Draw Trend ... + ); // // Detect Signal Box ... @@ -298,7 +293,6 @@ class XCX121SMCXWZSignalDetector : public XCBase hasWorkingZone && workingZone.DetectSignalConditions( signalBox, - signalHolderBox, signalBoxDir, signalProvider, provider, @@ -306,6 +300,10 @@ class XCX121SMCXWZSignalDetector : public XCBase ); // + // Remove Signal Box form + // Waiting Boxes and Breaked Boxes + // if Exists on them, then add it to + // UnAvailable Boxes ... if (hasSignalBox) { // @@ -355,6 +353,13 @@ class XCX121SMCXWZSignalDetector : public XCBase ); } } + + // + // Adding to UnAvailable Box ... + AddRef( + signalBox, + workingZone.unavailableBoxes // + ); } // @@ -367,27 +372,30 @@ class XCX121SMCXWZSignalDetector : public XCBase { // signalBox.Clean(); - signalHolderBox.Clean(); signalBoxDir = X_DIRECTION_NONE; } // // Check Priority Exists ... - hasPriority = workingZone - .DetectPriority( - priority, - signalBoxDir, - zIndex, - period // - ); + hasPriority = + hasWorkingZone && + workingZone + .DetectPriority( + priority, + signalBoxDir, + zIndex, + period // + ); // // Check Price Reward and Amount Exists ... - hasRewardAmount = CalculateRiskReward( - priority, - reward, - amountPercent // - ); + hasRewardAmount = + hasWorkingZone && + CalculateRiskReward( + priority, + reward, + amountPercent // + ); // // Check Signal Conditions ... @@ -399,37 +407,22 @@ class XCX121SMCXWZSignalDetector : public XCBase // // Draw Signal Box ... - XCBoxObject *iSignalBoxObj; - has = drawer.DrawBox( + XCBaseObject *objects[]; + has = drawer.DrawSignalBox( signalBox, - iSignalBoxObj // + objects, + clrYellow // ); if (has) { // - iSignalBoxObj.BoxWidth(1); - iSignalBoxObj.BoxColor(clrYellow); - iSignalBoxObj.BoxStyle(STYLE_SOLID); - - // - workingZone.mDrawnObjects.Add(iSignalBoxObj); - } - - // - // Draw Signal Holder Box if Exists ... - if (signalHolderBox.IsValid()) - { - // - XCBoxObject *iSignalHolderBoxObj; - has = drawer.DrawBox( - signalHolderBox, - iSignalHolderBoxObj // - ); - if (has) + int count = ArraySize(objects); + for (int i = 0; i < count; i++) { - workingZone.mDrawnObjects.Add(iSignalHolderBoxObj); + workingZone.mDrawnObjects.Add(objects[i]); } } + Clean(objects); // // Detect Signal Direction ... @@ -438,17 +431,17 @@ class XCX121SMCXWZSignalDetector : public XCBase // pivot = isBullish - ? signalBox.lower - : signalBox.upper; + ? signalBox.ob.lower + : signalBox.ob.upper; // point = isBullish - ? signalBox.upper - : signalBox.lower; + ? signalBox.ob.upper + : signalBox.ob.lower; // double entry = GetEntry( - signalBox.symbol, + signalBox.ob.symbol, signalBoxDir // ); @@ -471,41 +464,12 @@ class XCX121SMCXWZSignalDetector : public XCBase // // Select and Provide SL Based on ... double iAtr = 0; - if (signalProvider == X121SMC_XWZ_PROVIDER_XHKMA) + if (signalProvider == X121SMC_XWZ_PROVIDER_XREJECTED_BOX) { // 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) - { - // - iAtr = provider.decisionXConditions.atrBuffer[1]; - iAtr *= 0; - - // - Clean(sls); - - // - // Prepare Box fro SL ... - iSL = signalBox.lower + ((signalBox.upper - signalBox.lower) / 2); - Add( - iSL, - sls // - ); - // // Fix rf Reward ... rfRewar = 2; @@ -900,7 +864,7 @@ class XCX121SMCXWZSignalDetector : public XCBase mConditions.setupTime = cTime; mConditions.dir = signalBoxDir; mConditions.priority = priority; - mConditions.signalBox = signalBox; + mConditions.signalBox = signalBox.ob; mConditions.provider = signalProvider; mConditions.amountPercent = amountPercent; } @@ -921,7 +885,6 @@ class XCX121SMCXWZSignalDetector : public XCBase // signalBox.Clean(); - signalHolderBox.Clean(); consolidationZBar.Clean(); // diff --git a/X121SMCEA/Signals/x-121.smc.xwz.signal.lib.mq5 b/X121SMCEA/Signals/x-121.smc.xwz.signal.lib.mq5 index 94fc39e0..618ebbac 100644 --- a/X121SMCEA/Signals/x-121.smc.xwz.signal.lib.mq5 +++ b/X121SMCEA/Signals/x-121.smc.xwz.signal.lib.mq5 @@ -31,7 +31,6 @@ enum ENUM_X121SMC_XWZ_PROVIDERS { X121SMC_XWZ_PROVIDER_NONE, - X121SMC_XWZ_PROVIDER_XHKMA, X121SMC_XWZ_PROVIDER_XBREAKED_BOX, X121SMC_XWZ_PROVIDER_XREJECTED_BOX, X121SMC_XWZ_PROVIDER_XACTIVATED_BOX, @@ -488,6 +487,7 @@ struct X121SMCStrategyXWZWorkingZone int idx = -1; int count = 0; bool has = false; + datetime cTime = TimeCurrent(); // if (barIndex < 0) @@ -559,235 +559,19 @@ struct X121SMCStrategyXWZWorkingZone } // - // Select Order Blocks ... - if (obStateEvents.hasNewOrderBlock) - { - // - idx = GetYoungest(obState.orderBlocks); - has = IsValidIndex(idx); - if (has) - { - // - XCFVG *iFVG = NULL; - XCOrderBlock *iOB = obState.orderBlocks[idx]; - bool isBullish = iOB.IsBullish(); - - // - // Detecting Inside FVG ... - has = fvgState.HasFairValueGaps(); - if (has) - { - // - XCFVG *tmpFVGs[]; - count = fvgState.CountFairValueGaps(); - for (int i = 0; i < count; i++) - { - // - XCFVG *jFVG = fvgState.fairValueGaps[i]; - - // - bool isDirPassed = jFVG.GetDirection() == iOB.GetDirection(); - bool isFromPassed = jFVG.From() >= iOB.From(); - bool isPlacePassed = IsInsideOrDiff( - jFVG, - iOB, - false // - ); - - // - has = isDirPassed && - isFromPassed && - isPlacePassed; - if (has) - { - // - Add( - jFVG, - tmpFVGs // - ); - } - - // - ZeroMemory(jFVG); - } - - // - // Selecting iFVG Based on Direction of OB ... - has = HasChild(tmpFVGs); - if (has) - { - // - idx = - isBullish - ? GetLowest(tmpFVGs) - : GetHighest(tmpFVGs); - has = IsValidIndex(idx); - if (has) - { - iFVG = tmpFVGs[idx]; - } - } - - // - Clean(tmpFVGs); - } - - // - XBoxZone iOBBox; - XBoxZone iFVGBox; - if (iFVG != NULL) - { - // - has = ToBox( - iFVGBox, - iFVG // - ); - } - - // - has = ToBox( - iOBBox, - iOB // - ); - - // - has = iOBBox.IsValid() && - iFVGBox.IsValid(); - if (has) - { - // - XSignalBox iSignalBox; - - // - iSignalBox.ob = iOBBox; - iSignalBox.fvg = iFVGBox; - - // - // Here We Check Waiting Box Contains Other Zones ... - // Like Support/Resistances ... - bool forceVerification = false; - if (forceVerification) - { - // - XBoxZone iVerificationBox; - XBoxZone tmpBoxes[]; - if (isBullish) - { - // - ToBox( - provider.decisionState.supportZones, - tmpBoxes // - ); - } - else - { - // - ToBox( - provider.decisionState.resistanceZones, - tmpBoxes // - ); - } - has = HasChild(tmpBoxes); - if (has) - { - // - while (HasChild(tmpBoxes)) - { - // - idx = GetYoungest(tmpBoxes); - has = IsValidIndex(idx); - if (!has) - { - break; - } - - // - // Select Box ... - XBoxZone iBox = tmpBoxes[idx]; - ArrayRemove( - tmpBoxes, - idx, - 1 // - ); - - // - // Validate Box ... - bool isValidPassed = !IsBoxValid( - iBox, - barIndex // - ); - bool isDirPassed = iBox.dir == iOBBox.dir; - bool isPlacePassed = - IsBoxInside( - iBox, - iOBBox // - ) - // - && - // - (!iFVGBox.IsValid() - ? true - : IsBoxInsideOr( - iBox, - iFVGBox // - )); - - // - has = - isDirPassed && - isValidPassed && - isPlacePassed; - if (has) - { - // - iVerificationBox = iBox; - iBox.Clean(); - break; - } - - // - iBox.Clean(); - } - } - has = iVerificationBox.IsValid(); - Clean(tmpBoxes); - iVerificationBox.Clean(); - } - - // - if (has) - { - // - AddRef( - iSignalBox, - waitingBoxes // - ); - } - - // - iSignalBox.Clean(); - } - - // - iOBBox.Clean(); - iFVGBox.Clean(); - ZeroMemory(iOB); - ZeroMemory(iFVG); - } - } - - // - // Checking Other Senario for Waiting Boxes ... + // Detect a Sharp Zone Which Contains + // an Order Block and Also an FVG ... if (obStateEvents.hasNewSharp) { // + XBoxZone ob; + XBoxZone fvg; XBoxZone currSharp; XBoxZone prevSharp; XBoxZone sharpConsolidation; // // Retrieve Current Sharp ... - XCPOIDrawer *drawer = provider.visionCycleHelper.mPOIDrawer; XBoxZone tmpBoxes[]; Copy( obState.sharps, @@ -906,37 +690,225 @@ struct X121SMCStrategyXWZWorkingZone } // + // Detect Order Block / FVG ... has = sharpConsolidation.IsValid(); + if (has) + { + // + // Check Direction ... + bool isBullish = sharpConsolidation.IsBullish(); + + // + // Find Inside Order Block ... + Clean(tmpBoxes); + if (isBullish) + { + // + ToBox( + obState.bullishOrderBlocks, + tmpBoxes // + ); + } + else + { + // + ToBox( + obState.bearishOrderBlocks, + tmpBoxes // + ); + } + + // + // Select Order Block ... + has = HasChild(tmpBoxes); + if (has) + { + // + while (HasChild(tmpBoxes)) + { + // + idx = GetYoungest(tmpBoxes); + has = IsValidIndex(idx); + if (!has) + { + break; + } + + // + XBoxZone iBox = tmpBoxes[idx]; + ArrayRemove( + tmpBoxes, + idx, + 1 // + ); + + // + // Validate Selected Box ... + bool isDirPassed = iBox.dir == sharpConsolidation.dir; + bool isFromPassed = iBox.from > sharpConsolidation.from; + bool isInsidePassed = IsBoxInside( + iBox, + sharpConsolidation // + ); + bool isValidationPassed = IsBoxValid( + iBox, + barIndex // + ); + + // + has = isDirPassed && + isFromPassed && + isInsidePassed && + isValidationPassed; + if (has) + { + ob = iBox; + } + + // + iBox.Clean(); + + // + if (ob.IsValid()) + { + break; + } + } + } + Clean(tmpBoxes); + + // + // Find Inside FVG ... + has = ob.IsValid(); + if (has) + { + // + Clean(tmpBoxes); + if (isBullish) + { + // + ToBox( + fvgState.bullishFairValueGaps, + tmpBoxes // + ); + } + else + { + // + ToBox( + fvgState.bearishFairValueGaps, + tmpBoxes // + ); + } + + // + // Select FVG ... + has = HasChild(tmpBoxes); + if (has) + { + // + while (HasChild(tmpBoxes)) + { + // + idx = isBullish + ? GetLowest(tmpBoxes) + : GetHighest(tmpBoxes); + has = IsValidIndex(idx); + if (!has) + { + break; + } + + // + XBoxZone iBox = tmpBoxes[idx]; + ArrayRemove( + tmpBoxes, + idx, + 1 // + ); + + // + // Validate Selected Box ... + bool isDirPassed = iBox.dir == ob.dir; + bool isFromPassed = iBox.from > ob.from; + bool isInsidePassed = IsBoxInside( + iBox, + ob // + ); + + // + has = isDirPassed && + isFromPassed && + isInsidePassed; + if (has) + { + fvg = iBox; + } + + // + iBox.Clean(); + + // + if (fvg.IsValid()) + { + break; + } + } + } + Clean(tmpBoxes); + } + } + + // + // Checking Validation of Boxes ... + has = ob.IsValid() && + fvg.IsValid() && + sharpConsolidation.IsValid(); + if (has) + { + // + // Update Time ... + ob.to = cTime; + fvg.to = cTime; + sharpConsolidation.to = cTime; + + // + XSignalBox iSBox; + + // + iSBox.ob = ob; + iSBox.fvg = fvg; + iSBox.sharp = sharpConsolidation; + + // + has = iSBox.IsValid(); + if (has) + { + // + AddRef( + iSBox, + waitingBoxes // + ); + } + + // + iSBox.Clean(); + } + + // + ob.Clean(); + fvg.Clean(); + toBar.Clean(); + currSharp.Clean(); + prevSharp.Clean(); + sharpConsolidation.Clean(); } // - if (has) - { - // - XCBoxObject *iCurrObj; - XCBoxObject *iPrevObj; - XCBoxObject *iSharpConsolidationObj; - has = drawer.DrawBox( - currSharp, - iCurrObj // - ); - has = - has && - drawer.DrawBox( - prevSharp, - iPrevObj // - ); - has = - has && - drawer.DrawBox( - sharpConsolidation, - iSharpConsolidationObj // - ); - if (has) - { - Print("Sharp Detection ..."); - } - } + Clean(tmpBoxes); + currSharp.Clean(); + prevSharp.Clean(); + sharpConsolidation.Clean(); } // @@ -1017,15 +989,6 @@ struct X121SMCStrategyXWZWorkingZone // has = isInite && ( - // - IsBoxBreaked( - iBox.fvg, - iBar.Index() - 1, - barIndex, - period // - ) - // - || // IsBoxBreaked( iBox.ob, @@ -1335,14 +1298,7 @@ struct X121SMCStrategyXWZWorkingZone count = CountWaitingBoxes(); for (int i = 0; i < count; i++) { - // - waitingBoxes[i].ob.to = value; - - // - if (waitingBoxes[i].fvg.IsValid()) - { - waitingBoxes[i].fvg.to = value; - } + waitingBoxes[i].UpdateTo(value); } } @@ -1443,7 +1399,6 @@ struct X121SMCStrategyXWZWorkingZone * Detect Signal Box Conditions ... * * @param box: XBoxZone instance reference, Signalled Box ... - * @param holderBox: XBoxZone instance reference, Signalled Holder Box ... * @param dir: ENUM_X_DIRECTION member, Specified Signal Direction ... * @param signalProvider: ENUM_X121SMC_XWZ_PROVIDERS member, Specified Signal Type ... * @param provider: X121SMCStrategySignalProviderData instance reference ... @@ -1452,8 +1407,7 @@ struct X121SMCStrategyXWZWorkingZone * @return ( bool ) */ bool DetectSignalConditions( - XBoxZone &box, - XBoxZone &holderBox, + XSignalBox &box, ENUM_X_DIRECTION &dir, ENUM_X121SMC_XWZ_PROVIDERS &signalProvider, X121SMCStrategySignalProviderData &provider, @@ -1468,7 +1422,6 @@ struct X121SMCStrategyXWZWorkingZone // box.Clean(); - holderBox.Clean(); dir = X_DIRECTION_NONE; signalProvider = X121SMC_XWZ_PROVIDER_NONE; @@ -1507,14 +1460,14 @@ struct X121SMCStrategyXWZWorkingZone // --------------------------------------------- // Rejected Box ... // --------------------------------------------- - bool useSenario1 = true; + bool useSenario1 = false; bool isSenario1Happend = false; bool isSenario1Bullish = false; bool isSenario1Bearish = false; if (useSenario1) { // - isSenario1Happend = cParser.HasSenario1Conditions( + isSenario1Happend = cParser.HasRejectedBoxConditions( X_CYCLE_DECISION, box, holderBox, @@ -1553,32 +1506,6 @@ struct X121SMCStrategyXWZWorkingZone if (!isSenario1Happend && useSenario2) { - // - isSenario2Happend = cParser.HasSenario2Conditions( - X_CYCLE_DECISION, - box, - holderBox, - dir, - waitingBoxes, - provider, - barIndex // - ); - - // - isSenario2Bullish = - isSenario2Happend && - IsBullish(dir); - - // - isSenario2Bearish = - isSenario2Happend && - IsBearish(dir); - - // - if (isSenario2Happend) - { - signalProvider = X121SMC_XWZ_PROVIDER_XACTIVATED_BOX; - } } // @@ -1594,32 +1521,6 @@ struct X121SMCStrategyXWZWorkingZone !isSenario2Happend && useSenario3) { - // - isSenario3Happend = cParser.HasSenario3Conditions( - X_CYCLE_DECISION, - box, - holderBox, - dir, - waitingBoxes, - provider, - barIndex // - ); - - // - isSenario3Bullish = - isSenario3Happend && - IsBullish(dir); - - // - isSenario3Bearish = - isSenario3Happend && - IsBearish(dir); - - // - if (isSenario3Happend) - { - signalProvider = X121SMC_XWZ_PROVIDER_XBREAKED_BOX; - } } // @@ -1636,40 +1537,14 @@ 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; - } } // // Senario 5: // --------------------------------------------- + // XSHCNZ Signal Box Detection Conditions ... // --------------------------------------------- - bool useSenario5 = false; + bool useSenario5 = true; bool isSenario5Happend = false; bool isSenario5Bullish = false; bool isSenario5Bearish = false; @@ -1708,7 +1583,8 @@ struct X121SMCStrategyXWZWorkingZone isSenario2Bullish || isSenario3Bullish || isSenario4Bullish || - isSenario5Bullish + isSenario5Bullish || + isSenario6Bullish // ; @@ -1719,7 +1595,8 @@ struct X121SMCStrategyXWZWorkingZone isSenario2Bearish || isSenario3Bearish || isSenario4Bearish || - isSenario5Bearish + isSenario5Bearish || + isSenario6Bearish // ; @@ -1876,13 +1753,13 @@ struct X121SMCStrategyXWZWorkingZone * * @param drawSupplyZone: boolean ... * @param drawDemandZone: boolean ... - * @param drawWaitingZones: boolean ... + * @param drawWaitingBoxes: boolean ... */ void Draw( XCPOIDrawer *drawer, bool drawSupplyZone = false, bool drawDemandZone = false, - bool drawWaitingZones = false, + bool drawWaitingBoxes = false, bool drawTrend = false // ) { @@ -2108,7 +1985,7 @@ struct X121SMCStrategyXWZWorkingZone // // Waiting Zones ... - if (drawWaitingZones) + if (drawWaitingBoxes) { // has = HasWaitingBoxes(); @@ -2119,42 +1996,21 @@ struct X121SMCStrategyXWZWorkingZone for (int i = 0; i < count; i++) { // - // OB ... - XCBoxObject *iOBBoxObj; - has = drawer.DrawBox( - waitingBoxes[i].ob, - iOBBoxObj // + XCBaseObject *objects[]; + has = drawer.DrawSignalBox( + waitingBoxes[i], + objects // ); if (has) - { - mDrawnObjects.Add(iOBBoxObj); - } - - // - // FVG ... - if (waitingBoxes[i].fvg.IsValid()) { // - XCBoxObject *iFVGBoxObj; - has = drawer.DrawBox( - waitingBoxes[i].fvg, - iFVGBoxObj // - ); - if (has) + count = ArraySize(objects); + for (int i = 0; i < count; i++) { - // - iFVGBoxObj.BoxStyle(STYLE_SOLID); - - // - mDrawnObjects.Add(iFVGBoxObj); + mWorkingZoneObjects.Add(objects[i]); } - - // - ZeroMemory(iFVGBoxObj); } - - // - ZeroMemory(iOBBoxObj); + Clean(objects); } } } diff --git a/X121SMCEA/Strategy/x-121.smc.strategy.class.mq5 b/X121SMCEA/Strategy/x-121.smc.strategy.class.mq5 index b7b89f31..d65d3487 100644 --- a/X121SMCEA/Strategy/x-121.smc.strategy.class.mq5 +++ b/X121SMCEA/Strategy/x-121.smc.strategy.class.mq5 @@ -835,8 +835,8 @@ class XCX121SMCStrategy : public XCX121SMCBaseStrategy // // XVWAP ... - x121Inputs.xvwapInputs.showVWapFast = showAll || false; - x121Inputs.xvwapInputs.showVWapMedium = showAll || false; + x121Inputs.xvwapInputs.showVWapFast = showAll || true; + x121Inputs.xvwapInputs.showVWapMedium = showAll || true; x121Inputs.xvwapInputs.showVWapSlow = showAll || false; //