From 70a373802d49ca4140ba509f44a8034a45034551 Mon Sep 17 00:00:00 2001 From: Hadi Khazaee Asl Date: Wed, 20 Nov 2024 13:12:19 +0330 Subject: [PATCH] Last ... --- .../x-121.smc.test.strategy.class.mq5 | 189 +++++++++++++----- 1 file changed, 143 insertions(+), 46 deletions(-) diff --git a/X121SMCEA/Strategy/x-121.smc.test.strategy.class.mq5 b/X121SMCEA/Strategy/x-121.smc.test.strategy.class.mq5 index f988b8b6..1c7c1d5d 100644 --- a/X121SMCEA/Strategy/x-121.smc.test.strategy.class.mq5 +++ b/X121SMCEA/Strategy/x-121.smc.test.strategy.class.mq5 @@ -120,6 +120,9 @@ class XCX121SMCTestStrategy : public XCX121SMCBaseStrategy double pip = GetPipPrice(_symbol); double pip2 = 2 * pip; + // + datetime cTime = TimeCurrent(); + // int zIndex = 0; int cIndex = zIndex + 1; @@ -184,9 +187,6 @@ class XCX121SMCTestStrategy : public XCX121SMCBaseStrategy return result; } - // - RedrawOrderFlow(); - // XPVPivot lastPivot; result = GetLastItem( @@ -197,6 +197,113 @@ class XCX121SMCTestStrategy : public XCX121SMCBaseStrategy { return result; } + bool isBullishOrderFlow = IsBullish(mOrderFlowDir); + bool isBearishOrderFlow = IsBearish(mOrderFlowDir); + double pivotMid = lastPivot.CalculateMid(); + // RedrawOrderFlow(); + + // + // Calculate Liquidity Percent ... + double bullishLiquidityPercent = lastPivot + .CalculateLiquidityPercent(X_DIRECTION_BULLISH); + double bearishLiquidityPercent = lastPivot + .CalculateLiquidityPercent(X_DIRECTION_BEARISH); + + // + // Detect Order Blocks ... + int obsCount = 0; + + // + // Find Bullish Order Block ... + XCOrderBlock *bullishOB = NULL; + obsCount = lastPivot.state.CountBullishOrderBlocks(); + if (IsValidSize(obsCount)) + { + // + for (int i = 0; i < obsCount; i++) + { + // + XCOrderBlock *iOB = lastPivot.state.bullishOrderBlocks[i]; + + // + XOHCL iBar; + bool hasBar = iOB.FillBar(iBar); + bool isPeriodSame = hasBar && + iBar.period == _period; + + // + if (iOB.Upper() <= pivotMid && + iOB.Lower() >= lastPivot.lower) + { + // + bullishOB = iOB; + break; + } + } + } + bool hasBullishOB = bullishOB != NULL; + if (hasBullishOB) + { + // + bullishOB.To(cTime); + XCBullishOrderBlockObject *iObj; + bool isCreated = mPOIDrawer.CreateBullishOrderBlock( + bullishOB, + iObj // + ); + if (isCreated) + { + AddObjectIfNotExists(iObj); + } + } + + // + // Find Bearish Order Block ... + XCOrderBlock *bearishOB = NULL; + obsCount = lastPivot.state.CountBearishOrderBlocks(); + if (IsValidSize(obsCount)) + { + // + for (int i = 0; i < obsCount; i++) + { + // + XCOrderBlock *iOB = lastPivot.state.bearishOrderBlocks[i]; + + // + XOHCL iBar; + bool hasBar = iOB.FillBar(iBar); + bool isPeriodSame = hasBar && + iBar.period == _period; + + // + if (iOB.Lower() >= pivotMid && + iOB.Upper() <= lastPivot.upper) + { + // + bearishOB = iOB; + break; + } + } + } + bool hasBearishOB = bearishOB != NULL; + if (hasBearishOB) + { + // + bearishOB.To(cTime); + XCBearishOrderBlockObject *iObj; + bool isCreated = mPOIDrawer.CreateBearishOrderBlock( + bearishOB, + iObj // + ); + if (isCreated) + { + AddObjectIfNotExists(iObj); + } + } + + // + // Find an Order Block ... + bool isBearishOrderBlockRejected = false; // // Check Candlestick PullBacks ... @@ -411,16 +518,6 @@ class XCX121SMCTestStrategy : public XCX121SMCBaseStrategy // // Prepare Areas ... double bid = GetBid(_symbol); - bool isBullish = IsBullish(mOrderFlowDir); - bool isBearish = IsBearish(mOrderFlowDir); - double pivotMid = lastPivot.CalculateMid(); - - // - // Calculate Liquidity Percent ... - double bullishLiquidityPercent = lastPivot - .CalculateLiquidityPercent(X_DIRECTION_BULLISH); - double bearishLiquidityPercent = lastPivot - .CalculateLiquidityPercent(X_DIRECTION_BEARISH); // bool isInDiscount = @@ -439,21 +536,21 @@ class XCX121SMCTestStrategy : public XCX121SMCBaseStrategy // For Bullish Order Flow ... // if Price Breakes Lower to Down, means Change of Charcter Happens ... bool isCHOCHHappens = - isBullish ? bid < lastPivot.lower - pip - : bid > lastPivot.upper + pip; + isBullishOrderFlow ? bid < lastPivot.lower - pip + : bid > lastPivot.upper + pip; // // For Bullish Order Flow ... // if Price Breakes Upper to Up, means Breake of Structure Happens ... bool isBOSHappens = - isBullish ? bid > lastPivot.upper + pip - : bid < lastPivot.lower - pip; + isBullishOrderFlow ? bid > lastPivot.upper + pip + : bid < lastPivot.lower - pip; // if (isBOSHappens) { // - RedrawOrderFlow(); + // RedrawOrderFlow(); } // @@ -465,27 +562,27 @@ class XCX121SMCTestStrategy : public XCX121SMCBaseStrategy return result; } - // - hasLong = - // - is3Bullish && - // isInDiscount && - isSarBullish && - // hasBullishPullback && - bullishLiquidityPercent > 30 - // - ; + // // + // hasLong = + // // + // is3Bullish && + // // isInDiscount && + // isSarBullish // && + // // hasBullishPullback && + // // bullishLiquidityPercent > 30 + // // + // ; - // - hasShort = - // - is3Bearish && - // isInPremium && - isSarBearish && - // hasBearishPullback && - bearishLiquidityPercent > 30 - // - ; + // // + // hasShort = + // // + // is3Bearish && + // // isInPremium && + // isSarBearish // && + // // hasBearishPullback && + // // bearishLiquidityPercent > 30 + // // + // ; // result = hasLong || @@ -589,7 +686,7 @@ class XCX121SMCTestStrategy : public XCX121SMCBaseStrategy // int cIndex = 1; - + // if (entry <= 0 || !conditions.IsValid() || @@ -776,11 +873,11 @@ class XCX121SMCTestStrategy : public XCX121SMCBaseStrategy // // Check Order Flow Direction ... - result = mOrderFlowDir != X_DIRECTION_NONE; - if (!result) - { - return result; - } + // result = mOrderFlowDir != X_DIRECTION_NONE; + // if (!result) + // { + // return result; + // } // return result; @@ -1952,8 +2049,8 @@ class XCX121SMCTestStrategy : public XCX121SMCBaseStrategy false, // Draw ResistanceZones .. false, // Draw SupplyZones .. false, // Draw DemandZones .. - false, // Draw BullishOrderBlocks .. - false, // Draw BearishOrderBlocks .. + true, // Draw BullishOrderBlocks .. + true, // Draw BearishOrderBlocks .. false, // Draw BullishFairValueGaps .. false, // Draw BearishFairValueGaps .. false, // Draw BullishRejectionBars ..