diff --git a/Indicators/x-saherelm.x121.xcatb.v1.mq5 b/Indicators/x-saherelm.x121.xcatb.v1.mq5 index 928fae96..1b2db274 100644 --- a/Indicators/x-saherelm.x121.xcatb.v1.mq5 +++ b/Indicators/x-saherelm.x121.xcatb.v1.mq5 @@ -651,7 +651,7 @@ double mSameValeGolden = 0; // bool mDrawLiquidities = false; -bool mDrawRangeBreakes = false; +bool mDrawRangeBreakes = true; // bool mDetectLiquidities = true; @@ -2020,7 +2020,7 @@ void CalculateValues( /** * Calculate Cycle Ranges Values ... - * + * * @param barIndex: int, Specified Bar Index ... * @param prevCalculated: int, Provides Previous Calculated Bars ... * @param ratesTotal: int, Provides All Availabled Bars ... @@ -2080,7 +2080,7 @@ void CalculateCycleRanges( /** * Calculate KI Values ... - * + * * @param barIndex: int, Specified Bar Index ... * @param prevCalculated: int, Provides Previous Calculated Bars ... * @param ratesTotal: int, Provides All Availabled Bars ... @@ -2175,7 +2175,7 @@ void CalculateKI( /** * Calculate Peaks and Vales Values ... - * + * * @param barIndex: int, Specified Bar Index ... * @param prevCalculated: int, Provides Previous Calculated Bars ... * @param ratesTotal: int, Provides All Availabled Bars ... @@ -2304,7 +2304,7 @@ void CalculatePV( /** * Calculate PSar Values ... - * + * * @param barIndex: int, Specified Bar Index ... * @param prevCalculated: int, Provides Previous Calculated Bars ... * @param ratesTotal: int, Provides All Availabled Bars ... @@ -2353,7 +2353,7 @@ void CalculateSAR( /** * Calculate Signal Bar Values ... - * + * * @param barIndex: int, Specified Bar Index ... * @param prevCalculated: int, Provides Previous Calculated Bars ... * @param ratesTotal: int, Provides All Availabled Bars ... @@ -2933,7 +2933,7 @@ void HideBars() // // POI(s) Handlers ... -// +// /** * Detect POI(s) ... @@ -3663,6 +3663,9 @@ void DoProcess( // Detecting Trigger Bar ... // + bool hasSignal = false; + bool isBullish = false; + bool isBearish = false; string namePrefix = NULL; int triggerBarPushers = 0; ENUM_X_DIRECTION triggerDir; @@ -3898,206 +3901,209 @@ void DoProcess( ; // - // Validating Trigger Bar ... + // Reading Required Condiions ... + + // + // HK Signal Bar ... + + // + double iHKSOpen = hkSBarOpenBuffer[barIndex]; + double iHKSClose = hkSBarCloseBuffer[barIndex]; + + // + double iHKSMax = MathMax(iHKSOpen, iHKSClose); + double iHKSMin = MathMin(iHKSOpen, iHKSClose); + + // + bool isHKSBullish = hkSBarOpenBuffer[barIndex] < hkSBarCloseBuffer[barIndex]; + bool isPHKSBullish = hkSBarOpenBuffer[barIndex + 1] < hkSBarCloseBuffer[barIndex + 1]; + + // + bool isHKSBearish = hkSBarOpenBuffer[barIndex] > hkSBarCloseBuffer[barIndex]; + bool isPHKSBearish = hkSBarOpenBuffer[barIndex + 1] > hkSBarCloseBuffer[barIndex + 1]; + + // + bool isHKSSwitchedToBullish = + isHKSBullish && + !isPHKSBullish; + + // + bool isHKSSwitchedToBearish = + isHKSBearish && + !isPHKSBearish; + + // + // TREND ... + + // + double iTrend = trendBuffer[barIndex]; + bool isTrendBullish = trendStateBuffer[barIndex] > 0; + bool isTrendBearish = trendStateBuffer[barIndex] < 0; + bool isTrendSwitchedToBullish = + trendStateBuffer[barIndex] > 0 && + trendStateBuffer[barIndex + 1] <= 0; + bool isTrendSwitchedToBearish = + trendStateBuffer[barIndex] < 0 && + trendStateBuffer[barIndex + 1] >= 0; + + // + // RSI ... + + // + bool isRSIOverOB = rsiBuffer[barIndex] > rsiOBLevel; + bool isPRSIOverOB = rsiBuffer[barIndex + 1] > rsiOBLevel; + + // + bool isRSIUnderOB = rsiBuffer[barIndex] < rsiOBLevel; + bool isPRSIUnderOB = rsiBuffer[barIndex + 1] < rsiOBLevel; + + // + bool isRSICrossedOverOB = + isRSIOverOB && + !isPRSIOverOB; + + // + bool isRSICrossedUnderOB = + isRSIUnderOB && + !isPRSIUnderOB; + + // + bool isRSIOverOS = rsiBuffer[barIndex] > rsiOSLevel; + bool isPRSIOverOS = rsiBuffer[barIndex + 1] > rsiOSLevel; + + // + bool isRSIUnderOS = rsiBuffer[barIndex] < rsiOSLevel; + bool isPRSIUnderOS = rsiBuffer[barIndex + 1] < rsiOSLevel; + + // + bool isRSICrossedOverOS = + isRSIOverOS && + !isPRSIOverOS; + + // + bool isRSICrossedUnderOS = + isRSIUnderOS && + !isPRSIUnderOS; + + // + // ADX ... + + // + bool isADXOverThreshold = adxBuffer[barIndex] > adxThreshold; + bool isPADXOverThreshold = adxBuffer[barIndex + 1] > adxThreshold; + + // + bool isADXUnderThreshold = adxBuffer[barIndex] < adxThreshold; + bool isPADXUnderThreshold = adxBuffer[barIndex + 1] < adxThreshold; + + // + bool isADXCrossedOverThreshold = + isADXOverThreshold && + !isPADXOverThreshold; + + // + bool isADXCrossedUnderThreshold = + isADXUnderThreshold && + !isPADXUnderThreshold; + + // + bool isADXBullish = adxpBuffer[barIndex] > adxnBuffer[barIndex]; + bool isPADXBullish = adxpBuffer[barIndex + 1] > adxnBuffer[barIndex + 1]; + + // + bool isADXBearish = adxpBuffer[barIndex] < adxnBuffer[barIndex]; + bool isPADXBearish = adxpBuffer[barIndex + 1] < adxnBuffer[barIndex + 1]; + + // + bool isADXSwitchedToBullish = + isADXBullish && + !isPADXBullish; + + // + bool isADXSwitchedToBearish = + isADXBearish && + !isPADXBearish; + + // + bool isADXFullySwitchedToBullish = + isADXSwitchedToBullish && + isADXCrossedOverThreshold; + + // + bool isADXFullySwitchedToBearish = + isADXSwitchedToBearish && + isADXCrossedUnderThreshold; + + // + bool isTriggerBarOverHKS = + iBar.low > iHKSMax; + bool isTriggerBarUnderHKS = + iBar.high < iHKSMin; + + // + // KI ... + + // + bool isKIBullish = kiStateBuffer[barIndex] > 0; + bool isPKIBullish = kiStateBuffer[barIndex + 1] > 0; + + // + bool isKIBearish = kiStateBuffer[barIndex] < 0; + bool isPKIBearish = kiStateBuffer[barIndex = 1] < 0; + + // + bool isKISwitchedToBullish = + isKIBullish && + !isPKIBullish; + + // + bool isKISwitchedToBearish = + isKIBearish && + !isPKIBearish; + + // + // Validating Trigger Bar based on Conditions ... if (isTriggerBar) { // - // Reading Required Info ... - - // - // HK Signal Bar ... - - // - double iHKSOpen = hkSBarOpenBuffer[barIndex]; - double iHKSClose = hkSBarCloseBuffer[barIndex]; - - // - double iHKSMax = MathMax(iHKSOpen, iHKSClose); - double iHKSMin = MathMin(iHKSOpen, iHKSClose); - - // - bool isHKSBullish = hkSBarOpenBuffer[barIndex] < hkSBarCloseBuffer[barIndex]; - bool isPHKSBullish = hkSBarOpenBuffer[barIndex + 1] < hkSBarCloseBuffer[barIndex + 1]; - - // - bool isHKSBearish = hkSBarOpenBuffer[barIndex] > hkSBarCloseBuffer[barIndex]; - bool isPHKSBearish = hkSBarOpenBuffer[barIndex + 1] > hkSBarCloseBuffer[barIndex + 1]; - - // - bool isHKSSwitchedToBullish = - isHKSBullish && - !isPHKSBullish; - - // - bool isHKSSwitchedToBearish = - isHKSBearish && - !isPHKSBearish; - - // - // TREND ... - - // - double iTrend = trendBuffer[barIndex]; - bool isTrendBullish = trendStateBuffer[barIndex] > 0; - bool isTrendBearish = trendStateBuffer[barIndex] < 0; - bool isTrendSwitchedToBullish = - trendStateBuffer[barIndex] > 0 && - trendStateBuffer[barIndex + 1] <= 0; - bool isTrendSwitchedToBearish = - trendStateBuffer[barIndex] < 0 && - trendStateBuffer[barIndex + 1] >= 0; - - // - // RSI ... - - // - bool isRSIOverOB = rsiBuffer[barIndex] > rsiOBLevel; - bool isPRSIOverOB = rsiBuffer[barIndex + 1] > rsiOBLevel; - - // - bool isRSIUnderOB = rsiBuffer[barIndex] < rsiOBLevel; - bool isPRSIUnderOB = rsiBuffer[barIndex + 1] < rsiOBLevel; - - // - bool isRSICrossedOverOB = - isRSIOverOB && - !isPRSIOverOB; - - // - bool isRSICrossedUnderOB = - isRSIUnderOB && - !isPRSIUnderOB; - - // - bool isRSIOverOS = rsiBuffer[barIndex] > rsiOSLevel; - bool isPRSIOverOS = rsiBuffer[barIndex + 1] > rsiOSLevel; - - // - bool isRSIUnderOS = rsiBuffer[barIndex] < rsiOSLevel; - bool isPRSIUnderOS = rsiBuffer[barIndex + 1] < rsiOSLevel; - - // - bool isRSICrossedOverOS = - isRSIOverOS && - !isPRSIOverOS; - - // - bool isRSICrossedUnderOS = - isRSIUnderOS && - !isPRSIUnderOS; - - // - // ADX ... - - // - bool isADXOverThreshold = adxBuffer[barIndex] > adxThreshold; - bool isPADXOverThreshold = adxBuffer[barIndex + 1] > adxThreshold; - - // - bool isADXUnderThreshold = adxBuffer[barIndex] < adxThreshold; - bool isPADXUnderThreshold = adxBuffer[barIndex + 1] < adxThreshold; - - // - bool isADXCrossedOverThreshold = - isADXOverThreshold && - !isPADXOverThreshold; - - // - bool isADXCrossedUnderThreshold = - isADXUnderThreshold && - !isPADXUnderThreshold; - - // - bool isADXBullish = adxpBuffer[barIndex] > adxnBuffer[barIndex]; - bool isPADXBullish = adxpBuffer[barIndex + 1] > adxnBuffer[barIndex + 1]; - - // - bool isADXBearish = adxpBuffer[barIndex] < adxnBuffer[barIndex]; - bool isPADXBearish = adxpBuffer[barIndex + 1] < adxnBuffer[barIndex + 1]; - - // - bool isADXSwitchedToBullish = - isADXBullish && - !isPADXBullish; - - // - bool isADXSwitchedToBearish = - isADXBearish && - !isPADXBearish; - - // - bool isADXFullySwitchedToBullish = - isADXSwitchedToBullish && - isADXCrossedOverThreshold; - - // - bool isADXFullySwitchedToBearish = - isADXSwitchedToBearish && - isADXCrossedUnderThreshold; - - // - bool isTriggerBarOverHKS = - iBar.low > iHKSMax; - bool isTriggerBarUnderHKS = - iBar.high < iHKSMin; - - // - // - // - - // - // Validate Bullish Trigger Bar ... - isBullishTriggerBar = - // - isBullishTriggerBar && - // - ( - // - // isHKSBullish && - // isTrendBullish - // - // isRSICrossedOverOS - // - isHKSSwitchedToBullish - // - ) - // - ; - - // - // Validate Bearish Trigger Bar ... - isBearishTriggerBar = - // - isBearishTriggerBar && - // - ( - // - // isHKSBearish && - // isTrendBearish - // - // isRSICrossedUnderOB - // - isHKSSwitchedToBearish - // - ) - // - ; - - // - // Summarizing Result ... - isTriggerBar = - // - isBullishTriggerBar || - isBearishTriggerBar - // - ; - - // + // TODO: Remove this if required ... isTriggerBar = false; isBullishTriggerBar = false; isBearishTriggerBar = false; } + // + // Detecting Signal ... + + // + // Bullish ... + isBullish = + // + isHKSBullish && + isKISwitchedToBullish && + iBar.close > kiBuffer[barIndex] + // + ; + + // + // Bearish ... + isBearish = + // + isHKSBearish && + isKISwitchedToBearish && + iBar.close < kiBuffer[barIndex] + // + ; + + // + // Summarizing Signal ... + hasSignal = + isBullish || + isBearish; + + // + // Draw Requirements ... + // // Draw Trigger Bar ... if (isTriggerBar) @@ -4209,6 +4215,104 @@ void DoProcess( // } + // + // Draw Signal ... + if (hasSignal) + { + // + int bullishArrowCode = 225; + int bearishArrowCode = 226; + + // + color bullishColor = clrLime; + color bearishColor = clrRed; + + // + ENUM_ARROW_ANCHOR bullishAnchor = ANCHOR_TOP; + ENUM_ARROW_ANCHOR bearishAnchor = ANCHOR_BOTTOM; + + // + int arrowWidth = 3; + int arrowCode = + isBullish + ? bullishArrowCode + : bearishArrowCode; + ENUM_X_PRICE arrowPriceType = + isBullish + ? X_PRICE_LOW + : X_PRICE_HIGH; + color arrowColor = + isBullish + ? bullishColor + : bearishColor; + ENUM_ARROW_ANCHOR arrowAnchor = + isBullish + ? bullishAnchor + : bearishAnchor; + + // + XCBarArrowObject *iObj; + has = mDrawer.CreateBarArrow( + iBar, + iObj, + arrowPriceType, + arrowCode, + arrowColor, + arrowWidth, + arrowAnchor, + namePrefix // + ); + if (has) + { + mObjects.Add(iObj); + } + + // + // Converts to Box ... + XBoxZone iBox; + iBox.type = "XSG"; + iBox.to = iBar.time; + iBox.symbol = _Symbol; + iBox.period = _Period; + iBox.lower = iPBar.low; + iBox.from = iPBar.time; + iBox.upper = iPBar.high; + iBox.dir = + isBullish + ? X_DIRECTION_BULLISH + : X_DIRECTION_BEARISH; + if (iBox.IsValid()) + { + // + XSignal iSignal; + double iRewardRatios[] = { + 1, + 1.5, + 2 // + }; + has = ToSignal( + iBox, + iSignal, + iRewardRatios, + 0 // Additional SL ... + ); + if (has) + { + // + XCSignalObject *iObj; + has = mDrawer.DrawSignal( + iSignal, + iObj, + 4 // + ); + if (has) + { + mObjects.Add(iObj); + } + } + } + } + // // Cleanup Resources ...