diff --git a/Classes/x-saherelm.x121.provider.class.mq5 b/Classes/x-saherelm.x121.provider.class.mq5 index 4ace96cb..a897ecec 100644 --- a/Classes/x-saherelm.x121.provider.class.mq5 +++ b/Classes/x-saherelm.x121.provider.class.mq5 @@ -1390,7 +1390,7 @@ public: // mNumberOfItems = 15; mNumberOfSRVerified = 71; - mMinRequiredSupportAndResistances = 50; + mMinRequiredSupportAndResistances = 10; } // @@ -2805,6 +2805,61 @@ private: ); } + // + 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 ... @@ -4023,7 +4078,7 @@ private: } // - // Use XCHE and XSTR ... + // Use XSTR ... bool X786HasSpecifiedLongSignal( X121MarketConditions &mConditions, // double &sl, // Provided SL ... @@ -4034,107 +4089,95 @@ private: bool result = false; // - // TODO: Remove this ... - return result; - - // - // Check For Long ... - bool isSTRLong = + bool isCMStrLong = // - (mConditions.hMarketConditions.isTrendSwitchedToBullish && - (mConditions.lMarketConditions.isTrendBullish && - mConditions.mMarketConditions.isTrendBullish && - mConditions.sMarketConditions.isTrendBullish && - mConditions.cMarketConditions.isTrendBullish)) - // - || - // - (mConditions.lMarketConditions.isTrendSwitchedToBullish && - (mConditions.hMarketConditions.isTrendBullish && - mConditions.mMarketConditions.isTrendBullish && - mConditions.sMarketConditions.isTrendBullish && - mConditions.cMarketConditions.isTrendBullish)) - // - || - // - (mConditions.mMarketConditions.isTrendSwitchedToBullish && - (mConditions.hMarketConditions.isTrendBullish && - mConditions.lMarketConditions.isTrendBullish && - mConditions.sMarketConditions.isTrendBullish && - mConditions.cMarketConditions.isTrendBullish)) - // - || - // - (mConditions.sMarketConditions.isTrendSwitchedToBullish && - (mConditions.hMarketConditions.isTrendBullish && - mConditions.lMarketConditions.isTrendBullish && - mConditions.mMarketConditions.isTrendBullish && - mConditions.cMarketConditions.isTrendBullish)) - // - || - // - (mConditions.cMarketConditions.isTrendSwitchedToBullish && - (mConditions.hMarketConditions.isTrendBullish && - mConditions.lMarketConditions.isTrendBullish && - mConditions.mMarketConditions.isTrendBullish && - mConditions.sMarketConditions.isTrendBullish)) + mConditions.cMarketConditions.isTrendSwitchedToBullish && + (mConditions.hMarketConditions.isTrendBullish && + mConditions.lMarketConditions.isTrendBullish && + mConditions.mMarketConditions.isTrendBullish && + mConditions.sMarketConditions.isTrendBullish) // ; // - bool isCHELong = + bool isSMStrLong = // - (mConditions.hMarketConditions.isCHESwitchedInStrongLong && - (mConditions.cMarketConditions.isCHEInStrongLong && - mConditions.sMarketConditions.isCHEInStrongLong && - mConditions.mMarketConditions.isCHEInStrongLong && - mConditions.lMarketConditions.isCHEInStrongLong)) - // - || - // - (mConditions.lMarketConditions.isCHESwitchedInStrongLong && - (mConditions.cMarketConditions.isCHEInStrongLong && - mConditions.sMarketConditions.isCHEInStrongLong && - mConditions.mMarketConditions.isCHEInStrongLong && - mConditions.hMarketConditions.isCHEInStrongLong)) - // - || - // - (mConditions.mMarketConditions.isCHESwitchedInStrongLong && - (mConditions.cMarketConditions.isCHEInStrongLong && - mConditions.sMarketConditions.isCHEInStrongLong && - mConditions.lMarketConditions.isCHEInStrongLong && - mConditions.hMarketConditions.isCHEInStrongLong)) - // - || - // - (mConditions.sMarketConditions.isCHESwitchedInStrongLong && - (mConditions.cMarketConditions.isCHEInStrongLong && - mConditions.mMarketConditions.isCHEInStrongLong && - mConditions.lMarketConditions.isCHEInStrongLong && - mConditions.hMarketConditions.isCHEInStrongLong)) - // - || - // - (mConditions.cMarketConditions.isCHESwitchedInStrongLong && - (mConditions.sMarketConditions.isCHEInStrongLong && - mConditions.mMarketConditions.isCHEInStrongLong && - mConditions.lMarketConditions.isCHEInStrongLong && - mConditions.hMarketConditions.isCHEInStrongLong)) + mConditions.sMarketConditions.isTrendSwitchedToBullish && + (mConditions.hMarketConditions.isTrendBullish && + mConditions.lMarketConditions.isTrendBullish && + mConditions.mMarketConditions.isTrendBullish && + mConditions.cMarketConditions.isTrendBullish) // ; + // + bool isMMStrLong = + // + mConditions.mMarketConditions.isTrendSwitchedToBullish && + (mConditions.hMarketConditions.isTrendBullish && + mConditions.lMarketConditions.isTrendBullish && + mConditions.sMarketConditions.isTrendBullish && + mConditions.cMarketConditions.isTrendBullish) + // + ; + + // + bool isLMStrLong = + // + mConditions.lMarketConditions.isTrendSwitchedToBullish && + (mConditions.hMarketConditions.isTrendBullish && + mConditions.mMarketConditions.isTrendBullish && + mConditions.sMarketConditions.isTrendBullish && + mConditions.cMarketConditions.isTrendBullish) + // + ; + + // + bool isHMStrLong = + // + mConditions.hMarketConditions.isTrendSwitchedToBullish && + (mConditions.lMarketConditions.isTrendBullish && + mConditions.mMarketConditions.isTrendBullish && + mConditions.sMarketConditions.isTrendBullish && + mConditions.cMarketConditions.isTrendBullish) + // + ; + + // + bool isScorePassed = IsScorePassedForLong(); + // result = // - isSTRLong + isCMStrLong // - && + || // - isCHELong + isSMStrLong + // + || + // + isMMStrLong + // + || + // + isLMStrLong + // + || + // + isHMStrLong // ; + // + result = result && isScorePassed; + + // + if (result) + { + sl = GetMinVales(); + } + // return result; } @@ -4150,10 +4193,6 @@ private: // bool result = false; - // - sl = 0; - tp = 0; - // // Current Market ... bool isCMCLong = @@ -4170,6 +4209,36 @@ private: // ) // + && + // + (mConditions.cMarketConditions.isCloseOverFast && + mConditions.cMarketConditions.isCloseOverSlow && + mConditions.cMarketConditions.isCloseOverVerifier) + // + ; + + // + // Short Market ... + bool isSMCLong = + // + ( + // + (mConditions.sMarketConditions.isSlowOverVerifier && + mConditions.sMarketConditions.isFastCrossedOverVerifier) + // + || + // + (mConditions.sMarketConditions.isFastOverVerifier && + mConditions.sMarketConditions.isSlowCrossedOverVerifier) + // + ) + // + && + // + (mConditions.sMarketConditions.isCloseOverFast && + mConditions.sMarketConditions.isCloseOverSlow && + mConditions.sMarketConditions.isCloseOverVerifier) + // ; // @@ -4188,6 +4257,12 @@ private: // ) // + && + // + (mConditions.mMarketConditions.isCloseOverFast && + mConditions.mMarketConditions.isCloseOverSlow && + mConditions.mMarketConditions.isCloseOverVerifier) + // ; // @@ -4206,6 +4281,12 @@ private: // ) // + && + // + (mConditions.lMarketConditions.isCloseOverFast && + mConditions.lMarketConditions.isCloseOverSlow && + mConditions.lMarketConditions.isCloseOverVerifier) + // ; // @@ -4224,8 +4305,17 @@ private: // ) // + && + // + (mConditions.hMarketConditions.isCloseOverFast && + mConditions.hMarketConditions.isCloseOverSlow && + mConditions.hMarketConditions.isCloseOverVerifier) + // ; + // + bool isScorePassed = IsScorePassedForLong(); + // result = // @@ -4233,6 +4323,10 @@ private: // || // + isSMCLong + // + || + // isMMCLong // || @@ -4245,10 +4339,13 @@ private: // ; + // + result = result && isScorePassed; + // if (result) { - sl = GetMinPeaks(); + sl = GetMinVales(); } // @@ -4266,6 +4363,96 @@ private: // bool result = false; + // + bool isCCHELong = + // + (mConditions.cMarketConditions.isCHESwitchedInStrongLong && + (mConditions.sMarketConditions.isCHEInStrongLong && + mConditions.mMarketConditions.isCHEInStrongLong && + mConditions.lMarketConditions.isCHEInStrongLong && + mConditions.hMarketConditions.isCHEInStrongLong)) + // + ; + + // + bool isSCHELong = + // + (mConditions.sMarketConditions.isCHESwitchedInStrongLong && + (mConditions.cMarketConditions.isCHEInStrongLong && + mConditions.mMarketConditions.isCHEInStrongLong && + mConditions.lMarketConditions.isCHEInStrongLong && + mConditions.hMarketConditions.isCHEInStrongLong)) + // + ; + + // + bool isMCHELong = + // + (mConditions.mMarketConditions.isCHESwitchedInStrongLong && + (mConditions.cMarketConditions.isCHEInStrongLong && + mConditions.sMarketConditions.isCHEInStrongLong && + mConditions.lMarketConditions.isCHEInStrongLong && + mConditions.hMarketConditions.isCHEInStrongLong)) + // + ; + + // + bool isLCHELong = + // + (mConditions.lMarketConditions.isCHESwitchedInStrongLong && + (mConditions.cMarketConditions.isCHEInStrongLong && + mConditions.sMarketConditions.isCHEInStrongLong && + mConditions.mMarketConditions.isCHEInStrongLong && + mConditions.hMarketConditions.isCHEInStrongLong)) + // + ; + + // + bool isHCHELong = + // + (mConditions.hMarketConditions.isCHESwitchedInStrongLong && + (mConditions.cMarketConditions.isCHEInStrongLong && + mConditions.sMarketConditions.isCHEInStrongLong && + mConditions.mMarketConditions.isCHEInStrongLong && + mConditions.lMarketConditions.isCHEInStrongLong)) + // + ; + + // + bool isScorePassed = IsScorePassedForLong(); + + // + result = + // + isCCHELong + // + || + // + isSCHELong + // + || + // + isMCHELong + // + || + // + isLCHELong + // + || + // + isHCHELong + // + ; + + // + result = result && isScorePassed; + + // + if (result) + { + sl = GetMinVales(); + } + // return result; } @@ -4281,53 +4468,32 @@ private: // bool result = false; - // - // return false; - // double bullishScore = mBullishScore[0]; double bullishMin100 = GetBullishScoreMin(0, 100); double bullishMax100 = GetBullishScoreMax(0, 100); - double bullish7AVG = GetBullishScoreAverage(0, 7); - double bullish21AVG = GetBullishScoreAverage(0, 21); + double bullish9AVG = GetBullishScoreAverage(0, 9); + double bullish17AVG = GetBullishScoreAverage(0, 17); + double bullish26AVG = GetBullishScoreAverage(0, 26); // double bearishScore = mBearishScore[0]; - double bearishMin100 = GetBearishScoreMin(0, 100); - double bearishMax100 = GetBearishScoreMax(0, 100); - double bearish7AVG = GetBearishScoreAverage(0, 7); - double bearish21AVG = GetBearishScoreAverage(0, 21); + + // + bool isScorePassed = IsScorePassedForLong(); // bool isBullishOverAVGs = // + ArraySize(mBullishScore) > 100 && + bullishScore > mBullishScore[1] && bullishScore > bearishScore && - bullishScore > bullish7AVG && - bullishScore > bullish21AVG + bullishScore > bullish9AVG && + bullishScore > bullish17AVG && + bullishScore > bullish26AVG // ; - // - if (isBullishOverAVGs) - { - sl = GetMinVales(); - } - - // // - // bool isBearishEqualOverMax100 = - // // - // bearishScore > bearish7AVG && - // bearishScore > bearish21AVG && - // bearishScore >= bearishMax100 - // // - // ; - - // // - // if (isBearishEqualOverMax100) - // { - // sl = 0; // GetMaxVales() - PointToPrice(100, GetSymbol()); - // } - // result = // @@ -4335,6 +4501,15 @@ private: // ; + // + result = result && isScorePassed; + + // + if (result) + { + sl = GetMinVales(); + } + // return result; } @@ -4368,7 +4543,7 @@ private: } // - // Use XCHE and XSTR ... + // Use XSTR ... bool X786HasSpecifiedShortSignal( X121MarketConditions &mConditions, // double &sl, // Provided SL ... @@ -4379,107 +4554,95 @@ private: bool result = false; // - // TODO: Remove this ... - return result; - - // - // Check For Short ... - bool isSTRShort = + bool isCMStrShort = // - (mConditions.hMarketConditions.isTrendSwitchedToBearish && - (mConditions.lMarketConditions.isTrendBearish && - mConditions.mMarketConditions.isTrendBearish && - mConditions.sMarketConditions.isTrendBearish && - mConditions.cMarketConditions.isTrendBearish)) - // - || - // - (mConditions.lMarketConditions.isTrendSwitchedToBearish && - (mConditions.hMarketConditions.isTrendBearish && - mConditions.mMarketConditions.isTrendBearish && - mConditions.sMarketConditions.isTrendBearish && - mConditions.cMarketConditions.isTrendBearish)) - // - || - // - (mConditions.mMarketConditions.isTrendSwitchedToBearish && - (mConditions.hMarketConditions.isTrendBearish && - mConditions.lMarketConditions.isTrendBearish && - mConditions.sMarketConditions.isTrendBearish && - mConditions.cMarketConditions.isTrendBearish)) - // - || - // - (mConditions.sMarketConditions.isTrendSwitchedToBearish && - (mConditions.hMarketConditions.isTrendBearish && - mConditions.lMarketConditions.isTrendBearish && - mConditions.mMarketConditions.isTrendBearish && - mConditions.cMarketConditions.isTrendBearish)) - // - || - // - (mConditions.cMarketConditions.isTrendSwitchedToBearish && - (mConditions.hMarketConditions.isTrendBearish && - mConditions.lMarketConditions.isTrendBearish && - mConditions.mMarketConditions.isTrendBearish && - mConditions.sMarketConditions.isTrendBearish)) + mConditions.cMarketConditions.isTrendSwitchedToBearish && + (mConditions.hMarketConditions.isTrendBearish && + mConditions.lMarketConditions.isTrendBearish && + mConditions.mMarketConditions.isTrendBearish && + mConditions.sMarketConditions.isTrendBearish) // ; // - bool isCHEShort = + bool isSMStrShort = // - (mConditions.hMarketConditions.isCHESwitchedInStrongShort && - (mConditions.cMarketConditions.isCHEInStrongShort && - mConditions.sMarketConditions.isCHEInStrongShort && - mConditions.mMarketConditions.isCHEInStrongShort && - mConditions.lMarketConditions.isCHEInStrongShort)) - // - || - // - (mConditions.lMarketConditions.isCHESwitchedInStrongShort && - (mConditions.cMarketConditions.isCHEInStrongShort && - mConditions.sMarketConditions.isCHEInStrongShort && - mConditions.mMarketConditions.isCHEInStrongShort && - mConditions.hMarketConditions.isCHEInStrongShort)) - // - || - // - (mConditions.mMarketConditions.isCHESwitchedInStrongShort && - (mConditions.cMarketConditions.isCHEInStrongShort && - mConditions.sMarketConditions.isCHEInStrongShort && - mConditions.lMarketConditions.isCHEInStrongShort && - mConditions.hMarketConditions.isCHEInStrongShort)) - // - || - // - (mConditions.sMarketConditions.isCHESwitchedInStrongShort && - (mConditions.cMarketConditions.isCHEInStrongShort && - mConditions.mMarketConditions.isCHEInStrongShort && - mConditions.lMarketConditions.isCHEInStrongShort && - mConditions.hMarketConditions.isCHEInStrongShort)) - // - || - // - (mConditions.cMarketConditions.isCHESwitchedInStrongShort && - (mConditions.sMarketConditions.isCHEInStrongShort && - mConditions.mMarketConditions.isCHEInStrongShort && - mConditions.lMarketConditions.isCHEInStrongShort && - mConditions.hMarketConditions.isCHEInStrongShort)) + mConditions.sMarketConditions.isTrendSwitchedToBearish && + (mConditions.hMarketConditions.isTrendBearish && + mConditions.lMarketConditions.isTrendBearish && + mConditions.mMarketConditions.isTrendBearish && + mConditions.cMarketConditions.isTrendBearish) // ; + // + bool isMMStrShort = + // + mConditions.mMarketConditions.isTrendSwitchedToBearish && + (mConditions.hMarketConditions.isTrendBearish && + mConditions.lMarketConditions.isTrendBearish && + mConditions.sMarketConditions.isTrendBearish && + mConditions.cMarketConditions.isTrendBearish) + // + ; + + // + bool isLMStrShort = + // + mConditions.lMarketConditions.isTrendSwitchedToBearish && + (mConditions.hMarketConditions.isTrendBearish && + mConditions.mMarketConditions.isTrendBearish && + mConditions.sMarketConditions.isTrendBearish && + mConditions.cMarketConditions.isTrendBearish) + // + ; + + // + bool isHMStrShort = + // + mConditions.hMarketConditions.isTrendSwitchedToBearish && + (mConditions.lMarketConditions.isTrendBearish && + mConditions.mMarketConditions.isTrendBearish && + mConditions.sMarketConditions.isTrendBearish && + mConditions.cMarketConditions.isTrendBearish) + // + ; + + // + bool isScorePassed = IsScorePassedForShort(); + // result = // - isSTRShort + isCMStrShort // - && + || // - isCHEShort + isSMStrShort + // + || + // + isMMStrShort + // + || + // + isLMStrShort + // + || + // + isHMStrShort // ; + // + result = result && isScorePassed; + + // + if (result) + { + sl = GetMaxPeaks(); + } + // return result; } @@ -4496,10 +4659,7 @@ private: bool result = false; // - // TODO: Remove this ... - return result; - - // + // Current Market ... bool isCMCShort = // ( @@ -4514,9 +4674,40 @@ private: // ) // + && + // + (mConditions.cMarketConditions.isCloseUnderFast && + mConditions.cMarketConditions.isCloseUnderSlow && + mConditions.cMarketConditions.isCloseUnderVerifier) + // ; // + // Short Market ... + bool isSMCShort = + // + ( + // + (mConditions.sMarketConditions.isSlowUnderVerifier && + mConditions.sMarketConditions.isFastCrossedUnderVerifier) + // + || + // + (mConditions.sMarketConditions.isFastUnderVerifier && + mConditions.sMarketConditions.isSlowCrossedUnderVerifier) + // + ) + // + && + // + (mConditions.sMarketConditions.isCloseUnderFast && + mConditions.sMarketConditions.isCloseUnderSlow && + mConditions.sMarketConditions.isCloseUnderVerifier) + // + ; + + // + // Medium Market ... bool isMMCShort = // ( @@ -4531,9 +4722,16 @@ private: // ) // + && + // + (mConditions.mMarketConditions.isCloseUnderFast && + mConditions.mMarketConditions.isCloseUnderSlow && + mConditions.mMarketConditions.isCloseUnderVerifier) + // ; // + // Long Market ... bool isLMCShort = // ( @@ -4548,9 +4746,16 @@ private: // ) // + && + // + (mConditions.lMarketConditions.isCloseUnderFast && + mConditions.lMarketConditions.isCloseUnderSlow && + mConditions.lMarketConditions.isCloseUnderVerifier) + // ; // + // Hind Market ... bool isHMCShort = // ( @@ -4565,8 +4770,17 @@ private: // ) // + && + // + (mConditions.hMarketConditions.isCloseUnderFast && + mConditions.hMarketConditions.isCloseUnderSlow && + mConditions.hMarketConditions.isCloseUnderVerifier) + // ; + // + bool isScorePassed = IsScorePassedForShort(); + // result = // @@ -4574,6 +4788,10 @@ private: // || // + isSMCShort + // + || + // isMMCShort // || @@ -4586,6 +4804,9 @@ private: // ; + // + result = result && isScorePassed; + // if (result) { @@ -4607,6 +4828,96 @@ private: // bool result = false; + // + bool isCCHEShort = + // + (mConditions.cMarketConditions.isCHESwitchedInStrongShort && + (mConditions.sMarketConditions.isCHEInStrongShort && + mConditions.mMarketConditions.isCHEInStrongShort && + mConditions.lMarketConditions.isCHEInStrongShort && + mConditions.hMarketConditions.isCHEInStrongShort)) + // + ; + + // + bool isSCHEShort = + // + (mConditions.sMarketConditions.isCHESwitchedInStrongShort && + (mConditions.cMarketConditions.isCHEInStrongShort && + mConditions.mMarketConditions.isCHEInStrongShort && + mConditions.lMarketConditions.isCHEInStrongShort && + mConditions.hMarketConditions.isCHEInStrongShort)) + // + ; + + // + bool isMCHEShort = + // + (mConditions.mMarketConditions.isCHESwitchedInStrongShort && + (mConditions.cMarketConditions.isCHEInStrongShort && + mConditions.sMarketConditions.isCHEInStrongShort && + mConditions.lMarketConditions.isCHEInStrongShort && + mConditions.hMarketConditions.isCHEInStrongShort)) + // + ; + + // + bool isLCHEShort = + // + (mConditions.lMarketConditions.isCHESwitchedInStrongShort && + (mConditions.cMarketConditions.isCHEInStrongShort && + mConditions.sMarketConditions.isCHEInStrongShort && + mConditions.mMarketConditions.isCHEInStrongShort && + mConditions.hMarketConditions.isCHEInStrongShort)) + // + ; + + // + bool isHCHEShort = + // + (mConditions.hMarketConditions.isCHESwitchedInStrongShort && + (mConditions.cMarketConditions.isCHEInStrongShort && + mConditions.sMarketConditions.isCHEInStrongShort && + mConditions.mMarketConditions.isCHEInStrongShort && + mConditions.lMarketConditions.isCHEInStrongShort)) + // + ; + + // + bool isScorePassed = IsScorePassedForShort(); + + // + result = + // + isCCHEShort + // + || + // + isSCHEShort + // + || + // + isMCHEShort + // + || + // + isLCHEShort + // + || + // + isHCHEShort + // + ; + + // + result = result && isScorePassed; + + // + if (result) + { + sl = GetMaxPeaks(); + } + // return result; } @@ -4623,48 +4934,30 @@ private: bool result = false; // - double bullishScore = mBullishScore[0]; - double bullishMin100 = GetBullishScoreMin(0, 71); - double bullishMax100 = GetBullishScoreMax(0, 71); - double bullish7AVG = GetBullishScoreAverage(0, 7); - double bullish21AVG = GetBullishScoreAverage(0, 21); + double bearishScore = mBearishScore[0]; + double bearishMin100 = GetBearishScoreMin(0, 100); + double bearishMax100 = GetBearishScoreMax(0, 100); + double bearish9AVG = GetBearishScoreAverage(0, 9); + double bearish17AVG = GetBearishScoreAverage(0, 17); + double bearish26AVG = GetBearishScoreAverage(0, 26); // - double bearishScore = mBearishScore[0]; - double bearishMin100 = GetBearishScoreMin(0, 71); - double bearishMax100 = GetBearishScoreMax(0, 71); - double bearish7AVG = GetBearishScoreAverage(0, 7); - double bearish21AVG = GetBearishScoreAverage(0, 21); + double bullishScore = mBullishScore[0]; // bool isBearishOverAVGs = // + ArraySize(mBearishScore) > 100 && + bearishScore > mBearishScore[1] && bearishScore > bullishScore && - bearishScore > bearish7AVG && - bearishScore > bearish21AVG + bearishScore > bearish9AVG && + bearishScore > bearish17AVG && + bearishScore > bearish26AVG // ; // - if (isBearishOverAVGs) - { - sl = GetMaxPeaks(); - } - - // // - // bool isBullishEqualOverMax100 = - // // - // bullishScore > bullish7AVG && - // bullishScore > bullish21AVG && - // bullishScore >= bullishMax100 - // // - // ; - - // // - // if (isBullishEqualOverMax100) - // { - // sl = GetMaxPeaks(); - // } + bool isScorePassed = IsScorePassedForShort(); // result = @@ -4673,6 +4966,15 @@ private: // ; + // + result = result && isScorePassed; + + // + if (result) + { + sl = GetMaxPeaks(); + } + // return result; } diff --git a/Classes/x-saherelm.x121.xea.class.mq5 b/Classes/x-saherelm.x121.xea.class.mq5 index 087a6482..5acefcb4 100644 --- a/Classes/x-saherelm.x121.xea.class.mq5 +++ b/Classes/x-saherelm.x121.xea.class.mq5 @@ -288,14 +288,6 @@ public: // bool result = false; - // - // TODO: - // Make them Configurable ... - int numberOfPositionsForHege = 4; - int levelsOnClose = 6; - int requiredAgeForSLTrail = 3; - int requiredDistanceForSLTrail = 10; - // XPosition positions[]; int positionsCount = mTrader.GetPositions(positions); @@ -304,6 +296,109 @@ public: return result; } + // + HandleEQMState(); + + // + HandleHedging(positions); + + // + HandleTrailManagement(positions); + + // + // Must false ... + return result; + } + + // + void HandleHedging(XPosition &positions[]) + { + // + // TODO: + // Make them Configurable ... + int numberOfPositionsForHege = 3; + + // + int positionsCount = ArraySize(positions); + if (positionsCount <= 0) + { + return; + } + + // + // Hedge ... + if (positionsCount >= numberOfPositionsForHege) + { + // + double profit = CalculatePositionsProfit(positions); + double requiredProfit = CalculateRequiredProfitForHedge(positions); + + // + bool isReadyForHedge = profit >= requiredProfit; + if (!isReadyForHedge) + { + return; + } + + // + string comment = "EQM Hedge ..."; + int closed = mTrader.Close( + positions, + comment + // + ); + if (closed > 0) + { + // + string message = "EQM Hedge Positions on Profit: " + ToString(profit); + + // + mAlert.Alert(message); + + // + for (int i = 0; i < positionsCount; i++) + { + RemoveSLTrail(positions[i].ticket); + } + } + } + } + + // + void HandleEQMState() + { + // + bool equityReached = !mTrader.CheckEquityForTrade(); + bool maxAllowedReached = !mTrader.CheckPositionsForTrade(); + bool enableEQM = equityReached || maxAllowedReached; + if (!enableEQM) + { + // + return; + } + + // + Print("EQM Enabled: " + (equityReached ? "Max Equity Reached ..." : maxAllowedReached ? "Max Allowed Positions Reached ..." + : "")); + } + + // + void HandleTrailManagement(XPosition &positions[]) + { + // + // TODO: + // Make them Configurable ... + int levelsOnClose = 6; + int requiredAgeForSLTrail = 3; + int requiredDistanceForSLTrail = 10; + + // + int positionsCount = ArraySize(positions); + if (positionsCount <= 0) + { + return; + } + // // Trail Positions Stop ... for (int i = 0; i < positionsCount; i++) @@ -316,6 +411,7 @@ public: // iPosition.provider == ToString(X786) || iPosition.provider == ToString(X121) || + iPosition.provider == ToString(X110) || iPosition.provider == ToString(X92) // ; @@ -496,48 +592,6 @@ public: } } } - - // - // Hedge ... - if (positionsCount >= numberOfPositionsForHege) - { - // - double profit = CalculatePositionsProfit(positions); - double requiredProfit = CalculateRequiredProfitForHedge(positions); - - // - bool isReadyForHedge = profit >= requiredProfit; - if (!isReadyForHedge) - { - return result; - } - - // - string comment = "EQM Hedge ..."; - int closed = mTrader.Close( - positions, - comment - // - ); - if (closed > 0) - { - // - string message = "EQM Hedge Positions on Profit: " + ToString(profit); - - // - mAlert.Alert(message); - - // - for (int i = 0; i < positionsCount; i++) - { - RemoveSLTrail(positions[i].ticket); - } - } - } - - // - // Must false ... - return result; } // @@ -598,7 +652,7 @@ public: NULL, // All Periods ... iSignal.type // ); - if (positionsCount <= 5) + if (positionsCount < 2) { // // First Signal in a While of Specific Provider ... @@ -610,71 +664,112 @@ public: // continue; } - else - { - // - // not First Signal ... + // else + // { + // // + // // not First Signal ... - // - // Calculate Provider Specified Open Positions Profit ... - double profits = CalculatePositionsProfit(positions); - if (profits > 0) - { - // - AddRef( - iSignal, - signals // - ); + // // + // // Calculate Provider Specified Open Positions Profit ... + // double profits = CalculatePositionsProfit(positions); + // if (profits > 0) + // { - // - continue; - } - else - { - // - // Find Max In Profit of Same Position ... - Clean(positions); - positionsCount = mTrader.GetInProfitPositions( - positions, - iSignal.symbol, - iSignal.provider, - NULL, // All Periods ... - iSignal.type, - X_POSITION_SELECT_MAX // Max In Profit ... - ); - if (positionsCount <= 0) - { - continue; - } + // // + // AddRef( + // iSignal, + // signals // + // ); - // - string comment = "EQM Close Max Profit ..."; - bool isClosed = mTrader.Close( - positions[0].ticket, - comment // - ); - if (isClosed) - { - // - RemoveTrail(positions[0].ticket); + // // // + // // // Find Max In Profit of Same Position ... + // // Clean(positions); + // // positionsCount = mTrader.GetInProfitPositions( + // // positions, + // // iSignal.symbol, + // // iSignal.provider, + // // NULL, // All Periods ... + // // iSignal.type, + // // X_POSITION_SELECT_MAX // Max In Profit ... + // // ); + // // if (positionsCount <= 0) + // // { + // // continue; + // // } - // - string message = "EQM Close Max In Profit (" + ToString(positions[0].ticket) + ") for new Signal ..."; + // // // + // // string comment = "EQM Close Max Profit ..."; + // // bool isClosed = mTrader.Close( + // // positions[0].ticket, + // // comment // + // // ); + // // if (isClosed) + // // { + // // // + // // RemoveTrail(positions[0].ticket); - // - mAlert.Alert(message); + // // // + // // string message = "EQM Close Max In Profit (" + ToString(positions[0].ticket) + ") for new Signal ..."; - // - AddRef( - iSignal, - signals // - ); + // // // + // // mAlert.Alert(message); - // - continue; - } - } - } + // // // + // // AddRef( + // // iSignal, + // // signals // + // // ); + + // // // + // // continue; + // // } + // } + // else + // { + // // // + // // // Find Max In Profit of Same Position ... + // // Clean(positions); + // // positionsCount = mTrader.GetInProfitPositions( + // // positions, + // // iSignal.symbol, + // // iSignal.provider, + // // NULL, // All Periods ... + // // iSignal.type, + // // X_POSITION_SELECT_MAX // Max In Profit ... + // // ); + // // if (positionsCount <= 0) + // // { + // // continue; + // // } + + // // // + // // string comment = "EQM Close Max Profit ..."; + // // bool isClosed = mTrader.Close( + // // positions[0].ticket, + // // comment // + // // ); + // // if (isClosed) + // // { + // // // + // // RemoveTrail(positions[0].ticket); + + // // // + // // string message = "EQM Close Max In Profit (" + ToString(positions[0].ticket) + ") for new Signal ..."; + + // // // + // // mAlert.Alert(message); + + // // // + // // AddRef( + // // iSignal, + // // signals // + // // ); + + // // // + // // continue; + // // } + // } + // } } // @@ -705,6 +800,9 @@ public: return false; } + // + // Profit Management ... + // // Tools ... diff --git a/Classes/x-saherelm.xea.class.mq5 b/Classes/x-saherelm.xea.class.mq5 index 8c1a8724..cc18b84e 100644 --- a/Classes/x-saherelm.xea.class.mq5 +++ b/Classes/x-saherelm.xea.class.mq5 @@ -29,12 +29,180 @@ // Define On Signal Event Handler Type ... typedef void (*TOnSignal)(XSignal &signals[]); +// +enum ENUM_X_PROFIT_TRACK_FIELDS +{ + X_PROFIT_TRACK_PROFIT, + X_PROFIT_TRACK_LONGS_PROFIT, + X_PROFIT_TRACK_SHORTS_PROFIT, +}; + // // Model Account Profits ... -struct XProfitTracker { +struct XProfitTrack +{ + // + int longs; // Number of Long ... + int shorts; // Number of Short ... + + // + double profit; // Profit of All ... + double longsProfit; // Profits of Longs ... + double shortsProfit; // Profits of Shorts ... + + // + double profitFrom; // Profit of All ... + double longsProfitFrom; // Profits of Longs ... + double shortsProfitFrom; // Profits of Shorts ... + + // + double volume; // Volume ... + double longsVolume; // Volume of Longs ... + double shortsVolume; // Volume of Shorts ... + + // + datetime time; // Check Time ... + + // + XProfitTrack() + { + Clean(); + } + + // + // Tools ... + + // + // Initialization ... + bool Init(XSCTrade *mTrader) + { + // + bool result = false; + + // + XPosition positions[]; + int positionsCount = mTrader.GetPositions(positions); + result = positionsCount > 0; + if (!result) + { + return result; + } + + // + for (int i = 0; i < positionsCount; i++) + { + // + XPosition iPosition = positions[i]; + + // + bool isLong = IsLong(iPosition.type); + + // + if (isLong) + { + // + longs++; + longsVolume += iPosition.volume; + longsProfit += iPosition.profit; + } + else + { + // + shorts++; + shortsVolume += iPosition.volume; + shortsProfit += iPosition.profit; + } + + // + profit += iPosition.profit; + volume += iPosition.volume; + } + + // + result = IsValid(); + if (result) + { + time = TimeCurrent(); + } + + // + return result; + } + + // + double SelectField(ENUM_X_PROFIT_TRACK_FIELDS field) + { + // + double result = profit; + + // + switch (field) + { + // + case X_PROFIT_TRACK_LONGS_PROFIT: + result = longsProfit; + break; + + // + case X_PROFIT_TRACK_SHORTS_PROFIT: + result = shortsProfit; + break; + + // + default: + case X_PROFIT_TRACK_PROFIT: + result = profit; + break; + } + + // + return result; + } + + // + // Cleanup ... + void Clean() + { + // + longs = 0; + shorts = 0; + profit = 0; + volume = 0; + profitFrom = 0; + longsVolume = 0; + longsProfit = 0; + shortsVolume = 0; + shortsProfit = 0; + longsProfitFrom = 0; + shortsProfitFrom = 0; + + // + time = NULL; + } + + // + // Validate ... + bool IsValid() + { + // + bool result = false; + + // + result = + // + (longs > 0 || shorts > 0) + // + && + // + volume > 0 + // + ; + + // + return result; + } + // - int count; // Number of Positions ... - }; // @@ -401,6 +569,9 @@ public: // Check Trade Events ... OnTrade(); + // + HandleProfitManageMent(); + // // First Check For Any Guard Actions ... // then Handle Guards if Provided ... @@ -698,6 +869,16 @@ public: } } + // + virtual void OnGoingToProfit(XProfitTrack &track) {} + virtual void OnLongsGoingToProfit(XProfitTrack &track) {} + virtual void OnShortsGoingToProfit(XProfitTrack &track) {} + + // + virtual void OnGoingToDrawdown(XProfitTrack &track) {} + virtual void OnLongsGoingToDrawdown(XProfitTrack &track) {} + virtual void OnShortsGoingToDrawdown(XProfitTrack &track) {} + // // Protected ... protected: @@ -815,6 +996,355 @@ protected: return result; } + // + // Profit Tracker ... + + // + XProfitTrack mProfitTracks[]; + + // + bool GetProfitTrack( + XProfitTrack &track, + int index = 0 // + ) + { + // + bool result = false; + + // + if (index < 0) + { + index = 0; + } + + // + int tracksCount = CountProfitTracks(); + result = tracksCount > 0 && index < tracksCount; + if (!result) + { + return result; + } + + // + track.Clean(); + + // + track = mProfitTracks[index]; + + // + result = track.IsValid(); + + // + return result; + } + + // + int CountProfitTracks() + { + return ArraySize(mProfitTracks); + } + + // + void AddProfitTrack() + { + // + XProfitTrack track; + bool isValid = track.Init(mTrader); + if (!isValid) + { + return; + } + + // + ArraySetAsSeries(mProfitTracks, false); + + // + AddRef( + track, + mProfitTracks // + ); + + // + ArraySetAsSeries(mProfitTracks, true); + } + + // + // Extract Specified Field Vales of XProfit Track Struct ... + int ExtractProfitTrackField( + double &result[], + ENUM_X_PROFIT_TRACK_FIELDS field, + int start = 0, + int count = 10 // + ) + { + // + Clean(result); + + // + if (start < 0) + { + start = 0; + } + + // + int end = start + count; + + // + int tracksCount = CountProfitTracks(); + if (end > tracksCount) + { + end = tracksCount; + } + + // + for (int i = start; i < end; i++) + { + // + XProfitTrack iTrack; + bool isValid = GetProfitTrack( + iTrack, + i // + ); + + // + if (!isValid) + { + continue; + } + + // + double iValue = iTrack.SelectField(field); + Add( + iValue, + result // + ); + } + + // + int mResult = ArraySize(result); + + // + return mResult; + } + + // + double AverageProfitTrackField( + ENUM_X_PROFIT_TRACK_FIELDS field, + int start = 0, + int count = 10 // + ) + { + // + double result = EMPTY_VALUE; + + // + double items[]; + int itemsCount = ExtractProfitTrackField( + items, + field, + start, + count // + ); + if (itemsCount <= 0) + { + return result; + } + + // + result = GetAverage(items); + + // + return result; + } + + // + bool IsProfitTrackFieldIncreasing( + ENUM_X_PROFIT_TRACK_FIELDS field, + int start = 0, + int count = 10 // + ) + { + // + bool result = false; + + // + double items[]; + int itemsCount = ExtractProfitTrackField( + items, + field, + start, + count // + ); + if (itemsCount <= 0) + { + return result; + } + + // + int from = itemsCount - 1; + int to = 0; + + // + result = IsIncreasing( + from, + to, + items // + ); + + // + return result; + } + + // + bool IsProfitTrackFieldDecreasing( + ENUM_X_PROFIT_TRACK_FIELDS field, + int start = 0, + int count = 10 // + ) + { + // + bool result = false; + + // + double items[]; + int itemsCount = ExtractProfitTrackField( + items, + field, + start, + count // + ); + if (itemsCount <= 0) + { + return result; + } + + // + int from = itemsCount - 1; + int to = 0; + + // + result = IsDecreasing( + from, + to, + items // + ); + + // + return result; + } + + // + void HandleProfitManageMent() + { + // + AddProfitTrack(); + + // + int profitsCount = CountProfitTracks(); + if (profitsCount <= 1) + { + return; + } + + // + XProfitTrack cT; + bool isValid = GetProfitTrack( + cT, + 0 // + ); + if (!isValid) + { + return; + } + + // + XProfitTrack pT; + isValid = GetProfitTrack( + pT, + 1 // + ); + if (!isValid) + { + return; + } + + // + cT.profitFrom = pT.profit; + cT.longsProfitFrom = pT.longsProfit; + cT.shortsProfitFrom = pT.shortsProfit; + + // + bool isGoningToProfit = + // + cT.profit > 0 && + pT.profit <= 0 + // + ; + if (isGoningToProfit) + { + // + OnGoingToProfit(cT); + } + + // + bool isLongsGoningToProfit = + // + cT.longsProfit > 0 && + pT.longsProfit <= 0 + // + ; + if (isLongsGoningToProfit) + { + OnLongsGoingToProfit(cT); + } + + // + bool isShortsGoningToProfit = + // + cT.shortsProfit > 0 && + pT.shortsProfit <= 0 + // + ; + if (isShortsGoningToProfit) + { + OnShortsGoingToProfit(cT); + } + + // + bool isGoningToDrawdown = + // + cT.profit < 0 && + pT.profit >= 0 + // + ; + if (isGoningToDrawdown) + { + OnGoingToDrawdown(cT); + } + + bool isLongsGoningToDrawdown = + // + cT.longsProfit < 0 && + pT.longsProfit >= 0 + // + ; + if (isLongsGoningToDrawdown) + { + OnLongsGoingToDrawdown(cT); + } + + bool isShortsGoningToDrawdown = + // + cT.shortsProfit < 0 && + pT.shortsProfit >= 0 + // + ; + if (isShortsGoningToDrawdown) + { + OnShortsGoingToDrawdown(cT); + } + } + // // Guards ... diff --git a/Experts/x-test.x121ea.mq5 b/Experts/x-test.x121ea.mq5 index 734b9314..e52e3b2b 100644 --- a/Experts/x-test.x121ea.mq5 +++ b/Experts/x-test.x121ea.mq5 @@ -30,18 +30,18 @@ // // Inputs ... -long x121EAMagicNumber = 78692110; // Magic Number -int x121EASlippage = 10; // Slippgae -string x121EASymbols = "EURUSDb"; // Symbols +long x121EAMagicNumber = 78692110; // Magic Number +int x121EASlippage = 10; // Slippgae +string x121EASymbols = "EURUSDb,USDCHFb,USDJPYb,GBPUSDb,XAUUSDb,AUDUSDb,USDCADb,NZDUSDb"; // Symbols // bool x121EAAllowLong = true; // Allow Long Trades bool x121EAAllowShort = true; // Allow Short Trades int x121EAManageInterval = 5; // Manager Check Intervals Seconds -int x121EAMaxAllowedPositions = 5; // Max Allowed Positions +int x121EAMaxAllowedPositions = 30; // Max Allowed Positions double x121EAMaxAllowedSpread = 0; // Max Allowed Spred for Opening Trades -double x121EAMinProfitPerTrade = 0.4; // Min Profit Per Trade based On Volume Factor (Hedge) +double x121EAMinProfitPerTrade = 0.3; // Min Profit Per Trade based On Volume Factor (Hedge) double x121EAMinProfitPerVolumeFactor = 0.01; // Min Volume Factor for Calculating Profit (Hedge) -double x121EAMaxAllowedDrawdownFactor = 0.015; // Max Allowed Drawdown Factor +double x121EAMaxAllowedDrawdownFactor = 0.05; // Max Allowed Drawdown Factor // double x121EAVolume = 0.01; @@ -190,7 +190,10 @@ bool InitialEA() // // Define Signallers ... ENUM_X121_SIGNAL_PROVIDERS signallers[]; - GetAllX121SignalProviders(signallers); + Add(X786, signallers); + Add(X110, signallers); + Add(X121, signallers); + // GetAllX121SignalProviders(signallers); // // Instantiate X121EA Class ... @@ -238,9 +241,9 @@ bool InitialEA() // // XMC ... - iDescriptor.inputs.mcInputs.showFastMa = true; - iDescriptor.inputs.mcInputs.showSlowMa = true; - iDescriptor.inputs.mcInputs.showVerifierMa = true; + iDescriptor.inputs.mcInputs.showFastMa = false; + iDescriptor.inputs.mcInputs.showSlowMa = false; + iDescriptor.inputs.mcInputs.showVerifierMa = false; // // XICH ... @@ -255,26 +258,26 @@ bool InitialEA() // // XCHE ... - iDescriptor.inputs.cheInputs.showLongExit1Line = true; - iDescriptor.inputs.cheInputs.showShortExit1Line = true; - iDescriptor.inputs.cheInputs.showLongExit2Line = true; - iDescriptor.inputs.cheInputs.showShortExit2Line = true; + iDescriptor.inputs.cheInputs.showLongExit1Line = false; + iDescriptor.inputs.cheInputs.showShortExit1Line = false; + iDescriptor.inputs.cheInputs.showLongExit2Line = false; + iDescriptor.inputs.cheInputs.showShortExit2Line = false; // // XPV ... - iDescriptor.inputs.pvInputs.showPeaksAndVales = true; + iDescriptor.inputs.pvInputs.showPeaksAndVales = false; iDescriptor.inputs.pvInputs.showLevels = false; iDescriptor.inputs.pvInputs.showConsolidations = false; iDescriptor.inputs.pvInputs.showFibo1Levels = false; iDescriptor.inputs.pvInputs.showFibo2Levels = false; - iDescriptor.inputs.pvInputs.showFibo3Levels = true; + iDescriptor.inputs.pvInputs.showFibo3Levels = false; iDescriptor.inputs.pvInputs.showFibo4Levels = false; iDescriptor.inputs.pvInputs.showFibo5Levels = false; // // XZG ... iDescriptor.inputs.zgInputs.showZigZag = false; - iDescriptor.inputs.zgInputs.showPeaksAndVales = true; + iDescriptor.inputs.zgInputs.showPeaksAndVales = false; // // XDON ... @@ -285,7 +288,7 @@ bool InitialEA() // // XSTR ... - iDescriptor.inputs.strInputs.showTrends = true; + iDescriptor.inputs.strInputs.showTrends = false; iDescriptor.inputs.strInputs.fillTrends = false; // diff --git a/Libraries/x-saherelm.common.lib.mq5 b/Libraries/x-saherelm.common.lib.mq5 index 7c9fc319..f533700a 100644 --- a/Libraries/x-saherelm.common.lib.mq5 +++ b/Libraries/x-saherelm.common.lib.mq5 @@ -3784,7 +3784,7 @@ bool IsUnder( // Check if a Value Increasing in Loopback ... bool IsIncreasing( const int from, // Last Time Index - const int to, // Fisr Tima Index + const int to, // Fisrs Tima Index const double &buffer[] // the Buffer which required to search ) {