diff --git a/Classes/x-saherelm.x-bar.analyser.class.mq5 b/Classes/x-saherelm.x-bar.analyser.class.mq5 index cd286baf..cb9988b4 100644 --- a/Classes/x-saherelm.x-bar.analyser.class.mq5 +++ b/Classes/x-saherelm.x-bar.analyser.class.mq5 @@ -573,7 +573,7 @@ class XCBarAnalyser : public XCBase /** * Check Specified Bar Has Bullish Pattern or not ... - * + * * @param bar: XOHCL instance, Specified Bar ... * @param loopback: Integer, Loopback Length for Patterns ... * @param verifications: Integer, Number of Given Verifications ... @@ -581,7 +581,7 @@ class XCBarAnalyser : public XCBase * @param checkMorningStar: Boolean, Specified Check Morning Star Pattern ... * @param checkBullishMarubozu: Boolean, Specified Check Marubozu Pattern ... * @param checkBullishEngulfing: Boolean, Specified Check Engulfing Pattern ... - * + * * @return ( bool ) */ bool HasBullishPattern( @@ -683,7 +683,7 @@ class XCBarAnalyser : public XCBase /** * Check Specified Bar Has Bearish Pattern or not ... - * + * * @param bar: XOHCL instance, Specified Bar ... * @param loopback: Integer, Loopback Length for Patterns ... * @param verifications: Integer, Number of Given Verifications ... @@ -691,7 +691,7 @@ class XCBarAnalyser : public XCBase * @param checkEveningStar: Boolean, Specified Check Evening Star Pattern ... * @param checkBearishMarubozu: Boolean, Specified Check Marubozu Pattern ... * @param checkBearishEngulfing: Boolean, Specified Check Engulfing Pattern ... - * + * * @return ( bool ) */ bool HasBearishPattern( @@ -1220,7 +1220,7 @@ class XCBarAnalyser : public XCBase * @param bar: XOHCL instance ... * @param dir: ENUM_X_DIRECTION member ... * @param extend: Integer ... - * @param bodyPercent: Double ... + * @param shadowPercent: Double ... * * @return ( bool ) */ @@ -1298,6 +1298,110 @@ class XCBarAnalyser : public XCBase return result; } + /** + * Check Specified Bar is Engulfing Bar or not ... + * + * @param bar: XOHCL instance ... + * @param dir: ENUM_X_DIRECTION member ... + * @param extend: Integer ... + * @param bodyPercent: Double ... + * + * @return ( bool ) + */ + bool IsEngulfBar( + XOHCL &bar, + ENUM_X_DIRECTION &dir, + int extend = 1, + double bodyPercent = 60 // + ) + { + // + bool result = false; + + // + if (extend < 0) + { + extend = 0; + } + + // + if (bodyPercent < 50) + { + bodyPercent = 50; + } + + // + dir = X_DIRECTION_NONE; + + // + result = bar.IsValid() && + bar.Index() > 0; + if (!result) + { + return result; + } + + // + // Previous Bar ... + XOHCL pBar; + result = bar.GetPreviousBar(pBar); + if (!result) + { + return result; + } + + // + if (extend > 0) + { + // + result = IsExtended( + pBar, + extend // + ); + + // + if (!result) + { + return result; + } + } + + // + // Check Engulfig ... + result = + bar.GetUp() > pBar.GetUp() && + bar.GetDown() < pBar.GetDown(); + if (!result) + { + return result; + } + + // + // Check Engulfing Direction ... + bool isBullishEngulfed = + pBar.IsBearish() && + bar.IsBullish(); + bool isBearishEngulfed = + pBar.IsBullish() && + bar.IsBearish(); + + // + result = isBullishEngulfed || + isBearishEngulfed; + if (!result) + { + return result; + } + + // + dir = isBullishEngulfed + ? X_DIRECTION_BULLISH + : X_DIRECTION_BEARISH; + + // + return result; + } + // // Support and Resistance Zones ... diff --git a/Indicators/x-saherelm.xpv.mq5 b/Indicators/x-saherelm.xpv.mq5 index 42ca5d68..022910f5 100644 --- a/Indicators/x-saherelm.xpv.mq5 +++ b/Indicators/x-saherelm.xpv.mq5 @@ -508,7 +508,10 @@ int OnCalculate( for (int i = limit - 1; i >= 0 && !IsStopped(); i--) { // - CalculateBuffers(i); + if (i <= 1000) + { + CalculateBuffers(i); + } } // diff --git a/X121SMCEA/Strategy/x-121.smc.test.strategy.class.mq5 b/X121SMCEA/Strategy/x-121.smc.test.strategy.class.mq5 index 3af2a678..8dbc2c16 100644 --- a/X121SMCEA/Strategy/x-121.smc.test.strategy.class.mq5 +++ b/X121SMCEA/Strategy/x-121.smc.test.strategy.class.mq5 @@ -181,31 +181,147 @@ class XCX121SMCTestStrategy : public XCX121SMCBaseStrategy // // Check Momentum Bar ... - ENUM_X_DIRECTION momentumBarDir; + ENUM_X_DIRECTION momentumCBarDir; bool isCMomentumBar = mBarAnalyser.IsMomentumBar( cBar, - momentumBarDir // + momentumCBarDir // ); bool isCBullishMomentumBar = isCMomentumBar && - IsBullish(momentumBarDir); + IsBullish(momentumCBarDir); bool isCBearishMomentumBar = isCMomentumBar && - IsBearish(momentumBarDir); + IsBearish(momentumCBarDir); + + // + // Check Momentum Bar ... + ENUM_X_DIRECTION momentumPBarDir; + bool isPMomentumBar = mBarAnalyser.IsMomentumBar( + pBar, + momentumPBarDir // + ); + bool isPBullishMomentumBar = + isPMomentumBar && + IsBullish(momentumPBarDir); + bool isPBearishMomentumBar = + isPMomentumBar && + IsBearish(momentumPBarDir); // // Check Rejection Bar ... - ENUM_X_DIRECTION rejectionBarDir; + ENUM_X_DIRECTION rejectionCBarDir; bool isCRejectionBar = mBarAnalyser.IsRejectionBar( cBar, - rejectionBarDir // + rejectionCBarDir // ); bool isCBullishRejectionBar = isCRejectionBar && - IsBullish(rejectionBarDir); + IsBullish(rejectionCBarDir); bool isCBearishRejectionBar = isCRejectionBar && - IsBearish(rejectionBarDir); + IsBearish(rejectionCBarDir); + + // + // Check Rejection Bar ... + ENUM_X_DIRECTION rejectionPBarDir; + bool isPRejectionBar = mBarAnalyser.IsRejectionBar( + pBar, + rejectionPBarDir // + ); + bool isPBullishRejectionBar = + isPRejectionBar && + IsBullish(rejectionPBarDir); + bool isPBearishRejectionBar = + isPRejectionBar && + IsBearish(rejectionPBarDir); + + // + // Check Engulfing ... + ENUM_X_DIRECTION engulfCBarDir; + bool isCEngulfed = mBarAnalyser.IsEngulfBar( + cBar, + engulfCBarDir // + ); + bool isCBullishEngulfed = + isCEngulfed && + IsBullish(engulfCBarDir); + bool isCBearishEngulfed = + isCEngulfed && + IsBearish(engulfCBarDir); + + // + // Check Engulfing ... + ENUM_X_DIRECTION engulfPBarDir; + bool isPEngulfed = mBarAnalyser.IsEngulfBar( + pBar, + engulfPBarDir // + ); + bool isPBullishEngulfed = + isPEngulfed && + IsBullish(engulfPBarDir); + bool isPBearishEngulfed = + isPEngulfed && + IsBearish(engulfPBarDir); + + // + bool isCRMEBullish = + // + isCBullishEngulfed + // + || + // + isCBullishMomentumBar + // + || + // + isCBullishRejectionBar + // + ; + + // + bool isPRMEBullish = + // + isPBullishEngulfed + // + || + // + isPBullishMomentumBar + // + || + // + isPBullishRejectionBar + // + ; + + // + bool isCRMEBearish = + // + isCBearishEngulfed + // + || + // + isCBearishMomentumBar + // + || + // + isCBearishRejectionBar + // + ; + + // + bool isPRMEBearish = + // + isPBearishEngulfed + // + || + // + isPBearishMomentumBar + // + || + // + isPBearishRejectionBar + // + ; // bool isSpreadPassed = IsSpreadPass(); @@ -263,13 +379,17 @@ class XCX121SMCTestStrategy : public XCX121SMCBaseStrategy // // Price Close Over Pivot's High ... cBar.IsBullish() && - cBar.close > lastPivot.upper + cBar.close > lastPivot.upper && + (pBar.close < lastPivot.upper || + pBar.low < lastPivot.upper) // : // // Price Must Close Under Pivots Low ... cBar.IsBearish() && - cBar.close < lastPivot.lower + cBar.close < lastPivot.lower && + (pBar.close > lastPivot.lower || + pBar.high > lastPivot.lower) // ; bool hasCHOCH = @@ -278,25 +398,50 @@ class XCX121SMCTestStrategy : public XCX121SMCBaseStrategy // // Price Close Under Pivot's Low ... cBar.IsBearish() && - cBar.close < lastPivot.lower + cBar.close < lastPivot.lower && + (pBar.close > lastPivot.lower || + pBar.high > lastPivot.lower) // : // // Price Must Close Over Pivots High ... cBar.IsBullish() && - cBar.close > lastPivot.upper + cBar.close > lastPivot.upper && + (pBar.close < lastPivot.upper || + pBar.low < lastPivot.upper) // ; // + // BOS Signals ... + bool has_BOS_Long = false; + bool has_BOS_Short = false; + + // + // CHOCH Signals ... + bool has_CHOCH_Long = false; + bool has_CHOCH_Short = false; + + // + // SAR Signals ... + bool has_SAR_Long = false; + bool has_SAR_Short = false; + + // + // PULLBACK Signals ... + bool has_PULLBK_Long = false; + bool has_PULLBK_Short = false; + + // + // Detect BOS Or CHOCH Signals ... if (hasBOS || hasCHOCH) { // // Do on CHOCH ... if (hasCHOCH) { - - hasLong = + // + has_CHOCH_Long = // !isOrderFlowBullish && cBar.IsBullish() && @@ -305,7 +450,7 @@ class XCX121SMCTestStrategy : public XCX121SMCBaseStrategy conditions.xchsarConditions.cSars[0] < cBar.low // ; - if (hasLong) + if (has_CHOCH_Long) { // provider = "CHOCH-Long"; @@ -313,7 +458,7 @@ class XCX121SMCTestStrategy : public XCX121SMCBaseStrategy } // - hasShort = + has_CHOCH_Short = // isOrderFlowBullish && cBar.IsBearish() && @@ -322,12 +467,15 @@ class XCX121SMCTestStrategy : public XCX121SMCBaseStrategy conditions.xchsarConditions.cSars[0] > cBar.high // ; - if (hasShort) + if (has_CHOCH_Short) { // provider = "CHOCH-Short"; selectedSL = cBar.high; } + + // + mLastCHOCHOn = TimeCurrent(); } // @@ -335,18 +483,17 @@ class XCX121SMCTestStrategy : public XCX121SMCBaseStrategy if (hasBOS) { // - hasLong = + has_BOS_Long = // isOrderFlowBullish && + isCRMEBullish && cBar.IsBullish() && - (isCBullishMomentumBar || - isCBullishRejectionBar) && conditions.xchsarConditions.cSars[0] < cBar.low // ; // - if (hasLong) + if (has_BOS_Long) { // provider = "BOS-Long"; @@ -354,23 +501,152 @@ class XCX121SMCTestStrategy : public XCX121SMCBaseStrategy } // - hasShort = + has_BOS_Short = // !isOrderFlowBullish && + isCRMEBearish && cBar.IsBearish() && - (isCBearishMomentumBar || - isCBearishRejectionBar) && conditions.xchsarConditions.cSars[0] > cBar.high // ; - if (hasShort) + if (has_BOS_Short) { // provider = "BOS-Short"; selectedSL = cBar.high; } + + // + mLastBOSOn = TimeCurrent(); } } + else + { + // + // Check PSar is Equals to Peak or Vale ... + bool isSAREqualsToPeak = + conditions.xchsarConditions.cSars[0] == conditions.xpvConditions.peaks[1]; + bool isSAREqualsToVale = + conditions.xchsarConditions.cSars[0] == conditions.xpvConditions.vales[1]; + + // + has_SAR_Long = + // + isSAREqualsToVale && + isOrderFlowBullish && + isPSarInDirectionOfOrderFlow + // + ; + if (has_SAR_Long) + { + // + provider = "SAR_Long"; + selectedSL = conditions.xchsarConditions.cSars[0]; + } + + // + has_SAR_Short = + // + isSAREqualsToPeak && + !isOrderFlowBullish && + isPSarInDirectionOfOrderFlow + // + ; + if (has_SAR_Short) + { + // + provider = "SAR_Short"; + selectedSL = conditions.xchsarConditions.cSars[0]; + } + + // + // Check PULLBK Conditions ... + + // + has_PULLBK_Long = + // + isCRMEBullish && + isPSarInDirectionOfOrderFlow && + (cBar.low < conditions.x3maConditions.fasts[0] && + cBar.GetDown() > conditions.x3maConditions.fasts[0]) && + !(pBar.low < conditions.x3maConditions.fasts[1] && + pBar.GetDown() > conditions.x3maConditions.fasts[1]) + // + ; + if (has_PULLBK_Long) + { + // + provider = "PULLBK-Long"; + selectedSL = cBar.low; + } + + // + has_PULLBK_Short = + // + isCRMEBearish && + isPSarInDirectionOfOrderFlow && + (cBar.high > conditions.x3maConditions.fasts[0] && + cBar.GetUp() < conditions.x3maConditions.fasts[0]) && + !(pBar.high > conditions.x3maConditions.fasts[1] && + pBar.GetUp() < conditions.x3maConditions.fasts[1]) + // + ; + if (has_PULLBK_Short) + { + // + provider = "PULLBK-Short"; + selectedSL = cBar.high; + } + } + + // + // Combine all Signals Conditions ... + + // + hasLong = + // + has_BOS_Long + // + || + // + has_CHOCH_Long + // // + // || + // // + // // has_SAR_Long + // // + // || + // // + // has_PULLBK_Long + // // + // || + // + // false + // + ; + + // + hasShort = + // + has_BOS_Short + // + || + // + has_CHOCH_Short + // // + // || + // // + // // has_SAR_Short + // // + // || + // // + // has_PULLBK_Short + // // + // || + // + // false + // + ; // result = hasLong || @@ -428,6 +704,7 @@ class XCX121SMCTestStrategy : public XCX121SMCBaseStrategy // Print("PRV: ", provider); + RedrawOrderFlow(); ClearDraws(); // @@ -568,6 +845,11 @@ class XCX121SMCTestStrategy : public XCX121SMCBaseStrategy XPVPivot mOrderFlow[]; ENUM_X_DIRECTION mOrderFlowDir; + // + // Holds Last CHOCH and BOS time ... + datetime mLastBOSOn; + datetime mLastCHOCHOn; + // // Actions ...