diff --git a/Classes/x-saherelm.x-bar.analyser.class.mq5 b/Classes/x-saherelm.x-bar.analyser.class.mq5 index 1fe7ae04..9369e1b1 100644 --- a/Classes/x-saherelm.x-bar.analyser.class.mq5 +++ b/Classes/x-saherelm.x-bar.analyser.class.mq5 @@ -1399,7 +1399,7 @@ class XCBarAnalyser : public XCBase // // Select OB Candidate Bars ... - + XOHCL sameBar; XOHCL rootBar; XOHCL rootPBar; @@ -1553,7 +1553,7 @@ class XCBarAnalyser : public XCBase // // Cleanup Resource ... - + // sBar.Clean(); rootBar.Clean(); @@ -2448,6 +2448,184 @@ class XCBarAnalyser : public XCBase return result; } + // + // + // + + /** + * Check a Bar is Valid for Specified Direction of Positions ... + * + * @param bar: XOHCL instance, Start Bar ... + * @param dir: ENUM_X_DIRECTION member, Provide Direction ... + * + * @return ( bool ) + */ + bool IsValidForPosition( + XOHCL &bar, + ENUM_X_DIRECTION &dir // + ) + { + // + bool result = false; + + // + int loopback = 3; + dir = X_DIRECTION_NONE; + + // + result = bar.IsValid(); + if (!result) + { + return result; + } + + // + // DOJI ... + ENUM_X_DIRECTION dojiDir; + bool isDoji = IsDoji( + bar, + dojiDir // + ); + bool isBullishDoji = + isDoji && + IsBullish(dojiDir); + bool isBearishDoji = + isDoji && + IsBearish(dojiDir); + + // + // SWING ... + ENUM_X_DIRECTION swingDir; + bool isSwing = IsSwing( + bar, + swingDir // + ); + bool isBullishSwing = + isSwing && + IsBullish(swingDir); + bool isBearishSwing = + isSwing && + IsBearish(swingDir); + + // + // HAMMER ... + ENUM_X_DIRECTION hammerDir; + bool isHammer = IsHammer( + bar, + hammerDir // + ); + bool isBullishHammer = + isHammer && + IsBullish(hammerDir); + bool isBearishHammer = + isHammer && + IsBearish(hammerDir); + + // + // ENGULF ... + ENUM_X_DIRECTION engulfDir; + bool isEngulfed = IsEngulfed( + bar, + engulfDir // + ); + bool isBullishEngulfed = + isEngulfed && + IsBullish(engulfDir); + bool isBearishEngulfed = + isEngulfed && + IsBearish(engulfDir); + + // + // REJECTED ... + ENUM_X_DIRECTION rejectedDir; + bool isRejected = IsRejected( + bar, + rejectedDir // + ); + bool isBullishRejected = + isRejected && + IsBullish(rejectedDir); + bool isBearishRejected = + isRejected && + IsBearish(rejectedDir); + + // + // MOMENTUM ... + ENUM_X_DIRECTION momentumDir; + bool isMomentum = IsMomentum( + bar, + momentumDir // + ); + bool isBullishMomentum = + isMomentum && + IsBullish(momentumDir); + bool isBearishMomentum = + isMomentum && + IsBearish(momentumDir); + + // + // PULLBACK ... + ENUM_X_DIRECTION pullbackDir; + bool isPullback = IsPullback( + bar, + pullbackDir // + ); + bool isBullishPullback = + isPullback && + IsBullish(pullbackDir); + bool isBearishPullback = + isPullback && + IsBearish(pullbackDir); + + // + // Summarize Conditions ... + + // + bool isBullishOr = + isBullishDoji || + isBullishSwing || + isBullishHammer || + isBullishEngulfed || + isBullishRejected || + isBullishMomentum || + isBullishPullback; + + // + bool isBearishOr = + isBearishDoji || + isBearishSwing || + isBearishHammer || + isBearishEngulfed || + isBearishRejected || + isBearishMomentum || + isBearishPullback; + + // + bool isBullish = + isBullishOr && + !isBearishOr; + + // + bool isBearish = + !isBullishOr && + isBearishOr; + + // + result = isBullish || + isBearish; + if (result) + { + // + dir = + isBullish + ? X_DIRECTION_BULLISH + : X_DIRECTION_BEARISH; + } + + // + return result; + } + // protected: // diff --git a/Documents/BKP/x-omid.signalling.mq5 b/Documents/BKP/x-omid.signalling.mq5 new file mode 100644 index 00000000..3b820c33 --- /dev/null +++ b/Documents/BKP/x-omid.signalling.mq5 @@ -0,0 +1,543 @@ + // + bool HasSenario1Conditions( + ENUM_X_CYCLES cycle, + XBoxZone &box, + XBoxZone &holderBox, + ENUM_X_DIRECTION &dir, + X121SMCStrategySignalProviderData &provider, + ENUM_X_CYCLES holderCycle = X_CYCLE_NONE, + int barIndex = 0 // + ) + { + // + bool result = false; + + // + // Fil Selected Data ... + XPOIState cState; + X121Conditions cXConditions; + XC121SMCCycleHelper *cHelper; + X121SMCCycleConditions cConditions; + result = provider.SelectCycle( + cycle, + cState, + cXConditions, + cHelper, + cConditions // + ); + if (!result) + { + // + cState.Clean(); + ZeroMemory(cHelper); + cConditions.Clean(); + cXConditions.Clean(); + + // + return result; + } + Parse(cXConditions); + + // + // Fil Selected Data ... + XPOIState chState; + X121Conditions chXConditions; + XC121SMCCycleHelper *chHelper; + X121SMCCycleConditions chConditions; + if (holderCycle != X_CYCLE_NONE) + { + // + result = provider.SelectCycle( + holderCycle, + chState, + chXConditions, + chHelper, + chConditions // + ); + if (!result) + { + // + chState.Clean(); + ZeroMemory(chHelper); + chConditions.Clean(); + chXConditions.Clean(); + + // + return result; + } + + // + Parse(chXConditions); + } + + // + // 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; + + // + 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(); + chState.Clean(); + ZeroMemory(cHelper); + cConditions.Clean(); + cXConditions.Clean(); + ZeroMemory(chHelper); + chConditions.Clean(); + chXConditions.Clean(); + + // + return result; + } + + // + // Detecting Signal Conditions ... + + // + bool isX3MAFastRejectUp = + // + cBar.low < cXConditions.x3maFastBuffer[cIDX] && + cBar.GetDown() > cXConditions.x3maFastBuffer[cIDX] + // + ; + + // + bool isX3MAFastRejectDown = + // + cBar.high > cXConditions.x3maFastBuffer[cIDX] && + cBar.GetUp() < cXConditions.x3maFastBuffer[cIDX] + // + ; + + // + // Find Breaker Bar ... + datetime nearCloseOverX3MAFast = cHelper.GetNearestCloseOverX3MAFast(cBar); + datetime nearCloseUnderX3MAFast = cHelper.GetNearestCloseUnderX3MAFast(cBar); + bool hasNearestCloseOverX3MAFast = + IsValid(nearCloseOverX3MAFast) && + IsValid(nearCloseUnderX3MAFast) + ? nearCloseOverX3MAFast > nearCloseUnderX3MAFast + : IsValid(nearCloseOverX3MAFast) + ? true + : false; + bool hasNearestCloseUnderX3MAFast = + IsValid(nearCloseOverX3MAFast) && + IsValid(nearCloseUnderX3MAFast) + ? nearCloseUnderX3MAFast > nearCloseOverX3MAFast + : IsValid(nearCloseUnderX3MAFast) + ? true + : false; + + // + // Bullish Conditions ... + isBullish = + // + // Base Condition ... + ( + // + cBar.IsBullish() && + isX3MAFastRejectUp && + cXConditions.isSMHKBullish && + hasNearestCloseOverX3MAFast && + cXConditions.xhkSMOpenBuffer[cIDX] < cXConditions.x3maMidBuffer[cIDX] + // + ) + // + ; + + // + // Bearish Conditions ... + isBearish = + // + // Base Condition ... + ( + // + cBar.IsBearish() && + isX3MAFastRejectDown && + cXConditions.isSMHKBearish && + hasNearestCloseUnderX3MAFast && + cXConditions.xhkSMOpenBuffer[cIDX] > cXConditions.x3maMidBuffer[cIDX] + // + ) + // + ; + + // + // Filling Requirements ... + result = + isBullish || + isBearish; + if (result) + { + // + dir = + isBullish + ? X_DIRECTION_BULLISH + : X_DIRECTION_BEARISH; + + // + box.dir = dir; + box.to = TimeCurrent(); + box.symbol = cXConditions.symbol; + box.period = cXConditions.period; + + // + int fromIDX = -1; + if (isBullish) + { + // + fromIDX = GetBarIndex( + cBar.symbol, + cBar.period, + nearCloseOverX3MAFast // + ); + } + else + { + // + fromIDX = GetBarIndex( + cBar.symbol, + cBar.period, + nearCloseUnderX3MAFast // + ); + } + + // + if (IsValidIndex(fromIDX)) + { + // + box.from = iTime( + zBar.symbol, + zBar.period, + fromIDX // + ); + } + else + { + box.from = pBar.time; + } + + // + // Detect Holder Box ... + XBoxZone tmpBoxes[]; + if (chState.IsValid()) + { + // + if (isBullish) + { + // + // Demand Zones ... + XBoxZone tmp[]; + ToBox( + chState.demandZones, + tmp // + ); + Copy( + tmp, + tmpBoxes, + false // + ); + Clean(tmp); + + // + // Bullish Order Blocks ... + ToBox( + chState.bullishOrderBlocks, + tmp // + ); + Copy( + tmp, + tmpBoxes, + false // + ); + Clean(tmp); + + // + // Bullish Fair Value Gaps ... + ToBox( + chState.bullishFairValueGaps, + tmp // + ); + Copy( + tmp, + tmpBoxes, + false // + ); + Clean(tmp); + } + else + { + // + // Supply Zones ... + XBoxZone tmp[]; + ToBox( + chState.supplyZones, + tmp // + ); + Copy( + tmp, + tmpBoxes, + false // + ); + Clean(tmp); + + // + // Bearish Order Blocks ... + ToBox( + chState.bearishOrderBlocks, + tmp // + ); + Copy( + tmp, + tmpBoxes, + false // + ); + Clean(tmp); + + // + // Bearish Fair Value Gaps ... + ToBox( + chState.bearishFairValueGaps, + tmp // + ); + Copy( + tmp, + tmpBoxes, + false // + ); + Clean(tmp); + } + } + + // + has = HasChild(tmpBoxes); + if (has) + { + // + while (HasChild(tmpBoxes)) + { + // + idx = GetOldest(tmpBoxes); + has = IsValidIndex(idx); + if (!has) + { + break; + } + + // + XBoxZone iBox = tmpBoxes[idx]; + ArrayRemove( + tmpBoxes, + idx, + 1 // + ); + + // + has = IsBoxInside( + box, + iBox // + ); + if (has) + { + // + holderBox = iBox; + holderBox.to = TimeCurrent(); + iBox.Clean(); + break; + } + + // + iBox.Clean(); + } + } + + // + Clean(tmpBoxes); + + // + // Fix Box Upper and Lower based on Strategy ... + + // + double points = GetPoints(box.symbol); + double minPointsDiff = points * 20; + + // + double prefferSL = 0; + + // + // Other SL Conditions ... + if (prefferSL <= 0) + { + // + prefferSL = cHelper + .mX121Helper + .xhkHelper + .GetSMHKOpen(fromIDX); + } + + // + if (prefferSL > 0) + { + // + box.upper = + isBullish + ? zBar.open + : prefferSL; + + // + box.lower = + isBullish + ? prefferSL + : zBar.open; + } + + // + if (box.IsValid()) + { + // + XCBoxObject *iObj; + bool isCreated = cHelper.mPOIDrawer.DrawBox( + box, + iObj // + ); + if (isCreated) + { + // + iObj.BoxWidth(2); + iObj.BoxFill(true); + iObj.BoxStyle(STYLE_DOT); + + // + Print("Signal ..."); + } + } + + // + // Validate Conditions to Force Has Holder Box ... + + // // + // result = + // result && + // holderBox.IsValid() && + // dir == holderBox.dir; + + // // + // if (!result) + // { + // // + // isBullish = false; + // isBearish = false; + // } + } + + // + // Check All Conditions ... + result = + box.IsValid() && + HasDirection(dir) && + (isBullish || + isBearish); + + // + // Cleanup Resources ... + zBar.Clean(); + cBar.Clean(); + pBar.Clean(); + cState.Clean(); + chState.Clean(); + ZeroMemory(cHelper); + cConditions.Clean(); + cXConditions.Clean(); + ZeroMemory(chHelper); + chConditions.Clean(); + chXConditions.Clean(); + + // + return result; + } + + /////////////////////////////////////////////////////////////// + + // + // Detecting Signal Conditions ... + + // + // Bullish Conditions ... + isBullish = + // + // Base Condition ... + ( + // + provider.visionXConditions.isSMHKBullish && + provider.decisionXConditions.isSarBullish && + provider.decisionXConditions.isVWapFastBullish && + provider.decisionXConditions.isX3MaFastBullish && + provider.consolidationXConditions.isSMHKBullish && + provider.decisionXConditions.isSMHKSwitchedToBullish + // + ) + // + ; + + // + // Bearish Conditions ... + isBearish = + // + // Base Condition ... + ( + // + provider.visionXConditions.isSMHKBearish && + provider.decisionXConditions.isSarBearish && + provider.decisionXConditions.isVWapFastBearish && + provider.decisionXConditions.isX3MaFastBearish && + provider.consolidationXConditions.isSMHKBearish && + provider.decisionXConditions.isSMHKSwitchedToBearish + // + ) + // + ; 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 1ee34e13..427329d7 100644 --- a/X121SMCEA/Classes/x-121.smc.market.cycle.helper.class.mq5 +++ b/X121SMCEA/Classes/x-121.smc.market.cycle.helper.class.mq5 @@ -824,6 +824,138 @@ class XC121SMCCycleHelper : public XCBase return result; } + // + datetime GetNearestCloseOverX3MAFast( + XOHCL &bar, + int maxAllowedBars = 20 // + ) + { + // + datetime result = NULL; + + // + if (!bar.IsValid()) + { + return result; + } + + // + bool has = false; + int idx = bar.Index(); + int start = idx; + int end = start + maxAllowedBars; + bool canContinue = true; + while (canContinue) + { + // + XOHCL iBar; + has = iBar.Init( + bar.symbol, + bar.period, + start // + ); + if (!has) + { + // + iBar.Clean(); + break; + } + + // + double iFast = mX121Helper + .x3maHelper + .GetX3MaFast(start); + + // + has = iBar.close > iFast && + iBar.open < iFast; + if (has) + { + result = iBar.time; + } + + // + canContinue = + start < end && + !IsValid(result); + + // + start++; + + // + iBar.Clean(); + } + + // + return result; + } + + // + datetime GetNearestCloseUnderX3MAFast( + XOHCL &bar, + int maxAllowedBars = 20 // + ) + { + // + datetime result = NULL; + + // + if (!bar.IsValid()) + { + return result; + } + + // + bool has = false; + int idx = bar.Index(); + int start = idx; + int end = start + maxAllowedBars; + bool canContinue = true; + while (canContinue) + { + // + XOHCL iBar; + has = iBar.Init( + bar.symbol, + bar.period, + start // + ); + if (!has) + { + // + iBar.Clean(); + break; + } + + // + double iFast = mX121Helper + .x3maHelper + .GetX3MaFast(start); + + // + has = iBar.close < iFast && + iBar.open > iFast; + if (has) + { + result = iBar.time; + } + + // + canContinue = + start < end && + !IsValid(result); + + // + start++; + + // + iBar.Clean(); + } + + // + return result; + } + // // Virtuals ... @@ -1448,6 +1580,7 @@ struct X121SMCStrategySignalProviderData bool SelectCycle( ENUM_X_CYCLES cycle, XPOIState &cState, + XPOIStateEvents &cStateEvents, X121Conditions &cXConditions, XC121SMCCycleHelper *&cHelper, X121SMCCycleConditions &cConditions // @@ -1460,6 +1593,7 @@ struct X121SMCStrategySignalProviderData cState.Clean(); ZeroMemory(cHelper); cConditions.Clean(); + cStateEvents.Clean(); cXConditions.Clean(); // @@ -1477,6 +1611,7 @@ struct X121SMCStrategySignalProviderData cHelper = triggerCycleHelper; cConditions = triggerConditions; cXConditions = triggerXConditions; + cStateEvents.Init(triggerPoiEvents); } else if (cycle == X_CYCLE_DECISION) { @@ -1485,6 +1620,7 @@ struct X121SMCStrategySignalProviderData cHelper = decisionCycleHelper; cConditions = decisionConditions; cXConditions = decisionXConditions; + cStateEvents.Init(decisionPoiEvents); } else if (cycle == X_CYCLE_ANALYSE) { @@ -1493,6 +1629,7 @@ struct X121SMCStrategySignalProviderData cHelper = analyseCycleHelper; cConditions = analyseConditions; cXConditions = analyseXConditions; + cStateEvents.Init(analysePoiEvents); } else if (cycle == X_CYCLE_VERIFICATION) { @@ -1501,6 +1638,7 @@ struct X121SMCStrategySignalProviderData cHelper = verificationCycleHelper; cConditions = verificationConditions; cXConditions = verificationXConditions; + cStateEvents.Init(verificationPoiEvents); } else if (cycle == X_CYCLE_CONSOLIDATION) { @@ -1509,6 +1647,7 @@ struct X121SMCStrategySignalProviderData cHelper = consolidationCycleHelper; cConditions = consolidationConditions; cXConditions = consolidationXConditions; + cStateEvents.Init(consolidationPoiEvents); } else if (cycle == X_CYCLE_VISION) { @@ -1517,6 +1656,7 @@ struct X121SMCStrategySignalProviderData cHelper = visionCycleHelper; cConditions = visionConditions; cXConditions = visionXConditions; + cStateEvents.Init(visionPoiEvents); } // @@ -2491,6 +2631,7 @@ struct X121SMCStrategyConditionParser XBoxZone &box, XBoxZone &holderBox, ENUM_X_DIRECTION &dir, + XBoxZone &waitingBoxes[], X121SMCStrategySignalProviderData &provider, ENUM_X_CYCLES holderCycle = X_CYCLE_NONE, int barIndex = 0 // @@ -2503,11 +2644,13 @@ struct X121SMCStrategyConditionParser // Fil Selected Data ... XPOIState cState; X121Conditions cXConditions; + XPOIStateEvents cStateEvents; XC121SMCCycleHelper *cHelper; X121SMCCycleConditions cConditions; result = provider.SelectCycle( cycle, cState, + cStateEvents, cXConditions, cHelper, cConditions // @@ -2519,6 +2662,7 @@ struct X121SMCStrategyConditionParser ZeroMemory(cHelper); cConditions.Clean(); cXConditions.Clean(); + cStateEvents.Clean(); // return result; @@ -2529,6 +2673,7 @@ struct X121SMCStrategyConditionParser // Fil Selected Data ... XPOIState chState; X121Conditions chXConditions; + XPOIStateEvents chStateEvents; XC121SMCCycleHelper *chHelper; X121SMCCycleConditions chConditions; if (holderCycle != X_CYCLE_NONE) @@ -2537,6 +2682,7 @@ struct X121SMCStrategyConditionParser result = provider.SelectCycle( holderCycle, chState, + chStateEvents, chXConditions, chHelper, chConditions // @@ -2548,6 +2694,7 @@ struct X121SMCStrategyConditionParser ZeroMemory(chHelper); chConditions.Clean(); chXConditions.Clean(); + chStateEvents.Clean(); // return result; @@ -2557,6 +2704,19 @@ struct X121SMCStrategyConditionParser Parse(chXConditions); } + // + // Checking Waiting Baoxes Exists ... + result = HasChild(waitingBoxes); + if (!result) + { + return result; + } + + // + XCPOIDrawer *drawer = provider + .visionCycleHelper + .mPOIDrawer; + // // Normalize Args ... @@ -2580,6 +2740,7 @@ struct X121SMCStrategyConditionParser int zIDX = barIndex; int cIDX = zIDX + 1; int pIDX = cIDX + 1; + int ppIDX = pIDX + 1; // bool isBullish = false; @@ -2623,927 +2784,86 @@ struct X121SMCStrategyConditionParser } // - // Detecting Signal Conditions ... - - // - // Bullish Conditions ... - isBullish = - // - // Base Condition ... - ( - // - cXConditions.supportsBuffer[cIDX] == cXConditions.valesBuffer[zIDX] - // - // cXConditions.isSarSwitchedToBullish && - // cXConditions.isSMHKSwitchedToBullish && - // cBar.low < cXConditions.masLowerBuffer[cIDX] && - // cBar.low < cXConditions.valesGoldenBuffer[cIDX] && - // zBar.close < cXConditions.valesGoldenBuffer[cIDX] && - // cXConditions.xhkSMCloseBuffer[cIDX] < cXConditions.valesGoldenBuffer[cIDX] - // - ) - // - ; - - // - // Bearish Conditions ... - isBearish = - // - // Base Condition ... - ( - // - false - // - ) - // - ; - - // - // Filling Requirements ... - result = - isBullish || - isBearish; - if (result) - { - // - dir = - isBullish - ? X_DIRECTION_BULLISH - : X_DIRECTION_BEARISH; - - // - box.dir = dir; - box.to = TimeCurrent(); - box.symbol = cXConditions.symbol; - box.period = cXConditions.period; - - // - int fromIDX = -1; - if (isBullish) - { - // - double vale = cXConditions.valesBuffer[cIDX]; - box.lower = vale; - box.upper = cXConditions.valesGoldenBuffer[cIDX]; - - // - int lowerValeIDX = -1; - double lowerVale = cHelper - .mX121Helper - .xpvHelper - .GetLowerVale( - lowerValeIDX, - vale, - cBar.Index() // - ); - - // - int higherValeIDX = -1; - double higherVale = cHelper - .mX121Helper - .xpvHelper - .GetHigherVale( - higherValeIDX, - vale, - cBar.Index() // - ); - - // - if (IsValidIndex(lowerValeIDX) && - IsValidIndex(higherValeIDX)) - { - // - fromIDX = - lowerValeIDX < higherValeIDX - ? lowerValeIDX - : higherValeIDX; - } - else if (IsValidIndex(lowerValeIDX) && - !IsValidIndex(higherValeIDX)) - { - // - fromIDX = lowerValeIDX; - } - else if (!IsValidIndex(lowerValeIDX) && - IsValidIndex(higherValeIDX)) - { - // - fromIDX = higherValeIDX; - } - } - else - { - // - double peak = cXConditions.peaksBuffer[cIDX]; - box.upper = peak; - - // - box.lower = cXConditions.peaksGoldenBuffer[cIDX]; - - // - int lowerPeakIDX = -1; - double lowerPeak = cHelper - .mX121Helper - .xpvHelper - .GetLowerPeak( - lowerPeakIDX, - peak, - cBar.Index() // - ); - - // - int higherPeakIDX = -1; - double higherPeak = cHelper - .mX121Helper - .xpvHelper - .GetHigherPeak( - higherPeakIDX, - peak, - cBar.Index() // - ); - - // - if (IsValidIndex(lowerPeakIDX) && - IsValidIndex(higherPeakIDX)) - { - // - fromIDX = - lowerPeakIDX < higherPeakIDX - ? lowerPeakIDX - : higherPeakIDX; - } - else if (IsValidIndex(lowerPeakIDX) && - !IsValidIndex(higherPeakIDX)) - { - // - fromIDX = lowerPeakIDX; - } - else if (!IsValidIndex(lowerPeakIDX) && - IsValidIndex(higherPeakIDX)) - { - // - fromIDX = higherPeakIDX; - } - } - - // - if (IsValidIndex(fromIDX)) - { - // - box.from = iTime( - zBar.symbol, - zBar.period, - fromIDX // - ); - } - else - { - box.from = pBar.time; - } - - // - // Detect Holder Box ... - XBoxZone tmpBoxes[]; - if (chState.IsValid()) - { - // - if (isBullish) - { - // - // Demand Zones ... - XBoxZone tmp[]; - ToBox( - chState.demandZones, - tmp // - ); - Copy( - tmp, - tmpBoxes, - false // - ); - Clean(tmp); - - // - // Bullish Order Blocks ... - ToBox( - chState.bullishOrderBlocks, - tmp // - ); - Copy( - tmp, - tmpBoxes, - false // - ); - Clean(tmp); - - // - // Bullish Fair Value Gaps ... - ToBox( - chState.bullishFairValueGaps, - tmp // - ); - Copy( - tmp, - tmpBoxes, - false // - ); - Clean(tmp); - } - else - { - // - // Supply Zones ... - XBoxZone tmp[]; - ToBox( - chState.supplyZones, - tmp // - ); - Copy( - tmp, - tmpBoxes, - false // - ); - Clean(tmp); - - // - // Bearish Order Blocks ... - ToBox( - chState.bearishOrderBlocks, - tmp // - ); - Copy( - tmp, - tmpBoxes, - false // - ); - Clean(tmp); - - // - // Bearish Fair Value Gaps ... - ToBox( - chState.bearishFairValueGaps, - tmp // - ); - Copy( - tmp, - tmpBoxes, - false // - ); - Clean(tmp); - } - } - - // - has = HasChild(tmpBoxes); - if (has) - { - // - while (HasChild(tmpBoxes)) - { - // - idx = GetOldest(tmpBoxes); - has = IsValidIndex(idx); - if (!has) - { - break; - } - - // - XBoxZone iBox = tmpBoxes[idx]; - ArrayRemove( - tmpBoxes, - idx, - 1 // - ); - - // - has = IsBoxInside( - box, - iBox // - ); - if (has) - { - // - holderBox = iBox; - holderBox.to = TimeCurrent(); - iBox.Clean(); - break; - } - - // - iBox.Clean(); - } - } - - // - Clean(tmpBoxes); - - // - // Fix Box Upper and Lower based on Strategy ... - - // - double points = GetPoints(box.symbol); - double minPointsDiff = points * 20; - - // - double prefferSL = 0; - - // - // Other SL Conditions ... - if (prefferSL <= 0) - { - // - if (isBullish) - { - // - if (zBar.open < cXConditions.valesGoldenBuffer[cIDX]) - { - prefferSL = cXConditions.valesBuffer[cIDX]; - } - else if (zBar.open > cXConditions.valesGoldenBuffer[cIDX] && - zBar.open < cXConditions.peaksGoldenBuffer[cIDX]) - { - prefferSL = cXConditions.valesGoldenBuffer[cIDX]; - } - else if (zBar.open > cXConditions.peaksGoldenBuffer[cIDX]) - { - // - if (cXConditions.sarBuffer[cIDX] > cXConditions.peaksGoldenBuffer[cIDX]) - { - prefferSL = cXConditions.sarBuffer[cIDX]; - } - else - { - prefferSL = zBar.open > cXConditions.peaksGoldenBuffer[cIDX]; - } - } - } - else - { - // - if (zBar.open > cXConditions.peaksGoldenBuffer[cIDX]) - { - prefferSL = cXConditions.peaksBuffer[cIDX]; - } - else if (zBar.open < cXConditions.peaksGoldenBuffer[cIDX] && - zBar.open > cXConditions.valesGoldenBuffer[cIDX]) - { - prefferSL = cXConditions.peaksGoldenBuffer[cIDX]; - } - else if (zBar.open < cXConditions.valesGoldenBuffer[cIDX]) - { - // - if (cXConditions.sarBuffer[cIDX] < cXConditions.valesGoldenBuffer[cIDX]) - { - prefferSL = cXConditions.sarBuffer[cIDX]; - } - else - { - prefferSL = cXConditions.valesGoldenBuffer[cIDX]; - } - } - } - } - - // - if (prefferSL > 0) - { - // - box.upper = - isBullish - ? zBar.open - : prefferSL; - - // - box.lower = - isBullish - ? prefferSL - : zBar.open; - } - - // - // Validate Conditions to Force Has Holder Box ... - - result = - result && - holderBox.IsValid() && - dir == holderBox.dir; - - // - if (!result) - { - // - isBullish = false; - isBearish = false; - } - } - - // - // Check All Conditions ... - result = - box.IsValid() && - HasDirection(dir) && - (isBullish || - isBearish); - - // - // Cleanup Resources ... - zBar.Clean(); - cBar.Clean(); - pBar.Clean(); - cState.Clean(); - chState.Clean(); - ZeroMemory(cHelper); - cConditions.Clean(); - cXConditions.Clean(); - ZeroMemory(chHelper); - chConditions.Clean(); - chXConditions.Clean(); - - // - return result; - } - - // - bool HasSenario2Conditions( - ENUM_X_CYCLES ttfCycle, - XBoxZone &breakedBoxes[], - XBoxZone &box, - ENUM_X_DIRECTION &dir, - X121SMCStrategySignalProviderData &provider, - int barIndex = 0, - bool forceBarType = false, - bool forceFiboPressure = false // - ) - { - // - bool result = false; - - // - // Validate Args ... - result = - IsValid(ttfCycle) && - HasChild(breakedBoxes); - if (!result) - { - return result; - } - - // - // TODO: Add support for Extracting Trend ... - ENUM_X_DIRECTION trend = X_DIRECTION_NONE; - bool hasBullishTrend = IsBullish(trend); - bool hasBearishTrend = IsBearish(trend); - - // - // TTF Cycle Extract ... - XPOIState ttfState; - X121Conditions ttfXConditions; - XC121SMCCycleHelper *ttfHelper; - X121SMCCycleConditions ttfConditions; - result = provider.SelectCycle( - ttfCycle, - ttfState, - ttfXConditions, - ttfHelper, - ttfConditions // - ); - if (!result) - { - // - ttfState.Clean(); - ZeroMemory(ttfHelper); - ttfConditions.Clean(); - ttfXConditions.Clean(); - - // - return result; - } - Parse(ttfXConditions); - - // - // Normalize Args ... - - // - box.Clean(); - dir = X_DIRECTION_NONE; - - // - if (barIndex < 0) - { - barIndex = 0; - } - - // - // Define Resources ... - - // - int idx = -1; - int count = 0; - bool has = false; - - // - int zIDX = barIndex; - int cIDX = zIDX + 1; - int pIDX = cIDX + 1; - - // - double ask = GetAsk(ttfState.symbol); - double bid = GetBid(ttfState.symbol); - - // - bool isBullish = false; - bool isBearish = false; - - // - XOHCL zBar; - XOHCL cBar; - XOHCL pBar; - - // - // Initial Bars ... - result = zBar.Init( - ttfState.symbol, - ttfState.period, - barIndex // - ); - result = - result && - zBar.GetPreviousBar(cBar); - result = - result && - cBar.GetPreviousBar(pBar); - if (!result) - { - // - zBar.Clean(); - cBar.Clean(); - pBar.Clean(); - ttfState.Clean(); - ZeroMemory(ttfHelper); - ttfConditions.Clean(); - ttfXConditions.Clean(); - - // - return result; - } - - // - // Conditions ... - - // - // First we Have to Detect Inside Box ... + // Detect Inside Box ... XBoxZone insideBox; - count = ArraySize(breakedBoxes); - for (int i = 0; i < count; i++) + count = ArraySize(waitingBoxes); + has = IsValidSize(count); + if (has) { // - XBoxZone iBox = breakedBoxes[i]; - - // - bool isInside = - IsInsideBox( - zBar, - iBox // - ); - if (isInside) + for (int i = 0; i < count; i++) { // - // Since we have to Follow Trend based on Breaked Boxes ... - // we have to use: - // - Breaked Bullish Boxes on Bearish Trend ... - // - Breaked Bearish Boxes on Bullish Trend ... - isInside = - hasBullishTrend - ? iBox.IsBearish() - : hasBearishTrend - ? iBox.IsBullish() - : false; + XBoxZone iBox = waitingBoxes[i]; + bool isBullish = iBox.IsBullish(); + double iMid = iBox.lower + ((iBox.upper - iBox.lower) / 2); // - // Check Inside ... - if (isInside) + has = + // + isBullish + ? cBar.low < iMid && + cBar.low > iBox.lower + : cBar.high > iMid && + cBar.high < iBox.upper + // + ; + if (has) { // insideBox = iBox; - iBox.Clean(); - - // break; } } - - // - iBox.Clean(); } + has = insideBox.IsValid(); // - // Check Inside Box is Valid or not ... - result = insideBox.IsValid(); - if (!result) + ENUM_X_DIRECTION iBarPosDir; + bool isBarValidForDir = cHelper + .mBarAnalyser + .IsValidForPosition( + cBar, + iBarPosDir // + ); + bool isBarValidForBullish = + isBarValidForDir && + IsBullish(iBarPosDir); + bool isBarValidForBearish = + isBarValidForDir && + IsBearish(iBarPosDir); + + // + if (has) { // - zBar.Clean(); - cBar.Clean(); - pBar.Clean(); - ttfState.Clean(); - insideBox.Clean(); - ZeroMemory(ttfHelper); - ttfConditions.Clean(); - ttfXConditions.Clean(); - } - - // - // Update Inside Box From and To ... - // Based on Breaked ... - insideBox.from = insideBox.to; - insideBox.to = TimeCurrent(); - - // - // Detect Breaked Box Direction ... - bool isInsideBoxBullish = insideBox.IsBullish(); - bool isInsideBoxBearish = insideBox.IsBearish(); - - // - // Detect Inside Box Rejection ... - - // - bool isUpperBearishReject = - cBar.high >= insideBox.upper && - cBar.GetUp() < insideBox.upper; - - // - bool isUpperBullishReject = - cBar.low <= insideBox.upper && - cBar.GetDown() > insideBox.upper; - - // - bool isLowerBearishReject = - cBar.high >= insideBox.lower && - cBar.GetUp() < insideBox.lower; - - // - bool isLowerBullishReject = - cBar.low <= insideBox.lower && - cBar.GetDown() > insideBox.lower; - - // - // Apply Force Bar Type ... - if (forceBarType) - { - // - isUpperBearishReject = - isUpperBearishReject && - cBar.IsBearish(); - - // - isUpperBullishReject = - isUpperBullishReject && - cBar.IsBullish(); - - // - isLowerBearishReject = - isLowerBearishReject && - cBar.IsBearish(); - - // - isLowerBullishReject = - isLowerBullishReject && - cBar.IsBullish(); - } - - // - // Apply Force Fibo Pressure ... - if (forceBarType) - { - // - isUpperBearishReject = - isUpperBearishReject && - ttfHelper - .mBarAnalyser - .HasFiboPressure( - cBar, - X_DIRECTION_BEARISH, - X_FIBO_LEVEL_382 // - ); - - // - isUpperBullishReject = - isUpperBullishReject && - ttfHelper - .mBarAnalyser - .HasFiboPressure( - cBar, - X_DIRECTION_BULLISH, - X_FIBO_LEVEL_382 // - ); - - // - isLowerBearishReject = - isLowerBearishReject && - ttfHelper - .mBarAnalyser - .HasFiboPressure( - cBar, - X_DIRECTION_BEARISH, - X_FIBO_LEVEL_382 // - ); - - // - isLowerBullishReject = - isLowerBullishReject && - ttfHelper - .mBarAnalyser - .HasFiboPressure( - cBar, - X_DIRECTION_BULLISH, - X_FIBO_LEVEL_382 // - ); - } - - // - // Bullish Conditions ... - isBullish = ( - // - hasBullishTrend && - isInsideBoxBearish && - isLowerBullishReject - // - ); - - // - // Bearish Conditions ... - isBearish = ( - // - hasBearishTrend && - isInsideBoxBullish && - isUpperBearishReject - // - ); - - // - // Filling Requirements ... - result = - isBullish || - isBearish; - if (result) - { - // - box = insideBox; - - // - dir = - isBullish - ? X_DIRECTION_BULLISH - : X_DIRECTION_BEARISH; - } - - // - // Check All Conditions ... - result = - box.IsValid() && - HasDirection(dir) && - (isBullish || - isBearish // + XCBoxObject *iObj; + has = drawer.DrawBox( + insideBox, + iObj // ); - - // - // Cleanup Resource ... - - // - zBar.Clean(); - cBar.Clean(); - pBar.Clean(); - - // - ttfState.Clean(); - insideBox.Clean(); - ZeroMemory(ttfHelper); - ttfConditions.Clean(); - ttfXConditions.Clean(); - - // - return result; - } - - // - bool HasSenario4Conditions( - ENUM_X_CYCLES cycle, - XBoxZone &box, - XBoxZone &holderBox, - ENUM_X_DIRECTION &dir, - X121SMCStrategySignalProviderData &provider, - ENUM_X_CYCLES holderCycle = X_CYCLE_NONE, - int barIndex = 0 // - ) - { - // - bool result = false; - - // - // Fil Selected Data ... - XPOIState cState; - X121Conditions cXConditions; - XC121SMCCycleHelper *cHelper; - X121SMCCycleConditions cConditions; - result = provider.SelectCycle( - cycle, - cState, - cXConditions, - cHelper, - cConditions // - ); - if (!result) - { - // - cState.Clean(); - ZeroMemory(cHelper); - cConditions.Clean(); - cXConditions.Clean(); - - // - return result; - } - Parse(cXConditions); - - // - // Fil Selected Data ... - XPOIState chState; - X121Conditions chXConditions; - XC121SMCCycleHelper *chHelper; - X121SMCCycleConditions chConditions; - if (holderCycle != X_CYCLE_NONE) - { - // - result = provider.SelectCycle( - holderCycle, - chState, - chXConditions, - chHelper, - chConditions // - ); - if (!result) + if (has) { // - chState.Clean(); - ZeroMemory(chHelper); - chConditions.Clean(); - chXConditions.Clean(); - - // - return result; + Print("Dec Scores:"); + Print("-------------"); + Print("Bull: ", provider.decisionBullishScore); + Print("Bear: ", provider.decisionBearishScore); + Print("-------------"); + Print("Anal Scores:"); + Print("-------------"); + Print("Bull: ", provider.analyseBullishScore); + Print("Bear: ", provider.analyseBearishScore); + Print("-------------"); + Print("Bar Valid For: " + ToString(iBarPosDir)); + Print("-------------"); + Print(ToString(insideBox.dir), " Inside ..."); + Print("-------------"); } - - // - Parse(chXConditions); } // - // 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; - - // - 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); + result = has; if (!result) { // @@ -3552,6 +2872,7 @@ struct X121SMCStrategyConditionParser pBar.Clean(); cState.Clean(); chState.Clean(); + insideBox.Clean(); ZeroMemory(cHelper); cConditions.Clean(); cXConditions.Clean(); @@ -3571,7 +2892,12 @@ struct X121SMCStrategyConditionParser isBullish = // // Base Condition ... - false + ( + // + insideBox.IsBullish() && + isBarValidForBullish + // + ) // ; @@ -3580,7 +2906,12 @@ struct X121SMCStrategyConditionParser isBearish = // // Base Condition ... - false + ( + // + insideBox.IsBearish() && + isBarValidForBearish + // + ) // ; @@ -3600,281 +2931,11 @@ struct X121SMCStrategyConditionParser // box.dir = dir; box.to = TimeCurrent(); + box.from = insideBox.from; + box.upper = insideBox.upper; + box.lower = insideBox.lower; box.symbol = cXConditions.symbol; box.period = cXConditions.period; - - // - int fromIDX = -1; - if (isBullish) - { - // - double vale = cXConditions.valesBuffer[cIDX]; - box.lower = vale; - box.upper = cXConditions.valesGoldenBuffer[cIDX]; - - // - int lowerValeIDX = -1; - double lowerVale = cHelper - .mX121Helper - .xpvHelper - .GetLowerVale( - lowerValeIDX, - vale, - cBar.Index() // - ); - - // - int higherValeIDX = -1; - double higherVale = cHelper - .mX121Helper - .xpvHelper - .GetHigherVale( - higherValeIDX, - vale, - cBar.Index() // - ); - - // - if (IsValidIndex(lowerValeIDX) && - IsValidIndex(higherValeIDX)) - { - // - fromIDX = - lowerValeIDX < higherValeIDX - ? lowerValeIDX - : higherValeIDX; - } - else if (IsValidIndex(lowerValeIDX) && - !IsValidIndex(higherValeIDX)) - { - // - fromIDX = lowerValeIDX; - } - else if (!IsValidIndex(lowerValeIDX) && - IsValidIndex(higherValeIDX)) - { - // - fromIDX = higherValeIDX; - } - } - else - { - // - double peak = cXConditions.peaksBuffer[cIDX]; - box.upper = peak; - - // - box.lower = cXConditions.peaksGoldenBuffer[cIDX]; - - // - int lowerPeakIDX = -1; - double lowerPeak = cHelper - .mX121Helper - .xpvHelper - .GetLowerPeak( - lowerPeakIDX, - peak, - cBar.Index() // - ); - - // - int higherPeakIDX = -1; - double higherPeak = cHelper - .mX121Helper - .xpvHelper - .GetHigherPeak( - higherPeakIDX, - peak, - cBar.Index() // - ); - - // - if (IsValidIndex(lowerPeakIDX) && - IsValidIndex(higherPeakIDX)) - { - // - fromIDX = - lowerPeakIDX < higherPeakIDX - ? lowerPeakIDX - : higherPeakIDX; - } - else if (IsValidIndex(lowerPeakIDX) && - !IsValidIndex(higherPeakIDX)) - { - // - fromIDX = lowerPeakIDX; - } - else if (!IsValidIndex(lowerPeakIDX) && - IsValidIndex(higherPeakIDX)) - { - // - fromIDX = higherPeakIDX; - } - } - - // - if (IsValidIndex(fromIDX)) - { - // - box.from = iTime( - zBar.symbol, - zBar.period, - fromIDX // - ); - } - else - { - box.from = pBar.time; - } - - // - // Detect Holder Box ... - XBoxZone tmpBoxes[]; - if (chState.IsValid()) - { - // - if (isBullish) - { - // - // Demand Zones ... - XBoxZone tmp[]; - ToBox( - chState.demandZones, - tmp // - ); - Copy( - tmp, - tmpBoxes, - false // - ); - Clean(tmp); - - // - // Bullish Order Blocks ... - ToBox( - chState.bullishOrderBlocks, - tmp // - ); - Copy( - tmp, - tmpBoxes, - false // - ); - Clean(tmp); - - // - // Bullish Fair Value Gaps ... - ToBox( - chState.bullishFairValueGaps, - tmp // - ); - Copy( - tmp, - tmpBoxes, - false // - ); - Clean(tmp); - } - else - { - // - // Supply Zones ... - XBoxZone tmp[]; - ToBox( - chState.supplyZones, - tmp // - ); - Copy( - tmp, - tmpBoxes, - false // - ); - Clean(tmp); - - // - // Bearish Order Blocks ... - ToBox( - chState.bearishOrderBlocks, - tmp // - ); - Copy( - tmp, - tmpBoxes, - false // - ); - Clean(tmp); - - // - // Bearish Fair Value Gaps ... - ToBox( - chState.bearishFairValueGaps, - tmp // - ); - Copy( - tmp, - tmpBoxes, - false // - ); - Clean(tmp); - } - } - - // - has = HasChild(tmpBoxes); - if (has) - { - // - while (HasChild(tmpBoxes)) - { - // - idx = GetOldest(tmpBoxes); - has = IsValidIndex(idx); - if (!has) - { - break; - } - - // - XBoxZone iBox = tmpBoxes[idx]; - ArrayRemove( - tmpBoxes, - idx, - 1 // - ); - - // - has = IsBoxInside( - box, - iBox // - ); - if (has) - { - // - holderBox = iBox; - holderBox.to = TimeCurrent(); - iBox.Clean(); - break; - } - - // - iBox.Clean(); - } - } - - // - Clean(tmpBoxes); - - // - // Validate Conditions to Force Has Holder Box ... - result = - result && - holderBox.IsValid(); - if (!result) - { - // - isBullish = false; - isBearish = false; - } } // @@ -3892,11 +2953,14 @@ struct X121SMCStrategyConditionParser pBar.Clean(); cState.Clean(); chState.Clean(); + insideBox.Clean(); ZeroMemory(cHelper); cConditions.Clean(); + cStateEvents.Clean(); cXConditions.Clean(); ZeroMemory(chHelper); chConditions.Clean(); + chStateEvents.Clean(); chXConditions.Clean(); // diff --git a/X121SMCEA/Signals/x-121.smc.xwz.signal.class.mq5 b/X121SMCEA/Signals/x-121.smc.xwz.signal.class.mq5 index 512971c4..cbd937b8 100644 --- a/X121SMCEA/Signals/x-121.smc.xwz.signal.class.mq5 +++ b/X121SMCEA/Signals/x-121.smc.xwz.signal.class.mq5 @@ -224,7 +224,7 @@ class XCX121SMCXWZSignalDetector : public XCBase // Detectiong Signal Boxes ... hasWaitingBoxes = workingZone .DetectSignalBoxes( - X_CYCLE_ANALYSE, + X_CYCLE_DECISION, provider, zIndex // ); @@ -464,58 +464,59 @@ class XCX121SMCXWZSignalDetector : public XCBase // // Select and Provide SL Based on ... double iAtr = 0; - if (signalProvider == X121SMC_XWZ_PROVIDER_ACTIVATED_MA) + if (signalProvider == X121SMC_XWZ_PROVIDER_XHKMA) { // iAtr = provider.decisionXConditions.atrBuffer[1]; - iAtr *= 1.5; + iAtr *= 0; } - else if (signalProvider == X121SMC_XWZ_PROVIDER_ACTIVATED_BOX) - { - // - iAtr = provider.decisionXConditions.atrBuffer[1]; - iAtr *= 1.5; + // else + // if (signalProvider == X121SMC_XWZ_PROVIDER_ACTIVATED_BOX) + // { + // // + // iAtr = provider.decisionXConditions.atrBuffer[1]; + // iAtr *= 1.5; - // // - // if (isBullish) - // { - // // - // iSL = MathMin( - // provider.decisionXConditions.le1Buffer[1], - // provider.decisionXConditions.le2Buffer[1] // - // ); - // if (iSL > 0) - // { - // // - // Add( - // iSL, - // sls // - // ); - // } - // } - // else - // { - // // - // iSL = MathMax( - // provider.decisionXConditions.se1Buffer[1], - // provider.decisionXConditions.se2Buffer[1] // - // ); - // if (iSL > 0) - // { - // // - // Add( - // iSL, - // sls // - // ); - // } - // } - } - else if (signalProvider == X121SMC_XWZ_PROVIDER_ACTIVATED_AREA) - { - // - iAtr = provider.decisionXConditions.atrBuffer[1]; - iAtr *= 1.5; - } + // // // + // // if (isBullish) + // // { + // // // + // // iSL = MathMin( + // // provider.decisionXConditions.le1Buffer[1], + // // provider.decisionXConditions.le2Buffer[1] // + // // ); + // // if (iSL > 0) + // // { + // // // + // // Add( + // // iSL, + // // sls // + // // ); + // // } + // // } + // // else + // // { + // // // + // // iSL = MathMax( + // // provider.decisionXConditions.se1Buffer[1], + // // provider.decisionXConditions.se2Buffer[1] // + // // ); + // // if (iSL > 0) + // // { + // // // + // // Add( + // // iSL, + // // sls // + // // ); + // // } + // // } + // } + // else if (signalProvider == X121SMC_XWZ_PROVIDER_ACTIVATED_AREA) + // { + // // + // iAtr = provider.decisionXConditions.atrBuffer[1]; + // iAtr *= 1.5; + // } // // Select Condition SL ... diff --git a/X121SMCEA/Signals/x-121.smc.xwz.signal.lib.mq5 b/X121SMCEA/Signals/x-121.smc.xwz.signal.lib.mq5 index ee8e93dd..48239d5f 100644 --- a/X121SMCEA/Signals/x-121.smc.xwz.signal.lib.mq5 +++ b/X121SMCEA/Signals/x-121.smc.xwz.signal.lib.mq5 @@ -31,10 +31,7 @@ enum ENUM_X121SMC_XWZ_PROVIDERS { X121SMC_XWZ_PROVIDER_NONE, - X121SMC_XWZ_PROVIDER_PVHK, - X121SMC_XWZ_PROVIDER_ACTIVATED_MA, - X121SMC_XWZ_PROVIDER_ACTIVATED_BOX, - X121SMC_XWZ_PROVIDER_ACTIVATED_AREA, + X121SMC_XWZ_PROVIDER_XHKMA, }; // @@ -478,6 +475,11 @@ struct X121SMCStrategyXWZWorkingZone // bool result = false; + // + int idx = -1; + int count = 0; + bool has = false; + // if (barIndex < 0) { @@ -487,12 +489,14 @@ struct X121SMCStrategyXWZWorkingZone // // Select Cycle ... XPOIState cState; + XPOIStateEvents cStateEvents; X121Conditions cXConditions; XC121SMCCycleHelper *cHelper; X121SMCCycleConditions cConditions; result = provider.SelectCycle( cycle, cState, + cStateEvents, cXConditions, cHelper, cConditions // @@ -503,6 +507,7 @@ struct X121SMCStrategyXWZWorkingZone cState.Clean(); ZeroMemory(cHelper); cConditions.Clean(); + cStateEvents.Clean(); cXConditions.Clean(); // @@ -510,30 +515,231 @@ struct X121SMCStrategyXWZWorkingZone } // - // Select Validate Rejection Boxes ... - XBoxZone rejections[]; - int count = cHelper - .DetectRejections( - rejections, - barIndex // - ); + // Select Rejection Boxes ... + + // // + // // Select Validate Rejection Boxes ... + // XBoxZone rejections[]; + // int count = cHelper + // .DetectRejections( + // rejections, + // barIndex // + // ); + + // // + // result = IsValidSize(count); + // if (result) + // { + // // + // for (int i = 0; i < count; i++) + // { + // // + // has = IsExists(rejections[i]); + // if (!has) + // { + // // + // AddRef( + // rejections[i], + // waitingBoxes // + // ); + // } + // } + // } // - result = IsValidSize(count); - if (result) + // Select Order Blocks ... + // if (cStateEvents.hasNewOrderBlock) + // { + // // + // idx = GetYoungest(cState.orderBlocks); + // has = IsValidIndex(idx); + // if (has) + // { + // // + // XCOrderBlock *iOB = cState.orderBlocks[idx]; + + // // + // XBoxZone iBox; + // has = ToBox( + // iBox, + // iOB // + // ); + // if (has) + // { + // // + // has = IsExists(iBox); + // if (!has) + // { + // // + // AddRef( + // iBox, + // waitingBoxes // + // ); + // } + // } + // } + // } + + // + // Select Fair Value Gaps ... + // if (cStateEvents.hasNewFairValueGap) + // { + // // + // idx = GetYoungest(cState.fairValueGaps); + // has = IsValidIndex(idx); + // if (has) + // { + // // + // XCFVG *iOB = cState.fairValueGaps[idx]; + + // // + // XBoxZone iBox; + // has = ToBox( + // iBox, + // iOB // + // ); + // if (has) + // { + // // + // has = IsExists(iBox); + // if (!has) + // { + // // + // AddRef( + // iBox, + // waitingBoxes // + // ); + // } + // } + // } + // } + + // + // Select Supply/Demand Zones ... + // if (cStateEvents.hasNewSupplyZone) + // { + // // + // idx = GetYoungest(cState.supplyZones); + // has = IsValidIndex(idx); + // if (has) + // { + // // + // XCSupplyZone *iSupply = cState.supplyZones[idx]; + + // // + // XBoxZone iBox; + // has = ToBox( + // iBox, + // iSupply // + // ); + // if (has) + // { + // // + // has = IsExists(iBox); + // if (!has) + // { + // // + // AddRef( + // iBox, + // waitingBoxes // + // ); + // } + // } + // } + // } + // if (cStateEvents.hasNewDemandZone) + // { + // // + // idx = GetYoungest(cState.demandZones); + // has = IsValidIndex(idx); + // if (has) + // { + // // + // XCDemandZone *iDemand = cState.demandZones[idx]; + + // // + // XBoxZone iBox; + // has = ToBox( + // iBox, + // iDemand // + // ); + // if (has) + // { + // // + // has = IsExists(iBox); + // if (!has) + // { + // // + // AddRef( + // iBox, + // waitingBoxes // + // ); + // } + // } + // } + // } + + // + // Select Support/Resistance Zones ... + if (cStateEvents.hasNewSupportZone) { // - for (int i = 0; i < count; i++) + idx = GetYoungest(cState.supportZones); + has = IsValidIndex(idx); + if (has) { // - bool has = IsExists(rejections[i]); - if (!has) + XCSupportZone *iSupport = cState.supportZones[idx]; + + // + XBoxZone iBox; + has = ToBox( + iBox, + iSupport // + ); + if (has) { // - AddRef( - rejections[i], - waitingBoxes // - ); + has = IsExists(iBox); + if (!has) + { + // + AddRef( + iBox, + waitingBoxes // + ); + } + } + } + } + if (cStateEvents.hasNewResistanceZone) + { + // + idx = GetYoungest(cState.resistanceZones); + has = IsValidIndex(idx); + if (has) + { + // + XCResistanceZone *iResistance = cState.resistanceZones[idx]; + + // + XBoxZone iBox; + has = ToBox( + iBox, + iResistance // + ); + if (has) + { + // + has = IsExists(iBox); + if (!has) + { + // + AddRef( + iBox, + waitingBoxes // + ); + } } } } @@ -550,6 +756,7 @@ struct X121SMCStrategyXWZWorkingZone ZeroMemory(cHelper); cConditions.Clean(); cXConditions.Clean(); + cStateEvents.Clean(); // return result; @@ -765,6 +972,13 @@ struct X121SMCStrategyXWZWorkingZone return result; } + /** + * Detect Trend Based On Boxes ... + * + * @param dir: ENUM_X_DIRECTION ember ... + * + * @return ( bool ) + */ bool DetectTreand( ENUM_X_DIRECTION &dir // ) @@ -1014,6 +1228,7 @@ struct X121SMCStrategyXWZWorkingZone box, holderBox, dir, + waitingBoxes, provider, X_CYCLE_ANALYSE, barIndex // @@ -1032,7 +1247,7 @@ struct X121SMCStrategyXWZWorkingZone // if (isSenario1Happend) { - signalProvider = X121SMC_XWZ_PROVIDER_PVHK; + signalProvider = X121SMC_XWZ_PROVIDER_XHKMA; } } @@ -1045,50 +1260,50 @@ struct X121SMCStrategyXWZWorkingZone bool isSenario2Happend = false; bool isSenario2Bullish = false; bool isSenario2Bearish = false; - if (useSenario2) - { - // - // Senario 2 Working Based on - // Breaked Boxes ... - // Since we Works only - // when Has UnAvailable Boxes ... - has = HasBreakedBoxes(); - if (has) - { - // - ENUM_X_DIRECTION overalTrend; - bool hasTrend = DetectOveralDirection(overalTrend); + // if (useSenario2) + // { + // // + // // Senario 2 Working Based on + // // Breaked Boxes ... + // // Since we Works only + // // when Has UnAvailable Boxes ... + // has = HasBreakedBoxes(); + // if (has) + // { + // // + // ENUM_X_DIRECTION overalTrend; + // bool hasTrend = DetectOveralDirection(overalTrend); - if (hasTrend) - { - // - isSenario2Happend = cParser.HasSenario2Conditions( - X_CYCLE_DECISION, - breakedBoxes, - box, - dir, - provider, - barIndex // - ); + // if (hasTrend) + // { + // // + // isSenario2Happend = cParser.HasSenario2Conditions( + // X_CYCLE_DECISION, + // breakedBoxes, + // box, + // dir, + // provider, + // barIndex // + // ); - // - isSenario2Bullish = - isSenario2Happend && - IsBullish(dir); + // // + // isSenario2Bullish = + // isSenario2Happend && + // IsBullish(dir); - // - isSenario2Bearish = - isSenario2Happend && - IsBearish(dir); + // // + // isSenario2Bearish = + // isSenario2Happend && + // IsBearish(dir); - // - if (isSenario2Happend) - { - signalProvider = X121SMC_XWZ_PROVIDER_ACTIVATED_BOX; - } - } - } - } + // // + // if (isSenario2Happend) + // { + // signalProvider = X121SMC_XWZ_PROVIDER_ACTIVATED_BOX; + // } + // } + // } + // } // // Senario 3: @@ -1098,9 +1313,9 @@ struct X121SMCStrategyXWZWorkingZone bool isSenario3Happend = false; bool isSenario3Bullish = false; bool isSenario3Bearish = false; - if (useSenario3) - { - } + // if (useSenario3) + // { + // } // // Senario 4: @@ -1111,35 +1326,35 @@ struct X121SMCStrategyXWZWorkingZone bool isSenario4Happend = false; bool isSenario4Bullish = false; bool isSenario4Bearish = false; - if (useSenario4) - { - // - isSenario4Happend = cParser.HasSenario4Conditions( - X_CYCLE_ANALYSE, - box, - holderBox, - dir, - provider, - X_CYCLE_CONSOLIDATION, - barIndex // - ); + // if (useSenario4) + // { + // // + // isSenario4Happend = cParser.HasSenario4Conditions( + // X_CYCLE_ANALYSE, + // box, + // holderBox, + // dir, + // provider, + // X_CYCLE_CONSOLIDATION, + // barIndex // + // ); - // - isSenario4Bullish = - isSenario4Happend && - IsBullish(dir); + // // + // isSenario4Bullish = + // isSenario4Happend && + // IsBullish(dir); - // - isSenario4Bearish = - isSenario4Happend && - IsBearish(dir); + // // + // isSenario4Bearish = + // isSenario4Happend && + // IsBearish(dir); - // - if (isSenario4Happend) - { - signalProvider = X121SMC_XWZ_PROVIDER_ACTIVATED_BOX; - } - } + // // + // if (isSenario4Happend) + // { + // signalProvider = X121SMC_XWZ_PROVIDER_ACTIVATED_BOX; + // } + // } // // Senario 5: @@ -1149,9 +1364,9 @@ struct X121SMCStrategyXWZWorkingZone bool isSenario5Happend = false; bool isSenario5Bullish = false; bool isSenario5Bearish = false; - if (useSenario5) - { - } + // if (useSenario5) + // { + // } // // Summarize All Senario(s) Conditions ... diff --git a/X121SMCEA/Strategy/x-121.smc.strategy.class.mq5 b/X121SMCEA/Strategy/x-121.smc.strategy.class.mq5 index 1a556429..b2b9bdeb 100644 --- a/X121SMCEA/Strategy/x-121.smc.strategy.class.mq5 +++ b/X121SMCEA/Strategy/x-121.smc.strategy.class.mq5 @@ -786,27 +786,27 @@ class XCX121SMCStrategy : public XCX121SMCBaseStrategy // // XPV ... - x121Inputs.xpvInputs.showSar = showAll || true; - x121Inputs.xpvInputs.showPeaks = showAll || true; - x121Inputs.xpvInputs.showVales = showAll || true; - x121Inputs.xpvInputs.showSupports = showAll || true; - x121Inputs.xpvInputs.showResistances = showAll || true; - x121Inputs.xpvInputs.showGoldenZones = showAll || true; + x121Inputs.xpvInputs.showSar = showAll || false; + x121Inputs.xpvInputs.showPeaks = showAll || false; + x121Inputs.xpvInputs.showVales = showAll || false; + x121Inputs.xpvInputs.showSupports = showAll || false; + x121Inputs.xpvInputs.showResistances = showAll || false; + x121Inputs.xpvInputs.showGoldenZones = showAll || false; // // XHK ... // x121Inputs.xhkInputs.drawRawXHKCandles = showAll || false; - x121Inputs.xhkInputs.drawSmoothedXHKCandles = showAll || true; + x121Inputs.xhkInputs.drawSmoothedXHKCandles = showAll || false; // // XMAS ... // - x121Inputs.xmasInputs.showUpper = showAll || true; - x121Inputs.xmasInputs.showMid = showAll || true; - x121Inputs.xmasInputs.showLower = showAll || true; + x121Inputs.xmasInputs.showUpper = showAll || false; + x121Inputs.xmasInputs.showMid = showAll || false; + x121Inputs.xmasInputs.showLower = showAll || false; // // XATR ... @@ -841,9 +841,9 @@ class XCX121SMCStrategy : public XCX121SMCBaseStrategy // // X3MA ... - x121Inputs.x3maInputs.showX3MaFast = showAll || false; - x121Inputs.x3maInputs.showX3MaMid = showAll || false; - x121Inputs.x3maInputs.showX3MaSlow = showAll || false; + x121Inputs.x3maInputs.showX3MaFast = showAll || true; + x121Inputs.x3maInputs.showX3MaMid = showAll || true; + x121Inputs.x3maInputs.showX3MaSlow = showAll || true; // // Initialize Cycle Helpers ...