diff --git a/Documents/BKP/tmp.codes.mq5 b/Documents/BKP/tmp.codes.mq5 index a343086d..34a47677 100644 --- a/Documents/BKP/tmp.codes.mq5 +++ b/Documents/BKP/tmp.codes.mq5 @@ -350,3 +350,208 @@ bool isHCMaSwitchedToBearish = isHCMaBearish && !isPHCMaBearish; + +/////////////////////////////////////////////////////////////////////////////// + + // + // HK Signal Bar ... + + // + double iHKSOpen = hkSBarOpenBuffer[barIndex]; + double iHKSClose = hkSBarCloseBuffer[barIndex]; + + // + double iHKSMax = MathMax(iHKSOpen, iHKSClose); + double iHKSMin = MathMin(iHKSOpen, iHKSClose); + + // + bool isHKSBullish = hkSBarOpenBuffer[barIndex] < hkSBarCloseBuffer[barIndex]; + bool isPHKSBullish = hkSBarOpenBuffer[barIndex + 1] < hkSBarCloseBuffer[barIndex + 1]; + + // + bool isHKSBearish = hkSBarOpenBuffer[barIndex] > hkSBarCloseBuffer[barIndex]; + bool isPHKSBearish = hkSBarOpenBuffer[barIndex + 1] > hkSBarCloseBuffer[barIndex + 1]; + + // + bool isHKSSwitchedToBullish = + isHKSBullish && + !isPHKSBullish; + + // + bool isHKSSwitchedToBearish = + isHKSBearish && + !isPHKSBearish; + + // + // TREND ... + + // + double iTrend = trendBuffer[barIndex]; + bool isTrendBullish = trendStateBuffer[barIndex] > 0; + bool isTrendBearish = trendStateBuffer[barIndex] < 0; + bool isTrendSwitchedToBullish = + trendStateBuffer[barIndex] > 0 && + trendStateBuffer[barIndex + 1] <= 0; + bool isTrendSwitchedToBearish = + trendStateBuffer[barIndex] < 0 && + trendStateBuffer[barIndex + 1] >= 0; + + // + // RSI ... + + // + bool isRSIOverOB = rsiBuffer[barIndex] > rsiOBLevel; + bool isPRSIOverOB = rsiBuffer[barIndex + 1] > rsiOBLevel; + + // + bool isRSIUnderOB = rsiBuffer[barIndex] < rsiOBLevel; + bool isPRSIUnderOB = rsiBuffer[barIndex + 1] < rsiOBLevel; + + // + bool isRSICrossedOverOB = + isRSIOverOB && + !isPRSIOverOB; + + // + bool isRSICrossedUnderOB = + isRSIUnderOB && + !isPRSIUnderOB; + + // + bool isRSIOverOS = rsiBuffer[barIndex] > rsiOSLevel; + bool isPRSIOverOS = rsiBuffer[barIndex + 1] > rsiOSLevel; + + // + bool isRSIUnderOS = rsiBuffer[barIndex] < rsiOSLevel; + bool isPRSIUnderOS = rsiBuffer[barIndex + 1] < rsiOSLevel; + + // + bool isRSICrossedOverOS = + isRSIOverOS && + !isPRSIOverOS; + + // + bool isRSICrossedUnderOS = + isRSIUnderOS && + !isPRSIUnderOS; + + // + // ADX ... + + // + bool isADXOverThreshold = adxBuffer[barIndex] > adxThreshold; + bool isPADXOverThreshold = adxBuffer[barIndex + 1] > adxThreshold; + + // + bool isADXUnderThreshold = adxBuffer[barIndex] < adxThreshold; + bool isPADXUnderThreshold = adxBuffer[barIndex + 1] < adxThreshold; + + // + bool isADXCrossedOverThreshold = + isADXOverThreshold && + !isPADXOverThreshold; + + // + bool isADXCrossedUnderThreshold = + isADXUnderThreshold && + !isPADXUnderThreshold; + + // + bool isADXBullish = adxpBuffer[barIndex] > adxnBuffer[barIndex]; + bool isPADXBullish = adxpBuffer[barIndex + 1] > adxnBuffer[barIndex + 1]; + + // + bool isADXBearish = adxpBuffer[barIndex] < adxnBuffer[barIndex]; + bool isPADXBearish = adxpBuffer[barIndex + 1] < adxnBuffer[barIndex + 1]; + + // + bool isADXSwitchedToBullish = + isADXBullish && + !isPADXBullish; + + // + bool isADXSwitchedToBearish = + isADXBearish && + !isPADXBearish; + + // + bool isADXFullySwitchedToBullish = + isADXSwitchedToBullish && + isADXCrossedOverThreshold; + + // + bool isADXFullySwitchedToBearish = + isADXSwitchedToBearish && + isADXCrossedUnderThreshold; + + // + bool isTriggerBarOverHKS = + iBar.low > iHKSMax; + bool isTriggerBarUnderHKS = + iBar.high < iHKSMin; + + // + // KI ... + + // + bool isKIBullish = kiStateBuffer[barIndex] > 0; + bool isPKIBullish = kiStateBuffer[barIndex + 1] > 0; + + // + bool isKIBearish = kiStateBuffer[barIndex] < 0; + bool isPKIBearish = kiStateBuffer[barIndex = 1] < 0; + + // // + // bool isKIOverHKS = + // kiBuffer[barIndex] > iHKSMax; + + // // + // bool isKIUnderHKS = + // kiBuffer[barIndex] < iHKSMin; + + // + bool isKISwitchedToBullish = + isKIBullish && + !isPKIBullish; + + // + bool isKISwitchedToBearish = + isKIBearish && + !isPKIBearish; + + // + // Detecting Signal ... + + // + // Bullish ... + isBullish = + // + false + // Conditions Validation ... + // isKIOverHKS && + // isHKSBullish && + // isKISwitchedToBullish + // && + // + // Bar Validation ... + // iBar.IsBullish() && + // iBar.close > kiBuffer[barIndex] + // + ; + + // + // Bearish ... + isBearish = + // + false + // Conditions Validation ... + // isKIUnderHKS && + // isHKSBearish && + // isKISwitchedToBearish + // && + // + // Bar Validation ... + // iBar.IsBearish() && + // iBar.close < kiBuffer[barIndex] + // + ; diff --git a/Indicators/x-saherelm.x121.xcatb.v1.mq5 b/Indicators/x-saherelm.x121.xcatb.v1.mq5 index 1b2db274..2ba3a73c 100644 --- a/Indicators/x-saherelm.x121.xcatb.v1.mq5 +++ b/Indicators/x-saherelm.x121.xcatb.v1.mq5 @@ -641,6 +641,11 @@ CArrayObj mObjects; XCPOIDrawer *mDrawer; XCBarAnalyser *mBarAnalyser; +// +int sameKICount = 0; +int sameKIBullishCount = 0; +int sameKIBearishCount = 0; + // int mSamePeakCount = 0; int mSameValeCount = 0; @@ -651,7 +656,7 @@ double mSameValeGolden = 0; // bool mDrawLiquidities = false; -bool mDrawRangeBreakes = true; +bool mDrawRangeBreakes = false; // bool mDetectLiquidities = true; @@ -3677,7 +3682,7 @@ void DoProcess( bool isCond1Trigger = mBarAnalyser .IsValidForTrigger( - iBar, + iPBar, triggerDir, true, // Cond 1 ... false, // Cond 2 ... @@ -3704,7 +3709,7 @@ void DoProcess( bool isCond2Trigger = mBarAnalyser .IsValidForTrigger( - iBar, + iPBar, triggerDir, false, // Cond 1 ... true, // Cond 2 ... @@ -3731,7 +3736,7 @@ void DoProcess( bool isCond3Trigger = mBarAnalyser .IsValidForTrigger( - iBar, + iPBar, triggerDir, false, // Cond 1 ... false, // Cond 2 ... @@ -3758,7 +3763,7 @@ void DoProcess( bool isCond4Trigger = mBarAnalyser .IsValidForTrigger( - iBar, + iPBar, triggerDir, false, // Cond 1 ... false, // Cond 2 ... @@ -3785,7 +3790,7 @@ void DoProcess( bool isCond5Trigger = mBarAnalyser .IsValidForTrigger( - iBar, + iPBar, triggerDir, false, // Cond 1 ... false, // Cond 2 ... @@ -3812,7 +3817,7 @@ void DoProcess( bool isCond6Trigger = mBarAnalyser .IsValidForTrigger( - iBar, + iPBar, triggerDir, false, // Cond 1 ... false, // Cond 2 ... @@ -3839,7 +3844,7 @@ void DoProcess( bool isCond7Trigger = mBarAnalyser .IsValidForTrigger( - iBar, + iPBar, triggerDir, false, // Cond 1 ... false, // Cond 2 ... @@ -3904,23 +3909,40 @@ void DoProcess( // Reading Required Condiions ... // - // HK Signal Bar ... + int pIndex = barIndex + 1; + int ppIndex = barIndex + 2; // - double iHKSOpen = hkSBarOpenBuffer[barIndex]; - double iHKSClose = hkSBarCloseBuffer[barIndex]; + // SAR ... // - double iHKSMax = MathMax(iHKSOpen, iHKSClose); - double iHKSMin = MathMin(iHKSOpen, iHKSClose); + bool isSarBullish = sarStateBuffer[pIndex] > 0; + bool isPSarBullish = sarStateBuffer[ppIndex] > 0; // - bool isHKSBullish = hkSBarOpenBuffer[barIndex] < hkSBarCloseBuffer[barIndex]; - bool isPHKSBullish = hkSBarOpenBuffer[barIndex + 1] < hkSBarCloseBuffer[barIndex + 1]; + bool isSarBearish = sarStateBuffer[pIndex] < 0; + bool isPSarBearish = sarStateBuffer[ppIndex] < 0; // - bool isHKSBearish = hkSBarOpenBuffer[barIndex] > hkSBarCloseBuffer[barIndex]; - bool isPHKSBearish = hkSBarOpenBuffer[barIndex + 1] > hkSBarCloseBuffer[barIndex + 1]; + bool isSarSwitchedToBullish = + isSarBullish && + !isPSarBullish; + + // + bool isSarSwitchedToBearish = + isSarBearish && + !isPSarBearish; + + // + // HKS ... + + // + bool isHKSBullish = hkSBarCloseBuffer[pIndex] > hkSBarOpenBuffer[pIndex]; + bool isPHKSBullish = hkSBarCloseBuffer[ppIndex] > hkSBarOpenBuffer[ppIndex]; + + // + bool isHKSBearish = hkSBarCloseBuffer[pIndex] < hkSBarOpenBuffer[pIndex]; + bool isPHKSBearish = hkSBarCloseBuffer[ppIndex] < hkSBarOpenBuffer[ppIndex]; // bool isHKSSwitchedToBullish = @@ -3933,123 +3955,36 @@ void DoProcess( !isPHKSBearish; // - // TREND ... + // SB ... // - double iTrend = trendBuffer[barIndex]; - bool isTrendBullish = trendStateBuffer[barIndex] > 0; - bool isTrendBearish = trendStateBuffer[barIndex] < 0; - bool isTrendSwitchedToBullish = - trendStateBuffer[barIndex] > 0 && - trendStateBuffer[barIndex + 1] <= 0; - bool isTrendSwitchedToBearish = - trendStateBuffer[barIndex] < 0 && - trendStateBuffer[barIndex + 1] >= 0; + bool isSBullish = sBarCloseBuffer[pIndex] > sBarOpenBuffer[pIndex]; + bool isPSBullish = sBarCloseBuffer[ppIndex] > sBarOpenBuffer[ppIndex]; // - // RSI ... + bool isSBearish = sBarCloseBuffer[pIndex] < sBarOpenBuffer[pIndex]; + bool isPSBearish = sBarCloseBuffer[ppIndex] < sBarOpenBuffer[ppIndex]; // - bool isRSIOverOB = rsiBuffer[barIndex] > rsiOBLevel; - bool isPRSIOverOB = rsiBuffer[barIndex + 1] > rsiOBLevel; + bool isSSwitchedToBullish = + isSBullish && + !isPSBullish; // - bool isRSIUnderOB = rsiBuffer[barIndex] < rsiOBLevel; - bool isPRSIUnderOB = rsiBuffer[barIndex + 1] < rsiOBLevel; - - // - bool isRSICrossedOverOB = - isRSIOverOB && - !isPRSIOverOB; - - // - bool isRSICrossedUnderOB = - isRSIUnderOB && - !isPRSIUnderOB; - - // - bool isRSIOverOS = rsiBuffer[barIndex] > rsiOSLevel; - bool isPRSIOverOS = rsiBuffer[barIndex + 1] > rsiOSLevel; - - // - bool isRSIUnderOS = rsiBuffer[barIndex] < rsiOSLevel; - bool isPRSIUnderOS = rsiBuffer[barIndex + 1] < rsiOSLevel; - - // - bool isRSICrossedOverOS = - isRSIOverOS && - !isPRSIOverOS; - - // - bool isRSICrossedUnderOS = - isRSIUnderOS && - !isPRSIUnderOS; - - // - // ADX ... - - // - bool isADXOverThreshold = adxBuffer[barIndex] > adxThreshold; - bool isPADXOverThreshold = adxBuffer[barIndex + 1] > adxThreshold; - - // - bool isADXUnderThreshold = adxBuffer[barIndex] < adxThreshold; - bool isPADXUnderThreshold = adxBuffer[barIndex + 1] < adxThreshold; - - // - bool isADXCrossedOverThreshold = - isADXOverThreshold && - !isPADXOverThreshold; - - // - bool isADXCrossedUnderThreshold = - isADXUnderThreshold && - !isPADXUnderThreshold; - - // - bool isADXBullish = adxpBuffer[barIndex] > adxnBuffer[barIndex]; - bool isPADXBullish = adxpBuffer[barIndex + 1] > adxnBuffer[barIndex + 1]; - - // - bool isADXBearish = adxpBuffer[barIndex] < adxnBuffer[barIndex]; - bool isPADXBearish = adxpBuffer[barIndex + 1] < adxnBuffer[barIndex + 1]; - - // - bool isADXSwitchedToBullish = - isADXBullish && - !isPADXBullish; - - // - bool isADXSwitchedToBearish = - isADXBearish && - !isPADXBearish; - - // - bool isADXFullySwitchedToBullish = - isADXSwitchedToBullish && - isADXCrossedOverThreshold; - - // - bool isADXFullySwitchedToBearish = - isADXSwitchedToBearish && - isADXCrossedUnderThreshold; - - // - bool isTriggerBarOverHKS = - iBar.low > iHKSMax; - bool isTriggerBarUnderHKS = - iBar.high < iHKSMin; + bool isSSwitchedToBearish = + isSBearish && + !isPSBearish; // // KI ... // - bool isKIBullish = kiStateBuffer[barIndex] > 0; - bool isPKIBullish = kiStateBuffer[barIndex + 1] > 0; + bool isKIBullish = kiStateBuffer[pIndex] > 0; + bool isPKIBullish = kiStateBuffer[ppIndex] > 0; // - bool isKIBearish = kiStateBuffer[barIndex] < 0; - bool isPKIBearish = kiStateBuffer[barIndex = 1] < 0; + bool isKIBearish = kiStateBuffer[pIndex] < 0; + bool isPKIBearish = kiStateBuffer[ppIndex] < 0; // bool isKISwitchedToBullish = @@ -4061,6 +3996,63 @@ void DoProcess( isKIBearish && !isPKIBearish; + // + bool isKIBullishBreaked = + iPBar.IsBreaked( + kiBuffer[pIndex], + X_DIRECTION_BULLISH, + X_FIBO_LEVEL_500, + X_BOUNDARY_PRICE_UP_DOWN // + ); + + // + bool isKIBearishBreaked = + iPBar.IsBreaked( + kiBuffer[pIndex], + X_DIRECTION_BEARISH, + X_FIBO_LEVEL_500, + X_BOUNDARY_PRICE_UP_DOWN // + ); + + // + bool isKISame = kiBuffer[pIndex] == kiBuffer[ppIndex]; + bool isKIBullishSame = + isKISame && + isKIBullish; + bool isKIBearishSame = + isKISame && + isKIBearish; + + // + if (isKISame) + { + sameKICount++; + } + else + { + sameKICount = 0; + } + + // + if (isKIBullishSame) + { + sameKIBullishCount++; + } + else + { + sameKIBullishCount = 0; + } + + // + if (isKIBearishSame) + { + sameKIBearishCount++; + } + else + { + sameKIBearishCount = 0; + } + // // Validating Trigger Bar based on Conditions ... if (isTriggerBar) @@ -4079,9 +4071,14 @@ void DoProcess( // Bullish ... isBullish = // - isHKSBullish && - isKISwitchedToBullish && - iBar.close > kiBuffer[barIndex] + // Conditions Validation ... + isKIBullishBreaked + // isSSwitchedToBullish + // isKISwitchedToBullish + // isSarSwitchedToBullish + // isHKSSwitchedToBullish + // + // Bar Validation ... // ; @@ -4089,9 +4086,14 @@ void DoProcess( // Bearish ... isBearish = // - isHKSBearish && - isKISwitchedToBearish && - iBar.close < kiBuffer[barIndex] + // Conditions Validation ... + isKIBearishBreaked + // isSSwitchedToBearish + // isKISwitchedToBearish + // isSarSwitchedToBearish + // isHKSSwitchedToBearish + // + // Bar Validation ... // ; diff --git a/Libraries/x-saherelm.x-ohcl.lib.mq5 b/Libraries/x-saherelm.x-ohcl.lib.mq5 index 943f9d77..5960aaec 100644 --- a/Libraries/x-saherelm.x-ohcl.lib.mq5 +++ b/Libraries/x-saherelm.x-ohcl.lib.mq5 @@ -1052,7 +1052,9 @@ struct XOHCL // bool IsBreaked( double price, - ENUM_X_DIRECTION forDir // + ENUM_X_DIRECTION forDir, + ENUM_X_FIBO_LEVELS fibLevel = X_FIBO_LEVEL_500, + ENUM_X_BOUNDARY_PRICE boundaryType = X_BOUNDARY_PRICE_UP_DOWN // ) { // @@ -1061,12 +1063,16 @@ struct XOHCL // result = IsValid() && price > 0 && - HasDirection(forDir); + HasDirection(forDir) && + IsValid(boundaryType); if (!result) { return result; } + // + bool isUpDownPriceType = boundaryType == X_BOUNDARY_PRICE_UP_DOWN; + // bool isBullish = IsBullish() && @@ -1084,6 +1090,37 @@ struct XOHCL // result = isBullish || isBearish; + if (result) + { + // + // Calculate Range ... + double range = + isUpDownPriceType + ? GetBody() + : GetRange(); + + // + // Apply Edge Range ... + double iReqRange = + (range / 100) * GetFiboLevelValue(fibLevel); + + // + // Calculate Boundary Price ... + double iBoundary = + isUpDownPriceType + ? iBullish + ? GetUp() + : GetDown() + : isBullish + ? high + : low; + + // + // Detect Breaked Value ... + result = + isBullish + ? + } // return result;