diff --git a/Experts/x-saherelm.x-121.smc.ea.mq5 b/Experts/x-saherelm.x-121.smc.ea.mq5 index 64042fe1..e78b3492 100644 --- a/Experts/x-saherelm.x-121.smc.ea.mq5 +++ b/Experts/x-saherelm.x-121.smc.ea.mq5 @@ -80,7 +80,7 @@ input int eaPauseSignallingAfterReachesMaxAllowedSLInSecconds = 7200; // Pause S // Protection ... input group "Protection"; input bool eaAllowHedging = true; // Allow Hedge Positions -input int eaMinOpenTradesFroHedging = 4; // Minimum Open Positions for Hedging +input int eaMinOpenTradesFroHedging = 5; // 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 diff --git a/X121SMCEA/Classes/x-121.smc.base.strategy.class.mq5 b/X121SMCEA/Classes/x-121.smc.base.strategy.class.mq5 index 1b841476..528cc7f1 100644 --- a/X121SMCEA/Classes/x-121.smc.base.strategy.class.mq5 +++ b/X121SMCEA/Classes/x-121.smc.base.strategy.class.mq5 @@ -596,7 +596,7 @@ class XCX121SMCBaseStrategy : public XCBaseAlert // XBarTracker mBarTracker; // Strategy Bar Tracker ... XBarTracker mGuardBarTracker; // Strategy Guard Bar Tracker ... - XCBarAnalyser mBarAnalyser; // Bar Analyser Instance + XCBarAnalyser *mBarAnalyser; // Bar Analyser Instance // // Actions ... @@ -954,6 +954,9 @@ class XCX121SMCBaseStrategy : public XCBaseAlert period // ); + // + mBarAnalyser = new XCBarAnalyser(); + // } @@ -964,6 +967,7 @@ class XCX121SMCBaseStrategy : public XCBaseAlert { // delete mPOIDrawer; + delete mBarAnalyser; // ArrayFree(mTicks); diff --git a/X121SMCEA/Experts/x-121.smc.expert.class.mq5 b/X121SMCEA/Experts/x-121.smc.expert.class.mq5 index 547c215d..17dfda8f 100644 --- a/X121SMCEA/Experts/x-121.smc.expert.class.mq5 +++ b/X121SMCEA/Experts/x-121.smc.expert.class.mq5 @@ -976,8 +976,15 @@ class XC121SMCExpert : public XCBaseExpert (XCBaseObject *)signalObject, objects // ); + + // + Clean(objects); } } + + // + signal.Clean(); + conditions.Clean(); } // @@ -1305,6 +1312,9 @@ class XC121SMCExpert : public XCBaseExpert RegisterStrategy(iX121SMCStrategy); } } + + // + Clean(symbols); } // @@ -2322,6 +2332,7 @@ class XC121SMCExpert : public XCBaseExpert // Clean(guards); + ArrayFree(guards); } // diff --git a/X121SMCEA/Libraries/x-121.smc.lib.mq5 b/X121SMCEA/Libraries/x-121.smc.lib.mq5 index e879ab35..a4308927 100644 --- a/X121SMCEA/Libraries/x-121.smc.lib.mq5 +++ b/X121SMCEA/Libraries/x-121.smc.lib.mq5 @@ -37,6 +37,7 @@ const string X121SMCStrategyToken = "X121SMC"; // const string X121SMCXTestToken = "X121XTest"; const string X121SMCXPZToken = "X121XPZ"; +const string X121SMCXRSPVIToken = "X121XRSPVI"; const string X121SMCXSTRPVToken = "X121XSTRPV"; // @@ -47,6 +48,7 @@ enum ENUM_X_121_SMC_PROVIDERS X_121_SMC_PROVIDER_NONE, X_121_SMC_PROVIDER_XTEST, X_121_SMC_PROVIDER_XPZ, + X_121_SMC_PROVIDER_XRSPVI, X_121_SMC_PROVIDER_XSTRPV, }; @@ -711,6 +713,11 @@ string ToString(ENUM_X_121_SMC_PROVIDERS value) result = X121SMCXPZToken; break; + // + case X_121_SMC_PROVIDER_XRSPVI: + result = X121SMCXRSPVIToken; + break; + // case X_121_SMC_PROVIDER_XSTRPV: result = X121SMCXSTRPVToken; @@ -748,6 +755,10 @@ ENUM_X_121_SMC_PROVIDERS ParseProvider(string value) { result = X_121_SMC_PROVIDER_XPZ; } + else if (Contains(X121SMCXRSPVIToken, value)) + { + result = X_121_SMC_PROVIDER_XRSPVI; + } else if (Contains(X121SMCXSTRPVToken, value)) { result = X_121_SMC_PROVIDER_XSTRPV; diff --git a/X121SMCEA/Signals/x-121.smc.test.signal.lib.mq5 b/X121SMCEA/Signals/x-121.smc.test.signal.lib.mq5 deleted file mode 100644 index 24beeff4..00000000 --- a/X121SMCEA/Signals/x-121.smc.test.signal.lib.mq5 +++ /dev/null @@ -1,662 +0,0 @@ -/////////////////////////////////////////////////////// -// -// SaherElm IT Center MQL5 X121 SMC Signal Class -// ------------------------------------------------- -// Name: -// Description: provide all Signalling functions ... -// -// -// Maintainer: -// ------------ -// Hadi Khazaee Asl (hadi_khazaee_asl@yahoo.com) -// -////////////////////////////////////////////////////// -// -// Global Properties ... -#property library -#property copyright "Copyright 2023, SaherElm IT Center" -#property link "https://www.saherelm.ir" -#property version "1.00" -#property strict - -// -// Imports ... -#include "../Classes/x-121.smc.market.cycle.helper.class.mq5" -#include "../Libraries/x-121.smc.lib.mq5" - -// -// Definitions ... -struct X121SMCStrategyTestSignalConditions -{ - // - // Props ... - - // - string symbol; - ENUM_TIMEFRAMES period; - - // - double sl; - double target; - ENUM_X_DIRECTION dir; - ENUM_X_POSITION_TYPES type; - - // - // Setup Props ... - - // - datetime setupTime; - datetime triggerTime; - - // - // Constructor ... - X121SMCStrategyTestSignalConditions() - { - Clean(); - } - - // - // Tools ... - - /** - * Cleaning Up ... - */ - void Clean() - { - // - sl = 0; - 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() - { - } - - // -}; - -// -// Extension Functions ... - -// -// Detect Setup Conditions ... -bool DetectX121SMCTestSiganlSetup( - string _symbol, - ENUM_TIMEFRAMES _period, - // - X121SMCStrategyTestSignalConditions &conditions, - // - XC121SMCCycleHelper *triggerCycleHelper, - XC121SMCCycleHelper *decisionCycleHelper, - XC121SMCCycleHelper *analyseCycleHelper, - XC121SMCCycleHelper *verificationCycleHelper, - XC121SMCCycleHelper *consolidationCycleHelper, - XC121SMCCycleHelper *visionCycleHelper - // -) -{ - // - bool result = false; - - // - bool isBullish = false; - bool isBearish = false; - - // - int zIndex = 0; - int cIndex = zIndex + 1; - int pIndex = cIndex + 1; - int ppIndex = pIndex + 1; - - // - int loopback = 10; - - // - string symbol = _symbol; - ENUM_TIMEFRAMES period = _period; - - // - conditions.symbol = symbol; - conditions.period = period; - - // - XOHCL zBar; - result = zBar.Init( - symbol, - period, - zIndex // - ); - if (!result) - { - return result; - } - - // - XOHCL cBar; - result = cBar.Init( - symbol, - period, - cIndex // - ); - if (!result) - { - return result; - } - - // - double ask = GetAsk(symbol); - double bid = GetBid(symbol); - datetime cTime = TimeCurrent(); - - // - double ll = cBar.FindLowest(9, MODE_LOW); - double hh = cBar.FindHighest(9, MODE_HIGH); - - // - int zoneValidationDivider = 10; - int validPivotRepetition = 10; - - // - double selectedSL = 0; - - // - // Cycles Conditions ... - - // - // Trigger ... - ENUM_XPOI_EVENTS triggerPoiEvents[]; - ENUM_X_CYCLE_EVENTS triggerCycleEvents[]; - X121SMCCycleConditions triggerConditions; - result = triggerCycleHelper.GetConditions( - triggerCycleEvents, - triggerPoiEvents, - triggerConditions, - zIndex, - loopback // - ); - if (!result) - { - return result; - } - - // - // Decision ... - ENUM_XPOI_EVENTS decisionPoiEvents[]; - ENUM_X_CYCLE_EVENTS decisionCycleEvents[]; - X121SMCCycleConditions decisionConditions; - result = decisionCycleHelper.GetConditions( - decisionCycleEvents, - decisionPoiEvents, - decisionConditions, - zIndex, - loopback // - ); - if (!result) - { - return result; - } - - // - // Analyse ... - ENUM_XPOI_EVENTS analysePoiEvents[]; - ENUM_X_CYCLE_EVENTS analyseCycleEvents[]; - X121SMCCycleConditions analyseConditions; - result = analyseCycleHelper.GetConditions( - analyseCycleEvents, - analysePoiEvents, - analyseConditions, - zIndex, - loopback // - ); - if (!result) - { - return result; - } - - // - // Verification ... - ENUM_XPOI_EVENTS verificationPoiEvents[]; - ENUM_X_CYCLE_EVENTS verificationCycleEvents[]; - X121SMCCycleConditions verificationConditions; - result = verificationCycleHelper.GetConditions( - verificationCycleEvents, - verificationPoiEvents, - verificationConditions, - zIndex, - loopback // - ); - if (!result) - { - return result; - } - - // - // Consolidation ... - ENUM_XPOI_EVENTS consolidationPoiEvents[]; - ENUM_X_CYCLE_EVENTS consolidationCycleEvents[]; - X121SMCCycleConditions consolidationConditions; - result = consolidationCycleHelper.GetConditions( - consolidationCycleEvents, - consolidationPoiEvents, - consolidationConditions, - zIndex, - loopback // - ); - if (!result) - { - return result; - } - - // - // Vision ... - ENUM_XPOI_EVENTS visionPoiEvents[]; - ENUM_X_CYCLE_EVENTS visionCycleEvents[]; - X121SMCCycleConditions visionConditions; - result = visionCycleHelper.GetConditions( - visionCycleEvents, - visionPoiEvents, - visionConditions, - zIndex, - loopback // - ); - if (!result) - { - return result; - } - - // - // Cycles POI States ... - XPOIState triggerState = triggerConditions.state; - XPOIState decisionState = decisionConditions.state; - XPOIState analyseState = analyseConditions.state; - XPOIState verificationState = verificationConditions.state; - XPOIState consolidationState = consolidationConditions.state; - XPOIState visionState = visionConditions.state; - - // - // Setup Conditions ... - - // - isBullish = - // - false - // - ; - - // - isBearish = - // - false - // - ; - - // - result = isBullish || - isBearish; - if (!result) - { - // - // Clean Conditions for Regenerate ... - - // - return result; - } - - // - conditions.setupTime = cTime; - conditions.dir = - isBullish - ? X_DIRECTION_BULLISH - : X_DIRECTION_BEARISH; - - // - return result; -} - -// -// Detect Trigger Conditions ... -bool DetectX121SMCTestSiganlTrigger( - // - X121SMCStrategyTestSignalConditions &conditions, - // - string _symbol, - ENUM_TIMEFRAMES _period, - // - XC121SMCCycleHelper *triggerCycleHelper, - XC121SMCCycleHelper *decisionCycleHelper, - XC121SMCCycleHelper *analyseCycleHelper, - XC121SMCCycleHelper *verificationCycleHelper, - XC121SMCCycleHelper *consolidationCycleHelper, - XC121SMCCycleHelper *visionCycleHelper, - // - int maxAllowedSetupAge = 60 // - // -) -{ - // - bool result = false; - - // - result = conditions.IsSetuped(); - if (!result) - { - return result; - } - - // - datetime setupTime = conditions.setupTime; - ENUM_X_DIRECTION setupDir = conditions.dir; - - // - bool isBullish = false; - bool isBearish = false; - - // - int zIndex = 0; - int cIndex = zIndex + 1; - int pIndex = cIndex + 1; - int ppIndex = pIndex + 1; - - // - int loopback = 10; - - // - string symbol = _symbol; - ENUM_TIMEFRAMES period = _period; - - // - XOHCL zBar; - result = zBar.Init( - symbol, - period, - zIndex // - ); - if (!result) - { - return result; - } - - // - XOHCL cBar; - result = cBar.Init( - symbol, - period, - cIndex // - ); - if (!result) - { - return result; - } - - // - double ask = GetAsk(symbol); - double bid = GetBid(symbol); - datetime cTime = TimeCurrent(); - - // - double ll = cBar.FindLowest(9, MODE_LOW); - double hh = cBar.FindHighest(9, MODE_HIGH); - - // - int zoneValidationDivider = 10; - int validPivotRepetition = 10; - - // - double selectedSL = 0; - - // - // Cycles Conditions ... - - // - // Trigger ... - ENUM_XPOI_EVENTS triggerPoiEvents[]; - ENUM_X_CYCLE_EVENTS triggerCycleEvents[]; - X121SMCCycleConditions triggerConditions; - result = triggerCycleHelper.GetConditions( - triggerCycleEvents, - triggerPoiEvents, - triggerConditions, - zIndex, - loopback // - ); - if (!result) - { - return result; - } - - // - // Decision ... - ENUM_XPOI_EVENTS decisionPoiEvents[]; - ENUM_X_CYCLE_EVENTS decisionCycleEvents[]; - X121SMCCycleConditions decisionConditions; - result = decisionCycleHelper.GetConditions( - decisionCycleEvents, - decisionPoiEvents, - decisionConditions, - zIndex, - loopback // - ); - if (!result) - { - return result; - } - - // - // Analyse ... - ENUM_XPOI_EVENTS analysePoiEvents[]; - ENUM_X_CYCLE_EVENTS analyseCycleEvents[]; - X121SMCCycleConditions analyseConditions; - result = analyseCycleHelper.GetConditions( - analyseCycleEvents, - analysePoiEvents, - analyseConditions, - zIndex, - loopback // - ); - if (!result) - { - return result; - } - - // - // Verification ... - ENUM_XPOI_EVENTS verificationPoiEvents[]; - ENUM_X_CYCLE_EVENTS verificationCycleEvents[]; - X121SMCCycleConditions verificationConditions; - result = verificationCycleHelper.GetConditions( - verificationCycleEvents, - verificationPoiEvents, - verificationConditions, - zIndex, - loopback // - ); - if (!result) - { - return result; - } - - // - // Consolidation ... - ENUM_XPOI_EVENTS consolidationPoiEvents[]; - ENUM_X_CYCLE_EVENTS consolidationCycleEvents[]; - X121SMCCycleConditions consolidationConditions; - result = consolidationCycleHelper.GetConditions( - consolidationCycleEvents, - consolidationPoiEvents, - consolidationConditions, - zIndex, - loopback // - ); - if (!result) - { - return result; - } - - // - // Vision ... - ENUM_XPOI_EVENTS visionPoiEvents[]; - ENUM_X_CYCLE_EVENTS visionCycleEvents[]; - X121SMCCycleConditions visionConditions; - result = visionCycleHelper.GetConditions( - visionCycleEvents, - visionPoiEvents, - visionConditions, - zIndex, - loopback // - ); - if (!result) - { - return result; - } - - // - // Cycles POI States ... - XPOIState triggerState = triggerConditions.state; - XPOIState decisionState = decisionConditions.state; - XPOIState analyseState = analyseConditions.state; - XPOIState verificationState = verificationConditions.state; - XPOIState consolidationState = consolidationConditions.state; - XPOIState visionState = visionConditions.state; - - // - // Trigger Conditions ... - - // - isBullish = - // - false - // - ; - - // - isBearish = - // - false - // - ; - - // - result = isBullish || - isBearish; - if (!result) - { - // - // Cleanup Setup Conditions ... - int setupAge = conditions.GetSetupAge(); - if (IsValidSize(setupAge) && - IsValidSize(maxAllowedSetupAge) && - setupAge >= maxAllowedSetupAge) - { - conditions.Clean(); - } - - // - return result; - } - - // - conditions.triggerTime = cTime; - conditions.sl = isBullish - ? 0 - : 0; - conditions.type = isBullish - ? X_POSITION_TYPE_LONG - : X_POSITION_TYPE_SHORT; - - // - 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 2db1a801..c1e5c3a0 100644 --- a/X121SMCEA/Signals/x-121.smc.xpz.signal.lib.mq5 +++ b/X121SMCEA/Signals/x-121.smc.xpz.signal.lib.mq5 @@ -761,17 +761,6 @@ bool DetectX121SMCXPZSiganlSetup( ? X_DIRECTION_BULLISH : X_DIRECTION_BEARISH; - // - XCBaseObject *drawnObjects[]; - int drawnObjectsCount = triggerCycleHelper - .mPOIDetector - .mDrawer - .DrawPriceZone( - analysePriceZone, - drawnObjects, - pzDir // - ); - // conditions.priceZone = analysePriceZone; conditions.isPriceZoneValidForPeak = isAnalysePriceZoneValidForPeak; diff --git a/X121SMCEA/Signals/x-121.smc.xrspvi.signal.lib.mq5 b/X121SMCEA/Signals/x-121.smc.xrspvi.signal.lib.mq5 new file mode 100644 index 00000000..eb6d3f34 --- /dev/null +++ b/X121SMCEA/Signals/x-121.smc.xrspvi.signal.lib.mq5 @@ -0,0 +1,2137 @@ +/////////////////////////////////////////////////////// +// +// SaherElm IT Center MQL5 X121 SMC Signal Class +// ------------------------------------------------- +// Name: XRSPVI +// 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" + +// +enum ENUM_X121_SMC_XRSPVI_CONDITIONS +{ + // + X121_SMC_XRSPVI_CONDITION_NONE, + X121_SMC_XRSPVI_CONDITION_1, + X121_SMC_XRSPVI_CONDITION_2, + X121_SMC_XRSPVI_CONDITION_3, + X121_SMC_XRSPVI_CONDITION_4 +}; + +// +// Definitions ... +struct X121SMCStrategyXRSPVISignalConditions +{ + // + // 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; + + // + XPriceZones priceZone; + bool isPriceZoneValidForPeak; + bool isPriceZoneValidForVale; + + // + XConsolidationZone consolidationZone; + + // + ENUM_X121_SMC_XRSPVI_CONDITIONS mode; + + // + // Constructor ... + X121SMCStrategyXRSPVISignalConditions() + { + 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; + + // + priceZone.Clean(); + consolidationZone.Clean(); + isPriceZoneValidForPeak = false; + isPriceZoneValidForVale = false; + + // + mode = X121_SMC_XRSPVI_CONDITION_NONE; + } + + // +}; + +// +// Signaller Data Sources ... +X121SMCStrategyXRSPVISignalConditions mXRSPVIConditions; +X121SMCStrategyXRSPVISignalConditions mXRSPVIConditionsCollection[]; + +// +// Extension Functions ... + +// +// Detect Setup Conditions ... +bool DetectX121SMCXRSPVISiganlSetup( + string _symbol, + ENUM_TIMEFRAMES _period, + // + X121SMCStrategyXRSPVISignalConditions &conditions, + // + XC121SMCCycleHelper *triggerCycleHelper, + XC121SMCCycleHelper *decisionCycleHelper, + XC121SMCCycleHelper *analyseCycleHelper, + XC121SMCCycleHelper *verificationCycleHelper, + XC121SMCCycleHelper *consolidationCycleHelper, + XC121SMCCycleHelper *visionCycleHelper + // +) +{ + // + bool result = false; + + // + bool isBullish = false; + bool isBearish = false; + + // + int zIndex = 0; + int cIndex = zIndex + 1; + int pIndex = cIndex + 1; + int ppIndex = pIndex + 1; + + // + int loopback = 10; + + // + string symbol = _symbol; + ENUM_TIMEFRAMES period = _period; + + // + conditions.symbol = symbol; + conditions.period = period; + + // + XOHCL zBar; + result = zBar.Init( + symbol, + period, + zIndex // + ); + if (!result) + { + return result; + } + + // + XOHCL cBar; + result = cBar.Init( + symbol, + period, + cIndex // + ); + if (!result) + { + return result; + } + + // + XOHCL pBar; + result = pBar.Init( + symbol, + period, + pIndex // + ); + if (!result) + { + return result; + } + + // + double ask = GetAsk(symbol); + double bid = GetBid(symbol); + datetime cTime = TimeCurrent(); + double points = GetPoints(symbol); + + // + int swingLoopback = 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 consolidationMarketDir; + bool hasConsolidationMarketDir = consolidationCycleHelper + .DetectMarketStructure(consolidationMarketDir); + + // + bool hasConsolidationBullishTrend = + hasConsolidationMarketDir && + IsBullish(consolidationMarketDir); + + // + bool hasConsolidationBearishTrend = + hasConsolidationMarketDir && + IsBearish(consolidationMarketDir); + + // + // Verification ... + ENUM_X_DIRECTION verificationMarketDir; + bool hasVerificationMarketDir = verificationCycleHelper + .DetectMarketStructure(verificationMarketDir); + + // + bool hasVerificationBullishTrend = + hasVerificationMarketDir && + IsBullish(verificationMarketDir); + + // + bool hasVerificationBearishTrend = + hasVerificationMarketDir && + IsBearish(verificationMarketDir); + + // + // Analyse ... + ENUM_X_DIRECTION analyseMarketDir; + bool hasAnalyseMarketDir = analyseCycleHelper + .DetectMarketStructure(analyseMarketDir); + + // + bool hasAnalyseBullishTrend = + hasAnalyseMarketDir && + IsBullish(analyseMarketDir); + + // + bool hasAnalyseBearishTrend = + hasAnalyseMarketDir && + IsBearish(analyseMarketDir); + + // + // Decision ... + ENUM_X_DIRECTION decisionMarketDir; + bool hasDecisionMarketDir = decisionCycleHelper + .DetectMarketStructure(decisionMarketDir); + + // + bool hasDecisionBullishTrend = + hasDecisionMarketDir && + IsBullish(decisionMarketDir); + + // + bool hasDecisionBearishTrend = + hasDecisionMarketDir && + IsBearish(decisionMarketDir); + + // + // Detect Bar State ... + + // + // 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); + + // + // HH/LL Break ... + + // + bool isCBarBreaksUpHH = IsBarBreak( + hh, + X_DIRECTION_BULLISH, + cBar // + ); + + // + bool isCBarBreaksDownLL = IsBarBreak( + hh, + X_DIRECTION_BEARISH, + cBar // + ); + + // + // Bar Checking Summary ... + + // + // Bullish ... + bool isCBarBullishFormed = + // + isCBarBreaksUpHH || + isCBarBullishEngulfed || + isCBarBullishMomentum || + isCBarBullishRejected + // + ; + + // + // Bearish ... + bool isCBarBearishFormed = + // + isCBarBreaksDownLL || + isCBarBearishEngulfed || + isCBarBearishMomentum || + isCBarBearishRejected + // + ; + + // + // 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 isDecisionPriceZoneBullish = false; + bool isDecisionPriceZoneBearish = false; + 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; + + // + isDecisionPriceZoneBullish = + hasBoundary && + decisionPriceZone.IsBullish(); + + // + isDecisionPriceZoneBearish = + hasBoundary && + decisionPriceZone.IsBearish(); + } + + // + // Detecting Analyse Price ones ... + XPriceZones analysePriceZone; + bool hasAnalysePriceZone = CalculatePriceInsideZones( + analysePriceZone, + analyseState, + cBar // + ); + double analysePriceZoneUpper = 0; + double analysePriceZoneLower = 0; + bool isAnalysePriceZoneBullish = false; + bool isAnalysePriceZoneBearish = false; + 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; + + // + isAnalysePriceZoneBullish = + hasBoundary && + analysePriceZone.IsBullish(); + + // + isAnalysePriceZoneBearish = + hasBoundary && + analysePriceZone.IsBearish(); + } + + // + // Detecting Verification Price ones ... + XPriceZones verificationPriceZone; + bool hasVerificationPriceZone = CalculatePriceInsideZones( + verificationPriceZone, + verificationState, + cBar // + ); + double verificationPriceZoneUpper = 0; + double verificationPriceZoneLower = 0; + bool isVerificationPriceZoneBullish = false; + bool isVerificationPriceZoneBearish = false; + 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; + + // + isVerificationPriceZoneBullish = + hasBoundary && + verificationPriceZone.IsBullish(); + + // + isVerificationPriceZoneBearish = + hasBoundary && + verificationPriceZone.IsBearish(); + } + + // + // Detect Consolidation Zone ... + int decisionConsolidationLoopback = 7; + double decisionConsolidationZoneLower = 0; + double decisionConsolidationZoneUpper = 0; + bool isDecisionConsolidationZoneBreaked = false; + bool isDecisionConsolidationZoneBreakedUp = false; + bool isDecisionConsolidationZoneBreakedDown = false; + bool hasDecisionConsolidationZone = conditions.consolidationZone.IsValid(); + + // + if (!hasDecisionConsolidationZone) + { + // + XOHCL decisionCBar; + bool isInited = decisionCBar.Init( + decisionCycleHelper.GetSymbol(), + decisionCycleHelper.GetPeriod(), + cIndex // + ); + + // + if (isInited) + { + // + double upper = 0; + double lower = 0; + hasDecisionConsolidationZone = + triggerCycleHelper + .mBarAnalyser + .IsConsolidate( + decisionCBar, + upper, + lower, + decisionConsolidationLoopback // + ); + + // + if (hasDecisionConsolidationZone) + { + // + hasDecisionConsolidationZone = conditions.consolidationZone.Init( + cBar.symbol, + cBar.period, + upper, + lower, + decisionConsolidationLoopback // + ); + } + } + } + + // + if (hasDecisionConsolidationZone) + { + // + conditions.consolidationZone.Update(); + + // + decisionConsolidationZoneLower = conditions.consolidationZone.upper; + decisionConsolidationZoneUpper = conditions.consolidationZone.lower; + + // + isDecisionConsolidationZoneBreaked = conditions.consolidationZone.IsBreaked(); + isDecisionConsolidationZoneBreakedUp = + isDecisionConsolidationZoneBreaked && + IsBullish(conditions.consolidationZone.breakDirection); + isDecisionConsolidationZoneBreakedDown = + isDecisionConsolidationZoneBreaked && + IsBearish(conditions.consolidationZone.breakDirection); + + // + decisionConsolidationZoneLower = triggerXConditions.peaksBuffer[1]; + decisionConsolidationZoneUpper = triggerXConditions.valesBuffer[1]; + + // + if (isDecisionConsolidationZoneBreaked) + { + conditions.consolidationZone.Clean(); + } + } + + // + // + // + + // + double decisionPVMiddle = decisionXConditions.valesBuffer[1] + + (decisionXConditions.peaksBuffer[1] - decisionXConditions.valesBuffer[1]) / 2; + bool isInDecisionPremium = + // + ask > decisionPVMiddle && + bid > decisionPVMiddle && + // + ask < decisionXConditions.peaksBuffer[1] && + bid < decisionXConditions.peaksBuffer[1] + // + ; + bool isInDecisionDiscount = + // + ask < decisionPVMiddle && + bid < decisionPVMiddle && + // + ask < decisionXConditions.valesBuffer[1] && + bid < decisionXConditions.valesBuffer[1] + // + ; + + // + double analysePVMiddle = analyseXConditions.valesBuffer[1] + + (analyseXConditions.peaksBuffer[1] - analyseXConditions.valesBuffer[1]) / 2; + bool isInAnalysePremium = + // + ask > analysePVMiddle && + bid > analysePVMiddle && + // + ask < analyseXConditions.peaksBuffer[1] && + bid < analyseXConditions.peaksBuffer[1] + // + ; + bool isInAnalyseDiscount = + // + ask < analysePVMiddle && + bid < analysePVMiddle && + // + ask < analyseXConditions.valesBuffer[1] && + bid < analyseXConditions.valesBuffer[1] + // + ; + + // + double verificationPVMiddle = verificationXConditions.valesBuffer[1] + + (verificationXConditions.peaksBuffer[1] - verificationXConditions.valesBuffer[1]) / 2; + bool isInVerificationPremium = + // + ask > verificationPVMiddle && + bid > verificationPVMiddle && + // + ask < verificationXConditions.peaksBuffer[1] && + bid < verificationXConditions.peaksBuffer[1] + // + ; + bool isInVerificationDiscount = + // + ask < verificationPVMiddle && + bid < verificationPVMiddle && + // + ask < verificationXConditions.valesBuffer[1] && + bid < verificationXConditions.valesBuffer[1] + // + ; + + // + // Summarize Conditions ... + + // + bool isCond1Bullish = + // + isInAnalyseDiscount && + isInDecisionDiscount && + isCBarBullishFormed && + // + hasAnalysePriceZone && + isAnalysePriceZoneBullish && + isAnalysePriceZoneValidForVale && + // + analyseXConditions.isRsiCrossedOverOverSold && + // + true + // + ; + + // + bool isCond1Bearish = + // + isInAnalysePremium && + isInDecisionPremium && + isCBarBearishFormed && + // + hasAnalysePriceZone && + isAnalysePriceZoneBearish && + isAnalysePriceZoneValidForPeak && + // + analyseXConditions.isRsiCrossedUnderOverBought && + // + true + // + ; + + // + bool hasCond1Condition = isCond1Bullish || + isCond1Bearish; + if (hasCond1Condition) + { + // + conditions.mode = X121_SMC_XRSPVI_CONDITION_1; + + // + ENUM_X_DIRECTION pzDir = + isCond1Bullish + ? 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 ... + + // + conditions.point = point; + + // + // Manipulate Conditions Pivot ... + + // + conditions.pivot = + isCond1Bullish + ? pzVale + : pzPeak; + } + + // + // + // + + // + bool isCond2Bullish = + // + hasDecisionBullishTrend && + // + isCBarBullishFormed && + isInAnalyseDiscount && + isInVerificationDiscount && + // + hasVerificationPriceZone && + isVerificationPriceZoneBullish && + isVerificationPriceZoneValidForVale && + // + verificationXConditions.isRsiCrossedOverOverSold && + // + true + // + ; + + // + bool isCond2Bearish = + // + hasDecisionBearishTrend && + // + isCBarBearishFormed && + isInAnalysePremium && + isInVerificationPremium && + // + hasVerificationPriceZone && + isVerificationPriceZoneBearish && + isVerificationPriceZoneValidForPeak && + // + verificationXConditions.isRsiCrossedUnderOverBought && + // + true + // + ; + + // + bool hasCond2Condition = isCond2Bullish || + isCond2Bearish; + if (hasCond2Condition) + { + // + conditions.mode = X121_SMC_XRSPVI_CONDITION_2; + + // + ENUM_X_DIRECTION pzDir = + isCond2Bullish + ? X_DIRECTION_BULLISH + : X_DIRECTION_BEARISH; + + // + conditions.priceZone = verificationPriceZone; + conditions.isPriceZoneValidForPeak = isVerificationPriceZoneValidForPeak; + conditions.isPriceZoneValidForVale = isVerificationPriceZoneValidForVale; + + // + pzPeak = verificationPriceZoneUpper; + pzVale = verificationPriceZoneLower; + + // + double point = GetEntry( + conditions.symbol, + pzDir // + ); + + // + // Manipulate Conditions Point ... + + // + conditions.point = point; + + // + // Manipulate Conditions Pivot ... + + // + conditions.pivot = + isCond2Bullish + ? pzVale + : pzPeak; + } + + // + // + // + + // + bool isCond3Bullish = + // + isCBarBullishFormed && + hasDecisionBullishTrend && + decisionXConditions.isSarBullish && + decisionXConditions.isStrCrossedOverVale && + // + true + // + ; + + // + bool isCond3Bearish = + // + isCBarBearishFormed && + hasDecisionBearishTrend && + decisionXConditions.isSarBearish && + decisionXConditions.isStrCrossedUnderPeak && + // + true + // + ; + + // + bool hasCond3Conditions = isCond3Bullish || + isCond3Bearish; + if (hasCond3Conditions) + { + // + conditions.mode = X121_SMC_XRSPVI_CONDITION_3; + + // + ENUM_X_DIRECTION pzDir = + isCond3Bullish + ? X_DIRECTION_BULLISH + : X_DIRECTION_BEARISH; + + // + // Manipulate Conditions Point ... + + // + conditions.point = decisionXConditions.strBuffer[1]; + + // + // Manipulate Conditions Pivot ... + + // + double pivot = decisionXConditions.sarBuffer[1]; + pivot = (decisionXConditions.sarBuffer[1] + decisionXConditions.strBuffer[1]) / 2; + + // + conditions.pivot = + isCond3Bullish + ? pivot + : pivot; + } + + // + // + // + + // + bool isCond4Bullish = + // + isCBarBullishFormed && + isInDecisionDiscount && + hasDecisionBullishTrend && + hasDecisionConsolidationZone && + isDecisionConsolidationZoneBreakedUp && + // + true + // + ; + + // + bool isCond4Bearish = + // + isInDecisionPremium && + isCBarBearishFormed && + hasDecisionBearishTrend && + hasDecisionConsolidationZone && + isDecisionConsolidationZoneBreakedDown && + // + true + // + ; + + // + bool hasCond4Conditions = isCond4Bullish || + isCond4Bearish; + if (hasCond4Conditions) + { + // + conditions.mode = X121_SMC_XRSPVI_CONDITION_4; + + // + ENUM_X_DIRECTION pzDir = + isCond4Bullish + ? X_DIRECTION_BULLISH + : X_DIRECTION_BEARISH; + + // + // Manipulate Conditions Point ... + + // + double point = GetEntry( + conditions.symbol, + pzDir // + ); + + // + conditions.point = point; + + // + // Manipulate Conditions Pivot ... + + // + pzPeak = decisionConsolidationZoneUpper; + pzVale = decisionConsolidationZoneLower; + + // + conditions.pivot = + isCond4Bullish + ? pzVale + : pzPeak; + } + + // + isBullish = + isCond1Bullish || + isCond2Bullish || + isCond3Bullish || + isCond4Bullish; + + // + isBearish = + isCond1Bearish || + isCond2Bearish || + isCond3Bearish || + isCond4Bearish; + + // + 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 DetectX121SMCXRSPVISiganlTrigger( + // + X121SMCStrategyXRSPVISignalConditions &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 = IsBarBreak( + point, + setupDir, + cBar // + ); + + // + bool isCond124 = + // + conditions.mode == X121_SMC_XRSPVI_CONDITION_1 || + conditions.mode == X121_SMC_XRSPVI_CONDITION_2 || + conditions.mode == X121_SMC_XRSPVI_CONDITION_4 + // + ; + + // + // Summary ... + + // + isBullish = + // + isBullish && + isSlopesBullish && + cBar.IsBullish() && + ( + // + (isCond124 && + isPointBreaked) + // + || + // + (!isCond124 && + decisionXConditions.isStrBullish && + decisionXConditions.isStrSlopeBullish && + decisionXConditions.strBuffer[1] > conditions.point && + decisionXConditions.strBuffer[1] > decisionXConditions.strBuffer[2]) + // + ) + // + ; + + // + isBearish = + // + isBearish && + isSlopesBearish && + cBar.IsBearish() && + ( + // + (isCond124 && + isPointBreaked) + // + || + // + (!isCond124 && + decisionXConditions.isStrBearish && + decisionXConditions.isStrSlopeBearish && + decisionXConditions.strBuffer[1] < conditions.point && + decisionXConditions.strBuffer[1] < decisionXConditions.strBuffer[2]) + // + ) + // + ; + + // + 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]; + + // + 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 DetectX121SMCXRSPVIGuards( + 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_XRSPVI); + + // + result = DetectX121SMCGuards( + provider, + guards, + positions, + triggerCycleHelper, + decisionCycleHelper, + analyseCycleHelper, + verificationCycleHelper, + consolidationCycleHelper, + visionCycleHelper // + ); + + // + return result; +} + +// +int AddX121SMCXRSPVIConditionsIfNotExists( + X121SMCStrategyXRSPVISignalConditions &item, + X121SMCStrategyXRSPVISignalConditions &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 ... + X121SMCStrategyXRSPVISignalConditions tmpItems[]; + Copy( + items, + tmpItems // + ); + + // + // Prese Item Data ... + bool isBullish = IsBullish(item.dir); + + // + for (int i = 0; i < count; i++) + { + // + X121SMCStrategyXRSPVISignalConditions 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 DrawX121SMCXRSPVIConditions( + X121SMCStrategyXRSPVISignalConditions &conditions, + XCBaseObject *&drawnObjects[], + XCPOIDrawer *drawer // +) +{ + // + int result = 0; + + // + Clean(drawnObjects); + + // + if (drawer == NULL) + { + return result; + } + + // + bool isSetuped = conditions.IsSetuped(); + if (!isSetuped) + { + return result; + } + + // + bool hasPriceZone = conditions.priceZone.IsValid(); + if (!hasPriceZone) + { + return result; + } + + // + int zonesObjCount = drawer.DrawPriceZone( + conditions.priceZone, + drawnObjects, + conditions.dir // + ); + result = zonesObjCount; + + // + return result; +} + +// diff --git a/X121SMCEA/Strategy/x-121.smc.strategy.class.mq5 b/X121SMCEA/Strategy/x-121.smc.strategy.class.mq5 index 427aa87b..ac4e5a5d 100644 --- a/X121SMCEA/Strategy/x-121.smc.strategy.class.mq5 +++ b/X121SMCEA/Strategy/x-121.smc.strategy.class.mq5 @@ -28,6 +28,7 @@ // #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 // // Props ... bool useXPZSignal; + bool useXRSPVISignal; bool useXSTRPVSignal; // @@ -64,7 +66,10 @@ class XCX121SMCStrategy : public XCX121SMCBaseStrategy { // Destroy(); + + // ArrayFree(mXPZConditionsCollection); + ArrayFree(mXRSPVIConditionsCollection); ArrayFree(mXSTRPVConditionsCollection); } @@ -191,10 +196,11 @@ class XCX121SMCStrategy : public XCX121SMCBaseStrategy // bool hasXPZSignal = false; + bool hasXRSPVISignal = false; bool hasXSTRPVSignal = false; // - // XOBGPV Signal ... + // XPZ Signal ... if (useXPZSignal && !hasSignal) { // @@ -202,6 +208,15 @@ class XCX121SMCStrategy : public XCX121SMCBaseStrategy hasSignal = hasXPZSignal; } + // + // XRSPVI Signal ... + if (useXRSPVISignal && !hasSignal) + { + // + hasXRSPVISignal = DetectXRSPVISignal(conditions); + hasSignal = hasXRSPVISignal; + } + // // XSTRPV Signal ... if (useXSTRPVSignal && !hasSignal) @@ -400,6 +415,23 @@ class XCX121SMCStrategy : public XCX121SMCBaseStrategy ); } + // + // XRSPVI Guard Detection ... + if (useXRSPVISignal) + { + // + bool hasGuard = DetectX121SMCXRSPVIGuards( + guards, + positions, + mTriggerCycleHelper, + mDecisionCycleHelper, + mAnalyseCycleHelper, + mVerificationCycleHelper, + mConsolidationCycleHelper, + mVisionCycleHelper // + ); + } + // count = ArraySize(guards); result = IsValidSize(count); @@ -634,14 +666,6 @@ class XCX121SMCStrategy : public XCX121SMCBaseStrategy 1 // ); - // - XCBaseObject *objects[]; - DrawX121SMCXSTRPVConditions( - mConditions, - objects, - mPOIDrawer // - ); - // // Check Signal Direction ... isBullish = IsBullish(mConditions.dir); @@ -861,11 +885,221 @@ class XCX121SMCStrategy : public XCX121SMCBaseStrategy ); // - XCBaseObject *objects[]; - DrawX121SMCXPZConditions( - mConditions, - objects, - mPOIDrawer // + // 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( + 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_XRSPVI; + string providerStr = ToString(provider); + + // + // Detect Setup Conditions ... + datetime setupTime = mXRSPVIConditions.setupTime; + bool isSetuped = mXRSPVIConditions.IsSetuped(); + ENUM_X_DIRECTION setupDir = mXRSPVIConditions.dir; + if (!isSetuped) + { + // + // Detect Signal Setup ... + isSetuped = DetectX121SMCXRSPVISiganlSetup( + symbol, + period, + mXRSPVIConditions, + mTriggerCycleHelper, + mDecisionCycleHelper, + mAnalyseCycleHelper, + mVerificationCycleHelper, + mConsolidationCycleHelper, + mVisionCycleHelper // + ); + + // + setupDir = mXRSPVIConditions.dir; + setupTime = mXRSPVIConditions.setupTime; + + // + if (isSetuped) + { + // + int items = AddX121SMCXRSPVIConditionsIfNotExists( + mXRSPVIConditions, + mXRSPVIConditionsCollection // + ); + + // + mXRSPVIConditions.Clean(); + } + } + + // + int conditionsCount = ArraySize(mXRSPVIConditionsCollection); + result = IsValidSize(conditionsCount); + if (!result) + { + return result; + } + + // + // Looking For Conditions ... + int selectedIndex = 0; + X121SMCStrategyXRSPVISignalConditions mTmpConditions[]; + Copy( + mXRSPVIConditionsCollection, + mTmpConditions // + ); + X121SMCStrategyXRSPVISignalConditions 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 = DetectX121SMCXRSPVISiganlTrigger( + mTmpConditions[i], + symbol, + period, + mTriggerCycleHelper, + mDecisionCycleHelper, + mAnalyseCycleHelper, + mVerificationCycleHelper, + mConsolidationCycleHelper, + mVisionCycleHelper // + ); + + // + result = canTrigger; + if (!result) + { + // + bool isISetuped = mTmpConditions[i].IsSetuped(); + if (!isISetuped) + { + // + ArrayRemove( + mXRSPVIConditionsCollection, + 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( + mXRSPVIConditionsCollection, + selectedIndex, + 1 // ); // @@ -906,6 +1140,7 @@ class XCX121SMCStrategy : public XCX121SMCBaseStrategy { // useXPZSignal = true; + useXRSPVISignal = true; useXSTRPVSignal = true; //