From 8611e4a2216becc3dbe50d9f7cf30fb1ab14584b Mon Sep 17 00:00:00 2001 From: Hadi Khazaee Asl Date: Sun, 1 Jun 2025 13:16:07 +0330 Subject: [PATCH] last ... --- Experts/x-saherelm.x121.xcatb.ea.mq5 | 4 +- XCATBEA/Classes/xcatbea.expert.class.mq5 | 9 ++- XCATBEA/Classes/xcatbea.signaller.class.mq5 | 33 ++++++++- .../Classes/xcatbea.x-trade.manager.class.mq5 | 36 +++++++++ XCATBEA/Libraries/xcatbea.lib.mq5 | 73 ++++++++++--------- 5 files changed, 114 insertions(+), 41 deletions(-) diff --git a/Experts/x-saherelm.x121.xcatb.ea.mq5 b/Experts/x-saherelm.x121.xcatb.ea.mq5 index f4542eb1..3d2e5167 100644 --- a/Experts/x-saherelm.x121.xcatb.ea.mq5 +++ b/Experts/x-saherelm.x121.xcatb.ea.mq5 @@ -87,7 +87,6 @@ input bool eaForceHasTrendDirOnBothSide = false; // TREND Must Has Following Dir input bool eaFilterBasedOnDelta = false; // Filter Based On Delta input bool eaFilterBasedOnVolume = false; // Filter Based On Volume input bool eaFilterBasedOnSignalBar = false; // Filter Based on Signal Bar -input bool eaFilterBasedOnRoundPrice = false; // Filter Based On Round Prices input bool eaFilterBasedOnHKSignalBar = false; // Filter Based On HK Signal Bar // @@ -110,7 +109,7 @@ input double eaConstantBalance = 0.0; // Constant Ba // // Management ... // eaSymbols => comma separated Symbols for Trading, use Default if not Provided ... -// eaSessions => (SYDNEY_02:00_14:00),(NY_19:00_23:00) +// eaSessions => (ST_04:00_08:30),(TL_10:30_12:00),(NY_16:00_19:00) input group "Management"; input string eaSymbols = ""; // Allowed Trading Symbols input bool eaAllowGuards = false; // Allow Guards @@ -256,7 +255,6 @@ int OnInit() eaExpert.eaFilterBasedOnDelta = eaFilterBasedOnDelta; eaExpert.eaFilterBasedOnVolume = eaFilterBasedOnVolume; eaExpert.eaFilterBasedOnSignalBar = eaFilterBasedOnSignalBar; - eaExpert.eaFilterBasedOnRoundPrice = eaFilterBasedOnRoundPrice; eaExpert.eaFilterBasedOnHKSignalBar = eaFilterBasedOnHKSignalBar; // diff --git a/XCATBEA/Classes/xcatbea.expert.class.mq5 b/XCATBEA/Classes/xcatbea.expert.class.mq5 index 8fb8e9c3..3ddd75ed 100644 --- a/XCATBEA/Classes/xcatbea.expert.class.mq5 +++ b/XCATBEA/Classes/xcatbea.expert.class.mq5 @@ -96,7 +96,6 @@ class XCXCATBEAExpert : public XCBase bool eaFilterBasedOnDelta; // Filter Based On Delta bool eaFilterBasedOnVolume; // Filter Based On Volume bool eaFilterBasedOnSignalBar; // Filter Based on Signal Bar - bool eaFilterBasedOnRoundPrice; // Filter Based On Round Prices bool eaFilterBasedOnHKSignalBar; // Filter Based On HK Signal Bar // @@ -535,7 +534,6 @@ class XCXCATBEAExpert : public XCBase iSignallerInputs.filters.filterBasedOnDelta = eaFilterBasedOnDelta; iSignallerInputs.filters.filterBasedOnVolume = eaFilterBasedOnVolume; iSignallerInputs.filters.filterBasedOnSignalBar = eaFilterBasedOnSignalBar; - iSignallerInputs.filters.filterBasedOnRoundPrice = eaFilterBasedOnRoundPrice; iSignallerInputs.filters.filterBasedOnHKSignalBar = eaFilterBasedOnHKSignalBar; // @@ -680,6 +678,10 @@ class XCXCATBEAExpert : public XCBase XPosition iPositions[]; // Retrieve Signaller Positions ... XCATBEAStrategyConditions iConditions; // Recieve Triggered Conditions ... + // + // Check Active Session ... + bool isActiveSession = eaTradeManager.IsActiveSession(iSymbol); + // // Reading Signaller Positions ... eaTradeManager.GetPositions( @@ -694,7 +696,8 @@ class XCXCATBEAExpert : public XCBase iSignaller.ProcessTick( iPositions, iGuards, - iConditions // + iConditions, + isActiveSession // ); // diff --git a/XCATBEA/Classes/xcatbea.signaller.class.mq5 b/XCATBEA/Classes/xcatbea.signaller.class.mq5 index 05fb21bf..39d277a1 100644 --- a/XCATBEA/Classes/xcatbea.signaller.class.mq5 +++ b/XCATBEA/Classes/xcatbea.signaller.class.mq5 @@ -182,7 +182,8 @@ class XCXCATBEASignaller : XCBase void ProcessTick( XPosition &positions[], XGuard &guards[], - XCATBEAStrategyConditions &conditions // + XCATBEAStrategyConditions &conditions, + bool isActiveSession = true // ) { // @@ -293,6 +294,16 @@ class XCXCATBEASignaller : XCBase return; } + // + // Here we Check Active Session ... + // and Prevent Moving forward if there is not + // Session actives ... + // for improvement Calculation Speeds ... + if (!isActiveSession) + { + return; + } + // // Initialize Bar ... bar.Init( @@ -504,9 +515,27 @@ class XCXCATBEASignaller : XCBase if (result && conditions.triggerBlock.IsValid()) { + // + // Checking Score ... + double bullishScore = 0; + double bearishScore = 0; + conditions + .conditions + .GenerateScore( + bullishScore, + bearishScore // + ); + bool isScorePassed = + isBullish + ? bullishScore > bearishScore + : bearishScore > bullishScore; + // // Complete Conditions Here ... - conditions.triggerTime = TimeCurrent(); + if (isScorePassed) + { + conditions.triggerTime = TimeCurrent(); + } } // diff --git a/XCATBEA/Classes/xcatbea.x-trade.manager.class.mq5 b/XCATBEA/Classes/xcatbea.x-trade.manager.class.mq5 index 5541c148..2b7539a1 100644 --- a/XCATBEA/Classes/xcatbea.x-trade.manager.class.mq5 +++ b/XCATBEA/Classes/xcatbea.x-trade.manager.class.mq5 @@ -1296,6 +1296,42 @@ class XCXCATBEATradeManager : public XCBaseAlert } } + /** + * Check Specified Symbol is Active for + * Analysing or Open Trades ... + */ + bool IsActiveSession(string symbol) + { + // + bool result = false; + + // + // Validate Args ... + result = IsValid(symbol); + if (!result) + { + return result; + } + + // + // Check Symbol Session Exists or not ... + int symbolSessionIDX = -1; + bool isSymbolSessionExists = FindSymbolSession( + symbolSessionIDX, + symbol // + ); + + // + // Chack Trade Session Validating ... + if (isSymbolSessionExists) + { + result = sessions[symbolSessionIDX].CanTrade(); + } + + // + return result; + } + /** * Check Signal Execution Conditions ... * diff --git a/XCATBEA/Libraries/xcatbea.lib.mq5 b/XCATBEA/Libraries/xcatbea.lib.mq5 index 65f6a96e..9df09be2 100644 --- a/XCATBEA/Libraries/xcatbea.lib.mq5 +++ b/XCATBEA/Libraries/xcatbea.lib.mq5 @@ -204,7 +204,6 @@ struct XTriggerBlockFilters bool filterBasedOnDelta; // Filter Based On Delta ... bool filterBasedOnVolume; // Filter Based On Volume ... bool filterBasedOnSignalBar; // Filter Based on Signal Bar ... - bool filterBasedOnRoundPrice; // Filter Based On Round Prices ... bool filterBasedOnHKSignalBar; // Filter Based On HK Signal Bar ... // @@ -263,7 +262,6 @@ struct XTriggerBlockFilters filterBasedOnDelta = false; filterBasedOnVolume = false; filterBasedOnSignalBar = false; - filterBasedOnRoundPrice = false; filterBasedOnHKSignalBar = false; // @@ -1361,34 +1359,52 @@ bool FilterTriggerBlock( iPFSarState >= 0; // - // Creating Filters ... + // Check SAR Direction ... // - bool isToFilterPassed = - !filters.forceSarSwitched - ? (isBullish - ? isSarBullish - : isSarBearish) - : (isBullish - ? isSarSwitchedToBullish - : isSarSwitchedToBearish); + if (result && + !filters.forceSarSwitched) + { + // + result = isBullish + ? isSarBullish + : isSarBearish; + } // - bool isFromFilterPassed = - !filters.forceSarSwitched - ? (isBullish - ? isFSarBullish - : isFSarBearish) - : (isBullish - ? isFSarSwitchedToBullish - : isFSarSwitchedToBearish); + if (result && + filters.forceSarSwitched) + { + // + result = isBullish + ? isSarSwitchedToBullish + : isSarSwitchedToBearish; + } // - result = - !filters.forceSarOnBothSide - ? isToFilterPassed - : isToFilterPassed && - isFromFilterPassed; + if (result && + filters.forceSarOnBothSide) + { + // + if (result && + !filters.forceSarSwitched) + { + // + result = isBullish + ? isFSarBullish + : isFSarBearish; + } + + // + if (result && + filters.forceSarSwitched) + { + // + result = isBullish + ? isFSarSwitchedToBullish + : isFSarSwitchedToBearish; + } + } // // Check Sar Has Reversal Direction inside Trigger Block ... @@ -2262,15 +2278,6 @@ bool FilterTriggerBlock( } } - // - // Filter Based Round Price ... - if (result && - filters.filterBasedOnRoundPrice) - { - // - // TODO: Implement this ... - } - // if (!result) {