From 43b3cdc6b9f95502d3ac9437b2cfc42e16a3deb8 Mon Sep 17 00:00:00 2001 From: Hadi Khazaee Asl Date: Wed, 25 Dec 2024 05:17:29 +0330 Subject: [PATCH] complete XPVSUPDEM Provider and attached it to SMC Strategy ... also Cleanup Test Provider and Make a Backup of it for Next Usages ... --- Classes/x-saherelm.x-cobject.class.mq5 | 29 +- Classes/x-saherelm.x-expert.class.mq5 | 32 +- Documents/BKP/2/x-test-signal.smc.mq5 | 830 ++++++++++++ Libraries/x-saherelm.x-poi.lib.mq5 | 14 +- .../x-121.smc.market.cycle.helper.class.mq5 | 62 + X121SMCEA/Experts/x-121.smc.expert.class.mq5 | 20 +- X121SMCEA/Libraries/x-121.smc.lib.mq5 | 11 + .../Signals/x-121.smc.test.signal.class.mq5 | 68 +- .../Signals/x-121.smc.xpvob.signal.class.mq5 | 9 +- .../x-121.smc.xpvsupdem.signal.class.mq5 | 1188 +++++++++++++++++ .../Strategy/x-121.smc.strategy.class.mq5 | 321 ++++- 11 files changed, 2470 insertions(+), 114 deletions(-) create mode 100644 Documents/BKP/2/x-test-signal.smc.mq5 create mode 100644 X121SMCEA/Signals/x-121.smc.xpvsupdem.signal.class.mq5 diff --git a/Classes/x-saherelm.x-cobject.class.mq5 b/Classes/x-saherelm.x-cobject.class.mq5 index 26fc987e..55c89acf 100644 --- a/Classes/x-saherelm.x-cobject.class.mq5 +++ b/Classes/x-saherelm.x-cobject.class.mq5 @@ -1527,7 +1527,6 @@ class XCConsolidationZoneObject : public XCBaseObject ObjName(name); } - // return result; } @@ -2168,7 +2167,7 @@ class XCTickZoneObject : public XCBaseObject chart_id, lblName, window, - from, + to, zone.high // ); if (!result) @@ -2179,6 +2178,23 @@ class XCTickZoneObject : public XCBaseObject // mLabel.Description(ToString(zone.percent) + "%"); + // + string lblVName = "LBLV_" + name; + result = mVLabel.Create( + chart_id, + lblVName, + window, + to, + zone.low // + ); + if (!result) + { + return result; + } + + // + mVLabel.Description(ToString(zone.volumePercent) + "%"); + // ObjName(name); @@ -2256,7 +2272,9 @@ class XCTickZoneObject : public XCBaseObject */ void LabelColor(color value) { + // mLabel.Color(value); + mVLabel.Color(value); } /** @@ -2266,7 +2284,9 @@ class XCTickZoneObject : public XCBaseObject */ void LabelSize(int value) { + // mLabel.FontSize(value); + mVLabel.FontSize(value); } /** @@ -2276,7 +2296,9 @@ class XCTickZoneObject : public XCBaseObject */ void LabelFont(string value) { + // mLabel.Font(value); + mVLabel.Font(value); } /** @@ -2286,7 +2308,9 @@ class XCTickZoneObject : public XCBaseObject */ void LabelAngle(double value) { + // mLabel.Angle(value); + mVLabel.Angle(value); } // @@ -2295,6 +2319,7 @@ class XCTickZoneObject : public XCBaseObject // Props ... CChartObjectRectangle mRect; CChartObjectLabel mLabel; + CChartObjectLabel mVLabel; // }; diff --git a/Classes/x-saherelm.x-expert.class.mq5 b/Classes/x-saherelm.x-expert.class.mq5 index 35017ea8..ecf1273c 100644 --- a/Classes/x-saherelm.x-expert.class.mq5 +++ b/Classes/x-saherelm.x-expert.class.mq5 @@ -81,7 +81,7 @@ class XCBaseExpert : public XCBaseAlert { // mMagicNumber = value; - InitEA(); + ReConfigure(); } /** @@ -103,7 +103,7 @@ class XCBaseExpert : public XCBaseAlert { // mSlippage = value; - InitEA(); + ReConfigure(); } /** @@ -125,7 +125,7 @@ class XCBaseExpert : public XCBaseAlert { // mTagPrefix = value; - InitEA(); + ReConfigure(); } // @@ -150,7 +150,7 @@ class XCBaseExpert : public XCBaseAlert { // mPeriod = value; - InitEA(); + ReConfigure(); } /** @@ -172,7 +172,7 @@ class XCBaseExpert : public XCBaseAlert { // mSymbol = value; - InitEA(); + ReConfigure(); } /** @@ -194,7 +194,7 @@ class XCBaseExpert : public XCBaseAlert { // mMultiSymbol = value; - InitEA(); + ReConfigure(); } /** @@ -216,7 +216,7 @@ class XCBaseExpert : public XCBaseAlert { // mSymbols = value; - InitEA(); + ReConfigure(); } // @@ -241,7 +241,7 @@ class XCBaseExpert : public XCBaseAlert { // mDisabled = value; - InitEA(); + ReConfigure(); } /** @@ -263,7 +263,7 @@ class XCBaseExpert : public XCBaseAlert { // mAllowLong = value; - InitEA(); + ReConfigure(); } /** @@ -285,7 +285,7 @@ class XCBaseExpert : public XCBaseAlert { // mAllowShort = value; - InitEA(); + ReConfigure(); } // @@ -310,7 +310,7 @@ class XCBaseExpert : public XCBaseAlert { // mReportNewMonths = value; - InitEA(); + ReConfigure(); } /** @@ -332,7 +332,7 @@ class XCBaseExpert : public XCBaseAlert { // mReportNewWeeks = value; - InitEA(); + ReConfigure(); } /** @@ -354,7 +354,7 @@ class XCBaseExpert : public XCBaseAlert { // mReportNewDays = value; - InitEA(); + ReConfigure(); } /** @@ -376,7 +376,7 @@ class XCBaseExpert : public XCBaseAlert { // mReportNewHours = value; - InitEA(); + ReConfigure(); } // @@ -805,6 +805,10 @@ class XCBaseExpert : public XCBaseAlert { } + virtual void ReConfigure() + { + } + /** * Generate Identifier Tag ... * diff --git a/Documents/BKP/2/x-test-signal.smc.mq5 b/Documents/BKP/2/x-test-signal.smc.mq5 new file mode 100644 index 00000000..524e508c --- /dev/null +++ b/Documents/BKP/2/x-test-signal.smc.mq5 @@ -0,0 +1,830 @@ +///////////////////////////////////////////////////////////////////////////////////////////////////////////// + + +/////////////////////////////////////////////////////// +// +// SaherElm IT Center MQL5 X121 SMC Signal Class +// ------------------------------------------------- +// Name: +// 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.lib.mq5" + +// +// Definitions ... +struct X121SMCStrategyTestSignalConditions +{ + // + // Props ... + + // + string symbol; + ENUM_TIMEFRAMES period; + + // + double sl; + ENUM_X_DIRECTION dir; + ENUM_X_POSITION_TYPES type; + + // + // Setup Props ... + + // + datetime setupTime; + datetime triggerTime; + + // + // Constructor ... + X121SMCStrategyTestSignalConditions() + { + Clean(); + } + + // + // Tools ... + + /** + * Cleaning Up ... + */ + void Clean() + { + // + sl = 0; + + // + dir = X_DIRECTION_NONE; + type = X_POSITION_TYPE_NONE; + + // + symbol = NULL; + period = NULL; + setupTime = NULL; + triggerTime = NULL; + + // + ExtensionClean(); + } + + /** + * 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() + { + } + + // +}; + +// +// Extension Functions ... + +// +// Detect Setup Conditions ... +bool DetectX121SMCTestSiganlSetup( + string _symbol, + ENUM_TIMEFRAMES _period, + // + X121SMCStrategyTestSignalConditions &conditions, + // + XC121SMCCycleHelper *triggerCycleHelper, + XC121SMCCycleHelper *decisionCycleHelper, + XC121SMCCycleHelper *analyseCycleHelper, + XC121SMCCycleHelper *verificationCycleHelper, + XC121SMCCycleHelper *consolidationCycleHelper, + XC121SMCCycleHelper *visionCycleHelper + // +) +{ + // + bool result = false; + + // + 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; + + // + conditions.symbol = symbol; + conditions.period = period; + + // + XOHCL zBar; + result = zBar.Init( + symbol, + period, + zIndex // + ); + if (!result) + { + return result; + } + + // + XOHCL cBar; + result = cBar.Init( + symbol, + period, + cIndex // + ); + if (!result) + { + return result; + } + + // + double ask = GetAsk(symbol); + double bid = GetBid(symbol); + datetime cTime = TimeCurrent(); + + // + double ll = cBar.FindLowest(9, MODE_LOW); + double hh = cBar.FindHighest(9, MODE_HIGH); + + // + int zoneValidationDivider = 10; + int validPivotRepetition = triggerCycleHelper.mX121Helper + .GetDonChainLength(); + + // + double selectedSL = 0; + + // + // Cycles Conditions ... + + // + // Trigger ... + ENUM_XPOI_EVENTS triggerPoiEvents[]; + ENUM_X_CYCLE_EVENTS triggerCycleEvents[]; + X121SMCCycleConditions triggerConditions; + result = triggerCycleHelper.GetConditions( + triggerCycleEvents, + triggerPoiEvents, + triggerConditions, + zIndex, + loopback // + ); + if (!result) + { + return result; + } + + // + // 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; + } + + // + // Verification ... + ENUM_XPOI_EVENTS verificationPoiEvents[]; + ENUM_X_CYCLE_EVENTS verificationCycleEvents[]; + X121SMCCycleConditions verificationConditions; + result = verificationCycleHelper.GetConditions( + verificationCycleEvents, + verificationPoiEvents, + verificationConditions, + 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 triggerState = triggerConditions.state; + XPOIState decisionState = decisionConditions.state; + XPOIState analyseState = analyseConditions.state; + XPOIState verificationState = verificationConditions.state; + XPOIState consolidationState = consolidationConditions.state; + XPOIState visionState = visionConditions.state; + + // + // Setup Conditions ... + + // + isBullish = + // + false + // + ; + + // + isBearish = + // + false + // + ; + + // + result = isBullish || + isBearish; + if (!result) + { + // + // Clean Conditions for Regenerate ... + + // + return result; + } + + // + conditions.setupTime = cTime; + conditions.dir = + isBullish + ? X_DIRECTION_BULLISH + : X_DIRECTION_BEARISH; + + // + return result; +} + +// +// Detect Trigger Conditions ... +bool DetectX121SMCTestSiganlTrigger( + // + X121SMCStrategyTestSignalConditions &conditions, + // + string _symbol, + ENUM_TIMEFRAMES _period, + // + XC121SMCCycleHelper *triggerCycleHelper, + XC121SMCCycleHelper *decisionCycleHelper, + XC121SMCCycleHelper *analyseCycleHelper, + XC121SMCCycleHelper *verificationCycleHelper, + XC121SMCCycleHelper *consolidationCycleHelper, + XC121SMCCycleHelper *visionCycleHelper, + // + int maxAllowedSetupAge = 60 // + // +) +{ + // + bool result = false; + + // + result = conditions.IsSetuped(); + if (!result) + { + return result; + } + + // + datetime setupTime = conditions.setupTime; + ENUM_X_DIRECTION setupDir = conditions.dir; + + // + 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; + + // + XOHCL zBar; + result = zBar.Init( + symbol, + period, + zIndex // + ); + if (!result) + { + return result; + } + + // + XOHCL cBar; + result = cBar.Init( + symbol, + period, + cIndex // + ); + if (!result) + { + return result; + } + + // + double ask = GetAsk(symbol); + double bid = GetBid(symbol); + datetime cTime = TimeCurrent(); + + // + double ll = cBar.FindLowest(9, MODE_LOW); + double hh = cBar.FindHighest(9, MODE_HIGH); + + // + int zoneValidationDivider = 10; + int validPivotRepetition = triggerCycleHelper.mX121Helper + .GetDonChainLength(); + + // + double selectedSL = 0; + + // + // Cycles Conditions ... + + // + // Trigger ... + ENUM_XPOI_EVENTS triggerPoiEvents[]; + ENUM_X_CYCLE_EVENTS triggerCycleEvents[]; + X121SMCCycleConditions triggerConditions; + result = triggerCycleHelper.GetConditions( + triggerCycleEvents, + triggerPoiEvents, + triggerConditions, + zIndex, + loopback // + ); + if (!result) + { + return result; + } + + // + // 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; + } + + // + // Verification ... + ENUM_XPOI_EVENTS verificationPoiEvents[]; + ENUM_X_CYCLE_EVENTS verificationCycleEvents[]; + X121SMCCycleConditions verificationConditions; + result = verificationCycleHelper.GetConditions( + verificationCycleEvents, + verificationPoiEvents, + verificationConditions, + 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 triggerState = triggerConditions.state; + XPOIState decisionState = decisionConditions.state; + XPOIState analyseState = analyseConditions.state; + XPOIState verificationState = verificationConditions.state; + XPOIState consolidationState = consolidationConditions.state; + XPOIState visionState = visionConditions.state; + + // + // Trigger Conditions ... + + // + isBullish = + // + false + // + ; + + // + isBearish = + // + false + // + ; + + // + result = isBullish || + isBearish; + if (!result) + { + // + // Cleanup Setup Conditions ... + + // + return result; + } + + // + conditions.triggerTime = cTime; + conditions.sl = isBullish + ? 0 + : 0; + conditions.type = isBullish + ? X_POSITION_TYPE_LONG + : X_POSITION_TYPE_SHORT; + + // + return result; +} + +// + + +////////////////////////////////////////////////////////////////////////////////////////// + + + // + // Test Signal ... + X121SMCStrategyTestSignalConditions mTestConditions; + bool DetectTestSignal( + X121SMCStrategyConditions &conditions // + ) + { + // + bool result = false; + + // + bool isBullish = false; + bool isBearish = false; + + // + string symbol = GetSymbol(); + ENUM_TIMEFRAMES period = GetPeriod(); + + // + datetime cTime = TimeCurrent(); + + // + ENUM_X_121_SMC_PROVIDERS provider = X_121_SMC_PROVIDER_XTEST; + string providerStr = ToString(provider); + + // + // Detect Setup Conditions ... + datetime setupTime = mTestConditions.setupTime; + bool isSetuped = mTestConditions.IsSetuped(); + ENUM_X_DIRECTION setupDir = mTestConditions.dir; + if (!isSetuped) + { + // + // Detect Signal Setup ... + isSetuped = DetectX121SMCTestSiganlSetup( + symbol, + period, + mTestConditions, + mTriggerCycleHelper, + mDecisionCycleHelper, + mAnalyseCycleHelper, + mVerificationCycleHelper, + mConsolidationCycleHelper, + mVisionCycleHelper // + ); + + // + setupDir = mTestConditions.dir; + setupTime = mTestConditions.setupTime; + } + + // ClearDraws(); + // ENUM_X_DIRECTION activeZoneDir; + // bool hasTicksZone = mTestConditions.HasTicksZone(); + // bool hasActiveZone = mTestConditions.HasActiveZone(activeZoneDir); + // if (hasActiveZone) + // { + // // + // if (IsBullish(activeZoneDir)) + // { + // // + // mTestConditions.activeDemandZone.To(cTime); + // XCDemandZoneObject *iObj; + // bool isCreated = mPOIDrawer.CreateDemandZone( + // mTestConditions.activeDemandZone, + // iObj // + // ); + // if (isCreated) + // { + // AddObjectIfNotExists(iObj); + // } + // } + // else + // { + // // + // mTestConditions.activeSupplyZone.To(cTime); + // XCSupplyZoneObject *iObj; + // bool isCreated = mPOIDrawer.CreateSupplyZone( + // mTestConditions.activeSupplyZone, + // iObj // + // ); + // if (isCreated) + // { + // AddObjectIfNotExists(iObj); + // } + // } + // } + // if (hasTicksZone) + // { + // // + // XCTicksZoneObject *iObj; + // bool isCreated = mPOIDrawer.CreateTicksZone( + // mTestConditions.ticksZone, + // iObj // + // ); + // if (isCreated) + // { + // AddObjectIfNotExists(iObj); + // } + // } + + // + result = isSetuped; + if (!result) + { + return result; + } + + // + // Detect Trigger Conditions ... + bool canTrigger = mTestConditions.CanTrigger(); + datetime triggerTime = mTestConditions.triggerTime; + if (!canTrigger) + { + // + // Detect Signal Trigger ... + canTrigger = DetectX121SMCTestSiganlTrigger( + mTestConditions, + symbol, + period, + mTriggerCycleHelper, + mDecisionCycleHelper, + mAnalyseCycleHelper, + mVerificationCycleHelper, + mConsolidationCycleHelper, + mVisionCycleHelper // + ); + + // + result = canTrigger; + if (!result) + { + return result; + } + + // + triggerTime = mTestConditions.triggerTime; + } + + // + // Check Signal Direction ... + + // + isBullish = IsBullish(setupDir); + isBearish = IsBearish(setupDir); + result = isBullish || + isBearish; + if (!result) + { + return result; + } + + // + // Issues Signal on Conditions ... + conditions.signalDir = setupDir; + conditions.provider = providerStr; + conditions.sl = mTestConditions.sl; + + // + mTestConditions.Clean(); + + // + return result; + } + + +////////////////////////////////////////////////////////////////////////////////////////// diff --git a/Libraries/x-saherelm.x-poi.lib.mq5 b/Libraries/x-saherelm.x-poi.lib.mq5 index cfd7d38f..a915367e 100644 --- a/Libraries/x-saherelm.x-poi.lib.mq5 +++ b/Libraries/x-saherelm.x-poi.lib.mq5 @@ -377,7 +377,15 @@ class XCZone : public XCBasePOI */ bool IsValidFrom() { - return IsSpecifiedValid(From()); + // + bool result = false; + + // + datetime from = From(); + result = IsSpecifiedValid(from); + + // + return result; } // @@ -2822,6 +2830,10 @@ class XCTicksZone : public XCTwoBarZone // result = IsValid(); + if (!result) + { + return result; + } // // Try to Find Out PERIOD_1M times in each zone ... diff --git a/X121SMCEA/Classes/x-121.smc.market.cycle.helper.class.mq5 b/X121SMCEA/Classes/x-121.smc.market.cycle.helper.class.mq5 index a4b9bdc8..04339619 100644 --- a/X121SMCEA/Classes/x-121.smc.market.cycle.helper.class.mq5 +++ b/X121SMCEA/Classes/x-121.smc.market.cycle.helper.class.mq5 @@ -1330,6 +1330,37 @@ class XC121SMCCycleHelper : public XCBase return result; } + /** + * Get Last Peaks Pivot Point ... + * + * @param pivot: XPVPivotPoint instance Reference ... + * + * @return ( bool ) + */ + bool GetLastPeakPivotPoint(XPVPivotPoint &pivot) + { + // + bool result = false; + + // + pivot.Clean(); + + // + XPVPivotPoint pivots[]; + int count = FillPeakPivotPoints(pivots); + result = IsValidSize(count); + if (!result) + { + return result; + } + + // + pivot = pivots[count - 1]; + + // + return result; + } + /** * Retrieve All Vale Pivot Point Changes as a Collection ... * @@ -1377,6 +1408,37 @@ class XC121SMCCycleHelper : public XCBase return result; } + /** + * Get Last Vale Pivot Point ... + * + * @param pivot: XPVPivotPoint instance Reference ... + * + * @return ( bool ) + */ + bool GetLastValePivotPoint(XPVPivotPoint &pivot) + { + // + bool result = false; + + // + pivot.Clean(); + + // + XPVPivotPoint pivots[]; + int count = FillValePivotPoints(pivots); + result = IsValidSize(count); + if (!result) + { + return result; + } + + // + pivot = pivots[count - 1]; + + // + return result; + } + /** * Get Current Active Pivot ... * diff --git a/X121SMCEA/Experts/x-121.smc.expert.class.mq5 b/X121SMCEA/Experts/x-121.smc.expert.class.mq5 index d1ec948d..200107f1 100644 --- a/X121SMCEA/Experts/x-121.smc.expert.class.mq5 +++ b/X121SMCEA/Experts/x-121.smc.expert.class.mq5 @@ -1277,6 +1277,17 @@ class XC121SMCExpert : public XCBaseExpert mTradeHandler.ResumePausedSymbols(); } + /** + * Re Configure Materials on Properties Changed ... + */ + void ReConfigure() override + { + // + // TODO: Enable this on Production ... + // ReConfigureTradeHandler(); + // ReConfigureAllStrategies(); + } + /** * Generate Identifier Tag ... * @@ -1562,15 +1573,6 @@ class XC121SMCExpert : public XCBaseExpert double mHedgingMinVolumeStep; // Minimum Volume Step for Hedging ... double mHedgeingMinRequiredProfitPerVolumeStep; // Minimum Required Profit Per Volume Step for Hedging ... - // - // Reconfigure Class On Properties Change ... - void ReConfigure() - { - // - ReConfigureTradeHandler(); - ReConfigureAllStrategies(); - } - // double CalculateAdditionalVolumeMultiplier(XSignal &signal) { diff --git a/X121SMCEA/Libraries/x-121.smc.lib.mq5 b/X121SMCEA/Libraries/x-121.smc.lib.mq5 index ad2f8c35..85471e89 100644 --- a/X121SMCEA/Libraries/x-121.smc.lib.mq5 +++ b/X121SMCEA/Libraries/x-121.smc.lib.mq5 @@ -36,6 +36,7 @@ const string X121SMCStrategyToken = "X121SMC"; // const string X121SMCXTestToken = "X121XTest"; const string X121SMCXPVOBToken = "X121XPVOB"; +const string X121SMCXPVSupDemToken = "X121XPVSUPDEM"; // // X121 SMC Providers ... @@ -45,6 +46,7 @@ enum ENUM_X_121_SMC_PROVIDERS X_121_SMC_PROVIDER_NONE, X_121_SMC_PROVIDER_XTEST, X_121_SMC_PROVIDER_XPVOB, + X_121_SMC_PROVIDER_XPVSUPDEM, }; // @@ -1957,6 +1959,11 @@ string ToString(ENUM_X_121_SMC_PROVIDERS value) case X_121_SMC_PROVIDER_XPVOB: result = X121SMCXPVOBToken; break; + + // + case X_121_SMC_PROVIDER_XPVSUPDEM: + result = X121SMCXPVSupDemToken; + break; } // @@ -1990,6 +1997,10 @@ ENUM_X_121_SMC_PROVIDERS ParseProvider(string value) { result = X_121_SMC_PROVIDER_XPVOB; } + else if (Contains(X121SMCXPVSupDemToken, value)) + { + result = X_121_SMC_PROVIDER_XPVSUPDEM; + } // return result; diff --git a/X121SMCEA/Signals/x-121.smc.test.signal.class.mq5 b/X121SMCEA/Signals/x-121.smc.test.signal.class.mq5 index 30550e76..e020c575 100644 --- a/X121SMCEA/Signals/x-121.smc.test.signal.class.mq5 +++ b/X121SMCEA/Signals/x-121.smc.test.signal.class.mq5 @@ -47,9 +47,6 @@ struct X121SMCStrategyTestSignalConditions datetime setupTime; datetime triggerTime; - // - // Trigger Props ... - // // Constructor ... X121SMCStrategyTestSignalConditions() @@ -79,6 +76,7 @@ struct X121SMCStrategyTestSignalConditions triggerTime = NULL; // + ExtensionClean(); } /** @@ -157,6 +155,13 @@ struct X121SMCStrategyTestSignalConditions // // Extensions ... + /** + * Clean Additional Properties ... + */ + void ExtensionClean() + { + } + // }; @@ -359,26 +364,30 @@ bool DetectX121SMCTestSiganlSetup( XPOIState consolidationState = consolidationConditions.state; XPOIState visionState = visionConditions.state; + // + // Setup Conditions ... + + // + isBullish = + // + false + // + ; + + // + isBearish = + // + false + // + ; + // result = isBullish || isBearish; if (!result) { // - // if (lookupForLong) - // { - // // - // conditions.activeFVG = NULL; - // Clean(conditions.bullishOBs); - // Clean(conditions.bullishFVGs); - // } - // else if (lookupForShort) - // { - // // - // conditions.activeFVG = NULL; - // Clean(conditions.bearishOBs); - // Clean(conditions.bearishFVGs); - // } + // Clean Conditions for Regenerate ... // return result; @@ -605,13 +614,18 @@ bool DetectX121SMCTestSiganlTrigger( // Trigger Conditions ... // - // Create Trigger ... + isBullish = + // + false + // + ; // - isBullish = false; - - // - isBearish = false; + isBearish = + // + false + // + ; // result = isBullish || @@ -620,13 +634,6 @@ bool DetectX121SMCTestSiganlTrigger( { // // Cleanup Setup Conditions ... - int setupAge = conditions.GetSetupAge(); - if (IsValidSize(setupAge) && - IsValidSize(maxAllowedSetupAge) && - setupAge >= maxAllowedSetupAge) - { - conditions.Clean(); - } // return result; @@ -645,7 +652,4 @@ bool DetectX121SMCTestSiganlTrigger( return result; } -// -// Tools Functions ... - // \ No newline at end of file diff --git a/X121SMCEA/Signals/x-121.smc.xpvob.signal.class.mq5 b/X121SMCEA/Signals/x-121.smc.xpvob.signal.class.mq5 index cca39532..3522224c 100644 --- a/X121SMCEA/Signals/x-121.smc.xpvob.signal.class.mq5 +++ b/X121SMCEA/Signals/x-121.smc.xpvob.signal.class.mq5 @@ -56,9 +56,6 @@ struct X121SMCStrategyXPVOBSignalConditions XCFVG *bullishFVGs[]; XCFVG *bearishFVGs[]; - // - // Trigger Props ... - // // Constructor ... X121SMCStrategyXPVOBSignalConditions() @@ -420,11 +417,15 @@ bool DetectX121SMCXPVOBSiganlSetup( XPOIState visionState = visionConditions.state; // - // Detect Imbalances ... + // Setup Conditions ... // + // Select Source State ... XPOIState state = decisionState; + // + // Detect Imbalance ... + // bool hasBullishOB = conditions.HasBullishOB(); if (!hasBullishOB) diff --git a/X121SMCEA/Signals/x-121.smc.xpvsupdem.signal.class.mq5 b/X121SMCEA/Signals/x-121.smc.xpvsupdem.signal.class.mq5 new file mode 100644 index 00000000..a5d59a95 --- /dev/null +++ b/X121SMCEA/Signals/x-121.smc.xpvsupdem.signal.class.mq5 @@ -0,0 +1,1188 @@ +/////////////////////////////////////////////////////// +// +// SaherElm IT Center MQL5 X121 SMC Signal Class +// ------------------------------------------------- +// Name: +// 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.lib.mq5" + +// +// Definitions ... +struct X121SMCStrategyXPVSUPDEMSignalConditions +{ + // + // Props ... + + // + string symbol; + ENUM_TIMEFRAMES period; + + // + double sl; + ENUM_X_DIRECTION dir; + ENUM_X_POSITION_TYPES type; + + // + // Setup Props ... + + // + datetime setupTime; + datetime triggerTime; + + // + XCTicksZone *ticksZone; + XCSupplyZone *supplyZones[]; + XCDemandZone *demandZones[]; + datetime activeZoneFoundedAt; + XCSupplyZone *activeSupplyZone; + XCDemandZone *activeDemandZone; + + // + // Constructor ... + X121SMCStrategyXPVSUPDEMSignalConditions() + { + Clean(); + } + + // + // Tools ... + + /** + * Cleaning Up ... + */ + void Clean() + { + // + sl = 0; + + // + dir = X_DIRECTION_NONE; + type = X_POSITION_TYPE_NONE; + + // + symbol = NULL; + period = NULL; + setupTime = NULL; + triggerTime = NULL; + + // + ExtensionClean(); + } + + /** + * 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() + { + // + ticksZone = NULL; + activeSupplyZone = NULL; + activeDemandZone = NULL; + activeZoneFoundedAt = NULL; + + // + Clean(supplyZones); + Clean(demandZones); + } + + /** + * Count Supply Zones ... + * + * @return ( int ) + */ + int CountSupplyZones() + { + return ArraySize(supplyZones); + } + + /** + * Count Demand Zones ... + * + * @return ( int ) + */ + int CountDemandZones() + { + return ArraySize(demandZones); + } + + /** + * Check Has Supply Zones ... + * + * @return ( bool ) + */ + bool HasSupplyZones() + { + return IsValidSize(CountSupplyZones()); + } + + /** + * Check Has Demand Zones ... + * + * @return ( bool ) + */ + bool HasDemandZones() + { + return IsValidSize(CountDemandZones()); + } + + /** + * Check Has Active Supply or Demand Zone ... + * + * @param _dir: ENUM_X_DIRECTION member Reference for Specify Active Zone ... + * + * @return ( bool ) + */ + bool HasActiveZone(ENUM_X_DIRECTION &_dir) + { + // + bool result = false; + + // + _dir = X_DIRECTION_NONE; + + // + // Check Supplies ... + bool hasActiveSupplyZone = activeSupplyZone != NULL && + activeSupplyZone.IsValid(); + + // + // Check Demnds ... + bool hasActiveDemandZone = activeDemandZone != NULL && + activeDemandZone.IsValid(); + + // + result = hasActiveSupplyZone || + hasActiveDemandZone; + if (!result) + { + return result; + } + + // + _dir = hasActiveDemandZone + ? X_DIRECTION_BULLISH + : X_DIRECTION_BEARISH; + + // + return result; + } + + /** + * Retrieve Active Zone Reference if Exists ... + * + * @return ( bool ) + */ + bool GetActiveZone(XCBarZone *&activeZone) + { + // + bool result = false; + + // + activeZone = NULL; + + // + ENUM_X_DIRECTION activeZoneDir; + result = HasActiveZone(activeZoneDir); + if (!result) + { + return result; + } + + // + if (IsBullish(activeZoneDir)) + { + // + activeDemandZone.To(TimeCurrent()); + activeZone = activeDemandZone; + } + else + { + // + activeSupplyZone.To(TimeCurrent()); + activeZone = activeSupplyZone; + } + + // + return result; + } + + /** + * Check Ticks Zone is Initialized or not ... + * @return ( bool ) + */ + bool HasTicksZone() + { + // + bool result = false; + + // + result = + // + ticksZone != NULL && + ticksZone.IsValid() && + IsValidSize(ticksZone.Count()) + // + ; + + // + return result; + } + + // +}; + +// +// Extension Functions ... + +// +// Detect Setup Conditions ... +bool DetectX121SMCXPVSUPDEMSiganlSetup( + string _symbol, + ENUM_TIMEFRAMES _period, + // + X121SMCStrategyXPVSUPDEMSignalConditions &conditions, + // + XC121SMCCycleHelper *triggerCycleHelper, + XC121SMCCycleHelper *decisionCycleHelper, + XC121SMCCycleHelper *analyseCycleHelper, + XC121SMCCycleHelper *verificationCycleHelper, + XC121SMCCycleHelper *consolidationCycleHelper, + XC121SMCCycleHelper *visionCycleHelper + // +) +{ + // + bool result = false; + + // + 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; + + // + conditions.symbol = symbol; + conditions.period = period; + + // + XOHCL zBar; + result = zBar.Init( + symbol, + period, + zIndex // + ); + if (!result) + { + return result; + } + + // + XOHCL cBar; + result = cBar.Init( + symbol, + period, + cIndex // + ); + if (!result) + { + return result; + } + + // + double ask = GetAsk(symbol); + double bid = GetBid(symbol); + datetime cTime = TimeCurrent(); + + // + double ll = cBar.FindLowest(9, MODE_LOW); + double hh = cBar.FindHighest(9, MODE_HIGH); + + // + int zoneValidationDivider = 10; + int validPivotRepetition = triggerCycleHelper.mX121Helper + .GetDonChainLength(); + + // + double selectedSL = 0; + + // + // Cycles Conditions ... + + // + // Trigger ... + ENUM_XPOI_EVENTS triggerPoiEvents[]; + ENUM_X_CYCLE_EVENTS triggerCycleEvents[]; + X121SMCCycleConditions triggerConditions; + result = triggerCycleHelper.GetConditions( + triggerCycleEvents, + triggerPoiEvents, + triggerConditions, + zIndex, + loopback // + ); + if (!result) + { + return result; + } + + // + // 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; + } + + // + // Verification ... + ENUM_XPOI_EVENTS verificationPoiEvents[]; + ENUM_X_CYCLE_EVENTS verificationCycleEvents[]; + X121SMCCycleConditions verificationConditions; + result = verificationCycleHelper.GetConditions( + verificationCycleEvents, + verificationPoiEvents, + verificationConditions, + 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 triggerState = triggerConditions.state; + XPOIState decisionState = decisionConditions.state; + XPOIState analyseState = analyseConditions.state; + XPOIState verificationState = verificationConditions.state; + XPOIState consolidationState = consolidationConditions.state; + XPOIState visionState = visionConditions.state; + + // + // Setup Conditions ... + + // + // Select Source State ... + XPOIState state = consolidationState; + + // + // Detect Supply and Demand Zones ... + + // + // Supply ... + bool hasSupplyZones = conditions.HasSupplyZones(); + if (!hasSupplyZones) + { + // + int count = state.CountSupplyZones(); + for (int i = count - 1; i >= 0; i--) + { + // + XCSupplyZone *iZone = state.supplyZones[i]; + + // + bool isValid = + // + ask < iZone.Lower() && + bid < iZone.Lower() && + cBar.high < iZone.Lower() + // + ; + if (isValid) + { + // + Add( + iZone, + conditions.supplyZones // + ); + } + } + + // + hasSupplyZones = conditions.HasSupplyZones(); + result = hasSupplyZones; + if (!result) + { + return result; + } + } + + // + // Demand ... + bool hasDemandZones = conditions.HasDemandZones(); + if (!hasDemandZones) + { + // + int count = state.CountDemandZones(); + for (int i = count - 1; i >= 0; i--) + { + // + XCDemandZone *iZone = state.demandZones[i]; + + // + bool isValid = + // + ask > iZone.Upper() && + bid > iZone.Upper() && + cBar.low > iZone.Upper() + // + ; + if (isValid) + { + // + Add( + iZone, + conditions.demandZones // + ); + } + } + + // + hasDemandZones = conditions.HasDemandZones(); + result = hasDemandZones; + if (!result) + { + return result; + } + } + + // + // Waits For Price to Go Inside a Zone ... + ENUM_X_DIRECTION activeZoneDir = X_DIRECTION_NONE; + bool hasActiveZone = conditions.HasActiveZone(activeZoneDir); + if (!hasActiveZone) + { + // + // Looking Up For Active Zone ... + + // + // Supply ... + if (hasSupplyZones) + { + // + int count = conditions.CountSupplyZones(); + for (int i = count - 1; i >= 0; i--) + { + // + XCSupplyZone *iZone = conditions.supplyZones[i]; + + // + bool isValid = + // + ask <= iZone.Upper() && + bid <= iZone.Upper() && + ask >= iZone.Lower() && + bid >= iZone.Lower() && + cBar.high <= iZone.Upper() && + cBar.low >= iZone.Lower() + // + ; + if (isValid) + { + // + conditions.activeSupplyZone = iZone; + break; + } + } + } + + // + hasActiveZone = conditions.HasActiveZone(activeZoneDir); + if (!hasActiveZone) + { + // + // Demand ... + if (hasDemandZones) + { + // + int count = conditions.CountDemandZones(); + for (int i = count - 1; i >= 0; i--) + { + // + XCDemandZone *iZone = conditions.demandZones[i]; + + // + bool isValid = + // + ask <= iZone.Upper() && + bid <= iZone.Upper() && + ask >= iZone.Lower() && + bid >= iZone.Lower() && + cBar.high <= iZone.Upper() && + cBar.low >= iZone.Lower() + // + ; + if (isValid) + { + // + conditions.activeDemandZone = iZone; + break; + } + } + } + } + + // + hasActiveZone = conditions.HasActiveZone(activeZoneDir); + result = hasActiveZone; + if (!result) + { + return result; + } + + // + conditions.activeZoneFoundedAt = cTime; + } + + // + // Now we Have to Calculate Active Zones Ticks ... + + // + // Select Active Zone ... + XCBarZone *activeZone = NULL; + result = conditions.GetActiveZone(activeZone); + if (!result) + { + return result; + } + + // + // Extract Active Zone Start Bar ... + XOHCL fromBar; + datetime fromTime = activeZone.BarTime(); + result = triggerCycleHelper.GetBar( + fromBar, + fromTime // + ); + if (!result) + { + return result; + } + + // + bool hasTicksZone = conditions.HasTicksZone(); + if (!hasTicksZone) + { + // + // Istantiate Ticks Zone ... + conditions.ticksZone = new XCTicksZone(); + conditions.ticksZone.Levels(40); + } + + // + // Update Ticks Zone ... + result = conditions.ticksZone.Init( + fromBar, + cBar // + ); + if (!result) + { + return result; + } + + // + // Regenrate Conditions ... + hasTicksZone = conditions.HasTicksZone(); + result = hasTicksZone; + if (!result) + { + return result; + } + + // + // Make Sure we Have a Direction for Setup ... + isBullish = IsBullish(activeZoneDir); + isBearish = IsBearish(activeZoneDir); + result = isBullish || + isBearish; + if (!result) + { + return result; + } + + // + // Check New Peaks or Vales Happens inside Zero Tick or Volume Percent Zone and + // also Active Zone ... + double peak = triggerConditions.x121Conditions.peaksBuffer[1]; + double vale = triggerConditions.x121Conditions.valesBuffer[1]; + bool isNewPeakOverLast = triggerConditions.x121Conditions.isNewPeakOverLast; + bool isNewValeUnderLast = triggerConditions.x121Conditions.isNewValeUnderLast; + + // + bool isPeakInsideActiveZone = + // + peak <= activeZone.Upper() && + peak >= activeZone.Lower() + // + ; + bool isValeInsideActiveZone = + // + vale <= activeZone.Upper() && + vale >= activeZone.Lower() + // + ; + + // + bool isPeakInsideZeroZone = false; + bool isValeInsideZeroZone = false; + int tzCount = conditions.ticksZone.Count(); + if (IsValidSize(tzCount)) + { + // + for (int i = 0; i < tzCount; i++) + { + // + XCTickZone *iTZ = conditions.ticksZone.GetZone(i); + + // + if (isBearish && + !isPeakInsideZeroZone) + { + // + isPeakInsideZeroZone = + // + peak <= iTZ.high && + peak >= iTZ.low && + (iTZ.percent == 0 || + iTZ.volumePercent == 0) + // + ; + } + + // + if (isBullish && + !isValeInsideZeroZone) + { + // + isValeInsideZeroZone = + // + vale <= iTZ.high && + vale >= iTZ.low && + (iTZ.percent == 0 || + iTZ.volumePercent == 0) + // + ; + } + + // + if (isPeakInsideZeroZone || + isValeInsideZeroZone) + { + break; + } + } + } + + // + isBullish = + // + isBullish && + isNewValeUnderLast && + isValeInsideZeroZone && + isValeInsideActiveZone + // + ; + + // + isBearish = + // + isBearish && + isNewPeakOverLast && + isPeakInsideZeroZone && + isPeakInsideActiveZone + // + ; + + // + result = isBullish || + isBearish; + if (!result) + { + // + // Clean Conditions for Regenerate ... + int activeZoneAge = (int)(cTime - conditions.activeZoneFoundedAt) / PeriodSeconds(conditions.period); + if (activeZoneAge >= 200) + { + conditions.Clean(); + } + + // + return result; + } + + // + conditions.setupTime = cTime; + conditions.dir = + isBullish + ? X_DIRECTION_BULLISH + : X_DIRECTION_BEARISH; + + // + return result; +} + +// +// Detect Trigger Conditions ... +bool DetectX121SMCXPVSUPDEMSiganlTrigger( + // + X121SMCStrategyXPVSUPDEMSignalConditions &conditions, + // + string _symbol, + ENUM_TIMEFRAMES _period, + // + XC121SMCCycleHelper *triggerCycleHelper, + XC121SMCCycleHelper *decisionCycleHelper, + XC121SMCCycleHelper *analyseCycleHelper, + XC121SMCCycleHelper *verificationCycleHelper, + XC121SMCCycleHelper *consolidationCycleHelper, + XC121SMCCycleHelper *visionCycleHelper, + // + int maxAllowedSetupAge = 60 // + // +) +{ + // + bool result = false; + + // + result = conditions.IsSetuped(); + if (!result) + { + return result; + } + + // + datetime setupTime = conditions.setupTime; + ENUM_X_DIRECTION setupDir = conditions.dir; + + // + 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; + + // + XOHCL zBar; + result = zBar.Init( + symbol, + period, + zIndex // + ); + if (!result) + { + return result; + } + + // + XOHCL cBar; + result = cBar.Init( + symbol, + period, + cIndex // + ); + if (!result) + { + return result; + } + + // + double ask = GetAsk(symbol); + double bid = GetBid(symbol); + datetime cTime = TimeCurrent(); + + // + double ll = cBar.FindLowest(9, MODE_LOW); + double hh = cBar.FindHighest(9, MODE_HIGH); + + // + int zoneValidationDivider = 10; + int validPivotRepetition = triggerCycleHelper.mX121Helper + .GetDonChainLength(); + + // + double selectedSL = 0; + + // + // Cycles Conditions ... + + // + // Trigger ... + ENUM_XPOI_EVENTS triggerPoiEvents[]; + ENUM_X_CYCLE_EVENTS triggerCycleEvents[]; + X121SMCCycleConditions triggerConditions; + result = triggerCycleHelper.GetConditions( + triggerCycleEvents, + triggerPoiEvents, + triggerConditions, + zIndex, + loopback // + ); + if (!result) + { + return result; + } + + // + // 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; + } + + // + // Verification ... + ENUM_XPOI_EVENTS verificationPoiEvents[]; + ENUM_X_CYCLE_EVENTS verificationCycleEvents[]; + X121SMCCycleConditions verificationConditions; + result = verificationCycleHelper.GetConditions( + verificationCycleEvents, + verificationPoiEvents, + verificationConditions, + 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 triggerState = triggerConditions.state; + XPOIState decisionState = decisionConditions.state; + XPOIState analyseState = analyseConditions.state; + XPOIState verificationState = verificationConditions.state; + XPOIState consolidationState = consolidationConditions.state; + XPOIState visionState = visionConditions.state; + + // + // Trigger Conditions ... + + // + // Select Active Zone Class ... + XCBarZone *activeZone = NULL; + result = conditions.GetActiveZone(activeZone); + if (!result) + { + return result; + } + + // + // Check Last Valid Peak or Last Valid Vales Breaks ... + // Beak Of Structure ... + + // + // Peak ... + double peak = triggerConditions.x121Conditions.peaksBuffer[1]; + XPVPivotPoint lastPeakPivot; + bool hasLastPeakPivot = triggerCycleHelper + .GetLastPeakPivotPoint(lastPeakPivot); + bool isLastPeakPivotBreaked = + // + lastPeakPivot.IsPeak() && + lastPeakPivot.IsValid() && + peak > lastPeakPivot.value + // + ; + + // + // Vale ... + double vale = triggerConditions.x121Conditions.valesBuffer[1]; + XPVPivotPoint lastValePivot; + bool hasLastValePivot = triggerCycleHelper + .GetLastValePivotPoint(lastValePivot); + bool isLastValePivotBreaked = + // + lastValePivot.IsVale() && + lastValePivot.IsValid() && + vale < lastValePivot.value + // + ; + + // + isBullish = + // + IsBullish(setupDir) && + isLastValePivotBreaked + // + ; + + // + isBearish = + // + IsBearish(setupDir) && + isLastPeakPivotBreaked + // + ; + + // + result = isBullish || + isBearish; + if (!result) + { + // + // Cleanup Setup Conditions ... + int setupAge = conditions.GetSetupAge(); + if (IsValidSize(setupAge) && + IsValidSize(maxAllowedSetupAge) && + setupAge >= maxAllowedSetupAge) + { + conditions.Clean(); + } + + // + return result; + } + + // + conditions.triggerTime = cTime; + conditions.sl = isBullish + ? activeZone.Lower() + : activeZone.Upper(); + conditions.type = isBullish + ? X_POSITION_TYPE_LONG + : X_POSITION_TYPE_SHORT; + + // + return result; +} + +// \ No newline at end of file diff --git a/X121SMCEA/Strategy/x-121.smc.strategy.class.mq5 b/X121SMCEA/Strategy/x-121.smc.strategy.class.mq5 index 9e0809d6..4b6bf969 100644 --- a/X121SMCEA/Strategy/x-121.smc.strategy.class.mq5 +++ b/X121SMCEA/Strategy/x-121.smc.strategy.class.mq5 @@ -29,6 +29,7 @@ // #include "../Signals/x-121.smc.test.signal.class.mq5" #include "../Signals/x-121.smc.xpvob.signal.class.mq5" +#include "../Signals/x-121.smc.xpvsupdem.signal.class.mq5" // // Definitions ... @@ -157,6 +158,7 @@ class XCX121SMCStrategy : public XCX121SMCBaseStrategy // bool hasTestSignal = false; bool hasXPVOBSignal = false; + bool hasXPVSUPDEMSignal = false; // // Test Signal ... @@ -176,6 +178,15 @@ class XCX121SMCStrategy : public XCX121SMCBaseStrategy // hasSignal = hasXPVOBSignal; } + // + // XPVSUPDEM Signal ... + if (!hasSignal) + { + // + hasXPVSUPDEMSignal = DetectXPVSUPDEMSignal(conditions); + hasSignal = hasXPVSUPDEMSignal; + } + // result = hasSignal; if (!result) @@ -262,12 +273,10 @@ class XCX121SMCStrategy : public XCX121SMCBaseStrategy signal.time = TimeCurrent(); // - // XPVOB Signal ... - if (hasXPVOBSignal) + // Configure Signal Protecting ... + if (hasXPVOBSignal || + hasXPVSUPDEMSignal) { - // - // Add Aditionsal Info ... - // signal.fullTPLevel = r2r; signal.partialCloseOnTPLevel = 2; @@ -545,23 +554,66 @@ class XCX121SMCStrategy : public XCX121SMCBaseStrategy mVisionCycleHelper // ); - // - result = isSetuped; - if (!result) - { - return result; - } - // setupDir = mTestConditions.dir; setupTime = mTestConditions.setupTime; } + // ClearDraws(); + // ENUM_X_DIRECTION activeZoneDir; + // bool hasTicksZone = mTestConditions.HasTicksZone(); + // bool hasActiveZone = mTestConditions.HasActiveZone(activeZoneDir); + // if (hasActiveZone) + // { + // // + // if (IsBullish(activeZoneDir)) + // { + // // + // mTestConditions.activeDemandZone.To(cTime); + // XCDemandZoneObject *iObj; + // bool isCreated = mPOIDrawer.CreateDemandZone( + // mTestConditions.activeDemandZone, + // iObj // + // ); + // if (isCreated) + // { + // AddObjectIfNotExists(iObj); + // } + // } + // else + // { + // // + // mTestConditions.activeSupplyZone.To(cTime); + // XCSupplyZoneObject *iObj; + // bool isCreated = mPOIDrawer.CreateSupplyZone( + // mTestConditions.activeSupplyZone, + // iObj // + // ); + // if (isCreated) + // { + // AddObjectIfNotExists(iObj); + // } + // } + // } + // if (hasTicksZone) + // { + // // + // XCTicksZoneObject *iObj; + // bool isCreated = mPOIDrawer.CreateTicksZone( + // mTestConditions.ticksZone, + // iObj // + // ); + // if (isCreated) + // { + // AddObjectIfNotExists(iObj); + // } + // } + // - // Draw Conditions Active FVG ... - if (isSetuped) + result = isSetuped; + if (!result) { - // + return result; } // @@ -681,43 +733,43 @@ class XCX121SMCStrategy : public XCX121SMCBaseStrategy // // Draw Conditions Active FVG ... - if (isSetuped) - { - // - XCFVG *iFVG = mXPVOBConditions.activeFVG; - if (iFVG != NULL && iFVG.IsValid()) - { - // - ClearDraws(); - iFVG.To(cTime); - if (IsBullish(setupDir) && iFVG.IsBullish()) - { - // - XCBullishFairValueGapObject *iObj; - bool isCreated = mPOIDrawer.CreateBullishFairValueGap( - iFVG, - iObj // - ); - if (isCreated) - { - AddObjectIfNotExists(iObj); - } - } - else if (IsBearish(setupDir) && iFVG.IsBearish()) - { - // - XCBearishFairValueGapObject *iObj; - bool isCreated = mPOIDrawer.CreateBearishFairValueGap( - iFVG, - iObj // - ); - if (isCreated) - { - AddObjectIfNotExists(iObj); - } - } - } - } + // if (isSetuped) + // { + // // + // XCFVG *iFVG = mXPVOBConditions.activeFVG; + // if (iFVG != NULL && iFVG.IsValid()) + // { + // // + // ClearDraws(); + // iFVG.To(cTime); + // if (IsBullish(setupDir) && iFVG.IsBullish()) + // { + // // + // XCBullishFairValueGapObject *iObj; + // bool isCreated = mPOIDrawer.CreateBullishFairValueGap( + // iFVG, + // iObj // + // ); + // if (isCreated) + // { + // AddObjectIfNotExists(iObj); + // } + // } + // else if (IsBearish(setupDir) && iFVG.IsBearish()) + // { + // // + // XCBearishFairValueGapObject *iObj; + // bool isCreated = mPOIDrawer.CreateBearishFairValueGap( + // iFVG, + // iObj // + // ); + // if (isCreated) + // { + // AddObjectIfNotExists(iObj); + // } + // } + // } + // } // // Detect Trigger Conditions ... @@ -776,6 +828,171 @@ class XCX121SMCStrategy : public XCX121SMCBaseStrategy return result; } + // + // XPVSUPDEM Signal ... + X121SMCStrategyXPVSUPDEMSignalConditions mXPVSUPDEMConditions; + bool DetectXPVSUPDEMSignal( + X121SMCStrategyConditions &conditions // + ) + { + // + bool result = false; + + // + bool isBullish = false; + bool isBearish = false; + + // + string symbol = GetSymbol(); + ENUM_TIMEFRAMES period = GetPeriod(); + + // + datetime cTime = TimeCurrent(); + + // + ENUM_X_121_SMC_PROVIDERS provider = X_121_SMC_PROVIDER_XPVSUPDEM; + string providerStr = ToString(provider); + + // + // Detect Setup Conditions ... + datetime setupTime = mXPVSUPDEMConditions.setupTime; + bool isSetuped = mXPVSUPDEMConditions.IsSetuped(); + ENUM_X_DIRECTION setupDir = mXPVSUPDEMConditions.dir; + if (!isSetuped) + { + // + // Detect Signal Setup ... + isSetuped = DetectX121SMCXPVSUPDEMSiganlSetup( + symbol, + period, + mXPVSUPDEMConditions, + mTriggerCycleHelper, + mDecisionCycleHelper, + mAnalyseCycleHelper, + mVerificationCycleHelper, + mConsolidationCycleHelper, + mVisionCycleHelper // + ); + + // + setupDir = mXPVSUPDEMConditions.dir; + setupTime = mXPVSUPDEMConditions.setupTime; + } + + // ClearDraws(); + // ENUM_X_DIRECTION activeZoneDir; + // bool hasTicksZone = mXPVSUPDEMConditions.HasTicksZone(); + // bool hasActiveZone = mXPVSUPDEMConditions.HasActiveZone(activeZoneDir); + // if (hasActiveZone) + // { + // // + // if (IsBullish(activeZoneDir)) + // { + // // + // mXPVSUPDEMConditions.activeDemandZone.To(cTime); + // XCDemandZoneObject *iObj; + // bool isCreated = mPOIDrawer.CreateDemandZone( + // mXPVSUPDEMConditions.activeDemandZone, + // iObj // + // ); + // if (isCreated) + // { + // AddObjectIfNotExists(iObj); + // } + // } + // else + // { + // // + // mXPVSUPDEMConditions.activeSupplyZone.To(cTime); + // XCSupplyZoneObject *iObj; + // bool isCreated = mPOIDrawer.CreateSupplyZone( + // mXPVSUPDEMConditions.activeSupplyZone, + // iObj // + // ); + // if (isCreated) + // { + // AddObjectIfNotExists(iObj); + // } + // } + // } + // if (hasTicksZone) + // { + // // + // XCTicksZoneObject *iObj; + // bool isCreated = mPOIDrawer.CreateTicksZone( + // mXPVSUPDEMConditions.ticksZone, + // iObj // + // ); + // if (isCreated) + // { + // AddObjectIfNotExists(iObj); + // } + // } + + // + result = isSetuped; + if (!result) + { + return result; + } + + // + // Detect Trigger Conditions ... + bool canTrigger = mXPVSUPDEMConditions.CanTrigger(); + datetime triggerTime = mXPVSUPDEMConditions.triggerTime; + if (!canTrigger) + { + // + // Detect Signal Trigger ... + canTrigger = DetectX121SMCXPVSUPDEMSiganlTrigger( + mXPVSUPDEMConditions, + symbol, + period, + mTriggerCycleHelper, + mDecisionCycleHelper, + mAnalyseCycleHelper, + mVerificationCycleHelper, + mConsolidationCycleHelper, + mVisionCycleHelper // + ); + + // + result = canTrigger; + if (!result) + { + return result; + } + + // + triggerTime = mXPVSUPDEMConditions.triggerTime; + } + + // + // Check Signal Direction ... + + // + isBullish = IsBullish(setupDir); + isBearish = IsBearish(setupDir); + result = isBullish || + isBearish; + if (!result) + { + return result; + } + + // + // Issues Signal on Conditions ... + conditions.signalDir = setupDir; + conditions.provider = providerStr; + conditions.sl = mXPVSUPDEMConditions.sl; + + // + mXPVSUPDEMConditions.Clean(); + + // + return result; + } + // // Private ... private: