diff --git a/Documents/BKP/X121XKI/tmp.poi.mq5 b/Documents/BKP/X121XKI/tmp.poi.mq5 index 1d723195..d73516d2 100644 --- a/Documents/BKP/X121XKI/tmp.poi.mq5 +++ b/Documents/BKP/X121XKI/tmp.poi.mq5 @@ -1,1194 +1,1726 @@ - // #region XDetectors ... - bool IsKIPOI( - ENUM_X_DIRECTION &dir, - int barIndex = 0 // - ) +// #region XDetectors ... +bool IsKIPOI( + ENUM_X_DIRECTION &dir, + int barIndex = 0 // +) +{ + // + bool result = false; + + // + dir = X_DIRECTION_NONE; + + // + bool isBullish = IsKIBullishPOI(barIndex); + bool isBearish = IsKIBearishPOI(barIndex); + + // + dir = isBullish + ? X_DIRECTION_BULLISH + : isBearish + ? X_DIRECTION_BEARISH + : X_DIRECTION_NONE; + + // + result = HasDirection(dir); + + // + return result; +} + +bool IsKIBullishPOI(int barIndex = 0) +{ + // + bool result = false; + + // + barIndex = kiParser.NormalizeBarIndex(barIndex); + + // + result = + kiParser.IsValid() && + kiParser.IsKISlowBullish(barIndex) && + kiParser.IsKIFastBearish(barIndex); + + // + return result; +} + +bool IsKIBearishPOI(int barIndex = 0) +{ + // + bool result = false; + + // + barIndex = kiParser.NormalizeBarIndex(barIndex); + + // + result = + kiParser.IsValid() && + kiParser.IsKISlowBearish(barIndex) && + kiParser.IsKIFastBullish(barIndex); + + // + return result; +} + +bool IsKISignal( + ENUM_X_DIRECTION &dir, // + int barIndex = 0 // +) +{ + // + bool result = false; + + // + dir = X_DIRECTION_NONE; + barIndex = kiParser.NormalizeBarIndex(barIndex); + + // + // Retrieve KI State ... + bool isBullish = kiParser.IsKIFastSwitchedToBullish(barIndex + 1) && + kiParser.IsKIFastBullish(barIndex) && + kiParser.IsKISlowBullish(barIndex); + bool isBearish = kiParser.IsKIFastSwitchedToBearish(barIndex + 1) && + kiParser.IsKIFastBearish(barIndex) && + kiParser.IsKISlowBearish(barIndex); + result = isBullish || + isBearish; + if (!result) { - // - bool result = false; - - // - dir = X_DIRECTION_NONE; - - // - bool isBullish = IsKIBullishPOI(barIndex); - bool isBearish = IsKIBearishPOI(barIndex); - - // - dir = isBullish - ? X_DIRECTION_BULLISH - : isBearish - ? X_DIRECTION_BEARISH - : X_DIRECTION_NONE; - - // - result = HasDirection(dir); - - // return result; } - bool IsKIBullishPOI(int barIndex = 0) + // + dir = isBullish + ? X_DIRECTION_BULLISH + : isBearish + ? X_DIRECTION_BEARISH + : X_DIRECTION_NONE; + result = HasDirection(dir); + if (!result) { - // - bool result = false; - - // - barIndex = kiParser.NormalizeBarIndex(barIndex); - - // - result = - kiParser.IsValid() && - kiParser.IsKISlowBullish(barIndex) && - kiParser.IsKIFastBearish(barIndex); - - // return result; } - bool IsKIBearishPOI(int barIndex = 0) + // + XOHCL bar; + result = bar.Init(symbol, period, barIndex + 1); + if (!result) { - // - bool result = false; - - // - barIndex = kiParser.NormalizeBarIndex(barIndex); - - // - result = - kiParser.IsValid() && - kiParser.IsKISlowBearish(barIndex) && - kiParser.IsKIFastBullish(barIndex); - - // return result; } - bool IsKISignal( - ENUM_X_DIRECTION &dir, // - int barIndex = 0 // - ) + // + // Bar Direction Same as Dir ... + + // + // Price Place Check ... + double kiFast = kiHelper.GetKIFast(barIndex + 1); + double kiSlow = kiHelper.GetKISlow(barIndex + 1); + isBullish = + isBullish && + bar.close > kiFast && + kiFast > kiSlow && + (kiParser.IsKIFastOverLast(barIndex + 1) || + kiParser.IsKISlowOverLast(barIndex + 1)); + isBearish = + isBearish && + bar.close < kiFast && + kiFast < kiSlow && + (kiParser.IsKIFastUnderLast(barIndex + 1) || + kiParser.IsKISlowUnderLast(barIndex + 1)); + + // + result = + result && + (isBullish || + isBearish); + + // + // Cleanup Resources ... + bar.Clean(); + + // + return result; +} +// #endregion + +// #region Detectors ... +bool IsPOI( + ENUM_X_DIRECTION &forDir, + int barIndex = 0 // +) +{ + // + bool result = false; + + // + // Normalize ... + forDir = X_DIRECTION_NONE; + barIndex = kiParser.NormalizeBarIndex(barIndex); + + // + bool isBullish = IsBullishPOI(barIndex); + bool isBearish = IsBearishPOI(barIndex); + result = isBullish || isBearish; + if (!result) { - // - bool result = false; - - // - dir = X_DIRECTION_NONE; - barIndex = kiParser.NormalizeBarIndex(barIndex); - - // - // Retrieve KI State ... - bool isBullish = kiParser.IsKIFastSwitchedToBullish(barIndex + 1) && - kiParser.IsKIFastBullish(barIndex) && - kiParser.IsKISlowBullish(barIndex); - bool isBearish = kiParser.IsKIFastSwitchedToBearish(barIndex + 1) && - kiParser.IsKIFastBearish(barIndex) && - kiParser.IsKISlowBearish(barIndex); - result = isBullish || - isBearish; - if (!result) - { - return result; - } - - // - dir = isBullish - ? X_DIRECTION_BULLISH - : isBearish - ? X_DIRECTION_BEARISH - : X_DIRECTION_NONE; - result = HasDirection(dir); - if (!result) - { - return result; - } - - // - XOHCL bar; - result = bar.Init(symbol, period, barIndex + 1); - if (!result) - { - return result; - } - - // - // Bar Direction Same as Dir ... - - // - // Price Place Check ... - double kiFast = kiHelper.GetKIFast(barIndex + 1); - double kiSlow = kiHelper.GetKISlow(barIndex + 1); - isBullish = - isBullish && - bar.close > kiFast && - kiFast > kiSlow && - (kiParser.IsKIFastOverLast(barIndex + 1) || - kiParser.IsKISlowOverLast(barIndex + 1)); - isBearish = - isBearish && - bar.close < kiFast && - kiFast < kiSlow && - (kiParser.IsKIFastUnderLast(barIndex + 1) || - kiParser.IsKISlowUnderLast(barIndex + 1)); - - // - result = - result && - (isBullish || - isBearish); - - // - // Cleanup Resources ... - bar.Clean(); - - // - return result; - } - // #endregion - - - // #region Detectors ... - bool IsPOI( - ENUM_X_DIRECTION &forDir, - int barIndex = 0 // - ) - { - // - bool result = false; - - // - // Normalize ... - forDir = X_DIRECTION_NONE; - barIndex = kiParser.NormalizeBarIndex(barIndex); - - // - bool isBullish = IsBullishPOI(barIndex); - bool isBearish = IsBearishPOI(barIndex); - result = isBullish || isBearish; - if (!result) - { - return result; - } - - // - forDir = - isBullish - ? X_DIRECTION_BULLISH - : isBearish - ? X_DIRECTION_BEARISH - : X_DIRECTION_NONE; - result = HasDirection(forDir); - - // return result; } - bool IsBullishPOI(int barIndex = 0) + // + forDir = + isBullish + ? X_DIRECTION_BULLISH + : isBearish + ? X_DIRECTION_BEARISH + : X_DIRECTION_NONE; + result = HasDirection(forDir); + + // + return result; +} + +bool IsBullishPOI(int barIndex = 0) +{ + // + bool result = false; + + // + barIndex = kiParser.NormalizeBarIndex(barIndex); + + // + result = kiParser.IsTrendBullish(barIndex) && + kiParser.IsRSIBullish(barIndex); + if (!result) { - // - bool result = false; - - // - barIndex = kiParser.NormalizeBarIndex(barIndex); - - // - result = kiParser.IsTrendBullish(barIndex) && - kiParser.IsRSIBullish(barIndex); - if (!result) - { - return result; - } - - // - // Add candlestick confirmation ... - XOHCL bar; - result = result && - bar.Init(symbol, period, barIndex); - if (!result) - { - return result; - } - - // - result = result && - HasCandlestickDirection( - bar, - X_DIRECTION_BULLISH // - ); - - // - bar.Clean(); - - // return result; } - bool IsBearishPOI(int barIndex = 0) + // + // Add candlestick confirmation ... + XOHCL bar; + result = result && + bar.Init(symbol, period, barIndex); + if (!result) { - // - bool result = false; - - // - barIndex = kiParser.NormalizeBarIndex(barIndex); - - // - result = kiParser.IsTrendBearish(barIndex) && - kiParser.IsRSIBearish(barIndex); - if (!result) - { - return result; - } - - // - // Add candlestick confirmation ... - XOHCL bar; - result = result && - bar.Init(symbol, period, barIndex); - if (!result) - { - return result; - } - - // - result = result && - HasCandlestickDirection( - bar, - X_DIRECTION_BEARISH // - ); - - // - bar.Clean(); - - // return result; } - bool IsBreakoutPOI( - ENUM_X_DIRECTION &forDir, - int barIndex = 0 // - ) + // + result = result && + HasCandlestickDirection( + bar, + X_DIRECTION_BULLISH // + ); + + // + bar.Clean(); + + // + return result; +} + +bool IsBearishPOI(int barIndex = 0) +{ + // + bool result = false; + + // + barIndex = kiParser.NormalizeBarIndex(barIndex); + + // + result = kiParser.IsTrendBearish(barIndex) && + kiParser.IsRSIBearish(barIndex); + if (!result) { - // - bool result = false; - - // - // Normalize ... - forDir = X_DIRECTION_NONE; - barIndex = kiParser.NormalizeBarIndex(barIndex); - - // - bool isBullish = IsBullishBreakoutPOI(barIndex); - bool isBearish = IsBearishBreakoutPOI(barIndex); - result = isBullish || isBearish; - if (!result) - { - return result; - } - - // - forDir = - isBullish - ? X_DIRECTION_BULLISH - : isBearish - ? X_DIRECTION_BEARISH - : X_DIRECTION_NONE; - result = HasDirection(forDir); - - // return result; } - bool IsBullishBreakoutPOI(int barIndex = 0) + // + // Add candlestick confirmation ... + XOHCL bar; + result = result && + bar.Init(symbol, period, barIndex); + if (!result) { - // - bool result = false; - - // - barIndex = kiParser.NormalizeBarIndex(barIndex); - - // - result = kiParser.IsBullishBreakout(barIndex); - if (!result) - { - return result; - } - - // - // Add candlestick confirmation ... - XOHCL bar; - result = result && - bar.Init(symbol, period, barIndex); - if (!result) - { - return result; - } - - // - result = result && - HasCandlestickDirection( - bar, - X_DIRECTION_BULLISH // - ); - - // - bar.Clean(); - - // return result; } - bool IsBearishBreakoutPOI(int barIndex = 0) + // + result = result && + HasCandlestickDirection( + bar, + X_DIRECTION_BEARISH // + ); + + // + bar.Clean(); + + // + return result; +} + +bool IsBreakoutPOI( + ENUM_X_DIRECTION &forDir, + int barIndex = 0 // +) +{ + // + bool result = false; + + // + // Normalize ... + forDir = X_DIRECTION_NONE; + barIndex = kiParser.NormalizeBarIndex(barIndex); + + // + bool isBullish = IsBullishBreakoutPOI(barIndex); + bool isBearish = IsBearishBreakoutPOI(barIndex); + result = isBullish || isBearish; + if (!result) { - // - bool result = false; - - // - barIndex = kiParser.NormalizeBarIndex(barIndex); - - // - result = kiParser.IsBearishBreakout(barIndex); - if (!result) - { - return result; - } - - // - // Add candlestick confirmation ... - XOHCL bar; - result = result && - bar.Init(symbol, period, barIndex); - if (!result) - { - return result; - } - - // - result = result && - HasCandlestickDirection( - bar, - X_DIRECTION_BEARISH // - ); - - // - bar.Clean(); - - // return result; } - bool IsReversalPOI( - ENUM_X_DIRECTION &forDir, - int barIndex = 0 // - ) + // + forDir = + isBullish + ? X_DIRECTION_BULLISH + : isBearish + ? X_DIRECTION_BEARISH + : X_DIRECTION_NONE; + result = HasDirection(forDir); + + // + return result; +} + +bool IsBullishBreakoutPOI(int barIndex = 0) +{ + // + bool result = false; + + // + barIndex = kiParser.NormalizeBarIndex(barIndex); + + // + result = kiParser.IsBullishBreakout(barIndex); + if (!result) { - // - bool result = false; - - // - // Normalize ... - forDir = X_DIRECTION_NONE; - barIndex = kiParser.NormalizeBarIndex(barIndex); - - // - bool isBullish = IsBullishReversalPOI(barIndex); - bool isBearish = IsBearishReversalPOI(barIndex); - result = isBullish || isBearish; - if (!result) - { - return result; - } - - // - forDir = - isBullish - ? X_DIRECTION_BULLISH - : isBearish - ? X_DIRECTION_BEARISH - : X_DIRECTION_NONE; - result = HasDirection(forDir); - - // return result; } - bool IsBullishReversalPOI(int barIndex = 0) + // + // Add candlestick confirmation ... + XOHCL bar; + result = result && + bar.Init(symbol, period, barIndex); + if (!result) { - // - bool result = false; - - // - barIndex = kiParser.NormalizeBarIndex(barIndex); - - // - result = kiParser.IsBullishReversal(barIndex); - if (!result) - { - return result; - } - - // - // Add candlestick confirmation ... - XOHCL bar; - result = result && - bar.Init(symbol, period, barIndex); - if (!result) - { - return result; - } - - // - result = result && - HasCandlestickDirection( - bar, - X_DIRECTION_BULLISH // - ); - - // - bar.Clean(); - - // return result; } - bool IsBearishReversalPOI(int barIndex = 0) + // + result = result && + HasCandlestickDirection( + bar, + X_DIRECTION_BULLISH // + ); + + // + bar.Clean(); + + // + return result; +} + +bool IsBearishBreakoutPOI(int barIndex = 0) +{ + // + bool result = false; + + // + barIndex = kiParser.NormalizeBarIndex(barIndex); + + // + result = kiParser.IsBearishBreakout(barIndex); + if (!result) { - // - bool result = false; - - // - barIndex = kiParser.NormalizeBarIndex(barIndex); - - // - result = kiParser.IsBearishReversal(barIndex); - if (!result) - { - return result; - } - - // - // Add candlestick confirmation ... - XOHCL bar; - result = result && - bar.Init(symbol, period, barIndex); - if (!result) - { - return result; - } - - // - result = result && - HasCandlestickDirection( - bar, - X_DIRECTION_BEARISH // - ); - - // - bar.Clean(); - - // return result; } - bool IsContinuationPOI( - ENUM_X_DIRECTION &forDir, - int barIndex = 0 // - ) + // + // Add candlestick confirmation ... + XOHCL bar; + result = result && + bar.Init(symbol, period, barIndex); + if (!result) { - // - bool result = false; - - // - // Normalize ... - forDir = X_DIRECTION_NONE; - barIndex = kiParser.NormalizeBarIndex(barIndex); - - // - bool isBullish = IsBullishContinuationPOI(barIndex); - bool isBearish = IsBearishContinuationPOI(barIndex); - result = isBullish || isBearish; - if (!result) - { - return result; - } - - // - forDir = - isBullish - ? X_DIRECTION_BULLISH - : isBearish - ? X_DIRECTION_BEARISH - : X_DIRECTION_NONE; - result = HasDirection(forDir); - - // return result; } - bool IsBullishContinuationPOI(int barIndex = 0) + // + result = result && + HasCandlestickDirection( + bar, + X_DIRECTION_BEARISH // + ); + + // + bar.Clean(); + + // + return result; +} + +bool IsReversalPOI( + ENUM_X_DIRECTION &forDir, + int barIndex = 0 // +) +{ + // + bool result = false; + + // + // Normalize ... + forDir = X_DIRECTION_NONE; + barIndex = kiParser.NormalizeBarIndex(barIndex); + + // + bool isBullish = IsBullishReversalPOI(barIndex); + bool isBearish = IsBearishReversalPOI(barIndex); + result = isBullish || isBearish; + if (!result) { - // - bool result = false; - - // - barIndex = kiParser.NormalizeBarIndex(barIndex); - - // - result = kiParser.IsTrendStrongBullish(barIndex); - if (!result) - { - return result; - } - - // - // Add candlestick confirmation ... - XOHCL bar; - ENUM_X_DIRECTION dir; - result = result && - bar.Init(symbol, period, barIndex); - if (!result) - { - return result; - } - - // - XOHCL swingBar; - result = result && - IsFlagPattern(bar, dir, swingBar) && - IsXBullish(dir); - - // - bar.Clean(); - swingBar.Clean(); - - // return result; } - bool IsBearishContinuationPOI(int barIndex = 0) + // + forDir = + isBullish + ? X_DIRECTION_BULLISH + : isBearish + ? X_DIRECTION_BEARISH + : X_DIRECTION_NONE; + result = HasDirection(forDir); + + // + return result; +} + +bool IsBullishReversalPOI(int barIndex = 0) +{ + // + bool result = false; + + // + barIndex = kiParser.NormalizeBarIndex(barIndex); + + // + result = kiParser.IsBullishReversal(barIndex); + if (!result) { - // - bool result = false; - - // - barIndex = kiParser.NormalizeBarIndex(barIndex); - - // - result = kiParser.IsTrendStrongBearish(barIndex); - if (!result) - { - return result; - } - - // - // Add candlestick confirmation ... - XOHCL bar; - ENUM_X_DIRECTION dir; - result = result && - bar.Init(symbol, period, barIndex); - if (!result) - { - return result; - } - - // - XOHCL swingBar; - result = result && - IsFlagPattern(bar, dir, swingBar) && - IsXBearish(dir); - - // - bar.Clean(); - swingBar.Clean(); - - // return result; } - bool IsExhaustionPOI( - ENUM_X_DIRECTION &forDir, - int barIndex = 0 // - ) + // + // Add candlestick confirmation ... + XOHCL bar; + result = result && + bar.Init(symbol, period, barIndex); + if (!result) { - // - bool result = false; - - // - // Normalize ... - forDir = X_DIRECTION_NONE; - barIndex = kiParser.NormalizeBarIndex(barIndex); - - // - bool isBullish = IsBullishExhaustionPOI(barIndex); - bool isBearish = IsBearishExhaustionPOI(barIndex); - result = isBullish || isBearish; - if (!result) - { - return result; - } - - // - forDir = - isBullish - ? X_DIRECTION_BULLISH - : isBearish - ? X_DIRECTION_BEARISH - : X_DIRECTION_NONE; - result = HasDirection(forDir); - - // return result; } - bool IsBullishExhaustionPOI(int barIndex = 0) + // + result = result && + HasCandlestickDirection( + bar, + X_DIRECTION_BULLISH // + ); + + // + bar.Clean(); + + // + return result; +} + +bool IsBearishReversalPOI(int barIndex = 0) +{ + // + bool result = false; + + // + barIndex = kiParser.NormalizeBarIndex(barIndex); + + // + result = kiParser.IsBearishReversal(barIndex); + if (!result) { - // - bool result = false; - - // - barIndex = kiParser.NormalizeBarIndex(barIndex); - - // - bool isTrendOk = kiParser.IsTrendStrongBullish(barIndex); - bool isRSIOk = kiParser.IsRSIOverbought(barIndex); - result = isTrendOk && isRSIOk; - if (!result) - { - return result; - } - - // - // Add candlestick confirmation ... - XOHCL bar; - result = result && - bar.Init(symbol, period, barIndex); - if (!result) - { - return result; - } - - // - result = result && - HasCandlestickDirection( - bar, - X_DIRECTION_BEARISH // - ); - - // - bar.Clean(); - - // return result; } - bool IsBearishExhaustionPOI(int barIndex = 0) + // + // Add candlestick confirmation ... + XOHCL bar; + result = result && + bar.Init(symbol, period, barIndex); + if (!result) { - // - bool result = false; - - // - barIndex = kiParser.NormalizeBarIndex(barIndex); - - // - bool isTrendOk = kiParser.IsTrendStrongBearish(barIndex); - bool isRSIOk = kiParser.IsRSIOversold(barIndex); - result = isTrendOk && isRSIOk; - if (!result) - { - return result; - } - - // - // Add candlestick confirmation ... - XOHCL bar; - result = result && - bar.Init(symbol, period, barIndex); - if (!result) - { - return result; - } - - // - result = result && - HasCandlestickDirection( - bar, - X_DIRECTION_BULLISH // - ); - - // - bar.Clean(); - - // return result; } - bool IsTrendExhaustedPOI( - ENUM_X_DIRECTION &forDir, - int barIndex = 0 // - ) + // + result = result && + HasCandlestickDirection( + bar, + X_DIRECTION_BEARISH // + ); + + // + bar.Clean(); + + // + return result; +} + +bool IsContinuationPOI( + ENUM_X_DIRECTION &forDir, + int barIndex = 0 // +) +{ + // + bool result = false; + + // + // Normalize ... + forDir = X_DIRECTION_NONE; + barIndex = kiParser.NormalizeBarIndex(barIndex); + + // + bool isBullish = IsBullishContinuationPOI(barIndex); + bool isBearish = IsBearishContinuationPOI(barIndex); + result = isBullish || isBearish; + if (!result) { - // - bool result = false; - - // - // Normalize ... - forDir = X_DIRECTION_NONE; - barIndex = kiParser.NormalizeBarIndex(barIndex); - - // - bool isBullish = IsBullishTrendExhaustedPOI(barIndex); - bool isBearish = IsBearishTrendExhaustedPOI(barIndex); - result = isBullish || isBearish; - if (!result) - { - return result; - } - - // - forDir = - isBullish - ? X_DIRECTION_BULLISH - : isBearish - ? X_DIRECTION_BEARISH - : X_DIRECTION_NONE; - result = HasDirection(forDir); - - // return result; } - bool IsBullishTrendExhaustedPOI(int barIndex = 0) + // + forDir = + isBullish + ? X_DIRECTION_BULLISH + : isBearish + ? X_DIRECTION_BEARISH + : X_DIRECTION_NONE; + result = HasDirection(forDir); + + // + return result; +} + +bool IsBullishContinuationPOI(int barIndex = 0) +{ + // + bool result = false; + + // + barIndex = kiParser.NormalizeBarIndex(barIndex); + + // + result = kiParser.IsTrendStrongBullish(barIndex); + if (!result) + { + return result; + } + + // + // Add candlestick confirmation ... + XOHCL bar; + ENUM_X_DIRECTION dir; + result = result && + bar.Init(symbol, period, barIndex); + if (!result) + { + return result; + } + + // + XOHCL swingBar; + result = result && + IsFlagPattern(bar, dir, swingBar) && + IsXBullish(dir); + + // + bar.Clean(); + swingBar.Clean(); + + // + return result; +} + +bool IsBearishContinuationPOI(int barIndex = 0) +{ + // + bool result = false; + + // + barIndex = kiParser.NormalizeBarIndex(barIndex); + + // + result = kiParser.IsTrendStrongBearish(barIndex); + if (!result) + { + return result; + } + + // + // Add candlestick confirmation ... + XOHCL bar; + ENUM_X_DIRECTION dir; + result = result && + bar.Init(symbol, period, barIndex); + if (!result) + { + return result; + } + + // + XOHCL swingBar; + result = result && + IsFlagPattern(bar, dir, swingBar) && + IsXBearish(dir); + + // + bar.Clean(); + swingBar.Clean(); + + // + return result; +} + +bool IsExhaustionPOI( + ENUM_X_DIRECTION &forDir, + int barIndex = 0 // +) +{ + // + bool result = false; + + // + // Normalize ... + forDir = X_DIRECTION_NONE; + barIndex = kiParser.NormalizeBarIndex(barIndex); + + // + bool isBullish = IsBullishExhaustionPOI(barIndex); + bool isBearish = IsBearishExhaustionPOI(barIndex); + result = isBullish || isBearish; + if (!result) + { + return result; + } + + // + forDir = + isBullish + ? X_DIRECTION_BULLISH + : isBearish + ? X_DIRECTION_BEARISH + : X_DIRECTION_NONE; + result = HasDirection(forDir); + + // + return result; +} + +bool IsBullishExhaustionPOI(int barIndex = 0) +{ + // + bool result = false; + + // + barIndex = kiParser.NormalizeBarIndex(barIndex); + + // + bool isTrendOk = kiParser.IsTrendStrongBullish(barIndex); + bool isRSIOk = kiParser.IsRSIOverbought(barIndex); + result = isTrendOk && isRSIOk; + if (!result) + { + return result; + } + + // + // Add candlestick confirmation ... + XOHCL bar; + result = result && + bar.Init(symbol, period, barIndex); + if (!result) + { + return result; + } + + // + result = result && + HasCandlestickDirection( + bar, + X_DIRECTION_BEARISH // + ); + + // + bar.Clean(); + + // + return result; +} + +bool IsBearishExhaustionPOI(int barIndex = 0) +{ + // + bool result = false; + + // + barIndex = kiParser.NormalizeBarIndex(barIndex); + + // + bool isTrendOk = kiParser.IsTrendStrongBearish(barIndex); + bool isRSIOk = kiParser.IsRSIOversold(barIndex); + result = isTrendOk && isRSIOk; + if (!result) + { + return result; + } + + // + // Add candlestick confirmation ... + XOHCL bar; + result = result && + bar.Init(symbol, period, barIndex); + if (!result) + { + return result; + } + + // + result = result && + HasCandlestickDirection( + bar, + X_DIRECTION_BULLISH // + ); + + // + bar.Clean(); + + // + return result; +} + +bool IsTrendExhaustedPOI( + ENUM_X_DIRECTION &forDir, + int barIndex = 0 // +) +{ + // + bool result = false; + + // + // Normalize ... + forDir = X_DIRECTION_NONE; + barIndex = kiParser.NormalizeBarIndex(barIndex); + + // + bool isBullish = IsBullishTrendExhaustedPOI(barIndex); + bool isBearish = IsBearishTrendExhaustedPOI(barIndex); + result = isBullish || isBearish; + if (!result) + { + return result; + } + + // + forDir = + isBullish + ? X_DIRECTION_BULLISH + : isBearish + ? X_DIRECTION_BEARISH + : X_DIRECTION_NONE; + result = HasDirection(forDir); + + // + return result; +} + +bool IsBullishTrendExhaustedPOI(int barIndex = 0) +{ + // + bool result = false; + + // + barIndex = kiParser.NormalizeBarIndex(barIndex); + + // + // Trend was strong in last 3 bars ... + bool isTrendOk = kiParser.IsTrendStrongBullish(barIndex + 1); + for (int i = 1; i <= 3; i++) { // - bool result = false; + if (kiParser.IsTrendStrongBullish(barIndex + i)) + { + isTrendOk = true; + break; + } + } - // - barIndex = kiParser.NormalizeBarIndex(barIndex); + // + // RSI rolling over from overbought ... + double rsiNow = kiHelper.GetRSI(barIndex); + double rsiPrev = kiHelper.GetRSI(barIndex + 1); + bool rsiFlip = (rsiPrev > 70 && rsiNow < rsiPrev); + bool isRSIOk = rsiFlip || kiParser.IsRSIOverbought(barIndex); + // + bool volCooling = kiHelper.GetATR(barIndex) <= kiHelper.GetATRSmoothed(barIndex) * 1.05; + bool isVolatilityOk = volCooling || kiParser.IsVolatilityLow(barIndex); + + // + result = isRSIOk && + isTrendOk && + isVolatilityOk; + if (!result) + { + return result; + } + + // + // Add candlestick confirmation ... + XOHCL bar; + result = result && + bar.Init(symbol, period, barIndex); + if (!result) + { + return result; + } + + // + result = result && + HasCandlestickDirection( + bar, + X_DIRECTION_BEARISH // + ); + + // + bar.Clean(); + + // + return result; +} + +bool IsBearishTrendExhaustedPOI(int barIndex = 0) +{ + // + bool result = false; + + // + barIndex = kiParser.NormalizeBarIndex(barIndex); + + // + bool isTrendOk = kiParser.IsTrendStrongBearish(barIndex + 1); + for (int i = 1; i <= 3; i++) + { // - // Trend was strong in last 3 bars ... - bool isTrendOk = kiParser.IsTrendStrongBullish(barIndex + 1); - for (int i = 1; i <= 3; i++) + if (kiParser.IsTrendStrongBearish(barIndex + i)) + { + isTrendOk = true; + break; + } + } + + // + // RSI rolling over from overbought ... + double rsiNow = kiHelper.GetRSI(barIndex); + double rsiPrev = kiHelper.GetRSI(barIndex + 1); + bool rsiFlip = (rsiPrev < 30 && rsiNow > rsiPrev); + bool isRSIOk = rsiFlip || kiParser.IsRSIOversold(barIndex); + + // + bool volCooling = kiHelper.GetATR(barIndex) <= kiHelper.GetATRSmoothed(barIndex) * 1.05; + bool isVolatilityOk = volCooling || kiParser.IsVolatilityLow(barIndex); + + // + result = isRSIOk && + isTrendOk && + isVolatilityOk; + if (!result) + { + return result; + } + + // + // Add candlestick confirmation ... + XOHCL bar; + result = result && + bar.Init(symbol, period, barIndex); + if (!result) + { + return result; + } + + // + result = result && + HasCandlestickDirection( + bar, + X_DIRECTION_BULLISH // + ); + + // + bar.Clean(); + + // + return result; +} +// #endregion + +// #region POI Detectors ... +bool NearestKIFastBullish( + int &index, + int barIndex = 0, + int loopback = 50 // +) +{ + // + bool result = false; + + // + index = -1; + + // + // Normalize ... + barIndex = kiParser.NormalizeBarIndex(barIndex); + + // + // Loop Back ... + bool isPassed = false; + for (int i = barIndex; i < barIndex + loopback; i++) + { + // + isPassed = kiParser.IsKIFastBullish(i); + if (isPassed) { // - if (kiParser.IsTrendStrongBullish(barIndex + i)) - { - isTrendOk = true; - break; - } + index = i; + break; } - - // - // RSI rolling over from overbought ... - double rsiNow = kiHelper.GetRSI(barIndex); - double rsiPrev = kiHelper.GetRSI(barIndex + 1); - bool rsiFlip = (rsiPrev > 70 && rsiNow < rsiPrev); - bool isRSIOk = rsiFlip || kiParser.IsRSIOverbought(barIndex); - - // - bool volCooling = kiHelper.GetATR(barIndex) <= kiHelper.GetATRSmoothed(barIndex) * 1.05; - bool isVolatilityOk = volCooling || kiParser.IsVolatilityLow(barIndex); - - // - result = isRSIOk && - isTrendOk && - isVolatilityOk; - if (!result) - { - return result; - } - - // - // Add candlestick confirmation ... - XOHCL bar; - result = result && - bar.Init(symbol, period, barIndex); - if (!result) - { - return result; - } - - // - result = result && - HasCandlestickDirection( - bar, - X_DIRECTION_BEARISH // - ); - - // - bar.Clean(); - - // - return result; } - bool IsBearishTrendExhaustedPOI(int barIndex = 0) + // + result = IsValidIndex(index); + + // + return result; +} + +bool NearestKIFastBearish( + int &index, + int barIndex = 0, + int loopback = 50 // +) +{ + // + bool result = false; + + // + index = -1; + + // + // Normalize ... + barIndex = kiParser.NormalizeBarIndex(barIndex); + + // + // Loop Back ... + bool isPassed = false; + for (int i = barIndex; i < barIndex + loopback; i++) { // - bool result = false; - - // - barIndex = kiParser.NormalizeBarIndex(barIndex); - - // - bool isTrendOk = kiParser.IsTrendStrongBearish(barIndex + 1); - for (int i = 1; i <= 3; i++) + isPassed = kiParser.IsKIFastBearish(i); + if (isPassed) { // - if (kiParser.IsTrendStrongBearish(barIndex + i)) - { - isTrendOk = true; - break; - } + index = i; + break; } - - // - // RSI rolling over from overbought ... - double rsiNow = kiHelper.GetRSI(barIndex); - double rsiPrev = kiHelper.GetRSI(barIndex + 1); - bool rsiFlip = (rsiPrev < 30 && rsiNow > rsiPrev); - bool isRSIOk = rsiFlip || kiParser.IsRSIOversold(barIndex); - - // - bool volCooling = kiHelper.GetATR(barIndex) <= kiHelper.GetATRSmoothed(barIndex) * 1.05; - bool isVolatilityOk = volCooling || kiParser.IsVolatilityLow(barIndex); - - // - result = isRSIOk && - isTrendOk && - isVolatilityOk; - if (!result) - { - return result; - } - - // - // Add candlestick confirmation ... - XOHCL bar; - result = result && - bar.Init(symbol, period, barIndex); - if (!result) - { - return result; - } - - // - result = result && - HasCandlestickDirection( - bar, - X_DIRECTION_BULLISH // - ); - - // - bar.Clean(); - - // - return result; } - // #endregion - // #region POI Detectors ... - bool NearestKIFastBullish( - int &index, - int barIndex = 0, - int loopback = 50 // - ) + // + result = IsValidIndex(index); + + // + return result; +} + +bool NearestKIFastSwitchedToBullish( + int &index, + int barIndex = 0, + int loopback = 50 // +) +{ + // + bool result = false; + + // + index = -1; + + // + // Normalize ... + barIndex = kiParser.NormalizeBarIndex(barIndex); + + // + // Loop Back ... + bool isPassed = false; + for (int i = barIndex; i < barIndex + loopback; i++) { // - bool result = false; - - // - index = -1; - - // - // Normalize ... - barIndex = kiParser.NormalizeBarIndex(barIndex); - - // - // Loop Back ... - bool isPassed = false; - for (int i = barIndex; i < barIndex + loopback; i++) + isPassed = kiParser.IsKIFastSwitchedToBullish(i); + if (isPassed) { // - isPassed = kiParser.IsKIFastBullish(i); - if (isPassed) - { - // - index = i; - break; - } + index = i; + break; } - - // - result = IsValidIndex(index); - - // - return result; } - bool NearestKIFastBearish( - int &index, - int barIndex = 0, - int loopback = 50 // - ) + // + result = IsValidIndex(index); + + // + return result; +} + +bool NearestKIFastSwitchedToBearish( + int &index, + int barIndex = 0, + int loopback = 50 // +) +{ + // + bool result = false; + + // + index = -1; + + // + // Normalize ... + barIndex = kiParser.NormalizeBarIndex(barIndex); + + // + // Loop Back ... + bool isPassed = false; + for (int i = barIndex; i < barIndex + loopback; i++) { // - bool result = false; - - // - index = -1; - - // - // Normalize ... - barIndex = kiParser.NormalizeBarIndex(barIndex); - - // - // Loop Back ... - bool isPassed = false; - for (int i = barIndex; i < barIndex + loopback; i++) + isPassed = kiParser.IsKIFastSwitchedToBearish(i); + if (isPassed) { // - isPassed = kiParser.IsKIFastBearish(i); - if (isPassed) - { - // - index = i; - break; - } + index = i; + break; } - - // - result = IsValidIndex(index); - - // - return result; } - bool NearestKIFastSwitchedToBullish( - int &index, - int barIndex = 0, - int loopback = 50 // - ) + // + result = IsValidIndex(index); + + // + return result; +} + +bool NearestKISlowBullish( + int &index, + int barIndex = 0, + int loopback = 50 // +) +{ + // + bool result = false; + + // + index = -1; + + // + // Normalize ... + barIndex = kiParser.NormalizeBarIndex(barIndex); + + // + // Loop Back ... + bool isPassed = false; + for (int i = barIndex; i < barIndex + loopback; i++) { // - bool result = false; - - // - index = -1; - - // - // Normalize ... - barIndex = kiParser.NormalizeBarIndex(barIndex); - - // - // Loop Back ... - bool isPassed = false; - for (int i = barIndex; i < barIndex + loopback; i++) + isPassed = kiParser.IsKISlowBullish(i); + if (isPassed) { // - isPassed = kiParser.IsKIFastSwitchedToBullish(i); - if (isPassed) - { - // - index = i; - break; - } + index = i; + break; } - - // - result = IsValidIndex(index); - - // - return result; } - bool NearestKIFastSwitchedToBearish( - int &index, - int barIndex = 0, - int loopback = 50 // - ) + // + result = IsValidIndex(index); + + // + return result; +} + +bool NearestKISlowBearish( + int &index, + int barIndex = 0, + int loopback = 50 // +) +{ + // + bool result = false; + + // + index = -1; + + // + // Normalize ... + barIndex = kiParser.NormalizeBarIndex(barIndex); + + // + // Loop Back ... + bool isPassed = false; + for (int i = barIndex; i < barIndex + loopback; i++) { // - bool result = false; - - // - index = -1; - - // - // Normalize ... - barIndex = kiParser.NormalizeBarIndex(barIndex); - - // - // Loop Back ... - bool isPassed = false; - for (int i = barIndex; i < barIndex + loopback; i++) + isPassed = kiParser.IsKISlowBearish(i); + if (isPassed) { // - isPassed = kiParser.IsKIFastSwitchedToBearish(i); - if (isPassed) - { - // - index = i; - break; - } + index = i; + break; } - - // - result = IsValidIndex(index); - - // - return result; } - bool NearestKISlowBullish( - int &index, - int barIndex = 0, - int loopback = 50 // - ) + // + result = IsValidIndex(index); + + // + return result; +} + +bool NearestKISlowSwitchedToBullish( + int &index, + int barIndex = 0, + int loopback = 50 // +) +{ + // + bool result = false; + + // + index = -1; + + // + // Normalize ... + barIndex = kiParser.NormalizeBarIndex(barIndex); + + // + // Loop Back ... + bool isPassed = false; + for (int i = barIndex; i < barIndex + loopback; i++) { // - bool result = false; - - // - index = -1; - - // - // Normalize ... - barIndex = kiParser.NormalizeBarIndex(barIndex); - - // - // Loop Back ... - bool isPassed = false; - for (int i = barIndex; i < barIndex + loopback; i++) + isPassed = kiParser.IsKISlowSwitchedToBullish(i); + if (isPassed) { // - isPassed = kiParser.IsKISlowBullish(i); - if (isPassed) - { - // - index = i; - break; - } + index = i; + break; } - - // - result = IsValidIndex(index); - - // - return result; } - bool NearestKISlowBearish( - int &index, - int barIndex = 0, - int loopback = 50 // - ) + // + result = IsValidIndex(index); + + // + return result; +} + +bool NearestKISlowSwitchedToBearish( + int &index, + int barIndex = 0, + int loopback = 50 // +) +{ + // + bool result = false; + + // + index = -1; + + // + // Normalize ... + barIndex = kiParser.NormalizeBarIndex(barIndex); + + // + // Loop Back ... + bool isPassed = false; + for (int i = barIndex; i < barIndex + loopback; i++) { // - bool result = false; - - // - index = -1; - - // - // Normalize ... - barIndex = kiParser.NormalizeBarIndex(barIndex); - - // - // Loop Back ... - bool isPassed = false; - for (int i = barIndex; i < barIndex + loopback; i++) + isPassed = kiParser.IsKISlowSwitchedToBearish(i); + if (isPassed) { // - isPassed = kiParser.IsKISlowBearish(i); - if (isPassed) - { - // - index = i; - break; - } + index = i; + break; } + } - // - result = IsValidIndex(index); + // + result = IsValidIndex(index); - // + // + return result; +} +// #endregion + +// #region Composite ... +bool IsTrendBullish(int barIndex = 0) +{ + // + bool result = false; + + // + // Normalize ... + barIndex = NormalizeBarIndex(barIndex); + + // + // Validate ... + result = IsValid(); + if (!result) + { return result; } - bool NearestKISlowSwitchedToBullish( - int &index, - int barIndex = 0, - int loopback = 50 // - ) + // + result = IsKIFastBullish(barIndex) && + IsKISlowBullish(barIndex) && + IsMACrossoverBullish(barIndex); + + // + return result; +} + +bool IsTrendBearish(int barIndex = 0) +{ + // + bool result = false; + + // + // Normalize ... + barIndex = NormalizeBarIndex(barIndex); + + // + // Validate ... + result = IsValid(); + if (!result) + { + return result; + } + + // + result = IsKIFastBearish(barIndex) && + IsKISlowBearish(barIndex) && + IsMACrossoverBearish(barIndex); + + // + return result; +} + +bool IsBullishMomentumTrend(int barIndex = 0) +{ + // + bool result = false; + + // + // Normalize ... + barIndex = NormalizeBarIndex(barIndex); + + // + // Validate ... + result = IsValid(); + if (!result) + { + return result; + } + + // + result = IsTrendBullish(barIndex) && + IsRSIBullish(barIndex); + + // + return result; +} + +bool IsBearishMomentumTrend(int barIndex = 0) +{ + // + bool result = false; + + // + // Normalize ... + barIndex = NormalizeBarIndex(barIndex); + + // + // Validate ... + result = IsValid(); + if (!result) + { + return result; + } + + // + result = IsTrendBearish(barIndex) && + IsRSIBearish(barIndex); + + // + return result; +} + +bool IsBullishBreakout(int barIndex = 0) +{ + // + bool result = false; + + // + // Normalize ... + barIndex = NormalizeBarIndex(barIndex); + + // + // Validate ... + result = IsValid(); + if (!result) + { + return result; + } + + // + result = + IsPriceAboveKIUpper(barIndex) && + IsATRBreakoutUp(barIndex) && + IsVolatilityHigh(barIndex); + + // + return result; +} + +bool IsBearishBreakout(int barIndex = 0) +{ + // + bool result = false; + + // + // Normalize ... + barIndex = NormalizeBarIndex(barIndex); + + // + // Validate ... + result = IsValid(); + if (!result) + { + return result; + } + + // + result = + IsPriceBelowKILower(barIndex) && + IsATRBreakoutDown(barIndex) && + IsVolatilityHigh(barIndex); + return result; +} + +bool IsBullishReversal(int barIndex = 0) +{ + // + bool result = false; + + // + // Normalize ... + barIndex = NormalizeBarIndex(barIndex); + + // + // Validate ... + result = IsValid(); + if (!result) + { + return result; + } + + // + // RSI oversold and turning upward ... + double rsiNow = helper.GetRSI(barIndex); + double rsiPrev = helper.GetRSI(barIndex + 1); + bool rsiFlip = (rsiNow > rsiPrev) && (rsiPrev < 30); + + // + // ATR check (volatility supportive) ... + double atrNow = helper.GetATR(barIndex); + double atrPrev = helper.GetATR(barIndex + 1); + double atrMaNow = helper.GetATRSmoothed(barIndex); + double atrMaPrev = helper.GetATRSmoothed(barIndex + 1); + bool atrOk = atrNow > atrMaNow || atrNow > atrPrev || atrMaNow > atrMaPrev; + + // + // MA crossover bullish ... + double maFastNow = helper.GetMAFast(barIndex); + double maSlowNow = helper.GetMASlow(barIndex); + bool maOk = maFastNow > maSlowNow; + + // + result = rsiFlip && (atrOk || maOk); + + // + return result; +} + +bool IsBearishReversal(int barIndex = 0) +{ + // + bool result = false; + + // + // Normalize ... + barIndex = NormalizeBarIndex(barIndex); + + // + // Validate ... + result = IsValid(); + if (!result) + { + return result; + } + + // + // RSI overbought and turning downward ... + double rsiNow = helper.GetRSI(barIndex); + double rsiPrev = helper.GetRSI(barIndex + 1); + bool rsiFlip = (rsiNow < rsiPrev) && (rsiPrev > 70); + + // + // ATR check (volatility supportive) ... + double atrNow = helper.GetATR(barIndex); + double atrPrev = helper.GetATR(barIndex + 1); + double atrMaNow = helper.GetATRSmoothed(barIndex); + double atrMaPrev = helper.GetATRSmoothed(barIndex + 1); + bool atrOk = atrNow > atrMaNow || atrNow > atrPrev || atrMaNow > atrMaPrev; + + // + // MA crossover bearish ... + double maFastNow = helper.GetMAFast(barIndex); + double maSlowNow = helper.GetMASlow(barIndex); + bool maOk = maFastNow < maSlowNow; + + // + result = rsiFlip && (atrOk || maOk); + + // + return result; +} + +bool IsSafeBullishEntry(int barIndex = 0) +{ + // + bool result = false; + + // + // Normalize ... + barIndex = NormalizeBarIndex(barIndex); + + // + // Validate ... + result = IsValid(); + if (!result) + { + return result; + } + + // + result = IsBullishMomentumTrend(barIndex) && !IsRSIOverbought(barIndex); + return result; +} + +bool IsSafeBearishEntry(int barIndex = 0) +{ + // + bool result = false; + + // + // Normalize ... + barIndex = NormalizeBarIndex(barIndex); + + // + // Validate ... + result = IsValid(); + if (!result) + { + return result; + } + + // + result = IsBearishMomentumTrend(barIndex) && !IsRSIOversold(barIndex); + return result; +} + +bool IsTrendStrongBullish(int barIndex = 0) +{ + // + bool result = false; + + // + // Normalize ... + barIndex = NormalizeBarIndex(barIndex); + + // + // Validate ... + result = IsValid(); + if (!result) + { + return result; + } + + // + // Strong bullish trend requires: + // - KI Fast bullish + // - KI Slow bullish + // - MA crossover bullish + // - RSI > 60 + // - Volatility high + result = IsKIFastBullish(barIndex) && + IsKISlowBullish(barIndex) && + IsMACrossoverBullish(barIndex) && + (helper.GetRSI(barIndex) > 60) && + IsVolatilityHigh(barIndex); + + // + return result; +} + +bool IsTrendStrongBearish(int barIndex = 0) +{ + // + bool result = false; + + // + // Normalize ... + barIndex = NormalizeBarIndex(barIndex); + + // + // Validate ... + result = IsValid(); + if (!result) + { + return result; + } + + // + // Strong bearish trend requires: + // - KI Fast bearish + // - KI Slow bearish + // - MA crossover bearish + // - RSI < 40 + // - Volatility high + result = IsKIFastBearish(barIndex) && + IsKISlowBearish(barIndex) && + IsMACrossoverBearish(barIndex) && + (helper.GetRSI(barIndex) < 40) && + IsVolatilityHigh(barIndex); + + // + return result; +} + +/** + * Counting Touches ... + * + * @param bullish: int reference to holds bullih touches ... + * @param bearish: int reference to holds bearish touches ... + * @param barIndex: int, start Bar Index ... + * @param loopback: int, loopback length for counting ... + * @param countKIFast: boolean, Count KI Fast ... + * @param countKISlow: boolean, Count KI Slow ... + * @param countKIUpper: boolean, Count KI Upper ... + * @param countKILower: boolean, Count KI Lower ... + * @param countMAFast: boolean, Count MA Fast ... + * @param countMASlow: boolean, Count MA Slow ... + * @param forceClean: boolean, Force Clean results before Start Counting ... + * @param priceType: ENUM_X_BOUNDARY_PRICE, Specified Price Type for Boundary Countinf ... + */ +void CountTouches( + int &bullish, + int &bearish, + int barIndex = 0, + int loopback = 5, + bool countKIFast = true, + bool countKISlow = true, + bool countKIUpper = true, + bool countKILower = true, + bool countMAFast = true, + bool countMASlow = true, + bool forceClean = true, + ENUM_X_BOUNDARY_PRICE priceType = X_BOUNDARY_PRICE_HIGH_LOW // +) +{ + // + if (forceClean) + { + bullish = 0; + bearish = 0; + } + + // + // KI Fast ... + if (countKIFast) { // - bool result = false; + // Bullish ... + bullish += CountKIFastTouches( + barIndex, + loopback, + X_DIRECTION_BULLISH, + priceType // + ); // - index = -1; - - // - // Normalize ... - barIndex = kiParser.NormalizeBarIndex(barIndex); - - // - // Loop Back ... - bool isPassed = false; - for (int i = barIndex; i < barIndex + loopback; i++) - { - // - isPassed = kiParser.IsKISlowSwitchedToBullish(i); - if (isPassed) - { - // - index = i; - break; - } - } - - // - result = IsValidIndex(index); - - // - return result; + // Bearish ... + bearish += CountKIFastTouches( + barIndex, + loopback, + X_DIRECTION_BEARISH, + priceType // + ); } - bool NearestKISlowSwitchedToBearish( - int &index, - int barIndex = 0, - int loopback = 50 // - ) + // + // KI Slow ... + if (countKISlow) { // - bool result = false; + // Bullish ... + bullish += CountKISlowTouches( + barIndex, + loopback, + X_DIRECTION_BULLISH, + priceType // + ); // - index = -1; - - // - // Normalize ... - barIndex = kiParser.NormalizeBarIndex(barIndex); - - // - // Loop Back ... - bool isPassed = false; - for (int i = barIndex; i < barIndex + loopback; i++) - { - // - isPassed = kiParser.IsKISlowSwitchedToBearish(i); - if (isPassed) - { - // - index = i; - break; - } - } - - // - result = IsValidIndex(index); - - // - return result; + // Bearish ... + bearish += CountKISlowTouches( + barIndex, + loopback, + X_DIRECTION_BEARISH, + priceType // + ); } - // #endregion + + // + // KI Upper ... + if (countKIUpper) + { + // + // Bullish ... + bullish += CountKIUpperTouches( + barIndex, + loopback, + X_DIRECTION_BULLISH, + priceType // + ); + + // + // Bearish ... + bearish += CountKIUpperTouches( + barIndex, + loopback, + X_DIRECTION_BEARISH, + priceType // + ); + } + + // + // KI Lower ... + if (countKILower) + { + // + // Bullish ... + bullish += CountKILowerTouches( + barIndex, + loopback, + X_DIRECTION_BULLISH, + priceType // + ); + + // + // Bearish ... + bearish += CountKILowerTouches( + barIndex, + loopback, + X_DIRECTION_BEARISH, + priceType // + ); + } + + // + // KI MA Fast ... + if (countMAFast) + { + // + // Bullish ... + bullish += CountMAFastTouches( + barIndex, + loopback, + X_DIRECTION_BULLISH, + priceType // + ); + + // + // Bearish ... + bearish += CountMAFastTouches( + barIndex, + loopback, + X_DIRECTION_BEARISH, + priceType // + ); + } + + // + // KI MA Slow ... + if (countMASlow) + { + // + // Bullish ... + bullish += CountMASlowTouches( + barIndex, + loopback, + X_DIRECTION_BULLISH, + priceType // + ); + + // + // Bearish ... + bearish += CountMASlowTouches( + barIndex, + loopback, + X_DIRECTION_BEARISH, + priceType // + ); + } +} +// #endregion diff --git a/Documents/BKP/X121XKI/tmp.xki.helper.mq5 b/Documents/BKP/X121XKI/tmp.xki.helper.mq5 new file mode 100644 index 00000000..8309b23d --- /dev/null +++ b/Documents/BKP/X121XKI/tmp.xki.helper.mq5 @@ -0,0 +1,825 @@ + + int CountKIFastTouches( + int barIndex = 0, + int loopback = 5, + ENUM_X_DIRECTION forDir = X_DIRECTION_NONE, + ENUM_X_BOUNDARY_PRICE priceType = X_BOUNDARY_PRICE_HIGH_LOW // + ) + { + // + int result = 0; + + // + // Normalize ... + loopback = NormalizeInt(loopback, 1); + barIndex = NormalizeBarIndex(barIndex); + + // + if (!IsValid()) + { + return result; + } + + // + XOHCL iBar; + bool has = false; + double iValue = 0; + double affectedValue = 0; + double iConfirnValue = 0; + bool isBullish = !HasDirection(forDir) || IsXBullish(forDir); + bool isBearish = !HasDirection(forDir) || IsXBearish(forDir); + ENUM_X_PRICE bullishTouchUpperPriceType = priceType == X_BOUNDARY_PRICE_HIGH_LOW + ? X_PRICE_HIGH + : X_PRICE_UP; + ENUM_X_PRICE bullishTouchLowerPriceType = priceType == X_BOUNDARY_PRICE_HIGH_LOW + ? X_PRICE_LOW + : X_PRICE_DOWN; + ENUM_X_PRICE bearishTouchUpperPriceType = priceType == X_BOUNDARY_PRICE_HIGH_LOW + ? X_PRICE_HIGH + : X_PRICE_UP; + ENUM_X_PRICE bearishTouchLowerPriceType = priceType == X_BOUNDARY_PRICE_HIGH_LOW + ? X_PRICE_LOW + : X_PRICE_DOWN; + for (int i = barIndex; i < barIndex + loopback; i++) + { + // + has = iBar.Init(symbol, period, i); + if (!has) + { + continue; + } + + // + affectedValue = helper.GetKIFast(i); + + // + // Bullish Touches ... + if (isBullish) + { + // + iValue = iBar.GetPrice(bullishTouchLowerPriceType); + iConfirnValue = iBar.GetPrice(bullishTouchUpperPriceType); + has = + NotEmptyZero(iValue) && + NotEmptyZero(affectedValue) && + NotEmptyZero(iConfirnValue) && + iValue <= affectedValue && + iConfirnValue >= affectedValue; + if (has) + { + result++; + } + } + + // + // Bearish Touches ... + if (isBearish) + { + // + iValue = iBar.GetPrice(bearishTouchUpperPriceType); + iConfirnValue = iBar.GetPrice(bearishTouchLowerPriceType); + has = + NotEmptyZero(iValue) && + NotEmptyZero(affectedValue) && + NotEmptyZero(iConfirnValue) && + iValue >= affectedValue && + iConfirnValue <= affectedValue; + if (has) + { + result++; + } + } + + // + iBar.Clean(); + } + + // + iBar.Clean(); + + // + return result; + } + + + int CountKISlowTouches( + int barIndex = 0, + int loopback = 5, + ENUM_X_DIRECTION forDir = X_DIRECTION_NONE, + ENUM_X_BOUNDARY_PRICE priceType = X_BOUNDARY_PRICE_HIGH_LOW // + ) + { + // + int result = 0; + + // + // Normalize ... + loopback = NormalizeInt(loopback, 1); + barIndex = NormalizeBarIndex(barIndex); + + // + if (!IsValid()) + { + return result; + } + + // + XOHCL iBar; + bool has = false; + double iValue = 0; + double affectedValue = 0; + double iConfirnValue = 0; + bool isBullish = !HasDirection(forDir) || IsXBullish(forDir); + bool isBearish = !HasDirection(forDir) || IsXBearish(forDir); + ENUM_X_PRICE bullishTouchUpperPriceType = priceType == X_BOUNDARY_PRICE_HIGH_LOW + ? X_PRICE_HIGH + : X_PRICE_UP; + ENUM_X_PRICE bullishTouchLowerPriceType = priceType == X_BOUNDARY_PRICE_HIGH_LOW + ? X_PRICE_LOW + : X_PRICE_DOWN; + ENUM_X_PRICE bearishTouchUpperPriceType = priceType == X_BOUNDARY_PRICE_HIGH_LOW + ? X_PRICE_HIGH + : X_PRICE_UP; + ENUM_X_PRICE bearishTouchLowerPriceType = priceType == X_BOUNDARY_PRICE_HIGH_LOW + ? X_PRICE_LOW + : X_PRICE_DOWN; + for (int i = barIndex; i < barIndex + loopback; i++) + { + // + has = iBar.Init(symbol, period, i); + if (!has) + { + continue; + } + + // + affectedValue = helper.GetKISlow(i); + + // + // Bullish Touches ... + if (isBullish) + { + // + iValue = iBar.GetPrice(bullishTouchLowerPriceType); + iConfirnValue = iBar.GetPrice(bullishTouchUpperPriceType); + has = + NotEmptyZero(iValue) && + NotEmptyZero(affectedValue) && + NotEmptyZero(iConfirnValue) && + iValue <= affectedValue && + iConfirnValue >= affectedValue; + if (has) + { + result++; + } + } + + // + // Bearish Touches ... + if (isBearish) + { + // + iValue = iBar.GetPrice(bearishTouchUpperPriceType); + iConfirnValue = iBar.GetPrice(bearishTouchLowerPriceType); + has = + NotEmptyZero(iValue) && + NotEmptyZero(affectedValue) && + NotEmptyZero(iConfirnValue) && + iValue >= affectedValue && + iConfirnValue <= affectedValue; + if (has) + { + result++; + } + } + + // + iBar.Clean(); + } + + // + iBar.Clean(); + + // + return result; + } + + + int CountKISuperSlowTouches( + int barIndex = 0, + int loopback = 5, + ENUM_X_DIRECTION forDir = X_DIRECTION_NONE, + ENUM_X_BOUNDARY_PRICE priceType = X_BOUNDARY_PRICE_HIGH_LOW // + ) + { + // + int result = 0; + + // + // Normalize ... + loopback = NormalizeInt(loopback, 1); + barIndex = NormalizeBarIndex(barIndex); + + // + if (!IsValid()) + { + return result; + } + + // + XOHCL iBar; + bool has = false; + double iValue = 0; + double affectedValue = 0; + double iConfirnValue = 0; + bool isBullish = !HasDirection(forDir) || IsXBullish(forDir); + bool isBearish = !HasDirection(forDir) || IsXBearish(forDir); + ENUM_X_PRICE bullishTouchUpperPriceType = priceType == X_BOUNDARY_PRICE_HIGH_LOW + ? X_PRICE_HIGH + : X_PRICE_UP; + ENUM_X_PRICE bullishTouchLowerPriceType = priceType == X_BOUNDARY_PRICE_HIGH_LOW + ? X_PRICE_LOW + : X_PRICE_DOWN; + ENUM_X_PRICE bearishTouchUpperPriceType = priceType == X_BOUNDARY_PRICE_HIGH_LOW + ? X_PRICE_HIGH + : X_PRICE_UP; + ENUM_X_PRICE bearishTouchLowerPriceType = priceType == X_BOUNDARY_PRICE_HIGH_LOW + ? X_PRICE_LOW + : X_PRICE_DOWN; + for (int i = barIndex; i < barIndex + loopback; i++) + { + // + has = iBar.Init(symbol, period, i); + if (!has) + { + continue; + } + + // + affectedValue = helper.GetKISuperSlow(i); + + // + // Bullish Touches ... + if (isBullish) + { + // + iValue = iBar.GetPrice(bullishTouchLowerPriceType); + iConfirnValue = iBar.GetPrice(bullishTouchUpperPriceType); + has = + NotEmptyZero(iValue) && + NotEmptyZero(affectedValue) && + NotEmptyZero(iConfirnValue) && + iValue <= affectedValue && + iConfirnValue >= affectedValue; + if (has) + { + result++; + } + } + + // + // Bearish Touches ... + if (isBearish) + { + // + iValue = iBar.GetPrice(bearishTouchUpperPriceType); + iConfirnValue = iBar.GetPrice(bearishTouchLowerPriceType); + has = + NotEmptyZero(iValue) && + NotEmptyZero(affectedValue) && + NotEmptyZero(iConfirnValue) && + iValue >= affectedValue && + iConfirnValue <= affectedValue; + if (has) + { + result++; + } + } + + // + iBar.Clean(); + } + + // + iBar.Clean(); + + // + return result; + } + + + int CountKIUpperTouches( + int barIndex = 0, + int loopback = 5, + ENUM_X_DIRECTION forDir = X_DIRECTION_NONE, + ENUM_X_BOUNDARY_PRICE priceType = X_BOUNDARY_PRICE_HIGH_LOW // + ) + { + // + int result = 0; + + // + // Normalize ... + loopback = NormalizeInt(loopback, 1); + barIndex = NormalizeBarIndex(barIndex); + + // + if (!IsValid()) + { + return result; + } + + // + XOHCL iBar; + bool has = false; + double iValue = 0; + double affectedValue = 0; + double iConfirnValue = 0; + bool isBullish = !HasDirection(forDir) || IsXBullish(forDir); + bool isBearish = !HasDirection(forDir) || IsXBearish(forDir); + ENUM_X_PRICE bullishTouchUpperPriceType = priceType == X_BOUNDARY_PRICE_HIGH_LOW + ? X_PRICE_HIGH + : X_PRICE_UP; + ENUM_X_PRICE bullishTouchLowerPriceType = priceType == X_BOUNDARY_PRICE_HIGH_LOW + ? X_PRICE_LOW + : X_PRICE_DOWN; + ENUM_X_PRICE bearishTouchUpperPriceType = priceType == X_BOUNDARY_PRICE_HIGH_LOW + ? X_PRICE_HIGH + : X_PRICE_UP; + ENUM_X_PRICE bearishTouchLowerPriceType = priceType == X_BOUNDARY_PRICE_HIGH_LOW + ? X_PRICE_LOW + : X_PRICE_DOWN; + for (int i = barIndex; i < barIndex + loopback; i++) + { + // + has = iBar.Init(symbol, period, i); + if (!has) + { + continue; + } + + // + affectedValue = helper.GetKIUpper(i); + + // + // Bullish Touches ... + if (isBullish) + { + // + iValue = iBar.GetPrice(bullishTouchLowerPriceType); + iConfirnValue = iBar.GetPrice(bullishTouchUpperPriceType); + has = + NotEmptyZero(iValue) && + NotEmptyZero(affectedValue) && + NotEmptyZero(iConfirnValue) && + iValue <= affectedValue && + iConfirnValue >= affectedValue; + if (has) + { + result++; + } + } + + // + // Bearish Touches ... + if (isBearish) + { + // + iValue = iBar.GetPrice(bearishTouchUpperPriceType); + iConfirnValue = iBar.GetPrice(bearishTouchLowerPriceType); + has = + NotEmptyZero(iValue) && + NotEmptyZero(affectedValue) && + NotEmptyZero(iConfirnValue) && + iValue >= affectedValue && + iConfirnValue <= affectedValue; + if (has) + { + result++; + } + } + + // + iBar.Clean(); + } + + // + iBar.Clean(); + + // + return result; + } + + + int CountKILowerTouches( + int barIndex = 0, + int loopback = 5, + ENUM_X_DIRECTION forDir = X_DIRECTION_NONE, + ENUM_X_BOUNDARY_PRICE priceType = X_BOUNDARY_PRICE_HIGH_LOW // + ) + { + // + int result = 0; + + // + // Normalize ... + loopback = NormalizeInt(loopback, 1); + barIndex = NormalizeBarIndex(barIndex); + + // + if (!IsValid()) + { + return result; + } + + // + XOHCL iBar; + bool has = false; + double iValue = 0; + double affectedValue = 0; + double iConfirnValue = 0; + bool isBullish = !HasDirection(forDir) || IsXBullish(forDir); + bool isBearish = !HasDirection(forDir) || IsXBearish(forDir); + ENUM_X_PRICE bullishTouchUpperPriceType = priceType == X_BOUNDARY_PRICE_HIGH_LOW + ? X_PRICE_HIGH + : X_PRICE_UP; + ENUM_X_PRICE bullishTouchLowerPriceType = priceType == X_BOUNDARY_PRICE_HIGH_LOW + ? X_PRICE_LOW + : X_PRICE_DOWN; + ENUM_X_PRICE bearishTouchUpperPriceType = priceType == X_BOUNDARY_PRICE_HIGH_LOW + ? X_PRICE_HIGH + : X_PRICE_UP; + ENUM_X_PRICE bearishTouchLowerPriceType = priceType == X_BOUNDARY_PRICE_HIGH_LOW + ? X_PRICE_LOW + : X_PRICE_DOWN; + for (int i = barIndex; i < barIndex + loopback; i++) + { + // + has = iBar.Init(symbol, period, i); + if (!has) + { + continue; + } + + // + affectedValue = helper.GetKILower(i); + + // + // Bullish Touches ... + if (isBullish) + { + // + iValue = iBar.GetPrice(bullishTouchLowerPriceType); + iConfirnValue = iBar.GetPrice(bullishTouchUpperPriceType); + has = + NotEmptyZero(iValue) && + NotEmptyZero(affectedValue) && + NotEmptyZero(iConfirnValue) && + iValue <= affectedValue && + iConfirnValue >= affectedValue; + if (has) + { + result++; + } + } + + // + // Bearish Touches ... + if (isBearish) + { + // + iValue = iBar.GetPrice(bearishTouchUpperPriceType); + iConfirnValue = iBar.GetPrice(bearishTouchLowerPriceType); + has = + NotEmptyZero(iValue) && + NotEmptyZero(affectedValue) && + NotEmptyZero(iConfirnValue) && + iValue >= affectedValue && + iConfirnValue <= affectedValue; + if (has) + { + result++; + } + } + + // + iBar.Clean(); + } + + // + iBar.Clean(); + + // + return result; + } + + + int CountMAFastTouches( + int barIndex = 0, + int loopback = 5, + ENUM_X_DIRECTION forDir = X_DIRECTION_NONE, + ENUM_X_BOUNDARY_PRICE priceType = X_BOUNDARY_PRICE_HIGH_LOW // + ) + { + // + int result = 0; + + // + // Normalize ... + loopback = NormalizeInt(loopback, 1); + barIndex = NormalizeBarIndex(barIndex); + + // + if (!IsValid()) + { + return result; + } + + // + XOHCL iBar; + bool has = false; + double iValue = 0; + double affectedValue = 0; + double iConfirnValue = 0; + bool isBullish = !HasDirection(forDir) || IsXBullish(forDir); + bool isBearish = !HasDirection(forDir) || IsXBearish(forDir); + ENUM_X_PRICE bullishTouchUpperPriceType = priceType == X_BOUNDARY_PRICE_HIGH_LOW + ? X_PRICE_HIGH + : X_PRICE_UP; + ENUM_X_PRICE bullishTouchLowerPriceType = priceType == X_BOUNDARY_PRICE_HIGH_LOW + ? X_PRICE_LOW + : X_PRICE_DOWN; + ENUM_X_PRICE bearishTouchUpperPriceType = priceType == X_BOUNDARY_PRICE_HIGH_LOW + ? X_PRICE_HIGH + : X_PRICE_UP; + ENUM_X_PRICE bearishTouchLowerPriceType = priceType == X_BOUNDARY_PRICE_HIGH_LOW + ? X_PRICE_LOW + : X_PRICE_DOWN; + for (int i = barIndex; i < barIndex + loopback; i++) + { + // + has = iBar.Init(symbol, period, i); + if (!has) + { + continue; + } + + // + affectedValue = helper.GetMAFast(i); + + // + // Bullish Touches ... + if (isBullish) + { + // + iValue = iBar.GetPrice(bullishTouchLowerPriceType); + iConfirnValue = iBar.GetPrice(bullishTouchUpperPriceType); + has = + NotEmptyZero(iValue) && + NotEmptyZero(affectedValue) && + NotEmptyZero(iConfirnValue) && + iValue <= affectedValue && + iConfirnValue >= affectedValue; + if (has) + { + result++; + } + } + + // + // Bearish Touches ... + if (isBearish) + { + // + iValue = iBar.GetPrice(bearishTouchUpperPriceType); + iConfirnValue = iBar.GetPrice(bearishTouchLowerPriceType); + has = + NotEmptyZero(iValue) && + NotEmptyZero(affectedValue) && + NotEmptyZero(iConfirnValue) && + iValue >= affectedValue && + iConfirnValue <= affectedValue; + if (has) + { + result++; + } + } + + // + iBar.Clean(); + } + + // + iBar.Clean(); + + // + return result; + } + + + int CountMASlowTouches( + int barIndex = 0, + int loopback = 5, + ENUM_X_DIRECTION forDir = X_DIRECTION_NONE, + ENUM_X_BOUNDARY_PRICE priceType = X_BOUNDARY_PRICE_HIGH_LOW // + ) + { + // + int result = 0; + + // + // Normalize ... + loopback = NormalizeInt(loopback, 1); + barIndex = NormalizeBarIndex(barIndex); + + // + if (!IsValid()) + { + return result; + } + + // + XOHCL iBar; + bool has = false; + double iValue = 0; + double affectedValue = 0; + double iConfirnValue = 0; + bool isBullish = !HasDirection(forDir) || IsXBullish(forDir); + bool isBearish = !HasDirection(forDir) || IsXBearish(forDir); + ENUM_X_PRICE bullishTouchUpperPriceType = priceType == X_BOUNDARY_PRICE_HIGH_LOW + ? X_PRICE_HIGH + : X_PRICE_UP; + ENUM_X_PRICE bullishTouchLowerPriceType = priceType == X_BOUNDARY_PRICE_HIGH_LOW + ? X_PRICE_LOW + : X_PRICE_DOWN; + ENUM_X_PRICE bearishTouchUpperPriceType = priceType == X_BOUNDARY_PRICE_HIGH_LOW + ? X_PRICE_HIGH + : X_PRICE_UP; + ENUM_X_PRICE bearishTouchLowerPriceType = priceType == X_BOUNDARY_PRICE_HIGH_LOW + ? X_PRICE_LOW + : X_PRICE_DOWN; + for (int i = barIndex; i < barIndex + loopback; i++) + { + // + has = iBar.Init(symbol, period, i); + if (!has) + { + continue; + } + + // + affectedValue = helper.GetMASlow(i); + + // + // Bullish Touches ... + if (isBullish) + { + // + iValue = iBar.GetPrice(bullishTouchLowerPriceType); + iConfirnValue = iBar.GetPrice(bullishTouchUpperPriceType); + has = + NotEmptyZero(iValue) && + NotEmptyZero(affectedValue) && + NotEmptyZero(iConfirnValue) && + iValue <= affectedValue && + iConfirnValue >= affectedValue; + if (has) + { + result++; + } + } + + // + // Bearish Touches ... + if (isBearish) + { + // + iValue = iBar.GetPrice(bearishTouchUpperPriceType); + iConfirnValue = iBar.GetPrice(bearishTouchLowerPriceType); + has = + NotEmptyZero(iValue) && + NotEmptyZero(affectedValue) && + NotEmptyZero(iConfirnValue) && + iValue >= affectedValue && + iConfirnValue <= affectedValue; + if (has) + { + result++; + } + } + + // + iBar.Clean(); + } + + // + iBar.Clean(); + + // + return result; + } + + + int CountMASuperSlowTouches( + int barIndex = 0, + int loopback = 5, + ENUM_X_DIRECTION forDir = X_DIRECTION_NONE, + ENUM_X_BOUNDARY_PRICE priceType = X_BOUNDARY_PRICE_HIGH_LOW // + ) + { + // + int result = 0; + + // + // Normalize ... + loopback = NormalizeInt(loopback, 1); + barIndex = NormalizeBarIndex(barIndex); + + // + if (!IsValid()) + { + return result; + } + + // + XOHCL iBar; + bool has = false; + double iValue = 0; + double affectedValue = 0; + double iConfirnValue = 0; + bool isBullish = !HasDirection(forDir) || IsXBullish(forDir); + bool isBearish = !HasDirection(forDir) || IsXBearish(forDir); + ENUM_X_PRICE bullishTouchUpperPriceType = priceType == X_BOUNDARY_PRICE_HIGH_LOW + ? X_PRICE_HIGH + : X_PRICE_UP; + ENUM_X_PRICE bullishTouchLowerPriceType = priceType == X_BOUNDARY_PRICE_HIGH_LOW + ? X_PRICE_LOW + : X_PRICE_DOWN; + ENUM_X_PRICE bearishTouchUpperPriceType = priceType == X_BOUNDARY_PRICE_HIGH_LOW + ? X_PRICE_HIGH + : X_PRICE_UP; + ENUM_X_PRICE bearishTouchLowerPriceType = priceType == X_BOUNDARY_PRICE_HIGH_LOW + ? X_PRICE_LOW + : X_PRICE_DOWN; + for (int i = barIndex; i < barIndex + loopback; i++) + { + // + has = iBar.Init(symbol, period, i); + if (!has) + { + continue; + } + + // + affectedValue = helper.GetMASuperSlow(i); + + // + // Bullish Touches ... + if (isBullish) + { + // + iValue = iBar.GetPrice(bullishTouchLowerPriceType); + iConfirnValue = iBar.GetPrice(bullishTouchUpperPriceType); + has = + NotEmptyZero(iValue) && + NotEmptyZero(affectedValue) && + NotEmptyZero(iConfirnValue) && + iValue <= affectedValue && + iConfirnValue >= affectedValue; + if (has) + { + result++; + } + } + + // + // Bearish Touches ... + if (isBearish) + { + // + iValue = iBar.GetPrice(bearishTouchUpperPriceType); + iConfirnValue = iBar.GetPrice(bearishTouchLowerPriceType); + has = + NotEmptyZero(iValue) && + NotEmptyZero(affectedValue) && + NotEmptyZero(iConfirnValue) && + iValue >= affectedValue && + iConfirnValue <= affectedValue; + if (has) + { + result++; + } + } + + // + iBar.Clean(); + } + + // + iBar.Clean(); + + // + return result; + } + + diff --git a/Documents/Diagrams/MQL5.X121XKI.Board.kanban b/Documents/Diagrams/MQL5.X121XKI.Board.kanban index 09313d18..66f22db7 100644 --- a/Documents/Diagrams/MQL5.X121XKI.Board.kanban +++ b/Documents/Diagrams/MQL5.X121XKI.Board.kanban @@ -8,22 +8,21 @@ { "id": "61ca33e6-05e4-4b44-b88d-3bc8ae5cba86", "title": "To Do", - "cards": [ - { - "id": "a59a73f4-1ab4-477b-893e-b2dfb71fe6ea", - "listId": "61ca33e6-05e4-4b44-b88d-3bc8ae5cba86", - "title": "Add Support for PV in XKI Indicator.", - "description": "", - "labels": [], - "checkboxes": [], - "comments": [] - } - ] + "cards": [] }, { "id": "6f8db3d6-fcaa-4522-bee5-0e3e38c96e73", "title": "Doing", "cards": [ + { + "id": "a59a73f4-1ab4-477b-893e-b2dfb71fe6ea", + "listId": "6f8db3d6-fcaa-4522-bee5-0e3e38c96e73", + "title": "Add Support for PV in XKI Indicator.", + "description": "", + "labels": [], + "checkboxes": [], + "comments": [] + }, { "id": "f8eb6951-f337-40da-9b98-e468f77709fd", "listId": "6f8db3d6-fcaa-4522-bee5-0e3e38c96e73", @@ -57,6 +56,506 @@ "labels": [], "checkboxes": [], "comments": [] + }, + { + "id": "bcb422f9-89db-4816-ba3a-bae95c9c8da4", + "listId": "6f8db3d6-fcaa-4522-bee5-0e3e38c96e73", + "title": "Test all XKI Helper Functions", + "description": "Test all KI Parser Conditional Tools ...\n ", + "labels": [], + "checkboxes": [ + { + "id": "987aadc7-1775-4ddb-96a8-c7867b41c5dc", + "title": "IsKIFastBullish", + "checked": true + }, + { + "id": "33d30e91-1d65-4cc9-8955-4fcdac1a1a1c", + "title": "IsKIFastBearish", + "checked": true + }, + { + "id": "f5efdef3-3dd5-4a67-9335-27ade4a08119", + "title": "IsKIFastSwitchedToBullish", + "checked": true + }, + { + "id": "95fd5f87-3076-4a10-9d1d-2190c74e77dc", + "title": "IsKIFastSwitchedToBearish", + "checked": true + }, + { + "id": "5848cd3c-7f60-4310-adde-56d0e80896a2", + "title": "IsKIFastOverLast", + "checked": true + }, + { + "id": "879b6657-8a36-4329-9edd-2b5243733c37", + "title": "IsKIFastUnderLast", + "checked": true + }, + { + "id": "7ebd6627-2bd7-47b1-9b3c-51643a446cb3", + "title": "IsKIFastSameAsLast", + "checked": true + }, + { + "id": "4533e930-8c54-45ea-95b8-a95aa9278bd8", + "title": "IsKIFastSwitchedOverLast", + "checked": true + }, + { + "id": "1231584a-5181-457b-8f31-02da2962c54a", + "title": "IsKIFastSwitchedUnderLast", + "checked": true + }, + { + "id": "67f9ccdb-eff3-4e1e-945b-5232773f16f5", + "title": "IsKISlowBullish", + "checked": true + }, + { + "id": "2262f093-f7c9-4a73-983c-055b6098f915", + "title": "IsKISlowBearish", + "checked": true + }, + { + "id": "0e6b67fe-0ff5-4783-a4e3-36b3a70007f5", + "title": "IsKISlowSwitchedToBullish", + "checked": true + }, + { + "id": "0ec4ea00-63bc-4059-92e2-46afa6793325", + "title": "IsKISlowSwitchedToBearish", + "checked": true + }, + { + "id": "cf71aa02-fbf9-4f42-a4f2-791353cc290e", + "title": "IsKISlowOverLast", + "checked": true + }, + { + "id": "da046ac2-0ed5-4c45-ba5b-ffd31a1f65a3", + "title": "IsKISlowUnderLast", + "checked": true + }, + { + "id": "f57c9dde-9294-4909-b5c8-4a8a9a661072", + "title": "IsKISlowSameAsLast", + "checked": true + }, + { + "id": "c52951e5-7a57-4823-a061-9d7a4aa9f0f4", + "title": "IsKISlowSwitchedOverLast", + "checked": true + }, + { + "id": "9e523117-d742-4ffa-ae7d-cbd995b6bc61", + "title": "IsKISlowSwitchedUnderLast", + "checked": true + }, + { + "id": "3ae34a28-6172-4209-832d-41647e45c072", + "title": "IsKISuperSlowBullish", + "checked": true + }, + { + "id": "a7720bdf-2535-430f-9f55-81fa2d281910", + "title": "IsKISuperSlowBearish", + "checked": true + }, + { + "id": "b03e521f-d1b4-4e83-9aaa-6a65297420d5", + "title": "IsKISuperSlowSwitchedToBullish", + "checked": true + }, + { + "id": "3a59a397-816d-4e41-93cd-cab889ebcc1e", + "title": "IsKISuperSlowSwitchedToBearish", + "checked": true + }, + { + "id": "315380e3-702b-41bf-abf5-4b85c0e00ce4", + "title": "IsKISuperSlowOverLast", + "checked": true + }, + { + "id": "3a18f5b6-f18e-43d8-b8e6-43fc530ac80d", + "title": "IsKISuperSlowUnderLast", + "checked": true + }, + { + "id": "4174d12c-382f-4615-9a65-99c447fa6a2a", + "title": "IsKISuperSlowSameAsLast", + "checked": true + }, + { + "id": "03c1fc35-b0c4-477f-ab30-d183a990aff1", + "title": "IsKISuperSlowSwitchedOverLast", + "checked": true + }, + { + "id": "82f549d7-6afa-4408-9d3a-d41d4d623bb7", + "title": "IsKISuperSlowSwitchedUnderLast", + "checked": true + }, + { + "id": "abd7362a-29ba-4f92-9fe0-0496ccb7e9c6", + "title": "IsKIWaveBullish", + "checked": false + }, + { + "id": "440e446f-9aa9-4f74-a950-63a013b42fa5", + "title": "IsKIWaveBearish", + "checked": false + }, + { + "id": "2606bddb-aae1-4cca-8a29-b11c9f7015e6", + "title": "IsKIWaveSwitchedToBullish", + "checked": false + }, + { + "id": "2036fddf-c4eb-4c5d-a550-d3f84341e78b", + "title": "IsKIWaveSwitchedToBearish", + "checked": false + }, + { + "id": "649905b4-d0e9-4009-aeda-08a633861201", + "title": "IsKIWaveOverLast", + "checked": false + }, + { + "id": "cc181a1f-298a-438d-afc8-74b0d4200228", + "title": "IsKIWaveUnderLast", + "checked": false + }, + { + "id": "66bafec6-7794-4650-8919-d6409b49fbdf", + "title": "IsKIWaveSwitchedOverLast", + "checked": false + }, + { + "id": "a5a714cb-ea11-42e3-8e9c-8745405998ae", + "title": "IsKIWaveSwitchedUnderLast", + "checked": false + }, + { + "id": "b94e9071-5f85-4a38-828c-7cf8a1e99a63", + "title": "IsPriceOverKIUpper", + "checked": false + }, + { + "id": "c3a7d88b-c81f-46d4-a3cc-a0d1f5597371", + "title": "IsPriceUnderKIUpper", + "checked": false + }, + { + "id": "1efcb06a-0edd-41d0-8e8b-18cba4f64226", + "title": "IsPriceOverKILower", + "checked": false + }, + { + "id": "7e95d7e0-a50f-412b-a024-2568bf66c3f1", + "title": "IsPriceUnderKILower", + "checked": false + }, + { + "id": "d747f70e-af68-42f1-a621-efd3ce518b47", + "title": "IsPriceInsideKIBands", + "checked": false + }, + { + "id": "f534622b-5a7f-4c9c-85ed-c562d907fd89", + "title": "IsPriceSwitchedOverKIUpper", + "checked": false + }, + { + "id": "8e559cb9-f6a9-412e-8882-e622030cf838", + "title": "IsPriceSwitchedUnderKIUpper", + "checked": false + }, + { + "id": "b16ad1a1-1fb2-4bb6-b2f8-f9310d012f4f", + "title": "IsPriceSwitchedOverKILower", + "checked": false + }, + { + "id": "dd0deb1f-a259-4ce9-a471-92e268e10abe", + "title": "IsPriceSwitchedUnderKILower", + "checked": false + }, + { + "id": "ebf997ee-8944-4442-86fb-6d01ea64b8a6", + "title": "IsMAFastBullish", + "checked": false + }, + { + "id": "11eb8b4c-004c-4272-921f-4067315aac6a", + "title": "IsMAFastBearish", + "checked": false + }, + { + "id": "90451b0f-ec2e-48e0-8797-7f48cedf743c", + "title": "IsMAFastOverLast", + "checked": false + }, + { + "id": "6158296f-fec3-443e-826b-84a481225013", + "title": "IsMAFastUnderLast", + "checked": false + }, + { + "id": "14210197-c670-4f49-8935-b65926945837", + "title": "IsMAFastSwitchedOverLast", + "checked": false + }, + { + "id": "e84b372e-fbdc-45da-a604-76a0fc6381c4", + "title": "IsMAFastSwitchedUnderLast", + "checked": false + }, + { + "id": "e756a5d0-4477-4277-be7d-5897079add6a", + "title": "IsMAFastSwitchedToBullish", + "checked": false + }, + { + "id": "548819d7-06fa-4ca5-adf2-c4c2d3064d7e", + "title": "IsMAFastSwitchedToBearish", + "checked": false + }, + { + "id": "ef0feb55-069c-4e9a-a56e-de05f6b6801f", + "title": "IsMASlowBullish", + "checked": false + }, + { + "id": "630cd36a-f848-44d6-958b-728c4757df6e", + "title": "IsMASlowBearish", + "checked": false + }, + { + "id": "acca2b2e-27d6-44dc-bd7f-98857e1b7e64", + "title": "IsMASlowOverLast", + "checked": false + }, + { + "id": "49631b5a-8b69-4649-a47d-bef5bda3e137", + "title": "IsMASlowUnderLast", + "checked": false + }, + { + "id": "762fd136-113c-444f-8373-2104bc4db466", + "title": "IsMASlowSwitchedOverLast", + "checked": false + }, + { + "id": "3cd7c2a1-8a8a-4aba-85c2-6279a356c49e", + "title": "IsMASlowSwitchedUnderLast", + "checked": false + }, + { + "id": "0568553a-8ad1-4588-834e-26befe2a9bbb", + "title": "IsMASlowSwitchedToBullish", + "checked": false + }, + { + "id": "62899e4a-87da-4fc9-8b4b-f1b8b077c177", + "title": "IsMASlowSwitchedToBearish", + "checked": false + }, + { + "id": "43bbc4df-7601-4460-b636-61b73b30f10a", + "title": "IsMASuperSlowBullish", + "checked": false + }, + { + "id": "91c30277-6ea9-40e8-8467-d06beabf486b", + "title": "IsMASuperSlowBearish", + "checked": false + }, + { + "id": "0a102b6a-fabe-4aba-938f-d87a22e11b5e", + "title": "IsMASuperSlowOverLast", + "checked": false + }, + { + "id": "97e4a349-77c8-4997-8f1b-875fff8229ab", + "title": "IsMASuperSlowUnderLast", + "checked": false + }, + { + "id": "cc1a7131-227d-4007-82ed-78c8cc9ef33e", + "title": "IsMASuperSlowSwitchedOverLast", + "checked": false + }, + { + "id": "93899467-f06d-420a-ac6e-e645c8c07389", + "title": "IsMASuperSlowSwitchedUnderLast", + "checked": false + }, + { + "id": "a64507e6-c99a-4e6a-a995-c1be671d1083", + "title": "IsMASuperSlowSwitchedToBullish", + "checked": false + }, + { + "id": "65295670-87f7-481c-ab9e-a92c8606923f", + "title": "IsMASuperSlowSwitchedToBearish", + "checked": false + }, + { + "id": "2cbc64ba-1882-47a6-9206-7b25e8008395", + "title": "IsMACrossoverBullish", + "checked": false + }, + { + "id": "44b233e6-5a56-4f3a-9c28-60e11aa2059a", + "title": "IsMACrossoverBearish", + "checked": false + }, + { + "id": "d7af351b-1de4-4ca9-958a-388d944d4fa9", + "title": "IsMACrossoverSwitchedToBullish", + "checked": false + }, + { + "id": "5af39475-d1f8-477f-b867-5359aaaf94fa", + "title": "IsMACrossoverSwitchedToBearish", + "checked": false + }, + { + "id": "dd69c2c0-c999-4235-8cb5-74607b27c7ec", + "title": "IsATRBreakoutUp", + "checked": false + }, + { + "id": "1a77e8e1-b3e8-48b4-b072-1cda3a69c6f9", + "title": "IsATRBreakoutDown", + "checked": false + }, + { + "id": "bfeb3c24-f0ed-4aed-99af-bec8db026a62", + "title": "IsATROverLast", + "checked": false + }, + { + "id": "62881e04-9b38-49e4-ae9d-e5161c1b0b5c", + "title": "IsATRUnderLast", + "checked": false + }, + { + "id": "33ec5ba0-d31a-4602-ba79-7d3b4d9d7986", + "title": "IsATRSwitchedOverLast", + "checked": false + }, + { + "id": "cf0fb674-8dfc-4ed1-b1dd-5a8447d818a4", + "title": "IsATRSwitchedUnderLast", + "checked": false + }, + { + "id": "ab07c8e5-454c-4c9b-a69d-fa2e8330a2e0", + "title": "IsVolatilityHigh", + "checked": false + }, + { + "id": "031521be-0062-4d07-ade4-ff17782888c7", + "title": "IsVolatilityLow", + "checked": false + }, + { + "id": "49376783-45aa-4a57-a304-3547babf0ccd", + "title": "IsVolatilitySwitchdToHigh", + "checked": false + }, + { + "id": "5803601b-9143-471d-968f-59622d37b70a", + "title": "IsVolatilitySwitchdToLow", + "checked": false + }, + { + "id": "0ab99ddc-75b8-45c7-9140-8cd3dc6921c6", + "title": "IsRSIBullish", + "checked": false + }, + { + "id": "ba39f76c-2257-48fe-94ca-addf2148ee23", + "title": "IsRSIBearish", + "checked": false + }, + { + "id": "91c098b3-56d8-4728-b411-edf7e42d60b0", + "title": "IsRSIOverbought", + "checked": false + }, + { + "id": "7917431d-9bc9-4514-8aea-7fae7c11b0de", + "title": "IsRSIOversold", + "checked": false + }, + { + "id": "83d4b28b-fe6c-411c-a209-c57e3c8251d0", + "title": "IsRSISwitchedToOverSold", + "checked": false + }, + { + "id": "96493d94-9db6-49de-a7f1-e3990b9469b8", + "title": "IsRSISwitchedFromOverSold", + "checked": false + }, + { + "id": "02579268-284f-40f3-93c9-0cb3f70d103a", + "title": "IsRSISwitchedToOverbought", + "checked": false + }, + { + "id": "6c473b2e-1b37-44b2-a08c-ce6217d0c00e", + "title": "IsRSISwitchedFromOverbought", + "checked": false + }, + { + "id": "30177c7a-47df-4d90-8132-0f467ebc071c", + "title": "IsRSISwitchedToBullish", + "checked": false + }, + { + "id": "a3e07f9c-72da-49b4-8101-f742644a2b81", + "title": "IsRSISwitchedToBearish", + "checked": false + }, + { + "id": "d2a8183b-3553-4016-8155-a114c70da5ec", + "title": "IsPeakSameAsLast", + "checked": false + }, + { + "id": "7395f77c-7491-417e-8ca8-a41923b46b68", + "title": "IsPeakOverLast", + "checked": false + }, + { + "id": "afdae94d-1a14-408d-b1bd-e84c0868a655", + "title": "IsPeakUnderLast", + "checked": false + }, + { + "id": "45f52be4-1f08-4e7a-b15b-d8db48752449", + "title": "IsValeSameAsLast", + "checked": false + }, + { + "id": "ebc003bc-850d-44e2-a0ed-5ddaba71ae1a", + "title": "IsValeOverLast", + "checked": false + }, + { + "id": "c979f0c3-e356-4fa6-bead-596e4a06b962", + "title": "IsValeUnderLast", + "checked": false + } + ], + "comments": [] } ] }, diff --git a/Helpers/x-saherelm.x121.xki.helper.mq5 b/Helpers/x-saherelm.x121.xki.helper.mq5 index 531a1d14..b6817114 100644 --- a/Helpers/x-saherelm.x121.xki.helper.mq5 +++ b/Helpers/x-saherelm.x121.xki.helper.mq5 @@ -24,6 +24,140 @@ // Imports ... #include "../Classes/x-saherelm.x-helper.class.mq5" +// #region Definitions ... +enum ENUM_X121_XKI_BUFFER_NAME +{ + X121_XKI_NONE = 0, + X121_XKI_FAST = 1, + X121_XKI_SLOW = 2, + X121_XKI_SUPER_SLOW = 3, + X121_XKI_UPPER = 4, + X121_XKI_LOWER = 5, + X121_XKI_WAVE = 6, + X121_XKI_MA_FAST = 7, + X121_XKI_MA_SLOW = 8, + X121_XKI_MA_SUPER_SLOW = 9, + X121_XKI_MA_CROSS = 10, + X121_XKI_ATR = 11, +}; + +bool IsXValid(ENUM_X121_XKI_BUFFER_NAME value) +{ + return value != X121_XKI_NONE; +} +string ToXString(ENUM_X121_XKI_BUFFER_NAME value) +{ + // + string result = NULL; + + // + if (IsXValid(value)) + { + // + switch (value) + { + // + case X121_XKI_FAST: + result = "FAST"; + break; + + // + case X121_XKI_SLOW: + result = "SLOW"; + break; + + // + case X121_XKI_SUPER_SLOW: + result = "SUPER_SLOW"; + break; + + // + case X121_XKI_UPPER: + result = "UPPER"; + break; + + // + case X121_XKI_LOWER: + result = "LOWER"; + break; + + // + case X121_XKI_WAVE: + result = "WAVE"; + break; + + // + case X121_XKI_MA_FAST: + result = "MA_FAST"; + break; + + // + case X121_XKI_MA_SLOW: + result = "MA_SLOW"; + break; + + // + case X121_XKI_MA_SUPER_SLOW: + result = "MA_SUPER_SLOW"; + break; + } + } + + // + return result; +} +ENUM_X121_XKI_BUFFER_NAME ToXKIBufferName(string value) +{ + // + ENUM_X121_XKI_BUFFER_NAME result = X121_XKI_NONE; + + // + if (IsXValid(value)) + { + // + if (value == ToXString(X121_XKI_FAST)) + { + result = X121_XKI_FAST; + } + else if (value == ToXString(X121_XKI_SLOW)) + { + result = X121_XKI_SLOW; + } + else if (value == ToXString(X121_XKI_SUPER_SLOW)) + { + result = X121_XKI_SUPER_SLOW; + } + else if (value == ToXString(X121_XKI_UPPER)) + { + result = X121_XKI_UPPER; + } + else if (value == ToXString(X121_XKI_LOWER)) + { + result = X121_XKI_LOWER; + } + else if (value == ToXString(X121_XKI_WAVE)) + { + result = X121_XKI_WAVE; + } + else if (value == ToXString(X121_XKI_MA_FAST)) + { + result = X121_XKI_MA_FAST; + } + else if (value == ToXString(X121_XKI_MA_SLOW)) + { + result = X121_XKI_MA_SLOW; + } + else if (value == ToXString(X121_XKI_MA_SUPER_SLOW)) + { + result = X121_XKI_MA_SUPER_SLOW; + } + } + + // + return result; +} +// #endregion + // #region Buffers ... enum ENUM_X121_XKI_BUFFERS { @@ -86,6 +220,8 @@ struct X121XKIInputs int maSuperSlowLength; // MA Super Slow Length ENUM_MA_METHOD maMethod; // MA Mode ENUM_APPLIED_PRICE maAppliedTo; // MA Applied To + double rsiBullishConfirmation; // RSI Bullish Confirmation Level + double rsiBearishConfirmation; // RSI Bearish Confirmation Level int rsiLength; // RSI Length ENUM_APPLIED_PRICE rsiAppliedTo; // RSI Applied To int kiWaveSmoothingLength; // RSI KI Wave Smoothing Length @@ -151,6 +287,8 @@ struct X121XKIInputs maAppliedTo = PRICE_CLOSE; rsiLength = 14; rsiAppliedTo = PRICE_CLOSE; + rsiBullishConfirmation = 55; + rsiBearishConfirmation = 45; kiWaveSmoothingLength = 14; kiWaveSmoothingMode = X_MA_MODE_EMA; rsiMultiplier = 0.5; @@ -224,7 +362,11 @@ struct X121XKIInputs atrLength >= 5 && // // RSI ... - rsiLength >= 5 + rsiLength >= 5 && + rsiBullishConfirmation > 0 && + rsiBullishConfirmation < 100 && + rsiBearishConfirmation > 0 && + rsiBearishConfirmation < 100 // ; @@ -430,6 +572,8 @@ class XCX121XKIHelper : public XCBaseHelper mInputs.maMethod, mInputs.maAppliedTo, mInputs.rsiLength, + mInputs.rsiBullishConfirmation, + mInputs.rsiBearishConfirmation, mInputs.rsiAppliedTo, mInputs.kiWaveSmoothingLength, mInputs.kiWaveSmoothingMode, diff --git a/Indicators/x-saherelm.x121.xki.mq5 b/Indicators/x-saherelm.x121.xki.mq5 index 3a84b2ef..91fd20d6 100644 --- a/Indicators/x-saherelm.x121.xki.mq5 +++ b/Indicators/x-saherelm.x121.xki.mq5 @@ -43,6 +43,8 @@ input ENUM_MA_METHOD maMethod = MODE_EMA; // MA Mode input ENUM_APPLIED_PRICE maAppliedTo = PRICE_CLOSE; // MA Applied To input int rsiLength = 14; // RSI Length input ENUM_APPLIED_PRICE rsiAppliedTo = PRICE_CLOSE; // RSI Applied To +input double rsiBullishConfirmation = 55; // RSI Bullish Confirmation Level +input double rsiBearishConfirmation = 45; // RSI Bearish Confirmation Level input int kiWaveSmoothingLength = 14; // RSI KI Wave Smoothing Length input ENUM_X_MA_METHOD kiWaveSmoothingMode = X_MA_MODE_EMA; // RSI KI Wave Smoothing Method input double rsiMultiplier = 0.5; // RSI Multiplier @@ -626,7 +628,11 @@ bool ValidateInputs() atrLength >= 5 && // // RSI ... - rsiLength >= 5 + rsiLength >= 5 && + rsiBullishConfirmation > 0 && + rsiBullishConfirmation < 100 && + rsiBearishConfirmation > 0 && + rsiBearishConfirmation < 100 // ; @@ -1700,15 +1706,15 @@ void CalculateRSI( // double iState = - iRsi >= 55 + iRsi >= rsiBullishConfirmation ? bullishState - : iRsi <= 45 + : iRsi <= rsiBearishConfirmation ? bearishState : neuturalState; double iColor = - iRsi >= 55 + iRsi >= rsiBullishConfirmation ? bullishColorIDX - : iRsi <= 45 + : iRsi <= rsiBearishConfirmation ? bearishColorIDX : neuturalColorIDX; if (!showKIWave) diff --git a/Libraries/x-saherelm.x-poi.lib.mq5 b/Libraries/x-saherelm.x-poi.lib.mq5 index e085a15e..155aa67f 100644 --- a/Libraries/x-saherelm.x-poi.lib.mq5 +++ b/Libraries/x-saherelm.x-poi.lib.mq5 @@ -506,7 +506,6 @@ int GetCandlestickPatterns( Add(X_BAR_PATTERN_TRUE_GAPED, dest); Add(forDir, dir); - // result = ArraySize(dest); @@ -1955,6 +1954,51 @@ struct XDirectionShift return result; } + // + bool Init( + string _type, + datetime _at, + double _after, + double _before, + string _symbol, + ENUM_TIMEFRAMES _period, + ENUM_X_DIRECTION _shiftTo // + ) + { + // + bool result = false; + + // + // Validate ... + result = + IsXValid(_at) && + IsXValid(_type) && + IsXValid(_symbol) && + IsXValid(_period) && + NotEmptyZero(_after) && + NotEmptyZero(_before) && + HasDirection(_shiftTo); + if (!result) + { + return result; + } + + // + type = _type; + at = _at; + after = _after; + before = _before; + symbol = _symbol; + period = _period; + shiftTo = _shiftTo; + + // + result = IsValid(); + + // + return result; + } + // // Get Bar Index of Direction Shift ... int Index() diff --git a/X121XKIEA/Backup/x-ki.parser.conditions.tester.bkp.mq5 b/X121XKIEA/Backup/x-ki.parser.conditions.tester.bkp.mq5 new file mode 100644 index 00000000..c1ead7f7 --- /dev/null +++ b/X121XKIEA/Backup/x-ki.parser.conditions.tester.bkp.mq5 @@ -0,0 +1,168 @@ +// #region KI Fast ... +// +// if (kiParser.IsKIFastBullish(barIndex)) +// { +// DebugBreak(); +// } + +// +// if (kiParser.IsKIFastSwitchedToBullish(barIndex)) +// { +// DebugBreak(); +// } + +// +// if (kiParser.IsKIFastBearish(barIndex)) +// { +// DebugBreak(); +// } + +// +// if (kiParser.IsKIFastSwitchedToBearish(barIndex)) +// { +// DebugBreak(); +// } + +// +// if (kiParser.IsKIFastOverLast(barIndex)) +// { +// DebugBreak(); +// } + +// +// if (kiParser.IsKIFastUnderLast(barIndex)) +// { +// DebugBreak(); +// } + +// +// if (kiParser.IsKIFastSameAsLast(barIndex)) +// { +// DebugBreak(); +// } + +// +// if (kiParser.IsKIFastSwitchedOverLast(barIndex)) +// { +// DebugBreak(); +// } + +// +// if (kiParser.IsKIFastSwitchedUnderLast(barIndex)) +// { +// DebugBreak(); +// } +// #endregion + +// #region KI Slow ... +// +// if (kiParser.IsKISlowBullish(barIndex)) +// { +// DebugBreak(); +// } + +// +// if (kiParser.IsKISlowSwitchedToBullish(barIndex)) +// { +// DebugBreak(); +// } + +// +// if (kiParser.IsKISlowBearish(barIndex)) +// { +// DebugBreak(); +// } + +// +// if (kiParser.IsKISlowSwitchedToBearish(barIndex)) +// { +// DebugBreak(); +// } + +// +// if (kiParser.IsKISlowOverLast(barIndex)) +// { +// DebugBreak(); +// } + +// +// if (kiParser.IsKISlowUnderLast(barIndex)) +// { +// DebugBreak(); +// } + +// +// if (kiParser.IsKISlowSameAsLast(barIndex)) +// { +// DebugBreak(); +// } + +// +// if (kiParser.IsKISlowSwitchedOverLast(barIndex)) +// { +// DebugBreak(); +// } + +// +// if (kiParser.IsKISlowSwitchedUnderLast(barIndex)) +// { +// DebugBreak(); +// } +// #endregion + +// #region KI Super Slow ... +// +// if (kiParser.IsKISuperSlowBullish(barIndex)) +// { +// DebugBreak(); +// } + +// +// if (kiParser.IsKISuperSlowSwitchedToBullish(barIndex)) +// { +// DebugBreak(); +// } + +// +// if (kiParser.IsKISuperSlowBearish(barIndex)) +// { +// DebugBreak(); +// } + +// +// if (kiParser.IsKISuperSlowSwitchedToBearish(barIndex)) +// { +// DebugBreak(); +// } + +// +// if (kiParser.IsKISuperSlowOverLast(barIndex)) +// { +// DebugBreak(); +// } + +// +// if (kiParser.IsKISuperSlowUnderLast(barIndex)) +// { +// DebugBreak(); +// } + +// +// if (kiParser.IsKISuperSlowSameAsLast(barIndex)) +// { +// DebugBreak(); +// } + +// +// if (kiParser.IsKISuperSlowSwitchedOverLast(barIndex)) +// { +// DebugBreak(); +// } + +// +// if (kiParser.IsKISuperSlowSwitchedUnderLast(barIndex)) +// { +// DebugBreak(); +// } +// #endregion + diff --git a/X121XKIEA/Classes/x-saherelm.x121.xki.parser.class.mq5 b/X121XKIEA/Classes/x-saherelm.x121.xki.parser.class.mq5 index 51231eca..a080e84f 100644 --- a/X121XKIEA/Classes/x-saherelm.x121.xki.parser.class.mq5 +++ b/X121XKIEA/Classes/x-saherelm.x121.xki.parser.class.mq5 @@ -275,103 +275,61 @@ class XCX121XKIHelperParser : XCBase return result; } - int CountKIFastTouches( - int barIndex = 0, - int loopback = 5, - ENUM_X_DIRECTION forDir = X_DIRECTION_NONE, - ENUM_X_BOUNDARY_PRICE priceType = X_BOUNDARY_PRICE_HIGH_LOW // - ) + bool IsKIFastSameAsLast(int barIndex = 0) { // - int result = 0; + bool result = false; // - // Normalize ... - loopback = NormalizeInt(loopback, 1); barIndex = NormalizeBarIndex(barIndex); // - if (!IsValid()) + result = IsValid() && + helper.GetKIFast(barIndex) == helper.GetKIFast(barIndex + 1); + + // + return result; + } + + bool IsKIFastSwitchedOverLast(int barIndex = 0) + { + // + bool result = false; + + // + barIndex = NormalizeBarIndex(barIndex); + + // + result = + IsValid() && + IsKIFastOverLast(barIndex) && + !IsKIFastOverLast(barIndex + 1); + if (!result) { return result; } // - XOHCL iBar; - bool has = false; - double iValue = 0; - double affectedValue = 0; - double iConfirnValue = 0; - bool isBullish = !HasDirection(forDir) || IsXBullish(forDir); - bool isBearish = !HasDirection(forDir) || IsXBearish(forDir); - ENUM_X_PRICE bullishTouchUpperPriceType = priceType == X_BOUNDARY_PRICE_HIGH_LOW - ? X_PRICE_HIGH - : X_PRICE_UP; - ENUM_X_PRICE bullishTouchLowerPriceType = priceType == X_BOUNDARY_PRICE_HIGH_LOW - ? X_PRICE_LOW - : X_PRICE_DOWN; - ENUM_X_PRICE bearishTouchUpperPriceType = priceType == X_BOUNDARY_PRICE_HIGH_LOW - ? X_PRICE_HIGH - : X_PRICE_UP; - ENUM_X_PRICE bearishTouchLowerPriceType = priceType == X_BOUNDARY_PRICE_HIGH_LOW - ? X_PRICE_LOW - : X_PRICE_DOWN; - for (int i = barIndex; i < barIndex + loopback; i++) - { - // - has = iBar.Init(symbol, period, i); - if (!has) - { - continue; - } + return result; + } - // - affectedValue = helper.GetKIFast(i); - - // - // Bullish Touches ... - if (isBullish) - { - // - iValue = iBar.GetPrice(bullishTouchLowerPriceType); - iConfirnValue = iBar.GetPrice(bullishTouchUpperPriceType); - has = - NotEmptyZero(iValue) && - NotEmptyZero(affectedValue) && - NotEmptyZero(iConfirnValue) && - iValue <= affectedValue && - iConfirnValue >= affectedValue; - if (has) - { - result++; - } - } - - // - // Bearish Touches ... - if (isBearish) - { - // - iValue = iBar.GetPrice(bearishTouchUpperPriceType); - iConfirnValue = iBar.GetPrice(bearishTouchLowerPriceType); - has = - NotEmptyZero(iValue) && - NotEmptyZero(affectedValue) && - NotEmptyZero(iConfirnValue) && - iValue >= affectedValue && - iConfirnValue <= affectedValue; - if (has) - { - result++; - } - } - - // - iBar.Clean(); - } + bool IsKIFastSwitchedUnderLast(int barIndex = 0) + { + // + bool result = false; // - iBar.Clean(); + barIndex = NormalizeBarIndex(barIndex); + + // + result = + IsValid() && + IsKIFastUnderLast(barIndex) && + !IsKIFastUnderLast(barIndex + 1); + if (!result) + { + return result; + } // return result; @@ -545,103 +503,61 @@ class XCX121XKIHelperParser : XCBase return result; } - int CountKISlowTouches( - int barIndex = 0, - int loopback = 5, - ENUM_X_DIRECTION forDir = X_DIRECTION_NONE, - ENUM_X_BOUNDARY_PRICE priceType = X_BOUNDARY_PRICE_HIGH_LOW // - ) + bool IsKISlowSameAsLast(int barIndex = 0) { // - int result = 0; + bool result = false; // - // Normalize ... - loopback = NormalizeInt(loopback, 1); barIndex = NormalizeBarIndex(barIndex); // - if (!IsValid()) + result = IsValid() && + helper.GetKISlow(barIndex) == helper.GetKISlow(barIndex + 1); + + // + return result; + } + + bool IsKISlowSwitchedOverLast(int barIndex = 0) + { + // + bool result = false; + + // + barIndex = NormalizeBarIndex(barIndex); + + // + result = + IsValid() && + IsKISlowOverLast(barIndex) && + !IsKISlowOverLast(barIndex + 1); + if (!result) { return result; } // - XOHCL iBar; - bool has = false; - double iValue = 0; - double affectedValue = 0; - double iConfirnValue = 0; - bool isBullish = !HasDirection(forDir) || IsXBullish(forDir); - bool isBearish = !HasDirection(forDir) || IsXBearish(forDir); - ENUM_X_PRICE bullishTouchUpperPriceType = priceType == X_BOUNDARY_PRICE_HIGH_LOW - ? X_PRICE_HIGH - : X_PRICE_UP; - ENUM_X_PRICE bullishTouchLowerPriceType = priceType == X_BOUNDARY_PRICE_HIGH_LOW - ? X_PRICE_LOW - : X_PRICE_DOWN; - ENUM_X_PRICE bearishTouchUpperPriceType = priceType == X_BOUNDARY_PRICE_HIGH_LOW - ? X_PRICE_HIGH - : X_PRICE_UP; - ENUM_X_PRICE bearishTouchLowerPriceType = priceType == X_BOUNDARY_PRICE_HIGH_LOW - ? X_PRICE_LOW - : X_PRICE_DOWN; - for (int i = barIndex; i < barIndex + loopback; i++) - { - // - has = iBar.Init(symbol, period, i); - if (!has) - { - continue; - } + return result; + } - // - affectedValue = helper.GetKISlow(i); - - // - // Bullish Touches ... - if (isBullish) - { - // - iValue = iBar.GetPrice(bullishTouchLowerPriceType); - iConfirnValue = iBar.GetPrice(bullishTouchUpperPriceType); - has = - NotEmptyZero(iValue) && - NotEmptyZero(affectedValue) && - NotEmptyZero(iConfirnValue) && - iValue <= affectedValue && - iConfirnValue >= affectedValue; - if (has) - { - result++; - } - } - - // - // Bearish Touches ... - if (isBearish) - { - // - iValue = iBar.GetPrice(bearishTouchUpperPriceType); - iConfirnValue = iBar.GetPrice(bearishTouchLowerPriceType); - has = - NotEmptyZero(iValue) && - NotEmptyZero(affectedValue) && - NotEmptyZero(iConfirnValue) && - iValue >= affectedValue && - iConfirnValue <= affectedValue; - if (has) - { - result++; - } - } - - // - iBar.Clean(); - } + bool IsKISlowSwitchedUnderLast(int barIndex = 0) + { + // + bool result = false; // - iBar.Clean(); + barIndex = NormalizeBarIndex(barIndex); + + // + result = + IsValid() && + IsKISlowUnderLast(barIndex) && + !IsKISlowUnderLast(barIndex + 1); + if (!result) + { + return result; + } // return result; @@ -815,103 +731,61 @@ class XCX121XKIHelperParser : XCBase return result; } - int CountKISuperSlowTouches( - int barIndex = 0, - int loopback = 5, - ENUM_X_DIRECTION forDir = X_DIRECTION_NONE, - ENUM_X_BOUNDARY_PRICE priceType = X_BOUNDARY_PRICE_HIGH_LOW // - ) + bool IsKISuperSlowSameAsLast(int barIndex = 0) { // - int result = 0; + bool result = false; // - // Normalize ... - loopback = NormalizeInt(loopback, 1); barIndex = NormalizeBarIndex(barIndex); // - if (!IsValid()) + result = IsValid() && + helper.GetKISuperSlow(barIndex) == helper.GetKISuperSlow(barIndex + 1); + + // + return result; + } + + bool IsKISuperSlowSwitchedOverLast(int barIndex = 0) + { + // + bool result = false; + + // + barIndex = NormalizeBarIndex(barIndex); + + // + result = + IsValid() && + IsKISuperSlowOverLast(barIndex) && + !IsKISuperSlowOverLast(barIndex + 1); + if (!result) { return result; } // - XOHCL iBar; - bool has = false; - double iValue = 0; - double affectedValue = 0; - double iConfirnValue = 0; - bool isBullish = !HasDirection(forDir) || IsXBullish(forDir); - bool isBearish = !HasDirection(forDir) || IsXBearish(forDir); - ENUM_X_PRICE bullishTouchUpperPriceType = priceType == X_BOUNDARY_PRICE_HIGH_LOW - ? X_PRICE_HIGH - : X_PRICE_UP; - ENUM_X_PRICE bullishTouchLowerPriceType = priceType == X_BOUNDARY_PRICE_HIGH_LOW - ? X_PRICE_LOW - : X_PRICE_DOWN; - ENUM_X_PRICE bearishTouchUpperPriceType = priceType == X_BOUNDARY_PRICE_HIGH_LOW - ? X_PRICE_HIGH - : X_PRICE_UP; - ENUM_X_PRICE bearishTouchLowerPriceType = priceType == X_BOUNDARY_PRICE_HIGH_LOW - ? X_PRICE_LOW - : X_PRICE_DOWN; - for (int i = barIndex; i < barIndex + loopback; i++) - { - // - has = iBar.Init(symbol, period, i); - if (!has) - { - continue; - } + return result; + } - // - affectedValue = helper.GetKISuperSlow(i); - - // - // Bullish Touches ... - if (isBullish) - { - // - iValue = iBar.GetPrice(bullishTouchLowerPriceType); - iConfirnValue = iBar.GetPrice(bullishTouchUpperPriceType); - has = - NotEmptyZero(iValue) && - NotEmptyZero(affectedValue) && - NotEmptyZero(iConfirnValue) && - iValue <= affectedValue && - iConfirnValue >= affectedValue; - if (has) - { - result++; - } - } - - // - // Bearish Touches ... - if (isBearish) - { - // - iValue = iBar.GetPrice(bearishTouchUpperPriceType); - iConfirnValue = iBar.GetPrice(bearishTouchLowerPriceType); - has = - NotEmptyZero(iValue) && - NotEmptyZero(affectedValue) && - NotEmptyZero(iConfirnValue) && - iValue >= affectedValue && - iConfirnValue <= affectedValue; - if (has) - { - result++; - } - } - - // - iBar.Clean(); - } + bool IsKISuperSlowSwitchedUnderLast(int barIndex = 0) + { + // + bool result = false; // - iBar.Clean(); + barIndex = NormalizeBarIndex(barIndex); + + // + result = + IsValid() && + IsKISuperSlowUnderLast(barIndex) && + !IsKISuperSlowUnderLast(barIndex + 1); + if (!result) + { + return result; + } // return result; @@ -1016,10 +890,78 @@ class XCX121XKIHelperParser : XCBase // return result; } + + bool IsKIWaveOverLast(int barIndex = 0) + { + // + bool result = false; + + // + barIndex = NormalizeBarIndex(barIndex); + + // + result = IsValid() && + helper.GetKIWave(barIndex) > helper.GetKIWave(barIndex + 1); + + // + return result; + } + + bool IsKIWaveUnderLast(int barIndex = 0) + { + // + bool result = false; + + // + barIndex = NormalizeBarIndex(barIndex); + + // + result = IsValid() && + helper.GetKIWave(barIndex) < helper.GetKIWave(barIndex + 1); + + // + return result; + } + + bool IsKIWaveSwitchedOverLast(int barIndex = 0) + { + // + bool result = false; + + // + barIndex = NormalizeBarIndex(barIndex); + + // + result = + IsValid() && + IsKIWaveOverLast(barIndex) && + !IsKIWaveOverLast(barIndex + 1); + + // + return result; + } + + bool IsKIWaveSwitchedUnderLast(int barIndex = 0) + { + // + bool result = false; + + // + barIndex = NormalizeBarIndex(barIndex); + + // + result = + IsValid() && + IsKIWaveUnderLast(barIndex) && + !IsKIWaveUnderLast(barIndex + 1); + + // + return result; + } // #endregion // #region KI Band ... - bool IsPriceAboveKIUpper( + bool IsPriceOverKIUpper( int barIndex = 0, ENUM_X_PRICE priceType = X_PRICE_CLOSE // ) @@ -1057,7 +999,83 @@ class XCX121XKIHelperParser : XCBase return result; } - bool IsPriceBelowKILower( + bool IsPriceUnderKIUpper( + int barIndex = 0, + ENUM_X_PRICE priceType = X_PRICE_CLOSE // + ) + { + // + bool result = false; + + // + // Normalize ... + barIndex = NormalizeBarIndex(barIndex); + + // + // Validate ... + result = IsValid() && + IsXValid(priceType); + if (!result) + { + return result; + } + + // + XOHCL bar; + result = bar.Init(symbol, period, barIndex); + if (!result) + { + return result; + } + + // + double price = bar.GetPrice(priceType); + result = price < helper.GetKIUpper(barIndex); + bar.Clean(); + + // + return result; + } + + bool IsPriceOverKILower( + int barIndex = 0, + ENUM_X_PRICE priceType = X_PRICE_CLOSE // + ) + { + // + bool result = false; + + // + // Normalize ... + barIndex = NormalizeBarIndex(barIndex); + + // + // Validate ... + result = IsValid() && + IsXValid(priceType); + if (!result) + { + return result; + } + + // + XOHCL bar; + result = bar.Init(symbol, period, barIndex); + if (!result) + { + return result; + } + + // + double price = bar.GetPrice(priceType); + result = price > helper.GetKILower(barIndex); + bar.Clean(); + + // + return result; + } + + bool IsPriceUnderKILower( int barIndex = 0, ENUM_X_PRICE priceType = X_PRICE_CLOSE // ) @@ -1134,205 +1152,85 @@ class XCX121XKIHelperParser : XCBase return result; } - int CountKIUpperTouches( + bool IsPriceSwitchedOverKIUpper( int barIndex = 0, - int loopback = 5, - ENUM_X_DIRECTION forDir = X_DIRECTION_NONE, - ENUM_X_BOUNDARY_PRICE priceType = X_BOUNDARY_PRICE_HIGH_LOW // + ENUM_X_PRICE priceType = X_PRICE_CLOSE // ) { // - int result = 0; + bool result = false; // - // Normalize ... - loopback = NormalizeInt(loopback, 1); barIndex = NormalizeBarIndex(barIndex); // - if (!IsValid()) - { - return result; - } - - // - XOHCL iBar; - bool has = false; - double iValue = 0; - double affectedValue = 0; - double iConfirnValue = 0; - bool isBullish = !HasDirection(forDir) || IsXBullish(forDir); - bool isBearish = !HasDirection(forDir) || IsXBearish(forDir); - ENUM_X_PRICE bullishTouchUpperPriceType = priceType == X_BOUNDARY_PRICE_HIGH_LOW - ? X_PRICE_HIGH - : X_PRICE_UP; - ENUM_X_PRICE bullishTouchLowerPriceType = priceType == X_BOUNDARY_PRICE_HIGH_LOW - ? X_PRICE_LOW - : X_PRICE_DOWN; - ENUM_X_PRICE bearishTouchUpperPriceType = priceType == X_BOUNDARY_PRICE_HIGH_LOW - ? X_PRICE_HIGH - : X_PRICE_UP; - ENUM_X_PRICE bearishTouchLowerPriceType = priceType == X_BOUNDARY_PRICE_HIGH_LOW - ? X_PRICE_LOW - : X_PRICE_DOWN; - for (int i = barIndex; i < barIndex + loopback; i++) - { - // - has = iBar.Init(symbol, period, i); - if (!has) - { - continue; - } - - // - affectedValue = helper.GetKIUpper(i); - - // - // Bullish Touches ... - if (isBullish) - { - // - iValue = iBar.GetPrice(bullishTouchLowerPriceType); - iConfirnValue = iBar.GetPrice(bullishTouchUpperPriceType); - has = - NotEmptyZero(iValue) && - NotEmptyZero(affectedValue) && - NotEmptyZero(iConfirnValue) && - iValue <= affectedValue && - iConfirnValue >= affectedValue; - if (has) - { - result++; - } - } - - // - // Bearish Touches ... - if (isBearish) - { - // - iValue = iBar.GetPrice(bearishTouchUpperPriceType); - iConfirnValue = iBar.GetPrice(bearishTouchLowerPriceType); - has = - NotEmptyZero(iValue) && - NotEmptyZero(affectedValue) && - NotEmptyZero(iConfirnValue) && - iValue >= affectedValue && - iConfirnValue <= affectedValue; - if (has) - { - result++; - } - } - - // - iBar.Clean(); - } - - // - iBar.Clean(); + result = + IsValid() && + IsPriceOverKIUpper(barIndex, priceType) && + !IsPriceOverKIUpper(barIndex + 1, priceType); // return result; } - int CountKILowerTouches( + bool IsPriceSwitchedUnderKIUpper( int barIndex = 0, - int loopback = 5, - ENUM_X_DIRECTION forDir = X_DIRECTION_NONE, - ENUM_X_BOUNDARY_PRICE priceType = X_BOUNDARY_PRICE_HIGH_LOW // + ENUM_X_PRICE priceType = X_PRICE_CLOSE // ) { // - int result = 0; + bool result = false; // - // Normalize ... - loopback = NormalizeInt(loopback, 1); barIndex = NormalizeBarIndex(barIndex); // - if (!IsValid()) - { - return result; - } + result = + IsValid() && + IsPriceUnderKIUpper(barIndex, priceType) && + !IsPriceUnderKIUpper(barIndex + 1, priceType); // - XOHCL iBar; - bool has = false; - double iValue = 0; - double affectedValue = 0; - double iConfirnValue = 0; - bool isBullish = !HasDirection(forDir) || IsXBullish(forDir); - bool isBearish = !HasDirection(forDir) || IsXBearish(forDir); - ENUM_X_PRICE bullishTouchUpperPriceType = priceType == X_BOUNDARY_PRICE_HIGH_LOW - ? X_PRICE_HIGH - : X_PRICE_UP; - ENUM_X_PRICE bullishTouchLowerPriceType = priceType == X_BOUNDARY_PRICE_HIGH_LOW - ? X_PRICE_LOW - : X_PRICE_DOWN; - ENUM_X_PRICE bearishTouchUpperPriceType = priceType == X_BOUNDARY_PRICE_HIGH_LOW - ? X_PRICE_HIGH - : X_PRICE_UP; - ENUM_X_PRICE bearishTouchLowerPriceType = priceType == X_BOUNDARY_PRICE_HIGH_LOW - ? X_PRICE_LOW - : X_PRICE_DOWN; - for (int i = barIndex; i < barIndex + loopback; i++) - { - // - has = iBar.Init(symbol, period, i); - if (!has) - { - continue; - } + return result; + } - // - affectedValue = helper.GetKILower(i); - - // - // Bullish Touches ... - if (isBullish) - { - // - iValue = iBar.GetPrice(bullishTouchLowerPriceType); - iConfirnValue = iBar.GetPrice(bullishTouchUpperPriceType); - has = - NotEmptyZero(iValue) && - NotEmptyZero(affectedValue) && - NotEmptyZero(iConfirnValue) && - iValue <= affectedValue && - iConfirnValue >= affectedValue; - if (has) - { - result++; - } - } - - // - // Bearish Touches ... - if (isBearish) - { - // - iValue = iBar.GetPrice(bearishTouchUpperPriceType); - iConfirnValue = iBar.GetPrice(bearishTouchLowerPriceType); - has = - NotEmptyZero(iValue) && - NotEmptyZero(affectedValue) && - NotEmptyZero(iConfirnValue) && - iValue >= affectedValue && - iConfirnValue <= affectedValue; - if (has) - { - result++; - } - } - - // - iBar.Clean(); - } + bool IsPriceSwitchedOverKILower( + int barIndex = 0, + ENUM_X_PRICE priceType = X_PRICE_CLOSE // + ) + { + // + bool result = false; // - iBar.Clean(); + barIndex = NormalizeBarIndex(barIndex); + + // + result = + IsValid() && + IsPriceOverKILower(barIndex, priceType) && + !IsPriceOverKILower(barIndex + 1, priceType); + + // + return result; + } + + bool IsPriceSwitchedUnderKILower( + int barIndex = 0, + ENUM_X_PRICE priceType = X_PRICE_CLOSE // + ) + { + // + bool result = false; + + // + barIndex = NormalizeBarIndex(barIndex); + + // + result = + IsValid() && + IsPriceUnderKILower(barIndex, priceType) && + !IsPriceUnderKILower(barIndex + 1, priceType); // return result; @@ -1406,6 +1304,76 @@ class XCX121XKIHelperParser : XCBase return result; } + bool IsMAFastOverLast(int barIndex = 0) + { + // + bool result = false; + + // + barIndex = NormalizeBarIndex(barIndex); + + // + result = + IsValid() && + helper.GetMAFast(barIndex) > helper.GetMAFast(barIndex + 1); + + // + return result; + } + + bool IsMAFastUnderLast(int barIndex = 0) + { + // + bool result = false; + + // + barIndex = NormalizeBarIndex(barIndex); + + // + result = + IsValid() && + helper.GetMAFast(barIndex) < helper.GetMAFast(barIndex + 1); + + // + return result; + } + + bool IsMAFastSwitchedOverLast(int barIndex = 0) + { + // + bool result = false; + + // + barIndex = NormalizeBarIndex(barIndex); + + // + result = + IsValid() && + IsMAFastOverLast(barIndex) && + !IsMAFastOverLast(barIndex + 1); + + // + return result; + } + + bool IsMAFastSwitchedUnderLast(int barIndex = 0) + { + // + bool result = false; + + // + barIndex = NormalizeBarIndex(barIndex); + + // + result = + IsValid() && + IsMAFastUnderLast(barIndex) && + !IsMAFastUnderLast(barIndex + 1); + + // + return result; + } + bool IsMAFastSwitchedToBullish( int barIndex = 0, ENUM_X_PRICE priceType = X_PRICE_CLOSE // @@ -1445,108 +1413,6 @@ class XCX121XKIHelperParser : XCBase // return result; } - - int CountMAFastTouches( - int barIndex = 0, - int loopback = 5, - ENUM_X_DIRECTION forDir = X_DIRECTION_NONE, - ENUM_X_BOUNDARY_PRICE priceType = X_BOUNDARY_PRICE_HIGH_LOW // - ) - { - // - int result = 0; - - // - // Normalize ... - loopback = NormalizeInt(loopback, 1); - barIndex = NormalizeBarIndex(barIndex); - - // - if (!IsValid()) - { - return result; - } - - // - XOHCL iBar; - bool has = false; - double iValue = 0; - double affectedValue = 0; - double iConfirnValue = 0; - bool isBullish = !HasDirection(forDir) || IsXBullish(forDir); - bool isBearish = !HasDirection(forDir) || IsXBearish(forDir); - ENUM_X_PRICE bullishTouchUpperPriceType = priceType == X_BOUNDARY_PRICE_HIGH_LOW - ? X_PRICE_HIGH - : X_PRICE_UP; - ENUM_X_PRICE bullishTouchLowerPriceType = priceType == X_BOUNDARY_PRICE_HIGH_LOW - ? X_PRICE_LOW - : X_PRICE_DOWN; - ENUM_X_PRICE bearishTouchUpperPriceType = priceType == X_BOUNDARY_PRICE_HIGH_LOW - ? X_PRICE_HIGH - : X_PRICE_UP; - ENUM_X_PRICE bearishTouchLowerPriceType = priceType == X_BOUNDARY_PRICE_HIGH_LOW - ? X_PRICE_LOW - : X_PRICE_DOWN; - for (int i = barIndex; i < barIndex + loopback; i++) - { - // - has = iBar.Init(symbol, period, i); - if (!has) - { - continue; - } - - // - affectedValue = helper.GetMAFast(i); - - // - // Bullish Touches ... - if (isBullish) - { - // - iValue = iBar.GetPrice(bullishTouchLowerPriceType); - iConfirnValue = iBar.GetPrice(bullishTouchUpperPriceType); - has = - NotEmptyZero(iValue) && - NotEmptyZero(affectedValue) && - NotEmptyZero(iConfirnValue) && - iValue <= affectedValue && - iConfirnValue >= affectedValue; - if (has) - { - result++; - } - } - - // - // Bearish Touches ... - if (isBearish) - { - // - iValue = iBar.GetPrice(bearishTouchUpperPriceType); - iConfirnValue = iBar.GetPrice(bearishTouchLowerPriceType); - has = - NotEmptyZero(iValue) && - NotEmptyZero(affectedValue) && - NotEmptyZero(iConfirnValue) && - iValue >= affectedValue && - iConfirnValue <= affectedValue; - if (has) - { - result++; - } - } - - // - iBar.Clean(); - } - - // - iBar.Clean(); - - // - return result; - } // #endregion // #region MA Slow ... @@ -1614,6 +1480,76 @@ class XCX121XKIHelperParser : XCBase return result; } + bool IsMASlowOverLast(int barIndex = 0) + { + // + bool result = false; + + // + barIndex = NormalizeBarIndex(barIndex); + + // + result = + IsValid() && + helper.GetMASlow(barIndex) > helper.GetMASlow(barIndex + 1); + + // + return result; + } + + bool IsMASlowUnderLast(int barIndex = 0) + { + // + bool result = false; + + // + barIndex = NormalizeBarIndex(barIndex); + + // + result = + IsValid() && + helper.GetMASlow(barIndex) < helper.GetMASlow(barIndex + 1); + + // + return result; + } + + bool IsMASlowSwitchedOverLast(int barIndex = 0) + { + // + bool result = false; + + // + barIndex = NormalizeBarIndex(barIndex); + + // + result = + IsValid() && + IsMASlowOverLast(barIndex) && + !IsMASlowOverLast(barIndex + 1); + + // + return result; + } + + bool IsMASlowSwitchedUnderLast(int barIndex = 0) + { + // + bool result = false; + + // + barIndex = NormalizeBarIndex(barIndex); + + // + result = + IsValid() && + IsMASlowUnderLast(barIndex) && + !IsMASlowUnderLast(barIndex + 1); + + // + return result; + } + bool IsMASlowSwitchedToBullish( int barIndex = 0, ENUM_X_PRICE priceType = X_PRICE_CLOSE // @@ -1653,108 +1589,6 @@ class XCX121XKIHelperParser : XCBase // return result; } - - int CountMASlowTouches( - int barIndex = 0, - int loopback = 5, - ENUM_X_DIRECTION forDir = X_DIRECTION_NONE, - ENUM_X_BOUNDARY_PRICE priceType = X_BOUNDARY_PRICE_HIGH_LOW // - ) - { - // - int result = 0; - - // - // Normalize ... - loopback = NormalizeInt(loopback, 1); - barIndex = NormalizeBarIndex(barIndex); - - // - if (!IsValid()) - { - return result; - } - - // - XOHCL iBar; - bool has = false; - double iValue = 0; - double affectedValue = 0; - double iConfirnValue = 0; - bool isBullish = !HasDirection(forDir) || IsXBullish(forDir); - bool isBearish = !HasDirection(forDir) || IsXBearish(forDir); - ENUM_X_PRICE bullishTouchUpperPriceType = priceType == X_BOUNDARY_PRICE_HIGH_LOW - ? X_PRICE_HIGH - : X_PRICE_UP; - ENUM_X_PRICE bullishTouchLowerPriceType = priceType == X_BOUNDARY_PRICE_HIGH_LOW - ? X_PRICE_LOW - : X_PRICE_DOWN; - ENUM_X_PRICE bearishTouchUpperPriceType = priceType == X_BOUNDARY_PRICE_HIGH_LOW - ? X_PRICE_HIGH - : X_PRICE_UP; - ENUM_X_PRICE bearishTouchLowerPriceType = priceType == X_BOUNDARY_PRICE_HIGH_LOW - ? X_PRICE_LOW - : X_PRICE_DOWN; - for (int i = barIndex; i < barIndex + loopback; i++) - { - // - has = iBar.Init(symbol, period, i); - if (!has) - { - continue; - } - - // - affectedValue = helper.GetMASlow(i); - - // - // Bullish Touches ... - if (isBullish) - { - // - iValue = iBar.GetPrice(bullishTouchLowerPriceType); - iConfirnValue = iBar.GetPrice(bullishTouchUpperPriceType); - has = - NotEmptyZero(iValue) && - NotEmptyZero(affectedValue) && - NotEmptyZero(iConfirnValue) && - iValue <= affectedValue && - iConfirnValue >= affectedValue; - if (has) - { - result++; - } - } - - // - // Bearish Touches ... - if (isBearish) - { - // - iValue = iBar.GetPrice(bearishTouchUpperPriceType); - iConfirnValue = iBar.GetPrice(bearishTouchLowerPriceType); - has = - NotEmptyZero(iValue) && - NotEmptyZero(affectedValue) && - NotEmptyZero(iConfirnValue) && - iValue >= affectedValue && - iConfirnValue <= affectedValue; - if (has) - { - result++; - } - } - - // - iBar.Clean(); - } - - // - iBar.Clean(); - - // - return result; - } // #endregion // #region MA Super Slow ... @@ -1822,6 +1656,76 @@ class XCX121XKIHelperParser : XCBase return result; } + bool IsMASuperSlowOverLast(int barIndex = 0) + { + // + bool result = false; + + // + barIndex = NormalizeBarIndex(barIndex); + + // + result = + IsValid() && + helper.GetMASuperSlow(barIndex) > helper.GetMASuperSlow(barIndex + 1); + + // + return result; + } + + bool IsMASuperSlowUnderLast(int barIndex = 0) + { + // + bool result = false; + + // + barIndex = NormalizeBarIndex(barIndex); + + // + result = + IsValid() && + helper.GetMASuperSlow(barIndex) < helper.GetMASuperSlow(barIndex + 1); + + // + return result; + } + + bool IsMASuperSlowSwitchedOverLast(int barIndex = 0) + { + // + bool result = false; + + // + barIndex = NormalizeBarIndex(barIndex); + + // + result = + IsValid() && + IsMASuperSlowOverLast(barIndex) && + !IsMASuperSlowOverLast(barIndex + 1); + + // + return result; + } + + bool IsMASuperSlowSwitchedUnderLast(int barIndex = 0) + { + // + bool result = false; + + // + barIndex = NormalizeBarIndex(barIndex); + + // + result = + IsValid() && + IsMASuperSlowUnderLast(barIndex) && + !IsMASuperSlowUnderLast(barIndex + 1); + + // + return result; + } + bool IsMASuperSlowSwitchedToBullish( int barIndex = 0, ENUM_X_PRICE priceType = X_PRICE_CLOSE // @@ -1861,108 +1765,6 @@ class XCX121XKIHelperParser : XCBase // return result; } - - int CountMASuperSlowTouches( - int barIndex = 0, - int loopback = 5, - ENUM_X_DIRECTION forDir = X_DIRECTION_NONE, - ENUM_X_BOUNDARY_PRICE priceType = X_BOUNDARY_PRICE_HIGH_LOW // - ) - { - // - int result = 0; - - // - // Normalize ... - loopback = NormalizeInt(loopback, 1); - barIndex = NormalizeBarIndex(barIndex); - - // - if (!IsValid()) - { - return result; - } - - // - XOHCL iBar; - bool has = false; - double iValue = 0; - double affectedValue = 0; - double iConfirnValue = 0; - bool isBullish = !HasDirection(forDir) || IsXBullish(forDir); - bool isBearish = !HasDirection(forDir) || IsXBearish(forDir); - ENUM_X_PRICE bullishTouchUpperPriceType = priceType == X_BOUNDARY_PRICE_HIGH_LOW - ? X_PRICE_HIGH - : X_PRICE_UP; - ENUM_X_PRICE bullishTouchLowerPriceType = priceType == X_BOUNDARY_PRICE_HIGH_LOW - ? X_PRICE_LOW - : X_PRICE_DOWN; - ENUM_X_PRICE bearishTouchUpperPriceType = priceType == X_BOUNDARY_PRICE_HIGH_LOW - ? X_PRICE_HIGH - : X_PRICE_UP; - ENUM_X_PRICE bearishTouchLowerPriceType = priceType == X_BOUNDARY_PRICE_HIGH_LOW - ? X_PRICE_LOW - : X_PRICE_DOWN; - for (int i = barIndex; i < barIndex + loopback; i++) - { - // - has = iBar.Init(symbol, period, i); - if (!has) - { - continue; - } - - // - affectedValue = helper.GetMASuperSlow(i); - - // - // Bullish Touches ... - if (isBullish) - { - // - iValue = iBar.GetPrice(bullishTouchLowerPriceType); - iConfirnValue = iBar.GetPrice(bullishTouchUpperPriceType); - has = - NotEmptyZero(iValue) && - NotEmptyZero(affectedValue) && - NotEmptyZero(iConfirnValue) && - iValue <= affectedValue && - iConfirnValue >= affectedValue; - if (has) - { - result++; - } - } - - // - // Bearish Touches ... - if (isBearish) - { - // - iValue = iBar.GetPrice(bearishTouchUpperPriceType); - iConfirnValue = iBar.GetPrice(bearishTouchLowerPriceType); - has = - NotEmptyZero(iValue) && - NotEmptyZero(affectedValue) && - NotEmptyZero(iConfirnValue) && - iValue >= affectedValue && - iConfirnValue <= affectedValue; - if (has) - { - result++; - } - } - - // - iBar.Clean(); - } - - // - iBar.Clean(); - - // - return result; - } // #endregion bool IsMACrossoverBullish(int barIndex = 0) @@ -2331,6 +2133,76 @@ class XCX121XKIHelperParser : XCBase return result; } + bool IsATROverLast(int barIndex = 0) + { + // + bool result = false; + + // + barIndex = NormalizeBarIndex(barIndex); + + // + result = + IsValid() && + helper.GetATR(barIndex) > helper.GetATR(barIndex + 1); + + // + return result; + } + + bool IsATRUnderLast(int barIndex = 0) + { + // + bool result = false; + + // + barIndex = NormalizeBarIndex(barIndex); + + // + result = + IsValid() && + helper.GetATR(barIndex) < helper.GetATR(barIndex + 1); + + // + return result; + } + + bool IsATRSwitchedOverLast(int barIndex = 0) + { + // + bool result = false; + + // + barIndex = NormalizeBarIndex(barIndex); + + // + result = + IsValid() && + IsATROverLast(barIndex) && + !IsATROverLast(barIndex + 1); + + // + return result; + } + + bool IsATRSwitchedUnderLast(int barIndex = 0) + { + // + bool result = false; + + // + barIndex = NormalizeBarIndex(barIndex); + + // + result = + IsValid() && + IsATRUnderLast(barIndex) && + !IsATRUnderLast(barIndex + 1); + + // + return result; + } + bool IsVolatilityHigh(int barIndex = 0) { // @@ -2449,7 +2321,10 @@ class XCX121XKIHelperParser : XCBase // #endregion // #region RSI ... - bool IsRSIBullish(int barIndex = 0) + bool IsRSIBullish( + int barIndex = 0, + double threshold = 50 // + ) { // bool result = false; @@ -2467,11 +2342,14 @@ class XCX121XKIHelperParser : XCBase } // - result = helper.GetRSI(barIndex) > 50; + result = helper.GetRSI(barIndex) > threshold; return result; } - bool IsRSIBearish(int barIndex = 0) + bool IsRSIBearish( + int barIndex = 0, + double threshold = 50 // + ) { // bool result = false; @@ -2489,11 +2367,14 @@ class XCX121XKIHelperParser : XCBase } // - result = helper.GetRSI(barIndex) < 50; + result = helper.GetRSI(barIndex) < threshold; return result; } - bool IsRSIOverbought(int barIndex = 0) + bool IsRSIOverbought( + int barIndex = 0, + double threshold = 70 // + ) { // bool result = false; @@ -2511,11 +2392,14 @@ class XCX121XKIHelperParser : XCBase } // - result = helper.GetRSI(barIndex) > 70; + result = helper.GetRSI(barIndex) > threshold; return result; } - bool IsRSIOversold(int barIndex = 0) + bool IsRSIOversold( + int barIndex = 0, + double threshold = 30 // + ) { // bool result = false; @@ -2533,33 +2417,98 @@ class XCX121XKIHelperParser : XCBase } // - result = helper.GetRSI(barIndex) < 30; + result = helper.GetRSI(barIndex) < threshold; return result; } - bool IsRSISwitchedToBullish(int barIndex = 0) + bool IsRSISwitchedToOverSold( + int barIndex = 0, + double threshold = 30 // + ) { // bool result = false; // - // Normalize ... barIndex = NormalizeBarIndex(barIndex); // - // Validate ... - result = IsValid(); - if (!result) - { - return result; - } + result = + IsValid() && + IsRSIOversold(barIndex, threshold) && + !IsRSIOversold(barIndex + 1, threshold); // - result = IsRSIBullish(barIndex) && !IsRSIBullish(barIndex + 1); return result; } - bool IsRSISwitchedToBearish(int barIndex = 0) + bool IsRSISwitchedFromOverSold( + int barIndex = 0, + double threshold = 30 // + ) + { + // + bool result = false; + + // + barIndex = NormalizeBarIndex(barIndex); + + // + result = + IsValid() && + !IsRSIOversold(barIndex, threshold) && + IsRSIOversold(barIndex + 1, threshold); + + // + return result; + } + + bool IsRSISwitchedToOverbought( + int barIndex = 0, + double threshold = 70 // + ) + { + // + bool result = false; + + // + barIndex = NormalizeBarIndex(barIndex); + + // + result = + IsValid() && + IsRSIOverbought(barIndex, threshold) && + !IsRSIOverbought(barIndex + 1, threshold); + + // + return result; + } + + bool IsRSISwitchedFromOverbought( + int barIndex = 0, + double threshold = 70 // + ) + { + // + bool result = false; + + // + barIndex = NormalizeBarIndex(barIndex); + + // + result = + IsValid() && + !IsRSIOverbought(barIndex, threshold) && + IsRSIOverbought(barIndex + 1, threshold); + + // + return result; + } + + bool IsRSISwitchedToBullish( + int barIndex = 0, + double threshold = 50 // + ) { // bool result = false; @@ -2577,542 +2526,45 @@ class XCX121XKIHelperParser : XCBase } // - result = IsRSIBearish(barIndex) && !IsRSIBearish(barIndex + 1); + result = + IsRSIBullish(barIndex, threshold) && + !IsRSIBullish(barIndex + 1, threshold); + + // + return result; + } + + bool IsRSISwitchedToBearish( + int barIndex = 0, + double threshold = 50 // + ) + { + // + bool result = false; + + // + // Normalize ... + barIndex = NormalizeBarIndex(barIndex); + + // + // Validate ... + result = IsValid(); + if (!result) + { + return result; + } + + // + result = + IsRSIBearish(barIndex, threshold) && + !IsRSIBearish(barIndex + 1, threshold); + + // return result; } // #endregion // #region Composite ... - bool IsTrendBullish(int barIndex = 0) - { - // - bool result = false; - - // - // Normalize ... - barIndex = NormalizeBarIndex(barIndex); - - // - // Validate ... - result = IsValid(); - if (!result) - { - return result; - } - - // - result = IsKIFastBullish(barIndex) && - IsKISlowBullish(barIndex) && - IsMACrossoverBullish(barIndex); - - // - return result; - } - - bool IsTrendBearish(int barIndex = 0) - { - // - bool result = false; - - // - // Normalize ... - barIndex = NormalizeBarIndex(barIndex); - - // - // Validate ... - result = IsValid(); - if (!result) - { - return result; - } - - // - result = IsKIFastBearish(barIndex) && - IsKISlowBearish(barIndex) && - IsMACrossoverBearish(barIndex); - - // - return result; - } - - bool IsBullishMomentumTrend(int barIndex = 0) - { - // - bool result = false; - - // - // Normalize ... - barIndex = NormalizeBarIndex(barIndex); - - // - // Validate ... - result = IsValid(); - if (!result) - { - return result; - } - - // - result = IsTrendBullish(barIndex) && - IsRSIBullish(barIndex); - - // - return result; - } - - bool IsBearishMomentumTrend(int barIndex = 0) - { - // - bool result = false; - - // - // Normalize ... - barIndex = NormalizeBarIndex(barIndex); - - // - // Validate ... - result = IsValid(); - if (!result) - { - return result; - } - - // - result = IsTrendBearish(barIndex) && - IsRSIBearish(barIndex); - - // - return result; - } - - bool IsBullishBreakout(int barIndex = 0) - { - // - bool result = false; - - // - // Normalize ... - barIndex = NormalizeBarIndex(barIndex); - - // - // Validate ... - result = IsValid(); - if (!result) - { - return result; - } - - // - result = - IsPriceAboveKIUpper(barIndex) && - IsATRBreakoutUp(barIndex) && - IsVolatilityHigh(barIndex); - - // - return result; - } - - bool IsBearishBreakout(int barIndex = 0) - { - // - bool result = false; - - // - // Normalize ... - barIndex = NormalizeBarIndex(barIndex); - - // - // Validate ... - result = IsValid(); - if (!result) - { - return result; - } - - // - result = - IsPriceBelowKILower(barIndex) && - IsATRBreakoutDown(barIndex) && - IsVolatilityHigh(barIndex); - return result; - } - - bool IsBullishReversal(int barIndex = 0) - { - // - bool result = false; - - // - // Normalize ... - barIndex = NormalizeBarIndex(barIndex); - - // - // Validate ... - result = IsValid(); - if (!result) - { - return result; - } - - // - // RSI oversold and turning upward ... - double rsiNow = helper.GetRSI(barIndex); - double rsiPrev = helper.GetRSI(barIndex + 1); - bool rsiFlip = (rsiNow > rsiPrev) && (rsiPrev < 30); - - // - // ATR check (volatility supportive) ... - double atrNow = helper.GetATR(barIndex); - double atrPrev = helper.GetATR(barIndex + 1); - double atrMaNow = helper.GetATRSmoothed(barIndex); - double atrMaPrev = helper.GetATRSmoothed(barIndex + 1); - bool atrOk = atrNow > atrMaNow || atrNow > atrPrev || atrMaNow > atrMaPrev; - - // - // MA crossover bullish ... - double maFastNow = helper.GetMAFast(barIndex); - double maSlowNow = helper.GetMASlow(barIndex); - bool maOk = maFastNow > maSlowNow; - - // - result = rsiFlip && (atrOk || maOk); - - // - return result; - } - - bool IsBearishReversal(int barIndex = 0) - { - // - bool result = false; - - // - // Normalize ... - barIndex = NormalizeBarIndex(barIndex); - - // - // Validate ... - result = IsValid(); - if (!result) - { - return result; - } - - // - // RSI overbought and turning downward ... - double rsiNow = helper.GetRSI(barIndex); - double rsiPrev = helper.GetRSI(barIndex + 1); - bool rsiFlip = (rsiNow < rsiPrev) && (rsiPrev > 70); - - // - // ATR check (volatility supportive) ... - double atrNow = helper.GetATR(barIndex); - double atrPrev = helper.GetATR(barIndex + 1); - double atrMaNow = helper.GetATRSmoothed(barIndex); - double atrMaPrev = helper.GetATRSmoothed(barIndex + 1); - bool atrOk = atrNow > atrMaNow || atrNow > atrPrev || atrMaNow > atrMaPrev; - - // - // MA crossover bearish ... - double maFastNow = helper.GetMAFast(barIndex); - double maSlowNow = helper.GetMASlow(barIndex); - bool maOk = maFastNow < maSlowNow; - - // - result = rsiFlip && (atrOk || maOk); - - // - return result; - } - - bool IsSafeBullishEntry(int barIndex = 0) - { - // - bool result = false; - - // - // Normalize ... - barIndex = NormalizeBarIndex(barIndex); - - // - // Validate ... - result = IsValid(); - if (!result) - { - return result; - } - - // - result = IsBullishMomentumTrend(barIndex) && !IsRSIOverbought(barIndex); - return result; - } - - bool IsSafeBearishEntry(int barIndex = 0) - { - // - bool result = false; - - // - // Normalize ... - barIndex = NormalizeBarIndex(barIndex); - - // - // Validate ... - result = IsValid(); - if (!result) - { - return result; - } - - // - result = IsBearishMomentumTrend(barIndex) && !IsRSIOversold(barIndex); - return result; - } - - bool IsTrendStrongBullish(int barIndex = 0) - { - // - bool result = false; - - // - // Normalize ... - barIndex = NormalizeBarIndex(barIndex); - - // - // Validate ... - result = IsValid(); - if (!result) - { - return result; - } - - // - // Strong bullish trend requires: - // - KI Fast bullish - // - KI Slow bullish - // - MA crossover bullish - // - RSI > 60 - // - Volatility high - result = IsKIFastBullish(barIndex) && - IsKISlowBullish(barIndex) && - IsMACrossoverBullish(barIndex) && - (helper.GetRSI(barIndex) > 60) && - IsVolatilityHigh(barIndex); - - // - return result; - } - - bool IsTrendStrongBearish(int barIndex = 0) - { - // - bool result = false; - - // - // Normalize ... - barIndex = NormalizeBarIndex(barIndex); - - // - // Validate ... - result = IsValid(); - if (!result) - { - return result; - } - - // - // Strong bearish trend requires: - // - KI Fast bearish - // - KI Slow bearish - // - MA crossover bearish - // - RSI < 40 - // - Volatility high - result = IsKIFastBearish(barIndex) && - IsKISlowBearish(barIndex) && - IsMACrossoverBearish(barIndex) && - (helper.GetRSI(barIndex) < 40) && - IsVolatilityHigh(barIndex); - - // - return result; - } - - /** - * Counting Touches ... - * - * @param bullish: int reference to holds bullih touches ... - * @param bearish: int reference to holds bearish touches ... - * @param barIndex: int, start Bar Index ... - * @param loopback: int, loopback length for counting ... - * @param countKIFast: boolean, Count KI Fast ... - * @param countKISlow: boolean, Count KI Slow ... - * @param countKIUpper: boolean, Count KI Upper ... - * @param countKILower: boolean, Count KI Lower ... - * @param countMAFast: boolean, Count MA Fast ... - * @param countMASlow: boolean, Count MA Slow ... - * @param forceClean: boolean, Force Clean results before Start Counting ... - * @param priceType: ENUM_X_BOUNDARY_PRICE, Specified Price Type for Boundary Countinf ... - */ - void CountTouches( - int &bullish, - int &bearish, - int barIndex = 0, - int loopback = 5, - bool countKIFast = true, - bool countKISlow = true, - bool countKIUpper = true, - bool countKILower = true, - bool countMAFast = true, - bool countMASlow = true, - bool forceClean = true, - ENUM_X_BOUNDARY_PRICE priceType = X_BOUNDARY_PRICE_HIGH_LOW // - ) - { - // - if (forceClean) - { - bullish = 0; - bearish = 0; - } - - // - // KI Fast ... - if (countKIFast) - { - // - // Bullish ... - bullish += CountKIFastTouches( - barIndex, - loopback, - X_DIRECTION_BULLISH, - priceType // - ); - - // - // Bearish ... - bearish += CountKIFastTouches( - barIndex, - loopback, - X_DIRECTION_BEARISH, - priceType // - ); - } - - // - // KI Slow ... - if (countKISlow) - { - // - // Bullish ... - bullish += CountKISlowTouches( - barIndex, - loopback, - X_DIRECTION_BULLISH, - priceType // - ); - - // - // Bearish ... - bearish += CountKISlowTouches( - barIndex, - loopback, - X_DIRECTION_BEARISH, - priceType // - ); - } - - // - // KI Upper ... - if (countKIUpper) - { - // - // Bullish ... - bullish += CountKIUpperTouches( - barIndex, - loopback, - X_DIRECTION_BULLISH, - priceType // - ); - - // - // Bearish ... - bearish += CountKIUpperTouches( - barIndex, - loopback, - X_DIRECTION_BEARISH, - priceType // - ); - } - - // - // KI Lower ... - if (countKILower) - { - // - // Bullish ... - bullish += CountKILowerTouches( - barIndex, - loopback, - X_DIRECTION_BULLISH, - priceType // - ); - - // - // Bearish ... - bearish += CountKILowerTouches( - barIndex, - loopback, - X_DIRECTION_BEARISH, - priceType // - ); - } - - // - // KI MA Fast ... - if (countMAFast) - { - // - // Bullish ... - bullish += CountMAFastTouches( - barIndex, - loopback, - X_DIRECTION_BULLISH, - priceType // - ); - - // - // Bearish ... - bearish += CountMAFastTouches( - barIndex, - loopback, - X_DIRECTION_BEARISH, - priceType // - ); - } - - // - // KI MA Slow ... - if (countMASlow) - { - // - // Bullish ... - bullish += CountMASlowTouches( - barIndex, - loopback, - X_DIRECTION_BULLISH, - priceType // - ); - - // - // Bearish ... - bearish += CountMASlowTouches( - barIndex, - loopback, - X_DIRECTION_BEARISH, - priceType // - ); - } - } // #endregion // diff --git a/X121XKIEA/Classes/x-saherelm.x121.xki.signaller.class.mq5 b/X121XKIEA/Classes/x-saherelm.x121.xki.signaller.class.mq5 index e0ee60d5..6ff5a568 100644 --- a/X121XKIEA/Classes/x-saherelm.x121.xki.signaller.class.mq5 +++ b/X121XKIEA/Classes/x-saherelm.x121.xki.signaller.class.mq5 @@ -979,6 +979,66 @@ class XCX121XKIStrategy1Signaller : public XCX121XKIBaseSignaller bool isBearish = false; int barIndex = bar.Index() + 1; + // + // TEST ... + + // + // if (kiParser.IsKISuperSlowBullish(barIndex)) + // { + // DebugBreak(); + // } + + // + // if (kiParser.IsKISuperSlowSwitchedToBullish(barIndex)) + // { + // DebugBreak(); + // } + + // + // if (kiParser.IsKISuperSlowBearish(barIndex)) + // { + // DebugBreak(); + // } + + // + // if (kiParser.IsKISuperSlowSwitchedToBearish(barIndex)) + // { + // DebugBreak(); + // } + + // + // if (kiParser.IsKISuperSlowOverLast(barIndex)) + // { + // DebugBreak(); + // } + + // + // if (kiParser.IsKISuperSlowUnderLast(barIndex)) + // { + // DebugBreak(); + // } + + // + // if (kiParser.IsKISuperSlowSameAsLast(barIndex)) + // { + // DebugBreak(); + // } + + // + // if (kiParser.IsKISuperSlowSwitchedOverLast(barIndex)) + // { + // DebugBreak(); + // } + + // + // if (kiParser.IsKISuperSlowSwitchedUnderLast(barIndex)) + // { + // DebugBreak(); + // } + + // + return false; + // // Initialize Indexed Bar ... XOHCL iBar; @@ -1072,44 +1132,44 @@ class XCX121XKIStrategy1Signaller : public XCX121XKIBaseSignaller // // Count Touches ... - int bullishTouches = 0; - int bearishTouches = 0; - if (result) - { - // - kiParser.CountTouches( - bullishTouches, - bearishTouches, - barIndex, - 4 // Loopback ... - ); + // int bullishTouches = 0; + // int bearishTouches = 0; + // if (result) + // { + // // + // kiParser.CountTouches( + // bullishTouches, + // bearishTouches, + // barIndex, + // 4 // Loopback ... + // ); - // - isBullish = - isBullish && - bullishTouches >= bearishTouches; + // // + // isBullish = + // isBullish && + // bullishTouches >= bearishTouches; - // - isBearish = - isBearish && - bearishTouches >= bullishTouches; + // // + // isBearish = + // isBearish && + // bearishTouches >= bullishTouches; - // - // Summarize Result ... - result = isBullish || isBearish; - if (!result) - { - // - isBullish = false; - isBearish = false; - } + // // + // // Summarize Result ... + // result = isBullish || isBearish; + // if (!result) + // { + // // + // isBullish = false; + // isBearish = false; + // } - // - if (bullishTouches > 0 || bearishTouches > 0) - { - // DebugBreak(); - } - } + // // + // if (bullishTouches > 0 || bearishTouches > 0) + // { + // // DebugBreak(); + // } + // } // if (!result) diff --git a/X121XKIEA/Classes/x-saherelm.x121.xki.x-poi.detector.class.mq5 b/X121XKIEA/Classes/x-saherelm.x121.xki.x-poi.detector.class.mq5 index 2cbc7512..f115482e 100644 --- a/X121XKIEA/Classes/x-saherelm.x121.xki.x-poi.detector.class.mq5 +++ b/X121XKIEA/Classes/x-saherelm.x121.xki.x-poi.detector.class.mq5 @@ -1547,7 +1547,851 @@ class XCX121XKIPOIDetector : public XCMarketPatternDetector // #endregion // #region Switches ... - // TODO: Implement Switches Checkers in Loopback ... + int HasKIFastSwitch( + XDirectionShift &switches[], + int barIndex = 0, + int loopback = 10, + ENUM_X_DIRECTION forDir = X_DIRECTION_NONE // + ) + { + // + int result = 0; + + // + XClean(switches); + + // + loopback = NormalizeInt(loopback, 2); + barIndex = kiParser.NormalizeBarIndex(barIndex); + + // + bool isBullish = !HasDirection(forDir) || IsXBullish(forDir); + bool isBearish = !HasDirection(forDir) || IsXBearish(forDir); + + // + bool has = false; + XDirectionShift iShift; + for (int i = barIndex; i < barIndex + loopback; i++) + { + // + // Bullish ... + bool hasBullish = kiParser.IsKIFastSwitchedToBullish(i); + has = hasBullish && isBullish; + if (has) + { + // + iShift.Clean(); + has = iShift.Init( + ToXString(X121_XKI_FAST), + GetBarTime(symbol, period, i), + kiHelper.GetKIFast(i), + kiHelper.GetKIFast(i + 1), + symbol, + period, + X_DIRECTION_BULLISH // + ); + if (has) + { + // + AddIfNotExists( + iShift, + switches // + ); + + // + iShift.Clean(); + } + } + + // + // Bearish ... + bool hasBearish = kiParser.IsKIFastSwitchedToBearish(i); + has = hasBearish && isBearish; + if (has) + { + // + iShift.Clean(); + has = iShift.Init( + ToXString(X121_XKI_FAST), + GetBarTime(symbol, period, i), + kiHelper.GetKIFast(i), + kiHelper.GetKIFast(i + 1), + symbol, + period, + X_DIRECTION_BEARISH // + ); + if (has) + { + // + AddIfNotExists( + iShift, + switches // + ); + + // + iShift.Clean(); + } + } + } + + // + result = ArraySize(switches); + + // + return result; + } + + int HasKISlowSwitch( + XDirectionShift &switches[], + int barIndex = 0, + int loopback = 10, + ENUM_X_DIRECTION forDir = X_DIRECTION_NONE // + ) + { + // + int result = 0; + + // + XClean(switches); + + // + loopback = NormalizeInt(loopback, 2); + barIndex = kiParser.NormalizeBarIndex(barIndex); + + // + bool isBullish = !HasDirection(forDir) || IsXBullish(forDir); + bool isBearish = !HasDirection(forDir) || IsXBearish(forDir); + + // + bool has = false; + XDirectionShift iShift; + for (int i = barIndex; i < barIndex + loopback; i++) + { + // + // Bullish ... + bool hasBullish = kiParser.IsKISlowSwitchedToBullish(i); + has = hasBullish && isBullish; + if (has) + { + // + iShift.Clean(); + has = iShift.Init( + ToXString(X121_XKI_SLOW), + GetBarTime(symbol, period, i), + kiHelper.GetKISlow(i), + kiHelper.GetKISlow(i + 1), + symbol, + period, + X_DIRECTION_BULLISH // + ); + if (has) + { + // + AddIfNotExists( + iShift, + switches // + ); + + // + iShift.Clean(); + } + } + + // + // Bearish ... + bool hasBearish = kiParser.IsKISlowSwitchedToBearish(i); + has = hasBearish && isBearish; + if (has) + { + // + iShift.Clean(); + has = iShift.Init( + ToXString(X121_XKI_SLOW), + GetBarTime(symbol, period, i), + kiHelper.GetKIFast(i), + kiHelper.GetKIFast(i + 1), + symbol, + period, + X_DIRECTION_BEARISH // + ); + if (has) + { + // + AddIfNotExists( + iShift, + switches // + ); + + // + iShift.Clean(); + } + } + } + + // + result = ArraySize(switches); + + // + return result; + } + + int HasKISuperSlowSwitch( + XDirectionShift &switches[], + int barIndex = 0, + int loopback = 10, + ENUM_X_DIRECTION forDir = X_DIRECTION_NONE // + ) + { + // + int result = 0; + + // + XClean(switches); + + // + loopback = NormalizeInt(loopback, 2); + barIndex = kiParser.NormalizeBarIndex(barIndex); + + // + bool isBullish = !HasDirection(forDir) || IsXBullish(forDir); + bool isBearish = !HasDirection(forDir) || IsXBearish(forDir); + + // + bool has = false; + XDirectionShift iShift; + for (int i = barIndex; i < barIndex + loopback; i++) + { + // + // Bullish ... + bool hasBullish = kiParser.IsKISuperSlowSwitchedToBullish(i); + has = hasBullish && isBullish; + if (has) + { + // + iShift.Clean(); + has = iShift.Init( + ToXString(X121_XKI_SUPER_SLOW), + GetBarTime(symbol, period, i), + kiHelper.GetKISuperSlow(i), + kiHelper.GetKISuperSlow(i + 1), + symbol, + period, + X_DIRECTION_BULLISH // + ); + if (has) + { + // + AddIfNotExists( + iShift, + switches // + ); + + // + iShift.Clean(); + } + } + + // + // Bearish ... + bool hasBearish = kiParser.IsKISuperSlowSwitchedToBearish(i); + has = hasBearish && isBearish; + if (has) + { + // + iShift.Clean(); + has = iShift.Init( + ToXString(X121_XKI_SUPER_SLOW), + GetBarTime(symbol, period, i), + kiHelper.GetKIFast(i), + kiHelper.GetKIFast(i + 1), + symbol, + period, + X_DIRECTION_BEARISH // + ); + if (has) + { + // + AddIfNotExists( + iShift, + switches // + ); + + // + iShift.Clean(); + } + } + } + + // + result = ArraySize(switches); + + // + return result; + } + + int HasKIWaveSwitch( + XDirectionShift &switches[], + int barIndex = 0, + int loopback = 10, + ENUM_X_DIRECTION forDir = X_DIRECTION_NONE // + ) + { + // + int result = 0; + + // + XClean(switches); + + // + loopback = NormalizeInt(loopback, 2); + barIndex = kiParser.NormalizeBarIndex(barIndex); + + // + bool isBullish = !HasDirection(forDir) || IsXBullish(forDir); + bool isBearish = !HasDirection(forDir) || IsXBearish(forDir); + + // + bool has = false; + XDirectionShift iShift; + for (int i = barIndex; i < barIndex + loopback; i++) + { + // + // Bullish ... + bool hasBullish = kiParser.IsKIWaveSwitchedToBullish(i); + has = hasBullish && isBullish; + if (has) + { + // + iShift.Clean(); + has = iShift.Init( + ToXString(X121_XKI_WAVE), + GetBarTime(symbol, period, i), + kiHelper.GetKIWave(i), + kiHelper.GetKIWave(i + 1), + symbol, + period, + X_DIRECTION_BULLISH // + ); + if (has) + { + // + AddIfNotExists( + iShift, + switches // + ); + + // + iShift.Clean(); + } + } + + // + // Bearish ... + bool hasBearish = kiParser.IsKIWaveSwitchedToBearish(i); + has = hasBearish && isBearish; + if (has) + { + // + iShift.Clean(); + has = iShift.Init( + ToXString(X121_XKI_WAVE), + GetBarTime(symbol, period, i), + kiHelper.GetKIWave(i), + kiHelper.GetKIWave(i + 1), + symbol, + period, + X_DIRECTION_BEARISH // + ); + if (has) + { + // + AddIfNotExists( + iShift, + switches // + ); + + // + iShift.Clean(); + } + } + } + + // + result = ArraySize(switches); + + // + return result; + } + + int HasMAFastSwitch( + XDirectionShift &switches[], + int barIndex = 0, + int loopback = 10, + ENUM_X_DIRECTION forDir = X_DIRECTION_NONE // + ) + { + // + int result = 0; + + // + XClean(switches); + + // + loopback = NormalizeInt(loopback, 2); + barIndex = kiParser.NormalizeBarIndex(barIndex); + + // + bool isBullish = !HasDirection(forDir) || IsXBullish(forDir); + bool isBearish = !HasDirection(forDir) || IsXBearish(forDir); + + // + bool has = false; + XDirectionShift iShift; + for (int i = barIndex; i < barIndex + loopback; i++) + { + // + // Bullish ... + bool hasBullish = kiParser.IsMAFastSwitchedToBullish(i); + has = hasBullish && isBullish; + if (has) + { + // + iShift.Clean(); + has = iShift.Init( + ToXString(X121_XKI_MA_FAST), + GetBarTime(symbol, period, i), + kiHelper.GetMAFast(i), + kiHelper.GetMAFast(i + 1), + symbol, + period, + X_DIRECTION_BULLISH // + ); + if (has) + { + // + AddIfNotExists( + iShift, + switches // + ); + + // + iShift.Clean(); + } + } + + // + // Bearish ... + bool hasBearish = kiParser.IsMAFastSwitchedToBearish(i); + has = hasBearish && isBearish; + if (has) + { + // + iShift.Clean(); + has = iShift.Init( + ToXString(X121_XKI_MA_FAST), + GetBarTime(symbol, period, i), + kiHelper.GetMAFast(i), + kiHelper.GetMAFast(i + 1), + symbol, + period, + X_DIRECTION_BEARISH // + ); + if (has) + { + // + AddIfNotExists( + iShift, + switches // + ); + + // + iShift.Clean(); + } + } + } + + // + result = ArraySize(switches); + + // + return result; + } + + int HasMASlowSwitch( + XDirectionShift &switches[], + int barIndex = 0, + int loopback = 10, + ENUM_X_DIRECTION forDir = X_DIRECTION_NONE // + ) + { + // + int result = 0; + + // + XClean(switches); + + // + loopback = NormalizeInt(loopback, 2); + barIndex = kiParser.NormalizeBarIndex(barIndex); + + // + bool isBullish = !HasDirection(forDir) || IsXBullish(forDir); + bool isBearish = !HasDirection(forDir) || IsXBearish(forDir); + + // + bool has = false; + XDirectionShift iShift; + for (int i = barIndex; i < barIndex + loopback; i++) + { + // + // Bullish ... + bool hasBullish = kiParser.IsMASlowSwitchedToBullish(i); + has = hasBullish && isBullish; + if (has) + { + // + iShift.Clean(); + has = iShift.Init( + ToXString(X121_XKI_MA_SLOW), + GetBarTime(symbol, period, i), + kiHelper.GetMASlow(i), + kiHelper.GetMASlow(i + 1), + symbol, + period, + X_DIRECTION_BULLISH // + ); + if (has) + { + // + AddIfNotExists( + iShift, + switches // + ); + + // + iShift.Clean(); + } + } + + // + // Bearish ... + bool hasBearish = kiParser.IsMASlowSwitchedToBearish(i); + has = hasBearish && isBearish; + if (has) + { + // + iShift.Clean(); + has = iShift.Init( + ToXString(X121_XKI_MA_SLOW), + GetBarTime(symbol, period, i), + kiHelper.GetMAFast(i), + kiHelper.GetMAFast(i + 1), + symbol, + period, + X_DIRECTION_BEARISH // + ); + if (has) + { + // + AddIfNotExists( + iShift, + switches // + ); + + // + iShift.Clean(); + } + } + } + + // + result = ArraySize(switches); + + // + return result; + } + + int HasMASuperSlowSwitch( + XDirectionShift &switches[], + int barIndex = 0, + int loopback = 10, + ENUM_X_DIRECTION forDir = X_DIRECTION_NONE // + ) + { + // + int result = 0; + + // + XClean(switches); + + // + loopback = NormalizeInt(loopback, 2); + barIndex = kiParser.NormalizeBarIndex(barIndex); + + // + bool isBullish = !HasDirection(forDir) || IsXBullish(forDir); + bool isBearish = !HasDirection(forDir) || IsXBearish(forDir); + + // + bool has = false; + XDirectionShift iShift; + for (int i = barIndex; i < barIndex + loopback; i++) + { + // + // Bullish ... + bool hasBullish = kiParser.IsMASuperSlowSwitchedToBullish(i); + has = hasBullish && isBullish; + if (has) + { + // + iShift.Clean(); + has = iShift.Init( + ToXString(X121_XKI_MA_SUPER_SLOW), + GetBarTime(symbol, period, i), + kiHelper.GetMASuperSlow(i), + kiHelper.GetMASuperSlow(i + 1), + symbol, + period, + X_DIRECTION_BULLISH // + ); + if (has) + { + // + AddIfNotExists( + iShift, + switches // + ); + + // + iShift.Clean(); + } + } + + // + // Bearish ... + bool hasBearish = kiParser.IsMASuperSlowSwitchedToBearish(i); + has = hasBearish && isBearish; + if (has) + { + // + iShift.Clean(); + has = iShift.Init( + ToXString(X121_XKI_MA_SUPER_SLOW), + GetBarTime(symbol, period, i), + kiHelper.GetMAFast(i), + kiHelper.GetMAFast(i + 1), + symbol, + period, + X_DIRECTION_BEARISH // + ); + if (has) + { + // + AddIfNotExists( + iShift, + switches // + ); + + // + iShift.Clean(); + } + } + } + + // + result = ArraySize(switches); + + // + return result; + } + + int HasMACrossedSwitch( + XDirectionShift &switches[], + int barIndex = 0, + int loopback = 10, + ENUM_X_DIRECTION forDir = X_DIRECTION_NONE // + ) + { + // + int result = 0; + + // + XClean(switches); + + // + loopback = NormalizeInt(loopback, 2); + barIndex = kiParser.NormalizeBarIndex(barIndex); + + // + bool isBullish = !HasDirection(forDir) || IsXBullish(forDir); + bool isBearish = !HasDirection(forDir) || IsXBearish(forDir); + + // + bool has = false; + XDirectionShift iShift; + for (int i = barIndex; i < barIndex + loopback; i++) + { + // + // Bullish ... + bool hasBullish = kiParser.IsMACrossoverSwitchedToBullish(i); + has = hasBullish && isBullish; + if (has) + { + // + iShift.Clean(); + has = iShift.Init( + ToXString(X121_XKI_MA_CROSS), + GetBarTime(symbol, period, i), + MathMin(kiHelper.GetMAFast(i), kiHelper.GetMASlow(i)), + MathMin(kiHelper.GetMAFast(i + 1), kiHelper.GetMASlow(i + 1)), + symbol, + period, + X_DIRECTION_BULLISH // + ); + if (has) + { + // + AddIfNotExists( + iShift, + switches // + ); + + // + iShift.Clean(); + } + } + + // + // Bearish ... + bool hasBearish = kiParser.IsMACrossoverSwitchedToBearish(i); + has = hasBearish && isBearish; + if (has) + { + // + iShift.Clean(); + has = iShift.Init( + ToXString(X121_XKI_MA_CROSS), + GetBarTime(symbol, period, i), + MathMin(kiHelper.GetMAFast(i), kiHelper.GetMASlow(i)), + MathMin(kiHelper.GetMAFast(i + 1), kiHelper.GetMASlow(i + 1)), + symbol, + period, + X_DIRECTION_BEARISH // + ); + if (has) + { + // + AddIfNotExists( + iShift, + switches // + ); + + // + iShift.Clean(); + } + } + } + + // + result = ArraySize(switches); + + // + return result; + } + + int HasATRVolatilitySwitch( + XDirectionShift &switches[], + int barIndex = 0, + int loopback = 10, + ENUM_X_DIRECTION forDir = X_DIRECTION_NONE // + ) + { + // + int result = 0; + + // + XClean(switches); + + // + loopback = NormalizeInt(loopback, 2); + barIndex = kiParser.NormalizeBarIndex(barIndex); + + // + bool isBullish = !HasDirection(forDir) || IsXBullish(forDir); + bool isBearish = !HasDirection(forDir) || IsXBearish(forDir); + + // + bool has = false; + XDirectionShift iShift; + for (int i = barIndex; i < barIndex + loopback; i++) + { + // + // Bullish ... + bool hasBullish = kiParser.IsVolatilitySwitchdToHigh(i); + has = hasBullish && isBullish; + if (has) + { + // + iShift.Clean(); + has = iShift.Init( + ToXString(X121_XKI_ATR), + GetBarTime(symbol, period, i), + kiHelper.GetATR(i), + kiHelper.GetATR(i + 1), + symbol, + period, + X_DIRECTION_BULLISH // + ); + if (has) + { + // + AddIfNotExists( + iShift, + switches // + ); + + // + iShift.Clean(); + } + } + + // + // Bearish ... + bool hasBearish = kiParser.IsVolatilitySwitchdToLow(i); + has = hasBearish && isBearish; + if (has) + { + // + iShift.Clean(); + has = iShift.Init( + ToXString(X121_XKI_ATR), + GetBarTime(symbol, period, i), + kiHelper.GetATR(i), + kiHelper.GetATR(i + 1), + symbol, + period, + X_DIRECTION_BEARISH // + ); + if (has) + { + // + AddIfNotExists( + iShift, + switches // + ); + + // + iShift.Clean(); + } + } + } + + // + result = ArraySize(switches); + + // + return result; + } // #endregion // #region Peak and Vale ...