diff --git a/Classes/x-saherelm.x-poi.drawer.class.mq5 b/Classes/x-saherelm.x-poi.drawer.class.mq5 index eb1e40e2..2cd03112 100644 --- a/Classes/x-saherelm.x-poi.drawer.class.mq5 +++ b/Classes/x-saherelm.x-poi.drawer.class.mq5 @@ -4584,11 +4584,7 @@ class XCPOIDrawer : public XCBase XCBaseObject *&objects[], // bool drawOrderBlock = true, - bool drawFairValueGap = true, - bool drawSupplyZones = true, - bool drawDemandZones = true, - bool drawSupportZones = true, - bool drawResistanceZones = true, + bool drawFairValueGaps = true, // bool drawOBStartedBar = true, bool drawOBActivatedBar = true, @@ -4699,41 +4695,46 @@ class XCPOIDrawer : public XCBase // // Fair Value Gap ... - has = item.HasFVG(); + has = item.HasFVGs(); if (has && - drawFairValueGap) + drawFairValueGaps) { // - Clean(tmpObjects); - count = DrawFairValueGap( - item.fvg, - tmpObjects, - drawFVGStartedBar, - drawFVGActivatedBar, - drawFVGBreakedBar, - drawFVGWorkedBar, - widthFVGStartedBar, - clrFVGStartedBar, - styleFVGStartedBar, - widthFVGActivatedBar, - clrFVGActivatedBar, - styleFVGActivatedBar, - widthFVGBreakedBar, - clrFVGBreakedBar, - styleFVGBreakedBar, - widthFVGWorkedBar, - clrFVGWorkedBar, - styleFVGWorkedBar // - ); - has = IsValidSize(count); - if (has) + count = item.CountFVGs(); + for (int i = 0; i < count; i++) { // - Copy( + Clean(tmpObjects); + int fvgsCount = DrawFairValueGap( + item.fvgs[i], tmpObjects, - objects, - false // + drawFVGStartedBar, + drawFVGActivatedBar, + drawFVGBreakedBar, + drawFVGWorkedBar, + widthFVGStartedBar, + clrFVGStartedBar, + styleFVGStartedBar, + widthFVGActivatedBar, + clrFVGActivatedBar, + styleFVGActivatedBar, + widthFVGBreakedBar, + clrFVGBreakedBar, + styleFVGBreakedBar, + widthFVGWorkedBar, + clrFVGWorkedBar, + styleFVGWorkedBar // ); + has = IsValidSize(fvgsCount); + if (has) + { + // + Copy( + tmpObjects, + objects, + false // + ); + } } } diff --git a/Documents/BKP/1.mq5 b/Documents/BKP/1.mq5 index 66a5551e..e15df54d 100644 --- a/Documents/BKP/1.mq5 +++ b/Documents/BKP/1.mq5 @@ -7862,4 +7862,2699 @@ bool DetectSelectedZoneSLCandidates( //////////////////////////////////////////////////////// - \ No newline at end of file + + // + // Waiting Zone Detection ... + // XPOIState iState = mtfState; + + // + // Detect Waiting Zones ... + + // // + // // Using Order Blocks ... + // if (mUseOrderBlocks) + // { + // // + // has = iState.HasOrderBlocks(); + // if (has) + // { + // // + // XCOrderBlock *obs[]; + // count = iState.FilterOrderBlocks( + // obs, + // period, + // XZONE_STATE_PASSED, + // false, + // XZONE_STATE_FAILED, + // false, + // XZONE_STATE_FAILED, + // false, + // XZONE_STATE_IGNORED, + // false // + // ); + + // // + // has = IsValidSize(count); + // if (has) + // { + // // + // ToBox( + // obs, + // waitingBoxes // + // ); + // } + + // // + // Clean(obs); + // } + // } + + // // + // // Using Fair Value Gaps ... + // if (mUseFairValueGaps) + // { + // // + // has = iState.HasFairValueGaps(); + // if (has) + // { + // // + // XBoxZone boxes[]; + // XCFVG *fvgs[]; + // count = iState.FilterFairValueGaps( + // fvgs, + // period, + // XZONE_STATE_PASSED, + // false, + // XZONE_STATE_FAILED, + // false, + // XZONE_STATE_FAILED, + // false, + // XZONE_STATE_IGNORED, + // false // + // ); + + // // + // has = IsValidSize(count); + // if (has) + // { + // // + // count = ToBox( + // fvgs, + // boxes // + // ); + + // // + // for (int i = 0; i < count; i++) + // { + // // + // XBoxZone iBox = boxes[i]; + + // // + // int idx = FindIndex( + // iBox, + // waitingBoxes // + // ); + // has = !IsValidIndex(idx); + // if (has) + // { + // // + // AddRef( + // iBox, + // waitingBoxes // + // ); + // } + + // // + // iBox.Clean(); + // } + // } + + // // + // Clean(fvgs); + // Clean(boxes); + // } + // } + + // + // Cleaning State ... + // iState.Clean(); + + /////////////////////////////////////////////////////////////////////////// + + + // + // Waiting Box Detected ... + bool hasWaitingBoxes = hasWorkingZone && + workingZone.HasWaitingBoxes(); + if (hasWaitingBoxes) + { + // + XOHCL zBar; + XOHCL cBar; + XOHCL pBar; + int count = 0; + int idx = -1; + bool has = false; + + // + bool isInited = zBar.Init( + symbol, + period, + zIndex // + ); + isInited = + isInited && + zBar.GetPreviousBar(cBar); + isInited = + isInited && + cBar.GetPreviousBar(pBar); + + // + count = workingZone.CountWaitingBoxes(); + for (int i = 0; i < count; i++) + { + // + XBoxZone iBox = workingZone.waitingBoxes[i]; + ENUM_X_DIRECTION iDir = iBox.dir; + bool isBullish = IsBullish(iDir); + + // + // Check Price Rejection ... + + // + bool hasBullishFiboPressure = + decisionCycleHelper + .mBarAnalyser + .HasFiboPressure( + cBar, + X_DIRECTION_BULLISH, + X_FIBO_LEVEL_382 // + ); + + // + bool hasBearishFiboPressure = + decisionCycleHelper + .mBarAnalyser + .HasFiboPressure( + cBar, + X_DIRECTION_BEARISH, + X_FIBO_LEVEL_382 // + ); + + // + // Bullish Rejection ... + bool isBullishRejected = + // + isInited && + isBullish && + cBar.low < pBar.low && + zBar.low > iBox.upper && + cBar.low <= iBox.upper && + zBar.open > iBox.upper && + hasBullishFiboPressure && + cBar.GetLowShadow() > pBar.GetLowShadow() + // + ; + + // + // Bearish Rejection ... + bool isBearishhRejected = + // + isInited && + !isBullish && + cBar.high > pBar.high && + zBar.open < iBox.lower && + zBar.high < iBox.lower && + hasBearishFiboPressure && + cBar.high >= iBox.lower && + cBar.GetHighShadow() > pBar.GetHighShadow() + // + ; + + // + has = isBullishRejected || + isBearishhRejected; + if (has) + { + // + idx = i; + signalBox = iBox; + hasSignalBox = has; + signalBox.to = cTime; + signalBoxDir = iBox.dir; + isSignalBoxReversal = false; + provider = X121SMC_XWZ_PROVIDER_ACTIVATED_ZONE; + } + + // + iBox.Clean(); + } + + // + // Remove Signal Box from Waiting Boxes of + // Working Zone ... + if (hasSignalBox) + { + // + if (IsValidIndex(idx)) + { + // + ArrayRemove( + workingZone.waitingBoxes, + idx, + 1 // + ); + } + } + + // + // Ignore Zone's Signals ... + hasSignalBox = false; + + // + // Cleanup Resources ... + + // + zBar.Clean(); + cBar.Clean(); + pBar.Clean(); + } + + // + // Check Conditions if Has Inside Boxes ... + bool hasInsideBoxes = hasWorkingZone && + workingZone.HasInsideBoxes(); + if (hasInsideBoxes) + { + } + + // + // Check Conditions if has Breaked Boxes ... + bool hasBreakedBoxes = hasWorkingZone && + workingZone.HasBreakedBoxes(); + if (hasBreakedBoxes) + { + } + + // + // Checking Other Conditions ... + if (!hasSignalBox) + { + // + // Senari A ... + // hasSignalBox = hasWorkingZone && + // workingZone.DetectSenarioASignalBox( + // signalBox, + // signalBoxDir, + // decisionXConditions, + // analyseXConditions, + // decisionCycleHelper, + // drawer, + // zIndex // + // ); + // if (hasSignalBox) + // { + // // + // signalBox.to = cTime; + // isSignalBoxReversal = false; + // provider = X121SMC_XWZ_PROVIDER_PV_ZONE; + // } + + // // + // // Validating Signal Box if Exists ... + // if (hasSignalBox) + // { + // // + // // Validate Signal Boxes using Inside Box ... + // if (hasInsideBoxes) + // { + // // + // int idx = -1; + // bool has = false; + + // // + // idx = + // IsBullish(signalBoxDir) + // ? GetLowest(workingZone.insideBoxes) + // : GetHighest(workingZone.insideBoxes); + // has = IsValidIndex(idx); + // if (has) + // { + // // + // hasSignalBox = + // signalBoxDir == workingZone.insideBoxes[idx].dir; + // } + // } + + // // + // // Validate Signal Box Using Overal Trend ... + // if (hasWorkingZoneOveralDirection) + // { + // // + // hasSignalBox = + // signalBoxDir == wzOveralDir; + // } + // } + } + +////////////////////////////////////////////////////////////////////////////////// + + + // + // + // + + // + // Supply Zones ... + has = HasSupplyZones(); + if (has) + { + // + int removeIDXs[]; + count = CountSupplyZones(); + for (int i = 0; i < count; i++) + { + // + XCSupplyZone *iZone = supplyZones[i]; + ENUM_X_DIRECTION iDir = X_DIRECTION_BEARISH; + + // + XBoxZone iBox; + bool hasBox = ToBox( + iBox, + iZone // + ); + if (!hasBox) + { + // + iBox.Clean(); + continue; + } + + // + XOHCL passedBar; + bool isBodyIn = false; + bool isBodyOut = false; + + // + // Check Activation ... + bool isActivated = iZone.IsActivated( + iDir, + passedBar, + isBodyIn, + true, + period // + ); + if (isActivated) + { + // + // AddRef( + // iBox, + // insideBoxes // + // ); + + // + Add( + i, + removeIDXs // + ); + + // + iBox.Clean(); + passedBar.Clean(); + continue; + } + + // + // Checking Breaked ... + bool isBreaked = iZone.IsBreaked( + iDir, + passedBar, + isBodyOut, + false, + true, + period // + ); + if (isBreaked) + { + // // + // AddRef( + // iBox, + // breakedBoxes // + // ); + + // + Add( + i, + removeIDXs // + ); + + // + iBox.Clean(); + passedBar.Clean(); + continue; + } + + // + passedBar.Clean(); + } + + // + count = ArraySize(removeIDXs); + has = IsValidSize(count); + if (has) + { + // + CleanupArray( + removeIDXs, + supplyZones // + ); + } + + // + Clean(removeIDXs); + } + + // + // Demand Zones ... + has = HasDemandZones(); + if (has) + { + // + int removeIDXs[]; + count = CountDemandZones(); + for (int i = 0; i < count; i++) + { + // + XCDemandZone *iZone = demandZones[i]; + ENUM_X_DIRECTION iDir = X_DIRECTION_BULLISH; + + // + XBoxZone iBox; + bool hasBox = ToBox( + iBox, + iZone // + ); + if (!hasBox) + { + // + iBox.Clean(); + continue; + } + + // + XOHCL passedBar; + bool isBodyIn = false; + bool isBodyOut = false; + + // + // Check Activation ... + bool isActivated = iZone.IsActivated( + iDir, + passedBar, + isBodyIn, + true, + period // + ); + if (isActivated) + { + // + // AddRef( + // iBox, + // insideBoxes // + // ); + + // + Add( + i, + removeIDXs // + ); + + // + iBox.Clean(); + passedBar.Clean(); + continue; + } + + // + // Checking Breaked ... + bool isBreaked = iZone.IsBreaked( + iDir, + passedBar, + isBodyOut, + false, + true, + period // + ); + if (isBreaked) + { + // // + // AddRef( + // iBox, + // breakedBoxes // + // ); + + // + Add( + i, + removeIDXs // + ); + + // + iBox.Clean(); + passedBar.Clean(); + continue; + } + + // + passedBar.Clean(); + } + + // + count = ArraySize(removeIDXs); + has = IsValidSize(count); + if (has) + { + // + CleanupArray( + removeIDXs, + demandZones // + ); + } + + // + Clean(removeIDXs); + } + + // + // Update Boxes ... + + // + // Waiting Boxes ... + has = HasWaitingBoxes(); + if (has) + { + // + int removeIDXs[]; + count = CountWaitingBoxes(); + for (int i = 0; i < count; i++) + { + // + XBoxZone iBox = waitingBoxes[i]; + ENUM_X_DIRECTION iDir = iBox.dir; + bool isBullish = IsBullish(iDir); + + // + bool isInside = + // + zBar.low < iBox.upper && + zBar.low > iBox.lower + // + ; + if (isInside) + { + // + AddRef( + iBox, + insideBoxes // + ); + + // + Add( + i, + removeIDXs // + ); + + // + iBox.Clean(); + break; + } + + // + bool isBreakedUpper = + // + cBar.low < iBox.upper && + cBar.low > iBox.lower && + zBar.low > iBox.upper + // + ; + + // + bool isBreakedLower = + // + cBar.high > iBox.lower && + cBar.high < iBox.upper && + zBar.high < iBox.lower + // + ; + + // + bool isBreaked = + (isBullish && + isBreakedLower) || + (!isBullish && + isBreakedUpper); + + // + if (isBreaked) + { + // + AddRef( + iBox, + breakedBoxes // + ); + + // + Add( + i, + removeIDXs // + ); + + // + iBox.Clean(); + break; + } + } + + // + count = ArraySize(removeIDXs); + has = IsValidSize(count); + if (has) + { + // + CleanupArray( + removeIDXs, + waitingBoxes // + ); + } + + // + Clean(removeIDXs); + } + + // + // Inside Boxes ... + has = HasInsideBoxes(); + if (has) + { + // + int removeIDXs[]; + count = CountInsideBoxes(); + for (int i = 0; i < count; i++) + { + // + XBoxZone iBox = insideBoxes[i]; + ENUM_X_DIRECTION iDir = iBox.dir; + bool isBullish = IsBullish(iDir); + + // + bool isBreakedUpper = + // + cBar.low < iBox.upper && + cBar.low > iBox.lower && + zBar.low > iBox.upper + // + ; + + // + bool isBreakedLower = + // + cBar.high > iBox.lower && + cBar.high < iBox.upper && + zBar.high < iBox.lower + // + ; + + // + bool isBreaked = + (isBullish && + isBreakedLower) || + (!isBullish && + isBreakedUpper); + + // + if (isBreaked) + { + // + AddRef( + iBox, + breakedBoxes // + ); + + // + Add( + i, + removeIDXs // + ); + + // + iBox.Clean(); + break; + } + } + + // + count = ArraySize(removeIDXs); + has = IsValidSize(count); + if (has) + { + // + CleanupArray( + removeIDXs, + insideBoxes // + ); + } + + // + Clean(removeIDXs); + } + + // + has = HasBreakedBoxes(); + if (has) + { + // + int removeIDXs[]; + count = CountBreakedBoxes(); + for (int i = 0; i < count; i++) + { + // + XBoxZone iBox = breakedBoxes[i]; + ENUM_X_DIRECTION iDir = iBox.dir; + bool isBullish = IsBullish(iDir); + + // + bool isInside = false; + + // + if (isInside) + { + // + AddRef( + iBox, + breakedInsideBoxes // + ); + + // + Add( + i, + removeIDXs // + ); + + // + iBox.Clean(); + break; + } + } + + // + count = ArraySize(removeIDXs); + has = IsValidSize(count); + if (has) + { + // + CleanupArray( + removeIDXs, + breakedBoxes // + ); + } + + // + Clean(removeIDXs); + } + + // + // Update Waiting Boxes ... + + // + XPOIState iState = mtfState; + + // + // Use Order Blocks ... + if (mUseOrderBlocks) + { + // + has = iState.HasOrderBlocks(); + if (has) + { + // + XCOrderBlock *obs[]; + count = iState.FilterOrderBlocks( + obs, + period, + XZONE_STATE_PASSED, + false, + XZONE_STATE_FAILED, + false, + XZONE_STATE_FAILED, + false, + XZONE_STATE_IGNORED, + false // + ); + + // + has = IsValidSize(count); + if (has) + { + // + // Try to Add new OBs into Waiting Zones ... + // if it's not exists ... + for (int i = 0; i < count; i++) + { + // + XBoxZone iBox; + bool hasBox = ToBox( + iBox, + obs[i] // + ); + if (!hasBox) + { + // + iBox.Clean(); + continue; + } + + // + // Check Index in Waiting Boxes ... + idx = FindIndex( + iBox, + waitingBoxes // + ); + has = !IsValidIndex(idx); + if (!has) + { + // + iBox.Clean(); + continue; + } + + // + // Check Index in Inside Boxes ... + idx = FindIndex( + iBox, + insideBoxes // + ); + has = !IsValidIndex(idx); + if (!has) + { + // + iBox.Clean(); + continue; + } + + // + // Check Index in Breaked Boxes ... + idx = FindIndex( + iBox, + breakedBoxes // + ); + has = !IsValidIndex(idx); + if (!has) + { + // + iBox.Clean(); + continue; + } + + // + AddRef( + iBox, + waitingBoxes // + ); + } + } + + // + Clean(obs); + } + } + + // + // Use Fair Value Gaps ... + if (mUseFairValueGaps) + { + // + has = iState.HasFairValueGaps(); + if (has) + { + // + XCFVG *fvgs[]; + count = iState.FilterFairValueGaps( + fvgs, + period, + XZONE_STATE_PASSED, + false, + XZONE_STATE_FAILED, + false, + XZONE_STATE_FAILED, + false, + XZONE_STATE_IGNORED, + false // + ); + + // + has = IsValidSize(count); + if (has) + { + // + for (int i = 0; i < count; i++) + { + // + XBoxZone iBox; + bool hasBox = ToBox( + iBox, + fvgs[i] // + ); + if (!hasBox) + { + // + iBox.Clean(); + continue; + } + + // + // Check Index in Waiting Boxes ... + idx = FindIndex( + iBox, + waitingBoxes // + ); + has = !IsValidIndex(idx); + if (!has) + { + // + iBox.Clean(); + continue; + } + + // + // Check Index in Inside Boxes ... + idx = FindIndex( + iBox, + insideBoxes // + ); + has = !IsValidIndex(idx); + if (!has) + { + // + iBox.Clean(); + continue; + } + + // + // Check Index in Breaked Boxes ... + idx = FindIndex( + iBox, + breakedBoxes // + ); + has = !IsValidIndex(idx); + if (!has) + { + // + iBox.Clean(); + continue; + } + + // + AddRef( + iBox, + waitingBoxes // + ); + + // + iBox.Clean(); + } + } + + // + Clean(fvgs); + } + } + + // + iState.Clean(); + +///////////////////////////////////////////////////////////////////////////// + + + // + // Update Working Zone ... + // workingZone.Update( + // zIndex, + // visionState, + // consolidationState, + // analyseState, + // decisionState // + // ); + +////////////////////////////////////////////////////////////////////////////////// + + + // + // + // + + // + // Supply Zones ... + if (drawSupplyZones) + { + // + has = HasSupplyZones(); + if (has) + { + // + count = CountSupplyZones(); + for (int i = 0; i < count; i++) + { + // + XCSupplyZoneObject *iObj; + isCreated = drawer.CreateSupplyZone( + supplyZones[i], + iObj // + ); + + // + if (isCreated) + { + mWorkingZoneObjects.Add(iObj); + } + } + } + } + + // + // Demand Zones ... + if (drawDemandZones) + { + // + has = HasDemandZones(); + if (has) + { + // + count = CountDemandZones(); + for (int i = 0; i < count; i++) + { + // + XCDemandZoneObject *iObj; + isCreated = drawer.CreateDemandZone( + demandZones[i], + iObj // + ); + + // + if (isCreated) + { + mWorkingZoneObjects.Add(iObj); + } + } + } + } + + // + // Support Zones ... + if (drawSupportZones) + { + // + has = HasSupportZones(); + if (has) + { + // + count = CountSupportZones(); + for (int i = 0; i < count; i++) + { + // + XCSupportZoneObject *iObj; + isCreated = drawer.CreateSupportZone( + supportZones[i], + iObj // + ); + + // + if (isCreated) + { + mWorkingZoneObjects.Add(iObj); + } + } + } + } + + // + // Resistance Zones ... + if (drawResistanceZones) + { + // + has = HasResistanceZones(); + if (has) + { + // + count = CountResistanceZones(); + for (int i = 0; i < count; i++) + { + // + XCResistanceZoneObject *iObj; + isCreated = drawer.CreateResistanceZone( + resistanceZones[i], + iObj // + ); + + // + if (isCreated) + { + mWorkingZoneObjects.Add(iObj); + } + } + } + } + + // + // + // + + // + // Waiting Boxes ... + if (drawWaitingBoxes) + { + // + has = HasWaitingBoxes(); + if (has) + { + // + count = CountWaitingBoxes(); + for (int i = 0; i < count; i++) + { + // + XBoxZone iBox = waitingBoxes[i]; + + // + XCBoxObject *iObj; + bool isCreated = drawer.DrawBox( + iBox, + iObj // + ); + + // + if (isCreated) + { + mWorkingZoneObjects.Add(iObj); + } + + // + iBox.Clean(); + } + } + } + + // + // Inside Boxes ... + if (drawInsideBoxes) + { + // + has = HasInsideBoxes(); + if (has) + { + } + } + + // + // Breaked Boxes ... + if (drawBreakedBoxes) + { + // + has = HasBreakedBoxes(); + if (has) + { + // + } + } + + // + // Breaked Inside Boxes ... + if (drawBreakedInsideBoxes) + { + // + has = HasBreakedInsideBoxes(); + if (has) + { + // + count = CountBreakedInsideBoxes(); + for (int i = 0; i < count; i++) + { + // + XBoxZone iBox = breakedInsideBoxes[i]; + XCBoxObject *iObj; + has = drawer.DrawBox( + iBox, + iObj // + ); + if (has) + { + // + iObj.BoxWidth(1); + mBreakedInsideZoneObjects.Add(iObj); + } + } + } + } + + +////////////////////////////////////////////////////////////////////////////////// + + // + XCSupplyZone *supplyZone; + XCDemandZone *demandZone; + + // + XCSupplyZone *supplyZones[]; + XCDemandZone *demandZones[]; + + // + XCSupportZone *supportZones[]; + XCResistanceZone *resistanceZones[]; + + // + XBoxZone insideBoxes[]; + XBoxZone breakedBoxes[]; + XBoxZone waitingBoxes[]; + XBoxZone breakedInsideBoxes[]; + XConsolidationZone consolidationZones[]; + + // + bool mUseSupDems; + bool mUseOrderBlocks; + bool mUseFairValueGaps; + + + // + // + // + + // // + // // Supply Zones ... + // has = HasSupplyZones(); + // if (!has) + // { + // // + // count = mtfState.FilterSupplyZones( + // supplyZones, + // period, + // XZONE_STATE_PASSED, + // false, + // XZONE_STATE_FAILED, + // false, + // XZONE_STATE_FAILED, + // false, + // XZONE_STATE_IGNORED, + // false // + // ); + // } + + // // + // // Demand Zones ... + // has = HasDemandZones(); + // if (!has) + // { + // // + // count = mtfState.FilterDemandZones( + // demandZones, + // period, + // XZONE_STATE_PASSED, + // false, + // XZONE_STATE_FAILED, + // false, + // XZONE_STATE_FAILED, + // false, + // XZONE_STATE_IGNORED, + // false // + // ); + // } + + // + // Support Zones ... + // has = HasSupportZones(); + // if (!has) + // { + // // + // count = mtfState.FilterSupportZones( + // supportZones, + // period, + // XZONE_STATE_PASSED, + // false, + // XZONE_STATE_FAILED, + // false, + // XZONE_STATE_FAILED, + // false, + // XZONE_STATE_IGNORED, + // false // + // ); + // } + + // + // Resistance Zones ... + // has = HasResistanceZones(); + // if (!has) + // { + // // + // count = mtfState.FilterResistanceZones( + // resistanceZones, + // period, + // XZONE_STATE_PASSED, + // false, + // XZONE_STATE_FAILED, + // false, + // XZONE_STATE_FAILED, + // false, + // XZONE_STATE_IGNORED, + // false // + // ); + // } + + + // + // Update Exists Zones ... + + // + // Supply Zones ... + has = mtfState.HasSupplyZones(); + if (has) + { + // + XCSupplyZone *zone; + idx = GetYoungest(mtfState.supplyZones); + has = IsValidIndex(idx); + if (has) + { + // + zone = mtfState.supplyZones[idx]; + has = IsSupplyExists(zone); + if (!has) + { + // + Add( + zone, + supplyZones // + ); + } + else + { + ZeroMemory(zone); + } + } + } + + // + // Demand Zones ... + has = mtfState.HasDemandZones(); + if (has) + { + // + XCDemandZone *zone; + idx = GetYoungest(mtfState.demandZones); + has = IsValidIndex(idx); + if (has) + { + // + zone = mtfState.demandZones[idx]; + has = IsDemandExists(zone); + if (!has) + { + // + Add( + zone, + demandZones // + ); + } + else + { + ZeroMemory(zone); + } + } + } + +/////////////////////////////////////////////////////////////////////////// + + // + bool IsExists(XBoxZone &box) + { + // + bool result = false; + + // + result = box.IsValid(); + if (!result) + { + return result; + } + + // + int idx = -1; + bool has = false; + + // + // Checking Index Waiting Box ... + has = HasWaitingBoxes(); + if (has) + { + // + idx = FindIndex( + box, + waitingBoxes // + ); + result = !IsValidIndex(idx); + if (!result) + { + return result; + } + } + + // + // Checking Index Inside Boxes ... + has = HasInsideBoxes(); + if (has) + { + // + idx = FindIndex( + box, + insideBoxes // + ); + result = !IsValidIndex(idx); + if (!result) + { + return result; + } + } + + // + // Checking Index Breaked Boxes ... + has = HasBreakedBoxes(); + if (has) + { + // + idx = FindIndex( + box, + breakedBoxes // + ); + result = !IsValidIndex(idx); + if (!result) + { + return result; + } + } + + // + // Checking Index BreakedInside Boxes ... + has = HasBreakedInsideBoxes(); + if (has) + { + // + idx = FindIndex( + box, + breakedInsideBoxes // + ); + result = !IsValidIndex(idx); + if (!result) + { + return result; + } + } + + // + return result; + } + + // + bool IsSupplyExists(XCSupplyZone *zone) + { + // + bool result = false; + + // + result = zone != NULL && + zone.IsValid(); + if (!result) + { + return result; + } + + // + // Converts Zone to Box ... + XBoxZone box; + result = ToBox( + box, + zone // + ); + if (!result) + { + // + box.Clean(); + return result; + } + + // + // Checking Index in SupplyZones ... + int idx = FindIndex( + zone, + supplyZones // + ); + result = !IsValidIndex(idx); + if (!result) + { + // + box.Clean(); + return result; + } + + // + result = IsExists(box); + + // + box.Clean(); + + // + return result; + } + + // + bool IsDemandExists(XCDemandZone *zone) + { + // + bool result = false; + + // + result = zone != NULL && + zone.IsValid(); + if (!result) + { + return result; + } + + // + // Converts Zone to Box ... + XBoxZone box; + result = ToBox( + box, + zone // + ); + if (!result) + { + // + box.Clean(); + return result; + } + + // + // Checking Index in SupplyZones ... + int idx = FindIndex( + zone, + demandZones // + ); + result = !IsValidIndex(idx); + if (!result) + { + // + box.Clean(); + return result; + } + + // + result = IsExists(box); + + // + box.Clean(); + + // + return result; + } + +////////////////////////////////////////////////////////////////////////////// + + + // + Clean(supplyZones); + Clean(demandZones); + + // + Clean(insideBoxes); + Clean(breakedBoxes); + Clean(waitingBoxes); + + // + Clean(supportZones); + Clean(resistanceZones); + + // + mUseSupDems = false; + mUseOrderBlocks = true; + mUseFairValueGaps = true; + +///////////////////////////////////////////////////////////////////////////// + + + // + bool HasInsideBox( + XBoxZone &box // + ) + { + // + bool result = false; + + // + int index = -1; + + // + result = box.IsValid(); + if (!result) + { + return result; + } + + // + int count = 0; + bool has = false; + + // + has = HasWaitingBoxes(); + if (has) + { + // + result = HasInsideBox( + index, + box, + waitingBoxes // + ); + } + + // + // Supply Zones ... + if (!result) + { + // + has = HasSupplyZones(); + if (has) + { + // + XBoxZone tmpBoxes[]; + count = ToBox( + supplyZones, + tmpBoxes // + ); + + // + has = IsValidSize(count); + if (has) + { + // + result = HasInsideBox( + index, + box, + tmpBoxes // + ); + } + + // + Clean(tmpBoxes); + } + } + + // + // Demand Zones ... + if (!result) + { + // + has = HasDemandZones(); + if (has) + { + // + XBoxZone tmpBoxes[]; + count = ToBox( + demandZones, + tmpBoxes // + ); + + // + has = IsValidSize(count); + if (has) + { + // + result = HasInsideBox( + index, + box, + tmpBoxes // + ); + } + + // + Clean(tmpBoxes); + } + } + + // + result = IsValidIndex(index); + + // + return result; + } + + + // + bool DetectSenarioASignalBox( + XBoxZone &signalBox, + ENUM_X_DIRECTION &signalDir, + X121Conditions &decisionXConditions, + X121Conditions &analyseXConditions, + XC121SMCCycleHelper *decisionCycleHelper, + XCPOIDrawer *drawer = NULL, + int barIndex = 0 // + ) + { + // + bool result = false; + + // + signalBox.Clean(); + signalDir = X_DIRECTION_NONE; + + // + if (barIndex < 0) + { + barIndex = 0; + } + + // + result = decisionCycleHelper != NULL; + if (!result) + { + return result; + } + + // + // Decision ... + double decisionBullishScore = 0; + double decisionBearishScore = 0; + decisionXConditions.GenerateScore( + decisionBullishScore, + decisionBearishScore // + ); + + // + // Analyse ... + double analyseBullishScore = 0; + double analyseBearishScore = 0; + analyseXConditions.GenerateScore( + analyseBullishScore, + analyseBearishScore // + ); + + // + // Score Conditions ... + double scoreMultiplier = 3; + bool isBullishScorePassed = + // + analyseBullishScore > (analyseBearishScore * scoreMultiplier) && + decisionBullishScore > (decisionBearishScore * scoreMultiplier) + // + ; + bool isBearishScorePassed = + // + analyseBearishScore > (analyseBullishScore * scoreMultiplier) && + decisionBearishScore > (decisionBullishScore * scoreMultiplier) + // + ; + + // + // Checking Other Conditions + + // + bool isCommonBullish = + // + decisionXConditions.isSarBullish && + decisionXConditions.isStrBullish && + decisionXConditions.isCheBullish && + decisionXConditions.isSMHKBullish && + decisionXConditions.isRawHKBullish && + decisionXConditions.isRawHKClosedOverSMHK + // + ; + + // + bool isCommonBearish = + // + decisionXConditions.isSarBearish && + decisionXConditions.isStrBearish && + decisionXConditions.isCheBearish && + decisionXConditions.isSMHKBearish && + decisionXConditions.isRawHKBearish && + decisionXConditions.isRawHKClosedUnderSMHK + // + ; + + // + // X3Ma ... + + // + // X3Ma Bullish ... + bool isX3MaBullish = + // + decisionXConditions.isX3MaBullishState && + decisionXConditions.isX3MaSwitchedToBullishOrdered && + decisionXConditions.x3maMidBuffer[1] > decisionXConditions.x3maSlowBuffer[1] + // + ; + + // + // X3Ma Bearish ... + bool isX3MaBearish = + // + decisionXConditions.isX3MaBearishState && + decisionXConditions.isX3MaSwitchedToBearishOrdered && + decisionXConditions.x3maMidBuffer[1] < decisionXConditions.x3maSlowBuffer[1] + // + ; + + // + bool isX3MaHasCondition = + (isX3MaBullish && + isCommonBullish && + isBullishScorePassed) || + (isX3MaBearish && + isCommonBearish && + isBearishScorePassed); + + // + // VWap ... + + // + // VWap Bullish ... + bool isVWapBullish = + // + decisionXConditions.isVWapBullishState && + decisionXConditions.isVWapSwitchedToBullishOrdered && + decisionXConditions.vwapMidBuffer[1] > decisionXConditions.vwapSlowBuffer[1] + // + ; + + // + // VWap Bearish ... + bool isVWapBearish = + // + decisionXConditions.isVWapBearishState && + decisionXConditions.isVWapSwitchedToBearishOrdered && + decisionXConditions.vwapMidBuffer[1] < decisionXConditions.vwapSlowBuffer[1] + // + ; + + // + bool isVWapHasCondition = + (isVWapBullish && + isBullishScorePassed) || + (isVWapBearish && + isBearishScorePassed); + + // + // Senario .... + // - a vale Under X3MA Slow when X3MA Bullish Ordered ... + + // + bool isX3MASenarioBBullish = + // + decisionXConditions.isX3MaBullishOrdered && + decisionXConditions.valesBuffer[1] < decisionXConditions.x3maSlowBuffer[1] && + decisionXConditions.valesBuffer[2] >= decisionXConditions.x3maSlowBuffer[2] + // + ; + if (isX3MASenarioBBullish) + { + } + + // + bool isX3MASenarioBBearish = + // + decisionXConditions.isX3MaBearishOrdered && + decisionXConditions.peaksBuffer[1] > decisionXConditions.x3maSlowBuffer[1] && + decisionXConditions.peaksBuffer[2] <= decisionXConditions.x3maSlowBuffer[2] + // + ; + if (isX3MASenarioBBearish) + { + } + + // + // Checking Other Conditions XWZ Reject on EMA 20 ... + + // + // Check Has Conditions ... + bool hasXConditions = + (isX3MaHasCondition || + isVWapHasCondition); + + // + result = hasXConditions; + if (!result) + { + return result; + } + + // + if (isX3MaHasCondition) + { + // + signalDir = + isX3MaBullish + ? X_DIRECTION_BULLISH + : isX3MaBearish + ? X_DIRECTION_BEARISH + : X_DIRECTION_NONE; + } + + // + if (isVWapHasCondition) + { + // + signalDir = + isVWapBullish + ? X_DIRECTION_BULLISH + : isVWapBearish + ? X_DIRECTION_BEARISH + : X_DIRECTION_NONE; + } + + // + // Creating SignalBox ... + + // + // Detect Box based on PV ... + bool hasSignalBox = decisionCycleHelper.GeneratePVBox( + signalBox, + barIndex // + ); + + // + result = + hasSignalBox && + signalDir == signalBox.dir; + + // + if (result) + { + // + XCBoxObject *iObj; + bool isCreated = drawer.DrawBox( + signalBox, + iObj // + ); + if (isCreated) + { + // + iObj.BoxWidth(1); + iObj.BoxColor(clrYellow); + iObj.BoxStyle(STYLE_SOLID); + } + + // + Print("Senario A ..."); + } + + // + return result; + } + + // + bool DetetctSenarioBSignalBox( + XBoxZone &signalBox, + ENUM_X_DIRECTION &signalDir, + X121Conditions &decisionXConditions, + X121Conditions &analyseXConditions, + XC121SMCCycleHelper *decisionCycleHelper, + int barIndex = 0 // + ) + { + // + bool result = false; + + // + signalBox.Clean(); + signalDir = X_DIRECTION_NONE; + + // + if (barIndex < 0) + { + barIndex = 0; + } + + // + result = decisionCycleHelper != NULL; + if (!result) + { + return result; + } + + // + // Decision ... + double decisionBullishScore = 0; + double decisionBearishScore = 0; + decisionXConditions.GenerateScore( + decisionBullishScore, + decisionBearishScore // + ); + + // + // Analyse ... + double analyseBullishScore = 0; + double analyseBearishScore = 0; + analyseXConditions.GenerateScore( + analyseBullishScore, + analyseBearishScore // + ); + + // + // Score Conditions ... + double scoreMultiplier = 3; + bool isBullishScorePassed = + // + analyseBullishScore > (analyseBearishScore * scoreMultiplier) && + decisionBullishScore > (decisionBearishScore * scoreMultiplier) + // + ; + bool isBearishScorePassed = + // + analyseBearishScore > (analyseBullishScore * scoreMultiplier) && + decisionBearishScore > (decisionBullishScore * scoreMultiplier) + // + ; + + // + // Senario .... + // - a vale Under X3MA Slow when X3MA Bullish Ordered ... + + // + bool isX3MASenarioBBullish = + // + decisionXConditions.isX3MaBullishOrdered && + decisionXConditions.valesBuffer[1] < decisionXConditions.x3maSlowBuffer[1] && + decisionXConditions.valesBuffer[2] >= decisionXConditions.x3maSlowBuffer[2] + // + ; + if (isX3MASenarioBBullish) + { + } + + // + bool isX3MASenarioBBearish = + // + decisionXConditions.isX3MaBearishOrdered && + decisionXConditions.peaksBuffer[1] > decisionXConditions.x3maSlowBuffer[1] && + decisionXConditions.peaksBuffer[2] <= decisionXConditions.x3maSlowBuffer[2] + // + ; + if (isX3MASenarioBBearish) + { + } + + // + return result; + } + + + // + bool HasSupplyZones() + { + return HasChild(supplyZones); + } + + // + int CountSupplyZones() + { + return ArraySize(supplyZones); + } + + // + bool HasDemandZones() + { + return HasChild(demandZones); + } + + // + int CountDemandZones() + { + return ArraySize(demandZones); + } + + // + bool HasSupportZones() + { + return HasChild(supportZones); + } + + // + int CountSupportZones() + { + return ArraySize(supportZones); + } + + // + bool HasResistanceZones() + { + return HasChild(resistanceZones); + } + + // + int CountResistanceZones() + { + return ArraySize(resistanceZones); + } + + // + bool HasConsolidationZones() + { + return HasChild(consolidationZones); + } + + // + int CountConsolidationZones() + { + return ArraySize(consolidationZones); + } + + // + bool HasWaitingBoxes() + { + return HasChild(waitingBoxes); + } + + // + int CountWaitingBoxes() + { + return ArraySize(waitingBoxes); + } + + // + bool HasInsideBoxes() + { + return HasChild(insideBoxes); + } + + // + int CountInsideBoxes() + { + return ArraySize(insideBoxes); + } + + // + bool HasBreakedBoxes() + { + return HasChild(breakedBoxes); + } + + // + int CountBreakedBoxes() + { + return ArraySize(breakedBoxes); + } + + // + bool HasBreakedInsideBoxes() + { + return HasChild(breakedInsideBoxes); + } + + // + int CountBreakedInsideBoxes() + { + return ArraySize(breakedInsideBoxes); + } + +/////////////////////////////////////////////////////////////////////////////////// + + // + has = ttfState.HasConsolidationZones(); + if (has) + { + // + Copy( + ttfState.consolidationZones, + consolidationZones // + ); + CleanupArray( + consolidationZones, + 50 // + ); + } + + + // + has = HasSupplyZones(); + if (has) + { + // + count = CountSupplyZones(); + for (int i = 0; i < count; i++) + { + supplyZones[i].To(value); + } + } + + // + has = HasDemandZones(); + if (has) + { + // + count = CountDemandZones(); + for (int i = 0; i < count; i++) + { + demandZones[i].To(value); + } + } + + // + has = HasSupportZones(); + if (has) + { + // + count = CountSupportZones(); + for (int i = 0; i < count; i++) + { + supportZones[i].To(value); + } + } + + // + has = HasResistanceZones(); + if (has) + { + // + count = CountResistanceZones(); + for (int i = 0; i < count; i++) + { + resistanceZones[i].To(value); + } + } + + // + // + // + + // + has = HasWaitingBoxes(); + if (has) + { + // + count = ArraySize(waitingBoxes); + for (int i = 0; i < count; i++) + { + waitingBoxes[i].to = value; + } + } + + // + has = HasInsideBoxes(); + if (has) + { + // + count = CountInsideBoxes(); + for (int i = 0; i < count; i++) + { + insideBoxes[i].to = value; + } + } + + // + has = HasBreakedBoxes(); + if (has) + { + } + + // + has = HasBreakedInsideBoxes(); + if (has) + { + // + count = CountBreakedInsideBoxes(); + for (int i = 0; i < count; i++) + { + breakedInsideBoxes[i].to = value; + } + } + +/////////////////////////////////////////////////////////////////////////////////// + + // + XBoxZone waitingBoxes[]; + has = workingZone.HasWaitingBoxes(); + if (has) + { + // + Copy( + workingZone.waitingBoxes, + waitingBoxes // + ); + + // + while (HasChild(waitingBoxes)) + { + // + XBoxZone iBox; + idx = GetYoungest(waitingBoxes); + has = IsValidIndex(idx); + if (!has) + { + // + iBox.Clean(); + continue; + } + + // + iBox = waitingBoxes[idx]; + ArrayRemove( + waitingBoxes, + idx, + 1 // + ); + + // + bool hasInside = workingZone.HasInsideBox(iBox); + if (!hasInside) + { + continue; + } + + // + double iTarget = + IsBullish(signalBoxDir) + ? iBox.lower + : iBox.upper; + + // + Add( + iTarget, + targets // + ); + + // + iBox.Clean(); + } + } + +/////////////////////////////////////////////////////////////////////////////////// + + // + void Update( + int barIndex, + XPOIState &htfState, + XPOIState &mtfState, + XPOIState &stfState, + XPOIState &ttfState // + ) + { + // + int idx = -1; + int count = 0; + bool has = false; + + // + if (barIndex < 0) + { + barIndex = 0; + } + + // + has = + // + IsValid() && + // + htfState.IsValid() && + mtfState.IsValid() && + stfState.IsValid() && + // + htfState.HasChild() && + mtfState.HasChild() && + stfState.HasChild() + // + ; + if (!has) + { + return; + } + + // + XOHCL zBar; + has = zBar.Init( + symbol, + period, + barIndex // + ); + if (!has) + { + // + zBar.Clean(); + return; + } + + // + XOHCL cBar; + has = zBar.GetPreviousBar(cBar); + if (!has) + { + // + zBar.Clean(); + cBar.Clean(); + + // + return; + } + + // + // Cleanup Resource ... + + // + zBar.Clean(); + cBar.Clean(); + } + +/////////////////////////////////////////////////////////////////////////////////// + +// +int ExtractOBFVGs( + XOBFVG &dest[], + XPOIState &obState, + XPOIState &fvgState, + // + ENUM_X_OBFVG_FVG_FILTERS filterFVGs = X_OBFVG_FVG_FILTER_INSIDE_OR, + ENUM_X_OBFVG_FVG_SELECTION selectFVG = X_OBFVG_FVG_SELECT_OLDEST, + // + ENUM_TIMEFRAMES forPeriod = NULL, + // + // Start ... + ENUM_XZONE_STATE startState = XZONE_STATE_PASSED, + bool forceStartedBodyOut = false, + // + // Activation ... + ENUM_XZONE_STATE activeState = XZONE_STATE_FAILED, + bool forceActivatedBodyIn = false, + // + // Breaktion ... + ENUM_XZONE_STATE breakState = XZONE_STATE_FAILED, + bool forceBreakedBodyOut = false, + // + // Works ... + ENUM_XZONE_STATE workState = XZONE_STATE_IGNORED, + bool forceWorkedBodyOut = false // +) +{ + // + int result = 0; + + // + bool has = false; + + // + Clean(dest); + + // + has = obState.IsValid() && + fvgState.IsValid() && + obState.HasChild() && + fvgState.HasChild() && + selectFVG != X_OBFVG_FVG_SELECT_NONE && + filterFVGs != X_OBFVG_FVG_FILTER_NONE; + if (!has) + { + return result; + } + + // + XCOrderBlock *obs[]; + int obsCount = obState.FilterOrderBlocks( + obs, + forPeriod, + startState, + forceStartedBodyOut, + activeState, + forceActivatedBodyIn, + breakState, + forceBreakedBodyOut, + workState, + forceWorkedBodyOut // + ); + has = IsValidSize(obsCount); + if (!has) + { + return result; + } + + // + XCFVG *fvgs[]; + int fvgsCount = fvgState.FilterFairValueGaps( + fvgs, + forPeriod, + startState, + forceStartedBodyOut, + activeState, + forceActivatedBodyIn, + breakState, + forceBreakedBodyOut, + workState, + forceWorkedBodyOut // + ); + has = IsValidSize(fvgsCount); + if (!has) + { + return result; + } + + // + for (int i = 0; i < obsCount; i++) + { + // + XCOrderBlock *iOB = obs[i]; + XCFVG *iFVG = NULL; + + // + ENUM_X_DIRECTION iOBDir = iOB.GetDirection(); + bool isIOBBullish = IsBullish(iOBDir); + + // + XCFVG *iFVGs[]; + for (int j = 0; j < fvgsCount; j++) + { + // + XCFVG *jFVG = fvgs[j]; + ENUM_X_DIRECTION jFVGDir = jFVG.GetDirection(); + + // + bool isSameDir = iOBDir == jFVGDir; + bool isFromPassed = jFVG.From() >= iOB.From(); + bool isInsideOr = IsInsideOrDiff( + jFVG, + iOB // + ); + bool isAbove = IsAboveDiff( + jFVG, + iOB, + true // + ); + bool isBelow = IsBelowDiff( + jFVG, + iOB, + true // + ); + + // + bool isFilterPassed = + filterFVGs == X_OBFVG_FVG_FILTER_ABOVE_BELOW + ? isIOBBullish + ? isAbove + : isBelow + : filterFVGs == X_OBFVG_FVG_FILTER_INSIDE_OR + ? isInsideOr + : false; + + // + has = + isSameDir && + isFromPassed && + isFilterPassed; + if (has) + { + // + Add( + jFVG, + iFVGs // + ); + } + } + has = HasChild(iFVGs); + if (!has) + { + continue; + } + + // + int idx = -1; + idx = selectFVG == X_OBFVG_FVG_SELECT_OLDEST + ? GetOldest(iFVGs) + : selectFVG == X_OBFVG_FVG_SELECT_YOUNGEST + ? GetYoungest(iFVGs) + : selectFVG == X_OBFVG_FVG_SELECT_HIGHEST_LOWEST + ? isIOBBullish + ? GetHighest(iFVGs) + : GetLowest(iFVGs) + : selectFVG == X_OBFVG_FVG_SELECT_LOWEST_HIGHEST + ? isIOBBullish + ? GetLowest(iFVGs) + : GetHighest(iFVGs) + : selectFVG == X_OBFVG_FVG_SELECT_LOWEST + ? GetLowest(iFVGs) + : selectFVG == X_OBFVG_FVG_SELECT_HIGHEST + ? GetHighest(iFVGs) + : -1; + + // + has = IsValidIndex(idx); + if (!has) + { + continue; + } + + // + iFVG = iFVGs[idx]; + Clean(iFVGs); + + // + XOBFVG iOBFVG; + iOBFVG.ob = iOB; + iOBFVG.fvg = iFVG; + + // + has = iOBFVG.IsValid(); + if (!has) + { + // + iOBFVG.Clean(); + continue; + } + + // + AddRef( + iOBFVG, + dest // + ); + + // + iOBFVG.Clean(); + } + + // + result = ArraySize(dest); + + // + return result; +} + +/////////////////////////////////////////////////////////////////////////////////// + + +/////////////////////////////////////////////////////////////////////////////////// + + +/////////////////////////////////////////////////////////////////////////////////// + + +/////////////////////////////////////////////////////////////////////////////////// + + +/////////////////////////////////////////////////////////////////////////////////// + + +/////////////////////////////////////////////////////////////////////////////////// + + +/////////////////////////////////////////////////////////////////////////////////// + + +/////////////////////////////////////////////////////////////////////////////////// + + +/////////////////////////////////////////////////////////////////////////////////// + + +/////////////////////////////////////////////////////////////////////////////////// + + diff --git a/Documents/BKP/x-121.smc.xwz.signal.class copy 2.mq5 b/Documents/BKP/x-121.smc.xwz.signal.class copy 2.mq5 new file mode 100644 index 00000000..1f79c257 --- /dev/null +++ b/Documents/BKP/x-121.smc.xwz.signal.class copy 2.mq5 @@ -0,0 +1,2295 @@ +/////////////////////////////////////////////////////// +// +// SaherElm IT Center MQL5 X121 SMC Signal Class +// ------------------------------------------------- +// Name: XWZ +// Description: provide all Signalling functions ... +// +// +// Maintainer: +// ------------ +// Hadi Khazaee Asl (hadi_khazaee_asl@yahoo.com) +// +////////////////////////////////////////////////////// +// +// Global Properties ... +#property library +#property copyright "Copyright 2023, SaherElm IT Center" +#property link "https://www.saherelm.ir" +#property version "1.00" +#property strict + +// +// Imports ... +#include "../Classes/x-121.smc.market.cycle.helper.class.mq5" +#include "../Libraries/x-121.smc.guard.lib.mq5" +#include "../Libraries/x-121.smc.lib.mq5" +#include "./x-121.smc.xwz.signal.lib.mq5" + +// +// Definition ... +class XCX121SMCXWZSignalDetector : public XCBase +{ + // + public: + // + // Props ... + X121SMCStrategyXWZWorkingZone workingZone; + X121SMCStrategyXWZSignalConditions mConditions; + X121SMCStrategyXWZSignalConditions mConditionsCollection[]; + + // + // Constructor(s) ... + XCX121SMCXWZSignalDetector( + string _symbol, + ENUM_TIMEFRAMES _period // + ) + { + // + symbol = _symbol; + period = _period; + Init(); + } + + // + // Deconstructor ... + ~XCX121SMCXWZSignalDetector() + { + DeInit(); + } + + // + // + // + + // + // Detect Setup Conditions ... + bool DetectSignalSetup( + // + XC121SMCCycleHelper *decisionCycleHelper, + XC121SMCCycleHelper *analyseCycleHelper, + XC121SMCCycleHelper *consolidationCycleHelper, + XC121SMCCycleHelper *visionCycleHelper, + // + double maxAllowedSLDistanceInPoint = 300 + // + ) + { + // + bool result = false; + + // + // Validate Cycle Helpers ... + result = + // + visionCycleHelper != NULL && + analyseCycleHelper != NULL && + decisionCycleHelper != NULL && + consolidationCycleHelper != NULL + // + ; + if (!result) + { + // + mConditions.Clean(); + + // + return result; + } + + // + bool isBullish = false; + bool isBearish = false; + + // + int zIndex = 0; + int cIndex = zIndex + 1; + int pIndex = cIndex + 1; + int ppIndex = pIndex + 1; + + // + int loopback = 10; + + // + mConditions.symbol = symbol; + mConditions.period = period; + + // + double ask = GetAsk(symbol); + double bid = GetBid(symbol); + datetime cTime = TimeCurrent(); + double points = GetPoints(symbol); + + // + // Cycles Conditions ... + + // + XOHCL consolidationZBar; + result = consolidationCycleHelper.GetBar( + consolidationZBar, + zIndex // + ); + if (!result) + { + // + consolidationZBar.Clean(); + return result; + } + + // + bool drawBar = false; + if (drawBar) + { + // + DrawBar( + consolidationZBar, + decisionCycleHelper.mPOIDrawer // + ); + } + + // + // Decision ... + ENUM_XPOI_EVENTS decisionPoiEvents[]; + ENUM_X_CYCLE_EVENTS decisionCycleEvents[]; + X121SMCCycleConditions decisionConditions; + result = decisionCycleHelper.GetConditions( + decisionCycleEvents, + decisionPoiEvents, + decisionConditions, + zIndex, + loopback // + ); + if (!result) + { + // + Clean(decisionPoiEvents); + Clean(decisionCycleEvents); + + // + decisionConditions.Clean(); + + // + mConditions.Clean(); + consolidationZBar.Clean(); + + // + return result; + } + + // + // Analyse ... + ENUM_XPOI_EVENTS analysePoiEvents[]; + ENUM_X_CYCLE_EVENTS analyseCycleEvents[]; + X121SMCCycleConditions analyseConditions; + result = analyseCycleHelper.GetConditions( + analyseCycleEvents, + analysePoiEvents, + analyseConditions, + zIndex, + loopback // + ); + if (!result) + { + // + Clean(analysePoiEvents); + Clean(decisionPoiEvents); + + // + Clean(analyseCycleEvents); + Clean(decisionCycleEvents); + + // + analyseConditions.Clean(); + decisionConditions.Clean(); + + // + mConditions.Clean(); + consolidationZBar.Clean(); + + // + return result; + } + + // + // Consolidation ... + ENUM_XPOI_EVENTS consolidationPoiEvents[]; + ENUM_X_CYCLE_EVENTS consolidationCycleEvents[]; + X121SMCCycleConditions consolidationConditions; + result = consolidationCycleHelper.GetConditions( + consolidationCycleEvents, + consolidationPoiEvents, + consolidationConditions, + zIndex, + loopback // + ); + if (!result) + { + // + Clean(analysePoiEvents); + Clean(decisionPoiEvents); + Clean(consolidationPoiEvents); + + // + Clean(analyseCycleEvents); + Clean(decisionCycleEvents); + Clean(consolidationCycleEvents); + + // + analyseConditions.Clean(); + decisionConditions.Clean(); + consolidationConditions.Clean(); + + // + mConditions.Clean(); + consolidationZBar.Clean(); + + // + return result; + } + + // + // Vision ... + ENUM_XPOI_EVENTS visionPoiEvents[]; + ENUM_X_CYCLE_EVENTS visionCycleEvents[]; + X121SMCCycleConditions visionConditions; + result = visionCycleHelper.GetConditions( + visionCycleEvents, + visionPoiEvents, + visionConditions, + zIndex, + loopback // + ); + if (!result) + { + // + Clean(visionPoiEvents); + Clean(analysePoiEvents); + Clean(decisionPoiEvents); + Clean(consolidationPoiEvents); + + // + Clean(visionCycleEvents); + Clean(analyseCycleEvents); + Clean(decisionCycleEvents); + Clean(consolidationCycleEvents); + + // + visionConditions.Clean(); + analyseConditions.Clean(); + decisionConditions.Clean(); + consolidationConditions.Clean(); + + // + mConditions.Clean(); + consolidationZBar.Clean(); + + // + return result; + } + + // + // Cycles POI States ... + XPOIState decisionState = decisionConditions.state; + XPOIState analyseState = analyseConditions.state; + XPOIState consolidationState = consolidationConditions.state; + XPOIState visionState = visionConditions.state; + + // + // Cycle X121Conditions ... + X121Conditions decisionXConditions = decisionConditions.x121Conditions; + X121Conditions analyseXConditions = analyseConditions.x121Conditions; + X121Conditions consolidationXConditions = consolidationConditions.x121Conditions; + X121Conditions visionXConditions = visionConditions.x121Conditions; + + // + // Scores ... + + // + // Decision ... + double decisionBullishScore = 0; + double decisionBearishScore = 0; + decisionXConditions.GenerateScore( + decisionBullishScore, + decisionBearishScore // + ); + + // + // Analyse ... + double analyseBullishScore = 0; + double analyseBearishScore = 0; + analyseXConditions.GenerateScore( + analyseBullishScore, + analyseBearishScore // + ); + + // + // + // + + // + bool hasNewSupply = Contains( + X_SUPPLY_ZONE_DETECTED, + analysePoiEvents // + ); + + // + bool hasNewDemand = Contains( + X_DEMAND_ZONE_DETECTED, + analysePoiEvents // + ); + + // + bool hasNewFairValueGap = + Contains( + X_BULLISH_FVG_DETECTED, + analysePoiEvents // + ) || + Contains( + X_BEARISH_FVG_DETECTED, + analysePoiEvents // + ); + + // + bool hasNewOrderBlock = + Contains( + X_BULLISH_ORDERBLOCK_DETECTED, + analysePoiEvents // + ) || + Contains( + X_BEARISH_ORDERBLOCK_DETECTED, + analysePoiEvents // + ); + + // + // + // + + // + // Select Drawer Class ... + XCPOIDrawer *drawer = visionCycleHelper.mPOIDrawer; + + // + // Setup Conditions ... + double sls[]; + double sl = 0; + double pivot = 0; + double point = 0; + double targets[]; + double reward = 0; + XBoxZone signalBox; + double amountPercent = 0; + bool hasPriority = false; + bool hasSignalBox = false; + bool hasRewardAmount = false; + bool isSignalBoxReversal = false; + bool hasWorkingZoneOveralDirection = false; + ENUM_X_DIRECTION wzOveralDir = X_DIRECTION_NONE; + ENUM_X_DIRECTION signalBoxDir = X_DIRECTION_NONE; + ENUM_X121SMC_XWZ_PRIORITY priority = X121SMC_XWZ_PRIORITY_NONE; + ENUM_X121SMC_XWZ_PROVIDERS provider = X121SMC_XWZ_PROVIDER_NONE; + + // + // + // + + // + // First We Have to Has Working Zone ... + bool hasWorkingZone = workingZone.IsValid(); + if (!hasWorkingZone) + { + // + hasWorkingZone = workingZone.Init( + symbol, + period, + zIndex, + visionState, + consolidationState, + analyseState, + decisionState // + ); + } + + // + // Update Working Zone ... + if (hasWorkingZone) + { + // + // Reset POI Detector Required POI(s) ... + visionCycleHelper.mPOIDetector.MaxRequiredPOIs(50); + analyseCycleHelper.mPOIDetector.MaxRequiredPOIs(50); + decisionCycleHelper.mPOIDetector.MaxRequiredPOIs(50); + consolidationCycleHelper.mPOIDetector.MaxRequiredPOIs(50); + + // + // Reset POI Detector Allowed Loopback ... + visionCycleHelper.mPOIDetector.MaxAllowedLoopbackForInit(578); + analyseCycleHelper.mPOIDetector.MaxAllowedLoopbackForInit(578); + decisionCycleHelper.mPOIDetector.MaxAllowedLoopbackForInit(578); + consolidationCycleHelper.mPOIDetector.MaxAllowedLoopbackForInit(578); + + // + // Update Working Zone ... + // workingZone.Update( + // zIndex, + // visionState, + // consolidationState, + // analyseState, + // decisionState // + // ); + + // + // Check Working Zone Overal Direction ... + hasWorkingZoneOveralDirection = workingZone + .DetectOveralDirection(wzOveralDir); + + // + // Checking Working Zone Destory or not ... + bool isWorkingZoneDestroyed = workingZone.IsDestroyed( + zIndex, + period // + ); + + // + // Cleanup WorkingZone and ignore all conditions ... + if (isWorkingZoneDestroyed) + { + // + result = false; + workingZone.Clean(); + hasWorkingZone = false; + + // + // Cleanup Resources ... + Clean(visionPoiEvents); + Clean(analysePoiEvents); + Clean(decisionPoiEvents); + Clean(consolidationPoiEvents); + + // + Clean(visionCycleEvents); + Clean(analyseCycleEvents); + Clean(decisionCycleEvents); + Clean(consolidationCycleEvents); + + // + visionState.Clean(); + analyseState.Clean(); + decisionState.Clean(); + consolidationState.Clean(); + + // + visionConditions.Clean(); + analyseConditions.Clean(); + decisionConditions.Clean(); + consolidationConditions.Clean(); + + // + visionXConditions.Clean(); + analyseXConditions.Clean(); + decisionXConditions.Clean(); + consolidationXConditions.Clean(); + + // + mConditions.Clean(); + consolidationZBar.Clean(); + + // + return result; + } + } + + // + // + // + + // + // Waiting Box Detected ... + bool hasWaitingBoxes = hasWorkingZone && + workingZone.HasWaitingBoxes(); + if (hasWaitingBoxes) + { + // + XOHCL zBar; + XOHCL cBar; + XOHCL pBar; + int count = 0; + int idx = -1; + bool has = false; + + // + bool isInited = zBar.Init( + symbol, + period, + zIndex // + ); + isInited = + isInited && + zBar.GetPreviousBar(cBar); + isInited = + isInited && + cBar.GetPreviousBar(pBar); + + // + count = workingZone.CountWaitingBoxes(); + for (int i = 0; i < count; i++) + { + // + XBoxZone iBox = workingZone.waitingBoxes[i]; + ENUM_X_DIRECTION iDir = iBox.dir; + bool isBullish = IsBullish(iDir); + + // + // Check Price Rejection ... + + // + bool hasBullishFiboPressure = + decisionCycleHelper + .mBarAnalyser + .HasFiboPressure( + cBar, + X_DIRECTION_BULLISH, + X_FIBO_LEVEL_382 // + ); + + // + bool hasBearishFiboPressure = + decisionCycleHelper + .mBarAnalyser + .HasFiboPressure( + cBar, + X_DIRECTION_BEARISH, + X_FIBO_LEVEL_382 // + ); + + // + // Bullish Rejection ... + bool isBullishRejected = + // + isInited && + isBullish && + cBar.low < pBar.low && + zBar.low > iBox.upper && + cBar.low <= iBox.upper && + zBar.open > iBox.upper && + hasBullishFiboPressure && + cBar.GetLowShadow() > pBar.GetLowShadow() + // + ; + + // + // Bearish Rejection ... + bool isBearishhRejected = + // + isInited && + !isBullish && + cBar.high > pBar.high && + zBar.open < iBox.lower && + zBar.high < iBox.lower && + hasBearishFiboPressure && + cBar.high >= iBox.lower && + cBar.GetHighShadow() > pBar.GetHighShadow() + // + ; + + // + has = isBullishRejected || + isBearishhRejected; + if (has) + { + // + idx = i; + signalBox = iBox; + hasSignalBox = has; + signalBox.to = cTime; + signalBoxDir = iBox.dir; + isSignalBoxReversal = false; + provider = X121SMC_XWZ_PROVIDER_ACTIVATED_ZONE; + } + + // + iBox.Clean(); + } + + // + // Remove Signal Box from Waiting Boxes of + // Working Zone ... + if (hasSignalBox) + { + // + if (IsValidIndex(idx)) + { + // + ArrayRemove( + workingZone.waitingBoxes, + idx, + 1 // + ); + } + } + + // + // Ignore Zone's Signals ... + hasSignalBox = false; + + // + // Cleanup Resources ... + + // + zBar.Clean(); + cBar.Clean(); + pBar.Clean(); + } + + // + // Check Conditions if Has Inside Boxes ... + bool hasInsideBoxes = hasWorkingZone && + workingZone.HasInsideBoxes(); + if (hasInsideBoxes) + { + } + + // + // Check Conditions if has Breaked Boxes ... + bool hasBreakedBoxes = hasWorkingZone && + workingZone.HasBreakedBoxes(); + if (hasBreakedBoxes) + { + } + + // + // Checking Other Conditions ... + if (!hasSignalBox) + { + // + // Senari A ... + // hasSignalBox = hasWorkingZone && + // workingZone.DetectSenarioASignalBox( + // signalBox, + // signalBoxDir, + // decisionXConditions, + // analyseXConditions, + // decisionCycleHelper, + // drawer, + // zIndex // + // ); + // if (hasSignalBox) + // { + // // + // signalBox.to = cTime; + // isSignalBoxReversal = false; + // provider = X121SMC_XWZ_PROVIDER_PV_ZONE; + // } + + // // + // // Validating Signal Box if Exists ... + // if (hasSignalBox) + // { + // // + // // Validate Signal Boxes using Inside Box ... + // if (hasInsideBoxes) + // { + // // + // int idx = -1; + // bool has = false; + + // // + // idx = + // IsBullish(signalBoxDir) + // ? GetLowest(workingZone.insideBoxes) + // : GetHighest(workingZone.insideBoxes); + // has = IsValidIndex(idx); + // if (has) + // { + // // + // hasSignalBox = + // signalBoxDir == workingZone.insideBoxes[idx].dir; + // } + // } + + // // + // // Validate Signal Box Using Overal Trend ... + // if (hasWorkingZoneOveralDirection) + // { + // // + // hasSignalBox = + // signalBoxDir == wzOveralDir; + // } + // } + } + + // + // + // + + // + // Cleanup Signal if UnApproved ... + if (!hasSignalBox) + { + // + signalBox.Clean(); + signalBoxDir = X_DIRECTION_NONE; + } + + // + // + // + + // + // Check Priority Exists ... + hasPriority = workingZone + .DetectPriority( + priority, + signalBoxDir, + zIndex, + period // + ); + + // + // Check Price Reward and Amount Exists ... + hasRewardAmount = CalculateRiskReward( + priority, + reward, + amountPercent // + ); + + // + // Check Signal Conditions ... + if (hasSignalBox) + { + // + int idx = -1; + bool has = false; + + // + XCBoxObject *iObj; + has = drawer.DrawBox( + signalBox, + iObj // + ); + if (has) + { + // + iObj.BoxWidth(1); + iObj.BoxColor(clrYellow); + iObj.BoxStyle(STYLE_SOLID); + } + + // + isBullish = IsBullish(signalBoxDir); + isBearish = IsBearish(signalBoxDir); + + // + pivot = isBullish + ? signalBox.lower + : signalBox.upper; + + // + point = isBullish + ? signalBox.upper + : signalBox.lower; + + // + double iSL = 0; + double signalBoxRange = (signalBox.upper - signalBox.lower); + if (signalBoxRange < points * 100) + { + iSL = pivot; + } + else + { + iSL = signalBox.lower + (signalBox.upper - signalBox.lower) / 2; + } + + // + if (provider == X121SMC_XWZ_PROVIDER_PV_ZONE) + { + } + + // + Add( + iSL, + sls // + ); + + // + // Select Condition SL ... + + // + double entry = GetEntry( + signalBox.symbol, + signalBoxDir // + ); + + // + double slsMin = GetMin(sls); + double slsMax = GetMax(sls); + + // + double longSL = slsMin; + double shortSL = slsMax; + + // + sl = isBullish + ? longSL + : shortSL; + + // + // Targets ... + + // + // Force Add TP 2 as Target ... + double risk = MathAbs(entry - sl); + double reward2 = 2 * risk; + // double iTP2 = isBullish + // ? entry + reward2 + // : entry - reward2; + // Add( + // iTP2, + // targets // + // ); + + // + // Based On Priority ... + has = priority != X121SMC_XWZ_PRIORITY_NONE; + if (has) + { + // + switch (priority) + { + // + case X121SMC_XWZ_PRIORITY_WEAK: + // + if (isBullish) + { + // + // Weak ... + Add( + workingZone.supplyZone.Lower(), + targets // + ); + } + else + { + // + // Weak ... + Add( + workingZone.demandZone.Upper(), + targets // + ); + } + break; + + // + case X121SMC_XWZ_PRIORITY_LOW: + // + if (isBullish) + { + // + // Weak ... + Add( + workingZone.supplyZone.Lower(), + targets // + ); + + // + // Low ... + Add( + workingZone.quarter1, + targets // + ); + } + else + { + // + // Weak ... + Add( + workingZone.demandZone.Upper(), + targets // + ); + + // + // Low ... + Add( + workingZone.quarter3, + targets // + ); + } + break; + + // + case X121SMC_XWZ_PRIORITY_REGULAR: + // + if (isBullish) + { + // + // Weak ... + Add( + workingZone.supplyZone.Lower(), + targets // + ); + + // + // Low ... + Add( + workingZone.quarter1, + targets // + ); + + // + // Regular ... + Add( + workingZone.quarter2, + targets // + ); + } + else + { + // + // Weak ... + Add( + workingZone.demandZone.Upper(), + targets // + ); + + // + // Low ... + Add( + workingZone.quarter3, + targets // + ); + + // + // Regular ... + Add( + workingZone.quarter2, + targets // + ); + } + break; + + // + case X121SMC_XWZ_PRIORITY_HIGH: + // + if (isBullish) + { + // + // Weak ... + Add( + workingZone.supplyZone.Lower(), + targets // + ); + + // + // Low ... + Add( + workingZone.quarter1, + targets // + ); + + // + // Regular ... + Add( + workingZone.quarter2, + targets // + ); + + // + // High ... + Add( + workingZone.quarter3, + targets // + ); + } + else + { + // + // Weak ... + Add( + workingZone.demandZone.Upper(), + targets // + ); + + // + // Low ... + Add( + workingZone.quarter3, + targets // + ); + + // + // Regular ... + Add( + workingZone.quarter2, + targets // + ); + + // + // High ... + Add( + workingZone.quarter1, + targets // + ); + } + break; + + // + case X121SMC_XWZ_PRIORITY_STRONG_HIGH: + // + if (isBullish) + { + // + // Weak ... + Add( + workingZone.supplyZone.Lower(), + targets // + ); + + // + // Low ... + Add( + workingZone.quarter1, + targets // + ); + + // + // Regular ... + Add( + workingZone.quarter2, + targets // + ); + + // + // High ... + Add( + workingZone.quarter3, + targets // + ); + + // + // Strong High ... + Add( + workingZone.demandZone.Upper(), + targets // + ); + } + else + { + // + // Weak ... + Add( + workingZone.demandZone.Upper(), + targets // + ); + + // + // Low ... + Add( + workingZone.quarter3, + targets // + ); + + // + // Regular ... + Add( + workingZone.quarter2, + targets // + ); + + // + // High ... + Add( + workingZone.quarter1, + targets // + ); + + // + // Strong High ... + Add( + workingZone.supplyZone.Lower(), + targets // + ); + } + break; + } + } + + // + XBoxZone waitingBoxes[]; + has = workingZone.HasWaitingBoxes(); + if (has) + { + // + Copy( + workingZone.waitingBoxes, + waitingBoxes // + ); + + // + while (HasChild(waitingBoxes)) + { + // + XBoxZone iBox; + idx = GetYoungest(waitingBoxes); + has = IsValidIndex(idx); + if (!has) + { + // + iBox.Clean(); + continue; + } + + // + iBox = waitingBoxes[idx]; + ArrayRemove( + waitingBoxes, + idx, + 1 // + ); + + // + bool hasInside = workingZone.HasInsideBox(iBox); + if (!hasInside) + { + continue; + } + + // + double iTarget = + IsBullish(signalBoxDir) + ? iBox.lower + : iBox.upper; + + // + Add( + iTarget, + targets // + ); + + // + iBox.Clean(); + } + } + } + + // + // Summarize Results ... + result = hasPriority && + hasSignalBox && + hasRewardAmount; + + // + if (result) + { + // + Copy( + sls, + mConditions.sls // + ); + Copy( + targets, + mConditions.targets // + ); + + // + mConditions.sl = sl; + mConditions.pivot = pivot; + mConditions.point = point; + mConditions.reward = reward; + mConditions.setupTime = cTime; + mConditions.dir = signalBoxDir; + mConditions.priority = priority; + mConditions.provider = provider; + mConditions.signalBox = signalBox; + mConditions.amountPercent = amountPercent; + } + + // + UpdateTo(cTime); + + // + // Draw Working Zone ... + if (hasWorkingZone) + { + // + workingZone.Draw( + drawer, + // + true, // Draw Waiting Boxes ... + true, // Draw Inside Boxes ... + true, // Draw Breaked Boxes ... + true, // Draw Breaked Inside Boxes ... + // + true, // Draw Supply Zone ... + true, // Draw Demand Zone ... + true, // Draw Supply Zones ... + true, // Draw Demand Zones ... + true, // Draw Support Zones ... + true // Draw Resistance Zones ... + ); + } + + // + // + // + + // + // Cleanup Resources ... + + // + Clean(visionPoiEvents); + Clean(analysePoiEvents); + Clean(decisionPoiEvents); + Clean(consolidationPoiEvents); + + // + Clean(visionCycleEvents); + Clean(analyseCycleEvents); + Clean(decisionCycleEvents); + Clean(consolidationCycleEvents); + + // + visionState.Clean(); + analyseState.Clean(); + decisionState.Clean(); + consolidationState.Clean(); + + // + visionConditions.Clean(); + analyseConditions.Clean(); + decisionConditions.Clean(); + consolidationConditions.Clean(); + + // + visionXConditions.Clean(); + analyseXConditions.Clean(); + decisionXConditions.Clean(); + consolidationXConditions.Clean(); + + // + consolidationZBar.Clean(); + + // + return result; + } + + // + // Detect Trigger Conditions ... + bool DetectSignalTrigger( + // + X121SMCStrategyXWZSignalConditions &conditions, + // + XC121SMCCycleHelper *decisionCycleHelper, + XC121SMCCycleHelper *analyseCycleHelper, + XC121SMCCycleHelper *consolidationCycleHelper, + XC121SMCCycleHelper *visionCycleHelper, + // + int maxAllowedSetupAge = 60 + // + ) + { + // + bool result = false; + + // + result = + // + visionCycleHelper != NULL && + analyseCycleHelper != NULL && + decisionCycleHelper != NULL && + consolidationCycleHelper != NULL + // + ; + if (!result) + { + return result; + } + + // + result = conditions.IsSetuped(); + if (!result) + { + return result; + } + + // + datetime setupTime = conditions.setupTime; + ENUM_X_DIRECTION setupDir = conditions.dir; + + // + bool isBullish = IsBullish(setupDir); + bool isBearish = IsBearish(setupDir); + + // + int zIndex = 0; + int cIndex = zIndex + 1; + int pIndex = cIndex + 1; + int ppIndex = pIndex + 1; + + // + int loopback = 10; + + // + double ask = GetAsk(symbol); + double bid = GetBid(symbol); + datetime cTime = TimeCurrent(); + double points = GetPoints(symbol); + + // + // Cycles Conditions ... + + // + // Decision ... + ENUM_XPOI_EVENTS decisionPoiEvents[]; + ENUM_X_CYCLE_EVENTS decisionCycleEvents[]; + X121SMCCycleConditions decisionConditions; + result = decisionCycleHelper.GetConditions( + decisionCycleEvents, + decisionPoiEvents, + decisionConditions, + zIndex, + loopback // + ); + if (!result) + { + // + // Cleanup ... + + // + Clean(decisionPoiEvents); + Clean(decisionCycleEvents); + + // + decisionConditions.Clean(); + + // + return result; + } + + // + // Analyse ... + ENUM_XPOI_EVENTS analysePoiEvents[]; + ENUM_X_CYCLE_EVENTS analyseCycleEvents[]; + X121SMCCycleConditions analyseConditions; + result = analyseCycleHelper.GetConditions( + analyseCycleEvents, + analysePoiEvents, + analyseConditions, + zIndex, + loopback // + ); + if (!result) + { + // + Clean(analysePoiEvents); + Clean(decisionPoiEvents); + + // + Clean(analyseCycleEvents); + Clean(decisionCycleEvents); + + // + analyseConditions.Clean(); + decisionConditions.Clean(); + + // + return result; + } + + // + // Cycles POI States ... + XPOIState decisionState = decisionConditions.state; + XPOIState analyseState = analyseConditions.state; + + // + // Cycle X121Conditions ... + X121Conditions decisionXConditions = decisionConditions.x121Conditions; + X121Conditions analyseXConditions = analyseConditions.x121Conditions; + + // + double iAtr = decisionXConditions.atrBuffer[1]; + iAtr *= 1.5; + + // + // Check Signal Validation ... + // IMPORTANT: since all Validations done in SetUp Process ... + // here we only Execute Signal ... + + // + result = isBullish || + isBearish; + + // + if (result) + { + // + conditions.triggerTime = cTime; + conditions.type = isBullish + ? X_POSITION_TYPE_LONG + : X_POSITION_TYPE_SHORT; + + // + } + + // + // Cleanup ... + + // + Clean(decisionPoiEvents); + Clean(decisionCycleEvents); + + // + decisionState.Clean(); + decisionConditions.Clean(); + decisionXConditions.Clean(); + + // + Clean(analysePoiEvents); + Clean(analyseCycleEvents); + + // + analyseState.Clean(); + analyseConditions.Clean(); + analyseXConditions.Clean(); + + // + return result; + } + + // + // Detect Guards ... + bool DetectGuards( + // + X121SMCGuard &guards[], + const XPosition &positions[], + // + XC121SMCCycleHelper *decisionCycleHelper, + XC121SMCCycleHelper *analyseCycleHelper, + XC121SMCCycleHelper *consolidationCycleHelper, + XC121SMCCycleHelper *visionCycleHelper + // + ) + { + // + bool result = false; + return false; + + // + Clean(guards); + + // + bool isCycleHelpersValid = + // + visionCycleHelper != NULL && + analyseCycleHelper != NULL && + decisionCycleHelper != NULL && + consolidationCycleHelper != NULL + // + ; + + // + // Set Provider for Common Guards ... + string provider = ToString(X_121_SMC_PROVIDER_XWZ); + + // + // Check Cycle Helpers Validation ... + result = isCycleHelpersValid; + if (!result) + { + return result; + } + + // + // Select Own Positions ... + int count = ArraySize(positions); + result = IsValidSize(count); + if (!result) + { + return result; + } + + // + XPosition ownPositions[]; + XPosition ownLongPositions[]; + XPosition ownShortPositions[]; + for (int i = 0; i < count; i++) + { + // + XPosition iPosition = positions[i]; + bool isOwn = iPosition + .IsFiltersPassed( + symbol, + provider, + NULL, + X_POSITION_TYPE_ALL, + iPosition.magic // + ); + if (isOwn) + { + // + AddRef( + iPosition, + ownPositions // + ); + + // + bool isLong = IsLong(positions[i].type); + if (isLong) + { + // + AddRef( + iPosition, + ownLongPositions // + ); + } + else + { + // + AddRef( + iPosition, + ownShortPositions // + ); + } + } + } + + // + // Check Extracted Positions ... + + // + count = ArraySize(ownPositions); + + // + int longsCount = ArraySize(ownLongPositions); + bool hasLongs = IsValidSize(longsCount); + + // + int shortsCount = ArraySize(ownShortPositions); + bool hasShorts = IsValidSize(shortsCount); + + // + // Validate Own Positions ... + result = IsValidSize(count); + if (!result) + { + // + Clean(ownPositions); + Clean(ownLongPositions); + Clean(ownShortPositions); + + // + return result; + } + + // + // + // + + // + // Get Global and Common Guards ... + + // + ENUM_X_121_SMC_GUARD_ACTIONS ignoreGuards[1] = { + X_121_SMC_GUARD_ACTION_TRAIL_STOP // + }; + result = DetectX121SMCGuards( + provider, + guards, + positions, + decisionCycleHelper, + analyseCycleHelper, + consolidationCycleHelper, + visionCycleHelper, + // + ignoreGuards + // + ); + + // + // + // + + // + // Implement Custom Implemented Guards ... + + // + // Here we Are Sure there is Positions to Guard ... + // based on Current Provider ... + + // + // Detect Required Data for Analyse Market to Guard Positions ... + + // + int zIndex = 0; + int cIndex = zIndex + 1; + int pIndex = cIndex + 1; + int ppIndex = pIndex + 1; + + // + int loopback = 10; + + // + double ask = GetAsk(symbol); + double bid = GetBid(symbol); + datetime cTime = TimeCurrent(); + double points = GetPoints(symbol); + + // + // Cycles Conditions ... + + // + // Decision ... + ENUM_XPOI_EVENTS decisionPoiEvents[]; + ENUM_X_CYCLE_EVENTS decisionCycleEvents[]; + X121SMCCycleConditions decisionConditions; + result = decisionCycleHelper.GetConditions( + decisionCycleEvents, + decisionPoiEvents, + decisionConditions, + zIndex, + loopback // + ); + if (!result) + { + // + Clean(decisionPoiEvents); + Clean(decisionCycleEvents); + + // + decisionConditions.Clean(); + + // + result = HasChild(guards); + return result; + } + + // + // Analyse ... + ENUM_XPOI_EVENTS analysePoiEvents[]; + ENUM_X_CYCLE_EVENTS analyseCycleEvents[]; + X121SMCCycleConditions analyseConditions; + result = analyseCycleHelper.GetConditions( + analyseCycleEvents, + analysePoiEvents, + analyseConditions, + zIndex, + loopback // + ); + if (!result) + { + // + Clean(decisionPoiEvents); + Clean(decisionCycleEvents); + + // + decisionConditions.Clean(); + + // + Clean(analysePoiEvents); + Clean(analyseCycleEvents); + + // + analyseConditions.Clean(); + + // + result = HasChild(guards); + return result; + } + + // + // Consolidation ... + ENUM_XPOI_EVENTS consolidationPoiEvents[]; + ENUM_X_CYCLE_EVENTS consolidationCycleEvents[]; + X121SMCCycleConditions consolidationConditions; + result = consolidationCycleHelper.GetConditions( + consolidationCycleEvents, + consolidationPoiEvents, + consolidationConditions, + zIndex, + loopback // + ); + if (!result) + { + // + Clean(decisionPoiEvents); + Clean(decisionCycleEvents); + + // + decisionConditions.Clean(); + + // + Clean(analysePoiEvents); + Clean(analyseCycleEvents); + + // + analyseConditions.Clean(); + + // + Clean(consolidationPoiEvents); + Clean(consolidationCycleEvents); + + // + consolidationConditions.Clean(); + + // + result = HasChild(guards); + return result; + } + + // + // Vision ... + ENUM_XPOI_EVENTS visionPoiEvents[]; + ENUM_X_CYCLE_EVENTS visionCycleEvents[]; + X121SMCCycleConditions visionConditions; + result = visionCycleHelper.GetConditions( + visionCycleEvents, + visionPoiEvents, + visionConditions, + zIndex, + loopback // + ); + if (!result) + { + // + Clean(decisionPoiEvents); + Clean(decisionCycleEvents); + + // + decisionConditions.Clean(); + + // + Clean(analysePoiEvents); + Clean(analyseCycleEvents); + + // + analyseConditions.Clean(); + + // + Clean(consolidationPoiEvents); + Clean(consolidationCycleEvents); + + // + consolidationConditions.Clean(); + + // + Clean(visionPoiEvents); + Clean(visionCycleEvents); + + // + visionConditions.Clean(); + + // + result = HasChild(guards); + return result; + } + + // + // Cycles POI States ... + XPOIState visionState = visionConditions.state; + XPOIState analyseState = analyseConditions.state; + XPOIState decisionState = decisionConditions.state; + XPOIState consolidationState = consolidationConditions.state; + + // + // Cycle X121Conditions ... + X121Conditions visionXConditions = visionConditions.x121Conditions; + X121Conditions analyseXConditions = analyseConditions.x121Conditions; + X121Conditions decisionXConditions = decisionConditions.x121Conditions; + X121Conditions consolidationXConditions = consolidationConditions.x121Conditions; + + // + // + // + + // + // Selected Consolidation Zones ... + + // + int idx = -1; + bool has = false; + + // + bool hasBullishConsolidationZone = false; + XConsolidationZone bullishConsolidationZone; + has = decisionState.HasBullishConsolidationZones(); + if (has) + { + // + idx = GetYoungest(decisionState.bullishConsolidationZones); + hasBullishConsolidationZone = IsValidIndex(idx); + if (hasBullishConsolidationZone) + { + bullishConsolidationZone = decisionState.bullishConsolidationZones[idx]; + } + } + + // + bool hasBearishConsolidationZone = false; + XConsolidationZone bearishConsolidationZone; + has = decisionState.HasBearishConsolidationZones(); + if (has) + { + // + idx = GetYoungest(decisionState.bearishConsolidationZones); + hasBearishConsolidationZone = IsValidIndex(idx); + if (hasBearishConsolidationZone) + { + bearishConsolidationZone = decisionState.bearishConsolidationZones[idx]; + } + } + + // + // Here We Have all Requirements for Guarding Positions ... + + // + // Available Guards: + // X_121_SMC_GUARD_ACTION_NONE + // X_121_SMC_GUARD_ACTION_CLOSE + // X_121_SMC_GUARD_ACTION_CLOSE_ALL + // X_121_SMC_GUARD_ACTION_CLOSE_LONGS + // X_121_SMC_GUARD_ACTION_CLOSE_SHORTS + // X_121_SMC_GUARD_ACTION_PARTIAL_CLOSE + // X_121_SMC_GUARD_ACTION_TRAIL_STOP + // X_121_SMC_GUARD_ACTION_TRAIL_TARGET + // X_121_SMC_GUARD_ACTION_HEDGE + + // + // X_121_SMC_GUARD_ACTION_CLOSE: + // Close Specified Position on Specified Conditions ... + + // + // X_121_SMC_GUARD_ACTION_CLOSE_ALL: + // Close All Positions on Specified Conditions ... + + // + // X_121_SMC_GUARD_ACTION_CLOSE_LONGS: + // Close All Long Positions on Specified Conditions ... + + // + // X_121_SMC_GUARD_ACTION_CLOSE_SHORTS: + // Close All Short Positions on Specified Conditions ... + + // + // X_121_SMC_GUARD_ACTION_PARTIAL_CLOSE: + // Partial Close Specified Position on Specified Conditions ... + + // + // X_121_SMC_GUARD_ACTION_TRAIL_STOP: + // Trail Stop Specified Position on Specified Conditions ... + bool handleStoptrailingBasedOnConsolidationZones = true; + for (int i = 0; i < count; i++) + { + // + XPosition iPosition = ownPositions[i]; + + // + bool isLong = IsLong(iPosition.type); + bool isInProfit = iPosition.profit > 0; + + // + double sl = iPosition.sl; + double tp = iPosition.tp; + + // + // Trail Stops Using Consolidation Zones ... + + // + bool canTraiLonglUsingCZone = + // + handleStoptrailingBasedOnConsolidationZones && + // + (isLong && + isInProfit && + hasBullishConsolidationZone && + bullishConsolidationZone.lower > iPosition.sl && + bullishConsolidationZone.lower > iPosition.entry) + // + ; + if (canTraiLonglUsingCZone) + { + sl = bullishConsolidationZone.lower; + } + + // + bool canTraiShortlUsingCZone = + // + handleStoptrailingBasedOnConsolidationZones && + // + (!isLong && + isInProfit && + hasBearishConsolidationZone && + bearishConsolidationZone.upper < iPosition.sl && + bearishConsolidationZone.upper < iPosition.entry) + // + ; + if (canTraiShortlUsingCZone) + { + sl = bearishConsolidationZone.upper; + } + + // + bool canTrailUsingCZone = + canTraiLonglUsingCZone || + canTraiShortlUsingCZone; + + // + bool isSLPassed = + sl > 0 && + (isLong + ? iPosition.price - sl >= points * 15 + : sl - iPosition.price >= points * 15); + + // + bool canTrail = + isSLPassed && + canTrailUsingCZone; + if (canTrail) + { + // + X121SMCGuard iGuard; + + // + iGuard.time = cTime; + iGuard.symbol = symbol; + iGuard.provider = provider; + iGuard.action = X_121_SMC_GUARD_ACTION_TRAIL_STOP; + + // + iGuard.ticket = iPosition.ticket; + + // + iGuard.sl = sl; + + // + AddGuard( + iGuard, + guards // + ); + } + } + + // + // X_121_SMC_GUARD_ACTION_TRAIL_TARGET: + // Trail Target Specified Position on Specified Conditions ... + + // + // X_121_SMC_GUARD_ACTION_HEDGE: + // Hedge all Positions on Specified Conditions ... + + // + // Cleanup Collections ... + + // + Clean(ownPositions); + Clean(ownLongPositions); + Clean(ownShortPositions); + + // + visionState.Clean(); + analyseState.Clean(); + decisionState.Clean(); + consolidationState.Clean(); + + // + visionConditions.Clean(); + analyseConditions.Clean(); + decisionConditions.Clean(); + consolidationConditions.Clean(); + + // + visionXConditions.Clean(); + analyseXConditions.Clean(); + decisionXConditions.Clean(); + consolidationXConditions.Clean(); + + // + Clean(visionPoiEvents); + Clean(analysePoiEvents); + Clean(decisionPoiEvents); + Clean(consolidationPoiEvents); + + // + Clean(visionCycleEvents); + Clean(analyseCycleEvents); + Clean(decisionCycleEvents); + Clean(consolidationCycleEvents); + + // + count = ArraySize(guards); + result = IsValidSize(count); + + // + return result; + } + + // + // Add Conditions to Conditions Collection ... + int AddConditionsIfNotExists( + int maxAllowed = 10 // + ) + { + // + int result = 0; + + // + bool isSetuped = IsValid(mConditions.setupTime) && + HasDirection(mConditions.dir); + if (!isSetuped) + { + return result; + } + + // + int count = ArraySize(mConditionsCollection); + if (IsValidSize(count)) + { + // + // Copy Original Items ... + X121SMCStrategyXWZSignalConditions tmpItems[]; + Copy( + mConditionsCollection, + tmpItems // + ); + + // + // Prese Item Data ... + bool isBullish = IsBullish(mConditions.dir); + + // + for (int i = 0; i < count; i++) + { + // + X121SMCStrategyXWZSignalConditions iItem = tmpItems[i]; + + // + bool canRemove = mConditions.dir == iItem.dir && + mConditions.pivot == iItem.pivot; + if (canRemove) + { + // + ArrayRemove( + mConditionsCollection, + i, + 1 // + ); + } + } + + // + Clean(tmpItems); + } + + // + AddRef( + mConditions, + mConditionsCollection // + ); + + // + // Remove Olds ... + CleanupArray( + mConditionsCollection, + maxAllowed // + ); + + // + result = ArraySize(mConditionsCollection); + + // + return result; + } + + // + // Draw Functions ... + // + + // + void DrawBar( + XOHCL &bar, + XCPOIDrawer *drawer, + bool forceClean = true // + ) + { + // + if (forceClean) + { + mBarObjects.Clear(); + } + + // + if (drawer == NULL || + !bar.IsValid()) + { + return; + } + + // + bool isBullish = bar.IsBullish(); + + // + int widthBar = 2; + bool fillShadowsBar = true; + ENUM_LINE_STYLE styleBar = STYLE_SOLID; + color clrBar = + isBullish + ? clrAqua + : clrMagenta; + + // + datetime to = bar.NextAt(); + + // + XCOHCLObject *iObj; + bool isCreated = drawer + .CreateBar( + bar, + iObj, + to // + ); + if (isCreated) + { + // + iObj.BarSpes( + widthBar, + clrBar, + styleBar // + ); + + // + iObj.LowShadowFill(fillShadowsBar); + iObj.HighShadowFill(fillShadowsBar); + + // + mBarObjects.Add(iObj); + } + } + + // + protected: + // + + // + private: + // + // Props ... + string symbol; + ENUM_TIMEFRAMES period; + CArrayObj mObjects; + CArrayObj mBarObjects; + CArrayObj mWorkingZoneObjects; + + /** + * Initialize ... + */ + void Init() + { + } + + /** + * DeInitialize ... + */ + void DeInit() + { + // + mConditions.Clean(); + workingZone.Clean(); + Clean(mConditionsCollection); + + // + mBarObjects.Clear(); + } + + /** + * Update To Time of Exists Components ... + * + * @param value: updated time ... + */ + void UpdateTo( + datetime value = NULL // + ) + { + // + value = NormalizeTime(value); + + // + workingZone.UpdateTo(value); + } + + // + // Helpers ... + + // + bool CalculateRiskReward( + ENUM_X121SMC_XWZ_PRIORITY priority, + double &reward, + double &amountPercent // + ) + { + // + bool result = false; + + // + reward = 0; + amountPercent = 0; + + // + result = priority != X121SMC_XWZ_PRIORITY_NONE; + if (!result) + { + return result; + } + + // + switch (priority) + { + // + case X121SMC_XWZ_PRIORITY_STRONG_HIGH: + // + reward = 6; + amountPercent = 2; + break; + + // + case X121SMC_XWZ_PRIORITY_HIGH: + // + reward = 4; + amountPercent = 2; + break; + + // + case X121SMC_XWZ_PRIORITY_REGULAR: + // + reward = 3; + amountPercent = 1.5; + break; + + // + case X121SMC_XWZ_PRIORITY_LOW: + // + reward = 2; + amountPercent = 1; + break; + + // + case X121SMC_XWZ_PRIORITY_WEAK: + // + reward = 1; + amountPercent = 0.5; + break; + } + + // + result = + // + reward > 0 && + amountPercent > 0 + // + ; + + // + return result; + } + + // +}; + +// \ No newline at end of file diff --git a/Documents/BKP/x-121.smc.xwz.signal.lib copy 2.mq5 b/Documents/BKP/x-121.smc.xwz.signal.lib copy 2.mq5 new file mode 100644 index 00000000..8aa5b9cd --- /dev/null +++ b/Documents/BKP/x-121.smc.xwz.signal.lib copy 2.mq5 @@ -0,0 +1,3189 @@ +/////////////////////////////////////////////////////// +// +// SaherElm IT Center MQL5 X121 SMC Signal Class +// ------------------------------------------------- +// Name: XWZ +// Description: provide all Signalling functions ... +// +// +// Maintainer: +// ------------ +// Hadi Khazaee Asl (hadi_khazaee_asl@yahoo.com) +// +////////////////////////////////////////////////////// +// +// Global Properties ... +#property library +#property copyright "Copyright 2023, SaherElm IT Center" +#property link "https://www.saherelm.ir" +#property version "1.00" +#property strict + +// +// Imports ... +// #include "../../Libraries/x-trade.lib" +#include "../Classes/x-121.smc.market.cycle.helper.class.mq5" +#include "../Libraries/x-121.smc.guard.lib.mq5" +#include "../Libraries/x-121.smc.lib.mq5" + +// +enum ENUM_X121SMC_XWZ_PROVIDERS +{ + X121SMC_XWZ_PROVIDER_NONE, + X121SMC_XWZ_PROVIDER_PV_ZONE, + X121SMC_XWZ_PROVIDER_ACTIVATED_ZONE, + X121SMC_XWZ_PROVIDER_ACTIVATED_CHOCH, + X121SMC_XWZ_PROVIDER_PRICE_INSIDE_ZONE, +}; + +// +enum ENUM_X121SMC_XWZ_PRIORITY +{ + X121SMC_XWZ_PRIORITY_NONE, + X121SMC_XWZ_PRIORITY_WEAK, + X121SMC_XWZ_PRIORITY_LOW, + X121SMC_XWZ_PRIORITY_REGULAR, + X121SMC_XWZ_PRIORITY_HIGH, + X121SMC_XWZ_PRIORITY_STRONG_HIGH, +}; + +// +// Definitions ... + +// +struct X121SMCStrategyXWZWorkingZone +{ + // + // Props ... + + // + string symbol; + ENUM_TIMEFRAMES period; + + // + double quarter1; + double quarter2; + double quarter3; + + // + XCSupplyZone *supplyZone; + XCDemandZone *demandZone; + + // + XCSupplyZone *supplyZones[]; + XCDemandZone *demandZones[]; + + // + XCSupportZone *supportZones[]; + XCResistanceZone *resistanceZones[]; + + // + XBoxZone insideBoxes[]; + XBoxZone breakedBoxes[]; + XBoxZone waitingBoxes[]; + XBoxZone breakedInsideBoxes[]; + XConsolidationZone consolidationZones[]; + + // + CArrayObj mInsideZoneObjects; + CArrayObj mBreakedZoneObjects; + CArrayObj mWaitingZoneObjects; + CArrayObj mWorkingZoneObjects; + CArrayObj mBreakedInsideZoneObjects; + + // + bool mUseSupDems; + bool mUseOrderBlocks; + bool mUseFairValueGaps; + + // + // Constructor ... + X121SMCStrategyXWZWorkingZone() + { + Clean(); + } + + // + // Tools ... + + // + void Clean() + { + // + quarter1 = 0; + quarter2 = 0; + quarter3 = 0; + + // + symbol = NULL; + period = NULL; + + // + Clean(supplyZones); + Clean(demandZones); + + // + Clean(insideBoxes); + Clean(breakedBoxes); + Clean(waitingBoxes); + + // + Clean(supportZones); + Clean(resistanceZones); + + // + ZeroMemory(supplyZone); + ZeroMemory(demandZone); + + // + mInsideZoneObjects.Clear(); + mBreakedZoneObjects.Clear(); + mWaitingZoneObjects.Clear(); + mWorkingZoneObjects.Clear(); + mBreakedInsideZoneObjects.Clear(); + + // + mUseSupDems = false; + mUseOrderBlocks = true; + mUseFairValueGaps = true; + } + + // + bool IsValid() + { + // + bool result = false; + + // + result = + // + quarter1 > 0 && + quarter2 > 0 && + quarter3 > 0 && + HasSupplyZone() && + HasDemandZone() && + quarter1 > quarter2 && + quarter2 > quarter3 + // + ; + + // + return result; + } + + // + bool Init( + string _symbol, + ENUM_TIMEFRAMES _period, + int barIndex, + XPOIState &htfState, + XPOIState &mtfState, + XPOIState &stfState, // + XPOIState &ttfState // + ) + { + // + bool result = false; + + // + if (barIndex < 0) + { + barIndex = 0; + } + + // + result = + // + IsValid(_symbol) && + IsValid(_period) && + // + htfState.IsValid() && + mtfState.IsValid() && + stfState.IsValid() && + ttfState.IsValid() && + // + htfState.HasChild() && + mtfState.HasChild() && + stfState.HasChild() && + ttfState.HasChild() + // + ; + if (!result) + { + return result; + } + + // + symbol = _symbol; + period = _period; + + // + int idx = -1; + int count = 0; + bool has = false; + + // + XOHCL zBar; + has = zBar.Init( + symbol, + period, + barIndex // + ); + result = has; + if (!result) + { + zBar.Clean(); + return result; + } + double ll5 = zBar.FindLowest(5, MODE_LOW); + double hh5 = zBar.FindHighest(5, MODE_HIGH); + zBar.Clean(); + + // + // Supply Zone ... + has = HasSupplyZone(); + if (!has) + { + // + idx = GetHighest(mtfState.supplyZones); + has = IsValidIndex(idx); + if (has) + { + // + supplyZone = mtfState.supplyZones[idx]; + has = hh5 < supplyZone.Lower(); + if (!has) + { + supplyZone = NULL; + } + } + } + + // + // Demand Zone ... + has = HasDemandZone(); + if (!has) + { + // + idx = GetLowest(mtfState.demandZones); + has = IsValidIndex(idx); + if (has) + { + // + demandZone = mtfState.demandZones[idx]; + has = ll5 > demandZone.Upper(); + if (!has) + { + demandZone = NULL; + } + } + } + + // + // + // + + // // + // // Supply Zones ... + // has = HasSupplyZones(); + // if (!has) + // { + // // + // count = mtfState.FilterSupplyZones( + // supplyZones, + // period, + // XZONE_STATE_PASSED, + // false, + // XZONE_STATE_FAILED, + // false, + // XZONE_STATE_FAILED, + // false, + // XZONE_STATE_IGNORED, + // false // + // ); + // } + + // // + // // Demand Zones ... + // has = HasDemandZones(); + // if (!has) + // { + // // + // count = mtfState.FilterDemandZones( + // demandZones, + // period, + // XZONE_STATE_PASSED, + // false, + // XZONE_STATE_FAILED, + // false, + // XZONE_STATE_FAILED, + // false, + // XZONE_STATE_IGNORED, + // false // + // ); + // } + + // + // Support Zones ... + // has = HasSupportZones(); + // if (!has) + // { + // // + // count = mtfState.FilterSupportZones( + // supportZones, + // period, + // XZONE_STATE_PASSED, + // false, + // XZONE_STATE_FAILED, + // false, + // XZONE_STATE_FAILED, + // false, + // XZONE_STATE_IGNORED, + // false // + // ); + // } + + // + // Resistance Zones ... + // has = HasResistanceZones(); + // if (!has) + // { + // // + // count = mtfState.FilterResistanceZones( + // resistanceZones, + // period, + // XZONE_STATE_PASSED, + // false, + // XZONE_STATE_FAILED, + // false, + // XZONE_STATE_FAILED, + // false, + // XZONE_STATE_IGNORED, + // false // + // ); + // } + + // + has = ttfState.HasConsolidationZones(); + if (has) + { + // + Copy( + ttfState.consolidationZones, + consolidationZones // + ); + CleanupArray( + consolidationZones, + 50 // + ); + } + + // + if (supplyZone != NULL && + demandZone != NULL && + supplyZone.IsValid() && + demandZone.IsValid()) + { + // + double upper = supplyZone.Lower(); + double lower = demandZone.Upper(); + + // + double delta = ((upper - lower) / 100) * 25; + + // + quarter1 = upper - (1 * delta); + quarter2 = upper - (2 * delta); + quarter3 = upper - (3 * delta); + } + + // + // Waiting Zone Detection ... + // XPOIState iState = mtfState; + + // + // Detect Waiting Zones ... + + // // + // // Using Order Blocks ... + // if (mUseOrderBlocks) + // { + // // + // has = iState.HasOrderBlocks(); + // if (has) + // { + // // + // XCOrderBlock *obs[]; + // count = iState.FilterOrderBlocks( + // obs, + // period, + // XZONE_STATE_PASSED, + // false, + // XZONE_STATE_FAILED, + // false, + // XZONE_STATE_FAILED, + // false, + // XZONE_STATE_IGNORED, + // false // + // ); + + // // + // has = IsValidSize(count); + // if (has) + // { + // // + // ToBox( + // obs, + // waitingBoxes // + // ); + // } + + // // + // Clean(obs); + // } + // } + + // // + // // Using Fair Value Gaps ... + // if (mUseFairValueGaps) + // { + // // + // has = iState.HasFairValueGaps(); + // if (has) + // { + // // + // XBoxZone boxes[]; + // XCFVG *fvgs[]; + // count = iState.FilterFairValueGaps( + // fvgs, + // period, + // XZONE_STATE_PASSED, + // false, + // XZONE_STATE_FAILED, + // false, + // XZONE_STATE_FAILED, + // false, + // XZONE_STATE_IGNORED, + // false // + // ); + + // // + // has = IsValidSize(count); + // if (has) + // { + // // + // count = ToBox( + // fvgs, + // boxes // + // ); + + // // + // for (int i = 0; i < count; i++) + // { + // // + // XBoxZone iBox = boxes[i]; + + // // + // int idx = FindIndex( + // iBox, + // waitingBoxes // + // ); + // has = !IsValidIndex(idx); + // if (has) + // { + // // + // AddRef( + // iBox, + // waitingBoxes // + // ); + // } + + // // + // iBox.Clean(); + // } + // } + + // // + // Clean(fvgs); + // Clean(boxes); + // } + // } + + // + // Cleaning State ... + // iState.Clean(); + + // + result = IsValid(); + if (!result) + { + Clean(); + } + + // + return result; + } + + // + void Update( + int barIndex, + XPOIState &htfState, + XPOIState &mtfState, + XPOIState &stfState, + XPOIState &ttfState // + ) + { + // + int idx = -1; + int count = 0; + bool has = false; + + // + if (barIndex < 0) + { + barIndex = 0; + } + + // + has = + // + IsValid() && + // + htfState.IsValid() && + mtfState.IsValid() && + stfState.IsValid() && + // + htfState.HasChild() && + mtfState.HasChild() && + stfState.HasChild() + // + ; + if (!has) + { + return; + } + + // + XOHCL zBar; + has = zBar.Init( + symbol, + period, + barIndex // + ); + if (!has) + { + // + zBar.Clean(); + return; + } + + // + XOHCL cBar; + has = zBar.GetPreviousBar(cBar); + if (!has) + { + // + zBar.Clean(); + cBar.Clean(); + + // + return; + } + + // + // Update Exists Zones ... + + // + // Supply Zones ... + has = mtfState.HasSupplyZones(); + if (has) + { + // + XCSupplyZone *zone; + idx = GetYoungest(mtfState.supplyZones); + has = IsValidIndex(idx); + if (has) + { + // + zone = mtfState.supplyZones[idx]; + has = IsSupplyExists(zone); + if (!has) + { + // + Add( + zone, + supplyZones // + ); + } + else + { + ZeroMemory(zone); + } + } + } + + // + // Demand Zones ... + has = mtfState.HasDemandZones(); + if (has) + { + // + XCDemandZone *zone; + idx = GetYoungest(mtfState.demandZones); + has = IsValidIndex(idx); + if (has) + { + // + zone = mtfState.demandZones[idx]; + has = IsDemandExists(zone); + if (!has) + { + // + Add( + zone, + demandZones // + ); + } + else + { + ZeroMemory(zone); + } + } + } + + // + // + // + + // + // Supply Zones ... + has = HasSupplyZones(); + if (has) + { + // + int removeIDXs[]; + count = CountSupplyZones(); + for (int i = 0; i < count; i++) + { + // + XCSupplyZone *iZone = supplyZones[i]; + ENUM_X_DIRECTION iDir = X_DIRECTION_BEARISH; + + // + XBoxZone iBox; + bool hasBox = ToBox( + iBox, + iZone // + ); + if (!hasBox) + { + // + iBox.Clean(); + continue; + } + + // + XOHCL passedBar; + bool isBodyIn = false; + bool isBodyOut = false; + + // + // Check Activation ... + bool isActivated = iZone.IsActivated( + iDir, + passedBar, + isBodyIn, + true, + period // + ); + if (isActivated) + { + // + // AddRef( + // iBox, + // insideBoxes // + // ); + + // + Add( + i, + removeIDXs // + ); + + // + iBox.Clean(); + passedBar.Clean(); + continue; + } + + // + // Checking Breaked ... + bool isBreaked = iZone.IsBreaked( + iDir, + passedBar, + isBodyOut, + false, + true, + period // + ); + if (isBreaked) + { + // // + // AddRef( + // iBox, + // breakedBoxes // + // ); + + // + Add( + i, + removeIDXs // + ); + + // + iBox.Clean(); + passedBar.Clean(); + continue; + } + + // + passedBar.Clean(); + } + + // + count = ArraySize(removeIDXs); + has = IsValidSize(count); + if (has) + { + // + CleanupArray( + removeIDXs, + supplyZones // + ); + } + + // + Clean(removeIDXs); + } + + // + // Demand Zones ... + has = HasDemandZones(); + if (has) + { + // + int removeIDXs[]; + count = CountDemandZones(); + for (int i = 0; i < count; i++) + { + // + XCDemandZone *iZone = demandZones[i]; + ENUM_X_DIRECTION iDir = X_DIRECTION_BULLISH; + + // + XBoxZone iBox; + bool hasBox = ToBox( + iBox, + iZone // + ); + if (!hasBox) + { + // + iBox.Clean(); + continue; + } + + // + XOHCL passedBar; + bool isBodyIn = false; + bool isBodyOut = false; + + // + // Check Activation ... + bool isActivated = iZone.IsActivated( + iDir, + passedBar, + isBodyIn, + true, + period // + ); + if (isActivated) + { + // + // AddRef( + // iBox, + // insideBoxes // + // ); + + // + Add( + i, + removeIDXs // + ); + + // + iBox.Clean(); + passedBar.Clean(); + continue; + } + + // + // Checking Breaked ... + bool isBreaked = iZone.IsBreaked( + iDir, + passedBar, + isBodyOut, + false, + true, + period // + ); + if (isBreaked) + { + // // + // AddRef( + // iBox, + // breakedBoxes // + // ); + + // + Add( + i, + removeIDXs // + ); + + // + iBox.Clean(); + passedBar.Clean(); + continue; + } + + // + passedBar.Clean(); + } + + // + count = ArraySize(removeIDXs); + has = IsValidSize(count); + if (has) + { + // + CleanupArray( + removeIDXs, + demandZones // + ); + } + + // + Clean(removeIDXs); + } + + // + // Update Boxes ... + + // + // Waiting Boxes ... + has = HasWaitingBoxes(); + if (has) + { + // + int removeIDXs[]; + count = CountWaitingBoxes(); + for (int i = 0; i < count; i++) + { + // + XBoxZone iBox = waitingBoxes[i]; + ENUM_X_DIRECTION iDir = iBox.dir; + bool isBullish = IsBullish(iDir); + + // + bool isInside = + // + zBar.low < iBox.upper && + zBar.low > iBox.lower + // + ; + if (isInside) + { + // + AddRef( + iBox, + insideBoxes // + ); + + // + Add( + i, + removeIDXs // + ); + + // + iBox.Clean(); + break; + } + + // + bool isBreakedUpper = + // + cBar.low < iBox.upper && + cBar.low > iBox.lower && + zBar.low > iBox.upper + // + ; + + // + bool isBreakedLower = + // + cBar.high > iBox.lower && + cBar.high < iBox.upper && + zBar.high < iBox.lower + // + ; + + // + bool isBreaked = + (isBullish && + isBreakedLower) || + (!isBullish && + isBreakedUpper); + + // + if (isBreaked) + { + // + AddRef( + iBox, + breakedBoxes // + ); + + // + Add( + i, + removeIDXs // + ); + + // + iBox.Clean(); + break; + } + } + + // + count = ArraySize(removeIDXs); + has = IsValidSize(count); + if (has) + { + // + CleanupArray( + removeIDXs, + waitingBoxes // + ); + } + + // + Clean(removeIDXs); + } + + // + // Inside Boxes ... + has = HasInsideBoxes(); + if (has) + { + // + int removeIDXs[]; + count = CountInsideBoxes(); + for (int i = 0; i < count; i++) + { + // + XBoxZone iBox = insideBoxes[i]; + ENUM_X_DIRECTION iDir = iBox.dir; + bool isBullish = IsBullish(iDir); + + // + bool isBreakedUpper = + // + cBar.low < iBox.upper && + cBar.low > iBox.lower && + zBar.low > iBox.upper + // + ; + + // + bool isBreakedLower = + // + cBar.high > iBox.lower && + cBar.high < iBox.upper && + zBar.high < iBox.lower + // + ; + + // + bool isBreaked = + (isBullish && + isBreakedLower) || + (!isBullish && + isBreakedUpper); + + // + if (isBreaked) + { + // + AddRef( + iBox, + breakedBoxes // + ); + + // + Add( + i, + removeIDXs // + ); + + // + iBox.Clean(); + break; + } + } + + // + count = ArraySize(removeIDXs); + has = IsValidSize(count); + if (has) + { + // + CleanupArray( + removeIDXs, + insideBoxes // + ); + } + + // + Clean(removeIDXs); + } + + // + has = HasBreakedBoxes(); + if (has) + { + // + int removeIDXs[]; + count = CountBreakedBoxes(); + for (int i = 0; i < count; i++) + { + // + XBoxZone iBox = breakedBoxes[i]; + ENUM_X_DIRECTION iDir = iBox.dir; + bool isBullish = IsBullish(iDir); + + // + bool isInside = false; + + // + if (isInside) + { + // + AddRef( + iBox, + breakedInsideBoxes // + ); + + // + Add( + i, + removeIDXs // + ); + + // + iBox.Clean(); + break; + } + } + + // + count = ArraySize(removeIDXs); + has = IsValidSize(count); + if (has) + { + // + CleanupArray( + removeIDXs, + breakedBoxes // + ); + } + + // + Clean(removeIDXs); + } + + // + // Update Waiting Boxes ... + + // + XPOIState iState = mtfState; + + // + // Use Order Blocks ... + if (mUseOrderBlocks) + { + // + has = iState.HasOrderBlocks(); + if (has) + { + // + XCOrderBlock *obs[]; + count = iState.FilterOrderBlocks( + obs, + period, + XZONE_STATE_PASSED, + false, + XZONE_STATE_FAILED, + false, + XZONE_STATE_FAILED, + false, + XZONE_STATE_IGNORED, + false // + ); + + // + has = IsValidSize(count); + if (has) + { + // + // Try to Add new OBs into Waiting Zones ... + // if it's not exists ... + for (int i = 0; i < count; i++) + { + // + XBoxZone iBox; + bool hasBox = ToBox( + iBox, + obs[i] // + ); + if (!hasBox) + { + // + iBox.Clean(); + continue; + } + + // + // Check Index in Waiting Boxes ... + idx = FindIndex( + iBox, + waitingBoxes // + ); + has = !IsValidIndex(idx); + if (!has) + { + // + iBox.Clean(); + continue; + } + + // + // Check Index in Inside Boxes ... + idx = FindIndex( + iBox, + insideBoxes // + ); + has = !IsValidIndex(idx); + if (!has) + { + // + iBox.Clean(); + continue; + } + + // + // Check Index in Breaked Boxes ... + idx = FindIndex( + iBox, + breakedBoxes // + ); + has = !IsValidIndex(idx); + if (!has) + { + // + iBox.Clean(); + continue; + } + + // + AddRef( + iBox, + waitingBoxes // + ); + } + } + + // + Clean(obs); + } + } + + // + // Use Fair Value Gaps ... + if (mUseFairValueGaps) + { + // + has = iState.HasFairValueGaps(); + if (has) + { + // + XCFVG *fvgs[]; + count = iState.FilterFairValueGaps( + fvgs, + period, + XZONE_STATE_PASSED, + false, + XZONE_STATE_FAILED, + false, + XZONE_STATE_FAILED, + false, + XZONE_STATE_IGNORED, + false // + ); + + // + has = IsValidSize(count); + if (has) + { + // + for (int i = 0; i < count; i++) + { + // + XBoxZone iBox; + bool hasBox = ToBox( + iBox, + fvgs[i] // + ); + if (!hasBox) + { + // + iBox.Clean(); + continue; + } + + // + // Check Index in Waiting Boxes ... + idx = FindIndex( + iBox, + waitingBoxes // + ); + has = !IsValidIndex(idx); + if (!has) + { + // + iBox.Clean(); + continue; + } + + // + // Check Index in Inside Boxes ... + idx = FindIndex( + iBox, + insideBoxes // + ); + has = !IsValidIndex(idx); + if (!has) + { + // + iBox.Clean(); + continue; + } + + // + // Check Index in Breaked Boxes ... + idx = FindIndex( + iBox, + breakedBoxes // + ); + has = !IsValidIndex(idx); + if (!has) + { + // + iBox.Clean(); + continue; + } + + // + AddRef( + iBox, + waitingBoxes // + ); + + // + iBox.Clean(); + } + } + + // + Clean(fvgs); + } + } + + // + iState.Clean(); + + // + // Cleanup Resource ... + + // + zBar.Clean(); + cBar.Clean(); + } + + // + bool IsDestroyed( + int barIndex = 0, + ENUM_TIMEFRAMES forPeriod = NULL // + ) + { + // + bool result = false; + + // + if (barIndex < 0) + { + barIndex = 0; + } + + // + if (!IsValid(forPeriod)) + { + forPeriod = period; + } + + // + result = IsValid(); + if (!result) + { + return result; + } + + // + XOHCL bar; + result = bar.Init( + symbol, + period, + barIndex // + ); + if (!result) + { + // + bar.Clean(); + return result; + } + + // + XOHCL cBar; + result = bar.GetPreviousBar(cBar); + if (!result) + { + // + bar.Clean(); + cBar.Clean(); + + // + return result; + } + + // + bool isSupplyZoneBreaked = + // + bar.low > supplyZone.Upper() && + cBar.low > supplyZone.Upper() + // + ; + + // + bool isDemandZoneBreaked = + // + bar.high < demandZone.Lower() && + cBar.high < demandZone.Lower() + // + ; + + // + bar.Clean(); + cBar.Clean(); + + // + result = isSupplyZoneBreaked || + isDemandZoneBreaked; + + // + return result; + } + + // + bool DetectPriority( + ENUM_X121SMC_XWZ_PRIORITY &priority, + ENUM_X_DIRECTION forDir, + int barIndex = 0, + ENUM_TIMEFRAMES forPeriod = NULL // + ) + { + // + bool result = false; + + // + priority = X121SMC_XWZ_PRIORITY_NONE; + + // + if (barIndex < 0) + { + barIndex = 0; + } + + // + if (!IsValid(forPeriod)) + { + forPeriod = period; + } + + // + result = IsValid() && + HasDirection(forDir); + if (!result) + { + return result; + } + + // + bool isBullish = IsBullish(forDir); + + // + XOHCL bar; + result = bar.Init( + symbol, + forPeriod, + barIndex // + ); + if (!result) + { + // + bar.Clean(); + return result; + } + + // + if (bar.high < supplyZone.Upper() && + bar.low > supplyZone.Lower()) + { + // + priority = + isBullish + ? X121SMC_XWZ_PRIORITY_NONE + : X121SMC_XWZ_PRIORITY_STRONG_HIGH; + } + else if (bar.high < supplyZone.Lower() && + bar.low > quarter1) + { + // + priority = + isBullish + ? X121SMC_XWZ_PRIORITY_WEAK + : X121SMC_XWZ_PRIORITY_HIGH; + } + else if (bar.high < quarter1 && + bar.low > quarter2) + { + // + priority = + isBullish + ? X121SMC_XWZ_PRIORITY_LOW + : X121SMC_XWZ_PRIORITY_REGULAR; + } + else if (bar.high < quarter2 && + bar.low > quarter3) + { + // + priority = + isBullish + ? X121SMC_XWZ_PRIORITY_REGULAR + : X121SMC_XWZ_PRIORITY_LOW; + } + else if (bar.high < quarter3 && + bar.low > demandZone.Upper()) + { + // + priority = + isBullish + ? X121SMC_XWZ_PRIORITY_HIGH + : X121SMC_XWZ_PRIORITY_WEAK; + } + else if (bar.high < demandZone.Upper() && + bar.low > demandZone.Lower()) + { + // + priority = + isBullish + ? X121SMC_XWZ_PRIORITY_STRONG_HIGH + : X121SMC_XWZ_PRIORITY_NONE; + } + + // + result = priority != X121SMC_XWZ_PRIORITY_NONE && + priority != X121SMC_XWZ_PRIORITY_WEAK; + + // + bar.Clean(); + + // + return result; + } + + // + bool DetectSenarioASignalBox( + XBoxZone &signalBox, + ENUM_X_DIRECTION &signalDir, + X121Conditions &decisionXConditions, + X121Conditions &analyseXConditions, + XC121SMCCycleHelper *decisionCycleHelper, + XCPOIDrawer *drawer = NULL, + int barIndex = 0 // + ) + { + // + bool result = false; + + // + signalBox.Clean(); + signalDir = X_DIRECTION_NONE; + + // + if (barIndex < 0) + { + barIndex = 0; + } + + // + result = decisionCycleHelper != NULL; + if (!result) + { + return result; + } + + // + // Decision ... + double decisionBullishScore = 0; + double decisionBearishScore = 0; + decisionXConditions.GenerateScore( + decisionBullishScore, + decisionBearishScore // + ); + + // + // Analyse ... + double analyseBullishScore = 0; + double analyseBearishScore = 0; + analyseXConditions.GenerateScore( + analyseBullishScore, + analyseBearishScore // + ); + + // + // Score Conditions ... + double scoreMultiplier = 3; + bool isBullishScorePassed = + // + analyseBullishScore > (analyseBearishScore * scoreMultiplier) && + decisionBullishScore > (decisionBearishScore * scoreMultiplier) + // + ; + bool isBearishScorePassed = + // + analyseBearishScore > (analyseBullishScore * scoreMultiplier) && + decisionBearishScore > (decisionBullishScore * scoreMultiplier) + // + ; + + // + // Checking Other Conditions + + // + bool isCommonBullish = + // + decisionXConditions.isSarBullish && + decisionXConditions.isStrBullish && + decisionXConditions.isCheBullish && + decisionXConditions.isSMHKBullish && + decisionXConditions.isRawHKBullish && + decisionXConditions.isRawHKClosedOverSMHK + // + ; + + // + bool isCommonBearish = + // + decisionXConditions.isSarBearish && + decisionXConditions.isStrBearish && + decisionXConditions.isCheBearish && + decisionXConditions.isSMHKBearish && + decisionXConditions.isRawHKBearish && + decisionXConditions.isRawHKClosedUnderSMHK + // + ; + + // + // X3Ma ... + + // + // X3Ma Bullish ... + bool isX3MaBullish = + // + decisionXConditions.isX3MaBullishState && + decisionXConditions.isX3MaSwitchedToBullishOrdered && + decisionXConditions.x3maMidBuffer[1] > decisionXConditions.x3maSlowBuffer[1] + // + ; + + // + // X3Ma Bearish ... + bool isX3MaBearish = + // + decisionXConditions.isX3MaBearishState && + decisionXConditions.isX3MaSwitchedToBearishOrdered && + decisionXConditions.x3maMidBuffer[1] < decisionXConditions.x3maSlowBuffer[1] + // + ; + + // + bool isX3MaHasCondition = + (isX3MaBullish && + isCommonBullish && + isBullishScorePassed) || + (isX3MaBearish && + isCommonBearish && + isBearishScorePassed); + + // + // VWap ... + + // + // VWap Bullish ... + bool isVWapBullish = + // + decisionXConditions.isVWapBullishState && + decisionXConditions.isVWapSwitchedToBullishOrdered && + decisionXConditions.vwapMidBuffer[1] > decisionXConditions.vwapSlowBuffer[1] + // + ; + + // + // VWap Bearish ... + bool isVWapBearish = + // + decisionXConditions.isVWapBearishState && + decisionXConditions.isVWapSwitchedToBearishOrdered && + decisionXConditions.vwapMidBuffer[1] < decisionXConditions.vwapSlowBuffer[1] + // + ; + + // + bool isVWapHasCondition = + (isVWapBullish && + isBullishScorePassed) || + (isVWapBearish && + isBearishScorePassed); + + // + // Senario .... + // - a vale Under X3MA Slow when X3MA Bullish Ordered ... + + // + bool isX3MASenarioBBullish = + // + decisionXConditions.isX3MaBullishOrdered && + decisionXConditions.valesBuffer[1] < decisionXConditions.x3maSlowBuffer[1] && + decisionXConditions.valesBuffer[2] >= decisionXConditions.x3maSlowBuffer[2] + // + ; + if (isX3MASenarioBBullish) + { + } + + // + bool isX3MASenarioBBearish = + // + decisionXConditions.isX3MaBearishOrdered && + decisionXConditions.peaksBuffer[1] > decisionXConditions.x3maSlowBuffer[1] && + decisionXConditions.peaksBuffer[2] <= decisionXConditions.x3maSlowBuffer[2] + // + ; + if (isX3MASenarioBBearish) + { + } + + // + // Checking Other Conditions XWZ Reject on EMA 20 ... + + // + // Check Has Conditions ... + bool hasXConditions = + (isX3MaHasCondition || + isVWapHasCondition); + + // + result = hasXConditions; + if (!result) + { + return result; + } + + // + if (isX3MaHasCondition) + { + // + signalDir = + isX3MaBullish + ? X_DIRECTION_BULLISH + : isX3MaBearish + ? X_DIRECTION_BEARISH + : X_DIRECTION_NONE; + } + + // + if (isVWapHasCondition) + { + // + signalDir = + isVWapBullish + ? X_DIRECTION_BULLISH + : isVWapBearish + ? X_DIRECTION_BEARISH + : X_DIRECTION_NONE; + } + + // + // Creating SignalBox ... + + // + // Detect Box based on PV ... + bool hasSignalBox = decisionCycleHelper.GeneratePVBox( + signalBox, + barIndex // + ); + + // + result = + hasSignalBox && + signalDir == signalBox.dir; + + // + if (result) + { + // + XCBoxObject *iObj; + bool isCreated = drawer.DrawBox( + signalBox, + iObj // + ); + if (isCreated) + { + // + iObj.BoxWidth(1); + iObj.BoxColor(clrYellow); + iObj.BoxStyle(STYLE_SOLID); + } + + // + Print("Senario A ..."); + } + + // + return result; + } + + // + bool DetetctSenarioBSignalBox( + XBoxZone &signalBox, + ENUM_X_DIRECTION &signalDir, + X121Conditions &decisionXConditions, + X121Conditions &analyseXConditions, + XC121SMCCycleHelper *decisionCycleHelper, + int barIndex = 0 // + ) + { + // + bool result = false; + + // + signalBox.Clean(); + signalDir = X_DIRECTION_NONE; + + // + if (barIndex < 0) + { + barIndex = 0; + } + + // + result = decisionCycleHelper != NULL; + if (!result) + { + return result; + } + + // + // Decision ... + double decisionBullishScore = 0; + double decisionBearishScore = 0; + decisionXConditions.GenerateScore( + decisionBullishScore, + decisionBearishScore // + ); + + // + // Analyse ... + double analyseBullishScore = 0; + double analyseBearishScore = 0; + analyseXConditions.GenerateScore( + analyseBullishScore, + analyseBearishScore // + ); + + // + // Score Conditions ... + double scoreMultiplier = 3; + bool isBullishScorePassed = + // + analyseBullishScore > (analyseBearishScore * scoreMultiplier) && + decisionBullishScore > (decisionBearishScore * scoreMultiplier) + // + ; + bool isBearishScorePassed = + // + analyseBearishScore > (analyseBullishScore * scoreMultiplier) && + decisionBearishScore > (decisionBullishScore * scoreMultiplier) + // + ; + + // + // Senario .... + // - a vale Under X3MA Slow when X3MA Bullish Ordered ... + + // + bool isX3MASenarioBBullish = + // + decisionXConditions.isX3MaBullishOrdered && + decisionXConditions.valesBuffer[1] < decisionXConditions.x3maSlowBuffer[1] && + decisionXConditions.valesBuffer[2] >= decisionXConditions.x3maSlowBuffer[2] + // + ; + if (isX3MASenarioBBullish) + { + } + + // + bool isX3MASenarioBBearish = + // + decisionXConditions.isX3MaBearishOrdered && + decisionXConditions.peaksBuffer[1] > decisionXConditions.x3maSlowBuffer[1] && + decisionXConditions.peaksBuffer[2] <= decisionXConditions.x3maSlowBuffer[2] + // + ; + if (isX3MASenarioBBearish) + { + } + + // + return result; + } + + // + bool DetectOveralDirection( + ENUM_X_DIRECTION &dir // + ) + { + // + bool result = false; + + // + dir = X_DIRECTION_NONE; + + // + result = IsValid() && + HasSupplyZone() && + HasDemandZone(); + if (!result) + { + return result; + } + + // + XBoxZone demBox; + XBoxZone supBox; + result = ToBox( + demBox, + demandZone // + ); + if (!result) + { + // + supBox.Clean(); + demBox.Clean(); + + // + return result; + } + result = ToBox( + supBox, + supplyZone // + ); + if (!result) + { + // + supBox.Clean(); + demBox.Clean(); + + // + return result; + } + + // + XOHCL supPriceOutBar; + XOHCL demPriceOutBar; + result = DetectBoxNearestPriceOut( + supBox, + supPriceOutBar, + period // + ); + if (!result) + { + // + demBox.Clean(); + supBox.Clean(); + supPriceOutBar.Clean(); + demPriceOutBar.Clean(); + + // + return result; + } + result = DetectBoxNearestPriceOut( + demBox, + demPriceOutBar, + period // + ); + if (!result) + { + // + demBox.Clean(); + supBox.Clean(); + supPriceOutBar.Clean(); + demPriceOutBar.Clean(); + + // + return result; + } + + // + // Specified Direction ... + dir = + (supPriceOutBar.IsValid() && + demPriceOutBar.IsValid()) + ? supPriceOutBar.time > demPriceOutBar.time + ? X_DIRECTION_BEARISH + : demPriceOutBar.time > supPriceOutBar.time + ? X_DIRECTION_BULLISH + : X_DIRECTION_NONE + : X_DIRECTION_NONE; + + // + result = HasDirection(dir); + + // + // Clean Up Resources ... + + // + demBox.Clean(); + supBox.Clean(); + supPriceOutBar.Clean(); + demPriceOutBar.Clean(); + + // + return result; + } + + // + bool HasInsideBox( + XBoxZone &box // + ) + { + // + bool result = false; + + // + int index = -1; + + // + result = box.IsValid(); + if (!result) + { + return result; + } + + // + int count = 0; + bool has = false; + + // + has = HasWaitingBoxes(); + if (has) + { + // + result = HasInsideBox( + index, + box, + waitingBoxes // + ); + } + + // + // Supply Zones ... + if (!result) + { + // + has = HasSupplyZones(); + if (has) + { + // + XBoxZone tmpBoxes[]; + count = ToBox( + supplyZones, + tmpBoxes // + ); + + // + has = IsValidSize(count); + if (has) + { + // + result = HasInsideBox( + index, + box, + tmpBoxes // + ); + } + + // + Clean(tmpBoxes); + } + } + + // + // Demand Zones ... + if (!result) + { + // + has = HasDemandZones(); + if (has) + { + // + XBoxZone tmpBoxes[]; + count = ToBox( + demandZones, + tmpBoxes // + ); + + // + has = IsValidSize(count); + if (has) + { + // + result = HasInsideBox( + index, + box, + tmpBoxes // + ); + } + + // + Clean(tmpBoxes); + } + } + + // + result = IsValidIndex(index); + + // + return result; + } + + // + bool IsExists(XBoxZone &box) + { + // + bool result = false; + + // + result = box.IsValid(); + if (!result) + { + return result; + } + + // + int idx = -1; + bool has = false; + + // + // Checking Index Waiting Box ... + has = HasWaitingBoxes(); + if (has) + { + // + idx = FindIndex( + box, + waitingBoxes // + ); + result = !IsValidIndex(idx); + if (!result) + { + return result; + } + } + + // + // Checking Index Inside Boxes ... + has = HasInsideBoxes(); + if (has) + { + // + idx = FindIndex( + box, + insideBoxes // + ); + result = !IsValidIndex(idx); + if (!result) + { + return result; + } + } + + // + // Checking Index Breaked Boxes ... + has = HasBreakedBoxes(); + if (has) + { + // + idx = FindIndex( + box, + breakedBoxes // + ); + result = !IsValidIndex(idx); + if (!result) + { + return result; + } + } + + // + // Checking Index BreakedInside Boxes ... + has = HasBreakedInsideBoxes(); + if (has) + { + // + idx = FindIndex( + box, + breakedInsideBoxes // + ); + result = !IsValidIndex(idx); + if (!result) + { + return result; + } + } + + // + return result; + } + + // + bool IsSupplyExists(XCSupplyZone *zone) + { + // + bool result = false; + + // + result = zone != NULL && + zone.IsValid(); + if (!result) + { + return result; + } + + // + // Converts Zone to Box ... + XBoxZone box; + result = ToBox( + box, + zone // + ); + if (!result) + { + // + box.Clean(); + return result; + } + + // + // Checking Index in SupplyZones ... + int idx = FindIndex( + zone, + supplyZones // + ); + result = !IsValidIndex(idx); + if (!result) + { + // + box.Clean(); + return result; + } + + // + result = IsExists(box); + + // + box.Clean(); + + // + return result; + } + + // + bool IsDemandExists(XCDemandZone *zone) + { + // + bool result = false; + + // + result = zone != NULL && + zone.IsValid(); + if (!result) + { + return result; + } + + // + // Converts Zone to Box ... + XBoxZone box; + result = ToBox( + box, + zone // + ); + if (!result) + { + // + box.Clean(); + return result; + } + + // + // Checking Index in SupplyZones ... + int idx = FindIndex( + zone, + demandZones // + ); + result = !IsValidIndex(idx); + if (!result) + { + // + box.Clean(); + return result; + } + + // + result = IsExists(box); + + // + box.Clean(); + + // + return result; + } + + // + void UpdateTo(datetime value = NULL) + { + // + value = NormalizeTime(value); + + // + int count = 0; + bool has = false; + + // + has = HasSupplyZone(); + if (has) + { + supplyZone.To(value); + } + + // + has = HasDemandZone(); + if (has) + { + demandZone.To(value); + } + + // + has = HasSupplyZones(); + if (has) + { + // + count = CountSupplyZones(); + for (int i = 0; i < count; i++) + { + supplyZones[i].To(value); + } + } + + // + has = HasDemandZones(); + if (has) + { + // + count = CountDemandZones(); + for (int i = 0; i < count; i++) + { + demandZones[i].To(value); + } + } + + // + has = HasSupportZones(); + if (has) + { + // + count = CountSupportZones(); + for (int i = 0; i < count; i++) + { + supportZones[i].To(value); + } + } + + // + has = HasResistanceZones(); + if (has) + { + // + count = CountResistanceZones(); + for (int i = 0; i < count; i++) + { + resistanceZones[i].To(value); + } + } + + // + // + // + + // + has = HasWaitingBoxes(); + if (has) + { + // + count = ArraySize(waitingBoxes); + for (int i = 0; i < count; i++) + { + waitingBoxes[i].to = value; + } + } + + // + has = HasInsideBoxes(); + if (has) + { + // + count = CountInsideBoxes(); + for (int i = 0; i < count; i++) + { + insideBoxes[i].to = value; + } + } + + // + has = HasBreakedBoxes(); + if (has) + { + } + + // + has = HasBreakedInsideBoxes(); + if (has) + { + // + count = CountBreakedInsideBoxes(); + for (int i = 0; i < count; i++) + { + breakedInsideBoxes[i].to = value; + } + } + + // + } + + // + void Draw( + XCPOIDrawer *drawer, + bool drawWaitingBoxes = true, + bool drawInsideBoxes = false, + bool drawBreakedBoxes = false, + bool drawBreakedInsideBoxes = false, + bool drawSupplyZone = false, + bool drawDemandZone = false, + bool drawSupplyZones = false, + bool drawDemandZones = false, + bool drawSupportZones = false, + bool drawResistanceZones = false // + ) + { + // + if (drawer == NULL) + { + return; + } + + // + int count = 0; + bool has = false; + bool isCreated = false; + + // + ulong chartID = drawer.ChartIdentification(); + int subWindow = drawer.SubWindowIdentification(); + color bullishColor = drawer.BarBullishColor(); + color bearishColor = drawer.BarBearishColor(); + + // + // Supply Zone ... + if (drawSupplyZone) + { + // + has = HasSupplyZone(); + if (has) + { + // + XCSupplyZoneObject *iObj; + isCreated = drawer.CreateSupplyZone( + supplyZone, + iObj // + ); + + // + if (isCreated) + { + mWorkingZoneObjects.Add(iObj); + } + } + } + + // + // Demand Zone ... + if (drawDemandZone) + { + // + has = HasDemandZone(); + if (has) + { + // + XCDemandZoneObject *iObj; + isCreated = drawer.CreateDemandZone( + demandZone, + iObj // + ); + + // + if (isCreated) + { + mWorkingZoneObjects.Add(iObj); + } + } + } + + // + // + // + + // + // Supply Zones ... + if (drawSupplyZones) + { + // + has = HasSupplyZones(); + if (has) + { + // + count = CountSupplyZones(); + for (int i = 0; i < count; i++) + { + // + XCSupplyZoneObject *iObj; + isCreated = drawer.CreateSupplyZone( + supplyZones[i], + iObj // + ); + + // + if (isCreated) + { + mWorkingZoneObjects.Add(iObj); + } + } + } + } + + // + // Demand Zones ... + if (drawDemandZones) + { + // + has = HasDemandZones(); + if (has) + { + // + count = CountDemandZones(); + for (int i = 0; i < count; i++) + { + // + XCDemandZoneObject *iObj; + isCreated = drawer.CreateDemandZone( + demandZones[i], + iObj // + ); + + // + if (isCreated) + { + mWorkingZoneObjects.Add(iObj); + } + } + } + } + + // + // Support Zones ... + if (drawSupportZones) + { + // + has = HasSupportZones(); + if (has) + { + // + count = CountSupportZones(); + for (int i = 0; i < count; i++) + { + // + XCSupportZoneObject *iObj; + isCreated = drawer.CreateSupportZone( + supportZones[i], + iObj // + ); + + // + if (isCreated) + { + mWorkingZoneObjects.Add(iObj); + } + } + } + } + + // + // Resistance Zones ... + if (drawResistanceZones) + { + // + has = HasResistanceZones(); + if (has) + { + // + count = CountResistanceZones(); + for (int i = 0; i < count; i++) + { + // + XCResistanceZoneObject *iObj; + isCreated = drawer.CreateResistanceZone( + resistanceZones[i], + iObj // + ); + + // + if (isCreated) + { + mWorkingZoneObjects.Add(iObj); + } + } + } + } + + // + // + // + + // + // Waiting Boxes ... + if (drawWaitingBoxes) + { + // + has = HasWaitingBoxes(); + if (has) + { + // + count = CountWaitingBoxes(); + for (int i = 0; i < count; i++) + { + // + XBoxZone iBox = waitingBoxes[i]; + + // + XCBoxObject *iObj; + bool isCreated = drawer.DrawBox( + iBox, + iObj // + ); + + // + if (isCreated) + { + mWorkingZoneObjects.Add(iObj); + } + + // + iBox.Clean(); + } + } + } + + // + // Inside Boxes ... + if (drawInsideBoxes) + { + // + has = HasInsideBoxes(); + if (has) + { + } + } + + // + // Breaked Boxes ... + if (drawBreakedBoxes) + { + // + has = HasBreakedBoxes(); + if (has) + { + // + } + } + + // + // Breaked Inside Boxes ... + if (drawBreakedInsideBoxes) + { + // + has = HasBreakedInsideBoxes(); + if (has) + { + // + count = CountBreakedInsideBoxes(); + for (int i = 0; i < count; i++) + { + // + XBoxZone iBox = breakedInsideBoxes[i]; + XCBoxObject *iObj; + has = drawer.DrawBox( + iBox, + iObj // + ); + if (has) + { + // + iObj.BoxWidth(1); + mBreakedInsideZoneObjects.Add(iObj); + } + } + } + } + + // + // + // + + // + // Quarters ... + has = IsValid(); + if (has) + { + // + double zoneUpper = supplyZone.Upper(); + double upper = supplyZone.Lower(); + + // + double lower = demandZone.Upper(); + double zoneLower = demandZone.Lower(); + + // + string prefix = "X121WZone_" + symbol + "_" + ToString(period); + + // + // Zone Upper ... + CChartObjectHLine *zoneUpperLine; + zoneUpperLine = new CChartObjectHLine(); + isCreated = zoneUpperLine.Create( + chartID, + prefix + "_ZoneTop", + subWindow, + zoneUpper // + ); + if (isCreated) + { + // + zoneUpperLine.Color(clrRed); + + // + mWaitingZoneObjects.Add(zoneUpperLine); + } + + // + // Zone Lower ... + CChartObjectHLine *zoneLowerLine; + zoneLowerLine = new CChartObjectHLine(); + isCreated = zoneLowerLine.Create( + chartID, + prefix + "_ZoneDown", + subWindow, + zoneLower // + ); + if (isCreated) + { + // + zoneLowerLine.Color(clrRed); + + // + mWaitingZoneObjects.Add(zoneLowerLine); + } + + // + // Upper ... + CChartObjectHLine *upperLine; + upperLine = new CChartObjectHLine(); + isCreated = upperLine.Create( + chartID, + prefix + "_Upper", + subWindow, + upper // + ); + if (isCreated) + { + // + upperLine.Color(clrLime); + + // + mWaitingZoneObjects.Add(upperLine); + } + + // + // Lower ... + CChartObjectHLine *lowerLine; + lowerLine = new CChartObjectHLine(); + isCreated = lowerLine.Create( + chartID, + prefix + "_Lower", + subWindow, + lower // + ); + if (isCreated) + { + // + lowerLine.Color(clrLime); + + // + mWaitingZoneObjects.Add(lowerLine); + } + + // + // Quarters ... + + // + // Quarter 1 ... + CChartObjectHLine *q1Line; + q1Line = new CChartObjectHLine(); + isCreated = q1Line.Create( + chartID, + prefix + "_Q1", + subWindow, + quarter1 // + ); + if (isCreated) + { + // + q1Line.Color(clrYellow); + + // + mWaitingZoneObjects.Add(q1Line); + } + + // + // Quarter 2 ... + CChartObjectHLine *q2Line; + q2Line = new CChartObjectHLine(); + isCreated = q2Line.Create( + chartID, + prefix + "_Q2", + subWindow, + quarter2 // + ); + if (isCreated) + { + // + q2Line.Color(clrYellow); + + // + mWaitingZoneObjects.Add(q2Line); + } + + // + // Quarter 3 ... + CChartObjectHLine *q3Line; + q3Line = new CChartObjectHLine(); + isCreated = q3Line.Create( + chartID, + prefix + "_Q3", + subWindow, + quarter3 // + ); + if (isCreated) + { + // + q3Line.Color(clrYellow); + + // + mWaitingZoneObjects.Add(q3Line); + } + } + } + + // + // + // + + // + bool HasSupplyZone() + { + return supplyZone != NULL && + supplyZone.IsValid(); + } + + // + bool HasDemandZone() + { + return demandZone != NULL && + demandZone.IsValid(); + } + + // + bool HasSupplyZones() + { + return HasChild(supplyZones); + } + + // + int CountSupplyZones() + { + return ArraySize(supplyZones); + } + + // + bool HasDemandZones() + { + return HasChild(demandZones); + } + + // + int CountDemandZones() + { + return ArraySize(demandZones); + } + + // + bool HasSupportZones() + { + return HasChild(supportZones); + } + + // + int CountSupportZones() + { + return ArraySize(supportZones); + } + + // + bool HasResistanceZones() + { + return HasChild(resistanceZones); + } + + // + int CountResistanceZones() + { + return ArraySize(resistanceZones); + } + + // + bool HasConsolidationZones() + { + return HasChild(consolidationZones); + } + + // + int CountConsolidationZones() + { + return ArraySize(consolidationZones); + } + + // + bool HasWaitingBoxes() + { + return HasChild(waitingBoxes); + } + + // + int CountWaitingBoxes() + { + return ArraySize(waitingBoxes); + } + + // + bool HasInsideBoxes() + { + return HasChild(insideBoxes); + } + + // + int CountInsideBoxes() + { + return ArraySize(insideBoxes); + } + + // + bool HasBreakedBoxes() + { + return HasChild(breakedBoxes); + } + + // + int CountBreakedBoxes() + { + return ArraySize(breakedBoxes); + } + + // + bool HasBreakedInsideBoxes() + { + return HasChild(breakedInsideBoxes); + } + + // + int CountBreakedInsideBoxes() + { + return ArraySize(breakedInsideBoxes); + } + + // +}; + +// +struct X121SMCStrategyXWZSignalConditions +{ + // + // Props ... + + // + string symbol; + ENUM_TIMEFRAMES period; + + // + double sl; + double reward; + double amountPercent; + ENUM_X_DIRECTION dir; + ENUM_X_POSITION_TYPES type; + + // + // Setup Props ... + + // + datetime setupTime; + datetime triggerTime; + + // + double pivot; + double point; + double sls[]; + double targets[]; + + // + XBoxZone signalBox; + + // + ENUM_X121SMC_XWZ_PRIORITY priority; + ENUM_X121SMC_XWZ_PROVIDERS provider; + + // + // Constructor ... + X121SMCStrategyXWZSignalConditions() + { + Clean(); + } + + // + // Tools ... + + /** + * Cleaning Up ... + */ + void Clean() + { + // + sl = 0; + + // + dir = X_DIRECTION_NONE; + type = X_POSITION_TYPE_NONE; + + // + symbol = NULL; + period = NULL; + setupTime = NULL; + triggerTime = NULL; + + // + ExtensionClean(); + + // + ZeroMemory(this); + } + + /** + * Check Condition is Setting Up ... + * + * @param dir: ENUM_X_DIRECTION member, Setting Up Direction ... + * + * @return ( bool ) + */ + bool IsSetuped() + { + // + bool result = false; + + // + result = IsValid(setupTime) && + HasDirection(dir); + if (!result) + { + return result; + } + + // + return result; + } + + /** + * Calculate Setup Age ... + * + * @return ( int ) + */ + int GetSetupAge() + { + // + int result = 0; + + // + if (!IsSetuped()) + { + return result; + } + + // + result = (int)(TimeCurrent() - setupTime) / PeriodSeconds(period); + + // + return result; + } + + /** + * Detect How we Can Trigger Signal ... + * + * @return ( bool ) + */ + bool CanTrigger() + { + // + bool result = false; + + // + result = + // + sl > 0 && + IsValid(symbol) && + IsValid(period) && + IsValid(triggerTime) && + type != X_POSITION_TYPE_ALL && + type != X_POSITION_TYPE_NONE + // + ; + + // + return result; + } + + // + // Extensions ... + + /** + * Clean Additional Properties ... + */ + void ExtensionClean() + { + // + pivot = 0; + point = 0; + + // + reward = 0; + amountPercent = 0; + + // + Clean(sls); + Clean(targets); + signalBox.Clean(); + + // + provider = X121SMC_XWZ_PROVIDER_NONE; + } + + // + // + // + + // + void UpdateTo(datetime value = NULL) + { + // + value = NormalizeTime(value); + + // + int count = 0; + bool has = false; + } + + // +}; + +// +// Extension Functions ... + +// \ No newline at end of file diff --git a/Libraries/x-saherelm.x-poi.state.lib.mq5 b/Libraries/x-saherelm.x-poi.state.lib.mq5 index 1c369288..23ba425b 100644 --- a/Libraries/x-saherelm.x-poi.state.lib.mq5 +++ b/Libraries/x-saherelm.x-poi.state.lib.mq5 @@ -95,7 +95,7 @@ struct XOBFVG { // // Props ... - XCFVG *fvg; + XCFVG *fvgs[]; XCOrderBlock *ob; // @@ -112,8 +112,8 @@ struct XOBFVG void Clean() { // + Clean(fvgs); ZeroMemory(ob); - ZeroMemory(fvg); // ZeroMemory(this); @@ -123,7 +123,7 @@ struct XOBFVG bool IsValid() { return HasOB() && - HasFVG(); + HasFVGs(); } // @@ -134,10 +134,15 @@ struct XOBFVG } // - bool HasFVG() + bool HasFVGs() { - return fvg != NULL && - fvg.IsValid(); + return HasChild(fvgs); + } + + // + int CountFVGs() + { + return ArraySize(fvgs); } // @@ -300,6 +305,39 @@ struct XOBFVG return result; } + // + void AddFVG(XCFVG *fvg) + { + // + int idx = -1; + bool has = false; + + // + has = fvg != NULL && + fvg.IsValid(); + if (!has) + { + return; + } + + // + idx = FindIndex( + fvg, + fvgs // + ); + has = !IsValidIndex(idx); + if (!has) + { + return; + } + + // + Add( + fvg, + fvgs // + ); + } + // bool IsSameAs(XOBFVG &item) { @@ -308,8 +346,7 @@ struct XOBFVG // result = IsValid() && - IsSame(ob, item.ob) && - IsSame(fvg, item.fvg); + IsSame(ob, item.ob); // return result; @@ -333,10 +370,15 @@ struct XOBFVG } // - has = HasFVG(); + has = HasFVGs(); if (has) { - fvg.To(value); + // + count = CountFVGs(); + for (int i = 0; i < count; i++) + { + fvgs[i].To(value); + } } } }; @@ -3639,224 +3681,6 @@ struct XPOIState // }; -// -int ExtractOBFVGs( - XOBFVG &dest[], - XPOIState &obState, - XPOIState &fvgState, - // - ENUM_X_OBFVG_FVG_FILTERS filterFVGs = X_OBFVG_FVG_FILTER_INSIDE_OR, - ENUM_X_OBFVG_FVG_SELECTION selectFVG = X_OBFVG_FVG_SELECT_OLDEST, - // - ENUM_TIMEFRAMES forPeriod = NULL, - // - // Start ... - ENUM_XZONE_STATE startState = XZONE_STATE_PASSED, - bool forceStartedBodyOut = false, - // - // Activation ... - ENUM_XZONE_STATE activeState = XZONE_STATE_FAILED, - bool forceActivatedBodyIn = false, - // - // Breaktion ... - ENUM_XZONE_STATE breakState = XZONE_STATE_FAILED, - bool forceBreakedBodyOut = false, - // - // Works ... - ENUM_XZONE_STATE workState = XZONE_STATE_IGNORED, - bool forceWorkedBodyOut = false // -) -{ - // - int result = 0; - - // - bool has = false; - - // - Clean(dest); - - // - has = obState.IsValid() && - fvgState.IsValid() && - obState.HasChild() && - fvgState.HasChild() && - selectFVG != X_OBFVG_FVG_SELECT_NONE && - filterFVGs != X_OBFVG_FVG_FILTER_NONE; - if (!has) - { - return result; - } - - // - XCOrderBlock *obs[]; - int obsCount = obState.FilterOrderBlocks( - obs, - forPeriod, - startState, - forceStartedBodyOut, - activeState, - forceActivatedBodyIn, - breakState, - forceBreakedBodyOut, - workState, - forceWorkedBodyOut // - ); - has = IsValidSize(obsCount); - if (!has) - { - return result; - } - - // - XCFVG *fvgs[]; - int fvgsCount = fvgState.FilterFairValueGaps( - fvgs, - forPeriod, - startState, - forceStartedBodyOut, - activeState, - forceActivatedBodyIn, - breakState, - forceBreakedBodyOut, - workState, - forceWorkedBodyOut // - ); - has = IsValidSize(fvgsCount); - if (!has) - { - return result; - } - - // - for (int i = 0; i < obsCount; i++) - { - // - XCOrderBlock *iOB = obs[i]; - XCFVG *iFVG = NULL; - - // - ENUM_X_DIRECTION iOBDir = iOB.GetDirection(); - bool isIOBBullish = IsBullish(iOBDir); - - // - XCFVG *iFVGs[]; - for (int j = 0; j < fvgsCount; j++) - { - // - XCFVG *jFVG = fvgs[j]; - ENUM_X_DIRECTION jFVGDir = jFVG.GetDirection(); - - // - bool isSameDir = iOBDir == jFVGDir; - bool isFromPassed = jFVG.From() >= iOB.From(); - bool isInsideOr = IsInsideOrDiff( - jFVG, - iOB // - ); - bool isAbove = IsAboveDiff( - jFVG, - iOB, - true // - ); - bool isBelow = IsBelowDiff( - jFVG, - iOB, - true // - ); - - // - bool isFilterPassed = - filterFVGs == X_OBFVG_FVG_FILTER_ABOVE_BELOW - ? isIOBBullish - ? isAbove - : isBelow - : filterFVGs == X_OBFVG_FVG_FILTER_INSIDE_OR - ? isInsideOr - : false; - - // - has = - isSameDir && - isFromPassed && - isFilterPassed; - if (has) - { - // - Add( - jFVG, - iFVGs // - ); - } - } - has = HasChild(iFVGs); - if (!has) - { - continue; - } - - // - int idx = -1; - idx = selectFVG == X_OBFVG_FVG_SELECT_OLDEST - ? GetOldest(iFVGs) - : selectFVG == X_OBFVG_FVG_SELECT_YOUNGEST - ? GetYoungest(iFVGs) - : selectFVG == X_OBFVG_FVG_SELECT_HIGHEST_LOWEST - ? isIOBBullish - ? GetHighest(iFVGs) - : GetLowest(iFVGs) - : selectFVG == X_OBFVG_FVG_SELECT_LOWEST_HIGHEST - ? isIOBBullish - ? GetLowest(iFVGs) - : GetHighest(iFVGs) - : selectFVG == X_OBFVG_FVG_SELECT_LOWEST - ? GetLowest(iFVGs) - : selectFVG == X_OBFVG_FVG_SELECT_HIGHEST - ? GetHighest(iFVGs) - : -1; - - // - has = IsValidIndex(idx); - if (!has) - { - continue; - } - - // - iFVG = iFVGs[idx]; - Clean(iFVGs); - - // - XOBFVG iOBFVG; - iOBFVG.ob = iOB; - iOBFVG.fvg = iFVG; - - // - has = iOBFVG.IsValid(); - if (!has) - { - // - iOBFVG.Clean(); - continue; - } - - // - AddRef( - iOBFVG, - dest // - ); - - // - iOBFVG.Clean(); - } - - // - result = ArraySize(dest); - - // - return result; -} - // // Extensions Functions ... // diff --git a/X121SMCEA/Signals/x-121.smc.xwz.signal.class.mq5 b/X121SMCEA/Signals/x-121.smc.xwz.signal.class.mq5 index b0339133..8e758072 100644 --- a/X121SMCEA/Signals/x-121.smc.xwz.signal.class.mq5 +++ b/X121SMCEA/Signals/x-121.smc.xwz.signal.class.mq5 @@ -301,6 +301,10 @@ class XCX121SMCXWZSignalDetector : public XCBase X121Conditions consolidationXConditions = consolidationConditions.x121Conditions; X121Conditions visionXConditions = visionConditions.x121Conditions; + // + // Select Drawer Class ... + XCPOIDrawer *drawer = visionCycleHelper.mPOIDrawer; + // // Scores ... @@ -323,8 +327,8 @@ class XCX121SMCXWZSignalDetector : public XCBase ); // - // Select Drawer Class ... - XCPOIDrawer *drawer = visionCycleHelper.mPOIDrawer; + // + // // // Setup Conditions ... @@ -338,6 +342,7 @@ class XCX121SMCXWZSignalDetector : public XCBase double amountPercent = 0; bool hasPriority = false; bool hasSignalBox = false; + bool hasWaitingZones = false; bool hasRewardAmount = false; bool isSignalBoxReversal = false; bool hasWorkingZoneOveralDirection = false; @@ -385,21 +390,22 @@ class XCX121SMCXWZSignalDetector : public XCBase decisionCycleHelper.mPOIDetector.MaxAllowedLoopbackForInit(578); consolidationCycleHelper.mPOIDetector.MaxAllowedLoopbackForInit(578); - // - // Update Working Zone ... - workingZone.Update( - zIndex, - visionState, - consolidationState, - analyseState, - decisionState // - ); - // // Check Working Zone Overal Direction ... hasWorkingZoneOveralDirection = workingZone .DetectOveralDirection(wzOveralDir); + // + hasWaitingZones = workingZone.DetectZone( + drawer, + analysePoiEvents, + consolidationPoiEvents, + consolidationPoiEvents, + consolidationState, + analyseState, + consolidationState // + ); + // // Checking Working Zone Destory or not ... bool isWorkingZoneDestroyed = workingZone.IsDestroyed( @@ -460,225 +466,6 @@ class XCX121SMCXWZSignalDetector : public XCBase // // - // - // Waiting Box Detected ... - bool hasWaitingBoxes = hasWorkingZone && - workingZone.HasWaitingBoxes(); - if (hasWaitingBoxes) - { - // - XOHCL zBar; - XOHCL cBar; - XOHCL pBar; - int count = 0; - int idx = -1; - bool has = false; - - // - bool isInited = zBar.Init( - symbol, - period, - zIndex // - ); - isInited = - isInited && - zBar.GetPreviousBar(cBar); - isInited = - isInited && - cBar.GetPreviousBar(pBar); - - // - count = workingZone.CountWaitingBoxes(); - for (int i = 0; i < count; i++) - { - // - XBoxZone iBox = workingZone.waitingBoxes[i]; - ENUM_X_DIRECTION iDir = iBox.dir; - bool isBullish = IsBullish(iDir); - - // - // Check Price Rejection ... - - // - bool hasBullishFiboPressure = - decisionCycleHelper - .mBarAnalyser - .HasFiboPressure( - cBar, - X_DIRECTION_BULLISH, - X_FIBO_LEVEL_382 // - ); - - // - bool hasBearishFiboPressure = - decisionCycleHelper - .mBarAnalyser - .HasFiboPressure( - cBar, - X_DIRECTION_BEARISH, - X_FIBO_LEVEL_382 // - ); - - // - // Bullish Rejection ... - bool isBullishRejected = - // - isInited && - isBullish && - cBar.low < pBar.low && - zBar.low > iBox.upper && - cBar.low <= iBox.upper && - zBar.open > iBox.upper && - hasBullishFiboPressure && - cBar.GetLowShadow() > pBar.GetLowShadow() - // - ; - - // - // Bearish Rejection ... - bool isBearishhRejected = - // - isInited && - !isBullish && - cBar.high > pBar.high && - zBar.open < iBox.lower && - zBar.high < iBox.lower && - hasBearishFiboPressure && - cBar.high >= iBox.lower && - cBar.GetHighShadow() > pBar.GetHighShadow() - // - ; - - // - has = isBullishRejected || - isBearishhRejected; - if (has) - { - // - idx = i; - signalBox = iBox; - hasSignalBox = has; - signalBox.to = cTime; - signalBoxDir = iBox.dir; - isSignalBoxReversal = false; - provider = X121SMC_XWZ_PROVIDER_ACTIVATED_ZONE; - } - - // - iBox.Clean(); - } - - // - // Remove Signal Box from Waiting Boxes of - // Working Zone ... - if (hasSignalBox) - { - // - if (IsValidIndex(idx)) - { - // - ArrayRemove( - workingZone.waitingBoxes, - idx, - 1 // - ); - } - } - - // - // Ignore Zone's Signals ... - hasSignalBox = false; - - // - // Cleanup Resources ... - - // - zBar.Clean(); - cBar.Clean(); - pBar.Clean(); - } - - // - // Check Conditions if Has Inside Boxes ... - bool hasInsideBoxes = hasWorkingZone && - workingZone.HasInsideBoxes(); - if (hasInsideBoxes) - { - } - - // - // Check Conditions if has Breaked Boxes ... - bool hasBreakedBoxes = hasWorkingZone && - workingZone.HasBreakedBoxes(); - if (hasBreakedBoxes) - { - } - - // - // Checking Other Conditions ... - if (!hasSignalBox) - { - // - // Senari A ... - hasSignalBox = hasWorkingZone && - workingZone.DetectSenarioASignalBox( - signalBox, - signalBoxDir, - decisionXConditions, - analyseXConditions, - decisionCycleHelper, - drawer, - zIndex // - ); - if (hasSignalBox) - { - // - signalBox.to = cTime; - isSignalBoxReversal = false; - provider = X121SMC_XWZ_PROVIDER_PV_ZONE; - } - - // - // Validating Signal Box if Exists ... - if (hasSignalBox) - { - // - // Validate Signal Boxes using Inside Box ... - if (hasInsideBoxes) - { - // - int idx = -1; - bool has = false; - - // - idx = - IsBullish(signalBoxDir) - ? GetLowest(workingZone.insideBoxes) - : GetHighest(workingZone.insideBoxes); - has = IsValidIndex(idx); - if (has) - { - // - hasSignalBox = - signalBoxDir == workingZone.insideBoxes[idx].dir; - } - } - - // - // Validate Signal Box Using Overal Trend ... - if (hasWorkingZoneOveralDirection) - { - // - hasSignalBox = - signalBoxDir == wzOveralDir; - } - } - } - - // - // - // - // // Cleanup Signal if UnApproved ... if (!hasSignalBox) @@ -798,13 +585,13 @@ class XCX121SMCXWZSignalDetector : public XCBase // Force Add TP 2 as Target ... double risk = MathAbs(entry - sl); double reward2 = 2 * risk; - double iTP2 = isBullish - ? entry + reward2 - : entry - reward2; - Add( - iTP2, - targets // - ); + // double iTP2 = isBullish + // ? entry + reward2 + // : entry - reward2; + // Add( + // iTP2, + // targets // + // ); // // Based On Priority ... @@ -1070,63 +857,6 @@ class XCX121SMCXWZSignalDetector : public XCBase break; } } - - // - XBoxZone waitingBoxes[]; - has = workingZone.HasWaitingBoxes(); - if (has) - { - // - Copy( - workingZone.waitingBoxes, - waitingBoxes // - ); - - // - while (HasChild(waitingBoxes)) - { - // - XBoxZone iBox; - idx = GetYoungest(waitingBoxes); - has = IsValidIndex(idx); - if (!has) - { - // - iBox.Clean(); - continue; - } - - // - iBox = waitingBoxes[idx]; - ArrayRemove( - waitingBoxes, - idx, - 1 // - ); - - // - bool hasInside = workingZone.HasInsideBox(iBox); - if (!hasInside) - { - continue; - } - - // - double iTarget = - IsBullish(signalBoxDir) - ? iBox.lower - : iBox.upper; - - // - Add( - iTarget, - targets // - ); - - // - iBox.Clean(); - } - } } // @@ -1172,17 +902,17 @@ class XCX121SMCXWZSignalDetector : public XCBase workingZone.Draw( drawer, // - true, // Draw Waiting Boxes ... - true, // Draw Inside Boxes ... - true, // Draw Breaked Boxes ... - // true, // Draw Supply Zone ... true, // Draw Demand Zone ... - true, // Draw Supply Zones ... - true, // Draw Demand Zones ... - true, // Draw Support Zones ... - true // Draw Resistance Zones ... + true // Draw Waiting Zones ... + // ); + + // + if (hasWaitingZones) + { + Print("Has Waiting Zones ..."); + } } // diff --git a/X121SMCEA/Signals/x-121.smc.xwz.signal.lib.mq5 b/X121SMCEA/Signals/x-121.smc.xwz.signal.lib.mq5 index d70385e2..183b489e 100644 --- a/X121SMCEA/Signals/x-121.smc.xwz.signal.lib.mq5 +++ b/X121SMCEA/Signals/x-121.smc.xwz.signal.lib.mq5 @@ -70,31 +70,11 @@ struct X121SMCStrategyXWZWorkingZone XCDemandZone *demandZone; // - XCSupplyZone *supplyZones[]; - XCDemandZone *demandZones[]; + XOBFVG waitingZones[]; // - XCSupportZone *supportZones[]; - XCResistanceZone *resistanceZones[]; - - // - XBoxZone insideBoxes[]; - XBoxZone breakedBoxes[]; - XBoxZone waitingBoxes[]; - XBoxZone breakedInsideBoxes[]; - XConsolidationZone consolidationZones[]; - - // - CArrayObj mInsideZoneObjects; - CArrayObj mBreakedZoneObjects; - CArrayObj mWaitingZoneObjects; + CArrayObj mDrawnObjects; CArrayObj mWorkingZoneObjects; - CArrayObj mBreakedInsideZoneObjects; - - // - bool mUseSupDems; - bool mUseOrderBlocks; - bool mUseFairValueGaps; // // Constructor ... @@ -119,33 +99,15 @@ struct X121SMCStrategyXWZWorkingZone period = NULL; // - Clean(supplyZones); - Clean(demandZones); - - // - Clean(insideBoxes); - Clean(breakedBoxes); - Clean(waitingBoxes); - - // - Clean(supportZones); - Clean(resistanceZones); + Clean(waitingZones); // ZeroMemory(supplyZone); ZeroMemory(demandZone); // - mInsideZoneObjects.Clear(); - mBreakedZoneObjects.Clear(); - mWaitingZoneObjects.Clear(); + mDrawnObjects.Clear(); mWorkingZoneObjects.Clear(); - mBreakedInsideZoneObjects.Clear(); - - // - mUseSupDems = false; - mUseOrderBlocks = true; - mUseFairValueGaps = true; } // @@ -279,105 +241,6 @@ struct X121SMCStrategyXWZWorkingZone } } - // - // - // - - // - // Supply Zones ... - has = HasSupplyZones(); - if (!has) - { - // - count = mtfState.FilterSupplyZones( - supplyZones, - period, - XZONE_STATE_PASSED, - false, - XZONE_STATE_FAILED, - false, - XZONE_STATE_FAILED, - false, - XZONE_STATE_IGNORED, - false // - ); - } - - // - // Demand Zones ... - has = HasDemandZones(); - if (!has) - { - // - count = mtfState.FilterDemandZones( - demandZones, - period, - XZONE_STATE_PASSED, - false, - XZONE_STATE_FAILED, - false, - XZONE_STATE_FAILED, - false, - XZONE_STATE_IGNORED, - false // - ); - } - - // - // Support Zones ... - // has = HasSupportZones(); - // if (!has) - // { - // // - // count = mtfState.FilterSupportZones( - // supportZones, - // period, - // XZONE_STATE_PASSED, - // false, - // XZONE_STATE_FAILED, - // false, - // XZONE_STATE_FAILED, - // false, - // XZONE_STATE_IGNORED, - // false // - // ); - // } - - // - // Resistance Zones ... - // has = HasResistanceZones(); - // if (!has) - // { - // // - // count = mtfState.FilterResistanceZones( - // resistanceZones, - // period, - // XZONE_STATE_PASSED, - // false, - // XZONE_STATE_FAILED, - // false, - // XZONE_STATE_FAILED, - // false, - // XZONE_STATE_IGNORED, - // false // - // ); - // } - - // - has = ttfState.HasConsolidationZones(); - if (has) - { - // - Copy( - ttfState.consolidationZones, - consolidationZones // - ); - CleanupArray( - consolidationZones, - 50 // - ); - } - // if (supplyZone != NULL && demandZone != NULL && @@ -397,122 +260,6 @@ struct X121SMCStrategyXWZWorkingZone quarter3 = upper - (3 * delta); } - // - // Waiting Zone Detection ... - XPOIState iState = mtfState; - - // - // Detect Waiting Zones ... - - // - // Using Order Blocks ... - if (mUseOrderBlocks) - { - // - has = iState.HasOrderBlocks(); - if (has) - { - // - XCOrderBlock *obs[]; - count = iState.FilterOrderBlocks( - obs, - period, - XZONE_STATE_PASSED, - false, - XZONE_STATE_FAILED, - false, - XZONE_STATE_FAILED, - false, - XZONE_STATE_IGNORED, - false // - ); - - // - has = IsValidSize(count); - if (has) - { - // - ToBox( - obs, - waitingBoxes // - ); - } - - // - Clean(obs); - } - } - - // - // Using Fair Value Gaps ... - if (mUseFairValueGaps) - { - // - has = iState.HasFairValueGaps(); - if (has) - { - // - XBoxZone boxes[]; - XCFVG *fvgs[]; - count = iState.FilterFairValueGaps( - fvgs, - period, - XZONE_STATE_PASSED, - false, - XZONE_STATE_FAILED, - false, - XZONE_STATE_FAILED, - false, - XZONE_STATE_IGNORED, - false // - ); - - // - has = IsValidSize(count); - if (has) - { - // - count = ToBox( - fvgs, - boxes // - ); - - // - for (int i = 0; i < count; i++) - { - // - XBoxZone iBox = boxes[i]; - - // - int idx = FindIndex( - iBox, - waitingBoxes // - ); - has = !IsValidIndex(idx); - if (has) - { - // - AddRef( - iBox, - waitingBoxes // - ); - } - - // - iBox.Clean(); - } - } - - // - Clean(fvgs); - Clean(boxes); - } - } - - // - // Cleaning State ... - iState.Clean(); - // result = IsValid(); if (!result) @@ -525,791 +272,330 @@ struct X121SMCStrategyXWZWorkingZone } // - void Update( - int barIndex, - XPOIState &htfState, - XPOIState &mtfState, - XPOIState &stfState, - XPOIState &ttfState // + bool DetectZone( + XCPOIDrawer *drawer, + ENUM_XPOI_EVENTS &obPOIEvents[], + ENUM_XPOI_EVENTS &fvgPOIEvents[], + ENUM_XPOI_EVENTS &supDemPOIEvents[], + XPOIState &obState, + XPOIState &fvgState, + XPOIState &supDemState // ) { + // + bool result = false; + + // + result = IsValid() && + obState.IsValid() && + fvgState.IsValid() && + supDemState.IsValid() && + obState.HasOrderBlocks() && + fvgState.HasFairValueGaps() && + supDemState.HasSupplyZones() && + supDemState.HasDemandZones(); + if (!result) + { + return result; + } + // int idx = -1; - int count = 0; bool has = false; + datetime cTime = TimeCurrent(); // - if (barIndex < 0) - { - barIndex = 0; - } + XOBFVG obFVG; + XBoxZone obBox; + XBoxZone fvgBox; + XBoxZone supplyBox; + XBoxZone demandBox; // - has = - // - IsValid() && - // - htfState.IsValid() && - mtfState.IsValid() && - stfState.IsValid() && - // - htfState.HasChild() && - mtfState.HasChild() && - stfState.HasChild() - // - ; - if (!has) - { - return; - } + XCFVG *fvg = NULL; + XCOrderBlock *ob = NULL; + XCSupplyZone *supply = NULL; + XCDemandZone *demand = NULL; // - XOHCL zBar; - has = zBar.Init( - symbol, - period, - barIndex // - ); - if (!has) + // Check New Supply Zone Detection ... + bool hasNewSupply = + Contains( + X_SUPPLY_ZONE_DETECTED, + supDemPOIEvents // + ); + if (hasNewSupply) { // - zBar.Clean(); - return; - } - - // - XOHCL cBar; - has = zBar.GetPreviousBar(cBar); - if (!has) - { - // - zBar.Clean(); - cBar.Clean(); - - // - return; - } - - // - // Update Exists Zones ... - - // // - // // Supply Zones ... - // has = mtfState.HasSupplyZones(); - // if (has) - // { - // // - // XCSupplyZone *tmpZones[]; - // count = mtfState.FilterSupplyZones( - // tmpZones, - // period, - // XZONE_STATE_PASSED, - // false, - // XZONE_STATE_FAILED, - // false, - // XZONE_STATE_FAILED, - // false, - // XZONE_STATE_IGNORED, - // false // - // ); - // has = IsValidSize(count); - // if (has) - // { - // // - // for (int i = 0; i < count; i++) - // { - // // - // // Try to Validate Indexes ... - - // // - // XCSupplyZone *iZone = tmpZones[i]; - // has = IsSupplyExists(iZone); - // if (!has) - // { - // // - // Add( - // iZone, - // supplyZones // - // ); - // } - // } - // } - - // // - // Clean(tmpZones); - // } - - // // - // // Demand Zones ... - // has = mtfState.HasDemandZones(); - // if (has) - // { - // // - // XCDemandZone *tmpZones[]; - // count = mtfState.FilterDemandZones( - // tmpZones, - // period, - // XZONE_STATE_PASSED, - // false, - // XZONE_STATE_FAILED, - // false, - // XZONE_STATE_FAILED, - // false, - // XZONE_STATE_IGNORED, - // false // - // ); - // has = IsValidSize(count); - // if (has) - // { - // // - // for (int i = 0; i < count; i++) - // { - // // - // // Try to Validate Indexes ... - - // // - // XCDemandZone *iZone = tmpZones[i]; - // has = IsDemandExists(iZone); - // if (!has) - // { - // // - // Add( - // iZone, - // demandZones // - // ); - // } - // } - // } - - // // - // Clean(tmpZones); - // } - - // - // - // - - // - // Supply Zones ... - has = HasSupplyZones(); - if (has) - { - // - int removeIDXs[]; - count = CountSupplyZones(); - for (int i = 0; i < count; i++) - { - // - XCSupplyZone *iZone = supplyZones[i]; - ENUM_X_DIRECTION iDir = X_DIRECTION_BEARISH; - - // - XBoxZone iBox; - bool hasBox = ToBox( - iBox, - iZone // - ); - if (!hasBox) - { - // - iBox.Clean(); - continue; - } - - // - XOHCL passedBar; - bool isBodyIn = false; - bool isBodyOut = false; - - // - // Check Activation ... - bool isActivated = iZone.IsActivated( - iDir, - passedBar, - isBodyIn, - true, - period // - ); - if (isActivated) - { - // - // AddRef( - // iBox, - // insideBoxes // - // ); - - // - Add( - i, - removeIDXs // - ); - - // - iBox.Clean(); - passedBar.Clean(); - continue; - } - - // - // Checking Breaked ... - bool isBreaked = iZone.IsBreaked( - iDir, - passedBar, - isBodyOut, - false, - true, - period // - ); - if (isBreaked) - { - // // - // AddRef( - // iBox, - // breakedBoxes // - // ); - - // - Add( - i, - removeIDXs // - ); - - // - iBox.Clean(); - passedBar.Clean(); - continue; - } - - // - passedBar.Clean(); - } - - // - count = ArraySize(removeIDXs); - has = IsValidSize(count); + idx = GetYoungest(supDemState.supplyZones); + has = IsValidIndex(idx); if (has) { // - CleanupArray( - removeIDXs, - supplyZones // + supply = supDemState.supplyZones[idx]; + has = ToBox( + supplyBox, + supply // ); - } - - // - Clean(removeIDXs); - } - - // - // Demand Zones ... - has = HasDemandZones(); - if (has) - { - // - int removeIDXs[]; - count = CountDemandZones(); - for (int i = 0; i < count; i++) - { - // - XCDemandZone *iZone = demandZones[i]; - ENUM_X_DIRECTION iDir = X_DIRECTION_BULLISH; - - // - XBoxZone iBox; - bool hasBox = ToBox( - iBox, - iZone // - ); - if (!hasBox) - { - // - iBox.Clean(); - continue; - } - - // - XOHCL passedBar; - bool isBodyIn = false; - bool isBodyOut = false; - - // - // Check Activation ... - bool isActivated = iZone.IsActivated( - iDir, - passedBar, - isBodyIn, - true, - period // - ); - if (isActivated) - { - // - // AddRef( - // iBox, - // insideBoxes // - // ); - - // - Add( - i, - removeIDXs // - ); - - // - iBox.Clean(); - passedBar.Clean(); - continue; - } - - // - // Checking Breaked ... - bool isBreaked = iZone.IsBreaked( - iDir, - passedBar, - isBodyOut, - false, - true, - period // - ); - if (isBreaked) - { - // // - // AddRef( - // iBox, - // breakedBoxes // - // ); - - // - Add( - i, - removeIDXs // - ); - - // - iBox.Clean(); - passedBar.Clean(); - continue; - } - - // - passedBar.Clean(); - } - - // - count = ArraySize(removeIDXs); - has = IsValidSize(count); - if (has) - { - // - CleanupArray( - removeIDXs, - demandZones // - ); - } - - // - Clean(removeIDXs); - } - - // - // Update Boxes ... - - // - // Waiting Boxes ... - has = HasWaitingBoxes(); - if (has) - { - // - int removeIDXs[]; - count = CountWaitingBoxes(); - for (int i = 0; i < count; i++) - { - // - XBoxZone iBox = waitingBoxes[i]; - ENUM_X_DIRECTION iDir = iBox.dir; - bool isBullish = IsBullish(iDir); - - // - bool isInside = - // - zBar.low < iBox.upper && - zBar.low > iBox.lower - // - ; - if (isInside) - { - // - AddRef( - iBox, - insideBoxes // - ); - - // - Add( - i, - removeIDXs // - ); - - // - iBox.Clean(); - break; - } - - // - bool isBreakedUpper = - // - cBar.low < iBox.upper && - cBar.low > iBox.lower && - zBar.low > iBox.upper - // - ; - - // - bool isBreakedLower = - // - cBar.high > iBox.lower && - cBar.high < iBox.upper && - zBar.high < iBox.lower - // - ; - - // - bool isBreaked = - (isBullish && - isBreakedLower) || - (!isBullish && - isBreakedUpper); - - // - if (isBreaked) - { - // - AddRef( - iBox, - breakedBoxes // - ); - - // - Add( - i, - removeIDXs // - ); - - // - iBox.Clean(); - break; - } - } - - // - count = ArraySize(removeIDXs); - has = IsValidSize(count); - if (has) - { - // - CleanupArray( - removeIDXs, - waitingBoxes // - ); - } - - // - Clean(removeIDXs); - } - - // - // Inside Boxes ... - has = HasInsideBoxes(); - if (has) - { - // - int removeIDXs[]; - count = CountInsideBoxes(); - for (int i = 0; i < count; i++) - { - // - XBoxZone iBox = insideBoxes[i]; - ENUM_X_DIRECTION iDir = iBox.dir; - bool isBullish = IsBullish(iDir); - - // - bool isBreakedUpper = - // - cBar.low < iBox.upper && - cBar.low > iBox.lower && - zBar.low > iBox.upper - // - ; - - // - bool isBreakedLower = - // - cBar.high > iBox.lower && - cBar.high < iBox.upper && - zBar.high < iBox.lower - // - ; - - // - bool isBreaked = - (isBullish && - isBreakedLower) || - (!isBullish && - isBreakedUpper); - - // - if (isBreaked) - { - // - AddRef( - iBox, - breakedBoxes // - ); - - // - Add( - i, - removeIDXs // - ); - - // - iBox.Clean(); - break; - } - } - - // - count = ArraySize(removeIDXs); - has = IsValidSize(count); - if (has) - { - // - CleanupArray( - removeIDXs, - insideBoxes // - ); - } - - // - Clean(removeIDXs); - } - - // - // Update Waiting Boxes ... - - // - XPOIState iState = mtfState; - - // - // Use Order Blocks ... - if (mUseOrderBlocks) - { - // - has = iState.HasOrderBlocks(); - if (has) - { - // - XCOrderBlock *obs[]; - count = iState.FilterOrderBlocks( - obs, - period, - XZONE_STATE_PASSED, - false, - XZONE_STATE_FAILED, - false, - XZONE_STATE_FAILED, - false, - XZONE_STATE_IGNORED, - false // - ); - - // - has = IsValidSize(count); if (has) { // - // Try to Add new OBs into Waiting Zones ... - // if it's not exists ... - for (int i = 0; i < count; i++) + supply.To(cTime); + supplyBox.to = cTime; + hasNewSupply = supplyBox.IsValid(); + } + } + } + + // + // Check New Demand Zone Detection ... + bool hasNewDemand = + Contains( + X_DEMAND_ZONE_DETECTED, + supDemPOIEvents // + ); + if (hasNewDemand) + { + // + idx = GetYoungest(supDemState.demandZones); + has = IsValidIndex(idx); + if (has) + { + // + demand = supDemState.demandZones[idx]; + has = ToBox( + demandBox, + demand // + ); + if (has) + { + // + demand.To(cTime); + demandBox.to = cTime; + hasNewDemand = demandBox.IsValid(); + } + } + } + + // + // Check New Fair Value Gap Detection ... + bool hasNewFairValueGap = + Contains( + X_BULLISH_FVG_DETECTED, + fvgPOIEvents // + ) || + Contains( + X_BEARISH_FVG_DETECTED, + fvgPOIEvents // + ); + if (hasNewFairValueGap) + { + // + idx = GetYoungest(fvgState.fairValueGaps); + has = IsValidIndex(idx); + if (has) + { + // + fvg = fvgState.fairValueGaps[idx]; + has = ToBox( + fvgBox, + fvg // + ); + if (has) + { + // + fvg.To(cTime); + fvgBox.to = cTime; + hasNewFairValueGap = fvgBox.IsValid(); + } + } + } + + // + // Check New Order Block Detection ... + bool hasNewOrderBlock = + Contains( + X_BULLISH_ORDERBLOCK_DETECTED, + obPOIEvents // + ) || + Contains( + X_BEARISH_ORDERBLOCK_DETECTED, + obPOIEvents // + ); + if (hasNewOrderBlock) + { + // + idx = GetYoungest(obState.orderBlocks); + has = IsValidIndex(idx); + if (has) + { + // + ob = obState.orderBlocks[idx]; + has = ToBox( + obBox, + ob // + ); + if (has) + { + // + ob.To(cTime); + obBox.to = cTime; + hasNewOrderBlock = obBox.IsValid(); + } + } + } + + // + // Detect OB FVG ... + result = + hasNewOrderBlock && + hasNewFairValueGap; + if (result) + { + // + obFVG.ob = ob; + obFVG.AddFVG(fvg); + + // + has = obFVG.IsValid(); + if (has) + { + // + // Check Item Is not Exists ... + idx = FindIndex( + obFVG, + waitingZones // + ); + has = !IsValidIndex(idx); + if (has) + { + // + // New Waiting Zone ... + AddRef( + obFVG, + waitingZones // + ); + } + else + { + // + // Update Exists Waiting Zone ... + waitingZones[idx].AddFVG(fvg); + } + } + } + + // + // Detect SupDem FVG ... + if (!result) + { + // + result = hasNewFairValueGap && + (hasNewSupply || + hasNewDemand); + if (result) + { + // + // Converts Supply or Demand Zone to OrderBlock ... + XOHCL bar; + ob = new XCOrderBlock(); + if (hasNewSupply) + { + // + has = supply.FillBar(bar); + if (has) { // - XBoxZone iBox; - bool hasBox = ToBox( - iBox, - obs[i] // + has = ob.Init( + bar, + X_DIRECTION_BEARISH // ); - if (!hasBox) + if (has) { // - iBox.Clean(); - continue; + ob.Upper(supply.Upper()); + ob.Lower(supply.Lower()); } - + } + } + else if (hasNewDemand) + { + // + has = demand.FillBar(bar); + if (has) + { // - // Check Index in Waiting Boxes ... - idx = FindIndex( - iBox, - waitingBoxes // + has = ob.Init( + bar, + X_DIRECTION_BULLISH // ); - has = !IsValidIndex(idx); - if (!has) + if (has) { // - iBox.Clean(); - continue; + ob.Upper(demand.Upper()); + ob.Lower(demand.Lower()); } - - // - // Check Index in Inside Boxes ... - idx = FindIndex( - iBox, - insideBoxes // - ); - has = !IsValidIndex(idx); - if (!has) - { - // - iBox.Clean(); - continue; - } - - // - // Check Index in Breaked Boxes ... - idx = FindIndex( - iBox, - breakedBoxes // - ); - has = !IsValidIndex(idx); - if (!has) - { - // - iBox.Clean(); - continue; - } - - // - AddRef( - iBox, - waitingBoxes // - ); } } // - Clean(obs); - } - } - - // - // Use Fair Value Gaps ... - if (mUseFairValueGaps) - { - // - has = iState.HasFairValueGaps(); - if (has) - { - // - XCFVG *fvgs[]; - count = iState.FilterFairValueGaps( - fvgs, - period, - XZONE_STATE_PASSED, - false, - XZONE_STATE_FAILED, - false, - XZONE_STATE_FAILED, - false, - XZONE_STATE_IGNORED, - false // - ); + obFVG.ob = ob; + obFVG.AddFVG(fvg); // - has = IsValidSize(count); + has = obFVG.IsValid(); if (has) { // - for (int i = 0; i < count; i++) + // Check Item Is not Exists ... + idx = FindIndex( + obFVG, + waitingZones // + ); + has = !IsValidIndex(idx); + if (has) { // - XBoxZone iBox; - bool hasBox = ToBox( - iBox, - fvgs[i] // - ); - if (!hasBox) - { - // - iBox.Clean(); - continue; - } - - // - // Check Index in Waiting Boxes ... - idx = FindIndex( - iBox, - waitingBoxes // - ); - has = !IsValidIndex(idx); - if (!has) - { - // - iBox.Clean(); - continue; - } - - // - // Check Index in Inside Boxes ... - idx = FindIndex( - iBox, - insideBoxes // - ); - has = !IsValidIndex(idx); - if (!has) - { - // - iBox.Clean(); - continue; - } - - // - // Check Index in Breaked Boxes ... - idx = FindIndex( - iBox, - breakedBoxes // - ); - has = !IsValidIndex(idx); - if (!has) - { - // - iBox.Clean(); - continue; - } - - // + // New Waiting Zone ... AddRef( - iBox, - waitingBoxes // + obFVG, + waitingZones // ); - + } + else + { // - iBox.Clean(); + // Update Exists Waiting Zone ... + waitingZones[idx].AddFVG(fvg); } } // - Clean(fvgs); + bar.Clean(); } } // - iState.Clean(); + result = HasWaitingZones(); // - // Cleanup Resource ... + // Cleanup Resources ... // - zBar.Clean(); - cBar.Clean(); + obFVG.Clean(); + obBox.Clean(); + fvgBox.Clean(); + supplyBox.Clean(); + demandBox.Clean(); + + // + ZeroMemory(ob); + ZeroMemory(fvg); + ZeroMemory(supplyZone); + ZeroMemory(demandZone); + + // + return result; } // @@ -1513,364 +799,6 @@ struct X121SMCStrategyXWZWorkingZone return result; } - // - bool DetectSenarioASignalBox( - XBoxZone &signalBox, - ENUM_X_DIRECTION &signalDir, - X121Conditions &decisionXConditions, - X121Conditions &analyseXConditions, - XC121SMCCycleHelper *decisionCycleHelper, - XCPOIDrawer *drawer = NULL, - int barIndex = 0 // - ) - { - // - bool result = false; - - // - signalBox.Clean(); - signalDir = X_DIRECTION_NONE; - - // - if (barIndex < 0) - { - barIndex = 0; - } - - // - result = decisionCycleHelper != NULL; - if (!result) - { - return result; - } - - // - // Decision ... - double decisionBullishScore = 0; - double decisionBearishScore = 0; - decisionXConditions.GenerateScore( - decisionBullishScore, - decisionBearishScore // - ); - - // - // Analyse ... - double analyseBullishScore = 0; - double analyseBearishScore = 0; - analyseXConditions.GenerateScore( - analyseBullishScore, - analyseBearishScore // - ); - - // - // Score Conditions ... - double scoreMultiplier = 3; - bool isBullishScorePassed = - // - analyseBullishScore > (analyseBearishScore * scoreMultiplier) && - decisionBullishScore > (decisionBearishScore * scoreMultiplier) - // - ; - bool isBearishScorePassed = - // - analyseBearishScore > (analyseBullishScore * scoreMultiplier) && - decisionBearishScore > (decisionBullishScore * scoreMultiplier) - // - ; - - // - // Checking Other Conditions - - // - bool isCommonBullish = - // - decisionXConditions.isSarBullish && - decisionXConditions.isStrBullish && - decisionXConditions.isCheBullish && - decisionXConditions.isSMHKBullish && - decisionXConditions.isRawHKBullish && - decisionXConditions.isRawHKClosedOverSMHK - // - ; - - // - bool isCommonBearish = - // - decisionXConditions.isSarBearish && - decisionXConditions.isStrBearish && - decisionXConditions.isCheBearish && - decisionXConditions.isSMHKBearish && - decisionXConditions.isRawHKBearish && - decisionXConditions.isRawHKClosedUnderSMHK - // - ; - - // - // X3Ma ... - - // - // X3Ma Bullish ... - bool isX3MaBullish = - // - decisionXConditions.isX3MaBullishState && - decisionXConditions.isX3MaSwitchedToBullishOrdered && - decisionXConditions.x3maMidBuffer[1] > decisionXConditions.x3maSlowBuffer[1] - // - ; - - // - // X3Ma Bearish ... - bool isX3MaBearish = - // - decisionXConditions.isX3MaBearishState && - decisionXConditions.isX3MaSwitchedToBearishOrdered && - decisionXConditions.x3maMidBuffer[1] < decisionXConditions.x3maSlowBuffer[1] - // - ; - - // - bool isX3MaHasCondition = - (isX3MaBullish && - isCommonBullish && - isBullishScorePassed) || - (isX3MaBearish && - isCommonBearish && - isBearishScorePassed); - - // - // VWap ... - - // - // VWap Bullish ... - bool isVWapBullish = - // - decisionXConditions.isVWapBullishState && - decisionXConditions.isVWapSwitchedToBullishOrdered && - decisionXConditions.vwapMidBuffer[1] > decisionXConditions.vwapSlowBuffer[1] - // - ; - - // - // VWap Bearish ... - bool isVWapBearish = - // - decisionXConditions.isVWapBearishState && - decisionXConditions.isVWapSwitchedToBearishOrdered && - decisionXConditions.vwapMidBuffer[1] < decisionXConditions.vwapSlowBuffer[1] - // - ; - - // - bool isVWapHasCondition = - (isVWapBullish && - isBullishScorePassed) || - (isVWapBearish && - isBearishScorePassed); - - // - // Senario .... - // - a vale Under X3MA Slow when X3MA Bullish Ordered ... - - // - bool isX3MASenarioBBullish = - // - decisionXConditions.isX3MaBullishOrdered && - decisionXConditions.valesBuffer[1] < decisionXConditions.x3maSlowBuffer[1] && - decisionXConditions.valesBuffer[2] >= decisionXConditions.x3maSlowBuffer[2] - // - ; - if (isX3MASenarioBBullish) - { - } - - // - bool isX3MASenarioBBearish = - // - decisionXConditions.isX3MaBearishOrdered && - decisionXConditions.peaksBuffer[1] > decisionXConditions.x3maSlowBuffer[1] && - decisionXConditions.peaksBuffer[2] <= decisionXConditions.x3maSlowBuffer[2] - // - ; - if (isX3MASenarioBBearish) - { - } - - // - // Checking Other Conditions XWZ Reject on EMA 20 ... - - // - // Check Has Conditions ... - bool hasXConditions = - (isX3MaHasCondition || - isVWapHasCondition); - - // - result = hasXConditions; - if (!result) - { - return result; - } - - // - if (isX3MaHasCondition) - { - // - signalDir = - isX3MaBullish - ? X_DIRECTION_BULLISH - : isX3MaBearish - ? X_DIRECTION_BEARISH - : X_DIRECTION_NONE; - } - - // - if (isVWapHasCondition) - { - // - signalDir = - isVWapBullish - ? X_DIRECTION_BULLISH - : isVWapBearish - ? X_DIRECTION_BEARISH - : X_DIRECTION_NONE; - } - - // - // Creating SignalBox ... - - // - // Detect Box based on PV ... - bool hasSignalBox = decisionCycleHelper.GeneratePVBox( - signalBox, - barIndex // - ); - - // - result = - hasSignalBox && - signalDir == signalBox.dir; - - // - if (result) - { - // - XCBoxObject *iObj; - bool isCreated = drawer.DrawBox( - signalBox, - iObj // - ); - if (isCreated) - { - // - iObj.BoxWidth(1); - iObj.BoxColor(clrYellow); - iObj.BoxStyle(STYLE_SOLID); - } - - // - Print("Senario A ..."); - } - - // - return result; - } - - // - bool DetetctSenarioBSignalBox( - XBoxZone &signalBox, - ENUM_X_DIRECTION &signalDir, - X121Conditions &decisionXConditions, - X121Conditions &analyseXConditions, - XC121SMCCycleHelper *decisionCycleHelper, - int barIndex = 0 // - ) - { - // - bool result = false; - - // - signalBox.Clean(); - signalDir = X_DIRECTION_NONE; - - // - if (barIndex < 0) - { - barIndex = 0; - } - - // - result = decisionCycleHelper != NULL; - if (!result) - { - return result; - } - - // - // Decision ... - double decisionBullishScore = 0; - double decisionBearishScore = 0; - decisionXConditions.GenerateScore( - decisionBullishScore, - decisionBearishScore // - ); - - // - // Analyse ... - double analyseBullishScore = 0; - double analyseBearishScore = 0; - analyseXConditions.GenerateScore( - analyseBullishScore, - analyseBearishScore // - ); - - // - // Score Conditions ... - double scoreMultiplier = 3; - bool isBullishScorePassed = - // - analyseBullishScore > (analyseBearishScore * scoreMultiplier) && - decisionBullishScore > (decisionBearishScore * scoreMultiplier) - // - ; - bool isBearishScorePassed = - // - analyseBearishScore > (analyseBullishScore * scoreMultiplier) && - decisionBearishScore > (decisionBullishScore * scoreMultiplier) - // - ; - - // - // Senario .... - // - a vale Under X3MA Slow when X3MA Bullish Ordered ... - - // - bool isX3MASenarioBBullish = - // - decisionXConditions.isX3MaBullishOrdered && - decisionXConditions.valesBuffer[1] < decisionXConditions.x3maSlowBuffer[1] && - decisionXConditions.valesBuffer[2] >= decisionXConditions.x3maSlowBuffer[2] - // - ; - if (isX3MASenarioBBullish) - { - } - - // - bool isX3MASenarioBBearish = - // - decisionXConditions.isX3MaBearishOrdered && - decisionXConditions.peaksBuffer[1] > decisionXConditions.x3maSlowBuffer[1] && - decisionXConditions.peaksBuffer[2] <= decisionXConditions.x3maSlowBuffer[2] - // - ; - if (isX3MASenarioBBearish) - { - } - - // - return result; - } - // bool DetectOveralDirection( ENUM_X_DIRECTION &dir // @@ -1985,304 +913,6 @@ struct X121SMCStrategyXWZWorkingZone return result; } - // - bool HasInsideBox( - XBoxZone &box // - ) - { - // - bool result = false; - - // - int index = -1; - - // - result = box.IsValid(); - if (!result) - { - return result; - } - - // - int count = 0; - bool has = false; - - // - has = HasWaitingBoxes(); - if (has) - { - // - result = HasInsideBox( - index, - box, - waitingBoxes // - ); - } - - // - // Supply Zones ... - if (!result) - { - // - has = HasSupplyZones(); - if (has) - { - // - XBoxZone tmpBoxes[]; - count = ToBox( - supplyZones, - tmpBoxes // - ); - - // - has = IsValidSize(count); - if (has) - { - // - result = HasInsideBox( - index, - box, - tmpBoxes // - ); - } - - // - Clean(tmpBoxes); - } - } - - // - // Demand Zones ... - if (!result) - { - // - has = HasDemandZones(); - if (has) - { - // - XBoxZone tmpBoxes[]; - count = ToBox( - demandZones, - tmpBoxes // - ); - - // - has = IsValidSize(count); - if (has) - { - // - result = HasInsideBox( - index, - box, - tmpBoxes // - ); - } - - // - Clean(tmpBoxes); - } - } - - // - result = IsValidIndex(index); - - // - return result; - } - - // - bool IsExists(XBoxZone &box) - { - // - bool result = false; - - // - result = box.IsValid(); - if (!result) - { - return result; - } - - // - int idx = -1; - bool has = false; - - // - // Checking Index Waiting Box ... - has = HasWaitingBoxes(); - if (has) - { - // - idx = FindIndex( - box, - waitingBoxes // - ); - result = !IsValidIndex(idx); - if (!result) - { - return result; - } - } - - // - // Checking Index Inside Boxes ... - has = HasInsideBoxes(); - if (has) - { - // - idx = FindIndex( - box, - insideBoxes // - ); - result = !IsValidIndex(idx); - if (!result) - { - return result; - } - } - - // - // Checking Index Breaked Boxes ... - has = HasBreakedBoxes(); - if (has) - { - // - idx = FindIndex( - box, - breakedBoxes // - ); - result = !IsValidIndex(idx); - if (!result) - { - return result; - } - } - - // - // Checking Index BreakedInside Boxes ... - has = HasBreakedInsideBoxes(); - if (has) - { - // - idx = FindIndex( - box, - breakedInsideBoxes // - ); - result = !IsValidIndex(idx); - if (!result) - { - return result; - } - } - - // - return result; - } - - // - bool IsSupplyExists(XCSupplyZone *zone) - { - // - bool result = false; - - // - result = zone != NULL && - zone.IsValid(); - if (!result) - { - return result; - } - - // - // Converts Zone to Box ... - XBoxZone box; - result = ToBox( - box, - zone // - ); - if (!result) - { - // - box.Clean(); - return result; - } - - // - // Checking Index in SupplyZones ... - int idx = FindIndex( - zone, - supplyZones // - ); - result = !IsValidIndex(idx); - if (!result) - { - // - box.Clean(); - return result; - } - - // - result = IsExists(box); - - // - box.Clean(); - - // - return result; - } - - // - bool IsDemandExists(XCDemandZone *zone) - { - // - bool result = false; - - // - result = zone != NULL && - zone.IsValid(); - if (!result) - { - return result; - } - - // - // Converts Zone to Box ... - XBoxZone box; - result = ToBox( - box, - zone // - ); - if (!result) - { - // - box.Clean(); - return result; - } - - // - // Checking Index in SupplyZones ... - int idx = FindIndex( - zone, - demandZones // - ); - result = !IsValidIndex(idx); - if (!result) - { - // - box.Clean(); - return result; - } - - // - result = IsExists(box); - - // - box.Clean(); - - // - return result; - } - // void UpdateTo(datetime value = NULL) { @@ -2308,78 +938,14 @@ struct X121SMCStrategyXWZWorkingZone } // - has = HasSupplyZones(); + has = HasWaitingZones(); if (has) { // - count = CountSupplyZones(); + count = CountWaitingZones(); for (int i = 0; i < count; i++) { - supplyZones[i].To(value); - } - } - - // - has = HasDemandZones(); - if (has) - { - // - count = CountDemandZones(); - for (int i = 0; i < count; i++) - { - demandZones[i].To(value); - } - } - - // - has = HasSupportZones(); - if (has) - { - // - count = CountSupportZones(); - for (int i = 0; i < count; i++) - { - supportZones[i].To(value); - } - } - - // - has = HasResistanceZones(); - if (has) - { - // - count = CountResistanceZones(); - for (int i = 0; i < count; i++) - { - resistanceZones[i].To(value); - } - } - - // - // - // - - // - has = HasWaitingBoxes(); - if (has) - { - // - count = ArraySize(waitingBoxes); - for (int i = 0; i < count; i++) - { - waitingBoxes[i].to = value; - } - } - - // - has = HasInsideBoxes(); - if (has) - { - // - count = CountInsideBoxes(); - for (int i = 0; i < count; i++) - { - insideBoxes[i].to = value; + waitingZones[i].UpdateTo(value); } } @@ -2389,15 +955,9 @@ struct X121SMCStrategyXWZWorkingZone // void Draw( XCPOIDrawer *drawer, - bool drawWaitingBoxes = true, - bool drawInsideBoxes = false, - bool drawBreakedBoxes = false, bool drawSupplyZone = false, bool drawDemandZone = false, - bool drawSupplyZones = false, - bool drawDemandZones = false, - bool drawSupportZones = false, - bool drawResistanceZones = false // + bool drawWaitingZones = false // ) { // @@ -2467,172 +1027,6 @@ struct X121SMCStrategyXWZWorkingZone // // - // - // Supply Zones ... - if (drawSupplyZones) - { - // - has = HasSupplyZones(); - if (has) - { - // - count = CountSupplyZones(); - for (int i = 0; i < count; i++) - { - // - XCSupplyZoneObject *iObj; - isCreated = drawer.CreateSupplyZone( - supplyZones[i], - iObj // - ); - - // - if (isCreated) - { - mWorkingZoneObjects.Add(iObj); - } - } - } - } - - // - // Demand Zones ... - if (drawDemandZones) - { - // - has = HasDemandZones(); - if (has) - { - // - count = CountDemandZones(); - for (int i = 0; i < count; i++) - { - // - XCDemandZoneObject *iObj; - isCreated = drawer.CreateDemandZone( - demandZones[i], - iObj // - ); - - // - if (isCreated) - { - mWorkingZoneObjects.Add(iObj); - } - } - } - } - - // - // Support Zones ... - if (drawSupportZones) - { - // - has = HasSupportZones(); - if (has) - { - // - count = CountSupportZones(); - for (int i = 0; i < count; i++) - { - // - XCSupportZoneObject *iObj; - isCreated = drawer.CreateSupportZone( - supportZones[i], - iObj // - ); - - // - if (isCreated) - { - mWorkingZoneObjects.Add(iObj); - } - } - } - } - - // - // Resistance Zones ... - if (drawResistanceZones) - { - // - has = HasResistanceZones(); - if (has) - { - // - count = CountResistanceZones(); - for (int i = 0; i < count; i++) - { - // - XCResistanceZoneObject *iObj; - isCreated = drawer.CreateResistanceZone( - resistanceZones[i], - iObj // - ); - - // - if (isCreated) - { - mWorkingZoneObjects.Add(iObj); - } - } - } - } - - // - // - // - - // - // Waiting Boxes ... - if (drawWaitingBoxes) - { - // - has = HasWaitingBoxes(); - if (has) - { - // - count = CountWaitingBoxes(); - for (int i = 0; i < count; i++) - { - // - XBoxZone iBox = waitingBoxes[i]; - - // - XCBoxObject *iObj; - bool isCreated = drawer.DrawBox( - iBox, - iObj // - ); - - // - if (isCreated) - { - mWorkingZoneObjects.Add(iObj); - } - - // - iBox.Clean(); - } - } - } - - // - // Inside Boxes ... - if (drawInsideBoxes) - { - } - - // - // Breaked Boxes ... - if (drawBreakedBoxes) - { - } - - // - // - // - // // Quarters ... has = IsValid(); @@ -2665,7 +1059,7 @@ struct X121SMCStrategyXWZWorkingZone zoneUpperLine.Color(clrRed); // - mWaitingZoneObjects.Add(zoneUpperLine); + mWorkingZoneObjects.Add(zoneUpperLine); } // @@ -2684,7 +1078,7 @@ struct X121SMCStrategyXWZWorkingZone zoneLowerLine.Color(clrRed); // - mWaitingZoneObjects.Add(zoneLowerLine); + mWorkingZoneObjects.Add(zoneLowerLine); } // @@ -2703,7 +1097,7 @@ struct X121SMCStrategyXWZWorkingZone upperLine.Color(clrLime); // - mWaitingZoneObjects.Add(upperLine); + mWorkingZoneObjects.Add(upperLine); } // @@ -2722,7 +1116,7 @@ struct X121SMCStrategyXWZWorkingZone lowerLine.Color(clrLime); // - mWaitingZoneObjects.Add(lowerLine); + mWorkingZoneObjects.Add(lowerLine); } // @@ -2744,7 +1138,7 @@ struct X121SMCStrategyXWZWorkingZone q1Line.Color(clrYellow); // - mWaitingZoneObjects.Add(q1Line); + mWorkingZoneObjects.Add(q1Line); } // @@ -2763,7 +1157,7 @@ struct X121SMCStrategyXWZWorkingZone q2Line.Color(clrYellow); // - mWaitingZoneObjects.Add(q2Line); + mWorkingZoneObjects.Add(q2Line); } // @@ -2782,9 +1176,55 @@ struct X121SMCStrategyXWZWorkingZone q3Line.Color(clrYellow); // - mWaitingZoneObjects.Add(q3Line); + mWorkingZoneObjects.Add(q3Line); } } + + // + // Waiting Zones ... + if (drawWaitingZones) + { + // + has = HasWaitingZones(); + if (has) + { + // + count = CountWaitingZones(); + for (int i = 0; i < count; i++) + { + // + XCBaseObject *iObjects[]; + int iObjectsCount = drawer.DrawOBFVG( + waitingZones[i], + iObjects, + true, // Draw Order Block ... + true, // Draw Fair Value Gaps ... + // + true, // Draw OB StartedBar ... + true, // Draw OB ActivatedBar ... + true, // Draw OB BreakedBar ... + true, // Draw OB WorkedBar ... + // + true, // Draw FVG StartedBar ... + true, // Draw FVG ActivatedBar ... + true, // Draw FVG BreakedBar ... + true // Draw FVG WorkedBar ... + // + ); + has = IsValidSize(iObjectsCount); + if (has) + { + // + for (int j = 0; j < iObjectsCount; j++) + { + mDrawnObjects.Add(iObjects[j]); + } + } + } + } + } + + // } // @@ -2806,111 +1246,15 @@ struct X121SMCStrategyXWZWorkingZone } // - bool HasSupplyZones() + bool HasWaitingZones() { - return HasChild(supplyZones); + return HasChild(waitingZones); } // - int CountSupplyZones() + int CountWaitingZones() { - return ArraySize(supplyZones); - } - - // - bool HasDemandZones() - { - return HasChild(demandZones); - } - - // - int CountDemandZones() - { - return ArraySize(demandZones); - } - - // - bool HasSupportZones() - { - return HasChild(supportZones); - } - - // - int CountSupportZones() - { - return ArraySize(supportZones); - } - - // - bool HasResistanceZones() - { - return HasChild(resistanceZones); - } - - // - int CountResistanceZones() - { - return ArraySize(resistanceZones); - } - - // - bool HasConsolidationZones() - { - return HasChild(consolidationZones); - } - - // - int CountConsolidationZones() - { - return ArraySize(consolidationZones); - } - - // - bool HasWaitingBoxes() - { - return HasChild(waitingBoxes); - } - - // - int CountWaitingBoxes() - { - return ArraySize(waitingBoxes); - } - - // - bool HasInsideBoxes() - { - return HasChild(insideBoxes); - } - - // - int CountInsideBoxes() - { - return ArraySize(insideBoxes); - } - - // - bool HasBreakedBoxes() - { - return HasChild(breakedBoxes); - } - - // - int CountBreakedBoxes() - { - return ArraySize(breakedBoxes); - } - - // - bool HasBreakedInsideBoxes() - { - return HasChild(breakedInsideBoxes); - } - - // - int CountBreakedInsideBoxes() - { - return ArraySize(breakedInsideBoxes); + return ArraySize(waitingZones); } // diff --git a/X121SMCEA/Strategy/x-121.smc.strategy.class.mq5 b/X121SMCEA/Strategy/x-121.smc.strategy.class.mq5 index 21e1e2c7..83a085b2 100644 --- a/X121SMCEA/Strategy/x-121.smc.strategy.class.mq5 +++ b/X121SMCEA/Strategy/x-121.smc.strategy.class.mq5 @@ -768,8 +768,8 @@ class XCX121SMCStrategy : public XCX121SMCBaseStrategy // // XPV ... x121Inputs.xpvInputs.showSar = showAll || false; - x121Inputs.xpvInputs.showPeaks = showAll || false; - x121Inputs.xpvInputs.showVales = showAll || false; + x121Inputs.xpvInputs.showPeaks = showAll || true; + x121Inputs.xpvInputs.showVales = showAll || true; // // XHK ...