diff --git a/X121SMCEA/Libraries/x-121.smc.lib.mq5 b/X121SMCEA/Libraries/x-121.smc.lib.mq5 index 4eae0397..0fbbfb9c 100644 --- a/X121SMCEA/Libraries/x-121.smc.lib.mq5 +++ b/X121SMCEA/Libraries/x-121.smc.lib.mq5 @@ -801,6 +801,204 @@ struct X121SMCCycleState return IsValidSize(CountBearishFVGs()); } + // + bool GetOldestOB( + XCOrderBlock *&orderBlock // + ) + { + // + bool result = false; + + // + orderBlock = NULL; + + // + bool hasBullishOB = HasBullishOBs(); + bool hasBearishOB = HasBearishOBs(); + result = hasBullishOB || + hasBearishOB; + if (!result) + { + return result; + } + + // + int iBullOBIDX = -1; + bool iHasBullOB = false; + XCOrderBlock *iBullOB = NULL; + if (hasBullishOB) + { + // + XCZone* iZones[]; + ToZone( + bullishOBs, + iZones // + ); + + // + iBullOBIDX = GetOldest( + iZones // + ); + + // + iHasBullOB = IsValidIndex(iBullOBIDX); + if (iHasBullOB) + { + iBullOB = bullishOBs[iBullOBIDX]; + } + } + + // + int iBearOBIDX = -1; + bool iHasBearOB = false; + XCOrderBlock *iBearOB = NULL; + if (hasBearishOB) + { + // + XCZone* iZones[]; + ToZone( + bearishOBs, + iZones // + ); + + // + iBearOBIDX = GetOldest( + iZones // + ); + + // + iHasBearOB = IsValidIndex(iBearOBIDX); + if (iHasBearOB) + { + iBearOB = bearishOBs[iBearOBIDX]; + } + } + + // + if (iHasBullOB) + { + orderBlock = iBullOB; + } + + // + if (iHasBearOB) + { + // + bool canSet = orderBlock == NULL || + orderBlock.From() > iBearOB.From(); + if (canSet) + { + orderBlock = iBearOB; + } + } + + // + result = orderBlock != NULL && + orderBlock.IsValid(); + + // + return result; + } + + // + bool GetYoungestOB( + XCOrderBlock *&orderBlock // + ) + { + // + bool result = false; + + // + orderBlock = NULL; + + // + bool hasBullishOB = HasBullishOBs(); + bool hasBearishOB = HasBearishOBs(); + result = hasBullishOB || + hasBearishOB; + if (!result) + { + return result; + } + + // + int iBullOBIDX = -1; + bool iHasBullOB = false; + XCOrderBlock *iBullOB = NULL; + if (hasBullishOB) + { + // + XCZone* iZones[]; + ToZone( + bullishOBs, + iZones // + ); + + // + iBullOBIDX = GetYoungest( + iZones // + ); + + // + iHasBullOB = IsValidIndex(iBullOBIDX); + if (iHasBullOB) + { + iBullOB = bullishOBs[iBullOBIDX]; + } + } + + // + int iBearOBIDX = -1; + bool iHasBearOB = false; + XCOrderBlock *iBearOB = NULL; + if (hasBearishOB) + { + // + XCZone* iZones[]; + ToZone( + bearishOBs, + iZones // + ); + + // + iBearOBIDX = GetYoungest( + iZones // + ); + + // + iHasBearOB = IsValidIndex(iBearOBIDX); + if (iHasBearOB) + { + iBearOB = bearishOBs[iBearOBIDX]; + } + } + + // + if (iHasBullOB) + { + orderBlock = iBullOB; + } + + // + if (iHasBearOB) + { + // + bool canSet = orderBlock == NULL || + orderBlock.From() < iBearOB.From(); + if (canSet) + { + orderBlock = iBearOB; + } + } + + // + result = orderBlock != NULL && + orderBlock.IsValid(); + + // + return result; + } + // }; diff --git a/X121SMCEA/Signals/x-121.smc.xhkpv.signal.lib.mq5 b/X121SMCEA/Signals/x-121.smc.xhkpv.signal.lib.mq5 index 2597085b..0864e7ae 100644 --- a/X121SMCEA/Signals/x-121.smc.xhkpv.signal.lib.mq5 +++ b/X121SMCEA/Signals/x-121.smc.xhkpv.signal.lib.mq5 @@ -700,9 +700,11 @@ bool DetectX121SMCXHKPVSignalSetup( // double upper = 0; double lower = 0; + bool hasYoungestOB = false; bool isPriceOBValid = false; bool isBullishHappens = false; bool isBearishHappens = false; + XCOrderBlock *youngestOB = NULL; bool hasPriceBox = conditions.priceBox.IsValid(); bool hasState = visionCycleHelper.GetCycleState(conditions.state); @@ -730,10 +732,21 @@ bool DetectX121SMCXHKPVSignalSetup( upper = conditions.priceOB.Upper(); lower = conditions.priceOB.Lower(); + // + hasYoungestOB = conditions.state.GetYoungestOB(youngestOB); + // // Here We Can Validate Box by Same Cycles Peaks and Vales ... bool isBullish = IsBullish(conditions.priceBox.dir); + // + bool isPriceBoxSameAsOB = + // + conditions.priceBox.upper <= conditions.priceOB.Upper() && + conditions.priceBox.lower >= conditions.priceOB.Lower() + // + ; + // int cIDX = 1; @@ -760,6 +773,7 @@ bool DetectX121SMCXHKPVSignalSetup( isPriceOBValid = // hasPriceBox && + isPriceBoxSameAsOB && (isBullish ? isSameCycleVales : isSameCyclePeaks) @@ -1369,29 +1383,61 @@ bool DetectX121SMCXHKPVSignalSetup( if (!result) { // - bool canReset = - // - hasPriceBox && - conditions.isPriceOBActed && - conditions.isPriceOBBreaked && - // - ( - // - IsBullish(conditions.priceBox.dir) - ? pBar.high < lower && - cBar.high < lower - : pBar.low > upper && - cBar.low > upper - // - ) - // - ; - if (canReset) + if (hasPriceBox && hasYoungestOB) { // - Print("canReset"); + X121SMCCycleState iState; + bool iHasState = visionCycleHelper.GetCycleState(iState); + if (iHasState) + { + // + // Retrieve Youngest Order Blocks ... + XCOrderBlock *iYOB; + bool iHasYoungestOB = iState.GetYoungestOB(iYOB); + if (iHasYoungestOB) + { + // + // Compare it with current Condition PriceOB ... + bool isSame = + // + conditions.priceOB.Upper() == iYOB.Upper() && + conditions.priceOB.Lower() == iYOB.Lower() && + conditions.priceOB.From() == iYOB.From() && + conditions.priceOB.Type() == iYOB.Type() + // + ; + if (!isSame) + { + conditions.Clean(); + } + } + } } + // + // bool canReset = + // // + // hasPriceBox && + // conditions.isPriceOBActed && + // conditions.isPriceOBBreaked && + // // + // ( + // // + // IsBullish(conditions.priceBox.dir) + // ? pBar.high < lower && + // cBar.high < lower + // : pBar.low > upper && + // cBar.low > upper + // // + // ) + // // + // ; + // if (canReset) + // { + // // + // Print("canReset"); + // } + // // Cleanup Arrays ... ArrayFree(triggerPoiEvents); diff --git a/X121SMCEA/Strategy/x-121.smc.strategy.class.mq5 b/X121SMCEA/Strategy/x-121.smc.strategy.class.mq5 index c786c4d0..752690aa 100644 --- a/X121SMCEA/Strategy/x-121.smc.strategy.class.mq5 +++ b/X121SMCEA/Strategy/x-121.smc.strategy.class.mq5 @@ -1251,10 +1251,10 @@ class XCX121SMCStrategy : public XCX121SMCBaseStrategy // // XCHE ... - x121Inputs.xcheInputs.showLE1 = showAll || true; - x121Inputs.xcheInputs.showLE2 = showAll || true; - x121Inputs.xcheInputs.showSE1 = showAll || true; - x121Inputs.xcheInputs.showSE2 = showAll || true; + x121Inputs.xcheInputs.showLE1 = showAll || false; + x121Inputs.xcheInputs.showLE2 = showAll || false; + x121Inputs.xcheInputs.showSE1 = showAll || false; + x121Inputs.xcheInputs.showSE2 = showAll || false; // // XDON ...