diff --git a/Documents/BKP/Test.mq5 b/Documents/BKP/Test.mq5 deleted file mode 100644 index 35310c1d..00000000 Binary files a/Documents/BKP/Test.mq5 and /dev/null differ diff --git a/Documents/BKP/tmpPOIS.mq5 b/Documents/BKP/tmpPOIS.mq5 deleted file mode 100644 index 62c9cda4..00000000 --- a/Documents/BKP/tmpPOIS.mq5 +++ /dev/null @@ -1,346 +0,0 @@ - // - // Detect Inside Zones ... - - // - XCFVG *insideFVG; - bool hasInsideFVG = false; - - // - XCOrderBlock *insideOB; - bool hasInsideOB = false; - - // - XCSupplyZone *insideSupply; - bool hasInsideSupply = false; - - // - XCDemandZone *insideDemand; - bool hasInsideDemand = false; - - // - XCSupportZone *insideSupport; - bool hasInsideSupport = false; - - // - XCResistanceZone *insideResistnce; - bool hasInsideResistance = false; - - // - // Detect PullBack ... - - // - ENUM_X_DIRECTION pullbackDir; - bool hasPullBack = mXWZBarAnalyser.HasPullBack( - pullbackDir, - iBar // - ); - bool hasBullishPullBack = - hasPullBack && - IsBullish(pullbackDir); - bool hasBearishPullBack = - hasPullBack && - IsBearish(pullbackDir); - - // - // Detect PinBar ... - - // - ENUM_X_DIRECTION pinBarDir; - bool hasPinBar = mXWZBarAnalyser.IsPinBar( - iBar, - pinBarDir, - 0 // - ); - bool hasBullishPinBar = - hasPinBar && - IsBullish(pinBarDir); - bool hasBearishPinBar = - hasPinBar && - IsBearish(pinBarDir); - - // - // Detect Order Block ... - - // - XOHCL obBar; - XCOrderBlock *ob; - ENUM_X_DIRECTION obDir; - bool hasOB = mXWZBarAnalyser.HasOrderBlock( - iBar, - 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 forDir = ob.GetDirection(); - - // - // Check OB Not Activated ... - XOHCL activationBar; - bool isObActivationBarBodyIn = false; - bool isActivated = ob.IsActivated( - forDir, - activationBar, - isObActivationBarBodyIn, - false, - _Period // - ); - - // - if (isActivated) - { - // - hasOB = false; - obBar.Clean(); - ZeroMemory(ob); - hasBullishOB = false; - hasBearishOB = false; - } - } - } - - // - if (hasBullishPinBar) - { - // - XCBarArrowObject *iObj; - bool isCreated = mXWZPOIDrawer - .CreateBarArrow( - iBar, - iObj, - X_PRICE_LOW, - 159, - clrAqua, - 3, - ANCHOR_BOTTOM, - "BULLPULL" // - ); - if (isCreated) - { - mXWZDrawnObjects.Add(iObj); - } - } - - // - if (hasBearishPinBar) - { - // - XCBarArrowObject *iObj; - bool isCreated = mXWZPOIDrawer - .CreateBarArrow( - iBar, - iObj, - X_PRICE_HIGH, - 159, - clrMagenta, - 3, - ANCHOR_TOP, - "BEARPULL" // - ); - if (isCreated) - { - mXWZDrawnObjects.Add(iObj); - } - } - - // - if (hasOB) - { - // - XCBaseObject *iObj; - bool isCreated = mXWZPOIDrawer.CreateOrderBlock( - ob, - iObj // - ); - if (isCreated) - { - mXWZDrawnObjects.Add(iObj); - } - } - - // - int idx = -1; - int count = 0; - bool has = false; - - // - ENUM_X_DIRECTION trend = - IsValid(lastBullishTrend) && - lastBullishTrend > lastBearishTrend - ? X_DIRECTION_BULLISH - : IsValid(lastBearishTrend) && - lastBearishTrend > lastBullishTrend - ? X_DIRECTION_BEARISH - : X_DIRECTION_NONE; - bool hasTrend = HasDirection(trend); - bool hasBullishTrend = hasTrend && - IsBullish(trend); - bool hasBearishTrend = hasTrend && - IsBearish(trend); - - // - // Order Block ... - has = hasBullishTrend; - if (has) - { - } - has = hasBearishTrend; - if (has) - { - } - - // - // Fair Value Gap ... - has = hasBullishTrend; - if (has) - { - } - has = hasBearishTrend; - if (has) - { - } - - // - // Supply Zone ... - has = hasBearishTrend; - if (has) - { - } - - // - // Resistance Zone ... - has = hasBearishTrend; - if (has) - { - } - - // - // Demand Zone ... - has = hasBullishTrend; - if (has) - { - } - - // - // Support Zone ... - has = hasBullishTrend; - if (has) - { - } - - // - // Draw Inside Zones ... - - // - if (hasInsideOB) - { - // - XCBaseObject *iObj; - bool isCreated = mXWZPOIDrawer - .CreateOrderBlock( - insideOB, - iObj // - ); - // - if (isCreated) - { - mXWZDrawnObjects.Add(iObj); - } - } - - // - if (hasInsideFVG) - { - // - XCBaseObject *iObj; - bool isCreated = mXWZPOIDrawer - .CreateFairValueGap( - insideFVG, - iObj // - ); - // - if (isCreated) - { - mXWZDrawnObjects.Add(iObj); - } - } - - // - if (hasInsideSupply) - { - // - XCSupplyZoneObject *iObj; - bool isCreated = mXWZPOIDrawer - .CreateSupplyZone( - insideSupply, - iObj // - ); - // - if (isCreated) - { - mXWZDrawnObjects.Add(iObj); - } - } - - // - if (hasInsideDemand) - { - // - XCDemandZoneObject *iObj; - bool isCreated = mXWZPOIDrawer - .CreateDemandZone( - insideDemand, - iObj // - ); - // - if (isCreated) - { - mXWZDrawnObjects.Add(iObj); - } - } - - // - if (hasInsideSupport) - { - // - XCSupportZoneObject *iObj; - bool isCreated = mXWZPOIDrawer - .CreateSupportZone( - insideSupport, - iObj // - ); - // - if (isCreated) - { - mXWZDrawnObjects.Add(iObj); - } - } - - // - if (hasInsideResistance) - { - // - XCResistanceZoneObject *iObj; - bool isCreated = mXWZPOIDrawer - .CreateResistanceZone( - insideResistnce, - iObj // - ); - // - if (isCreated) - { - mXWZDrawnObjects.Add(iObj); - } - } 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 a604caf4..00000000 --- a/Documents/BKP/x-121.smc.xwz.signal.class copy 2.mq5 +++ /dev/null @@ -1,2725 +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 ... - X121SMCStrategyXWZSignalConditions mConditions; - X121SMCStrategyXWZSignalConditions mConditionsCollection[]; - - // - // Constructor(s) ... - XCX121SMCXWZSignalDetector() - { - Init(); - } - - // - // Deconstructor ... - ~XCX121SMCXWZSignalDetector() - { - DeInit(); - } - - // - // - // - - // - // Detect Setup Conditions ... - bool DetectSignalSetup( - // - string _symbol, - ENUM_TIMEFRAMES _period, - // - 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; - - // - string symbol = _symbol; - ENUM_TIMEFRAMES period = _period; - - // - mConditions.symbol = symbol; - mConditions.period = period; - - // - double ask = GetAsk(symbol); - double bid = GetBid(symbol); - datetime cTime = TimeCurrent(); - double points = GetPoints(symbol); - - // - double target = 0; - - // - // Cycles Conditions ... - - // - // Decision ... - ENUM_XPOI_EVENTS decisionPoiEvents[]; - ENUM_X_CYCLE_EVENTS decisionCycleEvents[]; - X121SMCCycleConditions decisionConditions; - result = decisionCycleHelper.GetConditions( - decisionCycleEvents, - decisionPoiEvents, - decisionConditions, - zIndex, - loopback // - ); - if (!result) - { - // - mConditions.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) - { - // - mConditions.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) - { - // - mConditions.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) - { - // - mConditions.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 ... - - // - // Check Working Zone ... - bool hasWorkingZone = mConditions.HasWorkingZone(); - if (!hasWorkingZone) - { - // - hasWorkingZone = mConditions.ExtractWorkingZone( - visionState, - consolidationState, - analyseState, - zIndex // - ); - } - - // - result = hasWorkingZone; - if (!result) - { - // - Clean(visionPoiEvents); - Clean(analysePoiEvents); - Clean(decisionPoiEvents); - Clean(visionCycleEvents); - Clean(analyseCycleEvents); - Clean(decisionCycleEvents); - Clean(consolidationPoiEvents); - Clean(consolidationCycleEvents); - - // - visionState.Clean(); - analyseState.Clean(); - decisionState.Clean(); - visionConditions.Clean(); - analyseConditions.Clean(); - visionXConditions.Clean(); - consolidationState.Clean(); - decisionConditions.Clean(); - analyseXConditions.Clean(); - decisionXConditions.Clean(); - consolidationConditions.Clean(); - consolidationXConditions.Clean(); - - // - mConditions.Clean(); - - // - return result; - } - - // - mConditions.UpdateTo(cTime); - - // - // Check Working Zone still Alive ... - ENUM_X_DIRECTION destroyedDir = X_DIRECTION_NONE; - bool isWorkingZoneDestroyed = mConditions - .IsWorkingZoneDestroyed( - destroyedDir, - zIndex, - decisionState.period // - ); - if (isWorkingZoneDestroyed) - { - RemoveWorkingZoneDraws(); - } - - // - result = !isWorkingZoneDestroyed; - if (!result) - { - // - Clean(visionPoiEvents); - Clean(analysePoiEvents); - Clean(decisionPoiEvents); - Clean(visionCycleEvents); - Clean(analyseCycleEvents); - Clean(decisionCycleEvents); - Clean(consolidationPoiEvents); - Clean(consolidationCycleEvents); - - // - visionState.Clean(); - analyseState.Clean(); - decisionState.Clean(); - visionConditions.Clean(); - analyseConditions.Clean(); - visionXConditions.Clean(); - consolidationState.Clean(); - decisionConditions.Clean(); - analyseXConditions.Clean(); - decisionXConditions.Clean(); - consolidationConditions.Clean(); - consolidationXConditions.Clean(); - - // - mConditions.Clean(); - - // - return result; - } - - // - // Detecting Trend ... - ENUM_X_DIRECTION trend; - bool hasTrend = mConditions.DetectTrend( - trend, - period // - ); - bool hasBullishTrend = hasTrend && - IsBullish(trend); - bool hasBearishTrend = hasTrend && - IsBearish(trend); - result = hasTrend; - if (!result) - { - // - Clean(visionPoiEvents); - Clean(analysePoiEvents); - Clean(decisionPoiEvents); - Clean(visionCycleEvents); - Clean(analyseCycleEvents); - Clean(decisionCycleEvents); - Clean(consolidationPoiEvents); - Clean(consolidationCycleEvents); - - // - visionState.Clean(); - analyseState.Clean(); - decisionState.Clean(); - visionConditions.Clean(); - analyseConditions.Clean(); - visionXConditions.Clean(); - consolidationState.Clean(); - decisionConditions.Clean(); - analyseXConditions.Clean(); - decisionXConditions.Clean(); - consolidationConditions.Clean(); - consolidationXConditions.Clean(); - - // - mConditions.Clean(); - - // - return result; - } - - // - bool hasStartZone = mConditions.DetectStartZones( - trend, - consolidationState, - analyseState, - decisionState, - decisionCycleHelper // - ); - - // - mConditions.UpdateTo(cTime); - - // - // Detect Condition Priority ... - ENUM_X121SMC_XWZ_PRIORITY bullishPriority; - ENUM_X121SMC_XWZ_PRIORITY bearishPriority; - mConditions.DetectPriority( - bullishPriority, - bearishPriority // - ); - - // - bool canLookupLong = bullishPriority != X121SMC_XWZ_PRIORITY_NONE && - bullishPriority != X121SMC_XWZ_PRIORITY_WEAK; - bool canLookupShort = bearishPriority != X121SMC_XWZ_PRIORITY_NONE && - bearishPriority != X121SMC_XWZ_PRIORITY_WEAK; - bool isPriorityPassed = - hasBullishTrend - ? canLookupLong - : hasBearishTrend - ? canLookupShort - : false; - - // - // Here we are Make sure we have Correct: - // - WorkSpace ... - // - Trend ... - // - What we looking for: Long or Short ... - // - Priority ... - - // - double pivot = 0; - double point = 0; - ENUM_X_DIRECTION conditionsDir = X_DIRECTION_NONE; - - // - // Detect Start Zone Conditions ... - bool hasConditions = mConditions - .HasConditions( - pivot, - point, - conditionsDir, - decisionState, - zIndex, - decisionState.period // - ); - result = hasConditions; - if (!result) - { - // - Clean(visionPoiEvents); - Clean(analysePoiEvents); - Clean(decisionPoiEvents); - Clean(visionCycleEvents); - Clean(analyseCycleEvents); - Clean(decisionCycleEvents); - Clean(consolidationPoiEvents); - Clean(consolidationCycleEvents); - - // - visionState.Clean(); - analyseState.Clean(); - decisionState.Clean(); - visionConditions.Clean(); - analyseConditions.Clean(); - visionXConditions.Clean(); - consolidationState.Clean(); - decisionConditions.Clean(); - analyseXConditions.Clean(); - decisionXConditions.Clean(); - consolidationConditions.Clean(); - consolidationXConditions.Clean(); - - // - return result; - } - - // - isBullish = IsBullish(conditionsDir); - isBearish = IsBearish(conditionsDir); - - // - double reward; - double amountPercent; - ENUM_X121SMC_XWZ_PRIORITY priority = - isBullish - ? bullishPriority - : bearishPriority; - bool hasRewardAmount = CalculateRiskReward( - priority, - reward, - amountPercent // - ); - - // - // Apply Traget ... - switch (priority) - { - // - case X121SMC_XWZ_PRIORITY_STRONG_HIGH: - // - target = - isBullish - ? mConditions.workingZone.quarter3 - : mConditions.workingZone.quarter1; - break; - - // - case X121SMC_XWZ_PRIORITY_HIGH: - // - target = - isBullish - ? mConditions.workingZone.quarter3 - : mConditions.workingZone.quarter1; - break; - - // - case X121SMC_XWZ_PRIORITY_REGULAR: - // - target = - isBullish - ? mConditions.workingZone.quarter2 - : mConditions.workingZone.quarter2; - break; - - // - case X121SMC_XWZ_PRIORITY_LOW: - // - target = - isBullish - ? mConditions.workingZone.quarter1 - : mConditions.workingZone.quarter3; - break; - - // - default: - target = 0; - break; - } - - // - bool hasLastBullishConsolidationZone = false; - bool hasLastBearishConsolidationZone = false; - bool hasPrevBullishConsolidationZone = false; - bool hasPrevBearishConsolidationZone = false; - XConsolidationZone lastBullishConsolidationZone; - XConsolidationZone lastBearishConsolidationZone; - XConsolidationZone prevBullishConsolidationZone; - XConsolidationZone prevBearishConsolidationZone; - bool isLastBullishConsolidationZoneInsidePivot = false; - bool isPrevBullishConsolidationZoneInsidePivot = false; - bool isLastBearishConsolidationZoneInsidePivot = false; - bool isPrevBearishConsolidationZoneInsidePivot = false; - bool hasConsolidationZones = decisionCycleHelper.HasConsolidationZones(); - if (hasConsolidationZones) - { - // - int cZCount = 0; - XConsolidationZone tmp[]; - - // - cZCount = decisionCycleHelper - .FillConsolidationZones( - X_DIRECTION_BULLISH, - tmp // - ); - if (IsValidSize(cZCount)) - { - // - lastBullishConsolidationZone = tmp[cZCount - 1]; - if (cZCount >= 2) - { - prevBullishConsolidationZone = tmp[cZCount - 2]; - } - } - - // - Clean(tmp); - cZCount = decisionCycleHelper - .FillConsolidationZones( - X_DIRECTION_BEARISH, - tmp // - ); - if (IsValidSize(cZCount)) - { - // - lastBearishConsolidationZone = tmp[cZCount - 1]; - if (cZCount >= 2) - { - prevBearishConsolidationZone = tmp[cZCount - 2]; - } - } - - // - Clean(tmp); - - // - hasLastBullishConsolidationZone = lastBullishConsolidationZone.IsValid(); - hasLastBearishConsolidationZone = lastBearishConsolidationZone.IsValid(); - hasPrevBullishConsolidationZone = prevBullishConsolidationZone.IsValid(); - hasPrevBearishConsolidationZone = prevBearishConsolidationZone.IsValid(); - - // - isLastBullishConsolidationZoneInsidePivot = - // - hasLastBullishConsolidationZone && - (lastBullishConsolidationZone.lower < point && - lastBullishConsolidationZone.upper > pivot) - // - ; - isPrevBullishConsolidationZoneInsidePivot = - // - hasPrevBullishConsolidationZone && - (prevBullishConsolidationZone.lower < point && - prevBullishConsolidationZone.upper > pivot) - // - ; - - // - isLastBearishConsolidationZoneInsidePivot = - // - hasLastBearishConsolidationZone && - (lastBearishConsolidationZone.upper > point && - lastBearishConsolidationZone.lower < pivot) - // - ; - isPrevBearishConsolidationZoneInsidePivot = - // - hasPrevBearishConsolidationZone && - (prevBearishConsolidationZone.upper > point && - prevBearishConsolidationZone.lower < pivot) - // - ; - } - - // - bool isConsolidationZonePassed = - isBullish - // - ? (point > 0 && - pivot > 0 && - pivot < point && - hasPrevBullishConsolidationZone && - point > prevBullishConsolidationZone.upper && - (isLastBullishConsolidationZoneInsidePivot || - isPrevBullishConsolidationZoneInsidePivot)) - : (point > 0 && - pivot > 0 && - pivot > point && - hasPrevBearishConsolidationZone && - point < prevBearishConsolidationZone.lower && - (isLastBearishConsolidationZoneInsidePivot || - isPrevBearishConsolidationZoneInsidePivot)) - // - ; - - // - result = hasConditions && - hasRewardAmount && - isPriorityPassed && - trend == conditionsDir; // && - // isConsolidationZonePassed; - if (!result) - { - // - Clean(visionPoiEvents); - Clean(analysePoiEvents); - Clean(decisionPoiEvents); - Clean(visionCycleEvents); - Clean(analyseCycleEvents); - Clean(decisionCycleEvents); - Clean(consolidationPoiEvents); - Clean(consolidationCycleEvents); - - // - visionState.Clean(); - analyseState.Clean(); - decisionState.Clean(); - visionConditions.Clean(); - analyseConditions.Clean(); - visionXConditions.Clean(); - consolidationState.Clean(); - decisionConditions.Clean(); - analyseXConditions.Clean(); - decisionXConditions.Clean(); - consolidationConditions.Clean(); - consolidationXConditions.Clean(); - - // - lastBullishConsolidationZone.Clean(); - lastBearishConsolidationZone.Clean(); - prevBullishConsolidationZone.Clean(); - prevBearishConsolidationZone.Clean(); - - // - mConditions.Clean(); - - // - return result; - } - - // - mConditions.pivot = pivot; - mConditions.point = point; - mConditions.reward = reward; - mConditions.target = target; - mConditions.setupTime = cTime; - mConditions.priority = priority; - mConditions.dir = conditionsDir; - mConditions.amountPercent = amountPercent; - - // - mConditions.UpdateTo(cTime); - - // - Clean(visionPoiEvents); - Clean(analysePoiEvents); - Clean(decisionPoiEvents); - Clean(visionCycleEvents); - Clean(analyseCycleEvents); - Clean(decisionCycleEvents); - Clean(consolidationPoiEvents); - Clean(consolidationCycleEvents); - - // - visionState.Clean(); - analyseState.Clean(); - decisionState.Clean(); - visionConditions.Clean(); - analyseConditions.Clean(); - visionXConditions.Clean(); - consolidationState.Clean(); - decisionConditions.Clean(); - analyseXConditions.Clean(); - decisionXConditions.Clean(); - consolidationConditions.Clean(); - consolidationXConditions.Clean(); - - // - lastBullishConsolidationZone.Clean(); - lastBearishConsolidationZone.Clean(); - prevBullishConsolidationZone.Clean(); - prevBearishConsolidationZone.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; - - // - string symbol = _symbol; - ENUM_TIMEFRAMES period = _period; - - // - XOHCL zBar; - result = decisionCycleHelper.GetBar( - zBar, - zIndex // - ); - if (!result) - { - return result; - } - - // - XOHCL cBar; - result = decisionCycleHelper.GetBar( - cBar, - cIndex // - ); - if (!result) - { - return result; - } - - // - XOHCL pBar; - result = decisionCycleHelper.GetBar( - pBar, - pIndex // - ); - if (!result) - { - return result; - } - - // - double ask = GetAsk(symbol); - double bid = GetBid(symbol); - datetime cTime = TimeCurrent(); - double points = GetPoints(symbol); - - // - int swingLoopback = 9; - double ll = cBar.FindLowest(swingLoopback, MODE_LOW); - double hh = cBar.FindHighest(swingLoopback, MODE_HIGH); - double llDown = cBar.FindLowesttDown(swingLoopback); - double hhUp = cBar.FindHighestUp(swingLoopback); - - // - // 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 ... - zBar.Clean(); - cBar.Clean(); - pBar.Clean(); - - // - Clean(decisionPoiEvents); - Clean(decisionCycleEvents); - - // - decisionConditions.Clean(); - - // - return result; - } - - // - // Cycles POI States ... - XPOIState decisionState = decisionConditions.state; - - // - // Cycle X121Conditions ... - X121Conditions decisionXConditions = decisionConditions.x121Conditions; - - // - // Trigger Conditions ... - - // - double point = conditions.point; - bool isPointBreaked = IsBarBreak( - point, - setupDir, - cBar // - ); - - // - // Summary ... - - // - isBullish = - // - isBullish && - isPointBreaked && - cBar.IsBullish() - // - ; - - // - isBearish = - // - isBearish && - isPointBreaked && - cBar.IsBearish() - // - ; - - // - result = isBullish || - isBearish; - if (!result) - { - // - // Cleanup Setup Conditions ... - int setupAge = conditions.GetSetupAge(); - if (IsValidSize(setupAge) && - IsValidSize(maxAllowedSetupAge) && - setupAge >= maxAllowedSetupAge) - { - conditions.Clean(); - } - - // - // Cleanup ... - zBar.Clean(); - cBar.Clean(); - pBar.Clean(); - - // - Clean(decisionPoiEvents); - Clean(decisionCycleEvents); - - // - decisionState.Clean(); - decisionConditions.Clean(); - decisionXConditions.Clean(); - - // - return result; - } - - // - // Detect Nearest Pivot Point ... - - // - double entry = GetEntry( - conditions.symbol, - setupDir // - ); - - // - // Manipulate SL Based on Consolidation Zones ... - - // - double sls[]; - Add( - conditions.pivot, - sls // - ); - - // - // TODO: Add Consolidation Zone for SLs ... - - // - double iAtr = decisionXConditions.atrBuffer[1]; - iAtr *= 2; - - // - 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; - - // - // Cleanup ... - zBar.Clean(); - cBar.Clean(); - pBar.Clean(); - - // - Clean(decisionPoiEvents); - Clean(decisionCycleEvents); - - // - decisionState.Clean(); - decisionConditions.Clean(); - decisionXConditions.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 - // - ; - - // - result = isCycleHelpersValid; - if (!result) - { - return result; - } - - // - int count = ArraySize(positions); - result = IsValidSize(count); - if (!result) - { - return result; - } - - // - string symbol = decisionCycleHelper.GetSymbol(); - ENUM_TIMEFRAMES period = decisionCycleHelper.GetPeriod(); - 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 ... - - // - XBoxZone lastBullishBox; - XBoxZone prevLastBullishBox; - bool hasLastBullishBox = false; - bool hasPrevLastBullishBox = false; - XConsolidationZone lastBullishZone; - bool isLastBullishAbovePrev = false; - bool isLastBullishBelowPrev = false; - XConsolidationZone prevLastBullishZone; - - // - XBoxZone lastBearishBox; - XBoxZone prevLastBearishBox; - bool hasLastBearishBox = false; - bool hasPrevLastBearishBox = false; - XConsolidationZone lastBearishZone; - bool isLastBearishAbovePrev = false; - bool isLastBearishBelowPrev = false; - XConsolidationZone prevLastBearishZone; - - // - int bullishConsolidationZonesCount = 0; - int bearishConsolidationZonesCount = 0; - bool hasBullishConsolidationZones = false; - bool hasBearishConsolidationZones = false; - XConsolidationZone bullishConsolidationZones[]; - XConsolidationZone bearishConsolidationZones[]; - bool hasConsolidationZones = decisionCycleHelper.HasConsolidationZones(); - int consolidationZonesCount = decisionCycleHelper.CountConsolidationZones(); - if (hasConsolidationZones) - { - // - bullishConsolidationZonesCount = decisionCycleHelper - .FillConsolidationZones( - X_DIRECTION_BULLISH, - bullishConsolidationZones // - ); - hasBullishConsolidationZones = IsValidSize(bullishConsolidationZonesCount); - - // - bearishConsolidationZonesCount = decisionCycleHelper - .FillConsolidationZones( - X_DIRECTION_BEARISH, - bearishConsolidationZones // - ); - hasBearishConsolidationZones = IsValidSize(bearishConsolidationZonesCount); - - // - // - // - - // - if (hasBullishConsolidationZones && - bullishConsolidationZonesCount >= 2) - { - // - lastBullishZone = bullishConsolidationZones[bullishConsolidationZonesCount - 1]; - prevLastBullishZone = bullishConsolidationZones[bullishConsolidationZonesCount - 2]; - - // - hasLastBullishBox = ToBox( - lastBullishBox, - lastBullishZone // - ); - hasPrevLastBullishBox = ToBox( - prevLastBullishBox, - prevLastBullishZone // - ); - - // - isLastBullishAbovePrev = hasLastBullishBox && - hasPrevLastBullishBox && - IsBoxAbove( - lastBullishBox, - prevLastBullishBox // - ); - - // - isLastBullishBelowPrev = hasLastBullishBox && - hasPrevLastBullishBox && - IsBoxBelow( - lastBullishBox, - prevLastBullishBox // - ); - } - - // - if (hasBearishConsolidationZones && - bearishConsolidationZonesCount >= 2) - { - // - lastBearishZone = bearishConsolidationZones[bearishConsolidationZonesCount - 1]; - prevLastBearishZone = bearishConsolidationZones[bearishConsolidationZonesCount - 2]; - - // - hasLastBearishBox = ToBox( - lastBearishBox, - lastBearishZone // - ); - hasPrevLastBearishBox = ToBox( - prevLastBearishBox, - prevLastBearishZone // - ); - - // - isLastBearishAbovePrev = hasLastBearishBox && - hasPrevLastBearishBox && - IsBoxAbove( - lastBearishBox, - prevLastBearishBox // - ); - - // - isLastBearishBelowPrev = hasLastBearishBox && - hasPrevLastBearishBox && - IsBoxBelow( - lastBearishBox, - prevLastBearishBox // - ); - } - - // - } - - // - // 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 isStrongSwingLowAboveLastBullishBox = - isStrongSwingLow && - hasLastBullishBox && - pBar.low > lastBullishBox.upper; - - // - bool isStrongSwingHighBelowLastBearishBox = - isStrongSwingHigh && - hasLastBearishBox && - pBar.high < lastBearishBox.lower; - - // - // 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 ... - - // - // 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(); - - // - lastBullishBox.Clean(); - lastBearishBox.Clean(); - lastBullishZone.Clean(); - lastBearishZone.Clean(); - prevLastBullishBox.Clean(); - prevLastBearishBox.Clean(); - prevLastBullishZone.Clean(); - prevLastBearishZone.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; - } - - // - // Draw Functions ... - // - - // - void RemoveDraws() - { - mObjects.Clear(); - } - - // - void RemoveWorkingZoneDraws() - { - mWorkingZoneObjects.Clear(); - } - - // - void DrawOrderBlock( - XCOrderBlock *ob, - XCPOIDrawer *drawer, - bool forWorkingZone = false // - ) - { - // - if (ob == NULL || - drawer == NULL) - { - return; - } - - // - ENUM_X_DIRECTION forDir = ob.GetDirection(); - - // - color bullishColor = drawer.BarBullishColor(); - color bearishColor = drawer.BarBearishColor(); - color forColor = IsBullish(forDir) - ? bullishColor - : bearishColor; - - // - // Draw Order Block ... - XCBaseObject *obj; - bool isCreated = drawer.CreateOrderBlock( - ob, - obj // - ); - if (isCreated) - { - // - if (forWorkingZone) - { - mWorkingZoneObjects.Add(obj); - } - else - { - mObjects.Add(obj); - } - } - - // - ulong chartID = drawer.ChartIdentification(); - int subWindow = drawer.SubWindowIdentification(); - - // - XOHCL startedBar; - ENUM_X_DIRECTION startedDir; - bool isStarted = ob.IsStarted( - forDir, - startedBar, - startedDir // - ); - if (isStarted) - { - // - datetime to = startedBar.time + (PeriodSeconds(startedBar.period)); - - // - XCOHCLObject *obj; - bool isCreated = drawer.CreateBar( - startedBar, - obj, - to // - ); - if (isCreated) - { - // - obj.BodyColor(clrYellow); - obj.HighShadowColor(clrYellow); - obj.LowShadowColor(clrYellow); - - // - obj.BodyStyle(STYLE_SOLID); - obj.HighShadowStyle(STYLE_SOLID); - obj.LowShadowStyle(STYLE_SOLID); - - // - if (forWorkingZone) - { - mWorkingZoneObjects.Add(obj); - } - else - { - mObjects.Add(obj); - } - } - - // - string startVLineName = "Start_" + ob.GetTag(); - - // - CChartObjectVLine *startVLine; - startVLine = new CChartObjectVLine(); - isCreated = startVLine.Create( - chartID, - startVLineName, - subWindow, - startedBar.time // - ); - if (isCreated) - { - // - startVLine.Color(forColor); - - // - if (forWorkingZone) - { - mWorkingZoneObjects.Add(startVLine); - } - else - { - mObjects.Add(startVLine); - } - } - } - } - - // - void DrawFairValueGap( - XCFVG *fvg, - XCPOIDrawer *drawer, - bool forWorkingZone = false // - ) - { - // - if (fvg == NULL || - drawer == NULL) - { - return; - } - - // - ENUM_X_DIRECTION forDir = fvg.GetDirection(); - - // - color bullishColor = drawer.BarBullishColor(); - color bearishColor = drawer.BarBearishColor(); - color forColor = IsBullish(forDir) - ? bullishColor - : bearishColor; - - // - // Draw Order Block ... - XCBaseObject *obj; - bool isCreated = drawer.CreateFairValueGap( - fvg, - obj // - ); - if (isCreated) - { - // - if (forWorkingZone) - { - mWorkingZoneObjects.Add(obj); - } - else - { - mObjects.Add(obj); - } - } - - // - ulong chartID = drawer.ChartIdentification(); - int subWindow = drawer.SubWindowIdentification(); - - // - XOHCL startedBar; - ENUM_X_DIRECTION startedDir; - bool isStarted = fvg.IsStarted( - forDir, - startedBar, - startedDir // - ); - if (isStarted) - { - // - datetime to = startedBar.time + (PeriodSeconds(startedBar.period)); - - // - XCOHCLObject *obj; - bool isCreated = drawer.CreateBar( - startedBar, - obj, - to // - ); - if (isCreated) - { - // - obj.BodyColor(clrYellow); - obj.HighShadowColor(clrYellow); - obj.LowShadowColor(clrYellow); - - // - obj.BodyStyle(STYLE_SOLID); - obj.HighShadowStyle(STYLE_SOLID); - obj.LowShadowStyle(STYLE_SOLID); - - // - if (forWorkingZone) - { - mWorkingZoneObjects.Add(obj); - } - else - { - mObjects.Add(obj); - } - } - - // - string startVLineName = "Start_" + fvg.GetTag(); - - // - CChartObjectVLine *startVLine; - startVLine = new CChartObjectVLine(); - isCreated = startVLine.Create( - chartID, - startVLineName, - subWindow, - startedBar.time // - ); - if (isCreated) - { - // - startVLine.Color(forColor); - - // - if (forWorkingZone) - { - mWorkingZoneObjects.Add(startVLine); - } - else - { - mObjects.Add(startVLine); - } - } - } - } - - // - void DrawWorkingZone( - X121SMCStrategyXWZSignalConditions &conditions, - XCPOIDrawer *drawer // - ) - { - // - if (drawer == NULL) - { - return; - } - - // - bool hasWorkingZone = conditions.HasWorkingZone(); - if (!hasWorkingZone) - { - return; - } - - // - string prefix = "WKZ_" + conditions.workingZone.symbol + ToString(conditions.workingZone.period) + "_"; - string tag = prefix + ToString(conditions.workingZone.upper) + "_" + ToString(conditions.workingZone.lower); - string suffix = ToMD5(tag); - - // - string upperName = prefix + "_Upper_" + suffix; - string lowerName = prefix + "_Lower_" + suffix; - string zoneUpperName = prefix + "_ZoneUpper_" + suffix; - string zoneLowerName = prefix + "_ZoneLower_" + suffix; - - // - string q1Name = prefix + "_Q1_" + suffix; - string q2Name = prefix + "_Q2_" + suffix; - string q3Name = prefix + "_Q3_" + suffix; - - // - ulong chartID = drawer.ChartIdentification(); - int subWindow = drawer.SubWindowIdentification(); - - // - bool isCreated = false; - - // - // Check For Trend Approced ... - bool isTrendApproved = conditions.HasOrderBlock() && - conditions.HasFairValueGap(); - if (isTrendApproved) - { - // - DrawOrderBlock( - conditions.orderBlock, - drawer, - true // - ); - - // - DrawFairValueGap( - conditions.fairValueGap, - drawer, - true // - ); - } - - // - XCSupplyZoneObject *iSupObj; - isCreated = drawer.CreateSupplyZone( - conditions.supplyZone, - iSupObj // - ); - if (isCreated) - { - mWorkingZoneObjects.Add(iSupObj); - } - - // - XCDemandZoneObject *iDemObj; - isCreated = drawer.CreateDemandZone( - conditions.demandZone, - iDemObj // - ); - if (isCreated) - { - mWorkingZoneObjects.Add(iDemObj); - } - - // - // Lower ... - CChartObjectTrend *lowerHLine; - lowerHLine = new CChartObjectTrend(); - isCreated = lowerHLine.Create( - chartID, - lowerName, - subWindow, - conditions.workingZone.from, - conditions.workingZone.lower, - conditions.workingZone.to, - conditions.workingZone.lower // - ); - if (isCreated) - { - // - lowerHLine.Color(clrLime); - mWorkingZoneObjects.Add(lowerHLine); - } - - // - CChartObjectTrend *upperHLine; - upperHLine = new CChartObjectTrend(); - isCreated = upperHLine.Create( - chartID, - upperName, - subWindow, - conditions.workingZone.from, - conditions.workingZone.upper, - conditions.workingZone.to, - conditions.workingZone.upper // - ); - if (isCreated) - { - // - upperHLine.Color(clrLime); - mWorkingZoneObjects.Add(upperHLine); - } - - // - CChartObjectTrend *zoneLowerHLine; - zoneLowerHLine = new CChartObjectTrend(); - isCreated = zoneLowerHLine.Create( - chartID, - zoneLowerName, - subWindow, - conditions.workingZone.from, - conditions.workingZone.zoneLower, - conditions.workingZone.to, - conditions.workingZone.zoneLower // - ); - if (isCreated) - { - // - zoneLowerHLine.Color(clrRed); - mWorkingZoneObjects.Add(zoneLowerHLine); - } - - // - CChartObjectTrend *zoneUpperHLine; - zoneUpperHLine = new CChartObjectTrend(); - isCreated = zoneUpperHLine.Create( - chartID, - zoneUpperName, - subWindow, - conditions.workingZone.from, - conditions.workingZone.zoneUpper, - conditions.workingZone.to, - conditions.workingZone.zoneUpper // - ); - if (isCreated) - { - // - zoneUpperHLine.Color(clrRed); - mWorkingZoneObjects.Add(zoneUpperHLine); - } - - // - CChartObjectTrend *quarter1HLine; - quarter1HLine = new CChartObjectTrend(); - isCreated = quarter1HLine.Create( - chartID, - q1Name, - subWindow, - conditions.workingZone.from, - conditions.workingZone.quarter1, - conditions.workingZone.to, - conditions.workingZone.quarter1 // - ); - if (isCreated) - { - // - quarter1HLine.Color(clrYellow); - mWorkingZoneObjects.Add(quarter1HLine); - } - - // - CChartObjectTrend *quarter2HLine; - quarter2HLine = new CChartObjectTrend(); - isCreated = quarter2HLine.Create( - chartID, - q2Name, - subWindow, - conditions.workingZone.from, - conditions.workingZone.quarter2, - conditions.workingZone.to, - conditions.workingZone.quarter2 // - ); - if (isCreated) - { - // - quarter2HLine.Color(clrYellow); - mWorkingZoneObjects.Add(quarter2HLine); - } - - // - CChartObjectTrend *quarter3HLine; - quarter3HLine = new CChartObjectTrend(); - isCreated = quarter3HLine.Create( - chartID, - q3Name, - subWindow, - conditions.workingZone.from, - conditions.workingZone.quarter3, - conditions.workingZone.to, - conditions.workingZone.quarter3 // - ); - if (isCreated) - { - // - quarter3HLine.Color(clrYellow); - mWorkingZoneObjects.Add(quarter3HLine); - } - - // - } - - // - void DrawConditions( - X121SMCStrategyXWZSignalConditions &conditions, - XCPOIDrawer *drawer, - bool forceClean = false // - ) - { - // - if (drawer == NULL) - { - return; - } - - // - if (forceClean) - { - mObjects.Clear(); - } - - // - bool isCreated = false; - - // - ulong chartID = drawer.ChartIdentification(); - int subWindow = drawer.SubWindowIdentification(); - color bullishColor = drawer.BarBullishColor(); - color bearishColor = drawer.BarBearishColor(); - - // - // Start Zones ... - bool hasStartZones = conditions.HasStartZones(); - if (hasStartZones) - { - // - int count = conditions.CountStartZones(); - for (int i = 0; i < count; i++) - { - // - bool isBullish = conditions.startZones[i].IsBullish(); - - // - bool hasOB = conditions.startZones[i].HasOB(); - if (hasOB) - { - // // - // XCBaseObject *iObj; - // isCreated = drawer.CreateOrderBlock( - // conditions.startZones[i].ob, - // iObj // - // ); - - // // - // if (isCreated) - // { - // mObjects.Add(iObj); - // } - - // - DrawOrderBlock( - conditions.startZones[i].ob, - drawer // - ); - } - - // - bool hasFVG = conditions.startZones[i].HasFVG(); - if (hasFVG) - { - // // - // XCBaseObject *iObj; - // isCreated = drawer.CreateFairValueGap( - // conditions.startZones[i].fvg, - // iObj // - // ); - - // // - // if (isCreated) - // { - // mObjects.Add(iObj); - // } - - // - DrawFairValueGap( - conditions.startZones[i].fvg, - drawer // - ); - } - - // // - // bool hasSupply = conditions.startZones[i].HasSupply(); - // if (hasSupply) - // { - // // - // XCSupplyZoneObject *iObj; - // isCreated = drawer.CreateSupplyZone( - // conditions.startZones[i].supply, - // iObj // - // ); - - // // - // if (isCreated) - // { - // mObjects.Add(iObj); - // } - // } - - // // - // bool hasDemand = conditions.startZones[i].HasDemand(); - // if (hasDemand) - // { - // // - // XCDemandZoneObject *iObj; - // isCreated = drawer.CreateDemandZone( - // conditions.startZones[i].demand, - // iObj // - // ); - - // // - // if (isCreated) - // { - // mObjects.Add(iObj); - // } - // } - - // // - // bool hasSupport = conditions.startZones[i].HasSupport(); - // if (hasSupport) - // { - // // - // XCSupportZoneObject *iObj; - // isCreated = drawer.CreateSupportZone( - // conditions.startZones[i].support, - // iObj // - // ); - - // // - // if (isCreated) - // { - // mObjects.Add(iObj); - // } - // } - - // // - // bool hasResistance = conditions.startZones[i].HasResistance(); - // if (hasResistance) - // { - // // - // XCResistanceZoneObject *iObj; - // isCreated = drawer.CreateResistanceZone( - // conditions.startZones[i].resistance, - // iObj // - // ); - - // // - // if (isCreated) - // { - // mObjects.Add(iObj); - // } - // } - - // - // - // - - // - string bName = ""; - int arrowCode = 0; - string bSuffix = ""; - color arrowColor = clrNONE; - ENUM_X_PRICE bPrice = X_PRICE_CLOSE; - - // - bool hasSwingBar = conditions.startZones[i].swingBar.IsValid(); - if (hasSwingBar) - { - // - bSuffix = ToMD5(conditions.startZones[i].swingBar.GetTag()); - bName = - (isBullish - ? "SWING_LOW" - : "SWING_HIGH") + - "_" + bSuffix; - arrowCode = 159; - arrowColor = - isBullish - ? bullishColor - : bearishColor; - bPrice = - isBullish - ? X_PRICE_LOW - : X_PRICE_HIGH; - - // - XCBarArrowObject *iObj; - iObj = new XCBarArrowObject(); - isCreated = iObj.CreateByBar( - chartID, - bName, - subWindow, - arrowCode, - conditions.startZones[i].swingBar, - bPrice // - ); - if (isCreated) - { - // - iObj.ArrowColor(arrowColor); - - // - mObjects.Add(iObj); - } - } - - // - bool hasBreakerBar = conditions.startZones[i].breakerBar.IsValid(); - if (hasBreakerBar) - { - // - bSuffix = ToMD5(conditions.startZones[i].breakerBar.GetTag()); - bName = - (isBullish - ? "BULL_BREAKER" - : "BEAR_BREAKER") + - "_" + bSuffix; - arrowCode = - isBullish - ? 71 - : 72; - arrowColor = - isBullish - ? bullishColor - : bearishColor; - bPrice = - isBullish - ? X_PRICE_LOW - : X_PRICE_HIGH; - - // - XCBarArrowObject *iObj; - iObj = new XCBarArrowObject(); - isCreated = iObj.CreateByBar( - chartID, - bName, - subWindow, - arrowCode, - conditions.startZones[i].breakerBar, - bPrice // - ); - if (isCreated) - { - // - iObj.ArrowColor(arrowColor); - - // - mObjects.Add(iObj); - } - } - - // - bool hasMomentumBar = conditions.startZones[i].momentumBar.IsValid(); - if (hasMomentumBar) - { - // - bSuffix = ToMD5(conditions.startZones[i].momentumBar.GetTag()); - bName = - (isBullish - ? "BULL_MOMENTUM" - : "BEAR_MOMENTUM") + - "_" + bSuffix; - arrowCode = - isBullish - ? 233 - : 234; - arrowColor = - isBullish - ? bullishColor - : bearishColor; - bPrice = - isBullish - ? X_PRICE_LOW - : X_PRICE_HIGH; - - // - XCBarArrowObject *iObj; - iObj = new XCBarArrowObject(); - isCreated = iObj.CreateByBar( - chartID, - bName, - subWindow, - arrowCode, - conditions.startZones[i].momentumBar, - bPrice // - ); - if (isCreated) - { - // - iObj.ArrowColor(arrowColor); - - // - mObjects.Add(iObj); - } - } - - // - bool hasRejectionBar = conditions.startZones[i].rejectionBar.IsValid(); - if (hasRejectionBar) - { - // - bSuffix = ToMD5(conditions.startZones[i].rejectionBar.GetTag()); - bName = - (isBullish - ? "BULL_REJECTION" - : "BEAR_REJECTION") + - "_" + bSuffix; - arrowCode = - isBullish - ? 241 - : 242; - arrowColor = - isBullish - ? bullishColor - : bearishColor; - bPrice = - isBullish - ? X_PRICE_LOW - : X_PRICE_HIGH; - - // - XCBarArrowObject *iObj; - iObj = new XCBarArrowObject(); - isCreated = iObj.CreateByBar( - chartID, - bName, - subWindow, - arrowCode, - conditions.startZones[i].rejectionBar, - bPrice // - ); - if (isCreated) - { - // - iObj.ArrowColor(arrowColor); - - // - mObjects.Add(iObj); - } - } - - // - bool hasAppliedBox = conditions.startZones[i].appliedBox.IsValid(); - if (hasAppliedBox) - { - // - arrowColor = - IsBullish(conditions.startZones[i].appliedBox.dir) - ? bullishColor - : bearishColor; - - // - XCBoxObject *iObj; - isCreated = drawer.CreateBox( - conditions.startZones[i].appliedBox, - iObj // - ); - - // - if (isCreated) - { - // - iObj.BoxWidth(2); - iObj.BoxColor(arrowColor); - - // - mObjects.Add(iObj); - } - } - } - } - } - - // - protected: - // - - // - private: - // - // Props ... - CArrayObj mObjects; - CArrayObj mWorkingZoneObjects; - - /** - * Initialize ... - */ - void Init() - { - } - - /** - * DeInitialize ... - */ - void DeInit() - { - // - RemoveDraws(); - mConditions.Clean(); - RemoveWorkingZoneDraws(); - Clean(mConditionsCollection); - } - - // - // 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 485360b1..00000000 --- a/Documents/BKP/x-121.smc.xwz.signal.class copy.mq5 +++ /dev/null @@ -1,2725 +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 ... - X121SMCStrategyXWZSignalConditions mConditions; - X121SMCStrategyXWZSignalConditions mConditionsCollection[]; - - // - // Constructor(s) ... - XCX121SMCXWZSignalDetector() - { - Init(); - } - - // - // Deconstructor ... - ~XCX121SMCXWZSignalDetector() - { - DeInit(); - } - - // - // - // - - // - // Detect Setup Conditions ... - bool DetectSignalSetup( - // - string _symbol, - ENUM_TIMEFRAMES _period, - // - 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; - - // - string symbol = _symbol; - ENUM_TIMEFRAMES period = _period; - - // - mConditions.symbol = symbol; - mConditions.period = period; - - // - double ask = GetAsk(symbol); - double bid = GetBid(symbol); - datetime cTime = TimeCurrent(); - double points = GetPoints(symbol); - - // - double target = 0; - - // - // Cycles Conditions ... - - // - // Decision ... - ENUM_XPOI_EVENTS decisionPoiEvents[]; - ENUM_X_CYCLE_EVENTS decisionCycleEvents[]; - X121SMCCycleConditions decisionConditions; - result = decisionCycleHelper.GetConditions( - decisionCycleEvents, - decisionPoiEvents, - decisionConditions, - zIndex, - loopback // - ); - if (!result) - { - // - mConditions.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) - { - // - mConditions.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) - { - // - mConditions.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) - { - // - mConditions.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 ... - - // - // Check Working Zone ... - bool hasWorkingZone = mConditions.HasWorkingZone(); - if (!hasWorkingZone) - { - // - hasWorkingZone = mConditions.ExtractWorkingZone( - visionState, - consolidationState, - analyseState, - zIndex // - ); - } - - // - result = hasWorkingZone; - if (!result) - { - // - Clean(visionPoiEvents); - Clean(analysePoiEvents); - Clean(decisionPoiEvents); - Clean(visionCycleEvents); - Clean(analyseCycleEvents); - Clean(decisionCycleEvents); - Clean(consolidationPoiEvents); - Clean(consolidationCycleEvents); - - // - visionState.Clean(); - analyseState.Clean(); - decisionState.Clean(); - visionConditions.Clean(); - analyseConditions.Clean(); - visionXConditions.Clean(); - consolidationState.Clean(); - decisionConditions.Clean(); - analyseXConditions.Clean(); - decisionXConditions.Clean(); - consolidationConditions.Clean(); - consolidationXConditions.Clean(); - - // - mConditions.Clean(); - - // - return result; - } - - // - mConditions.UpdateTo(cTime); - - // - // Check Working Zone still Alive ... - ENUM_X_DIRECTION destroyedDir = X_DIRECTION_NONE; - bool isWorkingZoneDestroyed = mConditions - .IsWorkingZoneDestroyed( - destroyedDir, - zIndex, - decisionState.period // - ); - if (isWorkingZoneDestroyed) - { - RemoveWorkingZoneDraws(); - } - - // - result = !isWorkingZoneDestroyed; - if (!result) - { - // - Clean(visionPoiEvents); - Clean(analysePoiEvents); - Clean(decisionPoiEvents); - Clean(visionCycleEvents); - Clean(analyseCycleEvents); - Clean(decisionCycleEvents); - Clean(consolidationPoiEvents); - Clean(consolidationCycleEvents); - - // - visionState.Clean(); - analyseState.Clean(); - decisionState.Clean(); - visionConditions.Clean(); - analyseConditions.Clean(); - visionXConditions.Clean(); - consolidationState.Clean(); - decisionConditions.Clean(); - analyseXConditions.Clean(); - decisionXConditions.Clean(); - consolidationConditions.Clean(); - consolidationXConditions.Clean(); - - // - mConditions.Clean(); - - // - return result; - } - - // - // Detecting Trend ... - ENUM_X_DIRECTION trend; - bool hasTrend = mConditions.DetectTrend( - trend, - period // - ); - bool hasBullishTrend = hasTrend && - IsBullish(trend); - bool hasBearishTrend = hasTrend && - IsBearish(trend); - result = hasTrend; - if (!result) - { - // - Clean(visionPoiEvents); - Clean(analysePoiEvents); - Clean(decisionPoiEvents); - Clean(visionCycleEvents); - Clean(analyseCycleEvents); - Clean(decisionCycleEvents); - Clean(consolidationPoiEvents); - Clean(consolidationCycleEvents); - - // - visionState.Clean(); - analyseState.Clean(); - decisionState.Clean(); - visionConditions.Clean(); - analyseConditions.Clean(); - visionXConditions.Clean(); - consolidationState.Clean(); - decisionConditions.Clean(); - analyseXConditions.Clean(); - decisionXConditions.Clean(); - consolidationConditions.Clean(); - consolidationXConditions.Clean(); - - // - mConditions.Clean(); - - // - return result; - } - - // - bool hasStartZone = mConditions.DetectStartZones( - trend, - analyseState, - analyseState, - decisionState, - decisionCycleHelper // - ); - - // - mConditions.UpdateTo(cTime); - - // - // Detect Condition Priority ... - ENUM_X121SMC_XWZ_PRIORITY bullishPriority; - ENUM_X121SMC_XWZ_PRIORITY bearishPriority; - mConditions.DetectPriority( - bullishPriority, - bearishPriority // - ); - - // - bool canLookupLong = bullishPriority != X121SMC_XWZ_PRIORITY_NONE && - bullishPriority != X121SMC_XWZ_PRIORITY_WEAK; - bool canLookupShort = bearishPriority != X121SMC_XWZ_PRIORITY_NONE && - bearishPriority != X121SMC_XWZ_PRIORITY_WEAK; - bool isPriorityPassed = - hasBullishTrend - ? canLookupLong - : hasBearishTrend - ? canLookupShort - : false; - - // - // Here we are Make sure we have Correct: - // - WorkSpace ... - // - Trend ... - // - What we looking for: Long or Short ... - // - Priority ... - - // - double pivot = 0; - double point = 0; - ENUM_X_DIRECTION conditionsDir = X_DIRECTION_NONE; - - // - // Detect Start Zone Conditions ... - bool hasConditions = mConditions - .HasConditions( - pivot, - point, - conditionsDir, - decisionState, - zIndex, - decisionState.period // - ); - result = hasConditions; - if (!result) - { - // - Clean(visionPoiEvents); - Clean(analysePoiEvents); - Clean(decisionPoiEvents); - Clean(visionCycleEvents); - Clean(analyseCycleEvents); - Clean(decisionCycleEvents); - Clean(consolidationPoiEvents); - Clean(consolidationCycleEvents); - - // - visionState.Clean(); - analyseState.Clean(); - decisionState.Clean(); - visionConditions.Clean(); - analyseConditions.Clean(); - visionXConditions.Clean(); - consolidationState.Clean(); - decisionConditions.Clean(); - analyseXConditions.Clean(); - decisionXConditions.Clean(); - consolidationConditions.Clean(); - consolidationXConditions.Clean(); - - // - return result; - } - - // - isBullish = IsBullish(conditionsDir); - isBearish = IsBearish(conditionsDir); - - // - double reward; - double amountPercent; - ENUM_X121SMC_XWZ_PRIORITY priority = - isBullish - ? bullishPriority - : bearishPriority; - bool hasRewardAmount = CalculateRiskReward( - priority, - reward, - amountPercent // - ); - - // - // Apply Traget ... - switch (priority) - { - // - case X121SMC_XWZ_PRIORITY_STRONG_HIGH: - // - target = - isBullish - ? mConditions.workingZone.quarter3 - : mConditions.workingZone.quarter1; - break; - - // - case X121SMC_XWZ_PRIORITY_HIGH: - // - target = - isBullish - ? mConditions.workingZone.quarter3 - : mConditions.workingZone.quarter1; - break; - - // - case X121SMC_XWZ_PRIORITY_REGULAR: - // - target = - isBullish - ? mConditions.workingZone.quarter2 - : mConditions.workingZone.quarter2; - break; - - // - case X121SMC_XWZ_PRIORITY_LOW: - // - target = - isBullish - ? mConditions.workingZone.quarter1 - : mConditions.workingZone.quarter3; - break; - - // - default: - target = 0; - break; - } - - // - bool hasLastBullishConsolidationZone = false; - bool hasLastBearishConsolidationZone = false; - bool hasPrevBullishConsolidationZone = false; - bool hasPrevBearishConsolidationZone = false; - XConsolidationZone lastBullishConsolidationZone; - XConsolidationZone lastBearishConsolidationZone; - XConsolidationZone prevBullishConsolidationZone; - XConsolidationZone prevBearishConsolidationZone; - bool isLastBullishConsolidationZoneInsidePivot = false; - bool isPrevBullishConsolidationZoneInsidePivot = false; - bool isLastBearishConsolidationZoneInsidePivot = false; - bool isPrevBearishConsolidationZoneInsidePivot = false; - bool hasConsolidationZones = decisionCycleHelper.HasConsolidationZones(); - if (hasConsolidationZones) - { - // - int cZCount = 0; - XConsolidationZone tmp[]; - - // - cZCount = decisionCycleHelper - .FillConsolidationZones( - X_DIRECTION_BULLISH, - tmp // - ); - if (IsValidSize(cZCount)) - { - // - lastBullishConsolidationZone = tmp[cZCount - 1]; - if (cZCount >= 2) - { - prevBullishConsolidationZone = tmp[cZCount - 2]; - } - } - - // - Clean(tmp); - cZCount = decisionCycleHelper - .FillConsolidationZones( - X_DIRECTION_BEARISH, - tmp // - ); - if (IsValidSize(cZCount)) - { - // - lastBearishConsolidationZone = tmp[cZCount - 1]; - if (cZCount >= 2) - { - prevBearishConsolidationZone = tmp[cZCount - 2]; - } - } - - // - Clean(tmp); - - // - hasLastBullishConsolidationZone = lastBullishConsolidationZone.IsValid(); - hasLastBearishConsolidationZone = lastBearishConsolidationZone.IsValid(); - hasPrevBullishConsolidationZone = prevBullishConsolidationZone.IsValid(); - hasPrevBearishConsolidationZone = prevBearishConsolidationZone.IsValid(); - - // - isLastBullishConsolidationZoneInsidePivot = - // - hasLastBullishConsolidationZone && - (lastBullishConsolidationZone.lower < point && - lastBullishConsolidationZone.upper > pivot) - // - ; - isPrevBullishConsolidationZoneInsidePivot = - // - hasPrevBullishConsolidationZone && - (prevBullishConsolidationZone.lower < point && - prevBullishConsolidationZone.upper > pivot) - // - ; - - // - isLastBearishConsolidationZoneInsidePivot = - // - hasLastBearishConsolidationZone && - (lastBearishConsolidationZone.upper > point && - lastBearishConsolidationZone.lower < pivot) - // - ; - isPrevBearishConsolidationZoneInsidePivot = - // - hasPrevBearishConsolidationZone && - (prevBearishConsolidationZone.upper > point && - prevBearishConsolidationZone.lower < pivot) - // - ; - } - - // - bool isConsolidationZonePassed = - isBullish - // - ? (point > 0 && - pivot > 0 && - pivot < point && - hasPrevBullishConsolidationZone && - point > prevBullishConsolidationZone.upper && - (isLastBullishConsolidationZoneInsidePivot || - isPrevBullishConsolidationZoneInsidePivot)) - : (point > 0 && - pivot > 0 && - pivot > point && - hasPrevBearishConsolidationZone && - point < prevBearishConsolidationZone.lower && - (isLastBearishConsolidationZoneInsidePivot || - isPrevBearishConsolidationZoneInsidePivot)) - // - ; - - // - result = hasConditions && - hasRewardAmount && - isPriorityPassed && - trend == conditionsDir; // && - // isConsolidationZonePassed; - if (!result) - { - // - Clean(visionPoiEvents); - Clean(analysePoiEvents); - Clean(decisionPoiEvents); - Clean(visionCycleEvents); - Clean(analyseCycleEvents); - Clean(decisionCycleEvents); - Clean(consolidationPoiEvents); - Clean(consolidationCycleEvents); - - // - visionState.Clean(); - analyseState.Clean(); - decisionState.Clean(); - visionConditions.Clean(); - analyseConditions.Clean(); - visionXConditions.Clean(); - consolidationState.Clean(); - decisionConditions.Clean(); - analyseXConditions.Clean(); - decisionXConditions.Clean(); - consolidationConditions.Clean(); - consolidationXConditions.Clean(); - - // - lastBullishConsolidationZone.Clean(); - lastBearishConsolidationZone.Clean(); - prevBullishConsolidationZone.Clean(); - prevBearishConsolidationZone.Clean(); - - // - mConditions.Clean(); - - // - return result; - } - - // - mConditions.pivot = pivot; - mConditions.point = point; - mConditions.reward = reward; - mConditions.target = target; - mConditions.setupTime = cTime; - mConditions.priority = priority; - mConditions.dir = conditionsDir; - mConditions.amountPercent = amountPercent; - - // - mConditions.UpdateTo(cTime); - - // - Clean(visionPoiEvents); - Clean(analysePoiEvents); - Clean(decisionPoiEvents); - Clean(visionCycleEvents); - Clean(analyseCycleEvents); - Clean(decisionCycleEvents); - Clean(consolidationPoiEvents); - Clean(consolidationCycleEvents); - - // - visionState.Clean(); - analyseState.Clean(); - decisionState.Clean(); - visionConditions.Clean(); - analyseConditions.Clean(); - visionXConditions.Clean(); - consolidationState.Clean(); - decisionConditions.Clean(); - analyseXConditions.Clean(); - decisionXConditions.Clean(); - consolidationConditions.Clean(); - consolidationXConditions.Clean(); - - // - lastBullishConsolidationZone.Clean(); - lastBearishConsolidationZone.Clean(); - prevBullishConsolidationZone.Clean(); - prevBearishConsolidationZone.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 = 30 - // - ) - { - // - 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; - - // - string symbol = _symbol; - ENUM_TIMEFRAMES period = _period; - - // - XOHCL zBar; - result = decisionCycleHelper.GetBar( - zBar, - zIndex // - ); - if (!result) - { - return result; - } - - // - XOHCL cBar; - result = decisionCycleHelper.GetBar( - cBar, - cIndex // - ); - if (!result) - { - return result; - } - - // - XOHCL pBar; - result = decisionCycleHelper.GetBar( - pBar, - pIndex // - ); - if (!result) - { - return result; - } - - // - double ask = GetAsk(symbol); - double bid = GetBid(symbol); - datetime cTime = TimeCurrent(); - double points = GetPoints(symbol); - - // - int swingLoopback = 9; - double ll = cBar.FindLowest(swingLoopback, MODE_LOW); - double hh = cBar.FindHighest(swingLoopback, MODE_HIGH); - double llDown = cBar.FindLowesttDown(swingLoopback); - double hhUp = cBar.FindHighestUp(swingLoopback); - - // - // 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 ... - zBar.Clean(); - cBar.Clean(); - pBar.Clean(); - - // - Clean(decisionPoiEvents); - Clean(decisionCycleEvents); - - // - decisionConditions.Clean(); - - // - return result; - } - - // - // Cycles POI States ... - XPOIState decisionState = decisionConditions.state; - - // - // Cycle X121Conditions ... - X121Conditions decisionXConditions = decisionConditions.x121Conditions; - - // - // Trigger Conditions ... - - // - double point = conditions.point; - bool isPointBreaked = IsBarBreak( - point, - setupDir, - cBar // - ); - - // - // Summary ... - - // - isBullish = - // - isBullish && - isPointBreaked && - cBar.IsBullish() - // - ; - - // - isBearish = - // - isBearish && - isPointBreaked && - cBar.IsBearish() - // - ; - - // - result = isBullish || - isBearish; - if (!result) - { - // - // Cleanup Setup Conditions ... - int setupAge = conditions.GetSetupAge(); - if (IsValidSize(setupAge) && - IsValidSize(maxAllowedSetupAge) && - setupAge >= maxAllowedSetupAge) - { - conditions.Clean(); - } - - // - // Cleanup ... - zBar.Clean(); - cBar.Clean(); - pBar.Clean(); - - // - Clean(decisionPoiEvents); - Clean(decisionCycleEvents); - - // - decisionState.Clean(); - decisionConditions.Clean(); - decisionXConditions.Clean(); - - // - return result; - } - - // - // Detect Nearest Pivot Point ... - - // - double entry = GetEntry( - conditions.symbol, - setupDir // - ); - - // - // Manipulate SL Based on Consolidation Zones ... - - // - double sls[]; - Add( - conditions.pivot, - sls // - ); - - // - // TODO: Add Consolidation Zone for SLs ... - - // - double iAtr = decisionXConditions.atrBuffer[1]; - iAtr *= 2; - - // - 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; - - // - // Cleanup ... - zBar.Clean(); - cBar.Clean(); - pBar.Clean(); - - // - Clean(decisionPoiEvents); - Clean(decisionCycleEvents); - - // - decisionState.Clean(); - decisionConditions.Clean(); - decisionXConditions.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 - // - ; - - // - result = isCycleHelpersValid; - if (!result) - { - return result; - } - - // - int count = ArraySize(positions); - result = IsValidSize(count); - if (!result) - { - return result; - } - - // - string symbol = decisionCycleHelper.GetSymbol(); - ENUM_TIMEFRAMES period = decisionCycleHelper.GetPeriod(); - 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 ... - - // - XBoxZone lastBullishBox; - XBoxZone prevLastBullishBox; - bool hasLastBullishBox = false; - bool hasPrevLastBullishBox = false; - XConsolidationZone lastBullishZone; - bool isLastBullishAbovePrev = false; - bool isLastBullishBelowPrev = false; - XConsolidationZone prevLastBullishZone; - - // - XBoxZone lastBearishBox; - XBoxZone prevLastBearishBox; - bool hasLastBearishBox = false; - bool hasPrevLastBearishBox = false; - XConsolidationZone lastBearishZone; - bool isLastBearishAbovePrev = false; - bool isLastBearishBelowPrev = false; - XConsolidationZone prevLastBearishZone; - - // - int bullishConsolidationZonesCount = 0; - int bearishConsolidationZonesCount = 0; - bool hasBullishConsolidationZones = false; - bool hasBearishConsolidationZones = false; - XConsolidationZone bullishConsolidationZones[]; - XConsolidationZone bearishConsolidationZones[]; - bool hasConsolidationZones = decisionCycleHelper.HasConsolidationZones(); - int consolidationZonesCount = decisionCycleHelper.CountConsolidationZones(); - if (hasConsolidationZones) - { - // - bullishConsolidationZonesCount = decisionCycleHelper - .FillConsolidationZones( - X_DIRECTION_BULLISH, - bullishConsolidationZones // - ); - hasBullishConsolidationZones = IsValidSize(bullishConsolidationZonesCount); - - // - bearishConsolidationZonesCount = decisionCycleHelper - .FillConsolidationZones( - X_DIRECTION_BEARISH, - bearishConsolidationZones // - ); - hasBearishConsolidationZones = IsValidSize(bearishConsolidationZonesCount); - - // - // - // - - // - if (hasBullishConsolidationZones && - bullishConsolidationZonesCount >= 2) - { - // - lastBullishZone = bullishConsolidationZones[bullishConsolidationZonesCount - 1]; - prevLastBullishZone = bullishConsolidationZones[bullishConsolidationZonesCount - 2]; - - // - hasLastBullishBox = ToBox( - lastBullishBox, - lastBullishZone // - ); - hasPrevLastBullishBox = ToBox( - prevLastBullishBox, - prevLastBullishZone // - ); - - // - isLastBullishAbovePrev = hasLastBullishBox && - hasPrevLastBullishBox && - IsBoxAbove( - lastBullishBox, - prevLastBullishBox // - ); - - // - isLastBullishBelowPrev = hasLastBullishBox && - hasPrevLastBullishBox && - IsBoxBelow( - lastBullishBox, - prevLastBullishBox // - ); - } - - // - if (hasBearishConsolidationZones && - bearishConsolidationZonesCount >= 2) - { - // - lastBearishZone = bearishConsolidationZones[bearishConsolidationZonesCount - 1]; - prevLastBearishZone = bearishConsolidationZones[bearishConsolidationZonesCount - 2]; - - // - hasLastBearishBox = ToBox( - lastBearishBox, - lastBearishZone // - ); - hasPrevLastBearishBox = ToBox( - prevLastBearishBox, - prevLastBearishZone // - ); - - // - isLastBearishAbovePrev = hasLastBearishBox && - hasPrevLastBearishBox && - IsBoxAbove( - lastBearishBox, - prevLastBearishBox // - ); - - // - isLastBearishBelowPrev = hasLastBearishBox && - hasPrevLastBearishBox && - IsBoxBelow( - lastBearishBox, - prevLastBearishBox // - ); - } - - // - } - - // - // 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 isStrongSwingLowAboveLastBullishBox = - isStrongSwingLow && - hasLastBullishBox && - pBar.low > lastBullishBox.upper; - - // - bool isStrongSwingHighBelowLastBearishBox = - isStrongSwingHigh && - hasLastBearishBox && - pBar.high < lastBearishBox.lower; - - // - // 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 ... - - // - // 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(); - - // - lastBullishBox.Clean(); - lastBearishBox.Clean(); - lastBullishZone.Clean(); - lastBearishZone.Clean(); - prevLastBullishBox.Clean(); - prevLastBearishBox.Clean(); - prevLastBullishZone.Clean(); - prevLastBearishZone.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; - } - - // - // Draw Functions ... - // - - // - void RemoveDraws() - { - mObjects.Clear(); - } - - // - void RemoveWorkingZoneDraws() - { - mWorkingZoneObjects.Clear(); - } - - // - void DrawOrderBlock( - XCOrderBlock *ob, - XCPOIDrawer *drawer, - bool forWorkingZone = false // - ) - { - // - if (ob == NULL || - drawer == NULL) - { - return; - } - - // - ENUM_X_DIRECTION forDir = ob.GetDirection(); - - // - color bullishColor = drawer.BarBullishColor(); - color bearishColor = drawer.BarBearishColor(); - color forColor = IsBullish(forDir) - ? bullishColor - : bearishColor; - - // - // Draw Order Block ... - XCBaseObject *obj; - bool isCreated = drawer.CreateOrderBlock( - ob, - obj // - ); - if (isCreated) - { - // - if (forWorkingZone) - { - mWorkingZoneObjects.Add(obj); - } - else - { - mObjects.Add(obj); - } - } - - // - ulong chartID = drawer.ChartIdentification(); - int subWindow = drawer.SubWindowIdentification(); - - // - XOHCL startedBar; - ENUM_X_DIRECTION startedDir; - bool isStarted = ob.IsStarted( - forDir, - startedBar, - startedDir // - ); - if (isStarted) - { - // - datetime to = startedBar.time + (PeriodSeconds(startedBar.period)); - - // - XCOHCLObject *obj; - bool isCreated = drawer.CreateBar( - startedBar, - obj, - to // - ); - if (isCreated) - { - // - obj.BodyColor(clrYellow); - obj.HighShadowColor(clrYellow); - obj.LowShadowColor(clrYellow); - - // - obj.BodyStyle(STYLE_SOLID); - obj.HighShadowStyle(STYLE_SOLID); - obj.LowShadowStyle(STYLE_SOLID); - - // - if (forWorkingZone) - { - mWorkingZoneObjects.Add(obj); - } - else - { - mObjects.Add(obj); - } - } - - // - string startVLineName = "Start_" + ob.GetTag(); - - // - CChartObjectVLine *startVLine; - startVLine = new CChartObjectVLine(); - isCreated = startVLine.Create( - chartID, - startVLineName, - subWindow, - startedBar.time // - ); - if (isCreated) - { - // - startVLine.Color(forColor); - - // - if (forWorkingZone) - { - mWorkingZoneObjects.Add(startVLine); - } - else - { - mObjects.Add(startVLine); - } - } - } - } - - // - void DrawFairValueGap( - XCFVG *fvg, - XCPOIDrawer *drawer, - bool forWorkingZone = false // - ) - { - // - if (fvg == NULL || - drawer == NULL) - { - return; - } - - // - ENUM_X_DIRECTION forDir = fvg.GetDirection(); - - // - color bullishColor = drawer.BarBullishColor(); - color bearishColor = drawer.BarBearishColor(); - color forColor = IsBullish(forDir) - ? bullishColor - : bearishColor; - - // - // Draw Order Block ... - XCBaseObject *obj; - bool isCreated = drawer.CreateFairValueGap( - fvg, - obj // - ); - if (isCreated) - { - // - if (forWorkingZone) - { - mWorkingZoneObjects.Add(obj); - } - else - { - mObjects.Add(obj); - } - } - - // - ulong chartID = drawer.ChartIdentification(); - int subWindow = drawer.SubWindowIdentification(); - - // - XOHCL startedBar; - ENUM_X_DIRECTION startedDir; - bool isStarted = fvg.IsStarted( - forDir, - startedBar, - startedDir // - ); - if (isStarted) - { - // - datetime to = startedBar.time + (PeriodSeconds(startedBar.period)); - - // - XCOHCLObject *obj; - bool isCreated = drawer.CreateBar( - startedBar, - obj, - to // - ); - if (isCreated) - { - // - obj.BodyColor(clrYellow); - obj.HighShadowColor(clrYellow); - obj.LowShadowColor(clrYellow); - - // - obj.BodyStyle(STYLE_SOLID); - obj.HighShadowStyle(STYLE_SOLID); - obj.LowShadowStyle(STYLE_SOLID); - - // - if (forWorkingZone) - { - mWorkingZoneObjects.Add(obj); - } - else - { - mObjects.Add(obj); - } - } - - // - string startVLineName = "Start_" + fvg.GetTag(); - - // - CChartObjectVLine *startVLine; - startVLine = new CChartObjectVLine(); - isCreated = startVLine.Create( - chartID, - startVLineName, - subWindow, - startedBar.time // - ); - if (isCreated) - { - // - startVLine.Color(forColor); - - // - if (forWorkingZone) - { - mWorkingZoneObjects.Add(startVLine); - } - else - { - mObjects.Add(startVLine); - } - } - } - } - - // - void DrawWorkingZone( - X121SMCStrategyXWZSignalConditions &conditions, - XCPOIDrawer *drawer // - ) - { - // - if (drawer == NULL) - { - return; - } - - // - bool hasWorkingZone = conditions.HasWorkingZone(); - if (!hasWorkingZone) - { - return; - } - - // - string prefix = "WKZ_" + conditions.workingZone.symbol + ToString(conditions.workingZone.period) + "_"; - string tag = prefix + ToString(conditions.workingZone.upper) + "_" + ToString(conditions.workingZone.lower); - string suffix = ToMD5(tag); - - // - string upperName = prefix + "_Upper_" + suffix; - string lowerName = prefix + "_Lower_" + suffix; - string zoneUpperName = prefix + "_ZoneUpper_" + suffix; - string zoneLowerName = prefix + "_ZoneLower_" + suffix; - - // - string q1Name = prefix + "_Q1_" + suffix; - string q2Name = prefix + "_Q2_" + suffix; - string q3Name = prefix + "_Q3_" + suffix; - - // - ulong chartID = drawer.ChartIdentification(); - int subWindow = drawer.SubWindowIdentification(); - - // - bool isCreated = false; - - // - // Check For Trend Approced ... - bool isTrendApproved = conditions.HasOrderBlock() && - conditions.HasFairValueGap(); - if (isTrendApproved) - { - // - DrawOrderBlock( - conditions.orderBlock, - drawer, - true // - ); - - // - DrawFairValueGap( - conditions.fairValueGap, - drawer, - true // - ); - } - - // - XCSupplyZoneObject *iSupObj; - isCreated = drawer.CreateSupplyZone( - conditions.supplyZone, - iSupObj // - ); - if (isCreated) - { - mWorkingZoneObjects.Add(iSupObj); - } - - // - XCDemandZoneObject *iDemObj; - isCreated = drawer.CreateDemandZone( - conditions.demandZone, - iDemObj // - ); - if (isCreated) - { - mWorkingZoneObjects.Add(iDemObj); - } - - // - // Lower ... - CChartObjectTrend *lowerHLine; - lowerHLine = new CChartObjectTrend(); - isCreated = lowerHLine.Create( - chartID, - lowerName, - subWindow, - conditions.workingZone.from, - conditions.workingZone.lower, - conditions.workingZone.to, - conditions.workingZone.lower // - ); - if (isCreated) - { - // - lowerHLine.Color(clrLime); - mWorkingZoneObjects.Add(lowerHLine); - } - - // - CChartObjectTrend *upperHLine; - upperHLine = new CChartObjectTrend(); - isCreated = upperHLine.Create( - chartID, - upperName, - subWindow, - conditions.workingZone.from, - conditions.workingZone.upper, - conditions.workingZone.to, - conditions.workingZone.upper // - ); - if (isCreated) - { - // - upperHLine.Color(clrLime); - mWorkingZoneObjects.Add(upperHLine); - } - - // - CChartObjectTrend *zoneLowerHLine; - zoneLowerHLine = new CChartObjectTrend(); - isCreated = zoneLowerHLine.Create( - chartID, - zoneLowerName, - subWindow, - conditions.workingZone.from, - conditions.workingZone.zoneLower, - conditions.workingZone.to, - conditions.workingZone.zoneLower // - ); - if (isCreated) - { - // - zoneLowerHLine.Color(clrRed); - mWorkingZoneObjects.Add(zoneLowerHLine); - } - - // - CChartObjectTrend *zoneUpperHLine; - zoneUpperHLine = new CChartObjectTrend(); - isCreated = zoneUpperHLine.Create( - chartID, - zoneUpperName, - subWindow, - conditions.workingZone.from, - conditions.workingZone.zoneUpper, - conditions.workingZone.to, - conditions.workingZone.zoneUpper // - ); - if (isCreated) - { - // - zoneUpperHLine.Color(clrRed); - mWorkingZoneObjects.Add(zoneUpperHLine); - } - - // - CChartObjectTrend *quarter1HLine; - quarter1HLine = new CChartObjectTrend(); - isCreated = quarter1HLine.Create( - chartID, - q1Name, - subWindow, - conditions.workingZone.from, - conditions.workingZone.quarter1, - conditions.workingZone.to, - conditions.workingZone.quarter1 // - ); - if (isCreated) - { - // - quarter1HLine.Color(clrYellow); - mWorkingZoneObjects.Add(quarter1HLine); - } - - // - CChartObjectTrend *quarter2HLine; - quarter2HLine = new CChartObjectTrend(); - isCreated = quarter2HLine.Create( - chartID, - q2Name, - subWindow, - conditions.workingZone.from, - conditions.workingZone.quarter2, - conditions.workingZone.to, - conditions.workingZone.quarter2 // - ); - if (isCreated) - { - // - quarter2HLine.Color(clrYellow); - mWorkingZoneObjects.Add(quarter2HLine); - } - - // - CChartObjectTrend *quarter3HLine; - quarter3HLine = new CChartObjectTrend(); - isCreated = quarter3HLine.Create( - chartID, - q3Name, - subWindow, - conditions.workingZone.from, - conditions.workingZone.quarter3, - conditions.workingZone.to, - conditions.workingZone.quarter3 // - ); - if (isCreated) - { - // - quarter3HLine.Color(clrYellow); - mWorkingZoneObjects.Add(quarter3HLine); - } - - // - } - - // - void DrawConditions( - X121SMCStrategyXWZSignalConditions &conditions, - XCPOIDrawer *drawer, - bool forceClean = false // - ) - { - // - if (drawer == NULL) - { - return; - } - - // - if (forceClean) - { - mObjects.Clear(); - } - - // - bool isCreated = false; - - // - ulong chartID = drawer.ChartIdentification(); - int subWindow = drawer.SubWindowIdentification(); - color bullishColor = drawer.BarBullishColor(); - color bearishColor = drawer.BarBearishColor(); - - // - // Start Zones ... - bool hasStartZones = conditions.HasStartZones(); - if (hasStartZones) - { - // - int count = conditions.CountStartZones(); - for (int i = 0; i < count; i++) - { - // - bool isBullish = conditions.startZones[i].IsBullish(); - - // - bool hasOB = conditions.startZones[i].HasOB(); - if (hasOB) - { - // // - // XCBaseObject *iObj; - // isCreated = drawer.CreateOrderBlock( - // conditions.startZones[i].ob, - // iObj // - // ); - - // // - // if (isCreated) - // { - // mObjects.Add(iObj); - // } - - // - DrawOrderBlock( - conditions.startZones[i].ob, - drawer // - ); - } - - // - bool hasFVG = conditions.startZones[i].HasFVG(); - if (hasFVG) - { - // // - // XCBaseObject *iObj; - // isCreated = drawer.CreateFairValueGap( - // conditions.startZones[i].fvg, - // iObj // - // ); - - // // - // if (isCreated) - // { - // mObjects.Add(iObj); - // } - - // - DrawFairValueGap( - conditions.startZones[i].fvg, - drawer // - ); - } - - // // - // bool hasSupply = conditions.startZones[i].HasSupply(); - // if (hasSupply) - // { - // // - // XCSupplyZoneObject *iObj; - // isCreated = drawer.CreateSupplyZone( - // conditions.startZones[i].supply, - // iObj // - // ); - - // // - // if (isCreated) - // { - // mObjects.Add(iObj); - // } - // } - - // // - // bool hasDemand = conditions.startZones[i].HasDemand(); - // if (hasDemand) - // { - // // - // XCDemandZoneObject *iObj; - // isCreated = drawer.CreateDemandZone( - // conditions.startZones[i].demand, - // iObj // - // ); - - // // - // if (isCreated) - // { - // mObjects.Add(iObj); - // } - // } - - // // - // bool hasSupport = conditions.startZones[i].HasSupport(); - // if (hasSupport) - // { - // // - // XCSupportZoneObject *iObj; - // isCreated = drawer.CreateSupportZone( - // conditions.startZones[i].support, - // iObj // - // ); - - // // - // if (isCreated) - // { - // mObjects.Add(iObj); - // } - // } - - // // - // bool hasResistance = conditions.startZones[i].HasResistance(); - // if (hasResistance) - // { - // // - // XCResistanceZoneObject *iObj; - // isCreated = drawer.CreateResistanceZone( - // conditions.startZones[i].resistance, - // iObj // - // ); - - // // - // if (isCreated) - // { - // mObjects.Add(iObj); - // } - // } - - // - // - // - - // - string bName = ""; - int arrowCode = 0; - string bSuffix = ""; - color arrowColor = clrNONE; - ENUM_X_PRICE bPrice = X_PRICE_CLOSE; - - // - bool hasSwingBar = conditions.startZones[i].swingBar.IsValid(); - if (hasSwingBar) - { - // - bSuffix = ToMD5(conditions.startZones[i].swingBar.GetTag()); - bName = - (isBullish - ? "SWING_LOW" - : "SWING_HIGH") + - "_" + bSuffix; - arrowCode = 159; - arrowColor = - isBullish - ? bullishColor - : bearishColor; - bPrice = - isBullish - ? X_PRICE_LOW - : X_PRICE_HIGH; - - // - XCBarArrowObject *iObj; - iObj = new XCBarArrowObject(); - isCreated = iObj.CreateByBar( - chartID, - bName, - subWindow, - arrowCode, - conditions.startZones[i].swingBar, - bPrice // - ); - if (isCreated) - { - // - iObj.ArrowColor(arrowColor); - - // - mObjects.Add(iObj); - } - } - - // - bool hasBreakerBar = conditions.startZones[i].breakerBar.IsValid(); - if (hasBreakerBar) - { - // - bSuffix = ToMD5(conditions.startZones[i].breakerBar.GetTag()); - bName = - (isBullish - ? "BULL_BREAKER" - : "BEAR_BREAKER") + - "_" + bSuffix; - arrowCode = - isBullish - ? 71 - : 72; - arrowColor = - isBullish - ? bullishColor - : bearishColor; - bPrice = - isBullish - ? X_PRICE_LOW - : X_PRICE_HIGH; - - // - XCBarArrowObject *iObj; - iObj = new XCBarArrowObject(); - isCreated = iObj.CreateByBar( - chartID, - bName, - subWindow, - arrowCode, - conditions.startZones[i].breakerBar, - bPrice // - ); - if (isCreated) - { - // - iObj.ArrowColor(arrowColor); - - // - mObjects.Add(iObj); - } - } - - // - bool hasMomentumBar = conditions.startZones[i].momentumBar.IsValid(); - if (hasMomentumBar) - { - // - bSuffix = ToMD5(conditions.startZones[i].momentumBar.GetTag()); - bName = - (isBullish - ? "BULL_MOMENTUM" - : "BEAR_MOMENTUM") + - "_" + bSuffix; - arrowCode = - isBullish - ? 233 - : 234; - arrowColor = - isBullish - ? bullishColor - : bearishColor; - bPrice = - isBullish - ? X_PRICE_LOW - : X_PRICE_HIGH; - - // - XCBarArrowObject *iObj; - iObj = new XCBarArrowObject(); - isCreated = iObj.CreateByBar( - chartID, - bName, - subWindow, - arrowCode, - conditions.startZones[i].momentumBar, - bPrice // - ); - if (isCreated) - { - // - iObj.ArrowColor(arrowColor); - - // - mObjects.Add(iObj); - } - } - - // - bool hasRejectionBar = conditions.startZones[i].rejectionBar.IsValid(); - if (hasRejectionBar) - { - // - bSuffix = ToMD5(conditions.startZones[i].rejectionBar.GetTag()); - bName = - (isBullish - ? "BULL_REJECTION" - : "BEAR_REJECTION") + - "_" + bSuffix; - arrowCode = - isBullish - ? 241 - : 242; - arrowColor = - isBullish - ? bullishColor - : bearishColor; - bPrice = - isBullish - ? X_PRICE_LOW - : X_PRICE_HIGH; - - // - XCBarArrowObject *iObj; - iObj = new XCBarArrowObject(); - isCreated = iObj.CreateByBar( - chartID, - bName, - subWindow, - arrowCode, - conditions.startZones[i].rejectionBar, - bPrice // - ); - if (isCreated) - { - // - iObj.ArrowColor(arrowColor); - - // - mObjects.Add(iObj); - } - } - - // - bool hasAppliedBox = conditions.startZones[i].appliedBox.IsValid(); - if (hasAppliedBox) - { - // - arrowColor = - IsBullish(conditions.startZones[i].appliedBox.dir) - ? bullishColor - : bearishColor; - - // - XCBoxObject *iObj; - isCreated = drawer.CreateBox( - conditions.startZones[i].appliedBox, - iObj // - ); - - // - if (isCreated) - { - // - iObj.BoxWidth(2); - iObj.BoxColor(arrowColor); - - // - mObjects.Add(iObj); - } - } - } - } - } - - // - protected: - // - - // - private: - // - // Props ... - CArrayObj mObjects; - CArrayObj mWorkingZoneObjects; - - /** - * Initialize ... - */ - void Init() - { - } - - /** - * DeInitialize ... - */ - void DeInit() - { - // - RemoveDraws(); - mConditions.Clean(); - RemoveWorkingZoneDraws(); - Clean(mConditionsCollection); - } - - // - // 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 24a476f0..00000000 --- a/Documents/BKP/x-121.smc.xwz.signal.class.mq5 +++ /dev/null @@ -1,2725 +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 ... - X121SMCStrategyXWZSignalConditions mConditions; - X121SMCStrategyXWZSignalConditions mConditionsCollection[]; - - // - // Constructor(s) ... - XCX121SMCXWZSignalDetector() - { - Init(); - } - - // - // Deconstructor ... - ~XCX121SMCXWZSignalDetector() - { - DeInit(); - } - - // - // - // - - // - // Detect Setup Conditions ... - bool DetectSignalSetup( - // - string _symbol, - ENUM_TIMEFRAMES _period, - // - 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; - - // - string symbol = _symbol; - ENUM_TIMEFRAMES period = _period; - - // - mConditions.symbol = symbol; - mConditions.period = period; - - // - double ask = GetAsk(symbol); - double bid = GetBid(symbol); - datetime cTime = TimeCurrent(); - double points = GetPoints(symbol); - - // - double target = 0; - - // - // Cycles Conditions ... - - // - // Decision ... - ENUM_XPOI_EVENTS decisionPoiEvents[]; - ENUM_X_CYCLE_EVENTS decisionCycleEvents[]; - X121SMCCycleConditions decisionConditions; - result = decisionCycleHelper.GetConditions( - decisionCycleEvents, - decisionPoiEvents, - decisionConditions, - zIndex, - loopback // - ); - if (!result) - { - // - mConditions.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) - { - // - mConditions.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) - { - // - mConditions.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) - { - // - mConditions.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 ... - - // - // Check Working Zone ... - bool hasWorkingZone = mConditions.HasWorkingZone(); - if (!hasWorkingZone) - { - // - hasWorkingZone = mConditions.ExtractWorkingZone( - visionState, - consolidationState, - analyseState, - zIndex // - ); - } - - // - result = hasWorkingZone; - if (!result) - { - // - Clean(visionPoiEvents); - Clean(analysePoiEvents); - Clean(decisionPoiEvents); - Clean(visionCycleEvents); - Clean(analyseCycleEvents); - Clean(decisionCycleEvents); - Clean(consolidationPoiEvents); - Clean(consolidationCycleEvents); - - // - visionState.Clean(); - analyseState.Clean(); - decisionState.Clean(); - visionConditions.Clean(); - analyseConditions.Clean(); - visionXConditions.Clean(); - consolidationState.Clean(); - decisionConditions.Clean(); - analyseXConditions.Clean(); - decisionXConditions.Clean(); - consolidationConditions.Clean(); - consolidationXConditions.Clean(); - - // - mConditions.Clean(); - - // - return result; - } - - // - mConditions.UpdateTo(cTime); - - // - // Check Working Zone still Alive ... - ENUM_X_DIRECTION destroyedDir = X_DIRECTION_NONE; - bool isWorkingZoneDestroyed = mConditions - .IsWorkingZoneDestroyed( - destroyedDir, - zIndex, - decisionState.period // - ); - if (isWorkingZoneDestroyed) - { - RemoveWorkingZoneDraws(); - } - - // - result = !isWorkingZoneDestroyed; - if (!result) - { - // - Clean(visionPoiEvents); - Clean(analysePoiEvents); - Clean(decisionPoiEvents); - Clean(visionCycleEvents); - Clean(analyseCycleEvents); - Clean(decisionCycleEvents); - Clean(consolidationPoiEvents); - Clean(consolidationCycleEvents); - - // - visionState.Clean(); - analyseState.Clean(); - decisionState.Clean(); - visionConditions.Clean(); - analyseConditions.Clean(); - visionXConditions.Clean(); - consolidationState.Clean(); - decisionConditions.Clean(); - analyseXConditions.Clean(); - decisionXConditions.Clean(); - consolidationConditions.Clean(); - consolidationXConditions.Clean(); - - // - mConditions.Clean(); - - // - return result; - } - - // - // Detecting Trend ... - ENUM_X_DIRECTION trend; - bool hasTrend = mConditions.DetectTrend( - trend, - period // - ); - bool hasBullishTrend = hasTrend && - IsBullish(trend); - bool hasBearishTrend = hasTrend && - IsBearish(trend); - result = hasTrend; - if (!result) - { - // - Clean(visionPoiEvents); - Clean(analysePoiEvents); - Clean(decisionPoiEvents); - Clean(visionCycleEvents); - Clean(analyseCycleEvents); - Clean(decisionCycleEvents); - Clean(consolidationPoiEvents); - Clean(consolidationCycleEvents); - - // - visionState.Clean(); - analyseState.Clean(); - decisionState.Clean(); - visionConditions.Clean(); - analyseConditions.Clean(); - visionXConditions.Clean(); - consolidationState.Clean(); - decisionConditions.Clean(); - analyseXConditions.Clean(); - decisionXConditions.Clean(); - consolidationConditions.Clean(); - consolidationXConditions.Clean(); - - // - mConditions.Clean(); - - // - return result; - } - - // - // bool hasStartZone = mConditions.DetectStartZones( - // trend, - // consolidationState, - // analyseState, - // decisionState, - // decisionCycleHelper // - // ); - - // - mConditions.UpdateTo(cTime); - - // - // Detect Condition Priority ... - ENUM_X121SMC_XWZ_PRIORITY bullishPriority; - ENUM_X121SMC_XWZ_PRIORITY bearishPriority; - mConditions.DetectPriority( - bullishPriority, - bearishPriority // - ); - - // - bool canLookupLong = bullishPriority != X121SMC_XWZ_PRIORITY_NONE && - bullishPriority != X121SMC_XWZ_PRIORITY_WEAK; - bool canLookupShort = bearishPriority != X121SMC_XWZ_PRIORITY_NONE && - bearishPriority != X121SMC_XWZ_PRIORITY_WEAK; - bool isPriorityPassed = - hasBullishTrend - ? canLookupLong - : hasBearishTrend - ? canLookupShort - : false; - - // - // Here we are Make sure we have Correct: - // - WorkSpace ... - // - Trend ... - // - What we looking for: Long or Short ... - // - Priority ... - - // - double pivot = 0; - double point = 0; - ENUM_X_DIRECTION conditionsDir = X_DIRECTION_NONE; - - // - // Detect Start Zone Conditions ... - bool hasConditions = mConditions - .HasConditions( - pivot, - point, - conditionsDir, - decisionState, - zIndex, - decisionState.period // - ); - result = hasConditions; - if (!result) - { - // - Clean(visionPoiEvents); - Clean(analysePoiEvents); - Clean(decisionPoiEvents); - Clean(visionCycleEvents); - Clean(analyseCycleEvents); - Clean(decisionCycleEvents); - Clean(consolidationPoiEvents); - Clean(consolidationCycleEvents); - - // - visionState.Clean(); - analyseState.Clean(); - decisionState.Clean(); - visionConditions.Clean(); - analyseConditions.Clean(); - visionXConditions.Clean(); - consolidationState.Clean(); - decisionConditions.Clean(); - analyseXConditions.Clean(); - decisionXConditions.Clean(); - consolidationConditions.Clean(); - consolidationXConditions.Clean(); - - // - return result; - } - - // - isBullish = IsBullish(conditionsDir); - isBearish = IsBearish(conditionsDir); - - // - double reward; - double amountPercent; - ENUM_X121SMC_XWZ_PRIORITY priority = - isBullish - ? bullishPriority - : bearishPriority; - bool hasRewardAmount = CalculateRiskReward( - priority, - reward, - amountPercent // - ); - - // - // Apply Traget ... - switch (priority) - { - // - case X121SMC_XWZ_PRIORITY_STRONG_HIGH: - // - target = - isBullish - ? mConditions.workingZone.quarter3 - : mConditions.workingZone.quarter1; - break; - - // - case X121SMC_XWZ_PRIORITY_HIGH: - // - target = - isBullish - ? mConditions.workingZone.quarter3 - : mConditions.workingZone.quarter1; - break; - - // - case X121SMC_XWZ_PRIORITY_REGULAR: - // - target = - isBullish - ? mConditions.workingZone.quarter2 - : mConditions.workingZone.quarter2; - break; - - // - case X121SMC_XWZ_PRIORITY_LOW: - // - target = - isBullish - ? mConditions.workingZone.quarter1 - : mConditions.workingZone.quarter3; - break; - - // - default: - target = 0; - break; - } - - // - bool hasLastBullishConsolidationZone = false; - bool hasLastBearishConsolidationZone = false; - bool hasPrevBullishConsolidationZone = false; - bool hasPrevBearishConsolidationZone = false; - XConsolidationZone lastBullishConsolidationZone; - XConsolidationZone lastBearishConsolidationZone; - XConsolidationZone prevBullishConsolidationZone; - XConsolidationZone prevBearishConsolidationZone; - bool isLastBullishConsolidationZoneInsidePivot = false; - bool isPrevBullishConsolidationZoneInsidePivot = false; - bool isLastBearishConsolidationZoneInsidePivot = false; - bool isPrevBearishConsolidationZoneInsidePivot = false; - bool hasConsolidationZones = decisionCycleHelper.HasConsolidationZones(); - if (hasConsolidationZones) - { - // - int cZCount = 0; - XConsolidationZone tmp[]; - - // - cZCount = decisionCycleHelper - .FillConsolidationZones( - X_DIRECTION_BULLISH, - tmp // - ); - if (IsValidSize(cZCount)) - { - // - lastBullishConsolidationZone = tmp[cZCount - 1]; - if (cZCount >= 2) - { - prevBullishConsolidationZone = tmp[cZCount - 2]; - } - } - - // - Clean(tmp); - cZCount = decisionCycleHelper - .FillConsolidationZones( - X_DIRECTION_BEARISH, - tmp // - ); - if (IsValidSize(cZCount)) - { - // - lastBearishConsolidationZone = tmp[cZCount - 1]; - if (cZCount >= 2) - { - prevBearishConsolidationZone = tmp[cZCount - 2]; - } - } - - // - Clean(tmp); - - // - hasLastBullishConsolidationZone = lastBullishConsolidationZone.IsValid(); - hasLastBearishConsolidationZone = lastBearishConsolidationZone.IsValid(); - hasPrevBullishConsolidationZone = prevBullishConsolidationZone.IsValid(); - hasPrevBearishConsolidationZone = prevBearishConsolidationZone.IsValid(); - - // - isLastBullishConsolidationZoneInsidePivot = - // - hasLastBullishConsolidationZone && - (lastBullishConsolidationZone.lower < point && - lastBullishConsolidationZone.upper > pivot) - // - ; - isPrevBullishConsolidationZoneInsidePivot = - // - hasPrevBullishConsolidationZone && - (prevBullishConsolidationZone.lower < point && - prevBullishConsolidationZone.upper > pivot) - // - ; - - // - isLastBearishConsolidationZoneInsidePivot = - // - hasLastBearishConsolidationZone && - (lastBearishConsolidationZone.upper > point && - lastBearishConsolidationZone.lower < pivot) - // - ; - isPrevBearishConsolidationZoneInsidePivot = - // - hasPrevBearishConsolidationZone && - (prevBearishConsolidationZone.upper > point && - prevBearishConsolidationZone.lower < pivot) - // - ; - } - - // - bool isConsolidationZonePassed = - isBullish - // - ? (point > 0 && - pivot > 0 && - pivot < point && - hasPrevBullishConsolidationZone && - point > prevBullishConsolidationZone.upper && - (isLastBullishConsolidationZoneInsidePivot || - isPrevBullishConsolidationZoneInsidePivot)) - : (point > 0 && - pivot > 0 && - pivot > point && - hasPrevBearishConsolidationZone && - point < prevBearishConsolidationZone.lower && - (isLastBearishConsolidationZoneInsidePivot || - isPrevBearishConsolidationZoneInsidePivot)) - // - ; - - // - result = hasConditions && - hasRewardAmount && - isPriorityPassed && - trend == conditionsDir; // && - // isConsolidationZonePassed; - if (!result) - { - // - Clean(visionPoiEvents); - Clean(analysePoiEvents); - Clean(decisionPoiEvents); - Clean(visionCycleEvents); - Clean(analyseCycleEvents); - Clean(decisionCycleEvents); - Clean(consolidationPoiEvents); - Clean(consolidationCycleEvents); - - // - visionState.Clean(); - analyseState.Clean(); - decisionState.Clean(); - visionConditions.Clean(); - analyseConditions.Clean(); - visionXConditions.Clean(); - consolidationState.Clean(); - decisionConditions.Clean(); - analyseXConditions.Clean(); - decisionXConditions.Clean(); - consolidationConditions.Clean(); - consolidationXConditions.Clean(); - - // - lastBullishConsolidationZone.Clean(); - lastBearishConsolidationZone.Clean(); - prevBullishConsolidationZone.Clean(); - prevBearishConsolidationZone.Clean(); - - // - mConditions.Clean(); - - // - return result; - } - - // - mConditions.pivot = pivot; - mConditions.point = point; - mConditions.reward = reward; - mConditions.target = target; - mConditions.setupTime = cTime; - mConditions.priority = priority; - mConditions.dir = conditionsDir; - mConditions.amountPercent = amountPercent; - - // - mConditions.UpdateTo(cTime); - - // - Clean(visionPoiEvents); - Clean(analysePoiEvents); - Clean(decisionPoiEvents); - Clean(visionCycleEvents); - Clean(analyseCycleEvents); - Clean(decisionCycleEvents); - Clean(consolidationPoiEvents); - Clean(consolidationCycleEvents); - - // - visionState.Clean(); - analyseState.Clean(); - decisionState.Clean(); - visionConditions.Clean(); - analyseConditions.Clean(); - visionXConditions.Clean(); - consolidationState.Clean(); - decisionConditions.Clean(); - analyseXConditions.Clean(); - decisionXConditions.Clean(); - consolidationConditions.Clean(); - consolidationXConditions.Clean(); - - // - lastBullishConsolidationZone.Clean(); - lastBearishConsolidationZone.Clean(); - prevBullishConsolidationZone.Clean(); - prevBearishConsolidationZone.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 = 30 - // - ) - { - // - 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; - - // - string symbol = _symbol; - ENUM_TIMEFRAMES period = _period; - - // - XOHCL zBar; - result = decisionCycleHelper.GetBar( - zBar, - zIndex // - ); - if (!result) - { - return result; - } - - // - XOHCL cBar; - result = decisionCycleHelper.GetBar( - cBar, - cIndex // - ); - if (!result) - { - return result; - } - - // - XOHCL pBar; - result = decisionCycleHelper.GetBar( - pBar, - pIndex // - ); - if (!result) - { - return result; - } - - // - double ask = GetAsk(symbol); - double bid = GetBid(symbol); - datetime cTime = TimeCurrent(); - double points = GetPoints(symbol); - - // - int swingLoopback = 9; - double ll = cBar.FindLowest(swingLoopback, MODE_LOW); - double hh = cBar.FindHighest(swingLoopback, MODE_HIGH); - double llDown = cBar.FindLowesttDown(swingLoopback); - double hhUp = cBar.FindHighestUp(swingLoopback); - - // - // 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 ... - zBar.Clean(); - cBar.Clean(); - pBar.Clean(); - - // - Clean(decisionPoiEvents); - Clean(decisionCycleEvents); - - // - decisionConditions.Clean(); - - // - return result; - } - - // - // Cycles POI States ... - XPOIState decisionState = decisionConditions.state; - - // - // Cycle X121Conditions ... - X121Conditions decisionXConditions = decisionConditions.x121Conditions; - - // - // Trigger Conditions ... - - // - double point = conditions.point; - bool isPointBreaked = IsBarBreak( - point, - setupDir, - cBar // - ); - - // - // Summary ... - - // - isBullish = - // - isBullish && - isPointBreaked && - cBar.IsBullish() - // - ; - - // - isBearish = - // - isBearish && - isPointBreaked && - cBar.IsBearish() - // - ; - - // - result = isBullish || - isBearish; - if (!result) - { - // - // Cleanup Setup Conditions ... - int setupAge = conditions.GetSetupAge(); - if (IsValidSize(setupAge) && - IsValidSize(maxAllowedSetupAge) && - setupAge >= maxAllowedSetupAge) - { - conditions.Clean(); - } - - // - // Cleanup ... - zBar.Clean(); - cBar.Clean(); - pBar.Clean(); - - // - Clean(decisionPoiEvents); - Clean(decisionCycleEvents); - - // - decisionState.Clean(); - decisionConditions.Clean(); - decisionXConditions.Clean(); - - // - return result; - } - - // - // Detect Nearest Pivot Point ... - - // - double entry = GetEntry( - conditions.symbol, - setupDir // - ); - - // - // Manipulate SL Based on Consolidation Zones ... - - // - double sls[]; - Add( - conditions.pivot, - sls // - ); - - // - // TODO: Add Consolidation Zone for SLs ... - - // - double iAtr = decisionXConditions.atrBuffer[1]; - iAtr *= 2; - - // - 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; - - // - // Cleanup ... - zBar.Clean(); - cBar.Clean(); - pBar.Clean(); - - // - Clean(decisionPoiEvents); - Clean(decisionCycleEvents); - - // - decisionState.Clean(); - decisionConditions.Clean(); - decisionXConditions.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 - // - ; - - // - result = isCycleHelpersValid; - if (!result) - { - return result; - } - - // - int count = ArraySize(positions); - result = IsValidSize(count); - if (!result) - { - return result; - } - - // - string symbol = decisionCycleHelper.GetSymbol(); - ENUM_TIMEFRAMES period = decisionCycleHelper.GetPeriod(); - 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 ... - - // - XBoxZone lastBullishBox; - XBoxZone prevLastBullishBox; - bool hasLastBullishBox = false; - bool hasPrevLastBullishBox = false; - XConsolidationZone lastBullishZone; - bool isLastBullishAbovePrev = false; - bool isLastBullishBelowPrev = false; - XConsolidationZone prevLastBullishZone; - - // - XBoxZone lastBearishBox; - XBoxZone prevLastBearishBox; - bool hasLastBearishBox = false; - bool hasPrevLastBearishBox = false; - XConsolidationZone lastBearishZone; - bool isLastBearishAbovePrev = false; - bool isLastBearishBelowPrev = false; - XConsolidationZone prevLastBearishZone; - - // - int bullishConsolidationZonesCount = 0; - int bearishConsolidationZonesCount = 0; - bool hasBullishConsolidationZones = false; - bool hasBearishConsolidationZones = false; - XConsolidationZone bullishConsolidationZones[]; - XConsolidationZone bearishConsolidationZones[]; - bool hasConsolidationZones = decisionCycleHelper.HasConsolidationZones(); - int consolidationZonesCount = decisionCycleHelper.CountConsolidationZones(); - if (hasConsolidationZones) - { - // - bullishConsolidationZonesCount = decisionCycleHelper - .FillConsolidationZones( - X_DIRECTION_BULLISH, - bullishConsolidationZones // - ); - hasBullishConsolidationZones = IsValidSize(bullishConsolidationZonesCount); - - // - bearishConsolidationZonesCount = decisionCycleHelper - .FillConsolidationZones( - X_DIRECTION_BEARISH, - bearishConsolidationZones // - ); - hasBearishConsolidationZones = IsValidSize(bearishConsolidationZonesCount); - - // - // - // - - // - if (hasBullishConsolidationZones && - bullishConsolidationZonesCount >= 2) - { - // - lastBullishZone = bullishConsolidationZones[bullishConsolidationZonesCount - 1]; - prevLastBullishZone = bullishConsolidationZones[bullishConsolidationZonesCount - 2]; - - // - hasLastBullishBox = ToBox( - lastBullishBox, - lastBullishZone // - ); - hasPrevLastBullishBox = ToBox( - prevLastBullishBox, - prevLastBullishZone // - ); - - // - isLastBullishAbovePrev = hasLastBullishBox && - hasPrevLastBullishBox && - IsBoxAbove( - lastBullishBox, - prevLastBullishBox // - ); - - // - isLastBullishBelowPrev = hasLastBullishBox && - hasPrevLastBullishBox && - IsBoxBelow( - lastBullishBox, - prevLastBullishBox // - ); - } - - // - if (hasBearishConsolidationZones && - bearishConsolidationZonesCount >= 2) - { - // - lastBearishZone = bearishConsolidationZones[bearishConsolidationZonesCount - 1]; - prevLastBearishZone = bearishConsolidationZones[bearishConsolidationZonesCount - 2]; - - // - hasLastBearishBox = ToBox( - lastBearishBox, - lastBearishZone // - ); - hasPrevLastBearishBox = ToBox( - prevLastBearishBox, - prevLastBearishZone // - ); - - // - isLastBearishAbovePrev = hasLastBearishBox && - hasPrevLastBearishBox && - IsBoxAbove( - lastBearishBox, - prevLastBearishBox // - ); - - // - isLastBearishBelowPrev = hasLastBearishBox && - hasPrevLastBearishBox && - IsBoxBelow( - lastBearishBox, - prevLastBearishBox // - ); - } - - // - } - - // - // 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 isStrongSwingLowAboveLastBullishBox = - isStrongSwingLow && - hasLastBullishBox && - pBar.low > lastBullishBox.upper; - - // - bool isStrongSwingHighBelowLastBearishBox = - isStrongSwingHigh && - hasLastBearishBox && - pBar.high < lastBearishBox.lower; - - // - // 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 ... - - // - // 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(); - - // - lastBullishBox.Clean(); - lastBearishBox.Clean(); - lastBullishZone.Clean(); - lastBearishZone.Clean(); - prevLastBullishBox.Clean(); - prevLastBearishBox.Clean(); - prevLastBullishZone.Clean(); - prevLastBearishZone.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; - } - - // - // Draw Functions ... - // - - // - void RemoveDraws() - { - mObjects.Clear(); - } - - // - void RemoveWorkingZoneDraws() - { - mWorkingZoneObjects.Clear(); - } - - // - void DrawOrderBlock( - XCOrderBlock *ob, - XCPOIDrawer *drawer, - bool forWorkingZone = false // - ) - { - // - if (ob == NULL || - drawer == NULL) - { - return; - } - - // - ENUM_X_DIRECTION forDir = ob.GetDirection(); - - // - color bullishColor = drawer.BarBullishColor(); - color bearishColor = drawer.BarBearishColor(); - color forColor = IsBullish(forDir) - ? bullishColor - : bearishColor; - - // - // Draw Order Block ... - XCBaseObject *obj; - bool isCreated = drawer.CreateOrderBlock( - ob, - obj // - ); - if (isCreated) - { - // - if (forWorkingZone) - { - mWorkingZoneObjects.Add(obj); - } - else - { - mObjects.Add(obj); - } - } - - // - ulong chartID = drawer.ChartIdentification(); - int subWindow = drawer.SubWindowIdentification(); - - // - XOHCL startedBar; - ENUM_X_DIRECTION startedDir; - bool isStarted = ob.IsStarted( - forDir, - startedBar, - startedDir // - ); - if (isStarted) - { - // - datetime to = startedBar.time + (PeriodSeconds(startedBar.period)); - - // - XCOHCLObject *obj; - bool isCreated = drawer.CreateBar( - startedBar, - obj, - to // - ); - if (isCreated) - { - // - obj.BodyColor(clrYellow); - obj.HighShadowColor(clrYellow); - obj.LowShadowColor(clrYellow); - - // - obj.BodyStyle(STYLE_SOLID); - obj.HighShadowStyle(STYLE_SOLID); - obj.LowShadowStyle(STYLE_SOLID); - - // - if (forWorkingZone) - { - mWorkingZoneObjects.Add(obj); - } - else - { - mObjects.Add(obj); - } - } - - // - string startVLineName = "Start_" + ob.GetTag(); - - // - CChartObjectVLine *startVLine; - startVLine = new CChartObjectVLine(); - isCreated = startVLine.Create( - chartID, - startVLineName, - subWindow, - startedBar.time // - ); - if (isCreated) - { - // - startVLine.Color(forColor); - - // - if (forWorkingZone) - { - mWorkingZoneObjects.Add(startVLine); - } - else - { - mObjects.Add(startVLine); - } - } - } - } - - // - void DrawFairValueGap( - XCFVG *fvg, - XCPOIDrawer *drawer, - bool forWorkingZone = false // - ) - { - // - if (fvg == NULL || - drawer == NULL) - { - return; - } - - // - ENUM_X_DIRECTION forDir = fvg.GetDirection(); - - // - color bullishColor = drawer.BarBullishColor(); - color bearishColor = drawer.BarBearishColor(); - color forColor = IsBullish(forDir) - ? bullishColor - : bearishColor; - - // - // Draw Order Block ... - XCBaseObject *obj; - bool isCreated = drawer.CreateFairValueGap( - fvg, - obj // - ); - if (isCreated) - { - // - if (forWorkingZone) - { - mWorkingZoneObjects.Add(obj); - } - else - { - mObjects.Add(obj); - } - } - - // - ulong chartID = drawer.ChartIdentification(); - int subWindow = drawer.SubWindowIdentification(); - - // - XOHCL startedBar; - ENUM_X_DIRECTION startedDir; - bool isStarted = fvg.IsStarted( - forDir, - startedBar, - startedDir // - ); - if (isStarted) - { - // - datetime to = startedBar.time + (PeriodSeconds(startedBar.period)); - - // - XCOHCLObject *obj; - bool isCreated = drawer.CreateBar( - startedBar, - obj, - to // - ); - if (isCreated) - { - // - obj.BodyColor(clrYellow); - obj.HighShadowColor(clrYellow); - obj.LowShadowColor(clrYellow); - - // - obj.BodyStyle(STYLE_SOLID); - obj.HighShadowStyle(STYLE_SOLID); - obj.LowShadowStyle(STYLE_SOLID); - - // - if (forWorkingZone) - { - mWorkingZoneObjects.Add(obj); - } - else - { - mObjects.Add(obj); - } - } - - // - string startVLineName = "Start_" + fvg.GetTag(); - - // - CChartObjectVLine *startVLine; - startVLine = new CChartObjectVLine(); - isCreated = startVLine.Create( - chartID, - startVLineName, - subWindow, - startedBar.time // - ); - if (isCreated) - { - // - startVLine.Color(forColor); - - // - if (forWorkingZone) - { - mWorkingZoneObjects.Add(startVLine); - } - else - { - mObjects.Add(startVLine); - } - } - } - } - - // - void DrawWorkingZone( - X121SMCStrategyXWZSignalConditions &conditions, - XCPOIDrawer *drawer // - ) - { - // - if (drawer == NULL) - { - return; - } - - // - bool hasWorkingZone = conditions.HasWorkingZone(); - if (!hasWorkingZone) - { - return; - } - - // - string prefix = "WKZ_" + conditions.workingZone.symbol + ToString(conditions.workingZone.period) + "_"; - string tag = prefix + ToString(conditions.workingZone.upper) + "_" + ToString(conditions.workingZone.lower); - string suffix = ToMD5(tag); - - // - string upperName = prefix + "_Upper_" + suffix; - string lowerName = prefix + "_Lower_" + suffix; - string zoneUpperName = prefix + "_ZoneUpper_" + suffix; - string zoneLowerName = prefix + "_ZoneLower_" + suffix; - - // - string q1Name = prefix + "_Q1_" + suffix; - string q2Name = prefix + "_Q2_" + suffix; - string q3Name = prefix + "_Q3_" + suffix; - - // - ulong chartID = drawer.ChartIdentification(); - int subWindow = drawer.SubWindowIdentification(); - - // - bool isCreated = false; - - // - // Check For Trend Approced ... - bool isTrendApproved = conditions.HasOrderBlock() && - conditions.HasFairValueGap(); - if (isTrendApproved) - { - // - DrawOrderBlock( - conditions.orderBlock, - drawer, - true // - ); - - // - DrawFairValueGap( - conditions.fairValueGap, - drawer, - true // - ); - } - - // - XCSupplyZoneObject *iSupObj; - isCreated = drawer.CreateSupplyZone( - conditions.supplyZone, - iSupObj // - ); - if (isCreated) - { - mWorkingZoneObjects.Add(iSupObj); - } - - // - XCDemandZoneObject *iDemObj; - isCreated = drawer.CreateDemandZone( - conditions.demandZone, - iDemObj // - ); - if (isCreated) - { - mWorkingZoneObjects.Add(iDemObj); - } - - // - // Lower ... - CChartObjectTrend *lowerHLine; - lowerHLine = new CChartObjectTrend(); - isCreated = lowerHLine.Create( - chartID, - lowerName, - subWindow, - conditions.workingZone.from, - conditions.workingZone.lower, - conditions.workingZone.to, - conditions.workingZone.lower // - ); - if (isCreated) - { - // - lowerHLine.Color(clrLime); - mWorkingZoneObjects.Add(lowerHLine); - } - - // - CChartObjectTrend *upperHLine; - upperHLine = new CChartObjectTrend(); - isCreated = upperHLine.Create( - chartID, - upperName, - subWindow, - conditions.workingZone.from, - conditions.workingZone.upper, - conditions.workingZone.to, - conditions.workingZone.upper // - ); - if (isCreated) - { - // - upperHLine.Color(clrLime); - mWorkingZoneObjects.Add(upperHLine); - } - - // - CChartObjectTrend *zoneLowerHLine; - zoneLowerHLine = new CChartObjectTrend(); - isCreated = zoneLowerHLine.Create( - chartID, - zoneLowerName, - subWindow, - conditions.workingZone.from, - conditions.workingZone.zoneLower, - conditions.workingZone.to, - conditions.workingZone.zoneLower // - ); - if (isCreated) - { - // - zoneLowerHLine.Color(clrRed); - mWorkingZoneObjects.Add(zoneLowerHLine); - } - - // - CChartObjectTrend *zoneUpperHLine; - zoneUpperHLine = new CChartObjectTrend(); - isCreated = zoneUpperHLine.Create( - chartID, - zoneUpperName, - subWindow, - conditions.workingZone.from, - conditions.workingZone.zoneUpper, - conditions.workingZone.to, - conditions.workingZone.zoneUpper // - ); - if (isCreated) - { - // - zoneUpperHLine.Color(clrRed); - mWorkingZoneObjects.Add(zoneUpperHLine); - } - - // - CChartObjectTrend *quarter1HLine; - quarter1HLine = new CChartObjectTrend(); - isCreated = quarter1HLine.Create( - chartID, - q1Name, - subWindow, - conditions.workingZone.from, - conditions.workingZone.quarter1, - conditions.workingZone.to, - conditions.workingZone.quarter1 // - ); - if (isCreated) - { - // - quarter1HLine.Color(clrYellow); - mWorkingZoneObjects.Add(quarter1HLine); - } - - // - CChartObjectTrend *quarter2HLine; - quarter2HLine = new CChartObjectTrend(); - isCreated = quarter2HLine.Create( - chartID, - q2Name, - subWindow, - conditions.workingZone.from, - conditions.workingZone.quarter2, - conditions.workingZone.to, - conditions.workingZone.quarter2 // - ); - if (isCreated) - { - // - quarter2HLine.Color(clrYellow); - mWorkingZoneObjects.Add(quarter2HLine); - } - - // - CChartObjectTrend *quarter3HLine; - quarter3HLine = new CChartObjectTrend(); - isCreated = quarter3HLine.Create( - chartID, - q3Name, - subWindow, - conditions.workingZone.from, - conditions.workingZone.quarter3, - conditions.workingZone.to, - conditions.workingZone.quarter3 // - ); - if (isCreated) - { - // - quarter3HLine.Color(clrYellow); - mWorkingZoneObjects.Add(quarter3HLine); - } - - // - } - - // - void DrawConditions( - X121SMCStrategyXWZSignalConditions &conditions, - XCPOIDrawer *drawer, - bool forceClean = false // - ) - { - // - if (drawer == NULL) - { - return; - } - - // - if (forceClean) - { - mObjects.Clear(); - } - - // - bool isCreated = false; - - // - ulong chartID = drawer.ChartIdentification(); - int subWindow = drawer.SubWindowIdentification(); - color bullishColor = drawer.BarBullishColor(); - color bearishColor = drawer.BarBearishColor(); - - // - // Start Zones ... - bool hasStartZones = conditions.HasStartZones(); - if (hasStartZones) - { - // - int count = conditions.CountStartZones(); - for (int i = 0; i < count; i++) - { - // - bool isBullish = conditions.startZones[i].IsBullish(); - - // - bool hasOB = conditions.startZones[i].HasOB(); - if (hasOB) - { - // // - // XCBaseObject *iObj; - // isCreated = drawer.CreateOrderBlock( - // conditions.startZones[i].ob, - // iObj // - // ); - - // // - // if (isCreated) - // { - // mObjects.Add(iObj); - // } - - // - DrawOrderBlock( - conditions.startZones[i].ob, - drawer // - ); - } - - // - bool hasFVG = conditions.startZones[i].HasFVG(); - if (hasFVG) - { - // // - // XCBaseObject *iObj; - // isCreated = drawer.CreateFairValueGap( - // conditions.startZones[i].fvg, - // iObj // - // ); - - // // - // if (isCreated) - // { - // mObjects.Add(iObj); - // } - - // - DrawFairValueGap( - conditions.startZones[i].fvg, - drawer // - ); - } - - // // - // bool hasSupply = conditions.startZones[i].HasSupply(); - // if (hasSupply) - // { - // // - // XCSupplyZoneObject *iObj; - // isCreated = drawer.CreateSupplyZone( - // conditions.startZones[i].supply, - // iObj // - // ); - - // // - // if (isCreated) - // { - // mObjects.Add(iObj); - // } - // } - - // // - // bool hasDemand = conditions.startZones[i].HasDemand(); - // if (hasDemand) - // { - // // - // XCDemandZoneObject *iObj; - // isCreated = drawer.CreateDemandZone( - // conditions.startZones[i].demand, - // iObj // - // ); - - // // - // if (isCreated) - // { - // mObjects.Add(iObj); - // } - // } - - // // - // bool hasSupport = conditions.startZones[i].HasSupport(); - // if (hasSupport) - // { - // // - // XCSupportZoneObject *iObj; - // isCreated = drawer.CreateSupportZone( - // conditions.startZones[i].support, - // iObj // - // ); - - // // - // if (isCreated) - // { - // mObjects.Add(iObj); - // } - // } - - // // - // bool hasResistance = conditions.startZones[i].HasResistance(); - // if (hasResistance) - // { - // // - // XCResistanceZoneObject *iObj; - // isCreated = drawer.CreateResistanceZone( - // conditions.startZones[i].resistance, - // iObj // - // ); - - // // - // if (isCreated) - // { - // mObjects.Add(iObj); - // } - // } - - // - // - // - - // - string bName = ""; - int arrowCode = 0; - string bSuffix = ""; - color arrowColor = clrNONE; - ENUM_X_PRICE bPrice = X_PRICE_CLOSE; - - // - bool hasSwingBar = conditions.startZones[i].swingBar.IsValid(); - if (hasSwingBar) - { - // - bSuffix = ToMD5(conditions.startZones[i].swingBar.GetTag()); - bName = - (isBullish - ? "SWING_LOW" - : "SWING_HIGH") + - "_" + bSuffix; - arrowCode = 159; - arrowColor = - isBullish - ? bullishColor - : bearishColor; - bPrice = - isBullish - ? X_PRICE_LOW - : X_PRICE_HIGH; - - // - XCBarArrowObject *iObj; - iObj = new XCBarArrowObject(); - isCreated = iObj.CreateByBar( - chartID, - bName, - subWindow, - arrowCode, - conditions.startZones[i].swingBar, - bPrice // - ); - if (isCreated) - { - // - iObj.ArrowColor(arrowColor); - - // - mObjects.Add(iObj); - } - } - - // - bool hasBreakerBar = conditions.startZones[i].breakerBar.IsValid(); - if (hasBreakerBar) - { - // - bSuffix = ToMD5(conditions.startZones[i].breakerBar.GetTag()); - bName = - (isBullish - ? "BULL_BREAKER" - : "BEAR_BREAKER") + - "_" + bSuffix; - arrowCode = - isBullish - ? 71 - : 72; - arrowColor = - isBullish - ? bullishColor - : bearishColor; - bPrice = - isBullish - ? X_PRICE_LOW - : X_PRICE_HIGH; - - // - XCBarArrowObject *iObj; - iObj = new XCBarArrowObject(); - isCreated = iObj.CreateByBar( - chartID, - bName, - subWindow, - arrowCode, - conditions.startZones[i].breakerBar, - bPrice // - ); - if (isCreated) - { - // - iObj.ArrowColor(arrowColor); - - // - mObjects.Add(iObj); - } - } - - // - bool hasMomentumBar = conditions.startZones[i].momentumBar.IsValid(); - if (hasMomentumBar) - { - // - bSuffix = ToMD5(conditions.startZones[i].momentumBar.GetTag()); - bName = - (isBullish - ? "BULL_MOMENTUM" - : "BEAR_MOMENTUM") + - "_" + bSuffix; - arrowCode = - isBullish - ? 233 - : 234; - arrowColor = - isBullish - ? bullishColor - : bearishColor; - bPrice = - isBullish - ? X_PRICE_LOW - : X_PRICE_HIGH; - - // - XCBarArrowObject *iObj; - iObj = new XCBarArrowObject(); - isCreated = iObj.CreateByBar( - chartID, - bName, - subWindow, - arrowCode, - conditions.startZones[i].momentumBar, - bPrice // - ); - if (isCreated) - { - // - iObj.ArrowColor(arrowColor); - - // - mObjects.Add(iObj); - } - } - - // - bool hasRejectionBar = conditions.startZones[i].rejectionBar.IsValid(); - if (hasRejectionBar) - { - // - bSuffix = ToMD5(conditions.startZones[i].rejectionBar.GetTag()); - bName = - (isBullish - ? "BULL_REJECTION" - : "BEAR_REJECTION") + - "_" + bSuffix; - arrowCode = - isBullish - ? 241 - : 242; - arrowColor = - isBullish - ? bullishColor - : bearishColor; - bPrice = - isBullish - ? X_PRICE_LOW - : X_PRICE_HIGH; - - // - XCBarArrowObject *iObj; - iObj = new XCBarArrowObject(); - isCreated = iObj.CreateByBar( - chartID, - bName, - subWindow, - arrowCode, - conditions.startZones[i].rejectionBar, - bPrice // - ); - if (isCreated) - { - // - iObj.ArrowColor(arrowColor); - - // - mObjects.Add(iObj); - } - } - - // - bool hasAppliedBox = conditions.startZones[i].appliedBox.IsValid(); - if (hasAppliedBox) - { - // - arrowColor = - IsBullish(conditions.startZones[i].appliedBox.dir) - ? bullishColor - : bearishColor; - - // - XCBoxObject *iObj; - isCreated = drawer.CreateBox( - conditions.startZones[i].appliedBox, - iObj // - ); - - // - if (isCreated) - { - // - iObj.BoxWidth(2); - iObj.BoxColor(arrowColor); - - // - mObjects.Add(iObj); - } - } - } - } - } - - // - protected: - // - - // - private: - // - // Props ... - CArrayObj mObjects; - CArrayObj mWorkingZoneObjects; - - /** - * Initialize ... - */ - void Init() - { - } - - /** - * DeInitialize ... - */ - void DeInit() - { - // - RemoveDraws(); - mConditions.Clean(); - RemoveWorkingZoneDraws(); - Clean(mConditionsCollection); - } - - // - // Helpers ... - - // - bool CalculateRiskReward( - ENUM_X121SMC_XWZ_PRIORITY priority, - double &reward, - double &amountPercent // - ) - { - // - bool result = false; - - // - reward = 0; - amountPercent = 0; - - // - result = priority != X121SMC_XWZ_PRIORITY_NONE; - if (!result) - { - return result; - } - - // - switch (priority) - { - // - case X121SMC_XWZ_PRIORITY_STRONG_HIGH: - // - reward = 6; - amountPercent = 2; - break; - - // - case X121SMC_XWZ_PRIORITY_HIGH: - // - reward = 4; - amountPercent = 2; - break; - - // - case X121SMC_XWZ_PRIORITY_REGULAR: - // - reward = 3; - amountPercent = 1.5; - break; - - // - case X121SMC_XWZ_PRIORITY_LOW: - // - reward = 2; - amountPercent = 1; - break; - - // - case X121SMC_XWZ_PRIORITY_WEAK: - // - reward = 1; - amountPercent = 0.5; - break; - } - - // - result = - // - reward > 0 && - amountPercent > 0 - // - ; - - // - return result; - } - - // -}; - -// \ No newline at end of file diff --git a/Documents/BKP/x-121.smc.xwz.signal.lib copy 2.mq5 b/Documents/BKP/x-121.smc.xwz.signal.lib copy 2.mq5 deleted file mode 100644 index 9a7025d0..00000000 --- a/Documents/BKP/x-121.smc.xwz.signal.lib copy 2.mq5 +++ /dev/null @@ -1,3749 +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_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 X121SMCXWZZone -{ - // - // Props ... - XCFVG *fvg; - XCOrderBlock *ob; - XCSupplyZone *supply; - XCDemandZone *demand; - XCSupportZone *support; - XCResistanceZone *resistance; - - // - XOHCL swingBar; - XOHCL breakerBar; - XOHCL momentumBar; - XOHCL rejectionBar; - XBoxZone appliedBox; - - // - // Constructor ... - X121SMCXWZZone() - { - Clean(); - } - - // - // Tools ... - - // - void Clean() - { - // - ZeroMemory(ob); - ZeroMemory(fvg); - ZeroMemory(supply); - ZeroMemory(demand); - ZeroMemory(support); - ZeroMemory(resistance); - - // - swingBar.Clean(); - breakerBar.Clean(); - appliedBox.Clean(); - momentumBar.Clean(); - rejectionBar.Clean(); - } - - // - bool IsValid() - { - // - return HasOB() && - HasFVG() && - HasDirection(); - } - - // - bool AsBox(XBoxZone &box) - { - // - bool result = false; - - // - box.Clean(); - - // - result = IsValid() && - HasDirection(); - if (!result) - { - return result; - } - - // - XBoxZone obBox; - bool hasOBBox = ToBox( - obBox, - ob // - ); - result = hasOBBox; - if (!result) - { - // - box.Clean(); - obBox.Clean(); - return result; - } - - // - box = obBox; - - // - obBox.Clean(); - - // - bool hasOB = HasOB(); - bool hasFVG = HasFVG(); - bool hasSupply = HasSupply(); - bool hasDemand = HasDemand(); - bool hasSupport = HasSupport(); - bool hasResistance = HasResistance(); - - // - // OB Compared since box used obBox ... - - // - if (hasFVG) - { - // - if (fvg.Upper() > box.upper) - { - box.upper = fvg.Upper(); - } - - // - if (fvg.Lower() < box.lower) - { - box.lower = fvg.Lower(); - } - } - - // - result = box.IsValid(); - - // - return result; - } - - // - bool HasOB() - { - return ob != NULL && - ob.IsValid(); - } - - // - bool HasFVG() - { - return fvg != NULL && - fvg.IsValid(); - } - - // - bool HasSupply() - { - return supply != NULL && - supply.IsValid(); - } - - // - bool HasDemand() - { - return demand != NULL && - demand.IsValid(); - } - - // - bool HasSupport() - { - return support != NULL && - support.IsValid(); - } - - // - bool HasResistance() - { - return resistance != NULL && - resistance.IsValid(); - } - - // - bool IsBullish() - { - // - return HasOB() && - ob.IsBullish() && - HasFVG() && - fvg.IsBullish(); - } - - // - bool IsBearish() - { - // - return HasOB() && - ob.IsBearish() && - HasFVG() && - fvg.IsBearish(); - } - - // - bool HasDirection() - { - return IsBullish() || - IsBearish(); - } - - // - bool ValidateZone( - int barIndex = 0, - ENUM_TIMEFRAMES forPeriod = NULL // - ) - { - // - bool result = false; - - // - if (barIndex < 0) - { - barIndex = 0; - } - - // - result = IsValid() && - HasDirection(); - if (!result) - { - return result; - } - - // - string symbol = ob.GetSymbol(); - if (forPeriod == NULL) - { - forPeriod = ob.GetPeriod(); - } - ENUM_X_DIRECTION forDir = GetDirection(); - - // - XOHCL cBar; - result = cBar.Init( - symbol, - forPeriod, - barIndex + 1 // - ); - if (!result) - { - // - cBar.Clean(); - return result; - } - - // - bool isBreaked = - IsBullish(forDir) - ? cBar.close < ob.Lower() || - cBar.close < fvg.Lower() - : cBar.close > ob.Upper() || - cBar.close > fvg.Upper(); - result = !isBreaked; - - // - cBar.Clean(); - - // - return result; - } - - // - ENUM_X_DIRECTION GetDirection() - { - // - ENUM_X_DIRECTION result = X_DIRECTION_NONE; - - // - bool hasDirection = HasDirection(); - if (!hasDirection) - { - return result; - } - - // - bool isBullish = IsBullish(); - - // - result = - isBullish - ? X_DIRECTION_BULLISH - : X_DIRECTION_BEARISH; - - // - return result; - } - - // - bool IsPriceInside( - XBoxZone &box, - int barIndex = 0, - ENUM_TIMEFRAMES forPeriod = NULL, - bool forceOB = false, - bool forceFVG = false // - ) - { - // - bool result = false; - - // - box.Clean(); - - // - if (barIndex < 0) - { - barIndex = 0; - } - - // - result = IsValid() && - HasOB() && - HasFVG() && - HasDirection(); - if (!result) - { - return result; - } - - // - string symbol = ob.GetSymbol(); - if (forPeriod == NULL) - { - forPeriod = ob.GetPeriod(); - } - - // - ENUM_X_DIRECTION forDir = ob.GetDirection(); - bool isBullish = IsBullish(forDir); - - // - // Check Start Bars ... - - // - XOHCL obStartedBar; - ENUM_X_DIRECTION obStartedDir; - bool isOBStarted = ob.IsStarted( - forDir, - obStartedBar, - obStartedDir // - ); - result = isOBStarted; - if (!result) - { - return result; - } - - // - XOHCL fvgStartedBar; - ENUM_X_DIRECTION fvgStartedDir; - bool isFVGStarted = fvg.IsStarted( - forDir, - fvgStartedBar, - fvgStartedDir // - ); - result = isFVGStarted; - if (!result) - { - return result; - } - - // - // Retrieve Bars ... - - // - XOHCL zBar; - result = zBar.Init( - symbol, - forPeriod, - barIndex // - ); - if (!result) - { - // - box.Clean(); - zBar.Clean(); - - // - return result; - } - - // - XOHCL cBar; - result = zBar.GetPreviousBar(cBar); - if (!result) - { - // - box.Clean(); - zBar.Clean(); - cBar.Clean(); - - // - return result; - } - - // - XOHCL pBar; - result = cBar.GetPreviousBar(pBar); - if (!result) - { - // - box.Clean(); - zBar.Clean(); - cBar.Clean(); - pBar.Clean(); - - // - return result; - } - - // - bool isPriceInsideOB = X121SMCXWZCheckPriceInside( - zBar, - cBar, - ob.Upper(), - ob.Lower() // - ); - - // - // isBullish - // ? ( - // // - // pBar.close > ob.Upper() && - // cBar.low <= ob.Upper() && - // cBar.close <= ob.Upper() && - // zBar.open <= ob.Upper() - // // - // ) - // : ( - // // - // pBar.close < ob.Lower() && - // cBar.high >= ob.Lower() && - // cBar.close >= ob.Lower() && - // zBar.open >= ob.Lower() - // // - // ); - - // - bool isPriceInsideFVG = X121SMCXWZCheckPriceInside( - zBar, - cBar, - fvg.Upper(), - fvg.Lower() // - ); - - // - // isBullish - // ? ( - // // - // pBar.close > fvg.Upper() && - // cBar.low <= fvg.Upper() && - // cBar.close <= fvg.Upper() && - // zBar.open <= fvg.Upper() - // // - // ) - // : ( - // // - // pBar.close < fvg.Lower() && - // cBar.high >= fvg.Lower() && - // cBar.close >= fvg.Lower() && - // zBar.open >= fvg.Lower() - // // - // ); - - // - if ((forceOB && forceFVG) || - (!forceOB && !forceFVG)) - { - // - result = - isPriceInsideOB || - isPriceInsideFVG; - } - else if (forceOB) - { - result = isPriceInsideOB; - } - else if (forceFVG) - { - result = isPriceInsideFVG; - } - - // - if (result) - { - // - if (isPriceInsideOB && !isPriceInsideFVG) - { - // - result = ToBox( - box, - ob // - ); - } - else if (isPriceInsideFVG && !isPriceInsideOB) - { - // - result = ToBox( - box, - fvg // - ); - } - else if (isPriceInsideOB && isPriceInsideFVG) - { - result = AsBox(box); - } - } - - // - zBar.Clean(); - cBar.Clean(); - pBar.Clean(); - - // - return result; - } - - // - bool HasInsideConditions( - XPOIState &state, - int barIndex = 0, - ENUM_TIMEFRAMES forPeriod = NULL // - ) - { - // - bool result = false; - - // - if (barIndex < 0) - { - barIndex = 0; - } - - // - swingBar.Clean(); - breakerBar.Clean(); - appliedBox.Clean(); - momentumBar.Clean(); - rejectionBar.Clean(); - - // - XBoxZone zoneBox; - bool hasBox = AsBox(zoneBox); - - // - result = hasBox && - IsValid() && - HasDirection() && - state.IsValid() && - state.HasChild(); - if (!result) - { - // - swingBar.Clean(); - breakerBar.Clean(); - appliedBox.Clean(); - momentumBar.Clean(); - rejectionBar.Clean(); - - // - return result; - } - - // - string symbol = zoneBox.symbol; - if (!IsValid(forPeriod)) - { - forPeriod = zoneBox.period; - } - datetime cTime = iTime( - symbol, - forPeriod, - barIndex // - ); - - // - ENUM_X_DIRECTION forDir = zoneBox.dir; - bool isBullish = IsBullish(forDir); - - // - int count = 0; - bool has = false; - - // - XBoxZone supResBoxes[]; - int supresBoxesCount = 0; - bool hasSupResBoxes = false; - - // - has = state.HasSupportZones(); - if (has) - { - // - count = state.CountSupportZones(); - for (int i = 0; i < count; i++) - { - // - XCSupportZone *iZone = state.supportZones[i]; - - // - iZone.To(cTime); - - // - XBoxZone iBox; - bool hasBox = ToBox( - iBox, - iZone // - ); - if (!hasBox) - { - // - iBox.Clean(); - continue; - } - - // - // Check From ... - bool isInside = IsBoxInside( - iBox, - zoneBox // - ); - if (!isInside) - { - // - iBox.Clean(); - continue; - } - - // - AddRef( - iBox, - supResBoxes // - ); - - // - iBox.Clean(); - ZeroMemory(iZone); - } - - // - supresBoxesCount = ArraySize(supResBoxes); - hasSupResBoxes = IsValidSize(supresBoxesCount); - } - - // - has = state.HasResistanceZones(); - if (has) - { - // - count = state.CountResistanceZones(); - for (int i = 0; i < count; i++) - { - // - XCResistanceZone *iZone = state.resistanceZones[i]; - - // - iZone.To(cTime); - - // - XBoxZone iBox; - bool hasBox = ToBox( - iBox, - iZone // - ); - if (!hasBox) - { - // - iBox.Clean(); - continue; - } - - // - // Check From ... - bool isInside = IsBoxInside( - iBox, - zoneBox // - ); - if (!isInside) - { - // - iBox.Clean(); - continue; - } - - // - AddRef( - iBox, - supResBoxes // - ); - - // - iBox.Clean(); - ZeroMemory(iZone); - } - - // - supresBoxesCount = ArraySize(supResBoxes); - hasSupResBoxes = IsValidSize(supresBoxesCount); - } - - // - result = hasSupResBoxes; - if (!result) - { - // - Clean(supResBoxes); - - // - swingBar.Clean(); - breakerBar.Clean(); - appliedBox.Clean(); - momentumBar.Clean(); - rejectionBar.Clean(); - - // - return result; - } - - // - for (int i = 0; i < supresBoxesCount; i++) - { - // - XBoxZone iBox = supResBoxes[i]; - - // - bool hasBoxConditions = HasBoxConitions( - iBox, - state, - barIndex, - forPeriod // - ); - if (hasBoxConditions) - { - // - appliedBox = iBox; - result = true; - iBox.Clean(); - break; - } - - // - iBox.Clean(); - } - - // - if (!result) - { - // - swingBar.Clean(); - breakerBar.Clean(); - appliedBox.Clean(); - momentumBar.Clean(); - rejectionBar.Clean(); - } - - // - Clean(supResBoxes); - - // - return result; - } - - // - bool HasBoxConitions( - XBoxZone &box, - XPOIState &state, - int barIndex = 0, - ENUM_TIMEFRAMES forPeriod = NULL // - ) - { - // - bool result = false; - - // - if (barIndex < 0) - { - barIndex = 0; - } - - // - result = box.IsValid() && - IsValid() && - HasDirection(); - if (!result) - { - // - swingBar.Clean(); - breakerBar.Clean(); - appliedBox.Clean(); - momentumBar.Clean(); - rejectionBar.Clean(); - - // - return result; - } - - // - string symbol = box.symbol; - if (forPeriod == NULL) - { - forPeriod = box.period; - } - ENUM_X_DIRECTION forDir = box.dir; - bool isBullish = IsBullish(forDir); - - // - // Detect Bars ... - - // - XOHCL zBar; - result = zBar.Init( - symbol, - forPeriod, - barIndex // - ); - if (!result) - { - // - zBar.Clean(); - - // - swingBar.Clean(); - breakerBar.Clean(); - appliedBox.Clean(); - momentumBar.Clean(); - rejectionBar.Clean(); - - // - return result; - } - - // - XOHCL cBar; - result = zBar.GetPreviousBar(cBar); - if (!result) - { - // - zBar.Clean(); - cBar.Clean(); - - // - swingBar.Clean(); - breakerBar.Clean(); - appliedBox.Clean(); - momentumBar.Clean(); - rejectionBar.Clean(); - - // - return result; - } - - // - XOHCL pBar; - result = cBar.GetPreviousBar(pBar); - if (!result) - { - // - zBar.Clean(); - cBar.Clean(); - pBar.Clean(); - - // - swingBar.Clean(); - breakerBar.Clean(); - appliedBox.Clean(); - momentumBar.Clean(); - rejectionBar.Clean(); - - // - return result; - } - - // - XOHCL ppBar; - result = pBar.GetPreviousBar(ppBar); - if (!result) - { - // - zBar.Clean(); - cBar.Clean(); - pBar.Clean(); - ppBar.Clean(); - - // - swingBar.Clean(); - breakerBar.Clean(); - appliedBox.Clean(); - momentumBar.Clean(); - rejectionBar.Clean(); - - // - return result; - } - - // - double fiboPressureLevel = GetFiboLevelValue(X_FIBO_LEVEL_382); - - // - double fiboUpDown = GetFibonacciLevel( - pBar.high, - pBar.low, - X_FIBO_LEVEL_382, - X_DIRECTION_BEARISH // - ); - double fiboDownUp = GetFibonacciLevel( - pBar.high, - pBar.low, - X_FIBO_LEVEL_382, - X_DIRECTION_BULLISH // - ); - - // - bool hasFiboToUpPressure = - fiboDownUp > 0 && - fiboDownUp <= pBar.GetDown(); - bool hasFiboToDownPressure = - fiboUpDown > 0 && - fiboUpDown >= pBar.GetUp(); - - // - double appliedPrice = - isBullish - ? box.upper - : box.lower; - - // - // Check Swing Low ... - bool isSwingLow = - // - pBar.low < ppBar.low && - pBar.low < cBar.low && - zBar.open > pBar.low && - // - appliedPrice > pBar.low && - appliedPrice < pBar.GetDown() - // - ; - bool isPressuredSwingLow = - isSwingLow && - hasFiboToUpPressure; - bool isPressuredStrongSwingLow = - pBar.IsBullish() && - isPressuredSwingLow; - - // - bool isSwingHigh = - // - pBar.high > ppBar.high && - pBar.high > cBar.high && - zBar.open < pBar.high && - // - appliedPrice < pBar.high && - appliedPrice > pBar.GetUp() - // - ; - bool isPressuredSwingHigh = - isSwingHigh && - hasFiboToDownPressure; - bool isPressuredStrongSwingHigh = - pBar.IsBearish() && - isPressuredSwingHigh; - - // - bool hasValidSwing = - isBullish - ? isSwingLow - : isSwingHigh; - bool hasValidPressuredSwing = - isBullish - ? isPressuredSwingLow - : isPressuredSwingHigh; - bool hasValidPressuredStrongSwing = - isBullish - ? isPressuredStrongSwingLow - : isPressuredStrongSwingHigh; - if (hasValidSwing) - { - swingBar = pBar; - } - if (hasValidPressuredSwing) - { - swingBar = pBar; - } - if (hasValidPressuredStrongSwing) - { - swingBar = pBar; - } - - // - bool isCBarBreaked = IsBarBreak( - appliedPrice, - forDir, - cBar // - ); - if (isCBarBreaked) - { - breakerBar = cBar; - } - bool isPBarBreaked = IsBarBreak( - appliedPrice, - forDir, - pBar // - ); - if (!isCBarBreaked && isPBarBreaked) - { - breakerBar = pBar; - } - else - { - isPBarBreaked = false; - } - bool isPPBarBreaked = IsBarBreak( - appliedPrice, - forDir, - ppBar // - ); - if (!isCBarBreaked && - !isPBarBreaked && - isPPBarBreaked) - { - breakerBar = ppBar; - } - else - { - isPPBarBreaked = false; - } - bool isBoxBreaked = isCBarBreaked || - isPBarBreaked || - isPPBarBreaked; - - // - bool isCBarRejected = IsBarReject( - appliedPrice, - forDir, - cBar // - ); - if (isCBarRejected) - { - rejectionBar = cBar; - } - bool isPBarRejected = IsBarReject( - appliedPrice, - forDir, - pBar // - ); - if (!isCBarRejected && isPBarRejected) - { - rejectionBar = pBar; - } - else - { - isPBarRejected = false; - } - bool isPPBarRejected = IsBarReject( - appliedPrice, - forDir, - ppBar // - ); - if (!isCBarRejected && - !isPBarRejected && - isPPBarRejected) - { - rejectionBar = ppBar; - } - else - { - isPPBarRejected = false; - } - bool isBoxRejected = isCBarRejected || - isPBarRejected || - isPPBarRejected; - - // - result = - // - isBoxBreaked || - isBoxRejected || - hasValidPressuredSwing - // - ; - if (!result) - { - // - swingBar.Clean(); - breakerBar.Clean(); - appliedBox.Clean(); - momentumBar.Clean(); - rejectionBar.Clean(); - } - else - { - appliedBox = box; - } - - // - zBar.Clean(); - cBar.Clean(); - pBar.Clean(); - ppBar.Clean(); - - // - return result; - } - - // -}; - -// -struct X121SMCXWZWorkingZone -{ - // - string symbol; - ENUM_TIMEFRAMES period; - - // - double upper; - double lower; - - // - double zoneUpper; - double zoneLower; - - // - double quarter1; - double quarter2; - double quarter3; - - // - datetime to; - datetime from; - - // - XOHCL swingBar; - XOHCL breakerBar; - XOHCL momentumBar; - XOHCL rejectionBar; - XBoxZone appliedBox; - - // - X121SMCXWZWorkingZone() - { - Clean(); - } - - // - void Clean() - { - // - upper = 0; - lower = 0; - quarter1 = 0; - quarter2 = 0; - quarter3 = 0; - zoneLower = 0; - zoneUpper = 0; - - // - from = NULL; - symbol = NULL; - period = NULL; - - // - CleanConditionBars(); - - // - ZeroMemory(this); - } - - // - void CleanConditionBars() - { - // - swingBar.Clean(); - breakerBar.Clean(); - appliedBox.Clean(); - momentumBar.Clean(); - rejectionBar.Clean(); - } - - // - bool IsValid() - { - // - bool result = false; - - // - result = - lower > 0 && - upper > 0 && - quarter1 > 0 && - quarter2 > 0 && - quarter3 > 0 && - upper > lower && - zoneLower > 0 && - zoneUpper > 0 && - IsValid(from) && - IsValid(symbol) && - IsValid(period) && - zoneUpper > upper && - zoneLower < lower; - - // - return result; - } - - // - bool IsDestroyed( - ENUM_X_DIRECTION &destroyedDir, - int barIndex = 0, - ENUM_TIMEFRAMES forPeriod = NULL // - ) - { - // - bool result = false; - - // - if (barIndex < 0) - { - barIndex = 0; - } - - // - if (!IsValid(forPeriod)) - { - forPeriod = period; - } - - // - destroyedDir = X_DIRECTION_NONE; - - // - result = IsValid(); - if (!result) - { - return result; - } - - // - XOHCL bar; - result = bar.Init( - symbol, - forPeriod, - barIndex // - ); - if (!result) - { - return result; - } - - // - bool isUpperBreaked = - bar.high > zoneUpper && - bar.close > zoneUpper; - - // - bool isLowerBreaked = - bar.low < zoneLower && - bar.close < zoneLower; - - // - result = isUpperBreaked || - isLowerBreaked; - if (result) - { - // - destroyedDir = - isUpperBreaked - ? X_DIRECTION_BULLISH - : X_DIRECTION_BEARISH; - } - - // - return result; - } - - // -}; - -// -// Definitions ... -struct X121SMCStrategyXWZSignalConditions -{ - // - // Props ... - - // - string symbol; - ENUM_TIMEFRAMES period; - - // - double sl; - double target; - double reward; - double amountPercent; - ENUM_X_DIRECTION dir; - ENUM_X_POSITION_TYPES type; - - // - // Setup Props ... - - // - datetime setupTime; - datetime triggerTime; - - // - double pivot; - double point; - - // - ENUM_X121SMC_XWZ_PRIORITY priority; - - // - // Working Zone ... - XCFVG *fairValueGap; - XCOrderBlock *orderBlock; - XCSupplyZone *supplyZone; - XCDemandZone *demandZone; - X121SMCXWZWorkingZone workingZone; - - // - // X121SMCXWZZone startZone; - X121SMCXWZZone startZones[]; - - // - // Constructor ... - X121SMCStrategyXWZSignalConditions() - { - Clean(); - } - - // - // Tools ... - - /** - * Cleaning Up ... - */ - void Clean() - { - // - sl = 0; - target = 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; - - // - target = 0; - reward = 0; - amountPercent = 0; - - // - ZeroMemory(supplyZone); - - // - ZeroMemory(demandZone); - - // - ZeroMemory(orderBlock); - - // - ZeroMemory(fairValueGap); - - // - // startZone.Clean(); - Clean(startZones); - - // - workingZone.Clean(); - } - - // - // - // - - // - bool HasWorkingZone() - { - return workingZone.IsValid(); - } - - // - bool HasOrderBlock() - { - return orderBlock != NULL && - orderBlock.IsValid(); - } - - // - bool HasFairValueGap() - { - return fairValueGap != NULL && - fairValueGap.IsValid(); - } - - // - bool HasSupplyZone() - { - return supplyZone != NULL && - supplyZone.IsValid(); - } - - // - bool HasDemandZone() - { - return demandZone != NULL && - demandZone.IsValid(); - } - - // - bool HasStartZones() - { - return HasChild(startZones); - } - - // - int CountStartZones() - { - return ArraySize(startZones); - } - - // - void UpdateTo(datetime value = NULL) - { - // - value = NormalizeTime(value); - - // - bool hasSupplyZone = HasSupplyZone(); - if (hasSupplyZone) - { - supplyZone.To(value); - } - - // - bool hasDemandZone = HasDemandZone(); - if (hasDemandZone) - { - demandZone.To(value); - } - - // - bool hasOrderBlock = HasOrderBlock(); - if (hasOrderBlock) - { - orderBlock.To(value); - } - - // - bool hasFairValueGap = HasFairValueGap(); - if (hasFairValueGap) - { - fairValueGap.To(value); - } - - // - // Working Zone ... - bool hasWorkingZone = HasWorkingZone(); - if (hasWorkingZone) - { - workingZone.to = value; - } - - // - // Start Zone ... - bool hasStartZones = HasStartZones(); - if (hasStartZones) - { - // - int count = CountStartZones(); - for (int i = 0; i < count; i++) - { - // - bool hasOB = startZones[i].HasOB(); - if (hasOB) - { - startZones[i].ob.To(value); - } - - // - bool hasFVG = startZones[i].HasFVG(); - if (hasFVG) - { - startZones[i].fvg.To(value); - } - - // - bool hasSupply = startZones[i].HasSupply(); - if (hasSupply) - { - startZones[i].supply.To(value); - } - - // - bool hasDemand = startZones[i].HasDemand(); - if (hasDemand) - { - startZones[i].demand.To(value); - } - - // - bool hasSupport = startZones[i].HasSupport(); - if (hasSupport) - { - startZones[i].support.To(value); - } - - // - bool hasResistance = startZones[i].HasResistance(); - if (hasResistance) - { - startZones[i].resistance.To(value); - } - } - } - } - - // - // - // - - // - // Working Zone is an Area which - // we decide to trade inside it ... - bool ExtractWorkingZone( - XPOIState &htfState, - XPOIState &mtfState, - XPOIState &stfState, - int barIndex = 0 // - ) - { - // - bool result = false; - - // - if (barIndex < 0) - { - barIndex = 0; - } - int zIndex = barIndex; - - // - result = !HasWorkingZone(); - if (!result) - { - return result; - } - - // - result = IsValid(symbol) && - IsValid(period); - if (!result) - { - // - Clean(); - return result; - } - - // - datetime cTime = iTime( - symbol, - period, - zIndex // - ); - - // - result = - // - htfState.IsValid() && - htfState.HasChild() && - htfState.HasSupplyZones() && - htfState.HasDemandZones() && - // - mtfState.IsValid() && - mtfState.HasChild() && - mtfState.HasSupplyZones() && - mtfState.HasDemandZones() && - // - stfState.IsValid() && - stfState.HasChild() - // - ; - if (!result) - { - return result; - } - - // - // Retrieve Highest Supply Zone ... - int hSupplyIDX = GetHighest(htfState.supplyZones); - int lDemandIDX = GetLowest(htfState.demandZones); - - // - result = - // - IsValidIndex(hSupplyIDX) && - IsValidIndex(lDemandIDX) - // - ; - if (!result) - { - return result; - } - - // - supplyZone = htfState.supplyZones[hSupplyIDX]; - demandZone = htfState.demandZones[lDemandIDX]; - - // - result = - // - supplyZone != NULL && - demandZone != NULL && - supplyZone.IsValid() && - demandZone.IsValid() - // - ; - if (!result) - { - // - Clean(); - return result; - } - - // - // Check Validation of Supply and Demand Zones ... - lDemandIDX = GetLowest(mtfState.demandZones); - hSupplyIDX = GetHighest(mtfState.supplyZones); - result = IsValidIndex(lDemandIDX) && - IsValidIndex(hSupplyIDX); - if (!result) - { - // - Clean(); - return result; - } - - // - // Validate Supply and Demand ... - bool isMTFHSupplyInside = - IsInside( - mtfState.supplyZones[hSupplyIDX], - supplyZone); - bool isMTFLDemandInside = - IsInside( - mtfState.demandZones[lDemandIDX], - demandZone // - ); - if (isMTFHSupplyInside && - !isMTFLDemandInside) - { - demandZone = mtfState.demandZones[lDemandIDX]; - } - else if (!isMTFHSupplyInside && - isMTFLDemandInside) - { - supplyZone = mtfState.supplyZones[hSupplyIDX]; - } - else if (isMTFHSupplyInside && - isMTFLDemandInside) - { - // - supplyZone = mtfState.supplyZones[hSupplyIDX]; - demandZone = mtfState.demandZones[lDemandIDX]; - } - - // - // Check Zones Validation ... - bool hasTrend = - supplyZone != NULL && - supplyZone.IsValid() && - demandZone != NULL && - demandZone.IsValid(); - result = hasTrend; - if (!result) - { - // - Clean(); - return result; - } - - // - datetime from = MathMax( - supplyZone.From(), - demandZone.From()); - - // - int fromIndex = iBarShift( - symbol, - period, - from // - ); - - // - // Detect Trend ... - ENUM_X_DIRECTION trend = X_DIRECTION_NONE; - datetime supplyTouch = NULL; - datetime demandTouch = NULL; - for (int i = zIndex; i < fromIndex; i++) - { - // - XOHCL iBar; - bool isInited = iBar.Init( - symbol, - period, - i // - ); - if (!isInited) - { - continue; - } - - // - bool isTouchSupplyZone = - // - iBar.low < supplyZone.Lower() && - iBar.GetUp() > supplyZone.Lower() - // - ; - if (isTouchSupplyZone && - !IsValid(supplyTouch)) - { - supplyTouch = iBar.time; - } - - // - bool isTouchDemandZone = - // - iBar.high > demandZone.Upper() && - iBar.GetDown() < demandZone.Upper() - // - ; - if (isTouchDemandZone && - !IsValid(demandTouch)) - { - demandTouch = iBar.time; - } - - // - bool canBreak = - IsValid(supplyTouch) && - IsValid(demandTouch); - - // - iBar.Clean(); - - // - if (canBreak) - { - break; - } - } - - // - hasTrend = - // - IsValid(supplyTouch) || - IsValid(demandTouch) - // - ; - if (hasTrend) - { - // - trend = - // - supplyTouch > demandTouch - ? X_DIRECTION_BEARISH - : X_DIRECTION_BULLISH - // - ; - } - - // - // Check Trend ... - result = hasTrend; - if (!result) - { - // - Clean(); - return result; - } - - // - bool hasBullishTrend = IsBullish(trend); - bool hasBearishTrend = IsBearish(trend); - - // - // Find Order Block and FVG for Trend Approve ... - - // - bool isBullishTrendApproved = false; - bool isBearishTrendApproved = false; - - // - // Now We Have to Detect at least One OrderBlock with FVG ... - // for Trend Approvement ... - bool hasOrderBlock = HasOrderBlock(); - bool hasFairValueGap = HasFairValueGap(); - if (!hasOrderBlock && - !hasFairValueGap) - { - // - int count = 0; - bool has = false; - - // - XCFVG *fvg = NULL; - XCOrderBlock *ob = NULL; - - // - has = mtfState.HasBullishOrderBlocks(); - count = mtfState.CountBullishOrderBlocks(); - - // - if (has) - { - // - // Check Order Block ... - for (int i = 0; i < count; i++) - { - // - XCOrderBlock *iOB = mtfState.bullishOrderBlocks[i]; - - // - iOB.To(cTime); - - // - // Check From Passes ... - bool isFromPassed = iOB.From() > demandZone.From(); - if (!isFromPassed) - { - continue; - } - - // - // Must inside DemandZone ... - bool isInsideDemand = IsInsideDiff( - iOB, - demandZone // - ); - if (!isInsideDemand) - { - continue; - } - - // - // Check Started ... - XOHCL startedBar; - ENUM_X_DIRECTION startedDir; - bool isStarted = iOB.IsStarted( - X_DIRECTION_BULLISH, - startedBar, - startedDir // - ); - if (!isStarted) - { - // - startedBar.Clean(); - continue; - } - - // - // Converts to Box ... - XBoxZone obBox; - bool hasOBBox = ToBox( - obBox, - iOB // - ); - if (!hasOBBox) - { - // - obBox.Clean(); - startedBar.Clean(); - continue; - } - - // - // Check Zone Must not Used before ... - bool isUsed = IsBoxUsed( - obBox, - startedBar.Index() - 1, - zIndex // - ); - if (isUsed) - { - // - obBox.Clean(); - startedBar.Clean(); - continue; - } - - // - ob = iOB; - - // - obBox.Clean(); - startedBar.Clean(); - - // - break; - } - - // - // Detect Fair Value Gap ... - if (ob != NULL && - ob.IsValid()) - { - // - has = stfState.HasBullishFairValueGaps(); - count = stfState.CountBullishFairValueGaps(); - if (has) - { - // - // Check Fir Value Gap ... - for (int i = 0; i < count; i++) - { - // - XCFVG *iFVG = stfState.bullishFairValueGaps[i]; - - // - iFVG.To(cTime); - - // - // Check From Passes ... - bool isFromPassed = iFVG.From() > ob.From(); - if (!isFromPassed) - { - continue; - } - - // - // Check Started ... - XOHCL startedBar; - ENUM_X_DIRECTION startedDir; - bool isStarted = iFVG.IsStarted( - X_DIRECTION_BULLISH, - startedBar, - startedDir // - ); - if (!isStarted) - { - // - startedBar.Clean(); - continue; - } - - // - // Converts to Box ... - XBoxZone fvgBox; - bool hasFVGBox = ToBox( - fvgBox, - iFVG // - ); - if (!hasFVGBox) - { - // - fvgBox.Clean(); - startedBar.Clean(); - continue; - } - - // - // Check Inside Order Block ... - bool isInside = IsInsideDiff( - iFVG, - ob, - true // Force Side Out ... - ); - if (!isInside) - { - continue; - } - - // - fvg = iFVG; - - // - fvgBox.Clean(); - startedBar.Clean(); - - // - break; - } - } - else - { - // - ob = NULL; - } - } - - // - if (ob != NULL && - fvg != NULL) - { - // - orderBlock = ob; - fairValueGap = fvg; - } - - // - hasOrderBlock = HasOrderBlock(); - hasFairValueGap = HasFairValueGap(); - isBullishTrendApproved = hasOrderBlock && - hasFairValueGap; - } - - // - if (!isBullishTrendApproved) - { - // - has = mtfState.HasBearishOrderBlocks(); - count = mtfState.CountBearishOrderBlocks(); - - // - if (has) - { - // - // Check Order Block ... - for (int i = 0; i < count; i++) - { - // - XCOrderBlock *iOB = mtfState.bearishOrderBlocks[i]; - - // - iOB.To(cTime); - - // - // Check From Passes ... - bool isFromPassed = iOB.From() > supplyZone.From(); - if (!isFromPassed) - { - continue; - } - - // - // Must inside DemandZone ... - bool isInsideDemand = IsInsideDiff( - iOB, - supplyZone // - ); - if (!isInsideDemand) - { - continue; - } - - // - // Check Started ... - XOHCL startedBar; - ENUM_X_DIRECTION startedDir; - bool isStarted = iOB.IsStarted( - X_DIRECTION_BEARISH, - startedBar, - startedDir // - ); - if (!isStarted) - { - // - startedBar.Clean(); - continue; - } - - // - // Converts to Box ... - XBoxZone obBox; - bool hasOBBox = ToBox( - obBox, - iOB // - ); - if (!hasOBBox) - { - // - obBox.Clean(); - startedBar.Clean(); - continue; - } - - // - // Check Zone Must not Used before ... - bool isUsed = IsBoxUsed( - obBox, - startedBar.Index() - 1, - zIndex // - ); - if (isUsed) - { - // - obBox.Clean(); - startedBar.Clean(); - continue; - } - - // - ob = iOB; - - // - obBox.Clean(); - startedBar.Clean(); - - // - break; - } - - // - // Detect Fair Value Gap ... - if (ob != NULL && - ob.IsValid()) - { - // - has = stfState.HasBearishFairValueGaps(); - count = stfState.CountBearishFairValueGaps(); - if (has) - { - // - // Check Fir Value Gap ... - for (int i = 0; i < count; i++) - { - // - XCFVG *iFVG = stfState.bearishFairValueGaps[i]; - - // - iFVG.To(cTime); - - // - // Check From Passes ... - bool isFromPassed = iFVG.From() > ob.From(); - if (!isFromPassed) - { - continue; - } - - // - // Check Started ... - XOHCL startedBar; - ENUM_X_DIRECTION startedDir; - bool isStarted = iFVG.IsStarted( - X_DIRECTION_BEARISH, - startedBar, - startedDir // - ); - if (!isStarted) - { - // - startedBar.Clean(); - continue; - } - - // - // Converts to Box ... - XBoxZone fvgBox; - bool hasFVGBox = ToBox( - fvgBox, - iFVG // - ); - if (!hasFVGBox) - { - // - fvgBox.Clean(); - startedBar.Clean(); - continue; - } - - // - // Check Inside Order Block ... - bool isInside = IsInsideDiff( - iFVG, - ob, - true // Force Side Out ... - ); - if (!isInside) - { - continue; - } - - // - fvg = iFVG; - - // - fvgBox.Clean(); - startedBar.Clean(); - - // - break; - } - } - else - { - // - ob = NULL; - } - } - - // - if (ob != NULL && - fvg != NULL) - { - // - orderBlock = ob; - fairValueGap = fvg; - } - - // - hasOrderBlock = HasOrderBlock(); - hasFairValueGap = HasFairValueGap(); - isBearishTrendApproved = hasOrderBlock && - hasFairValueGap; - } - } - } - - // - // Check Trend Approved ... - bool isTrendApproved = - hasOrderBlock && - hasFairValueGap && - (isBullishTrendApproved || - isBearishTrendApproved); - result = isTrendApproved; - if (!result) - { - // - Clean(); - return result; - } - - // - // Prepare Working Zone ... - workingZone.symbol = symbol; - workingZone.period = period; - - // - workingZone.upper = supplyZone.Lower(); - workingZone.zoneUpper = supplyZone.Upper(); - - // - workingZone.lower = demandZone.Upper(); - workingZone.zoneLower = demandZone.Lower(); - - // - workingZone.from = from; - - // - double upper = workingZone.upper; - double range = - workingZone.upper - workingZone.lower; - double ranegPercent = range / 100; - double quarterValue = ranegPercent * 25; - - // - workingZone.quarter1 = upper - (quarterValue * 1); - workingZone.quarter2 = upper - (quarterValue * 2); - workingZone.quarter3 = upper - (quarterValue * 3); - - // - result = workingZone.IsValid(); - if (!result) - { - Clean(); - } - - // - return result; - } - - // - bool IsWorkingZoneDestroyed( - ENUM_X_DIRECTION &destroyedDir, - int barIndex = 0, - ENUM_TIMEFRAMES forPeriod = NULL // - ) - { - // - bool result = false; - - // - if (barIndex < 0) - { - barIndex = 0; - } - - // - if (!IsValid(forPeriod)) - { - forPeriod = period; - } - - // - destroyedDir = X_DIRECTION_NONE; - - // - result = workingZone.IsValid(); - if (!result) - { - return result; - } - - // - result = workingZone.IsDestroyed( - destroyedDir, - barIndex, - forPeriod // - ); - - // - return result; - } - - // - bool DetectTrend( - ENUM_X_DIRECTION &trend, - int barIndex = 0, - ENUM_TIMEFRAMES forPeriod = NULL // - ) - { - // - bool result = false; - - // - if (barIndex < 0) - { - barIndex = 0; - } - - // - if (forPeriod == NULL) - { - forPeriod = period; - } - - // - trend = X_DIRECTION_NONE; - - // - result = HasWorkingZone(); - if (!result) - { - return result; - } - - // - int FromIndex = iBarShift( - symbol, - forPeriod, - workingZone.from // - ); - - // - datetime supplyTouch = NULL; - datetime demandTouch = NULL; - for (int i = barIndex; i < FromIndex; i++) - { - // - XOHCL iBar; - bool isInited = iBar.Init( - symbol, - forPeriod, - i // - ); - if (!isInited) - { - continue; - } - - // - bool isTouchSupplyZone = - // - iBar.low < supplyZone.Lower() && - iBar.GetUp() > supplyZone.Lower() - // - ; - if (isTouchSupplyZone && - !IsValid(supplyTouch)) - { - supplyTouch = iBar.time; - } - - // - bool isTouchDemandZone = - // - iBar.high > demandZone.Upper() && - iBar.GetDown() < demandZone.Upper() - // - ; - if (isTouchDemandZone && - !IsValid(demandTouch)) - { - demandTouch = iBar.time; - } - - // - bool canBreak = - IsValid(supplyTouch) && - IsValid(demandTouch); - - // - iBar.Clean(); - - // - if (canBreak) - { - break; - } - } - - // - result = - // - IsValid(supplyTouch) || - IsValid(demandTouch) - // - ; - if (result) - { - // - trend = - // - supplyTouch > demandTouch - ? X_DIRECTION_BEARISH - : X_DIRECTION_BULLISH - // - ; - } - - // - return result; - } - - // - bool DetectStartZones( - ENUM_X_DIRECTION forDir, - XPOIState &obState, - XPOIState &fvgState, - XPOIState &otherState, - XC121SMCCycleHelper *cycleHelper // - ) - { - // - bool result = false; - - // - result = obState.IsValid() && - obState.HasChild() && - fvgState.IsValid() && - fvgState.HasChild() && - otherState.IsValid() && - otherState.HasChild() && - HasDirection(forDir); - if (!result) - { - return result; - } - - // - bool isBullish = IsBullish(forDir); - - // - int idx = -1; - int count = 0; - int has = false; - - // - X121SMCXWZZone startZone; - X121SMCXWZZone lastStartZone; - bool hasLastStartZone = HasStartZones(); - if (hasLastStartZone) - { - // - int startZonesCount = CountStartZones(); - lastStartZone = startZones[startZonesCount - 1]; - } - - // - if (isBullish) - { - // - has = obState.HasBullishOrderBlocks(); - if (has) - { - // - count = obState.CountBullishOrderBlocks(); - for (int i = 0; i < count; i++) - { - // - XCOrderBlock *iOB = obState.bullishOrderBlocks[i]; - - // - bool isFromPassed = - !hasLastStartZone - ? true - : iOB.From() > lastStartZone.ob.From(); - if (!isFromPassed) - { - // - ZeroMemory(iOB); - continue; - } - - // - XOHCL startedBar; - ENUM_X_DIRECTION startedDir; - bool isStarted = iOB.IsStarted( - forDir, - startedBar, - startedDir // - ); - if (!isStarted) - { - // - ZeroMemory(iOB); - startedBar.Clean(); - continue; - } - - // - XOHCL activatedBar; - ENUM_X_DIRECTION activatedDir; - bool isActivated = iOB.IsActivated( - forDir, - activatedBar, - activatedDir // - ); - if (isActivated) - { - // - ZeroMemory(iOB); - startedBar.Clean(); - activatedBar.Clean(); - continue; - } - - // - // Validate Zone Iverse Breake ... - XOHCL breakedBar; - ENUM_X_DIRECTION breakedDir; - bool isBreaked = iOB.IsBreaked( - Opposit(forDir), - breakedBar, - breakedDir, - true // Ignore Activation ... - ); - if (isBreaked) - { - // - ZeroMemory(iOB); - startedBar.Clean(); - breakedBar.Clean(); - activatedBar.Clean(); - continue; - } - - // - bool isPlacePassed = - !IsInsideDiff( - iOB, - demandZone // - ) && - (!hasLastStartZone - ? workingZone.IsValid() && - HasOrderBlock() && - forDir == orderBlock.GetDirection() - ? IsAbove( - iOB, - orderBlock, - true // Ignore Inside ... - ) - : true - : lastStartZone.HasOB() && - IsAbove( - iOB, - lastStartZone.ob, - true // Ignore Inside ... - )); - if (!isPlacePassed) - { - // - ZeroMemory(iOB); - startedBar.Clean(); - activatedBar.Clean(); - continue; - } - - // - // Attache OB ... - startZone.ob = iOB; - - // - // Now we Have to Find Specified FVG ... - has = fvgState.HasBullishFairValueGaps(); - if (has) - { - // - int jCount = fvgState.CountBullishFairValueGaps(); - for (int j = 0; j < jCount; j++) - { - // - XCFVG *jFVG = fvgState.bullishFairValueGaps[j]; - - // - startedBar.Clean(); - startedDir = X_DIRECTION_NONE; - isStarted = jFVG.IsStarted( - forDir, - startedBar, - startedDir // - ); - if (!isStarted) - { - // - ZeroMemory(jFVG); - startedBar.Clean(); - continue; - } - - // - activatedBar.Clean(); - activatedDir = X_DIRECTION_NONE; - isActivated = jFVG.IsActivated( - forDir, - activatedBar, - activatedDir // - ); - if (isActivated) - { - // - ZeroMemory(jFVG); - startedBar.Clean(); - activatedBar.Clean(); - continue; - } - - // - // Validate Zone Iverse Breake ... - breakedBar.Clean(); - breakedDir = X_DIRECTION_NONE; - bool isBreaked = jFVG.IsBreaked( - Opposit(forDir), - breakedBar, - breakedDir, - true // Ignore Activation ... - ); - if (isBreaked) - { - // - ZeroMemory(jFVG); - startedBar.Clean(); - breakedBar.Clean(); - activatedBar.Clean(); - continue; - } - - // - isPlacePassed = - // - !IsInsideDiff( - jFVG, - demandZone // - ) && - IsAboveDiff( - jFVG, - iOB, - true // Ignore Inside ... - ) - // - ; - if (!isPlacePassed) - { - // - ZeroMemory(jFVG); - startedBar.Clean(); - activatedBar.Clean(); - } - - // - startZone.fvg = jFVG; - } - } - - // - startedBar.Clean(); - activatedBar.Clean(); - } - } - } - else - { - // - has = obState.HasBearishOrderBlocks(); - if (has) - { - // - count = obState.CountBearishOrderBlocks(); - for (int i = 0; i < count; i++) - { - // - XCOrderBlock *iOB = obState.bearishOrderBlocks[i]; - - // - bool isFromPassed = - !hasLastStartZone - ? true - : iOB.From() > lastStartZone.ob.From(); - if (!isFromPassed) - { - // - ZeroMemory(iOB); - continue; - } - - // - XOHCL startedBar; - ENUM_X_DIRECTION startedDir; - bool isStarted = iOB.IsStarted( - forDir, - startedBar, - startedDir // - ); - if (!isStarted) - { - // - ZeroMemory(iOB); - startedBar.Clean(); - continue; - } - - // - XOHCL activatedBar; - ENUM_X_DIRECTION activatedDir; - bool isActivated = iOB.IsActivated( - forDir, - activatedBar, - activatedDir // - ); - if (isActivated) - { - // - ZeroMemory(iOB); - startedBar.Clean(); - activatedBar.Clean(); - continue; - } - - // - // Validate Zone Iverse Breake ... - XOHCL breakedBar; - ENUM_X_DIRECTION breakedDir; - bool isBreaked = iOB.IsBreaked( - Opposit(forDir), - breakedBar, - breakedDir, - true // Ignore Activation ... - ); - if (isBreaked) - { - // - ZeroMemory(iOB); - startedBar.Clean(); - breakedBar.Clean(); - activatedBar.Clean(); - continue; - } - - // - bool isPlacePassed = - !IsInsideDiff( - iOB, - supplyZone // - ) && - (!hasLastStartZone - ? workingZone.IsValid() && - HasOrderBlock() && - forDir == orderBlock.GetDirection() - ? IsBelow( - iOB, - orderBlock, - true // Ignore Inside ... - ) - : true - : lastStartZone.HasOB() && - IsBelow( - iOB, - lastStartZone.ob, - true // Ignore Inside ... - )); - if (!isPlacePassed) - { - // - ZeroMemory(iOB); - startedBar.Clean(); - activatedBar.Clean(); - continue; - } - - // - // Attache OB ... - startZone.ob = iOB; - - // - // Now we Have to Find Specified FVG ... - has = fvgState.HasBearishFairValueGaps(); - if (has) - { - // - int jCount = fvgState.CountBearishFairValueGaps(); - for (int j = 0; j < jCount; j++) - { - // - XCFVG *jFVG = fvgState.bearishFairValueGaps[j]; - - // - startedBar.Clean(); - startedDir = X_DIRECTION_NONE; - isStarted = jFVG.IsStarted( - forDir, - startedBar, - startedDir // - ); - if (!isStarted) - { - // - ZeroMemory(jFVG); - startedBar.Clean(); - continue; - } - - // - activatedBar.Clean(); - activatedDir = X_DIRECTION_NONE; - isActivated = jFVG.IsActivated( - forDir, - activatedBar, - activatedDir // - ); - if (isActivated) - { - // - ZeroMemory(jFVG); - startedBar.Clean(); - activatedBar.Clean(); - continue; - } - - // - // Validate Zone Iverse Breake ... - breakedBar.Clean(); - breakedDir = X_DIRECTION_NONE; - bool isBreaked = jFVG.IsBreaked( - Opposit(forDir), - breakedBar, - breakedDir, - true // Ignore Activation ... - ); - if (isBreaked) - { - // - ZeroMemory(jFVG); - startedBar.Clean(); - breakedBar.Clean(); - activatedBar.Clean(); - continue; - } - - // - isPlacePassed = - // - !IsInsideDiff( - jFVG, - supplyZone // - ) && - IsBelowDiff( - jFVG, - iOB, - true // Ignore Inside ... - ) - // - ; - if (!isPlacePassed) - { - // - ZeroMemory(jFVG); - startedBar.Clean(); - activatedBar.Clean(); - } - - // - startZone.fvg = jFVG; - } - } - - // - startedBar.Clean(); - activatedBar.Clean(); - } - } - } - - // - bool hasOBFVG = startZone.HasOB() && - startZone.HasFVG(); - result = hasOBFVG; - if (!result) - { - // - startZone.Clean(); - lastStartZone.Clean(); - - // - return result; - } - - // - XBoxZone startBox; - bool hasStartBox = startZone.AsBox(startBox); - result = hasStartBox; - if (!result) - { - // - startBox.Clean(); - startZone.Clean(); - lastStartZone.Clean(); - - // - return result; - } - - // - // Detect Other Zones Inside Box ... - XBoxZone tmpBoxes[]; - - // - // Supply Zones ... - has = otherState.HasSupplyZones(); - if (has) - { - // - count = ToBox( - otherState.supplyZones, - tmpBoxes // - ); - - // - has = IsValidSize(count); - if (has) - { - // - for (int i = 0; i < count; i++) - { - // - XBoxZone iBox = tmpBoxes[i]; - - // - bool isPlacePassed = - // - IsBoxInside( - iBox, - startBox, - false, - false // - ) - // - ; - if (!isPlacePassed) - { - // - iBox.Clean(); - continue; - } - - // - startZone.supply = otherState.supplyZones[i]; - - // - iBox.Clean(); - break; - } - } - } - - // - // Demand Zones ... - Clean(tmpBoxes); - has = otherState.HasDemandZones(); - if (has) - { - // - count = ToBox( - otherState.demandZones, - tmpBoxes // - ); - - // - has = IsValidSize(count); - if (has) - { - // - for (int i = 0; i < count; i++) - { - // - XBoxZone iBox = tmpBoxes[i]; - - // - bool isPlacePassed = - // - IsBoxInside( - iBox, - startBox, - false, - false // - ) - // - ; - if (!isPlacePassed) - { - // - iBox.Clean(); - continue; - } - - // - startZone.demand = otherState.demandZones[i]; - - // - iBox.Clean(); - break; - } - } - } - - // - // Support Zones ... - Clean(tmpBoxes); - has = otherState.HasSupportZones(); - if (has) - { - // - count = ToBox( - otherState.supportZones, - tmpBoxes // - ); - - // - has = IsValidSize(count); - if (has) - { - // - for (int i = 0; i < count; i++) - { - // - XBoxZone iBox = tmpBoxes[i]; - - // - bool isPlacePassed = - // - IsBoxInside( - iBox, - startBox, - false, - false // - ) - // - ; - if (!isPlacePassed) - { - // - iBox.Clean(); - continue; - } - - // - startZone.support = otherState.supportZones[i]; - - // - iBox.Clean(); - break; - } - } - } - - // - // Resistance Zones ... - Clean(tmpBoxes); - has = otherState.HasResistanceZones(); - if (has) - { - // - count = ToBox( - otherState.resistanceZones, - tmpBoxes // - ); - - // - has = IsValidSize(count); - if (has) - { - // - for (int i = 0; i < count; i++) - { - // - XBoxZone iBox = tmpBoxes[i]; - - // - bool isPlacePassed = - // - IsBoxInside( - iBox, - startBox, - false, - false // - ) - // - ; - if (!isPlacePassed) - { - // - iBox.Clean(); - continue; - } - - // - startZone.resistance = otherState.resistanceZones[i]; - - // - iBox.Clean(); - break; - } - } - } - - // - result = startZone.IsValid() && - startZone.HasDirection(); - if (result) - { - // - AddRef( - startZone, - startZones // - ); - } - - // - Clean(tmpBoxes); - startBox.Clean(); - startZone.Clean(); - lastStartZone.Clean(); - - // - return result; - } - - // - void ValidateStartZones( - int barIndex = 0, - ENUM_TIMEFRAMES forPeriod = NULL // - ) - { - // - bool has = HasStartZones(); - if (!has) - { - return; - } - - // - X121SMCXWZZone tmpZones[]; - int count = CountStartZones(); - Copy( - startZones, - tmpZones // - ); - for (int i = 0; i < count; i++) - { - // - bool isValid = tmpZones[i].ValidateZone( - barIndex, - forPeriod // - ); - if (!isValid) - { - // - ArrayRemove( - startZones, - i, - 1 // - ); - } - } - - // - Clean(tmpZones); - } - - // - void DetectPriority( - ENUM_X121SMC_XWZ_PRIORITY &bullish, - ENUM_X121SMC_XWZ_PRIORITY &bearish, - int barIndex = 0, - ENUM_TIMEFRAMES forPeriod = NULL // - ) - { - // - bullish = X121SMC_XWZ_PRIORITY_NONE; - bearish = X121SMC_XWZ_PRIORITY_NONE; - - // - if (barIndex < 0) - { - barIndex = 0; - } - - // - if (!IsValid(forPeriod)) - { - forPeriod = period; - } - - // - bool hasWorkingZone = HasWorkingZone(); - if (!hasWorkingZone) - { - return; - } - - // - XOHCL zBar; - bool isInited = zBar.Init( - symbol, - forPeriod, - barIndex // - ); - if (!isInited) - { - // - zBar.Clean(); - return; - } - - // - XOHCL cBar; - isInited = zBar.GetPreviousBar(cBar); - if (!isInited) - { - // - zBar.Clean(); - cBar.Clean(); - return; - } - - // - // ZoneUpper, Upper ... - if (cBar.low > workingZone.upper && - cBar.high < workingZone.zoneUpper && - zBar.low > workingZone.upper && - zBar.high < workingZone.zoneUpper) - { - // - bullish = X121SMC_XWZ_PRIORITY_NONE; - bearish = X121SMC_XWZ_PRIORITY_STRONG_HIGH; - } - // - // Upper, Quarter1 ... - else if (cBar.low > workingZone.quarter1 && - cBar.high < workingZone.upper && - zBar.low > workingZone.quarter1 && - zBar.high < workingZone.upper) - { - // - bullish = X121SMC_XWZ_PRIORITY_WEAK; - bearish = X121SMC_XWZ_PRIORITY_HIGH; - } - // - // Quarter1, Quarter2 ... - else if (cBar.low > workingZone.quarter2 && - cBar.high < workingZone.quarter1 && - zBar.low > workingZone.quarter2 && - zBar.high < workingZone.quarter1) - { - // - bullish = X121SMC_XWZ_PRIORITY_LOW; - bearish = X121SMC_XWZ_PRIORITY_REGULAR; - } - // - // Quarter2, Quarter3 ... - else if (cBar.low > workingZone.quarter3 && - cBar.high < workingZone.quarter2 && - zBar.low > workingZone.quarter3 && - zBar.high < workingZone.quarter2) - { - // - bullish = X121SMC_XWZ_PRIORITY_REGULAR; - bearish = X121SMC_XWZ_PRIORITY_LOW; - } - // - // Quarter3, Lower ... - else if (cBar.low > workingZone.lower && - cBar.high < workingZone.quarter3 && - zBar.low > workingZone.lower && - zBar.high < workingZone.quarter3) - { - // - bullish = X121SMC_XWZ_PRIORITY_HIGH; - bearish = X121SMC_XWZ_PRIORITY_WEAK; - } - // - // Lower, ZoneLower ... - else if (cBar.low > workingZone.zoneLower && - cBar.high < workingZone.lower && - zBar.low > workingZone.zoneLower && - zBar.high < workingZone.lower) - { - // - bullish = X121SMC_XWZ_PRIORITY_STRONG_HIGH; - bearish = X121SMC_XWZ_PRIORITY_NONE; - } - - // - zBar.Clean(); - cBar.Clean(); - } - - // - bool HasConditions( - double &_pivot, - double &_point, - ENUM_X_DIRECTION &conditionsDir, - XPOIState &state, - int barIndex = 0, - ENUM_TIMEFRAMES forPeriod = NULL // - ) - { - // - bool result = false; - - // - _pivot = 0; - _point = 0; - conditionsDir = X_DIRECTION_NONE; - - // - if (barIndex < 0) - { - barIndex = 0; - } - - // - if (forPeriod == NULL) - { - forPeriod = period; - } - - // - result = - // - IsValid(symbol) && - IsValid(period) && - state.IsValid() && - HasWorkingZone() && - state.HasChild() - // - ; - if (!result) - { - return result; - } - - // - result = false; - - // - ValidateStartZones( - barIndex, - forPeriod // - ); - - // - // Detect Conditions Based On Start Zones ... - bool hasStartZones = HasStartZones(); - if (hasStartZones) - { - // - int selectedIndex = -1; - int count = CountStartZones(); - for (int i = 0; i < count; i++) - { - // - X121SMCXWZZone iStartZone = startZones[i]; - - // - XBoxZone selectedBox; - bool hasConditions = false; - bool isBullish = iStartZone.IsBullish(); - - // - // Conditions Inside Box ... - bool isPriceInside = iStartZone.IsPriceInside( - selectedBox, - barIndex, - forPeriod, - false, - false // - ); - if (isPriceInside) - { - // - // hasConditions = iStartZone.HasInsideConditions( - // state, - // barIndex, - // period // - // ); - - // - hasConditions = true; - - // - if (hasConditions) - { - // - _pivot = - // - isBullish - ? selectedBox.lower - : selectedBox.upper - // - ; - - // - _point = - // - isBullish - ? selectedBox.upper - : selectedBox.lower - // - ; - - // - conditionsDir = selectedBox.dir; - result = hasConditions; - iStartZone.Clean(); - break; - } - } - - // // - // // Order Block Rejection Conditions ... - // bool hasOBBox = ToBox( - // selectedBox, - // iStartZone.ob // - // ); - // if (hasOBBox && - // !hasConditions) - // { - // // - // hasConditions = iStartZone.HasBoxConitions( - // selectedBox, - // state, - // barIndex, - // forPeriod // - // ); - - // // - // if (hasConditions) - // { - // // - // _pivot = - // // - // isBullish - // ? selectedBox.lower - // : selectedBox.upper - // // - // ; - - // // - // _point = - // // - // isBullish - // ? selectedBox.upper - // : selectedBox.lower - // // - // ; - - // // - // conditionsDir = selectedBox.dir; - // result = hasConditions; - // iStartZone.Clean(); - // break; - // } - // } - - // // - // // Fair Value Gap Rejection Conditions ... - // bool hasFVGBox = ToBox( - // selectedBox, - // iStartZone.fvg // - // ); - // if (hasFVGBox) - // { - // // - // hasConditions = iStartZone.HasBoxConitions( - // selectedBox, - // state, - // barIndex, - // forPeriod // - // ); - - // // - // if (hasConditions) - // { - // // - // _pivot = - // // - // isBullish - // ? selectedBox.lower - // : selectedBox.upper - // // - // ; - - // // - // _point = - // // - // isBullish - // ? selectedBox.upper - // : selectedBox.lower - // // - // ; - - // // - // conditionsDir = selectedBox.dir; - // result = hasConditions; - // iStartZone.Clean(); - // break; - // } - // } - - // - iStartZone.Clean(); - } - - // - if (result && - IsValidIndex(selectedIndex)) - { - // - ArrayRemove( - startZones, - selectedIndex, - 1 // - ); - } - } - - // - // Detect Conditions Based On Working Zones ... - if (!result) - { - // - // Detect Result Based On WorkingZone ... - } - - // - if (!result) - { - // - _point = 0; - _pivot = 0; - conditionsDir = X_DIRECTION_NONE; - - // - return result; - } - - // - return result; - } - - // -}; - -// -bool X121SMCXWZCheckPriceInside( - XOHCL &zBar, - XOHCL &cBar, - double upper, - double lower // -) -{ - // - bool result = false; - - // - result = zBar.IsValid() && - cBar.IsValid() && - upper > 0 && - lower > 0 && - upper > lower && - zBar.time > cBar.time; - if (!result) - { - return result; - } - - // - result = - // - zBar.high < upper && - cBar.high < upper && - // - zBar.low > lower && - cBar.low > lower - // - ; - - // - return result; -} - -// \ 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 9a7025d0..00000000 --- a/Documents/BKP/x-121.smc.xwz.signal.lib copy.mq5 +++ /dev/null @@ -1,3749 +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_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 X121SMCXWZZone -{ - // - // Props ... - XCFVG *fvg; - XCOrderBlock *ob; - XCSupplyZone *supply; - XCDemandZone *demand; - XCSupportZone *support; - XCResistanceZone *resistance; - - // - XOHCL swingBar; - XOHCL breakerBar; - XOHCL momentumBar; - XOHCL rejectionBar; - XBoxZone appliedBox; - - // - // Constructor ... - X121SMCXWZZone() - { - Clean(); - } - - // - // Tools ... - - // - void Clean() - { - // - ZeroMemory(ob); - ZeroMemory(fvg); - ZeroMemory(supply); - ZeroMemory(demand); - ZeroMemory(support); - ZeroMemory(resistance); - - // - swingBar.Clean(); - breakerBar.Clean(); - appliedBox.Clean(); - momentumBar.Clean(); - rejectionBar.Clean(); - } - - // - bool IsValid() - { - // - return HasOB() && - HasFVG() && - HasDirection(); - } - - // - bool AsBox(XBoxZone &box) - { - // - bool result = false; - - // - box.Clean(); - - // - result = IsValid() && - HasDirection(); - if (!result) - { - return result; - } - - // - XBoxZone obBox; - bool hasOBBox = ToBox( - obBox, - ob // - ); - result = hasOBBox; - if (!result) - { - // - box.Clean(); - obBox.Clean(); - return result; - } - - // - box = obBox; - - // - obBox.Clean(); - - // - bool hasOB = HasOB(); - bool hasFVG = HasFVG(); - bool hasSupply = HasSupply(); - bool hasDemand = HasDemand(); - bool hasSupport = HasSupport(); - bool hasResistance = HasResistance(); - - // - // OB Compared since box used obBox ... - - // - if (hasFVG) - { - // - if (fvg.Upper() > box.upper) - { - box.upper = fvg.Upper(); - } - - // - if (fvg.Lower() < box.lower) - { - box.lower = fvg.Lower(); - } - } - - // - result = box.IsValid(); - - // - return result; - } - - // - bool HasOB() - { - return ob != NULL && - ob.IsValid(); - } - - // - bool HasFVG() - { - return fvg != NULL && - fvg.IsValid(); - } - - // - bool HasSupply() - { - return supply != NULL && - supply.IsValid(); - } - - // - bool HasDemand() - { - return demand != NULL && - demand.IsValid(); - } - - // - bool HasSupport() - { - return support != NULL && - support.IsValid(); - } - - // - bool HasResistance() - { - return resistance != NULL && - resistance.IsValid(); - } - - // - bool IsBullish() - { - // - return HasOB() && - ob.IsBullish() && - HasFVG() && - fvg.IsBullish(); - } - - // - bool IsBearish() - { - // - return HasOB() && - ob.IsBearish() && - HasFVG() && - fvg.IsBearish(); - } - - // - bool HasDirection() - { - return IsBullish() || - IsBearish(); - } - - // - bool ValidateZone( - int barIndex = 0, - ENUM_TIMEFRAMES forPeriod = NULL // - ) - { - // - bool result = false; - - // - if (barIndex < 0) - { - barIndex = 0; - } - - // - result = IsValid() && - HasDirection(); - if (!result) - { - return result; - } - - // - string symbol = ob.GetSymbol(); - if (forPeriod == NULL) - { - forPeriod = ob.GetPeriod(); - } - ENUM_X_DIRECTION forDir = GetDirection(); - - // - XOHCL cBar; - result = cBar.Init( - symbol, - forPeriod, - barIndex + 1 // - ); - if (!result) - { - // - cBar.Clean(); - return result; - } - - // - bool isBreaked = - IsBullish(forDir) - ? cBar.close < ob.Lower() || - cBar.close < fvg.Lower() - : cBar.close > ob.Upper() || - cBar.close > fvg.Upper(); - result = !isBreaked; - - // - cBar.Clean(); - - // - return result; - } - - // - ENUM_X_DIRECTION GetDirection() - { - // - ENUM_X_DIRECTION result = X_DIRECTION_NONE; - - // - bool hasDirection = HasDirection(); - if (!hasDirection) - { - return result; - } - - // - bool isBullish = IsBullish(); - - // - result = - isBullish - ? X_DIRECTION_BULLISH - : X_DIRECTION_BEARISH; - - // - return result; - } - - // - bool IsPriceInside( - XBoxZone &box, - int barIndex = 0, - ENUM_TIMEFRAMES forPeriod = NULL, - bool forceOB = false, - bool forceFVG = false // - ) - { - // - bool result = false; - - // - box.Clean(); - - // - if (barIndex < 0) - { - barIndex = 0; - } - - // - result = IsValid() && - HasOB() && - HasFVG() && - HasDirection(); - if (!result) - { - return result; - } - - // - string symbol = ob.GetSymbol(); - if (forPeriod == NULL) - { - forPeriod = ob.GetPeriod(); - } - - // - ENUM_X_DIRECTION forDir = ob.GetDirection(); - bool isBullish = IsBullish(forDir); - - // - // Check Start Bars ... - - // - XOHCL obStartedBar; - ENUM_X_DIRECTION obStartedDir; - bool isOBStarted = ob.IsStarted( - forDir, - obStartedBar, - obStartedDir // - ); - result = isOBStarted; - if (!result) - { - return result; - } - - // - XOHCL fvgStartedBar; - ENUM_X_DIRECTION fvgStartedDir; - bool isFVGStarted = fvg.IsStarted( - forDir, - fvgStartedBar, - fvgStartedDir // - ); - result = isFVGStarted; - if (!result) - { - return result; - } - - // - // Retrieve Bars ... - - // - XOHCL zBar; - result = zBar.Init( - symbol, - forPeriod, - barIndex // - ); - if (!result) - { - // - box.Clean(); - zBar.Clean(); - - // - return result; - } - - // - XOHCL cBar; - result = zBar.GetPreviousBar(cBar); - if (!result) - { - // - box.Clean(); - zBar.Clean(); - cBar.Clean(); - - // - return result; - } - - // - XOHCL pBar; - result = cBar.GetPreviousBar(pBar); - if (!result) - { - // - box.Clean(); - zBar.Clean(); - cBar.Clean(); - pBar.Clean(); - - // - return result; - } - - // - bool isPriceInsideOB = X121SMCXWZCheckPriceInside( - zBar, - cBar, - ob.Upper(), - ob.Lower() // - ); - - // - // isBullish - // ? ( - // // - // pBar.close > ob.Upper() && - // cBar.low <= ob.Upper() && - // cBar.close <= ob.Upper() && - // zBar.open <= ob.Upper() - // // - // ) - // : ( - // // - // pBar.close < ob.Lower() && - // cBar.high >= ob.Lower() && - // cBar.close >= ob.Lower() && - // zBar.open >= ob.Lower() - // // - // ); - - // - bool isPriceInsideFVG = X121SMCXWZCheckPriceInside( - zBar, - cBar, - fvg.Upper(), - fvg.Lower() // - ); - - // - // isBullish - // ? ( - // // - // pBar.close > fvg.Upper() && - // cBar.low <= fvg.Upper() && - // cBar.close <= fvg.Upper() && - // zBar.open <= fvg.Upper() - // // - // ) - // : ( - // // - // pBar.close < fvg.Lower() && - // cBar.high >= fvg.Lower() && - // cBar.close >= fvg.Lower() && - // zBar.open >= fvg.Lower() - // // - // ); - - // - if ((forceOB && forceFVG) || - (!forceOB && !forceFVG)) - { - // - result = - isPriceInsideOB || - isPriceInsideFVG; - } - else if (forceOB) - { - result = isPriceInsideOB; - } - else if (forceFVG) - { - result = isPriceInsideFVG; - } - - // - if (result) - { - // - if (isPriceInsideOB && !isPriceInsideFVG) - { - // - result = ToBox( - box, - ob // - ); - } - else if (isPriceInsideFVG && !isPriceInsideOB) - { - // - result = ToBox( - box, - fvg // - ); - } - else if (isPriceInsideOB && isPriceInsideFVG) - { - result = AsBox(box); - } - } - - // - zBar.Clean(); - cBar.Clean(); - pBar.Clean(); - - // - return result; - } - - // - bool HasInsideConditions( - XPOIState &state, - int barIndex = 0, - ENUM_TIMEFRAMES forPeriod = NULL // - ) - { - // - bool result = false; - - // - if (barIndex < 0) - { - barIndex = 0; - } - - // - swingBar.Clean(); - breakerBar.Clean(); - appliedBox.Clean(); - momentumBar.Clean(); - rejectionBar.Clean(); - - // - XBoxZone zoneBox; - bool hasBox = AsBox(zoneBox); - - // - result = hasBox && - IsValid() && - HasDirection() && - state.IsValid() && - state.HasChild(); - if (!result) - { - // - swingBar.Clean(); - breakerBar.Clean(); - appliedBox.Clean(); - momentumBar.Clean(); - rejectionBar.Clean(); - - // - return result; - } - - // - string symbol = zoneBox.symbol; - if (!IsValid(forPeriod)) - { - forPeriod = zoneBox.period; - } - datetime cTime = iTime( - symbol, - forPeriod, - barIndex // - ); - - // - ENUM_X_DIRECTION forDir = zoneBox.dir; - bool isBullish = IsBullish(forDir); - - // - int count = 0; - bool has = false; - - // - XBoxZone supResBoxes[]; - int supresBoxesCount = 0; - bool hasSupResBoxes = false; - - // - has = state.HasSupportZones(); - if (has) - { - // - count = state.CountSupportZones(); - for (int i = 0; i < count; i++) - { - // - XCSupportZone *iZone = state.supportZones[i]; - - // - iZone.To(cTime); - - // - XBoxZone iBox; - bool hasBox = ToBox( - iBox, - iZone // - ); - if (!hasBox) - { - // - iBox.Clean(); - continue; - } - - // - // Check From ... - bool isInside = IsBoxInside( - iBox, - zoneBox // - ); - if (!isInside) - { - // - iBox.Clean(); - continue; - } - - // - AddRef( - iBox, - supResBoxes // - ); - - // - iBox.Clean(); - ZeroMemory(iZone); - } - - // - supresBoxesCount = ArraySize(supResBoxes); - hasSupResBoxes = IsValidSize(supresBoxesCount); - } - - // - has = state.HasResistanceZones(); - if (has) - { - // - count = state.CountResistanceZones(); - for (int i = 0; i < count; i++) - { - // - XCResistanceZone *iZone = state.resistanceZones[i]; - - // - iZone.To(cTime); - - // - XBoxZone iBox; - bool hasBox = ToBox( - iBox, - iZone // - ); - if (!hasBox) - { - // - iBox.Clean(); - continue; - } - - // - // Check From ... - bool isInside = IsBoxInside( - iBox, - zoneBox // - ); - if (!isInside) - { - // - iBox.Clean(); - continue; - } - - // - AddRef( - iBox, - supResBoxes // - ); - - // - iBox.Clean(); - ZeroMemory(iZone); - } - - // - supresBoxesCount = ArraySize(supResBoxes); - hasSupResBoxes = IsValidSize(supresBoxesCount); - } - - // - result = hasSupResBoxes; - if (!result) - { - // - Clean(supResBoxes); - - // - swingBar.Clean(); - breakerBar.Clean(); - appliedBox.Clean(); - momentumBar.Clean(); - rejectionBar.Clean(); - - // - return result; - } - - // - for (int i = 0; i < supresBoxesCount; i++) - { - // - XBoxZone iBox = supResBoxes[i]; - - // - bool hasBoxConditions = HasBoxConitions( - iBox, - state, - barIndex, - forPeriod // - ); - if (hasBoxConditions) - { - // - appliedBox = iBox; - result = true; - iBox.Clean(); - break; - } - - // - iBox.Clean(); - } - - // - if (!result) - { - // - swingBar.Clean(); - breakerBar.Clean(); - appliedBox.Clean(); - momentumBar.Clean(); - rejectionBar.Clean(); - } - - // - Clean(supResBoxes); - - // - return result; - } - - // - bool HasBoxConitions( - XBoxZone &box, - XPOIState &state, - int barIndex = 0, - ENUM_TIMEFRAMES forPeriod = NULL // - ) - { - // - bool result = false; - - // - if (barIndex < 0) - { - barIndex = 0; - } - - // - result = box.IsValid() && - IsValid() && - HasDirection(); - if (!result) - { - // - swingBar.Clean(); - breakerBar.Clean(); - appliedBox.Clean(); - momentumBar.Clean(); - rejectionBar.Clean(); - - // - return result; - } - - // - string symbol = box.symbol; - if (forPeriod == NULL) - { - forPeriod = box.period; - } - ENUM_X_DIRECTION forDir = box.dir; - bool isBullish = IsBullish(forDir); - - // - // Detect Bars ... - - // - XOHCL zBar; - result = zBar.Init( - symbol, - forPeriod, - barIndex // - ); - if (!result) - { - // - zBar.Clean(); - - // - swingBar.Clean(); - breakerBar.Clean(); - appliedBox.Clean(); - momentumBar.Clean(); - rejectionBar.Clean(); - - // - return result; - } - - // - XOHCL cBar; - result = zBar.GetPreviousBar(cBar); - if (!result) - { - // - zBar.Clean(); - cBar.Clean(); - - // - swingBar.Clean(); - breakerBar.Clean(); - appliedBox.Clean(); - momentumBar.Clean(); - rejectionBar.Clean(); - - // - return result; - } - - // - XOHCL pBar; - result = cBar.GetPreviousBar(pBar); - if (!result) - { - // - zBar.Clean(); - cBar.Clean(); - pBar.Clean(); - - // - swingBar.Clean(); - breakerBar.Clean(); - appliedBox.Clean(); - momentumBar.Clean(); - rejectionBar.Clean(); - - // - return result; - } - - // - XOHCL ppBar; - result = pBar.GetPreviousBar(ppBar); - if (!result) - { - // - zBar.Clean(); - cBar.Clean(); - pBar.Clean(); - ppBar.Clean(); - - // - swingBar.Clean(); - breakerBar.Clean(); - appliedBox.Clean(); - momentumBar.Clean(); - rejectionBar.Clean(); - - // - return result; - } - - // - double fiboPressureLevel = GetFiboLevelValue(X_FIBO_LEVEL_382); - - // - double fiboUpDown = GetFibonacciLevel( - pBar.high, - pBar.low, - X_FIBO_LEVEL_382, - X_DIRECTION_BEARISH // - ); - double fiboDownUp = GetFibonacciLevel( - pBar.high, - pBar.low, - X_FIBO_LEVEL_382, - X_DIRECTION_BULLISH // - ); - - // - bool hasFiboToUpPressure = - fiboDownUp > 0 && - fiboDownUp <= pBar.GetDown(); - bool hasFiboToDownPressure = - fiboUpDown > 0 && - fiboUpDown >= pBar.GetUp(); - - // - double appliedPrice = - isBullish - ? box.upper - : box.lower; - - // - // Check Swing Low ... - bool isSwingLow = - // - pBar.low < ppBar.low && - pBar.low < cBar.low && - zBar.open > pBar.low && - // - appliedPrice > pBar.low && - appliedPrice < pBar.GetDown() - // - ; - bool isPressuredSwingLow = - isSwingLow && - hasFiboToUpPressure; - bool isPressuredStrongSwingLow = - pBar.IsBullish() && - isPressuredSwingLow; - - // - bool isSwingHigh = - // - pBar.high > ppBar.high && - pBar.high > cBar.high && - zBar.open < pBar.high && - // - appliedPrice < pBar.high && - appliedPrice > pBar.GetUp() - // - ; - bool isPressuredSwingHigh = - isSwingHigh && - hasFiboToDownPressure; - bool isPressuredStrongSwingHigh = - pBar.IsBearish() && - isPressuredSwingHigh; - - // - bool hasValidSwing = - isBullish - ? isSwingLow - : isSwingHigh; - bool hasValidPressuredSwing = - isBullish - ? isPressuredSwingLow - : isPressuredSwingHigh; - bool hasValidPressuredStrongSwing = - isBullish - ? isPressuredStrongSwingLow - : isPressuredStrongSwingHigh; - if (hasValidSwing) - { - swingBar = pBar; - } - if (hasValidPressuredSwing) - { - swingBar = pBar; - } - if (hasValidPressuredStrongSwing) - { - swingBar = pBar; - } - - // - bool isCBarBreaked = IsBarBreak( - appliedPrice, - forDir, - cBar // - ); - if (isCBarBreaked) - { - breakerBar = cBar; - } - bool isPBarBreaked = IsBarBreak( - appliedPrice, - forDir, - pBar // - ); - if (!isCBarBreaked && isPBarBreaked) - { - breakerBar = pBar; - } - else - { - isPBarBreaked = false; - } - bool isPPBarBreaked = IsBarBreak( - appliedPrice, - forDir, - ppBar // - ); - if (!isCBarBreaked && - !isPBarBreaked && - isPPBarBreaked) - { - breakerBar = ppBar; - } - else - { - isPPBarBreaked = false; - } - bool isBoxBreaked = isCBarBreaked || - isPBarBreaked || - isPPBarBreaked; - - // - bool isCBarRejected = IsBarReject( - appliedPrice, - forDir, - cBar // - ); - if (isCBarRejected) - { - rejectionBar = cBar; - } - bool isPBarRejected = IsBarReject( - appliedPrice, - forDir, - pBar // - ); - if (!isCBarRejected && isPBarRejected) - { - rejectionBar = pBar; - } - else - { - isPBarRejected = false; - } - bool isPPBarRejected = IsBarReject( - appliedPrice, - forDir, - ppBar // - ); - if (!isCBarRejected && - !isPBarRejected && - isPPBarRejected) - { - rejectionBar = ppBar; - } - else - { - isPPBarRejected = false; - } - bool isBoxRejected = isCBarRejected || - isPBarRejected || - isPPBarRejected; - - // - result = - // - isBoxBreaked || - isBoxRejected || - hasValidPressuredSwing - // - ; - if (!result) - { - // - swingBar.Clean(); - breakerBar.Clean(); - appliedBox.Clean(); - momentumBar.Clean(); - rejectionBar.Clean(); - } - else - { - appliedBox = box; - } - - // - zBar.Clean(); - cBar.Clean(); - pBar.Clean(); - ppBar.Clean(); - - // - return result; - } - - // -}; - -// -struct X121SMCXWZWorkingZone -{ - // - string symbol; - ENUM_TIMEFRAMES period; - - // - double upper; - double lower; - - // - double zoneUpper; - double zoneLower; - - // - double quarter1; - double quarter2; - double quarter3; - - // - datetime to; - datetime from; - - // - XOHCL swingBar; - XOHCL breakerBar; - XOHCL momentumBar; - XOHCL rejectionBar; - XBoxZone appliedBox; - - // - X121SMCXWZWorkingZone() - { - Clean(); - } - - // - void Clean() - { - // - upper = 0; - lower = 0; - quarter1 = 0; - quarter2 = 0; - quarter3 = 0; - zoneLower = 0; - zoneUpper = 0; - - // - from = NULL; - symbol = NULL; - period = NULL; - - // - CleanConditionBars(); - - // - ZeroMemory(this); - } - - // - void CleanConditionBars() - { - // - swingBar.Clean(); - breakerBar.Clean(); - appliedBox.Clean(); - momentumBar.Clean(); - rejectionBar.Clean(); - } - - // - bool IsValid() - { - // - bool result = false; - - // - result = - lower > 0 && - upper > 0 && - quarter1 > 0 && - quarter2 > 0 && - quarter3 > 0 && - upper > lower && - zoneLower > 0 && - zoneUpper > 0 && - IsValid(from) && - IsValid(symbol) && - IsValid(period) && - zoneUpper > upper && - zoneLower < lower; - - // - return result; - } - - // - bool IsDestroyed( - ENUM_X_DIRECTION &destroyedDir, - int barIndex = 0, - ENUM_TIMEFRAMES forPeriod = NULL // - ) - { - // - bool result = false; - - // - if (barIndex < 0) - { - barIndex = 0; - } - - // - if (!IsValid(forPeriod)) - { - forPeriod = period; - } - - // - destroyedDir = X_DIRECTION_NONE; - - // - result = IsValid(); - if (!result) - { - return result; - } - - // - XOHCL bar; - result = bar.Init( - symbol, - forPeriod, - barIndex // - ); - if (!result) - { - return result; - } - - // - bool isUpperBreaked = - bar.high > zoneUpper && - bar.close > zoneUpper; - - // - bool isLowerBreaked = - bar.low < zoneLower && - bar.close < zoneLower; - - // - result = isUpperBreaked || - isLowerBreaked; - if (result) - { - // - destroyedDir = - isUpperBreaked - ? X_DIRECTION_BULLISH - : X_DIRECTION_BEARISH; - } - - // - return result; - } - - // -}; - -// -// Definitions ... -struct X121SMCStrategyXWZSignalConditions -{ - // - // Props ... - - // - string symbol; - ENUM_TIMEFRAMES period; - - // - double sl; - double target; - double reward; - double amountPercent; - ENUM_X_DIRECTION dir; - ENUM_X_POSITION_TYPES type; - - // - // Setup Props ... - - // - datetime setupTime; - datetime triggerTime; - - // - double pivot; - double point; - - // - ENUM_X121SMC_XWZ_PRIORITY priority; - - // - // Working Zone ... - XCFVG *fairValueGap; - XCOrderBlock *orderBlock; - XCSupplyZone *supplyZone; - XCDemandZone *demandZone; - X121SMCXWZWorkingZone workingZone; - - // - // X121SMCXWZZone startZone; - X121SMCXWZZone startZones[]; - - // - // Constructor ... - X121SMCStrategyXWZSignalConditions() - { - Clean(); - } - - // - // Tools ... - - /** - * Cleaning Up ... - */ - void Clean() - { - // - sl = 0; - target = 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; - - // - target = 0; - reward = 0; - amountPercent = 0; - - // - ZeroMemory(supplyZone); - - // - ZeroMemory(demandZone); - - // - ZeroMemory(orderBlock); - - // - ZeroMemory(fairValueGap); - - // - // startZone.Clean(); - Clean(startZones); - - // - workingZone.Clean(); - } - - // - // - // - - // - bool HasWorkingZone() - { - return workingZone.IsValid(); - } - - // - bool HasOrderBlock() - { - return orderBlock != NULL && - orderBlock.IsValid(); - } - - // - bool HasFairValueGap() - { - return fairValueGap != NULL && - fairValueGap.IsValid(); - } - - // - bool HasSupplyZone() - { - return supplyZone != NULL && - supplyZone.IsValid(); - } - - // - bool HasDemandZone() - { - return demandZone != NULL && - demandZone.IsValid(); - } - - // - bool HasStartZones() - { - return HasChild(startZones); - } - - // - int CountStartZones() - { - return ArraySize(startZones); - } - - // - void UpdateTo(datetime value = NULL) - { - // - value = NormalizeTime(value); - - // - bool hasSupplyZone = HasSupplyZone(); - if (hasSupplyZone) - { - supplyZone.To(value); - } - - // - bool hasDemandZone = HasDemandZone(); - if (hasDemandZone) - { - demandZone.To(value); - } - - // - bool hasOrderBlock = HasOrderBlock(); - if (hasOrderBlock) - { - orderBlock.To(value); - } - - // - bool hasFairValueGap = HasFairValueGap(); - if (hasFairValueGap) - { - fairValueGap.To(value); - } - - // - // Working Zone ... - bool hasWorkingZone = HasWorkingZone(); - if (hasWorkingZone) - { - workingZone.to = value; - } - - // - // Start Zone ... - bool hasStartZones = HasStartZones(); - if (hasStartZones) - { - // - int count = CountStartZones(); - for (int i = 0; i < count; i++) - { - // - bool hasOB = startZones[i].HasOB(); - if (hasOB) - { - startZones[i].ob.To(value); - } - - // - bool hasFVG = startZones[i].HasFVG(); - if (hasFVG) - { - startZones[i].fvg.To(value); - } - - // - bool hasSupply = startZones[i].HasSupply(); - if (hasSupply) - { - startZones[i].supply.To(value); - } - - // - bool hasDemand = startZones[i].HasDemand(); - if (hasDemand) - { - startZones[i].demand.To(value); - } - - // - bool hasSupport = startZones[i].HasSupport(); - if (hasSupport) - { - startZones[i].support.To(value); - } - - // - bool hasResistance = startZones[i].HasResistance(); - if (hasResistance) - { - startZones[i].resistance.To(value); - } - } - } - } - - // - // - // - - // - // Working Zone is an Area which - // we decide to trade inside it ... - bool ExtractWorkingZone( - XPOIState &htfState, - XPOIState &mtfState, - XPOIState &stfState, - int barIndex = 0 // - ) - { - // - bool result = false; - - // - if (barIndex < 0) - { - barIndex = 0; - } - int zIndex = barIndex; - - // - result = !HasWorkingZone(); - if (!result) - { - return result; - } - - // - result = IsValid(symbol) && - IsValid(period); - if (!result) - { - // - Clean(); - return result; - } - - // - datetime cTime = iTime( - symbol, - period, - zIndex // - ); - - // - result = - // - htfState.IsValid() && - htfState.HasChild() && - htfState.HasSupplyZones() && - htfState.HasDemandZones() && - // - mtfState.IsValid() && - mtfState.HasChild() && - mtfState.HasSupplyZones() && - mtfState.HasDemandZones() && - // - stfState.IsValid() && - stfState.HasChild() - // - ; - if (!result) - { - return result; - } - - // - // Retrieve Highest Supply Zone ... - int hSupplyIDX = GetHighest(htfState.supplyZones); - int lDemandIDX = GetLowest(htfState.demandZones); - - // - result = - // - IsValidIndex(hSupplyIDX) && - IsValidIndex(lDemandIDX) - // - ; - if (!result) - { - return result; - } - - // - supplyZone = htfState.supplyZones[hSupplyIDX]; - demandZone = htfState.demandZones[lDemandIDX]; - - // - result = - // - supplyZone != NULL && - demandZone != NULL && - supplyZone.IsValid() && - demandZone.IsValid() - // - ; - if (!result) - { - // - Clean(); - return result; - } - - // - // Check Validation of Supply and Demand Zones ... - lDemandIDX = GetLowest(mtfState.demandZones); - hSupplyIDX = GetHighest(mtfState.supplyZones); - result = IsValidIndex(lDemandIDX) && - IsValidIndex(hSupplyIDX); - if (!result) - { - // - Clean(); - return result; - } - - // - // Validate Supply and Demand ... - bool isMTFHSupplyInside = - IsInside( - mtfState.supplyZones[hSupplyIDX], - supplyZone); - bool isMTFLDemandInside = - IsInside( - mtfState.demandZones[lDemandIDX], - demandZone // - ); - if (isMTFHSupplyInside && - !isMTFLDemandInside) - { - demandZone = mtfState.demandZones[lDemandIDX]; - } - else if (!isMTFHSupplyInside && - isMTFLDemandInside) - { - supplyZone = mtfState.supplyZones[hSupplyIDX]; - } - else if (isMTFHSupplyInside && - isMTFLDemandInside) - { - // - supplyZone = mtfState.supplyZones[hSupplyIDX]; - demandZone = mtfState.demandZones[lDemandIDX]; - } - - // - // Check Zones Validation ... - bool hasTrend = - supplyZone != NULL && - supplyZone.IsValid() && - demandZone != NULL && - demandZone.IsValid(); - result = hasTrend; - if (!result) - { - // - Clean(); - return result; - } - - // - datetime from = MathMax( - supplyZone.From(), - demandZone.From()); - - // - int fromIndex = iBarShift( - symbol, - period, - from // - ); - - // - // Detect Trend ... - ENUM_X_DIRECTION trend = X_DIRECTION_NONE; - datetime supplyTouch = NULL; - datetime demandTouch = NULL; - for (int i = zIndex; i < fromIndex; i++) - { - // - XOHCL iBar; - bool isInited = iBar.Init( - symbol, - period, - i // - ); - if (!isInited) - { - continue; - } - - // - bool isTouchSupplyZone = - // - iBar.low < supplyZone.Lower() && - iBar.GetUp() > supplyZone.Lower() - // - ; - if (isTouchSupplyZone && - !IsValid(supplyTouch)) - { - supplyTouch = iBar.time; - } - - // - bool isTouchDemandZone = - // - iBar.high > demandZone.Upper() && - iBar.GetDown() < demandZone.Upper() - // - ; - if (isTouchDemandZone && - !IsValid(demandTouch)) - { - demandTouch = iBar.time; - } - - // - bool canBreak = - IsValid(supplyTouch) && - IsValid(demandTouch); - - // - iBar.Clean(); - - // - if (canBreak) - { - break; - } - } - - // - hasTrend = - // - IsValid(supplyTouch) || - IsValid(demandTouch) - // - ; - if (hasTrend) - { - // - trend = - // - supplyTouch > demandTouch - ? X_DIRECTION_BEARISH - : X_DIRECTION_BULLISH - // - ; - } - - // - // Check Trend ... - result = hasTrend; - if (!result) - { - // - Clean(); - return result; - } - - // - bool hasBullishTrend = IsBullish(trend); - bool hasBearishTrend = IsBearish(trend); - - // - // Find Order Block and FVG for Trend Approve ... - - // - bool isBullishTrendApproved = false; - bool isBearishTrendApproved = false; - - // - // Now We Have to Detect at least One OrderBlock with FVG ... - // for Trend Approvement ... - bool hasOrderBlock = HasOrderBlock(); - bool hasFairValueGap = HasFairValueGap(); - if (!hasOrderBlock && - !hasFairValueGap) - { - // - int count = 0; - bool has = false; - - // - XCFVG *fvg = NULL; - XCOrderBlock *ob = NULL; - - // - has = mtfState.HasBullishOrderBlocks(); - count = mtfState.CountBullishOrderBlocks(); - - // - if (has) - { - // - // Check Order Block ... - for (int i = 0; i < count; i++) - { - // - XCOrderBlock *iOB = mtfState.bullishOrderBlocks[i]; - - // - iOB.To(cTime); - - // - // Check From Passes ... - bool isFromPassed = iOB.From() > demandZone.From(); - if (!isFromPassed) - { - continue; - } - - // - // Must inside DemandZone ... - bool isInsideDemand = IsInsideDiff( - iOB, - demandZone // - ); - if (!isInsideDemand) - { - continue; - } - - // - // Check Started ... - XOHCL startedBar; - ENUM_X_DIRECTION startedDir; - bool isStarted = iOB.IsStarted( - X_DIRECTION_BULLISH, - startedBar, - startedDir // - ); - if (!isStarted) - { - // - startedBar.Clean(); - continue; - } - - // - // Converts to Box ... - XBoxZone obBox; - bool hasOBBox = ToBox( - obBox, - iOB // - ); - if (!hasOBBox) - { - // - obBox.Clean(); - startedBar.Clean(); - continue; - } - - // - // Check Zone Must not Used before ... - bool isUsed = IsBoxUsed( - obBox, - startedBar.Index() - 1, - zIndex // - ); - if (isUsed) - { - // - obBox.Clean(); - startedBar.Clean(); - continue; - } - - // - ob = iOB; - - // - obBox.Clean(); - startedBar.Clean(); - - // - break; - } - - // - // Detect Fair Value Gap ... - if (ob != NULL && - ob.IsValid()) - { - // - has = stfState.HasBullishFairValueGaps(); - count = stfState.CountBullishFairValueGaps(); - if (has) - { - // - // Check Fir Value Gap ... - for (int i = 0; i < count; i++) - { - // - XCFVG *iFVG = stfState.bullishFairValueGaps[i]; - - // - iFVG.To(cTime); - - // - // Check From Passes ... - bool isFromPassed = iFVG.From() > ob.From(); - if (!isFromPassed) - { - continue; - } - - // - // Check Started ... - XOHCL startedBar; - ENUM_X_DIRECTION startedDir; - bool isStarted = iFVG.IsStarted( - X_DIRECTION_BULLISH, - startedBar, - startedDir // - ); - if (!isStarted) - { - // - startedBar.Clean(); - continue; - } - - // - // Converts to Box ... - XBoxZone fvgBox; - bool hasFVGBox = ToBox( - fvgBox, - iFVG // - ); - if (!hasFVGBox) - { - // - fvgBox.Clean(); - startedBar.Clean(); - continue; - } - - // - // Check Inside Order Block ... - bool isInside = IsInsideDiff( - iFVG, - ob, - true // Force Side Out ... - ); - if (!isInside) - { - continue; - } - - // - fvg = iFVG; - - // - fvgBox.Clean(); - startedBar.Clean(); - - // - break; - } - } - else - { - // - ob = NULL; - } - } - - // - if (ob != NULL && - fvg != NULL) - { - // - orderBlock = ob; - fairValueGap = fvg; - } - - // - hasOrderBlock = HasOrderBlock(); - hasFairValueGap = HasFairValueGap(); - isBullishTrendApproved = hasOrderBlock && - hasFairValueGap; - } - - // - if (!isBullishTrendApproved) - { - // - has = mtfState.HasBearishOrderBlocks(); - count = mtfState.CountBearishOrderBlocks(); - - // - if (has) - { - // - // Check Order Block ... - for (int i = 0; i < count; i++) - { - // - XCOrderBlock *iOB = mtfState.bearishOrderBlocks[i]; - - // - iOB.To(cTime); - - // - // Check From Passes ... - bool isFromPassed = iOB.From() > supplyZone.From(); - if (!isFromPassed) - { - continue; - } - - // - // Must inside DemandZone ... - bool isInsideDemand = IsInsideDiff( - iOB, - supplyZone // - ); - if (!isInsideDemand) - { - continue; - } - - // - // Check Started ... - XOHCL startedBar; - ENUM_X_DIRECTION startedDir; - bool isStarted = iOB.IsStarted( - X_DIRECTION_BEARISH, - startedBar, - startedDir // - ); - if (!isStarted) - { - // - startedBar.Clean(); - continue; - } - - // - // Converts to Box ... - XBoxZone obBox; - bool hasOBBox = ToBox( - obBox, - iOB // - ); - if (!hasOBBox) - { - // - obBox.Clean(); - startedBar.Clean(); - continue; - } - - // - // Check Zone Must not Used before ... - bool isUsed = IsBoxUsed( - obBox, - startedBar.Index() - 1, - zIndex // - ); - if (isUsed) - { - // - obBox.Clean(); - startedBar.Clean(); - continue; - } - - // - ob = iOB; - - // - obBox.Clean(); - startedBar.Clean(); - - // - break; - } - - // - // Detect Fair Value Gap ... - if (ob != NULL && - ob.IsValid()) - { - // - has = stfState.HasBearishFairValueGaps(); - count = stfState.CountBearishFairValueGaps(); - if (has) - { - // - // Check Fir Value Gap ... - for (int i = 0; i < count; i++) - { - // - XCFVG *iFVG = stfState.bearishFairValueGaps[i]; - - // - iFVG.To(cTime); - - // - // Check From Passes ... - bool isFromPassed = iFVG.From() > ob.From(); - if (!isFromPassed) - { - continue; - } - - // - // Check Started ... - XOHCL startedBar; - ENUM_X_DIRECTION startedDir; - bool isStarted = iFVG.IsStarted( - X_DIRECTION_BEARISH, - startedBar, - startedDir // - ); - if (!isStarted) - { - // - startedBar.Clean(); - continue; - } - - // - // Converts to Box ... - XBoxZone fvgBox; - bool hasFVGBox = ToBox( - fvgBox, - iFVG // - ); - if (!hasFVGBox) - { - // - fvgBox.Clean(); - startedBar.Clean(); - continue; - } - - // - // Check Inside Order Block ... - bool isInside = IsInsideDiff( - iFVG, - ob, - true // Force Side Out ... - ); - if (!isInside) - { - continue; - } - - // - fvg = iFVG; - - // - fvgBox.Clean(); - startedBar.Clean(); - - // - break; - } - } - else - { - // - ob = NULL; - } - } - - // - if (ob != NULL && - fvg != NULL) - { - // - orderBlock = ob; - fairValueGap = fvg; - } - - // - hasOrderBlock = HasOrderBlock(); - hasFairValueGap = HasFairValueGap(); - isBearishTrendApproved = hasOrderBlock && - hasFairValueGap; - } - } - } - - // - // Check Trend Approved ... - bool isTrendApproved = - hasOrderBlock && - hasFairValueGap && - (isBullishTrendApproved || - isBearishTrendApproved); - result = isTrendApproved; - if (!result) - { - // - Clean(); - return result; - } - - // - // Prepare Working Zone ... - workingZone.symbol = symbol; - workingZone.period = period; - - // - workingZone.upper = supplyZone.Lower(); - workingZone.zoneUpper = supplyZone.Upper(); - - // - workingZone.lower = demandZone.Upper(); - workingZone.zoneLower = demandZone.Lower(); - - // - workingZone.from = from; - - // - double upper = workingZone.upper; - double range = - workingZone.upper - workingZone.lower; - double ranegPercent = range / 100; - double quarterValue = ranegPercent * 25; - - // - workingZone.quarter1 = upper - (quarterValue * 1); - workingZone.quarter2 = upper - (quarterValue * 2); - workingZone.quarter3 = upper - (quarterValue * 3); - - // - result = workingZone.IsValid(); - if (!result) - { - Clean(); - } - - // - return result; - } - - // - bool IsWorkingZoneDestroyed( - ENUM_X_DIRECTION &destroyedDir, - int barIndex = 0, - ENUM_TIMEFRAMES forPeriod = NULL // - ) - { - // - bool result = false; - - // - if (barIndex < 0) - { - barIndex = 0; - } - - // - if (!IsValid(forPeriod)) - { - forPeriod = period; - } - - // - destroyedDir = X_DIRECTION_NONE; - - // - result = workingZone.IsValid(); - if (!result) - { - return result; - } - - // - result = workingZone.IsDestroyed( - destroyedDir, - barIndex, - forPeriod // - ); - - // - return result; - } - - // - bool DetectTrend( - ENUM_X_DIRECTION &trend, - int barIndex = 0, - ENUM_TIMEFRAMES forPeriod = NULL // - ) - { - // - bool result = false; - - // - if (barIndex < 0) - { - barIndex = 0; - } - - // - if (forPeriod == NULL) - { - forPeriod = period; - } - - // - trend = X_DIRECTION_NONE; - - // - result = HasWorkingZone(); - if (!result) - { - return result; - } - - // - int FromIndex = iBarShift( - symbol, - forPeriod, - workingZone.from // - ); - - // - datetime supplyTouch = NULL; - datetime demandTouch = NULL; - for (int i = barIndex; i < FromIndex; i++) - { - // - XOHCL iBar; - bool isInited = iBar.Init( - symbol, - forPeriod, - i // - ); - if (!isInited) - { - continue; - } - - // - bool isTouchSupplyZone = - // - iBar.low < supplyZone.Lower() && - iBar.GetUp() > supplyZone.Lower() - // - ; - if (isTouchSupplyZone && - !IsValid(supplyTouch)) - { - supplyTouch = iBar.time; - } - - // - bool isTouchDemandZone = - // - iBar.high > demandZone.Upper() && - iBar.GetDown() < demandZone.Upper() - // - ; - if (isTouchDemandZone && - !IsValid(demandTouch)) - { - demandTouch = iBar.time; - } - - // - bool canBreak = - IsValid(supplyTouch) && - IsValid(demandTouch); - - // - iBar.Clean(); - - // - if (canBreak) - { - break; - } - } - - // - result = - // - IsValid(supplyTouch) || - IsValid(demandTouch) - // - ; - if (result) - { - // - trend = - // - supplyTouch > demandTouch - ? X_DIRECTION_BEARISH - : X_DIRECTION_BULLISH - // - ; - } - - // - return result; - } - - // - bool DetectStartZones( - ENUM_X_DIRECTION forDir, - XPOIState &obState, - XPOIState &fvgState, - XPOIState &otherState, - XC121SMCCycleHelper *cycleHelper // - ) - { - // - bool result = false; - - // - result = obState.IsValid() && - obState.HasChild() && - fvgState.IsValid() && - fvgState.HasChild() && - otherState.IsValid() && - otherState.HasChild() && - HasDirection(forDir); - if (!result) - { - return result; - } - - // - bool isBullish = IsBullish(forDir); - - // - int idx = -1; - int count = 0; - int has = false; - - // - X121SMCXWZZone startZone; - X121SMCXWZZone lastStartZone; - bool hasLastStartZone = HasStartZones(); - if (hasLastStartZone) - { - // - int startZonesCount = CountStartZones(); - lastStartZone = startZones[startZonesCount - 1]; - } - - // - if (isBullish) - { - // - has = obState.HasBullishOrderBlocks(); - if (has) - { - // - count = obState.CountBullishOrderBlocks(); - for (int i = 0; i < count; i++) - { - // - XCOrderBlock *iOB = obState.bullishOrderBlocks[i]; - - // - bool isFromPassed = - !hasLastStartZone - ? true - : iOB.From() > lastStartZone.ob.From(); - if (!isFromPassed) - { - // - ZeroMemory(iOB); - continue; - } - - // - XOHCL startedBar; - ENUM_X_DIRECTION startedDir; - bool isStarted = iOB.IsStarted( - forDir, - startedBar, - startedDir // - ); - if (!isStarted) - { - // - ZeroMemory(iOB); - startedBar.Clean(); - continue; - } - - // - XOHCL activatedBar; - ENUM_X_DIRECTION activatedDir; - bool isActivated = iOB.IsActivated( - forDir, - activatedBar, - activatedDir // - ); - if (isActivated) - { - // - ZeroMemory(iOB); - startedBar.Clean(); - activatedBar.Clean(); - continue; - } - - // - // Validate Zone Iverse Breake ... - XOHCL breakedBar; - ENUM_X_DIRECTION breakedDir; - bool isBreaked = iOB.IsBreaked( - Opposit(forDir), - breakedBar, - breakedDir, - true // Ignore Activation ... - ); - if (isBreaked) - { - // - ZeroMemory(iOB); - startedBar.Clean(); - breakedBar.Clean(); - activatedBar.Clean(); - continue; - } - - // - bool isPlacePassed = - !IsInsideDiff( - iOB, - demandZone // - ) && - (!hasLastStartZone - ? workingZone.IsValid() && - HasOrderBlock() && - forDir == orderBlock.GetDirection() - ? IsAbove( - iOB, - orderBlock, - true // Ignore Inside ... - ) - : true - : lastStartZone.HasOB() && - IsAbove( - iOB, - lastStartZone.ob, - true // Ignore Inside ... - )); - if (!isPlacePassed) - { - // - ZeroMemory(iOB); - startedBar.Clean(); - activatedBar.Clean(); - continue; - } - - // - // Attache OB ... - startZone.ob = iOB; - - // - // Now we Have to Find Specified FVG ... - has = fvgState.HasBullishFairValueGaps(); - if (has) - { - // - int jCount = fvgState.CountBullishFairValueGaps(); - for (int j = 0; j < jCount; j++) - { - // - XCFVG *jFVG = fvgState.bullishFairValueGaps[j]; - - // - startedBar.Clean(); - startedDir = X_DIRECTION_NONE; - isStarted = jFVG.IsStarted( - forDir, - startedBar, - startedDir // - ); - if (!isStarted) - { - // - ZeroMemory(jFVG); - startedBar.Clean(); - continue; - } - - // - activatedBar.Clean(); - activatedDir = X_DIRECTION_NONE; - isActivated = jFVG.IsActivated( - forDir, - activatedBar, - activatedDir // - ); - if (isActivated) - { - // - ZeroMemory(jFVG); - startedBar.Clean(); - activatedBar.Clean(); - continue; - } - - // - // Validate Zone Iverse Breake ... - breakedBar.Clean(); - breakedDir = X_DIRECTION_NONE; - bool isBreaked = jFVG.IsBreaked( - Opposit(forDir), - breakedBar, - breakedDir, - true // Ignore Activation ... - ); - if (isBreaked) - { - // - ZeroMemory(jFVG); - startedBar.Clean(); - breakedBar.Clean(); - activatedBar.Clean(); - continue; - } - - // - isPlacePassed = - // - !IsInsideDiff( - jFVG, - demandZone // - ) && - IsAboveDiff( - jFVG, - iOB, - true // Ignore Inside ... - ) - // - ; - if (!isPlacePassed) - { - // - ZeroMemory(jFVG); - startedBar.Clean(); - activatedBar.Clean(); - } - - // - startZone.fvg = jFVG; - } - } - - // - startedBar.Clean(); - activatedBar.Clean(); - } - } - } - else - { - // - has = obState.HasBearishOrderBlocks(); - if (has) - { - // - count = obState.CountBearishOrderBlocks(); - for (int i = 0; i < count; i++) - { - // - XCOrderBlock *iOB = obState.bearishOrderBlocks[i]; - - // - bool isFromPassed = - !hasLastStartZone - ? true - : iOB.From() > lastStartZone.ob.From(); - if (!isFromPassed) - { - // - ZeroMemory(iOB); - continue; - } - - // - XOHCL startedBar; - ENUM_X_DIRECTION startedDir; - bool isStarted = iOB.IsStarted( - forDir, - startedBar, - startedDir // - ); - if (!isStarted) - { - // - ZeroMemory(iOB); - startedBar.Clean(); - continue; - } - - // - XOHCL activatedBar; - ENUM_X_DIRECTION activatedDir; - bool isActivated = iOB.IsActivated( - forDir, - activatedBar, - activatedDir // - ); - if (isActivated) - { - // - ZeroMemory(iOB); - startedBar.Clean(); - activatedBar.Clean(); - continue; - } - - // - // Validate Zone Iverse Breake ... - XOHCL breakedBar; - ENUM_X_DIRECTION breakedDir; - bool isBreaked = iOB.IsBreaked( - Opposit(forDir), - breakedBar, - breakedDir, - true // Ignore Activation ... - ); - if (isBreaked) - { - // - ZeroMemory(iOB); - startedBar.Clean(); - breakedBar.Clean(); - activatedBar.Clean(); - continue; - } - - // - bool isPlacePassed = - !IsInsideDiff( - iOB, - supplyZone // - ) && - (!hasLastStartZone - ? workingZone.IsValid() && - HasOrderBlock() && - forDir == orderBlock.GetDirection() - ? IsBelow( - iOB, - orderBlock, - true // Ignore Inside ... - ) - : true - : lastStartZone.HasOB() && - IsBelow( - iOB, - lastStartZone.ob, - true // Ignore Inside ... - )); - if (!isPlacePassed) - { - // - ZeroMemory(iOB); - startedBar.Clean(); - activatedBar.Clean(); - continue; - } - - // - // Attache OB ... - startZone.ob = iOB; - - // - // Now we Have to Find Specified FVG ... - has = fvgState.HasBearishFairValueGaps(); - if (has) - { - // - int jCount = fvgState.CountBearishFairValueGaps(); - for (int j = 0; j < jCount; j++) - { - // - XCFVG *jFVG = fvgState.bearishFairValueGaps[j]; - - // - startedBar.Clean(); - startedDir = X_DIRECTION_NONE; - isStarted = jFVG.IsStarted( - forDir, - startedBar, - startedDir // - ); - if (!isStarted) - { - // - ZeroMemory(jFVG); - startedBar.Clean(); - continue; - } - - // - activatedBar.Clean(); - activatedDir = X_DIRECTION_NONE; - isActivated = jFVG.IsActivated( - forDir, - activatedBar, - activatedDir // - ); - if (isActivated) - { - // - ZeroMemory(jFVG); - startedBar.Clean(); - activatedBar.Clean(); - continue; - } - - // - // Validate Zone Iverse Breake ... - breakedBar.Clean(); - breakedDir = X_DIRECTION_NONE; - bool isBreaked = jFVG.IsBreaked( - Opposit(forDir), - breakedBar, - breakedDir, - true // Ignore Activation ... - ); - if (isBreaked) - { - // - ZeroMemory(jFVG); - startedBar.Clean(); - breakedBar.Clean(); - activatedBar.Clean(); - continue; - } - - // - isPlacePassed = - // - !IsInsideDiff( - jFVG, - supplyZone // - ) && - IsBelowDiff( - jFVG, - iOB, - true // Ignore Inside ... - ) - // - ; - if (!isPlacePassed) - { - // - ZeroMemory(jFVG); - startedBar.Clean(); - activatedBar.Clean(); - } - - // - startZone.fvg = jFVG; - } - } - - // - startedBar.Clean(); - activatedBar.Clean(); - } - } - } - - // - bool hasOBFVG = startZone.HasOB() && - startZone.HasFVG(); - result = hasOBFVG; - if (!result) - { - // - startZone.Clean(); - lastStartZone.Clean(); - - // - return result; - } - - // - XBoxZone startBox; - bool hasStartBox = startZone.AsBox(startBox); - result = hasStartBox; - if (!result) - { - // - startBox.Clean(); - startZone.Clean(); - lastStartZone.Clean(); - - // - return result; - } - - // - // Detect Other Zones Inside Box ... - XBoxZone tmpBoxes[]; - - // - // Supply Zones ... - has = otherState.HasSupplyZones(); - if (has) - { - // - count = ToBox( - otherState.supplyZones, - tmpBoxes // - ); - - // - has = IsValidSize(count); - if (has) - { - // - for (int i = 0; i < count; i++) - { - // - XBoxZone iBox = tmpBoxes[i]; - - // - bool isPlacePassed = - // - IsBoxInside( - iBox, - startBox, - false, - false // - ) - // - ; - if (!isPlacePassed) - { - // - iBox.Clean(); - continue; - } - - // - startZone.supply = otherState.supplyZones[i]; - - // - iBox.Clean(); - break; - } - } - } - - // - // Demand Zones ... - Clean(tmpBoxes); - has = otherState.HasDemandZones(); - if (has) - { - // - count = ToBox( - otherState.demandZones, - tmpBoxes // - ); - - // - has = IsValidSize(count); - if (has) - { - // - for (int i = 0; i < count; i++) - { - // - XBoxZone iBox = tmpBoxes[i]; - - // - bool isPlacePassed = - // - IsBoxInside( - iBox, - startBox, - false, - false // - ) - // - ; - if (!isPlacePassed) - { - // - iBox.Clean(); - continue; - } - - // - startZone.demand = otherState.demandZones[i]; - - // - iBox.Clean(); - break; - } - } - } - - // - // Support Zones ... - Clean(tmpBoxes); - has = otherState.HasSupportZones(); - if (has) - { - // - count = ToBox( - otherState.supportZones, - tmpBoxes // - ); - - // - has = IsValidSize(count); - if (has) - { - // - for (int i = 0; i < count; i++) - { - // - XBoxZone iBox = tmpBoxes[i]; - - // - bool isPlacePassed = - // - IsBoxInside( - iBox, - startBox, - false, - false // - ) - // - ; - if (!isPlacePassed) - { - // - iBox.Clean(); - continue; - } - - // - startZone.support = otherState.supportZones[i]; - - // - iBox.Clean(); - break; - } - } - } - - // - // Resistance Zones ... - Clean(tmpBoxes); - has = otherState.HasResistanceZones(); - if (has) - { - // - count = ToBox( - otherState.resistanceZones, - tmpBoxes // - ); - - // - has = IsValidSize(count); - if (has) - { - // - for (int i = 0; i < count; i++) - { - // - XBoxZone iBox = tmpBoxes[i]; - - // - bool isPlacePassed = - // - IsBoxInside( - iBox, - startBox, - false, - false // - ) - // - ; - if (!isPlacePassed) - { - // - iBox.Clean(); - continue; - } - - // - startZone.resistance = otherState.resistanceZones[i]; - - // - iBox.Clean(); - break; - } - } - } - - // - result = startZone.IsValid() && - startZone.HasDirection(); - if (result) - { - // - AddRef( - startZone, - startZones // - ); - } - - // - Clean(tmpBoxes); - startBox.Clean(); - startZone.Clean(); - lastStartZone.Clean(); - - // - return result; - } - - // - void ValidateStartZones( - int barIndex = 0, - ENUM_TIMEFRAMES forPeriod = NULL // - ) - { - // - bool has = HasStartZones(); - if (!has) - { - return; - } - - // - X121SMCXWZZone tmpZones[]; - int count = CountStartZones(); - Copy( - startZones, - tmpZones // - ); - for (int i = 0; i < count; i++) - { - // - bool isValid = tmpZones[i].ValidateZone( - barIndex, - forPeriod // - ); - if (!isValid) - { - // - ArrayRemove( - startZones, - i, - 1 // - ); - } - } - - // - Clean(tmpZones); - } - - // - void DetectPriority( - ENUM_X121SMC_XWZ_PRIORITY &bullish, - ENUM_X121SMC_XWZ_PRIORITY &bearish, - int barIndex = 0, - ENUM_TIMEFRAMES forPeriod = NULL // - ) - { - // - bullish = X121SMC_XWZ_PRIORITY_NONE; - bearish = X121SMC_XWZ_PRIORITY_NONE; - - // - if (barIndex < 0) - { - barIndex = 0; - } - - // - if (!IsValid(forPeriod)) - { - forPeriod = period; - } - - // - bool hasWorkingZone = HasWorkingZone(); - if (!hasWorkingZone) - { - return; - } - - // - XOHCL zBar; - bool isInited = zBar.Init( - symbol, - forPeriod, - barIndex // - ); - if (!isInited) - { - // - zBar.Clean(); - return; - } - - // - XOHCL cBar; - isInited = zBar.GetPreviousBar(cBar); - if (!isInited) - { - // - zBar.Clean(); - cBar.Clean(); - return; - } - - // - // ZoneUpper, Upper ... - if (cBar.low > workingZone.upper && - cBar.high < workingZone.zoneUpper && - zBar.low > workingZone.upper && - zBar.high < workingZone.zoneUpper) - { - // - bullish = X121SMC_XWZ_PRIORITY_NONE; - bearish = X121SMC_XWZ_PRIORITY_STRONG_HIGH; - } - // - // Upper, Quarter1 ... - else if (cBar.low > workingZone.quarter1 && - cBar.high < workingZone.upper && - zBar.low > workingZone.quarter1 && - zBar.high < workingZone.upper) - { - // - bullish = X121SMC_XWZ_PRIORITY_WEAK; - bearish = X121SMC_XWZ_PRIORITY_HIGH; - } - // - // Quarter1, Quarter2 ... - else if (cBar.low > workingZone.quarter2 && - cBar.high < workingZone.quarter1 && - zBar.low > workingZone.quarter2 && - zBar.high < workingZone.quarter1) - { - // - bullish = X121SMC_XWZ_PRIORITY_LOW; - bearish = X121SMC_XWZ_PRIORITY_REGULAR; - } - // - // Quarter2, Quarter3 ... - else if (cBar.low > workingZone.quarter3 && - cBar.high < workingZone.quarter2 && - zBar.low > workingZone.quarter3 && - zBar.high < workingZone.quarter2) - { - // - bullish = X121SMC_XWZ_PRIORITY_REGULAR; - bearish = X121SMC_XWZ_PRIORITY_LOW; - } - // - // Quarter3, Lower ... - else if (cBar.low > workingZone.lower && - cBar.high < workingZone.quarter3 && - zBar.low > workingZone.lower && - zBar.high < workingZone.quarter3) - { - // - bullish = X121SMC_XWZ_PRIORITY_HIGH; - bearish = X121SMC_XWZ_PRIORITY_WEAK; - } - // - // Lower, ZoneLower ... - else if (cBar.low > workingZone.zoneLower && - cBar.high < workingZone.lower && - zBar.low > workingZone.zoneLower && - zBar.high < workingZone.lower) - { - // - bullish = X121SMC_XWZ_PRIORITY_STRONG_HIGH; - bearish = X121SMC_XWZ_PRIORITY_NONE; - } - - // - zBar.Clean(); - cBar.Clean(); - } - - // - bool HasConditions( - double &_pivot, - double &_point, - ENUM_X_DIRECTION &conditionsDir, - XPOIState &state, - int barIndex = 0, - ENUM_TIMEFRAMES forPeriod = NULL // - ) - { - // - bool result = false; - - // - _pivot = 0; - _point = 0; - conditionsDir = X_DIRECTION_NONE; - - // - if (barIndex < 0) - { - barIndex = 0; - } - - // - if (forPeriod == NULL) - { - forPeriod = period; - } - - // - result = - // - IsValid(symbol) && - IsValid(period) && - state.IsValid() && - HasWorkingZone() && - state.HasChild() - // - ; - if (!result) - { - return result; - } - - // - result = false; - - // - ValidateStartZones( - barIndex, - forPeriod // - ); - - // - // Detect Conditions Based On Start Zones ... - bool hasStartZones = HasStartZones(); - if (hasStartZones) - { - // - int selectedIndex = -1; - int count = CountStartZones(); - for (int i = 0; i < count; i++) - { - // - X121SMCXWZZone iStartZone = startZones[i]; - - // - XBoxZone selectedBox; - bool hasConditions = false; - bool isBullish = iStartZone.IsBullish(); - - // - // Conditions Inside Box ... - bool isPriceInside = iStartZone.IsPriceInside( - selectedBox, - barIndex, - forPeriod, - false, - false // - ); - if (isPriceInside) - { - // - // hasConditions = iStartZone.HasInsideConditions( - // state, - // barIndex, - // period // - // ); - - // - hasConditions = true; - - // - if (hasConditions) - { - // - _pivot = - // - isBullish - ? selectedBox.lower - : selectedBox.upper - // - ; - - // - _point = - // - isBullish - ? selectedBox.upper - : selectedBox.lower - // - ; - - // - conditionsDir = selectedBox.dir; - result = hasConditions; - iStartZone.Clean(); - break; - } - } - - // // - // // Order Block Rejection Conditions ... - // bool hasOBBox = ToBox( - // selectedBox, - // iStartZone.ob // - // ); - // if (hasOBBox && - // !hasConditions) - // { - // // - // hasConditions = iStartZone.HasBoxConitions( - // selectedBox, - // state, - // barIndex, - // forPeriod // - // ); - - // // - // if (hasConditions) - // { - // // - // _pivot = - // // - // isBullish - // ? selectedBox.lower - // : selectedBox.upper - // // - // ; - - // // - // _point = - // // - // isBullish - // ? selectedBox.upper - // : selectedBox.lower - // // - // ; - - // // - // conditionsDir = selectedBox.dir; - // result = hasConditions; - // iStartZone.Clean(); - // break; - // } - // } - - // // - // // Fair Value Gap Rejection Conditions ... - // bool hasFVGBox = ToBox( - // selectedBox, - // iStartZone.fvg // - // ); - // if (hasFVGBox) - // { - // // - // hasConditions = iStartZone.HasBoxConitions( - // selectedBox, - // state, - // barIndex, - // forPeriod // - // ); - - // // - // if (hasConditions) - // { - // // - // _pivot = - // // - // isBullish - // ? selectedBox.lower - // : selectedBox.upper - // // - // ; - - // // - // _point = - // // - // isBullish - // ? selectedBox.upper - // : selectedBox.lower - // // - // ; - - // // - // conditionsDir = selectedBox.dir; - // result = hasConditions; - // iStartZone.Clean(); - // break; - // } - // } - - // - iStartZone.Clean(); - } - - // - if (result && - IsValidIndex(selectedIndex)) - { - // - ArrayRemove( - startZones, - selectedIndex, - 1 // - ); - } - } - - // - // Detect Conditions Based On Working Zones ... - if (!result) - { - // - // Detect Result Based On WorkingZone ... - } - - // - if (!result) - { - // - _point = 0; - _pivot = 0; - conditionsDir = X_DIRECTION_NONE; - - // - return result; - } - - // - return result; - } - - // -}; - -// -bool X121SMCXWZCheckPriceInside( - XOHCL &zBar, - XOHCL &cBar, - double upper, - double lower // -) -{ - // - bool result = false; - - // - result = zBar.IsValid() && - cBar.IsValid() && - upper > 0 && - lower > 0 && - upper > lower && - zBar.time > cBar.time; - if (!result) - { - return result; - } - - // - result = - // - zBar.high < upper && - cBar.high < upper && - // - zBar.low > lower && - cBar.low > lower - // - ; - - // - 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 ac6f0427..00000000 --- a/Documents/BKP/x-121.smc.xwz.signal.lib.mq5 +++ /dev/null @@ -1,3560 +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_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 X121SMCXWZZone -{ - // - // Props ... - XCFVG *fvg; - XCOrderBlock *ob; - XCSupplyZone *supply; - XCDemandZone *demand; - XCSupportZone *support; - XCResistanceZone *resistance; - - // - XOHCL swingBar; - XOHCL breakerBar; - XOHCL momentumBar; - XOHCL rejectionBar; - XBoxZone appliedBox; - - // - // Constructor ... - X121SMCXWZZone() - { - Clean(); - } - - // - // Tools ... - - // - void Clean() - { - // - ZeroMemory(ob); - ZeroMemory(fvg); - ZeroMemory(supply); - ZeroMemory(demand); - ZeroMemory(support); - ZeroMemory(resistance); - - // - swingBar.Clean(); - breakerBar.Clean(); - appliedBox.Clean(); - momentumBar.Clean(); - rejectionBar.Clean(); - } - - // - bool IsValid() - { - // - return HasOB() && - HasFVG() && - HasDirection(); - } - - // - bool AsBox(XBoxZone &box) - { - // - bool result = false; - - // - box.Clean(); - - // - result = IsValid() && - HasDirection(); - if (!result) - { - return result; - } - - // - XBoxZone obBox; - bool hasOBBox = ToBox( - obBox, - ob // - ); - result = hasOBBox; - if (!result) - { - // - box.Clean(); - obBox.Clean(); - return result; - } - - // - box = obBox; - - // - obBox.Clean(); - - // - bool hasOB = HasOB(); - bool hasFVG = HasFVG(); - bool hasSupply = HasSupply(); - bool hasDemand = HasDemand(); - bool hasSupport = HasSupport(); - bool hasResistance = HasResistance(); - - // - // OB Compared since box used obBox ... - - // - if (hasFVG) - { - // - if (fvg.Upper() > box.upper) - { - box.upper = fvg.Upper(); - } - - // - if (fvg.Lower() < box.lower) - { - box.lower = fvg.Lower(); - } - } - - // - result = box.IsValid(); - - // - return result; - } - - // - bool HasOB() - { - return ob != NULL && - ob.IsValid(); - } - - // - bool HasFVG() - { - return fvg != NULL && - fvg.IsValid(); - } - - // - bool HasSupply() - { - return supply != NULL && - supply.IsValid(); - } - - // - bool HasDemand() - { - return demand != NULL && - demand.IsValid(); - } - - // - bool HasSupport() - { - return support != NULL && - support.IsValid(); - } - - // - bool HasResistance() - { - return resistance != NULL && - resistance.IsValid(); - } - - // - bool IsBullish() - { - // - return HasOB() && - ob.IsBullish() && - HasFVG() && - fvg.IsBullish(); - } - - // - bool IsBearish() - { - // - return HasOB() && - ob.IsBearish() && - HasFVG() && - fvg.IsBearish(); - } - - // - bool HasDirection() - { - return IsBullish() || - IsBearish(); - } - - // - ENUM_X_DIRECTION GetDirection() - { - // - ENUM_X_DIRECTION result = X_DIRECTION_NONE; - - // - bool hasDirection = HasDirection(); - if (!hasDirection) - { - return result; - } - - // - bool isBullish = IsBullish(); - - // - result = - isBullish - ? X_DIRECTION_BULLISH - : X_DIRECTION_BEARISH; - - // - return result; - } - - // - bool IsPriceInside( - XBoxZone &box, - int barIndex = 0, - ENUM_TIMEFRAMES forPeriod = NULL, - bool forceOB = false, - bool forceFVG = false // - ) - { - // - bool result = false; - - // - box.Clean(); - - // - if (barIndex < 0) - { - barIndex = 0; - } - - // - result = IsValid() && - HasOB() && - HasFVG() && - HasDirection(); - if (!result) - { - return result; - } - - // - string symbol = ob.GetSymbol(); - if (forPeriod == NULL) - { - forPeriod = ob.GetPeriod(); - } - - // - ENUM_X_DIRECTION forDir = ob.GetDirection(); - bool isBullish = IsBullish(forDir); - - // - // Check Start Bars ... - - // - XOHCL obStartedBar; - ENUM_X_DIRECTION obStartedDir; - bool isOBStarted = ob.IsStarted( - forDir, - obStartedBar, - obStartedDir // - ); - result = isOBStarted; - if (!result) - { - return result; - } - - // - XOHCL fvgStartedBar; - ENUM_X_DIRECTION fvgStartedDir; - bool isFVGStarted = fvg.IsStarted( - forDir, - fvgStartedBar, - fvgStartedDir // - ); - result = isFVGStarted; - if (!result) - { - return result; - } - - // - // Retrieve Bars ... - - // - XOHCL zBar; - result = zBar.Init( - symbol, - forPeriod, - barIndex // - ); - if (!result) - { - // - box.Clean(); - zBar.Clean(); - - // - return result; - } - - // - XOHCL cBar; - result = zBar.GetPreviousBar(cBar); - if (!result) - { - // - box.Clean(); - zBar.Clean(); - cBar.Clean(); - - // - return result; - } - - // - XOHCL pBar; - result = cBar.GetPreviousBar(pBar); - if (!result) - { - // - box.Clean(); - zBar.Clean(); - cBar.Clean(); - pBar.Clean(); - - // - return result; - } - - // - bool isPriceInsideOB = X121SMCXWZCheckPriceInside( - zBar, - cBar, - ob.Upper(), - ob.Lower() // - ); - - // - // isBullish - // ? ( - // // - // pBar.close > ob.Upper() && - // cBar.low <= ob.Upper() && - // cBar.close <= ob.Upper() && - // zBar.open <= ob.Upper() - // // - // ) - // : ( - // // - // pBar.close < ob.Lower() && - // cBar.high >= ob.Lower() && - // cBar.close >= ob.Lower() && - // zBar.open >= ob.Lower() - // // - // ); - - // - bool isPriceInsideFVG = X121SMCXWZCheckPriceInside( - zBar, - cBar, - fvg.Upper(), - fvg.Lower() // - ); - - // - // isBullish - // ? ( - // // - // pBar.close > fvg.Upper() && - // cBar.low <= fvg.Upper() && - // cBar.close <= fvg.Upper() && - // zBar.open <= fvg.Upper() - // // - // ) - // : ( - // // - // pBar.close < fvg.Lower() && - // cBar.high >= fvg.Lower() && - // cBar.close >= fvg.Lower() && - // zBar.open >= fvg.Lower() - // // - // ); - - // - if ((forceOB && forceFVG) || - (!forceOB && !forceFVG)) - { - // - result = - isPriceInsideOB || - isPriceInsideFVG; - } - else if (forceOB) - { - result = isPriceInsideOB; - } - else if (forceFVG) - { - result = isPriceInsideFVG; - } - - // - if (result) - { - // - if (isPriceInsideOB && !isPriceInsideFVG) - { - // - result = ToBox( - box, - ob // - ); - } - else if (isPriceInsideFVG && !isPriceInsideOB) - { - // - result = ToBox( - box, - fvg // - ); - } - else if (isPriceInsideOB && isPriceInsideFVG) - { - result = AsBox(box); - } - } - - // - zBar.Clean(); - cBar.Clean(); - pBar.Clean(); - - // - return result; - } - - // - bool HasInsideConditions( - XPOIState &state, - int barIndex = 0, - ENUM_TIMEFRAMES forPeriod = NULL // - ) - { - // - bool result = false; - - // - if (barIndex < 0) - { - barIndex = 0; - } - - // - swingBar.Clean(); - breakerBar.Clean(); - appliedBox.Clean(); - momentumBar.Clean(); - rejectionBar.Clean(); - - // - XBoxZone zoneBox; - bool hasBox = AsBox(zoneBox); - - // - result = hasBox && - IsValid() && - HasDirection() && - state.IsValid() && - state.HasChild(); - if (!result) - { - // - swingBar.Clean(); - breakerBar.Clean(); - appliedBox.Clean(); - momentumBar.Clean(); - rejectionBar.Clean(); - - // - return result; - } - - // - string symbol = zoneBox.symbol; - if (!IsValid(forPeriod)) - { - forPeriod = zoneBox.period; - } - datetime cTime = iTime( - symbol, - forPeriod, - barIndex // - ); - - // - ENUM_X_DIRECTION forDir = zoneBox.dir; - bool isBullish = IsBullish(forDir); - - // - int count = 0; - bool has = false; - - // - XBoxZone supResBoxes[]; - int supresBoxesCount = 0; - bool hasSupResBoxes = false; - - // - has = state.HasSupportZones(); - if (has) - { - // - count = state.CountSupportZones(); - for (int i = 0; i < count; i++) - { - // - XCSupportZone *iZone = state.supportZones[i]; - - // - iZone.To(cTime); - - // - XBoxZone iBox; - bool hasBox = ToBox( - iBox, - iZone // - ); - if (!hasBox) - { - // - iBox.Clean(); - continue; - } - - // - // Check From ... - bool isInside = IsBoxInside( - iBox, - zoneBox // - ); - if (!isInside) - { - // - iBox.Clean(); - continue; - } - - // - AddRef( - iBox, - supResBoxes // - ); - - // - iBox.Clean(); - ZeroMemory(iZone); - } - - // - supresBoxesCount = ArraySize(supResBoxes); - hasSupResBoxes = IsValidSize(supresBoxesCount); - } - - // - has = state.HasResistanceZones(); - if (has) - { - // - count = state.CountResistanceZones(); - for (int i = 0; i < count; i++) - { - // - XCResistanceZone *iZone = state.resistanceZones[i]; - - // - iZone.To(cTime); - - // - XBoxZone iBox; - bool hasBox = ToBox( - iBox, - iZone // - ); - if (!hasBox) - { - // - iBox.Clean(); - continue; - } - - // - // Check From ... - bool isInside = IsBoxInside( - iBox, - zoneBox // - ); - if (!isInside) - { - // - iBox.Clean(); - continue; - } - - // - AddRef( - iBox, - supResBoxes // - ); - - // - iBox.Clean(); - ZeroMemory(iZone); - } - - // - supresBoxesCount = ArraySize(supResBoxes); - hasSupResBoxes = IsValidSize(supresBoxesCount); - } - - // - result = hasSupResBoxes; - if (!result) - { - // - Clean(supResBoxes); - - // - swingBar.Clean(); - breakerBar.Clean(); - appliedBox.Clean(); - momentumBar.Clean(); - rejectionBar.Clean(); - - // - return result; - } - - // - for (int i = 0; i < supresBoxesCount; i++) - { - // - XBoxZone iBox = supResBoxes[i]; - - // - bool hasBoxConditions = HasBoxConitions( - iBox, - state, - barIndex, - forPeriod // - ); - if (hasBoxConditions) - { - // - appliedBox = iBox; - result = true; - iBox.Clean(); - break; - } - - // - iBox.Clean(); - } - - // - if (!result) - { - // - swingBar.Clean(); - breakerBar.Clean(); - appliedBox.Clean(); - momentumBar.Clean(); - rejectionBar.Clean(); - } - - // - Clean(supResBoxes); - - // - return result; - } - - // - bool HasBoxConitions( - XBoxZone &box, - XPOIState &state, - int barIndex = 0, - ENUM_TIMEFRAMES forPeriod = NULL // - ) - { - // - bool result = false; - - // - if (barIndex < 0) - { - barIndex = 0; - } - - // - result = box.IsValid() && - IsValid() && - HasDirection(); - if (!result) - { - // - swingBar.Clean(); - breakerBar.Clean(); - appliedBox.Clean(); - momentumBar.Clean(); - rejectionBar.Clean(); - - // - return result; - } - - // - string symbol = box.symbol; - if (forPeriod == NULL) - { - forPeriod = box.period; - } - ENUM_X_DIRECTION forDir = box.dir; - bool isBullish = IsBullish(forDir); - - // - // Detect Bars ... - - // - XOHCL zBar; - result = zBar.Init( - symbol, - forPeriod, - barIndex // - ); - if (!result) - { - // - zBar.Clean(); - - // - swingBar.Clean(); - breakerBar.Clean(); - appliedBox.Clean(); - momentumBar.Clean(); - rejectionBar.Clean(); - - // - return result; - } - - // - XOHCL cBar; - result = zBar.GetPreviousBar(cBar); - if (!result) - { - // - zBar.Clean(); - cBar.Clean(); - - // - swingBar.Clean(); - breakerBar.Clean(); - appliedBox.Clean(); - momentumBar.Clean(); - rejectionBar.Clean(); - - // - return result; - } - - // - XOHCL pBar; - result = cBar.GetPreviousBar(pBar); - if (!result) - { - // - zBar.Clean(); - cBar.Clean(); - pBar.Clean(); - - // - swingBar.Clean(); - breakerBar.Clean(); - appliedBox.Clean(); - momentumBar.Clean(); - rejectionBar.Clean(); - - // - return result; - } - - // - XOHCL ppBar; - result = pBar.GetPreviousBar(ppBar); - if (!result) - { - // - zBar.Clean(); - cBar.Clean(); - pBar.Clean(); - ppBar.Clean(); - - // - swingBar.Clean(); - breakerBar.Clean(); - appliedBox.Clean(); - momentumBar.Clean(); - rejectionBar.Clean(); - - // - return result; - } - - // - double fiboPressureLevel = GetFiboLevelValue(X_FIBO_LEVEL_382); - - // - double fiboUpDown = GetFibonacciLevel( - pBar.high, - pBar.low, - X_FIBO_LEVEL_382, - X_DIRECTION_BEARISH // - ); - double fiboDownUp = GetFibonacciLevel( - pBar.high, - pBar.low, - X_FIBO_LEVEL_382, - X_DIRECTION_BULLISH // - ); - - // - bool hasFiboToUpPressure = - fiboDownUp > 0 && - fiboDownUp <= pBar.GetDown(); - bool hasFiboToDownPressure = - fiboUpDown > 0 && - fiboUpDown >= pBar.GetUp(); - - // - double appliedPrice = - isBullish - ? box.upper - : box.lower; - - // - // Check Swing Low ... - bool isSwingLow = - // - pBar.low < ppBar.low && - pBar.low < cBar.low && - zBar.open > pBar.low && - // - appliedPrice > pBar.low && - appliedPrice < pBar.GetDown() - // - ; - bool isPressuredSwingLow = - isSwingLow && - hasFiboToUpPressure; - bool isPressuredStrongSwingLow = - pBar.IsBullish() && - isPressuredSwingLow; - - // - bool isSwingHigh = - // - pBar.high > ppBar.high && - pBar.high > cBar.high && - zBar.open < pBar.high && - // - appliedPrice < pBar.high && - appliedPrice > pBar.GetUp() - // - ; - bool isPressuredSwingHigh = - isSwingHigh && - hasFiboToDownPressure; - bool isPressuredStrongSwingHigh = - pBar.IsBearish() && - isPressuredSwingHigh; - - // - bool hasValidSwing = - isBullish - ? isSwingLow - : isSwingHigh; - bool hasValidPressuredSwing = - isBullish - ? isPressuredSwingLow - : isPressuredSwingHigh; - bool hasValidPressuredStrongSwing = - isBullish - ? isPressuredStrongSwingLow - : isPressuredStrongSwingHigh; - if (hasValidSwing) - { - swingBar = pBar; - } - if (hasValidPressuredSwing) - { - swingBar = pBar; - } - if (hasValidPressuredStrongSwing) - { - swingBar = pBar; - } - - // - bool isCBarBreaked = IsBarBreak( - appliedPrice, - forDir, - cBar // - ); - if (isCBarBreaked) - { - breakerBar = cBar; - } - bool isPBarBreaked = IsBarBreak( - appliedPrice, - forDir, - pBar // - ); - if (!isCBarBreaked && isPBarBreaked) - { - breakerBar = pBar; - } - else - { - isPBarBreaked = false; - } - bool isPPBarBreaked = IsBarBreak( - appliedPrice, - forDir, - ppBar // - ); - if (!isCBarBreaked && - !isPBarBreaked && - isPPBarBreaked) - { - breakerBar = ppBar; - } - else - { - isPPBarBreaked = false; - } - bool isBoxBreaked = isCBarBreaked || - isPBarBreaked || - isPPBarBreaked; - - // - bool isCBarRejected = IsBarReject( - appliedPrice, - forDir, - cBar // - ); - if (isCBarRejected) - { - rejectionBar = cBar; - } - bool isPBarRejected = IsBarReject( - appliedPrice, - forDir, - pBar // - ); - if (!isCBarRejected && isPBarRejected) - { - rejectionBar = pBar; - } - else - { - isPBarRejected = false; - } - bool isPPBarRejected = IsBarReject( - appliedPrice, - forDir, - ppBar // - ); - if (!isCBarRejected && - !isPBarRejected && - isPPBarRejected) - { - rejectionBar = ppBar; - } - else - { - isPPBarRejected = false; - } - bool isBoxRejected = isCBarRejected || - isPBarRejected || - isPPBarRejected; - - // - result = - // - isBoxBreaked || - isBoxRejected || - hasValidPressuredSwing - // - ; - if (!result) - { - // - swingBar.Clean(); - breakerBar.Clean(); - appliedBox.Clean(); - momentumBar.Clean(); - rejectionBar.Clean(); - } - else - { - appliedBox = box; - } - - // - zBar.Clean(); - cBar.Clean(); - pBar.Clean(); - ppBar.Clean(); - - // - return result; - } - - // -}; - -// -struct X121SMCXWZWorkingZone -{ - // - string symbol; - ENUM_TIMEFRAMES period; - - // - double upper; - double lower; - - // - double zoneUpper; - double zoneLower; - - // - double quarter1; - double quarter2; - double quarter3; - - // - datetime to; - datetime from; - - // - XOHCL swingBar; - XOHCL breakerBar; - XOHCL momentumBar; - XOHCL rejectionBar; - XBoxZone appliedBox; - - // - X121SMCXWZWorkingZone() - { - Clean(); - } - - // - void Clean() - { - // - upper = 0; - lower = 0; - quarter1 = 0; - quarter2 = 0; - quarter3 = 0; - zoneLower = 0; - zoneUpper = 0; - - // - from = NULL; - symbol = NULL; - period = NULL; - - // - CleanConditionBars(); - - // - ZeroMemory(this); - } - - // - void CleanConditionBars() - { - // - swingBar.Clean(); - breakerBar.Clean(); - appliedBox.Clean(); - momentumBar.Clean(); - rejectionBar.Clean(); - } - - // - bool IsValid() - { - // - bool result = false; - - // - result = - lower > 0 && - upper > 0 && - quarter1 > 0 && - quarter2 > 0 && - quarter3 > 0 && - upper > lower && - zoneLower > 0 && - zoneUpper > 0 && - IsValid(from) && - IsValid(symbol) && - IsValid(period) && - zoneUpper > upper && - zoneLower < lower; - - // - return result; - } - - // - bool IsDestroyed( - ENUM_X_DIRECTION &destroyedDir, - int barIndex = 0, - ENUM_TIMEFRAMES forPeriod = NULL // - ) - { - // - bool result = false; - - // - if (barIndex < 0) - { - barIndex = 0; - } - - // - if (!IsValid(forPeriod)) - { - forPeriod = period; - } - - // - destroyedDir = X_DIRECTION_NONE; - - // - result = IsValid(); - if (!result) - { - return result; - } - - // - XOHCL bar; - result = bar.Init( - symbol, - forPeriod, - barIndex // - ); - if (!result) - { - return result; - } - - // - bool isUpperBreaked = - bar.high > zoneUpper && - bar.close > zoneUpper; - - // - bool isLowerBreaked = - bar.low < zoneLower && - bar.close < zoneLower; - - // - result = isUpperBreaked || - isLowerBreaked; - if (result) - { - // - destroyedDir = - isUpperBreaked - ? X_DIRECTION_BULLISH - : X_DIRECTION_BEARISH; - } - - // - return result; - } - - // -}; - -// -// Definitions ... -struct X121SMCStrategyXWZSignalConditions -{ - // - // Props ... - - // - string symbol; - ENUM_TIMEFRAMES period; - - // - double sl; - double target; - double reward; - double amountPercent; - ENUM_X_DIRECTION dir; - ENUM_X_POSITION_TYPES type; - - // - // Setup Props ... - - // - datetime setupTime; - datetime triggerTime; - - // - double pivot; - double point; - - // - ENUM_X121SMC_XWZ_PRIORITY priority; - - // - // Working Zone ... - XCFVG *fairValueGap; - XCOrderBlock *orderBlock; - XCSupplyZone *supplyZone; - XCDemandZone *demandZone; - X121SMCXWZWorkingZone workingZone; - - // - // X121SMCXWZZone startZone; - X121SMCXWZZone startZones[]; - - // - // Constructor ... - X121SMCStrategyXWZSignalConditions() - { - Clean(); - } - - // - // Tools ... - - /** - * Cleaning Up ... - */ - void Clean() - { - // - sl = 0; - target = 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; - - // - target = 0; - reward = 0; - amountPercent = 0; - - // - ZeroMemory(supplyZone); - - // - ZeroMemory(demandZone); - - // - ZeroMemory(orderBlock); - - // - ZeroMemory(fairValueGap); - - // - // startZone.Clean(); - Clean(startZones); - - // - workingZone.Clean(); - } - - // - // - // - - // - bool HasWorkingZone() - { - return workingZone.IsValid(); - } - - // - bool HasOrderBlock() - { - return orderBlock != NULL && - orderBlock.IsValid(); - } - - // - bool HasFairValueGap() - { - return fairValueGap != NULL && - fairValueGap.IsValid(); - } - - // - bool HasSupplyZone() - { - return supplyZone != NULL && - supplyZone.IsValid(); - } - - // - bool HasDemandZone() - { - return demandZone != NULL && - demandZone.IsValid(); - } - - // - bool HasStartZones() - { - return HasChild(startZones); - } - - // - int CountStartZones() - { - return ArraySize(startZones); - } - - // - void UpdateTo(datetime value = NULL) - { - // - value = NormalizeTime(value); - - // - bool hasSupplyZone = HasSupplyZone(); - if (hasSupplyZone) - { - supplyZone.To(value); - } - - // - bool hasDemandZone = HasDemandZone(); - if (hasDemandZone) - { - demandZone.To(value); - } - - // - bool hasOrderBlock = HasOrderBlock(); - if (hasOrderBlock) - { - orderBlock.To(value); - } - - // - bool hasFairValueGap = HasFairValueGap(); - if (hasFairValueGap) - { - fairValueGap.To(value); - } - - // - // Working Zone ... - bool hasWorkingZone = HasWorkingZone(); - if (hasWorkingZone) - { - workingZone.to = value; - } - - // - // Start Zone ... - bool hasStartZones = HasStartZones(); - if (hasStartZones) - { - // - int count = CountStartZones(); - for (int i = 0; i < count; i++) - { - // - bool hasOB = startZones[i].HasOB(); - if (hasOB) - { - startZones[i].ob.To(value); - } - - // - bool hasFVG = startZones[i].HasFVG(); - if (hasFVG) - { - startZones[i].fvg.To(value); - } - - // - bool hasSupply = startZones[i].HasSupply(); - if (hasSupply) - { - startZones[i].supply.To(value); - } - - // - bool hasDemand = startZones[i].HasDemand(); - if (hasDemand) - { - startZones[i].demand.To(value); - } - - // - bool hasSupport = startZones[i].HasSupport(); - if (hasSupport) - { - startZones[i].support.To(value); - } - - // - bool hasResistance = startZones[i].HasResistance(); - if (hasResistance) - { - startZones[i].resistance.To(value); - } - } - } - } - - // - // - // - - // - // Working Zone is an Area which - // we decide to trade inside it ... - bool ExtractWorkingZone( - XPOIState &htfState, - XPOIState &mtfState, - XPOIState &stfState, - int barIndex = 0 // - ) - { - // - bool result = false; - - // - if (barIndex < 0) - { - barIndex = 0; - } - int zIndex = barIndex; - - // - result = !HasWorkingZone(); - if (!result) - { - return result; - } - - // - result = IsValid(symbol) && - IsValid(period); - if (!result) - { - // - Clean(); - return result; - } - - // - datetime cTime = iTime( - symbol, - period, - zIndex // - ); - - // - result = - // - htfState.IsValid() && - htfState.HasChild() && - htfState.HasSupplyZones() && - htfState.HasDemandZones() && - // - mtfState.IsValid() && - mtfState.HasChild() && - mtfState.HasSupplyZones() && - mtfState.HasDemandZones() && - // - stfState.IsValid() && - stfState.HasChild() - // - ; - if (!result) - { - return result; - } - - // - // Retrieve Highest Supply Zone ... - int hSupplyIDX = GetHighest(htfState.supplyZones); - int lDemandIDX = GetLowest(htfState.demandZones); - - // - result = - // - IsValidIndex(hSupplyIDX) && - IsValidIndex(lDemandIDX) - // - ; - if (!result) - { - return result; - } - - // - supplyZone = htfState.supplyZones[hSupplyIDX]; - demandZone = htfState.demandZones[lDemandIDX]; - - // - result = - // - supplyZone != NULL && - demandZone != NULL && - supplyZone.IsValid() && - demandZone.IsValid() - // - ; - if (!result) - { - // - Clean(); - return result; - } - - // - // Check Validation of Supply and Demand Zones ... - lDemandIDX = GetLowest(mtfState.demandZones); - hSupplyIDX = GetHighest(mtfState.supplyZones); - result = IsValidIndex(lDemandIDX) && - IsValidIndex(hSupplyIDX); - if (!result) - { - // - Clean(); - return result; - } - - // - // Validate Supply and Demand ... - bool isMTFHSupplyInside = - IsInside( - mtfState.supplyZones[hSupplyIDX], - supplyZone); - bool isMTFLDemandInside = - IsInside( - mtfState.demandZones[lDemandIDX], - demandZone // - ); - if (isMTFHSupplyInside && - !isMTFLDemandInside) - { - demandZone = mtfState.demandZones[lDemandIDX]; - } - else if (!isMTFHSupplyInside && - isMTFLDemandInside) - { - supplyZone = mtfState.supplyZones[hSupplyIDX]; - } - else if (isMTFHSupplyInside && - isMTFLDemandInside) - { - // - supplyZone = mtfState.supplyZones[hSupplyIDX]; - demandZone = mtfState.demandZones[lDemandIDX]; - } - - // - // Check Zones Validation ... - bool hasTrend = - supplyZone != NULL && - supplyZone.IsValid() && - demandZone != NULL && - demandZone.IsValid(); - result = hasTrend; - if (!result) - { - // - Clean(); - return result; - } - - // - datetime from = MathMax( - supplyZone.From(), - demandZone.From()); - - // - int fromIndex = iBarShift( - symbol, - period, - from // - ); - - // - // Detect Trend ... - ENUM_X_DIRECTION trend = X_DIRECTION_NONE; - datetime supplyTouch = NULL; - datetime demandTouch = NULL; - for (int i = zIndex; i < fromIndex; i++) - { - // - XOHCL iBar; - bool isInited = iBar.Init( - symbol, - period, - i // - ); - if (!isInited) - { - continue; - } - - // - bool isTouchSupplyZone = - // - iBar.low < supplyZone.Lower() && - iBar.GetUp() > supplyZone.Lower() - // - ; - if (isTouchSupplyZone && - !IsValid(supplyTouch)) - { - supplyTouch = iBar.time; - } - - // - bool isTouchDemandZone = - // - iBar.high > demandZone.Upper() && - iBar.GetDown() < demandZone.Upper() - // - ; - if (isTouchDemandZone && - !IsValid(demandTouch)) - { - demandTouch = iBar.time; - } - - // - bool canBreak = - IsValid(supplyTouch) && - IsValid(demandTouch); - - // - iBar.Clean(); - - // - if (canBreak) - { - break; - } - } - - // - hasTrend = - // - IsValid(supplyTouch) || - IsValid(demandTouch) - // - ; - if (hasTrend) - { - // - trend = - // - supplyTouch > demandTouch - ? X_DIRECTION_BEARISH - : X_DIRECTION_BULLISH - // - ; - } - - // - // Check Trend ... - result = hasTrend; - if (!result) - { - // - Clean(); - return result; - } - - // - bool hasBullishTrend = IsBullish(trend); - bool hasBearishTrend = IsBearish(trend); - - // - // Find Order Block and FVG for Trend Approve ... - - // - bool isBullishTrendApproved = false; - bool isBearishTrendApproved = false; - - // - // Now We Have to Detect at least One OrderBlock with FVG ... - // for Trend Approvement ... - bool hasOrderBlock = HasOrderBlock(); - bool hasFairValueGap = HasFairValueGap(); - if (!hasOrderBlock && - !hasFairValueGap) - { - // - int count = 0; - bool has = false; - - // - XCFVG *fvg = NULL; - XCOrderBlock *ob = NULL; - - // - has = mtfState.HasBullishOrderBlocks(); - count = mtfState.CountBullishOrderBlocks(); - - // - if (has) - { - // - // Check Order Block ... - for (int i = 0; i < count; i++) - { - // - XCOrderBlock *iOB = mtfState.bullishOrderBlocks[i]; - - // - iOB.To(cTime); - - // - // Check From Passes ... - bool isFromPassed = iOB.From() > demandZone.From(); - if (!isFromPassed) - { - continue; - } - - // - // Must inside DemandZone ... - bool isInsideDemand = IsInsideDiff( - iOB, - demandZone // - ); - if (!isInsideDemand) - { - continue; - } - - // - // Check Started ... - XOHCL startedBar; - ENUM_X_DIRECTION startedDir; - bool isStarted = iOB.IsStarted( - X_DIRECTION_BULLISH, - startedBar, - startedDir // - ); - if (!isStarted) - { - // - startedBar.Clean(); - continue; - } - - // - // Converts to Box ... - XBoxZone obBox; - bool hasOBBox = ToBox( - obBox, - iOB // - ); - if (!hasOBBox) - { - // - obBox.Clean(); - startedBar.Clean(); - continue; - } - - // - // Check Zone Must not Used before ... - bool isUsed = IsBoxUsed( - obBox, - startedBar.Index() - 1, - zIndex // - ); - if (isUsed) - { - // - obBox.Clean(); - startedBar.Clean(); - continue; - } - - // - ob = iOB; - - // - obBox.Clean(); - startedBar.Clean(); - - // - break; - } - - // - // Detect Fair Value Gap ... - if (ob != NULL && - ob.IsValid()) - { - // - has = stfState.HasBullishFairValueGaps(); - count = stfState.CountBullishFairValueGaps(); - if (has) - { - // - // Check Fir Value Gap ... - for (int i = 0; i < count; i++) - { - // - XCFVG *iFVG = stfState.bullishFairValueGaps[i]; - - // - iFVG.To(cTime); - - // - // Check From Passes ... - bool isFromPassed = iFVG.From() > ob.From(); - if (!isFromPassed) - { - continue; - } - - // - // Check Started ... - XOHCL startedBar; - ENUM_X_DIRECTION startedDir; - bool isStarted = iFVG.IsStarted( - X_DIRECTION_BULLISH, - startedBar, - startedDir // - ); - if (!isStarted) - { - // - startedBar.Clean(); - continue; - } - - // - // Converts to Box ... - XBoxZone fvgBox; - bool hasFVGBox = ToBox( - fvgBox, - iFVG // - ); - if (!hasFVGBox) - { - // - fvgBox.Clean(); - startedBar.Clean(); - continue; - } - - // - // Check Inside Order Block ... - bool isInside = IsInsideDiff( - iFVG, - ob, - true // Force Side Out ... - ); - if (!isInside) - { - continue; - } - - // - fvg = iFVG; - - // - fvgBox.Clean(); - startedBar.Clean(); - - // - break; - } - } - else - { - // - ob = NULL; - } - } - - // - if (ob != NULL && - fvg != NULL) - { - // - orderBlock = ob; - fairValueGap = fvg; - } - - // - hasOrderBlock = HasOrderBlock(); - hasFairValueGap = HasFairValueGap(); - isBullishTrendApproved = hasOrderBlock && - hasFairValueGap; - } - - // - if (!isBullishTrendApproved) - { - // - has = mtfState.HasBearishOrderBlocks(); - count = mtfState.CountBearishOrderBlocks(); - - // - if (has) - { - // - // Check Order Block ... - for (int i = 0; i < count; i++) - { - // - XCOrderBlock *iOB = mtfState.bearishOrderBlocks[i]; - - // - iOB.To(cTime); - - // - // Check From Passes ... - bool isFromPassed = iOB.From() > supplyZone.From(); - if (!isFromPassed) - { - continue; - } - - // - // Must inside DemandZone ... - bool isInsideDemand = IsInsideDiff( - iOB, - supplyZone // - ); - if (!isInsideDemand) - { - continue; - } - - // - // Check Started ... - XOHCL startedBar; - ENUM_X_DIRECTION startedDir; - bool isStarted = iOB.IsStarted( - X_DIRECTION_BEARISH, - startedBar, - startedDir // - ); - if (!isStarted) - { - // - startedBar.Clean(); - continue; - } - - // - // Converts to Box ... - XBoxZone obBox; - bool hasOBBox = ToBox( - obBox, - iOB // - ); - if (!hasOBBox) - { - // - obBox.Clean(); - startedBar.Clean(); - continue; - } - - // - // Check Zone Must not Used before ... - bool isUsed = IsBoxUsed( - obBox, - startedBar.Index() - 1, - zIndex // - ); - if (isUsed) - { - // - obBox.Clean(); - startedBar.Clean(); - continue; - } - - // - ob = iOB; - - // - obBox.Clean(); - startedBar.Clean(); - - // - break; - } - - // - // Detect Fair Value Gap ... - if (ob != NULL && - ob.IsValid()) - { - // - has = stfState.HasBearishFairValueGaps(); - count = stfState.CountBearishFairValueGaps(); - if (has) - { - // - // Check Fir Value Gap ... - for (int i = 0; i < count; i++) - { - // - XCFVG *iFVG = stfState.bearishFairValueGaps[i]; - - // - iFVG.To(cTime); - - // - // Check From Passes ... - bool isFromPassed = iFVG.From() > ob.From(); - if (!isFromPassed) - { - continue; - } - - // - // Check Started ... - XOHCL startedBar; - ENUM_X_DIRECTION startedDir; - bool isStarted = iFVG.IsStarted( - X_DIRECTION_BEARISH, - startedBar, - startedDir // - ); - if (!isStarted) - { - // - startedBar.Clean(); - continue; - } - - // - // Converts to Box ... - XBoxZone fvgBox; - bool hasFVGBox = ToBox( - fvgBox, - iFVG // - ); - if (!hasFVGBox) - { - // - fvgBox.Clean(); - startedBar.Clean(); - continue; - } - - // - // Check Inside Order Block ... - bool isInside = IsInsideDiff( - iFVG, - ob, - true // Force Side Out ... - ); - if (!isInside) - { - continue; - } - - // - fvg = iFVG; - - // - fvgBox.Clean(); - startedBar.Clean(); - - // - break; - } - } - else - { - // - ob = NULL; - } - } - - // - if (ob != NULL && - fvg != NULL) - { - // - orderBlock = ob; - fairValueGap = fvg; - } - - // - hasOrderBlock = HasOrderBlock(); - hasFairValueGap = HasFairValueGap(); - isBearishTrendApproved = hasOrderBlock && - hasFairValueGap; - } - } - } - - // - // Check Trend Approved ... - bool isTrendApproved = - hasOrderBlock && - hasFairValueGap && - (isBullishTrendApproved || - isBearishTrendApproved); - result = isTrendApproved; - if (!result) - { - // - Clean(); - return result; - } - - // - // Prepare Working Zone ... - workingZone.symbol = symbol; - workingZone.period = period; - - // - workingZone.upper = supplyZone.Lower(); - workingZone.zoneUpper = supplyZone.Upper(); - - // - workingZone.lower = demandZone.Upper(); - workingZone.zoneLower = demandZone.Lower(); - - // - workingZone.from = from; - - // - double upper = workingZone.upper; - double range = - workingZone.upper - workingZone.lower; - double ranegPercent = range / 100; - double quarterValue = ranegPercent * 25; - - // - workingZone.quarter1 = upper - (quarterValue * 1); - workingZone.quarter2 = upper - (quarterValue * 2); - workingZone.quarter3 = upper - (quarterValue * 3); - - // - result = workingZone.IsValid(); - if (!result) - { - Clean(); - } - - // - return result; - } - - // - bool IsWorkingZoneDestroyed( - ENUM_X_DIRECTION &destroyedDir, - int barIndex = 0, - ENUM_TIMEFRAMES forPeriod = NULL // - ) - { - // - bool result = false; - - // - if (barIndex < 0) - { - barIndex = 0; - } - - // - if (!IsValid(forPeriod)) - { - forPeriod = period; - } - - // - destroyedDir = X_DIRECTION_NONE; - - // - result = workingZone.IsValid(); - if (!result) - { - return result; - } - - // - result = workingZone.IsDestroyed( - destroyedDir, - barIndex, - forPeriod // - ); - - // - return result; - } - - // - bool DetectTrend( - ENUM_X_DIRECTION &trend, - int barIndex = 0, - ENUM_TIMEFRAMES forPeriod = NULL // - ) - { - // - bool result = false; - - // - if (barIndex < 0) - { - barIndex = 0; - } - - // - if (forPeriod == NULL) - { - forPeriod = period; - } - - // - trend = X_DIRECTION_NONE; - - // - result = HasWorkingZone(); - if (!result) - { - return result; - } - - // - int FromIndex = iBarShift( - symbol, - forPeriod, - workingZone.from // - ); - - // - datetime supplyTouch = NULL; - datetime demandTouch = NULL; - for (int i = barIndex; i < FromIndex; i++) - { - // - XOHCL iBar; - bool isInited = iBar.Init( - symbol, - forPeriod, - i // - ); - if (!isInited) - { - continue; - } - - // - bool isTouchSupplyZone = - // - iBar.low < supplyZone.Lower() && - iBar.GetUp() > supplyZone.Lower() - // - ; - if (isTouchSupplyZone && - !IsValid(supplyTouch)) - { - supplyTouch = iBar.time; - } - - // - bool isTouchDemandZone = - // - iBar.high > demandZone.Upper() && - iBar.GetDown() < demandZone.Upper() - // - ; - if (isTouchDemandZone && - !IsValid(demandTouch)) - { - demandTouch = iBar.time; - } - - // - bool canBreak = - IsValid(supplyTouch) && - IsValid(demandTouch); - - // - iBar.Clean(); - - // - if (canBreak) - { - break; - } - } - - // - result = - // - IsValid(supplyTouch) || - IsValid(demandTouch) - // - ; - if (result) - { - // - trend = - // - supplyTouch > demandTouch - ? X_DIRECTION_BEARISH - : X_DIRECTION_BULLISH - // - ; - } - - // - return result; - } - - // - bool DetectStartZones( - ENUM_X_DIRECTION forDir, - XPOIState &obState, - XPOIState &fvgState, - XPOIState &otherState, - XC121SMCCycleHelper *cycleHelper // - ) - { - // - bool result = false; - - // - result = obState.IsValid() && - obState.HasChild() && - fvgState.IsValid() && - fvgState.HasChild() && - otherState.IsValid() && - otherState.HasChild() && - HasDirection(forDir); - if (!result) - { - return result; - } - - // - bool isBullish = IsBullish(forDir); - - // - int idx = -1; - int count = 0; - int has = false; - - // - X121SMCXWZZone startZone; - X121SMCXWZZone lastStartZone; - bool hasLastStartZone = HasStartZones(); - if (hasLastStartZone) - { - // - int startZonesCount = CountStartZones(); - lastStartZone = startZones[startZonesCount - 1]; - } - - // - if (isBullish) - { - // - has = obState.HasBullishOrderBlocks(); - if (has) - { - // - count = obState.CountBullishOrderBlocks(); - for (int i = 0; i < count; i++) - { - // - XCOrderBlock *iOB = obState.bullishOrderBlocks[i]; - - // - bool isFromPassed = - !hasLastStartZone - ? true - : iOB.From() > lastStartZone.ob.From(); - if (!isFromPassed) - { - // - ZeroMemory(iOB); - continue; - } - - // - XOHCL startedBar; - ENUM_X_DIRECTION startedDir; - bool isStarted = iOB.IsStarted( - forDir, - startedBar, - startedDir // - ); - if (!isStarted) - { - // - ZeroMemory(iOB); - startedBar.Clean(); - continue; - } - - // - XOHCL activatedBar; - ENUM_X_DIRECTION activatedDir; - bool isActivated = iOB.IsActivated( - forDir, - activatedBar, - activatedDir // - ); - if (isActivated) - { - // - ZeroMemory(iOB); - startedBar.Clean(); - activatedBar.Clean(); - continue; - } - - // - bool isPlacePassed = - !IsInsideDiff( - iOB, - demandZone // - ) && - (!hasLastStartZone - ? workingZone.IsValid() && - HasOrderBlock() && - forDir == orderBlock.GetDirection() - ? IsAbove( - iOB, - orderBlock, - true // Ignore Inside ... - ) - : true - : lastStartZone.HasOB() && - IsAbove( - iOB, - lastStartZone.ob, - true // Ignore Inside ... - )); - if (!isPlacePassed) - { - // - ZeroMemory(iOB); - startedBar.Clean(); - activatedBar.Clean(); - continue; - } - - // - // Attache OB ... - startZone.ob = iOB; - - // - // Now we Have to Find Specified FVG ... - has = fvgState.HasBullishFairValueGaps(); - if (has) - { - // - int jCount = fvgState.CountBullishFairValueGaps(); - for (int j = 0; j < jCount; j++) - { - // - XCFVG *jFVG = fvgState.bullishFairValueGaps[j]; - - // - startedBar.Clean(); - startedDir = X_DIRECTION_NONE; - isStarted = jFVG.IsStarted( - forDir, - startedBar, - startedDir // - ); - if (!isStarted) - { - // - ZeroMemory(jFVG); - startedBar.Clean(); - continue; - } - - // - activatedBar.Clean(); - activatedDir = X_DIRECTION_NONE; - isActivated = jFVG.IsActivated( - forDir, - activatedBar, - activatedDir // - ); - if (isActivated) - { - // - ZeroMemory(jFVG); - startedBar.Clean(); - activatedBar.Clean(); - continue; - } - - // - isPlacePassed = - // - !IsInsideDiff( - jFVG, - demandZone // - ) && - IsAboveDiff( - jFVG, - iOB, - true // Ignore Inside ... - ) - // - ; - if (!isPlacePassed) - { - // - ZeroMemory(jFVG); - startedBar.Clean(); - activatedBar.Clean(); - } - - // - startZone.fvg = jFVG; - } - } - - // - startedBar.Clean(); - activatedBar.Clean(); - } - } - } - else - { - // - has = obState.HasBearishOrderBlocks(); - if (has) - { - // - count = obState.CountBearishOrderBlocks(); - for (int i = 0; i < count; i++) - { - // - XCOrderBlock *iOB = obState.bearishOrderBlocks[i]; - - // - bool isFromPassed = - !hasLastStartZone - ? true - : iOB.From() > lastStartZone.ob.From(); - if (!isFromPassed) - { - // - ZeroMemory(iOB); - continue; - } - - // - XOHCL startedBar; - ENUM_X_DIRECTION startedDir; - bool isStarted = iOB.IsStarted( - forDir, - startedBar, - startedDir // - ); - if (!isStarted) - { - // - ZeroMemory(iOB); - startedBar.Clean(); - continue; - } - - // - XOHCL activatedBar; - ENUM_X_DIRECTION activatedDir; - bool isActivated = iOB.IsActivated( - forDir, - activatedBar, - activatedDir // - ); - if (isActivated) - { - // - ZeroMemory(iOB); - startedBar.Clean(); - activatedBar.Clean(); - continue; - } - - // - bool isPlacePassed = - !IsInsideDiff( - iOB, - supplyZone // - ) && - (!hasLastStartZone - ? workingZone.IsValid() && - HasOrderBlock() && - forDir == orderBlock.GetDirection() - ? IsBelow( - iOB, - orderBlock, - true // Ignore Inside ... - ) - : true - : lastStartZone.HasOB() && - IsBelow( - iOB, - lastStartZone.ob, - true // Ignore Inside ... - )); - if (!isPlacePassed) - { - // - ZeroMemory(iOB); - startedBar.Clean(); - activatedBar.Clean(); - continue; - } - - // - // Attache OB ... - startZone.ob = iOB; - - // - // Now we Have to Find Specified FVG ... - has = fvgState.HasBearishFairValueGaps(); - if (has) - { - // - int jCount = fvgState.CountBearishFairValueGaps(); - for (int j = 0; j < jCount; j++) - { - // - XCFVG *jFVG = fvgState.bearishFairValueGaps[j]; - - // - startedBar.Clean(); - startedDir = X_DIRECTION_NONE; - isStarted = jFVG.IsStarted( - forDir, - startedBar, - startedDir // - ); - if (!isStarted) - { - // - ZeroMemory(jFVG); - startedBar.Clean(); - continue; - } - - // - activatedBar.Clean(); - activatedDir = X_DIRECTION_NONE; - isActivated = jFVG.IsActivated( - forDir, - activatedBar, - activatedDir // - ); - if (isActivated) - { - // - ZeroMemory(jFVG); - startedBar.Clean(); - activatedBar.Clean(); - continue; - } - - // - isPlacePassed = - // - !IsInsideDiff( - jFVG, - supplyZone // - ) && - IsBelowDiff( - jFVG, - iOB, - true // Ignore Inside ... - ) - // - ; - if (!isPlacePassed) - { - // - ZeroMemory(jFVG); - startedBar.Clean(); - activatedBar.Clean(); - } - - // - startZone.fvg = jFVG; - } - } - - // - startedBar.Clean(); - activatedBar.Clean(); - } - } - } - - // - bool hasOBFVG = startZone.HasOB() && - startZone.HasFVG(); - result = hasOBFVG; - if (!result) - { - // - startZone.Clean(); - lastStartZone.Clean(); - - // - return result; - } - - // - XBoxZone startBox; - bool hasStartBox = startZone.AsBox(startBox); - result = hasStartBox; - if (!result) - { - // - startBox.Clean(); - startZone.Clean(); - lastStartZone.Clean(); - - // - return result; - } - - // - // Detect Other Zones Inside Box ... - XBoxZone tmpBoxes[]; - - // - // Supply Zones ... - has = otherState.HasSupplyZones(); - if (has) - { - // - count = ToBox( - otherState.supplyZones, - tmpBoxes // - ); - - // - has = IsValidSize(count); - if (has) - { - // - for (int i = 0; i < count; i++) - { - // - XBoxZone iBox = tmpBoxes[i]; - - // - bool isPlacePassed = - // - IsBoxInside( - iBox, - startBox, - false, - false // - ) - // - ; - if (!isPlacePassed) - { - // - iBox.Clean(); - continue; - } - - // - startZone.supply = otherState.supplyZones[i]; - - // - iBox.Clean(); - break; - } - } - } - - // - // Demand Zones ... - Clean(tmpBoxes); - has = otherState.HasDemandZones(); - if (has) - { - // - count = ToBox( - otherState.demandZones, - tmpBoxes // - ); - - // - has = IsValidSize(count); - if (has) - { - // - for (int i = 0; i < count; i++) - { - // - XBoxZone iBox = tmpBoxes[i]; - - // - bool isPlacePassed = - // - IsBoxInside( - iBox, - startBox, - false, - false // - ) - // - ; - if (!isPlacePassed) - { - // - iBox.Clean(); - continue; - } - - // - startZone.demand = otherState.demandZones[i]; - - // - iBox.Clean(); - break; - } - } - } - - // - // Support Zones ... - Clean(tmpBoxes); - has = otherState.HasSupportZones(); - if (has) - { - // - count = ToBox( - otherState.supportZones, - tmpBoxes // - ); - - // - has = IsValidSize(count); - if (has) - { - // - for (int i = 0; i < count; i++) - { - // - XBoxZone iBox = tmpBoxes[i]; - - // - bool isPlacePassed = - // - IsBoxInside( - iBox, - startBox, - false, - false // - ) - // - ; - if (!isPlacePassed) - { - // - iBox.Clean(); - continue; - } - - // - startZone.support = otherState.supportZones[i]; - - // - iBox.Clean(); - break; - } - } - } - - // - // Resistance Zones ... - Clean(tmpBoxes); - has = otherState.HasResistanceZones(); - if (has) - { - // - count = ToBox( - otherState.resistanceZones, - tmpBoxes // - ); - - // - has = IsValidSize(count); - if (has) - { - // - for (int i = 0; i < count; i++) - { - // - XBoxZone iBox = tmpBoxes[i]; - - // - bool isPlacePassed = - // - IsBoxInside( - iBox, - startBox, - false, - false // - ) - // - ; - if (!isPlacePassed) - { - // - iBox.Clean(); - continue; - } - - // - startZone.resistance = otherState.resistanceZones[i]; - - // - iBox.Clean(); - break; - } - } - } - - // - result = startZone.IsValid() && - startZone.HasDirection(); - if (result) - { - // - AddRef( - startZone, - startZones // - ); - } - - // - Clean(tmpBoxes); - startBox.Clean(); - startZone.Clean(); - lastStartZone.Clean(); - - // - return result; - } - - // - void DetectPriority( - ENUM_X121SMC_XWZ_PRIORITY &bullish, - ENUM_X121SMC_XWZ_PRIORITY &bearish, - int barIndex = 0, - ENUM_TIMEFRAMES forPeriod = NULL // - ) - { - // - bullish = X121SMC_XWZ_PRIORITY_NONE; - bearish = X121SMC_XWZ_PRIORITY_NONE; - - // - if (barIndex < 0) - { - barIndex = 0; - } - - // - if (!IsValid(forPeriod)) - { - forPeriod = period; - } - - // - bool hasWorkingZone = HasWorkingZone(); - if (!hasWorkingZone) - { - return; - } - - // - XOHCL zBar; - bool isInited = zBar.Init( - symbol, - forPeriod, - barIndex // - ); - if (!isInited) - { - // - zBar.Clean(); - return; - } - - // - XOHCL cBar; - isInited = zBar.GetPreviousBar(cBar); - if (!isInited) - { - // - zBar.Clean(); - cBar.Clean(); - return; - } - - // - // ZoneUpper, Upper ... - if (cBar.low > workingZone.upper && - cBar.high < workingZone.zoneUpper && - zBar.low > workingZone.upper && - zBar.high < workingZone.zoneUpper) - { - // - bullish = X121SMC_XWZ_PRIORITY_NONE; - bearish = X121SMC_XWZ_PRIORITY_STRONG_HIGH; - } - // - // Upper, Quarter1 ... - else if (cBar.low > workingZone.quarter1 && - cBar.high < workingZone.upper && - zBar.low > workingZone.quarter1 && - zBar.high < workingZone.upper) - { - // - bullish = X121SMC_XWZ_PRIORITY_WEAK; - bearish = X121SMC_XWZ_PRIORITY_HIGH; - } - // - // Quarter1, Quarter2 ... - else if (cBar.low > workingZone.quarter2 && - cBar.high < workingZone.quarter1 && - zBar.low > workingZone.quarter2 && - zBar.high < workingZone.quarter1) - { - // - bullish = X121SMC_XWZ_PRIORITY_LOW; - bearish = X121SMC_XWZ_PRIORITY_REGULAR; - } - // - // Quarter2, Quarter3 ... - else if (cBar.low > workingZone.quarter3 && - cBar.high < workingZone.quarter2 && - zBar.low > workingZone.quarter3 && - zBar.high < workingZone.quarter2) - { - // - bullish = X121SMC_XWZ_PRIORITY_REGULAR; - bearish = X121SMC_XWZ_PRIORITY_LOW; - } - // - // Quarter3, Lower ... - else if (cBar.low > workingZone.lower && - cBar.high < workingZone.quarter3 && - zBar.low > workingZone.lower && - zBar.high < workingZone.quarter3) - { - // - bullish = X121SMC_XWZ_PRIORITY_HIGH; - bearish = X121SMC_XWZ_PRIORITY_WEAK; - } - // - // Lower, ZoneLower ... - else if (cBar.low > workingZone.zoneLower && - cBar.high < workingZone.lower && - zBar.low > workingZone.zoneLower && - zBar.high < workingZone.lower) - { - // - bullish = X121SMC_XWZ_PRIORITY_STRONG_HIGH; - bearish = X121SMC_XWZ_PRIORITY_NONE; - } - - // - zBar.Clean(); - cBar.Clean(); - } - - // - bool HasConditions( - double &_pivot, - double &_point, - ENUM_X_DIRECTION &conditionsDir, - XPOIState &state, - int barIndex = 0, - ENUM_TIMEFRAMES forPeriod = NULL // - ) - { - // - bool result = false; - - // - _pivot = 0; - _point = 0; - conditionsDir = X_DIRECTION_NONE; - - // - if (barIndex < 0) - { - barIndex = 0; - } - - // - if (forPeriod == NULL) - { - forPeriod = period; - } - - // - result = - // - IsValid(symbol) && - IsValid(period) && - state.IsValid() && - HasWorkingZone() && - state.HasChild() - // - ; - if (!result) - { - return result; - } - - // - result = false; - - // - // Detect Conditions Based On Start Zones ... - bool hasStartZones = HasStartZones(); - if (hasStartZones) - { - // - int selectedIndex = -1; - int count = CountStartZones(); - for (int i = 0; i < count; i++) - { - // - X121SMCXWZZone iStartZone = startZones[i]; - - // - XBoxZone selectedBox; - bool hasConditions = false; - bool isBullish = iStartZone.IsBullish(); - - // - // Conditions Inside Box ... - bool isPriceInside = iStartZone.IsPriceInside( - selectedBox, - barIndex, - forPeriod, - false, - false // - ); - if (isPriceInside) - { - // - // hasConditions = iStartZone.HasInsideConditions( - // state, - // barIndex, - // period // - // ); - - // - hasConditions = true; - - // - if (hasConditions) - { - // - _pivot = - // - isBullish - ? selectedBox.lower - : selectedBox.upper - // - ; - - // - _point = - // - isBullish - ? selectedBox.upper - : selectedBox.lower - // - ; - - // - conditionsDir = selectedBox.dir; - result = hasConditions; - iStartZone.Clean(); - break; - } - } - - // // - // // Order Block Rejection Conditions ... - // bool hasOBBox = ToBox( - // selectedBox, - // iStartZone.ob // - // ); - // if (hasOBBox && - // !hasConditions) - // { - // // - // hasConditions = iStartZone.HasBoxConitions( - // selectedBox, - // state, - // barIndex, - // forPeriod // - // ); - - // // - // if (hasConditions) - // { - // // - // _pivot = - // // - // isBullish - // ? selectedBox.lower - // : selectedBox.upper - // // - // ; - - // // - // _point = - // // - // isBullish - // ? selectedBox.upper - // : selectedBox.lower - // // - // ; - - // // - // conditionsDir = selectedBox.dir; - // result = hasConditions; - // iStartZone.Clean(); - // break; - // } - // } - - // // - // // Fair Value Gap Rejection Conditions ... - // bool hasFVGBox = ToBox( - // selectedBox, - // iStartZone.fvg // - // ); - // if (hasFVGBox) - // { - // // - // hasConditions = iStartZone.HasBoxConitions( - // selectedBox, - // state, - // barIndex, - // forPeriod // - // ); - - // // - // if (hasConditions) - // { - // // - // _pivot = - // // - // isBullish - // ? selectedBox.lower - // : selectedBox.upper - // // - // ; - - // // - // _point = - // // - // isBullish - // ? selectedBox.upper - // : selectedBox.lower - // // - // ; - - // // - // conditionsDir = selectedBox.dir; - // result = hasConditions; - // iStartZone.Clean(); - // break; - // } - // } - - // - iStartZone.Clean(); - } - - // - if (result && - IsValidIndex(selectedIndex)) - { - // - ArrayRemove( - startZones, - selectedIndex, - 1 // - ); - } - } - - // - // Detect Conditions Based On Working Zones ... - if (!result) - { - // - // Detect Result Based On WorkingZone ... - } - - // - if (!result) - { - // - _point = 0; - _pivot = 0; - conditionsDir = X_DIRECTION_NONE; - - // - return result; - } - - // - return result; - } - - // -}; - -// -bool X121SMCXWZCheckPriceInside( - XOHCL &zBar, - XOHCL &cBar, - double upper, - double lower // -) -{ - // - bool result = false; - - // - result = zBar.IsValid() && - cBar.IsValid() && - upper > 0 && - lower > 0 && - upper > lower && - zBar.time > cBar.time; - if (!result) - { - return result; - } - - // - result = - // - zBar.high < upper && - cBar.high < upper && - // - zBar.low > lower && - cBar.low > lower - // - ; - - // - return result; -} - -// \ No newline at end of file diff --git a/Documents/BKP/xsupdem/plib.tmp.codes.mq5 b/Documents/BKP/xsupdem/plib.tmp.codes.mq5 deleted file mode 100644 index f99ce31e..00000000 --- a/Documents/BKP/xsupdem/plib.tmp.codes.mq5 +++ /dev/null @@ -1,2732 +0,0 @@ - -/** - * Sort Order Blocks / Fair Value Gaps based on Place and Remove unused ... - */ -template -void OrderedSortZones( - T *youngest, - T *&items[] // -) -{ - // - int count = ArraySize(items); - if (youngest == NULL || - !youngest.IsValid() || - !IsValidSize(count)) - { - return; - } - - // - ENUM_X_DIRECTION dir = youngest.GetDirection(); - bool isBullish = IsBullish(dir); - - // - T *tmp[]; - T *lastOB = youngest; - while (IsValidSize(count)) - { - // - // Detect Youngest of Collection ... - int idx = GetYoungest(items); - T *iChild = items[idx]; - ArrayRemove( - items, - idx, - 1 // - ); - count = ArraySize(items); - - // - // Check Direction Must be Same ... - ENUM_X_DIRECTION iDir = iChild.GetDirection(); - bool isSameDir = dir == iDir; - if (!isSameDir) - { - continue; - } - - // - // Check Creation time Sequence ... - bool isFromPassed = lastOB.From() > iChild.From(); - if (!isFromPassed) - { - continue; - } - - // - // Check Order Block Place ... - bool isPlacePassed = - isBullish - ? IsBelow( - iChild, - lastOB, - true // Ignore Inside ... - ) - : IsAbove( - iOB, - lastOB, - true // Ignore Inside ... - ); - if (!isPlacePassed) - { - continue; - } - - // - // Update Last OB ... - lastOB = iChild; - Add( - iChild, - tmp // - ); - - // - } - - // - // Update Ordered Sorted Order Blocks ... - count = ArraySize(tmp); - if (IsValidSize(count)) - { - // - Copy( - tmp, - orderBlocks // - ); - } -} -template -void OrderedSortZones( - T *&items[] // -) -{ - // - int count = ArraySize(items); - if (!IsValidSize(count)) - { - return; - } - - // - // Detect Youngest ... - int youngestIDX = GetYoungest( - items // - ); - bool hasYoungest = IsValidSize(youngestIDX); - if (!hasYoungest) - { - return; - } - - // - T *youngest = items[youngestIDX]; - ArrayRemove( - items, - youngestIDX, - 1 // - ); - count = ArraySize(items); - if (!IsValidSize(count)) - { - // - Add( - youngest, - items // - ); - - // - return; - } - - // - if (youngest == NULL || - !youngest.IsValid()) - { - return; - } - - // - ENUM_X_DIRECTION dir = youngest.GetDirection(); - bool isBullish = IsBullish(dir); - - // - T *tmp[]; - T *lastOB = youngest; - while (IsValidSize(count)) - { - // - // Detect Youngest of Collection ... - int idx = GetYoungest(items); - T *iChild = items[idx]; - ArrayRemove( - items, - idx, - 1 // - ); - count = ArraySize(items); - - // - // Check Direction Must be Same ... - ENUM_X_DIRECTION iDir = iChild.GetDirection(); - bool isSameDir = dir == iDir; - if (!isSameDir) - { - continue; - } - - // - // Check Creation time Sequence ... - bool isFromPassed = lastOB.From() > iChild.From(); - if (!isFromPassed) - { - continue; - } - - // - // Check Order Block Place ... - bool isPlacePassed = - isBullish - ? IsBelow( - iChild, - lastOB, - true // Ignore Inside ... - ) - : IsAbove( - iChild, - lastOB, - true // Ignore Inside ... - ); - if (!isPlacePassed) - { - continue; - } - - // - // Update Last OB ... - lastOB = iChild; - Add( - iChild, - tmp // - ); - - // - } - - // - // Update Ordered Sorted Order Blocks ... - count = ArraySize(tmp); - if (IsValidSize(count)) - { - // - Copy( - tmp, - items // - ); - } -} - -void OrderedSortBoxes( - XBoxZone &items[] // -) -{ - // - int count = ArraySize(items); - if (!IsValidSize(count)) - { - return; - } - - // - // Detect Youngest ... - int youngestIDX = GetYoungest( - items // - ); - bool hasYoungest = IsValidSize(youngestIDX); - if (!hasYoungest) - { - return; - } - - // - XBoxZone youngest = items[youngestIDX]; - ArrayRemove( - items, - youngestIDX, - 1 // - ); - count = ArraySize(items); - if (!IsValidSize(count)) - { - // - AddRef( - youngest, - items // - ); - - // - return; - } - - // - if (!youngest.IsValid()) - { - return; - } - - // - ENUM_X_DIRECTION dir = youngest.dir; - bool isBullish = IsBullish(dir); - - // - XBoxZone tmp[]; - XBoxZone last = youngest; - while (IsValidSize(count)) - { - // - // Detect Youngest of Collection ... - int idx = GetYoungest(items); - XBoxZone iChild = items[idx]; - ArrayRemove( - items, - idx, - 1 // - ); - count = ArraySize(items); - - // - // Check Direction Must be Same ... - ENUM_X_DIRECTION iDir = iChild.dir; - bool isSameDir = dir == iDir; - if (!isSameDir) - { - continue; - } - - // - // Check Creation time Sequence ... - bool isFromPassed = last.from > iChild.from; - if (!isFromPassed) - { - continue; - } - - // - // Check Order Block Place ... - bool isPlacePassed = - isBullish - ? IsBoxBelow( - iChild, - last, - true // Ignore Inside ... - ) - : IsBoxAbove( - iChild, - last, - true // Ignore Inside ... - ); - if (!isPlacePassed) - { - continue; - } - - // - // Update Last OB ... - last = iChild; - AddRef( - iChild, - tmp // - ); - - // - } - - // - // Update Ordered Sorted Order Blocks ... - count = ArraySize(tmp); - if (IsValidSize(count)) - { - // - Copy( - tmp, - items // - ); - } -} - -/** - * Extract Order Flows Swing Points ... - * - * @param type: ENUM_X_SWING_TYPE member ... - * @param swings: double Collection ... - * - * @return ( int ) - */ -int ExtractSwingPoints( - ENUM_X_SWING_TYPE type, - XCOrderBlock *&orderBlocks[], - XSwingPoint &swings[] // -) -{ - // - int result = 0; - - // - Clean(swings); - - // - int count = ArraySize(orderBlocks); - - // - if (type == X_NO_SWING || - !IsValidSize(count)) - { - return result; - } - - // - bool lookingForSwingLows = type == X_SWING_LOW; - - // - for (int i = 0; i < count; i++) - { - // - XCOrderBlock *iOB = orderBlocks[i]; - - // - string iSymbol = iOB.GetSymbol(); - ENUM_TIMEFRAMES iPeriod = iOB.GetPeriod(); - - // - int fromIndex = iBarShift( - iSymbol, - iPeriod, - iOB.From() // - ); - - // - fromIndex++; - - // - double iValue = 0; - datetime iVTime = NULL; - if (lookingForSwingLows) - { - // - int idx = iLowest( - iSymbol, - iPeriod, - MODE_LOW, - fromIndex // - ); - - // - if (IsValidIndex(idx)) - { - // - iValue = iLow( - iSymbol, - iPeriod, - idx // - ); - - // - iVTime = iTime( - iSymbol, - iPeriod, - idx // - ); - } - } - else - { - // - int idx = iHighest( - iSymbol, - iPeriod, - MODE_HIGH, - fromIndex // - ); - - // - if (IsValidIndex(idx)) - { - // - iValue = iHigh( - iSymbol, - iPeriod, - idx // - ); - - // - iVTime = iTime( - iSymbol, - iPeriod, - idx // - ); - } - } - - // - if (iValue > 0) - { - // - XSwingPoint iSwingP; - - // - iSwingP.type = type; - iSwingP.time = iVTime; - iSwingP.swing = iValue; - iSwingP.symbol = iSymbol; - iSwingP.period = iPeriod; - - // - if (iSwingP.IsValid()) - { - // - AddRef( - iSwingP, - swings // - ); - } - - // - iSwingP.Clean(); - } - } - - // - result = ArraySize(swings); - - // - return result; -} - - -// -bool IsRejectBox( - ENUM_X_DIRECTION &forDir, - XOHCL &bar, - XBoxZone &box, - XPOIState &state, - XOHCL &swingBar, - XOHCL &rejectBar, - XOHCL &breakerBar, - XOHCL &momentumBar, - bool forceSwingRejection = true // -) -{ - // - bool result = false; - - // - swingBar.Clean(); - rejectBar.Clean(); - breakerBar.Clean(); - momentumBar.Clean(); - - // - result = bar.IsValid() && - box.IsValid() && - state.IsValid() && - state.HasChild() && - HasDirection(forDir); - if (!result) - { - return result; - } - - // - bool isBullish = IsBullish(forDir); - - // - double appliedPrice = - isBullish - ? box.upper - : box.lower; - - // - // Fetch Required Bars ... - - // - XOHCL cBar; - result = bar.GetPreviousBar(cBar); - if (!result) - { - return result; - } - - // - XOHCL pBar; - result = cBar.GetPreviousBar(pBar); - if (!result) - { - return result; - } - - // - XOHCL ppBar; - result = pBar.GetPreviousBar(ppBar); - if (!result) - { - return result; - } - - // - // Check Directional Swing Type ... - ENUM_X_SWING_TYPE swingType = - isBullish - ? X_SWING_LOW - : X_SWING_HIGH; - - // - bool isSwingLow = - // - pBar.low < ppBar.low && - pBar.low < cBar.low && - bar.open > pBar.low && - // - appliedPrice > pBar.low && - appliedPrice < pBar.GetDown() - // - ; - - // - bool isSwingHigh = - // - pBar.high > ppBar.high && - pBar.high > cBar.high && - bar.open < pBar.high && - // - appliedPrice < pBar.high && - appliedPrice > pBar.GetUp() - // - ; - - // - // Force Rejected By Swing ... - if (forceSwingRejection) - { - // - result = swingType == X_SWING_HIGH - ? isSwingHigh - : swingType == X_SWING_LOW - ? isSwingLow - : false; - if (!result) - { - return result; - } - } - - // - bool hasValidSwing = - isBullish - ? isSwingLow - : isSwingHigh; - if (hasValidSwing) - { - swingBar = pBar; - } - - // - bool isCBarBreaked = IsBarBreak( - appliedPrice, - forDir, - cBar // - ); - if (isCBarBreaked) - { - breakerBar = cBar; - } - bool isPBarBreaked = IsBarBreak( - appliedPrice, - forDir, - pBar // - ); - if (isPBarBreaked) - { - breakerBar = pBar; - } - bool isPPBarBreaked = IsBarBreak( - appliedPrice, - forDir, - ppBar // - ); - if (isPPBarBreaked) - { - breakerBar = ppBar; - } - bool isBoxBreaked = isCBarBreaked || - isPBarBreaked || - isPPBarBreaked; - - // - bool isCBarRejected = IsBarReject( - appliedPrice, - forDir, - cBar // - ); - if (isCBarRejected) - { - rejectBar = cBar; - } - bool isPBarRejected = IsBarReject( - appliedPrice, - forDir, - pBar // - ); - if (isPBarRejected) - { - rejectBar = pBar; - } - bool isPPBarRejected = IsBarReject( - appliedPrice, - forDir, - ppBar // - ); - if (isPPBarRejected) - { - rejectBar = ppBar; - } - bool isBoxRejected = isCBarRejected || - isPBarRejected || - isPPBarRejected; - - // - int count = 0; - - // - bool hasRejectionBar = false; - if (isBullish) - { - // - count = state.CountBullishRejectionBars(); - for (int i = 0; i < count; i++) - { - // - XCRejectionBar *iZone = state.bullishRejectionBars[i]; - - // - XOHCL iBar; - bool isFilled = iZone.FillBar(iBar); - if (!isFilled) - { - continue; - } - - // - int iBarIndex = iBar.Index(); - - // - hasRejectionBar = - // - (iBarIndex == cBar.Index() || - iBarIndex == pBar.Index()) - // - ; - if (hasRejectionBar) - { - // - if (!rejectBar.IsValid()) - { - rejectBar = iBar; - } - - // - break; - } - } - } - else - { - // - count = state.CountBearishRejectionBars(); - for (int i = 0; i < count; i++) - { - // - XCRejectionBar *iZone = state.bearishRejectionBars[i]; - - // - XOHCL iBar; - bool isFilled = iZone.FillBar(iBar); - if (!isFilled) - { - continue; - } - - // - int iBarIndex = iBar.Index(); - - // - hasRejectionBar = - // - (iBarIndex == cBar.Index() || - iBarIndex == pBar.Index()) - // - ; - if (hasRejectionBar) - { - // - if (!rejectBar.IsValid()) - { - rejectBar = iBar; - } - - // - break; - } - } - } - - // - bool hasMomentumBar = false; - if (isBullish) - { - // - count = state.CountBullishMomentumBars(); - for (int i = 0; i < count; i++) - { - // - XCMomentumBar *iZone = state.bullishMomentumBars[i]; - - // - XOHCL iBar; - bool isFilled = iZone.FillBar(iBar); - if (!isFilled) - { - continue; - } - - // - int iBarIndex = iBar.Index(); - - // - hasMomentumBar = - // - (iBarIndex == cBar.Index() || - iBarIndex == pBar.Index()) - // - ; - if (hasMomentumBar) - { - // - if (!momentumBar.IsValid()) - { - momentumBar = iBar; - } - - // - break; - } - } - } - else - { - // - count = state.CountBearishMomentumBars(); - for (int i = 0; i < count; i++) - { - // - XCMomentumBar *iZone = state.bearishMomentumBars[i]; - - // - XOHCL iBar; - bool isFilled = iZone.FillBar(iBar); - if (!isFilled) - { - continue; - } - - // - int iBarIndex = iBar.Index(); - - // - hasMomentumBar = - // - (iBarIndex == cBar.Index() || - iBarIndex == pBar.Index()) - // - ; - if (hasMomentumBar) - { - // - if (!momentumBar.IsValid()) - { - momentumBar = iBar; - } - - // - break; - } - } - } - - // - bool hasSwing = false; - if (isBullish) - { - // - count = state.CountSwingLows(); - for (int i = 0; i < count; i++) - { - // - XCSwing *iSwing = state.swingLows[i]; - - // - XOHCL iBar; - bool isFilled = iSwing.FillBar(iBar); - if (!isFilled) - { - continue; - } - - // - int iBarIndex = iBar.Index(); - - // - hasSwing = - // - (iBarIndex == cBar.Index() || - iBarIndex == pBar.Index()) - // - ; - if (hasSwing) - { - // - if (!swingBar.IsValid()) - { - swingBar = iBar; - } - - // - break; - } - } - } - else - { - // - count = state.CountSwingHighs(); - for (int i = 0; i < count; i++) - { - // - XCSwing *iSwing = state.swingHighs[i]; - - // - XOHCL iBar; - bool isFilled = iSwing.FillBar(iBar); - if (!isFilled) - { - continue; - } - - // - int iBarIndex = iBar.Index(); - - // - hasSwing = - // - (iBarIndex == cBar.Index() || - iBarIndex == pBar.Index()) - // - ; - if (hasSwing) - { - // - if (!swingBar.IsValid()) - { - swingBar = iBar; - } - - // - break; - } - } - } - - // - bool hasRequiredValidations = - // - (hasRejectionBar || - hasMomentumBar) - // - || - // - (hasRejectionBar || - hasSwing) - // - || - // - (hasMomentumBar || - hasSwing) - // - ; - - // - result = - // - (isBoxBreaked && - (hasRequiredValidations || - hasValidSwing)) - // - || - // - (isBoxRejected && - (hasRequiredValidations || - hasValidSwing)) - // - ; - - // - return result; -} - - -template -void UpdateTo( - T *&source[], - datetime time = NULL // -) -{ - // - if (!IsValid(time)) - { - time = TimeCurrent(); - } - - // - int count = ArraySize(source); - if (!IsValidSize(count)) - { - return; - } - - // - for (int i = 0; i < count; i++) - { - source[i].To(time); - } -} - - -template -bool IsReject( - ENUM_X_DIRECTION forDir, - XOHCL &bar, - T *source, - XPOIState &state, - XOHCL &swingBar, - XOHCL &rejectBar, - XOHCL &breakerBar, - XOHCL &momentumBar, - bool forceSwingRejection = true // -) -{ - // - bool result = false; - - // - XBoxZone sourceBox; - result = ToBox( - sourceBox, - source // - ); - if (!result) - { - return result; - } - - // - result = IsRejectBox( - forDir, - bar, - sourceBox, - state, - swingBar, - rejectBar, - breakerBar, - momentumBar, - forceSwingRejection // - ); - - // - return result; -} - - - // - bool HasConditions( - ENUM_X_DIRECTION &conditionsDir, - XPOIState &state, - int barIndex = 0, - ENUM_TIMEFRAMES forPeriod = NULL // - ) - { - // - bool result = false; - - // - conditionsDir = X_DIRECTION_NONE; - - // - if (barIndex < 0) - { - barIndex = 0; - } - - // - if (forPeriod == NULL) - { - forPeriod = period; - } - - // - result = - // - IsValid(symbol) && - IsValid(period) && - state.IsValid() && - HasWorkingZone() && - state.HasChild() - // - ; - if (!result) - { - return result; - } - - // - result = false; - - // - // Detect Conditions Based On Start Zones ... - bool hasStartZones = HasStartZones(); - if (hasStartZones) - { - // - int count = CountStartZones(); - for (int i = 0; i < count; i++) - { - // - X121SMCXWZZone iStartZone = startZones[i]; - - // - XBoxZone insideBox; - bool isPriceInside = iStartZone.IsPriceInside( - insideBox, - barIndex, - forPeriod // - ); - if (!isPriceInside) - { - // - iStartZone.Clean(); - continue; - } - - // - Print("PriceInside ..."); - - // - bool hasConditions = iStartZone.HasCondition( - insideBox, - state, - barIndex, - forPeriod // - ); - if (!hasConditions) - { - // - iStartZone.Clean(); - continue; - } - - // - iStartZone.Clean(); - } - } - - // - // Detect Conditions Based On Working Zones ... - if (!result) - { - // - // Detect Result Based On WorkingZone ... - } - - // - return result; - } - - - // - bool HasCondition( - XBoxZone &box, - XPOIState &state, - int barIndex = 0, - ENUM_TIMEFRAMES forPeriod = NULL // - ) - { - // - bool result = false; - - // - if (barIndex < 0) - { - barIndex = 0; - } - - // - swingBar.Clean(); - breakerBar.Clean(); - appliedBox.Clean(); - momentumBar.Clean(); - rejectionBar.Clean(); - - // - result = IsValid() && - box.IsValid() && - HasDirection() && - state.IsValid() && - state.HasChild(); - if (!result) - { - // - swingBar.Clean(); - breakerBar.Clean(); - appliedBox.Clean(); - momentumBar.Clean(); - rejectionBar.Clean(); - - // - return result; - } - - // - string symbol = box.symbol; - if (!IsValid(forPeriod)) - { - forPeriod = box.period; - } - datetime cTime = iTime( - symbol, - forPeriod, - barIndex // - ); - - // - ENUM_X_DIRECTION forDir = box.dir; - bool isBullish = IsBullish(forDir); - - // - int supportsCount = 0; - bool hasSupports = false; - XCSupportZone *supports[]; - - // - int resistancesCount = 0; - bool hasResistances = false; - XCResistanceZone *resistances[]; - - // - XBoxZone supResBoxes[]; - int supresBoxesCount = 0; - bool hasSupResBoxes = false; - - // - int count = 0; - bool has = false; - - // - has = state.HasSupportZones(); - if (has) - { - // - count = state.CountSupportZones(); - for (int i = 0; i < count; i++) - { - // - XCSupportZone *iZone = state.supportZones[i]; - - // - iZone.To(cTime); - - // - XBoxZone iBox; - bool hasBox = ToBox( - iBox, - iZone // - ); - if (!hasBox) - { - // - iBox.Clean(); - continue; - } - - // - // Check From ... - bool isInside = IsBoxInside( - iBox, - box // - ); - if (!isInside) - { - // - iBox.Clean(); - continue; - } - - // - Add( - iZone, - supports // - ); - - // - AddRef( - iBox, - supResBoxes // - ); - - // - iBox.Clean(); - } - - // - supportsCount = ArraySize(supports); - hasSupports = IsValidSize(supportsCount); - - // - supresBoxesCount = ArraySize(supResBoxes); - hasSupResBoxes = IsValidSize(supresBoxesCount); - } - - // - has = state.HasResistanceZones(); - if (has) - { - // - count = state.CountResistanceZones(); - for (int i = 0; i < count; i++) - { - // - XCResistanceZone *iZone = state.resistanceZones[i]; - - // - iZone.To(cTime); - - // - XBoxZone iBox; - bool hasBox = ToBox( - iBox, - iZone // - ); - if (!hasBox) - { - // - iBox.Clean(); - continue; - } - - // - // Check From ... - bool isInside = IsBoxInside( - iBox, - box // - ); - if (!isInside) - { - // - iBox.Clean(); - continue; - } - - // - Add( - iZone, - resistances // - ); - - // - AddRef( - iBox, - supResBoxes // - ); - - // - iBox.Clean(); - } - - // - resistancesCount = ArraySize(resistances); - hasResistances = IsValidSize(resistancesCount); - - // - supresBoxesCount = ArraySize(supResBoxes); - hasSupResBoxes = IsValidSize(supresBoxesCount); - } - - // - result = hasSupResBoxes; - if (!result) - { - // - Clean(supports); - Clean(resistances); - Clean(supResBoxes); - - // - swingBar.Clean(); - breakerBar.Clean(); - appliedBox.Clean(); - momentumBar.Clean(); - rejectionBar.Clean(); - - // - return result; - } - - // // - // AddRef( - // box, - // supResBoxes // - // ); - - // - // Detect Bars ... - - // - XOHCL zBar; - result = zBar.Init( - symbol, - forPeriod, - barIndex // - ); - if (!result) - { - // - zBar.Clean(); - Clean(supports); - Clean(resistances); - Clean(supResBoxes); - - // - swingBar.Clean(); - breakerBar.Clean(); - appliedBox.Clean(); - momentumBar.Clean(); - rejectionBar.Clean(); - - // - return result; - } - - // - XOHCL cBar; - result = zBar.GetPreviousBar(cBar); - if (!result) - { - // - zBar.Clean(); - cBar.Clean(); - Clean(supports); - Clean(resistances); - Clean(supResBoxes); - - // - swingBar.Clean(); - breakerBar.Clean(); - appliedBox.Clean(); - momentumBar.Clean(); - rejectionBar.Clean(); - - // - return result; - } - - // - XOHCL pBar; - result = cBar.GetPreviousBar(pBar); - if (!result) - { - // - zBar.Clean(); - cBar.Clean(); - pBar.Clean(); - Clean(supports); - Clean(resistances); - Clean(supResBoxes); - - // - swingBar.Clean(); - breakerBar.Clean(); - appliedBox.Clean(); - momentumBar.Clean(); - rejectionBar.Clean(); - - // - return result; - } - - // - XOHCL ppBar; - result = pBar.GetPreviousBar(ppBar); - if (!result) - { - // - zBar.Clean(); - cBar.Clean(); - pBar.Clean(); - ppBar.Clean(); - Clean(supports); - Clean(resistances); - Clean(supResBoxes); - - // - swingBar.Clean(); - breakerBar.Clean(); - appliedBox.Clean(); - momentumBar.Clean(); - rejectionBar.Clean(); - - // - return result; - } - - // - // Check Conditions ... - - // - // Detect Start Senario ... - - // - double fiboPressureLevel = GetFiboLevelValue(X_FIBO_LEVEL_382); - - // - double fiboUpDown = GetFibonacciLevel( - pBar.high, - pBar.low, - X_FIBO_LEVEL_382, - X_DIRECTION_BEARISH // - ); - double fiboDownUp = GetFibonacciLevel( - pBar.high, - pBar.low, - X_FIBO_LEVEL_382, - X_DIRECTION_BULLISH // - ); - - // - bool hasFiboToUpPressure = - fiboDownUp > 0 && - fiboDownUp <= pBar.GetDown(); - bool hasFiboToDownPressure = - fiboUpDown > 0 && - fiboUpDown >= pBar.GetUp(); - - // - int selectedBoxIDX = -1; - for (int j = 0; j < supresBoxesCount; j++) - { - // - double appliedPrice = - isBullish - ? supResBoxes[j].lower - : supResBoxes[j].upper; - - // - // Check Swing Low ... - bool isSwingLow = - // - pBar.low < ppBar.low && - pBar.low < cBar.low && - zBar.open > pBar.low && - // - appliedPrice > pBar.low && - appliedPrice < pBar.GetDown() - // - ; - bool isPressuredSwingLow = - isSwingLow && - hasFiboToUpPressure; - bool isPressuredStrongSwingLow = - pBar.IsBullish() && - isPressuredSwingLow; - - // - bool isSwingHigh = - // - pBar.high > ppBar.high && - pBar.high > cBar.high && - zBar.open < pBar.high && - // - appliedPrice < pBar.high && - appliedPrice > pBar.GetUp() - // - ; - bool isPressuredSwingHigh = - isSwingHigh && - hasFiboToDownPressure; - bool isPressuredStrongSwingHigh = - pBar.IsBearish() && - isPressuredSwingHigh; - - // - bool hasValidSwing = - isBullish - ? isSwingLow - : isSwingHigh; - bool hasValidPressuredSwing = - isBullish - ? isPressuredSwingLow - : isPressuredSwingHigh; - bool hasValidPressuredStrongSwing = - isBullish - ? isPressuredStrongSwingLow - : isPressuredStrongSwingHigh; - if (hasValidSwing) - { - swingBar = pBar; - } - if (hasValidPressuredSwing) - { - swingBar = pBar; - } - if (hasValidPressuredStrongSwing) - { - swingBar = pBar; - } - - // - bool isCBarBreaked = IsBarBreak( - appliedPrice, - forDir, - cBar // - ); - if (isCBarBreaked) - { - breakerBar = cBar; - } - bool isPBarBreaked = IsBarBreak( - appliedPrice, - forDir, - pBar // - ); - if (!isCBarBreaked && isPBarBreaked) - { - breakerBar = pBar; - } - else - { - isPBarBreaked = false; - } - bool isPPBarBreaked = IsBarBreak( - appliedPrice, - forDir, - ppBar // - ); - if (!isCBarBreaked && - !isPBarBreaked && - isPPBarBreaked) - { - breakerBar = ppBar; - } - else - { - isPPBarBreaked = false; - } - bool isBoxBreaked = isCBarBreaked || - isPBarBreaked || - isPPBarBreaked; - - // - bool isCBarRejected = IsBarReject( - appliedPrice, - forDir, - cBar // - ); - if (isCBarRejected) - { - rejectionBar = cBar; - } - bool isPBarRejected = IsBarReject( - appliedPrice, - forDir, - pBar // - ); - if (!isCBarRejected && isPBarRejected) - { - rejectionBar = pBar; - } - else - { - isPBarRejected = false; - } - bool isPPBarRejected = IsBarReject( - appliedPrice, - forDir, - ppBar // - ); - if (!isCBarRejected && - !isPBarRejected && - isPPBarRejected) - { - rejectionBar = ppBar; - } - else - { - isPPBarRejected = false; - } - bool isBoxRejected = isCBarRejected || - isPBarRejected || - isPPBarRejected; - - // - bool hasRejectionBar = false; - if (isBullish) - { - // - count = state.CountBullishRejectionBars(); - for (int i = 0; i < count; i++) - { - // - XCRejectionBar *iZone = state.bullishRejectionBars[i]; - - // - XOHCL iBar; - bool isFilled = iZone.FillBar(iBar); - if (!isFilled) - { - continue; - } - - // - int iBarIndex = iBar.Index(); - - // - hasRejectionBar = - // - (iBarIndex == cBar.Index() || - iBarIndex == pBar.Index()) - // - ; - if (hasRejectionBar) - { - // - if (!rejectionBar.IsValid()) - { - rejectionBar = iBar; - } - - // - break; - } - } - } - else - { - // - count = state.CountBearishRejectionBars(); - for (int i = 0; i < count; i++) - { - // - XCRejectionBar *iZone = state.bearishRejectionBars[i]; - - // - XOHCL iBar; - bool isFilled = iZone.FillBar(iBar); - if (!isFilled) - { - continue; - } - - // - int iBarIndex = iBar.Index(); - - // - hasRejectionBar = - // - (iBarIndex == cBar.Index() || - iBarIndex == pBar.Index()) - // - ; - if (hasRejectionBar) - { - // - if (!rejectionBar.IsValid()) - { - rejectionBar = iBar; - } - - // - break; - } - } - } - - // - bool hasMomentumBar = false; - if (isBullish) - { - // - count = state.CountBullishMomentumBars(); - for (int i = 0; i < count; i++) - { - // - XCMomentumBar *iZone = state.bullishMomentumBars[i]; - - // - XOHCL iBar; - bool isFilled = iZone.FillBar(iBar); - if (!isFilled) - { - continue; - } - - // - int iBarIndex = iBar.Index(); - - // - hasMomentumBar = - // - (iBarIndex == cBar.Index() || - iBarIndex == pBar.Index()) - // - ; - if (hasMomentumBar) - { - // - if (!momentumBar.IsValid()) - { - momentumBar = iBar; - } - - // - break; - } - } - } - else - { - // - count = state.CountBearishMomentumBars(); - for (int i = 0; i < count; i++) - { - // - XCMomentumBar *iZone = state.bearishMomentumBars[i]; - - // - XOHCL iBar; - bool isFilled = iZone.FillBar(iBar); - if (!isFilled) - { - continue; - } - - // - int iBarIndex = iBar.Index(); - - // - hasMomentumBar = - // - (iBarIndex == cBar.Index() || - iBarIndex == pBar.Index()) - // - ; - if (hasMomentumBar) - { - // - if (!momentumBar.IsValid()) - { - momentumBar = iBar; - } - - // - break; - } - } - } - - // - bool hasSwing = false; - if (isBullish) - { - // - count = state.CountSwingLows(); - for (int i = 0; i < count; i++) - { - // - XCSwing *iSwing = state.swingLows[i]; - - // - XOHCL iBar; - bool isFilled = iSwing.FillBar(iBar); - if (!isFilled) - { - continue; - } - - // - int iBarIndex = iBar.Index(); - - // - hasSwing = - // - (iBarIndex == cBar.Index() || - iBarIndex == pBar.Index()) - // - ; - if (hasSwing) - { - // - if (!swingBar.IsValid()) - { - swingBar = iBar; - } - - // - break; - } - } - } - else - { - // - count = state.CountSwingHighs(); - for (int i = 0; i < count; i++) - { - // - XCSwing *iSwing = state.swingHighs[i]; - - // - XOHCL iBar; - bool isFilled = iSwing.FillBar(iBar); - if (!isFilled) - { - continue; - } - - // - int iBarIndex = iBar.Index(); - - // - hasSwing = - // - (iBarIndex == cBar.Index() || - iBarIndex == pBar.Index()) - // - ; - if (hasSwing) - { - // - if (!swingBar.IsValid()) - { - swingBar = iBar; - } - - // - break; - } - } - } - - // - bool hasRequiredValidations = - // - (hasRejectionBar || - hasMomentumBar) - // - || - // - (hasRejectionBar || - hasSwing) - // - || - // - (hasMomentumBar || - hasSwing) - // - ; - - // - result = - // - (isBoxBreaked && - (hasRequiredValidations || - hasValidPressuredSwing)) - // - || - // - (isBoxRejected && - (hasRequiredValidations || - hasValidPressuredSwing)) - // - ; - if (result) - { - // - selectedBoxIDX = j; - break; - } - } - - // - result = - result && - (isBullish - ? zBar.open >= box.upper - : zBar.open <= box.lower) && - IsValidIndex(selectedBoxIDX); - if (result) - { - appliedBox = supResBoxes[selectedBoxIDX]; - } - - // - zBar.Clean(); - cBar.Clean(); - pBar.Clean(); - ppBar.Clean(); - Clean(supports); - Clean(resistances); - Clean(supResBoxes); - - // - return result; - } - - - - // - ulong chartID = visionCycleHelper.mPOIDrawer.ChartIdentification(); - int subWindow = visionCycleHelper.mPOIDrawer.SubWindowIdentification(); - - // - if (pivot > 0) - { - // - string name = "Pivot_" + symbol + ToString(period) + ToString(pivot) + "_"; - CChartObjectHLine *iObj; - iObj = new CChartObjectHLine(); - bool isCreated = iObj.Create( - chartID, - name, - subWindow, - pivot // - ); - if (isCreated) - { - // - iObj.Color(clrLime); - mObjects.Add(iObj); - } - } - - // - if (point > 0) - { - // - string name = "Point_" + symbol + ToString(period) + ToString(pivot) + "_"; - CChartObjectHLine *iObj; - iObj = new CChartObjectHLine(); - bool isCreated = iObj.Create( - chartID, - name, - subWindow, - point // - ); - if (isCreated) - { - // - iObj.Color(clrLime); - mObjects.Add(iObj); - } - } - - - - // - RemoveDraws(); - - // - if (hasLastBullishConsolidationZone) - { - // - XCConsolidationZoneObject *iObj; - bool isCreated = visionCycleHelper - .mPOIDrawer - .CreateConsolidationZone( - lastBullishConsolidationZone, - iObj // - ); - if (isCreated) - { - mObjects.Add(iObj); - } - } - - // - if (hasLastBearishConsolidationZone) - { - // - XCConsolidationZoneObject *iObj; - bool isCreated = visionCycleHelper - .mPOIDrawer - .CreateConsolidationZone( - lastBearishConsolidationZone, - iObj // - ); - if (isCreated) - { - mObjects.Add(iObj); - } - } - - // - if (hasPrevBullishConsolidationZone) - { - // - XCConsolidationZoneObject *iObj; - bool isCreated = visionCycleHelper - .mPOIDrawer - .CreateConsolidationZone( - prevBullishConsolidationZone, - iObj // - ); - if (isCreated) - { - mObjects.Add(iObj); - } - } - - // - if (hasPrevBearishConsolidationZone) - { - // - XCConsolidationZoneObject *iObj; - bool isCreated = visionCycleHelper - .mPOIDrawer - .CreateConsolidationZone( - prevBearishConsolidationZone, - iObj // - ); - if (isCreated) - { - mObjects.Add(iObj); - } - } - -////////////////////////////////////////////////////////////////////////////////////////////// - - // - XPOIState state; - mXWZPOIDetector.GetState(state); - - // - ENUM_X_DIRECTION trend = - IsValid(lastBullishTrend) && - lastBullishTrend > lastBearishTrend - ? X_DIRECTION_BULLISH - : IsValid(lastBearishTrend) && - lastBearishTrend > lastBullishTrend - ? X_DIRECTION_BEARISH - : X_DIRECTION_NONE; - bool hasTrend = HasDirection(trend); - bool hasBullishTrend = hasTrend && - IsBullish(trend); - bool hasBearishTrend = hasTrend && - IsBearish(trend); - - // - // Order Block ... - has = hasBullishTrend && - state.HasBullishOrderBlocks(); - if (has) - { - // - XCOrderBlock *tmps[]; - count = ExtractInsideZones( - iBar, - state.bullishOrderBlocks, - tmps // - ); - has = IsValidSize(count); - if (has) - { - // - idx = GetLowest(tmps); - hasInsideOB = IsValidIndex(idx); - if (hasInsideOB) - { - insideOB = tmps[idx]; - } - } - - // - Clean(tmps); - } - has = hasBearishTrend && - state.HasBearishOrderBlocks(); - if (has) - { - // - XCOrderBlock *tmps[]; - count = ExtractInsideZones( - iBar, - state.bearishOrderBlocks, - tmps // - ); - has = IsValidSize(count); - if (has) - { - // - idx = GetHighest(tmps); - hasInsideOB = IsValidIndex(idx); - if (hasInsideOB) - { - insideOB = tmps[idx]; - } - } - - // - Clean(tmps); - } - - // - // Fair Value Gap ... - has = hasBullishTrend && - state.HasBullishFairValueGaps(); - if (has) - { - // - XCFVG *tmps[]; - count = ExtractInsideZones( - iBar, - state.bullishFairValueGaps, - tmps // - ); - has = IsValidSize(count); - if (has) - { - // - idx = GetLowest(tmps); - hasInsideFVG = IsValidIndex(idx); - if (hasInsideFVG) - { - insideFVG = tmps[idx]; - } - } - - // - Clean(tmps); - } - has = hasBearishTrend && - state.HasBearishFairValueGaps(); - if (has) - { - // - XCFVG *tmps[]; - count = ExtractInsideZones( - iBar, - state.bearishFairValueGaps, - tmps // - ); - has = IsValidSize(count); - if (has) - { - // - idx = GetHighest(tmps); - hasInsideFVG = IsValidIndex(idx); - if (hasInsideFVG) - { - insideFVG = tmps[idx]; - } - } - - // - Clean(tmps); - } - - // - // Supply Zone ... - has = hasBearishTrend && - state.HasSupplyZones(); - if (has) - { - // - XCSupplyZone *tmps[]; - count = ExtractInsideZones( - iBar, - state.supplyZones, - tmps // - ); - has = IsValidSize(count); - if (has) - { - // - idx = GetHighest(tmps); - hasInsideSupply = IsValidIndex(idx); - if (hasInsideSupply) - { - insideSupply = tmps[idx]; - } - } - - // - Clean(tmps); - } - - // - // Resistance Zone ... - has = hasBearishTrend && - state.HasResistanceZones(); - if (has) - { - // - XCResistanceZone *tmps[]; - count = ExtractInsideZones( - iBar, - state.resistanceZones, - tmps // - ); - has = IsValidSize(count); - if (has) - { - // - idx = GetHighest(tmps); - hasInsideResistance = IsValidIndex(idx); - if (hasInsideResistance) - { - insideResistnce = tmps[idx]; - } - } - - // - Clean(tmps); - } - - // - // Demand Zone ... - has = hasBullishTrend && - state.HasDemandZones(); - if (has) - { - // - XCDemandZone *tmps[]; - count = ExtractInsideZones( - iBar, - state.demandZones, - tmps // - ); - has = IsValidSize(count); - if (has) - { - // - idx = GetLowest(tmps); - hasInsideDemand = IsValidIndex(idx); - if (hasInsideDemand) - { - insideDemand = tmps[idx]; - } - } - - // - Clean(tmps); - } - - // - // Support Zone ... - has = hasBullishTrend && - state.HasSupportZones(); - if (has) - { - // - XCSupportZone *tmps[]; - count = ExtractInsideZones( - iBar, - state.supportZones, - tmps // - ); - has = IsValidSize(count); - if (has) - { - // - idx = GetLowest(tmps); - hasInsideSupport = IsValidIndex(idx); - if (hasInsideSupport) - { - insideSupport = tmps[idx]; - } - } - - // - Clean(tmps); - } - - - ////////////////////////////////////////////////////////// - - - // // - // // Calculate Rejection Values ... - - // // - // double fiboUpDown = GetFibonacciLevel( - // iBar.high, - // iBar.low, - // X_FIBO_LEVEL_382, - // X_DIRECTION_BEARISH // - // ); - // double fiboDownUp = GetFibonacciLevel( - // iBar.high, - // iBar.low, - // X_FIBO_LEVEL_382, - // X_DIRECTION_BULLISH // - // ); - - // // - // bool hasFiboToUpPressure = - // fiboDownUp > 0 && - // fiboDownUp <= iBar.GetDown(); - // bool hasFiboToDownPressure = - // fiboUpDown > 0 && - // fiboUpDown >= iBar.GetUp(); - - // // - // bool isLongReject = - // // - // iBar.low < iMa && - // iBar.high >= iMa && - // iBar.GetDown() >= iMa - // // - // ; - // bool isStrongLongReject = - // iBar.IsBullish() && - // isLongReject; - // bool isPressuredLongReject = - // isLongReject && - // hasFiboToUpPressure; - // bool isPressuredStrongLongReject = - // isStrongLongReject && - // isPressuredLongReject; - - // // - // bool isShortReject = - // // - // iBar.high > iMa && - // iBar.low <= iMa && - // iBar.GetUp() <= iMa - // // - // ; - // bool isStrongShortReject = - // iBar.IsBearish() && - // isShortReject; - // bool isPressuredShortReject = - // isShortReject && - // hasFiboToDownPressure; - // bool isPressuredStrongShortReject = - // isStrongShortReject && - // isPressuredShortReject; - - // // - // double iLongRejectValue = 0; - // double iShortRejectValue = 0; - - // // - // bool isAppliedLongReject = false; - // bool isAppliedShortReject = false; - // switch (rejectionType) - // { - // // - // case XWZ_REJECTION_BAR: - // isAppliedLongReject = isLongReject; - // isAppliedShortReject = isShortReject; - // break; - - // // - // case XWZ_REJECTION_STRONG_BAR: - // isAppliedLongReject = isStrongLongReject; - // isAppliedShortReject = isStrongShortReject; - // break; - - // // - // case XWZ_REJECTION_PRESSURED_BAR: - // isAppliedLongReject = isPressuredLongReject; - // isAppliedShortReject = isPressuredShortReject; - // break; - - // // - // case XWZ_REJECTION_STRONG_PRESSURED_BAR: - // isAppliedLongReject = isPressuredStrongLongReject; - // isAppliedShortReject = isPressuredStrongShortReject; - // break; - // } - - // // - // // Calculate Rejection Verification Values ... - - // // - // int iLLIDX = pBar - // .FindLowestIndex( - // rejectionVerificationLength, - // MODE_LOW // - // ); - // datetime iLLTime = iTime( - // _Symbol, - // _Period, - // iLLIDX // - // ); - // double iLL = iLow( - // _Symbol, - // _Period, - // iLLIDX // - // ); - - // // - // int iHHIDX = pBar - // .FindHighestIndex( - // rejectionVerificationLength, - // MODE_HIGH // - // ); - // datetime iHHTime = iTime( - // _Symbol, - // _Period, - // iHHIDX // - // ); - // double iHH = iHigh( - // _Symbol, - // _Period, - // iHHIDX // - // ); - - // // - // bool isLLBreaked = false; - // bool isHHBreaked = false; - // if (rejectionVerificationLength > 0) - // { - // // - // for (int i = bar_index + 1; i < bar_index + rejectionVerificationLength; i++) - // { - // // - // double iMaValue = maBuffer[i]; - - // // - // XOHCL iBar; - // bool isInited = iBar.Init( - // _Symbol, - // _Period, - // i // - // ); - // if (!isInited) - // { - // // - // iBar.Clean(); - // isLLBreaked = true; - // isHHBreaked = true; - // break; - // } - - // // - // if (!isLLBreaked) - // { - // isLLBreaked = iBar.low < iMaValue; - // } - - // // - // if (!isHHBreaked) - // { - // isHHBreaked = iBar.high > iMaValue; - // } - - // // - // if (isLLBreaked && - // isHHBreaked) - // { - // break; - // } - // } - // } - - // // - // // Validate Rejections ... - - // // - // // -[] Before Reject Long, price - // // must not touch Ma from Up for at least 3 Bar ... - // bool isValidAppliedLongReject = - // !isLLBreaked && - // isAppliedLongReject; - - // // - // // -[] Before Reject Short Price - // // must no touch Ma from down at least 3 Bar ... - // bool isValidAppliedShortReject = - // !isHHBreaked && - // isAppliedShortReject; - - // // - // if (isValidAppliedLongReject) - // { - // iLongRejectValue = iBar.low - points10; - // } - // else - // { - // iLongRejectValue = 0; - // } - - // // - // if (isValidAppliedShortReject) - // { - // iShortRejectValue = iBar.high + points10; - // } - // else - // { - // iShortRejectValue = 0; - // } - - // // - // // Draw Verification Box ... - // if (isValidAppliedLongReject || - // isValidAppliedShortReject) - // { - // // - // datetime time1 = iTime( - // _Symbol, - // _Period, - // iBar.Index() + rejectionVerificationLength // - // ); - // datetime time2 = iTime( - // _Symbol, - // _Period, - // iBar.Index() + 0 // - // ); - // string llName = ToString(iLLIDX) + "_" + - // ToString(iLL) + "_" + - // ToMD5(iLLTime); - // CChartObjectTrend *llTrend; - // llTrend = new CChartObjectTrend(); - // bool isCreated = llTrend.Create( - // 0, - // llName, - // 0, - // time1, - // iLL, - // time2, - // iLL // - // ); - // if (isCreated) - // { - // mXWZDrawnObjects.Add(llTrend); - // } - - // // - // string hhName = ToString(iHHIDX) + "_" + - // ToString(iHH) + "_" + - // ToMD5(iHHTime); - // CChartObjectTrend *hhTrend; - // hhTrend = new CChartObjectTrend(); - // isCreated = hhTrend.Create( - // 0, - // hhName, - // 0, - // time1, - // iHH, - // time2, - // iHH // - // ); - // if (isCreated) - // { - // mXWZDrawnObjects.Add(hhTrend); - // } - // } - - // // - // int idx = -1; - // int count = 0; - // bool has = false; - - // // - // ENUM_X_DIRECTION trend = - // IsValid(lastBullishTrend) && - // lastBullishTrend > lastBearishTrend - // ? X_DIRECTION_BULLISH - // : IsValid(lastBearishTrend) && - // lastBearishTrend > lastBullishTrend - // ? X_DIRECTION_BEARISH - // : X_DIRECTION_NONE; - // bool hasTrend = HasDirection(trend); - // bool hasBullishTrend = hasTrend && - // IsBullish(trend); - // bool hasBearishTrend = hasTrend && - // IsBearish(trend); - - // // - // // Filling Buffers ... - - // // - // longSLBuffer[bar_index] = iLongSL; - // shortSLBuffer[bar_index] = iShortSL; - - - /////////////////////////////////////////////////// - - // - // Draw ... - bool isBullish = signalZone.ob.IsBullish(); - bool isCreated = false; - XCBaseObject *iObj = NULL; - if (isBullish) - { - // - XCBullishOrderBlockObject *mObj; - isCreated = visionCycleHelper.mPOIDrawer - .CreateBullishOrderBlock( - signalZone.ob, - mObj // - ); - - // - if (isCreated) - { - // - mObj.ZoneWidth(2); - mObj.ZoneColor(clrGold); - mObj.ZoneStyle(STYLE_SOLID); - - // - iObj = (XCBaseObject *)mObj; - } - } - else - { - // - XCBearishOrderBlockObject *mObj; - isCreated = visionCycleHelper.mPOIDrawer - .CreateBearishOrderBlock( - signalZone.ob, - mObj // - ); - - // - if (isCreated) - { - // - mObj.ZoneWidth(2); - mObj.ZoneColor(clrGold); - mObj.ZoneStyle(STYLE_SOLID); - - // - iObj = (XCBaseObject *)mObj; - } - } - - // - if (isCreated) - { - mWorkingZoneObjects.Add(iObj); - } - - // - Print("Signal Zone ..."); diff --git a/Documents/BKP/xsupdem/tmp.signal.mq5 b/Documents/BKP/xsupdem/tmp.signal.mq5 deleted file mode 100644 index e67d9389..00000000 --- a/Documents/BKP/xsupdem/tmp.signal.mq5 +++ /dev/null @@ -1,1234 +0,0 @@ -///////////////////////////////////////////////////////////////////////////////////////////////////// - -else if (isPriceRejected) -{ - // - bool hasRejectedOB = rejectedOB != NULL; - bool hasRejectedFVG = rejectedFVG != NULL; - - // // - // if (hasRejectedOB) - // { - // // - // DrawX121SMCXSupDemOBSOrderBlock( - // rejectedOB, - // consolidationCycleHelper.mPOIDrawer // - // ); - // } - - // // - // if (hasRejectedFVG) - // { - // // - // DrawX121SMCXSupDemOBSFairValueGap( - // rejectedFVG, - // consolidationCycleHelper.mPOIDrawer // - // ); - // } - - // // - // if (!hasRejectedOB && - // !hasRejectedFVG) - // { - // // - // if (hasInsideSupDemZone) - // { - // // - // double min = 0; - // double max = 0; - // bool canSetMin = false; - // bool canSetMax = false; - - // // - // if (swingBar.IsValid()) - // { - // // - // canSetMin = - // min == 0 || min > swingBar.low; - // if (canSetMin) - // { - // min = swingBar.low; - // } - - // // - // canSetMax = - // max == 0 || max < swingBar.high; - // if (canSetMax) - // { - // max = swingBar.high; - // } - // } - - // // - // if (rejectBar.IsValid()) - // { - // // - // canSetMin = - // min == 0 || min > rejectBar.low; - // if (canSetMin) - // { - // min = rejectBar.low; - // } - - // // - // canSetMax = - // max == 0 || max < rejectBar.high; - // if (canSetMax) - // { - // max = rejectBar.high; - // } - // } - - // // - // if (breakerBar.IsValid()) - // { - // // - // canSetMin = - // min == 0 || min > breakerBar.low; - // if (canSetMin) - // { - // min = breakerBar.low; - // } - - // // - // canSetMax = - // max == 0 || max < breakerBar.high; - // if (canSetMax) - // { - // max = breakerBar.high; - // } - // } - - // // - // if (momentumBar.IsValid()) - // { - // // - // canSetMin = - // min == 0 || min > momentumBar.low; - // if (canSetMin) - // { - // min = momentumBar.low; - // } - - // // - // canSetMax = - // max == 0 || max < momentumBar.high; - // if (canSetMax) - // { - // max = momentumBar.high; - // } - // } - - // // - // upper = max; - // lower = min; - - // // - // if (hasInsideSupplyZone) - // { - // // - // isInsideZoneDirectionBullish = false; - // isInsideZoneDirectionBearish = true; - - // // - // lower = GetEntry( - // conditions.symbol, - // POSITION_TYPE_SELL // - // ); - // } - - // // - // if (hasInsideDemandZone) - // { - // // - // isInsideZoneDirectionBullish = true; - // isInsideZoneDirectionBearish = false; - - // // - // upper = GetEntry( - // conditions.symbol, - // POSITION_TYPE_BUY // - // ); - // } - // } - // } -} - -///////////////////////////////////////////////////////////////////////////////////////////////////// - - // - if (!hasInsideZone && - !hasRejectedZone && - hasInsideSupDemZone) - { - // - // Check Supply and Demand Zone Rejection ... - if (hasInsideSupplyZone) - { - // - isPriceRejected = IsReject( - X_DIRECTION_BEARISH, - decisionZBar, - insideSupplyZone, - decisionState, - swingBar, - rejectBar, - breakerBar, - momentumBar, - false // - ); - } - else if (hasInsideDemandZone) - { - // - isPriceRejected = IsReject( - X_DIRECTION_BULLISH, - decisionZBar, - insideDemandZone, - decisionState, - swingBar, - rejectBar, - breakerBar, - momentumBar, - false // - ); - } - } - -///////////////////////////////////////////////////////////////////////////////////////////////////// - - // // - // // Detect Overal Trend ... - // ENUM_X_DIRECTION trend; - // bool hasTrend = mConditions.DetectTrend( - // trend, - // zIndex // - // ); - // bool hasBullishTrend = - // // - // hasTrend && - // IsBullish(trend) - // // - // ; - // bool hasBearishTrend = - // // - // hasTrend && - // IsBearish(trend) - // // - // ; - // result = hasTrend; - // if (!result) - // { - // return result; - // } - - // // - // // Now We Have to Detect at least One OrderBlock with FVG ... - // // for Trend Approvement ... - // bool hasOrderBlock = mConditions.HasOrderBlock(); - // bool hasFairValueGap = mConditions.HasFairValueGap(); - // if (!hasOrderBlock && - // !hasFairValueGap) - // { - // // - // int count = 0; - // bool has = false; - - // // - // XCFVG *fvg = NULL; - // XCOrderBlock *ob = NULL; - - // // - // if (hasBullishTrend) - // { - // // - // has = consolidationState.HasBullishOrderBlocks(); - // count = consolidationState.CountBullishOrderBlocks(); - - // // - // if (has) - // { - // // - // // Check Order Block ... - // for (int i = 0; i < count; i++) - // { - // // - // XCOrderBlock *iOB = consolidationState.bullishOrderBlocks[i]; - - // // - // iOB.To(cTime); - - // // - // // Check From Passes ... - // bool isFromPassed = iOB.From() > mConditions.demandZone.From(); - // if (!isFromPassed) - // { - // continue; - // } - - // // - // // Must inside DemandZone ... - // bool isInsideDemand = IsInsideDiff( - // iOB, - // mConditions.demandZone // - // ); - // if (!isInsideDemand) - // { - // continue; - // } - - // // - // // Check Started ... - // XOHCL startedBar; - // ENUM_X_DIRECTION startedDir; - // bool isStarted = iOB.IsStarted( - // X_DIRECTION_BULLISH, - // startedBar, - // startedDir // - // ); - // if (!isStarted) - // { - // // - // startedBar.Clean(); - // continue; - // } - - // // - // // Converts to Box ... - // XBoxZone obBox; - // bool hasOBBox = ToBox( - // obBox, - // iOB // - // ); - // if (!hasOBBox) - // { - // // - // obBox.Clean(); - // startedBar.Clean(); - // continue; - // } - - // // - // // Check Zone Must not Used before ... - // bool isUsed = IsBoxUsed( - // obBox, - // startedBar.Index() - 1, - // zIndex // - // ); - // if (isUsed) - // { - // // - // obBox.Clean(); - // startedBar.Clean(); - // continue; - // } - - // // - // ob = iOB; - - // // - // obBox.Clean(); - // startedBar.Clean(); - - // // - // break; - // } - - // // - // // Detect Fair Value Gap ... - // if (ob != NULL && - // ob.IsValid()) - // { - // // - // has = analyseState.HasBullishFairValueGaps(); - // count = analyseState.CountBullishFairValueGaps(); - // if (has) - // { - // // - // // Check Fir Value Gap ... - // for (int i = 0; i < count; i++) - // { - // // - // XCFVG *iFVG = analyseState.bullishFairValueGaps[i]; - - // // - // iFVG.To(cTime); - - // // - // // Check From Passes ... - // bool isFromPassed = iFVG.From() > ob.From(); - // if (!isFromPassed) - // { - // continue; - // } - - // // - // // Check Started ... - // XOHCL startedBar; - // ENUM_X_DIRECTION startedDir; - // bool isStarted = iFVG.IsStarted( - // X_DIRECTION_BULLISH, - // startedBar, - // startedDir // - // ); - // if (!isStarted) - // { - // // - // startedBar.Clean(); - // continue; - // } - - // // - // // Converts to Box ... - // XBoxZone fvgBox; - // bool hasFVGBox = ToBox( - // fvgBox, - // iFVG // - // ); - // if (!hasFVGBox) - // { - // // - // fvgBox.Clean(); - // startedBar.Clean(); - // continue; - // } - - // // - // // Check Inside Order Block ... - // bool isInside = IsInsideDiff( - // iFVG, - // ob, - // true // Force Side Out ... - // ); - // if (!isInside) - // { - // continue; - // } - - // // - // fvg = iFVG; - - // // - // fvgBox.Clean(); - // startedBar.Clean(); - - // // - // break; - // } - // } - // else - // { - // // - // ob = NULL; - // } - // } - // } - // } - // else if (hasBearishTrend) - // { - // // - // has = consolidationState.HasBearishOrderBlocks(); - // count = consolidationState.CountBearishOrderBlocks(); - - // // - // if (has) - // { - // // - // // Check Order Block ... - // for (int i = 0; i < count; i++) - // { - // // - // XCOrderBlock *iOB = consolidationState.bearishOrderBlocks[i]; - - // // - // iOB.To(cTime); - - // // - // // Check From Passes ... - // bool isFromPassed = iOB.From() > mConditions.supplyZone.From(); - // if (!isFromPassed) - // { - // continue; - // } - - // // - // // Must inside DemandZone ... - // bool isInsideDemand = IsInsideDiff( - // iOB, - // mConditions.supplyZone // - // ); - // if (!isInsideDemand) - // { - // continue; - // } - - // // - // // Check Started ... - // XOHCL startedBar; - // ENUM_X_DIRECTION startedDir; - // bool isStarted = iOB.IsStarted( - // X_DIRECTION_BEARISH, - // startedBar, - // startedDir // - // ); - // if (!isStarted) - // { - // // - // startedBar.Clean(); - // continue; - // } - - // // - // // Converts to Box ... - // XBoxZone obBox; - // bool hasOBBox = ToBox( - // obBox, - // iOB // - // ); - // if (!hasOBBox) - // { - // // - // obBox.Clean(); - // startedBar.Clean(); - // continue; - // } - - // // - // // Check Zone Must not Used before ... - // bool isUsed = IsBoxUsed( - // obBox, - // startedBar.Index() - 1, - // zIndex // - // ); - // if (isUsed) - // { - // // - // obBox.Clean(); - // startedBar.Clean(); - // continue; - // } - - // // - // ob = iOB; - - // // - // obBox.Clean(); - // startedBar.Clean(); - - // // - // break; - // } - - // // - // // Detect Fair Value Gap ... - // if (ob != NULL && - // ob.IsValid()) - // { - // // - // has = analyseState.HasBearishFairValueGaps(); - // count = analyseState.CountBearishFairValueGaps(); - // if (has) - // { - // // - // // Check Fir Value Gap ... - // for (int i = 0; i < count; i++) - // { - // // - // XCFVG *iFVG = analyseState.bearishFairValueGaps[i]; - - // // - // iFVG.To(cTime); - - // // - // // Check From Passes ... - // bool isFromPassed = iFVG.From() > ob.From(); - // if (!isFromPassed) - // { - // continue; - // } - - // // - // // Check Started ... - // XOHCL startedBar; - // ENUM_X_DIRECTION startedDir; - // bool isStarted = iFVG.IsStarted( - // X_DIRECTION_BEARISH, - // startedBar, - // startedDir // - // ); - // if (!isStarted) - // { - // // - // startedBar.Clean(); - // continue; - // } - - // // - // // Converts to Box ... - // XBoxZone fvgBox; - // bool hasFVGBox = ToBox( - // fvgBox, - // iFVG // - // ); - // if (!hasFVGBox) - // { - // // - // fvgBox.Clean(); - // startedBar.Clean(); - // continue; - // } - - // // - // // Check Inside Order Block ... - // bool isInside = IsInsideDiff( - // iFVG, - // ob, - // true // Force Side Out ... - // ); - // if (!isInside) - // { - // continue; - // } - - // // - // fvg = iFVG; - - // // - // fvgBox.Clean(); - // startedBar.Clean(); - - // // - // break; - // } - // } - // else - // { - // // - // ob = NULL; - // } - // } - // } - // } - - // // - // if (ob != NULL && - // fvg != NULL) - // { - // // - // mConditions.orderBlock = ob; - // mConditions.fairValueGap = fvg; - // } - - // // - // hasOrderBlock = mConditions.HasOrderBlock(); - // hasFairValueGap = mConditions.HasFairValueGap(); - // } - - // // - // bool isTrendApproved = hasOrderBlock && - // hasFairValueGap; - // result = isTrendApproved; - // if (!result) - // { - // return result; - // } - - // // - // mConditions.UpdateTo(cTime); - - // // - // // TODO: Remove ... - // RemoveDraws(); - // DrawConditions( - // mConditions, - // visionCycleHelper.mPOIDrawer // - // ); - - // // - // // Now We have to Detect Start Zones ... - // int count = 0; - // bool has = false; - - // - - // // - // XBoxZone targetBoxes[]; - // if (hasBullishTrend) - // { - // // - // // - // } - // else if (hasBearishTrend) - // { - // // - // // Demand Zones ... - // has = consolidationState.HasDemandZones(); - // count = consolidationState.CountDemandZones(); - // XBoxZone demandBox; - - // // - // if (has) - // { - // // - // XCDemandZone *demands[]; - // for (int i = 0; i < count; i++) - // { - // // - // XCDemandZone *iZone = consolidationState.demandZones[i]; - - // // - // iZone.To(cTime); - - // // - // // Check Price ... - // bool isPricePassed = decisionCBar.low > iZone.Upper(); - // if (!isPricePassed) - // { - // continue; - // } - - // // - // XBoxZone iBox; - // bool hasBox = ToBox( - // iBox, - // iZone // - // ); - // if (!hasBox) - // { - // // - // iBox.Clean(); - // continue; - // } - - // // // - // // XCDemandZoneObject *iObj; - // // bool isCreated = visionCycleHelper - // // .mPOIDrawer - // // .CreateDemandZone( - // // iZone, - // // iObj // - // // ); - - // // - // Add( - // iZone, - // demands // - // ); - - // // - // // AddRef( - // // iBox, - // // targetBoxes // - // // ); - - // // - // iBox.Clean(); - // } - - // // - // count = ArraySize(demands); - // has = IsValidSize(count); - // if (has) - // { - // // - // int lowestIDX = GetLowest(demands); - // int highestIDX = GetHighest(demands); - // int youngestIDX = GetYoungest(demands); - // bool hasHighAndLow = - // IsValidIndex(lowestIDX) && - // IsValidIndex(highestIDX) && - // IsValidIndex(youngestIDX); - // if (hasHighAndLow) - // { - // // - // XBoxZone box; - - // // - // box.symbol = demands[highestIDX].GetSymbol(); - // box.period = demands[highestIDX].GetPeriod(); - - // // - // box.to = cTime; - // box.dir = X_DIRECTION_BULLISH; - // box.from = demands[youngestIDX].From(); - // box.type = demands[highestIDX].TypeAsString(); - - // // - // box.upper = demands[highestIDX].Upper(); - // box.lower = demands[lowestIDX].Lower(); - - // // - // bool isValid = box.IsValid(); - // if (isValid) - // { - // // // - // // XCBoxObject *iBoxObj; - // // bool isCreated = visionCycleHelper - // // .mPOIDrawer - // // .CreateBox( - // // box, - // // iBoxObj // - // // ); - - // // // - // // if (isCreated) - // // { - // // // - // // color boxColor = - // // IsBullish(box.dir) - // // ? clrAqua - // // : clrMagenta; - - // // // - // // ENUM_LINE_STYLE boxStyle = STYLE_DOT; - - // // // - // // iBoxObj.BoxColor(boxColor); - // // iBoxObj.BoxStyle(boxStyle); - - // // // - // // Print("BOX ..."); - - // // } - - // // - // demandBox = box; - // } - - // // - // box.Clean(); - // } - // } - // } - - // // - // // Bullish Order Blocks ... - // // has = consolidationState.HasBullishOrderBlocks(); - // // count = consolidationState.CountBullishOrderBlocks(); - - // // - // // if (has) - // // { - // // // - // // for (int i = 0; i < count; i++) - // // { - // // // - // // XCOrderBlock *iZone = consolidationState.bullishOrderBlocks[i]; - - // // // - // // iZone.To(cTime); - - // // // - // // // Check Price ... - // // bool isPricePassed = decisionCBar.low > iZone.Upper(); - // // if (!isPricePassed) - // // { - // // continue; - // // } - - // // // - // // XBoxZone iBox; - // // bool hasBox = ToBox( - // // iBox, - // // iZone // - // // ); - // // if (!hasBox) - // // { - // // // - // // iBox.Clean(); - // // continue; - // // } - - // // // - // // AddRef( - // // iBox, - // // targetBoxes // - // // ); - - // // // - // // iBox.Clean(); - // // } - // // } - - // // - // // Bullish Fair Value Gaps ... - // // has = consolidationState.HasBullishFairValueGaps(); - // // count = consolidationState.CountBullishFairValueGaps(); - - // // - // // if (has) - // // { - // // // - // // for (int i = 0; i < count; i++) - // // { - // // // - // // XCFVG *iZone = consolidationState.bullishFairValueGaps[i]; - - // // // - // // iZone.To(cTime); - - // // // - // // // Check Price ... - // // bool isPricePassed = decisionCBar.low > iZone.Upper(); - // // if (!isPricePassed) - // // { - // // continue; - // // } - - // // // - // // XBoxZone iBox; - // // bool hasBox = ToBox( - // // iBox, - // // iZone // - // // ); - // // if (!hasBox) - // // { - // // // - // // iBox.Clean(); - // // continue; - // // } - - // // // - // // AddRef( - // // iBox, - // // targetBoxes // - // // ); - - // // // - // // iBox.Clean(); - // // } - // // } - // } - - // // - // count = ArraySize(targetBoxes); - // has = IsValidSize(count); - // if (has) - // { - // // - // for (int i = 0; i < count; i++) - // { - // // - // XBoxZone iBox = targetBoxes[i]; - - // // - // XCBoxObject *iBoxObj; - // bool isCreated = visionCycleHelper - // .mPOIDrawer - // .CreateBox( - // iBox, - // iBoxObj // - // ); - - // // - // iBox.Clean(); - // } - // } - -///////////////////////////////////////////////////////////////////////////////////////////////////// - - // - // When FVg is Worked ... - else - { - // - XCFVG *fvgs[]; - if (isBullish) - { - // - Copy( - analyseState.bullishFairValueGaps, - fvgs // - ); - } - else - { - // - Copy( - analyseState.bearishFairValueGaps, - fvgs // - ); - } - - // - // int count = ArraySize(fvgs); - // bool has = IsValidSize(count); - // if (has) - // { - // // - // for (int i = 0; i < count; i++) - // { - // // - // XCBaseObject *iObj; - // bool isCreate = visionCycleHelper - // .mPOIDrawer - // .CreateFairValueGap( - // fvgs[i], - // iObj // - // ); - // } - // } - - // - // Extract UnActivated FVGs ... - int fvgsCount = FilterZones( - // - fvgs, - // - trend, - NULL, // For Period ... - workerBar.time, - // - // Start ... - XZONE_STATE_IGNORED, - true, // Force Body Out ... - // - // Activation ... - XZONE_STATE_FAILED, - false, // Force Body Out ... - // - // Breaktion ... - XZONE_STATE_IGNORED, - false, // Force Body Out ... - // - // Works ... - XZONE_STATE_IGNORED, - false, // Body Out ... - // - true, // Apply Sorting ... - true // Ignore Inside ... - ); - - // - bool has = IsValidSize(fvgsCount); - if (has) - { - // - int youngestIDX = GetYoungest(fvgs); - has = IsValidIndex(youngestIDX); - if (has) - { - // - workingZone - .orderFlow[youngestOBFVGIDX] - .fvg = fvgs[youngestIDX]; - - // - workingZone.UpdateTo(cTime); - - // - XCBaseObject *iFVGObj; - bool isCreated = visionCycleHelper - .mPOIDrawer.CreateFairValueGap( - fvgs[youngestIDX], - iFVGObj // - ); - if (isCreated) - { - Print(""); - } - } - } - } - -///////////////////////////////////////////////////////////////////////////////////////////////////// - - // - // TODO: Neews to Review ... - else if ( - isOBWorked && - isFVGWorked && - isOBActivated && - isFVGActivated && - fvgActivationBar.time >= obActivationBar.time && - fvgActivationBar.time <= obActivationBar.NextAt() && - obWorkerBar.time > fvgWorkerBar.time) - { - // - XOHCL iBar; - bool isBarPassed = iBar.Init( - symbol, - period, - zIndex // - ); - - // - if (isBarPassed) - { - // - bool isBarInsideFVG = - isBullish - ? ( - // - iBar.low < workingZone.orderFlow[youngestOBFVGIDX].fvg.Upper() && - iBar.high > workingZone.orderFlow[youngestOBFVGIDX].fvg.Lower() && - // - consolidationZBar.low < workingZone.orderFlow[youngestOBFVGIDX].fvg.Upper() - // - ) - : ( - // - iBar.high > workingZone.orderFlow[youngestOBFVGIDX].fvg.Lower() && - iBar.low < workingZone.orderFlow[youngestOBFVGIDX].fvg.Upper() && - // - consolidationZBar.high > workingZone.orderFlow[youngestOBFVGIDX].fvg.Lower() - // - ); - if (isBarInsideFVG) - { - Print(""); - } - } - - // - iBar.Clean(); - } - -///////////////////////////////////////////////////////////////////////////////////////////////////// - - - // - // TODO: - // Remove Drawn Objects ... - - // // - // if (hasNewOB) - // { - // // - // XCBaseObject *iObj; - // bool isCreated = visionCycleHelper - // .mPOIDrawer - // .CreateOrderBlock( - // newOB, - // iObj // - // ); - // Print("New OB"); - // } - - // // - // if (hasNewFVG) - // { - // // - // XCBaseObject *iObj; - // bool isCreated = visionCycleHelper - // .mPOIDrawer - // .CreateFairValueGap( - // newFVG, - // iObj // - // ); - // Print("New FVG"); - // } - - // // - // if (hasNewAnalyseOB) - // { - // // - // XCBaseObject *iObj; - // bool isCreated = analyseCycleHelper - // .mPOIDrawer - // .CreateOrderBlock( - // newAnalyseOB, - // iObj // - // ); - // Print("New OB"); - // } - - // // - // if (hasNewAnalyseFVG) - // { - // // - // XCBaseObject *iObj; - // bool isCreated = analyseCycleHelper - // .mPOIDrawer - // .CreateFairValueGap( - // newAnalyseFVG, - // iObj // - // ); - // Print("New FVG"); - // } - -///////////////////////////////////////////////////////////////////////////////////////////////////// - - // - XPoint llPoint; - llPoint.value = iLL; - llPoint.at = iLLTime; - - // - // - - // - XPoint hhPoint; - hhPoint.value = iHH; - hhPoint.at = iHHTime; - - // - XPoint llSwings[]; - AddRef( - llPoint, - llSwings // - ); - - // - llPoint.at = iHHTime; - AddRef( - llPoint, - llSwings // - ); - - // - // - - // - XPoint hhSwings[]; - - // - hhPoint.at = iLLTime; - AddRef( - hhPoint, - hhSwings // - ); - - // - hhPoint.at = iHHTime; - AddRef( - hhPoint, - hhSwings // - ); - - // - XCTrendObject *llTrendObj; - bool isCreated = mXWZPOIDrawer.CreateTrend( - llSwings, - llTrendObj // - ); - if (isCreated) - { - mXWZDrawnObjects.Add(llTrendObj); - } - - // - XCTrendObject *hhTrendObj; - isCreated = mXWZPOIDrawer.CreateTrend( - hhSwings, - hhTrendObj // - ); - if (isCreated) - { - mXWZDrawnObjects.Add(hhTrendObj); - } - - // - // - - // - Clean(llSwings); - Clean(hhSwings); - llPoint.Clean(); - hhPoint.Clean(); - -///////////////////////////////////////////////////////////////////////////////////////////////////// - - -///////////////////////////////////////////////////////////////////////////////////////////////////// - diff --git a/Documents/BKP/xsupdem/x-121.smc.expert.alert.class.mq5 b/Documents/BKP/xsupdem/x-121.smc.expert.alert.class.mq5 deleted file mode 100644 index 680898ad..00000000 --- a/Documents/BKP/xsupdem/x-121.smc.expert.alert.class.mq5 +++ /dev/null @@ -1,2458 +0,0 @@ -/////////////////////////////////////////////////////// -// -// SaherElm IT Center MQL5 Class Library -// -------------------------------------- -// Name: XC121SMCExpert -// Description: provides all based classes for use ... -// -// -// 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-expert.class.mq5" -#include "../../Helpers/x-saherelm.x121.xcc.helper.mq5" -#include "../../Helpers/x-saherelm.x121.xct.helper.mq5" -#include "../Classes/x-121.smc.x-tradehandler.class.mq5" -#include "../Libraries/x-121.smc.lib.mq5" -#include "../Strategy/x-121.smc.strategy.class.mq5" - -// -// Definitions ... -string XC121SMCExpertToken = "XC121SMCEA"; - -// -// Implementation ... - -class XC121SMCExpert : public XCBaseExpert -{ - // - public: - // - XCX121XCCHelper *xccHelper; - XCX121XCTHelper *xctHelper; - - // - // Signal Event Listener ... - TOnStopLoss OnPositionSLEventListener; - TOnTakeProfit OnPositionTPEventListener; - TOnPartialClose OnPositionPartialCloseEventListener; - TOnModify OnPositionModifiedEventListener; - TOnForceClose OnPositionForceCloseEventListener; - - // - TOnDealsChanged OnDealsChangedEventListener; - TOnOrdersChanged OnOrdersChangedEventListener; - TOnPositionsChanged OnPositionsChangedEventListener; - - // - TOnX121SMCSignal OnSignalEventListener; - - // - // Constructor(s) ... - XC121SMCExpert() - { - } - - // - // Deconstructor(s) ... - ~XC121SMCExpert() - { - Clean(mStrategies); - } - - // - // Getter(s) / Setter(s) ... - - // - // Signalling Props ... - - /** - * Get Allow Long Signals State ... - * - * @return ( bool ) - */ - bool AllowLong() - { - return mAllowLong; - } - - /** - * Set Allow Long Signals State ... - * - * @param value: Boolean ... - */ - void AllowLong(bool value) - { - // - mAllowLong = value; - ReConfigure(); - } - - /** - * Get Allow Short Signals State ... - * - * @return ( bool ) - */ - bool AllowShort() - { - return mAllowShort; - } - - /** - * Set Allow Short Signals State ... - * - * @param value: Boolean ... - */ - void AllowShort(bool value) - { - // - mAllowShort = value; - ReConfigure(); - } - - /** - * Get Max Allowed Long Signals ... - * 0 => Unlimited ... - * - * @return ( int ) - */ - int MaxAllowedLongs() - { - return mMaxAllowedLongs; - } - - /** - * Set Max Allowed Long Signals ... - * - * @param value: Integer ... - * 0 => Unlimited ... - */ - void MaxAllowedLongs(int value) - { - // - if (value < 0) - { - value = 0; - } - - // - mMaxAllowedLongs = value; - ReConfigure(); - } - - /** - * Get Max Allowed Short Signals ... - * 0 => Unlimited ... - * - * @return ( int ) - */ - int MaxAllowedShorts() - { - return mMaxAllowedShorts; - } - - /** - * Set Max Allowed Short Signals ... - * - * @param value: Integer ... - * 0 => Unlimited ... - */ - void MaxAllowedShorts(int value) - { - // - if (value < 0) - { - value = 0; - } - - // - mMaxAllowedShorts = value; - ReConfigure(); - } - - /** - * Get Use Max Allowed Signal Types Per Symbol State ... - * - * @return ( bool ) - */ - bool UseMaxAllowedSignalsPerSymbol() - { - return mUseMaxAllowedSignalsPerSymbol; - } - - /** - * Set Use Max Allowed Signal Types Per Symbol State ... - * - * @param value: Boolean ... - */ - void UseMaxAllowedSignalsPerSymbol(bool value) - { - // - mUseMaxAllowedSignalsPerSymbol = false; - ReConfigure(); - } - - /** - * Get Last Position Profit In Points for Accept new Signal ... - * 0 => Accept All ... - * - * @return ( double ) - */ - double LastPositionProfitForAcceptNextInPoint() - { - return mLastPositionProfitForAcceptNextInPoint; - } - - /** - * Set Last Position Profit In Points for Accept new Signal ... - * - * @param value: Double ... - * 0 => Accept All ... - */ - void LastPositionProfitForAcceptNextInPoint(double value) - { - // - if (value < 0) - { - value = 0; - } - - // - mLastPositionProfitForAcceptNextInPoint = value; - ReConfigure(); - } - - /** - * Get Delay between two Signals in Bars ... - * 0 => Accept All ... - * - * @return ( int ) - */ - int DelaysBetweenTwoSignalsInBar() - { - return mDelaysBetweenTwoSignalsInBar; - } - - /** - * Set Delay between two Signals in Bars ... - * - * @param value: Integer ... - * 0 => Accept All ... - */ - void DelaysBetweenTwoSignalsInBar(int value) - { - // - if (value < 0) - { - value = 0; - } - - // - mDelaysBetweenTwoSignalsInBar = value; - ReConfigure(); - } - - /** - * Get Max Allowed Spread for Signalling ... - * 0 => Accept All ... - * - * @return ( double ) - */ - double MaxAllowedSpread() - { - return mMaxAllowedSpread; - } - - /** - * Set Max Allowed Spread for Signalling ... - * - * @param value: Double ... - * 0 => Accept All ... - */ - void MaxAllowedSpread(double value) - { - // - if (value < 0) - { - value = 0; - } - - // - mMaxAllowedSpread = value; - ReConfigure(); - } - - /** - * Get Minimum Spread Verification for Signalling ... - * 0 => Ignore ... - * - * @return ( int ) - */ - int MinRequiredVerificationForSpreadPass() - { - return mMinRequiredVerificationForSpreadPass; - } - - /** - * Set Minimum Spread Verification for Signalling ... - * - * @param value: Integer ... - * 0 => Ignore ... - */ - void MinRequiredVerificationForSpreadPass(int value) - { - // - if (value < 0) - { - value = 0; - } - - // - mMinRequiredVerificationForSpreadPass = value; - ReConfigure(); - } - - // - // Trade ... - - /** - * Get Allow Open Trade On Signals State ... - * - * @return ( bool ) - */ - bool AllowTrade() - { - return mAllowTrade; - } - - /** - * Set Allow Open Trade On Signals State ... - * - * @param value: Boolean ... - */ - void AllowTrade(bool value) - { - mAllowTrade = value; - } - - /** - * Get Enable Trade on Signals on Time ... - * - * @return ( string ) - */ - string StartTradeAt() - { - return mStartTradeAt; - } - - /** - * Set Enable Trade on Signals on Time ... - * - * @param value: String ... - */ - void StartTradeAt(string value) - { - mStartTradeAt = value; - } - - /** - * Get Enable Trade on Signals on Time ... - * - * @return ( string ) - */ - string StopTradeAt() - { - return mStopTradeAt; - } - - /** - * Set Enable Trade on Signals on Time ... - * - * @param value: String ... - */ - void StopTradeAt(string value) - { - mStopTradeAt = value; - } - - /** - * Get Enable Close All Trades on Signals on Time ... - * - * @return ( string ) - */ - string CloseAllTradesAt() - { - return mCloseAllTradesAt; - } - - /** - * Set Enable Close All Trades on Signals on Time ... - * - * @param value: String ... - */ - void CloseAllTradesAt(string value) - { - mCloseAllTradesAt = value; - } - - // - // Risk Management Props ... - - /** - * Get Risk to Reward Ratio ... - * - * @return ( double ) - */ - double R2R() - { - return mR2R; - } - - /** - * Set Risk to Reward Ratio ... - * - * @param value: Double ... - */ - void R2R(double value) - { - // - if (value < 1) - { - value = 1; - } - - // - mR2R = value; - ReConfigure(); - } - - /** - * Get Static Volume ... - * - * @return ( double ) - */ - double Volume() - { - return mVolume; - } - - /** - * Set Static Volume ... - * - * @param value: Double ... - */ - void Volume(double value) - { - // - if (value < 0.01) - { - value = 0.01; - } - - // - mVolume = value; - ReConfigure(); - } - - /** - * Get Static Balance for Calculate Trade Volume ... - * - * @return ( double ) - */ - double StaticBalance() - { - return mStaticBalance; - } - - /** - * Set Static Balance for Calculate Trade Volume ... - * - * @param value: Argument 1 - */ - void StaticBalance(double value) - { - // - if (value < 0) - { - value = 0; - } - - // - mStaticBalance = value; - } - - /** - * Get Balance Used In Each Trade ... - * - * @return ( double ) - */ - double BalancePerTrade() - { - return mBalancePerTrade; - } - - /** - * Set Balance Used In Each Trade ... - * - * @param value: Argument 1 - */ - void BalancePerTrade(double value) - { - // - if (value < 0) - { - value = 0; - } - - // - mBalancePerTrade = value; - } - - /** - * Get Risk Percent Per Balance in Each Trade ... - * - * @return ( double ) - */ - double RiskPercentPerBalance() - { - return mRiskPercentPerBalance; - } - - /** - * Set Risk Percent Per Balance in Each Trade ... - * - * @param value: Double - */ - void RiskPercentPerBalance(double value) - { - // - if (value < 0) - { - value = 0; - } - - // - mRiskPercentPerBalance = value; - ReConfigure(); - } - - /** - * Get Dynamic Risk Management State ... - * - * @return ( bool ) - */ - bool DynamicRiskManagement() - { - return mDynamicRiskManagement; - } - - /** - * Set Dynamic Risk Management State ... - * - * @param value: Boolean ... - */ - void DynamicRiskManagement(bool value) - { - // - mDynamicRiskManagement = value; - ReConfigure(); - } - - /** - * Get Use Dynamic Volume State ... - * - * @return ( bool ) - */ - bool UseDynamicVolume() - { - return mUseDynamicVolume; - } - - /** - * Set Use Dynamic Volume State ... - * - * @param value: Boolean ... - */ - void UseDynamicVolume(bool value) - { - // - mUseDynamicVolume = value; - ReConfigure(); - } - - /** - * Get Increase Volume Step ... - * - * @return ( double ) - */ - double DynamicVolumeStep() - { - return mDynamicVolumeStep; - } - - /** - * Set Increase Volume Step ... - * - * @param value: Double ... - */ - void DynamicVolumeStep(double value) - { - // - if (value < 0.01) - { - value = 0.01; - } - - // - mDynamicVolumeStep = value; - ReConfigure(); - } - - /** - * Get Balance Factor for Generate Dynamic Volume ... - * - * @return ( double ) - */ - double DynamicVolumeBalanceFactor() - { - return mDynamicVolumeBalanceFactor; - } - - /** - * Set Balance Factor for Generate Dynamic Volume ... - * - * @param value: Double ... - */ - void DynamicVolumeBalanceFactor(double value) - { - // - if (value < 0) - { - value = 0; - } - - // - mDynamicVolumeBalanceFactor = value; - ReConfigure(); - } - - /** - * Get Max Allowed Drawdown Percent for Open Trades ... - * 0 => Ignore ... - * min => 0 ... - * max => 100 ... - * - * @return ( double ) - */ - double MaxAllowedDrawdownToOpenTrades() - { - return mMaxAllowedDrawdownToOpenTrades; - } - - /** - * Set Max Allowed Drawdown Percent for Open Trades ... - * - * @param value: Double ... - * 0 => Ignore ... - * min => 0 ... - * max => 100 ... - */ - void MaxAllowedDrawdownToOpenTrades(double value) - { - // - if (value < 0) - { - value = 0; - } - - // - if (value > 50) - { - value = 50; - } - - // - mMaxAllowedDrawdownToOpenTrades = value; - ReConfigure(); - } - - /** - * Get Max Allowed SL for Pause Signalling Per Symbol ... - * 0 => Unlimited ... - * - * @return ( int ) - */ - int MaxAllowedSLToPauseSignallingPerSymbol() - { - return mMaxAllowedSLToPauseSignallingPerSymbol; - } - - /** - * Set Max Allowed SL for Pause Signalling Per Symbol ... - * - * @param value: Integer ... - * 0 => Unlimited ... - */ - void MaxAllowedSLToPauseSignallingPerSymbol(int value) - { - // - if (value < 0) - { - value = 0; - } - - // - mMaxAllowedSLToPauseSignallingPerSymbol = value; - ReConfigure(); - } - - /** - * Get Pause Signalling Per Symbol afte Max Allowed SL Reached In Seconds ... - * 0 => Ignore ... - * - * @return ( int ) - */ - int PauseSignallingAfterReachesMaxAllowedSLInSecconds() - { - return mPauseSignallingAfterReachesMaxAllowedSLInSecconds; - } - - /** - * Set Pause Signalling Per Symbol afte Max Allowed SL Reached In Seconds ... - * - * @param value: Integer ... - * 0 => Ignore ... - */ - void PauseSignallingAfterReachesMaxAllowedSLInSecconds(int value) - { - // - if (value < 0) - { - value = 0; - } - - // - mPauseSignallingAfterReachesMaxAllowedSLInSecconds = value; - ReConfigure(); - } - - // - // Protection Props ... - - /** - * Get Allow Hedge Positions State ... - * - * @return ( bool ) - */ - bool AllowHedging() - { - return mAllowHedging; - } - - /** - * Set Allow Hedge Positions State ... - * - * @param value: Boolean ... - */ - void AllowHedging(bool value) - { - // - mAllowHedging = value; - ReConfigure(); - } - - /** - * Get Minimum Open Positions for Hedging ... - * 0 => Ignore ... - * - * @return ( int ) - */ - int MinOpenTradesFroHedging() - { - return mMinOpenTradesFroHedging; - } - - /** - * Set Minimum Open Positions for Hedging ... - * - * @param value: Integer ... - * 0 => Ignore ... - */ - void MinOpenTradesFroHedging(int value) - { - // - if (value < 0) - { - value = 0; - } - - // - mMinOpenTradesFroHedging = value; - ReConfigure(); - } - - /** - * Get Minimum Volume Step for Hedging ... - * 0 => Ignore ... - * - * @return ( double ) - */ - double HedgingMinVolumeStep() - { - return mHedgingMinVolumeStep; - } - - /** - * Set Minimum Volume Step for Hedging ... - * - * @param value: Double ... - * 0 => Ignore ... - */ - void HedgingMinVolumeStep(double value) - { - // - if (value < 0) - { - value = 0; - } - - // - if (value > 0 && value < 0.01) - { - value = 0.01; - } - - // - if (value > 0 && value > 0.1) - { - value = 0.1; - } - - // - mHedgingMinVolumeStep = value; - ReConfigure(); - } - - /** - * Get Minimum Required Profit Per Volume Step for Hedging ... - * 0 => Ignore ... - * - * @return ( double ) - */ - double HedgeingMinRequiredProfitPerVolumeStep() - { - return mHedgeingMinRequiredProfitPerVolumeStep; - } - - /** - * Set Minimum Required Profit Per Volume Step for Hedging ... - * - * @param value: Double ... - * 0 => Ignore ... - */ - void HedgeingMinRequiredProfitPerVolumeStep(double value) - { - // - if (value < 0) - { - value = 0; - } - - // - mHedgeingMinRequiredProfitPerVolumeStep = value; - ReConfigure(); - } - - // - // Actions ... - - /** - * Handle OnSignalRecieved Event ... - * - * @param signal: XSignal instance ... - * @param conditions: X121SMCStrategyConditions instance ... - */ - void HandleOnSignalRecieved( - XSignal &signal, - X121SMCStrategyConditions &conditions // - ) - { - // - // Check Signal and Conditions Validations ... - - // - if (!signal.IsValid()) - { - return; - } - - // - if (!conditions.IsValid()) - { - return; - } - - // - bool isLong = IsLong(signal.type); - - // - // Notify When a Raw (Unfiltered) Signal Recieved - // if it's Provided ... - bool mAlertRawSignals = false; - if (mAlertRawSignals) - { - // - string msg = "Raw " + (IsLong(signal.type) ? "Long" : "Short") + - " Signal Recieved: (" + signal.provider + "," + - signal.symbol + "," + - ToString(signal.period) + - ") ..."; - - // - Alert(msg); - } - - // - // Apply Volume On Signal ... - ApplyVolumeOnSignal(signal); - - // - // Chekc Signalling Enable or not ... - bool canContinue = - isLong - ? AllowLong() - : AllowShort(); - if (!canContinue) - { - return; - } - - // - // TODO: Apply Filtering On Signal ... - bool isFiltered = false; - if (isFiltered) - { - // - mTradeHandler.Remove(signal); - return; - } - - // - // Attach Conditions Summary to Signal ... - string conditionsSummary = conditions.GenerateSummary( - false, - false, - true, - false // - ); - - // - // TODO: Retrieve Conditions Summary based on Filter ... - signal.conditions = conditionsSummary; - - // - datetime currentTime = TimeCurrent(); - - // - // Chack Allow Trades ... - bool allowTrade = AllowTrade(); - if (allowTrade) - { - // - string startTime = StartTradeAt(); - string endTime = StopTradeAt(); - bool isTimePassed = IsTimeInRange( - TimeCurrent(), - startTime, - endTime // - ); - - // - if (isTimePassed) - { - // - // Execute Signal Using Trade Handler ... - ENUM_X_SIGNAL_EXECUTION_RESULT state; - bool isExecuted = mTradeHandler.ExecuteSignal( - signal, - conditions, - state, - false // ignore Policies ... - ); - } - } - else - { - // - // Only Alert Signals ... - string msg = (IsLong(signal.type) - ? "Long" - : "Short") + - " Signal Recieved: (" + - signal.provider + "," + - signal.symbol + "," + - ToString(signal.period) + - ") ..."; - - // - Alert(msg); - } - - // - signal.Clean(); - conditions.Clean(); - } - - // - // Override Actions ... - - /** - * Apply Default Configurations ... - */ - void DefaultConfigure() override - { - // - // Commons ... - Slippage(10); - TagPrefix(""); - MagicNumber(1694056); - - // - // Symbol ... - SetSymbol(_Symbol); - SetPeriod(_Period); - MultiSymbol(false); - Symbols("EURUSDb,GBPUSDb,USDJPYb,USDCHFb,DowJones30,XAUUSDb"); - - // - // Signalling ... - Disabled(false); - AllowLong(true); - AllowShort(true); - - // - string tag = GetTag(); - - // - // Alert ... - SetAlertPrefix(tag); - SetAlertLogAlerts(true); - SetAlertPushAlerts(true); - SetAlertMailAlerts(false); - SetAlertEnableAlerts(true); - SetAlertTerminalAlerts(false); - - // - // Reports ... - ReportNewDays(true); - ReportNewWeeks(false); - ReportNewHours(false); - ReportNewMonths(false); - - // - R2R(1); - - // - // Volume Default Configurations ... - Volume(0.01); - UseDynamicVolume(false); - DynamicVolumeStep(0.01); - DynamicVolumeBalanceFactor(200); - - // - RiskPercentPerBalance(0); - DynamicRiskManagement(false); - } - - /** - * Vaslidate Inputs ... - * - * @return ( bool ) - */ - bool ValidateInputs() override - { - // - bool result = false; - - // - string errMessage = ""; - - // - bool isCommonValid = ( - // - Slippage() > 0 && - MagicNumber() > 0 - // - ); - if (!isCommonValid) - { - // - errMessage += "common configurations error;" + "\n"; - } - - // - // Checking Volume ... - bool isVolumeValid = true; - if (UseDynamicVolume()) - { - // - isVolumeValid = - DynamicVolumeStep() > 0 && - DynamicVolumeBalanceFactor() > 0; - if (!isVolumeValid) - { - errMessage += "Dynamic Volume configurations error;" + "\n"; - } - } - isVolumeValid = isVolumeValid && - Volume() > 0; - if (!isVolumeValid) - { - errMessage += "Static Volume configurations error;" + "\n"; - } - - // - result = - // - // Common ... - isCommonValid && - // - // Volume Coniguration ... - isVolumeValid && - // - // Otere ... - true - // - ; - - // - if (!result) - { - // - // Since here Logger not Initiallized, we Use Raw Print Command ... - errMessage = " Errors: \n" + errMessage; - Alert(errMessage); - } - - // - return result; - } - - // - // Initializers and DeInitializers ... - - /** - * Initial EA Requirements ... - * - * @return ( bool ) - */ - bool InitEA() override - { - // - bool result = true; - - // - // Initialize Indicator Helpers ... - - // - X121XCCInputs xccInputs; - xccInputs.Default(); - xccHelper = new XCX121XCCHelper(); - result = xccHelper.Init( - _Symbol, - _Period, - xccInputs // - ); - if (!result) - { - return result; - } - - // - X121XCTInputs xctInputs; - xctInputs.Default(); - xctHelper = new XCX121XCTHelper(); - result = xctHelper.Init( - _Symbol, - _Period, - xctInputs // - ); - if (!result) - { - return result; - } - - // - // Configure Alerts ... - SetAlertPrefix(GetTag()); - SetAlertEnableAlerts(GetAlertEnableAlerts()); - SetAlertLogAlerts(GetAlertLogAlerts()); - SetAlertMailAlerts(GetAlertMailAlerts()); - SetAlertPushAlerts(GetAlertPushAlerts()); - SetAlertTerminalAlerts(GetAlertTerminalAlerts()); - - // - // Create Trader Instance and Configure it ... - mTrader = new XCTrade( - Slippage(), - MagicNumber() // - ); - mTrader.AddOnStopLossEventHandler(OnPositionSLEventListener); - mTrader.AddOnTakeProfitEventHandler(OnPositionTPEventListener); - mTrader.AddOnDealsChangedEventHandler(OnDealsChangedEventListener); - mTrader.AddOnOrdersChangedEventHandler(OnOrdersChangedEventListener); - mTrader.AddOnModifyPositionEventHandler(OnPositionModifiedEventListener); - mTrader.AddOnPositionsChangedEventHandler(OnPositionsChangedEventListener); - mTrader.AddOnForceClosePositionEventHandler(OnPositionForceCloseEventListener); - mTrader.AddOnPartialClosePositionEventHandler(OnPositionPartialCloseEventListener); - - // - // Initialize Trade Handler ... - mTradeHandler = new XC121SMCTradeHandler(mTrader); - mTradeHandler.SaveTrades(false); - mTradeHandler.SaveSignals(false); - mTradeHandler.SaveConditions(false); - - // - ReConfigureTradeHandler(); - - // - // Parsers ... - XSymbolParser _symbolParser; - - // - // Single Symbol ... - if (!MultiSymbol()) - { - // - // Register Strategy ... - - // - // Create Class Instance ... - XCX121SMCBaseStrategy *iX121SMCStrategy; - iX121SMCStrategy = new XCX121SMCStrategy( - _Symbol, - _Period // - ); - - // - iX121SMCStrategy.AddXSignalEventHandler(OnSignalEventListener); - - // - ConfigureStrategy(iX121SMCStrategy); - RegisterStrategy(iX121SMCStrategy); - } - // - // Multi Symbol ... - else - { - // - // Parse Symbols ... - string symbols[]; - int symbolsCount = SplitContent( - symbols, - Symbols() // - ); - result = IsValidSize(symbolsCount); - if (!result) - { - return result; - } - - // - for (int i = 0; i < symbolsCount; i++) - { - // - // Select Symbol ... - string iSymbol = symbols[i]; - - // - // Register Strategy Based On Symbol ... - - // - // Parse Symbol ... - bool isEURUSD = _symbolParser.IsEURUSD(_Symbol); - bool isGBPUSD = _symbolParser.IsGBPUSD(_Symbol); - bool isEURGBP = _symbolParser.IsEURGBP(_Symbol); - bool isUSDCHF = _symbolParser.IsUSDCHF(_Symbol); - bool isEURCHF = _symbolParser.IsEURCHF(_Symbol); - bool isUSDJPY = _symbolParser.IsUSDJPY(_Symbol); - bool isEURJPY = _symbolParser.IsEURJPY(_Symbol); - bool isUSDCAD = _symbolParser.IsUSDCAD(_Symbol); - bool isEURCAD = _symbolParser.IsEURCAD(_Symbol); - bool isAUDUSD = _symbolParser.IsAUDUSD(_Symbol); - bool isEURAUD = _symbolParser.IsEURAUD(_Symbol); - bool isNZDUSD = _symbolParser.IsNZDUSD(_Symbol); - bool isEURNZD = _symbolParser.IsEURNZD(_Symbol); - - // - // Check Symbol Can Register or not ... - bool canRegisterStrategy = true; - - // - if (canRegisterStrategy) - { - // - // Create Class Instance ... - XCX121SMCBaseStrategy *iX121SMCStrategy; - iX121SMCStrategy = new XCX121SMCStrategy( - iSymbol, - _Period // - ); - - // - iX121SMCStrategy.AddXSignalEventHandler(OnSignalEventListener); - - // - // Register Strategy ... - ConfigureStrategy(iX121SMCStrategy); - RegisterStrategy(iX121SMCStrategy); - } - } - - // - Clean(symbols); - } - - // - return result; - } - - /** - * Destroy all Initialized EA Requirements ... - */ - void DestroyEA() override - { - // - ZeroMemory(xccHelper); - ZeroMemory(xctHelper); - ZeroMemory(mTradeHandler); - - // - delete xccHelper; - delete xctHelper; - delete mTradeHandler; - - // - Clean(mStrategies); - } - - /** - * Call all Registered Strategies On Tick ... - */ - void HandleStrategiesOnTick() override - { - // - // Check Force Close ... - string forceCloseTimeStr = CloseAllTradesAt(); - if (IsValid(forceCloseTimeStr)) - { - // - datetime forceCloseTime = ParseDateTimeFromTimeString(forceCloseTimeStr); - bool canForceClose = IsTimeInRange( - TimeCurrent(), - forceCloseTime // - ) && - !mIsForceCloseAtTime; - if (canForceClose) - { - mIsForceCloseAtTime = mTradeHandler.ForceClose(); - } - } - - // - // Update Positions Data ... - mTradeHandler.UpdateData(); - - // - // Protect Positions ... - mTradeHandler.HandleProtection(); - - // - int count = ArraySize(mStrategies); - if (!IsValidSize(count)) - { - return; - } - - // - for (int i = 0; i < count; i++) - { - // - // Call Tick Handler Function ... - mStrategies[i].HandleTick(); - } - } - - /** - * Handle Strategies Guards ... - */ - void HandleStrategiesGuard() override - { - // - int count = ArraySize(mStrategies); - if (!IsValidSize(count)) - { - return; - } - - // - XPosition positions[]; - int positionsCount = mTrader.GetPositions( - positions, // Result ... - NULL, // Symbol ... - NULL, // Provider ... - NULL, // Period ... - X_POSITION_TYPE_ALL // All Types ... - ); - if (!IsValidSize(positionsCount)) - { - return; - } - - // - for (int i = 0; i < count; i++) - { - // - // Call Tick Handler Function ... - X121SMCGuard iGuards[]; - bool hasGuards = mStrategies[i].HandleGuard( - iGuards, - positions // - ); - if (hasGuards) - { - HandleGuards(iGuards); - } - } - - // - Clean(positions); - } - - // - // Event Handlers ... - - /** - * Calls When a Deals Changed Triggered ... - * - * @param count: Integer, Number of Changes ... - */ - void HandleOnDealsChanged(int count) override - { - } - - /** - * Calls When a Order Changed Triggered ... - * - * @param count: Integer, Number of Changes ... - */ - void HandleOnOrdersChanged(int count) override - { - } - - /** - * Calls When a Positions Changed Triggered ... - * - * @param count: Integer, Number of Changes ... - */ - void HandleOnPositionsChanged(int count) override - { - // - if (IsValidSize(count)) - { - mTradeHandler.HandleNewPosition(); - } - } - - /** - * Calls When a Position's SL Triggered ... - * - * @param deal: XDeal instance ... - */ - void HandleOnStopLossTriggered(const XDeal &deal) override - { - // - // Finish ... - mTradeHandler.Finish(deal); - - // - HandleReportBalance(); - } - - /** - * Calls When a Position's TP Triggered ... - * - * @param deal: XDeal instance ... - */ - void HandleOnTakeProfitTriggered(const XDeal &deal) override - { - // - // Finish ... - mTradeHandler.Finish(deal); - - // - bool useDynamicRiskManagement = DynamicRiskManagement(); - if (useDynamicRiskManagement) - { - mTradeHandler.ResetSymbolInfo(deal.symbol); - } - - // - HandleReportBalance(); - } - - /** - * Handle Force Close a Position ... - * - * @param ticket: Position Ticket ... - * @param position: XPosition ... - * @param comment: Closing Comment ... - */ - void HandleOnPositionForceClosed( - const ulong ticket, - const XPosition &position, - const string comment // - ) override - { - // - // Finish ... - mTradeHandler.Finish( - ticket, - position, - comment // - ); - - // - HandleReportBalance(); - } - - /** - * Reset All Paused Symbols on Each New Days ... - */ - void HandleOnNewDay() override - { - // - mIsForceCloseAtTime = false; - mTradeHandler.ResumePausedSymbols(); - } - - /** - * Re Configure Materials on Properties Changed ... - */ - void ReConfigure() override - { - // - ReConfigureTradeHandler(); - ReConfigureAllStrategies(); - } - - /** - * Generate Identifier Tag ... - * - * @return ( string ) - */ - string GetTag() override - { - // - string result = NULL; - - // - string tagPrefix = TagPrefix(); - if (IsValid(tagPrefix)) - { - result = tagPrefix; - } - else - { - result = ""; - } - - // - result = - XC121SMCExpertToken + result; - - // - return result; - } - - // - protected: - // - - // - // Props ... - - // - XC121SMCTradeHandler *mTradeHandler; // Trade Handler ... - XCX121SMCBaseStrategy *mStrategies[]; // Registere Strategies in EA ... - - // - // Actions ... - - /** - * Apply Volume Based On Configurations on Signal ... - * - * @param signal: XSignal instance - */ - void ApplyVolumeOnSignal(XSignal &signal) - { - // - if (signal.ignoreEAVolume) - { - return; - } - - // - double staticVolume = Volume(); - double fVolume = staticVolume > 0 - ? staticVolume - : 0.01; - - // - double staticBalance = StaticBalance(); - double accountBalance = mTrader.mAccount.GetBalance(); - double balance = staticBalance > 0 - ? staticBalance - : accountBalance; - - // - bool useDynamicVolume = UseDynamicVolume(); - double balancePerTrade = BalancePerTrade(); - double dynamicVolumeStep = DynamicVolumeStep(); - double riskPercentPerBalance = RiskPercentPerBalance(); - bool allowDynamicRiskManagement = DynamicRiskManagement(); - double dynamicVolumeBalanceFactor = DynamicVolumeBalanceFactor(); - - // - // Apply Static Volume ... - bool allowStaticVolume = staticVolume > 0; - - // - // Apply Dynamic Volume ... - bool aloowApplyDynamicVolume = useDynamicVolume && - dynamicVolumeStep && - dynamicVolumeBalanceFactor; - - // - // Apply Risk Per Trade Volume ... - bool allowApplyRiskPerTradeVolume = - !aloowApplyDynamicVolume && - riskPercentPerBalance > 0; - - // - // Apply Balance Per Trade Volume ... - bool allowApplyBalacePerTradeVolume = - !aloowApplyDynamicVolume && - !allowApplyRiskPerTradeVolume && - balancePerTrade > 0; - - // - // First Check Dynamic Volume ... - if (aloowApplyDynamicVolume) - { - // - // Dynamic Volume ... - double dVolume = mTrader.GetDynamicVolume( - signal.symbol, - dynamicVolumeBalanceFactor, - dynamicVolumeStep // - ); - if (dVolume < fVolume) - { - dVolume = fVolume; - } - - // - signal.volume = dVolume; - } - else if (allowApplyRiskPerTradeVolume) - { - // - double riskAmountPerBalance = (riskPercentPerBalance * balance) / 100; - - // - double risk = signal.GetRisk(); - double points = GetPoints(signal.symbol); - double riskInPoints = risk / points; - - // - double volume = mTrader.mAccount.CalculateVolume( - signal.symbol, - riskAmountPerBalance, - riskInPoints // - ); - if (volume <= 0) - { - volume = fVolume; - } - - // - // Check Dynamic Risk Management ... - bool allowDynamicRiskManagement = DynamicRiskManagement(); - if (allowDynamicRiskManagement) - { - // - // Calculate Dynamic Additional Risk Management Volume Multiplier ... - double mAdditionalRiskMultiplier = CalculateAdditionalVolumeMultiplier(signal); - if (mAdditionalRiskMultiplier < 1) - { - mAdditionalRiskMultiplier = 1; - } - - // - volume *= mAdditionalRiskMultiplier; - } - - // - signal.volume = volume; - } - else if (allowApplyBalacePerTradeVolume) - { - // - double risk = signal.GetRisk(); - double points = GetPoints(signal.symbol); - double riskInPoints = risk / points; - - // - double volume = mTrader.mAccount.CalculateVolume( - signal.symbol, - balancePerTrade, - riskInPoints // - ); - if (volume <= 0) - { - volume = fVolume; - } - - // - signal.volume = volume; - } - else if (allowStaticVolume) - { - signal.volume = staticVolume; - } - else - { - signal.volume = fVolume; - } - - // - // Normalize Signal Volume ... - signal.volume = NormalizeVolume( - signal.volume, - signal.symbol // - ); - } - - /** - * Configure Startegy ... - */ - void ConfigureStrategy(XCX121SMCBaseStrategy *&strategy) - { - // - if (strategy == NULL) - { - return; - } - - // - // Configure Alerts ... - strategy.SetAlertPrefix(GetTag()); - strategy.SetAlertLogAlerts(GetAlertLogAlerts()); - strategy.SetAlertMailAlerts(GetAlertMailAlerts()); - strategy.SetAlertPushAlerts(GetAlertPushAlerts()); - strategy.SetAlertEnableAlerts(GetAlertEnableAlerts()); - strategy.SetAlertTerminalAlerts(GetAlertTerminalAlerts()); - - // - // Confiugre Signalling ... - - // - strategy.R2R(R2R()); - strategy.AllowLong(AllowLong()); - strategy.AllowShort(AllowShort()); - strategy.MaxAllowedSpread(20); - // strategy.MaxAllowedSaveTicks(150); - // strategy.MinRequiredTicksForSpreadPass(100); - - // - if (Disabled()) - { - strategy.Disable(); - } - else - { - strategy.Enable(); - } - - // - } - - /** - * Register an Strategy in EA ... - * - * @param strategy: XCX121SMCBaseStrategy instance ... - */ - void RegisterStrategy(XCX121SMCBaseStrategy *strategy) - { - // - if (strategy == NULL) - { - return; - } - - // - ArrayResize( - mStrategies, - ArraySize(mStrategies) + 1 // - ); - - // - mStrategies[ArraySize(mStrategies) - 1] = strategy; - } - - /** - * Re Configure All Registered Strategies ... - */ - void ReConfigureAllStrategies() - { - // - int count = ArraySize(mStrategies); - if (!IsValidSize(count)) - { - return; - } - - // - for (int i = 0; i < count; i++) - { - // - ConfigureStrategy(mStrategies[i]); - } - } - - /** - * Re Configure Trade Handler ... - */ - void ReConfigureTradeHandler() - { - // - if (mTradeHandler == NULL) - { - return; - } - - // - // Configure Alerts ... - mTradeHandler.SetAlertPrefix(GetTag()); - mTradeHandler.SetAlertEnableAlerts(GetAlertEnableAlerts()); - mTradeHandler.SetAlertLogAlerts(GetAlertLogAlerts()); - mTradeHandler.SetAlertMailAlerts(GetAlertMailAlerts()); - mTradeHandler.SetAlertPushAlerts(GetAlertPushAlerts()); - mTradeHandler.SetAlertTerminalAlerts(GetAlertTerminalAlerts()); - - // - mTradeHandler.AllowLong(AllowLong()); - mTradeHandler.AllowShort(AllowShort()); - mTradeHandler.MaxAllowedLongs(MaxAllowedLongs()); - mTradeHandler.MaxAllowedShorts(MaxAllowedShorts()); - mTradeHandler.UseMaxAllowedSignalsPerSymbol(UseMaxAllowedSignalsPerSymbol()); - mTradeHandler.LastPositionProfitForAcceptNextInPoint(LastPositionProfitForAcceptNextInPoint()); - mTradeHandler.DelaysBetweenTwoSignalsInBar(DelaysBetweenTwoSignalsInBar()); - mTradeHandler.MaxAllowedSpread(MaxAllowedSpread()); - mTradeHandler.MaxAllowedDrawdownToOpenTrades(MaxAllowedDrawdownToOpenTrades()); - mTradeHandler.MaxAllowedSLToPauseSignallingPerSymbol(MaxAllowedSLToPauseSignallingPerSymbol()); - mTradeHandler.PauseSignallingAfterReachesMaxAllowedSLInSecconds(PauseSignallingAfterReachesMaxAllowedSLInSecconds()); - mTradeHandler.AllowHedging(AllowHedging()); - mTradeHandler.MinOpenTradesFroHedging(MinOpenTradesFroHedging()); - mTradeHandler.HedgingMinVolumeStep(HedgingMinVolumeStep()); - mTradeHandler.HedgeingMinRequiredProfitPerVolumeStep(HedgeingMinRequiredProfitPerVolumeStep()); - } - - // - private: - // - - // - // Props ... - - // - // Signalling Props ... - bool mAllowLong; // Allow Long Signals ... - bool mAllowShort; // Allow Short Signals ... - int mMaxAllowedLongs; // Max Allowed Long Signals ... - int mMaxAllowedShorts; // Max Allowed Short Signals ... - bool mUseMaxAllowedSignalsPerSymbol; // Use Max Allowed Signal Types Per Symbol ... - double mLastPositionProfitForAcceptNextInPoint; // Last Position Profit In Points for Accept new Signal ... - int mDelaysBetweenTwoSignalsInBar; // Delay between two Signals in Bars ... - double mMaxAllowedSpread; // Max Allowed Spread for Signalling ... - int mMinRequiredVerificationForSpreadPass; // Minimum Spread Verification for Signalling ... - - // - // Trade ... - bool mAllowTrade; // Allow Open Trade On Signals ... - string mStartTradeAt; // Enable Trade on Signals on Time ... - string mStopTradeAt; // Enable Trade on Signals on Time ... - string mCloseAllTradesAt; // Enable Close All Trades on Signals on Time ... - - // - bool mIsForceCloseAtTime; - - // - // Risk Management Props ... - double mR2R; // Signallers Risk to Reward Ratio ... - double mVolume; // Static Volume ... - double mStaticBalance; // Static Balance for Calculate Trade Volume ... - double mBalancePerTrade; // Balance Used in Each Trade ... - double mRiskPercentPerBalance; // Risk Percent Per Balance in Each Trade ... - bool mDynamicRiskManagement; // Dynamic Risk Management ... - bool mUseDynamicVolume; // Use Dynamic Volume ... - double mDynamicVolumeStep; // Increase Volume Step ... - double mDynamicVolumeBalanceFactor; // Balance Factor for Generate Dynamic Volume ... - double mMaxAllowedDrawdownToOpenTrades; // Max Allowed Drawdown for Open Trades ... - int mMaxAllowedSLToPauseSignallingPerSymbol; // Max Allowed SL for Pause Signalling Per Symbol ... - int mPauseSignallingAfterReachesMaxAllowedSLInSecconds; // Pause Signalling Per Symbol afte Max Allowed SL Reached In Seconds ... - - // - // Protection Props ... - bool mAllowHedging; // Allow Hedge Positions ... - int mMinOpenTradesFroHedging; // Minimum Open Positions for Hedging ... - double mHedgingMinVolumeStep; // Minimum Volume Step for Hedging ... - double mHedgeingMinRequiredProfitPerVolumeStep; // Minimum Required Profit Per Volume Step for Hedging ... - - // - double CalculateAdditionalVolumeMultiplier(XSignal &signal) - { - // - double result = 0; - - // - if (!signal.IsValid()) - { - return result; - } - - // - X121SMCSymbolPositionInfo info; - bool hasInfo = mTradeHandler.GetSymbolInfo( - signal.symbol, - info // - ); - if (!hasInfo) - { - return result; - } - - // - if (info.countedSLs >= 2) - { - result = (info.countedSLs / 2) + 1; - } - - // - return result; - } - - /** - * Handle Guard Actions ... - * - * @param guards: X121SMCGuard instance Collection ... - */ - void HandleGuards(X121SMCGuard &guards[]) - { - // - int count = ArraySize(guards); - if (!IsValidSize(guards)) - { - return; - } - - // - for (int i = 0; i < count; i++) - { - // - X121SMCGuard iGuard = guards[i]; - - // - if (!iGuard.IsValid()) - { - continue; - } - - // - // Here we Have to Handle Guard Actions ... - - // - // Close ... - bool canClose = - NotEmpty(iGuard.ticket) && - iGuard.action == X_121_SMC_GUARD_ACTION_CLOSE; - - // - // Close All ... - bool canCloseAll = iGuard.action == X_121_SMC_GUARD_ACTION_CLOSE_ALL; - - // - // Close Longs ... - bool canCloseLongs = iGuard.action == X_121_SMC_GUARD_ACTION_CLOSE_LONGS; - - // - // Close Shorts ... - bool canCloseShorts = iGuard.action == X_121_SMC_GUARD_ACTION_CLOSE_SHORTS; - - // - // Partial Close ... - bool canPartialClose = - NotEmpty(iGuard.ticket) && - iGuard.volumeMultiplier > 0 && - iGuard.action == X_121_SMC_GUARD_ACTION_PARTIAL_CLOSE; - - // - // Trail Stop ... - bool canTrailStop = - iGuard.sl > 0 && - NotEmpty(iGuard.ticket) && - iGuard.action == X_121_SMC_GUARD_ACTION_TRAIL_STOP; - - // - // Trail Target ... - bool canTrailTarget = - iGuard.tp > 0 && - NotEmpty(iGuard.ticket) && - iGuard.action == X_121_SMC_GUARD_ACTION_TRAIL_TARGET; - - // - // Hedge ... - bool canHedge = iGuard.action == X_121_SMC_GUARD_ACTION_HEDGE; - - // - // Check is Guard Valid ... - bool isValidGuardAction = - canHedge || - canClose || - canCloseAll || - canTrailStop || - canCloseLongs || - canTrailTarget || - canCloseShorts || - canPartialClose; - if (!isValidGuardAction) - { - continue; - } - - // - // Now we Sure to Have a Valid Guard ... - // Start to o Guard Actions ... - - // - // Close All ... - if (canCloseAll) - { - // - XPosition positions[]; - int positionsCount = - mTrader - .GetPositions( - positions, // Result ... - iGuard.symbol, - iGuard.provider, - NULL, // Period ... - X_POSITION_TYPE_ALL, // All Types ... - true // Filter by Magic ... - ); - if (IsValidSize(positionsCount)) - { - // - string comment = "Guard Close All ..."; - string message = "Guard Close All (" + ToString(positionsCount) + ") Positions Successfully ..."; - int forceClosed = mTradeHandler.ForceClose( - positions, - comment, - message // - ); - - // - if (forceClosed) - { - RestEA(120 * 60); - } - } - } - - // - // Close Longs ... - if (canCloseLongs) - { - // - XPosition longPositions[]; - XPosition shortPositions[]; - mTrader - .GetPositions( - longPositions, // Result ... - shortPositions, // Result ... - iGuard.symbol, - iGuard.provider, - NULL, // Period ... - true // Filter by Magic ... - ); - - // - int longPositionsCount = ArraySize(longPositions); - bool hasLongPositions = IsValidSize(longPositionsCount); - - // - int shortPositionsCount = ArraySize(shortPositions); - bool hasShortPositions = IsValidSize(shortPositionsCount); - - // - if (hasLongPositions) - { - // - string comment = "Guard Close Longs ..."; - string message = "Guard Close (" + ToString(longPositionsCount) + ") Long Positions Successfully ..."; - bool isClosed = mTradeHandler.ForceClose( - longPositions, - comment, - message // - ); - - // - if (isClosed) - { - RestEA(120 * 60); - } - } - } - - // - // Close Shorts ... - if (canCloseShorts) - { - // - XPosition longPositions[]; - XPosition shortPositions[]; - mTrader - .GetPositions( - longPositions, // Result ... - shortPositions, // Result ... - iGuard.symbol, - iGuard.provider, - NULL, // Period ... - true // Filter by Magic ... - ); - - // - int longPositionsCount = ArraySize(longPositions); - bool hasLongPositions = IsValidSize(longPositionsCount); - - // - int shortPositionsCount = ArraySize(shortPositions); - bool hasShortPositions = IsValidSize(shortPositionsCount); - - // - if (hasShortPositions) - { - // - string comment = "Guard Close Shorts ..."; - string message = "Guard Close (" + ToString(shortPositionsCount) + ") Short Positions Successfully ..."; - bool isClosed = mTradeHandler.ForceClose( - shortPositions, - comment, - message // - ); - - // - if (isClosed) - { - RestEA(120 * 60); - } - } - } - - // - // Close ... - if (canClose) - { - // - XPosition iPosition; - bool hasPosition = mTrader.GetPosition( - iGuard.ticket, - iPosition // - ); - - // - bool isLong = IsLong(iPosition.type); - - // - if (hasPosition) - { - // - XPosition positions[]; - AddRef( - iPosition, - positions // - ); - - // - string comment = "Guard Close ..."; - string message = "Guard Close " + (isLong ? "Long" : "Short") + " Position: (" + ToString(iGuard.ticket) + ") Successfully ..."; - bool isClosed = mTradeHandler.ForceClose( - positions, - comment, - message // - ); - - // - if (isClosed) - { - RestEA(120 * 60); - } - } - } - - // - // Partial Close ... - if (canPartialClose) - { - // - XPosition iPosition; - bool hasPosition = mTrader.GetPosition( - iGuard.ticket, - iPosition // - ); - - // - bool isLong = IsLong(iPosition.type); - - // - if (hasPosition) - { - // - // Normalize Volume Multiplier ... - double vMult = iGuard.volumeMultiplier; - if (vMult > 0.5) - { - vMult = 0.5; - } - if (vMult < 0) - { - vMult = 0.5; - } - - // - // Calculate and Normalize Volume ... - double volume = iPosition.volume * iGuard.volumeMultiplier; - volume = NormalizeVolume( - volume, - iPosition.symbol // - ); - - // - string comment = "Guard Partially Closed: " + ToString(volume) + " ..."; - string message = "Guard Partially Closed " + (isLong ? "Long" : "Short") + ": " + ToString(volume) + " Successfully ..."; - bool isModified = mTrader.ClosePartial( - iPosition.ticket, - volume, - comment // - ); - if (isModified) - { - // - mTradeHandler.Alert(message); - - // - if (volume == iPosition.volume) - { - // - mTradeHandler.Finish( - iPosition.ticket, - iPosition, - comment // - ); - - // - RestEA(120 * 60); - } - } - } - } - - // - // Hedge ... - if (canHedge) - { - // - XPosition positions[]; - int positionsCount = - mTrader - .GetPositions( - positions, // Result ... - iGuard.symbol, - iGuard.provider, - NULL, // Period ... - X_POSITION_TYPE_ALL, // All Types ... - true // Filter by Magic ... - ); - if (IsValidSize(positionsCount)) - { - // - int longs = 0; - double longProfits = 0; - double longVolumes = 0; - - // - int shorts = 0; - double shortProfits = 0; - double shortVolumes = 0; - CountPositions( - positions, - longs, - longProfits, - longVolumes, - shorts, - shortProfits, - shortVolumes // - ); - - // - int count = longs + shorts; - double profits = longProfits + shortProfits; - double volumes = longVolumes + shortVolumes; - - // - bool canDoHedge = - count > 0 && - profits > 0 && - volumes > 0; - if (canDoHedge) - { - // - string comment = "Guard Hedge ..."; - string message = "Guard Hedge (" + ToString(count) + ") Positions by: (" + ToString(profits) + ") Successfully ..."; - bool isClosed = mTradeHandler.ForceClose( - positions, - comment, - message // - ); - - // - if (isClosed) - { - RestEA(120 * 60); - } - } - } - } - - // - // Trail Stop ... - if (canTrailStop) - { - // - XPosition iPosition; - bool hasPosition = mTrader.GetPosition( - iGuard.ticket, - iPosition // - ); - - // - bool isLong = IsLong(iPosition.type); - - // - bool canDoTrail = - hasPosition && - iPosition.profit > 0 && - isLong - ? iPosition.price > iGuard.sl && - (iPosition.sl == 0 || - iPosition.sl < iGuard.sl) - : iPosition.price < iGuard.sl && - (iPosition.sl == 0 || - iPosition.sl > iGuard.sl); - if (canDoTrail) - { - // - string comment = "Guard Trail Stop ..."; - string message = "Guard Trail " + (isLong ? "Long" : "Short") + " Position: (" + ToString(iGuard.ticket) + ") Stop Successfully ..."; - bool isModified = mTrader.Modify( - iPosition.ticket, - iGuard.sl, - iPosition.tp, - comment // - ); - if (isModified) - { - mTradeHandler.Alert(message); - } - } - } - - // - // Trail Target ... - if (canTrailTarget) - { - // - XPosition iPosition; - bool hasPosition = mTrader.GetPosition( - iGuard.ticket, - iPosition // - ); - - // - bool isLong = IsLong(iPosition.type); - - // - bool canDoTrail = - hasPosition && - iGuard.tp != iPosition.tp && - isLong - ? iGuard.tp > iPosition.price - : iGuard.tp < iPosition.price; - if (canDoTrail) - { - // - string comment = "Guard Trail Target ..."; - string message = "Guard Trail " + (isLong ? "Long" : "Short") + " Position: (" + ToString(iGuard.ticket) + ") Target Successfully ..."; - bool isModified = mTrader.Modify( - iPosition.ticket, - iPosition.sl, - iGuard.tp, - comment // - ); - if (isModified) - { - mTradeHandler.Alert(message); - } - } - } - } - - // - Clean(guards); - Clean(guards); - } - - // - void RestEA(int seconds) - { - // - } - - // -}; - -// \ No newline at end of file diff --git a/Documents/BKP/xsupdem/x-121.smc.xsupdemobs.signal.class.mq5 b/Documents/BKP/xsupdem/x-121.smc.xsupdemobs.signal.class.mq5 deleted file mode 100644 index 1e58957e..00000000 --- a/Documents/BKP/xsupdem/x-121.smc.xsupdemobs.signal.class.mq5 +++ /dev/null @@ -1,3699 +0,0 @@ -/////////////////////////////////////////////////////// -// -// SaherElm IT Center MQL5 X121 SMC Signal Class -// ------------------------------------------------- -// Name: XSupDemOBS -// 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.xsupdemobs.signal.lib.mq5" - -// -// Definition ... -class XCX121SMCXSupDemOBSSignalDetector : public XCBase -{ - // - public: - // - // Props ... - X121SMCStrategyXSupDemOBSSignalConditions mConditions; - X121SMCStrategyXSupDemOBSSignalConditions mConditionsCollection[]; - - // - // Constructor(s) ... - XCX121SMCXSupDemOBSSignalDetector() - { - Init(); - } - - // - // Deconstructor ... - ~XCX121SMCXSupDemOBSSignalDetector() - { - DeInit(); - } - - // - // - // - - // - // Detect Setup Conditions ... - bool DetectSignalSetup( - // - string _symbol, - ENUM_TIMEFRAMES _period, - // - 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) - { - 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; - - // - string symbol = _symbol; - ENUM_TIMEFRAMES period = _period; - - // - mConditions.symbol = symbol; - mConditions.period = period; - - // - double ask = GetAsk(symbol); - double bid = GetBid(symbol); - datetime cTime = TimeCurrent(); - double points = GetPoints(symbol); - - // - double target = 0; - - // - // Cycles Conditions ... - - // - // Decision ... - ENUM_XPOI_EVENTS decisionPoiEvents[]; - ENUM_X_CYCLE_EVENTS decisionCycleEvents[]; - X121SMCCycleConditions decisionConditions; - result = decisionCycleHelper.GetConditions( - decisionCycleEvents, - decisionPoiEvents, - decisionConditions, - zIndex, - loopback // - ); - if (!result) - { - return result; - } - - // - // Analyse ... - ENUM_XPOI_EVENTS analysePoiEvents[]; - ENUM_X_CYCLE_EVENTS analyseCycleEvents[]; - X121SMCCycleConditions analyseConditions; - result = analyseCycleHelper.GetConditions( - analyseCycleEvents, - analysePoiEvents, - analyseConditions, - zIndex, - loopback // - ); - if (!result) - { - return result; - } - - // - // Consolidation ... - ENUM_XPOI_EVENTS consolidationPoiEvents[]; - ENUM_X_CYCLE_EVENTS consolidationCycleEvents[]; - X121SMCCycleConditions consolidationConditions; - result = consolidationCycleHelper.GetConditions( - consolidationCycleEvents, - consolidationPoiEvents, - consolidationConditions, - zIndex, - loopback // - ); - if (!result) - { - return result; - } - - // - // Vision ... - ENUM_XPOI_EVENTS visionPoiEvents[]; - ENUM_X_CYCLE_EVENTS visionCycleEvents[]; - X121SMCCycleConditions visionConditions; - result = visionCycleHelper.GetConditions( - visionCycleEvents, - visionPoiEvents, - visionConditions, - zIndex, - loopback // - ); - if (!result) - { - 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 ... - - // - XOHCL decisionZBar; - XOHCL decisionCBar; - XOHCL decisionPBar; - double decisionCBarBullishZoneChechValue = 0; - double decisionCBarBearishZoneChechValue = 0; - - // - result = decisionZBar.Init( - decisionState.symbol, - decisionState.period, - 0 // - ); - if (!result) - { - // - Clean(visionPoiEvents); - Clean(analysePoiEvents); - Clean(decisionPoiEvents); - Clean(visionCycleEvents); - Clean(analyseCycleEvents); - Clean(decisionCycleEvents); - Clean(consolidationPoiEvents); - Clean(consolidationCycleEvents); - - // - visionState.Clean(); - analyseState.Clean(); - decisionZBar.Clean(); - decisionCBar.Clean(); - decisionPBar.Clean(); - decisionState.Clean(); - visionConditions.Clean(); - analyseConditions.Clean(); - visionXConditions.Clean(); - consolidationState.Clean(); - decisionConditions.Clean(); - analyseXConditions.Clean(); - decisionXConditions.Clean(); - consolidationConditions.Clean(); - consolidationXConditions.Clean(); - - // - return result; - } - - // - result = decisionZBar - .GetPreviousBar(decisionCBar); - if (!result) - { - // - Clean(visionPoiEvents); - Clean(analysePoiEvents); - Clean(decisionPoiEvents); - Clean(visionCycleEvents); - Clean(analyseCycleEvents); - Clean(decisionCycleEvents); - Clean(consolidationPoiEvents); - Clean(consolidationCycleEvents); - - // - visionState.Clean(); - analyseState.Clean(); - decisionZBar.Clean(); - decisionCBar.Clean(); - decisionPBar.Clean(); - decisionState.Clean(); - visionConditions.Clean(); - analyseConditions.Clean(); - visionXConditions.Clean(); - consolidationState.Clean(); - decisionConditions.Clean(); - analyseXConditions.Clean(); - decisionXConditions.Clean(); - consolidationConditions.Clean(); - consolidationXConditions.Clean(); - - // - return result; - } - - // - result = decisionCBar - .GetPreviousBar(decisionPBar); - if (!result) - { - // - Clean(visionPoiEvents); - Clean(analysePoiEvents); - Clean(decisionPoiEvents); - Clean(visionCycleEvents); - Clean(analyseCycleEvents); - Clean(decisionCycleEvents); - Clean(consolidationPoiEvents); - Clean(consolidationCycleEvents); - - // - visionState.Clean(); - analyseState.Clean(); - decisionZBar.Clean(); - decisionCBar.Clean(); - decisionPBar.Clean(); - decisionState.Clean(); - visionConditions.Clean(); - analyseConditions.Clean(); - visionXConditions.Clean(); - consolidationState.Clean(); - decisionConditions.Clean(); - analyseXConditions.Clean(); - decisionXConditions.Clean(); - consolidationConditions.Clean(); - consolidationXConditions.Clean(); - - // - return result; - } - - // - decisionCBarBullishZoneChechValue = decisionCBar - .GetZoneCheckValue(X_DIRECTION_BULLISH); - decisionCBarBearishZoneChechValue = decisionCBar - .GetZoneCheckValue(X_DIRECTION_BEARISH); - - // - mConditions.UpdateTo(); - - // - // 1- Detect Valid Working Area ... - - // - bool hasVisionHighestSupplyZone = mConditions.HasVisionHighestSupplyZone(); - bool hasConsolidationHighestSupplyZone = mConditions.HasConsolidationHighestSupplyZone(); - - // - bool hasVisionLowestDemandZone = mConditions.HasVisionLowestDemandZone(); - bool hasConsolidationLowestDemandZone = mConditions.HasConsolidationLowestDemandZone(); - - // - bool hasWorkingZone = mConditions.workingZone.IsValid(); - - // - bool isDestroyed = false; - ENUM_X_DIRECTION destroyedDir; - - // - XOHCL trendStartBar; - ENUM_X_DIRECTION trendDir; - bool hasTrend = false; - bool hasBullishTrend = false; - bool hasBearishTrend = false; - - // - if (!hasVisionHighestSupplyZone) - { - // - int hasZones = visionState.HasSupplyZones(); - int zonesCount = visionState.HasSupplyZones(); - - // - if (hasZones) - { - // - int idx = GetHighest(visionState.supplyZones); - hasVisionHighestSupplyZone = IsValidIndex(idx); - if (hasVisionHighestSupplyZone) - { - // - // Validate Zone ... - XCSupplyZone *zone = visionState.supplyZones[idx]; - bool isBelow = IsBelow( - decisionCBarBearishZoneChechValue, - zone // - ); - if (isBelow) - { - mConditions.visionHighestSupplyZone = zone; - } - } - } - - // - hasVisionHighestSupplyZone = mConditions.HasVisionHighestSupplyZone(); - } - - // - if (!hasVisionLowestDemandZone) - { - // - int hasZones = visionState.HasDemandZones(); - int zonesCount = visionState.HasDemandZones(); - - // - if (hasZones) - { - // - int idx = GetLowest(visionState.demandZones); - hasVisionLowestDemandZone = IsValidIndex(idx); - if (hasVisionLowestDemandZone) - { - // - // Validate Zone ... - XCDemandZone *zone = visionState.demandZones[idx]; - bool isAbove = IsAbove( - decisionCBarBullishZoneChechValue, - zone // - ); - if (isAbove) - { - mConditions.visionLowestDemandZone = zone; - } - } - } - - // - hasVisionLowestDemandZone = mConditions.HasVisionLowestDemandZone(); - } - - // - if (!hasConsolidationHighestSupplyZone) - { - // - int hasZones = consolidationState.HasSupplyZones(); - int zonesCount = consolidationState.HasSupplyZones(); - - // - if (hasZones) - { - // - int idx = GetHighest(consolidationState.supplyZones); - hasConsolidationHighestSupplyZone = IsValidIndex(idx); - if (hasConsolidationHighestSupplyZone) - { - // - // Validate Zone ... - XCSupplyZone *zone = consolidationState.supplyZones[idx]; - bool isBelow = IsBelow( - decisionCBarBearishZoneChechValue, - zone // - ); - if (isBelow) - { - // - if (mConditions.workingZone.IsValid()) - { - // - RemoveDraws(); - result = false; - mConditions.Clean(); - RemoveWorkingZoneDraws(); - - // - return result; - } - - // - mConditions.consolidationHighestSupplyZone = zone; - } - } - } - - // - hasConsolidationHighestSupplyZone = mConditions.HasConsolidationHighestSupplyZone(); - } - - // - if (!hasConsolidationLowestDemandZone) - { - // - int hasZones = consolidationState.HasDemandZones(); - int zonesCount = consolidationState.HasDemandZones(); - - // - if (hasZones) - { - // - int idx = GetLowest(consolidationState.demandZones); - hasConsolidationLowestDemandZone = IsValidIndex(idx); - if (hasConsolidationLowestDemandZone) - { - // - // Validate Zone ... - XCDemandZone *zone = consolidationState.demandZones[idx]; - bool isAbove = IsAbove( - decisionCBarBullishZoneChechValue, - zone // - ); - if (isAbove) - { - // - if (mConditions.workingZone.IsValid()) - { - // - RemoveDraws(); - result = false; - mConditions.Clean(); - RemoveWorkingZoneDraws(); - - // - return result; - } - - // - mConditions.consolidationLowestDemandZone = zone; - } - } - } - - // - hasConsolidationLowestDemandZone = mConditions.HasConsolidationLowestDemandZone(); - } - - // - // 2- Detect Working Zone ... - if (!hasWorkingZone) - { - hasWorkingZone = mConditions.ExtractWorkingZone(); - } - - // - // Here we Can Detect Price Inside SupDem Zones ... - - // - bool isPriceInsideSupplyZone = false; - bool isPriceInsideDemandZone = false; - bool isPriceInsideVisionSupplyZone = false; - bool isPriceInsideVisionDemandZone = false; - bool isPriceInsideConsolidationSupplyZone = false; - bool isPriceInsideConsolidationDemandZone = false; - if (hasVisionLowestDemandZone) - { - // - double iUpper = mConditions.visionLowestDemandZone.Upper(); - double iLower = mConditions.visionLowestDemandZone.Lower(); - - // - isPriceInsideVisionDemandZone = - // - decisionZBar.high < iUpper && - decisionCBar.high < iUpper && - // - decisionZBar.low > iLower && - decisionCBar.low > iLower - // - ; - } - if (hasVisionHighestSupplyZone) - { - // - double iUpper = mConditions.visionHighestSupplyZone.Upper(); - double iLower = mConditions.visionHighestSupplyZone.Lower(); - - // - isPriceInsideVisionSupplyZone = - // - decisionZBar.high < iUpper && - decisionCBar.high < iUpper && - // - decisionZBar.low > iLower && - decisionCBar.low > iLower - // - ; - } - if (hasConsolidationLowestDemandZone) - { - // - double iUpper = mConditions.consolidationLowestDemandZone.Upper(); - double iLower = mConditions.consolidationLowestDemandZone.Lower(); - - // - isPriceInsideConsolidationDemandZone = - // - decisionZBar.high < iUpper && - decisionCBar.high < iUpper && - // - decisionZBar.low > iLower && - decisionCBar.low > iLower - // - ; - } - if (hasConsolidationHighestSupplyZone) - { - // - double iUpper = mConditions.consolidationHighestSupplyZone.Upper(); - double iLower = mConditions.consolidationHighestSupplyZone.Lower(); - - // - isPriceInsideConsolidationSupplyZone = - // - decisionZBar.high < iUpper && - decisionCBar.high < iUpper && - // - decisionZBar.low > iLower && - decisionCBar.low > iLower - // - ; - } - - // - isPriceInsideSupplyZone = isPriceInsideVisionSupplyZone || - isPriceInsideConsolidationSupplyZone; - if (isPriceInsideSupplyZone) - { - // - if (isPriceInsideVisionSupplyZone) - { - mConditions.insideSupplyZone = mConditions.visionHighestSupplyZone; - } - else if (isPriceInsideConsolidationSupplyZone) - { - mConditions.insideSupplyZone = mConditions.consolidationHighestSupplyZone; - } - } - - // - isPriceInsideDemandZone = isPriceInsideVisionDemandZone || - isPriceInsideConsolidationDemandZone; - if (isPriceInsideDemandZone) - { - // - if (isPriceInsideVisionDemandZone) - { - mConditions.insideDemandZone = mConditions.visionLowestDemandZone; - } - else if (isPriceInsideConsolidationDemandZone) - { - mConditions.insideDemandZone = mConditions.consolidationLowestDemandZone; - } - } - - // - // Check Working Zone Destroy ... - isDestroyed = mConditions.IsWorkingZoneDestroyed( - destroyedDir, // Direction ... - 0, // Bar Index ... - decisionState.period // Period ... - ); - if (isDestroyed) - { - // - Clean(visionPoiEvents); - Clean(analysePoiEvents); - Clean(decisionPoiEvents); - Clean(visionCycleEvents); - Clean(analyseCycleEvents); - Clean(decisionCycleEvents); - Clean(consolidationPoiEvents); - Clean(consolidationCycleEvents); - - // - visionState.Clean(); - analyseState.Clean(); - decisionZBar.Clean(); - decisionCBar.Clean(); - decisionPBar.Clean(); - decisionState.Clean(); - visionConditions.Clean(); - analyseConditions.Clean(); - visionXConditions.Clean(); - consolidationState.Clean(); - decisionConditions.Clean(); - analyseXConditions.Clean(); - decisionXConditions.Clean(); - consolidationConditions.Clean(); - consolidationXConditions.Clean(); - - // - result = false; - mConditions.Clean(); - RemoveDraws(); - RemoveWorkingZoneDraws(); - - // - return result; - } - - // - // 2- Detect Market Trend Based On Nearest Zone Hunting ... - hasTrend = mConditions.DetectOveralTrend( - trendStartBar, - trendDir, - 0 // - ); - hasBullishTrend = IsBullish(trendDir); - hasBearishTrend = IsBearish(trendDir); - - // - result = hasTrend; - if (!result) - { - // - Clean(visionPoiEvents); - Clean(analysePoiEvents); - Clean(decisionPoiEvents); - Clean(visionCycleEvents); - Clean(analyseCycleEvents); - Clean(decisionCycleEvents); - Clean(consolidationPoiEvents); - Clean(consolidationCycleEvents); - - // - visionState.Clean(); - analyseState.Clean(); - decisionZBar.Clean(); - decisionCBar.Clean(); - decisionPBar.Clean(); - decisionState.Clean(); - visionConditions.Clean(); - analyseConditions.Clean(); - visionXConditions.Clean(); - consolidationState.Clean(); - decisionConditions.Clean(); - analyseXConditions.Clean(); - decisionXConditions.Clean(); - consolidationConditions.Clean(); - consolidationXConditions.Clean(); - - // - RemoveDraws(); - RemoveWorkingZoneDraws(); - - // - return result; - } - - // - // 3- Checking Price Inside Valid Quarters Based on Trend ... - - // - // in Bullish Trend: - // ----------------------------- - // - if Price Under Lower: HIGH; - // - if Price Under Quarter 3 and Above Lower: REGULAR; - // - if Price Under Quarter 2 and Above Quarter 3: LOW; - // - if Price Above Quarter 2: NONE; - - // - // in Bearish Trend: - // ----------------------------- - // - if Price Above Upper: HIGH; - // - if Price Above Quarter 1 and Below Upper: REGULAR; - // - if Price Above Quarter 2 and Below Quarter 1: LOW; - // - if Price Below Quarter 2: NONE; - - // - ENUM_X121SMC_XSUPDEMOBS_PRIORITY bullishPriority = X121SMC_XSUPDEMOBS_PRIORITY_NONE; - ENUM_X121SMC_XSUPDEMOBS_PRIORITY bearishPriority = X121SMC_XSUPDEMOBS_PRIORITY_NONE; - - // - bool isInQuarter0 = CheckPriceInside( - decisionZBar, - decisionCBar, - mConditions.workingZone.zoneUpper, - mConditions.workingZone.upper // - ); - bool isInQuarter1 = CheckPriceInside( - decisionZBar, - decisionCBar, - mConditions.workingZone.upper, - mConditions.workingZone.quarter1 // - ); - bool isInQuarter2 = CheckPriceInside( - decisionZBar, - decisionCBar, - mConditions.workingZone.quarter1, - mConditions.workingZone.quarter2 // - ); - bool isInQuarter3 = CheckPriceInside( - decisionZBar, - decisionCBar, - mConditions.workingZone.quarter2, - mConditions.workingZone.quarter3 // - ); - bool isInQuarter4 = CheckPriceInside( - decisionZBar, - decisionCBar, - mConditions.workingZone.quarter3, - mConditions.workingZone.lower // - ); - bool isInQuarter5 = CheckPriceInside( - decisionZBar, - decisionCBar, - mConditions.workingZone.lower, - mConditions.workingZone.zoneLower // - ); - - // - if (isInQuarter0) - { - // - bullishPriority = X121SMC_XSUPDEMOBS_PRIORITY_NONE; - bearishPriority = X121SMC_XSUPDEMOBS_PRIORITY_HIGH; - } - else if (isInQuarter1) - { - // - bullishPriority = X121SMC_XSUPDEMOBS_PRIORITY_NONE; - bearishPriority = X121SMC_XSUPDEMOBS_PRIORITY_REGULAR; - } - else if (isInQuarter2) - { - // - bullishPriority = X121SMC_XSUPDEMOBS_PRIORITY_WEAK; - bearishPriority = X121SMC_XSUPDEMOBS_PRIORITY_LOW; - } - else if (isInQuarter3) - { - // - bullishPriority = X121SMC_XSUPDEMOBS_PRIORITY_LOW; - bearishPriority = X121SMC_XSUPDEMOBS_PRIORITY_WEAK; - } - else if (isInQuarter4) - { - // - bullishPriority = X121SMC_XSUPDEMOBS_PRIORITY_REGULAR; - bearishPriority = X121SMC_XSUPDEMOBS_PRIORITY_NONE; - } - else if (isInQuarter5) - { - // - bullishPriority = X121SMC_XSUPDEMOBS_PRIORITY_HIGH; - bearishPriority = X121SMC_XSUPDEMOBS_PRIORITY_NONE; - } - - // - bool lookingForLong = bullishPriority != X121SMC_XSUPDEMOBS_PRIORITY_NONE; - bool lookingForShort = bearishPriority != X121SMC_XSUPDEMOBS_PRIORITY_NONE; - - // - result = lookingForLong || - lookingForShort; - if (!result) - { - // - Clean(visionPoiEvents); - Clean(analysePoiEvents); - Clean(visionCycleEvents); - Clean(decisionPoiEvents); - Clean(analyseCycleEvents); - Clean(decisionCycleEvents); - Clean(consolidationPoiEvents); - Clean(consolidationCycleEvents); - - // - visionState.Clean(); - analyseState.Clean(); - decisionZBar.Clean(); - decisionCBar.Clean(); - decisionPBar.Clean(); - decisionState.Clean(); - visionConditions.Clean(); - analyseConditions.Clean(); - visionXConditions.Clean(); - consolidationState.Clean(); - decisionConditions.Clean(); - analyseXConditions.Clean(); - decisionXConditions.Clean(); - consolidationConditions.Clean(); - consolidationXConditions.Clean(); - - // - RemoveDraws(); - RemoveWorkingZoneDraws(); - - // - return result; - } - - // - // Detect Order Blocks in Direction of Trend ... - XCOrderBlock *obs[]; - Copy( - consolidationState.bullishOrderBlocks, - obs // - ); - Copy( - consolidationState.bearishOrderBlocks, - obs // - ); - - // - // Validate OB FVG ... - XCFVG *fvgs[]; - Copy( - analyseState.bullishFairValueGaps, - fvgs // - ); - Copy( - analyseState.bearishFairValueGaps, - fvgs // - ); - - // - int obsCount = ArraySize(obs); - bool hasOBs = IsValidSize(obsCount); - - // - int fvgsCount = ArraySize(fvgs); - bool hasFVGs = IsValidSize(fvgsCount); - - // - bool hasOBFVGs = mConditions.HasOBFVGs(); - int obFVGsCount = mConditions.CountOBFVGs(); - - // - if (hasOBs && - hasFVGs && - !hasOBFVGs) - { - // - for (int i = 0; i < obsCount; i++) - { - // - XCOrderBlock *iOB = obs[i]; - - // - // Check Ob Index inside OB FVGS ... - bool isOBFVGExists = false; - hasOBFVGs = mConditions.HasOBFVGs(); - obFVGsCount = mConditions.CountOBFVGs(); - if (hasOBFVGs) - { - // - for (int j = 0; j < obFVGsCount; j++) - { - // - bool isSame = IsSame( - mConditions.obFVGs[j].ob, - iOB // - ); - - // - if (isSame) - { - // - isOBFVGExists = true; - break; - } - } - } - if (isOBFVGExists) - { - continue; - } - - // - for (int j = 0; j < fvgsCount; j++) - { - // - XCFVG *jFVG = fvgs[j]; - - // - ENUM_TIMEFRAMES jPeriod = jFVG.GetPeriod(); - if (jPeriod != PERIOD_M15) - { - Print(ToString(jPeriod)); - } - - // - XOBFVG iOBFVG; - - // - iOBFVG.time = cTime; - iOBFVG.symbol = iOB.GetSymbol(); - iOBFVG.period = iOB.GetPeriod(); - - // - iOBFVG.ob = iOB; - iOBFVG.fvg = jFVG; - - // - bool isValidOBFVG = iOBFVG.IsValid(); - if (isValidOBFVG) - { - // - AddRef( - iOBFVG, - mConditions.obFVGs // - ); - - // - iOBFVG.Clean(); - - // - break; - } - - // - iOBFVG.Clean(); - } - } - - // - hasOBFVGs = mConditions.HasOBFVGs(); - obFVGsCount = mConditions.CountOBFVGs(); - } - - // - // Now We Have to Check OBFVGs ... - result = hasOBFVGs; - if (!result) - { - // - Clean(obs); - Clean(fvgs); - - // - Clean(visionPoiEvents); - Clean(analysePoiEvents); - Clean(decisionPoiEvents); - Clean(visionCycleEvents); - Clean(analyseCycleEvents); - Clean(decisionCycleEvents); - Clean(consolidationPoiEvents); - Clean(consolidationCycleEvents); - - // - visionState.Clean(); - analyseState.Clean(); - decisionZBar.Clean(); - decisionCBar.Clean(); - decisionPBar.Clean(); - decisionState.Clean(); - visionConditions.Clean(); - analyseConditions.Clean(); - visionXConditions.Clean(); - consolidationState.Clean(); - decisionConditions.Clean(); - analyseXConditions.Clean(); - decisionXConditions.Clean(); - consolidationConditions.Clean(); - consolidationXConditions.Clean(); - - // - RemoveDraws(); - RemoveWorkingZoneDraws(); - - // - return result; - } - - // - // Detect Un Activated POI(s) ... - // including: - // - Order Blocks; - // - Fair Value Gaps; - - // - bool hasUnActivatedOBs = false; - bool hasUnActivatedFVGs = false; - for (int i = 0; i < obFVGsCount; i++) - { - // - bool iHasUnActivatedOBs = mConditions.obFVGs[i].HasUnActivatedOBs(); - bool iHasUnActivatedFVGs = mConditions.obFVGs[i].HasUnActivatedFVGs(); - - // - if (hasOBs) - { - // - for (int j = 0; j < obsCount; j++) - { - mConditions.obFVGs[i].AddUnActivatedOB( - obs[j], - decisionZBar // - ); - } - - // - iHasUnActivatedOBs = mConditions.obFVGs[i].HasUnActivatedOBs(); - } - - // - if (hasFVGs) - { - // - for (int j = 0; j < fvgsCount; j++) - { - mConditions.obFVGs[i].AddUnActivatedFVG( - fvgs[j], - decisionZBar // - ); - } - - // - iHasUnActivatedFVGs = mConditions.obFVGs[i].HasUnActivatedFVGs(); - } - - // - if (iHasUnActivatedOBs && - !hasUnActivatedOBs) - { - hasUnActivatedOBs = iHasUnActivatedOBs; - } - - // - if (iHasUnActivatedFVGs && - !hasUnActivatedFVGs) - { - hasUnActivatedFVGs = iHasUnActivatedFVGs; - } - } - - // - result = - (isPriceInsideSupplyZone || - isPriceInsideDemandZone) - ? true - : (hasUnActivatedOBs || - hasUnActivatedFVGs); - if (!result) - { - // - Clean(obs); - Clean(fvgs); - - // - Clean(visionPoiEvents); - Clean(analysePoiEvents); - Clean(visionCycleEvents); - Clean(decisionPoiEvents); - Clean(analyseCycleEvents); - Clean(decisionCycleEvents); - Clean(consolidationPoiEvents); - Clean(consolidationCycleEvents); - - // - visionState.Clean(); - analyseState.Clean(); - decisionZBar.Clean(); - decisionCBar.Clean(); - decisionPBar.Clean(); - decisionState.Clean(); - visionConditions.Clean(); - analyseConditions.Clean(); - visionXConditions.Clean(); - consolidationState.Clean(); - decisionConditions.Clean(); - analyseXConditions.Clean(); - decisionXConditions.Clean(); - consolidationConditions.Clean(); - consolidationXConditions.Clean(); - - // - RemoveDraws(); - RemoveWorkingZoneDraws(); - - // - return result; - } - - // - // Now We Have to Wait for Price Inside Box ... - - // - XOHCL swingBar; - XOHCL rejectBar; - XOHCL breakerBar; - XOHCL momentumBar; - bool isPriceRejected = false; - XCFVG *insideFVG = mConditions.insideFVG; - XCFVG *rejectedFVG = mConditions.rejectedFVG; - XCOrderBlock *insideOB = mConditions.insideOB; - XCOrderBlock *rejectedOB = mConditions.rejectedOB; - XCSupplyZone *insideSupplyZone = mConditions.insideSupplyZone; - XCDemandZone *insideDemandZone = mConditions.insideDemandZone; - - // - bool hasInsideOB = insideOB != NULL && - insideOB.IsValid(); - bool hasInsideFVG = insideFVG != NULL && - insideFVG.IsValid(); - bool hasInsideZone = hasInsideOB || - hasInsideFVG; - bool hasRejectedOB = rejectedOB != NULL && - rejectedOB.IsValid(); - bool hasRejectedFVG = rejectedFVG != NULL && - rejectedFVG.IsValid(); - bool hasRejectedZone = hasRejectedOB || - hasRejectedFVG; - bool hasInsideSupplyZone = insideSupplyZone != NULL && - insideSupplyZone.IsValid(); - bool hasInsideDemandZone = insideDemandZone != NULL && - insideDemandZone.IsValid(); - bool hasInsideSupDemZone = hasInsideSupplyZone || - hasInsideDemandZone; - if (!hasInsideZone) - { - // - for (int i = 0; i < obFVGsCount; i++) - { - // - bool iOBFVGHasUnActivatedOBs = mConditions.obFVGs[i].HasUnActivatedOBs(); - int iOBFVGUnActivatedOBsCount = mConditions.obFVGs[i].CountUnActivatedOBs(); - - // - bool iOBFVGHasUnActivatedFVGs = mConditions.obFVGs[i].HasUnActivatedFVGs(); - int iOBFVGUnActivatedFVGsCount = mConditions.obFVGs[i].CountUnActivatedFVGs(); - - // - // Detect Inside Zones ... - - // - if (!hasInsideOB && - iOBFVGHasUnActivatedOBs) - { - // - int idx = -1; - for (int j = 0; j < iOBFVGUnActivatedOBsCount; j++) - { - // - ENUM_X_DIRECTION iForDir = mConditions.obFVGs[i].unActivatedOBs[j].GetDirection(); - bool isIBullish = IsBullish(iForDir); - - // - bool isInsideFromUpper = IsInside( - decisionZBar.low, - mConditions.obFVGs[i].unActivatedOBs[j] // - ); - bool isInsideFromLower = IsInside( - decisionZBar.high, - mConditions.obFVGs[i].unActivatedOBs[j] // - ); - - // - bool isInside = - isBullish - ? isInsideFromUpper - : isInsideFromLower; - if (isInside) - { - // - idx = j; - insideOB = mConditions.obFVGs[i].unActivatedOBs[j]; - mConditions.insideOB = insideOB; - break; - } - } - - // - if (IsValidIndex(idx)) - { - // - ArrayRemove( - mConditions.obFVGs[i].unActivatedOBs, - idx, - 1 // - ); - } - } - - // - if (insideOB == NULL && - !hasInsideFVG && - iOBFVGHasUnActivatedFVGs) - { - // - int idx = -1; - for (int j = 0; j < iOBFVGUnActivatedFVGsCount; j++) - { - // - ENUM_X_DIRECTION iForDir = mConditions.obFVGs[i].unActivatedFVGs[j].GetDirection(); - bool isIBullish = IsBullish(iForDir); - - // - bool isInsideFromUpper = IsInside( - decisionZBar.low, - mConditions.obFVGs[i].unActivatedFVGs[j] // - ); - bool isInsideFromLower = IsInside( - decisionZBar.high, - mConditions.obFVGs[i].unActivatedFVGs[j] // - ); - - // - bool isInside = - isBullish - ? isInsideFromUpper - : isInsideFromLower; - if (isInside) - { - // - idx = j; - insideFVG = mConditions.obFVGs[i].unActivatedFVGs[j]; - mConditions.insideFVG = insideFVG; - break; - } - } - - // - if (IsValidIndex(idx)) - { - // - ArrayRemove( - mConditions.obFVGs[i].unActivatedFVGs, - idx, - 1 // - ); - } - } - } - - // - hasInsideOB = insideOB != NULL && - insideOB.IsValid(); - hasInsideFVG = insideFVG != NULL && - insideFVG.IsValid(); - hasInsideZone = hasInsideOB || - hasInsideFVG; - - // - // Here Detect Inside or Rejected Zones inside Supply and Demand Zones ... - // For Using them for Positions ... - if (!hasInsideZone && - hasInsideSupDemZone) - { - // - ENUM_X_DIRECTION forDir = - hasInsideSupplyZone - ? X_DIRECTION_BEARISH - : X_DIRECTION_BULLISH; - - // - bool isLookingForBullish = IsBullish(forDir); - - // - XCFVG *fvgs[]; - XCOrderBlock *obs[]; - int obsCount = 0; - int fvgsCount = 0; - bool hasOBs = false; - bool hasFVGs = false; - - // - if (isLookingForBullish) - { - // - Copy( - analyseState.bullishOrderBlocks, - obs // - ); - FilterZones( - insideDemandZone, - obs, - true, // Filter Direction ... - true, // Filter From ... - true, // Filter Price ... - true, // Ignore Out of Box ... - true, // Apply Sort ... - true // Ignore Inside ... - ); - - // - Copy( - analyseState.bullishFairValueGaps, - fvgs // - ); - FilterZones( - insideDemandZone, - fvgs, - true, // Filter Direction ... - true, // Filter From ... - true, // Filter Price ... - true, // Ignore Out of Box ... - true, // Apply Sort ... - true // Ignore Inside ... - ); - } - else - { - // - Copy( - analyseState.bearishOrderBlocks, - obs // - ); - FilterZones( - insideSupplyZone, - obs, - true, // Filter Direction ... - true, // Filter From ... - true, // Filter Price ... - false, // Ignore Out of Box ... - true, // Apply Sort ... - true // Ignore Inside ... - ); - - // - Copy( - analyseState.bearishFairValueGaps, - fvgs // - ); - FilterZones( - insideSupplyZone, - fvgs, - true, // Filter Direction ... - true, // Filter From ... - true, // Filter Price ... - false, // Ignore Out of Box ... - true, // Apply Sort ... - true // Ignore Inside ... - ); - } - - // - obsCount = ArraySize(obs); - fvgsCount = ArraySize(fvgs); - - // - hasOBs = IsValidSize(obsCount); - hasFVGs = IsValidSize(fvgsCount); - - // - if (hasOBs || - hasFVGs) - { - // - if (hasOBs) - { - // - for (int i = 0; i < obsCount; i++) - { - // - ENUM_X_DIRECTION iForDir = obs[i].GetDirection(); - bool isIBullish = IsBullish(iForDir); - - // - isPriceRejected = false; - // IsReject( - // iForDir, - // decisionZBar, - // obs[i], - // decisionState, - // swingBar, - // rejectBar, - // breakerBar, - // momentumBar, - // false // - // ); - if (isPriceRejected) - { - // - rejectedOB = obs[i]; - mConditions.rejectedOB = rejectedOB; - } - - // - bool isInsideFromUpper = IsInside( - decisionZBar.low, - obs[i] // - ); - bool isInsideFromLower = IsInside( - decisionZBar.high, - obs[i] // - ); - - // - bool isInside = - isBullish - ? isInsideFromUpper - : isInsideFromLower; - if (isInside) - { - // - insideOB = obs[i]; - mConditions.insideOB = obs[i]; - break; - } - } - } - - // - hasInsideOB = insideOB != NULL && - insideOB.IsValid(); - // - hasRejectedOB = rejectedOB != NULL && - rejectedOB.IsValid(); - - // - if (hasFVGs && - !hasInsideOB && - !hasRejectedOB) - { - // - for (int i = 0; i < fvgsCount; i++) - { - // - ENUM_X_DIRECTION iForDir = fvgs[i].GetDirection(); - bool isIBullish = IsBullish(iForDir); - - // - isPriceRejected = false; - // IsReject( - // iForDir, - // decisionZBar, - // fvgs[i], - // decisionState, - // swingBar, - // rejectBar, - // breakerBar, - // momentumBar, - // false // - // ); - if (isPriceRejected) - { - // - rejectedFVG = fvgs[i]; - mConditions.rejectedFVG = rejectedFVG; - } - - // - bool isInsideFromUpper = IsInside( - decisionZBar.low, - fvgs[i] // - ); - bool isInsideFromLower = IsInside( - decisionZBar.high, - fvgs[i] // - ); - - // - bool isInside = - isBullish - ? isInsideFromUpper - : isInsideFromLower; - if (isInside) - { - // - insideFVG = fvgs[i]; - mConditions.insideFVG = fvgs[i]; - break; - } - } - } - } - - // - Clean(obs); - Clean(fvgs); - } - - // - mConditions.UpdateTo(cTime); - - // - hasInsideOB = insideOB != NULL && - insideOB.IsValid(); - hasInsideFVG = insideFVG != NULL && - insideFVG.IsValid(); - hasInsideZone = hasInsideOB || - hasInsideFVG; - - // - hasRejectedOB = rejectedOB != NULL && - rejectedOB.IsValid(); - hasRejectedFVG = rejectedFVG != NULL && - rejectedFVG.IsValid(); - hasRejectedZone = hasRejectedOB || - hasRejectedFVG; - - // - if (hasInsideSupDemZone && - (hasInsideZone || - hasRejectedZone)) - { - // - RemoveDraws(); - RemoveWorkingZoneDraws(); - - // - // Set Target Based On Supply or Demand Zone ... - - // - // Supply Zone ... - if (isPriceInsideSupplyZone) - { - target = mConditions.workingZone.quarter1; - } - - // - // Demand Zone ... - if (isPriceInsideDemandZone) - { - target = mConditions.workingZone.quarter3; - } - } - } - - // - result = hasInsideZone || - hasRejectedZone; - if (!result) - { - // - decisionZBar.Clean(); - decisionCBar.Clean(); - decisionPBar.Clean(); - - // - swingBar.Clean(); - rejectBar.Clean(); - breakerBar.Clean(); - momentumBar.Clean(); - - // - Clean(obs); - Clean(fvgs); - - // - 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(); - consolidationState.Clean(); - decisionConditions.Clean(); - analyseXConditions.Clean(); - decisionXConditions.Clean(); - consolidationConditions.Clean(); - consolidationXConditions.Clean(); - - // - ZeroMemory(insideOB); - ZeroMemory(insideFVG); - ZeroMemory(rejectedOB); - ZeroMemory(rejectedFVG); - ZeroMemory(insideSupplyZone); - ZeroMemory(insideDemandZone); - - // - return result; - } - - // - // Waiting for Price Breakes Inside Zone ... - - // - double upper = 0; - double lower = 0; - bool isInsideZoneDirectionBullish = false; - bool isInsideZoneDirectionBearish = false; - - // - if (hasInsideOB) - { - // - upper = insideOB.Upper(); - lower = insideOB.Lower(); - - // - isInsideZoneDirectionBullish = insideOB.IsBullish(); - isInsideZoneDirectionBearish = insideOB.IsBearish(); - } - else if (hasInsideFVG) - { - // - upper = insideFVG.Upper(); - lower = insideFVG.Lower(); - - // - isInsideZoneDirectionBullish = insideFVG.IsBullish(); - isInsideZoneDirectionBearish = insideFVG.IsBearish(); - } - - // - // Cleanup Unused Objects ... - // - decisionZBar.Clean(); - decisionCBar.Clean(); - decisionPBar.Clean(); - - // - ZeroMemory(insideOB); - ZeroMemory(insideFVG); - ZeroMemory(rejectedOB); - ZeroMemory(rejectedFVG); - ZeroMemory(insideSupplyZone); - ZeroMemory(insideDemandZone); - - // - Clean(visionPoiEvents); - Clean(analysePoiEvents); - Clean(visionCycleEvents); - Clean(decisionPoiEvents); - Clean(analyseCycleEvents); - Clean(decisionCycleEvents); - Clean(consolidationPoiEvents); - Clean(consolidationCycleEvents); - - // - visionState.Clean(); - analyseState.Clean(); - decisionZBar.Clean(); - decisionCBar.Clean(); - decisionPBar.Clean(); - decisionState.Clean(); - visionConditions.Clean(); - analyseConditions.Clean(); - visionXConditions.Clean(); - consolidationState.Clean(); - decisionConditions.Clean(); - analyseXConditions.Clean(); - decisionXConditions.Clean(); - consolidationConditions.Clean(); - consolidationXConditions.Clean(); - - // - // Summarize Conditions ... - - // - bool isCondition1Bullish = - // - hasBullishTrend && - isInsideZoneDirectionBullish && - bullishPriority != X121SMC_XSUPDEMOBS_PRIORITY_NONE - // - ; - - // - bool isCondition1Bearish = - // - hasBearishTrend && - isInsideZoneDirectionBearish && - bearishPriority != X121SMC_XSUPDEMOBS_PRIORITY_NONE - // - ; - - // - bool hasCondition1 = isCondition1Bullish || - isCondition1Bearish; - if (hasCondition1) - { - // - ENUM_X_DIRECTION pzDir = - isCondition1Bullish - ? X_DIRECTION_BULLISH - : X_DIRECTION_BEARISH; - - // - double point = GetEntry( - mConditions.symbol, - pzDir // - ); - - // - double longPivot = lower; // triggerXConditions.valesBuffer[1]; - double shortPivot = upper; // triggerXConditions.peaksBuffer[1]; - - // - // Manipulate Conditions Point ... - - // - mConditions.point = - isCondition1Bullish - ? shortPivot - : longPivot; - - // - // Manipulate Conditions Pivot ... - - // - mConditions.pivot = - isCondition1Bullish - ? longPivot - : shortPivot; - } - - // - // Summarize Conditions ... - // - - // - isBullish = - // - isCondition1Bullish - // - ; - - // - isBearish = - // - isCondition1Bearish - // - ; - - // - result = isBullish || - isBearish; - if (!result) - { - return result; - } - - // - double reward; - double amountPercent; - ENUM_X121SMC_XSUPDEMOBS_PRIORITY priority = - isBullish - ? bullishPriority - : bearishPriority; - bool hasRewardAmount = CalculateRiskReward( - priority, - reward, - amountPercent // - ); - result = hasRewardAmount; - if (!result) - { - return result; - } - - // - mConditions.setupTime = cTime; - mConditions.dir = - isBullish - ? X_DIRECTION_BULLISH - : X_DIRECTION_BEARISH; - - // - mConditions.reward = reward; - mConditions.target = target; - mConditions.priority = priority; - mConditions.amountPercent = amountPercent; - - // - swingBar.Clean(); - rejectBar.Clean(); - breakerBar.Clean(); - momentumBar.Clean(); - - // - return result; - } - - // - // Detect Trigger Conditions ... - bool DetectSignalTrigger( - // - X121SMCStrategyXSupDemOBSSignalConditions &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; - - // - string symbol = _symbol; - ENUM_TIMEFRAMES period = _period; - - // - XOHCL zBar; - result = decisionCycleHelper.GetBar( - zBar, - zIndex // - ); - if (!result) - { - return result; - } - - // - XOHCL cBar; - result = decisionCycleHelper.GetBar( - cBar, - cIndex // - ); - if (!result) - { - return result; - } - - // - XOHCL pBar; - result = decisionCycleHelper.GetBar( - pBar, - pIndex // - ); - if (!result) - { - return result; - } - - // - double ask = GetAsk(symbol); - double bid = GetBid(symbol); - datetime cTime = TimeCurrent(); - double points = GetPoints(symbol); - - // - int swingLoopback = 9; - double ll = cBar.FindLowest(swingLoopback, MODE_LOW); - double hh = cBar.FindHighest(swingLoopback, MODE_HIGH); - double llDown = cBar.FindLowesttDown(swingLoopback); - double hhUp = cBar.FindHighestUp(swingLoopback); - - // - // 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 ... - zBar.Clean(); - cBar.Clean(); - pBar.Clean(); - - // - Clean(decisionPoiEvents); - Clean(decisionCycleEvents); - - // - decisionConditions.Clean(); - - // - return result; - } - - // - // Cycles POI States ... - XPOIState decisionState = decisionConditions.state; - - // - // Cycle X121Conditions ... - X121Conditions decisionXConditions = decisionConditions.x121Conditions; - - // - // Trigger Conditions ... - - // - double point = conditions.point; - bool isPointBreaked = IsBarBreak( - point, - setupDir, - cBar // - ); - - // - // Summary ... - - // - isBullish = - // - isBullish && - isPointBreaked - // - ; - - // - isBearish = - // - isBearish && - isPointBreaked - // - ; - - // - result = isBullish || - isBearish; - if (!result) - { - // - // Cleanup Setup Conditions ... - int setupAge = conditions.GetSetupAge(); - if (IsValidSize(setupAge) && - IsValidSize(maxAllowedSetupAge) && - setupAge >= maxAllowedSetupAge) - { - conditions.Clean(); - } - - // - // Cleanup ... - zBar.Clean(); - cBar.Clean(); - pBar.Clean(); - - // - Clean(decisionPoiEvents); - Clean(decisionCycleEvents); - - // - decisionState.Clean(); - decisionConditions.Clean(); - decisionXConditions.Clean(); - - // - return result; - } - - // - // Detect Nearest Pivot Point ... - - // - double entry = GetEntry( - conditions.symbol, - setupDir // - ); - - // - // Manipulate SL Based on Consolidation Zones ... - XConsolidationZone cZone; - bool hasCZone = decisionCycleHelper.GetActiveConsolidationZone(cZone); - bool hasCZones = decisionCycleHelper.HasConsolidationZones(); - int cZonesCount = decisionCycleHelper.CountConsolidationZones(); - if (!hasCZone && - hasCZones) - { - // - hasCZone = decisionCycleHelper.GetLastDirectionalConsolidationZone( - conditions.dir, - cZone // - ); - } - - // - double sls[]; - Add( - conditions.pivot, - sls // - ); - - // - if (hasCZone) - { - // - conditions.consolidationZone = cZone; - - // - if (isBullish) - { - // - Add( - cZone.lower, - sls // - ); - } - else - { - // - Add( - cZone.upper, - sls // - ); - } - } - - // - double iAtr = decisionXConditions.atrBuffer[1]; - iAtr *= 2; - - // - 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; - - // - // Cleanup ... - zBar.Clean(); - cBar.Clean(); - pBar.Clean(); - - // - Clean(decisionPoiEvents); - Clean(decisionCycleEvents); - - // - decisionState.Clean(); - decisionConditions.Clean(); - decisionXConditions.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 - // - ; - - // - result = isCycleHelpersValid; - if (!result) - { - return result; - } - - // - int count = ArraySize(positions); - result = IsValidSize(count); - if (!result) - { - return result; - } - - // - string symbol = decisionCycleHelper.GetSymbol(); - ENUM_TIMEFRAMES period = decisionCycleHelper.GetPeriod(); - string provider = ToString(X_121_SMC_PROVIDER_XSUPDEMOBS); - - // - 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 ... - - // - XBoxZone lastBullishBox; - XBoxZone prevLastBullishBox; - bool hasLastBullishBox = false; - bool hasPrevLastBullishBox = false; - XConsolidationZone lastBullishZone; - bool isLastBullishAbovePrev = false; - bool isLastBullishBelowPrev = false; - XConsolidationZone prevLastBullishZone; - - // - XBoxZone lastBearishBox; - XBoxZone prevLastBearishBox; - bool hasLastBearishBox = false; - bool hasPrevLastBearishBox = false; - XConsolidationZone lastBearishZone; - bool isLastBearishAbovePrev = false; - bool isLastBearishBelowPrev = false; - XConsolidationZone prevLastBearishZone; - - // - int bullishConsolidationZonesCount = 0; - int bearishConsolidationZonesCount = 0; - bool hasBullishConsolidationZones = false; - bool hasBearishConsolidationZones = false; - XConsolidationZone bullishConsolidationZones[]; - XConsolidationZone bearishConsolidationZones[]; - bool hasConsolidationZones = decisionCycleHelper.HasConsolidationZones(); - int consolidationZonesCount = decisionCycleHelper.CountConsolidationZones(); - if (hasConsolidationZones) - { - // - bullishConsolidationZonesCount = decisionCycleHelper - .FillConsolidationZones( - X_DIRECTION_BULLISH, - bullishConsolidationZones // - ); - hasBullishConsolidationZones = IsValidSize(bullishConsolidationZonesCount); - - // - bearishConsolidationZonesCount = decisionCycleHelper - .FillConsolidationZones( - X_DIRECTION_BEARISH, - bearishConsolidationZones // - ); - hasBearishConsolidationZones = IsValidSize(bearishConsolidationZonesCount); - - // - // - // - - // - if (hasBullishConsolidationZones && - bullishConsolidationZonesCount >= 2) - { - // - lastBullishZone = bullishConsolidationZones[bullishConsolidationZonesCount - 1]; - prevLastBullishZone = bullishConsolidationZones[bullishConsolidationZonesCount - 2]; - - // - hasLastBullishBox = ToBox( - lastBullishBox, - lastBullishZone // - ); - hasPrevLastBullishBox = ToBox( - prevLastBullishBox, - prevLastBullishZone // - ); - - // - isLastBullishAbovePrev = hasLastBullishBox && - hasPrevLastBullishBox && - IsBoxAbove( - lastBullishBox, - prevLastBullishBox // - ); - - // - isLastBullishBelowPrev = hasLastBullishBox && - hasPrevLastBullishBox && - IsBoxBelow( - lastBullishBox, - prevLastBullishBox // - ); - } - - // - if (hasBearishConsolidationZones && - bearishConsolidationZonesCount >= 2) - { - // - lastBearishZone = bearishConsolidationZones[bearishConsolidationZonesCount - 1]; - prevLastBearishZone = bearishConsolidationZones[bearishConsolidationZonesCount - 2]; - - // - hasLastBearishBox = ToBox( - lastBearishBox, - lastBearishZone // - ); - hasPrevLastBearishBox = ToBox( - prevLastBearishBox, - prevLastBearishZone // - ); - - // - isLastBearishAbovePrev = hasLastBearishBox && - hasPrevLastBearishBox && - IsBoxAbove( - lastBearishBox, - prevLastBearishBox // - ); - - // - isLastBearishBelowPrev = hasLastBearishBox && - hasPrevLastBearishBox && - IsBoxBelow( - lastBearishBox, - prevLastBearishBox // - ); - } - - // - } - - // - // 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 isStrongSwingLowAboveLastBullishBox = - isStrongSwingLow && - hasLastBullishBox && - pBar.low > lastBullishBox.upper; - - // - bool isStrongSwingHighBelowLastBearishBox = - isStrongSwingHigh && - hasLastBearishBox && - pBar.high < lastBearishBox.lower; - - // - // 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 ... - - // - // 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(); - - // - lastBullishBox.Clean(); - lastBearishBox.Clean(); - lastBullishZone.Clean(); - lastBearishZone.Clean(); - prevLastBullishBox.Clean(); - prevLastBearishBox.Clean(); - prevLastBullishZone.Clean(); - prevLastBearishZone.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 ... - X121SMCStrategyXSupDemOBSSignalConditions tmpItems[]; - Copy( - mConditionsCollection, - tmpItems // - ); - - // - // Prese Item Data ... - bool isBullish = IsBullish(mConditions.dir); - - // - for (int i = 0; i < count; i++) - { - // - X121SMCStrategyXSupDemOBSSignalConditions 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 RemoveDraws() - { - mObjects.Clear(); - } - - // - void RemoveWorkingZoneDraws() - { - mWorkingZoneObjects.Clear(); - } - - // - void DrawOrderBlock( - XCOrderBlock *ob, - XCPOIDrawer *drawer // - ) - { - // - if (ob == NULL || - drawer == NULL) - { - return; - } - - // - ENUM_X_DIRECTION forDir = ob.GetDirection(); - - // - color bullishColor = drawer.BarBullishColor(); - color bearishColor = drawer.BarBearishColor(); - color forColor = IsBullish(forDir) - ? bullishColor - : bearishColor; - - // - // Draw Order Block ... - XCBaseObject *obj; - bool isCreated = drawer.CreateOrderBlock( - ob, - obj // - ); - if (isCreated) - { - mObjects.Add(obj); - } - - // - ulong chartID = drawer.ChartIdentification(); - int subWindow = drawer.SubWindowIdentification(); - - // - XOHCL startedBar; - ENUM_X_DIRECTION startedDir; - bool isStarted = ob.IsStarted( - forDir, - startedBar, - startedDir // - ); - if (isStarted) - { - // - datetime to = startedBar.time + (PeriodSeconds(startedBar.period)); - - // - XCOHCLObject *obj; - bool isCreated = drawer.CreateBar( - startedBar, - obj, - to // - ); - if (isCreated) - { - // - obj.BodyColor(clrYellow); - obj.HighShadowColor(clrYellow); - obj.LowShadowColor(clrYellow); - - // - obj.BodyStyle(STYLE_SOLID); - obj.HighShadowStyle(STYLE_SOLID); - obj.LowShadowStyle(STYLE_SOLID); - - // - mObjects.Add(obj); - } - - // - string startVLineName = "Start_" + ob.GetTag(); - - // - CChartObjectVLine *startVLine; - startVLine = new CChartObjectVLine(); - isCreated = startVLine.Create( - chartID, - startVLineName, - subWindow, - startedBar.time // - ); - if (isCreated) - { - // - startVLine.Color(forColor); - - // - mObjects.Add(startVLine); - } - } - } - - // - void DrawFairValueGap( - XCFVG *fvg, - XCPOIDrawer *drawer // - ) - { - // - if (fvg == NULL || - drawer == NULL) - { - return; - } - - // - ENUM_X_DIRECTION forDir = fvg.GetDirection(); - - // - color bullishColor = drawer.BarBullishColor(); - color bearishColor = drawer.BarBearishColor(); - color forColor = IsBullish(forDir) - ? bullishColor - : bearishColor; - - // - // Draw Order Block ... - XCBaseObject *obj; - bool isCreated = drawer.CreateFairValueGap( - fvg, - obj // - ); - if (isCreated) - { - mObjects.Add(obj); - } - - // - ulong chartID = drawer.ChartIdentification(); - int subWindow = drawer.SubWindowIdentification(); - - // - XOHCL startedBar; - ENUM_X_DIRECTION startedDir; - bool isStarted = fvg.IsStarted( - forDir, - startedBar, - startedDir // - ); - if (isStarted) - { - // - datetime to = startedBar.time + (PeriodSeconds(startedBar.period)); - - // - XCOHCLObject *obj; - bool isCreated = drawer.CreateBar( - startedBar, - obj, - to // - ); - if (isCreated) - { - // - obj.BodyColor(clrYellow); - obj.HighShadowColor(clrYellow); - obj.LowShadowColor(clrYellow); - - // - obj.BodyStyle(STYLE_SOLID); - obj.HighShadowStyle(STYLE_SOLID); - obj.LowShadowStyle(STYLE_SOLID); - - // - mObjects.Add(obj); - } - - // - string startVLineName = "Start_" + fvg.GetTag(); - - // - CChartObjectVLine *startVLine; - startVLine = new CChartObjectVLine(); - isCreated = startVLine.Create( - chartID, - startVLineName, - subWindow, - startedBar.time // - ); - if (isCreated) - { - // - startVLine.Color(forColor); - - // - mObjects.Add(startVLine); - } - } - } - - // - void DrawWorkingZone( - X121SMCStrategyXSupDemOBSSignalConditions &conditions, - XCPOIDrawer *drawer // - ) - { - // - if (drawer == NULL) - { - return; - } - - // - bool isCreated = false; - - // - bool hasVisionHighestSupplyZone = conditions.HasVisionHighestSupplyZone(); - if (hasVisionHighestSupplyZone) - { - // - XCSupplyZoneObject *ivhSupObj; - isCreated = drawer.CreateSupplyZone( - conditions.visionHighestSupplyZone, - ivhSupObj // - ); - if (isCreated) - { - mWorkingZoneObjects.Add(ivhSupObj); - } - } - - // - bool hasConsolidationHighestSupplyZone = conditions.HasConsolidationHighestSupplyZone(); - if (hasConsolidationHighestSupplyZone) - { - // - XCSupplyZoneObject *ichSupObj; - isCreated = drawer.CreateSupplyZone( - conditions.consolidationHighestSupplyZone, - ichSupObj // - ); - if (isCreated) - { - mWorkingZoneObjects.Add(ichSupObj); - } - } - - // - bool hasVisionLowestDemandZone = conditions.HasVisionLowestDemandZone(); - if (hasVisionLowestDemandZone) - { - // - XCDemandZoneObject *ivlSupObj; - isCreated = drawer.CreateDemandZone( - conditions.visionLowestDemandZone, - ivlSupObj // - ); - if (isCreated) - { - mWorkingZoneObjects.Add(ivlSupObj); - } - } - - // - bool hasConsolidationLowestDemandZone = conditions.HasConsolidationLowestDemandZone(); - if (hasConsolidationLowestDemandZone) - { - // - XCDemandZoneObject *iclSupObj; - isCreated = drawer.CreateDemandZone( - conditions.consolidationLowestDemandZone, - iclSupObj // - ); - if (isCreated) - { - mWorkingZoneObjects.Add(iclSupObj); - } - } - - // - bool hasWorkingZone = conditions.workingZone.IsValid(); - if (hasWorkingZone) - { - // - string zonePrefix = "X121_WZ_" + conditions.workingZone.symbol + "_" + ToString(conditions.workingZone.period); - string fromStr = ToFormatString(conditions.workingZone.from); - string fromMD5 = ToMD5(fromStr); - - // - string upperName = zonePrefix + "_Upper_" + fromMD5; - string lowerName = zonePrefix + "_Lower_" + fromMD5; - string zoneUpperName = zonePrefix + "_ZoneUpper_" + fromMD5; - string zoneLowerName = zonePrefix + "_ZoneLower_" + fromMD5; - - // - string q1Name = zonePrefix + "_Q1_" + fromMD5; - string q2Name = zonePrefix + "_Q2_" + fromMD5; - string q3Name = zonePrefix + "_Q3_" + fromMD5; - - // - ulong chartID = drawer.ChartIdentification(); - int subWindow = drawer.SubWindowIdentification(); - - // - bool isCreated = false; - - // - // Lower ... - CChartObjectHLine *lowerHLine; - lowerHLine = new CChartObjectHLine(); - isCreated = lowerHLine.Create( - chartID, - lowerName, - subWindow, - conditions.workingZone.lower // - ); - if (isCreated) - { - // - lowerHLine.Color(clrLime); - mWorkingZoneObjects.Add(lowerHLine); - } - - // - CChartObjectHLine *upperHLine; - upperHLine = new CChartObjectHLine(); - isCreated = upperHLine.Create( - chartID, - upperName, - subWindow, - conditions.workingZone.upper // - ); - if (isCreated) - { - // - upperHLine.Color(clrLime); - mWorkingZoneObjects.Add(upperHLine); - } - - // - CChartObjectHLine *zoneLowerHLine; - zoneLowerHLine = new CChartObjectHLine(); - isCreated = zoneLowerHLine.Create( - chartID, - zoneLowerName, - subWindow, - conditions.workingZone.zoneLower // - ); - if (isCreated) - { - // - zoneLowerHLine.Color(clrRed); - mWorkingZoneObjects.Add(zoneLowerHLine); - } - - // - CChartObjectHLine *zoneUpperHLine; - zoneUpperHLine = new CChartObjectHLine(); - isCreated = zoneUpperHLine.Create( - chartID, - zoneUpperName, - subWindow, - conditions.workingZone.zoneUpper // - ); - if (isCreated) - { - // - zoneUpperHLine.Color(clrRed); - mWorkingZoneObjects.Add(zoneUpperHLine); - } - - // - CChartObjectHLine *quarter1HLine; - quarter1HLine = new CChartObjectHLine(); - isCreated = quarter1HLine.Create( - chartID, - q1Name, - subWindow, - conditions.workingZone.quarter1 // - ); - if (isCreated) - { - // - quarter1HLine.Color(clrYellow); - mWorkingZoneObjects.Add(quarter1HLine); - } - - // - CChartObjectHLine *quarter2HLine; - quarter2HLine = new CChartObjectHLine(); - isCreated = quarter2HLine.Create( - chartID, - q2Name, - subWindow, - conditions.workingZone.quarter2 // - ); - if (isCreated) - { - // - quarter2HLine.Color(clrYellow); - mWorkingZoneObjects.Add(quarter2HLine); - } - - // - CChartObjectHLine *quarter3HLine; - quarter3HLine = new CChartObjectHLine(); - isCreated = quarter3HLine.Create( - chartID, - q3Name, - subWindow, - conditions.workingZone.quarter3 // - ); - if (isCreated) - { - // - quarter3HLine.Color(clrYellow); - mWorkingZoneObjects.Add(quarter3HLine); - } - } - } - - // - void DrawConditions( - X121SMCStrategyXSupDemOBSSignalConditions &conditions, - XCPOIDrawer *drawer, - bool forceClean = false // - ) - { - // - if (drawer == NULL) - { - return; - } - - // - if (forceClean) - { - mObjects.Clear(); - } - - // - bool isCreated = false; - - // - int obFVGsCount = ArraySize(conditions.obFVGs); - bool hasOBFVGs = IsValidSize(obFVGsCount); - if (hasOBFVGs) - { - // - for (int i = 0; i < obFVGsCount; i++) - { - // - XOBFVG iOBFVG = conditions.obFVGs[i]; - - // - DrawOrderBlock( - iOBFVG.ob, - drawer // - ); - - // - DrawFairValueGap( - iOBFVG.fvg, - drawer // - ); - - // - int hasUnActivatedOBs = iOBFVG.HasUnActivatedOBs(); - int unActivatedOBsCount = iOBFVG.CountUnActivatedOBs(); - if (hasUnActivatedOBs) - { - // - for (int j = 0; j < unActivatedOBsCount; j++) - { - // - DrawOrderBlock( - iOBFVG.unActivatedOBs[j], - drawer // - ); - } - } - - // - int hasUnActivatedFVGs = iOBFVG.HasUnActivatedFVGs(); - int unActivatedFVGsCount = iOBFVG.CountUnActivatedFVGs(); - if (hasUnActivatedFVGs) - { - // - for (int j = 0; j < unActivatedFVGsCount; j++) - { - // - DrawFairValueGap( - iOBFVG.unActivatedFVGs[j], - drawer // - ); - } - } - } - } - - // - int insideZoneWidth = 1; - color insideZoneColor = clrYellow; - bool hasInsideOB = conditions.insideOB != NULL && - conditions.insideOB.IsValid(); - if (hasInsideOB) - { - // - bool isBullish = conditions.insideOB.IsBullish(); - - // - XCBaseObject *iObj = NULL; - isCreated = false; - if (isBullish) - { - // - XCBullishOrderBlockObject *iiObj; - isCreated = drawer.CreateBullishOrderBlock( - conditions.insideOB, - iiObj // - ); - - // - if (isCreated) - { - // - iiObj.ZoneColor(insideZoneColor); - iiObj.ZoneWidth(insideZoneWidth); - - // - iObj = (XCBaseObject *)iiObj; - } - } - else - { - // - XCBearishOrderBlockObject *iiObj; - isCreated = drawer.CreateBearishOrderBlock( - conditions.insideOB, - iiObj // - ); - - // - if (isCreated) - { - // - iiObj.ZoneColor(insideZoneColor); - iiObj.ZoneWidth(insideZoneWidth); - - // - iObj = (XCBaseObject *)iiObj; - } - } - - // - if (isCreated) - { - mObjects.Add(iObj); - } - } - - // - bool hasInsideFVG = conditions.insideFVG != NULL && - conditions.insideFVG.IsValid(); - if (hasInsideFVG) - { - // - bool isBullish = conditions.insideFVG.IsBullish(); - - // - XCBaseObject *iObj = NULL; - isCreated = false; - if (isBullish) - { - // - XCBullishFairValueGapObject *iiObj; - isCreated = drawer.CreateBullishFairValueGap( - conditions.insideFVG, - iiObj // - ); - - // - if (isCreated) - { - // - iiObj.ZoneColor(insideZoneColor); - iiObj.ZoneWidth(insideZoneWidth); - - // - iObj = (XCBaseObject *)iiObj; - } - } - else - { - // - XCBearishFairValueGapObject *iiObj; - isCreated = drawer.CreateBearishFairValueGap( - conditions.insideFVG, - iiObj // - ); - - // - if (isCreated) - { - // - iiObj.ZoneColor(insideZoneColor); - iiObj.ZoneWidth(insideZoneWidth); - - // - iObj = (XCBaseObject *)iiObj; - } - } - - // - if (isCreated) - { - mObjects.Add(iObj); - } - } - - // - bool hasConsolidationZone = conditions.consolidationZone.IsValid(); - if (hasConsolidationZone) - { - // - XCConsolidationZoneObject *iObj; - isCreated = drawer.CreateConsolidationZone( - conditions.consolidationZone, - iObj // - ); - - // - if (isCreated) - { - mObjects.Add(iObj); - } - } - } - - // - protected: - // - - // - private: - // - // Props ... - CArrayObj mObjects; - CArrayObj mWorkingZoneObjects; - - /** - * Initialize ... - */ - void Init() - { - } - - /** - * DeInitialize ... - */ - void DeInit() - { - // - RemoveDraws(); - mConditions.Clean(); - RemoveWorkingZoneDraws(); - Clean(mConditionsCollection); - } - - // - // Helpers ... - - // - bool CheckPriceInside( - XOHCL &zBar, - XOHCL &cBar, - double upper, - double lower // - ) - { - // - bool result = false; - - // - result = zBar.IsValid() && - cBar.IsValid() && - upper > 0 && - lower > 0 && - upper > lower && - zBar.time > cBar.time; - if (!result) - { - return result; - } - - // - result = - // - zBar.high < upper && - cBar.high < upper && - // - zBar.low > lower && - cBar.low > lower - // - ; - - // - return result; - } - - // - bool CalculateRiskReward( - ENUM_X121SMC_XSUPDEMOBS_PRIORITY priority, - double &reward, - double &amountPercent // - ) - { - // - bool result = false; - - // - reward = 0; - amountPercent = 0; - - // - result = priority != X121SMC_XSUPDEMOBS_PRIORITY_NONE; - if (!result) - { - return result; - } - - // - switch (priority) - { - // - case X121SMC_XSUPDEMOBS_PRIORITY_HIGH: - // - reward = 6; - amountPercent = 2; - break; - - // - case X121SMC_XSUPDEMOBS_PRIORITY_REGULAR: - // - reward = 6; - amountPercent = 1.5; - break; - - // - case X121SMC_XSUPDEMOBS_PRIORITY_LOW: - // - reward = 4; - amountPercent = 1; - break; - - // - case X121SMC_XSUPDEMOBS_PRIORITY_WEAK: - // - reward = 2; - amountPercent = 0.5; - break; - } - - // - result = - // - reward > 0 && - amountPercent > 0 - // - ; - - // - return result; - } - - // -}; - -// \ No newline at end of file diff --git a/Documents/BKP/xsupdem/x-121.smc.xsupdemobs.signal.lib.mq5 b/Documents/BKP/xsupdem/x-121.smc.xsupdemobs.signal.lib.mq5 deleted file mode 100644 index c5df488b..00000000 --- a/Documents/BKP/xsupdem/x-121.smc.xsupdemobs.signal.lib.mq5 +++ /dev/null @@ -1,1686 +0,0 @@ -/////////////////////////////////////////////////////// -// -// SaherElm IT Center MQL5 X121 SMC Signal Class -// ------------------------------------------------- -// Name: XSupDemOBS -// 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_XSUPDEMOBS_PRIORITY -{ - X121SMC_XSUPDEMOBS_PRIORITY_NONE, - X121SMC_XSUPDEMOBS_PRIORITY_WEAK, - X121SMC_XSUPDEMOBS_PRIORITY_LOW, - X121SMC_XSUPDEMOBS_PRIORITY_REGULAR, - X121SMC_XSUPDEMOBS_PRIORITY_HIGH, -}; - -// -struct XOBFVG -{ - // - string symbol; - ENUM_TIMEFRAMES period; - - // - datetime time; - - // - XCOrderBlock *ob; - XCFVG *fvg; - - // - XCFVG *unActivatedFVGs[]; - XCOrderBlock *unActivatedOBs[]; - - // - XOBFVG() - { - Clean(); - } - - // - void Clean() - { - // - ob = NULL; - fvg = NULL; - time = NULL; - symbol = NULL; - period = NULL; - - // - Clean(unActivatedOBs); - Clean(unActivatedFVGs); - - // - ZeroMemory(this); - } - - // - bool IsValid() - { - // - bool result = false; - - // - result = - // - ob != NULL && - ob.IsValid() && - fvg != NULL && - fvg.IsValid() && - ob.From() < fvg.From() && - IsValid(time) && - IsValid(symbol) && - IsValid(period) - // - ; - if (!result) - { - return result; - } - - // - ENUM_X_DIRECTION mDir = GetDirection(); - - // - // Validate Order Block ... - - // - // Validate Started Zones ... - XOHCL obStartedBar; - ENUM_X_DIRECTION obStartedDir; - bool isStarted = ob.IsStarted( - mDir, - obStartedBar, - obStartedDir // - ); - result = isStarted; - if (!result) - { - return result; - } - - // - // Validate InActive Zone ... - XOHCL obActivatedBar; - ENUM_X_DIRECTION obActivatedDir; - bool isActivated = ob.IsActivated( - mDir, - obActivatedBar, - obActivatedDir // - ); - result = !isActivated; - if (!result) - { - return result; - } - - // - // Validate Zone Iverse Breake ... - XOHCL obBreakedBar; - ENUM_X_DIRECTION obBreakedDir; - bool isBreaked = ob.IsBreaked( - Opposit(mDir), - obBreakedBar, - obBreakedDir, - true // Ignore Activation ... - ); - result = !isBreaked; - if (!result) - { - return result; - } - - // - // Checking Dirction(s) ... - result = - HasDirection(mDir) && - mDir == fvg.GetDirection(); - if (!result) - { - return result; - } - - // - // Validate FVG From Date ... - - // - // Checking FVG Place ... - - // - bool isBullish = IsBullish(mDir); - - // - bool isAbove = IsAboveDiff( - fvg, - ob, - true // Ignore Inside ... - ); - - // - bool isBelow = IsBelowDiff( - fvg, - ob, - true // Ignore Inside ... - ); - - // - result = - isBullish - ? isAbove - : isBelow; - if (!result) - { - return result; - } - - // - // Check FVG Must Be Started ... - XOHCL fvgStartedBar; - ENUM_X_DIRECTION fvgStartedDir; - isStarted = fvg.IsStarted( - mDir, - fvgStartedBar, - fvgStartedDir // - ); - result = isStarted; - if (!result) - { - return result; - } - - // - // Check FVg Not Breaked in Reversal Direction ... - XOHCL fvgBreakedBar; - ENUM_X_DIRECTION fvgBreakedDir; - isBreaked = fvg.IsBreaked( - Opposit(mDir), - fvgBreakedBar, - fvgBreakedDir, - true // Ignore Activation ... - ); - result = !isBreaked; - if (!result) - { - return result; - } - - // - return result; - } - - // - ENUM_X_DIRECTION GetDirection() - { - return ob.GetDirection(); - } - - // - int CountUnActivatedOBs() - { - return ArraySize(unActivatedOBs); - } - - // - bool HasUnActivatedOBs() - { - return IsValidSize(CountUnActivatedOBs()); - } - - // - bool AddUnActivatedOB( - XCOrderBlock *_ob, - XOHCL &bar // - ) - { - // - bool result = false; - - // - result = IsValid() && - bar.IsValid() && - _ob != NULL && - _ob.IsValid(); - if (!result) - { - return result; - } - - // - // Check Order Block is not Same as Current OB ... - bool isSame = IsSame( - _ob, - ob // - ); - result = !isSame; - if (!result) - { - return result; - } - - // - ENUM_X_DIRECTION mDir = GetDirection(); - bool isBullish = IsBullish(mDir); - - // - // Check Bars ... - XOHCL pBar; - result = bar.GetPreviousBar(pBar); - if (!result) - { - return result; - } - - // - bool isPricePassed = - isBullish - ? IsAbove( - bar.low, - _ob // - ) && - IsAbove( - pBar.low, - _ob // - ) - : IsBelow( - bar.high, - _ob // - ) && - IsBelow( - pBar.high, - _ob // - ); - result = isPricePassed; - if (!result) - { - return result; - } - - // - // Validate Order Block is Not Activated ... - - // - // Validate Started Zones ... - XOHCL obStartedBar; - ENUM_X_DIRECTION obStartedDir; - bool isStarted = _ob.IsStarted( - mDir, - obStartedBar, - obStartedDir // - ); - result = isStarted; - if (!result) - { - return result; - } - - // - // Validate InActive Zone ... - XOHCL obActivatedBar; - ENUM_X_DIRECTION obActivatedDir; - bool isActivated = _ob.IsActivated( - mDir, - obActivatedBar, - obActivatedDir // - ); - result = !isActivated; - if (!result) - { - return result; - } - - // - // Validate Zone Iverse Breake ... - XOHCL obBreakedBar; - ENUM_X_DIRECTION obBreakedDir; - bool isBreaked = _ob.IsBreaked( - Opposit(mDir), - obBreakedBar, - obBreakedDir, - true // Ignore Activation ... - ); - result = !isBreaked; - if (!result) - { - return result; - } - - // - int idx = FindIndex( - _ob, - unActivatedOBs // - ); - result = !IsValidIndex(idx); - if (!result) - { - return result; - } - - // - bool isLastPassed = true; - bool isAboveLast = false; - bool isBelowLast = false; - XCOrderBlock *lastOB = NULL; - int unActivatedOBsCount = CountUnActivatedOBs(); - bool hasUnActivatedOBs = HasUnActivatedOBs(); - if (hasUnActivatedOBs) - { - lastOB = unActivatedOBs[unActivatedOBsCount - 1]; - } - bool hasLastOB = lastOB != NULL && - lastOB.IsValid(); - if (hasLastOB) - { - // - isAboveLast = IsAbove( - _ob, - lastOB, - true // Ignore Inside ... - ); - - // - isBelowLast = IsBelow( - _ob, - lastOB, - true // Ignore Inside ... - ); - - // - isLastPassed = - isBullish - ? isAboveLast - : isBelowLast; - } - result = isLastPassed; - if (!result) - { - return result; - } - - // - Add( - _ob, - unActivatedOBs // - ); - - // - return result; - } - - // - int CountUnActivatedFVGs() - { - return ArraySize(unActivatedFVGs); - } - - // - bool HasUnActivatedFVGs() - { - return IsValidSize(CountUnActivatedFVGs()); - } - - // - bool AddUnActivatedFVG( - XCFVG *_fvg, - XOHCL &bar // - ) - { - // - bool result = false; - - // - result = IsValid() && - bar.IsValid() && - _fvg != NULL && - _fvg.IsValid(); - if (!result) - { - return result; - } - - // - // Check Order Block is not Same as Current OB ... - bool isSame = IsSame( - _fvg, - fvg // - ); - result = !isSame; - if (!result) - { - return result; - } - - // - ENUM_X_DIRECTION mDir = GetDirection(); - bool isBullish = IsBullish(mDir); - - // - // Check Bars ... - XOHCL pBar; - result = bar.GetPreviousBar(pBar); - if (!result) - { - return result; - } - - // - bool isPricePassed = - isBullish - ? IsAbove( - bar.low, - _fvg // - ) && - IsAbove( - pBar.low, - _fvg // - ) - : IsBelow( - bar.high, - _fvg // - ) && - IsBelow( - pBar.high, - _fvg // - ); - result = isPricePassed; - if (!result) - { - return result; - } - - // - // Validate Order Block is Not Activated ... - - // - // Validate Started Zones ... - XOHCL fvgStartedBar; - ENUM_X_DIRECTION fvgStartedDir; - bool isStarted = _fvg.IsStarted( - mDir, - fvgStartedBar, - fvgStartedDir // - ); - result = isStarted; - if (!result) - { - return result; - } - - // - // Validate InActive Zone ... - XOHCL fvgActivatedBar; - ENUM_X_DIRECTION fvgActivatedDir; - bool isActivated = _fvg.IsActivated( - mDir, - fvgActivatedBar, - fvgActivatedDir // - ); - result = !isActivated; - if (!result) - { - return result; - } - - // - // Validate Zone Iverse Breake ... - XOHCL fvgBreakedBar; - ENUM_X_DIRECTION fvgBreakedDir; - bool isBreaked = _fvg.IsBreaked( - Opposit(mDir), - fvgBreakedBar, - fvgBreakedDir, - true // Ignore Activation ... - ); - result = !isBreaked; - if (!result) - { - return result; - } - - // - int idx = FindIndex( - _fvg, - unActivatedFVGs // - ); - result = !IsValidIndex(idx); - if (!result) - { - return result; - } - - // - XCFVG *lastFVG = NULL; - bool isLastPassed = true; - bool isAboveLast = false; - bool isBelowLast = false; - int unActivatedFVGsCount = CountUnActivatedFVGs(); - bool hasUnActivatedFVGs = HasUnActivatedFVGs(); - if (hasUnActivatedFVGs) - { - lastFVG = unActivatedFVGs[unActivatedFVGsCount - 1]; - } - bool hasLastFVG = lastFVG != NULL && - lastFVG.IsValid(); - if (hasLastFVG) - { - // - isAboveLast = IsAbove( - _fvg, - lastFVG, - true // Ignore Inside ... - ); - - // - isBelowLast = IsBelow( - _fvg, - lastFVG, - true // Ignore Inside ... - ); - - // - isLastPassed = - isBullish - ? isAboveLast - : isBelowLast; - } - result = isLastPassed; - if (!result) - { - return result; - } - - // - Add( - _fvg, - unActivatedFVGs // - ); - - // - return result; - } -}; - -// -struct X121SMCXSupDemOBSWorkingZone -{ - // - string symbol; - ENUM_TIMEFRAMES period; - - // - double upper; - double lower; - - // - double zoneUpper; - double zoneLower; - - // - double quarter1; - double quarter2; - double quarter3; - - // - datetime from; - - // - X121SMCXSupDemOBSWorkingZone() - { - Clean(); - } - - // - void Clean() - { - // - upper = 0; - lower = 0; - quarter1 = 0; - quarter2 = 0; - quarter3 = 0; - zoneLower = 0; - zoneUpper = 0; - - // - from = NULL; - symbol = NULL; - period = NULL; - - // - ZeroMemory(this); - } - - // - bool IsValid() - { - // - bool result = false; - - // - result = - lower > 0 && - upper > 0 && - quarter1 > 0 && - quarter2 > 0 && - quarter3 > 0 && - upper > lower && - zoneLower > 0 && - zoneUpper > 0 && - IsValid(from) && - IsValid(symbol) && - IsValid(period) && - zoneUpper > upper && - zoneLower < lower; - - // - return result; - } - - // - bool DetectOveralTrend( - XOHCL &touchedBar, - ENUM_X_DIRECTION &trendDir, - int barIndex = 0 // - ) - { - // - bool result = false; - - // - if (barIndex < 0) - { - barIndex = 0; - } - - // - trendDir = X_DIRECTION_NONE; - - // - result = IsValid(); - if (!result) - { - return result; - } - - // - int fromBarIndex = iBarShift( - symbol, - period, - from // - ); - result = IsValidIndex(fromBarIndex); - if (!result) - { - return result; - } - - // - XOHCL nearestUpperTouchedBar; - XOHCL nearestLowerTouchedBar; - bool hasNearestUpperTouchedBar = false; - bool hasNearestLowerTouchedBar = false; - for (int i = barIndex; i < fromBarIndex; i++) - { - // - XOHCL iBar; - bool isInited = iBar.Init( - symbol, - period, - i // - ); - - // - hasNearestUpperTouchedBar = nearestUpperTouchedBar.IsValid(); - if (!hasNearestUpperTouchedBar) - { - // - bool isBarTouchedUpper = iBar.high > upper; - if (isBarTouchedUpper) - { - // - nearestUpperTouchedBar = iBar; - hasNearestUpperTouchedBar = true; - } - } - - // - hasNearestLowerTouchedBar = nearestLowerTouchedBar.IsValid(); - if (!hasNearestLowerTouchedBar) - { - // - bool isBarTouchedLower = iBar.low < lower; - if (isBarTouchedLower) - { - // - nearestLowerTouchedBar = iBar; - hasNearestLowerTouchedBar = true; - } - } - - // - if (hasNearestUpperTouchedBar && - hasNearestLowerTouchedBar) - { - break; - } - } - - // - result = hasNearestUpperTouchedBar || - hasNearestLowerTouchedBar; - if (result) - { - // - if (hasNearestUpperTouchedBar && - !hasNearestLowerTouchedBar) - { - // - trendDir = X_DIRECTION_BEARISH; - touchedBar = nearestUpperTouchedBar; - } - else if (!hasNearestUpperTouchedBar && - hasNearestLowerTouchedBar) - { - // - trendDir = X_DIRECTION_BULLISH; - touchedBar = nearestLowerTouchedBar; - } - else if (hasNearestUpperTouchedBar && - hasNearestLowerTouchedBar) - { - // - trendDir = - nearestUpperTouchedBar.time < nearestLowerTouchedBar.time - ? X_DIRECTION_BULLISH - : X_DIRECTION_BEARISH; - - // - if (IsBullish(trendDir)) - { - touchedBar = nearestLowerTouchedBar; - } - else - { - touchedBar = nearestUpperTouchedBar; - } - } - } - - // - return result; - } - - // - bool IsDestroyed( - ENUM_X_DIRECTION &destroyedDir, - int barIndex = 0, - ENUM_TIMEFRAMES forPeriod = NULL // - ) - { - // - bool result = false; - - // - if (barIndex < 0) - { - barIndex = 0; - } - - // - if (!IsValid(forPeriod)) - { - forPeriod = period; - } - - // - destroyedDir = X_DIRECTION_NONE; - - // - result = IsValid(); - if (!result) - { - return result; - } - - // - XOHCL bar; - result = bar.Init( - symbol, - forPeriod, - barIndex // - ); - if (!result) - { - return result; - } - - // - bool isUpperBreaked = - bar.high > zoneUpper && - bar.close > zoneUpper; - - // - bool isLowerBreaked = - bar.low < zoneLower && - bar.close < zoneLower; - - // - result = isUpperBreaked || - isLowerBreaked; - if (result) - { - // - destroyedDir = - isUpperBreaked - ? X_DIRECTION_BULLISH - : X_DIRECTION_BEARISH; - } - - // - return result; - } - - // -}; - -// -// Definitions ... -struct X121SMCStrategyXSupDemOBSSignalConditions -{ - // - // Props ... - - // - string symbol; - ENUM_TIMEFRAMES period; - - // - double sl; - double target; - double reward; - double amountPercent; - ENUM_X_DIRECTION dir; - ENUM_X_POSITION_TYPES type; - - // - // Setup Props ... - - // - datetime setupTime; - datetime triggerTime; - - // - double pivot; - double point; - - // - ENUM_X121SMC_XSUPDEMOBS_PRIORITY priority; - - // - // Working Zone ... - - // - XCSupplyZone *visionHighestSupplyZone; - XCSupplyZone *consolidationHighestSupplyZone; - - // - XCDemandZone *visionLowestDemandZone; - XCDemandZone *consolidationLowestDemandZone; - - // - XCFVG *insideFVG; - XCOrderBlock *insideOB; - - // - XCFVG *rejectedFVG; - XCOrderBlock *rejectedOB; - - // - XCSupplyZone *insideSupplyZone; - XCDemandZone *insideDemandZone; - - // - XConsolidationZone consolidationZone; - - // - XOBFVG obFVGs[]; - - // - X121SMCXSupDemOBSWorkingZone workingZone; - - // - // Constructor ... - X121SMCStrategyXSupDemOBSSignalConditions() - { - Clean(); - } - - // - // Tools ... - - /** - * Cleaning Up ... - */ - void Clean() - { - // - sl = 0; - target = 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(obFVGs); - workingZone.Clean(); - consolidationZone.Clean(); - - // - insideOB = NULL; - insideFVG = NULL; - rejectedOB = NULL; - rejectedFVG = NULL; - insideSupplyZone = NULL; - insideDemandZone = NULL; - - // - visionLowestDemandZone = NULL; - visionHighestSupplyZone = NULL; - consolidationLowestDemandZone = NULL; - consolidationHighestSupplyZone = NULL; - - // - ZeroMemory(visionLowestDemandZone); - ZeroMemory(visionHighestSupplyZone); - ZeroMemory(consolidationLowestDemandZone); - ZeroMemory(consolidationHighestSupplyZone); - - // - priority = X121SMC_XSUPDEMOBS_PRIORITY_NONE; - } - - // - // - // - - // - bool HasVisionHighestSupplyZone() - { - // - return visionHighestSupplyZone != NULL && - visionHighestSupplyZone.IsValid(); - } - - // - bool HasConsolidationHighestSupplyZone() - { - // - return consolidationHighestSupplyZone != NULL && - consolidationHighestSupplyZone.IsValid(); - } - - // - bool HasVisionLowestDemandZone() - { - // - return visionLowestDemandZone != NULL && - visionLowestDemandZone.IsValid(); - } - - // - bool HasConsolidationLowestDemandZone() - { - // - return consolidationLowestDemandZone != NULL && - consolidationLowestDemandZone.IsValid(); - } - - // - // X_DIRECTION_BULLISH: - // Supply Zone of Consolidation Cycle appears inside - // Supply Zone of Vision Cycle ... - // - // X_DIRECTION_BEARISH: - // Demnad Zone of Consolidation Cycle appears inside - // Demnad Zone of Vision Cycle ... - bool HasHighImpactSide(ENUM_X_DIRECTION &highImpactDir) - { - // - bool result = false; - - // - highImpactDir = X_DIRECTION_NONE; - - // - bool isSupplyInside = false; - bool hasVisionHighestSupplyZone = HasVisionHighestSupplyZone(); - bool hasConsolidationHighestSupplyZone = HasConsolidationHighestSupplyZone(); - if (hasVisionHighestSupplyZone && - hasConsolidationHighestSupplyZone) - { - isSupplyInside = IsInside( - consolidationHighestSupplyZone, - visionHighestSupplyZone // - ); - } - - // - bool isDemandInside = false; - bool hasVisionLowestDemandZone = HasVisionLowestDemandZone(); - bool hasConsolidationLowestDemandZone = HasConsolidationLowestDemandZone(); - if (hasVisionLowestDemandZone && - hasConsolidationLowestDemandZone) - { - // - isDemandInside = IsInside( - consolidationLowestDemandZone, - visionLowestDemandZone // - ); - } - - // - result = isSupplyInside || - isDemandInside; - if (result) - { - // - highImpactDir = - isSupplyInside - ? X_DIRECTION_BULLISH - : X_DIRECTION_BEARISH; - } - - // - return result; - } - - // - datetime ExtractNearestFromDate() - { - // - datetime result = NULL; - - // - bool hasVisionLowestDemandZone = HasVisionLowestDemandZone(); - bool hasVisionHighestSupplyZone = HasVisionHighestSupplyZone(); - bool hasConsolidationLowestDemandZone = HasConsolidationLowestDemandZone(); - bool hasConsolidationHighestSupplyZone = HasConsolidationHighestSupplyZone(); - if (hasVisionLowestDemandZone) - { - // - bool canSet = - !IsValid(result) - ? true - : visionLowestDemandZone.From() > result; - if (canSet) - { - result = visionLowestDemandZone.From(); - } - } - if (hasVisionHighestSupplyZone) - { - // - bool canSet = - !IsValid(result) - ? true - : visionHighestSupplyZone.From() > result; - if (canSet) - { - result = visionHighestSupplyZone.From(); - } - } - if (hasConsolidationLowestDemandZone) - { - // - bool canSet = - !IsValid(result) - ? true - : consolidationLowestDemandZone.From() > result; - if (canSet) - { - result = consolidationLowestDemandZone.From(); - } - } - if (hasConsolidationHighestSupplyZone) - { - // - bool canSet = - !IsValid(result) - ? true - : consolidationHighestSupplyZone.From() > result; - if (canSet) - { - result = consolidationHighestSupplyZone.From(); - } - } - - // - return result; - } - - // - datetime ExtractFarestFromDate() - { - // - datetime result = NULL; - - // - bool hasVisionLowestDemandZone = HasVisionLowestDemandZone(); - bool hasVisionHighestSupplyZone = HasVisionHighestSupplyZone(); - bool hasConsolidationLowestDemandZone = HasConsolidationLowestDemandZone(); - bool hasConsolidationHighestSupplyZone = HasConsolidationHighestSupplyZone(); - if (hasVisionLowestDemandZone) - { - // - bool canSet = - !IsValid(result) - ? true - : visionLowestDemandZone.From() < result; - if (canSet) - { - result = visionLowestDemandZone.From(); - } - } - if (hasVisionHighestSupplyZone) - { - // - bool canSet = - !IsValid(result) - ? true - : visionHighestSupplyZone.From() < result; - if (canSet) - { - result = visionHighestSupplyZone.From(); - } - } - if (hasConsolidationLowestDemandZone) - { - // - bool canSet = - !IsValid(result) - ? true - : consolidationLowestDemandZone.From() < result; - if (canSet) - { - result = consolidationLowestDemandZone.From(); - } - } - if (hasConsolidationHighestSupplyZone) - { - // - bool canSet = - !IsValid(result) - ? true - : consolidationHighestSupplyZone.From() < result; - if (canSet) - { - result = consolidationHighestSupplyZone.From(); - } - } - - // - return result; - } - - // - int CountOBFVGs() - { - return ArraySize(obFVGs); - } - - // - bool HasOBFVGs() - { - return IsValidSize(CountOBFVGs()); - } - - // - // Working Zone is an Area which - // we decide to trade inside it ... - bool ExtractWorkingZone( - int barIndex = 0, - ENUM_TIMEFRAMES forPeriod = NULL // - ) - { - // - bool result = false; - - // - if (barIndex < 0) - { - barIndex = 0; - } - - // - if (!IsValid(forPeriod)) - { - forPeriod = period; - } - - // - result = workingZone.IsValid(); - if (result) - { - return result; - } - - // - XOHCL bar; - result = bar.Init( - symbol, - forPeriod, - barIndex // - ); - - // - double upper = 0; - double lower = 0; - double quarter1 = 0; - double quarter2 = 0; - double quarter3 = 0; - double zoneUpper = 0; - double zoneLower = 0; - - // - ENUM_X_DIRECTION highImpactDir; - bool hasHighImpactSide = HasHighImpactSide(highImpactDir); - result = hasHighImpactSide; - if (!result) - { - return result; - } - - // - // Select Newest Zone From time ... - datetime from = ExtractFarestFromDate(); - - // - bool isSupplyHighImpacted = IsBullish(highImpactDir); - bool isDemandHighImpacted = IsBearish(highImpactDir); - - // - if (isSupplyHighImpacted) - { - // - upper = visionHighestSupplyZone.Lower(); - if (HasConsolidationLowestDemandZone()) - { - lower = consolidationLowestDemandZone.Upper(); - } - else - { - lower = visionLowestDemandZone.Upper(); - } - - // - zoneUpper = visionHighestSupplyZone.Upper(); - if (HasConsolidationLowestDemandZone()) - { - zoneLower = consolidationLowestDemandZone.Lower(); - } - else - { - zoneLower = visionLowestDemandZone.Lower(); - } - } - else - { - // - if (HasConsolidationHighestSupplyZone()) - { - upper = consolidationHighestSupplyZone.Lower(); - } - else - { - upper = visionHighestSupplyZone.Lower(); - } - lower = visionLowestDemandZone.Upper(); - - // - if (HasConsolidationHighestSupplyZone()) - { - zoneUpper = consolidationHighestSupplyZone.Upper(); - } - else - { - zoneUpper = visionHighestSupplyZone.Upper(); - } - zoneLower = visionLowestDemandZone.Lower(); - } - - // - result = - lower > 0 && - upper > 0 && - upper > lower && - zoneUpper > 0 && - zoneLower > 0 && - zoneUpper > upper && - zoneLower < lower; - if (!result) - { - return result; - } - - // - double range = (upper - lower) / 100; - double quarter = range * 25; - - // - quarter1 = upper - (1 * quarter); - quarter2 = upper - (2 * quarter); - quarter3 = upper - (3 * quarter); - - // - workingZone.from = from; - workingZone.upper = upper; - workingZone.lower = lower; - workingZone.symbol = symbol; - workingZone.period = period; - workingZone.quarter1 = quarter1; - workingZone.quarter2 = quarter2; - workingZone.quarter3 = quarter3; - workingZone.zoneUpper = zoneUpper; - workingZone.zoneLower = zoneLower; - - // - result = workingZone.IsValid(); - - // - return result; - } - - // - bool IsWorkingZoneDestroyed( - ENUM_X_DIRECTION &destroyedDir, - int barIndex = 0, - ENUM_TIMEFRAMES forPeriod = NULL // - ) - { - // - bool result = false; - - // - if (barIndex < 0) - { - barIndex = 0; - } - - // - if (!IsValid(forPeriod)) - { - forPeriod = period; - } - - // - destroyedDir = X_DIRECTION_NONE; - - // - result = workingZone.IsValid(); - if (!result) - { - return result; - } - - // - result = workingZone.IsDestroyed( - destroyedDir, - barIndex, - forPeriod // - ); - - // - return result; - } - - // - bool DetectOveralTrend( - XOHCL &touchedBar, - ENUM_X_DIRECTION &trendDir, - int barIndex = 0 // - ) - { - // - bool result = false; - - // - if (barIndex < 0) - { - barIndex = 0; - } - - // - trendDir = X_DIRECTION_NONE; - - // - result = workingZone.IsValid(); - if (!result) - { - return result; - } - - // - result = workingZone.DetectOveralTrend( - touchedBar, - trendDir, - barIndex // - ); - - // - return result; - } - - // - void UpdateTo(datetime value = NULL) - { - // - value = NormalizeTime(value); - - // - bool hasVisionLowestDemandZone = HasVisionLowestDemandZone(); - if (hasVisionLowestDemandZone) - { - visionLowestDemandZone.To(value); - } - - bool hasVisionHighestSupplyZone = HasVisionHighestSupplyZone(); - if (hasVisionHighestSupplyZone) - { - visionHighestSupplyZone.To(value); - } - - bool hasConsolidationLowestDemandZone = HasConsolidationLowestDemandZone(); - if (hasConsolidationLowestDemandZone) - { - consolidationLowestDemandZone.To(value); - } - - bool hasConsolidationHighestSupplyZone = HasConsolidationHighestSupplyZone(); - if (hasConsolidationHighestSupplyZone) - { - consolidationHighestSupplyZone.To(value); - } - - // - bool hasInsideOB = insideOB != NULL && - insideOB.IsValid(); - if (hasInsideOB) - { - insideOB.To(value); - } - - // - bool hasInsideFVG = insideFVG != NULL && - insideFVG.IsValid(); - if (hasInsideFVG) - { - insideFVG.To(value); - } - - // - bool hasOBFVGs = HasOBFVGs(); - int obFVGsCount = CountOBFVGs(); - if (hasOBFVGs) - { - // - for (int i = 0; i < obFVGsCount; i++) - { - // - obFVGs[i].ob.To(value); - obFVGs[i].fvg.To(value); - - // - bool hasUnActivatedOBs = obFVGs[i].HasUnActivatedOBs(); - int unActivatedOBsCount = obFVGs[i].CountUnActivatedOBs(); - if (hasUnActivatedOBs) - { - // - for (int j = 0; j < unActivatedOBsCount; j++) - { - obFVGs[i].unActivatedOBs[j].To(value); - } - } - - // - bool hasUnActivatedFVGs = obFVGs[i].HasUnActivatedFVGs(); - int unActivatedFVGsCount = obFVGs[i].CountUnActivatedFVGs(); - if (hasUnActivatedFVGs) - { - // - for (int j = 0; j < unActivatedFVGsCount; j++) - { - obFVGs[i].unActivatedFVGs[j].To(value); - } - } - } - } - } - - // -}; diff --git a/Documents/BKP/xsupdem/x-121.smc.xwz.signal.class.mq5 b/Documents/BKP/xsupdem/x-121.smc.xwz.signal.class.mq5 deleted file mode 100644 index 757942e0..00000000 --- a/Documents/BKP/xsupdem/x-121.smc.xwz.signal.class.mq5 +++ /dev/null @@ -1,2996 +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 ... - X121SMCStrategyXWZSignalConditions mConditions; - X121SMCStrategyXWZSignalConditions mConditionsCollection[]; - - // - // Constructor(s) ... - XCX121SMCXWZSignalDetector() - { - Init(); - } - - // - // Deconstructor ... - ~XCX121SMCXWZSignalDetector() - { - DeInit(); - } - - // - // - // - - // - // Detect Setup Conditions ... - bool DetectSignalSetup( - // - string _symbol, - ENUM_TIMEFRAMES _period, - // - 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; - - // - string symbol = _symbol; - ENUM_TIMEFRAMES period = _period; - - // - mConditions.symbol = symbol; - mConditions.period = period; - - // - double ask = GetAsk(symbol); - double bid = GetBid(symbol); - datetime cTime = TimeCurrent(); - double points = GetPoints(symbol); - - // - double target = 0; - - // - // Cycles Conditions ... - - // - // Decision ... - ENUM_XPOI_EVENTS decisionPoiEvents[]; - ENUM_X_CYCLE_EVENTS decisionCycleEvents[]; - X121SMCCycleConditions decisionConditions; - result = decisionCycleHelper.GetConditions( - decisionCycleEvents, - decisionPoiEvents, - decisionConditions, - zIndex, - loopback // - ); - if (!result) - { - // - mConditions.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) - { - // - mConditions.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) - { - // - mConditions.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) - { - // - mConditions.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 ... - - // - XOHCL decisionZBar; - XOHCL decisionCBar; - XOHCL decisionPBar; - double decisionCBarBullishZoneChechValue = 0; - double decisionCBarBearishZoneChechValue = 0; - - // - result = decisionZBar.Init( - decisionState.symbol, - decisionState.period, - 0 // - ); - if (!result) - { - // - Clean(visionPoiEvents); - Clean(analysePoiEvents); - Clean(decisionPoiEvents); - Clean(visionCycleEvents); - Clean(analyseCycleEvents); - Clean(decisionCycleEvents); - Clean(consolidationPoiEvents); - Clean(consolidationCycleEvents); - - // - visionState.Clean(); - analyseState.Clean(); - decisionZBar.Clean(); - decisionCBar.Clean(); - decisionPBar.Clean(); - decisionState.Clean(); - visionConditions.Clean(); - analyseConditions.Clean(); - visionXConditions.Clean(); - consolidationState.Clean(); - decisionConditions.Clean(); - analyseXConditions.Clean(); - decisionXConditions.Clean(); - consolidationConditions.Clean(); - consolidationXConditions.Clean(); - - // - mConditions.Clean(); - - // - return result; - } - - // - result = decisionZBar - .GetPreviousBar(decisionCBar); - if (!result) - { - // - Clean(visionPoiEvents); - Clean(analysePoiEvents); - Clean(decisionPoiEvents); - Clean(visionCycleEvents); - Clean(analyseCycleEvents); - Clean(decisionCycleEvents); - Clean(consolidationPoiEvents); - Clean(consolidationCycleEvents); - - // - visionState.Clean(); - analyseState.Clean(); - decisionZBar.Clean(); - decisionCBar.Clean(); - decisionPBar.Clean(); - decisionState.Clean(); - visionConditions.Clean(); - analyseConditions.Clean(); - visionXConditions.Clean(); - consolidationState.Clean(); - decisionConditions.Clean(); - analyseXConditions.Clean(); - decisionXConditions.Clean(); - consolidationConditions.Clean(); - consolidationXConditions.Clean(); - - // - mConditions.Clean(); - - // - return result; - } - - // - result = decisionCBar - .GetPreviousBar(decisionPBar); - if (!result) - { - // - Clean(visionPoiEvents); - Clean(analysePoiEvents); - Clean(decisionPoiEvents); - Clean(visionCycleEvents); - Clean(analyseCycleEvents); - Clean(decisionCycleEvents); - Clean(consolidationPoiEvents); - Clean(consolidationCycleEvents); - - // - visionState.Clean(); - analyseState.Clean(); - decisionZBar.Clean(); - decisionCBar.Clean(); - decisionPBar.Clean(); - decisionState.Clean(); - visionConditions.Clean(); - analyseConditions.Clean(); - visionXConditions.Clean(); - consolidationState.Clean(); - decisionConditions.Clean(); - analyseXConditions.Clean(); - decisionXConditions.Clean(); - consolidationConditions.Clean(); - consolidationXConditions.Clean(); - - // - mConditions.Clean(); - - // - return result; - } - - // - decisionCBarBullishZoneChechValue = decisionCBar - .GetZoneCheckValue(X_DIRECTION_BULLISH); - decisionCBarBearishZoneChechValue = decisionCBar - .GetZoneCheckValue(X_DIRECTION_BEARISH); - - // - // Check Working Zone ... - bool hasWorkingZone = mConditions.HasWorkingZone(); - if (!hasWorkingZone) - { - // - hasWorkingZone = mConditions.ExtractWorkingZone( - visionState, - consolidationState, - analyseState, - zIndex // - ); - } - - // - result = hasWorkingZone; - if (!result) - { - // - Clean(visionPoiEvents); - Clean(analysePoiEvents); - Clean(decisionPoiEvents); - Clean(visionCycleEvents); - Clean(analyseCycleEvents); - Clean(decisionCycleEvents); - Clean(consolidationPoiEvents); - Clean(consolidationCycleEvents); - - // - visionState.Clean(); - analyseState.Clean(); - decisionZBar.Clean(); - decisionCBar.Clean(); - decisionPBar.Clean(); - decisionState.Clean(); - visionConditions.Clean(); - analyseConditions.Clean(); - visionXConditions.Clean(); - consolidationState.Clean(); - decisionConditions.Clean(); - analyseXConditions.Clean(); - decisionXConditions.Clean(); - consolidationConditions.Clean(); - consolidationXConditions.Clean(); - - // - RemoveDraws(); - RemoveWorkingZoneDraws(); - - // - mConditions.Clean(); - - // - return result; - } - - // - mConditions.UpdateTo(cTime); - - // - // Check Working Zone still Alive ... - ENUM_X_DIRECTION destroyedDir = X_DIRECTION_NONE; - bool isWorkingZoneDestroyed = mConditions - .IsWorkingZoneDestroyed( - destroyedDir, - zIndex, - decisionState.period // - ); - if (isWorkingZoneDestroyed) - { - RemoveWorkingZoneDraws(); - } - - // - result = !isWorkingZoneDestroyed; - if (!result) - { - // - Clean(visionPoiEvents); - Clean(analysePoiEvents); - Clean(decisionPoiEvents); - Clean(visionCycleEvents); - Clean(analyseCycleEvents); - Clean(decisionCycleEvents); - Clean(consolidationPoiEvents); - Clean(consolidationCycleEvents); - - // - visionState.Clean(); - analyseState.Clean(); - decisionZBar.Clean(); - decisionCBar.Clean(); - decisionPBar.Clean(); - decisionState.Clean(); - visionConditions.Clean(); - analyseConditions.Clean(); - visionXConditions.Clean(); - consolidationState.Clean(); - decisionConditions.Clean(); - analyseXConditions.Clean(); - decisionXConditions.Clean(); - consolidationConditions.Clean(); - consolidationXConditions.Clean(); - - // - RemoveDraws(); - RemoveWorkingZoneDraws(); - - // - mConditions.Clean(); - - // - return result; - } - - // - // Detecting Trend ... - ENUM_X_DIRECTION trend; - bool hasTrend = mConditions.DetectTrend( - trend, - period // - ); - bool hasBullishTrend = hasTrend && - IsBullish(trend); - bool hasBearishTrend = hasTrend && - IsBearish(trend); - result = hasTrend; - if (!result) - { - // - Clean(visionPoiEvents); - Clean(analysePoiEvents); - Clean(decisionPoiEvents); - Clean(visionCycleEvents); - Clean(analyseCycleEvents); - Clean(decisionCycleEvents); - Clean(consolidationPoiEvents); - Clean(consolidationCycleEvents); - - // - visionState.Clean(); - analyseState.Clean(); - decisionZBar.Clean(); - decisionCBar.Clean(); - decisionPBar.Clean(); - decisionState.Clean(); - visionConditions.Clean(); - analyseConditions.Clean(); - visionXConditions.Clean(); - consolidationState.Clean(); - decisionConditions.Clean(); - analyseXConditions.Clean(); - decisionXConditions.Clean(); - consolidationConditions.Clean(); - consolidationXConditions.Clean(); - - // - RemoveDraws(); - RemoveWorkingZoneDraws(); - - // - mConditions.Clean(); - - // - return result; - } - - // - // Detect Start Zones ... - bool hasStartZone = mConditions.HasStartZone(); - if (!hasStartZone) - { - // - hasStartZone = mConditions.DetectStartZone( - trend, - analyseState, - decisionCycleHelper // - ); - } - - // - mConditions.UpdateTo(cTime); - - // - // Detect Condition Priority ... - ENUM_X121SMC_XWZ_PRIORITY bullishPriority; - ENUM_X121SMC_XWZ_PRIORITY bearishPriority; - mConditions.DetectPriority( - bullishPriority, - bearishPriority // - ); - - // - bool canLookupLong = bullishPriority != X121SMC_XWZ_PRIORITY_NONE && - bullishPriority != X121SMC_XWZ_PRIORITY_WEAK; - bool canLookupShort = bearishPriority != X121SMC_XWZ_PRIORITY_NONE && - bearishPriority != X121SMC_XWZ_PRIORITY_WEAK; - bool isPriorityPassed = - hasBullishTrend - ? canLookupLong - : hasBearishTrend - ? canLookupShort - : false; - - // - double pivot = 0; - double point = 0; - bool hasCondition = false; - ENUM_X_DIRECTION conditionsDir = X_DIRECTION_NONE; - - // - // Detect Start Zone Based Conditions ... - if (hasStartZone) - { - // - DrawConditions( - mConditions, - visionCycleHelper.mPOIDrawer // - ); - - // - // Detect Start Zone Conditions ... - hasCondition = mConditions - .startZone - .HasCondition( - decisionState, - zIndex, - NULL // period // - ); - conditionsDir = mConditions - .startZone - .GetDirection(); - if (hasCondition) - { - // - XBoxZone startZoneBox; - bool hasBox = mConditions.startZone.AsBox(startZoneBox); - if (hasBox) - { - // - bool isBullish = IsBullish(conditionsDir); - - // - pivot = - isBullish - ? startZoneBox.lower - : startZoneBox.upper; - - // - point = - isBullish - ? startZoneBox.upper - : startZoneBox.lower; - } - } - } - - // - RemoveWorkingZoneDraws(); - DrawWorkingZone(mConditions, visionCycleHelper.mPOIDrawer); - - // - // Detect Supply and Deman Zone Based Conditions ... - if (!hasCondition) - { - // - bool isPriceInsideSupplyZone = - bearishPriority == X121SMC_XWZ_PRIORITY_STRONG_HIGH; - - // - bool isPriceInsideDemandZone = - bullishPriority == X121SMC_XWZ_PRIORITY_STRONG_HIGH; - - // - bool isPriceInsideSupDem = isPriceInsideSupplyZone || - isPriceInsideDemandZone; - if (isPriceInsideSupDem) - { - // - hasCondition = mConditions.HasWorkingZoneConditions( - conditionsDir, - decisionState // - ); - - // - if (hasCondition) - { - // - if (IsBullish(conditionsDir)) - { - // - pivot = mConditions.demandZone.Lower(); - point = mConditions.demandZone.Upper(); - } - else if (IsBearish(conditionsDir)) - { - // - pivot = mConditions.supplyZone.Upper(); - point = mConditions.supplyZone.Lower(); - } - } - } - } - - // - isBullish = IsBullish(conditionsDir); - isBearish = IsBearish(conditionsDir); - - // - double reward; - double amountPercent; - ENUM_X121SMC_XWZ_PRIORITY priority = - isBullish - ? bullishPriority - : bearishPriority; - bool hasRewardAmount = CalculateRiskReward( - priority, - reward, - amountPercent // - ); - - // - bool hasLastBullishConsolidationZone = false; - bool hasLastBearishConsolidationZone = false; - bool hasPrevBullishConsolidationZone = false; - bool hasPrevBearishConsolidationZone = false; - XConsolidationZone lastBullishConsolidationZone; - XConsolidationZone lastBearishConsolidationZone; - XConsolidationZone prevBullishConsolidationZone; - XConsolidationZone prevBearishConsolidationZone; - bool hasConsolidationZones = decisionCycleHelper.HasConsolidationZones(); - if (hasConsolidationZones) - { - // - int cZCount = 0; - XConsolidationZone tmp[]; - - // - cZCount = decisionCycleHelper - .FillConsolidationZones( - X_DIRECTION_BULLISH, - tmp // - ); - if (IsValidSize(cZCount)) - { - // - lastBullishConsolidationZone = tmp[cZCount - 1]; - if (cZCount >= 2) - { - prevBullishConsolidationZone = tmp[cZCount - 2]; - } - } - - // - Clean(tmp); - cZCount = decisionCycleHelper - .FillConsolidationZones( - X_DIRECTION_BEARISH, - tmp // - ); - if (IsValidSize(cZCount)) - { - // - lastBearishConsolidationZone = tmp[cZCount - 1]; - if (cZCount >= 2) - { - prevBearishConsolidationZone = tmp[cZCount - 2]; - } - } - - // - Clean(tmp); - - // - hasLastBullishConsolidationZone = lastBullishConsolidationZone.IsValid(); - hasLastBearishConsolidationZone = lastBearishConsolidationZone.IsValid(); - hasPrevBullishConsolidationZone = prevBullishConsolidationZone.IsValid(); - hasPrevBearishConsolidationZone = prevBearishConsolidationZone.IsValid(); - } - - // - RemoveDraws(); - - // - if (hasLastBullishConsolidationZone) - { - // - XCConsolidationZoneObject *iObj; - bool isCreated = visionCycleHelper - .mPOIDrawer - .CreateConsolidationZone( - lastBullishConsolidationZone, - iObj // - ); - if (isCreated) - { - mObjects.Add(iObj); - } - } - - // - if (hasLastBearishConsolidationZone) - { - // - XCConsolidationZoneObject *iObj; - bool isCreated = visionCycleHelper - .mPOIDrawer - .CreateConsolidationZone( - lastBearishConsolidationZone, - iObj // - ); - if (isCreated) - { - mObjects.Add(iObj); - } - } - - // - if (hasPrevBullishConsolidationZone) - { - // - XCConsolidationZoneObject *iObj; - bool isCreated = visionCycleHelper - .mPOIDrawer - .CreateConsolidationZone( - prevBullishConsolidationZone, - iObj // - ); - if (isCreated) - { - mObjects.Add(iObj); - } - } - - // - if (hasPrevBearishConsolidationZone) - { - // - XCConsolidationZoneObject *iObj; - bool isCreated = visionCycleHelper - .mPOIDrawer - .CreateConsolidationZone( - prevBearishConsolidationZone, - iObj // - ); - if (isCreated) - { - mObjects.Add(iObj); - } - } - - // - bool isConsolidationZonePassed = - isBullish - ? (point > 0 && - hasPrevBullishConsolidationZone && - point >= prevBullishConsolidationZone.upper) - : (point > 0 && - hasPrevBearishConsolidationZone && - point <= prevBearishConsolidationZone.lower); - - // - result = hasCondition && - hasRewardAmount && - isPriorityPassed && - trend == conditionsDir && - isConsolidationZonePassed; - if (!result) - { - // - Clean(visionPoiEvents); - Clean(analysePoiEvents); - Clean(decisionPoiEvents); - Clean(visionCycleEvents); - Clean(analyseCycleEvents); - Clean(decisionCycleEvents); - Clean(consolidationPoiEvents); - Clean(consolidationCycleEvents); - - // - visionState.Clean(); - analyseState.Clean(); - decisionZBar.Clean(); - decisionCBar.Clean(); - decisionPBar.Clean(); - decisionState.Clean(); - visionConditions.Clean(); - analyseConditions.Clean(); - visionXConditions.Clean(); - consolidationState.Clean(); - decisionConditions.Clean(); - analyseXConditions.Clean(); - decisionXConditions.Clean(); - consolidationConditions.Clean(); - consolidationXConditions.Clean(); - - // - lastBullishConsolidationZone.Clean(); - lastBearishConsolidationZone.Clean(); - prevBullishConsolidationZone.Clean(); - prevBearishConsolidationZone.Clean(); - - // - mConditions.Clean(); - - // - return result; - } - - // - // Apply Traget ... - switch (priority) - { - // - case X121SMC_XWZ_PRIORITY_STRONG_HIGH: - // - target = - isBullish - ? mConditions.workingZone.quarter3 - : mConditions.workingZone.quarter1; - break; - - // - case X121SMC_XWZ_PRIORITY_HIGH: - // - target = - isBullish - ? mConditions.workingZone.quarter3 - : mConditions.workingZone.quarter1; - break; - - // - case X121SMC_XWZ_PRIORITY_REGULAR: - // - target = - isBullish - ? mConditions.workingZone.quarter2 - : mConditions.workingZone.quarter2; - break; - - // - case X121SMC_XWZ_PRIORITY_LOW: - // - target = - isBullish - ? mConditions.workingZone.quarter1 - : mConditions.workingZone.quarter3; - break; - - // - default: - target = 0; - break; - } - - // - mConditions.pivot = pivot; - mConditions.point = point; - mConditions.reward = reward; - mConditions.target = target; - mConditions.setupTime = cTime; - mConditions.priority = priority; - mConditions.dir = conditionsDir; - mConditions.amountPercent = amountPercent; - - // - mConditions.UpdateTo(cTime); - - // - DrawConditions( - mConditions, - visionCycleHelper.mPOIDrawer // - ); - - // - Clean(visionPoiEvents); - Clean(analysePoiEvents); - Clean(decisionPoiEvents); - Clean(visionCycleEvents); - Clean(analyseCycleEvents); - Clean(decisionCycleEvents); - Clean(consolidationPoiEvents); - Clean(consolidationCycleEvents); - - // - visionState.Clean(); - analyseState.Clean(); - decisionZBar.Clean(); - decisionCBar.Clean(); - decisionPBar.Clean(); - decisionState.Clean(); - visionConditions.Clean(); - analyseConditions.Clean(); - visionXConditions.Clean(); - consolidationState.Clean(); - decisionConditions.Clean(); - analyseXConditions.Clean(); - decisionXConditions.Clean(); - consolidationConditions.Clean(); - consolidationXConditions.Clean(); - - // - lastBullishConsolidationZone.Clean(); - lastBearishConsolidationZone.Clean(); - prevBullishConsolidationZone.Clean(); - prevBearishConsolidationZone.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; - - // - string symbol = _symbol; - ENUM_TIMEFRAMES period = _period; - - // - XOHCL zBar; - result = decisionCycleHelper.GetBar( - zBar, - zIndex // - ); - if (!result) - { - return result; - } - - // - XOHCL cBar; - result = decisionCycleHelper.GetBar( - cBar, - cIndex // - ); - if (!result) - { - return result; - } - - // - XOHCL pBar; - result = decisionCycleHelper.GetBar( - pBar, - pIndex // - ); - if (!result) - { - return result; - } - - // - double ask = GetAsk(symbol); - double bid = GetBid(symbol); - datetime cTime = TimeCurrent(); - double points = GetPoints(symbol); - - // - int swingLoopback = 9; - double ll = cBar.FindLowest(swingLoopback, MODE_LOW); - double hh = cBar.FindHighest(swingLoopback, MODE_HIGH); - double llDown = cBar.FindLowesttDown(swingLoopback); - double hhUp = cBar.FindHighestUp(swingLoopback); - - // - // 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 ... - zBar.Clean(); - cBar.Clean(); - pBar.Clean(); - - // - Clean(decisionPoiEvents); - Clean(decisionCycleEvents); - - // - decisionConditions.Clean(); - - // - return result; - } - - // - // Cycles POI States ... - XPOIState decisionState = decisionConditions.state; - - // - // Cycle X121Conditions ... - X121Conditions decisionXConditions = decisionConditions.x121Conditions; - - // - // Trigger Conditions ... - - // - double point = conditions.point; - bool isPointBreaked = IsBarBreak( - point, - setupDir, - cBar // - ); - - // - // Summary ... - - // - isBullish = - // - isBullish - // && - // isPointBreaked - // - ; - - // - isBearish = - // - isBearish - // && - // isPointBreaked - // - ; - - // - result = isBullish || - isBearish; - if (!result) - { - // - // Cleanup Setup Conditions ... - int setupAge = conditions.GetSetupAge(); - if (IsValidSize(setupAge) && - IsValidSize(maxAllowedSetupAge) && - setupAge >= maxAllowedSetupAge) - { - conditions.Clean(); - } - - // - // Cleanup ... - zBar.Clean(); - cBar.Clean(); - pBar.Clean(); - - // - Clean(decisionPoiEvents); - Clean(decisionCycleEvents); - - // - decisionState.Clean(); - decisionConditions.Clean(); - decisionXConditions.Clean(); - - // - return result; - } - - // - // Detect Nearest Pivot Point ... - - // - double entry = GetEntry( - conditions.symbol, - setupDir // - ); - - // - // Manipulate SL Based on Consolidation Zones ... - - // - double sls[]; - Add( - conditions.pivot, - sls // - ); - - // - double iAtr = decisionXConditions.atrBuffer[1]; - iAtr *= 2; - - // - 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; - - // - // Cleanup ... - zBar.Clean(); - cBar.Clean(); - pBar.Clean(); - - // - Clean(decisionPoiEvents); - Clean(decisionCycleEvents); - - // - decisionState.Clean(); - decisionConditions.Clean(); - decisionXConditions.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 - // - ; - - // - // TODO: Implement Guards ... - return false; - - // - result = isCycleHelpersValid; - if (!result) - { - return result; - } - - // - int count = ArraySize(positions); - result = IsValidSize(count); - if (!result) - { - return result; - } - - // - string symbol = decisionCycleHelper.GetSymbol(); - ENUM_TIMEFRAMES period = decisionCycleHelper.GetPeriod(); - 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 ... - - // - XBoxZone lastBullishBox; - XBoxZone prevLastBullishBox; - bool hasLastBullishBox = false; - bool hasPrevLastBullishBox = false; - XConsolidationZone lastBullishZone; - bool isLastBullishAbovePrev = false; - bool isLastBullishBelowPrev = false; - XConsolidationZone prevLastBullishZone; - - // - XBoxZone lastBearishBox; - XBoxZone prevLastBearishBox; - bool hasLastBearishBox = false; - bool hasPrevLastBearishBox = false; - XConsolidationZone lastBearishZone; - bool isLastBearishAbovePrev = false; - bool isLastBearishBelowPrev = false; - XConsolidationZone prevLastBearishZone; - - // - int bullishConsolidationZonesCount = 0; - int bearishConsolidationZonesCount = 0; - bool hasBullishConsolidationZones = false; - bool hasBearishConsolidationZones = false; - XConsolidationZone bullishConsolidationZones[]; - XConsolidationZone bearishConsolidationZones[]; - bool hasConsolidationZones = decisionCycleHelper.HasConsolidationZones(); - int consolidationZonesCount = decisionCycleHelper.CountConsolidationZones(); - if (hasConsolidationZones) - { - // - bullishConsolidationZonesCount = decisionCycleHelper - .FillConsolidationZones( - X_DIRECTION_BULLISH, - bullishConsolidationZones // - ); - hasBullishConsolidationZones = IsValidSize(bullishConsolidationZonesCount); - - // - bearishConsolidationZonesCount = decisionCycleHelper - .FillConsolidationZones( - X_DIRECTION_BEARISH, - bearishConsolidationZones // - ); - hasBearishConsolidationZones = IsValidSize(bearishConsolidationZonesCount); - - // - // - // - - // - if (hasBullishConsolidationZones && - bullishConsolidationZonesCount >= 2) - { - // - lastBullishZone = bullishConsolidationZones[bullishConsolidationZonesCount - 1]; - prevLastBullishZone = bullishConsolidationZones[bullishConsolidationZonesCount - 2]; - - // - hasLastBullishBox = ToBox( - lastBullishBox, - lastBullishZone // - ); - hasPrevLastBullishBox = ToBox( - prevLastBullishBox, - prevLastBullishZone // - ); - - // - isLastBullishAbovePrev = hasLastBullishBox && - hasPrevLastBullishBox && - IsBoxAbove( - lastBullishBox, - prevLastBullishBox // - ); - - // - isLastBullishBelowPrev = hasLastBullishBox && - hasPrevLastBullishBox && - IsBoxBelow( - lastBullishBox, - prevLastBullishBox // - ); - } - - // - if (hasBearishConsolidationZones && - bearishConsolidationZonesCount >= 2) - { - // - lastBearishZone = bearishConsolidationZones[bearishConsolidationZonesCount - 1]; - prevLastBearishZone = bearishConsolidationZones[bearishConsolidationZonesCount - 2]; - - // - hasLastBearishBox = ToBox( - lastBearishBox, - lastBearishZone // - ); - hasPrevLastBearishBox = ToBox( - prevLastBearishBox, - prevLastBearishZone // - ); - - // - isLastBearishAbovePrev = hasLastBearishBox && - hasPrevLastBearishBox && - IsBoxAbove( - lastBearishBox, - prevLastBearishBox // - ); - - // - isLastBearishBelowPrev = hasLastBearishBox && - hasPrevLastBearishBox && - IsBoxBelow( - lastBearishBox, - prevLastBearishBox // - ); - } - - // - } - - // - // 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 isStrongSwingLowAboveLastBullishBox = - isStrongSwingLow && - hasLastBullishBox && - pBar.low > lastBullishBox.upper; - - // - bool isStrongSwingHighBelowLastBearishBox = - isStrongSwingHigh && - hasLastBearishBox && - pBar.high < lastBearishBox.lower; - - // - // 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 ... - - // - // 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(); - - // - lastBullishBox.Clean(); - lastBearishBox.Clean(); - lastBullishZone.Clean(); - lastBearishZone.Clean(); - prevLastBullishBox.Clean(); - prevLastBearishBox.Clean(); - prevLastBullishZone.Clean(); - prevLastBearishZone.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; - } - - // - // Draw Functions ... - // - - // - void RemoveDraws() - { - mObjects.Clear(); - } - - // - void RemoveWorkingZoneDraws() - { - mWorkingZoneObjects.Clear(); - } - - // - void DrawOrderBlock( - XCOrderBlock *ob, - XCPOIDrawer *drawer, - bool forWorkingZone = false // - ) - { - // - if (ob == NULL || - drawer == NULL) - { - return; - } - - // - ENUM_X_DIRECTION forDir = ob.GetDirection(); - - // - color bullishColor = drawer.BarBullishColor(); - color bearishColor = drawer.BarBearishColor(); - color forColor = IsBullish(forDir) - ? bullishColor - : bearishColor; - - // - // Draw Order Block ... - XCBaseObject *obj; - bool isCreated = drawer.CreateOrderBlock( - ob, - obj // - ); - if (isCreated) - { - // - if (forWorkingZone) - { - mWorkingZoneObjects.Add(obj); - } - else - { - mObjects.Add(obj); - } - } - - // - ulong chartID = drawer.ChartIdentification(); - int subWindow = drawer.SubWindowIdentification(); - - // - XOHCL startedBar; - ENUM_X_DIRECTION startedDir; - bool isStarted = ob.IsStarted( - forDir, - startedBar, - startedDir // - ); - if (isStarted) - { - // - datetime to = startedBar.time + (PeriodSeconds(startedBar.period)); - - // - XCOHCLObject *obj; - bool isCreated = drawer.CreateBar( - startedBar, - obj, - to // - ); - if (isCreated) - { - // - obj.BodyColor(clrYellow); - obj.HighShadowColor(clrYellow); - obj.LowShadowColor(clrYellow); - - // - obj.BodyStyle(STYLE_SOLID); - obj.HighShadowStyle(STYLE_SOLID); - obj.LowShadowStyle(STYLE_SOLID); - - // - if (forWorkingZone) - { - mWorkingZoneObjects.Add(obj); - } - else - { - mObjects.Add(obj); - } - } - - // - string startVLineName = "Start_" + ob.GetTag(); - - // - CChartObjectVLine *startVLine; - startVLine = new CChartObjectVLine(); - isCreated = startVLine.Create( - chartID, - startVLineName, - subWindow, - startedBar.time // - ); - if (isCreated) - { - // - startVLine.Color(forColor); - - // - if (forWorkingZone) - { - mWorkingZoneObjects.Add(startVLine); - } - else - { - mObjects.Add(startVLine); - } - } - } - } - - // - void DrawFairValueGap( - XCFVG *fvg, - XCPOIDrawer *drawer, - bool forWorkingZone = false // - ) - { - // - if (fvg == NULL || - drawer == NULL) - { - return; - } - - // - ENUM_X_DIRECTION forDir = fvg.GetDirection(); - - // - color bullishColor = drawer.BarBullishColor(); - color bearishColor = drawer.BarBearishColor(); - color forColor = IsBullish(forDir) - ? bullishColor - : bearishColor; - - // - // Draw Order Block ... - XCBaseObject *obj; - bool isCreated = drawer.CreateFairValueGap( - fvg, - obj // - ); - if (isCreated) - { - // - if (forWorkingZone) - { - mWorkingZoneObjects.Add(obj); - } - else - { - mObjects.Add(obj); - } - } - - // - ulong chartID = drawer.ChartIdentification(); - int subWindow = drawer.SubWindowIdentification(); - - // - XOHCL startedBar; - ENUM_X_DIRECTION startedDir; - bool isStarted = fvg.IsStarted( - forDir, - startedBar, - startedDir // - ); - if (isStarted) - { - // - datetime to = startedBar.time + (PeriodSeconds(startedBar.period)); - - // - XCOHCLObject *obj; - bool isCreated = drawer.CreateBar( - startedBar, - obj, - to // - ); - if (isCreated) - { - // - obj.BodyColor(clrYellow); - obj.HighShadowColor(clrYellow); - obj.LowShadowColor(clrYellow); - - // - obj.BodyStyle(STYLE_SOLID); - obj.HighShadowStyle(STYLE_SOLID); - obj.LowShadowStyle(STYLE_SOLID); - - // - if (forWorkingZone) - { - mWorkingZoneObjects.Add(obj); - } - else - { - mObjects.Add(obj); - } - } - - // - string startVLineName = "Start_" + fvg.GetTag(); - - // - CChartObjectVLine *startVLine; - startVLine = new CChartObjectVLine(); - isCreated = startVLine.Create( - chartID, - startVLineName, - subWindow, - startedBar.time // - ); - if (isCreated) - { - // - startVLine.Color(forColor); - - // - if (forWorkingZone) - { - mWorkingZoneObjects.Add(startVLine); - } - else - { - mObjects.Add(startVLine); - } - } - } - } - - // - void DrawWorkingZone( - X121SMCStrategyXWZSignalConditions &conditions, - XCPOIDrawer *drawer // - ) - { - // - if (drawer == NULL) - { - return; - } - - // - bool hasWorkingZone = conditions.HasWorkingZone(); - if (!hasWorkingZone) - { - return; - } - - // - string prefix = "WKZ_" + conditions.workingZone.symbol + ToString(conditions.workingZone.period) + "_"; - string tag = prefix + ToString(conditions.workingZone.upper) + "_" + ToString(conditions.workingZone.lower); - string suffix = ToMD5(tag); - - // - string upperName = prefix + "_Upper_" + suffix; - string lowerName = prefix + "_Lower_" + suffix; - string zoneUpperName = prefix + "_ZoneUpper_" + suffix; - string zoneLowerName = prefix + "_ZoneLower_" + suffix; - - // - string q1Name = prefix + "_Q1_" + suffix; - string q2Name = prefix + "_Q2_" + suffix; - string q3Name = prefix + "_Q3_" + suffix; - - // - ulong chartID = drawer.ChartIdentification(); - int subWindow = drawer.SubWindowIdentification(); - - // - bool isCreated = false; - - // - // Check For Trend Approced ... - bool isTrendApproved = conditions.HasOrderBlock() && - conditions.HasFairValueGap(); - if (isTrendApproved) - { - // - DrawOrderBlock( - conditions.orderBlock, - drawer, - true // - ); - - // - DrawFairValueGap( - conditions.fairValueGap, - drawer, - true // - ); - } - - // - XCSupplyZoneObject *iSupObj; - isCreated = drawer.CreateSupplyZone( - conditions.supplyZone, - iSupObj // - ); - if (isCreated) - { - mWorkingZoneObjects.Add(iSupObj); - } - - // - XCDemandZoneObject *iDemObj; - isCreated = drawer.CreateDemandZone( - conditions.demandZone, - iDemObj // - ); - if (isCreated) - { - mWorkingZoneObjects.Add(iDemObj); - } - - // - // Lower ... - CChartObjectTrend *lowerHLine; - lowerHLine = new CChartObjectTrend(); - isCreated = lowerHLine.Create( - chartID, - lowerName, - subWindow, - conditions.workingZone.from, - conditions.workingZone.lower, - conditions.workingZone.to, - conditions.workingZone.lower // - ); - if (isCreated) - { - // - lowerHLine.Color(clrLime); - mWorkingZoneObjects.Add(lowerHLine); - } - - // - CChartObjectTrend *upperHLine; - upperHLine = new CChartObjectTrend(); - isCreated = upperHLine.Create( - chartID, - upperName, - subWindow, - conditions.workingZone.from, - conditions.workingZone.upper, - conditions.workingZone.to, - conditions.workingZone.upper // - ); - if (isCreated) - { - // - upperHLine.Color(clrLime); - mWorkingZoneObjects.Add(upperHLine); - } - - // - CChartObjectTrend *zoneLowerHLine; - zoneLowerHLine = new CChartObjectTrend(); - isCreated = zoneLowerHLine.Create( - chartID, - zoneLowerName, - subWindow, - conditions.workingZone.from, - conditions.workingZone.zoneLower, - conditions.workingZone.to, - conditions.workingZone.zoneLower // - ); - if (isCreated) - { - // - zoneLowerHLine.Color(clrRed); - mWorkingZoneObjects.Add(zoneLowerHLine); - } - - // - CChartObjectTrend *zoneUpperHLine; - zoneUpperHLine = new CChartObjectTrend(); - isCreated = zoneUpperHLine.Create( - chartID, - zoneUpperName, - subWindow, - conditions.workingZone.from, - conditions.workingZone.zoneUpper, - conditions.workingZone.to, - conditions.workingZone.zoneUpper // - ); - if (isCreated) - { - // - zoneUpperHLine.Color(clrRed); - mWorkingZoneObjects.Add(zoneUpperHLine); - } - - // - CChartObjectTrend *quarter1HLine; - quarter1HLine = new CChartObjectTrend(); - isCreated = quarter1HLine.Create( - chartID, - q1Name, - subWindow, - conditions.workingZone.from, - conditions.workingZone.quarter1, - conditions.workingZone.to, - conditions.workingZone.quarter1 // - ); - if (isCreated) - { - // - quarter1HLine.Color(clrYellow); - mWorkingZoneObjects.Add(quarter1HLine); - } - - // - CChartObjectTrend *quarter2HLine; - quarter2HLine = new CChartObjectTrend(); - isCreated = quarter2HLine.Create( - chartID, - q2Name, - subWindow, - conditions.workingZone.from, - conditions.workingZone.quarter2, - conditions.workingZone.to, - conditions.workingZone.quarter2 // - ); - if (isCreated) - { - // - quarter2HLine.Color(clrYellow); - mWorkingZoneObjects.Add(quarter2HLine); - } - - // - CChartObjectTrend *quarter3HLine; - quarter3HLine = new CChartObjectTrend(); - isCreated = quarter3HLine.Create( - chartID, - q3Name, - subWindow, - conditions.workingZone.from, - conditions.workingZone.quarter3, - conditions.workingZone.to, - conditions.workingZone.quarter3 // - ); - if (isCreated) - { - // - quarter3HLine.Color(clrYellow); - mWorkingZoneObjects.Add(quarter3HLine); - } - - // - } - - // - void DrawConditions( - X121SMCStrategyXWZSignalConditions &conditions, - XCPOIDrawer *drawer, - bool forceClean = false // - ) - { - // - if (drawer == NULL) - { - return; - } - - // - if (forceClean) - { - mObjects.Clear(); - } - - // - bool isCreated = false; - - // - ulong chartID = drawer.ChartIdentification(); - int subWindow = drawer.SubWindowIdentification(); - color bullishColor = drawer.BarBullishColor(); - color bearishColor = drawer.BarBearishColor(); - - // - // Start Zone ... - bool hasStartZone = conditions.HasStartZone(); - if (hasStartZone) - { - // - bool isBullish = conditions.startZone.IsBullish(); - - // - bool hasOB = conditions.startZone.HasOB(); - if (hasOB) - { - // // - // XCBaseObject *iObj; - // isCreated = drawer.CreateOrderBlock( - // conditions.startZone.ob, - // iObj // - // ); - - // // - // if (isCreated) - // { - // mObjects.Add(iObj); - // } - - // - DrawOrderBlock( - conditions.startZone.ob, - drawer // - ); - } - - // - bool hasFVG = conditions.startZone.HasFVG(); - if (hasFVG) - { - // // - // XCBaseObject *iObj; - // isCreated = drawer.CreateFairValueGap( - // conditions.startZone.fvg, - // iObj // - // ); - - // // - // if (isCreated) - // { - // mObjects.Add(iObj); - // } - - // - DrawFairValueGap( - conditions.startZone.fvg, - drawer // - ); - } - - // - bool hasSupply = conditions.startZone.HasSupply(); - if (hasSupply) - { - // - XCSupplyZoneObject *iObj; - isCreated = drawer.CreateSupplyZone( - conditions.startZone.supply, - iObj // - ); - - // - if (isCreated) - { - mObjects.Add(iObj); - } - } - - // - bool hasDemand = conditions.startZone.HasDemand(); - if (hasDemand) - { - // - XCDemandZoneObject *iObj; - isCreated = drawer.CreateDemandZone( - conditions.startZone.demand, - iObj // - ); - - // - if (isCreated) - { - mObjects.Add(iObj); - } - } - - // - bool hasSupport = conditions.startZone.HasSupport(); - if (hasSupport) - { - // - XCSupportZoneObject *iObj; - isCreated = drawer.CreateSupportZone( - conditions.startZone.support, - iObj // - ); - - // - if (isCreated) - { - mObjects.Add(iObj); - } - } - - // - bool hasResistance = conditions.startZone.HasResistance(); - if (hasResistance) - { - // - XCResistanceZoneObject *iObj; - isCreated = drawer.CreateResistanceZone( - conditions.startZone.resistance, - iObj // - ); - - // - if (isCreated) - { - mObjects.Add(iObj); - } - } - - // - bool hasBullishCZone = conditions.startZone.HasBullishConsolidationZone(); - if (hasBullishCZone) - { - // - XCConsolidationZoneObject *iObj; - isCreated = drawer.CreateConsolidationZone( - conditions.startZone.bullishConsolidationZone, - iObj // - ); - - // - if (isCreated) - { - mObjects.Add(iObj); - } - } - - // - bool hasBearishCZone = conditions.startZone.HasBearishConsolidationZone(); - if (hasBearishCZone) - { - // - XCConsolidationZoneObject *iObj; - isCreated = drawer.CreateConsolidationZone( - conditions.startZone.bearishConsolidationZone, - iObj // - ); - - // - if (isCreated) - { - mObjects.Add(iObj); - } - } - - // - // - // - - // - string bName = ""; - int arrowCode = 0; - string bSuffix = ""; - color arrowColor = clrNONE; - ENUM_X_PRICE bPrice = X_PRICE_CLOSE; - - // - bool hasSwingBar = conditions.startZone.swingBar.IsValid(); - if (hasSwingBar) - { - // - bSuffix = ToMD5(conditions.startZone.swingBar.GetTag()); - bName = - (isBullish - ? "SWING_LOW" - : "SWING_HIGH") + - "_" + bSuffix; - arrowCode = 159; - arrowColor = - isBullish - ? bullishColor - : bearishColor; - bPrice = - isBullish - ? X_PRICE_LOW - : X_PRICE_HIGH; - - // - XCBarArrowObject *iObj; - iObj = new XCBarArrowObject(); - isCreated = iObj.CreateByBar( - chartID, - bName, - subWindow, - arrowCode, - conditions.startZone.swingBar, - bPrice // - ); - if (isCreated) - { - // - iObj.ArrowColor(arrowColor); - - // - mObjects.Add(iObj); - } - } - - // - bool hasBreakerBar = conditions.startZone.breakerBar.IsValid(); - if (hasBreakerBar) - { - // - bSuffix = ToMD5(conditions.startZone.breakerBar.GetTag()); - bName = - (isBullish - ? "BULL_BREAKER" - : "BEAR_BREAKER") + - "_" + bSuffix; - arrowCode = - isBullish - ? 71 - : 72; - arrowColor = - isBullish - ? bullishColor - : bearishColor; - bPrice = - isBullish - ? X_PRICE_LOW - : X_PRICE_HIGH; - - // - XCBarArrowObject *iObj; - iObj = new XCBarArrowObject(); - isCreated = iObj.CreateByBar( - chartID, - bName, - subWindow, - arrowCode, - conditions.startZone.breakerBar, - bPrice // - ); - if (isCreated) - { - // - iObj.ArrowColor(arrowColor); - - // - mObjects.Add(iObj); - } - } - - // - bool hasMomentumBar = conditions.startZone.momentumBar.IsValid(); - if (hasMomentumBar) - { - // - bSuffix = ToMD5(conditions.startZone.momentumBar.GetTag()); - bName = - (isBullish - ? "BULL_MOMENTUM" - : "BEAR_MOMENTUM") + - "_" + bSuffix; - arrowCode = - isBullish - ? 233 - : 234; - arrowColor = - isBullish - ? bullishColor - : bearishColor; - bPrice = - isBullish - ? X_PRICE_LOW - : X_PRICE_HIGH; - - // - XCBarArrowObject *iObj; - iObj = new XCBarArrowObject(); - isCreated = iObj.CreateByBar( - chartID, - bName, - subWindow, - arrowCode, - conditions.startZone.momentumBar, - bPrice // - ); - if (isCreated) - { - // - iObj.ArrowColor(arrowColor); - - // - mObjects.Add(iObj); - } - } - - // - bool hasRejectionBar = conditions.startZone.rejectionBar.IsValid(); - if (hasRejectionBar) - { - // - bSuffix = ToMD5(conditions.startZone.rejectionBar.GetTag()); - bName = - (isBullish - ? "BULL_REJECTION" - : "BEAR_REJECTION") + - "_" + bSuffix; - arrowCode = - isBullish - ? 241 - : 242; - arrowColor = - isBullish - ? bullishColor - : bearishColor; - bPrice = - isBullish - ? X_PRICE_LOW - : X_PRICE_HIGH; - - // - XCBarArrowObject *iObj; - iObj = new XCBarArrowObject(); - isCreated = iObj.CreateByBar( - chartID, - bName, - subWindow, - arrowCode, - conditions.startZone.rejectionBar, - bPrice // - ); - if (isCreated) - { - // - iObj.ArrowColor(arrowColor); - - // - mObjects.Add(iObj); - } - } - - // - bool hasAppliedBox = conditions.startZone.appliedBox.IsValid(); - if (hasAppliedBox) - { - // - arrowColor = - IsBullish(conditions.startZone.appliedBox.dir) - ? bullishColor - : bearishColor; - - // - XCBoxObject *iObj; - isCreated = drawer.CreateBox( - conditions.startZone.appliedBox, - iObj // - ); - - // - if (isCreated) - { - // - iObj.BoxWidth(2); - iObj.BoxColor(arrowColor); - - // - mObjects.Add(iObj); - } - } - } - } - - // - protected: - // - - // - private: - // - // Props ... - CArrayObj mObjects; - CArrayObj mWorkingZoneObjects; - - /** - * Initialize ... - */ - void Init() - { - } - - /** - * DeInitialize ... - */ - void DeInit() - { - // - RemoveDraws(); - mConditions.Clean(); - RemoveWorkingZoneDraws(); - Clean(mConditionsCollection); - } - - // - // 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/xsupdem/x-121.smc.xwz.signal.lib.mq5 b/Documents/BKP/xsupdem/x-121.smc.xwz.signal.lib.mq5 deleted file mode 100644 index 23b7f262..00000000 --- a/Documents/BKP/xsupdem/x-121.smc.xwz.signal.lib.mq5 +++ /dev/null @@ -1,3283 +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_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 X121SMCXWZZone -{ - // - // Props ... - XCFVG *fvg; - XCOrderBlock *ob; - XCSupplyZone *supply; - XCDemandZone *demand; - XCSupportZone *support; - XCResistanceZone *resistance; - XConsolidationZone bullishConsolidationZone; - XConsolidationZone bearishConsolidationZone; - - // - XOHCL swingBar; - XOHCL breakerBar; - XOHCL momentumBar; - XOHCL rejectionBar; - XBoxZone appliedBox; - - // - // Constructor ... - X121SMCXWZZone() - { - Clean(); - } - - // - // Tools ... - - // - void Clean() - { - // - ZeroMemory(ob); - ZeroMemory(fvg); - ZeroMemory(supply); - ZeroMemory(demand); - ZeroMemory(support); - ZeroMemory(resistance); - - // - swingBar.Clean(); - breakerBar.Clean(); - appliedBox.Clean(); - momentumBar.Clean(); - rejectionBar.Clean(); - - // - bullishConsolidationZone.Clean(); - bearishConsolidationZone.Clean(); - } - - // - bool IsValid() - { - // - return HasOB() && - HasFVG() && - HasDirection(); - } - - // - bool AsBox(XBoxZone &box) - { - // - bool result = false; - - // - box.Clean(); - - // - result = IsValid() && - HasDirection(); - if (!result) - { - return result; - } - - // - XBoxZone obBox; - bool hasOBBox = ToBox( - obBox, - ob // - ); - result = hasOBBox; - if (!result) - { - // - box.Clean(); - obBox.Clean(); - return result; - } - - // - box = obBox; - - // - obBox.Clean(); - - // - bool hasOB = HasOB(); - bool hasFVG = HasFVG(); - bool hasSupply = HasSupply(); - bool hasDemand = HasDemand(); - bool hasSupport = HasSupport(); - bool hasResistance = HasResistance(); - - // - // OB Compared since box used obBox ... - - // - if (hasFVG) - { - // - if (fvg.Upper() > box.upper) - { - box.upper = fvg.Upper(); - } - - // - if (fvg.Lower() < box.lower) - { - box.lower = fvg.Lower(); - } - } - - // - result = box.IsValid(); - - // - return result; - } - - // - bool HasOB() - { - return ob != NULL && - ob.IsValid(); - } - - // - bool HasFVG() - { - return fvg != NULL && - fvg.IsValid(); - } - - // - bool HasSupply() - { - return supply != NULL && - supply.IsValid(); - } - - // - bool HasDemand() - { - return demand != NULL && - demand.IsValid(); - } - - // - bool HasSupport() - { - return support != NULL && - support.IsValid(); - } - - // - bool HasResistance() - { - return resistance != NULL && - resistance.IsValid(); - } - - // - bool HasBullishConsolidationZone() - { - return bullishConsolidationZone.IsValid() && - bullishConsolidationZone.IsBreaked() && - IsBullish(bullishConsolidationZone.breakDir); - } - - // - bool HasBearishConsolidationZone() - { - return bearishConsolidationZone.IsValid() && - bearishConsolidationZone.IsBreaked() && - IsBullish(bearishConsolidationZone.breakDir); - } - - // - bool IsBullish() - { - // - return HasOB() && - ob.IsBullish() && - HasFVG() && - fvg.IsBullish() && - HasSupport() && - HasDemand(); - } - - // - bool IsBearish() - { - // - return HasOB() && - ob.IsBearish() && - HasFVG() && - fvg.IsBearish() && - HasSupply() && - HasResistance(); - } - - // - bool HasDirection() - { - return IsBullish() || - IsBearish(); - } - - // - ENUM_X_DIRECTION GetDirection() - { - // - ENUM_X_DIRECTION result = X_DIRECTION_NONE; - - // - bool hasDirection = HasDirection(); - if (!hasDirection) - { - return result; - } - - // - bool isBullish = IsBullish(); - - // - result = - isBullish - ? X_DIRECTION_BULLISH - : X_DIRECTION_BEARISH; - - // - return result; - } - - // - bool HasCondition( - XPOIState &state, - int barIndex = 0, - ENUM_TIMEFRAMES forPeriod = NULL // - ) - { - // - bool result = false; - - // - if (barIndex < 0) - { - barIndex = 0; - } - - // - swingBar.Clean(); - breakerBar.Clean(); - appliedBox.Clean(); - momentumBar.Clean(); - rejectionBar.Clean(); - - // - result = IsValid() && - HasDirection() && - state.IsValid() && - state.HasChild(); - if (!result) - { - // - swingBar.Clean(); - breakerBar.Clean(); - appliedBox.Clean(); - momentumBar.Clean(); - rejectionBar.Clean(); - - // - return result; - } - - // - string symbol = ob.GetSymbol(); - if (!IsValid(forPeriod)) - { - forPeriod = ob.GetPeriod(); - } - datetime cTime = iTime( - symbol, - forPeriod, - barIndex // - ); - - // - bool isInside = IsPriceInside( - barIndex, - forPeriod // - ); - result = isInside; - if (!result) - { - return result; - } - - // - XBoxZone box; - result = AsBox(box); - if (!result) - { - // - box.Clean(); - - // - swingBar.Clean(); - breakerBar.Clean(); - appliedBox.Clean(); - momentumBar.Clean(); - rejectionBar.Clean(); - - // - return result; - } - - // - bool isBullish = IsBullish(); - ENUM_X_DIRECTION forDir = box.dir; - - // - int supportsCount = 0; - bool hasSupports = false; - XCSupportZone *supports[]; - - // - int resistancesCount = 0; - bool hasResistances = false; - XCResistanceZone *resistances[]; - - // - XBoxZone supResBoxes[]; - int supresBoxesCount = 0; - bool hasSupResBoxes = false; - - // - int count = 0; - bool has = false; - - // - has = state.HasSupportZones(); - if (has) - { - // - count = state.CountSupportZones(); - for (int i = 0; i < count; i++) - { - // - XCSupportZone *iZone = state.supportZones[i]; - - // - iZone.To(cTime); - - // - XBoxZone iBox; - bool hasBox = ToBox( - iBox, - iZone // - ); - if (!hasBox) - { - // - iBox.Clean(); - continue; - } - - // - // Check From ... - bool isInside = IsBoxInside( - iBox, - box // - ); - if (!isInside) - { - // - iBox.Clean(); - continue; - } - - // - Add( - iZone, - supports // - ); - - // - AddRef( - iBox, - supResBoxes // - ); - - // - iBox.Clean(); - } - - // - supportsCount = ArraySize(supports); - hasSupports = IsValidSize(supportsCount); - - // - supresBoxesCount = ArraySize(supResBoxes); - hasSupResBoxes = IsValidSize(supresBoxesCount); - } - - // - has = state.HasResistanceZones(); - if (has) - { - // - count = state.CountResistanceZones(); - for (int i = 0; i < count; i++) - { - // - XCResistanceZone *iZone = state.resistanceZones[i]; - - // - iZone.To(cTime); - - // - XBoxZone iBox; - bool hasBox = ToBox( - iBox, - iZone // - ); - if (!hasBox) - { - // - iBox.Clean(); - continue; - } - - // - // Check From ... - bool isInside = IsBoxInside( - iBox, - box // - ); - if (!isInside) - { - // - iBox.Clean(); - continue; - } - - // - Add( - iZone, - resistances // - ); - - // - AddRef( - iBox, - supResBoxes // - ); - - // - iBox.Clean(); - } - - // - resistancesCount = ArraySize(resistances); - hasResistances = IsValidSize(resistancesCount); - - // - supresBoxesCount = ArraySize(supResBoxes); - hasSupResBoxes = IsValidSize(supresBoxesCount); - } - - // - result = hasSupResBoxes; - if (!result) - { - // - box.Clean(); - Clean(supports); - Clean(resistances); - Clean(supResBoxes); - - // - swingBar.Clean(); - breakerBar.Clean(); - appliedBox.Clean(); - momentumBar.Clean(); - rejectionBar.Clean(); - - // - return result; - } - - // - // Detect Bars ... - - // - XOHCL zBar; - result = zBar.Init( - symbol, - forPeriod, - barIndex // - ); - if (!result) - { - // - box.Clean(); - zBar.Clean(); - Clean(supports); - Clean(resistances); - Clean(supResBoxes); - - // - swingBar.Clean(); - breakerBar.Clean(); - appliedBox.Clean(); - momentumBar.Clean(); - rejectionBar.Clean(); - - // - return result; - } - - // - XOHCL cBar; - result = zBar.GetPreviousBar(cBar); - if (!result) - { - // - box.Clean(); - zBar.Clean(); - cBar.Clean(); - Clean(supports); - Clean(resistances); - Clean(supResBoxes); - - // - swingBar.Clean(); - breakerBar.Clean(); - appliedBox.Clean(); - momentumBar.Clean(); - rejectionBar.Clean(); - - // - return result; - } - - // - XOHCL pBar; - result = cBar.GetPreviousBar(pBar); - if (!result) - { - // - box.Clean(); - zBar.Clean(); - cBar.Clean(); - pBar.Clean(); - Clean(supports); - Clean(resistances); - Clean(supResBoxes); - - // - swingBar.Clean(); - breakerBar.Clean(); - appliedBox.Clean(); - momentumBar.Clean(); - rejectionBar.Clean(); - - // - return result; - } - - // - XOHCL ppBar; - result = pBar.GetPreviousBar(ppBar); - if (!result) - { - // - box.Clean(); - zBar.Clean(); - cBar.Clean(); - pBar.Clean(); - ppBar.Clean(); - Clean(supports); - Clean(resistances); - Clean(supResBoxes); - - // - swingBar.Clean(); - breakerBar.Clean(); - appliedBox.Clean(); - momentumBar.Clean(); - rejectionBar.Clean(); - - // - return result; - } - - // - // Check Conditions ... - - // - // Detect Start Senario ... - - // - double fiboPressureLevel = GetFiboLevelValue(X_FIBO_LEVEL_382); - - // - double fiboUpDown = GetFibonacciLevel( - pBar.high, - pBar.low, - X_FIBO_LEVEL_382, - X_DIRECTION_BEARISH // - ); - double fiboDownUp = GetFibonacciLevel( - pBar.high, - pBar.low, - X_FIBO_LEVEL_382, - X_DIRECTION_BULLISH // - ); - - // - bool hasFiboToUpPressure = - fiboDownUp > 0 && - fiboDownUp <= pBar.GetDown(); - bool hasFiboToDownPressure = - fiboUpDown > 0 && - fiboUpDown >= pBar.GetUp(); - - // - int selectedBoxIDX = -1; - for (int j = 0; j < supresBoxesCount; j++) - { - // - double appliedPrice = - isBullish - ? supResBoxes[j].lower - : supResBoxes[j].upper; - - // - // Check Swing Low ... - bool isSwingLow = - // - pBar.low < ppBar.low && - pBar.low < cBar.low && - zBar.open > pBar.low && - // - appliedPrice > pBar.low && - appliedPrice < pBar.GetDown() - // - ; - bool isPressuredSwingLow = - isSwingLow && - hasFiboToUpPressure; - bool isPressuredStrongSwingLow = - pBar.IsBullish() && - isPressuredSwingLow; - - // - bool isSwingHigh = - // - pBar.high > ppBar.high && - pBar.high > cBar.high && - zBar.open < pBar.high && - // - appliedPrice < pBar.high && - appliedPrice > pBar.GetUp() - // - ; - bool isPressuredSwingHigh = - isSwingHigh && - hasFiboToDownPressure; - bool isPressuredStrongSwingHigh = - pBar.IsBearish() && - isPressuredSwingHigh; - - // - bool hasValidSwing = - isBullish - ? isSwingLow - : isSwingHigh; - bool hasValidPressuredSwing = - isBullish - ? isPressuredSwingLow - : isPressuredSwingHigh; - bool hasValidPressuredStrongSwing = - isBullish - ? isPressuredStrongSwingLow - : isPressuredStrongSwingHigh; - if (hasValidSwing) - { - swingBar = pBar; - } - if (hasValidPressuredSwing) - { - swingBar = pBar; - } - if (hasValidPressuredStrongSwing) - { - swingBar = pBar; - } - - // - bool isCBarBreaked = IsBarBreak( - appliedPrice, - forDir, - cBar // - ); - if (isCBarBreaked) - { - breakerBar = cBar; - } - bool isPBarBreaked = IsBarBreak( - appliedPrice, - forDir, - pBar // - ); - if (!isCBarBreaked && isPBarBreaked) - { - breakerBar = pBar; - } - else - { - isPBarBreaked = false; - } - bool isPPBarBreaked = IsBarBreak( - appliedPrice, - forDir, - ppBar // - ); - if (!isCBarBreaked && - !isPBarBreaked && - isPPBarBreaked) - { - breakerBar = ppBar; - } - else - { - isPPBarBreaked = false; - } - bool isBoxBreaked = isCBarBreaked || - isPBarBreaked || - isPPBarBreaked; - - // - bool isCBarRejected = IsBarReject( - appliedPrice, - forDir, - cBar // - ); - if (isCBarRejected) - { - rejectionBar = cBar; - } - bool isPBarRejected = IsBarReject( - appliedPrice, - forDir, - pBar // - ); - if (!isCBarRejected && isPBarRejected) - { - rejectionBar = pBar; - } - else - { - isPBarRejected = false; - } - bool isPPBarRejected = IsBarReject( - appliedPrice, - forDir, - ppBar // - ); - if (!isCBarRejected && - !isPBarRejected && - isPPBarRejected) - { - rejectionBar = ppBar; - } - else - { - isPPBarRejected = false; - } - bool isBoxRejected = isCBarRejected || - isPBarRejected || - isPPBarRejected; - - // - bool hasRejectionBar = false; - if (isBullish) - { - // - count = state.CountBullishRejectionBars(); - for (int i = 0; i < count; i++) - { - // - XCRejectionBar *iZone = state.bullishRejectionBars[i]; - - // - XOHCL iBar; - bool isFilled = iZone.FillBar(iBar); - if (!isFilled) - { - continue; - } - - // - int iBarIndex = iBar.Index(); - - // - hasRejectionBar = - // - (iBarIndex == cBar.Index() || - iBarIndex == pBar.Index()) - // - ; - if (hasRejectionBar) - { - // - if (!rejectionBar.IsValid()) - { - rejectionBar = iBar; - } - - // - break; - } - } - } - else - { - // - count = state.CountBearishRejectionBars(); - for (int i = 0; i < count; i++) - { - // - XCRejectionBar *iZone = state.bearishRejectionBars[i]; - - // - XOHCL iBar; - bool isFilled = iZone.FillBar(iBar); - if (!isFilled) - { - continue; - } - - // - int iBarIndex = iBar.Index(); - - // - hasRejectionBar = - // - (iBarIndex == cBar.Index() || - iBarIndex == pBar.Index()) - // - ; - if (hasRejectionBar) - { - // - if (!rejectionBar.IsValid()) - { - rejectionBar = iBar; - } - - // - break; - } - } - } - - // - bool hasMomentumBar = false; - if (isBullish) - { - // - count = state.CountBullishMomentumBars(); - for (int i = 0; i < count; i++) - { - // - XCMomentumBar *iZone = state.bullishMomentumBars[i]; - - // - XOHCL iBar; - bool isFilled = iZone.FillBar(iBar); - if (!isFilled) - { - continue; - } - - // - int iBarIndex = iBar.Index(); - - // - hasMomentumBar = - // - (iBarIndex == cBar.Index() || - iBarIndex == pBar.Index()) - // - ; - if (hasMomentumBar) - { - // - if (!momentumBar.IsValid()) - { - momentumBar = iBar; - } - - // - break; - } - } - } - else - { - // - count = state.CountBearishMomentumBars(); - for (int i = 0; i < count; i++) - { - // - XCMomentumBar *iZone = state.bearishMomentumBars[i]; - - // - XOHCL iBar; - bool isFilled = iZone.FillBar(iBar); - if (!isFilled) - { - continue; - } - - // - int iBarIndex = iBar.Index(); - - // - hasMomentumBar = - // - (iBarIndex == cBar.Index() || - iBarIndex == pBar.Index()) - // - ; - if (hasMomentumBar) - { - // - if (!momentumBar.IsValid()) - { - momentumBar = iBar; - } - - // - break; - } - } - } - - // - bool hasSwing = false; - if (isBullish) - { - // - count = state.CountSwingLows(); - for (int i = 0; i < count; i++) - { - // - XCSwing *iSwing = state.swingLows[i]; - - // - XOHCL iBar; - bool isFilled = iSwing.FillBar(iBar); - if (!isFilled) - { - continue; - } - - // - int iBarIndex = iBar.Index(); - - // - hasSwing = - // - (iBarIndex == cBar.Index() || - iBarIndex == pBar.Index()) - // - ; - if (hasSwing) - { - // - if (!swingBar.IsValid()) - { - swingBar = iBar; - } - - // - break; - } - } - } - else - { - // - count = state.CountSwingHighs(); - for (int i = 0; i < count; i++) - { - // - XCSwing *iSwing = state.swingHighs[i]; - - // - XOHCL iBar; - bool isFilled = iSwing.FillBar(iBar); - if (!isFilled) - { - continue; - } - - // - int iBarIndex = iBar.Index(); - - // - hasSwing = - // - (iBarIndex == cBar.Index() || - iBarIndex == pBar.Index()) - // - ; - if (hasSwing) - { - // - if (!swingBar.IsValid()) - { - swingBar = iBar; - } - - // - break; - } - } - } - - // - bool hasRequiredValidations = - // - (hasRejectionBar || - hasMomentumBar) - // - || - // - (hasRejectionBar || - hasSwing) - // - || - // - (hasMomentumBar || - hasSwing) - // - ; - - // - result = - // - (isBoxBreaked && - (hasRequiredValidations || - hasValidPressuredSwing)) - // - || - // - (isBoxRejected && - (hasRequiredValidations || - hasValidPressuredSwing)) - // - ; - if (result) - { - // - selectedBoxIDX = j; - break; - } - } - - // - result = - result && - (isBullish - ? zBar.open > box.upper - : zBar.open < box.lower) && - IsValidIndex(selectedBoxIDX); - if (result) - { - appliedBox = supResBoxes[selectedBoxIDX]; - } - - // - box.Clean(); - zBar.Clean(); - cBar.Clean(); - pBar.Clean(); - ppBar.Clean(); - Clean(supports); - Clean(resistances); - Clean(supResBoxes); - - // - return result; - } - - // - bool IsPriceInside( - int barIndex = 0, - ENUM_TIMEFRAMES forPeriod = NULL // - ) - { - // - bool result = false; - - // - if (barIndex < 0) - { - barIndex = 0; - } - - // - result = IsValid() && - HasOB() && - HasFVG() && - HasDirection(); - if (!result) - { - return result; - } - - // - string symbol = ob.GetSymbol(); - if (forPeriod == NULL) - { - forPeriod = ob.GetPeriod(); - } - - // - ENUM_X_DIRECTION forDir = ob.GetDirection(); - bool isBullish = IsBullish(forDir); - - // - // Check Start Bars ... - - // - XOHCL obStartedBar; - ENUM_X_DIRECTION obStartedDir; - bool isOBStarted = ob.IsStarted( - forDir, - obStartedBar, - obStartedDir // - ); - result = isOBStarted; - if (!result) - { - return result; - } - - // - XOHCL fvgStartedBar; - ENUM_X_DIRECTION fvgStartedDir; - bool isFVGStarted = fvg.IsStarted( - forDir, - fvgStartedBar, - fvgStartedDir // - ); - result = isFVGStarted; - if (!result) - { - return result; - } - - // - // Get Zone Box ... - XBoxZone box; - bool hasBox = AsBox(box); - result = hasBox; - if (!result) - { - // - box.Clean(); - - // - return result; - } - - // - // Retrieve Bars ... - - // - XOHCL zBar; - result = zBar.Init( - symbol, - forPeriod, - barIndex // - ); - if (!result) - { - // - box.Clean(); - zBar.Clean(); - - // - return result; - } - - // - XOHCL cBar; - result = zBar.GetPreviousBar(cBar); - if (!result) - { - // - box.Clean(); - zBar.Clean(); - cBar.Clean(); - - // - return result; - } - - // - XOHCL pBar; - result = cBar.GetPreviousBar(pBar); - if (!result) - { - // - box.Clean(); - zBar.Clean(); - cBar.Clean(); - pBar.Clean(); - - // - return result; - } - - // - result = - // - isBullish - ? ( - // - pBar.low > box.upper && - cBar.low <= box.upper && - zBar.open <= box.upper - // - ) - : ( - // - pBar.high < box.lower && - cBar.high >= box.lower && - zBar.open >= box.lower - // - ) - // - ; - - // - box.Clean(); - zBar.Clean(); - cBar.Clean(); - pBar.Clean(); - - // - return result; - } - - // -}; - -// -struct X121SMCXWZWorkingZone -{ - // - string symbol; - ENUM_TIMEFRAMES period; - - // - double upper; - double lower; - - // - double zoneUpper; - double zoneLower; - - // - double quarter1; - double quarter2; - double quarter3; - - // - datetime to; - datetime from; - - // - XOHCL swingBar; - XOHCL breakerBar; - XOHCL momentumBar; - XOHCL rejectionBar; - XBoxZone appliedBox; - - // - X121SMCXWZWorkingZone() - { - Clean(); - } - - // - void Clean() - { - // - upper = 0; - lower = 0; - quarter1 = 0; - quarter2 = 0; - quarter3 = 0; - zoneLower = 0; - zoneUpper = 0; - - // - from = NULL; - symbol = NULL; - period = NULL; - - // - CleanConditionBars(); - - // - ZeroMemory(this); - } - - // - void CleanConditionBars() - { - // - swingBar.Clean(); - breakerBar.Clean(); - appliedBox.Clean(); - momentumBar.Clean(); - rejectionBar.Clean(); - } - - // - bool IsValid() - { - // - bool result = false; - - // - result = - lower > 0 && - upper > 0 && - quarter1 > 0 && - quarter2 > 0 && - quarter3 > 0 && - upper > lower && - zoneLower > 0 && - zoneUpper > 0 && - IsValid(from) && - IsValid(symbol) && - IsValid(period) && - zoneUpper > upper && - zoneLower < lower; - - // - return result; - } - - // - bool IsDestroyed( - ENUM_X_DIRECTION &destroyedDir, - int barIndex = 0, - ENUM_TIMEFRAMES forPeriod = NULL // - ) - { - // - bool result = false; - - // - if (barIndex < 0) - { - barIndex = 0; - } - - // - if (!IsValid(forPeriod)) - { - forPeriod = period; - } - - // - destroyedDir = X_DIRECTION_NONE; - - // - result = IsValid(); - if (!result) - { - return result; - } - - // - XOHCL bar; - result = bar.Init( - symbol, - forPeriod, - barIndex // - ); - if (!result) - { - return result; - } - - // - bool isUpperBreaked = - bar.high > zoneUpper && - bar.close > zoneUpper; - - // - bool isLowerBreaked = - bar.low < zoneLower && - bar.close < zoneLower; - - // - result = isUpperBreaked || - isLowerBreaked; - if (result) - { - // - destroyedDir = - isUpperBreaked - ? X_DIRECTION_BULLISH - : X_DIRECTION_BEARISH; - } - - // - return result; - } - - // -}; - -// -// Definitions ... -struct X121SMCStrategyXWZSignalConditions -{ - // - // Props ... - - // - string symbol; - ENUM_TIMEFRAMES period; - - // - double sl; - double target; - double reward; - double amountPercent; - ENUM_X_DIRECTION dir; - ENUM_X_POSITION_TYPES type; - - // - // Setup Props ... - - // - datetime setupTime; - datetime triggerTime; - - // - double pivot; - double point; - - // - ENUM_X121SMC_XWZ_PRIORITY priority; - - // - // Working Zone ... - XCFVG *fairValueGap; - XCOrderBlock *orderBlock; - XCSupplyZone *supplyZone; - XCDemandZone *demandZone; - X121SMCXWZWorkingZone workingZone; - - // - X121SMCXWZZone startZone; - - // - // Constructor ... - X121SMCStrategyXWZSignalConditions() - { - Clean(); - } - - // - // Tools ... - - /** - * Cleaning Up ... - */ - void Clean() - { - // - sl = 0; - target = 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; - - // - target = 0; - reward = 0; - amountPercent = 0; - - // - ZeroMemory(supplyZone); - - // - ZeroMemory(demandZone); - - // - ZeroMemory(orderBlock); - - // - ZeroMemory(fairValueGap); - - // - startZone.Clean(); - - // - workingZone.Clean(); - } - - // - // - // - - // - bool HasWorkingZone() - { - return workingZone.IsValid(); - } - - // - bool HasOrderBlock() - { - return orderBlock != NULL && - orderBlock.IsValid(); - } - - // - bool HasFairValueGap() - { - return fairValueGap != NULL && - fairValueGap.IsValid(); - } - - // - bool HasSupplyZone() - { - return supplyZone != NULL && - supplyZone.IsValid(); - } - - // - bool HasDemandZone() - { - return demandZone != NULL && - demandZone.IsValid(); - } - - // - bool HasStartZone() - { - return startZone.IsValid(); - } - - // - void UpdateTo(datetime value = NULL) - { - // - value = NormalizeTime(value); - - // - bool hasSupplyZone = HasSupplyZone(); - if (hasSupplyZone) - { - supplyZone.To(value); - } - - // - bool hasDemandZone = HasDemandZone(); - if (hasDemandZone) - { - demandZone.To(value); - } - - // - bool hasOrderBlock = HasOrderBlock(); - if (hasOrderBlock) - { - orderBlock.To(value); - } - - // - bool hasFairValueGap = HasFairValueGap(); - if (hasFairValueGap) - { - fairValueGap.To(value); - } - - // - // Working Zone ... - bool hasWorkingZone = HasWorkingZone(); - if (hasWorkingZone) - { - workingZone.to = value; - } - - // - // Start Zone ... - bool hasStartZone = HasStartZone(); - if (hasStartZone) - { - // - bool hasOB = startZone.HasOB(); - if (hasOB) - { - startZone.ob.To(value); - } - - // - bool hasFVG = startZone.HasFVG(); - if (hasFVG) - { - startZone.fvg.To(value); - } - - // - bool hasSupply = startZone.HasSupply(); - if (hasSupply) - { - startZone.supply.To(value); - } - - // - bool hasDemand = startZone.HasDemand(); - if (hasDemand) - { - startZone.demand.To(value); - } - - // - bool hasSupport = startZone.HasSupport(); - if (hasSupport) - { - startZone.support.To(value); - } - - // - bool hasResistance = startZone.HasResistance(); - if (hasResistance) - { - startZone.resistance.To(value); - } - - // - bool hasBullishCZone = startZone.HasBullishConsolidationZone(); - if (hasBullishCZone) - { - // startZone.bullishConsolidationZone.to = cTime; - } - - // - bool hasBearishCZone = startZone.HasBearishConsolidationZone(); - if (hasBearishCZone) - { - // startZone.bearishConsolidationZone.to = cTime; - } - } - } - - // - // - // - - // - // Working Zone is an Area which - // we decide to trade inside it ... - bool ExtractWorkingZone( - XPOIState &htfState, - XPOIState &mtfState, - XPOIState &stfState, - int barIndex = 0 // - ) - { - // - bool result = false; - - // - if (barIndex < 0) - { - barIndex = 0; - } - int zIndex = barIndex; - - // - result = !HasWorkingZone(); - if (!result) - { - return result; - } - - // - result = IsValid(symbol) && - IsValid(period); - if (!result) - { - // - Clean(); - return result; - } - - // - datetime cTime = iTime( - symbol, - period, - zIndex // - ); - - // - result = - // - htfState.IsValid() && - htfState.HasChild() && - htfState.HasSupplyZones() && - htfState.HasDemandZones() && - // - mtfState.IsValid() && - mtfState.HasChild() && - mtfState.HasSupplyZones() && - mtfState.HasDemandZones() && - // - stfState.IsValid() && - stfState.HasChild() - // - ; - if (!result) - { - return result; - } - - // - // Retrieve Highest Supply Zone ... - int hSupplyIDX = GetHighest(htfState.supplyZones); - int lDemandIDX = GetLowest(htfState.demandZones); - - // - result = - // - IsValidIndex(hSupplyIDX) && - IsValidIndex(lDemandIDX) - // - ; - if (!result) - { - return result; - } - - // - supplyZone = htfState.supplyZones[hSupplyIDX]; - demandZone = htfState.demandZones[lDemandIDX]; - - // - result = - // - supplyZone != NULL && - demandZone != NULL && - supplyZone.IsValid() && - demandZone.IsValid() - // - ; - if (!result) - { - // - Clean(); - return result; - } - - // - // Check Validation of Supply and Demand Zones ... - lDemandIDX = GetLowest(mtfState.demandZones); - hSupplyIDX = GetHighest(mtfState.supplyZones); - result = IsValidIndex(lDemandIDX) && - IsValidIndex(hSupplyIDX); - if (!result) - { - // - Clean(); - return result; - } - - // - // Validate Supply and Demand ... - bool isMTFHSupplyInside = - IsInside( - mtfState.supplyZones[hSupplyIDX], - supplyZone); - bool isMTFLDemandInside = - IsInside( - mtfState.demandZones[lDemandIDX], - demandZone // - ); - if (isMTFHSupplyInside && - !isMTFLDemandInside) - { - demandZone = mtfState.demandZones[lDemandIDX]; - } - else if (!isMTFHSupplyInside && - isMTFLDemandInside) - { - supplyZone = mtfState.supplyZones[hSupplyIDX]; - } - else if (isMTFHSupplyInside && - isMTFLDemandInside) - { - // - supplyZone = mtfState.supplyZones[hSupplyIDX]; - demandZone = mtfState.demandZones[lDemandIDX]; - } - - // - // Check Zones Validation ... - bool hasTrend = - supplyZone != NULL && - supplyZone.IsValid() && - demandZone != NULL && - demandZone.IsValid(); - result = hasTrend; - if (!result) - { - // - Clean(); - return result; - } - - // - datetime from = MathMax( - supplyZone.From(), - demandZone.From()); - - // - int fromIndex = iBarShift( - symbol, - period, - from // - ); - - // - // Detect Trend ... - ENUM_X_DIRECTION trend = X_DIRECTION_NONE; - datetime supplyTouch = NULL; - datetime demandTouch = NULL; - for (int i = zIndex; i < fromIndex; i++) - { - // - XOHCL iBar; - bool isInited = iBar.Init( - symbol, - period, - i // - ); - if (!isInited) - { - continue; - } - - // - bool isTouchSupplyZone = - // - iBar.low < supplyZone.Lower() && - iBar.GetUp() > supplyZone.Lower() - // - ; - if (isTouchSupplyZone && - !IsValid(supplyTouch)) - { - supplyTouch = iBar.time; - } - - // - bool isTouchDemandZone = - // - iBar.high > demandZone.Upper() && - iBar.GetDown() < demandZone.Upper() - // - ; - if (isTouchDemandZone && - !IsValid(demandTouch)) - { - demandTouch = iBar.time; - } - - // - bool canBreak = - IsValid(supplyTouch) && - IsValid(demandTouch); - - // - iBar.Clean(); - - // - if (canBreak) - { - break; - } - } - - // - hasTrend = - // - IsValid(supplyTouch) || - IsValid(demandTouch) - // - ; - if (hasTrend) - { - // - trend = - // - supplyTouch > demandTouch - ? X_DIRECTION_BEARISH - : X_DIRECTION_BULLISH - // - ; - } - - // - // Check Trend ... - result = hasTrend; - if (!result) - { - // - Clean(); - return result; - } - - // - bool hasBullishTrend = IsBullish(trend); - bool hasBearishTrend = IsBearish(trend); - - // - // Find Order Block and FVG for Trend Approve ... - - // - bool isBullishTrendApproved = false; - bool isBearishTrendApproved = false; - - // - // Now We Have to Detect at least One OrderBlock with FVG ... - // for Trend Approvement ... - bool hasOrderBlock = HasOrderBlock(); - bool hasFairValueGap = HasFairValueGap(); - if (!hasOrderBlock && - !hasFairValueGap) - { - // - int count = 0; - bool has = false; - - // - XCFVG *fvg = NULL; - XCOrderBlock *ob = NULL; - - // - has = mtfState.HasBullishOrderBlocks(); - count = mtfState.CountBullishOrderBlocks(); - - // - if (has) - { - // - // Check Order Block ... - for (int i = 0; i < count; i++) - { - // - XCOrderBlock *iOB = mtfState.bullishOrderBlocks[i]; - - // - iOB.To(cTime); - - // - // Check From Passes ... - bool isFromPassed = iOB.From() > demandZone.From(); - if (!isFromPassed) - { - continue; - } - - // - // Must inside DemandZone ... - bool isInsideDemand = IsInsideDiff( - iOB, - demandZone // - ); - if (!isInsideDemand) - { - continue; - } - - // - // Check Started ... - XOHCL startedBar; - ENUM_X_DIRECTION startedDir; - bool isStarted = iOB.IsStarted( - X_DIRECTION_BULLISH, - startedBar, - startedDir // - ); - if (!isStarted) - { - // - startedBar.Clean(); - continue; - } - - // - // Converts to Box ... - XBoxZone obBox; - bool hasOBBox = ToBox( - obBox, - iOB // - ); - if (!hasOBBox) - { - // - obBox.Clean(); - startedBar.Clean(); - continue; - } - - // - // Check Zone Must not Used before ... - bool isUsed = IsBoxUsed( - obBox, - startedBar.Index() - 1, - zIndex // - ); - if (isUsed) - { - // - obBox.Clean(); - startedBar.Clean(); - continue; - } - - // - ob = iOB; - - // - obBox.Clean(); - startedBar.Clean(); - - // - break; - } - - // - // Detect Fair Value Gap ... - if (ob != NULL && - ob.IsValid()) - { - // - has = stfState.HasBullishFairValueGaps(); - count = stfState.CountBullishFairValueGaps(); - if (has) - { - // - // Check Fir Value Gap ... - for (int i = 0; i < count; i++) - { - // - XCFVG *iFVG = stfState.bullishFairValueGaps[i]; - - // - iFVG.To(cTime); - - // - // Check From Passes ... - bool isFromPassed = iFVG.From() > ob.From(); - if (!isFromPassed) - { - continue; - } - - // - // Check Started ... - XOHCL startedBar; - ENUM_X_DIRECTION startedDir; - bool isStarted = iFVG.IsStarted( - X_DIRECTION_BULLISH, - startedBar, - startedDir // - ); - if (!isStarted) - { - // - startedBar.Clean(); - continue; - } - - // - // Converts to Box ... - XBoxZone fvgBox; - bool hasFVGBox = ToBox( - fvgBox, - iFVG // - ); - if (!hasFVGBox) - { - // - fvgBox.Clean(); - startedBar.Clean(); - continue; - } - - // - // Check Inside Order Block ... - bool isInside = IsInsideDiff( - iFVG, - ob, - true // Force Side Out ... - ); - if (!isInside) - { - continue; - } - - // - fvg = iFVG; - - // - fvgBox.Clean(); - startedBar.Clean(); - - // - break; - } - } - else - { - // - ob = NULL; - } - } - - // - if (ob != NULL && - fvg != NULL) - { - // - orderBlock = ob; - fairValueGap = fvg; - } - - // - hasOrderBlock = HasOrderBlock(); - hasFairValueGap = HasFairValueGap(); - isBullishTrendApproved = hasOrderBlock && - hasFairValueGap; - } - - // - if (!isBullishTrendApproved) - { - // - has = mtfState.HasBearishOrderBlocks(); - count = mtfState.CountBearishOrderBlocks(); - - // - if (has) - { - // - // Check Order Block ... - for (int i = 0; i < count; i++) - { - // - XCOrderBlock *iOB = mtfState.bearishOrderBlocks[i]; - - // - iOB.To(cTime); - - // - // Check From Passes ... - bool isFromPassed = iOB.From() > supplyZone.From(); - if (!isFromPassed) - { - continue; - } - - // - // Must inside DemandZone ... - bool isInsideDemand = IsInsideDiff( - iOB, - supplyZone // - ); - if (!isInsideDemand) - { - continue; - } - - // - // Check Started ... - XOHCL startedBar; - ENUM_X_DIRECTION startedDir; - bool isStarted = iOB.IsStarted( - X_DIRECTION_BEARISH, - startedBar, - startedDir // - ); - if (!isStarted) - { - // - startedBar.Clean(); - continue; - } - - // - // Converts to Box ... - XBoxZone obBox; - bool hasOBBox = ToBox( - obBox, - iOB // - ); - if (!hasOBBox) - { - // - obBox.Clean(); - startedBar.Clean(); - continue; - } - - // - // Check Zone Must not Used before ... - bool isUsed = IsBoxUsed( - obBox, - startedBar.Index() - 1, - zIndex // - ); - if (isUsed) - { - // - obBox.Clean(); - startedBar.Clean(); - continue; - } - - // - ob = iOB; - - // - obBox.Clean(); - startedBar.Clean(); - - // - break; - } - - // - // Detect Fair Value Gap ... - if (ob != NULL && - ob.IsValid()) - { - // - has = stfState.HasBearishFairValueGaps(); - count = stfState.CountBearishFairValueGaps(); - if (has) - { - // - // Check Fir Value Gap ... - for (int i = 0; i < count; i++) - { - // - XCFVG *iFVG = stfState.bearishFairValueGaps[i]; - - // - iFVG.To(cTime); - - // - // Check From Passes ... - bool isFromPassed = iFVG.From() > ob.From(); - if (!isFromPassed) - { - continue; - } - - // - // Check Started ... - XOHCL startedBar; - ENUM_X_DIRECTION startedDir; - bool isStarted = iFVG.IsStarted( - X_DIRECTION_BEARISH, - startedBar, - startedDir // - ); - if (!isStarted) - { - // - startedBar.Clean(); - continue; - } - - // - // Converts to Box ... - XBoxZone fvgBox; - bool hasFVGBox = ToBox( - fvgBox, - iFVG // - ); - if (!hasFVGBox) - { - // - fvgBox.Clean(); - startedBar.Clean(); - continue; - } - - // - // Check Inside Order Block ... - bool isInside = IsInsideDiff( - iFVG, - ob, - true // Force Side Out ... - ); - if (!isInside) - { - continue; - } - - // - fvg = iFVG; - - // - fvgBox.Clean(); - startedBar.Clean(); - - // - break; - } - } - else - { - // - ob = NULL; - } - } - - // - if (ob != NULL && - fvg != NULL) - { - // - orderBlock = ob; - fairValueGap = fvg; - } - - // - hasOrderBlock = HasOrderBlock(); - hasFairValueGap = HasFairValueGap(); - isBearishTrendApproved = hasOrderBlock && - hasFairValueGap; - } - } - } - - // - // Check Trend Approved ... - bool isTrendApproved = - hasOrderBlock && - hasFairValueGap && - (isBullishTrendApproved || - isBearishTrendApproved); - result = isTrendApproved; - if (!result) - { - // - Clean(); - return result; - } - - // - // Prepare Working Zone ... - workingZone.symbol = symbol; - workingZone.period = period; - - // - workingZone.upper = supplyZone.Lower(); - workingZone.zoneUpper = supplyZone.Upper(); - - // - workingZone.lower = demandZone.Upper(); - workingZone.zoneLower = demandZone.Lower(); - - // - workingZone.from = from; - - // - double upper = workingZone.upper; - double range = - workingZone.upper - workingZone.lower; - double ranegPercent = range / 100; - double quarterValue = ranegPercent * 25; - - // - workingZone.quarter1 = upper - (quarterValue * 1); - workingZone.quarter2 = upper - (quarterValue * 2); - workingZone.quarter3 = upper - (quarterValue * 3); - - // - result = workingZone.IsValid(); - if (!result) - { - Clean(); - } - - // - return result; - } - - // - bool IsWorkingZoneDestroyed( - ENUM_X_DIRECTION &destroyedDir, - int barIndex = 0, - ENUM_TIMEFRAMES forPeriod = NULL // - ) - { - // - bool result = false; - - // - if (barIndex < 0) - { - barIndex = 0; - } - - // - if (!IsValid(forPeriod)) - { - forPeriod = period; - } - - // - destroyedDir = X_DIRECTION_NONE; - - // - result = workingZone.IsValid(); - if (!result) - { - return result; - } - - // - result = workingZone.IsDestroyed( - destroyedDir, - barIndex, - forPeriod // - ); - - // - return result; - } - - // - bool DetectTrend( - ENUM_X_DIRECTION &trend, - int barIndex = 0, - ENUM_TIMEFRAMES forPeriod = NULL // - ) - { - // - bool result = false; - - // - if (barIndex < 0) - { - barIndex = 0; - } - - // - if (forPeriod == NULL) - { - forPeriod = period; - } - - // - trend = X_DIRECTION_NONE; - - // - result = HasWorkingZone(); - if (!result) - { - return result; - } - - // - int FromIndex = iBarShift( - symbol, - forPeriod, - workingZone.from // - ); - - // - datetime supplyTouch = NULL; - datetime demandTouch = NULL; - for (int i = barIndex; i < FromIndex; i++) - { - // - XOHCL iBar; - bool isInited = iBar.Init( - symbol, - forPeriod, - i // - ); - if (!isInited) - { - continue; - } - - // - bool isTouchSupplyZone = - // - iBar.low < supplyZone.Lower() && - iBar.GetUp() > supplyZone.Lower() - // - ; - if (isTouchSupplyZone && - !IsValid(supplyTouch)) - { - supplyTouch = iBar.time; - } - - // - bool isTouchDemandZone = - // - iBar.high > demandZone.Upper() && - iBar.GetDown() < demandZone.Upper() - // - ; - if (isTouchDemandZone && - !IsValid(demandTouch)) - { - demandTouch = iBar.time; - } - - // - bool canBreak = - IsValid(supplyTouch) && - IsValid(demandTouch); - - // - iBar.Clean(); - - // - if (canBreak) - { - break; - } - } - - // - result = - // - IsValid(supplyTouch) || - IsValid(demandTouch) - // - ; - if (result) - { - // - trend = - // - supplyTouch > demandTouch - ? X_DIRECTION_BEARISH - : X_DIRECTION_BULLISH - // - ; - } - - // - return result; - } - - // - bool DetectStartZone( - ENUM_X_DIRECTION forDir, - XPOIState &state, - XC121SMCCycleHelper *cycleHelper // - ) - { - // - bool result = false; - - // - result = state.IsValid() && - state.HasChild() && - HasDirection(forDir); - if (!result) - { - return result; - } - - // - bool isBullish = IsBullish(forDir); - - // - int idx = -1; - int count = 0; - int has = false; - - // - // Supply Zones ... - has = state.HasSupplyZones(); - if (has) - { - // - idx = GetYoungest(state.supplyZones); - if (IsValidIndex(idx)) - { - startZone.supply = state.supplyZones[idx]; - } - } - - // - // Demand Zones ... - has = state.HasDemandZones(); - if (has) - { - // - idx = GetYoungest(state.demandZones); - if (IsValidIndex(idx)) - { - startZone.demand = state.demandZones[idx]; - } - } - - // - // Support Zones ... - has = state.HasSupportZones(); - if (has) - { - // - idx = GetYoungest(state.supportZones); - if (IsValidIndex(idx)) - { - startZone.support = state.supportZones[idx]; - } - } - - // - // Resistance Zones ... - has = state.HasResistanceZones(); - if (has) - { - // - idx = GetYoungest(state.resistanceZones); - if (IsValidIndex(idx)) - { - startZone.resistance = state.resistanceZones[idx]; - } - } - - // - // Other Zones ... - if (isBullish) - { - // - // Order Block ... - has = state.HasBullishOrderBlocks(); - if (has) - { - // - idx = GetYoungest(state.bullishOrderBlocks); - if (IsValidIndex(idx)) - { - startZone.ob = state.bullishOrderBlocks[idx]; - } - } - - // - // Fair Value Gap ... - has = state.HasBullishFairValueGaps(); - if (has) - { - // - idx = GetYoungest(state.bullishFairValueGaps); - if (IsValidIndex(idx)) - { - startZone.fvg = state.bullishFairValueGaps[idx]; - } - } - } - else - { - // - // Order Block ... - has = state.HasBearishOrderBlocks(); - if (has) - { - // - idx = GetYoungest(state.bearishOrderBlocks); - if (IsValidIndex(idx)) - { - startZone.ob = state.bearishOrderBlocks[idx]; - } - } - - // - // Fair Value Gap ... - has = state.HasBearishFairValueGaps(); - if (has) - { - // - idx = GetYoungest(state.bearishFairValueGaps); - if (IsValidIndex(idx)) - { - startZone.fvg = state.bearishFairValueGaps[idx]; - } - } - } - - // - bool hasOBFVG = startZone.HasOB() && - startZone.HasFVG(); - bool isOBStarted = false; - bool isFVGStarted = false; - bool isOBActivated = false; - bool isFVGActivated = false; - bool isOBInsideFVG = false; - bool isFVGInsideOB = false; - if (hasOBFVG) - { - // - ENUM_X_DIRECTION forDir = startZone.ob.GetDirection(); - - // - XOHCL startedBar; - ENUM_X_DIRECTION startedDir; - - // - isOBStarted = startZone.ob.IsStarted( - forDir, - startedBar, - startedDir // - ); - - // - isOBActivated = startZone.ob.IsActivated( - forDir, - startedBar, - startedDir // - ); - - // - forDir = startZone.fvg.GetDirection(); - - // - isFVGStarted = startZone.fvg.IsStarted( - forDir, - startedBar, - startedDir // - ); - - // - isFVGActivated = startZone.fvg.IsActivated( - forDir, - startedBar, - startedDir // - ); - - // - isOBInsideFVG = - IsInsideDiff( - startZone.ob, - startZone.fvg // - ) || - (isBullish - ? IsAboveDiff( - startZone.ob, - startZone.fvg, - true // IgnoreInside - ) - : IsBelowDiff( - startZone.ob, - startZone.fvg, - true // IgnoreInside - )); - // - isFVGInsideOB = - IsInsideDiff( - startZone.fvg, - startZone.ob // - ) || - (isBullish - ? IsAboveDiff( - startZone.fvg, - startZone.ob, - true // IgnoreInside - ) - : IsBelowDiff( - startZone.fvg, - startZone.ob, - true // IgnoreInside - )); - - // - startedBar.Clean(); - } - - // - result = - isOBStarted && - isFVGStarted && - !isOBActivated && - !isFVGActivated && - startZone.IsValid() && - (isOBInsideFVG || - isFVGInsideOB) && - (isBullish - ? startZone.IsBullish() - : startZone.IsBearish()); - if (!result) - { - // - startZone.Clean(); - - // - return result; - } - - // - return result; - } - - // - void DetectPriority( - ENUM_X121SMC_XWZ_PRIORITY &bullish, - ENUM_X121SMC_XWZ_PRIORITY &bearish, - int barIndex = 0, - ENUM_TIMEFRAMES forPeriod = NULL // - ) - { - // - bullish = X121SMC_XWZ_PRIORITY_NONE; - bearish = X121SMC_XWZ_PRIORITY_NONE; - - // - if (barIndex < 0) - { - barIndex = 0; - } - - // - if (!IsValid(forPeriod)) - { - forPeriod = period; - } - - // - bool hasWorkingZone = HasWorkingZone(); - if (!hasWorkingZone) - { - return; - } - - // - XOHCL zBar; - bool isInited = zBar.Init( - symbol, - forPeriod, - barIndex // - ); - if (!isInited) - { - // - zBar.Clean(); - return; - } - - // - XOHCL cBar; - isInited = zBar.GetPreviousBar(cBar); - if (!isInited) - { - // - zBar.Clean(); - cBar.Clean(); - return; - } - - // - // ZoneUpper, Upper ... - if (cBar.low > workingZone.upper && - cBar.high < workingZone.zoneUpper && - zBar.low > workingZone.upper && - zBar.high < workingZone.zoneUpper) - { - // - bullish = X121SMC_XWZ_PRIORITY_NONE; - bearish = X121SMC_XWZ_PRIORITY_STRONG_HIGH; - } - // - // Upper, Quarter1 ... - else if (cBar.low > workingZone.quarter1 && - cBar.high < workingZone.upper && - zBar.low > workingZone.quarter1 && - zBar.high < workingZone.upper) - { - // - bullish = X121SMC_XWZ_PRIORITY_WEAK; - bearish = X121SMC_XWZ_PRIORITY_HIGH; - } - // - // Quarter1, Quarter2 ... - else if (cBar.low > workingZone.quarter2 && - cBar.high < workingZone.quarter1 && - zBar.low > workingZone.quarter2 && - zBar.high < workingZone.quarter1) - { - // - bullish = X121SMC_XWZ_PRIORITY_LOW; - bearish = X121SMC_XWZ_PRIORITY_REGULAR; - } - // - // Quarter2, Quarter3 ... - else if (cBar.low > workingZone.quarter3 && - cBar.high < workingZone.quarter2 && - zBar.low > workingZone.quarter3 && - zBar.high < workingZone.quarter2) - { - // - bullish = X121SMC_XWZ_PRIORITY_REGULAR; - bearish = X121SMC_XWZ_PRIORITY_LOW; - } - // - // Quarter3, Lower ... - else if (cBar.low > workingZone.lower && - cBar.high < workingZone.quarter3 && - zBar.low > workingZone.lower && - zBar.high < workingZone.quarter3) - { - // - bullish = X121SMC_XWZ_PRIORITY_HIGH; - bearish = X121SMC_XWZ_PRIORITY_WEAK; - } - // - // Lower, ZoneLower ... - else if (cBar.low > workingZone.zoneLower && - cBar.high < workingZone.lower && - zBar.low > workingZone.zoneLower && - zBar.high < workingZone.lower) - { - // - bullish = X121SMC_XWZ_PRIORITY_STRONG_HIGH; - bearish = X121SMC_XWZ_PRIORITY_NONE; - } - - // - zBar.Clean(); - cBar.Clean(); - } - - // - bool HasWorkingZoneConditions( - ENUM_X_DIRECTION &conditionsDir, - XPOIState &state, - int barIndex = 0, - ENUM_TIMEFRAMES forPeriod = NULL // - ) - { - // - bool result = false; - - // - if (barIndex < 0) - { - barIndex = 0; - } - - // - conditionsDir = X_DIRECTION_NONE; - - // - result = HasWorkingZone(); - if (!result) - { - return result; - } - - // - XBoxZone appliedBox; - - // - // Clean Condition Bars ... - workingZone.CleanConditionBars(); - - // - // Validate ... - result = state.IsValid() && - state.HasChild(); - if (!result) - { - // - workingZone.CleanConditionBars(); - return result; - } - - // - if (!IsValid(forPeriod)) - { - forPeriod = period; - } - - // - datetime cTime = iTime( - symbol, - forPeriod, - barIndex // - ); - - // - // Check Supply Zone ... - - // - XBoxZone supplyBox; - bool hasSupplyBox = - supplyZone != NULL && - supplyZone.IsValid() && - ToBox( - supplyBox, - supplyZone // - ); - if (hasSupplyBox) - { - // - result = CheckBoxForTradeConditions( - supplyBox, - appliedBox, - workingZone.swingBar, - workingZone.breakerBar, - workingZone.rejectionBar, - workingZone.momentumBar, - state, - barIndex, - forPeriod // - ); - - // - if (result) - { - conditionsDir = X_DIRECTION_BEARISH; - } - } - - // - // Check Demand Zone ... - XBoxZone demandBox; - bool hasDemandBox = false; - if (!result) - { - // - hasDemandBox = - demandZone != NULL && - demandZone.IsValid() && - ToBox( - demandBox, - demandZone // - ); - if (hasDemandBox) - { - // - result = CheckBoxForTradeConditions( - demandBox, - appliedBox, - workingZone.swingBar, - workingZone.breakerBar, - workingZone.rejectionBar, - workingZone.momentumBar, - state, - barIndex, - forPeriod // - ); - - // - if (result) - { - conditionsDir = X_DIRECTION_BULLISH; - } - } - } - - // - if (!result) - { - workingZone.CleanConditionBars(); - } - - // - supplyBox.Clean(); - demandBox.Clean(); - appliedBox.Clean(); - - // - return result; - } - - // - double GetSpread() - { - // - double result = 0; - - // - if (!IsValid(symbol)) - { - return result; - } - - // - result = GetSpread( - symbol // - ); - - // - return result; - } - - // -}; diff --git a/Documents/BKP/xsupdem/x-saherelm.x-121.smc.alert.ea.mq5 b/Documents/BKP/xsupdem/x-saherelm.x-121.smc.alert.ea.mq5 deleted file mode 100644 index 1eb6e98b..00000000 --- a/Documents/BKP/xsupdem/x-saherelm.x-121.smc.alert.ea.mq5 +++ /dev/null @@ -1,464 +0,0 @@ -/////////////////////////////////////////////////////// -// -// SaherElm IT Center XTest MQL5 Expert Advisor -// ------------------------------------------------- -// Name: X121SMCEA -// Description: an Exper Advisor which used Panels -// -// 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 X121SMCEA" -#property strict - -// -#define ShortName "X121SMCEA" - -// -// Imports ... -#include "../X121SMCEA/Experts/x-121.smc.expert.alert.class.mq5" - -// -// Inputs ... - -// -// Common ... -input group "Common"; -input long eaMagicNumber = 78692110; // Magic Number -input int eaSlippage = 10; // Slippgae -input string eaLogSuffix = ""; // Log Suffix - -// -// Symbols ... -input group "Symbols"; -input bool eaMultiSymbol = false; // Use Multi Symbol -input string eaSymbols = "EURUSDb"; // Trading Symbols - -// -// Signalling ... -input group "Signalling"; -input bool eaAllowLong = true; // Allow Long Signals -input bool eaAllowShort = true; // Allow Short Signals -input int eaMaxAllowedLongs = 5; // Max Allowed Long Signals -input int eaMaxAllowedShorts = 5; // Max Allowed Short Signals -input bool eaUseMaxAllowedSignalsPerSymbol = true; // Use Max Allowed Signal Types Per Symbol -input double eaLastPositionProfitForAcceptNextInPoint = 0; // Last Position Profit In Points for Accept new Signal -input int eaDelaysBetweenTwoSignalsInBar = 0; // Delay between two Signals in Bars -input double eaMaxAllowedSpread = 25; // Max Allowed Spread for Signalling -input int eaMinRequiredVerificationForSpreadPass = 20; // Minimum Spread Verification for Signalling - -// -// Trade ... -input group "Trade"; -input bool eaAllowTrade = false; // Allow Open Trade On Signals -input string eaStartTradeAt = ""; // Enable Trade on Signals on Time -input string eaStopTradeAt = ""; // Enable Trade on Signals on Time -input string eaCloseAllTradesAt = ""; // Enable Close All Trades on Signals on Time - -// -// Risk Management ... -input group "Risk Management"; -input double eaR2R = 4; // Signallers Risk to Reward Ratio -input double eaVolume = 0; // Static Volume -input double eaStaticBalance = 1000; // Static Balance -input double eaBalancePerTrade = 10; // Balance Used in Each Trade -input double eaRiskPercentPerBalance = 0; // Risk Percent Per Balance in Each Trade -input bool eaDynamicRiskManagement = false; // Dynamic Risk Management -input bool eaUseDynamicVolume = false; // Use Dynamic Volume -input double eaDynamicVolumeStep = 0.01; // Increase Volume Step -input double eaDynamicVolumeBalanceFactor = 200; // Balance Factor for Generate Dynamic Volume -input double eaMaxAllowedDrawdownToOpenTrades = 3; // Max Allowed Drawdown for Open Trades -input int eaMaxAllowedSLToPauseSignallingPerSymbol = 2; // Max Allowed SL for Pause Signalling Per Symbol -input int eaPauseSignallingAfterReachesMaxAllowedSLInSecconds = 7200; // Pause Signalling Per Symbol afte Max Allowed SL Reached In Seconds - -// -// Protection ... -input group "Protection"; -input bool eaAllowHedging = false; // Allow Hedge Positions -input int eaMinOpenTradesFroHedging = 4; // Minimum Open Positions for Hedging -input double eaHedgingMinVolumeStep = 0.01; // Minimum Volume Step for Hedging -input double eaHedgeingMinRequiredProfitPerVolumeStep = 2.0; // Minimum Required Profit Per Volume Step for Hedging - -// -// Alert ... -// Here we Provider All Requirements for -// Configuring Alert Provider ... -input group "Alert"; -input bool eaEnableAlerts = true; // Enable Alerts -input bool eaLogAlerts = true; // Log Alerts -input bool eaMailAlerts = false; // Mail Alerts -input bool eaPushAlerts = true; // Push Alerts -input bool eaTerminalAlerts = false; // Terminal Alerts - -// -// Time Report ... -input group "Reports"; -input bool eaReportNewMonths = false; // Report New Month -input bool eaReportNewWeeks = false; // Report New Weeks -input bool eaReportNewDays = true; // Report New Days -input bool eaReportNewHours = false; // Report New Hours - -// -// Define Local Variables ... - -XC121SMCExpert *eaExpert; - -// -// Event Handlers ... - -// -// Initialization ... -int OnInit() -{ - // - // Validate Inputs and Required Parameters - // for EA to Works fine ... - if (!ValidateInputs()) - { - return INIT_PARAMETERS_INCORRECT; - } - - // - // Initialize Timer ... - if (!InitTimer()) - { - return INIT_FAILED; - } - - // - // Configure EA Expert Class ... - eaExpert = new XC121SMCExpert(); - - // - // Event Handlers ... - eaExpert.OnSignalEventListener = OnSignalRecieved; - eaExpert.OnDealsChangedEventListener = OnDealsChanged; - eaExpert.OnOrdersChangedEventListener = OnOrdersChanged; - eaExpert.OnPositionSLEventListener = OnStopLossTriggered; - eaExpert.OnPositionTPEventListener = OnTakeProfitTriggered; - eaExpert.OnPositionsChangedEventListener = OnPositionsChanged; - eaExpert.OnPositionForceCloseEventListener = OnPositionForceClosed; - - // - // Common ... - eaExpert.MagicNumber(eaMagicNumber); - eaExpert.Slippage(eaSlippage); - eaExpert.TagPrefix(eaLogSuffix); - - // - // Symbol ... - eaExpert.SetSymbol(_Symbol); - eaExpert.SetPeriod(_Period); - eaExpert.Symbols(eaSymbols); - eaExpert.MultiSymbol(eaMultiSymbol); - - // - // Signalling ... - eaExpert.AllowLong(eaAllowLong); - eaExpert.AllowShort(eaAllowShort); - eaExpert.MaxAllowedLongs(eaMaxAllowedLongs); - eaExpert.MaxAllowedShorts(eaMaxAllowedShorts); - eaExpert.UseMaxAllowedSignalsPerSymbol(eaUseMaxAllowedSignalsPerSymbol); - eaExpert.LastPositionProfitForAcceptNextInPoint(eaLastPositionProfitForAcceptNextInPoint); - eaExpert.DelaysBetweenTwoSignalsInBar(eaDelaysBetweenTwoSignalsInBar); - eaExpert.MaxAllowedSpread(eaMaxAllowedSpread); - eaExpert.MinRequiredVerificationForSpreadPass(eaMinRequiredVerificationForSpreadPass); - - // - // Trade ... - eaExpert.AllowTrade(eaAllowTrade); - eaExpert.StartTradeAt(eaStartTradeAt); - eaExpert.StopTradeAt(eaStopTradeAt); - eaExpert.CloseAllTradesAt(eaCloseAllTradesAt); - - // - // Risk Management ... - eaExpert.R2R(eaR2R); - eaExpert.Volume(eaVolume); - eaExpert.StaticBalance(eaStaticBalance); - eaExpert.BalancePerTrade(eaBalancePerTrade); - eaExpert.RiskPercentPerBalance(eaRiskPercentPerBalance); - eaExpert.DynamicRiskManagement(eaDynamicRiskManagement); - eaExpert.UseDynamicVolume(eaUseDynamicVolume); - eaExpert.DynamicVolumeStep(eaDynamicVolumeStep); - eaExpert.DynamicVolumeBalanceFactor(eaDynamicVolumeBalanceFactor); - eaExpert.MaxAllowedDrawdownToOpenTrades(eaMaxAllowedDrawdownToOpenTrades); - eaExpert.MaxAllowedSLToPauseSignallingPerSymbol(eaMaxAllowedSLToPauseSignallingPerSymbol); - eaExpert.PauseSignallingAfterReachesMaxAllowedSLInSecconds(eaPauseSignallingAfterReachesMaxAllowedSLInSecconds); - - // - // Protection ... - eaExpert.AllowHedging(eaAllowHedging); - eaExpert.MinOpenTradesFroHedging(eaMinOpenTradesFroHedging); - eaExpert.HedgingMinVolumeStep(eaHedgingMinVolumeStep); - eaExpert.HedgeingMinRequiredProfitPerVolumeStep(eaHedgeingMinRequiredProfitPerVolumeStep); - - // - // Alert ... - eaExpert.SetAlertEnableAlerts(eaEnableAlerts); - eaExpert.SetAlertLogAlerts(eaLogAlerts); - eaExpert.SetAlertMailAlerts(eaMailAlerts); - eaExpert.SetAlertPushAlerts(eaPushAlerts); - eaExpert.SetAlertTerminalAlerts(eaTerminalAlerts); - - // - // Reports ... - eaExpert.ReportNewMonths(eaReportNewMonths); - eaExpert.ReportNewWeeks(eaReportNewWeeks); - eaExpert.ReportNewDays(eaReportNewDays); - eaExpert.ReportNewHours(eaReportNewHours); - - // - bool isInited = eaExpert.HandleOnInit(); - if (!isInited) - { - return INIT_FAILED; - } - - // - // Init Succeed ... - return INIT_SUCCEEDED; -} - -// -// DeInitialization ... -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 - - // - // Destroy Timer ... - eaExpert.HandleOnDeInit(); - - // - delete eaExpert; - - // - ZeroMemory(eaExpert); -} - -// -// On Tick Handler ... -void OnTick() -{ - eaExpert.HandleOnTick(); -} - -// -// Handle On Trade Event ... -void OnTrade() -{ - eaExpert.HandleOnTrade(); -} - -// -// On Timer ... -void OnTimer() -{ - eaExpert.HandleOnTimer(); -} - -// -// Chart Event Handler ... -void OnChartEvent( - const int id, - const long &lparam, - const double &dparam, - const string &sparam // -) -{ - eaExpert.HandleOnChartEvent(id, lparam, dparam, sparam); -} - -// -// Event Listeners ... - -/** - * Do What we Want by Specific Signal ... - * - * @param signal: XSignal instance ... - * @param conditions: XStrategyConditions instance ... - */ -void OnSignalRecieved( - XSignal &signal, - X121SMCStrategyConditions &conditions // -) -{ - // - eaExpert.HandleOnSignalRecieved( - signal, - conditions // - ); -} - -/** - * Handle StopLoss Triggered Positions ... - * - * @param deal: XDeal instance ... - */ -void OnStopLossTriggered(const XDeal &deal) -{ - eaExpert.HandleOnStopLossTriggered(deal); -} - -/** - * Handle Take Profit Triggered Positions ... - * - * @param deal: XDeal instance ... - */ -void OnTakeProfitTriggered(const XDeal &deal) -{ - eaExpert.HandleOnTakeProfitTriggered(deal); -} - -/** - * Handle Force Close a Position ... - * - * @param ticket: ULONG ... - * @param position: XPosition instance ... - * @param comment: String ... - */ -void OnPositionForceClosed( - const ulong ticket, - const XPosition &position, - const string comment // -) -{ - // - eaExpert.HandleOnPositionForceClosed( - ticket, - position, - comment // - ); -} - -/** - * Handle Deals Changes ... - * - * @param count: Integer, Number of Changes ... - */ -void OnDealsChanged(int count) -{ - eaExpert.HandleOnDealsChanged(count); -} - -/** - * Handle Orders Changes ... - * - * @param count: Integer, Number of Changes ... - */ -void OnOrdersChanged(int count) -{ - eaExpert.HandleOnOrdersChanged(count); -} - -/** - * Handle Positions Changes ... - * - * @param count: Integer, Number of Changes ... - */ -void OnPositionsChanged(int count) -{ - eaExpert.HandleOnPositionsChanged(count); -} - -// -// Custom Functions ... - -/** - * Validate all Inputs of Expert Adviser ... - * - * @return ( bool ) - */ -bool ValidateInputs() -{ - // - bool result = false; - - // - string errMessage = ""; - - // - bool isCommonValid = ( - // - eaSlippage > 0 && - eaMagicNumber > 0 - // - ); - if (!isCommonValid) - { - // - errMessage += "common configurations error;" + "\n"; - } - - // - result = - // - // Common ... - isCommonValid && - // - // Otere ... - true - // - ; - - // - if (!result) - { - // - // Since here Logger not Initiallized, we Use Raw Print Command ... - Print(ShortName + " Errors: \n", errMessage); - } - - // - return result; -} - -/** - * Initialize Timer ... - * - * @return ( bool ) - */ -bool InitTimer() -{ - // - bool result = false; - - // - // TODO: Initialize Timer if necessary ... - // result = EventSetTimer(1); - // result = EventSetMillisecondTimer(100); - result = true; - - // - return result; -} - -/** - * Destroy Timer ... - */ -void DestroyTimer() -{ - // - // TODO: Use This ... - // EventKillTimer(); -} - -//