diff --git a/Documents/BKP/tmp.codes.mq5 b/Documents/BKP/tmp.codes.mq5 index 34a47677..003f38b7 100644 --- a/Documents/BKP/tmp.codes.mq5 +++ b/Documents/BKP/tmp.codes.mq5 @@ -555,3 +555,1494 @@ // iBar.close < kiBuffer[barIndex] // ; + +//////////////////////////////////////////////////////////////////// + + +// +int mSameKICount = 0; +int mSameKIBullishCount = 0; +int mSameKIBearishCount = 0; + +// +int mSamePeakCount = 0; +int mSameValeCount = 0; + +// +double mSamePeaksGoldenMin = 0; +double mSamePeaksGoldenMax = 0; + +// +double mSameValesGoldenMin = 0; +double mSameValesGoldenMax = 0; + +// +int mSamePeakGoldenCount = 0; +int mSameValeGoldenCount = 0; + +// +bool mDrawLiquidities = false; +bool mDrawRangeBreakes = false; + +// +bool mDetectLiquidities = true; +bool mDetectRangeBreakes = true; + +// +XBoxZone mBullishLiquidities[]; +XBoxZone mBearishLiquidities[]; +XBoxZone mBullishRangeBreakes[]; +XBoxZone mBearishRangeBreakes[]; + +// +// POI(s) Handlers ... +// + +/** + * Detect POI(s) ... + * + * @param barIndex: int, Specified Bar Index ... + * @param prevCalculated: int, Provides Previous Calculated Bars ... + * @param ratesTotal: int, Provides All Availabled Bars ... + * @param open: double Collection, Provides Open Prices Time Series ... + * @param high: double Collection, Provides High Prices Time Series ... + * @param close: double Collection, Provides Close Prices Time Series ... + * @param low: double Collection, Provides Low Prices Time Series ... + * @param tickVolume: long Collection, Provides Ticks Volume Prices Time Series ... + */ +void DetectPOIs( + int barIndex, + const int prevCalculated, + const int ratesTotal, + const double &open[], + const double &high[], + const double &close[], + const double &low[], + const long &tickVolume[] // +) +{ + // + // Check Some Requirements ... + int lastBarIndex = barIndex + 1; + int maxBarIndex = startCalculationForLastBars > 0 + ? startCalculationForLastBars + : ratesTotal; + bool isFirstBar = + startCalculationForLastBars > 0 + ? barIndex == startCalculationForLastBars + : barIndex == firstBarIndex; + + // + // Handle Minimum Required Bars ... + bool isPassedRequiredBars = barIndex < maxBarIndex - 3; + if (!isPassedRequiredBars) + { + return; + } + + // + // Recieve Bar ... + XOHCL iBar; + XOHCL iPBar; + bool has = iBar.Init( + _Symbol, + _Period, + barIndex + // + ); + has = + has && + iBar.GetPreviousBar(iPBar); + if (!has) + { + return; + } + + // + bool isBullish = false; + bool isBearish = false; + int maxAllowedPOIs = 50; + + // + ENUM_X_DIRECTION iDir; + + // + // Detecting Liquidity ... + if (mDetectLiquidities) + { + // + bool isLiquidity = + mBarAnalyser + .IsRejected( + iBar, + iDir, + true, + true // + ); + bool isBullishLiquiditySweeped = + isLiquidity && + IsBullish(iDir); + bool isBearishLiquiditySweeped = + isLiquidity && + IsBearish(iDir); + if (isLiquidity) + { + // + XBoxZone iLiq; + + // + iLiq.dir = iDir; + iLiq.type = "XLIQ"; + iLiq.upper = + isBullishLiquiditySweeped + ? iBar.GetDown() + : iBar.high; + iLiq.lower = + isBullishLiquiditySweeped + ? iBar.low + : iBar.GetUp(); + iLiq.at = iBar.time; + iLiq.from = iBar.time; + iLiq.symbol = _Symbol; + iLiq.period = _Period; + iLiq.to = ((datetime)((int)iBar.time + (PeriodSeconds(_Period)))); + + // + if (iLiq.IsValid()) + { + // + if (isBullishLiquiditySweeped) + { + // + has = AddBoxIfNotExists( + iLiq, + mBullishLiquidities // + ); + if (has) + { + // + SortBoxes( + mBullishLiquidities, + maxAllowedPOIs // + ); + } + } + else + { + // + has = AddBoxIfNotExists( + iLiq, + mBearishLiquidities // + ); + if (has) + { + // + SortBoxes( + mBearishLiquidities, + maxAllowedPOIs // + ); + } + } + } + + // + iLiq.Clean(); + } + } + + // + // Detecting Bullish and Bearish Breakes ... + + // + bool isPeakSame = peakBuffer[barIndex] == peakBuffer[barIndex + 1]; + bool isPPeakSame = peakBuffer[barIndex + 1] == peakBuffer[barIndex + 2]; + + // + bool isPeakOverLast = peakBuffer[barIndex] > peakBuffer[barIndex + 1]; + bool isPPeakOverLast = peakBuffer[barIndex + 1] > peakBuffer[barIndex + 2]; + + // + bool isPeakUnderLast = peakBuffer[barIndex] < peakBuffer[barIndex + 1]; + bool isPPeakUnderLast = peakBuffer[barIndex + 1] < peakBuffer[barIndex + 2]; + + // + bool isSamePeakOverLast = + isPPeakSame && + isPeakOverLast; + bool isSamePeakUnderLast = + isPPeakSame && + isPeakUnderLast; + + // + bool isValeSame = valeBuffer[barIndex] == valeBuffer[barIndex + 1]; + bool isPValeSame = valeBuffer[barIndex + 1] == valeBuffer[barIndex + 2]; + + // + bool isValeOverLast = valeBuffer[barIndex] > valeBuffer[barIndex + 1]; + bool isPValeOverLast = valeBuffer[barIndex + 1] > valeBuffer[barIndex + 2]; + + // + bool isValeUnderLast = valeBuffer[barIndex] < valeBuffer[barIndex + 1]; + bool isPValeUnderLast = valeBuffer[barIndex + 1] < valeBuffer[barIndex + 2]; + + // + bool isSameValeOverLast = + isPValeSame && + isValeOverLast; + bool isSameValeUnderLast = + isPValeSame && + isValeUnderLast; + + // + // Detecting Range Breakes ... + if (mDetectRangeBreakes) + { + // + isBullish = isSamePeakOverLast + // || isSameValeOverLast + ; + isBearish = + isSameValeUnderLast + // || isSamePeakUnderLast + ; + + // + bool basedOnPeak = + isSamePeakOverLast + // || isSamePeakUnderLast + ; + + // + bool basedOnVale = + isSameValeUnderLast + // isSameValeOverLast || + ; + + // + has = isBullish || + isBearish; + + // + if (has) + { + // + XBoxZone iRNGBreak; + + // + iDir = + isBullish + ? X_DIRECTION_BULLISH + : isBearish + ? X_DIRECTION_BEARISH + : X_DIRECTION_NONE; + + // + iRNGBreak.dir = iDir; + iRNGBreak.at = iBar.time; + iRNGBreak.type = "XRNGB"; + iRNGBreak.to = iBar.time; + iRNGBreak.symbol = _Symbol; + iRNGBreak.period = _Period; + + // + int fromIDX = + iBar.Index() + + (basedOnPeak + ? mSamePeakCount + : basedOnVale + ? mSameValeCount + : 0); + datetime from = GetBarTime( + _Symbol, + _Period, + fromIDX // + ); + iRNGBreak.from = from; + + // + double upper = + isBullish + ? basedOnPeak + ? peakBuffer[barIndex] + : basedOnVale + ? mSameValeGoldenCount + : 0 + : isBearish + ? basedOnPeak + ? peakBuffer[barIndex] + : basedOnVale + ? mSameValeGoldenCount + : 0 + : 0; + + // + double lower = + isBullish + ? basedOnPeak + ? mSamePeakGoldenCount + : basedOnVale + ? valeBuffer[barIndex] + : 0 + : isBearish + ? basedOnPeak + ? mSamePeakGoldenCount + : basedOnVale + ? valeBuffer[barIndex] + : 0 + : 0; + + // + iRNGBreak.upper = upper; + iRNGBreak.lower = lower; + + // + // Adding POI ... + has = iRNGBreak.IsValid(); + if (has) + { + // + if (isBullish) + { + // + has = AddBoxIfNotExists( + iRNGBreak, + mBullishRangeBreakes // + ); + if (has) + { + // + SortBoxes( + mBullishRangeBreakes, + maxAllowedPOIs // + ); + } + } + else if (isBearish) + { + // + has = AddBoxIfNotExists( + iRNGBreak, + mBearishRangeBreakes // + ); + if (has) + { + // + SortBoxes( + mBearishRangeBreakes, + maxAllowedPOIs // + ); + } + } + } + } + } + + // + if (isPeakSame) + { + // + mSamePeakGoldenCount = + mSamePeakGoldenCount == 0 + ? iBar.GetUp() + : MathMax(mSamePeakGoldenCount, iBar.GetUp()); + mSamePeakCount++; + } + else + { + // + mSamePeakCount = 0; + mSamePeakGoldenCount = 0; + } + + // + if (isValeSame) + { + // + mSameValeGoldenCount = + mSameValeGoldenCount == 0 + ? iBar.GetDown() + : MathMin(mSameValeGoldenCount, iBar.GetDown()); + mSameValeCount++; + } + else + { + // + mSameValeCount = 0; + mSameValeGoldenCount = 0; + } + + // + // Cleanup Resources ... + + // + iBar.Clean(); + iPBar.Clean(); +} + +/** + * Validate Detected POI(s) ... + * + * @param barIndex: int, Specified Bar Index ... + * @param prevCalculated: int, Provides Previous Calculated Bars ... + * @param ratesTotal: int, Provides All Availabled Bars ... + * @param open: double Collection, Provides Open Prices Time Series ... + * @param high: double Collection, Provides High Prices Time Series ... + * @param close: double Collection, Provides Close Prices Time Series ... + * @param low: double Collection, Provides Low Prices Time Series ... + * @param tickVolume: long Collection, Provides Ticks Volume Prices Time Series ... + */ +void ValidatePOIs( + int barIndex, + const int prevCalculated, + const int ratesTotal, + const double &open[], + const double &high[], + const double &close[], + const double &low[], + const long &tickVolume[] // +) +{ + // + int count = 0; + bool has = false; + int barsLength = 3; + datetime to = GetBarTime( + _Symbol, + _Period, + barIndex // + ); + + // + // Liquidities ... + + // + // Bullish Liquidities ... + count = ArraySize(mBullishLiquidities); + has = IsValidSize(count); + if (has) + { + // + ValidateBoxes( + mBullishLiquidities, + barIndex, + barsLength // + ); + } + + // + // Bearish Liquidities ... + count = ArraySize(mBearishLiquidities); + has = IsValidSize(count); + if (has) + { + // + ValidateBoxes( + mBearishLiquidities, + barIndex, + barsLength // + ); + } + + // + // Range Breaks ... + + // + // Bullish ... + count = ArraySize(mBullishRangeBreakes); + has = IsValidSize(count); + if (has) + { + // + ValidateBoxes( + mBullishRangeBreakes, + barIndex, + barsLength // + ); + } + + // + // Bearish ... + count = ArraySize(mBearishRangeBreakes); + has = IsValidSize(count); + if (has) + { + // + ValidateBoxes( + mBearishRangeBreakes, + barIndex, + barsLength // + ); + } + + // +} + +/** + * Draw Detected POI(s) ... + * + * @param barIndex: int, Specified Bar Index ... + * @param prevCalculated: int, Provides Previous Calculated Bars ... + * @param ratesTotal: int, Provides All Availabled Bars ... + * @param open: double Collection, Provides Open Prices Time Series ... + * @param high: double Collection, Provides High Prices Time Series ... + * @param close: double Collection, Provides Close Prices Time Series ... + * @param low: double Collection, Provides Low Prices Time Series ... + * @param tickVolume: long Collection, Provides Ticks Volume Prices Time Series ... + */ +void DrawPOIs( + int barIndex, + const int prevCalculated, + const int ratesTotal, + const double &open[], + const double &high[], + const double &close[], + const double &low[], + const long &tickVolume[] // +) +{ + // + int count = 0; + XBoxZone iBox; + bool has = false; + datetime to = GetBarTime( + _Symbol, + _Period, + barIndex // + ); + + // + // Liquidities ... + if (mDrawLiquidities) + { + // + count = ArraySize(mBullishLiquidities); + has = IsValidSize(count); + if (has) + { + // + for (int i = 0; i < count; i++) + { + // + iBox = mBullishLiquidities[i]; + iBox.to = to; + + // + XCBoxObject *iObj; + has = mDrawer.DrawBox( + iBox, + iObj // + ); + if (has) + { + mObjects.Add(iObj); + } + + // + iBox.Clean(); + } + } + + // + count = ArraySize(mBearishLiquidities); + has = IsValidSize(count); + if (has) + { + // + for (int i = 0; i < count; i++) + { + // + iBox = mBearishLiquidities[i]; + iBox.to = to; + + // + XCBoxObject *iObj; + has = mDrawer.DrawBox( + iBox, + iObj // + ); + if (has) + { + mObjects.Add(iObj); + } + + // + iBox.Clean(); + } + } + } + + // + // Range Breaks ... + if (mDrawRangeBreakes) + { + // + // Bullish ... + count = ArraySize(mBullishRangeBreakes); + has = IsValidSize(count); + if (has) + { + // + for (int i = 0; i < count; i++) + { + // + iBox = mBullishRangeBreakes[i]; + iBox.to = to; + + // + XCBoxObject *iObj; + has = mDrawer.DrawBox( + iBox, + iObj // + ); + if (has) + { + // + XPOIStyle iStyle; + iStyle.width = 1; + iStyle.clr = clrAqua; + iStyle.style = STYLE_DOT; + + // + mDrawer.ApplyStyle( + iObj, + iStyle // + ); + + // + mObjects.Add(iObj); + } + + // + iBox.Clean(); + } + } + + // + // Bearish ... + count = ArraySize(mBearishRangeBreakes); + has = IsValidSize(count); + if (has) + { + // + for (int i = 0; i < count; i++) + { + // + iBox = mBearishRangeBreakes[i]; + iBox.to = to; + + // + XCBoxObject *iObj; + has = mDrawer.DrawBox( + iBox, + iObj // + ); + if (has) + { + // + XPOIStyle iStyle; + iStyle.width = 1; + iStyle.clr = clrMagenta; + iStyle.style = STYLE_DOT; + + // + mDrawer.ApplyStyle( + iObj, + iStyle // + ); + + // + mObjects.Add(iObj); + } + + // + iBox.Clean(); + } + } + } + + // +} + +/** + * Process Custom Analysing Senarios ... + * + * @param barIndex: int, Specified Bar Index ... + * @param prevCalculated: int, Provides Previous Calculated Bars ... + * @param ratesTotal: int, Provides All Availabled Bars ... + * @param open: double Collection, Provides Open Prices Time Series ... + * @param high: double Collection, Provides High Prices Time Series ... + * @param close: double Collection, Provides Close Prices Time Series ... + * @param low: double Collection, Provides Low Prices Time Series ... + * @param tickVolume: long Collection, Provides Ticks Volume Prices Time Series ... + */ +void DoProcess( + int barIndex, + const int prevCalculated, + const int ratesTotal, + const double &open[], + const double &high[], + const double &close[], + const double &low[], + const long &tickVolume[] // +) +{ + // + // Check Some Requirements ... + int lastBarIndex = barIndex + 1; + int maxBarIndex = startCalculationForLastBars > 0 + ? startCalculationForLastBars + : ratesTotal; + bool isFirstBar = + startCalculationForLastBars > 0 + ? barIndex == startCalculationForLastBars + : barIndex == firstBarIndex; + + // + // Recieve Bar ... + XOHCL iBar; + XOHCL iPBar; + bool has = iBar.Init( + _Symbol, + _Period, + barIndex + // + ); + has = + has && + iBar.GetPreviousBar(iPBar); + if (!has) + { + return; + } + + // + // Do Process ... + + // + // Detecting Trigger Bar ... + + // + bool hasSignal = false; + bool isBullish = false; + bool isBearish = false; + string namePrefix = NULL; + int triggerBarPushers = 0; + ENUM_X_DIRECTION triggerDir; + + // + // Detecting Trigger Bars ... + + // + bool isCond1Trigger = + mBarAnalyser + .IsValidForTrigger( + iPBar, + triggerDir, + true, // Cond 1 ... + false, // Cond 2 ... + false, // Cond 3 ... + false, // Cond 4 ... + false, // Cond 5 ... + false, // Cond 6 ... + false // Cond 7 ... + ); + bool isCond1BullishTrigger = + isCond1Trigger && + IsBullish(triggerDir); + bool isCond1BearishTrigger = + isCond1Trigger && + IsBearish(triggerDir); + if (isCond1Trigger) + { + // + triggerBarPushers++; + namePrefix += "Cond1"; + } + + // + bool isCond2Trigger = + mBarAnalyser + .IsValidForTrigger( + iPBar, + triggerDir, + false, // Cond 1 ... + true, // Cond 2 ... + false, // Cond 3 ... + false, // Cond 4 ... + false, // Cond 5 ... + false, // Cond 6 ... + false // Cond 7 ... + ); + bool isCond2BullishTrigger = + isCond2Trigger && + IsBullish(triggerDir); + bool isCond2BearishTrigger = + isCond2Trigger && + IsBearish(triggerDir); + if (isCond2Trigger) + { + // + triggerBarPushers++; + namePrefix += "Cond2"; + } + + // + bool isCond3Trigger = + mBarAnalyser + .IsValidForTrigger( + iPBar, + triggerDir, + false, // Cond 1 ... + false, // Cond 2 ... + true, // Cond 3 ... + false, // Cond 4 ... + false, // Cond 5 ... + false, // Cond 6 ... + false // Cond 7 ... + ); + bool isCond3BullishTrigger = + isCond3Trigger && + IsBullish(triggerDir); + bool isCond3BearishTrigger = + isCond3Trigger && + IsBearish(triggerDir); + if (isCond3Trigger) + { + // + triggerBarPushers++; + namePrefix += "Cond3"; + } + + // + bool isCond4Trigger = + mBarAnalyser + .IsValidForTrigger( + iPBar, + triggerDir, + false, // Cond 1 ... + false, // Cond 2 ... + false, // Cond 3 ... + true, // Cond 4 ... + false, // Cond 5 ... + false, // Cond 6 ... + false // Cond 7 ... + ); + bool isCond4BullishTrigger = + isCond4Trigger && + IsBullish(triggerDir); + bool isCond4BearishTrigger = + isCond4Trigger && + IsBearish(triggerDir); + if (isCond4Trigger) + { + // + triggerBarPushers++; + namePrefix += "Cond4"; + } + + // + bool isCond5Trigger = + mBarAnalyser + .IsValidForTrigger( + iPBar, + triggerDir, + false, // Cond 1 ... + false, // Cond 2 ... + false, // Cond 3 ... + false, // Cond 4 ... + true, // Cond 5 ... + false, // Cond 6 ... + false // Cond 7 ... + ); + bool isCond5BullishTrigger = + isCond5Trigger && + IsBullish(triggerDir); + bool isCond5BearishTrigger = + isCond5Trigger && + IsBearish(triggerDir); + if (isCond5Trigger) + { + // + triggerBarPushers++; + namePrefix += "Cond5"; + } + + // + bool isCond6Trigger = + mBarAnalyser + .IsValidForTrigger( + iPBar, + triggerDir, + false, // Cond 1 ... + false, // Cond 2 ... + false, // Cond 3 ... + false, // Cond 4 ... + false, // Cond 5 ... + true, // Cond 6 ... + false // Cond 7 ... + ); + bool isCond6BullishTrigger = + isCond6Trigger && + IsBullish(triggerDir); + bool isCond6BearishTrigger = + isCond6Trigger && + IsBearish(triggerDir); + if (isCond6Trigger) + { + // + triggerBarPushers++; + namePrefix += "Cond6"; + } + + // + bool isCond7Trigger = + mBarAnalyser + .IsValidForTrigger( + iPBar, + triggerDir, + false, // Cond 1 ... + false, // Cond 2 ... + false, // Cond 3 ... + false, // Cond 4 ... + false, // Cond 5 ... + false, // Cond 6 ... + true // Cond 7 ... + ); + bool isCond7BullishTrigger = + isCond7Trigger && + IsBullish(triggerDir); + bool isCond7BearishTrigger = + isCond7Trigger && + IsBearish(triggerDir); + if (isCond7Trigger) + { + // + triggerBarPushers++; + namePrefix += "Cond7"; + } + + // + // Summarizing Trigger Bars ... + + // + bool isBullishTriggerBar = + // + isCond1BullishTrigger || + isCond2BullishTrigger || + isCond3BullishTrigger || + isCond4BullishTrigger || + isCond5BullishTrigger || + isCond6BullishTrigger || + isCond7BullishTrigger + // + ; + + // + bool isBearishTriggerBar = + // + isCond1BearishTrigger || + isCond2BearishTrigger || + isCond3BearishTrigger || + isCond4BearishTrigger || + isCond5BearishTrigger || + isCond6BearishTrigger || + isCond7BearishTrigger + // + ; + + // + bool isTriggerBar = + // + triggerBarPushers >= 1 && + (isBullishTriggerBar || + isBearishTriggerBar) + // + ; + + // + // Reading Required Condiions ... + + // + int pIndex = barIndex + 1; + int ppIndex = barIndex + 2; + + // + // PV ... + + // + bool isSamePeak = peakBuffer[pIndex] == peakBuffer[ppIndex]; + bool isSameVale = valeBuffer[pIndex] == valeBuffer[ppIndex]; + + // + bool isPeakOverLast = peakBuffer[pIndex] > peakBuffer[ppIndex]; + bool isPeakUnderLast = peakBuffer[pIndex] < peakBuffer[ppIndex]; + + // + bool isValeOverLast = valeBuffer[pIndex] > valeBuffer[ppIndex]; + bool isValeUnderLast = valeBuffer[pIndex] < valeBuffer[ppIndex]; + + // + bool isSamePeakGolden = peakGoldenBuffer[pIndex] == peakGoldenBuffer[ppIndex]; + bool isSameValeGolden = valeGoldenBuffer[pIndex] == valeGoldenBuffer[ppIndex]; + + // + bool isPeakGoldeOverLast = peakGoldenBuffer[pIndex] > peakGoldenBuffer[ppIndex]; + bool isPeakGoldenUnderLast = peakGoldenBuffer[pIndex] < peakGoldenBuffer[ppIndex]; + + // + bool isValeGoldenOverLast = valeGoldenBuffer[pIndex] > valeGoldenBuffer[ppIndex]; + bool isValeGoldenUnderLast = valeGoldenBuffer[pIndex] < valeGoldenBuffer[ppIndex]; + + // + if (isSamePeak) + { + mSamePeakCount++; + } + else + { + mSamePeakCount = 0; + } + + // + if (isSameVale) + { + mSameValeCount++; + } + else + { + mSameValeCount = 0; + } + + // + if (isSamePeakGolden) + { + mSamePeakGoldenCount++; + } + else + { + mSamePeakGoldenCount = 0; + } + + // + if (isSameValeGolden) + { + mSameValeGoldenCount++; + } + else + { + mSameValeGoldenCount = 0; + } + + // + // SAR ... + + // + bool isSarBullish = sarStateBuffer[pIndex] > 0; + bool isPSarBullish = sarStateBuffer[ppIndex] > 0; + + // + bool isSarBearish = sarStateBuffer[pIndex] < 0; + bool isPSarBearish = sarStateBuffer[ppIndex] < 0; + + // + bool isSarSwitchedToBullish = + isSarBullish && + !isPSarBullish; + + // + bool isSarSwitchedToBearish = + isSarBearish && + !isPSarBearish; + + // + // HKS ... + + // + bool isHKSBullish = hkSBarCloseBuffer[pIndex] > hkSBarOpenBuffer[pIndex]; + bool isPHKSBullish = hkSBarCloseBuffer[ppIndex] > hkSBarOpenBuffer[ppIndex]; + + // + bool isHKSBearish = hkSBarCloseBuffer[pIndex] < hkSBarOpenBuffer[pIndex]; + bool isPHKSBearish = hkSBarCloseBuffer[ppIndex] < hkSBarOpenBuffer[ppIndex]; + + // + bool isHKSSwitchedToBullish = + isHKSBullish && + !isPHKSBullish; + + // + bool isHKSSwitchedToBearish = + isHKSBearish && + !isPHKSBearish; + + // + // SB ... + + // + bool isSBullish = sBarCloseBuffer[pIndex] > sBarOpenBuffer[pIndex]; + bool isPSBullish = sBarCloseBuffer[ppIndex] > sBarOpenBuffer[ppIndex]; + + // + bool isSBearish = sBarCloseBuffer[pIndex] < sBarOpenBuffer[pIndex]; + bool isPSBearish = sBarCloseBuffer[ppIndex] < sBarOpenBuffer[ppIndex]; + + // + bool isSSwitchedToBullish = + isSBullish && + !isPSBullish; + + // + bool isSSwitchedToBearish = + isSBearish && + !isPSBearish; + + // + // KI ... + + // + bool isKIBullish = kiStateBuffer[pIndex] > 0; + bool isPKIBullish = kiStateBuffer[ppIndex] > 0; + + // + bool isKIBearish = kiStateBuffer[pIndex] < 0; + bool isPKIBearish = kiStateBuffer[ppIndex] < 0; + + // + bool isKISwitchedToBullish = + isKIBullish && + !isPKIBullish; + + // + bool isKISwitchedToBearish = + isKIBearish && + !isPKIBearish; + + // + bool isKIBullishBreaked = + iPBar.IsBreaked( + kiBuffer[pIndex], + X_DIRECTION_BULLISH, + X_FIBO_LEVEL_500, + X_BOUNDARY_PRICE_UP_DOWN // + ); + + // + bool isKIBearishBreaked = + iPBar.IsBreaked( + kiBuffer[pIndex], + X_DIRECTION_BEARISH, + X_FIBO_LEVEL_500, + X_BOUNDARY_PRICE_UP_DOWN // + ); + + // + bool isKISame = kiBuffer[pIndex] == kiBuffer[ppIndex]; + bool isKIBullishSame = + isKISame && + isKIBullish; + bool isKIBearishSame = + isKISame && + isKIBearish; + + // + if (isKISame) + { + mSameKICount++; + } + else + { + mSameKICount = 0; + } + + // + if (isKIBullishSame) + { + mSameKIBullishCount++; + } + else + { + mSameKIBullishCount = 0; + } + + // + if (isKIBearishSame) + { + mSameKIBearishCount++; + } + else + { + mSameKIBearishCount = 0; + } + + // + // Validating Trigger Bar based on Conditions ... + if (isTriggerBar) + { + // + // TODO: Remove this if required ... + isTriggerBar = false; + isBullishTriggerBar = false; + isBearishTriggerBar = false; + } + + // + // Detecting Signal ... + + // + // Bullish ... + isBullish = + // + // Conditions Validation ... + isKIBullishBreaked + // isSSwitchedToBullish + // isKISwitchedToBullish + // isSarSwitchedToBullish + // isHKSSwitchedToBullish + // + // Bar Validation ... + // + ; + + // + // Bearish ... + isBearish = + // + // Conditions Validation ... + isKIBearishBreaked + // isSSwitchedToBearish + // isKISwitchedToBearish + // isSarSwitchedToBearish + // isHKSSwitchedToBearish + // + // Bar Validation ... + // + ; + + // + // Summarizing Signal ... + hasSignal = + isBullish || + isBearish; + + // + // Draw Requirements ... + + // + // Draw Trigger Bar ... + if (isTriggerBar) + { + // + int triggerBullishArrowCode = 225; + int triggerBearishArrowCode = 226; + + // + color triggerBarBullishColor = clrLime; + color triggerBarBearishColor = clrRed; + + // + ENUM_ARROW_ANCHOR triggerBullishAnchor = ANCHOR_TOP; + ENUM_ARROW_ANCHOR triggerBearishAnchor = ANCHOR_BOTTOM; + + // + int arrowWidth = 3; + int arrowCode = + isBullishTriggerBar + ? triggerBullishArrowCode + : triggerBearishArrowCode; + ENUM_X_PRICE arrowPriceType = + isBullishTriggerBar + ? X_PRICE_LOW + : X_PRICE_HIGH; + color arrowColor = + isBullishTriggerBar + ? triggerBarBullishColor + : triggerBarBearishColor; + ENUM_ARROW_ANCHOR arrowAnchor = + isBullishTriggerBar + ? triggerBullishAnchor + : triggerBearishAnchor; + + // + 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 = "XTRB"; + iBox.to = iBar.time; + iBox.symbol = _Symbol; + iBox.period = _Period; + iBox.lower = iPBar.low; + iBox.from = iPBar.time; + iBox.upper = iPBar.high; + iBox.dir = + isBullishTriggerBar + ? X_DIRECTION_BULLISH + : X_DIRECTION_BEARISH; + if (iBox.IsValid()) + { + // + // XCBoxObject *iObj; + // has = mDrawer.DrawBox( + // iBox, + // iObj // + // ); + // if (has) + // { + // mObjects.Add(iObj); + // } + + // + 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); + } + } + } + + // + } + + // + // 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 ... + + // + iBar.Clean(); + iPBar.Clean(); +} + +//////////////////////////////////////////////////////////////////// + diff --git a/Indicators/x-saherelm.x121.xcatb.v1.mq5 b/Indicators/x-saherelm.x121.xcatb.v1.mq5 index 2ba3a73c..167b8097 100644 --- a/Indicators/x-saherelm.x121.xcatb.v1.mq5 +++ b/Indicators/x-saherelm.x121.xcatb.v1.mq5 @@ -642,31 +642,175 @@ XCPOIDrawer *mDrawer; XCBarAnalyser *mBarAnalyser; // -int sameKICount = 0; -int sameKIBullishCount = 0; -int sameKIBearishCount = 0; +// Conditions Variables ... // -int mSamePeakCount = 0; -int mSameValeCount = 0; +// Temparory ... +ENUM_X_DIRECTION mDir; +bool mHasSignal = false; +bool mIsBullish = false; +bool mIsBearish = false; +string mTriggerBarConditions; // -double mSamePeakGolden = 0; -double mSameValeGolden = 0; +// Trigger Bars Conditions ... // -bool mDrawLiquidities = false; -bool mDrawRangeBreakes = false; +bool isTriggerBarCond1 = false; +bool isTriggerBarCond1Bullish = false; +bool isTriggerBarCond1Bearish = false; // -bool mDetectLiquidities = true; -bool mDetectRangeBreakes = true; +bool isTriggerBarCond2 = false; +bool isTriggerBarCond2Bullish = false; +bool isTriggerBarCond2Bearish = false; // -XBoxZone mBullishLiquidities[]; -XBoxZone mBearishLiquidities[]; -XBoxZone mBullishRangeBreakes[]; -XBoxZone mBearishRangeBreakes[]; +bool isTriggerBarCond3 = false; +bool isTriggerBarCond3Bullish = false; +bool isTriggerBarCond3Bearish = false; + +// +bool isTriggerBarCond4 = false; +bool isTriggerBarCond4Bullish = false; +bool isTriggerBarCond4Bearish = false; + +// +bool isTriggerBarCond5 = false; +bool isTriggerBarCond5Bullish = false; +bool isTriggerBarCond5Bearish = false; + +// +bool isTriggerBarCond6 = false; +bool isTriggerBarCond6Bullish = false; +bool isTriggerBarCond6Bearish = false; + +// +bool isTriggerBarCond7 = false; +bool isTriggerBarCond7Bullish = false; +bool isTriggerBarCond7Bearish = false; + +// +// Summarizing Trigger Bar ... +bool isTriggerBar = false; +bool isTriggerBarBullish = false; +bool isTriggerBarBearish = false; + +// +// XPV ... + +// +bool isSamePeak = false; +bool isSamePeakP = false; + +// +bool isSameVale = false; +bool isSameValeP = false; + +// +bool isPeakOverLast = false; +bool isPeakUnderLast = false; + +// +bool isValeOverLast = false; +bool isValeUnderLast = false; + +// +bool isSamePeakGolden = false; +bool isSamePeakGoldenP = false; + +// +bool isSameValeGolden = false; +bool isSameValeGoldenP = false; + +// +bool isPeakGoldenOverLast = false; +bool isPeakGoldenUnderLast = false; + +// +bool isValeGoldenOverLast = false; +bool isValeGoldenUnderLast = false; + +// +// XSAR ... + +// +bool isSarBullish = false; +bool isSarBullishP = false; + +// +bool isSarBearish = false; +bool isSarBearishP = false; + +// +bool isSarSwitchedToBullish = false; +bool isSarSwitchedToBearish = false; + +// +bool isBullishSarBreakedLast = false; +bool isBearishSarBreakedLast = false; + +// +// XSB ... + +// +bool isSBBullish = false; +bool isSBBullishP = false; + +// +bool isSBBearish = false; +bool isSBBearishP = false; + +// +bool isSBSwitchedToBullish = false; +bool isSBSwitchedToBearish = false; + +// +bool isBullishSBBreakedLast = false; +bool isBearishSBBreakedLast = false; + +// +// XHKS ... + +// +bool isHKSBullish = false; +bool isHKSBullishP = false; + +// +bool isHKSBearish = false; +bool isHKSBearishP = false; + +// +bool isHKSSwitchedToBullish = false; +bool isHKSSwitchedToBearish = false; + +// +bool isBullishHKSBreakedLast = false; +bool isBearishHKSBreakedLast = false; + +// +// XKI ... + +// +bool isKIBullish = false; +bool isKIBullishP = false; + +// +bool isKIBearish = false; +bool isKIBearishP = false; + +// +bool isKISame = false; +bool isBullishKISame = false; +bool isBearishKISame = false; + +// +bool isKISwitchedToBullish = false; +bool isKISwitchedToBearish = false; + +// +bool isBullishKIBreakedLast = false; +bool isBearishKIBreakedLast = false; // // Event Handlers ... @@ -1970,35 +2114,48 @@ void CalculateValues( // // Handling POI(s) ... - // - // Detecting POI(s) ... - DetectPOIs( - barIndex, - prevCalculated, - ratesTotal, - open, - high, - close, - low, - tickVolume // - ); + // // + // // Detecting POI(s) ... + // DetectPOIs( + // barIndex, + // prevCalculated, + // ratesTotal, + // open, + // high, + // close, + // low, + // tickVolume // + // ); + + // // + // // Validating ... + // ValidatePOIs( + // barIndex, + // prevCalculated, + // ratesTotal, + // open, + // high, + // close, + // low, + // tickVolume // + // ); + + // // + // // Drawing ... + // DrawPOIs( + // barIndex, + // prevCalculated, + // ratesTotal, + // open, + // high, + // close, + // low, + // tickVolume // + // ); // - // Validating ... - ValidatePOIs( - barIndex, - prevCalculated, - ratesTotal, - open, - high, - close, - low, - tickVolume // - ); - - // - // Drawing ... - DrawPOIs( + // Prepare Market Conditions ... + PrepareMarketConditions( barIndex, prevCalculated, ratesTotal, @@ -2937,11 +3094,11 @@ void HideBars() } // -// POI(s) Handlers ... +// Process Handlers ... // /** - * Detect POI(s) ... + * Prepare Market Conditions ... * * @param barIndex: int, Specified Bar Index ... * @param prevCalculated: int, Provides Previous Calculated Bars ... @@ -2952,7 +3109,7 @@ void HideBars() * @param low: double Collection, Provides Low Prices Time Series ... * @param tickVolume: long Collection, Provides Ticks Volume Prices Time Series ... */ -void DetectPOIs( +void PrepareMarketConditions( int barIndex, const int prevCalculated, const int ratesTotal, @@ -2974,14 +3131,6 @@ void DetectPOIs( ? barIndex == startCalculationForLastBars : barIndex == firstBarIndex; - // - // Handle Minimum Required Bars ... - bool isPassedRequiredBars = barIndex < maxBarIndex - 3; - if (!isPassedRequiredBars) - { - return; - } - // // Recieve Bar ... XOHCL iBar; @@ -3001,317 +3150,327 @@ void DetectPOIs( } // - bool isBullish = false; - bool isBearish = false; - int maxAllowedPOIs = 50; + int cIndex = barIndex; + int pIndex = barIndex + 1; + int p2Index = barIndex + 2; + int p3Index = barIndex + 3; // - ENUM_X_DIRECTION iDir; - - // - // Detecting Liquidity ... - if (mDetectLiquidities) + // Check Required Bars Passed ... + has = p3Index <= maxBarIndex; + if (!has) { - // - bool isLiquidity = - mBarAnalyser - .IsRejected( - iBar, - iDir, - true, - true // - ); - bool isBullishLiquiditySweeped = - isLiquidity && - IsBullish(iDir); - bool isBearishLiquiditySweeped = - isLiquidity && - IsBearish(iDir); - if (isLiquidity) - { - // - XBoxZone iLiq; - - // - iLiq.dir = iDir; - iLiq.type = "XLIQ"; - iLiq.upper = - isBullishLiquiditySweeped - ? iBar.GetDown() - : iBar.high; - iLiq.lower = - isBullishLiquiditySweeped - ? iBar.low - : iBar.GetUp(); - iLiq.at = iBar.time; - iLiq.from = iBar.time; - iLiq.symbol = _Symbol; - iLiq.period = _Period; - iLiq.to = ((datetime)((int)iBar.time + (PeriodSeconds(_Period)))); - - // - if (iLiq.IsValid()) - { - // - if (isBullishLiquiditySweeped) - { - // - has = AddBoxIfNotExists( - iLiq, - mBullishLiquidities // - ); - if (has) - { - // - SortBoxes( - mBullishLiquidities, - maxAllowedPOIs // - ); - } - } - else - { - // - has = AddBoxIfNotExists( - iLiq, - mBearishLiquidities // - ); - if (has) - { - // - SortBoxes( - mBearishLiquidities, - maxAllowedPOIs // - ); - } - } - } - - // - iLiq.Clean(); - } + return; } // - // Detecting Bullish and Bearish Breakes ... + // Start Preparing Conditions ... // - bool isPeakSame = peakBuffer[barIndex] == peakBuffer[barIndex + 1]; - bool isPPeakSame = peakBuffer[barIndex + 1] == peakBuffer[barIndex + 2]; + // Trigger Bars Conditions ... // - bool isPeakOverLast = peakBuffer[barIndex] > peakBuffer[barIndex + 1]; - bool isPPeakOverLast = peakBuffer[barIndex + 1] > peakBuffer[barIndex + 2]; - - // - bool isPeakUnderLast = peakBuffer[barIndex] < peakBuffer[barIndex + 1]; - bool isPPeakUnderLast = peakBuffer[barIndex + 1] < peakBuffer[barIndex + 2]; - - // - bool isSamePeakOverLast = - isPPeakSame && - isPeakOverLast; - bool isSamePeakUnderLast = - isPPeakSame && - isPeakUnderLast; - - // - bool isValeSame = valeBuffer[barIndex] == valeBuffer[barIndex + 1]; - bool isPValeSame = valeBuffer[barIndex + 1] == valeBuffer[barIndex + 2]; - - // - bool isValeOverLast = valeBuffer[barIndex] > valeBuffer[barIndex + 1]; - bool isPValeOverLast = valeBuffer[barIndex + 1] > valeBuffer[barIndex + 2]; - - // - bool isValeUnderLast = valeBuffer[barIndex] < valeBuffer[barIndex + 1]; - bool isPValeUnderLast = valeBuffer[barIndex + 1] < valeBuffer[barIndex + 2]; - - // - bool isSameValeOverLast = - isPValeSame && - isValeOverLast; - bool isSameValeUnderLast = - isPValeSame && - isValeUnderLast; - - // - // Detecting Range Breakes ... - if (mDetectRangeBreakes) - { - // - isBullish = isSamePeakOverLast - // || isSameValeOverLast - ; - isBearish = - isSameValeUnderLast - // || isSamePeakUnderLast - ; - - // - bool basedOnPeak = - isSamePeakOverLast - // || isSamePeakUnderLast - ; - - // - bool basedOnVale = - isSameValeUnderLast - // isSameValeOverLast || - ; - - // - has = isBullish || - isBearish; - - // - if (has) - { - // - XBoxZone iRNGBreak; - - // - iDir = - isBullish - ? X_DIRECTION_BULLISH - : isBearish - ? X_DIRECTION_BEARISH - : X_DIRECTION_NONE; - - // - iRNGBreak.dir = iDir; - iRNGBreak.at = iBar.time; - iRNGBreak.type = "XRNGB"; - iRNGBreak.to = iBar.time; - iRNGBreak.symbol = _Symbol; - iRNGBreak.period = _Period; - - // - int fromIDX = - iBar.Index() + - (basedOnPeak - ? mSamePeakCount - : basedOnVale - ? mSameValeCount - : 0); - datetime from = GetBarTime( - _Symbol, - _Period, - fromIDX // + // Cond 1 ... + isTriggerBarCond1 = + mBarAnalyser + .IsValidForTrigger( + iPBar, + triggerDir, + true, // Cond 1 ... + false, // Cond 2 ... + false, // Cond 3 ... + false, // Cond 4 ... + false, // Cond 5 ... + false, // Cond 6 ... + false // Cond 7 ... ); - iRNGBreak.from = from; - - // - double upper = - isBullish - ? basedOnPeak - ? peakBuffer[barIndex] - : basedOnVale - ? mSameValeGolden - : 0 - : isBearish - ? basedOnPeak - ? peakBuffer[barIndex] - : basedOnVale - ? mSameValeGolden - : 0 - : 0; - - // - double lower = - isBullish - ? basedOnPeak - ? mSamePeakGolden - : basedOnVale - ? valeBuffer[barIndex] - : 0 - : isBearish - ? basedOnPeak - ? mSamePeakGolden - : basedOnVale - ? valeBuffer[barIndex] - : 0 - : 0; - - // - iRNGBreak.upper = upper; - iRNGBreak.lower = lower; - - // - // Adding POI ... - has = iRNGBreak.IsValid(); - if (has) - { - // - if (isBullish) - { - // - has = AddBoxIfNotExists( - iRNGBreak, - mBullishRangeBreakes // - ); - if (has) - { - // - SortBoxes( - mBullishRangeBreakes, - maxAllowedPOIs // - ); - } - } - else if (isBearish) - { - // - has = AddBoxIfNotExists( - iRNGBreak, - mBearishRangeBreakes // - ); - if (has) - { - // - SortBoxes( - mBearishRangeBreakes, - maxAllowedPOIs // - ); - } - } - } - } - } + isTriggerBarCond1Bullish = + isTriggerBarCond1 && + IsBullish(mDir); + isTriggerBarCond1Bearish = + isTriggerBarCond1 && + IsBearish(mDir); // - if (isPeakSame) - { - // - mSamePeakGolden = - mSamePeakGolden == 0 - ? iBar.GetUp() - : MathMax(mSamePeakGolden, iBar.GetUp()); - mSamePeakCount++; - } - else - { - // - mSamePeakCount = 0; - mSamePeakGolden = 0; - } + // Cond 2 ... + isTriggerBarCond2 = + mBarAnalyser + .IsValidForTrigger( + iPBar, + triggerDir, + false, // Cond 1 ... + true, // Cond 2 ... + false, // Cond 3 ... + false, // Cond 4 ... + false, // Cond 5 ... + false, // Cond 6 ... + false // Cond 7 ... + ); + isTriggerBarCond2Bullish = + isTriggerBarCond2 && + IsBullish(mDir); + isTriggerBarCond2Bearish = + isTriggerBarCond2 && + IsBearish(mDir); // - if (isValeSame) - { - // - mSameValeGolden = - mSameValeGolden == 0 - ? iBar.GetDown() - : MathMin(mSameValeGolden, iBar.GetDown()); - mSameValeCount++; - } - else - { - // - mSameValeCount = 0; - mSameValeGolden = 0; - } + // Cond 3 ... + isTriggerBarCond3 = + mBarAnalyser + .IsValidForTrigger( + iPBar, + triggerDir, + false, // Cond 1 ... + false, // Cond 2 ... + true, // Cond 3 ... + false, // Cond 4 ... + false, // Cond 5 ... + false, // Cond 6 ... + false // Cond 7 ... + ); + isTriggerBarCond3Bullish = + isTriggerBarCond3 && + IsBullish(mDir); + isTriggerBarCond3Bearish = + isTriggerBarCond3 && + IsBearish(mDir); + + // + // Cond 4 ... + isTriggerBarCond4 = + mBarAnalyser + .IsValidForTrigger( + iPBar, + triggerDir, + false, // Cond 1 ... + false, // Cond 2 ... + false, // Cond 3 ... + true, // Cond 4 ... + false, // Cond 5 ... + false, // Cond 6 ... + false // Cond 7 ... + ); + isTriggerBarCond4Bullish = + isTriggerBarCond4 && + IsBullish(mDir); + isTriggerBarCond4Bearish = + isTriggerBarCond4 && + IsBearish(mDir); + + // + // Cond 5 ... + isTriggerBarCond5 = + mBarAnalyser + .IsValidForTrigger( + iPBar, + triggerDir, + false, // Cond 1 ... + false, // Cond 2 ... + false, // Cond 3 ... + false, // Cond 4 ... + true, // Cond 5 ... + false, // Cond 6 ... + false // Cond 7 ... + ); + isTriggerBarCond5Bullish = + isTriggerBarCond5 && + IsBullish(mDir); + isTriggerBarCond5Bearish = + isTriggerBarCond5 && + IsBearish(mDir); + + // + // Cond 6 ... + isTriggerBarCond6 = + mBarAnalyser + .IsValidForTrigger( + iPBar, + triggerDir, + false, // Cond 1 ... + false, // Cond 2 ... + false, // Cond 3 ... + false, // Cond 4 ... + false, // Cond 5 ... + true, // Cond 6 ... + false // Cond 7 ... + ); + isTriggerBarCond6Bullish = + isTriggerBarCond6 && + IsBullish(mDir); + isTriggerBarCond6Bearish = + isTriggerBarCond6 && + IsBearish(mDir); + + // + // Cond 7 ... + isTriggerBarCond7 = + mBarAnalyser + .IsValidForTrigger( + iPBar, + triggerDir, + false, // Cond 1 ... + false, // Cond 2 ... + false, // Cond 3 ... + false, // Cond 4 ... + false, // Cond 5 ... + false, // Cond 6 ... + true // Cond 7 ... + ); + isTriggerBarCond7Bullish = + isTriggerBarCond7 && + IsBullish(mDir); + isTriggerBarCond7Bearish = + isTriggerBarCond7 && + IsBearish(mDir); + + // + // Summarizing Trigger Bar ... + + // + isTriggerBar = + isTriggerBarCond1 || + isTriggerBarCond2 || + isTriggerBarCond3 || + isTriggerBarCond4 || + isTriggerBarCond5 || + isTriggerBarCond6 || + isTriggerBarCond7; + + // + isTriggerBarBullish = + isTriggerBarCond1Bullish || + isTriggerBarCond2Bullish || + isTriggerBarCond3Bullish || + isTriggerBarCond4Bullish || + isTriggerBarCond5Bullish || + isTriggerBarCond6Bullish || + isTriggerBarCond7Bullish; + + // + isTriggerBarBearish = + isTriggerBarCond1Bearish || + isTriggerBarCond2Bearish || + isTriggerBarCond3Bearish || + isTriggerBarCond4Bearish || + isTriggerBarCond5Bearish || + isTriggerBarCond6Bearish || + isTriggerBarCond7Bearish; + + // + // XPV ... + + // + isSamePeak = false; + isSamePeakP = false; + + // + isSameVale = false; + isSameValeP = false; + + // + isPeakOverLast = false; + isPeakUnderLast = false; + + // + isValeOverLast = false; + isValeUnderLast = false; + + // + isSamePeakGolden = false; + isSamePeakGoldenP = false; + + // + isSameValeGolden = false; + isSameValeGoldenP = false; + + // + isPeakGoldenOverLast = false; + isPeakGoldenUnderLast = false; + + // + isValeGoldenOverLast = false; + isValeGoldenUnderLast = false; + + // + // XSAR ... + + // + isSarBullish = false; + isSarBullishP = false; + + // + isSarBearish = false; + isSarBearishP = false; + + // + isSarSwitchedToBullish = false; + isSarSwitchedToBearish = false; + + // + isBullishSarBreakedLast = false; + isBearishSarBreakedLast = false; + + // + // XSB ... + + // + isSBBullish = false; + isSBBullishP = false; + + // + isSBBearish = false; + isSBBearishP = false; + + // + isSBSwitchedToBullish = false; + isSBSwitchedToBearish = false; + + // + isBullishSBBreakedLast = false; + isBearishSBBreakedLast = false; + + // + // XHKS ... + + // + isHKSBullish = false; + isHKSBullishP = false; + + // + isHKSBearish = false; + isHKSBearishP = false; + + // + isHKSSwitchedToBullish = false; + isHKSSwitchedToBearish = false; + + // + isBullishHKSBreakedLast = false; + isBearishHKSBreakedLast = false; + + // + // XKI ... + + // + isKIBullish = false; + isKIBullishP = false; + + // + isKIBearish = false; + isKIBearishP = false; + + // + isKISame = false; + isBullishKISame = false; + isBearishKISame = false; + + // + isKISwitchedToBullish = false; + isKISwitchedToBearish = false; + + // + isBullishKIBreakedLast = false; + isBearishKIBreakedLast = false; // // Cleanup Resources ... @@ -3321,294 +3480,6 @@ void DetectPOIs( iPBar.Clean(); } -/** - * Validate Detected POI(s) ... - * - * @param barIndex: int, Specified Bar Index ... - * @param prevCalculated: int, Provides Previous Calculated Bars ... - * @param ratesTotal: int, Provides All Availabled Bars ... - * @param open: double Collection, Provides Open Prices Time Series ... - * @param high: double Collection, Provides High Prices Time Series ... - * @param close: double Collection, Provides Close Prices Time Series ... - * @param low: double Collection, Provides Low Prices Time Series ... - * @param tickVolume: long Collection, Provides Ticks Volume Prices Time Series ... - */ -void ValidatePOIs( - int barIndex, - const int prevCalculated, - const int ratesTotal, - const double &open[], - const double &high[], - const double &close[], - const double &low[], - const long &tickVolume[] // -) -{ - // - int count = 0; - bool has = false; - int barsLength = 3; - datetime to = GetBarTime( - _Symbol, - _Period, - barIndex // - ); - - // - // Liquidities ... - - // - // Bullish Liquidities ... - count = ArraySize(mBullishLiquidities); - has = IsValidSize(count); - if (has) - { - // - ValidateBoxes( - mBullishLiquidities, - barIndex, - barsLength // - ); - } - - // - // Bearish Liquidities ... - count = ArraySize(mBearishLiquidities); - has = IsValidSize(count); - if (has) - { - // - ValidateBoxes( - mBearishLiquidities, - barIndex, - barsLength // - ); - } - - // - // Range Breaks ... - - // - // Bullish ... - count = ArraySize(mBullishRangeBreakes); - has = IsValidSize(count); - if (has) - { - // - ValidateBoxes( - mBullishRangeBreakes, - barIndex, - barsLength // - ); - } - - // - // Bearish ... - count = ArraySize(mBearishRangeBreakes); - has = IsValidSize(count); - if (has) - { - // - ValidateBoxes( - mBearishRangeBreakes, - barIndex, - barsLength // - ); - } - - // -} - -/** - * Draw Detected POI(s) ... - * - * @param barIndex: int, Specified Bar Index ... - * @param prevCalculated: int, Provides Previous Calculated Bars ... - * @param ratesTotal: int, Provides All Availabled Bars ... - * @param open: double Collection, Provides Open Prices Time Series ... - * @param high: double Collection, Provides High Prices Time Series ... - * @param close: double Collection, Provides Close Prices Time Series ... - * @param low: double Collection, Provides Low Prices Time Series ... - * @param tickVolume: long Collection, Provides Ticks Volume Prices Time Series ... - */ -void DrawPOIs( - int barIndex, - const int prevCalculated, - const int ratesTotal, - const double &open[], - const double &high[], - const double &close[], - const double &low[], - const long &tickVolume[] // -) -{ - // - int count = 0; - XBoxZone iBox; - bool has = false; - datetime to = GetBarTime( - _Symbol, - _Period, - barIndex // - ); - - // - // Liquidities ... - if (mDrawLiquidities) - { - // - count = ArraySize(mBullishLiquidities); - has = IsValidSize(count); - if (has) - { - // - for (int i = 0; i < count; i++) - { - // - iBox = mBullishLiquidities[i]; - iBox.to = to; - - // - XCBoxObject *iObj; - has = mDrawer.DrawBox( - iBox, - iObj // - ); - if (has) - { - mObjects.Add(iObj); - } - - // - iBox.Clean(); - } - } - - // - count = ArraySize(mBearishLiquidities); - has = IsValidSize(count); - if (has) - { - // - for (int i = 0; i < count; i++) - { - // - iBox = mBearishLiquidities[i]; - iBox.to = to; - - // - XCBoxObject *iObj; - has = mDrawer.DrawBox( - iBox, - iObj // - ); - if (has) - { - mObjects.Add(iObj); - } - - // - iBox.Clean(); - } - } - } - - // - // Range Breaks ... - if (mDrawRangeBreakes) - { - // - // Bullish ... - count = ArraySize(mBullishRangeBreakes); - has = IsValidSize(count); - if (has) - { - // - for (int i = 0; i < count; i++) - { - // - iBox = mBullishRangeBreakes[i]; - iBox.to = to; - - // - XCBoxObject *iObj; - has = mDrawer.DrawBox( - iBox, - iObj // - ); - if (has) - { - // - XPOIStyle iStyle; - iStyle.width = 1; - iStyle.clr = clrAqua; - iStyle.style = STYLE_DOT; - - // - mDrawer.ApplyStyle( - iObj, - iStyle // - ); - - // - mObjects.Add(iObj); - } - - // - iBox.Clean(); - } - } - - // - // Bearish ... - count = ArraySize(mBearishRangeBreakes); - has = IsValidSize(count); - if (has) - { - // - for (int i = 0; i < count; i++) - { - // - iBox = mBearishRangeBreakes[i]; - iBox.to = to; - - // - XCBoxObject *iObj; - has = mDrawer.DrawBox( - iBox, - iObj // - ); - if (has) - { - // - XPOIStyle iStyle; - iStyle.width = 1; - iStyle.clr = clrMagenta; - iStyle.style = STYLE_DOT; - - // - mDrawer.ApplyStyle( - iObj, - iStyle // - ); - - // - mObjects.Add(iObj); - } - - // - iBox.Clean(); - } - } - } - - // -} - -// -// Process Handlers ... -// - /** * Process Custom Analysing Senarios ... * @@ -3632,695 +3503,6 @@ void DoProcess( const long &tickVolume[] // ) { - // - // Check Some Requirements ... - int lastBarIndex = barIndex + 1; - int maxBarIndex = startCalculationForLastBars > 0 - ? startCalculationForLastBars - : ratesTotal; - bool isFirstBar = - startCalculationForLastBars > 0 - ? barIndex == startCalculationForLastBars - : barIndex == firstBarIndex; - - // - // Recieve Bar ... - XOHCL iBar; - XOHCL iPBar; - bool has = iBar.Init( - _Symbol, - _Period, - barIndex - // - ); - has = - has && - iBar.GetPreviousBar(iPBar); - if (!has) - { - return; - } - - // - // Do Process ... - - // - // Detecting Trigger Bar ... - - // - bool hasSignal = false; - bool isBullish = false; - bool isBearish = false; - string namePrefix = NULL; - int triggerBarPushers = 0; - ENUM_X_DIRECTION triggerDir; - - // - // Detecting Trigger Bars ... - - // - bool isCond1Trigger = - mBarAnalyser - .IsValidForTrigger( - iPBar, - triggerDir, - true, // Cond 1 ... - false, // Cond 2 ... - false, // Cond 3 ... - false, // Cond 4 ... - false, // Cond 5 ... - false, // Cond 6 ... - false // Cond 7 ... - ); - bool isCond1BullishTrigger = - isCond1Trigger && - IsBullish(triggerDir); - bool isCond1BearishTrigger = - isCond1Trigger && - IsBearish(triggerDir); - if (isCond1Trigger) - { - // - triggerBarPushers++; - namePrefix += "Cond1"; - } - - // - bool isCond2Trigger = - mBarAnalyser - .IsValidForTrigger( - iPBar, - triggerDir, - false, // Cond 1 ... - true, // Cond 2 ... - false, // Cond 3 ... - false, // Cond 4 ... - false, // Cond 5 ... - false, // Cond 6 ... - false // Cond 7 ... - ); - bool isCond2BullishTrigger = - isCond2Trigger && - IsBullish(triggerDir); - bool isCond2BearishTrigger = - isCond2Trigger && - IsBearish(triggerDir); - if (isCond2Trigger) - { - // - triggerBarPushers++; - namePrefix += "Cond2"; - } - - // - bool isCond3Trigger = - mBarAnalyser - .IsValidForTrigger( - iPBar, - triggerDir, - false, // Cond 1 ... - false, // Cond 2 ... - true, // Cond 3 ... - false, // Cond 4 ... - false, // Cond 5 ... - false, // Cond 6 ... - false // Cond 7 ... - ); - bool isCond3BullishTrigger = - isCond3Trigger && - IsBullish(triggerDir); - bool isCond3BearishTrigger = - isCond3Trigger && - IsBearish(triggerDir); - if (isCond3Trigger) - { - // - triggerBarPushers++; - namePrefix += "Cond3"; - } - - // - bool isCond4Trigger = - mBarAnalyser - .IsValidForTrigger( - iPBar, - triggerDir, - false, // Cond 1 ... - false, // Cond 2 ... - false, // Cond 3 ... - true, // Cond 4 ... - false, // Cond 5 ... - false, // Cond 6 ... - false // Cond 7 ... - ); - bool isCond4BullishTrigger = - isCond4Trigger && - IsBullish(triggerDir); - bool isCond4BearishTrigger = - isCond4Trigger && - IsBearish(triggerDir); - if (isCond4Trigger) - { - // - triggerBarPushers++; - namePrefix += "Cond4"; - } - - // - bool isCond5Trigger = - mBarAnalyser - .IsValidForTrigger( - iPBar, - triggerDir, - false, // Cond 1 ... - false, // Cond 2 ... - false, // Cond 3 ... - false, // Cond 4 ... - true, // Cond 5 ... - false, // Cond 6 ... - false // Cond 7 ... - ); - bool isCond5BullishTrigger = - isCond5Trigger && - IsBullish(triggerDir); - bool isCond5BearishTrigger = - isCond5Trigger && - IsBearish(triggerDir); - if (isCond5Trigger) - { - // - triggerBarPushers++; - namePrefix += "Cond5"; - } - - // - bool isCond6Trigger = - mBarAnalyser - .IsValidForTrigger( - iPBar, - triggerDir, - false, // Cond 1 ... - false, // Cond 2 ... - false, // Cond 3 ... - false, // Cond 4 ... - false, // Cond 5 ... - true, // Cond 6 ... - false // Cond 7 ... - ); - bool isCond6BullishTrigger = - isCond6Trigger && - IsBullish(triggerDir); - bool isCond6BearishTrigger = - isCond6Trigger && - IsBearish(triggerDir); - if (isCond6Trigger) - { - // - triggerBarPushers++; - namePrefix += "Cond6"; - } - - // - bool isCond7Trigger = - mBarAnalyser - .IsValidForTrigger( - iPBar, - triggerDir, - false, // Cond 1 ... - false, // Cond 2 ... - false, // Cond 3 ... - false, // Cond 4 ... - false, // Cond 5 ... - false, // Cond 6 ... - true // Cond 7 ... - ); - bool isCond7BullishTrigger = - isCond7Trigger && - IsBullish(triggerDir); - bool isCond7BearishTrigger = - isCond7Trigger && - IsBearish(triggerDir); - if (isCond7Trigger) - { - // - triggerBarPushers++; - namePrefix += "Cond7"; - } - - // - // Summarizing Trigger Bars ... - - // - bool isBullishTriggerBar = - // - isCond1BullishTrigger || - isCond2BullishTrigger || - isCond3BullishTrigger || - isCond4BullishTrigger || - isCond5BullishTrigger || - isCond6BullishTrigger || - isCond7BullishTrigger - // - ; - - // - bool isBearishTriggerBar = - // - isCond1BearishTrigger || - isCond2BearishTrigger || - isCond3BearishTrigger || - isCond4BearishTrigger || - isCond5BearishTrigger || - isCond6BearishTrigger || - isCond7BearishTrigger - // - ; - - // - bool isTriggerBar = - // - triggerBarPushers >= 1 && - (isBullishTriggerBar || - isBearishTriggerBar) - // - ; - - // - // Reading Required Condiions ... - - // - int pIndex = barIndex + 1; - int ppIndex = barIndex + 2; - - // - // SAR ... - - // - bool isSarBullish = sarStateBuffer[pIndex] > 0; - bool isPSarBullish = sarStateBuffer[ppIndex] > 0; - - // - bool isSarBearish = sarStateBuffer[pIndex] < 0; - bool isPSarBearish = sarStateBuffer[ppIndex] < 0; - - // - bool isSarSwitchedToBullish = - isSarBullish && - !isPSarBullish; - - // - bool isSarSwitchedToBearish = - isSarBearish && - !isPSarBearish; - - // - // HKS ... - - // - bool isHKSBullish = hkSBarCloseBuffer[pIndex] > hkSBarOpenBuffer[pIndex]; - bool isPHKSBullish = hkSBarCloseBuffer[ppIndex] > hkSBarOpenBuffer[ppIndex]; - - // - bool isHKSBearish = hkSBarCloseBuffer[pIndex] < hkSBarOpenBuffer[pIndex]; - bool isPHKSBearish = hkSBarCloseBuffer[ppIndex] < hkSBarOpenBuffer[ppIndex]; - - // - bool isHKSSwitchedToBullish = - isHKSBullish && - !isPHKSBullish; - - // - bool isHKSSwitchedToBearish = - isHKSBearish && - !isPHKSBearish; - - // - // SB ... - - // - bool isSBullish = sBarCloseBuffer[pIndex] > sBarOpenBuffer[pIndex]; - bool isPSBullish = sBarCloseBuffer[ppIndex] > sBarOpenBuffer[ppIndex]; - - // - bool isSBearish = sBarCloseBuffer[pIndex] < sBarOpenBuffer[pIndex]; - bool isPSBearish = sBarCloseBuffer[ppIndex] < sBarOpenBuffer[ppIndex]; - - // - bool isSSwitchedToBullish = - isSBullish && - !isPSBullish; - - // - bool isSSwitchedToBearish = - isSBearish && - !isPSBearish; - - // - // KI ... - - // - bool isKIBullish = kiStateBuffer[pIndex] > 0; - bool isPKIBullish = kiStateBuffer[ppIndex] > 0; - - // - bool isKIBearish = kiStateBuffer[pIndex] < 0; - bool isPKIBearish = kiStateBuffer[ppIndex] < 0; - - // - bool isKISwitchedToBullish = - isKIBullish && - !isPKIBullish; - - // - bool isKISwitchedToBearish = - isKIBearish && - !isPKIBearish; - - // - bool isKIBullishBreaked = - iPBar.IsBreaked( - kiBuffer[pIndex], - X_DIRECTION_BULLISH, - X_FIBO_LEVEL_500, - X_BOUNDARY_PRICE_UP_DOWN // - ); - - // - bool isKIBearishBreaked = - iPBar.IsBreaked( - kiBuffer[pIndex], - X_DIRECTION_BEARISH, - X_FIBO_LEVEL_500, - X_BOUNDARY_PRICE_UP_DOWN // - ); - - // - bool isKISame = kiBuffer[pIndex] == kiBuffer[ppIndex]; - bool isKIBullishSame = - isKISame && - isKIBullish; - bool isKIBearishSame = - isKISame && - isKIBearish; - - // - if (isKISame) - { - sameKICount++; - } - else - { - sameKICount = 0; - } - - // - if (isKIBullishSame) - { - sameKIBullishCount++; - } - else - { - sameKIBullishCount = 0; - } - - // - if (isKIBearishSame) - { - sameKIBearishCount++; - } - else - { - sameKIBearishCount = 0; - } - - // - // Validating Trigger Bar based on Conditions ... - if (isTriggerBar) - { - // - // TODO: Remove this if required ... - isTriggerBar = false; - isBullishTriggerBar = false; - isBearishTriggerBar = false; - } - - // - // Detecting Signal ... - - // - // Bullish ... - isBullish = - // - // Conditions Validation ... - isKIBullishBreaked - // isSSwitchedToBullish - // isKISwitchedToBullish - // isSarSwitchedToBullish - // isHKSSwitchedToBullish - // - // Bar Validation ... - // - ; - - // - // Bearish ... - isBearish = - // - // Conditions Validation ... - isKIBearishBreaked - // isSSwitchedToBearish - // isKISwitchedToBearish - // isSarSwitchedToBearish - // isHKSSwitchedToBearish - // - // Bar Validation ... - // - ; - - // - // Summarizing Signal ... - hasSignal = - isBullish || - isBearish; - - // - // Draw Requirements ... - - // - // Draw Trigger Bar ... - if (isTriggerBar) - { - // - int triggerBullishArrowCode = 225; - int triggerBearishArrowCode = 226; - - // - color triggerBarBullishColor = clrLime; - color triggerBarBearishColor = clrRed; - - // - ENUM_ARROW_ANCHOR triggerBullishAnchor = ANCHOR_TOP; - ENUM_ARROW_ANCHOR triggerBearishAnchor = ANCHOR_BOTTOM; - - // - int arrowWidth = 3; - int arrowCode = - isBullishTriggerBar - ? triggerBullishArrowCode - : triggerBearishArrowCode; - ENUM_X_PRICE arrowPriceType = - isBullishTriggerBar - ? X_PRICE_LOW - : X_PRICE_HIGH; - color arrowColor = - isBullishTriggerBar - ? triggerBarBullishColor - : triggerBarBearishColor; - ENUM_ARROW_ANCHOR arrowAnchor = - isBullishTriggerBar - ? triggerBullishAnchor - : triggerBearishAnchor; - - // - 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 = "XTRB"; - iBox.to = iBar.time; - iBox.symbol = _Symbol; - iBox.period = _Period; - iBox.lower = iPBar.low; - iBox.from = iPBar.time; - iBox.upper = iPBar.high; - iBox.dir = - isBullishTriggerBar - ? X_DIRECTION_BULLISH - : X_DIRECTION_BEARISH; - if (iBox.IsValid()) - { - // - // XCBoxObject *iObj; - // has = mDrawer.DrawBox( - // iBox, - // iObj // - // ); - // if (has) - // { - // mObjects.Add(iObj); - // } - - // - 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); - } - } - } - - // - } - - // - // 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 ... - - // - iBar.Clean(); - iPBar.Clean(); } // \ No newline at end of file diff --git a/Libraries/x-saherelm.x-ohcl.lib.mq5 b/Libraries/x-saherelm.x-ohcl.lib.mq5 index 5960aaec..43a1de31 100644 --- a/Libraries/x-saherelm.x-ohcl.lib.mq5 +++ b/Libraries/x-saherelm.x-ohcl.lib.mq5 @@ -1108,7 +1108,7 @@ struct XOHCL // Calculate Boundary Price ... double iBoundary = isUpDownPriceType - ? iBullish + ? isBullish ? GetUp() : GetDown() : isBullish @@ -1117,9 +1117,9 @@ struct XOHCL // // Detect Breaked Value ... - result = - isBullish - ? + // result = + // isBullish + // ? } //