diff --git a/Indicators/x-saherelm.x121.xcatb.v1.mq5 b/Indicators/x-saherelm.x121.xcatb.v1.mq5 index e5a2dae1..9a5737ce 100644 --- a/Indicators/x-saherelm.x121.xcatb.v1.mq5 +++ b/Indicators/x-saherelm.x121.xcatb.v1.mq5 @@ -649,6 +649,10 @@ int mSameValeCount = 0; double mSamePeakGolden = 0; double mSameValeGolden = 0; +// +bool mDrawLiquidities = false; +bool mDrawRangeBreakes = true; + // bool mDetectLiquidities = true; bool mDetectRangeBreakes = true; @@ -1793,7 +1797,7 @@ void FillBuffersZero(int barIndex) } // -// Custom Handlers ... +// Value Calculators ... /** * Calculate Values ... @@ -1958,6 +1962,48 @@ void CalculateValues( tickVolume // ); + // + // Handling POI(s) ... + + // + // 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 // + ); + // // Do Process on Bars ... DoProcess( @@ -1972,7 +2018,18 @@ 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 ... + * @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 CalculateCycleRanges( int barIndex, const int prevCalculated, @@ -2021,7 +2078,18 @@ 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 ... + * @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 CalculateKI( int barIndex, const int prevCalculated, @@ -2105,7 +2173,18 @@ void CalculateKI( iBar.Clean(); } -// +/** + * 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 ... + * @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 CalculatePV( int barIndex, const int prevCalculated, @@ -2223,7 +2302,18 @@ void CalculatePV( iBar.Clean(); } -// +/** + * Calculate PSar Values ... + * + * @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 CalculateSAR( int barIndex, const int prevCalculated, @@ -2261,7 +2351,18 @@ void CalculateSAR( : hideColorIDX; } -// +/** + * Calculate Signal Bar Values ... + * + * @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 CalculateSBar( int barIndex, const int prevCalculated, @@ -2317,7 +2418,18 @@ void CalculateSBar( : hideColorIDX; } -// +/** + * Calculate HK and HK Signal Bars Values ... + * + * @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 CalculateHKBar( int barIndex, const int prevCalculated, @@ -2406,7 +2518,18 @@ void CalculateHKBar( : hideColorIDX; } -// +/** + * Calculate Delta Oscillator Values ... + * + * @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 CalculateDelta( int barIndex, const int prevCalculated, @@ -2461,7 +2584,18 @@ void CalculateDelta( ); } -// +/** + * Calculate Trend Values ... + * + * @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 CalculateTrend( int barIndex, const int prevCalculated, @@ -2502,7 +2636,18 @@ void CalculateTrend( : hideColorIDX; } -// +/** + * Calculate Volume Oscillators Values ... + * + * @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 CalculateVolume( int barIndex, const int prevCalculated, @@ -2572,7 +2717,18 @@ void CalculateVolume( ); } -// +/** + * Calculate ATR Band Values ... + * + * @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 CalculateATRBand( int barIndex, const int prevCalculated, @@ -2724,6 +2880,742 @@ void CalculateCycle( } // +// +// + +/** + * Reading Bar Style and Store it ... + */ +void ReadBarStyle() +{ + // + long chartId = ChartID(); + + // + _upColor = GetChartUpColor(chartId); + _downColor = GetChartDownColor(chartId); + _lineColor = GetChartLineColor(chartId); + _bullishColor = GetChartBullishColor(chartId); + _bearishColor = GetChartBearishColor(chartId); +} + +/** + * Show Bars ... + */ +void ShowBars() +{ + // + long chartId = ChartID(); + + // + SetChartUpColor(_upColor, chartId); + SetChartDownColor(_downColor, chartId); + SetChartLineColor(_lineColor, chartId); + SetChartBullishColor(_bullishColor, chartId); + SetChartBearishColor(_bearishColor, chartId); +} + +/** + * Hide Bars ... + */ +void HideBars() +{ + // + long chartId = ChartID(); + + // + SetChartUpColor(CLR_NONE, chartId); + SetChartDownColor(CLR_NONE, chartId); + SetChartLineColor(CLR_NONE, chartId); + SetChartBullishColor(CLR_NONE, chartId); + SetChartBearishColor(CLR_NONE, chartId); +} + +// +// 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 + ? 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 // + ); + } + } + } + } + } + + // + if (isPeakSame) + { + // + mSamePeakGolden = + mSamePeakGolden == 0 + ? iBar.GetUp() + : MathMax(mSamePeakGolden, iBar.GetUp()); + mSamePeakCount++; + } + else + { + // + mSamePeakCount = 0; + mSamePeakGolden = 0; + } + + // + if (isValeSame) + { + // + mSameValeGolden = + mSameValeGolden == 0 + ? iBar.GetDown() + : MathMin(mSameValeGolden, iBar.GetDown()); + mSameValeCount++; + } + else + { + // + mSameValeCount = 0; + mSameValeGolden = 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 Handlers ... +// + +/** + * 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, @@ -2767,45 +3659,6 @@ void DoProcess( // // Do Process ... - // - // 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 // - ); - // // Detecting Trigger Bar ... @@ -3364,678 +4217,4 @@ void DoProcess( iPBar.Clean(); } -// -// -// - -// -void ReadBarStyle() -{ - // - long chartId = ChartID(); - - // - _upColor = GetChartUpColor(chartId); - _downColor = GetChartDownColor(chartId); - _lineColor = GetChartLineColor(chartId); - _bullishColor = GetChartBullishColor(chartId); - _bearishColor = GetChartBearishColor(chartId); -} - -// -void ShowBars() -{ - // - long chartId = ChartID(); - - // - SetChartUpColor(_upColor, chartId); - SetChartDownColor(_downColor, chartId); - SetChartLineColor(_lineColor, chartId); - SetChartBullishColor(_bullishColor, chartId); - SetChartBearishColor(_bearishColor, chartId); -} - -// -void HideBars() -{ - // - long chartId = ChartID(); - - // - SetChartUpColor(CLR_NONE, chartId); - SetChartDownColor(CLR_NONE, chartId); - SetChartLineColor(CLR_NONE, chartId); - SetChartBullishColor(CLR_NONE, chartId); - SetChartBearishColor(CLR_NONE, chartId); -} - -// -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 - ? 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 // - ); - } - } - } - } - } - - // - if (isPeakSame) - { - // - mSamePeakGolden = - mSamePeakGolden == 0 - ? iBar.GetUp() - : MathMax(mSamePeakGolden, iBar.GetUp()); - mSamePeakCount++; - } - else - { - // - mSamePeakCount = 0; - mSamePeakGolden = 0; - } - - // - if (isValeSame) - { - // - mSameValeGolden = - mSameValeGolden == 0 - ? iBar.GetDown() - : MathMin(mSameValeGolden, iBar.GetDown()); - mSameValeCount++; - } - else - { - // - mSameValeCount = 0; - mSameValeGolden = 0; - } - - // - // Cleanup Resources ... - - // - iBar.Clean(); - iPBar.Clean(); -} - -// -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 // - ); - } - - // -} - -// -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 ... - - // - 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 ... - - // - // 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(); - } - } - - // -} - // \ No newline at end of file