From 5c7c5f288dad441f64e0d889cc1d081b74995d5b Mon Sep 17 00:00:00 2001 From: Hadi Khazaee Asl Date: Thu, 8 Jan 2026 18:44:19 +0330 Subject: [PATCH] last ... --- Documents/BKP/X121XKI/tmps.bkp.mq5 | 66 +- Documents/Diagrams/MQL5.X121XKI.Board.kanban | 224 +- Helpers/x-saherelm.x121.xki.helper.mq5 | 47 + Indicators/x-saherelm.x121.xki.mq5 | 41 +- .../x-saherelm.common.extensions.lib.mq5 | 55 + .../x-ki.parser.conditions.tester.bkp.mq5 | 184 ++ .../x-saherelm.x121.xki.parser.class.mq5 | 1982 +++++++++++++---- .../x-saherelm.x121.xki.signaller.class.mq5 | 1 - 8 files changed, 2073 insertions(+), 527 deletions(-) diff --git a/Documents/BKP/X121XKI/tmps.bkp.mq5 b/Documents/BKP/X121XKI/tmps.bkp.mq5 index 6a733b99..4dcfbbcf 100644 --- a/Documents/BKP/X121XKI/tmps.bkp.mq5 +++ b/Documents/BKP/X121XKI/tmps.bkp.mq5 @@ -2124,4 +2124,68 @@ bool Strategy1HasSignal( { DebugBreak(); } - } \ No newline at end of file + } + + int CountSameVales( + int barIndex = 0, + int loopback = 10 // + ) + { + // + int result = 0; + + // + if (!IsValid()) + { + return result; + } + + // + loopback = NormalizeInt(loopback, 2); + barIndex = NormalizeBarIndex(barIndex); + + // + for (int i = barIndex; i < barIndex + loopback; i++) + { + // + if (IsValeSameAsLast(i)) + { + result++; + } + } + + // + return result; + } + + int CountSamePeaks( + int barIndex = 0, + int loopback = 10 // + ) + { + // + int result = 0; + + // + if (!IsValid()) + { + return result; + } + + // + loopback = NormalizeInt(loopback, 2); + barIndex = NormalizeBarIndex(barIndex); + + // + for (int i = barIndex; i < barIndex + loopback; i++) + { + // + if (IsPeakSameAsLast(i)) + { + result++; + } + } + + // + return result; + } diff --git a/Documents/Diagrams/MQL5.X121XKI.Board.kanban b/Documents/Diagrams/MQL5.X121XKI.Board.kanban index ad0a2bbc..a4669fe7 100644 --- a/Documents/Diagrams/MQL5.X121XKI.Board.kanban +++ b/Documents/Diagrams/MQL5.X121XKI.Board.kanban @@ -14,15 +14,6 @@ "id": "6f8db3d6-fcaa-4522-bee5-0e3e38c96e73", "title": "Doing", "cards": [ - { - "id": "a59a73f4-1ab4-477b-893e-b2dfb71fe6ea", - "listId": "6f8db3d6-fcaa-4522-bee5-0e3e38c96e73", - "title": "Add Support for PV in XKI Indicator.", - "description": "", - "labels": [], - "checkboxes": [], - "comments": [] - }, { "id": "f8eb6951-f337-40da-9b98-e468f77709fd", "listId": "6f8db3d6-fcaa-4522-bee5-0e3e38c96e73", @@ -58,8 +49,23 @@ "comments": [] }, { - "id": "bcb422f9-89db-4816-ba3a-bae95c9c8da4", + "id": "ab436301-ddac-4e19-97e6-935986e0316b", "listId": "6f8db3d6-fcaa-4522-bee5-0e3e38c96e73", + "title": "Add Composite Semantic Conditions ...", + "description": "here we complete all stand alone semantic conditions ...\nbut for now we have to add some Composite Conditions ...", + "labels": [], + "checkboxes": [], + "comments": [] + } + ] + }, + { + "id": "c6b07a7f-d2e7-4f67-a5a9-0d93cd8bf981", + "title": "Test", + "cards": [ + { + "id": "bcb422f9-89db-4816-ba3a-bae95c9c8da4", + "listId": "c6b07a7f-d2e7-4f67-a5a9-0d93cd8bf981", "title": "Test all XKI Helper Functions", "description": "Test all KI Parser Conditional Tools ...\n ", "labels": [], @@ -457,112 +463,184 @@ { "id": "dd69c2c0-c999-4235-8cb5-74607b27c7ec", "title": "IsATRBreakoutUp", - "checked": false + "checked": true }, { "id": "1a77e8e1-b3e8-48b4-b072-1cda3a69c6f9", "title": "IsATRBreakoutDown", - "checked": false + "checked": true }, { "id": "bfeb3c24-f0ed-4aed-99af-bec8db026a62", "title": "IsATROverLast", - "checked": false - }, - { - "id": "62881e04-9b38-49e4-ae9d-e5161c1b0b5c", - "title": "IsATRUnderLast", - "checked": false + "checked": true }, { "id": "33ec5ba0-d31a-4602-ba79-7d3b4d9d7986", "title": "IsATRSwitchedOverLast", - "checked": false + "checked": true + }, + { + "id": "62881e04-9b38-49e4-ae9d-e5161c1b0b5c", + "title": "IsATRUnderLast", + "checked": true }, { "id": "cf0fb674-8dfc-4ed1-b1dd-5a8447d818a4", "title": "IsATRSwitchedUnderLast", - "checked": false + "checked": true + }, + { + "id": "efaca1b4-aa77-4809-b3ad-6a3962da8c40", + "title": "IsATRSmoothedOverLast", + "checked": true + }, + { + "id": "5778c239-bf3a-40f1-88f5-9073c77d5b33", + "title": "IsATRSmoothedSwitchedOverLast", + "checked": true + }, + { + "id": "d9f2be28-df91-4317-b5bb-227edcd0be7d", + "title": "IsATRSmoothedUnderLast", + "checked": true + }, + { + "id": "d26df086-8d93-4d3a-abbc-64c59efd564c", + "title": "IsATRSmoothedSwitchedUnderLast", + "checked": true }, { "id": "ab07c8e5-454c-4c9b-a69d-fa2e8330a2e0", "title": "IsVolatilityHigh", - "checked": false - }, - { - "id": "031521be-0062-4d07-ade4-ff17782888c7", - "title": "IsVolatilityLow", - "checked": false + "checked": true }, { "id": "49376783-45aa-4a57-a304-3547babf0ccd", "title": "IsVolatilitySwitchdToHigh", - "checked": false + "checked": true + }, + { + "id": "031521be-0062-4d07-ade4-ff17782888c7", + "title": "IsVolatilityLow", + "checked": true }, { "id": "5803601b-9143-471d-968f-59622d37b70a", "title": "IsVolatilitySwitchdToLow", - "checked": false + "checked": true }, { "id": "0ab99ddc-75b8-45c7-9140-8cd3dc6921c6", "title": "IsRSIBullish", - "checked": false - }, - { - "id": "ba39f76c-2257-48fe-94ca-addf2148ee23", - "title": "IsRSIBearish", - "checked": false - }, - { - "id": "91c098b3-56d8-4728-b411-edf7e42d60b0", - "title": "IsRSIOverbought", - "checked": false - }, - { - "id": "7917431d-9bc9-4514-8aea-7fae7c11b0de", - "title": "IsRSIOversold", - "checked": false - }, - { - "id": "83d4b28b-fe6c-411c-a209-c57e3c8251d0", - "title": "IsRSISwitchedToOverSold", - "checked": false - }, - { - "id": "96493d94-9db6-49de-a7f1-e3990b9469b8", - "title": "IsRSISwitchedFromOverSold", - "checked": false - }, - { - "id": "02579268-284f-40f3-93c9-0cb3f70d103a", - "title": "IsRSISwitchedToOverbought", - "checked": false - }, - { - "id": "6c473b2e-1b37-44b2-a08c-ce6217d0c00e", - "title": "IsRSISwitchedFromOverbought", - "checked": false + "checked": true }, { "id": "30177c7a-47df-4d90-8132-0f467ebc071c", "title": "IsRSISwitchedToBullish", - "checked": false + "checked": true + }, + { + "id": "ba39f76c-2257-48fe-94ca-addf2148ee23", + "title": "IsRSIBearish", + "checked": true }, { "id": "a3e07f9c-72da-49b4-8101-f742644a2b81", "title": "IsRSISwitchedToBearish", - "checked": false + "checked": true + }, + { + "id": "8b8675aa-a27d-4640-9a72-75d79ba3be31", + "title": "IsRSIRising", + "checked": true + }, + { + "id": "83b917ce-6296-4fac-80e9-4bb60d5e7b0c", + "title": "IsRSISwitchedToRising", + "checked": true + }, + { + "id": "d6321889-78ef-46b3-a68e-6fb3dc1bbb2b", + "title": "IsRSIFalling", + "checked": true + }, + { + "id": "84ea179e-0d13-4481-8ffd-03400f89cacf", + "title": "IsRSISwitchedToFalling", + "checked": true + }, + { + "id": "a2765ea8-3383-4c54-8d3a-2ede0c5dd204", + "title": "IsRSIOverLast", + "checked": true + }, + { + "id": "87ffaa2a-9dd8-41b3-9f98-7d9cbc30c64d", + "title": "IsRSISwitchedOverLast", + "checked": true + }, + { + "id": "b5f59e63-2841-413c-a2f9-1940db5fa3c1", + "title": "IsRSIUnderLast", + "checked": true + }, + { + "id": "feedbb53-61ad-4717-bf2d-07daf9d51ec4", + "title": "IsRSISwitchedUnderLast", + "checked": true + }, + { + "id": "91c098b3-56d8-4728-b411-edf7e42d60b0", + "title": "IsRSIOverbought", + "checked": true + }, + { + "id": "02579268-284f-40f3-93c9-0cb3f70d103a", + "title": "IsRSISwitchedToOverbought", + "checked": true + }, + { + "id": "6c473b2e-1b37-44b2-a08c-ce6217d0c00e", + "title": "IsRSISwitchedFromOverbought", + "checked": true + }, + { + "id": "7917431d-9bc9-4514-8aea-7fae7c11b0de", + "title": "IsRSIOversold", + "checked": true + }, + { + "id": "83d4b28b-fe6c-411c-a209-c57e3c8251d0", + "title": "IsRSISwitchedToOversold", + "checked": true + }, + { + "id": "96493d94-9db6-49de-a7f1-e3990b9469b8", + "title": "IsRSISwitchedFromOversold", + "checked": true } ], "comments": [] - } - ] - }, - { - "id": "c6b07a7f-d2e7-4f67-a5a9-0d93cd8bf981", - "title": "Test", - "cards": [ + }, + { + "id": "a59a73f4-1ab4-477b-893e-b2dfb71fe6ea", + "listId": "c6b07a7f-d2e7-4f67-a5a9-0d93cd8bf981", + "title": "Add Support for PV in XKI Indicator.", + "description": "", + "labels": [], + "checkboxes": [], + "comments": [] + }, + { + "id": "73b1de13-b615-4747-bd28-4f826a6a9239", + "listId": "c6b07a7f-d2e7-4f67-a5a9-0d93cd8bf981", + "title": "Adding Support for RSI Smoothing ...", + "description": "", + "labels": [], + "checkboxes": [], + "comments": [] + }, { "id": "128af636-5cd8-4311-a565-e822ba380d59", "listId": "c6b07a7f-d2e7-4f67-a5a9-0d93cd8bf981", diff --git a/Helpers/x-saherelm.x121.xki.helper.mq5 b/Helpers/x-saherelm.x121.xki.helper.mq5 index 7f2b11d2..b40b627b 100644 --- a/Helpers/x-saherelm.x121.xki.helper.mq5 +++ b/Helpers/x-saherelm.x121.xki.helper.mq5 @@ -204,6 +204,7 @@ enum ENUM_X121_XKI_BUFFERS // // RSI ... X121_XKI_RSI_LINE = 19, + X121_XKI_RSI_SMOOTHED_LINE = 25, }; // #endregion @@ -224,6 +225,8 @@ struct X121XKIInputs ENUM_APPLIED_PRICE rsiAppliedTo; // RSI Applied To double rsiBullishConfirmation; // RSI Bullish Confirmation Level double rsiBearishConfirmation; // RSI Bearish Confirmation Level + int rsiSmoothingLength; // RSI Smoothing Length + ENUM_X_MA_METHOD rsiSmoothingMode; // RSI Smoothing Method int kiWaveSmoothingLength; // RSI KI Wave Smoothing Length ENUM_X_MA_METHOD kiWaveSmoothingMode; // RSI KI Wave Smoothing Method double rsiMultiplier; // RSI Multiplier @@ -289,6 +292,8 @@ struct X121XKIInputs rsiAppliedTo = PRICE_CLOSE; rsiBullishConfirmation = 55; rsiBearishConfirmation = 45; + rsiSmoothingLength = 14; + rsiSmoothingMode = X_MA_MODE_EMA; kiWaveSmoothingLength = 14; kiWaveSmoothingMode = X_MA_MODE_EMA; rsiMultiplier = 0.5; @@ -415,6 +420,7 @@ struct X121XKIConditions double atrRawUpperBuffer[]; double atrRawLowerBuffer[]; double rsiBuffer[]; + double rsiSmoothedBuffer[]; double kiWaveRawBuffer[]; double kiWaveStateBuffer[]; // #endregion @@ -467,6 +473,7 @@ struct X121XKIConditions XClean(atrRawUpperBuffer); XClean(atrRawLowerBuffer); XClean(rsiBuffer); + XClean(rsiSmoothedBuffer); XClean(kiWaveRawBuffer); XClean(kiWaveStateBuffer); @@ -494,6 +501,7 @@ struct X121XKIConditions ArraySetAsSeries(atrRawUpperBuffer, true); ArraySetAsSeries(atrRawLowerBuffer, true); ArraySetAsSeries(rsiBuffer, true); + ArraySetAsSeries(rsiSmoothedBuffer, true); ArraySetAsSeries(kiWaveRawBuffer, true); ArraySetAsSeries(kiWaveStateBuffer, true); @@ -575,6 +583,8 @@ class XCX121XKIHelper : public XCBaseHelper mInputs.rsiAppliedTo, mInputs.rsiBullishConfirmation, mInputs.rsiBearishConfirmation, + mInputs.rsiSmoothingLength, + mInputs.rsiSmoothingMode, mInputs.kiWaveSmoothingLength, mInputs.kiWaveSmoothingMode, mInputs.rsiMultiplier, @@ -787,6 +797,11 @@ class XCX121XKIHelper : public XCBaseHelper loopback, conditions.rsiBuffer // ); + CopyRSISmoothed( + zIndex, + loopback, + conditions.rsiSmoothedBuffer // + ); CopyATR( zIndex, loopback, @@ -1487,6 +1502,38 @@ class XCX121XKIHelper : public XCBaseHelper } // #endregion + // #region RSI Smoothed ... + // + double GetRSISmoothed( + int barIndex // Bar Index + ) + { + // + return ReadValue( + (int)X121_XKI_RSI_SMOOTHED_LINE, + barIndex // + ); + } + + // + int CopyRSISmoothed( + int start, // Start + int count, // Number of Items for read + double &buffer[], // Dest Buffer + bool asSeries = true // As Series Flag + ) + { + // + return ReadValues( + buffer, + (int)X121_XKI_RSI_SMOOTHED_LINE, + start, + count, + asSeries // + ); + } + // #endregion + // #region ATR ... // double GetATR( diff --git a/Indicators/x-saherelm.x121.xki.mq5 b/Indicators/x-saherelm.x121.xki.mq5 index 91fd20d6..7011b98c 100644 --- a/Indicators/x-saherelm.x121.xki.mq5 +++ b/Indicators/x-saherelm.x121.xki.mq5 @@ -45,6 +45,8 @@ input int rsiLength = 14; // RSI Length input ENUM_APPLIED_PRICE rsiAppliedTo = PRICE_CLOSE; // RSI Applied To input double rsiBullishConfirmation = 55; // RSI Bullish Confirmation Level input double rsiBearishConfirmation = 45; // RSI Bearish Confirmation Level +input int rsiSmoothingLength = 14; // RSI Smoothing Length +input ENUM_X_MA_METHOD rsiSmoothingMode = X_MA_MODE_EMA; // RSI Smoothing Method input int kiWaveSmoothingLength = 14; // RSI KI Wave Smoothing Length input ENUM_X_MA_METHOD kiWaveSmoothingMode = X_MA_MODE_EMA; // RSI KI Wave Smoothing Method input double rsiMultiplier = 0.5; // RSI Multiplier @@ -98,7 +100,7 @@ input int valeArrowCode = 159; // Vales Arrow Code #property indicator_chart_window // -#property indicator_buffers 25 +#property indicator_buffers 26 #property indicator_plots 11 // #region Plot Buffers ... @@ -318,6 +320,10 @@ double atrSmoothedBuffer[]; // #define kiSuperSlowStateBufferIndex mLastBufferIndex + 10 double kiSuperSlowStateBuffer[]; + +// +#define rsiSmoothedBufferIndex mLastBufferIndex + 11 +double rsiSmoothedBuffer[]; // #endregion // #endregion @@ -660,6 +666,10 @@ int ExtractMaxLengthOfInputs() result = MathMax(result, kiSuperSlowLength); // + if (rsiSmoothingLength > 0) + { + result = MathMax(result, rsiSmoothingLength); + } if (atrSmoothingLength > 0) { result = MathMax(result, atrSmoothingLength); @@ -779,6 +789,10 @@ void DefineBuffers() ArraySetAsSeries(rsiBuffer, true); SetIndexBuffer(rsiBufferIndex, rsiBuffer, INDICATOR_CALCULATIONS); + // + ArraySetAsSeries(rsiSmoothedBuffer, true); + SetIndexBuffer(rsiSmoothedBufferIndex, rsiSmoothedBuffer, INDICATOR_CALCULATIONS); + // ArraySetAsSeries(kiWaveRawBuffer, true); SetIndexBuffer(kiWaveRawBufferIndex, kiWaveRawBuffer, INDICATOR_CALCULATIONS); @@ -1728,7 +1742,7 @@ void CalculateRSI( kiWaveStateBuffer[barIndex] = iState; // - // Check Can Smooth Atr ... + // Check Can Smooth KI Wave ... if (IsXValid(kiWaveSmoothingMode) && kiWaveSmoothingLength > 0) { @@ -1749,5 +1763,28 @@ void CalculateRSI( // kiWaveBuffer[barIndex] = iValue; } + + // + // Check Can Smooth RSI ... + if (IsXValid(rsiSmoothingMode) && + rsiSmoothingLength > 0) + { + // + // Ki Wave ... + iMAOnBuffer( + ratesTotal, + prevCalculated, + barIndex, + rsiSmoothingLength, + rsiBuffer, + rsiSmoothedBuffer, + rsiSmoothingMode // + ); + } + else + { + // + rsiSmoothedBuffer[barIndex] = iRsi; + } } // #endregion \ No newline at end of file diff --git a/Libraries/x-saherelm.common.extensions.lib.mq5 b/Libraries/x-saherelm.common.extensions.lib.mq5 index cc2fcf48..a79f4d22 100644 --- a/Libraries/x-saherelm.common.extensions.lib.mq5 +++ b/Libraries/x-saherelm.common.extensions.lib.mq5 @@ -412,6 +412,14 @@ double NormalizeDouble( // return value; } +double NormalizeXDouble( + double value, + double min = 0, + double max = DBL_MAX // +) +{ + return NormalizeDouble(value, min, max); +} /** * Normalize Index based on Collection ... @@ -5287,6 +5295,53 @@ void AddsIfNotExists( // START Buffers ... // +bool IsSame( + double current, + double previous, + double tolerance = 2 // +) +{ + // + bool result = + NotEmptyZero(current) && + NotEmptyZero(previous) && + current <= previous + tolerance && + current >= previous + tolerance; + + // + return result; +} + +bool IsOver( + double current, + double previous, + double tolerance = 2 // +) { + // + bool result = + NotEmptyZero(current) && + NotEmptyZero(previous) && + current >= previous + tolerance; + + // + return result; +} + +bool IsUnder( + double current, + double previous, + double tolerance = 2 // +) { + // + bool result = + NotEmptyZero(current) && + NotEmptyZero(previous) && + current <= previous - tolerance; + + // + return result; +} + // template bool IsSame( diff --git a/X121XKIEA/Backup/x-ki.parser.conditions.tester.bkp.mq5 b/X121XKIEA/Backup/x-ki.parser.conditions.tester.bkp.mq5 index ddda3efc..ae2971b1 100644 --- a/X121XKIEA/Backup/x-ki.parser.conditions.tester.bkp.mq5 +++ b/X121XKIEA/Backup/x-ki.parser.conditions.tester.bkp.mq5 @@ -486,4 +486,188 @@ // } // #endregion +// #region ATR ... +// +// if (kiParser.IsATRBreakoutUp(barIndex, X_PRICE_CLOSE)) { +// DebugBreak(); +// } + +// +// if (kiParser.IsATRBreakoutDown(barIndex, X_PRICE_CLOSE)) { +// DebugBreak(); +// } + +// +// if (kiParser.IsATROverLast(barIndex)) { +// DebugBreak(); +// } + +// +// if (kiParser.IsATRSwitchedOverLast(barIndex)) { +// DebugBreak(); +// } + +// +// if (kiParser.IsATRUnderLast(barIndex)) { +// DebugBreak(); +// } + +// +// if (kiParser.IsATRSwitchedUnderLast(barIndex)) { +// DebugBreak(); +// } + +// +// if (kiParser.IsATRSmoothedOverLast(barIndex)) { +// DebugBreak(); +// } + +// +// if (kiParser.IsATRSmoothedSwitchedOverLast(barIndex)) { +// DebugBreak(); +// } + +// +// if (kiParser.IsATRSmoothedUnderLast(barIndex)) { +// DebugBreak(); +// } + +// +// if (kiParser.IsATRSmoothedSwitchedUnderLast(barIndex)) { +// DebugBreak(); +// } + +// +// if (kiParser.IsVolatilityHigh(barIndex)) { +// DebugBreak(); +// } + +// +// if (kiParser.IsVolatilitySwitchdToHigh(barIndex)) { +// DebugBreak(); +// } + +// +// if (kiParser.IsVolatilityLow(barIndex)) { +// DebugBreak(); +// } + +// +// if (kiParser.IsVolatilitySwitchdToLow(barIndex)) { +// DebugBreak(); +// } +// #endregion + +// #region RSI ... + +// +// if (kiParser.IsRSIBullish(barIndex, 55)) +// { +// DebugBreak(); +// } + +// +// if (kiParser.IsRSISwitchedToBullish(barIndex, 55)) +// { +// DebugBreak(); +// } + +// +// if (kiParser.IsRSIBearish(barIndex, 45)) +// { +// DebugBreak(); +// } + +// +// if (kiParser.IsRSISwitchedToBearish(barIndex, 45)) +// { +// DebugBreak(); +// } + +// +// if (kiParser.IsRSIRising(barIndex)) +// { +// DebugBreak(); +// } + +// +// if (kiParser.IsRSISwitchedToRising(barIndex)) +// { +// DebugBreak(); +// } + +// +// if (kiParser.IsRSIFalling(barIndex)) +// { +// DebugBreak(); +// } + +// +// if (kiParser.IsRSISwitchedToFalling(barIndex)) +// { +// DebugBreak(); +// } + +// +// if (kiParser.IsRSIOverLast(barIndex)) +// { +// DebugBreak(); +// } + +// +// if (kiParser.IsRSISwitchedOverLast(barIndex)) +// { +// DebugBreak(); +// } + +// +// if (kiParser.IsRSIUnderLast(barIndex)) +// { +// DebugBreak(); +// } + +// +// if (kiParser.IsRSISwitchedUnderLast(barIndex)) +// { +// DebugBreak(); +// } + +// +// if (kiParser.IsRSIOverbought(barIndex, 70)) +// { +// DebugBreak(); +// } + +// +// if (kiParser.IsRSISwitchedToOverbought(barIndex, 70)) +// { +// DebugBreak(); +// } + +// +// if (kiParser.IsRSISwitchedFromOverbought(barIndex, 70)) +// { +// DebugBreak(); +// } + +// +// if (kiParser.IsRSIOversold(barIndex, 30)) +// { +// DebugBreak(); +// } + +// +// if (kiParser.IsRSISwitchedToOversold(barIndex, 30)) +// { +// DebugBreak(); +// } + +// +// if (kiParser.IsRSISwitchedFromOversold(barIndex, 30)) +// { +// DebugBreak(); +// } +// #endregion + + diff --git a/X121XKIEA/Classes/x-saherelm.x121.xki.parser.class.mq5 b/X121XKIEA/Classes/x-saherelm.x121.xki.parser.class.mq5 index a080e84f..8b5610c9 100644 --- a/X121XKIEA/Classes/x-saherelm.x121.xki.parser.class.mq5 +++ b/X121XKIEA/Classes/x-saherelm.x121.xki.parser.class.mq5 @@ -26,6 +26,13 @@ // // 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 ... @@ -211,7 +218,7 @@ class XCX121XKIHelperParser : XCBase bool IsKIFastOverLast( int barIndex = 0, - double distancePoint = 5 // + double tolerance = 2 // ) { // @@ -230,13 +237,11 @@ class XCX121XKIHelperParser : XCBase } // - double value = helper.GetKIFast(barIndex); - double pValue = helper.GetKIFast(barIndex + 1); - double point = GetPoints(symbol); - double distance = point * distancePoint; - - // - result = value >= pValue + distance; + result = IsOver( + helper.GetKIFast(barIndex), + helper.GetKIFast(barIndex + 1), + GetPoints(symbol) * tolerance // + ); // return result; @@ -244,7 +249,7 @@ class XCX121XKIHelperParser : XCBase bool IsKIFastUnderLast( int barIndex = 0, - double distancePoint = 5 // + double tolerance = 2 // ) { // @@ -263,19 +268,20 @@ class XCX121XKIHelperParser : XCBase } // - double value = helper.GetKIFast(barIndex); - double pValue = helper.GetKIFast(barIndex + 1); - double point = GetPoints(symbol); - double distance = point * distancePoint; - - // - result = value <= pValue - distance; + result = IsUnder( + helper.GetKIFast(barIndex), + helper.GetKIFast(barIndex + 1), + GetPoints(symbol) * tolerance // + ); // return result; } - bool IsKIFastSameAsLast(int barIndex = 0) + bool IsKIFastSameAsLast( + int barIndex = 0, + double tolerance = 2 // + ) { // bool result = false; @@ -285,13 +291,20 @@ class XCX121XKIHelperParser : XCBase // result = IsValid() && - helper.GetKIFast(barIndex) == helper.GetKIFast(barIndex + 1); + IsSame( + helper.GetKIFast(barIndex), + helper.GetKIFast(barIndex + 1), + GetPoints(symbol) * tolerance // + ); // return result; } - bool IsKIFastSwitchedOverLast(int barIndex = 0) + bool IsKIFastSwitchedOverLast( + int barIndex = 0, + double tolerance = 2 // + ) { // bool result = false; @@ -302,8 +315,8 @@ class XCX121XKIHelperParser : XCBase // result = IsValid() && - IsKIFastOverLast(barIndex) && - !IsKIFastOverLast(barIndex + 1); + IsKIFastOverLast(barIndex, tolerance) && + !IsKIFastOverLast(barIndex + 1, tolerance); if (!result) { return result; @@ -313,7 +326,10 @@ class XCX121XKIHelperParser : XCBase return result; } - bool IsKIFastSwitchedUnderLast(int barIndex = 0) + bool IsKIFastSwitchedUnderLast( + int barIndex = 0, + double tolerance = 2 // + ) { // bool result = false; @@ -324,8 +340,8 @@ class XCX121XKIHelperParser : XCBase // result = IsValid() && - IsKIFastUnderLast(barIndex) && - !IsKIFastUnderLast(barIndex + 1); + IsKIFastUnderLast(barIndex, tolerance) && + !IsKIFastUnderLast(barIndex + 1, tolerance); if (!result) { return result; @@ -439,7 +455,7 @@ class XCX121XKIHelperParser : XCBase bool IsKISlowOverLast( int barIndex = 0, - double distancePoint = 5 // + double tolerance = 2 // ) { // @@ -458,13 +474,11 @@ class XCX121XKIHelperParser : XCBase } // - double value = helper.GetKISlow(barIndex); - double pValue = helper.GetKISlow(barIndex + 1); - double point = GetPoints(symbol); - double distance = point * distancePoint; - - // - result = value >= pValue + distance; + result = IsOver( + helper.GetKISlow(barIndex), + helper.GetKISlow(barIndex + 1), + GetPoints(symbol) * tolerance // + ); // return result; @@ -472,7 +486,7 @@ class XCX121XKIHelperParser : XCBase bool IsKISlowUnderLast( int barIndex = 0, - double distancePoint = 5 // + double tolerance = 2 // ) { // @@ -491,19 +505,20 @@ class XCX121XKIHelperParser : XCBase } // - double value = helper.GetKISlow(barIndex); - double pValue = helper.GetKISlow(barIndex + 1); - double point = GetPoints(symbol); - double distance = point * distancePoint; - - // - result = value <= pValue - distance; + result = IsUnder( + helper.GetKISlow(barIndex), + helper.GetKISlow(barIndex + 1), + GetPoints(symbol) * tolerance // + ); // return result; } - bool IsKISlowSameAsLast(int barIndex = 0) + bool IsKISlowSameAsLast( + int barIndex = 0, + double tolerance = 2 // + ) { // bool result = false; @@ -512,14 +527,20 @@ class XCX121XKIHelperParser : XCBase barIndex = NormalizeBarIndex(barIndex); // - result = IsValid() && - helper.GetKISlow(barIndex) == helper.GetKISlow(barIndex + 1); + result = IsSame( + helper.GetKISlow(barIndex), + helper.GetKISlow(barIndex + 1), + GetPoints(symbol) * tolerance // + ); // return result; } - bool IsKISlowSwitchedOverLast(int barIndex = 0) + bool IsKISlowSwitchedOverLast( + int barIndex = 0, + double tolerance = 2 // + ) { // bool result = false; @@ -530,8 +551,8 @@ class XCX121XKIHelperParser : XCBase // result = IsValid() && - IsKISlowOverLast(barIndex) && - !IsKISlowOverLast(barIndex + 1); + IsKISlowOverLast(barIndex, tolerance) && + !IsKISlowOverLast(barIndex + 1, tolerance); if (!result) { return result; @@ -541,7 +562,10 @@ class XCX121XKIHelperParser : XCBase return result; } - bool IsKISlowSwitchedUnderLast(int barIndex = 0) + bool IsKISlowSwitchedUnderLast( + int barIndex = 0, + double tolerance = 2 // + ) { // bool result = false; @@ -552,8 +576,8 @@ class XCX121XKIHelperParser : XCBase // result = IsValid() && - IsKISlowUnderLast(barIndex) && - !IsKISlowUnderLast(barIndex + 1); + IsKISlowUnderLast(barIndex, tolerance) && + !IsKISlowUnderLast(barIndex + 1, tolerance); if (!result) { return result; @@ -667,7 +691,7 @@ class XCX121XKIHelperParser : XCBase bool IsKISuperSlowOverLast( int barIndex = 0, - double distancePoint = 5 // + double tolerance = 2 // ) { // @@ -686,13 +710,11 @@ class XCX121XKIHelperParser : XCBase } // - double value = helper.GetKISuperSlow(barIndex); - double pValue = helper.GetKISuperSlow(barIndex + 1); - double point = GetPoints(symbol); - double distance = point * distancePoint; - - // - result = value >= pValue + distance; + result = IsOver( + helper.GetKISuperSlow(barIndex), + helper.GetKISuperSlow(barIndex + 1), + GetPoints(symbol) * tolerance // + ); // return result; @@ -700,7 +722,7 @@ class XCX121XKIHelperParser : XCBase bool IsKISuperSlowUnderLast( int barIndex = 0, - double distancePoint = 5 // + double tolerance = 2 // ) { // @@ -719,19 +741,20 @@ class XCX121XKIHelperParser : XCBase } // - double value = helper.GetKISuperSlow(barIndex); - double pValue = helper.GetKISuperSlow(barIndex + 1); - double point = GetPoints(symbol); - double distance = point * distancePoint; - - // - result = value <= pValue - distance; + result = IsUnder( + helper.GetKISuperSlow(barIndex), + helper.GetKISuperSlow(barIndex + 1), + GetPoints(symbol) * tolerance // + ); // return result; } - bool IsKISuperSlowSameAsLast(int barIndex = 0) + bool IsKISuperSlowSameAsLast( + int barIndex = 0, + double tolerance = 2 // + ) { // bool result = false; @@ -740,14 +763,20 @@ class XCX121XKIHelperParser : XCBase barIndex = NormalizeBarIndex(barIndex); // - result = IsValid() && - helper.GetKISuperSlow(barIndex) == helper.GetKISuperSlow(barIndex + 1); + result = IsSame( + helper.GetKISuperSlow(barIndex), + helper.GetKISuperSlow(barIndex + 1), + GetPoints(symbol) * tolerance // + ); // return result; } - bool IsKISuperSlowSwitchedOverLast(int barIndex = 0) + bool IsKISuperSlowSwitchedOverLast( + int barIndex = 0, + double tolerance = 2 // + ) { // bool result = false; @@ -758,8 +787,8 @@ class XCX121XKIHelperParser : XCBase // result = IsValid() && - IsKISuperSlowOverLast(barIndex) && - !IsKISuperSlowOverLast(barIndex + 1); + IsKISuperSlowOverLast(barIndex, tolerance) && + !IsKISuperSlowOverLast(barIndex + 1, tolerance); if (!result) { return result; @@ -769,7 +798,10 @@ class XCX121XKIHelperParser : XCBase return result; } - bool IsKISuperSlowSwitchedUnderLast(int barIndex = 0) + bool IsKISuperSlowSwitchedUnderLast( + int barIndex = 0, + double tolerance = 2 // + ) { // bool result = false; @@ -780,8 +812,8 @@ class XCX121XKIHelperParser : XCBase // result = IsValid() && - IsKISuperSlowUnderLast(barIndex) && - !IsKISuperSlowUnderLast(barIndex + 1); + IsKISuperSlowUnderLast(barIndex, tolerance) && + !IsKISuperSlowUnderLast(barIndex + 1, tolerance); if (!result) { return result; @@ -891,7 +923,10 @@ class XCX121XKIHelperParser : XCBase return result; } - bool IsKIWaveOverLast(int barIndex = 0) + bool IsKIWaveOverLast( + int barIndex = 0, + double tolerance = 2 // + ) { // bool result = false; @@ -907,7 +942,10 @@ class XCX121XKIHelperParser : XCBase return result; } - bool IsKIWaveUnderLast(int barIndex = 0) + bool IsKIWaveUnderLast( + int barIndex = 0, + double tolerance = 2 // + ) { // bool result = false; @@ -923,7 +961,10 @@ class XCX121XKIHelperParser : XCBase return result; } - bool IsKIWaveSwitchedOverLast(int barIndex = 0) + bool IsKIWaveSwitchedOverLast( + int barIndex = 0, + double tolerance = 2 // + ) { // bool result = false; @@ -941,7 +982,10 @@ class XCX121XKIHelperParser : XCBase return result; } - bool IsKIWaveSwitchedUnderLast(int barIndex = 0) + bool IsKIWaveSwitchedUnderLast( + int barIndex = 0, + double tolerance = 2 // + ) { // bool result = false; @@ -1304,7 +1348,10 @@ class XCX121XKIHelperParser : XCBase return result; } - bool IsMAFastOverLast(int barIndex = 0) + bool IsMAFastOverLast( + int barIndex = 0, + double tolerance = 2 // + ) { // bool result = false; @@ -1315,13 +1362,20 @@ class XCX121XKIHelperParser : XCBase // result = IsValid() && - helper.GetMAFast(barIndex) > helper.GetMAFast(barIndex + 1); + IsOver( + helper.GetMAFast(barIndex), + helper.GetMAFast(barIndex + 1), + GetPoints(symbol) * tolerance // + ); // return result; } - bool IsMAFastUnderLast(int barIndex = 0) + bool IsMAFastUnderLast( + int barIndex = 0, + double tolerance = 2 // + ) { // bool result = false; @@ -1332,13 +1386,20 @@ class XCX121XKIHelperParser : XCBase // result = IsValid() && - helper.GetMAFast(barIndex) < helper.GetMAFast(barIndex + 1); + IsUnder( + helper.GetMAFast(barIndex), + helper.GetMAFast(barIndex + 1), + GetPoints(symbol) * tolerance // + ); // return result; } - bool IsMAFastSwitchedOverLast(int barIndex = 0) + bool IsMAFastSwitchedOverLast( + int barIndex = 0, + double tolerance = 2 // + ) { // bool result = false; @@ -1349,14 +1410,17 @@ class XCX121XKIHelperParser : XCBase // result = IsValid() && - IsMAFastOverLast(barIndex) && - !IsMAFastOverLast(barIndex + 1); + IsMAFastOverLast(barIndex, tolerance) && + !IsMAFastOverLast(barIndex + 1, tolerance); // return result; } - bool IsMAFastSwitchedUnderLast(int barIndex = 0) + bool IsMAFastSwitchedUnderLast( + int barIndex = 0, + double tolerance = 2 // + ) { // bool result = false; @@ -1367,8 +1431,8 @@ class XCX121XKIHelperParser : XCBase // result = IsValid() && - IsMAFastUnderLast(barIndex) && - !IsMAFastUnderLast(barIndex + 1); + IsMAFastUnderLast(barIndex, tolerance) && + !IsMAFastUnderLast(barIndex + 1, tolerance); // return result; @@ -1480,7 +1544,10 @@ class XCX121XKIHelperParser : XCBase return result; } - bool IsMASlowOverLast(int barIndex = 0) + bool IsMASlowOverLast( + int barIndex = 0, + double tolerance = 2 // + ) { // bool result = false; @@ -1491,13 +1558,20 @@ class XCX121XKIHelperParser : XCBase // result = IsValid() && - helper.GetMASlow(barIndex) > helper.GetMASlow(barIndex + 1); + IsOver( + helper.GetMASlow(barIndex), + helper.GetMASlow(barIndex + 1), + GetPoints(symbol) * tolerance // + ); // return result; } - bool IsMASlowUnderLast(int barIndex = 0) + bool IsMASlowUnderLast( + int barIndex = 0, + double tolerance = 2 // + ) { // bool result = false; @@ -1508,13 +1582,20 @@ class XCX121XKIHelperParser : XCBase // result = IsValid() && - helper.GetMASlow(barIndex) < helper.GetMASlow(barIndex + 1); + IsUnder( + helper.GetMASlow(barIndex), + helper.GetMASlow(barIndex + 1), + GetPoints(symbol) * tolerance // + ); // return result; } - bool IsMASlowSwitchedOverLast(int barIndex = 0) + bool IsMASlowSwitchedOverLast( + int barIndex = 0, + double tolerance = 2 // + ) { // bool result = false; @@ -1525,14 +1606,17 @@ class XCX121XKIHelperParser : XCBase // result = IsValid() && - IsMASlowOverLast(barIndex) && - !IsMASlowOverLast(barIndex + 1); + IsMASlowOverLast(barIndex, tolerance) && + !IsMASlowOverLast(barIndex + 1, tolerance); // return result; } - bool IsMASlowSwitchedUnderLast(int barIndex = 0) + bool IsMASlowSwitchedUnderLast( + int barIndex = 0, + double tolerance = 2 // + ) { // bool result = false; @@ -1543,8 +1627,8 @@ class XCX121XKIHelperParser : XCBase // result = IsValid() && - IsMASlowUnderLast(barIndex) && - !IsMASlowUnderLast(barIndex + 1); + IsMASlowUnderLast(barIndex, tolerance) && + !IsMASlowUnderLast(barIndex + 1, tolerance); // return result; @@ -1656,7 +1740,10 @@ class XCX121XKIHelperParser : XCBase return result; } - bool IsMASuperSlowOverLast(int barIndex = 0) + bool IsMASuperSlowOverLast( + int barIndex = 0, + double tolerance = 2 // + ) { // bool result = false; @@ -1667,13 +1754,20 @@ class XCX121XKIHelperParser : XCBase // result = IsValid() && - helper.GetMASuperSlow(barIndex) > helper.GetMASuperSlow(barIndex + 1); + IsOver( + helper.GetMASuperSlow(barIndex), + helper.GetMASuperSlow(barIndex + 1), + GetPoints(symbol) * tolerance // + ); // return result; } - bool IsMASuperSlowUnderLast(int barIndex = 0) + bool IsMASuperSlowUnderLast( + int barIndex = 0, + double tolerance = 2 // + ) { // bool result = false; @@ -1684,13 +1778,20 @@ class XCX121XKIHelperParser : XCBase // result = IsValid() && - helper.GetMASuperSlow(barIndex) < helper.GetMASuperSlow(barIndex + 1); + IsUnder( + helper.GetMASuperSlow(barIndex), + helper.GetMASuperSlow(barIndex + 1), + GetPoints(symbol) * tolerance // + ); // return result; } - bool IsMASuperSlowSwitchedOverLast(int barIndex = 0) + bool IsMASuperSlowSwitchedOverLast( + int barIndex = 0, + double tolerance = 2 // + ) { // bool result = false; @@ -1701,14 +1802,17 @@ class XCX121XKIHelperParser : XCBase // result = IsValid() && - IsMASuperSlowOverLast(barIndex) && - !IsMASuperSlowOverLast(barIndex + 1); + IsMASuperSlowOverLast(barIndex, tolerance) && + !IsMASuperSlowOverLast(barIndex + 1, tolerance); // return result; } - bool IsMASuperSlowSwitchedUnderLast(int barIndex = 0) + bool IsMASuperSlowSwitchedUnderLast( + int barIndex = 0, + double tolerance = 2 // + ) { // bool result = false; @@ -1719,8 +1823,8 @@ class XCX121XKIHelperParser : XCBase // result = IsValid() && - IsMASuperSlowUnderLast(barIndex) && - !IsMASuperSlowUnderLast(barIndex + 1); + IsMASuperSlowUnderLast(barIndex, tolerance) && + !IsMASuperSlowUnderLast(barIndex + 1, tolerance); // return result; @@ -1859,105 +1963,10 @@ class XCX121XKIHelperParser : XCBase // #endregion // #region PV ... - bool IsPeakSameAsLast(int barIndex = 0) - { - // - bool result = false; - - // - barIndex = NormalizeBarIndex(barIndex); - - // - result = IsValid(); - if (!result) - { - return result; - } - - // - result = helper.GetPeak(barIndex) == helper.GetPeak(barIndex + 1); - - // - return result; - } - - bool IsPeakOverLast(int barIndex = 0) - { - // - bool result = false; - - // - barIndex = NormalizeBarIndex(barIndex); - - // - result = IsValid(); - if (!result) - { - return result; - } - - // - result = helper.GetPeak(barIndex) > helper.GetPeak(barIndex + 1); - - // - return result; - } - - bool IsPeakUnderLast(int barIndex = 0) - { - // - bool result = false; - - // - barIndex = NormalizeBarIndex(barIndex); - - // - result = IsValid(); - if (!result) - { - return result; - } - - // - result = helper.GetPeak(barIndex) < helper.GetPeak(barIndex + 1); - - // - return result; - } - - int CountSamePeaks( + bool IsPeakSameAsLast( int barIndex = 0, - int loopback = 10 // + double tolerance = 2 // ) - { - // - int result = 0; - - // - if (!IsValid()) - { - return result; - } - - // - loopback = NormalizeInt(loopback, 2); - barIndex = NormalizeBarIndex(barIndex); - - // - for (int i = barIndex; i < barIndex + loopback; i++) - { - // - if (IsPeakSameAsLast(i)) - { - result++; - } - } - - // - return result; - } - - bool IsValeSameAsLast(int barIndex = 0) { // bool result = false; @@ -1966,90 +1975,133 @@ class XCX121XKIHelperParser : XCBase barIndex = NormalizeBarIndex(barIndex); // - result = IsValid(); - if (!result) - { - return result; - } - - // - result = helper.GetVale(barIndex) == helper.GetVale(barIndex + 1); + result = + IsValid() && + IsSame( + helper.GetPeak(barIndex), + helper.GetPeak(barIndex + 1), + GetPoints(symbol) * tolerance // + ); // return result; } - bool IsValeOverLast(int barIndex = 0) - { - // - bool result = false; - - // - barIndex = NormalizeBarIndex(barIndex); - - // - result = IsValid(); - if (!result) - { - return result; - } - - // - result = helper.GetVale(barIndex) > helper.GetVale(barIndex + 1); - - // - return result; - } - - bool IsValeUnderLast(int barIndex = 0) - { - // - bool result = false; - - // - barIndex = NormalizeBarIndex(barIndex); - - // - result = IsValid(); - if (!result) - { - return result; - } - - // - result = helper.GetVale(barIndex) < helper.GetVale(barIndex + 1); - - // - return result; - } - - int CountSameVales( + bool IsPeakOverLast( int barIndex = 0, - int loopback = 10 // + double tolerance = 2 // ) { // - int result = 0; + bool result = false; // - if (!IsValid()) - { - return result; - } - - // - loopback = NormalizeInt(loopback, 2); barIndex = NormalizeBarIndex(barIndex); // - for (int i = barIndex; i < barIndex + loopback; i++) - { - // - if (IsValeSameAsLast(i)) - { - result++; - } - } + result = + IsValid() && + IsOver( + helper.GetPeak(barIndex), + helper.GetPeak(barIndex + 1), + GetPoints(symbol) * tolerance // + ); + + // + return result; + } + + bool IsPeakUnderLast( + int barIndex = 0, + double tolerance = 2 // + ) + { + // + bool result = false; + + // + barIndex = NormalizeBarIndex(barIndex); + + // + result = + IsValid() && + IsUnder( + helper.GetPeak(barIndex), + helper.GetPeak(barIndex + 1), + GetPoints(symbol) * tolerance // + ); + + // + return result; + } + + bool IsValeSameAsLast( + int barIndex = 0, + double tolerance = 2 // + ) + { + // + bool result = false; + + // + barIndex = NormalizeBarIndex(barIndex); + + // + result = + IsValid() && + IsSame( + helper.GetVale(barIndex), + helper.GetVale(barIndex + 1), + GetPoints(symbol) * tolerance // + ); + + // + return result; + } + + bool IsValeOverLast( + int barIndex = 0, + double tolerance = 2 // + ) + { + // + bool result = false; + + // + barIndex = NormalizeBarIndex(barIndex); + + // + result = + IsValid() && + IsOver( + helper.GetVale(barIndex), + helper.GetVale(barIndex + 1), + GetPoints(symbol) * tolerance // + ); + + // + return result; + } + + bool IsValeUnderLast( + int barIndex = 0, + double tolerance = 2 // + ) + { + // + bool result = false; + + // + barIndex = NormalizeBarIndex(barIndex); + + // + result = + IsValid() && + IsUnder( + helper.GetVale(barIndex), + helper.GetVale(barIndex + 1), + GetPoints(symbol) * tolerance // + ); // return result; @@ -2133,7 +2185,10 @@ class XCX121XKIHelperParser : XCBase return result; } - bool IsATROverLast(int barIndex = 0) + bool IsATROverLast( + int barIndex = 0, + double tolerance = 2 // + ) { // bool result = false; @@ -2144,13 +2199,20 @@ class XCX121XKIHelperParser : XCBase // result = IsValid() && - helper.GetATR(barIndex) > helper.GetATR(barIndex + 1); + IsOver( + helper.GetATR(barIndex), + helper.GetATR(barIndex + 1), + GetPoints(symbol) * tolerance // + ); // return result; } - bool IsATRUnderLast(int barIndex = 0) + bool IsATRUnderLast( + int barIndex = 0, + double tolerance = 2 // + ) { // bool result = false; @@ -2161,13 +2223,20 @@ class XCX121XKIHelperParser : XCBase // result = IsValid() && - helper.GetATR(barIndex) < helper.GetATR(barIndex + 1); + IsUnder( + helper.GetATR(barIndex), + helper.GetATR(barIndex + 1), + GetPoints(symbol) * tolerance // + ); // return result; } - bool IsATRSwitchedOverLast(int barIndex = 0) + bool IsATRSwitchedOverLast( + int barIndex = 0, + double tolerance = 2 // + ) { // bool result = false; @@ -2178,14 +2247,17 @@ class XCX121XKIHelperParser : XCBase // result = IsValid() && - IsATROverLast(barIndex) && - !IsATROverLast(barIndex + 1); + IsATROverLast(barIndex, tolerance) && + !IsATROverLast(barIndex + 1, tolerance); // return result; } - bool IsATRSwitchedUnderLast(int barIndex = 0) + bool IsATRSwitchedUnderLast( + int barIndex = 0, + double tolerance = 2 // + ) { // bool result = false; @@ -2196,8 +2268,98 @@ class XCX121XKIHelperParser : XCBase // result = IsValid() && - IsATRUnderLast(barIndex) && - !IsATRUnderLast(barIndex + 1); + IsATRUnderLast(barIndex, tolerance) && + !IsATRUnderLast(barIndex + 1, tolerance); + + // + return result; + } + + bool IsATRSmoothedOverLast( + int barIndex = 0, + double tolerance = 2 // + ) + { + // + bool result = false; + + // + barIndex = NormalizeBarIndex(barIndex); + + // + result = + IsValid() && + IsOver( + helper.GetATRSmoothed(barIndex), + helper.GetATRSmoothed(barIndex + 1), + GetPoints(symbol) * tolerance // + ); + + // + return result; + } + + bool IsATRSmoothedUnderLast( + int barIndex = 0, + double tolerance = 2 // + ) + { + // + bool result = false; + + // + barIndex = NormalizeBarIndex(barIndex); + + // + result = + IsValid() && + IsUnder( + helper.GetATRSmoothed(barIndex), + helper.GetATRSmoothed(barIndex + 1), + GetPoints(symbol) * tolerance // + ); + + // + return result; + } + + bool IsATRSmoothedSwitchedOverLast( + int barIndex = 0, + double tolerance = 2 // + ) + { + // + bool result = false; + + // + barIndex = NormalizeBarIndex(barIndex); + + // + result = + IsValid() && + IsATRSmoothedOverLast(barIndex, tolerance) && + !IsATRSmoothedOverLast(barIndex + 1, tolerance); + + // + return result; + } + + bool IsATRSmoothedSwitchedUnderLast( + int barIndex = 0, + double tolerance = 2 // + ) + { + // + bool result = false; + + // + barIndex = NormalizeBarIndex(barIndex); + + // + result = + IsValid() && + IsATRSmoothedUnderLast(barIndex, tolerance) && + !IsATRSmoothedUnderLast(barIndex + 1, tolerance); // return result; @@ -2323,7 +2485,8 @@ class XCX121XKIHelperParser : XCBase // #region RSI ... bool IsRSIBullish( int barIndex = 0, - double threshold = 50 // + double threshold = 55, + double tolerance = 2 // ) { // @@ -2342,164 +2505,8 @@ class XCX121XKIHelperParser : XCBase } // - result = helper.GetRSI(barIndex) > threshold; - return result; - } - - bool IsRSIBearish( - int barIndex = 0, - double threshold = 50 // - ) - { - // - bool result = false; - - // - // Normalize ... - barIndex = NormalizeBarIndex(barIndex); - - // - // Validate ... - result = IsValid(); - if (!result) - { - return result; - } - - // - result = helper.GetRSI(barIndex) < threshold; - return result; - } - - bool IsRSIOverbought( - int barIndex = 0, - double threshold = 70 // - ) - { - // - bool result = false; - - // - // Normalize ... - barIndex = NormalizeBarIndex(barIndex); - - // - // Validate ... - result = IsValid(); - if (!result) - { - return result; - } - - // - result = helper.GetRSI(barIndex) > threshold; - return result; - } - - bool IsRSIOversold( - int barIndex = 0, - double threshold = 30 // - ) - { - // - bool result = false; - - // - // Normalize ... - barIndex = NormalizeBarIndex(barIndex); - - // - // Validate ... - result = IsValid(); - if (!result) - { - return result; - } - - // - result = helper.GetRSI(barIndex) < threshold; - return result; - } - - bool IsRSISwitchedToOverSold( - int barIndex = 0, - double threshold = 30 // - ) - { - // - bool result = false; - - // - barIndex = NormalizeBarIndex(barIndex); - - // - result = - IsValid() && - IsRSIOversold(barIndex, threshold) && - !IsRSIOversold(barIndex + 1, threshold); - - // - return result; - } - - bool IsRSISwitchedFromOverSold( - int barIndex = 0, - double threshold = 30 // - ) - { - // - bool result = false; - - // - barIndex = NormalizeBarIndex(barIndex); - - // - result = - IsValid() && - !IsRSIOversold(barIndex, threshold) && - IsRSIOversold(barIndex + 1, threshold); - - // - return result; - } - - bool IsRSISwitchedToOverbought( - int barIndex = 0, - double threshold = 70 // - ) - { - // - bool result = false; - - // - barIndex = NormalizeBarIndex(barIndex); - - // - result = - IsValid() && - IsRSIOverbought(barIndex, threshold) && - !IsRSIOverbought(barIndex + 1, threshold); - - // - return result; - } - - bool IsRSISwitchedFromOverbought( - int barIndex = 0, - double threshold = 70 // - ) - { - // - bool result = false; - - // - barIndex = NormalizeBarIndex(barIndex); - - // - result = - IsValid() && - !IsRSIOverbought(barIndex, threshold) && - IsRSIOverbought(barIndex + 1, threshold); + result = helper.GetRSI(barIndex) > threshold + (GetPoints(symbol) * tolerance) || + helper.GetRSI(barIndex) > threshold - (GetPoints(symbol) * tolerance); // return result; @@ -2507,7 +2514,8 @@ class XCX121XKIHelperParser : XCBase bool IsRSISwitchedToBullish( int barIndex = 0, - double threshold = 50 // + double threshold = 55, + double tolerance = 2 // ) { // @@ -2527,8 +2535,37 @@ class XCX121XKIHelperParser : XCBase // result = - IsRSIBullish(barIndex, threshold) && - !IsRSIBullish(barIndex + 1, threshold); + IsRSIBullish(barIndex, threshold, tolerance) && + !IsRSIBullish(barIndex + 1, threshold, tolerance); + + // + return result; + } + + bool IsRSIBearish( + int barIndex = 0, + double threshold = 45, + double tolerance = 2 // + ) + { + // + bool result = false; + + // + // Normalize ... + barIndex = NormalizeBarIndex(barIndex); + + // + // Validate ... + result = IsValid(); + if (!result) + { + return result; + } + + // + result = helper.GetRSI(barIndex) < threshold + (GetPoints(symbol) * tolerance) || + helper.GetRSI(barIndex) < threshold - (GetPoints(symbol) * tolerance); // return result; @@ -2536,7 +2573,8 @@ class XCX121XKIHelperParser : XCBase bool IsRSISwitchedToBearish( int barIndex = 0, - double threshold = 50 // + double threshold = 45, + double tolerance = 2 // ) { // @@ -2556,8 +2594,314 @@ class XCX121XKIHelperParser : XCBase // result = - IsRSIBearish(barIndex, threshold) && - !IsRSIBearish(barIndex + 1, threshold); + IsRSIBearish(barIndex, threshold, tolerance) && + !IsRSIBearish(barIndex + 1, threshold, tolerance); + + // + return result; + } + + bool IsRSIRising(int barIndex = 0) + { + // + bool result = false; + + // + barIndex = NormalizeBarIndex(barIndex); + + // + result = + IsValid() && + helper.GetRSI(barIndex) > helper.GetRSISmoothed(barIndex); + + // + return result; + } + + bool IsRSISwitchedToRising(int barIndex = 0) + { + // + bool result = false; + + // + barIndex = NormalizeBarIndex(barIndex); + + // + result = + IsValid() && + IsRSIRising(barIndex) && + !IsRSIRising(barIndex + 1); + + // + return result; + } + + bool IsRSIFalling(int barIndex = 0) + { + // + bool result = false; + + // + barIndex = NormalizeBarIndex(barIndex); + + // + result = + IsValid() && + helper.GetRSI(barIndex) < helper.GetRSISmoothed(barIndex); + + // + return result; + } + + bool IsRSISwitchedToFalling(int barIndex = 0) + { + // + bool result = false; + + // + barIndex = NormalizeBarIndex(barIndex); + + // + result = + IsValid() && + IsRSIFalling(barIndex) && + !IsRSIFalling(barIndex + 1); + + // + return result; + } + + bool IsRSIOverLast( + int barIndex = 0, + double tolerance = 2 // + ) + { + // + bool result = false; + + // + barIndex = NormalizeBarIndex(barIndex); + + // + result = + IsValid() && + IsOver( + helper.GetRSI(barIndex), + helper.GetRSI(barIndex + 1), + GetPoints(symbol) * tolerance // + ); + + // + return result; + } + + bool IsRSISwitchedOverLast( + int barIndex = 0, + double tolerance = 2 // + ) + { + // + bool result = false; + + // + barIndex = NormalizeBarIndex(barIndex); + + // + result = + IsValid() && + IsRSIOverLast(barIndex, tolerance) && + !IsRSIOverLast(barIndex + 1, tolerance); + + // + return result; + } + + bool IsRSIUnderLast( + int barIndex = 0, + double tolerance = 2 // + ) + { + // + bool result = false; + + // + barIndex = NormalizeBarIndex(barIndex); + + // + result = + IsValid() && + IsUnder( + helper.GetRSI(barIndex), + helper.GetRSI(barIndex + 1), + GetPoints(symbol) * tolerance // + ); + + // + return result; + } + + bool IsRSISwitchedUnderLast( + int barIndex = 0, + double tolerance = 2 // + ) + { + // + bool result = false; + + // + barIndex = NormalizeBarIndex(barIndex); + + // + result = + IsValid() && + IsRSIUnderLast(barIndex, tolerance) && + !IsRSIUnderLast(barIndex + 1, tolerance); + + // + return result; + } + + bool IsRSIOverbought( + int barIndex = 0, + double threshold = 70, + double tolerance = 2 // + ) + { + // + bool result = false; + + // + // Normalize ... + barIndex = NormalizeBarIndex(barIndex); + + // + // Validate ... + result = IsValid(); + if (!result) + { + return result; + } + + // + result = helper.GetRSI(barIndex) > threshold + (GetPoints(symbol) * tolerance) || + helper.GetRSI(barIndex) > threshold - (GetPoints(symbol) * tolerance); + + // + return result; + } + + bool IsRSIOversold( + int barIndex = 0, + double threshold = 30, + double tolerance = 2 // + ) + { + // + bool result = false; + + // + // Normalize ... + barIndex = NormalizeBarIndex(barIndex); + + // + // Validate ... + result = IsValid(); + if (!result) + { + return result; + } + + // + result = helper.GetRSI(barIndex) < threshold + (GetPoints(symbol) * tolerance) || + helper.GetRSI(barIndex) < threshold - (GetPoints(symbol) * tolerance); + + // + return result; + } + + bool IsRSISwitchedToOversold( + int barIndex = 0, + double threshold = 30, + double tolerance = 2 // + ) + { + // + bool result = false; + + // + barIndex = NormalizeBarIndex(barIndex); + + // + result = + IsValid() && + IsRSIOversold(barIndex, threshold, tolerance) && + !IsRSIOversold(barIndex + 1, threshold, tolerance); + + // + return result; + } + + bool IsRSISwitchedFromOversold( + int barIndex = 0, + double threshold = 30, + double tolerance = 2 // + ) + { + // + bool result = false; + + // + barIndex = NormalizeBarIndex(barIndex); + + // + result = + IsValid() && + !IsRSIOversold(barIndex, threshold, tolerance) && + IsRSIOversold(barIndex + 1, threshold, tolerance); + + // + return result; + } + + bool IsRSISwitchedToOverbought( + int barIndex = 0, + double threshold = 70, + double tolerance = 2 // + ) + { + // + bool result = false; + + // + barIndex = NormalizeBarIndex(barIndex); + + // + result = + IsValid() && + IsRSIOverbought(barIndex, threshold, tolerance) && + !IsRSIOverbought(barIndex + 1, threshold, tolerance); + + // + return result; + } + + bool IsRSISwitchedFromOverbought( + int barIndex = 0, + double threshold = 70, + double tolerance = 2 // + ) + { + // + bool result = false; + + // + barIndex = NormalizeBarIndex(barIndex); + + // + result = + IsValid() && + !IsRSIOverbought(barIndex, threshold, tolerance) && + IsRSIOverbought(barIndex + 1, threshold, tolerance); // return result; @@ -2565,6 +2909,744 @@ 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 // diff --git a/X121XKIEA/Classes/x-saherelm.x121.xki.signaller.class.mq5 b/X121XKIEA/Classes/x-saherelm.x121.xki.signaller.class.mq5 index e8bb8e48..c182b54f 100644 --- a/X121XKIEA/Classes/x-saherelm.x121.xki.signaller.class.mq5 +++ b/X121XKIEA/Classes/x-saherelm.x121.xki.signaller.class.mq5 @@ -982,7 +982,6 @@ class XCX121XKIStrategy1Signaller : public XCX121XKIBaseSignaller // // TEST ... - // return false;