diff --git a/Classes/x-saherelm.x121.setup.class.mq5 b/Classes/x-saherelm.x121.setup.class.mq5 index 44bffc49..f02edb0e 100644 --- a/Classes/x-saherelm.x121.setup.class.mq5 +++ b/Classes/x-saherelm.x121.setup.class.mq5 @@ -2395,10 +2395,378 @@ struct X121SignalGenerator // ) // + || + // + // CUSTOM ... + ( + // + ( + // + // XICH ... + (conditions.ichConditions.isSenkouSpanAOverB && + conditions.ichConditions.isClosedOverKijunSen && + conditions.ichConditions.isSenkouSpanAOverLast && + conditions.ichConditions.isTenkanSenOverKijunSen && + conditions.ichConditions.isFutureSenkouSpanAOverB && + conditions.ichConditions.isFutureSenkouSpanAOverLast) && + // + // XCHMA ... + (conditions.chmaConditions.isSlowSupport && + conditions.chmaConditions.isFastOverSlow && + conditions.chmaConditions.isCLoseOverFast && + conditions.chmaConditions.isCloseOverSlow && + conditions.chmaConditions.isRetestFastSlow && + conditions.chmaConditions.isRetestSFastSlow && + conditions.chmaConditions.isRetestMFastSlow && + conditions.chmaConditions.isRetestLFastSlow && + conditions.chmaConditions.isRetestHFastSlow && + !conditions.chmaConditions.isFastSupport && + !conditions.chmaConditions.isRetestCFastSlow) + // + ) + // + || + // + ( + // + // XICH ... + conditions.ichConditions.isSenkouSpanAOverB && + conditions.ichConditions.isClosedUnderKijunSen && + conditions.ichConditions.isSenkouSpanAOverLast && + conditions.ichConditions.isFutureSenkouSpanAOverB && + conditions.ichConditions.isFutureSenkouSpanAOverLast && + !conditions.ichConditions.isTenkanSenOverKijunSen && + !conditions.ichConditions.isTenkanSenUnderKijunSen && + // + // XTD ... + conditions.tdConditions.isSwitchedToBullish && + // + // XVLM ... + conditions.vlmConditions.isVolumeBullish && + conditions.vlmConditions.isVolumeOverLast && + conditions.vlmConditions.isVolumeChangedToBullish && + // + // XHULL ... + conditions.hullConditions.isBullish && + conditions.hullConditions.isUpBullish && + conditions.hullConditions.isDownBullish && + conditions.hullConditions.isSwitchedToBullish && + // + // XCHMA ... + conditions.chmaConditions.isFastOverSlow && + conditions.chmaConditions.isCLoseOverFast && + conditions.chmaConditions.isCloseOverSlow && + conditions.chmaConditions.isSlowSupport && + conditions.chmaConditions.isRetestFastSlow && + conditions.chmaConditions.isRetestSFastSlow && + conditions.chmaConditions.isRetestMFastSlow && + conditions.chmaConditions.isRetestLFastSlow && + conditions.chmaConditions.isRetestHFastSlow && + !conditions.chmaConditions.isFastSupport && + !conditions.chmaConditions.isRetestCFastSlow + // + ) + // + || + // + ( + // + // XPV ... + (conditions.pvConditions.isNewPeak && + conditions.pvConditions.isNewPeakOverLast && + conditions.pvConditions.isFiboIncreased && + conditions.pvConditions.isCloseOverFib1 && + conditions.pvConditions.isCloseOverFib2 && + conditions.pvConditions.isCloseOverFib3 && + conditions.pvConditions.isCloseOverFib4 && + conditions.pvConditions.isCloseOverFib5) && + ( + // + ( + // + // XPV ... + conditions.pvConditions.isSCHHBullish && + conditions.pvConditions.isMCBullish && + conditions.pvConditions.isMCHHBullish && + conditions.pvConditions.isMCLLBullish && + conditions.pvConditions.isLCHHBullish && + conditions.pvConditions.isHCHHBullish && + !conditions.pvConditions.isSCBullish && + !conditions.pvConditions.isSCLLBullish && + !conditions.pvConditions.isLCBullish && + !conditions.pvConditions.isLCLLBullish && + !conditions.pvConditions.isHCBullish && + !conditions.pvConditions.isHCLLBullish && + // + // XTD ... + conditions.tdConditions.isSwitchedToBullish && + // + // XICH ... + conditions.ichConditions.isTenkanSenCrossedOverKijunSen && + // + // XHULL ... + conditions.hullConditions.isSwitchedToBullish && + // + // XCHMA ... + conditions.chmaConditions.isFastOverSlow && + conditions.chmaConditions.isCLoseOverFast && + conditions.chmaConditions.isCloseOverSlow && + conditions.chmaConditions.isRetestFastSlow && + conditions.chmaConditions.isRetestMFastSlow && + conditions.chmaConditions.isRetestLFastSlow && + conditions.chmaConditions.isRetestHFastSlow && + conditions.chmaConditions.isSlowSupport && + !conditions.chmaConditions.isFastSupport && + !conditions.chmaConditions.isRetestCFastSlow && + !conditions.chmaConditions.isRetestSFastSlow + // + ) + // + || + // + ( + // + // XPV ... + conditions.pvConditions.isCloseCrossedOverFib1 && + conditions.pvConditions.isSCBullish && + conditions.pvConditions.isSCHHBullish && + conditions.pvConditions.isSCLLBullish && + conditions.pvConditions.isMCBullish && + conditions.pvConditions.isMCHHBullish && + conditions.pvConditions.isMCLLBullish && + conditions.pvConditions.isLCBullish && + conditions.pvConditions.isLCHHBullish && + conditions.pvConditions.isLCLLBullish && + conditions.pvConditions.isHCHHBullish && + conditions.pvConditions.isMCSwitchedToBullish && + conditions.pvConditions.isMCLLSwitchedToBullish && + conditions.pvConditions.isLCSwitchedToBullish && + conditions.pvConditions.isLCLLSwitchedToBullish && + !conditions.pvConditions.isHCBullish && + !conditions.pvConditions.isHCLLBullish && + !conditions.pvConditions.isMCHHSwitchedToBullish && + !conditions.pvConditions.isLCHHSwitchedToBullish && + // + // XICH ... + conditions.ichConditions.isClosedOverKijunSen && + conditions.ichConditions.isTenkanSenOverKijunSen && + conditions.ichConditions.isSenkouSpanAOverB && + conditions.ichConditions.isFutureSenkouSpanAOverB && + conditions.ichConditions.isFutureSenkouSpanAOverLast && + !conditions.ichConditions.isSenkouSpanAOverLast && + // + // XHULL ... + conditions.hullConditions.isSwitchedToBullish && + // + // XHTD ... + conditions.htdConditions.isSwitchedToBullish && + // + // XCHMA ... + conditions.chmaConditions.isFastOverSlow && + conditions.chmaConditions.isCLoseOverFast && + conditions.chmaConditions.isCloseOverSlow && + conditions.chmaConditions.isSlowSupport && + conditions.chmaConditions.isRetestFastSlow && + conditions.chmaConditions.isRetestMFastSlow && + conditions.chmaConditions.isRetestLFastSlow && + conditions.chmaConditions.isRetestHFastSlow && + !conditions.chmaConditions.isFastSupport && + !conditions.chmaConditions.isRetestCFastSlow && + !conditions.chmaConditions.isRetestSFastSlow + // + ) + // + || + // + ( + // + // XPV ... + conditions.pvConditions.isSCHHBullish && + conditions.pvConditions.isMCHHBullish && + conditions.pvConditions.isLCHHBullish && + conditions.pvConditions.isHCHHBullish && + !conditions.pvConditions.isSCBullish && + !conditions.pvConditions.isSCLLBullish && + !conditions.pvConditions.isMCBullish && + !conditions.pvConditions.isMCLLBullish && + !conditions.pvConditions.isLCBullish && + !conditions.pvConditions.isLCLLBullish && + !conditions.pvConditions.isHCBullish && + !conditions.pvConditions.isHCLLBullish && + // + // XICH ... + conditions.ichConditions.isTenkanSenCrossedOverKijunSen && + // + // XCHMA ... + conditions.chmaConditions.isFastOverSlow && + conditions.chmaConditions.isCLoseOverFast && + conditions.chmaConditions.isCloseOverSlow && + conditions.chmaConditions.isRetestFastSlow && + conditions.chmaConditions.isRetestSFastSlow && + conditions.chmaConditions.isRetestMFastSlow && + conditions.chmaConditions.isRetestLFastSlow && + conditions.chmaConditions.isRetestHFastSlow && + !conditions.chmaConditions.isRetestCFastSlow + // + ) + // + || + // + ( + // + // XPV ... + conditions.pvConditions.isSCBullish && + conditions.pvConditions.isSCHHBullish && + conditions.pvConditions.isSCLLBullish && + conditions.pvConditions.isSCSwitchedToBullish && + conditions.pvConditions.isSCLLSwitchedToBullish && + conditions.pvConditions.isMCHHBullish && + conditions.pvConditions.isLCHHBullish && + conditions.pvConditions.isHCHHBullish && + !conditions.pvConditions.isSCHHSwitchedToBullish && + !conditions.pvConditions.isMCBullish && + !conditions.pvConditions.isMCLLBullish && + !conditions.pvConditions.isLCBullish && + !conditions.pvConditions.isLCLLBullish && + !conditions.pvConditions.isHCBullish && + !conditions.pvConditions.isHCLLBullish && + // + // XICH ... + conditions.ichConditions.isClosedOverKijunSen && + conditions.ichConditions.isTenkanSenOverKijunSen && + conditions.ichConditions.isSenkouSpanAOverB && + conditions.ichConditions.isSenkouSpanAOverLast && + conditions.ichConditions.isFutureSenkouSpanAOverB && + conditions.ichConditions.isFutureSenkouSpanAOverLast && + conditions.ichConditions.isSenkouSpanACrossedOverB && + // + // XCHMA ... + conditions.chmaConditions.isFastOverSlow && + conditions.chmaConditions.isCLoseOverFast && + conditions.chmaConditions.isCloseOverSlow && + conditions.chmaConditions.isRetestFastSlow && + conditions.chmaConditions.isSlowSupport && + conditions.chmaConditions.isRetestSFastSlow && + conditions.chmaConditions.isRetestMFastSlow && + conditions.chmaConditions.isRetestLFastSlow && + conditions.chmaConditions.isRetestHFastSlow && + !conditions.chmaConditions.isRetestCFastSlow + // + ) + // + || + // + ( + // + // XPV ... + conditions.pvConditions.isSCBullish && + conditions.pvConditions.isSCHHBullish && + conditions.pvConditions.isSCLLBullish && + conditions.pvConditions.isMCBullish && + conditions.pvConditions.isMCHHBullish && + conditions.pvConditions.isMCLLBullish && + conditions.pvConditions.isLCHHBullish && + conditions.pvConditions.isHCBullish && + conditions.pvConditions.isHCHHBullish && + conditions.pvConditions.isHCLLBullish && + !conditions.pvConditions.isLCBullish && + !conditions.pvConditions.isLCLLBullish && + // + // XICH ... + conditions.ichConditions.isClosedOverKijunSen && + conditions.ichConditions.isTenkanSenOverKijunSen && + conditions.ichConditions.isSenkouSpanAOverB && + conditions.ichConditions.isFutureSenkouSpanAOverB && + conditions.ichConditions.isFutureSenkouSpanAOverLast && + !conditions.ichConditions.isSenkouSpanAOverLast && + // + // XSTR ... + conditions.strConditions.isTrendSwitchedToBullish && + // + // XCHMA ... + conditions.chmaConditions.isFastOverSlow && + conditions.chmaConditions.isCLoseOverFast && + conditions.chmaConditions.isCloseOverSlow + // + ) + // + ) + // + ) + // + || + // + ( + // + // XPV ... + conditions.pvConditions.isCloseOverFib1 && + conditions.pvConditions.isCloseOverFib2 && + conditions.pvConditions.isCloseOverFib3 && + conditions.pvConditions.isCloseOverFib4 && + conditions.pvConditions.isCloseOverFib5 && + conditions.pvConditions.isSCBullish && + conditions.pvConditions.isSCHHBullish && + conditions.pvConditions.isSCLLBullish && + conditions.pvConditions.isMCBullish && + conditions.pvConditions.isMCHHBullish && + conditions.pvConditions.isMCLLBullish && + conditions.pvConditions.isLCHHBullish && + !conditions.pvConditions.isLCBullish && + !conditions.pvConditions.isLCLLBullish && + !conditions.pvConditions.isHCBullish && + !conditions.pvConditions.isHCHHBullish && + !conditions.pvConditions.isHCLLBullish && + // + // XMC ... + conditions.mcConditions.isSwitchedToBullish && + conditions.mcConditions.isSlowCrossedOverVerifier && + // + // XICH ... + conditions.ichConditions.isSenkouSpanAOverB && + conditions.ichConditions.isClosedOverKijunSen && + conditions.ichConditions.isTenkanSenOverKijunSen && + !conditions.ichConditions.isSenkouSpanAOverLast && + // + // XSTR ... + conditions.strConditions.isTrendSwitchedToBullish + // + ) + // // + // || + // // + // ( + // // + // // + // ) + // + ) + // ) // ; + // // + // // Filter Conditions Based On Providers ... + // if (result) { + // // + // if (provider == ToString(PROVIDER_UNKNOWN)) { + // // + // result = + // // + // result && + // !( + // // + // // + // ( + + // ) + // // + // ) + // // + // ; + // } + // } + // // Apply Filter ... // Based On Symbol and Period ... @@ -3948,6 +4316,28 @@ struct X121SignalGenerator // ; + // // + // // Filter Conditions Based On Providers ... + // if (result) { + // // + // if (provider == ToString(PROVIDER_UNKNOWN)) { + // // + // result = + // // + // result && + // !( + // // + // // + // ( + + // ) + // // + // ) + // // + // ; + // } + // } + // // Apply Filter ... // Based On Symbol and Period ... diff --git a/Experts/x-test.ea.mq5 b/Experts/x-test.ea.mq5 index bd176b90..4f66d237 100644 --- a/Experts/x-test.ea.mq5 +++ b/Experts/x-test.ea.mq5 @@ -40,6 +40,9 @@ double eaAllowShort = true; // // Variables ... +XBarTracker eaBarTracker; + +// XSCXTestSetupEA *mSetupEA; XSCXCTHelper *mCTHelper; XSCXCCHelper *mCCHelper; @@ -63,6 +66,16 @@ int OnInit() return INIT_FAILED; } + // + bool isInited = eaBarTracker.Init( + _Symbol, + _Period // + ); + if (!isInited) + { + return INIT_FAILED; + } + // // Init Succeed ... return INIT_SUCCEEDED; @@ -95,7 +108,103 @@ void OnDeinit(const int reason) // On Tick Handler ... void OnTick() { - mSetupEA.OnTick(); + // mSetupEA.OnTick(); + + // + if (!eaBarTracker.CanProcessBar()) + { + return; + } + + // + XOHCL cBar; + bool isInit = cBar.Init( + _Symbol, + _Period, + 1 // + ); + if (!isInit) + { + return; + } + + // + datetime time1 = iTime( + _Symbol, + _Period, + 2 // + ); + + // + double fib382 = 0; + + // + bool isHammer = cBar.IsHammer(); + if (isHammer) + { + // + fib382 = GetFibonacciLevel( + cBar.high, + cBar.low, + 0.382, + -1 // + ); + DrawTrendLine( + ChartID(), + "HMR_TR", + 0, + time1, + fib382, + cBar.time, + fib382, + clrYellow // + ); + Print("Hammer ..."); + eaBarTracker.Waits(); + } + + // + bool isShootingStar = cBar.IsShootingStar(); + if (isShootingStar) + { + // + fib382 = GetFibonacciLevel( + cBar.high, + cBar.low, + 0.382, + 1 // + ); + DrawTrendLine( + ChartID(), + "HMR_TR", + 0, + time1, + fib382, + cBar.time, + fib382, + clrYellow // + ); + Print("ShootingStar ..."); + eaBarTracker.Waits(); + } + + // + bool isBullishEngulf = cBar.IsBullishEngulf(); + if (isBullishEngulf) + { + // + Print("Bullish Engulf ..."); + eaBarTracker.Waits(); + } + + // + bool isBearishEngulf = cBar.IsBearishEngulf(); + if (isBearishEngulf) + { + // + Print("Bearish Engulf ..."); + eaBarTracker.Waits(); + } } // @@ -212,9 +321,9 @@ void PreConfigureStyles(XTestInputs &inputs) { // // XRL ... - inputs.rlInputs.showFast = true; - inputs.rlInputs.showSlow = true; - inputs.rlInputs.showVerifier = true; + inputs.rlInputs.showFast = false; + inputs.rlInputs.showSlow = false; + inputs.rlInputs.showVerifier = false; // // XHTD ... @@ -222,7 +331,7 @@ void PreConfigureStyles(XTestInputs &inputs) // // XATSL ... - inputs.atslInputs.show = true; + inputs.atslInputs.show = false; // // XSLN ... @@ -240,12 +349,12 @@ void PreConfigureStyles(XTestInputs &inputs) // // XPV ... - inputs.pvInputs.showPeaksAndVales = true; + inputs.pvInputs.showPeaksAndVales = false; inputs.pvInputs.showLevels = false; inputs.pvInputs.showConsolidations = false; inputs.pvInputs.showFibo1Levels = false; inputs.pvInputs.showFibo2Levels = false; - inputs.pvInputs.showFibo3Levels = true; + inputs.pvInputs.showFibo3Levels = false; inputs.pvInputs.showFibo4Levels = false; inputs.pvInputs.showFibo5Levels = false; diff --git a/Libraries/x-saherelm.common.lib.mq5 b/Libraries/x-saherelm.common.lib.mq5 index 8af00dfc..aeddc604 100644 --- a/Libraries/x-saherelm.common.lib.mq5 +++ b/Libraries/x-saherelm.common.lib.mq5 @@ -1001,6 +1001,138 @@ struct XOHCL return result; } + // + // Check Bar Is Hammer Pattern ... + bool IsHammer() + { + // + bool result = false; + + // + double fib382 = GetFibonacciLevel( + high, + low, + 0.382, + -1 // + ); + + // + result = GetDown() > fib382; + + // + return result; + } + + // + // Check Bar Is Shooting Star Pattern ... + bool IsShootingStar() + { + // + bool result = false; + + // + double fib382 = GetFibonacciLevel( + high, + low, + 0.382, + 1 // + ); + + // + result = GetUp() < fib382; + + // + return result; + } + + // + // Check Bar Bullish Engulfing Pattern ... + bool IsBullishEngulf() + { + // + bool result = false; + + // + // Current Bar Must be Bullish ... + result = IsBullish(); + if (!result) + { + return result; + } + + // + // Retrieve Previous Bar ... + XOHCL pBar; + result = GetPreviousBar(pBar); + if (!result) + { + return result; + } + + // + // Prev Bar Must be Bearish ... + result = pBar.IsBearish(); + if (!result) + { + return result; + } + + // + // Close of Current Bar must be Higher than High of Prev Bar ... + result = close > pBar.high; + if (!result) + { + return result; + } + + // + return result; + } + + // + // Check Bar Bearish Engulfing Pattern ... + bool IsBearishEngulf() + { + // + bool result = false; + + // + // Current Bar Must be Bearish ... + result = IsBearish(); + if (!result) + { + return result; + } + + // + // Retrieve Previous Bar ... + XOHCL pBar; + result = GetPreviousBar(pBar); + if (!result) + { + return result; + } + + // + // Prev Bar Must be Bullish ... + result = pBar.IsBullish(); + if (!result) + { + return result; + } + + // + // Close of Current Bar must be Lower than Low of Prev Bar ... + result = close < pBar.low; + if (!result) + { + return result; + } + + // + return result; + } + // // Check Bar has Strong Body or Not ... bool HasStrongBody() @@ -2690,6 +2822,1002 @@ struct XMarketCycle } }; +// +// a Pivot Point ... +struct XPivot +{ + // + string symbol; // Trading Symbol ... + ENUM_TIMEFRAMES period; // Trading TimeFrame ... + + // + double price; // Price ... + datetime time; // Time ... + + // + int breakedAsSupport; // Number of Breaked As Support ... + int rejectedAsSupport; // Number of Rejected As Support ... + + // + int breakedAsResistance; // Number of Breaked As Resistance ... + int rejectedAsResistance; // Number of Rejected As Resistance ... + + // + bool isSupport; + bool isResistance; + + // + int _lastCalculatedBar; + int _loopbackForSupportAndResistance; // Number of LoopBacks for Support or Resistance ... + + // + // Constructor ... + XPivot() + { + Clean(); + } + + // + // Initialization ... + bool Init( + string _symbol, + ENUM_TIMEFRAMES _period, + double _price, + int _supResVerifications = 21 // + ) + { + // + bool result = false; + + // + result = + // + _price > 0 && + IsValid(_symbol) && + IsValid(_period) && + IsValidSize(_supResVerifications) + // + ; + + if (!result) + { + return result; + } + + // + symbol = _symbol; + period = _period; + price = _price; + + // + _loopbackForSupportAndResistance = _supResVerifications; + + // + Calculate(); + + // + result = IsValid(); + + // + return result; + } + + // + // Tools ... + + // + // Check Support Rejected ... + bool IsSupportRejected() + { + // + bool result = false; + + // + result = isSupport; + if (!result) + { + return result; + } + + // + // Initialize Required Bars ... + + // + XOHCL cBar; + result = cBar.Init( + symbol, + period, + 1 // + ); + if (!result) + { + return result; + } + + // + XOHCL pBar; + result = pBar.Init( + symbol, + period, + 2 // + ); + if (!result) + { + return result; + } + + // + result = + // + // Check Support Touch or Fake Break ... + pBar.low < price + // + && + // + // Check Rejection ... + cBar.low > price + // + ; + + // + return result; + } + + // + // Check Support Breaked ... + bool IsSupportBreaked() + { + // + bool result = false; + + // + result = isSupport; + if (!result) + { + return result; + } + + // + // Initialize Required Bars ... + + // + XOHCL cBar; + result = cBar.Init( + symbol, + period, + 1 // + ); + if (!result) + { + return result; + } + + // + XOHCL pBar; + result = pBar.Init( + symbol, + period, + 2 // + ); + if (!result) + { + return result; + } + + // + result = + // + // Check Support Breaks ... + pBar.close < price + // + && + // + // Check 50% ... + (price - pBar.close) > (pBar.GetBody() / 100) * 50 + // + && + // + // Also Next Bar must Closed Below Support ... + cBar.high < price + // + && + // + cBar.close < price + // + && + // + cBar.IsBullish() + // + ; + + // + return result; + } + + // + // Check Resistance Rejected ... + bool IsResistanceRejected() + { + // + bool result = false; + + // + result = isResistance; + if (!result) + { + return result; + } + + // + // Initialize Required Bars ... + + // + XOHCL cBar; + result = cBar.Init( + symbol, + period, + 1 // + ); + if (!result) + { + return result; + } + + // + XOHCL pBar; + result = pBar.Init( + symbol, + period, + 2 // + ); + if (!result) + { + return result; + } + + // + result = + // + // Check Resistance Touch or Fake Break ... + pBar.high > price + // + && + // + // Check Rejection ... + cBar.high < price + // + ; + + // + return result; + } + + // + // Check Resistance Breaked ... + bool IsResistanceBreaked() + { + // + bool result = false; + + // + result = isResistance; + if (!result) + { + return result; + } + + // + // Initialize Required Bars ... + + // + XOHCL cBar; + result = cBar.Init( + symbol, + period, + 1 // + ); + if (!result) + { + return result; + } + + // + XOHCL pBar; + result = pBar.Init( + symbol, + period, + 2 // + ); + if (!result) + { + return result; + } + + // + result = + // + // Check Resistance Breaks ... + pBar.close > price + // + && + // + // Check 50% ... + (pBar.close - price) > (pBar.GetBody() / 100) * 50 + // + && + // + // Also Next Bar Must Closed Above Resistance ... + cBar.low > price + // + && + // + cBar.close > price + // + && + // + cBar.IsBullish() + // + ; + + // + return result; + } + + // + // Cleanup ... + void Clean() + { + // + symbol = NULL; + period = NULL; + time = NULL; + + // + price = 0; + + // + breakedAsSupport = 0; + rejectedAsSupport = 0; + breakedAsResistance = 0; + rejectedAsResistance = 0; + + // + _lastCalculatedBar = -1; + + // + isSupport = false; + isResistance = false; + } + + // + // Validate Model ... + bool IsValid() + { + // + bool result = false; + + // + result = + // + IsValid(symbol) && + IsValid(period) && + price > 0 + // + ; + + // + return result; + } + + // + // Calculate Required Data ... + void Calculate(int loopback = 288) + { + // + if (isSupport || isResistance) + { + return; + } + + // + int bars = iBars( + symbol, + period // + ); + + // + // Normalizing Loopback ... + if (loopback > bars) + { + loopback = bars - 2 - _loopbackForSupportAndResistance; + } + + // + // Check Previous Calculation ... + if (bars == _lastCalculatedBar) + { + return; + } + + // + _lastCalculatedBar = bars; + + // + // First Get Current State of Pivot ... + // Means Use Zero Index ... + XOHCL pBar; + bool isInited = pBar.Init( + symbol, + period, + 1 // + ); + if (!isInited) + { + return; + } + + // + // Retrieve Highest High and Lowest Low of SupRes Loopback ... + double hhValue = pBar + .FindHighest( + _loopbackForSupportAndResistance, + MODE_HIGH // + ); + + // + double llValue = pBar + .FindLowest( + _loopbackForSupportAndResistance, + MODE_LOW // + ); + + // + isSupport = llValue > price; + isResistance = hhValue < price; + + // + // Prevent Moving Forward if it isn't Support or Resistance ... + if (!isSupport && !isResistance) + { + return; + } + + // + time = TimeCurrent(); + + // + for (int i = 2; i < loopback; i++) + { + // + XOHCL iBar; + isInited = iBar.Init( + symbol, + period, + i // + ); + if (!isInited) + { + continue; + } + + // + XOHCL iPBar; + isInited = iPBar.Init( + symbol, + period, + i + 1 // + ); + if (!isInited) + { + continue; + } + + // + XOHCL iPPBar; + isInited = iPPBar.Init( + symbol, + period, + i + 2 // + ); + if (!isInited) + { + continue; + } + + // + bool isBreaked = false; + bool isRejected = false; + + // + if (isSupport) + { + // + // Count Support Rejects + // and Support Breaks ... + + // + // Support Rejected ... + isRejected = + // + // Check Support Touch or Fake Break ... + iPBar.low < price + // + && + // + // Check Rejection ... + iBar.low > price + // + ; + if (isRejected) + { + rejectedAsSupport++; + } + + // + // Support Breaked ... + isBreaked = + // + // Check Support Breaks ... + iPBar.close < price + // + && + // + // Check 50% ... + (price - iPBar.close) > (iPBar.GetBody() / 100) * 50 + // + && + // + // Also Next Bar must Closed Below Support ... + iBar.high < price + // + && + // + iBar.close < price + // + && + // + iBar.IsBullish() + // + ; + if (isBreaked) + { + breakedAsSupport++; + } + } + else if (isResistance) + { + // + // Count Resistance Reject + // or Resistance Breaks ... + + // + // Resistance Rejected ... + isRejected = + // + // Check Resistance Touch or Fake Break ... + iPBar.high > price + // + && + // + // Check Rejection ... + iBar.high < price + // + ; + if (isRejected) + { + rejectedAsResistance++; + } + + // + // Resistance Breaked ... + isBreaked = + // + // Check Resistance Breaks ... + iPBar.close > price + // + && + // + // Check 50% ... + (iPBar.close - price) > (iPBar.GetBody() / 100) * 50 + // + && + // + // Also Next Bar Must Closed Above Resistance ... + iBar.low > price + // + && + // + iBar.close > price + // + && + // + iBar.IsBullish() + // + ; + if (isBreaked) + { + breakedAsResistance++; + } + } + } + } +}; + +// +// a Zone Modeling ... + +// +enum ENUM_XZONE_STATE +{ + XZONE_STATE_INVALID = 0, // Invalid Zone ... + XZONE_STATE_FULL_SUPPORT = 1, // Full Support (up / down) are Support ... + XZONE_STATE_FULL_RESISTANCE = 2, // Full Resistance (up / down) are Resistaence ... + XZONE_STATE_CONSOLIDATE = 3, // Down are Support and Up are Resistance ... +}; + +// +struct XZone +{ + // + string symbol; // Trading Symbol ... + ENUM_TIMEFRAMES period; // Trading TimeFrame ... + + // + datetime time; + + // + XPivot up; // Up pivot ... + XPivot down; // Down Pivot ... + + // + // Constructor ... + XZone() + { + Clean(); + } + + // + // Initialize a Zone ... + bool Init( + string _symbol, + ENUM_TIMEFRAMES _period, + double _upPrice, + double _downPrice // + ) + { + // + bool result = false; + + // + result = + // + IsValid(_symbol) && + IsValid(_period) && + _upPrice > 0 && + _downPrice > 0 && + _downPrice < _upPrice + // + ; + if (!result) + { + return result; + } + + // + symbol = _symbol; + period = _period; + + // + result = up.Init( + symbol, + period, + _upPrice // + ); + if (!result) + { + return result; + } + + // + result = down.Init( + symbol, + period, + _downPrice // + ); + if (!result) + { + return result; + } + + // + result = IsValid(); + + // + if (result) + { + time = TimeCurrent(); + } + + // + return result; + } + + // + // Tools ... + + // + // Check XZone State ... + ENUM_XZONE_STATE GetState() + { + // + ENUM_XZONE_STATE result = XZONE_STATE_INVALID; + if (!IsValid()) + { + return result; + } + + // + up.Calculate(); + down.Calculate(); + + // + if (up.isSupport && down.isSupport) + { + result = XZONE_STATE_FULL_SUPPORT; + } + else if (up.isResistance && down.isResistance) + { + result = XZONE_STATE_FULL_RESISTANCE; + } + else if (up.isSupport && down.isResistance) + { + result = XZONE_STATE_CONSOLIDATE; + } + + // + return result; + } + + // + // Check Zone Rejected ... + + // + // Check Zone Breaked ... + + // + // Cleanup ... + void Clean() + { + // + symbol = NULL; + period = NULL; + time = NULL; + + // + up.Clean(); + down.Clean(); + } + + // + // Validate ... + bool IsValid() + { + // + bool result = false; + + // + result = + // + IsValid(symbol) && + IsValid(period) && + up.IsValid() && + down.IsValid() + // + ; + + // + return result; + } +}; + +// +// a Range Box Model ... +struct XRBox +{ + // + string symbol; + ENUM_TIMEFRAMES period; + + // + datetime time; + datetime expiration; + + // + XZone up; // Up Zone ... + XZone down; // Down Zone ... + + // + // Constructor ... + XRBox() + { + Clean(); + } + + // + // Initialization ... + bool Init( + string _symbol, + ENUM_TIMEFRAMES _period, + double _upZoneUpperPrice, + double _upZoneLowerPrice, + double _downZoneUpperPrice, + double _downZoneLowerPrice, + datetime _expiration = NULL // + ) + { + // + bool result = false; + + // + result = + // + IsValid(_symbol) && + IsValid(_period) && + _upZoneUpperPrice > 0 && + _upZoneLowerPrice > 0 && + _upZoneLowerPrice < _upZoneUpperPrice && + _downZoneUpperPrice > 0 && + _downZoneLowerPrice > 0 && + _downZoneLowerPrice < _downZoneUpperPrice + // + ; + // + if (!result) + { + return result; + } + + // + result = IsValid(); + + // + if (result) + { + // + time = TimeCurrent(); + } + + // + return result; + } + + // + // Tools ... + + // + // Cleanup ... + void Clean() + { + // + time = NULL; + symbol = NULL; + period = NULL; + expiration = NULL; + + // + up.Clean(); + down.Clean(); + } + + // + // Validation ... + bool IsValid() + { + // + bool result = false; + + // + result = + // + IsValid(symbol) && + IsValid(period) && + up.IsValid() && + down.IsValid() + // + ; + + // + return result; + } +}; + +// +// Detect Trends ... +struct XTrendDetector +{ + // + string symbol; + ENUM_TIMEFRAMES period; + + // + double higherHighs[]; + datetime higherHighTimes[]; + + // + double higherLows[]; + datetime higherLowTimes[]; + + // + double lowerHighs[]; + datetime lowerHighTimes[]; + + // + double lowerLows[]; + datetime lowerLowTimes[]; + + // + int _numberOfPivots; + int _pivotShoulders; + + // + // Constructor ... + XTrendDetector() + { + Clean(); + } + + // + // Tools ... + + // + // Cleanup ... + void Clean() + { + // + symbol = NULL; + period = NULL; + + // + _numberOfPivots = 0; + _pivotShoulders = 0; + + // + Clean(higherHighs); + Clean(higherHighTimes); + + // + Clean(higherLows); + Clean(higherLowTimes); + + // + Clean(lowerHighs); + Clean(lowerHighTimes); + + // + Clean(lowerLows); + Clean(lowerLowTimes); + } + + // + // Validate ... + bool IsValid() + { + // + bool result = false; + + // + result = + // + IsValid(symbol) && + IsValid(period) + // + ; + + // + return result; + } +}; + // // Linear Regression ... @@ -2805,7 +3933,7 @@ struct XLinearRegression }; // -// Use To Parse Symbols for +// Use To Parse Symbols for // Ignore Brokers Additional Suffixes ... struct XSymbolParser {