/////////////////////////////////////////////////////// // // SaherElm IT Center MQL5 Helper Parser Class Library // ---------------------------------------------------- // Name: XCXFIMAHelperParser // Description: provides all Indicator // Helper Parse requirements ... // // // Maintainer: // ------------ // Hadi Khazaee Asl (hadi_khazaee_asl@yahoo.com) // ////////////////////////////////////////////////////// // // Global Properties ... #property library #property copyright "Copyright 2023, SaherElm IT Center" #property link "https://www.saherelm.ir" #property version "1.00" #property strict // // Imports ... #include "../../Helpers/x-saherelm.xfima.helper.mq5" // // Definitions ... // // Implementation ... class XCXFIMAHelperParser : XCBase { // // Public ... public: // string symbol; ENUM_TIMEFRAMES period; // // Constructor ... XCXFIMAHelperParser(XCXFIMAHelper *_helper) { // helper = _helper; symbol = _helper.GetSymbol(); period = _helper.GetPeriod(); } // // Deconstructor ... ~XCXFIMAHelperParser() { ZeroMemory(helper); } // // Tools ... /** * Validate ... * * @return ( bool ) */ bool IsValid() { // bool result = false; // result = helper != NULL && helper.IsValid() && IsXValid(symbol) && IsXValid(period); // return result; } /** * Normalize Bar Index ... * * @param barIndex: int, Provided Bar Index ... * * @return ( int ) */ int NormalizeBarIndex(int barIndex = 0) { // int result = -1; // if (!IsValid()) { return result; } // result = helper.NormalizeBarIndex(barIndex); // return result; } // // Parsers ... // // XSAR ... /** * Check SAR is Bullish or not ... * * @param barIndex: int, Specified Bar Index ... * * @return ( bool ) */ bool IsSARBullish(int barIndex = 0) { // bool result = false; // // Normalize ... barIndex = NormalizeBarIndex(barIndex); // // Validate ... result = IsValid(); if (!result) { return result; } // double state = helper.GetSARState(barIndex); result = state >= 1; // return result; } /** * Check SAR is Bearish or not ... * * @param barIndex: int, Specified Bar Index ... * * @return ( bool ) */ bool IsSARBearish(int barIndex = 0) { // bool result = false; // // Normalize ... barIndex = NormalizeBarIndex(barIndex); // // Validate ... result = IsValid(); if (!result) { return result; } // double state = helper.GetSARState(barIndex); result = state <= -1; // return result; } /** * Check SAR is Switched to Bullish or not ... * * @param barIndex: int, Specified Bar Index ... * * @return ( bool ) */ bool IsSARSwitchedToBullish(int barIndex = 0) { // bool result = false; // // Normalize ... barIndex = NormalizeBarIndex(barIndex); // int pBarIndex = barIndex + 1; // bool isBullish = IsSARBullish(barIndex); bool isPBullish = IsSARBullish(pBarIndex); // result = isBullish && !isPBullish; // return result; } /** * Check SAR is Switched to Bearish or not ... * * @param barIndex: int, Specified Bar Index ... * * @return ( bool ) */ bool IsSARSwitchedToBearish(int barIndex = 0) { // bool result = false; // // Normalize ... barIndex = NormalizeBarIndex(barIndex); // int pBarIndex = barIndex + 1; // bool isBearish = IsSARBearish(barIndex); bool isPBearish = IsSARBearish(pBarIndex); // result = isBearish && !isPBearish; // return result; } /** * Count Bullish SAR(s) ... * * @param barIndex: int, Specified Bar Index ... * @param loopback: int, Max Allowed Loopback Length ... * * @return ( int ) */ int CountBullishSARs( int barIndex = 0, int loopback = 500 // ) { // int result = 0; // // Normalize ... loopback = NormalizeInt(loopback, 50); barIndex = NormalizeBarIndex(barIndex); // // Validate ... bool has = IsValid(); if (!has) { return result; } // // DO ... int idx = barIndex; while (idx < barIndex + loopback) { // idx++; has = IsSARBullish(idx); if (has) { result++; } if (!has) { break; } } // return result; } /** * Count Bearish SAR(s) ... * * @param barIndex: int, Specified Bar Index ... * @param loopback: int, Max Allowed Loopback Length ... * * @return ( int ) */ int CountBearishSARs( int barIndex = 0, int loopback = 500 // ) { // int result = 0; // // Normalize ... loopback = NormalizeInt(loopback, 50); barIndex = NormalizeBarIndex(barIndex); // // Validate ... bool has = IsValid(); if (!has) { return result; } // // DO ... int idx = barIndex; while (idx < barIndex + loopback) { // idx++; has = IsSARBearish(idx); if (has) { result++; } if (!has) { break; } } // return result; } // // XMA ... /** * Check Fast Ma Over Slow or not ... * * @param barIndex: int, Specified Bar Index ... * * @return ( bool ) */ bool IsMAFastOverSlow(int barIndex = 0) { // bool result = false; // // Normalize ... barIndex = NormalizeBarIndex(barIndex); // // Validate ... result = IsValid(); if (!result) { return result; } // // Do ... double iFast = helper.GetMAFast(barIndex); double iSlow = helper.GetMASlow(barIndex); // result = iFast > iSlow; // return result; } /** * Check Fast Ma Under Slow or not ... * * @param barIndex: int, Specified Bar Index ... * * @return ( bool ) */ bool IsMAFastUnderSlow(int barIndex = 0) { // bool result = false; // // Normalize ... barIndex = NormalizeBarIndex(barIndex); // // Validate ... result = IsValid(); if (!result) { return result; } // // Do ... double iFast = helper.GetMAFast(barIndex); double iSlow = helper.GetMASlow(barIndex); // result = iFast < iSlow; // return result; } /** * Check Fast Ma Over Last or not ... * * @param barIndex: int, Specified Bar Index ... * * @return ( bool ) */ bool IsMAFastOverLast(int barIndex = 0) { // bool result = false; // // Normalize ... barIndex = NormalizeBarIndex(barIndex); // // Validate ... result = IsValid(); if (!result) { return result; } // // Do ... double iFast = helper.GetMAFast(barIndex); double pFast = helper.GetMAFast(barIndex + 1); // result = iFast > pFast; // return result; } /** * Check Slow Ma Over Last or not ... * * @param barIndex: int, Specified Bar Index ... * * @return ( bool ) */ bool IsMASlowOverLast(int barIndex = 0) { // bool result = false; // // Normalize ... barIndex = NormalizeBarIndex(barIndex); // // Validate ... result = IsValid(); if (!result) { return result; } // // Do ... double iSlow = helper.GetMASlow(barIndex); double pSlow = helper.GetMASlow(barIndex + 1); // result = iSlow > pSlow; // return result; } /** * Check Fast Ma Under Last or not ... * * @param barIndex: int, Specified Bar Index ... * * @return ( bool ) */ bool IsMAFastUnderLast(int barIndex = 0) { // bool result = false; // // Normalize ... barIndex = NormalizeBarIndex(barIndex); // // Validate ... result = IsValid(); if (!result) { return result; } // // Do ... double iFast = helper.GetMAFast(barIndex); double pFast = helper.GetMAFast(barIndex + 1); // result = iFast < pFast; // return result; } /** * Check Slow Ma Under Last or not ... * * @param barIndex: int, Specified Bar Index ... * * @return ( bool ) */ bool IsMASlowUnderLast(int barIndex = 0) { // bool result = false; // // Normalize ... barIndex = NormalizeBarIndex(barIndex); // // Validate ... result = IsValid(); if (!result) { return result; } // // Do ... double iSlow = helper.GetMASlow(barIndex); double pSlow = helper.GetMASlow(barIndex + 1); // result = iSlow < pSlow; // return result; } /** * Check MA Fast is Crossed Over Slow or not ... * * @param barIndex: int, Specified Bar Index ... * * @return ( bool ) */ bool IsMAFastCrossedOverSlow(int barIndex = 0) { // bool result = false; // // Normalize ... barIndex = NormalizeBarIndex(barIndex); // // Validate ... result = IsValid(); if (!result) { return result; } // // Do ... bool isFastOverSlow = IsMAFastOverSlow(barIndex); bool isPFastOverSlow = IsMAFastOverSlow(barIndex + 1); // result = isFastOverSlow && !isPFastOverSlow; // return result; } /** * Check MA Fast is Crossed Under Slow or not ... * * @param barIndex: int, Specified Bar Index ... * * @return ( bool ) */ bool IsMAFastCrossedUnderSlow(int barIndex = 0) { // bool result = false; // // Normalize ... barIndex = NormalizeBarIndex(barIndex); // // Validate ... result = IsValid(); if (!result) { return result; } // // Do ... bool isFastUnderSlow = IsMAFastUnderSlow(barIndex); bool isPFastUnderSlow = IsMAFastUnderSlow(barIndex + 1); // result = isFastUnderSlow && !isPFastUnderSlow; // return result; } /** * Check MA Fast is Crossed Over Last or not ... * * @param barIndex: int, Specified Bar Index ... * * @return ( bool ) */ bool IsMAFastCrossedOverLast(int barIndex = 0) { // bool result = false; // // Normalize ... barIndex = NormalizeBarIndex(barIndex); // // Validate ... result = IsValid(); if (!result) { return result; } // // Do ... bool isFastOverLast = IsMAFastOverLast(barIndex); bool isPFastOverLast = IsMAFastOverLast(barIndex + 1); // result = isFastOverLast && !isPFastOverLast; // return result; } /** * Check MA Fast is Crossed Under Last or not ... * * @param barIndex: int, Specified Bar Index ... * * @return ( bool ) */ bool IsMAFastCrossedUnderLast(int barIndex = 0) { // bool result = false; // // Normalize ... barIndex = NormalizeBarIndex(barIndex); // // Validate ... result = IsValid(); if (!result) { return result; } // // Do ... bool isFastUnderLast = IsMAFastUnderLast(barIndex); bool isPFastUnderLast = IsMAFastUnderLast(barIndex + 1); // result = isFastUnderLast && !isPFastUnderLast; // return result; } /** * Check MA Slow is Crossed Over Last or not ... * * @param barIndex: int, Specified Bar Index ... * * @return ( bool ) */ bool IsMASlowCrossedOverLast(int barIndex = 0) { // bool result = false; // // Normalize ... barIndex = NormalizeBarIndex(barIndex); // // Validate ... result = IsValid(); if (!result) { return result; } // // Do ... bool isSlowOverLast = IsMASlowOverLast(barIndex); bool isPSlowOverLast = IsMASlowOverLast(barIndex + 1); // result = isSlowOverLast && !isPSlowOverLast; // return result; } /** * Check MA Slow is Crossed Under Last or not ... * * @param barIndex: int, Specified Bar Index ... * * @return ( bool ) */ bool IsMASlowCrossedUnderLast(int barIndex = 0) { // bool result = false; // // Normalize ... barIndex = NormalizeBarIndex(barIndex); // // Validate ... result = IsValid(); if (!result) { return result; } // // Do ... bool isSlowUnderLast = IsMASlowUnderLast(barIndex); bool isPSlowUnderLast = IsMASlowUnderLast(barIndex + 1); // result = isSlowUnderLast && !isPSlowUnderLast; // return result; } /** * Check MA Fast and Slow Crossed Over Last or not ... * * @param barIndex: int, Specified Bar Index ... * * @return ( bool ) */ bool IsMACrossedOverLast(int barIndex = 0) { // bool result = false; // // Normalize ... barIndex = NormalizeBarIndex(barIndex); // // Validate ... result = IsValid(); if (!result) { return result; } // // Do ... bool isFastCrossedOverLast = IsMAFastCrossedOverLast(barIndex); bool isSlowCrossedOverLast = IsMASlowCrossedOverLast(barIndex); // result = isFastCrossedOverLast && isSlowCrossedOverLast; // return result; } /** * Check MA Fast and Slow Crossed Under Last or not ... * * @param barIndex: int, Specified Bar Index ... * * @return ( bool ) */ bool IsMACrossedUnderLast(int barIndex = 0) { // bool result = false; // // Normalize ... barIndex = NormalizeBarIndex(barIndex); // // Validate ... result = IsValid(); if (!result) { return result; } // // Do ... bool isFastCrossedUnderLast = IsMAFastCrossedUnderLast(barIndex); bool isSlowCrossedUnderLast = IsMASlowCrossedUnderLast(barIndex); // result = isFastCrossedUnderLast && isSlowCrossedUnderLast; // return result; } /** * Count MA Fast Over Slows ... * * @param barIndex: int, Specified Bar Index ... * @param loopback: int, Max Allowed Loopback Length ... * * @return ( int ) */ int CountMAFastOverSlows( int barIndex = 0, int loopback = 500 // ) { // int result = 0; // // Normalize ... loopback = NormalizeInt(loopback, 50); barIndex = NormalizeBarIndex(barIndex); // // Validate ... bool has = IsValid(); if (!has) { return result; } // // DO ... int idx = barIndex; while (idx < barIndex + loopback) { // idx++; has = IsMAFastOverSlow(idx); if (has) { result++; } if (!has) { break; } } // return result; } /** * Count MA Fast Under Slows ... * * @param barIndex: int, Specified Bar Index ... * @param loopback: int, Max Allowed Loopback Length ... * * @return ( int ) */ int CountMAFastUnderSlows( int barIndex = 0, int loopback = 500 // ) { // int result = 0; // // Normalize ... loopback = NormalizeInt(loopback, 50); barIndex = NormalizeBarIndex(barIndex); // // Validate ... bool has = IsValid(); if (!has) { return result; } // // DO ... int idx = barIndex; while (idx < barIndex + loopback) { // idx++; has = IsMAFastUnderSlow(idx); if (has) { result++; } if (!has) { break; } } // return result; } /** * Count MA Fast Over Lasts ... * * @param barIndex: int, Specified Bar Index ... * @param loopback: int, Max Allowed Loopback Length ... * * @return ( int ) */ int CountMAFastOverLasts( int barIndex = 0, int loopback = 500 // ) { // int result = 0; // // Normalize ... loopback = NormalizeInt(loopback, 50); barIndex = NormalizeBarIndex(barIndex); // // Validate ... bool has = IsValid(); if (!has) { return result; } // // DO ... int idx = barIndex; while (idx < barIndex + loopback) { // idx++; has = IsMAFastOverLast(idx); if (has) { result++; } if (!has) { break; } } // return result; } /** * Count MA Fast Under Lasts ... * * @param barIndex: int, Specified Bar Index ... * @param loopback: int, Max Allowed Loopback Length ... * * @return ( int ) */ int CountMAFastUnderLasts( int barIndex = 0, int loopback = 500 // ) { // int result = 0; // // Normalize ... loopback = NormalizeInt(loopback, 50); barIndex = NormalizeBarIndex(barIndex); // // Validate ... bool has = IsValid(); if (!has) { return result; } // // DO ... int idx = barIndex; while (idx < barIndex + loopback) { // idx++; has = IsMAFastUnderLast(idx); if (has) { result++; } if (!has) { break; } } // return result; } /** * Count MA Slow Over Lasts ... * * @param barIndex: int, Specified Bar Index ... * @param loopback: int, Max Allowed Loopback Length ... * * @return ( int ) */ int CountMASlowOverLasts( int barIndex = 0, int loopback = 500 // ) { // int result = 0; // // Normalize ... loopback = NormalizeInt(loopback, 50); barIndex = NormalizeBarIndex(barIndex); // // Validate ... bool has = IsValid(); if (!has) { return result; } // // DO ... int idx = barIndex; while (idx < barIndex + loopback) { // idx++; has = IsMASlowOverLast(idx); if (has) { result++; } if (!has) { break; } } // return result; } /** * Count MA Slow Under Lasts ... * * @param barIndex: int, Specified Bar Index ... * @param loopback: int, Max Allowed Loopback Length ... * * @return ( int ) */ int CountMASlowUnderLasts( int barIndex = 0, int loopback = 500 // ) { // int result = 0; // // Normalize ... loopback = NormalizeInt(loopback, 50); barIndex = NormalizeBarIndex(barIndex); // // Validate ... bool has = IsValid(); if (!has) { return result; } // // DO ... int idx = barIndex; while (idx < barIndex + loopback) { // idx++; has = IsMASlowUnderLast(idx); if (has) { result++; } if (!has) { break; } } // return result; } /** * Count Over MA Fast Bars ... * * @param barIndex: int, Specified Bar Index ... * @param priceType: ENUM_X_PRICE, Specified Price Type ... * @param loopback: int, Max Allowed Loopback Length ... * * @return ( int ) */ int CountOverMAFastBars( int barIndex = 0, ENUM_X_PRICE priceType = X_PRICE_LOW, int loopback = 500 // ) { // int result = 0; // // Normalize ... loopback = NormalizeInt(loopback, 50); barIndex = NormalizeBarIndex(barIndex); // // Validate ... bool has = IsValid() && IsXValid(priceType); if (!has) { return result; } // // DO ... XOHCL iBar; int idx = barIndex; double iValue = EMPTY_VALUE; double iPrice = EMPTY_VALUE; while (idx < barIndex + loopback) { // idx++; iBar.Clean(); has = iBar.Init(symbol, period, idx); if (!has) { break; } // iValue = helper.GetMAFast(idx); iPrice = iBar.GetPrice(priceType); // has = iPrice > iValue; if (has) { result++; } if (!has) { break; } } // // Cleanup ... iBar.Clean(); // return result; } /** * Count Under MA Fast Bars ... * * @param barIndex: int, Specified Bar Index ... * @param priceType: ENUM_X_PRICE, Specified Price Type ... * @param loopback: int, Max Allowed Loopback Length ... * * @return ( int ) */ int CountUnderMAFastBars( int barIndex = 0, ENUM_X_PRICE priceType = X_PRICE_HIGH, int loopback = 500 // ) { // int result = 0; // // Normalize ... loopback = NormalizeInt(loopback, 50); barIndex = NormalizeBarIndex(barIndex); // // Validate ... bool has = IsValid() && IsXValid(priceType); if (!has) { return result; } // // DO ... XOHCL iBar; int idx = barIndex; double iValue = EMPTY_VALUE; double iPrice = EMPTY_VALUE; while (idx < barIndex + loopback) { // idx++; iBar.Clean(); has = iBar.Init(symbol, period, idx); if (!has) { break; } // iValue = helper.GetMAFast(idx); iPrice = iBar.GetPrice(priceType); // has = iPrice < iValue; if (has) { result++; } if (!has) { break; } } // // Cleanup ... iBar.Clean(); // return result; } /** * Count Over MA Slow Bars ... * * @param barIndex: int, Specified Bar Index ... * @param priceType: ENUM_X_PRICE, Specified Price Type ... * @param loopback: int, Max Allowed Loopback Length ... * * @return ( int ) */ int CountOverMASlowBars( int barIndex = 0, ENUM_X_PRICE priceType = X_PRICE_LOW, int loopback = 500 // ) { // int result = 0; // // Normalize ... loopback = NormalizeInt(loopback, 50); barIndex = NormalizeBarIndex(barIndex); // // Validate ... bool has = IsValid() && IsXValid(priceType); if (!has) { return result; } // // DO ... XOHCL iBar; int idx = barIndex; double iValue = EMPTY_VALUE; double iPrice = EMPTY_VALUE; while (idx < barIndex + loopback) { // idx++; iBar.Clean(); has = iBar.Init(symbol, period, idx); if (!has) { break; } // iValue = helper.GetMASlow(idx); iPrice = iBar.GetPrice(priceType); // has = iPrice > iValue; if (has) { result++; } if (!has) { break; } } // // Cleanup ... iBar.Clean(); // return result; } /** * Count Under MA Slow Bars ... * * @param barIndex: int, Specified Bar Index ... * @param priceType: ENUM_X_PRICE, Specified Price Type ... * @param loopback: int, Max Allowed Loopback Length ... * * @return ( int ) */ int CountUnderMASlowBars( int barIndex = 0, ENUM_X_PRICE priceType = X_PRICE_HIGH, int loopback = 500 // ) { // int result = 0; // // Normalize ... loopback = NormalizeInt(loopback, 50); barIndex = NormalizeBarIndex(barIndex); // // Validate ... bool has = IsValid() && IsXValid(priceType); if (!has) { return result; } // // DO ... XOHCL iBar; int idx = barIndex; double iValue = EMPTY_VALUE; double iPrice = EMPTY_VALUE; while (idx < barIndex + loopback) { // idx++; iBar.Clean(); has = iBar.Init(symbol, period, idx); if (!has) { break; } // iValue = helper.GetMASlow(idx); iPrice = iBar.GetPrice(priceType); // has = iPrice < iValue; if (has) { result++; } if (!has) { break; } } // // Cleanup ... iBar.Clean(); // return result; } // // XHK ... /** * Check HK is Bullish or not ... * * @param barIndex: int, Specified BarIndex ... * * @return ( bool ) */ bool IsHKBullish(int barIndex = 0) { // bool result = false; // // Normalize ... barIndex = NormalizeBarIndex(barIndex); // // Validate ... result = IsValid(); if (!result) { return result; } // // Do ... double iO = helper.GetHKOpen(barIndex); double iC = helper.GetHKClose(barIndex); // result = NotEmptyZero(iO) && NotEmptyZero(iC) && iC > iO; // return result; } /** * Check HK is Bearish or not ... * * @param barIndex: int, Specified BarIndex ... * * @return ( bool ) */ bool IsHKBearish(int barIndex = 0) { // bool result = false; // // Normalize ... barIndex = NormalizeBarIndex(barIndex); // // Validate ... result = IsValid(); if (!result) { return result; } // // Do ... double iO = helper.GetHKOpen(barIndex); double iC = helper.GetHKClose(barIndex); // result = NotEmptyZero(iO) && NotEmptyZero(iC) && iC < iO; // return result; } /** * Check HK is Switched to Bullish or not ... * * @param barIndex: int, Specified BarIndex ... * * @return ( bool ) */ bool IsHKSwitchedToBullish(int barIndex = 0) { // bool result = false; // // Normalize ... barIndex = NormalizeBarIndex(barIndex); // // Validate ... result = IsValid(); if (!result) { return result; } // // Do ... bool is = IsHKBullish(barIndex); bool isP = IsHKBullish(barIndex + 1); // result = is && !isP; // return result; } /** * Check HK is Switched to Bearish or not ... * * @param barIndex: int, Specified BarIndex ... * * @return ( bool ) */ bool IsHKSwitchedToBearish(int barIndex = 0) { // bool result = false; // // Normalize ... barIndex = NormalizeBarIndex(barIndex); // // Validate ... result = IsValid(); if (!result) { return result; } // // Do ... bool is = IsHKBearish(barIndex); bool isP = IsHKBearish(barIndex + 1); // result = is && !isP; // return result; } /** * Count Bullish HK(s) ... * * @param barIndex: int, Specified Bar Index ... * @param loopback: int, Max Allowed Loopback Length ... * * @return ( int ) */ int CountBullishHKs( int barIndex = 0, int loopback = 500 // ) { // int result = 0; // // Normalize ... loopback = NormalizeInt(loopback, 50); barIndex = NormalizeBarIndex(barIndex); // // Validate ... bool has = IsValid(); if (!has) { return result; } // // DO ... int idx = barIndex; while (idx < barIndex + loopback) { // idx++; has = IsHKBullish(idx); if (has) { result++; } if (!has) { break; } } // return result; } /** * Count Bearish HK(s) ... * * @param barIndex: int, Specified Bar Index ... * @param loopback: int, Max Allowed Loopback Length ... * * @return ( int ) */ int CountBearishHKs( int barIndex = 0, int loopback = 500 // ) { // int result = 0; // // Normalize ... loopback = NormalizeInt(loopback, 50); barIndex = NormalizeBarIndex(barIndex); // // Validate ... bool has = IsValid(); if (!has) { return result; } // // DO ... int idx = barIndex; while (idx < barIndex + loopback) { // idx++; has = IsHKBearish(idx); if (has) { result++; } if (!has) { break; } } // return result; } /** * Count Over HK Band Bars ... * * @param barIndex: int, Specified Bar Index ... * @param priceType: ENUM_X_PRICE, Specified Price Type ... * @param loopback: int, Max Allowed Loopback Length ... * * @return ( int ) */ int CountOverHKBandLower( int barIndex = 0, ENUM_X_PRICE priceType = X_PRICE_CLOSE, int loopback = 500 // ) { // int result = 0; // // Normalize ... loopback = NormalizeInt(loopback, 50); barIndex = NormalizeBarIndex(barIndex); // // Validate ... bool has = IsValid() && IsXValid(priceType); if (!has) { return result; } // XOHCL iBar; int idx = barIndex; double iValue = EMPTY_VALUE; double iPrice = EMPTY_VALUE; while (idx < barIndex + loopback) { // idx++; iBar.Clean(); has = iBar.Init(symbol, period, idx); if (!has) { break; } // iValue = helper.GetHKBandLower(idx); iPrice = iBar.GetPrice(priceType); // has = iPrice > iValue; if (has) { result++; } if (!has) { break; } } // // Cleanup ... iBar.Clean(); // return result; } /** * Count Under HK Band Bars ... * * @param barIndex: int, Specified Bar Index ... * @param priceType: ENUM_X_PRICE, Specified Price Type ... * @param loopback: int, Max Allowed Loopback Length ... * * @return ( int ) */ int CountUnderHKBandLower( int barIndex = 0, ENUM_X_PRICE priceType = X_PRICE_CLOSE, int loopback = 500 // ) { // int result = 0; // // Normalize ... loopback = NormalizeInt(loopback, 50); barIndex = NormalizeBarIndex(barIndex); // // Validate ... bool has = IsValid() && IsXValid(priceType); if (!has) { return result; } // XOHCL iBar; int idx = barIndex; double iValue = EMPTY_VALUE; double iPrice = EMPTY_VALUE; while (idx < barIndex + loopback) { // idx++; iBar.Clean(); has = iBar.Init(symbol, period, idx); if (!has) { break; } // iValue = helper.GetHKBandLower(idx); iPrice = iBar.GetPrice(priceType); // has = iPrice < iValue; if (has) { result++; } if (!has) { break; } } // // Cleanup ... iBar.Clean(); // return result; } /** * Count Over HK Band Bars ... * * @param barIndex: int, Specified Bar Index ... * @param priceType: ENUM_X_PRICE, Specified Price Type ... * @param loopback: int, Max Allowed Loopback Length ... * * @return ( int ) */ int CountOverHKBandUpper( int barIndex = 0, ENUM_X_PRICE priceType = X_PRICE_CLOSE, int loopback = 500 // ) { // int result = 0; // // Normalize ... loopback = NormalizeInt(loopback, 50); barIndex = NormalizeBarIndex(barIndex); // // Validate ... bool has = IsValid() && IsXValid(priceType); if (!has) { return result; } // XOHCL iBar; int idx = barIndex; double iValue = EMPTY_VALUE; double iPrice = EMPTY_VALUE; while (idx < barIndex + loopback) { // idx++; iBar.Clean(); has = iBar.Init(symbol, period, idx); if (!has) { break; } // iValue = helper.GetHKBandUpper(idx); iPrice = iBar.GetPrice(priceType); // has = iPrice > iValue; if (has) { result++; } if (!has) { break; } } // // Cleanup ... iBar.Clean(); // return result; } /** * Count Under HK Band Bars ... * * @param barIndex: int, Specified Bar Index ... * @param priceType: ENUM_X_PRICE, Specified Price Type ... * @param loopback: int, Max Allowed Loopback Length ... * * @return ( int ) */ int CountUnderHKBandUpper( int barIndex = 0, ENUM_X_PRICE priceType = X_PRICE_CLOSE, int loopback = 500 // ) { // int result = 0; // // Normalize ... loopback = NormalizeInt(loopback, 50); barIndex = NormalizeBarIndex(barIndex); // // Validate ... bool has = IsValid() && IsXValid(priceType); if (!has) { return result; } // XOHCL iBar; int idx = barIndex; double iValue = EMPTY_VALUE; double iPrice = EMPTY_VALUE; while (idx < barIndex + loopback) { // idx++; iBar.Clean(); has = iBar.Init(symbol, period, idx); if (!has) { break; } // iValue = helper.GetHKBandUpper(idx); iPrice = iBar.GetPrice(priceType); // has = iPrice < iValue; if (has) { result++; } if (!has) { break; } } // // Cleanup ... iBar.Clean(); // return result; } // // XPV ... /** * Check Peak Same as Last ... * * @param barIndex: int, Specified Bar Index ... * * @return ( bool ) */ bool IsPeakSame(int barIndex = 0) { // bool result = false; // // Normalize ... barIndex = NormalizeBarIndex(barIndex); // // Validate ... result = IsValid(); if (!result) { return result; } // double iC = helper.GetPeak(barIndex); double iP = helper.GetPeak(barIndex + 1); // result = iC == iP && NotEmptyZero(iC); // return result; } /** * Check Vale Same as Last ... * * @param barIndex: int, Specified Bar Index ... * * @return ( bool ) */ bool IsValeSame(int barIndex = 0) { // bool result = false; // // Normalize ... barIndex = NormalizeBarIndex(barIndex); // // Validate ... result = IsValid(); if (!result) { return result; } // double iC = helper.GetVale(barIndex); double iP = helper.GetVale(barIndex + 1); // result = iC == iP && NotEmptyZero(iC); // return result; } /** * Count Same Peaks ... * * @param barIndex: int, Specified Bar Index ... * @param loopback: int, Max Allowed Loopback Length ... * * @return ( int ) */ int CountSamePeaks( int barIndex = 0, int loopback = 500 // ) { // int result = 0; // // Normalize ... loopback = NormalizeInt(loopback, 50); barIndex = NormalizeBarIndex(barIndex); // // Validate ... bool has = IsValid(); if (!has) { return result; } // double iPeak = EMPTY_VALUE; double peak = helper.GetPeak(barIndex); int idx = barIndex; while (idx < barIndex + loopback) { // idx++; iPeak = helper.GetPeak(idx); has = peak == iPeak; if (has) { result++; } if (!has) { break; } } // return result; } /** * Count Same Vales ... * * @param barIndex: int, Specified Bar Index ... * @param loopback: int, Max Allowed Loopback Length ... * * @return ( int ) */ int CountSameVales( int barIndex = 0, int loopback = 500 // ) { // int result = 0; // // Normalize ... loopback = NormalizeInt(loopback, 50); barIndex = NormalizeBarIndex(barIndex); // // Validate ... bool has = IsValid(); if (!has) { return result; } // double iVale = EMPTY_VALUE; double vale = helper.GetVale(barIndex); int idx = barIndex; while (idx < barIndex + loopback) { // idx++; iVale = helper.GetVale(idx); has = vale == iVale; if (has) { result++; } if (!has) { break; } } // return result; } /** * Check Peak Happens over Last ... * * @param barIndex: int, Specified Bar Index ... * * @return ( bool ) */ bool IsPeakOverLast(int barIndex = 0) { // bool result = false; // // Normalize ... barIndex = NormalizeBarIndex(barIndex); // // Validate ... result = IsValid(); if (!result) { return result; } // // Reading Values ... // double iPeak = helper.GetPeak(barIndex); double pPeak = helper.GetPeak(barIndex + 1); // result = NotEmptyZero(iPeak) && iPeak > pPeak; // return result; } /** * Check Vale Happens over Last ... * * @param barIndex: int, Specified Bar Index ... * * @return ( bool ) */ bool IsValeOverLast(int barIndex = 0) { // bool result = false; // // Normalize ... barIndex = NormalizeBarIndex(barIndex); // // Validate ... result = IsValid(); if (!result) { return result; } // // Reading Values ... // double iVale = helper.GetVale(barIndex); double pVale = helper.GetVale(barIndex + 1); // result = NotEmptyZero(iVale) && iVale > pVale; // return result; } /** * Check Peak Happens under Last ... * * @param barIndex: int, Specified Bar Index ... * * @return ( bool ) */ bool IsPeakUnderLast(int barIndex = 0) { // bool result = false; // // Normalize ... barIndex = NormalizeBarIndex(barIndex); // // Validate ... result = IsValid(); if (!result) { return result; } // // Reading Values ... // double iPeak = helper.GetPeak(barIndex); double pPeak = helper.GetPeak(barIndex + 1); // result = NotEmptyZero(iPeak) && iPeak < pPeak; // return result; } /** * Check Vale Happens under Last ... * * @param barIndex: int, Specified Bar Index ... * * @return ( bool ) */ bool IsValeUnderLast(int barIndex = 0) { // bool result = false; // // Normalize ... barIndex = NormalizeBarIndex(barIndex); // // Validate ... result = IsValid(); if (!result) { return result; } // // Reading Values ... // double iVale = helper.GetVale(barIndex); double pVale = helper.GetVale(barIndex + 1); // result = NotEmptyZero(iVale) && iVale < pVale; // return result; } /** * Detect Last Peak Change ... * * @param index: int, reference to hold change index ... * @param barIndex: int, Specified Bar Index ... * @param loopback: int, Max Allowed Loopback Length ... * * @return ( bool ) */ bool FindLastPeakOverLast( int &index, int barIndex = 0, int loopback = 500 // ) { // bool result = false; // // Prepare ... index = -1; // // Normalize ... loopback = NormalizeInt(loopback, 50); barIndex = NormalizeBarIndex(barIndex); // // Validate ... result = IsValid(); if (!result) { return result; } // // Loop ... int idx = barIndex; while (idx < barIndex + loopback) { // idx++; result = IsPeakOverLast(idx); if (result) { // index = idx; break; } } // result = IsValidIndex(index); // return result; } /** * Detect Last Peak Change ... * * @param index: int, reference to hold change index ... * @param barIndex: int, Specified Bar Index ... * @param loopback: int, Max Allowed Loopback Length ... * * @return ( bool ) */ bool FindLastPeakUnderLast( int &index, int barIndex = 0, int loopback = 500 // ) { // bool result = false; // // Prepare ... index = -1; // // Normalize ... loopback = NormalizeInt(loopback, 50); barIndex = NormalizeBarIndex(barIndex); // // Validate ... result = IsValid(); if (!result) { return result; } // // Loop ... int idx = barIndex; while (idx < barIndex + loopback) { // idx++; result = IsPeakUnderLast(idx); if (result) { // index = idx; break; } } // result = IsValidIndex(index); // return result; } /** * Detect Last Vale Change ... * * @param index: int, reference to hold change index ... * @param barIndex: int, Specified Bar Index ... * @param loopback: int, Max Allowed Loopback Length ... * * @return ( bool ) */ bool FindLastValeOverLast( int &index, int barIndex = 0, int loopback = 500 // ) { // bool result = false; // // Prepare ... index = -1; // // Normalize ... loopback = NormalizeInt(loopback, 50); barIndex = NormalizeBarIndex(barIndex); // // Validate ... result = IsValid(); if (!result) { return result; } // // Loop ... int idx = barIndex; while (idx < barIndex + loopback) { // idx++; result = IsValeOverLast(idx); if (result) { // index = idx; break; } } // result = IsValidIndex(index); // return result; } /** * Detect Last Vale Change ... * * @param index: int, reference to hold change index ... * @param barIndex: int, Specified Bar Index ... * @param loopback: int, Max Allowed Loopback Length ... * * @return ( bool ) */ bool FindLastValeUnderLast( int &index, int barIndex = 0, int loopback = 500 // ) { // bool result = false; // // Prepare ... index = -1; // // Normalize ... loopback = NormalizeInt(loopback, 50); barIndex = NormalizeBarIndex(barIndex); // // Validate ... result = IsValid(); if (!result) { return result; } // // Loop ... int idx = barIndex; while (idx < barIndex + loopback) { // idx++; result = IsValeUnderLast(idx); if (result) { // index = idx; break; } } // result = IsValidIndex(index); // return result; } // // XZG ... /** * Check ZigZag has Value and Read it ... * * @param value: double, reference to holds value ... * @param barIndex: int, Specified Bar Index ... * * @return ( bool ) */ bool HasZG( double &value, int barIndex = 0 // ) { // bool result = false; // // Prepare ... value = EMPTY_VALUE; // // Normalize ... barIndex = NormalizeBarIndex(barIndex); // // Validate ... result = IsValid(); if (!result) { return result; } // value = helper.GetZigZag(barIndex); // result = NotEmptyZero(value); // return result; } /** * Check ZG is Low or not ... * * @param barIndex: int, Specified Bar Index ... * * @return ( bool ) */ bool IsZGLow(int barIndex = 0) { // bool result = false; // // Normalize ... barIndex = NormalizeBarIndex(barIndex); // // Validate ... result = IsValid(); if (!result) { return result; } // // Do ... // // Reading Value ... double iValue; result = HasZG(iValue, barIndex); if (!result) { return result; } // // Reading Value ... XOHCL iBar; result = iBar.Init(symbol, period, barIndex); result = result && iBar.low == iValue; // // Cleanup ... iBar.Clean(); // return result; } /** * Check ZG is High or not ... * * @param barIndex: int, Specified Bar Index ... * * @return ( bool ) */ bool IsZGHigh(int barIndex = 0) { // bool result = false; // // Normalize ... barIndex = NormalizeBarIndex(barIndex); // // Validate ... result = IsValid(); if (!result) { return result; } // // Do ... // // Reading Value ... double iValue; result = HasZG(iValue, barIndex); if (!result) { return result; } // // Reading Value ... XOHCL iBar; result = iBar.Init(symbol, period, barIndex); result = result && iBar.high == iValue; // // Cleanup ... iBar.Clean(); // return result; } // // Protected ... protected: // // // Private ... private: // XCXFIMAHelper *helper; // }; //