diff --git a/Documents/BKP/test.tmp.mq5 b/Documents/BKP/test.tmp.mq5 new file mode 100644 index 00000000..295565c4 --- /dev/null +++ b/Documents/BKP/test.tmp.mq5 @@ -0,0 +1,273 @@ +// +// Detect SignalBox Trigger ... +// Cond1: +// - Close Under Min / Max ... +// - All Trendings in Direction ... +// - Consolidating Trendings ... +// - ... +bool CanTriggerCond1( + XCXCAEAHelper *helper, + XBoxZone &box, + ENUM_X_DIRECTION &dir, + double &sls[], + int barIndex = 0, + int loopback = 10 // +) +{ + // + bool result = false; + + // + // Normalize Args ... + Clean(sls); + dir = X_DIRECTION_NONE; + loopback = NormalizeInt(loopback, 5); + barIndex = NormalizeInt(barIndex, 0); + + // + // Validate Decision Box ... + result = box.IsValid(); + if (!result) + { + return result; + } + + // + // Retrieve Market Conditions ... + XCAEAConditions conditions; + result = helper.GetConditions( + conditions, + barIndex, + loopback // + ); + + // + // Extract CBar ... + XOHCL cBar; + result = cBar.Init( + conditions.symbol, + conditions.period, + barIndex // + ); + if (!result) + { + // + cBar.Clean(); + conditions.Clean(); + + // + return result; + } + + // + // Bar Conditions ... + + // + ENUM_X_DIRECTION barDir; + + // + // ENGULF ... + + // + bool isCBarEngulfed = helper + .barAnalyser + .IsEngulfed( + cBar, + barDir // + ); + + // + bool isCBarBullishEngulfed = + isCBarEngulfed && + IsBullish(barDir); + + // + bool isCBarBearishEngulfed = + isCBarEngulfed && + IsBearish(barDir); + + // + bool isBullish = box.IsBullish(); + bool isBearish = box.IsBearish(); + + // + int zIDX = 0; + int cIDX = zIDX + 1; + int pIDX = cIDX + 1; + int p2IDX = pIDX + 1; + int p3IDX = p2IDX + 1; + int p4IDX = p3IDX + 1; + + // + // Reading Values ... + + // + // SAR ... + double cSAR = conditions.sarBuffer[cIDX]; + + // + // SWH ... + double cSWH = conditions.swingHighBuffer[cIDX]; + + // + // SWL ... + double cSWL = conditions.swingLowBuffer[cIDX]; + + // + // PEAK ... + double cPeak = conditions.peakBuffer[cIDX]; + + // + // VALE ... + double cVale = conditions.valeBuffer[cIDX]; + + // + // MAH ... + double cMAH = conditions.mahBuffer[cIDX]; + + // + // MAC ... + double cMAC = conditions.macBuffer[cIDX]; + + // + // MAL ... + double cMAL = conditions.malBuffer[cIDX]; + + // + // KI ... + double cKI = conditions.kiBuffer[cIDX]; + double cKIState = conditions.kiStateBuffer[cIDX]; + + // + // TKI ... + double cTKI = conditions.tkiBuffer[cIDX]; + double cTKIState = conditions.tkiStateBuffer[cIDX]; + + // + // FAST ... + double cFast = conditions.fastBuffer[cIDX]; + double cFastState = conditions.fastStateBuffer[cIDX]; + + // + // VIDYA ... + double cVidya = conditions.vidyaBuffer[cIDX]; + double cVidyaState = conditions.vidyaStateBuffer[cIDX]; + + // + // TREND ... + double cTrend = conditions.trendBuffer[cIDX]; + double cTrendState = conditions.trendStateBuffer[cIDX]; + + // + // Generating Conditions ... + + // + bool isSWLOverBox = cSWL > box.lower; + bool isSWHUnderBox = cSWH < box.upper; + + // + bool isValeOverBox = cVale > box.lower; + bool isPeakUnderBox = cPeak < box.upper; + + // + bool hasBullishPress = + // isBullish && + (isSWLOverBox || + isValeOverBox); + + // + bool hasBearishPress = + // isBearish && + (isSWHUnderBox || + isPeakUnderBox); + + // + double trends[] = { + cMAH, + cMAC, + cMAL, + cKI, + cTKI, + cFast, + cVidya, + cTrend // + }; + double trendMax = GetMax(trends); + double trendMin = GetMin(trends); + Copy( + trends, + sls // + ); + + // + bool isCloseOverMax = cBar.close > trendMax; + bool isCloseUnderMin = cBar.close < trendMin; + + // + bool isStateBullish = + cKIState > 0 && + cTKIState > 0 && + cFastState > 0 && + cTrendState > 0 && + cVidyaState > 0; + + // + bool isStateBearish = + cKIState < 0 && + cTKIState < 0 && + cFastState < 0 && + cTrendState < 0 && + cVidyaState < 0; + + // + bool hasBullishTrend = + // isBullish && + isStateBullish && + isCloseOverMax; + + // + bool hasBearishTrend = + // isBearish && + isStateBearish && + isCloseUnderMin; + + // + // Summarizing ... + + // + bool canTriggerLong = + // isBullish && + hasBullishPress && + hasBullishTrend; + + // + bool canTriggerShort = + // isBearish && + hasBearishPress && + hasBearishTrend; + + // + result = canTriggerLong || + canTriggerShort; + if (result) + { + // + dir = canTriggerLong + ? X_DIRECTION_BULLISH + : X_DIRECTION_BEARISH; + + // + Print("Triggered ..."); + } + + // + // Cleanup Resources ... + + // + cBar.Clean(); + Clean(trends); + conditions.Clean(); + + // + return result; +} diff --git a/XCAEA/Libraries/xcaea.signaller.lib.mq5 b/XCAEA/Libraries/xcaea.signaller.lib.mq5 index ee07466b..06249a27 100644 --- a/XCAEA/Libraries/xcaea.signaller.lib.mq5 +++ b/XCAEA/Libraries/xcaea.signaller.lib.mq5 @@ -80,8 +80,8 @@ struct XCAEAStrategyConditions datetime triggerTime; // - XBoxZone signalBox; ENUM_X_DIRECTION dir; + XBoxZone decisionZone; ENUM_X_POSITION_TYPES type; XCAEAConditions conditions; @@ -122,8 +122,8 @@ struct XCAEAStrategyConditions Clean(targets); // - signalBox.Clean(); conditions.Clean(); + decisionZone.Clean(); // dir = X_DIRECTION_NONE; @@ -426,7 +426,8 @@ int AddGuard( } // -bool TestDetectSignal( +// Detect Decision Zone ... +bool DetectDecisionZone( XCXCAEAHelper *helper, XCXCAEAPOIDrawer *drawer, XBoxZone &box, @@ -1165,6 +1166,20 @@ bool TestDetectSignal( // Print("Conditions Finder ..."); } + // + bool isCond2 = + (cPeak == pPeak && + cPeak == cSWH && + cPeak == cResistance) && + (cVale == pVale && + cVale == cSWL && + cVale == cSupport); + if (isCond2) + { + // + Print("Decision Zone Full Cond1"); + } + // // Summarise Result ... @@ -1215,17 +1230,17 @@ bool TestDetectSignal( } // -// Detect SignalBox Trigger ... -// Cond1: -// - Close Under Min / Max ... -// - All Trendings in Direction ... -// - Consolidating Trendings ... -// - ... +// Trigger Conditions ... + +// +// Detect Trigger Based On Decision Zone's +// Fake Breaked out ... bool CanTriggerCond1( XCXCAEAHelper *helper, XBoxZone &box, ENUM_X_DIRECTION &dir, - double &sls[], + double &sl, + double &tp, int barIndex = 0, int loopback = 10 // ) @@ -1235,7 +1250,8 @@ bool CanTriggerCond1( // // Normalize Args ... - Clean(sls); + sl = 0; + tp = 0; dir = X_DIRECTION_NONE; loopback = NormalizeInt(loopback, 5); barIndex = NormalizeInt(barIndex, 0); @@ -1249,191 +1265,167 @@ bool CanTriggerCond1( } // - // Retrieve Market Conditions ... - XCAEAConditions conditions; - result = helper.GetConditions( - conditions, + // Check Box is Faked Breaked Out ... + + // + XBoxZone validatorFVG; + + // + bool isBullishFakedBreakedOut = IsBoxFakedBreakout( + helper, + box, + validatorFVG, + X_DIRECTION_BULLISH, barIndex, - loopback // + 100, // Loopback For FVG ... + true, // Force FVg Validation ... + true // Force FVG Bar Type ... ); // - // Extract CBar ... - XOHCL cBar; - result = cBar.Init( - conditions.symbol, - conditions.period, - barIndex // + bool isBearishFakedBreakedOut = IsBoxFakedBreakout( + helper, + box, + validatorFVG, + X_DIRECTION_BEARISH, + barIndex, + 100, // Loopback For FVG ... + true, // Force FVg Validation ... + true // Force FVG Bar Type ... ); - if (!result) + + // + bool isFakeBreaked = + isBullishFakedBreakedOut || + isBearishFakedBreakedOut; + if (isFakeBreaked) { // - cBar.Clean(); - conditions.Clean(); + // Preparing TP and SL ... // - return result; + sl = isBullishFakedBreakedOut + ? validatorFVG.lower + : validatorFVG.upper; + + // + tp = isBullishFakedBreakedOut + ? box.upper + : box.lower; } - // - bool isBullish = box.IsBullish(); - bool isBearish = box.IsBearish(); - - // - int zIDX = 0; - int cIDX = zIDX + 1; - int pIDX = cIDX + 1; - int p2IDX = pIDX + 1; - int p3IDX = p2IDX + 1; - int p4IDX = p3IDX + 1; - - // - // Reading Values ... - - // - // SAR ... - double cSAR = conditions.sarBuffer[cIDX]; - - // - // SWH ... - double cSWH = conditions.swingHighBuffer[cIDX]; - - // - // SWL ... - double cSWL = conditions.swingLowBuffer[cIDX]; - - // - // PEAK ... - double cPeak = conditions.peakBuffer[cIDX]; - - // - // VALE ... - double cVale = conditions.valeBuffer[cIDX]; - - // - // MAH ... - double cMAH = conditions.mahBuffer[cIDX]; - - // - // MAC ... - double cMAC = conditions.macBuffer[cIDX]; - - // - // MAL ... - double cMAL = conditions.malBuffer[cIDX]; - - // - // KI ... - double cKI = conditions.kiBuffer[cIDX]; - double cKIState = conditions.kiStateBuffer[cIDX]; - - // - // TKI ... - double cTKI = conditions.tkiBuffer[cIDX]; - double cTKIState = conditions.tkiStateBuffer[cIDX]; - - // - // FAST ... - double cFast = conditions.fastBuffer[cIDX]; - double cFastState = conditions.fastStateBuffer[cIDX]; - - // - // VIDYA ... - double cVidya = conditions.vidyaBuffer[cIDX]; - double cVidyaState = conditions.vidyaStateBuffer[cIDX]; - - // - // TREND ... - double cTrend = conditions.trendBuffer[cIDX]; - double cTrendState = conditions.trendStateBuffer[cIDX]; - - // - // Generating Conditions ... - - // - bool isSWLOverBox = cSWL > box.lower; - bool isSWHUnderBox = cSWH < box.upper; - - // - bool isValeOverBox = cVale > box.lower; - bool isPeakUnderBox = cPeak < box.upper; - - // - bool hasBullishPress = - // isBullish && - (isSWLOverBox || - isValeOverBox); - - // - bool hasBearishPress = - // isBearish && - (isSWHUnderBox || - isPeakUnderBox); - - // - double trends[] = { - cMAH, - cMAC, - cMAL, - cKI, - cTKI, - cFast, - cVidya, - cTrend // - }; - double trendMax = GetMax(trends); - double trendMin = GetMin(trends); - Copy( - trends, - sls // - ); - - // - bool isCloseOverMax = cBar.close > trendMax; - bool isCloseUnderMin = cBar.close < trendMin; - - // - bool isStateBullish = - cKIState > 0 && - cTKIState > 0 && - cFastState > 0 && - cTrendState > 0 && - cVidyaState > 0; - - // - bool isStateBearish = - cKIState < 0 && - cTKIState < 0 && - cFastState < 0 && - cTrendState < 0 && - cVidyaState < 0; - - // - bool hasBullishTrend = - // isBullish && - isStateBullish && - isCloseOverMax; - - // - bool hasBearishTrend = - // isBearish && - isStateBearish && - isCloseUnderMin; - // // Summarizing ... // bool canTriggerLong = - // isBullish && - hasBullishPress && - hasBullishTrend; + isBullishFakedBreakedOut; // bool canTriggerShort = - // isBearish && - hasBearishPress && - hasBearishTrend; + isBearishFakedBreakedOut; + + // + result = canTriggerLong || + canTriggerShort; + if (result) + { + // + dir = canTriggerLong + ? X_DIRECTION_BULLISH + : X_DIRECTION_BEARISH; + + // + Print("Triggered ..."); + } + + // + // Cleanup Resources ... + validatorFVG.Clean(); + + // + return result; +} + +// +// Detect Trigger Based On Decision Zone's +// Box Starts With FVG ... +bool CanTriggerCond2( + XCXCAEAHelper *helper, + XBoxZone &box, + ENUM_X_DIRECTION &dir, + double &sl, + double &tp, + int barIndex = 0, + int loopback = 10 // +) +{ + // + bool result = false; + + // + // Normalize Args ... + sl = 0; + tp = 0; + dir = X_DIRECTION_NONE; + loopback = NormalizeInt(loopback, 5); + barIndex = NormalizeInt(barIndex, 0); + + // + // Validate Decision Box ... + result = box.IsValid(); + if (!result) + { + return result; + } + + // + XBoxZone activatedFVG; + bool hasActivatedFVG = IsBoxHasActivatedFVG( + helper, + box, + activatedFVG, + barIndex, + loopback // + ); + + // + bool hasBullishActivatedFVG = + hasActivatedFVG && + activatedFVG.IsBullish(); + + // + bool hasBearishActivatedFVG = + hasActivatedFVG && + activatedFVG.IsBearish(); + + // + if (hasActivatedFVG) + { + // + // Preparing TP and SL ... + + // + sl = hasBullishActivatedFVG + ? box.lower // activatedFVG.lower + : box.upper; // activatedFVG.upper; + + // + // Since Here TP Must Calculated + // Using R2R we Ignore Target ... + tp = 0; + } + + // + // Summarizing ... + + // + bool canTriggerLong = + hasBullishActivatedFVG; + + // + bool canTriggerShort = + hasBearishActivatedFVG; // result = canTriggerLong || @@ -1452,9 +1444,741 @@ bool CanTriggerCond1( // // Cleanup Resources ... + // + return result; +} + +// +// Helper Functions ... + +// +// Check a Box is Breaked or Not ... +bool IsBoxBreaked( + XCXCAEAHelper *helper, + XBoxZone &box, + int barIndex = 0 // +) +{ + // + bool result = false; + + // + // Normalize Args ... + barIndex = NormalizeInt(barIndex, 0); + + // + // Validate Args ... + result = + box.IsValid() && + helper != NULL; + if (!result) + { + // + // Assume Box Invalid and Breaked + // When Args not Valid ... + result = true; + return result; + } + + // + bool isBullish = box.IsBullish(); + bool isBearish = box.IsBearish(); + + // + // Extract Bars ... + + // + XOHCL cBar; + XOHCL pBar; + XOHCL p2Bar; + XOHCL p3Bar; + + // + result = cBar.Init( + box.symbol, + box.period, + barIndex + 1 // + ); + result = result && + cBar.GetPreviousBar(pBar); + result = result && + pBar.GetPreviousBar(p2Bar); + result = result && + p2Bar.GetPreviousBar(p3Bar); + if (!result) + { + // + cBar.Clean(); + pBar.Clean(); + p2Bar.Clean(); + p3Bar.Clean(); + + // + // Assume Box Invalid and Breaked + // When Args not Valid ... + result = true; + + // + return result; + } + + // + // Check Box is Breaked or not ... + // a Box Assume Breakes when at least 3 Bars Close over / under applied Price ... + + // + double appliedPrice = + isBullish + ? box.lower + : box.upper; + + // + bool isBullishBreaked = + isBullish && + cBar.close < appliedPrice && + pBar.close < appliedPrice && + p2Bar.close < appliedPrice; + + // + bool isBearishBreaked = + isBearish && + cBar.close > appliedPrice && + pBar.close > appliedPrice && + p2Bar.close > appliedPrice; + + // + result = isBullishBreaked || + isBearishBreaked; + + // + // Cleanup Resources ... + // cBar.Clean(); - Clean(trends); + pBar.Clean(); + p2Bar.Clean(); + p3Bar.Clean(); + + // + return result; +} + +// +// Detect Fake Breakout ... +bool IsBoxFakedBreakout( + XCXCAEAHelper *helper, + XBoxZone &box, + XBoxZone &validatorFVG, + ENUM_X_DIRECTION forDir, + int barIndex = 0, + int loopback = 100, + bool forceFVGValidating = false, + bool forceFVGBarType = false // +) +{ + // + bool result = false; + + // + validatorFVG.Clean(); + + // + // Normalizing Args ... + barIndex = NormalizeInt(barIndex, 0); + loopback = NormalizeInt(loopback, 10); + + // + // Validate Decision Box ... + result = box.IsValid() && + helper != NULL && + (HasDirection(forDir)); + if (!result) + { + return result; + } + + // + double points = GetPoints(box.symbol); + + // + // Extract Bars ... + + // + XOHCL cBar; + XOHCL pBar; + XOHCL p2Bar; + XOHCL p3Bar; + + // + result = cBar.Init( + box.symbol, + box.period, + barIndex + 1 // + ); + result = result && + cBar.GetPreviousBar(pBar); + result = result && + pBar.GetPreviousBar(p2Bar); + result = result && + p2Bar.GetPreviousBar(p3Bar); + if (!result) + { + // + cBar.Clean(); + pBar.Clean(); + p2Bar.Clean(); + p3Bar.Clean(); + + // + return result; + } + + // + // Bar Conditions ... + + // + ENUM_X_DIRECTION barDir; + + // + // Engulfed ... + bool isCBarEngulfed = helper + .barAnalyser + .IsEngulfed( + cBar, + barDir // + ); + bool isCBarBullishEngulfed = + isCBarEngulfed && + IsBullish(barDir); + bool isCBarBearishEngulfed = + isCBarEngulfed && + IsBearish(barDir); + + // + // Rejected ... + bool isCBarRejected = helper + .barAnalyser + .IsRejected( + cBar, + barDir, + false, // Force Type ... + true // Force Fibo Pressure ... + ); + bool isCBarBullishRejected = + isCBarRejected && + IsBullish(barDir); + bool isCBarBearishRejected = + isCBarRejected && + IsBearish(barDir); + + // + bool isCBarHasBullishPower = isCBarBullishRejected || + isCBarBullishEngulfed; + + // + bool isCBarHasBearishPower = isCBarBearishRejected || + isCBarBearishEngulfed; + + // + bool isBullish = box.IsBullish(); + bool isBearish = box.IsBearish(); + + // + bool lookForBullish = IsBullish(forDir); + bool lookForBearish = IsBearish(forDir); + + // + // Calculate each Direction Breake Price ... + double bullishAppliedPrice = box.lower; + double bearishAppliedPrice = box.upper; + + // + bool isCBarPressedForBullish = + // + isCBarHasBullishPower && + cBar.low < bullishAppliedPrice && + cBar.close > bullishAppliedPrice + // + ; + + // + bool isCBarPressedForBearish = + // + isCBarHasBearishPower && + cBar.high > bearishAppliedPrice && + cBar.close < bearishAppliedPrice + // + ; + + // + bool isPBarBreakedBullishAppliedPrice = + pBar.low < bullishAppliedPrice && + pBar.high > bullishAppliedPrice; + + // + bool isPBarBreakedBearishAppliedPrice = + pBar.low < bearishAppliedPrice && + pBar.high > bearishAppliedPrice; + + // + bool isP2BarBreakedBullishAppliedPrice = + p2Bar.low < bullishAppliedPrice && + p2Bar.high > bullishAppliedPrice; + + // + bool isP2BarBreakedBearishAppliedPrice = + p2Bar.low < bearishAppliedPrice && + p2Bar.high > bearishAppliedPrice; + + // + bool isBullishAppliedPriceBreaked = + isPBarBreakedBullishAppliedPrice || + isP2BarBreakedBullishAppliedPrice; + + // + bool isBearishAppliedPriceBreaked = + isPBarBreakedBearishAppliedPrice || + isP2BarBreakedBearishAppliedPrice; + + // + bool isBullishFakeBreakedOut = + lookForBullish && + isCBarPressedForBullish && + isBullishAppliedPriceBreaked; + + // + bool isBearishFakeBreakedOut = + lookForBearish && + isCBarPressedForBearish && + isBearishAppliedPriceBreaked; + + // + result = isBullishFakeBreakedOut || + isBearishFakeBreakedOut; + + // + // Validating Using FVG if necessary ... + if (forceFVGValidating) + { + // + // Detecting All FVGs Which Placed in Box till Loopback ... + XBoxZone fvg; + + // + XOHCL iBar; + bool has = false; + int start = cBar.Index(); + int end = start + loopback; + for (int i = start; i < end; i++) + { + // + // Initialize Bar ... + has = iBar.Init( + cBar.symbol, + cBar.period, + i // + ); + if (!has) + { + // + fvg.Clean(); + iBar.Clean(); + + // + continue; + } + + // + // Check FVG ... + has = helper + .barAnalyser + .IsFVG( + iBar, + fvg, + forceFVGBarType // + ); + if (!has) + { + // + fvg.Clean(); + iBar.Clean(); + + // + continue; + } + + // + bool isBullishFVG = + fvg.IsBullish() && + isBullishFakeBreakedOut; + + // + bool isBearishFVG = + fvg.IsBearish() && + isBearishFakeBreakedOut; + + // + // Checking FVG Dir ... + has = isBullishFVG || + isBearishFVG; + if (!has) + { + // + fvg.Clean(); + iBar.Clean(); + + // + continue; + } + + // + // Check CBar Must Inside FVG ... + + // + bool isFVGBullishBreaked = + isBullishFVG && + cBar.low < fvg.upper && + cBar.close > fvg.upper && + isBullishFakeBreakedOut; + + // + bool isFVGBearishBreaked = + isBearishFVG && + cBar.high > fvg.lower && + cBar.close < fvg.lower && + isBearishFakeBreakedOut; + + // + has = + isFVGBullishBreaked || + isFVGBearishBreaked; + if (has) + { + // + iBar.Clean(); + + // + break; + } + + // + fvg.Clean(); + iBar.Clean(); + } + + // + result = + result && + fvg.IsValid(); + if (result) + { + // + fvg.to = cBar.time; + + // + // Check FVG Size ... + double fvgRange = fvg.upper - fvg.lower; + bool canApplyLastBar = fvgRange < (5 * points); + if (canApplyLastBar) + { + // + // Retrieve FVG Start Bar ... + XOHCL fvgStartBar; + has = fvgStartBar.Init( + cBar.symbol, + cBar.period, + cBar.Index() + 3 // + ); + if (has) + { + // + if (fvg.IsBullish()) + { + fvg.lower = fvgStartBar.low; + } + else + { + fvg.upper = fvgStartBar.high; + } + } + + // + fvgStartBar.Clean(); + } + + // + validatorFVG = fvg; + + // + XCBoxObject *iObj; + has = helper.poiDrawer.DrawBox( + fvg, + iObj // + ); + ZeroMemory(iObj); + } + + // + fvg.Clean(); + iBar.Clean(); + } + + // + // Cleanup Resources ... + + // + cBar.Clean(); + pBar.Clean(); + p2Bar.Clean(); + p3Bar.Clean(); + + // + return result; +} + +// +// Detect Activated FVG ... +bool IsBoxHasActivatedFVG( + XCXCAEAHelper *helper, + XBoxZone &box, + XBoxZone &fvg, + int barIndex = 0, + int loopback = 10, + bool forceFVGBarType = false // +) +{ + // + bool result = false; + + // + fvg.Clean(); + + // + // Normalize Args ... + barIndex = NormalizeInt(barIndex, 0); + loopback = NormalizeInt(loopback, 10); + + // + // Validate Decision Box ... + result = box.IsValid() && + helper != NULL; + if (!result) + { + return result; + } + + // + bool isBullish = box.IsBullish(); + bool isBearish = box.IsBearish(); + double points = GetPoints(box.symbol); + + // + // Retrieve Conditions ... + XCAEAConditions conditions; + result = helper.GetConditions( + conditions, + barIndex, + loopback // + ); + if (!result) + { + // + conditions.Clean(); + + // + return result; + } + + // + // Extract Bars ... + + // + XOHCL cBar; + XOHCL pBar; + XOHCL p2Bar; + XOHCL p3Bar; + + // + result = cBar.Init( + box.symbol, + box.period, + barIndex + 1 // + ); + result = result && + cBar.GetPreviousBar(pBar); + result = result && + pBar.GetPreviousBar(p2Bar); + result = result && + p2Bar.GetPreviousBar(p3Bar); + if (!result) + { + // + cBar.Clean(); + pBar.Clean(); + p2Bar.Clean(); + p3Bar.Clean(); + conditions.Clean(); + + // + return result; + } + + // + // Find FVG ... + + // + XOHCL iBar; + bool has = false; + int start = cBar.Index(); + int end = start + loopback; + for (int i = start; i < end; i++) + { + // + // Initialize Bar ... + has = iBar.Init( + cBar.symbol, + cBar.period, + i // + ); + if (!has) + { + // + fvg.Clean(); + iBar.Clean(); + + // + continue; + }; + + // + // Check FVG ... + has = helper + .barAnalyser + .IsFVG( + iBar, + fvg, + forceFVGBarType // + ); + if (!has) + { + // + fvg.Clean(); + iBar.Clean(); + + // + continue; + } + + // + // Validate FVG ... + has = + // + fvg.IsValid() && + fvg.dir == box.dir && + fvg.from > box.from && + fvg.upper <= box.upper && + fvg.lower >= box.lower + // + ; + if (!has) + { + // + fvg.Clean(); + iBar.Clean(); + + // + continue; + } + + // + // Check CBar FVG Validations ... + + // + bool isCBarBullishRejected = + isBullish && + cBar.low < fvg.upper && + cBar.close > fvg.upper; + + // + bool isCBarBearishRejected = + isBearish && + cBar.high > fvg.lower && + cBar.close < fvg.lower; + + // + has = isCBarBullishRejected || + isCBarBearishRejected; + if (has) + { + // + iBar.Clean(); + + // + break; + } + + // + fvg.Clean(); + iBar.Clean(); + } + + // + result = fvg.IsValid(); + if (result) + { + // + fvg.to = cBar.time; + + // + // Check FVG Size ... + double fvgRange = fvg.upper - fvg.lower; + bool canApplyLastBar = true; + // fvgRange < (5 * points); + if (canApplyLastBar) + { + // + // Retrieve FVG Start Bar ... + XOHCL fvgStartBar; + has = fvgStartBar.Init( + cBar.symbol, + cBar.period, + cBar.Index() + 4 // + ); + if (has) + { + // + if (fvg.IsBullish()) + { + fvg.lower = fvgStartBar.low; + } + else + { + fvg.upper = fvgStartBar.high; + } + } + + // + fvgStartBar.Clean(); + } + + // + XCBoxObject *iObj; + helper.poiDrawer.DrawBox( + fvg, + iObj // + ); + ZeroMemory(iObj); + } + + // + // Cleanup Resources ... + + // + iBar.Clean(); + cBar.Clean(); + pBar.Clean(); + p2Bar.Clean(); + p3Bar.Clean(); conditions.Clean(); // diff --git a/XCAEA/Signals/xcaea.signaller.class.mq5 b/XCAEA/Signals/xcaea.signaller.class.mq5 index f3dc3e3e..0d535359 100644 --- a/XCAEA/Signals/xcaea.signaller.class.mq5 +++ b/XCAEA/Signals/xcaea.signaller.class.mq5 @@ -454,18 +454,18 @@ class XCXCAEASignaller : XCBase // // Setup Conditions ... - XBoxZone signalBox; - bool hasSignalBox = false; + XBoxZone decisionZone; + bool hasDecisionZone = false; XCAEAConditions conditions; - ENUM_X_DIRECTION signalBoxDir = X_DIRECTION_NONE; + ENUM_X_DIRECTION decisionZoneDir = X_DIRECTION_NONE; // - // Checking Test Signal ... - hasSignalBox = TestDetectSignal( + // Checking Signal's Decision Zone ... + hasDecisionZone = DetectDecisionZone( helper, drawer, - signalBox, - signalBoxDir, + decisionZone, + decisionZoneDir, conditions, zIndex, loopback // @@ -473,22 +473,22 @@ class XCXCAEASignaller : XCBase // // Make Signal Box UnAvailable ... - if (hasSignalBox) + if (hasDecisionZone) { // AddRef( - signalBox, + decisionZone, unAvailableBoxes // ); } // - isBullish = hasSignalBox && - IsBullish(signalBoxDir); + isBullish = hasDecisionZone && + IsBullish(decisionZoneDir); // - isBearish = hasSignalBox && - IsBearish(signalBoxDir); + isBearish = hasDecisionZone && + IsBearish(decisionZoneDir); // result = isBullish || @@ -499,139 +499,17 @@ class XCXCAEASignaller : XCBase // Do What we Want ... barTraker.Waits(); - // - // Draw Signal Box ... - XCBoxObject *iObj; - bool isCreated = helper.poiDrawer.DrawBox( - signalBox, - iObj // - ); - if (isCreated) - { - // - mObjects.Add(iObj); - ZeroMemory(iObj); - - // - // Print("Signal Box ..."); - } - // // Prepare Conditions ... mConditions.symbol = symbol; mConditions.period = period; mConditions.time = zBar.time; - - // - double spread = GetSpread(symbol); - - // - double entry = - isBullish - ? signalBox.upper - : signalBox.lower; - - // - double sl = - isBullish - ? signalBox.lower - : signalBox.upper; - - // - double risk = - isBullish - ? entry - sl - : sl - entry; - risk += spread; - if (risk >= maxAllowedSLDistanceInPoint * points) - { - // - // Fix Risk in Big Distances ... - double hh5 = zBar.FindHighest(5, MODE_HIGH); - double ll5 = zBar.FindLowest(5, MODE_LOW); - - // - double hhll5Delta = hh5 - ll5; - double riskDelta = hhll5Delta / 2; - risk = riskDelta; - } - - // - double rewardTP = risk * tpReward; - - // - double tp = - isBullish - ? entry + rewardTP - : entry - rewardTP; - - // - // Filling ... - mConditions.sl = sl; - mConditions.tp = tp; mConditions.reward = tpReward; - mConditions.pivot = - isBullish - ? sl - : entry; - mConditions.point = - isBullish - ? entry - : sl; - mConditions.dir = signalBoxDir; mConditions.provider = "XCAEA"; - mConditions.signalBox = signalBox; mConditions.setupTime = zBar.time; + mConditions.dir = decisionZoneDir; mConditions.conditions = conditions; - - // - // Targets Preparing ... - if (useTargets) - { - // - // Select RF Rewards ... - if (continuesRFTillTarget) - { - // - double rfReward = 1; - while (rfReward < tpReward) - { - // - double rewardRF = risk * rfReward; - double rfTP = - isBullish - ? entry + rewardRF - : entry - rewardRF; - - // - Add( - rfTP, - mConditions.targets // - ); - - // - rfReward++; - } - } - else - { - // - double rfReward = 2; - - // - double rewardRF = risk * rfReward; - double rfTP = - isBullish - ? entry + rewardRF - : entry - rewardRF; - - // - Add( - rfTP, - mConditions.targets // - ); - } - } + mConditions.decisionZone = decisionZone; } // @@ -644,8 +522,8 @@ class XCXCAEASignaller : XCBase pPBar.Clean(); // - signalBox.Clean(); conditions.Clean(); + decisionZone.Clean(); // return result; @@ -682,6 +560,12 @@ class XCXCAEASignaller : XCBase datetime setupTime = conditions.setupTime; ENUM_X_DIRECTION setupDir = conditions.dir; + // + helper.GetConditions( + conditions.conditions, + barIndex // + ); + // bool isBullish = IsBullish(setupDir); bool isBearish = IsBearish(setupDir); @@ -716,35 +600,61 @@ class XCXCAEASignaller : XCBase // // Checking Trigger Conditions ... - double sls[]; + double sl = 0; + double tp = 0; ENUM_X_DIRECTION triggerDir; + + // + // Checking Trigger Cond 1 ... bool canTriggerCond1 = CanTriggerCond1( helper, - conditions.signalBox, + conditions.decisionZone, triggerDir, - sls, + sl, + tp, + barIndex // + ); + + // + // Checking Trigger Cond 2 ... + bool canTriggerCond2 = CanTriggerCond2( + helper, + conditions.decisionZone, + triggerDir, + sl, + tp, barIndex // ); // // Update Signal Box To ... - conditions.signalBox.to = cTime; + conditions.decisionZone.to = cTime; // - isBullish = IsBullish(triggerDir); - isBearish = IsBearish(triggerDir); - - // - // Try To Draw Signal Box ... XCBoxObject *iObj; - helper.poiDrawer.DrawBox( - conditions.signalBox, + bool has = helper.poiDrawer.DrawBox( + conditions.decisionZone, iObj // ); + if (has) + { + mObjects.Add(iObj); + } ZeroMemory(iObj); // - result = canTriggerCond1; + // Summarizing Result ... + result = + canTriggerCond1 || + canTriggerCond2; + + // + isBullish = result && + IsBullish(triggerDir); + isBearish = result && + IsBearish(triggerDir); + + // if (result) { // @@ -758,19 +668,35 @@ class XCXCAEASignaller : XCBase conditions.entry = entry; // - double slsMax = GetMax(sls); - double slsMin = GetMin(sls); - double sl = isBullish - ? slsMin - : slsMax; + if (tp > 0.0) + { + // + Add( + tp, + conditions.targets // + ); + } // double risk = MathAbs(entry - sl); - double tp = + double reward = (risk * conditions.reward); + tp = isBullish - ? entry + (risk * conditions.reward) - : entry - (risk * conditions.reward); - + ? entry + reward + : entry - reward; + + // + // Handling RF ... + double rfReward = risk * 1.85; + double rfPrice = + isBullish + ? entry + rfReward + : entry - rfReward; + Add( + rfPrice, + conditions.targets // + ); + // conditions.sl = sl; conditions.tp = tp; @@ -788,20 +714,30 @@ class XCXCAEASignaller : XCBase if (!result) { // + // Check Box Age ... int age = conditions.GetSetupAge(); bool has = age <= maxAllowedSetupAge; if (!has) { conditions.Clean(); } + + // + // Check Box Price ... + has = IsBoxBreaked( + helper, + conditions.decisionZone, + barIndex // + ); + if (has) + { + conditions.Clean(); + } } // // Cleanup ... - // - Clean(sls); - // return result; }