diff --git a/Documents/BKP/workingZone.zone.box.mq5 b/Documents/BKP/workingZone.zone.box.mq5 index 3fe43a34..dd43d93a 100644 --- a/Documents/BKP/workingZone.zone.box.mq5 +++ b/Documents/BKP/workingZone.zone.box.mq5 @@ -1164,6 +1164,103 @@ hasWaitingBoxes = workingZone.HasWaitingBoxes(); //////////////////////////////////////////////////////////////////////// +// +// Senario 1: +// ---------- +bool useSenario1 = true; +bool isSenario1Happend = false; +bool isSenario1Bullish = false; +bool isSenario1Bearish = false; +if (useSenario1) +{ + // + // Senario 1 Bullish Conditions ... + isSenario1Bullish = + // + // X3Ma / XVwap Switched To Bulish ... + ( + // + // X3Ma Switched To Bulish ... + ( + // + (provider.decisionXConditions.isX3MaFastCrossedOverMid && + decisionParser.isX3MaBullishStateUnderValesGoldenZone) + // + ) + // + || + // + // XVWap Switched To Bulish ... + ( + // + (provider.decisionXConditions.isVWapFastCrossedOverMid && + decisionParser.isVWapBullishStateUnderValesGoldenZone) + // + ) + // + ) + // + && + // + // Checking other Conditions ... + ( + // + // XSTR ... + provider.decisionXConditions.isStrBullish && + // + // XCHE ... + provider.decisionXConditions.isCheBullish && + provider.decisionXConditions.le1Buffer[cIDX] < cBar.low && + provider.decisionXConditions.le2Buffer[cIDX] < cBar.low + // + ) + // + ; + + // + // Senario 1 Bearish Conditions ... + isSenario1Bearish = + // + // X3Ma / XVwap Switched To Bearish ... + ( + // + // X3Ma Switched To Bearish ... + ( + // + (provider.decisionXConditions.isX3MaFastCrossedUnderMid && + decisionParser.isX3MaBearishStateOverPeaksGoldenZone) + // + ) + // + || + // + // XVWap Switched To Bearish ... + ( + // + (provider.decisionXConditions.isVWapFastCrossedUnderMid && + decisionParser.isVWapBearishStateOverPeaksGoldenZone) + // + ) + // + ) + // + && + // + // Checking other Conditions ... + ( + // + // XSTR ... + provider.decisionXConditions.isStrBearish && + // + // XCHE ... + provider.decisionXConditions.isCheBearish && + provider.decisionXConditions.se1Buffer[cIDX] > cBar.high && + provider.decisionXConditions.se2Buffer[cIDX] > cBar.high + // + ) + // + ; + //////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////// 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 4b56b9cd..6f9cfc4b 100644 --- a/X121SMCEA/Classes/x-121.smc.market.cycle.helper.class.mq5 +++ b/X121SMCEA/Classes/x-121.smc.market.cycle.helper.class.mq5 @@ -684,6 +684,473 @@ class XC121SMCCycleHelper : public XCBase // }; +// +struct X121SMCStrategySignalProviderData +{ + // + // Props ... + + // + // Decision ... + XPOIState decisionState; + double decisionBullishScore; + double decisionBearishScore; + X121Conditions decisionXConditions; + ENUM_XPOI_EVENTS decisionPoiEvents[]; + XC121SMCCycleHelper *decisionCycleHelper; + ENUM_X_CYCLE_EVENTS decisionCycleEvents[]; + X121SMCCycleConditions decisionConditions; + + // + // Analyse ... + XPOIState analyseState; + double analyseBullishScore; + double analyseBearishScore; + X121Conditions analyseXConditions; + ENUM_XPOI_EVENTS analysePoiEvents[]; + XC121SMCCycleHelper *analyseCycleHelper; + ENUM_X_CYCLE_EVENTS analyseCycleEvents[]; + X121SMCCycleConditions analyseConditions; + + // + // Consolidation ... + XPOIState consolidationState; + double consolidationBullishScore; + double consolidationBearishScore; + X121Conditions consolidationXConditions; + ENUM_XPOI_EVENTS consolidationPoiEvents[]; + XC121SMCCycleHelper *consolidationCycleHelper; + ENUM_X_CYCLE_EVENTS consolidationCycleEvents[]; + X121SMCCycleConditions consolidationConditions; + + // + // Vision ... + XPOIState visionState; + double visionBullishScore; + double visionBearishScore; + X121Conditions visionXConditions; + ENUM_XPOI_EVENTS visionPoiEvents[]; + XC121SMCCycleHelper *visionCycleHelper; + ENUM_X_CYCLE_EVENTS visionCycleEvents[]; + X121SMCCycleConditions visionConditions; + + // + // Constructor ... + X121SMCStrategySignalProviderData() + { + Clean(); + } + + // + // Tools ... + + // + // Cleanup ... + void Clean() + { + // + // Decision ... + decisionState.Clean(); + decisionBullishScore = 0; + decisionBearishScore = 0; + Clean(decisionPoiEvents); + Clean(decisionCycleEvents); + decisionConditions.Clean(); + decisionXConditions.Clean(); + + // + // Analyse ... + analyseState.Clean(); + analyseBullishScore = 0; + analyseBearishScore = 0; + Clean(analysePoiEvents); + Clean(analyseCycleEvents); + analyseConditions.Clean(); + analyseXConditions.Clean(); + + // + // Consolidation ... + consolidationState.Clean(); + consolidationBullishScore = 0; + consolidationBearishScore = 0; + Clean(consolidationPoiEvents); + Clean(consolidationCycleEvents); + consolidationConditions.Clean(); + consolidationXConditions.Clean(); + + // + // Vision ... + visionState.Clean(); + visionBullishScore = 0; + visionBearishScore = 0; + Clean(visionPoiEvents); + Clean(visionCycleEvents); + visionConditions.Clean(); + visionXConditions.Clean(); + } + + // + void Destroy() + { + // + Clean(); + + // + ZeroMemory(decisionCycleHelper); + ZeroMemory(analyseCycleHelper); + ZeroMemory(consolidationCycleHelper); + ZeroMemory(visionCycleHelper); + + // + ZeroMemory(this); + } + + // + bool IsValid() + { + // + bool result = false; + + // + result = + visionCycleHelper != NULL && + analyseCycleHelper != NULL && + decisionCycleHelper != NULL && + consolidationCycleHelper != NULL; + + // + return result; + } + + // + // Initialize ... + bool Init( + XC121SMCCycleHelper *_decisionCycleHelper, + XC121SMCCycleHelper *_analyseCycleHelper, + XC121SMCCycleHelper *_consolidationCycleHelper, + XC121SMCCycleHelper *_visionCycleHelper // + ) + { + // + bool result = false; + + // + // Validate Cycle Helpers ... + result = + // + _visionCycleHelper != NULL && + _analyseCycleHelper != NULL && + _decisionCycleHelper != NULL && + _consolidationCycleHelper != NULL + // + ; + if (!result) + { + return result; + } + + // + visionCycleHelper = _visionCycleHelper; + analyseCycleHelper = _analyseCycleHelper; + decisionCycleHelper = _decisionCycleHelper; + consolidationCycleHelper = _consolidationCycleHelper; + + // + result = IsValid(); + + // + return result; + } + + // + // Prepare all ... + bool Prepare( + int barIndex = 0, + int loopback = 10 // + ) + { + // + bool result = false; + + // + if (barIndex < 0) + { + barIndex = 0; + } + + // + if (loopback < 7) + { + loopback = 7; + } + + // + result = IsValid(); + if (!result) + { + return result; + } + + // + // Decision ... + result = decisionCycleHelper.GetConditions( + decisionCycleEvents, + decisionPoiEvents, + decisionConditions, + barIndex, + loopback // + ); + if (!result) + { + // + Clean(decisionPoiEvents); + Clean(decisionCycleEvents); + + // + decisionConditions.Clean(); + + // + return result; + } + + // + // Analyse ... + result = analyseCycleHelper.GetConditions( + analyseCycleEvents, + analysePoiEvents, + analyseConditions, + barIndex, + loopback // + ); + if (!result) + { + // + Clean(analysePoiEvents); + Clean(decisionPoiEvents); + + // + Clean(analyseCycleEvents); + Clean(decisionCycleEvents); + + // + analyseConditions.Clean(); + decisionConditions.Clean(); + + // + return result; + } + + // + // Consolidation ... + result = consolidationCycleHelper.GetConditions( + consolidationCycleEvents, + consolidationPoiEvents, + consolidationConditions, + barIndex, + loopback // + ); + if (!result) + { + // + Clean(analysePoiEvents); + Clean(decisionPoiEvents); + Clean(consolidationPoiEvents); + + // + Clean(analyseCycleEvents); + Clean(decisionCycleEvents); + Clean(consolidationCycleEvents); + + // + analyseConditions.Clean(); + decisionConditions.Clean(); + consolidationConditions.Clean(); + + // + return result; + } + + // + // Vision ... + result = visionCycleHelper.GetConditions( + visionCycleEvents, + visionPoiEvents, + visionConditions, + barIndex, + loopback // + ); + if (!result) + { + // + Clean(visionPoiEvents); + Clean(analysePoiEvents); + Clean(decisionPoiEvents); + Clean(consolidationPoiEvents); + + // + Clean(visionCycleEvents); + Clean(analyseCycleEvents); + Clean(decisionCycleEvents); + Clean(consolidationCycleEvents); + + // + visionConditions.Clean(); + analyseConditions.Clean(); + decisionConditions.Clean(); + consolidationConditions.Clean(); + + // + return result; + } + + // + // Cycles POI States ... + decisionState = decisionConditions.state; + analyseState = analyseConditions.state; + consolidationState = consolidationConditions.state; + visionState = visionConditions.state; + + // + // Cycle X121Conditions ... + decisionXConditions = decisionConditions.x121Conditions; + analyseXConditions = analyseConditions.x121Conditions; + consolidationXConditions = consolidationConditions.x121Conditions; + visionXConditions = visionConditions.x121Conditions; + + // + // Decision ... + decisionXConditions.GenerateScore( + decisionBullishScore, + decisionBearishScore // + ); + + // + // Analyse ... + analyseXConditions.GenerateScore( + analyseBullishScore, + analyseBearishScore // + ); + + // + // Consolidation ... + consolidationXConditions.GenerateScore( + consolidationBullishScore, + consolidationBearishScore // + ); + + // + // Vision ... + visionXConditions.GenerateScore( + visionBullishScore, + visionBearishScore // + ); + + // + return result; + } + + // + bool SelectCycle( + ENUM_X_CYCLES cycle, + XPOIState &cState, + X121Conditions &cXConditions, + XC121SMCCycleHelper *&cHelper, + X121SMCCycleConditions &cConditions // + ) + { + // + bool result = false; + + // + cState.Clean(); + ZeroMemory(cHelper); + cConditions.Clean(); + cXConditions.Clean(); + + // + result = cycle != X_CYCLE_NONE; + if (!result) + { + return result; + } + + // + if (cycle == X_CYCLE_DECISION) + { + // + cState = decisionState; + cHelper = decisionCycleHelper; + cConditions = decisionConditions; + cXConditions = decisionXConditions; + } + else if (cycle == X_CYCLE_ANALYSE) + { + // + cState = analyseState; + cHelper = analyseCycleHelper; + cConditions = analyseConditions; + cXConditions = analyseXConditions; + } + else if (cycle == X_CYCLE_CONSOLIDATION) + { + // + cState = consolidationState; + cHelper = consolidationCycleHelper; + cConditions = consolidationConditions; + cXConditions = consolidationXConditions; + } + else if (cycle == X_CYCLE_VISION) + { + // + cState = visionState; + cHelper = visionCycleHelper; + cConditions = visionConditions; + cXConditions = visionXConditions; + } + + // + result = cState.IsValid() && + cHelper != NULL; + + // + return result; + } + + // + void MaxRequiredPOIs(int value) + { + // + if (!IsValid()) + { + return; + } + + // + visionCycleHelper.mPOIDetector.MaxRequiredPOIs(value); + analyseCycleHelper.mPOIDetector.MaxRequiredPOIs(value); + decisionCycleHelper.mPOIDetector.MaxRequiredPOIs(value); + consolidationCycleHelper.mPOIDetector.MaxRequiredPOIs(value); + } + + // + void MaxAllowedLoopbackForInit(int value) + { + // + if (!IsValid()) + { + return; + } + + // + visionCycleHelper.mPOIDetector.MaxAllowedLoopbackForInit(value); + analyseCycleHelper.mPOIDetector.MaxAllowedLoopbackForInit(value); + decisionCycleHelper.mPOIDetector.MaxAllowedLoopbackForInit(value); + consolidationCycleHelper.mPOIDetector.MaxAllowedLoopbackForInit(value); + } + + // +}; + // struct X121SMCStrategyConditionParser { @@ -1607,195 +2074,84 @@ struct X121SMCStrategyConditionParser } // -}; - -// -struct X121SMCStrategySignalProviderData -{ - // - // Props ... - - // - // Decision ... - XPOIState decisionState; - double decisionBullishScore; - double decisionBearishScore; - X121Conditions decisionXConditions; - ENUM_XPOI_EVENTS decisionPoiEvents[]; - XC121SMCCycleHelper *decisionCycleHelper; - ENUM_X_CYCLE_EVENTS decisionCycleEvents[]; - X121SMCCycleConditions decisionConditions; - - // - // Analyse ... - XPOIState analyseState; - double analyseBullishScore; - double analyseBearishScore; - X121Conditions analyseXConditions; - ENUM_XPOI_EVENTS analysePoiEvents[]; - XC121SMCCycleHelper *analyseCycleHelper; - ENUM_X_CYCLE_EVENTS analyseCycleEvents[]; - X121SMCCycleConditions analyseConditions; - - // - // Consolidation ... - XPOIState consolidationState; - double consolidationBullishScore; - double consolidationBearishScore; - X121Conditions consolidationXConditions; - ENUM_XPOI_EVENTS consolidationPoiEvents[]; - XC121SMCCycleHelper *consolidationCycleHelper; - ENUM_X_CYCLE_EVENTS consolidationCycleEvents[]; - X121SMCCycleConditions consolidationConditions; - - // - // Vision ... - XPOIState visionState; - double visionBullishScore; - double visionBearishScore; - X121Conditions visionXConditions; - ENUM_XPOI_EVENTS visionPoiEvents[]; - XC121SMCCycleHelper *visionCycleHelper; - ENUM_X_CYCLE_EVENTS visionCycleEvents[]; - X121SMCCycleConditions visionConditions; - - // - // Constructor ... - X121SMCStrategySignalProviderData() - { - Clean(); - } - - // - // Tools ... - - // - // Cleanup ... - void Clean() - { - // - // Decision ... - decisionState.Clean(); - decisionBullishScore = 0; - decisionBearishScore = 0; - Clean(decisionPoiEvents); - Clean(decisionCycleEvents); - decisionConditions.Clean(); - decisionXConditions.Clean(); - - // - // Analyse ... - analyseState.Clean(); - analyseBullishScore = 0; - analyseBearishScore = 0; - Clean(analysePoiEvents); - Clean(analyseCycleEvents); - analyseConditions.Clean(); - analyseXConditions.Clean(); - - // - // Consolidation ... - consolidationState.Clean(); - consolidationBullishScore = 0; - consolidationBearishScore = 0; - Clean(consolidationPoiEvents); - Clean(consolidationCycleEvents); - consolidationConditions.Clean(); - consolidationXConditions.Clean(); - - // - // Vision ... - visionState.Clean(); - visionBullishScore = 0; - visionBearishScore = 0; - Clean(visionPoiEvents); - Clean(visionCycleEvents); - visionConditions.Clean(); - visionXConditions.Clean(); - } - - // - void Destroy() - { - // - Clean(); - - // - ZeroMemory(decisionCycleHelper); - ZeroMemory(analyseCycleHelper); - ZeroMemory(consolidationCycleHelper); - ZeroMemory(visionCycleHelper); - - // - ZeroMemory(this); - } - - // - bool IsValid() - { - // - bool result = false; - - // - result = - visionCycleHelper != NULL && - analyseCycleHelper != NULL && - decisionCycleHelper != NULL && - consolidationCycleHelper != NULL; - - // - return result; - } - - // - // Initialize ... - bool Init( - XC121SMCCycleHelper *_decisionCycleHelper, - XC121SMCCycleHelper *_analyseCycleHelper, - XC121SMCCycleHelper *_consolidationCycleHelper, - XC121SMCCycleHelper *_visionCycleHelper // + 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; // - // Validate Cycle Helpers ... - result = - // - _visionCycleHelper != NULL && - _analyseCycleHelper != NULL && - _decisionCycleHelper != NULL && - _consolidationCycleHelper != NULL - // - ; + // 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); + } // - visionCycleHelper = _visionCycleHelper; - analyseCycleHelper = _analyseCycleHelper; - decisionCycleHelper = _decisionCycleHelper; - consolidationCycleHelper = _consolidationCycleHelper; + // Normalize Args ... // - result = IsValid(); - - // - return result; - } - - // - // Prepare all ... - bool Prepare( - int barIndex = 0, - int loopback = 10 // - ) - { - // - bool result = false; + box.Clean(); + holderBox.Clean(); + dir = X_DIRECTION_NONE; // if (barIndex < 0) @@ -1804,207 +2160,521 @@ struct X121SMCStrategySignalProviderData } // - if (loopback < 7) - { - loopback = 7; - } + int idx = -1; + int count = 0; + bool has = false; // - result = IsValid(); - if (!result) - { - return result; - } + int zIDX = barIndex; + int cIDX = zIDX + 1; + int pIDX = cIDX + 1; // - // Decision ... - result = decisionCycleHelper.GetConditions( - decisionCycleEvents, - decisionPoiEvents, - decisionConditions, - barIndex, - loopback // + 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) { // - Clean(decisionPoiEvents); - Clean(decisionCycleEvents); - - // - decisionConditions.Clean(); + zBar.Clean(); + cBar.Clean(); + pBar.Clean(); + cState.Clean(); + chState.Clean(); + ZeroMemory(cHelper); + cConditions.Clean(); + cXConditions.Clean(); + ZeroMemory(chHelper); + chConditions.Clean(); + chXConditions.Clean(); // return result; } // - // Analyse ... - result = analyseCycleHelper.GetConditions( - analyseCycleEvents, - analysePoiEvents, - analyseConditions, - barIndex, - loopback // - ); - if (!result) + // Detecting Signal Conditions ... + + // + // Bullish Conditions ... + isBullish = + // + // Base Condition ... + ( + // + cBar.IsBullish() && + zBar.open >= cBar.close && + ( + // + // Regular Reject ... + (pBar.low > cBar.low && + cBar.low < cXConditions.valesGoldenBuffer[cIDX] && + cBar.GetDown() > cXConditions.valesGoldenBuffer[cIDX]) + // + || + // + // Regular Exit ... + (pBar.low < cXConditions.valesGoldenBuffer[cIDX] && + (cBar.low > cXConditions.valesGoldenBuffer[cIDX] || + cBar.GetUp() > cXConditions.valesGoldenBuffer[cIDX])) + // + || + // + IsBarBreak( + cXConditions.valesGoldenBuffer[cIDX], + X_DIRECTION_BULLISH, + cBar // + ) + // + || + // + IsBarReject( + cXConditions.valesGoldenBuffer[cIDX], + X_DIRECTION_BULLISH, + cBar // + ) + // + ) + // + ) + // + && + // + // Checking other Conditions ... + ( + // + // XSAR ... + cXConditions.isSarBullish && + // + // XSTR ... + cXConditions.isStrSwitchedToBullish && + // + // // X3MA ... + // // XVWAP ... + // (cXConditions.isX3MaFastOverMid || + // cXConditions.isVWapFastOverMid) && + // + // XHK ... + cXConditions.isSMHKBullish && + cXConditions.isRawHKBullish && + // + // XCHE ... + cXConditions.isCheBullish && + cXConditions.le1Buffer[cIDX] < cBar.low && + cXConditions.le2Buffer[cIDX] < cBar.low + // + ) + // + ; + + // + // Bearish Conditions ... + isBearish = + // + // Base Condition ... + ( + // + cBar.IsBearish() && + zBar.open <= cBar.close && + ( + // + // Regular Reject ... + (pBar.high < cBar.high && + cBar.high > cXConditions.peaksGoldenBuffer[cIDX] && + cBar.GetUp() < cXConditions.peaksGoldenBuffer[cIDX]) + // + || + // + // Regular Exit ... + (pBar.high > cXConditions.peaksGoldenBuffer[cIDX] && + (cBar.high < cXConditions.peaksGoldenBuffer[cIDX] || + cBar.GetDown() < cXConditions.peaksGoldenBuffer[cIDX])) + // + || + // + IsBarBreak( + cXConditions.peaksGoldenBuffer[cIDX], + X_DIRECTION_BEARISH, + cBar // + ) + // + || + // + IsBarReject( + cXConditions.peaksGoldenBuffer[cIDX], + X_DIRECTION_BEARISH, + cBar // + ) + // + ) + // + ) + // + && + // + // Checking other Conditions ... + ( + // + // XSAR ... + cXConditions.isSarBearish && + // + // XSTR ... + cXConditions.isStrSwitchedToBearish && + // + // // X3MA ... + // // XVWAP ... + // (cXConditions.isX3MaFastUnderMid || + // cXConditions.isVWapFastUnderMid) && + // + // XHK ... + cXConditions.isSMHKBearish && + cXConditions.isRawHKBearish && + // + // XCHE ... + cXConditions.isCheBearish && + cXConditions.se1Buffer[cIDX] > cBar.high && + cXConditions.se2Buffer[cIDX] > cBar.high + // + ) + // + ; + + // + // Filling Requirements ... + result = + isBullish || + isBearish; + if (result) { // - Clean(analysePoiEvents); - Clean(decisionPoiEvents); + dir = + isBullish + ? X_DIRECTION_BULLISH + : X_DIRECTION_BEARISH; // - Clean(analyseCycleEvents); - Clean(decisionCycleEvents); + box.dir = dir; + box.to = TimeCurrent(); + box.symbol = cXConditions.symbol; + box.period = cXConditions.period; // - analyseConditions.Clean(); - decisionConditions.Clean(); + 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; + } + } // - return result; + 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; + } } // - // Consolidation ... - result = consolidationCycleHelper.GetConditions( - consolidationCycleEvents, - consolidationPoiEvents, - consolidationConditions, - barIndex, - loopback // - ); - if (!result) - { - // - Clean(analysePoiEvents); - Clean(decisionPoiEvents); - Clean(consolidationPoiEvents); - - // - Clean(analyseCycleEvents); - Clean(decisionCycleEvents); - Clean(consolidationCycleEvents); - - // - analyseConditions.Clean(); - decisionConditions.Clean(); - consolidationConditions.Clean(); - - // - return result; - } + // Check All Conditions ... + result = + box.IsValid() && + HasDirection(dir) && + (isBullish || + isBearish); // - // Vision ... - result = visionCycleHelper.GetConditions( - visionCycleEvents, - visionPoiEvents, - visionConditions, - barIndex, - loopback // - ); - if (!result) - { - // - Clean(visionPoiEvents); - Clean(analysePoiEvents); - Clean(decisionPoiEvents); - Clean(consolidationPoiEvents); - - // - Clean(visionCycleEvents); - Clean(analyseCycleEvents); - Clean(decisionCycleEvents); - Clean(consolidationCycleEvents); - - // - visionConditions.Clean(); - analyseConditions.Clean(); - decisionConditions.Clean(); - consolidationConditions.Clean(); - - // - return result; - } - - // - // Cycles POI States ... - decisionState = decisionConditions.state; - analyseState = analyseConditions.state; - consolidationState = consolidationConditions.state; - visionState = visionConditions.state; - - // - // Cycle X121Conditions ... - decisionXConditions = decisionConditions.x121Conditions; - analyseXConditions = analyseConditions.x121Conditions; - consolidationXConditions = consolidationConditions.x121Conditions; - visionXConditions = visionConditions.x121Conditions; - - // - // Decision ... - decisionXConditions.GenerateScore( - decisionBullishScore, - decisionBearishScore // - ); - - // - // Analyse ... - analyseXConditions.GenerateScore( - analyseBullishScore, - analyseBearishScore // - ); - - // - // Consolidation ... - consolidationXConditions.GenerateScore( - consolidationBullishScore, - consolidationBearishScore // - ); - - // - // Vision ... - visionXConditions.GenerateScore( - visionBullishScore, - visionBearishScore // - ); + // 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; } - // - void MaxRequiredPOIs(int value) - { - // - if (!IsValid()) - { - return; - } - - // - visionCycleHelper.mPOIDetector.MaxRequiredPOIs(value); - analyseCycleHelper.mPOIDetector.MaxRequiredPOIs(value); - decisionCycleHelper.mPOIDetector.MaxRequiredPOIs(value); - consolidationCycleHelper.mPOIDetector.MaxRequiredPOIs(value); - } - - // - void MaxAllowedLoopbackForInit(int value) - { - // - if (!IsValid()) - { - return; - } - - // - visionCycleHelper.mPOIDetector.MaxAllowedLoopbackForInit(value); - analyseCycleHelper.mPOIDetector.MaxAllowedLoopbackForInit(value); - decisionCycleHelper.mPOIDetector.MaxAllowedLoopbackForInit(value); - consolidationCycleHelper.mPOIDetector.MaxAllowedLoopbackForInit(value); - } - // }; diff --git a/X121SMCEA/Signals/x-121.smc.xwz.signal.class.mq5 b/X121SMCEA/Signals/x-121.smc.xwz.signal.class.mq5 index 78fde82c..a88e9a8e 100644 --- a/X121SMCEA/Signals/x-121.smc.xwz.signal.class.mq5 +++ b/X121SMCEA/Signals/x-121.smc.xwz.signal.class.mq5 @@ -34,6 +34,8 @@ class XCX121SMCXWZSignalDetector : public XCBase public: // // Props ... + bool useGuards; + bool useQuarterTargets; X121SMCStrategyXWZWorkingZone workingZone; X121SMCStrategyXWZSignalConditions mConditions; X121SMCStrategyXWZSignalConditions mConditionsCollection[]; @@ -443,39 +445,39 @@ class XCX121SMCXWZSignalDetector : public XCBase } else if (signalProvider == X121SMC_XWZ_PROVIDER_ACTIVATED_BOX) { - // - 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 // - ); - } - } + // // + // 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) { @@ -483,7 +485,7 @@ class XCX121SMCXWZSignalDetector : public XCBase // double iAtr = provider.decisionXConditions.atrBuffer[1]; - iAtr *= 0; + iAtr *= 2; // // Select Condition SL ... @@ -532,266 +534,271 @@ class XCX121SMCXWZSignalDetector : public XCBase // // Based On Priority ... - has = priority != X121SMC_XWZ_PRIORITY_NONE; - if (has) + useQuarterTargets = false; + if (useQuarterTargets) { // - switch (priority) + has = priority != X121SMC_XWZ_PRIORITY_NONE; + if (has) { - // - case X121SMC_XWZ_PRIORITY_WEAK: // - if (isBullish) + switch (priority) { - // - // Weak ... - Add( - workingZone.supplyZone.Lower(), - targets // - ); - } - else - { - // - // Weak ... - Add( - workingZone.demandZone.Upper(), - targets // - ); - } - break; - - // - case X121SMC_XWZ_PRIORITY_LOW: // - if (isBullish) - { + case X121SMC_XWZ_PRIORITY_WEAK: // - // Weak ... - Add( - workingZone.supplyZone.Lower(), - targets // - ); + if (isBullish) + { + // + // Weak ... + Add( + workingZone.supplyZone.Lower(), + targets // + ); + } + else + { + // + // Weak ... + Add( + workingZone.demandZone.Upper(), + targets // + ); + } + break; - // - // Low ... - Add( - workingZone.quarter1, - targets // - ); - } - else - { - // - // Weak ... - Add( - workingZone.demandZone.Upper(), - targets // - ); - - // - // Low ... - Add( - workingZone.quarter3, - targets // - ); - } - break; - - // - case X121SMC_XWZ_PRIORITY_REGULAR: // - if (isBullish) - { + case X121SMC_XWZ_PRIORITY_LOW: // - // Weak ... - Add( - workingZone.supplyZone.Lower(), - targets // - ); + if (isBullish) + { + // + // Weak ... + Add( + workingZone.supplyZone.Lower(), + targets // + ); - // - // Low ... - Add( - workingZone.quarter1, - targets // - ); + // + // Low ... + Add( + workingZone.quarter1, + targets // + ); + } + else + { + // + // Weak ... + Add( + workingZone.demandZone.Upper(), + targets // + ); - // - // Regular ... - Add( - workingZone.quarter2, - targets // - ); - } - else - { - // - // Weak ... - Add( - workingZone.demandZone.Upper(), - targets // - ); + // + // Low ... + Add( + workingZone.quarter3, + targets // + ); + } + break; - // - // Low ... - Add( - workingZone.quarter3, - targets // - ); - - // - // Regular ... - Add( - workingZone.quarter2, - targets // - ); - } - break; - - // - case X121SMC_XWZ_PRIORITY_HIGH: // - if (isBullish) - { + case X121SMC_XWZ_PRIORITY_REGULAR: // - // Weak ... - Add( - workingZone.supplyZone.Lower(), - targets // - ); + if (isBullish) + { + // + // Weak ... + Add( + workingZone.supplyZone.Lower(), + targets // + ); - // - // Low ... - Add( - workingZone.quarter1, - targets // - ); + // + // Low ... + Add( + workingZone.quarter1, + targets // + ); - // - // Regular ... - Add( - workingZone.quarter2, - targets // - ); + // + // Regular ... + Add( + workingZone.quarter2, + targets // + ); + } + else + { + // + // Weak ... + Add( + workingZone.demandZone.Upper(), + targets // + ); - // - // High ... - Add( - workingZone.quarter3, - targets // - ); - } - else - { - // - // Weak ... - Add( - workingZone.demandZone.Upper(), - targets // - ); + // + // Low ... + Add( + workingZone.quarter3, + targets // + ); - // - // Low ... - Add( - workingZone.quarter3, - targets // - ); + // + // Regular ... + Add( + workingZone.quarter2, + targets // + ); + } + break; - // - // Regular ... - Add( - workingZone.quarter2, - targets // - ); - - // - // High ... - Add( - workingZone.quarter1, - targets // - ); - } - break; - - // - case X121SMC_XWZ_PRIORITY_STRONG_HIGH: // - if (isBullish) - { + case X121SMC_XWZ_PRIORITY_HIGH: // - // Weak ... - Add( - workingZone.supplyZone.Lower(), - targets // - ); + if (isBullish) + { + // + // Weak ... + Add( + workingZone.supplyZone.Lower(), + targets // + ); - // - // Low ... - Add( - workingZone.quarter1, - targets // - ); + // + // Low ... + Add( + workingZone.quarter1, + targets // + ); - // - // Regular ... - Add( - workingZone.quarter2, - targets // - ); + // + // Regular ... + Add( + workingZone.quarter2, + targets // + ); - // - // High ... - Add( - workingZone.quarter3, - targets // - ); + // + // High ... + Add( + workingZone.quarter3, + targets // + ); + } + else + { + // + // Weak ... + Add( + workingZone.demandZone.Upper(), + targets // + ); + // + // Low ... + Add( + workingZone.quarter3, + targets // + ); + + // + // Regular ... + Add( + workingZone.quarter2, + targets // + ); + + // + // High ... + Add( + workingZone.quarter1, + targets // + ); + } + break; + + // + case X121SMC_XWZ_PRIORITY_STRONG_HIGH: // - // Strong High ... - Add( - workingZone.demandZone.Upper(), - targets // - ); + if (isBullish) + { + // + // Weak ... + Add( + workingZone.supplyZone.Lower(), + targets // + ); + + // + // Low ... + Add( + workingZone.quarter1, + targets // + ); + + // + // Regular ... + Add( + workingZone.quarter2, + targets // + ); + + // + // High ... + Add( + workingZone.quarter3, + targets // + ); + + // + // Strong High ... + Add( + workingZone.demandZone.Upper(), + targets // + ); + } + else + { + // + // Weak ... + Add( + workingZone.demandZone.Upper(), + targets // + ); + + // + // Low ... + Add( + workingZone.quarter3, + targets // + ); + + // + // Regular ... + Add( + workingZone.quarter2, + targets // + ); + + // + // High ... + Add( + workingZone.quarter1, + targets // + ); + + // + // Strong High ... + Add( + workingZone.supplyZone.Lower(), + targets // + ); + } + break; } - else - { - // - // Weak ... - Add( - workingZone.demandZone.Upper(), - targets // - ); - - // - // Low ... - Add( - workingZone.quarter3, - targets // - ); - - // - // Regular ... - Add( - workingZone.quarter2, - targets // - ); - - // - // High ... - Add( - workingZone.quarter1, - targets // - ); - - // - // Strong High ... - Add( - workingZone.supplyZone.Lower(), - targets // - ); - } - break; } } } @@ -967,6 +974,12 @@ class XCX121SMCXWZSignalDetector : public XCBase // bool result = false; + // + if (!useGuards) + { + return result; + } + // Clean(guards); @@ -1653,6 +1666,9 @@ class XCX121SMCXWZSignalDetector : public XCBase */ void Init() { + // + useGuards = true; + useQuarterTargets = true; } /** diff --git a/X121SMCEA/Signals/x-121.smc.xwz.signal.lib.mq5 b/X121SMCEA/Signals/x-121.smc.xwz.signal.lib.mq5 index bea071bd..0f397839 100644 --- a/X121SMCEA/Signals/x-121.smc.xwz.signal.lib.mq5 +++ b/X121SMCEA/Signals/x-121.smc.xwz.signal.lib.mq5 @@ -924,38 +924,7 @@ struct X121SMCStrategyXWZWorkingZone bool isBearish = false; // - XOHCL zBar; - XOHCL cBar; - XOHCL pBar; - - // - // Initial Bars ... - result = zBar.Init( - symbol, - period, - barIndex // - ); - result = - result && - zBar.GetPreviousBar(cBar); - result = - result && - cBar.GetPreviousBar(pBar); - if (!result) - { - // - zBar.Clean(); - cBar.Clean(); - pBar.Clean(); - - // - return result; - } - - // - // Detecting Signal Conditions ... - X121SMCStrategyConditionParser decisionParser; - decisionParser.Parse(provider.decisionXConditions); + X121SMCStrategyConditionParser cParser; // // Senario 1: @@ -967,405 +936,30 @@ struct X121SMCStrategyXWZWorkingZone if (useSenario1) { // - // Senario 1 Bullish Conditions ... + isSenario1Happend = cParser.HasSenario1Conditions( + X_CYCLE_DECISION, + box, + holderBox, + dir, + provider, + X_CYCLE_ANALYSE, + barIndex // + ); + + // isSenario1Bullish = - // - // X3Ma / XVwap Switched To Bulish ... - ( - // - // X3Ma Switched To Bulish ... - ( - // - (provider.decisionXConditions.isX3MaFastCrossedOverMid && - decisionParser.isX3MaBullishStateUnderValesGoldenZone) - // - ) - // - || - // - // XVWap Switched To Bulish ... - ( - // - (provider.decisionXConditions.isVWapFastCrossedOverMid && - decisionParser.isVWapBullishStateUnderValesGoldenZone) - // - ) - // - ) - // - && - // - // Checking other Conditions ... - ( - // - // XSTR ... - provider.decisionXConditions.isStrBullish && - // - // XCHE ... - provider.decisionXConditions.isCheBullish && - provider.decisionXConditions.le1Buffer[cIDX] < cBar.low && - provider.decisionXConditions.le2Buffer[cIDX] < cBar.low - // - ) - // - ; + isSenario1Happend && + IsBullish(dir); // - // Senario 1 Bearish Conditions ... isSenario1Bearish = - // - // X3Ma / XVwap Switched To Bearish ... - ( - // - // X3Ma Switched To Bearish ... - ( - // - (provider.decisionXConditions.isX3MaFastCrossedUnderMid && - decisionParser.isX3MaBearishStateOverPeaksGoldenZone) - // - ) - // - || - // - // XVWap Switched To Bearish ... - ( - // - (provider.decisionXConditions.isVWapFastCrossedUnderMid && - decisionParser.isVWapBearishStateOverPeaksGoldenZone) - // - ) - // - ) - // - && - // - // Checking other Conditions ... - ( - // - // XSTR ... - provider.decisionXConditions.isStrBearish && - // - // XCHE ... - provider.decisionXConditions.isCheBearish && - provider.decisionXConditions.se1Buffer[cIDX] > cBar.high && - provider.decisionXConditions.se2Buffer[cIDX] > cBar.high - // - ) - // - ; + isSenario1Happend && + IsBearish(dir); // - // Filling Requirements using Senario 1 ... - isSenario1Happend = - isSenario1Bullish || - isSenario1Bearish; if (isSenario1Happend) { - // - dir = - isSenario1Bullish - ? X_DIRECTION_BULLISH - : X_DIRECTION_BEARISH; - - // - box.dir = dir; - box.to = TimeCurrent(); - box.symbol = provider - .decisionXConditions - .symbol; - box.period = provider - .decisionXConditions - .period; - - // - int fromIDX = -1; - if (isSenario1Bullish) - { - // - double vale = provider - .decisionXConditions - .valesBuffer[cIDX]; - - // - box.lower = vale; - - // - box.upper = provider - .decisionXConditions - .valesGoldenBuffer[cIDX]; - - // - int lowerValeIDX = -1; - double lowerVale = provider - .decisionCycleHelper - .mX121Helper - .xpvHelper - .GetLowerVale( - lowerValeIDX, - vale, - cBar.Index() // - ); - - // - int higherValeIDX = -1; - double higherVale = provider - .decisionCycleHelper - .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 = provider - .decisionXConditions - .peaksBuffer[cIDX]; - - // - box.upper = peak; - - // - box.lower = provider - .decisionXConditions - .peaksGoldenBuffer[cIDX]; - - // - int lowerPeakIDX = -1; - double lowerPeak = provider - .decisionCycleHelper - .mX121Helper - .xpvHelper - .GetLowerPeak( - lowerPeakIDX, - peak, - cBar.Index() // - ); - - // - int higherPeakIDX = -1; - double higherPeak = provider - .decisionCycleHelper - .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 (isSenario1Bullish) - { - // - // Demand Zones ... - XBoxZone tmp[]; - ToBox( - provider.visionState.demandZones, - tmp // - ); - Copy( - tmp, - tmpBoxes, - false // - ); - Clean(tmp); - - // - // Bullish Order Blocks ... - ToBox( - provider.visionState.bullishOrderBlocks, - tmp // - ); - Copy( - tmp, - tmpBoxes, - false // - ); - Clean(tmp); - - // - // Bullish Fair Value Gaps ... - ToBox( - provider.visionState.bullishFairValueGaps, - tmp // - ); - Copy( - tmp, - tmpBoxes, - false // - ); - Clean(tmp); - } - else - { - // - // Supply Zones ... - XBoxZone tmp[]; - ToBox( - provider.visionState.supplyZones, - tmp // - ); - Copy( - tmp, - tmpBoxes, - false // - ); - Clean(tmp); - - // - // Bearish Order Blocks ... - ToBox( - provider.visionState.bearishOrderBlocks, - tmp // - ); - Copy( - tmp, - tmpBoxes, - false // - ); - Clean(tmp); - - // - // Bearish Fair Value Gaps ... - ToBox( - provider.visionState.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); - - // signalProvider = X121SMC_XWZ_PROVIDER_ACTIVATED_BOX; - - // - // Validate Conditions to Force Has Holder Box ... - // isSenario1Happend = - // holderBox.IsValid() && - // isSenario1Happend; - // if (!isSenario1Happend) - // { - // // - // isSenario1Bullish = false; - // isSenario1Bearish = false; - // } } } @@ -1378,228 +972,6 @@ struct X121SMCStrategyXWZWorkingZone bool isSenario2Bearish = false; if (useSenario2) { - // - // Senario 2 Bullish Conditions ... - isSenario2Bullish = - // - // XSMHK ... - ( - // - (decisionParser.isRawHKBullishUnderValesGoldenZone && - decisionParser.isSMHKSwitchedToBullishUnderValesGoldenZone) - // - || - // - (decisionParser.isSMHKBullishUnderValesGoldenZone && - decisionParser.isRawHKSwitchedToBullishUnderValesGoldenZone) - // - ) - // - && - // - // Other Conditions ... - ( - // - provider.decisionXConditions.isSarBullish && - provider.decisionXConditions.isStrBullish - // - ); - - // - // Senario 2 Bearish Conditions ... - isSenario2Bearish = - // - // XSMHK ... - ( - // - (decisionParser.isRawHKBearishOverPeaksGoldenZone && - decisionParser.isSMHKSwitchedToBearishOverPeaksGoldenZone) - // - || - // - (decisionParser.isSMHKBearishOverPeaksGoldenZone && - decisionParser.isRawHKSwitchedToBearishOverPeaksGoldenZone) - // - ) - // - && - // - // Other Conditions ... - ( - // - provider.decisionXConditions.isSarBearish && - provider.decisionXConditions.isStrBearish - // - ); - - // - // Filling Requirements using Senario 2 ... - isSenario2Happend = - isSenario2Bullish || - isSenario2Bearish; - if (isSenario2Happend) - { - // - dir = - isSenario2Bullish - ? X_DIRECTION_BULLISH - : X_DIRECTION_BEARISH; - - // - box.dir = dir; - box.to = TimeCurrent(); - box.symbol = provider - .decisionXConditions - .symbol; - box.period = provider - .decisionXConditions - .period; - - // - int fromIDX = -1; - if (isSenario2Bullish) - { - // - double vale = provider - .decisionXConditions - .valesBuffer[cIDX]; - - // - box.lower = vale; - - // - box.upper = provider - .decisionXConditions - .valesGoldenBuffer[cIDX]; - - // - int lowerValeIDX = -1; - double lowerVale = provider - .decisionCycleHelper - .mX121Helper - .xpvHelper - .GetLowerVale( - lowerValeIDX, - vale, - cBar.Index() // - ); - - // - int higherValeIDX = -1; - double higherVale = provider - .decisionCycleHelper - .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 = provider - .decisionXConditions - .peaksBuffer[cIDX]; - - // - box.upper = peak; - - // - box.lower = provider - .decisionXConditions - .peaksGoldenBuffer[cIDX]; - - // - int lowerPeakIDX = -1; - double lowerPeak = provider - .decisionCycleHelper - .mX121Helper - .xpvHelper - .GetLowerPeak( - lowerPeakIDX, - peak, - cBar.Index() // - ); - - // - int higherPeakIDX = -1; - double higherPeak = provider - .decisionCycleHelper - .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; - } - - // - signalProvider = X121SMC_XWZ_PROVIDER_ACTIVATED_BOX; - } } // @@ -1611,182 +983,6 @@ struct X121SMCStrategyXWZWorkingZone bool isSenario3Bearish = false; if (useSenario3) { - // - // Senario 3 Bullish Conditions ... - isSenario3Bullish = false; - - // - // Senario 3 Bearish Conditions ... - isSenario3Bearish = false; - - // - // Filling Requirements using Senario 3 ... - isSenario3Happend = - isSenario3Bullish || - isSenario3Bearish; - if (isSenario3Happend) - { - // - dir = - isSenario3Bullish - ? X_DIRECTION_BULLISH - : X_DIRECTION_BEARISH; - - // - box.dir = dir; - box.to = TimeCurrent(); - box.symbol = provider - .decisionXConditions - .symbol; - box.period = provider - .decisionXConditions - .period; - - // - int fromIDX = -1; - if (isSenario3Bullish) - { - // - double vale = provider - .decisionXConditions - .valesBuffer[cIDX]; - - // - box.lower = vale; - - // - box.upper = provider - .decisionXConditions - .valesGoldenBuffer[cIDX]; - - // - int lowerValeIDX = -1; - double lowerVale = provider - .decisionCycleHelper - .mX121Helper - .xpvHelper - .GetLowerVale( - lowerValeIDX, - vale, - cBar.Index() // - ); - - // - int higherValeIDX = -1; - double higherVale = provider - .decisionCycleHelper - .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 = provider - .decisionXConditions - .peaksBuffer[cIDX]; - - // - box.upper = peak; - - // - box.lower = provider - .decisionXConditions - .peaksGoldenBuffer[cIDX]; - - // - int lowerPeakIDX = -1; - double lowerPeak = provider - .decisionCycleHelper - .mX121Helper - .xpvHelper - .GetLowerPeak( - lowerPeakIDX, - peak, - cBar.Index() // - ); - - // - int higherPeakIDX = -1; - double higherPeak = provider - .decisionCycleHelper - .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; - } - - // - signalProvider = X121SMC_XWZ_PROVIDER_ACTIVATED_BOX; - } } // @@ -1819,12 +1015,12 @@ struct X121SMCStrategyXWZWorkingZone isBearish); // - // Cleanup Resources ... - - // - zBar.Clean(); - cBar.Clean(); - pBar.Clean(); + if (!result) + { + // + box.Clean(); + holderBox.Clean(); + } // return result; diff --git a/X121SMCEA/Strategy/x-121.smc.strategy.class.mq5 b/X121SMCEA/Strategy/x-121.smc.strategy.class.mq5 index d271a7ac..3d425109 100644 --- a/X121SMCEA/Strategy/x-121.smc.strategy.class.mq5 +++ b/X121SMCEA/Strategy/x-121.smc.strategy.class.mq5 @@ -268,6 +268,9 @@ class XCX121SMCStrategy : public XCX121SMCBaseStrategy type // ); + // + double spread = GetSpread(conditions.symbol); + // double slAddition = 0; sl = @@ -317,8 +320,10 @@ class XCX121SMCStrategy : public XCX121SMCBaseStrategy hasXWZSignal) { // - // Configuring Amount Percent and ETC ... - bool ignoreEAVolume = mXWZConditions.reward > 0 && + // Configuring Amount Percent and etc ... + // TODO: Enable if required ... + bool ignoreEAVolume = false && + mXWZConditions.reward > 0 && mXWZConditions.amountPercent > 0; if (ignoreEAVolume) { @@ -379,6 +384,13 @@ class XCX121SMCStrategy : public XCX121SMCBaseStrategy } } + // + // Apply Spread on Signal's TP ... + signal.tp = + hasLong + ? signal.tp + spread + : signal.tp - spread; + // hasLong = false; hasShort = false; @@ -692,7 +704,7 @@ class XCX121SMCStrategy : public XCX121SMCBaseStrategy { // useXWZSignal = true; - useXWZSignalGuard = false; + useXWZSignalGuard = true; // string symbol = GetSymbol(); @@ -735,7 +747,7 @@ class XCX121SMCStrategy : public XCX121SMCBaseStrategy bool showAll = false; // - x121Inputs.showRSI = false; + x121Inputs.showRSI = showAll || false; // // XPV ... @@ -791,7 +803,7 @@ class XCX121SMCStrategy : public XCX121SMCBaseStrategy // // XPV ... - x121Inputs.xpvInputs.showSar = showAll || false; + x121Inputs.xpvInputs.showSar = showAll || true; x121Inputs.xpvInputs.showPeaks = showAll || true; x121Inputs.xpvInputs.showVales = showAll || true; x121Inputs.xpvInputs.showGoldenZones = showAll || true; @@ -810,7 +822,7 @@ class XCX121SMCStrategy : public XCX121SMCBaseStrategy // // XSTR ... - x121Inputs.xstrInputs.showStr = showAll || false; + x121Inputs.xstrInputs.showStr = showAll || true; x121Inputs.xstrInputs.showStrUpper = showAll || false; x121Inputs.xstrInputs.showStrLower = showAll || false;