diff --git a/XCAEA/Libraries/xcaea.trigger.block.lib.mq5 b/XCAEA/Libraries/xcaea.trigger.block.lib.mq5 index be28d947..addb4fb9 100644 --- a/XCAEA/Libraries/xcaea.trigger.block.lib.mq5 +++ b/XCAEA/Libraries/xcaea.trigger.block.lib.mq5 @@ -198,6 +198,112 @@ struct XCAEATriggerBlockConfiguration filterBasedOnTrend = true; } + // + void ConfigureSarRsiAdxFilter() + { + // + ConfigureFullFilter(); + + // + filterBasedOnTrend = false; + } + + // + void ConfigureSarRsiTrendFilter() + { + // + ConfigureFullFilter(); + + // + filterBasedOnADX = false; + } + + // + void ConfigureSarAdxTrendFilter() + { + // + ConfigureFullFilter(); + + // + filterBasedOnRSI = false; + } + + // + void ConfigureRsiAdxTrendFilter() + { + // + ConfigureFullFilter(); + + // + filterBasedOnSar = false; + } + + // + void ConfigureSarRsiFilter() + { + // + ConfigureFullFilter(); + + // + filterBasedOnADX = false; + filterBasedOnTrend = false; + } + + // + void ConfigureSarAdxFilter() + { + // + ConfigureFullFilter(); + + // + filterBasedOnRSI = false; + filterBasedOnTrend = false; + } + + // + void ConfigureSarTrendFilter() + { + // + ConfigureFullFilter(); + + // + filterBasedOnRSI = false; + filterBasedOnADX = false; + } + + // + void ConfigureRsiAdxFilter() + { + // + ConfigureFullFilter(); + + // + filterBasedOnSar = false; + filterBasedOnTrend = false; + } + + // + void ConfigureRsiTrendFilter() + { + // + ConfigureFullFilter(); + + // + filterBasedOnSar = false; + filterBasedOnADX = false; + } + + // + void ConfigureAdxTrendFilter() + { + // + ConfigureFullFilter(); + + // + filterBasedOnSar = false; + filterBasedOnRSI = false; + } + // }; @@ -359,12 +465,12 @@ bool DetectTriggerBlock( // bool isBullish = - has && + result && triggerBlock.IsBullish(); // bool isBearish = - has && + result && triggerBlock.IsBearish(); // @@ -382,7 +488,7 @@ bool DetectTriggerBlock( iDir = Opposit(triggerBlock.dir); // - has = + result = iDir == p3Bar.GetDirection() || iDir == p4Bar.GetDirection(); if (!result) @@ -693,7 +799,7 @@ bool DetectTriggerBlock( // // Here we Ensure which have a Valid Zone using Different Applied Validations ... - // from now we are Going to Filtered Validate Zones ... + // from now we are Going to Filterd Validate Zones ... // // Check Exists Filters or not ... @@ -778,21 +884,21 @@ bool DetectTriggerBlock( // Summarize Filtering ... // - bool isBullishFiltered = + bool isBullishFilterd = isBullish && (isCSarSwitchedToBullish || isPSarSwitchedToBullish); // - bool isBearishFiltered = + bool isBearishFilterd = isBearish && (isCSarSwitchedToBearish || isPSarSwitchedToBearish); // result = - isBullishFiltered || - isBearishFiltered; + isBullishFilterd || + isBearishFilterd; if (!result) { // @@ -963,7 +1069,7 @@ bool DetectTriggerBlock( // Summarize Filtering ... // - bool isBullishFiltered = + bool isBullishFilterd = isBullish && ( // @@ -991,7 +1097,7 @@ bool DetectTriggerBlock( ); // - bool isBearishFiltered = + bool isBearishFilterd = isBearish && ( // @@ -1020,8 +1126,8 @@ bool DetectTriggerBlock( // result = - isBullishFiltered || - isBearishFiltered; + isBullishFilterd || + isBearishFilterd; if (!result) { // @@ -1201,7 +1307,7 @@ bool DetectTriggerBlock( // Summarize Filtering ... // - bool isBullishFiltered = + bool isBullishFilterd = isBullish && ( // @@ -1223,7 +1329,7 @@ bool DetectTriggerBlock( ); // - bool isBearishFiltered = + bool isBearishFilterd = isBearish && ( // @@ -1246,8 +1352,8 @@ bool DetectTriggerBlock( // result = - isBullishFiltered || - isBearishFiltered; + isBullishFilterd || + isBearishFilterd; if (!result) { // @@ -1384,7 +1490,7 @@ bool DetectTriggerBlock( // Summarize Filtering ... // - bool isBullishFiltered = + bool isBullishFilterd = isBullish && ( // @@ -1406,7 +1512,7 @@ bool DetectTriggerBlock( ); // - bool isBearishFiltered = + bool isBearishFilterd = isBearish && ( // @@ -1429,8 +1535,8 @@ bool DetectTriggerBlock( // result = - isBullishFiltered || - isBearishFiltered; + isBullishFilterd || + isBearishFilterd; if (!result) { // @@ -1457,6 +1563,14 @@ bool DetectTriggerBlock( // result = triggerBlock.IsValid(); + if (result) + { + // + triggerBlock.type = + isBullish + ? ToString(XCA_TRIGGER_BULL) + : ToString(XCA_TRIGGER_BEAR); + } // // Cleanup Resources ... diff --git a/XCAEA/Signals/xcaea.signaller.class.mq5 b/XCAEA/Signals/xcaea.signaller.class.mq5 index 7ae8e9c9..799e41fd 100644 --- a/XCAEA/Signals/xcaea.signaller.class.mq5 +++ b/XCAEA/Signals/xcaea.signaller.class.mq5 @@ -196,6 +196,7 @@ class XCXCAEASignaller : XCBase int zIndex = 0; bool has = false; int loopback = 10; + int cIndex = zIndex + 1; bool isBullish = false; bool isBearish = false; @@ -244,7 +245,7 @@ class XCXCAEASignaller : XCBase // // Check Decision Zone Detection Based On Several Signalling ... - + // // Analyse DecisionZone ... // In this Used Case we fond an Analyse TF OB @@ -277,7 +278,297 @@ class XCXCAEASignaller : XCBase // In this Used Case we found a Tigger Block and use it // for Triggering ... if (!hasDecisionZone && - allowTriggerBlockDecisionZoneSignalling) { + allowTriggerBlockDecisionZoneSignalling) + { + // + int pushers = 0; + + // + // We Can Detect Multiple Decision Zones ... + XBoxZone tmpZone; + XCAEATriggerBlockConfiguration config; + + // + // Full Filteres ... + config.ConfigureFullFilter(); + bool hasFullFiltered = DetectTriggerBlock( + tmpZone, + conditions, + helper, + config, + zIndex, + loopback // + ); + if (hasFullFiltered) + { + // + pushers++; + + // + if (!decisionZone.IsValid()) + { + decisionZone = tmpZone; + } + } + + // + tmpZone.Clean(); + config.ConfigureSarRsiAdxFilter(); + bool hasSarRsiAdxFiltered = DetectTriggerBlock( + tmpZone, + conditions, + helper, + config, + zIndex, + loopback // + ); + if (hasSarRsiAdxFiltered) + { + // + pushers++; + + // + if (!decisionZone.IsValid()) + { + decisionZone = tmpZone; + } + } + + // + tmpZone.Clean(); + config.ConfigureSarRsiTrendFilter(); + bool hasSarRsiTrendFiltered = DetectTriggerBlock( + tmpZone, + conditions, + helper, + config, + zIndex, + loopback // + ); + if (hasSarRsiTrendFiltered) + { + // + pushers++; + + // + if (!decisionZone.IsValid()) + { + decisionZone = tmpZone; + } + } + + // + tmpZone.Clean(); + config.ConfigureSarAdxTrendFilter(); + bool hasSarAdxTrendFiltered = DetectTriggerBlock( + tmpZone, + conditions, + helper, + config, + zIndex, + loopback // + ); + if (hasSarAdxTrendFiltered) + { + // + pushers++; + + // + if (!decisionZone.IsValid()) + { + decisionZone = tmpZone; + } + } + + // + tmpZone.Clean(); + config.ConfigureRsiAdxTrendFilter(); + bool hasRsiAdxTrendFiltered = DetectTriggerBlock( + tmpZone, + conditions, + helper, + config, + zIndex, + loopback // + ); + if (hasRsiAdxTrendFiltered) + { + // + pushers++; + + // + if (!decisionZone.IsValid()) + { + decisionZone = tmpZone; + } + } + + // + tmpZone.Clean(); + config.ConfigureSarRsiFilter(); + bool hasSarRsiFiltered = DetectTriggerBlock( + tmpZone, + conditions, + helper, + config, + zIndex, + loopback // + ); + if (hasSarRsiFiltered) + { + // + pushers++; + + // + if (!decisionZone.IsValid()) + { + decisionZone = tmpZone; + } + } + + // + tmpZone.Clean(); + config.ConfigureSarAdxFilter(); + bool hasSarAdxFiltered = DetectTriggerBlock( + tmpZone, + conditions, + helper, + config, + zIndex, + loopback // + ); + if (hasSarAdxFiltered) + { + // + pushers++; + + // + if (!decisionZone.IsValid()) + { + decisionZone = tmpZone; + } + } + + // + tmpZone.Clean(); + config.ConfigureSarTrendFilter(); + bool hasSarTrendFiltered = DetectTriggerBlock( + tmpZone, + conditions, + helper, + config, + zIndex, + loopback // + ); + if (hasSarTrendFiltered) + { + // + pushers++; + + // + if (!decisionZone.IsValid()) + { + decisionZone = tmpZone; + } + } + + // + tmpZone.Clean(); + config.ConfigureRsiAdxFilter(); + bool hasRsiAdxFiltered = DetectTriggerBlock( + tmpZone, + conditions, + helper, + config, + zIndex, + loopback // + ); + if (hasRsiAdxFiltered) + { + // + pushers++; + + // + if (!decisionZone.IsValid()) + { + decisionZone = tmpZone; + } + } + + // + tmpZone.Clean(); + config.ConfigureRsiTrendFilter(); + bool hasRsiTrendFiltered = DetectTriggerBlock( + tmpZone, + conditions, + helper, + config, + zIndex, + loopback // + ); + if (hasRsiTrendFiltered) + { + // + pushers++; + + // + if (!decisionZone.IsValid()) + { + decisionZone = tmpZone; + } + } + + // + tmpZone.Clean(); + config.ConfigureAdxTrendFilter(); + bool hasAdxTrendFiltered = DetectTriggerBlock( + tmpZone, + conditions, + helper, + config, + zIndex, + loopback // + ); + if (hasAdxTrendFiltered) + { + // + pushers++; + + // + if (!decisionZone.IsValid()) + { + decisionZone = tmpZone; + } + } + + // + hasDecisionZone = + hasSarRsiFiltered || + hasSarAdxFiltered || + hasRsiAdxFiltered || + hasSarTrendFiltered || + hasRsiTrendFiltered || + hasAdxTrendFiltered || + hasSarRsiAdxFiltered || + hasSarRsiTrendFiltered || + hasSarAdxTrendFiltered || + hasRsiAdxTrendFiltered; + + // + if (hasDecisionZone) + { + // + drawer.DrawBox( + decisionZone, + cTime, + false, // Draw Middle ... + true // Ignore Type ... + ); + + // + Print(ToString(decisionZone.dir) + " Trigger Block Detected (" + ToString(pushers) + ") ..."); + } + // } @@ -285,6 +576,9 @@ class XCXCAEASignaller : XCBase // Make Signal Box UnAvailable ... if (hasDecisionZone) { + // + decisionZoneDir = decisionZone.dir; + // AddRef( decisionZone, @@ -428,152 +722,185 @@ class XCXCAEASignaller : XCBase int fromIDX = conditions.decisionZone.FromIndex(); // - // Check Box Size ... - double maxAllowedBoxRange = 400; - double range = conditions.decisionZone.GetRange(); - bool isTooLarge = range > (maxAllowedBoxRange * points); - double decisionMiddlePrice = conditions.decisionZone.GetMid(); + bool isAnalyseSignalled = + conditions.decisionZone.period == analyseHelper.GetPeriod(); // - // Draw Decision Zone ... - if (allowDraws) - { - // - drawer.DrawBox( - conditions.decisionZone, - cTime, - true, // Draw Middle Line ... - true // Ignore Type ... - ); - } + ENUM_XCAEA_TIGGER_TYPE decisionZoneType = GetType(conditions.decisionZone.type); + bool isTriggerBlockSignalled = IsValid(decisionZoneType); // - // Detect Required Pivots ... - XBoxZone decisionPivots[]; - ENUM_XCA_PIVOTS allowedTypes[]; - if (isBullish) + // Looking for Analyse Helper Triggers ... + if (isAnalyseSignalled && + allowAnalyseDecisionZoneSignalling) { // - Add( - XCA_OB_BULL, - allowedTypes // - ); - } - else - { - // - Add( - XCA_OB_BEAR, - allowedTypes // - ); - } - Add( - XCA_PEAK, - allowedTypes // - ); - Add( - XCA_VALE, - allowedTypes // - ); - int decisionPivotsCount = detector.FillPivots( - conditions.decisionZone, - decisionPivots, - unavailables, - allowedTypes, - cTime // - ); + // Trigger Analyse Signal ... - // - // Draw Pivots of Decision Zone only when - // it's Too Large ... - if (false && - allowDraws && - isTooLarge && - HasChild(decisionPivots)) - { // - for (int i = 0; i < decisionPivotsCount; i++) + // Check Box Size ... + double maxAllowedBoxRange = 400; + double range = conditions.decisionZone.GetRange(); + bool isTooLarge = range > (maxAllowedBoxRange * points); + double decisionMiddlePrice = conditions.decisionZone.GetMid(); + + // + // Detect Required Pivots ... + XBoxZone decisionPivots[]; + ENUM_XCA_PIVOTS allowedTypes[]; + if (isBullish) { // - drawer.DrawBox( - decisionPivots[i], - cTime, - false, // Draw Middle ... - true // Ignore Type ... + Add( + XCA_OB_BULL, + allowedTypes // ); } - } - - // - // Define a Temparory Objects - // Array instance for Holding Drawn Objects ... - CArrayObj *iObjects; - iObjects = new CArrayObj(); - - // - // Check Different Trigger Conditions ... - - // - // Checking Trigger Cond 0 ... - bool canTriggerCond0 = false; - - // - // Checking Trigger Cond 1 ... - bool canTriggerCond1 = false; - if (isTooLarge) - { - // - canTriggerCond1 = CanTriggerCond1( - helper, + else + { + // + Add( + XCA_OB_BEAR, + allowedTypes // + ); + } + Add( + XCA_PEAK, + allowedTypes // + ); + Add( + XCA_VALE, + allowedTypes // + ); + int decisionPivotsCount = detector.FillPivots( conditions.decisionZone, decisionPivots, - triggerDir, - sl, - targets, - allowDraws, - iObjects, - barIndex // + unavailables, + allowedTypes, + cTime // ); - } - // - // Checking Trigger Cond 2 ... - bool canTriggerCond2 = false; - if (!isTooLarge) + // + // Draw Pivots of Decision Zone only when + // it's Too Large ... + if (false && + allowDraws && + isTooLarge && + HasChild(decisionPivots)) + { + // + for (int i = 0; i < decisionPivotsCount; i++) + { + // + drawer.DrawBox( + decisionPivots[i], + cTime, + false, // Draw Middle ... + true // Ignore Type ... + ); + } + } + + // + // Define a Temparory Objects + // Array instance for Holding Drawn Objects ... + CArrayObj *iObjects; + iObjects = new CArrayObj(); + + // + // Check Different Trigger Conditions ... + + // + // Checking Trigger Cond 0 ... + bool canTriggerCond0 = false; + + // + // Checking Trigger Cond 1 ... + bool canTriggerCond1 = false; + if (isTooLarge) + { + // + canTriggerCond1 = CanTriggerCond1( + helper, + conditions.decisionZone, + decisionPivots, + triggerDir, + sl, + targets, + allowDraws, + iObjects, + barIndex // + ); + } + + // + // Checking Trigger Cond 2 ... + bool canTriggerCond2 = false; + if (!isTooLarge) + { + // + canTriggerCond2 = CanTriggerCond2( + helper, + conditions.decisionZone, + decisionPivots, + triggerDir, + sl, + targets, + allowDraws, + iObjects, + barIndex // + ); + } + + // + // Checking Trigger Cond 3 ... + bool canTriggerCond3 = false; + + // + // Adding Drawn Objects to Drawn Stores ... + for (int i = 0; i < iObjects.Total(); i++) + { + mObjects.Add(iObjects.At(i)); + } + + // + // Summarizing Result ... + result = + canTriggerCond0 || + canTriggerCond1 || + canTriggerCond2 || + canTriggerCond3; + } + else if (isTriggerBlockSignalled && + allowTriggerBlockDecisionZoneSignalling) { // - canTriggerCond2 = CanTriggerCond2( - helper, - conditions.decisionZone, - decisionPivots, - triggerDir, - sl, - targets, - allowDraws, - iObjects, - barIndex // - ); + // Trigger TRIGGER Block Signal ... + + // + // since we have to Trigger all TRIGGER Block's Signals + // exactly on Setting ups ... + result = isBullish || + isBearish; + if (result) + { + // + triggerDir = + isBullish + ? X_DIRECTION_BULLISH + : X_DIRECTION_BEARISH; + + // + sl = + isBullish + ? conditions.decisionZone.lower + : conditions.decisionZone.upper; + + // + conditions.reward = 2; + } } - // - // Checking Trigger Cond 3 ... - bool canTriggerCond3 = false; - - // - // Adding Drawn Objects to Drawn Stores ... - for (int i = 0; i < iObjects.Total(); i++) - { - mObjects.Add(iObjects.At(i)); - } - - // - // Summarizing Result ... - result = - canTriggerCond0 || - canTriggerCond1 || - canTriggerCond2 || - canTriggerCond3; - // isBullish = result && IsBullish(triggerDir); @@ -584,6 +911,19 @@ class XCXCAEASignaller : XCBase // Configure Conditions for Preparing Signal ... if (result) { + // + // Draw Decision Zone ... + if (allowDraws) + { + // + drawer.DrawBox( + conditions.decisionZone, + cTime, + true, // Draw Middle Line ... + true // Ignore Type ... + ); + } + // // Reconfigure Position TP/SL Entry and etc ...