From 4eba93231a7d70a06a3f52a237b3693e7e54d937 Mon Sep 17 00:00:00 2001 From: Hadi Khazaee Asl Date: Sun, 19 May 2024 03:51:48 +0330 Subject: [PATCH] test x5 provider reading Buffers correctly and also CanIgnoreProcess works properly ... --- Classes/x-saherelm.x5.provider.class.mq5 | 390 ++++++++++++++++++++++- Classes/x-saherelm.xprovider.class.mq5 | 6 +- Classes/x-saherelm.xtrade.class.mq5 | 108 +++---- Experts/x-test.x5ea.mq5 | 7 + Helpers/x-saherelm.xfi.helper.mq5 | 20 +- Libraries/x-saherelm.xtrade.lib.mq5 | 16 +- 6 files changed, 463 insertions(+), 84 deletions(-) diff --git a/Classes/x-saherelm.x5.provider.class.mq5 b/Classes/x-saherelm.x5.provider.class.mq5 index ed176710..252dc92e 100644 --- a/Classes/x-saherelm.x5.provider.class.mq5 +++ b/Classes/x-saherelm.x5.provider.class.mq5 @@ -109,7 +109,8 @@ public: // result = tsInputs.IsValid(); - if (!result) { + if (!result) + { return result; } @@ -258,12 +259,108 @@ public: // X5 Provider Market Conditions ... class X5MarketConditions : public XSCBaseProviderMarketConditions { - + // + // Public ... +public: // // Buffers ... + // + // XTS ... + double tsCurrents[]; + double tsNearests[]; + double tsMediests[]; + double tsFarests[]; + + // + // XFI ... + double fis[]; + + // + // XTD ... + double tdBullishs[]; + double tdBearishs[]; + double tdSignals[]; + + // + // XLH ... + double lhHhs[]; + double lhLls[]; + double lhSignals[]; + + // + // XTM ... + double tms[]; + + // + // XAMA ... + double amas[]; + + // + // XOBD ... + double obds[]; + + // + // XRSI ... + double rsis[]; + + // + // XCHMA ... + double chmaScFasts[]; + double chmaScSlows[]; + double chmaMcFasts[]; + double chmaMcSlows[]; + double chmaLcFasts[]; + double chmaLcSlows[]; + double chmaHotStates[]; + + // + // XCHLH ... + double chlhScHHs[]; + double chlhScLLs[]; + double chlhMcHHs[]; + double chlhMcLLs[]; + double chlhLcHHs[]; + double chlhLcLLs[]; + double chlhHotStates[]; + + // + // // Conditions ... + void Clear() + { + // + Clean(tsCurrents); + Clean(tsNearests); + Clean(tsMediests); + Clean(tsFarests); + Clean(fis); + Clean(tdBullishs); + Clean(tdBearishs); + Clean(tdSignals); + Clean(lhHhs); + Clean(lhLls); + Clean(lhSignals); + Clean(tms); + Clean(amas); + Clean(obds); + Clean(rsis); + Clean(chmaScFasts); + Clean(chmaScSlows); + Clean(chmaMcFasts); + Clean(chmaMcSlows); + Clean(chmaLcFasts); + Clean(chmaLcSlows); + Clean(chmaHotStates); + Clean(chlhScHHs); + Clean(chlhScLLs); + Clean(chlhMcHHs); + Clean(chlhMcLLs); + Clean(chlhLcHHs); + Clean(chlhLcLLs); + Clean(chlhHotStates); + } // // Generate Score ... @@ -335,6 +432,9 @@ public: amaHelper = new XSCXAMAHelper(); chmaHelper = new XSCXCHMAHelper(); chlhHelper = new XSCXCHLHHelper(); + + // + mNumberOfItems = 5; } // @@ -544,29 +644,300 @@ public: // Functions ... // - virtual bool GetMarketConditions( - X5MarketConditions &conditions, // Market Conditions Result - int barIndex = 0 // Specified Bar Index - ) + virtual string GetTag() { // - bool result = false; + string result = NULL; + + // + result = + // + GetToken() + + "[" + + GetSymbol() + + "," + + ToString(GetPeriod()) + + "]" + // + ; // return result; } + // + virtual void GetMarketConditions( + X5MarketConditions &mConditions, // Market Conditions Result + int barIndex = 0 // Specified Bar Index + ) + { + // + mConditions.Clear(); + + // + // XTM ... + tmHelper.CopyMain( + barIndex, + mNumberOfItems, + mConditions.tms); + + // + // XAMA ... + amaHelper.CopyMain( + barIndex, + mNumberOfItems, + mConditions.amas); + + // + // XFI ... + fiHelper.CopyMain( + barIndex, + mNumberOfItems, + mConditions.fis); + + // + // XOBD ... + obdHelper.CopyMain( + barIndex, + mNumberOfItems, + mConditions.obds); + + // + // XRSI ... + rsiHelper.CopyMain( + barIndex, + mNumberOfItems, + mConditions.rsis); + + // + // XLH ... + + // + // HH ... + lhHelper.CopyHH( + barIndex, + mNumberOfItems, + mConditions.lhHhs); + + // + // LL ... + lhHelper.CopyLL( + barIndex, + mNumberOfItems, + mConditions.lhLls); + + // + // Signal ... + lhHelper.CopySignal( + barIndex, + mNumberOfItems, + mConditions.lhSignals); + + // + // XTD ... + + // + // Bullish ... + tdHelper.CopyBullish( + barIndex, + mNumberOfItems, + mConditions.tdBullishs); + + // + // Bearish ... + tdHelper.CopyBearish( + barIndex, + mNumberOfItems, + mConditions.tdBearishs); + + // + // Signal ... + tdHelper.CopySignal( + barIndex, + mNumberOfItems, + mConditions.tdSignals); + + // + // XTS ... + + // + // Current ... + tsHelper.CopyCurrent( + barIndex, + mNumberOfItems, + mConditions.tsCurrents); + + // + // Nearest ... + tsHelper.CopyNearest( + barIndex, + mNumberOfItems, + mConditions.tsNearests); + + // + // Mediest ... + tsHelper.CopyMediest( + barIndex, + mNumberOfItems, + mConditions.tsMediests); + + // + // Farest ... + tsHelper.CopyFarest( + barIndex, + mNumberOfItems, + mConditions.tsFarests); + + // + // XCHMA ... + + // + // Short ... + + // + // Fast ... + chmaHelper.CopySCFast( + barIndex, + mNumberOfItems, + mConditions.chmaScFasts); + + // + // Slow ... + chmaHelper.CopySCSlow( + barIndex, + mNumberOfItems, + mConditions.chmaScSlows); + + // + // Medium ... + + // + // Fast ... + chmaHelper.CopyMCFast( + barIndex, + mNumberOfItems, + mConditions.chmaMcFasts); + + // + // Slow ... + chmaHelper.CopyMCSlow( + barIndex, + mNumberOfItems, + mConditions.chmaMcSlows); + + // + // Long ... + + // + // Fast ... + chmaHelper.CopyLCFast( + barIndex, + mNumberOfItems, + mConditions.chmaLcFasts); + + // + // Slow ... + chmaHelper.CopyLCSlow( + barIndex, + mNumberOfItems, + mConditions.chmaLcSlows); + + // + // Hot States ... + chmaHelper.CopyHotState( + barIndex, + mNumberOfItems, + mConditions.chmaHotStates); + + // + // XCHLH ... + + // + // Short ... + + // + // HH ... + chlhHelper.CopySCHH( + barIndex, + mNumberOfItems, + mConditions.chlhScHHs); + + // + // LL ... + chlhHelper.CopySCLL( + barIndex, + mNumberOfItems, + mConditions.chlhScLLs); + + // + // Medium ... + + // + // HH ... + chlhHelper.CopyMCHH( + barIndex, + mNumberOfItems, + mConditions.chlhMcHHs); + + // + // LL ... + chlhHelper.CopyMCLL( + barIndex, + mNumberOfItems, + mConditions.chlhMcLLs); + + // + // Long ... + + // + // HH ... + chlhHelper.CopyLCHH( + barIndex, + mNumberOfItems, + mConditions.chlhLcHHs); + + // + // LL ... + chlhHelper.CopyLCLL( + barIndex, + mNumberOfItems, + mConditions.chlhLcLLs); + + // + // Hot State ... + chlhHelper.CopyHotState( + barIndex, + mNumberOfItems, + mConditions.chlhHotStates); + } + // // Check Market For Signal ... virtual bool HasSignal( int barIndex, - XSignal &signal, // Hold's Signal if Exists ... - X5MarketConditions &conditions // Hold's Market Conditions ... + XSignal &mSignal, // Hold's Signal if Exists ... + X5MarketConditions &mConditions // Hold's Market Conditions ... ) { // bool result = false; + // + result = !CanIgnoreProcess(); + if (!result) + { + return result; + } + + // + GetMarketConditions(mConditions, barIndex); + + // + if (result) + { + Print(GetToken() + ", " + GetTag() + ", Salam"); + } + // return result; } @@ -582,6 +953,7 @@ protected: private: // // Props ... + int mNumberOfItems; // Number of Buffer Ites Read in Conditions ... // // Tools ... diff --git a/Classes/x-saherelm.xprovider.class.mq5 b/Classes/x-saherelm.xprovider.class.mq5 index 73715420..5f0bc3f6 100644 --- a/Classes/x-saherelm.xprovider.class.mq5 +++ b/Classes/x-saherelm.xprovider.class.mq5 @@ -110,8 +110,8 @@ public: mCycle.Init( symbol, period, - X_MARKET_CYCLE_UNKNOWN, - X_PERIOD_NOTHING, + X_MARKET_CYCLE_SHORT, + X_PERIOD_MANUALLY, period, "HOST Period" // @@ -148,7 +148,7 @@ public: virtual void DeInit(); // - virtual bool GetMarketConditions( + virtual void GetMarketConditions( XSCBaseProviderMarketConditions &conditions, // Market Conditions Result int barIndex = 0 // Specified Bar Index ); diff --git a/Classes/x-saherelm.xtrade.class.mq5 b/Classes/x-saherelm.xtrade.class.mq5 index 79793071..d83e326d 100644 --- a/Classes/x-saherelm.xtrade.class.mq5 +++ b/Classes/x-saherelm.xtrade.class.mq5 @@ -968,7 +968,7 @@ public: // // Check Spread is Ok for Executing Specific Signal ... - bool CheckSpreadForSignalExecution(XSignal &signal) + bool CheckSpreadForSignalExecution(XSignal &mSignal) { // bool result = false; @@ -983,7 +983,7 @@ public: { // // Retrieve Signal Spread ... - double spread = signal.GetSpread(); + double spread = mSignal.GetSpread(); result = spread <= mMaxAllowedSpread; } @@ -994,7 +994,7 @@ public: // // Check Account Policy ... bool CheckAccountPolicy( - XSignal &signal, // For Executing Signal + XSignal &mSignal, // For Executing Signal ENUM_X_SIGNAL_EXECUTION_RESULT &state // State Holder ) { @@ -1023,7 +1023,7 @@ public: // // Check Spread for Trade ... - result = CheckSpreadForSignalExecution(signal); + result = CheckSpreadForSignalExecution(mSignal); if (!result) { // @@ -1078,7 +1078,7 @@ public: // // Execute a Signal ... bool ExecuteSignal( - XSignal &signal, // Signal + XSignal &mSignal, // Signal ENUM_X_SIGNAL_EXECUTION_RESULT &state, // Result ENUM_ORDER_TYPE_TIME lifetime = ORDER_TIME_GTC, // Order LifeTime datetime expiration = NULL, // order expiration time @@ -1091,25 +1091,25 @@ public: // double currentEntry = GetEntry( - signal.symbol, - signal.type + mSignal.symbol, + mSignal.type // ); - bool isLong = IsLong(signal.type); + bool isLong = IsLong(mSignal.type); // // Select SL and TP ... // double selectedSL = 0; - signal.RegularSL(selectedSL); + mSignal.RegularSL(selectedSL); // double selectedTP = 0; - signal.RegularTP(selectedTP); + mSignal.RegularTP(selectedTP); // - if (!signal.IsValid()) + if (!mSignal.IsValid()) { // state = X_SIGNAL_EXECUTION_FAILED_INVALID_PARAMS; @@ -1118,13 +1118,13 @@ public: // // Handle Market Execution ... - if (signal.mode == X_ORDER_MODE_MARKET) + if (mSignal.mode == X_ORDER_MODE_MARKET) { // // Do Apply Policies here ... bool hasPolicy = !checkPolicies ? true - : CheckAccountPolicy(signal, state); + : CheckAccountPolicy(mSignal, state); if (!hasPolicy) { result = false; @@ -1136,13 +1136,13 @@ public: { // result = Buy( - signal.symbol, - signal.period, - signal.volume, - signal.entry, + mSignal.symbol, + mSignal.period, + mSignal.volume, + mSignal.entry, selectedSL, selectedTP, - signal.comment + mSignal.comment // ); } @@ -1150,13 +1150,13 @@ public: { // result = Sell( - signal.symbol, - signal.period, - signal.volume, - signal.entry, + mSignal.symbol, + mSignal.period, + mSignal.volume, + mSignal.entry, selectedSL, selectedTP, - signal.comment + mSignal.comment // ); } @@ -1164,7 +1164,7 @@ public: } // // Handle Stop Execution ... - else if (signal.mode == X_ORDER_MODE_STOP) + else if (mSignal.mode == X_ORDER_MODE_STOP) { // @@ -1173,8 +1173,8 @@ public: // // Check Price ... result = isLong - ? signal.entry > currentEntry - : signal.entry < currentEntry; + ? mSignal.entry > currentEntry + : mSignal.entry < currentEntry; if (!result) { // @@ -1188,15 +1188,15 @@ public: { // result = BuyStop( - signal.symbol, - signal.period, - signal.volume, - signal.entry, + mSignal.symbol, + mSignal.period, + mSignal.volume, + mSignal.entry, selectedSL, selectedTP, lifetime, expiration, - signal.comment + mSignal.comment // ); } @@ -1204,22 +1204,22 @@ public: { // result = SellStop( - signal.symbol, - signal.period, - signal.volume, - signal.entry, + mSignal.symbol, + mSignal.period, + mSignal.volume, + mSignal.entry, selectedSL, selectedTP, lifetime, expiration, - signal.comment + mSignal.comment // ); } } // // Handle Limit Execution ... - else if (signal.mode == X_ORDER_MODE_LIMIT) + else if (mSignal.mode == X_ORDER_MODE_LIMIT) { // // Check Conditions ... @@ -1227,8 +1227,8 @@ public: // // Check Price ... result = isLong - ? signal.entry < currentEntry - : signal.entry > currentEntry; + ? mSignal.entry < currentEntry + : mSignal.entry > currentEntry; if (!result) { // @@ -1242,15 +1242,15 @@ public: { // result = BuyLimit( - signal.symbol, - signal.period, - signal.volume, - signal.entry, + mSignal.symbol, + mSignal.period, + mSignal.volume, + mSignal.entry, selectedSL, selectedTP, lifetime, expiration, - signal.comment + mSignal.comment // ); } @@ -1258,15 +1258,15 @@ public: { // result = SellLimit( - signal.symbol, - signal.period, - signal.volume, - signal.entry, + mSignal.symbol, + mSignal.period, + mSignal.volume, + mSignal.entry, selectedSL, selectedTP, lifetime, expiration, - signal.comment + mSignal.comment // ); } @@ -1281,7 +1281,7 @@ public: // ulong ticket; - if (signal.mode == X_ORDER_MODE_MARKET) + if (mSignal.mode == X_ORDER_MODE_MARKET) { ticket = GetLastOpenPositionTicket(); } @@ -1291,11 +1291,11 @@ public: } // - signal.positionId = ticket; + mSignal.positionId = ticket; // // Handle Store XPositionInfo ... - if (signal.mode == X_ORDER_MODE_MARKET) + if (mSignal.mode == X_ORDER_MODE_MARKET) { // // TODO: Implement this ... @@ -1303,7 +1303,7 @@ public: // // Handle Executing Support Signals ... - int supportsCount = ArraySize(signal.supports); + int supportsCount = ArraySize(mSignal.supports); if (supportsCount > 0) { // @@ -1311,7 +1311,7 @@ public: for (int i = 0; i < supportsCount; i++) { // - XSignal iSupport = signal.supports[i]; + XSignal iSupport = mSignal.supports[i]; // int supIndex = i + 1; diff --git a/Experts/x-test.x5ea.mq5 b/Experts/x-test.x5ea.mq5 index 30a0bb5b..850d5552 100644 --- a/Experts/x-test.x5ea.mq5 +++ b/Experts/x-test.x5ea.mq5 @@ -47,8 +47,10 @@ MqlTick x5EATick; // // X5Provider ... +XSignal signal; X5ProviderInputs x5Inputs; XSCX5Provider *x5Provider; +X5MarketConditions conditions; // // Event Handlers ... @@ -134,6 +136,11 @@ void OnTick() { return; } + + // + signal.Clean(); + conditions.Clear(); + x5Provider.HasSignal(0, signal, conditions); } // diff --git a/Helpers/x-saherelm.xfi.helper.mq5 b/Helpers/x-saherelm.xfi.helper.mq5 index f0207604..c636da6d 100644 --- a/Helpers/x-saherelm.xfi.helper.mq5 +++ b/Helpers/x-saherelm.xfi.helper.mq5 @@ -275,16 +275,16 @@ private: // int totalBars = CountBars(); - // // - // // Short Exit 2 ... - // CopyBuffer( - // mHandler, - // X_CHE_SHORT_EXIT_2_LINE, - // 0, - // totalBars, - // shortExit2Buffer - // // - // ); + // + // Short Exit 2 ... + CopyBuffer( + mHandler, + XFI_MAIN_LINE, + 0, + totalBars, + mainBuffer + // + ); } }; diff --git a/Libraries/x-saherelm.xtrade.lib.mq5 b/Libraries/x-saherelm.xtrade.lib.mq5 index 2aa189b8..602c30de 100644 --- a/Libraries/x-saherelm.xtrade.lib.mq5 +++ b/Libraries/x-saherelm.xtrade.lib.mq5 @@ -2533,7 +2533,7 @@ struct XPositionInfo // Fill from a Signal ... // The Signal must Executed ... bool BySignal( - XSignal &signal // the Signal which need to use + XSignal &mSignal // the Signal which need to use ) { // @@ -2543,24 +2543,24 @@ struct XPositionInfo Clean(); // - result = signal.IsValid() && signal.IsExecuted() && signal.mode == X_ORDER_MODE_MARKET; + result = mSignal.IsValid() && mSignal.IsExecuted() && mSignal.mode == X_ORDER_MODE_MARKET; if (!result) { return result; } // - ticket = signal.positionId; - action = signal.action; + ticket = mSignal.positionId; + action = mSignal.action; // // Select TPS and SLS from signal ... // double sl = 0; - bool hasRegularSL = signal.RegularSL(sl); + bool hasRegularSL = mSignal.RegularSL(sl); Copy( - signal.sls, + mSignal.sls, sls // ); @@ -2576,9 +2576,9 @@ struct XPositionInfo // double tp = 0; - bool hasRegularTP = signal.RegularTP(tp); + bool hasRegularTP = mSignal.RegularTP(tp); Copy( - signal.tps, + mSignal.tps, tps // );