From 560a54af306ba76947ad383d666294a8ee1a3df5 Mon Sep 17 00:00:00 2001 From: Hadi Khazaee Asl Date: Tue, 21 Jan 2025 05:46:01 +0330 Subject: [PATCH] last ... --- Classes/x-saherelm.x-poi.drawer.class.mq5 | 5 +- Documents/BKP/1/4.mq5 | 530 ++++ Documents/BKP/1/tmp.codes.mq5 | 38 + .../BKP/1/x-121.smc.x.signal.lib copy.mq5 | 1983 +++++++++++++ Documents/BKP/1/x-121.smc.x.signal.lib.mq5 | 1943 +++++++++++++ Experts/x-saherelm.x-121.smc.ea.mq5 | 6 +- Helpers/x-saherelm.x121.helper.mq5 | 64 - Helpers/x-saherelm.x121.xpv.helper.mq5 | 390 +-- .../x-121.smc.market.cycle.helper.class.mq5 | 193 ++ X121SMCEA/Libraries/x-121.smc.guard.lib.mq5 | 42 +- X121SMCEA/Libraries/x-121.smc.lib.mq5 | 12 +- X121SMCEA/Signals/x-121.smc.x.signal.lib.mq5 | 2457 +++++++++++++++++ .../Signals/x-121.smc.xpz.signal.lib.mq5 | 389 +-- .../Signals/x-121.smc.xrspvi.signal.lib.mq5 | 58 +- .../Signals/x-121.smc.xstrpv.signal.lib.mq5 | 58 +- .../Strategy/x-121.smc.strategy.class.mq5 | 314 ++- 16 files changed, 7623 insertions(+), 859 deletions(-) create mode 100644 Documents/BKP/1/4.mq5 create mode 100644 Documents/BKP/1/x-121.smc.x.signal.lib copy.mq5 create mode 100644 Documents/BKP/1/x-121.smc.x.signal.lib.mq5 create mode 100644 X121SMCEA/Signals/x-121.smc.x.signal.lib.mq5 diff --git a/Classes/x-saherelm.x-poi.drawer.class.mq5 b/Classes/x-saherelm.x-poi.drawer.class.mq5 index 5c1064aa..eb7b9c08 100644 --- a/Classes/x-saherelm.x-poi.drawer.class.mq5 +++ b/Classes/x-saherelm.x-poi.drawer.class.mq5 @@ -2782,10 +2782,7 @@ class XCPOIDrawer : public XCBase } // - if (!IsValid(to)) - { - to = bar.time + PeriodSeconds(bar.period); - } + to = NormalizeTime(to); // string prefix = Prefix(); diff --git a/Documents/BKP/1/4.mq5 b/Documents/BKP/1/4.mq5 new file mode 100644 index 00000000..15975f62 --- /dev/null +++ b/Documents/BKP/1/4.mq5 @@ -0,0 +1,530 @@ +////////////////////////////////////////////////////////////////////////////////// +////// Detect Price Zones : +///////////////////////////////////////////////////////////////////////////////// + + // + XPriceZones priceZone; + bool isPriceZoneValidForPeak; + bool isPriceZoneValidForVale; + + // + priceZone.Clean(); + isPriceZoneValidForPeak = false; + isPriceZoneValidForVale = false; + + // + // Detect Price Zone ... + + // + double pzPeak = decisionXConditions.peaksBuffer[1]; + double pzVale = decisionXConditions.valesBuffer[1]; + + // + // Detecting Decision Price ones ... + XPriceZones decisionPriceZone; + bool hasDecisionPriceZone = CalculatePriceInsideZones( + decisionPriceZone, + decisionState, + cBar // + ); + double decisionPriceZoneUpper = 0; + double decisionPriceZoneLower = 0; + bool isDecisionPriceZoneValidForPeak = false; + bool isDecisionPriceZoneValidForVale = false; + if (hasDecisionPriceZone) + { + // + bool hasBoundary = decisionPriceZone.GetBoundary( + X_DIRECTION_ALL, + decisionPriceZoneUpper, + decisionPriceZoneLower // + ); + + // + isDecisionPriceZoneValidForPeak = + hasBoundary && + pzPeak <= decisionPriceZoneUpper && + pzPeak >= decisionPriceZoneLower; + + // + isDecisionPriceZoneValidForVale = + hasBoundary && + pzVale <= decisionPriceZoneUpper && + pzVale >= decisionPriceZoneLower; + } + + // + // Detecting Analyse Price ones ... + XPriceZones analysePriceZone; + bool hasAnalysePriceZone = CalculatePriceInsideZones( + analysePriceZone, + analyseState, + cBar // + ); + double analysePriceZoneUpper = 0; + double analysePriceZoneLower = 0; + bool isAnalysePriceZoneValidForPeak = false; + bool isAnalysePriceZoneValidForVale = false; + if (hasAnalysePriceZone) + { + // + bool hasBoundary = analysePriceZone.GetBoundary( + X_DIRECTION_ALL, + analysePriceZoneUpper, + analysePriceZoneLower // + ); + + // + isAnalysePriceZoneValidForPeak = + hasBoundary && + pzPeak <= analysePriceZoneUpper && + pzPeak >= analysePriceZoneLower; + + // + isAnalysePriceZoneValidForVale = + hasBoundary && + pzVale <= analysePriceZoneUpper && + pzVale >= analysePriceZoneLower; + } + + // + // Detecting Verification Price ones ... + XPriceZones verificationPriceZone; + bool hasVerificationPriceZone = CalculatePriceInsideZones( + verificationPriceZone, + verificationState, + cBar // + ); + double verificationPriceZoneUpper = 0; + double verificationPriceZoneLower = 0; + bool isVerificationPriceZoneValidForPeak = false; + bool isVerificationPriceZoneValidForVale = false; + if (hasVerificationPriceZone) + { + // + bool hasBoundary = verificationPriceZone.GetBoundary( + X_DIRECTION_ALL, + verificationPriceZoneUpper, + verificationPriceZoneLower // + ); + + // + isVerificationPriceZoneValidForPeak = + hasBoundary && + pzPeak <= verificationPriceZoneUpper && + pzPeak >= verificationPriceZoneLower; + + // + isVerificationPriceZoneValidForVale = + hasBoundary && + pzVale <= verificationPriceZoneUpper && + pzVale >= verificationPriceZoneLower; + } + + +////////////////////////////////////////////////////////////////////////////////// +////// Detect Pivot Zones : +///////////////////////////////////////////////////////////////////////////////// + + // + double X121SMCXPivotPeak; + double X121SMCXPivotVale; + datetime X121SMCXPivotEnd; + datetime X121SMCXPivotStart; + ENUM_XPV_PIVOTS X121SMCXPivotType = XPV_NONE; + + // + // Detect PV Pivot ... + + // + bool isPivotPeakZoneRejected = false; + bool isPivotPeakZoneBreakedUp = false; + bool isPivotPeakZoneBreakedDown = false; + bool isPivotValeZoneRejected = false; + bool isPivotValeZoneBreakedUp = false; + bool isPivotValeZoneBreakedDown = false; + bool hasPivot = conditions.pivotZone.IsValid(); + if (!hasPivot) + { + // + hasPivot = IsValid(X121SMCXPivotStart); + if (!hasPivot) + { + // + bool isNewVale = decisionXConditions.isNewVale; + bool isNewValeOverLast = decisionXConditions.isNewValeOverLast; + bool isNewValeUnderLast = decisionXConditions.isNewValeUnderLast; + bool isSameVales = decisionXConditions.valesBuffer[1] == + decisionXConditions.valesBuffer[2] && + decisionXConditions.valesBuffer[2] == + decisionXConditions.valesBuffer[3]; + bool isSameCycleVales = decisionXConditions.valesBuffer[1] == + analyseXConditions.valesBuffer[1] && + analyseXConditions.valesBuffer[1] == + verificationXConditions.valesBuffer[1]; + + // + bool isNewPeak = decisionXConditions.isNewPeak; + bool isNewPeakOverLast = decisionXConditions.isNewPeakOverLast; + bool isNewPeakUnderLast = decisionXConditions.isNewPeakUnderLast; + bool isSamePeaks = decisionXConditions.peaksBuffer[1] == + decisionXConditions.peaksBuffer[2] && + decisionXConditions.peaksBuffer[2] == + decisionXConditions.peaksBuffer[3]; + bool isSameCyclePeaks = decisionXConditions.peaksBuffer[1] == + analyseXConditions.peaksBuffer[1] && + analyseXConditions.peaksBuffer[1] == + verificationXConditions.peaksBuffer[1]; + + // + bool isValeStart = + isSameVales && + isSameCycleVales; + bool isPeakStart = + isSamePeaks && + isSameCyclePeaks; + + // + bool isStart = isPeakStart || + isValeStart; + if (isStart) + { + // + X121SMCXPivotStart = cTime; + X121SMCXPivotType = + isPeakStart + ? XPV_PEAK + : XPV_VALE; + + // + X121SMCXPivotPeak = decisionXConditions.peaksBuffer[1]; + X121SMCXPivotVale = decisionXConditions.valesBuffer[1]; + } + + // + hasPivot = IsValid(X121SMCXPivotStart); + + // + // Create XPVPivot instance ... + if (hasPivot) + { + // + conditions.pivotZone.symbol = symbol; + conditions.pivotZone.period = period; + + // + conditions.pivotZone.to = cTime; + conditions.pivotZone.repetition = 3; + + // + conditions.pivotZone.upper = X121SMCXPivotPeak; + conditions.pivotZone.lower = X121SMCXPivotVale; + + // + conditions.pivotZone.type = X121SMCXPivotType; + conditions.pivotZone.from = X121SMCXPivotStart; + } + } + } + + // + if (hasPivot) + { + // + bool isBreaked = X121SMCXPivotType == XPV_PEAK + ? decisionXConditions.isBreakedUpPrevPeak + : decisionXConditions.isBreakedDownPrevVale; + + // + if (!isBreaked) + { + // + X121SMCXPivotPeak = decisionXConditions.peaksBuffer[1]; + X121SMCXPivotVale = decisionXConditions.valesBuffer[1]; + + // + conditions.pivotZone.to = cTime; + conditions.pivotZone.repetition++; + conditions.pivotZone.upper = X121SMCXPivotPeak; + conditions.pivotZone.lower = X121SMCXPivotVale; + } + else + { + // + X121SMCXPivotEnd = cTime; + conditions.pivotZone.to = cTime; + } + + // + // Fill Pivot State ... + + // + XPOIState analysePivotState; + DetectPivotPOIs( + conditions.pivotZone, + analyseState, + analysePivotState // + ); + + // + XPOIState decisionPivotState; + DetectPivotPOIs( + conditions.pivotZone, + decisionState, + decisionPivotState // + ); + + // + // Combine two State ... + XPOIState combinedPivotState; + XPOIState iStates[]; + AddRef( + analysePivotState, + iStates // + ); + AddRef( + decisionPivotState, + iStates // + ); + CombineStates( + combinedPivotState, + iStates // + ); + combinedPivotState = decisionPivotState; + + // + ArrayFree(iStates); + + // + combinedPivotState.time = decisionPivotState.time; + combinedPivotState.symbol = decisionPivotState.symbol; + combinedPivotState.period = decisionPivotState.period; + + // + // Hold Only Areas Which on Upper or Lower bondary of Pivot Zone ... + FilterPivotState( + conditions.pivotZone, + combinedPivotState // + ); + + // + conditions.pivotZone.state = combinedPivotState; + + // + double peakUpper = 0; + double peakLower = 0; + double valeUpper = 0; + double valeLower = 0; + + // + datetime peakTo = NULL; + datetime valeTo = NULL; + datetime peakFrom = NULL; + datetime valeFrom = NULL; + + // + bool hasBoxData = DetectPivotStateBoxData( + conditions.pivotZone, + peakUpper, + peakLower, + peakFrom, + peakTo, + valeUpper, + valeLower, + valeFrom, + valeTo // + ); + + // + // Calculate Pivot Tick Zones ... + + // + int ticksLevels = decisionCycleHelper + .mPOIDetector + .TicksRangeZoneLevel(); + int ticksRange = decisionCycleHelper + .mPOIDetector + .TicksRangeZoneRange(); + + // + CalculatePivotTickZone( + conditions.pivotZone, + ticksLevels, + ticksRange // + ); + + // + isPivotPeakZoneRejected = + hasBoxData && + ( + // + IsBarReject( + peakLower, + X_DIRECTION_BEARISH, + cBar // + ) + // + || + // + IsBarReject( + peakUpper, + X_DIRECTION_BEARISH, + cBar // + ) + // + ); + isPivotPeakZoneBreakedUp = + hasBoxData && + IsBarBreak( + peakUpper, + X_DIRECTION_BULLISH, + cBar // + ); + isPivotPeakZoneBreakedDown = + hasBoxData && + IsBarBreak( + peakLower, + X_DIRECTION_BEARISH, + cBar // + ); + + // + isPivotValeZoneRejected = + hasBoxData && + ( + // + IsBarReject( + valeLower, + X_DIRECTION_BULLISH, + cBar // + ) + // + || + // + IsBarReject( + valeUpper, + X_DIRECTION_BULLISH, + cBar // + ) + // + ); + isPivotValeZoneBreakedUp = + hasBoxData && + IsBarBreak( + valeUpper, + X_DIRECTION_BULLISH, + cBar // + ); + isPivotValeZoneBreakedDown = + hasBoxData && + IsBarBreak( + valeLower, + X_DIRECTION_BEARISH, + cBar // + ); + } + + // + bool isPivotEnded = IsValid(X121SMCXPivotEnd); + if (isPivotEnded) + { + // + X121SMCXPivotPeak = 0; + X121SMCXPivotVale = 0; + X121SMCXPivotEnd = NULL; + X121SMCXPivotStart = NULL; + X121SMCXPivotType = XPV_NONE; + + // + conditions.pivotZone.Clean(); + } + + +////////////////////////////////////////////////////////////////////////////////// +////// Detect Pivot Zones : +///////////////////////////////////////////////////////////////////////////////// + + // + bool isCondition1Bullish = + // + hasPivot && + // + isCBarBullishFormed && + isCBarBullishPullbacked && + // + hasAnalyseBullishTrend && + hasDecisionBullishTrend && + hasVerificationBullishTrend && + // + decisionXConditions.isSarBullish && + analyseXConditions.isSarBullish && + verificationXConditions.isSarBullish && + // + false + // + ; + + // + bool isCondition1Bearish = + // + hasPivot && + // + isCBarBearishFormed && + isCBarBearishPullbacked && + // + hasAnalyseBearishTrend && + hasDecisionBearishTrend && + hasVerificationBearishTrend && + // + decisionXConditions.isSarBearish && + analyseXConditions.isSarBearish && + verificationXConditions.isSarBearish && + // + false + // + ; + + // + bool hasCondition1 = isCondition1Bullish || + isCondition1Bearish; + if (hasCondition1) + { + // + ENUM_X_DIRECTION pzDir = + isCondition1Bullish + ? X_DIRECTION_BULLISH + : X_DIRECTION_BEARISH; + + // + conditions.priceZone = analysePriceZone; + conditions.isPriceZoneValidForPeak = isAnalysePriceZoneValidForPeak; + conditions.isPriceZoneValidForVale = isAnalysePriceZoneValidForVale; + + // + pzPeak = analysePriceZoneUpper; + pzVale = analysePriceZoneLower; + + // + double point = GetEntry( + conditions.symbol, + pzDir // + ); + + // + // Manipulate Conditions Point ... + + // + // point = + // isCondition1Bullish ? pzPeak + // : pzVale; + conditions.point = point; + + // + // Manipulate Conditions Pivot ... + + // + conditions.pivot = + isCondition1Bullish + ? pzVale + : pzPeak; + } diff --git a/Documents/BKP/1/tmp.codes.mq5 b/Documents/BKP/1/tmp.codes.mq5 index 710e8ed5..2d5f91cb 100644 --- a/Documents/BKP/1/tmp.codes.mq5 +++ b/Documents/BKP/1/tmp.codes.mq5 @@ -335,3 +335,41 @@ int DrawX121SMCStrategyConditions( // return result; } + + +//////////////////////////////////////////////// + + // // + // isCBarBearishFormed && + // (isPivotToDownRejected || + // isPivotToDownBreaked) && + // conditions.pivotZone.IsVale() && + // // + // // SAR ... + // isSarBearishFormed && + // // // + // // // STR ... + // // !(decisionXConditions.isStrBullish) && + // // // + // // // VWAP ... + // // !(decisionXConditions.isVWapBullishState || + // // decisionXConditions.isVWapBullishOrdered) && + // // + + + // // + // isCBarBullishFormed && + // (isPivotToUpRejected || + // isPivotToUpBreaked) && + // conditions.pivotZone.IsPeak() && + // // + // // SAR ... + // isSarBullishFormed && + // // // + // // // STR ... + // // !(decisionXConditions.isStrBearish) && + // // // + // // // VWAP ... + // // !(decisionXConditions.isVWapBearishState || + // // decisionXConditions.isVWapBearishOrdered) && + // // diff --git a/Documents/BKP/1/x-121.smc.x.signal.lib copy.mq5 b/Documents/BKP/1/x-121.smc.x.signal.lib copy.mq5 new file mode 100644 index 00000000..64d1fc7c --- /dev/null +++ b/Documents/BKP/1/x-121.smc.x.signal.lib copy.mq5 @@ -0,0 +1,1983 @@ +/////////////////////////////////////////////////////// +// +// SaherElm IT Center MQL5 X121 SMC Signal Class +// ------------------------------------------------- +// Name: X +// Description: provide all Signalling functions ... +// +// +// Maintainer: +// ------------ +// Hadi Khazaee Asl (hadi_khazaee_asl@yahoo.com) +// +////////////////////////////////////////////////////// +// +// Global Properties ... +#property library +#property copyright "Copyright 2023, SaherElm IT Center" +#property link "https://www.saherelm.ir" +#property version "1.00" +#property strict + +// +// Imports ... +// #include "../../Libraries/x-trade.lib" +#include "../Classes/x-121.smc.market.cycle.helper.class.mq5" +#include "../Libraries/x-121.smc.lib.mq5" + +// +// Definitions ... +struct X121SMCStrategyXSignalConditions +{ + // + // 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; + + // + double pivot; + double point; + + // + double higherPeak; + datetime higherPeakTime; + + // + double lowerVale; + datetime lowerValeTime; + + // + XPVPivot pivotZone; + + // + // Constructor ... + X121SMCStrategyXSignalConditions() + { + 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() + { + // + pivot = 0; + point = 0; + + // + pivotZone.Clean(); + + // + higherPeak = 0; + higherPeakTime = NULL; + + // + lowerVale = 0; + lowerValeTime = NULL; + } + + // +}; + +// +// Signaller Data Sources ... +X121SMCStrategyXSignalConditions mXConditions; +X121SMCStrategyXSignalConditions mXConditionsCollection[]; + +// +// Extension Functions ... + +// +// Detect Setup Conditions ... +bool DetectX121SMCXSiganlSetup( + string _symbol, + ENUM_TIMEFRAMES _period, + // + X121SMCStrategyXSignalConditions &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 = decisionCycleHelper.GetBar( + zBar, + zIndex // + ); + // zBar.Init( + // symbol, + // period, + // zIndex // + // ); + if (!result) + { + return result; + } + + // + XOHCL cBar; + result = decisionCycleHelper.GetBar( + cBar, + cIndex // + ); + // cBar.Init( + // symbol, + // period, + // cIndex // + // ); + if (!result) + { + return result; + } + + // + XOHCL pBar; + result = decisionCycleHelper.GetBar( + pBar, + pIndex // + ); + // 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 = 3; + 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; + + // + // Cycle X121Conditions ... + X121Conditions triggerXConditions = triggerConditions.x121Conditions; + X121Conditions decisionXConditions = decisionConditions.x121Conditions; + X121Conditions analyseXConditions = analyseConditions.x121Conditions; + X121Conditions verificationXConditions = verificationConditions.x121Conditions; + X121Conditions consolidationXConditions = consolidationConditions.x121Conditions; + X121Conditions visionXConditions = visionConditions.x121Conditions; + + // + // Setup Conditions ... + + // + // Detect Trend ... + + // + // Consolidation ... + ENUM_X_DIRECTION consolidationTrendDir; + bool hasConsolidationTrend = + consolidationCycleHelper + .DetectMarketStructure( + consolidationTrendDir // + ); + bool hasConsolidationBullishTrend = + hasConsolidationTrend && + IsBullish(consolidationTrendDir); + bool hasConsolidationBearishTrend = + hasConsolidationTrend && + IsBearish(consolidationTrendDir); + + // + // Verification ... + ENUM_X_DIRECTION verificationTrendDir; + bool hasVerificationTrend = + verificationCycleHelper + .DetectMarketStructure( + verificationTrendDir // + ); + bool hasVerificationBullishTrend = + hasVerificationTrend && + IsBullish(verificationTrendDir); + bool hasVerificationBearishTrend = + hasVerificationTrend && + IsBearish(verificationTrendDir); + + // + // Analyse ... + ENUM_X_DIRECTION analyseTrendDir; + bool hasAnalyseTrend = + analyseCycleHelper + .DetectMarketStructure( + analyseTrendDir // + ); + bool hasAnalyseBullishTrend = + hasAnalyseTrend && + IsBullish(analyseTrendDir); + bool hasAnalyseBearishTrend = + hasAnalyseTrend && + IsBearish(analyseTrendDir); + + // + // Decision ... + ENUM_X_DIRECTION decisionTrendDir; + bool hasDecisionTrend = + decisionCycleHelper + .DetectMarketStructure( + decisionTrendDir // + ); + bool hasDecisionBullishTrend = + hasDecisionTrend && + IsBullish(decisionTrendDir); + bool hasDecisionBearishTrend = + hasDecisionTrend && + IsBearish(decisionTrendDir); + + // + // Detect Bar State ... + + // + // PinBar ... + ENUM_X_DIRECTION cBarPinDir; + bool isCBarPin = decisionCycleHelper + .mBarAnalyser + .IsPinBar( + cBar, + cBarPinDir, + 1 // + ); + bool isCBarBullishPin = + isCBarPin && + IsBullish(cBarPinDir); + bool isCBarBearishPin = + isCBarPin && + IsBearish(cBarPinDir); + + // + // Engulf ... + ENUM_X_DIRECTION cBarEngulfDir; + bool isCBarEngulfed = decisionCycleHelper + .mBarAnalyser + .IsEngulfBar( + cBar, + cBarEngulfDir, + 0 // Extended ... + ); + bool isCBarBullishEngulfed = + isCBarEngulfed && + IsBullish(cBarEngulfDir); + bool isCBarBearishEngulfed = + isCBarEngulfed && + IsBearish(cBarEngulfDir); + + // + // Momentum ... + ENUM_X_DIRECTION cBarMomentumDir; + bool isCBarMomentum = decisionCycleHelper + .mBarAnalyser + .IsMomentumBar( + cBar, + cBarMomentumDir, + 0 // Extended ... + ); + bool isCBarBullishMomentum = + isCBarMomentum && + IsBullish(cBarMomentumDir); + bool isCBarBearishMomentum = + isCBarMomentum && + IsBearish(cBarMomentumDir); + + // + // Reject ... + ENUM_X_DIRECTION cBarRejectDir; + bool isCBarRejected = decisionCycleHelper + .mBarAnalyser + .IsRejectionBar( + cBar, + cBarRejectDir, + 0 // Extended ... + ); + bool isCBarBullishRejected = + isCBarRejected && + IsBullish(cBarRejectDir); + bool isCBarBearishRejected = + isCBarRejected && + IsBearish(cBarRejectDir); + + // + // Pull Back ... + ENUM_X_DIRECTION cBarPullbackDir; + bool isCBarPullbacked = + decisionCycleHelper + .mBarAnalyser + .HasPullBack( + cBarPullbackDir, + cBar // + ); + bool isCBarBullishPullbacked = + isCBarPullbacked && + IsBullish(cBarPullbackDir); + bool isCBarBearishPullbacked = + isCBarPullbacked && + IsBearish(cBarPullbackDir); + + // + // HH/LL Break ... + + // + bool isCBarBreaksUpHH = IsBarBreak( + hh, + X_DIRECTION_BULLISH, + cBar // + ); + + // + bool isCBarBreaksDownLL = IsBarBreak( + hh, + X_DIRECTION_BEARISH, + cBar // + ); + + // + // Bars Pattern and Power and Pressures ... + + // + bool hasCBarBullishPattern = + decisionCycleHelper + .mBarAnalyser + .HasBullishPattern( + cBar, + 2 // + ); + + // + bool hasCBarBearishPattern = + decisionCycleHelper + .mBarAnalyser + .HasBearishPattern( + cBar, + 2 // + ); + + // + bool isCBarHasBullishPower = + decisionCycleHelper + .mBarAnalyser + .HasBullishPower( + cBar, + 2 // + ); + + // + bool isCBarHasBearishPower = + decisionCycleHelper + .mBarAnalyser + .HasBearishPower( + cBar, + 2 // + ); + + // + bool isCBarHasBullishPressure = + decisionCycleHelper + .mBarAnalyser + .HasBullishPressure( + cBar, + 2 // + ); + + // + bool isCBarHasBearishPressure = + decisionCycleHelper + .mBarAnalyser + .HasBearishPressure( + cBar, + 2 // + ); + + // + // Bar Checking Summary ... + + // + // Bullish ... + bool isCBarBullishFormed = + // + ( + // + hasCBarBullishPattern && + isCBarHasBullishPower && + isCBarHasBullishPressure + // + ) + // + || + // + ( + // + isCBarBullishPin || + isCBarBreaksUpHH || + isCBarBullishEngulfed || + isCBarBullishMomentum || + isCBarBullishRejected + // + ) + // + ; + + // + // Bearish ... + bool isCBarBearishFormed = + // + ( + // + hasCBarBearishPattern && + isCBarHasBearishPower && + isCBarHasBearishPressure + // + ) + // + || + // + ( + // + isCBarBearishPin || + isCBarBreaksDownLL || + isCBarBearishEngulfed || + isCBarBearishMomentum || + isCBarBearishRejected + // + ) + // + ; + + // + // Set Higher Peak and Lowe Vale ... + + // + XOHCL higherPeakBar; + bool hasHigherPeak = + conditions.higherPeak > 0 && + IsValid(conditions.higherPeakTime); + bool isHigherPeakBreaked = false; + bool isHigherPeakRejected = false; + + // + if (!hasHigherPeak) + { + // + int higherPeakIDX = -1; + double higherPeak = + decisionCycleHelper + .mX121Helper + .xpvHelper + .GetHigherPeak( + higherPeakIDX, + decisionXConditions.peaksBuffer[1], + cIndex // + ); + + // + if (higherPeak > 0 && + IsValidIndex(higherPeakIDX)) + { + // + bool hasHigherPeak = higherPeakBar.Init( + symbol, + period, + higherPeakIDX // + ); + + // + if (hasHigherPeak) + { + // + conditions.higherPeakTime = cTime; + conditions.higherPeak = higherPeak; + } + } + } + + // + if (hasHigherPeak) + { + // + isHigherPeakBreaked = IsBarBreak( + conditions.higherPeak, + X_DIRECTION_BULLISH, + cBar // + ); + + // + isHigherPeakRejected = IsBarReject( + conditions.higherPeak, + X_DIRECTION_BEARISH, + cBar // + ); + } + + // + XOHCL lowerValeBar; + bool hasLowerVale = + conditions.lowerVale > 0 && + IsValid(conditions.lowerValeTime); + bool isLowerValeBreaked = false; + bool isLowerValeRejected = false; + + // + if (!hasLowerVale) + { + // + int lowerValeIDX = -1; + double lowerVale = + decisionCycleHelper + .mX121Helper + .xpvHelper + .GetLowerVale( + lowerValeIDX, + decisionXConditions.valesBuffer[1], + cIndex // + ); + + // + if (lowerVale > 0 && + IsValidIndex(lowerValeIDX)) + { + // + hasLowerVale = lowerValeBar.Init( + symbol, + period, + lowerValeIDX // + ); + + // + if (hasLowerVale) + { + // + conditions.lowerVale = lowerVale; + conditions.lowerValeTime = cTime; + } + } + } + + // + if (hasLowerVale) + { + // + isLowerValeBreaked = IsBarBreak( + conditions.lowerVale, + X_DIRECTION_BEARISH, + cBar // + ); + + // + isLowerValeRejected = IsBarReject( + conditions.lowerVale, + X_DIRECTION_BULLISH, + cBar // + ); + } + + // + double pivotMid = 0; + bool isPivotToUpRejected = false; + bool isPivotToDownRejected = false; + bool isPivotToUpBreaked = false; + bool isPivotToDownBreaked = false; + bool hasPivot = conditions.pivotZone.IsValid(); + + // + if (!hasPivot) + { + // + bool isSamePeaks = decisionXConditions.peaksBuffer[1] == + decisionXConditions.peaksBuffer[2] && + decisionXConditions.peaksBuffer[2] == + decisionXConditions.peaksBuffer[3]; + bool isSameCyclePeaks = decisionXConditions.peaksBuffer[1] == + analyseXConditions.peaksBuffer[1] && + analyseXConditions.peaksBuffer[1] == + verificationXConditions.peaksBuffer[1]; + bool hasPeakPivot = + // isSamePeaks && + hasHigherPeak && + isSameCyclePeaks && + (isHigherPeakBreaked || + isHigherPeakRejected); + + // + bool isSameVales = decisionXConditions.valesBuffer[1] == + decisionXConditions.valesBuffer[2] && + decisionXConditions.valesBuffer[2] == + decisionXConditions.valesBuffer[3]; + bool isSameCycleVales = decisionXConditions.valesBuffer[1] == + analyseXConditions.valesBuffer[1] && + analyseXConditions.valesBuffer[1] == + verificationXConditions.valesBuffer[1]; + bool hasValePivot = + // isSameVales && + hasLowerVale && + isSameCycleVales && + (isLowerValeBreaked || + isLowerValeRejected); + + // + bool hasPivot = hasPeakPivot || + hasValePivot; + if (hasPivot) + { + // + XPVPivot pivot; + + // + pivot.symbol = symbol; + pivot.period = period; + + // + pivot.upper = decisionXConditions.peaksBuffer[1]; + pivot.lower = decisionXConditions.valesBuffer[1]; + + // + pivot.to = cTime; + pivot.from = cTime; + pivot.repetition = 3; + + // + pivot.type = + hasPeakPivot + ? XPV_PEAK + : XPV_VALE; + + // + hasPivot = pivot.IsValid(); + if (hasPivot) + { + conditions.pivotZone = pivot; + } + } + } + + // + if (hasPivot) + { + // + pivotMid = conditions + .pivotZone + .CalculateMid(); + + // + isPivotToUpRejected = IsBarReject( + pivotMid, + X_DIRECTION_BULLISH, + cBar // + ); + + // + isPivotToDownRejected = IsBarReject( + pivotMid, + X_DIRECTION_BEARISH, + cBar // + ); + + // + isPivotToUpBreaked = IsBarBreak( + pivotMid, + X_DIRECTION_BULLISH, + cBar // + ); + + // + isPivotToDownBreaked = IsBarBreak( + pivotMid, + X_DIRECTION_BEARISH, + cBar // + ); + } + + // + // Sar Conditions ... + + // + bool isSarBullishFormed = + ( + // + ( + // + decisionXConditions.isBreakedUpPrevSar && + (decisionXConditions.isSarBullish || + decisionXConditions.isSarSwitchedToBullish) + // + ) + // + ); + + // + bool isSarBearishFormed = + ( + // + ( + // + decisionXConditions.isBreakedDownPrevSar && + (decisionXConditions.isSarBearish || + decisionXConditions.isSarSwitchedToBearish) + // + ) + // + ); + + // + // + // + + // + // Summarize Conditions ... + + // + bool isCondition1Bullish = + // + hasPivot && + // + isCBarBullishFormed && + (isPivotToUpRejected || + isPivotToUpBreaked) && + conditions.pivotZone.IsPeak() && + // + // SAR ... + isSarBullishFormed && + // // + // // STR ... + // !(decisionXConditions.isStrBearish) && + // // + // // VWAP ... + // !(decisionXConditions.isVWapBearishState || + // decisionXConditions.isVWapBearishOrdered) && + // + true + // + ; + + // + bool isCondition1Bearish = + // + hasPivot && + // + isCBarBearishFormed && + (isPivotToDownRejected || + isPivotToDownBreaked) && + conditions.pivotZone.IsVale() && + // + // SAR ... + isSarBearishFormed && + // // + // // STR ... + // !(decisionXConditions.isStrBullish) && + // // + // // VWAP ... + // !(decisionXConditions.isVWapBullishState || + // decisionXConditions.isVWapBullishOrdered) && + // + true + // + ; + + // + bool hasCondition1 = isCondition1Bullish || + isCondition1Bearish; + if (hasCondition1) + { + // + ENUM_X_DIRECTION pzDir = + isCondition1Bullish + ? X_DIRECTION_BULLISH + : X_DIRECTION_BEARISH; + + // + double point = GetEntry( + conditions.symbol, + pzDir // + ); + + // + // Manipulate Conditions Point ... + + // + conditions.point = pivotMid; + + // + // Manipulate Conditions Pivot ... + + // + conditions.pivot = + isCondition1Bullish + ? conditions.pivotZone.upper + : conditions.pivotZone.lower; + + // + } + + // + // + // + + // + isBullish = + // + // false + isCondition1Bullish + // + ; + + // + isBearish = + // + // false + isCondition1Bearish + // + ; + + // + result = isBullish || + isBearish; + if (!result) + { + // + // Cleanup Arrays ... + ArrayFree(triggerPoiEvents); + ArrayFree(triggerCycleEvents); + ArrayFree(decisionPoiEvents); + ArrayFree(decisionCycleEvents); + ArrayFree(analysePoiEvents); + ArrayFree(analyseCycleEvents); + ArrayFree(verificationPoiEvents); + ArrayFree(verificationCycleEvents); + ArrayFree(consolidationPoiEvents); + ArrayFree(consolidationCycleEvents); + ArrayFree(visionPoiEvents); + ArrayFree(visionCycleEvents); + + // + return result; + } + + // + conditions.setupTime = cTime; + conditions.dir = + isBullish + ? X_DIRECTION_BULLISH + : X_DIRECTION_BEARISH; + + // + // Cleanup Arrays ... + ArrayFree(triggerPoiEvents); + ArrayFree(triggerCycleEvents); + ArrayFree(decisionPoiEvents); + ArrayFree(decisionCycleEvents); + ArrayFree(analysePoiEvents); + ArrayFree(analyseCycleEvents); + ArrayFree(verificationPoiEvents); + ArrayFree(verificationCycleEvents); + ArrayFree(consolidationPoiEvents); + ArrayFree(consolidationCycleEvents); + ArrayFree(visionPoiEvents); + ArrayFree(visionCycleEvents); + + // + return result; +} + +// +// Detect Trigger Conditions ... +bool DetectX121SMCXSiganlTrigger( + // + X121SMCStrategyXSignalConditions &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 = 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; + + // + // Cycle X121Conditions ... + X121Conditions triggerXConditions = triggerConditions.x121Conditions; + X121Conditions decisionXConditions = decisionConditions.x121Conditions; + X121Conditions analyseXConditions = analyseConditions.x121Conditions; + X121Conditions verificationXConditions = verificationConditions.x121Conditions; + X121Conditions consolidationXConditions = consolidationConditions.x121Conditions; + X121Conditions visionXConditions = visionConditions.x121Conditions; + + // + // Trigger Conditions ... + + // + // SAR ... + double sar = decisionXConditions.sarBuffer[1]; + + // + // STR ... + double str = decisionXConditions.strBuffer[1]; + + // + // CHE ... + double le1 = decisionXConditions.le1Buffer[1]; + double le2 = decisionXConditions.le2Buffer[1]; + double se1 = decisionXConditions.se1Buffer[1]; + double se2 = decisionXConditions.se2Buffer[1]; + + // + // ATR ... + double atrUpper = decisionXConditions.atrUpperBuffer[1]; + double atrLower = decisionXConditions.atrLowerBuffer[1]; + + // + // PV ... + double peak = decisionXConditions.peaksBuffer[1]; + double vale = decisionXConditions.valesBuffer[1]; + + // + int higherPeakIDX = -1; + double higherPeak = decisionCycleHelper + .mX121Helper + .xpvHelper.GetHigherPeak( + higherPeakIDX, + peak // + ); + + // + int lowerValeIDX = -1; + double lowerVale = decisionCycleHelper + .mX121Helper + .xpvHelper.GetLowerVale( + lowerValeIDX, + vale // + ); + + // + // Slopes ... + + // + bool isRsiSlopeBullish = decisionXConditions.isRsiSlopeBullish; + bool isStrSlopeBullish = decisionXConditions.isStrSlopeBullish; + bool isAtrUpperSlopeBullish = decisionXConditions.isAtrUpperSlopeBullish; + bool isAtrLowerSlopeBullish = decisionXConditions.isAtrLowerSlopeBullish; + bool isVwapFastSlopeBullish = decisionXConditions.isVwapFastSlopeBullish; + bool isVwapMidSlopeBullish = decisionXConditions.isVwapMidSlopeBullish; + bool isVwapSlowSlopeBullish = decisionXConditions.isVwapSlowSlopeBullish; + + // + bool isRsiSlopeBearish = decisionXConditions.isRsiSlopeBearish; + bool isStrSlopeBearish = decisionXConditions.isStrSlopeBearish; + bool isAtrUpperSlopeBearish = decisionXConditions.isAtrUpperSlopeBearish; + bool isAtrLowerSlopeBearish = decisionXConditions.isAtrLowerSlopeBearish; + bool isVwapFastSlopeBearish = decisionXConditions.isVwapFastSlopeBearish; + bool isVwapMidSlopeBearish = decisionXConditions.isVwapMidSlopeBearish; + bool isVwapSlowSlopeBearish = decisionXConditions.isVwapSlowSlopeBearish; + + // + bool isSlopesBullish = + isRsiSlopeBullish && + isStrSlopeBullish && + isAtrUpperSlopeBullish && + isAtrLowerSlopeBullish && + isVwapFastSlopeBullish && + isVwapMidSlopeBullish && + isVwapSlowSlopeBullish; + + // + bool isSlopesBearish = + isRsiSlopeBearish && + isStrSlopeBearish && + isAtrUpperSlopeBearish && + isAtrLowerSlopeBearish && + isVwapFastSlopeBearish && + isVwapMidSlopeBearish && + isVwapSlowSlopeBearish; + + // + double point = conditions.point; + bool isPointBreaked = + isBullish + ? ask > point && bid > point + : ask < point && bid < point; + // bool isPointBreaked = IsBarBreak( + // point, + // setupDir, + // cBar // + // ); + + // + // Summary ... + + // + isBullish = + // + isBullish && + // isPointBreaked && + // isSlopesBullish && + cBar.IsBullish() + // + ; + + // + isBearish = + // + isBearish && + // isPointBreaked && + // isSlopesBearish && + cBar.IsBearish() + // + ; + + // + result = isBullish || + isBearish; + if (!result) + { + // + // Cleanup Setup Conditions ... + int setupAge = conditions.GetSetupAge(); + if (IsValidSize(setupAge) && + IsValidSize(maxAllowedSetupAge) && + setupAge >= maxAllowedSetupAge) + { + conditions.Clean(); + } + + // + // Cleanup Arrays ... + ArrayFree(triggerPoiEvents); + ArrayFree(triggerCycleEvents); + ArrayFree(decisionPoiEvents); + ArrayFree(decisionCycleEvents); + ArrayFree(analysePoiEvents); + ArrayFree(analyseCycleEvents); + ArrayFree(verificationPoiEvents); + ArrayFree(verificationCycleEvents); + ArrayFree(consolidationPoiEvents); + ArrayFree(consolidationCycleEvents); + ArrayFree(visionPoiEvents); + ArrayFree(visionCycleEvents); + + // + return result; + } + + // + // Detect Nearest Pivot Point ... + + // + // Detect Target ... + double target = CalculateTarget( + cBar, + decisionState, + setupDir // + ); + if (target == 0) + { + // + target = CalculateTarget( + cBar, + analyseState, + setupDir // + ); + + // + if (target == 0) + { + // + target = CalculateTarget( + cBar, + verificationState, + setupDir // + ); + } + } + target = 0; + + // + double entry = GetEntry( + conditions.symbol, + setupDir // + ); + + // + // Filling SL Candidates ... + double momentumBarPointsDif = 30 * points; + + // + // Bullish Momentum Bar Selection ... + XOHCL bullishMomentumBar; + int bullishMomentumBarsCount = decisionState.CountBullishMomentumBars(); + if (IsValidSize(bullishMomentumBarsCount)) + { + // + for (int i = 0; i < bullishMomentumBarsCount; i++) + { + // + XCMomentumBar *iMomentum = decisionState.bullishMomentumBars[i]; + + // + XOHCL iBar; + bool isFilled = iMomentum.FillBar(iBar); + if (!isFilled) + { + continue; + } + + // + bool isValidDistane = (MathAbs(iBar.low) - entry) >= momentumBarPointsDif; + if (!isValidDistane) + { + continue; + } + + // + bool isIndexPassed = iBar.Index() <= 5; + if (!isIndexPassed) + { + continue; + } + + // + bool canSet = + !bullishMomentumBar.IsValid() || + (bullishMomentumBar.IsValid() && + bullishMomentumBar.low < entry && + bullishMomentumBar.Index() > iBar.Index()); + if (canSet) + { + bullishMomentumBar = iBar; + } + } + } + + // + // Bearish Momentum Bar Selection ... + XOHCL bearishMomentumBar; + int bearishMomentumBarsCount = decisionState.CountBearishMomentumBars(); + if (IsValidSize(bearishMomentumBarsCount)) + { + // + for (int i = 0; i < bearishMomentumBarsCount; i++) + { + // + XCMomentumBar *iMomentum = decisionState.bearishMomentumBars[i]; + + // + XOHCL iBar; + bool isFilled = iMomentum.FillBar(iBar); + if (!isFilled) + { + continue; + } + + // + bool isValidDistane = (MathAbs(iBar.high) - entry) >= momentumBarPointsDif; + if (!isValidDistane) + { + continue; + } + + // + bool isIndexPassed = iBar.Index() <= 5; + if (!isIndexPassed) + { + continue; + } + + // + bool canSet = + !bearishMomentumBar.IsValid() || + (bearishMomentumBar.IsValid() && + bearishMomentumBar.high > entry && + bearishMomentumBar.Index() > iBar.Index()); + if (canSet) + { + bearishMomentumBar = iBar; + } + } + } + + // + double sls[]; + Add( + sar, + sls // + ); + Add( + str, + sls // + ); + + // + if (isBullish) + { + // + Add( + atrLower, + sls // + ); + + // // + // Add( + // vale, + // sls // + // ); + + // + if (bullishMomentumBar.IsValid()) + { + // + Add( + bullishMomentumBar.low, + sls // + ); + } + + // // + // if (IsValidIndex(lowerValeIDX)) + // { + // // + // Add( + // lowerVale, + // sls // + // ); + // } + + // + if (le1 != EMPTY_VALUE) + { + // + Add( + le1, + sls // + ); + } + + // + if (le2 != EMPTY_VALUE) + { + // + Add( + le2, + sls // + ); + } + } + else + { + // + Add( + atrUpper, + sls // + ); + + // // + // Add( + // peak, + // sls // + // ); + + // + if (bearishMomentumBar.IsValid()) + { + // + Add( + bearishMomentumBar.high, + sls // + ); + } + + // + // if (IsValidIndex(higherPeakIDX)) + // { + // // + // Add( + // higherPeak, + // sls // + // ); + // } + + // + if (se1 != EMPTY_VALUE) + { + // + Add( + se1, + sls // + ); + } + + // + if (se2 != EMPTY_VALUE) + { + // + Add( + se2, + sls // + ); + } + } + + // + double iAtr = decisionConditions.x121Conditions.atrBuffer[1]; + iAtr *= 2.5; + + // + double slsMin = GetMin(sls); + double slsMax = GetMax(sls); + + // + double sl = isBullish + ? slsMin - iAtr + : slsMax + iAtr; + double risk = MathAbs(entry - sl); + double riskInPoints = risk / points; + if (riskInPoints >= 150) + { + // + target = + isBullish + ? entry + (points * 200) + : entry - (points * 200); + + // + 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; + + // + // Cleanup Arrays ... + ArrayFree(triggerPoiEvents); + ArrayFree(triggerCycleEvents); + ArrayFree(decisionPoiEvents); + ArrayFree(decisionCycleEvents); + ArrayFree(analysePoiEvents); + ArrayFree(analyseCycleEvents); + ArrayFree(verificationPoiEvents); + ArrayFree(verificationCycleEvents); + ArrayFree(consolidationPoiEvents); + ArrayFree(consolidationCycleEvents); + ArrayFree(visionPoiEvents); + ArrayFree(visionCycleEvents); + + // + return result; +} + +// +bool DetectX121SMCXGuards( + X121SMCGuard &guards[], + const XPosition &positions[], + XC121SMCCycleHelper *triggerCycleHelper, + XC121SMCCycleHelper *decisionCycleHelper, + XC121SMCCycleHelper *analyseCycleHelper, + XC121SMCCycleHelper *verificationCycleHelper, + XC121SMCCycleHelper *consolidationCycleHelper, + XC121SMCCycleHelper *visionCycleHelper // +) +{ + // + bool result = false; + + // + string provider = ToString(X_121_SMC_PROVIDER_X); + + // + // result = DetectX121SMCGuards( + // provider, + // guards, + // positions, + // triggerCycleHelper, + // decisionCycleHelper, + // analyseCycleHelper, + // verificationCycleHelper, + // consolidationCycleHelper, + // visionCycleHelper // + // ); + + // + return result; +} + +// +int AddX121SMCXConditionsIfNotExists( + X121SMCStrategyXSignalConditions &item, + X121SMCStrategyXSignalConditions &items[], + int maxAllowed = 10 // +) +{ + // + int result = 0; + + // + bool isSetuped = IsValid(item.setupTime) && + HasDirection(item.dir); + if (!isSetuped) + { + return result; + } + + // + int count = ArraySize(items); + if (IsValidSize(count)) + { + // + // Copy Original Items ... + X121SMCStrategyXSignalConditions tmpItems[]; + Copy( + items, + tmpItems // + ); + + // + // Prese Item Data ... + bool isBullish = IsBullish(item.dir); + + // + for (int i = 0; i < count; i++) + { + // + X121SMCStrategyXSignalConditions iItem = tmpItems[i]; + + // + bool canRemove = item.dir == iItem.dir && + item.pivot == iItem.pivot; + if (canRemove) + { + // + ArrayRemove( + items, + i, + 1 // + ); + } + } + + // + Clean(tmpItems); + } + + // + AddRef( + item, + items // + ); + + // + // Remove Olds ... + CleanupArray( + items, + maxAllowed // + ); + + // + result = ArraySize(items); + + // + return result; +} + +// +int DrawX121SMCXConditions( + X121SMCStrategyXSignalConditions &conditions, + XCBaseObject *&drawnObjects[], + XCPOIDrawer *drawer // +) +{ + // + int result = 0; + + // + Clean(drawnObjects); + + // + if (drawer == NULL) + { + return result; + } + + // + bool isSetuped = conditions.IsSetuped(); + if (!isSetuped) + { + return result; + } + + // + return result; +} + +// diff --git a/Documents/BKP/1/x-121.smc.x.signal.lib.mq5 b/Documents/BKP/1/x-121.smc.x.signal.lib.mq5 new file mode 100644 index 00000000..0e58dc61 --- /dev/null +++ b/Documents/BKP/1/x-121.smc.x.signal.lib.mq5 @@ -0,0 +1,1943 @@ +/////////////////////////////////////////////////////// +// +// SaherElm IT Center MQL5 X121 SMC Signal Class +// ------------------------------------------------- +// Name: X +// Description: provide all Signalling functions ... +// +// +// Maintainer: +// ------------ +// Hadi Khazaee Asl (hadi_khazaee_asl@yahoo.com) +// +////////////////////////////////////////////////////// +// +// Global Properties ... +#property library +#property copyright "Copyright 2023, SaherElm IT Center" +#property link "https://www.saherelm.ir" +#property version "1.00" +#property strict + +// +// Imports ... +// #include "../../Libraries/x-trade.lib" +#include "../Classes/x-121.smc.market.cycle.helper.class.mq5" +#include "../Libraries/x-121.smc.lib.mq5" + +// +// Definitions ... +struct X121SMCStrategyXSignalConditions +{ + // + // 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; + + // + double pivot; + double point; + + // + double higherPeak; + datetime higherPeakTime; + + // + double lowerVale; + datetime lowerValeTime; + + // + XPVPivot pivotZone; + + // + // Constructor ... + X121SMCStrategyXSignalConditions() + { + 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() + { + // + pivot = 0; + point = 0; + + // + pivotZone.Clean(); + + // + higherPeak = 0; + higherPeakTime = NULL; + + // + lowerVale = 0; + lowerValeTime = NULL; + } + + // +}; + +// +// Signaller Data Sources ... +X121SMCStrategyXSignalConditions mXConditions; +X121SMCStrategyXSignalConditions mXConditionsCollection[]; + +// +// Extension Functions ... + +// +// Detect Setup Conditions ... +bool DetectX121SMCXSiganlSetup( + string _symbol, + ENUM_TIMEFRAMES _period, + // + X121SMCStrategyXSignalConditions &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 = decisionCycleHelper.GetBar( + zBar, + zIndex // + ); + // zBar.Init( + // symbol, + // period, + // zIndex // + // ); + if (!result) + { + return result; + } + + // + XOHCL cBar; + result = decisionCycleHelper.GetBar( + cBar, + cIndex // + ); + // cBar.Init( + // symbol, + // period, + // cIndex // + // ); + if (!result) + { + return result; + } + + // + XOHCL pBar; + result = decisionCycleHelper.GetBar( + pBar, + pIndex // + ); + // 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 = 3; + 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; + + // + // Cycle X121Conditions ... + X121Conditions triggerXConditions = triggerConditions.x121Conditions; + X121Conditions decisionXConditions = decisionConditions.x121Conditions; + X121Conditions analyseXConditions = analyseConditions.x121Conditions; + X121Conditions verificationXConditions = verificationConditions.x121Conditions; + X121Conditions consolidationXConditions = consolidationConditions.x121Conditions; + X121Conditions visionXConditions = visionConditions.x121Conditions; + + // + // Setup Conditions ... + + // + // Detect Trend ... + + // + // Consolidation ... + bool hasConsolidationBullishTrend = consolidationXConditions.isTrendBullish; + bool hasConsolidationBearishTrend = consolidationXConditions.isTrendBearish; + + // + // Verification ... + bool hasVerificationBullishTrend = verificationXConditions.isTrendBullish; + bool hasVerificationBearishTrend = verificationXConditions.isTrendBearish; + + // + // Analyse ... + bool hasAnalyseBullishTrend = analyseXConditions.isTrendBullish; + bool hasAnalyseBearishTrend = analyseXConditions.isTrendBearish; + + // + // Decision ... + bool hasDecisionBullishTrend = decisionXConditions.isTrendBullish; + bool hasDecisionBearishTrend = decisionXConditions.isTrendBearish; + + // + // Detect Bar State ... + + // + // PinBar ... + ENUM_X_DIRECTION cBarPinDir; + bool isCBarPin = decisionCycleHelper + .mBarAnalyser + .IsPinBar( + cBar, + cBarPinDir, + 1 // + ); + bool isCBarBullishPin = + isCBarPin && + IsBullish(cBarPinDir); + bool isCBarBearishPin = + isCBarPin && + IsBearish(cBarPinDir); + + // + // Engulf ... + ENUM_X_DIRECTION cBarEngulfDir; + bool isCBarEngulfed = decisionCycleHelper + .mBarAnalyser + .IsEngulfBar( + cBar, + cBarEngulfDir, + 0 // Extended ... + ); + bool isCBarBullishEngulfed = + isCBarEngulfed && + IsBullish(cBarEngulfDir); + bool isCBarBearishEngulfed = + isCBarEngulfed && + IsBearish(cBarEngulfDir); + + // + // Momentum ... + ENUM_X_DIRECTION cBarMomentumDir; + bool isCBarMomentum = decisionCycleHelper + .mBarAnalyser + .IsMomentumBar( + cBar, + cBarMomentumDir, + 0 // Extended ... + ); + bool isCBarBullishMomentum = + isCBarMomentum && + IsBullish(cBarMomentumDir); + bool isCBarBearishMomentum = + isCBarMomentum && + IsBearish(cBarMomentumDir); + + // + // Reject ... + ENUM_X_DIRECTION cBarRejectDir; + bool isCBarRejected = decisionCycleHelper + .mBarAnalyser + .IsRejectionBar( + cBar, + cBarRejectDir, + 0 // Extended ... + ); + bool isCBarBullishRejected = + isCBarRejected && + IsBullish(cBarRejectDir); + bool isCBarBearishRejected = + isCBarRejected && + IsBearish(cBarRejectDir); + + // + // Pull Back ... + ENUM_X_DIRECTION cBarPullbackDir; + bool isCBarPullbacked = + decisionCycleHelper + .mBarAnalyser + .HasPullBack( + cBarPullbackDir, + cBar // + ); + bool isCBarBullishPullbacked = + isCBarPullbacked && + IsBullish(cBarPullbackDir); + bool isCBarBearishPullbacked = + isCBarPullbacked && + IsBearish(cBarPullbackDir); + + // + // HH/LL Break ... + + // + bool isCBarBreaksUpHH = IsBarBreak( + hh, + X_DIRECTION_BULLISH, + cBar // + ); + + // + bool isCBarBreaksDownLL = IsBarBreak( + hh, + X_DIRECTION_BEARISH, + cBar // + ); + + // + // Bars Pattern and Power and Pressures ... + + // + bool hasCBarBullishPattern = + decisionCycleHelper + .mBarAnalyser + .HasBullishPattern( + cBar, + 2 // + ); + + // + bool hasCBarBearishPattern = + decisionCycleHelper + .mBarAnalyser + .HasBearishPattern( + cBar, + 2 // + ); + + // + bool isCBarHasBullishPower = + decisionCycleHelper + .mBarAnalyser + .HasBullishPower( + cBar, + 2 // + ); + + // + bool isCBarHasBearishPower = + decisionCycleHelper + .mBarAnalyser + .HasBearishPower( + cBar, + 2 // + ); + + // + bool isCBarHasBullishPressure = + decisionCycleHelper + .mBarAnalyser + .HasBullishPressure( + cBar, + 2 // + ); + + // + bool isCBarHasBearishPressure = + decisionCycleHelper + .mBarAnalyser + .HasBearishPressure( + cBar, + 2 // + ); + + // + // Bar Checking Summary ... + + // + // Bullish ... + bool isCBarBullishFormed = + // + ( + // + hasCBarBullishPattern && + isCBarHasBullishPower && + isCBarHasBullishPressure + // + ) + // + || + // + ( + // + isCBarBullishPin || + // isCBarBreaksUpHH || + isCBarBullishEngulfed || + isCBarBullishMomentum || + isCBarBullishRejected + // + ) + // + ; + + // + // Bearish ... + bool isCBarBearishFormed = + // + ( + // + hasCBarBearishPattern && + isCBarHasBearishPower && + isCBarHasBearishPressure + // + ) + // + || + // + ( + // + isCBarBearishPin || + // isCBarBreaksDownLL || + isCBarBearishEngulfed || + isCBarBearishMomentum || + isCBarBearishRejected + // + ) + // + ; + + // + // Set Higher Peak and Lowe Vale ... + + // + XOHCL higherPeakBar; + bool hasHigherPeak = + conditions.higherPeak > 0 && + IsValid(conditions.higherPeakTime); + bool isHigherPeakBreaked = false; + bool isHigherPeakRejected = false; + + // + if (!hasHigherPeak) + { + // + int higherPeakIDX = -1; + double higherPeak = + decisionCycleHelper + .mX121Helper + .xpvHelper + .GetHigherPeak( + higherPeakIDX, + decisionXConditions.peaksBuffer[1], + cIndex // + ); + + // + if (higherPeak > 0 && + IsValidIndex(higherPeakIDX)) + { + // + bool hasHigherPeak = higherPeakBar.Init( + symbol, + period, + higherPeakIDX // + ); + + // + if (hasHigherPeak) + { + // + conditions.higherPeakTime = cTime; + conditions.higherPeak = higherPeak; + } + } + } + + // + if (hasHigherPeak) + { + // + isHigherPeakBreaked = IsBarBreak( + conditions.higherPeak, + X_DIRECTION_BULLISH, + cBar // + ); + + // + isHigherPeakRejected = IsBarReject( + conditions.higherPeak, + X_DIRECTION_BEARISH, + cBar // + ); + } + + // + XOHCL lowerValeBar; + bool hasLowerVale = + conditions.lowerVale > 0 && + IsValid(conditions.lowerValeTime); + bool isLowerValeBreaked = false; + bool isLowerValeRejected = false; + + // + if (!hasLowerVale) + { + // + int lowerValeIDX = -1; + double lowerVale = + decisionCycleHelper + .mX121Helper + .xpvHelper + .GetLowerVale( + lowerValeIDX, + decisionXConditions.valesBuffer[1], + cIndex // + ); + + // + if (lowerVale > 0 && + IsValidIndex(lowerValeIDX)) + { + // + hasLowerVale = lowerValeBar.Init( + symbol, + period, + lowerValeIDX // + ); + + // + if (hasLowerVale) + { + // + conditions.lowerVale = lowerVale; + conditions.lowerValeTime = cTime; + } + } + } + + // + if (hasLowerVale) + { + // + isLowerValeBreaked = IsBarBreak( + conditions.lowerVale, + X_DIRECTION_BEARISH, + cBar // + ); + + // + isLowerValeRejected = IsBarReject( + conditions.lowerVale, + X_DIRECTION_BULLISH, + cBar // + ); + } + + // + double pivotMid = 0; + bool isPivotToUpRejected = false; + bool isPivotToDownRejected = false; + bool isPivotToUpBreaked = false; + bool isPivotToDownBreaked = false; + bool hasPivot = conditions.pivotZone.IsValid(); + + // + if (!hasPivot) + { + // + bool isSamePeaks = decisionXConditions.peaksBuffer[1] == + decisionXConditions.peaksBuffer[2] && + decisionXConditions.peaksBuffer[2] == + decisionXConditions.peaksBuffer[3]; + bool isSameCyclePeaks = decisionXConditions.peaksBuffer[1] == + analyseXConditions.peaksBuffer[1] && + analyseXConditions.peaksBuffer[1] == + verificationXConditions.peaksBuffer[1]; + bool hasPeakPivot = + // isSamePeaks && + hasHigherPeak && + isSameCyclePeaks && + (isHigherPeakBreaked || + isHigherPeakRejected); + + // + bool isSameVales = decisionXConditions.valesBuffer[1] == + decisionXConditions.valesBuffer[2] && + decisionXConditions.valesBuffer[2] == + decisionXConditions.valesBuffer[3]; + bool isSameCycleVales = decisionXConditions.valesBuffer[1] == + analyseXConditions.valesBuffer[1] && + analyseXConditions.valesBuffer[1] == + verificationXConditions.valesBuffer[1]; + bool hasValePivot = + // isSameVales && + hasLowerVale && + isSameCycleVales && + (isLowerValeBreaked || + isLowerValeRejected); + + // + bool hasPivot = hasPeakPivot || + hasValePivot; + if (hasPivot) + { + // + XPVPivot pivot; + + // + pivot.symbol = symbol; + pivot.period = period; + + // + pivot.upper = decisionXConditions.peaksBuffer[1]; + pivot.lower = decisionXConditions.valesBuffer[1]; + + // + pivot.to = cTime; + pivot.from = cTime; + pivot.repetition = 3; + + // + pivot.type = + hasPeakPivot + ? XPV_PEAK + : XPV_VALE; + + // + hasPivot = pivot.IsValid(); + if (hasPivot) + { + conditions.pivotZone = pivot; + } + } + } + + // + if (hasPivot) + { + // + pivotMid = conditions + .pivotZone + .CalculateMid(); + + // + isPivotToUpRejected = IsBarReject( + pivotMid, + X_DIRECTION_BULLISH, + cBar // + ); + + // + isPivotToDownRejected = IsBarReject( + pivotMid, + X_DIRECTION_BEARISH, + cBar // + ); + + // + isPivotToUpBreaked = IsBarBreak( + pivotMid, + X_DIRECTION_BULLISH, + cBar // + ); + + // + isPivotToDownBreaked = IsBarBreak( + pivotMid, + X_DIRECTION_BEARISH, + cBar // + ); + } + + // + // Sar Conditions ... + + // + bool isSarBullishFormed = + ( + // + ( + // + decisionXConditions.isBreakedUpPrevSar && + (decisionXConditions.isSarBullish || + decisionXConditions.isSarSwitchedToBullish) + // + ) + // + ); + + // + bool isSarBearishFormed = + ( + // + ( + // + decisionXConditions.isBreakedDownPrevSar && + (decisionXConditions.isSarBearish || + decisionXConditions.isSarSwitchedToBearish) + // + ) + // + ); + + // + // + // + + // + // Summarize Conditions ... + + // + bool isCondition1Bullish = + // + hasPivot && + // + isCBarBullishFormed && + (isPivotToUpRejected || + isPivotToUpBreaked) && + conditions.pivotZone.IsPeak() && + // + // SAR ... + isSarBullishFormed && + // // + // // STR ... + // !(decisionXConditions.isStrBearish) && + // // + // // VWAP ... + // !(decisionXConditions.isVWapBearishState || + // decisionXConditions.isVWapBearishOrdered) && + // + true + // + ; + + // + bool isCondition1Bearish = + // + hasPivot && + // + isCBarBearishFormed && + (isPivotToDownRejected || + isPivotToDownBreaked) && + conditions.pivotZone.IsVale() && + // + // SAR ... + isSarBearishFormed && + // // + // // STR ... + // !(decisionXConditions.isStrBullish) && + // // + // // VWAP ... + // !(decisionXConditions.isVWapBullishState || + // decisionXConditions.isVWapBullishOrdered) && + // + true + // + ; + + // + bool hasCondition1 = isCondition1Bullish || + isCondition1Bearish; + if (hasCondition1) + { + // + ENUM_X_DIRECTION pzDir = + isCondition1Bullish + ? X_DIRECTION_BULLISH + : X_DIRECTION_BEARISH; + + // + double point = GetEntry( + conditions.symbol, + pzDir // + ); + + // + // Manipulate Conditions Point ... + + // + conditions.point = pivotMid; + + // + // Manipulate Conditions Pivot ... + + // + conditions.pivot = + isCondition1Bullish + ? conditions.pivotZone.upper + : conditions.pivotZone.lower; + + // + } + + // + // + // + + // + isBullish = + // + // false + isCondition1Bullish + // + ; + + // + isBearish = + // + // false + isCondition1Bearish + // + ; + + // + result = isBullish || + isBearish; + if (!result) + { + // + // Cleanup Arrays ... + ArrayFree(triggerPoiEvents); + ArrayFree(triggerCycleEvents); + ArrayFree(decisionPoiEvents); + ArrayFree(decisionCycleEvents); + ArrayFree(analysePoiEvents); + ArrayFree(analyseCycleEvents); + ArrayFree(verificationPoiEvents); + ArrayFree(verificationCycleEvents); + ArrayFree(consolidationPoiEvents); + ArrayFree(consolidationCycleEvents); + ArrayFree(visionPoiEvents); + ArrayFree(visionCycleEvents); + + // + return result; + } + + // + conditions.setupTime = cTime; + conditions.dir = + isBullish + ? X_DIRECTION_BULLISH + : X_DIRECTION_BEARISH; + + // + // Cleanup Arrays ... + ArrayFree(triggerPoiEvents); + ArrayFree(triggerCycleEvents); + ArrayFree(decisionPoiEvents); + ArrayFree(decisionCycleEvents); + ArrayFree(analysePoiEvents); + ArrayFree(analyseCycleEvents); + ArrayFree(verificationPoiEvents); + ArrayFree(verificationCycleEvents); + ArrayFree(consolidationPoiEvents); + ArrayFree(consolidationCycleEvents); + ArrayFree(visionPoiEvents); + ArrayFree(visionCycleEvents); + + // + return result; +} + +// +// Detect Trigger Conditions ... +bool DetectX121SMCXSiganlTrigger( + // + X121SMCStrategyXSignalConditions &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 = 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; + + // + // Cycle X121Conditions ... + X121Conditions triggerXConditions = triggerConditions.x121Conditions; + X121Conditions decisionXConditions = decisionConditions.x121Conditions; + X121Conditions analyseXConditions = analyseConditions.x121Conditions; + X121Conditions verificationXConditions = verificationConditions.x121Conditions; + X121Conditions consolidationXConditions = consolidationConditions.x121Conditions; + X121Conditions visionXConditions = visionConditions.x121Conditions; + + // + // Trigger Conditions ... + + // + // SAR ... + double sar = decisionXConditions.sarBuffer[1]; + + // + // STR ... + double str = decisionXConditions.strBuffer[1]; + + // + // CHE ... + double le1 = decisionXConditions.le1Buffer[1]; + double le2 = decisionXConditions.le2Buffer[1]; + double se1 = decisionXConditions.se1Buffer[1]; + double se2 = decisionXConditions.se2Buffer[1]; + + // + // ATR ... + double atrUpper = decisionXConditions.atrUpperBuffer[1]; + double atrLower = decisionXConditions.atrLowerBuffer[1]; + + // + // PV ... + double peak = decisionXConditions.peaksBuffer[1]; + double vale = decisionXConditions.valesBuffer[1]; + + // + int higherPeakIDX = -1; + double higherPeak = decisionCycleHelper + .mX121Helper + .xpvHelper.GetHigherPeak( + higherPeakIDX, + peak // + ); + + // + int lowerValeIDX = -1; + double lowerVale = decisionCycleHelper + .mX121Helper + .xpvHelper.GetLowerVale( + lowerValeIDX, + vale // + ); + + // + // Slopes ... + + // + bool isRsiSlopeBullish = decisionXConditions.isRsiSlopeBullish; + bool isStrSlopeBullish = decisionXConditions.isStrSlopeBullish; + bool isAtrUpperSlopeBullish = decisionXConditions.isAtrUpperSlopeBullish; + bool isAtrLowerSlopeBullish = decisionXConditions.isAtrLowerSlopeBullish; + bool isVwapFastSlopeBullish = decisionXConditions.isVwapFastSlopeBullish; + bool isVwapMidSlopeBullish = decisionXConditions.isVwapMidSlopeBullish; + bool isVwapSlowSlopeBullish = decisionXConditions.isVwapSlowSlopeBullish; + + // + bool isRsiSlopeBearish = decisionXConditions.isRsiSlopeBearish; + bool isStrSlopeBearish = decisionXConditions.isStrSlopeBearish; + bool isAtrUpperSlopeBearish = decisionXConditions.isAtrUpperSlopeBearish; + bool isAtrLowerSlopeBearish = decisionXConditions.isAtrLowerSlopeBearish; + bool isVwapFastSlopeBearish = decisionXConditions.isVwapFastSlopeBearish; + bool isVwapMidSlopeBearish = decisionXConditions.isVwapMidSlopeBearish; + bool isVwapSlowSlopeBearish = decisionXConditions.isVwapSlowSlopeBearish; + + // + bool isSlopesBullish = + isRsiSlopeBullish && + isStrSlopeBullish && + isAtrUpperSlopeBullish && + isAtrLowerSlopeBullish && + isVwapFastSlopeBullish && + isVwapMidSlopeBullish && + isVwapSlowSlopeBullish; + + // + bool isSlopesBearish = + isRsiSlopeBearish && + isStrSlopeBearish && + isAtrUpperSlopeBearish && + isAtrLowerSlopeBearish && + isVwapFastSlopeBearish && + isVwapMidSlopeBearish && + isVwapSlowSlopeBearish; + + // + double point = conditions.point; + bool isPointBreaked = + isBullish + ? ask > point && bid > point + : ask < point && bid < point; + // bool isPointBreaked = IsBarBreak( + // point, + // setupDir, + // cBar // + // ); + + // + // Summary ... + + // + isBullish = + // + isBullish && + // isPointBreaked && + // isSlopesBullish && + cBar.IsBullish() + // + ; + + // + isBearish = + // + isBearish && + // isPointBreaked && + // isSlopesBearish && + cBar.IsBearish() + // + ; + + // + result = isBullish || + isBearish; + if (!result) + { + // + // Cleanup Setup Conditions ... + int setupAge = conditions.GetSetupAge(); + if (IsValidSize(setupAge) && + IsValidSize(maxAllowedSetupAge) && + setupAge >= maxAllowedSetupAge) + { + conditions.Clean(); + } + + // + // Cleanup Arrays ... + ArrayFree(triggerPoiEvents); + ArrayFree(triggerCycleEvents); + ArrayFree(decisionPoiEvents); + ArrayFree(decisionCycleEvents); + ArrayFree(analysePoiEvents); + ArrayFree(analyseCycleEvents); + ArrayFree(verificationPoiEvents); + ArrayFree(verificationCycleEvents); + ArrayFree(consolidationPoiEvents); + ArrayFree(consolidationCycleEvents); + ArrayFree(visionPoiEvents); + ArrayFree(visionCycleEvents); + + // + return result; + } + + // + // Detect Nearest Pivot Point ... + + // + // Detect Target ... + double target = CalculateTarget( + cBar, + decisionState, + setupDir // + ); + if (target == 0) + { + // + target = CalculateTarget( + cBar, + analyseState, + setupDir // + ); + + // + if (target == 0) + { + // + target = CalculateTarget( + cBar, + verificationState, + setupDir // + ); + } + } + target = 0; + + // + double entry = GetEntry( + conditions.symbol, + setupDir // + ); + + // + // Filling SL Candidates ... + double momentumBarPointsDif = 30 * points; + + // + // Bullish Momentum Bar Selection ... + XOHCL bullishMomentumBar; + int bullishMomentumBarsCount = decisionState.CountBullishMomentumBars(); + if (IsValidSize(bullishMomentumBarsCount)) + { + // + for (int i = 0; i < bullishMomentumBarsCount; i++) + { + // + XCMomentumBar *iMomentum = decisionState.bullishMomentumBars[i]; + + // + XOHCL iBar; + bool isFilled = iMomentum.FillBar(iBar); + if (!isFilled) + { + continue; + } + + // + bool isValidDistane = (MathAbs(iBar.low) - entry) >= momentumBarPointsDif; + if (!isValidDistane) + { + continue; + } + + // + bool isIndexPassed = iBar.Index() <= 5; + if (!isIndexPassed) + { + continue; + } + + // + bool canSet = + !bullishMomentumBar.IsValid() || + (bullishMomentumBar.IsValid() && + bullishMomentumBar.low < entry && + bullishMomentumBar.Index() > iBar.Index()); + if (canSet) + { + bullishMomentumBar = iBar; + } + } + } + + // + // Bearish Momentum Bar Selection ... + XOHCL bearishMomentumBar; + int bearishMomentumBarsCount = decisionState.CountBearishMomentumBars(); + if (IsValidSize(bearishMomentumBarsCount)) + { + // + for (int i = 0; i < bearishMomentumBarsCount; i++) + { + // + XCMomentumBar *iMomentum = decisionState.bearishMomentumBars[i]; + + // + XOHCL iBar; + bool isFilled = iMomentum.FillBar(iBar); + if (!isFilled) + { + continue; + } + + // + bool isValidDistane = (MathAbs(iBar.high) - entry) >= momentumBarPointsDif; + if (!isValidDistane) + { + continue; + } + + // + bool isIndexPassed = iBar.Index() <= 5; + if (!isIndexPassed) + { + continue; + } + + // + bool canSet = + !bearishMomentumBar.IsValid() || + (bearishMomentumBar.IsValid() && + bearishMomentumBar.high > entry && + bearishMomentumBar.Index() > iBar.Index()); + if (canSet) + { + bearishMomentumBar = iBar; + } + } + } + + // + double sls[]; + Add( + sar, + sls // + ); + Add( + str, + sls // + ); + + // + if (isBullish) + { + // + Add( + atrLower, + sls // + ); + + // // + // Add( + // vale, + // sls // + // ); + + // + if (bullishMomentumBar.IsValid()) + { + // + Add( + bullishMomentumBar.low, + sls // + ); + } + + // // + // if (IsValidIndex(lowerValeIDX)) + // { + // // + // Add( + // lowerVale, + // sls // + // ); + // } + + // + if (le1 != EMPTY_VALUE) + { + // + Add( + le1, + sls // + ); + } + + // + if (le2 != EMPTY_VALUE) + { + // + Add( + le2, + sls // + ); + } + } + else + { + // + Add( + atrUpper, + sls // + ); + + // // + // Add( + // peak, + // sls // + // ); + + // + if (bearishMomentumBar.IsValid()) + { + // + Add( + bearishMomentumBar.high, + sls // + ); + } + + // + // if (IsValidIndex(higherPeakIDX)) + // { + // // + // Add( + // higherPeak, + // sls // + // ); + // } + + // + if (se1 != EMPTY_VALUE) + { + // + Add( + se1, + sls // + ); + } + + // + if (se2 != EMPTY_VALUE) + { + // + Add( + se2, + sls // + ); + } + } + + // + double iAtr = decisionConditions.x121Conditions.atrBuffer[1]; + iAtr *= 2.5; + + // + double slsMin = GetMin(sls); + double slsMax = GetMax(sls); + + // + double sl = isBullish + ? slsMin - iAtr + : slsMax + iAtr; + double risk = MathAbs(entry - sl); + double riskInPoints = risk / points; + if (riskInPoints >= 150) + { + // + target = + isBullish + ? entry + (points * 200) + : entry - (points * 200); + + // + 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; + + // + // Cleanup Arrays ... + ArrayFree(triggerPoiEvents); + ArrayFree(triggerCycleEvents); + ArrayFree(decisionPoiEvents); + ArrayFree(decisionCycleEvents); + ArrayFree(analysePoiEvents); + ArrayFree(analyseCycleEvents); + ArrayFree(verificationPoiEvents); + ArrayFree(verificationCycleEvents); + ArrayFree(consolidationPoiEvents); + ArrayFree(consolidationCycleEvents); + ArrayFree(visionPoiEvents); + ArrayFree(visionCycleEvents); + + // + return result; +} + +// +bool DetectX121SMCXGuards( + X121SMCGuard &guards[], + const XPosition &positions[], + XC121SMCCycleHelper *triggerCycleHelper, + XC121SMCCycleHelper *decisionCycleHelper, + XC121SMCCycleHelper *analyseCycleHelper, + XC121SMCCycleHelper *verificationCycleHelper, + XC121SMCCycleHelper *consolidationCycleHelper, + XC121SMCCycleHelper *visionCycleHelper // +) +{ + // + bool result = false; + + // + string provider = ToString(X_121_SMC_PROVIDER_X); + + // + // result = DetectX121SMCGuards( + // provider, + // guards, + // positions, + // triggerCycleHelper, + // decisionCycleHelper, + // analyseCycleHelper, + // verificationCycleHelper, + // consolidationCycleHelper, + // visionCycleHelper // + // ); + + // + return result; +} + +// +int AddX121SMCXConditionsIfNotExists( + X121SMCStrategyXSignalConditions &item, + X121SMCStrategyXSignalConditions &items[], + int maxAllowed = 10 // +) +{ + // + int result = 0; + + // + bool isSetuped = IsValid(item.setupTime) && + HasDirection(item.dir); + if (!isSetuped) + { + return result; + } + + // + int count = ArraySize(items); + if (IsValidSize(count)) + { + // + // Copy Original Items ... + X121SMCStrategyXSignalConditions tmpItems[]; + Copy( + items, + tmpItems // + ); + + // + // Prese Item Data ... + bool isBullish = IsBullish(item.dir); + + // + for (int i = 0; i < count; i++) + { + // + X121SMCStrategyXSignalConditions iItem = tmpItems[i]; + + // + bool canRemove = item.dir == iItem.dir && + item.pivot == iItem.pivot; + if (canRemove) + { + // + ArrayRemove( + items, + i, + 1 // + ); + } + } + + // + Clean(tmpItems); + } + + // + AddRef( + item, + items // + ); + + // + // Remove Olds ... + CleanupArray( + items, + maxAllowed // + ); + + // + result = ArraySize(items); + + // + return result; +} + +// +int DrawX121SMCXConditions( + X121SMCStrategyXSignalConditions &conditions, + XCBaseObject *&drawnObjects[], + XCPOIDrawer *drawer // +) +{ + // + int result = 0; + + // + Clean(drawnObjects); + + // + if (drawer == NULL) + { + return result; + } + + // + bool isSetuped = conditions.IsSetuped(); + if (!isSetuped) + { + return result; + } + + // + return result; +} + +// diff --git a/Experts/x-saherelm.x-121.smc.ea.mq5 b/Experts/x-saherelm.x-121.smc.ea.mq5 index e78b3492..4044eb94 100644 --- a/Experts/x-saherelm.x-121.smc.ea.mq5 +++ b/Experts/x-saherelm.x-121.smc.ea.mq5 @@ -65,7 +65,7 @@ input string eaCloseAllTradesAt = ""; // Enable Close All Trades on Signals on T // // Risk Management ... input group "Risk Management"; -input double eaR2R = 3; // Signallers Risk to Reward Ratio +input double eaR2R = 2; // Signallers Risk to Reward Ratio input double eaVolume = 0.05; // Static Volume input double eaRiskPercentPerBalance = 0; // Risk Percent Per Balance in Each Trade input bool eaDynamicRiskManagement = false; // Dynamic Risk Management @@ -80,9 +80,9 @@ input int eaPauseSignallingAfterReachesMaxAllowedSLInSecconds = 7200; // Pause S // Protection ... input group "Protection"; input bool eaAllowHedging = true; // Allow Hedge Positions -input int eaMinOpenTradesFroHedging = 5; // Minimum Open Positions for Hedging +input int eaMinOpenTradesFroHedging = 4; // Minimum Open Positions for Hedging input double eaHedgingMinVolumeStep = 0.01; // Minimum Volume Step for Hedging -input double eaHedgeingMinRequiredProfitPerVolumeStep = 1.5; // Minimum Required Profit Per Volume Step for Hedging +input double eaHedgeingMinRequiredProfitPerVolumeStep = 2.0; // Minimum Required Profit Per Volume Step for Hedging // // Alert ... diff --git a/Helpers/x-saherelm.x121.helper.mq5 b/Helpers/x-saherelm.x121.helper.mq5 index 694daafd..31d48a97 100644 --- a/Helpers/x-saherelm.x121.helper.mq5 +++ b/Helpers/x-saherelm.x121.helper.mq5 @@ -199,10 +199,6 @@ struct X121Conditions double donCloseUpperBuffer[]; double donCloseLowerBuffer[]; - // - bool bullishTrendBuffer[]; - bool bearishTrendBuffer[]; - // double rsiSlope; double strSlope; @@ -497,14 +493,6 @@ struct X121Conditions bool isStrLowerCrossedOverDonLowLower; bool isStrLowerCrossedUnderDonLowLower; - // - bool isTrendBullish; - bool isTrendBearish; - - // - bool isTrendSwirchedToBullish; - bool isTrendSwirchedToBearish; - // bool isAtrUpperOverPeak; bool isAtrUpperEqualsToPeak; @@ -592,10 +580,6 @@ struct X121Conditions Clean(donCloseUpperBuffer); Clean(donCloseLowerBuffer); - // - Clean(bullishTrendBuffer); - Clean(bearishTrendBuffer); - // ArraySetAsSeries(rsiBuffer, true); ArraySetAsSeries(atrBuffer, true); @@ -647,10 +631,6 @@ struct X121Conditions ArraySetAsSeries(donCloseUpperBuffer, true); ArraySetAsSeries(donCloseLowerBuffer, true); - // - ArraySetAsSeries(bullishTrendBuffer, true); - ArraySetAsSeries(bearishTrendBuffer, true); - // cheMin = 0; cheMax = 0; @@ -1014,14 +994,6 @@ struct X121Conditions // isStrLowerCrossedOverDonLowLower = false; isStrLowerCrossedUnderDonLowLower = false; - - // - isTrendBullish = false; - isTrendBearish = false; - - // - isTrendSwirchedToBullish = false; - isTrendSwirchedToBearish = false; } /** @@ -1231,10 +1203,6 @@ struct X121Conditions "-----------------------" + separator + "Coplex ..." + separator + "-----------------------" + separator + - ToString("isTrendBullish", isTrendBullish, ignoreFalseConditions, separator) + - ToString("isTrendBearish", isTrendBearish, ignoreFalseConditions, separator) + - ToString("isTrendSwirchedToBullish", isTrendSwirchedToBullish, ignoreFalseConditions, separator) + - ToString("isTrendSwirchedToBearish", isTrendSwirchedToBearish, ignoreFalseConditions, separator) + ToString("isSarIncreased", isSarIncreased, ignoreFalseConditions, separator) + ToString("isSarDecreased", isSarDecreased, ignoreFalseConditions, separator) + ToString("isSarEqualsToPeak", isSarEqualsToPeak, ignoreFalseConditions, separator) + @@ -1944,18 +1912,6 @@ class XCX121Helper : public XCBase conditions.hLLBuffer // ); - // - Copy( - xpvConditions.bullishTrendBuffer, - conditions.bullishTrendBuffer // - ); - - // - Copy( - xpvConditions.bearishTrendBuffer, - conditions.bearishTrendBuffer // - ); - // // Conditions ... @@ -2368,20 +2324,6 @@ class XCX121Helper : public XCBase // // Complex Conditions ... - // - bool isTrendBullish = conditions.bullishTrendBuffer[0]; - bool isTrendBullishPrev = conditions.bullishTrendBuffer[1]; - - // - bool isTrendBearish = conditions.bearishTrendBuffer[0]; - bool isTrendBearishPrev = conditions.bearishTrendBuffer[1]; - - // - bool isTrendSwirchedToBullish = isTrendBullish && - !isTrendBullishPrev; - bool isTrendSwirchedToBearish = isTrendBearish && - !isTrendBearishPrev; - // double vwapFast = conditions.vwapFastBuffer[cIDX]; double vwapMid = conditions.vwapMidBuffer[cIDX]; @@ -2801,12 +2743,6 @@ class XCX121Helper : public XCBase conditions.vwapMin = vwapMin; conditions.vwapMax = vwapMax; - // - conditions.isTrendBullish = isTrendBullish; - conditions.isTrendBearish = isTrendBearish; - conditions.isTrendSwirchedToBullish = isTrendSwirchedToBullish; - conditions.isTrendSwirchedToBearish = isTrendSwirchedToBearish; - // conditions.isSarIncreased = isSarIncreased; conditions.isSarDecreased = isSarDecreased; diff --git a/Helpers/x-saherelm.x121.xpv.helper.mq5 b/Helpers/x-saherelm.x121.xpv.helper.mq5 index d42b8849..6840ca5c 100644 --- a/Helpers/x-saherelm.x121.xpv.helper.mq5 +++ b/Helpers/x-saherelm.x121.xpv.helper.mq5 @@ -270,10 +270,6 @@ struct X121XPVConditions double hHHBuffer[]; double hLLBuffer[]; - // - bool bullishTrendBuffer[]; - bool bearishTrendBuffer[]; - // // Conditions ... @@ -345,8 +341,8 @@ struct X121XPVConditions Clean(hLLBuffer); // - Clean(bullishTrendBuffer); - Clean(bearishTrendBuffer); + // Clean(bullishTrendBuffer); + // Clean(bearishTrendBuffer); // ArraySetAsSeries(peaksBuffer, true); @@ -363,10 +359,6 @@ struct X121XPVConditions ArraySetAsSeries(hHHBuffer, true); ArraySetAsSeries(hLLBuffer, true); - // - ArraySetAsSeries(bullishTrendBuffer, true); - ArraySetAsSeries(bearishTrendBuffer, true); - // // Conditions ... @@ -1612,107 +1604,6 @@ class XCX121XPVHelper : public XCBaseHelper ); } - // - // Trends ... - - // // - // bool GetBullishTrend( - // int barIndex // Bar Index - // ) - // { - // // - // if (barIndex < 0) - // { - // barIndex = 0; - // } - - // // - // Calculate(); - - // // - // int count = ArraySize(bullishTrendBuffer); - // if (barIndex >= count) - // { - // barIndex = count - 1; - // } - - // // - // return bullishTrendBuffer[barIndex]; - // } - - // // - // int CopyBullishTrend( - // int start, // Start - // int count, // Number of Items for read - // bool &buffer[], // Dest Buffer - // bool forceClean = true // Force To Clean buffer - // ) - // { - // // - // // Update Calculations ... - // Calculate(); - - // // - // // Copy Items ... - // return Copy( - // start, - // count, - // bullishTrendBuffer, - // buffer, - // forceClean - // // - // ); - // } - - // // - // bool GetBearishTrend( - // int barIndex // Bar Index - // ) - // { - // // - // if (barIndex < 0) - // { - // barIndex = 0; - // } - - // // - // Calculate(); - - // // - // int count = ArraySize(bearishTrendBuffer); - // if (barIndex >= count) - // { - // barIndex = count - 1; - // } - - // // - // return bearishTrendBuffer[barIndex]; - // } - - // // - // int CopyBearishTrend( - // int start, // Start - // int count, // Number of Items for read - // bool &buffer[], // Dest Buffer - // bool forceClean = true // Force To Clean buffer - // ) - // { - // // - // // Update Calculations ... - // Calculate(); - - // // - // // Copy Items ... - // return Copy( - // start, - // count, - // bearishTrendBuffer, - // buffer, - // forceClean - // // - // ); - // } - // // Tools Function ... @@ -1936,191 +1827,6 @@ class XCX121XPVHelper : public XCBaseHelper return result; } - /** - * Detect Market Structure Method 2 ... - * - * @param model: XMarketStructure instance Reference ... - * - * @return ( bool ) - */ - bool DetectMarketStructure( - ENUM_X_DIRECTION &dir, - int pivotsCount = 3 // - ) - { - // - bool result = false; - - // - int barIndex = 0; - - // - if (pivotsCount < 3) - { - pivotsCount = 3; - } - - // - dir = X_DIRECTION_NONE; - string symbol = GetSymbol(); - ENUM_TIMEFRAMES period = GetPeriod(); - - // - int hpIndex = -1; - int hpIndexes[]; - double hpValues[]; - - // - int lvIndex = -1; - int lvIndexes[]; - double lvValues[]; - - // - for (int i = 0; i < pivotsCount; i++) - { - // - hpIndex = barIndex; - lvIndex = barIndex; - - // - double lastHP = 0; - double lastLV = 0; - - // - int hpCount = ArraySize(hpIndexes); - int lvCount = ArraySize(lvIndexes); - - // - if (IsValidSize(hpCount)) - { - // - lastHP = hpValues[hpCount - 1]; - hpIndex = hpIndexes[hpCount - 1]; - } - - // - if (IsValidSize(lvCount)) - { - // - lastLV = lvValues[lvCount - 1]; - lvIndex = lvIndexes[lvCount - 1]; - } - - // - if (lastHP == 0) - { - // - lastHP = GetPeak(hpIndex); - } - - // - if (lastLV == 0) - { - // - lastLV = GetVale(lvIndex); - } - - // - int highestPeakIndex = -1; - double highesrPeak = - GetHigherPeak( - highestPeakIndex, - lastHP, - hpIndex // - ); - if (IsValidIndex(highestPeakIndex)) - { - // - Add( - highestPeakIndex, - hpIndexes // - ); - - // - Add( - highesrPeak, - hpValues // - ); - } - - // - int lowestValeIndex = -1; - double lowestVale = - GetLowerVale( - lowestValeIndex, - lastLV, - lvIndex // - ); - if (IsValidIndex(lowestValeIndex)) - { - // - Add( - lowestValeIndex, - lvIndexes // - ); - - // - Add( - lowestVale, - lvValues // - ); - } - - // - bool canBreak = ArraySize(hpIndexes) >= pivotsCount || - ArraySize(lvIndexes) >= pivotsCount; - if (canBreak) - { - break; - } - } - - // - ArrayReverse(hpValues); - ArrayReverse(hpIndexes); - int countHPs = ArraySize(hpIndexes); - - // - ArrayReverse(lvValues); - ArrayReverse(lvIndexes); - int countLVs = ArraySize(lvIndexes); - - // - bool isValidHPs = countHPs >= pivotsCount; - bool isValidLVs = countLVs >= pivotsCount; - - // - result = isValidHPs || - isValidLVs; - if (!result) - { - return result; - } - - // - if (isValidHPs && isValidLVs) - { - // - hpIndex = hpIndexes[countHPs - 1]; - lvIndex = lvIndexes[countLVs - 1]; - } - - // - dir = - !isValidHPs && isValidLVs - ? X_DIRECTION_BULLISH - : !isValidLVs && isValidHPs - ? X_DIRECTION_BEARISH - : hpIndex < lvIndex - ? X_DIRECTION_BEARISH - : lvIndex < hpIndex - ? X_DIRECTION_BULLISH - : X_DIRECTION_ALL; - - // - return result; - } - // bool GetConditions( X121XPVConditions &conditions, // @@ -2281,48 +1987,6 @@ class XCX121XPVHelper : public XCBaseHelper conditions.hLLBuffer // ); - // // - // CopyBullishTrend( - // zIndex, - // loopback, - // conditions.bullishTrendBuffer // - // ); - - // // - // CopyBearishTrend( - // zIndex, - // loopback, - // conditions.bearishTrendBuffer // - // ); - - // - for (int i = barIndex + 1; i < barIndex + 3; i++) - { - // - ENUM_X_DIRECTION iDirection; - bool iHasDirection = DetectMarketStructure(iDirection); - - // - bool iHasBullishTrend = iHasDirection && - IsBullish(iDirection); - - // - bool iHasBearishTrend = iHasDirection && - IsBearish(iDirection); - - // - Add( - iHasBullishTrend, - conditions.bullishTrendBuffer // - ); - - // - Add( - iHasBearishTrend, - conditions.bearishTrendBuffer // - ); - } - // // Conditions ... @@ -2400,11 +2064,6 @@ class XCX121XPVHelper : public XCBaseHelper conditions.isRejectedPrevVale = isRejectedPrevVale; conditions.isBreakedDownPrevVale = isBreakedDownPrevVale; - // // - // if (isNewVale || isNewPeak) { - // CalculateTrend(); - // } - // return result; } @@ -2435,29 +2094,6 @@ class XCX121XPVHelper : public XCBaseHelper double hHHBuffer[]; double hLLBuffer[]; - // - // bool bullishTrendBuffer[]; - // bool bearishTrendBuffer[]; - - // - // void AddTrend( - // bool isBullish, - // bool isBearish // - // ) - // { - // // - // Add( - // isBullish, - // bullishTrendBuffer // - // ); - - // // - // Add( - // isBearish, - // bearishTrendBuffer // - // ); - // } - // void Calculate() { @@ -2632,28 +2268,6 @@ class XCX121XPVHelper : public XCBaseHelper // ); } - - // - // void CalculateTrend() - // { - // // - // ENUM_X_DIRECTION iDirection; - // bool iHasDirection = DetectMarketStructure(iDirection); - - // // - // bool iHasBullishTrend = iHasDirection && - // IsBullish(iDirection); - - // // - // bool iHasBearishTrend = iHasDirection && - // IsBearish(iDirection); - - // // - // AddTrend( - // iHasBullishTrend, - // iHasBearishTrend // - // ); - // } }; // 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 181d6666..0ae3f1ca 100644 --- a/X121SMCEA/Classes/x-121.smc.market.cycle.helper.class.mq5 +++ b/X121SMCEA/Classes/x-121.smc.market.cycle.helper.class.mq5 @@ -359,6 +359,199 @@ class XC121SMCCycleHelper : public XCBase return result; } + /** + * Detect Market Structure Method 2 ... + * + * @param model: XMarketStructure instance Reference ... + * + * @return ( bool ) + */ + bool DetectMarketStructure( + ENUM_X_DIRECTION &dir, + int pivotsCount = 3 // + ) + { + // + bool result = false; + + // + int barIndex = 0; + + // + if (pivotsCount < 3) + { + pivotsCount = 3; + } + + // + dir = X_DIRECTION_NONE; + string symbol = GetSymbol(); + ENUM_TIMEFRAMES period = GetPeriod(); + + // + int hpIndex = -1; + int hpIndexes[]; + double hpValues[]; + + // + int lvIndex = -1; + int lvIndexes[]; + double lvValues[]; + + // + for (int i = 0; i < pivotsCount; i++) + { + // + hpIndex = barIndex; + lvIndex = barIndex; + + // + double lastHP = 0; + double lastLV = 0; + + // + int hpCount = ArraySize(hpIndexes); + int lvCount = ArraySize(lvIndexes); + + // + if (IsValidSize(hpCount)) + { + // + lastHP = hpValues[hpCount - 1]; + hpIndex = hpIndexes[hpCount - 1]; + } + + // + if (IsValidSize(lvCount)) + { + // + lastLV = lvValues[lvCount - 1]; + lvIndex = lvIndexes[lvCount - 1]; + } + + // + if (lastHP == 0) + { + // + lastHP = mX121Helper + .xpvHelper + .GetPeak(hpIndex); + } + + // + if (lastLV == 0) + { + // + lastLV = mX121Helper + .xpvHelper + .GetVale(lvIndex); + } + + // + int highestPeakIndex = -1; + double highesrPeak = + mX121Helper + .xpvHelper + .GetHigherPeak( + highestPeakIndex, + lastHP, + hpIndex // + ); + if (IsValidIndex(highestPeakIndex)) + { + // + Add( + highestPeakIndex, + hpIndexes // + ); + + // + Add( + highesrPeak, + hpValues // + ); + } + + // + int lowestValeIndex = -1; + double lowestVale = + mX121Helper + .xpvHelper + .GetLowerVale( + lowestValeIndex, + lastLV, + lvIndex // + ); + if (IsValidIndex(lowestValeIndex)) + { + // + Add( + lowestValeIndex, + lvIndexes // + ); + + // + Add( + lowestVale, + lvValues // + ); + } + + // + bool canBreak = ArraySize(hpIndexes) >= pivotsCount || + ArraySize(lvIndexes) >= pivotsCount; + if (canBreak) + { + break; + } + } + + // + ArrayReverse(hpValues); + ArrayReverse(hpIndexes); + int countHPs = ArraySize(hpIndexes); + + // + ArrayReverse(lvValues); + ArrayReverse(lvIndexes); + int countLVs = ArraySize(lvIndexes); + + // + bool isValidHPs = countHPs >= pivotsCount; + bool isValidLVs = countLVs >= pivotsCount; + + // + result = isValidHPs || + isValidLVs; + if (!result) + { + return result; + } + + // + if (isValidHPs && isValidLVs) + { + // + hpIndex = hpIndexes[countHPs - 1]; + lvIndex = lvIndexes[countLVs - 1]; + } + + // + dir = + !isValidHPs && isValidLVs + ? X_DIRECTION_BULLISH + : !isValidLVs && isValidHPs + ? X_DIRECTION_BEARISH + : hpIndex < lvIndex + ? X_DIRECTION_BEARISH + : lvIndex < hpIndex + ? X_DIRECTION_BULLISH + : X_DIRECTION_ALL; + + // + return result; + } + /** * Retrieve Cycle Conditions ... * diff --git a/X121SMCEA/Libraries/x-121.smc.guard.lib.mq5 b/X121SMCEA/Libraries/x-121.smc.guard.lib.mq5 index 82f916e8..1050ca61 100644 --- a/X121SMCEA/Libraries/x-121.smc.guard.lib.mq5 +++ b/X121SMCEA/Libraries/x-121.smc.guard.lib.mq5 @@ -309,18 +309,48 @@ bool DetectX121SMCGuards( // // Trigger ... - bool hasTriggerBullishTrend = triggerXConditions.bullishTrendBuffer[1]; - bool hasTriggerBearishTrend = triggerXConditions.bearishTrendBuffer[1]; + ENUM_X_DIRECTION triggerTrendDir; + bool hasTriggerTrend = + triggerCycleHelper + .DetectMarketStructure( + triggerTrendDir // + ); + bool hasTriggerBullishTrend = + hasTriggerTrend && + IsBullish(triggerTrendDir); + bool hasTriggerBearishTrend = + hasTriggerTrend && + IsBearish(triggerTrendDir); // // Decision ... - bool hasDecisionBullishTrend = decisionXConditions.bullishTrendBuffer[1]; - bool hasDecisionBearishTrend = decisionXConditions.bearishTrendBuffer[1]; + ENUM_X_DIRECTION decisionTrendDir; + bool hasDecisionTrend = + decisionCycleHelper + .DetectMarketStructure( + decisionTrendDir // + ); + bool hasDecisionBullishTrend = + hasDecisionTrend && + IsBullish(decisionTrendDir); + bool hasDecisionBearishTrend = + hasDecisionTrend && + IsBearish(decisionTrendDir); // // Analyse ... - bool hasAnalyseBullishTrend = analyseXConditions.bullishTrendBuffer[1]; - bool hasAnalyseBearishTrend = analyseXConditions.bearishTrendBuffer[1]; + ENUM_X_DIRECTION analyseTrendDir; + bool hasAnalyseTrend = + analyseCycleHelper + .DetectMarketStructure( + analyseTrendDir // + ); + bool hasAnalyseBullishTrend = + hasAnalyseTrend && + IsBullish(analyseTrendDir); + bool hasAnalyseBearishTrend = + hasAnalyseTrend && + IsBearish(analyseTrendDir); // // Consolidation Zone ... diff --git a/X121SMCEA/Libraries/x-121.smc.lib.mq5 b/X121SMCEA/Libraries/x-121.smc.lib.mq5 index a4308927..6d27c414 100644 --- a/X121SMCEA/Libraries/x-121.smc.lib.mq5 +++ b/X121SMCEA/Libraries/x-121.smc.lib.mq5 @@ -35,7 +35,7 @@ const string X121SMCStrategyToken = "X121SMC"; // -const string X121SMCXTestToken = "X121XTest"; +const string X121SMCXToken = "X121X"; const string X121SMCXPZToken = "X121XPZ"; const string X121SMCXRSPVIToken = "X121XRSPVI"; const string X121SMCXSTRPVToken = "X121XSTRPV"; @@ -46,7 +46,7 @@ enum ENUM_X_121_SMC_PROVIDERS { // X_121_SMC_PROVIDER_NONE, - X_121_SMC_PROVIDER_XTEST, + X_121_SMC_PROVIDER_X, X_121_SMC_PROVIDER_XPZ, X_121_SMC_PROVIDER_XRSPVI, X_121_SMC_PROVIDER_XSTRPV, @@ -704,8 +704,8 @@ string ToString(ENUM_X_121_SMC_PROVIDERS value) switch (value) { // - case X_121_SMC_PROVIDER_XTEST: - result = X121SMCXTestToken; + case X_121_SMC_PROVIDER_X: + result = X121SMCXToken; break; // @@ -747,9 +747,9 @@ ENUM_X_121_SMC_PROVIDERS ParseProvider(string value) } // - if (Contains(X121SMCXTestToken, value)) + if (Contains(X121SMCXToken, value)) { - result = X_121_SMC_PROVIDER_XTEST; + result = X_121_SMC_PROVIDER_X; } else if (Contains(X121SMCXPZToken, value)) { diff --git a/X121SMCEA/Signals/x-121.smc.x.signal.lib.mq5 b/X121SMCEA/Signals/x-121.smc.x.signal.lib.mq5 new file mode 100644 index 00000000..16ae57f9 --- /dev/null +++ b/X121SMCEA/Signals/x-121.smc.x.signal.lib.mq5 @@ -0,0 +1,2457 @@ +/////////////////////////////////////////////////////// +// +// SaherElm IT Center MQL5 X121 SMC Signal Class +// ------------------------------------------------- +// Name: X +// Description: provide all Signalling functions ... +// +// +// Maintainer: +// ------------ +// Hadi Khazaee Asl (hadi_khazaee_asl@yahoo.com) +// +////////////////////////////////////////////////////// +// +// Global Properties ... +#property library +#property copyright "Copyright 2023, SaherElm IT Center" +#property link "https://www.saherelm.ir" +#property version "1.00" +#property strict + +// +// Imports ... +// #include "../../Libraries/x-trade.lib" +#include "../Classes/x-121.smc.market.cycle.helper.class.mq5" +#include "../Libraries/x-121.smc.lib.mq5" + +// +// Definitions ... +struct X121SMCStrategyXSignalConditions +{ + // + // 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; + + // + double pivot; + double point; + + // + double peak; + datetime peakTime; + + // + double higherPeak; + datetime higherPeakTime; + + // + double vale; + datetime valeTime; + + // + double lowerVale; + datetime lowerValeTime; + + // + ENUM_XPV_PIVOTS pvType; + + // + XPVPivot pivotZone; + + // + // Constructor ... + X121SMCStrategyXSignalConditions() + { + 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() + { + // + pivot = 0; + point = 0; + + // + pvType = XPV_NONE; + + // + peak = 0; + peakTime = NULL; + + // + higherPeak = 0; + higherPeakTime = NULL; + + // + vale = 0; + valeTime = NULL; + + // + lowerVale = 0; + lowerValeTime = NULL; + + // + pivotZone.Clean(); + } + + // + bool HasPeak() + { + // + bool result = false; + + // + result = + peak > 0 && + IsValid(peakTime); + + // + return result; + } + + // + bool HasHigherPeak() + { + // + bool result = false; + + // + result = + higherPeak > 0 && + IsValid(higherPeakTime); + + // + return result; + } + + // + bool HasVale() + { + // + bool result = false; + + // + result = + vale > 0 && + IsValid(valeTime); + + // + return result; + } + + // + bool HasLowerVale() + { + // + bool result = false; + + // + result = + lowerVale > 0 && + IsValid(lowerValeTime); + + // + return result; + } + + // +}; + +// +// Signaller Data Sources ... +X121SMCStrategyXSignalConditions mXConditions; +X121SMCStrategyXSignalConditions mXConditionsCollection[]; + +// +// Extension Functions ... + +// +// Detect Setup Conditions ... +bool DetectX121SMCXSiganlSetup( + string _symbol, + ENUM_TIMEFRAMES _period, + // + X121SMCStrategyXSignalConditions &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 = decisionCycleHelper.GetBar( + zBar, + zIndex // + ); + // zBar.Init( + // symbol, + // period, + // zIndex // + // ); + if (!result) + { + return result; + } + + // + XOHCL cBar; + result = decisionCycleHelper.GetBar( + cBar, + cIndex // + ); + // cBar.Init( + // symbol, + // period, + // cIndex // + // ); + if (!result) + { + return result; + } + + // + XOHCL pBar; + result = decisionCycleHelper.GetBar( + pBar, + pIndex // + ); + // 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 = 3; + 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; + + // + // Cycle X121Conditions ... + X121Conditions triggerXConditions = triggerConditions.x121Conditions; + X121Conditions decisionXConditions = decisionConditions.x121Conditions; + X121Conditions analyseXConditions = analyseConditions.x121Conditions; + X121Conditions verificationXConditions = verificationConditions.x121Conditions; + X121Conditions consolidationXConditions = consolidationConditions.x121Conditions; + X121Conditions visionXConditions = visionConditions.x121Conditions; + + // + // Setup Conditions ... + + // + // Detect Trend ... + + // + // Consolidation ... + ENUM_X_DIRECTION consolidationTrendDir; + bool hasConsolidationTrend = + consolidationCycleHelper + .DetectMarketStructure( + consolidationTrendDir // + ); + bool hasConsolidationBullishTrend = + hasConsolidationTrend && + IsBullish(consolidationTrendDir); + bool hasConsolidationBearishTrend = + hasConsolidationTrend && + IsBearish(consolidationTrendDir); + + // + // Verification ... + ENUM_X_DIRECTION verificationTrendDir; + bool hasVerificationTrend = + verificationCycleHelper + .DetectMarketStructure( + verificationTrendDir // + ); + bool hasVerificationBullishTrend = + hasVerificationTrend && + IsBullish(verificationTrendDir); + bool hasVerificationBearishTrend = + hasVerificationTrend && + IsBearish(verificationTrendDir); + + // + // Analyse ... + ENUM_X_DIRECTION analyseTrendDir; + bool hasAnalyseTrend = + analyseCycleHelper + .DetectMarketStructure( + analyseTrendDir // + ); + bool hasAnalyseBullishTrend = + hasAnalyseTrend && + IsBullish(analyseTrendDir); + bool hasAnalyseBearishTrend = + hasAnalyseTrend && + IsBearish(analyseTrendDir); + + // + // Decision ... + ENUM_X_DIRECTION decisionTrendDir; + bool hasDecisionTrend = + decisionCycleHelper + .DetectMarketStructure( + decisionTrendDir // + ); + bool hasDecisionBullishTrend = + hasDecisionTrend && + IsBullish(decisionTrendDir); + bool hasDecisionBearishTrend = + hasDecisionTrend && + IsBearish(decisionTrendDir); + + // + // Detect Bar State ... + + // + // PinBar ... + ENUM_X_DIRECTION cBarPinDir; + bool isCBarPin = decisionCycleHelper + .mBarAnalyser + .IsPinBar( + cBar, + cBarPinDir, + 1 // + ); + bool isCBarBullishPin = + isCBarPin && + IsBullish(cBarPinDir); + bool isCBarBearishPin = + isCBarPin && + IsBearish(cBarPinDir); + + // + // Engulf ... + ENUM_X_DIRECTION cBarEngulfDir; + bool isCBarEngulfed = decisionCycleHelper + .mBarAnalyser + .IsEngulfBar( + cBar, + cBarEngulfDir, + 0 // Extended ... + ); + bool isCBarBullishEngulfed = + isCBarEngulfed && + IsBullish(cBarEngulfDir); + bool isCBarBearishEngulfed = + isCBarEngulfed && + IsBearish(cBarEngulfDir); + + // + // Momentum ... + ENUM_X_DIRECTION cBarMomentumDir; + bool isCBarMomentum = decisionCycleHelper + .mBarAnalyser + .IsMomentumBar( + cBar, + cBarMomentumDir, + 0 // Extended ... + ); + bool isCBarBullishMomentum = + isCBarMomentum && + IsBullish(cBarMomentumDir); + bool isCBarBearishMomentum = + isCBarMomentum && + IsBearish(cBarMomentumDir); + + // + // Reject ... + ENUM_X_DIRECTION cBarRejectDir; + bool isCBarRejected = decisionCycleHelper + .mBarAnalyser + .IsRejectionBar( + cBar, + cBarRejectDir, + 0 // Extended ... + ); + bool isCBarBullishRejected = + isCBarRejected && + IsBullish(cBarRejectDir); + bool isCBarBearishRejected = + isCBarRejected && + IsBearish(cBarRejectDir); + + // + // Pull Back ... + ENUM_X_DIRECTION cBarPullbackDir; + bool isCBarPullbacked = + decisionCycleHelper + .mBarAnalyser + .HasPullBack( + cBarPullbackDir, + cBar // + ); + bool isCBarBullishPullbacked = + isCBarPullbacked && + IsBullish(cBarPullbackDir); + bool isCBarBearishPullbacked = + isCBarPullbacked && + IsBearish(cBarPullbackDir); + + // + // HH/LL Break ... + + // + bool isCBarBreaksUpHH = IsBarBreak( + hh, + X_DIRECTION_BULLISH, + cBar // + ); + + // + bool isCBarBreaksDownLL = IsBarBreak( + hh, + X_DIRECTION_BEARISH, + cBar // + ); + + // + // Bars Pattern and Power and Pressures ... + + // + bool hasCBarBullishPattern = + decisionCycleHelper + .mBarAnalyser + .HasBullishPattern( + cBar, + 2 // + ); + + // + bool hasCBarBearishPattern = + decisionCycleHelper + .mBarAnalyser + .HasBearishPattern( + cBar, + 2 // + ); + + // + bool isCBarHasBullishPower = + decisionCycleHelper + .mBarAnalyser + .HasBullishPower( + cBar, + 2 // + ); + + // + bool isCBarHasBearishPower = + decisionCycleHelper + .mBarAnalyser + .HasBearishPower( + cBar, + 2 // + ); + + // + bool isCBarHasBullishPressure = + decisionCycleHelper + .mBarAnalyser + .HasBullishPressure( + cBar, + 2 // + ); + + // + bool isCBarHasBearishPressure = + decisionCycleHelper + .mBarAnalyser + .HasBearishPressure( + cBar, + 2 // + ); + + // + // Bar Checking Summary ... + + // + // Bullish ... + bool isCBarBullishFormed = + // + ( + // + hasCBarBullishPattern && + isCBarHasBullishPower && + isCBarHasBullishPressure + // + ) + // + || + // + ( + // + isCBarBullishPin || + isCBarBreaksUpHH || + isCBarBullishEngulfed || + isCBarBullishMomentum || + isCBarBullishRejected + // + ) + // + ; + + // + // Bearish ... + bool isCBarBearishFormed = + // + ( + // + hasCBarBearishPattern && + isCBarHasBearishPower && + isCBarHasBearishPressure + // + ) + // + || + // + ( + // + isCBarBearishPin || + isCBarBreaksDownLL || + isCBarBearishEngulfed || + isCBarBearishMomentum || + isCBarBearishRejected + // + ) + // + ; + + // + // Detect Pivot ... + + // + double pivotPremiumDiscount = 0; + + // + bool isPivotUpperUpBreaked = false; + bool isPivotUpperDownBreaked = false; + bool isPivotUpperDownRejected = false; + + // + bool isPivotLowerUpBreaked = false; + bool isPivotLowerUpRejected = false; + bool isPivotLowerDownBreaked = false; + + // + bool isPriceInPivotPremium = false; + bool isPriceInPivotDiscount = false; + + // + bool isPivotPremiumUpBreaked = false; + bool isPivotPremiumDownBreaked = false; + bool isPivotPremiumUpRejected = false; + bool isPivotPremiumDownRejected = false; + + // + bool isPivotDiscountUpBreaked = false; + bool isPivotDiscountDownBreaked = false; + bool isPivotDiscountUpRejected = false; + bool isPivotDiscountDownRejected = false; + + // + bool hasPivot = conditions.pivotZone.IsValid(); + + // + if (!hasPivot) + { + // + bool hasPeak = conditions.HasPeak(); + bool hasVale = conditions.HasVale(); + + // + int higherPeakIDX = -1; + int higherPeakStartIDX = -1; + datetime higherPeakTime = NULL; + double higherPeak = decisionCycleHelper + .mX121Helper + .xpvHelper + .GetHigherPeak( + higherPeakIDX, + decisionXConditions.peaksBuffer[1] // + ); + bool hasHigherPeak = + higherPeak > 0 && + IsValidIndex(higherPeakIDX); + if (hasHigherPeak) + { + // + // Detect Higher Peak Start Index ... + int idx = higherPeakIDX; + bool canContinue = true; + while (canContinue) + { + // + double iPeak = decisionCycleHelper + .mX121Helper + .xpvHelper + .GetPeak(idx); + canContinue = iPeak == higherPeak; + if (!canContinue) + { + break; + } + + // + idx++; + } + + // + if (idx > higherPeakIDX) + { + higherPeakStartIDX = idx - 1; + } + } + + // + int lowerValeIDX = -1; + int lowerValeStartIDX = -1; + datetime lowerValeTime = NULL; + double lowerVale = decisionCycleHelper + .mX121Helper + .xpvHelper + .GetLowerVale( + lowerValeIDX, + decisionXConditions.valesBuffer[1] // + ); + bool hasLowerVale = + lowerVale > 0 && + IsValidIndex(lowerValeIDX); + if (hasLowerVale) + { + // + // Detect Lower Vale Start Index ... + int idx = lowerValeIDX; + bool canContinue = true; + while (canContinue) + { + // + double iVale = decisionCycleHelper + .mX121Helper + .xpvHelper + .GetVale(idx); + canContinue = iVale == lowerVale; + if (!canContinue) + { + break; + } + + // + idx++; + } + + // + if (idx > lowerValeIDX) + { + lowerValeStartIDX = idx - 1; + } + } + + // + // Now we Have to Detect Higher Peak and Lower Vale + // Zones ... + + // + if (hasHigherPeak) + { + // + XOHCL higherPeakStartBar; + bool isInited = higherPeakStartBar.Init( + symbol, + period, + higherPeakStartIDX // + ); + if (isInited) + { + higherPeakTime = higherPeakStartBar.time; + } + } + + // + if (hasLowerVale) + { + // + XOHCL lowerValeStartBar; + bool isInited = lowerValeStartBar.Init( + symbol, + period, + lowerValeStartIDX // + ); + if (isInited) + { + lowerValeTime = lowerValeStartBar.time; + } + } + + // + bool isNewPeak = + !hasPeak && + hasLowerVale && + hasHigherPeak && + decisionXConditions.isNewPeakUnderLast; + if (isNewPeak) + { + // + conditions.pvType = XPV_PEAK; + + // + conditions.peakTime = cTime; + conditions.peak = decisionXConditions.peaksBuffer[1]; + + // + conditions.higherPeakTime = higherPeakTime; + conditions.higherPeak = higherPeak; + + // + conditions.valeTime = cTime; + conditions.vale = decisionXConditions.valesBuffer[1]; + + // + conditions.lowerValeTime = lowerValeTime; + conditions.lowerVale = lowerVale; + + // + hasPeak = conditions.HasPeak(); + hasVale = conditions.HasVale(); + } + + // + bool isNewVale = + !hasVale && + !isNewPeak && + hasLowerVale && + hasHigherPeak && + decisionXConditions.isNewValeOverLast; + if (isNewVale) + { + // + conditions.pvType = XPV_PEAK; + + // + conditions.peakTime = cTime; + conditions.peak = decisionXConditions.peaksBuffer[1]; + + // + conditions.higherPeakTime = higherPeakTime; + conditions.higherPeak = higherPeak; + + // + conditions.valeTime = cTime; + conditions.vale = decisionXConditions.valesBuffer[1]; + + // + conditions.lowerValeTime = lowerValeTime; + conditions.lowerVale = lowerVale; + + // + hasPeak = conditions.HasPeak(); + hasVale = conditions.HasVale(); + } + + // + if (isNewPeak || isNewVale) + { + // + Print("Pivot ..."); + + // + XPVPivot pivot; + + // + pivot.symbol = symbol; + pivot.period = period; + + // + pivot.repetition = MathMax( + higherPeakIDX, + lowerValeIDX // + ); + pivot.type = conditions.pvType; + + // + pivot.upper = higherPeak; + pivot.lower = lowerVale; + + // + bool isHigherPeakOlder = + conditions.higherPeakTime < conditions.lowerValeTime; + + // + pivot.to = cTime; + pivot.from = + isHigherPeakOlder + ? conditions.higherPeakTime + : conditions.lowerValeTime; + + // + pivot.type = + isHigherPeakOlder + ? XPV_PEAK + : XPV_VALE; + + // + hasPivot = pivot.IsValid(); + if (hasPivot) + { + conditions.pivotZone = pivot; + } + + // + } + + // + // Has Pivot ... + hasPivot = conditions.pivotZone.IsValid(); + } + + // + if (hasPivot) + { + // + // Check Pivot Validation ... + + // + bool isPivotDied = + // + (cBar.low > conditions.pivotZone.upper && + cBar.close > conditions.pivotZone.upper) + // + || + // + (cBar.high < conditions.pivotZone.lower && + cBar.close < conditions.pivotZone.lower) + // + ; + if (isPivotDied) + { + conditions.Clean(); + } + + // + hasPivot = conditions.pivotZone.IsValid(); + if (hasPivot) + { + // + // Detect Pivot States ... + + // + XPOIState analysePivotState; + DetectPivotPOIs( + conditions.pivotZone, + analyseState, + analysePivotState // + ); + + // + XPOIState decisionPivotState; + DetectPivotPOIs( + conditions.pivotZone, + decisionState, + decisionPivotState // + ); + + // + // Combine two State ... + XPOIState combinedPivotState; + XPOIState iStates[]; + // AddRef( + // analysePivotState, + // iStates // + // ); + AddRef( + decisionPivotState, + iStates // + ); + CombineStates( + combinedPivotState, + iStates // + ); + combinedPivotState = decisionPivotState; + + // + ArrayFree(iStates); + + // + combinedPivotState.time = decisionPivotState.time; + combinedPivotState.symbol = decisionPivotState.symbol; + combinedPivotState.period = decisionPivotState.period; + + // + // Hold Only Areas Which on Upper or Lower bondary of Pivot Zone ... + FilterPivotState( + conditions.pivotZone, + combinedPivotState // + ); + + // + conditions.pivotZone.state = combinedPivotState; + + // + // Calculate Pivot Ticks Zone ... + + // + int ticksLevels = decisionCycleHelper + .mPOIDetector + .TicksRangeZoneLevel(); + int ticksRange = decisionCycleHelper + .mPOIDetector + .TicksRangeZoneRange(); + + // + CalculatePivotTickZone( + conditions.pivotZone, + ticksLevels, + ticksRange // + ); + + // + // Try to Fill up Pivot Conditions ... + + // + XOHCL pivotCBar; + bool isCInited = triggerCycleHelper.GetBar( + pivotCBar, + cIndex // + ); + + // + XOHCL pivotPBar; + bool isPInited = triggerCycleHelper.GetBar( + pivotPBar, + pIndex // + ); + + // + double upper = conditions.pivotZone.upper; + double lower = conditions.pivotZone.lower; + pivotPremiumDiscount = conditions.pivotZone.CalculateMid(); + + // + // Pivot Upper ... + + // + isPivotUpperUpBreaked = + isCInited && + IsBarBreak( + upper, + X_DIRECTION_BULLISH, + pivotCBar // + ); + + // + isPivotUpperDownBreaked = + isCInited && + IsBarBreak( + upper, + X_DIRECTION_BEARISH, + pivotCBar // + ); + + // + isPivotUpperDownRejected = + isCInited && + IsBarReject( + upper, + X_DIRECTION_BEARISH, + pivotCBar // + ); + + // + // Pivot Lower ... + + // + isPivotLowerUpBreaked = + isCInited && + IsBarBreak( + lower, + X_DIRECTION_BULLISH, + pivotCBar // + ); + + // + isPivotLowerUpRejected = + isCInited && + IsBarReject( + lower, + X_DIRECTION_BULLISH, + pivotCBar // + ); + + // + isPivotLowerDownBreaked = + isCInited && + IsBarBreak( + lower, + X_DIRECTION_BEARISH, + pivotCBar // + ); + + // + // Pivot Premium / Discount ... + + // + bool isPriceInPivotPremium = + isCInited && + ask < upper && + bid < upper && + ask > pivotPremiumDiscount && + bid > pivotPremiumDiscount; + + // + bool isPriceInPivotDiscount = + isCInited && + ask > lower && + bid > lower && + ask < pivotPremiumDiscount && + bid < pivotPremiumDiscount; + + // + // + // + + // + isPivotPremiumUpBreaked = + isCInited && + isPInited && + IsBarBreak( + pivotPremiumDiscount, + X_DIRECTION_BULLISH, + pivotCBar // + ) && + pivotPBar.high > pivotPremiumDiscount; + + // + isPivotPremiumDownBreaked = + isCInited && + isPInited && + IsBarBreak( + pivotPremiumDiscount, + X_DIRECTION_BEARISH, + pivotCBar // + ) && + pivotPBar.high > pivotPremiumDiscount; + + // + isPivotPremiumUpRejected = + isCInited && + isPInited && + IsBarReject( + pivotPremiumDiscount, + X_DIRECTION_BULLISH, + pivotCBar // + ) && + pivotPBar.high > pivotPremiumDiscount; + + // + isPivotPremiumDownRejected = + isCInited && + isPInited && + IsBarReject( + pivotPremiumDiscount, + X_DIRECTION_BEARISH, + pivotCBar // + ) && + pivotPBar.high > pivotPremiumDiscount; + + // + // + // + + // + isPivotDiscountUpBreaked = + isCInited && + isPInited && + IsBarBreak( + pivotPremiumDiscount, + X_DIRECTION_BULLISH, + pivotCBar // + ) && + pivotPBar.low < pivotPremiumDiscount; + + // + isPivotDiscountDownBreaked = + isCInited && + isPInited && + IsBarBreak( + pivotPremiumDiscount, + X_DIRECTION_BEARISH, + pivotCBar // + ) && + pivotPBar.low < pivotPremiumDiscount; + + // + isPivotDiscountUpRejected = + isCInited && + isPInited && + IsBarReject( + pivotPremiumDiscount, + X_DIRECTION_BULLISH, + pivotCBar // + ) && + pivotPBar.low < pivotPremiumDiscount; + + // + isPivotDiscountDownRejected = + isCInited && + isPInited && + IsBarReject( + pivotPremiumDiscount, + X_DIRECTION_BEARISH, + pivotCBar // + ) && + pivotPBar.low < pivotPremiumDiscount; + + // + // Detect Bar Patterns ... + + // + if (isCBarBullishRejected) + { + // + int count = conditions.pivotZone.state.CountBullishRejectionBars(); + isCBarBullishRejected = IsValidSize(count); + if (isCBarBullishRejected) + { + // + bool hasBar = false; + for (int i = 0; i < count; i++) + { + // + XCRejectionBar *iBar = conditions.pivotZone.state.bullishRejectionBars[i]; + + // + hasBar = iBar.BarTime() == cBar.time; + if (hasBar) + { + break; + } + } + + // + isCBarBullishRejected = hasBar; + } + } + + // + if (isCBarBearishRejected) + { + // + int count = conditions.pivotZone.state.CountBearishRejectionBars(); + isCBarBearishRejected = IsValidSize(count); + if (isCBarBearishRejected) + { + // + bool hasBar = false; + for (int i = 0; i < count; i++) + { + // + XCRejectionBar *iBar = conditions.pivotZone.state.bearishRejectionBars[i]; + + // + hasBar = iBar.BarTime() == cBar.time; + if (hasBar) + { + break; + } + } + + // + isCBarBearishRejected = hasBar; + } + } + + // + // Draw Pivot ... + XCBaseObject *drawnObjects[]; + triggerCycleHelper.mPOIDetector.mDrawer.DrawPivot( + conditions.pivotZone, + drawnObjects, + true, // Draw State ... + false, // State As Box ... + true // Tick Zone ... + ); + } + } + + // + // Sar Conditions ... + + // + bool isSarBullishFormed = + ( + // + ( + // + decisionXConditions.isBreakedUpPrevSar && + (decisionXConditions.isSarBullish || + decisionXConditions.isSarSwitchedToBullish) + // + ) + // + ); + + // + bool isSarBearishFormed = + ( + // + ( + // + decisionXConditions.isBreakedDownPrevSar && + (decisionXConditions.isSarBearish || + decisionXConditions.isSarSwitchedToBearish) + // + ) + // + ); + + // + // + // + + // + // Summarize Conditions ... + + // + bool isCondition1Bullish = + // + hasPivot && + // + isCBarBullishRejected && + // + // + true + // + ; + + // + bool isCondition1Bearish = + // + hasPivot && + // + isCBarBearishRejected && + // + // + true + // + ; + + // + bool hasCondition1 = isCondition1Bullish || + isCondition1Bearish; + if (hasCondition1) + { + // + ENUM_X_DIRECTION pzDir = + isCondition1Bullish + ? X_DIRECTION_BULLISH + : X_DIRECTION_BEARISH; + + // + double point = GetEntry( + conditions.symbol, + pzDir // + ); + + // + // Manipulate Conditions Point ... + + // + conditions.point = pivotPremiumDiscount; + + // + // Manipulate Conditions Pivot ... + + // + conditions.pivot = + isCondition1Bullish + ? conditions.pivotZone.upper + : conditions.pivotZone.lower; + + // + // conditions.Clean(); + isCondition1Bullish = false; + isCondition1Bearish = false; + } + + // + // + // + + // + isBullish = + // + // false + isCondition1Bullish + // + ; + + // + isBearish = + // + // false + isCondition1Bearish + // + ; + + // + result = isBullish || + isBearish; + if (!result) + { + // + // Cleanup Arrays ... + ArrayFree(triggerPoiEvents); + ArrayFree(triggerCycleEvents); + ArrayFree(decisionPoiEvents); + ArrayFree(decisionCycleEvents); + ArrayFree(analysePoiEvents); + ArrayFree(analyseCycleEvents); + ArrayFree(verificationPoiEvents); + ArrayFree(verificationCycleEvents); + ArrayFree(consolidationPoiEvents); + ArrayFree(consolidationCycleEvents); + ArrayFree(visionPoiEvents); + ArrayFree(visionCycleEvents); + + // + return result; + } + + // + conditions.setupTime = cTime; + conditions.dir = + isBullish + ? X_DIRECTION_BULLISH + : X_DIRECTION_BEARISH; + + // + // Cleanup Arrays ... + ArrayFree(triggerPoiEvents); + ArrayFree(triggerCycleEvents); + ArrayFree(decisionPoiEvents); + ArrayFree(decisionCycleEvents); + ArrayFree(analysePoiEvents); + ArrayFree(analyseCycleEvents); + ArrayFree(verificationPoiEvents); + ArrayFree(verificationCycleEvents); + ArrayFree(consolidationPoiEvents); + ArrayFree(consolidationCycleEvents); + ArrayFree(visionPoiEvents); + ArrayFree(visionCycleEvents); + + // + return result; +} + +// +// Detect Trigger Conditions ... +bool DetectX121SMCXSiganlTrigger( + // + X121SMCStrategyXSignalConditions &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 = 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; + + // + // Cycle X121Conditions ... + X121Conditions triggerXConditions = triggerConditions.x121Conditions; + X121Conditions decisionXConditions = decisionConditions.x121Conditions; + X121Conditions analyseXConditions = analyseConditions.x121Conditions; + X121Conditions verificationXConditions = verificationConditions.x121Conditions; + X121Conditions consolidationXConditions = consolidationConditions.x121Conditions; + X121Conditions visionXConditions = visionConditions.x121Conditions; + + // + // Trigger Conditions ... + + // + // SAR ... + double sar = decisionXConditions.sarBuffer[1]; + + // + // STR ... + double str = decisionXConditions.strBuffer[1]; + + // + // CHE ... + double le1 = decisionXConditions.le1Buffer[1]; + double le2 = decisionXConditions.le2Buffer[1]; + double se1 = decisionXConditions.se1Buffer[1]; + double se2 = decisionXConditions.se2Buffer[1]; + + // + // ATR ... + double atrUpper = decisionXConditions.atrUpperBuffer[1]; + double atrLower = decisionXConditions.atrLowerBuffer[1]; + + // + // PV ... + double peak = decisionXConditions.peaksBuffer[1]; + double vale = decisionXConditions.valesBuffer[1]; + + // + int higherPeakIDX = -1; + double higherPeak = decisionCycleHelper + .mX121Helper + .xpvHelper.GetHigherPeak( + higherPeakIDX, + peak // + ); + + // + int lowerValeIDX = -1; + double lowerVale = decisionCycleHelper + .mX121Helper + .xpvHelper.GetLowerVale( + lowerValeIDX, + vale // + ); + + // + // Slopes ... + + // + bool isRsiSlopeBullish = decisionXConditions.isRsiSlopeBullish; + bool isStrSlopeBullish = decisionXConditions.isStrSlopeBullish; + bool isAtrUpperSlopeBullish = decisionXConditions.isAtrUpperSlopeBullish; + bool isAtrLowerSlopeBullish = decisionXConditions.isAtrLowerSlopeBullish; + bool isVwapFastSlopeBullish = decisionXConditions.isVwapFastSlopeBullish; + bool isVwapMidSlopeBullish = decisionXConditions.isVwapMidSlopeBullish; + bool isVwapSlowSlopeBullish = decisionXConditions.isVwapSlowSlopeBullish; + + // + bool isRsiSlopeBearish = decisionXConditions.isRsiSlopeBearish; + bool isStrSlopeBearish = decisionXConditions.isStrSlopeBearish; + bool isAtrUpperSlopeBearish = decisionXConditions.isAtrUpperSlopeBearish; + bool isAtrLowerSlopeBearish = decisionXConditions.isAtrLowerSlopeBearish; + bool isVwapFastSlopeBearish = decisionXConditions.isVwapFastSlopeBearish; + bool isVwapMidSlopeBearish = decisionXConditions.isVwapMidSlopeBearish; + bool isVwapSlowSlopeBearish = decisionXConditions.isVwapSlowSlopeBearish; + + // + bool isSlopesBullish = + isRsiSlopeBullish && + isStrSlopeBullish && + isAtrUpperSlopeBullish && + isAtrLowerSlopeBullish && + isVwapFastSlopeBullish && + isVwapMidSlopeBullish && + isVwapSlowSlopeBullish; + + // + bool isSlopesBearish = + isRsiSlopeBearish && + isStrSlopeBearish && + isAtrUpperSlopeBearish && + isAtrLowerSlopeBearish && + isVwapFastSlopeBearish && + isVwapMidSlopeBearish && + isVwapSlowSlopeBearish; + + // + double point = conditions.point; + bool isPointBreaked = + isBullish + ? ask > point && bid > point + : ask < point && bid < point; + // bool isPointBreaked = IsBarBreak( + // point, + // setupDir, + // cBar // + // ); + + // + // Summary ... + + // + isBullish = + // + isBullish && + // isPointBreaked && + // isSlopesBullish && + cBar.IsBullish() + // + ; + + // + isBearish = + // + isBearish && + // isPointBreaked && + // isSlopesBearish && + cBar.IsBearish() + // + ; + + // + result = isBullish || + isBearish; + if (!result) + { + // + // Cleanup Setup Conditions ... + int setupAge = conditions.GetSetupAge(); + if (IsValidSize(setupAge) && + IsValidSize(maxAllowedSetupAge) && + setupAge >= maxAllowedSetupAge) + { + conditions.Clean(); + } + + // + // Cleanup Arrays ... + ArrayFree(triggerPoiEvents); + ArrayFree(triggerCycleEvents); + ArrayFree(decisionPoiEvents); + ArrayFree(decisionCycleEvents); + ArrayFree(analysePoiEvents); + ArrayFree(analyseCycleEvents); + ArrayFree(verificationPoiEvents); + ArrayFree(verificationCycleEvents); + ArrayFree(consolidationPoiEvents); + ArrayFree(consolidationCycleEvents); + ArrayFree(visionPoiEvents); + ArrayFree(visionCycleEvents); + + // + return result; + } + + // + // Detect Nearest Pivot Point ... + + // + // Detect Target ... + double target = CalculateTarget( + cBar, + decisionState, + setupDir // + ); + if (target == 0) + { + // + target = CalculateTarget( + cBar, + analyseState, + setupDir // + ); + + // + if (target == 0) + { + // + target = CalculateTarget( + cBar, + verificationState, + setupDir // + ); + } + } + target = 0; + + // + double entry = GetEntry( + conditions.symbol, + setupDir // + ); + + // + // Filling SL Candidates ... + double momentumBarPointsDif = 30 * points; + + // + // Bullish Momentum Bar Selection ... + XOHCL bullishMomentumBar; + int bullishMomentumBarsCount = decisionState.CountBullishMomentumBars(); + if (IsValidSize(bullishMomentumBarsCount)) + { + // + for (int i = 0; i < bullishMomentumBarsCount; i++) + { + // + XCMomentumBar *iMomentum = decisionState.bullishMomentumBars[i]; + + // + XOHCL iBar; + bool isFilled = iMomentum.FillBar(iBar); + if (!isFilled) + { + continue; + } + + // + bool isValidDistane = (MathAbs(iBar.low) - entry) >= momentumBarPointsDif; + if (!isValidDistane) + { + continue; + } + + // + bool isIndexPassed = iBar.Index() <= 5; + if (!isIndexPassed) + { + continue; + } + + // + bool canSet = + !bullishMomentumBar.IsValid() || + (bullishMomentumBar.IsValid() && + bullishMomentumBar.low < entry && + bullishMomentumBar.Index() > iBar.Index()); + if (canSet) + { + bullishMomentumBar = iBar; + } + } + } + + // + // Bearish Momentum Bar Selection ... + XOHCL bearishMomentumBar; + int bearishMomentumBarsCount = decisionState.CountBearishMomentumBars(); + if (IsValidSize(bearishMomentumBarsCount)) + { + // + for (int i = 0; i < bearishMomentumBarsCount; i++) + { + // + XCMomentumBar *iMomentum = decisionState.bearishMomentumBars[i]; + + // + XOHCL iBar; + bool isFilled = iMomentum.FillBar(iBar); + if (!isFilled) + { + continue; + } + + // + bool isValidDistane = (MathAbs(iBar.high) - entry) >= momentumBarPointsDif; + if (!isValidDistane) + { + continue; + } + + // + bool isIndexPassed = iBar.Index() <= 5; + if (!isIndexPassed) + { + continue; + } + + // + bool canSet = + !bearishMomentumBar.IsValid() || + (bearishMomentumBar.IsValid() && + bearishMomentumBar.high > entry && + bearishMomentumBar.Index() > iBar.Index()); + if (canSet) + { + bearishMomentumBar = iBar; + } + } + } + + // + double sls[]; + Add( + sar, + sls // + ); + Add( + str, + sls // + ); + + // + if (isBullish) + { + // + Add( + atrLower, + sls // + ); + + // // + // Add( + // vale, + // sls // + // ); + + // + if (bullishMomentumBar.IsValid()) + { + // + Add( + bullishMomentumBar.low, + sls // + ); + } + + // // + // if (IsValidIndex(lowerValeIDX)) + // { + // // + // Add( + // lowerVale, + // sls // + // ); + // } + + // + if (le1 != EMPTY_VALUE) + { + // + Add( + le1, + sls // + ); + } + + // + if (le2 != EMPTY_VALUE) + { + // + Add( + le2, + sls // + ); + } + } + else + { + // + Add( + atrUpper, + sls // + ); + + // // + // Add( + // peak, + // sls // + // ); + + // + if (bearishMomentumBar.IsValid()) + { + // + Add( + bearishMomentumBar.high, + sls // + ); + } + + // + // if (IsValidIndex(higherPeakIDX)) + // { + // // + // Add( + // higherPeak, + // sls // + // ); + // } + + // + if (se1 != EMPTY_VALUE) + { + // + Add( + se1, + sls // + ); + } + + // + if (se2 != EMPTY_VALUE) + { + // + Add( + se2, + sls // + ); + } + } + + // + double iAtr = decisionConditions.x121Conditions.atrBuffer[1]; + iAtr *= 2.5; + + // + double slsMin = GetMin(sls); + double slsMax = GetMax(sls); + + // + double sl = isBullish + ? slsMin - iAtr + : slsMax + iAtr; + double risk = MathAbs(entry - sl); + double riskInPoints = risk / points; + if (riskInPoints >= 150) + { + // + target = + isBullish + ? entry + (points * 200) + : entry - (points * 200); + + // + 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; + + // + // Cleanup Arrays ... + ArrayFree(triggerPoiEvents); + ArrayFree(triggerCycleEvents); + ArrayFree(decisionPoiEvents); + ArrayFree(decisionCycleEvents); + ArrayFree(analysePoiEvents); + ArrayFree(analyseCycleEvents); + ArrayFree(verificationPoiEvents); + ArrayFree(verificationCycleEvents); + ArrayFree(consolidationPoiEvents); + ArrayFree(consolidationCycleEvents); + ArrayFree(visionPoiEvents); + ArrayFree(visionCycleEvents); + + // + return result; +} + +// +bool DetectX121SMCXGuards( + X121SMCGuard &guards[], + const XPosition &positions[], + XC121SMCCycleHelper *triggerCycleHelper, + XC121SMCCycleHelper *decisionCycleHelper, + XC121SMCCycleHelper *analyseCycleHelper, + XC121SMCCycleHelper *verificationCycleHelper, + XC121SMCCycleHelper *consolidationCycleHelper, + XC121SMCCycleHelper *visionCycleHelper // +) +{ + // + bool result = false; + + // + string provider = ToString(X_121_SMC_PROVIDER_X); + + // + // result = DetectX121SMCGuards( + // provider, + // guards, + // positions, + // triggerCycleHelper, + // decisionCycleHelper, + // analyseCycleHelper, + // verificationCycleHelper, + // consolidationCycleHelper, + // visionCycleHelper // + // ); + + // + return result; +} + +// +int AddX121SMCXConditionsIfNotExists( + X121SMCStrategyXSignalConditions &item, + X121SMCStrategyXSignalConditions &items[], + int maxAllowed = 10 // +) +{ + // + int result = 0; + + // + bool isSetuped = IsValid(item.setupTime) && + HasDirection(item.dir); + if (!isSetuped) + { + return result; + } + + // + int count = ArraySize(items); + if (IsValidSize(count)) + { + // + // Copy Original Items ... + X121SMCStrategyXSignalConditions tmpItems[]; + Copy( + items, + tmpItems // + ); + + // + // Prese Item Data ... + bool isBullish = IsBullish(item.dir); + + // + for (int i = 0; i < count; i++) + { + // + X121SMCStrategyXSignalConditions iItem = tmpItems[i]; + + // + bool canRemove = item.dir == iItem.dir && + item.pivot == iItem.pivot; + if (canRemove) + { + // + ArrayRemove( + items, + i, + 1 // + ); + } + } + + // + Clean(tmpItems); + } + + // + AddRef( + item, + items // + ); + + // + // Remove Olds ... + CleanupArray( + items, + maxAllowed // + ); + + // + result = ArraySize(items); + + // + return result; +} + +// +int DrawX121SMCXConditions( + X121SMCStrategyXSignalConditions &conditions, + XCBaseObject *&drawnObjects[], + XCPOIDrawer *drawer // +) +{ + // + int result = 0; + + // + Clean(drawnObjects); + + // + if (drawer == NULL) + { + return result; + } + + // + bool isSetuped = conditions.IsSetuped(); + if (!isSetuped) + { + return result; + } + + // + return result; +} + +// diff --git a/X121SMCEA/Signals/x-121.smc.xpz.signal.lib.mq5 b/X121SMCEA/Signals/x-121.smc.xpz.signal.lib.mq5 index 8feb3f32..25d660f6 100644 --- a/X121SMCEA/Signals/x-121.smc.xpz.signal.lib.mq5 +++ b/X121SMCEA/Signals/x-121.smc.xpz.signal.lib.mq5 @@ -58,9 +58,6 @@ struct X121SMCStrategyXPZSignalConditions bool isPriceZoneValidForPeak; bool isPriceZoneValidForVale; - // - XPVPivot pivotZone; - // // Constructor ... X121SMCStrategyXPZSignalConditions() @@ -181,7 +178,6 @@ struct X121SMCStrategyXPZSignalConditions // priceZone.Clean(); - pivotZone.Clean(); isPriceZoneValidForPeak = false; isPriceZoneValidForVale = false; } @@ -194,13 +190,6 @@ struct X121SMCStrategyXPZSignalConditions X121SMCStrategyXPZSignalConditions mXPZConditions; X121SMCStrategyXPZSignalConditions mXPZConditionsCollection[]; -// -double X121SMCXPZPivotPeak; -double X121SMCXPZPivotVale; -datetime X121SMCXPZPivotEnd; -datetime X121SMCXPZPivotStart; -ENUM_XPV_PIVOTS X121SMCXPZPivotType = XPV_NONE; - // // Extension Functions ... @@ -425,25 +414,63 @@ bool DetectX121SMCXPZSiganlSetup( // // Consolidation ... - - // - bool hasConsolidationBullishTrend = consolidationXConditions.isTrendBullish; - bool hasConsolidationBearishTrend = consolidationXConditions.isTrendBearish; + ENUM_X_DIRECTION consolidationTrendDir; + bool hasConsolidationTrend = + consolidationCycleHelper + .DetectMarketStructure( + consolidationTrendDir // + ); + bool hasConsolidationBullishTrend = + hasConsolidationTrend && + IsBullish(consolidationTrendDir); + bool hasConsolidationBearishTrend = + hasConsolidationTrend && + IsBearish(consolidationTrendDir); // // Verification ... - bool hasVerificationBullishTrend = verificationXConditions.isTrendBullish; - bool hasVerificationBearishTrend = verificationXConditions.isTrendBearish; + ENUM_X_DIRECTION verificationTrendDir; + bool hasVerificationTrend = + verificationCycleHelper + .DetectMarketStructure( + verificationTrendDir // + ); + bool hasVerificationBullishTrend = + hasVerificationTrend && + IsBullish(verificationTrendDir); + bool hasVerificationBearishTrend = + hasVerificationTrend && + IsBearish(verificationTrendDir); // // Analyse ... - bool hasAnalyseBullishTrend = analyseXConditions.isTrendBullish; - bool hasAnalyseBearishTrend = analyseXConditions.isTrendBearish; + ENUM_X_DIRECTION analyseTrendDir; + bool hasAnalyseTrend = + analyseCycleHelper + .DetectMarketStructure( + analyseTrendDir // + ); + bool hasAnalyseBullishTrend = + hasAnalyseTrend && + IsBullish(analyseTrendDir); + bool hasAnalyseBearishTrend = + hasAnalyseTrend && + IsBearish(analyseTrendDir); // // Decision ... - bool hasDecisionBullishTrend = decisionXConditions.isTrendBullish; - bool hasDecisionBearishTrend = decisionXConditions.isTrendBearish; + ENUM_X_DIRECTION decisionTrendDir; + bool hasDecisionTrend = + decisionCycleHelper + .DetectMarketStructure( + decisionTrendDir // + ); + bool hasDecisionBullishTrend = + hasDecisionTrend && + IsBullish(decisionTrendDir); + bool hasDecisionBearishTrend = + hasDecisionTrend && + IsBearish(decisionTrendDir); // // Detect Bar State ... @@ -541,314 +568,6 @@ bool DetectX121SMCXPZSiganlSetup( // ; - // - // Detect PV Pivot ... - - // - bool isPivotPeakZoneRejected = false; - bool isPivotPeakZoneBreakedUp = false; - bool isPivotPeakZoneBreakedDown = false; - bool isPivotValeZoneRejected = false; - bool isPivotValeZoneBreakedUp = false; - bool isPivotValeZoneBreakedDown = false; - bool hasPivot = conditions.pivotZone.IsValid(); - if (!hasPivot) - { - // - hasPivot = IsValid(X121SMCXPZPivotStart); - if (!hasPivot) - { - // - bool isNewVale = decisionXConditions.isNewVale; - bool isNewValeOverLast = decisionXConditions.isNewValeOverLast; - bool isNewValeUnderLast = decisionXConditions.isNewValeUnderLast; - bool isSameVales = decisionXConditions.valesBuffer[1] == - decisionXConditions.valesBuffer[2] && - decisionXConditions.valesBuffer[2] == - decisionXConditions.valesBuffer[3]; - bool isSameCycleVales = decisionXConditions.valesBuffer[1] == - analyseXConditions.valesBuffer[1] && - analyseXConditions.valesBuffer[1] == - verificationXConditions.valesBuffer[1]; - - // - bool isNewPeak = decisionXConditions.isNewPeak; - bool isNewPeakOverLast = decisionXConditions.isNewPeakOverLast; - bool isNewPeakUnderLast = decisionXConditions.isNewPeakUnderLast; - bool isSamePeaks = decisionXConditions.peaksBuffer[1] == - decisionXConditions.peaksBuffer[2] && - decisionXConditions.peaksBuffer[2] == - decisionXConditions.peaksBuffer[3]; - bool isSameCyclePeaks = decisionXConditions.peaksBuffer[1] == - analyseXConditions.peaksBuffer[1] && - analyseXConditions.peaksBuffer[1] == - verificationXConditions.peaksBuffer[1]; - - // - bool isValeStart = - // isSameVales; - isSameVales && - isSameCycleVales; - bool isPeakStart = - // isSamePeaks; - isSamePeaks && - isSameCyclePeaks; - - // - bool isStart = isPeakStart || - isValeStart; - if (isStart) - { - // - X121SMCXPZPivotStart = cTime; - X121SMCXPZPivotType = - isPeakStart - ? XPV_PEAK - : XPV_VALE; - - // - X121SMCXPZPivotPeak = decisionXConditions.peaksBuffer[1]; - X121SMCXPZPivotVale = decisionXConditions.valesBuffer[1]; - } - - // - hasPivot = IsValid(X121SMCXPZPivotStart); - - // - // Create XPVPivot instance ... - if (hasPivot) - { - // - conditions.pivotZone.symbol = symbol; - conditions.pivotZone.period = period; - - // - conditions.pivotZone.to = cTime; - conditions.pivotZone.repetition = 3; - - // - conditions.pivotZone.upper = X121SMCXPZPivotPeak; - conditions.pivotZone.lower = X121SMCXPZPivotVale; - - // - conditions.pivotZone.type = X121SMCXPZPivotType; - conditions.pivotZone.from = X121SMCXPZPivotStart; - } - } - } - - // - if (hasPivot) - { - // - bool isBreaked = X121SMCXPZPivotType == XPV_PEAK - ? decisionXConditions.isBreakedUpPrevPeak - : decisionXConditions.isBreakedDownPrevVale; - - // - if (!isBreaked) - { - // - X121SMCXPZPivotPeak = decisionXConditions.peaksBuffer[1]; - X121SMCXPZPivotVale = decisionXConditions.valesBuffer[1]; - - // - conditions.pivotZone.to = cTime; - conditions.pivotZone.repetition++; - conditions.pivotZone.upper = X121SMCXPZPivotPeak; - conditions.pivotZone.lower = X121SMCXPZPivotVale; - } - else - { - // - X121SMCXPZPivotEnd = cTime; - conditions.pivotZone.to = cTime; - } - - // - // Fill Pivot State ... - - // - XPOIState analysePivotState; - DetectPivotPOIs( - conditions.pivotZone, - analyseState, - analysePivotState // - ); - - // - XPOIState decisionPivotState; - DetectPivotPOIs( - conditions.pivotZone, - decisionState, - decisionPivotState // - ); - - // - // Combine two State ... - XPOIState combinedPivotState; - XPOIState iStates[]; - AddRef( - analysePivotState, - iStates // - ); - AddRef( - decisionPivotState, - iStates // - ); - CombineStates( - combinedPivotState, - iStates // - ); - combinedPivotState = decisionPivotState; - - // - ArrayFree(iStates); - - // - combinedPivotState.time = decisionPivotState.time; - combinedPivotState.symbol = decisionPivotState.symbol; - combinedPivotState.period = decisionPivotState.period; - - // - // Hold Only Areas Which on Upper or Lower bondary of Pivot Zone ... - FilterPivotState( - conditions.pivotZone, - combinedPivotState // - ); - - // - conditions.pivotZone.state = combinedPivotState; - - // - double peakUpper = 0; - double peakLower = 0; - double valeUpper = 0; - double valeLower = 0; - - // - datetime peakTo = NULL; - datetime valeTo = NULL; - datetime peakFrom = NULL; - datetime valeFrom = NULL; - - // - bool hasBoxData = DetectPivotStateBoxData( - conditions.pivotZone, - peakUpper, - peakLower, - peakFrom, - peakTo, - valeUpper, - valeLower, - valeFrom, - valeTo // - ); - - // - // Calculate Pivot Tick Zones ... - - // - int ticksLevels = decisionCycleHelper - .mPOIDetector - .TicksRangeZoneLevel(); - int ticksRange = decisionCycleHelper - .mPOIDetector - .TicksRangeZoneRange(); - - // - CalculatePivotTickZone( - conditions.pivotZone, - ticksLevels, - ticksRange // - ); - - // - isPivotPeakZoneRejected = - hasBoxData && - ( - // - IsBarReject( - peakLower, - X_DIRECTION_BEARISH, - cBar // - ) - // - || - // - IsBarReject( - peakUpper, - X_DIRECTION_BEARISH, - cBar // - ) - // - ); - isPivotPeakZoneBreakedUp = - hasBoxData && - IsBarBreak( - peakUpper, - X_DIRECTION_BULLISH, - cBar // - ); - isPivotPeakZoneBreakedDown = - hasBoxData && - IsBarBreak( - peakLower, - X_DIRECTION_BEARISH, - cBar // - ); - - // - isPivotValeZoneRejected = - hasBoxData && - ( - // - IsBarReject( - valeLower, - X_DIRECTION_BULLISH, - cBar // - ) - // - || - // - IsBarReject( - valeUpper, - X_DIRECTION_BULLISH, - cBar // - ) - // - ); - isPivotValeZoneBreakedUp = - hasBoxData && - IsBarBreak( - valeUpper, - X_DIRECTION_BULLISH, - cBar // - ); - isPivotValeZoneBreakedDown = - hasBoxData && - IsBarBreak( - valeLower, - X_DIRECTION_BEARISH, - cBar // - ); - } - - // - bool isPivotEnded = IsValid(X121SMCXPZPivotEnd); - if (isPivotEnded) - { - // - X121SMCXPZPivotPeak = 0; - X121SMCXPZPivotVale = 0; - X121SMCXPZPivotEnd = NULL; - X121SMCXPZPivotStart = NULL; - X121SMCXPZPivotType = XPV_NONE; - - // - conditions.pivotZone.Clean(); - } - // // Detect Price Zone ... @@ -989,8 +708,6 @@ bool DetectX121SMCXPZSiganlSetup( // bool isPriceZoneBullish = - // - hasPivot && // hasVerificationBullishTrend && hasAnalyseBullishTrend && @@ -1003,14 +720,14 @@ bool DetectX121SMCXPZSiganlSetup( isCBarBullishFormed && isInDecisionDiscount && decisionXConditions.isAtrLowerUnderVale && - decisionXConditions.isAtrLowerSlopeBullish + decisionXConditions.isAtrLowerSlopeBullish && + // + true // ; // bool isPriceZoneBearish = - // - hasPivot && // hasVerificationBearishTrend && hasAnalyseBearishTrend && @@ -1023,7 +740,9 @@ bool DetectX121SMCXPZSiganlSetup( isInDecisionPremium && isCBarBearishFormed && decisionXConditions.isAtrUpperOverPeak && - decisionXConditions.isAtrUpperSlopeBearish + decisionXConditions.isAtrUpperSlopeBearish && + // + true // ; diff --git a/X121SMCEA/Signals/x-121.smc.xrspvi.signal.lib.mq5 b/X121SMCEA/Signals/x-121.smc.xrspvi.signal.lib.mq5 index 8c83cdb4..8d156d5d 100644 --- a/X121SMCEA/Signals/x-121.smc.xrspvi.signal.lib.mq5 +++ b/X121SMCEA/Signals/x-121.smc.xrspvi.signal.lib.mq5 @@ -445,25 +445,63 @@ bool DetectX121SMCXRSPVISiganlSetup( // // Consolidation ... - - // - bool hasConsolidationBullishTrend = consolidationXConditions.isTrendBullish; - bool hasConsolidationBearishTrend = consolidationXConditions.isTrendBearish; + ENUM_X_DIRECTION consolidationTrendDir; + bool hasConsolidationTrend = + consolidationCycleHelper + .DetectMarketStructure( + consolidationTrendDir // + ); + bool hasConsolidationBullishTrend = + hasConsolidationTrend && + IsBullish(consolidationTrendDir); + bool hasConsolidationBearishTrend = + hasConsolidationTrend && + IsBearish(consolidationTrendDir); // // Verification ... - bool hasVerificationBullishTrend = verificationXConditions.isTrendBullish; - bool hasVerificationBearishTrend = verificationXConditions.isTrendBearish; + ENUM_X_DIRECTION verificationTrendDir; + bool hasVerificationTrend = + verificationCycleHelper + .DetectMarketStructure( + verificationTrendDir // + ); + bool hasVerificationBullishTrend = + hasVerificationTrend && + IsBullish(verificationTrendDir); + bool hasVerificationBearishTrend = + hasVerificationTrend && + IsBearish(verificationTrendDir); // // Analyse ... - bool hasAnalyseBullishTrend = analyseXConditions.isTrendBullish; - bool hasAnalyseBearishTrend = analyseXConditions.isTrendBearish; + ENUM_X_DIRECTION analyseTrendDir; + bool hasAnalyseTrend = + analyseCycleHelper + .DetectMarketStructure( + analyseTrendDir // + ); + bool hasAnalyseBullishTrend = + hasAnalyseTrend && + IsBullish(analyseTrendDir); + bool hasAnalyseBearishTrend = + hasAnalyseTrend && + IsBearish(analyseTrendDir); // // Decision ... - bool hasDecisionBullishTrend = decisionXConditions.isTrendBullish; - bool hasDecisionBearishTrend = decisionXConditions.isTrendBearish; + ENUM_X_DIRECTION decisionTrendDir; + bool hasDecisionTrend = + decisionCycleHelper + .DetectMarketStructure( + decisionTrendDir // + ); + bool hasDecisionBullishTrend = + hasDecisionTrend && + IsBullish(decisionTrendDir); + bool hasDecisionBearishTrend = + hasDecisionTrend && + IsBearish(decisionTrendDir); // // Detect Bar State ... diff --git a/X121SMCEA/Signals/x-121.smc.xstrpv.signal.lib.mq5 b/X121SMCEA/Signals/x-121.smc.xstrpv.signal.lib.mq5 index 19c749b6..7f774b2b 100644 --- a/X121SMCEA/Signals/x-121.smc.xstrpv.signal.lib.mq5 +++ b/X121SMCEA/Signals/x-121.smc.xstrpv.signal.lib.mq5 @@ -423,25 +423,63 @@ bool DetectX121SMCXSTRPVSiganlSetup( // // Consolidation ... - - // - bool hasConsolidationBullishTrend = consolidationXConditions.isTrendBullish; - bool hasConsolidationBearishTrend = consolidationXConditions.isTrendBearish; + ENUM_X_DIRECTION consolidationTrendDir; + bool hasConsolidationTrend = + consolidationCycleHelper + .DetectMarketStructure( + consolidationTrendDir // + ); + bool hasConsolidationBullishTrend = + hasConsolidationTrend && + IsBullish(consolidationTrendDir); + bool hasConsolidationBearishTrend = + hasConsolidationTrend && + IsBearish(consolidationTrendDir); // // Verification ... - bool hasVerificationBullishTrend = verificationXConditions.isTrendBullish; - bool hasVerificationBearishTrend = verificationXConditions.isTrendBearish; + ENUM_X_DIRECTION verificationTrendDir; + bool hasVerificationTrend = + verificationCycleHelper + .DetectMarketStructure( + verificationTrendDir // + ); + bool hasVerificationBullishTrend = + hasVerificationTrend && + IsBullish(verificationTrendDir); + bool hasVerificationBearishTrend = + hasVerificationTrend && + IsBearish(verificationTrendDir); // // Analyse ... - bool hasAnalyseBullishTrend = analyseXConditions.isTrendBullish; - bool hasAnalyseBearishTrend = analyseXConditions.isTrendBearish; + ENUM_X_DIRECTION analyseTrendDir; + bool hasAnalyseTrend = + analyseCycleHelper + .DetectMarketStructure( + analyseTrendDir // + ); + bool hasAnalyseBullishTrend = + hasAnalyseTrend && + IsBullish(analyseTrendDir); + bool hasAnalyseBearishTrend = + hasAnalyseTrend && + IsBearish(analyseTrendDir); // // Decision ... - bool hasDecisionBullishTrend = decisionXConditions.isTrendBullish; - bool hasDecisionBearishTrend = decisionXConditions.isTrendBearish; + ENUM_X_DIRECTION decisionTrendDir; + bool hasDecisionTrend = + decisionCycleHelper + .DetectMarketStructure( + decisionTrendDir // + ); + bool hasDecisionBullishTrend = + hasDecisionTrend && + IsBullish(decisionTrendDir); + bool hasDecisionBearishTrend = + hasDecisionTrend && + IsBearish(decisionTrendDir); // // Detect Bar State ... diff --git a/X121SMCEA/Strategy/x-121.smc.strategy.class.mq5 b/X121SMCEA/Strategy/x-121.smc.strategy.class.mq5 index ac4e5a5d..3b4286d3 100644 --- a/X121SMCEA/Strategy/x-121.smc.strategy.class.mq5 +++ b/X121SMCEA/Strategy/x-121.smc.strategy.class.mq5 @@ -27,6 +27,7 @@ #include "../Classes/x-121.smc.market.cycle.helper.class.mq5" // +#include "../Signals/x-121.smc.x.signal.lib.mq5" #include "../Signals/x-121.smc.xpz.signal.lib.mq5" #include "../Signals/x-121.smc.xrspvi.signal.lib.mq5" #include "../Signals/x-121.smc.xstrpv.signal.lib.mq5" @@ -43,6 +44,7 @@ class XCX121SMCStrategy : public XCX121SMCBaseStrategy public: // // Props ... + bool useXSignal; bool useXPZSignal; bool useXRSPVISignal; bool useXSTRPVSignal; @@ -195,10 +197,20 @@ class XCX121SMCStrategy : public XCX121SMCBaseStrategy bool hasSignal = false; // + bool hasXSignal = false; bool hasXPZSignal = false; bool hasXRSPVISignal = false; bool hasXSTRPVSignal = false; + // + // X Signal ... + if (useXSignal && !hasSignal) + { + // + hasXSignal = DetectXSignal(conditions); + hasSignal = hasXSignal; + } + // // XPZ Signal ... if (useXPZSignal && !hasSignal) @@ -382,11 +394,11 @@ class XCX121SMCStrategy : public XCX121SMCBaseStrategy } // - // XSTRPV Guard Detection ... - if (useXSTRPVSignal) + // X Guard Detection ... + if (useXSignal) { // - bool hasGuard = DetectX121SMCXSTRPVGuards( + bool hasGuard = DetectX121SMCXGuards( guards, positions, mTriggerCycleHelper, @@ -415,6 +427,23 @@ class XCX121SMCStrategy : public XCX121SMCBaseStrategy ); } + // + // XSTRPV Guard Detection ... + if (useXSTRPVSignal) + { + // + bool hasGuard = DetectX121SMCXSTRPVGuards( + guards, + positions, + mTriggerCycleHelper, + mDecisionCycleHelper, + mAnalyseCycleHelper, + mVerificationCycleHelper, + mConsolidationCycleHelper, + mVisionCycleHelper // + ); + } + // // XRSPVI Guard Detection ... if (useXRSPVISignal) @@ -471,8 +500,8 @@ class XCX121SMCStrategy : public XCX121SMCBaseStrategy // Signalling Functions ... // - // XSTRPV Signal ... - bool DetectXSTRPVSignal( + // X Signal ... + bool DetectXSignal( X121SMCStrategyConditions &conditions // ) { @@ -537,22 +566,22 @@ class XCX121SMCStrategy : public XCX121SMCBaseStrategy datetime cTime = TimeCurrent(); // - ENUM_X_121_SMC_PROVIDERS provider = X_121_SMC_PROVIDER_XSTRPV; + ENUM_X_121_SMC_PROVIDERS provider = X_121_SMC_PROVIDER_X; string providerStr = ToString(provider); // // Detect Setup Conditions ... - datetime setupTime = mXSTRPVConditions.setupTime; - bool isSetuped = mXSTRPVConditions.IsSetuped(); - ENUM_X_DIRECTION setupDir = mXSTRPVConditions.dir; + datetime setupTime = mXConditions.setupTime; + bool isSetuped = mXConditions.IsSetuped(); + ENUM_X_DIRECTION setupDir = mXConditions.dir; if (!isSetuped) { // // Detect Signal Setup ... - isSetuped = DetectX121SMCXSTRPVSiganlSetup( + isSetuped = DetectX121SMCXSiganlSetup( symbol, period, - mXSTRPVConditions, + mXConditions, mTriggerCycleHelper, mDecisionCycleHelper, mAnalyseCycleHelper, @@ -562,25 +591,25 @@ class XCX121SMCStrategy : public XCX121SMCBaseStrategy ); // - setupDir = mXSTRPVConditions.dir; - setupTime = mXSTRPVConditions.setupTime; + setupDir = mXConditions.dir; + setupTime = mXConditions.setupTime; // if (isSetuped) { // - int items = AddX121SMCXSTRPVConditionsIfNotExists( - mXSTRPVConditions, - mXSTRPVConditionsCollection // + int items = AddX121SMCXConditionsIfNotExists( + mXConditions, + mXConditionsCollection // ); // - mXSTRPVConditions.Clean(); + mXConditions.Clean(); } } // - int conditionsCount = ArraySize(mXSTRPVConditionsCollection); + int conditionsCount = ArraySize(mXConditionsCollection); result = IsValidSize(conditionsCount); if (!result) { @@ -590,12 +619,12 @@ class XCX121SMCStrategy : public XCX121SMCBaseStrategy // // Looking For Conditions ... int selectedIndex = 0; - X121SMCStrategyXSTRPVSignalConditions mTmpConditions[]; + X121SMCStrategyXSignalConditions mTmpConditions[]; Copy( - mXSTRPVConditionsCollection, + mXConditionsCollection, mTmpConditions // ); - X121SMCStrategyXSTRPVSignalConditions mConditions; + X121SMCStrategyXSignalConditions mConditions; for (int i = 0; i < conditionsCount; i++) { // @@ -606,7 +635,7 @@ class XCX121SMCStrategy : public XCX121SMCBaseStrategy { // // Detect Signal Trigger ... - canTrigger = DetectX121SMCXSTRPVSiganlTrigger( + canTrigger = DetectX121SMCXSiganlTrigger( mTmpConditions[i], symbol, period, @@ -628,7 +657,7 @@ class XCX121SMCStrategy : public XCX121SMCBaseStrategy { // ArrayRemove( - mXSTRPVConditionsCollection, + mXConditionsCollection, i, 1 // ); @@ -661,7 +690,7 @@ class XCX121SMCStrategy : public XCX121SMCBaseStrategy // // Remove Selected Index from Main Collection ... ArrayRemove( - mXSTRPVConditionsCollection, + mXConditionsCollection, selectedIndex, 1 // ); @@ -906,6 +935,224 @@ class XCX121SMCStrategy : public XCX121SMCBaseStrategy return result; } + // + // XSTRPV Signal ... + bool DetectXSTRPVSignal( + X121SMCStrategyConditions &conditions // + ) + { + // + bool result = false; + + // + bool isBullish = false; + bool isBearish = false; + + // + int zIndex = 0; + int cIndex = zIndex + 1; + int pIndex = cIndex + 1; + int ppIndex = pIndex + 1; + + // + string symbol = GetSymbol(); + ENUM_TIMEFRAMES period = GetPeriod(); + + // + XOHCL zBar; + result = zBar.Init( + symbol, + period, + zIndex // + ); + if (!result) + { + return result; + } + + // + XOHCL cBar; + result = cBar.Init( + symbol, + period, + cIndex // + ); + if (!result) + { + return result; + } + + // + XOHCL pBar; + result = pBar.Init( + symbol, + period, + pIndex // + ); + if (!result) + { + return result; + } + + // + double cLL = cBar.FindLowest(7, MODE_LOW); + double cHH = cBar.FindHighest(7, MODE_HIGH); + + // + datetime cTime = TimeCurrent(); + + // + ENUM_X_121_SMC_PROVIDERS provider = X_121_SMC_PROVIDER_XSTRPV; + string providerStr = ToString(provider); + + // + // Detect Setup Conditions ... + datetime setupTime = mXSTRPVConditions.setupTime; + bool isSetuped = mXSTRPVConditions.IsSetuped(); + ENUM_X_DIRECTION setupDir = mXSTRPVConditions.dir; + if (!isSetuped) + { + // + // Detect Signal Setup ... + isSetuped = DetectX121SMCXSTRPVSiganlSetup( + symbol, + period, + mXSTRPVConditions, + mTriggerCycleHelper, + mDecisionCycleHelper, + mAnalyseCycleHelper, + mVerificationCycleHelper, + mConsolidationCycleHelper, + mVisionCycleHelper // + ); + + // + setupDir = mXSTRPVConditions.dir; + setupTime = mXSTRPVConditions.setupTime; + + // + if (isSetuped) + { + // + int items = AddX121SMCXSTRPVConditionsIfNotExists( + mXSTRPVConditions, + mXSTRPVConditionsCollection // + ); + + // + mXSTRPVConditions.Clean(); + } + } + + // + int conditionsCount = ArraySize(mXSTRPVConditionsCollection); + result = IsValidSize(conditionsCount); + if (!result) + { + return result; + } + + // + // Looking For Conditions ... + int selectedIndex = 0; + X121SMCStrategyXSTRPVSignalConditions mTmpConditions[]; + Copy( + mXSTRPVConditionsCollection, + mTmpConditions // + ); + X121SMCStrategyXSTRPVSignalConditions mConditions; + for (int i = 0; i < conditionsCount; i++) + { + // + // Check Triggers ... + bool canTrigger = mTmpConditions[i].CanTrigger(); + datetime triggerTime = mTmpConditions[i].triggerTime; + if (!canTrigger) + { + // + // Detect Signal Trigger ... + canTrigger = DetectX121SMCXSTRPVSiganlTrigger( + mTmpConditions[i], + symbol, + period, + mTriggerCycleHelper, + mDecisionCycleHelper, + mAnalyseCycleHelper, + mVerificationCycleHelper, + mConsolidationCycleHelper, + mVisionCycleHelper // + ); + + // + result = canTrigger; + if (!result) + { + // + bool isISetuped = mTmpConditions[i].IsSetuped(); + if (!isISetuped) + { + // + ArrayRemove( + mXSTRPVConditionsCollection, + i, + 1 // + ); + } + continue; + } + + // + triggerTime = mTmpConditions[i].triggerTime; + } + + // + if (canTrigger) + { + // + selectedIndex = i; + mConditions = mTmpConditions[i]; + break; + } + } + + // + result = IsValid(mConditions.setupTime) && + HasDirection(mConditions.dir); + if (!result) + { + return result; + } + + // + // Remove Selected Index from Main Collection ... + ArrayRemove( + mXSTRPVConditionsCollection, + selectedIndex, + 1 // + ); + + // + // Check Signal Direction ... + isBullish = IsBullish(mConditions.dir); + isBearish = IsBearish(mConditions.dir); + result = isBullish || + isBearish; + if (!result) + { + return result; + } + + // + // Issues Signal on Conditions ... + conditions.sl = mConditions.sl; + conditions.provider = providerStr; + conditions.signalDir = mConditions.dir; + conditions.target = mConditions.target; + + // + return result; + } + // // XRSPVI Signal ... bool DetectXRSPVISignal( @@ -1139,9 +1386,10 @@ class XCX121SMCStrategy : public XCX121SMCBaseStrategy void InitialHelpers() { // - useXPZSignal = true; - useXRSPVISignal = true; - useXSTRPVSignal = true; + useXSignal = true; + useXPZSignal = false; + useXRSPVISignal = false; + useXSTRPVSignal = false; // string symbol = GetSymbol(); @@ -1209,12 +1457,12 @@ class XCX121SMCStrategy : public XCX121SMCBaseStrategy // // XATR ... - x121Inputs.xatrInputs.showATRUpper = showAll || true; - x121Inputs.xatrInputs.showATRLower = showAll || true; + x121Inputs.xatrInputs.showATRUpper = showAll || false; + x121Inputs.xatrInputs.showATRLower = showAll || false; // // XSTR ... - x121Inputs.xstrInputs.showStr = showAll || true; + x121Inputs.xstrInputs.showStr = showAll || false; x121Inputs.xstrInputs.showStrUpper = showAll || false; x121Inputs.xstrInputs.showStrLower = showAll || false; @@ -1234,9 +1482,9 @@ class XCX121SMCStrategy : public XCX121SMCBaseStrategy // // XVWAP ... - x121Inputs.xvwapInputs.showVWapFast = showAll || true; - x121Inputs.xvwapInputs.showVWapMedium = showAll || true; - x121Inputs.xvwapInputs.showVWapSlow = showAll || true; + x121Inputs.xvwapInputs.showVWapFast = showAll || false; + x121Inputs.xvwapInputs.showVWapMedium = showAll || false; + x121Inputs.xvwapInputs.showVWapSlow = showAll || false; // // Initialize Cycle Helpers ...