diff --git a/Documents/BKP/X121XKI/tmps.bkp.mq5 b/Documents/BKP/X121XKI/tmps.bkp.mq5 index 8194f44f..4e9a4338 100644 --- a/Documents/BKP/X121XKI/tmps.bkp.mq5 +++ b/Documents/BKP/X121XKI/tmps.bkp.mq5 @@ -1,718 +1,715 @@ - /** - * Check Bar Has Signal Based on Strategy 1 ... - * - * Pattern‑based reversal: - * - Detects Pin Bar or Signal Key Bar. - * - Confirms with POI detector. - * - Good for reversals at support/resistance. - * - * @param bar: XOHCL, reference to Bar ... - * @param zone: XBoxZone, reference to holds affected zone ... - * @param targets: XTarget, reference to detected Signal's Targets collections ... - * @param dir: ENUM_X_DIRECTION, detected Signal's direction ... - * - * @return ( bool ) - */ - bool Strategy1HasSignal( - XOHCL &bar, - XBoxZone &zone, - XTarget &targets[], - ENUM_X_DIRECTION &dir // - ) +/** + * Check Bar Has Signal Based on Strategy 1 ... + * + * Pattern‑based reversal: + * - Detects Pin Bar or Signal Key Bar. + * - Confirms with POI detector. + * - Good for reversals at support/resistance. + * + * @param bar: XOHCL, reference to Bar ... + * @param zone: XBoxZone, reference to holds affected zone ... + * @param targets: XTarget, reference to detected Signal's Targets collections ... + * @param dir: ENUM_X_DIRECTION, detected Signal's direction ... + * + * @return ( bool ) + */ +bool Strategy1HasSignal( + XOHCL &bar, + XBoxZone &zone, + XTarget &targets[], + ENUM_X_DIRECTION &dir // +) +{ + // + bool result = false; + + // + zone.Clean(); + XClean(targets); + dir = X_DIRECTION_NONE; + + // + result = bar.IsValid(); + if (!result) { - // - bool result = false; - - // - zone.Clean(); - XClean(targets); - dir = X_DIRECTION_NONE; - - // - result = bar.IsValid(); - if (!result) - { - return result; - } - - // - result = poiDetector.IsKISignal( - dir, - bar.Index() // - ); - bool isBullish = result && - IsXBullish(dir); - bool isBearish = result && - IsXBearish(dir); - result = isBullish || - isBearish; - if (!result) - { - return result; - } - - // - // Detect Nearest Directional ... - int nearestDirectionalSwitchIndex = -1; - if (isBullish) - { - // - isBullish = poiDetector.NearestKIFastSwitchedToBullish( - nearestDirectionalSwitchIndex, - bar.Index() + 2 // - ); - } - else - { - // - isBearish = poiDetector.NearestKIFastSwitchedToBearish( - nearestDirectionalSwitchIndex, - bar.Index() + 2 // - ); - } - result = - IsValidIndex(nearestDirectionalSwitchIndex) && - (isBullish || - isBearish); - if (!result) - { - // - bar.Clean(); - return result; - } - - // - // Preparing Zone ... - double upper = bar.FindHighest(nearestDirectionalSwitchIndex - bar.Index(), MODE_HIGH); - double lower = bar.FindLowest(nearestDirectionalSwitchIndex - bar.Index(), MODE_LOW); - - // - result = zone.Init( - symbol, - period, - upper, - lower, - GetBarTime(symbol, period, nearestDirectionalSwitchIndex), - bar.time, - dir, - "XKI1" // - ); - - // - // Support and Resistance ... - XBoxZone supports[]; - XBoxZone resistances[]; - if (result) - { - // - // Supports ... - poiDetector.DetectSupports( - supports, - bar.Index(), - 50, // Loopback ... - true, // Force Validation ... - 7, // Validation Length ... - symbol, // For Symbol ... - period // For Period ... - ); - - // - // Resistances ... - poiDetector.DetectResistances( - resistances, - bar.Index(), - 50, // Loopback ... - true, // Force Validation ... - 7, // Validation Length ... - symbol, // For Symbol ... - period // For Period ... - ); - } - - // - // TODO: Rempve ... - if (result) - { - // - // Other Drawing Materials ... - XPOIDrawConfig drawConfig; - drawConfig.Default(); - - // - // this for Selected Zone ... - poiDrawer.DrawZone(zone, drawConfig); - - // - // Drawing Supports and Resistances ... - drawConfig.bearishColor = clrRed; - drawConfig.bullishColor = clrLime; - - // - if (HasChild(supports)) - { - poiDrawer.DrawZones(supports, drawConfig); - } - - // - if (HasChild(resistances)) - { - poiDrawer.DrawZones(resistances, drawConfig); - } - - // - drawConfig.Clean(); - - // - DebugBreak(); - } - - // - result = - result && - zone.IsValid() && - HasDirection(dir); - - // return result; } - - /** - * Check Bar Has Signal Based on Strategy 1 ... - * - * Pattern‑based reversal: - * - Detects Pin Bar or Signal Key Bar. - * - Confirms with POI detector. - * - Good for reversals at support/resistance. - * - * @param bar: XOHCL, reference to Bar ... - * @param zone: XBoxZone, reference to holds affected zone ... - * @param targets: XTarget, reference to detected Signal's Targets collections ... - * @param dir: ENUM_X_DIRECTION, detected Signal's direction ... - * - * @return ( bool ) - */ - bool Strategy1HasSignal( - XOHCL &bar, - XBoxZone &zone, - XTarget &targets[], - ENUM_X_DIRECTION &dir // - ) + // + result = poiDetector.IsKISignal( + dir, + bar.Index() // + ); + bool isBullish = result && + IsXBullish(dir); + bool isBearish = result && + IsXBearish(dir); + result = isBullish || + isBearish; + if (!result) { - // - bool result = false; - - // - zone.Clean(); - XClean(targets); - dir = X_DIRECTION_NONE; - - // - result = bar.IsValid(); - if (!result) - { - return result; - } - - // - result = poiDetector.IsKISignal( - dir, - bar.Index() // - ); - bool isBullish = result && - IsXBullish(dir); - bool isBearish = result && - IsXBearish(dir); - result = isBullish || - isBearish; - if (!result) - { - return result; - } - - // - // Detect Nearest Directional ... - int nearestDirectionalSwitchIndex = -1; - if (isBullish) - { - // - isBullish = poiDetector.NearestKIFastSwitchedToBullish( - nearestDirectionalSwitchIndex, - bar.Index() + 2 // - ); - } - else - { - // - isBearish = poiDetector.NearestKIFastSwitchedToBearish( - nearestDirectionalSwitchIndex, - bar.Index() + 2 // - ); - } - result = - IsValidIndex(nearestDirectionalSwitchIndex) && - (isBullish || - isBearish); - if (!result) - { - // - bar.Clean(); - return result; - } - - // - // Preparing Zone ... - double upper = bar.FindHighest(nearestDirectionalSwitchIndex - bar.Index(), MODE_HIGH); - double lower = bar.FindLowest(nearestDirectionalSwitchIndex - bar.Index(), MODE_LOW); - - // - result = zone.Init( - symbol, - period, - upper, - lower, - GetBarTime(symbol, period, nearestDirectionalSwitchIndex), - bar.time, - dir, - "XKI1" // - ); - - // - // Support and Resistance ... - XBoxZone supports[]; - XBoxZone resistances[]; - XBoxZone minorSupport; - XBoxZone majorSupport; - XBoxZone minorResistance; - XBoxZone majorResistance; - if (result) - { - // - // Supports ... - poiDetector.GetCurrentStructure( - supports, - resistances, - minorSupport, - majorSupport, - minorResistance, - majorResistance, - bar.Index(), - symbol, // For Symbol ... - period, // For Period ... - 50, // Loopback ... - 7, // Minor Validation Length ... - 14 // Major Validation Length ... - ); - } - - // - // TODO: Rempve ... - if (result) - { - // - // Other Drawing Materials ... - XPOIDrawConfig drawConfig; - drawConfig.Default(); - - // - // this for Selected Zone ... - poiDrawer.DrawZone(zone, drawConfig); - - // - // Drawing Supports and Resistances ... - drawConfig.bearishColor = clrRed; - drawConfig.bullishColor = clrLime; - - // - // Minors ... - - // - drawConfig.zonesStyle = STYLE_DOT; - if (minorSupport.IsValid()) - { - poiDrawer.DrawZone(minorSupport, drawConfig); - } - if (minorResistance.IsValid()) - { - poiDrawer.DrawZone(minorResistance, drawConfig); - } - - // - // Majors ... - - // - drawConfig.zonesStyle = STYLE_DASH; - if (majorSupport.IsValid()) - { - poiDrawer.DrawZone(majorSupport, drawConfig); - } - if (majorResistance.IsValid()) - { - poiDrawer.DrawZone(majorResistance, drawConfig); - } - - // // - // if (HasChild(supports)) - // { - // poiDrawer.DrawZones(supports, drawConfig); - // } - - // // - // if (HasChild(resistances)) - // { - // poiDrawer.DrawZones(resistances, drawConfig); - // } - - // - drawConfig.Clean(); - - // - DebugBreak(); - } - - // - result = - result && - zone.IsValid() && - HasDirection(dir); - - // return result; } - - /** - * Check Bar Has Signal Based on Strategy 1 ... - * - * Pattern‑based reversal: - * - Detects Pin Bar or Signal Key Bar. - * - Confirms with POI detector. - * - Good for reversals at support/resistance. - * - * @param bar: XOHCL, reference to Bar ... - * @param zone: XBoxZone, reference to holds affected zone ... - * @param targets: XTarget, reference to detected Signal's Targets collections ... - * @param dir: ENUM_X_DIRECTION, detected Signal's direction ... - * - * @return ( bool ) - */ - bool Strategy1HasSignal( - XOHCL &bar, - XBoxZone &zone, - XTarget &targets[], - ENUM_X_DIRECTION &dir // - ) + // + // Detect Nearest Directional ... + int nearestDirectionalSwitchIndex = -1; + if (isBullish) { // - bool result = false; - - // - zone.Clean(); - XClean(targets); - dir = X_DIRECTION_NONE; - - // - result = bar.IsValid(); - if (!result) - { - return result; - } - - // - result = poiDetector.IsKISignal( - dir, - bar.Index() // + isBullish = poiDetector.NearestKIFastSwitchedToBullish( + nearestDirectionalSwitchIndex, + bar.Index() + 2 // ); - bool isBullish = result && - IsXBullish(dir); - bool isBearish = result && - IsXBearish(dir); - result = isBullish || - isBearish; - if (!result) - { - return result; - } - + } + else + { // - // Detect Nearest Directional ... - int nearestDirectionalSwitchIndex = -1; - if (isBullish) - { - // - isBullish = poiDetector.NearestKIFastSwitchedToBullish( - nearestDirectionalSwitchIndex, - bar.Index() + 2 // - ); - } - else - { - // - isBearish = poiDetector.NearestKIFastSwitchedToBearish( - nearestDirectionalSwitchIndex, - bar.Index() + 2 // - ); - } - result = - IsValidIndex(nearestDirectionalSwitchIndex) && - (isBullish || - isBearish); - if (!result) - { - // - bar.Clean(); - return result; - } - - // - // Preparing Zone ... - double upper = bar.FindHighest(nearestDirectionalSwitchIndex - bar.Index(), MODE_HIGH); - double lower = bar.FindLowest(nearestDirectionalSwitchIndex - bar.Index(), MODE_LOW); - - // - result = zone.Init( - symbol, - period, - upper, - lower, - GetBarTime(symbol, period, nearestDirectionalSwitchIndex), - bar.time, - dir, - "XKI1" // + isBearish = poiDetector.NearestKIFastSwitchedToBearish( + nearestDirectionalSwitchIndex, + bar.Index() + 2 // ); - - // - // Support and Resistance ... - XBoxZone supports[]; - XBoxZone resistances[]; - XBoxZone minorSupport; - XBoxZone majorSupport; - XBoxZone minorResistance; - XBoxZone majorResistance; - if (result) - { - // - // Supports ... - poiDetector.GetCurrentStructure( - supports, - resistances, - minorSupport, - majorSupport, - minorResistance, - majorResistance, - bar.Index(), - symbol, // For Symbol ... - period, // For Period ... - 50, // Loopback ... - 7, // Minor Validation Length ... - 14 // Major Validation Length ... - ); - } - - // - // TODO: Rempve ... - if (result) - { - // - // Other Drawing Materials ... - XPOIDrawConfig drawConfig; - drawConfig.Default(); - - // - // this for Selected Zone ... - poiDrawer.DrawZone(zone, drawConfig); - - // - // Drawing Supports and Resistances ... - drawConfig.bearishColor = clrRed; - drawConfig.bullishColor = clrLime; - - // - // Minors ... - - // - drawConfig.zonesStyle = STYLE_DOT; - if (minorSupport.IsValid()) - { - poiDrawer.DrawZone(minorSupport, drawConfig); - } - if (minorResistance.IsValid()) - { - poiDrawer.DrawZone(minorResistance, drawConfig); - } - - // - // Majors ... - - // - drawConfig.zonesStyle = STYLE_DASH; - if (majorSupport.IsValid()) - { - poiDrawer.DrawZone(majorSupport, drawConfig); - } - if (majorResistance.IsValid()) - { - poiDrawer.DrawZone(majorResistance, drawConfig); - } - - // // - // if (HasChild(supports)) - // { - // poiDrawer.DrawZones(supports, drawConfig); - // } - - // // - // if (HasChild(resistances)) - // { - // poiDrawer.DrawZones(resistances, drawConfig); - // } - - // - drawConfig.Clean(); - - // - DebugBreak(); - } - - // - result = - result && - zone.IsValid() && - HasDirection(dir); - + } + result = + IsValidIndex(nearestDirectionalSwitchIndex) && + (isBullish || + isBearish); + if (!result) + { // + bar.Clean(); return result; } - /** - * Check Bar Has Signal Based on Strategy 1 ... - * - * Pattern‑based reversal: - * - Detects Pin Bar or Signal Key Bar. - * - Confirms with POI detector. - * - Good for reversals at support/resistance. - * - * @param bar: XOHCL, reference to Bar ... - * @param zone: XBoxZone, reference to holds affected zone ... - * @param targets: XTarget, reference to detected Signal's Targets collections ... - * @param dir: ENUM_X_DIRECTION, detected Signal's direction ... - * - * @return ( bool ) - */ - bool Strategy1HasSignal( - XOHCL &bar, - XBoxZone &zone, - XTarget &targets[], - ENUM_X_DIRECTION &dir // - ) + // + // Preparing Zone ... + double upper = bar.FindHighest(nearestDirectionalSwitchIndex - bar.Index(), MODE_HIGH); + double lower = bar.FindLowest(nearestDirectionalSwitchIndex - bar.Index(), MODE_LOW); + + // + result = zone.Init( + symbol, + period, + upper, + lower, + GetBarTime(symbol, period, nearestDirectionalSwitchIndex), + bar.time, + dir, + "XKI1" // + ); + + // + // Support and Resistance ... + XBoxZone supports[]; + XBoxZone resistances[]; + if (result) { // - bool result = false; + // Supports ... + poiDetector.DetectSupports( + supports, + bar.Index(), + 50, // Loopback ... + true, // Force Validation ... + 7, // Validation Length ... + symbol, // For Symbol ... + period // For Period ... + ); // - zone.Clean(); - XClean(targets); - dir = X_DIRECTION_NONE; + // Resistances ... + poiDetector.DetectResistances( + resistances, + bar.Index(), + 50, // Loopback ... + true, // Force Validation ... + 7, // Validation Length ... + symbol, // For Symbol ... + period // For Period ... + ); + } + + // + // TODO: Rempve ... + if (result) + { + // + // Other Drawing Materials ... + XPOIDrawConfig drawConfig; + drawConfig.Default(); // - result = bar.IsValid(); - if (!result) + // this for Selected Zone ... + poiDrawer.DrawZone(zone, drawConfig); + + // + // Drawing Supports and Resistances ... + drawConfig.bearishColor = clrRed; + drawConfig.bullishColor = clrLime; + + // + if (HasChild(supports)) { - return result; + poiDrawer.DrawZones(supports, drawConfig); } // - int barIndex = bar.Index() + 1; - - // - // Safe for Entry ... - bool isSafeForBullishEntry = kiParser.IsSafeBullishEntry(barIndex); - bool isSafeForBearishEntry = kiParser.IsSafeBearishEntry(barIndex); - - // - // POI ... - bool isPOI = poiDetector.IsPOI(dir, barIndex); - bool isBullishPOI = isPOI && - IsXBullish(dir); - bool isBearishPOI = isPOI && - IsXBearish(dir); - if (isPOI) + if (HasChild(resistances)) { - // - // Print("isPOI: ", ToXString(dir)); - // DebugBreak(); + poiDrawer.DrawZones(resistances, drawConfig); } // - // Breakout POI ... - bool isBreakoutPOI = poiDetector.IsBreakoutPOI(dir, barIndex); - bool isBullishBreakoutPOI = isBreakoutPOI && + drawConfig.Clean(); + + // + DebugBreak(); + } + + // + result = + result && + zone.IsValid() && + HasDirection(dir); + + // + return result; +} + +/** + * Check Bar Has Signal Based on Strategy 1 ... + * + * Pattern‑based reversal: + * - Detects Pin Bar or Signal Key Bar. + * - Confirms with POI detector. + * - Good for reversals at support/resistance. + * + * @param bar: XOHCL, reference to Bar ... + * @param zone: XBoxZone, reference to holds affected zone ... + * @param targets: XTarget, reference to detected Signal's Targets collections ... + * @param dir: ENUM_X_DIRECTION, detected Signal's direction ... + * + * @return ( bool ) + */ +bool Strategy1HasSignal( + XOHCL &bar, + XBoxZone &zone, + XTarget &targets[], + ENUM_X_DIRECTION &dir // +) +{ + // + bool result = false; + + // + zone.Clean(); + XClean(targets); + dir = X_DIRECTION_NONE; + + // + result = bar.IsValid(); + if (!result) + { + return result; + } + + // + result = poiDetector.IsKISignal( + dir, + bar.Index() // + ); + bool isBullish = result && + IsXBullish(dir); + bool isBearish = result && + IsXBearish(dir); + result = isBullish || + isBearish; + if (!result) + { + return result; + } + + // + // Detect Nearest Directional ... + int nearestDirectionalSwitchIndex = -1; + if (isBullish) + { + // + isBullish = poiDetector.NearestKIFastSwitchedToBullish( + nearestDirectionalSwitchIndex, + bar.Index() + 2 // + ); + } + else + { + // + isBearish = poiDetector.NearestKIFastSwitchedToBearish( + nearestDirectionalSwitchIndex, + bar.Index() + 2 // + ); + } + result = + IsValidIndex(nearestDirectionalSwitchIndex) && + (isBullish || + isBearish); + if (!result) + { + // + bar.Clean(); + return result; + } + + // + // Preparing Zone ... + double upper = bar.FindHighest(nearestDirectionalSwitchIndex - bar.Index(), MODE_HIGH); + double lower = bar.FindLowest(nearestDirectionalSwitchIndex - bar.Index(), MODE_LOW); + + // + result = zone.Init( + symbol, + period, + upper, + lower, + GetBarTime(symbol, period, nearestDirectionalSwitchIndex), + bar.time, + dir, + "XKI1" // + ); + + // + // Support and Resistance ... + XBoxZone supports[]; + XBoxZone resistances[]; + XBoxZone minorSupport; + XBoxZone majorSupport; + XBoxZone minorResistance; + XBoxZone majorResistance; + if (result) + { + // + // Supports ... + poiDetector.GetCurrentStructure( + supports, + resistances, + minorSupport, + majorSupport, + minorResistance, + majorResistance, + bar.Index(), + symbol, // For Symbol ... + period, // For Period ... + 50, // Loopback ... + 7, // Minor Validation Length ... + 14 // Major Validation Length ... + ); + } + + // + // TODO: Rempve ... + if (result) + { + // + // Other Drawing Materials ... + XPOIDrawConfig drawConfig; + drawConfig.Default(); + + // + // this for Selected Zone ... + poiDrawer.DrawZone(zone, drawConfig); + + // + // Drawing Supports and Resistances ... + drawConfig.bearishColor = clrRed; + drawConfig.bullishColor = clrLime; + + // + // Minors ... + + // + drawConfig.zonesStyle = STYLE_DOT; + if (minorSupport.IsValid()) + { + poiDrawer.DrawZone(minorSupport, drawConfig); + } + if (minorResistance.IsValid()) + { + poiDrawer.DrawZone(minorResistance, drawConfig); + } + + // + // Majors ... + + // + drawConfig.zonesStyle = STYLE_DASH; + if (majorSupport.IsValid()) + { + poiDrawer.DrawZone(majorSupport, drawConfig); + } + if (majorResistance.IsValid()) + { + poiDrawer.DrawZone(majorResistance, drawConfig); + } + + // // + // if (HasChild(supports)) + // { + // poiDrawer.DrawZones(supports, drawConfig); + // } + + // // + // if (HasChild(resistances)) + // { + // poiDrawer.DrawZones(resistances, drawConfig); + // } + + // + drawConfig.Clean(); + + // + DebugBreak(); + } + + // + result = + result && + zone.IsValid() && + HasDirection(dir); + + // + return result; +} + +/** + * Check Bar Has Signal Based on Strategy 1 ... + * + * Pattern‑based reversal: + * - Detects Pin Bar or Signal Key Bar. + * - Confirms with POI detector. + * - Good for reversals at support/resistance. + * + * @param bar: XOHCL, reference to Bar ... + * @param zone: XBoxZone, reference to holds affected zone ... + * @param targets: XTarget, reference to detected Signal's Targets collections ... + * @param dir: ENUM_X_DIRECTION, detected Signal's direction ... + * + * @return ( bool ) + */ +bool Strategy1HasSignal( + XOHCL &bar, + XBoxZone &zone, + XTarget &targets[], + ENUM_X_DIRECTION &dir // +) +{ + // + bool result = false; + + // + zone.Clean(); + XClean(targets); + dir = X_DIRECTION_NONE; + + // + result = bar.IsValid(); + if (!result) + { + return result; + } + + // + result = poiDetector.IsKISignal( + dir, + bar.Index() // + ); + bool isBullish = result && + IsXBullish(dir); + bool isBearish = result && + IsXBearish(dir); + result = isBullish || + isBearish; + if (!result) + { + return result; + } + + // + // Detect Nearest Directional ... + int nearestDirectionalSwitchIndex = -1; + if (isBullish) + { + // + isBullish = poiDetector.NearestKIFastSwitchedToBullish( + nearestDirectionalSwitchIndex, + bar.Index() + 2 // + ); + } + else + { + // + isBearish = poiDetector.NearestKIFastSwitchedToBearish( + nearestDirectionalSwitchIndex, + bar.Index() + 2 // + ); + } + result = + IsValidIndex(nearestDirectionalSwitchIndex) && + (isBullish || + isBearish); + if (!result) + { + // + bar.Clean(); + return result; + } + + // + // Preparing Zone ... + double upper = bar.FindHighest(nearestDirectionalSwitchIndex - bar.Index(), MODE_HIGH); + double lower = bar.FindLowest(nearestDirectionalSwitchIndex - bar.Index(), MODE_LOW); + + // + result = zone.Init( + symbol, + period, + upper, + lower, + GetBarTime(symbol, period, nearestDirectionalSwitchIndex), + bar.time, + dir, + "XKI1" // + ); + + // + // Support and Resistance ... + XBoxZone supports[]; + XBoxZone resistances[]; + XBoxZone minorSupport; + XBoxZone majorSupport; + XBoxZone minorResistance; + XBoxZone majorResistance; + if (result) + { + // + // Supports ... + poiDetector.GetCurrentStructure( + supports, + resistances, + minorSupport, + majorSupport, + minorResistance, + majorResistance, + bar.Index(), + symbol, // For Symbol ... + period, // For Period ... + 50, // Loopback ... + 7, // Minor Validation Length ... + 14 // Major Validation Length ... + ); + } + + // + // TODO: Rempve ... + if (result) + { + // + // Other Drawing Materials ... + XPOIDrawConfig drawConfig; + drawConfig.Default(); + + // + // this for Selected Zone ... + poiDrawer.DrawZone(zone, drawConfig); + + // + // Drawing Supports and Resistances ... + drawConfig.bearishColor = clrRed; + drawConfig.bullishColor = clrLime; + + // + // Minors ... + + // + drawConfig.zonesStyle = STYLE_DOT; + if (minorSupport.IsValid()) + { + poiDrawer.DrawZone(minorSupport, drawConfig); + } + if (minorResistance.IsValid()) + { + poiDrawer.DrawZone(minorResistance, drawConfig); + } + + // + // Majors ... + + // + drawConfig.zonesStyle = STYLE_DASH; + if (majorSupport.IsValid()) + { + poiDrawer.DrawZone(majorSupport, drawConfig); + } + if (majorResistance.IsValid()) + { + poiDrawer.DrawZone(majorResistance, drawConfig); + } + + // // + // if (HasChild(supports)) + // { + // poiDrawer.DrawZones(supports, drawConfig); + // } + + // // + // if (HasChild(resistances)) + // { + // poiDrawer.DrawZones(resistances, drawConfig); + // } + + // + drawConfig.Clean(); + + // + DebugBreak(); + } + + // + result = + result && + zone.IsValid() && + HasDirection(dir); + + // + return result; +} + +/** + * Check Bar Has Signal Based on Strategy 1 ... + * + * Pattern‑based reversal: + * - Detects Pin Bar or Signal Key Bar. + * - Confirms with POI detector. + * - Good for reversals at support/resistance. + * + * @param bar: XOHCL, reference to Bar ... + * @param zone: XBoxZone, reference to holds affected zone ... + * @param targets: XTarget, reference to detected Signal's Targets collections ... + * @param dir: ENUM_X_DIRECTION, detected Signal's direction ... + * + * @return ( bool ) + */ +bool Strategy1HasSignal( + XOHCL &bar, + XBoxZone &zone, + XTarget &targets[], + ENUM_X_DIRECTION &dir // +) +{ + // + bool result = false; + + // + zone.Clean(); + XClean(targets); + dir = X_DIRECTION_NONE; + + // + result = bar.IsValid(); + if (!result) + { + return result; + } + + // + int barIndex = bar.Index() + 1; + + // + // Safe for Entry ... + bool isSafeForBullishEntry = kiParser.IsSafeBullishEntry(barIndex); + bool isSafeForBearishEntry = kiParser.IsSafeBearishEntry(barIndex); + + // + // POI ... + bool isPOI = poiDetector.IsPOI(dir, barIndex); + bool isBullishPOI = isPOI && + IsXBullish(dir); + bool isBearishPOI = isPOI && + IsXBearish(dir); + if (isPOI) + { + // + // Print("isPOI: ", ToXString(dir)); + // DebugBreak(); + } + + // + // Breakout POI ... + bool isBreakoutPOI = poiDetector.IsBreakoutPOI(dir, barIndex); + bool isBullishBreakoutPOI = isBreakoutPOI && + IsXBullish(dir); + bool isBearishBreakoutPOI = isBreakoutPOI && + IsXBearish(dir); + if (isBreakoutPOI) + { + // + // Print("isBreakoutPOI: ", ToXString(dir)); + // DebugBreak(); + } + + // + // Reversal POI ... + bool isReversalPOI = poiDetector.IsReversalPOI(dir, barIndex); + bool isBullishReversalPOI = isReversalPOI && + IsXBullish(dir); + bool isBearishReversalPOI = isReversalPOI && + IsXBearish(dir); + if (isReversalPOI) + { + // // + // Print("isReversalPOI: ", ToXString(dir)); + // DebugBreak(); + } + + // + // Continuation POI ... + bool isContinuationPOI = poiDetector.IsContinuationPOI(dir, barIndex); + bool isBullishContinuationPOI = isContinuationPOI && IsXBullish(dir); - bool isBearishBreakoutPOI = isBreakoutPOI && + bool isBearishContinuationPOI = isContinuationPOI && IsXBearish(dir); - if (isBreakoutPOI) - { - // - // Print("isBreakoutPOI: ", ToXString(dir)); - // DebugBreak(); - } - + if (isContinuationPOI) + { // - // Reversal POI ... - bool isReversalPOI = poiDetector.IsReversalPOI(dir, barIndex); - bool isBullishReversalPOI = isReversalPOI && - IsXBullish(dir); - bool isBearishReversalPOI = isReversalPOI && - IsXBearish(dir); - if (isReversalPOI) - { - // // - // Print("isReversalPOI: ", ToXString(dir)); - // DebugBreak(); - } + // Print("isContinuationPOI: ", ToXString(dir)); + // DebugBreak(); + } + // + // Exhaustion POI ... + bool isExhaustionPOI = poiDetector.IsExhaustionPOI(dir, barIndex); + bool isBullishExhaustionPOI = isExhaustionPOI && + IsXBullish(dir); + bool isBearishExhaustionPOI = isExhaustionPOI && + IsXBearish(dir); + if (isExhaustionPOI) + { // - // Continuation POI ... - bool isContinuationPOI = poiDetector.IsContinuationPOI(dir, barIndex); - bool isBullishContinuationPOI = isContinuationPOI && - IsXBullish(dir); - bool isBearishContinuationPOI = isContinuationPOI && - IsXBearish(dir); - if (isContinuationPOI) - { - // - // Print("isContinuationPOI: ", ToXString(dir)); - // DebugBreak(); - } + // Print("isExhaustionPOI: ", ToXString(dir)); + // DebugBreak(); + } - // - // Exhaustion POI ... - bool isExhaustionPOI = poiDetector.IsExhaustionPOI(dir, barIndex); - bool isBullishExhaustionPOI = isExhaustionPOI && + // + // TrendExhausted POI ... + bool isTrendExhaustedPOI = poiDetector.IsTrendExhaustedPOI(dir, barIndex); + bool isBullishTrendExhaustedPOI = isTrendExhaustedPOI && IsXBullish(dir); - bool isBearishExhaustionPOI = isExhaustionPOI && + bool isBearishTrendExhaustedPOI = isTrendExhaustedPOI && IsXBearish(dir); - if (isExhaustionPOI) - { - // - // Print("isExhaustionPOI: ", ToXString(dir)); - // DebugBreak(); - } - + if (isTrendExhaustedPOI) + { // - // TrendExhausted POI ... - bool isTrendExhaustedPOI = poiDetector.IsTrendExhaustedPOI(dir, barIndex); - bool isBullishTrendExhaustedPOI = isTrendExhaustedPOI && - IsXBullish(dir); - bool isBearishTrendExhaustedPOI = isTrendExhaustedPOI && - IsXBearish(dir); - if (isTrendExhaustedPOI) - { - // - Print("isTrendExhaustedPOI: ", ToXString(dir)); - DebugBreak(); - } - + Print("isTrendExhaustedPOI: ", ToXString(dir)); + DebugBreak(); + } /** * Check Bar Has Signal Based on Strategy 2 ... @@ -725,10 +722,10 @@ * @return ( bool ) */ bool Strategy2HasSignal( - XOHCL &bar, - XBoxZone &zone, - XTarget &targets[], - ENUM_X_DIRECTION &dir // + XOHCL & bar, + XBoxZone & zone, + XTarget & targets[], + ENUM_X_DIRECTION & dir // ) { // @@ -785,10 +782,10 @@ * @return ( bool ) */ bool Strategy3HasSignal( - XOHCL &bar, - XBoxZone &zone, - XTarget &targets[], - ENUM_X_DIRECTION &dir // + XOHCL & bar, + XBoxZone & zone, + XTarget & targets[], + ENUM_X_DIRECTION & dir // ) { // @@ -842,10 +839,10 @@ * @return ( bool ) */ bool Strategy4HasSignal( - XOHCL &bar, - XBoxZone &zone, - XTarget &targets[], - ENUM_X_DIRECTION &dir // + XOHCL & bar, + XBoxZone & zone, + XTarget & targets[], + ENUM_X_DIRECTION & dir // ) { // @@ -900,10 +897,10 @@ * @return ( bool ) */ bool Strategy5HasSignal( - XOHCL &bar, - XBoxZone &zone, - XTarget &targets[], - ENUM_X_DIRECTION &dir // + XOHCL & bar, + XBoxZone & zone, + XTarget & targets[], + ENUM_X_DIRECTION & dir // ) { // @@ -961,3 +958,377 @@ // return result; } + + /// + // + // + /// + + result = + isBullish + ? // entry > iBar.low && + entry < iBar.high + // && + // iBar.GetLowShadow() > iBar.GetHighShadow() + : // entry < iBar.high && + entry > iBar.low + // && + // iBar.GetHighShadow() > iBar.GetLowShadow() + ; + + /// + /// + + /** + * Check Bar Has Signal Based on Strategy 1 ... + * POI ... + * + * @param bar: XOHCL, reference to Bar ... + * @param zone: XBoxZone, reference to holds affected zone ... + * @param targets: XTarget, reference to detected Signal's Targets collections ... + * @param dir: ENUM_X_DIRECTION, detected Signal's direction ... + * + * @return ( bool ) + */ + bool Strategy1HasSignal( + XOHCL & bar, + XBoxZone & zone, + XTarget & targets[], + ENUM_X_DIRECTION & dir // + ) + { + // + bool result = false; + + // + zone.Clean(); + XClean(targets); + dir = X_DIRECTION_NONE; + + // + result = bar.IsValid(); + if (!result) + { + return result; + } + + // + int barIndex = bar.Index() + 1; + + // + // Retrieve Base Conditions ... + bool isBullish = IsBullishPOILongEntry(barIndex); + bool isBearish = IsBearishPOIShortEntry(barIndex); + + // + // Validate Conditions ... + result = isBullish || isBearish; + if (!result) + { + return result; + } + + // + XOHCL iBar; + result = iBar.Init(bar.symbol, bar.period, barIndex); + if (!result) + { + return result; + } + + // + // Do Validation and Filtering Market Structure if required ... + + // + // Validate near Support / Resistance Zones ... + bool validateNearSupRes = true; + if (result && validateNearSupRes) + { + // + // Configs ... + int loopback = 100; + int validationLength = 7; + double nearThreshold = 5; + int validationRetests = 0; + int validationLoopback = 100; + double validationThreshold = 5; + + // + // Filling Zones ... + XBoxZone zones[]; + if (isBullish) + { + // + // Detect Supports ... + poiDetector.DetectSupports( + zones, + barIndex, + loopback, + true, + validationLength, // Validation Length ... + validationRetests, // Min Retest ... + validationThreshold, // Retest Threshold ... + validationLoopback, // Retest Loopback ... + symbol, + period // + ); + } + else if (isBearish) + { + // + // Detect Resistances ... + poiDetector.DetectResistances( + zones, + barIndex, + loopback, + true, + validationLength, // Validation Length ... + validationRetests, // Min Retest ... + validationThreshold, // Retest Threshold ... + validationLoopback, // Retest Loopback ... + symbol, + period // + ); + } + + // + if (HasChild(zones)) + { + // + XPOIDrawConfig iConfig; + iConfig.Default(); + + // + poiDrawer.DrawZones(zones, iConfig); + iConfig.Clean(); + DebugBreak(); + } + + // + // Check Has Nearest ... + int nearIDX = -1; + result = poiDetector.HasNearZone( + nearIDX, + bar.close, + nearThreshold, + zones // + ); + + // + // Validate ... + if (!result) + { + // + isBullish = false; + isBearish = false; + } + } + + // + // Validate by ATR Rising/Falling ... + bool validateByATRRaisFalling = false; + if (result && validateByATRRaisFalling) + { + // + // Bullish: + // - ATR Lower Rising ... + // - ATR Over ATR Ma ... + // Bearsih: + // - ATR Upper Falling ... + // - ATR Over ATR Ma ... + + // + isBullish = + isBullish && + // kiHelper.GetATR(barIndex) > kiHelper.GetATRSmoothed(barIndex) && + kiHelper.GetKILower(barIndex) > kiHelper.GetKILower(barIndex + 1); + isBearish = + isBearish && + // kiHelper.GetATR(barIndex) > kiHelper.GetATRSmoothed(barIndex) && + kiHelper.GetKIUpper(barIndex) < kiHelper.GetKIUpper(barIndex + 1); + result = isBullish || isBearish; + + // + if (!result) + { + // + isBullish = false; + isBearish = false; + } + } + + // + // Validate by RSI ... + bool validatebyRSI = false; + if (result && validatebyRSI) + { + // + // Bullish: + // - Not in Over Baught; + // - Rising; + // Bearish : + // - Not in Over Sold; + // - Falling; + + // + isBullish = + isBullish && + !kiParser.IsRSIOverbought(barIndex) && + kiHelper.GetRSI(barIndex) > kiHelper.GetRSI(barIndex + 1); + isBearish = + isBearish && + !kiParser.IsRSIOversold(barIndex) && + kiHelper.GetRSI(barIndex) < kiHelper.GetRSI(barIndex + 1); + result = isBullish || isBearish; + + // + if (!result) + { + // + isBullish = false; + isBearish = false; + } + } + + // + // Validate by iBar Pattern ... + // in this Strategy we have PinBar or SignalKeyBar ... + bool validateByBarPatterns = false; + if (result && validateByBarPatterns) + { + // + // Pin ... + bool isPinBar = poiDetector.IsPinnedBar( + iBar, + dir // + ); + bool isPinBarBullish = + isPinBar && + IsXBullish(dir); + bool isPinBarBearish = + isPinBar && + IsXBearish(dir); + + // + // Engulfe ... + bool isEngulfed = poiDetector.IsEngulfedBar( + iBar, + dir // + ); + bool isEngulfedBullish = + isEngulfed && + IsXBullish(dir); + bool isEngulfedBearish = + isEngulfed && + IsXBearish(dir); + + // + // Signal Key Bar ... + bool isSignalKeyBar = poiDetector.IsSignalKeyBarPattern( + iBar, + dir // + ); + bool isSignalKeyBarBullish = + isSignalKeyBar && + IsXBullish(dir); + bool isSignalKeyBarBearish = + isSignalKeyBar && + IsXBearish(dir); + + // + isBullish = + isBullish && + (isEngulfedBullish); + isBearish = + isBearish && + (isEngulfedBearish); + + // // + // isBullish = + // isBullish && + // (isPinBarBullish || + // isEngulfedBullish || + // isSignalKeyBarBullish); + // isBearish = + // isBearish && + // (isPinBarBearish || + // isEngulfedBearish || + // isSignalKeyBarBearish); + + // + result = isBullish || isBearish; + + // + if (!result) + { + // + isBullish = false; + isBearish = false; + } + } + + // + // Check and Prepare Direction ... + dir = + isBullish + ? X_DIRECTION_BULLISH + : isBearish ? X_DIRECTION_BEARISH + : X_DIRECTION_NONE; + result = HasDirection(dir); + if (!result) + { + // + iBar.Clean(); + return result; + } + + // + // Prepare Zone ... + double entry = GetEntry(iBar.symbol, dir); + if (result) + { + // + double upper = isBullish + ? entry + : iBar.high; + double lower = isBullish + ? iBar.low + : entry; + datetime to = bar.time; + datetime from = iBar.BeforeOn(); + result = zone.Init( + iBar.symbol, + iBar.period, + upper, + lower, + from, + to, + dir, + "XS1" // + ); + if (result) + { + // + XPOIDrawConfig iConfig; + iConfig.Default(); + + // + poiDrawer.DrawZone(zone, iConfig); + + // + // DebugBreak(); + } + } + + // + iBar.Clean(); + + // + result = + result && + zone.IsValid() && + HasDirection(dir); + + // + return result; + } diff --git a/Documents/Diagrams/MQL5.X121XKI.Board.kanban b/Documents/Diagrams/MQL5.X121XKI.Board.kanban index 11c11f02..3f349bdc 100644 --- a/Documents/Diagrams/MQL5.X121XKI.Board.kanban +++ b/Documents/Diagrams/MQL5.X121XKI.Board.kanban @@ -13,7 +13,33 @@ { "id": "6f8db3d6-fcaa-4522-bee5-0e3e38c96e73", "title": "Doing", - "cards": [] + "cards": [ + { + "id": "f8eb6951-f337-40da-9b98-e468f77709fd", + "listId": "6f8db3d6-fcaa-4522-bee5-0e3e38c96e73", + "title": "implementing Signallers Has Strategy Functions ...", + "description": "Fill Signal Strategies\n", + "labels": [], + "checkboxes": [ + { + "id": "832b1c6e-8219-48ed-a897-45251f444cb1", + "title": "Strategy 1", + "checked": false + }, + { + "id": "ca4683e7-14f0-4dde-86a2-16ea71e08a48", + "title": "Add more Validations on Entries in Strategy 1;", + "checked": false + }, + { + "id": "bd3c09a7-1fbf-45f9-bcf7-ec0f71d1be24", + "title": "adding support Validate by Support and Resistances Zones; on Strategy 1; ", + "checked": false + } + ], + "comments": [] + } + ] }, { "id": "c6b07a7f-d2e7-4f67-a5a9-0d93cd8bf981", diff --git a/Libraries/x-saherelm.x-trade.lib.mq5 b/Libraries/x-saherelm.x-trade.lib.mq5 index db5da321..57e740cf 100644 --- a/Libraries/x-saherelm.x-trade.lib.mq5 +++ b/Libraries/x-saherelm.x-trade.lib.mq5 @@ -4688,7 +4688,8 @@ bool IsProviderFilterPassed( // return !IsValid(provider) ? true - : provider == item.provider; + : provider == item.provider || + Contains(provider, item.provider); } // diff --git a/X121XKIEA/Classes/x-saherelm.x121.xki.signaller.class.mq5 b/X121XKIEA/Classes/x-saherelm.x121.xki.signaller.class.mq5 index b39a2526..77dd61d2 100644 --- a/X121XKIEA/Classes/x-saherelm.x121.xki.signaller.class.mq5 +++ b/X121XKIEA/Classes/x-saherelm.x121.xki.signaller.class.mq5 @@ -27,6 +27,7 @@ #include "../Classes/x-saherelm.x121.xki.parser.class.mq5" #include "../Classes/x-saherelm.x121.xki.x-poi.detector.class.mq5" #include "../Classes/x-saherelm.x121.xki.x-poi.drawer.class.mq5" +#include "../Libraries/x-saherelm.x121.xki.lib.mq5" // // Implementation ... @@ -380,6 +381,10 @@ class XCX121XKIStrategy1Signaller : public XCX121XKIBaseSignaller sl, // Provided Price for SL ... 0 // Specified Risk in Point .... ); + if (has) + { + iSignal.provider += "_" + iZone.type; + } } // @@ -436,6 +441,7 @@ class XCX121XKIStrategy1Signaller : public XCX121XKIBaseSignaller double points10 = 0; double points50 = 0; double points100 = 0; + string provider = NULL; int samePVValidation = 5; bool isPeakOverLast = false; bool isValeUnderLast = false; @@ -449,10 +455,31 @@ class XCX121XKIStrategy1Signaller : public XCX121XKIBaseSignaller points100 = 100 * positions[i].GetPointsValue(); // - // Near to TP Guard ... - has = positions[i].profit > 0; + // Check Provided By Strategy 1 ... + provider = positions[i].provider; + StringReplace( + provider, + name, + "" // + ); + has = Contains(ToXString(X121_XKI_STRATEGY_1), positions[i].provider); if (has) { + // + // Now we Check Exit ... + // if (positions[i].IsLong()) + // { + // has = ExitBullishPOILong(); + // } + // else if (positions[i].IsShort()) + // { + // has = ExitBearishPOIShort(); + // } + + // // + // if (has) + // { + // } } } @@ -564,7 +591,7 @@ class XCX121XKIStrategy1Signaller : public XCX121XKIBaseSignaller if (signaller1HasSignal) { // - provider += "1"; + provider += ToXString(X121_XKI_STRATEGY_1); // if (!zone.IsValid()) @@ -597,7 +624,7 @@ class XCX121XKIStrategy1Signaller : public XCX121XKIBaseSignaller if (signaller2HasSignal) { // - provider += "2"; + provider += ToXString(X121_XKI_STRATEGY_2); // if (!zone.IsValid()) @@ -630,7 +657,7 @@ class XCX121XKIStrategy1Signaller : public XCX121XKIBaseSignaller if (signaller3HasSignal) { // - provider += "3"; + provider += ToXString(X121_XKI_STRATEGY_3); // if (!zone.IsValid()) @@ -663,7 +690,7 @@ class XCX121XKIStrategy1Signaller : public XCX121XKIBaseSignaller if (signaller4HasSignal) { // - provider += "4"; + provider += ToXString(X121_XKI_STRATEGY_4); // if (!zone.IsValid()) @@ -696,7 +723,7 @@ class XCX121XKIStrategy1Signaller : public XCX121XKIBaseSignaller if (signaller5HasSignal) { // - provider += "5"; + provider += ToXString(X121_XKI_STRATEGY_5); // if (!zone.IsValid()) @@ -729,7 +756,7 @@ class XCX121XKIStrategy1Signaller : public XCX121XKIBaseSignaller if (signaller6HasSignal) { // - provider += "6"; + provider += ToXString(X121_XKI_STRATEGY_6); // if (!zone.IsValid()) @@ -870,6 +897,10 @@ class XCX121XKIStrategy1Signaller : public XCX121XKIBaseSignaller // Summarize Result ... result = zone.IsValid() && HasDirection(dir); + if (result) + { + zone.type = "" + provider; + } // // Cleanup ... @@ -944,6 +975,314 @@ class XCX121XKIStrategy1Signaller : public XCX121XKIBaseSignaller // int barIndex = bar.Index() + 1; + // + // Retrieve Base Conditions ... + bool isBullish = IsBullishPOILongEntry(barIndex); + bool isBearish = IsBearishPOIShortEntry(barIndex); + + // + // Validate Conditions ... + result = isBullish || isBearish; + if (!result) + { + return result; + } + + // + XOHCL iBar; + result = iBar.Init(bar.symbol, bar.period, barIndex); + if (!result) + { + return result; + } + + // + // Do Validation and Filtering Market Structure if required ... + + // + // Validate near Support / Resistance Zones ... + bool validateNearSupRes = true; + if (result && validateNearSupRes) + { + // + // Configs ... + int loopback = 100; + int validationLength = 7; + double nearThreshold = 5; + int validationRetests = 0; + int validationLoopback = 100; + double validationThreshold = 5; + + // + // Filling Zones ... + XBoxZone zones[]; + if (isBullish) + { + // + // Detect Supports ... + poiDetector.DetectSupports( + zones, + barIndex, + loopback, + true, + validationLength, // Validation Length ... + validationRetests, // Min Retest ... + validationThreshold, // Retest Threshold ... + validationLoopback, // Retest Loopback ... + symbol, + period // + ); + } + else if (isBearish) + { + // + // Detect Resistances ... + poiDetector.DetectResistances( + zones, + barIndex, + loopback, + true, + validationLength, // Validation Length ... + validationRetests, // Min Retest ... + validationThreshold, // Retest Threshold ... + validationLoopback, // Retest Loopback ... + symbol, + period // + ); + } + + // + if (HasChild(zones)) + { + // + XPOIDrawConfig iConfig; + iConfig.Default(); + + // + poiDrawer.DrawZones(zones, iConfig); + iConfig.Clean(); + // DebugBreak(); + } + + // + // Check Has Nearest ... + int nearIDX = -1; + result = poiDetector.HasNearZone( + nearIDX, + bar.close, + nearThreshold, + zones // + ); + + // + // Validate ... + if (!result) + { + // + isBullish = false; + isBearish = false; + } + } + + // + // Validate by ATR Rising/Falling ... + bool validateByATRRaisFalling = true; + if (result && validateByATRRaisFalling) + { + // + // Bullish: + // - ATR Lower Rising ... + // - ATR Over ATR Ma ... + // Bearsih: + // - ATR Upper Falling ... + // - ATR Over ATR Ma ... + + // + isBullish = + isBullish && + // kiHelper.GetATR(barIndex) > kiHelper.GetATRSmoothed(barIndex) && + kiHelper.GetKILower(barIndex) > kiHelper.GetKILower(barIndex + 1); + isBearish = + isBearish && + // kiHelper.GetATR(barIndex) > kiHelper.GetATRSmoothed(barIndex) && + kiHelper.GetKIUpper(barIndex) < kiHelper.GetKIUpper(barIndex + 1); + result = isBullish || isBearish; + + // + if (!result) + { + // + isBullish = false; + isBearish = false; + } + } + + // + // Validate by RSI ... + bool validatebyRSI = false; + if (result && validatebyRSI) + { + // + // Bullish: + // - Not in Over Baught; + // - Rising; + // Bearish : + // - Not in Over Sold; + // - Falling; + + // + isBullish = + isBullish && + !kiParser.IsRSIOverbought(barIndex) && + kiHelper.GetRSI(barIndex) > kiHelper.GetRSI(barIndex + 1); + isBearish = + isBearish && + !kiParser.IsRSIOversold(barIndex) && + kiHelper.GetRSI(barIndex) < kiHelper.GetRSI(barIndex + 1); + result = isBullish || isBearish; + + // + if (!result) + { + // + isBullish = false; + isBearish = false; + } + } + + // + // Validate by iBar Pattern ... + // in this Strategy we have PinBar or SignalKeyBar ... + bool validateByBarPatterns = false; + if (result && validateByBarPatterns) + { + // + // Pin ... + bool isPinBar = poiDetector.IsPinnedBar( + iBar, + dir // + ); + bool isPinBarBullish = + isPinBar && + IsXBullish(dir); + bool isPinBarBearish = + isPinBar && + IsXBearish(dir); + + // + // Engulfe ... + bool isEngulfed = poiDetector.IsEngulfedBar( + iBar, + dir // + ); + bool isEngulfedBullish = + isEngulfed && + IsXBullish(dir); + bool isEngulfedBearish = + isEngulfed && + IsXBearish(dir); + + // + // Signal Key Bar ... + bool isSignalKeyBar = poiDetector.IsSignalKeyBarPattern( + iBar, + dir // + ); + bool isSignalKeyBarBullish = + isSignalKeyBar && + IsXBullish(dir); + bool isSignalKeyBarBearish = + isSignalKeyBar && + IsXBearish(dir); + + // + isBullish = + isBullish && + (isEngulfedBullish); + isBearish = + isBearish && + (isEngulfedBearish); + + // // + // isBullish = + // isBullish && + // (isPinBarBullish || + // isEngulfedBullish || + // isSignalKeyBarBullish); + // isBearish = + // isBearish && + // (isPinBarBearish || + // isEngulfedBearish || + // isSignalKeyBarBearish); + + // + result = isBullish || isBearish; + + // + if (!result) + { + // + isBullish = false; + isBearish = false; + } + } + + // + // Check and Prepare Direction ... + dir = + isBullish + ? X_DIRECTION_BULLISH + : isBearish ? X_DIRECTION_BEARISH + : X_DIRECTION_NONE; + result = HasDirection(dir); + if (!result) + { + // + iBar.Clean(); + return result; + } + + // + // Prepare Zone ... + double entry = GetEntry(iBar.symbol, dir); + if (result) + { + // + double upper = isBullish + ? entry + : iBar.high; + double lower = isBullish + ? iBar.low + : entry; + datetime to = bar.time; + datetime from = iBar.BeforeOn(); + result = zone.Init( + iBar.symbol, + iBar.period, + upper, + lower, + from, + to, + dir, + "XS1" // + ); + if (result) + { + // + XPOIDrawConfig iConfig; + iConfig.Default(); + + // + poiDrawer.DrawZone(zone, iConfig); + + // + // DebugBreak(); + } + } + + // + iBar.Clean(); + // result = result && @@ -985,6 +1324,38 @@ class XCX121XKIStrategy1Signaller : public XCX121XKIBaseSignaller // int barIndex = bar.Index() + 1; + // + // Retrieve Base Conditions ... + bool isBullish = false; + bool isBearish = false; + + // + // Validate Conditions ... + result = isBullish || isBearish; + if (!result) + { + return result; + } + + // + // Do Validation and Filtering Market Structure if required ... + + // + // Check and Prepare Direction ... + dir = + isBullish + ? X_DIRECTION_BULLISH + : isBearish ? X_DIRECTION_BEARISH + : X_DIRECTION_NONE; + result = HasDirection(dir); + if (!result) + { + return result; + } + + // + // Prepare Zone ... + // result = result && @@ -1026,6 +1397,38 @@ class XCX121XKIStrategy1Signaller : public XCX121XKIBaseSignaller // int barIndex = bar.Index() + 1; + // + // Retrieve Base Conditions ... + bool isBullish = false; + bool isBearish = false; + + // + // Validate Conditions ... + result = isBullish || isBearish; + if (!result) + { + return result; + } + + // + // Do Validation and Filtering Market Structure if required ... + + // + // Check and Prepare Direction ... + dir = + isBullish + ? X_DIRECTION_BULLISH + : isBearish ? X_DIRECTION_BEARISH + : X_DIRECTION_NONE; + result = HasDirection(dir); + if (!result) + { + return result; + } + + // + // Prepare Zone ... + // result = result && @@ -1067,6 +1470,38 @@ class XCX121XKIStrategy1Signaller : public XCX121XKIBaseSignaller // int barIndex = bar.Index() + 1; + // + // Retrieve Base Conditions ... + bool isBullish = false; + bool isBearish = false; + + // + // Validate Conditions ... + result = isBullish || isBearish; + if (!result) + { + return result; + } + + // + // Do Validation and Filtering Market Structure if required ... + + // + // Check and Prepare Direction ... + dir = + isBullish + ? X_DIRECTION_BULLISH + : isBearish ? X_DIRECTION_BEARISH + : X_DIRECTION_NONE; + result = HasDirection(dir); + if (!result) + { + return result; + } + + // + // Prepare Zone ... + // result = result && @@ -1108,6 +1543,38 @@ class XCX121XKIStrategy1Signaller : public XCX121XKIBaseSignaller // int barIndex = bar.Index() + 1; + // + // Retrieve Base Conditions ... + bool isBullish = false; + bool isBearish = false; + + // + // Validate Conditions ... + result = isBullish || isBearish; + if (!result) + { + return result; + } + + // + // Do Validation and Filtering Market Structure if required ... + + // + // Check and Prepare Direction ... + dir = + isBullish + ? X_DIRECTION_BULLISH + : isBearish ? X_DIRECTION_BEARISH + : X_DIRECTION_NONE; + result = HasDirection(dir); + if (!result) + { + return result; + } + + // + // Prepare Zone ... + // result = result && @@ -1149,6 +1616,38 @@ class XCX121XKIStrategy1Signaller : public XCX121XKIBaseSignaller // int barIndex = bar.Index() + 1; + // + // Retrieve Base Conditions ... + bool isBullish = false; + bool isBearish = false; + + // + // Validate Conditions ... + result = isBullish || isBearish; + if (!result) + { + return result; + } + + // + // Do Validation and Filtering Market Structure if required ... + + // + // Check and Prepare Direction ... + dir = + isBullish + ? X_DIRECTION_BULLISH + : isBearish ? X_DIRECTION_BEARISH + : X_DIRECTION_NONE; + result = HasDirection(dir); + if (!result) + { + return result; + } + + // + // Prepare Zone ... + // result = result && diff --git a/X121XKIEA/Classes/x-saherelm.x121.xki.x-poi.detector.class.mq5 b/X121XKIEA/Classes/x-saherelm.x121.xki.x-poi.detector.class.mq5 index cf72cad2..f30d0ee3 100644 --- a/X121XKIEA/Classes/x-saherelm.x121.xki.x-poi.detector.class.mq5 +++ b/X121XKIEA/Classes/x-saherelm.x121.xki.x-poi.detector.class.mq5 @@ -438,7 +438,6 @@ class XCX121XKIPOIDetector : public XCMarketPatternDetector // // Add candlestick confirmation ... XOHCL bar; - ENUM_X_DIRECTION dir; result = result && bar.Init(symbol, period, barIndex); if (!result) @@ -448,8 +447,10 @@ class XCX121XKIPOIDetector : public XCMarketPatternDetector // result = result && - IsPinnedBar(bar, dir) && - IsXBullish(dir); + HasCandlestickDirection( + bar, + X_DIRECTION_BULLISH // + ); // bar.Clean(); @@ -477,7 +478,6 @@ class XCX121XKIPOIDetector : public XCMarketPatternDetector // // Add candlestick confirmation ... XOHCL bar; - ENUM_X_DIRECTION dir; result = result && bar.Init(symbol, period, barIndex); if (!result) @@ -487,8 +487,10 @@ class XCX121XKIPOIDetector : public XCMarketPatternDetector // result = result && - IsPinnedBar(bar, dir) && - IsXBearish(dir); + HasCandlestickDirection( + bar, + X_DIRECTION_BEARISH // + ); // bar.Clean(); @@ -550,7 +552,6 @@ class XCX121XKIPOIDetector : public XCMarketPatternDetector // // Add candlestick confirmation ... XOHCL bar; - ENUM_X_DIRECTION dir; result = result && bar.Init(symbol, period, barIndex); if (!result) @@ -560,8 +561,10 @@ class XCX121XKIPOIDetector : public XCMarketPatternDetector // result = result && - IsMomentumBar(bar, dir) && - IsXBullish(dir); + HasCandlestickDirection( + bar, + X_DIRECTION_BULLISH // + ); // bar.Clean(); @@ -588,7 +591,6 @@ class XCX121XKIPOIDetector : public XCMarketPatternDetector // // Add candlestick confirmation ... XOHCL bar; - ENUM_X_DIRECTION dir; result = result && bar.Init(symbol, period, barIndex); if (!result) @@ -598,8 +600,10 @@ class XCX121XKIPOIDetector : public XCMarketPatternDetector // result = result && - IsMomentumBar(bar, dir) && - IsXBearish(dir); + HasCandlestickDirection( + bar, + X_DIRECTION_BEARISH // + ); // bar.Clean(); @@ -1208,6 +1212,9 @@ class XCX121XKIPOIDetector : public XCMarketPatternDetector int loopback = 50, bool forceValidation = true, int validationLength = 7, + int minimumRetests = 2, + double retestThreshold = 10, + int retestLoopback = 100, string forSymbol = NULL, ENUM_TIMEFRAMES forPeriod = NULL // ) @@ -1284,6 +1291,8 @@ class XCX121XKIPOIDetector : public XCMarketPatternDetector tmpValue = tmpBar.FindLowest(validationLength, MODE_LOW); has = NotEmptyZero(tmpValue) && tmpValue == tmpBar.low; + + // if (has) { // @@ -1325,7 +1334,14 @@ class XCX121XKIPOIDetector : public XCMarketPatternDetector // Validate ... if (HasChild(zones) && forceValidation) { - ValidateZones(zones, barIndex); + // + ValidateZones( + zones, + barIndex, + minimumRetests, + retestThreshold, + retestLoopback // + ); } // @@ -1341,6 +1357,9 @@ class XCX121XKIPOIDetector : public XCMarketPatternDetector int loopback = 50, bool forceValidation = true, int validationLength = 7, + int minimumRetests = 2, + double retestThreshold = 10, + int retestLoopback = 100, string forSymbol = NULL, ENUM_TIMEFRAMES forPeriod = NULL // ) @@ -1458,7 +1477,14 @@ class XCX121XKIPOIDetector : public XCMarketPatternDetector // Validate ... if (HasChild(zones) && forceValidation) { - ValidateZones(zones, barIndex); + // + ValidateZones( + zones, + barIndex, + minimumRetests, + retestThreshold, + retestLoopback // + ); } // @@ -1471,6 +1497,9 @@ class XCX121XKIPOIDetector : public XCMarketPatternDetector void ValidateZones( XBoxZone &zones[], int barIndex = 0, + int minimumRetests = 2, + double retestThreshold = 10, + int retestLoopback = 100, ENUM_X_BOUNDARY_PRICE forPriceType = X_BOUNDARY_PRICE_UP_DOWN // ) { @@ -1478,9 +1507,7 @@ class XCX121XKIPOIDetector : public XCMarketPatternDetector bool has = false; // - barIndex = kiParser.NormalizeBarIndex(barIndex); - - // + // Validation ... has = HasChild(zones) && IsXValid(forPriceType); if (!has) @@ -1488,6 +1515,13 @@ class XCX121XKIPOIDetector : public XCMarketPatternDetector return; } + // + // Normalizetion ... + barIndex = kiParser.NormalizeBarIndex(barIndex); + minimumRetests = NormalizeInt(minimumRetests, 0); + retestLoopback = NormalizeInt(retestLoopback, 50); + retestThreshold = NormalizeDouble(retestThreshold, 5, 10); + // XOHCL tmpBar; XBoxZone tmp; @@ -1498,6 +1532,17 @@ class XCX121XKIPOIDetector : public XCMarketPatternDetector // tmp = zones[i]; + // + if (minimumRetests > 0) + { + // + int retests = CounteZoneTouches(tmp, retestThreshold, retestLoopback); + if (retests < minimumRetests) + { + continue; + } + } + // // Validate Zone ... has = false; @@ -1575,7 +1620,10 @@ class XCX121XKIPOIDetector : public XCMarketPatternDetector ENUM_TIMEFRAMES forPeriod = NULL, int loopback = 50, int minorValidation = 7, - int majorValidation = 14 // + int majorValidation = 14, + int minimumRetests = 2, + double retestThreshold = 10, + int retestLoopback = 100 // ) { // @@ -1618,6 +1666,9 @@ class XCX121XKIPOIDetector : public XCMarketPatternDetector loopback, true, // Force Validation ... minorValidation, + minimumRetests, + retestThreshold, + retestLoopback, forSymbol, forPeriod // ); @@ -1644,6 +1695,9 @@ class XCX121XKIPOIDetector : public XCMarketPatternDetector loopback, true, // Force Validation ... minorValidation, + minimumRetests, + retestThreshold, + retestLoopback, forSymbol, forPeriod // ); @@ -1677,6 +1731,9 @@ class XCX121XKIPOIDetector : public XCMarketPatternDetector loopback, true, // Force Validation ... majorValidation, + minimumRetests, + retestThreshold, + retestLoopback, forSymbol, forPeriod // ); @@ -1703,6 +1760,9 @@ class XCX121XKIPOIDetector : public XCMarketPatternDetector loopback, true, // Force Validation ... majorValidation, + minimumRetests, + retestThreshold, + retestLoopback, forSymbol, forPeriod // ); @@ -1726,6 +1786,121 @@ class XCX121XKIPOIDetector : public XCMarketPatternDetector XClean(tmpSupports); XClean(tmpResistances); } + + int CounteZoneTouches( + XBoxZone &zone, + double threshold = 10, + int loopback = 100 // + ) + { + // + int result = 0; + + // + // Normalize ... + loopback = NormalizeInt(loopback, 50); + threshold = NormalizeDouble(threshold, 10); + + // + if (!zone.IsValid()) + { + return result; + } + + // + XOHCL tmpBar; + int start = zone.ToIndex(); + bool isUpperTouched = false; + bool isLowerTouched = false; + double points = GetPoints(zone.symbol); + double distance = points * threshold; + int end = MathMin(start + loopback, zone.FromIndex()); + for (int i = start; i < end; i++) + { + // + if (tmpBar.Init(zone.symbol, zone.period, i)) + { + // + isUpperTouched = MathAbs(tmpBar.high - zone.upper) <= distance; + isLowerTouched = MathAbs(tmpBar.low - zone.lower) <= distance; + + // + if ( + (zone.IsBullish() && + (isLowerTouched || + MathAbs(tmpBar.close - zone.lower) <= distance)) || + (zone.IsBearish() && + (isUpperTouched || + MathAbs(tmpBar.close - zone.upper) <= distance))) + { + // + result++; + Add( + tmpBar.time, + zone.tests // + ); + } + + // + tmpBar.Clean(); + } + } + + // + tmpBar.Clean(); + + // + return result; + } + + bool HasNearZone( + int &index, + double price, + double threshold, + XBoxZone &zones[] // + ) + { + // + bool result = false; + + // + index = -1; + + // + // Validate ... + result = HasChild(zones) && + NotEmptyZero(price) && + NotEmptyZero(threshold) && + price > 0 && + threshold > 0; + if (!result) + { + return result; + } + + // + double points = GetPoints(zones[0].symbol); + double distance = points * threshold; + for (int i = 0; i < ArraySize(zones); i++) + { + // + // Check Price Distance by Upper ... + result = price >= zones[i].lower - distance && + price <= zones[i].upper + distance; + if (result) + { + // + index = i; + break; + } + } + + // + result = IsValidIndex(index); + + // + return result; + } // #endregion // diff --git a/X121XKIEA/Libraries/x-saherelm.x121.xki.lib.mq5 b/X121XKIEA/Libraries/x-saherelm.x121.xki.lib.mq5 new file mode 100644 index 00000000..afb85cfe --- /dev/null +++ b/X121XKIEA/Libraries/x-saherelm.x121.xki.lib.mq5 @@ -0,0 +1,124 @@ +/////////////////////////////////////////////////////// +// +// SaherElm IT Center MQL5 Library +// ------------------------------------------------- +// Name: XCX121XKIEALib ... +// Description: X121XKI Library ... +// +// +// Maintainer: +// ------------ +// Hadi Khazaee Asl (hadi_khazaee_asl@yahoo.com) +// +////////////////////////////////////////////////////// +// +// Global Properties ... +#property library +#property copyright "Copyright 2023, SaherElm IT Center" +#property link "https://saherelm.ir" +#property version "1.00" +#property description "SaherElm X121XKIEA Library" +#property strict + +// +// Imports ... +#include "../../Libraries/x-saherelm.common.lib.mq5" + +// +// Enums ... + +// #region XKIStrategies ... +enum X121XKIStrategies +{ + X121_XKI_STRATEGY_UNKNOWN = 0, + X121_XKI_STRATEGY_1 = 1, + X121_XKI_STRATEGY_2 = 2, + X121_XKI_STRATEGY_3 = 3, + X121_XKI_STRATEGY_4 = 4, + X121_XKI_STRATEGY_5 = 5, + X121_XKI_STRATEGY_6 = 6, +}; +bool IsXValid(X121XKIStrategies value) +{ + return value != X121_XKI_STRATEGY_UNKNOWN; +} +string ToXString(X121XKIStrategies value) +{ + // + string result = NULL; + + // + if (IsXValid(value)) + { + // + switch (value) + { + // + case X121_XKI_STRATEGY_1: + result = "1"; + break; + // + case X121_XKI_STRATEGY_2: + result = "2"; + break; + // + case X121_XKI_STRATEGY_3: + result = "3"; + break; + // + case X121_XKI_STRATEGY_4: + result = "4"; + break; + // + case X121_XKI_STRATEGY_5: + result = "5"; + break; + // + case X121_XKI_STRATEGY_6: + result = "6"; + break; + } + } + + // + return result; +} +X121XKIStrategies ToX121XKIStrategy(string value) +{ + // + X121XKIStrategies result = X121_XKI_STRATEGY_UNKNOWN; + + // + if (IsXValid(value)) + { + // + if (value == ToXString(X121_XKI_STRATEGY_1)) + { + result = X121_XKI_STRATEGY_1; + } + else if (value == ToXString(X121_XKI_STRATEGY_2)) + { + result = X121_XKI_STRATEGY_2; + } + else if (value == ToXString(X121_XKI_STRATEGY_3)) + { + result = X121_XKI_STRATEGY_3; + } + else if (value == ToXString(X121_XKI_STRATEGY_4)) + { + result = X121_XKI_STRATEGY_4; + } + else if (value == ToXString(X121_XKI_STRATEGY_5)) + { + result = X121_XKI_STRATEGY_5; + } + else if (value == ToXString(X121_XKI_STRATEGY_6)) + { + result = X121_XKI_STRATEGY_6; + } + } + + // + return result; +} +// #endregion \ No newline at end of file