diff --git a/Documents/BKP/1.mq5 b/Documents/BKP/1.mq5 index 1ad0bffc..90eefe41 100644 --- a/Documents/BKP/1.mq5 +++ b/Documents/BKP/1.mq5 @@ -245,1047 +245,1185 @@ if (hasSelectedConsolidationZone) ); } - ///////////////////////////////////////////////////////////////////////////////////// +// // +// // Based On Waiting Zones ... +// has = isBarInited && +// hasWorkingZone; +// if (has) +// { +// // +// XOBFVG tmpZones[]; +// Copy( +// workingZone.waitingZones, +// tmpZones // +// ); - // // - // // Based On Waiting Zones ... - // has = isBarInited && - // hasWorkingZone; - // if (has) - // { - // // - // XOBFVG tmpZones[]; - // Copy( - // workingZone.waitingZones, - // tmpZones // - // ); +// // +// while (HasChild(tmpZones)) +// { +// // +// XOBFVG iOBFVG; - // // - // while (HasChild(tmpZones)) - // { - // // - // XOBFVG iOBFVG; +// // +// idx = GetYoungest(tmpZones); +// if (!IsValidIndex(idx)) +// { +// // +// iOBFVG.Clean(); +// break; +// } - // // - // idx = GetYoungest(tmpZones); - // if (!IsValidIndex(idx)) - // { - // // - // iOBFVG.Clean(); - // break; - // } +// // +// iOBFVG = tmpZones[idx]; +// ArrayRemove( +// tmpZones, +// idx, +// 1 // +// ); - // // - // iOBFVG = tmpZones[idx]; - // ArrayRemove( - // tmpZones, - // idx, - // 1 // - // ); +// // +// double iTarget = +// isSelectedZonDirBullish +// ? iOBFVG.ob.Lower() +// : iOBFVG.ob.Upper(); - // // - // double iTarget = - // isSelectedZonDirBullish - // ? iOBFVG.ob.Lower() - // : iOBFVG.ob.Upper(); +// // +// has = +// isSelectedZonDirBullish +// ? cBar.high < iTarget +// : cBar.low > iTarget; - // // - // has = - // isSelectedZonDirBullish - // ? cBar.high < iTarget - // : cBar.low > iTarget; +// // +// if (has) +// { +// // +// Add( +// iTarget, +// targets // +// ); +// } - // // - // if (has) - // { - // // - // Add( - // iTarget, - // targets // - // ); - // } +// // +// iOBFVG.Clean(); +// } - // // - // iOBFVG.Clean(); - // } +// // +// Clean(tmpZones); +// } - // // - // Clean(tmpZones); - // } +// // +// // Based On Breaked Zones ... +// has = isBarInited && +// hasBreakedZones; +// if (has) +// { +// // +// XOBFVG tmpZones[]; +// Copy( +// workingZone.breakedZones, +// tmpZones // +// ); - // // - // // Based On Breaked Zones ... - // has = isBarInited && - // hasBreakedZones; - // if (has) - // { - // // - // XOBFVG tmpZones[]; - // Copy( - // workingZone.breakedZones, - // tmpZones // - // ); +// // +// while (HasChild(tmpZones)) +// { +// // +// XOBFVG iOBFVG; - // // - // while (HasChild(tmpZones)) - // { - // // - // XOBFVG iOBFVG; +// // +// idx = GetYoungest(tmpZones); +// if (!IsValidIndex(idx)) +// { +// // +// iOBFVG.Clean(); +// break; +// } - // // - // idx = GetYoungest(tmpZones); - // if (!IsValidIndex(idx)) - // { - // // - // iOBFVG.Clean(); - // break; - // } +// // +// iOBFVG = tmpZones[idx]; +// ArrayRemove( +// tmpZones, +// idx, +// 1 // +// ); - // // - // iOBFVG = tmpZones[idx]; - // ArrayRemove( - // tmpZones, - // idx, - // 1 // - // ); +// // +// double iTarget = +// isSelectedZonDirBullish +// ? iOBFVG.ob.Lower() +// : iOBFVG.ob.Upper(); - // // - // double iTarget = - // isSelectedZonDirBullish - // ? iOBFVG.ob.Lower() - // : iOBFVG.ob.Upper(); +// // +// has = +// isSelectedZonDirBullish +// ? cBar.high < iTarget +// : cBar.low > iTarget; - // // - // has = - // isSelectedZonDirBullish - // ? cBar.high < iTarget - // : cBar.low > iTarget; +// // +// if (has) +// { +// // +// Add( +// iTarget, +// targets // +// ); +// } - // // - // if (has) - // { - // // - // Add( - // iTarget, - // targets // - // ); - // } +// // +// iOBFVG.Clean(); +// } - // // - // iOBFVG.Clean(); - // } +// // +// Clean(tmpZones); +// } - // // - // Clean(tmpZones); - // } +// // +// // 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; - // // - // // 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; +// // +// case X121SMC_XWZ_PRIORITY_LOW: +// // +// if (isSelectedZonDirBullish) +// { +// // +// // Weak ... +// Add( +// workingZone.supplyZone.Lower(), +// targets // +// ); - // // - // case X121SMC_XWZ_PRIORITY_LOW: - // // - // if (isSelectedZonDirBullish) - // { - // // - // // Weak ... - // Add( - // workingZone.supplyZone.Lower(), - // targets // - // ); +// // +// // Low ... +// Add( +// workingZone.quarter1, +// targets // +// ); +// } +// else +// { +// // +// // Weak ... +// Add( +// workingZone.demandZone.Upper(), +// targets // +// ); - // // - // // Low ... - // Add( - // workingZone.quarter1, - // targets // - // ); - // } - // else - // { - // // - // // Weak ... - // Add( - // workingZone.demandZone.Upper(), - // targets // - // ); +// // +// // Low ... +// Add( +// workingZone.quarter3, +// targets // +// ); +// } +// break; - // // - // // Low ... - // Add( - // workingZone.quarter3, - // targets // - // ); - // } - // break; +// // +// case X121SMC_XWZ_PRIORITY_REGULAR: +// // +// if (isSelectedZonDirBullish) +// { +// // +// // Weak ... +// Add( +// workingZone.supplyZone.Lower(), +// targets // +// ); - // // - // case X121SMC_XWZ_PRIORITY_REGULAR: - // // - // if (isSelectedZonDirBullish) - // { - // // - // // Weak ... - // Add( - // workingZone.supplyZone.Lower(), - // targets // - // ); +// // +// // Low ... +// Add( +// workingZone.quarter1, +// targets // +// ); - // // - // // Low ... - // Add( - // workingZone.quarter1, - // targets // - // ); +// // +// // Regular ... +// Add( +// workingZone.quarter2, +// targets // +// ); +// } +// else +// { +// // +// // Weak ... +// Add( +// workingZone.demandZone.Upper(), +// targets // +// ); - // // - // // Regular ... - // Add( - // workingZone.quarter2, - // targets // - // ); - // } - // else - // { - // // - // // Weak ... - // Add( - // workingZone.demandZone.Upper(), - // targets // - // ); +// // +// // Low ... +// Add( +// workingZone.quarter3, +// targets // +// ); - // // - // // Low ... - // Add( - // workingZone.quarter3, - // targets // - // ); +// // +// // Regular ... +// Add( +// workingZone.quarter2, +// targets // +// ); +// } +// break; - // // - // // Regular ... - // Add( - // workingZone.quarter2, - // targets // - // ); - // } - // break; +// // +// case X121SMC_XWZ_PRIORITY_HIGH: +// // +// if (isSelectedZonDirBullish) +// { +// // +// // Weak ... +// Add( +// workingZone.supplyZone.Lower(), +// targets // +// ); - // // - // case X121SMC_XWZ_PRIORITY_HIGH: - // // - // if (isSelectedZonDirBullish) - // { - // // - // // Weak ... - // Add( - // workingZone.supplyZone.Lower(), - // targets // - // ); +// // +// // Low ... +// Add( +// workingZone.quarter1, +// targets // +// ); - // // - // // Low ... - // Add( - // workingZone.quarter1, - // targets // - // ); +// // +// // Regular ... +// Add( +// workingZone.quarter2, +// targets // +// ); - // // - // // Regular ... - // Add( - // workingZone.quarter2, - // targets // - // ); +// // +// // High ... +// Add( +// workingZone.quarter3, +// targets // +// ); +// } +// else +// { +// // +// // Weak ... +// Add( +// workingZone.demandZone.Upper(), +// targets // +// ); - // // - // // High ... - // Add( - // workingZone.quarter3, - // targets // - // ); - // } - // else - // { - // // - // // Weak ... - // Add( - // workingZone.demandZone.Upper(), - // targets // - // ); +// // +// // Low ... +// Add( +// workingZone.quarter3, +// targets // +// ); - // // - // // Low ... - // Add( - // workingZone.quarter3, - // targets // - // ); +// // +// // Regular ... +// Add( +// workingZone.quarter2, +// targets // +// ); - // // - // // Regular ... - // Add( - // workingZone.quarter2, - // targets // - // ); +// // +// // High ... +// Add( +// workingZone.quarter1, +// targets // +// ); +// } +// break; - // // - // // High ... - // Add( - // workingZone.quarter1, - // targets // - // ); - // } - // break; +// // +// case X121SMC_XWZ_PRIORITY_STRONG_HIGH: +// // +// if (isSelectedZonDirBullish) +// { +// // +// // Weak ... +// Add( +// workingZone.supplyZone.Lower(), +// targets // +// ); - // // - // case X121SMC_XWZ_PRIORITY_STRONG_HIGH: - // // - // if (isSelectedZonDirBullish) - // { - // // - // // Weak ... - // Add( - // workingZone.supplyZone.Lower(), - // targets // - // ); +// // +// // Low ... +// Add( +// workingZone.quarter1, +// targets // +// ); - // // - // // Low ... - // Add( - // workingZone.quarter1, - // targets // - // ); +// // +// // Regular ... +// Add( +// workingZone.quarter2, +// targets // +// ); - // // - // // Regular ... - // Add( - // workingZone.quarter2, - // targets // - // ); +// // +// // High ... +// Add( +// workingZone.quarter3, +// targets // +// ); - // // - // // High ... - // Add( - // workingZone.quarter3, - // targets // - // ); +// // +// // Strong High ... +// Add( +// workingZone.demandZone.Upper(), +// targets // +// ); +// } +// else +// { +// // +// // Weak ... +// Add( +// workingZone.demandZone.Upper(), +// targets // +// ); - // // - // // Strong High ... - // Add( - // workingZone.demandZone.Upper(), - // targets // - // ); - // } - // else - // { - // // - // // Weak ... - // Add( - // workingZone.demandZone.Upper(), - // targets // - // ); +// // +// // Low ... +// Add( +// workingZone.quarter3, +// targets // +// ); - // // - // // Low ... - // Add( - // workingZone.quarter3, - // targets // - // ); +// // +// // Regular ... +// Add( +// workingZone.quarter2, +// targets // +// ); - // // - // // Regular ... - // Add( - // workingZone.quarter2, - // targets // - // ); - - // // - // // High ... - // Add( - // workingZone.quarter1, - // targets // - // ); - - // // - // // Strong High ... - // Add( - // workingZone.supplyZone.Lower(), - // targets // - // ); - // } - // break; - // } - // } +// // +// // High ... +// Add( +// workingZone.quarter1, +// targets // +// ); +// // +// // Strong High ... +// Add( +// workingZone.supplyZone.Lower(), +// targets // +// ); +// } +// break; +// } +// } //////////////////////////////////////////////////////////////////// +// +// 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) + { // - // Based On Consolidation Zones ... - has = isBarInited && - decisionState.HasConsolidationZones(); - if (has) - { - // - XConsolidationZone tmpZones[]; - if (isSelectedZonDirBullish) - { - // - Copy( - decisionState.bullishConsolidationZones, - tmpZones // - ); - } - else - { - // - Copy( - decisionState.bearishConsolidationZones, - tmpZones // - ); - } + selectedConsolidationZone = iZone; + iZone.Clean(); + break; + } - // - while (HasChild(tmpZones)) - { - // - idx = GetYoungest(tmpZones); - if (!IsValidIndex(idx)) - { - break; - } + // + iZone.Clean(); + } - // - XConsolidationZone iZone = tmpZones[idx]; + // + Clean(tmpZones); - // - 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 // - ); - } - } - } + // + 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) + { // - // 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 // + Add( + iSL, + sls // ); - 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 // - ); - } - } + } + } +} +// +// 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) + { // - // Activation Bar ... - passedBar.Clean(); - isPassed = selectedZone.ob.IsActivated( - passedDir, - passedBar, - isBodyState // + Add( + iSL, + sls // ); - 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 // - ); - } - } + } + } + // + 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) + { // - // Worked Bar ... - passedBar.Clean(); - isPassed = selectedZone.ob.IsActivated( - passedDir, - passedBar, - isBodyState // + Add( + iSL, + sls // ); - 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 // - ); - } - } + } + } + // + 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) + { // - // Breaked Bar ... - passedBar.Clean(); - isPassed = selectedZone.ob.IsActivated( - passedDir, - passedBar, - isBodyState // + Add( + iSL, + sls // ); - 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 + // + 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 // + ); + } +} + +//////////////////////////////////////////////////////////////////// + +// // +// // Trail Stops Using Swings ... + +// // +// bool canTrailLongUsingSwings = +// // +// isLong && +// isInProfit && +// (isSwingLow || +// isStrongSwingLow) && +// pBar.low > iPosition.sl && +// pBar.low > iPosition.entry +// // +// ; +// if (canTrailLongUsingSwings) +// { +// sl = pBar.low; +// } + +// // +// bool canTraiShortlUsingSwings = +// // +// !isLong && +// isInProfit && +// (isSwingHigh || +// isStrongSwingHigh) && +// pBar.high < iPosition.sl && +// pBar.high < iPosition.entry +// // +// ; +// if (canTraiShortlUsingSwings) +// { +// sl = pBar.high; +// } + +// // +// bool canTrailUsingSwings = +// canTrailLongUsingSwings || +// canTraiShortlUsingSwings; + +// // +// // +// // + +//////////////////////////////////////////////////////////////////////////// + + + // // + // XOHCL zBar; + // result = zBar.Init( + // symbol, + // period, + // zIndex // + // ); + // if (!result) + // { + // // + // result = HasChild(guards); + // return result; + // } + + // // + // XOHCL cBar; + // result = cBar.Init( + // symbol, + // period, + // cIndex // + // ); + // if (!result) + // { + // // + // zBar.Clean(); + // result = HasChild(guards); + // return result; + // } + + // // + // XOHCL pBar; + // result = pBar.Init( + // symbol, + // period, + // pIndex // + // ); + // if (!result) + // { + // // + // zBar.Clean(); + // cBar.Clean(); + // result = HasChild(guards); + // return result; + // } + + // // + // XOHCL ppBar; + // result = ppBar.Init( + // symbol, + // period, + // ppIndex // + // ); + // if (!result) + // { + // // + // zBar.Clean(); + // cBar.Clean(); + // pBar.Clean(); + // result = HasChild(guards); + // return result; + // } + + // + // zBar.Clean(); + // cBar.Clean(); + // pBar.Clean(); + // ppBar.Clean(); + + + // + // Detect High Probability Swings ... + // bool isSwingLow = + // // + // cBar.low > pBar.low && + // ppBar.low > pBar.low && + // // + // zBar.low > pBar.low + // // + // ; + // bool isSwingHigh = + // // + // cBar.high < pBar.high && + // ppBar.high < pBar.high && + // // + // zBar.high < pBar.high + // // + // ; + // bool isStrongSwingLow = + // pBar.IsBullish() && + // pBar.GetLowShadow() >= pBar.GetBody() * 2; + // bool isStrongSwingHigh = + // pBar.IsBearish() && + // pBar.GetHighShadow() >= pBar.GetBody() * 2; diff --git a/X121SMCEA/Signals/x-121.smc.xwz.signal.class.mq5 b/X121SMCEA/Signals/x-121.smc.xwz.signal.class.mq5 index b38aaf96..20c5ba49 100644 --- a/X121SMCEA/Signals/x-121.smc.xwz.signal.class.mq5 +++ b/X121SMCEA/Signals/x-121.smc.xwz.signal.class.mq5 @@ -381,7 +381,7 @@ class XCX121SMCXWZSignalDetector : public XCBase for (int i = 0; i < count; i++) { // - bool has = CheckOBFVGXWZConditions( + bool has = DetectSelectedZoneConditions( isSelectedZoneReversal, workingZone.insideZones[i], decisionState, @@ -431,7 +431,7 @@ class XCX121SMCXWZSignalDetector : public XCBase for (int i = 0; i < count; i++) { // - bool has = CheckOBFVGXWZConditions( + bool has = DetectSelectedZoneConditions( isSelectedZoneReversal, workingZone.breakedZones[i], decisionState, @@ -467,6 +467,29 @@ class XCX121SMCXWZSignalDetector : public XCBase } } + // + // Checking Other Senario for Signals ... + // if (!hasWaitingZones && + // !hasSelectedZone) + // { + // // + // bool has = false; + // ENUM_X_DIRECTION dir; + + // // + // has = DetectX121Conditions( + // pivot, + // point, + // sls, + // targets, + // dir, + // analyseState, + // decisionState, + // decisionXConditions, + // drawer // + // ); + // } + // // Double Check and Prepare Signal Conditions ... // including Targets and SLs ... @@ -628,12 +651,12 @@ class XCX121SMCXWZSignalDetector : public XCBase true, // Draw Waiting Zones .. true, // Draw Inside Zones .. true, // Draw Breaked Zones .. - false, // Draw Supply Zone .. - false, // Draw Demand Zone .. - false, // Draw Supply Zones .. - false, // Draw Demand Zones .. - false, // Draw Support Zones .. - false // Draw Resistance Zones .. + true, // Draw Supply Zone .. + true, // Draw Demand Zone .. + true, // Draw Supply Zones .. + true, // Draw Demand Zones .. + true, // Draw Support Zones .. + true // Draw Resistance Zones .. ); } @@ -915,9 +938,11 @@ class XCX121SMCXWZSignalDetector : public XCBase ; // - return false; + // Set Provider for Common Guards ... + string provider = ToString(X_121_SMC_PROVIDER_XWZ); // + // Check Cycle Helpers Validation ... result = isCycleHelpersValid; if (!result) { @@ -925,6 +950,7 @@ class XCX121SMCXWZSignalDetector : public XCBase } // + // Select Own Positions ... int count = ArraySize(positions); result = IsValidSize(count); if (!result) @@ -932,9 +958,6 @@ class XCX121SMCXWZSignalDetector : public XCBase return result; } - // - string provider = ToString(X_121_SMC_PROVIDER_XWZ); - // XPosition ownPositions[]; XPosition ownLongPositions[]; @@ -980,6 +1003,9 @@ class XCX121SMCXWZSignalDetector : public XCBase } } + // + // Check Extracted Positions ... + // count = ArraySize(ownPositions); @@ -992,6 +1018,7 @@ class XCX121SMCXWZSignalDetector : public XCBase bool hasShorts = IsValidSize(shortsCount); // + // Validate Own Positions ... result = IsValidSize(count); if (!result) { @@ -1033,7 +1060,7 @@ class XCX121SMCXWZSignalDetector : public XCBase // // - // Get Custom Implemented Guards ... + // Implement Custom Implemented Guards ... // // Here we Are Sure there is Positions to Guard ... @@ -1051,76 +1078,12 @@ class XCX121SMCXWZSignalDetector : public XCBase // int loopback = 10; - // - XOHCL zBar; - result = zBar.Init( - symbol, - period, - zIndex // - ); - if (!result) - { - // - result = HasChild(guards); - return result; - } - - // - XOHCL cBar; - result = cBar.Init( - symbol, - period, - cIndex // - ); - if (!result) - { - // - zBar.Clean(); - result = HasChild(guards); - return result; - } - - // - XOHCL pBar; - result = pBar.Init( - symbol, - period, - pIndex // - ); - if (!result) - { - // - zBar.Clean(); - cBar.Clean(); - result = HasChild(guards); - return result; - } - - // - XOHCL ppBar; - result = ppBar.Init( - symbol, - period, - ppIndex // - ); - if (!result) - { - // - zBar.Clean(); - cBar.Clean(); - pBar.Clean(); - result = HasChild(guards); - return result; - } - // double ask = GetAsk(symbol); double bid = GetBid(symbol); datetime cTime = TimeCurrent(); double points = GetPoints(symbol); - // - // // Cycles Conditions ... @@ -1139,10 +1102,13 @@ class XCX121SMCXWZSignalDetector : public XCBase if (!result) { // - zBar.Clean(); - cBar.Clean(); - pBar.Clean(); - ppBar.Clean(); + Clean(decisionPoiEvents); + Clean(decisionCycleEvents); + + // + decisionConditions.Clean(); + + // result = HasChild(guards); return result; } @@ -1161,44 +1127,6 @@ class XCX121SMCXWZSignalDetector : public XCBase ); if (!result) { - // - zBar.Clean(); - cBar.Clean(); - pBar.Clean(); - ppBar.Clean(); - - // - Clean(decisionPoiEvents); - Clean(decisionCycleEvents); - - // - decisionConditions.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) - { - // - zBar.Clean(); - cBar.Clean(); - pBar.Clean(); - ppBar.Clean(); - // Clean(decisionPoiEvents); Clean(decisionCycleEvents); @@ -1219,25 +1147,19 @@ class XCX121SMCXWZSignalDetector : public XCBase } // - // Vision ... - ENUM_XPOI_EVENTS visionPoiEvents[]; - ENUM_X_CYCLE_EVENTS visionCycleEvents[]; - X121SMCCycleConditions visionConditions; - result = visionCycleHelper.GetConditions( - visionCycleEvents, - visionPoiEvents, - visionConditions, + // Consolidation ... + ENUM_XPOI_EVENTS consolidationPoiEvents[]; + ENUM_X_CYCLE_EVENTS consolidationCycleEvents[]; + X121SMCCycleConditions consolidationConditions; + result = consolidationCycleHelper.GetConditions( + consolidationCycleEvents, + consolidationPoiEvents, + consolidationConditions, zIndex, loopback // ); if (!result) { - // - zBar.Clean(); - cBar.Clean(); - pBar.Clean(); - ppBar.Clean(); - // Clean(decisionPoiEvents); Clean(decisionCycleEvents); @@ -1264,69 +1186,107 @@ class XCX121SMCXWZSignalDetector : public XCBase 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 decisionState = decisionConditions.state; - XPOIState analyseState = analyseConditions.state; - XPOIState consolidationState = consolidationConditions.state; XPOIState visionState = visionConditions.state; + XPOIState analyseState = analyseConditions.state; + XPOIState decisionState = decisionConditions.state; + XPOIState consolidationState = consolidationConditions.state; // // Cycle X121Conditions ... - X121Conditions decisionXConditions = decisionConditions.x121Conditions; - X121Conditions analyseXConditions = analyseConditions.x121Conditions; - X121Conditions consolidationXConditions = consolidationConditions.x121Conditions; X121Conditions visionXConditions = visionConditions.x121Conditions; + X121Conditions analyseXConditions = analyseConditions.x121Conditions; + X121Conditions decisionXConditions = decisionConditions.x121Conditions; + X121Conditions consolidationXConditions = consolidationConditions.x121Conditions; // // // - // // - // // Detect Consolidation Zone ... - - // // - // // Bullish ... - // XConsolidationZone bullishConsolidationZone; - // bool hasBullishConsolidationZone = decisionCycleHelper - // .GetLastDirectionalConsolidationZone( - // X_DIRECTION_BULLISH, - // bullishConsolidationZone // - // ); - - // // - // // Bearish ... - // XConsolidationZone bearishConsolidationZone; - // bool hasBearishConsolidationZone = decisionCycleHelper - // .GetLastDirectionalConsolidationZone( - // X_DIRECTION_BEARISH, - // bearishConsolidationZone // - // ); + // + // Selected Consolidation Zones ... // - // Detect High Probability Swings ... - bool isSwingLow = + int idx = -1; + bool has = false; + + // + bool hasBullishConsolidationZone = false; + XConsolidationZone bullishConsolidationZone; + has = decisionState.HasBullishConsolidationZones(); + if (has) + { // - cBar.low > pBar.low && - ppBar.low > pBar.low && + idx = GetYoungest(decisionState.bullishConsolidationZones); + hasBullishConsolidationZone = IsValidIndex(idx); + if (hasBullishConsolidationZone) + { + bullishConsolidationZone = decisionState.bullishConsolidationZones[idx]; + } + } + + // + bool hasBearishConsolidationZone = false; + XConsolidationZone bearishConsolidationZone; + has = decisionState.HasBearishConsolidationZones(); + if (has) + { // - zBar.low > pBar.low - // - ; - bool isSwingHigh = - // - cBar.high < pBar.high && - ppBar.high < pBar.high && - // - zBar.high < pBar.high - // - ; - bool isStrongSwingLow = - pBar.IsBullish() && - pBar.GetLowShadow() >= pBar.GetBody() * 2; - bool isStrongSwingHigh = - pBar.IsBearish() && - pBar.GetHighShadow() >= pBar.GetBody() * 2; + idx = GetYoungest(decisionState.bearishConsolidationZones); + hasBearishConsolidationZone = IsValidIndex(idx); + if (hasBearishConsolidationZone) + { + bearishConsolidationZone = decisionState.bearishConsolidationZones[idx]; + } + } // // Here We Have all Requirements for Guarding Positions ... @@ -1366,6 +1326,7 @@ class XCX121SMCXWZSignalDetector : public XCBase // // X_121_SMC_GUARD_ACTION_TRAIL_STOP: // Trail Stop Specified Position on Specified Conditions ... + bool handleStoptrailingBasedOnConsolidationZones = true; for (int i = 0; i < count; i++) { // @@ -1379,114 +1340,82 @@ class XCX121SMCXWZSignalDetector : public XCBase double sl = iPosition.sl; double tp = iPosition.tp; - // // - // // Trail Stops Using Consolidation Zones ... - // bool canTraiLonglUsingCZone = - // // - // (isLong && - // isInProfit && - // hasBullishConsolidationZone && - // bullishConsolidationZone.lower > iPosition.sl && - // bullishConsolidationZone.lower > iPosition.entry) - // // - // ; - // if (canTraiLonglUsingCZone) - // { - // sl = bullishConsolidationZone.lower; - // } + // + // Trail Stops Using Consolidation Zones ... - // // - // bool canTraiShortlUsingCZone = - // // - // (!isLong && - // isInProfit && - // hasBearishConsolidationZone && - // bearishConsolidationZone.upper < iPosition.sl && - // bearishConsolidationZone.upper < iPosition.entry) - // // - // ; - // if (canTraiShortlUsingCZone) - // { - // sl = bearishConsolidationZone.upper; - // } + // + bool canTraiLonglUsingCZone = + // + handleStoptrailingBasedOnConsolidationZones && + // + (isLong && + isInProfit && + hasBullishConsolidationZone && + bullishConsolidationZone.lower > iPosition.sl && + bullishConsolidationZone.lower > iPosition.entry) + // + ; + if (canTraiLonglUsingCZone) + { + sl = bullishConsolidationZone.lower; + } - // // - // bool canTrailUsingCZone = - // canTraiLonglUsingCZone || - // canTraiShortlUsingCZone; + // + bool canTraiShortlUsingCZone = + // + handleStoptrailingBasedOnConsolidationZones && + // + (!isLong && + isInProfit && + hasBearishConsolidationZone && + bearishConsolidationZone.upper < iPosition.sl && + bearishConsolidationZone.upper < iPosition.entry) + // + ; + if (canTraiShortlUsingCZone) + { + sl = bearishConsolidationZone.upper; + } - // // - // // Trail Stops Using Swings ... + // + bool canTrailUsingCZone = + canTraiLonglUsingCZone || + canTraiShortlUsingCZone; - // // - // bool canTrailLongUsingSwings = - // // - // isLong && - // isInProfit && - // (isSwingLow || - // isStrongSwingLow) && - // pBar.low > iPosition.sl && - // pBar.low > iPosition.entry - // // - // ; - // if (canTrailLongUsingSwings) - // { - // sl = pBar.low; - // } + // + bool isSLPassed = + sl > 0 && + (isLong + ? iPosition.price - sl >= points * 15 + : sl - iPosition.price >= points * 15); - // // - // bool canTraiShortlUsingSwings = - // // - // !isLong && - // isInProfit && - // (isSwingHigh || - // isStrongSwingHigh) && - // pBar.high < iPosition.sl && - // pBar.high < iPosition.entry - // // - // ; - // if (canTraiShortlUsingSwings) - // { - // sl = pBar.high; - // } + // + bool canTrail = + isSLPassed && + canTrailUsingCZone; + if (canTrail) + { + // + X121SMCGuard iGuard; - // // - // bool canTrailUsingSwings = - // canTrailLongUsingSwings || - // canTraiShortlUsingSwings; + // + iGuard.time = cTime; + iGuard.symbol = symbol; + iGuard.provider = provider; + iGuard.action = X_121_SMC_GUARD_ACTION_TRAIL_STOP; - // // - // // - // // + // + iGuard.ticket = iPosition.ticket; - // // - // bool canTrail = - // sl != iPosition.sl && - // (canTrailUsingCZone || - // canTrailUsingSwings); - // if (canTrail) - // { - // // - // X121SMCGuard iGuard; + // + iGuard.sl = sl; - // // - // 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 // - // ); - // } + // + AddGuard( + iGuard, + guards // + ); + } } // @@ -1506,34 +1435,34 @@ class XCX121SMCXWZSignalDetector : public XCBase Clean(ownShortPositions); // - zBar.Clean(); - cBar.Clean(); - pBar.Clean(); - ppBar.Clean(); + 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(visionCycleEvents); Clean(decisionPoiEvents); - Clean(analyseCycleEvents); - Clean(decisionCycleEvents); Clean(consolidationPoiEvents); - Clean(consolidationCycleEvents); // - visionState.Clean(); - analyseState.Clean(); - decisionState.Clean(); - visionConditions.Clean(); - analyseConditions.Clean(); - visionXConditions.Clean(); - decisionConditions.Clean(); - consolidationState.Clean(); - analyseXConditions.Clean(); - decisionXConditions.Clean(); - consolidationConditions.Clean(); - consolidationXConditions.Clean(); + Clean(visionCycleEvents); + Clean(analyseCycleEvents); + Clean(decisionCycleEvents); + Clean(consolidationCycleEvents); // count = ArraySize(guards); diff --git a/X121SMCEA/Signals/x-121.smc.xwz.signal.lib.mq5 b/X121SMCEA/Signals/x-121.smc.xwz.signal.lib.mq5 index d3b8f2ae..4193c9f4 100644 --- a/X121SMCEA/Signals/x-121.smc.xwz.signal.lib.mq5 +++ b/X121SMCEA/Signals/x-121.smc.xwz.signal.lib.mq5 @@ -386,6 +386,47 @@ struct X121SMCStrategyXWZWorkingZone stfState // ); + // + // Detect Waiting Zones based on STF and TTF ... + XOBFVG tmpWaitingZones[]; + count = ExtractOBFVGs( + tmpWaitingZones, + stfState, + ttfState // + ); + has = IsValidSize(count); + if (has) + { + // + for (int i = 0; i < count; i++) + { + // + XOBFVG iOBFVG = tmpWaitingZones[i]; + + // + idx = FindIndex( + iOBFVG, + waitingZones // + ); + has = IsValidIndex(idx); + if (has) + { + // + iOBFVG.Clean(); + continue; + } + + // + AddRef( + iOBFVG, + waitingZones // + ); + + // + iOBFVG.Clean(); + } + } + // result = IsValid(); if (!result) @@ -767,6 +808,47 @@ struct X121SMCStrategyXWZWorkingZone } } + // + // Detect Waiting Zones based on STF and TTF ... + Clean(tmpWaitingZones); + count = ExtractOBFVGs( + tmpWaitingZones, + stfState, + ttfState // + ); + has = IsValidSize(count); + if (has) + { + // + for (int i = 0; i < count; i++) + { + // + XOBFVG iOBFVG = tmpWaitingZones[i]; + + // + idx = FindIndex( + iOBFVG, + waitingZones // + ); + has = IsValidIndex(idx); + if (has) + { + // + iOBFVG.Clean(); + continue; + } + + // + AddRef( + iOBFVG, + waitingZones // + ); + + // + iOBFVG.Clean(); + } + } + // zBar.Clean(); cBar.Clean(); @@ -1846,7 +1928,7 @@ struct X121SMCStrategyXWZSignalConditions * * @return ( bool ) */ -bool CheckOBFVGXWZConditions( +bool DetectSelectedZoneConditions( bool &isReversal, XOBFVG &zone, XPOIState &state, @@ -1882,6 +1964,7 @@ bool CheckOBFVGXWZConditions( // double bullishScore = 0; double bearishScore = 0; + double scoreMultiplier = 1.5; conditions.GenerateScore( bullishScore, bearishScore // @@ -1890,12 +1973,12 @@ bool CheckOBFVGXWZConditions( // bool isBullishScorePassed = bullishScore > 0 && bearishScore >= 0 && - bullishScore > bearishScore; + bullishScore > bearishScore * scoreMultiplier; // bool isBearishScorePassed = bearishScore > 0 && bullishScore >= 0 && - bearishScore > bullishScore; + bearishScore > bullishScore * scoreMultiplier; // // VWap ... @@ -3241,4 +3324,90 @@ bool DetectSelectedZoneSLCandidates( return result; } +// +// +// + +bool DetectX121Conditions( + double &pivot, + double &point, + double &sls[], + double &targets[], + ENUM_X_DIRECTION &dir, + XPOIState &stfState, + XPOIState &ttfState, + X121Conditions &conditions, + XCPOIDrawer *drawer = NULL // +) +{ + // + bool result = false; + + // + bool canDraw = drawer != NULL; + + // + pivot = 0; + point = 0; + Clean(sls); + Clean(targets); + dir = X_DIRECTION_NONE; + + // + result = + stfState.IsValid() && + ttfState.IsValid() && + stfState.HasChild() && + ttfState.HasChild(); + if (!result) + { + return result; + } + + // + int idx = -1; + int count = 0; + bool has = false; + + // + // Detect Inside STF Order Blocks Zones ... + + // + XOBFVG tmpWaitingZones[]; + count = ExtractOBFVGs( + tmpWaitingZones, + stfState, + ttfState // + ); + has = IsValidSize(count); + if (has) + { + // + if (canDraw) + { + // + for (int i = 0; i < count; i++) + { + // + XOBFVG iOBFVG = tmpWaitingZones[i]; + + // + iOBFVG.UpdateTo(); + + // + XCBaseObject *iOBFVGObjects[]; + int iOBFVGObjectsCount = drawer.DrawOBFVG( + iOBFVG, + iOBFVGObjects // + ); + } + } + } + + // + + // + return result; +} + // \ No newline at end of file