From 753b99411f02457aea6061b047247ba5e148324a Mon Sep 17 00:00:00 2001 From: Hadi Khazaee Asl Date: Sat, 1 Jun 2024 03:51:48 +0330 Subject: [PATCH] complete scoring and summary generating in x121 market cycle conditions class ... --- Classes/x-saherelm.x121.provider.class.mq5 | 152 +-- Classes/x-saherelm.x121.xmcycle.class.mq5 | 1042 +++++++++++++++++++- Experts/x-test.x121ea.mq5 | 2 +- Libraries/x-saherelm.common.lib.mq5 | 107 +- 4 files changed, 1182 insertions(+), 121 deletions(-) diff --git a/Classes/x-saherelm.x121.provider.class.mq5 b/Classes/x-saherelm.x121.provider.class.mq5 index 4eaa6af4..a85a9898 100644 --- a/Classes/x-saherelm.x121.provider.class.mq5 +++ b/Classes/x-saherelm.x121.provider.class.mq5 @@ -44,21 +44,6 @@ // // Definitions ... -// -// Signallers ... -enum ENUM_X121_SIGNAL_PROVIDERS -{ - // - PROVIDER_NONE, - XSP, - XTEST, - X786, - X121, - X110, - X92, - X128, -}; - // // X121 Provider Inputs ... class X121ProviderInputs : public XSCBase @@ -1035,8 +1020,8 @@ public: // // Set Signal Providers ... void SetSignalProviderState( - ENUM_X121_SIGNAL_PROVIDERS provider, // Provider State - bool state // Which state is going to set ... + ENUM_XSIGNAL_PROVIDERS provider, // Provider State + bool state // Which state is going to set ... ) { // @@ -1087,8 +1072,8 @@ public: // void SetSignalProviderStates( - ENUM_X121_SIGNAL_PROVIDERS &providers[], // Collection of Providers ... - bool state // Which state is going to set ... + ENUM_XSIGNAL_PROVIDERS &providers[], // Collection of Providers ... + bool state // Which state is going to set ... ) { // @@ -3706,12 +3691,14 @@ private: bool condition1 = // ((cHasX786 && - sHasX786) + sHasX786 && + mHasX786) // || // (cHasX786 && - mHasX786)) + mHasX786 && + lHasX786)) // ; @@ -3719,12 +3706,14 @@ private: bool condition2 = // ((sHasX786 && - mHasX786) + mHasX786 && + lHasX786) // || // (sHasX786 && - lHasX786)) + lHasX786 && + hHasX786)) // ; @@ -3732,12 +3721,14 @@ private: bool condition3 = // ((mHasX786 && - lHasX786) + lHasX786 && + hHasX786) // || // (mHasX786 && - hHasX786)) + hHasX786 && + sHasX786)) // ; @@ -3745,7 +3736,8 @@ private: bool condition4 = // (lHasX786 && - hHasX786) + hHasX786 && + mHasX786) // ; @@ -4232,7 +4224,7 @@ private: // return result; } - + // bool X128HasSpecifiedShortSignal( X121MarketConditions &mConditions, // @@ -4259,12 +4251,12 @@ private: struct X121ProviderDescriptor { // - string symbol; // Trading Symbol - ENUM_TIMEFRAMES period; // Trading Timeframe - double staticVolume; // Static Volume for Positions - bool allowLong; // Allow Long Signals - bool allowShort; // Allow Short Signals - ENUM_X121_SIGNAL_PROVIDERS signallers[]; // Allowed Signal Providers + string symbol; // Trading Symbol + ENUM_TIMEFRAMES period; // Trading Timeframe + double staticVolume; // Static Volume for Positions + bool allowLong; // Allow Long Signals + bool allowShort; // Allow Short Signals + ENUM_XSIGNAL_PROVIDERS signallers[]; // Allowed Signal Providers // X121ProviderInputs inputs; @@ -4299,10 +4291,10 @@ struct X121ProviderDescriptor // bool Init( - ENUM_X121_SIGNAL_PROVIDERS &mSignallers[], // Allowed Signal Providers - bool mAllowLong = true, // Allow Long Signals - bool mAllowShort = true, // Allow Short Signals - double mStaticVolume = 0.01 // Static Volume for Positions + ENUM_XSIGNAL_PROVIDERS &mSignallers[], // Allowed Signal Providers + bool mAllowLong = true, // Allow Long Signals + bool mAllowShort = true, // Allow Short Signals + double mStaticVolume = 0.01 // Static Volume for Positions ) { // @@ -4324,12 +4316,12 @@ struct X121ProviderDescriptor // bool Init( - string mSymbol, // Trading Symbol - ENUM_TIMEFRAMES mPeriod, // Trading Timeframe - ENUM_X121_SIGNAL_PROVIDERS &mSignallers[], // Allowed Signal Providers - bool mAllowLong = true, // Allow Long Signals - bool mAllowShort = true, // Allow Short Signals - double mStaticVolume = 0.01 // Static Volume for Positions + string mSymbol, // Trading Symbol + ENUM_TIMEFRAMES mPeriod, // Trading Timeframe + ENUM_XSIGNAL_PROVIDERS &mSignallers[], // Allowed Signal Providers + bool mAllowLong = true, // Allow Long Signals + bool mAllowShort = true, // Allow Short Signals + double mStaticVolume = 0.01 // Static Volume for Positions ) { // @@ -4359,7 +4351,7 @@ struct X121ProviderDescriptor this.staticVolume = mStaticVolume; // - ENUM_X121_SIGNAL_PROVIDERS tmp[]; + ENUM_XSIGNAL_PROVIDERS tmp[]; Copy( mSignallers, tmp // @@ -4476,76 +4468,4 @@ struct X121ProviderDescriptor } }; -// -void GetAllX121SignalProviders(ENUM_X121_SIGNAL_PROVIDERS &result[]) -{ - // - Clean(result); - - // - Add(XSP, result); - Add(XTEST, result); - Add(X786, result); - Add(X121, result); - Add(X110, result); - Add(X92, result); - Add(X128, result); -} - -// -string ToString(ENUM_X121_SIGNAL_PROVIDERS value) -{ - return EnumToString(value); -} - -// -ENUM_X121_SIGNAL_PROVIDERS ToX121SignalProvider(string content) -{ - // - ENUM_X121_SIGNAL_PROVIDERS result = PROVIDER_NONE; - - // - if (!IsValid(content)) - { - return result; - } - - // - if (content == ToString(PROVIDER_NONE)) - { - result = PROVIDER_NONE; - } - else if (content == ToString(XSP)) - { - result = XSP; - } - else if (content == ToString(XTEST)) - { - result = XTEST; - } - else if (content == ToString(X786)) - { - result = X786; - } - else if (content == ToString(X121)) - { - result = X121; - } - else if (content == ToString(X110)) - { - result = X110; - } - else if (content == ToString(X92)) - { - result = X92; - } - else if (content == ToString(X128)) - { - result = X128; - } - - // - return result; -} - // \ No newline at end of file diff --git a/Classes/x-saherelm.x121.xmcycle.class.mq5 b/Classes/x-saherelm.x121.xmcycle.class.mq5 index 96e101c7..d2dd8802 100644 --- a/Classes/x-saherelm.x121.xmcycle.class.mq5 +++ b/Classes/x-saherelm.x121.xmcycle.class.mq5 @@ -45,6 +45,93 @@ // // Definitions ... +// +// Signallers ... +enum ENUM_XSIGNAL_PROVIDERS +{ + // + PROVIDER_NONE, + XSP, + XTEST, + X786, + X121, + X110, + X92, + X128, +}; + +// +void GetAllXSignalProviders(ENUM_XSIGNAL_PROVIDERS &result[]) +{ + // + Clean(result); + + // + Add(XSP, result); + Add(XTEST, result); + Add(X786, result); + Add(X121, result); + Add(X110, result); + Add(X92, result); + Add(X128, result); +} + +// +string ToString(ENUM_XSIGNAL_PROVIDERS value) +{ + return EnumToString(value); +} + +// +ENUM_XSIGNAL_PROVIDERS ToXSignalProvider(string content) +{ + // + ENUM_XSIGNAL_PROVIDERS result = PROVIDER_NONE; + + // + if (!IsValid(content)) + { + return result; + } + + // + if (content == ToString(PROVIDER_NONE)) + { + result = PROVIDER_NONE; + } + else if (content == ToString(XSP)) + { + result = XSP; + } + else if (content == ToString(XTEST)) + { + result = XTEST; + } + else if (content == ToString(X786)) + { + result = X786; + } + else if (content == ToString(X121)) + { + result = X121; + } + else if (content == ToString(X110)) + { + result = X110; + } + else if (content == ToString(X92)) + { + result = X92; + } + else if (content == ToString(X128)) + { + result = X128; + } + + // + return result; +} + // // X121 Specified Market Cycle Structure ... class X121MCycleInputs : public XSCBase @@ -1220,42 +1307,54 @@ public: // Candlestic ... if (isLastBullish) { + bullScore++; } if (isLastBearish) { + bearScore++; } if (isCurrentBullish) { + bullScore++; } if (isCurrentBearish) { + bearScore++; } if (isCurrentMidLineOverLastHigh) { + bullScore++; } if (isCurrentMidLineUnderLastLow) { + bearScore++; } if (isCurrentMidLineOverLastUp) { + bullScore++; } if (isCurrentMidLineUnderLastDown) { + bearScore++; } if (isCurrentMidLineOverLastMidLine) { + bullScore++; } if (isCurrentMidLineUnderLastMidLine) { + bearScore++; } // // XZG ... if (isZigZagInPeak) { + bullScore++; } if (isZigZagInVale) { + bearScore++; } // @@ -1264,6 +1363,7 @@ public: // if (isNewPeak) { + bearScore++; } if (isNewPeakOverLast) { @@ -1275,6 +1375,7 @@ public: // if (isNewVale) { + bullScore++; } if (isNewValeOverLast) { @@ -1286,9 +1387,11 @@ public: // if (isFiboIncreased) { + bullScore++; } if (isFiboDecreased) { + bearScore++; } if (isFiboSectionChanged) { @@ -1300,40 +1403,53 @@ public: // if (isSCBullish) { + bullScore++; } if (isSCHHBullish) { + bullScore++; } if (isSCLLBullish) { + bullScore++; } if (isSCSwitchedToBullish) { + bullScore++; } if (isSCHHSwitchedToBullish) { + bullScore++; } if (isSCLLSwitchedToBullish) { + bullScore++; } + // if (isSCBearish) { + bearScore++; } if (isSCHHBearish) { + bearScore++; } if (isSCLLBearish) { + bearScore++; } if (isSCSwitchedToBearish) { + bearScore++; } if (isSCHHSwitchedToBearish) { + bearScore++; } if (isSCLLSwitchedToBeraish) { + bearScore++; } // @@ -1342,41 +1458,53 @@ public: // if (isMCBullish) { + bullScore++; } if (isMCHHBullish) { + bullScore++; } if (isMCLLBullish) { + bullScore++; } if (isMCSwitchedToBullish) { + bullScore++; } if (isMCHHSwitchedToBullish) { + bullScore++; } if (isMCLLSwitchedToBullish) { + bullScore++; } // if (isMCBearish) { + bearScore++; } if (isMCHHBearish) { + bearScore++; } if (isMCLLBearish) { + bearScore++; } if (isMCSwitchedToBearish) { + bearScore++; } if (isMCHHSwitchedToBearish) { + bearScore++; } if (isMCLLSwitchedToBeraish) { + bearScore++; } // @@ -1385,41 +1513,53 @@ public: // if (isLCBullish) { + bullScore++; } if (isLCHHBullish) { + bullScore++; } if (isLCLLBullish) { + bullScore++; } if (isLCSwitchedToBullish) { + bullScore++; } if (isLCHHSwitchedToBullish) { + bullScore++; } if (isLCLLSwitchedToBullish) { + bullScore++; } // if (isLCBearish) { + bearScore++; } if (isLCHHBearish) { + bearScore++; } if (isLCLLBearish) { + bearScore++; } if (isLCSwitchedToBearish) { + bearScore++; } if (isLCHHSwitchedToBearish) { + bearScore++; } if (isLCLLSwitchedToBeraish) { + bearScore++; } // @@ -1428,41 +1568,53 @@ public: // if (isHCBullish) { + bullScore++; } if (isHCHHBullish) { + bullScore++; } if (isHCLLBullish) { + bullScore++; } if (isHCSwitchedToBullish) { + bullScore++; } if (isHCHHSwitchedToBullish) { + bullScore++; } if (isHCLLSwitchedToBullish) { + bullScore++; } // if (isHCBearish) { + bearScore++; } if (isHCHHBearish) { + bearScore++; } if (isHCLLBearish) { + bearScore++; } if (isHCSwitchedToBearish) { + bearScore++; } if (isHCHHSwitchedToBearish) { + bearScore++; } if (isHCLLSwitchedToBeraish) { + bearScore++; } // @@ -1471,164 +1623,212 @@ public: // if (isHKBullish) { + bullScore++; } if (isHKBearish) { + bearScore++; } if (isClosedOverHK) { + bullScore++; } if (isClosedUnderHK) { + bearScore++; } if (isHKSwitchedToBullish) { + bullScore++; } if (isHKSwitchedToBearish) { + bearScore++; } // if (isSMHKBullish) { + bullScore++; } if (isSMHKBearish) { + bearScore++; } if (isClosedOverSMHK) { + bullScore++; } if (isClosedUnderSMHK) { + bearScore++; } if (isSMHKSwitchedToBullish) { + bullScore++; } if (isSMHKSwitchedToBearish) { + bearScore++; } // // XSTR ... if (isTrendBullish) { + bullScore++; } if (isTrendBearish) { + bearScore++; } if (isTrendSwitchedToBullish) { + bullScore++; } if (isTrendSwitchedToBearish) { + bearScore++; } // // XTD ... if (isTDBullish) { + bullScore++; } if (isTDBearish) { + bearScore++; } if (isTDSwitchedToBullish) { + bullScore++; } if (isTDSwitchedToBearish) { + bearScore++; } // // XCHE ... if (isCHEBullish) { + bullScore++; } if (isCHEBearish) { + bearScore++; } if (isCHESwitchedToBullish) { + bullScore++; } if (isCHESwitchedToBearish) { + bearScore++; } // // XMC ... if (isMCFastOverSlow) { + bullScore++; } if (isMCFastUnderSlow) { + bearScore++; } if (isMCFastOverVerifier) { + bullScore++; } if (isMCFastUnderVerifier) { + bearScore++; } if (isMCSlowOverVerifier) { + bullScore++; } if (isMCSlowUnderVerifier) { + bearScore++; } if (isMCFastCrossedOverSlow) { + bullScore++; } if (isMCFastCrossedUnderSlow) { + bearScore++; } if (isMCFastCrossedOverVerifier) { + bullScore++; } if (isMCFastCrossedUnderVerifier) { + bearScore++; } if (isMCSlowCrossedOverVerifier) { + bullScore++; } if (isMCSlowCrossedUnderVerifier) { + bearScore++; } // // XMRB ... if (isMRBFastOverSlow) { + bullScore++; } if (isMRBFastUnderSlow) { + bearScore++; } if (isMRBFastCrossedOverSlow) { + bullScore++; } if (isMRBFastCrossedUnderSlow) { + bearScore++; } if (isMRBFastOverVerifier) { + bullScore++; } if (isMRBFastUnderVerifier) { + bearScore++; } if (isMRBFastCrossedtOverVerifier) { + bullScore++; } if (isMRBFastCrossedUnderVerifier) { + bearScore++; } if (isMRBSlowOverVerifier) { + bullScore++; } if (isMRBSlowUnderVerifier) { + bearScore++; } if (isMRBSlowCrossedtOverVerifier) { + bullScore++; } if (isMRBSlowCrossedUnderVerifier) { + bearScore++; } // @@ -1637,41 +1837,53 @@ public: // if (isDONAttachedMaxLower) { + bullScore++; } if (isDONAttachedMinLower) { + bullScore++; } if (isDONCrossedOverMaxLower) { + bullScore++; } if (isDONCrossedUnderMaxLower) { + bullScore++; } if (isDONCrossedOverMinLower) { + bullScore++; } if (isDONCrossedUnderMinLower) { + bullScore++; } // if (isDONAttachedMaxUpper) { + bearScore++; } if (isDONAttachedMinUpper) { + bearScore++; } if (isDONCrossedOverMaxUpper) { + bearScore++; } if (isDONCrossedUnderMaxUpper) { + bearScore++; } if (isDONCrossedOverMinUpper) { + bearScore++; } if (isDONCrossedUnderMinUpper) { + bearScore++; } // @@ -1680,73 +1892,95 @@ public: // if (isClosedOverKijunSen) { + bullScore++; } if (isClosedUnderKijunSen) { + bearScore++; } if (isTenkanSenOverKijunSen) { + bullScore++; } if (isTenkanSenUnderKijunSen) { + bearScore++; } if (isTenkanSenCrossedOverKijunSen) { + bullScore++; } if (isTenkanSenCrossedUnderKijunSen) { + bearScore++; } // if (isSenkouSpanAOverB) { + bullScore++; } if (isSenkouSpanAUnderB) { + bearScore++; } if (isSenkouSpanAOverLast) { + bullScore++; } if (isSenkouSpanAUnderLast) { + bearScore++; } if (isFutureSenkouSpanAOverB) { + bullScore++; } if (isFutureSenkouSpanAUnderB) { + bearScore++; } if (isFutureSenkouSpanAOverLast) { + bullScore++; } if (isFutureSenkouSpanAUnderLast) { + bearScore++; } // if (isSenkouSpanACrossedOverB) { + bullScore++; } if (isSenkouSpanACrossedUnderB) { + bearScore++; } if (isSenkouSpanACrossedOverLast) { + bullScore++; } if (isSenkouSpanACrossedUnderLast) { + bearScore++; } if (isFutureSenkouSpanACrossedOverB) { + bullScore++; } if (isFutureSenkouSpanACrossedUnderB) { + bearScore++; } if (isFutureSenkouSpanACrossedOverLast) { + bullScore++; } if (isFutureSenkouSpanACrossedUnderLast) { + bearScore++; } // @@ -1814,8 +2048,8 @@ public: // Common ... string commonStr = // - "Commons: " + separator + - "-----------------------------" + separator + + (onlySummary ? "" : "Commons: " + separator) + + (onlySummary ? "" : "-----------------------------" + separator) + "Time: " + ToString(TimeCurrent()) + separator + "-----------" + separator + "Scores: " + separator + @@ -1830,6 +2064,275 @@ public: // ; + // + // Candlestick ... + string candlestickStr = + // + ToString("isLastBullish", isLastBullish, ignoreFalseConditions, separator) + + ToString("isLastBearish", isLastBearish, ignoreFalseConditions, separator) + + ToString("isCurrentBullish", isCurrentBullish, ignoreFalseConditions, separator) + + ToString("isCurrentBearish", isCurrentBearish, ignoreFalseConditions, separator) + + ToString("isCurrentMidLineOverLastHigh", isCurrentMidLineOverLastHigh, ignoreFalseConditions, separator) + + ToString("isCurrentMidLineUnderLastLow", isCurrentMidLineUnderLastLow, ignoreFalseConditions, separator) + + ToString("isCurrentMidLineOverLastUp", isCurrentMidLineOverLastUp, ignoreFalseConditions, separator) + + ToString("isCurrentMidLineUnderLastDown", isCurrentMidLineUnderLastDown, ignoreFalseConditions, separator) + + ToString("isCurrentMidLineOverLastMidLine", isCurrentMidLineOverLastMidLine, ignoreFalseConditions, separator) + + ToString("isCurrentMidLineUnderLastMidLine", isCurrentMidLineUnderLastMidLine, ignoreFalseConditions, separator) + + "" + // + ; + candlestickStr = SetLabel(": ", candlestickStr, separator); + + // + // XZG ... + string zgStr = + // + ToString("isZigZagInPeak", isZigZagInPeak, ignoreFalseConditions, separator) + + ToString("isZigZagInVale", isZigZagInVale, ignoreFalseConditions, separator) + + "" + // + ; + zgStr = SetLabel(": ", zgStr, separator); + + // + // XSTR ... + string strStr = + // + ToString("isTrendBullish", isTrendBullish, ignoreFalseConditions, separator) + + ToString("isTrendBearish", isTrendBearish, ignoreFalseConditions, separator) + + ToString("isTrendSwitchedToBullish", isTrendSwitchedToBullish, ignoreFalseConditions, separator) + + ToString("isTrendSwitchedToBearish", isTrendSwitchedToBearish, ignoreFalseConditions, separator) + + "" + // + ; + strStr = SetLabel(": ", strStr, separator); + + // + // XCHE ... + string cheStr = + // + ToString("isCHEBullish", isCHEBullish, ignoreFalseConditions, separator) + + ToString("isCHEBearish", isCHEBearish, ignoreFalseConditions, separator) + + ToString("isCHESwitchedToBullish", isCHESwitchedToBullish, ignoreFalseConditions, separator) + + ToString("isCHESwitchedToBearish", isCHESwitchedToBearish, ignoreFalseConditions, separator) + + "" + // + ; + cheStr = SetLabel(": ", cheStr, separator); + + // + // XTD ... + string tdStr = + // + ToString("isTDBullish", isTDBullish, ignoreFalseConditions, separator) + + ToString("isTDBearish", isTDBearish, ignoreFalseConditions, separator) + + ToString("isTDSwitchedToBullish", isTDSwitchedToBullish, ignoreFalseConditions, separator) + + ToString("isTDSwitchedToBearish", isTDSwitchedToBearish, ignoreFalseConditions, separator) + + "" + // + ; + tdStr = SetLabel(": ", tdStr, separator); + + // + // XHK ... + string hkStr = + // + ToString("isHKBullish", isHKBullish, ignoreFalseConditions, separator) + + ToString("isHKBearish", isHKBearish, ignoreFalseConditions, separator) + + ToString("isClosedOverHK", isClosedOverHK, ignoreFalseConditions, separator) + + ToString("isClosedUnderHK", isClosedUnderHK, ignoreFalseConditions, separator) + + ToString("isHKSwitchedToBullish", isHKSwitchedToBullish, ignoreFalseConditions, separator) + + ToString("isHKSwitchedToBearish", isHKSwitchedToBearish, ignoreFalseConditions, separator) + + ToString("isSMHKBullish", isSMHKBullish, ignoreFalseConditions, separator) + + ToString("isSMHKBearish", isSMHKBearish, ignoreFalseConditions, separator) + + ToString("isClosedOverSMHK", isClosedOverSMHK, ignoreFalseConditions, separator) + + ToString("isClosedUnderSMHK", isClosedUnderSMHK, ignoreFalseConditions, separator) + + ToString("isSMHKSwitchedToBullish", isSMHKSwitchedToBullish, ignoreFalseConditions, separator) + + ToString("isSMHKSwitchedToBearish", isSMHKSwitchedToBearish, ignoreFalseConditions, separator) + + "" + // + ; + hkStr = SetLabel(": ", hkStr, separator); + + // + // XDON ... + string donStr = + // + ToString("isDONAttachedMaxLower", isDONAttachedMaxLower, ignoreFalseConditions, separator) + + ToString("isDONAttachedMinLower", isDONAttachedMinLower, ignoreFalseConditions, separator) + + ToString("isDONCrossedOverMaxLower", isDONCrossedOverMaxLower, ignoreFalseConditions, separator) + + ToString("isDONCrossedUnderMaxLower", isDONCrossedUnderMaxLower, ignoreFalseConditions, separator) + + ToString("isDONCrossedOverMinLower", isDONCrossedOverMinLower, ignoreFalseConditions, separator) + + ToString("isDONCrossedUnderMinLower", isDONCrossedUnderMinLower, ignoreFalseConditions, separator) + + ToString("isDONAttachedMaxUpper", isDONAttachedMaxUpper, ignoreFalseConditions, separator) + + ToString("isDONAttachedMinUpper", isDONAttachedMinUpper, ignoreFalseConditions, separator) + + ToString("isDONCrossedOverMaxUpper", isDONCrossedOverMaxUpper, ignoreFalseConditions, separator) + + ToString("isDONCrossedUnderMaxUpper", isDONCrossedUnderMaxUpper, ignoreFalseConditions, separator) + + ToString("isDONCrossedOverMinUpper", isDONCrossedOverMinUpper, ignoreFalseConditions, separator) + + ToString("isDONCrossedUnderMinUpper", isDONCrossedUnderMinUpper, ignoreFalseConditions, separator) + + "" + // + ; + donStr = SetLabel(": ", donStr, separator); + + // + // XMC ... + string mcStr = + // + ToString("isMCFastOverSlow", isMCFastOverSlow, ignoreFalseConditions, separator) + + ToString("isMCFastUnderSlow", isMCFastUnderSlow, ignoreFalseConditions, separator) + + ToString("isMCFastOverVerifier", isMCFastOverVerifier, ignoreFalseConditions, separator) + + ToString("isMCFastUnderVerifier", isMCFastUnderVerifier, ignoreFalseConditions, separator) + + ToString("isMCSlowOverVerifier", isMCSlowOverVerifier, ignoreFalseConditions, separator) + + ToString("isMCSlowUnderVerifier", isMCSlowUnderVerifier, ignoreFalseConditions, separator) + + ToString("isMCFastCrossedOverSlow", isMCFastCrossedOverSlow, ignoreFalseConditions, separator) + + ToString("isMCFastCrossedUnderSlow", isMCFastCrossedUnderSlow, ignoreFalseConditions, separator) + + ToString("isMCFastCrossedOverVerifier", isMCFastCrossedOverVerifier, ignoreFalseConditions, separator) + + ToString("isMCFastCrossedUnderVerifier", isMCFastCrossedUnderVerifier, ignoreFalseConditions, separator) + + ToString("isMCSlowCrossedOverVerifier", isMCSlowCrossedOverVerifier, ignoreFalseConditions, separator) + + ToString("isMCSlowCrossedUnderVerifier", isMCSlowCrossedUnderVerifier, ignoreFalseConditions, separator) + + "" + // + ; + mcStr = SetLabel(": ", mcStr, separator); + + // + // XMRB ... + string mrbStr = + // + ToString("isMRBFastOverSlow", isMRBFastOverSlow, ignoreFalseConditions, separator) + + ToString("isMRBFastUnderSlow", isMRBFastUnderSlow, ignoreFalseConditions, separator) + + ToString("isMRBFastCrossedOverSlow", isMRBFastCrossedOverSlow, ignoreFalseConditions, separator) + + ToString("isMRBFastCrossedUnderSlow", isMRBFastCrossedUnderSlow, ignoreFalseConditions, separator) + + ToString("isMRBFastOverVerifier", isMRBFastOverVerifier, ignoreFalseConditions, separator) + + ToString("isMRBFastUnderVerifier", isMRBFastUnderVerifier, ignoreFalseConditions, separator) + + ToString("isMRBFastCrossedtOverVerifier", isMRBFastCrossedtOverVerifier, ignoreFalseConditions, separator) + + ToString("isMRBFastCrossedUnderVerifier", isMRBFastCrossedUnderVerifier, ignoreFalseConditions, separator) + + ToString("isMRBSlowOverVerifier", isMRBSlowOverVerifier, ignoreFalseConditions, separator) + + ToString("isMRBSlowUnderVerifier", isMRBSlowUnderVerifier, ignoreFalseConditions, separator) + + ToString("isMRBSlowCrossedtOverVerifier", isMRBSlowCrossedtOverVerifier, ignoreFalseConditions, separator) + + ToString("isMRBSlowCrossedUnderVerifier", isMRBSlowCrossedUnderVerifier, ignoreFalseConditions, separator) + + "" + // + ; + mrbStr = SetLabel(": ", mrbStr, separator); + + // + // XICH ... + string ichStr = + // + ToString("isClosedOverKijunSen", isClosedOverKijunSen, ignoreFalseConditions, separator) + + ToString("isClosedUnderKijunSen", isClosedUnderKijunSen, ignoreFalseConditions, separator) + + ToString("isTenkanSenOverKijunSen", isTenkanSenOverKijunSen, ignoreFalseConditions, separator) + + ToString("isTenkanSenUnderKijunSen", isTenkanSenUnderKijunSen, ignoreFalseConditions, separator) + + ToString("isTenkanSenCrossedOverKijunSen", isTenkanSenCrossedOverKijunSen, ignoreFalseConditions, separator) + + ToString("isTenkanSenCrossedUnderKijunSen", isTenkanSenCrossedUnderKijunSen, ignoreFalseConditions, separator) + + ToString("isSenkouSpanAOverB", isSenkouSpanAOverB, ignoreFalseConditions, separator) + + ToString("isSenkouSpanAUnderB", isSenkouSpanAUnderB, ignoreFalseConditions, separator) + + ToString("isSenkouSpanAOverLast", isSenkouSpanAOverLast, ignoreFalseConditions, separator) + + ToString("isSenkouSpanAUnderLast", isSenkouSpanAUnderLast, ignoreFalseConditions, separator) + + ToString("isFutureSenkouSpanAOverB", isFutureSenkouSpanAOverB, ignoreFalseConditions, separator) + + ToString("isFutureSenkouSpanAUnderB", isFutureSenkouSpanAUnderB, ignoreFalseConditions, separator) + + ToString("isFutureSenkouSpanAOverLast", isFutureSenkouSpanAOverLast, ignoreFalseConditions, separator) + + ToString("isFutureSenkouSpanAUnderLast", isFutureSenkouSpanAUnderLast, ignoreFalseConditions, separator) + + ToString("isSenkouSpanACrossedOverB", isSenkouSpanACrossedOverB, ignoreFalseConditions, separator) + + ToString("isSenkouSpanACrossedUnderB", isSenkouSpanACrossedUnderB, ignoreFalseConditions, separator) + + ToString("isSenkouSpanACrossedOverLast", isSenkouSpanACrossedOverLast, ignoreFalseConditions, separator) + + ToString("isSenkouSpanACrossedUnderLast", isSenkouSpanACrossedUnderLast, ignoreFalseConditions, separator) + + ToString("isFutureSenkouSpanACrossedOverB", isFutureSenkouSpanACrossedOverB, ignoreFalseConditions, separator) + + ToString("isFutureSenkouSpanACrossedUnderB", isFutureSenkouSpanACrossedUnderB, ignoreFalseConditions, separator) + + ToString("isFutureSenkouSpanACrossedOverLast", isFutureSenkouSpanACrossedOverLast, ignoreFalseConditions, separator) + + ToString("isFutureSenkouSpanACrossedUnderLast", isFutureSenkouSpanACrossedUnderLast, ignoreFalseConditions, separator) + + "" + // + ; + ichStr = SetLabel(": ", ichStr, separator); + + // + // XPV ... + string pvStr = + // + ToString("isNewPeak", isNewPeak, ignoreFalseConditions, separator) + + ToString("isNewPeakOverLast", isNewPeakOverLast, ignoreFalseConditions, separator) + + ToString("isNewPeakUnderLast", isNewPeakUnderLast, ignoreFalseConditions, separator) + + ToString("isNewVale", isNewVale, ignoreFalseConditions, separator) + + ToString("isNewValeOverLast", isNewValeOverLast, ignoreFalseConditions, separator) + + ToString("isNewValeUnderLast", isNewValeUnderLast, ignoreFalseConditions, separator) + + ToString("isFiboIncreased", isFiboIncreased, ignoreFalseConditions, separator) + + ToString("isFiboDecreased", isFiboDecreased, ignoreFalseConditions, separator) + + ToString("isFiboSectionChanged", isFiboSectionChanged, ignoreFalseConditions, separator) + + ToString("isSCBullish", isSCBullish, ignoreFalseConditions, separator) + + ToString("isSCHHBullish", isSCHHBullish, ignoreFalseConditions, separator) + + ToString("isSCLLBullish", isSCLLBullish, ignoreFalseConditions, separator) + + ToString("isSCSwitchedToBullish", isSCSwitchedToBullish, ignoreFalseConditions, separator) + + ToString("isSCHHSwitchedToBullish", isSCHHSwitchedToBullish, ignoreFalseConditions, separator) + + ToString("isSCLLSwitchedToBullish", isSCLLSwitchedToBullish, ignoreFalseConditions, separator) + + ToString("isSCBearish", isSCBearish, ignoreFalseConditions, separator) + + ToString("isSCHHBearish", isSCHHBearish, ignoreFalseConditions, separator) + + ToString("isSCLLBearish", isSCLLBearish, ignoreFalseConditions, separator) + + ToString("isSCSwitchedToBearish", isSCSwitchedToBearish, ignoreFalseConditions, separator) + + ToString("isSCHHSwitchedToBearish", isSCHHSwitchedToBearish, ignoreFalseConditions, separator) + + ToString("isSCLLSwitchedToBeraish", isSCLLSwitchedToBeraish, ignoreFalseConditions, separator) + + ToString("isMCBullish", isMCBullish, ignoreFalseConditions, separator) + + ToString("isMCHHBullish", isMCHHBullish, ignoreFalseConditions, separator) + + ToString("isMCLLBullish", isMCLLBullish, ignoreFalseConditions, separator) + + ToString("isMCSwitchedToBullish", isMCSwitchedToBullish, ignoreFalseConditions, separator) + + ToString("isMCHHSwitchedToBullish", isMCHHSwitchedToBullish, ignoreFalseConditions, separator) + + ToString("isMCLLSwitchedToBullish", isMCLLSwitchedToBullish, ignoreFalseConditions, separator) + + ToString("isMCBearish", isMCBearish, ignoreFalseConditions, separator) + + ToString("isMCHHBearish", isMCHHBearish, ignoreFalseConditions, separator) + + ToString("isMCLLBearish", isMCLLBearish, ignoreFalseConditions, separator) + + ToString("isMCSwitchedToBearish", isMCSwitchedToBearish, ignoreFalseConditions, separator) + + ToString("isMCHHSwitchedToBearish", isMCHHSwitchedToBearish, ignoreFalseConditions, separator) + + ToString("isMCLLSwitchedToBeraish", isMCLLSwitchedToBeraish, ignoreFalseConditions, separator) + + ToString("isLCBullish", isLCBullish, ignoreFalseConditions, separator) + + ToString("isLCHHBullish", isLCHHBullish, ignoreFalseConditions, separator) + + ToString("isLCLLBullish", isLCLLBullish, ignoreFalseConditions, separator) + + ToString("isLCSwitchedToBullish", isLCSwitchedToBullish, ignoreFalseConditions, separator) + + ToString("isLCHHSwitchedToBullish", isLCHHSwitchedToBullish, ignoreFalseConditions, separator) + + ToString("isLCLLSwitchedToBullish", isLCLLSwitchedToBullish, ignoreFalseConditions, separator) + + ToString("isLCBearish", isLCBearish, ignoreFalseConditions, separator) + + ToString("isLCHHBearish", isLCHHBearish, ignoreFalseConditions, separator) + + ToString("isLCLLBearish", isLCLLBearish, ignoreFalseConditions, separator) + + ToString("isLCSwitchedToBearish", isLCSwitchedToBearish, ignoreFalseConditions, separator) + + ToString("isLCHHSwitchedToBearish", isLCHHSwitchedToBearish, ignoreFalseConditions, separator) + + ToString("isLCLLSwitchedToBeraish", isLCLLSwitchedToBeraish, ignoreFalseConditions, separator) + + ToString("isHCBullish", isHCBullish, ignoreFalseConditions, separator) + + ToString("isHCHHBullish", isHCHHBullish, ignoreFalseConditions, separator) + + ToString("isHCLLBullish", isHCLLBullish, ignoreFalseConditions, separator) + + ToString("isHCSwitchedToBullish", isHCSwitchedToBullish, ignoreFalseConditions, separator) + + ToString("isHCHHSwitchedToBullish", isHCHHSwitchedToBullish, ignoreFalseConditions, separator) + + ToString("isHCLLSwitchedToBullish", isHCLLSwitchedToBullish, ignoreFalseConditions, separator) + + ToString("isHCBearish", isHCBearish, ignoreFalseConditions, separator) + + ToString("isHCHHBearish", isHCHHBearish, ignoreFalseConditions, separator) + + ToString("isHCLLBearish", isHCLLBearish, ignoreFalseConditions, separator) + + ToString("isHCSwitchedToBearish", isHCSwitchedToBearish, ignoreFalseConditions, separator) + + ToString("isHCHHSwitchedToBearish", isHCHHSwitchedToBearish, ignoreFalseConditions, separator) + + ToString("isHCLLSwitchedToBeraish", isHCLLSwitchedToBeraish, ignoreFalseConditions, separator) + + "" + // + ; + pvStr = SetLabel(": ", pvStr, separator); + + // + result = + onlySummary + ? commonStr + : (commonStr + + candlestickStr + + zgStr + + strStr + + cheStr + + tdStr + + hkStr + + donStr + + mcStr + + mrbStr + + ichStr + + pvStr + + "" // + ); + // return result; } @@ -1852,6 +2355,260 @@ public: } }; +// +// Signaller Class Base Implementation ... +class XSignallerDescriptor +{ + // + // Public ... +public: + // + // Props ... + + // + ENUM_XSIGNAL_PROVIDERS name; + + // + bool enableLong; + bool enableShort; + + // + double r2r; + + // + double staticVolumeLong; + double staticVolumeShort; + + // + // Constructor ... + void XSignallerDescriptor() + { + Clean(); + } + + // + // Tools ... + + // + // Cleanup ... + void Clean() + { + // + name = PROVIDER_NONE; + + // + enableLong = false; + enableShort = false; + + // + r2r = 0; + + // + staticVolumeLong = 0; + staticVolumeShort = 0; + } + + // + // Validate ... + bool IsValid() + { + // + bool result = false; + + // + result = + // + name != PROVIDER_NONE && + r2r > 0 && + (enableLong + ? staticVolumeLong > 0 + : true) && + (enableShort + ? staticVolumeShort > 0 + : true) + // + ; + + // + return result; + } + + // + string GetName() + { + return ToString(name); + } + + // + // Generate Signal ... + bool GenerateSignal( + XSignal &signal, // Result + string mSymbol, // Trading Symbol + ENUM_TIMEFRAMES mPeriod, // Trading TimeFrame + ENUM_POSITION_TYPE mType, // Long (Buy) or Short (Sell) + ENUM_X_ORDER_MODES mMode, // Execution Mode + double mEntry, // Entry Price + double mSL = 0, // Stop Loss + double mTP = 0 // Take Profit + ) + { + // + bool result = false; + + // + signal.Clean(); + + // + // Validate Model ... + result = IsValid(); + if (!result) + { + return result; + } + + // + bool isLong = IsLong(mType); + + // + // Validate Signal Type ... + result = isLong + ? enableLong && staticVolumeLong > 0 + : enableShort && staticVolumeShort > 0; + if (!result) + { + return result; + } + + // + double mVolume = isLong + ? staticVolumeLong + : staticVolumeShort; + + // + result = signal.Prepare( + mSymbol, + GetName(), + mPeriod, + mType, + mMode, + mEntry, + mVolume, + mSL, + mTP // + ); + + // + return result; + } + + // + // Generate Market Signal ... + bool GenerateMarketSignal( + XSignal &signal, // Result + string mSymbol, // Trading Symbol + ENUM_TIMEFRAMES mPeriod, // Trading TimeFrame + ENUM_POSITION_TYPE mType, // Long (Buy) or Short (Sell) + double mEntry, // Entry Price + double mSL = 0, // Stop Loss + double mTP = 0 // Take Profit + ) + { + // + bool result = false; + + // + signal.Clean(); + + // + // Validate Model ... + result = IsValid(); + if (!result) + { + return result; + } + + // + bool isLong = IsLong(mType); + + // + // Validate Signal Type ... + result = isLong + ? enableLong && staticVolumeLong > 0 + : enableShort && staticVolumeShort > 0; + if (!result) + { + return result; + } + + // + double mVolume = isLong + ? staticVolumeLong + : staticVolumeShort; + + // + result = signal.Prepare( + mSymbol, + GetName(), + mPeriod, + mType, + X_ORDER_MODE_MARKET, + mEntry, + mVolume, + mSL, + mTP // + ); + + // + return result; + } + + // + // Check Has Conditions opr Not ... + bool HasConditions( + const X121MCycleConditions &conditions, // Market Conditions + bool &hasLong, // Hold Long Conditions Result + bool &hasShort, // Hold Short Conditions Result + double &sl, // Hold SL ... + double &tp // Hold TP ... + ) + { + // + bool result = false; + + // + hasLong = HasLongConditions(conditions, sl, tp); + hasShort = HasShortConditions(conditions, sl, tp); + + // + result = hasLong || hasShort; + + // + return result; + } + + // + // Check Has Long Conditions opr Not ... + virtual bool HasLongConditions( + const X121MCycleConditions &conditions, // Market Conditions + double &sl, // Hold SL ... + double &tp // Hold TP ... + ) + { + return false; + } + + // + // Check Has Short Conditions opr Not ... + virtual bool HasShortConditions( + const X121MCycleConditions &conditions, // Market Conditions + double &sl, // Hold SL ... + double &tp // Hold TP ... + ) + { + return false; + } +}; + // // Market Class ... class XSCX121Market : XSCBase @@ -1969,8 +2726,65 @@ public: return Init(inputs); } + // + bool AddSignaller( + XSignallerDescriptor &signaller // + ) + { + // + bool result = false; + + // + // Validate Signaller ... + result = signaller.IsValid(); + if (!result) + { + return result; + } + + // + AddRef( + signaller, + mSignallers // + ); + + // + return result; + } + + // + int AddSignallers( + XSignallerDescriptor &signallers[] // + ) + { + // + int result = 0; + + // + int count = ArraySize(signallers); + if (!IsValidSize(count)) + { + return result; + } + + // + for (int i = 0; i < count; i++) + { + // + bool isAdded = AddSignaller(signallers[i]); + if (isAdded) + { + result++; + } + } + + // + return result; + } + // // Tools ... + // void GetMarketConditions( X121MCycleConditions &conditions, // Market Conditions Result @@ -3568,6 +4382,160 @@ public: // // Market Parse Conditions ... + bool HasConditions( + XSignal &signal, // If Any Signal provided, Filled here ... + bool &hasLong, + int &longPusher, + bool &hasShort, + int &shortPusher // + ) + { + // + bool result = false; + + // + longPusher = 0; + shortPusher = 0; + hasLong = false; + hasShort = false; + + // + int count = CountSignallers(); + if (!IsValidSize(count)) + { + return result; + } + + // + X121MCycleConditions conditions; + GetMarketConditions(conditions); + + // + for (int i = 0; i < count; i++) + { + // + bool iHasLong = false; + bool iHasShort = false; + + // + double iTP = 0; + double iTPProvided = 0; + double iSL = 0; + double iSLProvided = 0; + double iEntry = 0; + ENUM_POSITION_TYPE iType; + string iSymbol = GetSymbol(); + double iR2R = mSignallers[i].r2r; + ENUM_TIMEFRAMES iPeriod = GetPeriod(); + string iProvider = mSignallers[i].GetName(); + + // + bool iHasSignal = mSignallers[i].HasConditions( + conditions, + iHasLong, + iHasShort, + iTPProvided, + iSLProvided // + ); + if (iHasSignal) + { + // + // Filling Pusher(s) ... + if (iHasLong) + { + longPusher++; + } + else if (iHasShort) + { + shortPusher++; + } + + // + if (iHasLong && !hasLong) + { + // + hasLong = iHasLong; + + // + // Filling Signal ... + iType = POSITION_TYPE_BUY; + + // + iEntry = GetEntry( + iSymbol, + iType // + ); + + // + CalculateTPSL( + iSL, + iTP, + iType, + iEntry, + iR2R, + iSLProvided, + iTPProvided // + ); + + // + // Fill Signal Here ... + bool isSignalGenerated = mSignallers[i].GenerateMarketSignal( + signal, + iSymbol, + iPeriod, + iType, + iEntry, + iSL, + iTP // + ); + } + else if (iHasShort && !hasShort) + { + // + hasShort = iHasShort; + + // + // Fill Signal Here ... + iType = POSITION_TYPE_SELL; + + // + iEntry = GetEntry( + iSymbol, + iType // + ); + + // + CalculateTPSL( + iSL, + iTP, + iType, + iEntry, + iR2R, + iSLProvided, + iTPProvided // + ); + + // + // Fill Signal Here ... + bool isSignalGenerated = mSignallers[i].GenerateMarketSignal( + signal, + iSymbol, + iPeriod, + iType, + iEntry, + iSL, + iTP // + ); + } + } + } + + // + result = hasLong || hasShort; + + // + return result; + } // // X786 Long ... @@ -4225,6 +5193,76 @@ private: // X121MCycleInputs mInputs; + // + // Signallers ... + + // + XSignallerDescriptor mSignallers[]; + + // + // Count Signallers ... + int CountSignallers() + { + return ArraySize(mSignallers); + } + + // + // Find Signaller Index ... + int FindSignallerIndex(ENUM_XSIGNAL_PROVIDERS signaller) + { + // + int result = -1; + + // + int count = CountSignallers(); + if (!IsValidSize(count)) + { + return result; + } + + // + for (int i = 0; i < count; i++) + { + // + XSignallerDescriptor iSignaller = mSignallers[i]; + + // + if (iSignaller.name == signaller) + { + // + result = i; + break; + } + } + + // + return result; + } + int FindSignallerIndex(string signaller) + { + // + int result = -1; + + // + if (!IsValid(signaller)) + { + return result; + } + + // + ENUM_XSIGNAL_PROVIDERS mSignaller = ToXSignalProvider(signaller); + if (mSignaller == PROVIDER_NONE) + { + return result; + } + + // + result = FindSignallerIndex(mSignaller); + + // + return result; + } + // // Tools ... diff --git a/Experts/x-test.x121ea.mq5 b/Experts/x-test.x121ea.mq5 index bd97c9ce..b8cf9acf 100644 --- a/Experts/x-test.x121ea.mq5 +++ b/Experts/x-test.x121ea.mq5 @@ -193,7 +193,7 @@ bool InitialEA() // // Define Signallers ... - ENUM_X121_SIGNAL_PROVIDERS signallers[]; + ENUM_XSIGNAL_PROVIDERS signallers[]; Add(X786, signallers); // Add(X121, signallers); // Add(X121, signallers); diff --git a/Libraries/x-saherelm.common.lib.mq5 b/Libraries/x-saherelm.common.lib.mq5 index 53f8f510..07fb5ba3 100644 --- a/Libraries/x-saherelm.common.lib.mq5 +++ b/Libraries/x-saherelm.common.lib.mq5 @@ -3711,6 +3711,109 @@ double GetAppliedPrice( return (0); } +// +// Calculate TP/SL for Specified Type of Positions ... +void CalculateTPSL( + double &mSL, // Hold SL + double &mTP, // Hold TP + ENUM_POSITION_TYPE mType, // Position Type Long (Buy) / Short (Sell) + double mEntry, // Entry Price + double mR2R = 1, // Provided Risk To Reward Ratio + double slPrice = 0, // Provided SL Price + double tpPrice = 0 // Provided TP Price +) +{ + // + // if Both TP and SL Provided, ignore R2R and Calculate direct ... + // if SL provided, Calculate TP based on Provided R2R ... + // if TP provided, Calculate SL based on Provided R2R ... + // default R2R is set to 1 ... + + // + mSL = 0; + mTP = 0; + + // + bool isLong = IsLong(mType); + + // + // Set Default R2R ... + if (mR2R < 1) + { + mR2R = 1; + } + + // + if (mEntry <= 0 || + (tpPrice <= 0 && slPrice <= 0)) + { + return; + } + + // + double risk = 0; + double reward = 0; + + // + bool canCalculateBasedOnSL = slPrice > 0 && + (isLong + ? slPrice < mEntry + : slPrice > mEntry); + + // + bool canCalculateBasedOnTP = tpPrice > 0 && + (isLong + ? tpPrice > mEntry + : tpPrice < mEntry); + + // + if (canCalculateBasedOnSL && !canCalculateBasedOnTP) + { + // + risk = MathAbs(mEntry - slPrice); + reward = risk * mR2R; + } + else if (!canCalculateBasedOnSL && canCalculateBasedOnTP) + { + // + reward = MathAbs(mEntry - tpPrice); + risk = reward / mR2R; + } + else if (!canCalculateBasedOnSL && !canCalculateBasedOnTP) + { + // + bool canSetTPPrice = isLong + ? tpPrice > mEntry + : tpPrice < mEntry; + if (canSetTPPrice) + { + mTP = tpPrice; + } + + // + bool canSetSLPrice = isLong + ? slPrice < mEntry + : slPrice > mEntry; + if (canSetSLPrice) + { + mSL = slPrice; + } + + // + return; + } + + // + mTP = isLong + ? mEntry + reward + : mEntry - reward; + + // + mSL = isLong + ? mEntry - reward + : mEntry + reward; +} + // // Symbols ... @@ -5792,8 +5895,8 @@ string ToString( string prefix, // Title bool value, // Value bool ignoreFalseConditions = true, // Ignore False Conditions - string prefixSeparator = ":", // Title Separator - string lineSeparator = "\n" // Line Separator + string lineSeparator = "\n", // Line Separator + string prefixSeparator = ":" // Title Separator ) { //