From d963ce8acf6983a178d8580e4e313af8c799fe91 Mon Sep 17 00:00:00 2001 From: Hadi Khazaee Asl Date: Wed, 8 Oct 2025 18:47:29 +0330 Subject: [PATCH] last ... --- Classes/x-saherelm.x-market.pattern.class.mq5 | 844 ++++-- Documents/BKP/x-saherelm.xfima.lib copy.mq5 | 694 +++++ ...-saherelm.xfima.signaller.class copy 2.mq5 | 2249 ++++++++++++++ Experts/x-saherelm.xfima.backtester.ea.mq5 | 12 +- Helpers/x-saherelm.xfima.helper.mq5 | 269 +- Libraries/x-saherelm.x-pivot.analysis.lib.mq5 | 304 ++ Libraries/x-saherelm.x-poi.extensions.lib.mq5 | 40 +- .../x-saherelm.xfima.signaller.class.mq5 | 2593 +++++++---------- .../x-saherelm.xfima.x-poi.detector.class.mq5 | 1941 ++++++------ XFIMAEA/Libraries/x-saherelm.xfima.lib.mq5 | 534 ---- 10 files changed, 6108 insertions(+), 3372 deletions(-) create mode 100644 Documents/BKP/x-saherelm.xfima.lib copy.mq5 create mode 100644 Documents/BKP/x-saherelm.xfima.signaller.class copy 2.mq5 diff --git a/Classes/x-saherelm.x-market.pattern.class.mq5 b/Classes/x-saherelm.x-market.pattern.class.mq5 index 344b00a3..bba4690e 100644 --- a/Classes/x-saherelm.x-market.pattern.class.mq5 +++ b/Classes/x-saherelm.x-market.pattern.class.mq5 @@ -23,8 +23,8 @@ // Imports ... #include "../Classes/x-saherelm.base.class.mq5" #include "../Classes/x-saherelm.x-bar.analyser.class.mq5" -#include "../Libraries/x-saherelm.x-poi.extensions.lib.mq5" #include "../Libraries/x-saherelm.x-pivot.analysis.lib.mq5" +#include "../Libraries/x-saherelm.x-poi.extensions.lib.mq5" #include "../Libraries/x-saherelm.x-poi.lib.mq5" // @@ -1995,36 +1995,37 @@ class XCMarketPatternDetector : public XCBase bool AnalyseBarPatterns( XOHCL &bar, XPatternAnalysis &analysis, - // - // PV ... - int pvValidationLength = 7, - ENUM_X_PRICE peakPriceType = X_PRICE_HIGH, - ENUM_X_PRICE valePriceType = X_PRICE_LOW, - // - // Momentum ... - int momentumBarValidationLength = 3, - double momentumBarApprovedMultiplier = 3, - // - // TrueGap ... - double trueGapApprovedStrength = 1, - // - // Pin ... - double pinBarShadowApprovedMultiplier = 3, - double pinBarRangeMultiplier = 4, - bool pinBarForceDirection = false, - // - // Flag ... - int flagPatternPullbackLength = 3, - // - // FVG ... - bool fvgForceType = false, - // - // OB ... - bool obForceTwoBar = false, - // - // Support and Resistance ... - int supportAndResistanceValidationLength = 21, - int supportAndResistanceLoopbackLength = 50 // + XPatternAnalysisConfig &config // + // // + // // PV ... + // int pvValidationLength = 7, + // ENUM_X_PRICE peakPriceType = X_PRICE_HIGH, + // ENUM_X_PRICE valePriceType = X_PRICE_LOW, + // // + // // Momentum ... + // int momentumBarValidationLength = 3, + // double momentumBarApprovedMultiplier = 3, + // // + // // TrueGap ... + // double trueGapApprovedStrength = 1, + // // + // // Pin ... + // double pinBarShadowApprovedMultiplier = 3, + // double pinBarRangeMultiplier = 4, + // bool pinBarForceDirection = false, + // // + // // Flag ... + // int flagPatternPullbackLength = 3, + // // + // // FVG ... + // bool fvgForceType = false, + // // + // // OB ... + // bool obForceTwoBar = false, + // // + // // Support and Resistance ... + // int supportAndResistanceValidationLength = 21, + // int supportAndResistanceLoopbackLength = 50 // // ) { @@ -2035,28 +2036,28 @@ class XCMarketPatternDetector : public XCBase // Prepare ... analysis.Clean(); - // - // Normalize ... - // - pvValidationLength = NormalizeInt(pvValidationLength, 2); + // // + // // Normalize ... + // // + // config.pvValidationLength = NormalizeInt(config.pvValidationLength, 2); - // - momentumBarValidationLength = NormalizeInt(momentumBarValidationLength, 2); - momentumBarApprovedMultiplier = NormalizeDouble(momentumBarApprovedMultiplier, 1); + // // + // config.momentumBarValidationLength = NormalizeInt(config.momentumBarValidationLength, 2); + // momentumBarApprovedMultiplier = NormalizeDouble(momentumBarApprovedMultiplier, 1); - // - trueGapApprovedStrength = NormalizeDouble(trueGapApprovedStrength, 1); + // // + // trueGapApprovedStrength = NormalizeDouble(trueGapApprovedStrength, 1); - // - pinBarRangeMultiplier = NormalizeDouble(pinBarRangeMultiplier, 4); - pinBarShadowApprovedMultiplier = NormalizeDouble(pinBarShadowApprovedMultiplier, 3); + // // + // pinBarRangeMultiplier = NormalizeDouble(pinBarRangeMultiplier, 4); + // pinBarShadowApprovedMultiplier = NormalizeDouble(pinBarShadowApprovedMultiplier, 3); - // - flagPatternPullbackLength = NormalizeInt(flagPatternPullbackLength, 3); + // // + // flagPatternPullbackLength = NormalizeInt(flagPatternPullbackLength, 3); - // - supportAndResistanceLoopbackLength = NormalizeInt(supportAndResistanceLoopbackLength, 10); - supportAndResistanceValidationLength = NormalizeInt(supportAndResistanceValidationLength, 10); + // // + // supportAndResistanceLoopbackLength = NormalizeInt(supportAndResistanceLoopbackLength, 10); + // supportAndResistanceValidationLength = NormalizeInt(supportAndResistanceValidationLength, 10); // // Validate ... @@ -2076,129 +2077,245 @@ class XCMarketPatternDetector : public XCBase ENUM_X_DIRECTION iDir; ENUM_X_BAR_PATTERN iPattern; + // + bool has; + bool isBullish; + bool isBearish; + + // + bool canDetect; + bool canDetectBullish; + bool canDetectBearish; + // // Bars Detectors ... // // XPV High Low Detection ... - bool isPV = IsPV( - bar, - iDir, - pvValidationLength, - peakPriceType, - valePriceType // - ); - bool isHigh = isPV && - IsXBearish(iDir); - bool isLow = isPV && - IsXBullish(iDir); - if (isPV) + canDetect = config.CanDetect(X_BAR_PATTERN_HIGH) || + config.CanDetect(X_BAR_PATTERN_LOW); + if (canDetect) { // - iPattern = - isHigh - ? X_BAR_PATTERN_HIGH - : X_BAR_PATTERN_LOW; + has = IsPV( + bar, + iDir, + config.pvValidationLength, + config.peakPriceType, + config.valePriceType // + ); // - analysis.AddPattern( - iPattern, - iDir // - ); + canDetectBullish = config.CanDetect(X_BAR_PATTERN_LOW); + canDetectBearish = config.CanDetect(X_BAR_PATTERN_HIGH); + + // + isBullish = + has && + IsXBullish(iDir) && + canDetectBullish; + + // + isBearish = + has && + IsXBearish(iDir) && + canDetectBearish; + + // + canDetect = isBullish || + isBearish; + if (canDetect) + { + // + iPattern = + isBearish + ? X_BAR_PATTERN_HIGH + : X_BAR_PATTERN_LOW; + + // + analysis.AddPattern( + iPattern, + iDir // + ); + } } // // Momentum ... - bool isMomentum = IsMomentumBar( - bar, - iDir, - momentumBarValidationLength, - momentumBarApprovedMultiplier // - ); - bool isBullishMomentum = isMomentum && - IsXBullish(iDir); - bool isBearishMomentum = isMomentum && - IsXBearish(iDir); - if (isMomentum) + iPattern = X_BAR_PATTERN_MOMENTUM; + canDetect = config.CanDetect(iPattern); + if (canDetect) { // - iPattern = X_BAR_PATTERN_MOMENTUM; + has = IsMomentumBar( + bar, + iDir, + config.momentumBarValidationLength, + config.momentumBarApprovedMultiplier // + ); // - analysis.AddPattern( + canDetectBullish = config.CanDetect( iPattern, - iDir // + X_DIRECTION_BULLISH // ); + canDetectBearish = config.CanDetect( + iPattern, + X_DIRECTION_BEARISH // + ); + + // + isBullish = has && + IsXBullish(iDir) && + canDetectBullish; + isBearish = has && + IsXBearish(iDir) && + canDetectBearish; + + // + canDetect = isBullish || + isBearish; + if (canDetect) + { + // + analysis.AddPattern( + iPattern, + iDir // + ); + } } // // Engulfed ... - bool isEngulfed = IsEngulfedBar( - bar, - iDir // - ); - bool isBullishEngulfed = isEngulfed && - IsXBullish(iDir); - bool isBearishEngulfed = isEngulfed && - IsXBearish(iDir); - if (isEngulfed) + iPattern = X_BAR_PATTERN_ENGULFED; + canDetect = config.CanDetect(iPattern); + if (canDetect) { // - iPattern = X_BAR_PATTERN_ENGULFED; - - // - analysis.AddPattern( - iPattern, + has = IsEngulfedBar( + bar, iDir // ); + + // + canDetectBullish = config.CanDetect( + iPattern, + X_DIRECTION_BULLISH // + ); + canDetectBearish = config.CanDetect( + iPattern, + X_DIRECTION_BEARISH // + ); + + // + isBullish = has && + IsXBullish(iDir) && + canDetectBullish; + isBearish = has && + IsXBearish(iDir) && + canDetectBearish; + + // + canDetect = isBullish || + isBearish; + if (canDetect) + { + // + analysis.AddPattern( + iPattern, + iDir // + ); + } } // // TrueGap ... - bool isTrueGaped = IsTrueGapedBar( - bar, - iDir, - trueGapApprovedStrength // - ); - bool isBullishTrueGaped = isTrueGaped && - IsXBullish(iDir); - bool isBearishTrueGaped = isTrueGaped && - IsXBearish(iDir); - if (isTrueGaped) + iPattern = X_BAR_PATTERN_TRUE_GAPED; + canDetect = config.CanDetect(iPattern); + if (canDetect) { // - iPattern = X_BAR_PATTERN_TRUE_GAPED; + has = IsTrueGapedBar( + bar, + iDir, + config.trueGapApprovedStrength // + ); // - analysis.AddPattern( + canDetectBullish = config.CanDetect( iPattern, - iDir // + X_DIRECTION_BULLISH // ); + canDetectBearish = config.CanDetect( + iPattern, + X_DIRECTION_BEARISH // + ); + + // + isBullish = has && + IsXBullish(iDir) && + canDetectBullish; + isBearish = has && + IsXBearish(iDir) && + canDetectBearish; + + // + canDetect = isBullish || + isBearish; + if (canDetect) + { + // + analysis.AddPattern( + iPattern, + iDir // + ); + } } // // Pinned ... - bool isPinned = IsPinnedBar( - bar, - iDir, - pinBarShadowApprovedMultiplier, - pinBarRangeMultiplier, - pinBarForceDirection // - ); - bool isBullishPinned = isPinned && - IsXBullish(iDir); - bool isBearishPinned = isPinned && - IsXBearish(iDir); - if (isPinned) + iPattern = X_BAR_PATTERN_PINNED; + canDetect = config.CanDetect(iPattern); + if (canDetect) { // - iPattern = X_BAR_PATTERN_PINNED; + has = IsPinnedBar( + bar, + iDir, + config.pinBarShadowApprovedMultiplier, + config.pinBarRangeMultiplier, + config.pinBarForceDirection // + ); // - analysis.AddPattern( + canDetectBullish = config.CanDetect( iPattern, - iDir // + X_DIRECTION_BULLISH // ); + canDetectBearish = config.CanDetect( + iPattern, + X_DIRECTION_BEARISH // + ); + + // + isBullish = has && + IsXBullish(iDir) && + canDetectBullish; + isBearish = has && + IsXBearish(iDir) && + canDetectBearish; + + // + canDetect = isBullish || + isBearish; + if (canDetect) + { + // + analysis.AddPattern( + iPattern, + iDir // + ); + } } // @@ -2206,120 +2323,225 @@ class XCMarketPatternDetector : public XCBase // // Star ... - bool isStar = IsStarPattern( - bar, - iDir // - ); - bool isBullishStar = isStar && - IsXBullish(iDir); - bool isBearishStar = isStar && - IsXBearish(iDir); - if (isStar) + iPattern = X_BAR_PATTERN_STAR; + canDetect = config.CanDetect(iPattern); + if (canDetect) { // - iPattern = X_BAR_PATTERN_STAR; - - // - analysis.AddPattern( - iPattern, + has = IsStarPattern( + bar, iDir // ); + + // + canDetectBullish = config.CanDetect( + iPattern, + X_DIRECTION_BULLISH // + ); + canDetectBearish = config.CanDetect( + iPattern, + X_DIRECTION_BEARISH // + ); + + // + isBullish = has && + IsXBullish(iDir) && + canDetectBullish; + isBearish = has && + IsXBearish(iDir) && + canDetectBearish; + + // + canDetect = isBullish || + isBearish; + if (canDetect) + { + // + analysis.AddPattern( + iPattern, + iDir // + ); + } } // // Piercing ... - bool isPiercing = IsPiercingPattern( - bar, - iDir // - ); - bool isBullishPiercing = isPiercing && - IsXBullish(iDir); - bool isBearishPiercing = isPiercing && - IsXBearish(iDir); - if (isPiercing) + iPattern = X_BAR_PATTERN_PIERCING; + canDetect = config.CanDetect(iPattern); + if (canDetect) { // - iPattern = X_BAR_PATTERN_PIERCING; - - // - analysis.AddPattern( - iPattern, + has = IsPiercingPattern( + bar, iDir // ); + + // + canDetectBullish = config.CanDetect( + iPattern, + X_DIRECTION_BULLISH // + ); + canDetectBearish = config.CanDetect( + iPattern, + X_DIRECTION_BEARISH // + ); + + // + isBullish = has && + IsXBullish(iDir) && + canDetectBullish; + isBearish = has && + IsXBearish(iDir) && + canDetectBearish; + + // + canDetect = isBullish || + isBearish; + if (canDetect) + { + // + analysis.AddPattern( + iPattern, + iDir // + ); + } } // // Rising ... - bool isRising = IsRisingPattern( - bar, - iDir // - ); - bool isBullishRising = isRising && - IsXBullish(iDir); - bool isBearishRising = isRising && - IsXBearish(iDir); - if (isRising) + iPattern = X_BAR_PATTERN_RISING; + canDetect = config.CanDetect(iPattern); + if (canDetect) { // - iPattern = X_BAR_PATTERN_RISING; - - // - analysis.AddPattern( - iPattern, + has = IsRisingPattern( + bar, iDir // ); + + // + canDetectBullish = config.CanDetect( + iPattern, + X_DIRECTION_BULLISH // + ); + canDetectBearish = config.CanDetect( + iPattern, + X_DIRECTION_BEARISH // + ); + + // + isBullish = has && + IsXBullish(iDir) && + canDetectBullish; + isBearish = has && + IsXBearish(iDir) && + canDetectBearish; + + // + canDetect = isBullish || + isBearish; + if (canDetect) + { + // + analysis.AddPattern( + iPattern, + iDir // + ); + } } // // Flag ... - bool isFlag = IsFlagPattern( - bar, - iDir, - iSwing, - flagPatternPullbackLength // - ); - bool isBullishFlag = isFlag && - IsXBullish(iDir); - bool isBearishFlag = isFlag && - IsXBearish(iDir); - if (isFlag) + iPattern = X_BAR_PATTERN_FLAG; + canDetect = config.CanDetect(iPattern); + if (canDetect) { // - iPattern = X_BAR_PATTERN_FLAG; - - // - analysis.AddPattern( - iPattern, - iDir // + has = IsFlagPattern( + bar, + iDir, + iSwing, + config.flagPatternPullbackLength // ); // - analysis.flagSwing = iSwing; + canDetectBullish = config.CanDetect( + iPattern, + X_DIRECTION_BULLISH // + ); + canDetectBearish = config.CanDetect( + iPattern, + X_DIRECTION_BEARISH // + ); + + // + isBullish = has && + IsXBullish(iDir) && + canDetectBullish; + isBearish = has && + IsXBearish(iDir) && + canDetectBearish; + + // + canDetect = isBullish || + isBearish; + if (canDetect) + { + // + analysis.AddPattern( + iPattern, + iDir // + ); + + // + analysis.flagSwing = iSwing; + } } // // SignalKey ... - bool isSignalKey = IsSignalKeyBarPattern( - bar, - iDir, - pinBarShadowApprovedMultiplier, - pinBarRangeMultiplier, - pinBarForceDirection // - ); - bool isBullishSignalKey = isSignalKey && - IsXBullish(iDir); - bool isBearishSignalKey = isSignalKey && - IsXBearish(iDir); - if (isSignalKey) + iPattern = X_BAR_PATTERN_SIGNALKEY; + canDetect = config.CanDetect(iPattern); + if (canDetect) { // - iPattern = X_BAR_PATTERN_SIGNALKEY; + has = IsSignalKeyBarPattern( + bar, + iDir, + config.pinBarShadowApprovedMultiplier, + config.pinBarRangeMultiplier, + config.pinBarForceDirection // + ); // - analysis.AddPattern( + canDetectBullish = config.CanDetect( iPattern, - iDir // + X_DIRECTION_BULLISH // ); + canDetectBearish = config.CanDetect( + iPattern, + X_DIRECTION_BEARISH // + ); + + // + isBullish = has && + IsXBullish(iDir) && + canDetectBullish; + isBearish = has && + IsXBearish(iDir) && + canDetectBearish; + + // + canDetect = isBullish || + isBearish; + if (canDetect) + { + // + analysis.AddPattern( + iPattern, + iDir // + ); + } } // @@ -2327,78 +2549,40 @@ class XCMarketPatternDetector : public XCBase // // OB ... - bool isOB = barAnalyser.IsOB( - bar, - iZone, - fvgForceType, - obForceTwoBar // - ); - bool isBullishOB = isOB && - iZone.IsBullish(); - bool isBearishOB = isOB && - iZone.IsBearish(); - if (isOB) + iPattern = X_BAR_PATTERN_OB; + canDetect = config.CanDetect(iPattern); + if (canDetect) { // - iPattern = X_BAR_PATTERN_OB; - - // - analysis.AddPattern( - iPattern, - iZone.dir // - ); - - // - analysis.ob = iZone; - } - - // - // FVG ... - bool isFVG = barAnalyser.IsFVG( - bar, - iZone, - fvgForceType // - ); - bool isBullishFVG = isFVG && - iZone.IsBullish(); - bool isBearishFVG = isFVG && - iZone.IsBearish(); - if (isFVG) - { - // - iPattern = X_BAR_PATTERN_FVG; - - // - analysis.AddPattern( - iPattern, - iZone.dir // - ); - - // - analysis.fvg = iZone; - } - - // - // Support ... - bool isSupport = HasSupport( - bar, - iSwing, - supportAndResistanceValidationLength, - supportAndResistanceLoopbackLength // - ); - if (isSupport) - { - // - iPattern = X_BAR_PATTERN_SUPPORT; - - // - bool has = ToSupportBox( - iSwing, + has = barAnalyser.IsOB( + bar, iZone, - bar.time, - supportAndResistanceValidationLength // + config.fvgForceType, + config.obForceTwoBar // ); - if (has) + + // + canDetectBullish = config.CanDetect( + iPattern, + X_DIRECTION_BULLISH // + ); + canDetectBearish = config.CanDetect( + iPattern, + X_DIRECTION_BEARISH // + ); + + // + isBullish = has && + iZone.IsBullish() && + canDetectBullish; + isBearish = has && + iZone.IsBearish() && + canDetectBearish; + + // + canDetect = isBullish || + isBearish; + if (canDetect) { // analysis.AddPattern( @@ -2407,40 +2591,126 @@ class XCMarketPatternDetector : public XCBase ); // - analysis.support = iZone; + analysis.ob = iZone; + } + } + + // + // FVG ... + iPattern = X_BAR_PATTERN_FVG; + canDetect = config.CanDetect(iPattern); + if (canDetect) + { + // + has = barAnalyser.IsFVG( + bar, + iZone, + config.fvgForceType // + ); + + // + canDetectBullish = config.CanDetect( + iPattern, + X_DIRECTION_BULLISH // + ); + canDetectBearish = config.CanDetect( + iPattern, + X_DIRECTION_BEARISH // + ); + + // + isBullish = has && + iZone.IsBullish() && + canDetectBullish; + isBearish = has && + iZone.IsBearish() && + canDetectBearish; + + // + canDetect = isBullish || + isBearish; + if (canDetect) + { + // + analysis.AddPattern( + iPattern, + iZone.dir // + ); + + // + analysis.fvg = iZone; + } + } + + // + // Support ... + iPattern = X_BAR_PATTERN_SUPPORT; + canDetect = config.CanDetect(iPattern); + if (canDetect) + { + // + has = HasSupport( + bar, + iSwing, + config.supportAndResistanceValidationLength, + config.supportAndResistanceLoopbackLength // + ); + if (has) + { + // + has = ToSupportBox( + iSwing, + iZone, + bar.time, + config.supportAndResistanceValidationLength // + ); + if (has) + { + // + analysis.AddPattern( + iPattern, + iZone.dir // + ); + + // + analysis.support = iZone; + } } } // // Resistance ... - bool isResistance = HasResistance( - bar, - iSwing, - supportAndResistanceValidationLength, - supportAndResistanceLoopbackLength // - ); - if (isResistance) + iPattern = X_BAR_PATTERN_RESISTANCE; + canDetect = config.CanDetect(iPattern); + if (canDetect) { // - iPattern = X_BAR_PATTERN_RESISTANCE; - - // - bool has = ToResistanceBox( + has = HasResistance( + bar, iSwing, - iZone, - bar.time, - supportAndResistanceValidationLength // + config.supportAndResistanceValidationLength, + config.supportAndResistanceLoopbackLength // ); if (has) { // - analysis.AddPattern( - iPattern, - iZone.dir // + has = ToResistanceBox( + iSwing, + iZone, + bar.time, + config.supportAndResistanceValidationLength // ); + if (has) + { + // + analysis.AddPattern( + iPattern, + iZone.dir // + ); - // - analysis.resistance = iZone; + // + analysis.resistance = iZone; + } } } diff --git a/Documents/BKP/x-saherelm.xfima.lib copy.mq5 b/Documents/BKP/x-saherelm.xfima.lib copy.mq5 new file mode 100644 index 00000000..78665e18 --- /dev/null +++ b/Documents/BKP/x-saherelm.xfima.lib copy.mq5 @@ -0,0 +1,694 @@ +/////////////////////////////////////////////////////// +// +// SaherElm IT Center MQL5 Library +// ------------------------------------------------- +// Name: XCXFIMAEALib ... +// Description: XFIMAEA Library ... +// +// +// Maintainer: +// ------------ +// Hadi Khazaee Asl (hadi_khazaee_asl@yahoo.com) +// +////////////////////////////////////////////////////// +// +// Global Properties ... +#property library +#property copyright "Copyright 2023, SaherElm IT Center" +#property link "https://saherelm.ir" +#property version "1.00" +#property description "SaherElm XFIMAEA Library" +#property strict + +// +// Imports ... +#include "../../Classes/x-saherelm.x-cobject.class.mq5" +#include "../../Helpers/x-saherelm.xfima.helper.mq5" +#include "../../Libraries/x-saherelm.x-pivot.analysis.lib.mq5" + +// +// Definitions ... + +/** + * Configure Market Structure Detection ... + **/ +struct XFIMAPatternDetectorConfig +{ + // + // Props ... + + // + bool detectSwingTrend; + + // + bool detectStarPattern; + bool detectFlagPattern; + bool detectRisingPattern; + bool detectPiercingPattern; + bool detectSignalKeyBarPattern; + + // + bool detectPinned; + bool detectMomentum; + bool detectEngulfed; + bool detectTrueGaped; + + // + bool analyseFIMAPVPivots; + bool analyseFIMAZigZagPivots; + + // + bool detectMACrosses; + double validMACrossDiffMultiplier; + + // + bool detectHKSwitches; + bool detectSARSwitches; + + // + // Configs ... + + // + // Trending ... + int trendingNumberOfSwings; + int trendingSwingShoulders; + + // + // Support and Resistance ... + int zonesRequiredNumber; + int zonesValidationLength; + double zonesMinAlloweStrength; + int zonesBreakValidationLength; + double zonesBarShadowMultiplier; + int zonesMaxAllowedLoopbackLength; + + // + // TrueGap ... + double truwGapApprovedPointMultiplier; + + // + // Flag Pattern ... + int flagPatternMinimumPullbackBars; + + // + // Momentum Bar ... + int momentumBarRangeLength; + double momentumBarApprovedMultiplier; + + // + // Pinned Bar ... + double pinnedBaarShadowApprovedMultiplier; + double pinnedBarMinimumPinBarRangeMultiplier; + bool pinnedBarForceDirection; + + // + // SignalKey Bar ... + double signalKeyBarShadowApprovedMultiplier; + double signalKeyBarMinimumPinBarRangeMultiplier; + bool signalKeyBarForceDirection; + + // + // Analyser ... + int pvPivotsValidationLength; + int numberOfRequiredPivotsForAnalysis; + int maxAllowedLoopbackLengthForAnalysis; + + // + // Constructor ... + XFIMAPatternDetectorConfig() + { + Clean(); + } + + // + // Tools ... + + /** + * Cleanup Model ... + */ + void Clean() + { + // + detectPinned = false; + detectMomentum = false; + detectEngulfed = false; + detectTrueGaped = false; + detectSwingTrend = false; + detectStarPattern = false; + detectFlagPattern = false; + detectRisingPattern = false; + analyseFIMAPVPivots = false; + detectPiercingPattern = false; + analyseFIMAZigZagPivots = false; + detectSignalKeyBarPattern = false; + + // + detectMACrosses = false; + validMACrossDiffMultiplier = 0; + + // + detectHKSwitches = false; + detectSARSwitches = false; + + // + zonesRequiredNumber = 0; + zonesValidationLength = 0; + zonesMinAlloweStrength = 0; + zonesBarShadowMultiplier = 0; + zonesBreakValidationLength = 0; + zonesMaxAllowedLoopbackLength = 0; + + // + trendingNumberOfSwings = 0; + trendingSwingShoulders = 0; + momentumBarRangeLength = 0; + pvPivotsValidationLength = 0; + pinnedBarForceDirection = false; + momentumBarApprovedMultiplier = 0; + signalKeyBarForceDirection = false; + truwGapApprovedPointMultiplier = 0; + flagPatternMinimumPullbackBars = 0; + numberOfRequiredPivotsForAnalysis = 0; + pinnedBaarShadowApprovedMultiplier = 0; + maxAllowedLoopbackLengthForAnalysis = 0; + signalKeyBarShadowApprovedMultiplier = 0; + pinnedBarMinimumPinBarRangeMultiplier = 0; + signalKeyBarMinimumPinBarRangeMultiplier = 0; + + // + ZeroMemory(this); + } + + /** + * Default Model ... + */ + void Default() + { + // + // Patterns ... + detectStarPattern = false; + detectFlagPattern = false; + detectRisingPattern = false; + detectPiercingPattern = false; + detectSignalKeyBarPattern = false; + + // + // Bars ... + detectPinned = false; + detectMomentum = false; + detectEngulfed = false; + detectTrueGaped = false; + + // + // Analysers ... + analyseFIMAPVPivots = false; + analyseFIMAZigZagPivots = false; + + // + detectMACrosses = true; + validMACrossDiffMultiplier = 1; + + // + detectHKSwitches = true; + detectSARSwitches = true; + + // + // Trending ... + trendingNumberOfSwings = 3; + trendingSwingShoulders = 11; + + // + // Support and Resistance ... + zonesRequiredNumber = 25; + zonesValidationLength = 21; + zonesMinAlloweStrength = 2; + zonesBarShadowMultiplier = 4; + zonesBreakValidationLength = 3; + zonesMaxAllowedLoopbackLength = 200; + + // + // TrueGap ... + truwGapApprovedPointMultiplier = 1; + + // + // Flag Pattern ... + flagPatternMinimumPullbackBars = 3; + + // + // Momentum Bar ... + momentumBarRangeLength = 3; + momentumBarApprovedMultiplier = 2; + + // + // Pinned Bar ... + pinnedBaarShadowApprovedMultiplier = 3; + pinnedBarMinimumPinBarRangeMultiplier = 4; + pinnedBarForceDirection = false; + + // + // SignalKey Bar ... + signalKeyBarShadowApprovedMultiplier = 3; + signalKeyBarMinimumPinBarRangeMultiplier = 4; + signalKeyBarForceDirection = false; + + // + // Length ... + pvPivotsValidationLength = 10; + numberOfRequiredPivotsForAnalysis = 50; + maxAllowedLoopbackLengthForAnalysis = 1500; + } + + /** + * Full Detection Model ... + */ + void FullDetect() + { + // + // Patterns ... + detectStarPattern = true; + detectFlagPattern = true; + detectRisingPattern = true; + detectPiercingPattern = true; + detectSignalKeyBarPattern = true; + + // + // Bars ... + detectPinned = true; + detectMomentum = true; + detectEngulfed = true; + detectTrueGaped = true; + + // + // Analysers ... + analyseFIMAPVPivots = true; + analyseFIMAZigZagPivots = true; + + // + detectMACrosses = true; + detectHKSwitches = true; + detectSARSwitches = true; + } + + /** + * Default Config, by turn off all detecting flags ... + */ + void OffDetectors() + { + // + // Patterns ... + detectStarPattern = false; + detectFlagPattern = false; + detectRisingPattern = false; + detectPiercingPattern = false; + detectSignalKeyBarPattern = false; + + // + // Bars ... + detectPinned = false; + detectMomentum = false; + detectEngulfed = false; + detectTrueGaped = false; + + // + // Analysers ... + analyseFIMAPVPivots = false; + analyseFIMAZigZagPivots = false; + + // + detectMACrosses = false; + detectHKSwitches = false; + detectSARSwitches = false; + } + + // +}; + +/** + * XFIMA Base Market Structure ... + * AnalyseMarket result ... + **/ +struct XFIMAMarketStructure +{ + // + XOHCL bar; + + // + XBoxZone obs[]; + XBoxZone fvgs[]; + XBoxZone supports[]; + XBoxZone resistances[]; + + // + XPivot pinBars[]; + XPivot engulfBars[]; + XPivot trueGapBars[]; + XPivot momentumBars[]; + + // + XBoxZone flagPatterns[]; + XBoxZone starPatterns[]; + XBoxZone risingPatterns[]; + XBoxZone piercingPatterns[]; + XBoxZone signalKeyBarPatterns[]; + + // + // Analysis ... + XPivotAnalysis pvAnalysis; + XPivotAnalysis zigzagAnalysis; + + // + ENUM_X_DIRECTION pinnedDir; + ENUM_X_DIRECTION momentumDir; + ENUM_X_DIRECTION engulfedDir; + ENUM_X_DIRECTION trueGapedDir; + + // + XOHCL flagSwing; + ENUM_X_DIRECTION flagPatternDir; + + // + XOHCL trendSwings[]; + ENUM_X_DIRECTION trendDir; + + // + ENUM_X_DIRECTION starPatternDir; + ENUM_X_DIRECTION risingPatternDir; + ENUM_X_DIRECTION piercingPatternDir; + ENUM_X_DIRECTION signalKeyBarPatternDir; + + // + ENUM_X_DIRECTION maCrossDir; + XPivot maCrosses[]; + + // + ENUM_X_DIRECTION hkSwitchDir; + XPivot hkSwitches[]; + + // + ENUM_X_DIRECTION sarSwitchDir; + XPivot sarSwitches[]; + + // + // Constructor ... + XFIMAMarketStructure() + { + Clean(); + } + + // + // Tools ... + + /** + * Cleanup Model ... + */ + void Clean() + { + // + bar.Clean(); + flagSwing.Clean(); + + // + pvAnalysis.Clean(); + zigzagAnalysis.Clean(); + + // + trendDir = X_DIRECTION_NONE; + pinnedDir = X_DIRECTION_NONE; + momentumDir = X_DIRECTION_NONE; + engulfedDir = X_DIRECTION_NONE; + trueGapedDir = X_DIRECTION_NONE; + flagPatternDir = X_DIRECTION_NONE; + starPatternDir = X_DIRECTION_NONE; + risingPatternDir = X_DIRECTION_NONE; + piercingPatternDir = X_DIRECTION_NONE; + signalKeyBarPatternDir = X_DIRECTION_NONE; + + // + maCrossDir = X_DIRECTION_NONE; + SpecifiedClean(maCrosses); + + // + hkSwitchDir = X_DIRECTION_NONE; + SpecifiedClean(hkSwitches); + + // + sarSwitchDir = X_DIRECTION_NONE; + SpecifiedClean(sarSwitches); + + // + SpecifiedClean(obs); + SpecifiedClean(fvgs); + SpecifiedClean(pinBars); + SpecifiedClean(supports); + SpecifiedClean(engulfBars); + SpecifiedClean(resistances); + SpecifiedClean(trueGapBars); + SpecifiedClean(momentumBars); + SpecifiedClean(flagPatterns); + SpecifiedClean(starPatterns); + SpecifiedClean(risingPatterns); + SpecifiedClean(piercingPatterns); + SpecifiedClean(signalKeyBarPatterns); + + // + SpecifiedClean(trendSwings); + + // + ZeroMemory(this); + } + + // + // Checker Functions ... + + // +}; + +/** + * Configure Market Structure Drawer ... + **/ +struct XFIMAMarketStructureDrawerConfig +{ + // + // Props ... + + // + bool drawOB; // Current Order Block ... + bool drawFVG; // Current Fair Value Gap ... + + // + bool drawSupport; // Detected Supports ... + bool drawResistance; // Detected Resistances ... + + // + bool drawSwingTrend; // Swing Trend ... + bool swingTrendRayLeft; // Ray Left Swing Trend ... + bool swingTrendRayRight; // Ray Right Swing Trend ... + + // + // Draw Current Detected Patterns ... + + // + bool drawPinned; + bool drawMomentum; + bool drawEngulfed; + bool drawTrueGaped; + + // + bool drawStarPattern; + bool drawFlagPattern; + bool drawRisingPattern; + bool drawPiercingPattern; + bool drawSignalKeyBarPattern; + + // + // Draw Recently Zones ... + bool drawRecentPatterns; + bool drawFakeBreakedZone; + bool drawRecentlyTestedZones; + bool drawRecentlyBreakedZones; + + // + // Draw Analysis Pivots ... + + // + // XPV ... + bool drawFIMAPVPivotsAnalysis; + bool drawFIMAPVPivotsAnalysisZones; + bool drawFIMAPVPivotsAnalysisTrends; + bool drawFIMAPVPivotsAnalysisPivots; + + // + // XSAR ... + bool drawFIMASARPivotsAnalysis; + bool drawFIMASARPivotsAnalysisZones; + bool drawFIMASARPivotsAnalysisTrends; + bool drawFIMASARPivotsAnalysisPivots; + + // + // XZIGZAG ... + bool drawFIMAZigZagPivotsAnalysis; + bool drawFIMAZigZagPivotsAnalysisZones; + bool drawFIMAZigZagPivotsAnalysisTrends; + bool drawFIMAZigZagPivotsAnalysisPivots; + + // + // Constructor ... + XFIMAMarketStructureDrawerConfig() + { + Clean(); + } + + // + // Tools ... + + /** + * Cleanup Model ... + */ + void Clean() + { + // + drawOB = false; + drawFVG = false; + drawPinned = false; + drawMomentum = false; + drawSupport = false; + drawEngulfed = false; + drawTrueGaped = false; + drawResistance = false; + drawSwingTrend = false; + drawStarPattern = false; + drawFlagPattern = false; + swingTrendRayLeft = false; + drawRisingPattern = false; + swingTrendRayRight = false; + drawPiercingPattern = false; + drawSignalKeyBarPattern = false; + + // + drawRecentPatterns = false; + drawFakeBreakedZone = false; + drawRecentlyTestedZones = false; + drawRecentlyBreakedZones = false; + + // + drawFIMAPVPivotsAnalysis = false; + drawFIMAPVPivotsAnalysisZones = false; + drawFIMAPVPivotsAnalysisTrends = false; + drawFIMAPVPivotsAnalysisPivots = false; + + // + drawFIMASARPivotsAnalysis = false; + drawFIMASARPivotsAnalysisZones = false; + drawFIMASARPivotsAnalysisTrends = false; + drawFIMASARPivotsAnalysisPivots = false; + + // + drawFIMAZigZagPivotsAnalysis = false; + drawFIMAZigZagPivotsAnalysisZones = false; + drawFIMAZigZagPivotsAnalysisTrends = false; + drawFIMAZigZagPivotsAnalysisPivots = false; + + // + ZeroMemory(this); + } + + /** + * Default Model ... + */ + void Default() + { + drawOB = true; + drawFVG = true; + drawPinned = true; + drawMomentum = true; + drawSupport = true; + drawEngulfed = true; + drawTrueGaped = true; + drawResistance = true; + drawSwingTrend = true; + drawStarPattern = true; + drawFlagPattern = true; + drawRisingPattern = true; + drawPiercingPattern = true; + swingTrendRayLeft = false; + swingTrendRayRight = true; + drawSignalKeyBarPattern = true; + + // + drawRecentPatterns = true; + drawFakeBreakedZone = true; + drawRecentlyTestedZones = true; + drawRecentlyBreakedZones = true; + + // + drawFIMAPVPivotsAnalysis = true; + drawFIMAPVPivotsAnalysisZones = true; + drawFIMAPVPivotsAnalysisTrends = true; + drawFIMAPVPivotsAnalysisPivots = true; + + // + drawFIMASARPivotsAnalysis = true; + drawFIMASARPivotsAnalysisZones = true; + drawFIMASARPivotsAnalysisTrends = true; + drawFIMASARPivotsAnalysisPivots = true; + + // + drawFIMAZigZagPivotsAnalysis = true; + drawFIMAZigZagPivotsAnalysisZones = true; + drawFIMAZigZagPivotsAnalysisTrends = true; + drawFIMAZigZagPivotsAnalysisPivots = true; + } + + /** + * Configure for Full Drawing ... + */ + void FullDraw() + { + // + Default(); + + // + drawOB = true; + drawFVG = true; + drawPinned = true; + drawMomentum = true; + drawSupport = true; + drawEngulfed = true; + drawTrueGaped = true; + drawResistance = true; + drawSwingTrend = true; + drawStarPattern = true; + drawFlagPattern = true; + drawRisingPattern = true; + swingTrendRayLeft = true; + swingTrendRayRight = true; + drawPiercingPattern = true; + drawSignalKeyBarPattern = true; + + // + drawRecentPatterns = true; + drawFakeBreakedZone = true; + drawRecentlyTestedZones = true; + drawRecentlyBreakedZones = true; + + // + drawFIMAPVPivotsAnalysis = true; + drawFIMAPVPivotsAnalysisZones = true; + drawFIMAPVPivotsAnalysisTrends = true; + drawFIMAPVPivotsAnalysisPivots = true; + + // + drawFIMASARPivotsAnalysis = true; + drawFIMASARPivotsAnalysisZones = true; + drawFIMASARPivotsAnalysisTrends = true; + drawFIMASARPivotsAnalysisPivots = true; + + // + drawFIMAZigZagPivotsAnalysis = true; + drawFIMAZigZagPivotsAnalysisZones = true; + drawFIMAZigZagPivotsAnalysisTrends = true; + drawFIMAZigZagPivotsAnalysisPivots = true; + } + + // +}; diff --git a/Documents/BKP/x-saherelm.xfima.signaller.class copy 2.mq5 b/Documents/BKP/x-saherelm.xfima.signaller.class copy 2.mq5 new file mode 100644 index 00000000..b2d9299d --- /dev/null +++ b/Documents/BKP/x-saherelm.xfima.signaller.class copy 2.mq5 @@ -0,0 +1,2249 @@ +/////////////////////////////////////////////////////// +// +// SaherElm IT Center MQL5 Class +// ------------------------------------------------- +// Name: XCXFIMASignaller ... +// Description: XFIMA Signaller Class ... +// +// +// Maintainer: +// ------------ +// Hadi Khazaee Asl (hadi_khazaee_asl@yahoo.com) +// +////////////////////////////////////////////////////// +// +// Global Properties ... +#property library +#property copyright "Copyright 2023, SaherElm IT Center" +#property link "https://saherelm.ir" +#property version "1.00" +#property description "SaherElm XFIMA Signaller Class" +#property strict + +// +// Imports ... +#include "../../Classes/x-saherelm.x-signaller.class.mq5" +#include "../../Helpers/x-saherelm.xfima.helper.mq5" +#include "../Classes/x-saherelm.xfima.x-poi.detector.class.mq5" +#include "../Classes/x-saherelm.xfima.x-poi.drawer.class.mq5" + +// +// Implementation ... + +// +// Base XFIMA base Signaller ... +class XCXFIMABaseSignaller : public XCBaseSignaller +{ + // + // Public ... + public: + // + // Props ... + + // + bool ignoreTargets; // Ignore Signal Targets ... + XFIMAInputs fimaInputs; // XFIMA Inputs ... + XCXFIMAHelper *fimaHelper; // XFIMA Indicator Helper ... + XCXFIMAPOIDrawer *poiDrawer; // XFIMA POI Drawer ... + XCXFIMAPOIDetector *poiDetector; // XFIMA POI Detector ... + + // + // Constructor ... + XCXFIMABaseSignaller( + string _name, // Name ... + string _symbol, // Symbol ... + ENUM_TIMEFRAMES _period, // Period ... + XFIMAInputs &_fimaInputs, // XFIMAInputs ... + bool _processAllTicks = false, // Process All Ticks ... + double _defaultSignalR2R = 1.5, // Default Signal Risk To Reward Ratio ... + double _defaultSignalRiskInPoint = 50, // Default Signal Risk In Point ... + double _defaultSignalVolume = 0.01 // Default Signal Volume ... + ) : XCBaseSignaller(_name, + _symbol, + _period, + _processAllTicks, + _defaultSignalR2R, + _defaultSignalRiskInPoint, + _defaultSignalVolume // + ) + { + // + // Instantiating XFIMA Indicator Helper Class ... + if (_fimaInputs.IsValid()) + { + // + fimaHelper = new XCXFIMAHelper(); + bool isInited = fimaHelper.Init( + _symbol, + _period, + _fimaInputs // + ); + if (isInited) + { + fimaInputs = _fimaInputs; + } + else + { + // + delete fimaHelper; + ZeroMemory(fimaHelper); + } + } + + // + poiDrawer = new XCXFIMAPOIDrawer(); + poiDetector = new XCXFIMAPOIDetector(fimaHelper); + } + + // + // Deconstructor ... + ~XCXFIMABaseSignaller() + { + Destroy(); + } + + // + // Overrides ... + + // + // Actions ... + + /** + * Destroy ... + */ + void Destroy() + { + // + BeforeDestroy(); + + // + fimaInputs.Clean(); + + // + delete fimaHelper; + ZeroMemory(fimaHelper); + + // + delete poiDrawer; + ZeroMemory(poiDrawer); + + // + delete poiDetector; + ZeroMemory(poiDetector); + } + + // + // Virtuals ... + + /** + * Before Destroy ... + */ + void virtual BeforeDestroy() + { + } + + /** + * Processing Tick ... + * + * @param barIndex: int, Specified Bar Index ... + */ + virtual void ProcessTick(int barIndex = 0) + { + } + + /** + * Processing New Bar ... + * + * @param barIndex: int, Specified Bar Index ... + */ + virtual void ProcessNewBar(int barIndex = 0) + { + } + + /** + * Check Guards Based on MarketConditions ... + * + * @param guards: XGuard, reference collection to holds result ... + * @param positions: XPosition, reference collection to provides positions ... + * @param barIndex: int + * + * @return ( int ) + */ + int virtual CheckForGuard( + XGuard &guards[], + XPosition &positions[], + int barIndex = 0 // + ) + { + // + int result = 0; + + // + SpecifiedClean(guards); + + // + result = ArraySize(guards); + + // + return result; + } + + /** + * Check Additional Validations on Childs Instances ... + * + * @return ( bool virtual ) + */ + bool virtual CheckAdditionslSignallerValidations() + { + // + bool result = false; + + // + // Validate Fima Helper Requirements ... + result = fimaInputs.IsValid() && + fimaHelper != NULL && + poiDetector != NULL; + + // + return result; + } + + /** + * Normalizing Signal by Signaller Custom Props ... + * + * @param signal: XSignal ... + */ + void virtual NormalizeSignal(XSignal &signal) + { + } + + // + // Protected ... + protected: + // + + // + // Protected Actions ... + + /** + * 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 ... + * + * @param bar: XOHCL, reference to Pattern Bar ... + * @param patternName: string, detected pattern's name ... + * @param patternDir: ENUM_X_DIRECTION, detected pattern's direction ... + * @param fimaConditions: XFIMAConditions, reference to Bar Specified XFIMA Conditions ... + * + * @return ( bool ) + */ + bool ValidatePatternBasedOnMABand( + XOHCL &bar, + string patternName, + ENUM_X_DIRECTION patternDir, + XFIMAConditions &fimaConditions // + ) + { + // + bool result = false; + + // + // Validate ... + result = bar.IsValid() && + IsXValid(patternName) && + HasDirection(patternDir); + if (!result) + { + return result; + } + + // + // Define Requirements ... + bool isBullish = false; + bool isBearish = false; + double iPrice = EMPTY_VALUE; + double iPriceEdge = EMPTY_VALUE; + ENUM_X_PRICE iPriceType = X_PRICE_NONE; + ENUM_X_PRICE iPriceEdgeType = X_PRICE_NONE; + + // + // Calculating Price and Price Types ... + + // + isBullish = IsXBullish(patternDir); + isBearish = IsXBearish(patternDir); + + // + 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 ... + result = + NotEmptyZero(iPrice) && + IsXValid(iPriceType) && + NotEmptyZero(iPriceEdge) && + IsXValid(iPriceEdgeType) && + ((isBullish && !isBearish) || + (isBearish && !isBullish)); + if (!result) + { + return result; + } + + // + // Validate Pattern based on MA Band ... + + // + // Retrieve MA Band for Validation ... + double iMABandUpper = fimaConditions.maBondUpperBuffer[0]; + double iMABandLower = fimaConditions.maBondLowerBuffer[0]; + + // + // Validate by Edge Price ... + result = + NotEmptyZero(iMABandUpper) && + NotEmptyZero(iMABandLower) && + (isBullish + ? iPriceEdge < iMABandLower + : iPriceEdge > iMABandUpper); + if (!result) + { + return result; + } + + // + return result; + } + + // + // Private ... + private: + // +}; + +// +// XFIMA Strategy 2 Signaller Class ... +class XCXFIMAStrategy1Signaller : public XCXFIMABaseSignaller +{ + // + // Public ... + public: + // + // Props ... + CArrayObj drawnObjects; + // XFIMAPatternDetectorConfig analyserConfig; + + // + // Constructor ... + XCXFIMAStrategy1Signaller( + string _symbol, // Symbol ... + ENUM_TIMEFRAMES _period, // Period ... + XFIMAInputs &_fimaInputs, // XFIMAInputs ... + bool _processAllTicks = false, // Process All Ticks ... + double _defaultSignalR2R = 1.5, // Default Signal Risk To Reward Ratio ... + double _defaultSignalRiskInPoint = 50, // Default Signal Risk In Point ... + double _defaultSignalVolume = 0.01 // Default Signal Volume ... + ) : XCXFIMABaseSignaller("XFIMA1", + _symbol, + _period, + _fimaInputs, + _processAllTicks, + _defaultSignalR2R, + _defaultSignalRiskInPoint, + _defaultSignalVolume // + ) + { + // + // Configure Detector ... + + // + analyserConfig.Default(); + analyserConfig.validMACrossDiffMultiplier = 4; + + // + analyserConfig.FullDetect(); + + // + // Ignore Signal Targets ... + ignoreTargets = true; + } + + // + // Deconstructor ... + ~XCXFIMAStrategy1Signaller() + { + // + Destroy(); + + // + analyserConfig.Clean(); + } + + // + // Overrides ... + + /** + * Processing Tick ... + * + * @param barIndex: int, Specified Bar Index ... + */ + virtual void ProcessTick(int barIndex = 0) + { + } + + /** + * Processing New Bar ... + * + * @param barIndex: int, Specified Bar Index ... + */ + virtual void ProcessNewBar(int barIndex = 0) + { + // + // Normalize ... + barIndex = NormalizeInt(barIndex, 0); + + // + XOHCL iBar; + int count = 0; + XBoxZone iZone; + XSignal iSignal; + bool has = false; + XTarget iTargets[]; + string iName = NULL; + bool isBullish = false; + bool isBearish = false; + XPatternAnalysis iBarAnalysis; + XFIMAConditions iFIMAConditions; + XFIMAMarketStructure iStructure; + ENUM_X_DIRECTION iDir = X_DIRECTION_NONE; + + // + // Initialize Bar as CBar ... + has = iBar.Init( + symbol, + period, + barIndex // + ); + if (!has) + { + // + iBar.Clean(); + return; + } + + // + // Retrieve Conditions ... + has = fimaHelper.GetConditions( + iFIMAConditions, + barIndex, + 10 // Loopback ... + ); + if (!has) + { + // + iBar.Clean(); + iFIMAConditions.Clean(); + + // + return; + } + + // + // Analyse Market ... + poiDetector.AnalyseMarket( + iBar, + iStructure, + analyserConfig // + ); + + // + // Bar Pattern Analysis Detection Test ... + has = poiDetector.AnalyseBarPatterns( + iBar, + iBarAnalysis + // + // Use Default Config ... + ); + DrawBarPatternAnalysis(iBarAnalysis); + + // + // Disable Signallers ... + has = false; + iDir = X_DIRECTION_NONE; + + // + // Strategy 1 ... + // Works on Support or Resistances Areas ... + // has = Strategy1HasSignal( + // iBar, + // iZone, + // iTargets, + // iDir, + // iFIMAConditions, + // iStructure // + // ); + + // + // Strategy 2 ... + // Works on MA Crosses ... + if (!has) + { + // + // has = Strategy2HasSignal( + // iBar, + // iZone, + // iTargets, + // iDir, + // iFIMAConditions, + // iStructure // + // ); + } + + // + has = HasDirection(iDir); + if (has) + { + // + isBullish = IsXBullish(iDir); + isBearish = IsXBearish(iDir); + + // + // TODO: Provided SL ... + double _point = GetPoints(iBar.symbol); + double slAddition = 5 * _point; + double slPrice = + isBullish + ? iZone.lower - slAddition + : iZone.upper + slAddition; + + // + // Prepare Founded Signal ... + + // + // Handle Signal Targets ... + if (ignoreTargets) + { + XClean(iTargets); + } + + // + has = PrepareSignal( + iSignal, + iDir, + iTargets, + 0, // Use Default R2R ... + slPrice, // Provided Price for SL ... + 0 // Specified Risk in Point .... + ); + if (has) + { + // + // Notify On Signal Event ... + NotifySignalEventListeners(iSignal); + } + } + + // + // Cleanup Resources ... + iBar.Clean(); + iZone.Clean(); + iSignal.Clean(); + iStructure.Clean(); + iBarAnalysis.Clean(); + iFIMAConditions.Clean(); + SpecifiedClean(iTargets); + } + + /** + * Check Guards Based on MarketConditions ... + * + * @param guards: XGuard, reference collection to holds result ... + * @param positions: XPosition, reference collection to provides positions ... + * @param barIndex: int + * + * @return ( int ) + */ + int virtual CheckForGuard( + XGuard &guards[], + XPosition &positions[], + int barIndex = 0 // + ) + { + // + int result = 0; + + // + SpecifiedClean(guards); + + // + result = ArraySize(guards); + + // + return result; + } + + // + // Private ... + private: + // + // Props ... + + // + // Implementing Strategies ... + + /** + * Check Bar Has Signal Based on Strategy 1 ... + * + * @param bar: XOHCL, reference to Bar ... + * @param zone: XBoxZone, reference to holds affected zone ... + * @param targets: XTarget, reference to detected Signal's Targets collections ... + * @param dir: ENUM_X_DIRECTION, detected Signal's direction ... + * @param conditions: XFIMAConditions, reference to Bar Specified XFIMA Conditions ... + * @param structure: XFIMAMarketStructure, refrence to Provides Market Structure ... + * + * @return ( bool ) + */ + bool Strategy1HasSignal( + XOHCL &bar, + XBoxZone &zone, + XTarget &targets[], + ENUM_X_DIRECTION &dir, + XFIMAConditions &conditions, + XFIMAMarketStructure &structure // + ) + { + // + bool result = false; + + // + // Prepare ... + zone.Clean(); + XClean(targets); + dir = X_DIRECTION_NONE; + + // + // Validate ... + 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; + } + + // + // Validate Pattern Based on MA Band ... + result = ValidatePatternBasedOnMABand( + bar, + patternName, + patternDir, + conditions // + ); + if (!result) + { + return result; + } + + // + // Here i Use Specified Supports and Resistances ... + XBoxZone tmpBox; + bool has = false; + XBoxZone supports[]; + XBoxZone resistances[]; + + // + has = structure.pvAnalysis.IsValid() && + structure.pvAnalysis.HasSupportBox(tmpBox); + if (has) + { + // + tmpBox.to = bar.time; + AddIfNotExists( + tmpBox, + supports // + ); + } + + // + has = structure.zigzagAnalysis.IsValid() && + structure.zigzagAnalysis.HasSupportBox(tmpBox); + if (has) + { + // + tmpBox.to = bar.time; + AddIfNotExists( + tmpBox, + supports // + ); + } + + // + has = structure.pvAnalysis.IsValid() && + structure.pvAnalysis.HasResistanceBox(tmpBox); + if (has) + { + // + tmpBox.to = bar.time; + AddIfNotExists( + tmpBox, + resistances // + ); + } + + // + has = structure.zigzagAnalysis.IsValid() && + structure.zigzagAnalysis.HasResistanceBox(tmpBox); + if (has) + { + // + tmpBox.to = bar.time; + AddIfNotExists( + tmpBox, + resistances // + ); + } + + // + // Check Affected Zone ... + // Select a Support or Resistance ... + int insideZoneIDX = -1; + result = + (IsXBullish(patternDir) + ? HasInside( + insideZoneIDX, + bar, + supports // + ) + : IsXBearish(patternDir) + ? HasInside( + insideZoneIDX, + bar, + resistances // + ) + : false // + ); + if (!result) + { + return result; + } + + // + // Filling Affected Zone ... + // and Validate it ... + if (IsXBullish(patternDir)) + { + zone = supports[insideZoneIDX]; + } + else if (IsXBearish(patternDir)) + { + zone = resistances[insideZoneIDX]; + } + result = zone.IsValid(); + if (!result) + { + return result; + } + + // + // Validate affected Zone based on Pattern's Bar ... + result = IsXBullish(patternDir) + ? bar.high > zone.upper + : IsXBearish(patternDir) + ? bar.low < zone.lower + : false; + // + // Validate Zone ... + if (result) + { + // + // + } + + // + // Draw Requirements ... + // if (result) + // { + // // + // // Support and Resistances ... + // CArrayObj *zoneObjs; + // poiDrawer.DrawBoxes( + // supports, + // zoneObjs // + // ); + // poiDrawer.DrawBoxes( + // resistances, + // zoneObjs // + // ); + + // // + // // Zone ... + // XCBoxObject *iZoneObj; + // bool isDrawn = poiDrawer.DrawBox( + // zone, + // iZoneObj, + // true, + // zone.type // + // ); + // if (isDrawn) + // { + // // + // XPOIStyle iStyle; + // iStyle.width = 2; + // iStyle.clr = clrYellow; + // poiDrawer.ApplyBoxStyle( + // iZoneObj, + // iStyle // + // ); + // } + + // // + // // Pattern ... + // XCBarArrowObject *iPObj; + // poiDrawer.DrawBarArrow( + // bar, + // iPObj, + // zone.IsBullish() ? X_PRICE_LOW : X_PRICE_HIGH, + // 159, + // clrYellow, + // 3, // With ... + // zone.IsBullish() ? ANCHOR_BOTTOM : ANCHOR_TOP, + // patternName // + // ); + + // // poiDrawer.DrawBoxes( + // // structure.fvgs, + // // zoneObjs, + // // false // + // // ); + + // Print("SALAM"); + // } + + if (result) + { + // + dir = patternDir; + + // + // Handle Targets Detection ... + + // + // Check Reversal FVGS ... + int idx = -1; + XTarget target; + XBoxZone targetZones[]; + int numberOfTargets = 3; + double actingDistance = 20; + double iValue = EMPTY_VALUE; + bool ignoreFirstTarget = false; + ENUM_X_DIRECTION targetsDir = Opposit(dir); + int count = ExtractByDirection( + targetZones, + structure.fvgs, + targetsDir // + ); + bool has = IsValidSize(count); + if (has) + { + // + // Calculate Value ... + double points = GetPoints(zone.symbol); + double zoneRange = zone.upper - zone.lower; + iValue = IsXBullish(dir) + ? (zone.upper + (zoneRange * defaultSignalR2R)) + : (zone.lower + (zoneRange * defaultSignalR2R)); + double defaultTarget = iValue; + + // + // Looping Back ... + for (int i = 0; i < numberOfTargets; i++) + { + // + // Detect Lowest Above Zone ... + if (IsXBullish(dir)) + { + // + idx = GetLowestAbove(iValue, targetZones); + has = IsValidIndex(idx); + if (!has) + { + break; + } + + // + iValue = targetZones[idx].lower; + } + // + // Detect Highest below Zone ... + else if (IsXBearish(dir)) + { + // + idx = GetHighestBelow(iValue, targetZones); + has = IsValidIndex(idx); + if (!has) + { + break; + } + + // + iValue = targetZones[idx].upper; + } + + // + // Validate Target Value ... + has = NotEmptyZero(iValue) && + iValue != defaultTarget; + if (has) + { + // + // Init Target ... + target.Clean(); + target.doRF = true; + target.target = iValue; + target.actingDistance = actingDistance; + has = target.IsValid(); + if (has) + { + // + // Add Target to Targets ... + AddRef( + target, + targets // + ); + } + target.Clean(); + } + } + + // + // Remove Nearest ... + has = ignoreFirstTarget && + HasChild(targets); + if (has) + { + // + ArrayRemove( + targets, + 0, + 1 // + ); + } + } + + // + // Cleanup Resources ... + target.Clean(); + XClean(targetZones); + } + + // + // Cleanup Resources ... + if (!result) + { + // + zone.Clean(); + XClean(targets); + } + + // + return result; + } + + /** + * Check Bar Has Signal Based on Strategy 1 ... + * + * @param bar: XOHCL, reference to Bar ... + * @param zone: XBoxZone, reference to holds affected zone ... + * @param targets: XTarget, reference to detected Signal's Targets collections ... + * @param dir: ENUM_X_DIRECTION, detected Signal's direction ... + * @param conditions: XFIMAConditions, reference to Bar Specified XFIMA Conditions ... + * @param structure: XFIMAMarketStructure, refrence to Provides Market Structure ... + * + * @return ( bool ) + */ + bool Strategy2HasSignal( + XOHCL &bar, + XBoxZone &zone, + XTarget &targets[], + ENUM_X_DIRECTION &dir, + XFIMAConditions &conditions, + XFIMAMarketStructure &structure // + ) + { + // + bool result = false; + + // + // Prepare ... + zone.Clean(); + XClean(targets); + dir = X_DIRECTION_NONE; + + // + // Validate ... + result = bar.IsValid(); + if (!result) + { + return result; + } + + // + // Detect Specified MA Cross ... + result = HasDirection(structure.maCrossDir); + + // + // Prepare zone ... + if (result) + { + // + zone.to = bar.time; + zone.from = GetBarTime( + bar.symbol, + bar.period, + bar.Index() + 2 // + ); + zone.symbol = bar.symbol; + zone.period = bar.period; + zone.dir = structure.maCrossDir; + zone.lower = bar.FindLowest(2, MODE_LOW); + zone.upper = bar.FindHighest(2, MODE_HIGH); + zone.type = name + "_" + ToXString(structure.maCrossDir); + + // + result = zone.IsValid(); + } + + // + // Check Result ... + if (result) + { + // + dir = structure.maCrossDir; + + // + // Handle Targets Detection ... + } + + // + // Cleanup Resources ... + if (!result) + { + // + zone.Clean(); + XClean(targets); + } + + // + return result; + } + + // + // Drawer Functions ... + + /** + * Draw Specified Pattern info ... + * + * @param _bar: XOHCL, reference to Pattern's Bar ... + * @param _pivot: XPivot, reference to Pattern's Pivot ... + * @param _zone: XBoxZone, reference to Pattern's Zone ... + * @param _pattern: ENUM_X_BAR_PATTERN, Specified Bar Pattern ... + * @param _patternDir: ENUM_X_DIRECTION, Specified Bar Pattern's Direction ... + */ + void DrawPattern( + XOHCL &_bar, + XPivot &_pivot, + XBoxZone &_zone, + ENUM_X_BAR_PATTERN _pattern, + ENUM_X_DIRECTION _patternDir, + int thresholdMultiplier = 0 // + ) + { + // + // Normalize ... + thresholdMultiplier = NormalizeInt(thresholdMultiplier, 1); + + // + // Validate ... + bool has = + poiDrawer != NULL && + _bar.IsValid() && + IsXValid(_pattern) && + HasDirection(_patternDir); + if (!has) + { + return; + } + + // + // Defien Draw Requirements ... + + // + int width = 3; + bool ignoreBoxAt = true; + int arrowThreshold = 5 * thresholdMultiplier; + + // + int bullishArrow = 159; + int bearishArrow = 159; + + // + ENUM_X_PRICE arrowValePriceType = X_PRICE_LOW; + ENUM_X_PRICE arrowPeakPriceType = X_PRICE_HIGH; + + // + color bullishColor = clrAqua; + color bearishColor = clrMagenta; + + // + // Draw Bar ... + + // + // Draw Pivot ... + if (_pivot.IsValid()) + { + // + XCBarArrowObject *iObj; + has = poiDrawer.DrawBarArrow( + _bar, + iObj, + _pivot.IsPeak() + ? arrowPeakPriceType + : arrowValePriceType, + IsXBullish(_patternDir) + ? bullishArrow + : bearishArrow, + IsXBullish(_patternDir) + ? bullishColor + : bearishColor, + width, + IsXBullish(_patternDir) + ? ANCHOR_TOP + : ANCHOR_BOTTOM, + _pivot.prefix + "_Pivot_" + ToXString(TimeToSeconds(_pivot.time)), + true, // Ignore Bar Tag ... + arrowThreshold // Threshold ... + ); + if (has) + { + drawnObjects.Add(iObj); + } + + // + ZeroMemory(iObj); + } + + // + // Draw Box ... + if (_zone.IsValid()) + { + // + XCBoxObject *iObj; + has = poiDrawer.DrawBox( + _zone, + iObj, + ignoreBoxAt, + _zone.type + "_Zone_" + ToXString(TimeToSeconds(_zone.from)) // + ); + if (has) + { + // + XPOIStyle iStyle; + poiDrawer.GetBoxStyle( + iStyle, + _zone.dir // + ); + + // + iStyle.clr = + IsXBullish(_patternDir) + ? bullishColor + : bearishColor; + + // + poiDrawer.ApplyBoxStyle( + iObj, + iStyle // + ); + + // + drawnObjects.Add(iObj); + + // + iStyle.Clean(); + } + + // + ZeroMemory(iObj); + } + } + + /** + * Draw Specified Bar Pattern Analysis ... + * + * @param barAnalysis: XPatternAnalysis, reference to Specified Bar Pattern Analysis ... + */ + void DrawBarPatternAnalysis(XPatternAnalysis &barAnalysis) + { + // + bool has = barAnalysis.IsValid(); + if (!has) + { + return; + } + + // + // Configure Draws ... + XPatternAnalysisDrawConfig config; + config.Clean(); + + // + Add(X_BAR_PATTERN_LOW, config.allowedDraws); + Add(X_BAR_PATTERN_HIGH, config.allowedDraws); + Add(X_BAR_PATTERN_STAR, config.allowedDraws); + Add(X_BAR_PATTERN_FLAG, config.allowedDraws); + Add(X_BAR_PATTERN_PINNED, config.allowedDraws); + Add(X_BAR_PATTERN_RISING, config.allowedDraws); + Add(X_BAR_PATTERN_MOMENTUM, config.allowedDraws); + Add(X_BAR_PATTERN_ENGULFED, config.allowedDraws); + Add(X_BAR_PATTERN_PIERCING, config.allowedDraws); + Add(X_BAR_PATTERN_SIGNALKEY, config.allowedDraws); + Add(X_BAR_PATTERN_TRUE_GAPED, config.allowedDraws); + + // + Add(X_BAR_PATTERN_LOW, config.allowedDrawPivots); + Add(X_BAR_PATTERN_HIGH, config.allowedDrawPivots); + Add(X_BAR_PATTERN_PINNED, config.allowedDrawPivots); + Add(X_BAR_PATTERN_MOMENTUM, config.allowedDrawPivots); + Add(X_BAR_PATTERN_ENGULFED, config.allowedDrawPivots); + Add(X_BAR_PATTERN_TRUE_GAPED, config.allowedDrawPivots); + + // + Add(X_BAR_PATTERN_STAR, config.allowedDrawZones); + Add(X_BAR_PATTERN_FLAG, config.allowedDrawZones); + Add(X_BAR_PATTERN_RISING, config.allowedDrawZones); + Add(X_BAR_PATTERN_PIERCING, config.allowedDrawZones); + Add(X_BAR_PATTERN_SIGNALKEY, config.allowedDrawZones); + + // + Add(X_BAR_PATTERN_SUPPORT, config.allowedDraws); + Add(X_BAR_PATTERN_RESISTANCE, config.allowedDraws); + + // + Add(X_BAR_PATTERN_SUPPORT, config.allowedDrawZones); + Add(X_BAR_PATTERN_RESISTANCE, config.allowedDrawZones); + + // + config.Clean(); + + // + // Draw Bar Patterns Analysis ... + + // + bool canDraw; + bool isBullish; + bool isBearish; + XOHCL patternBar; + bool canDrawZone; + bool canDrawPivot; + XPivot patternPivot; + XBoxZone patternBox; + ENUM_X_BAR_PATTERN pattern; + ENUM_X_DIRECTION patternDir; + + // + int patternsPivotThresholdMultiplier = 0; + + // + // Support and Resistance ... + + // + // Support ... + isBearish = false; + isBullish = barAnalysis.IsSupport(); + has = isBullish; + if (has) + { + // + pattern = X_BAR_PATTERN_SUPPORT; + patternDir = X_DIRECTION_BULLISH; + canDraw = config.CanDraw(pattern); + if (canDraw) + { + // + has = barAnalysis.GetPattern( + patternBar, + patternPivot, + patternBox, + pattern, + patternDir // + ); + if (has) + { + // + canDrawZone = config.CanDrawZone(pattern); + if (!canDrawZone) + { + patternBox.Clean(); + } + + // + canDrawPivot = config.CanDrawPivot(pattern); + if (!canDrawPivot) + { + patternPivot.Clean(); + } + else + { + patternsPivotThresholdMultiplier++; + } + + // + DrawPattern( + patternBar, + patternPivot, + patternBox, + pattern, + patternDir, + patternsPivotThresholdMultiplier // + ); + } + } + } + + // + // Resistance ... + isBullish = false; + isBearish = barAnalysis.IsResistance(); + has = isBearish; + if (has) + { + // + pattern = X_BAR_PATTERN_RESISTANCE; + patternDir = X_DIRECTION_BEARISH; + canDraw = config.CanDraw(pattern); + if (canDraw) + { + // + has = barAnalysis.GetPattern( + patternBar, + patternPivot, + patternBox, + pattern, + patternDir // + ); + if (has) + { + // + canDrawZone = config.CanDrawZone(pattern); + if (!canDrawZone) + { + patternBox.Clean(); + } + + // + canDrawPivot = config.CanDrawPivot(pattern); + if (!canDrawPivot) + { + patternPivot.Clean(); + } + else + { + patternsPivotThresholdMultiplier++; + } + + // + DrawPattern( + patternBar, + patternPivot, + patternBox, + pattern, + patternDir, + patternsPivotThresholdMultiplier // + ); + } + } + } + + // + // PV: High and Low ... + + // + // Low ... + isBearish = false; + isBullish = barAnalysis.IsLow(); + has = isBullish; + if (has) + { + // + pattern = X_BAR_PATTERN_LOW; + patternDir = X_DIRECTION_BULLISH; + canDraw = config.CanDraw(pattern); + if (canDraw) + { + // + has = barAnalysis.GetPattern( + patternBar, + patternPivot, + patternBox, + pattern, + patternDir // + ); + if (has) + { + // + canDrawZone = config.CanDrawZone(pattern); + if (!canDrawZone) + { + patternBox.Clean(); + } + + // + canDrawPivot = config.CanDrawPivot(pattern); + if (!canDrawPivot) + { + patternPivot.Clean(); + } + else + { + patternsPivotThresholdMultiplier++; + } + + // + DrawPattern( + patternBar, + patternPivot, + patternBox, + pattern, + patternDir, + patternsPivotThresholdMultiplier // + ); + } + } + } + + // + // High ... + isBullish = false; + isBearish = barAnalysis.IsHigh(); + has = isBearish; + if (has) + { + // + pattern = X_BAR_PATTERN_HIGH; + patternDir = X_DIRECTION_BEARISH; + canDraw = config.CanDraw(pattern); + if (canDraw) + { + // + has = barAnalysis.GetPattern( + patternBar, + patternPivot, + patternBox, + pattern, + patternDir // + ); + if (has) + { + // + canDrawZone = config.CanDrawZone(pattern); + if (!canDrawZone) + { + patternBox.Clean(); + } + + // + canDrawPivot = config.CanDrawPivot(pattern); + if (!canDrawPivot) + { + patternPivot.Clean(); + } + else + { + patternsPivotThresholdMultiplier++; + } + + // + DrawPattern( + patternBar, + patternPivot, + patternBox, + pattern, + patternDir, + patternsPivotThresholdMultiplier // + ); + } + } + } + + // + // OB ... + isBullish = barAnalysis.IsOB(X_DIRECTION_BULLISH); + isBearish = barAnalysis.IsOB(X_DIRECTION_BEARISH); + has = isBullish || isBearish; + if (has) + { + // + pattern = X_BAR_PATTERN_OB; + patternDir = + isBullish + ? X_DIRECTION_BULLISH + : X_DIRECTION_BEARISH; + canDraw = config.CanDraw(pattern); + if (canDraw) + { + // + has = barAnalysis.GetPattern( + patternBar, + patternPivot, + patternBox, + pattern, + patternDir // + ); + if (has) + { + // + canDrawZone = config.CanDrawZone(pattern); + if (!canDrawZone) + { + patternBox.Clean(); + } + + // + canDrawPivot = config.CanDrawPivot(pattern); + if (!canDrawPivot) + { + patternPivot.Clean(); + } + else + { + patternsPivotThresholdMultiplier++; + } + + // + DrawPattern( + patternBar, + patternPivot, + patternBox, + pattern, + patternDir, + patternsPivotThresholdMultiplier // + ); + } + } + } + + // + // FVG ... + isBullish = barAnalysis.IsFVG(X_DIRECTION_BULLISH); + isBearish = barAnalysis.IsFVG(X_DIRECTION_BEARISH); + has = isBullish || isBearish; + if (has) + { + // + pattern = X_BAR_PATTERN_FVG; + patternDir = + isBullish + ? X_DIRECTION_BULLISH + : X_DIRECTION_BEARISH; + canDraw = config.CanDraw(pattern); + if (canDraw) + { + // + has = barAnalysis.GetPattern( + patternBar, + patternPivot, + patternBox, + pattern, + patternDir // + ); + if (has) + { + // + canDrawZone = config.CanDrawZone(pattern); + if (!canDrawZone) + { + patternBox.Clean(); + } + + // + canDrawPivot = config.CanDrawPivot(pattern); + if (!canDrawPivot) + { + patternPivot.Clean(); + } + else + { + patternsPivotThresholdMultiplier++; + } + + // + DrawPattern( + patternBar, + patternPivot, + patternBox, + pattern, + patternDir, + patternsPivotThresholdMultiplier // + ); + } + } + } + + // + // Momentum ... + isBullish = barAnalysis.IsMomentum(X_DIRECTION_BULLISH); + isBearish = barAnalysis.IsMomentum(X_DIRECTION_BEARISH); + has = isBullish || isBearish; + if (has) + { + // + pattern = X_BAR_PATTERN_MOMENTUM; + patternDir = + isBullish + ? X_DIRECTION_BULLISH + : X_DIRECTION_BEARISH; + canDraw = config.CanDraw(pattern); + if (canDraw) + { + // + has = barAnalysis.GetPattern( + patternBar, + patternPivot, + patternBox, + pattern, + patternDir // + ); + if (has) + { + // + canDrawZone = config.CanDrawZone(pattern); + if (!canDrawZone) + { + patternBox.Clean(); + } + + // + canDrawPivot = config.CanDrawPivot(pattern); + if (!canDrawPivot) + { + patternPivot.Clean(); + } + else + { + patternsPivotThresholdMultiplier++; + } + + // + DrawPattern( + patternBar, + patternPivot, + patternBox, + pattern, + patternDir, + patternsPivotThresholdMultiplier // + ); + } + } + } + + // + // Engulfed ... + isBullish = barAnalysis.IsEngulfed(X_DIRECTION_BULLISH); + isBearish = barAnalysis.IsEngulfed(X_DIRECTION_BEARISH); + has = isBullish || isBearish; + if (has) + { + // + pattern = X_BAR_PATTERN_ENGULFED; + patternDir = + isBullish + ? X_DIRECTION_BULLISH + : X_DIRECTION_BEARISH; + canDraw = config.CanDraw(pattern); + if (canDraw) + { + // + has = barAnalysis.GetPattern( + patternBar, + patternPivot, + patternBox, + pattern, + patternDir // + ); + if (has) + { + // + canDrawZone = config.CanDrawZone(pattern); + if (!canDrawZone) + { + patternBox.Clean(); + } + + // + canDrawPivot = config.CanDrawPivot(pattern); + if (!canDrawPivot) + { + patternPivot.Clean(); + } + else + { + patternsPivotThresholdMultiplier++; + } + + // + DrawPattern( + patternBar, + patternPivot, + patternBox, + pattern, + patternDir, + patternsPivotThresholdMultiplier // + ); + } + } + } + + // + // Pinned ... + isBullish = barAnalysis.IsPinned(X_DIRECTION_BULLISH); + isBearish = barAnalysis.IsPinned(X_DIRECTION_BEARISH); + has = isBullish || isBearish; + if (has) + { + // + pattern = X_BAR_PATTERN_PINNED; + patternDir = + isBullish + ? X_DIRECTION_BULLISH + : X_DIRECTION_BEARISH; + canDraw = config.CanDraw(pattern); + if (canDraw) + { + // + has = barAnalysis.GetPattern( + patternBar, + patternPivot, + patternBox, + pattern, + patternDir // + ); + if (has) + { + // + canDrawZone = config.CanDrawZone(pattern); + if (!canDrawZone) + { + patternBox.Clean(); + } + + // + canDrawPivot = config.CanDrawPivot(pattern); + if (!canDrawPivot) + { + patternPivot.Clean(); + } + else + { + patternsPivotThresholdMultiplier++; + } + + // + DrawPattern( + patternBar, + patternPivot, + patternBox, + pattern, + patternDir, + patternsPivotThresholdMultiplier // + ); + } + } + } + + // + // TrueGaped ... + isBullish = barAnalysis.IsTrueGaped(X_DIRECTION_BULLISH); + isBearish = barAnalysis.IsTrueGaped(X_DIRECTION_BEARISH); + has = isBullish || isBearish; + if (has) + { + // + pattern = X_BAR_PATTERN_TRUE_GAPED; + patternDir = + isBullish + ? X_DIRECTION_BULLISH + : X_DIRECTION_BEARISH; + canDraw = config.CanDraw(pattern); + if (canDraw) + { + // + has = barAnalysis.GetPattern( + patternBar, + patternPivot, + patternBox, + pattern, + patternDir // + ); + if (has) + { + // + canDrawZone = config.CanDrawZone(pattern); + if (!canDrawZone) + { + patternBox.Clean(); + } + + // + canDrawPivot = config.CanDrawPivot(pattern); + if (!canDrawPivot) + { + patternPivot.Clean(); + } + else + { + patternsPivotThresholdMultiplier++; + } + + // + DrawPattern( + patternBar, + patternPivot, + patternBox, + pattern, + patternDir, + patternsPivotThresholdMultiplier // + ); + } + } + } + + // + // Star ... + isBullish = barAnalysis.IsStar(X_DIRECTION_BULLISH); + isBearish = barAnalysis.IsStar(X_DIRECTION_BEARISH); + has = isBullish || isBearish; + if (has) + { + // + pattern = X_BAR_PATTERN_STAR; + patternDir = + isBullish + ? X_DIRECTION_BULLISH + : X_DIRECTION_BEARISH; + canDraw = config.CanDraw(pattern); + if (canDraw) + { + // + has = barAnalysis.GetPattern( + patternBar, + patternPivot, + patternBox, + pattern, + patternDir // + ); + if (has) + { + // + canDrawZone = config.CanDrawZone(pattern); + if (!canDrawZone) + { + patternBox.Clean(); + } + + // + canDrawPivot = config.CanDrawPivot(pattern); + if (!canDrawPivot) + { + patternPivot.Clean(); + } + else + { + patternsPivotThresholdMultiplier++; + } + + // + DrawPattern( + patternBar, + patternPivot, + patternBox, + pattern, + patternDir, + patternsPivotThresholdMultiplier // + ); + } + } + } + + // + // Piercing ... + isBullish = barAnalysis.IsPiercing(X_DIRECTION_BULLISH); + isBearish = barAnalysis.IsPiercing(X_DIRECTION_BEARISH); + has = isBullish || isBearish; + if (has) + { + // + pattern = X_BAR_PATTERN_PIERCING; + patternDir = + isBullish + ? X_DIRECTION_BULLISH + : X_DIRECTION_BEARISH; + canDraw = config.CanDraw(pattern); + if (canDraw) + { + // + has = barAnalysis.GetPattern( + patternBar, + patternPivot, + patternBox, + pattern, + patternDir // + ); + if (has) + { + // + canDrawZone = config.CanDrawZone(pattern); + if (!canDrawZone) + { + patternBox.Clean(); + } + + // + canDrawPivot = config.CanDrawPivot(pattern); + if (!canDrawPivot) + { + patternPivot.Clean(); + } + else + { + patternsPivotThresholdMultiplier++; + } + + // + DrawPattern( + patternBar, + patternPivot, + patternBox, + pattern, + patternDir, + patternsPivotThresholdMultiplier // + ); + } + } + } + + // + // Rising ... + isBullish = barAnalysis.IsRising(X_DIRECTION_BULLISH); + isBearish = barAnalysis.IsRising(X_DIRECTION_BEARISH); + has = isBullish || isBearish; + if (has) + { + // + pattern = X_BAR_PATTERN_RISING; + patternDir = + isBullish + ? X_DIRECTION_BULLISH + : X_DIRECTION_BEARISH; + canDraw = config.CanDraw(pattern); + if (canDraw) + { + // + has = barAnalysis.GetPattern( + patternBar, + patternPivot, + patternBox, + pattern, + patternDir // + ); + if (has) + { + // + canDrawZone = config.CanDrawZone(pattern); + if (!canDrawZone) + { + patternBox.Clean(); + } + + // + canDrawPivot = config.CanDrawPivot(pattern); + if (!canDrawPivot) + { + patternPivot.Clean(); + } + else + { + patternsPivotThresholdMultiplier++; + } + + // + DrawPattern( + patternBar, + patternPivot, + patternBox, + pattern, + patternDir, + patternsPivotThresholdMultiplier // + ); + } + } + } + + // + // Flag ... + isBullish = barAnalysis.IsFlag(X_DIRECTION_BULLISH); + isBearish = barAnalysis.IsFlag(X_DIRECTION_BEARISH); + has = isBullish || isBearish; + if (has) + { + // + pattern = X_BAR_PATTERN_FLAG; + patternDir = + isBullish + ? X_DIRECTION_BULLISH + : X_DIRECTION_BEARISH; + canDraw = config.CanDraw(pattern); + if (canDraw) + { + // + has = barAnalysis.GetPattern( + patternBar, + patternPivot, + patternBox, + pattern, + patternDir // + ); + if (has) + { + // + canDrawZone = config.CanDrawZone(pattern); + if (!canDrawZone) + { + patternBox.Clean(); + } + + // + canDrawPivot = config.CanDrawPivot(pattern); + if (!canDrawPivot) + { + patternPivot.Clean(); + } + else + { + patternsPivotThresholdMultiplier++; + } + + // + DrawPattern( + patternBar, + patternPivot, + patternBox, + pattern, + patternDir, + patternsPivotThresholdMultiplier // + ); + } + } + } + + // + // SignalKey ... + isBullish = barAnalysis.IsSignalKey(X_DIRECTION_BULLISH); + isBearish = barAnalysis.IsSignalKey(X_DIRECTION_BEARISH); + has = isBullish || isBearish; + if (has) + { + // + pattern = X_BAR_PATTERN_SIGNALKEY; + patternDir = + isBullish + ? X_DIRECTION_BULLISH + : X_DIRECTION_BEARISH; + canDraw = config.CanDraw(pattern); + if (canDraw) + { + // + has = barAnalysis.GetPattern( + patternBar, + patternPivot, + patternBox, + pattern, + patternDir // + ); + if (has) + { + // + canDrawZone = config.CanDrawZone(pattern); + if (!canDrawZone) + { + patternBox.Clean(); + } + + // + canDrawPivot = config.CanDrawPivot(pattern); + if (!canDrawPivot) + { + patternPivot.Clean(); + } + else + { + patternsPivotThresholdMultiplier++; + } + + // + DrawPattern( + patternBar, + patternPivot, + patternBox, + pattern, + patternDir, + patternsPivotThresholdMultiplier // + ); + } + } + } + + // + // Cleanup Resources ... + patternBar.Clean(); + patternBox.Clean(); + patternPivot.Clean(); + } + + // +}; + +// \ No newline at end of file diff --git a/Experts/x-saherelm.xfima.backtester.ea.mq5 b/Experts/x-saherelm.xfima.backtester.ea.mq5 index 47aa7402..c9db4616 100644 --- a/Experts/x-saherelm.xfima.backtester.ea.mq5 +++ b/Experts/x-saherelm.xfima.backtester.ea.mq5 @@ -153,9 +153,9 @@ XCBackTesterEA *eaExpert; // EA Expert ... XCXFIMAStrategy1Signaller *fima1Signaller; // XFIMA1 Signaller ... // -XFIMAMarketStructure marketStructure; // POI Analysis Result ... -XFIMAPatternDetectorConfig detectorConfig; // POI Detector Config ... -XFIMAMarketStructureDrawerConfig marketStructureDrawerConfig; // POI Drawer Config ... +// XFIMAMarketStructure marketStructure; // POI Analysis Result ... +// XFIMAPatternDetectorConfig detectorConfig; // POI Detector Config ... +// XFIMAMarketStructureDrawerConfig marketStructureDrawerConfig; // POI Drawer Config ... // // Drawer and eaDraws ... @@ -426,9 +426,9 @@ int OnInit() // // Configure XFIMA POI Detector / Drawer ... - detectorConfig.Default(); - detectorConfig.FullDetect(); - marketStructureDrawerConfig.FullDraw(); + // detectorConfig.Default(); + // detectorConfig.FullDetect(); + // marketStructureDrawerConfig.FullDraw(); // Print(ShortName, ": Initialized Successfully ..."); diff --git a/Helpers/x-saherelm.xfima.helper.mq5 b/Helpers/x-saherelm.xfima.helper.mq5 index 102a4976..c46cc33c 100644 --- a/Helpers/x-saherelm.xfima.helper.mq5 +++ b/Helpers/x-saherelm.xfima.helper.mq5 @@ -908,6 +908,14 @@ class XCXFIMAHelper : public XCBaseHelper barIndex = NormalizeInt(barIndex, 0); validCrossDiffMultiplier = NormalizeDouble(validCrossDiffMultiplier, 0); + // + // Validate ... + result = IsValid(); + if (!result) + { + return result; + } + // double fast[]; int fastCount = CopyMAFast(barIndex, 2, fast); @@ -1107,7 +1115,7 @@ class XCXFIMAHelper : public XCBaseHelper // // Validate ... - result = mHandler != INVALID_HANDLE; + result = IsValid(); if (!result) { return result; @@ -1166,6 +1174,262 @@ class XCXFIMAHelper : public XCBaseHelper return result; } + /** + * Check Specified Bar's Price in Hot Place or Not ... + * + * @param dir: reference for holds cross Direction ... + * @param barIndex: int, Specified Bar Index ... + * @param overMaxPriceType: ENUM_X_PRICE, which price of Specified bar to Check ... + * @param underMinPriceType: ENUM_X_PRICE, which price of Specified bar to Check ... + * + * @return ( bool ) + */ + bool IsInHotPlace( + ENUM_X_DIRECTION &dir, + int barIndex = 0, + ENUM_X_PRICE overMaxPriceType = X_PRICE_NONE, + ENUM_X_PRICE underMinPriceType = X_PRICE_NONE // + ) + { + // + bool result = false; + + // + // Prepare ... + dir = X_DIRECTION_NONE; + + // + // Normalize ... + barIndex = NormalizeBarIndex(barIndex); + if (!IsXValid(overMaxPriceType)) + { + overMaxPriceType = X_PRICE_LOW; + } + if (!IsXValid(underMinPriceType)) + { + underMinPriceType = X_PRICE_HIGH; + } + + // + // Validate ... + result = IsValid(); + if (!result) + { + return result; + } + + // + // Initialize Bar ... + XOHCL bar; + result = bar.Init( + mSymbol, + mPeriod, + barIndex); + if (!result) + { + // + bar.Clean(); + return result; + } + + // + double overMaxPrice = bar.GetPrice(overMaxPriceType); + double underMinPrice = bar.GetPrice(underMinPriceType); + + // + // Reading Boundary Value ... + double min; + double max; + result = GetBoundaryValues( + min, + max, + barIndex // + ); + if (!result) + { + // + bar.Clean(); + return result; + } + + // + bool isBullish = underMinPrice < min; + bool isBearish = overMaxPrice > max; + + // + result = (isBullish && !isBearish) || + (isBearish && !isBullish); + if (result) + { + // + dir = + isBullish + ? X_DIRECTION_BULLISH + : X_DIRECTION_BEARISH; + } + + // + // Cleanup Resources ... + bar.Clean(); + + // + return result; + } + + bool ( + ENUM_X_DIRECTION &dir, + int barIndex = 0 // + ) + { + // + bool result = false; + + // + // Prepare ... + dir = X_DIRECTION_NONE; + + // + // Normalize ... + barIndex = NormalizeBarIndex(barIndex); + + // + // Validate ... + result = IsValid(); + if (!result) + { + return result; + } + + // + double fast = GetMAFast(barIndex); + double slow = GetMASlow(barIndex); + + // + double maBondUpper = GetMABondUpper(barIndex); + double maBondLower = GetMABondLower(barIndex); + + // + double pbBondUpper = GetPBBondUpper(barIndex); + double pbBondLower = GetPBBondLower(barIndex); + + // + double hkBondUpper = GetHKBondUpper(barIndex); + double hkBondLower = GetHKBondLower(barIndex); + + // + result = + NotEmptyZero(fast) && + NotEmptyZero(slow) && + NotEmptyZero(maBondUpper) && + NotEmptyZero(maBondLower) && + NotEmptyZero(hkBondUpper) && + NotEmptyZero(hkBondLower) && + NotEmptyZero(pbBondUpper) && + NotEmptyZero(pbBondLower); + if (!result) + { + return result; + } + + // + bool isBullish = + fast > hkBondLower && + slow > hkBondLower && + maBondUpper > hkBondLower && + maBondLower > hkBondLower && + pbBondUpper > hkBondLower && + pbBondLower > hkBondLower; + bool isBearish = + fast < hkBondUpper && + slow < hkBondUpper && + maBondUpper < hkBondUpper && + maBondLower < hkBondUpper && + pbBondUpper < hkBondUpper && + pbBondLower < hkBondUpper; + + // + result = (isBullish && !isBearish) || + (isBearish && !isBullish); + if (result) + { + // + dir = + isBullish + ? X_DIRECTION_BULLISH + : X_DIRECTION_BEARISH; + } + + // + return result; + } + + bool HasBoundarySwitch( + ENUM_X_DIRECTION &dir, + int barIndex = 0 // + ) + { + // + bool result = false; + + // + // Prepare ... + dir = X_DIRECTION_NONE; + + // + // Normalize ... + barIndex = NormalizeBarIndex(barIndex); + + // + // Validate ... + result = IsValid(); + if (!result) + { + return result; + } + + // + result = HasBoundaryTrend( + dir, + barIndex // + ); + if (!result) + { + return result; + } + bool isBullish = IsXBullish(dir); + bool isBearish = IsXBearish(dir); + + // + result = HasBoundaryTrend( + dir, + barIndex + 1 // + ); + if (!result) + { + return result; + } + bool isPBullish = IsXBullish(dir); + bool isPBearish = IsXBearish(dir); + + // + bool isSwitchedToBullish = + isBullish && !isPBullish; + bool isSwitchedToBearish = + isBearish && !isPBearish; + result = isSwitchedToBullish || + isSwitchedToBearish; + if (result) + { + // + dir = isSwitchedToBullish + ? X_DIRECTION_BULLISH + : X_DIRECTION_BEARISH; + } + + // + return result; + } + /** * Check Peak Happens over Last ... * @@ -3101,6 +3365,9 @@ class XCXFIMAHelper : public XCBaseHelper return result; } + // + // Detectors ... + /** * Detect Zones (Support / Resistance) based on XFIMA Validators ... * diff --git a/Libraries/x-saherelm.x-pivot.analysis.lib.mq5 b/Libraries/x-saherelm.x-pivot.analysis.lib.mq5 index ab3fb598..6b7a3b3f 100644 --- a/Libraries/x-saherelm.x-pivot.analysis.lib.mq5 +++ b/Libraries/x-saherelm.x-pivot.analysis.lib.mq5 @@ -2303,10 +2303,286 @@ struct XPatternAnalysis // }; +struct XPatternAnalysisConfig +{ + // + // Props ... + + // + // PV ... + int pvValidationLength; + ENUM_X_PRICE peakPriceType; + ENUM_X_PRICE valePriceType; + + // + // Momentum ... + int momentumBarValidationLength; + double momentumBarApprovedMultiplier; + + // + // TrueGap ... + double trueGapApprovedStrength; + + // + // Pin ... + double pinBarShadowApprovedMultiplier; + double pinBarRangeMultiplier; + bool pinBarForceDirection; + + // + // Flag ... + int flagPatternPullbackLength; + + // + // FVG ... + bool fvgForceType; + + // + // OB ... + bool obForceTwoBar; + + // + // Support and Resistance ... + int supportAndResistanceValidationLength; + int supportAndResistanceLoopbackLength; + + // + ENUM_X_DIRECTION allowedDirs[]; + ENUM_X_BAR_PATTERN allowedPatterns[]; + + // + // Constructor ... + XPatternAnalysisConfig() + { + Clean(); + } + + // + // Tools ... + + /** + * Cleanup ... + */ + void Clean() + { + // + // PV ... + pvValidationLength = 0; + peakPriceType = X_PRICE_NONE; + valePriceType = X_PRICE_NONE; + + // + // Momentum ... + momentumBarValidationLength = 0; + momentumBarApprovedMultiplier = 0; + + // + // TrueGap ... + trueGapApprovedStrength = 0; + + // + // Pin ... + pinBarShadowApprovedMultiplier = 0; + pinBarRangeMultiplier = 0; + pinBarForceDirection = false; + + // + // Flag ... + flagPatternPullbackLength = 0; + + // + // FVG ... + fvgForceType = false; + + // + // OB ... + obForceTwoBar = false; + + // + // Support and Resistance ... + supportAndResistanceValidationLength = 0; + supportAndResistanceLoopbackLength = 0; + + // + XClean(allowedDirs); + XClean(allowedPatterns); + + // + ZeroMemory(this); + } + + /** + * Default Configurations ... + */ + void Default() + { + // + // PV ... + pvValidationLength = 7; + peakPriceType = X_PRICE_HIGH; + valePriceType = X_PRICE_LOW; + + // + // Momentum ... + momentumBarValidationLength = 3; + momentumBarApprovedMultiplier = 3; + + // + // TrueGap ... + trueGapApprovedStrength = 1; + + // + // Pin ... + pinBarShadowApprovedMultiplier = 3; + pinBarRangeMultiplier = 4; + pinBarForceDirection = false; + + // + // Flag ... + flagPatternPullbackLength = 3; + + // + // FVG ... + fvgForceType = false; + + // + // OB ... + obForceTwoBar = false; + + // + // Support and Resistance ... + supportAndResistanceValidationLength = 21; + supportAndResistanceLoopbackLength = 50; + } + + // + // Permissions ... + + /** + * Check Specified Patterns Detection is Allowed or not ... + * + * @param pattern: ENUM_X_BAR_PATTERN, Specified Pattern to Detect ... + * @param patternDir: ENUM_X_DIRECTION, which Pattern Direction to Detect ... + * + * @return ( bool ) + */ + bool CanDetect( + ENUM_X_BAR_PATTERN pattern, + ENUM_X_DIRECTION patternDir = X_DIRECTION_NONE // + ) + { + // + bool result = false; + + // + // Validate Pattern and + // Check Pattern Exists ... + result = IsXValid(pattern) && + HasChild(allowedPatterns) && + Contains(pattern, allowedPatterns); + if (!result) + { + return result; + } + + // + // Now Check Direction ... + int index = FindIndex(pattern, allowedPatterns); + result = IsValidIndex(index) && + HasChild(allowedDirs) && + (!HasDirection(patternDir) + ? !HasDirection(allowedDirs[index]) + : (!HasDirection(allowedDirs[index]) || + patternDir == allowedDirs[index])); + + // + return result; + } + + // + // Collection Manipulations ... + + /** + * Full Detect Patterns ... + * + * @param forDir: ENUM_X_DIRECTION, which Pattern Direction to Detect ... + */ + void FullPattern( + ENUM_X_DIRECTION forDir = X_DIRECTION_NONE // + ) + { + // + int count = GetAllBarPatters(allowedPatterns); + for (int i = 0; i < count; i++) + { + // + Add( + forDir, + allowedDirs // + ); + } + } + + /** + * Add Specified Pattern to Detecte ... + * + * @param pattern: ENUM_X_BAR_PATTERN, Specified Pattern to Detect ... + * @param patternDir: ENUM_X_DIRECTION, which Pattern Direction to Detect ... + */ + void AddPattern( + ENUM_X_BAR_PATTERN pattern, + ENUM_X_DIRECTION patternDir = X_DIRECTION_NONE // + ) + { + // + bool has = IsXValid(pattern); + if (!has) + { + return; + } + + // + Add( + pattern, + allowedPatterns // + ); + + // + Add( + patternDir, + allowedDirs // + ); + } + + // +}; + struct XPatternAnalysisDrawConfig { // // Props ... + + // + int zonesWidth; + bool fillZones; + int arrowsWidth; + bool ignoreZonesAt; + int arrowsThreshold; + ENUM_LINE_STYLE zonesStyle; + + // + int bullishArrow; + int bearishArrow; + + // + color bullishColor; + color bearishColor; + + // + ENUM_X_PRICE arrowValePriceType; + ENUM_X_PRICE arrowPeakPriceType; + + // ENUM_X_BAR_PATTERN allowedDraws[]; // Allowed Draw Patterns ENUM_X_BAR_PATTERN allowedDrawZones[]; // Allowed Draw Pattern Zones ENUM_X_BAR_PATTERN allowedDrawPivots[]; // Allowed Draw Pattern Pivots @@ -2326,6 +2602,20 @@ struct XPatternAnalysisDrawConfig */ void Clean() { + // + arrowsWidth = 0; + zonesWidth = 0; + bullishArrow = 0; + bearishArrow = 0; + fillZones = false; + arrowsThreshold = 0; + ignoreZonesAt = false; + bullishColor = CLR_NONE; + bearishColor = CLR_NONE; + zonesStyle = STYLE_SOLID; + arrowValePriceType = X_PRICE_NONE; + arrowPeakPriceType = X_PRICE_NONE; + // XClean(allowedDraws); XClean(allowedDrawZones); @@ -2337,6 +2627,20 @@ struct XPatternAnalysisDrawConfig */ void Default() { + // + zonesWidth = 1; + arrowsWidth = 1; + arrowsThreshold = 2; + bullishArrow = 159; + bearishArrow = 159; + fillZones = false; + ignoreZonesAt = true; + bullishColor = clrAqua; + zonesStyle = STYLE_SOLID; + bearishColor = clrMagenta; + arrowValePriceType = X_PRICE_LOW; + arrowPeakPriceType = X_PRICE_HIGH; + // FullDraw(); diff --git a/Libraries/x-saherelm.x-poi.extensions.lib.mq5 b/Libraries/x-saherelm.x-poi.extensions.lib.mq5 index f4c50c90..75b5d8d2 100644 --- a/Libraries/x-saherelm.x-poi.extensions.lib.mq5 +++ b/Libraries/x-saherelm.x-poi.extensions.lib.mq5 @@ -3995,7 +3995,6 @@ bool ToBox( iLower = bar.FindLowest(idx, mLength, valePriceType); iUpper = bar.FindHighest(idx, mLength, peakPriceType); } - } break; @@ -4019,7 +4018,7 @@ bool ToBox( } // - iUpper = valePrice; + iUpper = peakPrice; iLower = valePrice; } break; @@ -4044,14 +4043,8 @@ bool ToBox( } // - iUpper = - isBullish - ? peakPrice - : valePrice; - iLower = - isBullish - ? peakPrice - : valePrice; + iUpper = peakPrice; + iLower = valePrice; } break; @@ -4075,14 +4068,10 @@ bool ToBox( } // - iUpper = - isBullish - ? peakPrice - : valePrice; - iLower = - isBullish - ? peakPrice - : valePrice; + int idx = -1; + int mLength = 3; + iUpper = bar.FindHighest(idx, mLength, peakPriceType); + iLower = bar.FindLowest(idx, mLength, valePriceType); } break; @@ -4106,14 +4095,13 @@ bool ToBox( } // - iUpper = - isBullish - ? peakPrice - : valePrice; - iLower = - isBullish - ? peakPrice - : valePrice; + has = bar.GetPreviousBar(tmpBar); + if (has) + { + // + iUpper = MathMax(peakPrice, tmpBar.GetPrice(peakPriceType)); + iLower = MathMin(valePrice, tmpBar.GetPrice(valePriceType)); + } } break; diff --git a/XFIMAEA/Classes/x-saherelm.xfima.signaller.class.mq5 b/XFIMAEA/Classes/x-saherelm.xfima.signaller.class.mq5 index 8e0a7632..bd25e1d7 100644 --- a/XFIMAEA/Classes/x-saherelm.xfima.signaller.class.mq5 +++ b/XFIMAEA/Classes/x-saherelm.xfima.signaller.class.mq5 @@ -41,11 +41,14 @@ class XCXFIMABaseSignaller : public XCBaseSignaller // Props ... // - bool ignoreTargets; // Ignore Signal Targets ... - XFIMAInputs fimaInputs; // XFIMA Inputs ... - XCXFIMAHelper *fimaHelper; // XFIMA Indicator Helper ... - XCXFIMAPOIDrawer *poiDrawer; // XFIMA POI Drawer ... - XCXFIMAPOIDetector *poiDetector; // XFIMA POI Detector ... + bool ignoreTargets; // Ignore Signal Targets ... + CArrayObj drawnObjects; // Drawing Objects Holder ... + XFIMAInputs fimaInputs; // XFIMA Inputs ... + XCXFIMAHelper *fimaHelper; // XFIMA Indicator Helper ... + XCXFIMAPOIDrawer *poiDrawer; // XFIMA POI Drawer ... + XCXFIMAPOIDetector *poiDetector; // XFIMA POI Detector ... + XPatternAnalysisConfig patternAnalyserConfig; // Bar Pattern Analyser Config ... + XPatternAnalysisDrawConfig patternAnalyserDrawConfig; // Bar Pattern Analysis Drawer Config ... // // Constructor ... @@ -93,6 +96,19 @@ class XCXFIMABaseSignaller : public XCBaseSignaller // poiDrawer = new XCXFIMAPOIDrawer(); poiDetector = new XCXFIMAPOIDetector(fimaHelper); + + // + // Configure ... + + // + patternAnalyserConfig.Clean(); + patternAnalyserConfig.Default(); + patternAnalyserConfig.FullPattern(); + + // + patternAnalyserDrawConfig.Clean(); + patternAnalyserDrawConfig.Default(); + patternAnalyserDrawConfig.FullDraw(); } // @@ -130,6 +146,11 @@ class XCXFIMABaseSignaller : public XCBaseSignaller // delete poiDetector; ZeroMemory(poiDetector); + + // + // analyserConfig.Clean(); + patternAnalyserConfig.Clean(); + patternAnalyserDrawConfig.Clean(); } // @@ -225,215 +246,1094 @@ class XCXFIMABaseSignaller : public XCBaseSignaller // // Protected Actions ... + // + // Drawer Functions ... + /** - * Check Specified Bar has Pattern or not ... + * Draw Specified Pattern Pivot ... * - * @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 ) + * @param _pivot: XPivot, reference to Specified Pivot ... + * @param config: XPatternAnalysisDrawConfig, Darwing Configuration ... + * @param thresholdMultiplier: int, pivot point threshold ... */ - bool HasPattern( - XOHCL &bar, - string &patternName, - ENUM_X_DIRECTION &patternDir, - XFIMAMarketStructure &structure // + void DrawPivot( + XPivot &_pivot, + XPatternAnalysisDrawConfig &config, + int thresholdMultiplier = 0 // ) { // - bool result = false; + // Normalize ... + thresholdMultiplier = NormalizeInt(thresholdMultiplier, 1); // - // Prepare ... - patternName = NULL; - patternDir = X_DIRECTION_NONE; + int arrowThreshold = config.arrowsThreshold * thresholdMultiplier; + arrowThreshold = NormalizeInt(arrowThreshold, 1); // // Validate ... - result = bar.IsValid(); - if (!result) + bool has = + poiDrawer != NULL && + _pivot.IsValid(); + if (!has) { - return result; + return; } // - // 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) + XOHCL _bar; + has = _pivot.GetBar(_bar); + if (!has) { // - 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)); - } + _bar.Clean(); + return; } // - result = - result && - IsXValid(patternName) && - HasDirection(patternDir); + XCBarArrowObject *iObj; + has = poiDrawer.DrawBarArrow( + _bar, + iObj, + _pivot.IsPeak() + ? config.arrowPeakPriceType + : config.arrowValePriceType, + _pivot.IsBullish() + ? config.bullishArrow + : config.bearishArrow, + _pivot.IsBullish() + ? config.bullishColor + : config.bearishColor, + config.arrowsWidth, + _pivot.IsBullish() + ? ANCHOR_TOP + : ANCHOR_BOTTOM, + _pivot.prefix + "_Pivot_" + ToXString(TimeToSeconds(_pivot.time)), + true, // Ignore Bar Tag ... + arrowThreshold // Threshold ... + ); + if (has) + { + drawnObjects.Add(iObj); + } // - return result; + ZeroMemory(iObj); } /** - * Validate a Pattern based on MA Band ... + * Draw Specified Pattern Zone ... * - * @param bar: XOHCL, reference to Pattern Bar ... - * @param patternName: string, detected pattern's name ... - * @param patternDir: ENUM_X_DIRECTION, detected pattern's direction ... - * @param fimaConditions: XFIMAConditions, reference to Bar Specified XFIMA Conditions ... - * - * @return ( bool ) + * @param _zone: XBozxZone, reference to Specified Zone ... + * @param config: XPatternAnalysisDrawConfig, Darwing Configuration ... */ - bool ValidatePatternBasedOnMABand( - XOHCL &bar, - string patternName, - ENUM_X_DIRECTION patternDir, - XFIMAConditions &fimaConditions // + void DrawZone( + XBoxZone &_zone, + XPatternAnalysisDrawConfig &config // ) { // - bool result = false; + // Validate ... + bool has = + poiDrawer != NULL && + _zone.IsValid(); + if (!has) + { + return; + } + // + XCBoxObject *iObj; + has = poiDrawer.DrawBox( + _zone, + iObj, + config.ignoreZonesAt, + _zone.type + "_Zone_" + ToXString(TimeToSeconds(_zone.from)) // + ); + if (has) + { + // + XPOIStyle iStyle; + poiDrawer.GetBoxStyle( + iStyle, + _zone.dir // + ); + + // + iStyle.clr = + _zone.IsBullish() + ? config.bullishColor + : config.bearishColor; + iStyle.width = config.zonesWidth; + iStyle.style = config.zonesStyle; + + // + poiDrawer.ApplyBoxStyle( + iObj, + iStyle // + ); + + // + drawnObjects.Add(iObj); + + // + iStyle.Clean(); + } + + // + ZeroMemory(iObj); + } + + /** + * Draw Specified Pattern info ... + * + * @param _bar: XOHCL, reference to Pattern's Bar ... + * @param _pivot: XPivot, reference to Pattern's Pivot ... + * @param _zone: XBoxZone, reference to Pattern's Zone ... + * @param _pattern: ENUM_X_BAR_PATTERN, Specified Bar Pattern ... + * @param _patternDir: ENUM_X_DIRECTION, Specified Bar Pattern's Direction ... + * @param thresholdMultiplier: int, pivot point threshold ... + * @param ignorePermissions: bool, force to Check Permissions from Config ... + */ + void DrawPattern( + XOHCL &_bar, + XPivot &_pivot, + XBoxZone &_zone, + ENUM_X_BAR_PATTERN _pattern, + ENUM_X_DIRECTION _patternDir, + int thresholdMultiplier = 0, + bool ignorePermissions = true // + ) + { // // Validate ... - result = bar.IsValid() && - IsXValid(patternName) && - HasDirection(patternDir); - if (!result) + bool has = + poiDrawer != NULL && + _bar.IsValid() && + IsXValid(_pattern) && + HasDirection(_patternDir); + if (!has) { - return result; + return; } // - // Define Requirements ... - bool isBullish = false; - bool isBearish = false; - double iPrice = EMPTY_VALUE; - double iPriceEdge = EMPTY_VALUE; - ENUM_X_PRICE iPriceType = X_PRICE_NONE; - ENUM_X_PRICE iPriceEdgeType = X_PRICE_NONE; + // Handle Draws ... // - // Calculating Price and Price Types ... + // Draw OHCL Bar ... // - isBullish = IsXBullish(patternDir); - isBearish = IsXBearish(patternDir); - - // - 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 ... - result = - NotEmptyZero(iPrice) && - IsXValid(iPriceType) && - NotEmptyZero(iPriceEdge) && - IsXValid(iPriceEdgeType) && - ((isBullish && !isBearish) || - (isBearish && !isBullish)); - if (!result) + // Draw Pivot ... + has = + ignorePermissions + ? true + : patternAnalyserDrawConfig.CanDrawPivot(_pattern); + if (has) { - return result; + DrawPivot(_pivot, patternAnalyserDrawConfig, thresholdMultiplier); } // - // Validate Pattern based on MA Band ... - - // - // Retrieve MA Band for Validation ... - double iMABandUpper = fimaConditions.maBondUpperBuffer[0]; - double iMABandLower = fimaConditions.maBondLowerBuffer[0]; - - // - // Validate by Edge Price ... - result = - NotEmptyZero(iMABandUpper) && - NotEmptyZero(iMABandLower) && - (isBullish - ? iPriceEdge < iMABandLower - : iPriceEdge > iMABandUpper); - if (!result) + // Draw Zone ... + has = + ignorePermissions + ? true + : patternAnalyserDrawConfig.CanDrawZone(_pattern); + if (has) { - return result; + DrawZone(_zone, patternAnalyserDrawConfig); + } + } + + /** + * Draw Specified Bar Pattern Analysis ... + * + * @param barAnalysis: XPatternAnalysis, reference to Specified Bar Pattern Analysis ... + */ + void DrawBarPatternAnalysis( + XPatternAnalysis &barAnalysis, + XPatternAnalysisDrawConfig &config // + ) + { + // + bool has = + poiDrawer != NULL && + barAnalysis.IsValid(); + if (!has) + { + return; } // - return result; + bool canDraw; + bool isBullish; + bool isBearish; + XOHCL patternBar; + bool canDrawZone; + bool canDrawPivot; + XPivot patternPivot; + XBoxZone patternBox; + ENUM_X_BAR_PATTERN pattern; + ENUM_X_DIRECTION patternDir; + + // + int patternsPivotThresholdMultiplier = 0; + + // + // Support and Resistance ... + + // + // Support ... + isBearish = false; + isBullish = barAnalysis.IsSupport(); + has = isBullish; + if (has) + { + // + pattern = X_BAR_PATTERN_SUPPORT; + patternDir = X_DIRECTION_BULLISH; + canDraw = config.CanDraw(pattern); + if (canDraw) + { + // + has = barAnalysis.GetPattern( + patternBar, + patternPivot, + patternBox, + pattern, + patternDir // + ); + if (has) + { + // + canDrawZone = config.CanDrawZone(pattern); + if (!canDrawZone) + { + patternBox.Clean(); + } + + // + canDrawPivot = config.CanDrawPivot(pattern); + if (!canDrawPivot) + { + patternPivot.Clean(); + } + else + { + patternsPivotThresholdMultiplier++; + } + + // + DrawPattern( + patternBar, + patternPivot, + patternBox, + pattern, + patternDir, + patternsPivotThresholdMultiplier // + ); + } + } + } + + // + // Resistance ... + isBullish = false; + isBearish = barAnalysis.IsResistance(); + has = isBearish; + if (has) + { + // + pattern = X_BAR_PATTERN_RESISTANCE; + patternDir = X_DIRECTION_BEARISH; + canDraw = config.CanDraw(pattern); + if (canDraw) + { + // + has = barAnalysis.GetPattern( + patternBar, + patternPivot, + patternBox, + pattern, + patternDir // + ); + if (has) + { + // + canDrawZone = config.CanDrawZone(pattern); + if (!canDrawZone) + { + patternBox.Clean(); + } + + // + canDrawPivot = config.CanDrawPivot(pattern); + if (!canDrawPivot) + { + patternPivot.Clean(); + } + else + { + patternsPivotThresholdMultiplier++; + } + + // + DrawPattern( + patternBar, + patternPivot, + patternBox, + pattern, + patternDir, + patternsPivotThresholdMultiplier // + ); + } + } + } + + // + // PV: High and Low ... + + // + // Low ... + isBearish = false; + isBullish = barAnalysis.IsLow(); + has = isBullish; + if (has) + { + // + pattern = X_BAR_PATTERN_LOW; + patternDir = X_DIRECTION_BULLISH; + canDraw = config.CanDraw(pattern); + if (canDraw) + { + // + has = barAnalysis.GetPattern( + patternBar, + patternPivot, + patternBox, + pattern, + patternDir // + ); + if (has) + { + // + canDrawZone = config.CanDrawZone(pattern); + if (!canDrawZone) + { + patternBox.Clean(); + } + + // + canDrawPivot = config.CanDrawPivot(pattern); + if (!canDrawPivot) + { + patternPivot.Clean(); + } + else + { + patternsPivotThresholdMultiplier++; + } + + // + DrawPattern( + patternBar, + patternPivot, + patternBox, + pattern, + patternDir, + patternsPivotThresholdMultiplier // + ); + } + } + } + + // + // High ... + isBullish = false; + isBearish = barAnalysis.IsHigh(); + has = isBearish; + if (has) + { + // + pattern = X_BAR_PATTERN_HIGH; + patternDir = X_DIRECTION_BEARISH; + canDraw = config.CanDraw(pattern); + if (canDraw) + { + // + has = barAnalysis.GetPattern( + patternBar, + patternPivot, + patternBox, + pattern, + patternDir // + ); + if (has) + { + // + canDrawZone = config.CanDrawZone(pattern); + if (!canDrawZone) + { + patternBox.Clean(); + } + + // + canDrawPivot = config.CanDrawPivot(pattern); + if (!canDrawPivot) + { + patternPivot.Clean(); + } + else + { + patternsPivotThresholdMultiplier++; + } + + // + DrawPattern( + patternBar, + patternPivot, + patternBox, + pattern, + patternDir, + patternsPivotThresholdMultiplier // + ); + } + } + } + + // + // OB ... + isBullish = barAnalysis.IsOB(X_DIRECTION_BULLISH); + isBearish = barAnalysis.IsOB(X_DIRECTION_BEARISH); + has = isBullish || isBearish; + if (has) + { + // + pattern = X_BAR_PATTERN_OB; + patternDir = + isBullish + ? X_DIRECTION_BULLISH + : X_DIRECTION_BEARISH; + canDraw = config.CanDraw(pattern); + if (canDraw) + { + // + has = barAnalysis.GetPattern( + patternBar, + patternPivot, + patternBox, + pattern, + patternDir // + ); + if (has) + { + // + canDrawZone = config.CanDrawZone(pattern); + if (!canDrawZone) + { + patternBox.Clean(); + } + + // + canDrawPivot = config.CanDrawPivot(pattern); + if (!canDrawPivot) + { + patternPivot.Clean(); + } + else + { + patternsPivotThresholdMultiplier++; + } + + // + DrawPattern( + patternBar, + patternPivot, + patternBox, + pattern, + patternDir, + patternsPivotThresholdMultiplier // + ); + } + } + } + + // + // FVG ... + isBullish = barAnalysis.IsFVG(X_DIRECTION_BULLISH); + isBearish = barAnalysis.IsFVG(X_DIRECTION_BEARISH); + has = isBullish || isBearish; + if (has) + { + // + pattern = X_BAR_PATTERN_FVG; + patternDir = + isBullish + ? X_DIRECTION_BULLISH + : X_DIRECTION_BEARISH; + canDraw = config.CanDraw(pattern); + if (canDraw) + { + // + has = barAnalysis.GetPattern( + patternBar, + patternPivot, + patternBox, + pattern, + patternDir // + ); + if (has) + { + // + canDrawZone = config.CanDrawZone(pattern); + if (!canDrawZone) + { + patternBox.Clean(); + } + + // + canDrawPivot = config.CanDrawPivot(pattern); + if (!canDrawPivot) + { + patternPivot.Clean(); + } + else + { + patternsPivotThresholdMultiplier++; + } + + // + DrawPattern( + patternBar, + patternPivot, + patternBox, + pattern, + patternDir, + patternsPivotThresholdMultiplier // + ); + } + } + } + + // + // Momentum ... + isBullish = barAnalysis.IsMomentum(X_DIRECTION_BULLISH); + isBearish = barAnalysis.IsMomentum(X_DIRECTION_BEARISH); + has = isBullish || isBearish; + if (has) + { + // + pattern = X_BAR_PATTERN_MOMENTUM; + patternDir = + isBullish + ? X_DIRECTION_BULLISH + : X_DIRECTION_BEARISH; + canDraw = config.CanDraw(pattern); + if (canDraw) + { + // + has = barAnalysis.GetPattern( + patternBar, + patternPivot, + patternBox, + pattern, + patternDir // + ); + if (has) + { + // + canDrawZone = config.CanDrawZone(pattern); + if (!canDrawZone) + { + patternBox.Clean(); + } + + // + canDrawPivot = config.CanDrawPivot(pattern); + if (!canDrawPivot) + { + patternPivot.Clean(); + } + else + { + patternsPivotThresholdMultiplier++; + } + + // + DrawPattern( + patternBar, + patternPivot, + patternBox, + pattern, + patternDir, + patternsPivotThresholdMultiplier // + ); + } + } + } + + // + // Engulfed ... + isBullish = barAnalysis.IsEngulfed(X_DIRECTION_BULLISH); + isBearish = barAnalysis.IsEngulfed(X_DIRECTION_BEARISH); + has = isBullish || isBearish; + if (has) + { + // + pattern = X_BAR_PATTERN_ENGULFED; + patternDir = + isBullish + ? X_DIRECTION_BULLISH + : X_DIRECTION_BEARISH; + canDraw = config.CanDraw(pattern); + if (canDraw) + { + // + has = barAnalysis.GetPattern( + patternBar, + patternPivot, + patternBox, + pattern, + patternDir // + ); + if (has) + { + // + canDrawZone = config.CanDrawZone(pattern); + if (!canDrawZone) + { + patternBox.Clean(); + } + + // + canDrawPivot = config.CanDrawPivot(pattern); + if (!canDrawPivot) + { + patternPivot.Clean(); + } + else + { + patternsPivotThresholdMultiplier++; + } + + // + DrawPattern( + patternBar, + patternPivot, + patternBox, + pattern, + patternDir, + patternsPivotThresholdMultiplier // + ); + } + } + } + + // + // Pinned ... + isBullish = barAnalysis.IsPinned(X_DIRECTION_BULLISH); + isBearish = barAnalysis.IsPinned(X_DIRECTION_BEARISH); + has = isBullish || isBearish; + if (has) + { + // + pattern = X_BAR_PATTERN_PINNED; + patternDir = + isBullish + ? X_DIRECTION_BULLISH + : X_DIRECTION_BEARISH; + canDraw = config.CanDraw(pattern); + if (canDraw) + { + // + has = barAnalysis.GetPattern( + patternBar, + patternPivot, + patternBox, + pattern, + patternDir // + ); + if (has) + { + // + canDrawZone = config.CanDrawZone(pattern); + if (!canDrawZone) + { + patternBox.Clean(); + } + + // + canDrawPivot = config.CanDrawPivot(pattern); + if (!canDrawPivot) + { + patternPivot.Clean(); + } + else + { + patternsPivotThresholdMultiplier++; + } + + // + DrawPattern( + patternBar, + patternPivot, + patternBox, + pattern, + patternDir, + patternsPivotThresholdMultiplier // + ); + } + } + } + + // + // TrueGaped ... + isBullish = barAnalysis.IsTrueGaped(X_DIRECTION_BULLISH); + isBearish = barAnalysis.IsTrueGaped(X_DIRECTION_BEARISH); + has = isBullish || isBearish; + if (has) + { + // + pattern = X_BAR_PATTERN_TRUE_GAPED; + patternDir = + isBullish + ? X_DIRECTION_BULLISH + : X_DIRECTION_BEARISH; + canDraw = config.CanDraw(pattern); + if (canDraw) + { + // + has = barAnalysis.GetPattern( + patternBar, + patternPivot, + patternBox, + pattern, + patternDir // + ); + if (has) + { + // + canDrawZone = config.CanDrawZone(pattern); + if (!canDrawZone) + { + patternBox.Clean(); + } + + // + canDrawPivot = config.CanDrawPivot(pattern); + if (!canDrawPivot) + { + patternPivot.Clean(); + } + else + { + patternsPivotThresholdMultiplier++; + } + + // + DrawPattern( + patternBar, + patternPivot, + patternBox, + pattern, + patternDir, + patternsPivotThresholdMultiplier // + ); + } + } + } + + // + // Star ... + isBullish = barAnalysis.IsStar(X_DIRECTION_BULLISH); + isBearish = barAnalysis.IsStar(X_DIRECTION_BEARISH); + has = isBullish || isBearish; + if (has) + { + // + pattern = X_BAR_PATTERN_STAR; + patternDir = + isBullish + ? X_DIRECTION_BULLISH + : X_DIRECTION_BEARISH; + canDraw = config.CanDraw(pattern); + if (canDraw) + { + // + has = barAnalysis.GetPattern( + patternBar, + patternPivot, + patternBox, + pattern, + patternDir // + ); + if (has) + { + // + canDrawZone = config.CanDrawZone(pattern); + if (!canDrawZone) + { + patternBox.Clean(); + } + + // + canDrawPivot = config.CanDrawPivot(pattern); + if (!canDrawPivot) + { + patternPivot.Clean(); + } + else + { + patternsPivotThresholdMultiplier++; + } + + // + DrawPattern( + patternBar, + patternPivot, + patternBox, + pattern, + patternDir, + patternsPivotThresholdMultiplier // + ); + } + } + } + + // + // Piercing ... + isBullish = barAnalysis.IsPiercing(X_DIRECTION_BULLISH); + isBearish = barAnalysis.IsPiercing(X_DIRECTION_BEARISH); + has = isBullish || isBearish; + if (has) + { + // + pattern = X_BAR_PATTERN_PIERCING; + patternDir = + isBullish + ? X_DIRECTION_BULLISH + : X_DIRECTION_BEARISH; + canDraw = config.CanDraw(pattern); + if (canDraw) + { + // + has = barAnalysis.GetPattern( + patternBar, + patternPivot, + patternBox, + pattern, + patternDir // + ); + if (has) + { + // + canDrawZone = config.CanDrawZone(pattern); + if (!canDrawZone) + { + patternBox.Clean(); + } + + // + canDrawPivot = config.CanDrawPivot(pattern); + if (!canDrawPivot) + { + patternPivot.Clean(); + } + else + { + patternsPivotThresholdMultiplier++; + } + + // + DrawPattern( + patternBar, + patternPivot, + patternBox, + pattern, + patternDir, + patternsPivotThresholdMultiplier // + ); + } + } + } + + // + // Rising ... + isBullish = barAnalysis.IsRising(X_DIRECTION_BULLISH); + isBearish = barAnalysis.IsRising(X_DIRECTION_BEARISH); + has = isBullish || isBearish; + if (has) + { + // + pattern = X_BAR_PATTERN_RISING; + patternDir = + isBullish + ? X_DIRECTION_BULLISH + : X_DIRECTION_BEARISH; + canDraw = config.CanDraw(pattern); + if (canDraw) + { + // + has = barAnalysis.GetPattern( + patternBar, + patternPivot, + patternBox, + pattern, + patternDir // + ); + if (has) + { + // + canDrawZone = config.CanDrawZone(pattern); + if (!canDrawZone) + { + patternBox.Clean(); + } + + // + canDrawPivot = config.CanDrawPivot(pattern); + if (!canDrawPivot) + { + patternPivot.Clean(); + } + else + { + patternsPivotThresholdMultiplier++; + } + + // + DrawPattern( + patternBar, + patternPivot, + patternBox, + pattern, + patternDir, + patternsPivotThresholdMultiplier // + ); + } + } + } + + // + // Flag ... + isBullish = barAnalysis.IsFlag(X_DIRECTION_BULLISH); + isBearish = barAnalysis.IsFlag(X_DIRECTION_BEARISH); + has = isBullish || isBearish; + if (has) + { + // + pattern = X_BAR_PATTERN_FLAG; + patternDir = + isBullish + ? X_DIRECTION_BULLISH + : X_DIRECTION_BEARISH; + canDraw = config.CanDraw(pattern); + if (canDraw) + { + // + has = barAnalysis.GetPattern( + patternBar, + patternPivot, + patternBox, + pattern, + patternDir // + ); + if (has) + { + // + canDrawZone = config.CanDrawZone(pattern); + if (!canDrawZone) + { + patternBox.Clean(); + } + + // + canDrawPivot = config.CanDrawPivot(pattern); + if (!canDrawPivot) + { + patternPivot.Clean(); + } + else + { + patternsPivotThresholdMultiplier++; + } + + // + DrawPattern( + patternBar, + patternPivot, + patternBox, + pattern, + patternDir, + patternsPivotThresholdMultiplier // + ); + } + } + } + + // + // SignalKey ... + isBullish = barAnalysis.IsSignalKey(X_DIRECTION_BULLISH); + isBearish = barAnalysis.IsSignalKey(X_DIRECTION_BEARISH); + has = isBullish || isBearish; + if (has) + { + // + pattern = X_BAR_PATTERN_SIGNALKEY; + patternDir = + isBullish + ? X_DIRECTION_BULLISH + : X_DIRECTION_BEARISH; + canDraw = config.CanDraw(pattern); + if (canDraw) + { + // + has = barAnalysis.GetPattern( + patternBar, + patternPivot, + patternBox, + pattern, + patternDir // + ); + if (has) + { + // + canDrawZone = config.CanDrawZone(pattern); + if (!canDrawZone) + { + patternBox.Clean(); + } + + // + canDrawPivot = config.CanDrawPivot(pattern); + if (!canDrawPivot) + { + patternPivot.Clean(); + } + else + { + patternsPivotThresholdMultiplier++; + } + + // + DrawPattern( + patternBar, + patternPivot, + patternBox, + pattern, + patternDir, + patternsPivotThresholdMultiplier // + ); + } + } + } + + // + // Cleanup Resources ... + patternBar.Clean(); + patternBox.Clean(); + patternPivot.Clean(); } // @@ -451,8 +1351,7 @@ class XCXFIMAStrategy1Signaller : public XCXFIMABaseSignaller public: // // Props ... - CArrayObj drawnObjects; - XFIMAPatternDetectorConfig analyserConfig; + // XFIMAPatternDetectorConfig analyserConfig; // // Constructor ... @@ -475,14 +1374,17 @@ class XCXFIMAStrategy1Signaller : public XCXFIMABaseSignaller ) { // - // Configure Detector ... + // Configures ... // - analyserConfig.Default(); - analyserConfig.validMACrossDiffMultiplier = 4; + patternAnalyserConfig.Clean(); + patternAnalyserConfig.Default(); + patternAnalyserConfig.FullPattern(); // - analyserConfig.FullDetect(); + patternAnalyserDrawConfig.Clean(); + patternAnalyserDrawConfig.Default(); + patternAnalyserDrawConfig.FullDraw(); // // Ignore Signal Targets ... @@ -493,11 +1395,7 @@ class XCXFIMAStrategy1Signaller : public XCXFIMABaseSignaller // Deconstructor ... ~XCXFIMAStrategy1Signaller() { - // Destroy(); - - // - analyserConfig.Clean(); } // @@ -571,21 +1469,30 @@ class XCXFIMAStrategy1Signaller : public XCXFIMABaseSignaller // // Analyse Market ... - poiDetector.AnalyseMarket( - iBar, - iStructure, - analyserConfig // - ); + // poiDetector.AnalyseMarket( + // iBar, + // iStructure, + // analyserConfig // + // ); // // Bar Pattern Analysis Detection Test ... - has = poiDetector.AnalyseBarPatterns( - iBar, - iBarAnalysis - // - // Use Default Config ... + // has = poiDetector.AnalyseBarPatterns( + // iBar, + // iBarAnalysis, + // patternAnalyserConfig // + // ); + // DrawBarPatternAnalysis(iBarAnalysis, patternAnalyserDrawConfig); + + // + has = fimaHelper.HasBoundarySwitch( + iDir, + iBar.Index() // ); - DrawBarPatternAnalysis(iBarAnalysis); + if (has) + { + Print("Hot Place Detected"); + } // // Disable Signallers ... @@ -751,323 +1658,36 @@ class XCXFIMAStrategy1Signaller : public XCXFIMABaseSignaller } // - // Check Pattern Exists ... - string patternName = NULL; - ENUM_X_DIRECTION patternDir = X_DIRECTION_NONE; - result = HasPattern( - bar, - patternName, - patternDir, - structure // - ); - if (!result) - { - return result; - } - - // - // Validate Pattern Based on MA Band ... - result = ValidatePatternBasedOnMABand( - bar, - patternName, - patternDir, - conditions // - ); - if (!result) - { - return result; - } - - // - // Here i Use Specified Supports and Resistances ... - XBoxZone tmpBox; - bool has = false; - XBoxZone supports[]; - XBoxZone resistances[]; - - // - has = structure.pvAnalysis.IsValid() && - structure.pvAnalysis.HasSupportBox(tmpBox); - if (has) - { - // - tmpBox.to = bar.time; - AddIfNotExists( - tmpBox, - supports // - ); - } - - // - has = structure.zigzagAnalysis.IsValid() && - structure.zigzagAnalysis.HasSupportBox(tmpBox); - if (has) - { - // - tmpBox.to = bar.time; - AddIfNotExists( - tmpBox, - supports // - ); - } - - // - has = structure.pvAnalysis.IsValid() && - structure.pvAnalysis.HasResistanceBox(tmpBox); - if (has) - { - // - tmpBox.to = bar.time; - AddIfNotExists( - tmpBox, - resistances // - ); - } - - // - has = structure.zigzagAnalysis.IsValid() && - structure.zigzagAnalysis.HasResistanceBox(tmpBox); - if (has) - { - // - tmpBox.to = bar.time; - AddIfNotExists( - tmpBox, - resistances // - ); - } - - // - // Check Affected Zone ... - // Select a Support or Resistance ... - int insideZoneIDX = -1; - result = - (IsXBullish(patternDir) - ? HasInside( - insideZoneIDX, - bar, - supports // - ) - : IsXBearish(patternDir) - ? HasInside( - insideZoneIDX, - bar, - resistances // - ) - : false // - ); - if (!result) - { - return result; - } - - // - // Filling Affected Zone ... - // and Validate it ... - if (IsXBullish(patternDir)) - { - zone = supports[insideZoneIDX]; - } - else if (IsXBearish(patternDir)) - { - zone = resistances[insideZoneIDX]; - } - result = zone.IsValid(); - if (!result) - { - return result; - } - - // - // Validate affected Zone based on Pattern's Bar ... - result = IsXBullish(patternDir) - ? bar.high > zone.upper - : IsXBearish(patternDir) - ? bar.low < zone.lower - : false; - // - // Validate Zone ... + // Prepare zone ... if (result) { // + zone.to = bar.time; + zone.from = GetBarTime( + bar.symbol, + bar.period, + bar.Index() + 2 // + ); + zone.symbol = bar.symbol; + zone.period = bar.period; + // zone.dir = structure.maCrossDir; + zone.lower = bar.FindLowest(2, MODE_LOW); + zone.upper = bar.FindHighest(2, MODE_HIGH); + // zone.type = name + "_" + ToXString(structure.maCrossDir); + // + result = zone.IsValid(); } // - // Draw Requirements ... - // if (result) - // { - // // - // // Support and Resistances ... - // CArrayObj *zoneObjs; - // poiDrawer.DrawBoxes( - // supports, - // zoneObjs // - // ); - // poiDrawer.DrawBoxes( - // resistances, - // zoneObjs // - // ); - - // // - // // Zone ... - // XCBoxObject *iZoneObj; - // bool isDrawn = poiDrawer.DrawBox( - // zone, - // iZoneObj, - // true, - // zone.type // - // ); - // if (isDrawn) - // { - // // - // XPOIStyle iStyle; - // iStyle.width = 2; - // iStyle.clr = clrYellow; - // poiDrawer.ApplyBoxStyle( - // iZoneObj, - // iStyle // - // ); - // } - - // // - // // Pattern ... - // XCBarArrowObject *iPObj; - // poiDrawer.DrawBarArrow( - // bar, - // iPObj, - // zone.IsBullish() ? X_PRICE_LOW : X_PRICE_HIGH, - // 159, - // clrYellow, - // 3, // With ... - // zone.IsBullish() ? ANCHOR_BOTTOM : ANCHOR_TOP, - // patternName // - // ); - - // // poiDrawer.DrawBoxes( - // // structure.fvgs, - // // zoneObjs, - // // false // - // // ); - - // Print("SALAM"); - // } - + // Check Result ... if (result) { // - dir = patternDir; + // dir = structure.maCrossDir; // // Handle Targets Detection ... - - // - // Check Reversal FVGS ... - int idx = -1; - XTarget target; - XBoxZone targetZones[]; - int numberOfTargets = 3; - double actingDistance = 20; - double iValue = EMPTY_VALUE; - bool ignoreFirstTarget = false; - ENUM_X_DIRECTION targetsDir = Opposit(dir); - int count = ExtractByDirection( - targetZones, - structure.fvgs, - targetsDir // - ); - bool has = IsValidSize(count); - if (has) - { - // - // Calculate Value ... - double points = GetPoints(zone.symbol); - double zoneRange = zone.upper - zone.lower; - iValue = IsXBullish(dir) - ? (zone.upper + (zoneRange * defaultSignalR2R)) - : (zone.lower + (zoneRange * defaultSignalR2R)); - double defaultTarget = iValue; - - // - // Looping Back ... - for (int i = 0; i < numberOfTargets; i++) - { - // - // Detect Lowest Above Zone ... - if (IsXBullish(dir)) - { - // - idx = GetLowestAbove(iValue, targetZones); - has = IsValidIndex(idx); - if (!has) - { - break; - } - - // - iValue = targetZones[idx].lower; - } - // - // Detect Highest below Zone ... - else if (IsXBearish(dir)) - { - // - idx = GetHighestBelow(iValue, targetZones); - has = IsValidIndex(idx); - if (!has) - { - break; - } - - // - iValue = targetZones[idx].upper; - } - - // - // Validate Target Value ... - has = NotEmptyZero(iValue) && - iValue != defaultTarget; - if (has) - { - // - // Init Target ... - target.Clean(); - target.doRF = true; - target.target = iValue; - target.actingDistance = actingDistance; - has = target.IsValid(); - if (has) - { - // - // Add Target to Targets ... - AddRef( - target, - targets // - ); - } - target.Clean(); - } - } - - // - // Remove Nearest ... - has = ignoreFirstTarget && - HasChild(targets); - if (has) - { - // - ArrayRemove( - targets, - 0, - 1 // - ); - } - } - - // - // Cleanup Resources ... - target.Clean(); - XClean(targetZones); } // @@ -1123,7 +1743,7 @@ class XCXFIMAStrategy1Signaller : public XCXFIMABaseSignaller // // Detect Specified MA Cross ... - result = HasDirection(structure.maCrossDir); + // result = HasDirection(structure.maCrossDir); // // Prepare zone ... @@ -1138,10 +1758,10 @@ class XCXFIMAStrategy1Signaller : public XCXFIMABaseSignaller ); zone.symbol = bar.symbol; zone.period = bar.period; - zone.dir = structure.maCrossDir; + // zone.dir = structure.maCrossDir; zone.lower = bar.FindLowest(2, MODE_LOW); zone.upper = bar.FindHighest(2, MODE_HIGH); - zone.type = name + "_" + ToXString(structure.maCrossDir); + // zone.type = name + "_" + ToXString(structure.maCrossDir); // result = zone.IsValid(); @@ -1152,7 +1772,7 @@ class XCXFIMAStrategy1Signaller : public XCXFIMABaseSignaller if (result) { // - dir = structure.maCrossDir; + // dir = structure.maCrossDir; // // Handle Targets Detection ... @@ -1171,991 +1791,6 @@ class XCXFIMAStrategy1Signaller : public XCXFIMABaseSignaller return result; } - // - // Drawer Functions ... - - /** - * Draw Specified Pattern info ... - * - * @param _bar: XOHCL, reference to Pattern's Bar ... - * @param _pivot: XPivot, reference to Pattern's Pivot ... - * @param _zone: XBoxZone, reference to Pattern's Zone ... - * @param _pattern: ENUM_X_BAR_PATTERN, Specified Bar Pattern ... - * @param _patternDir: ENUM_X_DIRECTION, Specified Bar Pattern's Direction ... - */ - void DrawPattern( - XOHCL &_bar, - XPivot &_pivot, - XBoxZone &_zone, - ENUM_X_BAR_PATTERN _pattern, - ENUM_X_DIRECTION _patternDir // - ) - { - // - // Validate ... - bool has = - poiDrawer != NULL && - _bar.IsValid() && - IsXValid(_pattern) && - HasDirection(_patternDir); - if (!has) - { - return; - } - - // - // Defien Draw Requirements ... - - // - int width = 3; - bool ignoreBoxAt = true; - int arrowThreshold = 5; - - // - int bullishArrow = 159; - int bearishArrow = 159; - - // - ENUM_X_PRICE arrowValePriceType = X_PRICE_LOW; - ENUM_X_PRICE arrowPeakPriceType = X_PRICE_HIGH; - - // - color bullishColor = clrAqua; - color bearishColor = clrMagenta; - - // - // Draw Bar ... - - // - // Draw Pivot ... - if (_pivot.IsValid()) - { - // - XCBarArrowObject *iObj; - has = poiDrawer.DrawBarArrow( - _bar, - iObj, - _pivot.IsPeak() - ? arrowPeakPriceType - : arrowValePriceType, - IsXBullish(_patternDir) - ? bullishArrow - : bearishArrow, - IsXBullish(_patternDir) - ? bullishColor - : bearishColor, - width, - IsXBullish(_patternDir) - ? ANCHOR_TOP - : ANCHOR_BOTTOM, - _pivot.prefix + "_Pivot_" + ToXString(TimeToSeconds(_pivot.time)), - true, // Ignore Bar Tag ... - arrowThreshold // Threshold ... - ); - if (has) - { - drawnObjects.Add(iObj); - } - - // - ZeroMemory(iObj); - } - - // - // Draw Box ... - if (_zone.IsValid()) - { - // - XCBoxObject *iObj; - has = poiDrawer.DrawBox( - _zone, - iObj, - ignoreBoxAt, - _zone.type + "_Zone_" + ToXString(TimeToSeconds(_zone.from)) // - ); - if (has) - { - // - XPOIStyle iStyle; - poiDrawer.GetBoxStyle( - iStyle, - _zone.dir // - ); - - // - iStyle.clr = - IsXBullish(_patternDir) - ? bullishColor - : bearishColor; - - // - poiDrawer.ApplyBoxStyle( - iObj, - iStyle // - ); - - // - drawnObjects.Add(iObj); - - // - iStyle.Clean(); - } - - // - ZeroMemory(iObj); - } - } - - /** - * Draw Specified Bar Pattern Analysis ... - * - * @param barAnalysis: XPatternAnalysis, reference to Specified Bar Pattern Analysis ... - */ - void DrawBarPatternAnalysis(XPatternAnalysis &barAnalysis) - { - // - bool has = barAnalysis.IsValid(); - if (!has) - { - return; - } - - // - // Configure Draws ... - XPatternAnalysisDrawConfig config; - config.Default(); - XClean(config.allowedDraws); - XClean(config.allowedDrawZones); - XClean(config.allowedDrawPivots); - - // - // X_BAR_PATTERN_PIERCING ... - Add( - X_BAR_PATTERN_PIERCING, - config.allowedDraws // - ); - Add( - X_BAR_PATTERN_PIERCING, - config.allowedDrawZones // - ); - Add( - X_BAR_PATTERN_PIERCING, - config.allowedDrawPivots // - ); - - // - // X_BAR_PATTERN_STAR ... - Add( - X_BAR_PATTERN_STAR, - config.allowedDraws // - ); - Add( - X_BAR_PATTERN_STAR, - config.allowedDrawZones // - ); - Add( - X_BAR_PATTERN_STAR, - config.allowedDrawPivots // - ); - - // - // Draw Bar Patterns Analysis ... - - // - bool isBullish; - bool isBearish; - XOHCL patternBar; - XPivot patternPivot; - XBoxZone patternBox; - ENUM_X_BAR_PATTERN pattern; - ENUM_X_DIRECTION patternDir; - - // - bool canDraw; - bool canDrawZone; - bool canDrawPivot; - - // - // Support and Resistance ... - - // - // Support ... - isBearish = false; - isBullish = barAnalysis.IsSupport(); - has = isBullish; - if (has) - { - // - pattern = X_BAR_PATTERN_SUPPORT; - patternDir = X_DIRECTION_BULLISH; - canDraw = config.CanDraw(pattern); - if (canDraw) - { - // - has = barAnalysis.GetPattern( - patternBar, - patternPivot, - patternBox, - pattern, - patternDir // - ); - if (has) - { - // - canDrawZone = config.CanDrawZone(pattern); - if (!canDrawZone) - { - patternBox.Clean(); - } - - // - canDrawPivot = config.CanDrawPivot(pattern); - if (!canDrawPivot) - { - patternPivot.Clean(); - } - - // - DrawPattern( - patternBar, - patternPivot, - patternBox, - pattern, - patternDir // - ); - } - } - } - - // - // Resistance ... - isBullish = false; - isBearish = barAnalysis.IsResistance(); - has = isBearish; - if (has) - { - // - pattern = X_BAR_PATTERN_RESISTANCE; - patternDir = X_DIRECTION_BEARISH; - canDraw = config.CanDraw(pattern); - if (canDraw) - { - // - has = barAnalysis.GetPattern( - patternBar, - patternPivot, - patternBox, - pattern, - patternDir // - ); - if (has) - { - // - canDrawZone = config.CanDrawZone(pattern); - if (!canDrawZone) - { - patternBox.Clean(); - } - - // - canDrawPivot = config.CanDrawPivot(pattern); - if (!canDrawPivot) - { - patternPivot.Clean(); - } - - // - DrawPattern( - patternBar, - patternPivot, - patternBox, - pattern, - patternDir // - ); - } - } - } - - // - // PV: High and Low ... - - // - // Low ... - isBearish = false; - isBullish = barAnalysis.IsLow(); - has = isBullish; - if (has) - { - // - pattern = X_BAR_PATTERN_LOW; - patternDir = X_DIRECTION_BULLISH; - canDraw = config.CanDraw(pattern); - if (canDraw) - { - // - has = barAnalysis.GetPattern( - patternBar, - patternPivot, - patternBox, - pattern, - patternDir // - ); - if (has) - { - // - canDrawZone = config.CanDrawZone(pattern); - if (!canDrawZone) - { - patternBox.Clean(); - } - - // - canDrawPivot = config.CanDrawPivot(pattern); - if (!canDrawPivot) - { - patternPivot.Clean(); - } - - // - DrawPattern( - patternBar, - patternPivot, - patternBox, - pattern, - patternDir // - ); - } - } - } - - // - // High ... - isBullish = false; - isBearish = barAnalysis.IsHigh(); - has = isBearish; - if (has) - { - // - pattern = X_BAR_PATTERN_HIGH; - patternDir = X_DIRECTION_BEARISH; - canDraw = config.CanDraw(pattern); - if (canDraw) - { - // - has = barAnalysis.GetPattern( - patternBar, - patternPivot, - patternBox, - pattern, - patternDir // - ); - if (has) - { - // - canDrawZone = config.CanDrawZone(pattern); - if (!canDrawZone) - { - patternBox.Clean(); - } - - // - canDrawPivot = config.CanDrawPivot(pattern); - if (!canDrawPivot) - { - patternPivot.Clean(); - } - - // - DrawPattern( - patternBar, - patternPivot, - patternBox, - pattern, - patternDir // - ); - } - } - } - - // - // OB ... - isBullish = barAnalysis.IsOB(X_DIRECTION_BULLISH); - isBearish = barAnalysis.IsOB(X_DIRECTION_BEARISH); - has = isBullish || isBearish; - if (has) - { - // - pattern = X_BAR_PATTERN_OB; - patternDir = - isBullish - ? X_DIRECTION_BULLISH - : X_DIRECTION_BEARISH; - canDraw = config.CanDraw(pattern); - if (canDraw) - { - // - has = barAnalysis.GetPattern( - patternBar, - patternPivot, - patternBox, - pattern, - patternDir // - ); - if (has) - { - // - canDrawZone = config.CanDrawZone(pattern); - if (!canDrawZone) - { - patternBox.Clean(); - } - - // - canDrawPivot = config.CanDrawPivot(pattern); - if (!canDrawPivot) - { - patternPivot.Clean(); - } - - // - DrawPattern( - patternBar, - patternPivot, - patternBox, - pattern, - patternDir // - ); - } - } - } - - // - // FVG ... - isBullish = barAnalysis.IsFVG(X_DIRECTION_BULLISH); - isBearish = barAnalysis.IsFVG(X_DIRECTION_BEARISH); - has = isBullish || isBearish; - if (has) - { - // - pattern = X_BAR_PATTERN_FVG; - patternDir = - isBullish - ? X_DIRECTION_BULLISH - : X_DIRECTION_BEARISH; - canDraw = config.CanDraw(pattern); - if (canDraw) - { - // - has = barAnalysis.GetPattern( - patternBar, - patternPivot, - patternBox, - pattern, - patternDir // - ); - if (has) - { - // - canDrawZone = config.CanDrawZone(pattern); - if (!canDrawZone) - { - patternBox.Clean(); - } - - // - canDrawPivot = config.CanDrawPivot(pattern); - if (!canDrawPivot) - { - patternPivot.Clean(); - } - - // - DrawPattern( - patternBar, - patternPivot, - patternBox, - pattern, - patternDir // - ); - } - } - } - - // - // Momentum ... - isBullish = barAnalysis.IsMomentum(X_DIRECTION_BULLISH); - isBearish = barAnalysis.IsMomentum(X_DIRECTION_BEARISH); - has = isBullish || isBearish; - if (has) - { - // - pattern = X_BAR_PATTERN_MOMENTUM; - patternDir = - isBullish - ? X_DIRECTION_BULLISH - : X_DIRECTION_BEARISH; - canDraw = config.CanDraw(pattern); - if (canDraw) - { - // - has = barAnalysis.GetPattern( - patternBar, - patternPivot, - patternBox, - pattern, - patternDir // - ); - if (has) - { - // - canDrawZone = config.CanDrawZone(pattern); - if (!canDrawZone) - { - patternBox.Clean(); - } - - // - canDrawPivot = config.CanDrawPivot(pattern); - if (!canDrawPivot) - { - patternPivot.Clean(); - } - - // - DrawPattern( - patternBar, - patternPivot, - patternBox, - pattern, - patternDir // - ); - } - } - } - - // - // Engulfed ... - isBullish = barAnalysis.IsEngulfed(X_DIRECTION_BULLISH); - isBearish = barAnalysis.IsEngulfed(X_DIRECTION_BEARISH); - has = isBullish || isBearish; - if (has) - { - // - pattern = X_BAR_PATTERN_ENGULFED; - patternDir = - isBullish - ? X_DIRECTION_BULLISH - : X_DIRECTION_BEARISH; - canDraw = config.CanDraw(pattern); - if (canDraw) - { - // - has = barAnalysis.GetPattern( - patternBar, - patternPivot, - patternBox, - pattern, - patternDir // - ); - if (has) - { - // - canDrawZone = config.CanDrawZone(pattern); - if (!canDrawZone) - { - patternBox.Clean(); - } - - // - canDrawPivot = config.CanDrawPivot(pattern); - if (!canDrawPivot) - { - patternPivot.Clean(); - } - - // - DrawPattern( - patternBar, - patternPivot, - patternBox, - pattern, - patternDir // - ); - } - } - } - - // - // Pinned ... - isBullish = barAnalysis.IsPinned(X_DIRECTION_BULLISH); - isBearish = barAnalysis.IsPinned(X_DIRECTION_BEARISH); - has = isBullish || isBearish; - if (has) - { - // - pattern = X_BAR_PATTERN_PINNED; - patternDir = - isBullish - ? X_DIRECTION_BULLISH - : X_DIRECTION_BEARISH; - canDraw = config.CanDraw(pattern); - if (canDraw) - { - // - has = barAnalysis.GetPattern( - patternBar, - patternPivot, - patternBox, - pattern, - patternDir // - ); - if (has) - { - // - canDrawZone = config.CanDrawZone(pattern); - if (!canDrawZone) - { - patternBox.Clean(); - } - - // - canDrawPivot = config.CanDrawPivot(pattern); - if (!canDrawPivot) - { - patternPivot.Clean(); - } - - // - DrawPattern( - patternBar, - patternPivot, - patternBox, - pattern, - patternDir // - ); - } - } - } - - // - // TrueGaped ... - isBullish = barAnalysis.IsTrueGaped(X_DIRECTION_BULLISH); - isBearish = barAnalysis.IsTrueGaped(X_DIRECTION_BEARISH); - has = isBullish || isBearish; - if (has) - { - // - pattern = X_BAR_PATTERN_TRUE_GAPED; - patternDir = - isBullish - ? X_DIRECTION_BULLISH - : X_DIRECTION_BEARISH; - canDraw = config.CanDraw(pattern); - if (canDraw) - { - // - has = barAnalysis.GetPattern( - patternBar, - patternPivot, - patternBox, - pattern, - patternDir // - ); - if (has) - { - // - canDrawZone = config.CanDrawZone(pattern); - if (!canDrawZone) - { - patternBox.Clean(); - } - - // - canDrawPivot = config.CanDrawPivot(pattern); - if (!canDrawPivot) - { - patternPivot.Clean(); - } - - // - DrawPattern( - patternBar, - patternPivot, - patternBox, - pattern, - patternDir // - ); - } - } - } - - // - // Star ... - isBullish = barAnalysis.IsStar(X_DIRECTION_BULLISH); - isBearish = barAnalysis.IsStar(X_DIRECTION_BEARISH); - has = isBullish || isBearish; - if (has) - { - // - pattern = X_BAR_PATTERN_STAR; - patternDir = - isBullish - ? X_DIRECTION_BULLISH - : X_DIRECTION_BEARISH; - canDraw = config.CanDraw(pattern); - if (canDraw) - { - // - has = barAnalysis.GetPattern( - patternBar, - patternPivot, - patternBox, - pattern, - patternDir // - ); - if (has) - { - // - canDrawZone = config.CanDrawZone(pattern); - if (!canDrawZone) - { - patternBox.Clean(); - } - - // - canDrawPivot = config.CanDrawPivot(pattern); - if (!canDrawPivot) - { - patternPivot.Clean(); - } - - // - DrawPattern( - patternBar, - patternPivot, - patternBox, - pattern, - patternDir // - ); - } - } - } - - // - // Piercing ... - isBullish = barAnalysis.IsPiercing(X_DIRECTION_BULLISH); - isBearish = barAnalysis.IsPiercing(X_DIRECTION_BEARISH); - has = isBullish || isBearish; - if (has) - { - // - pattern = X_BAR_PATTERN_PIERCING; - patternDir = - isBullish - ? X_DIRECTION_BULLISH - : X_DIRECTION_BEARISH; - canDraw = config.CanDraw(pattern); - if (canDraw) - { - // - has = barAnalysis.GetPattern( - patternBar, - patternPivot, - patternBox, - pattern, - patternDir // - ); - if (has) - { - // - canDrawZone = config.CanDrawZone(pattern); - if (!canDrawZone) - { - patternBox.Clean(); - } - - // - canDrawPivot = config.CanDrawPivot(pattern); - if (!canDrawPivot) - { - patternPivot.Clean(); - } - - // - DrawPattern( - patternBar, - patternPivot, - patternBox, - pattern, - patternDir // - ); - } - } - } - - // - // Rising ... - isBullish = barAnalysis.IsRising(X_DIRECTION_BULLISH); - isBearish = barAnalysis.IsRising(X_DIRECTION_BEARISH); - has = isBullish || isBearish; - if (has) - { - // - pattern = X_BAR_PATTERN_RISING; - patternDir = - isBullish - ? X_DIRECTION_BULLISH - : X_DIRECTION_BEARISH; - canDraw = config.CanDraw(pattern); - if (canDraw) - { - // - has = barAnalysis.GetPattern( - patternBar, - patternPivot, - patternBox, - pattern, - patternDir // - ); - if (has) - { - // - canDrawZone = config.CanDrawZone(pattern); - if (!canDrawZone) - { - patternBox.Clean(); - } - - // - canDrawPivot = config.CanDrawPivot(pattern); - if (!canDrawPivot) - { - patternPivot.Clean(); - } - - // - DrawPattern( - patternBar, - patternPivot, - patternBox, - pattern, - patternDir // - ); - } - } - } - - // - // Flag ... - isBullish = barAnalysis.IsFlag(X_DIRECTION_BULLISH); - isBearish = barAnalysis.IsFlag(X_DIRECTION_BEARISH); - has = isBullish || isBearish; - if (has) - { - // - pattern = X_BAR_PATTERN_FLAG; - patternDir = - isBullish - ? X_DIRECTION_BULLISH - : X_DIRECTION_BEARISH; - canDraw = config.CanDraw(pattern); - if (canDraw) - { - // - has = barAnalysis.GetPattern( - patternBar, - patternPivot, - patternBox, - pattern, - patternDir // - ); - if (has) - { - // - canDrawZone = config.CanDrawZone(pattern); - if (!canDrawZone) - { - patternBox.Clean(); - } - - // - canDrawPivot = config.CanDrawPivot(pattern); - if (!canDrawPivot) - { - patternPivot.Clean(); - } - - // - DrawPattern( - patternBar, - patternPivot, - patternBox, - pattern, - patternDir // - ); - } - } - } - - // - // SignalKey ... - isBullish = barAnalysis.IsSignalKey(X_DIRECTION_BULLISH); - isBearish = barAnalysis.IsSignalKey(X_DIRECTION_BEARISH); - has = isBullish || isBearish; - if (has) - { - // - pattern = X_BAR_PATTERN_SIGNALKEY; - patternDir = - isBullish - ? X_DIRECTION_BULLISH - : X_DIRECTION_BEARISH; - canDraw = config.CanDraw(pattern); - if (canDraw) - { - // - has = barAnalysis.GetPattern( - patternBar, - patternPivot, - patternBox, - pattern, - patternDir // - ); - if (has) - { - // - canDrawZone = config.CanDrawZone(pattern); - if (!canDrawZone) - { - patternBox.Clean(); - } - - // - canDrawPivot = config.CanDrawPivot(pattern); - if (!canDrawPivot) - { - patternPivot.Clean(); - } - - // - DrawPattern( - patternBar, - patternPivot, - patternBox, - pattern, - patternDir // - ); - } - } - } - - // - // Cleanup Resources ... - patternBar.Clean(); - patternBox.Clean(); - patternPivot.Clean(); - } - // }; 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 b73b35b1..de1d9c22 100644 --- a/XFIMAEA/Classes/x-saherelm.xfima.x-poi.detector.class.mq5 +++ b/XFIMAEA/Classes/x-saherelm.xfima.x-poi.detector.class.mq5 @@ -98,7 +98,7 @@ class XCXFIMAPOIDetector : public XCMarketPatternDetector // // Reading Pivots ... XPivot pivots[]; - int count = ExtractPVPivots( + int count = fimaHelper.ExtractPVPivots( pivots, // Result ... barIndex, // Bar Index ... requiredNumberOFPivots, // Required Number of Pivots ... @@ -167,7 +167,7 @@ class XCXFIMAPOIDetector : public XCMarketPatternDetector // // Reading Pivots ... XPivot pivots[]; - int count = ExtractMAPivots( + int count = fimaHelper.ExtractMAPivots( pivots, // Result ... barIndex, // Bar Index ... requiredNumberOFPivots, // Required Number of Pivots ... @@ -234,7 +234,7 @@ class XCXFIMAPOIDetector : public XCMarketPatternDetector // // Reading Pivots ... XPivot pivots[]; - int count = ExtractSARPivots( + int count = fimaHelper.ExtractSARPivots( pivots, // Result ... barIndex, // Bar Index ... requiredNumberOFPivots, // Required Number of Pivots ... @@ -300,7 +300,7 @@ class XCXFIMAPOIDetector : public XCMarketPatternDetector // // Reading Pivots ... XPivot pivots[]; - int count = ExtractZigZagPivots( + int count = fimaHelper.ExtractZigZagPivots( pivots, // Result ... barIndex, // Bar Index ... requiredNumberOFPivots, // Required Number of Pivots ... @@ -339,143 +339,6 @@ class XCXFIMAPOIDetector : public XCMarketPatternDetector return result; } - // - // Pivot Extractors ... - - /** - * 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 ... - * @param validationLength: int, Specified Pivots Validation Length ignore if <= 0 ... - * - * @return ( int ) - */ - int ExtractPVPivots( - XPivot &pivots[], - int barIndex = 0, - int requiredNumberOFPivots = 50, - int maxAllowedLoopbackLength = 1500, - int validationLength = 0 // - ) - { - // - int result = 0; - - // - result = fimaHelper.ExtractPVPivots( - pivots, - barIndex, - requiredNumberOFPivots, - maxAllowedLoopbackLength, - validationLength // - ); - - // - 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 ... - * @param validationLength: int, Specified Pivots Validation Length ignore if <= 0 ... - * - * @return ( int ) - */ - int ExtractMAPivots( - XPivot &pivots[], - int barIndex = 0, - int requiredNumberOFPivots = 50, - int maxAllowedLoopbackLength = 1500, - int validationLength = 0 // - ) - { - // - int result = 0; - - // - result = fimaHelper.ExtractMAPivots( - pivots, - barIndex, - requiredNumberOFPivots, - maxAllowedLoopbackLength, - validationLength // - ); - - // - 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 ExtractSARPivots( - XPivot &pivots[], - int barIndex = 0, - int requiredNumberOFPivots = 50, - int maxAllowedLoopbackLength = 1500 // - ) - { - // - int result = 0; - - // - result = fimaHelper.ExtractSARPivots( - pivots, - barIndex, - requiredNumberOFPivots, - maxAllowedLoopbackLength // - ); - - // - 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 ExtractZigZagPivots( - XPivot &pivots[], - int barIndex = 0, - int requiredNumberOFPivots = 50, - int maxAllowedLoopbackLength = 1500 // - ) - { - // - int result = 0; - - // - result = fimaHelper.ExtractZigZagPivots( - pivots, - barIndex, - requiredNumberOFPivots, - maxAllowedLoopbackLength // - ); - - // - return result; - } - /** * Destroy ... */ @@ -508,968 +371,968 @@ class XCXFIMAPOIDetector : public XCMarketPatternDetector XFIMAPatternDetectorConfig &config // ) { - // - // Prepare ... - structure.Clean(); + // // + // // Prepare ... + // structure.Clean(); - // - // Validate ... - if (!forBar.IsValid()) - { - return; - } + // // + // // Validate ... + // if (!forBar.IsValid()) + // { + // return; + // } - // - // Do Analysis ... + // // + // // Do Analysis ... - // - structure.bar = forBar; + // // + // structure.bar = forBar; - // - int idx = -1; - int count = 0; - XBoxZone iBox; - bool has = false; - ENUM_X_DIRECTION iDir = X_DIRECTION_NONE; + // // + // int idx = -1; + // int count = 0; + // XBoxZone iBox; + // bool has = false; + // ENUM_X_DIRECTION iDir = X_DIRECTION_NONE; - // - // Detecting POI Based on Config ... + // // + // // Detecting POI Based on Config ... - // - // Checking Momentum Bar ... - if (config.detectMomentum) - { - // - bool isMomentum = IsMomentumBar( - forBar, - iDir, - config.momentumBarRangeLength, - config.momentumBarApprovedMultiplier // - ); - bool isBullishMomentum = isMomentum && - IsSpecifiedBullish(iDir); - bool isBearishMomentum = isMomentum && - IsSpecifiedBearish(iDir); - if (isMomentum) - { - structure.momentumDir = iDir; - } - } + // // + // // Checking Momentum Bar ... + // if (config.detectMomentum) + // { + // // + // bool isMomentum = IsMomentumBar( + // forBar, + // iDir, + // config.momentumBarRangeLength, + // config.momentumBarApprovedMultiplier // + // ); + // bool isBullishMomentum = isMomentum && + // IsSpecifiedBullish(iDir); + // bool isBearishMomentum = isMomentum && + // IsSpecifiedBearish(iDir); + // if (isMomentum) + // { + // structure.momentumDir = iDir; + // } + // } - // - // Checking Engulfed Bar ... - if (config.detectEngulfed) - { - // - bool isEngulfed = IsEngulfedBar( - forBar, - iDir // - ); - bool isBullishEngulfed = isEngulfed && - IsSpecifiedBullish(iDir); - bool isBearishEngulfed = isEngulfed && - IsSpecifiedBearish(iDir); - if (isEngulfed) - { - structure.engulfedDir = iDir; - } - } + // // + // // Checking Engulfed Bar ... + // if (config.detectEngulfed) + // { + // // + // bool isEngulfed = IsEngulfedBar( + // forBar, + // iDir // + // ); + // bool isBullishEngulfed = isEngulfed && + // IsSpecifiedBullish(iDir); + // bool isBearishEngulfed = isEngulfed && + // IsSpecifiedBearish(iDir); + // if (isEngulfed) + // { + // structure.engulfedDir = iDir; + // } + // } - // - // Checking TruGaped Bar ... - if (config.detectTrueGaped) - { - // - bool isTrueGaped = IsTrueGapedBar( - forBar, - iDir, - config.truwGapApprovedPointMultiplier // - ); - bool isBullishTrueGaped = isTrueGaped && - IsSpecifiedBullish(iDir); - bool isBearishTrueGaped = isTrueGaped && - IsSpecifiedBearish(iDir); - if (isTrueGaped) - { - structure.trueGapedDir = iDir; - } - } + // // + // // Checking TruGaped Bar ... + // if (config.detectTrueGaped) + // { + // // + // bool isTrueGaped = IsTrueGapedBar( + // forBar, + // iDir, + // config.truwGapApprovedPointMultiplier // + // ); + // bool isBullishTrueGaped = isTrueGaped && + // IsSpecifiedBullish(iDir); + // bool isBearishTrueGaped = isTrueGaped && + // IsSpecifiedBearish(iDir); + // if (isTrueGaped) + // { + // structure.trueGapedDir = iDir; + // } + // } - // - // Checking Pinned Bar ... - if (config.detectPinned) - { - // - bool isPinned = IsPinnedBar( - forBar, - iDir, - config.pinnedBaarShadowApprovedMultiplier, - config.pinnedBarMinimumPinBarRangeMultiplier, - config.pinnedBarForceDirection // - ); - bool isBullishPinned = isPinned && - IsSpecifiedBullish(iDir); - bool isBearishPinned = isPinned && - IsSpecifiedBearish(iDir); - if (isPinned) - { - structure.pinnedDir = iDir; - } - } + // // + // // Checking Pinned Bar ... + // if (config.detectPinned) + // { + // // + // bool isPinned = IsPinnedBar( + // forBar, + // iDir, + // config.pinnedBaarShadowApprovedMultiplier, + // config.pinnedBarMinimumPinBarRangeMultiplier, + // config.pinnedBarForceDirection // + // ); + // bool isBullishPinned = isPinned && + // IsSpecifiedBullish(iDir); + // bool isBearishPinned = isPinned && + // IsSpecifiedBearish(iDir); + // if (isPinned) + // { + // structure.pinnedDir = iDir; + // } + // } - // - // Checking Star Pattern ... - if (config.detectStarPattern) - { - // - bool isStarPattern = IsStarPattern( - forBar, - iDir // - ); - bool isBullishStarPattern = isStarPattern && - IsSpecifiedBullish(iDir); - bool isBearishStarPattern = isStarPattern && - IsSpecifiedBearish(iDir); - if (isStarPattern) - { - structure.starPatternDir = iDir; - } - } + // // + // // Checking Star Pattern ... + // if (config.detectStarPattern) + // { + // // + // bool isStarPattern = IsStarPattern( + // forBar, + // iDir // + // ); + // bool isBullishStarPattern = isStarPattern && + // IsSpecifiedBullish(iDir); + // bool isBearishStarPattern = isStarPattern && + // IsSpecifiedBearish(iDir); + // if (isStarPattern) + // { + // structure.starPatternDir = iDir; + // } + // } - // - // Checking Piercing Pattern ... - if (config.detectPiercingPattern) - { - // - bool isPiercingPattern = IsPiercingPattern( - forBar, - iDir // - ); - bool isBullishPiercingPattern = isPiercingPattern && - IsSpecifiedBullish(iDir); - bool isBearishPiercingPattern = isPiercingPattern && - IsSpecifiedBearish(iDir); - if (isPiercingPattern) - { - structure.piercingPatternDir = iDir; - } - } + // // + // // Checking Piercing Pattern ... + // if (config.detectPiercingPattern) + // { + // // + // bool isPiercingPattern = IsPiercingPattern( + // forBar, + // iDir // + // ); + // bool isBullishPiercingPattern = isPiercingPattern && + // IsSpecifiedBullish(iDir); + // bool isBearishPiercingPattern = isPiercingPattern && + // IsSpecifiedBearish(iDir); + // if (isPiercingPattern) + // { + // structure.piercingPatternDir = iDir; + // } + // } - // - // Checking Rising Pattern ... - if (config.detectRisingPattern) - { - // - bool isRisingPattern = IsRisingPattern( - forBar, - iDir // - ); - bool isBullishRisingPattern = isRisingPattern && - IsSpecifiedBullish(iDir); - bool isBearishRisingPattern = isRisingPattern && - IsSpecifiedBearish(iDir); - if (isRisingPattern) - { - structure.risingPatternDir = iDir; - } - } + // // + // // Checking Rising Pattern ... + // if (config.detectRisingPattern) + // { + // // + // bool isRisingPattern = IsRisingPattern( + // forBar, + // iDir // + // ); + // bool isBullishRisingPattern = isRisingPattern && + // IsSpecifiedBullish(iDir); + // bool isBearishRisingPattern = isRisingPattern && + // IsSpecifiedBearish(iDir); + // if (isRisingPattern) + // { + // structure.risingPatternDir = iDir; + // } + // } - // - // Checking Flag Pattern ... - if (config.detectFlagPattern) - { - // - XOHCL swingBar; - bool isFlagPattern = IsFlagPattern( - forBar, - iDir, - swingBar, - config.flagPatternMinimumPullbackBars // - ); - bool isBullishFlagPattern = isFlagPattern && - IsSpecifiedBullish(iDir); - bool isBearishFlagPattern = isFlagPattern && - IsSpecifiedBearish(iDir); - if (isFlagPattern) - { - // - structure.flagSwing = swingBar; - structure.flagPatternDir = iDir; - } - swingBar.Clean(); - } + // // + // // Checking Flag Pattern ... + // if (config.detectFlagPattern) + // { + // // + // XOHCL swingBar; + // bool isFlagPattern = IsFlagPattern( + // forBar, + // iDir, + // swingBar, + // config.flagPatternMinimumPullbackBars // + // ); + // bool isBullishFlagPattern = isFlagPattern && + // IsSpecifiedBullish(iDir); + // bool isBearishFlagPattern = isFlagPattern && + // IsSpecifiedBearish(iDir); + // if (isFlagPattern) + // { + // // + // structure.flagSwing = swingBar; + // structure.flagPatternDir = iDir; + // } + // swingBar.Clean(); + // } - // - // Detect SignalKey Bar Pattern ... - if (config.detectSignalKeyBarPattern) - { - // - bool isSignalKeyBar = IsSignalKeyBarPattern( - forBar, - iDir, - config.signalKeyBarShadowApprovedMultiplier, - config.signalKeyBarMinimumPinBarRangeMultiplier, - config.signalKeyBarForceDirection // - ); - bool isBullishSignalKeyBar = isSignalKeyBar && - IsSpecifiedBullish(iDir); - bool isBearishSignalKeyBar = isSignalKeyBar && - IsSpecifiedBearish(iDir); - if (isSignalKeyBar) - { - structure.signalKeyBarPatternDir = iDir; - } - } + // // + // // Detect SignalKey Bar Pattern ... + // if (config.detectSignalKeyBarPattern) + // { + // // + // bool isSignalKeyBar = IsSignalKeyBarPattern( + // forBar, + // iDir, + // config.signalKeyBarShadowApprovedMultiplier, + // config.signalKeyBarMinimumPinBarRangeMultiplier, + // config.signalKeyBarForceDirection // + // ); + // bool isBullishSignalKeyBar = isSignalKeyBar && + // IsSpecifiedBullish(iDir); + // bool isBearishSignalKeyBar = isSignalKeyBar && + // IsSpecifiedBearish(iDir); + // if (isSignalKeyBar) + // { + // structure.signalKeyBarPatternDir = iDir; + // } + // } - // - // Detect Swing Trend ... - if (config.detectSwingTrend) - { - // - XOHCL swings[]; - bool hasSwingTrend = HasSwingTrend( - forBar, - iDir, - swings, - config.trendingNumberOfSwings, - config.trendingSwingShoulders // - ); - bool hasBullishSwingTrend = hasSwingTrend && - IsSpecifiedBullish(iDir); - bool hasBearishSwingTrend = hasSwingTrend && - IsSpecifiedBearish(iDir); - if (hasSwingTrend) - { - // - Copy( - swings, - structure.trendSwings // - ); - structure.trendDir = iDir; - } - SpecifiedClean(swings); - } + // // + // // Detect Swing Trend ... + // if (config.detectSwingTrend) + // { + // // + // XOHCL swings[]; + // bool hasSwingTrend = HasSwingTrend( + // forBar, + // iDir, + // swings, + // config.trendingNumberOfSwings, + // config.trendingSwingShoulders // + // ); + // bool hasBullishSwingTrend = hasSwingTrend && + // IsSpecifiedBullish(iDir); + // bool hasBearishSwingTrend = hasSwingTrend && + // IsSpecifiedBearish(iDir); + // if (hasSwingTrend) + // { + // // + // Copy( + // swings, + // structure.trendSwings // + // ); + // structure.trendDir = iDir; + // } + // SpecifiedClean(swings); + // } - // - // Custom Indicator Pivots ... + // // + // // Custom Indicator Pivots ... - // - // Detecting MA Crosses ... - if (config.detectMACrosses) - { - // - idx = forBar.Index(); - has = fimaHelper.HasMACross( - structure.maCrossDir, - idx, - config.validMACrossDiffMultiplier // - ); + // // + // // Detecting MA Crosses ... + // if (config.detectMACrosses) + // { + // // + // idx = forBar.Index(); + // has = fimaHelper.HasMACross( + // structure.maCrossDir, + // idx, + // config.validMACrossDiffMultiplier // + // ); - // - fimaHelper.ExtractMAPivots( - structure.maCrosses, - idx, - config.zonesRequiredNumber, - config.validMACrossDiffMultiplier, - config.zonesMaxAllowedLoopbackLength // - ); - } + // // + // fimaHelper.ExtractMAPivots( + // structure.maCrosses, + // idx, + // config.zonesRequiredNumber, + // config.validMACrossDiffMultiplier, + // config.zonesMaxAllowedLoopbackLength // + // ); + // } - // - // Detecting HK Switches ... - if (config.detectHKSwitches) - { - // - idx = forBar.Index(); - has = fimaHelper.HasHKSwitch( - structure.hkSwitchDir, - idx // - ); + // // + // // Detecting HK Switches ... + // if (config.detectHKSwitches) + // { + // // + // idx = forBar.Index(); + // has = fimaHelper.HasHKSwitch( + // structure.hkSwitchDir, + // idx // + // ); - // - fimaHelper.ExtractHKPivots( - structure.hkSwitches, - idx, - config.zonesRequiredNumber, - config.zonesMaxAllowedLoopbackLength // - ); - } + // // + // fimaHelper.ExtractHKPivots( + // structure.hkSwitches, + // idx, + // config.zonesRequiredNumber, + // config.zonesMaxAllowedLoopbackLength // + // ); + // } - // - // Detecting SAR Switches ... - if (config.detectSARSwitches) - { - // - idx = forBar.Index(); - has = fimaHelper.HasSARSwitch( - structure.sarSwitchDir, - idx // - ); + // // + // // Detecting SAR Switches ... + // if (config.detectSARSwitches) + // { + // // + // idx = forBar.Index(); + // has = fimaHelper.HasSARSwitch( + // structure.sarSwitchDir, + // idx // + // ); - // - fimaHelper.ExtractSARPivots( - structure.sarSwitches, - idx, - config.zonesRequiredNumber, - config.zonesMaxAllowedLoopbackLength // - ); - } + // // + // fimaHelper.ExtractSARPivots( + // structure.sarSwitches, + // idx, + // config.zonesRequiredNumber, + // config.zonesMaxAllowedLoopbackLength // + // ); + // } - // - // Custom Analysers ... + // // + // // Custom Analysers ... - // - // Analyse Based on PV ... - if (config.analyseFIMAPVPivots) - { - // - XPivotAnalysis analysis; - has = AnalysePVPivots( - analysis, // Result ... - forBar.Index(), // Bar Index ... - config.numberOfRequiredPivotsForAnalysis, // Required Number of Pivots ... - config.maxAllowedLoopbackLengthForAnalysis, // Max Allowed Loopback ... - config.pvPivotsValidationLength // Validation Length ... - ); - if (has) - { - structure.pvAnalysis = analysis; - } - } + // // + // // Analyse Based on PV ... + // if (config.analyseFIMAPVPivots) + // { + // // + // XPivotAnalysis analysis; + // has = AnalysePVPivots( + // analysis, // Result ... + // forBar.Index(), // Bar Index ... + // config.numberOfRequiredPivotsForAnalysis, // Required Number of Pivots ... + // config.maxAllowedLoopbackLengthForAnalysis, // Max Allowed Loopback ... + // config.pvPivotsValidationLength // Validation Length ... + // ); + // if (has) + // { + // structure.pvAnalysis = analysis; + // } + // } - // - // Analyse Based on ZigZag ... - if (config.analyseFIMAZigZagPivots) - { - // - XPivotAnalysis analysis; - has = AnalyseZigZagPivots( - analysis, // Result ... - forBar.Index(), // Bar Index ... - config.numberOfRequiredPivotsForAnalysis, // Required Number of Pivots ... - config.maxAllowedLoopbackLengthForAnalysis // Max Allowed Loopback ... - ); - if (has) - { - structure.zigzagAnalysis = analysis; - } - } + // // + // // Analyse Based on ZigZag ... + // if (config.analyseFIMAZigZagPivots) + // { + // // + // XPivotAnalysis analysis; + // has = AnalyseZigZagPivots( + // analysis, // Result ... + // forBar.Index(), // Bar Index ... + // config.numberOfRequiredPivotsForAnalysis, // Required Number of Pivots ... + // config.maxAllowedLoopbackLengthForAnalysis // Max Allowed Loopback ... + // ); + // if (has) + // { + // structure.zigzagAnalysis = analysis; + // } + // } - // - // Zones and Patterns Recent Actions ... - if (config.zonesRequiredNumber > 0 && - config.zonesMaxAllowedLoopbackLength > 0) - { - // - // Detect Recent Patterns ... + // // + // // Zones and Patterns Recent Actions ... + // if (config.zonesRequiredNumber > 0 && + // config.zonesMaxAllowedLoopbackLength > 0) + // { + // // + // // Detect Recent Patterns ... - // - XOHCL iBar; - XOHCL tmpBar; - XPivot iPivot; - XBoxZone iBox; - bool has = false; - string iPrefix = NULL; - int start = forBar.Index(); - ENUM_X_SORT_BY iSortBy = X_SORT_BY_DATE; - ENUM_X_DIRECTION iDir = X_DIRECTION_NONE; - ENUM_X_DIRECTION iSortDir = X_DIRECTION_BULLISH; - int end = start + config.zonesMaxAllowedLoopbackLength; + // // + // XOHCL iBar; + // XOHCL tmpBar; + // XPivot iPivot; + // XBoxZone iBox; + // bool has = false; + // string iPrefix = NULL; + // int start = forBar.Index(); + // ENUM_X_SORT_BY iSortBy = X_SORT_BY_DATE; + // ENUM_X_DIRECTION iDir = X_DIRECTION_NONE; + // ENUM_X_DIRECTION iSortDir = X_DIRECTION_BULLISH; + // int end = start + config.zonesMaxAllowedLoopbackLength; - // - // Loop through Items ... - for (int i = start; i < end; i++) - { - // - iPivot.Clean(); + // // + // // Loop through Items ... + // for (int i = start; i < end; i++) + // { + // // + // iPivot.Clean(); - // - // Initialize Indexed Bar ... - has = forBar.BarAt(i, iBar); - if (!has) - { - // - iBar.Clean(); - continue; - } + // // + // // Initialize Indexed Bar ... + // has = forBar.BarAt(i, iBar); + // if (!has) + // { + // // + // iBar.Clean(); + // continue; + // } - // - // OB ... - has = HasOB( - iBar, - iDir, - iBox, - 5 // - ); - if (has) - { - // - AddIfNotExists( - iBox, - obs // - ); - } + // // + // // OB ... + // has = HasOB( + // iBar, + // iDir, + // iBox, + // 5 // + // ); + // if (has) + // { + // // + // AddIfNotExists( + // iBox, + // obs // + // ); + // } - // - // FVG ... - has = HasFVG( - iBar, - iDir, - iBox, - 5 // - ); - if (has) - { - // - AddIfNotExists( - iBox, - fvgs // - ); - } + // // + // // FVG ... + // has = HasFVG( + // iBar, + // iDir, + // iBox, + // 5 // + // ); + // if (has) + // { + // // + // AddIfNotExists( + // iBox, + // fvgs // + // ); + // } - // - // SUPPORT ... - tmpBar.Clean(); - has = HasSupport( - iBar, - tmpBar, - config.zonesValidationLength, - config.zonesMaxAllowedLoopbackLength // - ); - if (has) - { - // - has = ToSupportBox(tmpBar, iBox, iBar.time); - if (has) - { - // - // Check Strength ... - if (config.zonesMinAlloweStrength > 0) - { - has = (iBox.upper - iBox.lower) > (config.zonesMinAlloweStrength * GetPoints(iBar.symbol)); - } + // // + // // SUPPORT ... + // tmpBar.Clean(); + // has = HasSupport( + // iBar, + // tmpBar, + // config.zonesValidationLength, + // config.zonesMaxAllowedLoopbackLength // + // ); + // if (has) + // { + // // + // has = ToSupportBox(tmpBar, iBox, iBar.time); + // if (has) + // { + // // + // // Check Strength ... + // if (config.zonesMinAlloweStrength > 0) + // { + // has = (iBox.upper - iBox.lower) > (config.zonesMinAlloweStrength * GetPoints(iBar.symbol)); + // } - // - if (has) - { - // - AddIfNotExists( - iBox, - supports // - ); - } - } - } - iBox.Clean(); - tmpBar.Clean(); + // // + // if (has) + // { + // // + // AddIfNotExists( + // iBox, + // supports // + // ); + // } + // } + // } + // iBox.Clean(); + // tmpBar.Clean(); - // - // RESISATNCE ... - tmpBar.Clean(); - has = HasResistance( - iBar, - tmpBar, - config.zonesValidationLength, - config.zonesMaxAllowedLoopbackLength // - ); - if (has) - { - // - has = ToResistanceBox(tmpBar, iBox, iBar.time); - if (has) - { - // - // Check Strength ... - if (config.zonesMinAlloweStrength > 0) - { - has = (iBox.upper - iBox.lower) > (config.zonesMinAlloweStrength * GetPoints(iBar.symbol)); - } + // // + // // RESISATNCE ... + // tmpBar.Clean(); + // has = HasResistance( + // iBar, + // tmpBar, + // config.zonesValidationLength, + // config.zonesMaxAllowedLoopbackLength // + // ); + // if (has) + // { + // // + // has = ToResistanceBox(tmpBar, iBox, iBar.time); + // if (has) + // { + // // + // // Check Strength ... + // if (config.zonesMinAlloweStrength > 0) + // { + // has = (iBox.upper - iBox.lower) > (config.zonesMinAlloweStrength * GetPoints(iBar.symbol)); + // } - // - if (has) - { - // - AddIfNotExists( - iBox, - resistances // - ); - } - } - } - iBox.Clean(); - tmpBar.Clean(); + // // + // if (has) + // { + // // + // AddIfNotExists( + // iBox, + // resistances // + // ); + // } + // } + // } + // iBox.Clean(); + // tmpBar.Clean(); - // - // Bars Detecting ... + // // + // // Bars Detecting ... - // - // Momentum Bars ... - if (config.detectMomentum) - { - // - iPrefix = "MomentumBar"; - has = IsMomentumBar( - iBar, - iDir, - config.momentumBarRangeLength, - config.momentumBarApprovedMultiplier // - ); - has = has && - ToPivot( - iBar, - iPivot, - iDir, - iPrefix // - ); - if (has) - { - // - AddIfNotExists( - iPivot, - structure.momentumBars // - ); - } - iPivot.Clean(); - } + // // + // // Momentum Bars ... + // if (config.detectMomentum) + // { + // // + // iPrefix = "MomentumBar"; + // has = IsMomentumBar( + // iBar, + // iDir, + // config.momentumBarRangeLength, + // config.momentumBarApprovedMultiplier // + // ); + // has = has && + // ToPivot( + // iBar, + // iPivot, + // iDir, + // iPrefix // + // ); + // if (has) + // { + // // + // AddIfNotExists( + // iPivot, + // structure.momentumBars // + // ); + // } + // iPivot.Clean(); + // } - // - // Engulfed Bars ... - if (config.detectEngulfed) - { - // - iPrefix = "EngulfedBar"; - has = IsEngulfedBar( - iBar, - iDir // - ); - has = has && - ToPivot( - iBar, - iPivot, - iDir, - iPrefix // - ); - if (has) - { - // - AddIfNotExists( - iPivot, - structure.engulfBars // - ); - } - iPivot.Clean(); - } + // // + // // Engulfed Bars ... + // if (config.detectEngulfed) + // { + // // + // iPrefix = "EngulfedBar"; + // has = IsEngulfedBar( + // iBar, + // iDir // + // ); + // has = has && + // ToPivot( + // iBar, + // iPivot, + // iDir, + // iPrefix // + // ); + // if (has) + // { + // // + // AddIfNotExists( + // iPivot, + // structure.engulfBars // + // ); + // } + // iPivot.Clean(); + // } - // - // TruGaped Bars ... - if (config.detectTrueGaped) - { - // - iPrefix = "TruGapedBar"; - has = IsTrueGapedBar( - iBar, - iDir, - config.truwGapApprovedPointMultiplier // - ); - has = has && - ToPivot( - iBar, - iPivot, - iDir, - iPrefix // - ); - if (has) - { - // - AddIfNotExists( - iPivot, - structure.trueGapBars // - ); - } - iPivot.Clean(); - } + // // + // // TruGaped Bars ... + // if (config.detectTrueGaped) + // { + // // + // iPrefix = "TruGapedBar"; + // has = IsTrueGapedBar( + // iBar, + // iDir, + // config.truwGapApprovedPointMultiplier // + // ); + // has = has && + // ToPivot( + // iBar, + // iPivot, + // iDir, + // iPrefix // + // ); + // if (has) + // { + // // + // AddIfNotExists( + // iPivot, + // structure.trueGapBars // + // ); + // } + // iPivot.Clean(); + // } - // - // Pin Bars ... - if (config.detectTrueGaped) - { - // - iPrefix = "PinBar"; - has = IsPinnedBar( - iBar, - iDir, - config.pinnedBaarShadowApprovedMultiplier, - config.pinnedBarMinimumPinBarRangeMultiplier, - config.pinnedBarForceDirection // - ); - has = has && - ToPivot( - iBar, - iPivot, - iDir, - iPrefix // - ); - if (has) - { - // - AddIfNotExists( - iPivot, - structure.pinBars // - ); - } - iPivot.Clean(); - } + // // + // // Pin Bars ... + // if (config.detectTrueGaped) + // { + // // + // iPrefix = "PinBar"; + // has = IsPinnedBar( + // iBar, + // iDir, + // config.pinnedBaarShadowApprovedMultiplier, + // config.pinnedBarMinimumPinBarRangeMultiplier, + // config.pinnedBarForceDirection // + // ); + // has = has && + // ToPivot( + // iBar, + // iPivot, + // iDir, + // iPrefix // + // ); + // if (has) + // { + // // + // AddIfNotExists( + // iPivot, + // structure.pinBars // + // ); + // } + // iPivot.Clean(); + // } - // - // Patterns Detecting ... + // // + // // Patterns Detecting ... - // - // Star Pattern ... - if (config.detectStarPattern) - { - // - iPrefix = "Star"; - has = IsStarPattern( - iBar, - iDir // - ); - has = has && - ToBox( - iBar, - iBox, - iDir, - iPrefix // - ); - if (has) - { - // - AddIfNotExists( - iBox, - structure.starPatterns // - ); - } - iBox.Clean(); - } + // // + // // Star Pattern ... + // if (config.detectStarPattern) + // { + // // + // iPrefix = "Star"; + // has = IsStarPattern( + // iBar, + // iDir // + // ); + // has = has && + // ToBox( + // iBar, + // iBox, + // iDir, + // iPrefix // + // ); + // if (has) + // { + // // + // AddIfNotExists( + // iBox, + // structure.starPatterns // + // ); + // } + // iBox.Clean(); + // } - // - // Piercing Pattern ... - if (config.detectPiercingPattern) - { - // - iPrefix = "Piercing"; - has = IsPiercingPattern( - iBar, - iDir // - ); - has = has && - ToBox( - iBar, - iBox, - iDir, - iPrefix // - ); - if (has) - { - // - AddIfNotExists( - iBox, - structure.piercingPatterns // - ); - } - iBox.Clean(); - } + // // + // // Piercing Pattern ... + // if (config.detectPiercingPattern) + // { + // // + // iPrefix = "Piercing"; + // has = IsPiercingPattern( + // iBar, + // iDir // + // ); + // has = has && + // ToBox( + // iBar, + // iBox, + // iDir, + // iPrefix // + // ); + // if (has) + // { + // // + // AddIfNotExists( + // iBox, + // structure.piercingPatterns // + // ); + // } + // iBox.Clean(); + // } - // - // Rising Pattern ... - if (config.detectRisingPattern) - { - // - iPrefix = "Rising"; - has = IsRisingPattern( - iBar, - iDir // - ); - has = has && - ToBox( - iBar, - iBox, - iDir, - iPrefix // - ); - if (has) - { - // - AddIfNotExists( - iBox, - structure.risingPatterns // - ); - } - iBox.Clean(); - } + // // + // // Rising Pattern ... + // if (config.detectRisingPattern) + // { + // // + // iPrefix = "Rising"; + // has = IsRisingPattern( + // iBar, + // iDir // + // ); + // has = has && + // ToBox( + // iBar, + // iBox, + // iDir, + // iPrefix // + // ); + // if (has) + // { + // // + // AddIfNotExists( + // iBox, + // structure.risingPatterns // + // ); + // } + // iBox.Clean(); + // } - // - // Flag Pattern ... - if (config.detectFlagPattern) - { - // - iPrefix = "Flag"; - XOHCL swingBar; - has = IsFlagPattern( - iBar, - iDir, - swingBar, - config.flagPatternMinimumPullbackBars // - ); - has = has && - ToBox( - iBar, - iBox, - iDir, - iPrefix // - ); - if (has) - { - // - AddIfNotExists( - iBox, - structure.flagPatterns // - ); - } - iBox.Clean(); - } + // // + // // Flag Pattern ... + // if (config.detectFlagPattern) + // { + // // + // iPrefix = "Flag"; + // XOHCL swingBar; + // has = IsFlagPattern( + // iBar, + // iDir, + // swingBar, + // config.flagPatternMinimumPullbackBars // + // ); + // has = has && + // ToBox( + // iBar, + // iBox, + // iDir, + // iPrefix // + // ); + // if (has) + // { + // // + // AddIfNotExists( + // iBox, + // structure.flagPatterns // + // ); + // } + // iBox.Clean(); + // } - // - // SignalKey Bar Pattern ... - if (config.detectSignalKeyBarPattern) - { - // - iPrefix = "SignalKeyBar"; - has = IsSignalKeyBarPattern( - iBar, - iDir, - config.signalKeyBarShadowApprovedMultiplier, - config.signalKeyBarMinimumPinBarRangeMultiplier, - config.signalKeyBarForceDirection // - ); - has = has && - ToBox( - iBar, - iBox, - iDir, - iPrefix // - ); - if (has) - { - // - AddIfNotExists( - iBox, - structure.signalKeyBarPatterns // - ); - } - iBox.Clean(); - } + // // + // // SignalKey Bar Pattern ... + // if (config.detectSignalKeyBarPattern) + // { + // // + // iPrefix = "SignalKeyBar"; + // has = IsSignalKeyBarPattern( + // iBar, + // iDir, + // config.signalKeyBarShadowApprovedMultiplier, + // config.signalKeyBarMinimumPinBarRangeMultiplier, + // config.signalKeyBarForceDirection // + // ); + // has = has && + // ToBox( + // iBar, + // iBox, + // iDir, + // iPrefix // + // ); + // if (has) + // { + // // + // AddIfNotExists( + // iBox, + // structure.signalKeyBarPatterns // + // ); + // } + // iBox.Clean(); + // } - // - iBar.Clean(); - iBox.Clean(); - tmpBar.Clean(); - iPivot.Clean(); - } + // // + // iBar.Clean(); + // iBox.Clean(); + // tmpBar.Clean(); + // iPivot.Clean(); + // } - // - // Zones Extractions ... + // // + // // Zones Extractions ... - // - // XBARZONES ... - XBoxZone tmpZones[]; - int tmpZonesCount = fimaHelper.ExtractBarZones( - tmpZones, - forBar.Index(), - config.zonesRequiredNumber, - config.zonesBreakValidationLength, - config.zonesBreakValidationLength > 0, - config.zonesBarShadowMultiplier, - config.zonesMinAlloweStrength, - config.zonesValidationLength, - config.zonesMaxAllowedLoopbackLength // - ); - has = IsValidSize(tmpZonesCount); - if (has) - { - // - for (int i = 0; i < tmpZonesCount; i++) - { - // - if (tmpZones[i].IsBullish()) - { - // - AddIfNotExists( - tmpZones[i], - supports // - ); - } - else if (tmpZones[i].IsBearish()) - { - // - AddIfNotExists( - tmpZones[i], - resistances // - ); - } - } - } + // // + // // XBARZONES ... + // XBoxZone tmpZones[]; + // int tmpZonesCount = fimaHelper.ExtractBarZones( + // tmpZones, + // forBar.Index(), + // config.zonesRequiredNumber, + // config.zonesBreakValidationLength, + // config.zonesBreakValidationLength > 0, + // config.zonesBarShadowMultiplier, + // config.zonesMinAlloweStrength, + // config.zonesValidationLength, + // config.zonesMaxAllowedLoopbackLength // + // ); + // has = IsValidSize(tmpZonesCount); + // if (has) + // { + // // + // for (int i = 0; i < tmpZonesCount; i++) + // { + // // + // if (tmpZones[i].IsBullish()) + // { + // // + // AddIfNotExists( + // tmpZones[i], + // supports // + // ); + // } + // else if (tmpZones[i].IsBearish()) + // { + // // + // AddIfNotExists( + // tmpZones[i], + // resistances // + // ); + // } + // } + // } - // - // XHK ... - XClean(tmpZones); - tmpZonesCount = fimaHelper.ExtractHKZones( - tmpZones, - forBar.Index(), - config.zonesRequiredNumber, - config.zonesBreakValidationLength, - config.zonesBreakValidationLength > 0, - config.zonesBarShadowMultiplier, - config.zonesMinAlloweStrength, - config.zonesValidationLength, - config.zonesMaxAllowedLoopbackLength // - ); - has = IsValidSize(tmpZonesCount); - if (has) - { - // - for (int i = 0; i < tmpZonesCount; i++) - { - // - if (tmpZones[i].IsBullish()) - { - // - AddIfNotExists( - tmpZones[i], - supports // - ); - } - else if (tmpZones[i].IsBearish()) - { - // - AddIfNotExists( - tmpZones[i], - resistances // - ); - } - } - } + // // + // // XHK ... + // XClean(tmpZones); + // tmpZonesCount = fimaHelper.ExtractHKZones( + // tmpZones, + // forBar.Index(), + // config.zonesRequiredNumber, + // config.zonesBreakValidationLength, + // config.zonesBreakValidationLength > 0, + // config.zonesBarShadowMultiplier, + // config.zonesMinAlloweStrength, + // config.zonesValidationLength, + // config.zonesMaxAllowedLoopbackLength // + // ); + // has = IsValidSize(tmpZonesCount); + // if (has) + // { + // // + // for (int i = 0; i < tmpZonesCount; i++) + // { + // // + // if (tmpZones[i].IsBullish()) + // { + // // + // AddIfNotExists( + // tmpZones[i], + // supports // + // ); + // } + // else if (tmpZones[i].IsBearish()) + // { + // // + // AddIfNotExists( + // tmpZones[i], + // resistances // + // ); + // } + // } + // } - // - // Cleanup Resources ... - iBar.Clean(); - iBox.Clean(); - tmpBar.Clean(); - iPivot.Clean(); - } + // // + // // Cleanup Resources ... + // iBar.Clean(); + // iBox.Clean(); + // tmpBar.Clean(); + // iPivot.Clean(); + // } - // - // Analysis Zones ... + // // + // // Analysis Zones ... - // - // XPV ... + // // + // // XPV ... - // - // Support ... - has = structure.pvAnalysis.IsValid() && - structure.pvAnalysis.HasSupportBox(iBox); - if (has) - { - // - AddIfNotExists( - iBox, - supports // - ); - } + // // + // // Support ... + // has = structure.pvAnalysis.IsValid() && + // structure.pvAnalysis.HasSupportBox(iBox); + // if (has) + // { + // // + // AddIfNotExists( + // iBox, + // supports // + // ); + // } - // - // Resistance ... - has = structure.pvAnalysis.IsValid() && - structure.pvAnalysis.HasResistanceBox(iBox); - if (has) - { - // - AddIfNotExists( - iBox, - resistances // - ); - } + // // + // // Resistance ... + // has = structure.pvAnalysis.IsValid() && + // structure.pvAnalysis.HasResistanceBox(iBox); + // if (has) + // { + // // + // AddIfNotExists( + // iBox, + // resistances // + // ); + // } - // - // XZG ... + // // + // // XZG ... - // - // Support ... - has = structure.zigzagAnalysis.IsValid() && - structure.zigzagAnalysis.HasSupportBox(iBox); - if (has) - { - // - AddIfNotExists( - iBox, - supports // - ); - } + // // + // // Support ... + // has = structure.zigzagAnalysis.IsValid() && + // structure.zigzagAnalysis.HasSupportBox(iBox); + // if (has) + // { + // // + // AddIfNotExists( + // iBox, + // supports // + // ); + // } - // - // Resistance ... - has = structure.zigzagAnalysis.IsValid() && - structure.zigzagAnalysis.HasResistanceBox(iBox); - if (has) - { - // - AddIfNotExists( - iBox, - resistances // - ); - } + // // + // // Resistance ... + // has = structure.zigzagAnalysis.IsValid() && + // structure.zigzagAnalysis.HasResistanceBox(iBox); + // if (has) + // { + // // + // AddIfNotExists( + // iBox, + // resistances // + // ); + // } - // - // ZONES Specified ... + // // + // // ZONES Specified ... - // - // OBS ... - CheckZones(forBar, obs); - UpdateToTime(obs, forBar.time); - Copy( - obs, - structure.obs // - ); + // // + // // OBS ... + // CheckZones(forBar, obs); + // UpdateToTime(obs, forBar.time); + // Copy( + // obs, + // structure.obs // + // ); - // - // FVGS ... - CheckZones(forBar, fvgs); - UpdateToTime(fvgs, forBar.time); - Copy( - fvgs, - structure.fvgs // - ); + // // + // // FVGS ... + // CheckZones(forBar, fvgs); + // UpdateToTime(fvgs, forBar.time); + // Copy( + // fvgs, + // structure.fvgs // + // ); - // - // SUPPORTS ... - CheckZones(forBar, supports); - UpdateToTime(supports, forBar.time); - Copy( - supports, - structure.supports // - ); + // // + // // SUPPORTS ... + // CheckZones(forBar, supports); + // UpdateToTime(supports, forBar.time); + // Copy( + // supports, + // structure.supports // + // ); - // - // RESISTANCES ... - CheckZones(forBar, resistances); - UpdateToTime(resistances, forBar.time); - Copy( - resistances, - structure.resistances // - ); + // // + // // RESISTANCES ... + // CheckZones(forBar, resistances); + // UpdateToTime(resistances, forBar.time); + // Copy( + // resistances, + // structure.resistances // + // ); - // - // Cleanup Resources ... - iBox.Clean(); + // // + // // Cleanup Resources ... + // iBox.Clean(); } // diff --git a/XFIMAEA/Libraries/x-saherelm.xfima.lib.mq5 b/XFIMAEA/Libraries/x-saherelm.xfima.lib.mq5 index 78665e18..1a953b24 100644 --- a/XFIMAEA/Libraries/x-saherelm.xfima.lib.mq5 +++ b/XFIMAEA/Libraries/x-saherelm.xfima.lib.mq5 @@ -37,82 +37,6 @@ struct XFIMAPatternDetectorConfig // // Props ... - // - bool detectSwingTrend; - - // - bool detectStarPattern; - bool detectFlagPattern; - bool detectRisingPattern; - bool detectPiercingPattern; - bool detectSignalKeyBarPattern; - - // - bool detectPinned; - bool detectMomentum; - bool detectEngulfed; - bool detectTrueGaped; - - // - bool analyseFIMAPVPivots; - bool analyseFIMAZigZagPivots; - - // - bool detectMACrosses; - double validMACrossDiffMultiplier; - - // - bool detectHKSwitches; - bool detectSARSwitches; - - // - // Configs ... - - // - // Trending ... - int trendingNumberOfSwings; - int trendingSwingShoulders; - - // - // Support and Resistance ... - int zonesRequiredNumber; - int zonesValidationLength; - double zonesMinAlloweStrength; - int zonesBreakValidationLength; - double zonesBarShadowMultiplier; - int zonesMaxAllowedLoopbackLength; - - // - // TrueGap ... - double truwGapApprovedPointMultiplier; - - // - // Flag Pattern ... - int flagPatternMinimumPullbackBars; - - // - // Momentum Bar ... - int momentumBarRangeLength; - double momentumBarApprovedMultiplier; - - // - // Pinned Bar ... - double pinnedBaarShadowApprovedMultiplier; - double pinnedBarMinimumPinBarRangeMultiplier; - bool pinnedBarForceDirection; - - // - // SignalKey Bar ... - double signalKeyBarShadowApprovedMultiplier; - double signalKeyBarMinimumPinBarRangeMultiplier; - bool signalKeyBarForceDirection; - - // - // Analyser ... - int pvPivotsValidationLength; - int numberOfRequiredPivotsForAnalysis; - int maxAllowedLoopbackLengthForAnalysis; - // // Constructor ... XFIMAPatternDetectorConfig() @@ -128,54 +52,6 @@ struct XFIMAPatternDetectorConfig */ void Clean() { - // - detectPinned = false; - detectMomentum = false; - detectEngulfed = false; - detectTrueGaped = false; - detectSwingTrend = false; - detectStarPattern = false; - detectFlagPattern = false; - detectRisingPattern = false; - analyseFIMAPVPivots = false; - detectPiercingPattern = false; - analyseFIMAZigZagPivots = false; - detectSignalKeyBarPattern = false; - - // - detectMACrosses = false; - validMACrossDiffMultiplier = 0; - - // - detectHKSwitches = false; - detectSARSwitches = false; - - // - zonesRequiredNumber = 0; - zonesValidationLength = 0; - zonesMinAlloweStrength = 0; - zonesBarShadowMultiplier = 0; - zonesBreakValidationLength = 0; - zonesMaxAllowedLoopbackLength = 0; - - // - trendingNumberOfSwings = 0; - trendingSwingShoulders = 0; - momentumBarRangeLength = 0; - pvPivotsValidationLength = 0; - pinnedBarForceDirection = false; - momentumBarApprovedMultiplier = 0; - signalKeyBarForceDirection = false; - truwGapApprovedPointMultiplier = 0; - flagPatternMinimumPullbackBars = 0; - numberOfRequiredPivotsForAnalysis = 0; - pinnedBaarShadowApprovedMultiplier = 0; - maxAllowedLoopbackLengthForAnalysis = 0; - signalKeyBarShadowApprovedMultiplier = 0; - pinnedBarMinimumPinBarRangeMultiplier = 0; - signalKeyBarMinimumPinBarRangeMultiplier = 0; - - // ZeroMemory(this); } @@ -184,78 +60,6 @@ struct XFIMAPatternDetectorConfig */ void Default() { - // - // Patterns ... - detectStarPattern = false; - detectFlagPattern = false; - detectRisingPattern = false; - detectPiercingPattern = false; - detectSignalKeyBarPattern = false; - - // - // Bars ... - detectPinned = false; - detectMomentum = false; - detectEngulfed = false; - detectTrueGaped = false; - - // - // Analysers ... - analyseFIMAPVPivots = false; - analyseFIMAZigZagPivots = false; - - // - detectMACrosses = true; - validMACrossDiffMultiplier = 1; - - // - detectHKSwitches = true; - detectSARSwitches = true; - - // - // Trending ... - trendingNumberOfSwings = 3; - trendingSwingShoulders = 11; - - // - // Support and Resistance ... - zonesRequiredNumber = 25; - zonesValidationLength = 21; - zonesMinAlloweStrength = 2; - zonesBarShadowMultiplier = 4; - zonesBreakValidationLength = 3; - zonesMaxAllowedLoopbackLength = 200; - - // - // TrueGap ... - truwGapApprovedPointMultiplier = 1; - - // - // Flag Pattern ... - flagPatternMinimumPullbackBars = 3; - - // - // Momentum Bar ... - momentumBarRangeLength = 3; - momentumBarApprovedMultiplier = 2; - - // - // Pinned Bar ... - pinnedBaarShadowApprovedMultiplier = 3; - pinnedBarMinimumPinBarRangeMultiplier = 4; - pinnedBarForceDirection = false; - - // - // SignalKey Bar ... - signalKeyBarShadowApprovedMultiplier = 3; - signalKeyBarMinimumPinBarRangeMultiplier = 4; - signalKeyBarForceDirection = false; - - // - // Length ... - pvPivotsValidationLength = 10; - numberOfRequiredPivotsForAnalysis = 50; - maxAllowedLoopbackLengthForAnalysis = 1500; } /** @@ -263,30 +67,6 @@ struct XFIMAPatternDetectorConfig */ void FullDetect() { - // - // Patterns ... - detectStarPattern = true; - detectFlagPattern = true; - detectRisingPattern = true; - detectPiercingPattern = true; - detectSignalKeyBarPattern = true; - - // - // Bars ... - detectPinned = true; - detectMomentum = true; - detectEngulfed = true; - detectTrueGaped = true; - - // - // Analysers ... - analyseFIMAPVPivots = true; - analyseFIMAZigZagPivots = true; - - // - detectMACrosses = true; - detectHKSwitches = true; - detectSARSwitches = true; } /** @@ -294,30 +74,6 @@ struct XFIMAPatternDetectorConfig */ void OffDetectors() { - // - // Patterns ... - detectStarPattern = false; - detectFlagPattern = false; - detectRisingPattern = false; - detectPiercingPattern = false; - detectSignalKeyBarPattern = false; - - // - // Bars ... - detectPinned = false; - detectMomentum = false; - detectEngulfed = false; - detectTrueGaped = false; - - // - // Analysers ... - analyseFIMAPVPivots = false; - analyseFIMAZigZagPivots = false; - - // - detectMACrosses = false; - detectHKSwitches = false; - detectSARSwitches = false; } // @@ -332,62 +88,6 @@ struct XFIMAMarketStructure // XOHCL bar; - // - XBoxZone obs[]; - XBoxZone fvgs[]; - XBoxZone supports[]; - XBoxZone resistances[]; - - // - XPivot pinBars[]; - XPivot engulfBars[]; - XPivot trueGapBars[]; - XPivot momentumBars[]; - - // - XBoxZone flagPatterns[]; - XBoxZone starPatterns[]; - XBoxZone risingPatterns[]; - XBoxZone piercingPatterns[]; - XBoxZone signalKeyBarPatterns[]; - - // - // Analysis ... - XPivotAnalysis pvAnalysis; - XPivotAnalysis zigzagAnalysis; - - // - ENUM_X_DIRECTION pinnedDir; - ENUM_X_DIRECTION momentumDir; - ENUM_X_DIRECTION engulfedDir; - ENUM_X_DIRECTION trueGapedDir; - - // - XOHCL flagSwing; - ENUM_X_DIRECTION flagPatternDir; - - // - XOHCL trendSwings[]; - ENUM_X_DIRECTION trendDir; - - // - ENUM_X_DIRECTION starPatternDir; - ENUM_X_DIRECTION risingPatternDir; - ENUM_X_DIRECTION piercingPatternDir; - ENUM_X_DIRECTION signalKeyBarPatternDir; - - // - ENUM_X_DIRECTION maCrossDir; - XPivot maCrosses[]; - - // - ENUM_X_DIRECTION hkSwitchDir; - XPivot hkSwitches[]; - - // - ENUM_X_DIRECTION sarSwitchDir; - XPivot sarSwitches[]; - // // Constructor ... XFIMAMarketStructure() @@ -403,55 +103,6 @@ struct XFIMAMarketStructure */ void Clean() { - // - bar.Clean(); - flagSwing.Clean(); - - // - pvAnalysis.Clean(); - zigzagAnalysis.Clean(); - - // - trendDir = X_DIRECTION_NONE; - pinnedDir = X_DIRECTION_NONE; - momentumDir = X_DIRECTION_NONE; - engulfedDir = X_DIRECTION_NONE; - trueGapedDir = X_DIRECTION_NONE; - flagPatternDir = X_DIRECTION_NONE; - starPatternDir = X_DIRECTION_NONE; - risingPatternDir = X_DIRECTION_NONE; - piercingPatternDir = X_DIRECTION_NONE; - signalKeyBarPatternDir = X_DIRECTION_NONE; - - // - maCrossDir = X_DIRECTION_NONE; - SpecifiedClean(maCrosses); - - // - hkSwitchDir = X_DIRECTION_NONE; - SpecifiedClean(hkSwitches); - - // - sarSwitchDir = X_DIRECTION_NONE; - SpecifiedClean(sarSwitches); - - // - SpecifiedClean(obs); - SpecifiedClean(fvgs); - SpecifiedClean(pinBars); - SpecifiedClean(supports); - SpecifiedClean(engulfBars); - SpecifiedClean(resistances); - SpecifiedClean(trueGapBars); - SpecifiedClean(momentumBars); - SpecifiedClean(flagPatterns); - SpecifiedClean(starPatterns); - SpecifiedClean(risingPatterns); - SpecifiedClean(piercingPatterns); - SpecifiedClean(signalKeyBarPatterns); - - // - SpecifiedClean(trendSwings); // ZeroMemory(this); @@ -471,66 +122,6 @@ struct XFIMAMarketStructureDrawerConfig // // Props ... - // - bool drawOB; // Current Order Block ... - bool drawFVG; // Current Fair Value Gap ... - - // - bool drawSupport; // Detected Supports ... - bool drawResistance; // Detected Resistances ... - - // - bool drawSwingTrend; // Swing Trend ... - bool swingTrendRayLeft; // Ray Left Swing Trend ... - bool swingTrendRayRight; // Ray Right Swing Trend ... - - // - // Draw Current Detected Patterns ... - - // - bool drawPinned; - bool drawMomentum; - bool drawEngulfed; - bool drawTrueGaped; - - // - bool drawStarPattern; - bool drawFlagPattern; - bool drawRisingPattern; - bool drawPiercingPattern; - bool drawSignalKeyBarPattern; - - // - // Draw Recently Zones ... - bool drawRecentPatterns; - bool drawFakeBreakedZone; - bool drawRecentlyTestedZones; - bool drawRecentlyBreakedZones; - - // - // Draw Analysis Pivots ... - - // - // XPV ... - bool drawFIMAPVPivotsAnalysis; - bool drawFIMAPVPivotsAnalysisZones; - bool drawFIMAPVPivotsAnalysisTrends; - bool drawFIMAPVPivotsAnalysisPivots; - - // - // XSAR ... - bool drawFIMASARPivotsAnalysis; - bool drawFIMASARPivotsAnalysisZones; - bool drawFIMASARPivotsAnalysisTrends; - bool drawFIMASARPivotsAnalysisPivots; - - // - // XZIGZAG ... - bool drawFIMAZigZagPivotsAnalysis; - bool drawFIMAZigZagPivotsAnalysisZones; - bool drawFIMAZigZagPivotsAnalysisTrends; - bool drawFIMAZigZagPivotsAnalysisPivots; - // // Constructor ... XFIMAMarketStructureDrawerConfig() @@ -546,47 +137,6 @@ struct XFIMAMarketStructureDrawerConfig */ void Clean() { - // - drawOB = false; - drawFVG = false; - drawPinned = false; - drawMomentum = false; - drawSupport = false; - drawEngulfed = false; - drawTrueGaped = false; - drawResistance = false; - drawSwingTrend = false; - drawStarPattern = false; - drawFlagPattern = false; - swingTrendRayLeft = false; - drawRisingPattern = false; - swingTrendRayRight = false; - drawPiercingPattern = false; - drawSignalKeyBarPattern = false; - - // - drawRecentPatterns = false; - drawFakeBreakedZone = false; - drawRecentlyTestedZones = false; - drawRecentlyBreakedZones = false; - - // - drawFIMAPVPivotsAnalysis = false; - drawFIMAPVPivotsAnalysisZones = false; - drawFIMAPVPivotsAnalysisTrends = false; - drawFIMAPVPivotsAnalysisPivots = false; - - // - drawFIMASARPivotsAnalysis = false; - drawFIMASARPivotsAnalysisZones = false; - drawFIMASARPivotsAnalysisTrends = false; - drawFIMASARPivotsAnalysisPivots = false; - - // - drawFIMAZigZagPivotsAnalysis = false; - drawFIMAZigZagPivotsAnalysisZones = false; - drawFIMAZigZagPivotsAnalysisTrends = false; - drawFIMAZigZagPivotsAnalysisPivots = false; // ZeroMemory(this); @@ -597,46 +147,6 @@ struct XFIMAMarketStructureDrawerConfig */ void Default() { - drawOB = true; - drawFVG = true; - drawPinned = true; - drawMomentum = true; - drawSupport = true; - drawEngulfed = true; - drawTrueGaped = true; - drawResistance = true; - drawSwingTrend = true; - drawStarPattern = true; - drawFlagPattern = true; - drawRisingPattern = true; - drawPiercingPattern = true; - swingTrendRayLeft = false; - swingTrendRayRight = true; - drawSignalKeyBarPattern = true; - - // - drawRecentPatterns = true; - drawFakeBreakedZone = true; - drawRecentlyTestedZones = true; - drawRecentlyBreakedZones = true; - - // - drawFIMAPVPivotsAnalysis = true; - drawFIMAPVPivotsAnalysisZones = true; - drawFIMAPVPivotsAnalysisTrends = true; - drawFIMAPVPivotsAnalysisPivots = true; - - // - drawFIMASARPivotsAnalysis = true; - drawFIMASARPivotsAnalysisZones = true; - drawFIMASARPivotsAnalysisTrends = true; - drawFIMASARPivotsAnalysisPivots = true; - - // - drawFIMAZigZagPivotsAnalysis = true; - drawFIMAZigZagPivotsAnalysisZones = true; - drawFIMAZigZagPivotsAnalysisTrends = true; - drawFIMAZigZagPivotsAnalysisPivots = true; } /** @@ -644,50 +154,6 @@ struct XFIMAMarketStructureDrawerConfig */ void FullDraw() { - // - Default(); - - // - drawOB = true; - drawFVG = true; - drawPinned = true; - drawMomentum = true; - drawSupport = true; - drawEngulfed = true; - drawTrueGaped = true; - drawResistance = true; - drawSwingTrend = true; - drawStarPattern = true; - drawFlagPattern = true; - drawRisingPattern = true; - swingTrendRayLeft = true; - swingTrendRayRight = true; - drawPiercingPattern = true; - drawSignalKeyBarPattern = true; - - // - drawRecentPatterns = true; - drawFakeBreakedZone = true; - drawRecentlyTestedZones = true; - drawRecentlyBreakedZones = true; - - // - drawFIMAPVPivotsAnalysis = true; - drawFIMAPVPivotsAnalysisZones = true; - drawFIMAPVPivotsAnalysisTrends = true; - drawFIMAPVPivotsAnalysisPivots = true; - - // - drawFIMASARPivotsAnalysis = true; - drawFIMASARPivotsAnalysisZones = true; - drawFIMASARPivotsAnalysisTrends = true; - drawFIMASARPivotsAnalysisPivots = true; - - // - drawFIMAZigZagPivotsAnalysis = true; - drawFIMAZigZagPivotsAnalysisZones = true; - drawFIMAZigZagPivotsAnalysisTrends = true; - drawFIMAZigZagPivotsAnalysisPivots = true; } //