diff --git a/X121SMCEA/Strategy/x-121.smc.strategy.class.mq5 b/X121SMCEA/Strategy/x-121.smc.strategy.class.mq5 index a0736902..2135cee0 100644 --- a/X121SMCEA/Strategy/x-121.smc.strategy.class.mq5 +++ b/X121SMCEA/Strategy/x-121.smc.strategy.class.mq5 @@ -479,21 +479,21 @@ class XCX121SMCStrategy : public XSCBaseAlert // bool isSoImportantLong = - conditions.demandZone.IsValid() && - conditions.bullishFVG.IsValid() && - conditions.bullishOrderBlock.IsValid(); + iConditions.demandZone.IsValid() && + iConditions.bullishFVG.IsValid() && + iConditions.bullishOrderBlock.IsValid(); // bool isImportantLong = - conditions.demandZone.IsValid() && - (conditions.bullishFVG.IsValid() || - conditions.bullishOrderBlock.IsValid()); + iConditions.demandZone.IsValid() && + (iConditions.bullishFVG.IsValid() || + iConditions.bullishOrderBlock.IsValid()); // bool isRiskyLong = - conditions.demandZone.IsValid() && - (conditions.bullishFVG.IsValid() || - conditions.bullishOrderBlock.IsValid()); + iConditions.demandZone.IsValid() && + (iConditions.bullishFVG.IsValid() || + iConditions.bullishOrderBlock.IsValid()); // bool hasLongConditions = isSoImportantLong || @@ -511,10 +511,50 @@ class XCX121SMCStrategy : public XSCBaseAlert // - [] Momentum Bar; // - removeIDX = i; - DrawConditions(conditions); - Print("hasLongConditions"); - // break; + // Price Must Breakout the Upper of Demand ... + bool isBreakout = + // + cBar.IsBullish() && + zBar.low > conditions.demandZone.upper && + cBar.high > conditions.demandZone.upper && + cBar.close > conditions.demandZone.upper && + (cBar.open < conditions.demandZone.upper || + cBar.low < conditions.demandZone.upper) + // + ; + + // + // Price Must have Bullish Trend and Momentum on Ticks ... + bool isTicksBullishMomentum = + IsTicksBullish() && + IsTicksHasMomentum(); + + // + bool hasMpmentumBar = + // + cBar. + // + ; + + // + hasLongConditions = + hasLongConditions && + // + isBreakout && + isTicksBullishMomentum + // + ; + + // + if (hasLongConditions) + { + // + removeIDX = i; + conditions = iConditions; + DrawConditions(iConditions); + Print("hasLongConditions"); + break; + } } // @@ -522,21 +562,21 @@ class XCX121SMCStrategy : public XSCBaseAlert // bool isSoImportantShort = - conditions.supplyZone.IsValid() && - conditions.bearishFVG.IsValid() && - conditions.bearishOrderBlock.IsValid(); + iConditions.supplyZone.IsValid() && + iConditions.bearishFVG.IsValid() && + iConditions.bearishOrderBlock.IsValid(); // bool isImportantShort = - conditions.supplyZone.IsValid() && - (conditions.bearishFVG.IsValid() || - conditions.bearishOrderBlock.IsValid()); + iConditions.supplyZone.IsValid() && + (iConditions.bearishFVG.IsValid() || + iConditions.bearishOrderBlock.IsValid()); // bool isRiskyShort = - conditions.supplyZone.IsValid() && - (!conditions.bearishFVG.IsValid() && - !conditions.bearishOrderBlock.IsValid()); + iConditions.supplyZone.IsValid() && + (!iConditions.bearishFVG.IsValid() && + !iConditions.bearishOrderBlock.IsValid()); // bool hasShortConditions = isSoImportantShort || @@ -552,12 +592,15 @@ class XCX121SMCStrategy : public XSCBaseAlert // - [] Engulf; // - [] Rejection Bar; // - [] Momentum Bar; - + + // + // removeIDX = i; - DrawConditions(conditions); + conditions = iConditions; + DrawConditions(iConditions); Print("hasShortConditions"); - // break; + break; } // @@ -572,7 +615,8 @@ class XCX121SMCStrategy : public XSCBaseAlert ArrayRemove( mConditions, removeIDX, - 1); + 1 // + ); } // @@ -613,8 +657,8 @@ class XCX121SMCStrategy : public XSCBaseAlert double mVolume; // Static Volume Per Trades ... // - MqlTick mLastTick; // Last Issued Tick ... XTick mTicks[]; // Hold Ticks Data ... + MqlTick mLastTick; // Last Issued Tick ... /** * Cleanup Ticks Size ... @@ -675,6 +719,180 @@ class XCX121SMCStrategy : public XSCBaseAlert ); } + /** + * Calculate Ticks Param for Looping through Last n items ... + * + * @param start: Integer Reference to Start ... + * @param end: Integer Reference to End ... + * @param numOfLastTicks: Integer Max Number of Required N Last Ticks ... + */ + void CalculateTicksParams( + int &start, + int &end, + int numOfLastTicks = 5 // + ) + { + // + start = -1; + end = -1; + + // + int count = ArraySize(mTicks); + + // + start = count - numOfLastTicks; + if (start < 0) + { + start = 0; + } + + // + end = start + numOfLastTicks; + if (end > count) + { + end = count; + } + } + + /** + * Check Ticks is Bullish or not ... + * + * @return ( bool ) + */ + bool IsTicksBullish() + { + // + bool result = false; + + // + int start = -1; + int end = -1; + CalculateTicksParams( + start, + end // + ); + result = IsValidIndex(start) && + IsValidIndex(end); + if (!result) + { + return result; + } + + // + result = true; + for (int i = start + 1; i < end; i++) + { + // + XTick iTick = mTicks[i]; + XTick prevTick = mTicks[i - 1]; + + // + bool isBullish = iTick.bid >= prevTick.bid; + result = result && isBullish; + if (!result) + { + break; + } + } + + // + return result; + } + + /** + * Check Ticks is Bearish or not ... + * + * @return ( bool ) + */ + bool IsTicksBearish() + { + // + bool result = false; + + // + int start = -1; + int end = -1; + CalculateTicksParams( + start, + end // + ); + result = IsValidIndex(start) && + IsValidIndex(end); + if (!result) + { + return result; + } + + // + result = true; + for (int i = start + 1; i < end; i++) + { + // + XTick iTick = mTicks[i]; + XTick prevTick = mTicks[i - 1]; + + // + bool isBearish = iTick.bid <= prevTick.bid; + result = result && isBearish; + if (!result) + { + break; + } + } + + // + return result; + } + + /** + * Check Ticks Has Momentum or not ... + * + * @return ( bool ) + */ + bool IsTicksHasMomentum() + { + // + bool result = false; + + // + int start = -1; + int end = -1; + CalculateTicksParams( + start, + end // + ); + result = IsValidIndex(start) && + IsValidIndex(end); + if (!result) + { + return result; + } + + // + result = true; + int lastDiff = 0; + for (int i = start + 1; i < end; i++) + { + // + XTick iTick = mTicks[i]; + XTick prevTick = mTicks[i - 1]; + + // + int timeDiff = MathAbs((int)iTick.time - (int)prevTick.bid); + result = result && timeDiff >= lastDiff; + if (!result) + { + break; + } + + // + lastDiff = timeDiff; + } + + // + return result; + } + // XBarTracker mBarTracker; // Strategy Time Tracker ...