From da4c0f6646cdff1a19567551de0c12803e16cbfa Mon Sep 17 00:00:00 2001 From: Hadi Khazaee Asl Date: Mon, 10 Jun 2024 12:44:15 +0330 Subject: [PATCH] last works on create X121Setup ... --- Classes/x-saherelm.base.class.mq5 | 32 +- Classes/x-saherelm.x121.setup.class.mq5 | 2120 +++++++++++++++++++++++ Classes/x-saherelm.xind.class.mq5 | 239 +++ Documents/BKP/Source Codes/cIADX.mq5 | 136 ++ Experts/x-test-xxx.mq5 | 1739 +++++++++++++++++++ Helpers/x-saherelm.xadxtd.helper.mq5 | 678 ++++++++ Helpers/x-saherelm.xasct.helper.mq5 | 197 +++ Helpers/x-saherelm.xche.helper.mq5 | 289 +++ Helpers/x-saherelm.xhk.helper.mq5 | 279 +++ Helpers/x-saherelm.xhull.helper.mq5 | 274 ++- Helpers/x-saherelm.xich.helper.mq5 | 746 ++++++++ Helpers/x-saherelm.xmatd.helper.mq5 | 1046 +++++++++++ Helpers/x-saherelm.xmrb.helper.mq5 | 221 +++ Helpers/x-saherelm.xsslc.helper.mq5 | 220 +++ Helpers/x-saherelm.xstr.helper.mq5 | 222 ++- Helpers/x-saherelm.xtd.helper.mq5 | 222 ++- Libraries/x-saherelm.common.lib.mq5 | 163 +- 17 files changed, 8813 insertions(+), 10 deletions(-) create mode 100644 Classes/x-saherelm.x121.setup.class.mq5 create mode 100644 Documents/BKP/Source Codes/cIADX.mq5 create mode 100644 Experts/x-test-xxx.mq5 create mode 100644 Helpers/x-saherelm.xadxtd.helper.mq5 create mode 100644 Helpers/x-saherelm.xmatd.helper.mq5 diff --git a/Classes/x-saherelm.base.class.mq5 b/Classes/x-saherelm.base.class.mq5 index 3178250b..8425c50e 100644 --- a/Classes/x-saherelm.base.class.mq5 +++ b/Classes/x-saherelm.base.class.mq5 @@ -46,4 +46,34 @@ protected: private: }; -// \ No newline at end of file +// +template +string GenerateSpecifiedCommonSummary( + T &mItem, + string separator = "\n", + bool includeScores = true, + bool setLabel = false // +) +{ + // + string result = NULL; + + // + result = + // + (!setLabel + ? "" + : "Commons:" + separator) + + "---------------" + separator + + "Symbol: " + mItem.symbol + separator + + "Period: " + ToString(mItem.period) + separator + + "Time: " + ToString(mItem.time) + separator + + "" + // + ; + + // + return result; +} + +// diff --git a/Classes/x-saherelm.x121.setup.class.mq5 b/Classes/x-saherelm.x121.setup.class.mq5 new file mode 100644 index 00000000..c9dc5d3c --- /dev/null +++ b/Classes/x-saherelm.x121.setup.class.mq5 @@ -0,0 +1,2120 @@ +/////////////////////////////////////////////////////// +// +// SaherElm IT Center MQL5 Class Library +// ---------------------------------------------- +// Name: XSCX121Setup +// Description: provides implementation of X121 +// Setup ... +// +// +// Maintainer: +// ------------ +// Hadi Khazaee Asl (hadi_khazaee_asl@yahoo.com) +// +////////////////////////////////////////////////////// +// +// Global Properties ... +#property library +#property copyright "Copyright 2023, SaherElm IT Center" +#property link "https://www.saherelm.ir" +#property version "1.00" +#property strict + +// +// Imports ... + +// +#include "../Libraries/x-saherelm.xtrade.lib.mq5" + +// +#include "../Classes/x-saherelm.xalert.class.mq5" + +// +#include "../Helpers/x-saherelm.xtd.helper.mq5" +#include "../Helpers/x-saherelm.xhk.helper.mq5" +#include "../Helpers/x-saherelm.xstr.helper.mq5" +#include "../Helpers/x-saherelm.xche.helper.mq5" +#include "../Helpers/x-saherelm.xich.helper.mq5" +#include "../Helpers/x-saherelm.xmrb.helper.mq5" +#include "../Helpers/x-saherelm.xosc.helper.mq5" +#include "../Helpers/x-saherelm.xasct.helper.mq5" +#include "../Helpers/x-saherelm.xsslc.helper.mq5" +#include "../Helpers/x-saherelm.xhull.helper.mq5" +#include "../Helpers/x-saherelm.xmatd.helper.mq5" +#include "../Helpers/x-saherelm.xadxtd.helper.mq5" + +// +// Definitions ... + +// +// Inputs ... +struct X121SetupInputs +{ + // + // Commons ... + string symbol; // Symbol + ENUM_TIMEFRAMES period; // Time Frame + + // + // Helpers Inputs ... + XTDInputs tdInputs; // XTD Inputs + XHKInputs hkInputs; // XHK Inputs + XCHEInputs cheInputs; // XCHE Inputs + XICHInputs ichInputs; // XICH Inputs + XSTRInputs strInputs; // XSTR Inputs + XMRBInputs mrbInputs; // XMRB Inputs + XOSCInputs oscInputs; // XOSC Inputs + XMATDInputs matdInputs; // XMATD Inputs + XASCTInputs asctInputs; // XASCT Inputs + XSSLCInputs sslcInputs; // XSSLC Inputs + XHULLInputs hullInputs; // XHULL Inputs + XADXTDInputs adxtdInputs; // XADXTD Inputs + + // + // Constructor ... + void X121SetupInputs() + { + Clean(); + } + + // + bool Init() + { + // + Default(); + + // + bool result = IsValid(); + + // + return result; + } + bool Init( + string _symbol, // Symbol + ENUM_TIMEFRAMES _period, // Time Frame + XTDInputs &_tdInputs, // XTD Inputs + XHKInputs &_hkInputs, // XHK Inputs + XCHEInputs &_cheInputs, // XCHE Inputs + XICHInputs &_ichInputs, // XICH Inputs + XSTRInputs &_strInputs, // XSTR Inputs + XMRBInputs &_mrbInputs, // XMRB Inputs + XOSCInputs &_oscInputs, // XOSC Inputs + XMATDInputs &_matdInputs, // XMATD Inputs + XASCTInputs &_asctInputs, // XASCT Inputs + XSSLCInputs &_sslcInputs, // XSSLC Inputs + XHULLInputs &_hullInputs, // XHULL Inputs + XADXTDInputs &_adxtdInputs // XADXTD Inputs + ) + { + // + this.symbol = _symbol; + this.period = _period; + + // + // Helpers Inputs ... + this.tdInputs = _tdInputs; + this.hkInputs = _hkInputs; + this.cheInputs = _cheInputs; + this.ichInputs = _ichInputs; + this.strInputs = _strInputs; + this.mrbInputs = _mrbInputs; + this.oscInputs = _oscInputs; + this.matdInputs = _matdInputs; + this.asctInputs = _asctInputs; + this.sslcInputs = _sslcInputs; + this.hullInputs = _hullInputs; + this.adxtdInputs = _adxtdInputs; + + // + bool result = IsValid(); + + // + return result; + } + + // + // Tools ... + + // + // Cleanup ... + void Clean() + { + // + symbol = NULL; + period = NULL; + + // + tdInputs.Clean(); + hkInputs.Clean(); + cheInputs.Clean(); + ichInputs.Clean(); + strInputs.Clean(); + mrbInputs.Clean(); + oscInputs.Clean(); + matdInputs.Clean(); + asctInputs.Clean(); + sslcInputs.Clean(); + hullInputs.Clean(); + adxtdInputs.Clean(); + } + + // + // Default ... + void Default() + { + // + tdInputs.Default(); + hkInputs.Default(); + cheInputs.Default(); + ichInputs.Default(); + strInputs.Default(); + mrbInputs.Default(); + oscInputs.Default(); + matdInputs.Default(); + asctInputs.Default(); + sslcInputs.Default(); + hullInputs.Default(); + adxtdInputs.Default(); + } + + // + // Validate ... + bool IsValid() + { + // + bool result = false; + + // + result = + // + IsValid(symbol) && + IsValid(period) + // + ; + if (!result) + { + return result; + } + + // + result = tdInputs.IsValid(); + if (!result) + { + return result; + } + + result = hkInputs.IsValid(); + if (!result) + { + return result; + } + + result = cheInputs.IsValid(); + if (!result) + { + return result; + } + + result = ichInputs.IsValid(); + if (!result) + { + return result; + } + + result = strInputs.IsValid(); + if (!result) + { + return result; + } + + result = mrbInputs.IsValid(); + if (!result) + { + return result; + } + + result = oscInputs.IsValid(); + if (!result) + { + return result; + } + + result = matdInputs.IsValid(); + if (!result) + { + return result; + } + + result = asctInputs.IsValid(); + if (!result) + { + return result; + } + + result = sslcInputs.IsValid(); + if (!result) + { + return result; + } + + result = hullInputs.IsValid(); + if (!result) + { + return result; + } + + result = adxtdInputs.IsValid(); + if (!result) + { + return result; + } + + // + return result; + } +}; + +// +// Conditions ... +struct X121SetupConditions +{ + // + // Common ... + string symbol; + ENUM_TIMEFRAMES period; + datetime time; + + // + // Conditions ... + XTDConditions tdConditions; + XHKConditions hkConditions; + XCHEConditions cheConditions; + XICHConditions ichConditions; + XSTRConditions strConditions; + XMRBConditions mrbConditions; + XMATDConditions matdConditions; + XASCTConditions asctConditions; + XSSLCConditions sslcConditions; + XHULLConditions hullConditions; + XADXTDConditions adxtdConditions; + + // + // Oscillators ... + double cci[]; + double rsi[]; + double macd[]; + double macdSignal[]; + + // + // Tools ... + + // + // Cleanup ... + void Clean() + { + // + time = NULL; + symbol = NULL; + period = NULL; + + // + Clean(cci); + Clean(rsi); + Clean(macd); + Clean(macdSignal); + + // + tdConditions.Clean(); + hkConditions.Clean(); + cheConditions.Clean(); + ichConditions.Clean(); + strConditions.Clean(); + mrbConditions.Clean(); + matdConditions.Clean(); + asctConditions.Clean(); + sslcConditions.Clean(); + hullConditions.Clean(); + adxtdConditions.Clean(); + } + + // + void GenerateScore( + double &bullishScore, + double &bearishScore // + ) + { + // + bullishScore = 0; + bearishScore = 0; + + // + double tempBullishScore = 0; + double tempBearishScore = 0; + + // + matdConditions.GenerateScore( + tempBullishScore, + tempBearishScore // + ); + bullishScore += tempBullishScore; + bearishScore += tempBearishScore; + + // + adxtdConditions.GenerateScore( + tempBullishScore, + tempBearishScore // + ); + bullishScore += tempBullishScore; + bearishScore += tempBearishScore; + + // + strConditions.GenerateScore( + tempBullishScore, + tempBearishScore // + ); + bullishScore += tempBullishScore; + bearishScore += tempBearishScore; + + // + cheConditions.GenerateScore( + tempBullishScore, + tempBearishScore // + ); + bullishScore += tempBullishScore; + bearishScore += tempBearishScore; + + // + asctConditions.GenerateScore( + tempBullishScore, + tempBearishScore // + ); + bullishScore += tempBullishScore; + bearishScore += tempBearishScore; + + // + tdConditions.GenerateScore( + tempBullishScore, + tempBearishScore // + ); + bullishScore += tempBullishScore; + bearishScore += tempBearishScore; + + // + ichConditions.GenerateScore( + tempBullishScore, + tempBearishScore // + ); + bullishScore += tempBullishScore; + bearishScore += tempBearishScore; + + // + hkConditions.GenerateScore( + tempBullishScore, + tempBearishScore // + ); + bullishScore += tempBullishScore; + bearishScore += tempBearishScore; + + // + mrbConditions.GenerateScore( + tempBullishScore, + tempBearishScore // + ); + bullishScore += tempBullishScore; + bearishScore += tempBearishScore; + + // + sslcConditions.GenerateScore( + tempBullishScore, + tempBearishScore // + ); + bullishScore += tempBullishScore; + bearishScore += tempBearishScore; + + // + hullConditions.GenerateScore( + tempBullishScore, + tempBearishScore // + ); + bullishScore += tempBullishScore; + bearishScore += tempBearishScore; + } + + // + string GenerateSummary( + bool onlyCommons = false, + bool onlyConditions = false, + bool includeScores = true, + bool ignoreFalseConditions = true, + string separator = "\n" // + ) + { + // + string result = NULL; + + // + double bullishScore = 0; + double bearishScore = 0; + GenerateScore( + bullishScore, + bearishScore // + ); + + // + string scoresStr = + // + "Scores: " + separator + + "---------------" + separator + + "Bullish: " + ToString(bullishScore) + separator + + "Bearish: " + ToString(bearishScore) + separator + + "" + // + ; + + // + string commonStr = GenerateSpecifiedCommonSummary( + this, + separator, + includeScores // + ); + + // + string matdSummary = matdConditions.GenerateSummary(false, true, false); + string adxtdSummary = adxtdConditions.GenerateSummary(false, true, false); + string strSummary = strConditions.GenerateSummary(false, true, false); + string cheSummary = cheConditions.GenerateSummary(false, true, false); + string asctSummary = asctConditions.GenerateSummary(false, true, false); + string tdSummary = tdConditions.GenerateSummary(false, true, false); + string ichSummary = ichConditions.GenerateSummary(false, true, false); + string hkSummary = hkConditions.GenerateSummary(false, true, false); + string mrbSummary = mrbConditions.GenerateSummary(false, true, false); + string sslcSummary = sslcConditions.GenerateSummary(false, true, false); + string hullSummary = hullConditions.GenerateSummary(false, true, false); + + // + string conditionsStr = + // + matdSummary + separator + + adxtdSummary + separator + + strSummary + separator + + cheSummary + separator + + asctSummary + separator + + tdSummary + separator + + ichSummary + separator + + hkSummary + separator + + mrbSummary + separator + + sslcSummary + separator + + hullSummary + separator + + "" + // + ; + + // + result = + // + "[" + GetTag() + "]" + separator + + (onlyConditions + ? "" + : commonStr) + + (!includeScores + ? "" + : scoresStr) + + " " + separator + + (onlyCommons + ? "" + : conditionsStr) + + "" + // + ; + + // + return result; + } + + // + string GetTag() + { + return "X121Setup"; + } +}; + +// +// Condition Parser ... +struct X121SignalGenerator +{ + // + string version; + + // + // 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; + } + // + // 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; + } + + // + // Check Market Conditions for Long Signals ... + bool HasLongConditions( + X121SetupConditions &conditions, // Conditions + int &pusher // Pushers + ) + { + // + bool result = false; + + // + pusher = 0; + + // + bool isOSCShortVerified = IsOSCShortVerified(conditions); + + // + int zIndex = 0; + int cIndex = zIndex + 1; + int pIndex = cIndex + 1; + + // + double bullishScore = 0; + double bearishScore = 0; + conditions.GenerateScore( + bullishScore, + bearishScore // + ); + + // + bool long1 = + // + // Starting Conditions ... + conditions.matdConditions.isSwitchedToBullish && + // + // Verifications ... + conditions.matdConditions.isSARBullish && + conditions.adxtdConditions.isStrong && + conditions.adxtdConditions.isBullish && + conditions.strConditions.isTrendBullish && + conditions.cheConditions.isStrongBullish && + conditions.tdConditions.isBullish && + conditions.hkConditions.isHKBullish && + conditions.hkConditions.isSMHKBullish && + conditions.mrbConditions.isFastOverSlow && + conditions.sslcConditions.isBullish && + conditions.hullConditions.isBullish + // + ; + if (long1) + { + pusher++; + } + + // + bool long2 = + // + // Starting Conditions ... + conditions.matdConditions.isSARSwitchedToBullish && + // + // Verifications ... + conditions.matdConditions.isBullish && + conditions.adxtdConditions.isStrong && + conditions.adxtdConditions.isBullish && + conditions.strConditions.isTrendBullish && + conditions.cheConditions.isStrongBullish && + conditions.tdConditions.isBullish && + conditions.hkConditions.isHKBullish && + conditions.hkConditions.isSMHKBullish && + conditions.mrbConditions.isFastOverSlow && + conditions.sslcConditions.isBullish && + conditions.hullConditions.isBullish + // + ; + if (long2) + { + pusher++; + } + + // + bool long3 = + // + // Starting Conditions ... + conditions.adxtdConditions.isStrongSwitchedToBullish && + // + // Verifications ... + conditions.matdConditions.isBullish && + conditions.strConditions.isTrendBullish && + conditions.cheConditions.isStrongBullish && + conditions.tdConditions.isBullish && + conditions.hkConditions.isHKBullish && + conditions.hkConditions.isSMHKBullish && + conditions.mrbConditions.isFastOverSlow && + conditions.sslcConditions.isBullish && + conditions.hullConditions.isBullish + // + ; + if (long3) + { + pusher++; + } + + // + bool long4 = + // + // Starting Conditions ... + conditions.strConditions.isTrendSwitchedToBullish && + // + // Verifications ... + conditions.matdConditions.isBullish && + conditions.adxtdConditions.isStrong && + conditions.adxtdConditions.isBullish && + conditions.cheConditions.isStrongBullish && + conditions.tdConditions.isBullish && + conditions.hkConditions.isHKBullish && + conditions.hkConditions.isSMHKBullish && + conditions.mrbConditions.isFastOverSlow && + conditions.sslcConditions.isBullish && + conditions.hullConditions.isBullish + // + ; + if (long4) + { + pusher++; + } + + // + bool long5 = + // + // Starting Conditions ... + conditions.cheConditions.isStrongSwitchedToBullish && + // + // Verifications ... + conditions.matdConditions.isBullish && + conditions.adxtdConditions.isStrong && + conditions.adxtdConditions.isBullish && + conditions.strConditions.isTrendBullish && + conditions.tdConditions.isBullish && + conditions.hkConditions.isHKBullish && + conditions.hkConditions.isSMHKBullish && + conditions.mrbConditions.isFastOverSlow && + conditions.sslcConditions.isBullish && + conditions.hullConditions.isBullish + // + ; + if (long5) + { + pusher++; + } + + // + bool long6 = + // + // Starting Conditions ... + conditions.tdConditions.isSwitchedToBullish && + // + // Verifications ... + conditions.matdConditions.isBullish && + conditions.adxtdConditions.isStrong && + conditions.adxtdConditions.isBullish && + conditions.strConditions.isTrendBullish && + conditions.cheConditions.isStrongBullish && + conditions.hkConditions.isHKBullish && + conditions.hkConditions.isSMHKBullish && + conditions.mrbConditions.isFastOverSlow && + conditions.sslcConditions.isBullish && + conditions.hullConditions.isBullish + // + ; + if (long6) + { + pusher++; + } + + // + bool long7 = + // + // Starting Conditions ... + conditions.rsi[cIndex] > 30 && + conditions.rsi[pIndex] <= 30 && + // + // Verifications ... + conditions.tdConditions.isBullish && + conditions.matdConditions.isBullish && + conditions.adxtdConditions.isStrong && + conditions.adxtdConditions.isBullish && + conditions.strConditions.isTrendBullish && + conditions.cheConditions.isStrongBullish && + conditions.hkConditions.isHKBullish && + conditions.hkConditions.isSMHKBullish && + conditions.mrbConditions.isFastOverSlow && + conditions.sslcConditions.isBullish && + conditions.hullConditions.isBullish + // + ; + if (long7) + { + pusher++; + } + + // + bool long8 = + // + // Starting Conditions ... + conditions.cci[cIndex] > -100 && + conditions.cci[pIndex] <= -100 && + // + // Verifications ... + conditions.tdConditions.isBullish && + conditions.matdConditions.isBullish && + conditions.adxtdConditions.isStrong && + conditions.adxtdConditions.isBullish && + conditions.strConditions.isTrendBullish && + conditions.cheConditions.isStrongBullish && + conditions.hkConditions.isHKBullish && + conditions.hkConditions.isSMHKBullish && + conditions.mrbConditions.isFastOverSlow && + conditions.sslcConditions.isBullish && + conditions.hullConditions.isBullish + // + ; + if (long8) + { + pusher++; + } + + // + bool long9 = + // + // Starting Conditions ... + conditions.macd[cIndex] > 0 && + conditions.macd[cIndex] > conditions.macdSignal[cIndex] && + // + // Verifications ... + conditions.tdConditions.isBullish && + conditions.matdConditions.isBullish && + conditions.adxtdConditions.isStrong && + conditions.adxtdConditions.isBullish && + conditions.strConditions.isTrendBullish && + conditions.cheConditions.isStrongBullish && + conditions.hkConditions.isHKBullish && + conditions.hkConditions.isSMHKBullish && + conditions.mrbConditions.isFastOverSlow && + conditions.sslcConditions.isBullish && + conditions.hullConditions.isBullish + // + ; + if (long9) + { + pusher++; + } + + // + bool long10 = + // + // Starting Conditions ... + conditions.ichConditions.HasLongConditions() && + // + // Verifications ... + conditions.tdConditions.isBullish && + conditions.matdConditions.isBullish && + conditions.adxtdConditions.isStrong && + conditions.adxtdConditions.isBullish && + conditions.strConditions.isTrendBullish && + conditions.cheConditions.isStrongBullish && + conditions.hkConditions.isHKBullish && + conditions.hkConditions.isSMHKBullish && + conditions.mrbConditions.isFastOverSlow && + conditions.sslcConditions.isBullish && + conditions.hullConditions.isBullish + // + ; + if (long10) + { + pusher++; + } + + // + bool long11 = + // + // Starting Conditions ... + conditions.hkConditions.isHKSwitchedToBullish && + // + // Verifications ... + conditions.tdConditions.isBullish && + conditions.matdConditions.isBullish && + conditions.adxtdConditions.isStrong && + conditions.adxtdConditions.isBullish && + conditions.strConditions.isTrendBullish && + conditions.cheConditions.isStrongBullish && + conditions.hkConditions.isSMHKBullish && + conditions.mrbConditions.isFastOverSlow && + conditions.sslcConditions.isBullish && + conditions.hullConditions.isBullish + // + ; + if (long11) + { + pusher++; + } + + // + bool long12 = + // + // Starting Conditions ... + conditions.hkConditions.isSMHKSwitchedToBullish && + // + // Verifications ... + conditions.tdConditions.isBullish && + conditions.matdConditions.isBullish && + conditions.adxtdConditions.isStrong && + conditions.adxtdConditions.isBullish && + conditions.strConditions.isTrendBullish && + conditions.cheConditions.isStrongBullish && + conditions.hkConditions.isHKBullish && + conditions.mrbConditions.isFastOverSlow && + conditions.sslcConditions.isBullish && + conditions.hullConditions.isBullish + // + ; + if (long12) + { + pusher++; + } + + // + bool long13 = + // + // Starting Conditions ... + conditions.mrbConditions.isFastCrossedOverSlow && + // + // Verifications ... + conditions.tdConditions.isBullish && + conditions.matdConditions.isBullish && + conditions.adxtdConditions.isStrong && + conditions.adxtdConditions.isBullish && + conditions.strConditions.isTrendBullish && + conditions.cheConditions.isStrongBullish && + conditions.hkConditions.isHKBullish && + conditions.hkConditions.isSMHKBullish && + conditions.sslcConditions.isBullish && + conditions.hullConditions.isBullish + // + ; + if (long13) + { + pusher++; + } + + // + bool long14 = + // + // Starting Conditions ... + conditions.sslcConditions.isSwitchedToBullish && + // + // Verifications ... + conditions.tdConditions.isBullish && + conditions.matdConditions.isBullish && + conditions.adxtdConditions.isStrong && + conditions.adxtdConditions.isBullish && + conditions.strConditions.isTrendBullish && + conditions.cheConditions.isStrongBullish && + conditions.hkConditions.isHKBullish && + conditions.hkConditions.isSMHKBullish && + conditions.mrbConditions.isFastOverSlow && + conditions.hullConditions.isBullish + // + ; + if (long14) + { + pusher++; + } + + // + bool long15 = + // + // Starting Conditions ... + conditions.hullConditions.isSwitchedToBullish && + // + // Verifications ... + conditions.tdConditions.isBullish && + conditions.matdConditions.isBullish && + conditions.adxtdConditions.isStrong && + conditions.adxtdConditions.isBullish && + conditions.strConditions.isTrendBullish && + conditions.cheConditions.isStrongBullish && + conditions.hkConditions.isHKBullish && + conditions.hkConditions.isSMHKBullish && + conditions.mrbConditions.isFastOverSlow && + conditions.sslcConditions.isBullish + // + ; + if (long15) + { + pusher++; + } + + // + result = + // + pusher >= 1 && + !isOSCShortVerified && + conditions.asctConditions.isLongSignal && + bullishScore > bearishScore * 2 && + ( + // + long1 + // + || + // + long2 + // + || + // + long3 + // + || + // + long4 + // + || + // + long5 + // + || + // + long6 + // + || + // + long7 + // + || + // + long8 + // + || + // + long9 + // + || + // + long10 + // + || + // + long11 + // + || + // + long12 + // + || + // + long13 + // + || + // + long14 + // + || + // + long15 + // + ) + // + ; + + // + return result; + } + + // + // Check Market Conditions for Short Signals ... + bool HasShortConditions( + X121SetupConditions &conditions, // Conditions + int &pusher // Pushers + ) + { + // + bool result = false; + + // + pusher = 0; + + // + bool isOSCLongVerified = IsOSCLongVerified(conditions); + + // + int zIndex = 0; + int cIndex = zIndex + 1; + int pIndex = cIndex + 1; + + // + double bullishScore = 0; + double bearishScore = 0; + conditions.GenerateScore( + bullishScore, + bearishScore // + ); + + // + bool short1 = + // + // Starting Conditions ... + conditions.matdConditions.isSwitchedToBearish && + // + // Verifications ... + conditions.matdConditions.isSARBearish && + conditions.adxtdConditions.isStrong && + conditions.adxtdConditions.isBearish && + conditions.strConditions.isTrendBearish && + conditions.cheConditions.isStrongBearish && + conditions.tdConditions.isBearish && + conditions.hkConditions.isHKBearish && + conditions.hkConditions.isSMHKBearish && + conditions.mrbConditions.isFastUnderSlow && + conditions.sslcConditions.isBearish && + conditions.hullConditions.isBearish + // + ; + if (short1) + { + pusher++; + } + + // + bool short2 = + // + // Starting Conditions ... + conditions.matdConditions.isSARSwitchedToBearish && + // + // Verifications ... + conditions.matdConditions.isBearish && + conditions.adxtdConditions.isStrong && + conditions.adxtdConditions.isBearish && + conditions.strConditions.isTrendBearish && + conditions.cheConditions.isStrongBearish && + conditions.tdConditions.isBearish && + conditions.hkConditions.isHKBearish && + conditions.hkConditions.isSMHKBearish && + conditions.mrbConditions.isFastUnderSlow && + conditions.sslcConditions.isBearish && + conditions.hullConditions.isBearish + // + ; + if (short2) + { + pusher++; + } + + // + bool short3 = + // + // Starting Conditions ... + conditions.adxtdConditions.isStrongSwitchedToBearish && + // + // Verifications ... + conditions.matdConditions.isBearish && + conditions.strConditions.isTrendBearish && + conditions.cheConditions.isStrongBearish && + conditions.tdConditions.isBearish && + conditions.hkConditions.isHKBearish && + conditions.hkConditions.isSMHKBearish && + conditions.mrbConditions.isFastUnderSlow && + conditions.sslcConditions.isBearish && + conditions.hullConditions.isBearish + // + ; + if (short3) + { + pusher++; + } + + // + bool short4 = + // + // Starting Conditions ... + conditions.strConditions.isTrendSwitchedToBearish && + // + // Verifications ... + conditions.matdConditions.isBearish && + conditions.adxtdConditions.isStrong && + conditions.adxtdConditions.isBearish && + conditions.cheConditions.isStrongBearish && + conditions.tdConditions.isBearish && + conditions.hkConditions.isHKBearish && + conditions.hkConditions.isSMHKBearish && + conditions.mrbConditions.isFastUnderSlow && + conditions.sslcConditions.isBearish && + conditions.hullConditions.isBearish + // + ; + if (short4) + { + pusher++; + } + + // + bool short5 = + // + // Starting Conditions ... + conditions.cheConditions.isStrongSwitchedToBearish && + // + // Verifications ... + conditions.matdConditions.isBearish && + conditions.adxtdConditions.isStrong && + conditions.adxtdConditions.isBearish && + conditions.strConditions.isTrendBearish && + conditions.tdConditions.isBearish && + conditions.hkConditions.isHKBearish && + conditions.hkConditions.isSMHKBearish && + conditions.mrbConditions.isFastUnderSlow && + conditions.sslcConditions.isBearish && + conditions.hullConditions.isBearish + // + ; + if (short5) + { + pusher++; + } + + // + bool short6 = + // + // Starting Conditions ... + conditions.tdConditions.isSwitchedToBearish && + // + // Verifications ... + conditions.matdConditions.isBearish && + conditions.adxtdConditions.isStrong && + conditions.adxtdConditions.isBearish && + conditions.strConditions.isTrendBearish && + conditions.cheConditions.isStrongBearish && + conditions.hkConditions.isHKBearish && + conditions.hkConditions.isSMHKBearish && + conditions.mrbConditions.isFastUnderSlow && + conditions.sslcConditions.isBearish && + conditions.hullConditions.isBearish + // + ; + if (short6) + { + pusher++; + } + + // + bool short7 = + // + // Starting Conditions ... + conditions.rsi[cIndex] < 70 && + conditions.rsi[pIndex] >= 70 && + // + // Verifications ... + conditions.tdConditions.isBearish && + conditions.matdConditions.isBearish && + conditions.adxtdConditions.isStrong && + conditions.adxtdConditions.isBearish && + conditions.strConditions.isTrendBearish && + conditions.cheConditions.isStrongBearish && + conditions.hkConditions.isHKBearish && + conditions.hkConditions.isSMHKBearish && + conditions.mrbConditions.isFastUnderSlow && + conditions.sslcConditions.isBearish && + conditions.hullConditions.isBearish + // + ; + if (short7) + { + pusher++; + } + + // + bool short8 = + // + // Starting Conditions ... + conditions.cci[cIndex] < 100 && + conditions.cci[pIndex] >= 100 && + // + // Verifications ... + conditions.tdConditions.isBearish && + conditions.matdConditions.isBearish && + conditions.adxtdConditions.isStrong && + conditions.adxtdConditions.isBearish && + conditions.strConditions.isTrendBearish && + conditions.cheConditions.isStrongBearish && + conditions.hkConditions.isHKBearish && + conditions.hkConditions.isSMHKBearish && + conditions.mrbConditions.isFastUnderSlow && + conditions.sslcConditions.isBearish && + conditions.hullConditions.isBearish + // + ; + if (short8) + { + pusher++; + } + + // + bool short9 = + // + // Starting Conditions ... + conditions.macd[cIndex] < 0 && + conditions.macd[cIndex] < conditions.macdSignal[cIndex] && + // + // Verifications ... + conditions.tdConditions.isBearish && + conditions.matdConditions.isBearish && + conditions.adxtdConditions.isStrong && + conditions.adxtdConditions.isBearish && + conditions.strConditions.isTrendBearish && + conditions.cheConditions.isStrongBearish && + conditions.hkConditions.isHKBearish && + conditions.hkConditions.isSMHKBearish && + conditions.mrbConditions.isFastUnderSlow && + conditions.sslcConditions.isBearish && + conditions.hullConditions.isBearish + // + ; + if (short9) + { + pusher++; + } + + // + bool short10 = + // + // Starting Conditions ... + conditions.ichConditions.HasShortConditions() && + // + // Verifications ... + conditions.tdConditions.isBearish && + conditions.matdConditions.isBearish && + conditions.adxtdConditions.isStrong && + conditions.adxtdConditions.isBearish && + conditions.strConditions.isTrendBearish && + conditions.cheConditions.isStrongBearish && + conditions.hkConditions.isHKBearish && + conditions.hkConditions.isSMHKBearish && + conditions.mrbConditions.isFastUnderSlow && + conditions.sslcConditions.isBearish && + conditions.hullConditions.isBearish + // + ; + if (short10) + { + pusher++; + } + + // + bool short11 = + // + // Starting Conditions ... + conditions.hkConditions.isHKSwitchedToBearish && + // + // Verifications ... + conditions.tdConditions.isBearish && + conditions.matdConditions.isBearish && + conditions.adxtdConditions.isStrong && + conditions.adxtdConditions.isBearish && + conditions.strConditions.isTrendBearish && + conditions.cheConditions.isStrongBearish && + conditions.hkConditions.isSMHKBearish && + conditions.mrbConditions.isFastUnderSlow && + conditions.sslcConditions.isBearish && + conditions.hullConditions.isBearish + // + ; + if (short11) + { + pusher++; + } + + // + bool short12 = + // + // Starting Conditions ... + conditions.hkConditions.isSMHKSwitchedToBearish && + // + // Verifications ... + conditions.tdConditions.isBearish && + conditions.matdConditions.isBearish && + conditions.adxtdConditions.isStrong && + conditions.adxtdConditions.isBearish && + conditions.strConditions.isTrendBearish && + conditions.cheConditions.isStrongBearish && + conditions.hkConditions.isHKBearish && + conditions.mrbConditions.isFastUnderSlow && + conditions.sslcConditions.isBearish && + conditions.hullConditions.isBearish + // + ; + if (short12) + { + pusher++; + } + + // + bool short13 = + // + // Starting Conditions ... + conditions.mrbConditions.isFastCrossedUnderSlow && + // + // Verifications ... + conditions.tdConditions.isBearish && + conditions.matdConditions.isBearish && + conditions.adxtdConditions.isStrong && + conditions.adxtdConditions.isBearish && + conditions.strConditions.isTrendBearish && + conditions.cheConditions.isStrongBearish && + conditions.hkConditions.isHKBearish && + conditions.hkConditions.isSMHKBearish && + conditions.sslcConditions.isBearish && + conditions.hullConditions.isBearish + + // + ; + if (short13) + { + pusher++; + } + + // + bool short14 = + // + // Starting Conditions ... + conditions.sslcConditions.isSwitchedToBearish && + // + // Verifications ... + conditions.tdConditions.isBearish && + conditions.matdConditions.isBearish && + conditions.adxtdConditions.isStrong && + conditions.adxtdConditions.isBearish && + conditions.strConditions.isTrendBearish && + conditions.cheConditions.isStrongBearish && + conditions.hkConditions.isHKBearish && + conditions.hkConditions.isSMHKBearish && + conditions.mrbConditions.isFastUnderSlow && + conditions.hullConditions.isBearish + + // + ; + if (short14) + { + pusher++; + } + + // + bool short15 = + // + // Starting Conditions ... + conditions.hullConditions.isSwitchedToBearish && + // + // Verifications ... + conditions.tdConditions.isBearish && + conditions.matdConditions.isBearish && + conditions.adxtdConditions.isStrong && + conditions.adxtdConditions.isBearish && + conditions.strConditions.isTrendBearish && + conditions.cheConditions.isStrongBearish && + conditions.hkConditions.isHKBearish && + conditions.hkConditions.isSMHKBearish && + conditions.mrbConditions.isFastUnderSlow && + conditions.sslcConditions.isBearish + + // + ; + if (short15) + { + pusher++; + } + + // + result = + // + pusher >= 1 && + !isOSCLongVerified && + conditions.asctConditions.isShortSignal && + bearishScore > bullishScore * 2 && + ( + // + short1 + // + || + // + short2 + // + || + // + short3 + // + || + // + short4 + // + || + // + short5 + // + || + // + short6 + // + || + // + short7 + // + || + // + short8 + // + || + // + short9 + // + || + // + short10 + // + || + // + short11 + // + || + // + short12 + // + || + // + short13 + // + || + // + short14 + // + || + // + short15 + // + ) + // + ; + + // + return result; + } + + // + // Check Conditions for Generating Possible Signals ... + bool HasSignal( + X121SetupConditions &conditions, // Conditions + XSignal &signal, // Signal if Exists + int &pusher, // Pushers + bool _allowLong, // Allow Long Signals + bool _allowShort, // Allow Short Signals + double _volume = 0.01, // Volume + double _slPoint = 0, // SL Point + double _tpPoint = 30 // TP Point + ) + { + // + bool result = false; + + // + signal.Clean(); + + // + result = _allowLong || _allowShort; + if (!result) + { + return result; + } + + // + bool hasLong = + !_allowLong + ? false + : HasLongConditions( + conditions, + pusher // + ); + + // + bool hasShort = + !_allowShort + ? false + : HasShortConditions( + conditions, + pusher // + ); + + // + result = hasLong || hasShort; + if (!result) + { + return result; + } + + // + // 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, + GetTag() + ToString(pusher), + conditions.period, + mType, + X_ORDER_MODE_MARKET, + mEntry, + _volume, + 0, // mSL, + mTP // + ); + if (!result) + { + return result; + } + + // + return result; + } + + // + string GetTag() + { + return "X121"; + } +}; + +// +// Class ... +class XSCX121Setup : public XSCBaseAlert +{ + // + // Public ... +public: + // + // Props ... + XSCXTDHelper *tdHelper; + XSCXHKHelper *hkHelper; + XSCXCHEHelper *cheHelper; + XSCXICHHelper *ichHelper; + XSCXSTRHelper *strHelper; + XSCXMRBHelper *mrbHelper; + XSCXOSCHelper *oscHelper; + XSCXMATDHelper *matdHelper; + XSCXASCTHelper *asctHelper; + XSCXSSLCHelper *sslcHelper; + XSCXHULLHelper *hullHelper; + XSCXADXTDHelper *adxtdHelper; + + // + // Constructor(s) ... + void XSCX121Setup() {} + + // + // Deconstructor ... + void ~XSCX121Setup() + { + // + delete tdHelper; + delete hkHelper; + delete cheHelper; + delete ichHelper; + delete strHelper; + delete mrbHelper; + delete oscHelper; + delete matdHelper; + delete asctHelper; + delete sslcHelper; + delete hullHelper; + delete adxtdHelper; + } + + // + // Getter(s) / Setter(s) ... + + // + string GetSymbol() + { + return inputs.symbol; + } + + // + ENUM_TIMEFRAMES GetPeriod() + { + return inputs.period; + } + + // + // Tools ... + + // + bool Init( + X121SetupInputs &_inputs // Configurations + ) + { + // + bool result = false; + + // + result = _inputs.IsValid(); + if (!result) + { + return result; + } + + // + inputs = _inputs; + + // + // Initialize Helpers ... + + // + // XTD ... + tdHelper = new XSCXTDHelper(); + result = tdHelper.Init( + inputs.symbol, + inputs.period, + inputs.tdInputs // + ); + if (!result) + { + return result; + } + + // + // XHK ... + hkHelper = new XSCXHKHelper(); + result = hkHelper.Init( + inputs.symbol, + inputs.period, + inputs.hkInputs // + ); + if (!result) + { + return result; + } + + // + // XCHE ... + cheHelper = new XSCXCHEHelper(); + result = cheHelper.Init( + inputs.symbol, + inputs.period, + inputs.cheInputs // + ); + if (!result) + { + return result; + } + + // + // XICH ... + ichHelper = new XSCXICHHelper(); + result = ichHelper.Init( + inputs.symbol, + inputs.period, + inputs.ichInputs // + ); + if (!result) + { + return result; + } + + // + // XSTR ... + strHelper = new XSCXSTRHelper(); + result = strHelper.Init( + inputs.symbol, + inputs.period, + inputs.strInputs // + ); + if (!result) + { + return result; + } + + // + // XMRB ... + mrbHelper = new XSCXMRBHelper(); + result = mrbHelper.Init( + inputs.symbol, + inputs.period, + inputs.mrbInputs // + ); + if (!result) + { + return result; + } + + // + // XOSC ... + oscHelper = new XSCXOSCHelper(); + result = oscHelper.Init( + inputs.symbol, + inputs.period, + inputs.oscInputs // + ); + if (!result) + { + return result; + } + + // + // XMATD ... + matdHelper = new XSCXMATDHelper( + inputs.symbol, + inputs.period // + ); + result = matdHelper.Init( + inputs.matdInputs // + ); + if (!result) + { + return result; + } + + // + // XASCT ... + asctHelper = new XSCXASCTHelper(); + result = asctHelper.Init( + inputs.symbol, + inputs.period, + inputs.asctInputs // + ); + if (!result) + { + return result; + } + + // + // XSSLC ... + sslcHelper = new XSCXSSLCHelper(); + result = sslcHelper.Init( + inputs.symbol, + inputs.period, + inputs.sslcInputs // + ); + if (!result) + { + return result; + } + + // + // XHULL ... + hullHelper = new XSCXHULLHelper(); + result = hullHelper.Init( + inputs.symbol, + inputs.period, + inputs.hullInputs // + ); + if (!result) + { + return result; + } + + // + // XADXTD ... + adxtdHelper = new XSCXADXTDHelper( + inputs.symbol, + inputs.period // + ); + result = adxtdHelper.Init( + inputs.adxtdInputs // + ); + if (!result) + { + return result; + } + + // + return result; + } + + // + X121SetupInputs GetInputs() + { + return inputs; + } + + // + bool SetInputs( + X121SetupInputs &_inputs // Configurations + ) + { + return Init(_inputs); + } + + // + bool GetConditions( + X121SetupConditions &conditions, // + int barIndex = 0, // + int loopback = 5 // + ) + { + // + bool result = true; + + // + conditions.Clean(); + + // + conditions.symbol = GetSymbol(); + conditions.period = GetPeriod(); + conditions.time = TimeCurrent(); + + // + result = tdHelper.GetConditions( + conditions.tdConditions, + barIndex, + loopback // + ); + if (!result) + { + return result; + } + + // + result = hkHelper.GetConditions( + conditions.hkConditions, + barIndex, + loopback // + ); + if (!result) + { + return result; + } + + // + result = cheHelper.GetConditions( + conditions.cheConditions, + barIndex, + loopback // + ); + if (!result) + { + return result; + } + + // + result = ichHelper.GetConditions( + conditions.ichConditions, + barIndex, + loopback // + ); + if (!result) + { + return result; + } + + // + result = strHelper.GetConditions( + conditions.strConditions, + barIndex, + loopback // + ); + if (!result) + { + return result; + } + + // + result = mrbHelper.GetConditions( + conditions.mrbConditions, + barIndex, + loopback // + ); + if (!result) + { + return result; + } + + // + result = matdHelper.GetConditions( + conditions.matdConditions, + barIndex, + loopback // + ); + if (!result) + { + return result; + } + + // + result = asctHelper.GetConditions( + conditions.asctConditions, + barIndex, + loopback // + ); + if (!result) + { + return result; + } + + // + result = sslcHelper.GetConditions( + conditions.sslcConditions, + barIndex, + loopback // + ); + if (!result) + { + return result; + } + + // + result = hullHelper.GetConditions( + conditions.hullConditions, + barIndex, + loopback // + ); + if (!result) + { + return result; + } + + // + result = adxtdHelper.GetConditions( + conditions.adxtdConditions, + barIndex, + loopback // + ); + if (!result) + { + return result; + } + + // + oscHelper.CopyCCI( + barIndex, + loopback, + conditions.cci // + ); + oscHelper.CopyRSI( + barIndex, + loopback, + conditions.rsi // + ); + oscHelper.CopyMACD( + barIndex, + loopback, + conditions.macd // + ); + oscHelper.CopyMACDSignal( + barIndex, + loopback, + conditions.macdSignal // + ); + + // + return result; + } + + // + // Protected ... +protected: + // + // Private ... +private: + // + // Props ... + X121SetupInputs inputs; // Setup Configurations ... +}; diff --git a/Classes/x-saherelm.xind.class.mq5 b/Classes/x-saherelm.xind.class.mq5 index 6927335a..4ac14119 100644 --- a/Classes/x-saherelm.xind.class.mq5 +++ b/Classes/x-saherelm.xind.class.mq5 @@ -249,6 +249,243 @@ struct XBuffer } }; +// +class XSCBaseBufferClass : public XSCBaseAlert +{ + // + // Public ... +public: + // + // Virtual ... + + // + // Validate ... + virtual bool IsValid() + { + return false; + } + + // + // Calculations ... + virtual void Calculate() {} + + // + // Protected ... +protected: + // + // Props ... + + // + // Indicators Buffers ... + XBuffer mBuffers[]; + + // + // Buffer Management ... + + // + // Count Registered Buffers ... + int CountBuffers() + { + return ArraySize(mBuffers); + } + + // + // Retrieve Specified Buffer Index ... + int GetBufferIndex( + string title // Specified Buffer Title + ) + { + // + int result = -1; + + // + if (!IsSpecifiedValid(title)) + { + return result; + } + + // + int buffersCount = CountBuffers(); + if (!IsValidSize(buffersCount)) + { + return result; + } + + // + for (int i = 0; i < buffersCount; i++) + { + // + XBuffer iBuffer = mBuffers[i]; + + // + bool isOwn = iBuffer.IsOwn(title); + if (isOwn) + { + // + result = i; + break; + } + } + + // + return result; + } + + // + // Check Contains Specific Buffer or not ... + bool HasBuffer( + string title // Specified Buffer Title + ) + { + // + bool result = false; + + // + int bufferIndex = GetBufferIndex(title); + result = bufferIndex >= 0; + + // + return result; + } + + // + // Retrieve Specified Buffer ... + bool GetBuffer( + string title, // Specified Buffer Title + XBuffer &buffer // Hold Result + ) + { + // + bool result = false; + + // + int idx = GetBufferIndex(title); + result = idx >= 0; + if (!result) + { + return result; + } + + // + buffer = mBuffers[idx]; + + // + result = buffer.IsValid(); + + // + return result; + } + + // + // Register Specified Buffer ... + bool SetBuffer( + XBuffer &buffer // Specified Buffer for Registration + ) + { + // + bool result = false; + + // + // Validate buffer ... + result = buffer.IsValid(); + if (!result) + { + return result; + } + + // + // Check Buffer Doesn't Exists before ... + int idx = GetBufferIndex(buffer.title); + result = idx == -1; + if (!result) + { + return result; + } + + // + AddRef( + buffer, + mBuffers // + ); + + // + return result; + } + + // + double GetBufferValue( + string mTitle, // Required Buffer Title + int index // Bar Index + ) + { + // + double result = EMPTY_VALUE; + + // + // Validate State ... + if (!IsValid()) + { + return result; + } + + // + int bufferIDX = GetBufferIndex(mTitle); + if (bufferIDX < 0) + { + return result; + } + + // + Calculate(); + + // + result = mBuffers[bufferIDX].Get(index); + + // + return result; + } + + // + int CopyBufferValue( + string mTitle, + double &buffer[], + int start, + int count // + ) + { + // + int result = 0; + + // + if (!IsValid()) + { + return result; + } + + // + int sourceIDX = GetBufferIndex(mTitle); + if (sourceIDX < 0) + { + return result; + } + + // + Calculate(); + + // + result = ArrayCopy( + buffer, + mBuffers[sourceIDX].values, + start, + start, + count // + ); + + // + return result; + } +}; + // // Base Indicator Class ... class XSCBaseInd : public XSCBaseAlert @@ -650,3 +887,5 @@ private: // // Props ... }; + +// \ No newline at end of file diff --git a/Documents/BKP/Source Codes/cIADX.mq5 b/Documents/BKP/Source Codes/cIADX.mq5 new file mode 100644 index 00000000..a3248acc --- /dev/null +++ b/Documents/BKP/Source Codes/cIADX.mq5 @@ -0,0 +1,136 @@ +//+------------------------------------------------------------------+ +//| Trend.mqh | +//| Copyright 2000-2024, MetaQuotes Ltd. | +//| https://www.mql5.com | +//+------------------------------------------------------------------+ +#include "Indicator.mqh" +//+------------------------------------------------------------------+ +//| Class CiADX. | +//| Purpose: Class of the "Average Directional Index" indicator. | +//| Derives from class CIndicator. | +//+------------------------------------------------------------------+ +class CiADX : public CIndicator +{ +protected: + int m_ma_period; + +public: + CiADX(void); + ~CiADX(void); + //--- methods of access to protected data + int MaPeriod(void) const { return (m_ma_period); } + //--- method of creation + bool Create(const string symbol, const ENUM_TIMEFRAMES period, const int ma_period); + //--- methods of access to indicator data + double Main(const int index) const; + double Plus(const int index) const; + double Minus(const int index) const; + //--- method of identifying + virtual int Type(void) const { return (IND_ADX); } + +protected: + //--- methods of tuning + virtual bool Initialize(const string symbol, const ENUM_TIMEFRAMES period, const int num_params, const MqlParam ¶ms[]); + bool Initialize(const string symbol, const ENUM_TIMEFRAMES period, const int ma_period); +}; +//+------------------------------------------------------------------+ +//| Constructor | +//+------------------------------------------------------------------+ +CiADX::CiADX(void) : m_ma_period(-1) +{ +} +//+------------------------------------------------------------------+ +//| Destructor | +//+------------------------------------------------------------------+ +CiADX::~CiADX(void) +{ +} +//+------------------------------------------------------------------+ +//| Create the "Average Directional Index" indicator | +//+------------------------------------------------------------------+ +bool CiADX::Create(const string symbol, const ENUM_TIMEFRAMES period, const int ma_period) +{ + //--- check history + if (!SetSymbolPeriod(symbol, period)) + return (false); + //--- create + m_handle = iADX(symbol, period, ma_period); + //--- check result + if (m_handle == INVALID_HANDLE) + return (false); + //--- indicator successfully created + if (!Initialize(symbol, period, ma_period)) + { + //--- initialization failed + IndicatorRelease(m_handle); + m_handle = INVALID_HANDLE; + return (false); + } + //--- ok + return (true); +} +//+------------------------------------------------------------------+ +//| Initialize the indicator with universal parameters | +//+------------------------------------------------------------------+ +bool CiADX::Initialize(const string symbol, const ENUM_TIMEFRAMES period, const int num_params, const MqlParam ¶ms[]) +{ + return (Initialize(symbol, period, (int)params[0].integer_value)); +} +//+------------------------------------------------------------------+ +//| Initialize indicator with the special parameters | +//+------------------------------------------------------------------+ +bool CiADX::Initialize(const string symbol, const ENUM_TIMEFRAMES period, const int ma_period) +{ + if (CreateBuffers(symbol, period, 3)) + { + //--- string of status of drawing + m_name = "ADX"; + m_status = "(" + symbol + "," + PeriodDescription() + "," + IntegerToString(ma_period) + ") H=" + IntegerToString(m_handle); + //--- save settings + m_ma_period = ma_period; + //--- create buffers + ((CIndicatorBuffer *)At(0)).Name("MAIN_LINE"); + ((CIndicatorBuffer *)At(1)).Name("PLUS_LINE"); + ((CIndicatorBuffer *)At(2)).Name("MINUS_LINE"); + //--- ok + return (true); + } + //--- error + return (false); +} +//+------------------------------------------------------------------+ +//| Access to Main buffer of "Average Directional Index" | +//+------------------------------------------------------------------+ +double CiADX::Main(const int index) const +{ + CIndicatorBuffer *buffer = At(0); + //--- check + if (buffer == NULL) + return (EMPTY_VALUE); + //--- + return (buffer.At(index)); +} +//+------------------------------------------------------------------+ +//| Access to Plus buffer of "Average Directional Index" | +//+------------------------------------------------------------------+ +double CiADX::Plus(const int index) const +{ + CIndicatorBuffer *buffer = At(1); + //--- check + if (buffer == NULL) + return (EMPTY_VALUE); + //--- + return (buffer.At(index)); +} +//+------------------------------------------------------------------+ +//| Access to Minus buffer of "Average Directional Index" | +//+------------------------------------------------------------------+ +double CiADX::Minus(const int index) const +{ + CIndicatorBuffer *buffer = At(2); + //--- check + if (buffer == NULL) + return (EMPTY_VALUE); + //--- + return (buffer.At(index)); +} diff --git a/Experts/x-test-xxx.mq5 b/Experts/x-test-xxx.mq5 new file mode 100644 index 00000000..d85abde0 --- /dev/null +++ b/Experts/x-test-xxx.mq5 @@ -0,0 +1,1739 @@ +/////////////////////////////////////////////////////// +// +// SaherElm IT Center XTESTXXX MQL5 Expert Advisor +// ------------------------------------------------- +// Name: XTESTXXX +// Description: an Exper Advisor which used RSI and MA +// to Analyse Market ... +// +// Maintainer: +// ------------ +// Hadi Khazaee Asl (hadi_khazaee_asl@yahoo.com) +// +//////////////////////////////////////////////////////x +// +// Global Properties ... +#property copyright "Copyright 2023, SaherElm IT Center" +#property link "https://saherelm.ir" +#property version "1.00" +#property description "SaherElm XTESTXXX" +#property strict + +// +// Imports ... +#include "../Libraries/x-saherelm.draw.lib.mq5" +#include "../Classes/x-saherelm.xalert.class.mq5" +#include "../Classes/x-saherelm.xtrade.class.mq5" +#include "../Libraries/x-saherelm.common.lib.mq5" +#include "../Classes/x-saherelm.x121.setup.class.mq5" + +// +// #include "../Helpers/x-saherelm.xtd.helper.mq5" +// #include "../Helpers/x-saherelm.xhk.helper.mq5" +// #include "../Helpers/x-saherelm.xstr.helper.mq5" +// #include "../Helpers/x-saherelm.xche.helper.mq5" +// #include "../Helpers/x-saherelm.xich.helper.mq5" +// #include "../Helpers/x-saherelm.xmrb.helper.mq5" +// #include "../Helpers/x-saherelm.xosc.helper.mq5" +// #include "../Helpers/x-saherelm.xasct.helper.mq5" +// #include "../Helpers/x-saherelm.xsslc.helper.mq5" +// #include "../Helpers/x-saherelm.xhull.helper.mq5" +// #include "../Helpers/x-saherelm.xmatd.helper.mq5" +// #include "../Helpers/x-saherelm.xadxtd.helper.mq5" + +// +#define ShortName "XTESTXXX" + +// +// Inputs ... + +// +long eaMagicNumber = 78692110; // Magic Number +int eaSlippage = 10; // Slippgae + +// +string eaSymbols = "EURUSDb"; // Symbols + +// +bool eaAllowLong = true; // Allow Long Trades +bool eaAllowShort = true; // Allow Short Trades +double eaVolume = 0.05; // Static Volume +int eaReuiredVerifications = 1; // Required Verifications for Signals + +// +// Definitions ... + +// +// Local Variables ... + +// +XSCAlert *mAlert; +XSCTrade *mTrader; + +// +XSCX121Setup *mSetup; +X121SignalGenerator mSignalGenerator; + +// // +// // Helpers ... +// XSCXTDHelper *tdHelper; +// XSCXHKHelper *hkHelper; +// XSCXCHEHelper *cheHelper; +// XSCXICHHelper *ichHelper; +// XSCXSTRHelper *strHelper; +// XSCXMRBHelper *mrbHelper; +// XSCXOSCHelper *oscHelper; +// XSCXMATDHelper *matdHelper; +// XSCXASCTHelper *asctHelper; +// XSCXSSLCHelper *sslcHelper; +// XSCXHULLHelper *hullHelper; +// XSCXADXTDHelper *adxtdHelper; + +// // +// int rsiHandler = INVALID_HANDLE; +// int cciHandler = INVALID_HANDLE; +// int macdHandler = INVALID_HANDLE; + +// +XBarTracker xBarTracker; + +// +// Event Handlers ... + +// +// Initialization ... +int OnInit() +{ + // + drawPrefix = ShortName; + + // + if (!InitialEA()) + { + return INIT_PARAMETERS_INCORRECT; + } + + // + // Init Succeed ... + return INIT_SUCCEEDED; +} + +// +// DeInitialization ... +void OnDeinit(const int reason) +{ + // + // REASON_PROGRAM 0 The EA has stopped working calling the ExpertRemove() function + // REASON_REMOVE 1 Program removed from a chart + // REASON_RECOMPILE 2 Program recompiled + // REASON_CHARTCHANGE 3 A symbol or a chart period is changed + // REASON_CHARTCLOSE 4 Chart closed + // REASON_PARAMETERS 5 Inputs changed by a user + // REASON_ACCOUNT 6 Another account has been activated or reconnection to the trade server has occurred due to changes in the account settings + // REASON_TEMPLATE 7 Another chart template applied + // REASON_INITFAILED 8 The OnInit() handler returned a non-zero value + // REASON_CLOSE 9 Terminal closed + + // + // De Initialize XSampleEA Providers ... + + // // + // delete tdHelper; + // delete hkHelper; + // delete cheHelper; + // delete strHelper; + // delete ichHelper; + // delete mrbHelper; + // delete oscHelper; + // delete matdHelper; + // delete asctHelper; + // delete sslcHelper; + // delete hullHelper; + // delete adxtdHelper; + + // + delete mSetup; + + // + delete mAlert; + delete mTrader; +} + +// +// On Tick Handler ... +void OnTick() +{ + // + if (!xBarTracker.CanProcessBar()) + { + return; + } + + // // + // double bullishScore = 0; + // double bearishScore = 0; + + // // + // double tempBullishScore = 0; + // double tempBearishScore = 0; + + // // + // XMATDConditions matdConditions; + // matdHelper.GetConditions(matdConditions); + // string matdSummary = matdConditions.GenerateSummary(false, true, false); + // matdConditions.GenerateScore( + // tempBullishScore, + // tempBearishScore // + // ); + // bullishScore += tempBullishScore; + // bearishScore += tempBearishScore; + + // // + // XADXTDConditions adxtdConditions; + // adxtdHelper.GetConditions(adxtdConditions); + // string adxtdSummary = adxtdConditions.GenerateSummary(false, true, false); + // adxtdConditions.GenerateScore( + // tempBullishScore, + // tempBearishScore // + // ); + // bullishScore += tempBullishScore; + // bearishScore += tempBearishScore; + + // // + // XSTRConditions strConditions; + // strHelper.GetConditions(strConditions); + // string strSummary = strConditions.GenerateSummary(false, true, false); + // strConditions.GenerateScore( + // tempBullishScore, + // tempBearishScore // + // ); + // bullishScore += tempBullishScore; + // bearishScore += tempBearishScore; + + // // + // XCHEConditions cheConditions; + // cheHelper.GetConditions(cheConditions); + // string cheSummary = cheConditions.GenerateSummary(false, true, false); + // cheConditions.GenerateScore( + // tempBullishScore, + // tempBearishScore // + // ); + // bullishScore += tempBullishScore; + // bearishScore += tempBearishScore; + + // // + // XASCTConditions asctConditions; + // asctHelper.GetConditions(asctConditions); + // string asctSummary = asctConditions.GenerateSummary(false, true, false); + // asctConditions.GenerateScore( + // tempBullishScore, + // tempBearishScore // + // ); + // bullishScore += tempBullishScore; + // bearishScore += tempBearishScore; + + // // + // XTDConditions tdConditions; + // tdHelper.GetConditions(tdConditions); + // string tdSummary = tdConditions.GenerateSummary(false, true, false); + // tdConditions.GenerateScore( + // tempBullishScore, + // tempBearishScore // + // ); + // bullishScore += tempBullishScore; + // bearishScore += tempBearishScore; + + // // + // XICHConditions ichConditions; + // ichHelper.GetConditions(ichConditions); + // string ichSummary = ichConditions.GenerateSummary(false, true, false); + // ichConditions.GenerateScore( + // tempBullishScore, + // tempBearishScore // + // ); + // bullishScore += tempBullishScore; + // bearishScore += tempBearishScore; + + // // + // XHKConditions hkConditions; + // hkHelper.GetConditions(hkConditions); + // string hkSummary = hkConditions.GenerateSummary(false, true, false); + // hkConditions.GenerateScore( + // tempBullishScore, + // tempBearishScore // + // ); + // bullishScore += tempBullishScore; + // bearishScore += tempBearishScore; + + // // + // XMRBConditions mrbConditions; + // mrbHelper.GetConditions(mrbConditions); + // string mrbSummary = mrbConditions.GenerateSummary(false, true, false); + // mrbConditions.GenerateScore( + // tempBullishScore, + // tempBearishScore // + // ); + // bullishScore += tempBullishScore; + // bearishScore += tempBearishScore; + + // // + // XSSLCConditions sslcConditions; + // sslcHelper.GetConditions(sslcConditions); + // string sslcSummary = sslcConditions.GenerateSummary(false, true, false); + // sslcConditions.GenerateScore( + // tempBullishScore, + // tempBearishScore // + // ); + // bullishScore += tempBullishScore; + // bearishScore += tempBearishScore; + + // // + // XHULLConditions hullConditions; + // hullHelper.GetConditions(hullConditions); + // string hullSummary = hullConditions.GenerateSummary(false, true, false); + // hullConditions.GenerateScore( + // tempBullishScore, + // tempBearishScore // + // ); + // bullishScore += tempBullishScore; + // bearishScore += tempBearishScore; + + // // + // // OSCS Verifications ... + // int zIndex = 0; + // int cIndex = zIndex + 1; + // int pIndex = cIndex + 1; + + // // + // int loopback = 3; + + // // + // double ccis[]; + // ArraySetAsSeries(ccis, true); + // oscHelper.CopyCCI( + // zIndex, + // loopback, + // ccis // + // ); + + // // + // double rsis[]; + // ArraySetAsSeries(rsis, true); + // oscHelper.CopyRSI( + // zIndex, + // loopback, + // rsis // + // ); + + // // + // double macdMains[]; + // double macdSignals[]; + // ArraySetAsSeries(macdMains, true); + // ArraySetAsSeries(macdSignals, true); + // oscHelper.CopyMACD( + // zIndex, + // loopback, + // macdMains // + // ); + // oscHelper.CopyMACDSignal( + // zIndex, + // loopback, + // macdSignals // + // ); + + // // + // bool oscLongVerifications = + // // + // // CCI ... + // ccis[cIndex] < 96 && + // ccis[cIndex] > ccis[pIndex] + // // + // && + // // + // // RSI ... + // rsis[cIndex] < 70 && + // rsis[cIndex] > rsis[pIndex] + // // + // && + // // + // // MACD ... + // macdMains[cIndex] > 0 && + // macdSignals[cIndex] > 0 && + // macdMains[cIndex] > macdSignals[cIndex] + // // + // ; + + // // + // bool oscShortVerifications = + // // + // // CCI ... + // ccis[cIndex] > -96 && + // ccis[cIndex] < ccis[pIndex] + // // + // && + // // + // // RSI ... + // rsis[cIndex] > 30 && + // rsis[cIndex] < rsis[pIndex] + // // + // && + // // + // // MACD ... + // macdMains[cIndex] < 0 && + // macdSignals[cIndex] < 0 && + // macdMains[cIndex] < macdSignals[cIndex] + // // + // ; + + // // + // string separator = "\n"; + // string summary = + // // + // matdSummary + separator + + // adxtdSummary + separator + + // strSummary + separator + + // cheSummary + separator + + // asctSummary + separator + + // tdSummary + separator + + // ichSummary + separator + + // hkSummary + separator + + // mrbSummary + separator + + // sslcSummary + separator + + // hullSummary + separator + + // "" + // // + // ; + + // // + // string scoreSummary = + // // + // "Scores:" + separator + + // "----------" + separator + + // "Bullish: " + ToString(bullishScore) + separator + + // "Bearish: " + ToString(bearishScore) + separator + + // // "---------" + separator + + // // "OSC Long: " + ToString(oscLongVerifications) + separator + + // // "OSC Short: " + ToString(oscShortVerifications) + separator + + // "" + // // + // ; + + // // + // Comment(scoreSummary); + + // // + // int longPusher = 0; + // int shortPusher = 0; + + // // + // // LONG ... + // bool hasLong = false; + // if (eaAllowLong) + // { + // // + // bool long1 = + // // + // // Starting Conditions ... + // matdConditions.isSwitchedToBullish && + // // + // // Verifications ... + // matdConditions.isSARBullish && + // adxtdConditions.isStrong && + // adxtdConditions.isBullish && + // strConditions.isTrendBullish && + // cheConditions.isStrongBullish && + // tdConditions.isBullish && + // hkConditions.isHKBullish && + // hkConditions.isSMHKBullish && + // mrbConditions.isFastOverSlow && + // sslcConditions.isBullish && + // hullConditions.isBullish + // // + // ; + // if (long1) + // { + // longPusher++; + // } + + // // + // bool long2 = + // // + // // Starting Conditions ... + // matdConditions.isSARSwitchedToBullish && + // // + // // Verifications ... + // matdConditions.isBullish && + // adxtdConditions.isStrong && + // adxtdConditions.isBullish && + // strConditions.isTrendBullish && + // cheConditions.isStrongBullish && + // tdConditions.isBullish && + // hkConditions.isHKBullish && + // hkConditions.isSMHKBullish && + // mrbConditions.isFastOverSlow && + // sslcConditions.isBullish && + // hullConditions.isBullish + // // + // ; + // if (long2) + // { + // longPusher++; + // } + + // // + // bool long3 = + // // + // // Starting Conditions ... + // adxtdConditions.isStrongSwitchedToBullish && + // // + // // Verifications ... + // matdConditions.isBullish && + // strConditions.isTrendBullish && + // cheConditions.isStrongBullish && + // tdConditions.isBullish && + // hkConditions.isHKBullish && + // hkConditions.isSMHKBullish && + // mrbConditions.isFastOverSlow && + // sslcConditions.isBullish && + // hullConditions.isBullish + // // + // ; + // if (long3) + // { + // longPusher++; + // } + + // // + // bool long4 = + // // + // // Starting Conditions ... + // strConditions.isTrendSwitchedToBullish && + // // + // // Verifications ... + // matdConditions.isBullish && + // adxtdConditions.isStrong && + // adxtdConditions.isBullish && + // cheConditions.isStrongBullish && + // tdConditions.isBullish && + // hkConditions.isHKBullish && + // hkConditions.isSMHKBullish && + // mrbConditions.isFastOverSlow && + // sslcConditions.isBullish && + // hullConditions.isBullish + // // + // ; + // if (long4) + // { + // longPusher++; + // } + + // // + // bool long5 = + // // + // // Starting Conditions ... + // cheConditions.isStrongSwitchedToBullish && + // // + // // Verifications ... + // matdConditions.isBullish && + // adxtdConditions.isStrong && + // adxtdConditions.isBullish && + // strConditions.isTrendBullish && + // tdConditions.isBullish && + // hkConditions.isHKBullish && + // hkConditions.isSMHKBullish && + // mrbConditions.isFastOverSlow && + // sslcConditions.isBullish && + // hullConditions.isBullish + // // + // ; + // if (long5) + // { + // longPusher++; + // } + + // // + // bool long6 = + // // + // // Starting Conditions ... + // tdConditions.isSwitchedToBullish && + // // + // // Verifications ... + // matdConditions.isBullish && + // adxtdConditions.isStrong && + // adxtdConditions.isBullish && + // strConditions.isTrendBullish && + // cheConditions.isStrongBullish && + // hkConditions.isHKBullish && + // hkConditions.isSMHKBullish && + // mrbConditions.isFastOverSlow && + // sslcConditions.isBullish && + // hullConditions.isBullish + // // + // ; + // if (long6) + // { + // longPusher++; + // } + + // // + // bool long7 = + // // + // // Starting Conditions ... + // rsis[cIndex] > 30 && + // rsis[pIndex] <= 30 && + // // + // // Verifications ... + // tdConditions.isBullish && + // matdConditions.isBullish && + // adxtdConditions.isStrong && + // adxtdConditions.isBullish && + // strConditions.isTrendBullish && + // cheConditions.isStrongBullish && + // hkConditions.isHKBullish && + // hkConditions.isSMHKBullish && + // mrbConditions.isFastOverSlow && + // sslcConditions.isBullish && + // hullConditions.isBullish + // // + // ; + // if (long7) + // { + // longPusher++; + // } + + // // + // bool long8 = + // // + // // Starting Conditions ... + // ccis[cIndex] > -100 && + // ccis[pIndex] <= -100 && + // // + // // Verifications ... + // tdConditions.isBullish && + // matdConditions.isBullish && + // adxtdConditions.isStrong && + // adxtdConditions.isBullish && + // strConditions.isTrendBullish && + // cheConditions.isStrongBullish && + // hkConditions.isHKBullish && + // hkConditions.isSMHKBullish && + // mrbConditions.isFastOverSlow && + // sslcConditions.isBullish && + // hullConditions.isBullish + // // + // ; + // if (long8) + // { + // longPusher++; + // } + + // // + // bool long9 = + // // + // // Starting Conditions ... + // macdMains[cIndex] > 0 && + // macdMains[cIndex] > macdSignals[cIndex] && + // // + // // Verifications ... + // tdConditions.isBullish && + // matdConditions.isBullish && + // adxtdConditions.isStrong && + // adxtdConditions.isBullish && + // strConditions.isTrendBullish && + // cheConditions.isStrongBullish && + // hkConditions.isHKBullish && + // hkConditions.isSMHKBullish && + // mrbConditions.isFastOverSlow && + // sslcConditions.isBullish && + // hullConditions.isBullish + // // + // ; + // if (long9) + // { + // longPusher++; + // } + + // // + // bool long10 = + // // + // // Starting Conditions ... + // ichConditions.HasLongConditions() && + // // + // // Verifications ... + // tdConditions.isBullish && + // matdConditions.isBullish && + // adxtdConditions.isStrong && + // adxtdConditions.isBullish && + // strConditions.isTrendBullish && + // cheConditions.isStrongBullish && + // hkConditions.isHKBullish && + // hkConditions.isSMHKBullish && + // mrbConditions.isFastOverSlow && + // sslcConditions.isBullish && + // hullConditions.isBullish + // // + // ; + // if (long10) + // { + // longPusher++; + // } + + // // + // bool long11 = + // // + // // Starting Conditions ... + // hkConditions.isHKSwitchedToBullish && + // // + // // Verifications ... + // tdConditions.isBullish && + // matdConditions.isBullish && + // adxtdConditions.isStrong && + // adxtdConditions.isBullish && + // strConditions.isTrendBullish && + // cheConditions.isStrongBullish && + // hkConditions.isSMHKBullish && + // mrbConditions.isFastOverSlow && + // sslcConditions.isBullish && + // hullConditions.isBullish + // // + // ; + // if (long11) + // { + // longPusher++; + // } + + // // + // bool long12 = + // // + // // Starting Conditions ... + // hkConditions.isSMHKSwitchedToBullish && + // // + // // Verifications ... + // tdConditions.isBullish && + // matdConditions.isBullish && + // adxtdConditions.isStrong && + // adxtdConditions.isBullish && + // strConditions.isTrendBullish && + // cheConditions.isStrongBullish && + // hkConditions.isHKBullish && + // mrbConditions.isFastOverSlow && + // sslcConditions.isBullish && + // hullConditions.isBullish + // // + // ; + // if (long12) + // { + // longPusher++; + // } + + // // + // bool long13 = + // // + // // Starting Conditions ... + // mrbConditions.isFastCrossedOverSlow && + // // + // // Verifications ... + // tdConditions.isBullish && + // matdConditions.isBullish && + // adxtdConditions.isStrong && + // adxtdConditions.isBullish && + // strConditions.isTrendBullish && + // cheConditions.isStrongBullish && + // hkConditions.isHKBullish && + // hkConditions.isSMHKBullish && + // sslcConditions.isBullish && + // hullConditions.isBullish + // // + // ; + // if (long13) + // { + // longPusher++; + // } + + // // + // bool long14 = + // // + // // Starting Conditions ... + // sslcConditions.isSwitchedToBullish && + // // + // // Verifications ... + // tdConditions.isBullish && + // matdConditions.isBullish && + // adxtdConditions.isStrong && + // adxtdConditions.isBullish && + // strConditions.isTrendBullish && + // cheConditions.isStrongBullish && + // hkConditions.isHKBullish && + // hkConditions.isSMHKBullish && + // mrbConditions.isFastOverSlow && + // hullConditions.isBullish + // // + // ; + // if (long14) + // { + // longPusher++; + // } + + // // + // bool long15 = + // // + // // Starting Conditions ... + // hullConditions.isSwitchedToBullish && + // // + // // Verifications ... + // tdConditions.isBullish && + // matdConditions.isBullish && + // adxtdConditions.isStrong && + // adxtdConditions.isBullish && + // strConditions.isTrendBullish && + // cheConditions.isStrongBullish && + // hkConditions.isHKBullish && + // hkConditions.isSMHKBullish && + // mrbConditions.isFastOverSlow && + // sslcConditions.isBullish + // // + // ; + // if (long15) + // { + // longPusher++; + // } + + // // + // hasLong = + // // + // longPusher >= 1 && + // !oscShortVerifications && + // asctConditions.isLongSignal && + // bullishScore > bearishScore * 2 && + // ( + // // + // long1 + // // + // || + // // + // long2 + // // + // || + // // + // long3 + // // + // || + // // + // long4 + // // + // || + // // + // long5 + // // + // || + // // + // long6 + // // + // || + // // + // long7 + // // + // || + // // + // long8 + // // + // || + // // + // long9 + // // + // || + // // + // long10 + // // + // || + // // + // long11 + // // + // || + // // + // long12 + // // + // || + // // + // long13 + // // + // || + // // + // long14 + // // + // || + // // + // long15 + // // + // ) + // // + // ; + // } + + // // + // // SHORT ... + // bool hasShort = false; + // if (eaAllowShort) + // { + // // + // bool short1 = + // // + // // Starting Conditions ... + // matdConditions.isSwitchedToBearish && + // // + // // Verifications ... + // matdConditions.isSARBearish && + // adxtdConditions.isStrong && + // adxtdConditions.isBearish && + // strConditions.isTrendBearish && + // cheConditions.isStrongBearish && + // tdConditions.isBearish && + // hkConditions.isHKBearish && + // hkConditions.isSMHKBearish && + // mrbConditions.isFastUnderSlow && + // sslcConditions.isBearish && + // hullConditions.isBearish + // // + // ; + // if (short1) + // { + // shortPusher++; + // } + + // // + // bool short2 = + // // + // // Starting Conditions ... + // matdConditions.isSARSwitchedToBearish && + // // + // // Verifications ... + // matdConditions.isBearish && + // adxtdConditions.isStrong && + // adxtdConditions.isBearish && + // strConditions.isTrendBearish && + // cheConditions.isStrongBearish && + // tdConditions.isBearish && + // hkConditions.isHKBearish && + // hkConditions.isSMHKBearish && + // mrbConditions.isFastUnderSlow && + // sslcConditions.isBearish && + // hullConditions.isBearish + // // + // ; + // if (short2) + // { + // shortPusher++; + // } + + // // + // bool short3 = + // // + // // Starting Conditions ... + // adxtdConditions.isStrongSwitchedToBearish && + // // + // // Verifications ... + // matdConditions.isBearish && + // strConditions.isTrendBearish && + // cheConditions.isStrongBearish && + // tdConditions.isBearish && + // hkConditions.isHKBearish && + // hkConditions.isSMHKBearish && + // mrbConditions.isFastUnderSlow && + // sslcConditions.isBearish && + // hullConditions.isBearish + // // + // ; + // if (short3) + // { + // shortPusher++; + // } + + // // + // bool short4 = + // // + // // Starting Conditions ... + // strConditions.isTrendSwitchedToBearish && + // // + // // Verifications ... + // matdConditions.isBearish && + // adxtdConditions.isStrong && + // adxtdConditions.isBearish && + // cheConditions.isStrongBearish && + // tdConditions.isBearish && + // hkConditions.isHKBearish && + // hkConditions.isSMHKBearish && + // mrbConditions.isFastUnderSlow && + // sslcConditions.isBearish && + // hullConditions.isBearish + // // + // ; + // if (short4) + // { + // shortPusher++; + // } + + // // + // bool short5 = + // // + // // Starting Conditions ... + // cheConditions.isStrongSwitchedToBearish && + // // + // // Verifications ... + // matdConditions.isBearish && + // adxtdConditions.isStrong && + // adxtdConditions.isBearish && + // strConditions.isTrendBearish && + // tdConditions.isBearish && + // hkConditions.isHKBearish && + // hkConditions.isSMHKBearish && + // mrbConditions.isFastUnderSlow && + // sslcConditions.isBearish && + // hullConditions.isBearish + // // + // ; + // if (short5) + // { + // shortPusher++; + // } + + // // + // bool short6 = + // // + // // Starting Conditions ... + // tdConditions.isSwitchedToBearish && + // // + // // Verifications ... + // matdConditions.isBearish && + // adxtdConditions.isStrong && + // adxtdConditions.isBearish && + // strConditions.isTrendBearish && + // cheConditions.isStrongBearish && + // hkConditions.isHKBearish && + // hkConditions.isSMHKBearish && + // mrbConditions.isFastUnderSlow && + // sslcConditions.isBearish && + // hullConditions.isBearish + // // + // ; + // if (short6) + // { + // shortPusher++; + // } + + // // + // bool short7 = + // // + // // Starting Conditions ... + // rsis[cIndex] < 70 && + // rsis[pIndex] >= 70 && + // // + // // Verifications ... + // tdConditions.isBearish && + // matdConditions.isBearish && + // adxtdConditions.isStrong && + // adxtdConditions.isBearish && + // strConditions.isTrendBearish && + // cheConditions.isStrongBearish && + // hkConditions.isHKBearish && + // hkConditions.isSMHKBearish && + // mrbConditions.isFastUnderSlow && + // sslcConditions.isBearish && + // hullConditions.isBearish + // // + // ; + // if (short7) + // { + // shortPusher++; + // } + + // // + // bool short8 = + // // + // // Starting Conditions ... + // ccis[cIndex] < 100 && + // ccis[pIndex] >= 100 && + // // + // // Verifications ... + // tdConditions.isBearish && + // matdConditions.isBearish && + // adxtdConditions.isStrong && + // adxtdConditions.isBearish && + // strConditions.isTrendBearish && + // cheConditions.isStrongBearish && + // hkConditions.isHKBearish && + // hkConditions.isSMHKBearish && + // mrbConditions.isFastUnderSlow && + // sslcConditions.isBearish && + // hullConditions.isBearish + // // + // ; + // if (short8) + // { + // shortPusher++; + // } + + // // + // bool short9 = + // // + // // Starting Conditions ... + // macdMains[cIndex] < 0 && + // macdMains[cIndex] < macdSignals[cIndex] && + // // + // // Verifications ... + // tdConditions.isBearish && + // matdConditions.isBearish && + // adxtdConditions.isStrong && + // adxtdConditions.isBearish && + // strConditions.isTrendBearish && + // cheConditions.isStrongBearish && + // hkConditions.isHKBearish && + // hkConditions.isSMHKBearish && + // mrbConditions.isFastUnderSlow && + // sslcConditions.isBearish && + // hullConditions.isBearish + // // + // ; + // if (short9) + // { + // shortPusher++; + // } + + // // + // bool short10 = + // // + // // Starting Conditions ... + // ichConditions.HasShortConditions() && + // // + // // Verifications ... + // tdConditions.isBearish && + // matdConditions.isBearish && + // adxtdConditions.isStrong && + // adxtdConditions.isBearish && + // strConditions.isTrendBearish && + // cheConditions.isStrongBearish && + // hkConditions.isHKBearish && + // hkConditions.isSMHKBearish && + // mrbConditions.isFastUnderSlow && + // sslcConditions.isBearish && + // hullConditions.isBearish + // // + // ; + // if (short10) + // { + // shortPusher++; + // } + + // // + // bool short11 = + // // + // // Starting Conditions ... + // hkConditions.isHKSwitchedToBearish && + // // + // // Verifications ... + // tdConditions.isBearish && + // matdConditions.isBearish && + // adxtdConditions.isStrong && + // adxtdConditions.isBearish && + // strConditions.isTrendBearish && + // cheConditions.isStrongBearish && + // hkConditions.isSMHKBearish && + // mrbConditions.isFastUnderSlow && + // sslcConditions.isBearish && + // hullConditions.isBearish + // // + // ; + // if (short11) + // { + // shortPusher++; + // } + + // // + // bool short12 = + // // + // // Starting Conditions ... + // hkConditions.isSMHKSwitchedToBearish && + // // + // // Verifications ... + // tdConditions.isBearish && + // matdConditions.isBearish && + // adxtdConditions.isStrong && + // adxtdConditions.isBearish && + // strConditions.isTrendBearish && + // cheConditions.isStrongBearish && + // hkConditions.isHKBearish && + // mrbConditions.isFastUnderSlow && + // sslcConditions.isBearish && + // hullConditions.isBearish + // // + // ; + // if (short12) + // { + // shortPusher++; + // } + + // // + // bool short13 = + // // + // // Starting Conditions ... + // mrbConditions.isFastCrossedUnderSlow && + // // + // // Verifications ... + // tdConditions.isBearish && + // matdConditions.isBearish && + // adxtdConditions.isStrong && + // adxtdConditions.isBearish && + // strConditions.isTrendBearish && + // cheConditions.isStrongBearish && + // hkConditions.isHKBearish && + // hkConditions.isSMHKBearish && + // sslcConditions.isBearish && + // hullConditions.isBearish + + // // + // ; + // if (short13) + // { + // shortPusher++; + // } + + // // + // bool short14 = + // // + // // Starting Conditions ... + // sslcConditions.isSwitchedToBearish && + // // + // // Verifications ... + // tdConditions.isBearish && + // matdConditions.isBearish && + // adxtdConditions.isStrong && + // adxtdConditions.isBearish && + // strConditions.isTrendBearish && + // cheConditions.isStrongBearish && + // hkConditions.isHKBearish && + // hkConditions.isSMHKBearish && + // mrbConditions.isFastUnderSlow && + // hullConditions.isBearish + + // // + // ; + // if (short14) + // { + // shortPusher++; + // } + + // // + // bool short15 = + // // + // // Starting Conditions ... + // hullConditions.isSwitchedToBearish && + // // + // // Verifications ... + // tdConditions.isBearish && + // matdConditions.isBearish && + // adxtdConditions.isStrong && + // adxtdConditions.isBearish && + // strConditions.isTrendBearish && + // cheConditions.isStrongBearish && + // hkConditions.isHKBearish && + // hkConditions.isSMHKBearish && + // mrbConditions.isFastUnderSlow && + // sslcConditions.isBearish + + // // + // ; + // if (short15) + // { + // shortPusher++; + // } + + // // + // hasShort = + // // + // shortPusher >= 1 && + // !oscLongVerifications && + // asctConditions.isShortSignal && + // bearishScore > bullishScore * 2 && + // ( + // // + // short1 + // // + // || + // // + // short2 + // // + // || + // // + // short3 + // // + // || + // // + // short4 + // // + // || + // // + // short5 + // // + // || + // // + // short6 + // // + // || + // // + // short7 + // // + // || + // // + // short8 + // // + // || + // // + // short9 + // // + // || + // // + // short10 + // // + // || + // // + // short11 + // // + // || + // // + // short12 + // // + // || + // // + // short13 + // // + // || + // // + // short14 + // // + // || + // // + // short15 + // // + // ) + // // + // ; + // } + + // // + // bool hasSignal = hasLong || hasShort; + // if (!hasSignal) + // { + // return; + // } + + // + + // + // Since we have a Signal in current Bar, ignore other ticks and + // waits for Next Bar ... + // xBarTracker.Waits(); + + // // + // int pusher = hasLong + // ? longPusher + // : shortPusher; + + // // + // XSignal mSignal; + // bool isPrepared = mSignal.Prepare( + // _Symbol, + // "XXX_" + ToString(pusher), + // _Period, + // mType, + // X_ORDER_MODE_MARKET, + // mEntry, + // eaVolume, + // 0, // mSL, + // mTP // + // ); + // if (!isPrepared) + // { + // return; + // } + + // + // Get Consitions and Validate it ... + X121SetupConditions conditions; + bool hasConditions = mSetup.GetConditions( + conditions // + ); + if (!hasConditions) + { + return; + } + + // + string separator = "\n"; + + // + // Retrieve Scores ... + double bullishScore = 0; + double bearishScore = 0; + conditions.GenerateScore( + bullishScore, + bearishScore // + ); + + // + // Create Score Summary for Commenting on Chart ... + string scoreSummary = + // + "Scores:" + separator + + "----------" + separator + + "Bullish: " + ToString(bullishScore) + separator + + "Bearish: " + ToString(bearishScore) + separator + + "" + // + ; + + // + Comment(scoreSummary); + + // + // Check Conditions has Signal or not ... + int pusher = 0; + XSignal signal; + bool hasSignal = mSignalGenerator + .HasSignal( + conditions, + signal, + pusher, + eaAllowLong, + eaAllowShort, + eaVolume, + 0, // SL Point ... + 30 // TP Point ... + ); + if (!hasSignal) + { + return; + } + + // + // Since we have a Signal in current Bar, ignore other ticks and + // waits for Next Bar ... + xBarTracker.Waits(); + + // + // Generate Condition Summary for Logging ... + string summary = conditions.GenerateSummary(false, true, false); + + // + Print(summary); + + // + ENUM_X_SIGNAL_EXECUTION_RESULT state; + int isExecuted = mTrader.ExecuteSignal( + signal, + state // + ); + if (isExecuted) + { + // + string message = "Signal Executed Successfully ..."; + + // + mAlert.Alert(message); + } +} + +// +// Custom Functions ... + +// +bool InitialEA() +{ + // + bool result = false; + + // + TesterHideIndicators(true); + + // + mAlert = new XSCAlert(); + mAlert.SetLogAlerts(true); + mAlert.SetPrefix(ShortName); + mAlert.SetEnableAlerts(true); + mAlert.SetPushAlerts(false); + mAlert.SetMailAlerts(false); + mAlert.SetTerminalAlerts(false); + + // + mTrader = new XSCTrade( + eaSlippage, + eaMagicNumber, + 0, + 0, + 0 // + ); + + // + result = xBarTracker.Init( + _Symbol, + _Period // + ); + if (!result) + { + return result; + } + + // + X121SetupInputs x121Inputs; + x121Inputs.symbol = _Symbol; + x121Inputs.period = _Period; + result = x121Inputs.Init(); + if (!result) + { + return result; + } + mSetup = new XSCX121Setup(); + result = mSetup.Init( + x121Inputs // + ); + if (!result) + { + return result; + } + + // + // Init Temp ... + + // // + // // CCI ... + // cciHandler = iCCI( + // _Symbol, + // _Period, + // 14, + // PRICE_CLOSE // + // ); + // result = cciHandler != INVALID_HANDLE; + // if (!result) + // { + // return result; + // } + + // // + // // RSI ... + // rsiHandler = iRSI( + // _Symbol, + // _Period, + // 14, + // PRICE_CLOSE // + // ); + // result = rsiHandler != INVALID_HANDLE; + // if (!result) + // { + // return result; + // } + + // // + // // MACD ... + // macdHandler = iMACD( + // _Symbol, + // _Period, + // 12, + // 26, + // 9, + // PRICE_CLOSE // + // ); + // result = macdHandler != INVALID_HANDLE; + // if (!result) + // { + // return result; + // } + + // + // Init Indicators ... + + // // + // // XMATD ... + // XMATDInputs matdInputs; + // matdInputs.Default(); + // matdHelper = new XSCXMATDHelper( + // _Symbol, + // _Period // + // ); + // result = matdHelper.Init(matdInputs); + // if (!result) + // { + // return result; + // } + + // // + // // XADXTD ... + // XADXTDInputs adxtdInputs; + // adxtdInputs.Default(); + // adxtdHelper = new XSCXADXTDHelper( + // _Symbol, + // _Period // + // ); + // result = adxtdHelper.Init(adxtdInputs); + // if (!result) + // { + // return result; + // } + + // // + // // XSTR ... + // XSTRInputs strInputs; + // strInputs.Default(); + // strInputs.showTrends = true; + // strHelper = new XSCXSTRHelper(); + // result = strHelper.Init( + // _Symbol, + // _Period, + // strInputs // + // ); + // if (!result) + // { + // return result; + // } + + // // + // // XCHE ... + // XCHEInputs cheInputs; + // cheInputs.Default(); + // cheInputs.showLongExit1Line = true; + // cheInputs.showShortExit1Line = true; + // cheInputs.showLongExit2Line = true; + // cheInputs.showShortExit2Line = true; + // cheHelper = new XSCXCHEHelper(); + // result = cheHelper.Init( + // _Symbol, + // _Period, + // cheInputs // + // ); + // if (!result) + // { + // return result; + // } + + // // + // // XASCT ... + // XASCTInputs asctInputs; + // asctInputs.Default(); + // asctInputs.showLongs = false; + // asctInputs.showShorts = false; + // asctHelper = new XSCXASCTHelper(); + // result = asctHelper.Init( + // _Symbol, + // _Period, + // asctInputs // + // ); + // if (!result) + // { + // return result; + // } + + // // + // // XTD ... + // XTDInputs tdInputs; + // tdInputs.Default(); + // tdHelper = new XSCXTDHelper(); + // result = tdHelper.Init( + // _Symbol, + // _Period, + // tdInputs // + // ); + // if (!result) + // { + // return result; + // } + + // // + // // XICH ... + // XICHInputs ichInputs; + // ichInputs.Default(); + // ichHelper = new XSCXICHHelper(); + // result = ichHelper.Init( + // _Symbol, + // _Period, + // ichInputs // + // ); + // if (!result) + // { + // return result; + // } + + // // + // // XHK ... + // XHKInputs hkInputs; + // hkInputs.Default(); + // hkHelper = new XSCXHKHelper(); + // result = hkHelper.Init( + // _Symbol, + // _Period, + // hkInputs // + // ); + // if (!result) + // { + // return result; + // } + + // // + // // XMRB ... + // XMRBInputs mrbInputs; + // mrbInputs.Default(); + // mrbHelper = new XSCXMRBHelper(); + // result = mrbHelper.Init( + // _Symbol, + // _Period, + // mrbInputs // + // ); + // if (!result) + // { + // return result; + // } + + // // + // // XSSLC ... + // XSSLCInputs sslcInputs; + // sslcInputs.Default(); + // sslcHelper = new XSCXSSLCHelper(); + // result = sslcHelper.Init( + // _Symbol, + // _Period, + // sslcInputs // + // ); + // if (!result) + // { + // return result; + // } + + // // + // // XHULL ... + // XHULLInputs hullInputs; + // hullInputs.Default(); + // hullHelper = new XSCXHULLHelper(); + // result = hullHelper.Init( + // _Symbol, + // _Period, + // hullInputs // + // ); + // if (!result) + // { + // return result; + // } + + // // + // // XOSC ... + // XOSCInputs oscInputs; + // oscInputs.Default(); + // oscHelper = new XSCXOSCHelper(); + // result = oscHelper.Init( + // _Symbol, + // _Period, + // oscInputs // + // ); + // if (!result) + // { + // return result; + // } + + // + return result; +} diff --git a/Helpers/x-saherelm.xadxtd.helper.mq5 b/Helpers/x-saherelm.xadxtd.helper.mq5 new file mode 100644 index 00000000..87b8a733 --- /dev/null +++ b/Helpers/x-saherelm.xadxtd.helper.mq5 @@ -0,0 +1,678 @@ +/////////////////////////////////////////////////////// +// +// SaherElm IT Center MQL5 Class Library +// ---------------------------------------------- +// Name: XADXTD +// Description: provides Indicator implementation +// requirements ... +// +// +// Maintainer: +// ------------ +// Hadi Khazaee Asl (hadi_khazaee_asl@yahoo.com) +// +////////////////////////////////////////////////////// +// +// Global Properties ... +#property library +#property copyright "Copyright 2023, SaherElm IT Center" +#property link "https://www.saherelm.ir" +#property version "1.00" +#property strict + +// +// Imports ... +#include "../Classes/x-saherelm.base.class.mq5" + +// +// Indicator Buffers ... +enum ENUM_XADXTD_BUFFERS +{ + XADXTD_STRENGTH_LINE = 0, // Strenght Buffer ... + XADXTD_BULL_LINE = 1, // Bull Buffer ... + XADXTD_BEAR_LINE = 2, // Bear Buffer ... +}; + +// +string GetTitle(ENUM_XADXTD_BUFFERS bufferLine) +{ + // + string result = NULL; + + // + switch (bufferLine) + { + // + case XADXTD_STRENGTH_LINE: + result = "XStrength"; + break; + + // + case XADXTD_BULL_LINE: + result = "XBull"; + break; + + // + case XADXTD_BEAR_LINE: + result = "XBear"; + break; + } + + // + return result; +} + +// +// XADXTD Indicator Inputs ... +struct XADXTDInputs +{ + // + // Props ... + string version; + + // + // Market ... + + // + int length; // Length + + // + // Constructor ... + XADXTDInputs() + { + Clean(); + } + + // + // Tools ... + + // + // Initial Inputs ... + bool Init( + int _length = 21 // Length + ) + { + // + bool result = false; + + // + this.length = _length; + + // + result = IsValid(); + + // + return result; + } + + // + // Cleanup ... + void Clean() + { + // + length = 0; + } + + // + // Default ... + void Default() + { + // + length = 21; + } + + // + // Validate ... + bool IsValid() + { + // + bool result = false; + + // + result = + // + length > 0 + // + ; + + // + return result; + } + + // + // Retrieve Max Length ... + int Max() + { + // + int result = 0; + + // + int values[1] = { + length // + }; + + // + result = GetMax(values); + + // + return result; + } +}; + +// +// Define Conditions ... +struct XADXTDConditions +{ + // + // Common ... + string symbol; + ENUM_TIMEFRAMES period; + datetime time; + + // + // Buffers ... + double strength[]; + double bullp[]; + double bearp[]; + + // + // Conditions ... + + // + bool isStrong; + bool isBullish; + bool isBearish; + bool isSwitchedToBullish; + bool isSwitchedToBearish; + bool isStrongSwitchedToBullish; + bool isStrongSwitchedToBearish; + + // + void Clean() + { + // + Clean(strength); + Clean(bullp); + Clean(bearp); + + // + ArraySetAsSeries(strength, true); + ArraySetAsSeries(bullp, true); + ArraySetAsSeries(bearp, true); + + // + isStrong = false; + isBullish = false; + isBearish = false; + isSwitchedToBullish = false; + isSwitchedToBearish = false; + isStrongSwitchedToBullish = false; + isStrongSwitchedToBearish = false; + } + + // + void GenerateScore( + double &bullishScore, + double &bearishScore // + ) + { + // + bullishScore = 0; + bearishScore = 0; + + // + if (isBullish) + { + // + bullishScore++; + if (isStrong) + { + bullishScore++; + } + } + if (isBearish) + { + bearishScore++; + if (isStrong) + { + bearishScore++; + } + } + if (isSwitchedToBullish) + { + bullishScore++; + if (isStrong) + { + bullishScore++; + } + } + if (isSwitchedToBearish) + { + bearishScore++; + if (isStrong) + { + bearishScore++; + } + } + if (isStrongSwitchedToBullish) + { + bullishScore++; + } + if (isStrongSwitchedToBearish) + { + bearishScore++; + } + } + + // + string GenerateSummary( + bool onlyCommons = false, + bool onlyConditions = false, + bool includeScores = true, + bool ignoreFalseConditions = true, + string separator = "\n" // + ) + { + // + string result = NULL; + + // + double bullishScore = 0; + double bearishScore = 0; + GenerateScore( + bullishScore, + bearishScore // + ); + + // + string scoresStr = + // + "Scores: " + separator + + "---------------" + separator + + "Bullish: " + ToString(bullishScore) + separator + + "Bearish: " + ToString(bearishScore) + separator + + "" + // + ; + + // + string commonStr = GenerateSpecifiedCommonSummary( + this, + separator, + includeScores // + ); + + // + string conditionsStr = + // + ToString("isStrong", isStrong, ignoreFalseConditions, separator) + + ToString("isBullish", isBullish, ignoreFalseConditions, separator) + + ToString("isBearish", isBearish, ignoreFalseConditions, separator) + + ToString("isSwitchedToBullish", isSwitchedToBullish, ignoreFalseConditions, separator) + + ToString("isSwitchedToBearish", isSwitchedToBearish, ignoreFalseConditions, separator) + + ToString("isStrongSwitchedToBullish", isStrongSwitchedToBullish, ignoreFalseConditions, separator) + + ToString("isStrongSwitchedToBearish", isStrongSwitchedToBearish, ignoreFalseConditions, separator) + + "" + // + ; + + // + result = + // + "[" + GetTag() + "]" + separator + + (onlyConditions + ? "" + : commonStr) + + (!includeScores + ? "" + : scoresStr) + + " " + separator + + (onlyCommons + ? "" + : conditionsStr) + + "" + // + ; + + // + return result; + } + + // + string GetTag() + { + return "XADXTD"; + } +}; + +// +// Indicator Class ... + +class XSCXADXTDHelper : public XSCBase +{ + // + // Public ... +public: + // + // Props ... + + // + // Constructor(s) ... + void XSCXADXTDHelper( + string symbol, // Trading Symbol + ENUM_TIMEFRAMES period // Trading TimeFrame + ) + { + // + mSymbol = symbol; + mPeriod = period; + } + + // + // Deconstructor ... + void ~XSCXADXTDHelper() {} + + // + // Initialize Indicator ... + bool Init( + XADXTDInputs &inputs // Indicator Properties + ) + { + // + bool result = false; + + // + result = inputs.IsValid(); + if (!result) + { + return result; + } + + // + // Set Inputs ... + this.mInputs = inputs; + + // + // Validate Indicator State ... + result = this.IsValid(); + if (!result) + { + return result; + } + + // + result = DefineBuffers(); + if (!result) + { + return result; + } + + // + handler = iADX( + mSymbol, + mPeriod, + mInputs.length // + ); + result = handler != INVALID_HANDLE; + + // + return result; + } + + // + XADXTDInputs GetInputs() + { + return mInputs; + } + + // + bool SetInputs( + XADXTDInputs &inputs // Indicator Properties + ) + { + return Init(inputs); + } + + // + // Get Tag ... + string GetTag() + { + // + string result = NULL; + + // + result = GetToken(); + + // + return result; + } + + // + // Get Token ... + string GetToken() + { + // + string result = NULL; + + // + result = GetSpecificToken(this); + + // + return result; + } + + // + string GetSymbol() + { + return mSymbol; + } + + // + ENUM_TIMEFRAMES GetPeriod() + { + return mPeriod; + } + + // + // Validate ... + bool IsValid() + { + // + bool result = false; + + // + result = + // + mInputs.IsValid() && + IsSpecifiedValid(mPeriod) && + IsSpecifiedValid(mSymbol) + // + ; + + // + return result; + } + + // + // De Initialize Class ... + void DeInit(int reason) + { + // + IndicatorRelease(handler); + } + + // + // Tools ... + int CopyData( + ENUM_XADXTD_BUFFERS line, + double &dest[], + int start = 0, + int count = 1 // + ) + { + // + int result = 0; + + // + int mLine = -1; + switch (line) + { + // + case XADXTD_STRENGTH_LINE: + mLine = MAIN_LINE; + break; + + // + case XADXTD_BULL_LINE: + mLine = PLUSDI_LINE; + break; + + // + case XADXTD_BEAR_LINE: + mLine = MINUSDI_LINE; + break; + } + + // + if (mLine == -1 || handler == INVALID_HANDLE) + { + return result; + } + + // + result = CopyBuffer( + handler, + mLine, + start, + count, + dest // + ); + + // + return result; + } + + // + bool GetConditions( + XADXTDConditions &conditions, // + int barIndex = 0, // + int loopback = 3 // + ) + { + // + bool result = true; + + // + if (loopback < 3) + { + loopback = 3; + } + + // + conditions.Clean(); + + // + conditions.symbol = mSymbol; + conditions.period = mPeriod; + conditions.time = TimeCurrent(); + + // + int zIndex = barIndex; + int cIndex = zIndex + 1; + int pIndex = cIndex + 1; + int ppIndex = pIndex + 1; + + // + CopyData( + XADXTD_STRENGTH_LINE, + conditions.strength, + zIndex, + loopback // + ); + CopyData( + XADXTD_BULL_LINE, + conditions.bullp, + zIndex, + loopback // + ); + CopyData( + XADXTD_BEAR_LINE, + conditions.bearp, + zIndex, + loopback // + ); + + // + // Calculate Conditions ... + + // + bool isStrong = conditions.strength[cIndex] >= 20; + + // + bool isBullish = conditions.bullp[cIndex] > conditions.bearp[cIndex]; + bool isBearish = conditions.bearp[cIndex] > conditions.bullp[cIndex]; + + // + bool isBullishPrev = conditions.bullp[pIndex] > conditions.bearp[pIndex]; + bool isBearishPrev = conditions.bearp[pIndex] > conditions.bullp[pIndex]; + + // + bool isSwitchedToBullish = isBullish && + !isBullishPrev; + bool isSwitchedToBearish = isBearish && + !isBearishPrev; + + // + bool isStrongSwitchedToBullish = isStrong && + isSwitchedToBullish; + bool isStrongSwitchedToBearish = isStrong && + isSwitchedToBearish; + + // + conditions.isStrong = isStrong; + conditions.isBullish = isBullish; + conditions.isBearish = isBearish; + conditions.isSwitchedToBullish = isSwitchedToBullish; + conditions.isSwitchedToBearish = isSwitchedToBearish; + conditions.isStrongSwitchedToBullish = isStrongSwitchedToBullish; + conditions.isStrongSwitchedToBearish = isStrongSwitchedToBearish; + + // + return result; + } + + // + // Protected ... +protected: + // + // Props ... + int handler; + + // + // Tools ... + bool DefineBuffers() + { + // + bool result = false; + + // + result = true; + + // + return result; + } + + // + // Private ... +private: + // + // Props ... + // + string mSymbol; // Symbol + ENUM_TIMEFRAMES mPeriod; // TimeFrame + + // + XADXTDInputs mInputs; // Properties +}; + +// \ No newline at end of file diff --git a/Helpers/x-saherelm.xasct.helper.mq5 b/Helpers/x-saherelm.xasct.helper.mq5 index 6ad34f9d..9cc3fd3c 100644 --- a/Helpers/x-saherelm.xasct.helper.mq5 +++ b/Helpers/x-saherelm.xasct.helper.mq5 @@ -122,6 +122,143 @@ struct XASCTInputs } }; +// +// Define Conditions ... +struct XASCTConditions +{ + // + // Common ... + string symbol; + ENUM_TIMEFRAMES period; + datetime time; + + // + // Buffers ... + double longSignal[]; + double shortSignal[]; + + // + // Conditions ... + + // + bool isLongSignal; + bool isShortSignal; + + // + void Clean() + { + // + Clean(longSignal); + Clean(shortSignal); + + // + ArraySetAsSeries(longSignal, true); + ArraySetAsSeries(shortSignal, true); + + // + isLongSignal = false; + isShortSignal = false; + } + + // + void GenerateScore( + double &bullishScore, + double &bearishScore // + ) + { + // + bullishScore = 0; + bearishScore = 0; + + // + if (isLongSignal) + { + bullishScore++; + } + + // + if (isShortSignal) + { + bearishScore++; + } + } + + // + string GenerateSummary( + bool onlyCommons = false, + bool onlyConditions = false, + bool includeScores = true, + bool ignoreFalseConditions = true, + string separator = "\n" // + ) + { + // + string result = NULL; + + // + double bullishScore = 0; + double bearishScore = 0; + GenerateScore( + bullishScore, + bearishScore // + ); + + // + string scoresStr = + // + "Scores: " + separator + + "---------------" + separator + + "Bullish: " + ToString(bullishScore) + separator + + "Bearish: " + ToString(bearishScore) + separator + + "" + // + ; + + // + string commonStr = GenerateSpecifiedCommonSummary( + this, + separator, + includeScores // + ); + + // + string conditionsStr = + // + ToString("isLongSignal", isLongSignal, ignoreFalseConditions, separator) + + ToString("isShortSignal", isShortSignal, ignoreFalseConditions, separator) + + "" + // + ; + + // + result = + // + "[" + GetTag() + "]" + separator + + (onlyConditions + ? "" + : commonStr) + + (!includeScores + ? "" + : scoresStr) + + " " + separator + + (onlyCommons + ? "" + : conditionsStr) + + "" + // + ; + + // + return result; + } + + // + string GetTag() + { + return "XASCT"; + } +}; + // // Class ... class XSCXASCTHelper : public XSCBaseHelper @@ -325,6 +462,66 @@ public: ); } + // + bool GetConditions( + XASCTConditions &conditions, // + int barIndex = 0, // + int loopback = 3 // + ) + { + // + bool result = true; + + // + if (loopback < 3) + { + loopback = 3; + } + + // + conditions.Clean(); + + // + conditions.symbol = mSymbol; + conditions.period = mPeriod; + conditions.time = TimeCurrent(); + + // + int zIndex = barIndex; + int cIndex = zIndex + 1; + int pIndex = cIndex + 1; + int ppIndex = pIndex + 1; + + // + // Buffers ... + + // + CopyLong( + zIndex, + loopback, + conditions.longSignal // + ); + CopyShort( + zIndex, + loopback, + conditions.shortSignal // + ); + + // + // Conditions ... + + // + bool isLongSignal = NotEmptyZero(conditions.longSignal[cIndex]); + bool isShortSignal = NotEmptyZero(conditions.shortSignal[cIndex]); + + // + conditions.isLongSignal = isLongSignal; + conditions.isShortSignal = isShortSignal; + + // + return result; + } + // // Protected ... protected: diff --git a/Helpers/x-saherelm.xche.helper.mq5 b/Helpers/x-saherelm.xche.helper.mq5 index 268fc298..894776aa 100644 --- a/Helpers/x-saherelm.xche.helper.mq5 +++ b/Helpers/x-saherelm.xche.helper.mq5 @@ -150,6 +150,191 @@ struct XCHEInputs } }; +// +// Define Conditions ... +struct XCHEConditions +{ + // + // Common ... + string symbol; + ENUM_TIMEFRAMES period; + datetime time; + + // + // Buffers ... + double long1[]; + double long2[]; + double short1[]; + double short2[]; + + // + // Conditions ... + + // + bool isBullish; + bool isBearish; + bool isStrongBullish; + bool isStrongBearish; + bool isSwitchedToBullish; + bool isSwitchedToBearish; + bool isStrongSwitchedToBullish; + bool isStrongSwitchedToBearish; + + // + void Clean() + { + // + Clean(long1); + Clean(long2); + Clean(short1); + Clean(short2); + + // + ArraySetAsSeries(long1, true); + ArraySetAsSeries(long2, true); + ArraySetAsSeries(short1, true); + ArraySetAsSeries(short2, true); + + // + isBullish = false; + isBearish = false; + isStrongBullish = false; + isStrongBearish = false; + isSwitchedToBullish = false; + isSwitchedToBearish = false; + isStrongSwitchedToBullish = false; + isStrongSwitchedToBearish = false; + } + + // + void GenerateScore( + double &bullishScore, + double &bearishScore // + ) + { + // + bullishScore = 0; + bearishScore = 0; + + // + if (isBullish) + { + bullishScore++; + } + if (isStrongBullish) + { + bullishScore++; + } + if (isSwitchedToBullish) + { + bullishScore++; + } + if (isStrongSwitchedToBullish) + { + bullishScore++; + } + + // + if (isBearish) + { + bearishScore++; + } + if (isStrongBearish) + { + bearishScore++; + } + if (isSwitchedToBearish) + { + bearishScore++; + } + if (isStrongSwitchedToBearish) + { + bearishScore++; + } + } + + // + string GenerateSummary( + bool onlyCommons = false, + bool onlyConditions = false, + bool includeScores = true, + bool ignoreFalseConditions = true, + string separator = "\n" // + ) + { + // + string result = NULL; + + // + double bullishScore = 0; + double bearishScore = 0; + GenerateScore( + bullishScore, + bearishScore // + ); + + // + string scoresStr = + // + "Scores: " + separator + + "---------------" + separator + + "Bullish: " + ToString(bullishScore) + separator + + "Bearish: " + ToString(bearishScore) + separator + + "" + // + ; + + // + string commonStr = GenerateSpecifiedCommonSummary( + this, + separator, + includeScores // + ); + + // + string conditionsStr = + // + ToString("isBullish", isBullish, ignoreFalseConditions, separator) + + ToString("isBearish", isBearish, ignoreFalseConditions, separator) + + ToString("isStrongBullish", isStrongBullish, ignoreFalseConditions, separator) + + ToString("isStrongBearish", isStrongBearish, ignoreFalseConditions, separator) + + ToString("isSwitchedToBullish", isSwitchedToBullish, ignoreFalseConditions, separator) + + ToString("isSwitchedToBearish", isSwitchedToBearish, ignoreFalseConditions, separator) + + ToString("isStrongSwitchedToBullish", isStrongSwitchedToBullish, ignoreFalseConditions, separator) + + ToString("isStrongSwitchedToBearish", isStrongSwitchedToBearish, ignoreFalseConditions, separator) + + "" + // + ; + + // + result = + // + "[" + GetTag() + "]" + separator + + (onlyConditions + ? "" + : commonStr) + + (!includeScores + ? "" + : scoresStr) + + " " + separator + + (onlyCommons + ? "" + : conditionsStr) + + "" + // + ; + + // + return result; + } + + // + string GetTag() + { + return "XCHE"; + } +}; + // // Class ... class XSCXCHEHelper : public XSCBaseHelper @@ -435,6 +620,110 @@ public: ); } + // + bool GetConditions( + XCHEConditions &conditions, // + int barIndex = 0, // + int loopback = 3 // + ) + { + // + bool result = true; + + // + if (loopback < 3) + { + loopback = 3; + } + + // + conditions.Clean(); + + // + conditions.symbol = mSymbol; + conditions.period = mPeriod; + conditions.time = TimeCurrent(); + + // + int zIndex = barIndex; + int cIndex = zIndex + 1; + int pIndex = cIndex + 1; + int ppIndex = pIndex + 1; + + // + // Buffers ... + + // + CopyLongExit1( + zIndex, + loopback, + conditions.long1 // + ); + CopyLongExit2( + zIndex, + loopback, + conditions.long2 // + ); + CopyShortExit1( + zIndex, + loopback, + conditions.short1 // + ); + CopyShortExit2( + zIndex, + loopback, + conditions.short2 // + ); + + // + // Conditions ... + + // + bool isBullish = NotEmptyZero(conditions.long1[cIndex]); + bool isBearish = NotEmptyZero(conditions.short1[cIndex]); + + // + bool isBullishPrev = NotEmptyZero(conditions.long1[pIndex]); + bool isBearishPrev = NotEmptyZero(conditions.short1[pIndex]); + + // + bool isStrongBullish = isBullish && + NotEmptyZero(conditions.long2[cIndex]); + bool isStrongBearish = isBearish && + NotEmptyZero(conditions.short2[cIndex]); + + // + bool isStrongBullishPrev = isBullishPrev && + NotEmptyZero(conditions.long2[pIndex]); + bool isStrongBearishPrev = isBearishPrev && + NotEmptyZero(conditions.short2[pIndex]); + + // + bool isSwitchedToBullish = isBullish && + !isBullishPrev; + bool isSwitchedToBearish = isBearish && + !isBearishPrev; + + // + bool isStrongSwitchedToBullish = isStrongBullish && + !isStrongBullishPrev; + bool isStrongSwitchedToBearish = isStrongBearish && + !isStrongBearishPrev; + + // + conditions.isBullish = isBullish; + conditions.isBearish = isBearish; + conditions.isStrongBullish = isStrongBullish; + conditions.isStrongBearish = isStrongBearish; + conditions.isSwitchedToBullish = isSwitchedToBullish; + conditions.isSwitchedToBearish = isSwitchedToBearish; + conditions.isStrongSwitchedToBullish = isStrongSwitchedToBullish; + conditions.isStrongSwitchedToBearish = isStrongSwitchedToBearish; + + // + return result; + } + // // Protected ... protected: diff --git a/Helpers/x-saherelm.xhk.helper.mq5 b/Helpers/x-saherelm.xhk.helper.mq5 index c9b26980..3be5a92c 100644 --- a/Helpers/x-saherelm.xhk.helper.mq5 +++ b/Helpers/x-saherelm.xhk.helper.mq5 @@ -129,6 +129,194 @@ struct XHKInputs } }; +// +// Define Conditions ... +struct XHKConditions +{ + // + // Common ... + string symbol; + ENUM_TIMEFRAMES period; + datetime time; + + // + // Buffers ... + XOHCL hkBar[]; + XOHCL smHKBar[]; + + // + // Conditions ... + + // + bool isHKBullish; + bool isHKBearish; + bool isHKSwitchedToBullish; + bool isHKSwitchedToBearish; + + // + bool isSMHKBullish; + bool isSMHKBearish; + bool isSMHKSwitchedToBullish; + bool isSMHKSwitchedToBearish; + + // + void Clean() + { + // + Clean(hkBar); + Clean(smHKBar); + + // + ArraySetAsSeries(hkBar, true); + ArraySetAsSeries(smHKBar, true); + + // + isHKBullish = false; + isHKBearish = false; + isHKSwitchedToBullish = false; + isHKSwitchedToBearish = false; + + // + isSMHKBullish = false; + isSMHKBearish = false; + isSMHKSwitchedToBullish = false; + isSMHKSwitchedToBearish = false; + } + + // + void GenerateScore( + double &bullishScore, + double &bearishScore // + ) + { + // + bullishScore = 0; + bearishScore = 0; + + // + if (isHKBullish) + { + bullishScore++; + } + if (isHKSwitchedToBullish) + { + bullishScore++; + } + + // + if (isHKBearish) + { + bearishScore++; + } + if (isHKSwitchedToBearish) + { + bearishScore++; + } + + // + if (isSMHKBullish) + { + bullishScore++; + } + if (isSMHKSwitchedToBullish) + { + bullishScore++; + } + + // + if (isSMHKBearish) + { + bearishScore++; + } + if (isSMHKSwitchedToBearish) + { + bearishScore++; + } + } + + // + string GenerateSummary( + bool onlyCommons = false, + bool onlyConditions = false, + bool includeScores = true, + bool ignoreFalseConditions = true, + string separator = "\n" // + ) + { + // + string result = NULL; + + // + double bullishScore = 0; + double bearishScore = 0; + GenerateScore( + bullishScore, + bearishScore // + ); + + // + string scoresStr = + // + "Scores: " + separator + + "---------------" + separator + + "Bullish: " + ToString(bullishScore) + separator + + "Bearish: " + ToString(bearishScore) + separator + + "" + // + ; + + // + string commonStr = GenerateSpecifiedCommonSummary( + this, + separator, + includeScores // + ); + + // + string conditionsStr = + // + ToString("isHKBullish", isHKBullish, ignoreFalseConditions, separator) + + ToString("isHKSwitchedToBullish", isHKSwitchedToBullish, ignoreFalseConditions, separator) + + ToString("isHKBearish", isHKBearish, ignoreFalseConditions, separator) + + ToString("isHKSwitchedToBearish", isHKSwitchedToBearish, ignoreFalseConditions, separator) + + // + ToString("isSMHKBullish", isSMHKBullish, ignoreFalseConditions, separator) + + ToString("isSMHKSwitchedToBullish", isSMHKSwitchedToBullish, ignoreFalseConditions, separator) + + ToString("isSMHKBearish", isSMHKBearish, ignoreFalseConditions, separator) + + ToString("isSMHKSwitchedToBearish", isSMHKSwitchedToBearish, ignoreFalseConditions, separator) + + "" + // + ; + + // + result = + // + "[" + GetTag() + "]" + separator + + (onlyConditions + ? "" + : commonStr) + + (!includeScores + ? "" + : scoresStr) + + " " + separator + + (onlyCommons + ? "" + : conditionsStr) + + "" + // + ; + + // + return result; + } + + // + string GetTag() + { + return "XHK"; + } +}; + // // Class ... class XSCXHKHelper : public XSCBaseHelper @@ -886,6 +1074,97 @@ public: return result; } + // + bool GetConditions( + XHKConditions &conditions, // + int barIndex = 0, // + int loopback = 3 // + ) + { + // + bool result = true; + + // + if (loopback < 3) + { + loopback = 3; + } + + // + conditions.Clean(); + + // + conditions.symbol = mSymbol; + conditions.period = mPeriod; + conditions.time = TimeCurrent(); + + // + int zIndex = barIndex; + int cIndex = zIndex + 1; + int pIndex = cIndex + 1; + int ppIndex = pIndex + 1; + + // + CopyAsOHCL( + zIndex, + loopback, + conditions.hkBar // + ); + CopySMAsOHCL( + zIndex, + loopback, + conditions.smHKBar // + ); + + // + // Calculate Conditions ... + + // + bool isHKBullish = conditions.hkBar[cIndex].IsBullish(); + bool isHKBullishPrev = conditions.hkBar[pIndex].IsBullish(); + + // + bool isHKSwitchedToBullish = isHKBullish && + !isHKBullishPrev; + + // + bool isHKBearish = conditions.hkBar[cIndex].IsBearish(); + bool isHKBearishPrev = conditions.hkBar[pIndex].IsBearish(); + + // + bool isHKSwitchedToBearish = isHKBearish && + !isHKBearishPrev; + + // + bool isSMHKBullish = conditions.smHKBar[cIndex].IsBullish(); + bool isSMHKBullishPrev = conditions.smHKBar[pIndex].IsBullish(); + + // + bool isSMHKSwitchedToBullish = isSMHKBullish && + !isSMHKBullishPrev; + + // + bool isSMHKBearish = conditions.smHKBar[cIndex].IsBearish(); + bool isSMHKBearishPrev = conditions.smHKBar[pIndex].IsBearish(); + + // + bool isSMHKSwitchedToBearish = isSMHKBearish && + !isSMHKBearishPrev; + + // + conditions.isHKBullish = isHKBullish; + conditions.isHKSwitchedToBullish = isHKSwitchedToBullish; + conditions.isHKBearish = isHKBearish; + conditions.isHKSwitchedToBearish = isHKSwitchedToBearish; + conditions.isSMHKBullish = isSMHKBullish; + conditions.isSMHKSwitchedToBullish = isSMHKSwitchedToBullish; + conditions.isSMHKBearish = isSMHKBearish; + conditions.isSMHKSwitchedToBearish = isSMHKSwitchedToBearish; + + // + return result; + } + // // Protected ... protected: diff --git a/Helpers/x-saherelm.xhull.helper.mq5 b/Helpers/x-saherelm.xhull.helper.mq5 index 900f6298..85413c48 100644 --- a/Helpers/x-saherelm.xhull.helper.mq5 +++ b/Helpers/x-saherelm.xhull.helper.mq5 @@ -140,6 +140,185 @@ struct XHULLInputs } }; +// +// Define Conditions ... +struct XHULLConditions +{ + // + // Common ... + string symbol; + ENUM_TIMEFRAMES period; + datetime time; + + // + // Buffers ... + double up[]; + double down[]; + + // + // Conditions ... + + // + bool isBullish; + bool isBearish; + bool isUpBullish; + bool isUpBearish; + bool isDownBullish; + bool isDownBearish; + bool isSwitchedToBullish; + bool isSwitchedToBearish; + + // + void Clean() + { + // + Clean(up); + Clean(down); + + // + ArraySetAsSeries(up, true); + ArraySetAsSeries(down, true); + + // + isBullish = false; + isBearish = false; + isUpBullish = false; + isUpBearish = false; + isDownBullish = false; + isDownBearish = false; + isSwitchedToBullish = false; + isSwitchedToBearish = false; + } + + // + void GenerateScore( + double &bullishScore, + double &bearishScore // + ) + { + // + bullishScore = 0; + bearishScore = 0; + + // + if (isBullish) + { + bullishScore++; + } + if (isUpBullish) + { + bullishScore++; + } + if (isDownBullish) + { + bullishScore++; + } + if (isSwitchedToBullish) + { + bullishScore++; + } + + // + if (isBearish) + { + bearishScore++; + } + if (isUpBearish) + { + bearishScore++; + } + if (isDownBearish) + { + bearishScore++; + } + if (isSwitchedToBearish) + { + bearishScore++; + } + } + + // + string GenerateSummary( + bool onlyCommons = false, + bool onlyConditions = false, + bool includeScores = true, + bool ignoreFalseConditions = true, + string separator = "\n" // + ) + { + // + string result = NULL; + + // + double bullishScore = 0; + double bearishScore = 0; + GenerateScore( + bullishScore, + bearishScore // + ); + + // + string scoresStr = + // + "Scores: " + separator + + "---------------" + separator + + "Bullish: " + ToString(bullishScore) + separator + + "Bearish: " + ToString(bearishScore) + separator + + "" + // + ; + + // + string commonStr = GenerateSpecifiedCommonSummary( + this, + separator, + includeScores // + ); + + // + string conditionsStr = + // + ToString("isBullish", isBullish, ignoreFalseConditions, separator) + + ToString("isBearish", isBearish, ignoreFalseConditions, separator) + + ToString("isUpBullish", isUpBullish, ignoreFalseConditions, separator) + + ToString("isUpBearish", isUpBearish, ignoreFalseConditions, separator) + + ToString("isDownBullish", isDownBullish, ignoreFalseConditions, separator) + + ToString("isDownBearish", isDownBearish, ignoreFalseConditions, separator) + + ToString("isSwitchedToBullish", isSwitchedToBullish, ignoreFalseConditions, separator) + + ToString("isSwitchedToBearish", isSwitchedToBearish, ignoreFalseConditions, separator) + + "" + // + ; + + // + result = + // + "[" + GetTag() + "]" + separator + + (onlyConditions + ? "" + : commonStr) + + (!includeScores + ? "" + : scoresStr) + + " " + separator + + (onlyCommons + ? "" + : conditionsStr) + + "" + // + ; + + // + return result; + } + + // + string GetTag() + { + return "XHULL"; + } +}; + // // Class ... class XSCXHULLHelper : public XSCBaseHelper @@ -165,7 +344,7 @@ public: bool Init( string symbol, // Trading Symbol ENUM_TIMEFRAMES period, // Trading Period - XHULLInputs &inputs // Inputs + XHULLInputs &inputs // Inputs ) { // @@ -346,6 +525,99 @@ public: ); } + // + bool GetConditions( + XHULLConditions &conditions, // + int barIndex = 0, // + int loopback = 4 // + ) + { + // + bool result = true; + + // + if (loopback < 4) + { + loopback = 4; + } + + // + conditions.Clean(); + + // + conditions.symbol = mSymbol; + conditions.period = mPeriod; + conditions.time = TimeCurrent(); + + // + int zIndex = barIndex; + int cIndex = zIndex + 1; + int pIndex = cIndex + 1; + int ppIndex = pIndex + 1; + + // + CopyUp( + zIndex, + loopback, + conditions.up // + ); + CopyDown( + zIndex, + loopback, + conditions.down // + ); + + // + // Calculate Conditions ... + + // + bool isUpBullish = conditions.up[cIndex] > conditions.up[pIndex]; + bool isUpBearish = conditions.up[cIndex] < conditions.up[pIndex]; + + // + bool isUpBullishPrev = conditions.up[pIndex] > conditions.up[ppIndex]; + bool isUpBearishPrev = conditions.up[pIndex] < conditions.up[ppIndex]; + + // + bool isDownBullish = conditions.down[cIndex] > conditions.down[pIndex]; + bool isDownBearish = conditions.down[cIndex] < conditions.down[pIndex]; + + // + bool isDownBullishPrev = conditions.down[pIndex] > conditions.down[ppIndex]; + bool isDownBearishPrev = conditions.down[pIndex] < conditions.down[ppIndex]; + + // + bool isBullish = isUpBullish && + isDownBullish; + bool isBearish = isUpBearish && + isDownBearish; + + // + bool isBullishPrev = isUpBullishPrev && + isDownBullishPrev; + bool isBearishPrev = isUpBearishPrev && + isDownBearishPrev; + + // + bool isSwitchedToBullish = isBullish && + !isBullishPrev; + bool isSwitchedToBearish = isBearish && + !isBearishPrev; + + // + conditions.isBullish = isBullish; + conditions.isBearish = isBearish; + conditions.isUpBullish = isUpBullish; + conditions.isUpBearish = isUpBearish; + conditions.isDownBullish = isDownBullish; + conditions.isDownBearish = isDownBearish; + conditions.isSwitchedToBullish = isSwitchedToBullish; + conditions.isSwitchedToBearish = isSwitchedToBearish; + + // + return result; + } + // // Protected ... protected: diff --git a/Helpers/x-saherelm.xich.helper.mq5 b/Helpers/x-saherelm.xich.helper.mq5 index bb44a0dc..717ed6a6 100644 --- a/Helpers/x-saherelm.xich.helper.mq5 +++ b/Helpers/x-saherelm.xich.helper.mq5 @@ -190,6 +190,568 @@ struct XICHInputs } }; +// +// Define Conditions ... +struct XICHConditions +{ + // + // Common ... + string symbol; + ENUM_TIMEFRAMES period; + datetime time; + + // + // Buffers ... + double tenkanSen[]; + double kijunSen[]; + double chikouSpan[]; + double senkouSpanA[]; + double senkouSpanB[]; + double futureSenkouSpanA[]; + double futureSenkouSpanB[]; + + // + // Conditions ... + + // + bool isClosedOverKijunSen; + bool isClosedUnderKijunSen; + bool isTenkanSenOverKijunSen; + bool isTenkanSenUnderKijunSen; + bool isTenkanSenCrossedOverKijunSen; + bool isTenkanSenCrossedUnderKijunSen; + + // + bool isSenkouSpanAOverB; + bool isSenkouSpanAUnderB; + bool isSenkouSpanAOverLast; + bool isSenkouSpanAUnderLast; + bool isFutureSenkouSpanAOverB; + bool isFutureSenkouSpanAUnderB; + bool isFutureSenkouSpanAOverLast; + bool isFutureSenkouSpanAUnderLast; + + // + bool isSenkouSpanACrossedOverB; + bool isSenkouSpanACrossedUnderB; + bool isSenkouSpanACrossedOverLast; + bool isSenkouSpanACrossedUnderLast; + bool isFutureSenkouSpanACrossedOverB; + bool isFutureSenkouSpanACrossedUnderB; + bool isFutureSenkouSpanACrossedOverLast; + bool isFutureSenkouSpanACrossedUnderLast; + + // + void Clean() + { + // + Clean(tenkanSen); + Clean(kijunSen); + Clean(chikouSpan); + Clean(senkouSpanA); + Clean(senkouSpanB); + Clean(futureSenkouSpanA); + Clean(futureSenkouSpanB); + + // + ArraySetAsSeries(tenkanSen, true); + ArraySetAsSeries(kijunSen, true); + ArraySetAsSeries(chikouSpan, true); + ArraySetAsSeries(senkouSpanA, true); + ArraySetAsSeries(senkouSpanB, true); + ArraySetAsSeries(futureSenkouSpanA, true); + ArraySetAsSeries(futureSenkouSpanB, true); + + // + isClosedOverKijunSen = false; + isClosedUnderKijunSen = false; + isTenkanSenOverKijunSen = false; + isTenkanSenUnderKijunSen = false; + isTenkanSenCrossedOverKijunSen = false; + isTenkanSenCrossedUnderKijunSen = false; + + // + isSenkouSpanAOverB = false; + isSenkouSpanAUnderB = false; + isSenkouSpanAOverLast = false; + isSenkouSpanAUnderLast = false; + isFutureSenkouSpanAOverB = false; + isFutureSenkouSpanAUnderB = false; + isFutureSenkouSpanAOverLast = false; + isFutureSenkouSpanAUnderLast = false; + + // + isSenkouSpanACrossedOverB = false; + isSenkouSpanACrossedUnderB = false; + isSenkouSpanACrossedOverLast = false; + isSenkouSpanACrossedUnderLast = false; + isFutureSenkouSpanACrossedOverB = false; + isFutureSenkouSpanACrossedUnderB = false; + isFutureSenkouSpanACrossedOverLast = false; + isFutureSenkouSpanACrossedUnderLast = false; + } + + // + void GenerateScore( + double &bullishScore, + double &bearishScore // + ) + { + // + bullishScore = 0; + bearishScore = 0; + + // + if (isClosedOverKijunSen) + { + bullishScore++; + } + if (isTenkanSenOverKijunSen) + { + bullishScore++; + } + if (isTenkanSenCrossedOverKijunSen) + { + bullishScore++; + } + if (isSenkouSpanAOverB) + { + bullishScore++; + } + if (isSenkouSpanAOverLast) + { + bullishScore++; + } + if (isFutureSenkouSpanAOverB) + { + bullishScore++; + } + if (isFutureSenkouSpanAOverLast) + { + bullishScore++; + } + if (isSenkouSpanACrossedOverB) + { + bullishScore++; + } + if (isSenkouSpanACrossedOverLast) + { + bullishScore++; + } + if (isFutureSenkouSpanACrossedOverB) + { + bullishScore++; + } + if (isFutureSenkouSpanACrossedOverLast) + { + bullishScore++; + } + + // + if (isClosedUnderKijunSen) + { + bearishScore++; + } + if (isTenkanSenUnderKijunSen) + { + bearishScore++; + } + if (isTenkanSenCrossedUnderKijunSen) + { + bearishScore++; + } + if (isSenkouSpanAUnderB) + { + bearishScore++; + } + if (isSenkouSpanAUnderLast) + { + bearishScore++; + } + if (isFutureSenkouSpanAUnderB) + { + bearishScore++; + } + if (isFutureSenkouSpanAUnderLast) + { + bearishScore++; + } + if (isSenkouSpanACrossedUnderB) + { + bearishScore++; + } + if (isSenkouSpanACrossedUnderLast) + { + bearishScore++; + } + if (isFutureSenkouSpanACrossedUnderB) + { + bearishScore++; + } + if (isFutureSenkouSpanACrossedUnderLast) + { + bearishScore++; + } + } + + // + string GenerateSummary( + bool onlyCommons = false, + bool onlyConditions = false, + bool includeScores = true, + bool ignoreFalseConditions = true, + string separator = "\n" // + ) + { + // + string result = NULL; + + // + double bullishScore = 0; + double bearishScore = 0; + GenerateScore( + bullishScore, + bearishScore // + ); + + // + string scoresStr = + // + "Scores: " + separator + + "---------------" + separator + + "Bullish: " + ToString(bullishScore) + separator + + "Bearish: " + ToString(bearishScore) + separator + + "" + // + ; + + // + string commonStr = GenerateSpecifiedCommonSummary( + this, + separator, + includeScores // + ); + + // + string conditionsStr = + // + 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) + + "" + // + ; + + // + result = + // + "[" + GetTag() + "]" + separator + + (onlyConditions + ? "" + : commonStr) + + (!includeScores + ? "" + : scoresStr) + + " " + separator + + (onlyCommons + ? "" + : conditionsStr) + + "" + // + ; + + // + return result; + } + + // + string GetTag() + { + return "XICH"; + } + + // + bool HasLongConditions() + { + // + bool result; + + // + int zIndex = 0; + int cIndex = zIndex + 1; + int pIndex = cIndex + 1; + + // + XOHCL cBar; + result = cBar.Init( + symbol, + period, + cIndex // + ); + if (!result) + { + return result; + } + + // + XOHCL pBar; + result = pBar.Init( + symbol, + period, + pIndex // + ); + if (!result) + { + return result; + } + + // + bool isCloseOverSenkouSpanA = cBar.close > senkouSpanA[cIndex]; + + // + bool isBaseBullish = isCloseOverSenkouSpanA && + isSenkouSpanAOverB && + isSenkouSpanAOverLast; + + // + bool isKijunSenOverSenkouSpanA = kijunSen[cIndex] > senkouSpanA[cIndex]; + + // + bool isCloseOverTenkanSen = cBar.close > tenkanSen[cIndex]; + + // + bool isPriceCloseCrossedUpTenkanSen = pBar.close <= tenkanSen[pIndex] && + cBar.close > tenkanSen[cIndex]; + + // + double cKumoUpper = MathMax(senkouSpanA[cIndex], senkouSpanB[cIndex]); + double pKumoUpper = MathMax(senkouSpanA[pIndex], senkouSpanB[pIndex]); + + // + double cKumoLower = MathMin(senkouSpanA[cIndex], senkouSpanB[cIndex]); + double pKumoLower = MathMin(senkouSpanA[pIndex], senkouSpanB[pIndex]); + + // + bool isTenkanSenOverKumo = tenkanSen[cIndex] > cKumoUpper; + bool isTenkanSenOverKumoPrev = tenkanSen[pIndex] > pKumoUpper; + + // + bool isTenkanSenUnderKumo = tenkanSen[cIndex] < cKumoLower; + bool isTenkanSenUnderKumoPrev = tenkanSen[pIndex] < pKumoLower; + + // + bool isTenkanSenCrossedOverKumo = isTenkanSenOverKumo && + !isTenkanSenOverKumoPrev; + + // + bool isTenkanSenCrossedUnderKumo = isTenkanSenUnderKumo && + !isTenkanSenUnderKumoPrev; + + // + bool condition1 = + isBaseBullish && + isCloseOverTenkanSen && + isKijunSenOverSenkouSpanA && + isTenkanSenCrossedOverKijunSen; + + // + bool condition2 = + isBaseBullish && + isCloseOverTenkanSen && + isKijunSenOverSenkouSpanA && + isTenkanSenOverKijunSen && + isSenkouSpanACrossedOverB; + + // + bool condition3 = + isBaseBullish && + isKijunSenOverSenkouSpanA && + isPriceCloseCrossedUpTenkanSen && + isTenkanSenOverKijunSen; + + // + bool condition4 = + isCloseOverTenkanSen && + isTenkanSenCrossedOverKumo && + isTenkanSenOverKijunSen && + isFutureSenkouSpanAOverB && + isFutureSenkouSpanAOverLast; + + // + result = + // + condition1 + // + || + // + condition2 + // + || + // + condition3 + // + || + // + condition4 + // + ; + + // + return result; + } + + // + bool HasShortConditions() + { + // + bool result = false; + + // + int zIndex = 0; + int cIndex = zIndex + 1; + int pIndex = cIndex + 1; + + // + XOHCL cBar; + result = cBar.Init( + symbol, + period, + cIndex // + ); + if (!result) + { + return result; + } + + // + XOHCL pBar; + result = pBar.Init( + symbol, + period, + pIndex // + ); + if (!result) + { + return result; + } + + // + bool isCloseUnderSenkouSpanB = cBar.close < senkouSpanB[cIndex]; + + // + bool isBaseBearish = isCloseUnderSenkouSpanB && + isSenkouSpanAUnderB && + isSenkouSpanAUnderLast; + + // + bool isKijunSenUnderSenkouSpanB = kijunSen[cIndex] < senkouSpanB[cIndex]; + + // + bool isCloseUnderTenkanSen = cBar.close < tenkanSen[cIndex]; + + // + bool isPriceCloseCrossedDownTenkanSen = pBar.close >= tenkanSen[pIndex] && + cBar.close < tenkanSen[cIndex]; + + // + double cKumoUpper = MathMax(senkouSpanA[cIndex], senkouSpanB[cIndex]); + double pKumoUpper = MathMax(senkouSpanA[pIndex], senkouSpanB[pIndex]); + + // + double cKumoLower = MathMin(senkouSpanA[cIndex], senkouSpanB[cIndex]); + double pKumoLower = MathMin(senkouSpanA[pIndex], senkouSpanB[pIndex]); + + // + bool isTenkanSenOverKumo = tenkanSen[cIndex] > cKumoUpper; + bool isTenkanSenOverKumoPrev = tenkanSen[pIndex] > pKumoUpper; + + // + bool isTenkanSenUnderKumo = tenkanSen[cIndex] < cKumoLower; + bool isTenkanSenUnderKumoPrev = tenkanSen[pIndex] < pKumoLower; + + // + bool isTenkanSenCrossedOverKumo = isTenkanSenOverKumo && + !isTenkanSenOverKumoPrev; + + // + bool isTenkanSenCrossedUnderKumo = isTenkanSenUnderKumo && + !isTenkanSenUnderKumoPrev; + + // + bool condition1 = + isBaseBearish && + isCloseUnderTenkanSen && + isKijunSenUnderSenkouSpanB && + isTenkanSenCrossedUnderKijunSen; + + // + bool condition2 = + isBaseBearish && + isCloseUnderTenkanSen && + isKijunSenUnderSenkouSpanB && + isTenkanSenUnderKijunSen && + isSenkouSpanACrossedUnderB; + + // + bool condition3 = + isBaseBearish && + isKijunSenUnderSenkouSpanB && + isPriceCloseCrossedDownTenkanSen && + isTenkanSenUnderKijunSen; + + // + bool condition4 = + isCloseUnderTenkanSen && + isTenkanSenCrossedUnderKumo && + isTenkanSenUnderKijunSen && + isFutureSenkouSpanAUnderB && + isFutureSenkouSpanAUnderLast; + + // + result = + // + condition1 + + || + // + condition2 + // + || + // + condition3 + // + || + // + condition4 + // + ; + + // + return result; + } +}; + // // Class ... class XSCXICHHelper : public XSCBaseHelper @@ -703,6 +1265,190 @@ public: ); } + // + bool GetConditions( + XICHConditions &conditions, // + int barIndex = 0, // + int loopback = 4 // + ) + { + // + bool result = true; + + // + if (loopback < 4) + { + loopback = 4; + } + + // + conditions.Clean(); + + // + conditions.symbol = mSymbol; + conditions.period = mPeriod; + conditions.time = TimeCurrent(); + + // + int zIndex = barIndex; + int cIndex = zIndex + 1; + int pIndex = cIndex + 1; + int ppIndex = pIndex + 1; + + // + CopyTenkanSen( + zIndex, + loopback, + conditions.tenkanSen // + ); + CopyKijunSen( + zIndex, + loopback, + conditions.kijunSen // + ); + CopyChikouSpan( + zIndex, + loopback, + conditions.chikouSpan // + ); + CopySenkouSpanA( + zIndex, + loopback, + conditions.senkouSpanA // + ); + CopySenkouSpanB( + zIndex, + loopback, + conditions.senkouSpanB // + ); + CopyFutureSenkouSpanA( + zIndex, + loopback, + conditions.futureSenkouSpanA // + ); + CopyFutureSenkouSpanB( + zIndex, + loopback, + conditions.futureSenkouSpanB // + ); + + // + // Calculate Conditions ... + + // + XOHCL cBar; + result = cBar.Init( + _Symbol, + _Period, + cIndex // + ); + if (!result) + { + return result; + } + + // + bool isClosedOverKijunSen = cBar.close > conditions.kijunSen[cIndex]; + bool isClosedUnderKijunSen = cBar.close < conditions.kijunSen[cIndex]; + + // + bool isTenkanSenOverKijunSen = conditions.tenkanSen[cIndex] > conditions.kijunSen[cIndex]; + bool isTenkanSenUnderKijunSen = conditions.tenkanSen[cIndex] < conditions.kijunSen[cIndex]; + + // + bool isTenkanSenOverKijunSenPrev = conditions.tenkanSen[pIndex] > conditions.kijunSen[pIndex]; + bool isTenkanSenUnderKijunSenPrev = conditions.tenkanSen[pIndex] < conditions.kijunSen[pIndex]; + + // + bool isTenkanSenCrossedOverKijunSen = isTenkanSenOverKijunSen && + !isTenkanSenOverKijunSenPrev; + bool isTenkanSenCrossedUnderKijunSen = isTenkanSenUnderKijunSen && + !isTenkanSenUnderKijunSenPrev; + + // + bool isSenkouSpanAOverB = conditions.senkouSpanA[cIndex] > conditions.senkouSpanB[cIndex]; + bool isSenkouSpanAUnderB = conditions.senkouSpanA[cIndex] < conditions.senkouSpanB[cIndex]; + + // + bool isSenkouSpanAOverBPrev = conditions.senkouSpanA[pIndex] > conditions.senkouSpanB[pIndex]; + bool isSenkouSpanAUnderBPrev = conditions.senkouSpanA[pIndex] < conditions.senkouSpanB[pIndex]; + + // + bool isSenkouSpanAOverLast = conditions.senkouSpanA[cIndex] > conditions.senkouSpanA[pIndex]; + bool isSenkouSpanAUnderLast = conditions.senkouSpanA[cIndex] < conditions.senkouSpanA[pIndex]; + + // + bool isSenkouSpanAOverLastPrev = conditions.senkouSpanA[pIndex] > conditions.senkouSpanA[ppIndex]; + bool isSenkouSpanAUnderLastPrev = conditions.senkouSpanA[pIndex] < conditions.senkouSpanA[ppIndex]; + + // + bool isFutureSenkouSpanAOverB = conditions.futureSenkouSpanA[cIndex] > conditions.futureSenkouSpanB[cIndex]; + bool isFutureSenkouSpanAUnderB = conditions.futureSenkouSpanA[cIndex] < conditions.futureSenkouSpanB[cIndex]; + + // + bool isFutureSenkouSpanAOverBPrev = conditions.futureSenkouSpanA[pIndex] > conditions.futureSenkouSpanB[pIndex]; + bool isFutureSenkouSpanAUnderBPrev = conditions.futureSenkouSpanA[pIndex] < conditions.futureSenkouSpanB[pIndex]; + + // + bool isFutureSenkouSpanAOverLast = conditions.futureSenkouSpanA[cIndex] > conditions.futureSenkouSpanA[pIndex]; + bool isFutureSenkouSpanAUnderLast = conditions.futureSenkouSpanA[cIndex] < conditions.futureSenkouSpanA[pIndex]; + + // + bool isFutureSenkouSpanAOverLastPrev = conditions.futureSenkouSpanA[pIndex] > conditions.futureSenkouSpanA[ppIndex]; + bool isFutureSenkouSpanAUnderLastPrev = conditions.futureSenkouSpanA[pIndex] < conditions.futureSenkouSpanA[ppIndex]; + + // + bool isSenkouSpanACrossedOverB = isSenkouSpanAOverB && + !isSenkouSpanAOverBPrev; + bool isSenkouSpanACrossedUnderB = isSenkouSpanAUnderB && + !isSenkouSpanAUnderBPrev; + + // + bool isSenkouSpanACrossedOverLast = isSenkouSpanAOverLast & + !isSenkouSpanAOverLastPrev; + bool isSenkouSpanACrossedUnderLast = isSenkouSpanAUnderLast && + !isSenkouSpanAUnderLastPrev; + + // + bool isFutureSenkouSpanACrossedOverB = isFutureSenkouSpanAOverB && + !isFutureSenkouSpanAOverBPrev; + bool isFutureSenkouSpanACrossedUnderB = isFutureSenkouSpanAUnderB && + !isFutureSenkouSpanAUnderBPrev; + + // + bool isFutureSenkouSpanACrossedOverLast = isFutureSenkouSpanAOverLast && + !isFutureSenkouSpanAOverLastPrev; + bool isFutureSenkouSpanACrossedUnderLast = isFutureSenkouSpanAUnderLast && + !isFutureSenkouSpanAUnderLastPrev; + + // + conditions.isClosedOverKijunSen = isClosedOverKijunSen; + conditions.isClosedUnderKijunSen = isClosedUnderKijunSen; + conditions.isTenkanSenOverKijunSen = isTenkanSenOverKijunSen; + conditions.isTenkanSenUnderKijunSen = isTenkanSenUnderKijunSen; + conditions.isTenkanSenCrossedOverKijunSen = isTenkanSenCrossedOverKijunSen; + conditions.isTenkanSenCrossedUnderKijunSen = isTenkanSenCrossedUnderKijunSen; + conditions.isSenkouSpanAOverB = isSenkouSpanAOverB; + conditions.isSenkouSpanAUnderB = isSenkouSpanAUnderB; + conditions.isSenkouSpanAOverLast = isSenkouSpanAOverLast; + conditions.isSenkouSpanAUnderLast = isSenkouSpanAUnderLast; + conditions.isFutureSenkouSpanAOverB = isFutureSenkouSpanAOverB; + conditions.isFutureSenkouSpanAUnderB = isFutureSenkouSpanAUnderB; + conditions.isFutureSenkouSpanAOverLast = isFutureSenkouSpanAOverLast; + conditions.isFutureSenkouSpanAUnderLast = isFutureSenkouSpanAUnderLast; + conditions.isSenkouSpanACrossedOverB = isSenkouSpanACrossedOverB; + conditions.isSenkouSpanACrossedUnderB = isSenkouSpanACrossedUnderB; + conditions.isSenkouSpanACrossedOverLast = isSenkouSpanACrossedOverLast; + conditions.isSenkouSpanACrossedUnderLast = isSenkouSpanACrossedUnderLast; + conditions.isFutureSenkouSpanACrossedOverB = isFutureSenkouSpanACrossedOverB; + conditions.isFutureSenkouSpanACrossedUnderB = isFutureSenkouSpanACrossedUnderB; + conditions.isFutureSenkouSpanACrossedOverLast = isFutureSenkouSpanACrossedOverLast; + conditions.isFutureSenkouSpanACrossedUnderLast = isFutureSenkouSpanACrossedUnderLast; + + // + return result; + } + // // Protected ... protected: diff --git a/Helpers/x-saherelm.xmatd.helper.mq5 b/Helpers/x-saherelm.xmatd.helper.mq5 new file mode 100644 index 00000000..ddb4be78 --- /dev/null +++ b/Helpers/x-saherelm.xmatd.helper.mq5 @@ -0,0 +1,1046 @@ +/////////////////////////////////////////////////////// +// +// SaherElm IT Center MQL5 Class Library +// ---------------------------------------------- +// Name: XMATD +// Description: provides Indicator implementation +// requirements ... +// +// +// Maintainer: +// ------------ +// Hadi Khazaee Asl (hadi_khazaee_asl@yahoo.com) +// +////////////////////////////////////////////////////// +// +// Global Properties ... +#property library +#property copyright "Copyright 2023, SaherElm IT Center" +#property link "https://www.saherelm.ir" +#property version "1.00" +#property strict + +// +// Imports ... +#include "../Classes/x-saherelm.base.class.mq5" + +// +// Indicator Buffers ... +enum ENUM_XMATD_BUFFERS +{ + XMATD_FAST_LINE = 0, // Fast Buffer ... + XMATD_MID_LINE = 1, // Mid Buffer ... + XMATD_SLOW_LINE = 2, // Slow Buffer ... + XMATD_PSAR_LINE = 3, // Parabolic Buffer ... +}; + +// +string GetTitle(ENUM_XMATD_BUFFERS bufferLine) +{ + // + string result = NULL; + + // + switch (bufferLine) + { + // + case XMATD_FAST_LINE: + result = "XFats"; + break; + + // + case XMATD_MID_LINE: + result = "XMid"; + break; + + // + case XMATD_SLOW_LINE: + result = "XSlow"; + break; + } + + // + return result; +} + +// +// XMATD Indicator Inputs ... +struct XMATDInputs +{ + // + // Props ... + string version; + + // + // Market ... + + // + int fastLength; // Fast Length + int midLength; // Mid Length + int slowLength; // Slow Length + + // + double step; // Sar Step + double maximum; // Sar Maximum + + // + // Calculation Mode ... + + // + int shift; // Shift + ENUM_MA_METHOD method; // Method of MA + ENUM_APPLIED_PRICE appliedTo; // Applied To + + // + // Constructor ... + XMATDInputs() + { + Clean(); + } + + // + // Tools ... + + // + // Initial Inputs ... + bool Init( + int _fastLength = 21, // Fast Length + int _midLength = 50, // Mid Length + int _slowLength = 200, // Slow Length + ENUM_MA_METHOD _method = MODE_SMA, // Shift + ENUM_APPLIED_PRICE _appliedTo = PRICE_CLOSE, // Method of MA + int _shift = 0 // Applied To + ) + { + // + bool result = false; + + // + this.fastLength = _fastLength; + this.midLength = _midLength; + this.slowLength = _slowLength; + + // + this.shift = _shift; + this.method = _method; + this.appliedTo = _appliedTo; + + // + result = IsValid(); + + // + return result; + } + + // + // Cleanup ... + void Clean() + { + // + fastLength = 0; + midLength = 0; + slowLength = 0; + + // + shift = 0; + + // + step = 0; + maximum = 0; + + // + method = MODE_SMA; + appliedTo = PRICE_CLOSE; + } + + // + // Default ... + void Default() + { + // + fastLength = 21; + midLength = 50; + slowLength = 200; + + // + method = MODE_SMA; + appliedTo = PRICE_CLOSE; + + // + step = 0.02; + maximum = 0.2; + } + + // + // Validate ... + bool IsValid() + { + // + bool result = false; + + // + result = + // + fastLength > 0 && + midLength > fastLength && + slowLength > midLength + // + && + // + step > 0 && + maximum > step + // + ; + + // + return result; + } + + // + // Retrieve Max Length ... + int Max() + { + // + int result = 0; + + // + int values[3] = { + fastLength, + midLength, + slowLength // + }; + + // + result = GetMax(values); + + // + return result; + } +}; + +// +// Define Conditions ... +struct XMATDConditions +{ + // + // Common ... + string symbol; + ENUM_TIMEFRAMES period; + datetime time; + + // + // Buffers ... + double fast[]; + double mid[]; + double slow[]; + + // + double psar[]; + + // + // Conditions ... + + // + // Trend ... + bool isBullish; + bool isBearish; + bool isSwitchedToBullish; + bool isSwitchedToBearish; + + // + // Fast Mid ... + bool isFastOverMid; + bool isFastUnderMid; + bool isFastCrossedOverMid; + bool isFastCrossedUnderMid; + + // + // Fast Slow ... + bool isFastOverSlow; + bool isFastUnderSlow; + bool isFastCrossedOverSlow; + bool isFastCrossedUnderSlow; + + // + // Mid Slow ... + bool isMidOverSlow; + bool isMidUnderSlow; + bool isMidCrossedOverSlow; + bool isMidCrossedUnderSlow; + + // + bool isSARBullish; + bool isSARBearish; + bool isSARSwitchedToBullish; + bool isSARSwitchedToBearish; + + // + void Clean() + { + // + Clean(fast); + Clean(mid); + Clean(slow); + Clean(psar); + + // + ArraySetAsSeries(fast, true); + ArraySetAsSeries(mid, true); + ArraySetAsSeries(slow, true); + ArraySetAsSeries(psar, true); + + // + // Trend ... + isBullish = false; + isBearish = false; + isSwitchedToBullish = false; + isSwitchedToBearish = false; + + // + // Fast Mid ... + isFastOverMid = false; + isFastUnderMid = false; + isFastCrossedOverMid = false; + isFastCrossedUnderMid = false; + + // + // Fast Slow ... + isFastOverSlow = false; + isFastUnderSlow = false; + isFastCrossedOverSlow = false; + isFastCrossedUnderSlow = false; + + // + // Mid Slow ... + isMidOverSlow = false; + isMidUnderSlow = false; + isMidCrossedOverSlow = false; + isMidCrossedUnderSlow = false; + + // + isSARBullish = false; + isSARBearish = false; + isSARSwitchedToBullish = false; + isSARSwitchedToBearish = false; + } + + // + void GenerateScore( + double &bullishScore, + double &bearishScore // + ) + { + // + bullishScore = 0; + bearishScore = 0; + + // + // Trend ... + + // + if (isBullish) + { + bullishScore++; + } + if (isSwitchedToBullish) + { + bullishScore++; + } + + // + if (isBearish) + { + bearishScore++; + } + if (isSwitchedToBearish) + { + bearishScore++; + } + + // + // Fast Mid ... + + // + if (isFastOverMid) + { + bullishScore++; + } + if (isFastCrossedOverMid) + { + bullishScore++; + } + + // + if (isFastUnderMid) + { + bearishScore++; + } + if (isFastCrossedUnderMid) + { + bearishScore++; + } + + // + // Fast Slow ... + + // + if (isFastOverSlow) + { + bullishScore++; + } + if (isFastCrossedOverSlow) + { + bullishScore++; + } + + // + if (isFastUnderSlow) + { + bearishScore++; + } + if (isFastCrossedUnderSlow) + { + bearishScore++; + } + + // + // Mid Slow ... + + // + if (isMidOverSlow) + { + bullishScore++; + } + if (isMidCrossedOverSlow) + { + bullishScore++; + } + + // + if (isMidUnderSlow) + { + bearishScore++; + } + if (isMidCrossedUnderSlow) + { + bearishScore++; + } + + // + if (isSARBullish) + { + bullishScore++; + } + if (isSARSwitchedToBullish) + { + bullishScore++; + } + + // + if (isSARBearish) + { + bearishScore++; + } + if (isSARSwitchedToBearish) + { + bearishScore++; + } + } + + // + string GenerateSummary( + bool onlyCommons = false, + bool onlyConditions = false, + bool includeScores = true, + bool ignoreFalseConditions = true, + string separator = "\n" // + ) + { + // + string result = NULL; + + // + double bullishScore = 0; + double bearishScore = 0; + GenerateScore( + bullishScore, + bearishScore // + ); + + // + string scoresStr = + // + "Scores: " + separator + + "---------------" + separator + + "Bullish: " + ToString(bullishScore) + separator + + "Bearish: " + ToString(bearishScore) + separator + + "" + // + ; + + // + string commonStr = GenerateSpecifiedCommonSummary( + this, + separator, + includeScores // + ); + + // + string conditionsStr = + // + // Trend ... + ToString("isBullish", isBullish, ignoreFalseConditions, separator) + + ToString("isBearish", isBearish, ignoreFalseConditions, separator) + + ToString("isSwitchedToBullish", isSwitchedToBullish, ignoreFalseConditions, separator) + + ToString("isSwitchedToBearish", isSwitchedToBearish, ignoreFalseConditions, separator) + + // + // Fast Mid ... + ToString("isFastOverMid", isFastOverMid, ignoreFalseConditions, separator) + + ToString("isFastUnderMid", isFastUnderMid, ignoreFalseConditions, separator) + + ToString("isFastCrossedOverMid", isFastCrossedOverMid, ignoreFalseConditions, separator) + + ToString("isFastCrossedUnderMid", isFastCrossedUnderMid, ignoreFalseConditions, separator) + + // + // Fast Slow ... + ToString("isFastOverSlow", isFastOverSlow, ignoreFalseConditions, separator) + + ToString("isFastUnderSlow", isFastUnderSlow, ignoreFalseConditions, separator) + + ToString("isFastCrossedOverSlow", isFastCrossedOverSlow, ignoreFalseConditions, separator) + + ToString("isFastCrossedUnderSlow", isFastCrossedUnderSlow, ignoreFalseConditions, separator) + + // + // Mid Slow ... + ToString("isMidOverSlow", isMidOverSlow, ignoreFalseConditions, separator) + + ToString("isMidUnderSlow", isMidUnderSlow, ignoreFalseConditions, separator) + + ToString("isMidCrossedOverSlow", isMidCrossedOverSlow, ignoreFalseConditions, separator) + + ToString("isMidCrossedUnderSlow", isMidCrossedUnderSlow, ignoreFalseConditions, separator) + + // + // Psar ... + ToString("isSARBullish", isSARBullish, ignoreFalseConditions, separator) + + ToString("isSARBearish", isSARBearish, ignoreFalseConditions, separator) + + ToString("isSARSwitchedToBullish", isSARSwitchedToBullish, ignoreFalseConditions, separator) + + ToString("isSARSwitchedToBearish", isSARSwitchedToBearish, ignoreFalseConditions, separator) + + // + "" + // + ; + + // + result = + // + "[" + GetTag() + "]" + separator + + (onlyConditions + ? "" + : commonStr) + + (!includeScores + ? "" + : scoresStr) + + " " + separator + + (onlyCommons + ? "" + : conditionsStr) + + "" + // + ; + + // + return result; + } + + // + string GetTag() + { + return "XMATD"; + } +}; + +// +// Indicator Class ... + +class XSCXMATDHelper : public XSCBase +{ + // + // Public ... +public: + // + // Props ... + + // + // Constructor(s) ... + void XSCXMATDHelper( + string symbol, // Trading Symbol + ENUM_TIMEFRAMES period // Trading TimeFrame + ) + { + // + mSymbol = symbol; + mPeriod = period; + } + + // + // Deconstructor ... + void ~XSCXMATDHelper() {} + + // + // Initialize Indicator ... + bool Init( + XMATDInputs &inputs // Indicator Properties + ) + { + // + bool result = false; + + // + result = inputs.IsValid(); + if (!result) + { + return result; + } + + // + // Set Inputs ... + this.mInputs = inputs; + + // + // Validate Indicator State ... + result = this.IsValid(); + if (!result) + { + return result; + } + + // + result = DefineBuffers(); + if (!result) + { + return result; + } + + // + fastHandler = iMA( + mSymbol, + mPeriod, + mInputs.fastLength, + mInputs.shift, + mInputs.method, + mInputs.appliedTo // + ); + midHandler = iMA( + mSymbol, + mPeriod, + mInputs.midLength, + mInputs.shift, + mInputs.method, + mInputs.appliedTo // + ); + slowHandler = iMA( + mSymbol, + mPeriod, + mInputs.slowLength, + mInputs.shift, + mInputs.method, + mInputs.appliedTo // + ); + result = + // + fastHandler != INVALID_HANDLE && + midHandler != INVALID_HANDLE && + slowHandler != INVALID_HANDLE + // + ; + if (!result) + { + return result; + } + + // + sarHandler = iSAR( + _Symbol, + _Period, + mInputs.step, + mInputs.maximum // + ); + result = sarHandler != INVALID_HANDLE; + + // + return result; + } + + // + XMATDInputs GetInputs() + { + return mInputs; + } + + // + bool SetInputs( + XMATDInputs &inputs // Indicator Properties + ) + { + return Init(inputs); + } + + // + // Get Tag ... + string GetTag() + { + // + string result = NULL; + + // + result = GetToken(); + + // + return result; + } + + // + // Get Token ... + string GetToken() + { + // + string result = NULL; + + // + result = GetSpecificToken(this); + + // + return result; + } + + // + string GetSymbol() + { + return mSymbol; + } + + // + ENUM_TIMEFRAMES GetPeriod() + { + return mPeriod; + } + + // + // Validate ... + bool IsValid() + { + // + bool result = false; + + // + result = + // + mInputs.IsValid() && + IsSpecifiedValid(mPeriod) && + IsSpecifiedValid(mSymbol) + // + ; + + // + return result; + } + + // + // De Initialize Class ... + void DeInit(int reason) + { + // + IndicatorRelease(fastHandler); + IndicatorRelease(midHandler); + IndicatorRelease(slowHandler); + } + + // + // Tools ... + int CopyData( + ENUM_XMATD_BUFFERS line, + double &dest[], + int start = 0, + int count = 1 // + ) + { + // + int result = 0; + + // + int mHandler = INVALID_HANDLE; + switch (line) + { + // + case XMATD_FAST_LINE: + mHandler = fastHandler; + break; + + // + case XMATD_MID_LINE: + mHandler = midHandler; + break; + + // + case XMATD_SLOW_LINE: + mHandler = slowHandler; + break; + + // + case XMATD_PSAR_LINE: + mHandler = sarHandler; + break; + } + + // + if (mHandler == INVALID_HANDLE) + { + return result; + } + + // + result = CopyBuffer( + mHandler, + 0, + start, + count, + dest // + ); + + // + return result; + } + + // + bool GetConditions( + XMATDConditions &conditions, // + int barIndex = 0, // + int loopback = 3 // + ) + { + // + bool result = true; + + // + if (loopback < 3) + { + loopback = 3; + } + + // + conditions.Clean(); + + // + conditions.symbol = mSymbol; + conditions.period = mPeriod; + conditions.time = TimeCurrent(); + + // + int zIndex = barIndex; + int cIndex = zIndex + 1; + int pIndex = cIndex + 1; + int ppIndex = pIndex + 1; + + // + CopyData( + XMATD_FAST_LINE, + conditions.fast, + zIndex, + loopback // + ); + CopyData( + XMATD_MID_LINE, + conditions.mid, + zIndex, + loopback // + ); + CopyData( + XMATD_SLOW_LINE, + conditions.slow, + zIndex, + loopback // + ); + + // + // Calculate Conditions ... + + // + // Trend ... + + // + bool isBullish = conditions.fast[cIndex] > conditions.mid[cIndex] && + conditions.mid[cIndex] > conditions.slow[cIndex]; + bool isBearish = conditions.fast[cIndex] < conditions.mid[cIndex] && + conditions.mid[cIndex] < conditions.slow[cIndex]; + + // + bool isBullishPrev = conditions.fast[pIndex] > conditions.mid[pIndex] && + conditions.mid[pIndex] > conditions.slow[pIndex]; + bool isBearishPrev = conditions.fast[pIndex] < conditions.mid[pIndex] && + conditions.mid[pIndex] < conditions.slow[pIndex]; + + // + bool isSwitchedToBullish = isBullish && + !isBullishPrev; + bool isSwitchedToBearish = isBearish && + !isBearishPrev; + + // + // Set Conditions to Structure ... + conditions.isBullish = isBullish; + conditions.isBearish = isBearish; + conditions.isSwitchedToBullish = isSwitchedToBullish; + conditions.isSwitchedToBearish = isSwitchedToBearish; + + // + // Fast Mid ... + + // + bool isFastOverMid = conditions.fast[cIndex] > conditions.mid[cIndex]; + bool isFastUnderMid = conditions.fast[cIndex] < conditions.mid[cIndex]; + + // + bool isFastOverMidPrev = conditions.fast[pIndex] > conditions.mid[pIndex]; + bool isFastUnderMidPrev = conditions.fast[pIndex] < conditions.mid[pIndex]; + + // + bool isFastCrossedOverMid = isFastOverMid && + !isFastOverMidPrev; + bool isFastCrossedUnderMid = isFastUnderMid && + !isFastUnderMidPrev; + + // + conditions.isFastOverMid = isFastOverMid; + conditions.isFastUnderMid = isFastUnderMid; + conditions.isFastCrossedOverMid = isFastCrossedOverMid; + conditions.isFastCrossedUnderMid = isFastCrossedUnderMid; + + // + // Fast Slow ... + + // + bool isFastOverSlow = conditions.fast[cIndex] > conditions.slow[cIndex]; + bool isFastUnderSlow = conditions.fast[cIndex] < conditions.slow[cIndex]; + + // + bool isFastOverSlowPrev = conditions.fast[pIndex] > conditions.slow[pIndex]; + bool isFastUnderSlowPrev = conditions.fast[pIndex] < conditions.slow[pIndex]; + + // + bool isFastCrossedOverSlow = isFastOverSlow && + !isFastOverSlowPrev; + bool isFastCrossedUnderSlow = isFastUnderSlow && + !isFastUnderSlowPrev; + + // + conditions.isFastOverSlow = isFastOverSlow; + conditions.isFastUnderSlow = isFastUnderSlow; + conditions.isFastCrossedOverSlow = isFastCrossedOverSlow; + conditions.isFastCrossedUnderSlow = isFastCrossedUnderSlow; + + // + // Mid Slow ... + + // + bool isMidOverSlow = conditions.mid[cIndex] > conditions.slow[cIndex]; + bool isMidUnderSlow = conditions.mid[cIndex] < conditions.slow[cIndex]; + + // + bool isMidOverSlowPrev = conditions.mid[pIndex] > conditions.slow[pIndex]; + bool isMidUnderSlowPrev = conditions.mid[pIndex] < conditions.slow[pIndex]; + + // + bool isMidCrossedOverSlow = isMidOverSlow && + !isMidOverSlowPrev; + bool isMidCrossedUnderSlow = isMidUnderSlow && + !isMidUnderSlowPrev; + + // + conditions.isMidOverSlow = isMidOverSlow; + conditions.isMidUnderSlow = isMidUnderSlow; + conditions.isMidCrossedOverSlow = isMidCrossedOverSlow; + conditions.isMidCrossedUnderSlow = isMidCrossedUnderSlow; + + // + // PSar ... + + // + CopyData( + XMATD_PSAR_LINE, + conditions.psar, + zIndex, + loopback // + ); + + // + XOHCL cBar; + cBar.Init( + mSymbol, + mPeriod, + cIndex // + ); + + // + XOHCL pBar; + pBar.Init( + mSymbol, + mPeriod, + pIndex // + ); + + // + bool isSARBullish = conditions.psar[cIndex] < cBar.low; + bool isSARBearish = conditions.psar[cIndex] > cBar.high; + + // + bool isSARBullishPrev = conditions.psar[pIndex] < pBar.low; + bool isSARBearishPrev = conditions.psar[pIndex] > pBar.high; + + // + bool isSARSwitchedToBullish = isSARBullish && + !isSARBullishPrev; + bool isSARSwitchedToBearish = isSARBearish && + !isSARBearishPrev; + + // + conditions.isSARBullish = isSARBullish; + conditions.isSARBearish = isSARBearish; + conditions.isSARSwitchedToBullish = isSARSwitchedToBullish; + conditions.isSARSwitchedToBearish = isSARSwitchedToBearish; + + // + return result; + } + + // + // Protected ... +protected: + // + // Props ... + int fastHandler; + int midHandler; + int slowHandler; + + // + int sarHandler; + + // + // Tools ... + bool DefineBuffers() + { + // + bool result = false; + + // + result = true; + + // + return result; + } + + // + // Private ... +private: + // + // Props ... + // + string mSymbol; // Symbol + ENUM_TIMEFRAMES mPeriod; // TimeFrame + + // + XMATDInputs mInputs; // Properties +}; + +// \ No newline at end of file diff --git a/Helpers/x-saherelm.xmrb.helper.mq5 b/Helpers/x-saherelm.xmrb.helper.mq5 index 78addb88..ccd73324 100644 --- a/Helpers/x-saherelm.xmrb.helper.mq5 +++ b/Helpers/x-saherelm.xmrb.helper.mq5 @@ -284,6 +284,159 @@ struct XMRBInputs } }; +// +// Define Conditions ... +struct XMRBConditions +{ + // + // Common ... + string symbol; + ENUM_TIMEFRAMES period; + datetime time; + + // + // Buffers ... + + // + double fast[]; + double slow[]; + + // + // Conditions ... + + // + bool isFastOverSlow; + bool isFastUnderSlow; + bool isFastCrossedOverSlow; + bool isFastCrossedUnderSlow; + + // + void Clean() + { + // + Clean(fast); + Clean(slow); + + // + ArraySetAsSeries(fast, true); + ArraySetAsSeries(slow, true); + + // + isFastOverSlow = false; + isFastUnderSlow = false; + isFastCrossedOverSlow = false; + isFastCrossedUnderSlow = false; + } + + // + void GenerateScore( + double &bullishScore, + double &bearishScore // + ) + { + // + bullishScore = 0; + bearishScore = 0; + + // + if (isFastOverSlow) + { + bullishScore++; + } + if (isFastCrossedOverSlow) + { + bullishScore++; + } + + // + if (isFastUnderSlow) + { + bearishScore++; + } + if (isFastCrossedUnderSlow) + { + bearishScore++; + } + } + + // + string GenerateSummary( + bool onlyCommons = false, + bool onlyConditions = false, + bool includeScores = true, + bool ignoreFalseConditions = true, + string separator = "\n" // + ) + { + // + string result = NULL; + + // + double bullishScore = 0; + double bearishScore = 0; + GenerateScore( + bullishScore, + bearishScore // + ); + + // + string scoresStr = + // + "Scores: " + separator + + "---------------" + separator + + "Bullish: " + ToString(bullishScore) + separator + + "Bearish: " + ToString(bearishScore) + separator + + "" + // + ; + + // + string commonStr = GenerateSpecifiedCommonSummary( + this, + separator, + includeScores // + ); + + // + string conditionsStr = + // + ToString("isFastOverSlow", isFastOverSlow, ignoreFalseConditions, separator) + + ToString("isFastUnderSlow", isFastUnderSlow, ignoreFalseConditions, separator) + + ToString("isFastCrossedOverSlow", isFastCrossedOverSlow, ignoreFalseConditions, separator) + + ToString("isFastCrossedUnderSlow", isFastCrossedUnderSlow, ignoreFalseConditions, separator) + + "" + // + ; + + // + result = + // + "[" + GetTag() + "]" + separator + + (onlyConditions + ? "" + : commonStr) + + (!includeScores + ? "" + : scoresStr) + + " " + separator + + (onlyCommons + ? "" + : conditionsStr) + + "" + // + ; + + // + return result; + } + + // + string GetTag() + { + return "XMRB"; + } +}; + // // Class ... class XSCXMRBHelper : public XSCBaseHelper @@ -1196,6 +1349,74 @@ public: ); } + // + bool GetConditions( + XMRBConditions &conditions, // + int barIndex = 0, // + int loopback = 3 // + ) + { + // + bool result = true; + + // + if (loopback < 3) + { + loopback = 3; + } + + // + conditions.Clean(); + + // + conditions.symbol = mSymbol; + conditions.period = mPeriod; + conditions.time = TimeCurrent(); + + // + int zIndex = barIndex; + int cIndex = zIndex + 1; + int pIndex = cIndex + 1; + int ppIndex = pIndex + 1; + + // + CopyFast( + zIndex, + loopback, + conditions.fast // + ); + CopySlow( + zIndex, + loopback, + conditions.slow // + ); + + // + // Calculate Conditions ... + + // + bool isFastOverSlow = conditions.fast[cIndex] > conditions.slow[cIndex]; + bool isFastUnderSlow = conditions.fast[cIndex] < conditions.slow[cIndex]; + + // + bool isFastOverSlowPrev = conditions.fast[pIndex] > conditions.slow[pIndex]; + bool isFastUnderSlowPrev = conditions.fast[pIndex] < conditions.slow[pIndex]; + + // + bool isFastCrossedOverSlow = isFastOverSlow && + !isFastOverSlowPrev; + bool isFastCrossedUnderSlow = isFastUnderSlow && + !isFastUnderSlowPrev; + + // + conditions.isFastOverSlow = isFastOverSlow; + conditions.isFastUnderSlow = isFastUnderSlow; + conditions.isFastCrossedOverSlow = isFastCrossedOverSlow; + conditions.isFastCrossedUnderSlow = isFastCrossedUnderSlow; + // + return result; + } + // // Protected ... protected: diff --git a/Helpers/x-saherelm.xsslc.helper.mq5 b/Helpers/x-saherelm.xsslc.helper.mq5 index f5cb7b4b..31b51244 100644 --- a/Helpers/x-saherelm.xsslc.helper.mq5 +++ b/Helpers/x-saherelm.xsslc.helper.mq5 @@ -140,6 +140,157 @@ struct XSSLCInputs } }; +// +// Define Conditions ... +struct XSSLCConditions +{ + // + // Common ... + string symbol; + ENUM_TIMEFRAMES period; + datetime time; + + // + // Buffers ... + double up[]; + double down[]; + + // + // Conditions ... + + // + bool isBullish; + bool isBearish; + bool isSwitchedToBullish; + bool isSwitchedToBearish; + + // + void Clean() + { + // + Clean(up); + Clean(down); + + // + ArraySetAsSeries(up, true); + ArraySetAsSeries(down, true); + + // + isBullish = false; + isBearish = false; + isSwitchedToBullish = false; + isSwitchedToBearish = false; + } + + // + void GenerateScore( + double &bullishScore, + double &bearishScore // + ) + { + // + bullishScore = 0; + bearishScore = 0; + + // + if (isBullish) + { + bullishScore++; + } + if (isSwitchedToBullish) + { + bullishScore++; + } + + // + if (isBearish) + { + bearishScore++; + } + if (isSwitchedToBearish) + { + bearishScore++; + } + } + + // + string GenerateSummary( + bool onlyCommons = false, + bool onlyConditions = false, + bool includeScores = true, + bool ignoreFalseConditions = true, + string separator = "\n" // + ) + { + // + string result = NULL; + + // + double bullishScore = 0; + double bearishScore = 0; + GenerateScore( + bullishScore, + bearishScore // + ); + + // + string scoresStr = + // + "Scores: " + separator + + "---------------" + separator + + "Bullish: " + ToString(bullishScore) + separator + + "Bearish: " + ToString(bearishScore) + separator + + "" + // + ; + + // + string commonStr = GenerateSpecifiedCommonSummary( + this, + separator, + includeScores // + ); + + // + string conditionsStr = + // + ToString("isBullish", isBullish, ignoreFalseConditions, separator) + + ToString("isBearish", isBearish, ignoreFalseConditions, separator) + + ToString("isSwitchedToBullish", isSwitchedToBullish, ignoreFalseConditions, separator) + + ToString("isSwitchedToBearish", isSwitchedToBearish, ignoreFalseConditions, separator) + + "" + // + ; + + // + result = + // + "[" + GetTag() + "]" + separator + + (onlyConditions + ? "" + : commonStr) + + (!includeScores + ? "" + : scoresStr) + + " " + separator + + (onlyCommons + ? "" + : conditionsStr) + + "" + // + ; + + // + return result; + } + + // + string GetTag() + { + return "XSSLC"; + } +}; + // // Class ... class XSCXSSLCHelper : public XSCBaseHelper @@ -355,6 +506,75 @@ public: ); } + // + bool GetConditions( + XSSLCConditions &conditions, // + int barIndex = 0, // + int loopback = 3 // + ) + { + // + bool result = true; + + // + if (loopback < 3) + { + loopback = 3; + } + + // + conditions.Clean(); + + // + conditions.symbol = mSymbol; + conditions.period = mPeriod; + conditions.time = TimeCurrent(); + + // + int zIndex = barIndex; + int cIndex = zIndex + 1; + int pIndex = cIndex + 1; + int ppIndex = pIndex + 1; + + // + CopyUp( + zIndex, + loopback, + conditions.up // + ); + CopyDown( + zIndex, + loopback, + conditions.down // + ); + + // + // Calculate Conditions ... + + // + bool isBullish = conditions.up[cIndex] > conditions.down[cIndex]; + bool isBearish = conditions.up[cIndex] < conditions.down[cIndex]; + + // + bool isBullishPrev = conditions.up[pIndex] > conditions.down[pIndex]; + bool isBearishPrev = conditions.up[pIndex] < conditions.down[pIndex]; + + // + bool isSwitchedToBullish = isBullish && + !isBullishPrev; + bool isSwitchedToBearish = isBearish && + !isBearishPrev; + + // + conditions.isBullish = isBullish; + conditions.isBearish = isBearish; + conditions.isSwitchedToBullish = isSwitchedToBullish; + conditions.isSwitchedToBearish = isSwitchedToBearish; + + // + return result; + } + // // Protected ... protected: diff --git a/Helpers/x-saherelm.xstr.helper.mq5 b/Helpers/x-saherelm.xstr.helper.mq5 index 009f3bae..2fdaf48b 100644 --- a/Helpers/x-saherelm.xstr.helper.mq5 +++ b/Helpers/x-saherelm.xstr.helper.mq5 @@ -129,6 +129,157 @@ struct XSTRInputs } }; +// +// Define Conditions ... +struct XSTRConditions +{ + // + // Common ... + string symbol; + ENUM_TIMEFRAMES period; + datetime time; + + // + // Buffers ... + double trend[]; + double state[]; + + // + // Conditions ... + + // + bool isTrendBullish; + bool isTrendBearish; + bool isTrendSwitchedToBullish; + bool isTrendSwitchedToBearish; + + // + void Clean() + { + // + Clean(trend); + Clean(state); + + // + ArraySetAsSeries(trend, true); + ArraySetAsSeries(state, true); + + // + isTrendBullish = false; + isTrendBearish = false; + isTrendSwitchedToBullish = false; + isTrendSwitchedToBearish = false; + } + + // + void GenerateScore( + double &bullishScore, + double &bearishScore // + ) + { + // + bullishScore = 0; + bearishScore = 0; + + // + if (isTrendBullish) + { + bullishScore++; + } + if (isTrendSwitchedToBullish) + { + bullishScore++; + } + + // + if (isTrendBearish) + { + bearishScore++; + } + if (isTrendSwitchedToBearish) + { + bearishScore++; + } + } + + // + string GenerateSummary( + bool onlyCommons = false, + bool onlyConditions = false, + bool includeScores = true, + bool ignoreFalseConditions = true, + string separator = "\n" // + ) + { + // + string result = NULL; + + // + double bullishScore = 0; + double bearishScore = 0; + GenerateScore( + bullishScore, + bearishScore // + ); + + // + string scoresStr = + // + "Scores: " + separator + + "---------------" + separator + + "Bullish: " + ToString(bullishScore) + separator + + "Bearish: " + ToString(bearishScore) + separator + + "" + // + ; + + // + string commonStr = GenerateSpecifiedCommonSummary( + this, + separator, + includeScores // + ); + + // + string conditionsStr = + // + ToString("isTrendBullish", isTrendBullish, ignoreFalseConditions, separator) + + ToString("isTrendBearish", isTrendBearish, ignoreFalseConditions, separator) + + ToString("isTrendSwitchedToBullish", isTrendSwitchedToBullish, ignoreFalseConditions, separator) + + ToString("isTrendSwitchedToBearish", isTrendSwitchedToBearish, ignoreFalseConditions, separator) + + "" + // + ; + + // + result = + // + "[" + GetTag() + "]" + separator + + (onlyConditions + ? "" + : commonStr) + + (!includeScores + ? "" + : scoresStr) + + " " + separator + + (onlyCommons + ? "" + : conditionsStr) + + "" + // + ; + + // + return result; + } + + // + string GetTag() + { + return "XSTR"; + } +}; + // // Class ... class XSCXSTRHelper : public XSCBaseHelper @@ -154,7 +305,7 @@ public: bool Init( string symbol, // Trading Symbol ENUM_TIMEFRAMES period, // Trading Period - XSTRInputs &inputs // Inputs + XSTRInputs &inputs // Inputs ) { // @@ -367,6 +518,75 @@ public: return result; } + // + bool GetConditions( + XSTRConditions &conditions, // + int barIndex = 0, // + int loopback = 3 // + ) + { + // + bool result = true; + + // + if (loopback < 3) + { + loopback = 3; + } + + // + conditions.Clean(); + + // + conditions.symbol = mSymbol; + conditions.period = mPeriod; + conditions.time = TimeCurrent(); + + // + int zIndex = barIndex; + int cIndex = zIndex + 1; + int pIndex = cIndex + 1; + int ppIndex = pIndex + 1; + + // + CopyTrend( + zIndex, + loopback, + conditions.trend // + ); + CopyState( + zIndex, + loopback, + conditions.state // + ); + + // + // Calculate Conditions ... + + // + bool isTrendBullish = IsBullish(conditions.state[cIndex]); + bool isTrendBearish = IsBearish(conditions.state[cIndex]); + + // + bool isTrendBullishPrev = IsBullish(conditions.state[pIndex]); + bool isTrendBearishPrev = IsBearish(conditions.state[pIndex]); + + // + bool isTrendSwitchedToBullish = isTrendBullish && + !isTrendBullishPrev; + bool isTrendSwitchedToBearish = isTrendBearish && + !isTrendBearishPrev; + + // + conditions.isTrendBullish = isTrendBullish; + conditions.isTrendBearish = isTrendBearish; + conditions.isTrendSwitchedToBullish = isTrendSwitchedToBullish; + conditions.isTrendSwitchedToBearish = isTrendSwitchedToBearish; + + // + return result; + } + // // Protected ... protected: diff --git a/Helpers/x-saherelm.xtd.helper.mq5 b/Helpers/x-saherelm.xtd.helper.mq5 index 488e7d67..1103f19a 100644 --- a/Helpers/x-saherelm.xtd.helper.mq5 +++ b/Helpers/x-saherelm.xtd.helper.mq5 @@ -137,6 +137,157 @@ struct XTDInputs } }; +// +// Define Conditions ... +struct XTDConditions +{ + // + // Common ... + string symbol; + ENUM_TIMEFRAMES period; + datetime time; + + // + // Buffers ... + double bullish[]; + double bearish[]; + + // + // Conditions ... + + // + bool isBullish; + bool isBearish; + bool isSwitchedToBullish; + bool isSwitchedToBearish; + + // + void Clean() + { + // + Clean(bullish); + Clean(bearish); + + // + ArraySetAsSeries(bullish, true); + ArraySetAsSeries(bearish, true); + + // + isBullish = false; + isBearish = false; + isSwitchedToBullish = false; + isSwitchedToBearish = false; + } + + // + void GenerateScore( + double &bullishScore, + double &bearishScore // + ) + { + // + bullishScore = 0; + bearishScore = 0; + + // + if (isBullish) + { + bullishScore++; + } + if (isSwitchedToBullish) + { + bullishScore++; + } + + // + if (isBearish) + { + bearishScore++; + } + if (isSwitchedToBearish) + { + bearishScore++; + } + } + + // + string GenerateSummary( + bool onlyCommons = false, + bool onlyConditions = false, + bool includeScores = true, + bool ignoreFalseConditions = true, + string separator = "\n" // + ) + { + // + string result = NULL; + + // + double bullishScore = 0; + double bearishScore = 0; + GenerateScore( + bullishScore, + bearishScore // + ); + + // + string scoresStr = + // + "Scores: " + separator + + "---------------" + separator + + "Bullish: " + ToString(bullishScore) + separator + + "Bearish: " + ToString(bearishScore) + separator + + "" + // + ; + + // + string commonStr = GenerateSpecifiedCommonSummary( + this, + separator, + includeScores // + ); + + // + string conditionsStr = + // + ToString("isBullish", isBullish, ignoreFalseConditions, separator) + + ToString("isBearish", isBearish, ignoreFalseConditions, separator) + + ToString("isSwitchedToBullish", isSwitchedToBullish, ignoreFalseConditions, separator) + + ToString("isSwitchedToBearish", isSwitchedToBearish, ignoreFalseConditions, separator) + + "" + // + ; + + // + result = + // + "[" + GetTag() + "]" + separator + + (onlyConditions + ? "" + : commonStr) + + (!includeScores + ? "" + : scoresStr) + + " " + separator + + (onlyCommons + ? "" + : conditionsStr) + + "" + // + ; + + // + return result; + } + + // + string GetTag() + { + return "XTD"; + } +}; + // // Class ... class XSCXTDHelper : public XSCBaseHelper @@ -162,7 +313,7 @@ public: bool Init( string symbol, // Trading Symbol ENUM_TIMEFRAMES period, // Trading Period - XTDInputs &inputs // Inputs + XTDInputs &inputs // Inputs ) { // @@ -393,6 +544,75 @@ public: ); } + // + bool GetConditions( + XTDConditions &conditions, // + int barIndex = 0, // + int loopback = 3 // + ) + { + // + bool result = true; + + // + if (loopback < 3) + { + loopback = 3; + } + + // + conditions.Clean(); + + // + conditions.symbol = mSymbol; + conditions.period = mPeriod; + conditions.time = TimeCurrent(); + + // + int zIndex = barIndex; + int cIndex = zIndex + 1; + int pIndex = cIndex + 1; + int ppIndex = pIndex + 1; + + // + CopyBullish( + zIndex, + loopback, + conditions.bullish // + ); + CopyBearish( + zIndex, + loopback, + conditions.bearish // + ); + + // + // Calculate Conditions ... + + // + bool isBullish = conditions.bullish[cIndex] > conditions.bearish[cIndex]; + bool isBearish = conditions.bullish[cIndex] < conditions.bearish[cIndex]; + + // + bool isBullishPrev = conditions.bullish[pIndex] > conditions.bearish[pIndex]; + bool isBearishPrev = conditions.bullish[pIndex] < conditions.bearish[pIndex]; + + // + bool isSwitchedToBullish = isBullish && + !isBullishPrev; + bool isSwitchedToBearish = isBearish && + !isBearishPrev; + + // + conditions.isBullish = isBullish; + conditions.isBearish = isBearish; + conditions.isSwitchedToBullish = isSwitchedToBullish; + conditions.isSwitchedToBearish = isSwitchedToBearish; + + // + return result; + } + // // Protected ... protected: diff --git a/Libraries/x-saherelm.common.lib.mq5 b/Libraries/x-saherelm.common.lib.mq5 index ab9e1095..a1fb2f16 100644 --- a/Libraries/x-saherelm.common.lib.mq5 +++ b/Libraries/x-saherelm.common.lib.mq5 @@ -2405,6 +2405,9 @@ struct XBarTracker // int lastTrackedBar; // Last Tracked Bar ... + // + bool waitsUntilNext; // Waits Until Next Bar ... + // // Constructor ... XBarTracker() @@ -2473,6 +2476,37 @@ struct XBarTracker return result; } + // + bool CanProcessBar() + { + // + bool isInTestMode = IsRunningOnTestMode(); + + // + bool isNewBar = IsNewBar(); + + // + bool result = + isInTestMode + ? isNewBar + : !waitsUntilNext + ? true + : isNewBar; + if (result && waitsUntilNext) + { + waitsUntilNext = false; + } + + // + return result; + } + + // + void Waits() + { + this.waitsUntilNext = true; + } + // // Tools ... void Clean() @@ -4516,6 +4550,29 @@ void CalculateTPSL( // return; } + 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 @@ -4528,6 +4585,100 @@ void CalculateTPSL( : mEntry + risk; } +// +bool CalculateTPSLByPoint( + double &mSL, // Hold SL + double &mTP, // Hold TP + ENUM_POSITION_TYPE mType, // Position Type Long (Buy) / Short (Sell) + double mEntry, // Entry Price + double mPointValue, // Point Value + double mR2R = 1, // Provided Risk To Reward Ratio + double slPoint = 0, // Provided SL Point + double tpPoint = 0 // Provided TP Point +) +{ + // + bool result = false; + + // + mSL = 0; + mTP = 0; + + // + bool isLong = IsLong(mType); + + // + // Set Default R2R ... + if (mR2R < 1) + { + mR2R = 1; + } + + // + if (mEntry <= 0 || + mPointValue <= 0 || + (slPoint <= 0 && tpPoint <= 0)) + { + return result; + } + + // + double risk = 0; + double reward = 0; + + // + bool canCalculateBasedOnSL = slPoint > 0; + + // + bool canCalculateBasedOnTP = tpPoint > 0; + + // + if (!canCalculateBasedOnSL && !canCalculateBasedOnTP) + { + return result; + } + + // + if (canCalculateBasedOnSL && canCalculateBasedOnTP) + { + // + reward = tpPoint * mPointValue; + risk = slPoint * mPointValue; + } + else if (!canCalculateBasedOnSL && canCalculateBasedOnTP) + { + // + reward = tpPoint * mPointValue; + risk = reward / mR2R; + } + else if (canCalculateBasedOnSL && !canCalculateBasedOnTP) + { + // + risk = slPoint * mPointValue; + reward = risk * mR2R; + } + + // + result = risk > 0 && reward > 0; + if (!result) + { + return result; + } + + // + mTP = isLong + ? mEntry + reward + : mEntry - reward; + + // + mSL = isLong + ? mEntry - risk + : mEntry + risk; + + // + return result; +} + // bool GetTick( string mSymbol, @@ -6161,14 +6312,14 @@ double GetAverage( // // Get Max of Specific Loopback of a Buffer ... template -double GetMax( +T GetMax( T &buffer[], // the Buffer which required to search int start = 0, // Start Index int count = 0 // Count for Search ) { // - double result = 0; + T result = 0; // if (count <= 0) @@ -6195,7 +6346,7 @@ double GetMax( for (int i = 0; i < tmpCount; i++) { // - double iValue = tmp[i]; + T iValue = tmp[i]; // result = @@ -6216,14 +6367,14 @@ double GetMax( // // Get Min of Specific Loopback of a Buffer ... template -double GetMin( +T GetMin( T &buffer[], // the Buffer which required to search int start = 0, // Start Index int count = 0 // Count for Search ) { // - double result = 0; + T result = 0; // if (count <= 0) @@ -6250,7 +6401,7 @@ double GetMin( for (int i = 0; i < tmpCount; i++) { // - double iValue = tmp[i]; + T iValue = tmp[i]; // result =