diff --git a/Libraries/x-saherelm.x-poi.lib.mq5 b/Libraries/x-saherelm.x-poi.lib.mq5 index 828b596f..9f617936 100644 --- a/Libraries/x-saherelm.x-poi.lib.mq5 +++ b/Libraries/x-saherelm.x-poi.lib.mq5 @@ -118,6 +118,12 @@ enum ENUM_XSESSION X_FRANKFORT, }; +enum ENUM_X_ZONE_EDGE +{ + X_ZONE_UPPER_EDGE, + X_ZONE_LOWER_EDGE +}; + // // Represent a Session Working Time ... struct XSession @@ -1472,7 +1478,6 @@ bool AddIfNotExists( bool result = false; // - int count = ArraySize(dest); result = source.IsValid(); if (!result) { @@ -1482,7 +1487,7 @@ bool AddIfNotExists( // int idx = FindIndex(source, dest); bool isExists = IsValidIndex(idx); - if (isExists) + if (!isExists) { // AddRef( @@ -1618,7 +1623,6 @@ bool AddIfNotExists( bool result = false; // - int count = ArraySize(dest); result = source.IsValid(); if (!result) { @@ -1628,7 +1632,7 @@ bool AddIfNotExists( // int idx = FindIndex(source, dest); bool isExists = IsValidIndex(idx); - if (isExists) + if (!isExists) { // AddRef( @@ -1644,6 +1648,117 @@ bool AddIfNotExists( return result; } +// + +/** + * Check if a Zone inside another one ... + * + * @param source: XZone instance ... + * @param dest: XZone instance ... + * @param edge: ENUM_X_ZONE_EDGE member, define inside edge of zone ... + * @param forceInside: Boolean, if set true means all edges of source must be inside dest ... + * + * @return ( bool ) + */ +bool IsInside( + XZone &source, + XZone &dest, + ENUM_X_ZONE_EDGE edge, + bool forceInside = true // +) +{ + // + bool result = false; + + // + result = source.IsValid() && + dest.IsValid(); + if (!result) + { + return result; + } + + // + bool isEdgePassed = + // + edge == X_ZONE_UPPER_EDGE + ? source.upper <= dest.upper + : source.lower >= dest.lower + // + ; + + // + bool isForcePassed = + // + forceInside + ? edge == X_ZONE_UPPER_EDGE + ? source.lower >= dest.lower + : source.upper <= dest.upper + : edge == X_ZONE_UPPER_EDGE + ? true + : true + // + ; + + // + result = isEdgePassed && + isForcePassed; + + // + return result; +} +bool IsInside( + XOHCL &source, + XZone &dest, + ENUM_X_ZONE_EDGE edge, + bool forceInside = true // +) +{ + // + bool result = false; + + // + result = source.IsValid() && + dest.IsValid(); + if (!result) + { + return result; + } + + // + XZone iSource; + double upper = + edge == X_ZONE_UPPER_EDGE + ? source.high + : source.GetDown(); + double lower = + edge == X_ZONE_UPPER_EDGE + ? source.GetUp() + : source.low; + result = iSource.Init( + upper, + lower, + "XOHCL", + source.time, + TimeCurrent() // + ); + if (!result) + { + return result; + } + + // + result = IsInside( + iSource, + dest, + edge, + forceInside // + ); + + // + return result; +} + // // State Extensions ... diff --git a/X121SMCEA/Strategy/x-121.smc.strategy.class.mq5 b/X121SMCEA/Strategy/x-121.smc.strategy.class.mq5 index e213b48b..d6d114a3 100644 Binary files a/X121SMCEA/Strategy/x-121.smc.strategy.class.mq5 and b/X121SMCEA/Strategy/x-121.smc.strategy.class.mq5 differ