diff --git a/Documents/BKP/1.mq5 b/Documents/BKP/1.mq5 index 18a50421..1ad0bffc 100644 --- a/Documents/BKP/1.mq5 +++ b/Documents/BKP/1.mq5 @@ -46,194 +46,1246 @@ // signal.target = tp; // } +// +// consolidationState.UpdateTo(cTime); +// XPOIState filtered; +// consolidationState.Filter( +// filtered, +// NULL, +// XZONE_STATE_PASSED, +// false, +// XZONE_STATE_FAILED, +// false, +// XZONE_STATE_FAILED, +// false, +// XZONE_STATE_IGNORED, +// false // +// ); +// XCBaseObject *objects[]; +// int objectsCount = drawer.DrawState( +// filtered, +// objects // +// ); +// if (IsValidSize(objectsCount)) +// { +// // +// Print(""); +// } - // - // consolidationState.UpdateTo(cTime); - // XPOIState filtered; - // consolidationState.Filter( - // filtered, - // NULL, - // XZONE_STATE_PASSED, - // false, - // XZONE_STATE_FAILED, - // false, - // XZONE_STATE_FAILED, - // false, - // XZONE_STATE_IGNORED, - // false // - // ); - // XCBaseObject *objects[]; - // int objectsCount = drawer.DrawState( - // filtered, - // objects // - // ); - // if (IsValidSize(objectsCount)) - // { - // // - // Print(""); - // } +// // +// XOBFVG activeObfvgs[]; +// int activeObfvgsCount = ExtractOBFVGs( +// activeObfvgs, +// consolidationState, +// analyseState // +// ); +// bool hasActiveOBFVGs = IsValidSize(activeObfvgsCount); +// if (hasActiveOBFVGs) +// { +// // +// SpecifiedUpdateTo(activeObfvgs); +// for (int i = 0; i < activeObfvgsCount; i++) +// { +// // +// XCBaseObject *objects[]; +// int objectsCount = drawer.DrawOBFVG( +// activeObfvgs[i], +// objects // +// ); +// } +// } - // // - // XOBFVG activeObfvgs[]; - // int activeObfvgsCount = ExtractOBFVGs( - // activeObfvgs, - // consolidationState, - // analyseState // - // ); - // bool hasActiveOBFVGs = IsValidSize(activeObfvgsCount); - // if (hasActiveOBFVGs) - // { - // // - // SpecifiedUpdateTo(activeObfvgs); - // for (int i = 0; i < activeObfvgsCount; i++) - // { - // // - // XCBaseObject *objects[]; - // int objectsCount = drawer.DrawOBFVG( - // activeObfvgs[i], - // objects // - // ); - // } - // } +// // +// // Swings ... +// bool lookupSwings = ArraySize(mSwingLows) < mMaxRequiredPOIs || +// ArraySize(mSwingHighs) < mMaxRequiredPOIs; +// lookupSwings = +// ignoreMaxAllowed +// ? true +// : lookupSwings; +// if (has && +// lookupSwings) +// { +// } + +// // +// // Momentum Bar ... +// bool lookupMomentums = ArraySize(mBullishMomentumBars) < mMaxRequiredPOIs || +// ArraySize(mBearishMomentumBars) < mMaxRequiredPOIs; +// lookupMomentums = +// ignoreMaxAllowed +// ? true +// : lookupMomentums; +// if (has && +// lookupMomentums) +// { +// } + +// // +// // Rejection Bar ... +// bool lookupRejections = ArraySize(mBullishRejectionBars) < mMaxRequiredPOIs || +// ArraySize(mBearishRejectionBars) < mMaxRequiredPOIs; +// lookupRejections = +// ignoreMaxAllowed +// ? true +// : lookupRejections; +// if (has && +// lookupRejections) +// { +// } + +// // +// // Support ... +// bool lookupSupports = ArraySize(mSupportZones) < mMaxRequiredPOIs; +// lookupSupports = +// ignoreMaxAllowed +// ? true +// : lookupSupports; +// if (has && +// lookupSupports) +// { +// } + +// // +// // Demand ... +// bool lookupDemands = ArraySize(mDemandZones) < mMaxRequiredPOIs; +// lookupDemands = +// ignoreMaxAllowed +// ? true +// : lookupDemands; +// if (has && +// lookupDemands) +// { +// } + +// // +// // Resistance ... +// bool lookupResistance = ArraySize(mResistanceZones) < mMaxRequiredPOIs; +// lookupResistance = +// ignoreMaxAllowed +// ? true +// : lookupResistance; +// if (has && +// lookupResistance) +// { +// } + +// // +// // Supply ... +// bool lookupSupplies = ArraySize(mSupplyZones) < mMaxRequiredPOIs; +// lookupSupplies = +// ignoreMaxAllowed +// ? true +// : lookupSupplies; +// if (has && +// lookupSupplies) +// { +// } + +// // +// // OrderBlock ... +// bool lookupOrderBlocks = ArraySize(mBullishOrderBlocks) < mMaxRequiredPOIs || +// ArraySize(mBearishOrderBlocks) < mMaxRequiredPOIs; +// lookupOrderBlocks = +// ignoreMaxAllowed +// ? true +// : lookupOrderBlocks; +// if (has && +// lookupOrderBlocks) +// { +// } + +// // +// // FairValueGap ... +// bool lookupFairValeGaps = ArraySize(mBullishFairValueGaps) < mMaxRequiredPOIs || +// ArraySize(mBearishFairValueGaps) < mMaxRequiredPOIs; +// lookupFairValeGaps = +// ignoreMaxAllowed +// ? true +// : lookupFairValeGaps; +// if (has && +// (lookupFairValeGaps)) +// { +// } + +// +XCBaseObject *stateObjects[]; +int stateObjectsCount = drawer.DrawState( + decisionState, + stateObjects, + false, // + true, // ignoreSwingHighs + true, // ignoreSwingLows + true, // ignoreSupportZones + true, // ignoreResistanceZones + true, // ignoreSupplyZones + true, // ignoreDemandZones + true, // ignoreBullishOrderBlocks + true, // ignoreBearishOrderBlocks + true, // ignoreBullishFairValueGaps + true, // ignoreBearishFairValueGaps + true, // ignoreBullishRejectionBars + true, // ignoreBearishRejectionBars + true, // ignoreBullishMomentumBars + true, // ignoreBearishMomentumBars + false, // ignoreBullishConsolidationZones + false // ignoreBearishConsolidationZones +); + +// +// Draw ... +if (hasSelectedConsolidationZone) +{ + // + XCConsolidationZoneObject *iObj; + selectedConsolidationZone.to = cTime; + bool isCreated = drawer.CreateConsolidationZone( + selectedConsolidationZone, + iObj // + ); +} + + +///////////////////////////////////////////////////////////////////////////////////// - // // - // // Swings ... - // bool lookupSwings = ArraySize(mSwingLows) < mMaxRequiredPOIs || - // ArraySize(mSwingHighs) < mMaxRequiredPOIs; - // lookupSwings = - // ignoreMaxAllowed - // ? true - // : lookupSwings; - // if (has && - // lookupSwings) + // // Based On Waiting Zones ... + // has = isBarInited && + // hasWorkingZone; + // if (has) // { + // // + // XOBFVG tmpZones[]; + // Copy( + // workingZone.waitingZones, + // tmpZones // + // ); + + // // + // while (HasChild(tmpZones)) + // { + // // + // XOBFVG iOBFVG; + + // // + // idx = GetYoungest(tmpZones); + // if (!IsValidIndex(idx)) + // { + // // + // iOBFVG.Clean(); + // break; + // } + + // // + // iOBFVG = tmpZones[idx]; + // ArrayRemove( + // tmpZones, + // idx, + // 1 // + // ); + + // // + // double iTarget = + // isSelectedZonDirBullish + // ? iOBFVG.ob.Lower() + // : iOBFVG.ob.Upper(); + + // // + // has = + // isSelectedZonDirBullish + // ? cBar.high < iTarget + // : cBar.low > iTarget; + + // // + // if (has) + // { + // // + // Add( + // iTarget, + // targets // + // ); + // } + + // // + // iOBFVG.Clean(); + // } + + // // + // Clean(tmpZones); // } // // - // // Momentum Bar ... - // bool lookupMomentums = ArraySize(mBullishMomentumBars) < mMaxRequiredPOIs || - // ArraySize(mBearishMomentumBars) < mMaxRequiredPOIs; - // lookupMomentums = - // ignoreMaxAllowed - // ? true - // : lookupMomentums; - // if (has && - // lookupMomentums) + // // Based On Breaked Zones ... + // has = isBarInited && + // hasBreakedZones; + // if (has) // { + // // + // XOBFVG tmpZones[]; + // Copy( + // workingZone.breakedZones, + // tmpZones // + // ); + + // // + // while (HasChild(tmpZones)) + // { + // // + // XOBFVG iOBFVG; + + // // + // idx = GetYoungest(tmpZones); + // if (!IsValidIndex(idx)) + // { + // // + // iOBFVG.Clean(); + // break; + // } + + // // + // iOBFVG = tmpZones[idx]; + // ArrayRemove( + // tmpZones, + // idx, + // 1 // + // ); + + // // + // double iTarget = + // isSelectedZonDirBullish + // ? iOBFVG.ob.Lower() + // : iOBFVG.ob.Upper(); + + // // + // has = + // isSelectedZonDirBullish + // ? cBar.high < iTarget + // : cBar.low > iTarget; + + // // + // if (has) + // { + // // + // Add( + // iTarget, + // targets // + // ); + // } + + // // + // iOBFVG.Clean(); + // } + + // // + // Clean(tmpZones); // } // // - // // Rejection Bar ... - // bool lookupRejections = ArraySize(mBullishRejectionBars) < mMaxRequiredPOIs || - // ArraySize(mBearishRejectionBars) < mMaxRequiredPOIs; - // lookupRejections = - // ignoreMaxAllowed - // ? true - // : lookupRejections; - // if (has && - // lookupRejections) + // // Based On Priority ... + // if (hasPriority) // { - // } + // // + // switch (priority) + // { + // // + // case X121SMC_XWZ_PRIORITY_WEAK: + // // + // if (isSelectedZonDirBullish) + // { + // // + // // Weak ... + // Add( + // workingZone.supplyZone.Lower(), + // targets // + // ); + // } + // else + // { + // // + // // Weak ... + // Add( + // workingZone.demandZone.Upper(), + // targets // + // ); + // } + // break; - // // - // // Support ... - // bool lookupSupports = ArraySize(mSupportZones) < mMaxRequiredPOIs; - // lookupSupports = - // ignoreMaxAllowed - // ? true - // : lookupSupports; - // if (has && - // lookupSupports) - // { - // } + // // + // case X121SMC_XWZ_PRIORITY_LOW: + // // + // if (isSelectedZonDirBullish) + // { + // // + // // Weak ... + // Add( + // workingZone.supplyZone.Lower(), + // targets // + // ); - // // - // // Demand ... - // bool lookupDemands = ArraySize(mDemandZones) < mMaxRequiredPOIs; - // lookupDemands = - // ignoreMaxAllowed - // ? true - // : lookupDemands; - // if (has && - // lookupDemands) - // { - // } + // // + // // Low ... + // Add( + // workingZone.quarter1, + // targets // + // ); + // } + // else + // { + // // + // // Weak ... + // Add( + // workingZone.demandZone.Upper(), + // targets // + // ); - // // - // // Resistance ... - // bool lookupResistance = ArraySize(mResistanceZones) < mMaxRequiredPOIs; - // lookupResistance = - // ignoreMaxAllowed - // ? true - // : lookupResistance; - // if (has && - // lookupResistance) - // { - // } + // // + // // Low ... + // Add( + // workingZone.quarter3, + // targets // + // ); + // } + // break; - // // - // // Supply ... - // bool lookupSupplies = ArraySize(mSupplyZones) < mMaxRequiredPOIs; - // lookupSupplies = - // ignoreMaxAllowed - // ? true - // : lookupSupplies; - // if (has && - // lookupSupplies) - // { - // } + // // + // case X121SMC_XWZ_PRIORITY_REGULAR: + // // + // if (isSelectedZonDirBullish) + // { + // // + // // Weak ... + // Add( + // workingZone.supplyZone.Lower(), + // targets // + // ); - // // - // // OrderBlock ... - // bool lookupOrderBlocks = ArraySize(mBullishOrderBlocks) < mMaxRequiredPOIs || - // ArraySize(mBearishOrderBlocks) < mMaxRequiredPOIs; - // lookupOrderBlocks = - // ignoreMaxAllowed - // ? true - // : lookupOrderBlocks; - // if (has && - // lookupOrderBlocks) - // { - // } + // // + // // Low ... + // Add( + // workingZone.quarter1, + // targets // + // ); - // // - // // FairValueGap ... - // bool lookupFairValeGaps = ArraySize(mBullishFairValueGaps) < mMaxRequiredPOIs || - // ArraySize(mBearishFairValueGaps) < mMaxRequiredPOIs; - // lookupFairValeGaps = - // ignoreMaxAllowed - // ? true - // : lookupFairValeGaps; - // if (has && - // (lookupFairValeGaps)) - // { + // // + // // 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 (isSelectedZonDirBullish) + // { + // // + // // 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 (isSelectedZonDirBullish) + // { + // // + // // 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; + // } // } - // - XCBaseObject *stateObjects[]; - int stateObjectsCount = drawer.DrawState( - decisionState, - stateObjects, - false, // - true, // ignoreSwingHighs - true, // ignoreSwingLows - true, // ignoreSupportZones - true, // ignoreResistanceZones - true, // ignoreSupplyZones - true, // ignoreDemandZones - true, // ignoreBullishOrderBlocks - true, // ignoreBearishOrderBlocks - true, // ignoreBullishFairValueGaps - true, // ignoreBearishFairValueGaps - true, // ignoreBullishRejectionBars - true, // ignoreBearishRejectionBars - true, // ignoreBullishMomentumBars - true, // ignoreBearishMomentumBars - false, // ignoreBullishConsolidationZones - false // ignoreBearishConsolidationZones - ); +//////////////////////////////////////////////////////////////////// - \ No newline at end of file + // + // Based On Consolidation Zones ... + has = isBarInited && + decisionState.HasConsolidationZones(); + if (has) + { + // + XConsolidationZone tmpZones[]; + if (isSelectedZonDirBullish) + { + // + Copy( + decisionState.bullishConsolidationZones, + tmpZones // + ); + } + else + { + // + Copy( + decisionState.bearishConsolidationZones, + tmpZones // + ); + } + + // + while (HasChild(tmpZones)) + { + // + idx = GetYoungest(tmpZones); + if (!IsValidIndex(idx)) + { + break; + } + + // + XConsolidationZone iZone = tmpZones[idx]; + + // + ArrayRemove( + tmpZones, + idx, + 1 // + ); + + // + hasSelectedConsolidationZone = + isSelectedZonDirBullish + ? cBar.low < iZone.upper + : cBar.high < iZone.lower; + if (hasSelectedConsolidationZone) + { + // + selectedConsolidationZone = iZone; + iZone.Clean(); + break; + } + + // + iZone.Clean(); + } + + // + Clean(tmpZones); + + // + if (hasSelectedConsolidationZone) + { + // + XCConsolidationZoneObject *iObj; + selectedConsolidationZone.to = cTime; + bool isCreated = drawer.CreateConsolidationZone( + selectedConsolidationZone, + iObj // + ); + + // + double iSL = + isSelectedZonDirBullish + ? selectedConsolidationZone.lower + : selectedConsolidationZone.upper; + double iSLDiff = MathAbs(iSL - pivot); + has = + iSLDiff > 0 && + iSLDiff <= maxAllowedSLDistanceInPoint * points; + if (has) + { + // + Add( + iSL, + sls // + ); + } + } + } + + // + // Based On Supply and Demand Zones ... + + // + // Demand Zones ... + has = hasWorkingZone && + workingZone.HasDemandZones(); + if (has) + { + // + XCDemandZone *tmpZones[]; + Copy( + workingZone.demandZones, + tmpZones // + ); + XCDemandZone *selectedDemand = NULL; + + // + while (HasChild(tmpZones)) + { + // + idx = GetLowest(tmpZones); + has = IsValidIndex(idx); + if (!has) + { + break; + } + + // + XCDemandZone *iZone = tmpZones[idx]; + ArrayRemove( + tmpZones, + idx, + 1 // + ); + + // + // Validate Zone ... + has = + isSelectedZonDirBullish + ? IsBelowDiff( + iZone, + selectedZone.ob, + true // Ignore Inside ... + ) + : IsAboveDiff( + iZone, + selectedZone.ob, + true // Ignore Inside ... + ); + if (!has) + { + continue; + } + + // + has = + selectedDemand == NULL + ? true + : isSelectedZonDirBullish + ? selectedDemand.Lower() < iZone.Lower() + : selectedDemand.Upper() > iZone.Upper(); + if (!has) + { + continue; + } + + // + selectedDemand = iZone; + + // + } + + // + has = selectedDemand != NULL; + if (has) + { + // + XCDemandZoneObject *iObj; + bool isCreated = drawer.CreateDemandZone( + selectedDemand, + iObj // + ); + + // + double iSL = + isSelectedZonDirBullish + ? selectedDemand.Lower() + : selectedDemand.Upper(); + double iSLDiff = MathAbs(iSL - pivot); + has = + iSLDiff > 0 && + iSLDiff <= maxAllowedSLDistanceInPoint * points; + if (has) + { + // + Add( + iSL, + sls // + ); + } + } + + // + Clean(tmpZones); + ZeroMemory(selectedDemand); + } + + // + // Support Zones ... + has = hasWorkingZone && + workingZone.HasSupportZones(); + if (has) + { + // + XCSupportZone *tmpZones[]; + Copy( + workingZone.supportZones, + tmpZones // + ); + XCSupportZone *selectedSupport = NULL; + + // + while (HasChild(tmpZones)) + { + // + idx = GetLowest(tmpZones); + has = IsValidIndex(idx); + if (!has) + { + break; + } + + // + XCSupportZone *iZone = tmpZones[idx]; + ArrayRemove( + tmpZones, + idx, + 1 // + ); + + // + // Validate Zone ... + has = + isSelectedZonDirBullish + ? IsBelowDiff( + iZone, + selectedZone.ob, + true // Ignore Inside ... + ) + : IsAboveDiff( + iZone, + selectedZone.ob, + true // Ignore Inside ... + ); + if (!has) + { + continue; + } + + // + has = + selectedSupport == NULL + ? true + : isSelectedZonDirBullish + ? selectedSupport.Lower() < iZone.Lower() + : selectedSupport.Upper() > iZone.Upper(); + if (!has) + { + continue; + } + + // + selectedSupport = iZone; + + // + } + + // + has = selectedSupport != NULL; + if (has) + { + // + XCSupportZoneObject *iObj; + bool isCreated = drawer.CreateSupportZone( + selectedSupport, + iObj // + ); + + // + double iSL = isSelectedZonDirBullish + ? selectedSupport.Lower() + : selectedSupport.Upper(); + double iSLDiff = MathAbs(iSL - pivot); + has = + iSLDiff > 0 && + iSLDiff <= maxAllowedSLDistanceInPoint * points; + if (has) + { + // + Add( + iSL, + sls // + ); + } + } + + // + Clean(tmpZones); + ZeroMemory(selectedSupport); + } + + // + // Supply Zones ... + has = hasWorkingZone && + workingZone.HasSupplyZones(); + if (has) + { + // + XCSupplyZone *tmpZones[]; + Copy( + workingZone.supplyZones, + tmpZones // + ); + XCSupplyZone *selectedSupply = NULL; + + // + while (HasChild(tmpZones)) + { + // + idx = GetHighest(tmpZones); + has = IsValidIndex(idx); + if (!has) + { + break; + } + + // + XCSupplyZone *iZone = tmpZones[idx]; + ArrayRemove( + tmpZones, + idx, + 1 // + ); + + // + // Validate Zone ... + has = + !isSelectedZonDirBullish + ? IsAboveDiff( + iZone, + selectedZone.ob, + true // Ignore Inside ... + ) + : IsBelowDiff( + iZone, + selectedZone.ob, + true // Ignore Inside ... + ); + if (!has) + { + continue; + } + + // + has = + selectedSupply == NULL + ? true + : !isSelectedZonDirBullish + ? selectedSupply.Upper() > iZone.Upper() + : selectedSupply.Lower() < iZone.Lower(); + if (!has) + { + continue; + } + + // + selectedSupply = iZone; + + // + } + + // + has = selectedSupply != NULL; + if (has) + { + // + XCSupplyZoneObject *iObj; + bool isCreated = drawer.CreateSupplyZone( + selectedSupply, + iObj // + ); + + // + double iSL = + !isSelectedZonDirBullish + ? selectedSupply.Upper() + : selectedSupply.Lower(); + double iSLDiff = MathAbs(iSL - pivot); + has = + iSLDiff > 0 && + iSLDiff <= maxAllowedSLDistanceInPoint * points; + if (has) + { + // + Add( + iSL, + sls // + ); + } + } + + // + Clean(tmpZones); + ZeroMemory(selectedSupply); + } + + // + // Resistance Zones ... + has = hasWorkingZone && + workingZone.HasDemandZones(); + if (has) + { + // + XCResistanceZone *tmpZones[]; + Copy( + workingZone.resistanceZones, + tmpZones // + ); + XCResistanceZone *selectedResistance = NULL; + + // + while (HasChild(tmpZones)) + { + // + idx = GetHighest(tmpZones); + has = IsValidIndex(idx); + if (!has) + { + break; + } + + // + XCResistanceZone *iZone = tmpZones[idx]; + ArrayRemove( + tmpZones, + idx, + 1 // + ); + + // + // Validate Zone ... + has = + !isSelectedZonDirBullish + ? IsAboveDiff( + iZone, + selectedZone.ob, + true // Ignore Inside ... + ) + : IsBelowDiff( + iZone, + selectedZone.ob, + true // Ignore Inside ... + ); + if (!has) + { + continue; + } + + // + has = + selectedResistance == NULL + ? true + : !isSelectedZonDirBullish + ? selectedResistance.Upper() < iZone.Upper() + : selectedResistance.Lower() > iZone.Lower(); + if (!has) + { + continue; + } + + // + selectedResistance = iZone; + + // + } + + // + has = selectedResistance != NULL; + if (has) + { + // + XCResistanceZoneObject *iObj; + bool isCreated = drawer.CreateResistanceZone( + selectedResistance, + iObj // + ); + + // + double iSL = + !isSelectedZonDirBullish + ? selectedResistance.Upper() + : selectedResistance.Lower(); + double iSLDiff = MathAbs(iSL - pivot); + has = + iSLDiff > 0 && + iSLDiff <= maxAllowedSLDistanceInPoint * points; + if (has) + { + // + Add( + iSL, + sls // + ); + } + } + + // + Clean(tmpZones); + ZeroMemory(selectedResistance); + } + + // + // Based On Passed Bars ... + XOHCL passedBar; + bool isPassed = false; + bool isBodyState = false; + ENUM_X_DIRECTION passedDir = selectedZone.GetDirection(); + + // + // Started Bar ... + isPassed = selectedZone.ob.IsStarted( + passedDir, + passedBar, + isBodyState // + ); + if (isPassed) + { + // + double iSL = + isSelectedZonDirBullish + ? passedBar.low + : passedBar.high; + double iSLDiff = MathAbs(iSL - pivot); + has = + iSLDiff > 0 && + iSLDiff <= maxAllowedSLDistanceInPoint * points; + if (has) + { + // + Add( + iSL, + sls // + ); + } + } + + // + // Activation Bar ... + passedBar.Clean(); + isPassed = selectedZone.ob.IsActivated( + passedDir, + passedBar, + isBodyState // + ); + if (isPassed) + { + // + double iSL = + isSelectedZonDirBullish + ? passedBar.low + : passedBar.high; + double iSLDiff = MathAbs(iSL - pivot); + has = + iSLDiff > 0 && + iSLDiff <= maxAllowedSLDistanceInPoint * points; + if (has) + { + // + Add( + iSL, + sls // + ); + } + } + + // + // Worked Bar ... + passedBar.Clean(); + isPassed = selectedZone.ob.IsActivated( + passedDir, + passedBar, + isBodyState // + ); + if (isPassed) + { + // + double iSL = + isSelectedZonDirBullish + ? passedBar.low + : passedBar.high; + double iSLDiff = MathAbs(iSL - pivot); + has = + iSLDiff > 0 && + iSLDiff <= maxAllowedSLDistanceInPoint * points; + if (has) + { + // + Add( + iSL, + sls // + ); + } + } + + // + // Breaked Bar ... + passedBar.Clean(); + isPassed = selectedZone.ob.IsActivated( + passedDir, + passedBar, + isBodyState // + ); + if (isPassed) + { + // + double iSL = + isSelectedZonDirBullish + ? passedBar.low + : passedBar.high; + double iSLDiff = MathAbs(iSL - pivot); + has = + iSLDiff > 0 && + iSLDiff <= maxAllowedSLDistanceInPoint * points; + if (has) + { + // + Add( + iSL, + sls // + ); + } + } + + \ No newline at end of file diff --git a/Libraries/x-saherelm.x-poi.extensions.lib.mq5 b/Libraries/x-saherelm.x-poi.extensions.lib.mq5 index 57e91262..25405c21 100644 --- a/Libraries/x-saherelm.x-poi.extensions.lib.mq5 +++ b/Libraries/x-saherelm.x-poi.extensions.lib.mq5 @@ -1805,10 +1805,14 @@ int GetLowest( return result; } +// +// +// + /** - * Get Oldest Box Index ... + * Get Oldest Index ... * - * @param source: XBoxZone instance Reference Collection ... + * @param source: XConsolidationZone instance Reference Collection ... * * @return ( int ) */ @@ -1868,9 +1872,9 @@ int GetOldest( } /** - * Get Youngest Box Index ... + * Get Youngest Index ... * - * @param source: XBoxZone instance Reference Collection ... + * @param source: XConsolidationZone instance Reference Collection ... * * @return ( int ) */ @@ -1930,9 +1934,9 @@ int GetYoungest( } /** - * Get Highest Box Index ... + * Get Highest Index ... * - * @param source: XBoxZone instance Reference Collection ... + * @param source: XConsolidationZone instance Reference Collection ... * * @return ( int ) */ @@ -1992,9 +1996,9 @@ int GetHighest( } /** - * Get Lowest Box Index ... + * Get Lowest Index ... * - * @param source: XBoxZone instance Reference Collection ... + * @param source: XConsolidationZone instance Reference Collection ... * * @return ( int ) */ @@ -2053,6 +2057,10 @@ int GetLowest( return result; } +// +// +// + // template void SortZones( diff --git a/Libraries/x-saherelm.x-poi.state.lib.mq5 b/Libraries/x-saherelm.x-poi.state.lib.mq5 index 717685fa..f8a1da40 100644 --- a/Libraries/x-saherelm.x-poi.state.lib.mq5 +++ b/Libraries/x-saherelm.x-poi.state.lib.mq5 @@ -3857,6 +3857,16 @@ int ExtractOBFVGs( return result; } +// +// Extensions Functions ... +// + +/** + * Update to Time of Specifiex Collection ... + * + * @param items: XOBFVG instance Collection ... + * @param value: datetime ... + */ void SpecifiedUpdateTo( XOBFVG &items[], datetime value = NULL // @@ -3880,4 +3890,335 @@ void SpecifiedUpdateTo( } } +/** + * Converts to XBoxZone ... + * + * @return ( bool ) + */ +bool ToBox( + XBoxZone &box, + XOBFVG &item // +) +{ + // + bool result = false; + + // + result = ToBox( + box, + item.ob // + ); + + // + return result; +} + +/** + * Converts to XBoxZone ... + * + * @return ( bool ) + */ +int ToBox( + XOBFVG &source[], + XBoxZone &dest[] // +) +{ + // + int result = 0; + + // + Clean(dest); + int count = ArraySize(source); + if (!IsValidSize(count)) + { + return result; + } + + // + for (int i = 0; i < count; i++) + { + // + XOBFVG iZone = source[i]; + + // + XBoxZone iBox; + bool hasBox = ToBox( + iBox, + iZone // + ); + + // + if (hasBox) + { + // + AddRef( + iBox, + dest // + ); + } + + // + iBox.Clean(); + iZone.Clean(); + } + + // + result = ArraySize(dest); + + // + return result; +} + +// +// +// + +/** + * Get Oldest Index ... + * + * @param source: XOBFVG instance Reference Collection ... + * + * @return ( int ) + */ +int GetOldest( + XOBFVG &source[] // +) +{ + // + int result = -1; + + // + int count = ArraySize(source); + if (!IsValidSize(count)) + { + return result; + } + + // + XBoxZone tmpBoxes[]; + int boxesCount = ToBox( + source, + tmpBoxes // + ); + if (!IsValidSize(boxesCount)) + { + // + Clean(tmpBoxes); + return result; + } + + // + XBoxZone selected; + for (int i = 0; i < boxesCount; i++) + { + // + XBoxZone iBox = tmpBoxes[i]; + + // + bool canSet = + !selected.IsValid() + ? true + : selected.from > iBox.from; + if (canSet) + { + // + result = i; + selected = iBox; + } + } + + // + Clean(tmpBoxes); + selected.Clean(); + + // + return result; +} + +/** + * Get Youngest Index ... + * + * @param source: XOBFVG instance Reference Collection ... + * + * @return ( int ) + */ +int GetYoungest( + XOBFVG &source[] // +) +{ + // + int result = -1; + + // + int count = ArraySize(source); + if (!IsValidSize(count)) + { + return result; + } + + // + XBoxZone tmpBoxes[]; + int boxesCount = ToBox( + source, + tmpBoxes // + ); + if (!IsValidSize(boxesCount)) + { + // + Clean(tmpBoxes); + return result; + } + + // + XBoxZone selected; + for (int i = 0; i < boxesCount; i++) + { + // + XBoxZone iBox = tmpBoxes[i]; + + // + bool canSet = + !selected.IsValid() + ? true + : selected.from < iBox.from; + if (canSet) + { + // + result = i; + selected = iBox; + } + } + + // + Clean(tmpBoxes); + selected.Clean(); + + // + return result; +} + +/** + * Get Highest Index ... + * + * @param source: XOBFVG instance Reference Collection ... + * + * @return ( int ) + */ +int GetHighest( + XOBFVG &source[] // +) +{ + // + int result = -1; + + // + int count = ArraySize(source); + if (!IsValidSize(count)) + { + return result; + } + + // + XBoxZone tmpBoxes[]; + int boxesCount = ToBox( + source, + tmpBoxes // + ); + if (!IsValidSize(boxesCount)) + { + // + Clean(tmpBoxes); + return result; + } + + // + XBoxZone selected; + for (int i = 0; i < boxesCount; i++) + { + // + XBoxZone iBox = tmpBoxes[i]; + + // + bool canSet = + !selected.IsValid() + ? true + : selected.upper < iBox.upper; + if (canSet) + { + // + result = i; + selected = iBox; + } + } + + // + Clean(tmpBoxes); + selected.Clean(); + + // + return result; +} + +/** + * Get Lowest Index ... + * + * @param source: XOBFVG instance Reference Collection ... + * + * @return ( int ) + */ +int GetLowest( + XOBFVG &source[] // +) +{ + // + int result = -1; + + // + int count = ArraySize(source); + if (!IsValidSize(count)) + { + return result; + } + + // + XBoxZone tmpBoxes[]; + int boxesCount = ToBox( + source, + tmpBoxes // + ); + if (!IsValidSize(boxesCount)) + { + // + Clean(tmpBoxes); + return result; + } + + // + XBoxZone selected; + for (int i = 0; i < boxesCount; i++) + { + // + XBoxZone iBox = tmpBoxes[i]; + + // + bool canSet = + !selected.IsValid() + ? true + : selected.lower > iBox.lower; + if (canSet) + { + // + result = i; + selected = iBox; + } + } + + // + Clean(tmpBoxes); + selected.Clean(); + + // + return result; +} + // diff --git a/X121SMCEA/Signals/x-121.smc.xwz.signal.class.mq5 b/X121SMCEA/Signals/x-121.smc.xwz.signal.class.mq5 index 2418cee2..b38aaf96 100644 --- a/X121SMCEA/Signals/x-121.smc.xwz.signal.class.mq5 +++ b/X121SMCEA/Signals/x-121.smc.xwz.signal.class.mq5 @@ -69,7 +69,9 @@ class XCX121SMCXWZSignalDetector : public XCBase XC121SMCCycleHelper *decisionCycleHelper, XC121SMCCycleHelper *analyseCycleHelper, XC121SMCCycleHelper *consolidationCycleHelper, - XC121SMCCycleHelper *visionCycleHelper + XC121SMCCycleHelper *visionCycleHelper, + // + double maxAllowedSLDistanceInPoint = 300 // ) { @@ -118,14 +120,6 @@ class XCX121SMCXWZSignalDetector : public XCBase datetime cTime = TimeCurrent(); double points = GetPoints(symbol); - // - double pivot = 0; - double point = 0; - double target = 0; - double reward = 0; - double amountPercent = 0; - ENUM_X121SMC_XWZ_PRIORITY priority = X121SMC_XWZ_PRIORITY_NONE; - // // Cycles Conditions ... @@ -312,9 +306,22 @@ class XCX121SMCXWZSignalDetector : public XCBase // // Setup Conditions ... + double sls[]; + double pivot = 0; + double point = 0; + double targets[]; + double reward = 0; XOBFVG selectedZone; + double amountPercent = 0; + bool hasPriority = false; + bool hasRewardAmount = false; bool hasSelectedZone = false; bool isSelectedZoneReversal = false; + bool hasSelectedConsolidationZone = false; + XConsolidationZone selectedConsolidationZone; + ENUM_X_DIRECTION selectedZoneDir = 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 ... @@ -328,7 +335,8 @@ class XCX121SMCXWZSignalDetector : public XCBase zIndex, visionState, consolidationState, - analyseState // + analyseState, + decisionState // ); } @@ -352,11 +360,17 @@ class XCX121SMCXWZSignalDetector : public XCBase zIndex, visionState, consolidationState, - analyseState // + analyseState, + decisionState // ); } // + bool hasWaitingZones = hasWorkingZone && + workingZone.HasWaitingZones(); + + // + // Check Conditions if Has Inside Zones ... bool hasInsideZones = hasWorkingZone && workingZone.HasInsideZones(); if (hasInsideZones) @@ -398,10 +412,12 @@ class XCX121SMCXWZSignalDetector : public XCBase // hasSelectedZone = selectedZone.IsValid(); + provider = X121SMC_XWZ_PROVIDER_PRICE_INSIDE_ZONE; } } // + // Check Conditions if Has Breaked Zones ... bool hasBreakedZones = hasWorkingZone && workingZone.HasBreakedZones(); if (hasBreakedZones) @@ -446,21 +462,164 @@ class XCX121SMCXWZSignalDetector : public XCBase // hasSelectedZone = selectedZone.IsValid(); + provider = X121SMC_XWZ_PROVIDER_ACTIVATED_ZONE; } } } // + // Double Check and Prepare Signal Conditions ... + // including Targets and SLs ... if (hasSelectedZone) { // - Print("Has Selected Zone ..."); + int idx = -1; + bool has = false; + + // + // Check Consolidation Zones for SL Handling ... + selectedZoneDir = + !isSelectedZoneReversal + ? selectedZone.GetDirection() + : Opposit(selectedZone.GetDirection()); + bool isSelectedZonDirBullish = IsBullish(selectedZoneDir); + + // + if (isSelectedZoneReversal) + { + provider = X121SMC_XWZ_PROVIDER_ACTIVATED_CHOCH; + } + + // + // Calculate Priority ... + hasPriority = + hasWorkingZone && + workingZone + .DetectPriority( + priority, + selectedZoneDir, + zIndex, + period // + ); + + // + // Calculate Risk Reward Ration based on Priority ... + hasRewardAmount = CalculateRiskReward( + priority, + reward, + amountPercent // + ); + + // + // Calculate Pivot and Point ... + + // + pivot = + isSelectedZonDirBullish + ? selectedZone.ob.Lower() + : selectedZone.ob.Upper(); + + // + point = + isSelectedZonDirBullish + ? selectedZone.ob.Upper() + : selectedZone.ob.Lower(); + + // + // Detect Targets ... + DetectSelectedZonesTargets( + targets, + selectedZone, + selectedZoneDir, + priority, + workingZone, + zIndex // + ); + + // + // Detect SLs ... + double iAtr = decisionXConditions.atrBuffer[0]; + iAtr *= 1.5; + + // + // Default SL is Pivot ... + if (pivot > 0) + { + // + Add( + pivot, + sls // + ); + + // + double iSL = iAtr * pivot; + Add( + iSL, + sls // + ); + } + + // + DetectSelectedZoneSLCandidates( + sls, + selectedZone, + selectedZoneDir, + workingZone, + zIndex, + maxAllowedSLDistanceInPoint // + ); + + // + // Summaries Conditions ... + result = + pivot > 0 && + point > 0 && + hasPriority && + hasRewardAmount && + HasDirection(selectedZoneDir); + if (result) + { + // + isBullish = IsBullish(selectedZoneDir); + isBearish = IsBearish(selectedZoneDir); + + // + Copy( + sls, + mConditions.sls // + ); + Copy( + targets, + mConditions.targets // + ); + + // + mConditions.pivot = pivot; + mConditions.point = point; + mConditions.reward = reward; + mConditions.setupTime = cTime; + mConditions.priority = priority; + mConditions.provider = provider; + mConditions.dir = selectedZoneDir; + mConditions.signalZone = selectedZone; + mConditions.amountPercent = amountPercent; + } + + // + // Cleanup Resources ... + + // + Clean(sls); + Clean(targets); + selectedZone.Clean(); + selectedConsolidationZone.Clean(); } // UpdateTo(cTime); // + // Draw Working Zone ... if (hasWorkingZone) { // @@ -478,9 +637,6 @@ class XCX121SMCXWZSignalDetector : public XCBase ); } - // - return false; - // // Cleanup Resources ... @@ -515,7 +671,6 @@ class XCX121SMCXWZSignalDetector : public XCBase consolidationXConditions.Clean(); // - // mConditions.Clean(); consolidationZBar.Clean(); // @@ -528,9 +683,6 @@ class XCX121SMCXWZSignalDetector : public XCBase // X121SMCStrategyXWZSignalConditions &conditions, // - string _symbol, - ENUM_TIMEFRAMES _period, - // XC121SMCCycleHelper *decisionCycleHelper, XC121SMCCycleHelper *analyseCycleHelper, XC121SMCCycleHelper *consolidationCycleHelper, @@ -587,9 +739,6 @@ class XCX121SMCXWZSignalDetector : public XCBase datetime cTime = TimeCurrent(); double points = GetPoints(symbol); - // - double sls[]; - // // Cycles Conditions ... @@ -662,95 +811,57 @@ class XCX121SMCXWZSignalDetector : public XCBase X121Conditions analyseXConditions = analyseConditions.x121Conditions; // - // Check Signal Validation ... + double iAtr = decisionXConditions.atrBuffer[1]; + iAtr *= 1.5; // - XOHCL cBar; - bool isInited = cBar.Init( - conditions.symbol, - conditions.period, - cIndex // - ); - XOHCL pBar; - isInited = - isInited && - cBar.GetPreviousBar(pBar); - bool isLowerBreaked = - // - isInited && - cBar.high < conditions.point && - pBar.high >= conditions.point - // - ; - bool isUpperBreaked = - // - isInited && - cBar.low > conditions.point && - pBar.low <= conditions.point - // - ; - bool isZoneBreaked = - (isBullish && - isLowerBreaked) || - (isBearish && - isUpperBreaked); - result = !isZoneBreaked; - if (!result) + // Check Signal Validation ... + // IMPORTANT: since all Validations done in SetUp Process ... + // here we only Execute Signal ... + + // + result = isBullish || + isBearish; + + // + if (result) { // - cBar.Clean(); - pBar.Clean(); - conditions.Clean(); + // Retrieve Entry Price ... + double entry = GetEntry( + conditions.symbol, + setupDir // + ); // - Clean(decisionPoiEvents); - Clean(decisionCycleEvents); + // Select and Apply SL ... // - decisionState.Clean(); - decisionConditions.Clean(); - decisionXConditions.Clean(); + double slsMin = GetMin(conditions.sls); + double slsMax = GetMax(conditions.sls); // - Clean(analysePoiEvents); - Clean(analyseCycleEvents); + double longSL = slsMin; + double shortSL = slsMax; + + // + double sl = isBullish + ? longSL + : shortSL; + + // + conditions.sl = sl; + conditions.triggerTime = cTime; + conditions.type = isBullish + ? X_POSITION_TYPE_LONG + : X_POSITION_TYPE_SHORT; // - analyseState.Clean(); - analyseConditions.Clean(); - analyseXConditions.Clean(); } - // - cBar.Clean(); - pBar.Clean(); - - // - double bullishScore = 0; - double bearishScore = 0; - decisionXConditions.GenerateScore( - bullishScore, - bearishScore // - ); - bool isBullishScorePassed = - isBullish && - bullishScore > (bearishScore * 1.5); - bool isBearishScorePassed = - isBearish && - bearishScore > (bullishScore * 1.5); - bool isScorePassed = isBullishScorePassed || - isBearishScorePassed; - - // - // Base SL Used Pivot of Conditions ... - // // Cleanup ... - // - cBar.Clean(); - pBar.Clean(); - // Clean(decisionPoiEvents); Clean(decisionCycleEvents); diff --git a/X121SMCEA/Signals/x-121.smc.xwz.signal.lib.mq5 b/X121SMCEA/Signals/x-121.smc.xwz.signal.lib.mq5 index ff20bd47..d3b8f2ae 100644 --- a/X121SMCEA/Signals/x-121.smc.xwz.signal.lib.mq5 +++ b/X121SMCEA/Signals/x-121.smc.xwz.signal.lib.mq5 @@ -73,6 +73,9 @@ struct X121SMCStrategyXWZWorkingZone XCSupportZone *supportZones[]; XCResistanceZone *resistanceZones[]; + // + XConsolidationZone consolidationZones[]; + // XOBFVG insideZones[]; XOBFVG breakedZones[]; @@ -160,7 +163,8 @@ struct X121SMCStrategyXWZWorkingZone int barIndex, XPOIState &htfState, XPOIState &mtfState, - XPOIState &stfState // + XPOIState &stfState, // + XPOIState &ttfState // ) { // @@ -181,10 +185,12 @@ struct X121SMCStrategyXWZWorkingZone htfState.IsValid() && mtfState.IsValid() && stfState.IsValid() && + ttfState.IsValid() && // htfState.HasChild() && mtfState.HasChild() && - stfState.HasChild() + stfState.HasChild() && + ttfState.HasChild() // ; if (!result) @@ -338,6 +344,21 @@ struct X121SMCStrategyXWZWorkingZone ); } + // + has = ttfState.HasConsolidationZones(); + if (has) + { + // + Copy( + ttfState.consolidationZones, + consolidationZones // + ); + CleanupArray( + consolidationZones, + 50 // + ); + } + // if (supplyZone != NULL && demandZone != NULL && @@ -381,7 +402,8 @@ struct X121SMCStrategyXWZWorkingZone int barIndex, XPOIState &htfState, XPOIState &mtfState, - XPOIState &stfState // + XPOIState &stfState, + XPOIState &ttfState // ) { // @@ -501,6 +523,52 @@ struct X121SMCStrategyXWZWorkingZone false // ); + // + // Support Zones ... + count = stfState.FilterSupportZones( + supportZones, + period, + XZONE_STATE_PASSED, + false, + XZONE_STATE_FAILED, + false, + XZONE_STATE_FAILED, + false, + XZONE_STATE_IGNORED, + false // + ); + + // + // Resistance Zones ... + count = stfState.FilterResistanceZones( + resistanceZones, + period, + XZONE_STATE_PASSED, + false, + XZONE_STATE_FAILED, + false, + XZONE_STATE_FAILED, + false, + XZONE_STATE_IGNORED, + false // + ); + + // + // Consolidation Zones ... + has = ttfState.HasConsolidationZones(); + if (has) + { + // + Copy( + ttfState.consolidationZones, + consolidationZones // + ); + CleanupArray( + consolidationZones, + 50 // + ); + } + // // // @@ -802,6 +870,18 @@ struct X121SMCStrategyXWZWorkingZone return ArraySize(breakedZones); } + // + bool HasConsolidationZones() + { + return HasChild(consolidationZones); + } + + // + int CountConsolidationZones() + { + return ArraySize(consolidationZones); + } + // // // @@ -1593,6 +1673,7 @@ struct X121SMCStrategyXWZSignalConditions // double pivot; double point; + double sls[]; double targets[]; // @@ -1727,6 +1808,7 @@ struct X121SMCStrategyXWZSignalConditions amountPercent = 0; // + Clean(sls); Clean(targets); signalZone.Clean(); @@ -1805,6 +1887,16 @@ bool CheckOBFVGXWZConditions( bearishScore // ); + // + bool isBullishScorePassed = bullishScore > 0 && + bearishScore >= 0 && + bullishScore > bearishScore; + + // + bool isBearishScorePassed = bearishScore > 0 && + bullishScore >= 0 && + bearishScore > bullishScore; + // // VWap ... @@ -1930,9 +2022,7 @@ bool CheckOBFVGXWZConditions( isBullish && isBullishTrend && isVWap3MaBullish && - bullishScore > 0 && - bearishScore >= 0 && - bullishScore > bearishScore + isBullishScorePassed // ; @@ -1943,22 +2033,1209 @@ bool CheckOBFVGXWZConditions( isBearish && isBearishTrend && isVWap3MaBearish && - bearishScore > 0 && - bullishScore >= 0 && - bearishScore > bullishScore + isBearishScorePassed // ; // - if (isInside) - { + bool isDirectionalPassed = + isDirectionalBullishPassed || + isDirectionalBearishPassed; + + // + bool isReversalBullishPassed = // - Print("X3MA VWAP Inside ..."); + isInside && + isBullish && + isBearishTrend && + isVWap3MaBearish && + isBearishScorePassed + // + ; + + // + bool isReversalBearishPassed = + // + isInside && + isBearish && + isBullishTrend && + isVWap3MaBullish && + isBullishScorePassed + // + ; + + // + bool isReversalPassed = isReversalBullishPassed || + isReversalBearishPassed; + + // + result = isReversalPassed || + isDirectionalPassed; + + // + if (result) + { + isReversal = isReversalPassed; } // - result = isDirectionalBullishPassed || - isDirectionalBearishPassed; + return result; +} + +/** + * Detect Targets Based on Selected Zone for Specified type of Directions ... + * + * @param targets: double Collection ... + * @param selectedZone: XOBFVG instance, selected Zone ... + * @param forDir: ENUM_X_DIRECTION specified Position Direction ... + * @param workingone: X121SMCStrategyXWZWorkingZone instance, Specified Working Zone ... + * @param barIndex: int Specified Bar Index ... + * + * @return ( bool ) + */ +bool DetectSelectedZonesTargets( + double &targets[], + XOBFVG &selectedZone, + ENUM_X_DIRECTION forDir, + ENUM_X121SMC_XWZ_PRIORITY forPriority, + X121SMCStrategyXWZWorkingZone &workingZone, + int barIndex = 0 // +) +{ + // + bool result = false; + + // + Clean(targets); + + // + if (barIndex < 0) + { + barIndex = 0; + } + + // + if (barIndex == 0) + { + barIndex++; + } + + // + result = + // + selectedZone.IsValid() && + HasDirection(forDir) && + workingZone.IsValid() && + forPriority != X121SMC_XWZ_PRIORITY_NONE + // + ; + if (!result) + { + return result; + } + + // + bool isBullish = IsBullish(forDir); + + // + XOHCL cBar; + result = cBar.Init( + workingZone.symbol, + workingZone.period, + barIndex // + ); + if (!result) + { + // + cBar.Clean(); + return result; + } + + // + int idx = -1; + bool has = false; + XOBFVG tmpZones[]; + + // + // Based On Waiting Zones ... + has = workingZone.HasWaitingZones(); + if (has) + { + // + Copy( + workingZone.waitingZones, + tmpZones // + ); + + // + while (HasChild(tmpZones)) + { + // + XOBFVG iOBFVG; + + // + idx = GetYoungest(tmpZones); + if (!IsValidIndex(idx)) + { + // + iOBFVG.Clean(); + break; + } + + // + iOBFVG = tmpZones[idx]; + ArrayRemove( + tmpZones, + idx, + 1 // + ); + + // + double iTarget = + isBullish + ? iOBFVG.ob.Lower() + : iOBFVG.ob.Upper(); + + // + has = + isBullish + ? cBar.high < iTarget + : cBar.low > iTarget; + + // + if (has) + { + // + Add( + iTarget, + targets // + ); + } + + // + iOBFVG.Clean(); + } + + // + Clean(tmpZones); + } + + // + // Based On Breaked Zones ... + has = workingZone.HasBreakedZones(); + if (has) + { + Copy( + workingZone.breakedZones, + tmpZones // + ); + + // + while (HasChild(tmpZones)) + { + // + XOBFVG iOBFVG; + + // + idx = GetYoungest(tmpZones); + if (!IsValidIndex(idx)) + { + // + iOBFVG.Clean(); + break; + } + + // + iOBFVG = tmpZones[idx]; + ArrayRemove( + tmpZones, + idx, + 1 // + ); + + // + double iTarget = + isBullish + ? iOBFVG.ob.Lower() + : iOBFVG.ob.Upper(); + + // + has = + isBullish + ? cBar.high < iTarget + : cBar.low > iTarget; + + // + if (has) + { + // + Add( + iTarget, + targets // + ); + } + + // + iOBFVG.Clean(); + } + + // + Clean(tmpZones); + } + + // + // Based On Priority ... + has = forPriority != X121SMC_XWZ_PRIORITY_NONE; + if (has) + { + // + switch (forPriority) + { + // + 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; + } + } + + // + result = HasChild(targets); + + // + // Cleanup ... + cBar.Clean(); + Clean(tmpZones); + + // + return result; +} + +/** + * Detect SL Candidates Based on Selected Zone for Specified type of Directions ... + * + * @param sls: double Collection ... + * @param selectedZone: XOBFVG instance, selected Zone ... + * @param forDir: ENUM_X_DIRECTION specified Position Direction ... + * @param workingZone: X121SMCStrategyXWZWorkingZone instance, Specified Working Zone ... + * @param barIndex: int Specified Bar Index ... + * @param maxAllowedSLDistanceInPoint: doube max Allowe SL distance ... + * + * @return ( bool ) + */ +bool DetectSelectedZoneSLCandidates( + double &sls[], + XOBFVG &selectedZone, + ENUM_X_DIRECTION forDir, + X121SMCStrategyXWZWorkingZone &workingZone, + int barIndex = 0, + double maxAllowedSLDistanceInPoint = 300 // +) +{ + // + bool result = false; + + // + Clean(sls); + + // + if (barIndex < 0) + { + barIndex = 0; + } + + // + if (barIndex == 0) + { + barIndex++; + } + + // + result = + // + selectedZone.IsValid() && + HasDirection(forDir) && + workingZone.IsValid() + // + ; + if (!result) + { + return result; + } + + // + bool isBullish = IsBullish(forDir); + + // + double pivot = + isBullish + ? selectedZone.ob.Lower() + : selectedZone.ob.Upper(); + double points = GetPoints(workingZone.symbol); + + // + XOHCL cBar; + result = cBar.Init( + workingZone.symbol, + workingZone.period, + barIndex // + ); + if (!result) + { + // + cBar.Clean(); + return result; + } + + // + int idx = -1; + bool has = false; + + // + // Based On Passed Bars ... + XOHCL passedBar; + bool isPassed = false; + bool isBodyState = false; + ENUM_X_DIRECTION passedDir = selectedZone.GetDirection(); + + // + // Started Bar ... + isPassed = selectedZone.ob.IsStarted( + passedDir, + passedBar, + isBodyState // + ); + if (isPassed) + { + // + double iSL = + isBullish + ? passedBar.low + : passedBar.high; + double iSLDiff = MathAbs(iSL - pivot); + has = + iSLDiff > 0 && + iSLDiff <= maxAllowedSLDistanceInPoint * points; + if (has) + { + // + Add( + iSL, + sls // + ); + } + } + + // + // Activation Bar ... + passedBar.Clean(); + isPassed = selectedZone.ob.IsActivated( + passedDir, + passedBar, + isBodyState // + ); + if (isPassed) + { + // + double iSL = + isBullish + ? passedBar.low + : passedBar.high; + double iSLDiff = MathAbs(iSL - pivot); + has = + iSLDiff > 0 && + iSLDiff <= maxAllowedSLDistanceInPoint * points; + if (has) + { + // + Add( + iSL, + sls // + ); + } + } + + // + // Worked Bar ... + passedBar.Clean(); + isPassed = selectedZone.ob.IsActivated( + passedDir, + passedBar, + isBodyState // + ); + if (isPassed) + { + // + double iSL = + isBullish + ? passedBar.low + : passedBar.high; + double iSLDiff = MathAbs(iSL - pivot); + has = + iSLDiff > 0 && + iSLDiff <= maxAllowedSLDistanceInPoint * points; + if (has) + { + // + Add( + iSL, + sls // + ); + } + } + + // + // Breaked Bar ... + passedBar.Clean(); + isPassed = selectedZone.ob.IsActivated( + passedDir, + passedBar, + isBodyState // + ); + if (isPassed) + { + // + double iSL = + isBullish + ? passedBar.low + : passedBar.high; + double iSLDiff = MathAbs(iSL - pivot); + has = + iSLDiff > 0 && + iSLDiff <= maxAllowedSLDistanceInPoint * points; + if (has) + { + // + Add( + iSL, + sls // + ); + } + } + + // + // Based On Consolidation Zones ... + has = workingZone.HasConsolidationZones(); + if (has) + { + // + XConsolidationZone tmpZones[]; + Copy( + workingZone.consolidationZones, + tmpZones // + ); + XConsolidationZone selectedConsolidationZone; + + // + while (HasChild(tmpZones)) + { + // + idx = GetYoungest(tmpZones); + if (!IsValidIndex(idx)) + { + break; + } + + // + XConsolidationZone iZone = tmpZones[idx]; + + // + ArrayRemove( + tmpZones, + idx, + 1 // + ); + + // + has = + !selectedConsolidationZone.IsValid() + ? isBullish + ? cBar.low < iZone.upper + : cBar.high < iZone.lower + : isBullish + ? selectedConsolidationZone.lower < iZone.lower + : selectedConsolidationZone.upper > iZone.upper; + if (has) + { + // + selectedConsolidationZone = iZone; + iZone.Clean(); + break; + } + + // + iZone.Clean(); + } + + // + Clean(tmpZones); + has = selectedConsolidationZone.IsValid(); + if (has) + { + // + double iSL = + isBullish + ? selectedConsolidationZone.lower + : selectedConsolidationZone.upper; + double iSLDiff = MathAbs(iSL - pivot); + has = + iSLDiff > 0 && + iSLDiff <= maxAllowedSLDistanceInPoint * points; + if (has) + { + // + Add( + iSL, + sls // + ); + } + } + } + + // + // Based On Supply and Demand Zones ... + + // + // Demand Zones ... + has = workingZone.HasDemandZones(); + if (has) + { + // + XCDemandZone *tmpZones[]; + Copy( + workingZone.demandZones, + tmpZones // + ); + XCDemandZone *selectedDemand = NULL; + + // + while (HasChild(tmpZones)) + { + // + idx = GetLowest(tmpZones); + has = IsValidIndex(idx); + if (!has) + { + break; + } + + // + XCDemandZone *iZone = tmpZones[idx]; + ArrayRemove( + tmpZones, + idx, + 1 // + ); + + // + // Validate Zone ... + has = + isBullish + ? IsBelowDiff( + iZone, + selectedZone.ob, + true // Ignore Inside ... + ) + : IsAboveDiff( + iZone, + selectedZone.ob, + true // Ignore Inside ... + ); + if (!has) + { + continue; + } + + // + has = + selectedDemand == NULL + ? true + : isBullish + ? selectedDemand.Lower() < iZone.Lower() + : selectedDemand.Upper() > iZone.Upper(); + if (!has) + { + continue; + } + + // + selectedDemand = iZone; + } + + // + has = selectedDemand != NULL; + if (has) + { + // + double iSL = + isBullish + ? selectedDemand.Lower() + : selectedDemand.Upper(); + double iSLDiff = MathAbs(iSL - pivot); + has = + iSLDiff > 0 && + iSLDiff <= maxAllowedSLDistanceInPoint * points; + if (has) + { + // + Add( + iSL, + sls // + ); + } + } + + // + Clean(tmpZones); + ZeroMemory(selectedDemand); + } + + // + // Support Zones ... + has = workingZone.HasSupportZones(); + if (has) + { + // + XCSupportZone *tmpZones[]; + Copy( + workingZone.supportZones, + tmpZones // + ); + XCSupportZone *selectedSupport = NULL; + + // + while (HasChild(tmpZones)) + { + // + idx = GetLowest(tmpZones); + has = IsValidIndex(idx); + if (!has) + { + break; + } + + // + XCSupportZone *iZone = tmpZones[idx]; + ArrayRemove( + tmpZones, + idx, + 1 // + ); + + // + // Validate Zone ... + has = + isBullish + ? IsBelowDiff( + iZone, + selectedZone.ob, + true // Ignore Inside ... + ) + : IsAboveDiff( + iZone, + selectedZone.ob, + true // Ignore Inside ... + ); + if (!has) + { + continue; + } + + // + has = + selectedSupport == NULL + ? true + : isBullish + ? selectedSupport.Lower() < iZone.Lower() + : selectedSupport.Upper() > iZone.Upper(); + if (!has) + { + continue; + } + + // + selectedSupport = iZone; + + // + } + + // + has = selectedSupport != NULL; + if (has) + { + // + double iSL = isBullish + ? selectedSupport.Lower() + : selectedSupport.Upper(); + double iSLDiff = MathAbs(iSL - pivot); + has = + iSLDiff > 0 && + iSLDiff <= maxAllowedSLDistanceInPoint * points; + if (has) + { + // + Add( + iSL, + sls // + ); + } + } + + // + Clean(tmpZones); + ZeroMemory(selectedSupport); + } + + // + // Supply Zones ... + has = workingZone.HasSupplyZones(); + if (has) + { + // + XCSupplyZone *tmpZones[]; + Copy( + workingZone.supplyZones, + tmpZones // + ); + XCSupplyZone *selectedSupply = NULL; + + // + while (HasChild(tmpZones)) + { + // + idx = GetHighest(tmpZones); + has = IsValidIndex(idx); + if (!has) + { + break; + } + + // + XCSupplyZone *iZone = tmpZones[idx]; + ArrayRemove( + tmpZones, + idx, + 1 // + ); + + // + // Validate Zone ... + has = + !isBullish + ? IsAboveDiff( + iZone, + selectedZone.ob, + true // Ignore Inside ... + ) + : IsBelowDiff( + iZone, + selectedZone.ob, + true // Ignore Inside ... + ); + if (!has) + { + continue; + } + + // + has = + selectedSupply == NULL + ? true + : !isBullish + ? selectedSupply.Upper() > iZone.Upper() + : selectedSupply.Lower() < iZone.Lower(); + if (!has) + { + continue; + } + + // + selectedSupply = iZone; + + // + } + + // + has = selectedSupply != NULL; + if (has) + { + // + double iSL = + !isBullish + ? selectedSupply.Upper() + : selectedSupply.Lower(); + double iSLDiff = MathAbs(iSL - pivot); + has = + iSLDiff > 0 && + iSLDiff <= maxAllowedSLDistanceInPoint * points; + if (has) + { + // + Add( + iSL, + sls // + ); + } + } + + // + Clean(tmpZones); + ZeroMemory(selectedSupply); + } + + // + // Resistance Zones ... + has = workingZone.HasDemandZones(); + if (has) + { + // + XCResistanceZone *tmpZones[]; + Copy( + workingZone.resistanceZones, + tmpZones // + ); + XCResistanceZone *selectedResistance = NULL; + + // + while (HasChild(tmpZones)) + { + // + idx = GetHighest(tmpZones); + has = IsValidIndex(idx); + if (!has) + { + break; + } + + // + XCResistanceZone *iZone = tmpZones[idx]; + ArrayRemove( + tmpZones, + idx, + 1 // + ); + + // + // Validate Zone ... + has = + !isBullish + ? IsAboveDiff( + iZone, + selectedZone.ob, + true // Ignore Inside ... + ) + : IsBelowDiff( + iZone, + selectedZone.ob, + true // Ignore Inside ... + ); + if (!has) + { + continue; + } + + // + has = + selectedResistance == NULL + ? true + : !isBullish + ? selectedResistance.Upper() < iZone.Upper() + : selectedResistance.Lower() > iZone.Lower(); + if (!has) + { + continue; + } + + // + selectedResistance = iZone; + + // + } + + // + has = selectedResistance != NULL; + if (has) + { + // + double iSL = + !isBullish + ? selectedResistance.Upper() + : selectedResistance.Lower(); + double iSLDiff = MathAbs(iSL - pivot); + has = + iSLDiff > 0 && + iSLDiff <= maxAllowedSLDistanceInPoint * points; + if (has) + { + // + Add( + iSL, + sls // + ); + } + } + + // + Clean(tmpZones); + ZeroMemory(selectedResistance); + } + + // + // Cleanp Resources ... + + // + cBar.Clean(); + passedBar.Clean(); + result = HasChild(sls); // return result; diff --git a/X121SMCEA/Strategy/x-121.smc.strategy.class.mq5 b/X121SMCEA/Strategy/x-121.smc.strategy.class.mq5 index 22550f84..6d40147c 100644 --- a/X121SMCEA/Strategy/x-121.smc.strategy.class.mq5 +++ b/X121SMCEA/Strategy/x-121.smc.strategy.class.mq5 @@ -592,8 +592,6 @@ class XCX121SMCStrategy : public XCX121SMCBaseStrategy canTrigger = mXWZSignalDetector .DetectSignalTrigger( mTmpConditions[i], - symbol, - period, mDecisionCycleHelper, mAnalyseCycleHelper, mConsolidationCycleHelper,