diff --git a/Documents/BKP/xsupdem/plib.tmp.codes.mq5 b/Documents/BKP/xsupdem/plib.tmp.codes.mq5 index c5bb2226..66a1e44e 100644 --- a/Documents/BKP/xsupdem/plib.tmp.codes.mq5 +++ b/Documents/BKP/xsupdem/plib.tmp.codes.mq5 @@ -1053,3 +1053,994 @@ bool IsReject( // return result; } + + + // + bool HasConditions( + ENUM_X_DIRECTION &conditionsDir, + XPOIState &state, + int barIndex = 0, + ENUM_TIMEFRAMES forPeriod = NULL // + ) + { + // + bool result = false; + + // + conditionsDir = X_DIRECTION_NONE; + + // + if (barIndex < 0) + { + barIndex = 0; + } + + // + if (forPeriod == NULL) + { + forPeriod = period; + } + + // + result = + // + IsValid(symbol) && + IsValid(period) && + state.IsValid() && + HasWorkingZone() && + state.HasChild() + // + ; + if (!result) + { + return result; + } + + // + result = false; + + // + // Detect Conditions Based On Start Zones ... + bool hasStartZones = HasStartZones(); + if (hasStartZones) + { + // + int count = CountStartZones(); + for (int i = 0; i < count; i++) + { + // + X121SMCXWZZone iStartZone = startZones[i]; + + // + XBoxZone insideBox; + bool isPriceInside = iStartZone.IsPriceInside( + insideBox, + barIndex, + forPeriod // + ); + if (!isPriceInside) + { + // + iStartZone.Clean(); + continue; + } + + // + Print("PriceInside ..."); + + // + bool hasConditions = iStartZone.HasCondition( + insideBox, + state, + barIndex, + forPeriod // + ); + if (!hasConditions) + { + // + iStartZone.Clean(); + continue; + } + + // + iStartZone.Clean(); + } + } + + // + // Detect Conditions Based On Working Zones ... + if (!result) + { + // + // Detect Result Based On WorkingZone ... + } + + // + return result; + } + + + // + bool HasCondition( + XBoxZone &box, + XPOIState &state, + int barIndex = 0, + ENUM_TIMEFRAMES forPeriod = NULL // + ) + { + // + bool result = false; + + // + if (barIndex < 0) + { + barIndex = 0; + } + + // + swingBar.Clean(); + breakerBar.Clean(); + appliedBox.Clean(); + momentumBar.Clean(); + rejectionBar.Clean(); + + // + result = IsValid() && + box.IsValid() && + HasDirection() && + state.IsValid() && + state.HasChild(); + if (!result) + { + // + swingBar.Clean(); + breakerBar.Clean(); + appliedBox.Clean(); + momentumBar.Clean(); + rejectionBar.Clean(); + + // + return result; + } + + // + string symbol = box.symbol; + if (!IsValid(forPeriod)) + { + forPeriod = box.period; + } + datetime cTime = iTime( + symbol, + forPeriod, + barIndex // + ); + + // + ENUM_X_DIRECTION forDir = box.dir; + bool isBullish = IsBullish(forDir); + + // + int supportsCount = 0; + bool hasSupports = false; + XCSupportZone *supports[]; + + // + int resistancesCount = 0; + bool hasResistances = false; + XCResistanceZone *resistances[]; + + // + XBoxZone supResBoxes[]; + int supresBoxesCount = 0; + bool hasSupResBoxes = false; + + // + int count = 0; + bool has = false; + + // + has = state.HasSupportZones(); + if (has) + { + // + count = state.CountSupportZones(); + for (int i = 0; i < count; i++) + { + // + XCSupportZone *iZone = state.supportZones[i]; + + // + iZone.To(cTime); + + // + XBoxZone iBox; + bool hasBox = ToBox( + iBox, + iZone // + ); + if (!hasBox) + { + // + iBox.Clean(); + continue; + } + + // + // Check From ... + bool isInside = IsBoxInside( + iBox, + box // + ); + if (!isInside) + { + // + iBox.Clean(); + continue; + } + + // + Add( + iZone, + supports // + ); + + // + AddRef( + iBox, + supResBoxes // + ); + + // + iBox.Clean(); + } + + // + supportsCount = ArraySize(supports); + hasSupports = IsValidSize(supportsCount); + + // + supresBoxesCount = ArraySize(supResBoxes); + hasSupResBoxes = IsValidSize(supresBoxesCount); + } + + // + has = state.HasResistanceZones(); + if (has) + { + // + count = state.CountResistanceZones(); + for (int i = 0; i < count; i++) + { + // + XCResistanceZone *iZone = state.resistanceZones[i]; + + // + iZone.To(cTime); + + // + XBoxZone iBox; + bool hasBox = ToBox( + iBox, + iZone // + ); + if (!hasBox) + { + // + iBox.Clean(); + continue; + } + + // + // Check From ... + bool isInside = IsBoxInside( + iBox, + box // + ); + if (!isInside) + { + // + iBox.Clean(); + continue; + } + + // + Add( + iZone, + resistances // + ); + + // + AddRef( + iBox, + supResBoxes // + ); + + // + iBox.Clean(); + } + + // + resistancesCount = ArraySize(resistances); + hasResistances = IsValidSize(resistancesCount); + + // + supresBoxesCount = ArraySize(supResBoxes); + hasSupResBoxes = IsValidSize(supresBoxesCount); + } + + // + result = hasSupResBoxes; + if (!result) + { + // + Clean(supports); + Clean(resistances); + Clean(supResBoxes); + + // + swingBar.Clean(); + breakerBar.Clean(); + appliedBox.Clean(); + momentumBar.Clean(); + rejectionBar.Clean(); + + // + return result; + } + + // // + // AddRef( + // box, + // supResBoxes // + // ); + + // + // Detect Bars ... + + // + XOHCL zBar; + result = zBar.Init( + symbol, + forPeriod, + barIndex // + ); + if (!result) + { + // + zBar.Clean(); + Clean(supports); + Clean(resistances); + Clean(supResBoxes); + + // + swingBar.Clean(); + breakerBar.Clean(); + appliedBox.Clean(); + momentumBar.Clean(); + rejectionBar.Clean(); + + // + return result; + } + + // + XOHCL cBar; + result = zBar.GetPreviousBar(cBar); + if (!result) + { + // + zBar.Clean(); + cBar.Clean(); + Clean(supports); + Clean(resistances); + Clean(supResBoxes); + + // + swingBar.Clean(); + breakerBar.Clean(); + appliedBox.Clean(); + momentumBar.Clean(); + rejectionBar.Clean(); + + // + return result; + } + + // + XOHCL pBar; + result = cBar.GetPreviousBar(pBar); + if (!result) + { + // + zBar.Clean(); + cBar.Clean(); + pBar.Clean(); + Clean(supports); + Clean(resistances); + Clean(supResBoxes); + + // + swingBar.Clean(); + breakerBar.Clean(); + appliedBox.Clean(); + momentumBar.Clean(); + rejectionBar.Clean(); + + // + return result; + } + + // + XOHCL ppBar; + result = pBar.GetPreviousBar(ppBar); + if (!result) + { + // + zBar.Clean(); + cBar.Clean(); + pBar.Clean(); + ppBar.Clean(); + Clean(supports); + Clean(resistances); + Clean(supResBoxes); + + // + swingBar.Clean(); + breakerBar.Clean(); + appliedBox.Clean(); + momentumBar.Clean(); + rejectionBar.Clean(); + + // + return result; + } + + // + // Check Conditions ... + + // + // Detect Start Senario ... + + // + double fiboPressureLevel = GetFiboLevelValue(X_FIBO_LEVEL_382); + + // + double fiboUpDown = GetFibonacciLevel( + pBar.high, + pBar.low, + X_FIBO_LEVEL_382, + X_DIRECTION_BEARISH // + ); + double fiboDownUp = GetFibonacciLevel( + pBar.high, + pBar.low, + X_FIBO_LEVEL_382, + X_DIRECTION_BULLISH // + ); + + // + bool hasFiboToUpPressure = + fiboDownUp > 0 && + fiboDownUp <= pBar.GetDown(); + bool hasFiboToDownPressure = + fiboUpDown > 0 && + fiboUpDown >= pBar.GetUp(); + + // + int selectedBoxIDX = -1; + for (int j = 0; j < supresBoxesCount; j++) + { + // + double appliedPrice = + isBullish + ? supResBoxes[j].lower + : supResBoxes[j].upper; + + // + // Check Swing Low ... + bool isSwingLow = + // + pBar.low < ppBar.low && + pBar.low < cBar.low && + zBar.open > pBar.low && + // + appliedPrice > pBar.low && + appliedPrice < pBar.GetDown() + // + ; + bool isPressuredSwingLow = + isSwingLow && + hasFiboToUpPressure; + bool isPressuredStrongSwingLow = + pBar.IsBullish() && + isPressuredSwingLow; + + // + bool isSwingHigh = + // + pBar.high > ppBar.high && + pBar.high > cBar.high && + zBar.open < pBar.high && + // + appliedPrice < pBar.high && + appliedPrice > pBar.GetUp() + // + ; + bool isPressuredSwingHigh = + isSwingHigh && + hasFiboToDownPressure; + bool isPressuredStrongSwingHigh = + pBar.IsBearish() && + isPressuredSwingHigh; + + // + bool hasValidSwing = + isBullish + ? isSwingLow + : isSwingHigh; + bool hasValidPressuredSwing = + isBullish + ? isPressuredSwingLow + : isPressuredSwingHigh; + bool hasValidPressuredStrongSwing = + isBullish + ? isPressuredStrongSwingLow + : isPressuredStrongSwingHigh; + if (hasValidSwing) + { + swingBar = pBar; + } + if (hasValidPressuredSwing) + { + swingBar = pBar; + } + if (hasValidPressuredStrongSwing) + { + swingBar = pBar; + } + + // + bool isCBarBreaked = IsBarBreak( + appliedPrice, + forDir, + cBar // + ); + if (isCBarBreaked) + { + breakerBar = cBar; + } + bool isPBarBreaked = IsBarBreak( + appliedPrice, + forDir, + pBar // + ); + if (!isCBarBreaked && isPBarBreaked) + { + breakerBar = pBar; + } + else + { + isPBarBreaked = false; + } + bool isPPBarBreaked = IsBarBreak( + appliedPrice, + forDir, + ppBar // + ); + if (!isCBarBreaked && + !isPBarBreaked && + isPPBarBreaked) + { + breakerBar = ppBar; + } + else + { + isPPBarBreaked = false; + } + bool isBoxBreaked = isCBarBreaked || + isPBarBreaked || + isPPBarBreaked; + + // + bool isCBarRejected = IsBarReject( + appliedPrice, + forDir, + cBar // + ); + if (isCBarRejected) + { + rejectionBar = cBar; + } + bool isPBarRejected = IsBarReject( + appliedPrice, + forDir, + pBar // + ); + if (!isCBarRejected && isPBarRejected) + { + rejectionBar = pBar; + } + else + { + isPBarRejected = false; + } + bool isPPBarRejected = IsBarReject( + appliedPrice, + forDir, + ppBar // + ); + if (!isCBarRejected && + !isPBarRejected && + isPPBarRejected) + { + rejectionBar = ppBar; + } + else + { + isPPBarRejected = false; + } + bool isBoxRejected = isCBarRejected || + isPBarRejected || + isPPBarRejected; + + // + bool hasRejectionBar = false; + if (isBullish) + { + // + count = state.CountBullishRejectionBars(); + for (int i = 0; i < count; i++) + { + // + XCRejectionBar *iZone = state.bullishRejectionBars[i]; + + // + XOHCL iBar; + bool isFilled = iZone.FillBar(iBar); + if (!isFilled) + { + continue; + } + + // + int iBarIndex = iBar.Index(); + + // + hasRejectionBar = + // + (iBarIndex == cBar.Index() || + iBarIndex == pBar.Index()) + // + ; + if (hasRejectionBar) + { + // + if (!rejectionBar.IsValid()) + { + rejectionBar = iBar; + } + + // + break; + } + } + } + else + { + // + count = state.CountBearishRejectionBars(); + for (int i = 0; i < count; i++) + { + // + XCRejectionBar *iZone = state.bearishRejectionBars[i]; + + // + XOHCL iBar; + bool isFilled = iZone.FillBar(iBar); + if (!isFilled) + { + continue; + } + + // + int iBarIndex = iBar.Index(); + + // + hasRejectionBar = + // + (iBarIndex == cBar.Index() || + iBarIndex == pBar.Index()) + // + ; + if (hasRejectionBar) + { + // + if (!rejectionBar.IsValid()) + { + rejectionBar = iBar; + } + + // + break; + } + } + } + + // + bool hasMomentumBar = false; + if (isBullish) + { + // + count = state.CountBullishMomentumBars(); + for (int i = 0; i < count; i++) + { + // + XCMomentumBar *iZone = state.bullishMomentumBars[i]; + + // + XOHCL iBar; + bool isFilled = iZone.FillBar(iBar); + if (!isFilled) + { + continue; + } + + // + int iBarIndex = iBar.Index(); + + // + hasMomentumBar = + // + (iBarIndex == cBar.Index() || + iBarIndex == pBar.Index()) + // + ; + if (hasMomentumBar) + { + // + if (!momentumBar.IsValid()) + { + momentumBar = iBar; + } + + // + break; + } + } + } + else + { + // + count = state.CountBearishMomentumBars(); + for (int i = 0; i < count; i++) + { + // + XCMomentumBar *iZone = state.bearishMomentumBars[i]; + + // + XOHCL iBar; + bool isFilled = iZone.FillBar(iBar); + if (!isFilled) + { + continue; + } + + // + int iBarIndex = iBar.Index(); + + // + hasMomentumBar = + // + (iBarIndex == cBar.Index() || + iBarIndex == pBar.Index()) + // + ; + if (hasMomentumBar) + { + // + if (!momentumBar.IsValid()) + { + momentumBar = iBar; + } + + // + break; + } + } + } + + // + bool hasSwing = false; + if (isBullish) + { + // + count = state.CountSwingLows(); + for (int i = 0; i < count; i++) + { + // + XCSwing *iSwing = state.swingLows[i]; + + // + XOHCL iBar; + bool isFilled = iSwing.FillBar(iBar); + if (!isFilled) + { + continue; + } + + // + int iBarIndex = iBar.Index(); + + // + hasSwing = + // + (iBarIndex == cBar.Index() || + iBarIndex == pBar.Index()) + // + ; + if (hasSwing) + { + // + if (!swingBar.IsValid()) + { + swingBar = iBar; + } + + // + break; + } + } + } + else + { + // + count = state.CountSwingHighs(); + for (int i = 0; i < count; i++) + { + // + XCSwing *iSwing = state.swingHighs[i]; + + // + XOHCL iBar; + bool isFilled = iSwing.FillBar(iBar); + if (!isFilled) + { + continue; + } + + // + int iBarIndex = iBar.Index(); + + // + hasSwing = + // + (iBarIndex == cBar.Index() || + iBarIndex == pBar.Index()) + // + ; + if (hasSwing) + { + // + if (!swingBar.IsValid()) + { + swingBar = iBar; + } + + // + break; + } + } + } + + // + bool hasRequiredValidations = + // + (hasRejectionBar || + hasMomentumBar) + // + || + // + (hasRejectionBar || + hasSwing) + // + || + // + (hasMomentumBar || + hasSwing) + // + ; + + // + result = + // + (isBoxBreaked && + (hasRequiredValidations || + hasValidPressuredSwing)) + // + || + // + (isBoxRejected && + (hasRequiredValidations || + hasValidPressuredSwing)) + // + ; + if (result) + { + // + selectedBoxIDX = j; + break; + } + } + + // + result = + result && + (isBullish + ? zBar.open >= box.upper + : zBar.open <= box.lower) && + IsValidIndex(selectedBoxIDX); + if (result) + { + appliedBox = supResBoxes[selectedBoxIDX]; + } + + // + zBar.Clean(); + cBar.Clean(); + pBar.Clean(); + ppBar.Clean(); + Clean(supports); + Clean(resistances); + Clean(supResBoxes); + + // + return result; + } + + + + // + ulong chartID = visionCycleHelper.mPOIDrawer.ChartIdentification(); + int subWindow = visionCycleHelper.mPOIDrawer.SubWindowIdentification(); + + // + if (pivot > 0) + { + // + string name = "Pivot_" + symbol + ToString(period) + ToString(pivot) + "_"; + CChartObjectHLine *iObj; + iObj = new CChartObjectHLine(); + bool isCreated = iObj.Create( + chartID, + name, + subWindow, + pivot // + ); + if (isCreated) + { + // + iObj.Color(clrLime); + mObjects.Add(iObj); + } + } + + // + if (point > 0) + { + // + string name = "Point_" + symbol + ToString(period) + ToString(pivot) + "_"; + CChartObjectHLine *iObj; + iObj = new CChartObjectHLine(); + bool isCreated = iObj.Create( + chartID, + name, + subWindow, + point // + ); + if (isCreated) + { + // + iObj.Color(clrLime); + mObjects.Add(iObj); + } + } diff --git a/X121SMCEA/Signals/x-121.smc.xwz.signal.class.mq5 b/X121SMCEA/Signals/x-121.smc.xwz.signal.class.mq5 index 257ad2dd..e470e15f 100644 --- a/X121SMCEA/Signals/x-121.smc.xwz.signal.class.mq5 +++ b/X121SMCEA/Signals/x-121.smc.xwz.signal.class.mq5 @@ -225,139 +225,6 @@ class XCX121SMCXWZSignalDetector : public XCBase // // Setup Conditions ... - // - XOHCL decisionZBar; - XOHCL decisionCBar; - XOHCL decisionPBar; - double decisionCBarBullishZoneChechValue = 0; - double decisionCBarBearishZoneChechValue = 0; - - // - result = decisionZBar.Init( - decisionState.symbol, - decisionState.period, - 0 // - ); - if (!result) - { - // - Clean(visionPoiEvents); - Clean(analysePoiEvents); - Clean(decisionPoiEvents); - Clean(visionCycleEvents); - Clean(analyseCycleEvents); - Clean(decisionCycleEvents); - Clean(consolidationPoiEvents); - Clean(consolidationCycleEvents); - - // - visionState.Clean(); - analyseState.Clean(); - decisionZBar.Clean(); - decisionCBar.Clean(); - decisionPBar.Clean(); - decisionState.Clean(); - visionConditions.Clean(); - analyseConditions.Clean(); - visionXConditions.Clean(); - consolidationState.Clean(); - decisionConditions.Clean(); - analyseXConditions.Clean(); - decisionXConditions.Clean(); - consolidationConditions.Clean(); - consolidationXConditions.Clean(); - - // - mConditions.Clean(); - - // - return result; - } - - // - result = decisionZBar - .GetPreviousBar(decisionCBar); - if (!result) - { - // - Clean(visionPoiEvents); - Clean(analysePoiEvents); - Clean(decisionPoiEvents); - Clean(visionCycleEvents); - Clean(analyseCycleEvents); - Clean(decisionCycleEvents); - Clean(consolidationPoiEvents); - Clean(consolidationCycleEvents); - - // - visionState.Clean(); - analyseState.Clean(); - decisionZBar.Clean(); - decisionCBar.Clean(); - decisionPBar.Clean(); - decisionState.Clean(); - visionConditions.Clean(); - analyseConditions.Clean(); - visionXConditions.Clean(); - consolidationState.Clean(); - decisionConditions.Clean(); - analyseXConditions.Clean(); - decisionXConditions.Clean(); - consolidationConditions.Clean(); - consolidationXConditions.Clean(); - - // - mConditions.Clean(); - - // - return result; - } - - // - result = decisionCBar - .GetPreviousBar(decisionPBar); - if (!result) - { - // - Clean(visionPoiEvents); - Clean(analysePoiEvents); - Clean(decisionPoiEvents); - Clean(visionCycleEvents); - Clean(analyseCycleEvents); - Clean(decisionCycleEvents); - Clean(consolidationPoiEvents); - Clean(consolidationCycleEvents); - - // - visionState.Clean(); - analyseState.Clean(); - decisionZBar.Clean(); - decisionCBar.Clean(); - decisionPBar.Clean(); - decisionState.Clean(); - visionConditions.Clean(); - analyseConditions.Clean(); - visionXConditions.Clean(); - consolidationState.Clean(); - decisionConditions.Clean(); - analyseXConditions.Clean(); - decisionXConditions.Clean(); - consolidationConditions.Clean(); - consolidationXConditions.Clean(); - - // - mConditions.Clean(); - - // - return result; - } - - // - decisionCBarBullishZoneChechValue = decisionCBar - .GetZoneCheckValue(X_DIRECTION_BULLISH); - decisionCBarBearishZoneChechValue = decisionCBar - .GetZoneCheckValue(X_DIRECTION_BEARISH); - // // Check Working Zone ... bool hasWorkingZone = mConditions.HasWorkingZone(); @@ -389,9 +256,6 @@ class XCX121SMCXWZSignalDetector : public XCBase // visionState.Clean(); analyseState.Clean(); - decisionZBar.Clean(); - decisionCBar.Clean(); - decisionPBar.Clean(); decisionState.Clean(); visionConditions.Clean(); analyseConditions.Clean(); @@ -448,9 +312,6 @@ class XCX121SMCXWZSignalDetector : public XCBase // visionState.Clean(); analyseState.Clean(); - decisionZBar.Clean(); - decisionCBar.Clean(); - decisionPBar.Clean(); decisionState.Clean(); visionConditions.Clean(); analyseConditions.Clean(); @@ -500,9 +361,6 @@ class XCX121SMCXWZSignalDetector : public XCBase // visionState.Clean(); analyseState.Clean(); - decisionZBar.Clean(); - decisionCBar.Clean(); - decisionPBar.Clean(); decisionState.Clean(); visionConditions.Clean(); analyseConditions.Clean(); @@ -526,28 +384,11 @@ class XCX121SMCXWZSignalDetector : public XCBase } // - // Detect Start Zones ... - bool hasStartZone = mConditions.HasStartZones(); - if (!hasStartZone) - { - // - hasStartZone = mConditions.DetectStartZones( - trend, - analyseState, - decisionCycleHelper // - ); - - // - if (hasStartZone) - { - // - mConditions.UpdateTo(cTime); - DrawConditions( - mConditions, - visionCycleHelper.mPOIDrawer // - ); - } - } + bool hasStartZone = mConditions.DetectStartZones( + trend, + analyseState, + decisionCycleHelper // + ); // mConditions.UpdateTo(cTime); @@ -586,93 +427,59 @@ class XCX121SMCXWZSignalDetector : public XCBase // - What we looking for: Long or Short ... // - Priority ... + // + double pivot = 0; + double point = 0; + ENUM_X_DIRECTION conditionsDir = X_DIRECTION_NONE; + + // + // Detect Start Zone Conditions ... + bool hasConditions = mConditions + .HasConditions( + pivot, + point, + conditionsDir, + decisionState, + zIndex, + decisionState.period // + ); + result = hasConditions; + if (!result) + { + // + Clean(visionPoiEvents); + Clean(analysePoiEvents); + Clean(decisionPoiEvents); + Clean(visionCycleEvents); + Clean(analyseCycleEvents); + Clean(decisionCycleEvents); + Clean(consolidationPoiEvents); + Clean(consolidationCycleEvents); + + // + visionState.Clean(); + analyseState.Clean(); + decisionState.Clean(); + visionConditions.Clean(); + analyseConditions.Clean(); + visionXConditions.Clean(); + consolidationState.Clean(); + decisionConditions.Clean(); + analyseXConditions.Clean(); + decisionXConditions.Clean(); + consolidationConditions.Clean(); + consolidationXConditions.Clean(); + + // + return result; + } + // DrawConditions( mConditions, visionCycleHelper.mPOIDrawer // ); - // - double pivot = 0; - double point = 0; - bool hasCondition = false; - ENUM_X_DIRECTION conditionsDir = X_DIRECTION_NONE; - // - // Detect Start Zone Conditions ... - hasCondition = mConditions - .HasConditions( - conditionsDir, - decisionState, - zIndex, - decisionState.period // - ); - if (hasCondition) - { - // // - // XBoxZone startZoneBox; - // bool hasBox = mConditions.startZone.AsBox(startZoneBox); - // if (hasBox) - // { - // // - // bool isBullish = IsBullish(conditionsDir); - - // // - // pivot = - // isBullish - // ? startZoneBox.lower - // : startZoneBox.upper; - - // // - // point = - // isBullish - // ? startZoneBox.upper - // : startZoneBox.lower; - // } - } - - // // - // // Detect Supply and Deman Zone Based Conditions ... - // if (!hasCondition) - // { - // // - // bool isPriceInsideSupplyZone = - // bearishPriority == X121SMC_XWZ_PRIORITY_STRONG_HIGH; - - // // - // bool isPriceInsideDemandZone = - // bullishPriority == X121SMC_XWZ_PRIORITY_STRONG_HIGH; - - // // - // bool isPriceInsideSupDem = isPriceInsideSupplyZone || - // isPriceInsideDemandZone; - // if (isPriceInsideSupDem) - // { - // // - // hasCondition = mConditions.HasWorkingZoneConditions( - // conditionsDir, - // decisionState // - // ); - - // // - // if (hasCondition) - // { - // // - // if (IsBullish(conditionsDir)) - // { - // // - // pivot = mConditions.demandZone.Lower(); - // point = mConditions.demandZone.Upper(); - // } - // else if (IsBearish(conditionsDir)) - // { - // // - // pivot = mConditions.supplyZone.Upper(); - // point = mConditions.supplyZone.Lower(); - // } - // } - // } - // } - // isBullish = IsBullish(conditionsDir); isBearish = IsBearish(conditionsDir); @@ -690,6 +497,52 @@ class XCX121SMCXWZSignalDetector : public XCBase amountPercent // ); + // + // Apply Traget ... + switch (priority) + { + // + case X121SMC_XWZ_PRIORITY_STRONG_HIGH: + // + target = + isBullish + ? mConditions.workingZone.quarter3 + : mConditions.workingZone.quarter1; + break; + + // + case X121SMC_XWZ_PRIORITY_HIGH: + // + target = + isBullish + ? mConditions.workingZone.quarter3 + : mConditions.workingZone.quarter1; + break; + + // + case X121SMC_XWZ_PRIORITY_REGULAR: + // + target = + isBullish + ? mConditions.workingZone.quarter2 + : mConditions.workingZone.quarter2; + break; + + // + case X121SMC_XWZ_PRIORITY_LOW: + // + target = + isBullish + ? mConditions.workingZone.quarter1 + : mConditions.workingZone.quarter3; + break; + + // + default: + target = 0; + break; + } + // bool hasLastBullishConsolidationZone = false; bool hasLastBearishConsolidationZone = false; @@ -699,6 +552,10 @@ class XCX121SMCXWZSignalDetector : public XCBase XConsolidationZone lastBearishConsolidationZone; XConsolidationZone prevBullishConsolidationZone; XConsolidationZone prevBearishConsolidationZone; + bool isLastBullishConsolidationZoneInsidePivot = false; + bool isPrevBullishConsolidationZoneInsidePivot = false; + bool isLastBearishConsolidationZoneInsidePivot = false; + bool isPrevBearishConsolidationZoneInsidePivot = false; bool hasConsolidationZones = decisionCycleHelper.HasConsolidationZones(); if (hasConsolidationZones) { @@ -747,6 +604,38 @@ class XCX121SMCXWZSignalDetector : public XCBase hasLastBearishConsolidationZone = lastBearishConsolidationZone.IsValid(); hasPrevBullishConsolidationZone = prevBullishConsolidationZone.IsValid(); hasPrevBearishConsolidationZone = prevBearishConsolidationZone.IsValid(); + + // + isLastBullishConsolidationZoneInsidePivot = + // + hasLastBullishConsolidationZone && + (lastBullishConsolidationZone.lower < point && + lastBullishConsolidationZone.upper > pivot) + // + ; + isPrevBullishConsolidationZoneInsidePivot = + // + hasPrevBullishConsolidationZone && + (prevBullishConsolidationZone.lower < point && + prevBullishConsolidationZone.upper > pivot) + // + ; + + // + isLastBearishConsolidationZoneInsidePivot = + // + hasLastBearishConsolidationZone && + (lastBearishConsolidationZone.upper > point && + lastBearishConsolidationZone.lower < pivot) + // + ; + isPrevBearishConsolidationZoneInsidePivot = + // + hasPrevBearishConsolidationZone && + (prevBearishConsolidationZone.upper > point && + prevBearishConsolidationZone.lower < pivot) + // + ; } // @@ -823,15 +712,26 @@ class XCX121SMCXWZSignalDetector : public XCBase // bool isConsolidationZonePassed = isBullish + // ? (point > 0 && + pivot > 0 && + pivot < point && hasPrevBullishConsolidationZone && - point >= prevBullishConsolidationZone.upper) + point > prevBullishConsolidationZone.upper && + (isLastBullishConsolidationZoneInsidePivot || + isPrevBullishConsolidationZoneInsidePivot)) : (point > 0 && + pivot > 0 && + pivot > point && hasPrevBearishConsolidationZone && - point <= prevBearishConsolidationZone.lower); + point < prevBearishConsolidationZone.lower && + (isLastBearishConsolidationZoneInsidePivot || + isPrevBearishConsolidationZoneInsidePivot)) + // + ; // - result = hasCondition && + result = hasConditions && hasRewardAmount && isPriorityPassed && trend == conditionsDir && @@ -851,9 +751,6 @@ class XCX121SMCXWZSignalDetector : public XCBase // visionState.Clean(); analyseState.Clean(); - decisionZBar.Clean(); - decisionCBar.Clean(); - decisionPBar.Clean(); decisionState.Clean(); visionConditions.Clean(); analyseConditions.Clean(); @@ -878,52 +775,6 @@ class XCX121SMCXWZSignalDetector : public XCBase return result; } - // - // Apply Traget ... - switch (priority) - { - // - case X121SMC_XWZ_PRIORITY_STRONG_HIGH: - // - target = - isBullish - ? mConditions.workingZone.quarter3 - : mConditions.workingZone.quarter1; - break; - - // - case X121SMC_XWZ_PRIORITY_HIGH: - // - target = - isBullish - ? mConditions.workingZone.quarter3 - : mConditions.workingZone.quarter1; - break; - - // - case X121SMC_XWZ_PRIORITY_REGULAR: - // - target = - isBullish - ? mConditions.workingZone.quarter2 - : mConditions.workingZone.quarter2; - break; - - // - case X121SMC_XWZ_PRIORITY_LOW: - // - target = - isBullish - ? mConditions.workingZone.quarter1 - : mConditions.workingZone.quarter3; - break; - - // - default: - target = 0; - break; - } - // mConditions.pivot = pivot; mConditions.point = point; @@ -956,9 +807,6 @@ class XCX121SMCXWZSignalDetector : public XCBase // visionState.Clean(); analyseState.Clean(); - decisionZBar.Clean(); - decisionCBar.Clean(); - decisionPBar.Clean(); decisionState.Clean(); visionConditions.Clean(); analyseConditions.Clean(); @@ -1148,18 +996,16 @@ class XCX121SMCXWZSignalDetector : public XCBase // isBullish = // - isBullish - // && - // isPointBreaked + isBullish && + isPointBreaked // ; // isBearish = // - isBearish - // && - // isPointBreaked + isBearish && + isPointBreaked // ; diff --git a/X121SMCEA/Signals/x-121.smc.xwz.signal.lib.mq5 b/X121SMCEA/Signals/x-121.smc.xwz.signal.lib.mq5 index 00cd98e9..e68abd68 100644 --- a/X121SMCEA/Signals/x-121.smc.xwz.signal.lib.mq5 +++ b/X121SMCEA/Signals/x-121.smc.xwz.signal.lib.mq5 @@ -262,8 +262,8 @@ struct X121SMCXWZZone } // - bool HasCondition( - XPOIState &state, + bool IsPriceInside( + XBoxZone &box, int barIndex = 0, ENUM_TIMEFRAMES forPeriod = NULL // ) @@ -271,869 +271,8 @@ struct X121SMCXWZZone // bool result = false; - // - if (barIndex < 0) - { - barIndex = 0; - } - - // - swingBar.Clean(); - breakerBar.Clean(); - appliedBox.Clean(); - momentumBar.Clean(); - rejectionBar.Clean(); - - // - result = IsValid() && - HasDirection() && - state.IsValid() && - state.HasChild(); - if (!result) - { - // - swingBar.Clean(); - breakerBar.Clean(); - appliedBox.Clean(); - momentumBar.Clean(); - rejectionBar.Clean(); - - // - return result; - } - - // - string symbol = ob.GetSymbol(); - if (!IsValid(forPeriod)) - { - forPeriod = ob.GetPeriod(); - } - datetime cTime = iTime( - symbol, - forPeriod, - barIndex // - ); - - // - bool isInside = IsPriceInside( - barIndex, - forPeriod // - ); - result = isInside; - if (!result) - { - return result; - } - - // - XBoxZone box; - result = AsBox(box); - if (!result) - { - // - box.Clean(); - - // - swingBar.Clean(); - breakerBar.Clean(); - appliedBox.Clean(); - momentumBar.Clean(); - rejectionBar.Clean(); - - // - return result; - } - - // - bool isBullish = IsBullish(); - ENUM_X_DIRECTION forDir = box.dir; - - // - int supportsCount = 0; - bool hasSupports = false; - XCSupportZone *supports[]; - - // - int resistancesCount = 0; - bool hasResistances = false; - XCResistanceZone *resistances[]; - - // - XBoxZone supResBoxes[]; - int supresBoxesCount = 0; - bool hasSupResBoxes = false; - - // - int count = 0; - bool has = false; - - // - has = state.HasSupportZones(); - if (has) - { - // - count = state.CountSupportZones(); - for (int i = 0; i < count; i++) - { - // - XCSupportZone *iZone = state.supportZones[i]; - - // - iZone.To(cTime); - - // - XBoxZone iBox; - bool hasBox = ToBox( - iBox, - iZone // - ); - if (!hasBox) - { - // - iBox.Clean(); - continue; - } - - // - // Check From ... - bool isInside = IsBoxInside( - iBox, - box // - ); - if (!isInside) - { - // - iBox.Clean(); - continue; - } - - // - Add( - iZone, - supports // - ); - - // - AddRef( - iBox, - supResBoxes // - ); - - // - iBox.Clean(); - } - - // - supportsCount = ArraySize(supports); - hasSupports = IsValidSize(supportsCount); - - // - supresBoxesCount = ArraySize(supResBoxes); - hasSupResBoxes = IsValidSize(supresBoxesCount); - } - - // - has = state.HasResistanceZones(); - if (has) - { - // - count = state.CountResistanceZones(); - for (int i = 0; i < count; i++) - { - // - XCResistanceZone *iZone = state.resistanceZones[i]; - - // - iZone.To(cTime); - - // - XBoxZone iBox; - bool hasBox = ToBox( - iBox, - iZone // - ); - if (!hasBox) - { - // - iBox.Clean(); - continue; - } - - // - // Check From ... - bool isInside = IsBoxInside( - iBox, - box // - ); - if (!isInside) - { - // - iBox.Clean(); - continue; - } - - // - Add( - iZone, - resistances // - ); - - // - AddRef( - iBox, - supResBoxes // - ); - - // - iBox.Clean(); - } - - // - resistancesCount = ArraySize(resistances); - hasResistances = IsValidSize(resistancesCount); - - // - supresBoxesCount = ArraySize(supResBoxes); - hasSupResBoxes = IsValidSize(supresBoxesCount); - } - - // - result = hasSupResBoxes; - if (!result) - { - // - box.Clean(); - Clean(supports); - Clean(resistances); - Clean(supResBoxes); - - // - swingBar.Clean(); - breakerBar.Clean(); - appliedBox.Clean(); - momentumBar.Clean(); - rejectionBar.Clean(); - - // - return result; - } - - // - // Detect Bars ... - - // - XOHCL zBar; - result = zBar.Init( - symbol, - forPeriod, - barIndex // - ); - if (!result) - { - // - box.Clean(); - zBar.Clean(); - Clean(supports); - Clean(resistances); - Clean(supResBoxes); - - // - swingBar.Clean(); - breakerBar.Clean(); - appliedBox.Clean(); - momentumBar.Clean(); - rejectionBar.Clean(); - - // - return result; - } - - // - XOHCL cBar; - result = zBar.GetPreviousBar(cBar); - if (!result) - { - // - box.Clean(); - zBar.Clean(); - cBar.Clean(); - Clean(supports); - Clean(resistances); - Clean(supResBoxes); - - // - swingBar.Clean(); - breakerBar.Clean(); - appliedBox.Clean(); - momentumBar.Clean(); - rejectionBar.Clean(); - - // - return result; - } - - // - XOHCL pBar; - result = cBar.GetPreviousBar(pBar); - if (!result) - { - // - box.Clean(); - zBar.Clean(); - cBar.Clean(); - pBar.Clean(); - Clean(supports); - Clean(resistances); - Clean(supResBoxes); - - // - swingBar.Clean(); - breakerBar.Clean(); - appliedBox.Clean(); - momentumBar.Clean(); - rejectionBar.Clean(); - - // - return result; - } - - // - XOHCL ppBar; - result = pBar.GetPreviousBar(ppBar); - if (!result) - { - // - box.Clean(); - zBar.Clean(); - cBar.Clean(); - pBar.Clean(); - ppBar.Clean(); - Clean(supports); - Clean(resistances); - Clean(supResBoxes); - - // - swingBar.Clean(); - breakerBar.Clean(); - appliedBox.Clean(); - momentumBar.Clean(); - rejectionBar.Clean(); - - // - return result; - } - - // - // Check Conditions ... - - // - // Detect Start Senario ... - - // - double fiboPressureLevel = GetFiboLevelValue(X_FIBO_LEVEL_382); - - // - double fiboUpDown = GetFibonacciLevel( - pBar.high, - pBar.low, - X_FIBO_LEVEL_382, - X_DIRECTION_BEARISH // - ); - double fiboDownUp = GetFibonacciLevel( - pBar.high, - pBar.low, - X_FIBO_LEVEL_382, - X_DIRECTION_BULLISH // - ); - - // - bool hasFiboToUpPressure = - fiboDownUp > 0 && - fiboDownUp <= pBar.GetDown(); - bool hasFiboToDownPressure = - fiboUpDown > 0 && - fiboUpDown >= pBar.GetUp(); - - // - int selectedBoxIDX = -1; - for (int j = 0; j < supresBoxesCount; j++) - { - // - double appliedPrice = - isBullish - ? supResBoxes[j].lower - : supResBoxes[j].upper; - - // - // Check Swing Low ... - bool isSwingLow = - // - pBar.low < ppBar.low && - pBar.low < cBar.low && - zBar.open > pBar.low && - // - appliedPrice > pBar.low && - appliedPrice < pBar.GetDown() - // - ; - bool isPressuredSwingLow = - isSwingLow && - hasFiboToUpPressure; - bool isPressuredStrongSwingLow = - pBar.IsBullish() && - isPressuredSwingLow; - - // - bool isSwingHigh = - // - pBar.high > ppBar.high && - pBar.high > cBar.high && - zBar.open < pBar.high && - // - appliedPrice < pBar.high && - appliedPrice > pBar.GetUp() - // - ; - bool isPressuredSwingHigh = - isSwingHigh && - hasFiboToDownPressure; - bool isPressuredStrongSwingHigh = - pBar.IsBearish() && - isPressuredSwingHigh; - - // - bool hasValidSwing = - isBullish - ? isSwingLow - : isSwingHigh; - bool hasValidPressuredSwing = - isBullish - ? isPressuredSwingLow - : isPressuredSwingHigh; - bool hasValidPressuredStrongSwing = - isBullish - ? isPressuredStrongSwingLow - : isPressuredStrongSwingHigh; - if (hasValidSwing) - { - swingBar = pBar; - } - if (hasValidPressuredSwing) - { - swingBar = pBar; - } - if (hasValidPressuredStrongSwing) - { - swingBar = pBar; - } - - // - bool isCBarBreaked = IsBarBreak( - appliedPrice, - forDir, - cBar // - ); - if (isCBarBreaked) - { - breakerBar = cBar; - } - bool isPBarBreaked = IsBarBreak( - appliedPrice, - forDir, - pBar // - ); - if (!isCBarBreaked && isPBarBreaked) - { - breakerBar = pBar; - } - else - { - isPBarBreaked = false; - } - bool isPPBarBreaked = IsBarBreak( - appliedPrice, - forDir, - ppBar // - ); - if (!isCBarBreaked && - !isPBarBreaked && - isPPBarBreaked) - { - breakerBar = ppBar; - } - else - { - isPPBarBreaked = false; - } - bool isBoxBreaked = isCBarBreaked || - isPBarBreaked || - isPPBarBreaked; - - // - bool isCBarRejected = IsBarReject( - appliedPrice, - forDir, - cBar // - ); - if (isCBarRejected) - { - rejectionBar = cBar; - } - bool isPBarRejected = IsBarReject( - appliedPrice, - forDir, - pBar // - ); - if (!isCBarRejected && isPBarRejected) - { - rejectionBar = pBar; - } - else - { - isPBarRejected = false; - } - bool isPPBarRejected = IsBarReject( - appliedPrice, - forDir, - ppBar // - ); - if (!isCBarRejected && - !isPBarRejected && - isPPBarRejected) - { - rejectionBar = ppBar; - } - else - { - isPPBarRejected = false; - } - bool isBoxRejected = isCBarRejected || - isPBarRejected || - isPPBarRejected; - - // - bool hasRejectionBar = false; - if (isBullish) - { - // - count = state.CountBullishRejectionBars(); - for (int i = 0; i < count; i++) - { - // - XCRejectionBar *iZone = state.bullishRejectionBars[i]; - - // - XOHCL iBar; - bool isFilled = iZone.FillBar(iBar); - if (!isFilled) - { - continue; - } - - // - int iBarIndex = iBar.Index(); - - // - hasRejectionBar = - // - (iBarIndex == cBar.Index() || - iBarIndex == pBar.Index()) - // - ; - if (hasRejectionBar) - { - // - if (!rejectionBar.IsValid()) - { - rejectionBar = iBar; - } - - // - break; - } - } - } - else - { - // - count = state.CountBearishRejectionBars(); - for (int i = 0; i < count; i++) - { - // - XCRejectionBar *iZone = state.bearishRejectionBars[i]; - - // - XOHCL iBar; - bool isFilled = iZone.FillBar(iBar); - if (!isFilled) - { - continue; - } - - // - int iBarIndex = iBar.Index(); - - // - hasRejectionBar = - // - (iBarIndex == cBar.Index() || - iBarIndex == pBar.Index()) - // - ; - if (hasRejectionBar) - { - // - if (!rejectionBar.IsValid()) - { - rejectionBar = iBar; - } - - // - break; - } - } - } - - // - bool hasMomentumBar = false; - if (isBullish) - { - // - count = state.CountBullishMomentumBars(); - for (int i = 0; i < count; i++) - { - // - XCMomentumBar *iZone = state.bullishMomentumBars[i]; - - // - XOHCL iBar; - bool isFilled = iZone.FillBar(iBar); - if (!isFilled) - { - continue; - } - - // - int iBarIndex = iBar.Index(); - - // - hasMomentumBar = - // - (iBarIndex == cBar.Index() || - iBarIndex == pBar.Index()) - // - ; - if (hasMomentumBar) - { - // - if (!momentumBar.IsValid()) - { - momentumBar = iBar; - } - - // - break; - } - } - } - else - { - // - count = state.CountBearishMomentumBars(); - for (int i = 0; i < count; i++) - { - // - XCMomentumBar *iZone = state.bearishMomentumBars[i]; - - // - XOHCL iBar; - bool isFilled = iZone.FillBar(iBar); - if (!isFilled) - { - continue; - } - - // - int iBarIndex = iBar.Index(); - - // - hasMomentumBar = - // - (iBarIndex == cBar.Index() || - iBarIndex == pBar.Index()) - // - ; - if (hasMomentumBar) - { - // - if (!momentumBar.IsValid()) - { - momentumBar = iBar; - } - - // - break; - } - } - } - - // - bool hasSwing = false; - if (isBullish) - { - // - count = state.CountSwingLows(); - for (int i = 0; i < count; i++) - { - // - XCSwing *iSwing = state.swingLows[i]; - - // - XOHCL iBar; - bool isFilled = iSwing.FillBar(iBar); - if (!isFilled) - { - continue; - } - - // - int iBarIndex = iBar.Index(); - - // - hasSwing = - // - (iBarIndex == cBar.Index() || - iBarIndex == pBar.Index()) - // - ; - if (hasSwing) - { - // - if (!swingBar.IsValid()) - { - swingBar = iBar; - } - - // - break; - } - } - } - else - { - // - count = state.CountSwingHighs(); - for (int i = 0; i < count; i++) - { - // - XCSwing *iSwing = state.swingHighs[i]; - - // - XOHCL iBar; - bool isFilled = iSwing.FillBar(iBar); - if (!isFilled) - { - continue; - } - - // - int iBarIndex = iBar.Index(); - - // - hasSwing = - // - (iBarIndex == cBar.Index() || - iBarIndex == pBar.Index()) - // - ; - if (hasSwing) - { - // - if (!swingBar.IsValid()) - { - swingBar = iBar; - } - - // - break; - } - } - } - - // - bool hasRequiredValidations = - // - (hasRejectionBar || - hasMomentumBar) - // - || - // - (hasRejectionBar || - hasSwing) - // - || - // - (hasMomentumBar || - hasSwing) - // - ; - - // - result = - // - (isBoxBreaked && - (hasRequiredValidations || - hasValidPressuredSwing)) - // - || - // - (isBoxRejected && - (hasRequiredValidations || - hasValidPressuredSwing)) - // - ; - if (result) - { - // - selectedBoxIDX = j; - break; - } - } - - // - result = - result && - (isBullish - ? zBar.open > box.upper - : zBar.open < box.lower) && - IsValidIndex(selectedBoxIDX); - if (result) - { - appliedBox = supResBoxes[selectedBoxIDX]; - } - // box.Clean(); - zBar.Clean(); - cBar.Clean(); - pBar.Clean(); - ppBar.Clean(); - Clean(supports); - Clean(resistances); - Clean(supResBoxes); - - // - return result; - } - - // - bool IsPriceInside( - int barIndex = 0, - ENUM_TIMEFRAMES forPeriod = NULL // - ) - { - // - bool result = false; // if (barIndex < 0) @@ -1193,20 +332,6 @@ struct X121SMCXWZZone return result; } - // - // Get Zone Box ... - XBoxZone box; - bool hasBox = AsBox(box); - result = hasBox; - if (!result) - { - // - box.Clean(); - - // - return result; - } - // // Retrieve Bars ... @@ -1257,28 +382,67 @@ struct X121SMCXWZZone } // - result = - // + bool isPriceInsideOB = isBullish ? ( // - pBar.low > box.upper && - cBar.low <= box.upper && - zBar.open <= box.upper + pBar.low > ob.Upper() && + cBar.low <= ob.Upper() && + zBar.open <= ob.Upper() // ) : ( // - pBar.high < box.lower && - cBar.high >= box.lower && - zBar.open >= box.lower + pBar.high < ob.Lower() && + cBar.high >= ob.Lower() && + zBar.open >= ob.Lower() // + ); + + // + bool isPriceInsideFVG = + isBullish + ? ( + // + pBar.low > fvg.Upper() && + cBar.low <= fvg.Upper() && + zBar.open <= fvg.Upper() + // ) + : ( + // + pBar.high < fvg.Lower() && + cBar.high >= fvg.Lower() && + zBar.open >= fvg.Lower() + // + ); + + // + result = + isPriceInsideOB || + isPriceInsideFVG; + if (result) + { // - ; + if (isPriceInsideOB) + { + // + result = ToBox( + box, + ob // + ); + } + else if (isPriceInsideFVG) + { + // + result = ToBox( + box, + fvg // + ); + } + } // - box.Clean(); zBar.Clean(); cBar.Clean(); pBar.Clean(); @@ -1287,6 +451,593 @@ struct X121SMCXWZZone return result; } + // + bool HasInsideConditions( + XPOIState &state, + int barIndex = 0, + ENUM_TIMEFRAMES forPeriod = NULL // + ) + { + // + bool result = false; + + // + if (barIndex < 0) + { + barIndex = 0; + } + + // + swingBar.Clean(); + breakerBar.Clean(); + appliedBox.Clean(); + momentumBar.Clean(); + rejectionBar.Clean(); + + // + XBoxZone zoneBox; + bool hasBox = AsBox(zoneBox); + + // + result = hasBox && + IsValid() && + HasDirection() && + state.IsValid() && + state.HasChild(); + if (!result) + { + // + swingBar.Clean(); + breakerBar.Clean(); + appliedBox.Clean(); + momentumBar.Clean(); + rejectionBar.Clean(); + + // + return result; + } + + // + string symbol = zoneBox.symbol; + if (!IsValid(forPeriod)) + { + forPeriod = zoneBox.period; + } + datetime cTime = iTime( + symbol, + forPeriod, + barIndex // + ); + + // + ENUM_X_DIRECTION forDir = zoneBox.dir; + bool isBullish = IsBullish(forDir); + + // + int count = 0; + bool has = false; + + // + XBoxZone supResBoxes[]; + int supresBoxesCount = 0; + bool hasSupResBoxes = false; + + // + has = state.HasSupportZones(); + if (has) + { + // + count = state.CountSupportZones(); + for (int i = 0; i < count; i++) + { + // + XCSupportZone *iZone = state.supportZones[i]; + + // + iZone.To(cTime); + + // + XBoxZone iBox; + bool hasBox = ToBox( + iBox, + iZone // + ); + if (!hasBox) + { + // + iBox.Clean(); + continue; + } + + // + // Check From ... + bool isInside = IsBoxInside( + iBox, + zoneBox // + ); + if (!isInside) + { + // + iBox.Clean(); + continue; + } + + // + AddRef( + iBox, + supResBoxes // + ); + + // + iBox.Clean(); + ZeroMemory(iZone); + } + + // + supresBoxesCount = ArraySize(supResBoxes); + hasSupResBoxes = IsValidSize(supresBoxesCount); + } + + // + has = state.HasResistanceZones(); + if (has) + { + // + count = state.CountResistanceZones(); + for (int i = 0; i < count; i++) + { + // + XCResistanceZone *iZone = state.resistanceZones[i]; + + // + iZone.To(cTime); + + // + XBoxZone iBox; + bool hasBox = ToBox( + iBox, + iZone // + ); + if (!hasBox) + { + // + iBox.Clean(); + continue; + } + + // + // Check From ... + bool isInside = IsBoxInside( + iBox, + zoneBox // + ); + if (!isInside) + { + // + iBox.Clean(); + continue; + } + + // + AddRef( + iBox, + supResBoxes // + ); + + // + iBox.Clean(); + ZeroMemory(iZone); + } + + // + supresBoxesCount = ArraySize(supResBoxes); + hasSupResBoxes = IsValidSize(supresBoxesCount); + } + + // + result = hasSupResBoxes; + if (!result) + { + // + Clean(supResBoxes); + + // + swingBar.Clean(); + breakerBar.Clean(); + appliedBox.Clean(); + momentumBar.Clean(); + rejectionBar.Clean(); + + // + return result; + } + + // + for (int i = 0; i < supresBoxesCount; i++) + { + // + XBoxZone iBox = supResBoxes[i]; + + // + bool hasBoxConditions = HasBoxConitions( + iBox, + state, + barIndex, + forPeriod // + ); + if (hasBoxConditions) + { + // + appliedBox = iBox; + result = true; + iBox.Clean(); + break; + } + + // + iBox.Clean(); + } + + // + if (!result) + { + // + swingBar.Clean(); + breakerBar.Clean(); + appliedBox.Clean(); + momentumBar.Clean(); + rejectionBar.Clean(); + } + + // + Clean(supResBoxes); + + // + return result; + } + + // + bool HasBoxConitions( + XBoxZone &box, + XPOIState &state, + int barIndex = 0, + ENUM_TIMEFRAMES forPeriod = NULL // + ) + { + // + bool result = false; + + // + if (barIndex < 0) + { + barIndex = 0; + } + + // + result = box.IsValid() && + IsValid() && + HasDirection(); + if (!result) + { + // + swingBar.Clean(); + breakerBar.Clean(); + appliedBox.Clean(); + momentumBar.Clean(); + rejectionBar.Clean(); + + // + return result; + } + + // + string symbol = box.symbol; + if (forPeriod == NULL) + { + forPeriod = box.period; + } + ENUM_X_DIRECTION forDir = box.dir; + bool isBullish = IsBullish(forDir); + + // + // Detect Bars ... + + // + XOHCL zBar; + result = zBar.Init( + symbol, + forPeriod, + barIndex // + ); + if (!result) + { + // + zBar.Clean(); + + // + swingBar.Clean(); + breakerBar.Clean(); + appliedBox.Clean(); + momentumBar.Clean(); + rejectionBar.Clean(); + + // + return result; + } + + // + XOHCL cBar; + result = zBar.GetPreviousBar(cBar); + if (!result) + { + // + zBar.Clean(); + cBar.Clean(); + + // + swingBar.Clean(); + breakerBar.Clean(); + appliedBox.Clean(); + momentumBar.Clean(); + rejectionBar.Clean(); + + // + return result; + } + + // + XOHCL pBar; + result = cBar.GetPreviousBar(pBar); + if (!result) + { + // + zBar.Clean(); + cBar.Clean(); + pBar.Clean(); + + // + swingBar.Clean(); + breakerBar.Clean(); + appliedBox.Clean(); + momentumBar.Clean(); + rejectionBar.Clean(); + + // + return result; + } + + // + XOHCL ppBar; + result = pBar.GetPreviousBar(ppBar); + if (!result) + { + // + zBar.Clean(); + cBar.Clean(); + pBar.Clean(); + ppBar.Clean(); + + // + swingBar.Clean(); + breakerBar.Clean(); + appliedBox.Clean(); + momentumBar.Clean(); + rejectionBar.Clean(); + + // + return result; + } + + // + double fiboPressureLevel = GetFiboLevelValue(X_FIBO_LEVEL_382); + + // + double fiboUpDown = GetFibonacciLevel( + pBar.high, + pBar.low, + X_FIBO_LEVEL_382, + X_DIRECTION_BEARISH // + ); + double fiboDownUp = GetFibonacciLevel( + pBar.high, + pBar.low, + X_FIBO_LEVEL_382, + X_DIRECTION_BULLISH // + ); + + // + bool hasFiboToUpPressure = + fiboDownUp > 0 && + fiboDownUp <= pBar.GetDown(); + bool hasFiboToDownPressure = + fiboUpDown > 0 && + fiboUpDown >= pBar.GetUp(); + + // + double appliedPrice = + isBullish + ? box.upper + : box.lower; + + // + // Check Swing Low ... + bool isSwingLow = + // + pBar.low < ppBar.low && + pBar.low < cBar.low && + zBar.open > pBar.low && + // + appliedPrice > pBar.low && + appliedPrice < pBar.GetDown() + // + ; + bool isPressuredSwingLow = + isSwingLow && + hasFiboToUpPressure; + bool isPressuredStrongSwingLow = + pBar.IsBullish() && + isPressuredSwingLow; + + // + bool isSwingHigh = + // + pBar.high > ppBar.high && + pBar.high > cBar.high && + zBar.open < pBar.high && + // + appliedPrice < pBar.high && + appliedPrice > pBar.GetUp() + // + ; + bool isPressuredSwingHigh = + isSwingHigh && + hasFiboToDownPressure; + bool isPressuredStrongSwingHigh = + pBar.IsBearish() && + isPressuredSwingHigh; + + // + bool hasValidSwing = + isBullish + ? isSwingLow + : isSwingHigh; + bool hasValidPressuredSwing = + isBullish + ? isPressuredSwingLow + : isPressuredSwingHigh; + bool hasValidPressuredStrongSwing = + isBullish + ? isPressuredStrongSwingLow + : isPressuredStrongSwingHigh; + if (hasValidSwing) + { + swingBar = pBar; + } + if (hasValidPressuredSwing) + { + swingBar = pBar; + } + if (hasValidPressuredStrongSwing) + { + swingBar = pBar; + } + + // + bool isCBarBreaked = IsBarBreak( + appliedPrice, + forDir, + cBar // + ); + if (isCBarBreaked) + { + breakerBar = cBar; + } + bool isPBarBreaked = IsBarBreak( + appliedPrice, + forDir, + pBar // + ); + if (!isCBarBreaked && isPBarBreaked) + { + breakerBar = pBar; + } + else + { + isPBarBreaked = false; + } + bool isPPBarBreaked = IsBarBreak( + appliedPrice, + forDir, + ppBar // + ); + if (!isCBarBreaked && + !isPBarBreaked && + isPPBarBreaked) + { + breakerBar = ppBar; + } + else + { + isPPBarBreaked = false; + } + bool isBoxBreaked = isCBarBreaked || + isPBarBreaked || + isPPBarBreaked; + + // + bool isCBarRejected = IsBarReject( + appliedPrice, + forDir, + cBar // + ); + if (isCBarRejected) + { + rejectionBar = cBar; + } + bool isPBarRejected = IsBarReject( + appliedPrice, + forDir, + pBar // + ); + if (!isCBarRejected && isPBarRejected) + { + rejectionBar = pBar; + } + else + { + isPBarRejected = false; + } + bool isPPBarRejected = IsBarReject( + appliedPrice, + forDir, + ppBar // + ); + if (!isCBarRejected && + !isPBarRejected && + isPPBarRejected) + { + rejectionBar = ppBar; + } + else + { + isPPBarRejected = false; + } + bool isBoxRejected = isCBarRejected || + isPBarRejected || + isPPBarRejected; + + // + result = + // + isBoxBreaked || + isBoxRejected || + hasValidPressuredSwing + // + ; + if (!result) + { + // + swingBar.Clean(); + breakerBar.Clean(); + appliedBox.Clean(); + momentumBar.Clean(); + rejectionBar.Clean(); + } + else + { + appliedBox = box; + } + + // + zBar.Clean(); + cBar.Clean(); + pBar.Clean(); + ppBar.Clean(); + + // + return result; + } + // }; @@ -3458,6 +3209,8 @@ struct X121SMCStrategyXWZSignalConditions // bool HasConditions( + double &_pivot, + double &_point, ENUM_X_DIRECTION &conditionsDir, XPOIState &state, int barIndex = 0, @@ -3468,6 +3221,8 @@ struct X121SMCStrategyXWZSignalConditions bool result = false; // + _pivot = 0; + _point = 0; conditionsDir = X_DIRECTION_NONE; // @@ -3497,12 +3252,16 @@ struct X121SMCStrategyXWZSignalConditions return result; } + // + result = false; + // // Detect Conditions Based On Start Zones ... bool hasStartZones = HasStartZones(); if (hasStartZones) { // + int selectedIndex = -1; int count = CountStartZones(); for (int i = 0; i < count; i++) { @@ -3510,36 +3269,161 @@ struct X121SMCStrategyXWZSignalConditions X121SMCXWZZone iStartZone = startZones[i]; // + XBoxZone selectedBox; + bool hasConditions = false; + bool isBullish = iStartZone.IsBullish(); + + // + // Conditions Inside Box ... bool isPriceInside = iStartZone.IsPriceInside( + selectedBox, barIndex, forPeriod // ); - if (!isPriceInside) + if (isPriceInside) { // - iStartZone.Clean(); - continue; + hasConditions = iStartZone.HasInsideConditions( + state, + barIndex, + period // + ); + + // + if (hasConditions) + { + // + _pivot = + // + isBullish + ? selectedBox.lower + : selectedBox.upper + // + ; + + // + _point = + // + isBullish + ? selectedBox.upper + : selectedBox.lower + // + ; + + // + conditionsDir = selectedBox.dir; + result = hasConditions; + iStartZone.Clean(); + break; + } } // - Print("PriceInside ..."); - - // - bool hasConditions = iStartZone.HasCondition( - state, - barIndex, - forPeriod // + // Order Block Rejection Conditions ... + bool hasOBBox = ToBox( + selectedBox, + iStartZone.ob // ); - if (!hasConditions) + if (hasOBBox && + !hasConditions) { // - iStartZone.Clean(); - continue; + hasConditions = iStartZone.HasBoxConitions( + selectedBox, + state, + barIndex, + forPeriod // + ); + + // + if (hasConditions) + { + // + _pivot = + // + isBullish + ? selectedBox.lower + : selectedBox.upper + // + ; + + // + _point = + // + isBullish + ? selectedBox.upper + : selectedBox.lower + // + ; + + // + conditionsDir = selectedBox.dir; + result = hasConditions; + iStartZone.Clean(); + break; + } + } + + // + // Fair Value Gap Rejection Conditions ... + bool hasFVGBox = ToBox( + selectedBox, + iStartZone.fvg // + ); + if (hasFVGBox) + { + // + hasConditions = iStartZone.HasBoxConitions( + selectedBox, + state, + barIndex, + forPeriod // + ); + + // + if (hasConditions) + { + // + _pivot = + // + isBullish + ? selectedBox.lower + : selectedBox.upper + // + ; + + // + _point = + // + isBullish + ? selectedBox.upper + : selectedBox.lower + // + ; + + // + conditionsDir = selectedBox.dir; + result = hasConditions; + iStartZone.Clean(); + break; + } } // iStartZone.Clean(); } + + // + if (result && + IsValidIndex(selectedIndex)) + { + // + ArrayRemove( + startZones, + selectedIndex, + 1 // + ); + } } // @@ -3550,6 +3434,18 @@ struct X121SMCStrategyXWZSignalConditions // Detect Result Based On WorkingZone ... } + // + if (!result) + { + // + _point = 0; + _pivot = 0; + conditionsDir = X_DIRECTION_NONE; + + // + return result; + } + // return result; }