From 1637a6ba921a5a290651d7fa55a0260f0c337e7e Mon Sep 17 00:00:00 2001 From: Hadi Khazaee Asl Date: Tue, 4 Jun 2024 18:34:34 +0330 Subject: [PATCH] prepare signaller's class ... --- Classes/x-saherelm.x121.provider.class.mq5 | 3694 +++-------------- .../x-saherelm.x121.x121.provider.class.mq5 | 97 + .../x-saherelm.x121.x786.provider.class.mq5 | 193 + Classes/x-saherelm.x121.xea.class.mq5 | 2 +- Classes/x-saherelm.x121.xmcycle.class.mq5 | 408 +- Classes/x-saherelm.xprovider.class.mq5 | 53 +- Experts/x-test.x121ea.mq5 | 38 +- Libraries/x-saherelm.common.lib.mq5 | 17 + 8 files changed, 825 insertions(+), 3677 deletions(-) create mode 100644 Classes/x-saherelm.x121.x121.provider.class.mq5 create mode 100644 Classes/x-saherelm.x121.x786.provider.class.mq5 diff --git a/Classes/x-saherelm.x121.provider.class.mq5 b/Classes/x-saherelm.x121.provider.class.mq5 index 8ac9d6fe..72586bac 100644 --- a/Classes/x-saherelm.x121.provider.class.mq5 +++ b/Classes/x-saherelm.x121.provider.class.mq5 @@ -41,9 +41,6 @@ #include "../Classes/x-saherelm.xprovider.class.mq5" #include "../Classes/x-saherelm.x121.xmcycle.class.mq5" -// -#include "../Classes/Indicators/x-saherelm.mid.class.mq5" - // // Definitions ... @@ -807,10 +804,6 @@ public: // // Props ... - // - XSCMidInputs midInputs; - XSCMid *mid; - // XSCXCCHelper *ccHelper; // Candle Clear XSCXCTHelper *ctHelper; // Candle Timer @@ -825,20 +818,14 @@ public: // // Constructor ... XSCX121Provider( - string symbol, // Trading Symbol - ENUM_TIMEFRAMES period, // Trading Period - double staticVolume // Static Volume for Positions - - ) : XSCBaseProvider(symbol, period, staticVolume) + string symbol, // Trading Symbol + ENUM_TIMEFRAMES period // Trading Period + ) : XSCBaseProvider(symbol, period) { // ccHelper = new XSCXCCHelper(); ctHelper = new XSCXCTHelper(); - // - midInputs.Init(); - mid = new XSCMid(symbol, period); - // // Instantiate X121 Market Cycles Classes ... cMarket = new XSCX121Market(); @@ -849,25 +836,11 @@ public: // mNumberOfItems = 15; - mNumberOfSRVerified = 71; - mMinRequiredSupportAndResistances = 30; } // // Properties Gettr(s) / Setter(s) ... - // - void SetNumberOfSRVerified(int value) - { - mNumberOfSRVerified = value; - } - - // - int GetNumberOfSRVerified() - { - return mNumberOfSRVerified; - } - // void SetNumberOfItems(int value) { @@ -880,18 +853,6 @@ public: return mNumberOfItems; } - // - void SetMinRequiredSupportAndResistances(int value) - { - mMinRequiredSupportAndResistances = value; - } - - // - int GetMinRequiredSupportAndResistances() - { - return mMinRequiredSupportAndResistances; - } - // // Overrides ... @@ -929,15 +890,6 @@ public: return result; } - // - result = mid.Init( - midInputs // - ); - if (!result) - { - return result; - } - // mInputs = inputs; @@ -1028,98 +980,6 @@ public: return result; } - // - // Set Default Position's Type ... - // Enable / Disable Long (Buy), Short (Sell) ... - void SetSignalTypeState( - ENUM_POSITION_TYPE type, // Which types are Signals be Targetted - bool state // Which State is going to Set - ) - { - // - if (IsLong(type)) - { - mIsLongEnable = state; - } - else - { - mIsShortEnable = state; - } - } - - // - // Set Signal Providers ... - void SetSignalProviderState( - ENUM_XSIGNAL_PROVIDERS provider, // Provider State - bool state // Which state is going to set ... - ) - { - // - if (provider == PROVIDER_NONE) - { - return; - } - - // - switch (provider) - { - // - case XSP: - mIsXSPSignalProviderEnable = state; - break; - - // - case XTEST: - mIsXTESTSignalProviderEnable = state; - break; - - // - case X786: - mIsX786SignalProviderEnable = state; - break; - - // - case X121: - mIsX121SignalProviderEnable = state; - break; - - // - case X110: - mIsX110SignalProviderEnable = state; - break; - - // - case X92: - mIsX92SignalProviderEnable = state; - break; - - // - case X128: - mIsX128SignalProviderEnable = state; - break; - } - } - - // - void SetSignalProviderStates( - ENUM_XSIGNAL_PROVIDERS &providers[], // Collection of Providers ... - bool state // Which state is going to set ... - ) - { - // - int providersCount = ArraySize(providers); - if (providersCount <= 0) - { - return; - } - - // - for (int i = 0; i < providersCount; i++) - { - SetSignalProviderState(providers[i], state); - } - } - // string GetTag() { @@ -1155,265 +1015,6 @@ public: CalculateConditions(mConditions, barIndex); } - // - // Check Market For Signal ... - bool HasSignal( - int barIndex, - XSignal &mSignal, // Hold's Signal if Exists ... - X121MarketConditions &mConditions // Hold's Market Conditions ... - ) - { - // - bool result = false; - - // - // Validate Enable Process ... - result = !CanIgnoreProcess(); - if (!result) - { - return result; - } - - // - mWaitsUntilNewBar = false; - - // - // Validate Enable Type of Signalling ... - result = mIsLongEnable || mIsShortEnable; - if (!result) - { - return result; - } - - // - // Now we Have to Pass the Conditions to Each Signal Provider - // for Retrieving Signals Based On them ... - - // - // Reading Market Conditions ... - GetMarketConditions(mConditions, barIndex); - AddScores(mConditions); - - // - int signalPusher = 0; - bool hasLong = false; - bool hasShort = false; - string provider = ""; - - // - double providedSL = 0; - double providedTP = 0; - double providedR2r = 2; - - // - // Long ... - if (mIsLongEnable) - { - // - signalPusher = 0; - - // - hasLong = HasSpecificSignal( - barIndex, - POSITION_TYPE_BUY, - provider, - signalPusher, - mConditions, - providedSL, - providedTP, - providedR2r // - ); - } - - // - // Short ... - if (mIsShortEnable) - { - // - signalPusher = 0; - - // - hasShort = HasSpecificSignal( - barIndex, - POSITION_TYPE_SELL, - provider, - signalPusher, - mConditions, - providedSL, - providedTP, - providedR2r // - ); - } - - // - result = hasLong || hasShort; - if (!result) - { - return result; - } - - // - if (result) - { - // - // Here We Have to Prepare Signal ... - - // - string symbol = GetSymbol(); - ENUM_TIMEFRAMES period = GetPeriod(); - double volume = GetStaticVolume(); // * signalPusher; - ENUM_POSITION_TYPE type = hasLong - ? POSITION_TYPE_BUY - : POSITION_TYPE_SELL; - ENUM_X_ORDER_MODES mode = X_ORDER_MODE_MARKET; - double entry = GetEntry( - symbol, - type // - ); - - // - double tp = 0; - double sl = 0; - - // - // TODO: Make Configurable ... - double r2r = providedR2r; - if (r2r <= 0) - { - r2r = 1.5; - } - - // - sl = 0; - tp = 0; - - // - // TP based on SL and Risk to Reward ... - if (providedSL > 0) - { - // - sl = providedSL; - - // - double risk = MathAbs(entry - sl); - - // - double reward = risk * r2r; - - // - tp = hasLong - ? entry + reward - : entry - reward; - } - else - // - // SL based on TP and Risk to Reward ... - if (providedTP > 0) - { - // - tp = providedTP; - - // - double reward = MathAbs(entry - tp); - - // - double risk = reward / r2r; - - // - sl = hasLong - ? entry - risk - : entry + risk; - } - else - { - // - // TODOO: Remove this ... - sl = hasLong - ? sMarket.pv.GetMCLL(0) - : sMarket.pv.GetMCHH(0); - double risk = MathAbs(entry - sl); - double reward = risk * r2r; - tp = hasLong - ? entry + reward - : entry - reward; - } - - // - result = mSignal.Prepare( - symbol, - provider, - period, - type, - mode, - entry, - volume, - sl, - tp - // - ); - - // - // Generate Support Signal for Specified Provider ... - if (result) - { - // - // Generate Opposit Signal ... - - // - // XSignal sSignal; - // bool isGenerated = mSignal.GenerateOpposit(sSignal); - // if (isGenerated) - // { - // // - // // mSignal = sSignal; - - // // - // AddRef( - // sSignal, - // mSignal.supports // - // ); - // } - } - - // - if (result) - { - mWaitsUntilNewBar = true; - } - } - - // - UpdateSupportsAndResistances(); - - // - return result; - } - - // - // Check for any Guards ... - bool HasGuard(XGuard &guards[]) - { - // - bool result = false; - - // - // Try to Find Support and Resistances if Configured ... - FindSupportAndResistances(); - - // - // TODO: - - // - // Here We Have to Implement Trail Management for - // Spearate Providers ... - - // - // And also Remove EA Trail Manage ment inside EA ... - - // - return result; - } - // // Tools ... @@ -1447,1329 +1048,12 @@ public: hMarket.Draw(chID, subWindow, offset); } - // - // Support and Resistances ... - - // - int CountSupportResistances() - { - return ArraySize(mSupportResistances); - } - - // - bool GenerateSupRes( - XOHCLSupRes &supRes, // SupRes Instance ... - ENUM_POSITION_TYPE type, // Position Type ... - int count = 5, - double step = 0, - bool useAtrAsStep = true // - ) - { - // - bool result = false; - - // - if (count <= 0) - { - count = 1; - } - - // - if (step <= 0) - { - // - if (useAtrAsStep) - { - step = cMarket.osc.GetATR(0); - } - else - { - step = 0; - } - } - - // - supRes.Clean(); - - // - double price = GetExit( - GetSymbol(), - type // - ); - - // - result = supRes.Init( - price, - mSupportResistances, - count, - step // - ); - - // - return result; - } - - // - bool GenerateLongSupRes( - XOHCLSupRes &supRes, // SupRes Instance ... - int count = 5, - double step = 0, - bool useAtrAsStep = true // - ) - { - // - bool result = false; - - // - result = GenerateSupRes( - supRes, - POSITION_TYPE_BUY, - count, - step, - useAtrAsStep // - ); - - // - return result; - } - - // - bool GenerateShortSupRes( - XOHCLSupRes &supRes, // SupRes Instance ... - int count = 5, - double step = 0, - bool useAtrAsStep = true // - ) - { - // - bool result = false; - - // - result = GenerateSupRes( - supRes, - POSITION_TYPE_BUY, - count, - step, - useAtrAsStep // - ); - - // - return result; - } - - // - // Peask and Vales Finder ... - - // - void GetPeaks( - double &peaks[], - bool ignoreCurrent = false // - ) - { - // - Clean(peaks); - - // - // - double cPVPeak = cMarket.pv.GetPeak(0); - double sPeak = sMarket.pv.GetPeak(0); - double mPeak = mMarket.pv.GetPeak(0); - double lPeak = lMarket.pv.GetPeak(0); - double hPeak = hMarket.pv.GetPeak(0); - - // - double mPeaks[] = { - cPVPeak, - sPeak, - mPeak, - lPeak, - hPeak // - }; - - // - if (ignoreCurrent) - { - // - Remove( - cPVPeak, - mPeaks // - ); - } - - // - Copy( - mPeaks, - peaks // - ); - } - - // - void GetVales( - double &vales[], - bool ignoreCurrent = false // - ) - { - // - Clean(vales); - - // - double cPVVale = cMarket.pv.GetVale(0); - double sVale = sMarket.pv.GetVale(0); - double mVale = mMarket.pv.GetVale(0); - double lVale = lMarket.pv.GetVale(0); - double hVale = hMarket.pv.GetVale(0); - - // - double mVales[] = { - cPVVale, - sVale, - mVale, - lVale, - hVale // - }; - - // - if (ignoreCurrent) - { - // - Remove( - cPVVale, - mVales // - ); - } - - // - Copy( - mVales, - vales // - ); - } - - // - double GetMinPeaks(bool ignoreCurrent = false) - { - // - double peaks[]; - GetPeaks( - peaks, - ignoreCurrent // - ); - - // - double minPeak = GetMin(peaks); - double maxPeak = GetMax(peaks); - - // - return minPeak; - } - - // - double GetMaxPeaks(bool ignoreCurrent = false) - { - // - double peaks[]; - GetPeaks( - peaks, - ignoreCurrent // - ); - - // - double minPeak = GetMin(peaks); - double maxPeak = GetMax(peaks); - - // - return maxPeak; - } - - // - double GetMinVales(bool ignoreCurrent = false) - { - // - double vales[]; - GetVales( - vales, - ignoreCurrent // - ); - - // - double minVale = GetMin(vales); - double maxVale = GetMax(vales); - - // - return minVale; - } - - // - double GetMaxVales(bool ignoreCurrent = false) - { - // - double vales[]; - GetVales( - vales, - ignoreCurrent // - ); - - // - double minVale = GetMin(vales); - double maxVale = GetMax(vales); - - // - return maxVale; - } - // // Protected ... protected: // X121ProviderInputs mInputs; - // - // Support and Resistances ... - - // - // Check has Enough Support and Resistance ... - bool HasEnoughSupportAndResistance() - { - // - bool result = false; - - // - if (mNumberOfSRVerified <= 0 || - mMinRequiredSupportAndResistances <= 0) - { - result = true; - } - else - { - // - int currentSRsCount = CountSupportResistances(); - result = currentSRsCount >= mMinRequiredSupportAndResistances; - } - - // - return result; - } - - // - // Update Bar Index base Support and Resistances .... - void UpdateSupportsAndResistances( - int barIndex = 0 // - ) - { - // - if (mNumberOfSRVerified <= 0 || - mMinRequiredSupportAndResistances <= 0) - { - return; - } - - // - int before = CountSupportResistances(); - - // - // XICH ... - - // - // Current ... - - // - if (cMarket.ich.IsSameKijunSen(barIndex, mNumberOfSRVerified)) - { - // - double selectedKijunSen = cMarket.ich.GetKijunSen(barIndex); - AddSRValue(selectedKijunSen); - } - - // - if (cMarket.ich.IsSameSenkouSpanA(barIndex, mNumberOfSRVerified)) - { - // - double selectedSenkouSpanA = cMarket.ich.GetSenkouSpanA(barIndex); - AddSRValue(selectedSenkouSpanA); - } - - // - if (cMarket.ich.IsSameSenkouSpanB(barIndex, mNumberOfSRVerified)) - { - // - double selectedSenkouSpanB = cMarket.ich.GetSenkouSpanB(barIndex); - AddSRValue(selectedSenkouSpanB); - } - - // - // Short ... - - // - if (sMarket.ich.IsSameKijunSen(barIndex, mNumberOfSRVerified)) - { - // - double selectedKijunSen = sMarket.ich.GetKijunSen(barIndex); - AddSRValue(selectedKijunSen); - } - - // - if (sMarket.ich.IsSameSenkouSpanA(barIndex, mNumberOfSRVerified)) - { - // - double selectedSenkouSpanA = sMarket.ich.GetSenkouSpanA(barIndex); - AddSRValue(selectedSenkouSpanA); - } - - // - if (sMarket.ich.IsSameSenkouSpanB(barIndex, mNumberOfSRVerified)) - { - // - double selectedSenkouSpanB = sMarket.ich.GetSenkouSpanB(barIndex); - AddSRValue(selectedSenkouSpanB); - } - - // - // Medium ... - - // - if (mMarket.ich.IsSameKijunSen(barIndex, mNumberOfSRVerified)) - { - // - double selectedKijunSen = mMarket.ich.GetKijunSen(barIndex); - AddSRValue(selectedKijunSen); - } - - // - if (mMarket.ich.IsSameSenkouSpanA(barIndex, mNumberOfSRVerified)) - { - // - double selectedSenkouSpanA = mMarket.ich.GetSenkouSpanA(barIndex); - AddSRValue(selectedSenkouSpanA); - } - - // - if (mMarket.ich.IsSameSenkouSpanB(barIndex, mNumberOfSRVerified)) - { - // - double selectedSenkouSpanB = mMarket.ich.GetSenkouSpanB(barIndex); - AddSRValue(selectedSenkouSpanB); - } - - // - // Long ... - - // - if (lMarket.ich.IsSameKijunSen(barIndex, mNumberOfSRVerified)) - { - // - double selectedKijunSen = lMarket.ich.GetKijunSen(barIndex); - AddSRValue(selectedKijunSen); - } - - // - if (lMarket.ich.IsSameSenkouSpanA(barIndex, mNumberOfSRVerified)) - { - // - double selectedSenkouSpanA = lMarket.ich.GetSenkouSpanA(barIndex); - AddSRValue(selectedSenkouSpanA); - } - - // - if (lMarket.ich.IsSameSenkouSpanB(barIndex, mNumberOfSRVerified)) - { - // - double selectedSenkouSpanB = lMarket.ich.GetSenkouSpanB(barIndex); - AddSRValue(selectedSenkouSpanB); - } - - // - // Hind ... - - // - if (hMarket.ich.IsSameKijunSen(barIndex, mNumberOfSRVerified)) - { - // - double selectedKijunSen = hMarket.ich.GetKijunSen(barIndex); - AddSRValue(selectedKijunSen); - } - - // - if (hMarket.ich.IsSameSenkouSpanA(barIndex, mNumberOfSRVerified)) - { - // - double selectedSenkouSpanA = hMarket.ich.GetSenkouSpanA(barIndex); - AddSRValue(selectedSenkouSpanA); - } - - // - if (hMarket.ich.IsSameSenkouSpanB(barIndex, mNumberOfSRVerified)) - { - // - double selectedSenkouSpanB = hMarket.ich.GetSenkouSpanB(barIndex); - AddSRValue(selectedSenkouSpanB); - } - - // - // XDON ... - - // - // Short Market ... - - // - if (sMarket.don.IsSameUpperO(barIndex, mNumberOfSRVerified)) - { - // - double selectedUpperO = sMarket.don.GetUpperO(barIndex); - AddSRValue(selectedUpperO); - } - - // - if (sMarket.don.IsSameLowerO(barIndex, mNumberOfSRVerified)) - { - // - double selectedLowerO = sMarket.don.GetLowerO(barIndex); - AddSRValue(selectedLowerO); - } - - // - if (sMarket.don.IsSameUpperC(barIndex, mNumberOfSRVerified)) - { - // - double selectedUpperC = sMarket.don.GetUpperC(barIndex); - AddSRValue(selectedUpperC); - } - - // - if (sMarket.don.IsSameLowerC(barIndex, mNumberOfSRVerified)) - { - // - double selectedLowerC = sMarket.don.GetLowerC(barIndex); - AddSRValue(selectedLowerC); - } - - // - if (sMarket.don.IsSameUpperH(barIndex, mNumberOfSRVerified)) - { - // - double selectedUpperH = sMarket.don.GetUpperH(barIndex); - AddSRValue(selectedUpperH); - } - - // - if (sMarket.don.IsSameLowerH(barIndex, mNumberOfSRVerified)) - { - // - double selectedLowerH = sMarket.don.GetLowerH(barIndex); - AddSRValue(selectedLowerH); - } - - // - if (sMarket.don.IsSameUpperL(barIndex, mNumberOfSRVerified)) - { - // - double selectedUpperL = sMarket.don.GetUpperL(barIndex); - AddSRValue(selectedUpperL); - } - - // - if (sMarket.don.IsSameLowerL(barIndex, mNumberOfSRVerified)) - { - // - double selectedLowerL = sMarket.don.GetLowerL(barIndex); - AddSRValue(selectedLowerL); - } - - // - // Medium Market ... - - // - if (mMarket.don.IsSameUpperO(barIndex, mNumberOfSRVerified)) - { - // - double selectedUpperO = mMarket.don.GetUpperO(barIndex); - AddSRValue(selectedUpperO); - } - - // - if (mMarket.don.IsSameLowerO(barIndex, mNumberOfSRVerified)) - { - // - double selectedLowerO = mMarket.don.GetLowerO(barIndex); - AddSRValue(selectedLowerO); - } - - // - if (mMarket.don.IsSameUpperC(barIndex, mNumberOfSRVerified)) - { - // - double selectedUpperC = mMarket.don.GetUpperC(barIndex); - AddSRValue(selectedUpperC); - } - - // - if (mMarket.don.IsSameLowerC(barIndex, mNumberOfSRVerified)) - { - // - double selectedLowerC = mMarket.don.GetLowerC(barIndex); - AddSRValue(selectedLowerC); - } - - // - if (mMarket.don.IsSameUpperH(barIndex, mNumberOfSRVerified)) - { - // - double selectedUpperH = mMarket.don.GetUpperH(barIndex); - AddSRValue(selectedUpperH); - } - - // - if (mMarket.don.IsSameLowerH(barIndex, mNumberOfSRVerified)) - { - // - double selectedLowerH = mMarket.don.GetLowerH(barIndex); - AddSRValue(selectedLowerH); - } - - // - if (mMarket.don.IsSameUpperL(barIndex, mNumberOfSRVerified)) - { - // - double selectedUpperL = mMarket.don.GetUpperL(barIndex); - AddSRValue(selectedUpperL); - } - - // - if (mMarket.don.IsSameLowerL(barIndex, mNumberOfSRVerified)) - { - // - double selectedLowerL = mMarket.don.GetLowerL(barIndex); - AddSRValue(selectedLowerL); - } - - // - // Long Market ... - - // - if (lMarket.don.IsSameUpperO(barIndex, mNumberOfSRVerified)) - { - // - double selectedUpperO = lMarket.don.GetUpperO(barIndex); - AddSRValue(selectedUpperO); - } - - // - if (lMarket.don.IsSameLowerO(barIndex, mNumberOfSRVerified)) - { - // - double selectedLowerO = lMarket.don.GetLowerO(barIndex); - AddSRValue(selectedLowerO); - } - - // - if (lMarket.don.IsSameUpperC(barIndex, mNumberOfSRVerified)) - { - // - double selectedUpperC = lMarket.don.GetUpperC(barIndex); - AddSRValue(selectedUpperC); - } - - // - if (lMarket.don.IsSameLowerC(barIndex, mNumberOfSRVerified)) - { - // - double selectedLowerC = lMarket.don.GetLowerC(barIndex); - AddSRValue(selectedLowerC); - } - - // - if (lMarket.don.IsSameUpperH(barIndex, mNumberOfSRVerified)) - { - // - double selectedUpperH = lMarket.don.GetUpperH(barIndex); - AddSRValue(selectedUpperH); - } - - // - if (lMarket.don.IsSameLowerH(barIndex, mNumberOfSRVerified)) - { - // - double selectedLowerH = lMarket.don.GetLowerH(barIndex); - AddSRValue(selectedLowerH); - } - - // - if (lMarket.don.IsSameUpperL(barIndex, mNumberOfSRVerified)) - { - // - double selectedUpperL = lMarket.don.GetUpperL(barIndex); - AddSRValue(selectedUpperL); - } - - // - if (lMarket.don.IsSameLowerL(barIndex, mNumberOfSRVerified)) - { - // - double selectedLowerL = lMarket.don.GetLowerL(barIndex); - AddSRValue(selectedLowerL); - } - - // - // Hind Market ... - - // - if (hMarket.don.IsSameUpperO(barIndex, mNumberOfSRVerified)) - { - // - double selectedUpperO = hMarket.don.GetUpperO(barIndex); - AddSRValue(selectedUpperO); - } - - // - if (hMarket.don.IsSameLowerO(barIndex, mNumberOfSRVerified)) - { - // - double selectedLowerO = hMarket.don.GetLowerO(barIndex); - AddSRValue(selectedLowerO); - } - - // - if (hMarket.don.IsSameUpperC(barIndex, mNumberOfSRVerified)) - { - // - double selectedUpperC = hMarket.don.GetUpperC(barIndex); - AddSRValue(selectedUpperC); - } - - // - if (hMarket.don.IsSameLowerC(barIndex, mNumberOfSRVerified)) - { - // - double selectedLowerC = hMarket.don.GetLowerC(barIndex); - AddSRValue(selectedLowerC); - } - - // - if (hMarket.don.IsSameUpperH(barIndex, mNumberOfSRVerified)) - { - // - double selectedUpperH = hMarket.don.GetUpperH(barIndex); - AddSRValue(selectedUpperH); - } - - // - if (hMarket.don.IsSameLowerH(barIndex, mNumberOfSRVerified)) - { - // - double selectedLowerH = hMarket.don.GetLowerH(barIndex); - AddSRValue(selectedLowerH); - } - - // - if (hMarket.don.IsSameUpperL(barIndex, mNumberOfSRVerified)) - { - // - double selectedUpperL = hMarket.don.GetUpperL(barIndex); - AddSRValue(selectedUpperL); - } - - // - if (hMarket.don.IsSameLowerL(barIndex, mNumberOfSRVerified)) - { - // - double selectedLowerL = hMarket.don.GetLowerL(barIndex); - AddSRValue(selectedLowerL); - } - - // - // XPV ... - - // - // Short Market ... - - // - if (sMarket.pv.IsSamePeak(barIndex, mNumberOfSRVerified)) - { - // - double selectedPeak = sMarket.pv.GetPeak(barIndex); - AddSRValue(selectedPeak); - } - - // - if (sMarket.pv.IsSameVale(barIndex, mNumberOfSRVerified)) - { - // - double selectedVale = sMarket.pv.GetVale(barIndex); - AddSRValue(selectedVale); - } - - // - if (sMarket.pv.IsSameFib1(barIndex, mNumberOfSRVerified)) - { - // - double selectedFib1 = sMarket.pv.GetFib1(barIndex); - AddSRValue(selectedFib1); - } - - // - if (sMarket.pv.IsSameFib2(barIndex, mNumberOfSRVerified)) - { - // - double selectedFib2 = sMarket.pv.GetFib2(barIndex); - AddSRValue(selectedFib2); - } - - // - if (sMarket.pv.IsSameFib3(barIndex, mNumberOfSRVerified)) - { - // - double selectedFib3 = sMarket.pv.GetFib3(barIndex); - AddSRValue(selectedFib3); - } - - // - if (sMarket.pv.IsSameFib4(barIndex, mNumberOfSRVerified)) - { - // - double selectedFib4 = sMarket.pv.GetFib4(barIndex); - AddSRValue(selectedFib4); - } - - // - if (sMarket.pv.IsSameFib5(barIndex, mNumberOfSRVerified)) - { - // - double selectedFib5 = sMarket.pv.GetFib5(barIndex); - AddSRValue(selectedFib5); - } - - // - if (sMarket.pv.IsSameSCHH(barIndex, mNumberOfSRVerified)) - { - // - double selectedSCHH = sMarket.pv.GetSCHH(barIndex); - AddSRValue(selectedSCHH); - } - - // - if (sMarket.pv.IsSameSCLL(barIndex, mNumberOfSRVerified)) - { - // - double selectedSCLL = sMarket.pv.GetSCLL(barIndex); - AddSRValue(selectedSCLL); - } - - // - if (sMarket.pv.IsSameMCHH(barIndex, mNumberOfSRVerified)) - { - // - double selectedMCHH = sMarket.pv.GetMCHH(barIndex); - AddSRValue(selectedMCHH); - } - - // - if (sMarket.pv.IsSameMCLL(barIndex, mNumberOfSRVerified)) - { - // - double selectedMCLL = sMarket.pv.GetMCLL(barIndex); - AddSRValue(selectedMCLL); - } - - // - if (sMarket.pv.IsSameLCHH(barIndex, mNumberOfSRVerified)) - { - // - double selectedLCHH = sMarket.pv.GetLCHH(barIndex); - AddSRValue(selectedLCHH); - } - - // - if (sMarket.pv.IsSameLCLL(barIndex, mNumberOfSRVerified)) - { - // - double selectedLCLL = sMarket.pv.GetLCLL(barIndex); - AddSRValue(selectedLCLL); - } - - // - if (sMarket.pv.IsSameHCHH(barIndex, mNumberOfSRVerified)) - { - // - double selectedHCHH = sMarket.pv.GetHCHH(barIndex); - AddSRValue(selectedHCHH); - } - - // - if (sMarket.pv.IsSameHCLL(barIndex, mNumberOfSRVerified)) - { - // - double selectedHCLL = sMarket.pv.GetHCLL(barIndex); - AddSRValue(selectedHCLL); - } - - // - // Medium Market ... - - // - if (mMarket.pv.IsSamePeak(barIndex, mNumberOfSRVerified)) - { - // - double selectedPeak = mMarket.pv.GetPeak(barIndex); - AddSRValue(selectedPeak); - } - - // - if (mMarket.pv.IsSameVale(barIndex, mNumberOfSRVerified)) - { - // - double selectedVale = mMarket.pv.GetVale(barIndex); - AddSRValue(selectedVale); - } - - // - if (mMarket.pv.IsSameFib1(barIndex, mNumberOfSRVerified)) - { - // - double selectedFib1 = mMarket.pv.GetFib1(barIndex); - AddSRValue(selectedFib1); - } - - // - if (mMarket.pv.IsSameFib2(barIndex, mNumberOfSRVerified)) - { - // - double selectedFib2 = mMarket.pv.GetFib2(barIndex); - AddSRValue(selectedFib2); - } - - // - if (mMarket.pv.IsSameFib3(barIndex, mNumberOfSRVerified)) - { - // - double selectedFib3 = mMarket.pv.GetFib3(barIndex); - AddSRValue(selectedFib3); - } - - // - if (mMarket.pv.IsSameFib4(barIndex, mNumberOfSRVerified)) - { - // - double selectedFib4 = mMarket.pv.GetFib4(barIndex); - AddSRValue(selectedFib4); - } - - // - if (mMarket.pv.IsSameFib5(barIndex, mNumberOfSRVerified)) - { - // - double selectedFib5 = mMarket.pv.GetFib5(barIndex); - AddSRValue(selectedFib5); - } - - // - if (mMarket.pv.IsSameSCHH(barIndex, mNumberOfSRVerified)) - { - // - double selectedSCHH = mMarket.pv.GetSCHH(barIndex); - AddSRValue(selectedSCHH); - } - - // - if (mMarket.pv.IsSameSCLL(barIndex, mNumberOfSRVerified)) - { - // - double selectedSCLL = mMarket.pv.GetSCLL(barIndex); - AddSRValue(selectedSCLL); - } - - // - if (mMarket.pv.IsSameMCHH(barIndex, mNumberOfSRVerified)) - { - // - double selectedMCHH = mMarket.pv.GetMCHH(barIndex); - AddSRValue(selectedMCHH); - } - - // - if (mMarket.pv.IsSameMCLL(barIndex, mNumberOfSRVerified)) - { - // - double selectedMCLL = mMarket.pv.GetMCLL(barIndex); - AddSRValue(selectedMCLL); - } - - // - if (mMarket.pv.IsSameLCHH(barIndex, mNumberOfSRVerified)) - { - // - double selectedLCHH = mMarket.pv.GetLCHH(barIndex); - AddSRValue(selectedLCHH); - } - - // - if (mMarket.pv.IsSameLCLL(barIndex, mNumberOfSRVerified)) - { - // - double selectedLCLL = mMarket.pv.GetLCLL(barIndex); - AddSRValue(selectedLCLL); - } - - // - if (mMarket.pv.IsSameHCHH(barIndex, mNumberOfSRVerified)) - { - // - double selectedHCHH = mMarket.pv.GetHCHH(barIndex); - AddSRValue(selectedHCHH); - } - - // - if (mMarket.pv.IsSameHCLL(barIndex, mNumberOfSRVerified)) - { - // - double selectedHCLL = mMarket.pv.GetHCLL(barIndex); - AddSRValue(selectedHCLL); - } - - // - // Long Market ... - - // - if (lMarket.pv.IsSamePeak(barIndex, mNumberOfSRVerified)) - { - // - double selectedPeak = lMarket.pv.GetPeak(barIndex); - AddSRValue(selectedPeak); - } - - // - if (lMarket.pv.IsSameVale(barIndex, mNumberOfSRVerified)) - { - // - double selectedVale = lMarket.pv.GetVale(barIndex); - AddSRValue(selectedVale); - } - - // - if (lMarket.pv.IsSameFib1(barIndex, mNumberOfSRVerified)) - { - // - double selectedFib1 = lMarket.pv.GetFib1(barIndex); - AddSRValue(selectedFib1); - } - - // - if (lMarket.pv.IsSameFib2(barIndex, mNumberOfSRVerified)) - { - // - double selectedFib2 = lMarket.pv.GetFib2(barIndex); - AddSRValue(selectedFib2); - } - - // - if (lMarket.pv.IsSameFib3(barIndex, mNumberOfSRVerified)) - { - // - double selectedFib3 = lMarket.pv.GetFib3(barIndex); - AddSRValue(selectedFib3); - } - - // - if (lMarket.pv.IsSameFib4(barIndex, mNumberOfSRVerified)) - { - // - double selectedFib4 = lMarket.pv.GetFib4(barIndex); - AddSRValue(selectedFib4); - } - - // - if (lMarket.pv.IsSameFib5(barIndex, mNumberOfSRVerified)) - { - // - double selectedFib5 = lMarket.pv.GetFib5(barIndex); - AddSRValue(selectedFib5); - } - - // - if (lMarket.pv.IsSameSCHH(barIndex, mNumberOfSRVerified)) - { - // - double selectedSCHH = lMarket.pv.GetSCHH(barIndex); - AddSRValue(selectedSCHH); - } - - // - if (lMarket.pv.IsSameSCLL(barIndex, mNumberOfSRVerified)) - { - // - double selectedSCLL = lMarket.pv.GetSCLL(barIndex); - AddSRValue(selectedSCLL); - } - - // - if (lMarket.pv.IsSameMCHH(barIndex, mNumberOfSRVerified)) - { - // - double selectedMCHH = lMarket.pv.GetMCHH(barIndex); - AddSRValue(selectedMCHH); - } - - // - if (lMarket.pv.IsSameMCLL(barIndex, mNumberOfSRVerified)) - { - // - double selectedMCLL = lMarket.pv.GetMCLL(barIndex); - AddSRValue(selectedMCLL); - } - - // - if (lMarket.pv.IsSameLCHH(barIndex, mNumberOfSRVerified)) - { - // - double selectedLCHH = lMarket.pv.GetLCHH(barIndex); - AddSRValue(selectedLCHH); - } - - // - if (lMarket.pv.IsSameLCLL(barIndex, mNumberOfSRVerified)) - { - // - double selectedLCLL = lMarket.pv.GetLCLL(barIndex); - AddSRValue(selectedLCLL); - } - - // - if (lMarket.pv.IsSameHCHH(barIndex, mNumberOfSRVerified)) - { - // - double selectedHCHH = lMarket.pv.GetHCHH(barIndex); - AddSRValue(selectedHCHH); - } - - // - if (lMarket.pv.IsSameHCLL(barIndex, mNumberOfSRVerified)) - { - // - double selectedHCLL = lMarket.pv.GetHCLL(barIndex); - AddSRValue(selectedHCLL); - } - - // - // Hind Market ... - - // - if (hMarket.pv.IsSamePeak(barIndex, mNumberOfSRVerified)) - { - // - double selectedPeak = hMarket.pv.GetPeak(barIndex); - AddSRValue(selectedPeak); - } - - // - if (hMarket.pv.IsSameVale(barIndex, mNumberOfSRVerified)) - { - // - double selectedVale = hMarket.pv.GetVale(barIndex); - AddSRValue(selectedVale); - } - - // - if (hMarket.pv.IsSameFib1(barIndex, mNumberOfSRVerified)) - { - // - double selectedFib1 = hMarket.pv.GetFib1(barIndex); - AddSRValue(selectedFib1); - } - - // - if (hMarket.pv.IsSameFib2(barIndex, mNumberOfSRVerified)) - { - // - double selectedFib2 = hMarket.pv.GetFib2(barIndex); - AddSRValue(selectedFib2); - } - - // - if (hMarket.pv.IsSameFib3(barIndex, mNumberOfSRVerified)) - { - // - double selectedFib3 = hMarket.pv.GetFib3(barIndex); - AddSRValue(selectedFib3); - } - - // - if (hMarket.pv.IsSameFib4(barIndex, mNumberOfSRVerified)) - { - // - double selectedFib4 = hMarket.pv.GetFib4(barIndex); - AddSRValue(selectedFib4); - } - - // - if (hMarket.pv.IsSameFib5(barIndex, mNumberOfSRVerified)) - { - // - double selectedFib5 = hMarket.pv.GetFib5(barIndex); - AddSRValue(selectedFib5); - } - - // - if (hMarket.pv.IsSameSCHH(barIndex, mNumberOfSRVerified)) - { - // - double selectedSCHH = hMarket.pv.GetSCHH(barIndex); - AddSRValue(selectedSCHH); - } - - // - if (hMarket.pv.IsSameSCLL(barIndex, mNumberOfSRVerified)) - { - // - double selectedSCLL = hMarket.pv.GetSCLL(barIndex); - AddSRValue(selectedSCLL); - } - - // - if (hMarket.pv.IsSameMCHH(barIndex, mNumberOfSRVerified)) - { - // - double selectedMCHH = hMarket.pv.GetMCHH(barIndex); - AddSRValue(selectedMCHH); - } - - // - if (hMarket.pv.IsSameMCLL(barIndex, mNumberOfSRVerified)) - { - // - double selectedMCLL = hMarket.pv.GetMCLL(barIndex); - AddSRValue(selectedMCLL); - } - - // - if (hMarket.pv.IsSameLCHH(barIndex, mNumberOfSRVerified)) - { - // - double selectedLCHH = hMarket.pv.GetLCHH(barIndex); - AddSRValue(selectedLCHH); - } - - // - if (hMarket.pv.IsSameLCLL(barIndex, mNumberOfSRVerified)) - { - // - double selectedLCLL = hMarket.pv.GetLCLL(barIndex); - AddSRValue(selectedLCLL); - } - - // - if (hMarket.pv.IsSameHCHH(barIndex, mNumberOfSRVerified)) - { - // - double selectedHCHH = hMarket.pv.GetHCHH(barIndex); - AddSRValue(selectedHCHH); - } - - // - if (hMarket.pv.IsSameHCLL(barIndex, mNumberOfSRVerified)) - { - // - double selectedHCLL = hMarket.pv.GetHCLL(barIndex); - AddSRValue(selectedHCLL); - } - - // - // Add Candelstick Pivots ... - - // - // XOHCL sPBar = sMarket.GetBar(barIndex + 1); - // AddSRValue(sPBar); - - // - XOHCL mPBar = mMarket.GetBar(barIndex + 1); - AddSRValue(mPBar); - - // - XOHCL lPBar = lMarket.GetBar(barIndex + 1); - AddSRValue(lPBar); - - // - XOHCL hPBar = hMarket.GetBar(barIndex + 1); - AddSRValue(hPBar); - - // - int after = CountSupportResistances(); - - // - if (after > before) - { - // - string message = "Found: " + ToString(after - before) + " new Pivot for " + GetSymbol() + " ..."; - Print(message); - } - } - - // - void FindSupportAndResistances() - { - // - bool hasEnough = HasEnoughSupportAndResistance(); - if (hasEnough) - { - // - // if (IsNewBar()) - // { - // UpdateSupportsAndResistances(); - // } - return; - } - - // - int idx = 0; - while (!HasEnoughSupportAndResistance()) - { - // - UpdateSupportsAndResistances(idx); - - // - if (HasEnoughSupportAndResistance()) - { - break; - } - - // - idx += 50; - - // - // Print("idx: " + ToString(idx) + ", Count: " + ToString(CountSupportResistances())); - Print("Pivots: " + ToString(CountSupportResistances())); - } - } - - // - void AddSRValue(double value) - { - // - if (value <= 0) - { - return; - } - - // - AddIfNotExists( - value, - mSupportResistances // - ); - } - - // - void AddSRValue(XOHCL &bar) - { - // - if (!bar.IsValid()) - { - return; - } - - // - AddSRValue(bar.open); - AddSRValue(bar.high); - AddSRValue(bar.close); - AddSRValue(bar.low); - } - // // Private ... private: @@ -2779,765 +1063,6 @@ private: // int mNumberOfItems; // Number of Buffer Ites Read in Conditions ... - // - // Support and Resistance ... - - // - int mNumberOfSRVerified; // Number of Verifications for Selecting Support and Resistances ... - - // - int mMinRequiredSupportAndResistances; // Minimum Requirement Supports and Resistances ... - - // - double mSupportResistances[]; // Holds Supports and Resistances ... - - // - // Bullish and Bearish Scores ... - - // - double mBullishScore[]; - double mBearishScore[]; - - // - // Store Market Conditions Scores ... - void AddScores(X121MarketConditions &conditions) - { - // - static datetime lasrScoreAdded = NULL; - ENUM_TIMEFRAMES mPeriod = GetPeriod(); - int seconds = PeriodSeconds(mPeriod); - datetime cTime = TimeCurrent(); - int dateDiff = (int)cTime - (int)lasrScoreAdded; - bool canDo = - // - lasrScoreAdded == NULL - ? true - : dateDiff >= seconds - // - ; - if (!canDo) - { - return; - } - - // - lasrScoreAdded = cTime; - - // - double bullishScore = 0; - double bearishScore = 0; - conditions.GenerateScore( - bullishScore, - bearishScore // - ); - - // - // Generate Summary ... - string summary = conditions.GenerateSummary( - true, // Only Summary ... - true // Only Cycles Summary ... - ); - Comment(summary); - - // - ArraySetAsSeries(mBullishScore, false); - ArraySetAsSeries(mBearishScore, false); - - // - Add( - bullishScore, - mBullishScore // - ); - - // - Add( - bearishScore, - mBearishScore // - ); - - // - ArraySetAsSeries(mBullishScore, true); - ArraySetAsSeries(mBearishScore, true); - - // - // string scoreMSG = "Scores: \nBullihs: " + ToString(bullishScore) + "\nBearish: " + ToString(bearishScore); - // Comment(scoreMSG); - } - - // - // Find Bullish Score Averages ... - double GetBullishScoreAverage( - int start = 0, - int count = 7 // - ) - { - // - return GetAverage( - mBullishScore, - start, - count // - ); - } - - // - // Find Bullish Scores Max Value ... - double GetBullishScoreMax( - int start = 0, - int count = 71 // - ) - { - // - return GetMax( - mBullishScore, - start, - count // - ); - } - - // - // Find Bullish Scores Min Value ... - double GetBullishScoreMin( - int start = 0, - int count = 71 // - ) - { - // - return GetMin( - mBullishScore, - start, - count // - ); - } - - // - // Find Bearish Score Averages ... - double GetBearishScoreAverage( - int start = 0, - int count = 7 // - ) - { - // - return GetAverage( - mBearishScore, - start, - count // - ); - } - - // - // Find Bearish Scores Max Value ... - double GetBearishScoreMax( - int start = 0, - int count = 71 // - ) - { - // - return GetMax( - mBearishScore, - start, - count // - ); - } - - // - // Find Bearish Scores Min Value ... - double GetBearishScoreMin( - int start = 0, - int count = 71 // - ) - { - // - return GetMin( - mBearishScore, - start, - count // - ); - } - - // - bool IsScorePassedForLong() - { - // - double bullishScore = mBullishScore[0]; - double bullishScoreAVG7 = GetBullishScoreAverage(0, 7); - - // - double bearishScore = mBearishScore[0]; - double bearishScoreAVG7 = GetBearishScoreAverage(0, 7); - - // - bool result = - // - ArraySize(mBullishScore) >= 7 && - ArraySize(mBearishScore) >= 7 && - bullishScore > bearishScore && - bullishScore > mBullishScore[1] && - bullishScore > bullishScoreAVG7 && - bearishScore < bearishScoreAVG7 - // - ; - - // - return result; - } - - // - bool IsScorePassedForShort() - { - - // - double bullishScore = mBullishScore[0]; - double bullishScoreAVG7 = GetBullishScoreAverage(0, 7); - - // - double bearishScore = mBearishScore[0]; - double bearishScoreAVG7 = GetBearishScoreAverage(0, 7); - - // - bool result = - // - ArraySize(mBullishScore) >= 7 && - ArraySize(mBearishScore) >= 7 && - bearishScore > bullishScore && - bearishScore > mBearishScore[1] && - bearishScore > bearishScoreAVG7 && - bullishScore < bullishScoreAVG7 - // - ; - - // - return result; - } - - // - // Signallers ... - - // - bool mIsLongEnable; - bool mIsShortEnable; - - // - bool mIsXSPSignalProviderEnable; - bool mIsXTESTSignalProviderEnable; - bool mIsX128SignalProviderEnable; - bool mIsX92SignalProviderEnable; - bool mIsX786SignalProviderEnable; - bool mIsX121SignalProviderEnable; - bool mIsX110SignalProviderEnable; - - // - // - // Detect Signal ... - bool HasSpecificSignal( - int barIndex, // Specified Bar Index ... - ENUM_POSITION_TYPE mType, // Specific Signal Type ... - string &provider, // Signal Provider ... - int &signalPusher, // Number Of Same Time Signals ... - X121MarketConditions &mConditions, // Specified Market Conition ... - double &providedSL, - double &providedTP, - double &providedR2r // - ) - { - // - bool result = false; - - // - // Validate Signal Type is Enables ... - bool isLong = IsLong(mType); - result = - (isLong && mIsLongEnable) || - (!isLong && mIsShortEnable); - if (!result) - { - return result; - } - - // - // Now we have to Filter based on Enabled Signal Providers ... - - // - // Long ... - if (isLong && mIsLongEnable) - { - // - XSignal lSignal; - - // - signalPusher = 0; - - // - bool hasXSPSignal = false; - bool hasXTESTSignal = false; - bool hasX786Signal = false; - bool hasX121Signal = false; - bool hasX110Signal = false; - bool hasX92Signal = false; - bool hasX128Signal = false; - - // - // XPS ... - if (mIsXSPSignalProviderEnable) - { - // - hasXSPSignal = XSPHasSpecifiedLongSignal( - mConditions, - providedSL, - providedTP, - providedR2r // - ); - - // - if (hasXSPSignal) - { - // - if (!IsValid(provider)) - { - provider = ToString(XSP); - } - - // - signalPusher++; - } - } - - // - // XTEST ... - if (mIsXTESTSignalProviderEnable) - { - // - hasXTESTSignal = XTESTHasSpecifiedLongSignal( - mConditions, - providedSL, - providedTP, - providedR2r // - ); - - // - if (hasXTESTSignal) - { - // - if (!IsValid(provider)) - { - provider = ToString(XTEST); - } - - // - signalPusher++; - } - } - - // - // X786 ... - if (mIsX786SignalProviderEnable) - { - // - hasX786Signal = X786HasSpecifiedLongSignal( - mConditions, - providedSL, - providedTP, - providedR2r // - ); - - // - if (hasX786Signal) - { - // - if (!IsValid(provider)) - { - provider = ToString(X786); - } - - // - signalPusher++; - } - } - - // - // X121 ... - if (mIsX121SignalProviderEnable) - { - // - hasX121Signal = X121HasSpecifiedLongSignal( - mConditions, - providedSL, - providedTP, - providedR2r // - ); - - // - if (hasX121Signal) - { - // - if (!IsValid(provider)) - { - provider = ToString(X121); - } - - // - signalPusher++; - } - } - - // - // X110 ... - if (mIsX110SignalProviderEnable) - { - // - hasX110Signal = X110HasSpecifiedLongSignal( - mConditions, - providedSL, - providedTP, - providedR2r // - ); - - // - if (hasX110Signal) - { - // - if (!IsValid(provider)) - { - provider = ToString(X110); - } - - // - signalPusher++; - } - } - - // - // X92 ... - if (mIsX92SignalProviderEnable) - { - // - hasX92Signal = X92HasSpecifiedLongSignal( - mConditions, - providedSL, - providedTP, - providedR2r // - ); - - // - if (hasX92Signal) - { - // - if (!IsValid(provider)) - { - provider = ToString(X92); - } - - // - signalPusher++; - } - } - - // - // X128 ... - if (mIsX128SignalProviderEnable) - { - // - hasX128Signal = X128HasSpecifiedLongSignal( - mConditions, - providedSL, - providedTP, - providedR2r // - ); - - // - if (hasX128Signal) - { - // - if (!IsValid(provider)) - { - provider = ToString(X128); - } - - // - signalPusher++; - } - } - - // - result = - // - hasXSPSignal - // - || - // - hasXTESTSignal - // - || - // - hasX786Signal - // - || - // - hasX121Signal - // - || - // - hasX110Signal - // - || - // - hasX92Signal - // - || - // - hasX128Signal - // - ; - - // - if (result) - { - return result; - } - } - - // - // Short ... - if (!isLong && mIsShortEnable) - { - // - XSignal sSignal; - - // - signalPusher = 0; - - // - bool hasXSPSignal = false; - bool hasXTESTSignal = false; - bool hasX786Signal = false; - bool hasX121Signal = false; - bool hasX110Signal = false; - bool hasX92Signal = false; - bool hasX128Signal = false; - - // - // XSP ... - if (mIsXSPSignalProviderEnable) - { - // - hasXSPSignal = XSPHasSpecifiedShortSignal( - mConditions, - providedSL, - providedTP, - providedR2r // - ); - - // - if (hasXSPSignal) - { - // - if (!IsValid(provider)) - { - provider = ToString(XSP); - } - - // - signalPusher++; - } - } - - // - // XTEST ... - if (mIsXTESTSignalProviderEnable) - { - // - hasXTESTSignal = XTESTHasSpecifiedShortSignal( - mConditions, - providedSL, - providedTP, - providedR2r // - ); - - // - if (hasXTESTSignal) - { - // - if (!IsValid(provider)) - { - provider = ToString(XTEST); - } - - // - signalPusher++; - } - } - - // - // X786 ... - if (mIsX786SignalProviderEnable) - { - // - hasX786Signal = X786HasSpecifiedShortSignal( - mConditions, - providedSL, - providedTP, - providedR2r // - ); - - // - if (hasX786Signal) - { - // - if (!IsValid(provider)) - { - provider = ToString(X786); - } - - // - signalPusher++; - } - } - - // - // X121 ... - if (mIsX121SignalProviderEnable) - { - // - hasX121Signal = X121HasSpecifiedShortSignal( - mConditions, - providedSL, - providedTP, - providedR2r // - ); - - // - if (hasX121Signal) - { - // - if (!IsValid(provider)) - { - provider = ToString(X121); - } - - // - signalPusher++; - } - } - - // - // X110 ... - if (mIsX110SignalProviderEnable) - { - // - hasX110Signal = X110HasSpecifiedShortSignal( - mConditions, - providedSL, - providedTP, - providedR2r // - ); - - // - if (hasX110Signal) - { - // - if (!IsValid(provider)) - { - provider = ToString(X110); - } - - // - signalPusher++; - } - } - - // - // X92 ... - if (mIsX92SignalProviderEnable) - { - // - hasX92Signal = X92HasSpecifiedShortSignal( - mConditions, - providedSL, - providedTP, - providedR2r // - ); - - // - if (hasX92Signal) - { - // - if (!IsValid(provider)) - { - provider = ToString(X92); - } - - // - signalPusher++; - } - } - - // - // X128 ... - if (mIsX128SignalProviderEnable) - { - // - hasX128Signal = X128HasSpecifiedShortSignal( - mConditions, - providedSL, - providedTP, - providedR2r // - ); - - // - if (hasX128Signal) - { - // - if (!IsValid(provider)) - { - provider = ToString(X128); - } - - // - signalPusher++; - } - } - - // - result = - // - hasXSPSignal - // - || - // - hasXTESTSignal - // - || - // - hasX786Signal - // - || - // - hasX121Signal - // - || - // - hasX110Signal - // - || - // - hasX92Signal - // - || - // - hasX128Signal - // - ; - - // - if (result) - { - return result; - } - } - - // - return result; - } - // void CalculateConditions( X121MarketConditions &mConditions, // Market Conditions Result @@ -3622,662 +1147,6 @@ private: ); } - // - // Signalling based On Signallers ... - - // - // XSP ... - - // - bool XSPHasSpecifiedLongSignal( - X121MarketConditions &mConditions, // - double &sl, // Provided SL ... - double &tp, // Provided TP ... - double &r2r // Risk Reward Ratio ... - ) - { - // - bool result = false; - - // - return result; - } - - // - bool XSPHasSpecifiedShortSignal( - X121MarketConditions &mConditions, // - double &sl, // Provided SL ... - double &tp, // Provided TP ... - double &r2r // Risk Reward Ratio ... - ) - { - // - bool result = false; - - // - return result; - } - - // - // XTEST ... - - // - bool XTESTHasSpecifiedLongSignal( - X121MarketConditions &mConditions, // - double &sl, // Provided SL ... - double &tp, // Provided TP ... - double &r2r // Risk Reward Ratio ... - ) - { - // - bool result = false; - - // - return result; - } - - // - bool XTESTHasSpecifiedShortSignal( - X121MarketConditions &mConditions, // - double &sl, // Provided SL ... - double &tp, // Provided TP ... - double &r2r // Risk Reward Ratio ... - ) - { - // - bool result = false; - - // - return result; - } - - // - // X786 ... - // TODO: Add Documentation Here ... - - // - bool X786HasSpecifiedLongSignal( - X121MarketConditions &mConditions, // - double &sl, // Provided SL ... - double &tp, // Provided TP ... - double &r2r // Risk Reward Ratio ... - ) - { - // - bool result = false; - - // - int zIndex = 0; - int cIndex = zIndex + 1; - int pIndex = cIndex + 1; - - // - bool cHasX786 = cMarket.HasX786LongConditions(); - bool sHasX786 = sMarket.HasX786LongConditions(); - bool mHasX786 = mMarket.HasX786LongConditions(); - bool lHasX786 = lMarket.HasX786LongConditions(); - bool hHasX786 = hMarket.HasX786LongConditions(); - - // - double cMarketSL = cMarket.don.GetLowerH(cIndex); - double sMarketSL = sMarket.don.GetLowerH(cIndex); - double mMarketSL = mMarket.don.GetLowerH(cIndex); - double lMarketSL = lMarket.don.GetLowerH(cIndex); - double hMarketSL = hMarket.don.GetLowerH(cIndex); - - // - bool condition1 = - // - ((cHasX786 && - sHasX786 && - mHasX786) - // - || - // - (cHasX786 && - mHasX786 && - lHasX786)) - // - ; - - // - bool condition2 = - // - ((sHasX786 && - mHasX786 && - lHasX786) - // - || - // - (sHasX786 && - lHasX786 && - hHasX786)) - // - ; - - // - bool condition3 = - // - ((mHasX786 && - lHasX786 && - hHasX786) - // - || - // - (mHasX786 && - hHasX786 && - sHasX786)) - // - ; - - // - bool condition4 = - // - (lHasX786 && - hHasX786 && - mHasX786) - // - ; - - // - if (condition1) - { - // - double sls[] = { - cMarketSL, - sMarketSL, - mMarketSL // - }; - - // - sl = GetAverage(sls); - } - else if (condition2) - { - // - double sls[] = { - sMarketSL, - mMarketSL, - lMarketSL // - }; - - // - sl = GetAverage(sls); - } - else if (condition3) - { - // - double sls[] = { - mMarketSL, - lMarketSL, - hMarketSL // - }; - - // - sl = GetAverage(sls); - } - else if (condition4) - { - // - double sls[] = { - lMarketSL, - hMarketSL // - }; - - // - sl = GetAverage(sls); - } - - // - result = - // - condition1 - // - || - // - condition2 - // - || - // - condition3 - // - || - // - condition4 - // - ; - - // - if (result) - { - r2r = 1; - } - - // - return result; - } - - // - bool X786HasSpecifiedShortSignal( - X121MarketConditions &mConditions, // - double &sl, // Provided SL ... - double &tp, // Provided TP ... - double &r2r // Risk Reward Ratio ... - ) - { - // - bool result = false; - - // - int zIndex = 0; - int cIndex = zIndex + 1; - int pIndex = cIndex + 1; - - // - bool cHasX786 = cMarket.HasX786ShortConditions(); - bool sHasX786 = sMarket.HasX786ShortConditions(); - bool mHasX786 = mMarket.HasX786ShortConditions(); - bool lHasX786 = lMarket.HasX786ShortConditions(); - bool hHasX786 = hMarket.HasX786ShortConditions(); - - // - double cMarketSL = cMarket.don.GetUpperL(cIndex); - double sMarketSL = sMarket.don.GetUpperL(cIndex); - double mMarketSL = mMarket.don.GetUpperL(cIndex); - double lMarketSL = lMarket.don.GetUpperL(cIndex); - double hMarketSL = hMarket.don.GetUpperL(cIndex); - - // - bool condition1 = - // - ((cHasX786 && - sHasX786) - // - || - // - (cHasX786 && - mHasX786)) - // - ; - - // - bool condition2 = - // - ((sHasX786 && - mHasX786) - // - || - // - (sHasX786 && - lHasX786)) - // - ; - - // - bool condition3 = - // - ((mHasX786 && - lHasX786) - // - || - // - (mHasX786 && - hHasX786)) - // - ; - - // - bool condition4 = - // - (lHasX786 && - hHasX786) - // - ; - - // - if (condition1) - { - // - double sls[] = { - cMarketSL, - sMarketSL, - mMarketSL // - }; - - // - sl = GetAverage(sls); - } - else if (condition2) - { - // - double sls[] = { - sMarketSL, - mMarketSL, - lMarketSL // - }; - - // - sl = GetAverage(sls); - } - else if (condition3) - { - // - double sls[] = { - mMarketSL, - lMarketSL, - hMarketSL // - }; - - // - sl = GetAverage(sls); - } - else if (condition4) - { - // - double sls[] = { - lMarketSL, - hMarketSL // - }; - - // - sl = GetAverage(sls); - } - - // - result = - // - condition1 - // - || - // - condition2 - // - || - // - condition3 - // - || - // - condition4 - // - ; - - // - if (result) - { - r2r = 1; - } - - // - return result; - } - - // - // X121 ... - // TODO: Add Documentation Here ... - - // - bool X121HasSpecifiedLongSignal( - X121MarketConditions &mConditions, // - double &sl, // Provided SL ... - double &tp, // Provided TP ... - double &r2r // Risk Reward Ratio ... - ) - { - // - bool result = false; - - // - int zIndex = 0; - int cIndex = zIndex + 1; - int pIndex = cIndex + 1; - - // - bool cHasX121 = cMarket.HasX121LongConditions(); - bool sHasX121 = sMarket.HasX121LongConditions(); - bool mHasX121 = mMarket.HasX121LongConditions(); - bool lHasX121 = lMarket.HasX121LongConditions(); - bool hHasX121 = hMarket.HasX121LongConditions(); - - // - if (cHasX121) - { - sl = cMarket.mrb.GetSlow(cIndex); - } - else if (sHasX121) - { - sl = sMarket.mrb.GetSlow(cIndex); - } - else if (mHasX121) - { - sl = mMarket.mrb.GetSlow(cIndex); - } - else if (lHasX121) - { - sl = lMarket.mrb.GetSlow(cIndex); - } - else if (hHasX121) - { - sl = hMarket.mrb.GetSlow(cIndex); - } - - // - result = - // - cHasX121 - // - && - // - sHasX121 - // - && - // - mHasX121 - // - && - // - lHasX121 - // - // && - // // - // hHasX121 - // - ; - - // - if (result) - { - // - r2r = 1; - sl = cMarket.mrb.GetSlow(cIndex); - } - - // - return result; - } - - // - bool X121HasSpecifiedShortSignal( - X121MarketConditions &mConditions, // - double &sl, // Provided SL ... - double &tp, // Provided TP ... - double &r2r // Risk Reward Ratio ... - ) - { - // - bool result = false; - - // - int zIndex = 0; - int cIndex = zIndex + 1; - int pIndex = cIndex + 1; - - // - bool cHasX121 = cMarket.HasX121ShortConditions(); - bool sHasX121 = sMarket.HasX121ShortConditions(); - bool mHasX121 = mMarket.HasX121ShortConditions(); - bool lHasX121 = lMarket.HasX121ShortConditions(); - bool hHasX121 = hMarket.HasX121ShortConditions(); - - // - if (cHasX121) - { - sl = cMarket.mrb.GetFast(cIndex); - } - else if (sHasX121) - { - sl = sMarket.mrb.GetFast(cIndex); - } - else if (mHasX121) - { - sl = mMarket.mrb.GetFast(cIndex); - } - else if (lHasX121) - { - sl = lMarket.mrb.GetFast(cIndex); - } - else if (hHasX121) - { - sl = hMarket.mrb.GetFast(cIndex); - } - - // - result = - // - cHasX121 - // - && - // - sHasX121 - // - && - // - mHasX121 - // - && - // - lHasX121 - // - // || - // // - // hHasX121 - // - ; - - // - if (result) - { - // - r2r = 1; - sl = cMarket.mrb.GetFast(cIndex); - } - - // - return result; - } - - // - // X110 ... - // TODO: Add Documentation Here ... - - // - bool X110HasSpecifiedLongSignal( - X121MarketConditions &mConditions, // - double &sl, // Provided SL ... - double &tp, // Provided TP ... - double &r2r // Risk Reward Ratio ... - ) - { - // - bool result = false; - - // - return result; - } - - // - bool X110HasSpecifiedShortSignal( - X121MarketConditions &mConditions, // - double &sl, // Provided SL ... - double &tp, // Provided TP ... - double &r2r // Risk Reward Ratio ... - ) - { - // - bool result = false; - - // - return result; - } - - // - // X92 ... - // TODO: Add Documentation Here ... - - // - bool X92HasSpecifiedLongSignal( - X121MarketConditions &mConditions, // - double &sl, // Provided SL ... - double &tp, // Provided TP ... - double &r2r // Risk Reward Ratio ... - ) - { - // - bool result = false; - - // - return result; - } - - // - bool X92HasSpecifiedShortSignal( - X121MarketConditions &mConditions, // - double &sl, // Provided SL ... - double &tp, // Provided TP ... - double &r2r // Risk Reward Ratio ... - ) - { - // - bool result = false; - - // - return result; - } - - // - // X128 ... - // TODO: Add Documentation Here ... - - // - bool X128HasSpecifiedLongSignal( - X121MarketConditions &mConditions, // - double &sl, // Provided SL ... - double &tp, // Provided TP ... - double &r2r // Risk Reward Ratio ... - ) - { - // - bool result = false; - - // - return result; - } - - // - bool X128HasSpecifiedShortSignal( - X121MarketConditions &mConditions, // - double &sl, // Provided SL ... - double &tp, // Provided TP ... - double &r2r // Risk Reward Ratio ... - ) - { - // - bool result = false; - - // - return result; - } - // }; @@ -4289,12 +1158,9 @@ private: struct X121ProviderDescriptor { // - string symbol; // Trading Symbol - ENUM_TIMEFRAMES period; // Trading Timeframe - double staticVolume; // Static Volume for Positions - bool allowLong; // Allow Long Signals - bool allowShort; // Allow Short Signals - ENUM_XSIGNAL_PROVIDERS signallers[]; // Allowed Signal Providers + string symbol; // Trading Symbol + ENUM_TIMEFRAMES period; // Trading Timeframe + XSignallerDescriptor *signallers[]; // Allowed Signal Providers // X121ProviderInputs inputs; @@ -4316,12 +1182,7 @@ struct X121ProviderDescriptor // result = this.Init( this.symbol, - this.period, - this.signallers, - this.allowLong, - this.allowShort, - this.staticVolume // - ); + this.period); // return result; @@ -4329,37 +1190,8 @@ struct X121ProviderDescriptor // bool Init( - ENUM_XSIGNAL_PROVIDERS &mSignallers[], // Allowed Signal Providers - bool mAllowLong = true, // Allow Long Signals - bool mAllowShort = true, // Allow Short Signals - double mStaticVolume = 0.01 // Static Volume for Positions - ) - { - // - bool result = false; - - // - result = this.Init( - this.symbol, - this.period, - mSignallers, - mAllowLong, - mAllowShort, - mStaticVolume // - ); - - // - return result; - } - - // - bool Init( - string mSymbol, // Trading Symbol - ENUM_TIMEFRAMES mPeriod, // Trading Timeframe - ENUM_XSIGNAL_PROVIDERS &mSignallers[], // Allowed Signal Providers - bool mAllowLong = true, // Allow Long Signals - bool mAllowShort = true, // Allow Short Signals - double mStaticVolume = 0.01 // Static Volume for Positions + string mSymbol, // Trading Symbol + ENUM_TIMEFRAMES mPeriod // Trading Timeframe ) { // @@ -4371,9 +1203,7 @@ struct X121ProviderDescriptor inputs.IsValid() && IsValid(mSymbol) && IsValid(mPeriod) && - NotEmpty(mStaticVolume) && - (allowLong || allowShort) && - ArraySize(mSignallers) > 0 + IsValidSize(ArraySize(this.signallers)) // ; if (!result) @@ -4384,59 +1214,18 @@ struct X121ProviderDescriptor // this.symbol = mSymbol; this.period = mPeriod; - this.allowLong = mAllowLong; - this.allowShort = mAllowShort; - this.staticVolume = mStaticVolume; - - // - ENUM_XSIGNAL_PROVIDERS tmp[]; - Copy( - mSignallers, - tmp // - ); - Copy( - tmp, - this.signallers // - ); // // Instantiate Provider ... provider = new XSCX121Provider( this.symbol, - this.period, - this.staticVolume // + this.period // ); - // - // Set Long/Short State ... - - // - provider - .SetSignalTypeState( - POSITION_TYPE_BUY, - this.allowLong // - ); - - // - provider - .SetSignalTypeState( - POSITION_TYPE_SELL, - this.allowShort // - ); - - // - // Enable Required Signallers ... - provider - .SetSignalProviderStates( - this.signallers, - true // - ); - // // Now Must to Initialize Provider ... result = provider.Init( - this.inputs // - ); + this.inputs); // return result; @@ -4463,11 +1252,9 @@ struct X121ProviderDescriptor // IsValid(symbol) && IsValid(period) && - NotEmpty(staticVolume) && (validateInputs ? inputs.IsValid() : true) && - (allowLong || allowShort) && ArraySize(signallers) > 0 // ; @@ -4490,17 +1277,466 @@ struct X121ProviderDescriptor return result; } + // + int signallersCount = ArraySize(this.signallers); + result = IsValidSize(signallersCount); + if (!result) + { + return result; + } + // // Clear Signal and Conditions ... Clean(); // - result = provider.HasSignal( - barIndex, - signal, - conditions // + // Check Waits Until New Bar ... + result = !this.provider.CanIgnoreProcess(); + if (!result) { + return result; + } + + // + // Fill Market Conditions ... + provider.GetMarketConditions( + this.conditions, + barIndex // ); + // + // Verifiers ... + int longVerifiers = 0; + int shortVerifiers = 0; + + // + double mR2R = 0; + double mVolume = 0; + double slPrice = 0; + double tpPrice = 0; + string mProvider = NULL; + + // + // Current Market ... + double cLNSL = 0; + double cLNTP = 0; + double cSHSL = 0; + double cSHTP = 0; + bool cHasLong = false; + bool cHasShort = false; + double cBullishScore = 0; + double cBearishScore = 0; + this.conditions.cMarketConditions.GenerateScore( + cBullishScore, + cBearishScore // + ); + + // + // Short Market ... + double sLNSL = 0; + double sLNTP = 0; + double sSHSL = 0; + double sSHTP = 0; + bool sHasLong = false; + bool sHasShort = false; + double sBullishScore = 0; + double sBearishScore = 0; + this.conditions.sMarketConditions.GenerateScore( + sBullishScore, + sBearishScore // + ); + + // + // Medium Market ... + double mLNSL = 0; + double mLNTP = 0; + double mSHSL = 0; + double mSHTP = 0; + bool mHasLong = false; + bool mHasShort = false; + double mBullishScore = 0; + double mBearishScore = 0; + this.conditions.mMarketConditions.GenerateScore( + mBullishScore, + mBearishScore // + ); + + // + // Long Market ... + double lLNSL = 0; + double lLNTP = 0; + double lSHSL = 0; + double lSHTP = 0; + bool lHasLong = false; + bool lHasShort = false; + double lBullishScore = 0; + double lBearishScore = 0; + this.conditions.lMarketConditions.GenerateScore( + lBullishScore, + lBearishScore // + ); + + // + // Hind Market ... + double hLNSL = 0; + double hLNTP = 0; + double hSHSL = 0; + double hSHTP = 0; + bool hHasLong = false; + bool hHasShort = false; + double hBullishScore = 0; + double hBearishScore = 0; + this.conditions.hMarketConditions.GenerateScore( + hBullishScore, + hBearishScore // + ); + + // + for (int i = 0; i < signallersCount; i++) + { + // + // Check all Markets for Long Conditions ... + + // + // Current Market ... + cLNSL = 0; + cLNTP = 0; + cHasLong = this.signallers[i] + .HasLongConditions( + this.conditions.cMarketConditions, + cLNSL, + cLNTP // + ); + if (cHasLong) + { + // + slPrice = cLNSL; + tpPrice = cLNTP; + longVerifiers++; + mR2R = this.signallers[i].r2r; + mProvider = this.signallers[i].GetName(); + mVolume = this.signallers[i].staticVolumeLong; + } + + // + // Short Market ... + sLNSL = 0; + sLNTP = 0; + sHasLong = this.signallers[i] + .HasLongConditions( + this.conditions.sMarketConditions, + sLNSL, + sLNTP // + ); + if (sHasLong) + { + // + slPrice = sLNSL; + tpPrice = sLNTP; + longVerifiers++; + mR2R = this.signallers[i].r2r; + mProvider = this.signallers[i].GetName(); + mVolume = this.signallers[i].staticVolumeLong; + } + + // + // Medium Market ... + mLNSL = 0; + mLNTP = 0; + mHasLong = this.signallers[i] + .HasLongConditions( + this.conditions.mMarketConditions, + mLNSL, + mLNTP // + ); + if (mHasLong) + { + // + slPrice = mLNSL; + tpPrice = mLNTP; + longVerifiers++; + mR2R = this.signallers[i].r2r; + mProvider = this.signallers[i].GetName(); + mVolume = this.signallers[i].staticVolumeLong; + } + + // + // Long Market ... + lLNSL = 0; + lLNTP = 0; + lHasLong = this.signallers[i] + .HasLongConditions( + this.conditions.lMarketConditions, + lLNSL, + lLNTP // + ); + if (lHasLong) + { + // + slPrice = lLNSL; + tpPrice = lLNTP; + longVerifiers++; + mR2R = this.signallers[i].r2r; + mProvider = this.signallers[i].GetName(); + mVolume = this.signallers[i].staticVolumeLong; + } + + // + // Hind Market ... + hLNSL = 0; + hLNTP = 0; + hHasLong = this.signallers[i] + .HasLongConditions( + this.conditions.hMarketConditions, + hLNSL, + hLNTP // + ); + if (hHasLong) + { + // + slPrice = hLNSL; + tpPrice = hLNTP; + longVerifiers++; + mR2R = this.signallers[i].r2r; + mProvider = this.signallers[i].GetName(); + mVolume = this.signallers[i].staticVolumeLong; + } + + // + // Check All Markets For Short Signals ... + + // + // Current Market ... + cSHSL = 0; + cSHTP = 0; + cHasShort = this.signallers[i] + .HasShortConditions( + this.conditions.cMarketConditions, + cSHSL, + cSHTP // + ); + if (cHasShort) + { + // + slPrice = cSHSL; + tpPrice = cSHTP; + shortVerifiers++; + mR2R = this.signallers[i].r2r; + mProvider = this.signallers[i].GetName(); + mVolume = this.signallers[i].staticVolumeShort; + } + + // + // Short Market ... + sSHSL = 0; + sSHTP = 0; + sHasShort = this.signallers[i] + .HasShortConditions( + this.conditions.sMarketConditions, + sSHSL, + sSHTP // + ); + if (sHasShort) + { + // + slPrice = sSHSL; + tpPrice = sSHTP; + shortVerifiers++; + mR2R = this.signallers[i].r2r; + mProvider = this.signallers[i].GetName(); + mVolume = this.signallers[i].staticVolumeShort; + } + + // + // Medium Market ... + mSHSL = 0; + mSHTP = 0; + mHasShort = this.signallers[i] + .HasShortConditions( + this.conditions.mMarketConditions, + mSHSL, + mSHTP // + ); + if (mHasShort) + { + // + slPrice = mSHSL; + tpPrice = mSHTP; + shortVerifiers++; + mR2R = this.signallers[i].r2r; + mProvider = this.signallers[i].GetName(); + mVolume = this.signallers[i].staticVolumeShort; + } + + // + // Long Market ... + lSHSL = 0; + lSHTP = 0; + lHasShort = this.signallers[i] + .HasShortConditions( + this.conditions.lMarketConditions, + lSHSL, + lSHTP // + ); + if (lHasShort) + { + // + slPrice = lSHSL; + tpPrice = lSHTP; + shortVerifiers++; + mR2R = this.signallers[i].r2r; + mProvider = this.signallers[i].GetName(); + mVolume = this.signallers[i].staticVolumeShort; + } + + // + // Hind Market ... + hSHSL = 0; + hSHTP = 0; + hHasShort = this.signallers[i] + .HasShortConditions( + this.conditions.hMarketConditions, + hSHSL, + hSHTP // + ); + if (hHasShort) + { + // + slPrice = hSHSL; + tpPrice = hSHTP; + shortVerifiers++; + mR2R = this.signallers[i].r2r; + mProvider = this.signallers[i].GetName(); + mVolume = this.signallers[i].staticVolumeShort; + } + } + + // + bool hasLong = + // + cHasLong + // + || + // + sHasLong + // + || + // + mHasLong + // + || + // + lHasLong + // + || + // + hHasLong + // + ; + + // + bool hasShort = + // + cHasShort + // + || + // + sHasShort + // + || + // + mHasShort + // + || + // + lHasShort + // + || + // + hHasShort + // + ; + + // + result = hasLong || hasShort; + if (!result) + { + return result; + } + + // + result = + hasLong + ? longVerifiers > 1 + : shortVerifiers > 1; + if (!result) + { + return result; + } + + // + // Generate Signal ... + this.signal.Clean(); + + // + ENUM_POSITION_TYPE mType = + hasLong + ? POSITION_TYPE_BUY + : POSITION_TYPE_SELL; + + // + double mEntry = GetEntry( + this.symbol, + mType // + ); + + // + double mTP = 0; + double mSL = 0; + CalculateTPSL( + mSL, + mTP, + mType, + mEntry, + mR2R, + slPrice, + tpPrice // + ); + + // + result = this.signal.Prepare( + this.symbol, + mProvider, + this.period, + mType, + X_ORDER_MODE_MARKET, + mEntry, + mVolume, + mSL, + mTP // + ); + if (!result) + { + this.signal.Clean(); + } + + // + // Set Wait Until New Bar ... + this.provider.SetWaitsUntilNewBar(true); + + // + return result; + } + + // + // Check for Guards ... + bool HasGuard(XGuard &guards[]) + { + // + Clean(guards); + + // + bool result = IsValidSize(guards); + // return result; } diff --git a/Classes/x-saherelm.x121.x121.provider.class.mq5 b/Classes/x-saherelm.x121.x121.provider.class.mq5 new file mode 100644 index 00000000..9ebb7b6a --- /dev/null +++ b/Classes/x-saherelm.x121.x121.provider.class.mq5 @@ -0,0 +1,97 @@ +/////////////////////////////////////////////////////// +// +// SaherElm IT Center MQL5 Class Library +// ---------------------------------------------- +// Name: X121Signaller +// Description: Signalling using X121 rules ... +// +// +// 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.x121.xmcycle.class.mq5" + +// +// Definitions ... + +// +// Class ... +class X121Signaller : public XSignallerDescriptor +{ + // + // Public ... +public: + // + // Props ... + + // + // Constructor(s) ... + void X121Signaller() + { + name = X121; + } + + // + // Deconstructor ... + void ~X121Signaller() {} + + // + // Override(s) ... + + // + bool HasLongConditions( + const X121MCycleConditions &conditions, // Market Conditions + double &sl, // Hold SL ... + double &tp // Hold TP ... + ) override + { + // + bool result = false; + + // + return result; + } + + // + bool HasShortConditions( + const X121MCycleConditions &conditions, // Market Conditions + double &sl, // Hold SL ... + double &tp // Hold TP ... + ) override + { + // + bool result = false; + + // + return result; + } + + // + // Tools ... + void Default() + { + // + enableLong = true; + enableShort = true; + + // + r2r = 1; + + // + staticVolumeLong = 0.01; + staticVolumeShort = 0.01; + } +}; \ No newline at end of file diff --git a/Classes/x-saherelm.x121.x786.provider.class.mq5 b/Classes/x-saherelm.x121.x786.provider.class.mq5 new file mode 100644 index 00000000..057e4f75 --- /dev/null +++ b/Classes/x-saherelm.x121.x786.provider.class.mq5 @@ -0,0 +1,193 @@ +/////////////////////////////////////////////////////// +// +// SaherElm IT Center MQL5 Class Library +// ---------------------------------------------- +// Name: X786Signaller +// Description: Signalling using X786 rules ... +// +// +// 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.x121.xmcycle.class.mq5" + +// +// Definitions ... + +// +// Class ... +class X786Signaller : public XSignallerDescriptor +{ + // + // Public ... +public: + // + // Props ... + + // + // Constructor(s) ... + void X786Signaller() + { + // + name = X786; + Default(); + } + + // + // Deconstructor ... + void ~X786Signaller() {} + + // + // Override(s) ... + + // + virtual bool HasLongConditions( + const X121MCycleConditions &conditions, // Market Conditions + double &sl, // Hold SL ... + double &tp // Hold TP ... + ) + { + // + bool result = false; + + // + sl = 0; + tp = 0; + + // + result = enableLong; + if (!result) + { + return result; + } + + // + result = + // + (conditions.isSMHKSwitchedToBullish && + (conditions.isTDBullish && + conditions.isCHEBullish && + conditions.isTrendBullish)) + // + || + // + (conditions.isTDSwitchedToBullish && + (conditions.isSMHKBullish && + conditions.isCHEBullish && + conditions.isTrendBullish)) + // + || + // + (conditions.isCHESwitchedToBullish && + (conditions.isTDBullish && + conditions.isSMHKBullish && + conditions.isTrendBullish)) + // + || + // + (conditions.isTrendSwitchedToBullish && + (conditions.isTDBullish && + conditions.isCHEBullish && + conditions.isSMHKBullish)) + // + ; + + // + if (result) { + sl = conditions.donLowerHs[1]; + } + + // + return result; + } + + // + virtual bool HasShortConditions( + const X121MCycleConditions &conditions, // Market Conditions + double &sl, // Hold SL ... + double &tp // Hold TP ... + ) + { + // + bool result = false; + + // + result = enableShort; + if (!result) + { + return result; + } + + // + tp = 0; + sl = 0; + + // + result = + // + (conditions.isSMHKSwitchedToBearish && + (conditions.isTDBearish && + conditions.isCHEBearish && + conditions.isTrendBearish)) + // + || + // + (conditions.isTDSwitchedToBearish && + (conditions.isSMHKBearish && + conditions.isCHEBearish && + conditions.isTrendBearish)) + // + || + // + (conditions.isCHESwitchedToBearish && + (conditions.isTDBearish && + conditions.isSMHKBearish && + conditions.isTrendBearish)) + // + || + // + (conditions.isTrendSwitchedToBearish && + (conditions.isTDBearish && + conditions.isCHEBearish && + conditions.isSMHKBearish)) + // + ; + + // + if (result) { + sl = conditions.donUpperLs[1]; + } + + // + return result; + } + + // + // Tools ... + void Default() + { + // + enableLong = true; + enableShort = true; + + // + r2r = 1; + + // + staticVolumeLong = 0.01; + staticVolumeShort = 0.01; + } +}; \ No newline at end of file diff --git a/Classes/x-saherelm.x121.xea.class.mq5 b/Classes/x-saherelm.x121.xea.class.mq5 index 60c1343f..a8207476 100644 --- a/Classes/x-saherelm.x121.xea.class.mq5 +++ b/Classes/x-saherelm.x121.xea.class.mq5 @@ -208,7 +208,7 @@ public: // XGuard iGuards[]; - bool iHasGuard = iDescriptor.provider.HasGuard(iGuards); + bool iHasGuard = iDescriptor.HasGuard(iGuards); if (iHasGuard) { // diff --git a/Classes/x-saherelm.x121.xmcycle.class.mq5 b/Classes/x-saherelm.x121.xmcycle.class.mq5 index f98c836a..c6568f81 100644 --- a/Classes/x-saherelm.x121.xmcycle.class.mq5 +++ b/Classes/x-saherelm.x121.xmcycle.class.mq5 @@ -40,6 +40,7 @@ #include "../Helpers/x-saherelm.xich.helper.mq5" // +#include "../Libraries/x-saherelm.xtrade.lib.mq5" #include "../Classes/x-saherelm.xalert.class.mq5" // @@ -2383,7 +2384,6 @@ public: // Constructor ... void XSignallerDescriptor() { - Clean(); } // @@ -2607,6 +2607,10 @@ public: { return false; } + + // + // Protected ... +protected: }; // @@ -2726,62 +2730,6 @@ public: return Init(inputs); } - // - bool AddSignaller( - XSignallerDescriptor &signaller // - ) - { - // - bool result = false; - - // - // Validate Signaller ... - result = signaller.IsValid(); - if (!result) - { - return result; - } - - // - AddRef( - signaller, - mSignallers // - ); - - // - return result; - } - - // - int AddSignallers( - XSignallerDescriptor &signallers[] // - ) - { - // - int result = 0; - - // - int count = ArraySize(signallers); - if (!IsValidSize(count)) - { - return result; - } - - // - for (int i = 0; i < count; i++) - { - // - bool isAdded = AddSignaller(signallers[i]); - if (isAdded) - { - result++; - } - } - - // - return result; - } - // // Tools ... @@ -4380,279 +4328,6 @@ public: conditions.isHCLLSwitchedToBeraish = isHCLLSwitchedToBeraish; } - // - // Market Parse Conditions ... - bool HasConditions( - XSignal &signal, // If Any Signal provided, Filled here ... - bool &hasLong, - int &longPusher, - bool &hasShort, - int &shortPusher // - ) - { - // - bool result = false; - - // - longPusher = 0; - shortPusher = 0; - hasLong = false; - hasShort = false; - - // - int count = CountSignallers(); - if (!IsValidSize(count)) - { - return result; - } - - // - X121MCycleConditions conditions; - GetMarketConditions(conditions); - - // - for (int i = 0; i < count; i++) - { - // - bool iHasLong = false; - bool iHasShort = false; - - // - double iTP = 0; - double iTPProvided = 0; - double iSL = 0; - double iSLProvided = 0; - double iEntry = 0; - ENUM_POSITION_TYPE iType; - string iSymbol = GetSymbol(); - double iR2R = mSignallers[i].r2r; - ENUM_TIMEFRAMES iPeriod = GetPeriod(); - string iProvider = mSignallers[i].GetName(); - - // - bool iHasSignal = mSignallers[i].HasConditions( - conditions, - iHasLong, - iHasShort, - iTPProvided, - iSLProvided // - ); - if (iHasSignal) - { - // - // Filling Pusher(s) ... - if (iHasLong) - { - longPusher++; - } - else if (iHasShort) - { - shortPusher++; - } - - // - if (iHasLong && !hasLong) - { - // - hasLong = iHasLong; - - // - // Filling Signal ... - iType = POSITION_TYPE_BUY; - - // - iEntry = GetEntry( - iSymbol, - iType // - ); - - // - CalculateTPSL( - iSL, - iTP, - iType, - iEntry, - iR2R, - iSLProvided, - iTPProvided // - ); - - // - // Fill Signal Here ... - bool isSignalGenerated = mSignallers[i].GenerateMarketSignal( - signal, - iSymbol, - iPeriod, - iType, - iEntry, - iSL, - iTP // - ); - } - else if (iHasShort && !hasShort) - { - // - hasShort = iHasShort; - - // - // Fill Signal Here ... - iType = POSITION_TYPE_SELL; - - // - iEntry = GetEntry( - iSymbol, - iType // - ); - - // - CalculateTPSL( - iSL, - iTP, - iType, - iEntry, - iR2R, - iSLProvided, - iTPProvided // - ); - - // - // Fill Signal Here ... - bool isSignalGenerated = mSignallers[i].GenerateMarketSignal( - signal, - iSymbol, - iPeriod, - iType, - iEntry, - iSL, - iTP // - ); - } - } - } - - // - result = hasLong || hasShort; - - // - return result; - } - - // - // X786 Long ... - bool HasX786LongConditions() - { - // - bool result = false; - - // - X121MCycleConditions conditions; - GetMarketConditions(conditions); - - // - result = - // - (conditions.isSMHKSwitchedToBullish && - (conditions.isTDBullish && - conditions.isCHEBullish && - conditions.isTrendBullish)) - // - || - // - (conditions.isTDSwitchedToBullish && - (conditions.isSMHKBullish && - conditions.isCHEBullish && - conditions.isTrendBullish)) - // - || - // - (conditions.isCHESwitchedToBullish && - (conditions.isTDBullish && - conditions.isSMHKBullish && - conditions.isTrendBullish)) - // - || - // - (conditions.isTrendSwitchedToBullish && - (conditions.isTDBullish && - conditions.isCHEBullish && - conditions.isSMHKBullish)) - // - ; - - // - return result; - } - - // - // X786 Short ... - bool HasX786ShortConditions() - { - // - bool result = false; - - // - X121MCycleConditions conditions; - GetMarketConditions(conditions); - - // - result = - // - (conditions.isSMHKSwitchedToBearish && - (conditions.isTDBearish && - conditions.isCHEBearish && - conditions.isTrendBearish)) - // - || - // - (conditions.isTDSwitchedToBearish && - (conditions.isSMHKBearish && - conditions.isCHEBearish && - conditions.isTrendBearish)) - // - || - // - (conditions.isCHESwitchedToBearish && - (conditions.isTDBearish && - conditions.isSMHKBearish && - conditions.isTrendBearish)) - // - || - // - (conditions.isTrendSwitchedToBearish && - (conditions.isTDBearish && - conditions.isCHEBearish && - conditions.isSMHKBearish)) - // - ; - - // - return result; - } - - // - // X121 Long ... - bool HasX121LongConditions() - { - // - bool result = false; - - // - return result; - } - - // - // X121 Short ... - bool HasX121ShortConditions() - { - // - bool result = false; - - // - return result; - } - - // - // // Initial Market Cycle ... bool Init( @@ -5193,76 +4868,6 @@ private: // X121MCycleInputs mInputs; - // - // Signallers ... - - // - XSignallerDescriptor mSignallers[]; - - // - // Count Signallers ... - int CountSignallers() - { - return ArraySize(mSignallers); - } - - // - // Find Signaller Index ... - int FindSignallerIndex(ENUM_XSIGNAL_PROVIDERS signaller) - { - // - int result = -1; - - // - int count = CountSignallers(); - if (!IsValidSize(count)) - { - return result; - } - - // - for (int i = 0; i < count; i++) - { - // - XSignallerDescriptor iSignaller = mSignallers[i]; - - // - if (iSignaller.name == signaller) - { - // - result = i; - break; - } - } - - // - return result; - } - int FindSignallerIndex(string signaller) - { - // - int result = -1; - - // - if (!IsValid(signaller)) - { - return result; - } - - // - ENUM_XSIGNAL_PROVIDERS mSignaller = ToXSignalProvider(signaller); - if (mSignaller == PROVIDER_NONE) - { - return result; - } - - // - result = FindSignallerIndex(mSignaller); - - // - return result; - } - // // Tools ... @@ -5519,9 +5124,6 @@ struct X121MarketCycleDescriptor // XSCX121Market *market; // Market - // - X121MCycleConditions conditions; // Market Conditions - // // Tools ... diff --git a/Classes/x-saherelm.xprovider.class.mq5 b/Classes/x-saherelm.xprovider.class.mq5 index 46a94374..d9043108 100644 --- a/Classes/x-saherelm.xprovider.class.mq5 +++ b/Classes/x-saherelm.xprovider.class.mq5 @@ -41,9 +41,8 @@ public: // // Constructor ... XSCBaseProvider( - string symbol, // Trading Symbol - ENUM_TIMEFRAMES period, // Trading Period - double staticVolume // Static Volume for Positions + string symbol, // Trading Symbol + ENUM_TIMEFRAMES period // Trading Period ) { // @@ -57,9 +56,6 @@ public: "HOST Period" // ); - - // - mStaticVolume = staticVolume; } // @@ -91,12 +87,6 @@ public: return mCycle.hostPeriod; } - // - double GetStaticVolume() - { - return mStaticVolume; - } - // // Count Bars ... int CountBars() @@ -115,21 +105,6 @@ public: .IsNewBar(); } - // - // Protected ... -protected: - // - // Props ... - - // - double mStaticVolume; // Static Volume for Positions - - // - XMarketCycle mCycle; - - // - bool mWaitsUntilNewBar; - // // Can Ignore Process ... bool CanIgnoreProcess() @@ -146,6 +121,12 @@ protected: // ; + // + if (!result) + { + mWaitsUntilNewBar = false; + } + // return result; } @@ -157,6 +138,24 @@ protected: mWaitsUntilNewBar = !mWaitsUntilNewBar; } + // + void SetWaitsUntilNewBar(bool value) + { + mWaitsUntilNewBar = value; + } + + // + // Protected ... +protected: + // + // Props ... + + // + XMarketCycle mCycle; + + // + bool mWaitsUntilNewBar; + // // Private ... private: diff --git a/Experts/x-test.x121ea.mq5 b/Experts/x-test.x121ea.mq5 index b8cf9acf..4aa88ea6 100644 --- a/Experts/x-test.x121ea.mq5 +++ b/Experts/x-test.x121ea.mq5 @@ -24,6 +24,7 @@ // #include "../Classes/x-saherelm.x121.xea.class.mq5" +#include "../Classes/x-saherelm.x121.x786.provider.class.mq5" // // "EURUSDb,USDCHFb,USDJPYb,XAUUSDb" @@ -191,17 +192,6 @@ bool InitialEA() return result; } - // - // Define Signallers ... - ENUM_XSIGNAL_PROVIDERS signallers[]; - Add(X786, signallers); - // Add(X121, signallers); - // Add(X121, signallers); - // Add(X128, signallers); - // Add(X92, signallers); - // Add(XTEST, signallers); - // GetAllX121SignalProviders(signallers); - // // Instantiate X121EA Class ... mX121EA = new XSCX121EA( @@ -237,12 +227,26 @@ bool InitialEA() // iDescriptor.symbol = iSymbol; iDescriptor.period = iPeriod; - iDescriptor.staticVolume = x121EAVolume; - iDescriptor.allowLong = x121EAAllowLong; - iDescriptor.allowShort = false; // x121EAAllowShort; - Copy( - signallers, - iDescriptor.signallers); + + // + // Prepare Signallers ... + Clean(iDescriptor.signallers); + + // + ArrayResize(iDescriptor.signallers, 1); + + // + X786Signaller *x786Signaller = new X786Signaller(); + x786Signaller.Default(); + + // + iDescriptor.signallers[0] = x786Signaller; + + // int signallersCount = ArraySize(signallers); + // for (int j = 0; j < signallersCount; j++) + // { + // iDescriptor.signallers[j] = signallers[j]; + // } // // Set Inputs to Default ... diff --git a/Libraries/x-saherelm.common.lib.mq5 b/Libraries/x-saherelm.common.lib.mq5 index 25684519..198f494c 100644 --- a/Libraries/x-saherelm.common.lib.mq5 +++ b/Libraries/x-saherelm.common.lib.mq5 @@ -3833,6 +3833,23 @@ bool IsValidSize(int size) return result; } +template +bool IsValidSize(T &buffer[]) +{ + // + bool result = false; + + // + result = + // + IsValidSize(ArraySize(buffer)) + // + ; + + // + return result; +} + // // Normalize Index Based On Specified Buffer ... template