diff --git a/Documents/BKP/xfima.signaller.tmp.codes.mq5 b/Documents/BKP/xfima.signaller.tmp.codes.mq5 new file mode 100644 index 00000000..3c487b17 --- /dev/null +++ b/Documents/BKP/xfima.signaller.tmp.codes.mq5 @@ -0,0 +1,511 @@ +// +// Testing Bar Zones ... +// XBoxZone barZones[]; +// int barCounts = fima2Signaller.fimaHelper.ExtractBarZones( +// barZones, +// 1, // Bar Index ... +// 50, // Number of Zones ... +// 3, // Break Validation Length ... +// true, // Validate Fake Breakes ... +// 5, // Shadow Multiplier ... +// 1, // Strength ... +// 14 // Validation Length ... +// ); +// if (IsValidSize(barCounts)) +// { +// // +// // XCBoxObject *iObj; +// // for (int i = 0; i < barCounts; i++) +// // { +// // // +// // iObj = NULL; +// // bool isCreated = fima2Signaller.poiDrawer.DrawBox( +// // barZones[i], +// // iObj, +// // true, // Ignore At ... +// // barZones[i].type // Name ... +// // ); + +// // // +// // ZeroMemory(iObj); +// // } + +// // // +// // Print("Bar Zones Detected ..."); +// } + +// +// Testing HK Zones ... +// XBoxZone hkZones[]; +// int hkCounts = fima2Signaller.fimaHelper.ExtractHKZones( +// hkZones, +// 1, // Bar Index ... +// 50, // Number of Zones ... +// 5, // Shadow Multiplier ... +// 1, // Strength ... +// 14 // Validation Length ... +// ); +// if (IsValidSize(hkCounts)) +// { +// // // +// // XCBoxObject *iObj; +// // for (int i = 0; i < hkCounts; i++) +// // { +// // // +// // iObj = NULL; +// // bool isCreated = fima2Signaller.poiDrawer.DrawBox( +// // hkZones[i], +// // iObj, +// // true, // Ignore At ... +// // hkZones[i].type // Name ... +// // ); + +// // // +// // ZeroMemory(iObj); +// // } + +// // // +// // Print("HK Zones Detected ..."); +// } + +// +// Testing XFIMA MA Pivots ... +// XPivot maPivots[]; +// int maPivotsCount = fimaHelper.ExtractMAPivots( +// maPivots, +// 1, // Bar Index ... +// 50, // Number of Pivots ... +// 1 // Validation Diff ... +// ); +// if (IsValidSize(maPivotsCount)) +// { +// // +// // CArrayObj *iPivotsObj; +// // maPivotsCount = poiDrawer.DrawPivots( +// // maPivots, +// // iPivotsObj // +// // ); + +// // +// // Print("MA Pivots Detected ..."); +// } + +// +// Custom Indicator Direction Shifts ... +bool hasMACross = HasDirection(structure.maCrossDir); +bool hasHKSwitch = HasDirection(structure.hkSwitchDir); +bool hasSARSwitch = HasDirection(structure.sarSwitchDir); + +// +// Check Required Pattern Exists ... +bool hasPinnedBar = HasDirection(structure.pinnedDir); +bool hasEngulfedBar = HasDirection(structure.engulfedDir); +bool hasFlagPattern = HasDirection(structure.flagPatternDir); +bool hasStarPattern = HasDirection(structure.starPatternDir); +bool hasRisingPattern = HasDirection(structure.risingPatternDir); +bool hasPiercingPattern = HasDirection(structure.piercingPatternDir); +bool hasSignalKeyBar = HasDirection(structure.signalKeyBarPatternDir); + +// +// Check Bar Pattern Exists ... +// and Select Pattern Direction and Price and Price Type ... +has = hasPinnedBar || + hasEngulfedBar || + hasFlagPattern || + hasStarPattern || + hasSignalKeyBar || + hasRisingPattern || + hasPiercingPattern; +if (has) +{ + // + if (hasPinnedBar) + { + // + iDir = structure.pinnedDir; + iName = "XPinned_" + ToXString(iDir) + ToXString(TimeToSeconds(bar.time)); + } + else if (hasEngulfedBar) + { + // + iDir = structure.engulfedDir; + iName = "XEngulfed_" + ToXString(iDir) + ToXString(TimeToSeconds(bar.time)); + } + else if (hasFlagPattern) + { + // + iDir = structure.flagPatternDir; + iName = "XFlag_" + ToXString(iDir) + ToXString(TimeToSeconds(bar.time)); + } + else if (hasStarPattern) + { + // + iDir = structure.starPatternDir; + iName = "XStar_" + ToXString(iDir) + ToXString(TimeToSeconds(bar.time)); + } + else if (hasSignalKeyBar) + { + // + iDir = structure.risingPatternDir; + iName = "XRising_" + ToXString(iDir) + ToXString(TimeToSeconds(bar.time)); + } + else if (hasRisingPattern) + { + // + iDir = structure.piercingPatternDir; + iName = "XPiercing_" + ToXString(iDir) + ToXString(TimeToSeconds(bar.time)); + } + else if (hasPiercingPattern) + { + // + iDir = structure.signalKeyBarPatternDir; + iName = "XSignalKey_" + ToXString(iDir) + ToXString(TimeToSeconds(bar.time)); + } + + // + isBullish = IsSpecifiedBullish(iDir); + isBearish = IsSpecifiedBearish(iDir); + + // + // Retrieve Price Type for Validate ... + iPriceType = isBullish + ? X_PRICE_DOWN + : X_PRICE_UP; + iPriceEdgeType = isBullish + ? X_PRICE_LOW + : X_PRICE_HIGH; + + // + iPrice = bar.GetPrice(iPriceType); + iPriceEdge = bar.GetPrice(iPriceEdgeType); + + // + // Validate Calculations ... + has = HasDirection(iDir) && + (isBullish || + isBearish) && + NotEmptyZero(iPrice) && + NotEmptyZero(iPriceEdge) && + iPrice != iPriceEdge; + if (!has) + { + // + isBullish = false; + isBearish = false; + iDir = X_DIRECTION_NONE; + } +} + +// +// Disable Signallers ... + +has = false; +// Strategy 1 ... +// Works on Support or Resistances Areas ... +// has = Strategy1HasSignal( +// bar, +// iZone, +// iName, +// supports, +// resistances, +// iDir, +// structure, +// fimaConditions // +// ); + +// +// Do all Draws Here ... +bool canDraw = false; +if (canDraw && has) +{ + // + int iWidth = 2; + XPOIStyle iStyle; + XCBoxObject *iBoxObj = NULL; + color iClr = isBullish + ? clrYellow + : clrDarkOrange; + + // + // Supports ... + has = HasChild(supports); + if (has) + { + // + count = ArraySize(supports); + for (int i = 0; i < count; i++) + { + // + has = poiDrawer.DrawBox( + supports[i], + iBoxObj, + true, // Ignore At ... + supports[i].type // Name ... + ); + if (has) + { + // + poiDrawer.GetBoxStyle( + iStyle, + supports[i].dir // + ); + + // + poiDrawer.ApplyBoxStyle( + iBoxObj, + iStyle // + ); + } + + // + iStyle.Clean(); + ZeroMemory(iBoxObj); + } + } + + // + // Resistances ... + has = HasChild(resistances); + if (has) + { + // + count = ArraySize(resistances); + for (int i = 0; i < count; i++) + { + // + has = poiDrawer.DrawBox( + resistances[i], + iBoxObj, + true, // Ignore At ... + resistances[i].type // Name ... + ); + if (has) + { + // + poiDrawer.GetBoxStyle( + iStyle, + resistances[i].dir // + ); + + // + poiDrawer.ApplyBoxStyle( + iBoxObj, + iStyle // + ); + } + + // + iStyle.Clean(); + ZeroMemory(iBoxObj); + } + } + + // + // Selected Zone ... + has = iZone.IsValid(); + if (has) + { + // + has = poiDrawer.DrawBox( + iZone, + iBoxObj, + true, // Ignore At ... + iZone.type // Name ... + ); + if (has) + { + // + poiDrawer.GetBoxStyle( + iStyle, + iZone.dir // + ); + + // + iStyle.clr = iClr; + iStyle.width = iWidth; + + // + poiDrawer.ApplyBoxStyle( + iBoxObj, + iStyle // + ); + } + } + + // + // TrendLines ... + + // + // Pivots ... + + // + has = HasChild(pvPivots); + if (has) + { + // + CArrayObj *drawnPivots = new CArrayObj(); + count = poiDrawer.DrawPivots( + pvPivots, + drawnPivots // + ); + } + + // + has = HasChild(zgPivots); + if (has) + { + // + CArrayObj *drawnPivots = new CArrayObj(); + count = poiDrawer.DrawPivots( + zgPivots, + drawnPivots // + ); + } + + // + // Patterns Bar ... + has = HasDirection(iDir); + if (has) + { + // + int iCode = 159; + ENUM_ARROW_ANCHOR iAnchor = isBullish + ? ANCHOR_TOP + : ANCHOR_BOTTOM; + + // + XCBarArrowObject *iPatternObj; + has = poiDrawer.DrawBarArrow( + bar, + iPatternObj, + iPriceEdgeType, + iCode, + iClr, + iWidth, + iAnchor, + iName, + true, // Ignore Bar Tag ... + 10 // Threshold ... + ); + } +} + +///////////////////////////////////////////////// + +/** + * Check Pattern Has Signal Based on Strategy 2 ... + * + * @param bar: XOHCL, reference to Pattern Bar ... + * @param iZone: XBoxZone, reference to holds affected zone ... + * @param patternName: string, detected pattern's name ... + * @param supports: XBoxZone, array reference to Provide Exists Supports ... + * @param resistances: XBoxZone, array reference to Provide Exists Resistances ... + * @param patternDir: ENUM_X_DIRECTION, detected pattern's direction ... + * @param fimaConditions: XFIMAConditions, reference to Bar Specified XFIMA Conditions ... + * @param fimaMarketStructure: XFIMAMarketStructure, refrence to Provides Market Structure ... + * + * @return ( bool ) + */ +bool Strategy2HasSignal( + XOHCL &bar, + XBoxZone &iZone, + string patternName, + XBoxZone &supports[], + XBoxZone &resistances[], + ENUM_X_DIRECTION patternDir, + XFIMAMarketStructure &structure, + XFIMAConditions &fimaConditions, + XFIMAMarketStructure &fimaMarketStructure // +) +{ + // + bool result = false; + + // + // Prepare ... + iZone.Clean(); + + // + // Validate ... + + // + // Do Detection ... + + // + // Validate result ... + + // + // Cleanup Resources ... + + // + return result; +} + +/** + * Check Pattern Has Signal Based on Strategy 1 ... + * + * @param bar: XOHCL, reference to Pattern Bar ... + * @param iZone: XBoxZone, reference to holds affected zone ... + * @param supports: XBoxZone, array reference to Provide Exists Supports ... + * @param resistances: XBoxZone, array reference to Provide Exists Resistances ... + * @param structure: XFIMAMarketStructure, refrence to Provides Market Structure ... + * @param fimaConditions: XFIMAConditions, reference to Bar Specified XFIMA Conditions ... + * + * @return ( bool ) + */ +bool Strategy3HasSignal( + XOHCL &bar, + XBoxZone &iZone, + XBoxZone &supports[], + XBoxZone &resistances[], + XFIMAMarketStructure &structure, + XFIMAConditions &fimaConditions // +) +{ + // + bool result = false; + + // + // Prepare ... + iZone.Clean(); + + // + // Validate ... + result = bar.IsValid(); + if (!result) + { + return result; + } + + // + // Reading XHK ... + + // + // Bar 1 ... + double cHKO = fimaConditions.hkOpenBuffer[0]; + double cHKH = fimaConditions.hkHighBuffer[0]; + double cHKL = fimaConditions.hkLowBuffer[0]; + double cHKC = fimaConditions.hkCloseBuffer[0]; + + // + // Bar 2 ... + double pHKO = fimaConditions.hkOpenBuffer[1]; + double pHKH = fimaConditions.hkHighBuffer[1]; + double pHKL = fimaConditions.hkLowBuffer[1]; + double pHKC = fimaConditions.hkCloseBuffer[1]; + + // + bool isCHKBullish = cHKO < cHKC; + bool isCHKBearish = cHKO > cHKC; + + // + bool isPHKBullish = pHKO < pHKC; + bool isPHKBearish = pHKO > pHKC; + + // + bool isCHKSwitchedToBullish = isCHKBullish && !isPHKBullish; + bool isCHKSwitchedToBearish = isCHKBearish && !isPHKBearish; + + // + return result; +} diff --git a/Helpers/x-saherelm.xfima.helper.mq5 b/Helpers/x-saherelm.xfima.helper.mq5 index b08d4fc4..f9033b99 100644 --- a/Helpers/x-saherelm.xfima.helper.mq5 +++ b/Helpers/x-saherelm.xfima.helper.mq5 @@ -943,6 +943,311 @@ class XCXFIMAHelper : public XCBaseHelper // // Pivot Actions ... + /** + * Check Specified Bar has MA Cross or not ... + * + * @param dir: reference for holds cross Direction ... + * @param barIndex: int, Specified Bar Index ... + * @param validCrossDiffMultiplier: double, validate diff between MAs on Cross happens ... + * + * @return ( bool ) + */ + bool HasMACross( + ENUM_X_DIRECTION &dir, + int barIndex = 0, + double validCrossDiffMultiplier = 1 // + ) + { + // + bool result = false; + + // + // Prepare ... + dir = X_DIRECTION_NONE; + + // + // Normalize ... + barIndex = NormalizeInt(barIndex, 0); + validCrossDiffMultiplier = NormalizeDouble(validCrossDiffMultiplier, 0); + + // + double fast[]; + double slow[]; + double upper[]; + double lower[]; + int count = ReadMAValues( + fast, + slow, + upper, + lower, + barIndex, + 2 // + ); + + // + bool isBullish = false; + bool isBearish = false; + + // + // Validate Readed Values ... + result = IsValidSize(count) && count >= 2; + if (result) + { + // + // Detect Direction Change ... + + // + bool notEmpty = + NotEmptyZero(fast[0]) && + NotEmptyZero(fast[1]) && + NotEmptyZero(slow[0]) && + NotEmptyZero(slow[1]); + + // + isBullish = + notEmpty && + fast[0] > slow[0] && + fast[1] < slow[1]; + + // + isBearish = + notEmpty && + fast[0] < slow[0] && + fast[1] > slow[1]; + + // + result = + isBullish || + isBearish; + + // + // Validate Direction Change ... + if (result && + validCrossDiffMultiplier > 0) + { + // + double _points = GetPoints(GetSymbol()); + double diff = MathAbs(fast[0] - slow[0]); + + // + result = diff >= (validCrossDiffMultiplier * _points); + } + } + + // + if (result) + { + // + // Setting Direction ... + dir = + isBullish + ? X_DIRECTION_BULLISH + : isBearish + ? X_DIRECTION_BEARISH + : X_DIRECTION_NONE; + } + + // + // Cleanup Resources ... + XClean(fast); + XClean(slow); + XClean(upper); + XClean(lower); + + // + return result; + } + + /** + * Check Specified Bar has HK Switch or not ... + * + * @param dir: reference for holds cross Direction ... + * @param barIndex: int, Specified Bar Index ... + * + * @return ( bool ) + */ + bool HasHKSwitch( + ENUM_X_DIRECTION &dir, + int barIndex = 0 // + ) + { + // + bool result = false; + + // + // Prepare ... + dir = X_DIRECTION_NONE; + + // + // Normalize ... + barIndex = NormalizeInt(barIndex, 0); + + // + double low[]; + double open[]; + double high[]; + double close[]; + int count = ReadHKBars( + open, + high, + low, + close, + barIndex, + 2 // + ); + + // + bool isBullish = false; + bool isBearish = false; + + // + // Validate Readed Values ... + result = IsValidSize(count) && count >= 2; + if (result) + { + // + // Detect Direction Change ... + + // + bool notEmpty = + NotEmptyZero(open[0]) && + NotEmptyZero(open[1]) && + NotEmptyZero(close[0]) && + NotEmptyZero(close[1]); + + // + isBullish = + notEmpty && + open[0] < close[0] && + open[1] > close[1]; + + // + isBearish = + notEmpty && + open[0] > close[0] && + open[1] < close[1]; + + // + result = + isBullish || + isBearish; + } + + // + if (result) + { + // + // Setting Direction ... + dir = + isBullish + ? X_DIRECTION_BULLISH + : isBearish + ? X_DIRECTION_BEARISH + : X_DIRECTION_NONE; + } + + // + // Cleanup Resources ... + XClean(low); + XClean(open); + XClean(high); + XClean(close); + + // + return result; + } + + /** + * Check Specified Bar has SAR Switch or not ... + * + * @param dir: reference for holds cross Direction ... + * @param barIndex: int, Specified Bar Index ... + * + * @return ( bool ) + */ + bool HasSARSwitch( + ENUM_X_DIRECTION &dir, + int barIndex = 0 // + ) + { + // + bool result = false; + + // + // Prepare ... + dir = X_DIRECTION_NONE; + + // + // Normalize ... + barIndex = NormalizeInt(barIndex, 0); + + // + // Validate ... + result = mHandler != INVALID_HANDLE; + if (!result) + { + return result; + } + + // + double sars[]; + int count = CopyBuffer( + mHandler, + XFIMA_SAR_STATE_LINE, + barIndex, + 2, + sars // + ); + + // + bool isBullish = false; + bool isBearish = false; + + // + // Validate Readed Values ... + result = IsValidSize(count) && count >= 2; + if (result) + { + // + // Detect Direction Change ... + + // + isBullish = + sars[0] >= 1 && + sars[1] <= -1; + + // + isBearish = + sars[0] <= -1 && + sars[1] >= 1; + + // + result = + isBullish || + isBearish; + } + + // + if (result) + { + // + // Setting Direction ... + dir = + isBullish + ? X_DIRECTION_BULLISH + : isBearish + ? X_DIRECTION_BEARISH + : X_DIRECTION_NONE; + } + + // + // Cleanup Resources ... + XClean(sars); + + // + return result; + } + /** * Extract Specified Kind of Pivots ... * @@ -1254,121 +1559,6 @@ class XCXFIMAHelper : public XCBaseHelper return result; } - /** - * Check Specified Bar has MA Cross or not ... - * - * @param dir: reference for holds cross Direction ... - * @param barIndex: int, Specified Bar Index ... - * @param validCrossDiffMultiplier: double, validate diff between MAs on Cross happens ... - * - * @return ( bool ) - */ - bool HasMACross( - ENUM_X_DIRECTION &dir, - int barIndex = 0, - double validCrossDiffMultiplier = 1 // - ) - { - // - bool result = false; - - // - // Prepare ... - dir = X_DIRECTION_NONE; - - // - // Normalize ... - barIndex = NormalizeInt(barIndex, 0); - validCrossDiffMultiplier = NormalizeDouble(validCrossDiffMultiplier, 0); - - // - double fast[]; - double slow[]; - double upper[]; - double lower[]; - int count = ReadMAValues( - fast, - slow, - upper, - lower, - barIndex, - 2 // - ); - - // - bool isBullish = false; - bool isBearish = false; - - // - // Validate Readed Values ... - result = IsValidSize(count) && count >= 2; - if (result) - { - // - // Detect Direction Change ... - - // - bool notEmpty = - NotEmptyZero(fast[0]) && - NotEmptyZero(fast[1]) && - NotEmptyZero(slow[0]) && - NotEmptyZero(slow[1]); - - // - isBullish = - notEmpty && - fast[0] > slow[0] && - fast[1] < slow[1]; - - // - isBearish = - notEmpty && - fast[0] < slow[0] && - fast[1] > slow[1]; - - // - result = - isBullish || - isBearish; - - // - // Validate Direction Change ... - if (result && - validCrossDiffMultiplier > 0) - { - // - double _points = GetPoints(GetSymbol()); - double diff = MathAbs(fast[0] - slow[0]); - - // - result = diff >= (validCrossDiffMultiplier * _points); - } - } - - // - if (result) - { - // - // Setting Direction ... - dir = - isBullish - ? X_DIRECTION_BULLISH - : isBearish - ? X_DIRECTION_BEARISH - : X_DIRECTION_NONE; - } - - // - // Cleanup Resources ... - XClean(fast); - XClean(slow); - XClean(upper); - XClean(lower); - - // - return result; - } - /** * Extract Specified Kind of Pivots ... * @@ -1596,6 +1786,214 @@ class XCXFIMAHelper : public XCBaseHelper return result; } + /** + * Extract Specified Kind of Pivots ... + * + * @param pivots: XPivot, refrence Collection to hold Extracted pivots ... + * @param barIndex: int, Specified Bar Index ... + * @param requiredNumberOFPivots: int, Specified which Number of Pivots must be Extracted ... + * @param maxAllowedLoopbackLength: int, Specified Maximum Loopback Length for Pivot Extraction ... + * + * @return ( int ) + */ + int ExtractHKPivots( + XPivot &pivots[], + int barIndex = 0, + int requiredNumberOFPivots = 50, + int maxAllowedLoopbackLength = 1500 // + ) + { + // + int result = 0; + + // + // Prepare ... + SpecifiedClean(pivots); + + // + // Normalize ... + barIndex = NormalizeInt(barIndex, 0); + requiredNumberOFPivots = NormalizeInt(requiredNumberOFPivots, 2); + maxAllowedLoopbackLength = NormalizeInt(maxAllowedLoopbackLength, 50); + + // + // Validate ... + if (mHandler == INVALID_HANDLE) + { + return result; + } + + // + double low[]; + double open[]; + XPivot iPivot; + int count = 0; + double high[]; + double close[]; + bool has = false; + int idx = barIndex - 1; + datetime iPivotTime = NULL; + string symbol = GetSymbol(); + bool isSwitchedToBullish = false; + bool isSwitchedToBearish = false; + double iSelectedValue = EMPTY_VALUE; + ENUM_TIMEFRAMES period = GetPeriod(); + ENUM_X_DIRECTION iDir = X_DIRECTION_NONE; + ENUM_X_PIVOT_TYPE iType = X_PIVOT_TYPE_NONE; + int maxAllowed = barIndex + maxAllowedLoopbackLength - 1; + while (idx < maxAllowed && + ArraySize(pivots) < requiredNumberOFPivots) + { + // + idx++; + + // + // Prepare ... + iPivot.Clean(); + SpecifiedClean(low); + SpecifiedClean(open); + SpecifiedClean(high); + SpecifiedClean(close); + + // + // Ignore First Item ... + if (idx == barIndex) + { + continue; + } + + // + // Reading Buffer ... + count = ReadHKBars( + open, + high, + low, + close, + idx, + 2 // + ); + has = IsValidSize(count); + + // + // Validate Value ... + has = + HasHKSwitch( + iDir, + idx // + ) && + NotEmptyZero(open[0]) && + NotEmptyZero(open[1]) && + NotEmptyZero(close[0]) && + NotEmptyZero(close[1]); + if (has) + { + // + // Check Direction Changed ... + isSwitchedToBullish = IsXBullish(iDir); + isSwitchedToBearish = IsXBearish(iDir); + has = + isSwitchedToBullish || + isSwitchedToBearish; + if (has) + { + // + // Calculate and Validate Type ... + // Peaks Only Valid when Confirmed by Bar High ... + iType = + isSwitchedToBearish + ? X_PIVOT_TYPE_PEAK + : isSwitchedToBullish + ? X_PIVOT_TYPE_VALE + : X_PIVOT_TYPE_NONE; + has = IsXValid(iType); + + // + // Calculate and Validate Dir ... + iDir = IsXPeak(iType) + ? X_DIRECTION_BEARISH + : IsXVale(iType) + ? X_DIRECTION_BULLISH + : X_DIRECTION_NONE; + has = has && + HasDirection(iDir); + + // + if (has) + { + // + iPivotTime = GetBarTime( + symbol, + period, + idx // + ); + + // + // Select Value based on Pivot Type ... + iSelectedValue = IsXPeak(iType) + ? MathMax(open[0], close[0]) + : MathMin(open[0], close[0]); + + // + // Initialize and Validate Pivot ... + has = iPivot.Init( + iSelectedValue, + iPivotTime, + symbol, + iDir, + period, + iType // + ); + if (has) + { + // + // Add Pivot to Collection only if not Exists ... + AddIfNotExists( + iPivot, + pivots // + ); + } + } + + // + // Cleanup Resources ... + iPivot.Clean(); + } + } + + // + // Cleanup Resources ... + iPivot.Clean(); + SpecifiedClean(low); + SpecifiedClean(open); + SpecifiedClean(high); + SpecifiedClean(close); + + // + // Check Moving Forward Condition ... + has = + idx < maxAllowed && + ArraySize(pivots) < requiredNumberOFPivots; + if (!has) + { + break; + } + } + + // + result = ArraySize(pivots); + + // + // Cleanup Resources ... + iPivot.Clean(); + SpecifiedClean(low); + SpecifiedClean(open); + SpecifiedClean(high); + SpecifiedClean(close); + + // + return result; + } + /** * Extract Specified Kind of Pivots ... * diff --git a/XFIMAEA/Classes/x-saherelm.xfima.signaller.class.mq5 b/XFIMAEA/Classes/x-saherelm.xfima.signaller.class.mq5 index e4bdd121..57b37511 100644 --- a/XFIMAEA/Classes/x-saherelm.xfima.signaller.class.mq5 +++ b/XFIMAEA/Classes/x-saherelm.xfima.signaller.class.mq5 @@ -616,25 +616,21 @@ class XCXFIMAStrategy2Signaller : public XCXFIMABaseSignaller fimaHelper.Update(barIndex); // - XOHCL bar; - XSignal signal; - XBoxZone iZone; + XOHCL iBar; int count = 0; + XBoxZone iZone; + XSignal iSignal; bool has = false; - int cIdx = 0; - int pIdx = cIdx + 1; + XTarget targets[]; string iName = NULL; XBoxZone supports[]; XBoxZone resistances[]; bool isBullish = false; bool isBearish = false; - double iPrice = EMPTY_VALUE; - double iPriceEdge = EMPTY_VALUE; - XFIMAMarketStructure structure; - XFIMAConditions fimaConditions; - ENUM_X_PRICE iPriceType = X_PRICE_NONE; + int numberOfPivots = 25; + XFIMAConditions iFIMAConditions; + XFIMAMarketStructure iStructure; ENUM_X_DIRECTION iDir = X_DIRECTION_NONE; - ENUM_X_PRICE iPriceEdgeType = X_PRICE_NONE; // XPivot pvPivots[]; @@ -650,7 +646,7 @@ class XCXFIMAStrategy2Signaller : public XCXFIMABaseSignaller // // Initialize Bar as CBar ... - has = bar.Init( + has = iBar.Init( symbol, period, barIndex // @@ -658,22 +654,22 @@ class XCXFIMAStrategy2Signaller : public XCXFIMABaseSignaller if (!has) { // - bar.Clean(); + iBar.Clean(); return; } // // Retrieve Conditions ... has = fimaHelper.GetConditions( - fimaConditions, + iFIMAConditions, barIndex, 10 // Loopback ... ); if (!has) { // - bar.Clean(); - fimaConditions.Clean(); + iBar.Clean(); + iFIMAConditions.Clean(); // return; @@ -682,8 +678,8 @@ class XCXFIMAStrategy2Signaller : public XCXFIMABaseSignaller // // Analyse Market ... poiDetector.AnalyseMarket( - bar, - structure, + iBar, + iStructure, analyserConfig // ); @@ -692,17 +688,17 @@ class XCXFIMAStrategy2Signaller : public XCXFIMABaseSignaller // // PV Trend Line ... - bool hasPVAnalysis = structure.pvAnalysis.IsValid(); + bool hasPVAnalysis = iStructure.pvAnalysis.IsValid(); if (hasPVAnalysis) { // // Support ... XBoxZone supportBox; - has = structure.pvAnalysis.HasSupportBox(supportBox); + has = iStructure.pvAnalysis.HasSupportBox(supportBox); if (has) { // - supportBox.to = bar.time; + supportBox.to = iBar.time; AddIfNotExists( supportBox, supports // @@ -712,11 +708,11 @@ class XCXFIMAStrategy2Signaller : public XCXFIMABaseSignaller // // Resistance ... XBoxZone resistanceBox; - has = structure.pvAnalysis.HasResistanceBox(resistanceBox); + has = iStructure.pvAnalysis.HasResistanceBox(resistanceBox); if (has) { // - resistanceBox.to = bar.time; + resistanceBox.to = iBar.time; AddIfNotExists( resistanceBox, supports // @@ -729,7 +725,7 @@ class XCXFIMAStrategy2Signaller : public XCXFIMABaseSignaller count = poiDetector.ExtractPVPivots( pivots, barIndex, - 50 // + numberOfPivots // ); has = IsValidSize(count); @@ -899,7 +895,6 @@ class XCXFIMAStrategy2Signaller : public XCXFIMABaseSignaller } // - // Draw Pivots ... has = HasChild(pivots); if (has) { @@ -917,17 +912,17 @@ class XCXFIMAStrategy2Signaller : public XCXFIMABaseSignaller // // ZigZag Trend Line ... - bool hasZGAnalysis = structure.zigzagAnalysis.IsValid(); + bool hasZGAnalysis = iStructure.zigzagAnalysis.IsValid(); if (hasZGAnalysis) { // // Support ... XBoxZone supportBox; - has = structure.zigzagAnalysis.HasSupportBox(supportBox); + has = iStructure.zigzagAnalysis.HasSupportBox(supportBox); if (has) { // - supportBox.to = bar.time; + supportBox.to = iBar.time; AddIfNotExists( supportBox, supports // @@ -937,11 +932,11 @@ class XCXFIMAStrategy2Signaller : public XCXFIMABaseSignaller // // Resistance ... XBoxZone resistanceBox; - has = structure.zigzagAnalysis.HasResistanceBox(resistanceBox); + has = iStructure.zigzagAnalysis.HasResistanceBox(resistanceBox); if (has) { // - resistanceBox.to = bar.time; + resistanceBox.to = iBar.time; AddIfNotExists( resistanceBox, supports // @@ -954,7 +949,7 @@ class XCXFIMAStrategy2Signaller : public XCXFIMABaseSignaller count = poiDetector.ExtractZigZagPivots( pivots, barIndex, - 10 // + numberOfPivots // ); has = IsValidSize(count); @@ -1124,7 +1119,6 @@ class XCXFIMAStrategy2Signaller : public XCXFIMABaseSignaller } // - // Draw Pivots ... has = HasChild(pivots); if (has) { @@ -1142,427 +1136,71 @@ class XCXFIMAStrategy2Signaller : public XCXFIMABaseSignaller // // Support ... - bool hasSupport = structure.support.IsValid(); + bool hasSupport = iStructure.support.IsValid(); if (hasSupport) { // + iStructure.support.to = iBar.time; AddIfNotExists( - structure.support, + iStructure.support, supports // ); } // // Resistance ... - bool hasResistance = structure.resistance.IsValid(); + bool hasResistance = iStructure.resistance.IsValid(); if (hasResistance) { // + iStructure.resistance.to = iBar.time; AddIfNotExists( - structure.resistance, + iStructure.resistance, resistances // ); } // - // Calling Without Candlestick Patterns Strategies ... - - // - // Testing Bar Zones ... - // XBoxZone barZones[]; - // int barCounts = fima2Signaller.fimaHelper.ExtractBarZones( - // barZones, - // 1, // Bar Index ... - // 50, // Number of Zones ... - // 3, // Break Validation Length ... - // true, // Validate Fake Breakes ... - // 5, // Shadow Multiplier ... - // 1, // Strength ... - // 14 // Validation Length ... - // ); - // if (IsValidSize(barCounts)) - // { - // // - // // XCBoxObject *iObj; - // // for (int i = 0; i < barCounts; i++) - // // { - // // // - // // iObj = NULL; - // // bool isCreated = fima2Signaller.poiDrawer.DrawBox( - // // barZones[i], - // // iObj, - // // true, // Ignore At ... - // // barZones[i].type // Name ... - // // ); - - // // // - // // ZeroMemory(iObj); - // // } - - // // // - // // Print("Bar Zones Detected ..."); - // } - - // - // Testing HK Zones ... - // XBoxZone hkZones[]; - // int hkCounts = fima2Signaller.fimaHelper.ExtractHKZones( - // hkZones, - // 1, // Bar Index ... - // 50, // Number of Zones ... - // 5, // Shadow Multiplier ... - // 1, // Strength ... - // 14 // Validation Length ... - // ); - // if (IsValidSize(hkCounts)) - // { - // // // - // // XCBoxObject *iObj; - // // for (int i = 0; i < hkCounts; i++) - // // { - // // // - // // iObj = NULL; - // // bool isCreated = fima2Signaller.poiDrawer.DrawBox( - // // hkZones[i], - // // iObj, - // // true, // Ignore At ... - // // hkZones[i].type // Name ... - // // ); - - // // // - // // ZeroMemory(iObj); - // // } - - // // // - // // Print("HK Zones Detected ..."); - // } - - // - // Testing XFIMA MA Pivots ... - // XPivot maPivots[]; - // int maPivotsCount = fimaHelper.ExtractMAPivots( - // maPivots, - // 1, // Bar Index ... - // 50, // Number of Pivots ... - // 1 // Validation Diff ... - // ); - // if (IsValidSize(maPivotsCount)) - // { - // // - // // CArrayObj *iPivotsObj; - // // maPivotsCount = poiDrawer.DrawPivots( - // // maPivots, - // // iPivotsObj // - // // ); - - // // - // // Print("MA Pivots Detected ..."); - // } - - // - bool hasMACross = HasDirection(structure.maCrossDir); - if (hasMACross) - { - Print(ToXString(structure.maCrossDir), " MaCross Detected ..."); - } - - // - // Check Required Pattern Exists ... - bool hasPinnedBar = HasDirection(structure.pinnedDir); - bool hasEngulfedBar = HasDirection(structure.engulfedDir); - bool hasFlagPattern = HasDirection(structure.flagPatternDir); - bool hasStarPattern = HasDirection(structure.starPatternDir); - bool hasRisingPattern = HasDirection(structure.risingPatternDir); - bool hasPiercingPattern = HasDirection(structure.piercingPatternDir); - bool hasSignalKeyBar = HasDirection(structure.signalKeyBarPatternDir); - - // - // Check Bar Pattern Exists ... - // and Select Pattern Direction and Price and Price Type ... - has = hasPinnedBar || - hasEngulfedBar || - hasFlagPattern || - hasStarPattern || - hasSignalKeyBar || - hasRisingPattern || - hasPiercingPattern; - if (has) - { - // - if (hasPinnedBar) - { - // - iDir = structure.pinnedDir; - iName = "XPinned_" + ToXString(iDir) + ToXString(TimeToSeconds(bar.time)); - } - else if (hasEngulfedBar) - { - // - iDir = structure.engulfedDir; - iName = "XEngulfed_" + ToXString(iDir) + ToXString(TimeToSeconds(bar.time)); - } - else if (hasFlagPattern) - { - // - iDir = structure.flagPatternDir; - iName = "XFlag_" + ToXString(iDir) + ToXString(TimeToSeconds(bar.time)); - } - else if (hasStarPattern) - { - // - iDir = structure.starPatternDir; - iName = "XStar_" + ToXString(iDir) + ToXString(TimeToSeconds(bar.time)); - } - else if (hasSignalKeyBar) - { - // - iDir = structure.risingPatternDir; - iName = "XRising_" + ToXString(iDir) + ToXString(TimeToSeconds(bar.time)); - } - else if (hasRisingPattern) - { - // - iDir = structure.piercingPatternDir; - iName = "XPiercing_" + ToXString(iDir) + ToXString(TimeToSeconds(bar.time)); - } - else if (hasPiercingPattern) - { - // - iDir = structure.signalKeyBarPatternDir; - iName = "XSignalKey_" + ToXString(iDir) + ToXString(TimeToSeconds(bar.time)); - } - - // - isBullish = IsSpecifiedBullish(iDir); - isBearish = IsSpecifiedBearish(iDir); - - // - // Retrieve Price Type for Validate ... - iPriceType = isBullish - ? X_PRICE_DOWN - : X_PRICE_UP; - iPriceEdgeType = isBullish - ? X_PRICE_LOW - : X_PRICE_HIGH; - - // - iPrice = bar.GetPrice(iPriceType); - iPriceEdge = bar.GetPrice(iPriceEdgeType); - - // - // Validate Calculations ... - has = HasDirection(iDir) && - (isBullish || - isBearish) && - NotEmptyZero(iPrice) && - NotEmptyZero(iPriceEdge) && - iPrice != iPriceEdge; - if (!has) - { - // - isBullish = false; - isBearish = false; - iDir = X_DIRECTION_NONE; - } - } + // Disable Signallers ... + has = false; // // Strategy 1 ... - has = false; + // Works on Support or Resistances Areas ... // has = Strategy1HasSignal( - // bar, + // iBar, // iZone, - // iName, // supports, // resistances, // iDir, - // structure, - // fimaConditions // + // iStructure, + // iFIMAConditions // // ); // - // Do all Draws Here ... - bool canDraw = false; - if (canDraw && has) - { - // - int iWidth = 2; - XPOIStyle iStyle; - XCBoxObject *iBoxObj = NULL; - color iClr = isBullish - ? clrYellow - : clrDarkOrange; - - // - // Supports ... - has = HasChild(supports); - if (has) - { - // - count = ArraySize(supports); - for (int i = 0; i < count; i++) - { - // - has = poiDrawer.DrawBox( - supports[i], - iBoxObj, - true, // Ignore At ... - supports[i].type // Name ... - ); - if (has) - { - // - poiDrawer.GetBoxStyle( - iStyle, - supports[i].dir // - ); - - // - poiDrawer.ApplyBoxStyle( - iBoxObj, - iStyle // - ); - } - - // - iStyle.Clean(); - ZeroMemory(iBoxObj); - } - } - - // - // Resistances ... - has = HasChild(resistances); - if (has) - { - // - count = ArraySize(resistances); - for (int i = 0; i < count; i++) - { - // - has = poiDrawer.DrawBox( - resistances[i], - iBoxObj, - true, // Ignore At ... - resistances[i].type // Name ... - ); - if (has) - { - // - poiDrawer.GetBoxStyle( - iStyle, - resistances[i].dir // - ); - - // - poiDrawer.ApplyBoxStyle( - iBoxObj, - iStyle // - ); - } - - // - iStyle.Clean(); - ZeroMemory(iBoxObj); - } - } - - // - // Selected Zone ... - has = iZone.IsValid(); - if (has) - { - // - has = poiDrawer.DrawBox( - iZone, - iBoxObj, - true, // Ignore At ... - iZone.type // Name ... - ); - if (has) - { - // - poiDrawer.GetBoxStyle( - iStyle, - iZone.dir // - ); - - // - iStyle.clr = iClr; - iStyle.width = iWidth; - - // - poiDrawer.ApplyBoxStyle( - iBoxObj, - iStyle // - ); - } - } - - // - // TrendLines ... - - // - // Pivots ... - - // - has = HasChild(pvPivots); - if (has) - { - // - CArrayObj *drawnPivots = new CArrayObj(); - count = poiDrawer.DrawPivots( - pvPivots, - drawnPivots // - ); - } - - // - has = HasChild(zgPivots); - if (has) - { - // - CArrayObj *drawnPivots = new CArrayObj(); - count = poiDrawer.DrawPivots( - zgPivots, - drawnPivots // - ); - } - - // - // Patterns Bar ... - has = HasDirection(iDir); - if (has) - { - // - int iCode = 159; - ENUM_ARROW_ANCHOR iAnchor = isBullish - ? ANCHOR_TOP - : ANCHOR_BOTTOM; - - // - XCBarArrowObject *iPatternObj; - has = poiDrawer.DrawBarArrow( - bar, - iPatternObj, - iPriceEdgeType, - iCode, - iClr, - iWidth, - iAnchor, - iName, - true, // Ignore Bar Tag ... - 10 // Threshold ... - ); - } - } + // Strategy 2 ... + // Works on MA Crosses ... + has = Strategy2HasSignal( + iBar, + iZone, + supports, + resistances, + iDir, + iStructure, + iFIMAConditions // + ); // + has = HasDirection(iDir); if (has) { + // + isBullish = IsXBullish(iDir); + isBearish = IsXBearish(iDir); + // // TODO: Provided SL ... - double _point = GetPoints(bar.symbol); + double _point = GetPoints(iBar.symbol); double slAddition = 5 * _point; double slPrice = isBullish @@ -1571,9 +1209,8 @@ class XCXFIMAStrategy2Signaller : public XCXFIMABaseSignaller // // Prepare Founded Signal ... - XTarget targets[]; has = PrepareSignal( - signal, + iSignal, iDir, targets, 0, // Use Default R2R ... @@ -1584,17 +1221,18 @@ class XCXFIMAStrategy2Signaller : public XCXFIMABaseSignaller { // // Notify On Signal Event ... - NotifySignalEventListeners(signal); + NotifySignalEventListeners(iSignal); } } // // Cleanup Resources ... - bar.Clean(); + iBar.Clean(); iZone.Clean(); - signal.Clean(); - structure.Clean(); - fimaConditions.Clean(); + iSignal.Clean(); + iStructure.Clean(); + iFIMAConditions.Clean(); + SpecifiedClean(targets); SpecifiedClean(pvPivots); SpecifiedClean(zgPivots); SpecifiedClean(supports); @@ -1636,6 +1274,118 @@ class XCXFIMAStrategy2Signaller : public XCXFIMABaseSignaller // // Implementing Strategies ... + /** + * Check Specified Bar has Pattern or not ... + * + * @param bar: XOHCL, reference to Specified Bar ... + * @param name: string, reference to holds Detected Patterns Name ... + * @param dir: ENUM_X_DIRECTION, reference to holds Detected Patterns Direction ... + * @param structure: XFIMAMarketStructure, refrence to Provides Market Structure ... + * + * @return ( bool ) + */ + bool HasPattern( + XOHCL &bar, + string &patternName, + ENUM_X_DIRECTION &patternDir, + XFIMAMarketStructure &structure // + ) + { + // + bool result = false; + + // + // Prepare ... + patternName = NULL; + patternDir = X_DIRECTION_NONE; + + // + // Validate ... + result = bar.IsValid(); + if (!result) + { + return result; + } + + // + // Check Required Pattern Exists ... + bool hasPinnedBar = HasDirection(structure.pinnedDir); + bool hasEngulfedBar = HasDirection(structure.engulfedDir); + bool hasFlagPattern = HasDirection(structure.flagPatternDir); + bool hasStarPattern = HasDirection(structure.starPatternDir); + bool hasRisingPattern = HasDirection(structure.risingPatternDir); + bool hasPiercingPattern = HasDirection(structure.piercingPatternDir); + bool hasSignalKeyBar = HasDirection(structure.signalKeyBarPatternDir); + + // + // Check Bar Pattern Exists ... + // and Select Pattern Direction and Price and Price Type ... + result = hasPinnedBar || + hasEngulfedBar || + hasFlagPattern || + hasStarPattern || + hasSignalKeyBar || + hasRisingPattern || + hasPiercingPattern; + + // + if (result) + { + // + if (hasPinnedBar) + { + // + patternDir = structure.pinnedDir; + patternName = "XPinned_" + ToXString(patternDir) + ToXString(TimeToSeconds(bar.time)); + } + else if (hasEngulfedBar) + { + // + patternDir = structure.engulfedDir; + patternName = "XEngulfed_" + ToXString(patternDir) + ToXString(TimeToSeconds(bar.time)); + } + else if (hasFlagPattern) + { + // + patternDir = structure.flagPatternDir; + patternName = "XFlag_" + ToXString(patternDir) + ToXString(TimeToSeconds(bar.time)); + } + else if (hasStarPattern) + { + // + patternDir = structure.starPatternDir; + patternName = "XStar_" + ToXString(patternDir) + ToXString(TimeToSeconds(bar.time)); + } + else if (hasSignalKeyBar) + { + // + patternDir = structure.risingPatternDir; + patternName = "XRising_" + ToXString(patternDir) + ToXString(TimeToSeconds(bar.time)); + } + else if (hasRisingPattern) + { + // + patternDir = structure.piercingPatternDir; + patternName = "XPiercing_" + ToXString(patternDir) + ToXString(TimeToSeconds(bar.time)); + } + else if (hasPiercingPattern) + { + // + patternDir = structure.signalKeyBarPatternDir; + patternName = "XSignalKey_" + ToXString(patternDir) + ToXString(TimeToSeconds(bar.time)); + } + } + + // + result = + result && + IsXValid(patternName) && + HasDirection(patternDir); + + // + return result; + } + /** * Validate a Pattern based on MA Band ... * @@ -1736,28 +1486,26 @@ class XCXFIMAStrategy2Signaller : public XCXFIMABaseSignaller } /** - * Check Pattern Has Signal Based on Strategy 1 ... + * Check Bar Has Signal Based on Strategy 1 ... * - * @param bar: XOHCL, reference to Pattern Bar ... + * @param bar: XOHCL, reference to Bar ... * @param iZone: XBoxZone, reference to holds affected zone ... - * @param patternName: string, detected pattern's name ... * @param supports: XBoxZone, array reference to Provide Exists Supports ... * @param resistances: XBoxZone, array reference to Provide Exists Resistances ... - * @param patternDir: ENUM_X_DIRECTION, detected pattern's direction ... + * @param iDir: ENUM_X_DIRECTION, detected Signal's direction ... * @param structure: XFIMAMarketStructure, refrence to Provides Market Structure ... - * @param fimaConditions: XFIMAConditions, reference to Bar Specified XFIMA Conditions ... + * @param conditions: XFIMAConditions, reference to Bar Specified XFIMA Conditions ... * * @return ( bool ) */ bool Strategy1HasSignal( XOHCL &bar, XBoxZone &iZone, - string patternName, XBoxZone &supports[], XBoxZone &resistances[], - ENUM_X_DIRECTION patternDir, + ENUM_X_DIRECTION &iDir, XFIMAMarketStructure &structure, - XFIMAConditions &fimaConditions // + XFIMAConditions &conditions // ) { // @@ -1766,12 +1514,26 @@ class XCXFIMAStrategy2Signaller : public XCXFIMABaseSignaller // // Prepare ... iZone.Clean(); + iDir = X_DIRECTION_NONE; // // Validate ... - result = bar.IsValid() && - IsXValid(patternName) && - HasDirection(patternDir); + result = bar.IsValid(); + if (!result) + { + return result; + } + + // + // Check Pattern Exists ... + string patternName = NULL; + ENUM_X_DIRECTION patternDir = X_DIRECTION_NONE; + result = HasPattern( + bar, + patternName, + patternDir, + structure // + ); if (!result) { return result; @@ -1783,7 +1545,7 @@ class XCXFIMAStrategy2Signaller : public XCXFIMABaseSignaller bar, patternName, patternDir, - fimaConditions // + conditions // ); if (!result) { @@ -1838,6 +1600,11 @@ class XCXFIMAStrategy2Signaller : public XCXFIMABaseSignaller : IsXBearish(patternDir) ? bar.low < iZone.lower : false; + if (result) + { + iDir = patternDir; + } + // // Cleanup Resources ... if (!result) @@ -1850,73 +1617,26 @@ class XCXFIMAStrategy2Signaller : public XCXFIMABaseSignaller } /** - * Check Pattern Has Signal Based on Strategy 2 ... + * Check Bar Has Signal Based on Strategy 1 ... * - * @param bar: XOHCL, reference to Pattern Bar ... + * @param bar: XOHCL, reference to Bar ... * @param iZone: XBoxZone, reference to holds affected zone ... - * @param patternName: string, detected pattern's name ... * @param supports: XBoxZone, array reference to Provide Exists Supports ... * @param resistances: XBoxZone, array reference to Provide Exists Resistances ... - * @param patternDir: ENUM_X_DIRECTION, detected pattern's direction ... - * @param fimaConditions: XFIMAConditions, reference to Bar Specified XFIMA Conditions ... - * @param fimaMarketStructure: XFIMAMarketStructure, refrence to Provides Market Structure ... + * @param iDir: ENUM_X_DIRECTION, detected Signal's direction ... + * @param structure: XFIMAMarketStructure, refrence to Provides Market Structure ... + * @param conditions: XFIMAConditions, reference to Bar Specified XFIMA Conditions ... * * @return ( bool ) */ bool Strategy2HasSignal( XOHCL &bar, XBoxZone &iZone, - string patternName, XBoxZone &supports[], XBoxZone &resistances[], - ENUM_X_DIRECTION patternDir, + ENUM_X_DIRECTION &iDir, XFIMAMarketStructure &structure, - XFIMAConditions &fimaConditions, - XFIMAMarketStructure &fimaMarketStructure // - ) - { - // - bool result = false; - - // - // Prepare ... - iZone.Clean(); - - // - // Validate ... - - // - // Do Detection ... - - // - // Validate result ... - - // - // Cleanup Resources ... - - // - return result; - } - - /** - * Check Pattern Has Signal Based on Strategy 1 ... - * - * @param bar: XOHCL, reference to Pattern Bar ... - * @param iZone: XBoxZone, reference to holds affected zone ... - * @param supports: XBoxZone, array reference to Provide Exists Supports ... - * @param resistances: XBoxZone, array reference to Provide Exists Resistances ... - * @param structure: XFIMAMarketStructure, refrence to Provides Market Structure ... - * @param fimaConditions: XFIMAConditions, reference to Bar Specified XFIMA Conditions ... - * - * @return ( bool ) - */ - bool Strategy3HasSignal( - XOHCL &bar, - XBoxZone &iZone, - XBoxZone &supports[], - XBoxZone &resistances[], - XFIMAMarketStructure &structure, - XFIMAConditions &fimaConditions // + XFIMAConditions &conditions // ) { // @@ -1925,6 +1645,7 @@ class XCXFIMAStrategy2Signaller : public XCXFIMABaseSignaller // // Prepare ... iZone.Clean(); + iDir = X_DIRECTION_NONE; // // Validate ... @@ -1935,33 +1656,41 @@ class XCXFIMAStrategy2Signaller : public XCXFIMABaseSignaller } // - // Reading XHK ... + // Detect Specified MA Cross ... + result = HasDirection(structure.maCrossDir); // - // Bar 1 ... - double cHKO = fimaConditions.hkOpenBuffer[0]; - double cHKH = fimaConditions.hkHighBuffer[0]; - double cHKL = fimaConditions.hkLowBuffer[0]; - double cHKC = fimaConditions.hkCloseBuffer[0]; + // Validate Conditions ... // - // Bar 2 ... - double pHKO = fimaConditions.hkOpenBuffer[1]; - double pHKH = fimaConditions.hkHighBuffer[1]; - double pHKL = fimaConditions.hkLowBuffer[1]; - double pHKC = fimaConditions.hkCloseBuffer[1]; + // Prepare iZone ... + iZone.to = bar.time; + iZone.from = GetBarTime( + bar.symbol, + bar.period, + bar.Index() + 2 // + ); + iZone.symbol = bar.symbol; + iZone.period = bar.period; + iZone.dir = structure.maCrossDir; + iZone.lower = bar.FindLowest(2, MODE_LOW); + iZone.upper = bar.FindHighest(2, MODE_HIGH); + iZone.type = name + "_" + ToXString(structure.maCrossDir); // - bool isCHKBullish = cHKO < cHKC; - bool isCHKBearish = cHKO > cHKC; + // Check Result ... + result = iZone.IsValid(); + if (result) + { + iDir = structure.maCrossDir; + } // - bool isPHKBullish = pHKO < pHKC; - bool isPHKBearish = pHKO > pHKC; - - // - bool isCHKSwitchedToBullish = isCHKBullish && !isPHKBullish; - bool isCHKSwitchedToBearish = isCHKBearish && !isPHKBearish; + // Cleanup Resources ... + if (!result) + { + iZone.Clean(); + } // return result; diff --git a/XFIMAEA/Classes/x-saherelm.xfima.x-poi.detector.class.mq5 b/XFIMAEA/Classes/x-saherelm.xfima.x-poi.detector.class.mq5 index 0929257b..f75d792f 100644 --- a/XFIMAEA/Classes/x-saherelm.xfima.x-poi.detector.class.mq5 +++ b/XFIMAEA/Classes/x-saherelm.xfima.x-poi.detector.class.mq5 @@ -916,6 +916,9 @@ class XCXFIMAPOIDetector : public XCMarketPatternDetector resistance.Clean(); } + // + // Custom Indicator Pivots ... + // // Detecting MA Crosses ... if (config.detectMACrosses) @@ -933,13 +936,52 @@ class XCXFIMAPOIDetector : public XCMarketPatternDetector structure.maCrosses, idx, config.recentlyPatternsMaxAllowedCollecting, - config.validMACrossDiffMultiplier, + config.validMACrossDiffMultiplier, config.recentlyPatternsMaxLookupLength // ); } // - // Analysers ... + // Detecting HK Switches ... + if (config.detectHKSwitches) + { + // + idx = forBar.Index(); + has = fimaHelper.HasHKSwitch( + structure.hkSwitchDir, + idx // + ); + + // + fimaHelper.ExtractHKPivots( + structure.hkSwitches, + idx, + config.recentlyPatternsMaxAllowedCollecting, + config.recentlyPatternsMaxLookupLength // + ); + } + + // + // Detecting SAR Switches ... + if (config.detectSARSwitches) { + // + idx = forBar.Index(); + has = fimaHelper.HasSARSwitch( + structure.sarSwitchDir, + idx // + ); + + // + fimaHelper.ExtractSARPivots( + structure.sarSwitches, + idx, + config.recentlyPatternsMaxAllowedCollecting, + config.recentlyPatternsMaxLookupLength // + ); + } + + // + // Custom Analysers ... // // Analyse Based on PV ... diff --git a/XFIMAEA/Libraries/x-saherelm.xfima.lib.mq5 b/XFIMAEA/Libraries/x-saherelm.xfima.lib.mq5 index 30765ece..3a376c25 100644 --- a/XFIMAEA/Libraries/x-saherelm.xfima.lib.mq5 +++ b/XFIMAEA/Libraries/x-saherelm.xfima.lib.mq5 @@ -73,6 +73,10 @@ struct XFIMAPatternDetectorConfig bool detectMACrosses; double validMACrossDiffMultiplier; + // + bool detectHKSwitches; + bool detectSARSwitches; + // // Configs ... @@ -167,6 +171,10 @@ struct XFIMAPatternDetectorConfig detectMACrosses = false; validMACrossDiffMultiplier = 0; + // + detectHKSwitches = false; + detectSARSwitches = false; + // obLoopback = 0; fvgLoopback = 0; @@ -238,6 +246,10 @@ struct XFIMAPatternDetectorConfig detectMACrosses = true; validMACrossDiffMultiplier = 1; + // + detectHKSwitches = true; + detectSARSwitches = true; + // // OB / FVg ... obLoopback = 5; @@ -329,6 +341,8 @@ struct XFIMAPatternDetectorConfig // detectMACrosses = true; + detectHKSwitches = true; + detectSARSwitches = true; } /** @@ -370,6 +384,8 @@ struct XFIMAPatternDetectorConfig // detectMACrosses = false; + detectHKSwitches = false; + detectSARSwitches = false; } // @@ -450,6 +466,14 @@ struct XFIMAMarketStructure ENUM_X_DIRECTION maCrossDir; XPivot maCrosses[]; + // + ENUM_X_DIRECTION hkSwitchDir; + XPivot hkSwitches[]; + + // + ENUM_X_DIRECTION sarSwitchDir; + XPivot sarSwitches[]; + // // Constructor ... XFIMAMarketStructure() @@ -499,6 +523,14 @@ struct XFIMAMarketStructure maCrossDir = X_DIRECTION_NONE; SpecifiedClean(maCrosses); + // + hkSwitchDir = X_DIRECTION_NONE; + SpecifiedClean(hkSwitches); + + // + sarSwitchDir = X_DIRECTION_NONE; + SpecifiedClean(sarSwitches); + // SpecifiedClean(obs); SpecifiedClean(fvgs);