From 8e502953a36ac08d2d4037bf048caaf7a5bc4054 Mon Sep 17 00:00:00 2001 From: Hadi Khazaee Asl Date: Sat, 25 Jan 2025 21:42:37 +0330 Subject: [PATCH] complete XHK Indicator and it's related Helper and also Attached it to x121 Helper ... --- Helpers/x-saherelm.x121.helper.mq5 | 251 ++- Helpers/x-saherelm.x121.xhk.helper.mq5 | 1448 ++++++++++++++++++ Indicators/x-saherelm.x121.xhk.mq5 | 484 +++--- X121SMCEA/Signals/x-121.smc.x.signal.lib.mq5 | 1 + 4 files changed, 1923 insertions(+), 261 deletions(-) create mode 100644 Helpers/x-saherelm.x121.xhk.helper.mq5 diff --git a/Helpers/x-saherelm.x121.helper.mq5 b/Helpers/x-saherelm.x121.helper.mq5 index 0c9a0d3b..26266a63 100644 --- a/Helpers/x-saherelm.x121.helper.mq5 +++ b/Helpers/x-saherelm.x121.helper.mq5 @@ -25,6 +25,7 @@ #include "../Helpers/x-saherelm.x121.xatr.helper.mq5" #include "../Helpers/x-saherelm.x121.xche.helper.mq5" #include "../Helpers/x-saherelm.x121.xdon.helper.mq5" +#include "../Helpers/x-saherelm.x121.xhk.helper.mq5" #include "../Helpers/x-saherelm.x121.xpv.helper.mq5" #include "../Helpers/x-saherelm.x121.xstr.helper.mq5" #include "../Helpers/x-saherelm.x121.xvwap.helper.mq5" @@ -37,6 +38,7 @@ struct X121Inputs // Props ... bool showRSI; X121XPVInputs xpvInputs; + X121XHKInputs xhkInputs; X121XATRInputs xatrInputs; X121XSTRInputs xstrInputs; X121XCHEInputs xcheInputs; @@ -60,6 +62,7 @@ struct X121Inputs { // xpvInputs.Clean(); + xhkInputs.Clean(); xatrInputs.Clean(); xstrInputs.Clean(); xcheInputs.Clean(); @@ -74,6 +77,7 @@ struct X121Inputs { // xpvInputs.Default(); + xhkInputs.Default(); xatrInputs.Default(); xstrInputs.Default(); xcheInputs.Default(); @@ -95,6 +99,7 @@ struct X121Inputs result = // xpvInputs.IsValid() && + xhkInputs.IsValid() && xatrInputs.IsValid() && xstrInputs.IsValid() && xcheInputs.IsValid() && @@ -119,6 +124,7 @@ struct X121Inputs // int xpvMax = xpvInputs.Max(); + int xhkMax = xpvInputs.Max(); int xatrMax = xatrInputs.Max(); int xstrMax = xstrInputs.Max(); int xcheMax = xcheInputs.Max(); @@ -126,7 +132,8 @@ struct X121Inputs int xvwapMax = xvwapInputs.Max(); // - result = MathMax(xpvMax, xatrMax); + result = MathMax(xpvMax, xpvMax); + result = MathMax(result, xatrMax); result = MathMax(result, xstrMax); result = MathMax(result, xcheMax); result = MathMax(result, xdonMax); @@ -183,8 +190,16 @@ struct X121Conditions double strStateBuffer[]; double vwapFastBuffer[]; double vwapSlowBuffer[]; + double xhkSMLowBuffer[]; double vwapPriceBuffer[]; + double xhkRawLowBuffer[]; + double xhkSMOpenBuffer[]; + double xhkSMHighBuffer[]; + double xhkRawOpenBuffer[]; + double xhkRawHighBuffer[]; + double xhkSMCloseBuffer[]; double vwapVolumeBuffer[]; + double xhkRawCloseBuffer[]; double atrUpperRawBuffer[]; double atrLowerRawBuffer[]; double donLowUpperBuffer[]; @@ -352,6 +367,32 @@ struct X121Conditions bool isVWapSwitchedToBullishOrdered; bool isVWapSwitchedToBearishOrdered; + // + bool isSMHKBullish; + bool isRawHKBullish; + bool isSMHKBearish; + bool isRawHKBearish; + bool isBreakedUpSMHK; + bool isBreakedUpRawHK; + bool isRejectedUpSMHK; + bool isClosedOverSMHK; + bool isRejectedUpRawHK; + bool isBreakedDownSMHK; + bool isClosedUnderSMHK; + bool isClosedOverRawHK; + bool isClosedUnderRawHK; + bool isBreakedDownRawHK; + bool isRejectedDownSMHK; + bool isRejectedDownRawHK; + bool isRawHKBreakedUpSMHK; + bool isRawHKClosedOverSMHK; + bool isSMHKSwitchedBearish; + bool isRawHKSwitchedBearish; + bool isRawHKClosedUnderSMHK; + bool isRawHKBreakedDownSMHK; + bool isSMHKSwitchedToBullish; + bool isRawHKSwitchedToBullish; + // // Complex Conditions ... double cheMin; @@ -562,10 +603,10 @@ struct X121Conditions Clean(lLLBuffer); Clean(hHHBuffer); Clean(hLLBuffer); + Clean(volumeBuffer); Clean(peaksBuffer); Clean(valesBuffer); Clean(strUpBuffer); - Clean(volumeBuffer); Clean(strDownBuffer); Clean(vwapMidBuffer); Clean(le1StartBuffer); @@ -578,8 +619,16 @@ struct X121Conditions Clean(strStateBuffer); Clean(vwapFastBuffer); Clean(vwapSlowBuffer); + Clean(xhkSMLowBuffer); Clean(vwapPriceBuffer); + Clean(xhkRawLowBuffer); + Clean(xhkSMOpenBuffer); + Clean(xhkSMHighBuffer); + Clean(xhkRawOpenBuffer); + Clean(xhkRawHighBuffer); + Clean(xhkSMCloseBuffer); Clean(vwapVolumeBuffer); + Clean(xhkRawCloseBuffer); Clean(atrUpperRawBuffer); Clean(atrLowerRawBuffer); Clean(donLowUpperBuffer); @@ -613,10 +662,10 @@ struct X121Conditions ArraySetAsSeries(lLLBuffer, true); ArraySetAsSeries(hHHBuffer, true); ArraySetAsSeries(hLLBuffer, true); + ArraySetAsSeries(volumeBuffer, true); ArraySetAsSeries(peaksBuffer, true); ArraySetAsSeries(valesBuffer, true); ArraySetAsSeries(strUpBuffer, true); - ArraySetAsSeries(volumeBuffer, true); ArraySetAsSeries(strDownBuffer, true); ArraySetAsSeries(vwapMidBuffer, true); ArraySetAsSeries(le1StartBuffer, true); @@ -629,8 +678,16 @@ struct X121Conditions ArraySetAsSeries(strStateBuffer, true); ArraySetAsSeries(vwapFastBuffer, true); ArraySetAsSeries(vwapSlowBuffer, true); + ArraySetAsSeries(xhkSMLowBuffer, true); ArraySetAsSeries(vwapPriceBuffer, true); + ArraySetAsSeries(xhkRawLowBuffer, true); + ArraySetAsSeries(xhkSMOpenBuffer, true); + ArraySetAsSeries(xhkSMHighBuffer, true); + ArraySetAsSeries(xhkRawOpenBuffer, true); + ArraySetAsSeries(xhkRawHighBuffer, true); + ArraySetAsSeries(xhkSMCloseBuffer, true); ArraySetAsSeries(vwapVolumeBuffer, true); + ArraySetAsSeries(xhkRawCloseBuffer, true); ArraySetAsSeries(atrUpperRawBuffer, true); ArraySetAsSeries(atrLowerRawBuffer, true); ArraySetAsSeries(donLowUpperBuffer, true); @@ -868,6 +925,33 @@ struct X121Conditions isClosedUnderCheMin = false; isClosedUnderCheMax = false; + // + // XHK ... + isSMHKBullish = false; + isRawHKBullish = false; + isSMHKBearish = false; + isRawHKBearish = false; + isBreakedUpSMHK = false; + isBreakedUpRawHK = false; + isRejectedUpSMHK = false; + isClosedOverSMHK = false; + isRejectedUpRawHK = false; + isBreakedDownSMHK = false; + isClosedUnderSMHK = false; + isClosedOverRawHK = false; + isClosedUnderRawHK = false; + isBreakedDownRawHK = false; + isRejectedDownSMHK = false; + isRejectedDownRawHK = false; + isRawHKBreakedUpSMHK = false; + isRawHKClosedOverSMHK = false; + isSMHKSwitchedBearish = false; + isRawHKSwitchedBearish = false; + isRawHKClosedUnderSMHK = false; + isRawHKBreakedDownSMHK = false; + isSMHKSwitchedToBullish = false; + isRawHKSwitchedToBullish = false; + // // Complex Conditions ... @@ -1217,6 +1301,34 @@ struct X121Conditions ToString("isClosedUnderCheMax", isClosedUnderCheMax, ignoreFalseConditions, separator) + // "-----------------------" + separator + + "HK ..." + separator + + "-----------------------" + separator + + ToString("isSMHKBullish", isSMHKBullish, ignoreFalseConditions, separator) + + ToString("isRawHKBullish", isRawHKBullish, ignoreFalseConditions, separator) + + ToString("isSMHKBearish", isSMHKBearish, ignoreFalseConditions, separator) + + ToString("isRawHKBearish", isRawHKBearish, ignoreFalseConditions, separator) + + ToString("isBreakedUpSMHK", isBreakedUpSMHK, ignoreFalseConditions, separator) + + ToString("isBreakedUpRawHK", isBreakedUpRawHK, ignoreFalseConditions, separator) + + ToString("isRejectedUpSMHK", isRejectedUpSMHK, ignoreFalseConditions, separator) + + ToString("isClosedOverSMHK", isClosedOverSMHK, ignoreFalseConditions, separator) + + ToString("isRejectedUpRawHK", isRejectedUpRawHK, ignoreFalseConditions, separator) + + ToString("isBreakedDownSMHK", isBreakedDownSMHK, ignoreFalseConditions, separator) + + ToString("isClosedUnderSMHK", isClosedUnderSMHK, ignoreFalseConditions, separator) + + ToString("isClosedOverRawHK", isClosedOverRawHK, ignoreFalseConditions, separator) + + ToString("isClosedUnderRawHK", isClosedUnderRawHK, ignoreFalseConditions, separator) + + ToString("isBreakedDownRawHK", isBreakedDownRawHK, ignoreFalseConditions, separator) + + ToString("isRejectedDownSMHK", isRejectedDownSMHK, ignoreFalseConditions, separator) + + ToString("isRejectedDownRawHK", isRejectedDownRawHK, ignoreFalseConditions, separator) + + ToString("isRawHKBreakedUpSMHK", isRawHKBreakedUpSMHK, ignoreFalseConditions, separator) + + ToString("isRawHKClosedOverSMHK", isRawHKClosedOverSMHK, ignoreFalseConditions, separator) + + ToString("isSMHKSwitchedBearish", isSMHKSwitchedBearish, ignoreFalseConditions, separator) + + ToString("isRawHKSwitchedBearish", isRawHKSwitchedBearish, ignoreFalseConditions, separator) + + ToString("isRawHKClosedUnderSMHK", isRawHKClosedUnderSMHK, ignoreFalseConditions, separator) + + ToString("isRawHKBreakedDownSMHK", isRawHKBreakedDownSMHK, ignoreFalseConditions, separator) + + ToString("isSMHKSwitchedToBullish", isSMHKSwitchedToBullish, ignoreFalseConditions, separator) + + ToString("isRawHKSwitchedToBullish", isRawHKSwitchedToBullish, ignoreFalseConditions, separator) + + // + "-----------------------" + separator + "Slopes ..." + separator + "-----------------------" + separator + ToString("isRsiSlopeBullish", isRsiSlopeBullish, ignoreFalseConditions, separator) + @@ -1372,6 +1484,7 @@ class XCX121Helper : public XCBase // // Helpers ... XCX121XPVHelper *xpvHelper; + XCX121XHKHelper *xhkHelper; XCX121XATRHelper *xatrHelper; XCX121XSTRHelper *xstrHelper; XCX121XCHEHelper *xcheHelper; @@ -1390,6 +1503,7 @@ class XCX121Helper : public XCBase { // delete xpvHelper; + delete xhkHelper; delete xatrHelper; delete xstrHelper; delete xcheHelper; @@ -1450,6 +1564,7 @@ class XCX121Helper : public XCBase // mInputs = inputs; xpvInputs = inputs.xpvInputs; + xhkInputs = inputs.xhkInputs; xatrInputs = inputs.xatrInputs; xstrInputs = inputs.xstrInputs; xcheInputs = inputs.xcheInputs; @@ -1472,6 +1587,19 @@ class XCX121Helper : public XCBase return result; } + // + // XHK ... + xhkHelper = new XCX121XHKHelper(); + result = xhkHelper.Init( + symbol, + period, + xhkInputs // + ); + if (!result) + { + return result; + } + // // XATR ... xatrHelper = new XCX121XATRHelper(); @@ -1585,6 +1713,28 @@ class XCX121Helper : public XCBase return result; } + // + // XHK ... + bool GetHKConditions( + X121XHKConditions &conditions, // + int barIndex = 0, // + int loopback = 5 // + ) + { + // + bool result = false; + + // + result = xhkHelper.GetConditions( + conditions, + barIndex, + loopback // + ); + + // + return result; + } + // // XATR ... bool GetATRConditions( @@ -1774,6 +1924,19 @@ class XCX121Helper : public XCBase return result; } + // + // XHK ... + X121XHKConditions xhkConditions; + result = GetHKConditions( + xhkConditions, + barIndex, + loopback // + ); + if (!result) + { + return result; + } + // // XATR ... X121XATRConditions xatrConditions; @@ -1969,6 +2132,87 @@ class XCX121Helper : public XCBase conditions.isSarSwitchedToBullish = xpvConditions.isSarSwitchedToBullish; conditions.isSarSwitchedToBearish = xpvConditions.isSarSwitchedToBearish; + // + // XHK ... + + // + // Buffers ... + + // + Copy( + xhkConditions.xhkRawOpenBuffer, + conditions.xhkRawOpenBuffer // + ); + + // + Copy( + xhkConditions.xhkRawHighBuffer, + conditions.xhkRawHighBuffer // + ); + + // + Copy( + xhkConditions.xhkRawLowBuffer, + conditions.xhkRawLowBuffer // + ); + + // + Copy( + xhkConditions.xhkRawCloseBuffer, + conditions.xhkRawCloseBuffer // + ); + + // + Copy( + xhkConditions.xhkSMOpenBuffer, + conditions.xhkSMOpenBuffer // + ); + + // + Copy( + xhkConditions.xhkSMHighBuffer, + conditions.xhkSMHighBuffer // + ); + + // + Copy( + xhkConditions.xhkSMLowBuffer, + conditions.xhkSMLowBuffer // + ); + + // + Copy( + xhkConditions.xhkSMCloseBuffer, + conditions.xhkSMCloseBuffer // + ); + + // + // Conditions ... + conditions.isSMHKBullish = xhkConditions.isSMHKBullish; + conditions.isRawHKBullish = xhkConditions.isRawHKBullish; + conditions.isSMHKBearish = xhkConditions.isSMHKBearish; + conditions.isRawHKBearish = xhkConditions.isRawHKBearish; + conditions.isBreakedUpSMHK = xhkConditions.isBreakedUpSMHK; + conditions.isBreakedUpRawHK = xhkConditions.isBreakedUpRawHK; + conditions.isRejectedUpSMHK = xhkConditions.isRejectedUpSMHK; + conditions.isClosedOverSMHK = xhkConditions.isClosedOverSMHK; + conditions.isRejectedUpRawHK = xhkConditions.isRejectedUpRawHK; + conditions.isBreakedDownSMHK = xhkConditions.isBreakedDownSMHK; + conditions.isClosedUnderSMHK = xhkConditions.isClosedUnderSMHK; + conditions.isClosedOverRawHK = xhkConditions.isClosedOverRawHK; + conditions.isClosedUnderRawHK = xhkConditions.isClosedUnderRawHK; + conditions.isBreakedDownRawHK = xhkConditions.isBreakedDownRawHK; + conditions.isRejectedDownSMHK = xhkConditions.isRejectedDownSMHK; + conditions.isRejectedDownRawHK = xhkConditions.isRejectedDownRawHK; + conditions.isRawHKBreakedUpSMHK = xhkConditions.isRawHKBreakedUpSMHK; + conditions.isRawHKClosedOverSMHK = xhkConditions.isRawHKClosedOverSMHK; + conditions.isSMHKSwitchedBearish = xhkConditions.isSMHKSwitchedBearish; + conditions.isRawHKSwitchedBearish = xhkConditions.isRawHKSwitchedBearish; + conditions.isRawHKClosedUnderSMHK = xhkConditions.isRawHKClosedUnderSMHK; + conditions.isRawHKBreakedDownSMHK = xhkConditions.isRawHKBreakedDownSMHK; + conditions.isSMHKSwitchedToBullish = xhkConditions.isSMHKSwitchedToBullish; + conditions.isRawHKSwitchedToBullish = xhkConditions.isRawHKSwitchedToBullish; + // // XATR ... @@ -2919,6 +3163,7 @@ class XCX121Helper : public XCBase // Inputs ... X121Inputs mInputs; X121XPVInputs xpvInputs; + X121XHKInputs xhkInputs; X121XATRInputs xatrInputs; X121XDONInputs xdonInputs; X121XSTRInputs xstrInputs; diff --git a/Helpers/x-saherelm.x121.xhk.helper.mq5 b/Helpers/x-saherelm.x121.xhk.helper.mq5 new file mode 100644 index 00000000..8112ebae --- /dev/null +++ b/Helpers/x-saherelm.x121.xhk.helper.mq5 @@ -0,0 +1,1448 @@ +/////////////////////////////////////////////////////// +// +// SaherElm IT Center MQL5 Helper Class Library +// ---------------------------------------------- +// Name: XCX121XHKHelper +// Description: provides all Indicator +// Helper requirements ... +// +// +// Maintainer: +// ------------ +// Hadi Khazaee Asl (hadi_khazaee_asl@yahoo.com) +// +////////////////////////////////////////////////////// +// +// Global Properties ... +#property library +#property copyright "Copyright 2023, SaherElm IT Center" +#property link "https://www.saherelm.ir" +#property version "1.00" +#property strict + +// +// Imports ... +#include "../Classes/x-saherelm.x-helper.class.mq5" + +// +// Definitions ... + +// +// Definitions ... +enum ENUM_X121_XHK_BUFFERS +{ + // + X121_XHK_RAW_OPEN_LINE = 0, + X121_XHK_RAW_HIGH_LINE = 1, + X121_XHK_RAW_LOW_LINE = 2, + X121_XHK_RAW_CLOSE_LINE = 3, + // + X121_XHK_SM_OPEN_LINE = 5, + X121_XHK_SM_HIGH_LINE = 6, + X121_XHK_SM_LOW_LINE = 7, + X121_XHK_SM_CLOSE_LINE = 8, +}; + +// +// Input Models ... +struct X121XHKInputs +{ + // + // Props ... + int xhkSmoothingLength; // Length + ENUM_X_MA_METHOD xhkSmoothingMode; // Smoothing Method + bool xhkIgnoreSmoothingShadows; // Ignore Smoothed Bar Shadows + int startCalculationForLastBars; // Calculate Last n Bars + bool drawRawXHKCandles; // Draw Raw Candle + bool drawSmoothedXHKCandles; // Draw Smoothed Candle + + // + // Constructor(s) ... + X121XHKInputs() + { + // + Clean(); + } + + // + // Tools ... + + // + // Clean ... + void Clean() + { + // + xhkSmoothingLength = 0; + xhkSmoothingMode = X_MA_MODE_NONE; + xhkIgnoreSmoothingShadows = false; + startCalculationForLastBars = 1500; + drawRawXHKCandles = false; + drawSmoothedXHKCandles = false; + } + + // + // Default ... + void Default() + { + // + xhkSmoothingLength = 14; + xhkSmoothingMode = X_MA_MODE_EMA; + xhkIgnoreSmoothingShadows = false; + startCalculationForLastBars = 1500; + drawRawXHKCandles = true; + drawSmoothedXHKCandles = true; + } + + // + // Validate ... + bool IsValid() + { + // + bool result = false; + + // + result = + // + true + // + ; + + // + return result; + } + + // + // Retrieve MAx Length ... + int Max() + { + // + int result = 0; + + // + result = MathMax(0, xhkSmoothingLength); + + // + return result; + } +}; + +// +// Conditions ... +struct X121XHKConditions +{ + // + // Common ... + string symbol; + ENUM_TIMEFRAMES period; + datetime time; + + // + // Buffers ... + + // + double xhkRawOpenBuffer[]; + double xhkRawHighBuffer[]; + double xhkRawLowBuffer[]; + double xhkRawCloseBuffer[]; + + // + double xhkSMOpenBuffer[]; + double xhkSMHighBuffer[]; + double xhkSMLowBuffer[]; + double xhkSMCloseBuffer[]; + + // + // Conditions ... + + // + bool isSMHKBullish; + bool isRawHKBullish; + bool isSMHKSwitchedToBullish; + bool isRawHKSwitchedToBullish; + + // + bool isSMHKBearish; + bool isRawHKBearish; + bool isSMHKSwitchedBearish; + bool isRawHKSwitchedBearish; + + // + bool isClosedOverSMHK; + bool isClosedUnderSMHK; + bool isClosedOverRawHK; + bool isClosedUnderRawHK; + + // + bool isRawHKClosedOverSMHK; + bool isRawHKClosedUnderSMHK; + + // + bool isBreakedUpSMHK; + bool isBreakedUpRawHK; + bool isRejectedUpSMHK; + bool isRejectedUpRawHK; + bool isRawHKBreakedUpSMHK; + + // + bool isBreakedDownSMHK; + bool isBreakedDownRawHK; + bool isRejectedDownSMHK; + bool isRejectedDownRawHK; + bool isRawHKBreakedDownSMHK; + + // + // Constructor ... + X121XHKConditions() + { + Clean(); + } + + // + // Tools ... + + /** + * Cleaning Up ... + */ + void Clean() + { + // + // Commons ... + symbol = NULL; + period = NULL; + time = NULL; + + // + // Buffers ... + + // + Clean(xhkRawOpenBuffer); + Clean(xhkRawHighBuffer); + Clean(xhkRawLowBuffer); + Clean(xhkRawCloseBuffer); + Clean(xhkSMOpenBuffer); + Clean(xhkSMHighBuffer); + Clean(xhkSMLowBuffer); + Clean(xhkSMCloseBuffer); + + // + ArraySetAsSeries(xhkRawOpenBuffer, true); + ArraySetAsSeries(xhkRawHighBuffer, true); + ArraySetAsSeries(xhkRawLowBuffer, true); + ArraySetAsSeries(xhkRawCloseBuffer, true); + ArraySetAsSeries(xhkSMOpenBuffer, true); + ArraySetAsSeries(xhkSMHighBuffer, true); + ArraySetAsSeries(xhkSMLowBuffer, true); + ArraySetAsSeries(xhkSMCloseBuffer, true); + + // + // Conditions ... + + // + isSMHKBullish = false; + isRawHKBullish = false; + isSMHKSwitchedToBullish = false; + isRawHKSwitchedToBullish = false; + + // + isSMHKBearish = false; + isRawHKBearish = false; + isSMHKSwitchedBearish = false; + isRawHKSwitchedBearish = false; + + // + isClosedOverSMHK = false; + isClosedUnderSMHK = false; + isClosedOverRawHK = false; + isClosedUnderRawHK = false; + + // + isRawHKClosedOverSMHK = false; + isRawHKClosedUnderSMHK = false; + + // + isBreakedUpSMHK = false; + isBreakedUpRawHK = false; + isRejectedUpSMHK = false; + isRejectedUpRawHK = false; + isRawHKBreakedUpSMHK = false; + + // + isBreakedDownSMHK = false; + isBreakedDownRawHK = false; + isRejectedDownSMHK = false; + isRejectedDownRawHK = false; + isRawHKBreakedDownSMHK = false; + } + + /** + * Generate Conditions Scores ... + * + * @param bullishScore: Double, Directional Scores Reference ... + * @param bearishScore: Double, Directional Scores Reference ... + */ + void GenerateScore( + double &bullishScore, + double &bearishScore // + ) + { + // + bullishScore = 0; + bearishScore = 0; + + // + // TODO: Implement if Required ... + } + + /** + * Generate Summary String for Represent Conditions State ... + * + * @param onlyCommons: Boolean, Just Generate Only Commons Conditions ... + * @param onlyConditions: Boolean, Just Generate Only Conditions ... + * @param includeScores: Boolean, Attach Scores Representations on Result ... + * @param ignoreFalseConditions: Boolean, Ignore False Conditions on Result ... + * @param separator: String, Separate Lines ... + * + * @return ( string ) + */ + string GenerateSummary( + bool onlyCommons = false, + bool onlyConditions = false, + bool includeScores = true, + bool ignoreFalseConditions = true, + string separator = "\n" // + ) + { + // + string result = NULL; + + // + double bullishScore = 0; + double bearishScore = 0; + GenerateScore( + bullishScore, + bearishScore // + ); + + // + string scoresStr = + // + "Scores: " + separator + + "---------------" + separator + + "Bullish: " + ToString(bullishScore) + separator + + "Bearish: " + ToString(bearishScore) + separator + + "" + // + ; + + // + string commonStr = GenerateSpecifiedCommonSummary( + this, + separator, + includeScores // + ); + + // + string conditionsStr = + // + ToString("isSMHKBullish", isSMHKBullish, ignoreFalseConditions, separator) + + ToString("isRawHKBullish", isRawHKBullish, ignoreFalseConditions, separator) + + ToString("isSMHKSwitchedToBullish", isSMHKSwitchedToBullish, ignoreFalseConditions, separator) + + ToString("isRawHKSwitchedToBullish", isRawHKSwitchedToBullish, ignoreFalseConditions, separator) + + ToString("isSMHKBearish", isSMHKBearish, ignoreFalseConditions, separator) + + ToString("isRawHKBearish", isRawHKBearish, ignoreFalseConditions, separator) + + ToString("isSMHKSwitchedBearish", isSMHKSwitchedBearish, ignoreFalseConditions, separator) + + ToString("isRawHKSwitchedBearish", isRawHKSwitchedBearish, ignoreFalseConditions, separator) + + ToString("isClosedOverSMHK", isClosedOverSMHK, ignoreFalseConditions, separator) + + ToString("isClosedUnderSMHK", isClosedUnderSMHK, ignoreFalseConditions, separator) + + ToString("isClosedOverRawHK", isClosedOverRawHK, ignoreFalseConditions, separator) + + ToString("isClosedUnderRawHK", isClosedUnderRawHK, ignoreFalseConditions, separator) + + ToString("isRawHKClosedOverSMHK", isRawHKClosedOverSMHK, ignoreFalseConditions, separator) + + ToString("isRawHKClosedUnderSMHK", isRawHKClosedUnderSMHK, ignoreFalseConditions, separator) + + ToString("isBreakedUpSMHK", isBreakedUpSMHK, ignoreFalseConditions, separator) + + ToString("isBreakedUpRawHK", isBreakedUpRawHK, ignoreFalseConditions, separator) + + ToString("isRejectedUpSMHK", isRejectedUpSMHK, ignoreFalseConditions, separator) + + ToString("isRejectedUpRawHK", isRejectedUpRawHK, ignoreFalseConditions, separator) + + ToString("isRawHKBreakedUpSMHK", isRawHKBreakedUpSMHK, ignoreFalseConditions, separator) + + ToString("isBreakedDownSMHK", isBreakedDownSMHK, ignoreFalseConditions, separator) + + ToString("isBreakedDownRawHK", isBreakedDownRawHK, ignoreFalseConditions, separator) + + ToString("isRejectedDownSMHK", isRejectedDownSMHK, ignoreFalseConditions, separator) + + ToString("isRejectedDownRawHK", isRejectedDownRawHK, ignoreFalseConditions, separator) + + ToString("isRawHKBreakedDownSMHK", isRawHKBreakedDownSMHK, ignoreFalseConditions, separator) + + // + "" + // + ; + + // + result = + // + "[" + GetTag() + "]" + separator + + (onlyConditions + ? "" + : commonStr) + + (!includeScores + ? "" + : scoresStr) + + " " + separator + + (onlyCommons + ? "" + : conditionsStr) + + "" + // + ; + + // + return result; + } + + /** + * Retrieve nique Tag Identifier ... + * + * @return ( string ) + */ + string GetTag() + { + return GetTypeName(this); + } + + // +}; + +// +// Class ... +class XCX121XHKHelper : public XCBaseHelper +{ + // + // Public ... + public: + // + // Props ... + + // + // Constructors ... + XCX121XHKHelper() + : XCBaseHelper(_Symbol, _Period) + { + } + + // + // Deconstructor ... + ~XCX121XHKHelper() + { + // + ArrayFree(xhkRawOpenBuffer); + ArrayFree(xhkRawHighBuffer); + ArrayFree(xhkRawLowBuffer); + ArrayFree(xhkRawCloseBuffer); + ArrayFree(xhkSMOpenBuffer); + ArrayFree(xhkSMHighBuffer); + ArrayFree(xhkSMLowBuffer); + ArrayFree(xhkSMCloseBuffer); + + // + mInputs.Clean(); + } + + // + // Tools ... + bool Init( + string symbol, // Trading Symbol + ENUM_TIMEFRAMES period, // Trading Period + X121XHKInputs &inputs // Inputs + ) + { + // + bool result = false; + + // + mSymbol = symbol; + mPeriod = period; + + // + result = inputs.IsValid(); + if (!result) + { + return result; + } + + // + ArraySetAsSeries(xhkRawOpenBuffer, true); + ArraySetAsSeries(xhkRawHighBuffer, true); + ArraySetAsSeries(xhkRawLowBuffer, true); + ArraySetAsSeries(xhkRawCloseBuffer, true); + ArraySetAsSeries(xhkSMOpenBuffer, true); + ArraySetAsSeries(xhkSMHighBuffer, true); + ArraySetAsSeries(xhkSMLowBuffer, true); + ArraySetAsSeries(xhkSMCloseBuffer, true); + + // + mInputs = inputs; + + // + mHandler = iCustom( + mSymbol, + mPeriod, + "x-saherelm.x121.xhk", + // + // Inputs ... + // + // Market ... + "", + mInputs.xhkSmoothingLength, + mInputs.xhkSmoothingMode, + mInputs.xhkIgnoreSmoothingShadows, + // + // Presentation ... + "", + mInputs.startCalculationForLastBars, + mInputs.drawRawXHKCandles, + mInputs.drawSmoothedXHKCandles + // + ); + result = mHandler != INVALID_HANDLE; + if (!result) + { + return result; + } + + // + return result; + } + + // + // Inputs ... + + // + X121XHKInputs GetInputs() + { + return mInputs; + } + + // + bool SetInputs( + X121XHKInputs &inputs // Configs + ) + { + // + return Init( + mSymbol, + mPeriod, + inputs + // + ); + } + + // + // Readers ... + + // + double GetRawHKOpen( + int barIndex // Bar Index + ) + { + // + if (barIndex < 0) + { + barIndex = 0; + } + + // + Calculate(); + + // + int count = ArraySize(xhkRawOpenBuffer); + if (barIndex >= count) + { + barIndex = count - 1; + } + + // + return xhkRawOpenBuffer[barIndex]; + } + + // + int CopyRawHKOpen( + int start, // Start + int count, // Number of Items for read + double &buffer[], // Dest Buffer + bool forceClean = true // Force To Clean buffer + ) + { + // + // Update Calculations ... + Calculate(); + + // + // Copy Items ... + return Copy( + start, + count, + xhkRawOpenBuffer, + buffer, + forceClean + // + ); + } + + // + double GetRawHKHigh( + int barIndex // Bar Index + ) + { + // + if (barIndex < 0) + { + barIndex = 0; + } + + // + Calculate(); + + // + int count = ArraySize(xhkRawHighBuffer); + if (barIndex >= count) + { + barIndex = count - 1; + } + + // + return xhkRawHighBuffer[barIndex]; + } + + // + int CopyRawHKHigh( + int start, // Start + int count, // Number of Items for read + double &buffer[], // Dest Buffer + bool forceClean = true // Force To Clean buffer + ) + { + // + // Update Calculations ... + Calculate(); + + // + // Copy Items ... + return Copy( + start, + count, + xhkRawHighBuffer, + buffer, + forceClean + // + ); + } + + // + double GetRawHKLow( + int barIndex // Bar Index + ) + { + // + if (barIndex < 0) + { + barIndex = 0; + } + + // + Calculate(); + + // + int count = ArraySize(xhkRawLowBuffer); + if (barIndex >= count) + { + barIndex = count - 1; + } + + // + return xhkRawLowBuffer[barIndex]; + } + + // + int CopyRawHKLow( + int start, // Start + int count, // Number of Items for read + double &buffer[], // Dest Buffer + bool forceClean = true // Force To Clean buffer + ) + { + // + // Update Calculations ... + Calculate(); + + // + // Copy Items ... + return Copy( + start, + count, + xhkRawLowBuffer, + buffer, + forceClean + // + ); + } + + // + double GetRawHKClose( + int barIndex // Bar Index + ) + { + // + if (barIndex < 0) + { + barIndex = 0; + } + + // + Calculate(); + + // + int count = ArraySize(xhkRawCloseBuffer); + if (barIndex >= count) + { + barIndex = count - 1; + } + + // + return xhkRawCloseBuffer[barIndex]; + } + + // + int CopyRawHKClose( + int start, // Start + int count, // Number of Items for read + double &buffer[], // Dest Buffer + bool forceClean = true // Force To Clean buffer + ) + { + // + // Update Calculations ... + Calculate(); + + // + // Copy Items ... + return Copy( + start, + count, + xhkRawCloseBuffer, + buffer, + forceClean + // + ); + } + + // + double GetSMHKOpen( + int barIndex // Bar Index + ) + { + // + if (barIndex < 0) + { + barIndex = 0; + } + + // + Calculate(); + + // + int count = ArraySize(xhkSMOpenBuffer); + if (barIndex >= count) + { + barIndex = count - 1; + } + + // + return xhkSMOpenBuffer[barIndex]; + } + + // + int CopySMHKOpen( + int start, // Start + int count, // Number of Items for read + double &buffer[], // Dest Buffer + bool forceClean = true // Force To Clean buffer + ) + { + // + // Update Calculations ... + Calculate(); + + // + // Copy Items ... + return Copy( + start, + count, + xhkSMOpenBuffer, + buffer, + forceClean + // + ); + } + + // + double GetSMHKHigh( + int barIndex // Bar Index + ) + { + // + if (barIndex < 0) + { + barIndex = 0; + } + + // + Calculate(); + + // + int count = ArraySize(xhkSMHighBuffer); + if (barIndex >= count) + { + barIndex = count - 1; + } + + // + return xhkSMHighBuffer[barIndex]; + } + + // + int CopySMHKHigh( + int start, // Start + int count, // Number of Items for read + double &buffer[], // Dest Buffer + bool forceClean = true // Force To Clean buffer + ) + { + // + // Update Calculations ... + Calculate(); + + // + // Copy Items ... + return Copy( + start, + count, + xhkSMHighBuffer, + buffer, + forceClean + // + ); + } + + // + double GetSMHKLow( + int barIndex // Bar Index + ) + { + // + if (barIndex < 0) + { + barIndex = 0; + } + + // + Calculate(); + + // + int count = ArraySize(xhkSMLowBuffer); + if (barIndex >= count) + { + barIndex = count - 1; + } + + // + return xhkSMLowBuffer[barIndex]; + } + + // + int CopySMHKLow( + int start, // Start + int count, // Number of Items for read + double &buffer[], // Dest Buffer + bool forceClean = true // Force To Clean buffer + ) + { + // + // Update Calculations ... + Calculate(); + + // + // Copy Items ... + return Copy( + start, + count, + xhkSMLowBuffer, + buffer, + forceClean + // + ); + } + + // + double GetSMHKClose( + int barIndex // Bar Index + ) + { + // + if (barIndex < 0) + { + barIndex = 0; + } + + // + Calculate(); + + // + int count = ArraySize(xhkSMCloseBuffer); + if (barIndex >= count) + { + barIndex = count - 1; + } + + // + return xhkSMCloseBuffer[barIndex]; + } + + // + int CopySMHKClose( + int start, // Start + int count, // Number of Items for read + double &buffer[], // Dest Buffer + bool forceClean = true // Force To Clean buffer + ) + { + // + // Update Calculations ... + Calculate(); + + // + // Copy Items ... + return Copy( + start, + count, + xhkSMCloseBuffer, + buffer, + forceClean + // + ); + } + + // + bool GetRawHKAsXOHCL( + int barIndex, // Bar Index + XOHCL &bar // Bar Result + ) + { + // + bool result = false; + + // + bar.Clean(); + + // + if (barIndex < 0) + { + barIndex = 0; + } + + // + result = bar.Init( + GetSymbol(), + GetPeriod(), + barIndex // + ); + if (!result) + { + return result; + } + + // + bar.open = xhkRawOpenBuffer[barIndex]; + bar.high = xhkRawHighBuffer[barIndex]; + bar.low = xhkRawLowBuffer[barIndex]; + bar.close = xhkRawCloseBuffer[barIndex]; + + // + return result; + } + + // + bool GetSMHKAsXOHCL( + int barIndex, // Bar Index + XOHCL &bar // Bar Result + ) + { + // + bool result = false; + + // + bar.Clean(); + + // + if (barIndex < 0) + { + barIndex = 0; + } + + // + result = bar.Init( + GetSymbol(), + GetPeriod(), + barIndex // + ); + if (!result) + { + return result; + } + + // + bar.open = xhkSMOpenBuffer[barIndex]; + bar.high = xhkSMHighBuffer[barIndex]; + bar.low = xhkSMLowBuffer[barIndex]; + bar.close = xhkSMCloseBuffer[barIndex]; + + // + return result; + } + + // + bool GetConditions( + X121XHKConditions &conditions, // + int barIndex = 0, // + int loopback = 5 // + ) + { + // + bool result = true; + + // + if (loopback < 5) + { + loopback = 5; + } + + // + conditions.Clean(); + + // + conditions.symbol = mSymbol; + conditions.period = mPeriod; + conditions.time = TimeCurrent(); + + // + int zIndex = barIndex; + int cIndex = zIndex + 1; + int pIndex = cIndex + 1; + int ppIndex = pIndex + 1; + + // + XOHCL zBar; + result = zBar.Init( + mSymbol, + mPeriod, + zIndex // + ); + if (!result) + { + return result; + } + + // + XOHCL cBar; + result = cBar.Init( + mSymbol, + mPeriod, + cIndex // + ); + if (!result) + { + return result; + } + + // + XOHCL pBar; + result = pBar.Init( + mSymbol, + mPeriod, + pIndex // + ); + if (!result) + { + return result; + } + + // + // Buffers ... + + // + CopyRawHKOpen( + zIndex, + loopback, + conditions.xhkRawOpenBuffer // + ); + + // + CopyRawHKHigh( + zIndex, + loopback, + conditions.xhkRawHighBuffer // + ); + + // + CopyRawHKLow( + zIndex, + loopback, + conditions.xhkRawLowBuffer // + ); + + // + CopyRawHKClose( + zIndex, + loopback, + conditions.xhkRawCloseBuffer // + ); + + // + CopySMHKOpen( + zIndex, + loopback, + conditions.xhkSMOpenBuffer // + ); + + // + CopySMHKHigh( + zIndex, + loopback, + conditions.xhkSMHighBuffer // + ); + + // + CopySMHKLow( + zIndex, + loopback, + conditions.xhkSMLowBuffer // + ); + + // + CopySMHKClose( + zIndex, + loopback, + conditions.xhkSMCloseBuffer // + ); + + // + // Conditions ... + + // + int cIDX = 1; + int pIDX = cIDX + 1; + + // + double smHKLow = conditions.xhkSMLowBuffer[cIDX]; + double smHKHigh = conditions.xhkSMHighBuffer[cIDX]; + double smHKOpen = conditions.xhkSMOpenBuffer[cIDX]; + double smHKClose = conditions.xhkSMCloseBuffer[cIDX]; + + // + double smHKLowPrev = conditions.xhkSMLowBuffer[pIDX]; + double smHKHighPrev = conditions.xhkSMHighBuffer[pIDX]; + double smHKOpenPrev = conditions.xhkSMOpenBuffer[pIDX]; + double smHKClosePrev = conditions.xhkSMCloseBuffer[pIDX]; + + // + double rawHKLow = conditions.xhkRawLowBuffer[cIDX]; + double rawHKHigh = conditions.xhkRawHighBuffer[cIDX]; + double rawHKOpen = conditions.xhkRawOpenBuffer[cIDX]; + double rawHKClose = conditions.xhkRawCloseBuffer[cIDX]; + + // + double rawHKLowPrev = conditions.xhkRawLowBuffer[pIDX]; + double rawHKHighPrev = conditions.xhkRawHighBuffer[pIDX]; + double rawHKOpenPrev = conditions.xhkRawOpenBuffer[pIDX]; + double rawHKClosePrev = conditions.xhkRawCloseBuffer[pIDX]; + + // + double smHKUp = MathMax(smHKOpen, smHKClose); + double smHKUpPrev = MathMax(smHKOpenPrev, smHKClosePrev); + + // + double smHKDown = MathMin(smHKOpen, smHKClose); + double smHKDownPrev = MathMin(smHKOpenPrev, smHKClosePrev); + + // + double rawHKUp = MathMax(rawHKOpen, rawHKClose); + double rawHKUpPrev = MathMax(rawHKOpenPrev, rawHKClosePrev); + + // + double rawHKDown = MathMin(rawHKOpen, rawHKClose); + double rawHKDownPrev = MathMin(rawHKOpenPrev, rawHKClosePrev); + + // + XOHCL rawHKCBar; + bool hasRawHKBar = GetRawHKAsXOHCL( + cIndex, + rawHKCBar // + ); + + // + // + // + + // + bool isSMHKBullish = smHKOpen < smHKClose; + bool isSMHKBullishPrev = smHKOpenPrev < smHKClosePrev; + + // + bool isRawHKBullish = rawHKOpen < rawHKClose; + bool isRawHKBullishPrev = rawHKOpenPrev < rawHKClosePrev; + + // + bool isSMHKSwitchedToBullish = isSMHKBullish && + !isSMHKBullishPrev; + bool isRawHKSwitchedToBullish = isRawHKBullish && + !isRawHKBullishPrev; + + // + bool isSMHKBearish = smHKOpen > smHKClose; + bool isSMHKBearishPrev = smHKOpenPrev > smHKClosePrev; + + // + bool isRawHKBearish = rawHKOpen > rawHKClose; + bool isRawHKBearishPrev = rawHKOpenPrev > rawHKClosePrev; + + // + bool isSMHKSwitchedBearish = isSMHKBearish && + !isSMHKBearishPrev; + bool isRawHKSwitchedBearish = isRawHKBearish && + !isRawHKBearishPrev; + + // + bool isClosedOverSMHK = cBar.close > smHKUp; + bool isClosedUnderSMHK = cBar.close < smHKDown; + + // + bool isClosedOverRawHK = cBar.close > rawHKUp; + bool isClosedUnderRawHK = cBar.close < rawHKDown; + + // + bool isRawHKClosedOverSMHK = rawHKClose > smHKUp; + bool isRawHKClosedUnderSMHK = rawHKClose < smHKDown; + + // + bool isBreakedUpSMHK = IsBarBreak( + smHKUp, + X_DIRECTION_BULLISH, + cBar // + ); + bool isBreakedUpRawHK = IsBarBreak( + rawHKUp, + X_DIRECTION_BULLISH, + cBar // + ); + bool isRejectedUpSMHK = IsBarReject( + smHKUp, + X_DIRECTION_BULLISH, + cBar // + ); + bool isRejectedUpRawHK = IsBarReject( + rawHKUp, + X_DIRECTION_BULLISH, + cBar // + ); + + // + bool isRawHKBreakedUpSMHK = + hasRawHKBar && + IsBarBreak( + smHKUp, + X_DIRECTION_BULLISH, + rawHKCBar // + ); + + // + bool isBreakedDownSMHK = IsBarBreak( + smHKDown, + X_DIRECTION_BEARISH, + cBar // + ); + bool isBreakedDownRawHK = IsBarBreak( + rawHKDown, + X_DIRECTION_BEARISH, + cBar // + ); + bool isRejectedDownSMHK = IsBarReject( + smHKDown, + X_DIRECTION_BEARISH, + cBar // + ); + bool isRejectedDownRawHK = IsBarReject( + rawHKDown, + X_DIRECTION_BEARISH, + cBar // + ); + + // + bool isRawHKBreakedDownSMHK = + hasRawHKBar && + IsBarBreak( + smHKDown, + X_DIRECTION_BEARISH, + rawHKCBar // + ); + + // + conditions.isSMHKBullish = isSMHKBullish; + conditions.isRawHKBullish = isRawHKBullish; + conditions.isSMHKSwitchedToBullish = isSMHKSwitchedToBullish; + conditions.isRawHKSwitchedToBullish = isRawHKSwitchedToBullish; + conditions.isSMHKBearish = isSMHKBearish; + conditions.isRawHKBearish = isRawHKBearish; + conditions.isSMHKSwitchedBearish = isSMHKSwitchedBearish; + conditions.isRawHKSwitchedBearish = isRawHKSwitchedBearish; + conditions.isClosedOverSMHK = isClosedOverSMHK; + conditions.isClosedUnderSMHK = isClosedUnderSMHK; + conditions.isClosedOverRawHK = isClosedOverRawHK; + conditions.isClosedUnderRawHK = isClosedUnderRawHK; + conditions.isRawHKClosedOverSMHK = isRawHKClosedOverSMHK; + conditions.isRawHKClosedUnderSMHK = isRawHKClosedUnderSMHK; + conditions.isBreakedUpSMHK = isBreakedUpSMHK; + conditions.isBreakedUpRawHK = isBreakedUpRawHK; + conditions.isRejectedUpSMHK = isRejectedUpSMHK; + conditions.isRejectedUpRawHK = isRejectedUpRawHK; + conditions.isRawHKBreakedUpSMHK = isRawHKBreakedUpSMHK; + conditions.isBreakedDownSMHK = isBreakedDownSMHK; + conditions.isBreakedDownRawHK = isBreakedDownRawHK; + conditions.isRejectedDownSMHK = isRejectedDownSMHK; + conditions.isRejectedDownRawHK = isRejectedDownRawHK; + conditions.isRawHKBreakedDownSMHK = isRawHKBreakedDownSMHK; + + // + return result; + } + + // + // Protected ... + protected: + // + // Private ... + private: + // + // Props ... + X121XHKInputs mInputs; // Inputs ... + + // + // Buffers ... + double xhkRawOpenBuffer[]; + double xhkRawHighBuffer[]; + double xhkRawLowBuffer[]; + double xhkRawCloseBuffer[]; + double xhkSMOpenBuffer[]; + double xhkSMHighBuffer[]; + double xhkSMLowBuffer[]; + double xhkSMCloseBuffer[]; + + // + void Calculate() + { + // + int totalBars = CountBars(); + if (totalBars > 1000) + { + totalBars = 1000; + } + + // + // Buffers ... + + // + // RAW Open ... + CopyBuffer( + mHandler, + X121_XHK_RAW_OPEN_LINE, + 0, + totalBars, + xhkRawOpenBuffer + // + ); + + // + // RAW High ... + CopyBuffer( + mHandler, + X121_XHK_RAW_HIGH_LINE, + 0, + totalBars, + xhkRawHighBuffer + // + ); + + // + // RAW Low ... + CopyBuffer( + mHandler, + X121_XHK_RAW_LOW_LINE, + 0, + totalBars, + xhkRawLowBuffer + // + ); + + // + // RAW Close ... + CopyBuffer( + mHandler, + X121_XHK_RAW_CLOSE_LINE, + 0, + totalBars, + xhkRawCloseBuffer + // + ); + + // + // SM Open ... + CopyBuffer( + mHandler, + X121_XHK_SM_OPEN_LINE, + 0, + totalBars, + xhkSMOpenBuffer + // + ); + + // + // SM High ... + CopyBuffer( + mHandler, + X121_XHK_SM_HIGH_LINE, + 0, + totalBars, + xhkSMHighBuffer + // + ); + + // + // SM Low ... + CopyBuffer( + mHandler, + X121_XHK_SM_LOW_LINE, + 0, + totalBars, + xhkSMLowBuffer + // + ); + + // + // SM Close ... + CopyBuffer( + mHandler, + X121_XHK_SM_CLOSE_LINE, + 0, + totalBars, + xhkSMCloseBuffer + // + ); + } +}; + +// +// Tools ... \ No newline at end of file diff --git a/Indicators/x-saherelm.x121.xhk.mq5 b/Indicators/x-saherelm.x121.xhk.mq5 index 57c5efaf..c6a7cfe5 100644 --- a/Indicators/x-saherelm.x121.xhk.mq5 +++ b/Indicators/x-saherelm.x121.xhk.mq5 @@ -35,19 +35,9 @@ // // Market ... input group "Market"; - -// -input group "RSI Detection"; -input int rsiLength = 14; // Length -input ENUM_APPLIED_PRICE rsiAppliedTo = PRICE_CLOSE; // Applied To - -// -input group "ATR Detection"; -input int atrLength = 14; // Length -input double atrMultiplier = 1; // Multiplier -input ENUM_APPLIED_PRICE atrUpperAppliedTo = PRICE_HIGH; // Upper Zone Applied To -input ENUM_APPLIED_PRICE atrLowerAppliedTo = PRICE_LOW; // Lower Zone Applied To -input ENUM_X_MA_METHOD atrSmoothingMode = X_MA_MODE_EMA; // Smoothing Method +input int xhkSmoothingLength = 14; // Length +input ENUM_X_MA_METHOD xhkSmoothingMode = X_MA_MODE_EMA; // Smoothing Method +input bool xhkIgnoreSmoothingShadows = false; // Ignore Smoothed Bar Shadows // input group "Presentation"; @@ -56,12 +46,19 @@ input group "Presentation"; input int startCalculationForLastBars = 1000; // Calculate Last n Bars // -input bool showAtrUpper = true; // Show Upper Zone -input bool showAtrLower = true; // Show Lower Zone +input bool drawRawXHKCandles = true; // Draw Raw Candle +input bool drawSmoothedXHKCandles = true; // Draw Smoothed Candle // // Buffers ... +// +#property indicator_chart_window + +// +#property indicator_buffers 10 +#property indicator_plots 2 + // #define hideColorIDX 0 #define bullishColorIDX 1 @@ -69,63 +66,64 @@ input bool showAtrLower = true; // Show Lower Zone #define neuturalColorIDX 3 // -#property indicator_chart_window +// PLOTTED Buffers ... // -#property indicator_buffers 6 -#property indicator_plots 2 +#define openHKBufferIndex 0 +double openHKBuffer[]; // -// ATR ... +#define highHKBufferIndex 1 +double highHKBuffer[]; // -// Upper ... +#define lowHKBufferIndex 2 +double lowHKBuffer[]; // -#define atrUpperBufferIndex 0 -double atrUpperBuffer[]; - -#property indicator_label1 "X121 ATRU" -#property indicator_type1 DRAW_LINE -#property indicator_color1 clrYellow -#property indicator_style1 STYLE_SOLID -#property indicator_width1 2 +#define closeHKBufferIndex 3 +double closeHKBuffer[]; // -// Lower ... +#define rawHKColorBufferIndex 4 +double rawHKColorBuffer[]; // -#define atrLowerBufferIndex 1 -double atrLowerBuffer[]; - -#property indicator_label2 "X121 ATRL" -#property indicator_type2 DRAW_LINE -#property indicator_color2 clrYellow -#property indicator_style2 STYLE_SOLID -#property indicator_width2 2 +#define rawHKBufferIndex 0 +#property indicator_label1 "X121 XHK Open;X121 XHK High;X121 XHK Low;X121 XHK Close" +#property indicator_type1 DRAW_COLOR_CANDLES +#property indicator_color1 CLR_NONE, clrDodgerBlue, clrDarkGoldenrod // -// Data Buffers ... +// Open ... +#define openBufferIndex 5 +double openBuffer[]; // -int mLastBufferIndex = 1; +// High ... +#define highBufferIndex 6 +double highBuffer[]; // -// ATR ... - -#define atrBufferIndex mLastBufferIndex + 1 -double atrBuffer[]; - -#define atrUpperRawBufferIndex mLastBufferIndex + 2 -double atrUpperRawBuffer[]; - -#define atrLowerRawBufferIndex mLastBufferIndex + 3 -double atrLowerRawBuffer[]; +// Low ... +#define lowBufferIndex 7 +double lowBuffer[]; // -// RSI ... -#define rsiBufferIndex mLastBufferIndex + 4 -double rsiBuffer[]; +// Close ... +#define closeBufferIndex 8 +double closeBuffer[]; + +// +// Candle Color ... +#define candleColorBufferIndex 9 +double candleColorBuffer[]; + +// +#define candlesBufferIndex 1 +#property indicator_label2 "X121 XHKSM Open;X121 XHKSM High;X121 XHKSM Low;X121 XHKSM Close" +#property indicator_type2 DRAW_COLOR_CANDLES +#property indicator_color2 CLR_NONE, clrAqua, clrMagenta // // Variables, Properties and etc ... @@ -138,17 +136,6 @@ int limit; int maxLength; // -// RSI Handler ... -int rsiHandler = INVALID_HANDLE; - -// -// ATR Handler ... -int atrHandler = INVALID_HANDLE; - -// -bool isStrTrendChanged; -bool isStrStartBearishTrend; -bool isStrStartBullishTrend; // // Event Handlers ... @@ -170,33 +157,6 @@ int OnInit() // // Initialize Indicator Handlers ... - // - // RSI ... - rsiHandler = iRSI( - _Symbol, - _Period, - rsiLength, - rsiAppliedTo // - ); - bool isInited = rsiHandler != INVALID_HANDLE; - if (!isInited) - { - return INIT_FAILED; - } - - // - // ATR ... - atrHandler = iATR( - _Symbol, - _Period, - atrLength // - ); - isInited = atrHandler != INVALID_HANDLE; - if (!isInited) - { - return INIT_FAILED; - } - // // because in some cases we may have more than one input for // calculation and we must prevent any calculation @@ -237,8 +197,6 @@ void OnDeinit(const int reason) // REASON_CLOSE 9 Terminal closed // - IndicatorRelease(rsiHandler); - IndicatorRelease(atrHandler); } /** @@ -287,65 +245,11 @@ int OnCalculate( { } - // - // Validate Calculated Bars ... - - // - // RSI ... - int rsiCalculatedBars = BarsCalculated(rsiHandler); - - // - // ATR ... - int atrCalculatedBars = BarsCalculated(atrHandler); - - // - bool isPassedRequiredCalculatedBars = - // - // RSI ... - rsiCalculatedBars >= maxLength && - // - // ATR ... - atrCalculatedBars >= maxLength - // - ; - if (!isPassedRequiredCalculatedBars) - { - return prev_calculated; - } - // limit = (prev_calculated > rates_total || prev_calculated <= 0) ? rates_total : (rates_total - prev_calculated) + 1; - // - // Buffers Copy ... - - // - // RSI ... - int copiedRsis = CopyBuffer(rsiHandler, 0, 0, limit, rsiBuffer); - - // - // ATR ... - int copiedAtrs = CopyBuffer(atrHandler, 0, 0, limit, atrBuffer); - - // - // Validate Copied Items ... - bool isPassedRequiredCopiedItems = - // - // - // RSI ... - copiedRsis > 0 && - // - // ATR ... - copiedAtrs > 0 - // - ; - if (!isPassedRequiredCopiedItems) - { - return prev_calculated; - } - // // Main Loop ... for (int i = limit - 1; i >= 0 && !IsStopped(); i--) @@ -381,12 +285,7 @@ bool ValidateInputs() // bool result = // - // RSI ... - rsiLength > 0 && - // - // ATR ... - atrLength > 0 && - atrMultiplier > 0 + true // ; @@ -405,7 +304,7 @@ int ExtractMaxLengthOfInputs() int result = 0; // - result = MathMax(rsiLength, atrLength); + result = MathMax(0, xhkSmoothingLength); // return result; @@ -416,53 +315,72 @@ int ExtractMaxLengthOfInputs() */ void DefineBuffers() { - // - // ATR ... // - // UPPER ... - bool canShowAtrUpper = showAtrUpper; - ENUM_DRAW_TYPE atrUpperDrawType = canShowAtrUpper ? DRAW_LINE : DRAW_NONE; - ArraySetAsSeries(atrUpperBuffer, true); - SetIndexBuffer(atrUpperBufferIndex, atrUpperBuffer, INDICATOR_DATA); - PlotIndexSetDouble(atrUpperBufferIndex, PLOT_EMPTY_VALUE, EMPTY_VALUE); - PlotIndexSetInteger(atrUpperBufferIndex, PLOT_SHOW_DATA, canShowAtrUpper); - PlotIndexSetInteger(atrUpperBufferIndex, PLOT_DRAW_TYPE, atrUpperDrawType); + // RAW ... // - // LOWER ... - bool canShowAtrLower = showAtrLower; - ENUM_DRAW_TYPE atrLowerDrawType = canShowAtrLower ? DRAW_LINE : DRAW_NONE; - ArraySetAsSeries(atrLowerBuffer, true); - SetIndexBuffer(atrLowerBufferIndex, atrLowerBuffer, INDICATOR_DATA); - PlotIndexSetDouble(atrLowerBufferIndex, PLOT_EMPTY_VALUE, EMPTY_VALUE); - PlotIndexSetInteger(atrLowerBufferIndex, PLOT_SHOW_DATA, canShowAtrLower); - PlotIndexSetInteger(atrLowerBufferIndex, PLOT_DRAW_TYPE, atrLowerDrawType); + // Raw Candles Color ... + ArraySetAsSeries(rawHKColorBuffer, true); + SetIndexBuffer(rawHKColorBufferIndex, rawHKColorBuffer, INDICATOR_COLOR_INDEX); // - // Data Buffers ... + // Set EMPTY_VALUE on Candles Buffer ... + PlotIndexSetDouble(rawHKBufferIndex, PLOT_EMPTY_VALUE, 0.0); + PlotIndexSetInteger(rawHKBufferIndex, PLOT_SHOW_DATA, false); // - // ATR ... + // Open ... + ArraySetAsSeries(openHKBuffer, true); + SetIndexBuffer(openHKBufferIndex, openHKBuffer, INDICATOR_DATA); // - ArraySetAsSeries(atrBuffer, true); - SetIndexBuffer(atrBufferIndex, atrBuffer, INDICATOR_CALCULATIONS); + // High ... + ArraySetAsSeries(highHKBuffer, true); + SetIndexBuffer(highHKBufferIndex, highHKBuffer, INDICATOR_DATA); // - ArraySetAsSeries(atrUpperRawBuffer, true); - SetIndexBuffer(atrUpperRawBufferIndex, atrUpperRawBuffer, INDICATOR_CALCULATIONS); + // Close ... + ArraySetAsSeries(closeHKBuffer, true); + SetIndexBuffer(closeHKBufferIndex, closeHKBuffer, INDICATOR_DATA); // - ArraySetAsSeries(atrLowerRawBuffer, true); - SetIndexBuffer(atrLowerRawBufferIndex, atrLowerRawBuffer, INDICATOR_CALCULATIONS); + // Low ... + ArraySetAsSeries(lowHKBuffer, true); + SetIndexBuffer(lowHKBufferIndex, lowHKBuffer, INDICATOR_DATA); // - // RSI ... + // SMOOTHED ... // - ArraySetAsSeries(rsiBuffer, true); - SetIndexBuffer(rsiBufferIndex, rsiBuffer, INDICATOR_CALCULATIONS); + // Candles Color ... + ArraySetAsSeries(candleColorBuffer, true); + SetIndexBuffer(candleColorBufferIndex, candleColorBuffer, INDICATOR_COLOR_INDEX); + + // + // Set EMPTY_VALUE on Candles Buffer ... + PlotIndexSetDouble(candlesBufferIndex, PLOT_EMPTY_VALUE, 0.0); + PlotIndexSetInteger(candlesBufferIndex, PLOT_SHOW_DATA, false); + + // + // Open ... + ArraySetAsSeries(openBuffer, true); + SetIndexBuffer(openBufferIndex, openBuffer, INDICATOR_DATA); + + // + // High ... + ArraySetAsSeries(highBuffer, true); + SetIndexBuffer(highBufferIndex, highBuffer, INDICATOR_DATA); + + // + // Close ... + ArraySetAsSeries(closeBuffer, true); + SetIndexBuffer(closeBufferIndex, closeBuffer, INDICATOR_DATA); + + // + // Low ... + ArraySetAsSeries(lowBuffer, true); + SetIndexBuffer(lowBufferIndex, lowBuffer, INDICATOR_DATA); } /** @@ -501,14 +419,13 @@ void CalculateBuffers( ? startCalculationForLastBars : 0; // - // bool canCalculate = true; bool canCalculate = barsLimit == 0 || bar_index <= barsLimit; if (canCalculate) { // - CalculateAtrZones( + CalculateXHK( bar_index, prevCalculated, ratesTotal, @@ -535,16 +452,18 @@ void CalculateBuffers( void FillBuffersZero(int barIndex) { // - // RSIS ... - rsiBuffer[barIndex] = 0; + lowHKBuffer[barIndex] = 0.0; + openHKBuffer[barIndex] = 0.0; + highHKBuffer[barIndex] = 0.0; + closeHKBuffer[barIndex] = 0.0; + rawHKColorBuffer[barIndex] = hideColorIDX; // - // ATRS ... - atrBuffer[barIndex] = 0; - atrUpperBuffer[barIndex] = 0; - atrUpperRawBuffer[barIndex] = 0; - atrUpperBuffer[barIndex] = 0; - atrLowerRawBuffer[barIndex] = 0; + lowBuffer[barIndex] = 0.0; + openBuffer[barIndex] = 0.0; + highBuffer[barIndex] = 0.0; + closeBuffer[barIndex] = 0.0; + candleColorBuffer[barIndex] = hideColorIDX; } /** @@ -558,7 +477,7 @@ void FillBuffersZero(int barIndex) * @param close: Double Array, History of Close Prices ... * @param low: Double Array, History of Low Prices ... */ -void CalculateAtrZones( +void CalculateXHK( int bar_index, // Selected Bar Index const int prevCalculated, const int ratesTotal, @@ -569,79 +488,128 @@ void CalculateAtrZones( ) { // - // Select ATr Value ... - double atrValue = atrBuffer[bar_index]; - double appliedAtrMultiplierValue = atrValue * atrMultiplier; + double mPrevHKOpenValue; + double mPrevHKCloseValue; // - // Select Upper Price ... - double upperPrice = GetAppliedPrice( - atrUpperAppliedTo, - open, - high, - low, - close, - bar_index // - ); - - // - // Select Lower Price ... - double lowerPrice = GetAppliedPrice( - atrLowerAppliedTo, - open, - high, - low, - close, - bar_index // - ); - - // - // Calculate Raw Atrs ... - - // - // Upper ... - double atrUpperRawValue = upperPrice + appliedAtrMultiplierValue; - atrUpperRawBuffer[bar_index] = atrUpperRawValue; - - // - // Lower ... - double atrLowerRawValue = lowerPrice - appliedAtrMultiplierValue; - atrLowerRawBuffer[bar_index] = atrLowerRawValue; - - // - bool canSmooth = atrSmoothingMode != X_MA_MODE_NONE; - if (canSmooth) + if (ArraySize(open) <= bar_index + 1) { // - // Upper ... - iMAOnBuffer( - ratesTotal, - prevCalculated, - bar_index, - atrLength, - atrUpperRawBuffer, - atrUpperBuffer, - atrSmoothingMode // - ); - - // - // Lower ... - iMAOnBuffer( - ratesTotal, - prevCalculated, - bar_index, - atrLength, - atrLowerRawBuffer, - atrLowerBuffer, - atrSmoothingMode // - ); + mPrevHKOpenValue = 0; + mPrevHKCloseValue = 0; } else { // - // Use Raw Values ... - atrUpperBuffer[bar_index] = atrUpperRawValue; - atrLowerBuffer[bar_index] = atrLowerRawValue; + mPrevHKOpenValue = openHKBuffer[bar_index + 1]; + mPrevHKCloseValue = closeHKBuffer[bar_index + 1]; + } + + // + double mHKOpenValue = (mPrevHKOpenValue + mPrevHKCloseValue) / 2; + double mHKCloseValue = (open[bar_index] + high[bar_index] + close[bar_index] + low[bar_index]) / 4; + double mHKHighValue = MathMax(high[bar_index], MathMax(mHKOpenValue, mHKCloseValue)); + double mHKLowValue = MathMin(low[bar_index], MathMin(mHKOpenValue, mHKCloseValue)); + + // + double candleColorValue = + mHKOpenValue < mHKCloseValue ? bullishColorIDX : bearishColorIDX; + + // + // Raw HK Buffers ... + openHKBuffer[bar_index] = mHKOpenValue; + highHKBuffer[bar_index] = mHKHighValue; + lowHKBuffer[bar_index] = mHKLowValue; + closeHKBuffer[bar_index] = mHKCloseValue; + rawHKColorBuffer[bar_index] = drawRawXHKCandles ? candleColorValue : hideColorIDX; + + // + // Apply Smoothing ... + bool canSmooth = xhkSmoothingLength > 0 && + xhkSmoothingMode != X_MA_MODE_NONE; + if (!canSmooth) + { + // + double min = MathMin(mHKOpenValue, mHKCloseValue); + double max = MathMax(mHKOpenValue, mHKCloseValue); + + // + openBuffer[bar_index] = mHKOpenValue; + highBuffer[bar_index] = xhkIgnoreSmoothingShadows ? max : mHKHighValue; + lowBuffer[bar_index] = xhkIgnoreSmoothingShadows ? min : mHKLowValue; + closeBuffer[bar_index] = mHKCloseValue; + candleColorBuffer[bar_index] = drawSmoothedXHKCandles ? candleColorValue : hideColorIDX; + } + else + { + // + // Open ... + iMAOnBuffer( + ratesTotal, + prevCalculated, + bar_index, + xhkSmoothingLength, + openHKBuffer, + openBuffer, + xhkSmoothingMode // + ); + + // + // Close ... + iMAOnBuffer( + ratesTotal, + prevCalculated, + bar_index, + xhkSmoothingLength, + closeHKBuffer, + closeBuffer, + xhkSmoothingMode // + ); + + // + // Ignoring Shadows ... + if (!xhkIgnoreSmoothingShadows) + { + // + // High ... + iMAOnBuffer( + ratesTotal, + prevCalculated, + bar_index, + xhkSmoothingLength, + highHKBuffer, + highBuffer, + xhkSmoothingMode // + ); + + // + // Low ... + iMAOnBuffer( + ratesTotal, + prevCalculated, + bar_index, + xhkSmoothingLength, + lowHKBuffer, + lowBuffer, + xhkSmoothingMode // + ); + } + else + { + // + double min = MathMin(closeBuffer[bar_index], openBuffer[bar_index]); + double max = MathMin(closeBuffer[bar_index], openBuffer[bar_index]); + + // + lowBuffer[bar_index] = min; + highBuffer[bar_index] = max; + } + + // + // Calculate Smoothed Color ... + candleColorValue = + openBuffer[bar_index] < closeBuffer[bar_index] ? bullishColorIDX : bearishColorIDX; + candleColorBuffer[bar_index] = drawSmoothedXHKCandles ? candleColorValue : hideColorIDX; } } diff --git a/X121SMCEA/Signals/x-121.smc.x.signal.lib.mq5 b/X121SMCEA/Signals/x-121.smc.x.signal.lib.mq5 index acf3972a..8d9578f3 100644 --- a/X121SMCEA/Signals/x-121.smc.x.signal.lib.mq5 +++ b/X121SMCEA/Signals/x-121.smc.x.signal.lib.mq5 @@ -24,6 +24,7 @@ // #include "../../Libraries/x-trade.lib" #include "../Classes/x-121.smc.market.cycle.helper.class.mq5" #include "../Libraries/x-121.smc.lib.mq5" +#include "../Libraries/x-121.smc.guard.lib.mq5" // // Definitions ...