diff --git a/Documents/BKP/xsupdem/plib.tmp.codes.mq5 b/Documents/BKP/xsupdem/plib.tmp.codes.mq5 new file mode 100644 index 00000000..c5bb2226 --- /dev/null +++ b/Documents/BKP/xsupdem/plib.tmp.codes.mq5 @@ -0,0 +1,1055 @@ + +/** + * Sort Order Blocks / Fair Value Gaps based on Place and Remove unused ... + */ +template +void OrderedSortZones( + T *youngest, + T *&items[] // +) +{ + // + int count = ArraySize(items); + if (youngest == NULL || + !youngest.IsValid() || + !IsValidSize(count)) + { + return; + } + + // + ENUM_X_DIRECTION dir = youngest.GetDirection(); + bool isBullish = IsBullish(dir); + + // + T *tmp[]; + T *lastOB = youngest; + while (IsValidSize(count)) + { + // + // Detect Youngest of Collection ... + int idx = GetYoungest(items); + T *iChild = items[idx]; + ArrayRemove( + items, + idx, + 1 // + ); + count = ArraySize(items); + + // + // Check Direction Must be Same ... + ENUM_X_DIRECTION iDir = iChild.GetDirection(); + bool isSameDir = dir == iDir; + if (!isSameDir) + { + continue; + } + + // + // Check Creation time Sequence ... + bool isFromPassed = lastOB.From() > iChild.From(); + if (!isFromPassed) + { + continue; + } + + // + // Check Order Block Place ... + bool isPlacePassed = + isBullish + ? IsBelow( + iChild, + lastOB, + true // Ignore Inside ... + ) + : IsAbove( + iOB, + lastOB, + true // Ignore Inside ... + ); + if (!isPlacePassed) + { + continue; + } + + // + // Update Last OB ... + lastOB = iChild; + Add( + iChild, + tmp // + ); + + // + } + + // + // Update Ordered Sorted Order Blocks ... + count = ArraySize(tmp); + if (IsValidSize(count)) + { + // + Copy( + tmp, + orderBlocks // + ); + } +} +template +void OrderedSortZones( + T *&items[] // +) +{ + // + int count = ArraySize(items); + if (!IsValidSize(count)) + { + return; + } + + // + // Detect Youngest ... + int youngestIDX = GetYoungest( + items // + ); + bool hasYoungest = IsValidSize(youngestIDX); + if (!hasYoungest) + { + return; + } + + // + T *youngest = items[youngestIDX]; + ArrayRemove( + items, + youngestIDX, + 1 // + ); + count = ArraySize(items); + if (!IsValidSize(count)) + { + // + Add( + youngest, + items // + ); + + // + return; + } + + // + if (youngest == NULL || + !youngest.IsValid()) + { + return; + } + + // + ENUM_X_DIRECTION dir = youngest.GetDirection(); + bool isBullish = IsBullish(dir); + + // + T *tmp[]; + T *lastOB = youngest; + while (IsValidSize(count)) + { + // + // Detect Youngest of Collection ... + int idx = GetYoungest(items); + T *iChild = items[idx]; + ArrayRemove( + items, + idx, + 1 // + ); + count = ArraySize(items); + + // + // Check Direction Must be Same ... + ENUM_X_DIRECTION iDir = iChild.GetDirection(); + bool isSameDir = dir == iDir; + if (!isSameDir) + { + continue; + } + + // + // Check Creation time Sequence ... + bool isFromPassed = lastOB.From() > iChild.From(); + if (!isFromPassed) + { + continue; + } + + // + // Check Order Block Place ... + bool isPlacePassed = + isBullish + ? IsBelow( + iChild, + lastOB, + true // Ignore Inside ... + ) + : IsAbove( + iChild, + lastOB, + true // Ignore Inside ... + ); + if (!isPlacePassed) + { + continue; + } + + // + // Update Last OB ... + lastOB = iChild; + Add( + iChild, + tmp // + ); + + // + } + + // + // Update Ordered Sorted Order Blocks ... + count = ArraySize(tmp); + if (IsValidSize(count)) + { + // + Copy( + tmp, + items // + ); + } +} + +void OrderedSortBoxes( + XBoxZone &items[] // +) +{ + // + int count = ArraySize(items); + if (!IsValidSize(count)) + { + return; + } + + // + // Detect Youngest ... + int youngestIDX = GetYoungest( + items // + ); + bool hasYoungest = IsValidSize(youngestIDX); + if (!hasYoungest) + { + return; + } + + // + XBoxZone youngest = items[youngestIDX]; + ArrayRemove( + items, + youngestIDX, + 1 // + ); + count = ArraySize(items); + if (!IsValidSize(count)) + { + // + AddRef( + youngest, + items // + ); + + // + return; + } + + // + if (!youngest.IsValid()) + { + return; + } + + // + ENUM_X_DIRECTION dir = youngest.dir; + bool isBullish = IsBullish(dir); + + // + XBoxZone tmp[]; + XBoxZone last = youngest; + while (IsValidSize(count)) + { + // + // Detect Youngest of Collection ... + int idx = GetYoungest(items); + XBoxZone iChild = items[idx]; + ArrayRemove( + items, + idx, + 1 // + ); + count = ArraySize(items); + + // + // Check Direction Must be Same ... + ENUM_X_DIRECTION iDir = iChild.dir; + bool isSameDir = dir == iDir; + if (!isSameDir) + { + continue; + } + + // + // Check Creation time Sequence ... + bool isFromPassed = last.from > iChild.from; + if (!isFromPassed) + { + continue; + } + + // + // Check Order Block Place ... + bool isPlacePassed = + isBullish + ? IsBoxBelow( + iChild, + last, + true // Ignore Inside ... + ) + : IsBoxAbove( + iChild, + last, + true // Ignore Inside ... + ); + if (!isPlacePassed) + { + continue; + } + + // + // Update Last OB ... + last = iChild; + AddRef( + iChild, + tmp // + ); + + // + } + + // + // Update Ordered Sorted Order Blocks ... + count = ArraySize(tmp); + if (IsValidSize(count)) + { + // + Copy( + tmp, + items // + ); + } +} + +/** + * Extract Order Flows Swing Points ... + * + * @param type: ENUM_X_SWING_TYPE member ... + * @param swings: double Collection ... + * + * @return ( int ) + */ +int ExtractSwingPoints( + ENUM_X_SWING_TYPE type, + XCOrderBlock *&orderBlocks[], + XSwingPoint &swings[] // +) +{ + // + int result = 0; + + // + Clean(swings); + + // + int count = ArraySize(orderBlocks); + + // + if (type == X_NO_SWING || + !IsValidSize(count)) + { + return result; + } + + // + bool lookingForSwingLows = type == X_SWING_LOW; + + // + for (int i = 0; i < count; i++) + { + // + XCOrderBlock *iOB = orderBlocks[i]; + + // + string iSymbol = iOB.GetSymbol(); + ENUM_TIMEFRAMES iPeriod = iOB.GetPeriod(); + + // + int fromIndex = iBarShift( + iSymbol, + iPeriod, + iOB.From() // + ); + + // + fromIndex++; + + // + double iValue = 0; + datetime iVTime = NULL; + if (lookingForSwingLows) + { + // + int idx = iLowest( + iSymbol, + iPeriod, + MODE_LOW, + fromIndex // + ); + + // + if (IsValidIndex(idx)) + { + // + iValue = iLow( + iSymbol, + iPeriod, + idx // + ); + + // + iVTime = iTime( + iSymbol, + iPeriod, + idx // + ); + } + } + else + { + // + int idx = iHighest( + iSymbol, + iPeriod, + MODE_HIGH, + fromIndex // + ); + + // + if (IsValidIndex(idx)) + { + // + iValue = iHigh( + iSymbol, + iPeriod, + idx // + ); + + // + iVTime = iTime( + iSymbol, + iPeriod, + idx // + ); + } + } + + // + if (iValue > 0) + { + // + XSwingPoint iSwingP; + + // + iSwingP.type = type; + iSwingP.time = iVTime; + iSwingP.swing = iValue; + iSwingP.symbol = iSymbol; + iSwingP.period = iPeriod; + + // + if (iSwingP.IsValid()) + { + // + AddRef( + iSwingP, + swings // + ); + } + + // + iSwingP.Clean(); + } + } + + // + result = ArraySize(swings); + + // + return result; +} + + +// +bool IsRejectBox( + ENUM_X_DIRECTION &forDir, + XOHCL &bar, + XBoxZone &box, + XPOIState &state, + XOHCL &swingBar, + XOHCL &rejectBar, + XOHCL &breakerBar, + XOHCL &momentumBar, + bool forceSwingRejection = true // +) +{ + // + bool result = false; + + // + swingBar.Clean(); + rejectBar.Clean(); + breakerBar.Clean(); + momentumBar.Clean(); + + // + result = bar.IsValid() && + box.IsValid() && + state.IsValid() && + state.HasChild() && + HasDirection(forDir); + if (!result) + { + return result; + } + + // + bool isBullish = IsBullish(forDir); + + // + double appliedPrice = + isBullish + ? box.upper + : box.lower; + + // + // Fetch Required Bars ... + + // + XOHCL cBar; + result = bar.GetPreviousBar(cBar); + if (!result) + { + return result; + } + + // + XOHCL pBar; + result = cBar.GetPreviousBar(pBar); + if (!result) + { + return result; + } + + // + XOHCL ppBar; + result = pBar.GetPreviousBar(ppBar); + if (!result) + { + return result; + } + + // + // Check Directional Swing Type ... + ENUM_X_SWING_TYPE swingType = + isBullish + ? X_SWING_LOW + : X_SWING_HIGH; + + // + bool isSwingLow = + // + pBar.low < ppBar.low && + pBar.low < cBar.low && + bar.open > pBar.low && + // + appliedPrice > pBar.low && + appliedPrice < pBar.GetDown() + // + ; + + // + bool isSwingHigh = + // + pBar.high > ppBar.high && + pBar.high > cBar.high && + bar.open < pBar.high && + // + appliedPrice < pBar.high && + appliedPrice > pBar.GetUp() + // + ; + + // + // Force Rejected By Swing ... + if (forceSwingRejection) + { + // + result = swingType == X_SWING_HIGH + ? isSwingHigh + : swingType == X_SWING_LOW + ? isSwingLow + : false; + if (!result) + { + return result; + } + } + + // + bool hasValidSwing = + isBullish + ? isSwingLow + : isSwingHigh; + if (hasValidSwing) + { + swingBar = pBar; + } + + // + bool isCBarBreaked = IsBarBreak( + appliedPrice, + forDir, + cBar // + ); + if (isCBarBreaked) + { + breakerBar = cBar; + } + bool isPBarBreaked = IsBarBreak( + appliedPrice, + forDir, + pBar // + ); + if (isPBarBreaked) + { + breakerBar = pBar; + } + bool isPPBarBreaked = IsBarBreak( + appliedPrice, + forDir, + ppBar // + ); + if (isPPBarBreaked) + { + breakerBar = ppBar; + } + bool isBoxBreaked = isCBarBreaked || + isPBarBreaked || + isPPBarBreaked; + + // + bool isCBarRejected = IsBarReject( + appliedPrice, + forDir, + cBar // + ); + if (isCBarRejected) + { + rejectBar = cBar; + } + bool isPBarRejected = IsBarReject( + appliedPrice, + forDir, + pBar // + ); + if (isPBarRejected) + { + rejectBar = pBar; + } + bool isPPBarRejected = IsBarReject( + appliedPrice, + forDir, + ppBar // + ); + if (isPPBarRejected) + { + rejectBar = ppBar; + } + bool isBoxRejected = isCBarRejected || + isPBarRejected || + isPPBarRejected; + + // + int count = 0; + + // + bool hasRejectionBar = false; + if (isBullish) + { + // + count = state.CountBullishRejectionBars(); + for (int i = 0; i < count; i++) + { + // + XCRejectionBar *iZone = state.bullishRejectionBars[i]; + + // + XOHCL iBar; + bool isFilled = iZone.FillBar(iBar); + if (!isFilled) + { + continue; + } + + // + int iBarIndex = iBar.Index(); + + // + hasRejectionBar = + // + (iBarIndex == cBar.Index() || + iBarIndex == pBar.Index()) + // + ; + if (hasRejectionBar) + { + // + if (!rejectBar.IsValid()) + { + rejectBar = iBar; + } + + // + break; + } + } + } + else + { + // + count = state.CountBearishRejectionBars(); + for (int i = 0; i < count; i++) + { + // + XCRejectionBar *iZone = state.bearishRejectionBars[i]; + + // + XOHCL iBar; + bool isFilled = iZone.FillBar(iBar); + if (!isFilled) + { + continue; + } + + // + int iBarIndex = iBar.Index(); + + // + hasRejectionBar = + // + (iBarIndex == cBar.Index() || + iBarIndex == pBar.Index()) + // + ; + if (hasRejectionBar) + { + // + if (!rejectBar.IsValid()) + { + rejectBar = iBar; + } + + // + break; + } + } + } + + // + bool hasMomentumBar = false; + if (isBullish) + { + // + count = state.CountBullishMomentumBars(); + for (int i = 0; i < count; i++) + { + // + XCMomentumBar *iZone = state.bullishMomentumBars[i]; + + // + XOHCL iBar; + bool isFilled = iZone.FillBar(iBar); + if (!isFilled) + { + continue; + } + + // + int iBarIndex = iBar.Index(); + + // + hasMomentumBar = + // + (iBarIndex == cBar.Index() || + iBarIndex == pBar.Index()) + // + ; + if (hasMomentumBar) + { + // + if (!momentumBar.IsValid()) + { + momentumBar = iBar; + } + + // + break; + } + } + } + else + { + // + count = state.CountBearishMomentumBars(); + for (int i = 0; i < count; i++) + { + // + XCMomentumBar *iZone = state.bearishMomentumBars[i]; + + // + XOHCL iBar; + bool isFilled = iZone.FillBar(iBar); + if (!isFilled) + { + continue; + } + + // + int iBarIndex = iBar.Index(); + + // + hasMomentumBar = + // + (iBarIndex == cBar.Index() || + iBarIndex == pBar.Index()) + // + ; + if (hasMomentumBar) + { + // + if (!momentumBar.IsValid()) + { + momentumBar = iBar; + } + + // + break; + } + } + } + + // + bool hasSwing = false; + if (isBullish) + { + // + count = state.CountSwingLows(); + for (int i = 0; i < count; i++) + { + // + XCSwing *iSwing = state.swingLows[i]; + + // + XOHCL iBar; + bool isFilled = iSwing.FillBar(iBar); + if (!isFilled) + { + continue; + } + + // + int iBarIndex = iBar.Index(); + + // + hasSwing = + // + (iBarIndex == cBar.Index() || + iBarIndex == pBar.Index()) + // + ; + if (hasSwing) + { + // + if (!swingBar.IsValid()) + { + swingBar = iBar; + } + + // + break; + } + } + } + else + { + // + count = state.CountSwingHighs(); + for (int i = 0; i < count; i++) + { + // + XCSwing *iSwing = state.swingHighs[i]; + + // + XOHCL iBar; + bool isFilled = iSwing.FillBar(iBar); + if (!isFilled) + { + continue; + } + + // + int iBarIndex = iBar.Index(); + + // + hasSwing = + // + (iBarIndex == cBar.Index() || + iBarIndex == pBar.Index()) + // + ; + if (hasSwing) + { + // + if (!swingBar.IsValid()) + { + swingBar = iBar; + } + + // + break; + } + } + } + + // + bool hasRequiredValidations = + // + (hasRejectionBar || + hasMomentumBar) + // + || + // + (hasRejectionBar || + hasSwing) + // + || + // + (hasMomentumBar || + hasSwing) + // + ; + + // + result = + // + (isBoxBreaked && + (hasRequiredValidations || + hasValidSwing)) + // + || + // + (isBoxRejected && + (hasRequiredValidations || + hasValidSwing)) + // + ; + + // + return result; +} + + +template +void UpdateTo( + T *&source[], + datetime time = NULL // +) +{ + // + if (!IsValid(time)) + { + time = TimeCurrent(); + } + + // + int count = ArraySize(source); + if (!IsValidSize(count)) + { + return; + } + + // + for (int i = 0; i < count; i++) + { + source[i].To(time); + } +} + + +template +bool IsReject( + ENUM_X_DIRECTION forDir, + XOHCL &bar, + T *source, + XPOIState &state, + XOHCL &swingBar, + XOHCL &rejectBar, + XOHCL &breakerBar, + XOHCL &momentumBar, + bool forceSwingRejection = true // +) +{ + // + bool result = false; + + // + XBoxZone sourceBox; + result = ToBox( + sourceBox, + source // + ); + if (!result) + { + return result; + } + + // + result = IsRejectBox( + forDir, + bar, + sourceBox, + state, + swingBar, + rejectBar, + breakerBar, + momentumBar, + forceSwingRejection // + ); + + // + return result; +} diff --git a/X121SMCEA/Signals/x-121.smc.xsupdemobs.signal.class.mq5 b/Documents/BKP/xsupdem/x-121.smc.xsupdemobs.signal.class.mq5 similarity index 98% rename from X121SMCEA/Signals/x-121.smc.xsupdemobs.signal.class.mq5 rename to Documents/BKP/xsupdem/x-121.smc.xsupdemobs.signal.class.mq5 index 51fde779..1e58957e 100644 --- a/X121SMCEA/Signals/x-121.smc.xsupdemobs.signal.class.mq5 +++ b/Documents/BKP/xsupdem/x-121.smc.xsupdemobs.signal.class.mq5 @@ -1431,17 +1431,18 @@ class XCX121SMCXSupDemOBSSignalDetector : public XCBase bool isIBullish = IsBullish(iForDir); // - isPriceRejected = IsReject( - iForDir, - decisionZBar, - obs[i], - decisionState, - swingBar, - rejectBar, - breakerBar, - momentumBar, - false // - ); + isPriceRejected = false; + // IsReject( + // iForDir, + // decisionZBar, + // obs[i], + // decisionState, + // swingBar, + // rejectBar, + // breakerBar, + // momentumBar, + // false // + // ); if (isPriceRejected) { // @@ -1494,17 +1495,18 @@ class XCX121SMCXSupDemOBSSignalDetector : public XCBase bool isIBullish = IsBullish(iForDir); // - isPriceRejected = IsReject( - iForDir, - decisionZBar, - fvgs[i], - decisionState, - swingBar, - rejectBar, - breakerBar, - momentumBar, - false // - ); + isPriceRejected = false; + // IsReject( + // iForDir, + // decisionZBar, + // fvgs[i], + // decisionState, + // swingBar, + // rejectBar, + // breakerBar, + // momentumBar, + // false // + // ); if (isPriceRejected) { // diff --git a/X121SMCEA/Signals/x-121.smc.xsupdemobs.signal.lib.mq5 b/Documents/BKP/xsupdem/x-121.smc.xsupdemobs.signal.lib.mq5 similarity index 100% rename from X121SMCEA/Signals/x-121.smc.xsupdemobs.signal.lib.mq5 rename to Documents/BKP/xsupdem/x-121.smc.xsupdemobs.signal.lib.mq5 diff --git a/Libraries/x-saherelm.x-poi.lib.mq5 b/Libraries/x-saherelm.x-poi.lib.mq5 index 7a06918e..19ae990e 100644 --- a/Libraries/x-saherelm.x-poi.lib.mq5 +++ b/Libraries/x-saherelm.x-poi.lib.mq5 @@ -7213,76 +7213,6 @@ bool IsBelow( return result; } -template -bool IsReject( - ENUM_X_DIRECTION forDir, - XOHCL &bar, - T *source, - XPOIState &state, - XOHCL &swingBar, - XOHCL &rejectBar, - XOHCL &breakerBar, - XOHCL &momentumBar, - bool forceSwingRejection = true // -) -{ - // - bool result = false; - - // - XBoxZone sourceBox; - result = ToBox( - sourceBox, - source // - ); - if (!result) - { - return result; - } - - // - result = IsRejectBox( - forDir, - bar, - sourceBox, - state, - swingBar, - rejectBar, - breakerBar, - momentumBar, - forceSwingRejection // - ); - - // - return result; -} - -template -void UpdateTo( - T *&source[], - datetime time = NULL // -) -{ - // - if (!IsValid(time)) - { - time = TimeCurrent(); - } - - // - int count = ArraySize(source); - if (!IsValidSize(count)) - { - return; - } - - // - for (int i = 0; i < count; i++) - { - source[i].To(time); - } -} - /** * Find Specified Box Index inside a Collection of Boxes ... * @@ -7634,485 +7564,6 @@ bool IsBoxUsed( return result; } -// -bool IsRejectBox( - ENUM_X_DIRECTION &forDir, - XOHCL &bar, - XBoxZone &box, - XPOIState &state, - XOHCL &swingBar, - XOHCL &rejectBar, - XOHCL &breakerBar, - XOHCL &momentumBar, - bool forceSwingRejection = true // -) -{ - // - bool result = false; - - // - swingBar.Clean(); - rejectBar.Clean(); - breakerBar.Clean(); - momentumBar.Clean(); - - // - result = bar.IsValid() && - box.IsValid() && - state.IsValid() && - state.HasChild() && - HasDirection(forDir); - if (!result) - { - return result; - } - - // - bool isBullish = IsBullish(forDir); - - // - double appliedPrice = - isBullish - ? box.upper - : box.lower; - - // - // Fetch Required Bars ... - - // - XOHCL cBar; - result = bar.GetPreviousBar(cBar); - if (!result) - { - return result; - } - - // - XOHCL pBar; - result = cBar.GetPreviousBar(pBar); - if (!result) - { - return result; - } - - // - XOHCL ppBar; - result = pBar.GetPreviousBar(ppBar); - if (!result) - { - return result; - } - - // - // Check Directional Swing Type ... - ENUM_X_SWING_TYPE swingType = - isBullish - ? X_SWING_LOW - : X_SWING_HIGH; - - // - bool isSwingLow = - // - pBar.low < ppBar.low && - pBar.low < cBar.low && - bar.open > pBar.low && - // - appliedPrice > pBar.low && - appliedPrice < pBar.GetDown() - // - ; - - // - bool isSwingHigh = - // - pBar.high > ppBar.high && - pBar.high > cBar.high && - bar.open < pBar.high && - // - appliedPrice < pBar.high && - appliedPrice > pBar.GetUp() - // - ; - - // - // Force Rejected By Swing ... - if (forceSwingRejection) - { - // - result = swingType == X_SWING_HIGH - ? isSwingHigh - : swingType == X_SWING_LOW - ? isSwingLow - : false; - if (!result) - { - return result; - } - } - - // - bool hasValidSwing = - isBullish - ? isSwingLow - : isSwingHigh; - if (hasValidSwing) - { - swingBar = pBar; - } - - // - bool isCBarBreaked = IsBarBreak( - appliedPrice, - forDir, - cBar // - ); - if (isCBarBreaked) - { - breakerBar = cBar; - } - bool isPBarBreaked = IsBarBreak( - appliedPrice, - forDir, - pBar // - ); - if (isPBarBreaked) - { - breakerBar = pBar; - } - bool isPPBarBreaked = IsBarBreak( - appliedPrice, - forDir, - ppBar // - ); - if (isPPBarBreaked) - { - breakerBar = ppBar; - } - bool isBoxBreaked = isCBarBreaked || - isPBarBreaked || - isPPBarBreaked; - - // - bool isCBarRejected = IsBarReject( - appliedPrice, - forDir, - cBar // - ); - if (isCBarRejected) - { - rejectBar = cBar; - } - bool isPBarRejected = IsBarReject( - appliedPrice, - forDir, - pBar // - ); - if (isPBarRejected) - { - rejectBar = pBar; - } - bool isPPBarRejected = IsBarReject( - appliedPrice, - forDir, - ppBar // - ); - if (isPPBarRejected) - { - rejectBar = ppBar; - } - bool isBoxRejected = isCBarRejected || - isPBarRejected || - isPPBarRejected; - - // - int count = 0; - - // - bool hasRejectionBar = false; - if (isBullish) - { - // - count = state.CountBullishRejectionBars(); - for (int i = 0; i < count; i++) - { - // - XCRejectionBar *iZone = state.bullishRejectionBars[i]; - - // - XOHCL iBar; - bool isFilled = iZone.FillBar(iBar); - if (!isFilled) - { - continue; - } - - // - int iBarIndex = iBar.Index(); - - // - hasRejectionBar = - // - (iBarIndex == cBar.Index() || - iBarIndex == pBar.Index()) - // - ; - if (hasRejectionBar) - { - // - if (!rejectBar.IsValid()) - { - rejectBar = iBar; - } - - // - break; - } - } - } - else - { - // - count = state.CountBearishRejectionBars(); - for (int i = 0; i < count; i++) - { - // - XCRejectionBar *iZone = state.bearishRejectionBars[i]; - - // - XOHCL iBar; - bool isFilled = iZone.FillBar(iBar); - if (!isFilled) - { - continue; - } - - // - int iBarIndex = iBar.Index(); - - // - hasRejectionBar = - // - (iBarIndex == cBar.Index() || - iBarIndex == pBar.Index()) - // - ; - if (hasRejectionBar) - { - // - if (!rejectBar.IsValid()) - { - rejectBar = iBar; - } - - // - break; - } - } - } - - // - bool hasMomentumBar = false; - if (isBullish) - { - // - count = state.CountBullishMomentumBars(); - for (int i = 0; i < count; i++) - { - // - XCMomentumBar *iZone = state.bullishMomentumBars[i]; - - // - XOHCL iBar; - bool isFilled = iZone.FillBar(iBar); - if (!isFilled) - { - continue; - } - - // - int iBarIndex = iBar.Index(); - - // - hasMomentumBar = - // - (iBarIndex == cBar.Index() || - iBarIndex == pBar.Index()) - // - ; - if (hasMomentumBar) - { - // - if (!momentumBar.IsValid()) - { - momentumBar = iBar; - } - - // - break; - } - } - } - else - { - // - count = state.CountBearishMomentumBars(); - for (int i = 0; i < count; i++) - { - // - XCMomentumBar *iZone = state.bearishMomentumBars[i]; - - // - XOHCL iBar; - bool isFilled = iZone.FillBar(iBar); - if (!isFilled) - { - continue; - } - - // - int iBarIndex = iBar.Index(); - - // - hasMomentumBar = - // - (iBarIndex == cBar.Index() || - iBarIndex == pBar.Index()) - // - ; - if (hasMomentumBar) - { - // - if (!momentumBar.IsValid()) - { - momentumBar = iBar; - } - - // - break; - } - } - } - - // - bool hasSwing = false; - if (isBullish) - { - // - count = state.CountSwingLows(); - for (int i = 0; i < count; i++) - { - // - XCSwing *iSwing = state.swingLows[i]; - - // - XOHCL iBar; - bool isFilled = iSwing.FillBar(iBar); - if (!isFilled) - { - continue; - } - - // - int iBarIndex = iBar.Index(); - - // - hasSwing = - // - (iBarIndex == cBar.Index() || - iBarIndex == pBar.Index()) - // - ; - if (hasSwing) - { - // - if (!swingBar.IsValid()) - { - swingBar = iBar; - } - - // - break; - } - } - } - else - { - // - count = state.CountSwingHighs(); - for (int i = 0; i < count; i++) - { - // - XCSwing *iSwing = state.swingHighs[i]; - - // - XOHCL iBar; - bool isFilled = iSwing.FillBar(iBar); - if (!isFilled) - { - continue; - } - - // - int iBarIndex = iBar.Index(); - - // - hasSwing = - // - (iBarIndex == cBar.Index() || - iBarIndex == pBar.Index()) - // - ; - if (hasSwing) - { - // - if (!swingBar.IsValid()) - { - swingBar = iBar; - } - - // - break; - } - } - } - - // - bool hasRequiredValidations = - // - (hasRejectionBar || - hasMomentumBar) - // - || - // - (hasRejectionBar || - hasSwing) - // - || - // - (hasMomentumBar || - hasSwing) - // - ; - - // - result = - // - (isBoxBreaked && - (hasRequiredValidations || - hasValidSwing)) - // - || - // - (isBoxRejected && - (hasRequiredValidations || - hasValidSwing)) - // - ; - - // - return result; -} - /** * Converts a Consolidation Zone ... * @@ -9457,503 +8908,813 @@ int ExtractDirectionalZones( } /** - * Sort Order Blocks / Fair Value Gaps based on Place and Remove unused ... - */ -template -void OrderedSortZones( - T *youngest, - T *&items[] // -) -{ - // - int count = ArraySize(items); - if (youngest == NULL || - !youngest.IsValid() || - !IsValidSize(count)) - { - return; - } - - // - ENUM_X_DIRECTION dir = youngest.GetDirection(); - bool isBullish = IsBullish(dir); - - // - T *tmp[]; - T *lastOB = youngest; - while (IsValidSize(count)) - { - // - // Detect Youngest of Collection ... - int idx = GetYoungest(items); - T *iChild = items[idx]; - ArrayRemove( - items, - idx, - 1 // - ); - count = ArraySize(items); - - // - // Check Direction Must be Same ... - ENUM_X_DIRECTION iDir = iChild.GetDirection(); - bool isSameDir = dir == iDir; - if (!isSameDir) - { - continue; - } - - // - // Check Creation time Sequence ... - bool isFromPassed = lastOB.From() > iChild.From(); - if (!isFromPassed) - { - continue; - } - - // - // Check Order Block Place ... - bool isPlacePassed = - isBullish - ? IsBelow( - iChild, - lastOB, - true // Ignore Inside ... - ) - : IsAbove( - iOB, - lastOB, - true // Ignore Inside ... - ); - if (!isPlacePassed) - { - continue; - } - - // - // Update Last OB ... - lastOB = iChild; - Add( - iChild, - tmp // - ); - - // - } - - // - // Update Ordered Sorted Order Blocks ... - count = ArraySize(tmp); - if (IsValidSize(count)) - { - // - Copy( - tmp, - orderBlocks // - ); - } -} -template -void OrderedSortZones( - T *&items[] // -) -{ - // - int count = ArraySize(items); - if (!IsValidSize(count)) - { - return; - } - - // - // Detect Youngest ... - int youngestIDX = GetYoungest( - items // - ); - bool hasYoungest = IsValidSize(youngestIDX); - if (!hasYoungest) - { - return; - } - - // - T *youngest = items[youngestIDX]; - ArrayRemove( - items, - youngestIDX, - 1 // - ); - count = ArraySize(items); - if (!IsValidSize(count)) - { - // - Add( - youngest, - items // - ); - - // - return; - } - - // - if (youngest == NULL || - !youngest.IsValid()) - { - return; - } - - // - ENUM_X_DIRECTION dir = youngest.GetDirection(); - bool isBullish = IsBullish(dir); - - // - T *tmp[]; - T *lastOB = youngest; - while (IsValidSize(count)) - { - // - // Detect Youngest of Collection ... - int idx = GetYoungest(items); - T *iChild = items[idx]; - ArrayRemove( - items, - idx, - 1 // - ); - count = ArraySize(items); - - // - // Check Direction Must be Same ... - ENUM_X_DIRECTION iDir = iChild.GetDirection(); - bool isSameDir = dir == iDir; - if (!isSameDir) - { - continue; - } - - // - // Check Creation time Sequence ... - bool isFromPassed = lastOB.From() > iChild.From(); - if (!isFromPassed) - { - continue; - } - - // - // Check Order Block Place ... - bool isPlacePassed = - isBullish - ? IsBelow( - iChild, - lastOB, - true // Ignore Inside ... - ) - : IsAbove( - iChild, - lastOB, - true // Ignore Inside ... - ); - if (!isPlacePassed) - { - continue; - } - - // - // Update Last OB ... - lastOB = iChild; - Add( - iChild, - tmp // - ); - - // - } - - // - // Update Ordered Sorted Order Blocks ... - count = ArraySize(tmp); - if (IsValidSize(count)) - { - // - Copy( - tmp, - items // - ); - } -} - -void OrderedSortBoxes( - XBoxZone &items[] // -) -{ - // - int count = ArraySize(items); - if (!IsValidSize(count)) - { - return; - } - - // - // Detect Youngest ... - int youngestIDX = GetYoungest( - items // - ); - bool hasYoungest = IsValidSize(youngestIDX); - if (!hasYoungest) - { - return; - } - - // - XBoxZone youngest = items[youngestIDX]; - ArrayRemove( - items, - youngestIDX, - 1 // - ); - count = ArraySize(items); - if (!IsValidSize(count)) - { - // - AddRef( - youngest, - items // - ); - - // - return; - } - - // - if (!youngest.IsValid()) - { - return; - } - - // - ENUM_X_DIRECTION dir = youngest.dir; - bool isBullish = IsBullish(dir); - - // - XBoxZone tmp[]; - XBoxZone last = youngest; - while (IsValidSize(count)) - { - // - // Detect Youngest of Collection ... - int idx = GetYoungest(items); - XBoxZone iChild = items[idx]; - ArrayRemove( - items, - idx, - 1 // - ); - count = ArraySize(items); - - // - // Check Direction Must be Same ... - ENUM_X_DIRECTION iDir = iChild.dir; - bool isSameDir = dir == iDir; - if (!isSameDir) - { - continue; - } - - // - // Check Creation time Sequence ... - bool isFromPassed = last.from > iChild.from; - if (!isFromPassed) - { - continue; - } - - // - // Check Order Block Place ... - bool isPlacePassed = - isBullish - ? IsBoxBelow( - iChild, - last, - true // Ignore Inside ... - ) - : IsBoxAbove( - iChild, - last, - true // Ignore Inside ... - ); - if (!isPlacePassed) - { - continue; - } - - // - // Update Last OB ... - last = iChild; - AddRef( - iChild, - tmp // - ); - - // - } - - // - // Update Ordered Sorted Order Blocks ... - count = ArraySize(tmp); - if (IsValidSize(count)) - { - // - Copy( - tmp, - items // - ); - } -} - -/** - * Extract Order Flows Swing Points ... + * Check Trading Conditions based on Specified Box ... * - * @param type: ENUM_X_SWING_TYPE member ... - * @param swings: double Collection ... + * @param box: XBoxZone instance Reference, specified Box for Checking Conditions ... + * @param appliedBox: XBoxZone instance Reference, hold's Selected Box inside Parent which trading conditions happens on it ... + * @param swingBar: XOHCL instance Reference, holds Swing Bar if Exists ... + * @param breakerBar: XOHCL instance Reference, holds Breaker Bar if Exists ... + * @param rejectionBar: XOHCL instance Reference, holds Rejection Bar if Exists ... + * @param momentumBar: XOHCL instance Reference, holds Momentum Bar if Exists ... + * @param state: XPOIState instance Reference, provides requirement zone's for check Conditions ... + * @param barIndex: int, Specified Bar Index ... + * @param forPeriod: ENUM_TIMEFRAMES member, Specified Conditions Checking Period ... * - * @return ( int ) + * @return ( bool ) */ -int ExtractSwingPoints( - ENUM_X_SWING_TYPE type, - XCOrderBlock *&orderBlocks[], - XSwingPoint &swings[] // +bool CheckBoxForTradeConditions( + XBoxZone &box, + XBoxZone &appliedBox, + XOHCL &swingBar, + XOHCL &breakerBar, + XOHCL &rejectionBar, + XOHCL &momentumBar, + XPOIState &state, + int barIndex = 0, + ENUM_TIMEFRAMES forPeriod = NULL // ) { // - int result = 0; + bool result = false; // - Clean(swings); + swingBar.Clean(); + appliedBox.Clean(); + breakerBar.Clean(); + momentumBar.Clean(); + rejectionBar.Clean(); // - int count = ArraySize(orderBlocks); + if (barIndex < 0) + { + barIndex = 0; + } // - if (type == X_NO_SWING || - !IsValidSize(count)) + result = box.IsValid() && + state.IsValid() && + state.HasChild(); + if (!result) { return result; } // - bool lookingForSwingLows = type == X_SWING_LOW; + if (!IsValid(forPeriod)) + { + forPeriod = box.period; + } // - for (int i = 0; i < count; i++) + string symbol = box.symbol; + datetime cTime = iTime( + symbol, + forPeriod, + barIndex // + ); + + // + ENUM_X_DIRECTION forDir = box.dir; + result = HasDirection(forDir); + if (!result) + { + return result; + } + + // + bool isBullish = IsBullish(forDir); + + // + int supportsCount = 0; + bool hasSupports = false; + XCSupportZone *supports[]; + + // + int resistancesCount = 0; + bool hasResistances = false; + XCResistanceZone *resistances[]; + + // + XBoxZone supResBoxes[]; + int supresBoxesCount = 0; + bool hasSupResBoxes = false; + + // + int count = 0; + bool has = false; + + // + has = state.HasSupportZones(); + if (has) { // - XCOrderBlock *iOB = orderBlocks[i]; - - // - string iSymbol = iOB.GetSymbol(); - ENUM_TIMEFRAMES iPeriod = iOB.GetPeriod(); - - // - int fromIndex = iBarShift( - iSymbol, - iPeriod, - iOB.From() // - ); - - // - fromIndex++; - - // - double iValue = 0; - datetime iVTime = NULL; - if (lookingForSwingLows) + count = state.CountSupportZones(); + for (int i = 0; i < count; i++) { // - int idx = iLowest( - iSymbol, - iPeriod, - MODE_LOW, - fromIndex // + XCSupportZone *iZone = state.supportZones[i]; + + // + iZone.To(cTime); + + // + XBoxZone iBox; + bool hasBox = ToBox( + iBox, + iZone // + ); + if (!hasBox) + { + // + iBox.Clean(); + continue; + } + + // + // Check From ... + bool isInside = IsBoxInside( + iBox, + box // + ); + if (!isInside) + { + // + iBox.Clean(); + continue; + } + + // + Add( + iZone, + supports // ); // - if (IsValidIndex(idx)) + AddRef( + iBox, + supResBoxes // + ); + + // + iBox.Clean(); + } + + // + supportsCount = ArraySize(supports); + hasSupports = IsValidSize(supportsCount); + + // + supresBoxesCount = ArraySize(supResBoxes); + hasSupResBoxes = IsValidSize(supresBoxesCount); + } + + // + has = state.HasResistanceZones(); + if (has) + { + // + count = state.CountResistanceZones(); + for (int i = 0; i < count; i++) + { + // + XCResistanceZone *iZone = state.resistanceZones[i]; + + // + iZone.To(cTime); + + // + XBoxZone iBox; + bool hasBox = ToBox( + iBox, + iZone // + ); + if (!hasBox) { // - iValue = iLow( - iSymbol, - iPeriod, - idx // - ); + iBox.Clean(); + continue; + } + + // + // Check From ... + bool isInside = IsBoxInside( + iBox, + box // + ); + if (!isInside) + { + // + iBox.Clean(); + continue; + } + + // + Add( + iZone, + resistances // + ); + + // + AddRef( + iBox, + supResBoxes // + ); + + // + iBox.Clean(); + } + + // + resistancesCount = ArraySize(resistances); + hasResistances = IsValidSize(resistancesCount); + + // + supresBoxesCount = ArraySize(supResBoxes); + hasSupResBoxes = IsValidSize(supresBoxesCount); + } + + // + result = hasSupResBoxes; + if (!result) + { + // + Clean(supports); + Clean(resistances); + Clean(supResBoxes); + + // + return result; + } + + // + // Detect Bars ... + + // + XOHCL zBar; + result = zBar.Init( + symbol, + forPeriod, + barIndex // + ); + if (!result) + { + // + zBar.Clean(); + Clean(supports); + Clean(resistances); + Clean(supResBoxes); + + // + return result; + } + + // + XOHCL cBar; + result = zBar.GetPreviousBar(cBar); + if (!result) + { + // + zBar.Clean(); + cBar.Clean(); + Clean(supports); + Clean(resistances); + Clean(supResBoxes); + + // + return result; + } + + // + XOHCL pBar; + result = cBar.GetPreviousBar(pBar); + if (!result) + { + // + zBar.Clean(); + cBar.Clean(); + pBar.Clean(); + Clean(supports); + Clean(resistances); + Clean(supResBoxes); + + // + return result; + } + + // + XOHCL ppBar; + result = pBar.GetPreviousBar(ppBar); + if (!result) + { + // + zBar.Clean(); + cBar.Clean(); + pBar.Clean(); + ppBar.Clean(); + Clean(supports); + Clean(resistances); + Clean(supResBoxes); + + // + return result; + } + // + // Check Conditions ... + + // + // Detect Start Senario ... + + // + double fiboPressureLevel = GetFiboLevelValue(X_FIBO_LEVEL_382); + + // + double fiboUpDown = GetFibonacciLevel( + pBar.high, + pBar.low, + X_FIBO_LEVEL_382, + X_DIRECTION_BEARISH // + ); + double fiboDownUp = GetFibonacciLevel( + pBar.high, + pBar.low, + X_FIBO_LEVEL_382, + X_DIRECTION_BULLISH // + ); + + // + bool hasFiboToUpPressure = + fiboDownUp > 0 && + fiboDownUp <= pBar.GetDown(); + bool hasFiboToDownPressure = + fiboUpDown > 0 && + fiboUpDown >= pBar.GetUp(); + + // + int selectedBoxIDX = -1; + for (int j = 0; j < supresBoxesCount; j++) + { + // + double appliedPrice = + isBullish + ? supResBoxes[j].lower + : supResBoxes[j].upper; + + // + // Check Swing Low ... + bool isSwingLow = + // + pBar.low < ppBar.low && + pBar.low < cBar.low && + zBar.open > pBar.low && + // + appliedPrice > pBar.low && + appliedPrice < pBar.GetDown() + // + ; + bool isPressuredSwingLow = + isSwingLow && + hasFiboToUpPressure; + bool isPressuredStrongSwingLow = + pBar.IsBullish() && + isPressuredSwingLow; + + // + bool isSwingHigh = + // + pBar.high > ppBar.high && + pBar.high > cBar.high && + zBar.open < pBar.high && + // + appliedPrice < pBar.high && + appliedPrice > pBar.GetUp() + // + ; + bool isPressuredSwingHigh = + isSwingHigh && + hasFiboToDownPressure; + bool isPressuredStrongSwingHigh = + pBar.IsBearish() && + isPressuredSwingHigh; + + // + bool hasValidSwing = + isBullish + ? isSwingLow + : isSwingHigh; + bool hasValidPressuredSwing = + isBullish + ? isPressuredSwingLow + : isPressuredSwingHigh; + bool hasValidPressuredStrongSwing = + isBullish + ? isPressuredStrongSwingLow + : isPressuredStrongSwingHigh; + if (hasValidSwing) + { + swingBar = pBar; + } + if (hasValidPressuredSwing) + { + swingBar = pBar; + } + if (hasValidPressuredStrongSwing) + { + swingBar = pBar; + } + + // + bool isCBarBreaked = IsBarBreak( + appliedPrice, + forDir, + cBar // + ); + if (isCBarBreaked) + { + breakerBar = cBar; + } + bool isPBarBreaked = IsBarBreak( + appliedPrice, + forDir, + pBar // + ); + if (!isCBarBreaked && isPBarBreaked) + { + breakerBar = pBar; + } + else + { + isPBarBreaked = false; + } + bool isPPBarBreaked = IsBarBreak( + appliedPrice, + forDir, + ppBar // + ); + if (!isCBarBreaked && + !isPBarBreaked && + isPPBarBreaked) + { + breakerBar = ppBar; + } + else + { + isPPBarBreaked = false; + } + bool isBoxBreaked = isCBarBreaked || + isPBarBreaked || + isPPBarBreaked; + + // + bool isCBarRejected = IsBarReject( + appliedPrice, + forDir, + cBar // + ); + if (isCBarRejected) + { + rejectionBar = cBar; + } + bool isPBarRejected = IsBarReject( + appliedPrice, + forDir, + pBar // + ); + if (!isCBarRejected && isPBarRejected) + { + rejectionBar = pBar; + } + else + { + isPBarRejected = false; + } + bool isPPBarRejected = IsBarReject( + appliedPrice, + forDir, + ppBar // + ); + if (!isCBarRejected && + !isPBarRejected && + isPPBarRejected) + { + rejectionBar = ppBar; + } + else + { + isPPBarRejected = false; + } + bool isBoxRejected = isCBarRejected || + isPBarRejected || + isPPBarRejected; + + // + bool hasRejectionBar = false; + if (isBullish) + { + // + count = state.CountBullishRejectionBars(); + for (int i = 0; i < count; i++) + { + // + XCRejectionBar *iZone = state.bullishRejectionBars[i]; // - iVTime = iTime( - iSymbol, - iPeriod, - idx // - ); + XOHCL iBar; + bool isFilled = iZone.FillBar(iBar); + if (!isFilled) + { + continue; + } + + // + int iBarIndex = iBar.Index(); + + // + hasRejectionBar = + // + (iBarIndex == cBar.Index() || + iBarIndex == pBar.Index()) + // + ; + if (hasRejectionBar) + { + // + if (!rejectionBar.IsValid()) + { + rejectionBar = iBar; + } + + // + break; + } } } else { // - int idx = iHighest( - iSymbol, - iPeriod, - MODE_HIGH, - fromIndex // - ); - - // - if (IsValidIndex(idx)) + count = state.CountBearishRejectionBars(); + for (int i = 0; i < count; i++) { // - iValue = iHigh( - iSymbol, - iPeriod, - idx // - ); + XCRejectionBar *iZone = state.bearishRejectionBars[i]; // - iVTime = iTime( - iSymbol, - iPeriod, - idx // - ); + XOHCL iBar; + bool isFilled = iZone.FillBar(iBar); + if (!isFilled) + { + continue; + } + + // + int iBarIndex = iBar.Index(); + + // + hasRejectionBar = + // + (iBarIndex == cBar.Index() || + iBarIndex == pBar.Index()) + // + ; + if (hasRejectionBar) + { + // + if (!rejectionBar.IsValid()) + { + rejectionBar = iBar; + } + + // + break; + } } } // - if (iValue > 0) + bool hasMomentumBar = false; + if (isBullish) { // - XSwingPoint iSwingP; - - // - iSwingP.type = type; - iSwingP.time = iVTime; - iSwingP.swing = iValue; - iSwingP.symbol = iSymbol; - iSwingP.period = iPeriod; - - // - if (iSwingP.IsValid()) + count = state.CountBullishMomentumBars(); + for (int i = 0; i < count; i++) { // - AddRef( - iSwingP, - swings // - ); - } + XCMomentumBar *iZone = state.bullishMomentumBars[i]; + // + XOHCL iBar; + bool isFilled = iZone.FillBar(iBar); + if (!isFilled) + { + continue; + } + + // + int iBarIndex = iBar.Index(); + + // + hasMomentumBar = + // + (iBarIndex == cBar.Index() || + iBarIndex == pBar.Index()) + // + ; + if (hasMomentumBar) + { + // + if (!momentumBar.IsValid()) + { + momentumBar = iBar; + } + + // + break; + } + } + } + else + { // - iSwingP.Clean(); + count = state.CountBearishMomentumBars(); + for (int i = 0; i < count; i++) + { + // + XCMomentumBar *iZone = state.bearishMomentumBars[i]; + + // + XOHCL iBar; + bool isFilled = iZone.FillBar(iBar); + if (!isFilled) + { + continue; + } + + // + int iBarIndex = iBar.Index(); + + // + hasMomentumBar = + // + (iBarIndex == cBar.Index() || + iBarIndex == pBar.Index()) + // + ; + if (hasMomentumBar) + { + // + if (!momentumBar.IsValid()) + { + momentumBar = iBar; + } + + // + break; + } + } + } + + // + bool hasSwing = false; + if (isBullish) + { + // + count = state.CountSwingLows(); + for (int i = 0; i < count; i++) + { + // + XCSwing *iSwing = state.swingLows[i]; + + // + XOHCL iBar; + bool isFilled = iSwing.FillBar(iBar); + if (!isFilled) + { + continue; + } + + // + int iBarIndex = iBar.Index(); + + // + hasSwing = + // + (iBarIndex == cBar.Index() || + iBarIndex == pBar.Index()) + // + ; + if (hasSwing) + { + // + if (!swingBar.IsValid()) + { + swingBar = iBar; + } + + // + break; + } + } + } + else + { + // + count = state.CountSwingHighs(); + for (int i = 0; i < count; i++) + { + // + XCSwing *iSwing = state.swingHighs[i]; + + // + XOHCL iBar; + bool isFilled = iSwing.FillBar(iBar); + if (!isFilled) + { + continue; + } + + // + int iBarIndex = iBar.Index(); + + // + hasSwing = + // + (iBarIndex == cBar.Index() || + iBarIndex == pBar.Index()) + // + ; + if (hasSwing) + { + // + if (!swingBar.IsValid()) + { + swingBar = iBar; + } + + // + break; + } + } + } + + // + bool hasRequiredValidations = + // + (hasRejectionBar || + hasMomentumBar) + // + || + // + (hasRejectionBar || + hasSwing) + // + || + // + (hasMomentumBar || + hasSwing) + // + ; + + // + result = + // + (isBoxBreaked && + (hasRequiredValidations || + hasValidPressuredSwing)) + // + || + // + (isBoxRejected && + (hasRequiredValidations || + hasValidPressuredSwing)) + // + ; + if (result) + { + // + selectedBoxIDX = j; + break; } } // - result = ArraySize(swings); + result = + result && + (isBullish + ? zBar.open > box.upper + : zBar.open < box.lower) && + IsValidIndex(selectedBoxIDX); + if (result) + { + appliedBox = supResBoxes[selectedBoxIDX]; + } + + // + zBar.Clean(); + cBar.Clean(); + pBar.Clean(); + ppBar.Clean(); + Clean(supports); + Clean(resistances); + Clean(supResBoxes); // return result; diff --git a/X121SMCEA/Libraries/x-121.smc.lib.mq5 b/X121SMCEA/Libraries/x-121.smc.lib.mq5 index 085aac6d..d631a4f4 100644 --- a/X121SMCEA/Libraries/x-121.smc.lib.mq5 +++ b/X121SMCEA/Libraries/x-121.smc.lib.mq5 @@ -36,7 +36,6 @@ const string X121SMCStrategyToken = "X121SMC"; // const string X121SMCXWZToken = "X121XWZ"; -const string X121SMCXSupDemOBSToken = "X121XSupDemOBS"; // // X121 SMC Providers ... @@ -45,7 +44,6 @@ enum ENUM_X_121_SMC_PROVIDERS // X_121_SMC_PROVIDER_NONE, X_121_SMC_PROVIDER_XWZ, - X_121_SMC_PROVIDER_XSUPDEMOBS, }; // @@ -698,11 +696,6 @@ string ToString(ENUM_X_121_SMC_PROVIDERS value) case X_121_SMC_PROVIDER_XWZ: result = X121SMCXWZToken; break; - - // - case X_121_SMC_PROVIDER_XSUPDEMOBS: - result = X121SMCXSupDemOBSToken; - break; } // @@ -732,10 +725,6 @@ ENUM_X_121_SMC_PROVIDERS ParseProvider(string value) { result = X_121_SMC_PROVIDER_XWZ; } - else if (Contains(X121SMCXSupDemOBSToken, value)) - { - result = X_121_SMC_PROVIDER_XSUPDEMOBS; - } // 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 96b373ac..7e0ff31d 100644 --- a/X121SMCEA/Signals/x-121.smc.xwz.signal.class.mq5 +++ b/X121SMCEA/Signals/x-121.smc.xwz.signal.class.mq5 @@ -538,64 +538,9 @@ class XCX121SMCXWZSignalDetector : public XCBase ); } - // - result = hasStartZone; - if (!result) - { - // - Clean(visionPoiEvents); - Clean(analysePoiEvents); - Clean(decisionPoiEvents); - Clean(visionCycleEvents); - Clean(analyseCycleEvents); - Clean(decisionCycleEvents); - Clean(consolidationPoiEvents); - Clean(consolidationCycleEvents); - - // - visionState.Clean(); - analyseState.Clean(); - decisionZBar.Clean(); - decisionCBar.Clean(); - decisionPBar.Clean(); - decisionState.Clean(); - visionConditions.Clean(); - analyseConditions.Clean(); - visionXConditions.Clean(); - consolidationState.Clean(); - decisionConditions.Clean(); - analyseXConditions.Clean(); - decisionXConditions.Clean(); - consolidationConditions.Clean(); - consolidationXConditions.Clean(); - - // - RemoveDraws(); - RemoveWorkingZoneDraws(); - - // - mConditions.Clean(); - - // - return result; - } - // mConditions.UpdateTo(cTime); - // - // Detect Start Zone Conditions ... - bool hasCondition = mConditions - .startZone - .HasCondition( - decisionState, - zIndex, - period // - ); - ENUM_X_DIRECTION conditionsDir = mConditions - .startZone - .GetDirection(); - // // Detect Condition Priority ... ENUM_X121SMC_XWZ_PRIORITY bullishPriority; @@ -617,8 +562,77 @@ class XCX121SMCXWZSignalDetector : public XCBase ? canLookupShort : false; + // + bool hasCondition = false; + ENUM_X_DIRECTION conditionsDir = X_DIRECTION_NONE; + + // + // Detect Start Zone Based Conditions ... + if (hasStartZone) + { + // + // Detect Start Zone Conditions ... + hasCondition = mConditions + .startZone + .HasCondition( + decisionState, + zIndex, + NULL // period // + ); + conditionsDir = mConditions + .startZone + .GetDirection(); + } + + // + RemoveWorkingZoneDraws(); + DrawWorkingZone(mConditions, visionCycleHelper.mPOIDrawer); + + // + // Detect Supply and Deman Zone Based Conditions ... + if (!hasCondition) + { + // + bool isPriceInsideSupplyZone = + bearishPriority == X121SMC_XWZ_PRIORITY_STRONG_HIGH; + + // + bool isPriceInsideDemandZone = + bullishPriority == X121SMC_XWZ_PRIORITY_STRONG_HIGH; + + // + bool isPriceInsideSupDem = isPriceInsideSupplyZone || + isPriceInsideDemandZone; + if (isPriceInsideSupDem) + { + // + hasCondition = mConditions.HasWorkingZoneConditions( + conditionsDir, + decisionState // + ); + } + } + + // + isBullish = IsBullish(conditionsDir); + isBearish = IsBearish(conditionsDir); + + // + double reward; + double amountPercent; + ENUM_X121SMC_XWZ_PRIORITY priority = + isBullish + ? bullishPriority + : bearishPriority; + bool hasRewardAmount = CalculateRiskReward( + priority, + reward, + amountPercent // + ); + // result = hasCondition && + hasRewardAmount && isPriorityPassed && trend == conditionsDir; if (!result) @@ -658,14 +672,60 @@ class XCX121SMCXWZSignalDetector : public XCBase } // + // Apply Traget ... + switch (priority) + { + // + case X121SMC_XWZ_PRIORITY_STRONG_HIGH: + // + target = + isBullish + ? mConditions.workingZone.quarter3 + : mConditions.workingZone.quarter1; + break; + + // + case X121SMC_XWZ_PRIORITY_HIGH: + // + target = + isBullish + ? mConditions.workingZone.quarter3 + : mConditions.workingZone.quarter1; + break; + + // + case X121SMC_XWZ_PRIORITY_REGULAR: + // + target = + isBullish + ? mConditions.workingZone.quarter2 + : mConditions.workingZone.quarter2; + break; + + // + case X121SMC_XWZ_PRIORITY_LOW: + // + target = + isBullish + ? mConditions.workingZone.quarter1 + : mConditions.workingZone.quarter3; + break; + + // + default: + target = 0; + break; + } + + // + mConditions.reward = reward; + mConditions.target = target; mConditions.setupTime = cTime; + mConditions.priority = priority; mConditions.dir = conditionsDir; + mConditions.amountPercent = amountPercent; mConditions.pivot = mConditions.GetExit(); mConditions.point = mConditions.GetPoint(); - isBullish = mConditions.startZone.IsBullish(); - isBearish = mConditions.startZone.IsBearish(); - result = isBullish || - isBearish; // mConditions.UpdateTo(cTime); @@ -869,18 +929,16 @@ class XCX121SMCXWZSignalDetector : public XCBase // isBullish = // - isBullish - // && - // isPointBreaked + isBullish && + isPointBreaked // ; // isBearish = // - isBearish - // && - // isPointBreaked + isBearish && + isPointBreaked // ; @@ -939,7 +997,7 @@ class XCX121SMCXWZSignalDetector : public XCBase // double iAtr = decisionXConditions.atrBuffer[1]; - iAtr *= 1.5; + iAtr *= 2; // double slsMin = GetMin(sls); @@ -2701,30 +2759,37 @@ class XCX121SMCXWZSignalDetector : public XCBase switch (priority) { // - case X121SMC_XWZ_PRIORITY_HIGH: + case X121SMC_XWZ_PRIORITY_STRONG_HIGH: // reward = 6; amountPercent = 2; break; + // + case X121SMC_XWZ_PRIORITY_HIGH: + // + reward = 4; + amountPercent = 2; + break; + // case X121SMC_XWZ_PRIORITY_REGULAR: // - reward = 6; + reward = 3; amountPercent = 1.5; break; // case X121SMC_XWZ_PRIORITY_LOW: // - reward = 4; + reward = 2; amountPercent = 1; break; // case X121SMC_XWZ_PRIORITY_WEAK: // - reward = 2; + reward = 1; amountPercent = 0.5; break; } diff --git a/X121SMCEA/Signals/x-121.smc.xwz.signal.lib.mq5 b/X121SMCEA/Signals/x-121.smc.xwz.signal.lib.mq5 index 62903257..c68def31 100644 --- a/X121SMCEA/Signals/x-121.smc.xwz.signal.lib.mq5 +++ b/X121SMCEA/Signals/x-121.smc.xwz.signal.lib.mq5 @@ -678,6 +678,7 @@ struct X121SMCXWZZone isBullish ? supResBoxes[j].lower : supResBoxes[j].upper; + // // Check Swing Low ... bool isSwingLow = @@ -1167,6 +1168,13 @@ struct X121SMCXWZWorkingZone datetime to; datetime from; + // + XOHCL swingBar; + XOHCL breakerBar; + XOHCL momentumBar; + XOHCL rejectionBar; + XBoxZone appliedBox; + // X121SMCXWZWorkingZone() { @@ -1190,10 +1198,24 @@ struct X121SMCXWZWorkingZone symbol = NULL; period = NULL; + // + CleanConditionBars(); + // ZeroMemory(this); } + // + void CleanConditionBars() + { + // + swingBar.Clean(); + breakerBar.Clean(); + appliedBox.Clean(); + momentumBar.Clean(); + rejectionBar.Clean(); + } + // bool IsValid() { @@ -2004,7 +2026,7 @@ struct X121SMCStrategyXWZSignalConditions // hasTrend = // - IsValid(supplyTouch) && + IsValid(supplyTouch) || IsValid(demandTouch) // ; @@ -2037,6 +2059,10 @@ struct X121SMCStrategyXWZSignalConditions // // Find Order Block and FVG for Trend Approve ... + // + bool isBullishTrendApproved = false; + bool isBearishTrendApproved = false; + // // Now We Have to Detect at least One OrderBlock with FVG ... // for Trend Approvement ... @@ -2054,192 +2080,205 @@ struct X121SMCStrategyXWZSignalConditions XCOrderBlock *ob = NULL; // - if (hasBullishTrend) + has = mtfState.HasBullishOrderBlocks(); + count = mtfState.CountBullishOrderBlocks(); + + // + if (has) { // - has = mtfState.HasBullishOrderBlocks(); - count = mtfState.CountBullishOrderBlocks(); - - // - if (has) + // Check Order Block ... + for (int i = 0; i < count; i++) { // - // Check Order Block ... - for (int i = 0; i < count; i++) + XCOrderBlock *iOB = mtfState.bullishOrderBlocks[i]; + + // + iOB.To(cTime); + + // + // Check From Passes ... + bool isFromPassed = iOB.From() > demandZone.From(); + if (!isFromPassed) + { + continue; + } + + // + // Must inside DemandZone ... + bool isInsideDemand = IsInsideDiff( + iOB, + demandZone // + ); + if (!isInsideDemand) + { + continue; + } + + // + // Check Started ... + XOHCL startedBar; + ENUM_X_DIRECTION startedDir; + bool isStarted = iOB.IsStarted( + X_DIRECTION_BULLISH, + startedBar, + startedDir // + ); + if (!isStarted) { // - XCOrderBlock *iOB = mtfState.bullishOrderBlocks[i]; - - // - iOB.To(cTime); - - // - // Check From Passes ... - bool isFromPassed = iOB.From() > demandZone.From(); - if (!isFromPassed) - { - continue; - } - - // - // Must inside DemandZone ... - bool isInsideDemand = IsInsideDiff( - iOB, - demandZone // - ); - if (!isInsideDemand) - { - continue; - } - - // - // Check Started ... - XOHCL startedBar; - ENUM_X_DIRECTION startedDir; - bool isStarted = iOB.IsStarted( - X_DIRECTION_BULLISH, - startedBar, - startedDir // - ); - if (!isStarted) - { - // - startedBar.Clean(); - continue; - } - - // - // Converts to Box ... - XBoxZone obBox; - bool hasOBBox = ToBox( - obBox, - iOB // - ); - if (!hasOBBox) - { - // - obBox.Clean(); - startedBar.Clean(); - continue; - } - - // - // Check Zone Must not Used before ... - bool isUsed = IsBoxUsed( - obBox, - startedBar.Index() - 1, - zIndex // - ); - if (isUsed) - { - // - obBox.Clean(); - startedBar.Clean(); - continue; - } - - // - ob = iOB; + startedBar.Clean(); + continue; + } + // + // Converts to Box ... + XBoxZone obBox; + bool hasOBBox = ToBox( + obBox, + iOB // + ); + if (!hasOBBox) + { // obBox.Clean(); startedBar.Clean(); - - // - break; + continue; } // - // Detect Fair Value Gap ... - if (ob != NULL && - ob.IsValid()) + // Check Zone Must not Used before ... + bool isUsed = IsBoxUsed( + obBox, + startedBar.Index() - 1, + zIndex // + ); + if (isUsed) { // - has = stfState.HasBullishFairValueGaps(); - count = stfState.CountBullishFairValueGaps(); - if (has) + obBox.Clean(); + startedBar.Clean(); + continue; + } + + // + ob = iOB; + + // + obBox.Clean(); + startedBar.Clean(); + + // + break; + } + + // + // Detect Fair Value Gap ... + if (ob != NULL && + ob.IsValid()) + { + // + has = stfState.HasBullishFairValueGaps(); + count = stfState.CountBullishFairValueGaps(); + if (has) + { + // + // Check Fir Value Gap ... + for (int i = 0; i < count; i++) { // - // Check Fir Value Gap ... - for (int i = 0; i < count; i++) + XCFVG *iFVG = stfState.bullishFairValueGaps[i]; + + // + iFVG.To(cTime); + + // + // Check From Passes ... + bool isFromPassed = iFVG.From() > ob.From(); + if (!isFromPassed) + { + continue; + } + + // + // Check Started ... + XOHCL startedBar; + ENUM_X_DIRECTION startedDir; + bool isStarted = iFVG.IsStarted( + X_DIRECTION_BULLISH, + startedBar, + startedDir // + ); + if (!isStarted) { // - XCFVG *iFVG = stfState.bullishFairValueGaps[i]; - - // - iFVG.To(cTime); - - // - // Check From Passes ... - bool isFromPassed = iFVG.From() > ob.From(); - if (!isFromPassed) - { - continue; - } - - // - // Check Started ... - XOHCL startedBar; - ENUM_X_DIRECTION startedDir; - bool isStarted = iFVG.IsStarted( - X_DIRECTION_BULLISH, - startedBar, - startedDir // - ); - if (!isStarted) - { - // - startedBar.Clean(); - continue; - } - - // - // Converts to Box ... - XBoxZone fvgBox; - bool hasFVGBox = ToBox( - fvgBox, - iFVG // - ); - if (!hasFVGBox) - { - // - fvgBox.Clean(); - startedBar.Clean(); - continue; - } - - // - // Check Inside Order Block ... - bool isInside = IsInsideDiff( - iFVG, - ob, - true // Force Side Out ... - ); - if (!isInside) - { - continue; - } - - // - fvg = iFVG; + startedBar.Clean(); + continue; + } + // + // Converts to Box ... + XBoxZone fvgBox; + bool hasFVGBox = ToBox( + fvgBox, + iFVG // + ); + if (!hasFVGBox) + { // fvgBox.Clean(); startedBar.Clean(); - - // - break; + continue; } - } - else - { + // - ob = NULL; + // Check Inside Order Block ... + bool isInside = IsInsideDiff( + iFVG, + ob, + true // Force Side Out ... + ); + if (!isInside) + { + continue; + } + + // + fvg = iFVG; + + // + fvgBox.Clean(); + startedBar.Clean(); + + // + break; } } + else + { + // + ob = NULL; + } } + + // + if (ob != NULL && + fvg != NULL) + { + // + orderBlock = ob; + fairValueGap = fvg; + } + + // + hasOrderBlock = HasOrderBlock(); + hasFairValueGap = HasFairValueGap(); + isBullishTrendApproved = hasOrderBlock && + hasFairValueGap; } - else if (hasBearishTrend) + + // + if (!isBullishTrendApproved) { // has = mtfState.HasBearishOrderBlocks(); @@ -2422,28 +2461,32 @@ struct X121SMCStrategyXWZSignalConditions ob = NULL; } } + + // + if (ob != NULL && + fvg != NULL) + { + // + orderBlock = ob; + fairValueGap = fvg; + } + + // + hasOrderBlock = HasOrderBlock(); + hasFairValueGap = HasFairValueGap(); + isBearishTrendApproved = hasOrderBlock && + hasFairValueGap; } } - - // - if (ob != NULL && - fvg != NULL) - { - // - orderBlock = ob; - fairValueGap = fvg; - } - - // - hasOrderBlock = HasOrderBlock(); - hasFairValueGap = HasFairValueGap(); } // // Check Trend Approved ... bool isTrendApproved = hasOrderBlock && - hasFairValueGap; + hasFairValueGap && + (isBullishTrendApproved || + isBearishTrendApproved); result = isTrendApproved; if (!result) { @@ -2634,7 +2677,7 @@ struct X121SMCStrategyXWZSignalConditions // result = // - IsValid(supplyTouch) && + IsValid(supplyTouch) || IsValid(demandTouch) // ; @@ -2819,10 +2862,54 @@ struct X121SMCStrategyXWZSignalConditions // bool hasOBFVG = startZone.HasOB() && startZone.HasFVG(); + bool isOBStarted = false; + bool isFVGStarted = false; + bool isOBActivated = false; + bool isFVGActivated = false; bool isOBInsideFVG = false; bool isFVGInsideOB = false; if (hasOBFVG) { + // + + // + ENUM_X_DIRECTION forDir = startZone.ob.GetDirection(); + + // + XOHCL startedBar; + ENUM_X_DIRECTION startedDir; + + // + isOBStarted = startZone.ob.IsStarted( + forDir, + startedBar, + startedDir // + ); + + // + isOBActivated = startZone.ob.IsActivated( + forDir, + startedBar, + startedDir // + ); + + // + forDir = startZone.fvg.GetDirection(); + + // + isFVGStarted = startZone.fvg.IsStarted( + forDir, + startedBar, + startedDir // + ); + + // + isFVGActivated = startZone.fvg.IsActivated( + forDir, + startedBar, + startedDir // + ); + // isOBInsideFVG = IsInsideDiff( @@ -2857,10 +2944,17 @@ struct X121SMCStrategyXWZSignalConditions startZone.ob, true // IgnoreInside )); + + // + startedBar.Clean(); } // result = + isOBStarted && + isFVGStarted && + isOBActivated && + isFVGActivated && startZone.IsValid() && (isOBInsideFVG || isFVGInsideOB) && @@ -3008,6 +3102,150 @@ struct X121SMCStrategyXWZSignalConditions cBar.Clean(); } + // + bool HasWorkingZoneConditions( + ENUM_X_DIRECTION &conditionsDir, + XPOIState &state, + int barIndex = 0, + ENUM_TIMEFRAMES forPeriod = NULL // + ) + { + // + bool result = false; + + // + if (barIndex < 0) + { + barIndex = 0; + } + + // + conditionsDir = X_DIRECTION_NONE; + + // + result = HasWorkingZone(); + if (!result) + { + return result; + } + + // + XBoxZone appliedBox; + + // + // Clean Condition Bars ... + workingZone.CleanConditionBars(); + + // + // Validate ... + result = state.IsValid() && + state.HasChild(); + if (!result) + { + // + workingZone.CleanConditionBars(); + return result; + } + + // + if (!IsValid(forPeriod)) + { + forPeriod = period; + } + + // + datetime cTime = iTime( + symbol, + forPeriod, + barIndex // + ); + + // + // Check Supply Zone ... + + // + XBoxZone supplyBox; + bool hasSupplyBox = + supplyZone != NULL && + supplyZone.IsValid() && + ToBox( + supplyBox, + supplyZone // + ); + if (hasSupplyBox) + { + // + result = CheckBoxForTradeConditions( + supplyBox, + appliedBox, + workingZone.swingBar, + workingZone.breakerBar, + workingZone.rejectionBar, + workingZone.momentumBar, + state, + barIndex, + forPeriod // + ); + + // + if (result) + { + conditionsDir = X_DIRECTION_BEARISH; + } + } + + // + // Check Demand Zone ... + XBoxZone demandBox; + bool hasDemandBox = false; + if (!result) + { + // + hasDemandBox = + demandZone != NULL && + demandZone.IsValid() && + ToBox( + demandBox, + demandZone // + ); + if (hasDemandBox) + { + // + result = CheckBoxForTradeConditions( + demandBox, + appliedBox, + workingZone.swingBar, + workingZone.breakerBar, + workingZone.rejectionBar, + workingZone.momentumBar, + state, + barIndex, + forPeriod // + ); + + // + if (result) + { + conditionsDir = X_DIRECTION_BULLISH; + } + } + } + + // + if (!result) + { + workingZone.CleanConditionBars(); + } + + // + supplyBox.Clean(); + demandBox.Clean(); + appliedBox.Clean(); + + // + return result; + } + // double GetEntry() { diff --git a/X121SMCEA/Strategy/x-121.smc.strategy.class.mq5 b/X121SMCEA/Strategy/x-121.smc.strategy.class.mq5 index 6e50394d..8466105d 100644 --- a/X121SMCEA/Strategy/x-121.smc.strategy.class.mq5 +++ b/X121SMCEA/Strategy/x-121.smc.strategy.class.mq5 @@ -27,7 +27,6 @@ #include "../Classes/x-121.smc.market.cycle.helper.class.mq5" // -#include "../Signals/x-121.smc.xsupdemobs.signal.class.mq5" #include "../Signals/x-121.smc.xwz.signal.class.mq5" // @@ -43,9 +42,7 @@ class XCX121SMCStrategy : public XCX121SMCBaseStrategy // // Props ... bool useXWZSignal; - bool useXSupDemOBSSignal; XCX121SMCXWZSignalDetector *mXWZSignalDetector; - XCX121SMCXSupDemOBSSignalDetector *mXSupDemOBSSignalDetector; // // Constructor(s) ... @@ -62,7 +59,6 @@ class XCX121SMCStrategy : public XCX121SMCBaseStrategy // mXWZSignalDetector = new XCX121SMCXWZSignalDetector(); - mXSupDemOBSSignalDetector = new XCX121SMCXSupDemOBSSignalDetector(); } // @@ -110,12 +106,6 @@ class XCX121SMCStrategy : public XCX121SMCBaseStrategy */ void Destroy() override { - // - delete mDecisionCycleHelper; - delete mAnalyseCycleHelper; - delete mConsolidationCycleHelper; - delete mVisionCycleHelper; - // ZeroMemory(mDecisionCycleHelper); ZeroMemory(mAnalyseCycleHelper); @@ -123,12 +113,7 @@ class XCX121SMCStrategy : public XCX121SMCBaseStrategy ZeroMemory(mVisionCycleHelper); // - delete mXWZSignalDetector; ZeroMemory(mXWZSignalDetector); - - // - delete mXSupDemOBSSignalDetector; - ZeroMemory(mXSupDemOBSSignalDetector); } /** @@ -208,7 +193,6 @@ class XCX121SMCStrategy : public XCX121SMCBaseStrategy // bool hasXWZSignal = false; - bool hasXSupDemOBSSignal = false; // // XSupDemOBS Signal ... @@ -223,19 +207,6 @@ class XCX121SMCStrategy : public XCX121SMCBaseStrategy hasSignal = hasXWZSignal; } - // - // XSupDemOBS Signal ... - X121SMCStrategyXSupDemOBSSignalConditions mXSupDemOBSConditions; - if (useXSupDemOBSSignal && !hasSignal) - { - // - hasXSupDemOBSSignal = DetectXSupDemOBSSignal( - conditions, - mXSupDemOBSConditions // - ); - hasSignal = hasXSupDemOBSSignal; - } - // result = hasSignal; if (!result) @@ -342,18 +313,18 @@ class XCX121SMCStrategy : public XCX121SMCBaseStrategy if (result) { // - if (useXSupDemOBSSignal && - hasXSupDemOBSSignal) + if (useXWZSignal && + hasXWZSignal) { // // Configuring Amount Percent and ETC ... - bool ignoreEAVolume = mXSupDemOBSConditions.reward > 0 && - mXSupDemOBSConditions.amountPercent > 0; + bool ignoreEAVolume = mXWZConditions.reward > 0 && + mXWZConditions.amountPercent > 0; if (ignoreEAVolume) { // - double cReward = mXSupDemOBSConditions.reward; - double cAmountPercent = mXSupDemOBSConditions.amountPercent; + double cReward = mXWZConditions.reward; + double cAmountPercent = mXWZConditions.amountPercent; // double cRiskReward = risk * cReward; @@ -385,8 +356,8 @@ class XCX121SMCStrategy : public XCX121SMCBaseStrategy // Fix Signal TP Based On Working Zone ... double maxAllowedTP = hasLong - ? mXSupDemOBSConditions.workingZone.upper - : mXSupDemOBSConditions.workingZone.lower; + ? mXWZConditions.workingZone.upper + : mXWZConditions.workingZone.lower; bool canApplyMaxAlowedTP = (hasLong && signal.tp > maxAllowedTP) || (!hasLong && signal.tp < maxAllowedTP); @@ -448,7 +419,7 @@ class XCX121SMCStrategy : public XCX121SMCBaseStrategy } // - mXSupDemOBSConditions.Clean(); + mXWZConditions.Clean(); // return result; @@ -501,33 +472,9 @@ class XCX121SMCStrategy : public XCX121SMCBaseStrategy false // ); } - } - - // - // XSupDemOBS Guard Detection ... - if (useXSupDemOBSSignal) - { - // - X121SMCGuard xsupDemOBSGuards[]; - bool hasGuard = mXSupDemOBSSignalDetector.DetectGuards( - xsupDemOBSGuards, - positions, - mDecisionCycleHelper, - mAnalyseCycleHelper, - mConsolidationCycleHelper, - mVisionCycleHelper // - ); // - if (hasGuard) - { - // - Copy( - xsupDemOBSGuards, - guards, - false // - ); - } + Clean(xwzGuards); } // @@ -618,51 +565,11 @@ class XCX121SMCStrategy : public XCX121SMCBaseStrategy string symbol = GetSymbol(); ENUM_TIMEFRAMES period = GetPeriod(); - // - XOHCL zBar; - result = zBar.Init( - symbol, - period, - zIndex // - ); - if (!result) - { - return result; - } - - // - XOHCL cBar; - result = cBar.Init( - symbol, - period, - cIndex // - ); - if (!result) - { - return result; - } - - // - XOHCL pBar; - result = pBar.Init( - symbol, - period, - pIndex // - ); - if (!result) - { - return result; - } - - // - double cLL = cBar.FindLowest(7, MODE_LOW); - double cHH = cBar.FindHighest(7, MODE_HIGH); - // datetime cTime = TimeCurrent(); // - ENUM_X_121_SMC_PROVIDERS provider = X_121_SMC_PROVIDER_XSUPDEMOBS; + ENUM_X_121_SMC_PROVIDERS provider = X_121_SMC_PROVIDER_XWZ; string providerStr = ToString(provider); // @@ -813,240 +720,6 @@ class XCX121SMCStrategy : public XCX121SMCBaseStrategy return result; } - // - // XSupDemOBS Signal ... - bool DetectXSupDemOBSSignal( - X121SMCStrategyConditions &conditions, - X121SMCStrategyXSupDemOBSSignalConditions &xSupDemOBSConditions // - ) - { - // - bool result = false; - - // - // Validate Cycle Helpers ... - result = - // - mVisionCycleHelper != NULL && - mAnalyseCycleHelper != NULL && - mDecisionCycleHelper != NULL && - mConsolidationCycleHelper != NULL - // - ; - if (!result) - { - return result; - } - - // - bool isBullish = false; - bool isBearish = false; - - // - int zIndex = 0; - int cIndex = zIndex + 1; - int pIndex = cIndex + 1; - int ppIndex = pIndex + 1; - - // - string symbol = GetSymbol(); - ENUM_TIMEFRAMES period = GetPeriod(); - - // - XOHCL zBar; - result = zBar.Init( - symbol, - period, - zIndex // - ); - if (!result) - { - return result; - } - - // - XOHCL cBar; - result = cBar.Init( - symbol, - period, - cIndex // - ); - if (!result) - { - return result; - } - - // - XOHCL pBar; - result = pBar.Init( - symbol, - period, - pIndex // - ); - if (!result) - { - return result; - } - - // - double cLL = cBar.FindLowest(7, MODE_LOW); - double cHH = cBar.FindHighest(7, MODE_HIGH); - - // - datetime cTime = TimeCurrent(); - - // - ENUM_X_121_SMC_PROVIDERS provider = X_121_SMC_PROVIDER_XSUPDEMOBS; - string providerStr = ToString(provider); - - // - // Detect Setup Conditions ... - datetime setupTime = mXSupDemOBSSignalDetector.mConditions.setupTime; - bool isSetuped = mXSupDemOBSSignalDetector.mConditions.IsSetuped(); - ENUM_X_DIRECTION setupDir = mXSupDemOBSSignalDetector.mConditions.dir; - if (!isSetuped) - { - // - // Detect Signal Setup ... - isSetuped = mXSupDemOBSSignalDetector.DetectSignalSetup( - symbol, - period, - mDecisionCycleHelper, - mAnalyseCycleHelper, - mConsolidationCycleHelper, - mVisionCycleHelper // - ); - - // - setupDir = mXSupDemOBSSignalDetector.mConditions.dir; - setupTime = mXSupDemOBSSignalDetector.mConditions.setupTime; - - // - if (isSetuped) - { - // - int items = mXSupDemOBSSignalDetector - .AddConditionsIfNotExists(); - - // - mXSupDemOBSSignalDetector.mConditions.Clean(); - } - } - - // - int conditionsCount = ArraySize(mXSupDemOBSSignalDetector.mConditionsCollection); - result = IsValidSize(conditionsCount); - if (!result) - { - return result; - } - - // - // Looking For Conditions ... - int selectedIndex = 0; - X121SMCStrategyXSupDemOBSSignalConditions mTmpConditions[]; - Copy( - mXSupDemOBSSignalDetector.mConditionsCollection, - mTmpConditions // - ); - X121SMCStrategyXSupDemOBSSignalConditions mConditions; - for (int i = 0; i < conditionsCount; i++) - { - // - // Check Triggers ... - bool canTrigger = mTmpConditions[i].CanTrigger(); - datetime triggerTime = mTmpConditions[i].triggerTime; - if (!canTrigger) - { - // - // Detect Signal Trigger ... - canTrigger = mXSupDemOBSSignalDetector - .DetectSignalTrigger( - mTmpConditions[i], - symbol, - period, - mDecisionCycleHelper, - mAnalyseCycleHelper, - mConsolidationCycleHelper, - mVisionCycleHelper // - ); - - // - result = canTrigger; - if (!result) - { - // - bool isISetuped = mTmpConditions[i].IsSetuped(); - if (!isISetuped) - { - // - ArrayRemove( - mXSupDemOBSSignalDetector.mConditionsCollection, - i, - 1 // - ); - } - continue; - } - - // - triggerTime = mTmpConditions[i].triggerTime; - } - - // - if (canTrigger) - { - // - selectedIndex = i; - mConditions = mTmpConditions[i]; - break; - } - } - - // - result = IsValid(mConditions.setupTime) && - HasDirection(mConditions.dir); - if (!result) - { - return result; - } - - // - // Remove Selected Index from Main Collection ... - ArrayRemove( - mXSupDemOBSSignalDetector.mConditionsCollection, - selectedIndex, - 1 // - ); - - // - // Check Signal Direction ... - isBullish = IsBullish(mConditions.dir); - isBearish = IsBearish(mConditions.dir); - result = isBullish || - isBearish; - if (!result) - { - return result; - } - - // - // Issues Signal on Conditions ... - conditions.sl = mConditions.sl; - conditions.provider = providerStr; - conditions.signalDir = mConditions.dir; - conditions.target = mConditions.target; - - // - xSupDemOBSConditions = mConditions; - - // - mConditions.Clean(); - - // - return result; - } - // // Private ... private: @@ -1063,7 +736,6 @@ class XCX121SMCStrategy : public XCX121SMCBaseStrategy { // useXWZSignal = true; - useXSupDemOBSSignal = false; // string symbol = GetSymbol();