From 2829430c0c8965d222b651cf53d39086a4a53134 Mon Sep 17 00:00:00 2001 From: Hadi Khazaee Asl Date: Thu, 8 Jan 2026 20:45:23 +0330 Subject: [PATCH] last ... --- Classes/x-saherelm.x-helper.class.mq5 | 151 + Documents/BKP/X121XKI/tmps.bkp.mq5 | 2590 ++++++++++++++++ .../x-saherelm.common.extensions.lib.mq5 | 10 +- .../x-saherelm.x121.xki.parser.class.mq5 | 2656 +---------------- .../x-saherelm.x121.xki.signaller.class.mq5 | 28 +- 5 files changed, 2837 insertions(+), 2598 deletions(-) diff --git a/Classes/x-saherelm.x-helper.class.mq5 b/Classes/x-saherelm.x-helper.class.mq5 index b2bf7362..792b93f8 100644 --- a/Classes/x-saherelm.x-helper.class.mq5 +++ b/Classes/x-saherelm.x-helper.class.mq5 @@ -27,6 +27,157 @@ // // Definitions ... +enum ENUM_X_SCORE +{ + X_SCORE_NONE = 0, + X_SCORE_MIN = 1, + X_SCORE_NORMAL = 2, + X_SCORE_MAX = 3, +}; + +// +// State Handler Generic Functions ... +#define DECLARE_STATE_FUNCTIONS(name, state_reader, bar_normalizer_func) \ + bool Is##name##Bullish(int barIndex = 0) \ + { \ + barIndex = bar_normalizer_func(barIndex); \ + return state_reader(barIndex) >= 1; \ + } \ + bool Is##name##Bearish(int barIndex = 0) \ + { \ + barIndex = bar_normalizer_func(barIndex); \ + return state_reader(barIndex) <= -1; \ + } \ + bool Is##name##SwitchedToBullish(int barIndex = 0) \ + { \ + barIndex = bar_normalizer_func(barIndex); \ + return Is##name##Bullish(barIndex) && !Is##name##Bullish(barIndex + 1); \ + } \ + bool Is##name##SwitchedToBearish(int barIndex = 0) \ + { \ + barIndex = bar_normalizer_func(barIndex); \ + return Is##name##Bearish(barIndex) && !Is##name##Bearish(barIndex + 1); \ + } + +// +// State Handler Based On Price Type Generic Functions ... +#define DECLARE_PRICE_BASED_STATE_FUNCTIONS(name, value_reader, bar_normalizer_func, point_reader_func, price_reader_func) \ + bool Is##name##Bullish(int barIndex = 0, ENUM_X_PRICE priceType = X_PRICE_CLOSE, double tolerance = 2) \ + { \ + barIndex = bar_normalizer_func(barIndex); \ + double threshold = point_reader_func() * tolerance; \ + return price_reader_func(barIndex, priceType) > value_reader(barIndex) + threshold || \ + price_reader_func(barIndex, priceType) > value_reader(barIndex) - threshold; \ + } \ + bool Is##name##Bearish(int barIndex = 0, ENUM_X_PRICE priceType = X_PRICE_CLOSE, double tolerance = 2) \ + { \ + barIndex = bar_normalizer_func(barIndex); \ + double threshold = point_reader_func() * tolerance; \ + return price_reader_func(barIndex, priceType) < value_reader(barIndex) + threshold || \ + price_reader_func(barIndex, priceType) < value_reader(barIndex) - threshold; \ + } \ + bool Is##name##SwitchedToBullish(int barIndex = 0, ENUM_X_PRICE priceType = X_PRICE_CLOSE, double tolerance = 2) \ + { \ + barIndex = bar_normalizer_func(barIndex); \ + return Is##name##Bullish(barIndex, priceType, tolerance) && !Is##name##Bullish(barIndex + 1, priceType, tolerance); \ + } \ + bool Is##name##SwitchedToBearish(int barIndex = 0, ENUM_X_PRICE priceType = X_PRICE_CLOSE, double tolerance = 2) \ + { \ + barIndex = bar_normalizer_func(barIndex); \ + return Is##name##Bearish(barIndex, priceType, tolerance) && !Is##name##Bearish(barIndex + 1, priceType, tolerance); \ + } + +// +// Value Comparator Generic Functions ... +#define DECLARE_VALUE_COMPARATOR_FUNCTIONS(name, value_reader, bar_normalizer_func, point_reader_func) \ + bool Is##name##OverLast(int barIndex = 0, double tolerance = 2) \ + { \ + barIndex = bar_normalizer_func(barIndex); \ + return IsOver( \ + value_reader(barIndex), \ + value_reader(barIndex + 1), \ + point_reader_func() * tolerance); \ + } \ + bool Is##name##UnderLast(int barIndex = 0, double tolerance = 2) \ + { \ + barIndex = bar_normalizer_func(barIndex); \ + return IsUnder( \ + value_reader(barIndex), \ + value_reader(barIndex + 1), \ + point_reader_func() * tolerance); \ + } \ + bool Is##name##SameAsLast(int barIndex = 0, double tolerance = 2) \ + { \ + barIndex = bar_normalizer_func(barIndex); \ + return IsSame( \ + value_reader(barIndex), \ + value_reader(barIndex + 1), \ + point_reader_func() * tolerance); \ + } \ + bool Is##name##CrossedOverLast(int barIndex = 0, double tolerance = 2) \ + { \ + barIndex = bar_normalizer_func(barIndex); \ + return Is##name##OverLast(barIndex, tolerance) && !Is##name##OverLast(barIndex + 1, tolerance); \ + } \ + bool Is##name##CrossedUnderLast(int barIndex = 0, double tolerance = 2) \ + { \ + barIndex = bar_normalizer_func(barIndex); \ + return Is##name##UnderLast(barIndex, tolerance) && !Is##name##UnderLast(barIndex + 1, tolerance); \ + } + +// +// Price Comparator Generic Functions ... +#define DECLARE_PRICE_COMPARATOR_FUNCTIONS(name, value_reader, bar_normalizer_func, price_reader_func) \ + bool IsPriceOver##name(int barIndex = 0, ENUM_X_PRICE priceType = X_PRICE_CLOSE) \ + { \ + barIndex = bar_normalizer_func(barIndex); \ + return price_reader_func(barIndex, priceType) > value_reader(barIndex); \ + } \ + bool IsPriceUnder##name(int barIndex = 0, ENUM_X_PRICE priceType = X_PRICE_CLOSE) \ + { \ + barIndex = bar_normalizer_func(barIndex); \ + return price_reader_func(barIndex, priceType) < value_reader(barIndex); \ + } \ + bool IsPriceCrossedOver##name(int barIndex = 0, ENUM_X_PRICE priceType = X_PRICE_CLOSE) \ + { \ + barIndex = bar_normalizer_func(barIndex); \ + return IsPriceOver##name(barIndex, priceType) && !IsPriceOver##name(barIndex + 1, priceType); \ + } \ + bool IsPriceCrossedUnder##name(int barIndex = 0, ENUM_X_PRICE priceType = X_PRICE_CLOSE) \ + { \ + barIndex = bar_normalizer_func(barIndex); \ + return IsPriceUnder##name(barIndex, priceType) && !IsPriceUnder##name(barIndex + 1, priceType); \ + } + +// +// Crossing Comparator Generic Functions ... +#define DECLARE_CROSSING_COMPARATOR_FUNCTIONS(baseName, fastName, slowName, fast_reader_func, slow_reader_func, bar_normalizer_func, point_reader_func) \ + bool Is##baseName##fastName##Over##Slow(int barIndex = 0, double tolerance = 2) \ + { \ + barIndex = bar_normalizer_func(barIndex); \ + double fast = fast_reader_func(barIndex); \ + double slow = slow_reader_func(barIndex); \ + double distance = tolerance * point_reader_func(); \ + return fast > slow && MathAbs(fast - slow) >= distance; \ + } \ + bool Is##baseName##fastName##Under##Slow(int barIndex = 0, double tolerance = 2) \ + { \ + barIndex = bar_normalizer_func(barIndex); \ + double fast = fast_reader_func(barIndex); \ + double slow = slow_reader_func(barIndex); \ + double distance = tolerance * point_reader_func(); \ + return fast < slow && MathAbs(fast - slow) >= distance; \ + } \ + bool Is##baseName##fastName##CrossedOver##Slow(int barIndex = 0, double tolerance = 2) \ + { \ + barIndex = bar_normalizer_func(barIndex); \ + return Is##baseName##fastName##Over##Slow(barIndex, tolerance) && !Is##baseName##fastName##Over##Slow(barIndex + 1, tolerance); \ + } \ + bool Is##baseName##fastName##CrossedUnder##Slow(int barIndex = 0, double tolerance = 2) \ + { \ + barIndex = bar_normalizer_func(barIndex); \ + return Is##baseName##fastName##Under##Slow(barIndex, tolerance) && !Is##baseName##fastName##Under##Slow(barIndex + 1, tolerance); \ + } // // a Class for Handle base requirements ... diff --git a/Documents/BKP/X121XKI/tmps.bkp.mq5 b/Documents/BKP/X121XKI/tmps.bkp.mq5 index 4dcfbbcf..32167e4c 100644 --- a/Documents/BKP/X121XKI/tmps.bkp.mq5 +++ b/Documents/BKP/X121XKI/tmps.bkp.mq5 @@ -2189,3 +2189,2593 @@ bool Strategy1HasSignal( // return result; } + + // #region KI Fast ... + + // bool IsKIFastBullish(int barIndex = 0) + // { + // // + // bool result = false; + + // // + // // Normalize ... + // barIndex = NormalizeBarIndex(barIndex); + + // // + // // Validate ... + // result = IsValid(); + // if (!result) + // { + // return result; + // } + + // // + // double state = helper.GetKIFastState(barIndex); + // result = state >= 1; + + // // + // return result; + // } + + // bool IsKIFastBearish(int barIndex = 0) + // { + // // + // bool result = false; + + // // + // // Normalize ... + // barIndex = NormalizeBarIndex(barIndex); + + // // + // // Validate ... + // result = IsValid(); + // if (!result) + // { + // return result; + // } + + // // + // double state = helper.GetKIFastState(barIndex); + // result = state <= -1; + + // // + // return result; + // } + + // bool IsKIFastSwitchedToBullish(int barIndex = 0) + // { + // // + // bool result = false; + + // // + // // Normalize ... + // barIndex = NormalizeBarIndex(barIndex); + + // // + // // Validate ... + // result = IsValid(); + // if (!result) + // { + // return result; + // } + + // // + // result = IsKIFastBullish(barIndex) && + // !IsKIFastBullish(barIndex + 1); + + // // + // return result; + // } + + // bool IsKIFastSwitchedToBearish(int barIndex = 0) + // { + // // + // bool result = false; + + // // + // // Normalize ... + // barIndex = NormalizeBarIndex(barIndex); + + // // + // // Validate ... + // result = IsValid(); + // if (!result) + // { + // return result; + // } + + // // + // result = IsKIFastBearish(barIndex) && + // !IsKIFastBearish(barIndex + 1); + + // // + // return result; + // } + + // bool IsKIFastOverLast( + // int barIndex = 0, + // double tolerance = 2 // + // ) + // { + // // + // bool result = false; + + // // + // // Normalize ... + // barIndex = NormalizeBarIndex(barIndex); + + // // + // // Validate ... + // result = IsValid(); + // if (!result) + // { + // return result; + // } + + // // + // result = IsOver( + // helper.GetKIFast(barIndex), + // helper.GetKIFast(barIndex + 1), + // GetPoints(symbol) * tolerance // + // ); + + // // + // return result; + // } + + // bool IsKIFastUnderLast( + // int barIndex = 0, + // double tolerance = 2 // + // ) + // { + // // + // bool result = false; + + // // + // // Normalize ... + // barIndex = NormalizeBarIndex(barIndex); + + // // + // // Validate ... + // result = IsValid(); + // if (!result) + // { + // return result; + // } + + // // + // result = IsUnder( + // helper.GetKIFast(barIndex), + // helper.GetKIFast(barIndex + 1), + // GetPoints(symbol) * tolerance // + // ); + + // // + // return result; + // } + + // bool IsKIFastSameAsLast( + // int barIndex = 0, + // double tolerance = 2 // + // ) + // { + // // + // bool result = false; + + // // + // barIndex = NormalizeBarIndex(barIndex); + + // // + // result = IsValid() && + // IsSame( + // helper.GetKIFast(barIndex), + // helper.GetKIFast(barIndex + 1), + // GetPoints(symbol) * tolerance // + // ); + + // // + // return result; + // } + + // bool IsKIFastSwitchedOverLast( + // int barIndex = 0, + // double tolerance = 2 // + // ) + // { + // // + // bool result = false; + + // // + // barIndex = NormalizeBarIndex(barIndex); + + // // + // result = + // IsValid() && + // IsKIFastOverLast(barIndex, tolerance) && + // !IsKIFastOverLast(barIndex + 1, tolerance); + // if (!result) + // { + // return result; + // } + + // // + // return result; + // } + + // bool IsKIFastSwitchedUnderLast( + // int barIndex = 0, + // double tolerance = 2 // + // ) + // { + // // + // bool result = false; + + // // + // barIndex = NormalizeBarIndex(barIndex); + + // // + // result = + // IsValid() && + // IsKIFastUnderLast(barIndex, tolerance) && + // !IsKIFastUnderLast(barIndex + 1, tolerance); + // if (!result) + // { + // return result; + // } + + // // + // return result; + // } + // #endregion + + // #region KI Slow ... + bool IsKISlowBullish(int barIndex = 0) + { + // + bool result = false; + + // + // Normalize ... + barIndex = NormalizeBarIndex(barIndex); + + // + // Validate ... + result = IsValid(); + if (!result) + { + return result; + } + + // + double state = helper.GetKISlowState(barIndex); + result = state >= 1; + + // + return result; + } + + bool IsKISlowBearish(int barIndex = 0) + { + // + bool result = false; + + // + // Normalize ... + barIndex = NormalizeBarIndex(barIndex); + + // + // Validate ... + result = IsValid(); + if (!result) + { + return result; + } + + // + double state = helper.GetKISlowState(barIndex); + result = state <= -1; + + // + return result; + } + + bool IsKISlowSwitchedToBullish(int barIndex = 0) + { + // + bool result = false; + + // + // Normalize ... + barIndex = NormalizeBarIndex(barIndex); + + // + // Validate ... + result = IsValid(); + if (!result) + { + return result; + } + + // + result = IsKISlowBullish(barIndex) && + !IsKISlowBullish(barIndex + 1); + + // + return result; + } + + bool IsKISlowSwitchedToBearish(int barIndex = 0) + { + // + bool result = false; + + // + // Normalize ... + barIndex = NormalizeBarIndex(barIndex); + + // + // Validate ... + result = IsValid(); + if (!result) + { + return result; + } + + // + result = IsKISlowBearish(barIndex) && + !IsKISlowBearish(barIndex + 1); + + // + return result; + } + + bool IsKISlowOverLast( + int barIndex = 0, + double tolerance = 2 // + ) + { + // + bool result = false; + + // + // Normalize ... + barIndex = NormalizeBarIndex(barIndex); + + // + // Validate ... + result = IsValid(); + if (!result) + { + return result; + } + + // + result = IsOver( + helper.GetKISlow(barIndex), + helper.GetKISlow(barIndex + 1), + GetPoints(symbol) * tolerance // + ); + + // + return result; + } + + bool IsKISlowUnderLast( + int barIndex = 0, + double tolerance = 2 // + ) + { + // + bool result = false; + + // + // Normalize ... + barIndex = NormalizeBarIndex(barIndex); + + // + // Validate ... + result = IsValid(); + if (!result) + { + return result; + } + + // + result = IsUnder( + helper.GetKISlow(barIndex), + helper.GetKISlow(barIndex + 1), + GetPoints(symbol) * tolerance // + ); + + // + return result; + } + + bool IsKISlowSameAsLast( + int barIndex = 0, + double tolerance = 2 // + ) + { + // + bool result = false; + + // + barIndex = NormalizeBarIndex(barIndex); + + // + result = IsSame( + helper.GetKISlow(barIndex), + helper.GetKISlow(barIndex + 1), + GetPoints(symbol) * tolerance // + ); + + // + return result; + } + + bool IsKISlowSwitchedOverLast( + int barIndex = 0, + double tolerance = 2 // + ) + { + // + bool result = false; + + // + barIndex = NormalizeBarIndex(barIndex); + + // + result = + IsValid() && + IsKISlowOverLast(barIndex, tolerance) && + !IsKISlowOverLast(barIndex + 1, tolerance); + if (!result) + { + return result; + } + + // + return result; + } + + bool IsKISlowSwitchedUnderLast( + int barIndex = 0, + double tolerance = 2 // + ) + { + // + bool result = false; + + // + barIndex = NormalizeBarIndex(barIndex); + + // + result = + IsValid() && + IsKISlowUnderLast(barIndex, tolerance) && + !IsKISlowUnderLast(barIndex + 1, tolerance); + if (!result) + { + return result; + } + + // + return result; + } + // #endregion + + // #region KI Super Slow ... + bool IsKISuperSlowBullish(int barIndex = 0) + { + // + bool result = false; + + // + // Normalize ... + barIndex = NormalizeBarIndex(barIndex); + + // + // Validate ... + result = IsValid(); + if (!result) + { + return result; + } + + // + double state = helper.GetKISuperSlowState(barIndex); + result = state >= 1; + + // + return result; + } + + bool IsKISuperSlowBearish(int barIndex = 0) + { + // + bool result = false; + + // + // Normalize ... + barIndex = NormalizeBarIndex(barIndex); + + // + // Validate ... + result = IsValid(); + if (!result) + { + return result; + } + + // + double state = helper.GetKISuperSlowState(barIndex); + result = state <= -1; + + // + return result; + } + + bool IsKISuperSlowSwitchedToBullish(int barIndex = 0) + { + // + bool result = false; + + // + // Normalize ... + barIndex = NormalizeBarIndex(barIndex); + + // + // Validate ... + result = IsValid(); + if (!result) + { + return result; + } + + // + result = IsKISuperSlowBullish(barIndex) && + !IsKISuperSlowBullish(barIndex + 1); + + // + return result; + } + + bool IsKISuperSlowSwitchedToBearish(int barIndex = 0) + { + // + bool result = false; + + // + // Normalize ... + barIndex = NormalizeBarIndex(barIndex); + + // + // Validate ... + result = IsValid(); + if (!result) + { + return result; + } + + // + result = IsKISuperSlowBearish(barIndex) && + !IsKISuperSlowBearish(barIndex + 1); + + // + return result; + } + + bool IsKISuperSlowOverLast( + int barIndex = 0, + double tolerance = 2 // + ) + { + // + bool result = false; + + // + // Normalize ... + barIndex = NormalizeBarIndex(barIndex); + + // + // Validate ... + result = IsValid(); + if (!result) + { + return result; + } + + // + result = IsOver( + helper.GetKISuperSlow(barIndex), + helper.GetKISuperSlow(barIndex + 1), + GetPoints(symbol) * tolerance // + ); + + // + return result; + } + + bool IsKISuperSlowUnderLast( + int barIndex = 0, + double tolerance = 2 // + ) + { + // + bool result = false; + + // + // Normalize ... + barIndex = NormalizeBarIndex(barIndex); + + // + // Validate ... + result = IsValid(); + if (!result) + { + return result; + } + + // + result = IsUnder( + helper.GetKISuperSlow(barIndex), + helper.GetKISuperSlow(barIndex + 1), + GetPoints(symbol) * tolerance // + ); + + // + return result; + } + + bool IsKISuperSlowSameAsLast( + int barIndex = 0, + double tolerance = 2 // + ) + { + // + bool result = false; + + // + barIndex = NormalizeBarIndex(barIndex); + + // + result = IsSame( + helper.GetKISuperSlow(barIndex), + helper.GetKISuperSlow(barIndex + 1), + GetPoints(symbol) * tolerance // + ); + + // + return result; + } + + bool IsKISuperSlowSwitchedOverLast( + int barIndex = 0, + double tolerance = 2 // + ) + { + // + bool result = false; + + // + barIndex = NormalizeBarIndex(barIndex); + + // + result = + IsValid() && + IsKISuperSlowOverLast(barIndex, tolerance) && + !IsKISuperSlowOverLast(barIndex + 1, tolerance); + if (!result) + { + return result; + } + + // + return result; + } + + bool IsKISuperSlowSwitchedUnderLast( + int barIndex = 0, + double tolerance = 2 // + ) + { + // + bool result = false; + + // + barIndex = NormalizeBarIndex(barIndex); + + // + result = + IsValid() && + IsKISuperSlowUnderLast(barIndex, tolerance) && + !IsKISuperSlowUnderLast(barIndex + 1, tolerance); + if (!result) + { + return result; + } + + // + return result; + } + // #endregion + + // #region KI Wave ... + bool IsKIWaveBullish(int barIndex = 0) + { + // + bool result = false; + + // + // Normalize ... + barIndex = NormalizeBarIndex(barIndex); + + // + // Validate ... + result = IsValid(); + if (!result) + { + return result; + } + + // + result = helper.GetKIWaveState(barIndex) >= 1; + + // + return result; + } + + bool IsKIWaveBearish(int barIndex = 0) + { + // + bool result = false; + + // + // Normalize ... + barIndex = NormalizeBarIndex(barIndex); + + // + // Validate ... + result = IsValid(); + if (!result) + { + return result; + } + + // + result = helper.GetKIWaveState(barIndex) <= -1; + + // + return result; + } + + bool IsKIWaveSwitchedToBullish(int barIndex = 0) + { + // + bool result = false; + + // + // Normalize ... + barIndex = NormalizeBarIndex(barIndex); + + // + // Validate ... + result = IsValid(); + if (!result) + { + return result; + } + + // + result = IsKIWaveBullish(barIndex) && + !IsKIWaveBullish(barIndex + 1); + + // + return result; + } + + bool IsKIWaveSwitchedToBearish(int barIndex = 0) + { + // + bool result = false; + + // + // Normalize ... + barIndex = NormalizeBarIndex(barIndex); + + // + // Validate ... + result = IsValid(); + if (!result) + { + return result; + } + + // + result = IsKIWaveBearish(barIndex) && + !IsKIWaveBearish(barIndex + 1); + + // + return result; + } + + bool IsKIWaveOverLast( + int barIndex = 0, + double tolerance = 2 // + ) + { + // + bool result = false; + + // + barIndex = NormalizeBarIndex(barIndex); + + // + result = IsValid() && + helper.GetKIWave(barIndex) > helper.GetKIWave(barIndex + 1); + + // + return result; + } + + bool IsKIWaveUnderLast( + int barIndex = 0, + double tolerance = 2 // + ) + { + // + bool result = false; + + // + barIndex = NormalizeBarIndex(barIndex); + + // + result = IsValid() && + helper.GetKIWave(barIndex) < helper.GetKIWave(barIndex + 1); + + // + return result; + } + + bool IsKIWaveSwitchedOverLast( + int barIndex = 0, + double tolerance = 2 // + ) + { + // + bool result = false; + + // + barIndex = NormalizeBarIndex(barIndex); + + // + result = + IsValid() && + IsKIWaveOverLast(barIndex) && + !IsKIWaveOverLast(barIndex + 1); + + // + return result; + } + + bool IsKIWaveSwitchedUnderLast( + int barIndex = 0, + double tolerance = 2 // + ) + { + // + bool result = false; + + // + barIndex = NormalizeBarIndex(barIndex); + + // + result = + IsValid() && + IsKIWaveUnderLast(barIndex) && + !IsKIWaveUnderLast(barIndex + 1); + + // + return result; + } + // #endregion + + // #region KI Band ... + bool IsPriceOverKIUpper( + 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 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 // + ) + { + // + 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 IsPriceInsideKIBands( + 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) && + price > helper.GetKILower(barIndex); + bar.Clean(); + + // + return result; + } + + bool IsPriceSwitchedOverKIUpper( + int barIndex = 0, + ENUM_X_PRICE priceType = X_PRICE_CLOSE // + ) + { + // + bool result = false; + + // + barIndex = NormalizeBarIndex(barIndex); + + // + result = + IsValid() && + IsPriceOverKIUpper(barIndex, priceType) && + !IsPriceOverKIUpper(barIndex + 1, priceType); + + // + return result; + } + + bool IsPriceSwitchedUnderKIUpper( + int barIndex = 0, + ENUM_X_PRICE priceType = X_PRICE_CLOSE // + ) + { + // + bool result = false; + + // + barIndex = NormalizeBarIndex(barIndex); + + // + result = + IsValid() && + IsPriceUnderKIUpper(barIndex, priceType) && + !IsPriceUnderKIUpper(barIndex + 1, priceType); + + // + return result; + } + + bool IsPriceSwitchedOverKILower( + int barIndex = 0, + ENUM_X_PRICE priceType = X_PRICE_CLOSE // + ) + { + // + bool result = false; + + // + 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; + } + // #endregion + + // #region MA Fast ... + bool IsMAFastBullish( + int barIndex = 0, + ENUM_X_PRICE priceType = X_PRICE_CLOSE // + ) + { + // + bool result = false; + + // + // Normalize ... + barIndex = NormalizeBarIndex(barIndex); + + // + // Validate ... + XOHCL iBar; + result = IsValid() && + iBar.Init(symbol, period, barIndex); + if (!result) + { + return result; + } + + // + result = iBar.GetPrice(priceType) > helper.GetMAFast(barIndex); + + // + iBar.Clean(); + + // + return result; + } + + bool IsMAFastBearish( + int barIndex = 0, + ENUM_X_PRICE priceType = X_PRICE_CLOSE // + ) + { + // + bool result = false; + + // + // Normalize ... + barIndex = NormalizeBarIndex(barIndex); + + // + // Validate ... + XOHCL iBar; + result = IsValid() && + iBar.Init(symbol, period, barIndex); + if (!result) + { + return result; + } + + // + result = iBar.GetPrice(priceType) < helper.GetMAFast(barIndex); + + // + iBar.Clean(); + + // + return result; + } + + bool IsMAFastOverLast( + int barIndex = 0, + double tolerance = 2 // + ) + { + // + bool result = false; + + // + barIndex = NormalizeBarIndex(barIndex); + + // + result = + IsValid() && + IsOver( + helper.GetMAFast(barIndex), + helper.GetMAFast(barIndex + 1), + GetPoints(symbol) * tolerance // + ); + + // + return result; + } + + bool IsMAFastUnderLast( + int barIndex = 0, + double tolerance = 2 // + ) + { + // + bool result = false; + + // + barIndex = NormalizeBarIndex(barIndex); + + // + result = + IsValid() && + IsUnder( + helper.GetMAFast(barIndex), + helper.GetMAFast(barIndex + 1), + GetPoints(symbol) * tolerance // + ); + + // + return result; + } + + bool IsMAFastSwitchedOverLast( + int barIndex = 0, + double tolerance = 2 // + ) + { + // + bool result = false; + + // + barIndex = NormalizeBarIndex(barIndex); + + // + result = + IsValid() && + IsMAFastOverLast(barIndex, tolerance) && + !IsMAFastOverLast(barIndex + 1, tolerance); + + // + return result; + } + + bool IsMAFastSwitchedUnderLast( + int barIndex = 0, + double tolerance = 2 // + ) + { + // + bool result = false; + + // + barIndex = NormalizeBarIndex(barIndex); + + // + result = + IsValid() && + IsMAFastUnderLast(barIndex, tolerance) && + !IsMAFastUnderLast(barIndex + 1, tolerance); + + // + return result; + } + + bool IsMAFastSwitchedToBullish( + int barIndex = 0, + ENUM_X_PRICE priceType = X_PRICE_CLOSE // + ) + { + // + bool result = false; + + // + barIndex = NormalizeBarIndex(barIndex); + + // + result = IsValid() && + IsMAFastBullish(barIndex) && + !IsMAFastBullish(barIndex + 1); + + // + return result; + } + + bool IsMAFastSwitchedToBearish( + int barIndex = 0, + ENUM_X_PRICE priceType = X_PRICE_CLOSE // + ) + { + // + bool result = false; + + // + barIndex = NormalizeBarIndex(barIndex); + + // + result = IsValid() && + IsMAFastBearish(barIndex) && + !IsMAFastBearish(barIndex + 1); + + // + return result; + } + // #endregion + + // #region MA Slow ... + bool IsMASlowBullish( + int barIndex = 0, + ENUM_X_PRICE priceType = X_PRICE_CLOSE // + ) + { + // + bool result = false; + + // + // Normalize ... + barIndex = NormalizeBarIndex(barIndex); + + // + // Validate ... + XOHCL iBar; + result = IsValid() && + iBar.Init(symbol, period, barIndex); + if (!result) + { + return result; + } + + // + result = iBar.GetPrice(priceType) > helper.GetMASlow(barIndex); + + // + iBar.Clean(); + + // + return result; + } + + bool IsMASlowBearish( + int barIndex = 0, + ENUM_X_PRICE priceType = X_PRICE_CLOSE // + ) + { + // + bool result = false; + + // + // Normalize ... + barIndex = NormalizeBarIndex(barIndex); + + // + // Validate ... + XOHCL iBar; + result = IsValid() && + iBar.Init(symbol, period, barIndex); + if (!result) + { + return result; + } + + // + result = iBar.GetPrice(priceType) < helper.GetMASlow(barIndex); + + // + iBar.Clean(); + + // + return result; + } + + bool IsMASlowOverLast( + int barIndex = 0, + double tolerance = 2 // + ) + { + // + bool result = false; + + // + barIndex = NormalizeBarIndex(barIndex); + + // + result = + IsValid() && + IsOver( + helper.GetMASlow(barIndex), + helper.GetMASlow(barIndex + 1), + GetPoints(symbol) * tolerance // + ); + + // + return result; + } + + bool IsMASlowUnderLast( + int barIndex = 0, + double tolerance = 2 // + ) + { + // + bool result = false; + + // + barIndex = NormalizeBarIndex(barIndex); + + // + result = + IsValid() && + IsUnder( + helper.GetMASlow(barIndex), + helper.GetMASlow(barIndex + 1), + GetPoints(symbol) * tolerance // + ); + + // + return result; + } + + bool IsMASlowSwitchedOverLast( + int barIndex = 0, + double tolerance = 2 // + ) + { + // + bool result = false; + + // + barIndex = NormalizeBarIndex(barIndex); + + // + result = + IsValid() && + IsMASlowOverLast(barIndex, tolerance) && + !IsMASlowOverLast(barIndex + 1, tolerance); + + // + return result; + } + + bool IsMASlowSwitchedUnderLast( + int barIndex = 0, + double tolerance = 2 // + ) + { + // + bool result = false; + + // + barIndex = NormalizeBarIndex(barIndex); + + // + result = + IsValid() && + IsMASlowUnderLast(barIndex, tolerance) && + !IsMASlowUnderLast(barIndex + 1, tolerance); + + // + return result; + } + + bool IsMASlowSwitchedToBullish( + int barIndex = 0, + ENUM_X_PRICE priceType = X_PRICE_CLOSE // + ) + { + // + bool result = false; + + // + barIndex = NormalizeBarIndex(barIndex); + + // + result = IsValid() && + IsMASlowBullish(barIndex) && + !IsMASlowBullish(barIndex + 1); + + // + return result; + } + + bool IsMASlowSwitchedToBearish( + int barIndex = 0, + ENUM_X_PRICE priceType = X_PRICE_CLOSE // + ) + { + // + bool result = false; + + // + barIndex = NormalizeBarIndex(barIndex); + + // + result = IsValid() && + IsMASlowBearish(barIndex) && + !IsMASlowBearish(barIndex + 1); + + // + return result; + } + // #endregion + + // #region MA Super Slow ... + bool IsMASuperSlowBullish( + int barIndex = 0, + ENUM_X_PRICE priceType = X_PRICE_CLOSE // + ) + { + // + bool result = false; + + // + // Normalize ... + barIndex = NormalizeBarIndex(barIndex); + + // + // Validate ... + XOHCL iBar; + result = IsValid() && + iBar.Init(symbol, period, barIndex); + if (!result) + { + return result; + } + + // + result = iBar.GetPrice(priceType) > helper.GetMASuperSlow(barIndex); + + // + iBar.Clean(); + + // + return result; + } + + bool IsMASuperSlowBearish( + int barIndex = 0, + ENUM_X_PRICE priceType = X_PRICE_CLOSE // + ) + { + // + bool result = false; + + // + // Normalize ... + barIndex = NormalizeBarIndex(barIndex); + + // + // Validate ... + XOHCL iBar; + result = IsValid() && + iBar.Init(symbol, period, barIndex); + if (!result) + { + return result; + } + + // + result = iBar.GetPrice(priceType) < helper.GetMASuperSlow(barIndex); + + // + iBar.Clean(); + + // + return result; + } + + bool IsMASuperSlowOverLast( + int barIndex = 0, + double tolerance = 2 // + ) + { + // + bool result = false; + + // + barIndex = NormalizeBarIndex(barIndex); + + // + result = + IsValid() && + IsOver( + helper.GetMASuperSlow(barIndex), + helper.GetMASuperSlow(barIndex + 1), + GetPoints(symbol) * tolerance // + ); + + // + return result; + } + + bool IsMASuperSlowUnderLast( + int barIndex = 0, + double tolerance = 2 // + ) + { + // + bool result = false; + + // + barIndex = NormalizeBarIndex(barIndex); + + // + result = + IsValid() && + IsUnder( + helper.GetMASuperSlow(barIndex), + helper.GetMASuperSlow(barIndex + 1), + GetPoints(symbol) * tolerance // + ); + + // + return result; + } + + bool IsMASuperSlowSwitchedOverLast( + int barIndex = 0, + double tolerance = 2 // + ) + { + // + bool result = false; + + // + barIndex = NormalizeBarIndex(barIndex); + + // + result = + IsValid() && + IsMASuperSlowOverLast(barIndex, tolerance) && + !IsMASuperSlowOverLast(barIndex + 1, tolerance); + + // + return result; + } + + bool IsMASuperSlowSwitchedUnderLast( + int barIndex = 0, + double tolerance = 2 // + ) + { + // + bool result = false; + + // + barIndex = NormalizeBarIndex(barIndex); + + // + result = + IsValid() && + IsMASuperSlowUnderLast(barIndex, tolerance) && + !IsMASuperSlowUnderLast(barIndex + 1, tolerance); + + // + return result; + } + + bool IsMASuperSlowSwitchedToBullish( + int barIndex = 0, + ENUM_X_PRICE priceType = X_PRICE_CLOSE // + ) + { + // + bool result = false; + + // + barIndex = NormalizeBarIndex(barIndex); + + // + result = IsValid() && + IsMASuperSlowBullish(barIndex) && + !IsMASuperSlowBullish(barIndex + 1); + + // + return result; + } + + bool IsMASuperSlowSwitchedToBearish( + int barIndex = 0, + ENUM_X_PRICE priceType = X_PRICE_CLOSE // + ) + { + // + bool result = false; + + // + barIndex = NormalizeBarIndex(barIndex); + + // + result = IsValid() && + IsMASuperSlowBearish(barIndex) && + !IsMASuperSlowBearish(barIndex + 1); + + // + return result; + } + // #endregion + + // #region MA Fast/Slow/SuperSlow ... + + bool IsMACrossoverBullish(int barIndex = 0) + { + // + bool result = false; + + // + // Normalize ... + barIndex = NormalizeBarIndex(barIndex); + + // + // Validate ... + result = IsValid(); + if (!result) + { + return result; + } + + // + result = helper.GetMAFast(barIndex) > helper.GetMASlow(barIndex); + return result; + } + + bool IsMACrossoverBearish(int barIndex = 0) + { + // + bool result = false; + + // + // Normalize ... + barIndex = NormalizeBarIndex(barIndex); + + // + // Validate ... + result = IsValid(); + if (!result) + { + return result; + } + + // + result = helper.GetMAFast(barIndex) < helper.GetMASlow(barIndex); + return result; + } + + bool IsMACrossoverSwitchedToBullish(int barIndex = 0) + { + // + bool result = false; + + // + // Normalize ... + barIndex = NormalizeBarIndex(barIndex); + + // + // Validate ... + result = IsValid(); + if (!result) + { + return result; + } + + // + result = IsMACrossoverBullish(barIndex) && + !IsMACrossoverBullish(barIndex + 1); + return result; + } + + bool IsMACrossoverSwitchedToBearish(int barIndex = 0) + { + // + bool result = false; + + // + // Normalize ... + barIndex = NormalizeBarIndex(barIndex); + + // + // Validate ... + result = IsValid(); + if (!result) + { + return result; + } + + // + result = IsMACrossoverBearish(barIndex) && + !IsMACrossoverBearish(barIndex + 1); + return result; + } + // #endregion + + + // #region Composite ... + bool IsKIHasTrend( + double &score, + ENUM_X_DIRECTION &dir, + int barIndex = 0, + double requiredScore = 0, + double tolerance = 2 // + ) + { + // + bool result = false; + + // + score = 0; + dir = X_DIRECTION_NONE; + if (requiredScore < 0) + { + requiredScore = 0; + } + barIndex = NormalizeBarIndex(barIndex); + result = IsValid(); + if (!result) + { + return result; + } + + // + bool isBullish = IsKIFastBullish(barIndex) && IsKISlowBullish(barIndex); + bool isBearish = IsKIFastBearish(barIndex) && IsKISlowBearish(barIndex); + + // + // Scoring ... + if (isBullish) + { + // + if (IsKIFastSwitchedToBullish(barIndex)) + { + score += X_SCORE_MAX; + } + + // + if (IsKISlowSwitchedToBullish(barIndex)) + { + score += X_SCORE_NORMAL; + } + + // + if (IsKIFastSwitchedOverLast(barIndex, tolerance)) + { + score += X_SCORE_NORMAL; + } + else if (IsKIFastOverLast(barIndex, tolerance)) + { + score += X_SCORE_MIN; + } + + // + if (IsKISlowSwitchedOverLast(barIndex, tolerance)) + { + score += X_SCORE_NORMAL; + } + else if (IsKISlowOverLast(barIndex, tolerance)) + { + score += X_SCORE_MIN; + } + + // + if (IsKISuperSlowSwitchedToBullish(barIndex)) + { + score += X_SCORE_NORMAL; + } + else if (IsKISuperSlowBullish(barIndex)) + { + score += X_SCORE_MIN; + } + + // + if (IsKISuperSlowSwitchedOverLast(barIndex, tolerance)) + { + score += X_SCORE_NORMAL; + } + else if (IsKISuperSlowOverLast(barIndex, tolerance)) + { + score += X_SCORE_MIN; + } + } + else if (isBearish) + { + // + if (IsKIFastSwitchedToBearish(barIndex)) + { + score += X_SCORE_MAX; + } + + // + if (IsKISlowSwitchedToBearish(barIndex)) + { + score += X_SCORE_NORMAL; + } + + // + if (IsKIFastSwitchedUnderLast(barIndex, tolerance)) + { + score += X_SCORE_NORMAL; + } + else if (IsKIFastUnderLast(barIndex, tolerance)) + { + score += X_SCORE_MIN; + } + + // + if (IsKISlowSwitchedUnderLast(barIndex, tolerance)) + { + score += X_SCORE_NORMAL; + } + else if (IsKISlowUnderLast(barIndex, tolerance)) + { + score += X_SCORE_MIN; + } + + // + if (IsKISuperSlowSwitchedToBearish(barIndex)) + { + score += X_SCORE_NORMAL; + } + else if (IsKISuperSlowBearish(barIndex)) + { + score += X_SCORE_MIN; + } + + // + if (IsKISuperSlowSwitchedUnderLast(barIndex, tolerance)) + { + score += X_SCORE_NORMAL; + } + else if (IsKISuperSlowUnderLast(barIndex, tolerance)) + { + score += X_SCORE_MIN; + } + } + + // + dir = isBullish + ? X_DIRECTION_BULLISH + : isBearish + ? X_DIRECTION_BEARISH + : X_DIRECTION_NONE; + + // + result = HasDirection(dir) && + score >= requiredScore; + + // + return result; + } + + bool IsMAHasTrend( + double &score, + ENUM_X_DIRECTION &dir, + int barIndex = 0, + double requiredScore = 0, + double tolerance = 2 // + ) + { + // + bool result = false; + + // + score = 0; + dir = X_DIRECTION_NONE; + if (requiredScore < 0) + { + requiredScore = 0; + } + barIndex = NormalizeBarIndex(barIndex); + + // + result = IsValid(); + if (!result) + { + return result; + } + + // + bool isBullish = IsMACrossoverBullish(barIndex); + bool isBearish = IsMACrossoverBearish(barIndex); + + // + if (isBullish) + { + // + if (IsMACrossoverSwitchedToBullish(barIndex)) + { + score += X_SCORE_MAX; + } + + // + if (IsMAFastSwitchedToBullish(barIndex)) + { + score += X_SCORE_MAX; + } + else if (IsMAFastBullish(barIndex)) + { + score += X_SCORE_NORMAL; + } + + // + if (IsMAFastSwitchedOverLast(barIndex, tolerance)) + { + score += X_SCORE_NORMAL; + } + else if (IsMAFastOverLast(barIndex, tolerance)) + { + score += X_SCORE_MIN; + } + + // + if (IsMASlowSwitchedToBullish(barIndex)) + { + score += X_SCORE_NORMAL; + } + else if (IsMASlowBullish(barIndex)) + { + score += X_SCORE_MIN; + } + + // + if (IsMASlowSwitchedOverLast(barIndex, tolerance)) + { + score += X_SCORE_NORMAL; + } + else if (IsMASlowOverLast(barIndex, tolerance)) + { + score += X_SCORE_MIN; + } + + // + if (IsMASuperSlowSwitchedToBullish(barIndex)) + { + score += X_SCORE_NORMAL; + } + else if (IsMASuperSlowBullish(barIndex)) + { + score += X_SCORE_MIN; + } + + // + if (IsMASuperSlowSwitchedOverLast(barIndex, tolerance)) + { + score += X_SCORE_NORMAL; + } + else if (IsMASuperSlowOverLast(barIndex, tolerance)) + { + score += X_SCORE_MIN; + } + } + else if (isBearish) + { + // + if (IsMACrossoverSwitchedToBearish(barIndex)) + { + score += X_SCORE_MAX; + } + + // + if (IsMAFastSwitchedToBearish(barIndex)) + { + score += X_SCORE_MAX; + } + else if (IsMAFastBearish(barIndex)) + { + score += X_SCORE_NORMAL; + } + + // + if (IsMAFastSwitchedUnderLast(barIndex, tolerance)) + { + score += X_SCORE_NORMAL; + } + else if (IsMAFastUnderLast(barIndex, tolerance)) + { + score += X_SCORE_MIN; + } + + // + if (IsMASlowSwitchedToBearish(barIndex)) + { + score += X_SCORE_NORMAL; + } + else if (IsMASlowBullish(barIndex)) + { + score += X_SCORE_MIN; + } + + // + if (IsMASlowSwitchedUnderLast(barIndex, tolerance)) + { + score += X_SCORE_NORMAL; + } + else if (IsMASlowUnderLast(barIndex, tolerance)) + { + score += X_SCORE_MIN; + } + + // + if (IsMASuperSlowSwitchedToBearish(barIndex)) + { + score += X_SCORE_NORMAL; + } + else if (IsMASuperSlowBearish(barIndex)) + { + score += X_SCORE_MIN; + } + + // + if (IsMASuperSlowSwitchedUnderLast(barIndex, tolerance)) + { + score += X_SCORE_NORMAL; + } + else if (IsMASuperSlowUnderLast(barIndex, tolerance)) + { + score += X_SCORE_MIN; + } + } + + // + dir = isBullish + ? X_DIRECTION_BULLISH + : isBearish + ? X_DIRECTION_BEARISH + : X_DIRECTION_NONE; + + // + result = HasDirection(dir) && + score >= requiredScore; + + // + return result; + } + + bool IsMomentumExists( + double &score, + ENUM_X_DIRECTION &dir, + int barIndex = 0, + double requiredScore = 0, + double tolerance = 2, + double bullishThreshold = 55, + double bearishThreshold = 45, + double overboughtThreshold = 70, + double oversoldThreshold = 30 // + ) + { + // + bool result = false; + + // + score = 0; + dir = X_DIRECTION_NONE; + if (requiredScore < 0) + { + requiredScore = 0; + } + barIndex = NormalizeBarIndex(barIndex); + bullishThreshold = NormalizeXDouble(bullishThreshold, 0, 100); + bearishThreshold = NormalizeXDouble(bearishThreshold, 0, 100); + oversoldThreshold = NormalizeXDouble(oversoldThreshold, 0, 100); + overboughtThreshold = NormalizeXDouble(overboughtThreshold, 0, 100); + + // + result = IsValid(); + if (!result) + { + return result; + } + + // + bool isBullish = IsRSIBullish(barIndex, bullishThreshold, tolerance); + bool isBearish = IsRSIBearish(barIndex, bearishThreshold, tolerance); + + // + if (isBullish) + { + // + if (!IsRSIOverbought(barIndex, overboughtThreshold, tolerance)) + { + score += X_SCORE_NORMAL; + } + + // + if (IsRSIOversold(barIndex, oversoldThreshold, tolerance)) + { + score += X_SCORE_NORMAL; + } + + // + if (IsRSISwitchedFromOversold(barIndex, oversoldThreshold, tolerance)) + { + score += X_SCORE_NORMAL; + } + + // + if (IsRSISwitchedToBullish(barIndex, bullishThreshold, tolerance)) + { + score += X_SCORE_NORMAL; + } + + // + if (IsRSISwitchedToRising(barIndex)) + { + score += X_SCORE_NORMAL; + } + else if (IsRSIRising(barIndex)) + { + score += X_SCORE_MIN; + } + + // + if (IsRSISwitchedOverLast(barIndex, tolerance)) + { + score += X_SCORE_NORMAL; + } + else if (IsRSIOverLast(barIndex, tolerance)) + { + score += X_SCORE_MIN; + } + } + else if (isBearish) + { + // + if (!IsRSIOversold(barIndex, oversoldThreshold, tolerance)) + { + score += X_SCORE_NORMAL; + } + + // + if (IsRSIOverbought(barIndex, overboughtThreshold, tolerance)) + { + score += X_SCORE_NORMAL; + } + + // + if (IsRSISwitchedFromOverbought(barIndex, overboughtThreshold, tolerance)) + { + score += X_SCORE_NORMAL; + } + + // + if (IsRSISwitchedToBearish(barIndex, bearishThreshold, tolerance)) + { + score += X_SCORE_NORMAL; + } + + // + if (IsRSISwitchedToFalling(barIndex)) + { + score += X_SCORE_NORMAL; + } + else if (IsRSIFalling(barIndex)) + { + score += X_SCORE_MIN; + } + + // + if (IsRSISwitchedUnderLast(barIndex, tolerance)) + { + score += X_SCORE_NORMAL; + } + else if (IsRSIUnderLast(barIndex, tolerance)) + { + score += X_SCORE_MIN; + } + } + + // + dir = isBullish + ? X_DIRECTION_BULLISH + : isBearish + ? X_DIRECTION_BEARISH + : X_DIRECTION_NONE; + + // + result = HasDirection(dir) && + score >= requiredScore; + + // + return result; + } + + bool IsVolatilityExists( + double &score, + ENUM_X_DIRECTION &dir, + int barIndex = 0, + double requiredScore = 0, + double tolerance = 2, + ENUM_X_PRICE priceType = X_PRICE_CLOSE // + ) + { + // + bool result = false; + + // + score = 0; + dir = X_DIRECTION_NONE; + if (requiredScore < 0) + { + requiredScore = 0; + } + barIndex = NormalizeBarIndex(barIndex); + + // + result = IsValid(); + if (!result) + { + return result; + } + + // + bool isBullish = IsATROverLast(barIndex, tolerance) || IsATRSmoothedOverLast(barIndex, tolerance); + bool isBearish = IsATRUnderLast(barIndex, tolerance) || IsATRSmoothedUnderLast(barIndex, tolerance); + + // + if (isBullish) + { + // + if (IsATRBreakoutDown(barIndex, priceType)) + { + score += X_SCORE_NORMAL; + } + + // + if (!IsATRBreakoutUp(barIndex, priceType)) + { + score += X_SCORE_MIN; + } + + // + if (IsATRSwitchedOverLast(barIndex, tolerance)) + { + score += X_SCORE_NORMAL; + } + else if (IsATROverLast(barIndex, tolerance)) + { + score += X_SCORE_MIN; + } + + // + if (IsATRSmoothedSwitchedOverLast(barIndex, tolerance)) + { + score += X_SCORE_NORMAL; + } + else if (IsATRSmoothedOverLast(barIndex, tolerance)) + { + score += X_SCORE_MIN; + } + + // + if (IsVolatilitySwitchdToHigh(barIndex)) + { + score += X_SCORE_NORMAL; + } + else if (IsVolatilityHigh(barIndex)) + { + score += X_SCORE_MIN; + } + } + else if (isBearish) + { + // + if (!IsATRBreakoutDown(barIndex, priceType)) + { + score += X_SCORE_NORMAL; + } + + // + if (IsATRBreakoutUp(barIndex, priceType)) + { + score += X_SCORE_MIN; + } + + // + if (IsATRSwitchedUnderLast(barIndex, tolerance)) + { + score += X_SCORE_NORMAL; + } + else if (IsATRUnderLast(barIndex, tolerance)) + { + score += X_SCORE_MIN; + } + + // + if (IsATRSmoothedSwitchedUnderLast(barIndex, tolerance)) + { + score += X_SCORE_NORMAL; + } + else if (IsATRSmoothedUnderLast(barIndex, tolerance)) + { + score += X_SCORE_MIN; + } + + // + if (IsVolatilitySwitchdToLow(barIndex)) + { + score += X_SCORE_NORMAL; + } + else if (IsVolatilityLow(barIndex)) + { + score += X_SCORE_MIN; + } + } + + // + dir = isBullish + ? X_DIRECTION_BULLISH + : isBearish + ? X_DIRECTION_BEARISH + : X_DIRECTION_NONE; + + // + result = HasDirection(dir) && + score >= requiredScore; + + // + return result; + } + // #endregion + + // #region Signalling Conditions ... + bool HasCompositeTrend( + double &score, + ENUM_X_DIRECTION &dir, + int barIndex = 0, + double requiredScore = 0, + double tolerance = 2, + ENUM_X_PRICE priceType = X_PRICE_CLOSE, + double bullishThreshold = 55, + double bearishThreshold = 45, + double overboughtThreshold = 70, + double oversoldThreshold = 30 // + ) + { + // + bool result = false; + + // + score = 0; + dir = X_DIRECTION_NONE; + barIndex = NormalizeBarIndex(barIndex); + + // + result = IsValid(); + if (!result) + { + return result; + } + + // + bool hasKI, hasMa, hasMomentum, hasVolatility; + double kiScore, maScore, momentumScore, volatilityScore; + ENUM_X_DIRECTION kiDir, maDir, momentumDir, volatilityDdir; + + // + hasKI = IsKIHasTrend( + kiScore, + kiDir, + barIndex, + 1, + tolerance // + ); + hasMa = IsMAHasTrend( + maScore, + maDir, + barIndex, + 1, + tolerance // + ); + hasVolatility = IsVolatilityExists( + volatilityScore, + volatilityDdir, + barIndex, + 1, + tolerance, + priceType // + ); + hasMomentum = IsMomentumExists( + momentumScore, + momentumDir, + barIndex, + 1, + tolerance, + bullishThreshold, + bearishThreshold, + overboughtThreshold, + oversoldThreshold // + ); + + // + bool isBullish = + hasKI && IsXBullish(kiDir) && + hasMa && IsXBullish(maDir) && + hasMomentum && IsXBullish(momentumDir) && + hasVolatility && IsXBullish(volatilityDdir); + + // + bool isBearish = + hasKI && IsXBearish(kiDir) && + hasMa && IsXBearish(maDir) && + hasMomentum && IsXBearish(momentumDir) && + hasVolatility && IsXBullish(volatilityDdir); + + // + result = isBullish || isBearish; + if (!result) + { + return result; + } + + // + // Summarizing Scores ... + score = (kiScore + maScore + momentumScore + volatilityScore); + result = + result && + score >= requiredScore; + if (result) + { + // + dir = isBullish + ? X_DIRECTION_BULLISH + : isBearish + ? X_DIRECTION_BEARISH + : X_DIRECTION_NONE; + } + + // + result = result && + HasDirection(dir); + + // + return result; + } + // #endregion diff --git a/Libraries/x-saherelm.common.extensions.lib.mq5 b/Libraries/x-saherelm.common.extensions.lib.mq5 index a79f4d22..1b457f1e 100644 --- a/Libraries/x-saherelm.common.extensions.lib.mq5 +++ b/Libraries/x-saherelm.common.extensions.lib.mq5 @@ -932,6 +932,10 @@ double GetPoints( // return result; } +double GetXPoints(string mSymbol = NULL) +{ + return GetPoints(mSymbol); +} /** * Converts Price to Point ... @@ -5316,7 +5320,8 @@ bool IsOver( double current, double previous, double tolerance = 2 // -) { +) +{ // bool result = NotEmptyZero(current) && @@ -5331,7 +5336,8 @@ bool IsUnder( double current, double previous, double tolerance = 2 // -) { +) +{ // bool result = NotEmptyZero(current) && diff --git a/X121XKIEA/Classes/x-saherelm.x121.xki.parser.class.mq5 b/X121XKIEA/Classes/x-saherelm.x121.xki.parser.class.mq5 index 8b5610c9..05e973b3 100644 --- a/X121XKIEA/Classes/x-saherelm.x121.xki.parser.class.mq5 +++ b/X121XKIEA/Classes/x-saherelm.x121.xki.parser.class.mq5 @@ -26,13 +26,6 @@ // // Definitions ... -enum ENUM_X121_XKI_SCORE -{ - X121_XKI_SCORE_NONE = 0, - X121_XKI_SCORE_MIN = 1, - X121_XKI_SCORE_NORMAL = 2, - X121_XKI_SCORE_MAX = 3, -}; // // Implementation ... @@ -111,1856 +104,72 @@ class XCX121XKIHelperParser : XCBase return result; } + double GetPoints() + { + return GetXPoints(symbol); + } + + XOHCL GetBar(int barIndex = 0) + { + // + barIndex = NormalizeBarIndex(barIndex); + XOHCL result; + result.Init(symbol, period); + return result; + } + + double GetPrice( + int barIndex = 0, + ENUM_X_PRICE priceType = X_PRICE_CLOSE // + ) + { + // + XOHCL bar = GetBar(barIndex); + double result = EMPTY_VALUE; + if (bar.IsValid()) + { + result = bar.GetPrice(priceType); + } + bar.Clean(); + + // + return result; + } + // // Parsers ... // Indicators Base Conditions ... - // #region KI Fast ... - bool IsKIFastBullish(int barIndex = 0) - { - // - bool result = false; - - // - // Normalize ... - barIndex = NormalizeBarIndex(barIndex); - - // - // Validate ... - result = IsValid(); - if (!result) - { - return result; - } - - // - double state = helper.GetKIFastState(barIndex); - result = state >= 1; - - // - return result; - } - - bool IsKIFastBearish(int barIndex = 0) - { - // - bool result = false; - - // - // Normalize ... - barIndex = NormalizeBarIndex(barIndex); - - // - // Validate ... - result = IsValid(); - if (!result) - { - return result; - } - - // - double state = helper.GetKIFastState(barIndex); - result = state <= -1; - - // - return result; - } - - bool IsKIFastSwitchedToBullish(int barIndex = 0) - { - // - bool result = false; - - // - // Normalize ... - barIndex = NormalizeBarIndex(barIndex); - - // - // Validate ... - result = IsValid(); - if (!result) - { - return result; - } - - // - result = IsKIFastBullish(barIndex) && - !IsKIFastBullish(barIndex + 1); - - // - return result; - } - - bool IsKIFastSwitchedToBearish(int barIndex = 0) - { - // - bool result = false; - - // - // Normalize ... - barIndex = NormalizeBarIndex(barIndex); - - // - // Validate ... - result = IsValid(); - if (!result) - { - return result; - } - - // - result = IsKIFastBearish(barIndex) && - !IsKIFastBearish(barIndex + 1); - - // - return result; - } - - bool IsKIFastOverLast( - int barIndex = 0, - double tolerance = 2 // - ) - { - // - bool result = false; - - // - // Normalize ... - barIndex = NormalizeBarIndex(barIndex); - - // - // Validate ... - result = IsValid(); - if (!result) - { - return result; - } - - // - result = IsOver( - helper.GetKIFast(barIndex), - helper.GetKIFast(barIndex + 1), - GetPoints(symbol) * tolerance // - ); - - // - return result; - } - - bool IsKIFastUnderLast( - int barIndex = 0, - double tolerance = 2 // - ) - { - // - bool result = false; - - // - // Normalize ... - barIndex = NormalizeBarIndex(barIndex); - - // - // Validate ... - result = IsValid(); - if (!result) - { - return result; - } - - // - result = IsUnder( - helper.GetKIFast(barIndex), - helper.GetKIFast(barIndex + 1), - GetPoints(symbol) * tolerance // - ); - - // - return result; - } - - bool IsKIFastSameAsLast( - int barIndex = 0, - double tolerance = 2 // - ) - { - // - bool result = false; - - // - barIndex = NormalizeBarIndex(barIndex); - - // - result = IsValid() && - IsSame( - helper.GetKIFast(barIndex), - helper.GetKIFast(barIndex + 1), - GetPoints(symbol) * tolerance // - ); - - // - return result; - } - - bool IsKIFastSwitchedOverLast( - int barIndex = 0, - double tolerance = 2 // - ) - { - // - bool result = false; - - // - barIndex = NormalizeBarIndex(barIndex); - - // - result = - IsValid() && - IsKIFastOverLast(barIndex, tolerance) && - !IsKIFastOverLast(barIndex + 1, tolerance); - if (!result) - { - return result; - } - - // - return result; - } - - bool IsKIFastSwitchedUnderLast( - int barIndex = 0, - double tolerance = 2 // - ) - { - // - bool result = false; - - // - barIndex = NormalizeBarIndex(barIndex); - - // - result = - IsValid() && - IsKIFastUnderLast(barIndex, tolerance) && - !IsKIFastUnderLast(barIndex + 1, tolerance); - if (!result) - { - return result; - } - - // - return result; - } - // #endregion - - // #region KI Slow ... - bool IsKISlowBullish(int barIndex = 0) - { - // - bool result = false; - - // - // Normalize ... - barIndex = NormalizeBarIndex(barIndex); - - // - // Validate ... - result = IsValid(); - if (!result) - { - return result; - } - - // - double state = helper.GetKISlowState(barIndex); - result = state >= 1; - - // - return result; - } - - bool IsKISlowBearish(int barIndex = 0) - { - // - bool result = false; - - // - // Normalize ... - barIndex = NormalizeBarIndex(barIndex); - - // - // Validate ... - result = IsValid(); - if (!result) - { - return result; - } - - // - double state = helper.GetKISlowState(barIndex); - result = state <= -1; - - // - return result; - } - - bool IsKISlowSwitchedToBullish(int barIndex = 0) - { - // - bool result = false; - - // - // Normalize ... - barIndex = NormalizeBarIndex(barIndex); - - // - // Validate ... - result = IsValid(); - if (!result) - { - return result; - } - - // - result = IsKISlowBullish(barIndex) && - !IsKISlowBullish(barIndex + 1); - - // - return result; - } - - bool IsKISlowSwitchedToBearish(int barIndex = 0) - { - // - bool result = false; - - // - // Normalize ... - barIndex = NormalizeBarIndex(barIndex); - - // - // Validate ... - result = IsValid(); - if (!result) - { - return result; - } - - // - result = IsKISlowBearish(barIndex) && - !IsKISlowBearish(barIndex + 1); - - // - return result; - } - - bool IsKISlowOverLast( - int barIndex = 0, - double tolerance = 2 // - ) - { - // - bool result = false; - - // - // Normalize ... - barIndex = NormalizeBarIndex(barIndex); - - // - // Validate ... - result = IsValid(); - if (!result) - { - return result; - } - - // - result = IsOver( - helper.GetKISlow(barIndex), - helper.GetKISlow(barIndex + 1), - GetPoints(symbol) * tolerance // - ); - - // - return result; - } - - bool IsKISlowUnderLast( - int barIndex = 0, - double tolerance = 2 // - ) - { - // - bool result = false; - - // - // Normalize ... - barIndex = NormalizeBarIndex(barIndex); - - // - // Validate ... - result = IsValid(); - if (!result) - { - return result; - } - - // - result = IsUnder( - helper.GetKISlow(barIndex), - helper.GetKISlow(barIndex + 1), - GetPoints(symbol) * tolerance // - ); - - // - return result; - } - - bool IsKISlowSameAsLast( - int barIndex = 0, - double tolerance = 2 // - ) - { - // - bool result = false; - - // - barIndex = NormalizeBarIndex(barIndex); - - // - result = IsSame( - helper.GetKISlow(barIndex), - helper.GetKISlow(barIndex + 1), - GetPoints(symbol) * tolerance // - ); - - // - return result; - } - - bool IsKISlowSwitchedOverLast( - int barIndex = 0, - double tolerance = 2 // - ) - { - // - bool result = false; - - // - barIndex = NormalizeBarIndex(barIndex); - - // - result = - IsValid() && - IsKISlowOverLast(barIndex, tolerance) && - !IsKISlowOverLast(barIndex + 1, tolerance); - if (!result) - { - return result; - } - - // - return result; - } - - bool IsKISlowSwitchedUnderLast( - int barIndex = 0, - double tolerance = 2 // - ) - { - // - bool result = false; - - // - barIndex = NormalizeBarIndex(barIndex); - - // - result = - IsValid() && - IsKISlowUnderLast(barIndex, tolerance) && - !IsKISlowUnderLast(barIndex + 1, tolerance); - if (!result) - { - return result; - } - - // - return result; - } - // #endregion - - // #region KI Super Slow ... - bool IsKISuperSlowBullish(int barIndex = 0) - { - // - bool result = false; - - // - // Normalize ... - barIndex = NormalizeBarIndex(barIndex); - - // - // Validate ... - result = IsValid(); - if (!result) - { - return result; - } - - // - double state = helper.GetKISuperSlowState(barIndex); - result = state >= 1; - - // - return result; - } - - bool IsKISuperSlowBearish(int barIndex = 0) - { - // - bool result = false; - - // - // Normalize ... - barIndex = NormalizeBarIndex(barIndex); - - // - // Validate ... - result = IsValid(); - if (!result) - { - return result; - } - - // - double state = helper.GetKISuperSlowState(barIndex); - result = state <= -1; - - // - return result; - } - - bool IsKISuperSlowSwitchedToBullish(int barIndex = 0) - { - // - bool result = false; - - // - // Normalize ... - barIndex = NormalizeBarIndex(barIndex); - - // - // Validate ... - result = IsValid(); - if (!result) - { - return result; - } - - // - result = IsKISuperSlowBullish(barIndex) && - !IsKISuperSlowBullish(barIndex + 1); - - // - return result; - } - - bool IsKISuperSlowSwitchedToBearish(int barIndex = 0) - { - // - bool result = false; - - // - // Normalize ... - barIndex = NormalizeBarIndex(barIndex); - - // - // Validate ... - result = IsValid(); - if (!result) - { - return result; - } - - // - result = IsKISuperSlowBearish(barIndex) && - !IsKISuperSlowBearish(barIndex + 1); - - // - return result; - } - - bool IsKISuperSlowOverLast( - int barIndex = 0, - double tolerance = 2 // - ) - { - // - bool result = false; - - // - // Normalize ... - barIndex = NormalizeBarIndex(barIndex); - - // - // Validate ... - result = IsValid(); - if (!result) - { - return result; - } - - // - result = IsOver( - helper.GetKISuperSlow(barIndex), - helper.GetKISuperSlow(barIndex + 1), - GetPoints(symbol) * tolerance // - ); - - // - return result; - } - - bool IsKISuperSlowUnderLast( - int barIndex = 0, - double tolerance = 2 // - ) - { - // - bool result = false; - - // - // Normalize ... - barIndex = NormalizeBarIndex(barIndex); - - // - // Validate ... - result = IsValid(); - if (!result) - { - return result; - } - - // - result = IsUnder( - helper.GetKISuperSlow(barIndex), - helper.GetKISuperSlow(barIndex + 1), - GetPoints(symbol) * tolerance // - ); - - // - return result; - } - - bool IsKISuperSlowSameAsLast( - int barIndex = 0, - double tolerance = 2 // - ) - { - // - bool result = false; - - // - barIndex = NormalizeBarIndex(barIndex); - - // - result = IsSame( - helper.GetKISuperSlow(barIndex), - helper.GetKISuperSlow(barIndex + 1), - GetPoints(symbol) * tolerance // - ); - - // - return result; - } - - bool IsKISuperSlowSwitchedOverLast( - int barIndex = 0, - double tolerance = 2 // - ) - { - // - bool result = false; - - // - barIndex = NormalizeBarIndex(barIndex); - - // - result = - IsValid() && - IsKISuperSlowOverLast(barIndex, tolerance) && - !IsKISuperSlowOverLast(barIndex + 1, tolerance); - if (!result) - { - return result; - } - - // - return result; - } - - bool IsKISuperSlowSwitchedUnderLast( - int barIndex = 0, - double tolerance = 2 // - ) - { - // - bool result = false; - - // - barIndex = NormalizeBarIndex(barIndex); - - // - result = - IsValid() && - IsKISuperSlowUnderLast(barIndex, tolerance) && - !IsKISuperSlowUnderLast(barIndex + 1, tolerance); - if (!result) - { - return result; - } - - // - return result; - } - // #endregion - - // #region KI Wave ... - bool IsKIWaveBullish(int barIndex = 0) - { - // - bool result = false; - - // - // Normalize ... - barIndex = NormalizeBarIndex(barIndex); - - // - // Validate ... - result = IsValid(); - if (!result) - { - return result; - } - - // - result = helper.GetKIWaveState(barIndex) >= 1; - - // - return result; - } - - bool IsKIWaveBearish(int barIndex = 0) - { - // - bool result = false; - - // - // Normalize ... - barIndex = NormalizeBarIndex(barIndex); - - // - // Validate ... - result = IsValid(); - if (!result) - { - return result; - } - - // - result = helper.GetKIWaveState(barIndex) <= -1; - - // - return result; - } - - bool IsKIWaveSwitchedToBullish(int barIndex = 0) - { - // - bool result = false; - - // - // Normalize ... - barIndex = NormalizeBarIndex(barIndex); - - // - // Validate ... - result = IsValid(); - if (!result) - { - return result; - } - - // - result = IsKIWaveBullish(barIndex) && - !IsKIWaveBullish(barIndex + 1); - - // - return result; - } - - bool IsKIWaveSwitchedToBearish(int barIndex = 0) - { - // - bool result = false; - - // - // Normalize ... - barIndex = NormalizeBarIndex(barIndex); - - // - // Validate ... - result = IsValid(); - if (!result) - { - return result; - } - - // - result = IsKIWaveBearish(barIndex) && - !IsKIWaveBearish(barIndex + 1); - - // - return result; - } - - bool IsKIWaveOverLast( - int barIndex = 0, - double tolerance = 2 // - ) - { - // - bool result = false; - - // - barIndex = NormalizeBarIndex(barIndex); - - // - result = IsValid() && - helper.GetKIWave(barIndex) > helper.GetKIWave(barIndex + 1); - - // - return result; - } - - bool IsKIWaveUnderLast( - int barIndex = 0, - double tolerance = 2 // - ) - { - // - bool result = false; - - // - barIndex = NormalizeBarIndex(barIndex); - - // - result = IsValid() && - helper.GetKIWave(barIndex) < helper.GetKIWave(barIndex + 1); - - // - return result; - } - - bool IsKIWaveSwitchedOverLast( - int barIndex = 0, - double tolerance = 2 // - ) - { - // - bool result = false; - - // - barIndex = NormalizeBarIndex(barIndex); - - // - result = - IsValid() && - IsKIWaveOverLast(barIndex) && - !IsKIWaveOverLast(barIndex + 1); - - // - return result; - } - - bool IsKIWaveSwitchedUnderLast( - int barIndex = 0, - double tolerance = 2 // - ) - { - // - bool result = false; - - // - barIndex = NormalizeBarIndex(barIndex); - - // - result = - IsValid() && - IsKIWaveUnderLast(barIndex) && - !IsKIWaveUnderLast(barIndex + 1); - - // - return result; - } - // #endregion - - // #region KI Band ... - bool IsPriceOverKIUpper( - 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 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 // - ) - { - // - 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 IsPriceInsideKIBands( - 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) && - price > helper.GetKILower(barIndex); - bar.Clean(); - - // - return result; - } - - bool IsPriceSwitchedOverKIUpper( - int barIndex = 0, - ENUM_X_PRICE priceType = X_PRICE_CLOSE // - ) - { - // - bool result = false; - - // - barIndex = NormalizeBarIndex(barIndex); - - // - result = - IsValid() && - IsPriceOverKIUpper(barIndex, priceType) && - !IsPriceOverKIUpper(barIndex + 1, priceType); - - // - return result; - } - - bool IsPriceSwitchedUnderKIUpper( - int barIndex = 0, - ENUM_X_PRICE priceType = X_PRICE_CLOSE // - ) - { - // - bool result = false; - - // - barIndex = NormalizeBarIndex(barIndex); - - // - result = - IsValid() && - IsPriceUnderKIUpper(barIndex, priceType) && - !IsPriceUnderKIUpper(barIndex + 1, priceType); - - // - return result; - } - - bool IsPriceSwitchedOverKILower( - int barIndex = 0, - ENUM_X_PRICE priceType = X_PRICE_CLOSE // - ) - { - // - bool result = false; - - // - 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; - } - // #endregion - - // #region MA Fast/Slow/SuperSlow ... - - // #region MA Fast ... - bool IsMAFastBullish( - int barIndex = 0, - ENUM_X_PRICE priceType = X_PRICE_CLOSE // - ) - { - // - bool result = false; - - // - // Normalize ... - barIndex = NormalizeBarIndex(barIndex); - - // - // Validate ... - XOHCL iBar; - result = IsValid() && - iBar.Init(symbol, period, barIndex); - if (!result) - { - return result; - } - - // - result = iBar.GetPrice(priceType) > helper.GetMAFast(barIndex); - - // - iBar.Clean(); - - // - return result; - } - - bool IsMAFastBearish( - int barIndex = 0, - ENUM_X_PRICE priceType = X_PRICE_CLOSE // - ) - { - // - bool result = false; - - // - // Normalize ... - barIndex = NormalizeBarIndex(barIndex); - - // - // Validate ... - XOHCL iBar; - result = IsValid() && - iBar.Init(symbol, period, barIndex); - if (!result) - { - return result; - } - - // - result = iBar.GetPrice(priceType) < helper.GetMAFast(barIndex); - - // - iBar.Clean(); - - // - return result; - } - - bool IsMAFastOverLast( - int barIndex = 0, - double tolerance = 2 // - ) - { - // - bool result = false; - - // - barIndex = NormalizeBarIndex(barIndex); - - // - result = - IsValid() && - IsOver( - helper.GetMAFast(barIndex), - helper.GetMAFast(barIndex + 1), - GetPoints(symbol) * tolerance // - ); - - // - return result; - } - - bool IsMAFastUnderLast( - int barIndex = 0, - double tolerance = 2 // - ) - { - // - bool result = false; - - // - barIndex = NormalizeBarIndex(barIndex); - - // - result = - IsValid() && - IsUnder( - helper.GetMAFast(barIndex), - helper.GetMAFast(barIndex + 1), - GetPoints(symbol) * tolerance // - ); - - // - return result; - } - - bool IsMAFastSwitchedOverLast( - int barIndex = 0, - double tolerance = 2 // - ) - { - // - bool result = false; - - // - barIndex = NormalizeBarIndex(barIndex); - - // - result = - IsValid() && - IsMAFastOverLast(barIndex, tolerance) && - !IsMAFastOverLast(barIndex + 1, tolerance); - - // - return result; - } - - bool IsMAFastSwitchedUnderLast( - int barIndex = 0, - double tolerance = 2 // - ) - { - // - bool result = false; - - // - barIndex = NormalizeBarIndex(barIndex); - - // - result = - IsValid() && - IsMAFastUnderLast(barIndex, tolerance) && - !IsMAFastUnderLast(barIndex + 1, tolerance); - - // - return result; - } - - bool IsMAFastSwitchedToBullish( - int barIndex = 0, - ENUM_X_PRICE priceType = X_PRICE_CLOSE // - ) - { - // - bool result = false; - - // - barIndex = NormalizeBarIndex(barIndex); - - // - result = IsValid() && - IsMAFastBullish(barIndex) && - !IsMAFastBullish(barIndex + 1); - - // - return result; - } - - bool IsMAFastSwitchedToBearish( - int barIndex = 0, - ENUM_X_PRICE priceType = X_PRICE_CLOSE // - ) - { - // - bool result = false; - - // - barIndex = NormalizeBarIndex(barIndex); - - // - result = IsValid() && - IsMAFastBearish(barIndex) && - !IsMAFastBearish(barIndex + 1); - - // - return result; - } - // #endregion - - // #region MA Slow ... - bool IsMASlowBullish( - int barIndex = 0, - ENUM_X_PRICE priceType = X_PRICE_CLOSE // - ) - { - // - bool result = false; - - // - // Normalize ... - barIndex = NormalizeBarIndex(barIndex); - - // - // Validate ... - XOHCL iBar; - result = IsValid() && - iBar.Init(symbol, period, barIndex); - if (!result) - { - return result; - } - - // - result = iBar.GetPrice(priceType) > helper.GetMASlow(barIndex); - - // - iBar.Clean(); - - // - return result; - } - - bool IsMASlowBearish( - int barIndex = 0, - ENUM_X_PRICE priceType = X_PRICE_CLOSE // - ) - { - // - bool result = false; - - // - // Normalize ... - barIndex = NormalizeBarIndex(barIndex); - - // - // Validate ... - XOHCL iBar; - result = IsValid() && - iBar.Init(symbol, period, barIndex); - if (!result) - { - return result; - } - - // - result = iBar.GetPrice(priceType) < helper.GetMASlow(barIndex); - - // - iBar.Clean(); - - // - return result; - } - - bool IsMASlowOverLast( - int barIndex = 0, - double tolerance = 2 // - ) - { - // - bool result = false; - - // - barIndex = NormalizeBarIndex(barIndex); - - // - result = - IsValid() && - IsOver( - helper.GetMASlow(barIndex), - helper.GetMASlow(barIndex + 1), - GetPoints(symbol) * tolerance // - ); - - // - return result; - } - - bool IsMASlowUnderLast( - int barIndex = 0, - double tolerance = 2 // - ) - { - // - bool result = false; - - // - barIndex = NormalizeBarIndex(barIndex); - - // - result = - IsValid() && - IsUnder( - helper.GetMASlow(barIndex), - helper.GetMASlow(barIndex + 1), - GetPoints(symbol) * tolerance // - ); - - // - return result; - } - - bool IsMASlowSwitchedOverLast( - int barIndex = 0, - double tolerance = 2 // - ) - { - // - bool result = false; - - // - barIndex = NormalizeBarIndex(barIndex); - - // - result = - IsValid() && - IsMASlowOverLast(barIndex, tolerance) && - !IsMASlowOverLast(barIndex + 1, tolerance); - - // - return result; - } - - bool IsMASlowSwitchedUnderLast( - int barIndex = 0, - double tolerance = 2 // - ) - { - // - bool result = false; - - // - barIndex = NormalizeBarIndex(barIndex); - - // - result = - IsValid() && - IsMASlowUnderLast(barIndex, tolerance) && - !IsMASlowUnderLast(barIndex + 1, tolerance); - - // - return result; - } - - bool IsMASlowSwitchedToBullish( - int barIndex = 0, - ENUM_X_PRICE priceType = X_PRICE_CLOSE // - ) - { - // - bool result = false; - - // - barIndex = NormalizeBarIndex(barIndex); - - // - result = IsValid() && - IsMASlowBullish(barIndex) && - !IsMASlowBullish(barIndex + 1); - - // - return result; - } - - bool IsMASlowSwitchedToBearish( - int barIndex = 0, - ENUM_X_PRICE priceType = X_PRICE_CLOSE // - ) - { - // - bool result = false; - - // - barIndex = NormalizeBarIndex(barIndex); - - // - result = IsValid() && - IsMASlowBearish(barIndex) && - !IsMASlowBearish(barIndex + 1); - - // - return result; - } - // #endregion - - // #region MA Super Slow ... - bool IsMASuperSlowBullish( - int barIndex = 0, - ENUM_X_PRICE priceType = X_PRICE_CLOSE // - ) - { - // - bool result = false; - - // - // Normalize ... - barIndex = NormalizeBarIndex(barIndex); - - // - // Validate ... - XOHCL iBar; - result = IsValid() && - iBar.Init(symbol, period, barIndex); - if (!result) - { - return result; - } - - // - result = iBar.GetPrice(priceType) > helper.GetMASuperSlow(barIndex); - - // - iBar.Clean(); - - // - return result; - } - - bool IsMASuperSlowBearish( - int barIndex = 0, - ENUM_X_PRICE priceType = X_PRICE_CLOSE // - ) - { - // - bool result = false; - - // - // Normalize ... - barIndex = NormalizeBarIndex(barIndex); - - // - // Validate ... - XOHCL iBar; - result = IsValid() && - iBar.Init(symbol, period, barIndex); - if (!result) - { - return result; - } - - // - result = iBar.GetPrice(priceType) < helper.GetMASuperSlow(barIndex); - - // - iBar.Clean(); - - // - return result; - } - - bool IsMASuperSlowOverLast( - int barIndex = 0, - double tolerance = 2 // - ) - { - // - bool result = false; - - // - barIndex = NormalizeBarIndex(barIndex); - - // - result = - IsValid() && - IsOver( - helper.GetMASuperSlow(barIndex), - helper.GetMASuperSlow(barIndex + 1), - GetPoints(symbol) * tolerance // - ); - - // - return result; - } - - bool IsMASuperSlowUnderLast( - int barIndex = 0, - double tolerance = 2 // - ) - { - // - bool result = false; - - // - barIndex = NormalizeBarIndex(barIndex); - - // - result = - IsValid() && - IsUnder( - helper.GetMASuperSlow(barIndex), - helper.GetMASuperSlow(barIndex + 1), - GetPoints(symbol) * tolerance // - ); - - // - return result; - } - - bool IsMASuperSlowSwitchedOverLast( - int barIndex = 0, - double tolerance = 2 // - ) - { - // - bool result = false; - - // - barIndex = NormalizeBarIndex(barIndex); - - // - result = - IsValid() && - IsMASuperSlowOverLast(barIndex, tolerance) && - !IsMASuperSlowOverLast(barIndex + 1, tolerance); - - // - return result; - } - - bool IsMASuperSlowSwitchedUnderLast( - int barIndex = 0, - double tolerance = 2 // - ) - { - // - bool result = false; - - // - barIndex = NormalizeBarIndex(barIndex); - - // - result = - IsValid() && - IsMASuperSlowUnderLast(barIndex, tolerance) && - !IsMASuperSlowUnderLast(barIndex + 1, tolerance); - - // - return result; - } - - bool IsMASuperSlowSwitchedToBullish( - int barIndex = 0, - ENUM_X_PRICE priceType = X_PRICE_CLOSE // - ) - { - // - bool result = false; - - // - barIndex = NormalizeBarIndex(barIndex); - - // - result = IsValid() && - IsMASuperSlowBullish(barIndex) && - !IsMASuperSlowBullish(barIndex + 1); - - // - return result; - } - - bool IsMASuperSlowSwitchedToBearish( - int barIndex = 0, - ENUM_X_PRICE priceType = X_PRICE_CLOSE // - ) - { - // - bool result = false; - - // - barIndex = NormalizeBarIndex(barIndex); - - // - result = IsValid() && - IsMASuperSlowBearish(barIndex) && - !IsMASuperSlowBearish(barIndex + 1); - - // - return result; - } - // #endregion - - bool IsMACrossoverBullish(int barIndex = 0) - { - // - bool result = false; - - // - // Normalize ... - barIndex = NormalizeBarIndex(barIndex); - - // - // Validate ... - result = IsValid(); - if (!result) - { - return result; - } - - // - result = helper.GetMAFast(barIndex) > helper.GetMASlow(barIndex); - return result; - } - - bool IsMACrossoverBearish(int barIndex = 0) - { - // - bool result = false; - - // - // Normalize ... - barIndex = NormalizeBarIndex(barIndex); - - // - // Validate ... - result = IsValid(); - if (!result) - { - return result; - } - - // - result = helper.GetMAFast(barIndex) < helper.GetMASlow(barIndex); - return result; - } - - bool IsMACrossoverSwitchedToBullish(int barIndex = 0) - { - // - bool result = false; - - // - // Normalize ... - barIndex = NormalizeBarIndex(barIndex); - - // - // Validate ... - result = IsValid(); - if (!result) - { - return result; - } - - // - result = IsMACrossoverBullish(barIndex) && - !IsMACrossoverBullish(barIndex + 1); - return result; - } - - bool IsMACrossoverSwitchedToBearish(int barIndex = 0) - { - // - bool result = false; - - // - // Normalize ... - barIndex = NormalizeBarIndex(barIndex); - - // - // Validate ... - result = IsValid(); - if (!result) - { - return result; - } - - // - result = IsMACrossoverBearish(barIndex) && - !IsMACrossoverBearish(barIndex + 1); - return result; - } - // #endregion + // + DECLARE_STATE_FUNCTIONS("KIFast", helper.GetKIFastState, NormalizeBarIndex); + DECLARE_VALUE_COMPARATOR_FUNCTIONS("KIFast", helper.GetKIFast, NormalizeBarIndex, GetPoints); + + // + DECLARE_STATE_FUNCTIONS("KISlow", helper.GetKISlowState, NormalizeBarIndex); + DECLARE_VALUE_COMPARATOR_FUNCTIONS("KISlow", helper.GetKISlow, NormalizeBarIndex, GetPoints); + + // + DECLARE_STATE_FUNCTIONS("KISuperSlow", helper.GetKISlowState, NormalizeBarIndex); + DECLARE_VALUE_COMPARATOR_FUNCTIONS("KISuperSlow", helper.GetKISlow, NormalizeBarIndex, GetPoints); + + // + DECLARE_STATE_FUNCTIONS("KIWave", helper.GetKIWaveState, NormalizeBarIndex); + DECLARE_VALUE_COMPARATOR_FUNCTIONS("KIWave", helper.GetKIWave, NormalizeBarIndex, GetPoints); + + // + DECLARE_PRICE_COMPARATOR_FUNCTIONS("KIUpper", helper.GetKIUpper, NormalizeBarIndex, GetPrice); + DECLARE_PRICE_COMPARATOR_FUNCTIONS("KILower", helper.GetKILower, NormalizeBarIndex, GetPrice); + + // + DECLARE_PRICE_BASED_STATE_FUNCTIONS("MAFast", helper.GetMAFast, NormalizeBarIndex, GetPoints, GetPrice); + DECLARE_PRICE_BASED_STATE_FUNCTIONS("MASlow", helper.GetMASlow, NormalizeBarIndex, GetPoints, GetPrice); + DECLARE_PRICE_BASED_STATE_FUNCTIONS("MASuperSlow", helper.GetMASuperSlow, NormalizeBarIndex, GetPoints, GetPrice); + + // + DECLARE_CROSSING_COMPARATOR_FUNCTIONS("KI", "Fast", "Slow", helper.GetKIFast, helper.GetKISlow, NormalizeBarIndex, GetPoints); + DECLARE_CROSSING_COMPARATOR_FUNCTIONS("MA", "Fast", "Slow", helper.GetMAFast, helper.GetMASlow, NormalizeBarIndex, GetPoints); + DECLARE_CROSSING_COMPARATOR_FUNCTIONS("KI", "Slow", "SuperSlow", helper.GetKISlow, helper.GetKISuperSlow, NormalizeBarIndex, GetPoints); + DECLARE_CROSSING_COMPARATOR_FUNCTIONS("MA", "Slow", "SuperSlow", helper.GetMASlow, helper.GetMASuperSlow, NormalizeBarIndex, GetPoints); // #region PV ... bool IsPeakSameAsLast( @@ -2908,747 +1117,6 @@ class XCX121XKIHelperParser : XCBase } // #endregion - // #region Composite ... - bool IsKIHasTrend( - double &score, - ENUM_X_DIRECTION &dir, - int barIndex = 0, - double requiredScore = 0, - double tolerance = 2 // - ) - { - // - bool result = false; - - // - score = 0; - dir = X_DIRECTION_NONE; - if (requiredScore < 0) - { - requiredScore = 0; - } - barIndex = NormalizeBarIndex(barIndex); - result = IsValid(); - if (!result) - { - return result; - } - - // - bool isBullish = IsKIFastBullish(barIndex) && IsKISlowBullish(barIndex); - bool isBearish = IsKIFastBearish(barIndex) && IsKISlowBearish(barIndex); - - // - // Scoring ... - if (isBullish) - { - // - if (IsKIFastSwitchedToBullish(barIndex)) - { - score += X121_XKI_SCORE_MAX; - } - - // - if (IsKISlowSwitchedToBullish(barIndex)) - { - score += X121_XKI_SCORE_NORMAL; - } - - // - if (IsKIFastSwitchedOverLast(barIndex, tolerance)) - { - score += X121_XKI_SCORE_NORMAL; - } - else if (IsKIFastOverLast(barIndex, tolerance)) - { - score += X121_XKI_SCORE_MIN; - } - - // - if (IsKISlowSwitchedOverLast(barIndex, tolerance)) - { - score += X121_XKI_SCORE_NORMAL; - } - else if (IsKISlowOverLast(barIndex, tolerance)) - { - score += X121_XKI_SCORE_MIN; - } - - // - if (IsKISuperSlowSwitchedToBullish(barIndex)) - { - score += X121_XKI_SCORE_NORMAL; - } - else if (IsKISuperSlowBullish(barIndex)) - { - score += X121_XKI_SCORE_MIN; - } - - // - if (IsKISuperSlowSwitchedOverLast(barIndex, tolerance)) - { - score += X121_XKI_SCORE_NORMAL; - } - else if (IsKISuperSlowOverLast(barIndex, tolerance)) - { - score += X121_XKI_SCORE_MIN; - } - } - else if (isBearish) - { - // - if (IsKIFastSwitchedToBearish(barIndex)) - { - score += X121_XKI_SCORE_MAX; - } - - // - if (IsKISlowSwitchedToBearish(barIndex)) - { - score += X121_XKI_SCORE_NORMAL; - } - - // - if (IsKIFastSwitchedUnderLast(barIndex, tolerance)) - { - score += X121_XKI_SCORE_NORMAL; - } - else if (IsKIFastUnderLast(barIndex, tolerance)) - { - score += X121_XKI_SCORE_MIN; - } - - // - if (IsKISlowSwitchedUnderLast(barIndex, tolerance)) - { - score += X121_XKI_SCORE_NORMAL; - } - else if (IsKISlowUnderLast(barIndex, tolerance)) - { - score += X121_XKI_SCORE_MIN; - } - - // - if (IsKISuperSlowSwitchedToBearish(barIndex)) - { - score += X121_XKI_SCORE_NORMAL; - } - else if (IsKISuperSlowBearish(barIndex)) - { - score += X121_XKI_SCORE_MIN; - } - - // - if (IsKISuperSlowSwitchedUnderLast(barIndex, tolerance)) - { - score += X121_XKI_SCORE_NORMAL; - } - else if (IsKISuperSlowUnderLast(barIndex, tolerance)) - { - score += X121_XKI_SCORE_MIN; - } - } - - // - dir = isBullish - ? X_DIRECTION_BULLISH - : isBearish - ? X_DIRECTION_BEARISH - : X_DIRECTION_NONE; - - // - result = HasDirection(dir) && - score >= requiredScore; - - // - return result; - } - - bool IsMAHasTrend( - double &score, - ENUM_X_DIRECTION &dir, - int barIndex = 0, - double requiredScore = 0, - double tolerance = 2 // - ) - { - // - bool result = false; - - // - score = 0; - dir = X_DIRECTION_NONE; - if (requiredScore < 0) - { - requiredScore = 0; - } - barIndex = NormalizeBarIndex(barIndex); - - // - result = IsValid(); - if (!result) - { - return result; - } - - // - bool isBullish = IsMACrossoverBullish(barIndex); - bool isBearish = IsMACrossoverBearish(barIndex); - - // - if (isBullish) - { - // - if (IsMACrossoverSwitchedToBullish(barIndex)) - { - score += X121_XKI_SCORE_MAX; - } - - // - if (IsMAFastSwitchedToBullish(barIndex)) - { - score += X121_XKI_SCORE_MAX; - } - else if (IsMAFastBullish(barIndex)) - { - score += X121_XKI_SCORE_NORMAL; - } - - // - if (IsMAFastSwitchedOverLast(barIndex, tolerance)) - { - score += X121_XKI_SCORE_NORMAL; - } - else if (IsMAFastOverLast(barIndex, tolerance)) - { - score += X121_XKI_SCORE_MIN; - } - - // - if (IsMASlowSwitchedToBullish(barIndex)) - { - score += X121_XKI_SCORE_NORMAL; - } - else if (IsMASlowBullish(barIndex)) - { - score += X121_XKI_SCORE_MIN; - } - - // - if (IsMASlowSwitchedOverLast(barIndex, tolerance)) - { - score += X121_XKI_SCORE_NORMAL; - } - else if (IsMASlowOverLast(barIndex, tolerance)) - { - score += X121_XKI_SCORE_MIN; - } - - // - if (IsMASuperSlowSwitchedToBullish(barIndex)) - { - score += X121_XKI_SCORE_NORMAL; - } - else if (IsMASuperSlowBullish(barIndex)) - { - score += X121_XKI_SCORE_MIN; - } - - // - if (IsMASuperSlowSwitchedOverLast(barIndex, tolerance)) - { - score += X121_XKI_SCORE_NORMAL; - } - else if (IsMASuperSlowOverLast(barIndex, tolerance)) - { - score += X121_XKI_SCORE_MIN; - } - } - else if (isBearish) - { - // - if (IsMACrossoverSwitchedToBearish(barIndex)) - { - score += X121_XKI_SCORE_MAX; - } - - // - if (IsMAFastSwitchedToBearish(barIndex)) - { - score += X121_XKI_SCORE_MAX; - } - else if (IsMAFastBearish(barIndex)) - { - score += X121_XKI_SCORE_NORMAL; - } - - // - if (IsMAFastSwitchedUnderLast(barIndex, tolerance)) - { - score += X121_XKI_SCORE_NORMAL; - } - else if (IsMAFastUnderLast(barIndex, tolerance)) - { - score += X121_XKI_SCORE_MIN; - } - - // - if (IsMASlowSwitchedToBearish(barIndex)) - { - score += X121_XKI_SCORE_NORMAL; - } - else if (IsMASlowBullish(barIndex)) - { - score += X121_XKI_SCORE_MIN; - } - - // - if (IsMASlowSwitchedUnderLast(barIndex, tolerance)) - { - score += X121_XKI_SCORE_NORMAL; - } - else if (IsMASlowUnderLast(barIndex, tolerance)) - { - score += X121_XKI_SCORE_MIN; - } - - // - if (IsMASuperSlowSwitchedToBearish(barIndex)) - { - score += X121_XKI_SCORE_NORMAL; - } - else if (IsMASuperSlowBearish(barIndex)) - { - score += X121_XKI_SCORE_MIN; - } - - // - if (IsMASuperSlowSwitchedUnderLast(barIndex, tolerance)) - { - score += X121_XKI_SCORE_NORMAL; - } - else if (IsMASuperSlowUnderLast(barIndex, tolerance)) - { - score += X121_XKI_SCORE_MIN; - } - } - - // - dir = isBullish - ? X_DIRECTION_BULLISH - : isBearish - ? X_DIRECTION_BEARISH - : X_DIRECTION_NONE; - - // - result = HasDirection(dir) && - score >= requiredScore; - - // - return result; - } - - bool IsMomentumExists( - double &score, - ENUM_X_DIRECTION &dir, - int barIndex = 0, - double requiredScore = 0, - double tolerance = 2, - double bullishThreshold = 55, - double bearishThreshold = 45, - double overboughtThreshold = 70, - double oversoldThreshold = 30 // - ) - { - // - bool result = false; - - // - score = 0; - dir = X_DIRECTION_NONE; - if (requiredScore < 0) - { - requiredScore = 0; - } - barIndex = NormalizeBarIndex(barIndex); - bullishThreshold = NormalizeXDouble(bullishThreshold, 0, 100); - bearishThreshold = NormalizeXDouble(bearishThreshold, 0, 100); - oversoldThreshold = NormalizeXDouble(oversoldThreshold, 0, 100); - overboughtThreshold = NormalizeXDouble(overboughtThreshold, 0, 100); - - // - result = IsValid(); - if (!result) - { - return result; - } - - // - bool isBullish = IsRSIBullish(barIndex, bullishThreshold, tolerance); - bool isBearish = IsRSIBearish(barIndex, bearishThreshold, tolerance); - - // - if (isBullish) - { - // - if (!IsRSIOverbought(barIndex, overboughtThreshold, tolerance)) - { - score += X121_XKI_SCORE_NORMAL; - } - - // - if (IsRSIOversold(barIndex, oversoldThreshold, tolerance)) - { - score += X121_XKI_SCORE_NORMAL; - } - - // - if (IsRSISwitchedFromOversold(barIndex, oversoldThreshold, tolerance)) - { - score += X121_XKI_SCORE_NORMAL; - } - - // - if (IsRSISwitchedToBullish(barIndex, bullishThreshold, tolerance)) - { - score += X121_XKI_SCORE_NORMAL; - } - - // - if (IsRSISwitchedToRising(barIndex)) - { - score += X121_XKI_SCORE_NORMAL; - } - else if (IsRSIRising(barIndex)) - { - score += X121_XKI_SCORE_MIN; - } - - // - if (IsRSISwitchedOverLast(barIndex, tolerance)) - { - score += X121_XKI_SCORE_NORMAL; - } - else if (IsRSIOverLast(barIndex, tolerance)) - { - score += X121_XKI_SCORE_MIN; - } - } - else if (isBearish) - { - // - if (!IsRSIOversold(barIndex, oversoldThreshold, tolerance)) - { - score += X121_XKI_SCORE_NORMAL; - } - - // - if (IsRSIOverbought(barIndex, overboughtThreshold, tolerance)) - { - score += X121_XKI_SCORE_NORMAL; - } - - // - if (IsRSISwitchedFromOverbought(barIndex, overboughtThreshold, tolerance)) - { - score += X121_XKI_SCORE_NORMAL; - } - - // - if (IsRSISwitchedToBearish(barIndex, bearishThreshold, tolerance)) - { - score += X121_XKI_SCORE_NORMAL; - } - - // - if (IsRSISwitchedToFalling(barIndex)) - { - score += X121_XKI_SCORE_NORMAL; - } - else if (IsRSIFalling(barIndex)) - { - score += X121_XKI_SCORE_MIN; - } - - // - if (IsRSISwitchedUnderLast(barIndex, tolerance)) - { - score += X121_XKI_SCORE_NORMAL; - } - else if (IsRSIUnderLast(barIndex, tolerance)) - { - score += X121_XKI_SCORE_MIN; - } - } - - // - dir = isBullish - ? X_DIRECTION_BULLISH - : isBearish - ? X_DIRECTION_BEARISH - : X_DIRECTION_NONE; - - // - result = HasDirection(dir) && - score >= requiredScore; - - // - return result; - } - - bool IsVolatilityExists( - double &score, - ENUM_X_DIRECTION &dir, - int barIndex = 0, - double requiredScore = 0, - double tolerance = 2, - ENUM_X_PRICE priceType = X_PRICE_CLOSE // - ) - { - // - bool result = false; - - // - score = 0; - dir = X_DIRECTION_NONE; - if (requiredScore < 0) - { - requiredScore = 0; - } - barIndex = NormalizeBarIndex(barIndex); - - // - result = IsValid(); - if (!result) - { - return result; - } - - // - bool isBullish = IsATROverLast(barIndex, tolerance) || IsATRSmoothedOverLast(barIndex, tolerance); - bool isBearish = IsATRUnderLast(barIndex, tolerance) || IsATRSmoothedUnderLast(barIndex, tolerance); - - // - if (isBullish) - { - // - if (IsATRBreakoutDown(barIndex, priceType)) - { - score += X121_XKI_SCORE_NORMAL; - } - - // - if (!IsATRBreakoutUp(barIndex, priceType)) - { - score += X121_XKI_SCORE_MIN; - } - - // - if (IsATRSwitchedOverLast(barIndex, tolerance)) - { - score += X121_XKI_SCORE_NORMAL; - } - else if (IsATROverLast(barIndex, tolerance)) - { - score += X121_XKI_SCORE_MIN; - } - - // - if (IsATRSmoothedSwitchedOverLast(barIndex, tolerance)) - { - score += X121_XKI_SCORE_NORMAL; - } - else if (IsATRSmoothedOverLast(barIndex, tolerance)) - { - score += X121_XKI_SCORE_MIN; - } - - // - if (IsVolatilitySwitchdToHigh(barIndex)) - { - score += X121_XKI_SCORE_NORMAL; - } - else if (IsVolatilityHigh(barIndex)) - { - score += X121_XKI_SCORE_MIN; - } - } - else if (isBearish) - { - // - if (!IsATRBreakoutDown(barIndex, priceType)) - { - score += X121_XKI_SCORE_NORMAL; - } - - // - if (IsATRBreakoutUp(barIndex, priceType)) - { - score += X121_XKI_SCORE_MIN; - } - - // - if (IsATRSwitchedUnderLast(barIndex, tolerance)) - { - score += X121_XKI_SCORE_NORMAL; - } - else if (IsATRUnderLast(barIndex, tolerance)) - { - score += X121_XKI_SCORE_MIN; - } - - // - if (IsATRSmoothedSwitchedUnderLast(barIndex, tolerance)) - { - score += X121_XKI_SCORE_NORMAL; - } - else if (IsATRSmoothedUnderLast(barIndex, tolerance)) - { - score += X121_XKI_SCORE_MIN; - } - - // - if (IsVolatilitySwitchdToLow(barIndex)) - { - score += X121_XKI_SCORE_NORMAL; - } - else if (IsVolatilityLow(barIndex)) - { - score += X121_XKI_SCORE_MIN; - } - } - - // - dir = isBullish - ? X_DIRECTION_BULLISH - : isBearish - ? X_DIRECTION_BEARISH - : X_DIRECTION_NONE; - - // - result = HasDirection(dir) && - score >= requiredScore; - - // - return result; - } - // #endregion - - // #region Signalling Conditions ... - bool HasCompositeTrend( - double &score, - ENUM_X_DIRECTION &dir, - int barIndex = 0, - double requiredScore = 0, - double tolerance = 2, - ENUM_X_PRICE priceType = X_PRICE_CLOSE, - double bullishThreshold = 55, - double bearishThreshold = 45, - double overboughtThreshold = 70, - double oversoldThreshold = 30 // - ) - { - // - bool result = false; - - // - score = 0; - dir = X_DIRECTION_NONE; - barIndex = NormalizeBarIndex(barIndex); - - // - result = IsValid(); - if (!result) - { - return result; - } - - // - bool hasKI, hasMa, hasMomentum, hasVolatility; - double kiScore, maScore, momentumScore, volatilityScore; - ENUM_X_DIRECTION kiDir, maDir, momentumDir, volatilityDdir; - - // - hasKI = IsKIHasTrend( - kiScore, - kiDir, - barIndex, - 1, - tolerance // - ); - hasMa = IsMAHasTrend( - maScore, - maDir, - barIndex, - 1, - tolerance // - ); - hasVolatility = IsVolatilityExists( - volatilityScore, - volatilityDdir, - barIndex, - 1, - tolerance, - priceType // - ); - hasMomentum = IsMomentumExists( - momentumScore, - momentumDir, - barIndex, - 1, - tolerance, - bullishThreshold, - bearishThreshold, - overboughtThreshold, - oversoldThreshold // - ); - - // - bool isBullish = - hasKI && IsXBullish(kiDir) && - hasMa && IsXBullish(maDir) && - hasMomentum && IsXBullish(momentumDir) && - hasVolatility && IsXBullish(volatilityDdir); - - // - bool isBearish = - hasKI && IsXBearish(kiDir) && - hasMa && IsXBearish(maDir) && - hasMomentum && IsXBullish(momentumDir) && - hasVolatility && IsXBullish(volatilityDdir); - - // - result = isBullish || isBearish; - if (!result) - { - return result; - } - - // - // Summarizing Scores ... - score = (kiScore + maScore + momentumScore + volatilityScore); - result = - result && - score >= requiredScore; - if (result) - { - // - dir = isBullish - ? X_DIRECTION_BULLISH - : isBearish - ? X_DIRECTION_BEARISH - : X_DIRECTION_NONE; - } - - // - result = result && - HasDirection(dir); - - // - return result; - } - // #endregion - // // Protected ... protected: diff --git a/X121XKIEA/Classes/x-saherelm.x121.xki.signaller.class.mq5 b/X121XKIEA/Classes/x-saherelm.x121.xki.signaller.class.mq5 index c182b54f..06f71b88 100644 --- a/X121XKIEA/Classes/x-saherelm.x121.xki.signaller.class.mq5 +++ b/X121XKIEA/Classes/x-saherelm.x121.xki.signaller.class.mq5 @@ -973,8 +973,7 @@ class XCX121XKIStrategy1Signaller : public XCX121XKIBaseSignaller } // - int scoreBullish = 0; - int scoreBearish = 0; + double score = 0; bool isBullish = false; bool isBearish = false; int barIndex = bar.Index() + 1; @@ -982,6 +981,31 @@ class XCX121XKIStrategy1Signaller : public XCX121XKIBaseSignaller // // TEST ... + // + if (kiParser.IsKIFastBullish(barIndex)) + { + DebugBreak(); + } + + // // + // bool hasTrend = + // kiParser.HasCompositeTrend( + // score, + // dir, + // barIndex, + // 20, // Required Score ... + // 2, // Tolerance ... + // X_PRICE_CLOSE, + // 55, + // 45, + // 70, + // 30 // + // ); + // if (hasTrend && IsXBearish(dir)) + // { + // DebugBreak(); + // } + // return false;