diff --git a/Documents/BKP/1.ind.ai.mq5 b/Documents/BKP/1.ind.ai.mq5 deleted file mode 100644 index 34d2e5f4..00000000 --- a/Documents/BKP/1.ind.ai.mq5 +++ /dev/null @@ -1,196 +0,0 @@ -//+------------------------------------------------------------------+ -//| HH_LH_LL_HL.mq5 | -//| Indicator for detecting HH, LH, LL, HL | -//| Created by [Your Name] | -//+------------------------------------------------------------------+ - -#property copyright "Your Name" -#property link "yourwebsite.com" -#property version "1.00" -#property indicator_chart_window -#property indicator_buffers 4 -#property indicator_plots 4 - -//--- Input parameters -input int LookbackPeriod = 20; // Number of bars to look back for pattern detection - -//--- Buffer declarations -double HH_Buffer[]; // Buffer for Higher Highs -double HL_Buffer[]; // Buffer for Higher Lows -double LH_Buffer[]; // Buffer for Lower Highs -double LL_Buffer[]; // Buffer for Lower Lows - -//--- Plot settings -#property indicator_label1 "Higher Highs" -#property indicator_type1 DRAW_ARROW -#property indicator_color1 clrGreen -#property indicator_style1 STYLE_SOLID -#property indicator_width1 1 - -#property indicator_label2 "Higher Lows" -#property indicator_type2 DRAW_ARROW -#property indicator_color2 clrBlue -#property indicator_style2 STYLE_SOLID -#property indicator_width2 1 - -#property indicator_label3 "Lower Highs" -#property indicator_type3 DRAW_ARROW -#property indicator_color3 clrRed -#property indicator_style3 STYLE_SOLID -#property indicator_width3 1 - -#property indicator_label4 "Lower Lows" -#property indicator_type4 DRAW_ARROW -#property indicator_color4 clrYellow -#property indicator_style4 STYLE_SOLID -#property indicator_width4 1 - -//+------------------------------------------------------------------+ -//| Initialization function | -//+------------------------------------------------------------------+ -int OnInit() -{ - // Set buffer properties - SetIndexBuffer(0, HH_Buffer); - SetIndexBuffer(1, HL_Buffer); - SetIndexBuffer(2, LH_Buffer); - SetIndexBuffer(3, LL_Buffer); - - // Clear buffers at each bar - ArrayInitialize(HH_Buffer, 0.0); - ArrayInitialize(HL_Buffer, 0.0); - ArrayInitialize(LH_Buffer, 0.0); - ArrayInitialize(LL_Buffer, 0.0); - - return(INIT_SUCCEEDED); -} - -//+------------------------------------------------------------------+ -//| Deinitialization function | -//+------------------------------------------------------------------+ -void OnDeinit(const int reason) -{ - // Cleanup if necessary -} - -//+------------------------------------------------------------------+ -//| Calculate function | -//+------------------------------------------------------------------+ -int OnCalculate(const int rates_total, - const int prev_calculated, - const datetime &time[], - const double &open[], - const double &high[], - const double &low[], - const double &close[], - const long &tick_volume[], - const long &volume[], - const int &spread[]) -{ - // Start from the last calculated bar - int start_bar = MathMax(prev_calculated - 1, 0); - - // Loop through bars - for (int i = start_bar; i < rates_total; i++) - { - // Get current high and low - double current_high = high[i]; - double current_low = low[i]; - - // Check for Higher High (HH) - if (IsHigherHigh(i, high, LookbackPeriod)) - { - HH_Buffer[i] = current_high; - HL_Buffer[i] = 0.0; // Reset other buffers - LH_Buffer[i] = 0.0; - LL_Buffer[i] = 0.0; - } - // Check for Higher Low (HL) - else if (IsHigherLow(i, low, LookbackPeriod)) - { - HL_Buffer[i] = current_low; - HH_Buffer[i] = 0.0; - LH_Buffer[i] = 0.0; - LL_Buffer[i] = 0.0; - } - // Check for Lower High (LH) - else if (IsLowerHigh(i, high, LookbackPeriod)) - { - LH_Buffer[i] = current_high; - HH_Buffer[i] = 0.0; - HL_Buffer[i] = 0.0; - LL_Buffer[i] = 0.0; - } - // Check for Lower Low (LL) - else if (IsLowerLow(i, low, LookbackPeriod)) - { - LL_Buffer[i] = current_low; - HH_Buffer[i] = 0.0; - HL_Buffer[i] = 0.0; - LH_Buffer[i] = 0.0; - } - else - { - // Reset all buffers if no pattern is detected - HH_Buffer[i] = 0.0; - HL_Buffer[i] = 0.0; - LH_Buffer[i] = 0.0; - LL_Buffer[i] = 0.0; - } - } - - // - return rates_total; -} - -//+------------------------------------------------------------------+ -//| Function to detect Higher High | -//+------------------------------------------------------------------+ -bool IsHigherHigh(int index, const double &high[], int lookback) -{ - for (int i = 1; i <= lookback; i++) - { - if (index - i < 0) continue; // Ensure we don't go out of bounds - if (high[index] <= high[index - i]) return false; - } - return true; -} - -//+------------------------------------------------------------------+ -//| Function to detect Higher Low | -//+------------------------------------------------------------------+ -bool IsHigherLow(int index, const double &low[], int lookback) -{ - for (int i = 1; i <= lookback; i++) - { - if (index - i < 0) continue; // Ensure we don't go out of bounds - if (low[index] <= low[index - i]) return false; - } - return true; -} - -//+------------------------------------------------------------------+ -//| Function to detect Lower High | -//+------------------------------------------------------------------+ -bool IsLowerHigh(int index, const double &high[], int lookback) -{ - for (int i = 1; i <= lookback; i++) - { - if (index - i < 0) continue; // Ensure we don't go out of bounds - if (high[index] >= high[index - i]) return false; - } - return true; -} - -//+------------------------------------------------------------------+ -//| Function to detect Lower Low | -//+------------------------------------------------------------------+ -bool IsLowerLow(int index, const double &low[], int lookback) -{ - for (int i = 1; i <= lookback; i++) - { - if (index - i < 0) continue; // Ensure we don't go out of bounds - if (low[index] >= low[index - i]) return false; - } - return true; -} \ No newline at end of file diff --git a/Documents/BKP/1.mq5 b/Documents/BKP/1.mq5 deleted file mode 100644 index fd7da809..00000000 --- a/Documents/BKP/1.mq5 +++ /dev/null @@ -1,10874 +0,0 @@ - -// -// Fix Signal TP Based On Working Zone ... -// double maxAllowedTP = -// hasLong -// ? mXWZConditions.workingZone.upper -// : mXWZConditions.workingZone.lower; -// bool canApplyMaxAlowedTP = (hasLong && -// signal.tp > maxAllowedTP) || -// (!hasLong && signal.tp < maxAllowedTP); -// if (canApplyMaxAlowedTP) -// { -// signal.tp = maxAllowedTP; -// } - -// -// Configuring Global Protector ... -// signal.trailSL = true; -// signal.trailSLStartOnReachTPLevel = 3; -// signal.fullTPLevel = signal.GetRiskRewardRatio(); - -// // -// mXSupDemOBSSignalDetector.RemoveDraws(); -// mXSupDemOBSSignalDetector.DrawConditions( -// mXSupDemOBSConditions, -// mVisionCycleHelper.mPOIDrawer // -// ); - -// // -// mXSupDemOBSSignalDetector.RemoveWorkingZoneDraws(); -// mXSupDemOBSSignalDetector.DrawWorkingZone( -// mXSupDemOBSConditions, -// mVisionCycleHelper.mPOIDrawer // -// ); - -// -// bool canReplaceTarget = -// signal.target > 0 && -// (hasLong -// ? signal.target > signal.tp -// : signal.target < signal.tp); -// if (canReplaceTarget) -// { -// // -// signal.tp = conditions.target; -// signal.target = tp; -// } - -// -// consolidationState.UpdateTo(cTime); -// XPOIState filtered; -// consolidationState.Filter( -// filtered, -// NULL, -// XZONE_STATE_PASSED, -// false, -// XZONE_STATE_FAILED, -// false, -// XZONE_STATE_FAILED, -// false, -// XZONE_STATE_IGNORED, -// false // -// ); -// XCBaseObject *objects[]; -// int objectsCount = drawer.DrawState( -// filtered, -// objects // -// ); -// if (IsValidSize(objectsCount)) -// { -// // -// Print(""); -// } - -// // -// XOBFVG activeObfvgs[]; -// int activeObfvgsCount = ExtractOBFVGs( -// activeObfvgs, -// consolidationState, -// analyseState // -// ); -// bool hasActiveOBFVGs = IsValidSize(activeObfvgsCount); -// if (hasActiveOBFVGs) -// { -// // -// SpecifiedUpdateTo(activeObfvgs); -// for (int i = 0; i < activeObfvgsCount; i++) -// { -// // -// XCBaseObject *objects[]; -// int objectsCount = drawer.DrawOBFVG( -// activeObfvgs[i], -// objects // -// ); -// } -// } - -// // -// // Swings ... -// bool lookupSwings = ArraySize(mSwingLows) < mMaxRequiredPOIs || -// ArraySize(mSwingHighs) < mMaxRequiredPOIs; -// lookupSwings = -// ignoreMaxAllowed -// ? true -// : lookupSwings; -// if (has && -// lookupSwings) -// { -// } - -// // -// // Momentum Bar ... -// bool lookupMomentums = ArraySize(mBullishMomentumBars) < mMaxRequiredPOIs || -// ArraySize(mBearishMomentumBars) < mMaxRequiredPOIs; -// lookupMomentums = -// ignoreMaxAllowed -// ? true -// : lookupMomentums; -// if (has && -// lookupMomentums) -// { -// } - -// // -// // Rejection Bar ... -// bool lookupRejections = ArraySize(mBullishRejectionBars) < mMaxRequiredPOIs || -// ArraySize(mBearishRejectionBars) < mMaxRequiredPOIs; -// lookupRejections = -// ignoreMaxAllowed -// ? true -// : lookupRejections; -// if (has && -// lookupRejections) -// { -// } - -// // -// // Support ... -// bool lookupSupports = ArraySize(mSupportZones) < mMaxRequiredPOIs; -// lookupSupports = -// ignoreMaxAllowed -// ? true -// : lookupSupports; -// if (has && -// lookupSupports) -// { -// } - -// // -// // Demand ... -// bool lookupDemands = ArraySize(mDemandZones) < mMaxRequiredPOIs; -// lookupDemands = -// ignoreMaxAllowed -// ? true -// : lookupDemands; -// if (has && -// lookupDemands) -// { -// } - -// // -// // Resistance ... -// bool lookupResistance = ArraySize(mResistanceZones) < mMaxRequiredPOIs; -// lookupResistance = -// ignoreMaxAllowed -// ? true -// : lookupResistance; -// if (has && -// lookupResistance) -// { -// } - -// // -// // Supply ... -// bool lookupSupplies = ArraySize(mSupplyZones) < mMaxRequiredPOIs; -// lookupSupplies = -// ignoreMaxAllowed -// ? true -// : lookupSupplies; -// if (has && -// lookupSupplies) -// { -// } - -// // -// // OrderBlock ... -// bool lookupOrderBlocks = ArraySize(mBullishOrderBlocks) < mMaxRequiredPOIs || -// ArraySize(mBearishOrderBlocks) < mMaxRequiredPOIs; -// lookupOrderBlocks = -// ignoreMaxAllowed -// ? true -// : lookupOrderBlocks; -// if (has && -// lookupOrderBlocks) -// { -// } - -// // -// // FairValueGap ... -// bool lookupFairValeGaps = ArraySize(mBullishFairValueGaps) < mMaxRequiredPOIs || -// ArraySize(mBearishFairValueGaps) < mMaxRequiredPOIs; -// lookupFairValeGaps = -// ignoreMaxAllowed -// ? true -// : lookupFairValeGaps; -// if (has && -// (lookupFairValeGaps)) -// { -// } - -// -XCBaseObject *stateObjects[]; -int stateObjectsCount = drawer.DrawState( - decisionState, - stateObjects, - false, // - true, // ignoreSwingHighs - true, // ignoreSwingLows - true, // ignoreSupportZones - true, // ignoreResistanceZones - true, // ignoreSupplyZones - true, // ignoreDemandZones - true, // ignoreBullishOrderBlocks - true, // ignoreBearishOrderBlocks - true, // ignoreBullishFairValueGaps - true, // ignoreBearishFairValueGaps - true, // ignoreBullishRejectionBars - true, // ignoreBearishRejectionBars - true, // ignoreBullishMomentumBars - true, // ignoreBearishMomentumBars - false, // ignoreBullishConsolidationZones - false // ignoreBearishConsolidationZones -); - -// -// Draw ... -if (hasSelectedConsolidationZone) -{ - // - XCConsolidationZoneObject *iObj; - selectedConsolidationZone.to = cTime; - bool isCreated = drawer.CreateConsolidationZone( - selectedConsolidationZone, - iObj // - ); -} - -///////////////////////////////////////////////////////////////////////////////////// - -// // -// // Based On Waiting Zones ... -// has = isBarInited && -// hasWorkingZone; -// if (has) -// { -// // -// XOBFVG tmpZones[]; -// Copy( -// workingZone.waitingZones, -// tmpZones // -// ); - -// // -// while (HasChild(tmpZones)) -// { -// // -// XOBFVG iOBFVG; - -// // -// idx = GetYoungest(tmpZones); -// if (!IsValidIndex(idx)) -// { -// // -// iOBFVG.Clean(); -// break; -// } - -// // -// iOBFVG = tmpZones[idx]; -// ArrayRemove( -// tmpZones, -// idx, -// 1 // -// ); - -// // -// double iTarget = -// isSelectedZonDirBullish -// ? iOBFVG.ob.Lower() -// : iOBFVG.ob.Upper(); - -// // -// has = -// isSelectedZonDirBullish -// ? cBar.high < iTarget -// : cBar.low > iTarget; - -// // -// if (has) -// { -// // -// Add( -// iTarget, -// targets // -// ); -// } - -// // -// iOBFVG.Clean(); -// } - -// // -// Clean(tmpZones); -// } - -// // -// // Based On Breaked Zones ... -// has = isBarInited && -// hasBreakedZones; -// if (has) -// { -// // -// XOBFVG tmpZones[]; -// Copy( -// workingZone.breakedZones, -// tmpZones // -// ); - -// // -// while (HasChild(tmpZones)) -// { -// // -// XOBFVG iOBFVG; - -// // -// idx = GetYoungest(tmpZones); -// if (!IsValidIndex(idx)) -// { -// // -// iOBFVG.Clean(); -// break; -// } - -// // -// iOBFVG = tmpZones[idx]; -// ArrayRemove( -// tmpZones, -// idx, -// 1 // -// ); - -// // -// double iTarget = -// isSelectedZonDirBullish -// ? iOBFVG.ob.Lower() -// : iOBFVG.ob.Upper(); - -// // -// has = -// isSelectedZonDirBullish -// ? cBar.high < iTarget -// : cBar.low > iTarget; - -// // -// if (has) -// { -// // -// Add( -// iTarget, -// targets // -// ); -// } - -// // -// iOBFVG.Clean(); -// } - -// // -// Clean(tmpZones); -// } - -// // -// // 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 // -// ); - -// // -// // Low ... -// Add( -// workingZone.quarter1, -// targets // -// ); -// } -// else -// { -// // -// // Weak ... -// Add( -// workingZone.demandZone.Upper(), -// targets // -// ); - -// // -// // Low ... -// Add( -// workingZone.quarter3, -// targets // -// ); -// } -// break; - -// // -// case X121SMC_XWZ_PRIORITY_REGULAR: -// // -// if (isSelectedZonDirBullish) -// { -// // -// // Weak ... -// Add( -// workingZone.supplyZone.Lower(), -// targets // -// ); - -// // -// // Low ... -// Add( -// workingZone.quarter1, -// targets // -// ); - -// // -// // Regular ... -// Add( -// workingZone.quarter2, -// targets // -// ); -// } -// else -// { -// // -// // Weak ... -// Add( -// workingZone.demandZone.Upper(), -// targets // -// ); - -// // -// // Low ... -// Add( -// workingZone.quarter3, -// targets // -// ); - -// // -// // Regular ... -// Add( -// workingZone.quarter2, -// targets // -// ); -// } -// break; - -// // -// case X121SMC_XWZ_PRIORITY_HIGH: -// // -// if (isSelectedZonDirBullish) -// { -// // -// // Weak ... -// Add( -// workingZone.supplyZone.Lower(), -// targets // -// ); - -// // -// // Low ... -// Add( -// workingZone.quarter1, -// targets // -// ); - -// // -// // Regular ... -// Add( -// workingZone.quarter2, -// targets // -// ); - -// // -// // High ... -// Add( -// workingZone.quarter3, -// targets // -// ); -// } -// else -// { -// // -// // Weak ... -// Add( -// workingZone.demandZone.Upper(), -// targets // -// ); - -// // -// // Low ... -// Add( -// workingZone.quarter3, -// targets // -// ); - -// // -// // Regular ... -// Add( -// workingZone.quarter2, -// targets // -// ); - -// // -// // High ... -// Add( -// workingZone.quarter1, -// targets // -// ); -// } -// break; - -// // -// case X121SMC_XWZ_PRIORITY_STRONG_HIGH: -// // -// if (isSelectedZonDirBullish) -// { -// // -// // Weak ... -// Add( -// workingZone.supplyZone.Lower(), -// targets // -// ); - -// // -// // Low ... -// Add( -// workingZone.quarter1, -// targets // -// ); - -// // -// // Regular ... -// Add( -// workingZone.quarter2, -// targets // -// ); - -// // -// // High ... -// Add( -// workingZone.quarter3, -// targets // -// ); - -// // -// // Strong High ... -// Add( -// workingZone.demandZone.Upper(), -// targets // -// ); -// } -// else -// { -// // -// // Weak ... -// Add( -// workingZone.demandZone.Upper(), -// targets // -// ); - -// // -// // Low ... -// Add( -// workingZone.quarter3, -// targets // -// ); - -// // -// // Regular ... -// Add( -// workingZone.quarter2, -// targets // -// ); - -// // -// // High ... -// Add( -// workingZone.quarter1, -// targets // -// ); - -// // -// // Strong High ... -// Add( -// workingZone.supplyZone.Lower(), -// targets // -// ); -// } -// break; -// } -// } - -//////////////////////////////////////////////////////////////////// - -// -// Based On Consolidation Zones ... -has = isBarInited && - decisionState.HasConsolidationZones(); -if (has) -{ - // - XConsolidationZone tmpZones[]; - if (isSelectedZonDirBullish) - { - // - Copy( - decisionState.bullishConsolidationZones, - tmpZones // - ); - } - else - { - // - Copy( - decisionState.bearishConsolidationZones, - tmpZones // - ); - } - - // - while (HasChild(tmpZones)) - { - // - idx = GetYoungest(tmpZones); - if (!IsValidIndex(idx)) - { - break; - } - - // - XConsolidationZone iZone = tmpZones[idx]; - - // - ArrayRemove( - tmpZones, - idx, - 1 // - ); - - // - hasSelectedConsolidationZone = - isSelectedZonDirBullish - ? cBar.low < iZone.upper - : cBar.high < iZone.lower; - if (hasSelectedConsolidationZone) - { - // - selectedConsolidationZone = iZone; - iZone.Clean(); - break; - } - - // - iZone.Clean(); - } - - // - Clean(tmpZones); - - // - if (hasSelectedConsolidationZone) - { - // - XCConsolidationZoneObject *iObj; - selectedConsolidationZone.to = cTime; - bool isCreated = drawer.CreateConsolidationZone( - selectedConsolidationZone, - iObj // - ); - - // - double iSL = - isSelectedZonDirBullish - ? selectedConsolidationZone.lower - : selectedConsolidationZone.upper; - double iSLDiff = MathAbs(iSL - pivot); - has = - iSLDiff > 0 && - iSLDiff <= maxAllowedSLDistanceInPoint * points; - if (has) - { - // - Add( - iSL, - sls // - ); - } - } -} - -// -// Based On Supply and Demand Zones ... - -// -// Demand Zones ... -has = hasWorkingZone && - workingZone.HasDemandZones(); -if (has) -{ - // - XCDemandZone *tmpZones[]; - Copy( - workingZone.demandZones, - tmpZones // - ); - XCDemandZone *selectedDemand = NULL; - - // - while (HasChild(tmpZones)) - { - // - idx = GetLowest(tmpZones); - has = IsValidIndex(idx); - if (!has) - { - break; - } - - // - XCDemandZone *iZone = tmpZones[idx]; - ArrayRemove( - tmpZones, - idx, - 1 // - ); - - // - // Validate Zone ... - has = - isSelectedZonDirBullish - ? IsBelowDiff( - iZone, - selectedZone.ob, - true // Ignore Inside ... - ) - : IsAboveDiff( - iZone, - selectedZone.ob, - true // Ignore Inside ... - ); - if (!has) - { - continue; - } - - // - has = - selectedDemand == NULL - ? true - : isSelectedZonDirBullish - ? selectedDemand.Lower() < iZone.Lower() - : selectedDemand.Upper() > iZone.Upper(); - if (!has) - { - continue; - } - - // - selectedDemand = iZone; - - // - } - - // - has = selectedDemand != NULL; - if (has) - { - // - XCDemandZoneObject *iObj; - bool isCreated = drawer.CreateDemandZone( - selectedDemand, - iObj // - ); - - // - double iSL = - isSelectedZonDirBullish - ? selectedDemand.Lower() - : selectedDemand.Upper(); - double iSLDiff = MathAbs(iSL - pivot); - has = - iSLDiff > 0 && - iSLDiff <= maxAllowedSLDistanceInPoint * points; - if (has) - { - // - Add( - iSL, - sls // - ); - } - } - - // - Clean(tmpZones); - ZeroMemory(selectedDemand); -} - -// -// Support Zones ... -has = hasWorkingZone && - workingZone.HasSupportZones(); -if (has) -{ - // - XCSupportZone *tmpZones[]; - Copy( - workingZone.supportZones, - tmpZones // - ); - XCSupportZone *selectedSupport = NULL; - - // - while (HasChild(tmpZones)) - { - // - idx = GetLowest(tmpZones); - has = IsValidIndex(idx); - if (!has) - { - break; - } - - // - XCSupportZone *iZone = tmpZones[idx]; - ArrayRemove( - tmpZones, - idx, - 1 // - ); - - // - // Validate Zone ... - has = - isSelectedZonDirBullish - ? IsBelowDiff( - iZone, - selectedZone.ob, - true // Ignore Inside ... - ) - : IsAboveDiff( - iZone, - selectedZone.ob, - true // Ignore Inside ... - ); - if (!has) - { - continue; - } - - // - has = - selectedSupport == NULL - ? true - : isSelectedZonDirBullish - ? selectedSupport.Lower() < iZone.Lower() - : selectedSupport.Upper() > iZone.Upper(); - if (!has) - { - continue; - } - - // - selectedSupport = iZone; - - // - } - - // - has = selectedSupport != NULL; - if (has) - { - // - XCSupportZoneObject *iObj; - bool isCreated = drawer.CreateSupportZone( - selectedSupport, - iObj // - ); - - // - double iSL = isSelectedZonDirBullish - ? selectedSupport.Lower() - : selectedSupport.Upper(); - double iSLDiff = MathAbs(iSL - pivot); - has = - iSLDiff > 0 && - iSLDiff <= maxAllowedSLDistanceInPoint * points; - if (has) - { - // - Add( - iSL, - sls // - ); - } - } - - // - Clean(tmpZones); - ZeroMemory(selectedSupport); -} - -// -// Supply Zones ... -has = hasWorkingZone && - workingZone.HasSupplyZones(); -if (has) -{ - // - XCSupplyZone *tmpZones[]; - Copy( - workingZone.supplyZones, - tmpZones // - ); - XCSupplyZone *selectedSupply = NULL; - - // - while (HasChild(tmpZones)) - { - // - idx = GetHighest(tmpZones); - has = IsValidIndex(idx); - if (!has) - { - break; - } - - // - XCSupplyZone *iZone = tmpZones[idx]; - ArrayRemove( - tmpZones, - idx, - 1 // - ); - - // - // Validate Zone ... - has = - !isSelectedZonDirBullish - ? IsAboveDiff( - iZone, - selectedZone.ob, - true // Ignore Inside ... - ) - : IsBelowDiff( - iZone, - selectedZone.ob, - true // Ignore Inside ... - ); - if (!has) - { - continue; - } - - // - has = - selectedSupply == NULL - ? true - : !isSelectedZonDirBullish - ? selectedSupply.Upper() > iZone.Upper() - : selectedSupply.Lower() < iZone.Lower(); - if (!has) - { - continue; - } - - // - selectedSupply = iZone; - - // - } - - // - has = selectedSupply != NULL; - if (has) - { - // - XCSupplyZoneObject *iObj; - bool isCreated = drawer.CreateSupplyZone( - selectedSupply, - iObj // - ); - - // - double iSL = - !isSelectedZonDirBullish - ? selectedSupply.Upper() - : selectedSupply.Lower(); - double iSLDiff = MathAbs(iSL - pivot); - has = - iSLDiff > 0 && - iSLDiff <= maxAllowedSLDistanceInPoint * points; - if (has) - { - // - Add( - iSL, - sls // - ); - } - } - - // - Clean(tmpZones); - ZeroMemory(selectedSupply); -} - -// -// Resistance Zones ... -has = hasWorkingZone && - workingZone.HasDemandZones(); -if (has) -{ - // - XCResistanceZone *tmpZones[]; - Copy( - workingZone.resistanceZones, - tmpZones // - ); - XCResistanceZone *selectedResistance = NULL; - - // - while (HasChild(tmpZones)) - { - // - idx = GetHighest(tmpZones); - has = IsValidIndex(idx); - if (!has) - { - break; - } - - // - XCResistanceZone *iZone = tmpZones[idx]; - ArrayRemove( - tmpZones, - idx, - 1 // - ); - - // - // Validate Zone ... - has = - !isSelectedZonDirBullish - ? IsAboveDiff( - iZone, - selectedZone.ob, - true // Ignore Inside ... - ) - : IsBelowDiff( - iZone, - selectedZone.ob, - true // Ignore Inside ... - ); - if (!has) - { - continue; - } - - // - has = - selectedResistance == NULL - ? true - : !isSelectedZonDirBullish - ? selectedResistance.Upper() < iZone.Upper() - : selectedResistance.Lower() > iZone.Lower(); - if (!has) - { - continue; - } - - // - selectedResistance = iZone; - - // - } - - // - has = selectedResistance != NULL; - if (has) - { - // - XCResistanceZoneObject *iObj; - bool isCreated = drawer.CreateResistanceZone( - selectedResistance, - iObj // - ); - - // - double iSL = - !isSelectedZonDirBullish - ? selectedResistance.Upper() - : selectedResistance.Lower(); - double iSLDiff = MathAbs(iSL - pivot); - has = - iSLDiff > 0 && - iSLDiff <= maxAllowedSLDistanceInPoint * points; - if (has) - { - // - Add( - iSL, - sls // - ); - } - } - - // - Clean(tmpZones); - ZeroMemory(selectedResistance); -} - -// -// Based On Passed Bars ... -XOHCL passedBar; -bool isPassed = false; -bool isBodyState = false; -ENUM_X_DIRECTION passedDir = selectedZone.GetDirection(); - -// -// Started Bar ... -isPassed = selectedZone.ob.IsStarted( - passedDir, - passedBar, - isBodyState // -); -if (isPassed) -{ - // - double iSL = - isSelectedZonDirBullish - ? passedBar.low - : passedBar.high; - double iSLDiff = MathAbs(iSL - pivot); - has = - iSLDiff > 0 && - iSLDiff <= maxAllowedSLDistanceInPoint * points; - if (has) - { - // - Add( - iSL, - sls // - ); - } -} - -// -// Activation Bar ... -passedBar.Clean(); -isPassed = selectedZone.ob.IsActivated( - passedDir, - passedBar, - isBodyState // -); -if (isPassed) -{ - // - double iSL = - isSelectedZonDirBullish - ? passedBar.low - : passedBar.high; - double iSLDiff = MathAbs(iSL - pivot); - has = - iSLDiff > 0 && - iSLDiff <= maxAllowedSLDistanceInPoint * points; - if (has) - { - // - Add( - iSL, - sls // - ); - } -} - -// -// Worked Bar ... -passedBar.Clean(); -isPassed = selectedZone.ob.IsActivated( - passedDir, - passedBar, - isBodyState // -); -if (isPassed) -{ - // - double iSL = - isSelectedZonDirBullish - ? passedBar.low - : passedBar.high; - double iSLDiff = MathAbs(iSL - pivot); - has = - iSLDiff > 0 && - iSLDiff <= maxAllowedSLDistanceInPoint * points; - if (has) - { - // - Add( - iSL, - sls // - ); - } -} - -// -// Breaked Bar ... -passedBar.Clean(); -isPassed = selectedZone.ob.IsActivated( - passedDir, - passedBar, - isBodyState // -); -if (isPassed) -{ - // - double iSL = - isSelectedZonDirBullish - ? passedBar.low - : passedBar.high; - double iSLDiff = MathAbs(iSL - pivot); - has = - iSLDiff > 0 && - iSLDiff <= maxAllowedSLDistanceInPoint * points; - if (has) - { - // - Add( - iSL, - sls // - ); - } -} - -//////////////////////////////////////////////////////////////////// - -// // -// // 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; - -/////////////////////////////////////////////////////////////////////////////// - -// -// -// - -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; -} - -////////////////////////////////////////////////////////////////////////// - -/** - * Check an XOBFVG instance has Required Conditions ... - * - * @param zone: XBoxZone instance ... - * @param state: XPOIState instance ... - * @param conditions: X121Conditions instance ... - * - * @return ( bool ) - */ -bool DetectSelectedBoxConditions( - bool &isReversal, - XBoxZone &zone, - XPOIState &state, - X121Conditions &conditions // -) -{ - // - bool result = false; - - // - isReversal = false; - - // - result = - zone.IsValid() && - state.IsValid() && - state.HasChild(); - if (!result) - { - return result; - } - - // - bool isBullish = zone.IsBullish(); - bool isBearish = zone.IsBearish(); - - // - bool isBullishTrend = conditions.isTrendBullish || - conditions.isTrendSwitchedToBullish; - bool isBearishTrend = conditions.isTrendBearish || - conditions.isTrendSwitchedToBearish; - - // - double bullishScore = 0; - double bearishScore = 0; - double scoreMultiplier = 1.5; - conditions.GenerateScore( - bullishScore, - bearishScore // - ); - - // - bool isBullishScorePassed = bullishScore > 0 && - bearishScore >= 0 && - bullishScore > bearishScore * scoreMultiplier; - - // - bool isBearishScorePassed = bearishScore > 0 && - bullishScore >= 0 && - bearishScore > bullishScore * scoreMultiplier; - - // - // VWap ... - - // - double vwapFast = conditions.vwapFastBuffer[0]; - double vwapMid = conditions.vwapMidBuffer[0]; - double vwapSlow = conditions.vwapSlowBuffer[0]; - - // - bool isVWapInside = - // - vwapFast > zone.lower && - vwapFast < zone.upper - // - && - vwapMid > zone.lower && - vwapMid < zone.upper - // - ; - - // - bool isVWapBullish = - // - (conditions.isVWapBullishState && - conditions.isVWapSwitchedToBullishOrdered) - // - || - // - (conditions.isVWapBullishOrdered && - conditions.isVWapSwitchedToBullishState) - // - ; - - // - bool isVWapBearish = - // - (conditions.isVWapBearishState && - conditions.isVWapSwitchedToBearishOrdered) - // - || - // - (conditions.isVWapBearishOrdered && - conditions.isVWapSwitchedToBearishState) - // - ; - - // - // X3Ma ... - - // - double x3maFast = conditions.x3maFastBuffer[0]; - double x3maMid = conditions.x3maMidBuffer[0]; - double x3maSlow = conditions.x3maSlowBuffer[0]; - - // - bool isX3MaInside = - // - x3maFast > zone.lower && - x3maFast < zone.upper - // - && - x3maMid > zone.lower && - x3maMid < zone.upper - // - ; - - // - bool isX3MaBullish = - // - (conditions.isX3MaBullishState && - conditions.isX3MaSwitchedToBullishOrdered) - // - || - // - (conditions.isX3MaBullishOrdered && - conditions.isX3MaSwitchedToBullishState) - // - ; - - // - bool isX3MaBearish = - // - (conditions.isX3MaBearishState && - conditions.isX3MaSwitchedToBearishOrdered) - // - || - // - (conditions.isX3MaBearishOrdered && - conditions.isX3MaSwitchedToBearishState) - // - ; - - // - // - // - - // - bool isInside = - // - isVWapInside || - isX3MaInside - // - ; - - // - bool isVWap3MaBullish = - isVWapBullish || - isX3MaBullish; - - // - bool isVWap3MaBearish = - isVWapBearish || - isX3MaBearish; - - // - // - // - - // - bool isDirectionalBullishPassed = - // - isInside && - isBullish && - isBullishTrend && - isVWap3MaBullish && - isBullishScorePassed - // - ; - - // - bool isDirectionalBearishPassed = - // - isInside && - isBearish && - isBearishTrend && - isVWap3MaBearish && - isBearishScorePassed - // - ; - - // - bool isDirectionalPassed = - isDirectionalBullishPassed || - isDirectionalBearishPassed; - - // - bool isReversalBullishPassed = - // - isInside && - isBullish && - isBearishTrend && - isVWap3MaBearish && - isBearishScorePassed - // - ; - - // - bool isReversalBearishPassed = - // - isInside && - isBearish && - isBullishTrend && - isVWap3MaBullish && - isBullishScorePassed - // - ; - - // - bool isReversalPassed = isReversalBullishPassed || - isReversalBearishPassed; - - // - result = isReversalPassed || - isDirectionalPassed; - - // - if (result) - { - isReversal = isReversalPassed; - } - - // - return result; -} - -/////////////////////////////////////////////////////////////////////////////// - -// if (hasWaitingZones) -// { -// // -// int idx = -1; -// int count = 0; -// XOBFVG youngest; -// bool has = false; -// XCFVG *selectedFVG; -// XCFVG *unActivatedFVGs[]; - -// // -// idx = GetYoungest(workingZone.waitingZones); -// has = IsValidIndex(idx); -// if (has) -// { -// // -// youngest = workingZone.waitingZones[idx]; -// selectedZoneDir = youngest.GetDirection(); - -// // -// if (IsBullish(selectedZoneDir)) -// { -// // -// Copy( -// analyseState.bullishFairValueGaps, -// unActivatedFVGs // -// ); -// } -// else -// { -// // -// Copy( -// analyseState.bearishFairValueGaps, -// unActivatedFVGs // -// ); -// } -// } - -// // -// count = ArraySize(unActivatedFVGs); -// has = IsValidSize(count); -// if (has) -// { -// // -// idx = GetYoungest(unActivatedFVGs); -// has = IsValidIndex(idx); -// if (has) -// { -// selectedFVG = unActivatedFVGs[idx]; -// } -// } - -// // -// has = selectedFVG != NULL; -// if (has) -// { -// // -// XCBaseObject *iObj; -// bool isCreated = drawer.CreateFairValueGap( -// selectedFVG, -// iObj // -// ); - -// // -// if (isCreated) -// { -// Print("Salam"); -// } -// } -// } - -////////////////////////////////////////////////////////////////////////////////////////// - -/** - * Check an XOBFVG instance has Required Conditions ... - * - * @param zone: XOBFVG instance ... - * @param state: XPOIState instance ... - * @param conditions: X121Conditions instance ... - * - * @return ( bool ) - */ -bool DetectInsideSelectedZoneConditions( - bool &isReversal, - XOBFVG &zone, - XPOIState &state, - X121Conditions &conditions // -) -{ - // - bool result = false; - - // - isReversal = false; - - // - result = - zone.IsValid() && - state.IsValid() && - state.HasChild(); - if (!result) - { - return result; - } - - // - bool isBullish = zone.IsBullish(); - bool isBearish = zone.IsBearish(); - - // - bool isBullishTrend = conditions.isTrendBullish || - conditions.isTrendSwitchedToBullish; - bool isBearishTrend = conditions.isTrendBearish || - conditions.isTrendSwitchedToBearish; - - // - double bullishScore = 0; - double bearishScore = 0; - double scoreMultiplier = 1.5; - conditions.GenerateScore( - bullishScore, - bearishScore // - ); - - // - bool isBullishScorePassed = bullishScore > 0 && - bearishScore >= 0 && - bullishScore > bearishScore * scoreMultiplier; - - // - bool isBearishScorePassed = bearishScore > 0 && - bullishScore >= 0 && - bearishScore > bullishScore * scoreMultiplier; - - // - // VWap ... - - // - double vwapFast = conditions.vwapFastBuffer[0]; - double vwapMid = conditions.vwapMidBuffer[0]; - double vwapSlow = conditions.vwapSlowBuffer[0]; - - // - bool isVWapInside = - // - vwapFast > zone.ob.Lower() && - vwapFast < zone.ob.Upper() - // - && - vwapMid > zone.ob.Lower() && - vwapMid < zone.ob.Upper() - // - ; - - // - bool isVWapBullish = - // - (conditions.isVWapBullishState && - conditions.isVWapSwitchedToBullishOrdered) - // - || - // - (conditions.isVWapBullishOrdered && - conditions.isVWapSwitchedToBullishState) - // - ; - - // - bool isVWapBearish = - // - (conditions.isVWapBearishState && - conditions.isVWapSwitchedToBearishOrdered) - // - || - // - (conditions.isVWapBearishOrdered && - conditions.isVWapSwitchedToBearishState) - // - ; - - // - // X3Ma ... - - // - double x3maFast = conditions.x3maFastBuffer[0]; - double x3maMid = conditions.x3maMidBuffer[0]; - double x3maSlow = conditions.x3maSlowBuffer[0]; - - // - bool isX3MaInside = - // - x3maFast > zone.ob.Lower() && - x3maFast < zone.ob.Upper() - // - && - x3maMid > zone.ob.Lower() && - x3maMid < zone.ob.Upper() - // - ; - - // - bool isX3MaBullish = - // - (conditions.isX3MaBullishState && - conditions.isX3MaSwitchedToBullishOrdered) - // - || - // - (conditions.isX3MaBullishOrdered && - conditions.isX3MaSwitchedToBullishState) - // - ; - - // - bool isX3MaBearish = - // - (conditions.isX3MaBearishState && - conditions.isX3MaSwitchedToBearishOrdered) - // - || - // - (conditions.isX3MaBearishOrdered && - conditions.isX3MaSwitchedToBearishState) - // - ; - - // - // - // - - // - bool isInside = - // - isVWapInside || - isX3MaInside - // - ; - - // - bool isVWap3MaBullish = - isVWapBullish || - isX3MaBullish; - - // - bool isVWap3MaBearish = - isVWapBearish || - isX3MaBearish; - - // - // - // - - // - bool isDirectionalBullishPassed = - // - isInside && - isBullish && - isBullishTrend && - isVWap3MaBullish && - isBullishScorePassed - // - ; - - // - bool isDirectionalBearishPassed = - // - isInside && - isBearish && - isBearishTrend && - isVWap3MaBearish && - isBearishScorePassed - // - ; - - // - bool isDirectionalPassed = - isDirectionalBullishPassed || - isDirectionalBearishPassed; - - // - bool isReversalBullishPassed = - // - isInside && - isBullish && - isBearishTrend && - isVWap3MaBearish && - isBearishScorePassed - // - ; - - // - bool isReversalBearishPassed = - // - isInside && - isBearish && - isBullishTrend && - isVWap3MaBullish && - isBullishScorePassed - // - ; - - // - bool isReversalPassed = isReversalBullishPassed || - isReversalBearishPassed; - - // - result = isReversalPassed || - isDirectionalPassed; - - // - if (result) - { - isReversal = isReversalPassed; - } - - // - return result; -} - -bool DetectBreakedSelectedZoneConditions( - bool &isReversal, - XOBFVG &zone, - XPOIState &mtfState, - XPOIState &stfState, - XPOIState &ttfState, - X121Conditions &conditions // -) -{ - // - bool result = false; - - // - isReversal = false; - - // - result = - // - zone.IsValid() && - mtfState.IsValid() && - stfState.IsValid() && - ttfState.IsValid() && - mtfState.HasChild() && - stfState.HasChild() && - ttfState.HasChild() - // - ; - if (!result) - { - return result; - } - - // - XBoxZone iBox; - result = ToBox( - iBox, - zone.ob // - ); - if (!result) - { - return result; - } - - // - ENUM_X_DIRECTION iDir = iBox.dir; - bool isBullish = IsBullish(iDir); - bool isBearish = IsBearish(iDir); - - // - // X3Ma ... - - // - double x3maFast = conditions.x3maFastBuffer[0]; - double x3maMid = conditions.x3maMidBuffer[0]; - double x3maSlow = conditions.x3maSlowBuffer[0]; - - // - bool isX3mInside = - // - (x3maFast < iBox.upper && - x3maMid < iBox.upper && - x3maSlow < iBox.upper) - // - && - // - (x3maFast > iBox.lower && - x3maMid > iBox.lower && - x3maSlow > iBox.lower) - // - ; - - // - bool isBullishConditions = - isBullish && - isX3mInside; - - // - bool isBearishConditions = - isBearish && - isX3mInside; - - // - result = isBullishConditions || - isBearishConditions; - - // - return result; -} - -/** - * Detect Targets Based on Selected Zone for Specified type of Directions ... - * - * @param targets: double Collection ... - * @param selectedZone: XOBFVG instance, selected Zone ... - * @param forDir: ENUM_X_DIRECTION specified Position Direction ... - * @param workingone: X121SMCStrategyXWZWorkingZone instance, Specified Working Zone ... - * @param barIndex: int Specified Bar Index ... - * - * @return ( bool ) - */ -bool DetectSelectedZonesTargets( - double &targets[], - XOBFVG &selectedZone, - ENUM_X_DIRECTION forDir, - ENUM_X121SMC_XWZ_PRIORITY forPriority, - X121SMCStrategyXWZWorkingZone &workingZone, - int barIndex = 0 // -) -{ - // - bool result = false; - - // - Clean(targets); - - // - if (barIndex < 0) - { - barIndex = 0; - } - - // - if (barIndex == 0) - { - barIndex++; - } - - // - result = - // - selectedZone.IsValid() && - HasDirection(forDir) && - workingZone.IsValid() && - forPriority != X121SMC_XWZ_PRIORITY_NONE - // - ; - if (!result) - { - return result; - } - - // - bool isBullish = IsBullish(forDir); - - // - XOHCL cBar; - result = cBar.Init( - workingZone.symbol, - workingZone.period, - barIndex // - ); - if (!result) - { - // - cBar.Clean(); - return result; - } - - // - int idx = -1; - bool has = false; - XOBFVG tmpZones[]; - - // - // Based On Waiting Zones ... - has = workingZone.HasWaitingZones(); - if (has) - { - // - Copy( - workingZone.waitingZones, - tmpZones // - ); - - // - while (HasChild(tmpZones)) - { - // - XOBFVG iOBFVG; - - // - idx = GetYoungest(tmpZones); - if (!IsValidIndex(idx)) - { - // - iOBFVG.Clean(); - break; - } - - // - iOBFVG = tmpZones[idx]; - ArrayRemove( - tmpZones, - idx, - 1 // - ); - - // - double iTarget = - isBullish - ? iOBFVG.ob.Lower() - : iOBFVG.ob.Upper(); - - // - has = - isBullish - ? cBar.high < iTarget - : cBar.low > iTarget; - - // - if (has) - { - // - Add( - iTarget, - targets // - ); - } - - // - iOBFVG.Clean(); - } - - // - Clean(tmpZones); - } - - // - // Based On Breaked Zones ... - has = workingZone.HasBreakedZones(); - if (has) - { - Copy( - workingZone.breakedZones, - tmpZones // - ); - - // - while (HasChild(tmpZones)) - { - // - XOBFVG iOBFVG; - - // - idx = GetYoungest(tmpZones); - if (!IsValidIndex(idx)) - { - // - iOBFVG.Clean(); - break; - } - - // - iOBFVG = tmpZones[idx]; - ArrayRemove( - tmpZones, - idx, - 1 // - ); - - // - double iTarget = - isBullish - ? iOBFVG.ob.Lower() - : iOBFVG.ob.Upper(); - - // - has = - isBullish - ? cBar.high < iTarget - : cBar.low > iTarget; - - // - if (has) - { - // - Add( - iTarget, - targets // - ); - } - - // - iOBFVG.Clean(); - } - - // - Clean(tmpZones); - } - - // - // Based On Priority ... - has = forPriority != X121SMC_XWZ_PRIORITY_NONE; - if (has) - { - // - switch (forPriority) - { - // - case X121SMC_XWZ_PRIORITY_WEAK: - // - if (isBullish) - { - // - // Weak ... - Add( - workingZone.supplyZone.Lower(), - targets // - ); - } - else - { - // - // Weak ... - Add( - workingZone.demandZone.Upper(), - targets // - ); - } - break; - - // - case X121SMC_XWZ_PRIORITY_LOW: - // - if (isBullish) - { - // - // Weak ... - Add( - workingZone.supplyZone.Lower(), - targets // - ); - - // - // Low ... - Add( - workingZone.quarter1, - targets // - ); - } - else - { - // - // Weak ... - Add( - workingZone.demandZone.Upper(), - targets // - ); - - // - // Low ... - Add( - workingZone.quarter3, - targets // - ); - } - break; - - // - case X121SMC_XWZ_PRIORITY_REGULAR: - // - if (isBullish) - { - // - // Weak ... - Add( - workingZone.supplyZone.Lower(), - targets // - ); - - // - // Low ... - Add( - workingZone.quarter1, - targets // - ); - - // - // Regular ... - Add( - workingZone.quarter2, - targets // - ); - } - else - { - // - // Weak ... - Add( - workingZone.demandZone.Upper(), - targets // - ); - - // - // Low ... - Add( - workingZone.quarter3, - targets // - ); - - // - // Regular ... - Add( - workingZone.quarter2, - targets // - ); - } - break; - - // - case X121SMC_XWZ_PRIORITY_HIGH: - // - if (isBullish) - { - // - // Weak ... - Add( - workingZone.supplyZone.Lower(), - targets // - ); - - // - // Low ... - Add( - workingZone.quarter1, - targets // - ); - - // - // Regular ... - Add( - workingZone.quarter2, - targets // - ); - - // - // High ... - Add( - workingZone.quarter3, - targets // - ); - } - else - { - // - // Weak ... - Add( - workingZone.demandZone.Upper(), - targets // - ); - - // - // Low ... - Add( - workingZone.quarter3, - targets // - ); - - // - // Regular ... - Add( - workingZone.quarter2, - targets // - ); - - // - // High ... - Add( - workingZone.quarter1, - targets // - ); - } - break; - - // - case X121SMC_XWZ_PRIORITY_STRONG_HIGH: - // - if (isBullish) - { - // - // Weak ... - Add( - workingZone.supplyZone.Lower(), - targets // - ); - - // - // Low ... - Add( - workingZone.quarter1, - targets // - ); - - // - // Regular ... - Add( - workingZone.quarter2, - targets // - ); - - // - // High ... - Add( - workingZone.quarter3, - targets // - ); - - // - // Strong High ... - Add( - workingZone.demandZone.Upper(), - targets // - ); - } - else - { - // - // Weak ... - Add( - workingZone.demandZone.Upper(), - targets // - ); - - // - // Low ... - Add( - workingZone.quarter3, - targets // - ); - - // - // Regular ... - Add( - workingZone.quarter2, - targets // - ); - - // - // High ... - Add( - workingZone.quarter1, - targets // - ); - - // - // Strong High ... - Add( - workingZone.supplyZone.Lower(), - targets // - ); - } - break; - } - } - - // - result = HasChild(targets); - - // - // Cleanup ... - cBar.Clean(); - Clean(tmpZones); - - // - return result; -} - -/** - * Detect Targets Based on Selected Zone for Specified type of Directions ... - * - * @param targets: double Collection ... - * @param selectedZone: XBoxZone instance, selected Zone ... - * @param forDir: ENUM_X_DIRECTION specified Position Direction ... - * @param workingone: X121SMCStrategyXWZWorkingZone instance, Specified Working Zone ... - * @param barIndex: int Specified Bar Index ... - * - * @return ( bool ) - */ -bool DetectSelectedZonesTargets( - double &targets[], - XBoxZone &selectedZone, - ENUM_X_DIRECTION forDir, - ENUM_X121SMC_XWZ_PRIORITY forPriority, - X121SMCStrategyXWZWorkingZone &workingZone, - int barIndex = 0 // -) -{ - // - bool result = false; - - // - Clean(targets); - - // - if (barIndex < 0) - { - barIndex = 0; - } - - // - if (barIndex == 0) - { - barIndex++; - } - - // - result = - // - selectedZone.IsValid() && - HasDirection(forDir) && - workingZone.IsValid() && - forPriority != X121SMC_XWZ_PRIORITY_NONE - // - ; - if (!result) - { - return result; - } - - // - bool isBullish = IsBullish(forDir); - - // - XOHCL cBar; - result = cBar.Init( - workingZone.symbol, - workingZone.period, - barIndex // - ); - if (!result) - { - // - cBar.Clean(); - return result; - } - - // - int idx = -1; - bool has = false; - XOBFVG tmpZones[]; - - // - // Based On Waiting Zones ... - has = workingZone.HasWaitingZones(); - if (has) - { - // - Copy( - workingZone.waitingZones, - tmpZones // - ); - - // - while (HasChild(tmpZones)) - { - // - XOBFVG iOBFVG; - - // - idx = GetYoungest(tmpZones); - if (!IsValidIndex(idx)) - { - // - iOBFVG.Clean(); - break; - } - - // - iOBFVG = tmpZones[idx]; - ArrayRemove( - tmpZones, - idx, - 1 // - ); - - // - double iTarget = - isBullish - ? iOBFVG.ob.Lower() - : iOBFVG.ob.Upper(); - - // - has = - isBullish - ? cBar.high < iTarget - : cBar.low > iTarget; - - // - if (has) - { - // - Add( - iTarget, - targets // - ); - } - - // - iOBFVG.Clean(); - } - - // - Clean(tmpZones); - } - - // - // Based On Breaked Zones ... - has = workingZone.HasBreakedZones(); - if (has) - { - Copy( - workingZone.breakedZones, - tmpZones // - ); - - // - while (HasChild(tmpZones)) - { - // - XOBFVG iOBFVG; - - // - idx = GetYoungest(tmpZones); - if (!IsValidIndex(idx)) - { - // - iOBFVG.Clean(); - break; - } - - // - iOBFVG = tmpZones[idx]; - ArrayRemove( - tmpZones, - idx, - 1 // - ); - - // - double iTarget = - isBullish - ? iOBFVG.ob.Lower() - : iOBFVG.ob.Upper(); - - // - has = - isBullish - ? cBar.high < iTarget - : cBar.low > iTarget; - - // - if (has) - { - // - Add( - iTarget, - targets // - ); - } - - // - iOBFVG.Clean(); - } - - // - Clean(tmpZones); - } - - // - // Based On Priority ... - has = forPriority != X121SMC_XWZ_PRIORITY_NONE; - if (has) - { - // - switch (forPriority) - { - // - case X121SMC_XWZ_PRIORITY_WEAK: - // - if (isBullish) - { - // - // Weak ... - Add( - workingZone.supplyZone.Lower(), - targets // - ); - } - else - { - // - // Weak ... - Add( - workingZone.demandZone.Upper(), - targets // - ); - } - break; - - // - case X121SMC_XWZ_PRIORITY_LOW: - // - if (isBullish) - { - // - // Weak ... - Add( - workingZone.supplyZone.Lower(), - targets // - ); - - // - // Low ... - Add( - workingZone.quarter1, - targets // - ); - } - else - { - // - // Weak ... - Add( - workingZone.demandZone.Upper(), - targets // - ); - - // - // Low ... - Add( - workingZone.quarter3, - targets // - ); - } - break; - - // - case X121SMC_XWZ_PRIORITY_REGULAR: - // - if (isBullish) - { - // - // Weak ... - Add( - workingZone.supplyZone.Lower(), - targets // - ); - - // - // Low ... - Add( - workingZone.quarter1, - targets // - ); - - // - // Regular ... - Add( - workingZone.quarter2, - targets // - ); - } - else - { - // - // Weak ... - Add( - workingZone.demandZone.Upper(), - targets // - ); - - // - // Low ... - Add( - workingZone.quarter3, - targets // - ); - - // - // Regular ... - Add( - workingZone.quarter2, - targets // - ); - } - break; - - // - case X121SMC_XWZ_PRIORITY_HIGH: - // - if (isBullish) - { - // - // Weak ... - Add( - workingZone.supplyZone.Lower(), - targets // - ); - - // - // Low ... - Add( - workingZone.quarter1, - targets // - ); - - // - // Regular ... - Add( - workingZone.quarter2, - targets // - ); - - // - // High ... - Add( - workingZone.quarter3, - targets // - ); - } - else - { - // - // Weak ... - Add( - workingZone.demandZone.Upper(), - targets // - ); - - // - // Low ... - Add( - workingZone.quarter3, - targets // - ); - - // - // Regular ... - Add( - workingZone.quarter2, - targets // - ); - - // - // High ... - Add( - workingZone.quarter1, - targets // - ); - } - break; - - // - case X121SMC_XWZ_PRIORITY_STRONG_HIGH: - // - if (isBullish) - { - // - // Weak ... - Add( - workingZone.supplyZone.Lower(), - targets // - ); - - // - // Low ... - Add( - workingZone.quarter1, - targets // - ); - - // - // Regular ... - Add( - workingZone.quarter2, - targets // - ); - - // - // High ... - Add( - workingZone.quarter3, - targets // - ); - - // - // Strong High ... - Add( - workingZone.demandZone.Upper(), - targets // - ); - } - else - { - // - // Weak ... - Add( - workingZone.demandZone.Upper(), - targets // - ); - - // - // Low ... - Add( - workingZone.quarter3, - targets // - ); - - // - // Regular ... - Add( - workingZone.quarter2, - targets // - ); - - // - // High ... - Add( - workingZone.quarter1, - targets // - ); - - // - // Strong High ... - Add( - workingZone.supplyZone.Lower(), - targets // - ); - } - break; - } - } - - // - result = HasChild(targets); - - // - // Cleanup ... - cBar.Clean(); - Clean(tmpZones); - - // - return result; -} - -/** - * Detect SL Candidates Based on Selected Zone for Specified type of Directions ... - * - * @param sls: double Collection ... - * @param selectedZone: XOBFVG instance, selected Zone ... - * @param forDir: ENUM_X_DIRECTION specified Position Direction ... - * @param workingZone: X121SMCStrategyXWZWorkingZone instance, Specified Working Zone ... - * @param barIndex: int Specified Bar Index ... - * @param maxAllowedSLDistanceInPoint: doube max Allowe SL distance ... - * - * @return ( bool ) - */ -bool DetectSelectedZoneSLCandidates( - double &sls[], - XOBFVG &selectedZone, - ENUM_X_DIRECTION forDir, - X121SMCStrategyXWZWorkingZone &workingZone, - X121Conditions &conditions, - int barIndex = 0, - double maxAllowedSLDistanceInPoint = 300 // -) -{ - // - bool result = false; - - // - Clean(sls); - - // - if (barIndex < 0) - { - barIndex = 0; - } - - // - if (barIndex == 0) - { - barIndex++; - } - - // - result = - // - selectedZone.IsValid() && - HasDirection(forDir) && - workingZone.IsValid() - // - ; - if (!result) - { - return result; - } - - // - bool isBullish = IsBullish(forDir); - - // - double pivot = - isBullish - ? selectedZone.ob.Lower() - : selectedZone.ob.Upper(); - double points = GetPoints(workingZone.symbol); - - // - XOHCL cBar; - result = cBar.Init( - workingZone.symbol, - workingZone.period, - barIndex // - ); - if (!result) - { - // - cBar.Clean(); - return result; - } - - // - int idx = -1; - bool has = false; - - // - double pvSL = isBullish - ? conditions.valesBuffer[0] - : conditions.peaksBuffer[1]; - - // - Add( - pvSL, - sls // - ); - - // - // Based On Passed Bars ... - // XOHCL passedBar; - // bool isPassed = false; - // bool isBodyState = false; - // ENUM_X_DIRECTION passedDir = selectedZone.GetDirection(); - - // // - // // Started Bar ... - // isPassed = selectedZone.ob.IsStarted( - // passedDir, - // passedBar, - // isBodyState // - // ); - // if (isPassed) - // { - // // - // double iSL = - // isBullish - // ? passedBar.low - // : passedBar.high; - // double iSLDiff = MathAbs(iSL - pivot); - // has = - // iSLDiff > 0 && - // iSLDiff <= maxAllowedSLDistanceInPoint * points; - // if (has) - // { - // // - // Add( - // iSL, - // sls // - // ); - // } - // } - - // // - // // Activation Bar ... - // passedBar.Clean(); - // isPassed = selectedZone.ob.IsActivated( - // passedDir, - // passedBar, - // isBodyState // - // ); - // if (isPassed) - // { - // // - // double iSL = - // isBullish - // ? passedBar.low - // : passedBar.high; - // double iSLDiff = MathAbs(iSL - pivot); - // has = - // iSLDiff > 0 && - // iSLDiff <= maxAllowedSLDistanceInPoint * points; - // if (has) - // { - // // - // Add( - // iSL, - // sls // - // ); - // } - // } - - // // - // // Worked Bar ... - // passedBar.Clean(); - // isPassed = selectedZone.ob.IsActivated( - // passedDir, - // passedBar, - // isBodyState // - // ); - // if (isPassed) - // { - // // - // double iSL = - // isBullish - // ? passedBar.low - // : passedBar.high; - // double iSLDiff = MathAbs(iSL - pivot); - // has = - // iSLDiff > 0 && - // iSLDiff <= maxAllowedSLDistanceInPoint * points; - // if (has) - // { - // // - // Add( - // iSL, - // sls // - // ); - // } - // } - - // // - // // Breaked Bar ... - // passedBar.Clean(); - // isPassed = selectedZone.ob.IsActivated( - // passedDir, - // passedBar, - // isBodyState // - // ); - // if (isPassed) - // { - // // - // double iSL = - // isBullish - // ? passedBar.low - // : passedBar.high; - // double iSLDiff = MathAbs(iSL - pivot); - // has = - // iSLDiff > 0 && - // iSLDiff <= maxAllowedSLDistanceInPoint * points; - // if (has) - // { - // // - // Add( - // iSL, - // sls // - // ); - // } - // } - - // - // Based On Consolidation Zones ... - has = workingZone.HasConsolidationZones(); - if (has) - { - // - XConsolidationZone tmpZones[]; - Copy( - workingZone.consolidationZones, - tmpZones // - ); - XConsolidationZone selectedConsolidationZone; - - // - while (HasChild(tmpZones)) - { - // - idx = GetYoungest(tmpZones); - if (!IsValidIndex(idx)) - { - break; - } - - // - XConsolidationZone iZone = tmpZones[idx]; - - // - ArrayRemove( - tmpZones, - idx, - 1 // - ); - - // - has = - !selectedConsolidationZone.IsValid() - ? isBullish - ? cBar.low < iZone.upper - : cBar.high < iZone.lower - : isBullish - ? selectedConsolidationZone.lower < iZone.lower - : selectedConsolidationZone.upper > iZone.upper; - if (has) - { - // - selectedConsolidationZone = iZone; - iZone.Clean(); - break; - } - - // - iZone.Clean(); - } - - // - Clean(tmpZones); - has = selectedConsolidationZone.IsValid(); - if (has) - { - // - double iSL = - isBullish - ? selectedConsolidationZone.lower - : selectedConsolidationZone.upper; - double iSLDiff = MathAbs(iSL - pivot); - has = - iSLDiff > 0 && - iSLDiff <= maxAllowedSLDistanceInPoint * points; - if (has) - { - // - Add( - iSL, - sls // - ); - } - } - } - - // - // Based On Supply and Demand Zones ... - - // - // Demand Zones ... - has = workingZone.HasDemandZones(); - if (has) - { - // - XCDemandZone *tmpZones[]; - Copy( - workingZone.demandZones, - tmpZones // - ); - XCDemandZone *selectedDemand = NULL; - - // - while (HasChild(tmpZones)) - { - // - idx = GetLowest(tmpZones); - has = IsValidIndex(idx); - if (!has) - { - break; - } - - // - XCDemandZone *iZone = tmpZones[idx]; - ArrayRemove( - tmpZones, - idx, - 1 // - ); - - // - // Validate Zone ... - has = - isBullish - ? IsBelowDiff( - iZone, - selectedZone.ob, - true // Ignore Inside ... - ) - : IsAboveDiff( - iZone, - selectedZone.ob, - true // Ignore Inside ... - ); - if (!has) - { - continue; - } - - // - has = - selectedDemand == NULL - ? true - : isBullish - ? selectedDemand.Lower() < iZone.Lower() - : selectedDemand.Upper() > iZone.Upper(); - if (!has) - { - continue; - } - - // - selectedDemand = iZone; - } - - // - has = selectedDemand != NULL; - if (has) - { - // - double iSL = - isBullish - ? selectedDemand.Lower() - : selectedDemand.Upper(); - double iSLDiff = MathAbs(iSL - pivot); - has = - iSLDiff > 0 && - iSLDiff <= maxAllowedSLDistanceInPoint * points; - if (has) - { - // - Add( - iSL, - sls // - ); - } - } - - // - Clean(tmpZones); - ZeroMemory(selectedDemand); - } - - // - // Support Zones ... - // has = workingZone.HasSupportZones(); - // if (has) - // { - // // - // XCSupportZone *tmpZones[]; - // Copy( - // workingZone.supportZones, - // tmpZones // - // ); - // XCSupportZone *selectedSupport = NULL; - - // // - // while (HasChild(tmpZones)) - // { - // // - // idx = GetLowest(tmpZones); - // has = IsValidIndex(idx); - // if (!has) - // { - // break; - // } - - // // - // XCSupportZone *iZone = tmpZones[idx]; - // ArrayRemove( - // tmpZones, - // idx, - // 1 // - // ); - - // // - // // Validate Zone ... - // has = - // isBullish - // ? IsBelowDiff( - // iZone, - // selectedZone.ob, - // true // Ignore Inside ... - // ) - // : IsAboveDiff( - // iZone, - // selectedZone.ob, - // true // Ignore Inside ... - // ); - // if (!has) - // { - // continue; - // } - - // // - // has = - // selectedSupport == NULL - // ? true - // : isBullish - // ? selectedSupport.Lower() < iZone.Lower() - // : selectedSupport.Upper() > iZone.Upper(); - // if (!has) - // { - // continue; - // } - - // // - // selectedSupport = iZone; - - // // - // } - - // // - // has = selectedSupport != NULL; - // if (has) - // { - // // - // double iSL = isBullish - // ? selectedSupport.Lower() - // : selectedSupport.Upper(); - // double iSLDiff = MathAbs(iSL - pivot); - // has = - // iSLDiff > 0 && - // iSLDiff <= maxAllowedSLDistanceInPoint * points; - // if (has) - // { - // // - // Add( - // iSL, - // sls // - // ); - // } - // } - - // // - // Clean(tmpZones); - // ZeroMemory(selectedSupport); - // } - - // - // Supply Zones ... - has = workingZone.HasSupplyZones(); - if (has) - { - // - XCSupplyZone *tmpZones[]; - Copy( - workingZone.supplyZones, - tmpZones // - ); - XCSupplyZone *selectedSupply = NULL; - - // - while (HasChild(tmpZones)) - { - // - idx = GetHighest(tmpZones); - has = IsValidIndex(idx); - if (!has) - { - break; - } - - // - XCSupplyZone *iZone = tmpZones[idx]; - ArrayRemove( - tmpZones, - idx, - 1 // - ); - - // - // Validate Zone ... - has = - !isBullish - ? IsAboveDiff( - iZone, - selectedZone.ob, - true // Ignore Inside ... - ) - : IsBelowDiff( - iZone, - selectedZone.ob, - true // Ignore Inside ... - ); - if (!has) - { - continue; - } - - // - has = - selectedSupply == NULL - ? true - : !isBullish - ? selectedSupply.Upper() > iZone.Upper() - : selectedSupply.Lower() < iZone.Lower(); - if (!has) - { - continue; - } - - // - selectedSupply = iZone; - - // - } - - // - has = selectedSupply != NULL; - if (has) - { - // - double iSL = - !isBullish - ? selectedSupply.Upper() - : selectedSupply.Lower(); - double iSLDiff = MathAbs(iSL - pivot); - has = - iSLDiff > 0 && - iSLDiff <= maxAllowedSLDistanceInPoint * points; - if (has) - { - // - Add( - iSL, - sls // - ); - } - } - - // - Clean(tmpZones); - ZeroMemory(selectedSupply); - } - - // - // Resistance Zones ... - // has = workingZone.HasDemandZones(); - // if (has) - // { - // // - // XCResistanceZone *tmpZones[]; - // Copy( - // workingZone.resistanceZones, - // tmpZones // - // ); - // XCResistanceZone *selectedResistance = NULL; - - // // - // while (HasChild(tmpZones)) - // { - // // - // idx = GetHighest(tmpZones); - // has = IsValidIndex(idx); - // if (!has) - // { - // break; - // } - - // // - // XCResistanceZone *iZone = tmpZones[idx]; - // ArrayRemove( - // tmpZones, - // idx, - // 1 // - // ); - - // // - // // Validate Zone ... - // has = - // !isBullish - // ? IsAboveDiff( - // iZone, - // selectedZone.ob, - // true // Ignore Inside ... - // ) - // : IsBelowDiff( - // iZone, - // selectedZone.ob, - // true // Ignore Inside ... - // ); - // if (!has) - // { - // continue; - // } - - // // - // has = - // selectedResistance == NULL - // ? true - // : !isBullish - // ? selectedResistance.Upper() < iZone.Upper() - // : selectedResistance.Lower() > iZone.Lower(); - // if (!has) - // { - // continue; - // } - - // // - // selectedResistance = iZone; - - // // - // } - - // // - // has = selectedResistance != NULL; - // if (has) - // { - // // - // double iSL = - // !isBullish - // ? selectedResistance.Upper() - // : selectedResistance.Lower(); - // double iSLDiff = MathAbs(iSL - pivot); - // has = - // iSLDiff > 0 && - // iSLDiff <= maxAllowedSLDistanceInPoint * points; - // if (has) - // { - // // - // Add( - // iSL, - // sls // - // ); - // } - // } - - // // - // Clean(tmpZones); - // ZeroMemory(selectedResistance); - // } - - // - // Cleanp Resources ... - - // - cBar.Clean(); - // passedBar.Clean(); - result = HasChild(sls); - - // - return result; -} - -//////////////////////////////////////////////////////////////////////////////// - -/** - * Detect Targets Based on Selected Zone for Specified type of Directions ... - * - * @param targets: double Collection ... - * @param selectedZone: XBoxZone instance, selected Zone ... - * @param forDir: ENUM_X_DIRECTION specified Position Direction ... - * @param workingone: X121SMCStrategyXWZWorkingZone instance, Specified Working Zone ... - * @param barIndex: int Specified Bar Index ... - * - * @return ( bool ) - */ -bool DetectSelectedZonesTargets( - double &targets[], - XBoxZone &selectedZone, - ENUM_X_DIRECTION forDir, - ENUM_X121SMC_XWZ_PRIORITY forPriority, - X121SMCStrategyXWZWorkingZone &workingZone, - int barIndex = 0 // -) -{ - // - bool result = false; - - // - Clean(targets); - - // - if (barIndex < 0) - { - barIndex = 0; - } - - // - if (barIndex == 0) - { - barIndex++; - } - - // - result = - // - selectedZone.IsValid() && - HasDirection(forDir) && - workingZone.IsValid() && - forPriority != X121SMC_XWZ_PRIORITY_NONE - // - ; - if (!result) - { - return result; - } - - // - bool isBullish = IsBullish(forDir); - - // - XOHCL cBar; - result = cBar.Init( - workingZone.symbol, - workingZone.period, - barIndex // - ); - if (!result) - { - // - cBar.Clean(); - return result; - } - - // - int idx = -1; - bool has = false; - XOBFVG tmpZones[]; - - // - // Based On Waiting Zones ... - has = workingZone.HasWaitingZones(); - if (has) - { - // - Copy( - workingZone.waitingZones, - tmpZones // - ); - - // - while (HasChild(tmpZones)) - { - // - XOBFVG iOBFVG; - - // - idx = GetYoungest(tmpZones); - if (!IsValidIndex(idx)) - { - // - iOBFVG.Clean(); - break; - } - - // - iOBFVG = tmpZones[idx]; - ArrayRemove( - tmpZones, - idx, - 1 // - ); - - // - double iTarget = - isBullish - ? iOBFVG.ob.Lower() - : iOBFVG.ob.Upper(); - - // - has = - isBullish - ? cBar.high < iTarget - : cBar.low > iTarget; - - // - if (has) - { - // - Add( - iTarget, - targets // - ); - } - - // - iOBFVG.Clean(); - } - - // - Clean(tmpZones); - } - - // - // Based On Breaked Zones ... - has = workingZone.HasBreakedZones(); - if (has) - { - Copy( - workingZone.breakedZones, - tmpZones // - ); - - // - while (HasChild(tmpZones)) - { - // - XOBFVG iOBFVG; - - // - idx = GetYoungest(tmpZones); - if (!IsValidIndex(idx)) - { - // - iOBFVG.Clean(); - break; - } - - // - iOBFVG = tmpZones[idx]; - ArrayRemove( - tmpZones, - idx, - 1 // - ); - - // - double iTarget = - isBullish - ? iOBFVG.ob.Lower() - : iOBFVG.ob.Upper(); - - // - has = - isBullish - ? cBar.high < iTarget - : cBar.low > iTarget; - - // - if (has) - { - // - Add( - iTarget, - targets // - ); - } - - // - iOBFVG.Clean(); - } - - // - Clean(tmpZones); - } - - // - // Based On Priority ... - has = forPriority != X121SMC_XWZ_PRIORITY_NONE; - if (has) - { - // - switch (forPriority) - { - // - case X121SMC_XWZ_PRIORITY_WEAK: - // - if (isBullish) - { - // - // Weak ... - Add( - workingZone.supplyZone.Lower(), - targets // - ); - } - else - { - // - // Weak ... - Add( - workingZone.demandZone.Upper(), - targets // - ); - } - break; - - // - case X121SMC_XWZ_PRIORITY_LOW: - // - if (isBullish) - { - // - // Weak ... - Add( - workingZone.supplyZone.Lower(), - targets // - ); - - // - // Low ... - Add( - workingZone.quarter1, - targets // - ); - } - else - { - // - // Weak ... - Add( - workingZone.demandZone.Upper(), - targets // - ); - - // - // Low ... - Add( - workingZone.quarter3, - targets // - ); - } - break; - - // - case X121SMC_XWZ_PRIORITY_REGULAR: - // - if (isBullish) - { - // - // Weak ... - Add( - workingZone.supplyZone.Lower(), - targets // - ); - - // - // Low ... - Add( - workingZone.quarter1, - targets // - ); - - // - // Regular ... - Add( - workingZone.quarter2, - targets // - ); - } - else - { - // - // Weak ... - Add( - workingZone.demandZone.Upper(), - targets // - ); - - // - // Low ... - Add( - workingZone.quarter3, - targets // - ); - - // - // Regular ... - Add( - workingZone.quarter2, - targets // - ); - } - break; - - // - case X121SMC_XWZ_PRIORITY_HIGH: - // - if (isBullish) - { - // - // Weak ... - Add( - workingZone.supplyZone.Lower(), - targets // - ); - - // - // Low ... - Add( - workingZone.quarter1, - targets // - ); - - // - // Regular ... - Add( - workingZone.quarter2, - targets // - ); - - // - // High ... - Add( - workingZone.quarter3, - targets // - ); - } - else - { - // - // Weak ... - Add( - workingZone.demandZone.Upper(), - targets // - ); - - // - // Low ... - Add( - workingZone.quarter3, - targets // - ); - - // - // Regular ... - Add( - workingZone.quarter2, - targets // - ); - - // - // High ... - Add( - workingZone.quarter1, - targets // - ); - } - break; - - // - case X121SMC_XWZ_PRIORITY_STRONG_HIGH: - // - if (isBullish) - { - // - // Weak ... - Add( - workingZone.supplyZone.Lower(), - targets // - ); - - // - // Low ... - Add( - workingZone.quarter1, - targets // - ); - - // - // Regular ... - Add( - workingZone.quarter2, - targets // - ); - - // - // High ... - Add( - workingZone.quarter3, - targets // - ); - - // - // Strong High ... - Add( - workingZone.demandZone.Upper(), - targets // - ); - } - else - { - // - // Weak ... - Add( - workingZone.demandZone.Upper(), - targets // - ); - - // - // Low ... - Add( - workingZone.quarter3, - targets // - ); - - // - // Regular ... - Add( - workingZone.quarter2, - targets // - ); - - // - // High ... - Add( - workingZone.quarter1, - targets // - ); - - // - // Strong High ... - Add( - workingZone.supplyZone.Lower(), - targets // - ); - } - break; - } - } - - // - result = HasChild(targets); - - // - // Cleanup ... - cBar.Clean(); - Clean(tmpZones); - - // - return result; -} - -/////////////////////////////////////////////////////////////////////// - -// -struct X121SMCStrategyXWZWorkingZone -{ - // - // Props ... - - // - string symbol; - ENUM_TIMEFRAMES period; - - // - double quarter1; - double quarter2; - double quarter3; - - // - XCSupplyZone *supplyZone; - XCDemandZone *demandZone; - - // - XCSupplyZone *supplyZones[]; - XCDemandZone *demandZones[]; - - // - XCSupportZone *supportZones[]; - XCResistanceZone *resistanceZones[]; - - // - XOBFVG insideZones[]; - XOBFVG breakedZones[]; - XOBFVG waitingZones[]; - - // - XBoxZone insideBoxes[]; - XBoxZone breakedBoxes[]; - XConsolidationZone consolidationZones[]; - - // - CArrayObj mInsideZoneObjects; - CArrayObj mBreakedZoneObjects; - CArrayObj mWaitingZoneObjects; - CArrayObj mWorkingZoneObjects; - - // - // Constructor ... - X121SMCStrategyXWZWorkingZone() - { - Clean(); - } - - // - // Tools ... - - // - void Clean() - { - // - quarter1 = 0; - quarter2 = 0; - quarter3 = 0; - - // - symbol = NULL; - period = NULL; - - // - Clean(supplyZones); - Clean(demandZones); - - // - Clean(insideZones); - Clean(waitingZones); - Clean(breakedZones); - - // - Clean(insideBoxes); - Clean(breakedBoxes); - - // - Clean(supportZones); - Clean(resistanceZones); - - // - ZeroMemory(supplyZone); - ZeroMemory(demandZone); - - // - mInsideZoneObjects.Clear(); - mBreakedZoneObjects.Clear(); - mWaitingZoneObjects.Clear(); - mWorkingZoneObjects.Clear(); - } - - // - bool IsValid() - { - // - bool result = false; - - // - result = - // - quarter1 > 0 && - quarter2 > 0 && - quarter3 > 0 && - HasSupplyZone() && - HasDemandZone() && - quarter1 > quarter2 && - quarter2 > quarter3 - // - ; - - // - return result; - } - - // - bool Init( - string _symbol, - ENUM_TIMEFRAMES _period, - int barIndex, - XPOIState &htfState, - XPOIState &mtfState, - XPOIState &stfState, // - XPOIState &ttfState // - ) - { - // - bool result = false; - - // - if (barIndex < 0) - { - barIndex = 0; - } - - // - result = - // - IsValid(_symbol) && - IsValid(_period) && - // - htfState.IsValid() && - mtfState.IsValid() && - stfState.IsValid() && - ttfState.IsValid() && - // - htfState.HasChild() && - mtfState.HasChild() && - stfState.HasChild() && - ttfState.HasChild() - // - ; - if (!result) - { - return result; - } - - // - symbol = _symbol; - period = _period; - - // - int idx = -1; - int count = 0; - bool has = false; - - // - XOHCL zBar; - has = zBar.Init( - symbol, - period, - barIndex // - ); - result = has; - if (!result) - { - zBar.Clean(); - return result; - } - double ll5 = zBar.FindLowest(5, MODE_LOW); - double hh5 = zBar.FindHighest(5, MODE_HIGH); - zBar.Clean(); - - // - // Supply Zone ... - has = HasSupplyZone(); - if (!has) - { - // - idx = GetHighest(htfState.supplyZones); - has = IsValidIndex(idx); - if (has) - { - // - supplyZone = htfState.supplyZones[idx]; - has = hh5 < supplyZone.Lower(); - if (!has) - { - supplyZone = NULL; - } - } - } - - // - // Demand Zone ... - has = HasDemandZone(); - if (!has) - { - // - idx = GetLowest(htfState.demandZones); - has = IsValidIndex(idx); - if (has) - { - // - demandZone = htfState.demandZones[idx]; - has = ll5 > demandZone.Upper(); - if (!has) - { - demandZone = NULL; - } - } - } - - // - // Supply Zones ... - has = HasSupplyZones(); - if (!has) - { - // - count = mtfState.FilterSupplyZones( - supplyZones, - period, - XZONE_STATE_PASSED, - false, - XZONE_STATE_FAILED, - false, - XZONE_STATE_FAILED, - false, - XZONE_STATE_IGNORED, - false // - ); - } - - // - // Demand Zones ... - has = HasDemandZones(); - if (!has) - { - // - count = mtfState.FilterDemandZones( - demandZones, - period, - XZONE_STATE_PASSED, - false, - XZONE_STATE_FAILED, - false, - XZONE_STATE_FAILED, - false, - XZONE_STATE_IGNORED, - false // - ); - } - - // - has = ttfState.HasConsolidationZones(); - if (has) - { - // - Copy( - ttfState.consolidationZones, - consolidationZones // - ); - CleanupArray( - consolidationZones, - 50 // - ); - } - - // - if (supplyZone != NULL && - demandZone != NULL && - supplyZone.IsValid() && - demandZone.IsValid()) - { - // - double upper = supplyZone.Lower(); - double lower = demandZone.Upper(); - - // - double delta = ((upper - lower) / 100) * 25; - - // - quarter1 = upper - (1 * delta); - quarter2 = upper - (2 * delta); - quarter3 = upper - (3 * delta); - } - - // - // Detect OBFVG(s) ... - ExtractOBFVGs( - waitingZones, - mtfState, - stfState); - - // - result = IsValid(); - if (!result) - { - Clean(); - } - - // - return result; - } - - // - void Update( - int barIndex, - XPOIState &htfState, - XPOIState &mtfState, - XPOIState &stfState, - XPOIState &ttfState // - ) - { - // - int idx = -1; - int count = 0; - bool has = false; - - // - if (barIndex < 0) - { - barIndex = 0; - } - - // - has = - // - IsValid() && - // - htfState.IsValid() && - mtfState.IsValid() && - stfState.IsValid() && - // - htfState.HasChild() && - mtfState.HasChild() && - stfState.HasChild() - // - ; - if (!has) - { - return; - } - - // - XOHCL zBar; - has = zBar.Init( - symbol, - period, - barIndex // - ); - if (!has) - { - // - zBar.Clean(); - return; - } - - // - XOHCL cBar; - has = zBar.GetPreviousBar(cBar); - if (!has) - { - // - zBar.Clean(); - cBar.Clean(); - - // - return; - } - - // - // Adding New OBFVG to Waiting Zones if not Exists ... - XOBFVG tmpWaitingZones[]; - count = ExtractOBFVGs( - tmpWaitingZones, - mtfState, - stfState // - ); - has = IsValidSize(count); - if (has) - { - // - AddIfNotExists( - tmpWaitingZones, - waitingZones // - ); - } - - // - // Since Usig States for Extracting Supply/Demand or - // Support/Resistance Zones and State's has Max Alllowed Restrication ... - // we have to Manage new Zones and also Hold's Breaked Zones ... - - // - // MTF STF ... - - // - // Supply Zones ... - XCSupplyZone *tmpSupplies[]; - count = mtfState.FilterSupplyZones( - tmpSupplies, - NULL, - XZONE_STATE_PASSED, - false, - XZONE_STATE_FAILED, - false, - XZONE_STATE_FAILED, - false, - XZONE_STATE_IGNORED, - false // - ); - has = IsValidSize(count); - if (has) - { - // - for (int i = 0; i < count; i++) - { - // - XBoxZone iBox; - has = ToBox( - iBox, - tmpSupplies[i] // - ); - if (!has) - { - // - iBox.Clean(); - continue; - } - - // - // Find Index ... - - // - idx = FindIndex( - iBox, - insideBoxes // - ); - has = !IsValidIndex(idx); - if (!has) - { - // - iBox.Clean(); - continue; - } - - // - idx = FindIndex( - iBox, - breakedBoxes // - ); - has = !IsValidIndex(idx); - if (!has) - { - // - iBox.Clean(); - continue; - } - - // - idx = FindIndex( - tmpSupplies[i], - supplyZones // - ); - has = !IsValidIndex(idx); - if (!has) - { - // - iBox.Clean(); - continue; - } - - // - // Checking Price Validation ... - has = cBar.high < tmpSupplies[i].Lower(); - if (!has) - { - // - iBox.Clean(); - continue; - } - - // - Add( - tmpSupplies[i], - supplyZones // - ); - - // - iBox.Clean(); - } - } - Clean(tmpSupplies); - - // - // Demand Zones ... - XCDemandZone *tmpDemands[]; - count = mtfState.FilterDemandZones( - tmpDemands, - NULL, - XZONE_STATE_PASSED, - false, - XZONE_STATE_FAILED, - false, - XZONE_STATE_FAILED, - false, - XZONE_STATE_IGNORED, - false // - ); - has = IsValidSize(count); - if (has) - { - // - for (int i = 0; i < count; i++) - { - // - XBoxZone iBox; - has = ToBox( - iBox, - tmpDemands[i] // - ); - if (!has) - { - // - iBox.Clean(); - continue; - } - - // - // Find Index ... - - // - idx = FindIndex( - iBox, - insideBoxes // - ); - has = !IsValidIndex(idx); - if (!has) - { - // - iBox.Clean(); - continue; - } - - // - idx = FindIndex( - iBox, - breakedBoxes // - ); - has = !IsValidIndex(idx); - if (!has) - { - // - iBox.Clean(); - continue; - } - - // - idx = FindIndex( - tmpDemands[i], - demandZones // - ); - has = !IsValidIndex(idx); - if (!has) - { - // - iBox.Clean(); - continue; - } - - // - // Checking Price Validation ... - has = cBar.low > tmpDemands[i].Upper(); - if (!has) - { - // - iBox.Clean(); - continue; - } - - // - Add( - tmpDemands[i], - demandZones // - ); - - // - iBox.Clean(); - } - } - Clean(tmpDemands); - - // - // - // - - // - // Consolidation Zones ... - has = ttfState.HasConsolidationZones(); - if (has) - { - // - Copy( - ttfState.consolidationZones, - consolidationZones // - ); - CleanupArray( - consolidationZones, - 50 // - ); - } - - // - // - // - - // - // Detect Price Inside Zones ... - has = HasWaitingZones(); - if (has) - { - // - int mustRemove[]; - count = CountWaitingZones(); - for (int i = 0; i < count; i++) - { - // - XOBFVG iOBFVG = waitingZones[i]; - - // - bool isInside = - // - zBar.high < iOBFVG.ob.Upper() && - zBar.low > iOBFVG.ob.Lower() && - // - cBar.high < iOBFVG.ob.Upper() && - cBar.low > iOBFVG.ob.Lower() - // - ; - if (isInside) - { - // - idx = FindIndex( - iOBFVG, - insideZones // - ); - has = IsValidSize(idx); - if (!has) - { - // - Add( - i, - mustRemove // - ); - - // - AddRef( - iOBFVG, - insideZones // - ); - } - } - } - - // - has = HasChild(mustRemove); - if (has) - { - // - count = ArraySize(mustRemove); - for (int i = 0; i < count; i++) - { - // - ArrayRemove( - waitingZones, - mustRemove[i], - 1 // - ); - } - } - - // - Clean(mustRemove); - } - - // - // Here we Looking for Price Inside Supply or Demand Zones ... - - // - // Supply Zones ... - has = HasSupplyZones(); - if (has) - { - // - int mustRemove[]; - count = CountSupplyZones(); - for (int i = 0; i < count; i++) - { - // - XCSupplyZone *iZone = supplyZones[i]; - - // - bool isInside = - // - zBar.high < iZone.Upper() && - zBar.low > iZone.Lower() && - // - cBar.high < iZone.Upper() && - cBar.low > iZone.Lower() - // - ; - if (isInside) - { - // - XBoxZone iBox; - has = ToBox( - iBox, - iZone // - ); - if (has) - { - // - idx = FindIndex( - iBox, - insideBoxes // - ); - has = IsValidSize(idx); - if (!has) - { - // - Add( - i, - mustRemove // - ); - - // - AddRef( - iBox, - insideBoxes // - ); - } - } - - // - iBox.Clean(); - } - } - - // - has = HasChild(mustRemove); - if (has) - { - // - count = ArraySize(mustRemove); - for (int i = 0; i < count; i++) - { - // - ArrayRemove( - supplyZones, - mustRemove[i], - 1 // - ); - } - } - - // - Clean(mustRemove); - } - - // - // Demand Zones ... - has = HasDemandZones(); - if (has) - { - // - int mustRemove[]; - count = CountDemandZones(); - for (int i = 0; i < count; i++) - { - // - XCDemandZone *iZone = demandZones[i]; - - // - bool isInside = - // - zBar.high < iZone.Upper() && - zBar.low > iZone.Lower() && - // - cBar.high < iZone.Upper() && - cBar.low > iZone.Lower() - // - ; - if (isInside) - { - // - XBoxZone iBox; - has = ToBox( - iBox, - iZone // - ); - if (has) - { - // - idx = FindIndex( - iBox, - insideBoxes // - ); - has = IsValidSize(idx); - if (!has) - { - // - Add( - i, - mustRemove // - ); - - // - AddRef( - iBox, - insideBoxes // - ); - } - } - - // - iBox.Clean(); - } - } - - // - has = HasChild(mustRemove); - if (has) - { - // - count = ArraySize(mustRemove); - for (int i = 0; i < count; i++) - { - // - ArrayRemove( - demandZones, - mustRemove[i], - 1 // - ); - } - } - - // - Clean(mustRemove); - } - - // - // Here we Detect Breaked Zone/Box (s) ... - - // // - // // Detect Breaked Zones ... - // has = HasInsideZones(); - // if (has) - // { - // // - // int mustRemove[]; - // count = CountInsideZones(); - // for (int i = 0; i < count; i++) - // { - // // - // XOBFVG iOBFVG = insideZones[i]; - // ENUM_X_DIRECTION iDir = iOBFVG.GetDirection(); - // bool isBullish = IsBullish(iDir); - - // // - // bool isBullishBreaked = - // // - // zBar.high < iOBFVG.ob.Lower() && - // cBar.high < iOBFVG.ob.Lower() - // // - // ; - - // // - // bool isBearishBreaked = - // // - // zBar.low > iOBFVG.ob.Upper() && - // cBar.low > iOBFVG.ob.Upper() - // // - // ; - - // // - // bool isBreaked = - // isBullish - // ? isBullishBreaked - // : isBearishBreaked; - - // // - // if (isBreaked) - // { - // // - // idx = FindIndex( - // iOBFVG, - // breakedZones // - // ); - // has = IsValidIndex(idx); - // if (!has) - // { - // // - // Add( - // i, - // mustRemove // - // ); - - // // - // AddRef( - // iOBFVG, - // breakedZones // - // ); - // } - // } - // } - - // // - // has = HasChild(mustRemove); - // if (has) - // { - // // - // count = ArraySize(mustRemove); - // for (int i = 0; i < count; i++) - // { - // // - // ArrayRemove( - // insideZones, - // mustRemove[i], - // 1 // - // ); - // } - // } - - // // - // Clean(mustRemove); - // } - - // // - // // Detect Breaked Boxes ... - // has = HasInsideBoxes(); - // if (has) - // { - // // - // int mustRemove[]; - // count = CountInsideBoxes(); - // for (int i = 0; i < count; i++) - // { - // // - // XBoxZone iBox = insideBoxes[i]; - // ENUM_X_DIRECTION iDir = iBox.dir; - // bool isBullish = iBox.IsBullish(); - - // // - // bool isBullishBreaked = - // // - // zBar.high < iBox.lower && - // cBar.high < iBox.lower - // // - // ; - - // // - // bool isBearishBreaked = - // // - // zBar.low > iBox.upper && - // cBar.low > iBox.upper - // // - // ; - - // // - // bool isBreaked = - // isBullish - // ? isBullishBreaked - // : isBearishBreaked; - - // // - // if (isBreaked) - // { - // // - // idx = FindIndex( - // iBox, - // breakedBoxes // - // ); - // has = IsValidIndex(idx); - // if (!has) - // { - // // - // Add( - // i, - // mustRemove // - // ); - - // // - // AddRef( - // iBox, - // breakedBoxes // - // ); - // } - // } - // } - - // // - // has = HasChild(mustRemove); - // if (has) - // { - // // - // count = ArraySize(mustRemove); - // for (int i = 0; i < count; i++) - // { - // // - // ArrayRemove( - // insideBoxes, - // mustRemove[i], - // 1 // - // ); - // } - // } - - // // - // Clean(mustRemove); - // } - - // - // Cleanup Resource ... - - // - zBar.Clean(); - cBar.Clean(); - } - - // - bool HasSupplyZone() - { - return supplyZone != NULL && - supplyZone.IsValid(); - } - - // - bool HasDemandZone() - { - return demandZone != NULL && - demandZone.IsValid(); - } - - // - bool HasSupplyZones() - { - return HasChild(supplyZones); - } - - // - int CountSupplyZones() - { - return ArraySize(supplyZones); - } - - // - bool HasDemandZones() - { - return HasChild(demandZones); - } - - // - int CountDemandZones() - { - return ArraySize(demandZones); - } - - // - bool HasSupportZones() - { - return HasChild(supportZones); - } - - // - int CountSupportZones() - { - return ArraySize(supportZones); - } - - // - bool HasResistanceZones() - { - return HasChild(resistanceZones); - } - - // - int CountResistanceZones() - { - return ArraySize(resistanceZones); - } - - // - bool HasWaitingZones() - { - return HasChild(waitingZones); - } - - // - int CountWaitingZones() - { - return ArraySize(waitingZones); - } - - // - bool HasInsideZones() - { - return HasChild(insideZones); - } - - // - int CountInsideZones() - { - return ArraySize(insideZones); - } - - // - bool HasBreakedZones() - { - return HasChild(breakedZones); - } - - // - int CountBreakedZones() - { - return ArraySize(breakedZones); - } - - // - bool HasConsolidationZones() - { - return HasChild(consolidationZones); - } - - // - int CountConsolidationZones() - { - return ArraySize(consolidationZones); - } - - // - bool HasInsideBoxes() - { - return HasChild(insideBoxes); - } - - // - int CountInsideBoxes() - { - return ArraySize(insideBoxes); - } - - // - bool HasBreakedBoxes() - { - return HasChild(breakedBoxes); - } - - // - int CountBreakedBoxes() - { - return ArraySize(breakedBoxes); - } - - // - // - // - - // - bool IsDestroyed( - int barIndex = 0, - ENUM_TIMEFRAMES forPeriod = NULL // - ) - { - // - bool result = false; - - // - if (barIndex < 0) - { - barIndex = 0; - } - - // - if (!IsValid(forPeriod)) - { - forPeriod = period; - } - - // - result = IsValid(); - if (!result) - { - return result; - } - - // - XOHCL bar; - result = bar.Init( - symbol, - period, - barIndex // - ); - if (!result) - { - // - bar.Clean(); - return result; - } - - // - XOHCL cBar; - result = bar.GetPreviousBar(cBar); - if (!result) - { - // - bar.Clean(); - cBar.Clean(); - - // - return result; - } - - // - bool isSupplyZoneBreaked = - // - bar.low > supplyZone.Upper() && - cBar.low > supplyZone.Upper() - // - ; - - // - bool isDemandZoneBreaked = - // - bar.high < demandZone.Lower() && - cBar.high < demandZone.Lower() - // - ; - - // - bar.Clean(); - cBar.Clean(); - - // - result = isSupplyZoneBreaked || - isDemandZoneBreaked; - - // - return result; - } - - // - bool DetectPriority( - ENUM_X121SMC_XWZ_PRIORITY &priority, - ENUM_X_DIRECTION forDir, - int barIndex = 0, - ENUM_TIMEFRAMES forPeriod = NULL // - ) - { - // - bool result = false; - - // - priority = X121SMC_XWZ_PRIORITY_NONE; - - // - if (barIndex < 0) - { - barIndex = 0; - } - - // - if (!IsValid(forPeriod)) - { - forPeriod = period; - } - - // - result = IsValid() && - HasDirection(forDir); - if (!result) - { - return result; - } - - // - bool isBullish = IsBullish(forDir); - - // - XOHCL bar; - result = bar.Init( - symbol, - forPeriod, - barIndex // - ); - if (!result) - { - // - bar.Clean(); - return result; - } - - // - if (bar.high < supplyZone.Upper() && - bar.low > supplyZone.Lower()) - { - // - priority = - isBullish - ? X121SMC_XWZ_PRIORITY_NONE - : X121SMC_XWZ_PRIORITY_STRONG_HIGH; - } - else if (bar.high < supplyZone.Lower() && - bar.low > quarter1) - { - // - priority = - isBullish - ? X121SMC_XWZ_PRIORITY_WEAK - : X121SMC_XWZ_PRIORITY_HIGH; - } - else if (bar.high < quarter1 && - bar.low > quarter2) - { - // - priority = - isBullish - ? X121SMC_XWZ_PRIORITY_LOW - : X121SMC_XWZ_PRIORITY_REGULAR; - } - else if (bar.high < quarter2 && - bar.low > quarter3) - { - // - priority = - isBullish - ? X121SMC_XWZ_PRIORITY_REGULAR - : X121SMC_XWZ_PRIORITY_LOW; - } - else if (bar.high < quarter3 && - bar.low > demandZone.Upper()) - { - // - priority = - isBullish - ? X121SMC_XWZ_PRIORITY_HIGH - : X121SMC_XWZ_PRIORITY_WEAK; - } - else if (bar.high < demandZone.Upper() && - bar.low > demandZone.Lower()) - { - // - priority = - isBullish - ? X121SMC_XWZ_PRIORITY_STRONG_HIGH - : X121SMC_XWZ_PRIORITY_NONE; - } - - // - result = priority != X121SMC_XWZ_PRIORITY_NONE && - priority != X121SMC_XWZ_PRIORITY_WEAK; - - // - bar.Clean(); - - // - return result; - } - - // - // - // - - // - void UpdateTo(datetime value = NULL) - { - // - value = NormalizeTime(value); - - // - int count = 0; - bool has = false; - - // - has = HasSupplyZone(); - if (has) - { - supplyZone.To(value); - } - - // - has = HasDemandZone(); - if (has) - { - demandZone.To(value); - } - - // - has = HasSupplyZones(); - if (has) - { - // - count = CountSupplyZones(); - for (int i = 0; i < count; i++) - { - supplyZones[i].To(value); - } - } - - // - has = HasDemandZones(); - if (has) - { - // - count = CountDemandZones(); - for (int i = 0; i < count; i++) - { - demandZones[i].To(value); - } - } - - // - has = HasSupportZones(); - if (has) - { - // - count = CountSupportZones(); - for (int i = 0; i < count; i++) - { - supportZones[i].To(value); - } - } - - // - has = HasResistanceZones(); - if (has) - { - // - count = CountResistanceZones(); - for (int i = 0; i < count; i++) - { - resistanceZones[i].To(value); - } - } - - // - has = HasWaitingZones(); - if (has) - { - // - count = CountWaitingZones(); - for (int i = 0; i < count; i++) - { - waitingZones[i].UpdateTo(value); - } - } - - // - has = HasInsideZones(); - if (has) - { - // - count = CountInsideZones(); - for (int i = 0; i < count; i++) - { - insideZones[i].UpdateTo(value); - } - } - - // - has = HasInsideBoxes(); - if (has) - { - // - count = CountInsideBoxes(); - for (int i = 0; i < count; i++) - { - insideBoxes[i].to = value; - } - } - - // - } - - // - void Draw( - XCPOIDrawer *drawer, - bool drawWaitingZones = true, - bool drawInsideZones = false, - bool drawBreakedZones = false, - bool drawSupplyZone = false, - bool drawDemandZone = false, - bool drawSupplyZones = false, - bool drawDemandZones = false, - bool drawSupportZones = false, - bool drawResistanceZones = false // - ) - { - // - if (drawer == NULL) - { - return; - } - - // - int count = 0; - bool has = false; - bool isCreated = false; - - // - ulong chartID = drawer.ChartIdentification(); - int subWindow = drawer.SubWindowIdentification(); - color bullishColor = drawer.BarBullishColor(); - color bearishColor = drawer.BarBearishColor(); - - // - // Supply Zone ... - if (drawSupplyZone) - { - // - has = HasSupplyZone(); - if (has) - { - // - XCSupplyZoneObject *iObj; - isCreated = drawer.CreateSupplyZone( - supplyZone, - iObj // - ); - - // - if (isCreated) - { - mWorkingZoneObjects.Add(iObj); - } - } - } - - // - // Demand Zone ... - if (drawDemandZone) - { - // - has = HasDemandZone(); - if (has) - { - // - XCDemandZoneObject *iObj; - isCreated = drawer.CreateDemandZone( - demandZone, - iObj // - ); - - // - if (isCreated) - { - mWorkingZoneObjects.Add(iObj); - } - } - } - - // - // - // - - // - // Supply Zones ... - if (drawSupplyZones) - { - // - has = HasSupplyZones(); - if (has) - { - // - count = CountSupplyZones(); - for (int i = 0; i < count; i++) - { - // - XCSupplyZoneObject *iObj; - isCreated = drawer.CreateSupplyZone( - supplyZones[i], - iObj // - ); - - // - if (isCreated) - { - mWorkingZoneObjects.Add(iObj); - } - } - } - } - - // - // Demand Zones ... - if (drawDemandZones) - { - // - has = HasDemandZones(); - if (has) - { - // - count = CountDemandZones(); - for (int i = 0; i < count; i++) - { - // - XCDemandZoneObject *iObj; - isCreated = drawer.CreateDemandZone( - demandZones[i], - iObj // - ); - - // - if (isCreated) - { - mWorkingZoneObjects.Add(iObj); - } - } - } - } - - // - // Support Zones ... - if (drawSupportZones) - { - // - has = HasSupportZones(); - if (has) - { - // - count = CountSupportZones(); - for (int i = 0; i < count; i++) - { - // - XCSupportZoneObject *iObj; - isCreated = drawer.CreateSupportZone( - supportZones[i], - iObj // - ); - - // - if (isCreated) - { - mWorkingZoneObjects.Add(iObj); - } - } - } - } - - // - // Resistance Zones ... - if (drawResistanceZones) - { - // - has = HasResistanceZones(); - if (has) - { - // - count = CountResistanceZones(); - for (int i = 0; i < count; i++) - { - // - XCResistanceZoneObject *iObj; - isCreated = drawer.CreateResistanceZone( - resistanceZones[i], - iObj // - ); - - // - if (isCreated) - { - mWorkingZoneObjects.Add(iObj); - } - } - } - } - - // - // - // - - // - // Waiting Zones ... - if (drawWaitingZones) - { - // - has = HasWaitingZones(); - if (has) - { - // - count = CountWaitingZones(); - for (int i = 0; i < count; i++) - { - // - XCBaseObject *objects[]; - int objectsCount = drawer.DrawOBFVG( - waitingZones[i], - objects // - ); - has = IsValidSize(objectsCount); - if (has) - { - // - for (int j = 0; j < objectsCount; j++) - { - mWaitingZoneObjects.Add(objects[j]); - } - } - } - } - } - - // - // Inside Zones ... - if (drawInsideZones) - { - // - // Zones ... - has = HasInsideZones(); - if (has) - { - // - count = CountInsideZones(); - for (int i = 0; i < count; i++) - { - // - XCBaseObject *objects[]; - int objectsCount = drawer.DrawOBFVG( - insideZones[i], - objects // - ); - - // - has = IsValidSize(objectsCount); - if (has) - { - // - for (int i = 0; i < objectsCount; i++) - { - mInsideZoneObjects.Add(objects[i]); - } - } - } - } - - // // - // // Boxes ... - // has = HasInsideBoxes(); - // if (has) - // { - // // - // count = CountInsideBoxes(); - // for (int i = 0; i < count; i++) - // { - // // - // XCBoxObject *object; - // bool isCreated = drawer.DrawBox( - // insideBoxes[i], - // object // - // ); - - // // - // if (isCreated) - // { - // mInsideZoneObjects.Add(object); - // } - // } - // } - } - - // - // Breaked Zones ... - if (drawBreakedZones) - { - // - has = HasBreakedZones(); - if (has) - { - // - count = CountBreakedZones(); - for (int i = 0; i < count; i++) - { - // - XCBaseObject *objects[]; - int objectsCount = drawer.DrawOBFVG( - breakedZones[i], - objects // - ); - - // - has = IsValidSize(objectsCount); - if (has) - { - // - for (int i = 0; i < objectsCount; i++) - { - mBreakedZoneObjects.Add(objects[i]); - } - } - } - } - - // // - // // Boxes ... - // has = HasBreakedBoxes(); - // if (has) - // { - // // - // count = CountBreakedBoxes(); - // for (int i = 0; i < count; i++) - // { - // // - // XCBoxObject *object; - // bool isCreated = drawer.DrawBox( - // breakedBoxes[i], - // object // - // ); - - // // - // if (isCreated) - // { - // mInsideZoneObjects.Add(object); - // } - // } - // } - } - - // - // - // - - // - // Quarters ... - has = IsValid(); - if (has) - { - // - double zoneUpper = supplyZone.Upper(); - double upper = supplyZone.Lower(); - - // - double lower = demandZone.Upper(); - double zoneLower = demandZone.Lower(); - - // - string prefix = "X121WZone_" + symbol + "_" + ToString(period); - - // - // Zone Upper ... - CChartObjectHLine *zoneUpperLine; - zoneUpperLine = new CChartObjectHLine(); - isCreated = zoneUpperLine.Create( - chartID, - prefix + "_ZoneTop", - subWindow, - zoneUpper // - ); - if (isCreated) - { - // - zoneUpperLine.Color(clrRed); - - // - mWaitingZoneObjects.Add(zoneUpperLine); - } - - // - // Zone Lower ... - CChartObjectHLine *zoneLowerLine; - zoneLowerLine = new CChartObjectHLine(); - isCreated = zoneLowerLine.Create( - chartID, - prefix + "_ZoneDown", - subWindow, - zoneLower // - ); - if (isCreated) - { - // - zoneLowerLine.Color(clrRed); - - // - mWaitingZoneObjects.Add(zoneLowerLine); - } - - // - // Upper ... - CChartObjectHLine *upperLine; - upperLine = new CChartObjectHLine(); - isCreated = upperLine.Create( - chartID, - prefix + "_Upper", - subWindow, - upper // - ); - if (isCreated) - { - // - upperLine.Color(clrLime); - - // - mWaitingZoneObjects.Add(upperLine); - } - - // - // Lower ... - CChartObjectHLine *lowerLine; - lowerLine = new CChartObjectHLine(); - isCreated = lowerLine.Create( - chartID, - prefix + "_Lower", - subWindow, - lower // - ); - if (isCreated) - { - // - lowerLine.Color(clrLime); - - // - mWaitingZoneObjects.Add(lowerLine); - } - - // - // Quarters ... - - // - // Quarter 1 ... - CChartObjectHLine *q1Line; - q1Line = new CChartObjectHLine(); - isCreated = q1Line.Create( - chartID, - prefix + "_Q1", - subWindow, - quarter1 // - ); - if (isCreated) - { - // - q1Line.Color(clrYellow); - - // - mWaitingZoneObjects.Add(q1Line); - } - - // - // Quarter 2 ... - CChartObjectHLine *q2Line; - q2Line = new CChartObjectHLine(); - isCreated = q2Line.Create( - chartID, - prefix + "_Q2", - subWindow, - quarter2 // - ); - if (isCreated) - { - // - q2Line.Color(clrYellow); - - // - mWaitingZoneObjects.Add(q2Line); - } - - // - // Quarter 3 ... - CChartObjectHLine *q3Line; - q3Line = new CChartObjectHLine(); - isCreated = q3Line.Create( - chartID, - prefix + "_Q3", - subWindow, - quarter3 // - ); - if (isCreated) - { - // - q3Line.Color(clrYellow); - - // - mWaitingZoneObjects.Add(q3Line); - } - } - } - - // -}; - -////////////////////////////////////////////////////// - -/** - * Detect Targets Based on Selected Zone for Specified type of Directions ... - * - * @param targets: double Collection ... - * @param selectedZone: XOBFVG instance, selected Zone ... - * @param forDir: ENUM_X_DIRECTION specified Position Direction ... - * @param workingone: X121SMCStrategyXWZWorkingZone instance, Specified Working Zone ... - * @param barIndex: int Specified Bar Index ... - * - * @return ( bool ) - */ -bool DetectSelectedZonesTargets( - double &targets[], - XOBFVG &selectedZone, - ENUM_X_DIRECTION forDir, - ENUM_X121SMC_XWZ_PRIORITY forPriority, - X121SMCStrategyXWZWorkingZone &workingZone, - int barIndex = 0 // -) -{ - // - bool result = false; - - // - Clean(targets); - - // - if (barIndex < 0) - { - barIndex = 0; - } - - // - if (barIndex == 0) - { - barIndex++; - } - - // - result = - // - selectedZone.IsValid() && - HasDirection(forDir) && - workingZone.IsValid() && - forPriority != X121SMC_XWZ_PRIORITY_NONE - // - ; - if (!result) - { - return result; - } - - // - bool isBullish = IsBullish(forDir); - - // - XOHCL cBar; - result = cBar.Init( - workingZone.symbol, - workingZone.period, - barIndex // - ); - if (!result) - { - // - cBar.Clean(); - return result; - } - - // - int idx = -1; - bool has = false; - - // - // Based On Priority ... - has = forPriority != X121SMC_XWZ_PRIORITY_NONE; - if (has) - { - // - switch (forPriority) - { - // - case X121SMC_XWZ_PRIORITY_WEAK: - // - if (isBullish) - { - // - // Weak ... - Add( - workingZone.supplyZone.Lower(), - targets // - ); - } - else - { - // - // Weak ... - Add( - workingZone.demandZone.Upper(), - targets // - ); - } - break; - - // - case X121SMC_XWZ_PRIORITY_LOW: - // - if (isBullish) - { - // - // Weak ... - Add( - workingZone.supplyZone.Lower(), - targets // - ); - - // - // Low ... - Add( - workingZone.quarter1, - targets // - ); - } - else - { - // - // Weak ... - Add( - workingZone.demandZone.Upper(), - targets // - ); - - // - // Low ... - Add( - workingZone.quarter3, - targets // - ); - } - break; - - // - case X121SMC_XWZ_PRIORITY_REGULAR: - // - if (isBullish) - { - // - // Weak ... - Add( - workingZone.supplyZone.Lower(), - targets // - ); - - // - // Low ... - Add( - workingZone.quarter1, - targets // - ); - - // - // Regular ... - Add( - workingZone.quarter2, - targets // - ); - } - else - { - // - // Weak ... - Add( - workingZone.demandZone.Upper(), - targets // - ); - - // - // Low ... - Add( - workingZone.quarter3, - targets // - ); - - // - // Regular ... - Add( - workingZone.quarter2, - targets // - ); - } - break; - - // - case X121SMC_XWZ_PRIORITY_HIGH: - // - if (isBullish) - { - // - // Weak ... - Add( - workingZone.supplyZone.Lower(), - targets // - ); - - // - // Low ... - Add( - workingZone.quarter1, - targets // - ); - - // - // Regular ... - Add( - workingZone.quarter2, - targets // - ); - - // - // High ... - Add( - workingZone.quarter3, - targets // - ); - } - else - { - // - // Weak ... - Add( - workingZone.demandZone.Upper(), - targets // - ); - - // - // Low ... - Add( - workingZone.quarter3, - targets // - ); - - // - // Regular ... - Add( - workingZone.quarter2, - targets // - ); - - // - // High ... - Add( - workingZone.quarter1, - targets // - ); - } - break; - - // - case X121SMC_XWZ_PRIORITY_STRONG_HIGH: - // - if (isBullish) - { - // - // Weak ... - Add( - workingZone.supplyZone.Lower(), - targets // - ); - - // - // Low ... - Add( - workingZone.quarter1, - targets // - ); - - // - // Regular ... - Add( - workingZone.quarter2, - targets // - ); - - // - // High ... - Add( - workingZone.quarter3, - targets // - ); - - // - // Strong High ... - Add( - workingZone.demandZone.Upper(), - targets // - ); - } - else - { - // - // Weak ... - Add( - workingZone.demandZone.Upper(), - targets // - ); - - // - // Low ... - Add( - workingZone.quarter3, - targets // - ); - - // - // Regular ... - Add( - workingZone.quarter2, - targets // - ); - - // - // High ... - Add( - workingZone.quarter1, - targets // - ); - - // - // Strong High ... - Add( - workingZone.supplyZone.Lower(), - targets // - ); - } - break; - } - } - - // - result = HasChild(targets); - - // - // Cleanup ... - cBar.Clean(); - Clean(tmpZones); - - // - return result; -} - -///////////////////////////////////////////////////////////// - -/** - * Check an XOBFVG instance has Required Conditions ... - * - * @param zone: XOBFVG instance ... - * @param state: XPOIState instance ... - * @param conditions: X121Conditions instance ... - * - * @return ( bool ) - */ -bool DetectInsideSelectedZoneConditions( - bool &isReversal, - XOBFVG &zone, - XPOIState &state, - X121Conditions &conditions, - int barIndex = 0 // -) -{ - // - bool result = false; - - // - isReversal = false; - - // - if (barIndex < 0) - { - barIndex = 0; - } - - // - if (barIndex == 0) - { - barIndex++; - } - - // - XOHCL bar; - result = bar.Init( - state.symbol, - state.period, - barIndex // - ); - if (!result) - { - // - bar.Clean(); - return result; - } - - // - result = - zone.IsValid() && - state.IsValid() && - state.HasChild(); - if (!result) - { - // - bar.Clean(); - return result; - } - - // - bool isBullish = zone.IsBullish(); - bool isBearish = zone.IsBearish(); - - // - double points = GetPoints(bar.symbol); - - // - double bullishScore = 0; - double bearishScore = 0; - double scoreMultiplier = 1.5; - conditions.GenerateScore( - bullishScore, - bearishScore // - ); - - // // - // bool isLowerBreaked = - // // - // conditions.isSarBearish && - // conditions.isCheBearish && - // bar.high < zone.ob.Lower() && - // bearishScore > bullishScore && - // conditions.isX3MaBearishState && - // conditions.isVWapBearishState && - // conditions.isX3MaBearishOrdered && - // conditions.isVWapBearishOrdered && - // bar.low < conditions.atrLowerBuffer[1] && - // conditions.atrLowerBuffer[1] < zone.ob.Lower() - // // - // ; - - // // - // bool isUpperBreaked = - // // - // conditions.isSarBullish && - // conditions.isCheBullish && - // bar.low > zone.ob.Upper() && - // bullishScore > bearishScore && - // conditions.isX3MaBullishState && - // conditions.isVWapBullishState && - // conditions.isX3MaBullishOrdered && - // conditions.isVWapBullishOrdered && - // bar.high > conditions.atrUpperBuffer[1] && - // conditions.atrUpperBuffer[1] > zone.ob.Upper() - // // - // ; - - // // - // bool isPeakEqualsToUpper = - // MathAbs(conditions.peaksBuffer[0] - zone.ob.Upper()) > points * 1; - - // // - // bool isValeEqualsToLower = - // MathAbs(conditions.valesBuffer[0] - zone.ob.Lower()) > points * 1; - - // - // bool isDirectionalBullishPassed = - // // - // isBullish && - // isUpperBreaked - // // ( - - // // || - // // isValeEqualsToLower) - // // - // ; - - // - // bool isDirectionalBearishPassed = - // // - // isBearish && - // isLowerBreaked - // // || - // // isPeakEqualsToUpper) - // // - // ; - - // - // bool isDirectionalPassed = - // isDirectionalBullishPassed || - // isDirectionalBearishPassed; - - // // - // bool isReversalBullishPassed = - // // - // // isBullish && - // // isLowerBreaked - // // ( || - // // isPeakEqualsToUpper) - // // - // ; - - // // - // bool isReversalBearishPassed = - // // - // // isBearish && - // // isUpperBreaked - // // || - // // isValeEqualsToLower) - // // - // ; - - // - // bool isReversalPassed = isReversalBullishPassed || - // isReversalBearishPassed; - - // - // result = isReversalPassed || - // isDirectionalPassed; - - // - result = false; - - // - if (result) - { - // isReversal = isReversalPassed; - } - - // - bar.Clean(); - return result; -} - -bool DetectBreakedSelectedZoneConditions( - bool &isReversal, - XOBFVG &zone, - XPOIState &mtfState, - XPOIState &stfState, - XPOIState &ttfState, - X121Conditions &conditions // -) -{ - // - bool result = false; - - // - isReversal = false; - - // - result = - // - zone.IsValid() && - mtfState.IsValid() && - stfState.IsValid() && - ttfState.IsValid() && - mtfState.HasChild() && - stfState.HasChild() && - ttfState.HasChild() - // - ; - if (!result) - { - return result; - } - - // - XBoxZone iBox; - result = ToBox( - iBox, - zone.ob // - ); - if (!result) - { - return result; - } - - // - ENUM_X_DIRECTION iDir = iBox.dir; - bool isBullish = IsBullish(iDir); - bool isBearish = IsBearish(iDir); - - // - // X3Ma ... - - // - double x3maFast = conditions.x3maFastBuffer[0]; - double x3maMid = conditions.x3maMidBuffer[0]; - double x3maSlow = conditions.x3maSlowBuffer[0]; - - // - bool isX3mInside = - // - (x3maFast < iBox.upper && - x3maMid < iBox.upper && - x3maSlow < iBox.upper) - // - && - // - (x3maFast > iBox.lower && - x3maMid > iBox.lower && - x3maSlow > iBox.lower) - // - ; - - // - bool isBullishConditions = - isBullish && - isX3mInside; - - // - bool isBearishConditions = - isBearish && - isX3mInside; - - // - result = isBullishConditions || - isBearishConditions; - - // - return result; -} - -/** - * Detect SL Candidates Based on Selected Zone for Specified type of Directions ... - * - * @param sls: double Collection ... - * @param selectedZone: XOBFVG instance, selected Zone ... - * @param forDir: ENUM_X_DIRECTION specified Position Direction ... - * @param workingZone: X121SMCStrategyXWZWorkingZone instance, Specified Working Zone ... - * @param barIndex: int Specified Bar Index ... - * @param maxAllowedSLDistanceInPoint: doube max Allowe SL distance ... - * - * @return ( bool ) - */ -bool DetectSelectedZoneSLCandidates( - double &sls[], - XOBFVG &selectedZone, - ENUM_X_DIRECTION forDir, - X121SMCStrategyXWZWorkingZone &workingZone, - X121Conditions &conditions, - int barIndex = 0, - double maxAllowedSLDistanceInPoint = 300 // -) -{ - // - bool result = false; - - // - Clean(sls); - - // - if (barIndex < 0) - { - barIndex = 0; - } - - // - if (barIndex == 0) - { - barIndex++; - } - - // - result = - // - selectedZone.IsValid() && - HasDirection(forDir) && - workingZone.IsValid() - // - ; - if (!result) - { - return result; - } - - // - bool isBullish = IsBullish(forDir); - - // - double pivot = - isBullish - ? selectedZone.ob.Lower() - : selectedZone.ob.Upper(); - double points = GetPoints(workingZone.symbol); - - // - XOHCL cBar; - result = cBar.Init( - workingZone.symbol, - workingZone.period, - barIndex // - ); - if (!result) - { - // - cBar.Clean(); - return result; - } - - // - int idx = -1; - bool has = false; - - // // - // double pvSL = isBullish - // ? conditions.valesBuffer[0] - // : conditions.peaksBuffer[1]; - - // // - // Add( - // pvSL, - // sls // - // ); - - // - // Based On Passed Bars ... - // XOHCL passedBar; - // bool isPassed = false; - // bool isBodyState = false; - // ENUM_X_DIRECTION passedDir = selectedZone.GetDirection(); - - // // - // // Started Bar ... - // isPassed = selectedZone.ob.IsStarted( - // passedDir, - // passedBar, - // isBodyState // - // ); - // if (isPassed) - // { - // // - // double iSL = - // isBullish - // ? passedBar.low - // : passedBar.high; - // double iSLDiff = MathAbs(iSL - pivot); - // has = - // iSLDiff > 0 && - // iSLDiff <= maxAllowedSLDistanceInPoint * points; - // if (has) - // { - // // - // Add( - // iSL, - // sls // - // ); - // } - // } - - // // - // // Activation Bar ... - // passedBar.Clean(); - // isPassed = selectedZone.ob.IsActivated( - // passedDir, - // passedBar, - // isBodyState // - // ); - // if (isPassed) - // { - // // - // double iSL = - // isBullish - // ? passedBar.low - // : passedBar.high; - // double iSLDiff = MathAbs(iSL - pivot); - // has = - // iSLDiff > 0 && - // iSLDiff <= maxAllowedSLDistanceInPoint * points; - // if (has) - // { - // // - // Add( - // iSL, - // sls // - // ); - // } - // } - - // // - // // Worked Bar ... - // passedBar.Clean(); - // isPassed = selectedZone.ob.IsActivated( - // passedDir, - // passedBar, - // isBodyState // - // ); - // if (isPassed) - // { - // // - // double iSL = - // isBullish - // ? passedBar.low - // : passedBar.high; - // double iSLDiff = MathAbs(iSL - pivot); - // has = - // iSLDiff > 0 && - // iSLDiff <= maxAllowedSLDistanceInPoint * points; - // if (has) - // { - // // - // Add( - // iSL, - // sls // - // ); - // } - // } - - // // - // // Breaked Bar ... - // passedBar.Clean(); - // isPassed = selectedZone.ob.IsActivated( - // passedDir, - // passedBar, - // isBodyState // - // ); - // if (isPassed) - // { - // // - // double iSL = - // isBullish - // ? passedBar.low - // : passedBar.high; - // double iSLDiff = MathAbs(iSL - pivot); - // has = - // iSLDiff > 0 && - // iSLDiff <= maxAllowedSLDistanceInPoint * points; - // if (has) - // { - // // - // Add( - // iSL, - // sls // - // ); - // } - // } - - // - // Based On Consolidation Zones ... - // has = workingZone.HasConsolidationZones(); - // if (has) - // { - // // - // XConsolidationZone tmpZones[]; - // Copy( - // workingZone.consolidationZones, - // tmpZones // - // ); - // XConsolidationZone selectedConsolidationZone; - - // // - // while (HasChild(tmpZones)) - // { - // // - // idx = GetYoungest(tmpZones); - // if (!IsValidIndex(idx)) - // { - // break; - // } - - // // - // XConsolidationZone iZone = tmpZones[idx]; - - // // - // ArrayRemove( - // tmpZones, - // idx, - // 1 // - // ); - - // // - // has = - // !selectedConsolidationZone.IsValid() - // ? isBullish - // ? cBar.low < iZone.upper - // : cBar.high < iZone.lower - // : isBullish - // ? selectedConsolidationZone.lower < iZone.lower - // : selectedConsolidationZone.upper > iZone.upper; - // if (has) - // { - // // - // selectedConsolidationZone = iZone; - // iZone.Clean(); - // break; - // } - - // // - // iZone.Clean(); - // } - - // // - // Clean(tmpZones); - // has = selectedConsolidationZone.IsValid(); - // if (has) - // { - // // - // double iSL = - // isBullish - // ? selectedConsolidationZone.lower - // : selectedConsolidationZone.upper; - // double iSLDiff = MathAbs(iSL - pivot); - // has = - // iSLDiff > 0 && - // iSLDiff <= maxAllowedSLDistanceInPoint * points; - // if (has) - // { - // // - // Add( - // iSL, - // sls // - // ); - // } - // } - // } - - // - // Based On Supply and Demand Zones ... - - // - // Demand Zones ... - // has = workingZone.HasDemandZones(); - // if (has) - // { - // // - // XCDemandZone *tmpZones[]; - // Copy( - // workingZone.demandZones, - // tmpZones // - // ); - // XCDemandZone *selectedDemand = NULL; - - // // - // while (HasChild(tmpZones)) - // { - // // - // idx = GetLowest(tmpZones); - // has = IsValidIndex(idx); - // if (!has) - // { - // break; - // } - - // // - // XCDemandZone *iZone = tmpZones[idx]; - // ArrayRemove( - // tmpZones, - // idx, - // 1 // - // ); - - // // - // // Validate Zone ... - // has = - // isBullish - // ? IsBelowDiff( - // iZone, - // selectedZone.ob, - // true // Ignore Inside ... - // ) - // : IsAboveDiff( - // iZone, - // selectedZone.ob, - // true // Ignore Inside ... - // ); - // if (!has) - // { - // continue; - // } - - // // - // has = - // selectedDemand == NULL - // ? true - // : isBullish - // ? selectedDemand.Lower() < iZone.Lower() - // : selectedDemand.Upper() > iZone.Upper(); - // if (!has) - // { - // continue; - // } - - // // - // selectedDemand = iZone; - // } - - // // - // has = selectedDemand != NULL; - // if (has) - // { - // // - // double iSL = - // isBullish - // ? selectedDemand.Lower() - // : selectedDemand.Upper(); - // double iSLDiff = MathAbs(iSL - pivot); - // has = - // iSLDiff > 0 && - // iSLDiff <= maxAllowedSLDistanceInPoint * points; - // if (has) - // { - // // - // Add( - // iSL, - // sls // - // ); - // } - // } - - // // - // Clean(tmpZones); - // ZeroMemory(selectedDemand); - // } - - // - // Support Zones ... - // has = workingZone.HasSupportZones(); - // if (has) - // { - // // - // XCSupportZone *tmpZones[]; - // Copy( - // workingZone.supportZones, - // tmpZones // - // ); - // XCSupportZone *selectedSupport = NULL; - - // // - // while (HasChild(tmpZones)) - // { - // // - // idx = GetLowest(tmpZones); - // has = IsValidIndex(idx); - // if (!has) - // { - // break; - // } - - // // - // XCSupportZone *iZone = tmpZones[idx]; - // ArrayRemove( - // tmpZones, - // idx, - // 1 // - // ); - - // // - // // Validate Zone ... - // has = - // isBullish - // ? IsBelowDiff( - // iZone, - // selectedZone.ob, - // true // Ignore Inside ... - // ) - // : IsAboveDiff( - // iZone, - // selectedZone.ob, - // true // Ignore Inside ... - // ); - // if (!has) - // { - // continue; - // } - - // // - // has = - // selectedSupport == NULL - // ? true - // : isBullish - // ? selectedSupport.Lower() < iZone.Lower() - // : selectedSupport.Upper() > iZone.Upper(); - // if (!has) - // { - // continue; - // } - - // // - // selectedSupport = iZone; - - // // - // } - - // // - // has = selectedSupport != NULL; - // if (has) - // { - // // - // double iSL = isBullish - // ? selectedSupport.Lower() - // : selectedSupport.Upper(); - // double iSLDiff = MathAbs(iSL - pivot); - // has = - // iSLDiff > 0 && - // iSLDiff <= maxAllowedSLDistanceInPoint * points; - // if (has) - // { - // // - // Add( - // iSL, - // sls // - // ); - // } - // } - - // // - // Clean(tmpZones); - // ZeroMemory(selectedSupport); - // } - - // - // Supply Zones ... - // has = workingZone.HasSupplyZones(); - // if (has) - // { - // // - // XCSupplyZone *tmpZones[]; - // Copy( - // workingZone.supplyZones, - // tmpZones // - // ); - // XCSupplyZone *selectedSupply = NULL; - - // // - // while (HasChild(tmpZones)) - // { - // // - // idx = GetHighest(tmpZones); - // has = IsValidIndex(idx); - // if (!has) - // { - // break; - // } - - // // - // XCSupplyZone *iZone = tmpZones[idx]; - // ArrayRemove( - // tmpZones, - // idx, - // 1 // - // ); - - // // - // // Validate Zone ... - // has = - // !isBullish - // ? IsAboveDiff( - // iZone, - // selectedZone.ob, - // true // Ignore Inside ... - // ) - // : IsBelowDiff( - // iZone, - // selectedZone.ob, - // true // Ignore Inside ... - // ); - // if (!has) - // { - // continue; - // } - - // // - // has = - // selectedSupply == NULL - // ? true - // : !isBullish - // ? selectedSupply.Upper() > iZone.Upper() - // : selectedSupply.Lower() < iZone.Lower(); - // if (!has) - // { - // continue; - // } - - // // - // selectedSupply = iZone; - - // // - // } - - // // - // has = selectedSupply != NULL; - // if (has) - // { - // // - // double iSL = - // !isBullish - // ? selectedSupply.Upper() - // : selectedSupply.Lower(); - // double iSLDiff = MathAbs(iSL - pivot); - // has = - // iSLDiff > 0 && - // iSLDiff <= maxAllowedSLDistanceInPoint * points; - // if (has) - // { - // // - // Add( - // iSL, - // sls // - // ); - // } - // } - - // // - // Clean(tmpZones); - // ZeroMemory(selectedSupply); - // } - - // - // Resistance Zones ... - // has = workingZone.HasDemandZones(); - // if (has) - // { - // // - // XCResistanceZone *tmpZones[]; - // Copy( - // workingZone.resistanceZones, - // tmpZones // - // ); - // XCResistanceZone *selectedResistance = NULL; - - // // - // while (HasChild(tmpZones)) - // { - // // - // idx = GetHighest(tmpZones); - // has = IsValidIndex(idx); - // if (!has) - // { - // break; - // } - - // // - // XCResistanceZone *iZone = tmpZones[idx]; - // ArrayRemove( - // tmpZones, - // idx, - // 1 // - // ); - - // // - // // Validate Zone ... - // has = - // !isBullish - // ? IsAboveDiff( - // iZone, - // selectedZone.ob, - // true // Ignore Inside ... - // ) - // : IsBelowDiff( - // iZone, - // selectedZone.ob, - // true // Ignore Inside ... - // ); - // if (!has) - // { - // continue; - // } - - // // - // has = - // selectedResistance == NULL - // ? true - // : !isBullish - // ? selectedResistance.Upper() < iZone.Upper() - // : selectedResistance.Lower() > iZone.Lower(); - // if (!has) - // { - // continue; - // } - - // // - // selectedResistance = iZone; - - // // - // } - - // // - // has = selectedResistance != NULL; - // if (has) - // { - // // - // double iSL = - // !isBullish - // ? selectedResistance.Upper() - // : selectedResistance.Lower(); - // double iSLDiff = MathAbs(iSL - pivot); - // has = - // iSLDiff > 0 && - // iSLDiff <= maxAllowedSLDistanceInPoint * points; - // if (has) - // { - // // - // Add( - // iSL, - // sls // - // ); - // } - // } - - // // - // Clean(tmpZones); - // ZeroMemory(selectedResistance); - // } - - // - // Cleanp Resources ... - - // - cBar.Clean(); - // passedBar.Clean(); - result = HasChild(sls); - - // - return result; -} - -///////////////////////////////////////////////////////////////////////// - -// -// Support Zones ... -// has = HasSupportZones(); -// if (has) -// { -// // -// int removeIDXs[]; -// count = CountSupportZones(); -// for (int i = 0; i < count; i++) -// { -// // -// XCSupportZone *iZone = supportZones[i]; -// ENUM_X_DIRECTION iDir = X_DIRECTION_BULLISH; - -// // -// XBoxZone iBox; -// bool hasBox = ToBox( -// iBox, -// iZone // -// ); -// if (!hasBox) -// { -// // -// iBox.Clean(); -// continue; -// } - -// // -// XOHCL passedBar; -// bool isBodyIn = false; -// bool isBodyOut = false; - -// // -// // Check Activation ... -// bool isActivated = iZone.IsActivated( -// iDir, -// passedBar, -// isBodyIn, -// true, -// period // -// ); -// if (isActivated) -// { -// // -// // AddRef( -// // iBox, -// // insideBoxes // -// // ); - -// // -// Add( -// i, -// removeIDXs // -// ); - -// // -// iBox.Clean(); -// passedBar.Clean(); -// continue; -// } - -// // -// // Checking Breaked ... -// bool isBreaked = iZone.IsBreaked( -// iDir, -// passedBar, -// isBodyOut, -// false, -// true, -// period // -// ); -// if (isBreaked) -// { -// // // -// // AddRef( -// // iBox, -// // breakedBoxes // -// // ); - -// // -// Add( -// i, -// removeIDXs // -// ); - -// // -// iBox.Clean(); -// passedBar.Clean(); -// continue; -// } - -// // -// passedBar.Clean(); -// } - -// // -// count = ArraySize(removeIDXs); -// has = IsValidSize(count); -// if (has) -// { -// // -// CleanupArray( -// removeIDXs, -// supportZones // -// ); -// } - -// // -// Clean(removeIDXs); -// } - -// -// Resistance Zones ... -// has = HasResistanceZones(); -// if (has) -// { -// // -// int removeIDXs[]; -// count = CountResistanceZones(); -// for (int i = 0; i < count; i++) -// { -// // -// XCResistanceZone *iZone = resistanceZones[i]; -// ENUM_X_DIRECTION iDir = X_DIRECTION_BEARISH; - -// // -// XBoxZone iBox; -// bool hasBox = ToBox( -// iBox, -// iZone // -// ); -// if (!hasBox) -// { -// // -// iBox.Clean(); -// continue; -// } - -// // -// XOHCL passedBar; -// bool isBodyIn = false; -// bool isBodyOut = false; - -// // -// // Check Activation ... -// bool isActivated = iZone.IsActivated( -// iDir, -// passedBar, -// isBodyIn, -// true, -// period // -// ); -// if (isActivated) -// { -// // -// // AddRef( -// // iBox, -// // insideBoxes // -// // ); - -// // -// Add( -// i, -// removeIDXs // -// ); - -// // -// iBox.Clean(); -// passedBar.Clean(); -// continue; -// } - -// // -// // Checking Breaked ... -// bool isBreaked = iZone.IsBreaked( -// iDir, -// passedBar, -// isBodyOut, -// false, -// true, -// period // -// ); -// if (isBreaked) -// { -// // // -// // AddRef( -// // iBox, -// // breakedBoxes // -// // ); - -// // -// Add( -// i, -// removeIDXs // -// ); - -// // -// iBox.Clean(); -// passedBar.Clean(); -// continue; -// } - -// // -// passedBar.Clean(); -// } - -// // -// count = ArraySize(removeIDXs); -// has = IsValidSize(count); -// if (has) -// { -// // -// CleanupArray( -// removeIDXs, -// resistanceZones // -// ); -// } - -// // -// Clean(removeIDXs); -// } - -//////////////////////////////////////////////////////// - -// -// Waiting Zone Detection ... -// XPOIState iState = mtfState; - -// -// Detect Waiting Zones ... - -// // -// // Using Order Blocks ... -// if (mUseOrderBlocks) -// { -// // -// has = iState.HasOrderBlocks(); -// if (has) -// { -// // -// XCOrderBlock *obs[]; -// count = iState.FilterOrderBlocks( -// obs, -// period, -// XZONE_STATE_PASSED, -// false, -// XZONE_STATE_FAILED, -// false, -// XZONE_STATE_FAILED, -// false, -// XZONE_STATE_IGNORED, -// false // -// ); - -// // -// has = IsValidSize(count); -// if (has) -// { -// // -// ToBox( -// obs, -// waitingBoxes // -// ); -// } - -// // -// Clean(obs); -// } -// } - -// // -// // Using Fair Value Gaps ... -// if (mUseFairValueGaps) -// { -// // -// has = iState.HasFairValueGaps(); -// if (has) -// { -// // -// XBoxZone boxes[]; -// XCFVG *fvgs[]; -// count = iState.FilterFairValueGaps( -// fvgs, -// period, -// XZONE_STATE_PASSED, -// false, -// XZONE_STATE_FAILED, -// false, -// XZONE_STATE_FAILED, -// false, -// XZONE_STATE_IGNORED, -// false // -// ); - -// // -// has = IsValidSize(count); -// if (has) -// { -// // -// count = ToBox( -// fvgs, -// boxes // -// ); - -// // -// for (int i = 0; i < count; i++) -// { -// // -// XBoxZone iBox = boxes[i]; - -// // -// int idx = FindIndex( -// iBox, -// waitingBoxes // -// ); -// has = !IsValidIndex(idx); -// if (has) -// { -// // -// AddRef( -// iBox, -// waitingBoxes // -// ); -// } - -// // -// iBox.Clean(); -// } -// } - -// // -// Clean(fvgs); -// Clean(boxes); -// } -// } - -// -// Cleaning State ... -// iState.Clean(); - -/////////////////////////////////////////////////////////////////////////// - -// -// Waiting Box Detected ... -bool hasWaitingBoxes = hasWorkingZone && - workingZone.HasWaitingBoxes(); -if (hasWaitingBoxes) -{ - // - XOHCL zBar; - XOHCL cBar; - XOHCL pBar; - int count = 0; - int idx = -1; - bool has = false; - - // - bool isInited = zBar.Init( - symbol, - period, - zIndex // - ); - isInited = - isInited && - zBar.GetPreviousBar(cBar); - isInited = - isInited && - cBar.GetPreviousBar(pBar); - - // - count = workingZone.CountWaitingBoxes(); - for (int i = 0; i < count; i++) - { - // - XBoxZone iBox = workingZone.waitingBoxes[i]; - ENUM_X_DIRECTION iDir = iBox.dir; - bool isBullish = IsBullish(iDir); - - // - // Check Price Rejection ... - - // - bool hasBullishFiboPressure = - decisionCycleHelper - .mBarAnalyser - .HasFiboPressure( - cBar, - X_DIRECTION_BULLISH, - X_FIBO_LEVEL_382 // - ); - - // - bool hasBearishFiboPressure = - decisionCycleHelper - .mBarAnalyser - .HasFiboPressure( - cBar, - X_DIRECTION_BEARISH, - X_FIBO_LEVEL_382 // - ); - - // - // Bullish Rejection ... - bool isBullishRejected = - // - isInited && - isBullish && - cBar.low < pBar.low && - zBar.low > iBox.upper && - cBar.low <= iBox.upper && - zBar.open > iBox.upper && - hasBullishFiboPressure && - cBar.GetLowShadow() > pBar.GetLowShadow() - // - ; - - // - // Bearish Rejection ... - bool isBearishhRejected = - // - isInited && - !isBullish && - cBar.high > pBar.high && - zBar.open < iBox.lower && - zBar.high < iBox.lower && - hasBearishFiboPressure && - cBar.high >= iBox.lower && - cBar.GetHighShadow() > pBar.GetHighShadow() - // - ; - - // - has = isBullishRejected || - isBearishhRejected; - if (has) - { - // - idx = i; - signalBox = iBox; - hasSignalBox = has; - signalBox.to = cTime; - signalBoxDir = iBox.dir; - isSignalBoxReversal = false; - provider = X121SMC_XWZ_PROVIDER_ACTIVATED_ZONE; - } - - // - iBox.Clean(); - } - - // - // Remove Signal Box from Waiting Boxes of - // Working Zone ... - if (hasSignalBox) - { - // - if (IsValidIndex(idx)) - { - // - ArrayRemove( - workingZone.waitingBoxes, - idx, - 1 // - ); - } - } - - // - // Ignore Zone's Signals ... - hasSignalBox = false; - - // - // Cleanup Resources ... - - // - zBar.Clean(); - cBar.Clean(); - pBar.Clean(); -} - -// -// Check Conditions if Has Inside Boxes ... -bool hasInsideBoxes = hasWorkingZone && - workingZone.HasInsideBoxes(); -if (hasInsideBoxes) -{ -} - -// -// Check Conditions if has Breaked Boxes ... -bool hasBreakedBoxes = hasWorkingZone && - workingZone.HasBreakedBoxes(); -if (hasBreakedBoxes) -{ -} - -// -// Checking Other Conditions ... -if (!hasSignalBox) -{ - // - // Senari A ... - // hasSignalBox = hasWorkingZone && - // workingZone.DetectSenarioASignalBox( - // signalBox, - // signalBoxDir, - // decisionXConditions, - // analyseXConditions, - // decisionCycleHelper, - // drawer, - // zIndex // - // ); - // if (hasSignalBox) - // { - // // - // signalBox.to = cTime; - // isSignalBoxReversal = false; - // provider = X121SMC_XWZ_PROVIDER_PV_ZONE; - // } - - // // - // // Validating Signal Box if Exists ... - // if (hasSignalBox) - // { - // // - // // Validate Signal Boxes using Inside Box ... - // if (hasInsideBoxes) - // { - // // - // int idx = -1; - // bool has = false; - - // // - // idx = - // IsBullish(signalBoxDir) - // ? GetLowest(workingZone.insideBoxes) - // : GetHighest(workingZone.insideBoxes); - // has = IsValidIndex(idx); - // if (has) - // { - // // - // hasSignalBox = - // signalBoxDir == workingZone.insideBoxes[idx].dir; - // } - // } - - // // - // // Validate Signal Box Using Overal Trend ... - // if (hasWorkingZoneOveralDirection) - // { - // // - // hasSignalBox = - // signalBoxDir == wzOveralDir; - // } - // } -} - -////////////////////////////////////////////////////////////////////////////////// - -// -// -// - -// -// Supply Zones ... -has = HasSupplyZones(); -if (has) -{ - // - int removeIDXs[]; - count = CountSupplyZones(); - for (int i = 0; i < count; i++) - { - // - XCSupplyZone *iZone = supplyZones[i]; - ENUM_X_DIRECTION iDir = X_DIRECTION_BEARISH; - - // - XBoxZone iBox; - bool hasBox = ToBox( - iBox, - iZone // - ); - if (!hasBox) - { - // - iBox.Clean(); - continue; - } - - // - XOHCL passedBar; - bool isBodyIn = false; - bool isBodyOut = false; - - // - // Check Activation ... - bool isActivated = iZone.IsActivated( - iDir, - passedBar, - isBodyIn, - true, - period // - ); - if (isActivated) - { - // - // AddRef( - // iBox, - // insideBoxes // - // ); - - // - Add( - i, - removeIDXs // - ); - - // - iBox.Clean(); - passedBar.Clean(); - continue; - } - - // - // Checking Breaked ... - bool isBreaked = iZone.IsBreaked( - iDir, - passedBar, - isBodyOut, - false, - true, - period // - ); - if (isBreaked) - { - // // - // AddRef( - // iBox, - // breakedBoxes // - // ); - - // - Add( - i, - removeIDXs // - ); - - // - iBox.Clean(); - passedBar.Clean(); - continue; - } - - // - passedBar.Clean(); - } - - // - count = ArraySize(removeIDXs); - has = IsValidSize(count); - if (has) - { - // - CleanupArray( - removeIDXs, - supplyZones // - ); - } - - // - Clean(removeIDXs); -} - -// -// Demand Zones ... -has = HasDemandZones(); -if (has) -{ - // - int removeIDXs[]; - count = CountDemandZones(); - for (int i = 0; i < count; i++) - { - // - XCDemandZone *iZone = demandZones[i]; - ENUM_X_DIRECTION iDir = X_DIRECTION_BULLISH; - - // - XBoxZone iBox; - bool hasBox = ToBox( - iBox, - iZone // - ); - if (!hasBox) - { - // - iBox.Clean(); - continue; - } - - // - XOHCL passedBar; - bool isBodyIn = false; - bool isBodyOut = false; - - // - // Check Activation ... - bool isActivated = iZone.IsActivated( - iDir, - passedBar, - isBodyIn, - true, - period // - ); - if (isActivated) - { - // - // AddRef( - // iBox, - // insideBoxes // - // ); - - // - Add( - i, - removeIDXs // - ); - - // - iBox.Clean(); - passedBar.Clean(); - continue; - } - - // - // Checking Breaked ... - bool isBreaked = iZone.IsBreaked( - iDir, - passedBar, - isBodyOut, - false, - true, - period // - ); - if (isBreaked) - { - // // - // AddRef( - // iBox, - // breakedBoxes // - // ); - - // - Add( - i, - removeIDXs // - ); - - // - iBox.Clean(); - passedBar.Clean(); - continue; - } - - // - passedBar.Clean(); - } - - // - count = ArraySize(removeIDXs); - has = IsValidSize(count); - if (has) - { - // - CleanupArray( - removeIDXs, - demandZones // - ); - } - - // - Clean(removeIDXs); -} - -// -// Update Boxes ... - -// -// Waiting Boxes ... -has = HasWaitingBoxes(); -if (has) -{ - // - int removeIDXs[]; - count = CountWaitingBoxes(); - for (int i = 0; i < count; i++) - { - // - XBoxZone iBox = waitingBoxes[i]; - ENUM_X_DIRECTION iDir = iBox.dir; - bool isBullish = IsBullish(iDir); - - // - bool isInside = - // - zBar.low < iBox.upper && - zBar.low > iBox.lower - // - ; - if (isInside) - { - // - AddRef( - iBox, - insideBoxes // - ); - - // - Add( - i, - removeIDXs // - ); - - // - iBox.Clean(); - break; - } - - // - bool isBreakedUpper = - // - cBar.low < iBox.upper && - cBar.low > iBox.lower && - zBar.low > iBox.upper - // - ; - - // - bool isBreakedLower = - // - cBar.high > iBox.lower && - cBar.high < iBox.upper && - zBar.high < iBox.lower - // - ; - - // - bool isBreaked = - (isBullish && - isBreakedLower) || - (!isBullish && - isBreakedUpper); - - // - if (isBreaked) - { - // - AddRef( - iBox, - breakedBoxes // - ); - - // - Add( - i, - removeIDXs // - ); - - // - iBox.Clean(); - break; - } - } - - // - count = ArraySize(removeIDXs); - has = IsValidSize(count); - if (has) - { - // - CleanupArray( - removeIDXs, - waitingBoxes // - ); - } - - // - Clean(removeIDXs); -} - -// -// Inside Boxes ... -has = HasInsideBoxes(); -if (has) -{ - // - int removeIDXs[]; - count = CountInsideBoxes(); - for (int i = 0; i < count; i++) - { - // - XBoxZone iBox = insideBoxes[i]; - ENUM_X_DIRECTION iDir = iBox.dir; - bool isBullish = IsBullish(iDir); - - // - bool isBreakedUpper = - // - cBar.low < iBox.upper && - cBar.low > iBox.lower && - zBar.low > iBox.upper - // - ; - - // - bool isBreakedLower = - // - cBar.high > iBox.lower && - cBar.high < iBox.upper && - zBar.high < iBox.lower - // - ; - - // - bool isBreaked = - (isBullish && - isBreakedLower) || - (!isBullish && - isBreakedUpper); - - // - if (isBreaked) - { - // - AddRef( - iBox, - breakedBoxes // - ); - - // - Add( - i, - removeIDXs // - ); - - // - iBox.Clean(); - break; - } - } - - // - count = ArraySize(removeIDXs); - has = IsValidSize(count); - if (has) - { - // - CleanupArray( - removeIDXs, - insideBoxes // - ); - } - - // - Clean(removeIDXs); -} - -// -has = HasBreakedBoxes(); -if (has) -{ - // - int removeIDXs[]; - count = CountBreakedBoxes(); - for (int i = 0; i < count; i++) - { - // - XBoxZone iBox = breakedBoxes[i]; - ENUM_X_DIRECTION iDir = iBox.dir; - bool isBullish = IsBullish(iDir); - - // - bool isInside = false; - - // - if (isInside) - { - // - AddRef( - iBox, - breakedInsideBoxes // - ); - - // - Add( - i, - removeIDXs // - ); - - // - iBox.Clean(); - break; - } - } - - // - count = ArraySize(removeIDXs); - has = IsValidSize(count); - if (has) - { - // - CleanupArray( - removeIDXs, - breakedBoxes // - ); - } - - // - Clean(removeIDXs); -} - -// -// Update Waiting Boxes ... - -// -XPOIState iState = mtfState; - -// -// Use Order Blocks ... -if (mUseOrderBlocks) -{ - // - has = iState.HasOrderBlocks(); - if (has) - { - // - XCOrderBlock *obs[]; - count = iState.FilterOrderBlocks( - obs, - period, - XZONE_STATE_PASSED, - false, - XZONE_STATE_FAILED, - false, - XZONE_STATE_FAILED, - false, - XZONE_STATE_IGNORED, - false // - ); - - // - has = IsValidSize(count); - if (has) - { - // - // Try to Add new OBs into Waiting Zones ... - // if it's not exists ... - for (int i = 0; i < count; i++) - { - // - XBoxZone iBox; - bool hasBox = ToBox( - iBox, - obs[i] // - ); - if (!hasBox) - { - // - iBox.Clean(); - continue; - } - - // - // Check Index in Waiting Boxes ... - idx = FindIndex( - iBox, - waitingBoxes // - ); - has = !IsValidIndex(idx); - if (!has) - { - // - iBox.Clean(); - continue; - } - - // - // Check Index in Inside Boxes ... - idx = FindIndex( - iBox, - insideBoxes // - ); - has = !IsValidIndex(idx); - if (!has) - { - // - iBox.Clean(); - continue; - } - - // - // Check Index in Breaked Boxes ... - idx = FindIndex( - iBox, - breakedBoxes // - ); - has = !IsValidIndex(idx); - if (!has) - { - // - iBox.Clean(); - continue; - } - - // - AddRef( - iBox, - waitingBoxes // - ); - } - } - - // - Clean(obs); - } -} - -// -// Use Fair Value Gaps ... -if (mUseFairValueGaps) -{ - // - has = iState.HasFairValueGaps(); - if (has) - { - // - XCFVG *fvgs[]; - count = iState.FilterFairValueGaps( - fvgs, - period, - XZONE_STATE_PASSED, - false, - XZONE_STATE_FAILED, - false, - XZONE_STATE_FAILED, - false, - XZONE_STATE_IGNORED, - false // - ); - - // - has = IsValidSize(count); - if (has) - { - // - for (int i = 0; i < count; i++) - { - // - XBoxZone iBox; - bool hasBox = ToBox( - iBox, - fvgs[i] // - ); - if (!hasBox) - { - // - iBox.Clean(); - continue; - } - - // - // Check Index in Waiting Boxes ... - idx = FindIndex( - iBox, - waitingBoxes // - ); - has = !IsValidIndex(idx); - if (!has) - { - // - iBox.Clean(); - continue; - } - - // - // Check Index in Inside Boxes ... - idx = FindIndex( - iBox, - insideBoxes // - ); - has = !IsValidIndex(idx); - if (!has) - { - // - iBox.Clean(); - continue; - } - - // - // Check Index in Breaked Boxes ... - idx = FindIndex( - iBox, - breakedBoxes // - ); - has = !IsValidIndex(idx); - if (!has) - { - // - iBox.Clean(); - continue; - } - - // - AddRef( - iBox, - waitingBoxes // - ); - - // - iBox.Clean(); - } - } - - // - Clean(fvgs); - } -} - -// -iState.Clean(); - -///////////////////////////////////////////////////////////////////////////// - -// -// Update Working Zone ... -// workingZone.Update( -// zIndex, -// visionState, -// consolidationState, -// analyseState, -// decisionState // -// ); - -////////////////////////////////////////////////////////////////////////////////// - -// -// -// - -// -// Supply Zones ... -if (drawSupplyZones) -{ - // - has = HasSupplyZones(); - if (has) - { - // - count = CountSupplyZones(); - for (int i = 0; i < count; i++) - { - // - XCSupplyZoneObject *iObj; - isCreated = drawer.CreateSupplyZone( - supplyZones[i], - iObj // - ); - - // - if (isCreated) - { - mWorkingZoneObjects.Add(iObj); - } - } - } -} - -// -// Demand Zones ... -if (drawDemandZones) -{ - // - has = HasDemandZones(); - if (has) - { - // - count = CountDemandZones(); - for (int i = 0; i < count; i++) - { - // - XCDemandZoneObject *iObj; - isCreated = drawer.CreateDemandZone( - demandZones[i], - iObj // - ); - - // - if (isCreated) - { - mWorkingZoneObjects.Add(iObj); - } - } - } -} - -// -// Support Zones ... -if (drawSupportZones) -{ - // - has = HasSupportZones(); - if (has) - { - // - count = CountSupportZones(); - for (int i = 0; i < count; i++) - { - // - XCSupportZoneObject *iObj; - isCreated = drawer.CreateSupportZone( - supportZones[i], - iObj // - ); - - // - if (isCreated) - { - mWorkingZoneObjects.Add(iObj); - } - } - } -} - -// -// Resistance Zones ... -if (drawResistanceZones) -{ - // - has = HasResistanceZones(); - if (has) - { - // - count = CountResistanceZones(); - for (int i = 0; i < count; i++) - { - // - XCResistanceZoneObject *iObj; - isCreated = drawer.CreateResistanceZone( - resistanceZones[i], - iObj // - ); - - // - if (isCreated) - { - mWorkingZoneObjects.Add(iObj); - } - } - } -} - -// -// -// - -// -// Waiting Boxes ... -if (drawWaitingBoxes) -{ - // - has = HasWaitingBoxes(); - if (has) - { - // - count = CountWaitingBoxes(); - for (int i = 0; i < count; i++) - { - // - XBoxZone iBox = waitingBoxes[i]; - - // - XCBoxObject *iObj; - bool isCreated = drawer.DrawBox( - iBox, - iObj // - ); - - // - if (isCreated) - { - mWorkingZoneObjects.Add(iObj); - } - - // - iBox.Clean(); - } - } -} - -// -// Inside Boxes ... -if (drawInsideBoxes) -{ - // - has = HasInsideBoxes(); - if (has) - { - } -} - -// -// Breaked Boxes ... -if (drawBreakedBoxes) -{ - // - has = HasBreakedBoxes(); - if (has) - { - // - } -} - -// -// Breaked Inside Boxes ... -if (drawBreakedInsideBoxes) -{ - // - has = HasBreakedInsideBoxes(); - if (has) - { - // - count = CountBreakedInsideBoxes(); - for (int i = 0; i < count; i++) - { - // - XBoxZone iBox = breakedInsideBoxes[i]; - XCBoxObject *iObj; - has = drawer.DrawBox( - iBox, - iObj // - ); - if (has) - { - // - iObj.BoxWidth(1); - mBreakedInsideZoneObjects.Add(iObj); - } - } - } -} - -////////////////////////////////////////////////////////////////////////////////// - -// -XCSupplyZone *supplyZone; -XCDemandZone *demandZone; - -// -XCSupplyZone *supplyZones[]; -XCDemandZone *demandZones[]; - -// -XCSupportZone *supportZones[]; -XCResistanceZone *resistanceZones[]; - -// -XBoxZone insideBoxes[]; -XBoxZone breakedBoxes[]; -XBoxZone waitingBoxes[]; -XBoxZone breakedInsideBoxes[]; -XConsolidationZone consolidationZones[]; - -// -bool mUseSupDems; -bool mUseOrderBlocks; -bool mUseFairValueGaps; - -// -// -// - -// // -// // Supply Zones ... -// has = HasSupplyZones(); -// if (!has) -// { -// // -// count = mtfState.FilterSupplyZones( -// supplyZones, -// period, -// XZONE_STATE_PASSED, -// false, -// XZONE_STATE_FAILED, -// false, -// XZONE_STATE_FAILED, -// false, -// XZONE_STATE_IGNORED, -// false // -// ); -// } - -// // -// // Demand Zones ... -// has = HasDemandZones(); -// if (!has) -// { -// // -// count = mtfState.FilterDemandZones( -// demandZones, -// period, -// XZONE_STATE_PASSED, -// false, -// XZONE_STATE_FAILED, -// false, -// XZONE_STATE_FAILED, -// false, -// XZONE_STATE_IGNORED, -// false // -// ); -// } - -// -// Support Zones ... -// has = HasSupportZones(); -// if (!has) -// { -// // -// count = mtfState.FilterSupportZones( -// supportZones, -// period, -// XZONE_STATE_PASSED, -// false, -// XZONE_STATE_FAILED, -// false, -// XZONE_STATE_FAILED, -// false, -// XZONE_STATE_IGNORED, -// false // -// ); -// } - -// -// Resistance Zones ... -// has = HasResistanceZones(); -// if (!has) -// { -// // -// count = mtfState.FilterResistanceZones( -// resistanceZones, -// period, -// XZONE_STATE_PASSED, -// false, -// XZONE_STATE_FAILED, -// false, -// XZONE_STATE_FAILED, -// false, -// XZONE_STATE_IGNORED, -// false // -// ); -// } - -// -// Update Exists Zones ... - -// -// Supply Zones ... -has = mtfState.HasSupplyZones(); -if (has) -{ - // - XCSupplyZone *zone; - idx = GetYoungest(mtfState.supplyZones); - has = IsValidIndex(idx); - if (has) - { - // - zone = mtfState.supplyZones[idx]; - has = IsSupplyExists(zone); - if (!has) - { - // - Add( - zone, - supplyZones // - ); - } - else - { - ZeroMemory(zone); - } - } -} - -// -// Demand Zones ... -has = mtfState.HasDemandZones(); -if (has) -{ - // - XCDemandZone *zone; - idx = GetYoungest(mtfState.demandZones); - has = IsValidIndex(idx); - if (has) - { - // - zone = mtfState.demandZones[idx]; - has = IsDemandExists(zone); - if (!has) - { - // - Add( - zone, - demandZones // - ); - } - else - { - ZeroMemory(zone); - } - } -} - -/////////////////////////////////////////////////////////////////////////// - -// -bool IsExists(XBoxZone &box) -{ - // - bool result = false; - - // - result = box.IsValid(); - if (!result) - { - return result; - } - - // - int idx = -1; - bool has = false; - - // - // Checking Index Waiting Box ... - has = HasWaitingBoxes(); - if (has) - { - // - idx = FindIndex( - box, - waitingBoxes // - ); - result = !IsValidIndex(idx); - if (!result) - { - return result; - } - } - - // - // Checking Index Inside Boxes ... - has = HasInsideBoxes(); - if (has) - { - // - idx = FindIndex( - box, - insideBoxes // - ); - result = !IsValidIndex(idx); - if (!result) - { - return result; - } - } - - // - // Checking Index Breaked Boxes ... - has = HasBreakedBoxes(); - if (has) - { - // - idx = FindIndex( - box, - breakedBoxes // - ); - result = !IsValidIndex(idx); - if (!result) - { - return result; - } - } - - // - // Checking Index BreakedInside Boxes ... - has = HasBreakedInsideBoxes(); - if (has) - { - // - idx = FindIndex( - box, - breakedInsideBoxes // - ); - result = !IsValidIndex(idx); - if (!result) - { - return result; - } - } - - // - return result; -} - -// -bool IsSupplyExists(XCSupplyZone *zone) -{ - // - bool result = false; - - // - result = zone != NULL && - zone.IsValid(); - if (!result) - { - return result; - } - - // - // Converts Zone to Box ... - XBoxZone box; - result = ToBox( - box, - zone // - ); - if (!result) - { - // - box.Clean(); - return result; - } - - // - // Checking Index in SupplyZones ... - int idx = FindIndex( - zone, - supplyZones // - ); - result = !IsValidIndex(idx); - if (!result) - { - // - box.Clean(); - return result; - } - - // - result = IsExists(box); - - // - box.Clean(); - - // - return result; -} - -// -bool IsDemandExists(XCDemandZone *zone) -{ - // - bool result = false; - - // - result = zone != NULL && - zone.IsValid(); - if (!result) - { - return result; - } - - // - // Converts Zone to Box ... - XBoxZone box; - result = ToBox( - box, - zone // - ); - if (!result) - { - // - box.Clean(); - return result; - } - - // - // Checking Index in SupplyZones ... - int idx = FindIndex( - zone, - demandZones // - ); - result = !IsValidIndex(idx); - if (!result) - { - // - box.Clean(); - return result; - } - - // - result = IsExists(box); - - // - box.Clean(); - - // - return result; -} - -////////////////////////////////////////////////////////////////////////////// - -// -Clean(supplyZones); -Clean(demandZones); - -// -Clean(insideBoxes); -Clean(breakedBoxes); -Clean(waitingBoxes); - -// -Clean(supportZones); -Clean(resistanceZones); - -// -mUseSupDems = false; -mUseOrderBlocks = true; -mUseFairValueGaps = true; - -///////////////////////////////////////////////////////////////////////////// - -// -bool HasInsideBox( - XBoxZone &box // -) -{ - // - bool result = false; - - // - int index = -1; - - // - result = box.IsValid(); - if (!result) - { - return result; - } - - // - int count = 0; - bool has = false; - - // - has = HasWaitingBoxes(); - if (has) - { - // - result = HasInsideBox( - index, - box, - waitingBoxes // - ); - } - - // - // Supply Zones ... - if (!result) - { - // - has = HasSupplyZones(); - if (has) - { - // - XBoxZone tmpBoxes[]; - count = ToBox( - supplyZones, - tmpBoxes // - ); - - // - has = IsValidSize(count); - if (has) - { - // - result = HasInsideBox( - index, - box, - tmpBoxes // - ); - } - - // - Clean(tmpBoxes); - } - } - - // - // Demand Zones ... - if (!result) - { - // - has = HasDemandZones(); - if (has) - { - // - XBoxZone tmpBoxes[]; - count = ToBox( - demandZones, - tmpBoxes // - ); - - // - has = IsValidSize(count); - if (has) - { - // - result = HasInsideBox( - index, - box, - tmpBoxes // - ); - } - - // - Clean(tmpBoxes); - } - } - - // - result = IsValidIndex(index); - - // - return result; -} - -// -bool DetectSenarioASignalBox( - XBoxZone &signalBox, - ENUM_X_DIRECTION &signalDir, - X121Conditions &decisionXConditions, - X121Conditions &analyseXConditions, - XC121SMCCycleHelper *decisionCycleHelper, - XCPOIDrawer *drawer = NULL, - int barIndex = 0 // -) -{ - // - bool result = false; - - // - signalBox.Clean(); - signalDir = X_DIRECTION_NONE; - - // - if (barIndex < 0) - { - barIndex = 0; - } - - // - result = decisionCycleHelper != NULL; - if (!result) - { - return result; - } - - // - // Decision ... - double decisionBullishScore = 0; - double decisionBearishScore = 0; - decisionXConditions.GenerateScore( - decisionBullishScore, - decisionBearishScore // - ); - - // - // Analyse ... - double analyseBullishScore = 0; - double analyseBearishScore = 0; - analyseXConditions.GenerateScore( - analyseBullishScore, - analyseBearishScore // - ); - - // - // Score Conditions ... - double scoreMultiplier = 3; - bool isBullishScorePassed = - // - analyseBullishScore > (analyseBearishScore * scoreMultiplier) && - decisionBullishScore > (decisionBearishScore * scoreMultiplier) - // - ; - bool isBearishScorePassed = - // - analyseBearishScore > (analyseBullishScore * scoreMultiplier) && - decisionBearishScore > (decisionBullishScore * scoreMultiplier) - // - ; - - // - // Checking Other Conditions - - // - bool isCommonBullish = - // - decisionXConditions.isSarBullish && - decisionXConditions.isStrBullish && - decisionXConditions.isCheBullish && - decisionXConditions.isSMHKBullish && - decisionXConditions.isRawHKBullish && - decisionXConditions.isRawHKClosedOverSMHK - // - ; - - // - bool isCommonBearish = - // - decisionXConditions.isSarBearish && - decisionXConditions.isStrBearish && - decisionXConditions.isCheBearish && - decisionXConditions.isSMHKBearish && - decisionXConditions.isRawHKBearish && - decisionXConditions.isRawHKClosedUnderSMHK - // - ; - - // - // X3Ma ... - - // - // X3Ma Bullish ... - bool isX3MaBullish = - // - decisionXConditions.isX3MaBullishState && - decisionXConditions.isX3MaSwitchedToBullishOrdered && - decisionXConditions.x3maMidBuffer[1] > decisionXConditions.x3maSlowBuffer[1] - // - ; - - // - // X3Ma Bearish ... - bool isX3MaBearish = - // - decisionXConditions.isX3MaBearishState && - decisionXConditions.isX3MaSwitchedToBearishOrdered && - decisionXConditions.x3maMidBuffer[1] < decisionXConditions.x3maSlowBuffer[1] - // - ; - - // - bool isX3MaHasCondition = - (isX3MaBullish && - isCommonBullish && - isBullishScorePassed) || - (isX3MaBearish && - isCommonBearish && - isBearishScorePassed); - - // - // VWap ... - - // - // VWap Bullish ... - bool isVWapBullish = - // - decisionXConditions.isVWapBullishState && - decisionXConditions.isVWapSwitchedToBullishOrdered && - decisionXConditions.vwapMidBuffer[1] > decisionXConditions.vwapSlowBuffer[1] - // - ; - - // - // VWap Bearish ... - bool isVWapBearish = - // - decisionXConditions.isVWapBearishState && - decisionXConditions.isVWapSwitchedToBearishOrdered && - decisionXConditions.vwapMidBuffer[1] < decisionXConditions.vwapSlowBuffer[1] - // - ; - - // - bool isVWapHasCondition = - (isVWapBullish && - isBullishScorePassed) || - (isVWapBearish && - isBearishScorePassed); - - // - // Senario .... - // - a vale Under X3MA Slow when X3MA Bullish Ordered ... - - // - bool isX3MASenarioBBullish = - // - decisionXConditions.isX3MaBullishOrdered && - decisionXConditions.valesBuffer[1] < decisionXConditions.x3maSlowBuffer[1] && - decisionXConditions.valesBuffer[2] >= decisionXConditions.x3maSlowBuffer[2] - // - ; - if (isX3MASenarioBBullish) - { - } - - // - bool isX3MASenarioBBearish = - // - decisionXConditions.isX3MaBearishOrdered && - decisionXConditions.peaksBuffer[1] > decisionXConditions.x3maSlowBuffer[1] && - decisionXConditions.peaksBuffer[2] <= decisionXConditions.x3maSlowBuffer[2] - // - ; - if (isX3MASenarioBBearish) - { - } - - // - // Checking Other Conditions XWZ Reject on EMA 20 ... - - // - // Check Has Conditions ... - bool hasXConditions = - (isX3MaHasCondition || - isVWapHasCondition); - - // - result = hasXConditions; - if (!result) - { - return result; - } - - // - if (isX3MaHasCondition) - { - // - signalDir = - isX3MaBullish - ? X_DIRECTION_BULLISH - : isX3MaBearish - ? X_DIRECTION_BEARISH - : X_DIRECTION_NONE; - } - - // - if (isVWapHasCondition) - { - // - signalDir = - isVWapBullish - ? X_DIRECTION_BULLISH - : isVWapBearish - ? X_DIRECTION_BEARISH - : X_DIRECTION_NONE; - } - - // - // Creating SignalBox ... - - // - // Detect Box based on PV ... - bool hasSignalBox = decisionCycleHelper.GeneratePVBox( - signalBox, - barIndex // - ); - - // - result = - hasSignalBox && - signalDir == signalBox.dir; - - // - if (result) - { - // - XCBoxObject *iObj; - bool isCreated = drawer.DrawBox( - signalBox, - iObj // - ); - if (isCreated) - { - // - iObj.BoxWidth(1); - iObj.BoxColor(clrYellow); - iObj.BoxStyle(STYLE_SOLID); - } - - // - Print("Senario A ..."); - } - - // - return result; -} - -// -bool DetetctSenarioBSignalBox( - XBoxZone &signalBox, - ENUM_X_DIRECTION &signalDir, - X121Conditions &decisionXConditions, - X121Conditions &analyseXConditions, - XC121SMCCycleHelper *decisionCycleHelper, - int barIndex = 0 // -) -{ - // - bool result = false; - - // - signalBox.Clean(); - signalDir = X_DIRECTION_NONE; - - // - if (barIndex < 0) - { - barIndex = 0; - } - - // - result = decisionCycleHelper != NULL; - if (!result) - { - return result; - } - - // - // Decision ... - double decisionBullishScore = 0; - double decisionBearishScore = 0; - decisionXConditions.GenerateScore( - decisionBullishScore, - decisionBearishScore // - ); - - // - // Analyse ... - double analyseBullishScore = 0; - double analyseBearishScore = 0; - analyseXConditions.GenerateScore( - analyseBullishScore, - analyseBearishScore // - ); - - // - // Score Conditions ... - double scoreMultiplier = 3; - bool isBullishScorePassed = - // - analyseBullishScore > (analyseBearishScore * scoreMultiplier) && - decisionBullishScore > (decisionBearishScore * scoreMultiplier) - // - ; - bool isBearishScorePassed = - // - analyseBearishScore > (analyseBullishScore * scoreMultiplier) && - decisionBearishScore > (decisionBullishScore * scoreMultiplier) - // - ; - - // - // Senario .... - // - a vale Under X3MA Slow when X3MA Bullish Ordered ... - - // - bool isX3MASenarioBBullish = - // - decisionXConditions.isX3MaBullishOrdered && - decisionXConditions.valesBuffer[1] < decisionXConditions.x3maSlowBuffer[1] && - decisionXConditions.valesBuffer[2] >= decisionXConditions.x3maSlowBuffer[2] - // - ; - if (isX3MASenarioBBullish) - { - } - - // - bool isX3MASenarioBBearish = - // - decisionXConditions.isX3MaBearishOrdered && - decisionXConditions.peaksBuffer[1] > decisionXConditions.x3maSlowBuffer[1] && - decisionXConditions.peaksBuffer[2] <= decisionXConditions.x3maSlowBuffer[2] - // - ; - if (isX3MASenarioBBearish) - { - } - - // - return result; -} - -// -bool HasSupplyZones() -{ - return HasChild(supplyZones); -} - -// -int CountSupplyZones() -{ - return ArraySize(supplyZones); -} - -// -bool HasDemandZones() -{ - return HasChild(demandZones); -} - -// -int CountDemandZones() -{ - return ArraySize(demandZones); -} - -// -bool HasSupportZones() -{ - return HasChild(supportZones); -} - -// -int CountSupportZones() -{ - return ArraySize(supportZones); -} - -// -bool HasResistanceZones() -{ - return HasChild(resistanceZones); -} - -// -int CountResistanceZones() -{ - return ArraySize(resistanceZones); -} - -// -bool HasConsolidationZones() -{ - return HasChild(consolidationZones); -} - -// -int CountConsolidationZones() -{ - return ArraySize(consolidationZones); -} - -// -bool HasWaitingBoxes() -{ - return HasChild(waitingBoxes); -} - -// -int CountWaitingBoxes() -{ - return ArraySize(waitingBoxes); -} - -// -bool HasInsideBoxes() -{ - return HasChild(insideBoxes); -} - -// -int CountInsideBoxes() -{ - return ArraySize(insideBoxes); -} - -// -bool HasBreakedBoxes() -{ - return HasChild(breakedBoxes); -} - -// -int CountBreakedBoxes() -{ - return ArraySize(breakedBoxes); -} - -// -bool HasBreakedInsideBoxes() -{ - return HasChild(breakedInsideBoxes); -} - -// -int CountBreakedInsideBoxes() -{ - return ArraySize(breakedInsideBoxes); -} - -/////////////////////////////////////////////////////////////////////////////////// - -// -has = ttfState.HasConsolidationZones(); -if (has) -{ - // - Copy( - ttfState.consolidationZones, - consolidationZones // - ); - CleanupArray( - consolidationZones, - 50 // - ); -} - -// -has = HasSupplyZones(); -if (has) -{ - // - count = CountSupplyZones(); - for (int i = 0; i < count; i++) - { - supplyZones[i].To(value); - } -} - -// -has = HasDemandZones(); -if (has) -{ - // - count = CountDemandZones(); - for (int i = 0; i < count; i++) - { - demandZones[i].To(value); - } -} - -// -has = HasSupportZones(); -if (has) -{ - // - count = CountSupportZones(); - for (int i = 0; i < count; i++) - { - supportZones[i].To(value); - } -} - -// -has = HasResistanceZones(); -if (has) -{ - // - count = CountResistanceZones(); - for (int i = 0; i < count; i++) - { - resistanceZones[i].To(value); - } -} - -// -// -// - -// -has = HasWaitingBoxes(); -if (has) -{ - // - count = ArraySize(waitingBoxes); - for (int i = 0; i < count; i++) - { - waitingBoxes[i].to = value; - } -} - -// -has = HasInsideBoxes(); -if (has) -{ - // - count = CountInsideBoxes(); - for (int i = 0; i < count; i++) - { - insideBoxes[i].to = value; - } -} - -// -has = HasBreakedBoxes(); -if (has) -{ -} - -// -has = HasBreakedInsideBoxes(); -if (has) -{ - // - count = CountBreakedInsideBoxes(); - for (int i = 0; i < count; i++) - { - breakedInsideBoxes[i].to = value; - } -} - -/////////////////////////////////////////////////////////////////////////////////// - -// -XBoxZone waitingBoxes[]; -has = workingZone.HasWaitingBoxes(); -if (has) -{ - // - Copy( - workingZone.waitingBoxes, - waitingBoxes // - ); - - // - while (HasChild(waitingBoxes)) - { - // - XBoxZone iBox; - idx = GetYoungest(waitingBoxes); - has = IsValidIndex(idx); - if (!has) - { - // - iBox.Clean(); - continue; - } - - // - iBox = waitingBoxes[idx]; - ArrayRemove( - waitingBoxes, - idx, - 1 // - ); - - // - bool hasInside = workingZone.HasInsideBox(iBox); - if (!hasInside) - { - continue; - } - - // - double iTarget = - IsBullish(signalBoxDir) - ? iBox.lower - : iBox.upper; - - // - Add( - iTarget, - targets // - ); - - // - iBox.Clean(); - } -} - -/////////////////////////////////////////////////////////////////////////////////// - -// -void Update( - int barIndex, - XPOIState &htfState, - XPOIState &mtfState, - XPOIState &stfState, - XPOIState &ttfState // -) -{ - // - int idx = -1; - int count = 0; - bool has = false; - - // - if (barIndex < 0) - { - barIndex = 0; - } - - // - has = - // - IsValid() && - // - htfState.IsValid() && - mtfState.IsValid() && - stfState.IsValid() && - // - htfState.HasChild() && - mtfState.HasChild() && - stfState.HasChild() - // - ; - if (!has) - { - return; - } - - // - XOHCL zBar; - has = zBar.Init( - symbol, - period, - barIndex // - ); - if (!has) - { - // - zBar.Clean(); - return; - } - - // - XOHCL cBar; - has = zBar.GetPreviousBar(cBar); - if (!has) - { - // - zBar.Clean(); - cBar.Clean(); - - // - return; - } - - // - // Cleanup Resource ... - - // - zBar.Clean(); - cBar.Clean(); -} - -/////////////////////////////////////////////////////////////////////////////////// - -// -int ExtractOBFVGs( - XOBFVG &dest[], - XPOIState &obState, - XPOIState &fvgState, - // - ENUM_X_OBFVG_FVG_FILTERS filterFVGs = X_OBFVG_FVG_FILTER_INSIDE_OR, - ENUM_X_OBFVG_FVG_SELECTION selectFVG = X_OBFVG_FVG_SELECT_OLDEST, - // - ENUM_TIMEFRAMES forPeriod = NULL, - // - // Start ... - ENUM_XZONE_STATE startState = XZONE_STATE_PASSED, - bool forceStartedBodyOut = false, - // - // Activation ... - ENUM_XZONE_STATE activeState = XZONE_STATE_FAILED, - bool forceActivatedBodyIn = false, - // - // Breaktion ... - ENUM_XZONE_STATE breakState = XZONE_STATE_FAILED, - bool forceBreakedBodyOut = false, - // - // Works ... - ENUM_XZONE_STATE workState = XZONE_STATE_IGNORED, - bool forceWorkedBodyOut = false // -) -{ - // - int result = 0; - - // - bool has = false; - - // - Clean(dest); - - // - has = obState.IsValid() && - fvgState.IsValid() && - obState.HasChild() && - fvgState.HasChild() && - selectFVG != X_OBFVG_FVG_SELECT_NONE && - filterFVGs != X_OBFVG_FVG_FILTER_NONE; - if (!has) - { - return result; - } - - // - XCOrderBlock *obs[]; - int obsCount = obState.FilterOrderBlocks( - obs, - forPeriod, - startState, - forceStartedBodyOut, - activeState, - forceActivatedBodyIn, - breakState, - forceBreakedBodyOut, - workState, - forceWorkedBodyOut // - ); - has = IsValidSize(obsCount); - if (!has) - { - return result; - } - - // - XCFVG *fvgs[]; - int fvgsCount = fvgState.FilterFairValueGaps( - fvgs, - forPeriod, - startState, - forceStartedBodyOut, - activeState, - forceActivatedBodyIn, - breakState, - forceBreakedBodyOut, - workState, - forceWorkedBodyOut // - ); - has = IsValidSize(fvgsCount); - if (!has) - { - return result; - } - - // - for (int i = 0; i < obsCount; i++) - { - // - XCOrderBlock *iOB = obs[i]; - XCFVG *iFVG = NULL; - - // - ENUM_X_DIRECTION iOBDir = iOB.GetDirection(); - bool isIOBBullish = IsBullish(iOBDir); - - // - XCFVG *iFVGs[]; - for (int j = 0; j < fvgsCount; j++) - { - // - XCFVG *jFVG = fvgs[j]; - ENUM_X_DIRECTION jFVGDir = jFVG.GetDirection(); - - // - bool isSameDir = iOBDir == jFVGDir; - bool isFromPassed = jFVG.From() >= iOB.From(); - bool isInsideOr = IsInsideOrDiff( - jFVG, - iOB // - ); - bool isAbove = IsAboveDiff( - jFVG, - iOB, - true // - ); - bool isBelow = IsBelowDiff( - jFVG, - iOB, - true // - ); - - // - bool isFilterPassed = - filterFVGs == X_OBFVG_FVG_FILTER_ABOVE_BELOW - ? isIOBBullish - ? isAbove - : isBelow - : filterFVGs == X_OBFVG_FVG_FILTER_INSIDE_OR - ? isInsideOr - : false; - - // - has = - isSameDir && - isFromPassed && - isFilterPassed; - if (has) - { - // - Add( - jFVG, - iFVGs // - ); - } - } - has = HasChild(iFVGs); - if (!has) - { - continue; - } - - // - int idx = -1; - idx = selectFVG == X_OBFVG_FVG_SELECT_OLDEST - ? GetOldest(iFVGs) - : selectFVG == X_OBFVG_FVG_SELECT_YOUNGEST - ? GetYoungest(iFVGs) - : selectFVG == X_OBFVG_FVG_SELECT_HIGHEST_LOWEST - ? isIOBBullish - ? GetHighest(iFVGs) - : GetLowest(iFVGs) - : selectFVG == X_OBFVG_FVG_SELECT_LOWEST_HIGHEST - ? isIOBBullish - ? GetLowest(iFVGs) - : GetHighest(iFVGs) - : selectFVG == X_OBFVG_FVG_SELECT_LOWEST - ? GetLowest(iFVGs) - : selectFVG == X_OBFVG_FVG_SELECT_HIGHEST - ? GetHighest(iFVGs) - : -1; - - // - has = IsValidIndex(idx); - if (!has) - { - continue; - } - - // - iFVG = iFVGs[idx]; - Clean(iFVGs); - - // - XOBFVG iOBFVG; - iOBFVG.ob = iOB; - iOBFVG.fvg = iFVG; - - // - has = iOBFVG.IsValid(); - if (!has) - { - // - iOBFVG.Clean(); - continue; - } - - // - AddRef( - iOBFVG, - dest // - ); - - // - iOBFVG.Clean(); - } - - // - result = ArraySize(dest); - - // - return result; -} - -/////////////////////////////////////////////////////////////////////////////////// - -// // -// XCBaseObject *obObject; -// bool isCreated = drawer.CreateOrderBlock( -// obFVG.ob, -// obObject // -// ); - -// // -// count = obFVG.CountFVGs(); -// for (int i = 0; i < count; i++) -// { -// // -// XCBaseObject *fvgObject; -// isCreated = drawer.CreateFairValueGap( -// obFVG.fvgs[i], -// fvgObject // -// ); -// } - -/////////////////////////////////////////////////////////////////////////////////// - -// -// Detect OB FVG ... -// result = -// hasNewOrderBlock && -// hasNewFairValueGap && -// ob.GetDirection() == fvg.GetDirection(); -// if (result) -// { -// // -// obFVG.ob = ob; -// obFVG.AddFVG(fvg); - -// // -// has = obFVG.IsValid(); -// if (has) -// { -// // -// has = IsExists(obFVG); -// if (!has) -// { -// // -// // New Waiting Zone ... -// AddRef( -// obFVG, -// waitingZones // -// ); -// } -// else -// { -// // -// // Check Item Is not Exists ... -// idx = FindIndex( -// obFVG, -// waitingZones // -// ); -// has = !IsValidIndex(idx); -// if (!has) -// { -// // -// // Update Exists Waiting Zone ... -// waitingZones[idx].AddFVG(fvg); -// } -// } -// } -// } - -// // -// XCFVG *decisionFVG; -// bool hasNewDecisionFVG = -// Contains( -// X_BULLISH_FVG_DETECTED, -// provider -// .decisionPoiEvents // -// ) || -// Contains( -// X_BEARISH_FVG_DETECTED, -// provider -// .decisionPoiEvents // -// ); -// if (hasNewDecisionFVG) -// { -// // -// idx = GetYoungest(provider -// .decisionState -// .fairValueGaps // -// ); -// has = IsValidIndex(idx); -// if (has) -// { -// // -// decisionFVG = provider -// .decisionState -// .fairValueGaps[idx]; - -// // -// XCBaseObject *iObj; -// bool isCreated = drawer.CreateFairValueGap( -// decisionFVG, -// iObj // -// ); - -// // -// if (isCreated) -// { -// Print("New Fair Value Gap ..."); -// } -// } -// } - -// -// Detect SupDem FVG ... -// if (!result) -// { -// // -// result = hasNewFairValueGap && -// (hasNewSupply || -// hasNewDemand); -// if (result) -// { -// // -// // Converts Supply or Demand Zone to OrderBlock ... -// XOHCL bar; -// ob = new XCOrderBlock(); -// if (hasNewSupply) -// { -// // -// has = supply.FillBar(bar); -// if (has) -// { -// // -// has = ob.Init( -// bar, -// X_DIRECTION_BEARISH // -// ); -// if (has) -// { -// // -// ob.Upper(supply.Upper()); -// ob.Lower(supply.Lower()); -// } -// } -// } -// else if (hasNewDemand) -// { -// // -// has = demand.FillBar(bar); -// if (has) -// { -// // -// has = ob.Init( -// bar, -// X_DIRECTION_BULLISH // -// ); -// if (has) -// { -// // -// ob.Upper(demand.Upper()); -// ob.Lower(demand.Lower()); -// } -// } -// } - -// // -// obFVG.ob = ob; -// obFVG.AddFVG(fvg); - -// // -// has = obFVG.IsValid(); -// if (has) -// { -// // -// // Check Item Is not Exists ... -// idx = FindIndex( -// obFVG, -// waitingZones // -// ); -// has = !IsValidIndex(idx); -// if (has) -// { -// // -// // New Waiting Zone ... -// AddRef( -// obFVG, -// waitingZones // -// ); -// } -// else -// { -// // -// // Update Exists Waiting Zone ... -// waitingZones[idx].AddFVG(fvg); -// } -// } - -// // -// bar.Clean(); -// } -// } - -/////////////////////////////////////////////////////////////////////////////////// - -// -bool IsValidZone( - XOHCL &invalidBar, - int barIndex = 0 // -) -{ - // - bool result = false; - - // - if (barIndex < 0) - { - barIndex = 0; - } - - // - invalidBar.Clean(); - - // - result = IsValid(); - if (!result) - { - return result; - } - - // - XCFVG *fvg; - result = GetMainFVG(fvg); - if (!result) - { - // - ZeroMemory(fvg); - return result; - } - - // - XOHCL startedBar; - bool isBodyOut = false; - result = fvg.IsStarted( - fvg.GetDirection(), - startedBar, - isBodyOut // - ); - if (!result) - { - // - ZeroMemory(fvg); - startedBar.Clean(); - - // - return result; - } - - // - XOHCL bar; - bool isBullish = fvg.IsBullish(); - - // - int fromIndex = iBarShift( - fvg.GetSymbol(), - fvg.GetPeriod(), - startedBar.NextAt() // - ); - result = IsValidIndex(fromIndex); - if (!result) - { - // - bar.Clean(); - ZeroMemory(fvg); - startedBar.Clean(); - - // - return result; - } - - // - bool isInited = false; - for (int i = barIndex; i < fromIndex; i++) - { - // - isInited = bar.Init( - fvg.GetSymbol(), - fvg.GetPeriod(), - i // - ); - if (!isInited) - { - // - bar.Clean(); - continue; - } - - // - bool isBarAbove = - bar.low > fvg.Upper(); - bool isBarBelow = - bar.high < fvg.Lower(); - - // - result = - isBullish - ? isBarAbove - : isBarBelow; - if (!result) - { - // - invalidBar = bar; - bar.Clean(); - - // - break; - } - - // - bar.Clean(); - } - - // - bar.Clean(); - ZeroMemory(fvg); - startedBar.Clean(); - - // - return result; -} - -/////////////////////////////////////////////////////////////////////////////////// - -// -// XBoxZone iBox; -// result = iOBFVG.ToZone(iBox); -// if (!result) -// { -// // -// iBox.Clean(); -// iOBFVG.Clean(); - -// // -// continue; -// } - -// -// XCFVG *fvg; -// result = iOBFVG.GetMainFVG(fvg); -// if (!result) -// { -// // -// iOBFVG.Clean(); -// ZeroMemory(fvg); - -// // -// continue; -// } - -/////////////////////////////////////////////////////////////////////////////////// - -/////////////////////////////////////////////////////////////////////////////////// - -/////////////////////////////////////////////////////////////////////////////////// - -/////////////////////////////////////////////////////////////////////////////////// - -/////////////////////////////////////////////////////////////////////////////////// - -/////////////////////////////////////////////////////////////////////////////////// diff --git a/Documents/BKP/Test.mq5 b/Documents/BKP/Test.mq5 deleted file mode 100644 index 02e4a712..00000000 --- a/Documents/BKP/Test.mq5 +++ /dev/null @@ -1,243 +0,0 @@ -//+------------------------------------------------------------------+ -//| Test.mq5 | -//| Copyright 2025, MetaQuotes Ltd. | -//| https://www.mql5.com | -//+------------------------------------------------------------------+ -#property copyright "Copyright 2025, MetaQuotes Ltd." -#property link "https://www.mql5.com" -#property version "1.00" - -// -#include "../Classes/x-saherelm.x-bar.analyser.class.mq5" -#include "../Classes/x-saherelm.x-poi.class.mq5" -#include "../Classes/x-saherelm.x-poi.drawer.class.mq5" - -// -XCPOIDrawer *mPOIDrawer; -XCPOIDetector *mPOIDetector; -XCBarAnalyser *mBarAnalyser; - -// -XBarTracker mBarTracker; - -//+------------------------------------------------------------------+ -//| Expert initialization function | -//+------------------------------------------------------------------+ -int OnInit() -{ - //--- - mPOIDetector = new XCPOIDetector( - _Symbol, - _Period // - ); - mPOIDetector.Init(); - - //--- - mPOIDrawer = new XCPOIDrawer(); - - //--- - mBarAnalyser = new XCBarAnalyser(); - - //--- - mBarTracker.Init( - _Symbol, - _Period // - ); - - //--- - return (INIT_SUCCEEDED); -} -//+------------------------------------------------------------------+ -//| Expert deinitialization function | -//+------------------------------------------------------------------+ -void OnDeinit(const int reason) -{ - //--- - ZeroMemory(mPOIDrawer); - ZeroMemory(mBarAnalyser); - ZeroMemory(mPOIDetector); -} -//+------------------------------------------------------------------+ -//| Expert tick function | -//+------------------------------------------------------------------+ -void OnTick() -{ - - // - bool isNewBar = mBarTracker.IsNewBar(); - if (!isNewBar) - { - return; - } - - // - ENUM_XPOI_EVENTS mPOIEvents[]; - mPOIDetector.Update(mPOIEvents); - - // - XPOIState mPOIState; - mPOIDetector.GetState(mPOIState); - - // - bool has = Contains( - X_BULLISH_FVG_DETECTED, - mPOIEvents // - ) || - Contains( - X_BEARISH_FVG_DETECTED, - mPOIEvents // - ); - if (has) - { - // - XCFVG *fvg; - int idx = GetYoungest(mPOIState.fairValueGaps); - has = IsValidIndex(idx); - if (has) - { - // - fvg = mPOIState.fairValueGaps[idx]; - - // - XCBaseObject *iObj; - has = mPOIDrawer.CreateFairValueGap( - fvg, - iObj // - ); - - // - if (has) - { - // - Print("New Fair Value Gap ..."); - } - } - } - - // // - // bool has = mPOIState.HasFairValueGaps(); - // if (has) - // { - // // - // int count = mPOIState.CountFairValueGaps(); - // for (int i = 0; i < count; i++) - // { - // // - // mPOIState.fairValueGaps[i].To(TimeCurrent()); - - // // - // XCBaseObject *iObj; - // bool isCreated = mPOIDrawer.CreateFairValueGap( - // mPOIState.fairValueGaps[i], - // iObj // - // ); - // } - - // - // Print("Salam"); - - // - return; - - // // - // XOHCL bar; - // bool isInited = bar.Init( - // _Symbol, - // _Period, - // 0 // - // ); - // if (!isInited) - // { - // return; - // } - - // // - // int index = 0; - // ENUM_X_DIRECTION sameBarDir; - // bool hasSameBars = mBarAnalyser.HasSameBars( - // bar, - // sameBarDir, - // index, - // 3 // - // ); - // if (hasSameBars) - // { - // } - - // // - // // Detect Fair Value Gap ... - // XOHCL fvgEndBar; - // XOHCL fvgStartBar; - // ENUM_X_DIRECTION fvgDir; - // bool hasFVG = mBarAnalyser.HasFairValueGap( - // bar, - // fvgStartBar, - // fvgEndBar, - // fvgDir, - // 3 // - // ); - // if (hasFVG) - // { - // // - // XCFVG *fvg; - // fvg = new XCFVG(); - // bool isInit = fvg.Init( - // fvgStartBar, - // fvgEndBar, - // fvgDir // - // ); - // // if (isInit) - // // { - // // // - // // XCBaseObject *iObj; - // // bool isCreated = mPOIDrawer.CreateFairValueGap( - // // fvg, - // // iObj // - // // ); - // // - // // // - // // if (isCreated) - // // { - // // } - // // } - // } - - // // - // XOHCL obBar; - // ENUM_X_DIRECTION obDir; - // bool hasOB = mBarAnalyser.HasOrderBlock( - // bar, - // obBar, - // obDir, - // 3 // - // ); - // if (hasOB) - // { - // // - // XCOrderBlock *ob; - // ob = new XCOrderBlock(); - // bool isInit = ob.Init( - // obBar, - // obDir // - // ); - // if (isInit) - // { - // // // - // // XCBaseObject *iObj; - // // bool isCreated = mPOIDrawer.CreateOrderBlock( - // // ob, - // // iObj // - // // ); - - // // // - // // if (isCreated) - // // { - // // Print("Order Block ..."); - // // } - // // } - // } - - // // - // } -} -//+------------------------------------------------------------------+ diff --git a/Documents/BKP/smc.ea.mq5 b/Documents/BKP/smc.ea.mq5 deleted file mode 100644 index d8e5e617..00000000 --- a/Documents/BKP/smc.ea.mq5 +++ /dev/null @@ -1,418 +0,0 @@ -//+------------------------------------------------------------------+ -//| SMC_OrderBlock_EA.mq5| -//| Copyright 2023, MetaQuotes Software Corp. | -//| https://www.mql5.com | -//+------------------------------------------------------------------+ -#property copyright "Copyright 2023, MetaQuotes Software Corp." -#property link "https://www.mql5.com" -#property version "1.00" -#property strict - -#include -#include - -// -// Input parameters -input ENUM_TIMEFRAMES TimeFrame = PERIOD_M15; // Timeframe for analysis -input double RiskPercent = 1.0; // Risk per trade (1-2%) -input int ATR_Period = 14; // ATR period for volatility -input int OrderBlockLength = 20; // Bars for consolidation -input int ConfirmationCandles = 3; // Candles to confirm breakout -input double StopLossMultiplier = 1.5; // Stop loss buffer -input double TakeProfitRatio = 2.0; // Risk:Reward ratio -input int TrailingStopPips = 50; // Trailing stop in pips - -// -CTrade trade; -CAccountInfo accountInfo; - -// -double Ask = 0; -double Bid = 0; - -// -// Order Block structure -struct OrderBlock -{ - datetime startTime; - double high; - double low; -}; - -// -int atrHandler = INVALID_HANDLE; -int maFastHandler = INVALID_HANDLE; -int maSlowHandler = INVALID_HANDLE; - -// -double atrs[]; -double fastMAs[]; -double slowMAs[]; - -//+------------------------------------------------------------------+ -//| Expert initialization function | -//+------------------------------------------------------------------+ -int OnInit() -{ - // - trade.SetExpertMagicNumber(123456); // Unique magic number - - // - atrHandler = iATR(_Symbol, TimeFrame, ATR_Period); - maFastHandler = iMA(_Symbol, TimeFrame, 20, 0, MODE_SMA, PRICE_CLOSE); - maSlowHandler = iMA(_Symbol, TimeFrame, 50, 0, MODE_SMA, PRICE_CLOSE); - - // - bool isValid = - atrHandler != INVALID_HANDLE && - maFastHandler != INVALID_HANDLE && - maSlowHandler != INVALID_HANDLE; - if (!isValid) - { - return (INIT_FAILED); - } - - // - return (INIT_SUCCEEDED); -} -//+------------------------------------------------------------------+ - -//+------------------------------------------------------------------+ -//| Expert deinitialization function | -//+------------------------------------------------------------------+ -void OnDeinit(const int reason) -{ - // - // Cleanup code if needed ... - IndicatorRelease(atrHandler); - IndicatorRelease(maFastHandler); - IndicatorRelease(maSlowHandler); - - // - ZeroMemory(atrs); - ZeroMemory(fastMAs); - ZeroMemory(slowMAs); -} -//+------------------------------------------------------------------+ - -//+------------------------------------------------------------------+ -//| Expert tick function | -//+------------------------------------------------------------------+ -void OnTick() -{ - // Avoid multiple orders - if (CheckOpenOrders()) - return; - - // - CopyBuffer(atrHandler, MAIN_LINE, 0, 200, atrs); - - // - CopyBuffer(maFastHandler, MAIN_LINE, 0, 2, fastMAs); - CopyBuffer(maSlowHandler, MAIN_LINE, 0, 2, slowMAs); - - // - Ask = NormalizeDouble(SymbolInfoDouble(_Symbol, SYMBOL_ASK), _Digits); // Get the Ask Price - Bid = NormalizeDouble(SymbolInfoDouble(_Symbol, SYMBOL_BID), _Digits); // Get the Bid Price - - // - // Check for trend and execute trades - if (IsUptrend()) - { - OrderBlock block = FindBullishOrderBlock(); - if (block.startTime != 0 && IsPriceInBlock(block)) - { - if (ConfirmBullishEntry()) - ExecuteTrade(block, ORDER_TYPE_BUY); - } - } - else if (IsDowntrend()) - { - OrderBlock block = FindBearishOrderBlock(); - if (block.startTime != 0 && IsPriceInBlock(block)) - { - if (ConfirmBearishEntry()) - ExecuteTrade(block, ORDER_TYPE_SELL); - } - } - - // Manage trailing stops - TrailStop(); -} -//+------------------------------------------------------------------+ - -//+------------------------------------------------------------------+ -//| Check if price is within the order block | -//+------------------------------------------------------------------+ -bool IsPriceInBlock(OrderBlock &block) -{ - double currentPrice = (Ask + Bid) / 2; // Mid-price - return (currentPrice >= block.low && currentPrice <= block.high); -} -//+------------------------------------------------------------------+ - -//+------------------------------------------------------------------+ -//| Detect uptrend using moving averages | -//+------------------------------------------------------------------+ -bool IsUptrend() -{ - // - double maFast = fastMAs[0]; - double maSlow = slowMAs[0]; - - // - return (maFast > maSlow); -} -//+------------------------------------------------------------------+ - -//+------------------------------------------------------------------+ -//| Detect downtrend using moving averages | -//+------------------------------------------------------------------+ -bool IsDowntrend() -{ - // - double maFast = fastMAs[0]; - double maSlow = slowMAs[0]; - - // - return (maFast < maSlow); -} -//+------------------------------------------------------------------+ - -//+------------------------------------------------------------------+ -//| Find bullish order blocks | -//+------------------------------------------------------------------+ -OrderBlock FindBullishOrderBlock() -{ - // - OrderBlock block; - block.startTime = 0; - - // - for (int i = 1; i < 100; i++) - { - double prevHigh = iHigh(NULL, TimeFrame, i); - double prevLow = iLow(NULL, TimeFrame, i); - double prevClose = iClose(NULL, TimeFrame, i); - double prevOpen = iOpen(NULL, TimeFrame, i); - - double atr = atrs[i]; - if (prevClose - prevOpen > 1.5 * atr) - { // Strong bullish candle - double consolidationHigh = prevHigh; - double consolidationLow = prevLow; - bool isConsolidation = true; - - for (int j = 1; j <= OrderBlockLength; j++) - { - double newHigh = iHigh(NULL, TimeFrame, i - j); - double newLow = iLow(NULL, TimeFrame, i - j); - consolidationHigh = MathMax(consolidationHigh, newHigh); - consolidationLow = MathMin(consolidationLow, newLow); - - if ((consolidationHigh - consolidationLow) > 0.5 * atr) - { - isConsolidation = false; - break; - } - } - - if (isConsolidation) - { - block.high = consolidationHigh; - block.low = consolidationLow; - block.startTime = iTime(NULL, TimeFrame, i); - return block; - } - } - } - return block; -} -//+------------------------------------------------------------------+ - -//+------------------------------------------------------------------+ -//| Find bearish order blocks | -//+------------------------------------------------------------------+ -OrderBlock FindBearishOrderBlock() -{ - // - OrderBlock block; - block.startTime = 0; - - // - for (int i = 1; i < 100; i++) - { - double prevHigh = iHigh(NULL, TimeFrame, i); - double prevLow = iLow(NULL, TimeFrame, i); - double prevClose = iClose(NULL, TimeFrame, i); - double prevOpen = iOpen(NULL, TimeFrame, i); - - double atr = atrs[i]; - if (prevOpen - prevClose > 1.5 * atr) - { // Strong bearish candle - double consolidationHigh = prevHigh; - double consolidationLow = prevLow; - bool isConsolidation = true; - - for (int j = 1; j <= OrderBlockLength; j++) - { - double newHigh = iHigh(NULL, TimeFrame, i - j); - double newLow = iLow(NULL, TimeFrame, i - j); - consolidationHigh = MathMax(consolidationHigh, newHigh); - consolidationLow = MathMin(consolidationLow, newLow); - - if ((consolidationHigh - consolidationLow) > 0.5 * atr) - { - isConsolidation = false; - break; - } - } - - if (isConsolidation) - { - block.high = consolidationHigh; - block.low = consolidationLow; - block.startTime = iTime(NULL, TimeFrame, i); - return block; - } - } - } - return block; -} -//+------------------------------------------------------------------+ - -//+------------------------------------------------------------------+ -//| Confirm bullish entry with candle pattern | -//+------------------------------------------------------------------+ -bool ConfirmBullishEntry() -{ - // - int shift = iBarShift(NULL, TimeFrame, TimeCurrent()); - double prevLow = iLow(NULL, TimeFrame, shift + 1); - double currentClose = iClose(NULL, TimeFrame, shift); - return (currentClose > prevLow && iOpen(NULL, TimeFrame, shift) < currentClose); -} -//+------------------------------------------------------------------+ - -//+------------------------------------------------------------------+ -//| Confirm bearish entry with candle pattern | -//+------------------------------------------------------------------+ -bool ConfirmBearishEntry() -{ - // - int shift = iBarShift(NULL, TimeFrame, TimeCurrent()); - double prevHigh = iHigh(NULL, TimeFrame, shift + 1); - double currentClose = iClose(NULL, TimeFrame, shift); - return (currentClose < prevHigh && iOpen(NULL, TimeFrame, shift) > currentClose); -} -//+------------------------------------------------------------------+ - -//+------------------------------------------------------------------+ -//| Execute trade with risk management | -//+------------------------------------------------------------------+ -void ExecuteTrade(OrderBlock &block, ENUM_ORDER_TYPE orderType) -{ - // - double atr = atrs[0]; - double stopLoss, takeProfit, lotSize; - double entryPrice = (orderType == ORDER_TYPE_BUY) ? Ask : Bid; - - // Calculate stop loss and take profit - if (orderType == ORDER_TYPE_BUY) - { - stopLoss = block.low - StopLossMultiplier * atr; - takeProfit = entryPrice + (entryPrice - stopLoss) * TakeProfitRatio; - } - else - { - stopLoss = block.high + StopLossMultiplier * atr; - takeProfit = entryPrice - (stopLoss - entryPrice) * TakeProfitRatio; - } - - // Calculate lot size based on risk - lotSize = CalculateLotSize(stopLoss, entryPrice, orderType); - if (lotSize <= 0) - return; - - // Place order - if (orderType == ORDER_TYPE_BUY) - { - trade.Buy(lotSize, _Symbol, entryPrice, stopLoss, takeProfit, "SMC Bullish Order Block"); - } - else - { - trade.Sell(lotSize, _Symbol, entryPrice, stopLoss, takeProfit, "SMC Bearish Order Block"); - } -} -//+------------------------------------------------------------------+ - -//+------------------------------------------------------------------+ -//| Calculate lot size based on risk per trade | -//+------------------------------------------------------------------+ -double CalculateLotSize(double stopLoss, double entryPrice, ENUM_ORDER_TYPE orderType) -{ - double riskAmount = AccountBalance() * RiskPercent / 100; - double stopLossPips = MathAbs((entryPrice - stopLoss) / SymbolInfoDouble(_Symbol, SYMBOL_POINT)); - - if (stopLossPips == 0) - return 0; - - double pipValue = SymbolInfoDouble(_Symbol, SYMBOL_TRADE_TICK_VALUE); - double lotSize = riskAmount / (stopLossPips * pipValue); - lotSize = NormalizeDouble(lotSize, 2); // Adjust to symbol's lot precision - - return MathMax(lotSize, SymbolInfoDouble(_Symbol, SYMBOL_VOLUME_MIN)); -} -//+------------------------------------------------------------------+ - -//+------------------------------------------------------------------+ -//| Check for existing open orders | -//+------------------------------------------------------------------+ -bool CheckOpenOrders() -{ - for (int i = 0; i < PositionsTotal(); i++) - { - if (PositionGetSymbol(i) == _Symbol) - return true; - } - return false; -} -//+------------------------------------------------------------------+ - -//+------------------------------------------------------------------+ -//| Trailing stop logic | -//+------------------------------------------------------------------+ -void TrailStop() -{ - for (int i = 0; i < PositionsTotal(); i++) - { - if (PositionGetSymbol(i) != _Symbol) - continue; - - ulong ticket = PositionGetInteger(POSITION_TICKET); - ENUM_POSITION_TYPE type = (ENUM_POSITION_TYPE)PositionGetInteger(POSITION_TYPE); - double currentPrice = (type == POSITION_TYPE_BUY) ? Bid : Ask; - double openPrice = PositionGetDouble(POSITION_PRICE_OPEN); - double stopLoss = PositionGetDouble(POSITION_SL); - double trailingStopPrice = (type == POSITION_TYPE_BUY) - ? currentPrice - TrailingStopPips * SymbolInfoDouble(_Symbol, SYMBOL_POINT) - : currentPrice + TrailingStopPips * SymbolInfoDouble(_Symbol, SYMBOL_POINT); - - // Update stop loss if price moves favorably - if ((type == POSITION_TYPE_BUY && trailingStopPrice > stopLoss) || - (type == POSITION_TYPE_SELL && trailingStopPrice < stopLoss)) - { - trade.PositionModify(ticket, trailingStopPrice, PositionGetDouble(POSITION_TP)); - } - } -} -//+------------------------------------------------------------------+ - -//+------------------------------------------------------------------+ -//| Calculate Account Balance | -//+------------------------------------------------------------------+ -double AccountBalance() -{ - return accountInfo.Balance(); -} -//+------------------------------------------------------------------+ diff --git a/Documents/BKP/testob.mq5 b/Documents/BKP/testob.mq5 deleted file mode 100644 index 8910672e..00000000 --- a/Documents/BKP/testob.mq5 +++ /dev/null @@ -1,275 +0,0 @@ -//+------------------------------------------------------------------+ -//| OrderBlockDetector.mq5| -//| Copyright 2023, MetaQuotes Software Corp. | -//| https://www.mql5.com| -//+------------------------------------------------------------------+ -#property strict - -// -// Input Parameters -input int ConsolidationPeriod = 20; // Bars for consolidation detection -input int AtrPeriod = 14; // ATR period for volatility -input double AtrMultiplier = 2.0; // Threshold multiplier (ATR * multiplier) -input int VolumeThreshold = 1000; // Minimum volume for breakout -input bool RequireRetest = true; // Retest confirmation required? -input int VpvrBars = 50; // Bars for VPVR calculation -input int TrendCheckPeriod = 30; // Bars for trend structure analysis -input int MACDFast = 12; // MACD Fast EMA period -input int MACDSlow = 26; // MACD Slow EMA period -input int MACDSignal = 9; // MACD Signal period -input int RSIPeriod = 14; // RSI period -input double RSILevel = 50; // RSI threshold level - -// Global Variables -int ObjectId = 0; -string Prefix = "OrderBlock_"; - -// -enum ENUM_X_DIRECTION -{ - X_DIRECTION_NONE, - X_DIRECTION_BULISH, - X_DIRECTION_BEARISH, -}; - -// -int atrHandler = INVALID_HANDLE; -double atrBuffer[]; - -// -int rsiHandler = INVALID_HANDLE; -double rsiBuffer[]; - -// -int macdHandler = INVALID_HANDLE; -double macdMainBuffer[]; -double macdSignalBuffer[]; - -//+------------------------------------------------------------------+ -//| Expert initialization function | -//+------------------------------------------------------------------+ -int OnInit() -{ - // - ArraySetAsSeries(atrBuffer, true); - atrHandler = iATR(_Symbol, _Period, AtrPeriod); - - // - ArraySetAsSeries(rsiBuffer, true); - rsiHandler = iRSI(_Symbol, _Period, RSIPeriod, PRICE_CLOSE); - - // - ArraySetAsSeries(macdMainBuffer, true); - ArraySetAsSeries(macdSignalBuffer, true); - macdHandler = iMACD(_Symbol, _Period, MACDFast, MACDSlow, MACDSignal, PRICE_CLOSE); - - // - ObjectsDeleteAll(0, Prefix); - return (INIT_SUCCEEDED); -} - -//+------------------------------------------------------------------+ -//| Expert deinitialization function | -//+------------------------------------------------------------------+ -void OnDeinit(const int reason) -{ - // - IndicatorRelease(atrHandler); - ObjectsDeleteAll(0, Prefix); -} - -//+------------------------------------------------------------------+ -//| Expert tick function | -//+------------------------------------------------------------------+ -void OnTick() -{ - DetectOrderBlocks(); -} - -//+------------------------------------------------------------------+ -//| Detect Order Blocks with ATR Dynamic Threshold | -//+------------------------------------------------------------------+ -void DetectOrderBlocks() -{ - double high, low, vpvrPrice, atr, dynamicThreshold; - datetime startTime, endTime; - bool isBullish, isBearish; - int bars = Bars(_Symbol, _Period); - - for (int i = ConsolidationPeriod; i < bars; i++) - { - // - // Get consolidation range - high = iHigh(_Symbol, _Period, iHighest(_Symbol, _Period, MODE_HIGH, ConsolidationPeriod, i)); - low = iLow(_Symbol, _Period, iLowest(_Symbol, _Period, MODE_LOW, ConsolidationPeriod, i)); - double range = high - low; - - // - // Calculate dynamic threshold using ATR - CopyBuffer(atrHandler, MAIN_LINE, i, 2, atrBuffer); - atr = atrBuffer[0]; - dynamicThreshold = atr * AtrMultiplier; - - // Check if consolidation range is within ATR-based threshold - if (range <= dynamicThreshold) - { - // VPVR Integration - vpvrPrice = CalculateVPVR(i, ConsolidationPeriod); - bool validVPVR = (vpvrPrice > low && vpvrPrice < high); - - // Check breakout direction - isBullish = iClose(_Symbol, _Period, i - ConsolidationPeriod) > high; - isBearish = iClose(_Symbol, _Period, i - ConsolidationPeriod) < low; - - // Trend Verification - ENUM_X_DIRECTION trend = CheckTrendStructure(TrendCheckPeriod); - - // MACD/RSI Verification - bool macdValid = CheckMACD(trend); - bool rsiValid = CheckRSI(trend); - - // Validate all conditions - if ((isBullish || isBearish) && validVPVR && - (trend != -1) && macdValid && rsiValid) - { - double breakoutVolume = (double)iVolume(_Symbol, _Period, i - ConsolidationPeriod); - if (breakoutVolume < VolumeThreshold) - continue; - - // Define order block time window - startTime = iTime(_Symbol, _Period, i); - endTime = iTime(_Symbol, _Period, i + ConsolidationPeriod); - - // Check retest (if required) - if (RequireRetest) - { - bool retestFound = false; - for (int j = i - ConsolidationPeriod; j > 0; j--) - { - if ((isBullish && iLow(_Symbol, _Period, j) <= low && iLow(_Symbol, _Period, j) >= high) || - (isBearish && iHigh(_Symbol, _Period, j) >= high && iHigh(_Symbol, _Period, j) <= low)) - { - retestFound = true; - break; - } - } - if (!retestFound) - continue; - } - - // Draw order block with ATR annotation - string name = Prefix + IntegerToString(ObjectId++); - DrawOrderBlock(name, startTime, endTime, low, high, - isBullish ? clrGreen : clrRed, vpvrPrice, dynamicThreshold); - } - } - } -} - -//+------------------------------------------------------------------+ -//| Trend Detection using Price Structure | -//+------------------------------------------------------------------+ -ENUM_X_DIRECTION CheckTrendStructure(int period) -{ - int currentStart = 1; - int previousStart = period + 1; - - double currentHigh = iHigh(_Symbol, _Period, iHighest(_Symbol, _Period, MODE_HIGH, period, currentStart)); - double previousHigh = iHigh(_Symbol, _Period, iHighest(_Symbol, _Period, MODE_HIGH, period, previousStart)); - double currentLow = iLow(_Symbol, _Period, iLowest(_Symbol, _Period, MODE_LOW, period, currentStart)); - double previousLow = iLow(_Symbol, _Period, iLowest(_Symbol, _Period, MODE_LOW, period, previousStart)); - - if (currentHigh > previousHigh && currentLow > previousLow) - return (X_DIRECTION_BULISH); // Uptrend - else if (currentHigh < previousHigh && currentLow < previousLow) - return (X_DIRECTION_BEARISH); // Downtrend - else - return (X_DIRECTION_NONE); // No clear trend -} - -//+------------------------------------------------------------------+ -//| MACD Trend Verification | -//+------------------------------------------------------------------+ -bool CheckMACD(ENUM_X_DIRECTION trend) -{ - // - CopyBuffer(macdHandler, MAIN_LINE, 0, 1, macdMainBuffer); - CopyBuffer(macdHandler, SIGNAL_LINE, 0, 1, macdSignalBuffer); - double macdMain = macdMainBuffer[0]; - double macdSignal = macdSignalBuffer[0]; - - // - if (trend == X_DIRECTION_BULISH) - return (macdMain > macdSignal); - if (trend == X_DIRECTION_BEARISH) - return (macdMain < macdSignal); - return (false); -} - -//+------------------------------------------------------------------+ -//| RSI Trend Verification | -//+------------------------------------------------------------------+ -bool CheckRSI(ENUM_X_DIRECTION trend) -{ - // - CopyBuffer(rsiHandler, MAIN_LINE, 0, 1, rsiBuffer); - double rsiValue = rsiBuffer[0]; - - // - if (trend == X_DIRECTION_BULISH) - return (rsiValue > RSILevel); - if (trend == X_DIRECTION_BEARISH) - return (rsiValue < RSILevel); - return (false); -} - -//+------------------------------------------------------------------+ -//| Calculate VPVR High Volume Node | -//+------------------------------------------------------------------+ -double CalculateVPVR(int startIdx, int period) -{ - double maxVolume = 0; - double vpvrPrice = 0; - double price, volume; - - for (int i = startIdx; i < startIdx + period; i++) - { - price = (iHigh(_Symbol, _Period, i) + iLow(_Symbol, _Period, i)) / 2; - volume = (double)iVolume(_Symbol, _Period, i); - if (volume > maxVolume) - { - maxVolume = volume; - vpvrPrice = price; - } - } - return (vpvrPrice); -} - -//+------------------------------------------------------------------+ -//| Draw Order Block with ATR Annotation | -//+------------------------------------------------------------------+ -void DrawOrderBlock(string name, datetime startTime, datetime endTime, - double bottom, double top, color clr, double vpvrPrice, double atrThreshold) -{ - // Draw rectangle - ObjectCreate(0, name + "_rect", OBJ_RECTANGLE, 0, startTime, top, endTime, bottom); - ObjectSetInteger(0, name + "_rect", OBJPROP_COLOR, clr); - ObjectSetInteger(0, name + "_rect", OBJPROP_FILL, true); - ObjectSetInteger(0, name + "_rect", OBJPROP_BACK, true); - ObjectSetInteger(0, name + "_rect", OBJPROP_WIDTH, 2); - - // Draw VPVR marker - if (vpvrPrice > 0) - { - ObjectCreate(0, name + "_vpvr", OBJ_HLINE, 0, 0, vpvrPrice); - ObjectSetInteger(0, name + "_vpvr", OBJPROP_COLOR, clrYellow); - ObjectSetInteger(0, name + "_vpvr", OBJPROP_WIDTH, 1); - } - - // Add ATR threshold label - string atrLabel = StringFormat("ATR Threshold: %.5f", atrThreshold); - ObjectCreate(0, name + "_atr", OBJ_TEXT, 0, startTime, top); - ObjectSetString(0, name + "_atr", OBJPROP_TEXT, atrLabel); - ObjectSetInteger(0, name + "_atr", OBJPROP_COLOR, clrWhite); -} -//+------------------------------------------------------------------+ \ No newline at end of file diff --git a/Documents/BKP/x-121.smc.xwz.signal.class copy 2.mq5 b/Documents/BKP/x-121.smc.xwz.signal.class copy 2.mq5 deleted file mode 100644 index 1f79c257..00000000 --- a/Documents/BKP/x-121.smc.xwz.signal.class copy 2.mq5 +++ /dev/null @@ -1,2295 +0,0 @@ -/////////////////////////////////////////////////////// -// -// SaherElm IT Center MQL5 X121 SMC Signal Class -// ------------------------------------------------- -// Name: XWZ -// Description: provide all Signalling functions ... -// -// -// Maintainer: -// ------------ -// Hadi Khazaee Asl (hadi_khazaee_asl@yahoo.com) -// -////////////////////////////////////////////////////// -// -// Global Properties ... -#property library -#property copyright "Copyright 2023, SaherElm IT Center" -#property link "https://www.saherelm.ir" -#property version "1.00" -#property strict - -// -// Imports ... -#include "../Classes/x-121.smc.market.cycle.helper.class.mq5" -#include "../Libraries/x-121.smc.guard.lib.mq5" -#include "../Libraries/x-121.smc.lib.mq5" -#include "./x-121.smc.xwz.signal.lib.mq5" - -// -// Definition ... -class XCX121SMCXWZSignalDetector : public XCBase -{ - // - public: - // - // Props ... - X121SMCStrategyXWZWorkingZone workingZone; - X121SMCStrategyXWZSignalConditions mConditions; - X121SMCStrategyXWZSignalConditions mConditionsCollection[]; - - // - // Constructor(s) ... - XCX121SMCXWZSignalDetector( - string _symbol, - ENUM_TIMEFRAMES _period // - ) - { - // - symbol = _symbol; - period = _period; - Init(); - } - - // - // Deconstructor ... - ~XCX121SMCXWZSignalDetector() - { - DeInit(); - } - - // - // - // - - // - // Detect Setup Conditions ... - bool DetectSignalSetup( - // - XC121SMCCycleHelper *decisionCycleHelper, - XC121SMCCycleHelper *analyseCycleHelper, - XC121SMCCycleHelper *consolidationCycleHelper, - XC121SMCCycleHelper *visionCycleHelper, - // - double maxAllowedSLDistanceInPoint = 300 - // - ) - { - // - bool result = false; - - // - // Validate Cycle Helpers ... - result = - // - visionCycleHelper != NULL && - analyseCycleHelper != NULL && - decisionCycleHelper != NULL && - consolidationCycleHelper != NULL - // - ; - if (!result) - { - // - mConditions.Clean(); - - // - return result; - } - - // - bool isBullish = false; - bool isBearish = false; - - // - int zIndex = 0; - int cIndex = zIndex + 1; - int pIndex = cIndex + 1; - int ppIndex = pIndex + 1; - - // - int loopback = 10; - - // - mConditions.symbol = symbol; - mConditions.period = period; - - // - double ask = GetAsk(symbol); - double bid = GetBid(symbol); - datetime cTime = TimeCurrent(); - double points = GetPoints(symbol); - - // - // Cycles Conditions ... - - // - XOHCL consolidationZBar; - result = consolidationCycleHelper.GetBar( - consolidationZBar, - zIndex // - ); - if (!result) - { - // - consolidationZBar.Clean(); - return result; - } - - // - bool drawBar = false; - if (drawBar) - { - // - DrawBar( - consolidationZBar, - decisionCycleHelper.mPOIDrawer // - ); - } - - // - // Decision ... - ENUM_XPOI_EVENTS decisionPoiEvents[]; - ENUM_X_CYCLE_EVENTS decisionCycleEvents[]; - X121SMCCycleConditions decisionConditions; - result = decisionCycleHelper.GetConditions( - decisionCycleEvents, - decisionPoiEvents, - decisionConditions, - zIndex, - loopback // - ); - if (!result) - { - // - Clean(decisionPoiEvents); - Clean(decisionCycleEvents); - - // - decisionConditions.Clean(); - - // - mConditions.Clean(); - consolidationZBar.Clean(); - - // - return result; - } - - // - // Analyse ... - ENUM_XPOI_EVENTS analysePoiEvents[]; - ENUM_X_CYCLE_EVENTS analyseCycleEvents[]; - X121SMCCycleConditions analyseConditions; - result = analyseCycleHelper.GetConditions( - analyseCycleEvents, - analysePoiEvents, - analyseConditions, - zIndex, - loopback // - ); - if (!result) - { - // - Clean(analysePoiEvents); - Clean(decisionPoiEvents); - - // - Clean(analyseCycleEvents); - Clean(decisionCycleEvents); - - // - analyseConditions.Clean(); - decisionConditions.Clean(); - - // - mConditions.Clean(); - consolidationZBar.Clean(); - - // - return result; - } - - // - // Consolidation ... - ENUM_XPOI_EVENTS consolidationPoiEvents[]; - ENUM_X_CYCLE_EVENTS consolidationCycleEvents[]; - X121SMCCycleConditions consolidationConditions; - result = consolidationCycleHelper.GetConditions( - consolidationCycleEvents, - consolidationPoiEvents, - consolidationConditions, - zIndex, - loopback // - ); - if (!result) - { - // - Clean(analysePoiEvents); - Clean(decisionPoiEvents); - Clean(consolidationPoiEvents); - - // - Clean(analyseCycleEvents); - Clean(decisionCycleEvents); - Clean(consolidationCycleEvents); - - // - analyseConditions.Clean(); - decisionConditions.Clean(); - consolidationConditions.Clean(); - - // - mConditions.Clean(); - consolidationZBar.Clean(); - - // - return result; - } - - // - // Vision ... - ENUM_XPOI_EVENTS visionPoiEvents[]; - ENUM_X_CYCLE_EVENTS visionCycleEvents[]; - X121SMCCycleConditions visionConditions; - result = visionCycleHelper.GetConditions( - visionCycleEvents, - visionPoiEvents, - visionConditions, - zIndex, - loopback // - ); - if (!result) - { - // - Clean(visionPoiEvents); - Clean(analysePoiEvents); - Clean(decisionPoiEvents); - Clean(consolidationPoiEvents); - - // - Clean(visionCycleEvents); - Clean(analyseCycleEvents); - Clean(decisionCycleEvents); - Clean(consolidationCycleEvents); - - // - visionConditions.Clean(); - analyseConditions.Clean(); - decisionConditions.Clean(); - consolidationConditions.Clean(); - - // - mConditions.Clean(); - consolidationZBar.Clean(); - - // - return result; - } - - // - // Cycles POI States ... - XPOIState decisionState = decisionConditions.state; - XPOIState analyseState = analyseConditions.state; - XPOIState consolidationState = consolidationConditions.state; - XPOIState visionState = visionConditions.state; - - // - // Cycle X121Conditions ... - X121Conditions decisionXConditions = decisionConditions.x121Conditions; - X121Conditions analyseXConditions = analyseConditions.x121Conditions; - X121Conditions consolidationXConditions = consolidationConditions.x121Conditions; - X121Conditions visionXConditions = visionConditions.x121Conditions; - - // - // Scores ... - - // - // Decision ... - double decisionBullishScore = 0; - double decisionBearishScore = 0; - decisionXConditions.GenerateScore( - decisionBullishScore, - decisionBearishScore // - ); - - // - // Analyse ... - double analyseBullishScore = 0; - double analyseBearishScore = 0; - analyseXConditions.GenerateScore( - analyseBullishScore, - analyseBearishScore // - ); - - // - // - // - - // - bool hasNewSupply = Contains( - X_SUPPLY_ZONE_DETECTED, - analysePoiEvents // - ); - - // - bool hasNewDemand = Contains( - X_DEMAND_ZONE_DETECTED, - analysePoiEvents // - ); - - // - bool hasNewFairValueGap = - Contains( - X_BULLISH_FVG_DETECTED, - analysePoiEvents // - ) || - Contains( - X_BEARISH_FVG_DETECTED, - analysePoiEvents // - ); - - // - bool hasNewOrderBlock = - Contains( - X_BULLISH_ORDERBLOCK_DETECTED, - analysePoiEvents // - ) || - Contains( - X_BEARISH_ORDERBLOCK_DETECTED, - analysePoiEvents // - ); - - // - // - // - - // - // Select Drawer Class ... - XCPOIDrawer *drawer = visionCycleHelper.mPOIDrawer; - - // - // Setup Conditions ... - double sls[]; - double sl = 0; - double pivot = 0; - double point = 0; - double targets[]; - double reward = 0; - XBoxZone signalBox; - double amountPercent = 0; - bool hasPriority = false; - bool hasSignalBox = false; - bool hasRewardAmount = false; - bool isSignalBoxReversal = false; - bool hasWorkingZoneOveralDirection = false; - ENUM_X_DIRECTION wzOveralDir = X_DIRECTION_NONE; - ENUM_X_DIRECTION signalBoxDir = X_DIRECTION_NONE; - ENUM_X121SMC_XWZ_PRIORITY priority = X121SMC_XWZ_PRIORITY_NONE; - ENUM_X121SMC_XWZ_PROVIDERS provider = X121SMC_XWZ_PROVIDER_NONE; - - // - // - // - - // - // First We Have to Has Working Zone ... - bool hasWorkingZone = workingZone.IsValid(); - if (!hasWorkingZone) - { - // - hasWorkingZone = workingZone.Init( - symbol, - period, - zIndex, - visionState, - consolidationState, - analyseState, - decisionState // - ); - } - - // - // Update Working Zone ... - if (hasWorkingZone) - { - // - // Reset POI Detector Required POI(s) ... - visionCycleHelper.mPOIDetector.MaxRequiredPOIs(50); - analyseCycleHelper.mPOIDetector.MaxRequiredPOIs(50); - decisionCycleHelper.mPOIDetector.MaxRequiredPOIs(50); - consolidationCycleHelper.mPOIDetector.MaxRequiredPOIs(50); - - // - // Reset POI Detector Allowed Loopback ... - visionCycleHelper.mPOIDetector.MaxAllowedLoopbackForInit(578); - analyseCycleHelper.mPOIDetector.MaxAllowedLoopbackForInit(578); - decisionCycleHelper.mPOIDetector.MaxAllowedLoopbackForInit(578); - consolidationCycleHelper.mPOIDetector.MaxAllowedLoopbackForInit(578); - - // - // Update Working Zone ... - // workingZone.Update( - // zIndex, - // visionState, - // consolidationState, - // analyseState, - // decisionState // - // ); - - // - // Check Working Zone Overal Direction ... - hasWorkingZoneOveralDirection = workingZone - .DetectOveralDirection(wzOveralDir); - - // - // Checking Working Zone Destory or not ... - bool isWorkingZoneDestroyed = workingZone.IsDestroyed( - zIndex, - period // - ); - - // - // Cleanup WorkingZone and ignore all conditions ... - if (isWorkingZoneDestroyed) - { - // - result = false; - workingZone.Clean(); - hasWorkingZone = false; - - // - // Cleanup Resources ... - Clean(visionPoiEvents); - Clean(analysePoiEvents); - Clean(decisionPoiEvents); - Clean(consolidationPoiEvents); - - // - Clean(visionCycleEvents); - Clean(analyseCycleEvents); - Clean(decisionCycleEvents); - Clean(consolidationCycleEvents); - - // - visionState.Clean(); - analyseState.Clean(); - decisionState.Clean(); - consolidationState.Clean(); - - // - visionConditions.Clean(); - analyseConditions.Clean(); - decisionConditions.Clean(); - consolidationConditions.Clean(); - - // - visionXConditions.Clean(); - analyseXConditions.Clean(); - decisionXConditions.Clean(); - consolidationXConditions.Clean(); - - // - mConditions.Clean(); - consolidationZBar.Clean(); - - // - return result; - } - } - - // - // - // - - // - // Waiting Box Detected ... - bool hasWaitingBoxes = hasWorkingZone && - workingZone.HasWaitingBoxes(); - if (hasWaitingBoxes) - { - // - XOHCL zBar; - XOHCL cBar; - XOHCL pBar; - int count = 0; - int idx = -1; - bool has = false; - - // - bool isInited = zBar.Init( - symbol, - period, - zIndex // - ); - isInited = - isInited && - zBar.GetPreviousBar(cBar); - isInited = - isInited && - cBar.GetPreviousBar(pBar); - - // - count = workingZone.CountWaitingBoxes(); - for (int i = 0; i < count; i++) - { - // - XBoxZone iBox = workingZone.waitingBoxes[i]; - ENUM_X_DIRECTION iDir = iBox.dir; - bool isBullish = IsBullish(iDir); - - // - // Check Price Rejection ... - - // - bool hasBullishFiboPressure = - decisionCycleHelper - .mBarAnalyser - .HasFiboPressure( - cBar, - X_DIRECTION_BULLISH, - X_FIBO_LEVEL_382 // - ); - - // - bool hasBearishFiboPressure = - decisionCycleHelper - .mBarAnalyser - .HasFiboPressure( - cBar, - X_DIRECTION_BEARISH, - X_FIBO_LEVEL_382 // - ); - - // - // Bullish Rejection ... - bool isBullishRejected = - // - isInited && - isBullish && - cBar.low < pBar.low && - zBar.low > iBox.upper && - cBar.low <= iBox.upper && - zBar.open > iBox.upper && - hasBullishFiboPressure && - cBar.GetLowShadow() > pBar.GetLowShadow() - // - ; - - // - // Bearish Rejection ... - bool isBearishhRejected = - // - isInited && - !isBullish && - cBar.high > pBar.high && - zBar.open < iBox.lower && - zBar.high < iBox.lower && - hasBearishFiboPressure && - cBar.high >= iBox.lower && - cBar.GetHighShadow() > pBar.GetHighShadow() - // - ; - - // - has = isBullishRejected || - isBearishhRejected; - if (has) - { - // - idx = i; - signalBox = iBox; - hasSignalBox = has; - signalBox.to = cTime; - signalBoxDir = iBox.dir; - isSignalBoxReversal = false; - provider = X121SMC_XWZ_PROVIDER_ACTIVATED_ZONE; - } - - // - iBox.Clean(); - } - - // - // Remove Signal Box from Waiting Boxes of - // Working Zone ... - if (hasSignalBox) - { - // - if (IsValidIndex(idx)) - { - // - ArrayRemove( - workingZone.waitingBoxes, - idx, - 1 // - ); - } - } - - // - // Ignore Zone's Signals ... - hasSignalBox = false; - - // - // Cleanup Resources ... - - // - zBar.Clean(); - cBar.Clean(); - pBar.Clean(); - } - - // - // Check Conditions if Has Inside Boxes ... - bool hasInsideBoxes = hasWorkingZone && - workingZone.HasInsideBoxes(); - if (hasInsideBoxes) - { - } - - // - // Check Conditions if has Breaked Boxes ... - bool hasBreakedBoxes = hasWorkingZone && - workingZone.HasBreakedBoxes(); - if (hasBreakedBoxes) - { - } - - // - // Checking Other Conditions ... - if (!hasSignalBox) - { - // - // Senari A ... - // hasSignalBox = hasWorkingZone && - // workingZone.DetectSenarioASignalBox( - // signalBox, - // signalBoxDir, - // decisionXConditions, - // analyseXConditions, - // decisionCycleHelper, - // drawer, - // zIndex // - // ); - // if (hasSignalBox) - // { - // // - // signalBox.to = cTime; - // isSignalBoxReversal = false; - // provider = X121SMC_XWZ_PROVIDER_PV_ZONE; - // } - - // // - // // Validating Signal Box if Exists ... - // if (hasSignalBox) - // { - // // - // // Validate Signal Boxes using Inside Box ... - // if (hasInsideBoxes) - // { - // // - // int idx = -1; - // bool has = false; - - // // - // idx = - // IsBullish(signalBoxDir) - // ? GetLowest(workingZone.insideBoxes) - // : GetHighest(workingZone.insideBoxes); - // has = IsValidIndex(idx); - // if (has) - // { - // // - // hasSignalBox = - // signalBoxDir == workingZone.insideBoxes[idx].dir; - // } - // } - - // // - // // Validate Signal Box Using Overal Trend ... - // if (hasWorkingZoneOveralDirection) - // { - // // - // hasSignalBox = - // signalBoxDir == wzOveralDir; - // } - // } - } - - // - // - // - - // - // Cleanup Signal if UnApproved ... - if (!hasSignalBox) - { - // - signalBox.Clean(); - signalBoxDir = X_DIRECTION_NONE; - } - - // - // - // - - // - // Check Priority Exists ... - hasPriority = workingZone - .DetectPriority( - priority, - signalBoxDir, - zIndex, - period // - ); - - // - // Check Price Reward and Amount Exists ... - hasRewardAmount = CalculateRiskReward( - priority, - reward, - amountPercent // - ); - - // - // Check Signal Conditions ... - if (hasSignalBox) - { - // - int idx = -1; - bool has = false; - - // - XCBoxObject *iObj; - has = drawer.DrawBox( - signalBox, - iObj // - ); - if (has) - { - // - iObj.BoxWidth(1); - iObj.BoxColor(clrYellow); - iObj.BoxStyle(STYLE_SOLID); - } - - // - isBullish = IsBullish(signalBoxDir); - isBearish = IsBearish(signalBoxDir); - - // - pivot = isBullish - ? signalBox.lower - : signalBox.upper; - - // - point = isBullish - ? signalBox.upper - : signalBox.lower; - - // - double iSL = 0; - double signalBoxRange = (signalBox.upper - signalBox.lower); - if (signalBoxRange < points * 100) - { - iSL = pivot; - } - else - { - iSL = signalBox.lower + (signalBox.upper - signalBox.lower) / 2; - } - - // - if (provider == X121SMC_XWZ_PROVIDER_PV_ZONE) - { - } - - // - Add( - iSL, - sls // - ); - - // - // Select Condition SL ... - - // - double entry = GetEntry( - signalBox.symbol, - signalBoxDir // - ); - - // - double slsMin = GetMin(sls); - double slsMax = GetMax(sls); - - // - double longSL = slsMin; - double shortSL = slsMax; - - // - sl = isBullish - ? longSL - : shortSL; - - // - // Targets ... - - // - // Force Add TP 2 as Target ... - double risk = MathAbs(entry - sl); - double reward2 = 2 * risk; - // double iTP2 = isBullish - // ? entry + reward2 - // : entry - reward2; - // Add( - // iTP2, - // targets // - // ); - - // - // Based On Priority ... - has = priority != X121SMC_XWZ_PRIORITY_NONE; - if (has) - { - // - switch (priority) - { - // - case X121SMC_XWZ_PRIORITY_WEAK: - // - if (isBullish) - { - // - // Weak ... - Add( - workingZone.supplyZone.Lower(), - targets // - ); - } - else - { - // - // Weak ... - Add( - workingZone.demandZone.Upper(), - targets // - ); - } - break; - - // - case X121SMC_XWZ_PRIORITY_LOW: - // - if (isBullish) - { - // - // Weak ... - Add( - workingZone.supplyZone.Lower(), - targets // - ); - - // - // Low ... - Add( - workingZone.quarter1, - targets // - ); - } - else - { - // - // Weak ... - Add( - workingZone.demandZone.Upper(), - targets // - ); - - // - // Low ... - Add( - workingZone.quarter3, - targets // - ); - } - break; - - // - case X121SMC_XWZ_PRIORITY_REGULAR: - // - if (isBullish) - { - // - // Weak ... - Add( - workingZone.supplyZone.Lower(), - targets // - ); - - // - // Low ... - Add( - workingZone.quarter1, - targets // - ); - - // - // Regular ... - Add( - workingZone.quarter2, - targets // - ); - } - else - { - // - // Weak ... - Add( - workingZone.demandZone.Upper(), - targets // - ); - - // - // Low ... - Add( - workingZone.quarter3, - targets // - ); - - // - // Regular ... - Add( - workingZone.quarter2, - targets // - ); - } - break; - - // - case X121SMC_XWZ_PRIORITY_HIGH: - // - if (isBullish) - { - // - // Weak ... - Add( - workingZone.supplyZone.Lower(), - targets // - ); - - // - // Low ... - Add( - workingZone.quarter1, - targets // - ); - - // - // Regular ... - Add( - workingZone.quarter2, - targets // - ); - - // - // High ... - Add( - workingZone.quarter3, - targets // - ); - } - else - { - // - // Weak ... - Add( - workingZone.demandZone.Upper(), - targets // - ); - - // - // Low ... - Add( - workingZone.quarter3, - targets // - ); - - // - // Regular ... - Add( - workingZone.quarter2, - targets // - ); - - // - // High ... - Add( - workingZone.quarter1, - targets // - ); - } - break; - - // - case X121SMC_XWZ_PRIORITY_STRONG_HIGH: - // - if (isBullish) - { - // - // Weak ... - Add( - workingZone.supplyZone.Lower(), - targets // - ); - - // - // Low ... - Add( - workingZone.quarter1, - targets // - ); - - // - // Regular ... - Add( - workingZone.quarter2, - targets // - ); - - // - // High ... - Add( - workingZone.quarter3, - targets // - ); - - // - // Strong High ... - Add( - workingZone.demandZone.Upper(), - targets // - ); - } - else - { - // - // Weak ... - Add( - workingZone.demandZone.Upper(), - targets // - ); - - // - // Low ... - Add( - workingZone.quarter3, - targets // - ); - - // - // Regular ... - Add( - workingZone.quarter2, - targets // - ); - - // - // High ... - Add( - workingZone.quarter1, - targets // - ); - - // - // Strong High ... - Add( - workingZone.supplyZone.Lower(), - targets // - ); - } - break; - } - } - - // - XBoxZone waitingBoxes[]; - has = workingZone.HasWaitingBoxes(); - if (has) - { - // - Copy( - workingZone.waitingBoxes, - waitingBoxes // - ); - - // - while (HasChild(waitingBoxes)) - { - // - XBoxZone iBox; - idx = GetYoungest(waitingBoxes); - has = IsValidIndex(idx); - if (!has) - { - // - iBox.Clean(); - continue; - } - - // - iBox = waitingBoxes[idx]; - ArrayRemove( - waitingBoxes, - idx, - 1 // - ); - - // - bool hasInside = workingZone.HasInsideBox(iBox); - if (!hasInside) - { - continue; - } - - // - double iTarget = - IsBullish(signalBoxDir) - ? iBox.lower - : iBox.upper; - - // - Add( - iTarget, - targets // - ); - - // - iBox.Clean(); - } - } - } - - // - // Summarize Results ... - result = hasPriority && - hasSignalBox && - hasRewardAmount; - - // - if (result) - { - // - Copy( - sls, - mConditions.sls // - ); - Copy( - targets, - mConditions.targets // - ); - - // - mConditions.sl = sl; - mConditions.pivot = pivot; - mConditions.point = point; - mConditions.reward = reward; - mConditions.setupTime = cTime; - mConditions.dir = signalBoxDir; - mConditions.priority = priority; - mConditions.provider = provider; - mConditions.signalBox = signalBox; - mConditions.amountPercent = amountPercent; - } - - // - UpdateTo(cTime); - - // - // Draw Working Zone ... - if (hasWorkingZone) - { - // - workingZone.Draw( - drawer, - // - true, // Draw Waiting Boxes ... - true, // Draw Inside Boxes ... - true, // Draw Breaked Boxes ... - true, // Draw Breaked Inside Boxes ... - // - true, // Draw Supply Zone ... - true, // Draw Demand Zone ... - true, // Draw Supply Zones ... - true, // Draw Demand Zones ... - true, // Draw Support Zones ... - true // Draw Resistance Zones ... - ); - } - - // - // - // - - // - // Cleanup Resources ... - - // - Clean(visionPoiEvents); - Clean(analysePoiEvents); - Clean(decisionPoiEvents); - Clean(consolidationPoiEvents); - - // - Clean(visionCycleEvents); - Clean(analyseCycleEvents); - Clean(decisionCycleEvents); - Clean(consolidationCycleEvents); - - // - visionState.Clean(); - analyseState.Clean(); - decisionState.Clean(); - consolidationState.Clean(); - - // - visionConditions.Clean(); - analyseConditions.Clean(); - decisionConditions.Clean(); - consolidationConditions.Clean(); - - // - visionXConditions.Clean(); - analyseXConditions.Clean(); - decisionXConditions.Clean(); - consolidationXConditions.Clean(); - - // - consolidationZBar.Clean(); - - // - return result; - } - - // - // Detect Trigger Conditions ... - bool DetectSignalTrigger( - // - X121SMCStrategyXWZSignalConditions &conditions, - // - XC121SMCCycleHelper *decisionCycleHelper, - XC121SMCCycleHelper *analyseCycleHelper, - XC121SMCCycleHelper *consolidationCycleHelper, - XC121SMCCycleHelper *visionCycleHelper, - // - int maxAllowedSetupAge = 60 - // - ) - { - // - bool result = false; - - // - result = - // - visionCycleHelper != NULL && - analyseCycleHelper != NULL && - decisionCycleHelper != NULL && - consolidationCycleHelper != NULL - // - ; - if (!result) - { - return result; - } - - // - result = conditions.IsSetuped(); - if (!result) - { - return result; - } - - // - datetime setupTime = conditions.setupTime; - ENUM_X_DIRECTION setupDir = conditions.dir; - - // - bool isBullish = IsBullish(setupDir); - bool isBearish = IsBearish(setupDir); - - // - int zIndex = 0; - int cIndex = zIndex + 1; - int pIndex = cIndex + 1; - int ppIndex = pIndex + 1; - - // - int loopback = 10; - - // - double ask = GetAsk(symbol); - double bid = GetBid(symbol); - datetime cTime = TimeCurrent(); - double points = GetPoints(symbol); - - // - // Cycles Conditions ... - - // - // Decision ... - ENUM_XPOI_EVENTS decisionPoiEvents[]; - ENUM_X_CYCLE_EVENTS decisionCycleEvents[]; - X121SMCCycleConditions decisionConditions; - result = decisionCycleHelper.GetConditions( - decisionCycleEvents, - decisionPoiEvents, - decisionConditions, - zIndex, - loopback // - ); - if (!result) - { - // - // Cleanup ... - - // - Clean(decisionPoiEvents); - Clean(decisionCycleEvents); - - // - decisionConditions.Clean(); - - // - return result; - } - - // - // Analyse ... - ENUM_XPOI_EVENTS analysePoiEvents[]; - ENUM_X_CYCLE_EVENTS analyseCycleEvents[]; - X121SMCCycleConditions analyseConditions; - result = analyseCycleHelper.GetConditions( - analyseCycleEvents, - analysePoiEvents, - analyseConditions, - zIndex, - loopback // - ); - if (!result) - { - // - Clean(analysePoiEvents); - Clean(decisionPoiEvents); - - // - Clean(analyseCycleEvents); - Clean(decisionCycleEvents); - - // - analyseConditions.Clean(); - decisionConditions.Clean(); - - // - return result; - } - - // - // Cycles POI States ... - XPOIState decisionState = decisionConditions.state; - XPOIState analyseState = analyseConditions.state; - - // - // Cycle X121Conditions ... - X121Conditions decisionXConditions = decisionConditions.x121Conditions; - X121Conditions analyseXConditions = analyseConditions.x121Conditions; - - // - double iAtr = decisionXConditions.atrBuffer[1]; - iAtr *= 1.5; - - // - // Check Signal Validation ... - // IMPORTANT: since all Validations done in SetUp Process ... - // here we only Execute Signal ... - - // - result = isBullish || - isBearish; - - // - if (result) - { - // - conditions.triggerTime = cTime; - conditions.type = isBullish - ? X_POSITION_TYPE_LONG - : X_POSITION_TYPE_SHORT; - - // - } - - // - // Cleanup ... - - // - Clean(decisionPoiEvents); - Clean(decisionCycleEvents); - - // - decisionState.Clean(); - decisionConditions.Clean(); - decisionXConditions.Clean(); - - // - Clean(analysePoiEvents); - Clean(analyseCycleEvents); - - // - analyseState.Clean(); - analyseConditions.Clean(); - analyseXConditions.Clean(); - - // - return result; - } - - // - // Detect Guards ... - bool DetectGuards( - // - X121SMCGuard &guards[], - const XPosition &positions[], - // - XC121SMCCycleHelper *decisionCycleHelper, - XC121SMCCycleHelper *analyseCycleHelper, - XC121SMCCycleHelper *consolidationCycleHelper, - XC121SMCCycleHelper *visionCycleHelper - // - ) - { - // - bool result = false; - return false; - - // - Clean(guards); - - // - bool isCycleHelpersValid = - // - visionCycleHelper != NULL && - analyseCycleHelper != NULL && - decisionCycleHelper != NULL && - consolidationCycleHelper != NULL - // - ; - - // - // Set Provider for Common Guards ... - string provider = ToString(X_121_SMC_PROVIDER_XWZ); - - // - // Check Cycle Helpers Validation ... - result = isCycleHelpersValid; - if (!result) - { - return result; - } - - // - // Select Own Positions ... - int count = ArraySize(positions); - result = IsValidSize(count); - if (!result) - { - return result; - } - - // - XPosition ownPositions[]; - XPosition ownLongPositions[]; - XPosition ownShortPositions[]; - for (int i = 0; i < count; i++) - { - // - XPosition iPosition = positions[i]; - bool isOwn = iPosition - .IsFiltersPassed( - symbol, - provider, - NULL, - X_POSITION_TYPE_ALL, - iPosition.magic // - ); - if (isOwn) - { - // - AddRef( - iPosition, - ownPositions // - ); - - // - bool isLong = IsLong(positions[i].type); - if (isLong) - { - // - AddRef( - iPosition, - ownLongPositions // - ); - } - else - { - // - AddRef( - iPosition, - ownShortPositions // - ); - } - } - } - - // - // Check Extracted Positions ... - - // - count = ArraySize(ownPositions); - - // - int longsCount = ArraySize(ownLongPositions); - bool hasLongs = IsValidSize(longsCount); - - // - int shortsCount = ArraySize(ownShortPositions); - bool hasShorts = IsValidSize(shortsCount); - - // - // Validate Own Positions ... - result = IsValidSize(count); - if (!result) - { - // - Clean(ownPositions); - Clean(ownLongPositions); - Clean(ownShortPositions); - - // - return result; - } - - // - // - // - - // - // Get Global and Common Guards ... - - // - ENUM_X_121_SMC_GUARD_ACTIONS ignoreGuards[1] = { - X_121_SMC_GUARD_ACTION_TRAIL_STOP // - }; - result = DetectX121SMCGuards( - provider, - guards, - positions, - decisionCycleHelper, - analyseCycleHelper, - consolidationCycleHelper, - visionCycleHelper, - // - ignoreGuards - // - ); - - // - // - // - - // - // Implement Custom Implemented Guards ... - - // - // Here we Are Sure there is Positions to Guard ... - // based on Current Provider ... - - // - // Detect Required Data for Analyse Market to Guard Positions ... - - // - int zIndex = 0; - int cIndex = zIndex + 1; - int pIndex = cIndex + 1; - int ppIndex = pIndex + 1; - - // - int loopback = 10; - - // - double ask = GetAsk(symbol); - double bid = GetBid(symbol); - datetime cTime = TimeCurrent(); - double points = GetPoints(symbol); - - // - // Cycles Conditions ... - - // - // Decision ... - ENUM_XPOI_EVENTS decisionPoiEvents[]; - ENUM_X_CYCLE_EVENTS decisionCycleEvents[]; - X121SMCCycleConditions decisionConditions; - result = decisionCycleHelper.GetConditions( - decisionCycleEvents, - decisionPoiEvents, - decisionConditions, - zIndex, - loopback // - ); - if (!result) - { - // - Clean(decisionPoiEvents); - Clean(decisionCycleEvents); - - // - decisionConditions.Clean(); - - // - result = HasChild(guards); - return result; - } - - // - // Analyse ... - ENUM_XPOI_EVENTS analysePoiEvents[]; - ENUM_X_CYCLE_EVENTS analyseCycleEvents[]; - X121SMCCycleConditions analyseConditions; - result = analyseCycleHelper.GetConditions( - analyseCycleEvents, - analysePoiEvents, - analyseConditions, - zIndex, - loopback // - ); - if (!result) - { - // - Clean(decisionPoiEvents); - Clean(decisionCycleEvents); - - // - decisionConditions.Clean(); - - // - Clean(analysePoiEvents); - Clean(analyseCycleEvents); - - // - analyseConditions.Clean(); - - // - result = HasChild(guards); - return result; - } - - // - // Consolidation ... - ENUM_XPOI_EVENTS consolidationPoiEvents[]; - ENUM_X_CYCLE_EVENTS consolidationCycleEvents[]; - X121SMCCycleConditions consolidationConditions; - result = consolidationCycleHelper.GetConditions( - consolidationCycleEvents, - consolidationPoiEvents, - consolidationConditions, - zIndex, - loopback // - ); - if (!result) - { - // - Clean(decisionPoiEvents); - Clean(decisionCycleEvents); - - // - decisionConditions.Clean(); - - // - Clean(analysePoiEvents); - Clean(analyseCycleEvents); - - // - analyseConditions.Clean(); - - // - Clean(consolidationPoiEvents); - Clean(consolidationCycleEvents); - - // - consolidationConditions.Clean(); - - // - result = HasChild(guards); - return result; - } - - // - // Vision ... - ENUM_XPOI_EVENTS visionPoiEvents[]; - ENUM_X_CYCLE_EVENTS visionCycleEvents[]; - X121SMCCycleConditions visionConditions; - result = visionCycleHelper.GetConditions( - visionCycleEvents, - visionPoiEvents, - visionConditions, - zIndex, - loopback // - ); - if (!result) - { - // - Clean(decisionPoiEvents); - Clean(decisionCycleEvents); - - // - decisionConditions.Clean(); - - // - Clean(analysePoiEvents); - Clean(analyseCycleEvents); - - // - analyseConditions.Clean(); - - // - Clean(consolidationPoiEvents); - Clean(consolidationCycleEvents); - - // - consolidationConditions.Clean(); - - // - Clean(visionPoiEvents); - Clean(visionCycleEvents); - - // - visionConditions.Clean(); - - // - result = HasChild(guards); - return result; - } - - // - // Cycles POI States ... - XPOIState visionState = visionConditions.state; - XPOIState analyseState = analyseConditions.state; - XPOIState decisionState = decisionConditions.state; - XPOIState consolidationState = consolidationConditions.state; - - // - // Cycle X121Conditions ... - X121Conditions visionXConditions = visionConditions.x121Conditions; - X121Conditions analyseXConditions = analyseConditions.x121Conditions; - X121Conditions decisionXConditions = decisionConditions.x121Conditions; - X121Conditions consolidationXConditions = consolidationConditions.x121Conditions; - - // - // - // - - // - // Selected Consolidation Zones ... - - // - int idx = -1; - bool has = false; - - // - bool hasBullishConsolidationZone = false; - XConsolidationZone bullishConsolidationZone; - has = decisionState.HasBullishConsolidationZones(); - if (has) - { - // - idx = GetYoungest(decisionState.bullishConsolidationZones); - hasBullishConsolidationZone = IsValidIndex(idx); - if (hasBullishConsolidationZone) - { - bullishConsolidationZone = decisionState.bullishConsolidationZones[idx]; - } - } - - // - bool hasBearishConsolidationZone = false; - XConsolidationZone bearishConsolidationZone; - has = decisionState.HasBearishConsolidationZones(); - if (has) - { - // - idx = GetYoungest(decisionState.bearishConsolidationZones); - hasBearishConsolidationZone = IsValidIndex(idx); - if (hasBearishConsolidationZone) - { - bearishConsolidationZone = decisionState.bearishConsolidationZones[idx]; - } - } - - // - // Here We Have all Requirements for Guarding Positions ... - - // - // Available Guards: - // X_121_SMC_GUARD_ACTION_NONE - // X_121_SMC_GUARD_ACTION_CLOSE - // X_121_SMC_GUARD_ACTION_CLOSE_ALL - // X_121_SMC_GUARD_ACTION_CLOSE_LONGS - // X_121_SMC_GUARD_ACTION_CLOSE_SHORTS - // X_121_SMC_GUARD_ACTION_PARTIAL_CLOSE - // X_121_SMC_GUARD_ACTION_TRAIL_STOP - // X_121_SMC_GUARD_ACTION_TRAIL_TARGET - // X_121_SMC_GUARD_ACTION_HEDGE - - // - // X_121_SMC_GUARD_ACTION_CLOSE: - // Close Specified Position on Specified Conditions ... - - // - // X_121_SMC_GUARD_ACTION_CLOSE_ALL: - // Close All Positions on Specified Conditions ... - - // - // X_121_SMC_GUARD_ACTION_CLOSE_LONGS: - // Close All Long Positions on Specified Conditions ... - - // - // X_121_SMC_GUARD_ACTION_CLOSE_SHORTS: - // Close All Short Positions on Specified Conditions ... - - // - // X_121_SMC_GUARD_ACTION_PARTIAL_CLOSE: - // Partial Close Specified Position on Specified Conditions ... - - // - // X_121_SMC_GUARD_ACTION_TRAIL_STOP: - // Trail Stop Specified Position on Specified Conditions ... - bool handleStoptrailingBasedOnConsolidationZones = true; - for (int i = 0; i < count; i++) - { - // - XPosition iPosition = ownPositions[i]; - - // - bool isLong = IsLong(iPosition.type); - bool isInProfit = iPosition.profit > 0; - - // - double sl = iPosition.sl; - double tp = iPosition.tp; - - // - // Trail Stops Using Consolidation Zones ... - - // - bool canTraiLonglUsingCZone = - // - handleStoptrailingBasedOnConsolidationZones && - // - (isLong && - isInProfit && - hasBullishConsolidationZone && - bullishConsolidationZone.lower > iPosition.sl && - bullishConsolidationZone.lower > iPosition.entry) - // - ; - if (canTraiLonglUsingCZone) - { - sl = bullishConsolidationZone.lower; - } - - // - bool canTraiShortlUsingCZone = - // - handleStoptrailingBasedOnConsolidationZones && - // - (!isLong && - isInProfit && - hasBearishConsolidationZone && - bearishConsolidationZone.upper < iPosition.sl && - bearishConsolidationZone.upper < iPosition.entry) - // - ; - if (canTraiShortlUsingCZone) - { - sl = bearishConsolidationZone.upper; - } - - // - bool canTrailUsingCZone = - canTraiLonglUsingCZone || - canTraiShortlUsingCZone; - - // - bool isSLPassed = - sl > 0 && - (isLong - ? iPosition.price - sl >= points * 15 - : sl - iPosition.price >= points * 15); - - // - bool canTrail = - isSLPassed && - canTrailUsingCZone; - if (canTrail) - { - // - X121SMCGuard iGuard; - - // - iGuard.time = cTime; - iGuard.symbol = symbol; - iGuard.provider = provider; - iGuard.action = X_121_SMC_GUARD_ACTION_TRAIL_STOP; - - // - iGuard.ticket = iPosition.ticket; - - // - iGuard.sl = sl; - - // - AddGuard( - iGuard, - guards // - ); - } - } - - // - // X_121_SMC_GUARD_ACTION_TRAIL_TARGET: - // Trail Target Specified Position on Specified Conditions ... - - // - // X_121_SMC_GUARD_ACTION_HEDGE: - // Hedge all Positions on Specified Conditions ... - - // - // Cleanup Collections ... - - // - Clean(ownPositions); - Clean(ownLongPositions); - Clean(ownShortPositions); - - // - visionState.Clean(); - analyseState.Clean(); - decisionState.Clean(); - consolidationState.Clean(); - - // - visionConditions.Clean(); - analyseConditions.Clean(); - decisionConditions.Clean(); - consolidationConditions.Clean(); - - // - visionXConditions.Clean(); - analyseXConditions.Clean(); - decisionXConditions.Clean(); - consolidationXConditions.Clean(); - - // - Clean(visionPoiEvents); - Clean(analysePoiEvents); - Clean(decisionPoiEvents); - Clean(consolidationPoiEvents); - - // - Clean(visionCycleEvents); - Clean(analyseCycleEvents); - Clean(decisionCycleEvents); - Clean(consolidationCycleEvents); - - // - count = ArraySize(guards); - result = IsValidSize(count); - - // - return result; - } - - // - // Add Conditions to Conditions Collection ... - int AddConditionsIfNotExists( - int maxAllowed = 10 // - ) - { - // - int result = 0; - - // - bool isSetuped = IsValid(mConditions.setupTime) && - HasDirection(mConditions.dir); - if (!isSetuped) - { - return result; - } - - // - int count = ArraySize(mConditionsCollection); - if (IsValidSize(count)) - { - // - // Copy Original Items ... - X121SMCStrategyXWZSignalConditions tmpItems[]; - Copy( - mConditionsCollection, - tmpItems // - ); - - // - // Prese Item Data ... - bool isBullish = IsBullish(mConditions.dir); - - // - for (int i = 0; i < count; i++) - { - // - X121SMCStrategyXWZSignalConditions iItem = tmpItems[i]; - - // - bool canRemove = mConditions.dir == iItem.dir && - mConditions.pivot == iItem.pivot; - if (canRemove) - { - // - ArrayRemove( - mConditionsCollection, - i, - 1 // - ); - } - } - - // - Clean(tmpItems); - } - - // - AddRef( - mConditions, - mConditionsCollection // - ); - - // - // Remove Olds ... - CleanupArray( - mConditionsCollection, - maxAllowed // - ); - - // - result = ArraySize(mConditionsCollection); - - // - return result; - } - - // - // Draw Functions ... - // - - // - void DrawBar( - XOHCL &bar, - XCPOIDrawer *drawer, - bool forceClean = true // - ) - { - // - if (forceClean) - { - mBarObjects.Clear(); - } - - // - if (drawer == NULL || - !bar.IsValid()) - { - return; - } - - // - bool isBullish = bar.IsBullish(); - - // - int widthBar = 2; - bool fillShadowsBar = true; - ENUM_LINE_STYLE styleBar = STYLE_SOLID; - color clrBar = - isBullish - ? clrAqua - : clrMagenta; - - // - datetime to = bar.NextAt(); - - // - XCOHCLObject *iObj; - bool isCreated = drawer - .CreateBar( - bar, - iObj, - to // - ); - if (isCreated) - { - // - iObj.BarSpes( - widthBar, - clrBar, - styleBar // - ); - - // - iObj.LowShadowFill(fillShadowsBar); - iObj.HighShadowFill(fillShadowsBar); - - // - mBarObjects.Add(iObj); - } - } - - // - protected: - // - - // - private: - // - // Props ... - string symbol; - ENUM_TIMEFRAMES period; - CArrayObj mObjects; - CArrayObj mBarObjects; - CArrayObj mWorkingZoneObjects; - - /** - * Initialize ... - */ - void Init() - { - } - - /** - * DeInitialize ... - */ - void DeInit() - { - // - mConditions.Clean(); - workingZone.Clean(); - Clean(mConditionsCollection); - - // - mBarObjects.Clear(); - } - - /** - * Update To Time of Exists Components ... - * - * @param value: updated time ... - */ - void UpdateTo( - datetime value = NULL // - ) - { - // - value = NormalizeTime(value); - - // - workingZone.UpdateTo(value); - } - - // - // Helpers ... - - // - bool CalculateRiskReward( - ENUM_X121SMC_XWZ_PRIORITY priority, - double &reward, - double &amountPercent // - ) - { - // - bool result = false; - - // - reward = 0; - amountPercent = 0; - - // - result = priority != X121SMC_XWZ_PRIORITY_NONE; - if (!result) - { - return result; - } - - // - switch (priority) - { - // - case X121SMC_XWZ_PRIORITY_STRONG_HIGH: - // - reward = 6; - amountPercent = 2; - break; - - // - case X121SMC_XWZ_PRIORITY_HIGH: - // - reward = 4; - amountPercent = 2; - break; - - // - case X121SMC_XWZ_PRIORITY_REGULAR: - // - reward = 3; - amountPercent = 1.5; - break; - - // - case X121SMC_XWZ_PRIORITY_LOW: - // - reward = 2; - amountPercent = 1; - break; - - // - case X121SMC_XWZ_PRIORITY_WEAK: - // - reward = 1; - amountPercent = 0.5; - break; - } - - // - result = - // - reward > 0 && - amountPercent > 0 - // - ; - - // - return result; - } - - // -}; - -// \ No newline at end of file diff --git a/Documents/BKP/x-121.smc.xwz.signal.class copy.mq5 b/Documents/BKP/x-121.smc.xwz.signal.class copy.mq5 deleted file mode 100644 index c1e8cc27..00000000 --- a/Documents/BKP/x-121.smc.xwz.signal.class copy.mq5 +++ /dev/null @@ -1,2124 +0,0 @@ -/////////////////////////////////////////////////////// -// -// SaherElm IT Center MQL5 X121 SMC Signal Class -// ------------------------------------------------- -// Name: XWZ -// Description: provide all Signalling functions ... -// -// -// Maintainer: -// ------------ -// Hadi Khazaee Asl (hadi_khazaee_asl@yahoo.com) -// -////////////////////////////////////////////////////// -// -// Global Properties ... -#property library -#property copyright "Copyright 2023, SaherElm IT Center" -#property link "https://www.saherelm.ir" -#property version "1.00" -#property strict - -// -// Imports ... -#include "../Classes/x-121.smc.market.cycle.helper.class.mq5" -#include "../Libraries/x-121.smc.guard.lib.mq5" -#include "../Libraries/x-121.smc.lib.mq5" -#include "./x-121.smc.xwz.signal.lib.mq5" - -// -// Definition ... -class XCX121SMCXWZSignalDetector : public XCBase -{ - // - public: - // - // Props ... - X121SMCStrategyXWZWorkingZone workingZone; - X121SMCStrategyXWZSignalConditions mConditions; - X121SMCStrategyXWZSignalConditions mConditionsCollection[]; - - // - // Constructor(s) ... - XCX121SMCXWZSignalDetector( - string _symbol, - ENUM_TIMEFRAMES _period // - ) - { - // - symbol = _symbol; - period = _period; - Init(); - } - - // - // Deconstructor ... - ~XCX121SMCXWZSignalDetector() - { - DeInit(); - } - - // - // - // - - // - // Detect Setup Conditions ... - bool DetectSignalSetup( - // - XC121SMCCycleHelper *decisionCycleHelper, - XC121SMCCycleHelper *analyseCycleHelper, - XC121SMCCycleHelper *consolidationCycleHelper, - XC121SMCCycleHelper *visionCycleHelper, - // - double maxAllowedSLDistanceInPoint = 300 - // - ) - { - // - bool result = false; - - // - // Validate Cycle Helpers ... - result = - // - visionCycleHelper != NULL && - analyseCycleHelper != NULL && - decisionCycleHelper != NULL && - consolidationCycleHelper != NULL - // - ; - if (!result) - { - // - mConditions.Clean(); - - // - return result; - } - - // - bool isBullish = false; - bool isBearish = false; - - // - int zIndex = 0; - int cIndex = zIndex + 1; - int pIndex = cIndex + 1; - int ppIndex = pIndex + 1; - - // - int loopback = 10; - - // - mConditions.symbol = symbol; - mConditions.period = period; - - // - double ask = GetAsk(symbol); - double bid = GetBid(symbol); - datetime cTime = TimeCurrent(); - double points = GetPoints(symbol); - - // - // Cycles Conditions ... - - // - XOHCL consolidationZBar; - result = consolidationCycleHelper.GetBar( - consolidationZBar, - zIndex // - ); - if (!result) - { - // - consolidationZBar.Clean(); - return result; - } - - // - bool drawBar = false; - if (drawBar) - { - // - DrawBar( - consolidationZBar, - decisionCycleHelper.mPOIDrawer // - ); - } - - // - // Decision ... - ENUM_XPOI_EVENTS decisionPoiEvents[]; - ENUM_X_CYCLE_EVENTS decisionCycleEvents[]; - X121SMCCycleConditions decisionConditions; - result = decisionCycleHelper.GetConditions( - decisionCycleEvents, - decisionPoiEvents, - decisionConditions, - zIndex, - loopback // - ); - if (!result) - { - // - Clean(decisionPoiEvents); - Clean(decisionCycleEvents); - - // - decisionConditions.Clean(); - - // - mConditions.Clean(); - consolidationZBar.Clean(); - - // - return result; - } - - // - // Analyse ... - ENUM_XPOI_EVENTS analysePoiEvents[]; - ENUM_X_CYCLE_EVENTS analyseCycleEvents[]; - X121SMCCycleConditions analyseConditions; - result = analyseCycleHelper.GetConditions( - analyseCycleEvents, - analysePoiEvents, - analyseConditions, - zIndex, - loopback // - ); - if (!result) - { - // - Clean(analysePoiEvents); - Clean(decisionPoiEvents); - - // - Clean(analyseCycleEvents); - Clean(decisionCycleEvents); - - // - analyseConditions.Clean(); - decisionConditions.Clean(); - - // - mConditions.Clean(); - consolidationZBar.Clean(); - - // - return result; - } - - // - // Consolidation ... - ENUM_XPOI_EVENTS consolidationPoiEvents[]; - ENUM_X_CYCLE_EVENTS consolidationCycleEvents[]; - X121SMCCycleConditions consolidationConditions; - result = consolidationCycleHelper.GetConditions( - consolidationCycleEvents, - consolidationPoiEvents, - consolidationConditions, - zIndex, - loopback // - ); - if (!result) - { - // - Clean(analysePoiEvents); - Clean(decisionPoiEvents); - Clean(consolidationPoiEvents); - - // - Clean(analyseCycleEvents); - Clean(decisionCycleEvents); - Clean(consolidationCycleEvents); - - // - analyseConditions.Clean(); - decisionConditions.Clean(); - consolidationConditions.Clean(); - - // - mConditions.Clean(); - consolidationZBar.Clean(); - - // - return result; - } - - // - // Vision ... - ENUM_XPOI_EVENTS visionPoiEvents[]; - ENUM_X_CYCLE_EVENTS visionCycleEvents[]; - X121SMCCycleConditions visionConditions; - result = visionCycleHelper.GetConditions( - visionCycleEvents, - visionPoiEvents, - visionConditions, - zIndex, - loopback // - ); - if (!result) - { - // - Clean(visionPoiEvents); - Clean(analysePoiEvents); - Clean(decisionPoiEvents); - Clean(consolidationPoiEvents); - - // - Clean(visionCycleEvents); - Clean(analyseCycleEvents); - Clean(decisionCycleEvents); - Clean(consolidationCycleEvents); - - // - visionConditions.Clean(); - analyseConditions.Clean(); - decisionConditions.Clean(); - consolidationConditions.Clean(); - - // - mConditions.Clean(); - consolidationZBar.Clean(); - - // - return result; - } - - // - // Cycles POI States ... - XPOIState decisionState = decisionConditions.state; - XPOIState analyseState = analyseConditions.state; - XPOIState consolidationState = consolidationConditions.state; - XPOIState visionState = visionConditions.state; - - // - // Cycle X121Conditions ... - X121Conditions decisionXConditions = decisionConditions.x121Conditions; - X121Conditions analyseXConditions = analyseConditions.x121Conditions; - X121Conditions consolidationXConditions = consolidationConditions.x121Conditions; - X121Conditions visionXConditions = visionConditions.x121Conditions; - - // - // Select Drawer Class ... - XCPOIDrawer *drawer = visionCycleHelper.mPOIDrawer; - - // - // Setup Conditions ... - double sls[]; - double pivot = 0; - double point = 0; - double targets[]; - double reward = 0; - XBoxZone signalBox; - XOBFVG selectedZone; - double amountPercent = 0; - bool hasPriority = false; - bool hasSignalBox = false; - bool hasRewardAmount = false; - bool hasSelectedZone = false; - bool isSignalBoxReversal = false; - bool isSelectedZoneReversal = false; - bool hasSelectedConsolidationZone = false; - XConsolidationZone selectedConsolidationZone; - ENUM_X_DIRECTION selectedZoneDir = X_DIRECTION_NONE; - ENUM_X121SMC_XWZ_PRIORITY priority = X121SMC_XWZ_PRIORITY_NONE; - ENUM_X121SMC_XWZ_PROVIDERS provider = X121SMC_XWZ_PROVIDER_NONE; - - // - // First We Have to Has Working Zone ... - bool hasWorkingZone = workingZone.IsValid(); - if (!hasWorkingZone) - { - // - hasWorkingZone = workingZone.Init( - symbol, - period, - zIndex, - visionState, - consolidationState, - analyseState, - decisionState // - ); - } - - // - if (hasWorkingZone) - { - // - visionCycleHelper.mPOIDetector.MaxRequiredPOIs(50); - analyseCycleHelper.mPOIDetector.MaxRequiredPOIs(50); - decisionCycleHelper.mPOIDetector.MaxRequiredPOIs(50); - consolidationCycleHelper.mPOIDetector.MaxRequiredPOIs(50); - - // - visionCycleHelper.mPOIDetector.MaxAllowedLoopbackForInit(578); - analyseCycleHelper.mPOIDetector.MaxAllowedLoopbackForInit(578); - decisionCycleHelper.mPOIDetector.MaxAllowedLoopbackForInit(578); - consolidationCycleHelper.mPOIDetector.MaxAllowedLoopbackForInit(578); - - // - workingZone.Update( - zIndex, - visionState, - consolidationState, - analyseState, - decisionState // - ); - } - - // - bool hasWaitingZones = hasWorkingZone && - workingZone.HasWaitingZones(); - - // - // - // - - // - // Check Conditions if Has Inside Zones ... - bool hasInsideZones = hasWorkingZone && - workingZone.HasInsideZones(); - if (hasInsideZones) - { - // - int selectedIDX = -1; - int count = workingZone.CountInsideZones(); - for (int i = 0; i < count; i++) - { - // - bool has = DetectSelectedZoneConditions( - isSelectedZoneReversal, - workingZone.insideZones[i], - decisionState, - decisionXConditions // - ); - - // - if (has) - { - // - selectedIDX = i; - selectedZone = workingZone.insideZones[i]; - - // - break; - } - } - - // - if (IsValidIndex(selectedIDX)) - { - // - ArrayRemove( - workingZone.insideZones, - selectedIDX, - 1 // - ); - - // - hasSelectedZone = selectedZone.IsValid(); - provider = X121SMC_XWZ_PROVIDER_PRICE_INSIDE_ZONE; - } - } - - // - // Check Conditions if Has Breaked Zones ... - // bool hasBreakedZones = hasWorkingZone && - // workingZone.HasBreakedZones(); - // if (hasBreakedZones) - // { - // // - // if (!hasSelectedZone) - // { - // // - // int selectedIDX = -1; - // int count = workingZone.CountBreakedZones(); - // for (int i = 0; i < count; i++) - // { - // // - // bool has = DetectSelectedZoneConditions( - // isSelectedZoneReversal, - // workingZone.breakedZones[i], - // decisionState, - // decisionXConditions // - // ); - - // // - // if (has) - // { - // // - // selectedIDX = i; - // selectedZone = workingZone.breakedZones[i]; - - // // - // break; - // } - // } - - // // - // if (IsValidIndex(selectedIDX)) - // { - // // - // ArrayRemove( - // workingZone.breakedZones, - // selectedIDX, - // 1 // - // ); - - // // - // hasSelectedZone = selectedZone.IsValid(); - // provider = X121SMC_XWZ_PROVIDER_ACTIVATED_ZONE; - // } - // } - // } - - // - // - // - - // - bool hasInsideBoxes = hasWorkingZone && - workingZone.HasInsideBoxes(); - if (hasInsideBoxes) - { - // - XOHCL zBar; - XOHCL cBar; - int count = 0; - bool has = false; - XBoxZone tmpSelectedBox; - int tmpSelectedBoxIDX = -1; - - // - has = zBar.Init( - symbol, - period, - zIndex // - ); - has = has && - zBar.GetPreviousBar(cBar); - if (has) - { - // - count = workingZone.CountInsideBoxes(); - for (int i = 0; i < count; i++) - { - // - tmpSelectedBox = workingZone.insideBoxes[i]; - - // - bool isBullish = tmpSelectedBox.IsBullish(); - bool isBearish = tmpSelectedBox.IsBearish(); - - // - bool hasFiboPressure = - visionCycleHelper - .mBarAnalyser - .HasFiboPressure( - cBar, - tmpSelectedBox.dir, - X_FIBO_LEVEL_382 // - ); - - // - bool isBullishRejectedUpper = - cBar.low < tmpSelectedBox.upper && - cBar.GetDown() > tmpSelectedBox.upper; - - // - bool isBullishRejectedLower = - cBar.low < tmpSelectedBox.lower && - cBar.GetDown() > tmpSelectedBox.lower; - - // - bool isBearishRejectedUpper = - cBar.high > tmpSelectedBox.upper && - cBar.GetUp() < tmpSelectedBox.upper; - - // - bool isBearishRejectedLower = - cBar.high > tmpSelectedBox.lower && - cBar.GetUp() < tmpSelectedBox.lower; - - // - bool isBullishRejected = - // isBullishRejectedUpper || - isBullishRejectedLower; - - // - bool isBearishRejected = - isBearishRejectedUpper - // || isBearishRejectedLower - ; - - // - bool isMaWapBullish = - // - (decisionXConditions.isX3MaBullishState && - decisionXConditions.isX3MaBullishOrdered) - // - && - // - (decisionXConditions.isVWapBullishState && - decisionXConditions.isVWapBullishOrdered) - // - ; - - // - bool isMaWapBearish = - // - (decisionXConditions.isX3MaBearishState && - decisionXConditions.isX3MaBearishOrdered) - // - && - // - (decisionXConditions.isVWapBearishState && - decisionXConditions.isVWapBearishOrdered) - // - ; - - // - bool isX2MaWapInside = - // - (decisionXConditions.x3maFastBuffer[cIndex] < tmpSelectedBox.upper && - decisionXConditions.x3maMidBuffer[cIndex] < tmpSelectedBox.upper && - decisionXConditions.x3maFastBuffer[cIndex] > tmpSelectedBox.lower && - decisionXConditions.x3maMidBuffer[cIndex] > tmpSelectedBox.lower) - // - && - // - (decisionXConditions.vwapFastBuffer[cIndex] < tmpSelectedBox.upper && - decisionXConditions.vwapMidBuffer[cIndex] < tmpSelectedBox.upper && - decisionXConditions.vwapFastBuffer[cIndex] > tmpSelectedBox.lower && - decisionXConditions.vwapMidBuffer[cIndex] > tmpSelectedBox.lower) - // - ; - - // - bool isBullishConditions = - // - isBullish && - isMaWapBearish && - isX2MaWapInside && - hasFiboPressure && - isBullishRejected && - cBar.low < cBar.GetDown() - // - ; - - // - bool isBearishConditions = - // - isBearish && - isMaWapBullish && - isX2MaWapInside && - hasFiboPressure && - isBearishRejected && - cBar.high > cBar.GetUp() - // - ; - - // - has = isBullishConditions || - isBearishConditions; - if (!has) - { - // - tmpSelectedBox.Clean(); - continue; - } - - // - tmpSelectedBoxIDX = i; - signalBox = tmpSelectedBox; - - // - tmpSelectedBox.Clean(); - break; - } - } - - // - isSignalBoxReversal = false; - hasSignalBox = signalBox.IsValid(); - if (hasSignalBox) - { - // - ArrayRemove( - workingZone.insideBoxes, - tmpSelectedBoxIDX, - 1 // - ); - } - - // - zBar.Clean(); - cBar.Clean(); - tmpSelectedBox.Clean(); - } - - // - bool hasBreakedBoxes = hasWorkingZone && - workingZone.HasBreakedBoxes(); - if (hasBreakedBoxes) - { - } - - // - if (!hasSignalBox) - { - } - - // - // - // - - // - // Double Check and Prepare Signal Conditions ... - // including Targets and SLs ... - - // - if (hasSelectedZone) - { - // - int idx = -1; - bool has = false; - - // - // Check Consolidation Zones for SL Handling ... - selectedZoneDir = - !isSelectedZoneReversal - ? selectedZone.GetDirection() - : Opposit(selectedZone.GetDirection()); - bool isSelectedZonDirBullish = IsBullish(selectedZoneDir); - - // - if (isSelectedZoneReversal) - { - provider = X121SMC_XWZ_PROVIDER_ACTIVATED_CHOCH; - } - - // - // Calculate Priority ... - hasPriority = - hasWorkingZone && - workingZone - .DetectPriority( - priority, - selectedZoneDir, - zIndex, - period // - ); - - // - // Calculate Risk Reward Ration based on Priority ... - hasRewardAmount = CalculateRiskReward( - priority, - reward, - amountPercent // - ); - - // - // Calculate Pivot and Point ... - - // - pivot = - isSelectedZonDirBullish - ? selectedZone.ob.Lower() - : selectedZone.ob.Upper(); - - // - point = - isSelectedZonDirBullish - ? selectedZone.ob.Upper() - : selectedZone.ob.Lower(); - - // - // Detect Targets ... - DetectSelectedZonesTargets( - targets, - selectedZone, - selectedZoneDir, - priority, - workingZone, - zIndex // - ); - - // - // Detect SLs ... - double iAtr = decisionXConditions.atrBuffer[0]; - iAtr *= 1.5; - - // - // Default SL is Pivot ... - if (pivot > 0) - { - // - Add( - pivot, - sls // - ); - - // - double iSL = iAtr * pivot; - Add( - iSL, - sls // - ); - } - - // - DetectSelectedZoneSLCandidates( - sls, - selectedZone, - selectedZoneDir, - workingZone, - decisionXConditions, - zIndex, - maxAllowedSLDistanceInPoint // - ); - - // - // Summaries Conditions ... - result = - pivot > 0 && - point > 0 && - hasPriority && - hasRewardAmount && - HasDirection(selectedZoneDir); - if (result) - { - // - isBullish = IsBullish(selectedZoneDir); - isBearish = IsBearish(selectedZoneDir); - - // - Copy( - sls, - mConditions.sls // - ); - Copy( - targets, - mConditions.targets // - ); - - // - mConditions.pivot = pivot; - mConditions.point = point; - mConditions.reward = reward; - mConditions.setupTime = cTime; - mConditions.priority = priority; - mConditions.provider = provider; - mConditions.dir = selectedZoneDir; - mConditions.signalBox = signalBox; - mConditions.amountPercent = amountPercent; - } - - // - // Cleanup Resources ... - - // - Clean(sls); - Clean(targets); - selectedZone.Clean(); - selectedConsolidationZone.Clean(); - } - - // - if (hasSignalBox) - { - // // - // workingZone.mInsideZoneObjects.Clear(); - // workingZone.mBreakedZoneObjects.Clear(); - // workingZone.mWaitingZoneObjects.Clear(); - // workingZone.mWorkingZoneObjects.Clear(); - - // // - // XCBoxObject *iObj; - // signalBox.to = cTime; - // bool isCreated = drawer.CreateBox( - // signalBox, - // iObj // - // ); - - // // - // if (isCreated) - // { - // // - // iObj.BoxWidth(2); - // iObj.BoxColor(clrYellow); - // iObj.BoxStyle(STYLE_SOLID); - // } - - // // - // bool isSignalBoxBullishDir = signalBox.IsBullish(); - - // // - // // Calculate Priority ... - // hasPriority = - // hasWorkingZone && - // workingZone - // .DetectPriority( - // priority, - // signalBox.dir, - // zIndex, - // period // - // ); - - // // - // // Calculate Risk Reward Ration based on Priority ... - // hasRewardAmount = CalculateRiskReward( - // priority, - // reward, - // amountPercent // - // ); - - // // - // // Calculate Pivot and Point ... - - // // - // pivot = - // isSignalBoxBullishDir - // ? signalBox.lower - // : signalBox.upper; - - // // - // point = - // isSignalBoxBullishDir - // ? signalBox.upper - // : signalBox.lower; - - // // - // double defaultTarget = - // isSignalBoxBullishDir - // ? signalBox.upper - // : signalBox.lower; - // Add( - // defaultTarget, - // targets // - // ); - - // // - // // Detect SLs ... - // double iAtr = decisionXConditions.atrBuffer[0]; - // iAtr *= 1.5; - - // // - // double defaultSL = - // isSignalBoxBullishDir - // ? decisionXConditions.valesBuffer[0] - iAtr - // : decisionXConditions.peaksBuffer[0] + iAtr; - - // // - // Add( - // defaultSL, - // sls // - // ); - - // // - // // Summaries Conditions ... - // result = - // pivot > 0 && - // point > 0 && - // hasPriority && - // hasRewardAmount; - // if (result) - // { - // // - // isBullish = signalBox.IsBullish(); - // isBearish = signalBox.IsBearish(); - - // // - // Copy( - // sls, - // mConditions.sls // - // ); - // Copy( - // targets, - // mConditions.targets // - // ); - - // // - // mConditions.pivot = pivot; - // mConditions.point = point; - // mConditions.reward = reward; - // mConditions.setupTime = cTime; - // mConditions.priority = priority; - // mConditions.provider = provider; - // mConditions.dir = signalBox.dir; - // mConditions.signalBox = signalBox; - // mConditions.amountPercent = amountPercent; - // } - - // // - // signalBox.Clean(); - // hasSignalBox = false; - } - - // - UpdateTo(cTime); - - // - // Draw Working Zone ... - if (hasWorkingZone) - { - // - workingZone.Draw( - drawer, - true, // Draw Waiting Zones ... - true, // Draw Inside Zones ... - true, // Draw Breaked Zones ... - true, // Draw Supply Zone ... - true, // Draw Demand Zone ... - false, // Draw Supply Zones ... - false, // Draw Demand Zones ... - false, // Draw Support Zones ... - false // Draw Resistance Zones ... - ); - - // - // XCBaseObject *objects[]; - // drawer.DrawState( - // decisionState, - // objects, - // false, // DrawT icksZone ... - // true, // Ignore SwingHighs ... - // true, // Ignore SwingLows ... - // true, // Ignore SupportZones ... - // true, // Ignore ResistanceZones ... - // true, // Ignore SupplyZones ... - // true, // Ignore DemandZones ... - // true, // Ignore BullishOrderBlocks ... - // true, // Ignore BearishOrderBlocks ... - // true, // Ignore BullishFairValueGaps ... - // true, // Ignore BearishFairValueGaps ... - // true, // Ignore BullishRejectionBars ... - // true, // Ignore BearishRejectionBars ... - // true, // Ignore BullishMomentumBars ... - // true, // Ignore BearishMomentumBars ... - // true, // Ignore BullishConsolidationZones ... - // true // Ignore BearishConsolidationZones ... - // ); - - // // - // int count = 0; - // bool has = false; - - // // - // has = workingZone.HasSupplyZones(); - // if (has) - // { - // } - - // // - // has = workingZone.HasDemandZones(); - // if (has) - // { - // // - // count = workingZone.CountDemandZones(); - // for (int i = 0; i < count; i++) - // { - // // - // XCDemandZone *iZone = workingZone.demandZones[i]; - - // // - // XCDemandZoneObject *iObj; - // bool isCreated = drawer.CreateDemandZone( - // iZone, - // iObj // - // ); - // } - // } - - // // - // Print(""); - } - - // - // Cleanup Resources ... - - // - Clean(visionPoiEvents); - Clean(analysePoiEvents); - Clean(decisionPoiEvents); - Clean(consolidationPoiEvents); - - // - Clean(visionCycleEvents); - Clean(analyseCycleEvents); - Clean(decisionCycleEvents); - Clean(consolidationCycleEvents); - - // - visionState.Clean(); - analyseState.Clean(); - decisionState.Clean(); - consolidationState.Clean(); - - // - visionConditions.Clean(); - analyseConditions.Clean(); - decisionConditions.Clean(); - consolidationConditions.Clean(); - - // - visionXConditions.Clean(); - analyseXConditions.Clean(); - decisionXConditions.Clean(); - consolidationXConditions.Clean(); - - // - consolidationZBar.Clean(); - - // - return result; - } - - // - // Detect Trigger Conditions ... - bool DetectSignalTrigger( - // - X121SMCStrategyXWZSignalConditions &conditions, - // - XC121SMCCycleHelper *decisionCycleHelper, - XC121SMCCycleHelper *analyseCycleHelper, - XC121SMCCycleHelper *consolidationCycleHelper, - XC121SMCCycleHelper *visionCycleHelper, - // - int maxAllowedSetupAge = 60 - // - ) - { - // - bool result = false; - - // - result = - // - visionCycleHelper != NULL && - analyseCycleHelper != NULL && - decisionCycleHelper != NULL && - consolidationCycleHelper != NULL - // - ; - if (!result) - { - return result; - } - - // - result = conditions.IsSetuped(); - if (!result) - { - return result; - } - - // - datetime setupTime = conditions.setupTime; - ENUM_X_DIRECTION setupDir = conditions.dir; - - // - bool isBullish = IsBullish(setupDir); - bool isBearish = IsBearish(setupDir); - - // - int zIndex = 0; - int cIndex = zIndex + 1; - int pIndex = cIndex + 1; - int ppIndex = pIndex + 1; - - // - int loopback = 10; - - // - double ask = GetAsk(symbol); - double bid = GetBid(symbol); - datetime cTime = TimeCurrent(); - double points = GetPoints(symbol); - - // - // Cycles Conditions ... - - // - // Decision ... - ENUM_XPOI_EVENTS decisionPoiEvents[]; - ENUM_X_CYCLE_EVENTS decisionCycleEvents[]; - X121SMCCycleConditions decisionConditions; - result = decisionCycleHelper.GetConditions( - decisionCycleEvents, - decisionPoiEvents, - decisionConditions, - zIndex, - loopback // - ); - if (!result) - { - // - // Cleanup ... - - // - Clean(decisionPoiEvents); - Clean(decisionCycleEvents); - - // - decisionConditions.Clean(); - - // - return result; - } - - // - // Analyse ... - ENUM_XPOI_EVENTS analysePoiEvents[]; - ENUM_X_CYCLE_EVENTS analyseCycleEvents[]; - X121SMCCycleConditions analyseConditions; - result = analyseCycleHelper.GetConditions( - analyseCycleEvents, - analysePoiEvents, - analyseConditions, - zIndex, - loopback // - ); - if (!result) - { - // - Clean(analysePoiEvents); - Clean(decisionPoiEvents); - - // - Clean(analyseCycleEvents); - Clean(decisionCycleEvents); - - // - analyseConditions.Clean(); - decisionConditions.Clean(); - - // - return result; - } - - // - // Cycles POI States ... - XPOIState decisionState = decisionConditions.state; - XPOIState analyseState = analyseConditions.state; - - // - // Cycle X121Conditions ... - X121Conditions decisionXConditions = decisionConditions.x121Conditions; - X121Conditions analyseXConditions = analyseConditions.x121Conditions; - - // - double iAtr = decisionXConditions.atrBuffer[1]; - iAtr *= 1.5; - - // - // Check Signal Validation ... - // IMPORTANT: since all Validations done in SetUp Process ... - // here we only Execute Signal ... - - // - result = isBullish || - isBearish; - - // - if (result) - { - // - // Retrieve Entry Price ... - double entry = GetEntry( - conditions.symbol, - setupDir // - ); - - // - // Select and Apply SL ... - - // - double slsMin = GetMin(conditions.sls); - double slsMax = GetMax(conditions.sls); - - // - double longSL = slsMin; - double shortSL = slsMax; - - // - double sl = isBullish - ? longSL - : shortSL; - - // - conditions.sl = sl; - conditions.triggerTime = cTime; - conditions.type = isBullish - ? X_POSITION_TYPE_LONG - : X_POSITION_TYPE_SHORT; - - // - } - - // - // Cleanup ... - - // - Clean(decisionPoiEvents); - Clean(decisionCycleEvents); - - // - decisionState.Clean(); - decisionConditions.Clean(); - decisionXConditions.Clean(); - - // - Clean(analysePoiEvents); - Clean(analyseCycleEvents); - - // - analyseState.Clean(); - analyseConditions.Clean(); - analyseXConditions.Clean(); - - // - return result; - } - - // - // Detect Guards ... - bool DetectGuards( - // - X121SMCGuard &guards[], - const XPosition &positions[], - // - XC121SMCCycleHelper *decisionCycleHelper, - XC121SMCCycleHelper *analyseCycleHelper, - XC121SMCCycleHelper *consolidationCycleHelper, - XC121SMCCycleHelper *visionCycleHelper - // - ) - { - // - bool result = false; - return false; - - // - Clean(guards); - - // - bool isCycleHelpersValid = - // - visionCycleHelper != NULL && - analyseCycleHelper != NULL && - decisionCycleHelper != NULL && - consolidationCycleHelper != NULL - // - ; - - // - // Set Provider for Common Guards ... - string provider = ToString(X_121_SMC_PROVIDER_XWZ); - - // - // Check Cycle Helpers Validation ... - result = isCycleHelpersValid; - if (!result) - { - return result; - } - - // - // Select Own Positions ... - int count = ArraySize(positions); - result = IsValidSize(count); - if (!result) - { - return result; - } - - // - XPosition ownPositions[]; - XPosition ownLongPositions[]; - XPosition ownShortPositions[]; - for (int i = 0; i < count; i++) - { - // - XPosition iPosition = positions[i]; - bool isOwn = iPosition - .IsFiltersPassed( - symbol, - provider, - NULL, - X_POSITION_TYPE_ALL, - iPosition.magic // - ); - if (isOwn) - { - // - AddRef( - iPosition, - ownPositions // - ); - - // - bool isLong = IsLong(positions[i].type); - if (isLong) - { - // - AddRef( - iPosition, - ownLongPositions // - ); - } - else - { - // - AddRef( - iPosition, - ownShortPositions // - ); - } - } - } - - // - // Check Extracted Positions ... - - // - count = ArraySize(ownPositions); - - // - int longsCount = ArraySize(ownLongPositions); - bool hasLongs = IsValidSize(longsCount); - - // - int shortsCount = ArraySize(ownShortPositions); - bool hasShorts = IsValidSize(shortsCount); - - // - // Validate Own Positions ... - result = IsValidSize(count); - if (!result) - { - // - Clean(ownPositions); - Clean(ownLongPositions); - Clean(ownShortPositions); - - // - return result; - } - - // - // - // - - // - // Get Global and Common Guards ... - - // - ENUM_X_121_SMC_GUARD_ACTIONS ignoreGuards[1] = { - X_121_SMC_GUARD_ACTION_TRAIL_STOP // - }; - result = DetectX121SMCGuards( - provider, - guards, - positions, - decisionCycleHelper, - analyseCycleHelper, - consolidationCycleHelper, - visionCycleHelper, - // - ignoreGuards - // - ); - - // - // - // - - // - // Implement Custom Implemented Guards ... - - // - // Here we Are Sure there is Positions to Guard ... - // based on Current Provider ... - - // - // Detect Required Data for Analyse Market to Guard Positions ... - - // - int zIndex = 0; - int cIndex = zIndex + 1; - int pIndex = cIndex + 1; - int ppIndex = pIndex + 1; - - // - int loopback = 10; - - // - double ask = GetAsk(symbol); - double bid = GetBid(symbol); - datetime cTime = TimeCurrent(); - double points = GetPoints(symbol); - - // - // Cycles Conditions ... - - // - // Decision ... - ENUM_XPOI_EVENTS decisionPoiEvents[]; - ENUM_X_CYCLE_EVENTS decisionCycleEvents[]; - X121SMCCycleConditions decisionConditions; - result = decisionCycleHelper.GetConditions( - decisionCycleEvents, - decisionPoiEvents, - decisionConditions, - zIndex, - loopback // - ); - if (!result) - { - // - Clean(decisionPoiEvents); - Clean(decisionCycleEvents); - - // - decisionConditions.Clean(); - - // - result = HasChild(guards); - return result; - } - - // - // Analyse ... - ENUM_XPOI_EVENTS analysePoiEvents[]; - ENUM_X_CYCLE_EVENTS analyseCycleEvents[]; - X121SMCCycleConditions analyseConditions; - result = analyseCycleHelper.GetConditions( - analyseCycleEvents, - analysePoiEvents, - analyseConditions, - zIndex, - loopback // - ); - if (!result) - { - // - Clean(decisionPoiEvents); - Clean(decisionCycleEvents); - - // - decisionConditions.Clean(); - - // - Clean(analysePoiEvents); - Clean(analyseCycleEvents); - - // - analyseConditions.Clean(); - - // - result = HasChild(guards); - return result; - } - - // - // Consolidation ... - ENUM_XPOI_EVENTS consolidationPoiEvents[]; - ENUM_X_CYCLE_EVENTS consolidationCycleEvents[]; - X121SMCCycleConditions consolidationConditions; - result = consolidationCycleHelper.GetConditions( - consolidationCycleEvents, - consolidationPoiEvents, - consolidationConditions, - zIndex, - loopback // - ); - if (!result) - { - // - Clean(decisionPoiEvents); - Clean(decisionCycleEvents); - - // - decisionConditions.Clean(); - - // - Clean(analysePoiEvents); - Clean(analyseCycleEvents); - - // - analyseConditions.Clean(); - - // - Clean(consolidationPoiEvents); - Clean(consolidationCycleEvents); - - // - consolidationConditions.Clean(); - - // - result = HasChild(guards); - return result; - } - - // - // Vision ... - ENUM_XPOI_EVENTS visionPoiEvents[]; - ENUM_X_CYCLE_EVENTS visionCycleEvents[]; - X121SMCCycleConditions visionConditions; - result = visionCycleHelper.GetConditions( - visionCycleEvents, - visionPoiEvents, - visionConditions, - zIndex, - loopback // - ); - if (!result) - { - // - Clean(decisionPoiEvents); - Clean(decisionCycleEvents); - - // - decisionConditions.Clean(); - - // - Clean(analysePoiEvents); - Clean(analyseCycleEvents); - - // - analyseConditions.Clean(); - - // - Clean(consolidationPoiEvents); - Clean(consolidationCycleEvents); - - // - consolidationConditions.Clean(); - - // - Clean(visionPoiEvents); - Clean(visionCycleEvents); - - // - visionConditions.Clean(); - - // - result = HasChild(guards); - return result; - } - - // - // Cycles POI States ... - XPOIState visionState = visionConditions.state; - XPOIState analyseState = analyseConditions.state; - XPOIState decisionState = decisionConditions.state; - XPOIState consolidationState = consolidationConditions.state; - - // - // Cycle X121Conditions ... - X121Conditions visionXConditions = visionConditions.x121Conditions; - X121Conditions analyseXConditions = analyseConditions.x121Conditions; - X121Conditions decisionXConditions = decisionConditions.x121Conditions; - X121Conditions consolidationXConditions = consolidationConditions.x121Conditions; - - // - // - // - - // - // Selected Consolidation Zones ... - - // - int idx = -1; - bool has = false; - - // - bool hasBullishConsolidationZone = false; - XConsolidationZone bullishConsolidationZone; - has = decisionState.HasBullishConsolidationZones(); - if (has) - { - // - idx = GetYoungest(decisionState.bullishConsolidationZones); - hasBullishConsolidationZone = IsValidIndex(idx); - if (hasBullishConsolidationZone) - { - bullishConsolidationZone = decisionState.bullishConsolidationZones[idx]; - } - } - - // - bool hasBearishConsolidationZone = false; - XConsolidationZone bearishConsolidationZone; - has = decisionState.HasBearishConsolidationZones(); - if (has) - { - // - idx = GetYoungest(decisionState.bearishConsolidationZones); - hasBearishConsolidationZone = IsValidIndex(idx); - if (hasBearishConsolidationZone) - { - bearishConsolidationZone = decisionState.bearishConsolidationZones[idx]; - } - } - - // - // Here We Have all Requirements for Guarding Positions ... - - // - // Available Guards: - // X_121_SMC_GUARD_ACTION_NONE - // X_121_SMC_GUARD_ACTION_CLOSE - // X_121_SMC_GUARD_ACTION_CLOSE_ALL - // X_121_SMC_GUARD_ACTION_CLOSE_LONGS - // X_121_SMC_GUARD_ACTION_CLOSE_SHORTS - // X_121_SMC_GUARD_ACTION_PARTIAL_CLOSE - // X_121_SMC_GUARD_ACTION_TRAIL_STOP - // X_121_SMC_GUARD_ACTION_TRAIL_TARGET - // X_121_SMC_GUARD_ACTION_HEDGE - - // - // X_121_SMC_GUARD_ACTION_CLOSE: - // Close Specified Position on Specified Conditions ... - - // - // X_121_SMC_GUARD_ACTION_CLOSE_ALL: - // Close All Positions on Specified Conditions ... - - // - // X_121_SMC_GUARD_ACTION_CLOSE_LONGS: - // Close All Long Positions on Specified Conditions ... - - // - // X_121_SMC_GUARD_ACTION_CLOSE_SHORTS: - // Close All Short Positions on Specified Conditions ... - - // - // X_121_SMC_GUARD_ACTION_PARTIAL_CLOSE: - // Partial Close Specified Position on Specified Conditions ... - - // - // X_121_SMC_GUARD_ACTION_TRAIL_STOP: - // Trail Stop Specified Position on Specified Conditions ... - bool handleStoptrailingBasedOnConsolidationZones = true; - for (int i = 0; i < count; i++) - { - // - XPosition iPosition = ownPositions[i]; - - // - bool isLong = IsLong(iPosition.type); - bool isInProfit = iPosition.profit > 0; - - // - double sl = iPosition.sl; - double tp = iPosition.tp; - - // - // Trail Stops Using Consolidation Zones ... - - // - bool canTraiLonglUsingCZone = - // - handleStoptrailingBasedOnConsolidationZones && - // - (isLong && - isInProfit && - hasBullishConsolidationZone && - bullishConsolidationZone.lower > iPosition.sl && - bullishConsolidationZone.lower > iPosition.entry) - // - ; - if (canTraiLonglUsingCZone) - { - sl = bullishConsolidationZone.lower; - } - - // - bool canTraiShortlUsingCZone = - // - handleStoptrailingBasedOnConsolidationZones && - // - (!isLong && - isInProfit && - hasBearishConsolidationZone && - bearishConsolidationZone.upper < iPosition.sl && - bearishConsolidationZone.upper < iPosition.entry) - // - ; - if (canTraiShortlUsingCZone) - { - sl = bearishConsolidationZone.upper; - } - - // - bool canTrailUsingCZone = - canTraiLonglUsingCZone || - canTraiShortlUsingCZone; - - // - bool isSLPassed = - sl > 0 && - (isLong - ? iPosition.price - sl >= points * 15 - : sl - iPosition.price >= points * 15); - - // - bool canTrail = - isSLPassed && - canTrailUsingCZone; - if (canTrail) - { - // - X121SMCGuard iGuard; - - // - iGuard.time = cTime; - iGuard.symbol = symbol; - iGuard.provider = provider; - iGuard.action = X_121_SMC_GUARD_ACTION_TRAIL_STOP; - - // - iGuard.ticket = iPosition.ticket; - - // - iGuard.sl = sl; - - // - AddGuard( - iGuard, - guards // - ); - } - } - - // - // X_121_SMC_GUARD_ACTION_TRAIL_TARGET: - // Trail Target Specified Position on Specified Conditions ... - - // - // X_121_SMC_GUARD_ACTION_HEDGE: - // Hedge all Positions on Specified Conditions ... - - // - // Cleanup Collections ... - - // - Clean(ownPositions); - Clean(ownLongPositions); - Clean(ownShortPositions); - - // - visionState.Clean(); - analyseState.Clean(); - decisionState.Clean(); - consolidationState.Clean(); - - // - visionConditions.Clean(); - analyseConditions.Clean(); - decisionConditions.Clean(); - consolidationConditions.Clean(); - - // - visionXConditions.Clean(); - analyseXConditions.Clean(); - decisionXConditions.Clean(); - consolidationXConditions.Clean(); - - // - Clean(visionPoiEvents); - Clean(analysePoiEvents); - Clean(decisionPoiEvents); - Clean(consolidationPoiEvents); - - // - Clean(visionCycleEvents); - Clean(analyseCycleEvents); - Clean(decisionCycleEvents); - Clean(consolidationCycleEvents); - - // - count = ArraySize(guards); - result = IsValidSize(count); - - // - return result; - } - - // - // Add Conditions to Conditions Collection ... - int AddConditionsIfNotExists( - int maxAllowed = 10 // - ) - { - // - int result = 0; - - // - bool isSetuped = IsValid(mConditions.setupTime) && - HasDirection(mConditions.dir); - if (!isSetuped) - { - return result; - } - - // - int count = ArraySize(mConditionsCollection); - if (IsValidSize(count)) - { - // - // Copy Original Items ... - X121SMCStrategyXWZSignalConditions tmpItems[]; - Copy( - mConditionsCollection, - tmpItems // - ); - - // - // Prese Item Data ... - bool isBullish = IsBullish(mConditions.dir); - - // - for (int i = 0; i < count; i++) - { - // - X121SMCStrategyXWZSignalConditions iItem = tmpItems[i]; - - // - bool canRemove = mConditions.dir == iItem.dir && - mConditions.pivot == iItem.pivot; - if (canRemove) - { - // - ArrayRemove( - mConditionsCollection, - i, - 1 // - ); - } - } - - // - Clean(tmpItems); - } - - // - AddRef( - mConditions, - mConditionsCollection // - ); - - // - // Remove Olds ... - CleanupArray( - mConditionsCollection, - maxAllowed // - ); - - // - result = ArraySize(mConditionsCollection); - - // - return result; - } - - // - // Draw Functions ... - // - - // - void DrawBar( - XOHCL &bar, - XCPOIDrawer *drawer, - bool forceClean = true // - ) - { - // - if (forceClean) - { - mBarObjects.Clear(); - } - - // - if (drawer == NULL || - !bar.IsValid()) - { - return; - } - - // - bool isBullish = bar.IsBullish(); - - // - int widthBar = 2; - bool fillShadowsBar = true; - ENUM_LINE_STYLE styleBar = STYLE_SOLID; - color clrBar = - isBullish - ? clrAqua - : clrMagenta; - - // - datetime to = bar.NextAt(); - - // - XCOHCLObject *iObj; - bool isCreated = drawer - .CreateBar( - bar, - iObj, - to // - ); - if (isCreated) - { - // - iObj.BarSpes( - widthBar, - clrBar, - styleBar // - ); - - // - iObj.LowShadowFill(fillShadowsBar); - iObj.HighShadowFill(fillShadowsBar); - - // - mBarObjects.Add(iObj); - } - } - - // - protected: - // - - // - private: - // - // Props ... - string symbol; - ENUM_TIMEFRAMES period; - CArrayObj mObjects; - CArrayObj mBarObjects; - CArrayObj mWorkingZoneObjects; - - /** - * Initialize ... - */ - void Init() - { - } - - /** - * DeInitialize ... - */ - void DeInit() - { - // - mConditions.Clean(); - workingZone.Clean(); - Clean(mConditionsCollection); - - // - mBarObjects.Clear(); - } - - /** - * Update To Time of Exists Components ... - * - * @param value: updated time ... - */ - void UpdateTo( - datetime value = NULL // - ) - { - // - value = NormalizeTime(value); - - // - workingZone.UpdateTo(value); - } - - // - // Helpers ... - - // - bool CalculateRiskReward( - ENUM_X121SMC_XWZ_PRIORITY priority, - double &reward, - double &amountPercent // - ) - { - // - bool result = false; - - // - reward = 0; - amountPercent = 0; - - // - result = priority != X121SMC_XWZ_PRIORITY_NONE; - if (!result) - { - return result; - } - - // - switch (priority) - { - // - case X121SMC_XWZ_PRIORITY_STRONG_HIGH: - // - reward = 6; - amountPercent = 2; - break; - - // - case X121SMC_XWZ_PRIORITY_HIGH: - // - reward = 4; - amountPercent = 2; - break; - - // - case X121SMC_XWZ_PRIORITY_REGULAR: - // - reward = 3; - amountPercent = 1.5; - break; - - // - case X121SMC_XWZ_PRIORITY_LOW: - // - reward = 2; - amountPercent = 1; - break; - - // - case X121SMC_XWZ_PRIORITY_WEAK: - // - reward = 1; - amountPercent = 0.5; - break; - } - - // - result = - // - reward > 0 && - amountPercent > 0 - // - ; - - // - return result; - } - - // -}; - -// \ No newline at end of file diff --git a/Documents/BKP/x-121.smc.xwz.signal.class.mq5 b/Documents/BKP/x-121.smc.xwz.signal.class.mq5 deleted file mode 100644 index c80b6cc3..00000000 --- a/Documents/BKP/x-121.smc.xwz.signal.class.mq5 +++ /dev/null @@ -1,3960 +0,0 @@ -/////////////////////////////////////////////////////// -// -// SaherElm IT Center MQL5 X121 SMC Signal Class -// ------------------------------------------------- -// Name: XWZ -// Description: provide all Signalling functions ... -// -// -// Maintainer: -// ------------ -// Hadi Khazaee Asl (hadi_khazaee_asl@yahoo.com) -// -////////////////////////////////////////////////////// -// -// Global Properties ... -#property library -#property copyright "Copyright 2023, SaherElm IT Center" -#property link "https://www.saherelm.ir" -#property version "1.00" -#property strict - -// -// Imports ... -#include "../Classes/x-121.smc.market.cycle.helper.class.mq5" -#include "../Libraries/x-121.smc.guard.lib.mq5" -#include "../Libraries/x-121.smc.lib.mq5" -#include "./x-121.smc.xwz.signal.lib.mq5" - -// -// Definition ... -class XCX121SMCXWZSignalDetector : public XCBase -{ - // - public: - // - // Props ... - XOBFVG chochZone; - XOBFVG targetZone; - XOBFVG signalZone; - XOBFVG waitingZone; - X121SMCStrategyXWZWorkingZone workingZone; - X121SMCStrategyXWZSignalConditions mConditions; - X121SMCStrategyXWZSignalConditions mConditionsCollection[]; - - // - // Constructor(s) ... - XCX121SMCXWZSignalDetector( - string _symbol, - ENUM_TIMEFRAMES _period // - ) - { - // - symbol = _symbol; - period = _period; - Init(); - } - - // - // Deconstructor ... - ~XCX121SMCXWZSignalDetector() - { - DeInit(); - } - - // - // - // - - // - // Detect Setup Conditions ... - bool DetectSignalSetup( - // - XC121SMCCycleHelper *decisionCycleHelper, - XC121SMCCycleHelper *analyseCycleHelper, - XC121SMCCycleHelper *consolidationCycleHelper, - XC121SMCCycleHelper *visionCycleHelper - // - ) - { - // - bool result = false; - - // - // Validate Cycle Helpers ... - result = - // - visionCycleHelper != NULL && - analyseCycleHelper != NULL && - decisionCycleHelper != NULL && - consolidationCycleHelper != NULL - // - ; - if (!result) - { - // - mConditions.Clean(); - - // - return result; - } - - // - bool isBullish = false; - bool isBearish = false; - - // - int zIndex = 0; - int cIndex = zIndex + 1; - int pIndex = cIndex + 1; - int ppIndex = pIndex + 1; - - // - int loopback = 10; - - // - mConditions.symbol = symbol; - mConditions.period = period; - - // - double ask = GetAsk(symbol); - double bid = GetBid(symbol); - datetime cTime = TimeCurrent(); - double points = GetPoints(symbol); - - // - double pivot = 0; - double point = 0; - double target = 0; - double reward = 0; - double amountPercent = 0; - ENUM_X121SMC_XWZ_PRIORITY priority = X121SMC_XWZ_PRIORITY_NONE; - - // - // Cycles Conditions ... - - // - XOHCL consolidationZBar; - result = consolidationCycleHelper.GetBar( - consolidationZBar, - zIndex // - ); - if (!result) - { - // - consolidationZBar.Clean(); - return result; - } - - // - bool drawBar = true; - if (drawBar) - { - // - DrawBar( - consolidationZBar, - decisionCycleHelper.mPOIDrawer // - ); - } - - // - // Decision ... - ENUM_XPOI_EVENTS decisionPoiEvents[]; - ENUM_X_CYCLE_EVENTS decisionCycleEvents[]; - X121SMCCycleConditions decisionConditions; - result = decisionCycleHelper.GetConditions( - decisionCycleEvents, - decisionPoiEvents, - decisionConditions, - zIndex, - loopback // - ); - if (!result) - { - // - Clean(decisionPoiEvents); - Clean(decisionCycleEvents); - - // - decisionConditions.Clean(); - - // - mConditions.Clean(); - consolidationZBar.Clean(); - - // - return result; - } - - // - // Analyse ... - ENUM_XPOI_EVENTS analysePoiEvents[]; - ENUM_X_CYCLE_EVENTS analyseCycleEvents[]; - X121SMCCycleConditions analyseConditions; - result = analyseCycleHelper.GetConditions( - analyseCycleEvents, - analysePoiEvents, - analyseConditions, - zIndex, - loopback // - ); - if (!result) - { - // - Clean(analysePoiEvents); - Clean(decisionPoiEvents); - - // - Clean(analyseCycleEvents); - Clean(decisionCycleEvents); - - // - analyseConditions.Clean(); - decisionConditions.Clean(); - - // - mConditions.Clean(); - consolidationZBar.Clean(); - - // - return result; - } - - // - // Consolidation ... - ENUM_XPOI_EVENTS consolidationPoiEvents[]; - ENUM_X_CYCLE_EVENTS consolidationCycleEvents[]; - X121SMCCycleConditions consolidationConditions; - result = consolidationCycleHelper.GetConditions( - consolidationCycleEvents, - consolidationPoiEvents, - consolidationConditions, - zIndex, - loopback // - ); - if (!result) - { - // - Clean(analysePoiEvents); - Clean(decisionPoiEvents); - Clean(consolidationPoiEvents); - - // - Clean(analyseCycleEvents); - Clean(decisionCycleEvents); - Clean(consolidationCycleEvents); - - // - analyseConditions.Clean(); - decisionConditions.Clean(); - consolidationConditions.Clean(); - - // - mConditions.Clean(); - consolidationZBar.Clean(); - - // - return result; - } - - // - // Vision ... - ENUM_XPOI_EVENTS visionPoiEvents[]; - ENUM_X_CYCLE_EVENTS visionCycleEvents[]; - X121SMCCycleConditions visionConditions; - result = visionCycleHelper.GetConditions( - visionCycleEvents, - visionPoiEvents, - visionConditions, - zIndex, - loopback // - ); - if (!result) - { - // - Clean(visionPoiEvents); - Clean(analysePoiEvents); - Clean(decisionPoiEvents); - Clean(consolidationPoiEvents); - - // - Clean(visionCycleEvents); - Clean(analyseCycleEvents); - Clean(decisionCycleEvents); - Clean(consolidationCycleEvents); - - // - visionConditions.Clean(); - analyseConditions.Clean(); - decisionConditions.Clean(); - consolidationConditions.Clean(); - - // - mConditions.Clean(); - consolidationZBar.Clean(); - - // - return result; - } - - // - // Cycles POI States ... - XPOIState decisionState = decisionConditions.state; - XPOIState analyseState = analyseConditions.state; - XPOIState consolidationState = consolidationConditions.state; - XPOIState visionState = visionConditions.state; - - // - // Cycle X121Conditions ... - X121Conditions decisionXConditions = decisionConditions.x121Conditions; - X121Conditions analyseXConditions = analyseConditions.x121Conditions; - X121Conditions consolidationXConditions = consolidationConditions.x121Conditions; - X121Conditions visionXConditions = visionConditions.x121Conditions; - - // - // Setup Conditions ... - - // - // Choch Trading Senario ... - bool hasChochBullishConditions = false; - bool hasChochBearishConditions = false; - - // - // Order Flow Side Trading Senario ... - bool hasOrderFlowhBullishConditions = false; - bool hasOrderFlowhBearishConditions = false; - - // - // Trend Line Trading Senario ... - bool hasTrendLineBullishConditions = false; - bool hasTrendLineBearishConditions = false; - - // - // Quarter Line Trading Senario ... - bool hasBQuarterLineBullishConditions = false; - bool hasBQuarterLineBearishConditions = false; - - // - // Supply and Demand Trading Senario ... - bool hasSupDemBullishConditions = false; - bool hasSupDemBearishConditions = false; - - // - // Support and Resistance Trading Senario ... - bool hasSupResBullishConditions = false; - bool hasSupResBearishConditions = false; - - // - ENUM_X121SMC_XWZ_PROVIDERS provider = X121SMC_XWZ_PROVIDER_NONE; - - // - // Detect Working Zone ... - bool hasWorkingZone = workingZone.IsValid(); - if (!hasWorkingZone) - { - hasWorkingZone = DetectWorkingZone(visionState); - } - - // - // result = hasWorkingZone; - // if (!result) - // { - // // - // Clean(visionPoiEvents); - // Clean(analysePoiEvents); - // Clean(decisionPoiEvents); - // Clean(consolidationPoiEvents); - - // // - // Clean(visionCycleEvents); - // Clean(analyseCycleEvents); - // Clean(decisionCycleEvents); - // Clean(consolidationCycleEvents); - - // // - // visionState.Clean(); - // analyseState.Clean(); - // decisionState.Clean(); - // consolidationState.Clean(); - - // // - // visionConditions.Clean(); - // analyseConditions.Clean(); - // decisionConditions.Clean(); - // consolidationConditions.Clean(); - - // // - // visionXConditions.Clean(); - // analyseXConditions.Clean(); - // decisionXConditions.Clean(); - // consolidationXConditions.Clean(); - - // // - // mConditions.Clean(); - // consolidationZBar.Clean(); - - // // - // return result; - // } - - // - // Supply Zones ... - bool hasSupplyZones = workingZone.HasSupplyZones(); - int supplyZonesCount = workingZone.CountSupplyZones(); - if (hasWorkingZone) - { - // - supplyZonesCount = workingZone - .DetectSupplyZones(consolidationState); - hasSupplyZones = IsValidSize(supplyZonesCount); - } - - // - // Demand Zones ... - bool hasDemandZones = workingZone.HasDemandZones(); - int demandZonesCount = workingZone.CountDemandZones(); - if (hasWorkingZone) - { - // - demandZonesCount = workingZone - .DetectDemandZones(consolidationState); - hasDemandZones = IsValidSize(demandZonesCount); - } - - // - // TODO: Remove this ... - UpdateTo(cTime); - - // - // Detect Working Zone Destroy ... - bool isWorkingZoneDetroyed = - hasWorkingZone && - workingZone.IsDestroyed(); - if (isWorkingZoneDetroyed) - { - mWorkingZoneObjects.Clear(); - } - - // - // result = !isWorkingZoneDetroyed; - // if (!result) - // { - // // - // workingZone.Clean(); - // mWorkingZoneObjects.Clear(); - - // // - // Clean(visionPoiEvents); - // Clean(analysePoiEvents); - // Clean(decisionPoiEvents); - // Clean(consolidationPoiEvents); - - // // - // Clean(visionCycleEvents); - // Clean(analyseCycleEvents); - // Clean(decisionCycleEvents); - // Clean(consolidationCycleEvents); - - // // - // visionState.Clean(); - // analyseState.Clean(); - // decisionState.Clean(); - // consolidationState.Clean(); - - // // - // visionConditions.Clean(); - // analyseConditions.Clean(); - // decisionConditions.Clean(); - // consolidationConditions.Clean(); - - // // - // visionXConditions.Clean(); - // analyseXConditions.Clean(); - // decisionXConditions.Clean(); - // consolidationXConditions.Clean(); - - // // - // mConditions.Clean(); - // consolidationZBar.Clean(); - - // // - // return result; - // } - - // - // Checking Target Zone Breaked ... - bool hasTargetZone = targetZone.IsValid(); - if (hasTargetZone) - { - // - XOHCL bar; - bool isInited = bar.Init( - symbol, - period, - zIndex // - ); - - XOHCL cBar; - isInited = - isInited && - bar.GetPreviousBar(cBar); - - // - bool isBullish = targetZone.IsBullish(); - - // - bool isLowerBreaked = - // - bar.high < targetZone.ob.Lower() && - cBar.high < targetZone.ob.Lower() - // - ; - - // - bool isUpperBreaked = - // - bar.low > targetZone.ob.Upper() && - cBar.low > targetZone.ob.Upper() - // - ; - - // - bool isBreaked = isBullish - ? isLowerBreaked - : isUpperBreaked; - if (isBreaked) - { - // - mWorkingZoneObjects.Clear(); - targetZone.Clean(); - } - } - - // - // Detect Order Flow ... - ENUM_X_DIRECTION trend = X_DIRECTION_NONE; - bool hasOrderFlow = - hasWorkingZone && - workingZone.HasOrderFlow(trend); - if (!hasOrderFlow) - { - // - int orderFlowCount = workingZone.DetectOrderFlow( - symbol, - period, - trend, - visionState, - consolidationState, - analyseState, - decisionState // - ); - hasOrderFlow = IsValidSize(orderFlowCount); - } - - // - bool hasTrend = HasDirection(trend); - bool hasBllishTrend = - hasTrend && - IsBullish(trend); - bool hasBearishTrend = - hasTrend && - IsBearish(trend); - - // - UpdateTo(cTime); - - // - isBullish = IsBullish(trend); - isBearish = IsBearish(trend); - - // - bool hasPriority = workingZone - .DetectPriority( - priority, - trend, - zIndex, - period // - ); - - // - bool hasRewardAmount = CalculateRiskReward( - priority, - reward, - amountPercent // - ); - - // - // Checking Order Flow Break ... - int breakedIDX = -1; - bool isOrderFlowBreaked = - hasOrderFlow && - hasWorkingZone && - workingZone.IsOrderFlowBreaked( - breakedIDX, - true, // Force OB Breaked - false, // Force FVG Breaked - zIndex, - period // - ); - - // - // Order Flow Breaked Senario ... - if (isOrderFlowBreaked) - { - // - AddRef( - workingZone.orderFlow[breakedIDX], - workingZone.brokenOrderFlow // - ); - - // - signalZone = workingZone.orderFlow[breakedIDX]; - provider = X121SMC_XWZ_PROVIDER_ACTIVATED_CHOCH; - - // - ArrayRemove( - workingZone.orderFlow, - breakedIDX, - 1 // - ); - Clean(workingZone.orderFlow); - - // - CleanupArray( - workingZone.brokenOrderFlow, - 10 // - ); - } - - // - // First Check Last Order Flow FVG ... - XOBFVG youngestOrderFlow; - int youngestOBFVGIDX = GetYoungest(workingZone.orderFlow); - bool hasYoungestOBFVG = IsValidIndex(youngestOBFVGIDX); - if (hasYoungestOBFVG) - { - // - youngestOrderFlow = workingZone.orderFlow[youngestOBFVGIDX]; - - // - XOHCL obWorkerBar; - XOHCL obActivationBar; - - // - XOHCL fvgWorkerBar; - XOHCL fvgActivationBar; - - // - bool isOBBodyOut = false; - bool isOBWorked = youngestOrderFlow - .ob - .IsWorked( - trend, - obWorkerBar, - isOBBodyOut, - false // - ); - - // - bool isOBBodyIn = false; - bool isOBActivated = youngestOrderFlow - .ob - .IsActivated( - trend, - obActivationBar, - isOBBodyIn, - false // - ); - - // - bool isFVGBodyOut = false; - bool isFVGWorked = youngestOrderFlow - .fvg - .IsWorked( - trend, - fvgWorkerBar, - isFVGBodyOut, - false // - ); - - // - bool isFVGBodyIn = false; - bool isFVGActivated = youngestOrderFlow - .fvg - .IsActivated( - trend, - fvgActivationBar, - isFVGBodyIn, - false // - ); - - // - if (!isFVGWorked && - isFVGActivated) - { - // - youngestOrderFlow - .UpdateZones(decisionState); - - // - signalZone = youngestOrderFlow; - youngestOrderFlow.Clean(); - ArrayRemove( - workingZone.orderFlow, - youngestOBFVGIDX, - 1 // - ); - - // - provider = X121SMC_XWZ_PROVIDER_ACTIVATED_ZONE; - } - else - { - // - bool isPriceInsideFVG = - // - IsInside( - consolidationZBar.high, - youngestOrderFlow.fvg // - ) - // - && - // - IsInside( - consolidationZBar.low, - youngestOrderFlow.fvg // - ) - // - ; - - // - if (isPriceInsideFVG) - { - // - youngestOrderFlow - .UpdateZones(decisionState); - - // - signalZone = youngestOrderFlow; - youngestOrderFlow.Clean(); - ArrayRemove( - workingZone.orderFlow, - youngestOBFVGIDX, - 1 // - ); - - // - provider = X121SMC_XWZ_PROVIDER_PRICE_INSIDE_ZONE; - } - } - - // - fvgWorkerBar.Clean(); - fvgActivationBar.Clean(); - } - - // - // Check New Order Blocks ... - bool hasNewConsolidationBullishOB = Contains( - X_BULLISH_ORDERBLOCK_DETECTED, - consolidationPoiEvents // - ); - bool hasNewConsolidationBearishOB = Contains( - X_BEARISH_ORDERBLOCK_DETECTED, - consolidationPoiEvents // - ); - bool hasNewOB = hasNewConsolidationBullishOB || - hasNewConsolidationBearishOB; - - // - // Check New Fair Value Gaps ... - bool hasNewConsolidationBullishFVG = Contains( - X_BULLISH_FVG_DETECTED, - consolidationPoiEvents // - ); - bool hasNewConsolidationBearishFVG = Contains( - X_BEARISH_FVG_DETECTED, - consolidationPoiEvents // - ); - bool hasNewFVG = hasNewConsolidationBullishFVG || - hasNewConsolidationBearishFVG; - - // - // Check New Order Blocks ... - bool hasNewAnalyseBullishOrderBlock = Contains( - X_BULLISH_ORDERBLOCK_DETECTED, - analysePoiEvents // - ); - bool hasNewAnalyseBearishOrderBlock = Contains( - X_BEARISH_ORDERBLOCK_DETECTED, - analysePoiEvents // - ); - bool hasNewAnalyseOB = hasNewAnalyseBullishOrderBlock || - hasNewAnalyseBearishOrderBlock; - - // - // Check New Fair Value Gaps ... - bool hasNewAnalyseBullishFVG = Contains( - X_BULLISH_FVG_DETECTED, - analysePoiEvents // - ); - bool hasNewAnalyseBearishFVG = Contains( - X_BEARISH_FVG_DETECTED, - analysePoiEvents // - ); - bool hasNewAnalyseFVG = hasNewAnalyseBullishFVG || - hasNewAnalyseBearishFVG; - - // - // Do Order Flow Actions when new Order Blocks - // or FVGs Formed ... - if (hasNewOB || - hasNewFVG || - hasNewAnalyseOB || - hasNewAnalyseFVG) - { - // - XCFVG *newFVG = NULL; - XCOrderBlock *newOB = NULL; - XCFVG *newAnalyseFVG = NULL; - XCOrderBlock *newAnalyseOB = NULL; - - // - bool isValid = false; - bool hasWaitingZone = waitingZone.IsValid(); - - // - int idx = -1; - if (hasNewOB) - { - // - if (hasNewConsolidationBullishOB) - { - // - idx = consolidationState.CountBullishOrderBlocks() - 1; - newOB = consolidationState.bullishOrderBlocks[idx]; - } - else - { - // - idx = consolidationState.CountBearishOrderBlocks() - 1; - newOB = consolidationState.bearishOrderBlocks[idx]; - } - - // - if (hasWaitingZone) - { - } - else - { - // - isValid = - !waitingZone.HasOB() - ? true - : !IsSame( - newOB, - waitingZone.ob // - ); - if (isValid) - { - // - bool isAbove = IsAbove( - newOB, - youngestOrderFlow.ob, - true // Ignore Inside ... - ); - bool isBelow = IsBelow( - newOB, - youngestOrderFlow.ob, - true // Ignore Inside ... - ); - - // - isValid = - isBullish - ? isAbove - : isBelow; - - // - if (isValid) - { - waitingZone.ob = newOB; - } - } - } - } - - // - if (hasNewFVG) - { - // - if (hasNewConsolidationBullishFVG) - { - // - idx = consolidationState.CountBullishFairValueGaps() - 1; - newFVG = consolidationState.bullishFairValueGaps[idx]; - } - else - { - // - idx = consolidationState.CountBearishFairValueGaps() - 1; - newFVG = consolidationState.bearishFairValueGaps[idx]; - } - } - - // - if (hasNewAnalyseOB) - { - // - if (hasNewAnalyseBullishOrderBlock) - { - // - idx = analyseState.CountBullishOrderBlocks() - 1; - newAnalyseOB = analyseState.bullishOrderBlocks[idx]; - } - else - { - // - idx = analyseState.CountBearishOrderBlocks() - 1; - newAnalyseOB = analyseState.bearishOrderBlocks[idx]; - } - } - - // - if (hasNewAnalyseFVG) - { - // - if (hasNewAnalyseBullishFVG) - { - // - idx = analyseState.CountBullishFairValueGaps() - 1; - newAnalyseFVG = analyseState.bullishFairValueGaps[idx]; - } - else - { - // - idx = analyseState.CountBearishFairValueGaps() - 1; - newAnalyseFVG = analyseState.bearishFairValueGaps[idx]; - } - - // - if (hasWaitingZone) - { - } - else - { - // - if (waitingZone.HasOB()) - { - // - XCFVG *tmpFVGs[]; - XCFVG *tmpWorkingFVGs[]; - bool isOBBullish = waitingZone.ob.IsBullish(); - if (isOBBullish) - { - Copy( - analyseState.bullishFairValueGaps, - tmpFVGs // - ); - } - else - { - Copy( - analyseState.bearishFairValueGaps, - tmpFVGs // - ); - } - - // - for (int j = 0; j < ArraySize(tmpFVGs); j++) - { - // - XCFVG *jFVG = tmpFVGs[j]; - - // - // Check Start Date ... - bool isFromPassed = jFVG.From() > waitingZone.ob.From(); - if (!isFromPassed) - { - // - ZeroMemory(jFVG); - continue; - } - - // - // Check Place ... - - // - bool isAbove = IsAboveDiff( - jFVG, - waitingZone.ob, - true // - ); - - // - bool isBelow = IsBelowDiff( - jFVG, - waitingZone.ob, - true // - ); - - // - bool isInside = IsInsideDiff( - jFVG, - waitingZone.ob, - false // - ); - - // - bool isPlacePassed = - isInside || - (isBullish - ? isAbove - : isBelow); - if (!isPlacePassed) - { - // - ZeroMemory(jFVG); - continue; - } - - // - Add( - jFVG, - tmpWorkingFVGs // - ); - } - - // - int fvgsCount = ArraySize(tmpWorkingFVGs); - isValid = IsValidSize(fvgsCount); - if (isValid) - { - // - idx = - isBullish - ? GetLowest(tmpWorkingFVGs) - : GetHighest(tmpWorkingFVGs); - - // - if (IsValidIndex(idx)) - { - // - XCFVG *selectedFVG = tmpWorkingFVGs[idx]; - - // - waitingZone.fvg = selectedFVG; - - // - bool isExists = FindIndex( - idx, - selectedFVG, - tmpFVGs // - ); - if (isExists) - { - // - ArrayRemove( - tmpFVGs, - idx, - 1 // - ); - } - } - } - - // - Clean(tmpFVGs); - Clean(tmpWorkingFVGs); - } - } - } - - // - hasWaitingZone = waitingZone.IsValid(); - if (hasWaitingZone) - { - // - bool isSameDir = waitingZone.GetDirection() == trend; - if (!isSameDir) - { - targetZone = waitingZone; - } - else - { - workingZone.AddOrderFlowItem(waitingZone); - } - - // - waitingZone.Clean(); - } - - // - if (signalZone.IsValid() && - provider == X121SMC_XWZ_PROVIDER_ACTIVATED_CHOCH) - { - // - ENUM_X_DIRECTION iForDir = Opposit(signalZone.GetDirection()); - if (hasNewAnalyseOB && - hasNewAnalyseFVG) - { - // - bool isSameDir = - newAnalyseOB.GetDirection() == iForDir && - newAnalyseFVG.GetDirection() == iForDir; - bool isOneInsideAnoter = - // - (newAnalyseFVG.Upper() < newAnalyseOB.Upper() && - newAnalyseFVG.Upper() > newAnalyseOB.Lower()) - // - || - // - (newAnalyseOB.Upper() < newAnalyseFVG.Upper() && - newAnalyseOB.Upper() > newAnalyseFVG.Lower()) - // - ; - - // - bool isZoneDetected = - isSameDir && - isOneInsideAnoter; - if (isZoneDetected) - { - // - XOBFVG iSignalZone; - iSignalZone.ob = newAnalyseOB; - iSignalZone.fvg = newAnalyseFVG; - - // - chochZone = iSignalZone; - } - } - } - - // - ZeroMemory(newOB); - ZeroMemory(newFVG); - ZeroMemory(newAnalyseOB); - ZeroMemory(newAnalyseFVG); - } - - // - bool isPriceInsideCHOCHZone = false; - bool hasCHOCHZone = chochZone.IsValid(); - if (hasCHOCHZone) - { - // - XOHCL cBar; - bool isInited = cBar.Init( - symbol, - period, - cIndex // - ); - - // - isPriceInsideCHOCHZone = - isInited && - cBar.low >= chochZone.fvg.Lower() && - cBar.high <= chochZone.fvg.Upper(); - if (isPriceInsideCHOCHZone) - { - // - // Reverse Trend and ReCalculate Requirements - // For CHOCH Tradng ... - - // - trend = chochZone.GetDirection(); - - // - isBullish = IsBullish(trend); - isBearish = IsBearish(trend); - - // - bool hasPriority = workingZone - .DetectPriority( - priority, - trend, - zIndex, - period // - ); - - // - bool hasRewardAmount = CalculateRiskReward( - priority, - reward, - amountPercent // - ); - - // - provider = X121SMC_XWZ_PROVIDER_ACTIVATED_CHOCH; - } - - // - cBar.Clean(); - } - - // - // - // - - // - if (hasSupplyZones || - hasDemandZones) - { - // - UpdateTo(cTime); - DrawWorkingZone( - visionCycleHelper.mPOIDrawer // - ); - Print("CHECK ..."); - } - - // - // Reading Trand Line Value ... - double zValue = workingZone.GetOrderFlowTrendLinePrice( - zIndex, - period // - ); - double cValue = workingZone.GetOrderFlowTrendLinePrice( - cIndex, - period // - ); - double pValue = workingZone.GetOrderFlowTrendLinePrice( - pIndex, - period // - ); - double ppValue = workingZone.GetOrderFlowTrendLinePrice( - ppIndex, - period // - ); - - // - // Implementing Signals ... - // - - // - // TODO: Implement Order Flow Side Trading Senario ... - bool hasOrderFlowConditions = - hasTrend && - hasPriority && - hasRewardAmount && - signalZone.IsValid() && - provider == X121SMC_XWZ_PROVIDER_ACTIVATED_ZONE; - - // - hasOrderFlowhBullishConditions = - isBullish && - hasOrderFlowConditions && - signalZone.IsBullish(); - - // - hasOrderFlowhBearishConditions = - isBearish && - hasOrderFlowConditions && - signalZone.IsBearish(); - - // - if (hasOrderFlowConditions) - { - // - mConditions.signalZone = signalZone; - - // - point = hasOrderFlowhBullishConditions - ? signalZone.ob.Upper() - : signalZone.ob.Lower(); - - // - pivot = hasOrderFlowhBullishConditions - ? signalZone.ob.Lower() - : signalZone.ob.Upper(); - - // - signalZone.Clean(); - } - - // - // TODO: Implement Inside Zone Trading Senario ... - bool hasInsideZoneConditions = - hasTrend && - hasPriority && - hasRewardAmount && - signalZone.IsValid() && - provider == X121SMC_XWZ_PROVIDER_PRICE_INSIDE_ZONE; - - // - bool hasInsideZoneBullishConditions = - isBullish && - signalZone.IsBullish() && - hasInsideZoneConditions; - - // - bool hasInsideZoneBearishConditions = - isBearish && - signalZone.IsBearish() && - hasInsideZoneConditions; - - // - if (hasInsideZoneConditions) - { - // - mConditions.signalZone = signalZone; - - // - point = hasOrderFlowhBullishConditions - ? signalZone.ob.Upper() - : signalZone.ob.Lower(); - - // - pivot = hasOrderFlowhBullishConditions - ? signalZone.ob.Lower() - : signalZone.ob.Upper(); - - // - signalZone.Clean(); - } - - // - // TODO: Implement CHOCH Trading Senario ... - bool hasCHOCHConditions = - hasCHOCHZone && - chochZone.IsValid() && - isPriceInsideCHOCHZone && - provider == X121SMC_XWZ_PROVIDER_ACTIVATED_CHOCH; - - // - hasChochBullishConditions = - hasCHOCHConditions && - chochZone.IsBullish(); - hasChochBearishConditions = - hasCHOCHConditions && - chochZone.IsBearish(); - - // - if (hasCHOCHConditions) - { - // - mConditions.signalZone = chochZone; - - // - point = hasChochBullishConditions - ? chochZone.ob.Upper() - : chochZone.ob.Lower(); - - // - pivot = hasChochBearishConditions - ? chochZone.ob.Lower() - : chochZone.ob.Upper(); - - // - chochZone.Clean(); - signalZone.Clean(); - } - - // - // TODO: Implement Trend Line Trading Senario ... - - // - // TODO: Implement Quarter Line Trading Senario ... - - // - // TODO: Implement Supply and Demand Trading Senario ... - - // - // TODO: Implement Support and Resistance Trading Senario ... - - // - // TODO: Implement Mitigation Blocks Trading Senario ... - - // - // Summarize ... - - // - bool hasBullishConditions = - // - hasChochBullishConditions || - hasSupDemBullishConditions || - hasSupResBullishConditions || - hasTrendLineBullishConditions || - hasOrderFlowhBullishConditions || - hasInsideZoneBullishConditions || - hasBQuarterLineBullishConditions - // - ; - - // - bool hasBearishConditions = - // - hasChochBearishConditions || - hasSupDemBearishConditions || - hasSupResBearishConditions || - hasTrendLineBearishConditions || - hasOrderFlowhBearishConditions || - hasInsideZoneBearishConditions || - hasBQuarterLineBearishConditions - // - ; - - // - result = - hasBullishConditions || - hasBearishConditions; - - // - if (result) - { - // - mConditions.dir = trend; - mConditions.pivot = pivot; - mConditions.point = point; - mConditions.reward = reward; - mConditions.setupTime = cTime; - mConditions.priority = priority; - mConditions.provider = provider; - mConditions.amountPercent = amountPercent; - } - - // - // Cleanups ... - - // - Clean(visionPoiEvents); - Clean(analysePoiEvents); - Clean(decisionPoiEvents); - Clean(consolidationPoiEvents); - - // - Clean(visionCycleEvents); - Clean(analyseCycleEvents); - Clean(decisionCycleEvents); - Clean(consolidationCycleEvents); - - // - visionState.Clean(); - analyseState.Clean(); - decisionState.Clean(); - consolidationState.Clean(); - - // - visionConditions.Clean(); - analyseConditions.Clean(); - decisionConditions.Clean(); - consolidationConditions.Clean(); - - // - visionXConditions.Clean(); - analyseXConditions.Clean(); - decisionXConditions.Clean(); - consolidationXConditions.Clean(); - - // - // mConditions.Clean(); - consolidationZBar.Clean(); - - // - return result; - } - - // - // Detect Trigger Conditions ... - bool DetectSignalTrigger( - // - X121SMCStrategyXWZSignalConditions &conditions, - // - string _symbol, - ENUM_TIMEFRAMES _period, - // - XC121SMCCycleHelper *decisionCycleHelper, - XC121SMCCycleHelper *analyseCycleHelper, - XC121SMCCycleHelper *consolidationCycleHelper, - XC121SMCCycleHelper *visionCycleHelper, - // - int maxAllowedSetupAge = 60 - // - ) - { - // - bool result = false; - - // - result = - // - visionCycleHelper != NULL && - analyseCycleHelper != NULL && - decisionCycleHelper != NULL && - consolidationCycleHelper != NULL - // - ; - if (!result) - { - return result; - } - - // - result = conditions.IsSetuped(); - if (!result) - { - return result; - } - - // - datetime setupTime = conditions.setupTime; - ENUM_X_DIRECTION setupDir = conditions.dir; - - // - bool isBullish = IsBullish(setupDir); - bool isBearish = IsBearish(setupDir); - - // - int zIndex = 0; - int cIndex = zIndex + 1; - int pIndex = cIndex + 1; - int ppIndex = pIndex + 1; - - // - int loopback = 10; - - // - double ask = GetAsk(symbol); - double bid = GetBid(symbol); - datetime cTime = TimeCurrent(); - double points = GetPoints(symbol); - - // - double sls[]; - - // - // Cycles Conditions ... - - // - // Decision ... - ENUM_XPOI_EVENTS decisionPoiEvents[]; - ENUM_X_CYCLE_EVENTS decisionCycleEvents[]; - X121SMCCycleConditions decisionConditions; - result = decisionCycleHelper.GetConditions( - decisionCycleEvents, - decisionPoiEvents, - decisionConditions, - zIndex, - loopback // - ); - if (!result) - { - // - // Cleanup ... - - // - Clean(decisionPoiEvents); - Clean(decisionCycleEvents); - - // - decisionConditions.Clean(); - - // - return result; - } - - // - // Analyse ... - ENUM_XPOI_EVENTS analysePoiEvents[]; - ENUM_X_CYCLE_EVENTS analyseCycleEvents[]; - X121SMCCycleConditions analyseConditions; - result = analyseCycleHelper.GetConditions( - analyseCycleEvents, - analysePoiEvents, - analyseConditions, - zIndex, - loopback // - ); - if (!result) - { - // - Clean(analysePoiEvents); - Clean(decisionPoiEvents); - - // - Clean(analyseCycleEvents); - Clean(decisionCycleEvents); - - // - analyseConditions.Clean(); - decisionConditions.Clean(); - - // - return result; - } - - // - // Cycles POI States ... - XPOIState decisionState = decisionConditions.state; - XPOIState analyseState = analyseConditions.state; - - // - // Cycle X121Conditions ... - X121Conditions decisionXConditions = decisionConditions.x121Conditions; - X121Conditions analyseXConditions = analyseConditions.x121Conditions; - - // - // Check Signal Validation ... - - // - XOHCL cBar; - bool isInited = cBar.Init( - conditions.symbol, - conditions.period, - cIndex // - ); - XOHCL pBar; - isInited = - isInited && - cBar.GetPreviousBar(pBar); - bool isLowerBreaked = - // - isInited && - cBar.high < conditions.point && - pBar.high >= conditions.point - // - ; - bool isUpperBreaked = - // - isInited && - cBar.low > conditions.point && - pBar.low <= conditions.point - // - ; - bool isZoneBreaked = - (isBullish && - isLowerBreaked) || - (isBearish && - isUpperBreaked); - result = !isZoneBreaked; - if (!result) - { - // - cBar.Clean(); - pBar.Clean(); - conditions.Clean(); - - // - Clean(decisionPoiEvents); - Clean(decisionCycleEvents); - - // - decisionState.Clean(); - decisionConditions.Clean(); - decisionXConditions.Clean(); - - // - Clean(analysePoiEvents); - Clean(analyseCycleEvents); - - // - analyseState.Clean(); - analyseConditions.Clean(); - analyseXConditions.Clean(); - } - - // - cBar.Clean(); - pBar.Clean(); - - // - double bullishScore = 0; - double bearishScore = 0; - decisionXConditions.GenerateScore( - bullishScore, - bearishScore // - ); - bool isBullishScorePassed = - isBullish && - bullishScore > (bearishScore * 1.5); - bool isBearishScorePassed = - isBearish && - bearishScore > (bullishScore * 1.5); - bool isScorePassed = isBullishScorePassed || - isBearishScorePassed; - - // - // Base SL Used Pivot of Conditions ... - // Add( - // conditions.pivot, - // sls // - // ); - - // - int lowestSupportIDX = -1; - int highestResistanceIDX = -1; - bool isSupportRejected = false; - bool isResistanceRejected = false; - bool hasSignalZone = conditions.signalZone.IsValid(); - if (hasSignalZone) - { - // - conditions - .signalZone - .UpdateZones(decisionState); - conditions - .signalZone - .UpdateTo(cTime); - - // - XOHCL cBar; - bool isBarInited = cBar.Init( - conditions.symbol, - conditions.period, - cIndex // - ); - - // - lowestSupportIDX = GetLowest(conditions.signalZone.supportZones); - if (IsValidIndex(lowestSupportIDX)) - { - // - isSupportRejected = - // - isBarInited && - ( - // - (cBar.low < conditions.signalZone.supportZones[lowestSupportIDX].Upper() && - cBar.GetDown() > conditions.signalZone.supportZones[lowestSupportIDX].Upper()) - // - || - // - (cBar.low < conditions.signalZone.supportZones[lowestSupportIDX].Lower() && - cBar.GetDown() > conditions.signalZone.supportZones[lowestSupportIDX].Lower()) - // - ) - // - ; - - // - isSupportRejected = - isBullish && - isSupportRejected; - if (isSupportRejected) - { - // - double vPivot = conditions.signalZone.supportZones[lowestSupportIDX].Lower(); - bool canSetPivot = vPivot > conditions.pivot && - vPivot < conditions.point; - if (canSetPivot) - { - // - Add( - vPivot, - sls // - ); - } - } - } - - // - highestResistanceIDX = GetHighest(conditions.signalZone.resistanceZones); - if (IsValidIndex(highestResistanceIDX)) - { - // - isResistanceRejected = - // - isBarInited && - ( - // - (cBar.high > conditions.signalZone.resistanceZones[highestResistanceIDX].Upper() && - cBar.GetUp() < conditions.signalZone.resistanceZones[highestResistanceIDX].Upper()) - // - || - // - (cBar.high > conditions.signalZone.resistanceZones[highestResistanceIDX].Lower() && - cBar.GetUp() < conditions.signalZone.resistanceZones[highestResistanceIDX].Lower()) - // - ) - // - ; - - // - isResistanceRejected = - isBearish && - isResistanceRejected; - if (isResistanceRejected) - { - // - double vPivot = conditions.signalZone.resistanceZones[highestResistanceIDX].Upper(); - bool canSetPivot = vPivot < conditions.pivot && - vPivot > conditions.point; - if (canSetPivot) - { - // - Add( - vPivot, - sls // - ); - } - } - } - - // - cBar.Clean(); - } - - // - // Consolidation Zone Detection ... - - // - // Detect Consolidation Zones ... - - // - // Bullish Consolidation Zone ... - XConsolidationZone bullishCZones[]; - bool hasBullishConsolidationZone = false; - XConsolidationZone bullishConsolidationZone; - int bullishCZonesCount = decisionCycleHelper.FillConsolidationZones( - X_DIRECTION_BULLISH, - bullishCZones // - ); - bool hasBullishConsolidationZones = IsValidSize(bullishCZonesCount); - if (hasBullishConsolidationZones) - { - // - int idx = -1; - while (HasChild(bullishCZones)) - { - // - idx = GetYoungest(bullishCZones); - hasBullishConsolidationZone = IsValidIndex(idx); - if (hasBullishConsolidationZone) - { - // - bullishConsolidationZone = bullishCZones[idx]; - - // - ArrayRemove( - bullishCZones, - idx, - 1 // - ); - - // - // Check Zone Based On pivot, since this is the SL ... - hasBullishConsolidationZone = - isBullish && - hasBullishConsolidationZone && - bullishConsolidationZone.lower > conditions.pivot && - bullishConsolidationZone.upper <= conditions.point; - if (hasBullishConsolidationZone) - { - // - Add( - bullishConsolidationZone.lower, - sls // - ); - } - } - } - } - Clean(bullishCZones); - bullishConsolidationZone.Clean(); - - // - // Bearish Consolidation Zone ... - XConsolidationZone bearishCZones[]; - bool hasBearishConsolidationZone = false; - XConsolidationZone bearishConsolidationZone; - int bearishCZonesCount = decisionCycleHelper.FillConsolidationZones( - X_DIRECTION_BEARISH, - bearishCZones // - ); - bool hasBearishConsolidationZones = IsValidSize(bearishCZones); - if (hasBearishConsolidationZones) - { - // - int idx = -1; - while (HasChild(bearishCZones)) - { - // - idx = GetYoungest(bearishCZones); - hasBearishConsolidationZone = IsValidIndex(idx); - if (hasBearishConsolidationZone) - { - // - bearishConsolidationZone = bearishCZones[idx]; - - // - ArrayRemove( - bearishCZones, - idx, - 1 // - ); - - // - hasBearishConsolidationZone = - isBearish && - hasBearishConsolidationZone && - bearishConsolidationZone.upper < conditions.pivot && - bearishConsolidationZone.lower >= conditions.point; - if (hasBearishConsolidationZone) - { - // - Add( - bearishConsolidationZone.upper, - sls // - ); - } - } - } - } - Clean(bearishCZones); - bearishConsolidationZone.Clean(); - - // - // Check VWap Crossing ... - - // - bool isVWapSwitchedToBullish = - // - (decisionXConditions.isVWapBullishOrdered && - decisionXConditions.isVWapSwitchedToBullishState) - // - || - // - (decisionXConditions.isVWapBullishState && - decisionXConditions.isVWapSwitchedToBullishOrdered) - // - ; - - // - isVWapSwitchedToBullish = - isBullish && - isVWapSwitchedToBullish; - if (isVWapSwitchedToBullish) - { - // - double vPivot = decisionXConditions.vwapMin; - bool canSetPivot = vPivot > conditions.pivot && - vPivot < conditions.point; - if (canSetPivot) - { - // - Add( - vPivot, - sls // - ); - } - } - - // - bool isVWapSwitchedToBearish = - // - (decisionXConditions.isVWapBearishOrdered && - decisionXConditions.isVWapSwitchedToBearishState) - // - || - // - (decisionXConditions.isVWapBearishState && - decisionXConditions.isVWapSwitchedToBearishOrdered) - // - ; - - // - isVWapSwitchedToBearish = - isBearish && - isVWapSwitchedToBearish; - if (isVWapSwitchedToBearish) - { - // - double vPivot = decisionXConditions.vwapMax; - bool canSetPivot = vPivot < conditions.pivot && - vPivot > conditions.point; - if (canSetPivot) - { - // - Add( - vPivot, - sls // - ); - } - } - - // - // Point Break ... - isInited = cBar.Init( - conditions.symbol, - conditions.period, - cIndex // - ); - double point = conditions.point; - bool isPointBreaked = - isInited && - IsBarBreak( - point, - setupDir, - cBar // - ); - cBar.Clean(); - - // - bool isCommonsPassed = - // - (isSupportRejected || - isResistanceRejected || - isVWapSwitchedToBullish || - isVWapSwitchedToBearish || - hasBullishConsolidationZone || - hasBearishConsolidationZone) - // - ; - - // - // Trigger Conditions ... - - // - bool canTriggerCHOCHZone = - // - isScorePassed && - isCommonsPassed && - conditions.provider == X121SMC_XWZ_PROVIDER_ACTIVATED_CHOCH - // - ; - - // - bool canTriggerActivatedZone = - // - // isPointBreaked && - isScorePassed && - isCommonsPassed && - conditions.provider == X121SMC_XWZ_PROVIDER_ACTIVATED_ZONE - // - ; - - // - bool canTriggerPriceInsideZone = - // - isScorePassed && - isCommonsPassed && - conditions.provider == X121SMC_XWZ_PROVIDER_PRICE_INSIDE_ZONE - // - ; - - // - bool canTrigger = (canTriggerCHOCHZone || - canTriggerActivatedZone || - canTriggerPriceInsideZone); - - // - // Summary ... - - // - isBullish = - // - isBullish && - canTrigger - // - ; - - // - isBearish = - // - isBearish && - canTrigger - // - ; - - // - result = isBullish || - isBearish; - if (!result) - { - // - // Cleanup Setup Conditions ... - int setupAge = conditions.GetSetupAge(); - if (IsValidSize(setupAge) && - IsValidSize(maxAllowedSetupAge) && - setupAge >= maxAllowedSetupAge) - { - conditions.Clean(); - } - - // - // Cleanup ... - - // - cBar.Clean(); - pBar.Clean(); - - // - Clean(decisionPoiEvents); - Clean(decisionCycleEvents); - - // - decisionState.Clean(); - decisionConditions.Clean(); - decisionXConditions.Clean(); - - // - Clean(analysePoiEvents); - Clean(analyseCycleEvents); - - // - analyseState.Clean(); - analyseConditions.Clean(); - analyseXConditions.Clean(); - - // - return result; - } - - // - double entry = GetEntry( - conditions.symbol, - setupDir // - ); - - // - // Manipulate SL Based on Consolidation Zones ... - - // - double iAtr = decisionXConditions.atrBuffer[1]; - iAtr *= 1.5; - - // - // Since Pivot Value almost used - // as Default SL, if there isn't any Refind SL - // we use Default ... - if (!HasChild(sls)) - { - // - Add( - conditions.pivot, - sls // - ); - } - - // - double slsMin = GetMin(sls); - double slsMax = GetMax(sls); - - // - double sl = isBullish - ? slsMin - iAtr - : slsMax + iAtr; - double risk = MathAbs(entry - sl); - - // - // Filling Conditions Props ... - conditions.sl = sl; - conditions.triggerTime = cTime; - conditions.type = isBullish - ? X_POSITION_TYPE_LONG - : X_POSITION_TYPE_SHORT; - - // - // Checking Targets ... - - // - ENUM_X121SMC_XWZ_PRIORITY priority = X121SMC_XWZ_PRIORITY_NONE; - bool hasPriority = workingZone - .DetectPriority( - priority, - setupDir, - zIndex, - decisionState.period // - ); - - // - // Order Block Targets ... - - // - XCOrderBlock *bullishOBs[]; - Copy( - analyseState.bullishOrderBlocks, - bullishOBs // - ); - - // - // Extract Available Order Blocks ... - int bullishOBsCont = FilterZones( - // - bullishOBs, - // - X_DIRECTION_BULLISH, - analyseState.period, - NULL, - // - // Start ... - XZONE_STATE_IGNORED, - false, - // - // Activation ... - XZONE_STATE_IGNORED, - false, - // - // Breake ... - XZONE_STATE_FAILED, - false, - // - // Work ... - XZONE_STATE_IGNORED, - false, - // - true, // Apply Sore ... - true // Ignore Inside ... - ); - bool hasBullishOBs = HasChild(bullishOBs); - - // - XCOrderBlock *bearishOBs[]; - Copy( - analyseState.bearishOrderBlocks, - bearishOBs // - ); - - // - // Extract Available Order Blocks ... - int bearishOBsCont = FilterZones( - // - bearishOBs, - // - X_DIRECTION_BEARISH, - analyseState.period, - NULL, - // - // Start ... - XZONE_STATE_IGNORED, - false, - // - // Activation ... - XZONE_STATE_IGNORED, - false, - // - // Breake ... - XZONE_STATE_FAILED, - false, - // - // Work ... - XZONE_STATE_IGNORED, - false, - // - true, // Apply Sore ... - true // Ignore Inside ... - ); - bool hasBearishOBs = HasChild(bearishOBs); - - // - if (isBullish && - hasBearishOBs) - { - // - int count = ArraySize(bearishOBs); - for (int i = 0; i < count; i++) - { - // - XCBaseObject *iObj; - bool isCreated = visionCycleHelper - .mPOIDrawer - .CreateOrderBlock( - bearishOBs[i], - iObj // - ); - if (isCreated) - { - mObjects.Add(iObj); - } - - // - double value = bearishOBs[i].Lower(); - bool canSet = value > entry; - if (canSet) - { - // - Add( - value, - conditions.targets // - ); - } - } - } - - // - if (isBearish && - hasBullishOBs) - { - // - int count = ArraySize(bullishOBs); - for (int i = 0; i < count; i++) - { - // - XCBaseObject *iObj; - bool isCreated = visionCycleHelper - .mPOIDrawer - .CreateOrderBlock( - bullishOBs[i], - iObj // - ); - if (isCreated) - { - mObjects.Add(iObj); - } - - // - double value = bullishOBs[i].Upper(); - bool canSet = value < entry; - if (canSet) - { - // - Add( - value, - conditions.targets // - ); - } - } - } - - // - Clean(bullishOBs); - Clean(bearishOBs); - - // - // Detect Quarter Targets ... - - // - double quarterTarget = 0; - if (hasPriority) - { - // - switch (priority) - { - // - case X121SMC_XWZ_PRIORITY_WEAK: - // - quarterTarget = - isBullish - ? workingZone.supplyZone.Lower() - : workingZone.demandZone.Upper(); - break; - - // - case X121SMC_XWZ_PRIORITY_LOW: - // - quarterTarget = - isBullish - ? workingZone.quarter1 - : workingZone.quarter3; - break; - - // - case X121SMC_XWZ_PRIORITY_REGULAR: - // - quarterTarget = - isBullish - ? workingZone.quarter2 - : workingZone.quarter2; - break; - - // - case X121SMC_XWZ_PRIORITY_HIGH: - // - quarterTarget = - isBullish - ? workingZone.quarter3 - : workingZone.quarter1; - break; - - // - case X121SMC_XWZ_PRIORITY_STRONG_HIGH: - // - quarterTarget = - isBullish - ? workingZone.demandZone.Upper() - : workingZone.supplyZone.Lower(); - break; - } - } - - // - if (quarterTarget > 0) - { - // - Add( - quarterTarget, - conditions.targets // - ); - } - - // - // Cleanup ... - - // - cBar.Clean(); - pBar.Clean(); - - // - Clean(decisionPoiEvents); - Clean(decisionCycleEvents); - - // - decisionState.Clean(); - decisionConditions.Clean(); - decisionXConditions.Clean(); - - // - Clean(analysePoiEvents); - Clean(analyseCycleEvents); - - // - analyseState.Clean(); - analyseConditions.Clean(); - analyseXConditions.Clean(); - - // - return result; - } - - // - // Detect Guards ... - bool DetectGuards( - // - X121SMCGuard &guards[], - const XPosition &positions[], - // - XC121SMCCycleHelper *decisionCycleHelper, - XC121SMCCycleHelper *analyseCycleHelper, - XC121SMCCycleHelper *consolidationCycleHelper, - XC121SMCCycleHelper *visionCycleHelper - // - ) - { - // - bool result = false; - - // - Clean(guards); - - // - bool isCycleHelpersValid = - // - visionCycleHelper != NULL && - analyseCycleHelper != NULL && - decisionCycleHelper != NULL && - consolidationCycleHelper != NULL - // - ; - - // - return false; - - // - result = isCycleHelpersValid; - if (!result) - { - return result; - } - - // - int count = ArraySize(positions); - result = IsValidSize(count); - if (!result) - { - return result; - } - - // - string provider = ToString(X_121_SMC_PROVIDER_XWZ); - - // - XPosition ownPositions[]; - XPosition ownLongPositions[]; - XPosition ownShortPositions[]; - for (int i = 0; i < count; i++) - { - // - XPosition iPosition = positions[i]; - bool isOwn = iPosition - .IsFiltersPassed( - symbol, - provider, - NULL, - X_POSITION_TYPE_ALL, - iPosition.magic // - ); - if (isOwn) - { - // - AddRef( - iPosition, - ownPositions // - ); - - // - bool isLong = IsLong(positions[i].type); - if (isLong) - { - // - AddRef( - iPosition, - ownLongPositions // - ); - } - else - { - // - AddRef( - iPosition, - ownShortPositions // - ); - } - } - } - - // - count = ArraySize(ownPositions); - - // - int longsCount = ArraySize(ownLongPositions); - bool hasLongs = IsValidSize(longsCount); - - // - int shortsCount = ArraySize(ownShortPositions); - bool hasShorts = IsValidSize(shortsCount); - - // - result = IsValidSize(count); - if (!result) - { - // - Clean(ownPositions); - Clean(ownLongPositions); - Clean(ownShortPositions); - - // - return result; - } - - // - // - // - - // - // Get Global and Common Guards ... - - // - ENUM_X_121_SMC_GUARD_ACTIONS ignoreGuards[1] = { - X_121_SMC_GUARD_ACTION_TRAIL_STOP // - }; - result = DetectX121SMCGuards( - provider, - guards, - positions, - decisionCycleHelper, - analyseCycleHelper, - consolidationCycleHelper, - visionCycleHelper, - // - ignoreGuards - // - ); - - // - // - // - - // - // Get Custom Implemented Guards ... - - // - // Here we Are Sure there is Positions to Guard ... - // based on Current Provider ... - - // - // Detect Required Data for Analyse Market to Guard Positions ... - - // - int zIndex = 0; - int cIndex = zIndex + 1; - int pIndex = cIndex + 1; - int ppIndex = pIndex + 1; - - // - int loopback = 10; - - // - 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 ... - - // - // Decision ... - ENUM_XPOI_EVENTS decisionPoiEvents[]; - ENUM_X_CYCLE_EVENTS decisionCycleEvents[]; - X121SMCCycleConditions decisionConditions; - result = decisionCycleHelper.GetConditions( - decisionCycleEvents, - decisionPoiEvents, - decisionConditions, - zIndex, - loopback // - ); - if (!result) - { - // - zBar.Clean(); - cBar.Clean(); - pBar.Clean(); - ppBar.Clean(); - result = HasChild(guards); - return result; - } - - // - // Analyse ... - ENUM_XPOI_EVENTS analysePoiEvents[]; - ENUM_X_CYCLE_EVENTS analyseCycleEvents[]; - X121SMCCycleConditions analyseConditions; - result = analyseCycleHelper.GetConditions( - analyseCycleEvents, - analysePoiEvents, - analyseConditions, - zIndex, - loopback // - ); - if (!result) - { - // - 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); - - // - decisionConditions.Clean(); - - // - Clean(analysePoiEvents); - Clean(analyseCycleEvents); - - // - analyseConditions.Clean(); - - // - result = HasChild(guards); - return result; - } - - // - // Vision ... - ENUM_XPOI_EVENTS visionPoiEvents[]; - ENUM_X_CYCLE_EVENTS visionCycleEvents[]; - X121SMCCycleConditions visionConditions; - result = visionCycleHelper.GetConditions( - visionCycleEvents, - visionPoiEvents, - visionConditions, - zIndex, - loopback // - ); - if (!result) - { - // - zBar.Clean(); - cBar.Clean(); - pBar.Clean(); - ppBar.Clean(); - - // - Clean(decisionPoiEvents); - Clean(decisionCycleEvents); - - // - decisionConditions.Clean(); - - // - Clean(analysePoiEvents); - Clean(analyseCycleEvents); - - // - analyseConditions.Clean(); - - // - Clean(consolidationPoiEvents); - Clean(consolidationCycleEvents); - - // - consolidationConditions.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; - - // - // Cycle X121Conditions ... - X121Conditions decisionXConditions = decisionConditions.x121Conditions; - X121Conditions analyseXConditions = analyseConditions.x121Conditions; - X121Conditions consolidationXConditions = consolidationConditions.x121Conditions; - X121Conditions visionXConditions = visionConditions.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 // - ); - - // - // 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; - - // - // Here We Have all Requirements for Guarding Positions ... - - // - // Available Guards: - // X_121_SMC_GUARD_ACTION_NONE - // X_121_SMC_GUARD_ACTION_CLOSE - // X_121_SMC_GUARD_ACTION_CLOSE_ALL - // X_121_SMC_GUARD_ACTION_CLOSE_LONGS - // X_121_SMC_GUARD_ACTION_CLOSE_SHORTS - // X_121_SMC_GUARD_ACTION_PARTIAL_CLOSE - // X_121_SMC_GUARD_ACTION_TRAIL_STOP - // X_121_SMC_GUARD_ACTION_TRAIL_TARGET - // X_121_SMC_GUARD_ACTION_HEDGE - - // - // X_121_SMC_GUARD_ACTION_CLOSE: - // Close Specified Position on Specified Conditions ... - - // - // X_121_SMC_GUARD_ACTION_CLOSE_ALL: - // Close All Positions on Specified Conditions ... - - // - // X_121_SMC_GUARD_ACTION_CLOSE_LONGS: - // Close All Long Positions on Specified Conditions ... - - // - // X_121_SMC_GUARD_ACTION_CLOSE_SHORTS: - // Close All Short Positions on Specified Conditions ... - - // - // X_121_SMC_GUARD_ACTION_PARTIAL_CLOSE: - // Partial Close Specified Position on Specified Conditions ... - - // - // X_121_SMC_GUARD_ACTION_TRAIL_STOP: - // Trail Stop Specified Position on Specified Conditions ... - for (int i = 0; i < count; i++) - { - // - XPosition iPosition = ownPositions[i]; - - // - bool isLong = IsLong(iPosition.type); - bool isInProfit = iPosition.profit > 0; - - // - double sl = iPosition.sl; - double tp = iPosition.tp; - - // - // Trail Stops Using Consolidation Zones ... - bool canTraiLonglUsingCZone = - // - (isLong && - isInProfit && - hasBullishConsolidationZone && - bullishConsolidationZone.lower > iPosition.sl && - bullishConsolidationZone.lower > iPosition.entry) - // - ; - if (canTraiLonglUsingCZone) - { - sl = bullishConsolidationZone.lower; - } - - // - bool canTraiShortlUsingCZone = - // - (!isLong && - isInProfit && - hasBearishConsolidationZone && - bearishConsolidationZone.upper < iPosition.sl && - bearishConsolidationZone.upper < iPosition.entry) - // - ; - if (canTraiShortlUsingCZone) - { - sl = bearishConsolidationZone.upper; - } - - // - bool canTrailUsingCZone = - canTraiLonglUsingCZone || - canTraiShortlUsingCZone; - - // - // 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; - - // - // - // - - // - bool canTrail = - sl != iPosition.sl && - (canTrailUsingCZone || - canTrailUsingSwings); - if (canTrail) - { - // - X121SMCGuard iGuard; - - // - iGuard.time = cTime; - iGuard.symbol = symbol; - iGuard.provider = provider; - iGuard.action = X_121_SMC_GUARD_ACTION_TRAIL_STOP; - - // - iGuard.ticket = iPosition.ticket; - - // - iGuard.sl = sl; - - // - AddGuard( - iGuard, - guards // - ); - } - } - - // - // X_121_SMC_GUARD_ACTION_TRAIL_TARGET: - // Trail Target Specified Position on Specified Conditions ... - - // - // X_121_SMC_GUARD_ACTION_HEDGE: - // Hedge all Positions on Specified Conditions ... - - // - // Cleanup Collections ... - - // - Clean(ownPositions); - Clean(ownLongPositions); - Clean(ownShortPositions); - - // - zBar.Clean(); - cBar.Clean(); - pBar.Clean(); - ppBar.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(); - - // - count = ArraySize(guards); - result = IsValidSize(count); - - // - return result; - } - - // - // Add Conditions to Conditions Collection ... - int AddConditionsIfNotExists( - int maxAllowed = 10 // - ) - { - // - int result = 0; - - // - bool isSetuped = IsValid(mConditions.setupTime) && - HasDirection(mConditions.dir); - if (!isSetuped) - { - return result; - } - - // - int count = ArraySize(mConditionsCollection); - if (IsValidSize(count)) - { - // - // Copy Original Items ... - X121SMCStrategyXWZSignalConditions tmpItems[]; - Copy( - mConditionsCollection, - tmpItems // - ); - - // - // Prese Item Data ... - bool isBullish = IsBullish(mConditions.dir); - - // - for (int i = 0; i < count; i++) - { - // - X121SMCStrategyXWZSignalConditions iItem = tmpItems[i]; - - // - bool canRemove = mConditions.dir == iItem.dir && - mConditions.pivot == iItem.pivot; - if (canRemove) - { - // - ArrayRemove( - mConditionsCollection, - i, - 1 // - ); - } - } - - // - Clean(tmpItems); - } - - // - AddRef( - mConditions, - mConditionsCollection // - ); - - // - // Remove Olds ... - CleanupArray( - mConditionsCollection, - maxAllowed // - ); - - // - result = ArraySize(mConditionsCollection); - - // - return result; - } - - // - bool DetectWorkingZone( - XPOIState <fState // - ) - { - // - bool result = false; - - // - result = IsValid(symbol) && - IsValid(period); - if (!result) - { - return result; - } - - // - result = !workingZone.IsValid(); - if (!result) - { - return result; - } - - // - workingZone.symbol = symbol; - workingZone.period = period; - - // - int idx = -1; - bool has = false; - - // - has = ltfState.HasSupplyZones(); - if (has) - { - // - idx = GetHighest(ltfState.supplyZones); - if (IsValidIndex(idx)) - { - workingZone.supplyZone = ltfState.supplyZones[idx]; - } - } - - // - has = ltfState.HasDemandZones(); - if (has) - { - // - idx = GetLowest(ltfState.demandZones); - if (IsValidIndex(idx)) - { - workingZone.demandZone = ltfState.demandZones[idx]; - } - } - - // - bool hasWorkingZone = workingZone.HasSupplyZone() && - workingZone.HasDemandZone(); - if (hasWorkingZone) - { - // - double upper = workingZone.supplyZone.Lower(); - double lower = workingZone.demandZone.Upper(); - - // - double delta = ((upper - lower) / 100) * 25; - - // - workingZone.quarter1 = upper - (1 * delta); - workingZone.quarter2 = upper - (2 * delta); - workingZone.quarter3 = upper - (3 * delta); - - // - hasWorkingZone = workingZone.IsValid(); - } - - // - result = hasWorkingZone; - - // - return result; - } - - // - // Draw Functions ... - // - - // - void RemoveDraws() - { - mObjects.Clear(); - } - - // - void DrawBar( - XOHCL &bar, - XCPOIDrawer *drawer, - bool forceClean = true // - ) - { - // - if (forceClean) - { - mBarObjects.Clear(); - } - - // - if (drawer == NULL || - !bar.IsValid()) - { - return; - } - - // - bool isBullish = bar.IsBullish(); - - // - int widthBar = 2; - bool fillShadowsBar = true; - ENUM_LINE_STYLE styleBar = STYLE_SOLID; - color clrBar = - isBullish - ? clrAqua - : clrMagenta; - - // - datetime to = bar.NextAt(); - - // - XCOHCLObject *iObj; - bool isCreated = drawer - .CreateBar( - bar, - iObj, - to // - ); - if (isCreated) - { - // - iObj.BarSpes( - widthBar, - clrBar, - styleBar // - ); - - // - iObj.LowShadowFill(fillShadowsBar); - iObj.HighShadowFill(fillShadowsBar); - - // - mBarObjects.Add(iObj); - } - } - - // - void DrawWorkingZone( - XCPOIDrawer *drawer, - bool drawTrendLine = true, - bool forceClean = false // - ) - { - // - if (drawer == NULL) - { - return; - } - - // - if (forceClean) - { - mWorkingZoneObjects.Clear(); - } - - // - int count = 0; - bool has = false; - bool isCreated = false; - - // - ulong chartID = drawer.ChartIdentification(); - int subWindow = drawer.SubWindowIdentification(); - color bullishColor = drawer.BarBullishColor(); - color bearishColor = drawer.BarBearishColor(); - - // - // Supply Zone ... - has = workingZone.HasSupplyZone(); - if (has) - { - // - XCSupplyZoneObject *iObj; - isCreated = drawer.CreateSupplyZone( - workingZone.supplyZone, - iObj // - ); - - // - if (isCreated) - { - mWorkingZoneObjects.Add(iObj); - } - } - - // - has = workingZone.HasSupplyZones(); - if (has) - { - // - count = workingZone.CountSupplyZones(); - for (int i = 0; i < count; i++) - { - // - XCSupplyZoneObject *iObj; - isCreated = drawer.CreateSupplyZone( - workingZone.supplyZones[i], - iObj // - ); - - // - if (isCreated) - { - mWorkingZoneObjects.Add(iObj); - } - } - } - - // - // Demand Zone ... - has = workingZone.HasDemandZone(); - if (has) - { - // - XCDemandZoneObject *iObj; - isCreated = drawer.CreateDemandZone( - workingZone.demandZone, - iObj // - ); - - // - if (isCreated) - { - mWorkingZoneObjects.Add(iObj); - } - } - - // - has = workingZone.HasDemandZones(); - if (has) - { - // - count = workingZone.CountDemandZones(); - for (int i = 0; i < count; i++) - { - // - XCDemandZoneObject *iObj; - isCreated = drawer.CreateDemandZone( - workingZone.demandZones[i], - iObj // - ); - - // - if (isCreated) - { - mWorkingZoneObjects.Add(iObj); - } - } - } - - // - // Quarters ... - has = workingZone.IsValid(); - if (has) - { - // - double zoneUpper = workingZone.supplyZone.Upper(); - double upper = workingZone.supplyZone.Lower(); - - // - double lower = workingZone.demandZone.Upper(); - double zoneLower = workingZone.demandZone.Lower(); - - // - string prefix = "X121WZone_" + workingZone.symbol + "_" + ToString(workingZone.period); - - // - // Zone Upper ... - CChartObjectHLine *zoneUpperLine; - zoneUpperLine = new CChartObjectHLine(); - isCreated = zoneUpperLine.Create( - chartID, - prefix + "_ZoneTop", - subWindow, - zoneUpper // - ); - if (isCreated) - { - // - zoneUpperLine.Color(clrRed); - - // - mWorkingZoneObjects.Add(zoneUpperLine); - } - - // - // Zone Lower ... - CChartObjectHLine *zoneLowerLine; - zoneLowerLine = new CChartObjectHLine(); - isCreated = zoneLowerLine.Create( - chartID, - prefix + "_ZoneDown", - subWindow, - zoneLower // - ); - if (isCreated) - { - // - zoneLowerLine.Color(clrRed); - - // - mWorkingZoneObjects.Add(zoneLowerLine); - } - - // - // Upper ... - CChartObjectHLine *upperLine; - upperLine = new CChartObjectHLine(); - isCreated = upperLine.Create( - chartID, - prefix + "_Upper", - subWindow, - upper // - ); - if (isCreated) - { - // - upperLine.Color(clrLime); - - // - mWorkingZoneObjects.Add(upperLine); - } - - // - // Lower ... - CChartObjectHLine *lowerLine; - lowerLine = new CChartObjectHLine(); - isCreated = lowerLine.Create( - chartID, - prefix + "_Lower", - subWindow, - lower // - ); - if (isCreated) - { - // - lowerLine.Color(clrLime); - - // - mWorkingZoneObjects.Add(lowerLine); - } - - // - // Quarters ... - - // - // Quarter 1 ... - CChartObjectHLine *q1Line; - q1Line = new CChartObjectHLine(); - isCreated = q1Line.Create( - chartID, - prefix + "_Q1", - subWindow, - workingZone.quarter1 // - ); - if (isCreated) - { - // - q1Line.Color(clrYellow); - - // - mWorkingZoneObjects.Add(q1Line); - } - - // - // Quarter 2 ... - CChartObjectHLine *q2Line; - q2Line = new CChartObjectHLine(); - isCreated = q2Line.Create( - chartID, - prefix + "_Q2", - subWindow, - workingZone.quarter2 // - ); - if (isCreated) - { - // - q2Line.Color(clrYellow); - - // - mWorkingZoneObjects.Add(q2Line); - } - - // - // Quarter 3 ... - CChartObjectHLine *q3Line; - q3Line = new CChartObjectHLine(); - isCreated = q3Line.Create( - chartID, - prefix + "_Q3", - subWindow, - workingZone.quarter3 // - ); - if (isCreated) - { - // - q3Line.Color(clrYellow); - - // - mWorkingZoneObjects.Add(q3Line); - } - } - - // - // Draw Order Flow ... - ENUM_X_DIRECTION trend; - has = workingZone.HasOrderFlow(trend); - if (has) - { - // - bool isBullish = IsBullish(trend); - - // - count = workingZone.CountOrderFlow(); - for (int i = 0; i < count; i++) - { - // - XOBFVG iOBFVG = workingZone.orderFlow[i]; - - // - XCBaseObject *drawnObjects[]; - int drawnObjectsCount = drawer - .DrawOBFVG( - // - iOBFVG, - drawnObjects, - // - true, // Draw Order Block ... - true, // Draw Fair Value Gap ... - false, // Draw Supply Zones ... - false, // Draw Demand Zones ... - false, // Draw Support Zones ... - false // Draw Resistance Zones ... - ); - if (IsValidSize(drawnObjectsCount)) - { - AddDrawnWorkingZoneObjects(drawnObjects); - } - } - - // - // Draw Trend Line ... - if (drawTrendLine) - { - // - XOBFVGPivot pivots[]; - count = workingZone.GetSwings(pivots); - has = count >= 2; - if (has) - { - // - // Get Max / Min ... - double max = 0; - double min = 0; - datetime maxAt = NULL; - datetime minAt = NULL; - for (int i = 0; i < count; i++) - { - // - XOBFVGPivot iPivot = pivots[i]; - - // - if (!iPivot.IsValid()) - { - // - iPivot.Clean(); - continue; - } - - // - // Min ... - bool canSetMin = - min == 0 - ? true - : min > iPivot.value; - if (canSetMin) - { - // - minAt = iPivot.at; - min = iPivot.value; - } - - // - // Max ... - bool canSetMax = - max == 0 - ? true - : max < iPivot.value; - if (canSetMax) - { - // - maxAt = iPivot.at; - max = iPivot.value; - } - - // - iPivot.Clean(); - } - - // - double price1 = - isBullish - ? min - : max; - double price2 = - isBullish - ? max - : min; - datetime time1 = - isBullish - ? minAt - : maxAt; - datetime time2 = - isBullish - ? maxAt - : minAt; - - // - color clrTrend = - isBullish - ? bullishColor - : bearishColor; - - // - string trendName = - ToString(trend) + "_" + "XTRNDL_" + - ToString(period) + "_" + - ToString(price1) + "_" + - ToString(price2) + "_"; - // + ToMD5(ToString(time1)); - - // - CChartObjectTrend *mTrend; - mTrend = new CChartObjectTrend(); - isCreated = mTrend.Create( - chartID, - trendName, - subWindow, - time1, - price1, - time2, - price2 // - ); - - // - if (isCreated) - { - // - mTrend.Width(2); - mTrend.Color(clrTrend); - mTrend.RayRight(true); - - // - mWorkingZoneObjects.Add(mTrend); - } - } - } - - // - // Draw Target Zone ... - has = targetZone.IsValid(); - if (has) - { - // - XCBaseObject *drawnObjects[]; - int drawnObjectsCount = drawer - .DrawOBFVG( - // - targetZone, - drawnObjects, - // - true, // Draw Order Block ... - true, // Draw Fair Value Gap ... - false, // Draw Supply Zones ... - false, // Draw Demand Zones ... - false, // Draw Support Zones ... - false // Draw Resistance Zones ... - ); - if (IsValidSize(drawnObjectsCount)) - { - AddDrawnWorkingZoneObjects(drawnObjects); - } - } - } - - // - } - - // - void DrawConditions( - X121SMCStrategyXWZSignalConditions &conditions, - XCPOIDrawer *drawer, - bool forceClean = false // - ) - { - // - if (drawer == NULL) - { - return; - } - - // - if (forceClean) - { - mObjects.Clear(); - } - - // - bool hasSignalZone = conditions.signalZone.IsValid(); - if (hasSignalZone) - { - // - XCBaseObject *iObjects[]; - int iObjectsCount = drawer.DrawOBFVG( - conditions.signalZone, - iObjects // - ); - AddDrawnObjects(iObjects); - } - } - - // - protected: - // - - // - private: - // - // Props ... - string symbol; - ENUM_TIMEFRAMES period; - CArrayObj mObjects; - CArrayObj mBarObjects; - CArrayObj mWorkingZoneObjects; - - /** - * Initialize ... - */ - void Init() - { - } - - /** - * DeInitialize ... - */ - void DeInit() - { - // - chochZone.Clean(); - signalZone.Clean(); - targetZone.Clean(); - mConditions.Clean(); - workingZone.Clean(); - Clean(mConditionsCollection); - - // - mObjects.Clear(); - mBarObjects.Clear(); - mWorkingZoneObjects.Clear(); - } - - /** - * Update To Time of Exists Components ... - * - * @param value: updated time ... - */ - void UpdateTo( - datetime value = NULL // - ) - { - // - value = NormalizeTime(value); - - // - chochZone.UpdateTo(value); - targetZone.UpdateTo(value); - signalZone.UpdateTo(value); - workingZone.UpdateTo(value); - mConditions.UpdateTo(value); - waitingZone.UpdateTo(value); - } - - // - // Helpers ... - - // - bool CalculateRiskReward( - ENUM_X121SMC_XWZ_PRIORITY priority, - double &reward, - double &amountPercent // - ) - { - // - bool result = false; - - // - reward = 0; - amountPercent = 0; - - // - result = priority != X121SMC_XWZ_PRIORITY_NONE; - if (!result) - { - return result; - } - - // - switch (priority) - { - // - case X121SMC_XWZ_PRIORITY_STRONG_HIGH: - // - reward = 6; - amountPercent = 2; - break; - - // - case X121SMC_XWZ_PRIORITY_HIGH: - // - reward = 4; - amountPercent = 2; - break; - - // - case X121SMC_XWZ_PRIORITY_REGULAR: - // - reward = 3; - amountPercent = 1.5; - break; - - // - case X121SMC_XWZ_PRIORITY_LOW: - // - reward = 2; - amountPercent = 1; - break; - - // - case X121SMC_XWZ_PRIORITY_WEAK: - // - reward = 1; - amountPercent = 0.5; - break; - } - - // - result = - // - reward > 0 && - amountPercent > 0 - // - ; - - // - return result; - } - - // - void AddDrawnObjects(XCBaseObject *&objects[]) - { - // - int count = ArraySize(objects); - bool has = IsValidSize(count); - if (!has) - { - return; - } - - // - for (int i = 0; i < count; i++) - { - mObjects.Add(objects[i]); - } - } - - // - void AddDrawnWorkingZoneObjects(XCBaseObject *&objects[]) - { - // - int count = ArraySize(objects); - bool has = IsValidSize(count); - if (!has) - { - return; - } - - // - for (int i = 0; i < count; i++) - { - mWorkingZoneObjects.Add(objects[i]); - } - } - - // -}; - -// \ No newline at end of file diff --git a/Documents/BKP/x-121.smc.xwz.signal.lib copy 2.mq5 b/Documents/BKP/x-121.smc.xwz.signal.lib copy 2.mq5 deleted file mode 100644 index 8aa5b9cd..00000000 --- a/Documents/BKP/x-121.smc.xwz.signal.lib copy 2.mq5 +++ /dev/null @@ -1,3189 +0,0 @@ -/////////////////////////////////////////////////////// -// -// SaherElm IT Center MQL5 X121 SMC Signal Class -// ------------------------------------------------- -// Name: XWZ -// Description: provide all Signalling functions ... -// -// -// Maintainer: -// ------------ -// Hadi Khazaee Asl (hadi_khazaee_asl@yahoo.com) -// -////////////////////////////////////////////////////// -// -// Global Properties ... -#property library -#property copyright "Copyright 2023, SaherElm IT Center" -#property link "https://www.saherelm.ir" -#property version "1.00" -#property strict - -// -// Imports ... -// #include "../../Libraries/x-trade.lib" -#include "../Classes/x-121.smc.market.cycle.helper.class.mq5" -#include "../Libraries/x-121.smc.guard.lib.mq5" -#include "../Libraries/x-121.smc.lib.mq5" - -// -enum ENUM_X121SMC_XWZ_PROVIDERS -{ - X121SMC_XWZ_PROVIDER_NONE, - X121SMC_XWZ_PROVIDER_PV_ZONE, - X121SMC_XWZ_PROVIDER_ACTIVATED_ZONE, - X121SMC_XWZ_PROVIDER_ACTIVATED_CHOCH, - X121SMC_XWZ_PROVIDER_PRICE_INSIDE_ZONE, -}; - -// -enum ENUM_X121SMC_XWZ_PRIORITY -{ - X121SMC_XWZ_PRIORITY_NONE, - X121SMC_XWZ_PRIORITY_WEAK, - X121SMC_XWZ_PRIORITY_LOW, - X121SMC_XWZ_PRIORITY_REGULAR, - X121SMC_XWZ_PRIORITY_HIGH, - X121SMC_XWZ_PRIORITY_STRONG_HIGH, -}; - -// -// Definitions ... - -// -struct X121SMCStrategyXWZWorkingZone -{ - // - // Props ... - - // - string symbol; - ENUM_TIMEFRAMES period; - - // - double quarter1; - double quarter2; - double quarter3; - - // - XCSupplyZone *supplyZone; - XCDemandZone *demandZone; - - // - XCSupplyZone *supplyZones[]; - XCDemandZone *demandZones[]; - - // - XCSupportZone *supportZones[]; - XCResistanceZone *resistanceZones[]; - - // - XBoxZone insideBoxes[]; - XBoxZone breakedBoxes[]; - XBoxZone waitingBoxes[]; - XBoxZone breakedInsideBoxes[]; - XConsolidationZone consolidationZones[]; - - // - CArrayObj mInsideZoneObjects; - CArrayObj mBreakedZoneObjects; - CArrayObj mWaitingZoneObjects; - CArrayObj mWorkingZoneObjects; - CArrayObj mBreakedInsideZoneObjects; - - // - bool mUseSupDems; - bool mUseOrderBlocks; - bool mUseFairValueGaps; - - // - // Constructor ... - X121SMCStrategyXWZWorkingZone() - { - Clean(); - } - - // - // Tools ... - - // - void Clean() - { - // - quarter1 = 0; - quarter2 = 0; - quarter3 = 0; - - // - symbol = NULL; - period = NULL; - - // - Clean(supplyZones); - Clean(demandZones); - - // - Clean(insideBoxes); - Clean(breakedBoxes); - Clean(waitingBoxes); - - // - Clean(supportZones); - Clean(resistanceZones); - - // - ZeroMemory(supplyZone); - ZeroMemory(demandZone); - - // - mInsideZoneObjects.Clear(); - mBreakedZoneObjects.Clear(); - mWaitingZoneObjects.Clear(); - mWorkingZoneObjects.Clear(); - mBreakedInsideZoneObjects.Clear(); - - // - mUseSupDems = false; - mUseOrderBlocks = true; - mUseFairValueGaps = true; - } - - // - bool IsValid() - { - // - bool result = false; - - // - result = - // - quarter1 > 0 && - quarter2 > 0 && - quarter3 > 0 && - HasSupplyZone() && - HasDemandZone() && - quarter1 > quarter2 && - quarter2 > quarter3 - // - ; - - // - return result; - } - - // - bool Init( - string _symbol, - ENUM_TIMEFRAMES _period, - int barIndex, - XPOIState &htfState, - XPOIState &mtfState, - XPOIState &stfState, // - XPOIState &ttfState // - ) - { - // - bool result = false; - - // - if (barIndex < 0) - { - barIndex = 0; - } - - // - result = - // - IsValid(_symbol) && - IsValid(_period) && - // - htfState.IsValid() && - mtfState.IsValid() && - stfState.IsValid() && - ttfState.IsValid() && - // - htfState.HasChild() && - mtfState.HasChild() && - stfState.HasChild() && - ttfState.HasChild() - // - ; - if (!result) - { - return result; - } - - // - symbol = _symbol; - period = _period; - - // - int idx = -1; - int count = 0; - bool has = false; - - // - XOHCL zBar; - has = zBar.Init( - symbol, - period, - barIndex // - ); - result = has; - if (!result) - { - zBar.Clean(); - return result; - } - double ll5 = zBar.FindLowest(5, MODE_LOW); - double hh5 = zBar.FindHighest(5, MODE_HIGH); - zBar.Clean(); - - // - // Supply Zone ... - has = HasSupplyZone(); - if (!has) - { - // - idx = GetHighest(mtfState.supplyZones); - has = IsValidIndex(idx); - if (has) - { - // - supplyZone = mtfState.supplyZones[idx]; - has = hh5 < supplyZone.Lower(); - if (!has) - { - supplyZone = NULL; - } - } - } - - // - // Demand Zone ... - has = HasDemandZone(); - if (!has) - { - // - idx = GetLowest(mtfState.demandZones); - has = IsValidIndex(idx); - if (has) - { - // - demandZone = mtfState.demandZones[idx]; - has = ll5 > demandZone.Upper(); - if (!has) - { - demandZone = NULL; - } - } - } - - // - // - // - - // // - // // Supply Zones ... - // has = HasSupplyZones(); - // if (!has) - // { - // // - // count = mtfState.FilterSupplyZones( - // supplyZones, - // period, - // XZONE_STATE_PASSED, - // false, - // XZONE_STATE_FAILED, - // false, - // XZONE_STATE_FAILED, - // false, - // XZONE_STATE_IGNORED, - // false // - // ); - // } - - // // - // // Demand Zones ... - // has = HasDemandZones(); - // if (!has) - // { - // // - // count = mtfState.FilterDemandZones( - // demandZones, - // period, - // XZONE_STATE_PASSED, - // false, - // XZONE_STATE_FAILED, - // false, - // XZONE_STATE_FAILED, - // false, - // XZONE_STATE_IGNORED, - // false // - // ); - // } - - // - // Support Zones ... - // has = HasSupportZones(); - // if (!has) - // { - // // - // count = mtfState.FilterSupportZones( - // supportZones, - // period, - // XZONE_STATE_PASSED, - // false, - // XZONE_STATE_FAILED, - // false, - // XZONE_STATE_FAILED, - // false, - // XZONE_STATE_IGNORED, - // false // - // ); - // } - - // - // Resistance Zones ... - // has = HasResistanceZones(); - // if (!has) - // { - // // - // count = mtfState.FilterResistanceZones( - // resistanceZones, - // period, - // XZONE_STATE_PASSED, - // false, - // XZONE_STATE_FAILED, - // false, - // XZONE_STATE_FAILED, - // false, - // XZONE_STATE_IGNORED, - // false // - // ); - // } - - // - has = ttfState.HasConsolidationZones(); - if (has) - { - // - Copy( - ttfState.consolidationZones, - consolidationZones // - ); - CleanupArray( - consolidationZones, - 50 // - ); - } - - // - if (supplyZone != NULL && - demandZone != NULL && - supplyZone.IsValid() && - demandZone.IsValid()) - { - // - double upper = supplyZone.Lower(); - double lower = demandZone.Upper(); - - // - double delta = ((upper - lower) / 100) * 25; - - // - quarter1 = upper - (1 * delta); - quarter2 = upper - (2 * delta); - quarter3 = upper - (3 * delta); - } - - // - // Waiting Zone Detection ... - // XPOIState iState = mtfState; - - // - // Detect Waiting Zones ... - - // // - // // Using Order Blocks ... - // if (mUseOrderBlocks) - // { - // // - // has = iState.HasOrderBlocks(); - // if (has) - // { - // // - // XCOrderBlock *obs[]; - // count = iState.FilterOrderBlocks( - // obs, - // period, - // XZONE_STATE_PASSED, - // false, - // XZONE_STATE_FAILED, - // false, - // XZONE_STATE_FAILED, - // false, - // XZONE_STATE_IGNORED, - // false // - // ); - - // // - // has = IsValidSize(count); - // if (has) - // { - // // - // ToBox( - // obs, - // waitingBoxes // - // ); - // } - - // // - // Clean(obs); - // } - // } - - // // - // // Using Fair Value Gaps ... - // if (mUseFairValueGaps) - // { - // // - // has = iState.HasFairValueGaps(); - // if (has) - // { - // // - // XBoxZone boxes[]; - // XCFVG *fvgs[]; - // count = iState.FilterFairValueGaps( - // fvgs, - // period, - // XZONE_STATE_PASSED, - // false, - // XZONE_STATE_FAILED, - // false, - // XZONE_STATE_FAILED, - // false, - // XZONE_STATE_IGNORED, - // false // - // ); - - // // - // has = IsValidSize(count); - // if (has) - // { - // // - // count = ToBox( - // fvgs, - // boxes // - // ); - - // // - // for (int i = 0; i < count; i++) - // { - // // - // XBoxZone iBox = boxes[i]; - - // // - // int idx = FindIndex( - // iBox, - // waitingBoxes // - // ); - // has = !IsValidIndex(idx); - // if (has) - // { - // // - // AddRef( - // iBox, - // waitingBoxes // - // ); - // } - - // // - // iBox.Clean(); - // } - // } - - // // - // Clean(fvgs); - // Clean(boxes); - // } - // } - - // - // Cleaning State ... - // iState.Clean(); - - // - result = IsValid(); - if (!result) - { - Clean(); - } - - // - return result; - } - - // - void Update( - int barIndex, - XPOIState &htfState, - XPOIState &mtfState, - XPOIState &stfState, - XPOIState &ttfState // - ) - { - // - int idx = -1; - int count = 0; - bool has = false; - - // - if (barIndex < 0) - { - barIndex = 0; - } - - // - has = - // - IsValid() && - // - htfState.IsValid() && - mtfState.IsValid() && - stfState.IsValid() && - // - htfState.HasChild() && - mtfState.HasChild() && - stfState.HasChild() - // - ; - if (!has) - { - return; - } - - // - XOHCL zBar; - has = zBar.Init( - symbol, - period, - barIndex // - ); - if (!has) - { - // - zBar.Clean(); - return; - } - - // - XOHCL cBar; - has = zBar.GetPreviousBar(cBar); - if (!has) - { - // - zBar.Clean(); - cBar.Clean(); - - // - return; - } - - // - // Update Exists Zones ... - - // - // Supply Zones ... - has = mtfState.HasSupplyZones(); - if (has) - { - // - XCSupplyZone *zone; - idx = GetYoungest(mtfState.supplyZones); - has = IsValidIndex(idx); - if (has) - { - // - zone = mtfState.supplyZones[idx]; - has = IsSupplyExists(zone); - if (!has) - { - // - Add( - zone, - supplyZones // - ); - } - else - { - ZeroMemory(zone); - } - } - } - - // - // Demand Zones ... - has = mtfState.HasDemandZones(); - if (has) - { - // - XCDemandZone *zone; - idx = GetYoungest(mtfState.demandZones); - has = IsValidIndex(idx); - if (has) - { - // - zone = mtfState.demandZones[idx]; - has = IsDemandExists(zone); - if (!has) - { - // - Add( - zone, - demandZones // - ); - } - else - { - ZeroMemory(zone); - } - } - } - - // - // - // - - // - // Supply Zones ... - has = HasSupplyZones(); - if (has) - { - // - int removeIDXs[]; - count = CountSupplyZones(); - for (int i = 0; i < count; i++) - { - // - XCSupplyZone *iZone = supplyZones[i]; - ENUM_X_DIRECTION iDir = X_DIRECTION_BEARISH; - - // - XBoxZone iBox; - bool hasBox = ToBox( - iBox, - iZone // - ); - if (!hasBox) - { - // - iBox.Clean(); - continue; - } - - // - XOHCL passedBar; - bool isBodyIn = false; - bool isBodyOut = false; - - // - // Check Activation ... - bool isActivated = iZone.IsActivated( - iDir, - passedBar, - isBodyIn, - true, - period // - ); - if (isActivated) - { - // - // AddRef( - // iBox, - // insideBoxes // - // ); - - // - Add( - i, - removeIDXs // - ); - - // - iBox.Clean(); - passedBar.Clean(); - continue; - } - - // - // Checking Breaked ... - bool isBreaked = iZone.IsBreaked( - iDir, - passedBar, - isBodyOut, - false, - true, - period // - ); - if (isBreaked) - { - // // - // AddRef( - // iBox, - // breakedBoxes // - // ); - - // - Add( - i, - removeIDXs // - ); - - // - iBox.Clean(); - passedBar.Clean(); - continue; - } - - // - passedBar.Clean(); - } - - // - count = ArraySize(removeIDXs); - has = IsValidSize(count); - if (has) - { - // - CleanupArray( - removeIDXs, - supplyZones // - ); - } - - // - Clean(removeIDXs); - } - - // - // Demand Zones ... - has = HasDemandZones(); - if (has) - { - // - int removeIDXs[]; - count = CountDemandZones(); - for (int i = 0; i < count; i++) - { - // - XCDemandZone *iZone = demandZones[i]; - ENUM_X_DIRECTION iDir = X_DIRECTION_BULLISH; - - // - XBoxZone iBox; - bool hasBox = ToBox( - iBox, - iZone // - ); - if (!hasBox) - { - // - iBox.Clean(); - continue; - } - - // - XOHCL passedBar; - bool isBodyIn = false; - bool isBodyOut = false; - - // - // Check Activation ... - bool isActivated = iZone.IsActivated( - iDir, - passedBar, - isBodyIn, - true, - period // - ); - if (isActivated) - { - // - // AddRef( - // iBox, - // insideBoxes // - // ); - - // - Add( - i, - removeIDXs // - ); - - // - iBox.Clean(); - passedBar.Clean(); - continue; - } - - // - // Checking Breaked ... - bool isBreaked = iZone.IsBreaked( - iDir, - passedBar, - isBodyOut, - false, - true, - period // - ); - if (isBreaked) - { - // // - // AddRef( - // iBox, - // breakedBoxes // - // ); - - // - Add( - i, - removeIDXs // - ); - - // - iBox.Clean(); - passedBar.Clean(); - continue; - } - - // - passedBar.Clean(); - } - - // - count = ArraySize(removeIDXs); - has = IsValidSize(count); - if (has) - { - // - CleanupArray( - removeIDXs, - demandZones // - ); - } - - // - Clean(removeIDXs); - } - - // - // Update Boxes ... - - // - // Waiting Boxes ... - has = HasWaitingBoxes(); - if (has) - { - // - int removeIDXs[]; - count = CountWaitingBoxes(); - for (int i = 0; i < count; i++) - { - // - XBoxZone iBox = waitingBoxes[i]; - ENUM_X_DIRECTION iDir = iBox.dir; - bool isBullish = IsBullish(iDir); - - // - bool isInside = - // - zBar.low < iBox.upper && - zBar.low > iBox.lower - // - ; - if (isInside) - { - // - AddRef( - iBox, - insideBoxes // - ); - - // - Add( - i, - removeIDXs // - ); - - // - iBox.Clean(); - break; - } - - // - bool isBreakedUpper = - // - cBar.low < iBox.upper && - cBar.low > iBox.lower && - zBar.low > iBox.upper - // - ; - - // - bool isBreakedLower = - // - cBar.high > iBox.lower && - cBar.high < iBox.upper && - zBar.high < iBox.lower - // - ; - - // - bool isBreaked = - (isBullish && - isBreakedLower) || - (!isBullish && - isBreakedUpper); - - // - if (isBreaked) - { - // - AddRef( - iBox, - breakedBoxes // - ); - - // - Add( - i, - removeIDXs // - ); - - // - iBox.Clean(); - break; - } - } - - // - count = ArraySize(removeIDXs); - has = IsValidSize(count); - if (has) - { - // - CleanupArray( - removeIDXs, - waitingBoxes // - ); - } - - // - Clean(removeIDXs); - } - - // - // Inside Boxes ... - has = HasInsideBoxes(); - if (has) - { - // - int removeIDXs[]; - count = CountInsideBoxes(); - for (int i = 0; i < count; i++) - { - // - XBoxZone iBox = insideBoxes[i]; - ENUM_X_DIRECTION iDir = iBox.dir; - bool isBullish = IsBullish(iDir); - - // - bool isBreakedUpper = - // - cBar.low < iBox.upper && - cBar.low > iBox.lower && - zBar.low > iBox.upper - // - ; - - // - bool isBreakedLower = - // - cBar.high > iBox.lower && - cBar.high < iBox.upper && - zBar.high < iBox.lower - // - ; - - // - bool isBreaked = - (isBullish && - isBreakedLower) || - (!isBullish && - isBreakedUpper); - - // - if (isBreaked) - { - // - AddRef( - iBox, - breakedBoxes // - ); - - // - Add( - i, - removeIDXs // - ); - - // - iBox.Clean(); - break; - } - } - - // - count = ArraySize(removeIDXs); - has = IsValidSize(count); - if (has) - { - // - CleanupArray( - removeIDXs, - insideBoxes // - ); - } - - // - Clean(removeIDXs); - } - - // - has = HasBreakedBoxes(); - if (has) - { - // - int removeIDXs[]; - count = CountBreakedBoxes(); - for (int i = 0; i < count; i++) - { - // - XBoxZone iBox = breakedBoxes[i]; - ENUM_X_DIRECTION iDir = iBox.dir; - bool isBullish = IsBullish(iDir); - - // - bool isInside = false; - - // - if (isInside) - { - // - AddRef( - iBox, - breakedInsideBoxes // - ); - - // - Add( - i, - removeIDXs // - ); - - // - iBox.Clean(); - break; - } - } - - // - count = ArraySize(removeIDXs); - has = IsValidSize(count); - if (has) - { - // - CleanupArray( - removeIDXs, - breakedBoxes // - ); - } - - // - Clean(removeIDXs); - } - - // - // Update Waiting Boxes ... - - // - XPOIState iState = mtfState; - - // - // Use Order Blocks ... - if (mUseOrderBlocks) - { - // - has = iState.HasOrderBlocks(); - if (has) - { - // - XCOrderBlock *obs[]; - count = iState.FilterOrderBlocks( - obs, - period, - XZONE_STATE_PASSED, - false, - XZONE_STATE_FAILED, - false, - XZONE_STATE_FAILED, - false, - XZONE_STATE_IGNORED, - false // - ); - - // - has = IsValidSize(count); - if (has) - { - // - // Try to Add new OBs into Waiting Zones ... - // if it's not exists ... - for (int i = 0; i < count; i++) - { - // - XBoxZone iBox; - bool hasBox = ToBox( - iBox, - obs[i] // - ); - if (!hasBox) - { - // - iBox.Clean(); - continue; - } - - // - // Check Index in Waiting Boxes ... - idx = FindIndex( - iBox, - waitingBoxes // - ); - has = !IsValidIndex(idx); - if (!has) - { - // - iBox.Clean(); - continue; - } - - // - // Check Index in Inside Boxes ... - idx = FindIndex( - iBox, - insideBoxes // - ); - has = !IsValidIndex(idx); - if (!has) - { - // - iBox.Clean(); - continue; - } - - // - // Check Index in Breaked Boxes ... - idx = FindIndex( - iBox, - breakedBoxes // - ); - has = !IsValidIndex(idx); - if (!has) - { - // - iBox.Clean(); - continue; - } - - // - AddRef( - iBox, - waitingBoxes // - ); - } - } - - // - Clean(obs); - } - } - - // - // Use Fair Value Gaps ... - if (mUseFairValueGaps) - { - // - has = iState.HasFairValueGaps(); - if (has) - { - // - XCFVG *fvgs[]; - count = iState.FilterFairValueGaps( - fvgs, - period, - XZONE_STATE_PASSED, - false, - XZONE_STATE_FAILED, - false, - XZONE_STATE_FAILED, - false, - XZONE_STATE_IGNORED, - false // - ); - - // - has = IsValidSize(count); - if (has) - { - // - for (int i = 0; i < count; i++) - { - // - XBoxZone iBox; - bool hasBox = ToBox( - iBox, - fvgs[i] // - ); - if (!hasBox) - { - // - iBox.Clean(); - continue; - } - - // - // Check Index in Waiting Boxes ... - idx = FindIndex( - iBox, - waitingBoxes // - ); - has = !IsValidIndex(idx); - if (!has) - { - // - iBox.Clean(); - continue; - } - - // - // Check Index in Inside Boxes ... - idx = FindIndex( - iBox, - insideBoxes // - ); - has = !IsValidIndex(idx); - if (!has) - { - // - iBox.Clean(); - continue; - } - - // - // Check Index in Breaked Boxes ... - idx = FindIndex( - iBox, - breakedBoxes // - ); - has = !IsValidIndex(idx); - if (!has) - { - // - iBox.Clean(); - continue; - } - - // - AddRef( - iBox, - waitingBoxes // - ); - - // - iBox.Clean(); - } - } - - // - Clean(fvgs); - } - } - - // - iState.Clean(); - - // - // Cleanup Resource ... - - // - zBar.Clean(); - cBar.Clean(); - } - - // - bool IsDestroyed( - int barIndex = 0, - ENUM_TIMEFRAMES forPeriod = NULL // - ) - { - // - bool result = false; - - // - if (barIndex < 0) - { - barIndex = 0; - } - - // - if (!IsValid(forPeriod)) - { - forPeriod = period; - } - - // - result = IsValid(); - if (!result) - { - return result; - } - - // - XOHCL bar; - result = bar.Init( - symbol, - period, - barIndex // - ); - if (!result) - { - // - bar.Clean(); - return result; - } - - // - XOHCL cBar; - result = bar.GetPreviousBar(cBar); - if (!result) - { - // - bar.Clean(); - cBar.Clean(); - - // - return result; - } - - // - bool isSupplyZoneBreaked = - // - bar.low > supplyZone.Upper() && - cBar.low > supplyZone.Upper() - // - ; - - // - bool isDemandZoneBreaked = - // - bar.high < demandZone.Lower() && - cBar.high < demandZone.Lower() - // - ; - - // - bar.Clean(); - cBar.Clean(); - - // - result = isSupplyZoneBreaked || - isDemandZoneBreaked; - - // - return result; - } - - // - bool DetectPriority( - ENUM_X121SMC_XWZ_PRIORITY &priority, - ENUM_X_DIRECTION forDir, - int barIndex = 0, - ENUM_TIMEFRAMES forPeriod = NULL // - ) - { - // - bool result = false; - - // - priority = X121SMC_XWZ_PRIORITY_NONE; - - // - if (barIndex < 0) - { - barIndex = 0; - } - - // - if (!IsValid(forPeriod)) - { - forPeriod = period; - } - - // - result = IsValid() && - HasDirection(forDir); - if (!result) - { - return result; - } - - // - bool isBullish = IsBullish(forDir); - - // - XOHCL bar; - result = bar.Init( - symbol, - forPeriod, - barIndex // - ); - if (!result) - { - // - bar.Clean(); - return result; - } - - // - if (bar.high < supplyZone.Upper() && - bar.low > supplyZone.Lower()) - { - // - priority = - isBullish - ? X121SMC_XWZ_PRIORITY_NONE - : X121SMC_XWZ_PRIORITY_STRONG_HIGH; - } - else if (bar.high < supplyZone.Lower() && - bar.low > quarter1) - { - // - priority = - isBullish - ? X121SMC_XWZ_PRIORITY_WEAK - : X121SMC_XWZ_PRIORITY_HIGH; - } - else if (bar.high < quarter1 && - bar.low > quarter2) - { - // - priority = - isBullish - ? X121SMC_XWZ_PRIORITY_LOW - : X121SMC_XWZ_PRIORITY_REGULAR; - } - else if (bar.high < quarter2 && - bar.low > quarter3) - { - // - priority = - isBullish - ? X121SMC_XWZ_PRIORITY_REGULAR - : X121SMC_XWZ_PRIORITY_LOW; - } - else if (bar.high < quarter3 && - bar.low > demandZone.Upper()) - { - // - priority = - isBullish - ? X121SMC_XWZ_PRIORITY_HIGH - : X121SMC_XWZ_PRIORITY_WEAK; - } - else if (bar.high < demandZone.Upper() && - bar.low > demandZone.Lower()) - { - // - priority = - isBullish - ? X121SMC_XWZ_PRIORITY_STRONG_HIGH - : X121SMC_XWZ_PRIORITY_NONE; - } - - // - result = priority != X121SMC_XWZ_PRIORITY_NONE && - priority != X121SMC_XWZ_PRIORITY_WEAK; - - // - bar.Clean(); - - // - return result; - } - - // - bool DetectSenarioASignalBox( - XBoxZone &signalBox, - ENUM_X_DIRECTION &signalDir, - X121Conditions &decisionXConditions, - X121Conditions &analyseXConditions, - XC121SMCCycleHelper *decisionCycleHelper, - XCPOIDrawer *drawer = NULL, - int barIndex = 0 // - ) - { - // - bool result = false; - - // - signalBox.Clean(); - signalDir = X_DIRECTION_NONE; - - // - if (barIndex < 0) - { - barIndex = 0; - } - - // - result = decisionCycleHelper != NULL; - if (!result) - { - return result; - } - - // - // Decision ... - double decisionBullishScore = 0; - double decisionBearishScore = 0; - decisionXConditions.GenerateScore( - decisionBullishScore, - decisionBearishScore // - ); - - // - // Analyse ... - double analyseBullishScore = 0; - double analyseBearishScore = 0; - analyseXConditions.GenerateScore( - analyseBullishScore, - analyseBearishScore // - ); - - // - // Score Conditions ... - double scoreMultiplier = 3; - bool isBullishScorePassed = - // - analyseBullishScore > (analyseBearishScore * scoreMultiplier) && - decisionBullishScore > (decisionBearishScore * scoreMultiplier) - // - ; - bool isBearishScorePassed = - // - analyseBearishScore > (analyseBullishScore * scoreMultiplier) && - decisionBearishScore > (decisionBullishScore * scoreMultiplier) - // - ; - - // - // Checking Other Conditions - - // - bool isCommonBullish = - // - decisionXConditions.isSarBullish && - decisionXConditions.isStrBullish && - decisionXConditions.isCheBullish && - decisionXConditions.isSMHKBullish && - decisionXConditions.isRawHKBullish && - decisionXConditions.isRawHKClosedOverSMHK - // - ; - - // - bool isCommonBearish = - // - decisionXConditions.isSarBearish && - decisionXConditions.isStrBearish && - decisionXConditions.isCheBearish && - decisionXConditions.isSMHKBearish && - decisionXConditions.isRawHKBearish && - decisionXConditions.isRawHKClosedUnderSMHK - // - ; - - // - // X3Ma ... - - // - // X3Ma Bullish ... - bool isX3MaBullish = - // - decisionXConditions.isX3MaBullishState && - decisionXConditions.isX3MaSwitchedToBullishOrdered && - decisionXConditions.x3maMidBuffer[1] > decisionXConditions.x3maSlowBuffer[1] - // - ; - - // - // X3Ma Bearish ... - bool isX3MaBearish = - // - decisionXConditions.isX3MaBearishState && - decisionXConditions.isX3MaSwitchedToBearishOrdered && - decisionXConditions.x3maMidBuffer[1] < decisionXConditions.x3maSlowBuffer[1] - // - ; - - // - bool isX3MaHasCondition = - (isX3MaBullish && - isCommonBullish && - isBullishScorePassed) || - (isX3MaBearish && - isCommonBearish && - isBearishScorePassed); - - // - // VWap ... - - // - // VWap Bullish ... - bool isVWapBullish = - // - decisionXConditions.isVWapBullishState && - decisionXConditions.isVWapSwitchedToBullishOrdered && - decisionXConditions.vwapMidBuffer[1] > decisionXConditions.vwapSlowBuffer[1] - // - ; - - // - // VWap Bearish ... - bool isVWapBearish = - // - decisionXConditions.isVWapBearishState && - decisionXConditions.isVWapSwitchedToBearishOrdered && - decisionXConditions.vwapMidBuffer[1] < decisionXConditions.vwapSlowBuffer[1] - // - ; - - // - bool isVWapHasCondition = - (isVWapBullish && - isBullishScorePassed) || - (isVWapBearish && - isBearishScorePassed); - - // - // Senario .... - // - a vale Under X3MA Slow when X3MA Bullish Ordered ... - - // - bool isX3MASenarioBBullish = - // - decisionXConditions.isX3MaBullishOrdered && - decisionXConditions.valesBuffer[1] < decisionXConditions.x3maSlowBuffer[1] && - decisionXConditions.valesBuffer[2] >= decisionXConditions.x3maSlowBuffer[2] - // - ; - if (isX3MASenarioBBullish) - { - } - - // - bool isX3MASenarioBBearish = - // - decisionXConditions.isX3MaBearishOrdered && - decisionXConditions.peaksBuffer[1] > decisionXConditions.x3maSlowBuffer[1] && - decisionXConditions.peaksBuffer[2] <= decisionXConditions.x3maSlowBuffer[2] - // - ; - if (isX3MASenarioBBearish) - { - } - - // - // Checking Other Conditions XWZ Reject on EMA 20 ... - - // - // Check Has Conditions ... - bool hasXConditions = - (isX3MaHasCondition || - isVWapHasCondition); - - // - result = hasXConditions; - if (!result) - { - return result; - } - - // - if (isX3MaHasCondition) - { - // - signalDir = - isX3MaBullish - ? X_DIRECTION_BULLISH - : isX3MaBearish - ? X_DIRECTION_BEARISH - : X_DIRECTION_NONE; - } - - // - if (isVWapHasCondition) - { - // - signalDir = - isVWapBullish - ? X_DIRECTION_BULLISH - : isVWapBearish - ? X_DIRECTION_BEARISH - : X_DIRECTION_NONE; - } - - // - // Creating SignalBox ... - - // - // Detect Box based on PV ... - bool hasSignalBox = decisionCycleHelper.GeneratePVBox( - signalBox, - barIndex // - ); - - // - result = - hasSignalBox && - signalDir == signalBox.dir; - - // - if (result) - { - // - XCBoxObject *iObj; - bool isCreated = drawer.DrawBox( - signalBox, - iObj // - ); - if (isCreated) - { - // - iObj.BoxWidth(1); - iObj.BoxColor(clrYellow); - iObj.BoxStyle(STYLE_SOLID); - } - - // - Print("Senario A ..."); - } - - // - return result; - } - - // - bool DetetctSenarioBSignalBox( - XBoxZone &signalBox, - ENUM_X_DIRECTION &signalDir, - X121Conditions &decisionXConditions, - X121Conditions &analyseXConditions, - XC121SMCCycleHelper *decisionCycleHelper, - int barIndex = 0 // - ) - { - // - bool result = false; - - // - signalBox.Clean(); - signalDir = X_DIRECTION_NONE; - - // - if (barIndex < 0) - { - barIndex = 0; - } - - // - result = decisionCycleHelper != NULL; - if (!result) - { - return result; - } - - // - // Decision ... - double decisionBullishScore = 0; - double decisionBearishScore = 0; - decisionXConditions.GenerateScore( - decisionBullishScore, - decisionBearishScore // - ); - - // - // Analyse ... - double analyseBullishScore = 0; - double analyseBearishScore = 0; - analyseXConditions.GenerateScore( - analyseBullishScore, - analyseBearishScore // - ); - - // - // Score Conditions ... - double scoreMultiplier = 3; - bool isBullishScorePassed = - // - analyseBullishScore > (analyseBearishScore * scoreMultiplier) && - decisionBullishScore > (decisionBearishScore * scoreMultiplier) - // - ; - bool isBearishScorePassed = - // - analyseBearishScore > (analyseBullishScore * scoreMultiplier) && - decisionBearishScore > (decisionBullishScore * scoreMultiplier) - // - ; - - // - // Senario .... - // - a vale Under X3MA Slow when X3MA Bullish Ordered ... - - // - bool isX3MASenarioBBullish = - // - decisionXConditions.isX3MaBullishOrdered && - decisionXConditions.valesBuffer[1] < decisionXConditions.x3maSlowBuffer[1] && - decisionXConditions.valesBuffer[2] >= decisionXConditions.x3maSlowBuffer[2] - // - ; - if (isX3MASenarioBBullish) - { - } - - // - bool isX3MASenarioBBearish = - // - decisionXConditions.isX3MaBearishOrdered && - decisionXConditions.peaksBuffer[1] > decisionXConditions.x3maSlowBuffer[1] && - decisionXConditions.peaksBuffer[2] <= decisionXConditions.x3maSlowBuffer[2] - // - ; - if (isX3MASenarioBBearish) - { - } - - // - return result; - } - - // - bool DetectOveralDirection( - ENUM_X_DIRECTION &dir // - ) - { - // - bool result = false; - - // - dir = X_DIRECTION_NONE; - - // - result = IsValid() && - HasSupplyZone() && - HasDemandZone(); - if (!result) - { - return result; - } - - // - XBoxZone demBox; - XBoxZone supBox; - result = ToBox( - demBox, - demandZone // - ); - if (!result) - { - // - supBox.Clean(); - demBox.Clean(); - - // - return result; - } - result = ToBox( - supBox, - supplyZone // - ); - if (!result) - { - // - supBox.Clean(); - demBox.Clean(); - - // - return result; - } - - // - XOHCL supPriceOutBar; - XOHCL demPriceOutBar; - result = DetectBoxNearestPriceOut( - supBox, - supPriceOutBar, - period // - ); - if (!result) - { - // - demBox.Clean(); - supBox.Clean(); - supPriceOutBar.Clean(); - demPriceOutBar.Clean(); - - // - return result; - } - result = DetectBoxNearestPriceOut( - demBox, - demPriceOutBar, - period // - ); - if (!result) - { - // - demBox.Clean(); - supBox.Clean(); - supPriceOutBar.Clean(); - demPriceOutBar.Clean(); - - // - return result; - } - - // - // Specified Direction ... - dir = - (supPriceOutBar.IsValid() && - demPriceOutBar.IsValid()) - ? supPriceOutBar.time > demPriceOutBar.time - ? X_DIRECTION_BEARISH - : demPriceOutBar.time > supPriceOutBar.time - ? X_DIRECTION_BULLISH - : X_DIRECTION_NONE - : X_DIRECTION_NONE; - - // - result = HasDirection(dir); - - // - // Clean Up Resources ... - - // - demBox.Clean(); - supBox.Clean(); - supPriceOutBar.Clean(); - demPriceOutBar.Clean(); - - // - return result; - } - - // - bool HasInsideBox( - XBoxZone &box // - ) - { - // - bool result = false; - - // - int index = -1; - - // - result = box.IsValid(); - if (!result) - { - return result; - } - - // - int count = 0; - bool has = false; - - // - has = HasWaitingBoxes(); - if (has) - { - // - result = HasInsideBox( - index, - box, - waitingBoxes // - ); - } - - // - // Supply Zones ... - if (!result) - { - // - has = HasSupplyZones(); - if (has) - { - // - XBoxZone tmpBoxes[]; - count = ToBox( - supplyZones, - tmpBoxes // - ); - - // - has = IsValidSize(count); - if (has) - { - // - result = HasInsideBox( - index, - box, - tmpBoxes // - ); - } - - // - Clean(tmpBoxes); - } - } - - // - // Demand Zones ... - if (!result) - { - // - has = HasDemandZones(); - if (has) - { - // - XBoxZone tmpBoxes[]; - count = ToBox( - demandZones, - tmpBoxes // - ); - - // - has = IsValidSize(count); - if (has) - { - // - result = HasInsideBox( - index, - box, - tmpBoxes // - ); - } - - // - Clean(tmpBoxes); - } - } - - // - result = IsValidIndex(index); - - // - return result; - } - - // - bool IsExists(XBoxZone &box) - { - // - bool result = false; - - // - result = box.IsValid(); - if (!result) - { - return result; - } - - // - int idx = -1; - bool has = false; - - // - // Checking Index Waiting Box ... - has = HasWaitingBoxes(); - if (has) - { - // - idx = FindIndex( - box, - waitingBoxes // - ); - result = !IsValidIndex(idx); - if (!result) - { - return result; - } - } - - // - // Checking Index Inside Boxes ... - has = HasInsideBoxes(); - if (has) - { - // - idx = FindIndex( - box, - insideBoxes // - ); - result = !IsValidIndex(idx); - if (!result) - { - return result; - } - } - - // - // Checking Index Breaked Boxes ... - has = HasBreakedBoxes(); - if (has) - { - // - idx = FindIndex( - box, - breakedBoxes // - ); - result = !IsValidIndex(idx); - if (!result) - { - return result; - } - } - - // - // Checking Index BreakedInside Boxes ... - has = HasBreakedInsideBoxes(); - if (has) - { - // - idx = FindIndex( - box, - breakedInsideBoxes // - ); - result = !IsValidIndex(idx); - if (!result) - { - return result; - } - } - - // - return result; - } - - // - bool IsSupplyExists(XCSupplyZone *zone) - { - // - bool result = false; - - // - result = zone != NULL && - zone.IsValid(); - if (!result) - { - return result; - } - - // - // Converts Zone to Box ... - XBoxZone box; - result = ToBox( - box, - zone // - ); - if (!result) - { - // - box.Clean(); - return result; - } - - // - // Checking Index in SupplyZones ... - int idx = FindIndex( - zone, - supplyZones // - ); - result = !IsValidIndex(idx); - if (!result) - { - // - box.Clean(); - return result; - } - - // - result = IsExists(box); - - // - box.Clean(); - - // - return result; - } - - // - bool IsDemandExists(XCDemandZone *zone) - { - // - bool result = false; - - // - result = zone != NULL && - zone.IsValid(); - if (!result) - { - return result; - } - - // - // Converts Zone to Box ... - XBoxZone box; - result = ToBox( - box, - zone // - ); - if (!result) - { - // - box.Clean(); - return result; - } - - // - // Checking Index in SupplyZones ... - int idx = FindIndex( - zone, - demandZones // - ); - result = !IsValidIndex(idx); - if (!result) - { - // - box.Clean(); - return result; - } - - // - result = IsExists(box); - - // - box.Clean(); - - // - return result; - } - - // - void UpdateTo(datetime value = NULL) - { - // - value = NormalizeTime(value); - - // - int count = 0; - bool has = false; - - // - has = HasSupplyZone(); - if (has) - { - supplyZone.To(value); - } - - // - has = HasDemandZone(); - if (has) - { - demandZone.To(value); - } - - // - has = HasSupplyZones(); - if (has) - { - // - count = CountSupplyZones(); - for (int i = 0; i < count; i++) - { - supplyZones[i].To(value); - } - } - - // - has = HasDemandZones(); - if (has) - { - // - count = CountDemandZones(); - for (int i = 0; i < count; i++) - { - demandZones[i].To(value); - } - } - - // - has = HasSupportZones(); - if (has) - { - // - count = CountSupportZones(); - for (int i = 0; i < count; i++) - { - supportZones[i].To(value); - } - } - - // - has = HasResistanceZones(); - if (has) - { - // - count = CountResistanceZones(); - for (int i = 0; i < count; i++) - { - resistanceZones[i].To(value); - } - } - - // - // - // - - // - has = HasWaitingBoxes(); - if (has) - { - // - count = ArraySize(waitingBoxes); - for (int i = 0; i < count; i++) - { - waitingBoxes[i].to = value; - } - } - - // - has = HasInsideBoxes(); - if (has) - { - // - count = CountInsideBoxes(); - for (int i = 0; i < count; i++) - { - insideBoxes[i].to = value; - } - } - - // - has = HasBreakedBoxes(); - if (has) - { - } - - // - has = HasBreakedInsideBoxes(); - if (has) - { - // - count = CountBreakedInsideBoxes(); - for (int i = 0; i < count; i++) - { - breakedInsideBoxes[i].to = value; - } - } - - // - } - - // - void Draw( - XCPOIDrawer *drawer, - bool drawWaitingBoxes = true, - bool drawInsideBoxes = false, - bool drawBreakedBoxes = false, - bool drawBreakedInsideBoxes = false, - bool drawSupplyZone = false, - bool drawDemandZone = false, - bool drawSupplyZones = false, - bool drawDemandZones = false, - bool drawSupportZones = false, - bool drawResistanceZones = false // - ) - { - // - if (drawer == NULL) - { - return; - } - - // - int count = 0; - bool has = false; - bool isCreated = false; - - // - ulong chartID = drawer.ChartIdentification(); - int subWindow = drawer.SubWindowIdentification(); - color bullishColor = drawer.BarBullishColor(); - color bearishColor = drawer.BarBearishColor(); - - // - // Supply Zone ... - if (drawSupplyZone) - { - // - has = HasSupplyZone(); - if (has) - { - // - XCSupplyZoneObject *iObj; - isCreated = drawer.CreateSupplyZone( - supplyZone, - iObj // - ); - - // - if (isCreated) - { - mWorkingZoneObjects.Add(iObj); - } - } - } - - // - // Demand Zone ... - if (drawDemandZone) - { - // - has = HasDemandZone(); - if (has) - { - // - XCDemandZoneObject *iObj; - isCreated = drawer.CreateDemandZone( - demandZone, - iObj // - ); - - // - if (isCreated) - { - mWorkingZoneObjects.Add(iObj); - } - } - } - - // - // - // - - // - // Supply Zones ... - if (drawSupplyZones) - { - // - has = HasSupplyZones(); - if (has) - { - // - count = CountSupplyZones(); - for (int i = 0; i < count; i++) - { - // - XCSupplyZoneObject *iObj; - isCreated = drawer.CreateSupplyZone( - supplyZones[i], - iObj // - ); - - // - if (isCreated) - { - mWorkingZoneObjects.Add(iObj); - } - } - } - } - - // - // Demand Zones ... - if (drawDemandZones) - { - // - has = HasDemandZones(); - if (has) - { - // - count = CountDemandZones(); - for (int i = 0; i < count; i++) - { - // - XCDemandZoneObject *iObj; - isCreated = drawer.CreateDemandZone( - demandZones[i], - iObj // - ); - - // - if (isCreated) - { - mWorkingZoneObjects.Add(iObj); - } - } - } - } - - // - // Support Zones ... - if (drawSupportZones) - { - // - has = HasSupportZones(); - if (has) - { - // - count = CountSupportZones(); - for (int i = 0; i < count; i++) - { - // - XCSupportZoneObject *iObj; - isCreated = drawer.CreateSupportZone( - supportZones[i], - iObj // - ); - - // - if (isCreated) - { - mWorkingZoneObjects.Add(iObj); - } - } - } - } - - // - // Resistance Zones ... - if (drawResistanceZones) - { - // - has = HasResistanceZones(); - if (has) - { - // - count = CountResistanceZones(); - for (int i = 0; i < count; i++) - { - // - XCResistanceZoneObject *iObj; - isCreated = drawer.CreateResistanceZone( - resistanceZones[i], - iObj // - ); - - // - if (isCreated) - { - mWorkingZoneObjects.Add(iObj); - } - } - } - } - - // - // - // - - // - // Waiting Boxes ... - if (drawWaitingBoxes) - { - // - has = HasWaitingBoxes(); - if (has) - { - // - count = CountWaitingBoxes(); - for (int i = 0; i < count; i++) - { - // - XBoxZone iBox = waitingBoxes[i]; - - // - XCBoxObject *iObj; - bool isCreated = drawer.DrawBox( - iBox, - iObj // - ); - - // - if (isCreated) - { - mWorkingZoneObjects.Add(iObj); - } - - // - iBox.Clean(); - } - } - } - - // - // Inside Boxes ... - if (drawInsideBoxes) - { - // - has = HasInsideBoxes(); - if (has) - { - } - } - - // - // Breaked Boxes ... - if (drawBreakedBoxes) - { - // - has = HasBreakedBoxes(); - if (has) - { - // - } - } - - // - // Breaked Inside Boxes ... - if (drawBreakedInsideBoxes) - { - // - has = HasBreakedInsideBoxes(); - if (has) - { - // - count = CountBreakedInsideBoxes(); - for (int i = 0; i < count; i++) - { - // - XBoxZone iBox = breakedInsideBoxes[i]; - XCBoxObject *iObj; - has = drawer.DrawBox( - iBox, - iObj // - ); - if (has) - { - // - iObj.BoxWidth(1); - mBreakedInsideZoneObjects.Add(iObj); - } - } - } - } - - // - // - // - - // - // Quarters ... - has = IsValid(); - if (has) - { - // - double zoneUpper = supplyZone.Upper(); - double upper = supplyZone.Lower(); - - // - double lower = demandZone.Upper(); - double zoneLower = demandZone.Lower(); - - // - string prefix = "X121WZone_" + symbol + "_" + ToString(period); - - // - // Zone Upper ... - CChartObjectHLine *zoneUpperLine; - zoneUpperLine = new CChartObjectHLine(); - isCreated = zoneUpperLine.Create( - chartID, - prefix + "_ZoneTop", - subWindow, - zoneUpper // - ); - if (isCreated) - { - // - zoneUpperLine.Color(clrRed); - - // - mWaitingZoneObjects.Add(zoneUpperLine); - } - - // - // Zone Lower ... - CChartObjectHLine *zoneLowerLine; - zoneLowerLine = new CChartObjectHLine(); - isCreated = zoneLowerLine.Create( - chartID, - prefix + "_ZoneDown", - subWindow, - zoneLower // - ); - if (isCreated) - { - // - zoneLowerLine.Color(clrRed); - - // - mWaitingZoneObjects.Add(zoneLowerLine); - } - - // - // Upper ... - CChartObjectHLine *upperLine; - upperLine = new CChartObjectHLine(); - isCreated = upperLine.Create( - chartID, - prefix + "_Upper", - subWindow, - upper // - ); - if (isCreated) - { - // - upperLine.Color(clrLime); - - // - mWaitingZoneObjects.Add(upperLine); - } - - // - // Lower ... - CChartObjectHLine *lowerLine; - lowerLine = new CChartObjectHLine(); - isCreated = lowerLine.Create( - chartID, - prefix + "_Lower", - subWindow, - lower // - ); - if (isCreated) - { - // - lowerLine.Color(clrLime); - - // - mWaitingZoneObjects.Add(lowerLine); - } - - // - // Quarters ... - - // - // Quarter 1 ... - CChartObjectHLine *q1Line; - q1Line = new CChartObjectHLine(); - isCreated = q1Line.Create( - chartID, - prefix + "_Q1", - subWindow, - quarter1 // - ); - if (isCreated) - { - // - q1Line.Color(clrYellow); - - // - mWaitingZoneObjects.Add(q1Line); - } - - // - // Quarter 2 ... - CChartObjectHLine *q2Line; - q2Line = new CChartObjectHLine(); - isCreated = q2Line.Create( - chartID, - prefix + "_Q2", - subWindow, - quarter2 // - ); - if (isCreated) - { - // - q2Line.Color(clrYellow); - - // - mWaitingZoneObjects.Add(q2Line); - } - - // - // Quarter 3 ... - CChartObjectHLine *q3Line; - q3Line = new CChartObjectHLine(); - isCreated = q3Line.Create( - chartID, - prefix + "_Q3", - subWindow, - quarter3 // - ); - if (isCreated) - { - // - q3Line.Color(clrYellow); - - // - mWaitingZoneObjects.Add(q3Line); - } - } - } - - // - // - // - - // - bool HasSupplyZone() - { - return supplyZone != NULL && - supplyZone.IsValid(); - } - - // - bool HasDemandZone() - { - return demandZone != NULL && - demandZone.IsValid(); - } - - // - bool HasSupplyZones() - { - return HasChild(supplyZones); - } - - // - int CountSupplyZones() - { - return ArraySize(supplyZones); - } - - // - bool HasDemandZones() - { - return HasChild(demandZones); - } - - // - int CountDemandZones() - { - return ArraySize(demandZones); - } - - // - bool HasSupportZones() - { - return HasChild(supportZones); - } - - // - int CountSupportZones() - { - return ArraySize(supportZones); - } - - // - bool HasResistanceZones() - { - return HasChild(resistanceZones); - } - - // - int CountResistanceZones() - { - return ArraySize(resistanceZones); - } - - // - bool HasConsolidationZones() - { - return HasChild(consolidationZones); - } - - // - int CountConsolidationZones() - { - return ArraySize(consolidationZones); - } - - // - bool HasWaitingBoxes() - { - return HasChild(waitingBoxes); - } - - // - int CountWaitingBoxes() - { - return ArraySize(waitingBoxes); - } - - // - bool HasInsideBoxes() - { - return HasChild(insideBoxes); - } - - // - int CountInsideBoxes() - { - return ArraySize(insideBoxes); - } - - // - bool HasBreakedBoxes() - { - return HasChild(breakedBoxes); - } - - // - int CountBreakedBoxes() - { - return ArraySize(breakedBoxes); - } - - // - bool HasBreakedInsideBoxes() - { - return HasChild(breakedInsideBoxes); - } - - // - int CountBreakedInsideBoxes() - { - return ArraySize(breakedInsideBoxes); - } - - // -}; - -// -struct X121SMCStrategyXWZSignalConditions -{ - // - // Props ... - - // - string symbol; - ENUM_TIMEFRAMES period; - - // - double sl; - double reward; - double amountPercent; - ENUM_X_DIRECTION dir; - ENUM_X_POSITION_TYPES type; - - // - // Setup Props ... - - // - datetime setupTime; - datetime triggerTime; - - // - double pivot; - double point; - double sls[]; - double targets[]; - - // - XBoxZone signalBox; - - // - ENUM_X121SMC_XWZ_PRIORITY priority; - ENUM_X121SMC_XWZ_PROVIDERS provider; - - // - // Constructor ... - X121SMCStrategyXWZSignalConditions() - { - Clean(); - } - - // - // Tools ... - - /** - * Cleaning Up ... - */ - void Clean() - { - // - sl = 0; - - // - dir = X_DIRECTION_NONE; - type = X_POSITION_TYPE_NONE; - - // - symbol = NULL; - period = NULL; - setupTime = NULL; - triggerTime = NULL; - - // - ExtensionClean(); - - // - ZeroMemory(this); - } - - /** - * Check Condition is Setting Up ... - * - * @param dir: ENUM_X_DIRECTION member, Setting Up Direction ... - * - * @return ( bool ) - */ - bool IsSetuped() - { - // - bool result = false; - - // - result = IsValid(setupTime) && - HasDirection(dir); - if (!result) - { - return result; - } - - // - return result; - } - - /** - * Calculate Setup Age ... - * - * @return ( int ) - */ - int GetSetupAge() - { - // - int result = 0; - - // - if (!IsSetuped()) - { - return result; - } - - // - result = (int)(TimeCurrent() - setupTime) / PeriodSeconds(period); - - // - return result; - } - - /** - * Detect How we Can Trigger Signal ... - * - * @return ( bool ) - */ - bool CanTrigger() - { - // - bool result = false; - - // - result = - // - sl > 0 && - IsValid(symbol) && - IsValid(period) && - IsValid(triggerTime) && - type != X_POSITION_TYPE_ALL && - type != X_POSITION_TYPE_NONE - // - ; - - // - return result; - } - - // - // Extensions ... - - /** - * Clean Additional Properties ... - */ - void ExtensionClean() - { - // - pivot = 0; - point = 0; - - // - reward = 0; - amountPercent = 0; - - // - Clean(sls); - Clean(targets); - signalBox.Clean(); - - // - provider = X121SMC_XWZ_PROVIDER_NONE; - } - - // - // - // - - // - void UpdateTo(datetime value = NULL) - { - // - value = NormalizeTime(value); - - // - int count = 0; - bool has = false; - } - - // -}; - -// -// Extension Functions ... - -// \ No newline at end of file diff --git a/Documents/BKP/x-121.smc.xwz.signal.lib copy.mq5 b/Documents/BKP/x-121.smc.xwz.signal.lib copy.mq5 deleted file mode 100644 index fd0c9ab4..00000000 --- a/Documents/BKP/x-121.smc.xwz.signal.lib copy.mq5 +++ /dev/null @@ -1,4871 +0,0 @@ -/////////////////////////////////////////////////////// -// -// SaherElm IT Center MQL5 X121 SMC Signal Class -// ------------------------------------------------- -// Name: XWZ -// Description: provide all Signalling functions ... -// -// -// Maintainer: -// ------------ -// Hadi Khazaee Asl (hadi_khazaee_asl@yahoo.com) -// -////////////////////////////////////////////////////// -// -// Global Properties ... -#property library -#property copyright "Copyright 2023, SaherElm IT Center" -#property link "https://www.saherelm.ir" -#property version "1.00" -#property strict - -// -// Imports ... -// #include "../../Libraries/x-trade.lib" -#include "../Classes/x-121.smc.market.cycle.helper.class.mq5" -#include "../Libraries/x-121.smc.guard.lib.mq5" -#include "../Libraries/x-121.smc.lib.mq5" - -// -enum ENUM_X121SMC_XWZ_PROVIDERS -{ - X121SMC_XWZ_PROVIDER_NONE, - X121SMC_XWZ_PROVIDER_ACTIVATED_ZONE, - X121SMC_XWZ_PROVIDER_ACTIVATED_CHOCH, - X121SMC_XWZ_PROVIDER_PRICE_INSIDE_ZONE, -}; - -// -enum ENUM_X121SMC_XWZ_PRIORITY -{ - X121SMC_XWZ_PRIORITY_NONE, - X121SMC_XWZ_PRIORITY_WEAK, - X121SMC_XWZ_PRIORITY_LOW, - X121SMC_XWZ_PRIORITY_REGULAR, - X121SMC_XWZ_PRIORITY_HIGH, - X121SMC_XWZ_PRIORITY_STRONG_HIGH, -}; - -// -struct X121SMCStrategyXWZWorkingZone -{ - // - // Props ... - - // - string symbol; - ENUM_TIMEFRAMES period; - - // - double quarter1; - double quarter2; - double quarter3; - - // - XCSupplyZone *supplyZone; - XCDemandZone *demandZone; - - // - XCSupplyZone *supplyZones[]; - XCDemandZone *demandZones[]; - - // - XCSupportZone *supportZones[]; - XCResistanceZone *resistanceZones[]; - - // - XOBFVG insideZones[]; - XOBFVG breakedZones[]; - XOBFVG waitingZones[]; - - // - XBoxZone insideBoxes[]; - XBoxZone breakedBoxes[]; - XConsolidationZone consolidationZones[]; - - // - CArrayObj mInsideZoneObjects; - CArrayObj mBreakedZoneObjects; - CArrayObj mWaitingZoneObjects; - CArrayObj mWorkingZoneObjects; - - // - // Constructor ... - X121SMCStrategyXWZWorkingZone() - { - Clean(); - } - - // - // Tools ... - - // - void Clean() - { - // - quarter1 = 0; - quarter2 = 0; - quarter3 = 0; - - // - symbol = NULL; - period = NULL; - - // - Clean(supplyZones); - Clean(demandZones); - - // - Clean(insideZones); - Clean(waitingZones); - Clean(breakedZones); - - // - Clean(insideBoxes); - Clean(breakedBoxes); - - // - Clean(supportZones); - Clean(resistanceZones); - - // - ZeroMemory(supplyZone); - ZeroMemory(demandZone); - - // - mInsideZoneObjects.Clear(); - mBreakedZoneObjects.Clear(); - mWaitingZoneObjects.Clear(); - mWorkingZoneObjects.Clear(); - } - - // - bool IsValid() - { - // - bool result = false; - - // - result = - // - quarter1 > 0 && - quarter2 > 0 && - quarter3 > 0 && - HasSupplyZone() && - HasDemandZone() && - quarter1 > quarter2 && - quarter2 > quarter3 - // - ; - - // - return result; - } - - // - bool Init( - string _symbol, - ENUM_TIMEFRAMES _period, - int barIndex, - XPOIState &htfState, - XPOIState &mtfState, - XPOIState &stfState, // - XPOIState &ttfState // - ) - { - // - bool result = false; - - // - if (barIndex < 0) - { - barIndex = 0; - } - - // - result = - // - IsValid(_symbol) && - IsValid(_period) && - // - htfState.IsValid() && - mtfState.IsValid() && - stfState.IsValid() && - ttfState.IsValid() && - // - htfState.HasChild() && - mtfState.HasChild() && - stfState.HasChild() && - ttfState.HasChild() - // - ; - if (!result) - { - return result; - } - - // - symbol = _symbol; - period = _period; - - // - int idx = -1; - int count = 0; - bool has = false; - - // - XOHCL zBar; - has = zBar.Init( - symbol, - period, - barIndex // - ); - result = has; - if (!result) - { - zBar.Clean(); - return result; - } - double ll5 = zBar.FindLowest(5, MODE_LOW); - double hh5 = zBar.FindHighest(5, MODE_HIGH); - zBar.Clean(); - - // - // Supply Zone ... - has = HasSupplyZone(); - if (!has) - { - // - idx = GetHighest(htfState.supplyZones); - has = IsValidIndex(idx); - if (has) - { - // - supplyZone = htfState.supplyZones[idx]; - has = hh5 < supplyZone.Lower(); - if (!has) - { - supplyZone = NULL; - } - } - } - - // - // Demand Zone ... - has = HasDemandZone(); - if (!has) - { - // - idx = GetLowest(htfState.demandZones); - has = IsValidIndex(idx); - if (has) - { - // - demandZone = htfState.demandZones[idx]; - has = ll5 > demandZone.Upper(); - if (!has) - { - demandZone = NULL; - } - } - } - - // - // Supply Zones ... - has = HasSupplyZones(); - if (!has) - { - // - count = mtfState.FilterSupplyZones( - supplyZones, - period, - XZONE_STATE_PASSED, - false, - XZONE_STATE_FAILED, - false, - XZONE_STATE_FAILED, - false, - XZONE_STATE_IGNORED, - false // - ); - } - - // - // Demand Zones ... - has = HasDemandZones(); - if (!has) - { - // - count = mtfState.FilterDemandZones( - demandZones, - period, - XZONE_STATE_PASSED, - false, - XZONE_STATE_FAILED, - false, - XZONE_STATE_FAILED, - false, - XZONE_STATE_IGNORED, - false // - ); - } - - // // - // // Support Zones ... - // has = HasSupportZones(); - // if (!has) - // { - // // - // count = stfState.FilterSupportZones( - // supportZones, - // period, - // XZONE_STATE_PASSED, - // false, - // XZONE_STATE_FAILED, - // false, - // XZONE_STATE_FAILED, - // false, - // XZONE_STATE_IGNORED, - // false // - // ); - // } - - // // - // // Resistance Zones ... - // has = HasResistanceZones(); - // if (!has) - // { - // // - // count = stfState.FilterResistanceZones( - // resistanceZones, - // period, - // XZONE_STATE_PASSED, - // false, - // XZONE_STATE_FAILED, - // false, - // XZONE_STATE_FAILED, - // false, - // XZONE_STATE_IGNORED, - // false // - // ); - // } - - // - has = ttfState.HasConsolidationZones(); - if (has) - { - // - Copy( - ttfState.consolidationZones, - consolidationZones // - ); - CleanupArray( - consolidationZones, - 50 // - ); - } - - // - if (supplyZone != NULL && - demandZone != NULL && - supplyZone.IsValid() && - demandZone.IsValid()) - { - // - double upper = supplyZone.Lower(); - double lower = demandZone.Upper(); - - // - double delta = ((upper - lower) / 100) * 25; - - // - quarter1 = upper - (1 * delta); - quarter2 = upper - (2 * delta); - quarter3 = upper - (3 * delta); - } - - // - // Detect OBFVG(s) ... - ExtractOBFVGs( - waitingZones, - mtfState, - stfState - // , - // X_OBFVG_FVG_FILTER_ABOVE_BELOW, - // X_OBFVG_FVG_SELECT_HIGHEST_LOWEST // - ); - - // // - // // Detect Waiting Zones based on STF and TTF ... - // XOBFVG tmpWaitingZones[]; - // count = ExtractOBFVGs( - // tmpWaitingZones, - // stfState, - // stfState // - // ); - // 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) - { - Clean(); - } - - // - return result; - } - - // - void Update( - int barIndex, - XPOIState &htfState, - XPOIState &mtfState, - XPOIState &stfState, - XPOIState &ttfState // - ) - { - // - int idx = -1; - int count = 0; - bool has = false; - - // - if (barIndex < 0) - { - barIndex = 0; - } - - // - has = - // - IsValid() && - // - htfState.IsValid() && - mtfState.IsValid() && - stfState.IsValid() && - // - htfState.HasChild() && - mtfState.HasChild() && - stfState.HasChild() - // - ; - if (!has) - { - return; - } - - // - XOHCL zBar; - has = zBar.Init( - symbol, - period, - barIndex // - ); - if (!has) - { - // - zBar.Clean(); - return; - } - - // - XOHCL cBar; - has = zBar.GetPreviousBar(cBar); - if (!has) - { - // - zBar.Clean(); - cBar.Clean(); - - // - return; - } - - // - // Adding New OBFVG to Waiting Zones if not Exists ... - XOBFVG tmpWaitingZones[]; - count = ExtractOBFVGs( - tmpWaitingZones, - mtfState, - stfState - // , - // X_OBFVG_FVG_FILTER_ABOVE_BELOW, - // X_OBFVG_FVG_SELECT_HIGHEST_LOWEST // - ); - has = IsValidSize(count); - if (has) - { - // - AddIfNotExists( - tmpWaitingZones, - waitingZones // - ); - } - - // - // Detect Waiting Zones based on STF and TTF ... - // Clean(tmpWaitingZones); - // count = ExtractOBFVGs( - // tmpWaitingZones, - // stfState, - // ttfState // - // ); - // has = IsValidSize(count); - // if (has) - // { - // // - // AddIfNotExists( - // tmpWaitingZones, - // waitingZones // - // ); - // } - - // - // Detect Waiting Zones based on TTF and TTF ... - // Clean(tmpWaitingZones); - // count = ExtractOBFVGs( - // tmpWaitingZones, - // stfState, - // stfState // - // ); - // has = IsValidSize(count); - // if (has) - // { - // // - // AddIfNotExists( - // tmpWaitingZones, - // waitingZones // - // ); - // } - - // - // Since Usig States for Extracting Supply/Demand or - // Support/Resistance Zones and State's has Max Alllowed Restrication ... - // we have to Manage new Zones and also Hold's Breaked Zones ... - - // - // MTF STF ... - - // - // Supply Zones ... - XCSupplyZone *tmpSupplies[]; - count = mtfState.FilterSupplyZones( - tmpSupplies, - NULL, - XZONE_STATE_PASSED, - false, - XZONE_STATE_FAILED, - false, - XZONE_STATE_FAILED, - false, - XZONE_STATE_IGNORED, - false // - ); - has = IsValidSize(count); - if (has) - { - // - for (int i = 0; i < count; i++) - { - // - XBoxZone iBox; - has = ToBox( - iBox, - tmpSupplies[i] // - ); - if (!has) - { - // - iBox.Clean(); - continue; - } - - // - // Find Index ... - - // - idx = FindIndex( - iBox, - insideBoxes // - ); - has = !IsValidIndex(idx); - if (!has) - { - // - iBox.Clean(); - continue; - } - - // - idx = FindIndex( - iBox, - breakedBoxes // - ); - has = !IsValidIndex(idx); - if (!has) - { - // - iBox.Clean(); - continue; - } - - // - idx = FindIndex( - tmpSupplies[i], - supplyZones // - ); - has = !IsValidIndex(idx); - if (!has) - { - // - iBox.Clean(); - continue; - } - - // - // Checking Price Validation ... - has = cBar.high < tmpSupplies[i].Lower(); - if (!has) - { - // - iBox.Clean(); - continue; - } - - // - Add( - tmpSupplies[i], - supplyZones // - ); - - // - iBox.Clean(); - } - } - Clean(tmpSupplies); - - // - // Demand Zones ... - XCDemandZone *tmpDemands[]; - count = mtfState.FilterDemandZones( - tmpDemands, - NULL, - XZONE_STATE_PASSED, - false, - XZONE_STATE_FAILED, - false, - XZONE_STATE_FAILED, - false, - XZONE_STATE_IGNORED, - false // - ); - has = IsValidSize(count); - if (has) - { - // - for (int i = 0; i < count; i++) - { - // - XBoxZone iBox; - has = ToBox( - iBox, - tmpDemands[i] // - ); - if (!has) - { - // - iBox.Clean(); - continue; - } - - // - // Find Index ... - - // - idx = FindIndex( - iBox, - insideBoxes // - ); - has = !IsValidIndex(idx); - if (!has) - { - // - iBox.Clean(); - continue; - } - - // - idx = FindIndex( - iBox, - breakedBoxes // - ); - has = !IsValidIndex(idx); - if (!has) - { - // - iBox.Clean(); - continue; - } - - // - idx = FindIndex( - tmpDemands[i], - demandZones // - ); - has = !IsValidIndex(idx); - if (!has) - { - // - iBox.Clean(); - continue; - } - - // - // Checking Price Validation ... - has = cBar.low > tmpDemands[i].Upper(); - if (!has) - { - // - iBox.Clean(); - continue; - } - - // - Add( - tmpDemands[i], - demandZones // - ); - - // - iBox.Clean(); - } - } - Clean(tmpDemands); - - // // - // // Support Zones ... - // XCSupportZone *tmpSupports[]; - // count = stfState.FilterSupportZones( - // tmpSupports, - // period, - // XZONE_STATE_PASSED, - // false, - // XZONE_STATE_FAILED, - // false, - // XZONE_STATE_FAILED, - // false, - // XZONE_STATE_IGNORED, - // false // - // ); - // has = IsValidSize(count); - // if (has) - // { - // // - // for (int i = 0; i < count; i++) - // { - // // - // XBoxZone iBox; - // has = ToBox( - // iBox, - // tmpSupports[i] // - // ); - // if (!has) - // { - // // - // iBox.Clean(); - // continue; - // } - - // // - // // Find Index ... - - // // - // idx = FindIndex( - // iBox, - // insideBoxes // - // ); - // has = !IsValidIndex(idx); - // if (!has) - // { - // // - // iBox.Clean(); - // continue; - // } - - // // - // idx = FindIndex( - // iBox, - // breakedBoxes // - // ); - // has = !IsValidIndex(idx); - // if (!has) - // { - // // - // iBox.Clean(); - // continue; - // } - - // // - // idx = FindIndex( - // tmpSupports[i], - // supportZones // - // ); - // has = !IsValidIndex(idx); - // if (!has) - // { - // // - // iBox.Clean(); - // continue; - // } - - // // - // // Checking Price Validation ... - // has = cBar.low > tmpSupports[i].Upper(); - // if (!has) - // { - // // - // iBox.Clean(); - // continue; - // } - - // // - // Add( - // tmpSupports[i], - // supportZones // - // ); - - // // - // iBox.Clean(); - // } - // } - // Clean(tmpSupports); - - // // - // // Resistance Zones .. - // XCResistanceZone *tmpResistances[]; - // count = stfState.FilterResistanceZones( - // tmpResistances, - // period, - // XZONE_STATE_PASSED, - // false, - // XZONE_STATE_FAILED, - // false, - // XZONE_STATE_FAILED, - // false, - // XZONE_STATE_IGNORED, - // false // - // ); - // has = IsValidSize(count); - // if (has) - // { - // // - // for (int i = 0; i < count; i++) - // { - // // - // XBoxZone iBox; - // has = ToBox( - // iBox, - // tmpResistances[i] // - // ); - // if (!has) - // { - // // - // iBox.Clean(); - // continue; - // } - - // // - // // Find Index ... - - // // - // idx = FindIndex( - // iBox, - // insideBoxes // - // ); - // has = !IsValidIndex(idx); - // if (!has) - // { - // // - // iBox.Clean(); - // continue; - // } - - // // - // idx = FindIndex( - // iBox, - // breakedBoxes // - // ); - // has = !IsValidIndex(idx); - // if (!has) - // { - // // - // iBox.Clean(); - // continue; - // } - - // // - // idx = FindIndex( - // tmpResistances[i], - // resistanceZones // - // ); - // has = !IsValidIndex(idx); - // if (!has) - // { - // // - // iBox.Clean(); - // continue; - // } - - // // - // // Checking Price Validation ... - // has = cBar.high < tmpResistances[i].Lower(); - // if (!has) - // { - // // - // iBox.Clean(); - // continue; - // } - - // // - // Add( - // tmpResistances[i], - // resistanceZones // - // ); - - // // - // iBox.Clean(); - // } - // } - // Clean(tmpResistances); - - // - // STF TTF ... - - // // - // // Supply Zones ... - // count = stfState.FilterSupplyZones( - // tmpSupplies, - // NULL, - // XZONE_STATE_PASSED, - // false, - // XZONE_STATE_FAILED, - // false, - // XZONE_STATE_FAILED, - // false, - // XZONE_STATE_IGNORED, - // false // - // ); - // has = IsValidSize(count); - // if (has) - // { - // // - // for (int i = 0; i < count; i++) - // { - // // - // XBoxZone iBox; - // has = ToBox( - // iBox, - // tmpSupplies[i] // - // ); - // if (!has) - // { - // // - // iBox.Clean(); - // continue; - // } - - // // - // // Find Index ... - - // // - // idx = FindIndex( - // iBox, - // insideBoxes // - // ); - // has = !IsValidIndex(idx); - // if (!has) - // { - // // - // iBox.Clean(); - // continue; - // } - - // // - // idx = FindIndex( - // iBox, - // breakedBoxes // - // ); - // has = !IsValidIndex(idx); - // if (!has) - // { - // // - // iBox.Clean(); - // continue; - // } - - // // - // idx = FindIndex( - // tmpSupplies[i], - // supplyZones // - // ); - // has = !IsValidIndex(idx); - // if (!has) - // { - // // - // iBox.Clean(); - // continue; - // } - - // // - // // Checking Price Validation ... - // has = cBar.high < tmpSupplies[i].Lower(); - // if (!has) - // { - // // - // iBox.Clean(); - // continue; - // } - - // // - // Add( - // tmpSupplies[i], - // supplyZones // - // ); - - // // - // iBox.Clean(); - // } - // } - // Clean(tmpSupplies); - - // // - // // Demand Zones ... - // count = stfState.FilterDemandZones( - // tmpDemands, - // NULL, - // XZONE_STATE_PASSED, - // false, - // XZONE_STATE_FAILED, - // false, - // XZONE_STATE_FAILED, - // false, - // XZONE_STATE_IGNORED, - // false // - // ); - // has = IsValidSize(count); - // if (has) - // { - // // - // for (int i = 0; i < count; i++) - // { - // // - // XBoxZone iBox; - // has = ToBox( - // iBox, - // tmpDemands[i] // - // ); - // if (!has) - // { - // // - // iBox.Clean(); - // continue; - // } - - // // - // // Find Index ... - - // // - // idx = FindIndex( - // iBox, - // insideBoxes // - // ); - // has = !IsValidIndex(idx); - // if (!has) - // { - // // - // iBox.Clean(); - // continue; - // } - - // // - // idx = FindIndex( - // iBox, - // breakedBoxes // - // ); - // has = !IsValidIndex(idx); - // if (!has) - // { - // // - // iBox.Clean(); - // continue; - // } - - // // - // idx = FindIndex( - // tmpDemands[i], - // demandZones // - // ); - // has = !IsValidIndex(idx); - // if (!has) - // { - // // - // iBox.Clean(); - // continue; - // } - - // // - // // Checking Price Validation ... - // has = cBar.low > tmpDemands[i].Upper(); - // if (!has) - // { - // // - // iBox.Clean(); - // continue; - // } - - // // - // Add( - // tmpDemands[i], - // demandZones // - // ); - - // // - // iBox.Clean(); - // } - // } - // Clean(tmpDemands); - - // // - // // Support Zones ... - // count = ttfState.FilterSupportZones( - // tmpSupports, - // period, - // XZONE_STATE_PASSED, - // false, - // XZONE_STATE_FAILED, - // false, - // XZONE_STATE_FAILED, - // false, - // XZONE_STATE_IGNORED, - // false // - // ); - // has = IsValidSize(count); - // if (has) - // { - // // - // for (int i = 0; i < count; i++) - // { - // // - // XBoxZone iBox; - // has = ToBox( - // iBox, - // tmpSupports[i] // - // ); - // if (!has) - // { - // // - // iBox.Clean(); - // continue; - // } - - // // - // // Find Index ... - - // // - // idx = FindIndex( - // iBox, - // insideBoxes // - // ); - // has = !IsValidIndex(idx); - // if (!has) - // { - // // - // iBox.Clean(); - // continue; - // } - - // // - // idx = FindIndex( - // iBox, - // breakedBoxes // - // ); - // has = !IsValidIndex(idx); - // if (!has) - // { - // // - // iBox.Clean(); - // continue; - // } - - // // - // idx = FindIndex( - // tmpSupports[i], - // supportZones // - // ); - // has = !IsValidIndex(idx); - // if (!has) - // { - // // - // iBox.Clean(); - // continue; - // } - - // // - // // Checking Price Validation ... - // has = cBar.low > tmpSupports[i].Upper(); - // if (!has) - // { - // // - // iBox.Clean(); - // continue; - // } - - // // - // Add( - // tmpSupports[i], - // supportZones // - // ); - - // // - // iBox.Clean(); - // } - // } - // Clean(tmpSupports); - - // // - // // Resistance Zones .. - // count = ttfState.FilterResistanceZones( - // tmpResistances, - // period, - // XZONE_STATE_PASSED, - // false, - // XZONE_STATE_FAILED, - // false, - // XZONE_STATE_FAILED, - // false, - // XZONE_STATE_IGNORED, - // false // - // ); - // has = IsValidSize(count); - // if (has) - // { - // // - // for (int i = 0; i < count; i++) - // { - // // - // XBoxZone iBox; - // has = ToBox( - // iBox, - // tmpResistances[i] // - // ); - // if (!has) - // { - // // - // iBox.Clean(); - // continue; - // } - - // // - // // Find Index ... - - // // - // idx = FindIndex( - // iBox, - // insideBoxes // - // ); - // has = !IsValidIndex(idx); - // if (!has) - // { - // // - // iBox.Clean(); - // continue; - // } - - // // - // idx = FindIndex( - // iBox, - // breakedBoxes // - // ); - // has = !IsValidIndex(idx); - // if (!has) - // { - // // - // iBox.Clean(); - // continue; - // } - - // // - // idx = FindIndex( - // tmpResistances[i], - // resistanceZones // - // ); - // has = !IsValidIndex(idx); - // if (!has) - // { - // // - // iBox.Clean(); - // continue; - // } - - // // - // // Checking Price Validation ... - // has = cBar.high < tmpResistances[i].Lower(); - // if (!has) - // { - // // - // iBox.Clean(); - // continue; - // } - - // // - // Add( - // tmpResistances[i], - // resistanceZones // - // ); - - // // - // iBox.Clean(); - // } - // } - // Clean(tmpResistances); - - // - // - // - - // - // Consolidation Zones ... - has = ttfState.HasConsolidationZones(); - if (has) - { - // - Copy( - ttfState.consolidationZones, - consolidationZones // - ); - CleanupArray( - consolidationZones, - 50 // - ); - } - - // - // - // - - // - // Detect Price Inside Zones ... - has = HasWaitingZones(); - if (has) - { - // - int mustRemove[]; - count = CountWaitingZones(); - for (int i = 0; i < count; i++) - { - // - XOBFVG iOBFVG = waitingZones[i]; - - // - bool isInside = - // - zBar.high < iOBFVG.ob.Upper() && - zBar.low > iOBFVG.ob.Lower() && - // - cBar.high < iOBFVG.ob.Upper() && - cBar.low > iOBFVG.ob.Lower() - // - ; - if (isInside) - { - // - idx = FindIndex( - iOBFVG, - insideZones // - ); - has = IsValidSize(idx); - if (!has) - { - // - Add( - i, - mustRemove // - ); - - // - AddRef( - iOBFVG, - insideZones // - ); - } - } - } - - // - has = HasChild(mustRemove); - if (has) - { - // - count = ArraySize(mustRemove); - for (int i = 0; i < count; i++) - { - // - ArrayRemove( - waitingZones, - mustRemove[i], - 1 // - ); - } - } - - // - Clean(mustRemove); - } - - // - // Here we Looking for Price Inside Supply or Demand Zones ... - - // - // Supply Zones ... - has = HasSupplyZones(); - if (has) - { - // - int mustRemove[]; - count = CountSupplyZones(); - for (int i = 0; i < count; i++) - { - // - XCSupplyZone *iZone = supplyZones[i]; - - // - bool isInside = - // - zBar.high < iZone.Upper() && - zBar.low > iZone.Lower() && - // - cBar.high < iZone.Upper() && - cBar.low > iZone.Lower() - // - ; - if (isInside) - { - // - XBoxZone iBox; - has = ToBox( - iBox, - iZone // - ); - if (has) - { - // - idx = FindIndex( - iBox, - insideBoxes // - ); - has = IsValidSize(idx); - if (!has) - { - // - Add( - i, - mustRemove // - ); - - // - AddRef( - iBox, - insideBoxes // - ); - } - } - - // - iBox.Clean(); - } - } - - // - has = HasChild(mustRemove); - if (has) - { - // - count = ArraySize(mustRemove); - for (int i = 0; i < count; i++) - { - // - ArrayRemove( - supplyZones, - mustRemove[i], - 1 // - ); - } - } - - // - Clean(mustRemove); - } - - // - // Demand Zones ... - has = HasDemandZones(); - if (has) - { - // - int mustRemove[]; - count = CountDemandZones(); - for (int i = 0; i < count; i++) - { - // - XCDemandZone *iZone = demandZones[i]; - - // - bool isInside = - // - zBar.high < iZone.Upper() && - zBar.low > iZone.Lower() && - // - cBar.high < iZone.Upper() && - cBar.low > iZone.Lower() - // - ; - if (isInside) - { - // - XBoxZone iBox; - has = ToBox( - iBox, - iZone // - ); - if (has) - { - // - idx = FindIndex( - iBox, - insideBoxes // - ); - has = IsValidSize(idx); - if (!has) - { - // - Add( - i, - mustRemove // - ); - - // - AddRef( - iBox, - insideBoxes // - ); - } - } - - // - iBox.Clean(); - } - } - - // - has = HasChild(mustRemove); - if (has) - { - // - count = ArraySize(mustRemove); - for (int i = 0; i < count; i++) - { - // - ArrayRemove( - demandZones, - mustRemove[i], - 1 // - ); - } - } - - // - Clean(mustRemove); - } - - // - // Here we Detect Breaked Zone/Box (s) ... - - // - // Detect Breaked Zones ... - has = HasInsideZones(); - if (has) - { - // - int mustRemove[]; - count = CountInsideZones(); - for (int i = 0; i < count; i++) - { - // - XOBFVG iOBFVG = insideZones[i]; - ENUM_X_DIRECTION iDir = iOBFVG.GetDirection(); - bool isBullish = IsBullish(iDir); - - // - bool isBullishBreaked = - // - zBar.high < iOBFVG.ob.Lower() && - cBar.high < iOBFVG.ob.Lower() - // - ; - - // - bool isBearishBreaked = - // - zBar.low > iOBFVG.ob.Upper() && - cBar.low > iOBFVG.ob.Upper() - // - ; - - // - bool isBreaked = - isBullish - ? isBullishBreaked - : isBearishBreaked; - - // - if (isBreaked) - { - // - idx = FindIndex( - iOBFVG, - breakedZones // - ); - has = IsValidIndex(idx); - if (!has) - { - // - Add( - i, - mustRemove // - ); - - // - AddRef( - iOBFVG, - breakedZones // - ); - } - } - } - - // - has = HasChild(mustRemove); - if (has) - { - // - count = ArraySize(mustRemove); - for (int i = 0; i < count; i++) - { - // - ArrayRemove( - insideZones, - mustRemove[i], - 1 // - ); - } - } - - // - Clean(mustRemove); - } - - // - // Detect Breaked Boxes ... - has = HasInsideBoxes(); - if (has) - { - // - int mustRemove[]; - count = CountInsideBoxes(); - for (int i = 0; i < count; i++) - { - // - XBoxZone iBox = insideBoxes[i]; - ENUM_X_DIRECTION iDir = iBox.dir; - bool isBullish = iBox.IsBullish(); - - // - bool isBullishBreaked = - // - zBar.high < iBox.lower && - cBar.high < iBox.lower - // - ; - - // - bool isBearishBreaked = - // - zBar.low > iBox.upper && - cBar.low > iBox.upper - // - ; - - // - bool isBreaked = - isBullish - ? isBullishBreaked - : isBearishBreaked; - - // - if (isBreaked) - { - // - idx = FindIndex( - iBox, - breakedBoxes // - ); - has = IsValidIndex(idx); - if (!has) - { - // - Add( - i, - mustRemove // - ); - - // - AddRef( - iBox, - breakedBoxes // - ); - } - } - } - - // - has = HasChild(mustRemove); - if (has) - { - // - count = ArraySize(mustRemove); - for (int i = 0; i < count; i++) - { - // - ArrayRemove( - insideBoxes, - mustRemove[i], - 1 // - ); - } - } - - // - Clean(mustRemove); - } - - // - // Cleanup Resource ... - - // - zBar.Clean(); - cBar.Clean(); - } - - // - bool HasSupplyZone() - { - return supplyZone != NULL && - supplyZone.IsValid(); - } - - // - bool HasDemandZone() - { - return demandZone != NULL && - demandZone.IsValid(); - } - - // - bool HasSupplyZones() - { - return HasChild(supplyZones); - } - - // - int CountSupplyZones() - { - return ArraySize(supplyZones); - } - - // - bool HasDemandZones() - { - return HasChild(demandZones); - } - - // - int CountDemandZones() - { - return ArraySize(demandZones); - } - - // - bool HasSupportZones() - { - return HasChild(supportZones); - } - - // - int CountSupportZones() - { - return ArraySize(supportZones); - } - - // - bool HasResistanceZones() - { - return HasChild(resistanceZones); - } - - // - int CountResistanceZones() - { - return ArraySize(resistanceZones); - } - - // - bool HasWaitingZones() - { - return HasChild(waitingZones); - } - - // - int CountWaitingZones() - { - return ArraySize(waitingZones); - } - - // - bool HasInsideZones() - { - return HasChild(insideZones); - } - - // - int CountInsideZones() - { - return ArraySize(insideZones); - } - - // - bool HasBreakedZones() - { - return HasChild(breakedZones); - } - - // - int CountBreakedZones() - { - return ArraySize(breakedZones); - } - - // - bool HasConsolidationZones() - { - return HasChild(consolidationZones); - } - - // - int CountConsolidationZones() - { - return ArraySize(consolidationZones); - } - - // - bool HasInsideBoxes() - { - return HasChild(insideBoxes); - } - - // - int CountInsideBoxes() - { - return ArraySize(insideBoxes); - } - - // - bool HasBreakedBoxes() - { - return HasChild(breakedBoxes); - } - - // - int CountBreakedBoxes() - { - return ArraySize(breakedBoxes); - } - - // - // - // - - // - bool IsDestroyed( - int barIndex = 0, - ENUM_TIMEFRAMES forPeriod = NULL // - ) - { - // - bool result = false; - - // - if (barIndex < 0) - { - barIndex = 0; - } - - // - if (!IsValid(forPeriod)) - { - forPeriod = period; - } - - // - result = IsValid(); - if (!result) - { - return result; - } - - // - XOHCL bar; - result = bar.Init( - symbol, - period, - barIndex // - ); - if (!result) - { - // - bar.Clean(); - return result; - } - - // - XOHCL cBar; - result = bar.GetPreviousBar(cBar); - if (!result) - { - // - bar.Clean(); - cBar.Clean(); - - // - return result; - } - - // - bool isSupplyZoneBreaked = - // - bar.low > supplyZone.Upper() && - cBar.low > supplyZone.Upper() - // - ; - - // - bool isDemandZoneBreaked = - // - bar.high < demandZone.Lower() && - cBar.high < demandZone.Lower() - // - ; - - // - bar.Clean(); - cBar.Clean(); - - // - result = isSupplyZoneBreaked || - isDemandZoneBreaked; - - // - return result; - } - - // - bool DetectPriority( - ENUM_X121SMC_XWZ_PRIORITY &priority, - ENUM_X_DIRECTION forDir, - int barIndex = 0, - ENUM_TIMEFRAMES forPeriod = NULL // - ) - { - // - bool result = false; - - // - priority = X121SMC_XWZ_PRIORITY_NONE; - - // - if (barIndex < 0) - { - barIndex = 0; - } - - // - if (!IsValid(forPeriod)) - { - forPeriod = period; - } - - // - result = IsValid() && - HasDirection(forDir); - if (!result) - { - return result; - } - - // - bool isBullish = IsBullish(forDir); - - // - XOHCL bar; - result = bar.Init( - symbol, - forPeriod, - barIndex // - ); - if (!result) - { - // - bar.Clean(); - return result; - } - - // - if (bar.high < supplyZone.Upper() && - bar.low > supplyZone.Lower()) - { - // - priority = - isBullish - ? X121SMC_XWZ_PRIORITY_NONE - : X121SMC_XWZ_PRIORITY_STRONG_HIGH; - } - else if (bar.high < supplyZone.Lower() && - bar.low > quarter1) - { - // - priority = - isBullish - ? X121SMC_XWZ_PRIORITY_WEAK - : X121SMC_XWZ_PRIORITY_HIGH; - } - else if (bar.high < quarter1 && - bar.low > quarter2) - { - // - priority = - isBullish - ? X121SMC_XWZ_PRIORITY_LOW - : X121SMC_XWZ_PRIORITY_REGULAR; - } - else if (bar.high < quarter2 && - bar.low > quarter3) - { - // - priority = - isBullish - ? X121SMC_XWZ_PRIORITY_REGULAR - : X121SMC_XWZ_PRIORITY_LOW; - } - else if (bar.high < quarter3 && - bar.low > demandZone.Upper()) - { - // - priority = - isBullish - ? X121SMC_XWZ_PRIORITY_HIGH - : X121SMC_XWZ_PRIORITY_WEAK; - } - else if (bar.high < demandZone.Upper() && - bar.low > demandZone.Lower()) - { - // - priority = - isBullish - ? X121SMC_XWZ_PRIORITY_STRONG_HIGH - : X121SMC_XWZ_PRIORITY_NONE; - } - - // - result = priority != X121SMC_XWZ_PRIORITY_NONE && - priority != X121SMC_XWZ_PRIORITY_WEAK; - - // - bar.Clean(); - - // - return result; - } - - // - // - // - - // - void UpdateTo(datetime value = NULL) - { - // - value = NormalizeTime(value); - - // - int count = 0; - bool has = false; - - // - has = HasSupplyZone(); - if (has) - { - supplyZone.To(value); - } - - // - has = HasDemandZone(); - if (has) - { - demandZone.To(value); - } - - // - has = HasSupplyZones(); - if (has) - { - // - count = CountSupplyZones(); - for (int i = 0; i < count; i++) - { - supplyZones[i].To(value); - } - } - - // - has = HasDemandZones(); - if (has) - { - // - count = CountDemandZones(); - for (int i = 0; i < count; i++) - { - demandZones[i].To(value); - } - } - - // - has = HasSupportZones(); - if (has) - { - // - count = CountSupportZones(); - for (int i = 0; i < count; i++) - { - supportZones[i].To(value); - } - } - - // - has = HasResistanceZones(); - if (has) - { - // - count = CountResistanceZones(); - for (int i = 0; i < count; i++) - { - resistanceZones[i].To(value); - } - } - - // - has = HasWaitingZones(); - if (has) - { - // - count = CountWaitingZones(); - for (int i = 0; i < count; i++) - { - waitingZones[i].UpdateTo(value); - } - } - - // - has = HasInsideZones(); - if (has) - { - // - count = CountInsideZones(); - for (int i = 0; i < count; i++) - { - insideZones[i].UpdateTo(value); - } - } - - // - // has = HasBreakedZones(); - // if (has) - // { - // // - // count = CountBreakedZones(); - // for (int i = 0; i < count; i++) - // { - // breakedZones[i].UpdateTo(value); - // } - // } - - // - has = HasInsideBoxes(); - if (has) - { - // - count = CountInsideBoxes(); - for (int i = 0; i < count; i++) - { - insideBoxes[i].to = value; - } - } - - // - // has = HasBreakedBoxes(); - // if (has) - // { - // // - // count = CountBreakedBoxes(); - // for (int i = 0; i < count; i++) - // { - // insideBoxes[i].to = value; - // } - // } - - // - } - - // - void Draw( - XCPOIDrawer *drawer, - bool drawWaitingZones = true, - bool drawInsideZones = false, - bool drawBreakedZones = false, - bool drawSupplyZone = false, - bool drawDemandZone = false, - bool drawSupplyZones = false, - bool drawDemandZones = false, - bool drawSupportZones = false, - bool drawResistanceZones = false // - ) - { - // - if (drawer == NULL) - { - return; - } - - // - int count = 0; - bool has = false; - bool isCreated = false; - - // - ulong chartID = drawer.ChartIdentification(); - int subWindow = drawer.SubWindowIdentification(); - color bullishColor = drawer.BarBullishColor(); - color bearishColor = drawer.BarBearishColor(); - - // - // Supply Zone ... - if (drawSupplyZone) - { - // - has = HasSupplyZone(); - if (has) - { - // - XCSupplyZoneObject *iObj; - isCreated = drawer.CreateSupplyZone( - supplyZone, - iObj // - ); - - // - if (isCreated) - { - mWorkingZoneObjects.Add(iObj); - } - } - } - - // - // Demand Zone ... - if (drawDemandZone) - { - // - has = HasDemandZone(); - if (has) - { - // - XCDemandZoneObject *iObj; - isCreated = drawer.CreateDemandZone( - demandZone, - iObj // - ); - - // - if (isCreated) - { - mWorkingZoneObjects.Add(iObj); - } - } - } - - // - // - // - - // - // Supply Zones ... - if (drawSupplyZones) - { - // - has = HasSupplyZones(); - if (has) - { - // - count = CountSupplyZones(); - for (int i = 0; i < count; i++) - { - // - XCSupplyZoneObject *iObj; - isCreated = drawer.CreateSupplyZone( - supplyZones[i], - iObj // - ); - - // - if (isCreated) - { - mWorkingZoneObjects.Add(iObj); - } - } - } - } - - // - // Demand Zones ... - if (drawDemandZones) - { - // - has = HasDemandZones(); - if (has) - { - // - count = CountDemandZones(); - for (int i = 0; i < count; i++) - { - // - XCDemandZoneObject *iObj; - isCreated = drawer.CreateDemandZone( - demandZones[i], - iObj // - ); - - // - if (isCreated) - { - mWorkingZoneObjects.Add(iObj); - } - } - } - } - - // - // Support Zones ... - if (drawSupportZones) - { - // - has = HasSupportZones(); - if (has) - { - // - count = CountSupportZones(); - for (int i = 0; i < count; i++) - { - // - XCSupportZoneObject *iObj; - isCreated = drawer.CreateSupportZone( - supportZones[i], - iObj // - ); - - // - if (isCreated) - { - mWorkingZoneObjects.Add(iObj); - } - } - } - } - - // - // Resistance Zones ... - if (drawResistanceZones) - { - // - has = HasResistanceZones(); - if (has) - { - // - count = CountResistanceZones(); - for (int i = 0; i < count; i++) - { - // - XCResistanceZoneObject *iObj; - isCreated = drawer.CreateResistanceZone( - resistanceZones[i], - iObj // - ); - - // - if (isCreated) - { - mWorkingZoneObjects.Add(iObj); - } - } - } - } - - // - // - // - - // - // Waiting Zones ... - if (drawWaitingZones) - { - // - has = HasWaitingZones(); - if (has) - { - // - count = CountWaitingZones(); - for (int i = 0; i < count; i++) - { - // - XCBaseObject *objects[]; - int objectsCount = drawer.DrawOBFVG( - waitingZones[i], - objects // - ); - has = IsValidSize(objectsCount); - if (has) - { - // - for (int j = 0; j < objectsCount; j++) - { - mWaitingZoneObjects.Add(objects[j]); - } - } - } - } - } - - // - // Inside Zones ... - if (drawInsideZones) - { - // - // Zones ... - has = HasInsideZones(); - if (has) - { - // - count = CountInsideZones(); - for (int i = 0; i < count; i++) - { - // - XCBaseObject *objects[]; - int objectsCount = drawer.DrawOBFVG( - insideZones[i], - objects // - ); - - // - has = IsValidSize(objectsCount); - if (has) - { - // - for (int i = 0; i < objectsCount; i++) - { - mInsideZoneObjects.Add(objects[i]); - } - } - } - } - - // // - // // Boxes ... - // has = HasInsideBoxes(); - // if (has) - // { - // // - // count = CountInsideBoxes(); - // for (int i = 0; i < count; i++) - // { - // // - // XCBoxObject *object; - // bool isCreated = drawer.DrawBox( - // insideBoxes[i], - // object // - // ); - - // // - // if (isCreated) - // { - // mInsideZoneObjects.Add(object); - // } - // } - // } - } - - // - // Breaked Zones ... - if (drawBreakedZones) - { - // - has = HasBreakedZones(); - if (has) - { - // - count = CountBreakedZones(); - for (int i = 0; i < count; i++) - { - // - XCBaseObject *objects[]; - int objectsCount = drawer.DrawOBFVG( - breakedZones[i], - objects // - ); - - // - has = IsValidSize(objectsCount); - if (has) - { - // - for (int i = 0; i < objectsCount; i++) - { - mBreakedZoneObjects.Add(objects[i]); - } - } - } - } - - // // - // // Boxes ... - // has = HasBreakedBoxes(); - // if (has) - // { - // // - // count = CountBreakedBoxes(); - // for (int i = 0; i < count; i++) - // { - // // - // XCBoxObject *object; - // bool isCreated = drawer.DrawBox( - // breakedBoxes[i], - // object // - // ); - - // // - // if (isCreated) - // { - // mInsideZoneObjects.Add(object); - // } - // } - // } - } - - // - // - // - - // - // Quarters ... - has = IsValid(); - if (has) - { - // - double zoneUpper = supplyZone.Upper(); - double upper = supplyZone.Lower(); - - // - double lower = demandZone.Upper(); - double zoneLower = demandZone.Lower(); - - // - string prefix = "X121WZone_" + symbol + "_" + ToString(period); - - // - // Zone Upper ... - CChartObjectHLine *zoneUpperLine; - zoneUpperLine = new CChartObjectHLine(); - isCreated = zoneUpperLine.Create( - chartID, - prefix + "_ZoneTop", - subWindow, - zoneUpper // - ); - if (isCreated) - { - // - zoneUpperLine.Color(clrRed); - - // - mWaitingZoneObjects.Add(zoneUpperLine); - } - - // - // Zone Lower ... - CChartObjectHLine *zoneLowerLine; - zoneLowerLine = new CChartObjectHLine(); - isCreated = zoneLowerLine.Create( - chartID, - prefix + "_ZoneDown", - subWindow, - zoneLower // - ); - if (isCreated) - { - // - zoneLowerLine.Color(clrRed); - - // - mWaitingZoneObjects.Add(zoneLowerLine); - } - - // - // Upper ... - CChartObjectHLine *upperLine; - upperLine = new CChartObjectHLine(); - isCreated = upperLine.Create( - chartID, - prefix + "_Upper", - subWindow, - upper // - ); - if (isCreated) - { - // - upperLine.Color(clrLime); - - // - mWaitingZoneObjects.Add(upperLine); - } - - // - // Lower ... - CChartObjectHLine *lowerLine; - lowerLine = new CChartObjectHLine(); - isCreated = lowerLine.Create( - chartID, - prefix + "_Lower", - subWindow, - lower // - ); - if (isCreated) - { - // - lowerLine.Color(clrLime); - - // - mWaitingZoneObjects.Add(lowerLine); - } - - // - // Quarters ... - - // - // Quarter 1 ... - CChartObjectHLine *q1Line; - q1Line = new CChartObjectHLine(); - isCreated = q1Line.Create( - chartID, - prefix + "_Q1", - subWindow, - quarter1 // - ); - if (isCreated) - { - // - q1Line.Color(clrYellow); - - // - mWaitingZoneObjects.Add(q1Line); - } - - // - // Quarter 2 ... - CChartObjectHLine *q2Line; - q2Line = new CChartObjectHLine(); - isCreated = q2Line.Create( - chartID, - prefix + "_Q2", - subWindow, - quarter2 // - ); - if (isCreated) - { - // - q2Line.Color(clrYellow); - - // - mWaitingZoneObjects.Add(q2Line); - } - - // - // Quarter 3 ... - CChartObjectHLine *q3Line; - q3Line = new CChartObjectHLine(); - isCreated = q3Line.Create( - chartID, - prefix + "_Q3", - subWindow, - quarter3 // - ); - if (isCreated) - { - // - q3Line.Color(clrYellow); - - // - mWaitingZoneObjects.Add(q3Line); - } - } - } - - // -}; - -// -// Definitions ... -struct X121SMCStrategyXWZSignalConditions -{ - // - // Props ... - - // - string symbol; - ENUM_TIMEFRAMES period; - - // - double sl; - double reward; - double amountPercent; - ENUM_X_DIRECTION dir; - ENUM_X_POSITION_TYPES type; - - // - // Setup Props ... - - // - datetime setupTime; - datetime triggerTime; - - // - double pivot; - double point; - double sls[]; - double targets[]; - - // - XBoxZone signalBox; - - // - ENUM_X121SMC_XWZ_PRIORITY priority; - ENUM_X121SMC_XWZ_PROVIDERS provider; - - // - // Constructor ... - X121SMCStrategyXWZSignalConditions() - { - Clean(); - } - - // - // Tools ... - - /** - * Cleaning Up ... - */ - void Clean() - { - // - sl = 0; - - // - dir = X_DIRECTION_NONE; - type = X_POSITION_TYPE_NONE; - - // - symbol = NULL; - period = NULL; - setupTime = NULL; - triggerTime = NULL; - - // - ExtensionClean(); - - // - ZeroMemory(this); - } - - /** - * Check Condition is Setting Up ... - * - * @param dir: ENUM_X_DIRECTION member, Setting Up Direction ... - * - * @return ( bool ) - */ - bool IsSetuped() - { - // - bool result = false; - - // - result = IsValid(setupTime) && - HasDirection(dir); - if (!result) - { - return result; - } - - // - return result; - } - - /** - * Calculate Setup Age ... - * - * @return ( int ) - */ - int GetSetupAge() - { - // - int result = 0; - - // - if (!IsSetuped()) - { - return result; - } - - // - result = (int)(TimeCurrent() - setupTime) / PeriodSeconds(period); - - // - return result; - } - - /** - * Detect How we Can Trigger Signal ... - * - * @return ( bool ) - */ - bool CanTrigger() - { - // - bool result = false; - - // - result = - // - sl > 0 && - IsValid(symbol) && - IsValid(period) && - IsValid(triggerTime) && - type != X_POSITION_TYPE_ALL && - type != X_POSITION_TYPE_NONE - // - ; - - // - return result; - } - - // - // Extensions ... - - /** - * Clean Additional Properties ... - */ - void ExtensionClean() - { - // - pivot = 0; - point = 0; - - // - reward = 0; - amountPercent = 0; - - // - Clean(sls); - Clean(targets); - signalBox.Clean(); - - // - provider = X121SMC_XWZ_PROVIDER_NONE; - } - - // - // - // - - // - void UpdateTo(datetime value = NULL) - { - // - value = NormalizeTime(value); - - // - int count = 0; - bool has = false; - } - - // -}; - -// -// Extension Functions ... - -/** - * Check an XOBFVG instance has Required Conditions ... - * - * @param zone: XOBFVG instance ... - * @param state: XPOIState instance ... - * @param conditions: X121Conditions instance ... - * - * @return ( bool ) - */ -bool DetectSelectedZoneConditions( - bool &isReversal, - XOBFVG &zone, - XPOIState &state, - X121Conditions &conditions // -) -{ - // - bool result = false; - - // - isReversal = false; - - // - result = - zone.IsValid() && - state.IsValid() && - state.HasChild(); - if (!result) - { - return result; - } - - // - bool isBullish = zone.IsBullish(); - bool isBearish = zone.IsBearish(); - - // - bool isBullishTrend = conditions.isTrendBullish || - conditions.isTrendSwitchedToBullish; - bool isBearishTrend = conditions.isTrendBearish || - conditions.isTrendSwitchedToBearish; - - // - double bullishScore = 0; - double bearishScore = 0; - double scoreMultiplier = 1.5; - conditions.GenerateScore( - bullishScore, - bearishScore // - ); - - // - bool isBullishScorePassed = bullishScore > 0 && - bearishScore >= 0 && - bullishScore > bearishScore * scoreMultiplier; - - // - bool isBearishScorePassed = bearishScore > 0 && - bullishScore >= 0 && - bearishScore > bullishScore * scoreMultiplier; - - // - // VWap ... - - // - double vwapFast = conditions.vwapFastBuffer[0]; - double vwapMid = conditions.vwapMidBuffer[0]; - double vwapSlow = conditions.vwapSlowBuffer[0]; - - // - bool isVWapInside = - // - vwapFast > zone.ob.Lower() && - vwapFast < zone.ob.Upper() - // - && - vwapMid > zone.ob.Lower() && - vwapMid < zone.ob.Upper() - // - ; - - // - bool isVWapBullish = - // - (conditions.isVWapBullishState && - conditions.isVWapSwitchedToBullishOrdered) - // - || - // - (conditions.isVWapBullishOrdered && - conditions.isVWapSwitchedToBullishState) - // - ; - - // - bool isVWapBearish = - // - (conditions.isVWapBearishState && - conditions.isVWapSwitchedToBearishOrdered) - // - || - // - (conditions.isVWapBearishOrdered && - conditions.isVWapSwitchedToBearishState) - // - ; - - // - // X3Ma ... - - // - double x3maFast = conditions.x3maFastBuffer[0]; - double x3maMid = conditions.x3maMidBuffer[0]; - double x3maSlow = conditions.x3maSlowBuffer[0]; - - // - bool isX3MaInside = - // - x3maFast > zone.ob.Lower() && - x3maFast < zone.ob.Upper() - // - && - x3maMid > zone.ob.Lower() && - x3maMid < zone.ob.Upper() - // - ; - - // - bool isX3MaBullish = - // - (conditions.isX3MaBullishState && - conditions.isX3MaSwitchedToBullishOrdered) - // - || - // - (conditions.isX3MaBullishOrdered && - conditions.isX3MaSwitchedToBullishState) - // - ; - - // - bool isX3MaBearish = - // - (conditions.isX3MaBearishState && - conditions.isX3MaSwitchedToBearishOrdered) - // - || - // - (conditions.isX3MaBearishOrdered && - conditions.isX3MaSwitchedToBearishState) - // - ; - - // - // - // - - // - bool isInside = - // - isVWapInside || - isX3MaInside - // - ; - - // - bool isVWap3MaBullish = - isVWapBullish || - isX3MaBullish; - - // - bool isVWap3MaBearish = - isVWapBearish || - isX3MaBearish; - - // - // - // - - // - bool isDirectionalBullishPassed = - // - isInside && - isBullish && - isBullishTrend && - isVWap3MaBullish && - isBullishScorePassed - // - ; - - // - bool isDirectionalBearishPassed = - // - isInside && - isBearish && - isBearishTrend && - isVWap3MaBearish && - isBearishScorePassed - // - ; - - // - bool isDirectionalPassed = - isDirectionalBullishPassed || - isDirectionalBearishPassed; - - // - bool isReversalBullishPassed = - // - isInside && - isBullish && - isBearishTrend && - isVWap3MaBearish && - isBearishScorePassed - // - ; - - // - bool isReversalBearishPassed = - // - isInside && - isBearish && - isBullishTrend && - isVWap3MaBullish && - isBullishScorePassed - // - ; - - // - bool isReversalPassed = isReversalBullishPassed || - isReversalBearishPassed; - - // - result = isReversalPassed || - isDirectionalPassed; - - // - if (result) - { - isReversal = isReversalPassed; - } - - // - return result; -} - -/** - * Detect Targets Based on Selected Zone for Specified type of Directions ... - * - * @param targets: double Collection ... - * @param selectedZone: XOBFVG instance, selected Zone ... - * @param forDir: ENUM_X_DIRECTION specified Position Direction ... - * @param workingone: X121SMCStrategyXWZWorkingZone instance, Specified Working Zone ... - * @param barIndex: int Specified Bar Index ... - * - * @return ( bool ) - */ -bool DetectSelectedZonesTargets( - double &targets[], - XOBFVG &selectedZone, - ENUM_X_DIRECTION forDir, - ENUM_X121SMC_XWZ_PRIORITY forPriority, - X121SMCStrategyXWZWorkingZone &workingZone, - int barIndex = 0 // -) -{ - // - bool result = false; - - // - Clean(targets); - - // - if (barIndex < 0) - { - barIndex = 0; - } - - // - if (barIndex == 0) - { - barIndex++; - } - - // - result = - // - selectedZone.IsValid() && - HasDirection(forDir) && - workingZone.IsValid() && - forPriority != X121SMC_XWZ_PRIORITY_NONE - // - ; - if (!result) - { - return result; - } - - // - bool isBullish = IsBullish(forDir); - - // - XOHCL cBar; - result = cBar.Init( - workingZone.symbol, - workingZone.period, - barIndex // - ); - if (!result) - { - // - cBar.Clean(); - return result; - } - - // - int idx = -1; - bool has = false; - XOBFVG tmpZones[]; - - // - // Based On Waiting Zones ... - has = workingZone.HasWaitingZones(); - if (has) - { - // - Copy( - workingZone.waitingZones, - tmpZones // - ); - - // - while (HasChild(tmpZones)) - { - // - XOBFVG iOBFVG; - - // - idx = GetYoungest(tmpZones); - if (!IsValidIndex(idx)) - { - // - iOBFVG.Clean(); - break; - } - - // - iOBFVG = tmpZones[idx]; - ArrayRemove( - tmpZones, - idx, - 1 // - ); - - // - double iTarget = - isBullish - ? iOBFVG.ob.Lower() - : iOBFVG.ob.Upper(); - - // - has = - isBullish - ? cBar.high < iTarget - : cBar.low > iTarget; - - // - if (has) - { - // - Add( - iTarget, - targets // - ); - } - - // - iOBFVG.Clean(); - } - - // - Clean(tmpZones); - } - - // - // Based On Breaked Zones ... - has = workingZone.HasBreakedZones(); - if (has) - { - Copy( - workingZone.breakedZones, - tmpZones // - ); - - // - while (HasChild(tmpZones)) - { - // - XOBFVG iOBFVG; - - // - idx = GetYoungest(tmpZones); - if (!IsValidIndex(idx)) - { - // - iOBFVG.Clean(); - break; - } - - // - iOBFVG = tmpZones[idx]; - ArrayRemove( - tmpZones, - idx, - 1 // - ); - - // - double iTarget = - isBullish - ? iOBFVG.ob.Lower() - : iOBFVG.ob.Upper(); - - // - has = - isBullish - ? cBar.high < iTarget - : cBar.low > iTarget; - - // - if (has) - { - // - Add( - iTarget, - targets // - ); - } - - // - iOBFVG.Clean(); - } - - // - Clean(tmpZones); - } - - // - // Based On Priority ... - has = forPriority != X121SMC_XWZ_PRIORITY_NONE; - if (has) - { - // - switch (forPriority) - { - // - case X121SMC_XWZ_PRIORITY_WEAK: - // - if (isBullish) - { - // - // Weak ... - Add( - workingZone.supplyZone.Lower(), - targets // - ); - } - else - { - // - // Weak ... - Add( - workingZone.demandZone.Upper(), - targets // - ); - } - break; - - // - case X121SMC_XWZ_PRIORITY_LOW: - // - if (isBullish) - { - // - // Weak ... - Add( - workingZone.supplyZone.Lower(), - targets // - ); - - // - // Low ... - Add( - workingZone.quarter1, - targets // - ); - } - else - { - // - // Weak ... - Add( - workingZone.demandZone.Upper(), - targets // - ); - - // - // Low ... - Add( - workingZone.quarter3, - targets // - ); - } - break; - - // - case X121SMC_XWZ_PRIORITY_REGULAR: - // - if (isBullish) - { - // - // Weak ... - Add( - workingZone.supplyZone.Lower(), - targets // - ); - - // - // Low ... - Add( - workingZone.quarter1, - targets // - ); - - // - // Regular ... - Add( - workingZone.quarter2, - targets // - ); - } - else - { - // - // Weak ... - Add( - workingZone.demandZone.Upper(), - targets // - ); - - // - // Low ... - Add( - workingZone.quarter3, - targets // - ); - - // - // Regular ... - Add( - workingZone.quarter2, - targets // - ); - } - break; - - // - case X121SMC_XWZ_PRIORITY_HIGH: - // - if (isBullish) - { - // - // Weak ... - Add( - workingZone.supplyZone.Lower(), - targets // - ); - - // - // Low ... - Add( - workingZone.quarter1, - targets // - ); - - // - // Regular ... - Add( - workingZone.quarter2, - targets // - ); - - // - // High ... - Add( - workingZone.quarter3, - targets // - ); - } - else - { - // - // Weak ... - Add( - workingZone.demandZone.Upper(), - targets // - ); - - // - // Low ... - Add( - workingZone.quarter3, - targets // - ); - - // - // Regular ... - Add( - workingZone.quarter2, - targets // - ); - - // - // High ... - Add( - workingZone.quarter1, - targets // - ); - } - break; - - // - case X121SMC_XWZ_PRIORITY_STRONG_HIGH: - // - if (isBullish) - { - // - // Weak ... - Add( - workingZone.supplyZone.Lower(), - targets // - ); - - // - // Low ... - Add( - workingZone.quarter1, - targets // - ); - - // - // Regular ... - Add( - workingZone.quarter2, - targets // - ); - - // - // High ... - Add( - workingZone.quarter3, - targets // - ); - - // - // Strong High ... - Add( - workingZone.demandZone.Upper(), - targets // - ); - } - else - { - // - // Weak ... - Add( - workingZone.demandZone.Upper(), - targets // - ); - - // - // Low ... - Add( - workingZone.quarter3, - targets // - ); - - // - // Regular ... - Add( - workingZone.quarter2, - targets // - ); - - // - // High ... - Add( - workingZone.quarter1, - targets // - ); - - // - // Strong High ... - Add( - workingZone.supplyZone.Lower(), - targets // - ); - } - break; - } - } - - // - result = HasChild(targets); - - // - // Cleanup ... - cBar.Clean(); - Clean(tmpZones); - - // - return result; -} - -/** - * Detect Targets Based on Selected Zone for Specified type of Directions ... - * - * @param targets: double Collection ... - * @param selectedZone: XBoxZone instance, selected Zone ... - * @param forDir: ENUM_X_DIRECTION specified Position Direction ... - * @param workingone: X121SMCStrategyXWZWorkingZone instance, Specified Working Zone ... - * @param barIndex: int Specified Bar Index ... - * - * @return ( bool ) - */ -bool DetectSelectedZonesTargets( - double &targets[], - XBoxZone &selectedZone, - ENUM_X_DIRECTION forDir, - ENUM_X121SMC_XWZ_PRIORITY forPriority, - X121SMCStrategyXWZWorkingZone &workingZone, - int barIndex = 0 // -) -{ - // - bool result = false; - - // - Clean(targets); - - // - if (barIndex < 0) - { - barIndex = 0; - } - - // - if (barIndex == 0) - { - barIndex++; - } - - // - result = - // - selectedZone.IsValid() && - HasDirection(forDir) && - workingZone.IsValid() && - forPriority != X121SMC_XWZ_PRIORITY_NONE - // - ; - if (!result) - { - return result; - } - - // - bool isBullish = IsBullish(forDir); - - // - XOHCL cBar; - result = cBar.Init( - workingZone.symbol, - workingZone.period, - barIndex // - ); - if (!result) - { - // - cBar.Clean(); - return result; - } - - // - int idx = -1; - bool has = false; - XOBFVG tmpZones[]; - - // - // Based On Waiting Zones ... - has = workingZone.HasWaitingZones(); - if (has) - { - // - Copy( - workingZone.waitingZones, - tmpZones // - ); - - // - while (HasChild(tmpZones)) - { - // - XOBFVG iOBFVG; - - // - idx = GetYoungest(tmpZones); - if (!IsValidIndex(idx)) - { - // - iOBFVG.Clean(); - break; - } - - // - iOBFVG = tmpZones[idx]; - ArrayRemove( - tmpZones, - idx, - 1 // - ); - - // - double iTarget = - isBullish - ? iOBFVG.ob.Lower() - : iOBFVG.ob.Upper(); - - // - has = - isBullish - ? cBar.high < iTarget - : cBar.low > iTarget; - - // - if (has) - { - // - Add( - iTarget, - targets // - ); - } - - // - iOBFVG.Clean(); - } - - // - Clean(tmpZones); - } - - // - // Based On Breaked Zones ... - has = workingZone.HasBreakedZones(); - if (has) - { - Copy( - workingZone.breakedZones, - tmpZones // - ); - - // - while (HasChild(tmpZones)) - { - // - XOBFVG iOBFVG; - - // - idx = GetYoungest(tmpZones); - if (!IsValidIndex(idx)) - { - // - iOBFVG.Clean(); - break; - } - - // - iOBFVG = tmpZones[idx]; - ArrayRemove( - tmpZones, - idx, - 1 // - ); - - // - double iTarget = - isBullish - ? iOBFVG.ob.Lower() - : iOBFVG.ob.Upper(); - - // - has = - isBullish - ? cBar.high < iTarget - : cBar.low > iTarget; - - // - if (has) - { - // - Add( - iTarget, - targets // - ); - } - - // - iOBFVG.Clean(); - } - - // - Clean(tmpZones); - } - - // - // Based On Priority ... - has = forPriority != X121SMC_XWZ_PRIORITY_NONE; - if (has) - { - // - switch (forPriority) - { - // - case X121SMC_XWZ_PRIORITY_WEAK: - // - if (isBullish) - { - // - // Weak ... - Add( - workingZone.supplyZone.Lower(), - targets // - ); - } - else - { - // - // Weak ... - Add( - workingZone.demandZone.Upper(), - targets // - ); - } - break; - - // - case X121SMC_XWZ_PRIORITY_LOW: - // - if (isBullish) - { - // - // Weak ... - Add( - workingZone.supplyZone.Lower(), - targets // - ); - - // - // Low ... - Add( - workingZone.quarter1, - targets // - ); - } - else - { - // - // Weak ... - Add( - workingZone.demandZone.Upper(), - targets // - ); - - // - // Low ... - Add( - workingZone.quarter3, - targets // - ); - } - break; - - // - case X121SMC_XWZ_PRIORITY_REGULAR: - // - if (isBullish) - { - // - // Weak ... - Add( - workingZone.supplyZone.Lower(), - targets // - ); - - // - // Low ... - Add( - workingZone.quarter1, - targets // - ); - - // - // Regular ... - Add( - workingZone.quarter2, - targets // - ); - } - else - { - // - // Weak ... - Add( - workingZone.demandZone.Upper(), - targets // - ); - - // - // Low ... - Add( - workingZone.quarter3, - targets // - ); - - // - // Regular ... - Add( - workingZone.quarter2, - targets // - ); - } - break; - - // - case X121SMC_XWZ_PRIORITY_HIGH: - // - if (isBullish) - { - // - // Weak ... - Add( - workingZone.supplyZone.Lower(), - targets // - ); - - // - // Low ... - Add( - workingZone.quarter1, - targets // - ); - - // - // Regular ... - Add( - workingZone.quarter2, - targets // - ); - - // - // High ... - Add( - workingZone.quarter3, - targets // - ); - } - else - { - // - // Weak ... - Add( - workingZone.demandZone.Upper(), - targets // - ); - - // - // Low ... - Add( - workingZone.quarter3, - targets // - ); - - // - // Regular ... - Add( - workingZone.quarter2, - targets // - ); - - // - // High ... - Add( - workingZone.quarter1, - targets // - ); - } - break; - - // - case X121SMC_XWZ_PRIORITY_STRONG_HIGH: - // - if (isBullish) - { - // - // Weak ... - Add( - workingZone.supplyZone.Lower(), - targets // - ); - - // - // Low ... - Add( - workingZone.quarter1, - targets // - ); - - // - // Regular ... - Add( - workingZone.quarter2, - targets // - ); - - // - // High ... - Add( - workingZone.quarter3, - targets // - ); - - // - // Strong High ... - Add( - workingZone.demandZone.Upper(), - targets // - ); - } - else - { - // - // Weak ... - Add( - workingZone.demandZone.Upper(), - targets // - ); - - // - // Low ... - Add( - workingZone.quarter3, - targets // - ); - - // - // Regular ... - Add( - workingZone.quarter2, - targets // - ); - - // - // High ... - Add( - workingZone.quarter1, - targets // - ); - - // - // Strong High ... - Add( - workingZone.supplyZone.Lower(), - targets // - ); - } - break; - } - } - - // - result = HasChild(targets); - - // - // Cleanup ... - cBar.Clean(); - Clean(tmpZones); - - // - return result; -} - -/** - * Detect SL Candidates Based on Selected Zone for Specified type of Directions ... - * - * @param sls: double Collection ... - * @param selectedZone: XOBFVG instance, selected Zone ... - * @param forDir: ENUM_X_DIRECTION specified Position Direction ... - * @param workingZone: X121SMCStrategyXWZWorkingZone instance, Specified Working Zone ... - * @param barIndex: int Specified Bar Index ... - * @param maxAllowedSLDistanceInPoint: doube max Allowe SL distance ... - * - * @return ( bool ) - */ -bool DetectSelectedZoneSLCandidates( - double &sls[], - XOBFVG &selectedZone, - ENUM_X_DIRECTION forDir, - X121SMCStrategyXWZWorkingZone &workingZone, - X121Conditions &conditions, - int barIndex = 0, - double maxAllowedSLDistanceInPoint = 300 // -) -{ - // - bool result = false; - - // - Clean(sls); - - // - if (barIndex < 0) - { - barIndex = 0; - } - - // - if (barIndex == 0) - { - barIndex++; - } - - // - result = - // - selectedZone.IsValid() && - HasDirection(forDir) && - workingZone.IsValid() - // - ; - if (!result) - { - return result; - } - - // - bool isBullish = IsBullish(forDir); - - // - double pivot = - isBullish - ? selectedZone.ob.Lower() - : selectedZone.ob.Upper(); - double points = GetPoints(workingZone.symbol); - - // - XOHCL cBar; - result = cBar.Init( - workingZone.symbol, - workingZone.period, - barIndex // - ); - if (!result) - { - // - cBar.Clean(); - return result; - } - - // - int idx = -1; - bool has = false; - - // - double pvSL = isBullish - ? conditions.valesBuffer[0] - : conditions.peaksBuffer[1]; - - // - Add( - pvSL, - sls // - ); - - // - // Based On Passed Bars ... - // XOHCL passedBar; - // bool isPassed = false; - // bool isBodyState = false; - // ENUM_X_DIRECTION passedDir = selectedZone.GetDirection(); - - // // - // // Started Bar ... - // isPassed = selectedZone.ob.IsStarted( - // passedDir, - // passedBar, - // isBodyState // - // ); - // if (isPassed) - // { - // // - // double iSL = - // isBullish - // ? passedBar.low - // : passedBar.high; - // double iSLDiff = MathAbs(iSL - pivot); - // has = - // iSLDiff > 0 && - // iSLDiff <= maxAllowedSLDistanceInPoint * points; - // if (has) - // { - // // - // Add( - // iSL, - // sls // - // ); - // } - // } - - // // - // // Activation Bar ... - // passedBar.Clean(); - // isPassed = selectedZone.ob.IsActivated( - // passedDir, - // passedBar, - // isBodyState // - // ); - // if (isPassed) - // { - // // - // double iSL = - // isBullish - // ? passedBar.low - // : passedBar.high; - // double iSLDiff = MathAbs(iSL - pivot); - // has = - // iSLDiff > 0 && - // iSLDiff <= maxAllowedSLDistanceInPoint * points; - // if (has) - // { - // // - // Add( - // iSL, - // sls // - // ); - // } - // } - - // // - // // Worked Bar ... - // passedBar.Clean(); - // isPassed = selectedZone.ob.IsActivated( - // passedDir, - // passedBar, - // isBodyState // - // ); - // if (isPassed) - // { - // // - // double iSL = - // isBullish - // ? passedBar.low - // : passedBar.high; - // double iSLDiff = MathAbs(iSL - pivot); - // has = - // iSLDiff > 0 && - // iSLDiff <= maxAllowedSLDistanceInPoint * points; - // if (has) - // { - // // - // Add( - // iSL, - // sls // - // ); - // } - // } - - // // - // // Breaked Bar ... - // passedBar.Clean(); - // isPassed = selectedZone.ob.IsActivated( - // passedDir, - // passedBar, - // isBodyState // - // ); - // if (isPassed) - // { - // // - // double iSL = - // isBullish - // ? passedBar.low - // : passedBar.high; - // double iSLDiff = MathAbs(iSL - pivot); - // has = - // iSLDiff > 0 && - // iSLDiff <= maxAllowedSLDistanceInPoint * points; - // if (has) - // { - // // - // Add( - // iSL, - // sls // - // ); - // } - // } - - // - // Based On Consolidation Zones ... - has = workingZone.HasConsolidationZones(); - if (has) - { - // - XConsolidationZone tmpZones[]; - Copy( - workingZone.consolidationZones, - tmpZones // - ); - XConsolidationZone selectedConsolidationZone; - - // - while (HasChild(tmpZones)) - { - // - idx = GetYoungest(tmpZones); - if (!IsValidIndex(idx)) - { - break; - } - - // - XConsolidationZone iZone = tmpZones[idx]; - - // - ArrayRemove( - tmpZones, - idx, - 1 // - ); - - // - has = - !selectedConsolidationZone.IsValid() - ? isBullish - ? cBar.low < iZone.upper - : cBar.high < iZone.lower - : isBullish - ? selectedConsolidationZone.lower < iZone.lower - : selectedConsolidationZone.upper > iZone.upper; - if (has) - { - // - selectedConsolidationZone = iZone; - iZone.Clean(); - break; - } - - // - iZone.Clean(); - } - - // - Clean(tmpZones); - has = selectedConsolidationZone.IsValid(); - if (has) - { - // - double iSL = - isBullish - ? selectedConsolidationZone.lower - : selectedConsolidationZone.upper; - double iSLDiff = MathAbs(iSL - pivot); - has = - iSLDiff > 0 && - iSLDiff <= maxAllowedSLDistanceInPoint * points; - if (has) - { - // - Add( - iSL, - sls // - ); - } - } - } - - // - // Based On Supply and Demand Zones ... - - // - // Demand Zones ... - has = workingZone.HasDemandZones(); - if (has) - { - // - XCDemandZone *tmpZones[]; - Copy( - workingZone.demandZones, - tmpZones // - ); - XCDemandZone *selectedDemand = NULL; - - // - while (HasChild(tmpZones)) - { - // - idx = GetLowest(tmpZones); - has = IsValidIndex(idx); - if (!has) - { - break; - } - - // - XCDemandZone *iZone = tmpZones[idx]; - ArrayRemove( - tmpZones, - idx, - 1 // - ); - - // - // Validate Zone ... - has = - isBullish - ? IsBelowDiff( - iZone, - selectedZone.ob, - true // Ignore Inside ... - ) - : IsAboveDiff( - iZone, - selectedZone.ob, - true // Ignore Inside ... - ); - if (!has) - { - continue; - } - - // - has = - selectedDemand == NULL - ? true - : isBullish - ? selectedDemand.Lower() < iZone.Lower() - : selectedDemand.Upper() > iZone.Upper(); - if (!has) - { - continue; - } - - // - selectedDemand = iZone; - } - - // - has = selectedDemand != NULL; - if (has) - { - // - double iSL = - isBullish - ? selectedDemand.Lower() - : selectedDemand.Upper(); - double iSLDiff = MathAbs(iSL - pivot); - has = - iSLDiff > 0 && - iSLDiff <= maxAllowedSLDistanceInPoint * points; - if (has) - { - // - Add( - iSL, - sls // - ); - } - } - - // - Clean(tmpZones); - ZeroMemory(selectedDemand); - } - - // - // Support Zones ... - // has = workingZone.HasSupportZones(); - // if (has) - // { - // // - // XCSupportZone *tmpZones[]; - // Copy( - // workingZone.supportZones, - // tmpZones // - // ); - // XCSupportZone *selectedSupport = NULL; - - // // - // while (HasChild(tmpZones)) - // { - // // - // idx = GetLowest(tmpZones); - // has = IsValidIndex(idx); - // if (!has) - // { - // break; - // } - - // // - // XCSupportZone *iZone = tmpZones[idx]; - // ArrayRemove( - // tmpZones, - // idx, - // 1 // - // ); - - // // - // // Validate Zone ... - // has = - // isBullish - // ? IsBelowDiff( - // iZone, - // selectedZone.ob, - // true // Ignore Inside ... - // ) - // : IsAboveDiff( - // iZone, - // selectedZone.ob, - // true // Ignore Inside ... - // ); - // if (!has) - // { - // continue; - // } - - // // - // has = - // selectedSupport == NULL - // ? true - // : isBullish - // ? selectedSupport.Lower() < iZone.Lower() - // : selectedSupport.Upper() > iZone.Upper(); - // if (!has) - // { - // continue; - // } - - // // - // selectedSupport = iZone; - - // // - // } - - // // - // has = selectedSupport != NULL; - // if (has) - // { - // // - // double iSL = isBullish - // ? selectedSupport.Lower() - // : selectedSupport.Upper(); - // double iSLDiff = MathAbs(iSL - pivot); - // has = - // iSLDiff > 0 && - // iSLDiff <= maxAllowedSLDistanceInPoint * points; - // if (has) - // { - // // - // Add( - // iSL, - // sls // - // ); - // } - // } - - // // - // Clean(tmpZones); - // ZeroMemory(selectedSupport); - // } - - // - // Supply Zones ... - has = workingZone.HasSupplyZones(); - if (has) - { - // - XCSupplyZone *tmpZones[]; - Copy( - workingZone.supplyZones, - tmpZones // - ); - XCSupplyZone *selectedSupply = NULL; - - // - while (HasChild(tmpZones)) - { - // - idx = GetHighest(tmpZones); - has = IsValidIndex(idx); - if (!has) - { - break; - } - - // - XCSupplyZone *iZone = tmpZones[idx]; - ArrayRemove( - tmpZones, - idx, - 1 // - ); - - // - // Validate Zone ... - has = - !isBullish - ? IsAboveDiff( - iZone, - selectedZone.ob, - true // Ignore Inside ... - ) - : IsBelowDiff( - iZone, - selectedZone.ob, - true // Ignore Inside ... - ); - if (!has) - { - continue; - } - - // - has = - selectedSupply == NULL - ? true - : !isBullish - ? selectedSupply.Upper() > iZone.Upper() - : selectedSupply.Lower() < iZone.Lower(); - if (!has) - { - continue; - } - - // - selectedSupply = iZone; - - // - } - - // - has = selectedSupply != NULL; - if (has) - { - // - double iSL = - !isBullish - ? selectedSupply.Upper() - : selectedSupply.Lower(); - double iSLDiff = MathAbs(iSL - pivot); - has = - iSLDiff > 0 && - iSLDiff <= maxAllowedSLDistanceInPoint * points; - if (has) - { - // - Add( - iSL, - sls // - ); - } - } - - // - Clean(tmpZones); - ZeroMemory(selectedSupply); - } - - // - // Resistance Zones ... - // has = workingZone.HasDemandZones(); - // if (has) - // { - // // - // XCResistanceZone *tmpZones[]; - // Copy( - // workingZone.resistanceZones, - // tmpZones // - // ); - // XCResistanceZone *selectedResistance = NULL; - - // // - // while (HasChild(tmpZones)) - // { - // // - // idx = GetHighest(tmpZones); - // has = IsValidIndex(idx); - // if (!has) - // { - // break; - // } - - // // - // XCResistanceZone *iZone = tmpZones[idx]; - // ArrayRemove( - // tmpZones, - // idx, - // 1 // - // ); - - // // - // // Validate Zone ... - // has = - // !isBullish - // ? IsAboveDiff( - // iZone, - // selectedZone.ob, - // true // Ignore Inside ... - // ) - // : IsBelowDiff( - // iZone, - // selectedZone.ob, - // true // Ignore Inside ... - // ); - // if (!has) - // { - // continue; - // } - - // // - // has = - // selectedResistance == NULL - // ? true - // : !isBullish - // ? selectedResistance.Upper() < iZone.Upper() - // : selectedResistance.Lower() > iZone.Lower(); - // if (!has) - // { - // continue; - // } - - // // - // selectedResistance = iZone; - - // // - // } - - // // - // has = selectedResistance != NULL; - // if (has) - // { - // // - // double iSL = - // !isBullish - // ? selectedResistance.Upper() - // : selectedResistance.Lower(); - // double iSLDiff = MathAbs(iSL - pivot); - // has = - // iSLDiff > 0 && - // iSLDiff <= maxAllowedSLDistanceInPoint * points; - // if (has) - // { - // // - // Add( - // iSL, - // sls // - // ); - // } - // } - - // // - // Clean(tmpZones); - // ZeroMemory(selectedResistance); - // } - - // - // Cleanp Resources ... - - // - cBar.Clean(); - // passedBar.Clean(); - result = HasChild(sls); - - // - return result; -} - - -// \ No newline at end of file diff --git a/Documents/BKP/x-121.smc.xwz.signal.lib.mq5 b/Documents/BKP/x-121.smc.xwz.signal.lib.mq5 deleted file mode 100644 index dd8835d8..00000000 --- a/Documents/BKP/x-121.smc.xwz.signal.lib.mq5 +++ /dev/null @@ -1,1582 +0,0 @@ -/////////////////////////////////////////////////////// -// -// SaherElm IT Center MQL5 X121 SMC Signal Class -// ------------------------------------------------- -// Name: XWZ -// Description: provide all Signalling functions ... -// -// -// Maintainer: -// ------------ -// Hadi Khazaee Asl (hadi_khazaee_asl@yahoo.com) -// -////////////////////////////////////////////////////// -// -// Global Properties ... -#property library -#property copyright "Copyright 2023, SaherElm IT Center" -#property link "https://www.saherelm.ir" -#property version "1.00" -#property strict - -// -// Imports ... -// #include "../../Libraries/x-trade.lib" -#include "../Classes/x-121.smc.market.cycle.helper.class.mq5" -#include "../Libraries/x-121.smc.guard.lib.mq5" -#include "../Libraries/x-121.smc.lib.mq5" - -// -enum ENUM_X121SMC_XWZ_PROVIDERS -{ - X121SMC_XWZ_PROVIDER_NONE, - X121SMC_XWZ_PROVIDER_ACTIVATED_ZONE, - X121SMC_XWZ_PROVIDER_ACTIVATED_CHOCH, - X121SMC_XWZ_PROVIDER_PRICE_INSIDE_ZONE, -}; - -// -enum ENUM_X121SMC_XWZ_PRIORITY -{ - X121SMC_XWZ_PRIORITY_NONE, - X121SMC_XWZ_PRIORITY_WEAK, - X121SMC_XWZ_PRIORITY_LOW, - X121SMC_XWZ_PRIORITY_REGULAR, - X121SMC_XWZ_PRIORITY_HIGH, - X121SMC_XWZ_PRIORITY_STRONG_HIGH, -}; - -// -struct X121SMCStrategyXWZWorkingZone -{ - // - // Props ... - - // - string symbol; - ENUM_TIMEFRAMES period; - - // - XCSupplyZone *supplyZone; - XCDemandZone *demandZone; - - // - double quarter1; - double quarter2; - double quarter3; - - // - XOBFVG orderFlow[]; - XOBFVGPivot swings[]; - XOBFVG brokenOrderFlow[]; - CChartObjectTrend *orderFlowTrend; - - // - XCSupplyZone *supplyZones[]; - XCDemandZone *demandZones[]; - - // - // Constructor ... - X121SMCStrategyXWZWorkingZone() - { - Clean(); - } - - // - // Tools ... - - // - void Clean() - { - // - quarter1 = 0; - quarter2 = 0; - quarter3 = 0; - - // - symbol = NULL; - period = NULL; - - // - Clean(orderFlow); - Clean(brokenOrderFlow); - - // - Clean(swings); - ZeroMemory(supplyZone); - ZeroMemory(demandZone); - - // - if (orderFlowTrend != NULL) - { - orderFlowTrend.Delete(); - } - ZeroMemory(orderFlowTrend); - - // - ZeroMemory(this); - } - - // - bool IsValid() - { - // - bool result = false; - - // - result = - // - quarter1 > 0 && - quarter2 > 0 && - quarter3 > 0 && - HasSupplyZone() && - HasDemandZone() && - quarter1 > quarter2 && - quarter2 > quarter3 - // - ; - - // - return result; - } - - // - bool HasSupplyZone() - { - return supplyZone != NULL && - supplyZone.IsValid(); - } - - // - bool HasDemandZone() - { - return demandZone != NULL && - demandZone.IsValid(); - } - - // - // - // - - // - bool HasOrderFlow() - { - // - bool result = false; - - // - result = IsValid() && - HasChild(orderFlow); - - // - return result; - } - - // - bool HasOrderFlow( - ENUM_X_DIRECTION &orderFlowDir // - ) - { - // - bool result = false; - - // - result = IsValid() && - HasChild(orderFlow); - if (result) - { - orderFlowDir = orderFlow[0].GetDirection(); - } - - // - return result; - } - - // - int CountOrderFlow() - { - return ArraySize(orderFlow); - } - - // - int GetSwings( - XOBFVGPivot &pivots[] // - ) - { - // - int result = 0; - - // - Clean(pivots); - - // - int count = 0; - bool has = false; - - // - has = HasOrderFlow(); - if (!has) - { - return result; - } - - // - count = CountOrderFlow(); - for (int i = 0; i < count; i++) - { - // - XOBFVGPivot iPivots[]; - int iPivotsCount = orderFlow[i] - .GetSwings(iPivots); - bool hasPivots = IsValidSize(iPivotsCount); - if (hasPivots) - { - // - Copy( - iPivots, - pivots, - false // - ); - } - - // - Clean(iPivots); - } - - // - result = ArraySize(pivots); - - // - return result; - } - - // - double GetOrderFlowTrendLinePrice( - int barIndex = 0, - ENUM_TIMEFRAMES forPeriod = NULL // - ) - { - // - double result = 0; - - // - if (barIndex < 0) - { - barIndex = 0; - } - - // - if (!IsValid(forPeriod)) - { - forPeriod = period; - } - - // - if (!IsValid() || - !HasOrderFlow() || - orderFlowTrend == NULL) - { - return result; - } - - // - datetime time = iTime( - symbol, - forPeriod, - barIndex // - ); - - // - result = ObjectGetValueByTime( - orderFlowTrend.ChartId(), - orderFlowTrend.Name(), - time // - ); - - // - return result; - } - - // - int DetectOrderFlow( - string forSymbol, - ENUM_TIMEFRAMES forPeriod, - ENUM_X_DIRECTION &orderFlowDir, - XPOIState <fState, - XPOIState &htfState, - XPOIState &mtfState, - XPOIState &stfState // - ) - { - // - int result = 0; - - // - Clean(orderFlow); - orderFlowDir = X_DIRECTION_NONE; - - // - bool isValid = - // - IsValid(forSymbol) && - IsValid(forPeriod) && - ltfState.HasChild() && - htfState.HasChild() && - mtfState.HasChild() && - stfState.HasChild() - // - ; - if (!isValid) - { - return result; - } - - // - // Find Working Zone ... - bool hasWorkingZone = IsValid(); - if (!hasWorkingZone) - { - // - symbol = forSymbol; - period = forPeriod; - - // - int idx = -1; - bool has = false; - - // - has = ltfState.HasSupplyZones(); - if (has) - { - // - idx = GetHighest(ltfState.supplyZones); - if (IsValidIndex(idx)) - { - supplyZone = ltfState.supplyZones[idx]; - } - } - - // - has = ltfState.HasDemandZones(); - if (has) - { - // - idx = GetLowest(ltfState.demandZones); - if (IsValidIndex(idx)) - { - demandZone = ltfState.demandZones[idx]; - } - } - - // - hasWorkingZone = HasSupplyZone() && - HasDemandZone(); - if (hasWorkingZone) - { - // - double upper = supplyZone.Lower(); - double lower = demandZone.Upper(); - - // - double delta = ((upper - lower) / 100) * 25; - - // - quarter1 = upper - (1 * delta); - quarter2 = upper - (2 * delta); - quarter3 = upper - (3 * delta); - - // - hasWorkingZone = IsValid(); - } - } - - // - if (!hasWorkingZone) - { - return result; - } - - // - // Bullish OBFVGs ... - XOBFVG bullOBFVGs[]; - int bullOBFVGsCount = ExtractOBFVGZones( - htfState, - mtfState, - stfState, - bullOBFVGs, - X_DIRECTION_BULLISH, - NULL, // For Period ... - // - // Start ... - XZONE_STATE_PASSED, - true, // Force Body Out ... - // - // Activation ... - XZONE_STATE_PASSED, - true, // Force Body In ... - // - // Breaktion ... - XZONE_STATE_FAILED, - false, // Force Body In ... - // - // Works ... - XZONE_STATE_PASSED, - true, // Force Body Out ... - // - true, // Apply Sort ... - true, // From Filter ... - true, // Place Filter ... - // - true, // Ignore Inside in Place Filter ... - // - true, // Detect Inside OB POI(s) ... - true, // Detect Inside FVG POI(s) ... - true // Apply From Filter to Selected POI(s) ... - ); - bool hasBullOBFVGs = IsValidSize(bullOBFVGsCount); - - // - // Bearish OBFVGs ... - XOBFVG bearOBFVGs[]; - int bearOBFVGsCount = ExtractOBFVGZones( - htfState, - mtfState, - stfState, - bearOBFVGs, - X_DIRECTION_BEARISH, - NULL, // For Period ... - // - // Start ... - XZONE_STATE_PASSED, - true, // Force Body Out ... - // - // Activation ... - XZONE_STATE_PASSED, - true, // Force Body In ... - // - // Breaktion ... - XZONE_STATE_FAILED, - false, // Force Body In ... - // - // Works ... - XZONE_STATE_PASSED, - true, // Force Body Out ... - // - true, // Apply Sort ... - true, // From Filter ... - true, // Place Filter ... - // - true, // Ignore Inside in Place Filter ... - // - true, // Detect Inside OB POI(s) ... - true, // Detect Inside FVG POI(s) ... - true // Apply From Filter to Selected POI(s) ... - ); - bool hasBearOBFVGs = IsValidSize(bearOBFVGsCount); - - // - XOBFVG lastBroken; - bool hasBroken = false; - int idx = GetYoungest(brokenOrderFlow); - if (IsValidIndex(idx)) - { - // - lastBroken = brokenOrderFlow[idx]; - hasBroken = lastBroken.IsValid(); - } - - // - bool hasOrderFlow = hasBearOBFVGs || - hasBullOBFVGs; - if (hasOrderFlow) - { - // - // Vlidate ... - isValid = - // - (hasBullOBFVGs && - !hasBearOBFVGs && - bullOBFVGsCount >= 1) - // - || - // - (hasBearOBFVGs && - !hasBullOBFVGs && - bearOBFVGsCount >= 1) - // - ; - - // - if (isValid) - { - // - if (hasBullOBFVGs) - { - // - Copy( - bullOBFVGs, - orderFlow // - ); - } - else if (hasBearOBFVGs) - { - // - Copy( - bearOBFVGs, - orderFlow // - ); - } - - // - orderFlowDir = - hasBullOBFVGs - ? X_DIRECTION_BULLISH - : X_DIRECTION_BEARISH; - - // - bool isPlacePassed = true; - if (hasBroken) - { - // - bool isBullish = IsBullish(orderFlowDir); - - // - idx = GetYoungest(orderFlow); - bool hasYounget = IsValidIndex(idx); - - // - isPlacePassed = - ArraySize(orderFlow) > 1 - ? true - : isBullish - ? (IsAbove( - orderFlow[idx].ob, - lastBroken.ob, - true // Ignore Inside ... - )) - : (IsBelow( - orderFlow[idx].ob, - lastBroken.ob, - true // Ignore Inside - )); - - // - Clean(brokenOrderFlow); - AddRef( - orderFlow[idx], - brokenOrderFlow // - ); - } - - // - if (!isPlacePassed) - { - // - Clean(orderFlow); - orderFlowDir = X_DIRECTION_NONE; - } - - // - result = ArraySize(orderFlow); - } - } - - // - Clean(bullOBFVGs); - Clean(bearOBFVGs); - - // - lastBroken.Clean(); - - // - if (IsValidSize(result)) - { - // - int count = GetSwings(swings); - bool has = count >= 2; - bool isBullish = IsBullish(orderFlowDir); - if (has) - { - // - // Get Max / Min ... - double max = 0; - double min = 0; - datetime maxAt = NULL; - datetime minAt = NULL; - for (int i = 0; i < count; i++) - { - // - XOBFVGPivot iPivot = swings[i]; - - // - if (!iPivot.IsValid()) - { - // - iPivot.Clean(); - continue; - } - - // - // Min ... - bool canSetMin = - min == 0 - ? true - : min > iPivot.value; - if (canSetMin) - { - // - minAt = iPivot.at; - min = iPivot.value; - } - - // - // Max ... - bool canSetMax = - max == 0 - ? true - : max < iPivot.value; - if (canSetMax) - { - // - maxAt = iPivot.at; - max = iPivot.value; - } - - // - iPivot.Clean(); - } - - // - double price1 = - isBullish - ? min - : max; - double price2 = - isBullish - ? max - : min; - datetime time1 = - isBullish - ? minAt - : maxAt; - datetime time2 = - isBullish - ? maxAt - : minAt; - - // - color clrTrend = clrNONE; - - // - string trendName = - "XORDFLW" + ToString(orderFlowDir) + "_" + "XTRNDL_" + - ToString(period) + "_" + - ToString(price1) + "_" + - ToString(price2) + "_"; - - // - orderFlowTrend = new CChartObjectTrend(); - has = orderFlowTrend.Create( - 0, - trendName, - 0, - time1, - price1, - time2, - price2 // - ); - - // - if (has) - { - // - orderFlowTrend.Width(1); - orderFlowTrend.Color(clrTrend); - orderFlowTrend.RayRight(true); - } - } - } - - // - return result; - } - - // - void AddOrderFlowItem( - XOBFVG &orderItem // - ) - { - // - ENUM_X_DIRECTION trend; - if (!HasOrderFlow(trend)) - { - return; - } - - // - bool isSameDir = orderItem - .GetDirection() == trend; - if (!isSameDir) - { - return; - } - - // - bool isBullish = IsBullish(trend); - - // - AddRef( - orderItem, - orderFlow // - ); - - // - Sort( - orderFlow, - trend, - true // Ignore Inside ... - ); - } - - // - bool IsDestroyed( - int barIndex = 0, - ENUM_TIMEFRAMES forPeriod = NULL // - ) - { - // - bool result = false; - - // - if (barIndex < 0) - { - barIndex = 0; - } - - // - if (!IsValid(forPeriod)) - { - forPeriod = period; - } - - // - result = IsValid(); - if (!result) - { - return result; - } - - // - XOHCL bar; - result = bar.Init( - symbol, - period, - barIndex // - ); - if (!result) - { - // - bar.Clean(); - return result; - } - - // - XOHCL cBar; - result = bar.GetPreviousBar(cBar); - if (!result) - { - // - bar.Clean(); - cBar.Clean(); - - // - return result; - } - - // - bool isSupplyZoneBreaked = - // - bar.low > supplyZone.Upper() && - cBar.low > supplyZone.Upper() - // - ; - - // - bool isDemandZoneBreaked = - // - bar.high < demandZone.Lower() && - cBar.high < demandZone.Lower() - // - ; - - // - bar.Clean(); - cBar.Clean(); - - // - result = isSupplyZoneBreaked || - isDemandZoneBreaked; - - // - return result; - } - - // - bool IsOrderFlowBreaked( - int &breakedIndex, - bool forceOBBreake = false, - bool forceFVGBreake = false, - int barIndex = 0, - ENUM_TIMEFRAMES forPeriod = NULL // - ) - { - // - bool result = false; - - // - breakedIndex = -1; - - // - if (barIndex < 0) - { - barIndex = 0; - } - - // - if (!IsValid(forPeriod)) - { - forPeriod = period; - } - - // - ENUM_X_DIRECTION orderFlowDir; - result = HasOrderFlow(orderFlowDir); - if (!result) - { - return result; - } - - // - XOHCL bar; - result = bar.Init( - symbol, - forPeriod, - barIndex // - ); - if (!result) - { - // - bar.Clean(); - return result; - } - - // - bool isBullish = IsBullish(orderFlowDir); - - // - int idx = - isBullish - ? GetHighest(orderFlow) - : GetLowest(orderFlow); - result = IsValidIndex(idx); - if (!result) - { - // - bar.Clean(); - return result; - } - - // - XOHCL obBreakerBar; - bool isOBBodyOut = false; - bool isOBBreaked = orderFlow[idx].ob.IsBreaked( - orderFlowDir, - obBreakerBar, - isOBBodyOut, - false, // Ignore Start ... - false, // Started Bar Body Out ... - forPeriod // - ); - - // - if (!isOBBreaked) - { - obBreakerBar.Clean(); - } - - // - XOHCL fvgBreakerBar; - bool isFVGBodyOut = false; - bool isFVGBreaked = orderFlow[idx].fvg.IsBreaked( - orderFlowDir, - fvgBreakerBar, - isFVGBodyOut, - false, // Ignore Start ... - true, // Started Bar Body Out ... - forPeriod // - ); - - // - if (!isFVGBreaked) - { - fvgBreakerBar.Clean(); - } - - // - isOBBreaked = - obBreakerBar.IsValid(); - - // - isFVGBreaked = - fvgBreakerBar.IsValid(); - - // - if ((forceOBBreake && forceFVGBreake) || - (!forceOBBreake && !forceFVGBreake)) - { - // - result = isOBBreaked || - isFVGBreaked; - } - else if (forceOBBreake) - { - result = isOBBreaked; - } - else if (forceFVGBreake) - { - result = isFVGBreaked; - } - - // - if (result) - { - breakedIndex = idx; - } - - // - bar.Clean(); - obBreakerBar.Clean(); - fvgBreakerBar.Clean(); - - // - return result; - } - - // - bool DetectPriority( - ENUM_X121SMC_XWZ_PRIORITY &priority, - ENUM_X_DIRECTION forDir, - int barIndex = 0, - ENUM_TIMEFRAMES forPeriod = NULL // - ) - { - // - bool result = false; - - // - priority = X121SMC_XWZ_PRIORITY_NONE; - - // - if (barIndex < 0) - { - barIndex = 0; - } - - // - if (!IsValid(forPeriod)) - { - forPeriod = period; - } - - // - result = IsValid() && - HasDirection(forDir); - if (!result) - { - return result; - } - - // - bool isBullish = IsBullish(forDir); - - // - XOHCL bar; - result = bar.Init( - symbol, - forPeriod, - barIndex // - ); - if (!result) - { - // - bar.Clean(); - return result; - } - - // - if (bar.high < supplyZone.Upper() && - bar.low > supplyZone.Lower()) - { - // - priority = - isBullish - ? X121SMC_XWZ_PRIORITY_NONE - : X121SMC_XWZ_PRIORITY_STRONG_HIGH; - } - else if (bar.high < supplyZone.Lower() && - bar.low > quarter1) - { - // - priority = - isBullish - ? X121SMC_XWZ_PRIORITY_WEAK - : X121SMC_XWZ_PRIORITY_HIGH; - } - else if (bar.high < quarter1 && - bar.low > quarter2) - { - // - priority = - isBullish - ? X121SMC_XWZ_PRIORITY_LOW - : X121SMC_XWZ_PRIORITY_REGULAR; - } - else if (bar.high < quarter2 && - bar.low > quarter3) - { - // - priority = - isBullish - ? X121SMC_XWZ_PRIORITY_REGULAR - : X121SMC_XWZ_PRIORITY_LOW; - } - else if (bar.high < quarter3 && - bar.low > demandZone.Upper()) - { - // - priority = - isBullish - ? X121SMC_XWZ_PRIORITY_HIGH - : X121SMC_XWZ_PRIORITY_WEAK; - } - else if (bar.high < demandZone.Upper() && - bar.low > demandZone.Lower()) - { - // - priority = - isBullish - ? X121SMC_XWZ_PRIORITY_STRONG_HIGH - : X121SMC_XWZ_PRIORITY_NONE; - } - - // - result = priority != X121SMC_XWZ_PRIORITY_NONE && - priority != X121SMC_XWZ_PRIORITY_WEAK; - - // - bar.Clean(); - - // - return result; - } - - // - // - // - - // - bool HasSupplyZones() - { - return HasChild(supplyZones); - } - - // - int CountSupplyZones() - { - return ArraySize(supplyZones); - } - - // - bool HasDemandZones() - { - return HasChild(demandZones); - } - - // - int CountDemandZones() - { - return ArraySize(demandZones); - } - - // - int DetectSupplyZones( - XPOIState &state // - ) - { - // - int result = CountSupplyZones(); - - bool isValid = state.IsValid() && - state.HasSupplyZones(); - if (!isValid) - { - return result; - } - - // - XCSupplyZone *tmpZones[]; - Copy( - state.supplyZones, - tmpZones // - ); - int count = FilterZones( - // - tmpZones, - // - X_DIRECTION_BULLISH, - state.period, - NULL, - // - // Start ... - XZONE_STATE_IGNORED, - false, - // - // Activation ... - XZONE_STATE_IGNORED, - false, - // - // Breake ... - XZONE_STATE_FAILED, - false, - // - // Work ... - XZONE_STATE_IGNORED, - false, - // - true, // Apply Sore ... - true // Ignore Inside ... - ); - bool has = IsValidSize(count); - if (!has) - { - return result; - } - - // - int idx = -1; - while (HasChild(tmpZones)) - { - // - XCSupplyZone *iZone; - idx = GetHighest(tmpZones); - has = IsValidIndex(idx); - if (!has) - { - // - ZeroMemory(iZone); - continue; - } - - // - iZone = tmpZones[idx]; - - // - ArrayRemove( - tmpZones, - idx, - 1 // - ); - - // - idx = FindIndex( - iZone, - supplyZones // - ); - has = IsValidIndex(idx); - if (has) - { - // - ZeroMemory(iZone); - continue; - } - - // - Add( - iZone, - supplyZones // - ); - } - - // - int after = CountSupplyZones(); - result = after; - - // - return result; - } - - // - int DetectDemandZones( - XPOIState &state // - ) - { - // - int result = CountDemandZones(); - - bool isValid = state.IsValid() && - state.HasDemandZones(); - if (!isValid) - { - return result; - } - - // - XCDemandZone *tmpZones[]; - Copy( - state.demandZones, - tmpZones // - ); - int count = FilterZones( - // - tmpZones, - // - X_DIRECTION_BEARISH, - state.period, - NULL, - // - // Start ... - XZONE_STATE_IGNORED, - false, - // - // Activation ... - XZONE_STATE_IGNORED, - false, - // - // Breake ... - XZONE_STATE_FAILED, - false, - // - // Work ... - XZONE_STATE_IGNORED, - false, - // - true, // Apply Sore ... - true // Ignore Inside ... - ); - bool has = IsValidSize(count); - if (!has) - { - return result; - } - - // - int idx = -1; - while (HasChild(tmpZones)) - { - // - XCDemandZone *iZone; - idx = GetLowest(tmpZones); - has = IsValidIndex(idx); - if (!has) - { - // - ZeroMemory(iZone); - continue; - } - - // - iZone = tmpZones[idx]; - - // - ArrayRemove( - tmpZones, - idx, - 1 // - ); - - // - idx = FindIndex( - iZone, - demandZones // - ); - has = IsValidIndex(idx); - if (has) - { - // - ZeroMemory(iZone); - continue; - } - - // - Add( - iZone, - demandZones // - ); - } - - // - int after = CountDemandZones(); - result = after; - - // - return result; - } - - // - // - // - - // - void UpdateTo(datetime value = NULL) - { - // - value = NormalizeTime(value); - - // - int count = 0; - bool has = false; - - // - has = HasSupplyZone(); - if (has) - { - supplyZone.To(value); - } - - // - has = HasDemandZone(); - if (has) - { - demandZone.To(value); - } - - // - // Order Flow ... - ENUM_X_DIRECTION orderFlowDir; - has = HasOrderFlow(orderFlowDir); - if (has) - { - // - count = CountOrderFlow(); - for (int i = 0; i < count; i++) - { - orderFlow[i].UpdateTo(value); - } - } - - // - has = HasSupplyZones(); - if (has) - { - // - count = CountSupplyZones(); - for (int i = 0; i < count; i++) - { - supplyZones[i].To(value); - } - } - - // - has = HasDemandZones(); - if (has) - { - // - count = CountDemandZones(); - for (int i = 0; i < count; i++) - { - demandZones[i].To(value); - } - } - - // - } -}; - -// -// Definitions ... -struct X121SMCStrategyXWZSignalConditions -{ - // - // Props ... - - // - string symbol; - ENUM_TIMEFRAMES period; - - // - double sl; - double reward; - double amountPercent; - ENUM_X_DIRECTION dir; - ENUM_X_POSITION_TYPES type; - - // - // Setup Props ... - - // - datetime setupTime; - datetime triggerTime; - - // - double pivot; - double point; - double targets[]; - - // - XOBFVG signalZone; - - // - ENUM_X121SMC_XWZ_PRIORITY priority; - ENUM_X121SMC_XWZ_PROVIDERS provider; - - // - // Constructor ... - X121SMCStrategyXWZSignalConditions() - { - Clean(); - } - - // - // Tools ... - - /** - * Cleaning Up ... - */ - void Clean() - { - // - sl = 0; - - // - dir = X_DIRECTION_NONE; - type = X_POSITION_TYPE_NONE; - - // - symbol = NULL; - period = NULL; - setupTime = NULL; - triggerTime = NULL; - - // - ExtensionClean(); - - // - ZeroMemory(this); - } - - /** - * Check Condition is Setting Up ... - * - * @param dir: ENUM_X_DIRECTION member, Setting Up Direction ... - * - * @return ( bool ) - */ - bool IsSetuped() - { - // - bool result = false; - - // - result = IsValid(setupTime) && - HasDirection(dir); - if (!result) - { - return result; - } - - // - return result; - } - - /** - * Calculate Setup Age ... - * - * @return ( int ) - */ - int GetSetupAge() - { - // - int result = 0; - - // - if (!IsSetuped()) - { - return result; - } - - // - result = (int)(TimeCurrent() - setupTime) / PeriodSeconds(period); - - // - return result; - } - - /** - * Detect How we Can Trigger Signal ... - * - * @return ( bool ) - */ - bool CanTrigger() - { - // - bool result = false; - - // - result = - // - sl > 0 && - IsValid(symbol) && - IsValid(period) && - IsValid(triggerTime) && - type != X_POSITION_TYPE_ALL && - type != X_POSITION_TYPE_NONE - // - ; - - // - return result; - } - - // - // Extensions ... - - /** - * Clean Additional Properties ... - */ - void ExtensionClean() - { - // - pivot = 0; - point = 0; - - // - reward = 0; - amountPercent = 0; - - // - Clean(targets); - signalZone.Clean(); - - // - provider = X121SMC_XWZ_PROVIDER_NONE; - } - - // - // - // - - // - void UpdateTo(datetime value = NULL) - { - // - value = NormalizeTime(value); - - // - int count = 0; - bool has = false; - } - - // -}; - -// \ No newline at end of file diff --git a/Documents/BKP/x-saherelm.x-poi.class.mq5 b/Documents/BKP/x-saherelm.x-poi.class.mq5 deleted file mode 100644 index be134d9f..00000000 --- a/Documents/BKP/x-saherelm.x-poi.class.mq5 +++ /dev/null @@ -1,4218 +0,0 @@ -/////////////////////////////////////////////////////// -// -// SaherElm IT Center MQL5 Class Library -// -------------------------------------- -// Name: XPOI -// Description: Provides Point of Interests ... -// - Swing Highs; -// - Swing Lows; -// -// Maintainer: -// ------------ -// Hadi Khazaee Asl (hadi_khazaee_asl@yahoo.com) -// -////////////////////////////////////////////////////// -// -// Global Properties ... -#property library -#property copyright "Copyright 2023, SaherElm IT Center" -#property link "https://www.saherelm.ir" -#property version "1.00" -#property strict - -// -// Imports ... - -// -#include "../Classes/x-saherelm.x-alert.class.mq5" -#include "../Classes/x-saherelm.x-bar.analyser.class.mq5" -#include "../Classes/x-saherelm.x-poi.drawer.class.mq5" -#include "../Libraries/x-saherelm.x-poi.lib.mq5" - -// -#include - -// -// Implementation ... - -// -// POI Detector Class ... -class XCPOIDetector : public XCBaseAlert -{ - // - public: - // - XCPOIDrawer *mDrawer; - - // - // Constructors ... - /** - * Create an Instance ... - * - * @param symbol: String ... - * @param period: ENUM_TIMEFRAMES member ... - */ - void XCPOIDetector( - string symbol, - ENUM_TIMEFRAMES period // - ) - { - // - // Attach Required Properties ... - mSymbol = symbol; - mPeriod = period; - - // - // Initialize Bar Tracker ... - mBarTracker.Init( - mSymbol, - mPeriod // - ); - - // - // Create Default Drawer Instance ... - mDrawer = new XCPOIDrawer(); - - // - // Apply Default Configurations ... - Default(); - } - - // - // Deconstructor ... - void ~XCPOIDetector() - { - Destroy(); - } - - // - // Getter(s) / Setter(s) ... - - /** - * Retrieve Detector Symbol ... - * - * @return ( string ) - */ - string GetSymbol() - { - return mSymbol; - } - - /** - * Retrieve Detector Period ... - * - * @return ( ENUM_TIMEFRAMES ) - */ - ENUM_TIMEFRAMES GetPeriod() - { - return mPeriod; - } - - /** - * Get Max Number of POIs which holds ... - * - * @return ( int ) - */ - int MaxNumberOfPOIs() - { - return mMaxNumberOfPOIs; - } - - /** - * Set Max Number of POIs which holds ... - * 0 => Infinity ... - * - * @param value: Integer ... - */ - void MaxNumberOfPOIs(int value) - { - // - if (value < 0) - { - value = 0; - } - - // - mMaxNumberOfPOIs = value; - } - - /** - * Get Number of POI(s) which must Find at Initializations ... - * - * @return ( int ) - */ - int MaxNumberOfRequiredPOIs() - { - return mMaxNumberOfRequiredPOIs; - } - - /** - * Set Number of POI(s) which must Find at Initializations ... - * 2 is Default ... - * - * @param value: Integer ... - */ - void MaxNumberOfRequiredPOIs(int value) - { - // - if (value < 2) - { - value = 2; - } - - // - mMaxNumberOfRequiredPOIs = value; - } - - /** - * Check Is Locked or not ... - * - * @return ( bool ) - */ - bool IsLocked() - { - return mLock; - } - - // - // POI(s) Configs ... - - // - // Swings ... - - /** - * Get Swing Verification Range Length ... - * - * @return ( int ) - */ - int SwingRange() - { - return mSwingRange; - } - - /** - * Set Swing Verification Range Length ... - * - * @param value: Integer ... - */ - void SwingRange(int value) - { - // - if (value < 0) - { - value = 0; - } - - // - mSwingRange = value; - } - - // - // Momentum Bars ... - - /** - * Get Momentum Bars must Extends Range ... - * - * @return ( int ) - */ - int MomentumBarExtendRange() - { - return mMomentumBarExtendRange; - } - - /** - * Set Momentum Bars must Extends Range ... - * - * @param value: Integer ... - */ - void MomentumBarExtendRange(int value) - { - // - if (value < 0) - { - value = 0; - } - - // - mMomentumBarExtendRange = value; - } - - /** - * Get Momentum Bars Body Percent ... - * - * @return ( double ) - */ - double MomentumBarBodyPercent() - { - return mMomentumBarBodyPercent; - } - - /** - * Set Momentum Bars Body Percent ... - * - * @param value: Double ... - */ - void MomentumBarBodyPercent(double value) - { - // - if (value < 50) - { - value = 50; - } - - // - mMomentumBarBodyPercent = value; - } - - // - // Rejection Bars ... - - /** - * Get Rejection Bars must Extends Range ... - * - * @return ( int ) - */ - int RejectionBarExtendRange() - { - return mRejectionBarExtendRange; - } - - /** - * Set Rejection Bars must Extends Range ... - * - * @param value: Integer ... - */ - void RejectionBarExtendRange(int value) - { - // - if (value < 0) - { - value = 0; - } - - // - mRejectionBarExtendRange = value; - } - - /** - * Get Rejection Bars Shadow Percent ... - * - * @return ( double ) - */ - double RejectionBarShadowPercent() - { - return mRejectionBarShadowPercent; - } - - /** - * Set Rejection Bars Shadow Percent ... - * - * @param value: Double ... - */ - void RejectionBarShadowPercent(double value) - { - // - if (value < 50) - { - value = 50; - } - - // - mRejectionBarShadowPercent = value; - } - - // - // Support and Resistance Zone(s) ... - - /** - * Get Support and Resistance Range for Verification ... - * - * @return ( int ) - */ - int SupportAndResistanceRange() - { - return mSupportAndResistanceRange; - } - - /** - * Set Support and Resistance Range for Verification ... - * - * @param value: Integer ... - */ - void SupportAndResistanceRange(int value) - { - // - if (value < 2) - { - value = 2; - } - - // - mSupportAndResistanceRange = value; - } - - // - // Supply and Demand Zone(s) ... - - /** - * Get Supply and Demand Range Verifications ... - * - * @return ( int ) - */ - int SupplyAndDemandRange() - { - return mSupplyAndDemandRange; - } - - /** - * Set Supply and Demand Range Verifications ... - * - * @param value: Integer ... - */ - void SupplyAndDemandRange(int value) - { - // - if (value < 2) - { - value = 2; - } - - // - mSupplyAndDemandRange = value; - } - - // - // Order Blocks ... - - /** - * Get Order Blocks Detection Bars ... - * - * @return ( int ) - */ - int OrderBlocksSameBars() - { - return mOrderBlocksSameBars; - } - - /** - * Set Order Blocks Detection Bars ... - * - * @param value: Argument 1 - */ - void OrderBlocksSameBars(int value) - { - // - if (value < 0) - { - value = 0; - } - - // - mOrderBlocksSameBars = value; - } - - // - // Fair Value Gaps ... - - /** - * Get Fair Value Gaps Detection Same Bars ... - * - * @return ( int ) - */ - int FairValueGapsSameBars() - { - return mFairValueGapsSameBars; - } - - /** - * Set Fair Value Gaps Detection Same Bars ... - * - * @param value: Integer ... - */ - void FairValueGapsSameBars(int value) - { - // - if (value < 0) - { - value = 0; - } - - // - mFairValueGapsSameBars = value; - } - - // - // Ticks Zone ... - - /** - * Get Ticks Range Levels ... - * - * @return ( int ) - */ - int TicksRangeZoneLevel() - { - return mTicksRangeZoneLevel; - } - - /** - * Set Ticks Range Levels ... - * - * @param value: Integer ... - */ - void TicksRangeZoneLevel(int value) - { - // - if (value < 2) - { - value = 2; - } - - // - mTicksRangeZoneLevel = value; - } - - /** - * Get Ticks Range Zone Loopback Period ... - * - * @return ( int ) - */ - int TicksRangeZoneRange() - { - return mTicksRangeZoneRange; - } - - /** - * Set Ticks Range Zone Loopback Period ... - * - * @param value: Integer ... - */ - void TicksRangeZoneRange(int value) - { - // - if (value < 7) - { - value = 7; - } - - // - mTicksRangeZoneRange = value; - } - - // - // Actions ... - - /** - * Initialize POI Detector ... - */ - void Init() - { - DetectRequiredPOIs(); - } - - /** - * Update POI(s) ... - * - * @param state: an Array Refrence of ENUM_XPOI_EVENTS members ... - */ - int Update( - ENUM_XPOI_EVENTS &state[] // - ) - { - // - int result = 0; - - // - Clean(state); - - // - // Check Bar Tracker if Waits ... - if (!mBarTracker.IsNewBar()) - { - return result; - } - - // - int zIndex = 0; - int cIndex = zIndex + 1; - int pIndex = cIndex + 1; - - // - string symbol = GetSymbol(); - ENUM_TIMEFRAMES period = GetPeriod(); - - // - datetime cTime = TimeCurrent(); - - // - XOHCL zBar; - bool isInited = zBar.Init( - symbol, - period, - zIndex // - ); - if (!isInited) - { - return result; - } - - // - XOHCL cBar; - isInited = cBar.Init( - symbol, - period, - cIndex // - ); - if (!isInited) - { - return result; - } - - // - // POI Detecting ... - bool isDetected = false; - - // - // Swings ... - int iSwingRange = SwingRange(); - if (iSwingRange > 0) - { - // - XOHCL swingBar; - isInited = swingBar.Init( - symbol, - period, - zIndex + iSwingRange // - ); - if (isInited) - { - // - // Swing High ... - isDetected = DetectSwingHigh(swingBar); - if (isDetected) - { - // - ENUM_XPOI_EVENTS event = X_SWING_HIGH_DETECTED; - XCSwing *param; - bool hasItem = GetLastItem( - param, - mSwingHighs // - ); - if (hasItem) - { - // - NotifyEventListeners( - event, - param // - ); - } - - // - Add( - event, - state // - ); - } - - // - // Swing Low ... - isDetected = DetectSwingLow(swingBar); - if (isDetected) - { - // - ENUM_XPOI_EVENTS event = X_SWING_LOW_DETECTED; - XCSwing *param; - bool hasItem = GetLastItem( - param, - mSwingLows // - ); - if (hasItem) - { - // - NotifyEventListeners( - event, - param // - ); - } - - // - Add( - event, - state // - ); - } - } - } - - // - // Bullish Momentum Bars ... - isDetected = DetectBullishMomentumBar(cBar); - if (isDetected) - { - // - ENUM_XPOI_EVENTS event = X_BULLISH_MOMENTUM_BAR_DETECTED; - XCMomentumBar *param; - bool hasItem = GetLastItem( - param, - mBullishMomentumBars // - ); - if (hasItem) - { - // - NotifyEventListeners( - event, - param // - ); - } - - // - Add( - event, - state // - ); - } - - // - // Bearish Momentum Bars ... - isDetected = DetectBearishMomentumBar(cBar); - if (isDetected) - { - // - ENUM_XPOI_EVENTS event = X_BEARISH_MOMENTUM_BAR_DETECTED; - XCMomentumBar *param; - bool hasItem = GetLastItem( - param, - mBearishMomentumBars // - ); - if (hasItem) - { - // - NotifyEventListeners( - event, - param // - ); - } - - // - Add( - event, - state // - ); - } - - // - // Bullish Rejection Bars ... - isDetected = DetectBullishRejectionBar(cBar); - if (isDetected) - { - // - ENUM_XPOI_EVENTS event = X_BULLISH_REJECTION_BAR_DETECTED; - XCRejectionBar *param; - bool hasItem = GetLastItem( - param, - mBullishRejectionBars // - ); - if (hasItem) - { - // - NotifyEventListeners( - event, - param // - ); - } - - // - Add( - event, - state // - ); - } - - // - // Bearish Rejection Bars ... - isDetected = DetectBearishRejectionBar(cBar); - if (isDetected) - { - // - ENUM_XPOI_EVENTS event = X_BEARISH_REJECTION_BAR_DETECTED; - XCRejectionBar *param; - bool hasItem = GetLastItem( - param, - mBearishRejectionBars // - ); - if (hasItem) - { - // - NotifyEventListeners( - event, - param // - ); - } - - // - Add( - event, - state // - ); - } - - // - // Support and Resistance Zones ... - int supResRange = SupportAndResistanceRange(); - if (supResRange > 0) - { - // - XOHCL supResBar; - isInited = supResBar.Init( - symbol, - period, - zIndex + supResRange // - ); - if (isInited) - { - // - // Support Zones ... - isDetected = DetectSupportZone(supResBar); - if (isDetected) - { - // - ENUM_XPOI_EVENTS event = X_SUPPORT_ZONE_DETECTED; - XCSupportZone *param; - bool hasItem = GetLastItem( - param, - mSupportZones // - ); - if (hasItem) - { - // - NotifyEventListeners( - event, - param // - ); - } - - // - Add( - event, - state // - ); - } - - // - // Resistance Zones ... - isDetected = DetectResistanceZone(supResBar); - if (isDetected) - { - // - ENUM_XPOI_EVENTS event = X_RESISTANCE_ZONE_DETECTED; - XCResistanceZone *param; - bool hasItem = GetLastItem( - param, - mResistanceZones // - ); - if (hasItem) - { - // - NotifyEventListeners( - event, - param // - ); - } - - // - Add( - event, - state // - ); - } - } - } - - // - // Supply And Demand Zones ... - int supDemRange = SupplyAndDemandRange(); - if (supDemRange > 0) - { - // - // Supply Zone ... - isDetected = DetectSupplyZone(cBar); - if (isDetected) - { - // - ENUM_XPOI_EVENTS event = X_SUPPLY_ZONE_DETECTED; - XCSupplyZone *param; - bool hasItem = GetLastItem( - param, - mSupplyZones // - ); - if (hasItem) - { - // - NotifyEventListeners( - event, - param // - ); - } - - // - Add( - event, - state // - ); - } - - // - // Demand Zone ... - isDetected = DetectDemandZone(cBar); - if (isDetected) - { - // - ENUM_XPOI_EVENTS event = X_DEMAND_ZONE_DETECTED; - XCDemandZone *param; - bool hasItem = GetLastItem( - param, - mDemandZones // - ); - if (hasItem) - { - // - NotifyEventListeners( - event, - param // - ); - } - - // - Add( - event, - state // - ); - } - } - - // - // Order Blocks ... - int obSameBars = OrderBlocksSameBars(); - if (obSameBars > 0) - { - // - // Bullish Order Block ... - isDetected = DetectBullishOrderBlock(cBar); - if (isDetected) - { - // - ENUM_XPOI_EVENTS event = X_BULLISH_ORDERBLOCK_DETECTED; - XCOrderBlock *param; - bool hasItem = GetLastItem( - param, - mBullishOrderBlocks // - ); - if (hasItem) - { - // - NotifyEventListeners( - event, - param // - ); - } - - // - Add( - event, - state // - ); - } - - // - // Bearish Order Block ... - isDetected = DetectBearishOrderBlock(cBar); - if (isDetected) - { - // - ENUM_XPOI_EVENTS event = X_BEARISH_ORDERBLOCK_DETECTED; - XCOrderBlock *param; - bool hasItem = GetLastItem( - param, - mBearishOrderBlocks // - ); - if (hasItem) - { - // - NotifyEventListeners( - event, - param // - ); - } - - // - Add( - event, - state // - ); - } - } - - // - // Fair Value Gaps ... - int fvgSameBars = FairValueGapsSameBars(); - if (fvgSameBars > 0) - { - // - // Bullish Fair Value Gap ... - isDetected = DetectBullishFairValueGap(cBar); - if (isDetected) - { - // - ENUM_XPOI_EVENTS event = X_BULLISH_FVG_DETECTED; - XCFVG *param; - bool hasItem = GetLastItem( - param, - mBullishFairValueGaps // - ); - if (hasItem) - { - // - NotifyEventListeners( - event, - param // - ); - } - - // - Add( - event, - state // - ); - } - - // - // Bearish Fair Value Gap ... - isDetected = DetectBearishFairValueGap(cBar); - if (isDetected) - { - // - ENUM_XPOI_EVENTS event = X_BEARISH_FVG_DETECTED; - XCFVG *param; - bool hasItem = GetLastItem( - param, - mBearishFairValueGaps // - ); - if (hasItem) - { - // - NotifyEventListeners( - event, - param // - ); - } - - // - Add( - event, - state // - ); - } - } - - // - // Ticks Range Zone ... - int ticksLevels = TicksRangeZoneLevel(); - int ticksRange = TicksRangeZoneRange(); - if (ticksLevels > 0 && - ticksRange > 0) - { - // - isDetected = DetectTicksZoneRange(cBar); - if (isDetected) - { - } - } - - // - ValidatePOIs(cBar); - - // - CleanupUnusedPOIs(); - - // - mBarTracker.Waits(); - - // - result = ArraySize(state); - - // - return result; - } - - /** - * Destroy Class ... - */ - void Destroy() - { - // - DestroyPOIs(); - DestroySessions(); - DestroyEventListeners(); - - // - delete mDrawer; - delete mTicksZone; - - // - ZeroMemory(mDrawer); - ZeroMemory(mTicksZone); - } - - // - // Retrievers ... - - /** - * Get Current State of POIs ... - * - * @param state: XPOIState instance ... - */ - void GetState( - XPOIState &state // - ) - { - // - state.Clean(); - - // - state.symbol = mSymbol; - state.period = mPeriod; - state.time = TimeCurrent(); - - // - Copy( - mSwingHighs, - state.swingHighs // - ); - - // - Copy( - mSwingLows, - state.swingLows // - ); - - // - Copy( - mBullishMomentumBars, - state.bullishMomentumBars // - ); - - // - Copy( - mBearishMomentumBars, - state.bearishMomentumBars // - ); - - // - Copy( - mBullishRejectionBars, - state.bullishRejectionBars // - ); - - // - Copy( - mBearishRejectionBars, - state.bearishRejectionBars // - ); - - // - Copy( - mSupportZones, - state.supportZones // - ); - - // - Copy( - mResistanceZones, - state.resistanceZones // - ); - - // - Copy( - mSupplyZones, - state.supplyZones // - ); - - // - Copy( - mDemandZones, - state.demandZones // - ); - - // - Copy( - mBullishOrderBlocks, - state.bullishOrderBlocks // - ); - - // - Copy( - mBearishOrderBlocks, - state.bearishOrderBlocks // - ); - - // - Copy( - mBullishFairValueGaps, - state.bullishFairValueGaps // - ); - - // - Copy( - mBearishFairValueGaps, - state.bearishFairValueGaps // - ); - - // - state.ticksZone = mTicksZone; - - // - } - - // - // Event Listeners ... - - /** - * Add Event Listener ... - * - * @param listener: TOnPOIEvent instance ... - */ - void AddEventListener(TOnPOIEvent listener) - { - // - Add( - listener, - mEventListeners // - ); - } - - // - // Destroy ... - - /** - * Destroy Detected POI(s) ... - */ - void DestroyPOIs() - { - // - Clean(mSwingHighs); - Clean(mSwingLows); - - // - Clean(mBullishMomentumBars); - Clean(mBearishMomentumBars); - - // - Clean(mBullishRejectionBars); - Clean(mBearishRejectionBars); - - // - Clean(mSupportZones); - Clean(mResistanceZones); - - // - Clean(mSupplyZones); - Clean(mDemandZones); - - // - Clean(mBullishOrderBlocks); - Clean(mBearishOrderBlocks); - - // - Clean(mBullishFairValueGaps); - Clean(mBearishFairValueGaps); - } - - /** - * Destroy Added Sessions ... - */ - void DestroySessions() - { - } - - /** - * Destroy Rejistered Event Handlers ... - */ - void DestroyEventListeners() - { - Clean(mEventListeners); - } - - // - // Virtual Actions ... - - /** - * Apply Default Configurations ... - */ - virtual void Default() - { - // - // Common ... - - // - MaxNumberOfPOIs(10); - MaxNumberOfRequiredPOIs(2); - - // - SwingRange(2); - - // - MomentumBarExtendRange(2); - MomentumBarBodyPercent(70); - - // - RejectionBarExtendRange(0); - RejectionBarShadowPercent(55); - - // - SupportAndResistanceRange(7); - - // - SupplyAndDemandRange(144); - - // - OrderBlocksSameBars(3); - - // - FairValueGapsSameBars(3); - - // - TicksRangeZoneLevel(10); - TicksRangeZoneRange(144); - } - - // - // Detector Functions ... - - /** - * Detect Swing High ... - * - * @param bar: XOHCL instance ... - * - * @return ( bool ) - */ - bool DetectSwingHigh(XOHCL &bar) - { - // - bool result = false; - - // - result = bar.IsValid(); - if (!result) - { - return result; - } - - // - int range = SwingRange(); - int barIndex = bar.Index(); - result = range > 0 && - barIndex >= range; - if (!result) - { - return result; - } - - // - result = mBarAnalyser.IsSwingHigh( - bar, - range // - ); - if (result) - { - // - XCSwing *swing; - swing = new XCSwing(); - result = swing.Init( - bar, - X_POI_SWING_HIGH // - ); - - // - if (result) - { - // - Add( - swing, - mSwingHighs // - ); - } - } - - // - return result; - } - - /** - * Detect Swing Low ... - * - * @param bar: XOHCL instance ... - * - * @return ( bool ) - */ - bool DetectSwingLow(XOHCL &bar) - { - // - bool result = false; - - // - result = bar.IsValid(); - if (!result) - { - return result; - } - - // - int range = SwingRange(); - int barIndex = bar.Index(); - result = range > 0 && - barIndex >= range; - if (!result) - { - return result; - } - - // - result = mBarAnalyser.IsSwingLow( - bar, - range // - ); - if (result) - { - // - XCSwing *swing; - swing = new XCSwing(); - result = swing.Init( - bar, - X_POI_SWING_LOW // - ); - - // - if (result) - { - // - Add( - swing, - mSwingLows // - ); - } - } - - // - return result; - } - - /** - * Detect Bullish Momentum Bar ... - * - * @param bar: XOHCL instance ... - * - * @return ( bool ) - */ - bool DetectBullishMomentumBar(XOHCL &bar) - { - // - bool result = false; - - // - result = bar.IsValid() && - bar.Index() > 0; - if (!result) - { - return result; - } - - // - int extendRange = MomentumBarExtendRange(); - double bodyPercent = MomentumBarBodyPercent(); - ENUM_X_DIRECTION dir; - result = mBarAnalyser.IsMomentumBar( - bar, - dir, - extendRange, - bodyPercent // - ); - result = - result && - dir == X_DIRECTION_BULLISH; - if (result) - { - // - XCMomentumBar *momentumBar; - momentumBar = new XCMomentumBar(); - result = momentumBar.Init(bar); - - // - if (result) - { - // - Add( - momentumBar, - mBullishMomentumBars // - ); - } - } - - // - return result; - } - - /** - * Detect Bearish Momentum Bar ... - * - * @param bar: XOHCL instance ... - * - * @return ( bool ) - */ - bool DetectBearishMomentumBar(XOHCL &bar) - { - // - bool result = false; - - // - result = bar.IsValid() && - bar.Index() > 0; - if (!result) - { - return result; - } - - // - int extendRange = MomentumBarExtendRange(); - double bodyPercent = MomentumBarBodyPercent(); - ENUM_X_DIRECTION dir; - result = mBarAnalyser.IsMomentumBar( - bar, - dir, - extendRange, - bodyPercent // - ); - result = - result && - dir == X_DIRECTION_BEARISH; - if (result) - { - // - XCMomentumBar *momentumBar; - momentumBar = new XCMomentumBar(); - result = momentumBar.Init(bar); - - // - if (result) - { - // - Add( - momentumBar, - mBearishMomentumBars // - ); - } - } - - // - return result; - } - - /** - * Detect Bullish Rejection Bar ... - * - * @param bar: XOHCL instance ... - * - * @return ( bool ) - */ - bool DetectBullishRejectionBar(XOHCL &bar) - { - // - bool result = false; - - // - result = bar.IsValid() && - bar.Index() > 0; - if (!result) - { - return result; - } - - // - int extendRange = RejectionBarExtendRange(); - double shadowPercent = RejectionBarShadowPercent(); - ENUM_X_DIRECTION dir; - result = mBarAnalyser.IsRejectionBar( - bar, - dir, - extendRange, - shadowPercent // - ); - result = - result && - dir == X_DIRECTION_BULLISH; - if (result) - { - // - XCRejectionBar *rejectionBar; - rejectionBar = new XCRejectionBar(); - result = rejectionBar.Init(bar); - - // - if (result) - { - // - Add( - rejectionBar, - mBullishRejectionBars // - ); - } - } - - // - return result; - } - - /** - * Detect Bearish Rejection Bar ... - * - * @param bar: XOHCL instance ... - * - * @return ( bool ) - */ - bool DetectBearishRejectionBar(XOHCL &bar) - { - // - bool result = false; - - // - result = bar.IsValid() && - bar.Index() > 0; - if (!result) - { - return result; - } - - // - int extendRange = RejectionBarExtendRange(); - double shadowPercent = RejectionBarShadowPercent(); - ENUM_X_DIRECTION dir; - result = mBarAnalyser.IsRejectionBar( - bar, - dir, - extendRange, - shadowPercent // - ); - result = - result && - dir == X_DIRECTION_BEARISH; - if (result) - { - // - XCRejectionBar *rejectionBar; - rejectionBar = new XCRejectionBar(); - result = rejectionBar.Init(bar); - - // - if (result) - { - // - Add( - rejectionBar, - mBearishRejectionBars // - ); - } - } - - // - return result; - } - - /** - * Detect Support Zone ... - * - * @param bar: XOHCL instance ... - * - * @return ( bool ) - */ - bool DetectSupportZone(XOHCL &bar) - { - // - bool result = false; - - // - result = bar.IsValid(); - if (!result) - { - return result; - } - - // - int range = SupportAndResistanceRange(); - int barIndex = bar.Index(); - result = range > 0 && - barIndex >= range; - if (!result) - { - return result; - } - - // - result = mBarAnalyser.IsSupport( - bar, - range // - ); - if (result) - { - // - XCSupportZone *support; - support = new XCSupportZone(); - result = support.Init( - bar, - range // - ); - - // - if (result) - { - // - datetime cTime = TimeCurrent(); - support.To(cTime); - - // - Add( - support, - mSupportZones // - ); - } - } - - // - return result; - } - - /** - * Detect Resistance Zone ... - * - * @param bar: XOHCL instance ... - * - * @return ( bool ) - */ - bool DetectResistanceZone(XOHCL &bar) - { - // - bool result = false; - - // - result = bar.IsValid(); - if (!result) - { - return result; - } - - // - int range = SupportAndResistanceRange(); - int barIndex = bar.Index(); - result = range > 0 && - barIndex >= range; - if (!result) - { - return result; - } - - // - result = mBarAnalyser.IsResistance( - bar, - range // - ); - if (result) - { - // - XCResistanceZone *resistance; - resistance = new XCResistanceZone(); - result = resistance.Init( - bar, - range // - ); - - // - if (result) - { - // - Add( - resistance, - mResistanceZones // - ); - } - } - - // - return result; - } - - /** - * Detect Supply Zone ... - * - * @param bar: XOHCL instance ... - * - * @return ( bool ) - */ - bool DetectSupplyZone(XOHCL &bar) - { - // - bool result = false; - - // - result = bar.IsValid(); - if (!result) - { - return result; - } - - // - int range = SupplyAndDemandRange(); - result = range > 0; - if (!result) - { - return result; - } - - // - int hhIDX = -1; - double hh = -1; - - // - int llIDX = -1; - double ll = -1; - - // - result = mBarAnalyser - .CalculateLoopbackHLData( - hhIDX, - hh, - llIDX, - ll, - bar, - range // - ); - if (!result) - { - return result; - } - - // - XOHCL supplyBar; - result = supplyBar.Init( - bar.symbol, - bar.period, - hhIDX // - ); - if (result) - { - // - XCSupplyZone *supply; - supply = new XCSupplyZone(); - result = supply.Init( - supplyBar, - range // - ); - - // - if (result) - { - // - datetime cTime = TimeCurrent(); - supply.To(cTime); - - // - Add( - supply, - mSupplyZones // - ); - } - } - - // - return result; - } - - /** - * Detect Demand Zone ... - * - * @param bar: XOHCL instance ... - * - * @return ( bool ) - */ - bool DetectDemandZone(XOHCL &bar) - { - // - bool result = false; - - // - result = bar.IsValid(); - if (!result) - { - return result; - } - - // - int range = SupplyAndDemandRange(); - result = range > 0; - if (!result) - { - return result; - } - - // - int hhIDX = -1; - double hh = -1; - - // - int llIDX = -1; - double ll = -1; - - // - result = mBarAnalyser - .CalculateLoopbackHLData( - hhIDX, - hh, - llIDX, - ll, - bar, - range // - ); - if (!result) - { - return result; - } - - // - XOHCL demandBar; - result = demandBar.Init( - bar.symbol, - bar.period, - llIDX // - ); - if (result) - { - // - XCDemandZone *demand; - demand = new XCDemandZone(); - result = demand.Init( - demandBar, - range // - ); - - // - if (result) - { - // - datetime cTime = TimeCurrent(); - demand.To(cTime); - - // - Add( - demand, - mDemandZones // - ); - } - } - - // - return result; - } - - /** - * Detect Bullish Order Block ... - * - * @param bar: XOHCL instance ... - * - * @return ( bool ) - */ - bool DetectBullishOrderBlock(XOHCL &bar) - { - // - bool result = false; - - // - result = bar.IsValid(); - if (!result) - { - return result; - } - - // - int sameBars = OrderBlocksSameBars(); - result = sameBars > 0; - if (!result) - { - return result; - } - - // - XOHCL obBar; - ENUM_X_DIRECTION dir; - result = mBarAnalyser - .HasOrderBlock( - bar, - obBar, - dir, - sameBars // - ); - result = - result && - dir == X_DIRECTION_BULLISH; - if (!result) - { - return result; - } - - // - if (result) - { - // - XCOrderBlock *ob; - ob = new XCOrderBlock(); - result = ob.Init( - obBar, - dir // - ); - - // - if (result) - { - // - datetime cTime = TimeCurrent(); - ob.To(cTime); - - // - Add( - ob, - mBullishOrderBlocks // - ); - } - } - - // - return result; - } - - /** - * Detect Bullish Order Block ... - * - * @param bar: XOHCL instance ... - * - * @return ( bool ) - */ - bool DetectBullishOrderBlock( - XOHCL &bar, - XCOrderBlock *&ob // - ) - { - // - bool result = false; - - // - result = bar.IsValid(); - if (!result) - { - return result; - } - - // - int sameBars = OrderBlocksSameBars(); - result = sameBars > 0; - if (!result) - { - return result; - } - - // - XOHCL obBar; - ENUM_X_DIRECTION dir; - result = mBarAnalyser - .HasOrderBlock( - bar, - obBar, - dir, - sameBars // - ); - result = - result && - dir == X_DIRECTION_BULLISH; - if (!result) - { - return result; - } - - // - if (result) - { - // - ob = new XCOrderBlock(); - result = ob.Init( - obBar, - dir // - ); - - // - if (result) - { - // - datetime cTime = TimeCurrent(); - ob.To(cTime); - } - } - - // - return result; - } - - /** - * Detect Bearish Order Block ... - * - * @param bar: XOHCL instance ... - * - * @return ( bool ) - */ - bool DetectBearishOrderBlock(XOHCL &bar) - { - // - bool result = false; - - // - result = bar.IsValid(); - if (!result) - { - return result; - } - - // - int sameBars = OrderBlocksSameBars(); - result = sameBars > 0; - if (!result) - { - return result; - } - - // - XOHCL obBar; - ENUM_X_DIRECTION dir; - result = mBarAnalyser - .HasOrderBlock( - bar, - obBar, - dir, - sameBars // - ); - result = - result && - dir == X_DIRECTION_BEARISH; - if (!result) - { - return result; - } - - // - if (result) - { - // - XCOrderBlock *ob; - ob = new XCOrderBlock(); - result = ob.Init( - obBar, - dir // - ); - - // - if (result) - { - // - datetime cTime = TimeCurrent(); - ob.To(cTime); - - // - Add( - ob, - mBearishOrderBlocks // - ); - } - } - - // - return result; - } - - /** - * Detect Bearish Order Block ... - * - * @param bar: XOHCL instance ... - * - * @return ( bool ) - */ - bool DetectBearishOrderBlock( - XOHCL &bar, - XCOrderBlock *&ob // - ) - { - // - bool result = false; - - // - result = bar.IsValid(); - if (!result) - { - return result; - } - - // - int sameBars = OrderBlocksSameBars(); - result = sameBars > 0; - if (!result) - { - return result; - } - - // - XOHCL obBar; - ENUM_X_DIRECTION dir; - result = mBarAnalyser - .HasOrderBlock( - bar, - obBar, - dir, - sameBars // - ); - result = - result && - dir == X_DIRECTION_BEARISH; - if (!result) - { - return result; - } - - // - if (result) - { - // - ob = new XCOrderBlock(); - result = ob.Init( - obBar, - dir // - ); - - // - if (result) - { - // - datetime cTime = TimeCurrent(); - ob.To(cTime); - } - } - - // - return result; - } - - /** - * Detect Bullish Fair Value Gap ... - * - * @param bar: XOHCL instance ... - * - * @return ( bool ) - */ - bool DetectBullishFairValueGap(XOHCL &bar) - { - // - bool result = false; - - // - result = bar.IsValid(); - if (!result) - { - return result; - } - - // - int sameBars = FairValueGapsSameBars(); - result = sameBars > 0; - if (!result) - { - return result; - } - - // - XOHCL prevBar; - XOHCL nextBar; - ENUM_X_DIRECTION dir; - result = mBarAnalyser - .HasFairValueGap( - bar, - prevBar, - nextBar, - dir, - sameBars // - ); - result = - result && - dir == X_DIRECTION_BULLISH; - if (!result) - { - return result; - } - - // - if (result) - { - // - XCFVG *fvg; - fvg = new XCFVG(); - result = fvg.Init( - prevBar, - nextBar, - dir // - ); - - // - if (result) - { - // - datetime cTime = TimeCurrent(); - fvg.To(cTime); - - // - Add( - fvg, - mBullishFairValueGaps // - ); - } - } - - // - return result; - } - - /** - * Detect Bearish Fair Value Gap ... - * - * @param bar: XOHCL instance ... - * - * @return ( bool ) - */ - bool DetectBearishFairValueGap(XOHCL &bar) - { - // - bool result = false; - - // - result = bar.IsValid(); - if (!result) - { - return result; - } - - // - int sameBars = FairValueGapsSameBars(); - result = sameBars > 0; - if (!result) - { - return result; - } - - // - XOHCL prevBar; - XOHCL nextBar; - ENUM_X_DIRECTION dir; - result = mBarAnalyser - .HasFairValueGap( - bar, - prevBar, - nextBar, - dir, - sameBars // - ); - result = - result && - dir == X_DIRECTION_BEARISH; - if (!result) - { - return result; - } - - // - if (result) - { - // - XCFVG *fvg; - fvg = new XCFVG(); - result = fvg.Init( - prevBar, - nextBar, - dir // - ); - - // - if (result) - { - // - datetime cTime = TimeCurrent(); - fvg.To(cTime); - - // - Add( - fvg, - mBearishFairValueGaps // - ); - } - } - - // - return result; - } - - // - protected: - // - - // - // Actions ... - - /** - * Lock ... - */ - void Lock() - { - mLock = true; - } - - /** - * Unlock ... - */ - void Unlock() - { - mLock = false; - } - - /** - * Detect Required POI(s) ... - * - * @param barIndex: Integer Start bar index ... - * 0 is Default ... - */ - void DetectRequiredPOIs(int barIndex = 0) - { - // - // Validate Reuired POI(s) ... - int requiredPOIs = MaxNumberOfRequiredPOIs(); - if (requiredPOIs <= 0) - { - return; - } - - // - // Locking Detector ... - Lock(); - - // - // Normalize Bar Index ... - if (barIndex < 0) - { - barIndex = 0; - } - - // - int swingLowsCount = 0; - int swingHighsCount = 0; - - // - int bullishMomentumBarsCount = 0; - int bearishMomentumBarsCount = 0; - - // - int bullishRejectionBarsCount = 0; - int bearishRejectionBarsCount = 0; - - // - int supportZonesCount = 0; - int resistanceZonesCount = 0; - - // - int supplyZonesCount = 0; - int demandZonesCount = 0; - - // - int bullishOrderBlocksCount = 0; - int bearishOrderBlocksCount = 0; - - // - int bullishFairValueGapsCount = 0; - int bearishFairValueGapsCount = 0; - - // - bool canContinue = true; - - // - while (canContinue) - { - // - // Swings ... - int iSwingRange = SwingRange(); - if (iSwingRange > 0) - { - // - // Swing Highs ... - swingHighsCount = DetectRequiredSwingHighs(barIndex); - if (swingHighsCount == requiredPOIs) - { - ArrayReverse(mSwingHighs); - } - - // - // Swing Lows ... - swingLowsCount = DetectRequiredSwingLows(barIndex); - if (swingLowsCount == requiredPOIs) - { - ArrayReverse(mSwingLows); - } - } - - // - bool canLookupMomentumBars = - MomentumBarExtendRange() >= 0 && - MomentumBarBodyPercent() > 0; - if (canLookupMomentumBars) - { - // - // - // Bullish Momentum Bars ... - bullishMomentumBarsCount = DetectRequiredBullishMomentumBars(barIndex); - if (bullishMomentumBarsCount == requiredPOIs) - { - ArrayReverse(mBullishMomentumBars); - } - - // - // Bearish Momentum Bars ... - bearishMomentumBarsCount = DetectRequiredBearishMomentumBars(barIndex); - if (bearishMomentumBarsCount == requiredPOIs) - { - ArrayReverse(mBearishMomentumBars); - } - } - - // - bool canLookupRejectionBars = - RejectionBarExtendRange() >= 0 && - RejectionBarShadowPercent() > 0; - if (canLookupRejectionBars) - { - // - // - // Bullish Rejection Bars ... - bullishRejectionBarsCount = DetectRequiredBullishRejectionBars(barIndex); - if (bullishRejectionBarsCount == requiredPOIs) - { - ArrayReverse(mBullishRejectionBars); - } - - // - // Bearish Rejection Bars ... - bearishRejectionBarsCount = DetectRequiredBearishRejectionBars(barIndex); - if (bearishRejectionBarsCount == requiredPOIs) - { - ArrayReverse(mBearishRejectionBars); - } - } - - // - // Support and Resistance Zones ... - int supResRange = SupportAndResistanceRange(); - if (supResRange > 0) - { - // - // Support Zone(s) ... - supportZonesCount = DetectRequiredSupportZones(barIndex); - if (supportZonesCount == requiredPOIs) - { - ArrayReverse(mSupportZones); - } - - // - // Resistance Zone(s) ... - resistanceZonesCount = DetectRequiredResistanceZones(barIndex); - if (resistanceZonesCount == requiredPOIs) - { - ArrayReverse(mResistanceZones); - } - } - - // - // Supply and Demand Zones ... - int supDemRange = SupplyAndDemandRange(); - if (supDemRange > 0) - { - // - supplyZonesCount = DetectRequiredSupplyZones(barIndex); - if (supplyZonesCount == requiredPOIs) - { - ArrayReverse(mSupplyZones); - } - - // - demandZonesCount = DetectRequiredDemandZones(barIndex); - if (demandZonesCount == requiredPOIs) - { - ArrayReverse(mDemandZones); - } - } - - // - // Oder Blocks ... - int obSameBars = OrderBlocksSameBars(); - if (obSameBars > 0) - { - // - // Bullish Order Blocks ... - bullishOrderBlocksCount = DetectRequiredBullishOrderBlocks(barIndex); - if (bullishOrderBlocksCount == requiredPOIs) - { - ArrayReverse(mBullishOrderBlocks); - } - - // - // Bearish Order Blocks ... - bearishOrderBlocksCount = DetectRequiredBearishOrderBlocks(barIndex); - if (bearishOrderBlocksCount == requiredPOIs) - { - ArrayReverse(mBearishOrderBlocks); - } - } - - // - // Fair Value Gaps ... - int fvgSameBars = FairValueGapsSameBars(); - if (fvgSameBars > 0) - { - // - // Bullish Fair Value Gaps ... - bullishFairValueGapsCount = DetectRequiredBullishFairValueGaps(barIndex); - if (bullishFairValueGapsCount == requiredPOIs) - { - ArrayReverse(mBullishFairValueGaps); - } - - // - // Bearish Fair Value Gaps ... - bearishFairValueGapsCount = DetectRequiredBearishFairValueGaps(barIndex); - if (bearishFairValueGapsCount == requiredPOIs) - { - ArrayReverse(mBearishFairValueGaps); - } - } - - // - // Swings ... - bool canContinueSwingHighs = - iSwingRange > 0 - ? swingHighsCount < requiredPOIs - : false; - bool canContinueSwingLows = - iSwingRange > 0 - ? swingLowsCount < requiredPOIs - : false; - - // - // Support and Resistance Zones ... - bool canContinueSupportZones = - supResRange > 0 - ? supportZonesCount < requiredPOIs - : false; - bool canContinueResistanceZones = - supResRange > 0 - ? resistanceZonesCount < requiredPOIs - : false; - - // - // Supply and Demand Zones ... - bool canContinueSupplyZones = - supDemRange > 0 - ? supplyZonesCount < requiredPOIs - : false; - bool canContinueDemandZones = - supDemRange > 0 - ? demandZonesCount < requiredPOIs - : false; - - // - // Order Blocks ... - bool canContinueBullishOrderBlocks = - obSameBars > 0 - ? bullishOrderBlocksCount < requiredPOIs - : false; - bool canContinueBearishOrderBlocks = - obSameBars > 0 - ? bearishOrderBlocksCount < requiredPOIs - : false; - - // - // Fair Value Gaps ... - bool canContinueBullishFairValueGaps = - fvgSameBars > 0 - ? bullishFairValueGapsCount < requiredPOIs - : false; - bool canContinueBearishFairValueGaps = - fvgSameBars > 0 - ? bearishFairValueGapsCount < requiredPOIs - : false; - - // - // Rejection Bars ... - bool canContinueBullishRejectionBars = - canLookupRejectionBars - ? bullishRejectionBarsCount < requiredPOIs - : false; - bool canContinueBearishRejectionBars = - canLookupRejectionBars - ? bearishRejectionBarsCount < requiredPOIs - : false; - - // - // Momentum Bars ... - bool canContinueBullishMomentumBars = - canLookupMomentumBars - ? bullishMomentumBarsCount < requiredPOIs - : false; - bool canContinueBearishMomentumBars = - canLookupMomentumBars - ? bearishMomentumBarsCount < requiredPOIs - : false; - - // - canContinue = - // - // Swings ... - canContinueSwingHighs || - canContinueSwingLows || - // - // Support and Resistance Zones ... - canContinueSupportZones || - canContinueResistanceZones || - // - // Supply and Demand Zones ... - canContinueSupplyZones || - canContinueDemandZones || - // - // Order Blocks ... - canContinueBullishOrderBlocks || - canContinueBearishOrderBlocks || - // - // Fair Value Gaps ... - canContinueBullishFairValueGaps || - canContinueBearishFairValueGaps || - // - // Rejection Bars ... - canContinueBullishRejectionBars || - canContinueBearishRejectionBars || - // - // Momentum Bars ... - canContinueBullishMomentumBars || - canContinueBearishMomentumBars - // - ; - if (canContinue) - { - barIndex++; - } - } - - // - // Unlocking Detector ... - Unlock(); - } - - /** - * Validate Founded POI(s) ... - * - * @param bar: XOHCL instance ... - */ - void ValidatePOIs(XOHCL &bar) - { - } - - /** - * Cleanup Unused Objects ... - */ - void CleanupUnusedPOIs() - { - // - int maxAllowed = MaxNumberOfPOIs(); - if (!IsValidSize(maxAllowed)) - { - return; - } - - // - int swingHighsCount = ArraySize(mSwingHighs); - int swingLowsCount = ArraySize(mSwingLows); - // int tradingDaysCount = ArraySize(mTradingDays); - // int marketSessionsCount = ArraySize(mMarketSessions); - // int momentumBarsCount = ArraySize(mMomentumBars); - // int rejectionBarsCount = ArraySize(mRejectionBars); - // int supportZonesCount = ArraySize(mSupportZones); - // int resistanceZonesCount = ArraySize(mResistanceZones); - // int supplyZonesCount = ArraySize(mSupplyZones); - // int demandZonesCount = ArraySize(mDemandZones); - // int bullishOBsCount = ArraySize(mBullishOrderBlocks); - // int bearishOBsCount = ArraySize(mBearishOrderBlocks); - // int bullishFVGsCount = ArraySize(mBullishFVGs); - // int bearishFVGsCount = ArraySize(mBearishFVGs); - - // - int from = 0; - int requiredPOIs = MaxNumberOfRequiredPOIs(); - int count = maxAllowed - requiredPOIs; - int to = count - 1; - - // - // Swings ... - - // // - // // Swing Highs ... - // if (swingHighsCount >= maxAllowed) - // { - // // - // ArrayRemove( - // mSwingHighs, - // from, - // count // - // ); - // } - - // // - // // Swing Lows ... - // if (swingLowsCount >= maxAllowed) - // { - // // - // ArrayRemove( - // mSwingLows, - // from, - // count // - // ); - // } - - // // - // // Trading Days ... - // if (tradingDaysCount >= maxAllowed) - // { - // // - // ArrayRemove( - // mTradingDays, - // from, - // count // - // ); - - // // - // mTradingDayObjects.DeleteRange( - // from, - // to // - // ); - // } - - // // - // // Market Sessions ... - // if (marketSessionsCount >= maxAllowed) - // { - // // - // ArrayRemove( - // mMarketSessions, - // from, - // count // - // ); - - // // - // mMarketSessionObjects.DeleteRange( - // from, - // to // - // ); - // } - - // // - // // Momentum Bars ... - // if (momentumBarsCount >= maxAllowed) - // { - // // - // ArrayRemove( - // mMomentumBars, - // from, - // count // - // ); - - // // - // mMomentumBarObjects.DeleteRange( - // from, - // to // - // ); - // } - - // // - // // Rejection Bars ... - // if (rejectionBarsCount >= maxAllowed) - // { - // // - // ArrayRemove( - // mRejectionBars, - // from, - // count // - // ); - - // // - // mRejectionBarObjects.DeleteRange( - // from, - // to // - // ); - // } - - // // - // // Support and Resistance Zones ... - - // // - // // Support Zones ... - // if (supportZonesCount >= maxAllowed) - // { - // // - // ArrayRemove( - // mSupportZones, - // from, - // count // - // ); - - // // - // mSupportZoneObjects.DeleteRange( - // from, - // to // - // ); - // } - - // // - // // Resistance Zones ... - // if (resistanceZonesCount >= maxAllowed) - // { - // // - // ArrayRemove( - // mResistanceZones, - // from, - // count // - // ); - - // // - // mResistanceZoneObjects.DeleteRange( - // from, - // to // - // ); - // } - - // // - // // Supply and Demand Zones ... - - // // - // // Supply Zones ... - // if (supplyZonesCount >= maxAllowed) - // { - // // - // ArrayRemove( - // mSupplyZones, - // from, - // count // - // ); - - // // - // mSupplyZoneObjects.DeleteRange( - // from, - // to // - // ); - // } - - // // - // // Demand Zones ... - // if (demandZonesCount >= maxAllowed) - // { - // // - // ArrayRemove( - // mDemandZones, - // from, - // count // - // ); - - // // - // mDemandZoneObjects.DeleteRange( - // from, - // to // - // ); - // } - - // // - // // Order Blocks ... - - // // - // // Bullish Order Blocks ... - // if (bullishOBsCount >= maxAllowed) - // { - // // - // ArrayRemove( - // mBullishOrderBlocks, - // from, - // count // - // ); - - // // - // mBullishOrderBlockObjects.DeleteRange( - // from, - // to // - // ); - // } - - // // - // // Bearish Order Blocks ... - // if (bearishOBsCount >= maxAllowed) - // { - // // - // ArrayRemove( - // mBearishOrderBlocks, - // from, - // count // - // ); - - // // - // mBearishOrderBlockObjects.DeleteRange( - // from, - // to // - // ); - // } - - // // - // // Fair Vakue Gaps ... - - // // - // // Bullish FVGs ... - // if (bullishFVGsCount >= maxAllowed) - // { - // // - // ArrayRemove( - // mBullishFVGs, - // from, - // count // - // ); - - // // - // mBullishFVGObjects.DeleteRange( - // from, - // to // - // ); - // } - - // // - // // Bearish FVGs ... - // if (bearishFVGsCount >= maxAllowed) - // { - // // - // ArrayRemove( - // mBearishFVGs, - // from, - // count // - // ); - - // // - // mBearishFVGObjects.DeleteRange( - // from, - // to // - // ); - // } - - // - } - - /** - * Notify Event Listeners ... - * - * @param event: ENUM_XPOI_EVENTS member, Specified Occured Event ... - * @param param: XCBasePOI implementation, Specified Event Object ... - */ - void NotifyEventListeners( - ENUM_XPOI_EVENTS event, - XCBasePOI *param // - ) - { - // - int count = ArraySize(mEventListeners); - if (!IsValidSize(count)) - { - return; - } - - // - for (int i = 0; i < count; i++) - { - // - mEventListeners[i]( - event, - param // - ); - } - } - - void AddObjectIfNotExists(XCBaseObject *object) - { - // - string name = object.ObjName(); - - // - bool canAdd = true; - int count = mDrawnObjects.Total(); - if (IsValidSize(count)) - { - // - for (int i = 0; i < count; i++) - { - // - string iName = ((XCBaseObject *)mDrawnObjects.At(i)).ObjName(); - - // - if (name == iName) - { - // - canAdd = false; - break; - } - } - } - - // - if (canAdd) - { - mDrawnObjects.Add(object); - } - } - - // - private: - // - - // - // Props ... - - // - bool mLock; // Lock State ... - string mSymbol; // Market Symbol ... - ENUM_TIMEFRAMES mPeriod; // Market Period ... - int mMaxNumberOfPOIs; // Max Allowed Number of POI(s) which Can Holds ... - int mMaxNumberOfRequiredPOIs; // Max Allowed Number of POI(s) which Must Find at Initializion Time ... - - // - CArrayObj mDrawnObjects; // Drawn Objects ... - XBarTracker mBarTracker; // Market Bar Tracker ... - XCBarAnalyser mBarAnalyser; // Bar Analyser ... - - // - TOnPOIEvent mEventListeners[]; // Event Listeners ... - - // - // POI Props ... - - // - // XDay ... - - // - // XSession ... - - // - // XSwing ... - int mSwingRange; // Swing Verification Range Length ... - - // - // Swing High ... - - // - XCSwing *mSwingHighs[]; // Holds Founded Swing Highs ... - - /** - * Detect Required Swing Highs ... - * - * @param barIndex: Integer Start bar index ... - * 0 is Default ... - * - * @return ( int ) - */ - int DetectRequiredSwingHighs(int barIndex = 0) - { - // - int result = 0; - - // - if (barIndex < 0) - { - barIndex = 0; - } - - // - int required = MaxNumberOfRequiredPOIs(); - if (required <= 0) - { - return result; - } - - // - int count = ArraySize(mSwingHighs); - if (count >= required) - { - // - result = count; - return result; - } - - // - int range = SwingRange(); - if (range < 0 || barIndex < range) - { - return result; - } - - // - string symbol = GetSymbol(); - ENUM_TIMEFRAMES period = GetPeriod(); - - // - XOHCL bar; - bool isInited = bar.Init( - symbol, - period, - barIndex // - ); - if (!isInited) - { - return result; - } - - // - DetectSwingHigh(bar); - - // - result = ArraySize(mSwingHighs); - - // - return result; - } - - // - // Swing Low ... - - // - XCSwing *mSwingLows[]; // Holds Founded Swing Lows ... - - /** - * Detect Required Swing Lows ... - * - * @param barIndex: Integer Start bar index ... - * 0 is Default ... - * - * @return ( int ) - */ - int DetectRequiredSwingLows(int barIndex = 0) - { - // - int result = 0; - - // - if (barIndex < 0) - { - barIndex = 0; - } - - // - int required = MaxNumberOfRequiredPOIs(); - if (required <= 0) - { - return result; - } - - // - int count = ArraySize(mSwingLows); - if (count >= required) - { - // - result = count; - return result; - } - - // - int range = SwingRange(); - if (range < 0 || barIndex < range) - { - return result; - } - - // - string symbol = GetSymbol(); - ENUM_TIMEFRAMES period = GetPeriod(); - - // - XOHCL bar; - bool isInited = bar.Init( - symbol, - period, - barIndex // - ); - if (!isInited) - { - return result; - } - - // - DetectSwingLow(bar); - - // - result = ArraySize(mSwingLows); - - // - return result; - } - - // - // Momentum Bars ... - int mMomentumBarExtendRange; // Momentum Bars must Extends Range ... - double mMomentumBarBodyPercent; // Momentum Bars Body Percent ... - - // - // Bullish ... - XCMomentumBar *mBullishMomentumBars[]; // Holds Founded Bullish Momentum Bars ... - - /** - * Detect Required Bullish Momentum Bars ... - * - * @param barIndex: Integer Start bar index ... - * 0 is Default ... - * - * @return ( int ) - */ - int DetectRequiredBullishMomentumBars(int barIndex = 0) - { - // - int result = 0; - - // - if (barIndex < 0) - { - barIndex = 0; - } - - // - int required = MaxNumberOfRequiredPOIs(); - if (required <= 0) - { - return result; - } - - // - int count = ArraySize(mBullishMomentumBars); - if (count >= required) - { - // - result = count; - return result; - } - - // - string symbol = GetSymbol(); - ENUM_TIMEFRAMES period = GetPeriod(); - - // - XOHCL bar; - bool isInited = bar.Init( - symbol, - period, - barIndex // - ); - if (!isInited) - { - return result; - } - - // - DetectBullishMomentumBar(bar); - - // - result = ArraySize(mBullishMomentumBars); - - // - return result; - } - - // - // Bearish ... - XCMomentumBar *mBearishMomentumBars[]; // Holds Founded Bearish Momentum Bars ... - - /** - * Detect Required Bearish Momentum Bars ... - * - * @param barIndex: Integer Start bar index ... - * 0 is Default ... - * - * @return ( int ) - */ - int DetectRequiredBearishMomentumBars(int barIndex = 0) - { - // - int result = 0; - - // - if (barIndex < 0) - { - barIndex = 0; - } - - // - int required = MaxNumberOfRequiredPOIs(); - if (required <= 0) - { - return result; - } - - // - int count = ArraySize(mBearishMomentumBars); - if (count >= required) - { - // - result = count; - return result; - } - - // - string symbol = GetSymbol(); - ENUM_TIMEFRAMES period = GetPeriod(); - - // - XOHCL bar; - bool isInited = bar.Init( - symbol, - period, - barIndex // - ); - if (!isInited) - { - return result; - } - - // - DetectBearishMomentumBar(bar); - - // - result = ArraySize(mBearishMomentumBars); - - // - return result; - } - - // - // Rejection Bars ... - int mRejectionBarExtendRange; // Rejection Bars must Extends Range ... - double mRejectionBarShadowPercent; // Rejection Bars Shadow Percent ... - - // - // Bullish ... - XCRejectionBar *mBullishRejectionBars[]; // Holds Founded Bullish Rejection Bars ... - - /** - * Detect Required Bullish Rejection Bars ... - * - * @param barIndex: Integer Start bar index ... - * 0 is Default ... - * - * @return ( int ) - */ - int DetectRequiredBullishRejectionBars(int barIndex = 0) - { - // - int result = 0; - - // - if (barIndex < 0) - { - barIndex = 0; - } - - // - int required = MaxNumberOfRequiredPOIs(); - if (required <= 0) - { - return result; - } - - // - int count = ArraySize(mBullishRejectionBars); - if (count >= required) - { - // - result = count; - return result; - } - - // - string symbol = GetSymbol(); - ENUM_TIMEFRAMES period = GetPeriod(); - - // - XOHCL bar; - bool isInited = bar.Init( - symbol, - period, - barIndex // - ); - if (!isInited) - { - return result; - } - - // - DetectBullishRejectionBar(bar); - - // - result = ArraySize(mBullishRejectionBars); - - // - return result; - } - - // - // Bearish ... - XCRejectionBar *mBearishRejectionBars[]; // Holds Founded Bearish Rejection Bars ... - - /** - * Detect Required Bearish Rejection Bars ... - * - * @param barIndex: Integer Start bar index ... - * 0 is Default ... - * - * @return ( int ) - */ - int DetectRequiredBearishRejectionBars(int barIndex = 0) - { - // - int result = 0; - - // - if (barIndex < 0) - { - barIndex = 0; - } - - // - int required = MaxNumberOfRequiredPOIs(); - if (required <= 0) - { - return result; - } - - // - int count = ArraySize(mBearishRejectionBars); - if (count >= required) - { - // - result = count; - return result; - } - - // - string symbol = GetSymbol(); - ENUM_TIMEFRAMES period = GetPeriod(); - - // - XOHCL bar; - bool isInited = bar.Init( - symbol, - period, - barIndex // - ); - if (!isInited) - { - return result; - } - - // - DetectBearishRejectionBar(bar); - - // - result = ArraySize(mBearishRejectionBars); - - // - return result; - } - - // - // Support and Resistance Zone ... - int mSupportAndResistanceRange; // Support and Resistance Range for Verification ... - - // - // Support Zone(s) ... - XCSupportZone *mSupportZones[]; // Holds Founded Support Zones ... - - /** - * Detect Required Support Zones ... - * - * @param barIndex: Integer Start bar index ... - * 0 is Default ... - * - * @return ( int ) - */ - int DetectRequiredSupportZones(int barIndex = 0) - { - // - int result = 0; - - // - if (barIndex < 0) - { - barIndex = 0; - } - - // - int required = MaxNumberOfRequiredPOIs(); - if (required <= 0) - { - return result; - } - - // - int count = ArraySize(mSupportZones); - if (count >= required) - { - // - result = count; - return result; - } - - // - int range = SupportAndResistanceRange(); - if (range < 0 || barIndex < range) - { - return result; - } - - // - string symbol = GetSymbol(); - ENUM_TIMEFRAMES period = GetPeriod(); - - // - XOHCL bar; - bool isInited = bar.Init( - symbol, - period, - barIndex // - ); - if (!isInited) - { - return result; - } - - // - DetectSupportZone(bar); - - // - result = ArraySize(mSupportZones); - - // - return result; - } - - // - // Resistance Zone(s) ... - XCResistanceZone *mResistanceZones[]; // Holds Founded Resistance Zones ... - - /** - * Detect Required Resistance Zones ... - * - * @param barIndex: Integer Start bar index ... - * 0 is Default ... - * - * @return ( int ) - */ - int DetectRequiredResistanceZones(int barIndex = 0) - { - // - int result = 0; - - // - if (barIndex < 0) - { - barIndex = 0; - } - - // - int required = MaxNumberOfRequiredPOIs(); - if (required <= 0) - { - return result; - } - - // - int count = ArraySize(mResistanceZones); - if (count >= required) - { - // - result = count; - return result; - } - - // - int range = SupportAndResistanceRange(); - if (range < 0 || barIndex < range) - { - return result; - } - - // - string symbol = GetSymbol(); - ENUM_TIMEFRAMES period = GetPeriod(); - - // - XOHCL bar; - bool isInited = bar.Init( - symbol, - period, - barIndex // - ); - if (!isInited) - { - return result; - } - - // - DetectResistanceZone(bar); - - // - result = ArraySize(mResistanceZones); - - // - return result; - } - - // - // Supply and Demand Zones ... - int mSupplyAndDemandRange; // Supply and Demand Range Verifications ... - - // - // Supply Zone(s) ... - XCSupplyZone *mSupplyZones[]; // Holds Founded Supply Zones ... - - /** - * Detect Required Supply Zones ... - * - * @param barIndex: Integer Start bar index ... - * 0 is Default ... - * - * @return ( int ) - */ - int DetectRequiredSupplyZones(int barIndex) - { - // - int result = 0; - - // - if (barIndex < 0) - { - barIndex = 0; - } - - // - int required = MaxNumberOfRequiredPOIs(); - if (required <= 0) - { - return result; - } - - // - int count = ArraySize(mSupplyZones); - if (count >= required) - { - // - result = count; - return result; - } - - // - int range = SupplyAndDemandRange(); - if (range < 0) - { - return result; - } - - // - string symbol = GetSymbol(); - ENUM_TIMEFRAMES period = GetPeriod(); - - // - XOHCL bar; - bool isInited = bar.Init( - symbol, - period, - barIndex // - ); - if (!isInited) - { - return result; - } - - // - DetectSupplyZone(bar); - - // - result = ArraySize(mSupplyZones); - - // - return result; - } - - // - // Demand Zone(s) ... - XCDemandZone *mDemandZones[]; // Holds Founded Demand Zones ... - - /** - * Detect Required Demand Zones ... - * - * @param barIndex: Integer Start bar index ... - * 0 is Default ... - * - * @return ( int ) - */ - int DetectRequiredDemandZones(int barIndex) - { - // - int result = 0; - - // - if (barIndex < 0) - { - barIndex = 0; - } - - // - int required = MaxNumberOfRequiredPOIs(); - if (required <= 0) - { - return result; - } - - // - int count = ArraySize(mDemandZones); - if (count >= required) - { - // - result = count; - return result; - } - - // - int range = SupplyAndDemandRange(); - if (range < 0) - { - return result; - } - - // - string symbol = GetSymbol(); - ENUM_TIMEFRAMES period = GetPeriod(); - - // - XOHCL bar; - bool isInited = bar.Init( - symbol, - period, - barIndex // - ); - if (!isInited) - { - return result; - } - - // - DetectDemandZone(bar); - - // - result = ArraySize(mDemandZones); - - // - return result; - } - - // - // Order Blocks ... - int mOrderBlocksSameBars; // Order Blocks Detection Bars ... - - // - // Bullish OB ... - XCOrderBlock *mBullishOrderBlocks[]; // Holds Founded Bullish Order Blocks ... - - /** - * Detect Required Bullish Order Blocks ... - * - * @param barIndex: Integer Start bar index ... - * 0 is Default ... - * - * @return ( int ) - */ - int DetectRequiredBullishOrderBlocks(int barIndex) - { - // - int result = 0; - - // - if (barIndex < 0) - { - barIndex = 0; - } - - // - int required = MaxNumberOfRequiredPOIs(); - if (required <= 0) - { - return result; - } - - // - int count = ArraySize(mBullishOrderBlocks); - if (count >= required) - { - // - result = count; - return result; - } - - // - int sameBars = OrderBlocksSameBars(); - if (sameBars < 0) - { - return result; - } - - // - string symbol = GetSymbol(); - ENUM_TIMEFRAMES period = GetPeriod(); - - // - XOHCL bar; - bool isInited = bar.Init( - symbol, - period, - barIndex // - ); - if (!isInited) - { - return result; - } - - // - DetectBullishOrderBlock(bar); - - // - result = ArraySize(mBullishOrderBlocks); - - // - return result; - } - - // - // Bearish OB ... - XCOrderBlock *mBearishOrderBlocks[]; // Holds Founded Bearish Order Blocks ... - - /** - * Detect Required Bearish Order Blocks ... - * - * @param barIndex: Integer Start bar index ... - * 0 is Default ... - * - * @return ( int ) - */ - int DetectRequiredBearishOrderBlocks(int barIndex) - { - // - int result = 0; - - // - if (barIndex < 0) - { - barIndex = 0; - } - - // - int required = MaxNumberOfRequiredPOIs(); - if (required <= 0) - { - return result; - } - - // - int count = ArraySize(mBearishOrderBlocks); - if (count >= required) - { - // - result = count; - return result; - } - - // - int sameBars = OrderBlocksSameBars(); - if (sameBars < 0) - { - return result; - } - - // - string symbol = GetSymbol(); - ENUM_TIMEFRAMES period = GetPeriod(); - - // - XOHCL bar; - bool isInited = bar.Init( - symbol, - period, - barIndex // - ); - if (!isInited) - { - return result; - } - - // - DetectBearishOrderBlock(bar); - - // - result = ArraySize(mBearishOrderBlocks); - - // - return result; - } - - // - // Fair Value Gaps ... - int mFairValueGapsSameBars; // Fair Value Gaps Detection Same Bars ... - - // - // Bullish FVG ... - XCFVG *mBullishFairValueGaps[]; // Holds Founded Bullish Fair Value Gaps ... - - /** - * Detect Required Bullish Fair Value Gaps ... - * - * @param barIndex: Integer Start bar index ... - * 0 is Default ... - * - * @return ( int ) - */ - int DetectRequiredBullishFairValueGaps(int barIndex) - { - // - int result = 0; - - // - if (barIndex < 0) - { - barIndex = 0; - } - - // - int required = MaxNumberOfRequiredPOIs(); - if (required <= 0) - { - return result; - } - - // - int count = ArraySize(mBullishFairValueGaps); - if (count >= required) - { - // - result = count; - return result; - } - - // - int sameBars = FairValueGapsSameBars(); - if (sameBars < 0) - { - return result; - } - - // - string symbol = GetSymbol(); - ENUM_TIMEFRAMES period = GetPeriod(); - - // - XOHCL bar; - bool isInited = bar.Init( - symbol, - period, - barIndex // - ); - if (!isInited) - { - return result; - } - - // - DetectBullishFairValueGap(bar); - - // - result = ArraySize(mBullishFairValueGaps); - - // - return result; - } - - // - // Bearish FVG ... - XCFVG *mBearishFairValueGaps[]; // Holds Founded Bearish Fair Value Gaps ... - - /** - * Detect Required Bearish Fair Value Gaps ... - * - * @param barIndex: Integer Start bar index ... - * 0 is Default ... - * - * @return ( int ) - */ - int DetectRequiredBearishFairValueGaps(int barIndex) - { - // - int result = 0; - - // - if (barIndex < 0) - { - barIndex = 0; - } - - // - int required = MaxNumberOfRequiredPOIs(); - if (required <= 0) - { - return result; - } - - // - int count = ArraySize(mBearishFairValueGaps); - if (count >= required) - { - // - result = count; - return result; - } - - // - int sameBars = FairValueGapsSameBars(); - if (sameBars < 0) - { - return result; - } - - // - string symbol = GetSymbol(); - ENUM_TIMEFRAMES period = GetPeriod(); - - // - XOHCL bar; - bool isInited = bar.Init( - symbol, - period, - barIndex // - ); - if (!isInited) - { - return result; - } - - // - DetectBearishFairValueGap(bar); - - // - result = ArraySize(mBearishFairValueGaps); - - // - return result; - } - - // - // Ticks Range Zones ... - int mTicksRangeZoneLevel; // Ticks Range Levels ... - int mTicksRangeZoneRange; // Ticks Range Zone Loopback Period ... - - // - XCTicksZone *mTicksZone; // Ticks Zone ... - // XCTicksZoneObject *mTicksZoneObject; // Ticks Zone Object ... - - /** - * Detect Ticks Zone Range ... - * - * @param bar: XOHCL instance ... - * - * @return ( bool ) - */ - bool DetectTicksZoneRange(XOHCL &bar) - { - // - bool result = false; - - // - result = bar.IsValid(); - if (!result) - { - return result; - } - - // - int ticksLevels = TicksRangeZoneLevel(); - int ticksRange = TicksRangeZoneRange(); - result = ticksLevels > 0 && - ticksRange > 0; - if (!result) - { - return result; - } - - // - int startBarIndex = bar.Index() + ticksRange; - XOHCL startBar; - result = startBar.Init( - bar.symbol, - bar.period, - startBarIndex // - ); - if (!result) - { - return result; - } - - // - mTicksZone = new XCTicksZone(); - result = mTicksZone.Init( - startBar, - bar // - ); - if (!result) - { - // - mTicksZone = NULL; - return result; - } - - // - return result; - } - - // - // Liquidity Zones ... - - // - // Sell Side ... - - // - // Buy Side ... - - // -}; - -// \ No newline at end of file diff --git a/Documents/BKP/x-saherelm.x121.xwz.mq5 b/Documents/BKP/x-saherelm.x121.xwz.mq5 deleted file mode 100644 index 8828b358..00000000 --- a/Documents/BKP/x-saherelm.x121.xwz.mq5 +++ /dev/null @@ -1,3438 +0,0 @@ -/////////////////////////////////////////////////////// -// -// SaherElm IT Center MQL5 Indicator -// ------------------------------------------------- -// Name: X121 XWZ -// Description: XWZ ... -// -// -// Maintainer: -// ------------ -// Hadi Khazaee Asl (hadi_khazaee_asl@yahoo.com) -// -////////////////////////////////////////////////////// -// -// Global Properties ... -#property copyright "Copyright 2023, SaherElm IT Center" -#property link "https://saherelm.ir" -#property version "1.00" -#property description "SaherElm X121 XWZ Indicator" -#property strict - -// -// Definitions ... - -// -#define ShortName "X121_XWZ" - -// -// Includes Common Library ... -#include "../Classes/x-saherelm.x-alert.class.mq5" -#include "../Classes/x-saherelm.x-bar.analyser.class.mq5" -#include "../Classes/x-saherelm.x-poi.drawer.class.mq5" -#include "../Libraries/x-saherelm.common.lib.mq5" -#include "../Libraries/x-saherelm.x-poi.extensions.lib.mq5" - -// -// Inputs ... - -// -// Market ... -input group "Market"; - -// -input group "Calculation"; -input ENUM_APPLIED_PRICE appliedTo = PRICE_CLOSE; // Detect Price Type - -// -input group "MA Detection"; -input int maLength = 20; // MA Length -input ENUM_MA_METHOD maMethod = MODE_EMA; // MA Method - -// -input group "ATR StopLoss"; -input int atrLength = 14; // ATR Length -input double atrMultiplier = 2; // ATR Multiplier - -// -input group "ADX Detection"; -input int adxLength = 14; // ADX Length -input double adxThreshold = 25; // ADX Threshold for Strong Trends - -// -input group "Alert"; -input bool mXWZEnableAlerts = true; // Enable Alerts -input bool mXWZPushAlerts = false; // Push Alerts -input bool mXWZMailAlerts = false; // Mail Alerts -input bool mXWZTerminalAlerts = false; // Terminal Alerts - -// -// Presentation ... -input group "Presentation"; - -// -input group "Buffer Presentation"; -input bool showMA = true; // Show Moving Average -input bool showPin = true; // Show Pin Bars -input bool showSwing = true; // Show Swing Bars -input bool showTrend = true; // Show Trend -input bool showEngulf = true; // Show Engulf Bars -input bool showLongSL = true; // Show Long SL -input bool showShortSL = true; // Show Short SL -input bool showMomentum = true; // Show Momentum Bars -input bool showRejection = true; // Show Rejection Bars - -// -input group "POI Presentation"; -input bool showPOIs = false; // Show POI(s) -input bool showActivatedPOIs = true; // Show Activated POI(s) -input bool showOrderBlocks = true; // Show Order Blocks -input bool showFairValueGaps = true; // Show Fair Value Gaps -input bool showSupportZones = false; // Show Support Zones -input bool showResistanceZones = false; // Show Resistance Zones - -// -input group "Presentation Config"; -input int startCalculationForLastBars = 1000; // Calculate Last n Bars -input int upTrendArrowCode = 236; // Up Trend Arrow Code -input int downTrendArrowCode = 238; // Down Trend Arrow Code -input int swingLowArrowCode = 108; // Swing Low Arrow Code -input int swingHighArrowCode = 108; // Swing High Arrow Code -input int bullishPinArrowCode = 246; // Bullish Pin Arrow Code -input int bearishPinArrowCode = 248; // Bearish Pin Arrow Code -input int bullishEngulfArrowCode = 200; // Bullish Engulf Arrow Code -input int bearishEngulfArrowCode = 202; // Bearish Engulf Arrow Code -input int bullishMomentumArrowCode = 233; // Bullish Momentum Arrow Code -input int bearishMomentumArrowCode = 234; // Bearish Momentum Arrow Code -input int bullishRejectionArrowCode = 241; // Bullish Rejection Arrow Code -input int bearishRejectionArrowCode = 242; // Bearish Rejection Arrow Code - -// -#property indicator_chart_window - -// -#property indicator_buffers 17 -#property indicator_plots 15 - -// -// Plot Buffers ... - -// -#define maBufferIndex 0 -double maBuffer[]; - -// -#property indicator_label1 "X121-XWZ MA" -#property indicator_type1 DRAW_LINE -#property indicator_color1 clrLightSkyBlue -#property indicator_style1 STYLE_SOLID -#property indicator_width1 2 - -// -#define longSLBufferIndex 1 -double longSLBuffer[]; - -// -#property indicator_label2 "X121-XWZ Long SL" -#property indicator_type2 DRAW_LINE -#property indicator_color2 clrOrange -#property indicator_style2 STYLE_SOLID -#property indicator_width2 1 - -// -#define shortSLBufferIndex 2 -double shortSLBuffer[]; - -// -#property indicator_label3 "X121-XWZ Short SL" -#property indicator_type3 DRAW_LINE -#property indicator_color3 clrOrange -#property indicator_style3 STYLE_SOLID -#property indicator_width3 1 - -// -#define upTrendBufferIndex 3 -double upTrendBuffer[]; - -// -#property indicator_label4 "X121-XWZ Trend Up" -#property indicator_type4 DRAW_ARROW -#property indicator_color4 clrAqua -#property indicator_width4 3 - -// -#define downTrendBufferIndex 4 -double downTrendBuffer[]; - -// -#property indicator_label5 "X121-XWZ Trend Down" -#property indicator_type5 DRAW_ARROW -#property indicator_color5 clrMagenta -#property indicator_width5 3 - -// -#define bullishMomentumBufferIndex 5 -double bullishMomentumBuffer[]; - -// -#property indicator_label6 "X121-XWZ Bull Momentum" -#property indicator_type6 DRAW_ARROW -#property indicator_color6 clrAqua -#property indicator_width6 3 - -// -#define bearishMomentumBufferIndex 6 -double bearishMomentumBuffer[]; - -// -#property indicator_label7 "X121-XWZ Bear Momentum" -#property indicator_type7 DRAW_ARROW -#property indicator_color7 clrMagenta -#property indicator_width7 3 - -// -#define bullishRejectionBufferIndex 7 -double bullishRejectionBuffer[]; - -// -#property indicator_label8 "X121-XWZ Bull Rejection" -#property indicator_type8 DRAW_ARROW -#property indicator_color8 clrAqua -#property indicator_width8 3 - -// -#define bearishRejectionBufferIndex 8 -double bearishRejectionBuffer[]; - -// -#property indicator_label9 "X121-XWZ Bear Rejection" -#property indicator_type9 DRAW_ARROW -#property indicator_color9 clrMagenta -#property indicator_width9 3 - -// -#define bullishPinBufferIndex 9 -double bullishPinBuffer[]; - -// -#property indicator_label10 "X121-XWZ Bull Pin" -#property indicator_type10 DRAW_ARROW -#property indicator_color10 clrAqua -#property indicator_width10 3 - -// -#define bearishPinBufferIndex 10 -double bearishPinBuffer[]; - -// -#property indicator_label11 "X121-XWZ Bear Pin" -#property indicator_type11 DRAW_ARROW -#property indicator_color11 clrMagenta -#property indicator_width11 3 - -// -#define bullishEngulfBufferIndex 11 -double bullishEngulfBuffer[]; - -// -#property indicator_label12 "X121-XWZ Bull Engulf" -#property indicator_type12 DRAW_ARROW -#property indicator_color12 clrAqua -#property indicator_width12 3 - -// -#define bearishEngulfBufferIndex 12 -double bearishEngulfBuffer[]; - -// -#property indicator_label13 "X121-XWZ Bear Engulf" -#property indicator_type13 DRAW_ARROW -#property indicator_color13 clrMagenta -#property indicator_width13 3 - -// -#define swingLowBufferIndex 13 -double swingLowBuffer[]; - -// -#property indicator_label14 "X121-XWZ Swing Low" -#property indicator_type14 DRAW_ARROW -#property indicator_color14 clrAqua -#property indicator_width14 3 - -// -#define swingHighBufferIndex 14 -double swingHighBuffer[]; - -// -#property indicator_label15 "X121-XWZ Swing High" -#property indicator_type15 DRAW_ARROW -#property indicator_color15 clrMagenta -#property indicator_width15 3 - -// -// Data Buffers ... - -// -int mLastBufferIndex = 14; - -// -#define atrBufferIndex mLastBufferIndex + 1 -double atrBuffer[]; - -// -#define adxBufferIndex mLastBufferIndex + 2 -double adxBuffer[]; - -// -// Variables, Properties and etc ... - -// -// this counts Available Bars ... -int limit; - -// -int maxLength; - -// -// MA Handler ... -int maHandler = INVALID_HANDLE; - -// -// ATR Handler ... -int atrHandler = INVALID_HANDLE; - -// -// ADX Handler ... -int adxHandler = INVALID_HANDLE; - -// -XCAlert *mXWZAlert; -CArrayObj mXWZDrawnObjects; -XCPOIDrawer *mXWZPOIDrawer; -XCBarAnalyser *mXWZBarAnalyser; - -// -datetime lastBullishTrend = NULL; -datetime lastBearishTrend = NULL; - -// -datetime lastCrossedOverMA = NULL; -datetime lastCrossedUnderMA = NULL; - -// -// POI(s) ... - -// -bool mXWZDetectOrderBlocks = true; -bool mXWZDetectFairValueGaps = false; -bool mXWZDetectSupportZones = false; -bool mXWZDetectResistanceZones = false; - -// -bool filterPOIsUsingMa = false; // Filter POI(s) Using MA -bool filterPOIsUsingZones = false; // Filter POI(s) Using Zones - -// -XCFVG *lastBullFVG; -XCFVG *lastBearFVG; -XCOrderBlock *lastBullOB; -XCOrderBlock *lastBearOB; -XCSupportZone *lastSupport; -XCResistanceZone *lastResistance; - -// -// Un Activated POI(s) ... -XCFVG *mXWZUnActivatedFVGs[]; -XCOrderBlock *mXWZUnActivatedOBs[]; -XCSupportZone *mXWZUnActivatedSupportZones[]; -XCResistanceZone *mXWZUnActivatedResistanceZones[]; - -// -// Activated POI(s) ... -XCFVG *mXWZActivatedFVGs[]; -XCOrderBlock *mXWZActivatedOBs[]; -XCSupportZone *mXWZActivatedSupportZones[]; -XCResistanceZone *mXWZActivatedResistanceZones[]; - -// -// Event Handlers ... - -/** - * Initialize Indicator ... - * - * @return ( int ) - */ -int OnInit() -{ - // - mXWZDrawnObjects.Clear(); - - // - // Validate Inputs ... - if (!ValidateInputs()) - { - return INIT_PARAMETERS_INCORRECT; - } - - // - // Initialize Indicator Handlers ... - - // - // MA ... - maHandler = iMA( - _Symbol, - _Period, - maLength, - 0, - maMethod, - appliedTo // - ); - bool isInited = maHandler != INVALID_HANDLE; - if (!isInited) - { - return INIT_FAILED; - } - - // - // ATR ... - atrHandler = iATR( - _Symbol, - _Period, - atrLength // - ); - isInited = maHandler != INVALID_HANDLE; - if (!isInited) - { - return INIT_FAILED; - } - - // - // ADX ... - adxHandler = iADX( - _Symbol, - _Period, - adxLength // - ); - isInited = maHandler != INVALID_HANDLE; - if (!isInited) - { - return INIT_FAILED; - } - - // - // because in some cases we may have more than one input for - // calculation and we must prevent any calculation - // untill we pass the biggest input length, here we get max Input length - // and then wait until pass it ... - maxLength = ExtractMaxLengthOfInputs(); - - // - // Define Index Buffers ... - DefineBuffers(); - - // - // Set Indicator ShortName ... - SetIndicatorName(); - IndicatorSetInteger(INDICATOR_DIGITS, 2); - - // - mXWZPOIDrawer = new XCPOIDrawer(); - ConfigurePOIDrawer(); - - // - mXWZAlert = new XCAlert(); - ConfigureAlert(); - - // - mXWZBarAnalyser = new XCBarAnalyser(); - - // - // Init Succeed ... - return INIT_SUCCEEDED; -} - -/** - * De Initialize Indicator ... - * - * @param reason: Integer, De Initialization Reason ... - */ -void OnDeinit(const int reason) -{ - // - // REASON_PROGRAM 0 The EA has stopped working calling the ExpertRemove() function - // REASON_REMOVE 1 Program removed from a chart - // REASON_RECOMPILE 2 Program recompiled - // REASON_CHARTCHANGE 3 A symbol or a chart period is changed - // REASON_CHARTCLOSE 4 Chart closed - // REASON_PARAMETERS 5 Inputs changed by a user - // REASON_ACCOUNT 6 Another account has been activated or reconnection to the trade server has occurred due to changes in the account settings - // REASON_TEMPLATE 7 Another chart template applied - // REASON_INITFAILED 8 The OnInit() handler returned a non-zero value - // REASON_CLOSE 9 Terminal closed - - // - IndicatorRelease(maHandler); - IndicatorRelease(atrHandler); - IndicatorRelease(adxHandler); - - // - mXWZDrawnObjects.Clear(); - - // - ZeroMemory(mXWZAlert); - ZeroMemory(mXWZPOIDrawer); - ZeroMemory(mXWZBarAnalyser); - - // - Clean(mXWZActivatedOBs); - Clean(mXWZActivatedFVGs); - Clean(mXWZActivatedSupportZones); - Clean(mXWZActivatedResistanceZones); - - // - Clean(mXWZUnActivatedOBs); - Clean(mXWZUnActivatedFVGs); - Clean(mXWZUnActivatedSupportZones); - Clean(mXWZUnActivatedResistanceZones); -} - -/** - * Calculate Bars ... - * - * @param rates_total: Integer, Total Bars on Chart ... - * @param prev_calculated: Integer, Total Calculated Bars on Charts ... - * @param time: DateTime Array, History of Open Time ... - * @param open: Double Array, History of Open Prices ... - * @param high: Double Array, History of High Prices ... - * @param low: Double Array, History of Low Prices ... - * @param close: Double Array, History of Close Prices ... - * @param tick_volume: Long, History of Tick Volumes on Bar ... - * @param volume: Long, History of Trade Volumes ... - * @param spread: Double, History of Spread Price ... - * - * @return ( int ) - */ -int OnCalculate( - const int rates_total, - const int prev_calculated, - const datetime &time[], - const double &open[], - const double &high[], - const double &low[], - const double &close[], - const long &tick_volume[], - const long &volume[], - const int &spread[] // -) -{ - // - // Prepare Buffers ... - ArraySetAsSeries(time, true); - ArraySetAsSeries(open, true); - ArraySetAsSeries(high, true); - ArraySetAsSeries(low, true); - ArraySetAsSeries(close, true); - ArraySetAsSeries(tick_volume, true); - ArraySetAsSeries(volume, true); - ArraySetAsSeries(spread, true); - - // - // Validate Calculated Bars ... - - // - // MA ... - int maCalculatedBars = BarsCalculated(maHandler); - - // - // ATR ... - int atrCalculatedBars = BarsCalculated(atrHandler); - - // - // ADX ... - int adxCalculatedBars = BarsCalculated(adxHandler); - - // - bool isPassedRequiredCalculatedBars = - // - // MA ... - maCalculatedBars >= maxLength && - // - // ATR ... - atrCalculatedBars >= maxLength && - // - // ADX ... - adxCalculatedBars >= maxLength - // - ; - if (!isPassedRequiredCalculatedBars) - { - return prev_calculated; - } - - // - limit = (prev_calculated > rates_total || prev_calculated <= 0) - ? rates_total - : (rates_total - prev_calculated) + 1; - - // - // Buffers Copy ... - - // - // MA ... - int copiedMas = CopyBuffer(maHandler, 0, 0, limit, maBuffer); - - // - // ATR ... - int copiedAtr = CopyBuffer(atrHandler, MAIN_LINE, 0, limit, atrBuffer); - - // - // ADX ... - int copiedAdxs = CopyBuffer(adxHandler, MAIN_LINE, 0, limit, adxBuffer); - - // - // Validate Copied Items ... - bool isPassedRequiredCopiedItems = - // - // MA ... - copiedMas > 0 && - // - // ATR ... - copiedAtr > 0 && - // - // ADX ... - copiedAdxs > 0 - // - ; - if (!isPassedRequiredCopiedItems) - { - return prev_calculated; - } - - // - // Main Loop ... - for (int i = limit - 1; i >= 0 && !IsStopped(); i--) - { - // - CalculateBuffers( - // - i, - prev_calculated, - rates_total, - // - open, - high, - close, - low, - tick_volume // - ); - } - - // - return rates_total; -} - -// -// Functions ... - -/** - * Validate Input Args for Initialization ... - * - * @return ( bool ) - */ -bool ValidateInputs() -{ - // - bool result = false; - - // - result = - // - // MA ... - maLength > 0 && - // - // ATR ... - atrLength > 0 && - atrMultiplier > 0 && - // - // ADX ... - adxLength > 0 && - adxThreshold > 0 - // - ; - - // - return result; -} - -/** - * Extract Max Length of Inputs ... - * - * @return ( int ) - */ -int ExtractMaxLengthOfInputs() -{ - // - int result = 0; - - // - result = MathMax(maLength, atrLength); - result = MathMax(result, adxLength); - - // - return result; -} - -/** - * Set Indicator Short Name and also we can define Buffers Labels ... - */ -void SetIndicatorName() -{ - IndicatorSetString(INDICATOR_SHORTNAME, ShortName); -} - -/** - * Define Required Buffers ... - */ -void DefineBuffers() -{ - // - // Plot Buffers ... - - // - // MA Buffer ... - - // - ENUM_DRAW_TYPE maDrawType = showMA ? DRAW_LINE : DRAW_NONE; - - // - ArraySetAsSeries(maBuffer, true); - SetIndexBuffer(maBufferIndex, maBuffer, INDICATOR_DATA); - - // - PlotIndexSetInteger(maBufferIndex, PLOT_SHOW_DATA, showMA); - PlotIndexSetInteger(maBufferIndex, PLOT_DRAW_TYPE, maDrawType); - - // - PlotIndexSetDouble(maBufferIndex, PLOT_EMPTY_VALUE, 0); - - // - // LONG SL Buffer ... - - // - ENUM_DRAW_TYPE longSLDrawType = showLongSL ? DRAW_LINE : DRAW_NONE; - - // - ArraySetAsSeries(longSLBuffer, true); - SetIndexBuffer(longSLBufferIndex, longSLBuffer, INDICATOR_DATA); - - // - PlotIndexSetInteger(longSLBufferIndex, PLOT_SHOW_DATA, showLongSL); - PlotIndexSetInteger(longSLBufferIndex, PLOT_DRAW_TYPE, longSLDrawType); - - // - PlotIndexSetDouble(longSLBufferIndex, PLOT_EMPTY_VALUE, 0); - - // - // SHORT SL Buffer ... - - // - ENUM_DRAW_TYPE shortSLDrawType = showShortSL ? DRAW_LINE : DRAW_NONE; - - // - ArraySetAsSeries(shortSLBuffer, true); - SetIndexBuffer(shortSLBufferIndex, shortSLBuffer, INDICATOR_DATA); - - // - PlotIndexSetInteger(shortSLBufferIndex, PLOT_SHOW_DATA, showShortSL); - PlotIndexSetInteger(shortSLBufferIndex, PLOT_DRAW_TYPE, shortSLDrawType); - - // - PlotIndexSetDouble(shortSLBufferIndex, PLOT_EMPTY_VALUE, 0); - - // - // UP Trend ... - - // - ENUM_DRAW_TYPE upTrendDrawType = showTrend ? DRAW_ARROW : DRAW_NONE; - - // - ArraySetAsSeries(upTrendBuffer, true); - SetIndexBuffer(upTrendBufferIndex, upTrendBuffer, INDICATOR_DATA); - - // - PlotIndexSetInteger(upTrendBufferIndex, PLOT_SHOW_DATA, showTrend); - PlotIndexSetInteger(upTrendBufferIndex, PLOT_DRAW_TYPE, upTrendDrawType); - - // - PlotIndexSetDouble(upTrendBufferIndex, PLOT_EMPTY_VALUE, 0); - PlotIndexSetInteger(upTrendBufferIndex, PLOT_ARROW, upTrendArrowCode); - - // - // DOWN Trend ... - - // - ENUM_DRAW_TYPE downTrendDrawType = showTrend ? DRAW_ARROW : DRAW_NONE; - - // - ArraySetAsSeries(downTrendBuffer, true); - SetIndexBuffer(downTrendBufferIndex, downTrendBuffer, INDICATOR_DATA); - - // - PlotIndexSetInteger(downTrendBufferIndex, PLOT_SHOW_DATA, showTrend); - PlotIndexSetInteger(downTrendBufferIndex, PLOT_DRAW_TYPE, downTrendDrawType); - - // - PlotIndexSetDouble(downTrendBufferIndex, PLOT_EMPTY_VALUE, 0); - PlotIndexSetInteger(downTrendBufferIndex, PLOT_ARROW, downTrendArrowCode); - - // - // Bullish Momentum ... - - // - ENUM_DRAW_TYPE bullishMomentumDrawType = showMomentum ? DRAW_ARROW : DRAW_NONE; - - // - ArraySetAsSeries(bullishMomentumBuffer, true); - SetIndexBuffer(bullishMomentumBufferIndex, bullishMomentumBuffer, INDICATOR_DATA); - - // - PlotIndexSetInteger(bullishMomentumBufferIndex, PLOT_SHOW_DATA, showMomentum); - PlotIndexSetInteger(bullishMomentumBufferIndex, PLOT_DRAW_TYPE, bullishMomentumDrawType); - - // - PlotIndexSetDouble(bullishMomentumBufferIndex, PLOT_EMPTY_VALUE, 0); - PlotIndexSetInteger(bullishMomentumBufferIndex, PLOT_ARROW, bullishMomentumArrowCode); - - // - // Bearish Momentum ... - - // - ENUM_DRAW_TYPE bearishMomentumDrawType = showMomentum ? DRAW_ARROW : DRAW_NONE; - - // - ArraySetAsSeries(bearishMomentumBuffer, true); - SetIndexBuffer(bearishMomentumBufferIndex, bearishMomentumBuffer, INDICATOR_DATA); - - // - PlotIndexSetInteger(bearishMomentumBufferIndex, PLOT_SHOW_DATA, showMomentum); - PlotIndexSetInteger(bearishMomentumBufferIndex, PLOT_DRAW_TYPE, bearishMomentumDrawType); - - // - PlotIndexSetDouble(bearishMomentumBufferIndex, PLOT_EMPTY_VALUE, 0); - PlotIndexSetInteger(bearishMomentumBufferIndex, PLOT_ARROW, bearishMomentumArrowCode); - - // - // Bullish Rejection ... - - // - ENUM_DRAW_TYPE bullishRejectionDrawType = showRejection ? DRAW_ARROW : DRAW_NONE; - - // - ArraySetAsSeries(bullishRejectionBuffer, true); - SetIndexBuffer(bullishRejectionBufferIndex, bullishRejectionBuffer, INDICATOR_DATA); - - // - PlotIndexSetInteger(bullishRejectionBufferIndex, PLOT_SHOW_DATA, showRejection); - PlotIndexSetInteger(bullishRejectionBufferIndex, PLOT_DRAW_TYPE, bullishRejectionDrawType); - - // - PlotIndexSetDouble(bullishRejectionBufferIndex, PLOT_EMPTY_VALUE, 0); - PlotIndexSetInteger(bullishRejectionBufferIndex, PLOT_ARROW, bullishRejectionArrowCode); - - // - // Bearish Rejection ... - - // - ENUM_DRAW_TYPE bearishRejectionDrawType = showRejection ? DRAW_ARROW : DRAW_NONE; - - // - ArraySetAsSeries(bearishRejectionBuffer, true); - SetIndexBuffer(bearishRejectionBufferIndex, bearishRejectionBuffer, INDICATOR_DATA); - - // - PlotIndexSetInteger(bearishRejectionBufferIndex, PLOT_SHOW_DATA, showRejection); - PlotIndexSetInteger(bearishRejectionBufferIndex, PLOT_DRAW_TYPE, bearishRejectionDrawType); - - // - PlotIndexSetDouble(bearishRejectionBufferIndex, PLOT_EMPTY_VALUE, 0); - PlotIndexSetInteger(bearishRejectionBufferIndex, PLOT_ARROW, bearishRejectionArrowCode); - - // - // Bullish Pin ... - - // - ENUM_DRAW_TYPE bullishPinDrawType = showPin ? DRAW_ARROW : DRAW_NONE; - - // - ArraySetAsSeries(bullishPinBuffer, true); - SetIndexBuffer(bullishPinBufferIndex, bullishPinBuffer, INDICATOR_DATA); - - // - PlotIndexSetInteger(bullishPinBufferIndex, PLOT_SHOW_DATA, showPin); - PlotIndexSetInteger(bullishPinBufferIndex, PLOT_DRAW_TYPE, bullishPinDrawType); - - // - PlotIndexSetDouble(bullishPinBufferIndex, PLOT_EMPTY_VALUE, 0); - PlotIndexSetInteger(bullishPinBufferIndex, PLOT_ARROW, bullishPinArrowCode); - - // - // Bearish Pin ... - - // - ENUM_DRAW_TYPE bearishPinDrawType = showPin ? DRAW_ARROW : DRAW_NONE; - - // - ArraySetAsSeries(bearishPinBuffer, true); - SetIndexBuffer(bearishPinBufferIndex, bearishPinBuffer, INDICATOR_DATA); - - // - PlotIndexSetInteger(bearishPinBufferIndex, PLOT_SHOW_DATA, showPin); - PlotIndexSetInteger(bearishPinBufferIndex, PLOT_DRAW_TYPE, bearishPinDrawType); - - // - PlotIndexSetDouble(bearishPinBufferIndex, PLOT_EMPTY_VALUE, 0); - PlotIndexSetInteger(bearishPinBufferIndex, PLOT_ARROW, bearishPinArrowCode); - - // - // Bullish Engulf ... - - // - ENUM_DRAW_TYPE bullishEngulfDrawType = showEngulf ? DRAW_ARROW : DRAW_NONE; - - // - ArraySetAsSeries(bullishEngulfBuffer, true); - SetIndexBuffer(bullishEngulfBufferIndex, bullishEngulfBuffer, INDICATOR_DATA); - - // - PlotIndexSetInteger(bullishEngulfBufferIndex, PLOT_SHOW_DATA, showEngulf); - PlotIndexSetInteger(bullishEngulfBufferIndex, PLOT_DRAW_TYPE, bullishEngulfDrawType); - - // - PlotIndexSetDouble(bullishEngulfBufferIndex, PLOT_EMPTY_VALUE, 0); - PlotIndexSetInteger(bullishEngulfBufferIndex, PLOT_ARROW, bullishEngulfArrowCode); - - // - // Bearish Engulf ... - - // - ENUM_DRAW_TYPE bearishEngulfDrawType = showEngulf ? DRAW_ARROW : DRAW_NONE; - - // - ArraySetAsSeries(bearishEngulfBuffer, true); - SetIndexBuffer(bearishEngulfBufferIndex, bearishEngulfBuffer, INDICATOR_DATA); - - // - PlotIndexSetInteger(bearishEngulfBufferIndex, PLOT_SHOW_DATA, showEngulf); - PlotIndexSetInteger(bearishEngulfBufferIndex, PLOT_DRAW_TYPE, bearishEngulfDrawType); - - // - PlotIndexSetDouble(bearishEngulfBufferIndex, PLOT_EMPTY_VALUE, 0); - PlotIndexSetInteger(bearishEngulfBufferIndex, PLOT_ARROW, bearishEngulfArrowCode); - - // - // Swing Low ... - - // - ENUM_DRAW_TYPE swingLowDrawType = showSwing ? DRAW_ARROW : DRAW_NONE; - - // - ArraySetAsSeries(swingLowBuffer, true); - SetIndexBuffer(swingLowBufferIndex, swingLowBuffer, INDICATOR_DATA); - - // - PlotIndexSetInteger(swingLowBufferIndex, PLOT_SHOW_DATA, showSwing); - PlotIndexSetInteger(swingLowBufferIndex, PLOT_DRAW_TYPE, swingLowDrawType); - - // - PlotIndexSetDouble(swingLowBufferIndex, PLOT_EMPTY_VALUE, 0); - PlotIndexSetInteger(swingLowBufferIndex, PLOT_ARROW, swingLowArrowCode); - - // - // Swing High ... - - // - ENUM_DRAW_TYPE swingHighDrawType = showSwing ? DRAW_ARROW : DRAW_NONE; - - // - ArraySetAsSeries(swingHighBuffer, true); - SetIndexBuffer(swingHighBufferIndex, swingHighBuffer, INDICATOR_DATA); - - // - PlotIndexSetInteger(swingHighBufferIndex, PLOT_SHOW_DATA, showSwing); - PlotIndexSetInteger(swingHighBufferIndex, PLOT_DRAW_TYPE, swingHighDrawType); - - // - PlotIndexSetDouble(swingHighBufferIndex, PLOT_EMPTY_VALUE, 0); - PlotIndexSetInteger(swingHighBufferIndex, PLOT_ARROW, swingHighArrowCode); - - // - // DATA Buffers ... - - // - ArraySetAsSeries(atrBuffer, true); - SetIndexBuffer(atrBufferIndex, atrBuffer, INDICATOR_CALCULATIONS); - - // - ArraySetAsSeries(adxBuffer, true); - SetIndexBuffer(adxBufferIndex, adxBuffer, INDICATOR_CALCULATIONS); -} - -/** - * Calculate Custom Buffers ... - * - * @param bar_index: Integer, Represent Current Bar ... - * @param prevCalculated: Integer, Represent Previous Calculated Bars ... - * @param ratesTotal: Integer, Represents All Available Bars ... - * @param open: Double Array, History of Open Prices ... - * @param high: Double Array, History of High Prices ... - * @param close: Double Array, History of Close Prices ... - * @param low: Double Array, History of Low Prices ... - * @param tickVolume: Long, History of Tick Volumes on Bar ... - */ -void CalculateBuffers( - int bar_index, // Selected Bar Index - const int prevCalculated, - const int ratesTotal, - const double &open[], - const double &high[], - const double &close[], - const double &low[], - const long &tickVolume[] // -) -{ - // - int barsLimit = startCalculationForLastBars > 0 - ? startCalculationForLastBars - : 0; - // - // bool canCalculate = true; - bool canCalculate = - barsLimit == 0 || - bar_index <= barsLimit; - if (canCalculate) - { - // - CalculatedPOIs( - // - bar_index, - prevCalculated, - ratesTotal, - // - open, - high, - close, - low, - tickVolume // - ); - - // - CalculateValues( - bar_index, - prevCalculated, - ratesTotal, - open, - high, - close, - low, - tickVolume // - ); - } - else - { - FillBuffersZero(bar_index); - } -} - -/** - * Fill All Bufers to Zero Vlue for Specified Bar Index ... - * - * @param barIndex: Integer ... - */ -void FillBuffersZero(int barIndex) -{ - // - maBuffer[barIndex] = 0; - atrBuffer[barIndex] = 0; - adxBuffer[barIndex] = 0; - longSLBuffer[barIndex] = 0; - shortSLBuffer[barIndex] = 0; - upTrendBuffer[barIndex] = 0; - swingLowBuffer[barIndex] = 0; - swingHighBuffer[barIndex] = 0; - downTrendBuffer[barIndex] = 0; - bullishPinBuffer[barIndex] = 0; - bearishPinBuffer[barIndex] = 0; - bullishEngulfBuffer[barIndex] = 0; - bearishEngulfBuffer[barIndex] = 0; - bullishMomentumBuffer[barIndex] = 0; - bearishMomentumBuffer[barIndex] = 0; - bullishRejectionBuffer[barIndex] = 0; - bearishRejectionBuffer[barIndex] = 0; -} - -/** - * Calculate Vales ... - * - * @param bar_index: Integer, Represent Current Bar ... - * @param prevCalculated: Integer, Represent Previous Calculated Bars ... - * @param ratesTotal: Integer, Represents All Available Bars ... - * @param open: Double Array, History of Open Prices ... - * @param high: Double Array, History of High Prices ... - * @param close: Double Array, History of Close Prices ... - * @param low: Double Array, History of Low Prices ... - * @param tickVolume: Long, History of Tick Volumes on Bar ... - */ -void CalculateValues( - int bar_index, // Selected Bar Index - const int prevCalculated, - const int ratesTotal, - const double &open[], - const double &high[], - const double &close[], - const double &low[], - const long &tickVolume[] // -) -{ - // - // Prepare Requirements ... - - // - XOHCL iBar; - bool isInited = iBar.Init( - _Symbol, - _Period, - bar_index // - ); - if (!isInited) - { - // - iBar.Clean(); - return; - } - - // - XOHCL pBar; - isInited = iBar.GetPreviousBar(pBar); - if (!isInited) - { - // - iBar.Clean(); - pBar.Clean(); - return; - } - int pIndex = pBar.Index(); - - // - // Calculate Applied Price ... - double iPrice = GetAppliedPrice( - appliedTo, - open, - high, - low, - close, - bar_index // - ); - - // - double iMa = maBuffer[bar_index]; - double iMaPrev = maBuffer[pIndex]; - double iAtr = atrBuffer[bar_index]; - double iAdx = adxBuffer[bar_index]; - double iAppliedAtr = iAtr * atrMultiplier; - - // - double points = GetPoints(_Symbol); - double points10 = 10 * points; - - // - ENUM_X_DIRECTION iDir = X_DIRECTION_NONE; - - // - bool hasLastBullOB = lastBullOB != NULL && - lastBullOB.IsValid(); - bool hasLastBearOB = lastBearOB != NULL && - lastBearOB.IsValid(); - - // - bool hasLastBullFVG = lastBullFVG != NULL && - lastBullFVG.IsValid(); - bool hasLastBearFVG = lastBearFVG != NULL && - lastBearFVG.IsValid(); - - // - bool hasLastSupport = lastSupport != NULL && - lastSupport.IsValid(); - - // - bool hasLastResistance = lastResistance != NULL && - lastResistance.IsValid(); - - // - // Calculate Crossing Over / Under Ma ... - bool isCrossedOverMA = - // - iBar.low > iMa && - (pBar.low <= iMaPrev && - (pBar.GetUp() <= iMaPrev || - pBar.GetDown() <= iMaPrev)) - // - ; - bool isCrossedUnderMA = - // - iBar.high < iMa && - (pBar.high >= iMaPrev && - (pBar.GetUp() >= iMaPrev || - pBar.GetDown() >= iMaPrev)) - // - ; - lastCrossedOverMA = - isCrossedOverMA - ? iBar.time - : lastCrossedOverMA; - lastCrossedUnderMA = - isCrossedUnderMA - ? iBar.time - : lastCrossedUnderMA; - - // - // SL Buffers ... - - // - double iLongSL = iPrice - iAppliedAtr; - double iShortSL = iPrice + iAppliedAtr; - - // - longSLBuffer[bar_index] = iLongSL; - shortSLBuffer[bar_index] = iShortSL; - - // - // Trend Buffers ... - - // - bool isUpTrend = - // - iPrice > iMa && - iBar.low < iMa && - iAdx > adxThreshold - // - ; - - // - bool isDownTrend = - // - iPrice < iMa && - iBar.high > iMa && - iAdx > adxThreshold - // - ; - - // - double upTrendValue = 0; - double downTrendValue = 0; - if (isUpTrend) - { - // - lastBullishTrend = iBar.time; - upTrendValue = iBar.low; - } - if (isDownTrend) - { - // - lastBearishTrend = iBar.time; - downTrendValue = iBar.high; - } - - // - upTrendBuffer[bar_index] = upTrendValue; - downTrendBuffer[bar_index] = downTrendValue; - - // - // Momentum Buffers ... - - // - bool isMomentum = mXWZBarAnalyser - .IsMomentumBar( - iBar, - iDir, - 1, // Extends ... - 70 // Body Percent ... - ); - bool isBullishMomentum = - isMomentum && - IsBullish(iDir); - bool isBearishMomentum = - isMomentum && - IsBearish(iDir); - if (isMomentum) - { - // - double iBullMomentumValue = 0; - double iBearMomentumValue = 0; - - // - if (isBullishMomentum) - { - // - double selectedValue = iBar.low; - - // - iBullMomentumValue = - !filterPOIsUsingZones - ? selectedValue - : !hasLastBullOB - ? 0 - : IsInside( - selectedValue, - lastBullOB // - ) - ? selectedValue - : 0; - - // - iBullMomentumValue = - !filterPOIsUsingMa - ? iBullMomentumValue - : iBullMomentumValue < iMa - ? iBullMomentumValue - : 0; - } - - // - if (isBearishMomentum) - { - // - double selectedValue = iBar.high; - - // - iBearMomentumValue = - !filterPOIsUsingZones - ? selectedValue - : !hasLastBearOB - ? 0 - : IsInside( - selectedValue, - lastBearOB // - ) - ? selectedValue - : 0; - - // - iBearMomentumValue = - !filterPOIsUsingMa - ? iBearMomentumValue - : iBearMomentumValue > iMa - ? iBearMomentumValue - : 0; - } - - // - bullishMomentumBuffer[bar_index] = iBullMomentumValue; - bearishMomentumBuffer[bar_index] = iBearMomentumValue; - } - - // - // Rejection Buffers ... - - // - bool isRejection = mXWZBarAnalyser - .IsRejectionBar( - iBar, - iDir, - 1, // Extends ... - 70 // Body Percent ... - ); - bool isBullishRejection = - isRejection && - IsBullish(iDir); - bool isBearishRejection = - isRejection && - IsBearish(iDir); - if (isRejection) - { - // - double iBullRejectionValue = 0; - double iBearRejectionValue = 0; - - // - if (isBullishRejection) - { - // - double selectedValue = iBar.low; - - // - iBullRejectionValue = - !filterPOIsUsingZones - ? selectedValue - : !hasLastBullOB - ? 0 - : IsInside( - selectedValue, - lastBullOB // - ) - ? selectedValue - : 0; - - // - iBullRejectionValue = - !filterPOIsUsingMa - ? iBullRejectionValue - : iBullRejectionValue < iMa - ? iBullRejectionValue - : 0; - } - - // - if (isBearishRejection) - { - // - double selectedValue = iBar.high; - - // - iBearRejectionValue = - !filterPOIsUsingZones - ? selectedValue - : !hasLastBearOB - ? 0 - : IsInside( - selectedValue, - lastBearOB // - ) - ? selectedValue - : 0; - - // - iBearRejectionValue = - !filterPOIsUsingMa - ? iBearRejectionValue - : iBearRejectionValue > iMa - ? iBearRejectionValue - : 0; - } - - // - bullishRejectionBuffer[bar_index] = iBullRejectionValue; - bearishRejectionBuffer[bar_index] = iBearRejectionValue; - } - - // - // Pin Buffers ... - - // - bool isPin = mXWZBarAnalyser - .IsPinBar( - iBar, - iDir, - 0, // Extends ... - 50, // Shadow Percent ... - 25 // Body Percent ... - ); - bool isBullishPin = - isPin && - IsBullish(iDir); - bool isBearishPin = - isPin && - IsBearish(iDir); - if (isPin) - { - // - double iBullPinValue = 0; - double iBearPinValue = 0; - - // - if (isBullishPin) - { - // - double selectedValue = iBar.low; - - // - iBullPinValue = - !filterPOIsUsingZones - ? selectedValue - : !hasLastBullOB - ? 0 - : IsInside( - selectedValue, - lastBullOB // - ) - ? selectedValue - : 0; - - // - iBullPinValue = - !filterPOIsUsingMa - ? iBullPinValue - : iBullPinValue < iMa - ? iBullPinValue - : 0; - } - - // - if (isBearishPin) - { - // - double selectedValue = iBar.high; - - // - iBearPinValue = - !filterPOIsUsingZones - ? selectedValue - : !hasLastBearOB - ? 0 - : IsInside( - selectedValue, - lastBearOB // - ) - ? selectedValue - : 0; - - // - iBearPinValue = - !filterPOIsUsingMa - ? iBearPinValue - : iBearPinValue > iMa - ? iBearPinValue - : 0; - } - - // - bullishPinBuffer[bar_index] = iBullPinValue; - bearishPinBuffer[bar_index] = iBearPinValue; - } - - // - // Engulf Buffers ... - - // - bool isEngulf = mXWZBarAnalyser - .IsEngulfBar( - iBar, - iDir, - 1, // Extends ... - 70 // Body Percent ... - ); - bool isBullishEngulf = - isEngulf && - IsBullish(iDir); - bool isBearishEngulf = - isEngulf && - IsBearish(iDir); - if (isEngulf) - { - // - double iBullEngulfValue = 0; - double iBearEngulfValue = 0; - - // - if (isBullishEngulf) - { - // - double selectedValue = iBar.low; - - // - iBullEngulfValue = - !filterPOIsUsingZones - ? selectedValue - : !hasLastBullOB - ? 0 - : IsInside( - selectedValue, - lastBullOB // - ) - ? selectedValue - : 0; - - // - iBullEngulfValue = - !filterPOIsUsingMa - ? iBullEngulfValue - : iBullEngulfValue < iMa - ? iBullEngulfValue - : 0; - } - - // - if (isBearishEngulf) - { - // - double selectedValue = iBar.high; - - // - iBearEngulfValue = - !filterPOIsUsingZones - ? selectedValue - : !hasLastBearOB - ? 0 - : IsInside( - selectedValue, - lastBearOB // - ) - ? selectedValue - : 0; - - // - iBearEngulfValue = - !filterPOIsUsingMa - ? iBearEngulfValue - : iBearEngulfValue > iMa - ? iBearEngulfValue - : 0; - } - - // - bullishEngulfBuffer[bar_index] = iBullEngulfValue; - bearishEngulfBuffer[bar_index] = iBearEngulfValue; - } - - // - // Swing Buffers ... - - // - bool isSwing = mXWZBarAnalyser - .IsSwing( - iBar, - iDir, - 2 // Range ... - ); - bool isSwingLow = - isSwing && - IsBullish(iDir); - bool isSwingHigh = - isSwing && - IsBearish(iDir); - if (isSwing) - { - // - double iSwingLowValue = 0; - double iSwingHighValue = 0; - - // - if (isSwingLow) - { - // - double selectedValue = iBar.low; - - // - iSwingLowValue = - !filterPOIsUsingZones - ? selectedValue - : !hasLastBullOB - ? 0 - : IsBelow( - selectedValue, - lastBullOB // - ) - ? selectedValue - : 0; - - // - iSwingLowValue = - !filterPOIsUsingMa - ? iSwingLowValue - : iSwingLowValue < iMa - ? iSwingLowValue - : 0; - } - - // - if (isSwingHigh) - { - // - double selectedValue = iBar.high; - - // - iSwingHighValue = - !filterPOIsUsingZones - ? selectedValue - : !hasLastBearOB - ? 0 - : IsAbove( - selectedValue, - lastBearOB // - ) - ? selectedValue - : 0; - - // - iSwingHighValue = - !filterPOIsUsingMa - ? iSwingHighValue - : iSwingHighValue > iMa - ? iSwingHighValue - : 0; - } - - // - swingLowBuffer[bar_index] = iSwingLowValue; - swingHighBuffer[bar_index] = iSwingHighValue; - } - - // - // - // - - // - DetectSignals( - bar_index, - prevCalculated, - ratesTotal, - open, - high, - close, - low, - tickVolume // - ); - - // - // Cleanup Resources ... - - // - iBar.Clean(); - pBar.Clean(); -} - -// -void ConfigureAlert() -{ - // - mXWZAlert.SetPrefix(ShortName); - - // - mXWZAlert.SetPushAlerts(mXWZPushAlerts); - mXWZAlert.SetMailAlerts(mXWZMailAlerts); - mXWZAlert.SetEnableAlerts(mXWZEnableAlerts); - mXWZAlert.SetTerminalAlerts(mXWZTerminalAlerts); -} - -// -void DetectSignals( - int barIndex, - const int prevCalculated, - const int ratesTotal, - const double &open[], - const double &high[], - const double &close[], - const double &low[], - const long &tickVolume[] // -) -{ - // - // Calculate Signals ... - - // - XOHCL bar; - XOHCL pBar; - XOHCL ppBar; - bool isInited = bar.Init( - _Symbol, - _Period, - barIndex // - ); - if (!isInited) - { - return; - } - - // - isInited = bar.GetPreviousBar(pBar); - if (!isInited) - { - return; - } - - // - isInited = pBar.GetPreviousBar(ppBar); - if (!isInited) - { - return; - } - - // - int pIDX = pBar.Index(); - int ppIDX = ppBar.Index(); - - // - // Reading Buffers ... - - // - double ma = maBuffer[barIndex]; - double maPrev = maBuffer[pIDX]; - double maPPrev = maBuffer[ppIDX]; - - // - // Pin Bar ... - bool isBullisPinned = bullishPinBuffer[pIDX] > 0; - bool isBearisPinned = bearishPinBuffer[pIDX] > 0; - - // - // Engulf Bar ... - bool isBullisEngulfed = bullishEngulfBuffer[pIDX] > 0; - bool isBearisEngulfed = bearishEngulfBuffer[pIDX] > 0; - - // - // Rejection Bar ... - bool isBullishRejected = bullishRejectionBuffer[pIDX] > 0; - bool isBearishRejected = bearishRejectionBuffer[pIDX] > 0; - - // - // Momentum Bar ... - bool isBullishMomentum = bullishMomentumBuffer[pIDX] > 0; - bool isBearishMomentum = bearishMomentumBuffer[pIDX] > 0; - - // - // Checking Pullback ... - ENUM_X_DIRECTION pullbackDir; - bool hasPullback = mXWZBarAnalyser.HasPullBack( - pullbackDir, - bar // - ); - bool hasBullishPullback = - hasPullback && - IsBullish(pullbackDir); - bool hasBearishPullback = - hasPullback && - IsBearish(pullbackDir); - - // - // Order Block Parsing ... - - // // - // bool isMACrossedOverBullishOB = - // // - // lastBullOB != NULL && - // lastBullOB.IsValid() && - // // - // IsInside( - // maPPrev, - // lastBullOB // - // ) && - // // - // IsAbove( - // maPrev, - // lastBullOB // - // ) - // // - // ; - - // // - // bool isMACrossedUnderBearishOB = - // // - // lastBearOB != NULL && - // lastBearOB.IsValid() && - // // - // IsInside( - // maPPrev, - // lastBearOB // - // ) && - // // - // IsBelow( - // maPrev, - // lastBearOB // - // ) - // // - // ; - - // - // Bullish ... - // -------------- - // -[] a Bullish Wave Which Crossed Over MA ... - // -[] Trend is Bullish ... - // -[] PullBack to MA ... - // -[] Has a Bllish Rejection ... - bool hasBullishSignal = - // - pBar.IsBullish() && - pBar.low < maPrev && - pBar.GetDown() >= maPrev && - // - bar.open >= ma && - // - hasBearishPullback && - // - false - // - ; - - // - // Bearish ... - // -------------- - // -[] a Bearish Wave Which Crossed Under MA ... - // -[] Trend is Bearish ... - // -[] PullBack to MA ... - // -[] Has a Bearish Rejection ... - bool hasBearishSignal = - // - false - // pBar.IsBearish() && - // pBar.high > maPrev && - // pBar.GetUp() <= maPrev && - // // - // bar.open <= ma && - // // - // true - // - ; - - // - // Draw ... - // - - // - long chartID = mXWZPOIDrawer.ChartIdentification(); - int window = mXWZPOIDrawer.SubWindowIdentification(); - - // // - // if (isMACrossedOverBullishOB) - // { - // // - // string name = - // "Bullish_" + - // ToMD5(ToFormatString(pBar.time)); - - // // - // CChartObjectVLine *iLine; - // iLine = new CChartObjectVLine(); - // bool isCreated = iLine.Create( - // chartID, - // name, - // window, - // pBar.time // - // ); - // if (isCreated) - // { - // // - // iLine.Color(clrAqua); - - // // - // mXWZDrawnObjects.Add(iLine); - // } - // } - - // // - // if (isMACrossedUnderBearishOB) - // { - // // - // string name = - // "Bearish_" + - // ToMD5(ToFormatString(pBar.time)); - - // // - // CChartObjectVLine *iLine; - // iLine = new CChartObjectVLine(); - // bool isCreated = iLine.Create( - // chartID, - // name, - // window, - // pBar.time // - // ); - // if (isCreated) - // { - // // - // iLine.Color(clrMagenta); - - // // - // mXWZDrawnObjects.Add(iLine); - // } - // } - - // - bool hasSignal = - (hasBullishSignal || - hasBearishSignal); - if (hasSignal) - { - // - long chartID = mXWZPOIDrawer.ChartIdentification(); - int window = mXWZPOIDrawer.SubWindowIdentification(); - string name = - (hasBullishSignal - ? "Bullish_" - : "Bearish_") + - "Signal_" + ToMD5(ToFormatString(bar.time)); - color signalColor = - hasBullishSignal - ? clrYellow - : clrOrange; - - // - CChartObjectVLine *iSignal; - iSignal = new CChartObjectVLine(); - bool isCreated = iSignal.Create( - chartID, - name, - window, - bar.time // - ); - if (isCreated) - { - // - iSignal.Color(signalColor); - - // - mXWZDrawnObjects.Add(iSignal); - } - - // - bool drawRR = false; - if (drawRR) - { - // - XRR iSigRR; - ENUM_X_POSITION_TYPES type = - hasBullishSignal - ? X_POSITION_TYPE_LONG - : X_POSITION_TYPE_SHORT; - double sl = hasBullishSignal - ? longSLBuffer[barIndex] - : shortSLBuffer[barIndex]; - - // - isCreated = iSigRR.Init( - _Symbol, - _Period, - sl, - bar.open, - type, - ShortName // - ); - if (!isCreated) - { - return; - } - - // - iSigRR.time = pBar.NextAt(); - - // - XCRRObject *iObj; - isCreated = mXWZPOIDrawer.CreateRR( - iSigRR, - iObj // - ); - if (isCreated) - { - mXWZDrawnObjects.Add(iObj); - } - - // - iSigRR.Clean(); - } - } - - // - bar.Clean(); - pBar.Clean(); -} - -// -// POIS Functions ... - -// -void ConfigurePOIDrawer() -{ - // - if (mXWZPOIDrawer == NULL) - { - return; - } - - // - mXWZPOIDrawer.Prefix(ShortName); - mXWZPOIDrawer.ChartIdentification(ChartID()); - mXWZPOIDrawer.SubWindowIdentification(0); - - // - mXWZPOIDrawer.BullishFVGWidth(1); - mXWZPOIDrawer.BullishFVGStyle(STYLE_DOT); - mXWZPOIDrawer.BullishFVGColor(clrAqua); - - // - mXWZPOIDrawer.BearishFVGWidth(1); - mXWZPOIDrawer.BearishFVGStyle(STYLE_DOT); - mXWZPOIDrawer.BearishFVGColor(clrMagenta); - - // - mXWZPOIDrawer.SupportZoneWidth(1); - mXWZPOIDrawer.SupportZoneStyle(STYLE_DASHDOTDOT); - mXWZPOIDrawer.SupportZoneColor(clrLime); - - // - mXWZPOIDrawer.ResistanceZoneWidth(1); - mXWZPOIDrawer.ResistanceZoneStyle(STYLE_DASHDOTDOT); - mXWZPOIDrawer.ResistanceZoneColor(clrRed); - - // - mXWZPOIDrawer.BullishOrderBlockWidth(4); - mXWZPOIDrawer.BullishOrderBlockStyle(STYLE_DASH); - mXWZPOIDrawer.BullishOrderBlockColor(clrAqua); - - // - mXWZPOIDrawer.BearishOrderBlockWidth(4); - mXWZPOIDrawer.BearishOrderBlockStyle(STYLE_DASH); - mXWZPOIDrawer.BearishOrderBlockColor(clrMagenta); -} - -// -void CalculatedPOIs( - int bar_index, // Selected Bar Index - const int prevCalculated, - const int ratesTotal, - const double &open[], - const double &high[], - const double &close[], - const double &low[], - const long &tickVolume[] // -) -{ - // - XOHCL iBar; - bool isInited = iBar.Init( - _Symbol, - _Period, - bar_index // - ); - if (!isInited) - { - // - iBar.Clean(); - return; - } - - // - XOHCL pBar; - isInited = iBar.GetPreviousBar(pBar); - if (!isInited) - { - // - iBar.Clean(); - pBar.Clean(); - return; - } - - // - // POI ... - DetectPOIs(iBar); - UpdatePOIs(iBar); - DrawPOIs(); - - // - iBar.Clean(); - pBar.Clean(); -} - -// -bool CanDetectPOIs() -{ - // - bool result = false; - - // - result = - // - mXWZDetectOrderBlocks || - mXWZDetectFairValueGaps || - mXWZDetectSupportZones || - mXWZDetectResistanceZones - // - ; - - // - return result; -} - -// -void DetectPOIs( - XOHCL &bar // -) -{ - // - if (!CanDetectPOIs()) - { - return; - } - - // - int idx = -1; - int range = 21; - - // - // Detect Order Block ... - - // - if (mXWZDetectOrderBlocks) - { - // - XOHCL obBar; - XCOrderBlock *ob; - ENUM_X_DIRECTION obDir; - bool hasOB = mXWZBarAnalyser.HasOrderBlock( - bar, - obBar, - obDir // - ); - bool hasBullishOB = - hasOB && - IsBullish(obDir); - bool hasBearishOB = - hasOB && - IsBearish(obDir); - if (hasOB) - { - // - ob = new XCOrderBlock(); - bool isInited = ob.Init(obBar, obDir); - if (isInited) - { - // - ENUM_X_DIRECTION iForDir = ob.GetDirection(); - bool isBullish = IsBullish(iForDir); - - // - // Check OB Not Activated ... - XOHCL activationBar; - bool isActivationBarBodyIn = false; - bool isActivated = ob.IsActivated( - iForDir, - activationBar, - isActivationBarBodyIn, - false, - _Period // - ); - - // - if (!isActivated) - { - // - idx = FindIndex( - ob, - mXWZUnActivatedOBs // - ); - if (!IsValidIndex(idx)) - { - // - if (isBullish) - { - lastBullOB = ob; - } - else - { - lastBearOB = ob; - } - - // - Add( - ob, - mXWZUnActivatedOBs // - ); - } - } - else - { - // - idx = FindIndex( - ob, - mXWZActivatedOBs // - ); - if (!IsValidIndex(idx)) - { - // - ob.To(activationBar.time); - - // - Add( - ob, - mXWZActivatedOBs // - ); - } - } - - // - activationBar.Clean(); - } - } - - // - obBar.Clean(); - } - - // - // Detect Fair Value Gap ... - - // - if (mXWZDetectFairValueGaps) - { - // - XOHCL fvgStartBar; - XOHCL fvgEndBar; - XCFVG *fvg; - ENUM_X_DIRECTION fvgDir; - bool hasFVG = mXWZBarAnalyser.HasFairValueGap( - bar, - fvgStartBar, - fvgEndBar, - fvgDir // - ); - bool hasBullishFVG = - hasFVG && - IsBullish(fvgDir); - bool hasBearishFVG = - hasFVG && - IsBearish(fvgDir); - if (hasFVG) - { - // - fvg = new XCFVG(); - bool isInited = fvg.Init( - fvgStartBar, - fvgEndBar, - fvgDir // - ); - if (isInited) - { - // - ENUM_X_DIRECTION iForDir = fvg.GetDirection(); - bool isBullish = IsBullish(iForDir); - - // - // Check OB Not Activated ... - XOHCL activationBar; - bool isActivationBarBodyIn = false; - bool isActivated = fvg.IsActivated( - iForDir, - activationBar, - isActivationBarBodyIn, - false, - _Period // - ); - - // - if (!isActivated) - { - // - idx = FindIndex( - fvg, - mXWZUnActivatedFVGs // - ); - if (!IsValidIndex(idx)) - { - // - if (isBullish) - { - lastBullFVG = fvg; - } - else - { - lastBearFVG = fvg; - } - - // - Add( - fvg, - mXWZUnActivatedFVGs // - ); - } - } - else - { - // - idx = FindIndex( - fvg, - mXWZActivatedFVGs // - ); - if (!IsValidIndex(idx)) - { - // - fvg.To(activationBar.time); - - // - Add( - fvg, - mXWZActivatedFVGs // - ); - } - } - - // - activationBar.Clean(); - } - } - - // - fvgEndBar.Clean(); - fvgStartBar.Clean(); - } - - // - // Detect Support Zone ... - - // - if (mXWZDetectSupportZones) - { - // - XOHCL supportBar; - XCSupportZone *supportZone; - bool hasSupport = mXWZBarAnalyser - .HasSupport( - bar, - supportBar, - range // - ); - if (hasSupport) - { - // - supportZone = new XCSupportZone(); - hasSupport = supportZone.Init( - supportBar, - range, - true // Use Range As Start ... - ); - - // - if (hasSupport) - { - // - // Check OB Not Activated ... - XOHCL activationBar; - bool isActivationBarBodyIn = false; - bool isActivated = supportZone.IsActivated( - X_DIRECTION_BULLISH, - activationBar, - isActivationBarBodyIn, - false, - _Period // - ); - - // - if (!isActivated) - { - // - idx = FindIndex( - supportZone, - mXWZUnActivatedSupportZones // - ); - hasSupport = !IsValidIndex(idx); - if (hasSupport) - { - // - lastSupport = supportZone; - - // - Add( - supportZone, - mXWZUnActivatedSupportZones // - ); - } - } - else - { - // - idx = FindIndex( - supportZone, - mXWZActivatedSupportZones // - ); - hasSupport = !IsValidIndex(idx); - if (hasSupport) - { - // - supportZone.To(activationBar.time); - - // - Add( - supportZone, - mXWZActivatedSupportZones // - ); - } - } - - // - activationBar.Clean(); - } - } - - // - supportBar.Clean(); - } - - // - // Detect Resistance Zone ... - - // - if (mXWZDetectResistanceZones) - { - // - XOHCL resistaneBar; - XCResistanceZone *resistanceZone; - bool hasResistance = mXWZBarAnalyser - .HasResistance( - bar, - resistaneBar, - range // - ); - if (hasResistance) - { - // - resistanceZone = new XCResistanceZone(); - hasResistance = resistanceZone.Init( - resistaneBar, - range, - true // Use Range As Start ... - ); - - // - if (hasResistance) - { - // - // Check OB Not Activated ... - XOHCL activationBar; - bool isActivationBarBodyIn = false; - bool isActivated = resistanceZone.IsActivated( - X_DIRECTION_BULLISH, - activationBar, - isActivationBarBodyIn, - false, - _Period // - ); - - // - if (!isActivated) - { - // - idx = FindIndex( - resistanceZone, - mXWZUnActivatedResistanceZones // - ); - hasResistance = !IsValidIndex(idx); - if (hasResistance) - { - // - lastResistance = resistanceZone; - - // - Add( - resistanceZone, - mXWZUnActivatedResistanceZones // - ); - } - } - else - { - // - idx = FindIndex( - resistanceZone, - mXWZActivatedResistanceZones // - ); - hasResistance = !IsValidIndex(idx); - if (hasResistance) - { - // - resistanceZone.To(activationBar.time); - - // - Add( - resistanceZone, - mXWZActivatedResistanceZones // - ); - } - } - - // - activationBar.Clean(); - } - } - - // - resistaneBar.Clean(); - } - - // -} - -// -void UpdatePOIs( - XOHCL &bar // -) -{ - // - int count = -1; - bool has = false; - bool resetDraws = false; - - // - if (!bar.IsValid()) - { - return; - } - - // - datetime to = bar.time; - - // - // Order Blocks ... - - // - count = ArraySize(mXWZUnActivatedOBs); - has = IsValidSize(count); - if (has) - { - // - XCOrderBlock *tmps[]; - for (int i = 0; i < count; i++) - { - // - // Update To ... - mXWZUnActivatedOBs[i].To(to); - - // - // Check Activation ... - - // - // Check OB Not Activated ... - XOHCL activationBar; - bool isActivationBarBodyIn = false; - bool isActivated = mXWZUnActivatedOBs[i] - .IsActivated( - mXWZUnActivatedOBs[i].GetDirection(), - activationBar, - isActivationBarBodyIn, - false, - _Period // - ); - - // - activationBar.Clean(); - - // - if (!isActivated) - { - // - Add( - mXWZUnActivatedOBs[i], - tmps // - ); - } - else - { - // - Add( - mXWZUnActivatedOBs[i], - mXWZActivatedOBs // - ); - } - } - - // - Copy( - tmps, - mXWZUnActivatedOBs // - ); - } - - // - count = ArraySize(mXWZActivatedOBs); - has = IsValidSize(count); - if (has) - { - // - // Remove UnWorks / Breaked Zones ... - int removeIDX[]; - for (int i = 0; i < count; i++) - { - // - XCOrderBlock *iZone = mXWZActivatedOBs[i]; - - // - XOHCL passedBar; - bool isBodyOut = false; - ENUM_X_DIRECTION iForDir = iZone.GetDirection(); - - // - // Check Works ... - bool isWorked = iZone.IsWorked( - iForDir, - passedBar, - isBodyOut, - true, - false, - false, - _Period // - ); - if (!isWorked) - { - // - Add( - i, - removeIDX // - ); - - // - passedBar.Clean(); - break; - } - - // - passedBar.Clean(); - } - - // - if (HasChild(removeIDX)) - { - // - resetDraws = true; - - // - count = ArraySize(removeIDX); - for (int i = 0; i < count; i++) - { - // - ArrayRemove( - mXWZActivatedOBs, - removeIDX[i], - 1 // - ); - } - } - - // - Clean(removeIDX); - } - - // - // Fair Value Gaps ... - - // - count = ArraySize(mXWZUnActivatedFVGs); - has = IsValidSize(count); - if (has) - { - // - XCFVG *tmps[]; - for (int i = 0; i < count; i++) - { - // - // Update To ... - mXWZUnActivatedFVGs[i].To(to); - - // - // Check Activation ... - - // - // Check OB Not Activated ... - XOHCL activationBar; - bool isActivationBarBodyIn = false; - bool isActivated = mXWZUnActivatedFVGs[i] - .IsActivated( - mXWZUnActivatedFVGs[i].GetDirection(), - activationBar, - isActivationBarBodyIn, - false, - _Period // - ); - - // - activationBar.Clean(); - - // - if (!isActivated) - { - // - Add( - mXWZUnActivatedFVGs[i], - tmps // - ); - } - else - { - // - Add( - mXWZUnActivatedFVGs[i], - mXWZActivatedFVGs // - ); - } - } - - // - Copy( - tmps, - mXWZUnActivatedFVGs // - ); - } - - // - count = ArraySize(mXWZActivatedFVGs); - has = IsValidSize(count); - if (has) - { - // - // Remove UnWorks / Breaked Zones ... - int removeIDX[]; - for (int i = 0; i < count; i++) - { - // - XCFVG *iZone = mXWZActivatedFVGs[i]; - - // - XOHCL passedBar; - bool isBodyOut = false; - ENUM_X_DIRECTION iForDir = iZone.GetDirection(); - - // - // Check Works ... - bool isWorked = iZone.IsWorked( - iForDir, - passedBar, - isBodyOut, - true, - false, - false, - _Period // - ); - if (!isWorked) - { - // - Add( - i, - removeIDX // - ); - - // - passedBar.Clean(); - break; - } - - // - passedBar.Clean(); - } - - // - if (HasChild(removeIDX)) - { - // - resetDraws = true; - - // - count = ArraySize(removeIDX); - for (int i = 0; i < count; i++) - { - // - ArrayRemove( - mXWZActivatedFVGs, - removeIDX[i], - 1 // - ); - } - } - - // - Clean(removeIDX); - } - - // - // Support Zones ... - - // - count = ArraySize(mXWZUnActivatedSupportZones); - has = IsValidSize(count); - if (has) - { - // - XCSupportZone *tmps[]; - for (int i = 0; i < count; i++) - { - // - // Update To ... - mXWZUnActivatedSupportZones[i].To(to); - - // - // Check Activation ... - - // - // Check OB Not Activated ... - XOHCL activationBar; - bool isActivationBarBodyIn = false; - bool isActivated = mXWZUnActivatedSupportZones[i] - .IsActivated( - X_DIRECTION_BULLISH, - activationBar, - isActivationBarBodyIn, - false, - _Period // - ); - - // - if (!isActivated) - { - // - Add( - mXWZUnActivatedSupportZones[i], - tmps // - ); - } - else - { - // - mXWZUnActivatedSupportZones[i].To(activationBar.time); - - // - Add( - mXWZUnActivatedSupportZones[i], - mXWZActivatedSupportZones // - ); - } - - // - activationBar.Clean(); - } - - // - Copy( - tmps, - mXWZUnActivatedSupportZones // - ); - } - - // - count = ArraySize(mXWZActivatedSupportZones); - has = IsValidSize(count); - if (has) - { - // - // Remove UnWorks / Breaked Zones ... - int removeIDX[]; - ENUM_X_DIRECTION iForDir = X_DIRECTION_BULLISH; - for (int i = 0; i < count; i++) - { - // - XCSupportZone *iZone = mXWZActivatedSupportZones[i]; - - // - XOHCL passedBar; - bool isBodyOut = false; - - // - // Check Works ... - bool isWorked = iZone.IsWorked( - iForDir, - passedBar, - isBodyOut, - true, - false, - false, - _Period // - ); - if (!isWorked) - { - // - Add( - i, - removeIDX // - ); - - // - passedBar.Clean(); - break; - } - - // - passedBar.Clean(); - } - - // - if (HasChild(removeIDX)) - { - // - resetDraws = true; - - // - count = ArraySize(removeIDX); - for (int i = 0; i < count; i++) - { - // - ArrayRemove( - mXWZActivatedSupportZones, - removeIDX[i], - 1 // - ); - } - } - - // - Clean(removeIDX); - } - - // - // Resistance Zones ... - - // - count = ArraySize(mXWZUnActivatedResistanceZones); - has = IsValidSize(count); - if (has) - { - // - XCResistanceZone *tmps[]; - for (int i = 0; i < count; i++) - { - // - // Update To ... - mXWZUnActivatedResistanceZones[i].To(to); - - // - // Check Activation ... - - // - // Check OB Not Activated ... - XOHCL activationBar; - bool isActivationBarBodyIn = false; - bool isActivated = mXWZUnActivatedResistanceZones[i] - .IsActivated( - X_DIRECTION_BULLISH, - activationBar, - isActivationBarBodyIn, - false, - _Period // - ); - - // - if (!isActivated) - { - // - Add( - mXWZUnActivatedResistanceZones[i], - tmps // - ); - } - else - { - // - mXWZUnActivatedResistanceZones[i].To(activationBar.time); - - // - Add( - mXWZUnActivatedResistanceZones[i], - mXWZActivatedResistanceZones // - ); - } - - // - activationBar.Clean(); - } - - // - Copy( - tmps, - mXWZUnActivatedResistanceZones // - ); - } - - // - count = ArraySize(mXWZActivatedResistanceZones); - has = IsValidSize(count); - if (has) - { - // - // Remove UnWorks / Breaked Zones ... - int removeIDX[]; - ENUM_X_DIRECTION iForDir = X_DIRECTION_BEARISH; - for (int i = 0; i < count; i++) - { - // - XCResistanceZone *iZone = mXWZActivatedResistanceZones[i]; - - // - XOHCL passedBar; - bool isBodyOut = false; - - // - // Check Breake ... - bool isBreaked = iZone.IsBreaked( - iForDir, - passedBar, - isBodyOut, - true, - false, - _Period // - ); - if (isBreaked) - { - // - Add( - i, - removeIDX // - ); - - // - passedBar.Clean(); - break; - } - - // - // Check Works ... - bool isWorked = iZone.IsWorked( - iForDir, - passedBar, - isBodyOut, - true, - false, - false, - _Period // - ); - if (!isWorked) - { - // - Add( - i, - removeIDX // - ); - - // - passedBar.Clean(); - break; - } - - // - passedBar.Clean(); - } - - // - if (HasChild(removeIDX)) - { - // - resetDraws = true; - - // - count = ArraySize(removeIDX); - for (int i = 0; i < count; i++) - { - // - ArrayRemove( - mXWZActivatedResistanceZones, - removeIDX[i], - 1 // - ); - } - } - - // - Clean(removeIDX); - } - - // - // - // - - // - // Clean Draws if has to ... - if (resetDraws) - { - mXWZDrawnObjects.Clear(); - } - - // -} - -// -void DrawPOIs() -{ - // - int count = 0; - bool has = false; - bool isCreated = false; - - // - if (!showPOIs) - { - return; - } - - // - // Order Blocks ... - if (showOrderBlocks) - { - // - bool showBullishOrderBlocks = true; - bool showBearishOrderBlocks = true; - - // - // UnActivated ... - count = ArraySize(mXWZUnActivatedOBs); - has = IsValidSize(count); - if (has) - { - // - for (int i = 0; i < count; i++) - { - // - bool isBullish = mXWZUnActivatedOBs[i].IsBullish(); - - // - if ((isBullish && - showBullishOrderBlocks) || - (!isBullish && - showBearishOrderBlocks)) - { - // - XCBaseObject *iObj; - isCreated = mXWZPOIDrawer - .CreateOrderBlock( - mXWZUnActivatedOBs[i], - iObj // - ); - if (isCreated) - { - mXWZDrawnObjects.Add(iObj); - } - } - } - } - - // - // Activated ... - count = ArraySize(mXWZActivatedOBs); - has = IsValidSize(count); - if (has) - { - // - for (int i = 0; i < count; i++) - { - // - XCOrderBlock *iOB = mXWZActivatedOBs[i]; - - // - bool isBullish = iOB.IsBullish(); - - // - if (showActivatedPOIs && - ((isBullish && - showBullishOrderBlocks) || - (!isBullish && - showBearishOrderBlocks))) - { - // - XCBaseObject *iObj; - isCreated = mXWZPOIDrawer - .CreateOrderBlock( - iOB, - iObj // - ); - if (isCreated) - { - // - // if (isBullish) - // { - // ((XCBullishOrderBlockObject *)iObj).ZoneFill(true); - // } - // else - // { - // ((XCBearishOrderBlockObject *)iObj).ZoneFill(true); - // } - - // - mXWZDrawnObjects.Add(iObj); - } - } - } - } - } - - // - // Fair Value Gaps ... - if (showFairValueGaps) - { - // - bool showBullishFairValueGaps = true; - bool showBearishFairValueGaps = true; - - // - // UnActivated ... - count = ArraySize(mXWZUnActivatedFVGs); - has = IsValidSize(count); - if (has) - { - // - for (int i = 0; i < count; i++) - { - // - bool isBullish = mXWZUnActivatedFVGs[i].IsBullish(); - - // - if ((isBullish && - showBullishFairValueGaps) || - (!isBullish && - showBearishFairValueGaps)) - { - // - XCBaseObject *iObj; - isCreated = mXWZPOIDrawer - .CreateFairValueGap( - mXWZUnActivatedFVGs[i], - iObj // - ); - if (isCreated) - { - mXWZDrawnObjects.Add(iObj); - } - } - } - } - - // - // Activated ... - count = ArraySize(mXWZActivatedFVGs); - has = IsValidSize(count); - if (has) - { - // - for (int i = 0; i < count; i++) - { - // - XCFVG *iFVG = mXWZActivatedFVGs[i]; - - // - bool isBullish = iFVG.IsBullish(); - - // - if (showActivatedPOIs && - ((isBullish && - showBullishFairValueGaps) || - (!isBullish && - showBearishFairValueGaps))) - { - XCBaseObject *iObj; - isCreated = mXWZPOIDrawer - .CreateFairValueGap( - iFVG, - iObj // - ); - if (isCreated) - { - // - // if (isBullish) - // { - // ((XCBullishOrderBlockObject *)iObj).ZoneFill(true); - // } - // else - // { - // ((XCBearishOrderBlockObject *)iObj).ZoneFill(true); - // } - - // - mXWZDrawnObjects.Add(iObj); - } - } - } - } - } - - // - // Support Zones ... - if (showSupportZones) - { - // - // UnActivated ... - count = ArraySize(mXWZUnActivatedSupportZones); - has = IsValidSize(count); - if (has) - { - // - for (int i = 0; i < count; i++) - { - // - XCSupportZoneObject *iObj; - isCreated = mXWZPOIDrawer - .CreateSupportZone( - mXWZUnActivatedSupportZones[i], - iObj // - ); - if (isCreated) - { - mXWZDrawnObjects.Add(iObj); - } - } - } - - // - // Activated ... - if (showActivatedPOIs) - { - // - count = ArraySize(mXWZActivatedSupportZones); - has = IsValidSize(count); - if (has) - { - // - for (int i = 0; i < count; i++) - { - // - XCSupportZoneObject *iObj; - isCreated = mXWZPOIDrawer - .CreateSupportZone( - mXWZActivatedSupportZones[i], - iObj // - ); - if (isCreated) - { - mXWZDrawnObjects.Add(iObj); - } - } - } - } - } - - // - // Resistance Zones ... - if (showResistanceZones) - { - // - // UnActivated ... - count = ArraySize(mXWZUnActivatedResistanceZones); - has = IsValidSize(count); - if (has) - { - // - for (int i = 0; i < count; i++) - { - // - XCResistanceZoneObject *iObj; - isCreated = mXWZPOIDrawer - .CreateResistanceZone( - mXWZUnActivatedResistanceZones[i], - iObj // - ); - if (isCreated) - { - mXWZDrawnObjects.Add(iObj); - } - } - } - - // - // Activated ... - if (showActivatedPOIs) - { - // - count = ArraySize(mXWZActivatedResistanceZones); - has = IsValidSize(count); - if (has) - { - // - for (int i = 0; i < count; i++) - { - // - XCResistanceZoneObject *iObj; - isCreated = mXWZPOIDrawer - .CreateResistanceZone( - mXWZActivatedResistanceZones[i], - iObj // - ); - if (isCreated) - { - mXWZDrawnObjects.Add(iObj); - } - } - } - } - } - - // -} - -// \ No newline at end of file diff --git a/Documents/BKP/x-saherelm.xobfvg.lib.mq5 b/Documents/BKP/x-saherelm.xobfvg.lib.mq5 deleted file mode 100644 index 39396031..00000000 --- a/Documents/BKP/x-saherelm.xobfvg.lib.mq5 +++ /dev/null @@ -1,1897 +0,0 @@ -// /////////////////////////////////////////////////////// -// // -// // SaherElm IT Center MQL5 Seriallize Library -// // --------------------------------------- -// // Name: XOBFVGLib -// // Description: All models related to POIs ... -// // -// // -// // Maintainer: -// // ------------ -// // Hadi Khazaee Asl (hadi_khazaee_asl@yahoo.com) -// // -// ////////////////////////////////////////////////////// -// // -// // Global Properties ... -// #property library -// #property copyright "Copyright `023, SaherElm IT Center" -// #property link "https://www.saherelm.ir" -// #property version "1.00" -// #property strict - -// // -// // Imports ... -// #include "../Libraries/x-saherelm.x-poi.state.lib.mq5" - -// // -// struct XOBFVGPivot -// { -// // -// // Props ... -// double value; -// datetime at; - -// // -// // Constructor ... -// XOBFVGPivot() -// { -// Clean(); -// } - -// // -// // Tools ... - -// // -// void Clean() -// { -// // -// value = 0; -// at = NULL; - -// // -// ZeroMemory(this); -// } - -// // -// bool IsValid() -// { -// // -// bool result = false; - -// // -// result = -// value > 0 && -// IsValid(at); - -// // -// return result; -// } -// }; - -// // -// struct XOBFVG -// { -// // -// // Props ... -// XCFVG *fvg; -// XCOrderBlock *ob; - -// // -// XCSupplyZone *supplyZones[]; -// XCDemandZone *demandZones[]; - -// // -// XCSupportZone *supportZones[]; -// XCResistanceZone *resistanceZones[]; - -// // -// // Constructor ... -// XOBFVG() -// { -// Clean(); -// } - -// // -// // Tools ... - -// // -// void Clean() -// { -// // -// ZeroMemory(ob); -// ZeroMemory(fvg); - -// // -// Clean(supplyZones); -// Clean(demandZones); -// Clean(supportZones); -// Clean(resistanceZones); - -// // -// ZeroMemory(this); -// } - -// // -// bool IsValid() -// { -// return HasOB() && -// HasFVG(); -// } - -// // -// bool HasOB() -// { -// return ob != NULL && -// ob.IsValid(); -// } - -// // -// bool HasFVG() -// { -// return fvg != NULL && -// fvg.IsValid(); -// } - -// // -// bool HasSupplyZones() -// { -// return HasChild(supplyZones); -// } - -// // -// int CountSupplyZones() -// { -// return ArraySize(supplyZones); -// } - -// // -// bool HasDemandZones() -// { -// return HasChild(demandZones); -// } - -// // -// int CountDemandZones() -// { -// return ArraySize(demandZones); -// } - -// // -// bool HasSupportZones() -// { -// return HasChild(supportZones); -// } - -// // -// int CountSupportZones() -// { -// return ArraySize(supportZones); -// } - -// // -// bool HasResistanceZones() -// { -// return HasChild(resistanceZones); -// } - -// // -// int CountResistanceZones() -// { -// return ArraySize(resistanceZones); -// } - -// // -// ENUM_X_DIRECTION GetDirection() -// { -// // -// ENUM_X_DIRECTION result = X_DIRECTION_NONE; - -// // -// bool isValid = IsValid(); -// if (!isValid) -// { -// return result; -// } - -// // -// result = ob.GetDirection(); - -// // -// return result; -// } - -// // -// bool IsBullish() -// { -// return IsBullish(GetDirection()); -// } - -// // -// bool IsBearish() -// { -// return IsBearish(GetDirection()); -// } - -// // -// int GetSwings( -// XOBFVGPivot &pivots[] // -// ) -// { -// // -// int result = 0; - -// // -// Clean(pivots); - -// // -// if (!IsValid()) -// { -// return result; -// } - -// // -// ENUM_X_DIRECTION forDir = GetDirection(); -// bool isBullish = IsBullish(forDir); - -// // -// XOHCL passedBar; -// XOBFVGPivot iPivot; -// bool isPassed = false; -// double appliedPrice = 0; -// bool isBodyState = false; - -// // -// // Start ... -// isPassed = ob.IsStarted( -// forDir, -// passedBar, -// isBodyState // -// ); -// if (isPassed) -// { -// // -// appliedPrice = -// isBullish -// ? passedBar.low -// : passedBar.high; - -// // -// iPivot.Clean(); -// iPivot.value = appliedPrice; -// iPivot.at = passedBar.time; - -// // -// AddRef( -// iPivot, -// pivots // -// ); - -// // -// iPivot.Clean(); -// } - -// // -// // Activation ... -// isPassed = ob.IsActivated( -// forDir, -// passedBar, -// isBodyState // -// ); -// if (isPassed) -// { -// // -// appliedPrice = -// isBullish -// ? passedBar.low -// : passedBar.high; - -// // -// iPivot.Clean(); -// iPivot.value = appliedPrice; -// iPivot.at = passedBar.time; - -// // -// AddRef( -// iPivot, -// pivots // -// ); - -// // -// iPivot.Clean(); -// } - -// // -// // Worked ... -// isPassed = ob.IsWorked( -// forDir, -// passedBar, -// isBodyState // -// ); -// if (isPassed) -// { -// // -// appliedPrice = -// isBullish -// ? passedBar.low -// : passedBar.high; - -// // -// iPivot.Clean(); -// iPivot.value = appliedPrice; -// iPivot.at = passedBar.time; - -// // -// AddRef( -// iPivot, -// pivots // -// ); - -// // -// iPivot.Clean(); -// } - -// // -// passedBar.Clean(); - -// // -// result = ArraySize(pivots); - -// // -// return result; -// } - -// // -// void UpdateZones( -// XPOIState &state // -// ) -// { -// // -// Clean(supplyZones); -// Clean(demandZones); -// Clean(supportZones); -// Clean(resistanceZones); - -// // -// bool isValid = -// IsValid() && -// state.HasChild(); -// if (!isValid) -// { -// return; -// } - -// // -// int count = 0; -// bool has = false; -// bool isPassed = false; - -// // -// // Supply Zones ... -// has = state.HasSupplyZones(); -// if (has) -// { -// // -// count = state.CountSupplyZones(); -// for (int i = 0; i < count; i++) -// { -// // -// XCSupplyZone *iZone = state.supplyZones[i]; - -// // -// isPassed = iZone.From() > ob.From(); -// if (!isPassed) -// { -// // -// ZeroMemory(iZone); -// continue; -// } - -// // -// isPassed = IsInsideDiff( -// iZone, -// ob // -// ); -// if (!isPassed) -// { -// // -// ZeroMemory(iZone); -// continue; -// } - -// // -// Add( -// iZone, -// supplyZones // -// ); -// } -// } - -// // -// // Demand Zones ... -// has = state.HasDemandZones(); -// if (has) -// { -// // -// count = state.CountDemandZones(); -// for (int i = 0; i < count; i++) -// { -// // -// XCDemandZone *iZone = state.demandZones[i]; - -// // -// isPassed = iZone.From() > ob.From(); -// if (!isPassed) -// { -// // -// ZeroMemory(iZone); -// continue; -// } - -// // -// isPassed = IsInsideDiff( -// iZone, -// ob // -// ); -// if (!isPassed) -// { -// // -// ZeroMemory(iZone); -// continue; -// } - -// // -// Add( -// iZone, -// demandZones // -// ); -// } -// } - -// // -// // Support Zones ... -// has = state.HasSupportZones(); -// if (has) -// { -// // -// count = state.CountSupportZones(); -// for (int i = 0; i < count; i++) -// { -// // -// XCSupportZone *iZone = state.supportZones[i]; - -// // -// isPassed = iZone.From() > ob.From(); -// if (!isPassed) -// { -// // -// ZeroMemory(iZone); -// continue; -// } - -// // -// isPassed = IsInsideDiff( -// iZone, -// ob // -// ); -// if (!isPassed) -// { -// // -// ZeroMemory(iZone); -// continue; -// } - -// // -// Add( -// iZone, -// supportZones // -// ); -// } -// } - -// // -// // Resistance Zones ... -// has = state.HasResistanceZones(); -// if (has) -// { -// // -// count = state.CountResistanceZones(); -// for (int i = 0; i < count; i++) -// { -// // -// XCResistanceZone *iZone = state.resistanceZones[i]; - -// // -// isPassed = iZone.From() > ob.From(); -// if (!isPassed) -// { -// // -// ZeroMemory(iZone); -// continue; -// } - -// // -// isPassed = IsInsideDiff( -// iZone, -// ob // -// ); -// if (!isPassed) -// { -// // -// ZeroMemory(iZone); -// continue; -// } - -// // -// Add( -// iZone, -// resistanceZones // -// ); -// } -// } -// } - -// // -// void UpdateTo(datetime value = NULL) -// { -// // -// value = NormalizeTime(value); - -// // -// int count = 0; -// bool has = false; - -// // -// has = HasOB(); -// if (has) -// { -// ob.To(value); -// } - -// // -// has = HasFVG(); -// if (has) -// { -// fvg.To(value); -// } - -// // -// // Supply Zones ... -// has = HasSupplyZones(); -// if (has) -// { -// // -// count = CountSupplyZones(); -// for (int i = 0; i < count; i++) -// { -// supplyZones[i].To(value); -// } -// } - -// // -// // Demand Zones ... -// has = HasDemandZones(); -// if (has) -// { -// // -// count = CountDemandZones(); -// for (int i = 0; i < count; i++) -// { -// demandZones[i].To(value); -// } -// } - -// // -// // Support Zones ... -// has = HasSupportZones(); -// if (has) -// { -// // -// count = CountSupportZones(); -// for (int i = 0; i < count; i++) -// { -// supportZones[i].To(value); -// } -// } - -// // -// // Resistance Zones ... -// has = HasResistanceZones(); -// if (has) -// { -// // -// count = CountResistanceZones(); -// for (int i = 0; i < count; i++) -// { -// resistanceZones[i].To(value); -// } -// } -// } -// }; - -// // -// // -// // - -// /** -// * Extract XOBFVG Collection of Market ... -// * -// * @param htfState: Higher Time Frame POI State (Used For Detecting Order Blocks) ... -// * @param mtfState: Medium Time Frame POI State (Used For Detecting Fair Value Gaps) ... -// * @param stfState: Short Time Frame POI State (Used For Detecting Other POI(s)) ... -// * @param dest: Result Collection ... -// * @param forDir: Market Direction for Detecting POI(s) ... -// * @param forPeriod: Time Frame which Used for Zones actions (NULL for Default) ... -// * @param startState: Zones Start State ... -// * @param forceStartedBodyOut: Zones Started Bar's Body State ... -// * @param activeState: Zones Activation State ... -// * @param forceActivatedBodyIn: Zones Activated Bar's Body State ... -// * @param breakState: Zones Breaked State ... -// * @param forceBreakedBodyOut: Zone Breaker Bar's Body State ... -// * @param workState: Zones Worked State ... -// * @param forceWorkedBodyOut: Zones Worked Bar's Body State ... -// * @param applySort: Specify Applying Sorting on Collections ... -// * @param applyFromFilter: Filter Sorted Zones based on Occured Date ... -// * @param applyPlaceFilter: Filter Sorted Zones based on Occured Place ... -// * @param ignoreInside: Ignore Inside Sides of POI(s) Zones in Related to Order Block ... -// * @param applyFromFilterForPOIs: Apply From Filter for Other POI(s) ... -// * -// * @return ( int ) -// */ -// int ExtractOBFVGZones( -// XPOIState &htfState, -// XPOIState &mtfState, -// XPOIState &stfState, -// XOBFVG &dest[], -// // -// ENUM_X_DIRECTION forDir, -// ENUM_TIMEFRAMES forPeriod = NULL, -// // -// // Start ... -// ENUM_XZONE_STATE startState = XZONE_STATE_PASSED, -// bool forceStartedBodyOut = false, -// // -// // Activation ... -// ENUM_XZONE_STATE activeState = XZONE_STATE_FAILED, -// bool forceActivatedBodyIn = false, -// // -// // Breaktion ... -// ENUM_XZONE_STATE breakState = XZONE_STATE_FAILED, -// bool forceBreakedBodyOut = false, -// // -// // Works ... -// ENUM_XZONE_STATE workState = XZONE_STATE_FAILED, -// bool forceWorkedBodyOut = false, -// // -// bool applySort = true, -// bool applyFromFilter = true, -// bool applyPlaceFilter = true, -// // -// bool ignoreInside = true, -// // -// bool detectInsideOBPOIs = true, -// bool detectInsideFVGPOIs = true, -// bool applyFromFilterForPOIs = true -// // -// ) -// { -// // -// int result = 0; - -// // -// Clean(dest); - -// // -// bool isValid = -// // -// htfState.HasChild() && -// mtfState.HasChild() && -// stfState.HasChild() && -// HasDirection(forDir) -// // -// ; -// if (!isValid) -// { -// return result; -// } - -// // -// // Implement Logic ... - -// // -// int idx = -1; -// int count = 0; -// bool has = false; -// XCFVG *tmpFVGs[]; -// XOBFVG tmpOBFVGs[]; -// XCOrderBlock *tmpOBs[]; -// XCOrderBlock *tmpWorkingOBs[]; -// datetime cTime = TimeCurrent(); -// bool isBullish = IsBullish(forDir); - -// // -// if (isBullish) -// { -// // -// has = htfState.HasBullishOrderBlocks(); -// if (has) -// { -// // -// Copy( -// htfState.bullishOrderBlocks, -// tmpOBs // -// ); - -// // -// has = mtfState.HasBullishFairValueGaps(); -// if (has) -// { -// // -// Copy( -// mtfState.bullishFairValueGaps, -// tmpFVGs // -// ); -// } -// } -// } -// else -// { -// // -// has = htfState.HasBearishOrderBlocks(); -// if (has) -// { -// // -// Copy( -// htfState.bearishOrderBlocks, -// tmpOBs // -// ); - -// // -// has = mtfState.HasBearishFairValueGaps(); -// if (has) -// { -// // -// Copy( -// mtfState.bearishFairValueGaps, -// tmpFVGs // -// ); -// } -// } -// } - -// // -// count = ArraySize(tmpOBs); -// has = IsValidSize(count); -// if (has) -// { -// // -// for (int i = 0; i < count; i++) -// { -// // -// XCOrderBlock *iOB = tmpOBs[i]; - -// // -// // Check Started State ... -// if (startState == XZONE_STATE_PASSED || -// startState == XZONE_STATE_FAILED) -// { -// // -// XOHCL passedBar; -// bool isBodyOut = false; -// bool isStarted = iOB.IsStarted( -// forDir, -// passedBar, -// isBodyOut, -// forPeriod // -// ); - -// // -// bool isPassed = -// startState == XZONE_STATE_FAILED -// ? !isStarted -// : !forceStartedBodyOut -// ? isStarted -// : isStarted && -// isBodyOut; - -// // -// passedBar.Clean(); -// if (!isPassed) -// { -// continue; -// } -// } - -// // -// // Check Activation State ... -// if (activeState == XZONE_STATE_PASSED || -// activeState == XZONE_STATE_FAILED) -// { -// // -// XOHCL passedBar; -// bool isBodyIn = false; -// bool isActivated = iOB.IsActivated( -// forDir, -// passedBar, -// isBodyIn, -// forceStartedBodyOut, -// forPeriod // -// ); - -// // -// bool isPassed = -// activeState == XZONE_STATE_FAILED -// ? !isActivated -// : !forceActivatedBodyIn -// ? isActivated -// : isActivated && -// isBodyIn; - -// // -// passedBar.Clean(); -// if (!isPassed) -// { -// continue; -// } -// } - -// // -// // Check Break State ... -// if (breakState == XZONE_STATE_PASSED || -// breakState == XZONE_STATE_FAILED) -// { -// // -// XOHCL passedBar; -// bool isBodyOut = false; -// bool isBreaked = iOB.IsBreaked( -// forDir, -// passedBar, -// isBodyOut, -// forceStartedBodyOut, -// forPeriod // -// ); - -// // -// bool isPassed = -// breakState == XZONE_STATE_FAILED -// ? !isBreaked -// : !forceBreakedBodyOut -// ? isBreaked -// : isBreaked && -// isBodyOut; - -// // -// passedBar.Clean(); -// if (!isPassed) -// { -// continue; -// } -// } - -// // -// // Check Work State ... -// if (workState == XZONE_STATE_PASSED || -// workState == XZONE_STATE_FAILED) -// { -// // -// bool ignoreActivation = activeState != XZONE_STATE_PASSED; - -// // -// XOHCL passedBar; -// bool isBodyOut = false; -// bool isWorked = iOB.IsWorked( -// forDir, -// passedBar, -// isBodyOut, -// ignoreActivation, -// forceStartedBodyOut, -// forceActivatedBodyIn, -// forPeriod // -// ); - -// // -// bool isPassed = -// workState == XZONE_STATE_FAILED -// ? !isWorked -// : !forceWorkedBodyOut -// ? isWorked -// : isWorked && -// isBodyOut; - -// // -// passedBar.Clean(); -// if (!isPassed) -// { -// continue; -// } -// } - -// // -// has = FindIndex( -// idx, -// iOB, -// tmpWorkingOBs // -// ); -// if (has) -// { -// // -// ZeroMemory(iOB); -// continue; -// } - -// // -// Add( -// iOB, -// tmpWorkingOBs // -// ); -// } -// } - -// // -// // Clean ... -// Clean(tmpOBs); -// has = HasChild(tmpWorkingOBs); -// if (has) -// { -// // -// Clean(tmpOBs); -// Copy( -// tmpWorkingOBs, -// tmpOBs // -// ); - -// // -// Clean(tmpWorkingOBs); -// } - -// // -// // Sorting ... -// if (applySort) -// { -// // -// Clean(tmpWorkingOBs); -// has = HasChild(tmpOBs); -// count = ArraySize(tmpOBs); - -// // -// // Sorting Applied Only when there is more than one item ... -// if (has && count > 1) -// { -// // -// bool hasLast = false; -// XCOrderBlock *last = NULL; -// while (HasChild(tmpOBs)) -// { -// // -// // Extract First Last Item ... -// if (!hasLast) -// { -// // -// idx = -// isBullish -// ? GetLowest(tmpOBs) -// : GetHighest(tmpOBs); -// hasLast = IsValidIndex(idx); -// if (hasLast) -// { -// // -// last = tmpOBs[idx]; -// ArrayRemove( -// tmpOBs, -// idx, -// 1 // -// ); - -// // -// Add( -// last, -// tmpWorkingOBs // -// ); -// } -// } - -// // -// has = false; -// XCOrderBlock *iOB = NULL; -// idx = -// isBullish -// ? GetLowest(tmpOBs) -// : GetHighest(tmpOBs); -// has = IsValidIndex(idx); -// if (has) -// { -// // -// iOB = tmpOBs[idx]; -// ArrayRemove( -// tmpOBs, -// idx, -// 1 // -// ); -// } - -// // -// if (!has) -// { -// break; -// } - -// // -// // Apply From Filter ... -// if (applyFromFilter) -// { -// // -// bool isFromPassed = -// hasLast && -// last.From() < iOB.From(); -// if (!isFromPassed) -// { -// continue; -// } -// } - -// // -// // Apply Place Filter ... -// if (applyPlaceFilter) -// { -// // -// bool isAbove = -// hasLast && -// IsAbove( -// iOB, -// last, -// ignoreInside // -// ); - -// // -// bool isBelow = -// hasLast && -// IsBelow( -// iOB, -// last, -// ignoreInside // -// ); - -// // -// bool isPlacePassed = -// isBullish -// ? isAbove -// : isBelow; -// if (!isPlacePassed) -// { -// continue; -// } -// } - -// // -// last = iOB; -// Add( -// iOB, -// tmpWorkingOBs // -// ); -// } - -// // -// if (hasLast && -// !HasChild(tmpWorkingOBs)) -// { -// // -// Add( -// last, -// tmpWorkingOBs // -// ); -// } -// } -// else -// { -// // -// Copy( -// tmpOBs, -// tmpWorkingOBs // -// ); -// } - -// // -// if (HasChild(tmpWorkingOBs)) -// { -// // -// Copy( -// tmpWorkingOBs, -// tmpOBs // -// ); -// } -// // -// } - -// // -// count = ArraySize(tmpOBs); -// has = IsValidSize(count); - -// // -// // Converts to XOBFVG ... -// if (has) -// { -// // -// for (int i = 0; i < count; i++) -// { -// // -// XOBFVG iOBFVG; - -// // -// iOBFVG.ob = tmpOBs[i]; - -// // -// AddRef( -// iOBFVG, -// tmpOBFVGs // -// ); - -// // -// iOBFVG.Clean(); -// } -// } - -// // -// Clean(dest); -// Clean(tmpOBs); -// Clean(tmpWorkingOBs); - -// // -// // Here we Going to Complete XOBFVGs ... -// has = HasChild(tmpOBFVGs); -// if (has && HasChild(tmpFVGs)) -// { -// // -// count = ArraySize(tmpOBFVGs); -// for (int i = 0; i < count; i++) -// { -// // -// XOBFVG iOBFVG = tmpOBFVGs[i]; - -// // -// // Detecting FVG ... -// XCFVG *tmpWorkingFVGs[]; -// for (int j = 0; j < ArraySize(tmpFVGs); j++) -// { -// // -// XCFVG *jFVG = tmpFVGs[j]; - -// // -// // Check Start Date ... -// bool isFromPassed = jFVG.From() > iOBFVG.ob.From(); -// if (!isFromPassed) -// { -// // -// ZeroMemory(jFVG); -// continue; -// } - -// // -// // Check Place ... - -// // -// bool isAbove = IsAboveDiff( -// jFVG, -// iOBFVG.ob, -// ignoreInside // -// ); - -// // -// bool isBelow = IsBelowDiff( -// jFVG, -// iOBFVG.ob, -// ignoreInside // -// ); - -// // -// bool isInside = IsInsideDiff( -// jFVG, -// iOBFVG.ob, -// false // -// ); - -// // -// bool isPlacePassed = -// isInside || -// (isBullish -// ? isAbove -// : isBelow); -// if (!isPlacePassed) -// { -// // -// ZeroMemory(jFVG); -// continue; -// } - -// // -// Add( -// jFVG, -// tmpWorkingFVGs // -// ); -// } - -// // -// int fvgsCount = ArraySize(tmpWorkingFVGs); -// has = IsValidSize(fvgsCount); -// if (has) -// { -// // -// idx = -// isBullish -// ? GetLowest(tmpWorkingFVGs) -// : GetHighest(tmpWorkingFVGs); - -// // -// if (IsValidIndex(idx)) -// { -// // -// XCFVG *selectedFVG = tmpWorkingFVGs[idx]; - -// // -// iOBFVG.fvg = selectedFVG; - -// // -// bool isExists = FindIndex( -// idx, -// selectedFVG, -// tmpFVGs // -// ); -// if (isExists) -// { -// // -// ArrayRemove( -// tmpFVGs, -// idx, -// 1 // -// ); -// } -// } -// } -// Clean(tmpWorkingFVGs); - -// // -// bool isFVGPassed = iOBFVG.HasFVG(); -// if (!isFVGPassed) -// { -// // -// iOBFVG.Clean(); -// continue; -// } - -// // -// // Validate Model ... -// bool isValid = iOBFVG.IsValid(); -// if (!isValid) -// { -// // -// iOBFVG.Clean(); -// continue; -// } - -// // -// iOBFVG.UpdateTo(cTime); - -// // -// AddRef( -// iOBFVG, -// dest // -// ); - -// // -// iOBFVG.Clean(); -// } - -// // -// Clean(tmpOBFVGs); -// } - -// // -// // Detecting Other POI(s) ... -// has = HasChild(dest); -// bool canDetectPOIs = -// detectInsideOBPOIs || -// detectInsideFVGPOIs; -// if (has && -// canDetectPOIs) -// { -// // -// count = ArraySize(dest); -// for (int i = 0; i < count; i++) -// { -// // -// // Supply Zones ... -// has = stfState.HasSupplyZones(); -// if (has) -// { -// // -// for (int j = 0; j < stfState.CountSupplyZones(); j++) -// { -// // -// bool isInsideOB = IsInsideDiff( -// stfState.supplyZones[j], -// dest[i].ob // -// ); - -// // -// bool isInsideFVG = IsInsideDiff( -// stfState.supplyZones[j], -// dest[i].fvg // -// ); - -// // -// bool isInside = isInsideOB || -// isInsideFVG; -// if (isInside) -// { -// // -// bool isPassed = -// detectInsideOBPOIs -// ? isInsideOB -// : detectInsideFVGPOIs -// ? isInsideFVG -// : false; -// if (isPassed) -// { -// // -// isPassed = -// !applyFromFilterForPOIs -// ? isPassed -// : isInsideOB -// ? stfState.supplyZones[j].From() > dest[i].ob.From() -// : isInsideFVG -// ? stfState.supplyZones[j].From() > dest[i].fvg.From() -// : false; -// } - -// // -// if (isPassed) -// { -// // -// Add( -// stfState.supplyZones[j], -// dest[i].supplyZones // -// ); -// } -// } -// } -// } - -// // -// // Demand Zones ... -// has = stfState.HasDemandZones(); -// if (has) -// { -// // -// for (int j = 0; j < stfState.CountDemandZones(); j++) -// { -// // -// bool isInsideOB = IsInsideDiff( -// stfState.demandZones[j], -// dest[i].ob // -// ); - -// // -// bool isInsideFVG = IsInsideDiff( -// stfState.demandZones[j], -// dest[i].fvg // -// ); - -// // -// bool isInside = isInsideOB || -// isInsideFVG; -// if (isInside) -// { -// // -// bool isPassed = -// detectInsideOBPOIs -// ? isInsideOB -// : detectInsideFVGPOIs -// ? isInsideFVG -// : false; -// if (isPassed) -// { -// // -// isPassed = -// !applyFromFilterForPOIs -// ? isPassed -// : isInsideOB -// ? stfState.demandZones[j].From() > dest[i].ob.From() -// : isInsideFVG -// ? stfState.demandZones[j].From() > dest[i].fvg.From() -// : false; -// } - -// // -// if (isPassed) -// { -// // -// Add( -// stfState.demandZones[j], -// dest[i].demandZones // -// ); -// } -// } -// } -// } - -// // -// // Support Zones ... -// has = stfState.HasSupportZones(); -// if (has) -// { -// // -// for (int j = 0; j < stfState.CountSupportZones(); j++) -// { -// // -// bool isInsideOB = IsInsideDiff( -// stfState.supportZones[j], -// dest[i].ob // -// ); - -// // -// bool isInsideFVG = IsInsideDiff( -// stfState.supportZones[j], -// dest[i].fvg // -// ); - -// // -// bool isInside = isInsideOB || -// isInsideFVG; -// if (isInside) -// { -// // -// bool isPassed = -// detectInsideOBPOIs -// ? isInsideOB -// : detectInsideFVGPOIs -// ? isInsideFVG -// : false; -// if (isPassed) -// { -// // -// isPassed = -// !applyFromFilterForPOIs -// ? isPassed -// : isInsideOB -// ? stfState.supportZones[j].From() > dest[i].ob.From() -// : isInsideFVG -// ? stfState.supportZones[j].From() > dest[i].fvg.From() -// : false; -// } - -// // -// if (isPassed) -// { -// // -// Add( -// stfState.supportZones[j], -// dest[i].supportZones // -// ); -// } -// } -// } -// } - -// // -// // Resistance Zones ... -// has = stfState.HasResistanceZones(); -// if (has) -// { -// // -// for (int j = 0; j < stfState.CountResistanceZones(); j++) -// { -// // -// bool isInsideOB = IsInsideDiff( -// stfState.resistanceZones[j], -// dest[i].ob // -// ); - -// // -// bool isInsideFVG = IsInsideDiff( -// stfState.resistanceZones[j], -// dest[i].fvg // -// ); - -// // -// bool isInside = isInsideOB || -// isInsideFVG; -// if (isInside) -// { -// // -// bool isPassed = -// detectInsideOBPOIs -// ? isInsideOB -// : detectInsideFVGPOIs -// ? isInsideFVG -// : false; -// if (isPassed) -// { -// // -// isPassed = -// !applyFromFilterForPOIs -// ? isPassed -// : isInsideOB -// ? stfState.resistanceZones[j].From() > dest[i].ob.From() -// : isInsideFVG -// ? stfState.resistanceZones[j].From() > dest[i].fvg.From() -// : false; -// } - -// // -// if (isPassed) -// { -// // -// Add( -// stfState.resistanceZones[j], -// dest[i].resistanceZones // -// ); -// } -// } -// } -// } -// } -// } - -// // -// Clean(tmpOBs); -// Clean(tmpFVGs); -// Clean(tmpOBFVGs); - -// // -// result = ArraySize(dest); - -// // -// return result; -// } - -// /** -// * Find Highest Order Block of XOBFVG Collection ... -// * -// * @param source: XOBFVG Collection ... -// * -// * @return ( int ) -// */ -// int GetHighest( -// XOBFVG &source[] // -// ) -// { -// // -// int result = -1; - -// // -// int count = ArraySize(source); -// bool has = IsValidSize(count); -// if (!has) -// { -// return result; -// } - -// // -// XOBFVG item; -// for (int i = 0; i < count; i++) -// { -// // -// XOBFVG iOBFVG = source[i]; - -// // -// bool canSet = -// !item.IsValid() -// ? true -// : item.ob.Upper() < iOBFVG.ob.Upper(); -// if (canSet) -// { -// // -// item = iOBFVG; -// result = i; -// } - -// // -// iOBFVG.Clean(); -// } - -// // -// item.Clean(); - -// // -// return result; -// } - -// /** -// * Find Lowest Order Block of XOBFVG Collection ... -// * -// * @param source: XOBFVG Collection ... -// * -// * @return ( int ) -// */ -// int GetLowest( -// XOBFVG &source[] // -// ) -// { -// // -// int result = -1; - -// // -// int count = ArraySize(source); -// bool has = IsValidSize(count); -// if (!has) -// { -// return result; -// } - -// // -// XOBFVG item; -// for (int i = 0; i < count; i++) -// { -// // -// XOBFVG iOBFVG = source[i]; - -// // -// bool canSet = -// !item.IsValid() -// ? true -// : item.ob.Lower() > iOBFVG.ob.Lower(); -// if (canSet) -// { -// // -// item = iOBFVG; -// result = i; -// } - -// // -// iOBFVG.Clean(); -// } - -// // -// item.Clean(); - -// // -// return result; -// } - -// /** -// * Find Youngest Order Block of XOBFVG Collection ... -// * -// * @param source: XOBFVG Collection ... -// * -// * @return ( int ) -// */ -// int GetYoungest( -// XOBFVG &source[] // -// ) -// { -// // -// int result = -1; - -// // -// int count = ArraySize(source); -// bool has = IsValidSize(count); -// if (!has) -// { -// return result; -// } - -// // -// XOBFVG item; -// for (int i = 0; i < count; i++) -// { -// // -// XOBFVG iOBFVG = source[i]; - -// // -// bool canSet = -// !item.IsValid() -// ? true -// : item.ob.From() < iOBFVG.ob.From(); -// if (canSet) -// { -// // -// item = iOBFVG; -// result = i; -// } - -// // -// iOBFVG.Clean(); -// } - -// // -// item.Clean(); - -// // -// return result; -// } - -// /** -// * Find Oldest Order Block of XOBFVG Collection ... -// * -// * @param source: XOBFVG Collection ... -// * -// * @return ( int ) -// */ -// int GetOldest( -// XOBFVG &source[] // -// ) -// { -// // -// int result = -1; - -// // -// int count = ArraySize(source); -// bool has = IsValidSize(count); -// if (!has) -// { -// return result; -// } - -// // -// XOBFVG item; -// for (int i = 0; i < count; i++) -// { -// // -// XOBFVG iOBFVG = source[i]; - -// // -// bool canSet = -// !item.IsValid() -// ? true -// : item.ob.From() > iOBFVG.ob.From(); -// if (canSet) -// { -// // -// item = iOBFVG; -// result = i; -// } - -// // -// iOBFVG.Clean(); -// } - -// // -// item.Clean(); - -// // -// return result; -// } - -// /** -// * Sort XOBFVG Collection based on OB Place ... -// * -// * @param source: XOBFVG instance Collection ... -// * @param forDir: ENUM_X_DIRECTION member ... -// * @param ignoreInside: Specified Ignoring price inside in Sorting ... -// */ -// void Sort( -// XOBFVG &source[], -// ENUM_X_DIRECTION forDir, -// bool ignoreInside = true // -// ) -// { -// // -// int idx = -1; -// int count = 0; -// bool has = false; - -// // -// has = HasDirection(forDir); -// if (!has) -// { -// return; -// } - -// // -// bool isBullish = IsBullish(forDir); - -// // -// count = ArraySize(source); -// has = IsValidSize(count); -// if (!has) -// { -// return; -// } - -// // -// XOBFVG last; -// XOBFVG tmpItems[]; -// bool hasLast = false; -// while (HasChild(source)) -// { -// // -// if (!hasLast) -// { -// // -// idx = GetOldest(source); -// hasLast = IsValidIndex(idx); -// if (hasLast) -// { -// // -// last = source[idx]; -// ArrayRemove( -// source, -// idx, -// 1 // -// ); - -// // -// AddRef( -// last, -// tmpItems // -// ); -// } - -// // -// count = ArraySize(source); -// has = IsValidSize(count); -// if (!has) -// { -// // -// last.Clean(); -// break; -// } -// } -// if (!hasLast) -// { -// // -// last.Clean(); -// break; -// } - -// // -// XOBFVG item; -// idx = GetOldest(source); -// has = IsValidIndex(idx); -// if (!has) -// { -// // -// item.Clean(); -// last.Clean(); -// break; -// } -// item = source[idx]; -// ArrayRemove( -// source, -// idx, -// 1 // -// ); - -// // -// bool isAbove = IsAbove( -// item.ob, -// last.ob, -// ignoreInside // -// ); - -// // -// bool isBelow = IsBelow( -// item.ob, -// last.ob, -// ignoreInside // -// ); - -// // -// has = -// isBullish -// ? isAbove -// : isBelow; -// if (has) -// { -// // -// AddRef( -// item, -// tmpItems // -// ); - -// // -// last = item; -// hasLast = item.IsValid(); -// } -// } - -// // -// Clean(source); -// Copy( -// tmpItems, -// source // -// ); - -// // -// Clean(tmpItems); -// } - -// //