From 5e6925104cb156a67c2ed73ea966a451d070fc36 Mon Sep 17 00:00:00 2001 From: Hadi Khazaee Asl Date: Fri, 8 Nov 2024 20:40:04 +0330 Subject: [PATCH] last ... --- Classes/z-saherelm.x-bar.analyser.class.mq5 | 479 ++++++++++++++---- .../x-121.smc.test.strategy.class.mq5 | Bin 156814 -> 157794 bytes 2 files changed, 386 insertions(+), 93 deletions(-) diff --git a/Classes/z-saherelm.x-bar.analyser.class.mq5 b/Classes/z-saherelm.x-bar.analyser.class.mq5 index aeb831a1..def070f5 100644 --- a/Classes/z-saherelm.x-bar.analyser.class.mq5 +++ b/Classes/z-saherelm.x-bar.analyser.class.mq5 @@ -421,20 +421,233 @@ class XCBarAnalyser : public XSCBase return result; } + // + // Bar CHOCH ... + + /** + * Check Specified Bar Has Bullish CHOCH or not ... + * + * @param bar: XOHCL instance, Speciied Bar ... + * @param loopback: Integer, loopback Length ... + * @param forceBody: Boolean, Specified Choch Happens only by Bar's Body ... + * + * @return ( bool ) + */ + bool HasBullishCHOCH( + XOHCL &bar, + int loopback = 3, + bool forceBody = false // + ) + { + // + bool result = false; + + // + ENUM_X_DIRECTION dir; + result = HasCHOCH( + dir, + bar, + loopback, + forceBody // + ); + result = + result && + dir == X_DIRECTION_BULLISH; + + // + return result; + } + + /** + * Check Specified Bar Has Bearish CHOCH or not ... + * + * @param bar: XOHCL instance, Speciied Bar ... + * @param loopback: Integer, loopback Length ... + * @param forceBody: Boolean, Specified Choch Happens only by Bar's Body ... + * + * @return ( bool ) + */ + bool HasBearishCHOCH( + XOHCL &bar, + int loopback = 3, + bool forceBody = false // + ) + { + // + bool result = false; + + // + ENUM_X_DIRECTION dir; + result = HasCHOCH( + dir, + bar, + loopback, + forceBody // + ); + result = + result && + dir == X_DIRECTION_BEARISH; + + // + return result; + } + // protected: // - // - private: - // - - // - // Props ... - // // Actions ... + /** + * Calculate Loopback Data for Specific Bar ... + * + * @param index: Integer, Bar Current Index ... + * @param start: Integer, Start of Loopback ... + * @param end: Integer, End of Loopback ... + * @param count: Integer, Number of Calculating Bars ... + * @param bar: XOHCL instance, Specified Bar ... + * @param loopback: Integer, Loopback Length ... + * @return ( bool ) + */ + bool CalculateLoopBackData( + int &index, + int &start, + int &end, + int &count, + XOHCL &bar, + int loopback = 1 // + ) + { + // + bool result = false; + + // + if (loopback < 1) + { + loopback = 1; + } + + // + index = -1; + start = -1; + end = -1; + count = -1; + + // + result = bar.IsValid(); + if (!result) + { + return result; + } + + // + index = bar.Index(); + start = index + 1; + end = start + loopback; + count = end - start; + result = count >= 1; + if (!result) + { + return result; + } + + // + return result; + } + + /** + * Retrieve Loopback HH & LL Data ... + * + * @param hhIDX: Integer, HH Index ... + * @param hh: Double, HH Value ... + * @param llIDX: Integer, LL Index ... + * @param ll: Double, LL Value ... + * @param bar: XOHCL instance ... + * @param loopback: Integer, Loopback Length ... + * + * @return ( bool ) + */ + bool CalculateLoopbackHLData( + int &hhIDX, + double &hh, + int &llIDX, + double &ll, + XOHCL &bar, + int loopback // + ) + { + // + bool result = false; + + // + if (loopback < 1) + { + loopback = 1; + } + + // + int index = -1; + int start = -1; + int end = -1; + int count = -1; + result = CalculateLoopBackData( + index, + start, + end, + count, + bar, + loopback // + ); + if (!result) + { + return result; + } + + // + hhIDX = iHighest( + bar.symbol, + bar.period, + MODE_HIGH, + start, + count // + ); + result = IsValidIndex(hhIDX); + if (!result) + { + return result; + } + + // + llIDX = iLowest( + bar.symbol, + bar.period, + MODE_LOW, + start, + count // + ); + result = IsValidIndex(llIDX); + if (!result) + { + return result; + } + + // + hh = iHigh( + bar.symbol, + bar.period, + hhIDX // + ); + ll = iLow( + bar.symbol, + bar.period, + llIDX // + ); + + // + return result; + } + /** * Calculate Bar Range ... * @@ -564,91 +777,6 @@ class XCBarAnalyser : public XSCBase return result; } - /** - * Retrieve Loopback HH LL Data ... - * - * @param hhIDX: Integer, HH Index ... - * @param hh: Double, HH Value ... - * @param llIDX: Integer, LL Index ... - * @param ll: Double, LL Value ... - * @param bar: XOHCL instance ... - * @param loopback: Integer, Loopback Length ... - * - * @return ( bool ) - */ - bool GetLoopbackData( - int &hhIDX, - double &hh, - int &llIDX, - double &ll, - XOHCL &bar, - int loopback // - ) - { - // - bool result = false; - - // - if (loopback < 1) - { - loopback = 1; - } - - // - int index = bar.Index(); - int start = index + 1; - int end = start + loopback; - int count = end - start; - result = count >= 1; - if (!result) - { - return result; - } - - // - hhIDX = iHighest( - bar.symbol, - bar.period, - MODE_HIGH, - start, - count // - ); - result = IsValidIndex(hhIDX); - if (!result) - { - return result; - } - - // - llIDX = iLowest( - bar.symbol, - bar.period, - MODE_LOW, - start, - count // - ); - result = IsValidIndex(llIDX); - if (!result) - { - return result; - } - - // - hh = iHigh( - bar.symbol, - bar.period, - hhIDX // - ); - ll = iLow( - bar.symbol, - bar.period, - llIDX // - ); - - // - return result; - } - /** * Check Bar is Engulfed or not ... * @@ -679,7 +807,7 @@ class XCBarAnalyser : public XSCBase double ll = 0; // - result = GetLoopbackData( + result = CalculateLoopbackHLData( hhIDX, hh, llIDX, @@ -707,6 +835,171 @@ class XCBarAnalyser : public XSCBase return result; } + /** + * Check Specified Bar Has CHOCH or not ... + * + * @param dir: ENUM_X_DIRECTION member, Specified Direction ... + * @param bar: XOHCL instance, Speciied Bar ... + * @param loopback: Integer, loopback Length ... + * @param forceBody: Boolean, Specified Choch Happens only by Bar's Body ... + * + * @return ( bool ) + */ + bool HasCHOCH( + ENUM_X_DIRECTION &dir, + XOHCL &bar, + int loopback = 3, + bool forceBody = false // + ) + { + // + bool result = false; + + // + dir = X_DIRECTION_NONE; + + // + if (loopback < 1) + { + loopback = 1; + } + + // + result = bar.IsValid(); + if (!result) + { + return result; + } + + // + string symbol = bar.symbol; + ENUM_TIMEFRAMES period = bar.period; + + // + // Calculate Loopback Data ... + int index = -1; + int start = -1; + int end = -1; + int count = -1; + result = CalculateLoopBackData( + index, + start, + end, + count, + bar, + loopback // + ); + if (!result) + { + return result; + } + + // + // Calculate Loopback HH and LL Data ... + int hhIDX = -1; + double hh = -1; + int llIDX = -1; + double ll = -1; + result = CalculateLoopbackHLData( + hhIDX, + hh, + llIDX, + ll, + bar, + loopback // + ); + if (!result) + { + return result; + } + + // + bool isBullishDirection = + bar.high > hh && + bar.low > ll; + bool isBearishDirection = + bar.high < hh && + bar.low < ll; + result = isBullishDirection || + isBearishDirection; + if (!result) + { + return result; + } + + // + if (forceBody) + { + // + isBullishDirection = + bar.GetUp() > hh && + bar.GetDown() > ll; + isBearishDirection = + bar.GetUp() < hh && + bar.GetDown() < ll; + result = isBullishDirection || + isBearishDirection; + if (!result) + { + return result; + } + } + + // + // Check Bar's Direction in related to CHOCH Direction ... + result = + isBullishDirection + ? bar.IsBullish() + : bar.IsBearish(); + if (!result) + { + return result; + } + + // + // Set Direction ... + dir = + isBullishDirection + ? X_DIRECTION_BULLISH + : X_DIRECTION_BEARISH; + + // + // Check Loopback End Bar ... + XOHCL endBar; + result = endBar.Init( + symbol, + period, + end // + ); + if (!result) + { + return result; + } + + // + // End Bar Must be InDirect by Specified Bar ... + result = + isBullishDirection + ? endBar.IsBearish() + : endBar.IsBullish(); + + // + // Check Loopback for Directional Bars ... + + // + return result; + } + + // + private: + // + + // + // Props ... + + // + // Actions ... + // }; diff --git a/X121SMCEA/Strategy/x-121.smc.test.strategy.class.mq5 b/X121SMCEA/Strategy/x-121.smc.test.strategy.class.mq5 index 41a4d515caca4e281dbeb3f67bdc3b82da09f1e8..f3f6f92dbca15550c165eebacd4b29107ba96d6c 100644 GIT binary patch delta 370 zcmeA>$@%C4XG06)7ABjN$rA(w#GM#Q8FGLylcAU)gTa}>gTWs}PQMtzq$umbkO&mU zrNl9m$$hd>x7_3nYFyF^4EjK*z~IJ^&rrmW%#aFXI|0pdVThcpC@DLAf)%5kYzEZ4 zR3Kf1-%9LCNV0N49FyDRdwOiR{5bibmhR*aCLnpNwoU#hD?hz1naNKQ9xOmlfx@H! o2vZsI7>cL=3}*_Ryg*)KvO&1WWCeCMfm#M@23`g(Fb0JP0OZ+GhyVZp delta 18 ZcmaEKfwS)i!{K>$qh2HF4s