diff --git a/Classes/x-saherelm.x121.setup.class.mq5 b/Classes/x-saherelm.x121.setup.class.mq5 index 981db4a6..654fb87c 100644 --- a/Classes/x-saherelm.x121.setup.class.mq5 +++ b/Classes/x-saherelm.x121.setup.class.mq5 @@ -989,84 +989,164 @@ struct X121SignalGenerator } // - // Retrieve OSC Based Long Verifications ... - bool IsOSCLongVerified( - X121SetupConditions &conditions // Conditions + // Check Conditions for Generating Possible Signals ... + bool HasSignal( + X121SetupConditions &conditions, // Conditions + XSignal &signal, // Signal if Exists + int &pusher, // Pushers + string &provider, // Signal Provider Name + double &tp, // Provided TP + double &sl, // Provided SL + bool _useSupport, // Generate Support Signals + bool _allowLong, // Allow Long Signals + bool _allowShort, // Allow Short Signals + double _volume = 0.01, // Volume + double _slPoint = 0, // SL Point + bool _ignoreSL = false, // Ignore Calculated SL + double _tpPoint = 30, // TP Point + bool _ignoreTP = false // Ignore Calculated TP ) { // bool result = false; // - int zIndex = 0; - int cIndex = zIndex + 1; - int pIndex = cIndex + 1; + signal.Clean(); // - result = + result = _allowLong || _allowShort; + if (!result) + { + return result; + } + + // + bool hasLong = false; + bool hasShort = false; + + // + if (_allowLong) + { // - // CCI ... - conditions.cci[cIndex] < 96 && - conditions.cci[cIndex] > conditions.cci[pIndex] + hasLong = + HasLongConditions( + conditions, + pusher, + provider, + tp, + sl // + ); + // - && + if (hasLong) + { + // + hasLong = FilterLongConditions( + conditions, + pusher, + provider // + ); + } + } + + // + if (_allowShort && !hasLong) + { // - // RSI ... - conditions.rsi[cIndex] < 70 && - conditions.rsi[cIndex] > conditions.rsi[pIndex] + hasShort = + HasShortConditions( + conditions, + pusher, + provider, + tp, + sl // + ); + // - && - // - // MACD ... - conditions.macd[cIndex] > 0 && - conditions.macdSignal[cIndex] > 0 && - conditions.macd[cIndex] > conditions.macdSignal[cIndex] - // - ; + if (hasShort) + { + // + hasShort = FilterShortConditions( + conditions, + pusher, + provider // + ); + } + } + + // + result = hasLong || hasShort; + if (!result) + { + return result; + } + + // + string mProvider = + IsValid(provider) + ? provider + : GetTag(); + + // + // Prepare Signals ... + ENUM_POSITION_TYPE mType = + hasLong + ? POSITION_TYPE_BUY + : POSITION_TYPE_SELL; + + // + double mEntry = GetEntry( + conditions.symbol, + mType // + ); + + // + double mSL = 0; + double mTP = 0; + double mPointValue = + GetPoints(conditions.symbol); + result = CalculateTPSLByPoint( + mSL, + mTP, + mType, + mEntry, + mPointValue, + 1, + _slPoint, + _tpPoint // + ); + if (!result) + { + return result; + } + + // + result = signal.Prepare( + conditions.symbol, + mProvider, + conditions.period, + mType, + X_ORDER_MODE_MARKET, + mEntry, + _volume, + _ignoreSL + ? 0 + : mSL, + _ignoreTP + ? 0 + : mTP // + ); + if (!result) + { + return result; + } // return result; } // - // Retrieve OSC Based Short Verifications ... - bool IsOSCShortVerified( - X121SetupConditions &conditions // Conditions - ) - { - // - bool result = false; - - // - int zIndex = 0; - int cIndex = zIndex + 1; - int pIndex = cIndex + 1; - - // - result = - // - // CCI ... - conditions.cci[cIndex] > -96 && - conditions.cci[cIndex] < conditions.cci[pIndex] - // - && - // - // RSI ... - conditions.rsi[cIndex] > 30 && - conditions.rsi[cIndex] < conditions.rsi[pIndex] - // - && - // - // MACD ... - conditions.macd[cIndex] < 0 && - conditions.macdSignal[cIndex] < 0 && - conditions.macd[cIndex] < conditions.macdSignal[cIndex] - // - ; - - // - return result; - } + // Long Specified Functions ... // // Check Market Conditions for Long Signals ... @@ -1935,6 +2015,378 @@ struct X121SignalGenerator return result; } + // + // Filter Long Conditions ... + bool FilterLongConditions( + X121SetupConditions &conditions, // Conditions + int pusher, // Pushers + string provider // Provider + ) + { + // + bool result = false; + + // + // TODO Filter ... + result = true; // provider == ToString(PROVIDER_XHTSRD); + + // + return result; + } + + // + // Retrieve Long Verifications ... + bool HasLongVerifications( + X121SetupConditions &conditions[] // Conditions Collection + ) + { + // + bool result = false; + + // + int count = ArraySize(conditions); + result = IsValidSize(count); + if (!result) + { + return result; + } + + // + // Loop through Conditions to Get Verifications ... + for (int i = count - 1; i >= 0; i--) + { + // + X121SetupConditions iConditions = conditions[i]; + + // + result = IsConditionsValidForLong(iConditions); + if (!result) + { + break; + } + } + + // + return result; + } + + // + // Count Number of Long Validations ... + int CountLongValidations( + X121SetupConditions &conditions // Conditions + ) + { + // + int result = 0; + + // + // 1 + // XTD ... + bool isTDPassed = + // + conditions.tdConditions.isBullish || + conditions.tdConditions.isSwitchedToBullish + // + ; + if (isTDPassed) + { + result++; + } + + // + // 2 + // XHK ... + bool isHKPassed = + // + (conditions.hkConditions.isHKBullish || + conditions.hkConditions.isHKSwitchedToBullish) + // + || + // + (conditions.hkConditions.isSMHKBullish || + conditions.hkConditions.isSMHKSwitchedToBullish) + // + ; + if (isHKPassed) + { + result++; + } + + // + // 3 + // XCHE ... + bool isCHEPassed = + // + conditions.cheConditions.isBullish || + conditions.cheConditions.isStrongBullish || + conditions.cheConditions.isSwitchedToBullish || + conditions.cheConditions.isStrongSwitchedToBullish + // + ; + if (isCHEPassed) + { + result++; + } + + // + // 4 + // XICH ... + bool isICHPassed = + // + (conditions.ichConditions.isTenkanSenOverKijunSen || + conditions.ichConditions.isTenkanSenCrossedOverKijunSen) + // + && + // + (conditions.ichConditions.isSenkouSpanAOverB || + conditions.ichConditions.isSenkouSpanAOverLast || + conditions.ichConditions.isSenkouSpanACrossedOverB || + conditions.ichConditions.isSenkouSpanACrossedOverLast) + // + && + // + (conditions.ichConditions.isFutureSenkouSpanAOverB || + conditions.ichConditions.isFutureSenkouSpanAOverLast || + conditions.ichConditions.isFutureSenkouSpanACrossedOverB || + conditions.ichConditions.isFutureSenkouSpanACrossedOverLast) + // + ; + if (isICHPassed) + { + result++; + } + + // + // 5 + // XSTR ... + bool isSTRPassed = + // + conditions.strConditions.isTrendBullish || + conditions.strConditions.isTrendSwitchedToBullish + // + ; + if (isSTRPassed) + { + result++; + } + + // + // 6 + // XMRB ... + bool isMRBPassed = + // + conditions.mrbConditions.isFastOverSlow || + conditions.mrbConditions.isFastCrossedOverSlow + // + ; + if (isMRBPassed) + { + result++; + } + + // + // 7 + // XVLM ... + bool isVLMPassed = + // + conditions.vlmConditions.isVolumeBullish || + conditions.vlmConditions.isVolumeOverLast || + conditions.vlmConditions.isVolumeChangedToBullish + // + ; + if (isVLMPassed) + { + result++; + } + + // + // 8 + // XSSLC ... + bool isSSLCPassed = + // + conditions.sslcConditions.isBullish || + conditions.sslcConditions.isSwitchedToBullish + // + ; + if (isSSLCPassed) + { + result++; + } + + // + // 9 + // XHULL ... + bool isHULLPassed = + // + conditions.hullConditions.isBullish || + conditions.hullConditions.isUpBullish || + conditions.hullConditions.isDownBullish || + conditions.hullConditions.isSwitchedToBullish + // + ; + if (isHULLPassed) + { + result++; + } + + // + // 10 + // XADX ... + bool isADXTDPassed = + // + conditions.adxtdConditions.isBullish || + conditions.adxtdConditions.isSwitchedToBullish || + conditions.adxtdConditions.isStrongSwitchedToBullish + // + ; + if (isADXTDPassed) + { + result++; + } + + // + // 11 + // XMC ... + bool isMCPassed = + // + ((conditions.mcConditions.isBullish || + conditions.mcConditions.isSwitchedToBullish) + // + || + // + ((conditions.mcConditions.isFastOverVerifier || + conditions.mcConditions.isFastCrossedOverVerifier) + // + && + // + (conditions.mcConditions.isSlowOverVerifier || + conditions.mcConditions.isSlowCrossedOverVerifier))) + // + || + // + (conditions.mcConditions.isSARBullish || + conditions.mcConditions.isSARSwitchedToBullish) + // + ; + if (isMCPassed) + { + result++; + } + + // + // 12 + // XSLN ... + bool isXSLNPassed = + // + (conditions.slnConditions.isBullish || + conditions.slnConditions.isSwitchedToBullish) + // + ; + if (isXSLNPassed) + { + result++; + } + + // + // 13 + // XHTD ... + bool isXHTDPassed = + // + (conditions.htdConditions.isBullish || + conditions.htdConditions.isSwitchedToBullish) + // + ; + if (isXHTDPassed) + { + result++; + } + + // + // 14 + // XATSL ... + bool isXATSLPassed = + // + (conditions.atslConditions.isBullish || + conditions.atslConditions.isSwitchedToBullish) + // + ; + if (isXATSLPassed) + { + result++; + } + + // + return result; + } + + // + bool IsConditionsValidForLong( + X121SetupConditions &conditions, // Conditions + int verifications = 10 // Number of Verifications + ) + { + // + bool result = false; + + // + int signs = CountLongValidations(conditions); + + // + result = + // + verifications <= 0 + ? signs > 0 + : signs >= verifications + // + ; + + // + return result; + } + + // + // Retrieve OSC Based Long Verifications ... + bool IsOSCLongVerified( + X121SetupConditions &conditions // Conditions + ) + { + // + bool result = false; + + // + int zIndex = 0; + int cIndex = zIndex + 1; + int pIndex = cIndex + 1; + + // + result = + // + // CCI ... + conditions.cci[cIndex] < 96 && + conditions.cci[cIndex] > conditions.cci[pIndex] + // + && + // + // RSI ... + conditions.rsi[cIndex] < 70 && + conditions.rsi[cIndex] > conditions.rsi[pIndex] + // + && + // + // MACD ... + conditions.macd[cIndex] > 0 && + conditions.macdSignal[cIndex] > 0 && + conditions.macd[cIndex] > conditions.macdSignal[cIndex] + // + ; + + // + return result; + } + + // + // Short Specified Functions ... + // // Check Market Conditions for Short Signals ... bool HasShortConditions( @@ -2802,310 +3254,19 @@ struct X121SignalGenerator } // - // Retrieve Long Verifications ... - bool HasLongVerifications( - X121SetupConditions &conditions[] // Conditions Collection - ) - { - // - bool result = false; - - // - int count = ArraySize(conditions); - result = IsValidSize(count); - if (!result) - { - return result; - } - - // - // Loop through Conditions to Get Verifications ... - for (int i = count - 1; i >= 0; i--) - { - // - X121SetupConditions iConditions = conditions[i]; - - // - result = IsConditionsValidForLong(iConditions); - if (result) - { - break; - } - } - - // - return result; - } - - // - // Count Number of Long Validations ... - int CountLongValidations( - X121SetupConditions &conditions // Conditions - ) - { - // - int result = 0; - - // - // 1 - // XTD ... - bool isTDPassed = - // - conditions.tdConditions.isBullish || - conditions.tdConditions.isSwitchedToBullish - // - ; - if (isTDPassed) - { - result++; - } - - // - // 2 - // XHK ... - bool isHKPassed = - // - (conditions.hkConditions.isHKBullish || - conditions.hkConditions.isHKSwitchedToBullish) - // - || - // - (conditions.hkConditions.isSMHKBullish || - conditions.hkConditions.isSMHKSwitchedToBullish) - // - ; - if (isHKPassed) - { - result++; - } - - // - // 3 - // XCHE ... - bool isCHEPassed = - // - conditions.cheConditions.isBullish || - conditions.cheConditions.isStrongBullish || - conditions.cheConditions.isSwitchedToBullish || - conditions.cheConditions.isStrongSwitchedToBullish - // - ; - if (isCHEPassed) - { - result++; - } - - // - // 4 - // XICH ... - bool isICHPassed = - // - (conditions.ichConditions.isTenkanSenOverKijunSen || - conditions.ichConditions.isTenkanSenCrossedOverKijunSen) - // - && - // - (conditions.ichConditions.isSenkouSpanAOverB || - conditions.ichConditions.isSenkouSpanAOverLast || - conditions.ichConditions.isSenkouSpanACrossedOverB || - conditions.ichConditions.isSenkouSpanACrossedOverLast) - // - && - // - (conditions.ichConditions.isFutureSenkouSpanAOverB || - conditions.ichConditions.isFutureSenkouSpanAOverLast || - conditions.ichConditions.isFutureSenkouSpanACrossedOverB || - conditions.ichConditions.isFutureSenkouSpanACrossedOverLast) - // - ; - if (isICHPassed) - { - result++; - } - - // - // 5 - // XSTR ... - bool isSTRPassed = - // - conditions.strConditions.isTrendBullish || - conditions.strConditions.isTrendSwitchedToBullish - // - ; - if (isSTRPassed) - { - result++; - } - - // - // 6 - // XMRB ... - bool isMRBPassed = - // - conditions.mrbConditions.isFastOverSlow || - conditions.mrbConditions.isFastCrossedOverSlow - // - ; - if (isMRBPassed) - { - result++; - } - - // - // 7 - // XVLM ... - bool isVLMPassed = - // - conditions.vlmConditions.isVolumeBullish || - conditions.vlmConditions.isVolumeOverLast || - conditions.vlmConditions.isVolumeChangedToBullish - // - ; - if (isVLMPassed) - { - result++; - } - - // - // 8 - // XSSLC ... - bool isSSLCPassed = - // - conditions.sslcConditions.isBullish || - conditions.sslcConditions.isSwitchedToBullish - // - ; - if (isSSLCPassed) - { - result++; - } - - // - // 9 - // XHULL ... - bool isHULLPassed = - // - conditions.hullConditions.isBullish || - conditions.hullConditions.isUpBullish || - conditions.hullConditions.isDownBullish || - conditions.hullConditions.isSwitchedToBullish - // - ; - if (isHULLPassed) - { - result++; - } - - // - // 10 - // XADX ... - bool isADXTDPassed = - // - conditions.adxtdConditions.isBullish || - conditions.adxtdConditions.isSwitchedToBullish || - conditions.adxtdConditions.isStrongSwitchedToBullish - // - ; - if (isADXTDPassed) - { - result++; - } - - // - // 11 - // XMC ... - bool isMCPassed = - // - ((conditions.mcConditions.isBullish || - conditions.mcConditions.isSwitchedToBullish) - // - || - // - ((conditions.mcConditions.isFastOverVerifier || - conditions.mcConditions.isFastCrossedOverVerifier) - // - && - // - (conditions.mcConditions.isSlowOverVerifier || - conditions.mcConditions.isSlowCrossedOverVerifier))) - // - || - // - (conditions.mcConditions.isSARBullish || - conditions.mcConditions.isSARSwitchedToBullish) - // - ; - if (isMCPassed) - { - result++; - } - - // - // 12 - // XSLN ... - bool isXSLNPassed = - // - (conditions.slnConditions.isBullish || - conditions.slnConditions.isSwitchedToBullish) - // - ; - if (isXSLNPassed) - { - result++; - } - - // - // 13 - // XHTD ... - bool isXHTDPassed = - // - (conditions.htdConditions.isBullish || - conditions.htdConditions.isSwitchedToBullish) - // - ; - if (isXHTDPassed) - { - result++; - } - - // - // 14 - // XATSL ... - bool isXATSLPassed = - // - (conditions.atslConditions.isBullish || - conditions.atslConditions.isSwitchedToBullish) - // - ; - if (isXATSLPassed) - { - result++; - } - - // - return result; - } - - // - bool IsConditionsValidForLong( + // Filter Short Conditions ... + bool FilterShortConditions( X121SetupConditions &conditions, // Conditions - int verifications = 10 // Number of Verifications + int pusher, // Pushers + string provider // Provider ) { // bool result = false; // - int signs = CountLongValidations(conditions); - - // - result = - // - verifications <= 0 - ? signs > 0 - : signs >= verifications - // - ; + // TODO Filter ... + result = true; // provider == ToString(PROVIDER_XHTSRD); // return result; @@ -3137,7 +3298,7 @@ struct X121SignalGenerator // result = IsConditionsValidForShort(iConditions); - if (result) + if (!result) { break; } @@ -3398,7 +3559,7 @@ struct X121SignalGenerator // bool IsConditionsValidForShort( X121SetupConditions &conditions, // Conditions - int verifications = 10 // Number of Verifications + int verifications = 10 // Number of Verifications ) { // @@ -3421,199 +3582,47 @@ struct X121SignalGenerator } // - // Filter Long Conditions ... - bool FilterLongConditions( - X121SetupConditions &conditions, // Conditions - int pusher, // Pushers - string provider // Provider + // Retrieve OSC Based Short Verifications ... + bool IsOSCShortVerified( + X121SetupConditions &conditions // Conditions ) { // bool result = false; // - // TODO Filter ... - result = true; // provider == ToString(PROVIDER_XHTSRD); + int zIndex = 0; + int cIndex = zIndex + 1; + int pIndex = cIndex + 1; + + // + result = + // + // CCI ... + conditions.cci[cIndex] > -96 && + conditions.cci[cIndex] < conditions.cci[pIndex] + // + && + // + // RSI ... + conditions.rsi[cIndex] > 30 && + conditions.rsi[cIndex] < conditions.rsi[pIndex] + // + && + // + // MACD ... + conditions.macd[cIndex] < 0 && + conditions.macdSignal[cIndex] < 0 && + conditions.macd[cIndex] < conditions.macdSignal[cIndex] + // + ; // return result; } // - // Filter Short Conditions ... - bool FilterShortConditions( - X121SetupConditions &conditions, // Conditions - int pusher, // Pushers - string provider // Provider - ) - { - // - bool result = false; - - // - // TODO Filter ... - result = true; // provider == ToString(PROVIDER_XHTSRD); - - // - return result; - } - - // - // Check Conditions for Generating Possible Signals ... - bool HasSignal( - X121SetupConditions &conditions, // Conditions - XSignal &signal, // Signal if Exists - int &pusher, // Pushers - string &provider, // Signal Provider Name - double &tp, // Provided TP - double &sl, // Provided SL - bool _useSupport, // Generate Support Signals - bool _allowLong, // Allow Long Signals - bool _allowShort, // Allow Short Signals - double _volume = 0.01, // Volume - double _slPoint = 0, // SL Point - bool _ignoreSL = false, // Ignore Calculated SL - double _tpPoint = 30, // TP Point - bool _ignoreTP = false // Ignore Calculated TP - ) - { - // - bool result = false; - - // - signal.Clean(); - - // - result = _allowLong || _allowShort; - if (!result) - { - return result; - } - - // - bool hasLong = false; - bool hasShort = false; - - // - if (_allowLong) - { - // - hasLong = - HasLongConditions( - conditions, - pusher, - provider, - tp, - sl // - ); - - // - if (hasLong) - { - // - hasLong = FilterLongConditions( - conditions, - pusher, - provider // - ); - } - } - - // - if (_allowShort && !hasLong) - { - // - hasShort = - HasShortConditions( - conditions, - pusher, - provider, - tp, - sl // - ); - - // - if (hasShort) - { - // - hasShort = FilterShortConditions( - conditions, - pusher, - provider // - ); - } - } - - // - result = hasLong || hasShort; - if (!result) - { - return result; - } - - // - string mProvider = - IsValid(provider) - ? provider - : GetTag(); - - // - // Prepare Signals ... - ENUM_POSITION_TYPE mType = - hasLong - ? POSITION_TYPE_BUY - : POSITION_TYPE_SELL; - - // - double mEntry = GetEntry( - conditions.symbol, - mType // - ); - - // - double mSL = 0; - double mTP = 0; - double mPointValue = - GetPoints(conditions.symbol); - result = CalculateTPSLByPoint( - mSL, - mTP, - mType, - mEntry, - mPointValue, - 1, - _slPoint, - _tpPoint // - ); - if (!result) - { - return result; - } - - // - result = signal.Prepare( - conditions.symbol, - mProvider, - conditions.period, - mType, - X_ORDER_MODE_MARKET, - mEntry, - _volume, - _ignoreSL - ? 0 - : mSL, - _ignoreTP - ? 0 - : mTP // - ); - if (!result) - { - return result; - } - - // - return result; - } + // Custom Functions ... // string GetTag() diff --git a/Documents/BKP/pivots.mq5 b/Documents/BKP/pivots.mq5 new file mode 100644 index 00000000..f2f2445b --- /dev/null +++ b/Documents/BKP/pivots.mq5 @@ -0,0 +1,845 @@ + +// +struct XPivot +{ + // + double pivot; // Pivot Price ... + int breaks; // Number of Breaks ... + int rejects; // Number of Rejects ... + + // + void XPivot() + { + Clean(); + } + + // + // Tools ... + + // + // Cleanup ... + void Clean() + { + // + pivot = 0; + breaks = 0; + rejects = 0; + } + + // + // Validate ... + bool IsValid() + { + // + bool result = false; + + // + result = pivot > 0; + + // + return result; + } +}; + +// +struct XPivotTracker +{ + // + XPivot pivots[]; + + // + // Constructor ... + void XPivotTracker() + { + Clean(); + } + + // + // Tools ... + + // + // Cleanup ... + void Clean() + { + // + Clean(pivots); + } + + // + int Count() + { + return ArraySize(pivots); + } + + // + double Get(int index) + { + // + double result = 0; + + // + NormalizeIndex(index, pivots); + + // + XPivot iPivot = pivots[index]; + + // + result = iPivot.pivot; + + // + return result; + } + + // + XPivot GetPivot(int index) + { + // + XPivot result; + + // + NormalizeIndex(index, pivots); + + // + result = pivots[index]; + + // + return result; + } + + // + bool Add(double mPivot) + { + // + bool result = false; + + // + result = mPivot > 0 && !Has(mPivot); + if (!result) + { + return result; + } + + // + XPivot pivot; + pivot.pivot = mPivot; + + // + AddRef( + pivot, + pivots // + ); + + // + result = true; + + // + return result; + } + + // + int Adds(double &mPivots[]) + { + // + int result = 0; + + // + int pivotsCount = ArraySize(mPivots); + if (!IsValidSize(pivotsCount)) + { + return result; + } + + // + for (int i = 0; i < pivotsCount; i++) + { + // + double iPivot = mPivots[i]; + + // + bool isAdded = Add(iPivot); + if (isAdded) + { + result++; + } + } + + // + return result; + } + + // + int FindIndex(double mPivot) + { + // + int result = -1; + + // + if (mPivot <= 0) + { + return result; + } + + // + int count = Count(); + if (!IsValidSize(count)) + { + return result; + } + + // + for (int i = 0; i < count; i++) + { + // + XPivot iPivot = pivots[i]; + + // + if (iPivot.pivot == mPivot) + { + // + result = i; + break; + } + } + + // + return result; + } + + // + double Has(double mPivot) + { + // + bool result = false; + + // + int pivotIDX = FindIndex(mPivot); + result = pivotIDX >= 0; + + // + return result; + } + + // + int Reject(double mPivot) + { + // + int result = 0; + + // + int pivotIDX = FindIndex(mPivot); + if (pivotIDX < 0) + { + return result; + } + + // + pivots[pivotIDX].rejects++; + + // + result = pivots[pivotIDX].rejects; + + // + return result; + } + + // + int Break(double mPivot) + { + // + int result = 0; + + // + int pivotIDX = FindIndex(mPivot); + if (pivotIDX < 0) + { + return result; + } + + // + pivots[pivotIDX].breaks++; + + // + result = pivots[pivotIDX].breaks; + + // + return result; + } + + // + bool Remove(double mPivot) + { + // + bool result = false; + + // + int pivotIDX = FindIndex(mPivot); + result = pivotIDX >= 0; + if (!result) + { + return result; + } + + // + result = ArrayRemove( + pivots, + pivotIDX, + 1 // + ); + + // + return result; + } + + // + bool HasChild() + { + // + bool result = false; + + // + int count = Count(); + result = IsValidSize(count); + + // + return result; + } +}; + +// +// Model Support and Resistance +// for Specific Bar ... +struct XOHCLSupRes +{ + // + // Props ... + + // + /// Resistances ... + double res[]; + + // + // Supports ... + double sup[]; + + // + // Constructor ... + XOHCLSupRes() + { + Clean(); + } + + // + // Init ... + bool Init( + double price, // Price ... + const double &pivots[], // Provided Pivot Points ... + int count = 3, // Number of Requireds ... + double step = 0 // Distance between each item with it's Last Side ... + ) + { + // + bool result = false; + + // + Clean(); + + // + if (price <= 0) + { + return result; + } + + // + int pivotsCount = ArraySize(pivots); + if (pivotsCount <= 0) + { + return result; + } + + // + if (count <= 0 || + count > pivotsCount - 1) + { + return result; + } + + // + double lastR = 0; + double tmpR[]; + + // + double lastS = 0; + double tmpS[]; + + // + // Extract Supports ... + // which prices is under low of candle ... + // + // Extract Resistance ... + // which prices is over high of candle ... + for (int i = 0; i < pivotsCount; i++) + { + // + double iFlat = pivots[i]; + + // + if (iFlat > price) + { + // + bool canAdd = + step <= 0 + ? true + : lastR == 0 || MathAbs(iFlat - lastR) >= step; + if (canAdd) + { + // + Add( + iFlat, + tmpR); + + // + lastR = iFlat; + } + } + else if (iFlat < price) + { + // + bool canAdd = + step <= 0 + ? true + : lastS == 0 || MathAbs(iFlat - lastS) >= step; + if (canAdd) + { + // + Add( + iFlat, + tmpS); + + // + lastS = iFlat; + } + } + } + + // + // Sorting Founded Resistance and Supports ... + + // + // Since Resistance Levels must be Increasing ... + ArraySort(tmpR); + + // + // Since Support Levels must be Decreasing ... + ArraySort(tmpS); + ArrayReverse(tmpS); + + // + // Fill Resistance ... + int tmpRCount = ArraySize(tmpR); + if (tmpRCount > 0) + { + // + if (tmpRCount < count) + { + // + ArrayCopy( + res, + tmpR); + } + else + { + // + ArrayCopy( + res, + tmpR, + 0, + 0, + count); + } + } + + // + // Fill Supports ... + int tmpSCount = ArraySize(tmpS); + if (tmpSCount > 0) + { + // + if (tmpSCount < count) + { + // + ArrayCopy( + sup, + tmpS); + } + else + { + // + ArrayCopy( + sup, + tmpS, + 0, + 0, + count); + } + } + + // + result = IsValid(); + + // + return result; + } + + // + // Tools ... + + // + // Cleanup ... + void Clean() + { + // + Clean(sup); + Clean(res); + } + + // + // Validate ... + bool IsValid() + { + // + bool result = false; + + // + result = + // + CountSupports() > 0 || + CountResistances() > 0 + // + ; + + // + return result; + } + + // + int CountSupports() + { + return ArraySize(sup); + } + + // + int CountResistances() + { + return ArraySize(res); + } +}; + + +// +// Track Value Changes ... +template +struct XValueTracker +{ + // + // Definitions ... + + // + // Model a Value Change ... + struct XValueChange + { + // + // Props ... + datetime at; // Change Time + T from; // Before Change Value + T to; // After Change Value + + // + // Constructor ... + XValueChange() + { + Clean(); + } + + // + // Cleanup ... + void Clean() + { + // + at = NULL; + from = NULL; + to = NULL; + } + + // + // Validate ... + bool IsValid() + { + // + bool result = false; + + // + result = IsValid(at); + if (!result) + { + return result; + } + + // + result = NotEmpty(from) && + NotEmpty(to); + + // + return result; + } + }; + + // + // Props ... + XValueChange changes[]; // Hold Changes + + // + // Constructor ... + XValueTracker() + { + Clean(); + } + + // + // Track a Change Happens Or Not ... + bool Track( + const T &source[] // Data Source for Track Changes + ) + { + // + bool result = false; + + // + if (ArraySize(source) <= 1) + { + return result; + } + + // + datetime time = TimeCurrent(); + + // + double from = source[1]; + double to = source[0]; + + // + result = to != from; + if (result) + { + return result; + } + + // + XValueChange lastChange; + bool hasLastChange = + GetLastItem( + lastChange, + changes + // + ); + result = + !hasLastChange + ? true + : lastChange.at < time && + lastChange.to != to && + lastChange.from != from; + if (!result) + { + return result; + } + + // + lastChange.Clean(); + + // + lastChange.to = to; + lastChange.at = time; + lastChange.from = from; + + // + AddRef( + lastChange, + changes + // + ); + + // + return result; + } + + // + // Tools ... + + // + // Cleanup ... + void Clean() + { + Clean(changes); + } +}; + +// +int GenerateEQMOrders( + XSignal &orders[], // Result + XPosition &position, // Supported Position + XOHCLSupRes &supRes, // Data Source + bool longs = true, + bool shorts = true // +) +{ + // + int result = 0; + + // + Clean(orders); + + // + if (!supRes.IsValid() || + !position.IsValid()) + { + return result; + } + + // + if (longs) + { + // + double longLevels[]; + + // + Copy( + supRes.res, + longLevels // + ); + + // + double minSup = GetMin( + supRes.sup // + ); + if (minSup > 0) + { + // + Add( + minSup, + longLevels // + ); + } + + // + ArraySort(longLevels); + + // + if (ArraySize(longLevels) > 2) + { + // + for (int i = 0; i < ArraySize(longLevels) - 2; i++) + { + // + double iSL = longLevels[i]; + double iEntry = longLevels[i + 1]; + double iTP = longLevels[i + 2]; + + // + XSignal iSignal; + bool isPrepared = iSignal.PrepareStopLong( + position.symbol, + XEQMSupportToken, + position.period, + iEntry, + position.volume, + iSL, + iTP // + ); + if (isPrepared) + { + // + string comment = GenerateSupportTag(position.ticket); + iSignal.comment = comment; + + // + AddRef( + iSignal, + orders // + ); + } + } + } + } + + // + if (shorts) + { + // + double shortLevels[]; + + // + Copy( + supRes.sup, + shortLevels // + ); + + // + double maxRes = GetMax( + supRes.res // + ); + if (maxRes > 0) + { + // + Add( + maxRes, + shortLevels // + ); + } + + // + ArraySort(shortLevels); + ArrayReverse(shortLevels); + + // + if (ArraySize(shortLevels) > 2) + { + // + for (int i = 0; i < ArraySize(shortLevels) - 2; i++) + { + // + double iSL = shortLevels[i]; + double iEntry = shortLevels[i + 1]; + double iTP = shortLevels[i + 2]; + + // + XSignal iSignal; + bool isPrepared = iSignal.PrepareStopShort( + position.symbol, + XEQMSupportToken, + position.period, + iEntry, + position.volume, + iSL, + iTP // + ); + if (isPrepared) + { + // + string comment = GenerateSupportTag(position.ticket); + iSignal.comment = comment; + + // + AddRef( + iSignal, + orders // + ); + } + } + } + } + + // + result = ArraySize(orders); + + // + return result; +} diff --git a/Libraries/x-saherelm.common.lib.mq5 b/Libraries/x-saherelm.common.lib.mq5 index f8d36ab3..789b5b42 100644 --- a/Libraries/x-saherelm.common.lib.mq5 +++ b/Libraries/x-saherelm.common.lib.mq5 @@ -1719,541 +1719,6 @@ struct XOHCL } }; -// -struct XPivot -{ - // - double pivot; // Pivot Price ... - int breaks; // Number of Breaks ... - int rejects; // Number of Rejects ... - - // - void XPivot() - { - Clean(); - } - - // - // Tools ... - - // - // Cleanup ... - void Clean() - { - // - pivot = 0; - breaks = 0; - rejects = 0; - } - - // - // Validate ... - bool IsValid() - { - // - bool result = false; - - // - result = pivot > 0; - - // - return result; - } -}; - -// -struct XPivotTracker -{ - // - XPivot pivots[]; - - // - // Constructor ... - void XPivotTracker() - { - Clean(); - } - - // - // Tools ... - - // - // Cleanup ... - void Clean() - { - // - Clean(pivots); - } - - // - int Count() - { - return ArraySize(pivots); - } - - // - double Get(int index) - { - // - double result = 0; - - // - NormalizeIndex(index, pivots); - - // - XPivot iPivot = pivots[index]; - - // - result = iPivot.pivot; - - // - return result; - } - - // - XPivot GetPivot(int index) - { - // - XPivot result; - - // - NormalizeIndex(index, pivots); - - // - result = pivots[index]; - - // - return result; - } - - // - bool Add(double mPivot) - { - // - bool result = false; - - // - result = mPivot > 0 && !Has(mPivot); - if (!result) - { - return result; - } - - // - XPivot pivot; - pivot.pivot = mPivot; - - // - AddRef( - pivot, - pivots // - ); - - // - result = true; - - // - return result; - } - - // - int Adds(double &mPivots[]) - { - // - int result = 0; - - // - int pivotsCount = ArraySize(mPivots); - if (!IsValidSize(pivotsCount)) - { - return result; - } - - // - for (int i = 0; i < pivotsCount; i++) - { - // - double iPivot = mPivots[i]; - - // - bool isAdded = Add(iPivot); - if (isAdded) - { - result++; - } - } - - // - return result; - } - - // - int FindIndex(double mPivot) - { - // - int result = -1; - - // - if (mPivot <= 0) - { - return result; - } - - // - int count = Count(); - if (!IsValidSize(count)) - { - return result; - } - - // - for (int i = 0; i < count; i++) - { - // - XPivot iPivot = pivots[i]; - - // - if (iPivot.pivot == mPivot) - { - // - result = i; - break; - } - } - - // - return result; - } - - // - double Has(double mPivot) - { - // - bool result = false; - - // - int pivotIDX = FindIndex(mPivot); - result = pivotIDX >= 0; - - // - return result; - } - - // - int Reject(double mPivot) - { - // - int result = 0; - - // - int pivotIDX = FindIndex(mPivot); - if (pivotIDX < 0) - { - return result; - } - - // - pivots[pivotIDX].rejects++; - - // - result = pivots[pivotIDX].rejects; - - // - return result; - } - - // - int Break(double mPivot) - { - // - int result = 0; - - // - int pivotIDX = FindIndex(mPivot); - if (pivotIDX < 0) - { - return result; - } - - // - pivots[pivotIDX].breaks++; - - // - result = pivots[pivotIDX].breaks; - - // - return result; - } - - // - bool Remove(double mPivot) - { - // - bool result = false; - - // - int pivotIDX = FindIndex(mPivot); - result = pivotIDX >= 0; - if (!result) - { - return result; - } - - // - result = ArrayRemove( - pivots, - pivotIDX, - 1 // - ); - - // - return result; - } - - // - bool HasChild() - { - // - bool result = false; - - // - int count = Count(); - result = IsValidSize(count); - - // - return result; - } -}; - -// -// Model Support and Resistance -// for Specific Bar ... -struct XOHCLSupRes -{ - // - // Props ... - - // - /// Resistances ... - double res[]; - - // - // Supports ... - double sup[]; - - // - // Constructor ... - XOHCLSupRes() - { - Clean(); - } - - // - // Init ... - bool Init( - double price, // Price ... - const double &pivots[], // Provided Pivot Points ... - int count = 3, // Number of Requireds ... - double step = 0 // Distance between each item with it's Last Side ... - ) - { - // - bool result = false; - - // - Clean(); - - // - if (price <= 0) - { - return result; - } - - // - int pivotsCount = ArraySize(pivots); - if (pivotsCount <= 0) - { - return result; - } - - // - if (count <= 0 || - count > pivotsCount - 1) - { - return result; - } - - // - double lastR = 0; - double tmpR[]; - - // - double lastS = 0; - double tmpS[]; - - // - // Extract Supports ... - // which prices is under low of candle ... - // - // Extract Resistance ... - // which prices is over high of candle ... - for (int i = 0; i < pivotsCount; i++) - { - // - double iFlat = pivots[i]; - - // - if (iFlat > price) - { - // - bool canAdd = - step <= 0 - ? true - : lastR == 0 || MathAbs(iFlat - lastR) >= step; - if (canAdd) - { - // - Add( - iFlat, - tmpR); - - // - lastR = iFlat; - } - } - else if (iFlat < price) - { - // - bool canAdd = - step <= 0 - ? true - : lastS == 0 || MathAbs(iFlat - lastS) >= step; - if (canAdd) - { - // - Add( - iFlat, - tmpS); - - // - lastS = iFlat; - } - } - } - - // - // Sorting Founded Resistance and Supports ... - - // - // Since Resistance Levels must be Increasing ... - ArraySort(tmpR); - - // - // Since Support Levels must be Decreasing ... - ArraySort(tmpS); - ArrayReverse(tmpS); - - // - // Fill Resistance ... - int tmpRCount = ArraySize(tmpR); - if (tmpRCount > 0) - { - // - if (tmpRCount < count) - { - // - ArrayCopy( - res, - tmpR); - } - else - { - // - ArrayCopy( - res, - tmpR, - 0, - 0, - count); - } - } - - // - // Fill Supports ... - int tmpSCount = ArraySize(tmpS); - if (tmpSCount > 0) - { - // - if (tmpSCount < count) - { - // - ArrayCopy( - sup, - tmpS); - } - else - { - // - ArrayCopy( - sup, - tmpS, - 0, - 0, - count); - } - } - - // - result = IsValid(); - - // - return result; - } - - // - // Tools ... - - // - // Cleanup ... - void Clean() - { - // - Clean(sup); - Clean(res); - } - - // - // Validate ... - bool IsValid() - { - // - bool result = false; - - // - result = - // - CountSupports() > 0 || - CountResistances() > 0 - // - ; - - // - return result; - } - - // - int CountSupports() - { - return ArraySize(sup); - } - - // - int CountResistances() - { - return ArraySize(res); - } -}; - // // Tracking Times ... struct XTimeTracker @@ -2615,153 +2080,6 @@ struct XBarTracker } }; -// -// Track Value Changes ... -template -struct XValueTracker -{ - // - // Definitions ... - - // - // Model a Value Change ... - struct XValueChange - { - // - // Props ... - datetime at; // Change Time - T from; // Before Change Value - T to; // After Change Value - - // - // Constructor ... - XValueChange() - { - Clean(); - } - - // - // Cleanup ... - void Clean() - { - // - at = NULL; - from = NULL; - to = NULL; - } - - // - // Validate ... - bool IsValid() - { - // - bool result = false; - - // - result = IsValid(at); - if (!result) - { - return result; - } - - // - result = NotEmpty(from) && - NotEmpty(to); - - // - return result; - } - }; - - // - // Props ... - XValueChange changes[]; // Hold Changes - - // - // Constructor ... - XValueTracker() - { - Clean(); - } - - // - // Track a Change Happens Or Not ... - bool Track( - const T &source[] // Data Source for Track Changes - ) - { - // - bool result = false; - - // - if (ArraySize(source) <= 1) - { - return result; - } - - // - datetime time = TimeCurrent(); - - // - double from = source[1]; - double to = source[0]; - - // - result = to != from; - if (result) - { - return result; - } - - // - XValueChange lastChange; - bool hasLastChange = - GetLastItem( - lastChange, - changes - // - ); - result = - !hasLastChange - ? true - : lastChange.at < time && - lastChange.to != to && - lastChange.from != from; - if (!result) - { - return result; - } - - // - lastChange.Clean(); - - // - lastChange.to = to; - lastChange.at = time; - lastChange.from = from; - - // - AddRef( - lastChange, - changes - // - ); - - // - return result; - } - - // - // Tools ... - - // - // Cleanup ... - void Clean() - { - Clean(changes); - } -}; - // // Model a Market Cycle ... struct XMarketCycle @@ -3486,6 +2804,306 @@ struct XLinearRegression // }; +// +// Use To Parse Symbols for +// Ignore Brokers Additional Suffixes ... +struct XSymbolParser +{ + // + string version; // Temp ... + + // + // Forext ... + + // + bool IsEURUSD(string symbol) + { + // + string symbolIdentifiers[] = { + "EUR", + "USD" // + }; + + // + bool result = Contains( + symbolIdentifiers, + symbol // + ); + + // + return result; + } + + // + bool IsUSDJPY(string symbol) + { + // + string symbolIdentifiers[] = { + "USD", + "JPY" // + }; + + // + bool result = Contains( + symbolIdentifiers, + symbol // + ); + + // + return result; + } + + // + bool IsEURJPY(string symbol) + { + // + string symbolIdentifiers[] = { + "EUR", + "JPY" // + }; + + // + bool result = Contains( + symbolIdentifiers, + symbol // + ); + + // + return result; + } + + // + bool IsUSDCHF(string symbol) + { + // + string symbolIdentifiers[] = { + "USD", + "CHF" // + }; + + // + bool result = Contains( + symbolIdentifiers, + symbol // + ); + + // + return result; + } + + // + bool IsEURCHF(string symbol) + { + // + string symbolIdentifiers[] = { + "EUR", + "CHF" // + }; + + // + bool result = Contains( + symbolIdentifiers, + symbol // + ); + + // + return result; + } + + // + bool IsGBPUSD(string symbol) + { + // + string symbolIdentifiers[] = { + "GBP", + "USD" // + }; + + // + bool result = Contains( + symbolIdentifiers, + symbol // + ); + + // + return result; + } + + // + bool IsEURGBP(string symbol) + { + // + string symbolIdentifiers[] = { + "EUR", + "GBP" // + }; + + // + bool result = Contains( + symbolIdentifiers, + symbol // + ); + + // + return result; + } + + // + bool IsAUDUSD(string symbol) + { + // + string symbolIdentifiers[] = { + "AUD", + "USD" // + }; + + // + bool result = Contains( + symbolIdentifiers, + symbol // + ); + + // + return result; + } + + // + bool IsEURAUD(string symbol) + { + // + string symbolIdentifiers[] = { + "EUR", + "AUD" // + }; + + // + bool result = Contains( + symbolIdentifiers, + symbol // + ); + + // + return result; + } + + // + bool IsUSDCAD(string symbol) + { + // + string symbolIdentifiers[] = { + "USD", + "CAD" // + }; + + // + bool result = Contains( + symbolIdentifiers, + symbol // + ); + + // + return result; + } + + // + bool IsEURCAD(string symbol) + { + // + string symbolIdentifiers[] = { + "EUR", + "CAD" // + }; + + // + bool result = Contains( + symbolIdentifiers, + symbol // + ); + + // + return result; + } + + // + bool IsNZDUSD(string symbol) + { + // + string symbolIdentifiers[] = { + "NZD", + "USD" // + }; + + // + bool result = Contains( + symbolIdentifiers, + symbol // + ); + + // + return result; + } + + // + bool IsEURNZD(string symbol) + { + // + string symbolIdentifiers[] = { + "EUR", + "NZD" // + }; + + // + bool result = Contains( + symbolIdentifiers, + symbol // + ); + + // + return result; + } + + // + // Metals ... + + // + bool IsXAUUSD(string symbol) + { + // + string symbolIdentifiers[] = { + "XAU", + "USD" // + }; + + // + bool result = Contains( + symbolIdentifiers, + symbol // + ); + + // + return result; + } + + // + bool IsXAGUSD(string symbol) + { + // + string symbolIdentifiers[] = { + "XAG", + "USD" // + }; + + // + bool result = Contains( + symbolIdentifiers, + symbol // + ); + + // + return result; + } +}; + // // Styling Buffers ... @@ -9061,4 +8679,6 @@ ENUM_TIMEFRAMES GetCyclePeriod( // return result; -} \ No newline at end of file +} + +// \ No newline at end of file diff --git a/Libraries/x-saherelm.xtrade.lib.mq5 b/Libraries/x-saherelm.xtrade.lib.mq5 index 9929d626..6d83a0bf 100644 --- a/Libraries/x-saherelm.xtrade.lib.mq5 +++ b/Libraries/x-saherelm.xtrade.lib.mq5 @@ -4988,171 +4988,6 @@ string PrepareSLTrailTag( return result; } -// -// EQM Support Orders ... - -// -int GenerateEQMOrders( - XSignal &orders[], // Result - XPosition &position, // Supported Position - XOHCLSupRes &supRes, // Data Source - bool longs = true, - bool shorts = true // -) -{ - // - int result = 0; - - // - Clean(orders); - - // - if (!supRes.IsValid() || - !position.IsValid()) - { - return result; - } - - // - if (longs) - { - // - double longLevels[]; - - // - Copy( - supRes.res, - longLevels // - ); - - // - double minSup = GetMin( - supRes.sup // - ); - if (minSup > 0) - { - // - Add( - minSup, - longLevels // - ); - } - - // - ArraySort(longLevels); - - // - if (ArraySize(longLevels) > 2) - { - // - for (int i = 0; i < ArraySize(longLevels) - 2; i++) - { - // - double iSL = longLevels[i]; - double iEntry = longLevels[i + 1]; - double iTP = longLevels[i + 2]; - - // - XSignal iSignal; - bool isPrepared = iSignal.PrepareStopLong( - position.symbol, - XEQMSupportToken, - position.period, - iEntry, - position.volume, - iSL, - iTP // - ); - if (isPrepared) - { - // - string comment = GenerateSupportTag(position.ticket); - iSignal.comment = comment; - - // - AddRef( - iSignal, - orders // - ); - } - } - } - } - - // - if (shorts) - { - // - double shortLevels[]; - - // - Copy( - supRes.sup, - shortLevels // - ); - - // - double maxRes = GetMax( - supRes.res // - ); - if (maxRes > 0) - { - // - Add( - maxRes, - shortLevels // - ); - } - - // - ArraySort(shortLevels); - ArrayReverse(shortLevels); - - // - if (ArraySize(shortLevels) > 2) - { - // - for (int i = 0; i < ArraySize(shortLevels) - 2; i++) - { - // - double iSL = shortLevels[i]; - double iEntry = shortLevels[i + 1]; - double iTP = shortLevels[i + 2]; - - // - XSignal iSignal; - bool isPrepared = iSignal.PrepareStopShort( - position.symbol, - XEQMSupportToken, - position.period, - iEntry, - position.volume, - iSL, - iTP // - ); - if (isPrepared) - { - // - string comment = GenerateSupportTag(position.ticket); - iSignal.comment = comment; - - // - AddRef( - iSignal, - orders // - ); - } - } - } - } - - // - result = ArraySize(orders); - - // - return result; -} - // // Count Positions from a Collection ... void CountPositions(