From d194d850826ede55cd4db091774ae27f47f6482f Mon Sep 17 00:00:00 2001 From: Hadi Khazaee Asl Date: Sun, 21 Jul 2024 18:25:54 +0330 Subject: [PATCH] last ... --- Experts/x-test-strategies.ea.mq5 | 28 +++-- Strategies/x-saherelm.xtest.strategy.mq5 | 151 ++++++++++++++--------- 2 files changed, 112 insertions(+), 67 deletions(-) diff --git a/Experts/x-test-strategies.ea.mq5 b/Experts/x-test-strategies.ea.mq5 index 2e917225..0a585b00 100644 --- a/Experts/x-test-strategies.ea.mq5 +++ b/Experts/x-test-strategies.ea.mq5 @@ -36,31 +36,35 @@ long eaMagicNumber = 78692110; // Magic Number int eaSlippage = 10; // Slippgae // -double eaVolume = 0.01; -double eaAllowLong = true; -double eaAllowShort = true; +double eaVolume = 0.01; // Static Volume +double eaAllowLong = true; // Allow Long Positions +double eaAllowShort = true; // Allow Short Positions // -int eaMaxAllowedLongs = 0; -int eaMaxAllowedShorts = 0; +int eaMaxAllowedLongs = 0; // Max Allowed Long Positions +int eaMaxAllowedShorts = 0; // Max Allowed Short Positions // -double eaTPPoint = 200; -double eaSLPoint = 100; +double eaTPPoint = 200; // Static TP Point +double eaSLPoint = 100; // Static SL Point // -bool eaIgnoreTP = false; -bool eaIgnoreSL = false; +bool eaIgnoreTP = false; // Ignore TP +bool eaIgnoreSL = false; // Ignore SL // -double eaR2R = 2; +double eaR2R = 2; // Risk to Reward Ratio // // Variables ... + +// +// Bar Style nad Time Instances ... XSCXCTHelper *mCTHelper; XSCXCCHelper *mCCHelper; // +// Registred Strategies ... XSCBaseStrategy *strategies[]; // @@ -237,9 +241,9 @@ bool InitialEA() eaR2R, // R2R ... eaSlippage, magicNumber, - true, // Use TP SL Point + true, // Use TP SL Point false, // Use Max - 100, // eaTPPoint, // TP + 50, // eaTPPoint, // TP eaSLPoint, // SL eaIgnoreTP, true, // eaIgnoreSL, diff --git a/Strategies/x-saherelm.xtest.strategy.mq5 b/Strategies/x-saherelm.xtest.strategy.mq5 index 54062c7b..20421a70 100644 --- a/Strategies/x-saherelm.xtest.strategy.mq5 +++ b/Strategies/x-saherelm.xtest.strategy.mq5 @@ -21,6 +21,9 @@ // // Imports ... + +// +// Import(s) Helper(s) ... #include "../Helpers/x-saherelm.xhk.helper.mq5" #include "../Helpers/x-saherelm.xmc.helper.mq5" #include "../Helpers/x-saherelm.xtd.helper.mq5" @@ -29,12 +32,17 @@ #include "../Helpers/x-saherelm.xvlm.helper.mq5" #include "../Helpers/x-saherelm.xosc.helper.mq5" #include "../Helpers/x-saherelm.xchma.helper.mq5" + +// +// Base Classes ... #include "../Classes/x-saherelm.xstrategy.class.mq5" // +// Specific Identifier(s) of XStrategy ... string XTestStartegyToken = "XTest"; // +// XStrategy Class Implementation(s) ... class XSCXTestStrategy : public XSCBaseStrategy { // @@ -140,6 +148,9 @@ public: bool hasLong = false; bool hasShort = false; + // + // Retrieve Conditions ... + // // XMC ... XMCConditions mcConditions; @@ -215,6 +226,9 @@ public: rsis // ); + // + // Start Calculations ... + // double points = GetPoints(mSymbol); @@ -225,15 +239,10 @@ public: int ppIndex = pIndex + 1; // - // For Trend ... - XOHCL tmpHSW[]; - XOHCL tmpLSW[]; + // Retrieve Bars ... // - // For Verifications ... - - // - // Bar On Trading Period ... + // Last Bar ... XOHCL cBar; result = cBar.Init( mSymbol, @@ -246,6 +255,7 @@ public: } // + // Previous Bar of Last Bar ... XOHCL pBar; result = cBar.GetPreviousBar(pBar); if (!result) @@ -254,6 +264,7 @@ public: } // + // Last Swing Low Bar ... XOHCL lastSwingLow; result = cBar.FindLastSwingLow(lastSwingLow); if (!result) @@ -262,6 +273,7 @@ public: } // + // Last Swing High Bar ... XOHCL lastSwingHigh; result = cBar.FindLastSwingHigh(lastSwingHigh); if (!result) @@ -270,10 +282,17 @@ public: } // + // Retrieve Highest High(s) and Lowest Low(s) ... + + // + // Highest High ... double hh5 = cBar.FindHighest( 5, MODE_HIGH // ); + + // + // Lowest Low ... double ll5 = cBar.FindLowest( 5, MODE_LOW // @@ -332,6 +351,15 @@ public: } // + // For Trend ... + XOHCL tmpHSW[]; + XOHCL tmpLSW[]; + + // + // Detect Bullish/Bearish Patterns and Trends ... + + // + // Bullish ... bool hasBullishPattern = HasBullishPattern(cBar); bool isBullishTrend = cBar.HasBullishTrend( tmpHSW, @@ -340,6 +368,7 @@ public: ); // + // Bearish ... bool hasBearishPattern = HasBearishPattern(cBar); bool isBearishTrend = cBar.HasBearishTrend( tmpHSW, @@ -347,6 +376,12 @@ public: false // ); + // + // Detect XCHMA based Conditions ... + + // + // Bullish ... + // bool isHCrossedOver = // @@ -404,6 +439,7 @@ public: ; // + // Bullish XCHMA Conditions ... bool isCrossedOver = // isHCrossedOver @@ -422,6 +458,9 @@ public: // ; + // + // Bearish ... + // bool isHCrossedUnder = // @@ -479,6 +518,7 @@ public: ; // + // Bullish XCHMA Conditions ... bool isCrossedUnder = // isHCrossedUnder @@ -497,6 +537,9 @@ public: // ; + // + // XCHE Conditions ... + // bool isCHESwitchedToStrongBullish = cheConditions.isStrongSwitchedToBullish; @@ -504,11 +547,13 @@ public: bool isCHESwitchedToStrongBearish = cheConditions.isStrongSwitchedToBearish; // + // Signalling ... + // Looking for Signals Based on Conditions ... + + // + // Long ... if (isCrossedOver) { - // - // Print("isCrossedOver"); - // hasLong = // @@ -528,10 +573,6 @@ public: // if (hasLong) { - // - // DrawSwingLow(lastSwingLow, ChartID()); - // DrawSwingHigh(lastSwingHigh, ChartID()); - // type = POSITION_TYPE_BUY; sl = cheConditions.long2[1]; @@ -539,41 +580,7 @@ public: } // - if (isCrossedUnder) - { - // - // Print("isCrossedUnder"); - - // - hasShort = - // - (isBearishTrend || - hasBearishPattern) - // - && - // - chmaConditions.isFastUnderSlow && - chmaConditions.isCloseUnderFast && - chmaConditions.isFastResistance && - chmaConditions.isSlowResistance && - cheConditions.isStrongBearish - // - ; - - // - if (hasShort) - { - // - // DrawSwingLow(lastSwingLow, ChartID()); - // DrawSwingHigh(lastSwingHigh, ChartID()); - - // - type = POSITION_TYPE_SELL; - sl = cheConditions.short2[1]; - } - } - - // + // Long ... if (isCHESwitchedToStrongBullish) { // @@ -597,6 +604,36 @@ public: } // + // Short ... + if (isCrossedUnder) + { + // + hasShort = + // + (isBearishTrend || + hasBearishPattern) + // + && + // + chmaConditions.isFastUnderSlow && + chmaConditions.isCloseUnderFast && + chmaConditions.isFastResistance && + chmaConditions.isSlowResistance && + cheConditions.isStrongBearish + // + ; + + // + if (hasShort) + { + // + type = POSITION_TYPE_SELL; + sl = cheConditions.short2[1]; + } + } + + // + // Short ... if (isCHESwitchedToStrongBearish) { // @@ -619,6 +656,9 @@ public: } } + // + // Preparing Signals for Execution ... + // result = hasLong || hasShort; if (!result) @@ -650,7 +690,12 @@ public: } // + // Retrieve Entry Price based on Position Type ... entry = GetEntry(mSymbol, type); + + // + // Calculate TP and SL ... + // based on Strategy ... CalculateTPSLByPrice( sl, tp, @@ -660,6 +705,7 @@ public: ); // + // Preparing Signal ... result = signal.Prepare( mSymbol, GetTag(), @@ -672,12 +718,6 @@ public: tp // ); - // - if (result) - { - // signal.sl = 0; - } - // return result; } @@ -698,6 +738,7 @@ protected: XSCXMCHelper *mcHelper; // + // XTD ... XTDInputs tdInputs; XSCXTDHelper *tdHelper;