From 9158a6cc6d620fa38008dd08f2af7d1e1f94ed41 Mon Sep 17 00:00:00 2001 From: Hadi Khazaee Asl Date: Wed, 8 Jan 2025 17:32:36 +0330 Subject: [PATCH] last ... --- Classes/x-saherelm.x-poi.drawer.class.mq5 | 151 +-- .../1/x-121.smc.xtwpv.old.4.signal.lib.mq5 | 1083 +++++++++++++++++ Libraries/x-saherelm.x-poi.lib.mq5 | 136 ++- X121SMCEA/Experts/x-121.smc.expert.class.mq5 | 20 +- .../Signals/x-121.smc.xtwpv.signal.lib.mq5 | 264 ++-- .../Strategy/x-121.smc.strategy.class.mq5 | 203 +-- 6 files changed, 1535 insertions(+), 322 deletions(-) create mode 100644 Documents/BKP/1/x-121.smc.xtwpv.old.4.signal.lib.mq5 diff --git a/Classes/x-saherelm.x-poi.drawer.class.mq5 b/Classes/x-saherelm.x-poi.drawer.class.mq5 index b3b47860..3aeeb722 100644 --- a/Classes/x-saherelm.x-poi.drawer.class.mq5 +++ b/Classes/x-saherelm.x-poi.drawer.class.mq5 @@ -4479,7 +4479,7 @@ class XCPOIDrawer : public XCBase * @return ( int ) */ int DrawFVGOrderBlock( - XFVGOrderBlock &models[], + XFVGOrderBlock &model, XCBaseObject *&drawnObjects[] // ) { @@ -4490,115 +4490,88 @@ class XCPOIDrawer : public XCBase Clean(drawnObjects); // - int count = ArraySize(models); - if (!IsValidSize(count)) + if (!model.IsValid()) { return result; } // - for (int i = 0; i < count; i++) + ENUM_X_DIRECTION iDir; + result = model.GetDirection(iDir); + if (!result) + { + return result; + } + + // + bool isBullish = IsBullish(iDir); + if (isBullish) { // - XFVGOrderBlock iModel = models[i]; - - // - ENUM_X_DIRECTION iDir; - bool hasDirection = iModel.GetDirection(iDir); - if (!hasDirection) + // Order Block ... + XCBullishOrderBlockObject *iOBObj; + bool isCreated = CreateBullishOrderBlock( + model.orderBlock, + iOBObj // + ); + if (isCreated) { - continue; + // + Add( + (XCBaseObject *)iOBObj, + drawnObjects // + ); } // - bool isBullish = IsBullish(iDir); - - // - if (isBullish) + // FVG ... + XCBullishFairValueGapObject *iFVGObj; + isCreated = CreateBullishFairValueGap( + model.fairValueGap, + iFVGObj // + ); + if (isCreated) { // - // Order Block ... - XCBullishOrderBlockObject *iOBObj; - bool isCreated = CreateBullishOrderBlock( - iModel.orderBlock, - iOBObj // + Add( + (XCBaseObject *)iOBObj, + drawnObjects // ); - if (isCreated) - { - // - Add( - (XCBaseObject *)iOBObj, - drawnObjects // - ); - } - - // - // FVG ... - XCBullishFairValueGapObject *iFVGObj; - isCreated = CreateBullishFairValueGap( - iModel.fairValueGap, - iFVGObj // - ); - if (isCreated) - { - // - Add( - (XCBaseObject *)iOBObj, - drawnObjects // - ); - } } - else + } + else + { + // + // Order Block ... + XCBearishOrderBlockObject *iOBObj; + bool isCreated = CreateBearishOrderBlock( + model.orderBlock, + iOBObj // + ); + if (isCreated) { // - // Order Block ... - XCBearishOrderBlockObject *iOBObj; - bool isCreated = CreateBearishOrderBlock( - iModel.orderBlock, - iOBObj // + Add( + (XCBaseObject *)iOBObj, + drawnObjects // ); - if (isCreated) - { - // - Add( - (XCBaseObject *)iOBObj, - drawnObjects // - ); - } - - // - // FVG ... - XCBearishFairValueGapObject *iFVGObj; - isCreated = CreateBearishFairValueGap( - iModel.fairValueGap, - iFVGObj // - ); - if (isCreated) - { - // - Add( - (XCBaseObject *)iFVGObj, - drawnObjects // - ); - } } // - // Price Zone ... - // XCBaseObject *stateZoneObjects[]; - // int stateZoneObjectsCount = DrawStateZones( - // iModel.stateZones, - // stateZoneObjects // - // ); - // if (IsValidSize(stateZoneObjectsCount)) - // { - // // - // Copy( - // stateZoneObjects, - // drawnObjects, - // false // Force Clean ... - // ); - // } + // FVG ... + XCBearishFairValueGapObject *iFVGObj; + isCreated = CreateBearishFairValueGap( + model.fairValueGap, + iFVGObj // + ); + if (isCreated) + { + // + Add( + (XCBaseObject *)iFVGObj, + drawnObjects // + ); + } } // diff --git a/Documents/BKP/1/x-121.smc.xtwpv.old.4.signal.lib.mq5 b/Documents/BKP/1/x-121.smc.xtwpv.old.4.signal.lib.mq5 new file mode 100644 index 00000000..66a317c2 --- /dev/null +++ b/Documents/BKP/1/x-121.smc.xtwpv.old.4.signal.lib.mq5 @@ -0,0 +1,1083 @@ +/////////////////////////////////////////////////////// +// +// 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 X121SMCStrategyXTWPVSignalConditions +{ + // + // Props ... + + // + string symbol; + ENUM_TIMEFRAMES period; + + // + double sl; + double target; + ENUM_X_DIRECTION dir; + ENUM_X_POSITION_TYPES type; + + // + // Setup Props ... + + // + datetime setupTime; + datetime triggerTime; + + // + XFVGOrderBlock bullishOrderBlocks[]; + XFVGOrderBlock bearishOrderBlocks[]; + + // + // Constructor ... + X121SMCStrategyXTWPVSignalConditions() + { + 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(); + } + + /** + * 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() + { + // + Clean(bullishOrderBlocks); + Clean(bearishOrderBlocks); + } + + /** + * Update Order Blocks Date ... + */ + void UpdateOrderBlocks() + { + // + int count = 0; + datetime cTime = TimeCurrent(); + + // + count = ArraySize(bullishOrderBlocks); + if (IsValidSize(count)) + { + // + for (int i = 0; i < count; i++) + { + // + bullishOrderBlocks[i].orderBlock.To(cTime); + bullishOrderBlocks[i].fairValueGap.To(cTime); + } + } + + // + count = ArraySize(bearishOrderBlocks); + if (IsValidSize(count)) + { + // + for (int i = 0; i < count; i++) + { + // + bearishOrderBlocks[i].orderBlock.To(cTime); + bearishOrderBlocks[i].fairValueGap.To(cTime); + } + } + } + + // +}; + +// +// Extension Functions ... + +// +// Detect Setup Conditions ... +bool DetectX121SMCXTWPVSiganlSetup( + string _symbol, + ENUM_TIMEFRAMES _period, + // + X121SMCStrategyXTWPVSignalConditions &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; + } + + // + XOHCL pBar; + result = pBar.Init( + symbol, + period, + 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 ... + + // + // 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 ... + + // + ENUM_X_DIRECTION forDir; + XFVGOrderBlock bullishOrderBlocks[]; + XFVGOrderBlock bearishOrderBlocks[]; + bool isTested = TestPOIState( + forDir, + bullishOrderBlocks, + bearishOrderBlocks, + consolidationState, + analyseState, + decisionState // + ); + + // + isBullish = + isTested && + IsBullish(forDir); + // + isBearish = + isTested && + IsBearish(forDir); + + // + result = isBullish || + isBearish; + if (!result) + { + return result; + } + + // + conditions.dir = forDir; + Copy( + bullishOrderBlocks, + conditions.bullishOrderBlocks // + ); + Copy( + bearishOrderBlocks, + conditions.bearishOrderBlocks // + ); + + // + conditions.setupTime = cTime; + conditions.dir = + isBullish + ? X_DIRECTION_BULLISH + : X_DIRECTION_BEARISH; + + // + return result; +} + +// +// Detect Trigger Conditions ... +bool DetectX121SMCXTWPVSiganlTrigger( + // + X121SMCStrategyXTWPVSignalConditions &conditions, + // + string _symbol, + ENUM_TIMEFRAMES _period, + // + XC121SMCCycleHelper *triggerCycleHelper, + XC121SMCCycleHelper *decisionCycleHelper, + XC121SMCCycleHelper *analyseCycleHelper, + XC121SMCCycleHelper *verificationCycleHelper, + XC121SMCCycleHelper *consolidationCycleHelper, + XC121SMCCycleHelper *visionCycleHelper, + // + int maxAllowedSetupAge = 576 // + // +) +{ + // + bool result = false; + + // + 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 = zBar.Init( + symbol, + period, + zIndex // + ); + if (!result) + { + return result; + } + + // + XOHCL cBar; + result = cBar.Init( + symbol, + period, + cIndex // + ); + if (!result) + { + return result; + } + + // + XOHCL pBar; + result = pBar.Init( + symbol, + period, + pIndex // + ); + if (!result) + { + return result; + } + + // + double 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 ... + + // + // 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 ... + + // + double decisionPeak = decisionConditions.x121Conditions.peaksBuffer[1]; + double isNewDecisionPeak = decisionConditions.x121Conditions.isNewPeak; + + // + double decisionVale = decisionConditions.x121Conditions.valesBuffer[1]; + double isNewDecisionVale = decisionConditions.x121Conditions.isNewVale; + + // + // Waits For Price to Go Inside FVG ... + XFVGOrderBlock fvgOrderBlock; + bool isPriceInsideOB = false; + bool isPriceInsideFVG = false; + if (isBullish) + { + // + int count = ArraySize(conditions.bullishOrderBlocks); + for (int i = 0; i < count; i++) + { + // + XFVGOrderBlock iModel = conditions.bullishOrderBlocks[i]; + + // + isPriceInsideOB = IsPriceInsideZone( + cBar, + iModel.orderBlock // + ); + + // + isPriceInsideFVG = IsPriceInsideZone( + cBar, + iModel.fairValueGap // + ); + + // + if (isPriceInsideOB && + isPriceInsideFVG) + { + // + fvgOrderBlock = iModel; + break; + } + + // + isPriceInsideOB = false; + isPriceInsideFVG = false; + } + } + else + { + // + int count = ArraySize(conditions.bearishOrderBlocks); + for (int i = 0; i < count; i++) + { + // + XFVGOrderBlock iModel = conditions.bearishOrderBlocks[i]; + + // + isPriceInsideOB = IsPriceInsideZone( + cBar, + iModel.orderBlock // + ); + + // + isPriceInsideFVG = IsPriceInsideZone( + cBar, + iModel.fairValueGap // + ); + + // + if (isPriceInsideOB && + isPriceInsideFVG) + { + // + fvgOrderBlock = iModel; + break; + } + + // + isPriceInsideOB = false; + isPriceInsideFVG = false; + } + } + + // + result = isPriceInsideOB && + isPriceInsideFVG && + fvgOrderBlock.IsValid(); + if (!result) + { + return result; + } + + // + double fvgOBUpper = 0; + double fvgOBLower = 0; + bool hasBoundary = fvgOrderBlock.GetBoundary( + fvgOBUpper, + fvgOBLower // + ); + result = hasBoundary; + if (!result) + { + return result; + } + + // + // Detect Bullish Conditions ... + isBullish = + isBullish && + cBar.IsBullish() && + isNewDecisionVale; + + // + // Detect Bearish Conditions ... + isBearish = + isBearish && + cBar.IsBearish() && + isNewDecisionPeak; + + // + result = isBullish || + isBearish; + if (!result) + { + // + // Cleanup Setup Conditions ... + + // + return result; + } + + // + // Detect Nearest Pivot Point ... + + // + // Detect Target ... + double target = CalculateTarget( + cBar, + analyseState, + setupDir // + ); + if (target == 0) + { + // + target = CalculateTarget( + cBar, + verificationState, + setupDir // + ); + } + + // + double oppositTarget = CalculateTarget( + cBar, + analyseState, + Opposit(setupDir) // + ); + + // + double entry = GetEntry( + conditions.symbol, + setupDir // + ); + + // + // Filling SL Candidates ... + + // + double sls[]; + + // + double atr = triggerConditions.x121Conditions.atrBuffer[1]; + double peak = triggerConditions.x121Conditions.peaksBuffer[1]; + double vale = triggerConditions.x121Conditions.valesBuffer[1]; + + // + if (fvgOrderBlock.IsValid()) + { + // + Add( + fvgOBUpper, + sls // + ); + + // + Add( + fvgOBLower, + sls // + ); + } + + // + if (isBullish) + { + // + double lowerVale = triggerCycleHelper.mX121Helper.xpvHelper.GetLowerVale(vale); + if (lowerVale > 0) + { + // + Add( + lowerVale, + sls // + ); + } + + // + Add( + vale, + sls // + ); + } + else if (isBearish) + { + // + double higherPeak = triggerCycleHelper.mX121Helper.xpvHelper.GetHigherPeak(peak); + if (higherPeak > 0) + { + // + Add( + higherPeak, + sls // + ); + } + + // + Add( + peak, + sls // + ); + } + + // + double slsMin = GetMin(sls); + double slsMax = GetMax(sls); + + // + double sl = isBullish + ? slsMin - atr + : slsMax + atr; + double risk = MathAbs(entry - sl); + double targetDelta = 2 * (risk / 3); + if (target == 0) + { + // + int minTargetPint = 50; + double minTargetPointValue = minTargetPint * points; + if (targetDelta < minTargetPointValue) + { + targetDelta = minTargetPointValue; + } + + // + // Force Target On Half Risk ... + target = + isBullish + ? entry + targetDelta + : entry - targetDelta; + + // + target = 0; + + // + } + + // + // Ignore Target ... + target = 0; + + // + // Filling Conditions Props ... + conditions.sl = sl; + conditions.target = target; + conditions.triggerTime = cTime; + conditions.type = isBullish + ? X_POSITION_TYPE_LONG + : X_POSITION_TYPE_SHORT; + + // + return result; +} + +// +int AddX121SMCXTWPVConditionsIfNotExists( + X121SMCStrategyXTWPVSignalConditions &item, + X121SMCStrategyXTWPVSignalConditions &items[] // +) +{ + // + int result = 0; + + // + bool isSetuped = IsValid(item.setupTime) && + HasDirection(item.dir); + if (!isSetuped) + { + return result; + } + + // + int count = ArraySize(items); + bool canAdd = !IsValidSize(count); + if (!canAdd) + { + // + // Prese Item Data ... + bool isBullish = IsBullish(item.dir); + + // + for (int i = 0; i < count; i++) { + // + X121SMCStrategyXTWPVSignalConditions iItem = items[i]; + + // + if (iItem.dir != item.dir) { + continue; + } + + // + bool isIBullish = IsBullish(iItem); + if (isIBullish) { + // + int iCount = ArraySize(iItem.bullishOrderBlocks); + for (int j = 0; j < iCount; j++) { + // + XFVGOrderBlock jFO = iItem.bullishOrderBlocks[j]; + + } + } else { + + } + } + } + + // + if (canAdd) + { + // + AddRef( + item, + items // + ); + + // + // Remove Olds ... + } + + // + result = ArraySize(items); + + // + return result; +} + +// +// Draw Signal ... +int DrawX121SMCXTWPVSiganl( + X121SMCStrategyXTWPVSignalConditions &conditions, + XCBaseObject *&drawnObjects[], + XCPOIDrawer *drawer // +) +{ + // + int result = 0; + + // + Clean(drawnObjects); + + // + if (drawer == NULL) + { + return result; + } + + // + bool isSetuped = conditions.IsSetuped(); + if (!isSetuped) + { + return result; + } + + // + bool isBullish = IsBullish(conditions.dir); + + // + result = ArraySize(drawnObjects); + + // + return result; +} + +// diff --git a/Libraries/x-saherelm.x-poi.lib.mq5 b/Libraries/x-saherelm.x-poi.lib.mq5 index c40cf0ad..857331d6 100644 --- a/Libraries/x-saherelm.x-poi.lib.mq5 +++ b/Libraries/x-saherelm.x-poi.lib.mq5 @@ -6425,6 +6425,110 @@ struct XFVGOrderBlock // return result; } + + /** + * Retrieve Boundary of Zone ... + * + * @param upper: Upper Boundary ...ّ + * @param lower: Lower Bondary ... + * @return ( bool ) + */ + bool GetBoundary( + double &upper, + double &lower // + ) + { + // + bool result = false; + + // + upper = 0; + lower = 0; + + // + result = IsValid(); + if (!result) + { + return result; + } + + // + upper = orderBlock.Upper(); + upper = MathMax(upper, fairValueGap.Upper()); + + // + lower = orderBlock.Lower(); + lower = MathMax(lower, fairValueGap.Lower()); + + // + result = lower > 0 && + upper > 0 && + upper > lower; + + // + return result; + } + + /** + * Check Model is same as another Istance ... + * + * @param value: XFVGOrderBlock instance Reference ... + * + * @return ( bool ) + */ + bool IsSameAs(XFVGOrderBlock &value) + { + // + bool result = false; + + // + result = + IsValid() && + value.IsValid(); + if (!result) + { + return result; + } + + // + ENUM_X_DIRECTION dir; + result = GetDirection(dir); + if (!result) + { + return result; + } + + // + ENUM_X_DIRECTION valueDir; + result = value.GetDirection(valueDir); + if (!result) + { + return result; + } + + // + result = + // + dir = valueDir + // + && + // + orderBlock.From() == value.orderBlock.From() && + orderBlock.Upper() == value.orderBlock.Upper() && + orderBlock.Lower() == value.orderBlock.Lower() + // + && + // + fairValueGap.From() == value.fairValueGap.From() && + fairValueGap.Upper() == value.fairValueGap.Upper() && + fairValueGap.Lower() == value.fairValueGap.Lower() + // + ; + + // + return result; + } + // }; // @@ -8819,7 +8923,7 @@ bool CalculateStateZones( } } } - + // result = zones.IsValid(); @@ -9055,15 +9159,9 @@ bool IsPriceAboveZone( return result; } - // - double ask = GetAsk(bar.symbol); - double bid = GetBid(bar.symbol); - // result = // - ask > zone.Upper() && - bid > zone.Upper() && bar.low > zone.Upper() // ; @@ -9131,16 +9229,10 @@ bool IsPriceBelowZone( return result; } - // - double ask = GetAsk(bar.symbol); - double bid = GetBid(bar.symbol); - // result = // - ask < zone.Lower() && - bid < zone.Lower() && - bar.low < zone.Lower() + bar.high < zone.Lower() // ; @@ -9207,21 +9299,13 @@ bool IsPriceInsideZone( return result; } - // - double ask = GetAsk(bar.symbol); - double bid = GetBid(bar.symbol); - // result = // - ask <= zone.Upper() && - bid <= zone.Upper() && bar.low <= zone.Upper() // && // - ask >= zone.Lower() && - bid >= zone.Lower() && bar.low >= zone.Lower() // ; @@ -9249,21 +9333,13 @@ bool IsPriceInsideZone( return result; } - // - double ask = GetAsk(bar.symbol); - double bid = GetBid(bar.symbol); - // result = // - ask <= upper && - bid <= upper && bar.low <= upper // && // - ask >= lower && - bid >= lower && bar.low >= lower // ; diff --git a/X121SMCEA/Experts/x-121.smc.expert.class.mq5 b/X121SMCEA/Experts/x-121.smc.expert.class.mq5 index 02c2e853..21f919b5 100644 --- a/X121SMCEA/Experts/x-121.smc.expert.class.mq5 +++ b/X121SMCEA/Experts/x-121.smc.expert.class.mq5 @@ -1326,15 +1326,19 @@ class XC121SMCExpert : public XCBaseExpert // // Check Force Close ... string forceCloseTimeStr = CloseAllTradesAt(); - datetime forceCloseTime = ParseDateTimeFromTimeString(forceCloseTimeStr); - bool canForceClose = IsTimeInRange( - TimeCurrent(), - forceCloseTime // - ) && - !mIsForceCloseAtTime; - if (canForceClose) + if (IsValid(forceCloseTimeStr)) { - mIsForceCloseAtTime = mTradeHandler.ForceClose(); + // + datetime forceCloseTime = ParseDateTimeFromTimeString(forceCloseTimeStr); + bool canForceClose = IsTimeInRange( + TimeCurrent(), + forceCloseTime // + ) && + !mIsForceCloseAtTime; + if (canForceClose) + { + mIsForceCloseAtTime = mTradeHandler.ForceClose(); + } } // diff --git a/X121SMCEA/Signals/x-121.smc.xtwpv.signal.lib.mq5 b/X121SMCEA/Signals/x-121.smc.xtwpv.signal.lib.mq5 index 80c375c4..8422b9e3 100644 --- a/X121SMCEA/Signals/x-121.smc.xtwpv.signal.lib.mq5 +++ b/X121SMCEA/Signals/x-121.smc.xtwpv.signal.lib.mq5 @@ -49,8 +49,7 @@ struct X121SMCStrategyXTWPVSignalConditions datetime triggerTime; // - XFVGOrderBlock bullishOrderBlocks[]; - XFVGOrderBlock bearishOrderBlocks[]; + XFVGOrderBlock fvgOB; // // Constructor ... @@ -166,40 +165,20 @@ struct X121SMCStrategyXTWPVSignalConditions */ void ExtensionClean() { - // - Clean(bullishOrderBlocks); - Clean(bearishOrderBlocks); + fvgOB.Clean(); } /** * Update Order Blocks Date ... */ - void UpdateOrderBlocks() { + void UpdateOrderBlocks() + { // - int count = 0; datetime cTime = TimeCurrent(); // - count = ArraySize(bullishOrderBlocks); - if (IsValidSize(count)) { - // - for (int i = 0; i < count; i++) { - // - bullishOrderBlocks[i].orderBlock.To(cTime); - bullishOrderBlocks[i].fairValueGap.To(cTime); - } - } - - // - count = ArraySize(bearishOrderBlocks); - if (IsValidSize(count)) { - // - for (int i = 0; i < count; i++) { - // - bearishOrderBlocks[i].orderBlock.To(cTime); - bearishOrderBlocks[i].fairValueGap.To(cTime); - } - } + fvgOB.orderBlock.To(cTime); + fvgOB.fairValueGap.To(cTime); } // @@ -447,14 +426,14 @@ bool DetectX121SMCXTWPVSiganlSetup( // conditions.dir = forDir; - Copy( - bullishOrderBlocks, - conditions.bullishOrderBlocks // - ); - Copy( - bearishOrderBlocks, - conditions.bearishOrderBlocks // - ); + if (isBullish) + { + conditions.fvgOB = bullishOrderBlocks[0]; + } + else + { + conditions.fvgOB = bearishOrderBlocks[0]; + } // conditions.setupTime = cTime; @@ -483,7 +462,7 @@ bool DetectX121SMCXTWPVSiganlTrigger( XC121SMCCycleHelper *consolidationCycleHelper, XC121SMCCycleHelper *visionCycleHelper, // - int maxAllowedSetupAge = 0 // + int maxAllowedSetupAge = 576 // // ) { @@ -684,86 +663,44 @@ bool DetectX121SMCXTWPVSiganlTrigger( // // Trigger Conditions ... + // + double decisionPeak = decisionConditions.x121Conditions.peaksBuffer[1]; + double isNewDecisionPeak = decisionConditions.x121Conditions.isNewPeak; + + // + double decisionVale = decisionConditions.x121Conditions.valesBuffer[1]; + double isNewDecisionVale = decisionConditions.x121Conditions.isNewVale; + // // Waits For Price to Go Inside FVG ... - XFVGOrderBlock fvgOrderBlock; - bool isPriceInsideOB = false; - bool isPriceInsideFVG = false; - if (isBullish) - { - // - int count = ArraySize(conditions.bullishOrderBlocks); - for (int i = 0; i < count; i++) - { - // - XFVGOrderBlock iModel = conditions.bullishOrderBlocks[i]; + bool isPriceInsideOB = IsPriceInsideZone( + cBar, + conditions.fvgOB.orderBlock // + ); - // - isPriceInsideOB = IsPriceInsideZone( - cBar, - iModel.orderBlock // - ); - - // - isPriceInsideFVG = IsPriceInsideZone( - cBar, - iModel.fairValueGap // - ); - - // - if (isPriceInsideOB && - isPriceInsideFVG) - { - // - fvgOrderBlock = iModel; - break; - } - - // - isPriceInsideOB = false; - isPriceInsideFVG = false; - } - } - else - { - // - int count = ArraySize(conditions.bearishOrderBlocks); - for (int i = 0; i < count; i++) - { - // - XFVGOrderBlock iModel = conditions.bearishOrderBlocks[i]; - - // - isPriceInsideOB = IsPriceInsideZone( - cBar, - iModel.orderBlock // - ); - - // - isPriceInsideFVG = IsPriceInsideZone( - cBar, - iModel.fairValueGap // - ); - - // - if (isPriceInsideOB && - isPriceInsideFVG) - { - // - fvgOrderBlock = iModel; - break; - } - - // - isPriceInsideOB = false; - isPriceInsideFVG = false; - } - } + // + bool isPriceInsideFVG = IsPriceInsideZone( + cBar, + conditions.fvgOB.fairValueGap // + ); // result = isPriceInsideOB && isPriceInsideFVG && - fvgOrderBlock.IsValid(); + conditions.fvgOB.IsValid(); + if (!result) + { + return result; + } + + // + double fvgOBUpper = 0; + double fvgOBLower = 0; + bool hasBoundary = conditions.fvgOB.GetBoundary( + fvgOBUpper, + fvgOBLower // + ); + result = hasBoundary; if (!result) { return result; @@ -773,13 +710,15 @@ bool DetectX121SMCXTWPVSiganlTrigger( // Detect Bullish Conditions ... isBullish = isBullish && - cBar.IsBullish(); + cBar.IsBullish() && + isNewDecisionVale; // // Detect Bearish Conditions ... isBearish = isBearish && - cBar.IsBearish(); + cBar.IsBearish() && + isNewDecisionPeak; // result = isBullish || @@ -788,13 +727,6 @@ bool DetectX121SMCXTWPVSiganlTrigger( { // // Cleanup Setup Conditions ... - // int setupAge = conditions.GetSetupAge(); - // if (IsValidSize(setupAge) && - // IsValidSize(maxAllowedSetupAge) && - // setupAge >= maxAllowedSetupAge) - // { - // conditions.Clean(); - // } // return result; @@ -844,6 +776,22 @@ bool DetectX121SMCXTWPVSiganlTrigger( double peak = triggerConditions.x121Conditions.peaksBuffer[1]; double vale = triggerConditions.x121Conditions.valesBuffer[1]; + // + if (conditions.fvgOB.IsValid()) + { + // + Add( + fvgOBUpper, + sls // + ); + + // + Add( + fvgOBLower, + sls // + ); + } + // if (isBullish) { @@ -857,6 +805,12 @@ bool DetectX121SMCXTWPVSiganlTrigger( sls // ); } + + // + Add( + vale, + sls // + ); } else if (isBearish) { @@ -870,11 +824,12 @@ bool DetectX121SMCXTWPVSiganlTrigger( sls // ); } - } - // - if (ArraySize(sls) == 0) - { + // + Add( + peak, + sls // + ); } // @@ -927,6 +882,71 @@ bool DetectX121SMCXTWPVSiganlTrigger( return result; } +// +int AddX121SMCXTWPVConditionsIfNotExists( + X121SMCStrategyXTWPVSignalConditions &item, + X121SMCStrategyXTWPVSignalConditions &items[] // +) +{ + // + int result = 0; + + // + bool isSetuped = IsValid(item.setupTime) && + HasDirection(item.dir); + if (!isSetuped) + { + return result; + } + + // + int count = ArraySize(items); + bool canAdd = !IsValidSize(count); + if (!canAdd) + { + // + // Prese Item Data ... + bool isBullish = IsBullish(item.dir); + + // + bool hasSame = false; + for (int i = 0; i < count; i++) + { + // + X121SMCStrategyXTWPVSignalConditions iItem = items[i]; + + // + hasSame = iItem.fvgOB.IsSameAs(item.fvgOB); + if (hasSame) + { + break; + } + } + + // + canAdd = !hasSame; + } + + // + if (canAdd) + { + // + AddRef( + item, + items // + ); + + // + // Remove Olds ... + + // + result = ArraySize(items); + } + + // + return result; +} + // // Draw Signal ... int DrawX121SMCXTWPVSiganl( diff --git a/X121SMCEA/Strategy/x-121.smc.strategy.class.mq5 b/X121SMCEA/Strategy/x-121.smc.strategy.class.mq5 index 5ad6d411..f4331115 100644 --- a/X121SMCEA/Strategy/x-121.smc.strategy.class.mq5 +++ b/X121SMCEA/Strategy/x-121.smc.strategy.class.mq5 @@ -478,6 +478,7 @@ class XCX121SMCStrategy : public XCX121SMCBaseStrategy // // XTWPV Signal ... X121SMCStrategyXTWPVSignalConditions mXTWPVConditions; + X121SMCStrategyXTWPVSignalConditions mXTWPVConditionsCollection[]; bool DetectXTWPVSignal( X121SMCStrategyConditions &conditions // ) @@ -489,10 +490,52 @@ class XCX121SMCStrategy : public XCX121SMCBaseStrategy bool isBullish = false; bool isBearish = false; + // + int zIndex = 0; + int cIndex = zIndex + 1; + int pIndex = cIndex + 1; + int ppIndex = pIndex + 1; + // string symbol = GetSymbol(); ENUM_TIMEFRAMES period = GetPeriod(); + // + XOHCL zBar; + result = zBar.Init( + symbol, + period, + zIndex // + ); + if (!result) + { + return result; + } + + // + XOHCL cBar; + result = cBar.Init( + symbol, + period, + cIndex // + ); + if (!result) + { + return result; + } + + // + XOHCL pBar; + result = pBar.Init( + symbol, + period, + pIndex // + ); + if (!result) + { + return result; + } + // datetime cTime = TimeCurrent(); @@ -524,81 +567,111 @@ class XCX121SMCStrategy : public XCX121SMCBaseStrategy // setupDir = mXTWPVConditions.dir; setupTime = mXTWPVConditions.setupTime; - } - - // - if (isSetuped) - { - // - mXTWPVConditions.UpdateOrderBlocks(); // - XCBaseObject *bullDrawnObjects[]; - int bullDrawnObjectsCount = mPOIDrawer.DrawFVGOrderBlock( - mXTWPVConditions.bullishOrderBlocks, - bullDrawnObjects // - ); - if (IsValidSize(bullDrawnObjectsCount)) + if (isSetuped) { - AddObjectsIfNotExists(bullDrawnObjects); - } + // + AddRef( + mXTWPVConditions, + mXTWPVConditionsCollection); - // - XCBaseObject *bearDrawnObjects[]; - int bearDrwanObjectsCount = mPOIDrawer.DrawFVGOrderBlock( - mXTWPVConditions.bearishOrderBlocks, - bearDrawnObjects // - ); - if (IsValidSize(bearDrwanObjectsCount)) - { - AddObjectsIfNotExists(bearDrawnObjects); + // + mXTWPVConditions.Clean(); } } // - result = isSetuped; + int conditionsCount = ArraySize(mXTWPVConditionsCollection); + result = IsValidSize(conditionsCount); if (!result) { return result; } // - // Detect Trigger Conditions ... - bool canTrigger = mXTWPVConditions.CanTrigger(); - datetime triggerTime = mXTWPVConditions.triggerTime; - if (!canTrigger) + // Looking For Conditions ... + int selectedIndex = 0; + X121SMCStrategyXTWPVSignalConditions mConditions; + for (int i = 0; i < conditionsCount; i++) { // - // Detect Signal Trigger ... - canTrigger = DetectX121SMCXTWPVSiganlTrigger( - mXTWPVConditions, - symbol, - period, - mTriggerCycleHelper, - mDecisionCycleHelper, - mAnalyseCycleHelper, - mVerificationCycleHelper, - mConsolidationCycleHelper, - mVisionCycleHelper // - ); + // Update Conditions ... + mXTWPVConditionsCollection[i].UpdateOrderBlocks(); // - result = canTrigger; - if (!result) + // Draw Conditions ... + + // + XFVGOrderBlock iFVGOB = mXTWPVConditionsCollection[i].fvgOB; + XCBaseObject *drawnObjects[]; + mPOIDrawer.DrawFVGOrderBlock( + iFVGOB, + drawnObjects // + ); + AddObjectsIfNotExists(drawnObjects); + + // + // Check Triggers ... + bool canTrigger = mXTWPVConditionsCollection[i].CanTrigger(); + datetime triggerTime = mXTWPVConditionsCollection[i].triggerTime; + if (!canTrigger) { - return result; + // + // Detect Signal Trigger ... + canTrigger = DetectX121SMCXTWPVSiganlTrigger( + mXTWPVConditionsCollection[i], + symbol, + period, + mTriggerCycleHelper, + mDecisionCycleHelper, + mAnalyseCycleHelper, + mVerificationCycleHelper, + mConsolidationCycleHelper, + mVisionCycleHelper // + ); + + // + result = canTrigger; + if (!result) + { + return result; + } + + // + triggerTime = mXTWPVConditionsCollection[i].triggerTime; } // - triggerTime = mXTWPVConditions.triggerTime; + if (canTrigger) + { + // + selectedIndex = i; + mConditions = mXTWPVConditionsCollection[i]; + break; + } } // - // Check Signal Direction ... + result = IsValid(mConditions.setupTime) && + HasDirection(mConditions.dir); + if (!result) + { + return result; + } // - isBullish = IsBullish(setupDir); - isBearish = IsBearish(setupDir); + // Remove Selected Index from Main Collection ... + ArrayRemove( + mXTWPVConditionsCollection, + selectedIndex, + 1 // + ); + + // + // Check Signal Direction ... + isBullish = IsBullish(mConditions.dir); + isBearish = IsBearish(mConditions.dir); result = isBullish || isBearish; if (!result) @@ -608,26 +681,10 @@ class XCX121SMCStrategy : public XCX121SMCBaseStrategy // // Issues Signal on Conditions ... - conditions.signalDir = setupDir; + conditions.sl = mConditions.sl; conditions.provider = providerStr; - conditions.sl = mXTWPVConditions.sl; - conditions.target = mXTWPVConditions.target; - - // - // TODO: Remove ... - // conditions.decisionZones = mXTWPVConditions.decisionZone; - // conditions.marketStructure = mXTWPVConditions.analyseMarketStructure; - // if (isBullish) - // { - // conditions.priceZones = mXTWPVConditions.valePriceZone; - // } - // else - // { - // conditions.priceZones = mXTWPVConditions.peakPriceZone; - // } - - // - mXTWPVConditions.Clean(); + conditions.signalDir = mConditions.dir; + conditions.target = mConditions.target; // return result; @@ -685,7 +742,7 @@ class XCX121SMCStrategy : public XCX121SMCBaseStrategy x121Inputs.Default(); // - x121Inputs.showRSI = false; + x121Inputs.showRSI = true; // bool isInited = false; @@ -710,14 +767,14 @@ class XCX121SMCStrategy : public XCX121SMCBaseStrategy // // XATR ... - x121Inputs.xatrInputs.showATRUpper = true; - x121Inputs.xatrInputs.showATRLower = true; + x121Inputs.xatrInputs.showATRUpper = false; + x121Inputs.xatrInputs.showATRLower = false; // // XSTR ... x121Inputs.xstrInputs.showStr = true; - x121Inputs.xstrInputs.showStrUpper = true; - x121Inputs.xstrInputs.showStrLower = true; + x121Inputs.xstrInputs.showStrUpper = false; + x121Inputs.xstrInputs.showStrLower = false; // // XDON ... @@ -729,7 +786,7 @@ class XCX121SMCStrategy : public XCX121SMCBaseStrategy // // XVWAP ... x121Inputs.xvwapInputs.showVWapFast = false; - x121Inputs.xvwapInputs.showVWapFast = false; + x121Inputs.xvwapInputs.showVWapMedium = false; x121Inputs.xvwapInputs.showVWapSlow = false; //