From 050b400412a6fedeb497eccdf7518f11485e27fd Mon Sep 17 00:00:00 2001 From: Hadi Khazaee Asl Date: Tue, 2 Jul 2024 16:42:17 +0330 Subject: [PATCH] last works on xchma ... --- Classes/x-saherelm.x121.setup.class.mq5 | 130 +- Helpers/x-saherelm.xchma.helper.mq5 | 4075 +++++++++++++++++++++++ Indicators/x-saherelm.xchma.mq5 | 1086 ++++++ 3 files changed, 5255 insertions(+), 36 deletions(-) create mode 100644 Helpers/x-saherelm.xchma.helper.mq5 create mode 100644 Indicators/x-saherelm.xchma.mq5 diff --git a/Classes/x-saherelm.x121.setup.class.mq5 b/Classes/x-saherelm.x121.setup.class.mq5 index 39f0bdea..c71c15f3 100644 --- a/Classes/x-saherelm.x121.setup.class.mq5 +++ b/Classes/x-saherelm.x121.setup.class.mq5 @@ -41,6 +41,7 @@ #include "../Helpers/x-saherelm.xosc.helper.mq5" #include "../Helpers/x-saherelm.xvlm.helper.mq5" #include "../Helpers/x-saherelm.xhtd.helper.mq5" +#include "../Helpers/x-saherelm.xchma.helper.mq5" #include "../Helpers/x-saherelm.xatsl.helper.mq5" #include "../Helpers/x-saherelm.xdmnt.helper.mq5" #include "../Helpers/x-saherelm.xasct.helper.mq5" @@ -244,6 +245,7 @@ struct X121SetupInputs XOSCInputs oscInputs; // XOSC Inputs XVLMInputs vlmInputs; // XVLM Inputs XSLNInputs slnInputs; // XSLN Inputs + XCHMAInputs chmaInputs; // XCHMA Inputs XATSLInputs atslInputs; // XATSL Inputs XDMNTInputs dmntInputs; // XDMNT Inputs XASCTInputs asctInputs; // XASCT Inputs @@ -286,6 +288,7 @@ struct X121SetupInputs XOSCInputs &_oscInputs, // XOSC Inputs XVLMInputs &_vlmInputs, // XVLM Inputs XSLNInputs &_slnInputs, // XSLN Inputs + XCHMAInputs &_chmaInputs, // XCHMA Inputs XATSLInputs &_atslInputs, // XATSL Inputs XDMNTInputs &_dmntInputs, // XDMNT Inputs XASCTInputs &_asctInputs, // XASCT Inputs @@ -311,6 +314,7 @@ struct X121SetupInputs this.mrbInputs = _mrbInputs; this.oscInputs = _oscInputs; this.vlmInputs = _vlmInputs; + this.chmaInputs = _chmaInputs; this.atslInputs = _atslInputs; this.dmntInputs = _dmntInputs; this.asctInputs = _asctInputs; @@ -350,10 +354,11 @@ struct X121SetupInputs vlmInputs.Clean(); slnInputs.Clean(); htdInputs.Clean(); + chmaInputs.Clean(); + atslInputs.Clean(); asctInputs.Clean(); sslcInputs.Clean(); hullInputs.Clean(); - atslInputs.Clean(); dmntInputs.Clean(); adxtdInputs.Clean(); } @@ -376,10 +381,11 @@ struct X121SetupInputs vlmInputs.Default(); slnInputs.Default(); htdInputs.Default(); + chmaInputs.Default(); + atslInputs.Default(); asctInputs.Default(); sslcInputs.Default(); hullInputs.Default(); - atslInputs.Default(); dmntInputs.Default(); adxtdInputs.Default(); } @@ -522,6 +528,13 @@ struct X121SetupInputs return result; } + // + result = chmaInputs.IsValid(); + if (!result) + { + return result; + } + // result = atslInputs.IsValid(); if (!result) @@ -565,6 +578,7 @@ struct X121SetupConditions XVLMConditions vlmConditions; XHTDConditions htdConditions; XSLNConditions slnConditions; + XCHMAConditions chmaConditions; XATSLConditions atslConditions; XASCTConditions asctConditions; XSSLCConditions sslcConditions; @@ -609,6 +623,7 @@ struct X121SetupConditions vlmConditions.Clean(); slnConditions.Clean(); htdConditions.Clean(); + chmaConditions.Clean(); atslConditions.Clean(); asctConditions.Clean(); sslcConditions.Clean(); @@ -767,6 +782,14 @@ struct X121SetupConditions bullishScore += tempBullishScore; bearishScore += tempBearishScore; + // + chmaConditions.GenerateScore( + tempBullishScore, + tempBearishScore // + ); + bullishScore += tempBullishScore; + bearishScore += tempBearishScore; + // dmntConditions.GenerateScore( tempBullishScore, @@ -829,7 +852,8 @@ struct X121SetupConditions string vlmSummary = vlmConditions.GenerateSummary(false, true, false, ignoreFalseConditions); string slnSummary = slnConditions.GenerateSummary(false, true, false, ignoreFalseConditions); string htdSummary = htdConditions.GenerateSummary(false, true, false, ignoreFalseConditions); - string atsSummary = atslConditions.GenerateSummary(false, true, false, ignoreFalseConditions); + string chmaSummary = chmaConditions.GenerateSummary(false, true, false, ignoreFalseConditions); + string atslSummary = atslConditions.GenerateSummary(false, true, false, ignoreFalseConditions); string asctSummary = asctConditions.GenerateSummary(false, true, false, ignoreFalseConditions); string sslcSummary = sslcConditions.GenerateSummary(false, true, false, ignoreFalseConditions); string hullSummary = hullConditions.GenerateSummary(false, true, false, ignoreFalseConditions); @@ -855,8 +879,9 @@ struct X121SetupConditions hullSummary + separator + adxtdSummary + separator + htdSummary + separator + - atsSummary + separator + + atslSummary + separator + dmntSummary + separator + + chmaSummary + separator + "" // ; @@ -3583,15 +3608,6 @@ struct X121SignalGenerator conditions.pvConditions.isCloseUnderFib4 && conditions.pvConditions.isCloseUnderFib5 // - ) // - && - // - ( - // - // XVLM ... - conditions.vlmConditions.isVolumeBearish && - conditions.vlmConditions.isVolumeOverLast - // ) // && @@ -3600,27 +3616,54 @@ struct X121SignalGenerator // ( // - conditions.pvConditions.isSCBearish && - conditions.pvConditions.isSCHHBearish && - conditions.pvConditions.isSCLLBearish && - conditions.pvConditions.isMCBearish && - conditions.pvConditions.isMCHHBearish && - conditions.pvConditions.isMCLLBearish && - conditions.pvConditions.isLCBearish && - conditions.pvConditions.isLCHHBearish && - conditions.pvConditions.isLCLLBearish && - conditions.pvConditions.isHCBearish && - conditions.pvConditions.isHCHHBearish && - conditions.pvConditions.isHCLLBearish && + ( + // + // XVLM ... + conditions.vlmConditions.isVolumeBearish && + conditions.vlmConditions.isVolumeOverLast + // + ) // - // XICH ... - conditions.ichConditions.isClosedUnderKijunSen && - conditions.ichConditions.isTenkanSenUnderKijunSen && - conditions.ichConditions.isSenkouSpanAUnderB && - conditions.ichConditions.isSenkouSpanAUnderLast && - conditions.ichConditions.isFutureSenkouSpanAUnderB && - conditions.ichConditions.isFutureSenkouSpanAUnderLast && - conditions.ichConditions.isSenkouSpanACrossedUnderLast + && + // + ( + // + ( + // + conditions.pvConditions.isSCBearish && + conditions.pvConditions.isSCHHBearish && + conditions.pvConditions.isSCLLBearish && + conditions.pvConditions.isMCBearish && + conditions.pvConditions.isMCHHBearish && + conditions.pvConditions.isMCLLBearish && + conditions.pvConditions.isLCBearish && + conditions.pvConditions.isLCHHBearish && + conditions.pvConditions.isLCLLBearish && + conditions.pvConditions.isHCBearish && + conditions.pvConditions.isHCHHBearish && + conditions.pvConditions.isHCLLBearish && + // + // XICH ... + conditions.ichConditions.isClosedUnderKijunSen && + conditions.ichConditions.isTenkanSenUnderKijunSen && + conditions.ichConditions.isSenkouSpanAUnderB && + conditions.ichConditions.isSenkouSpanAUnderLast && + conditions.ichConditions.isFutureSenkouSpanAUnderB && + conditions.ichConditions.isFutureSenkouSpanAUnderLast && + conditions.ichConditions.isSenkouSpanACrossedUnderLast + // + ) + // + || + // + ( + // + // XICH ... + conditions.ichConditions.isSenkouSpanACrossedUnderB + // + ) + // + ) // ) // @@ -3628,8 +3671,11 @@ struct X121SignalGenerator // ( // - // XICH ... - conditions.ichConditions.isSenkouSpanACrossedUnderB + // XRL ... + conditions.rlConditions.isFastBearish && + conditions.rlConditions.isSlowBearish && + conditions.rlConditions.isFastOverSlow && + conditions.rlConditions.isVerifierBearish // ) // @@ -4045,10 +4091,11 @@ public: XSCXVLMHelper *vlmHelper; XSCXSLNHelper *slnHelper; XSCXHTDHelper *hdtHelper; + XSCXCHMAHelper *chmaHelper; + XSCXATSLHelper *atslHelper; XSCXASCTHelper *asctHelper; XSCXSSLCHelper *sslcHelper; XSCXHULLHelper *hullHelper; - XSCXATSLHelper *atslHelper; XSCXDMNTHelper *dmntHelper; XSCXADXTDHelper *adxtdHelper; @@ -4436,6 +4483,17 @@ public: return result; } + // + result = chmaHelper.GetConditions( + conditions.chmaConditions, + barIndex, + loopback // + ); + if (!result) + { + return result; + } + // result = atslHelper.GetConditions( conditions.atslConditions, diff --git a/Helpers/x-saherelm.xchma.helper.mq5 b/Helpers/x-saherelm.xchma.helper.mq5 new file mode 100644 index 00000000..30fc2f18 --- /dev/null +++ b/Helpers/x-saherelm.xchma.helper.mq5 @@ -0,0 +1,4075 @@ +/////////////////////////////////////////////////////// +// +// SaherElm IT Center MQL5 Helper Class Library +// ---------------------------------------------- +// Name: XSCXCHMAHelper +// Description: provides all Indicator +// Helper requirements ... +// +// +// Maintainer: +// ------------ +// Hadi Khazaee Asl (hadi_khazaee_asl@yahoo.com) +// +////////////////////////////////////////////////////// +// +// Global Properties ... +#property library +#property copyright "Copyright 2023, SaherElm IT Center" +#property link "https://www.saherelm.ir" +#property version "1.00" +#property strict + +// +// Imports ... +#include "../Classes/x-saherelm.xhelper.class.mq5" + +// +// Definitions ... + +// +enum ENUM_XCHMA_BUFFERS +{ + // + // Main ... + XCHMA_FAST_LINE = 0, + XCHMA_SLOW_LINE = 1, + // + // Current ... + XCHMA_CFAST_LINE = 2, + XCHMA_CSLOW_LINE = 3, + // + // Short ... + XCHMA_SFAST_LINE = 4, + XCHMA_SSLOW_LINE = 5, + // + // Medium ... + XCHMA_MFAST_LINE = 6, + XCHMA_MSLOW_LINE = 7, + // + // Long ... + XCHMA_LFAST_LINE = 8, + XCHMA_LSLOW_LINE = 9, + // + // Hind ... + XCHMA_HFAST_LINE = 10, + XCHMA_HSLOW_LINE = 11, +}; + +// +// Input Models ... +struct XCHMAInputs +{ + // + // Props ... + + // + // Market ... + int fastLength; // Fast Length + int slowLength; // Slow Length + ENUM_MA_METHOD method; // Mode + ENUM_APPLIED_PRICE appliedTo; // Applied To + + // + // Cycles ... + + // + // Short ... + ENUM_X_PERIOD_METHOD scMethod; // How to Find Period + ENUM_TIMEFRAMES scPeriod; // Time Period + + // + // Medium ... + ENUM_X_PERIOD_METHOD mcMethod; // How to Find Period + ENUM_TIMEFRAMES mcPeriod; // Time Period + + // + // Long ... + ENUM_X_PERIOD_METHOD lcMethod; // How to Find Period + ENUM_TIMEFRAMES lcPeriod; // Time Period + + // + // Hind ... + ENUM_X_PERIOD_METHOD hcMethod; // How to Find Period + ENUM_TIMEFRAMES hcPeriod; // Time Period + + // + // Presentation ... + bool showFast; // Show Fast + bool showSlow; // Show Slow + bool showCCFast; // Show Current Cycle Fast + bool showCCSlow; // Show Current Cycle Slow + bool showSCFast; // Show Short Cycle Fast + bool showSCSlow; // Show Short Cycle Slow + bool showMCFast; // Show Medium Cycle Fast + bool showMCSlow; // Show Medium Cycle Slow + bool showLCFast; // Show Long Cycle Fast + bool showLCSlow; // Show Long Cycle Slow + bool showHCFast; // Show Hind Cycle Fast + bool showHCSlow; // Show Hind Cycle Slow + + // + // Constructor(s) ... + XCHMAInputs() + { + // + Clean(); + } + + // + // Tools ... + + // + // Clean ... + void Clean() + { + // + fastLength = 0; + slowLength = 0; + method = MODE_EMA; + appliedTo = PRICE_CLOSE; + + // + scMethod = X_PERIOD_AUTO; + scPeriod = NULL; + mcMethod = X_PERIOD_AUTO; + mcPeriod = NULL; + lcMethod = X_PERIOD_AUTO; + lcPeriod = NULL; + hcMethod = X_PERIOD_AUTO; + hcPeriod = NULL; + + // + showFast = false; + showSlow = false; + showCCFast = false; + showCCSlow = false; + showSCFast = false; + showSCSlow = false; + showMCFast = false; + showMCSlow = false; + showLCFast = false; + showLCSlow = false; + showHCFast = false; + showHCSlow = false; + } + + // + // Default ... + void Default() + { + // + fastLength = 9; + slowLength = 18; + method = MODE_EMA; + appliedTo = PRICE_CLOSE; + + // + scMethod = X_PERIOD_AUTO; + scPeriod = NULL; + mcMethod = X_PERIOD_AUTO; + mcPeriod = NULL; + lcMethod = X_PERIOD_AUTO; + lcPeriod = NULL; + hcMethod = X_PERIOD_AUTO; + hcPeriod = NULL; + + // + showFast = true; + showSlow = true; + showCCFast = true; + showCCSlow = true; + showSCFast = true; + showSCSlow = true; + showMCFast = true; + showMCSlow = true; + showLCFast = true; + showLCSlow = true; + showHCFast = true; + showHCSlow = true; + } + + // + // Validate ... + bool IsValid() + { + // + bool result = false; + + // + result = + // + fastLength > 2 && + slowLength > fastLength && + // + (IsValid(scMethod, scPeriod) && + IsValid(mcMethod, mcPeriod) && + IsValid(lcMethod, lcPeriod) && + IsValid(hcMethod, hcPeriod)) + // + ; + + // + return result; + } + + // + // Retrieve MAx Length ... + int Max() + { + // + int result = 0; + + // + result = + // + MathMax(fastLength, slowLength) + // + ; + + // + return result; + } +}; + +// +// Define Conditions ... +struct XCHMAConditions +{ + // + // Common ... + string symbol; + ENUM_TIMEFRAMES period; + datetime time; + + // + // Buffers ... + + // + double fast[]; + double slow[]; + + // + // Current ... + double cFast[]; + double cSlow[]; + + // + // Short ... + double sFast[]; + double sSlow[]; + + // + // Medium ... + double mFast[]; + double mSlow[]; + + // + // Long ... + double lFast[]; + double lSlow[]; + + // + // Hind ... + double hFast[]; + double hSlow[]; + + // + // Conditions ... + + // + // AVG ... + + // + bool isFastOverSlow; + bool isFastUnderSlow; + + // + bool isFastCrossedOverSlow; + bool isFastCrossedUnderSlow; + + // + bool isCLoseOverFast; + bool isCloseCrossedOverFast; + + // + bool isCloseUnderFast; + bool isCloseCrossedUnderFast; + + // + bool isCloseOverSlow; + bool isCloseCrossedOverSlow; + + // + bool isCloseUnderSlow; + bool isCloseCrossedUnderSlow; + + // + bool isRetestFastSlow; + + // + bool isFastOverMax; + bool isFastUnderMax; + + // + bool isFastOverMin; + bool isFastUnderMin; + + // + bool isFastCrossedOverMax; + bool isFastCrossedUnderMax; + + // + bool isFastCrossedOverMin; + bool isFastCrossedUnderMin; + + // + bool isSlowOverMax; + bool isSlowUnderMax; + + // + bool isSlowOverMin; + bool isSlowUnderMin; + + // + bool isSlowCrossedOverMax; + bool isSlowCrossedUnderMax; + + // + bool isSlowCrossedOverMin; + bool isSlowCrossedUnderMin; + + // + // Current ... + + // + bool isCFastOverSlow; + bool isCFastUnderSlow; + + // + bool isCFastCrossedOverSlow; + bool isCFastCrossedUnderSlow; + + // + bool isCLoseOverCFast; + bool isCloseCrossedOverCFast; + + // + bool isCloseUnderCFast; + bool isCloseCrossedUnderCFast; + + // + bool isCloseOverCSlow; + bool isCloseCrossedOverCSlow; + + // + bool isCloseUnderCSlow; + bool isCloseCrossedUnderCSlow; + + // + bool isRetestCFastSlow; + + // + bool isCFastOverMax; + bool isCFastUnderMax; + + // + bool isCFastOverMin; + bool isCFastUnderMin; + + // + bool isCFastCrossedOverMax; + bool isCFastCrossedUnderMax; + + // + bool isCFastCrossedOverMin; + bool isCFastCrossedUnderMin; + + // + bool isCSlowOverMax; + bool isCSlowUnderMax; + + // + bool isCSlowOverMin; + bool isCSlowUnderMin; + + // + bool isCSlowCrossedOverMax; + bool isCSlowCrossedUnderMax; + + // + bool isCSlowCrossedOverMin; + bool isCSlowCrossedUnderMin; + + // + // Short ... + + // + bool isSFastOverSlow; + bool isSFastUnderSlow; + + // + bool isSFastCrossedOverSlow; + bool isSFastCrossedUnderSlow; + + // + bool isCLoseOverSFast; + bool isCloseCrossedOverSFast; + + // + bool isCloseUnderSFast; + bool isCloseCrossedUnderSFast; + + // + bool isCloseOverSSlow; + bool isCloseCrossedOverSSlow; + + // + bool isCloseUnderSSlow; + bool isCloseCrossedUnderSSlow; + + // + bool isRetestSFastSlow; + + // + bool isSFastOverMax; + bool isSFastUnderMax; + + // + bool isSFastOverMin; + bool isSFastUnderMin; + + // + bool isSFastCrossedOverMax; + bool isSFastCrossedUnderMax; + + // + bool isSFastCrossedOverMin; + bool isSFastCrossedUnderMin; + + // + bool isSSlowOverMax; + bool isSSlowUnderMax; + + // + bool isSSlowOverMin; + bool isSSlowUnderMin; + + // + bool isSSlowCrossedOverMax; + bool isSSlowCrossedUnderMax; + + // + bool isSSlowCrossedOverMin; + bool isSSlowCrossedUnderMin; + + // + // Medium ... + + // + bool isMFastOverSlow; + bool isMFastUnderSlow; + + // + bool isMFastCrossedOverSlow; + bool isMFastCrossedUnderSlow; + + // + bool isCLoseOverMFast; + bool isCloseCrossedOverMFast; + + // + bool isCloseUnderMFast; + bool isCloseCrossedUnderMFast; + + // + bool isCloseOverMSlow; + bool isCloseCrossedOverMSlow; + + // + bool isCloseUnderMSlow; + bool isCloseCrossedUnderMSlow; + + // + bool isRetestMFastSlow; + + // + bool isMFastOverMax; + bool isMFastUnderMax; + + // + bool isMFastOverMin; + bool isMFastUnderMin; + + // + bool isMFastCrossedOverMax; + bool isMFastCrossedUnderMax; + + // + bool isMFastCrossedOverMin; + bool isMFastCrossedUnderMin; + + // + bool isMSlowOverMax; + bool isMSlowUnderMax; + + // + bool isMSlowOverMin; + bool isMSlowUnderMin; + + // + bool isMSlowCrossedOverMax; + bool isMSlowCrossedUnderMax; + + // + bool isMSlowCrossedOverMin; + bool isMSlowCrossedUnderMin; + + // + // Long ... + + // + bool isLFastOverSlow; + bool isLFastUnderSlow; + + // + bool isLFastCrossedOverSlow; + bool isLFastCrossedUnderSlow; + + // + bool isCLoseOverLFast; + bool isCloseCrossedOverLFast; + + // + bool isCloseUnderLFast; + bool isCloseCrossedUnderLFast; + + // + bool isCloseOverLSlow; + bool isCloseCrossedOverLSlow; + + // + bool isCloseUnderLSlow; + bool isCloseCrossedUnderLSlow; + + // + bool isRetestLFastSlow; + + // + bool isLFastOverMax; + bool isLFastUnderMax; + + // + bool isLFastOverMin; + bool isLFastUnderMin; + + // + bool isLFastCrossedOverMax; + bool isLFastCrossedUnderMax; + + // + bool isLFastCrossedOverMin; + bool isLFastCrossedUnderMin; + + // + bool isLSlowOverMax; + bool isLSlowUnderMax; + + // + bool isLSlowOverMin; + bool isLSlowUnderMin; + + // + bool isLSlowCrossedOverMax; + bool isLSlowCrossedUnderMax; + + // + bool isLSlowCrossedOverMin; + bool isLSlowCrossedUnderMin; + + // + // Hind ... + + // + bool isHFastOverSlow; + bool isHFastUnderSlow; + + // + bool isHFastCrossedOverSlow; + bool isHFastCrossedUnderSlow; + + // + bool isCLoseOverHFast; + bool isCloseCrossedOverHFast; + + // + bool isCloseUnderHFast; + bool isCloseCrossedUnderHFast; + + // + bool isCloseOverHSlow; + bool isCloseCrossedOverHSlow; + + // + bool isCloseUnderHSlow; + bool isCloseCrossedUnderHSlow; + + // + bool isRetestHFastSlow; + + // + bool isHFastOverMax; + bool isHFastUnderMax; + + // + bool isHFastOverMin; + bool isHFastUnderMin; + + // + bool isHFastCrossedOverMax; + bool isHFastCrossedUnderMax; + + // + bool isHFastCrossedOverMin; + bool isHFastCrossedUnderMin; + + // + bool isHSlowOverMax; + bool isHSlowUnderMax; + + // + bool isHSlowOverMin; + bool isHSlowUnderMin; + + // + bool isHSlowCrossedOverMax; + bool isHSlowCrossedUnderMax; + + // + bool isHSlowCrossedOverMin; + bool isHSlowCrossedUnderMin; + + // + void Clean() + { + // + Clean(fast); + Clean(slow); + Clean(cFast); + Clean(cSlow); + Clean(sFast); + Clean(sSlow); + Clean(mFast); + Clean(mSlow); + Clean(lFast); + Clean(lSlow); + Clean(hFast); + Clean(hSlow); + + // + ArraySetAsSeries(fast, true); + ArraySetAsSeries(slow, true); + ArraySetAsSeries(cFast, true); + ArraySetAsSeries(cSlow, true); + ArraySetAsSeries(sFast, true); + ArraySetAsSeries(sSlow, true); + ArraySetAsSeries(mFast, true); + ArraySetAsSeries(mSlow, true); + ArraySetAsSeries(lFast, true); + ArraySetAsSeries(lSlow, true); + ArraySetAsSeries(hFast, true); + ArraySetAsSeries(hSlow, true); + + // + // AVG ... + isFastOverSlow = false; + isFastUnderSlow = false; + isFastCrossedOverSlow = false; + isFastCrossedUnderSlow = false; + isCLoseOverFast = false; + isCloseCrossedOverFast = false; + isCloseUnderFast = false; + isCloseCrossedUnderFast = false; + isCloseOverSlow = false; + isCloseCrossedOverSlow = false; + isCloseUnderSlow = false; + isCloseCrossedUnderSlow = false; + isRetestFastSlow = false; + isFastOverMax = false; + isFastUnderMax = false; + isFastOverMin = false; + isFastUnderMin = false; + isFastCrossedOverMax = false; + isFastCrossedUnderMax = false; + isFastCrossedOverMin = false; + isFastCrossedUnderMin = false; + isSlowOverMax = false; + isSlowUnderMax = false; + isSlowOverMin = false; + isSlowUnderMin = false; + isSlowCrossedOverMax = false; + isSlowCrossedUnderMax = false; + isSlowCrossedOverMin = false; + isSlowCrossedUnderMin = false; + + // + // Current ... + isCFastOverSlow = false; + isCFastUnderSlow = false; + isCFastCrossedOverSlow = false; + isCFastCrossedUnderSlow = false; + isCLoseOverCFast = false; + isCloseCrossedOverCFast = false; + isCloseUnderCFast = false; + isCloseCrossedUnderCFast = false; + isCloseOverCSlow = false; + isCloseCrossedOverCSlow = false; + isCloseUnderCSlow = false; + isCloseCrossedUnderCSlow = false; + isRetestCFastSlow = false; + isCFastOverMax = false; + isCFastUnderMax = false; + isCFastOverMin = false; + isCFastUnderMin = false; + isCFastCrossedOverMax = false; + isCFastCrossedUnderMax = false; + isCFastCrossedOverMin = false; + isCFastCrossedUnderMin = false; + isCSlowOverMax = false; + isCSlowUnderMax = false; + isCSlowOverMin = false; + isCSlowUnderMin = false; + isCSlowCrossedOverMax = false; + isCSlowCrossedUnderMax = false; + isCSlowCrossedOverMin = false; + isCSlowCrossedUnderMin = false; + + // + // Short ... + isSFastOverSlow = false; + isSFastUnderSlow = false; + isSFastCrossedOverSlow = false; + isSFastCrossedUnderSlow = false; + isCLoseOverSFast = false; + isCloseCrossedOverSFast = false; + isCloseUnderSFast = false; + isCloseCrossedUnderSFast = false; + isCloseOverSSlow = false; + isCloseCrossedOverSSlow = false; + isCloseUnderSSlow = false; + isCloseCrossedUnderSSlow = false; + isRetestSFastSlow = false; + isSFastOverMax = false; + isSFastUnderMax = false; + isSFastOverMin = false; + isSFastUnderMin = false; + isSFastCrossedOverMax = false; + isSFastCrossedUnderMax = false; + isSFastCrossedOverMin = false; + isSFastCrossedUnderMin = false; + isSSlowOverMax = false; + isSSlowUnderMax = false; + isSSlowOverMin = false; + isSSlowUnderMin = false; + isSSlowCrossedOverMax = false; + isSSlowCrossedUnderMax = false; + isSSlowCrossedOverMin = false; + isSSlowCrossedUnderMin = false; + + // + // Medium ... + isMFastOverSlow = false; + isMFastUnderSlow = false; + isMFastCrossedOverSlow = false; + isMFastCrossedUnderSlow = false; + isCLoseOverMFast = false; + isCloseCrossedOverMFast = false; + isCloseUnderMFast = false; + isCloseCrossedUnderMFast = false; + isCloseOverMSlow = false; + isCloseCrossedOverMSlow = false; + isCloseUnderMSlow = false; + isCloseCrossedUnderMSlow = false; + isRetestMFastSlow = false; + isMFastOverMax = false; + isMFastUnderMax = false; + isMFastOverMin = false; + isMFastUnderMin = false; + isMFastCrossedOverMax = false; + isMFastCrossedUnderMax = false; + isMFastCrossedOverMin = false; + isMFastCrossedUnderMin = false; + isMSlowOverMax = false; + isMSlowUnderMax = false; + isMSlowOverMin = false; + isMSlowUnderMin = false; + isMSlowCrossedOverMax = false; + isMSlowCrossedUnderMax = false; + isMSlowCrossedOverMin = false; + isMSlowCrossedUnderMin = false; + + // + // Long ... + isLFastOverSlow = false; + isLFastUnderSlow = false; + isLFastCrossedOverSlow = false; + isLFastCrossedUnderSlow = false; + isCLoseOverLFast = false; + isCloseCrossedOverLFast = false; + isCloseUnderLFast = false; + isCloseCrossedUnderLFast = false; + isCloseOverLSlow = false; + isCloseCrossedOverLSlow = false; + isCloseUnderLSlow = false; + isCloseCrossedUnderLSlow = false; + isRetestLFastSlow = false; + isLFastOverMax = false; + isLFastUnderMax = false; + isLFastOverMin = false; + isLFastUnderMin = false; + isLFastCrossedOverMax = false; + isLFastCrossedUnderMax = false; + isLFastCrossedOverMin = false; + isLFastCrossedUnderMin = false; + isLSlowOverMax = false; + isLSlowUnderMax = false; + isLSlowOverMin = false; + isLSlowUnderMin = false; + isLSlowCrossedOverMax = false; + isLSlowCrossedUnderMax = false; + isLSlowCrossedOverMin = false; + isLSlowCrossedUnderMin = false; + + // + // Hind ... + isHFastOverSlow = false; + isHFastUnderSlow = false; + isHFastCrossedOverSlow = false; + isHFastCrossedUnderSlow = false; + isCLoseOverHFast = false; + isCloseCrossedOverHFast = false; + isCloseUnderHFast = false; + isCloseCrossedUnderHFast = false; + isCloseOverHSlow = false; + isCloseCrossedOverHSlow = false; + isCloseUnderHSlow = false; + isCloseCrossedUnderHSlow = false; + isRetestHFastSlow = false; + isHFastOverMax = false; + isHFastUnderMax = false; + isHFastOverMin = false; + isHFastUnderMin = false; + isHFastCrossedOverMax = false; + isHFastCrossedUnderMax = false; + isHFastCrossedOverMin = false; + isHFastCrossedUnderMin = false; + isHSlowOverMax = false; + isHSlowUnderMax = false; + isHSlowOverMin = false; + isHSlowUnderMin = false; + isHSlowCrossedOverMax = false; + isHSlowCrossedUnderMax = false; + isHSlowCrossedOverMin = false; + isHSlowCrossedUnderMin = false; + } + + // + void GenerateScore( + double &bullishScore, + double &bearishScore // + ) + { + // + bullishScore = 0; + bearishScore = 0; + + // + // Since We have to Use this + // Only for Filtering Signals ... + // We Can Ignore Scoring ... + // or Complete this later ... + + // + // AVG ... + if (isFastOverSlow) + { + } + if (isFastUnderSlow) + { + } + if (isFastCrossedOverSlow) + { + } + if (isFastCrossedUnderSlow) + { + } + if (isCLoseOverFast) + { + } + if (isCloseCrossedOverFast) + { + } + if (isCloseUnderFast) + { + } + if (isCloseCrossedUnderFast) + { + } + if (isCloseOverSlow) + { + } + if (isCloseCrossedOverSlow) + { + } + if (isCloseUnderSlow) + { + } + if (isCloseCrossedUnderSlow) + { + } + if (isRetestFastSlow) + { + } + if (isFastOverMax) + { + } + if (isFastUnderMax) + { + } + if (isFastOverMin) + { + } + if (isFastUnderMin) + { + } + if (isFastCrossedOverMax) + { + } + if (isFastCrossedUnderMax) + { + } + if (isFastCrossedOverMin) + { + } + if (isFastCrossedUnderMin) + { + } + if (isSlowOverMax) + { + } + if (isSlowUnderMax) + { + } + if (isSlowOverMin) + { + } + if (isSlowUnderMin) + { + } + if (isSlowCrossedOverMax) + { + } + if (isSlowCrossedUnderMax) + { + } + if (isSlowCrossedOverMin) + { + } + if (isSlowCrossedUnderMin) + { + } + + // + // Current ... + if (isCFastOverSlow) + { + } + if (isCFastUnderSlow) + { + } + if (isCFastCrossedOverSlow) + { + } + if (isCFastCrossedUnderSlow) + { + } + if (isCLoseOverCFast) + { + } + if (isCloseCrossedOverCFast) + { + } + if (isCloseUnderCFast) + { + } + if (isCloseCrossedUnderCFast) + { + } + if (isCloseOverCSlow) + { + } + if (isCloseCrossedOverCSlow) + { + } + if (isCloseUnderCSlow) + { + } + if (isCloseCrossedUnderCSlow) + { + } + if (isRetestCFastSlow) + { + } + if (isCFastOverMax) + { + } + if (isCFastUnderMax) + { + } + if (isCFastOverMin) + { + } + if (isCFastUnderMin) + { + } + if (isCFastCrossedOverMax) + { + } + if (isCFastCrossedUnderMax) + { + } + if (isCFastCrossedOverMin) + { + } + if (isCFastCrossedUnderMin) + { + } + if (isCSlowOverMax) + { + } + if (isCSlowUnderMax) + { + } + if (isCSlowOverMin) + { + } + if (isCSlowUnderMin) + { + } + if (isCSlowCrossedOverMax) + { + } + if (isCSlowCrossedUnderMax) + { + } + if (isCSlowCrossedOverMin) + { + } + if (isCSlowCrossedUnderMin) + { + } + + // + // Short ... + if (isSFastOverSlow) + { + } + if (isSFastUnderSlow) + { + } + if (isSFastCrossedOverSlow) + { + } + if (isSFastCrossedUnderSlow) + { + } + if (isCLoseOverSFast) + { + } + if (isCloseCrossedOverSFast) + { + } + if (isCloseUnderSFast) + { + } + if (isCloseCrossedUnderSFast) + { + } + if (isCloseOverSSlow) + { + } + if (isCloseCrossedOverSSlow) + { + } + if (isCloseUnderSSlow) + { + } + if (isCloseCrossedUnderSSlow) + { + } + if (isRetestSFastSlow) + { + } + if (isSFastOverMax) + { + } + if (isSFastUnderMax) + { + } + if (isSFastOverMin) + { + } + if (isSFastUnderMin) + { + } + if (isSFastCrossedOverMax) + { + } + if (isSFastCrossedUnderMax) + { + } + if (isSFastCrossedOverMin) + { + } + if (isSFastCrossedUnderMin) + { + } + if (isSSlowOverMax) + { + } + if (isSSlowUnderMax) + { + } + if (isSSlowOverMin) + { + } + if (isSSlowUnderMin) + { + } + if (isSSlowCrossedOverMax) + { + } + if (isSSlowCrossedUnderMax) + { + } + if (isSSlowCrossedOverMin) + { + } + if (isSSlowCrossedUnderMin) + { + } + + // + // Medium ... + if (isMFastOverSlow) + { + } + if (isMFastUnderSlow) + { + } + if (isMFastCrossedOverSlow) + { + } + if (isMFastCrossedUnderSlow) + { + } + if (isCLoseOverMFast) + { + } + if (isCloseCrossedOverMFast) + { + } + if (isCloseUnderMFast) + { + } + if (isCloseCrossedUnderMFast) + { + } + if (isCloseOverMSlow) + { + } + if (isCloseCrossedOverMSlow) + { + } + if (isCloseUnderMSlow) + { + } + if (isCloseCrossedUnderMSlow) + { + } + if (isRetestMFastSlow) + { + } + if (isMFastOverMax) + { + } + if (isMFastUnderMax) + { + } + if (isMFastOverMin) + { + } + if (isMFastUnderMin) + { + } + if (isMFastCrossedOverMax) + { + } + if (isMFastCrossedUnderMax) + { + } + if (isMFastCrossedOverMin) + { + } + if (isMFastCrossedUnderMin) + { + } + if (isMSlowOverMax) + { + } + if (isMSlowUnderMax) + { + } + if (isMSlowOverMin) + { + } + if (isMSlowUnderMin) + { + } + if (isMSlowCrossedOverMax) + { + } + if (isMSlowCrossedUnderMax) + { + } + if (isMSlowCrossedOverMin) + { + } + if (isMSlowCrossedUnderMin) + { + } + + // + // Long ... + if (isLFastOverSlow) + { + } + if (isLFastUnderSlow) + { + } + if (isLFastCrossedOverSlow) + { + } + if (isLFastCrossedUnderSlow) + { + } + if (isCLoseOverLFast) + { + } + if (isCloseCrossedOverLFast) + { + } + if (isCloseUnderLFast) + { + } + if (isCloseCrossedUnderLFast) + { + } + if (isCloseOverLSlow) + { + } + if (isCloseCrossedOverLSlow) + { + } + if (isCloseUnderLSlow) + { + } + if (isCloseCrossedUnderLSlow) + { + } + if (isRetestLFastSlow) + { + } + if (isLFastOverMax) + { + } + if (isLFastUnderMax) + { + } + if (isLFastOverMin) + { + } + if (isLFastUnderMin) + { + } + if (isLFastCrossedOverMax) + { + } + if (isLFastCrossedUnderMax) + { + } + if (isLFastCrossedOverMin) + { + } + if (isLFastCrossedUnderMin) + { + } + if (isLSlowOverMax) + { + } + if (isLSlowUnderMax) + { + } + if (isLSlowOverMin) + { + } + if (isLSlowUnderMin) + { + } + if (isLSlowCrossedOverMax) + { + } + if (isLSlowCrossedUnderMax) + { + } + if (isLSlowCrossedOverMin) + { + } + if (isLSlowCrossedUnderMin) + { + } + + // + // Hind ... + if (isHFastOverSlow) + { + } + if (isHFastUnderSlow) + { + } + if (isHFastCrossedOverSlow) + { + } + if (isHFastCrossedUnderSlow) + { + } + if (isCLoseOverHFast) + { + } + if (isCloseCrossedOverHFast) + { + } + if (isCloseUnderHFast) + { + } + if (isCloseCrossedUnderHFast) + { + } + if (isCloseOverHSlow) + { + } + if (isCloseCrossedOverHSlow) + { + } + if (isCloseUnderHSlow) + { + } + if (isCloseCrossedUnderHSlow) + { + } + if (isRetestHFastSlow) + { + } + if (isHFastOverMax) + { + } + if (isHFastUnderMax) + { + } + if (isHFastOverMin) + { + } + if (isHFastUnderMin) + { + } + if (isHFastCrossedOverMax) + { + } + if (isHFastCrossedUnderMax) + { + } + if (isHFastCrossedOverMin) + { + } + if (isHFastCrossedUnderMin) + { + } + if (isHSlowOverMax) + { + } + if (isHSlowUnderMax) + { + } + if (isHSlowOverMin) + { + } + if (isHSlowUnderMin) + { + } + if (isHSlowCrossedOverMax) + { + } + if (isHSlowCrossedUnderMax) + { + } + if (isHSlowCrossedOverMin) + { + } + if (isHSlowCrossedUnderMin) + { + } + } + + // + string GenerateSummary( + bool onlyCommons = false, + bool onlyConditions = false, + bool includeScores = true, + bool ignoreFalseConditions = true, + string separator = "\n" // + ) + { + // + string result = NULL; + + // + double bullishScore = 0; + double bearishScore = 0; + GenerateScore( + bullishScore, + bearishScore // + ); + + // + string scoresStr = + // + "Scores: " + separator + + "---------------" + separator + + "Bullish: " + ToString(bullishScore) + separator + + "Bearish: " + ToString(bearishScore) + separator + + "" + // + ; + + // + string commonStr = GenerateSpecifiedCommonSummary( + this, + separator, + includeScores // + ); + + // + string conditionsStr = + // + // AVG ... + ToString("isFastOverSlow", isFastOverSlow, ignoreFalseConditions, separator) + + ToString("isFastUnderSlow", isFastUnderSlow, ignoreFalseConditions, separator) + + ToString("isFastCrossedOverSlow", isFastCrossedOverSlow, ignoreFalseConditions, separator) + + ToString("isFastCrossedUnderSlow", isFastCrossedUnderSlow, ignoreFalseConditions, separator) + + ToString("isCLoseOverFast", isCLoseOverFast, ignoreFalseConditions, separator) + + ToString("isCloseCrossedOverFast", isCloseCrossedOverFast, ignoreFalseConditions, separator) + + ToString("isCloseUnderFast", isCloseUnderFast, ignoreFalseConditions, separator) + + ToString("isCloseCrossedUnderFast", isCloseCrossedUnderFast, ignoreFalseConditions, separator) + + ToString("isCloseOverSlow", isCloseOverSlow, ignoreFalseConditions, separator) + + ToString("isCloseCrossedOverSlow", isCloseCrossedOverSlow, ignoreFalseConditions, separator) + + ToString("isCloseUnderSlow", isCloseUnderSlow, ignoreFalseConditions, separator) + + ToString("isCloseCrossedUnderSlow", isCloseCrossedUnderSlow, ignoreFalseConditions, separator) + + ToString("isRetestFastSlow", isRetestFastSlow, ignoreFalseConditions, separator) + + ToString("isFastOverMax", isFastOverMax, ignoreFalseConditions, separator) + + ToString("isFastUnderMax", isFastUnderMax, ignoreFalseConditions, separator) + + ToString("isFastOverMin", isFastOverMin, ignoreFalseConditions, separator) + + ToString("isFastUnderMin", isFastUnderMin, ignoreFalseConditions, separator) + + ToString("isFastCrossedOverMax", isFastCrossedOverMax, ignoreFalseConditions, separator) + + ToString("isFastCrossedUnderMax", isFastCrossedUnderMax, ignoreFalseConditions, separator) + + ToString("isFastCrossedOverMin", isFastCrossedOverMin, ignoreFalseConditions, separator) + + ToString("isFastCrossedUnderMin", isFastCrossedUnderMin, ignoreFalseConditions, separator) + + ToString("isSlowOverMax", isSlowOverMax, ignoreFalseConditions, separator) + + ToString("isSlowUnderMax", isSlowUnderMax, ignoreFalseConditions, separator) + + ToString("isSlowOverMin", isSlowOverMin, ignoreFalseConditions, separator) + + ToString("isSlowUnderMin", isSlowUnderMin, ignoreFalseConditions, separator) + + ToString("isSlowCrossedOverMax", isSlowCrossedOverMax, ignoreFalseConditions, separator) + + ToString("isSlowCrossedUnderMax", isSlowCrossedUnderMax, ignoreFalseConditions, separator) + + ToString("isSlowCrossedOverMin", isSlowCrossedOverMin, ignoreFalseConditions, separator) + + ToString("isSlowCrossedUnderMin", isSlowCrossedUnderMin, ignoreFalseConditions, separator) + + // + // Current ... + ToString("isCFastOverSlow", isCFastOverSlow, ignoreFalseConditions, separator) + + ToString("isCFastUnderSlow", isCFastUnderSlow, ignoreFalseConditions, separator) + + ToString("isCFastCrossedOverSlow", isCFastCrossedOverSlow, ignoreFalseConditions, separator) + + ToString("isCFastCrossedUnderSlow", isCFastCrossedUnderSlow, ignoreFalseConditions, separator) + + ToString("isCLoseOverCFast", isCLoseOverCFast, ignoreFalseConditions, separator) + + ToString("isCloseCrossedOverCFast", isCloseCrossedOverCFast, ignoreFalseConditions, separator) + + ToString("isCloseUnderCFast", isCloseUnderCFast, ignoreFalseConditions, separator) + + ToString("isCloseCrossedUnderCFast", isCloseCrossedUnderCFast, ignoreFalseConditions, separator) + + ToString("isCloseOverCSlow", isCloseOverCSlow, ignoreFalseConditions, separator) + + ToString("isCloseCrossedOverCSlow", isCloseCrossedOverCSlow, ignoreFalseConditions, separator) + + ToString("isCloseUnderCSlow", isCloseUnderCSlow, ignoreFalseConditions, separator) + + ToString("isCloseCrossedUnderCSlow", isCloseCrossedUnderCSlow, ignoreFalseConditions, separator) + + ToString("isRetestCFastSlow", isRetestCFastSlow, ignoreFalseConditions, separator) + + ToString("isCFastOverMax", isCFastOverMax, ignoreFalseConditions, separator) + + ToString("isCFastUnderMax", isCFastUnderMax, ignoreFalseConditions, separator) + + ToString("isCFastOverMin", isCFastOverMin, ignoreFalseConditions, separator) + + ToString("isCFastUnderMin", isCFastUnderMin, ignoreFalseConditions, separator) + + ToString("isCFastCrossedOverMax", isCFastCrossedOverMax, ignoreFalseConditions, separator) + + ToString("isCFastCrossedUnderMax", isCFastCrossedUnderMax, ignoreFalseConditions, separator) + + ToString("isCFastCrossedOverMin", isCFastCrossedOverMin, ignoreFalseConditions, separator) + + ToString("isCFastCrossedUnderMin", isCFastCrossedUnderMin, ignoreFalseConditions, separator) + + ToString("isCSlowOverMax", isCSlowOverMax, ignoreFalseConditions, separator) + + ToString("isCSlowUnderMax", isCSlowUnderMax, ignoreFalseConditions, separator) + + ToString("isCSlowOverMin", isCSlowOverMin, ignoreFalseConditions, separator) + + ToString("isCSlowUnderMin", isCSlowUnderMin, ignoreFalseConditions, separator) + + ToString("isCSlowCrossedOverMax", isCSlowCrossedOverMax, ignoreFalseConditions, separator) + + ToString("isCSlowCrossedUnderMax", isCSlowCrossedUnderMax, ignoreFalseConditions, separator) + + ToString("isCSlowCrossedOverMin", isCSlowCrossedOverMin, ignoreFalseConditions, separator) + + ToString("isCSlowCrossedUnderMin", isCSlowCrossedUnderMin, ignoreFalseConditions, separator) + + // + // Short ... + ToString("isSFastOverSlow", isSFastOverSlow, ignoreFalseConditions, separator) + + ToString("isSFastUnderSlow", isSFastUnderSlow, ignoreFalseConditions, separator) + + ToString("isSFastCrossedOverSlow", isSFastCrossedOverSlow, ignoreFalseConditions, separator) + + ToString("isSFastCrossedUnderSlow", isSFastCrossedUnderSlow, ignoreFalseConditions, separator) + + ToString("isCLoseOverSFast", isCLoseOverSFast, ignoreFalseConditions, separator) + + ToString("isCloseCrossedOverSFast", isCloseCrossedOverSFast, ignoreFalseConditions, separator) + + ToString("isCloseUnderSFast", isCloseUnderSFast, ignoreFalseConditions, separator) + + ToString("isCloseCrossedUnderSFast", isCloseCrossedUnderSFast, ignoreFalseConditions, separator) + + ToString("isCloseOverSSlow", isCloseOverSSlow, ignoreFalseConditions, separator) + + ToString("isCloseCrossedOverSSlow", isCloseCrossedOverSSlow, ignoreFalseConditions, separator) + + ToString("isCloseUnderSSlow", isCloseUnderSSlow, ignoreFalseConditions, separator) + + ToString("isCloseCrossedUnderSSlow", isCloseCrossedUnderSSlow, ignoreFalseConditions, separator) + + ToString("isRetestSFastSlow", isRetestSFastSlow, ignoreFalseConditions, separator) + + ToString("isSFastOverMax", isSFastOverMax, ignoreFalseConditions, separator) + + ToString("isSFastUnderMax", isSFastUnderMax, ignoreFalseConditions, separator) + + ToString("isSFastOverMin", isSFastOverMin, ignoreFalseConditions, separator) + + ToString("isSFastUnderMin", isSFastUnderMin, ignoreFalseConditions, separator) + + ToString("isSFastCrossedOverMax", isSFastCrossedOverMax, ignoreFalseConditions, separator) + + ToString("isSFastCrossedUnderMax", isSFastCrossedUnderMax, ignoreFalseConditions, separator) + + ToString("isSFastCrossedOverMin", isSFastCrossedOverMin, ignoreFalseConditions, separator) + + ToString("isSFastCrossedUnderMin", isSFastCrossedUnderMin, ignoreFalseConditions, separator) + + ToString("isSSlowOverMax", isSSlowOverMax, ignoreFalseConditions, separator) + + ToString("isSSlowUnderMax", isSSlowUnderMax, ignoreFalseConditions, separator) + + ToString("isSSlowOverMin", isSSlowOverMin, ignoreFalseConditions, separator) + + ToString("isSSlowUnderMin", isSSlowUnderMin, ignoreFalseConditions, separator) + + ToString("isSSlowCrossedOverMax", isSSlowCrossedOverMax, ignoreFalseConditions, separator) + + ToString("isSSlowCrossedUnderMax", isSSlowCrossedUnderMax, ignoreFalseConditions, separator) + + ToString("isSSlowCrossedOverMin", isSSlowCrossedOverMin, ignoreFalseConditions, separator) + + ToString("isSSlowCrossedUnderMin", isSSlowCrossedUnderMin, ignoreFalseConditions, separator) + + // + // Medium ... + ToString("isMFastOverSlow", isMFastOverSlow, ignoreFalseConditions, separator) + + ToString("isMFastUnderSlow", isMFastUnderSlow, ignoreFalseConditions, separator) + + ToString("isMFastCrossedOverSlow", isMFastCrossedOverSlow, ignoreFalseConditions, separator) + + ToString("isMFastCrossedUnderSlow", isMFastCrossedUnderSlow, ignoreFalseConditions, separator) + + ToString("isCLoseOverMFast", isCLoseOverMFast, ignoreFalseConditions, separator) + + ToString("isCloseCrossedOverMFast", isCloseCrossedOverMFast, ignoreFalseConditions, separator) + + ToString("isCloseUnderMFast", isCloseUnderMFast, ignoreFalseConditions, separator) + + ToString("isCloseCrossedUnderMFast", isCloseCrossedUnderMFast, ignoreFalseConditions, separator) + + ToString("isCloseOverMSlow", isCloseOverMSlow, ignoreFalseConditions, separator) + + ToString("isCloseCrossedOverMSlow", isCloseCrossedOverMSlow, ignoreFalseConditions, separator) + + ToString("isCloseUnderMSlow", isCloseUnderMSlow, ignoreFalseConditions, separator) + + ToString("isCloseCrossedUnderMSlow", isCloseCrossedUnderMSlow, ignoreFalseConditions, separator) + + ToString("isRetestMFastSlow", isRetestMFastSlow, ignoreFalseConditions, separator) + + ToString("isMFastOverMax", isMFastOverMax, ignoreFalseConditions, separator) + + ToString("isMFastUnderMax", isMFastUnderMax, ignoreFalseConditions, separator) + + ToString("isMFastOverMin", isMFastOverMin, ignoreFalseConditions, separator) + + ToString("isMFastUnderMin", isMFastUnderMin, ignoreFalseConditions, separator) + + ToString("isMFastCrossedOverMax", isMFastCrossedOverMax, ignoreFalseConditions, separator) + + ToString("isMFastCrossedUnderMax", isMFastCrossedUnderMax, ignoreFalseConditions, separator) + + ToString("isMFastCrossedOverMin", isMFastCrossedOverMin, ignoreFalseConditions, separator) + + ToString("isMFastCrossedUnderMin", isMFastCrossedUnderMin, ignoreFalseConditions, separator) + + ToString("isMSlowOverMax", isMSlowOverMax, ignoreFalseConditions, separator) + + ToString("isMSlowUnderMax", isMSlowUnderMax, ignoreFalseConditions, separator) + + ToString("isMSlowOverMin", isMSlowOverMin, ignoreFalseConditions, separator) + + ToString("isMSlowUnderMin", isMSlowUnderMin, ignoreFalseConditions, separator) + + ToString("isMSlowCrossedOverMax", isMSlowCrossedOverMax, ignoreFalseConditions, separator) + + ToString("isMSlowCrossedUnderMax", isMSlowCrossedUnderMax, ignoreFalseConditions, separator) + + ToString("isMSlowCrossedOverMin", isMSlowCrossedOverMin, ignoreFalseConditions, separator) + + ToString("isMSlowCrossedUnderMin", isMSlowCrossedUnderMin, ignoreFalseConditions, separator) + + // + // Long ... + ToString("isLFastOverSlow", isLFastOverSlow, ignoreFalseConditions, separator) + + ToString("isLFastUnderSlow", isLFastUnderSlow, ignoreFalseConditions, separator) + + ToString("isLFastCrossedOverSlow", isLFastCrossedOverSlow, ignoreFalseConditions, separator) + + ToString("isLFastCrossedUnderSlow", isLFastCrossedUnderSlow, ignoreFalseConditions, separator) + + ToString("isCLoseOverLFast", isCLoseOverLFast, ignoreFalseConditions, separator) + + ToString("isCloseCrossedOverLFast", isCloseCrossedOverLFast, ignoreFalseConditions, separator) + + ToString("isCloseUnderLFast", isCloseUnderLFast, ignoreFalseConditions, separator) + + ToString("isCloseCrossedUnderLFast", isCloseCrossedUnderLFast, ignoreFalseConditions, separator) + + ToString("isCloseOverLSlow", isCloseOverLSlow, ignoreFalseConditions, separator) + + ToString("isCloseCrossedOverLSlow", isCloseCrossedOverLSlow, ignoreFalseConditions, separator) + + ToString("isCloseUnderLSlow", isCloseUnderLSlow, ignoreFalseConditions, separator) + + ToString("isCloseCrossedUnderLSlow", isCloseCrossedUnderLSlow, ignoreFalseConditions, separator) + + ToString("isRetestLFastSlow", isRetestLFastSlow, ignoreFalseConditions, separator) + + ToString("isLFastOverMax", isLFastOverMax, ignoreFalseConditions, separator) + + ToString("isLFastUnderMax", isLFastUnderMax, ignoreFalseConditions, separator) + + ToString("isLFastOverMin", isLFastOverMin, ignoreFalseConditions, separator) + + ToString("isLFastUnderMin", isLFastUnderMin, ignoreFalseConditions, separator) + + ToString("isLFastCrossedOverMax", isLFastCrossedOverMax, ignoreFalseConditions, separator) + + ToString("isLFastCrossedUnderMax", isLFastCrossedUnderMax, ignoreFalseConditions, separator) + + ToString("isLFastCrossedOverMin", isLFastCrossedOverMin, ignoreFalseConditions, separator) + + ToString("isLFastCrossedUnderMin", isLFastCrossedUnderMin, ignoreFalseConditions, separator) + + ToString("isLSlowOverMax", isLSlowOverMax, ignoreFalseConditions, separator) + + ToString("isLSlowUnderMax", isLSlowUnderMax, ignoreFalseConditions, separator) + + ToString("isLSlowOverMin", isLSlowOverMin, ignoreFalseConditions, separator) + + ToString("isLSlowUnderMin", isLSlowUnderMin, ignoreFalseConditions, separator) + + ToString("isLSlowCrossedOverMax", isLSlowCrossedOverMax, ignoreFalseConditions, separator) + + ToString("isLSlowCrossedUnderMax", isLSlowCrossedUnderMax, ignoreFalseConditions, separator) + + ToString("isLSlowCrossedOverMin", isLSlowCrossedOverMin, ignoreFalseConditions, separator) + + ToString("isLSlowCrossedUnderMin", isLSlowCrossedUnderMin, ignoreFalseConditions, separator) + + // + // Hind ... + ToString("isHFastOverSlow", isHFastOverSlow, ignoreFalseConditions, separator) + + ToString("isHFastUnderSlow", isHFastUnderSlow, ignoreFalseConditions, separator) + + ToString("isHFastCrossedOverSlow", isHFastCrossedOverSlow, ignoreFalseConditions, separator) + + ToString("isHFastCrossedUnderSlow", isHFastCrossedUnderSlow, ignoreFalseConditions, separator) + + ToString("isCLoseOverHFast", isCLoseOverHFast, ignoreFalseConditions, separator) + + ToString("isCloseCrossedOverHFast", isCloseCrossedOverHFast, ignoreFalseConditions, separator) + + ToString("isCloseUnderHFast", isCloseUnderHFast, ignoreFalseConditions, separator) + + ToString("isCloseCrossedUnderHFast", isCloseCrossedUnderHFast, ignoreFalseConditions, separator) + + ToString("isCloseOverHSlow", isCloseOverHSlow, ignoreFalseConditions, separator) + + ToString("isCloseCrossedOverHSlow", isCloseCrossedOverHSlow, ignoreFalseConditions, separator) + + ToString("isCloseUnderHSlow", isCloseUnderHSlow, ignoreFalseConditions, separator) + + ToString("isCloseCrossedUnderHSlow", isCloseCrossedUnderHSlow, ignoreFalseConditions, separator) + + ToString("isRetestHFastSlow", isRetestHFastSlow, ignoreFalseConditions, separator) + + ToString("isHFastOverMax", isHFastOverMax, ignoreFalseConditions, separator) + + ToString("isHFastUnderMax", isHFastUnderMax, ignoreFalseConditions, separator) + + ToString("isHFastOverMin", isHFastOverMin, ignoreFalseConditions, separator) + + ToString("isHFastUnderMin", isHFastUnderMin, ignoreFalseConditions, separator) + + ToString("isHFastCrossedOverMax", isHFastCrossedOverMax, ignoreFalseConditions, separator) + + ToString("isHFastCrossedUnderMax", isHFastCrossedUnderMax, ignoreFalseConditions, separator) + + ToString("isHFastCrossedOverMin", isHFastCrossedOverMin, ignoreFalseConditions, separator) + + ToString("isHFastCrossedUnderMin", isHFastCrossedUnderMin, ignoreFalseConditions, separator) + + ToString("isHSlowOverMax", isHSlowOverMax, ignoreFalseConditions, separator) + + ToString("isHSlowUnderMax", isHSlowUnderMax, ignoreFalseConditions, separator) + + ToString("isHSlowOverMin", isHSlowOverMin, ignoreFalseConditions, separator) + + ToString("isHSlowUnderMin", isHSlowUnderMin, ignoreFalseConditions, separator) + + ToString("isHSlowCrossedOverMax", isHSlowCrossedOverMax, ignoreFalseConditions, separator) + + ToString("isHSlowCrossedUnderMax", isHSlowCrossedUnderMax, ignoreFalseConditions, separator) + + ToString("isHSlowCrossedOverMin", isHSlowCrossedOverMin, ignoreFalseConditions, separator) + + ToString("isHSlowCrossedUnderMin", isHSlowCrossedUnderMin, ignoreFalseConditions, separator) + + // + "" + // + ; + + // + result = + // + "[" + GetTag() + "]" + separator + + (onlyConditions + ? "" + : commonStr) + + (!includeScores + ? "" + : scoresStr) + + " " + separator + + (onlyCommons + ? "" + : conditionsStr) + + "" + // + ; + + // + return result; + } + + // + string GetTag() + { + return "XCHMA"; + } +}; + +// +enum ENUM_XCHMA_VALUES +{ + XCHMA_ALL = 0, + XCHMA_NONE = 1, + XCHMA_ALL_BUT_AVG = 2, + XCHMA_ALL_BUT_CURRENT = 3, + XCHMA_ALL_BUT_SHORT = 4, + XCHMA_ALL_BUT_MEDIUM = 5, + XCHMA_ALL_BUT_LONG = 6, + XCHMA_ALL_BUT_HIND = 7, +}; + +// +void FillCHMAValues( + double &result[], // + XCHMAConditions &conditions, // + ENUM_XCHMA_VALUES method, // + int index = 1 // +) +{ + // + // Cleaning Result ... + Clean(result); + + // + if (method == XCHMA_NONE) + { + return; + } + + // + // AVG ... + double iFast = conditions.fast[index]; + double iSlow = conditions.slow[index]; + + // + // Current ... + double iCFast = conditions.cFast[index]; + double iCSlow = conditions.cSlow[index]; + + // + // Short ... + double iSFast = conditions.sFast[index]; + double iSSlow = conditions.sSlow[index]; + + // + // Medium ... + double iMFast = conditions.mFast[index]; + double iMSlow = conditions.mSlow[index]; + + // + // Long ... + double iLFast = conditions.lFast[index]; + double iLSlow = conditions.lSlow[index]; + + // + // Hind ... + double iHFast = conditions.hFast[index]; + double iHSlow = conditions.hSlow[index]; + + // + if (method == XCHMA_ALL) + { + // + // AVG ... + + // + Add( + iFast, + result // + ); + + // + Add( + iSlow, + result // + ); + + // + // Current ... + + // + Add( + iCFast, + result // + ); + + // + Add( + iCSlow, + result // + ); + + // + // Short ... + + // + Add( + iSFast, + result // + ); + + // + Add( + iSSlow, + result // + ); + + // + // Medium ... + + // + Add( + iMFast, + result // + ); + + // + Add( + iMSlow, + result // + ); + + // + // Long ... + + // + Add( + iLFast, + result // + ); + + // + Add( + iLSlow, + result // + ); + + // + // Hind ... + + // + Add( + iHFast, + result // + ); + + // + Add( + iHSlow, + result // + ); + + // + return; + } + + // + // AVG ... + if (method != XCHMA_ALL_BUT_AVG) + { + // + Add( + iFast, + result // + ); + + // + Add( + iSlow, + result // + ); + } + + // + // Current ... + if (method != XCHMA_ALL_BUT_CURRENT) + { + // + Add( + iCFast, + result // + ); + + // + Add( + iCSlow, + result // + ); + } + + // + // Short ... + if (method != XCHMA_ALL_BUT_SHORT) + { + // + Add( + iSFast, + result // + ); + + // + Add( + iSSlow, + result // + ); + } + + // + // Medium ... + if (method != XCHMA_ALL_BUT_MEDIUM) + { + // + Add( + iMFast, + result // + ); + + // + Add( + iMSlow, + result // + ); + } + + // + // Long ... + if (method != XCHMA_ALL_BUT_LONG) + { + // + Add( + iLFast, + result // + ); + + // + Add( + iLSlow, + result // + ); + } + + // + // Hind ... + if (method != XCHMA_ALL_BUT_HIND) + { + // + Add( + iHFast, + result // + ); + + // + Add( + iHSlow, + result // + ); + } + + // +} + +// +// Calculate Specific Cycle Conditions ... +void CalculateCycleConditions( + int barIndex, + double &fast[], + double &slow[], + XOHCL &cBar, + XOHCL &pBar, + double hhValue, + double llValue, + double minValue, + double minValuePrev, + double maxValue, + double maxValuePrev, + bool &isFastOverSlow, + bool &isFastCrossedOverSlow, + bool &isFastUnderSlow, + bool &isFastCrossedUnderSlow, + bool &isFastOverMax, + bool &isFastCrossedOverMax, + bool &isFastUnderMax, + bool &isFastCrossedUnderMax, + bool &isFastOverMin, + bool &isFastCrossedOverMin, + bool &isFastUnderMin, + bool &isFastCrossedUnderMin, + bool &isSlowOverMax, + bool &isSlowCrossedOverMax, + bool &isSlowUnderMax, + bool &isSlowCrossedUnderMax, + bool &isSlowOverMin, + bool &isSlowCrossedOverMin, + bool &isSlowUnderMin, + bool &isSlowCrossedUnderMin, + bool &isRetestFastSlow, + bool &isCLoseOverFast, + bool &isCloseCrossedOverFast, + bool &isCloseUnderFast, + bool &isCloseCrossedUnderFast, + bool &isCloseOverSlow, + bool &isCloseCrossedOverSlow, + bool &isCloseUnderSlow, + bool &isCloseCrossedUnderSlow // +) +{ + // + int zIndex = barIndex; + int cIndex = zIndex + 1; + int pIndex = cIndex + 1; + int ppIndex = pIndex + 1; + + // + isFastOverSlow = fast[cIndex] > slow[cIndex]; + bool isFastOverSlowPrev = fast[pIndex] > slow[pIndex]; + isFastCrossedOverSlow = isFastOverSlow && + !isFastOverSlowPrev; + + // + isFastUnderSlow = fast[cIndex] < slow[cIndex]; + bool isFastUnderSlowPrev = fast[pIndex] < slow[pIndex]; + isFastCrossedUnderSlow = isFastUnderSlow && + !isFastUnderSlowPrev; + + // + isFastOverMax = fast[cIndex] > maxValue; + bool isFastOverMaxPrev = fast[pIndex] > maxValuePrev; + isFastCrossedOverMax = isFastOverMax && + !isFastOverMaxPrev; + + // + isFastUnderMax = fast[cIndex] < maxValue; + bool isFastUnderMaxPrev = fast[pIndex] < maxValuePrev; + isFastCrossedUnderMax = isFastUnderMax && + !isFastUnderMaxPrev; + + // + isFastOverMin = fast[cIndex] > minValue; + bool isFastOverMinPrev = fast[pIndex] > minValuePrev; + isFastCrossedOverMin = isFastOverMin && + !isFastOverMinPrev; + + // + isFastUnderMin = fast[cIndex] > minValue; + bool isFastUnderMinPrev = fast[pIndex] > minValuePrev; + isFastCrossedUnderMin = isFastUnderMin && + !isFastUnderMinPrev; + + // + isSlowOverMax = slow[cIndex] > maxValue; + bool isSlowOverMaxPrev = slow[pIndex] > maxValuePrev; + isSlowCrossedOverMax = isSlowOverMax && + !isSlowOverMaxPrev; + + // + isSlowUnderMax = slow[cIndex] < maxValue; + bool isSlowUnderMaxPrev = slow[pIndex] < maxValuePrev; + isSlowCrossedUnderMax = isSlowUnderMax && + !isSlowUnderMaxPrev; + + // + isSlowOverMin = slow[cIndex] > minValue; + bool isSlowOverMinPrev = slow[pIndex] > minValuePrev; + isSlowCrossedOverMin = isSlowOverMin && + !isSlowOverMinPrev; + + // + isSlowUnderMin = slow[cIndex] < minValue; + bool isSlowUnderMinPrev = slow[pIndex] < minValuePrev; + isSlowCrossedUnderMin = isSlowUnderMin && + !isSlowUnderMinPrev; + + // + isRetestFastSlow = + // + // HH (s) ... + ( + // + hhValue > MathMax(fast[1], slow[1]) || + hhValue > MathMax(fast[2], slow[2]) || + hhValue > MathMax(fast[3], slow[3]) || + hhValue > MathMax(fast[4], slow[4]) + // + ) + // + && + // + // LL (s) ... + ( + // + llValue > MathMin(fast[1], slow[1]) || + llValue > MathMin(fast[2], slow[2]) || + llValue > MathMin(fast[3], slow[3]) || + llValue > MathMin(fast[4], slow[4]) + // + ) + // + ; + + // + isCLoseOverFast = cBar.close > fast[cIndex]; + bool isCLoseOverFastPrev = pBar.close > fast[pIndex]; + isCloseCrossedOverFast = isCLoseOverFast && + !isCLoseOverFastPrev; + + // + isCloseUnderFast = cBar.close < fast[cIndex]; + bool isCloseUnderFastPrev = pBar.close < fast[pIndex]; + isCloseCrossedUnderFast = isCloseUnderFast && + !isCloseUnderFastPrev; + + // + isCloseOverSlow = cBar.close > slow[cIndex]; + bool isCloseOverSlowPrev = pBar.close > slow[pIndex]; + isCloseCrossedOverSlow = isCloseOverSlow && + !isCloseOverSlowPrev; + + // + isCloseUnderSlow = cBar.close < slow[cIndex]; + bool isCloseUnderSlowPrev = pBar.close < slow[pIndex]; + isCloseCrossedUnderSlow = isCloseUnderSlow && + !isCloseUnderSlowPrev; +} + +// +// Class ... +class XSCXCHMAHelper : public XSCBaseHelper +{ + // + // Public ... +public: + // + // Props ... + + // + // Constructors ... + XSCXCHMAHelper() : XSCBaseHelper(_Symbol, _Period) + { + } + + // + // Deconstructor ... + ~XSCXCHMAHelper() {} + + // + // Tools ... + bool Init( + string symbol, // Trading Symbol + ENUM_TIMEFRAMES period, // Trading Period + XCHMAInputs &inputs // Inputs + ) + { + // + bool result = false; + + // + mSymbol = symbol; + mPeriod = period; + + // + result = inputs.IsValid(); + if (!result) + { + return result; + } + + // + mInputs = inputs; + + // + ArraySetAsSeries(fastBuffer, true); + ArraySetAsSeries(slowBuffer, true); + ArraySetAsSeries(cFastBuffer, true); + ArraySetAsSeries(cSlowBuffer, true); + ArraySetAsSeries(sFastBuffer, true); + ArraySetAsSeries(sSlowBuffer, true); + ArraySetAsSeries(mFastBuffer, true); + ArraySetAsSeries(mSlowBuffer, true); + ArraySetAsSeries(lFastBuffer, true); + ArraySetAsSeries(lSlowBuffer, true); + ArraySetAsSeries(hFastBuffer, true); + ArraySetAsSeries(hSlowBuffer, true); + + // + mHandler = iCustom( + mSymbol, + mPeriod, + "x-saherelm.xchma", + // + // Inputs ... + // + // Market ... + "", + mInputs.fastLength, + mInputs.slowLength, + mInputs.method, + mInputs.appliedTo, + // + // Cycles ... + "", + // + // Short ... + "", + mInputs.scMethod, + mInputs.scPeriod, + // + // Medium ... + "", + mInputs.mcMethod, + mInputs.mcPeriod, + // + // Long ... + "", + mInputs.lcMethod, + mInputs.lcPeriod, + // + // Hind ... + "", + mInputs.hcMethod, + mInputs.hcPeriod, + // + // Presentation ... + "", + mInputs.showFast, + mInputs.showSlow, + // + mInputs.showCCFast, + mInputs.showCCSlow, + mInputs.showSCFast, + mInputs.showSCSlow, + mInputs.showMCFast, + mInputs.showMCSlow, + mInputs.showLCFast, + mInputs.showLCSlow, + mInputs.showHCFast, + mInputs.showHCSlow + // + ); + result = mHandler != INVALID_HANDLE; + if (!result) + { + return result; + } + + // + return result; + } + + // + // Inputs ... + + // + XCHMAInputs GetInputs() + { + return mInputs; + } + + // + bool SetInputs( + XCHMAInputs &inputs // Configs + ) + { + // + return Init( + mSymbol, + mPeriod, + inputs + // + ); + } + + // + // Buffers ... + + // + // AVG ... + + // + double GetFast( + int barIndex // Bar Index + ) + { + // + if (barIndex < 0) + { + barIndex = 0; + } + + // + Calculate(); + + // + int count = ArraySize(fastBuffer); + if (barIndex >= count) + { + barIndex = count - 1; + } + + // + return fastBuffer[barIndex]; + } + + // + // Copy Required Items ... + int CopyFast( + int start, // Start + int count, // Number of Items for read + double &buffer[], // Dest Buffer + bool forceClean = true // Force To Clean buffer + ) + { + // + // Update Calculations ... + Calculate(); + + // + // Copy Items ... + return Copy( + start, + count, + fastBuffer, + buffer, + forceClean + // + ); + } + + // + double GetSlow( + int barIndex // Bar Index + ) + { + // + if (barIndex < 0) + { + barIndex = 0; + } + + // + Calculate(); + + // + int count = ArraySize(slowBuffer); + if (barIndex >= count) + { + barIndex = count - 1; + } + + // + return slowBuffer[barIndex]; + } + + // + // Copy Required Items ... + int CopySlow( + int start, // Start + int count, // Number of Items for read + double &buffer[], // Dest Buffer + bool forceClean = true // Force To Clean buffer + ) + { + // + // Update Calculations ... + Calculate(); + + // + // Copy Items ... + return Copy( + start, + count, + slowBuffer, + buffer, + forceClean + // + ); + } + + // + // Current ... + + // + double GetCFast( + int barIndex // Bar Index + ) + { + // + if (barIndex < 0) + { + barIndex = 0; + } + + // + Calculate(); + + // + int count = ArraySize(cFastBuffer); + if (barIndex >= count) + { + barIndex = count - 1; + } + + // + return cFastBuffer[barIndex]; + } + + // + // Copy Required Items ... + int CopyCFast( + int start, // Start + int count, // Number of Items for read + double &buffer[], // Dest Buffer + bool forceClean = true // Force To Clean buffer + ) + { + // + // Update Calculations ... + Calculate(); + + // + // Copy Items ... + return Copy( + start, + count, + cFastBuffer, + buffer, + forceClean + // + ); + } + + // + double GetCSlow( + int barIndex // Bar Index + ) + { + // + if (barIndex < 0) + { + barIndex = 0; + } + + // + Calculate(); + + // + int count = ArraySize(cSlowBuffer); + if (barIndex >= count) + { + barIndex = count - 1; + } + + // + return cSlowBuffer[barIndex]; + } + + // + // Copy Required Items ... + int CopyCSlow( + int start, // Start + int count, // Number of Items for read + double &buffer[], // Dest Buffer + bool forceClean = true // Force To Clean buffer + ) + { + // + // Update Calculations ... + Calculate(); + + // + // Copy Items ... + return Copy( + start, + count, + cSlowBuffer, + buffer, + forceClean + // + ); + } + + // + // Short ... + + // + double GetSFast( + int barIndex // Bar Index + ) + { + // + if (barIndex < 0) + { + barIndex = 0; + } + + // + Calculate(); + + // + int count = ArraySize(sFastBuffer); + if (barIndex >= count) + { + barIndex = count - 1; + } + + // + return sFastBuffer[barIndex]; + } + + // + // Copy Required Items ... + int CopySFast( + int start, // Start + int count, // Number of Items for read + double &buffer[], // Dest Buffer + bool forceClean = true // Force To Clean buffer + ) + { + // + // Update Calculations ... + Calculate(); + + // + // Copy Items ... + return Copy( + start, + count, + sFastBuffer, + buffer, + forceClean + // + ); + } + + // + double GetSSlow( + int barIndex // Bar Index + ) + { + // + if (barIndex < 0) + { + barIndex = 0; + } + + // + Calculate(); + + // + int count = ArraySize(sSlowBuffer); + if (barIndex >= count) + { + barIndex = count - 1; + } + + // + return sSlowBuffer[barIndex]; + } + + // + // Copy Required Items ... + int CopySSlow( + int start, // Start + int count, // Number of Items for read + double &buffer[], // Dest Buffer + bool forceClean = true // Force To Clean buffer + ) + { + // + // Update Calculations ... + Calculate(); + + // + // Copy Items ... + return Copy( + start, + count, + sSlowBuffer, + buffer, + forceClean + // + ); + } + + // + // Medium ... + + // + double GetMFast( + int barIndex // Bar Index + ) + { + // + if (barIndex < 0) + { + barIndex = 0; + } + + // + Calculate(); + + // + int count = ArraySize(mFastBuffer); + if (barIndex >= count) + { + barIndex = count - 1; + } + + // + return mFastBuffer[barIndex]; + } + + // + // Copy Required Items ... + int CopyMFast( + int start, // Start + int count, // Number of Items for read + double &buffer[], // Dest Buffer + bool forceClean = true // Force To Clean buffer + ) + { + // + // Update Calculations ... + Calculate(); + + // + // Copy Items ... + return Copy( + start, + count, + mFastBuffer, + buffer, + forceClean + // + ); + } + + // + double GetMSlow( + int barIndex // Bar Index + ) + { + // + if (barIndex < 0) + { + barIndex = 0; + } + + // + Calculate(); + + // + int count = ArraySize(mSlowBuffer); + if (barIndex >= count) + { + barIndex = count - 1; + } + + // + return mSlowBuffer[barIndex]; + } + + // + // Copy Required Items ... + int CopyMSlow( + int start, // Start + int count, // Number of Items for read + double &buffer[], // Dest Buffer + bool forceClean = true // Force To Clean buffer + ) + { + // + // Update Calculations ... + Calculate(); + + // + // Copy Items ... + return Copy( + start, + count, + mSlowBuffer, + buffer, + forceClean + // + ); + } + + // + // Long ... + + // + double GetLFast( + int barIndex // Bar Index + ) + { + // + if (barIndex < 0) + { + barIndex = 0; + } + + // + Calculate(); + + // + int count = ArraySize(lFastBuffer); + if (barIndex >= count) + { + barIndex = count - 1; + } + + // + return lFastBuffer[barIndex]; + } + + // + // Copy Required Items ... + int CopyLFast( + int start, // Start + int count, // Number of Items for read + double &buffer[], // Dest Buffer + bool forceClean = true // Force To Clean buffer + ) + { + // + // Update Calculations ... + Calculate(); + + // + // Copy Items ... + return Copy( + start, + count, + lFastBuffer, + buffer, + forceClean + // + ); + } + + // + double GetLSlow( + int barIndex // Bar Index + ) + { + // + if (barIndex < 0) + { + barIndex = 0; + } + + // + Calculate(); + + // + int count = ArraySize(lSlowBuffer); + if (barIndex >= count) + { + barIndex = count - 1; + } + + // + return lSlowBuffer[barIndex]; + } + + // + // Copy Required Items ... + int CopyLSlow( + int start, // Start + int count, // Number of Items for read + double &buffer[], // Dest Buffer + bool forceClean = true // Force To Clean buffer + ) + { + // + // Update Calculations ... + Calculate(); + + // + // Copy Items ... + return Copy( + start, + count, + lSlowBuffer, + buffer, + forceClean + // + ); + } + + // + // Hind ... + + // + double GetHFast( + int barIndex // Bar Index + ) + { + // + if (barIndex < 0) + { + barIndex = 0; + } + + // + Calculate(); + + // + int count = ArraySize(hFastBuffer); + if (barIndex >= count) + { + barIndex = count - 1; + } + + // + return hFastBuffer[barIndex]; + } + + // + // Copy Required Items ... + int CopyHFast( + int start, // Start + int count, // Number of Items for read + double &buffer[], // Dest Buffer + bool forceClean = true // Force To Clean buffer + ) + { + // + // Update Calculations ... + Calculate(); + + // + // Copy Items ... + return Copy( + start, + count, + hFastBuffer, + buffer, + forceClean + // + ); + } + + // + double GetHSlow( + int barIndex // Bar Index + ) + { + // + if (barIndex < 0) + { + barIndex = 0; + } + + // + Calculate(); + + // + int count = ArraySize(hSlowBuffer); + if (barIndex >= count) + { + barIndex = count - 1; + } + + // + return hSlowBuffer[barIndex]; + } + + // + // Copy Required Items ... + int CopyHSlow( + int start, // Start + int count, // Number of Items for read + double &buffer[], // Dest Buffer + bool forceClean = true // Force To Clean buffer + ) + { + // + // Update Calculations ... + Calculate(); + + // + // Copy Items ... + return Copy( + start, + count, + hSlowBuffer, + buffer, + forceClean + // + ); + } + + // + bool GetConditions( + XCHMAConditions &conditions, // + int barIndex = 0, // + int loopback = 3 // + ) + { + // + bool result = true; + + // + if (loopback < 3) + { + loopback = 3; + } + + // + conditions.Clean(); + + // + conditions.symbol = mSymbol; + conditions.period = mPeriod; + conditions.time = TimeCurrent(); + + // + int zIndex = barIndex; + int cIndex = zIndex + 1; + int pIndex = cIndex + 1; + int ppIndex = pIndex + 1; + + // + // Buffers ... + + // + // AVG ... + + // + // Fast ... + CopyFast( + zIndex, + loopback, + conditions.fast // + ); + + // + // Slow ... + CopySlow( + zIndex, + loopback, + conditions.slow // + ); + + // + // Current ... + + // + // Fast ... + CopyCFast( + zIndex, + loopback, + conditions.cFast // + ); + + // + // Slow ... + CopyCSlow( + zIndex, + loopback, + conditions.cSlow // + ); + + // + // Short ... + + // + // Fast ... + CopySFast( + zIndex, + loopback, + conditions.sFast // + ); + + // + // Slow ... + CopySSlow( + zIndex, + loopback, + conditions.sSlow // + ); + + // + // Medium ... + + // + // Fast ... + CopyMFast( + zIndex, + loopback, + conditions.mFast // + ); + + // + // Slow ... + CopyMSlow( + zIndex, + loopback, + conditions.mSlow // + ); + + // + // Long ... + + // + // Fast ... + CopyLFast( + zIndex, + loopback, + conditions.lFast // + ); + + // + // Slow ... + CopyLSlow( + zIndex, + loopback, + conditions.lSlow // + ); + + // + // Hind ... + + // + // Fast ... + CopyHFast( + zIndex, + loopback, + conditions.hFast // + ); + + // + // Slow ... + CopyHSlow( + zIndex, + loopback, + conditions.hSlow // + ); + + // + // Conditions ... + + // + XOHCL cBar; + result = cBar.Init( + mSymbol, + mPeriod, + cIndex // + ); + if (!result) + { + return result; + } + + // + XOHCL pBar; + result = pBar.Init( + mSymbol, + mPeriod, + pIndex // + ); + if (!result) + { + return result; + } + double hhValue = pBar.FindHighest( + loopback, + MODE_HIGH // + ); + double llValue = pBar.FindLowest( + loopback, + MODE_LOW // + ); + + // + double allValues[]; + double maxValue = 0; + double minValue = 0; + double maxValuePrev = 0; + double minValuePrev = 0; + + // + // AVG ... + + // + FillCHMAValues( + allValues, + conditions, + XCHMA_ALL_BUT_AVG, + cIndex // + ); + minValue = GetMin(allValues); + maxValue = GetMax(allValues); + + // + FillCHMAValues( + allValues, + conditions, + XCHMA_ALL_BUT_AVG, + pIndex // + ); + minValuePrev = GetMin(allValues); + maxValuePrev = GetMax(allValues); + + // + bool isFastOverSlow = false; + bool isFastCrossedOverSlow = false; + bool isFastUnderSlow = false; + bool isFastCrossedUnderSlow = false; + bool isFastOverMax = false; + bool isFastCrossedOverMax = false; + bool isFastUnderMax = false; + bool isFastCrossedUnderMax = false; + bool isFastOverMin = false; + bool isFastCrossedOverMin = false; + bool isFastUnderMin = false; + bool isFastCrossedUnderMin = false; + bool isSlowOverMax = false; + bool isSlowCrossedOverMax = false; + bool isSlowUnderMax = false; + bool isSlowCrossedUnderMax = false; + bool isSlowOverMin = false; + bool isSlowCrossedOverMin = false; + bool isSlowUnderMin = false; + bool isSlowCrossedUnderMin = false; + bool isRetestFastSlow = false; + bool isCLoseOverFast = false; + bool isCloseCrossedOverFast = false; + bool isCloseUnderFast = false; + bool isCloseCrossedUnderFast = false; + bool isCloseOverSlow = false; + bool isCloseCrossedOverSlow = false; + bool isCloseUnderSlow = false; + bool isCloseCrossedUnderSlow = false; + + // + CalculateCycleConditions( + barIndex, + conditions.fast, + conditions.slow, + cBar, + pBar, + hhValue, + llValue, + minValue, + minValuePrev, + maxValue, + maxValuePrev, + isFastOverSlow, + isFastCrossedOverSlow, + isFastUnderSlow, + isFastCrossedUnderSlow, + isFastOverMax, + isFastCrossedOverMax, + isFastUnderMax, + isFastCrossedUnderMax, + isFastOverMin, + isFastCrossedOverMin, + isFastUnderMin, + isFastCrossedUnderMin, + isSlowOverMax, + isSlowCrossedOverMax, + isSlowUnderMax, + isSlowCrossedUnderMax, + isSlowOverMin, + isSlowCrossedOverMin, + isSlowUnderMin, + isSlowCrossedUnderMin, + isRetestFastSlow, + isCLoseOverFast, + isCloseCrossedOverFast, + isCloseUnderFast, + isCloseCrossedUnderFast, + isCloseOverSlow, + isCloseCrossedOverSlow, + isCloseUnderSlow, + isCloseCrossedUnderSlow + // + ); + + // + // Current ... + + // + FillCHMAValues( + allValues, + conditions, + XCHMA_ALL_BUT_CURRENT, + cIndex // + ); + minValue = GetMin(allValues); + maxValue = GetMax(allValues); + + // + FillCHMAValues( + allValues, + conditions, + XCHMA_ALL_BUT_CURRENT, + pIndex // + ); + minValuePrev = GetMin(allValues); + maxValuePrev = GetMax(allValues); + + // + bool isCFastOverSlow = false; + bool isCFastCrossedOverSlow = false; + bool isCFastUnderSlow = false; + bool isCFastCrossedUnderSlow = false; + bool isCFastOverMax = false; + bool isCFastCrossedOverMax = false; + bool isCFastUnderMax = false; + bool isCFastCrossedUnderMax = false; + bool isCFastOverMin = false; + bool isCFastCrossedOverMin = false; + bool isCFastUnderMin = false; + bool isCFastCrossedUnderMin = false; + bool isCSlowOverMax = false; + bool isCSlowCrossedOverMax = false; + bool isCSlowUnderMax = false; + bool isCSlowCrossedUnderMax = false; + bool isCSlowOverMin = false; + bool isCSlowCrossedOverMin = false; + bool isCSlowUnderMin = false; + bool isCSlowCrossedUnderMin = false; + bool isRetestCFastSlow = false; + bool isCLoseOverCFast = false; + bool isCloseCrossedOverCFast = false; + bool isCloseUnderCFast = false; + bool isCloseCrossedUnderCFast = false; + bool isCloseOverCSlow = false; + bool isCloseCrossedOverCSlow = false; + bool isCloseUnderCSlow = false; + bool isCloseCrossedUnderCSlow = false; + + // + CalculateCycleConditions( + barIndex, + conditions.cFast, + conditions.cSlow, + cBar, + pBar, + hhValue, + llValue, + minValue, + minValuePrev, + maxValue, + maxValuePrev, + isCFastOverSlow, + isCFastCrossedOverSlow, + isCFastUnderSlow, + isCFastCrossedUnderSlow, + isCFastOverMax, + isCFastCrossedOverMax, + isCFastUnderMax, + isCFastCrossedUnderMax, + isCFastOverMin, + isCFastCrossedOverMin, + isCFastUnderMin, + isCFastCrossedUnderMin, + isCSlowOverMax, + isCSlowCrossedOverMax, + isCSlowUnderMax, + isCSlowCrossedUnderMax, + isCSlowOverMin, + isCSlowCrossedOverMin, + isCSlowUnderMin, + isCSlowCrossedUnderMin, + isRetestCFastSlow, + isCLoseOverCFast, + isCloseCrossedOverCFast, + isCloseUnderCFast, + isCloseCrossedUnderCFast, + isCloseOverCSlow, + isCloseCrossedOverCSlow, + isCloseUnderCSlow, + isCloseCrossedUnderCSlow + // + ); + + // + // Short ... + + // + FillCHMAValues( + allValues, + conditions, + XCHMA_ALL_BUT_SHORT, + cIndex // + ); + minValue = GetMin(allValues); + maxValue = GetMax(allValues); + + // + FillCHMAValues( + allValues, + conditions, + XCHMA_ALL_BUT_SHORT, + pIndex // + ); + minValuePrev = GetMin(allValues); + maxValuePrev = GetMax(allValues); + + // + bool isSFastOverSlow = false; + bool isSFastCrossedOverSlow = false; + bool isSFastUnderSlow = false; + bool isSFastCrossedUnderSlow = false; + bool isSFastOverMax = false; + bool isSFastCrossedOverMax = false; + bool isSFastUnderMax = false; + bool isSFastCrossedUnderMax = false; + bool isSFastOverMin = false; + bool isSFastCrossedOverMin = false; + bool isSFastUnderMin = false; + bool isSFastCrossedUnderMin = false; + bool isSSlowOverMax = false; + bool isSSlowCrossedOverMax = false; + bool isSSlowUnderMax = false; + bool isSSlowCrossedUnderMax = false; + bool isSSlowOverMin = false; + bool isSSlowCrossedOverMin = false; + bool isSSlowUnderMin = false; + bool isSSlowCrossedUnderMin = false; + bool isRetestSFastSlow = false; + bool isCLoseOverSFast = false; + bool isCloseCrossedOverSFast = false; + bool isCloseUnderSFast = false; + bool isCloseCrossedUnderSFast = false; + bool isCloseOverSSlow = false; + bool isCloseCrossedOverSSlow = false; + bool isCloseUnderSSlow = false; + bool isCloseCrossedUnderSSlow = false; + + // + CalculateCycleConditions( + barIndex, + conditions.sFast, + conditions.sSlow, + cBar, + pBar, + hhValue, + llValue, + minValue, + minValuePrev, + maxValue, + maxValuePrev, + isSFastOverSlow, + isSFastCrossedOverSlow, + isSFastUnderSlow, + isSFastCrossedUnderSlow, + isSFastOverMax, + isSFastCrossedOverMax, + isSFastUnderMax, + isSFastCrossedUnderMax, + isSFastOverMin, + isSFastCrossedOverMin, + isSFastUnderMin, + isSFastCrossedUnderMin, + isSSlowOverMax, + isSSlowCrossedOverMax, + isSSlowUnderMax, + isSSlowCrossedUnderMax, + isSSlowOverMin, + isSSlowCrossedOverMin, + isSSlowUnderMin, + isSSlowCrossedUnderMin, + isRetestSFastSlow, + isCLoseOverSFast, + isCloseCrossedOverSFast, + isCloseUnderSFast, + isCloseCrossedUnderSFast, + isCloseOverSSlow, + isCloseCrossedOverSSlow, + isCloseUnderSSlow, + isCloseCrossedUnderSSlow + // + ); + + // + // Medium ... + + // + FillCHMAValues( + allValues, + conditions, + XCHMA_ALL_BUT_MEDIUM, + cIndex // + ); + minValue = GetMin(allValues); + maxValue = GetMax(allValues); + + // + FillCHMAValues( + allValues, + conditions, + XCHMA_ALL_BUT_MEDIUM, + pIndex // + ); + minValuePrev = GetMin(allValues); + maxValuePrev = GetMax(allValues); + + // + bool isMFastOverSlow = false; + bool isMFastCrossedOverSlow = false; + bool isMFastUnderSlow = false; + bool isMFastCrossedUnderSlow = false; + bool isMFastOverMax = false; + bool isMFastCrossedOverMax = false; + bool isMFastUnderMax = false; + bool isMFastCrossedUnderMax = false; + bool isMFastOverMin = false; + bool isMFastCrossedOverMin = false; + bool isMFastUnderMin = false; + bool isMFastCrossedUnderMin = false; + bool isMSlowOverMax = false; + bool isMSlowCrossedOverMax = false; + bool isMSlowUnderMax = false; + bool isMSlowCrossedUnderMax = false; + bool isMSlowOverMin = false; + bool isMSlowCrossedOverMin = false; + bool isMSlowUnderMin = false; + bool isMSlowCrossedUnderMin = false; + bool isRetestMFastSlow = false; + bool isCLoseOverMFast = false; + bool isCloseCrossedOverMFast = false; + bool isCloseUnderMFast = false; + bool isCloseCrossedUnderMFast = false; + bool isCloseOverMSlow = false; + bool isCloseCrossedOverMSlow = false; + bool isCloseUnderMSlow = false; + bool isCloseCrossedUnderMSlow = false; + + // + CalculateCycleConditions( + barIndex, + conditions.mFast, + conditions.mSlow, + cBar, + pBar, + hhValue, + llValue, + minValue, + minValuePrev, + maxValue, + maxValuePrev, + isMFastOverSlow, + isMFastCrossedOverSlow, + isMFastUnderSlow, + isMFastCrossedUnderSlow, + isMFastOverMax, + isMFastCrossedOverMax, + isMFastUnderMax, + isMFastCrossedUnderMax, + isMFastOverMin, + isMFastCrossedOverMin, + isMFastUnderMin, + isMFastCrossedUnderMin, + isMSlowOverMax, + isMSlowCrossedOverMax, + isMSlowUnderMax, + isMSlowCrossedUnderMax, + isMSlowOverMin, + isMSlowCrossedOverMin, + isMSlowUnderMin, + isMSlowCrossedUnderMin, + isRetestMFastSlow, + isCLoseOverMFast, + isCloseCrossedOverMFast, + isCloseUnderMFast, + isCloseCrossedUnderMFast, + isCloseOverMSlow, + isCloseCrossedOverMSlow, + isCloseUnderMSlow, + isCloseCrossedUnderMSlow + // + ); + + // + // Long ... + + // + FillCHMAValues( + allValues, + conditions, + XCHMA_ALL_BUT_LONG, + cIndex // + ); + minValue = GetMin(allValues); + maxValue = GetMax(allValues); + + // + FillCHMAValues( + allValues, + conditions, + XCHMA_ALL_BUT_LONG, + pIndex // + ); + minValuePrev = GetMin(allValues); + maxValuePrev = GetMax(allValues); + + // + bool isLFastOverSlow = false; + bool isLFastCrossedOverSlow = false; + bool isLFastUnderSlow = false; + bool isLFastCrossedUnderSlow = false; + bool isLFastOverMax = false; + bool isLFastCrossedOverMax = false; + bool isLFastUnderMax = false; + bool isLFastCrossedUnderMax = false; + bool isLFastOverMin = false; + bool isLFastCrossedOverMin = false; + bool isLFastUnderMin = false; + bool isLFastCrossedUnderMin = false; + bool isLSlowOverMax = false; + bool isLSlowCrossedOverMax = false; + bool isLSlowUnderMax = false; + bool isLSlowCrossedUnderMax = false; + bool isLSlowOverMin = false; + bool isLSlowCrossedOverMin = false; + bool isLSlowUnderMin = false; + bool isLSlowCrossedUnderMin = false; + bool isRetestLFastSlow = false; + bool isCLoseOverLFast = false; + bool isCloseCrossedOverLFast = false; + bool isCloseUnderLFast = false; + bool isCloseCrossedUnderLFast = false; + bool isCloseOverLSlow = false; + bool isCloseCrossedOverLSlow = false; + bool isCloseUnderLSlow = false; + bool isCloseCrossedUnderLSlow = false; + + // + CalculateCycleConditions( + barIndex, + conditions.lFast, + conditions.lSlow, + cBar, + pBar, + hhValue, + llValue, + minValue, + minValuePrev, + maxValue, + maxValuePrev, + isLFastOverSlow, + isLFastCrossedOverSlow, + isLFastUnderSlow, + isLFastCrossedUnderSlow, + isLFastOverMax, + isLFastCrossedOverMax, + isLFastUnderMax, + isLFastCrossedUnderMax, + isLFastOverMin, + isLFastCrossedOverMin, + isLFastUnderMin, + isLFastCrossedUnderMin, + isLSlowOverMax, + isLSlowCrossedOverMax, + isLSlowUnderMax, + isLSlowCrossedUnderMax, + isLSlowOverMin, + isLSlowCrossedOverMin, + isLSlowUnderMin, + isLSlowCrossedUnderMin, + isRetestLFastSlow, + isCLoseOverLFast, + isCloseCrossedOverLFast, + isCloseUnderLFast, + isCloseCrossedUnderLFast, + isCloseOverLSlow, + isCloseCrossedOverLSlow, + isCloseUnderLSlow, + isCloseCrossedUnderLSlow + // + ); + + // + // Hind ... + + // + FillCHMAValues( + allValues, + conditions, + XCHMA_ALL_BUT_HIND, + cIndex // + ); + minValue = GetMin(allValues); + maxValue = GetMax(allValues); + + // + FillCHMAValues( + allValues, + conditions, + XCHMA_ALL_BUT_HIND, + pIndex // + ); + minValuePrev = GetMin(allValues); + maxValuePrev = GetMax(allValues); + + // + bool isHFastOverSlow = false; + bool isHFastCrossedOverSlow = false; + bool isHFastUnderSlow = false; + bool isHFastCrossedUnderSlow = false; + bool isHFastOverMax = false; + bool isHFastCrossedOverMax = false; + bool isHFastUnderMax = false; + bool isHFastCrossedUnderMax = false; + bool isHFastOverMin = false; + bool isHFastCrossedOverMin = false; + bool isHFastUnderMin = false; + bool isHFastCrossedUnderMin = false; + bool isHSlowOverMax = false; + bool isHSlowCrossedOverMax = false; + bool isHSlowUnderMax = false; + bool isHSlowCrossedUnderMax = false; + bool isHSlowOverMin = false; + bool isHSlowCrossedOverMin = false; + bool isHSlowUnderMin = false; + bool isHSlowCrossedUnderMin = false; + bool isRetestHFastSlow = false; + bool isCLoseOverHFast = false; + bool isCloseCrossedOverHFast = false; + bool isCloseUnderHFast = false; + bool isCloseCrossedUnderHFast = false; + bool isCloseOverHSlow = false; + bool isCloseCrossedOverHSlow = false; + bool isCloseUnderHSlow = false; + bool isCloseCrossedUnderHSlow = false; + + // + CalculateCycleConditions( + barIndex, + conditions.hFast, + conditions.hSlow, + cBar, + pBar, + hhValue, + llValue, + minValue, + minValuePrev, + maxValue, + maxValuePrev, + isHFastOverSlow, + isHFastCrossedOverSlow, + isHFastUnderSlow, + isHFastCrossedUnderSlow, + isHFastOverMax, + isHFastCrossedOverMax, + isHFastUnderMax, + isHFastCrossedUnderMax, + isHFastOverMin, + isHFastCrossedOverMin, + isHFastUnderMin, + isHFastCrossedUnderMin, + isHSlowOverMax, + isHSlowCrossedOverMax, + isHSlowUnderMax, + isHSlowCrossedUnderMax, + isHSlowOverMin, + isHSlowCrossedOverMin, + isHSlowUnderMin, + isHSlowCrossedUnderMin, + isRetestHFastSlow, + isCLoseOverHFast, + isCloseCrossedOverHFast, + isCloseUnderHFast, + isCloseCrossedUnderHFast, + isCloseOverHSlow, + isCloseCrossedOverHSlow, + isCloseUnderHSlow, + isCloseCrossedUnderHSlow + // + ); + + // + // Setting Conditions Variables to Conditions Object ... + + // + // AVG ... + conditions.isFastOverSlow = isFastOverSlow; + conditions.isFastUnderSlow = isFastUnderSlow; + conditions.isFastCrossedOverSlow = isFastCrossedOverSlow; + conditions.isFastCrossedUnderSlow = isFastCrossedUnderSlow; + conditions.isCLoseOverFast = isCLoseOverFast; + conditions.isCloseCrossedOverFast = isCloseCrossedOverFast; + conditions.isCloseUnderFast = isCloseUnderFast; + conditions.isCloseCrossedUnderFast = isCloseCrossedUnderFast; + conditions.isCloseOverSlow = isCloseOverSlow; + conditions.isCloseCrossedOverSlow = isCloseCrossedOverSlow; + conditions.isCloseUnderSlow = isCloseUnderSlow; + conditions.isCloseCrossedUnderSlow = isCloseCrossedUnderSlow; + conditions.isRetestFastSlow = isRetestFastSlow; + conditions.isFastOverMax = isFastOverMax; + conditions.isFastUnderMax = isFastUnderMax; + conditions.isFastOverMin = isFastOverMin; + conditions.isFastUnderMin = isFastUnderMin; + conditions.isFastCrossedOverMax = isFastCrossedOverMax; + conditions.isFastCrossedUnderMax = isFastCrossedUnderMax; + conditions.isFastCrossedOverMin = isFastCrossedOverMin; + conditions.isFastCrossedUnderMin = isFastCrossedUnderMin; + conditions.isSlowOverMax = isSlowOverMax; + conditions.isSlowUnderMax = isSlowUnderMax; + conditions.isSlowOverMin = isSlowOverMin; + conditions.isSlowUnderMin = isSlowUnderMin; + conditions.isSlowCrossedOverMax = isSlowCrossedOverMax; + conditions.isSlowCrossedUnderMax = isSlowCrossedUnderMax; + conditions.isSlowCrossedOverMin = isSlowCrossedOverMin; + conditions.isSlowCrossedUnderMin = isSlowCrossedUnderMin; + + // + // Current ... + conditions.isCFastOverSlow = isCFastOverSlow; + conditions.isCFastUnderSlow = isCFastUnderSlow; + conditions.isCFastCrossedOverSlow = isCFastCrossedOverSlow; + conditions.isCFastCrossedUnderSlow = isCFastCrossedUnderSlow; + conditions.isCLoseOverCFast = isCLoseOverCFast; + conditions.isCloseCrossedOverCFast = isCloseCrossedOverCFast; + conditions.isCloseUnderCFast = isCloseUnderCFast; + conditions.isCloseCrossedUnderCFast = isCloseCrossedUnderCFast; + conditions.isCloseOverCSlow = isCloseOverCSlow; + conditions.isCloseCrossedOverCSlow = isCloseCrossedOverCSlow; + conditions.isCloseUnderCSlow = isCloseUnderCSlow; + conditions.isCloseCrossedUnderCSlow = isCloseCrossedUnderCSlow; + conditions.isRetestCFastSlow = isRetestCFastSlow; + conditions.isCFastOverMax = isCFastOverMax; + conditions.isCFastUnderMax = isCFastUnderMax; + conditions.isCFastOverMin = isCFastOverMin; + conditions.isCFastUnderMin = isCFastUnderMin; + conditions.isCFastCrossedOverMax = isCFastCrossedOverMax; + conditions.isCFastCrossedUnderMax = isCFastCrossedUnderMax; + conditions.isCFastCrossedOverMin = isCFastCrossedOverMin; + conditions.isCFastCrossedUnderMin = isCFastCrossedUnderMin; + conditions.isCSlowOverMax = isCSlowOverMax; + conditions.isCSlowUnderMax = isCSlowUnderMax; + conditions.isCSlowOverMin = isCSlowOverMin; + conditions.isCSlowUnderMin = isCSlowUnderMin; + conditions.isCSlowCrossedOverMax = isCSlowCrossedOverMax; + conditions.isCSlowCrossedUnderMax = isCSlowCrossedUnderMax; + conditions.isCSlowCrossedOverMin = isCSlowCrossedOverMin; + conditions.isCSlowCrossedUnderMin = isCSlowCrossedUnderMin; + + // + // Short ... + conditions.isSFastOverSlow = isSFastOverSlow; + conditions.isSFastUnderSlow = isSFastUnderSlow; + conditions.isSFastCrossedOverSlow = isSFastCrossedOverSlow; + conditions.isSFastCrossedUnderSlow = isSFastCrossedUnderSlow; + conditions.isCLoseOverSFast = isCLoseOverSFast; + conditions.isCloseCrossedOverSFast = isCloseCrossedOverSFast; + conditions.isCloseUnderSFast = isCloseUnderSFast; + conditions.isCloseCrossedUnderSFast = isCloseCrossedUnderSFast; + conditions.isCloseOverSSlow = isCloseOverSSlow; + conditions.isCloseCrossedOverSSlow = isCloseCrossedOverSSlow; + conditions.isCloseUnderSSlow = isCloseUnderSSlow; + conditions.isCloseCrossedUnderSSlow = isCloseCrossedUnderSSlow; + conditions.isRetestSFastSlow = isRetestSFastSlow; + conditions.isSFastOverMax = isSFastOverMax; + conditions.isSFastUnderMax = isSFastUnderMax; + conditions.isSFastOverMin = isSFastOverMin; + conditions.isSFastUnderMin = isSFastUnderMin; + conditions.isSFastCrossedOverMax = isSFastCrossedOverMax; + conditions.isSFastCrossedUnderMax = isSFastCrossedUnderMax; + conditions.isSFastCrossedOverMin = isSFastCrossedOverMin; + conditions.isSFastCrossedUnderMin = isSFastCrossedUnderMin; + conditions.isSSlowOverMax = isSSlowOverMax; + conditions.isSSlowUnderMax = isSSlowUnderMax; + conditions.isSSlowOverMin = isSSlowOverMin; + conditions.isSSlowUnderMin = isSSlowUnderMin; + conditions.isSSlowCrossedOverMax = isSSlowCrossedOverMax; + conditions.isSSlowCrossedUnderMax = isSSlowCrossedUnderMax; + conditions.isSSlowCrossedOverMin = isSSlowCrossedOverMin; + conditions.isSSlowCrossedUnderMin = isSSlowCrossedUnderMin; + + // + // Medium ... + conditions.isMFastOverSlow = isMFastOverSlow; + conditions.isMFastUnderSlow = isMFastUnderSlow; + conditions.isMFastCrossedOverSlow = isMFastCrossedOverSlow; + conditions.isMFastCrossedUnderSlow = isMFastCrossedUnderSlow; + conditions.isCLoseOverMFast = isCLoseOverMFast; + conditions.isCloseCrossedOverMFast = isCloseCrossedOverMFast; + conditions.isCloseUnderMFast = isCloseUnderMFast; + conditions.isCloseCrossedUnderMFast = isCloseCrossedUnderMFast; + conditions.isCloseOverMSlow = isCloseOverMSlow; + conditions.isCloseCrossedOverMSlow = isCloseCrossedOverMSlow; + conditions.isCloseUnderMSlow = isCloseUnderMSlow; + conditions.isCloseCrossedUnderMSlow = isCloseCrossedUnderMSlow; + conditions.isRetestMFastSlow = isRetestMFastSlow; + conditions.isMFastOverMax = isMFastOverMax; + conditions.isMFastUnderMax = isMFastUnderMax; + conditions.isMFastOverMin = isMFastOverMin; + conditions.isMFastUnderMin = isMFastUnderMin; + conditions.isMFastCrossedOverMax = isMFastCrossedOverMax; + conditions.isMFastCrossedUnderMax = isMFastCrossedUnderMax; + conditions.isMFastCrossedOverMin = isMFastCrossedOverMin; + conditions.isMFastCrossedUnderMin = isMFastCrossedUnderMin; + conditions.isMSlowOverMax = isMSlowOverMax; + conditions.isMSlowUnderMax = isMSlowUnderMax; + conditions.isMSlowOverMin = isMSlowOverMin; + conditions.isMSlowUnderMin = isMSlowUnderMin; + conditions.isMSlowCrossedOverMax = isMSlowCrossedOverMax; + conditions.isMSlowCrossedUnderMax = isMSlowCrossedUnderMax; + conditions.isMSlowCrossedOverMin = isMSlowCrossedOverMin; + conditions.isMSlowCrossedUnderMin = isMSlowCrossedUnderMin; + + // + // Long ... + conditions.isLFastOverSlow = isLFastOverSlow; + conditions.isLFastUnderSlow = isLFastUnderSlow; + conditions.isLFastCrossedOverSlow = isLFastCrossedOverSlow; + conditions.isLFastCrossedUnderSlow = isLFastCrossedUnderSlow; + conditions.isCLoseOverLFast = isCLoseOverLFast; + conditions.isCloseCrossedOverLFast = isCloseCrossedOverLFast; + conditions.isCloseUnderLFast = isCloseUnderLFast; + conditions.isCloseCrossedUnderLFast = isCloseCrossedUnderLFast; + conditions.isCloseOverLSlow = isCloseOverLSlow; + conditions.isCloseCrossedOverLSlow = isCloseCrossedOverLSlow; + conditions.isCloseUnderLSlow = isCloseUnderLSlow; + conditions.isCloseCrossedUnderLSlow = isCloseCrossedUnderLSlow; + conditions.isRetestLFastSlow = isRetestLFastSlow; + conditions.isLFastOverMax = isLFastOverMax; + conditions.isLFastUnderMax = isLFastUnderMax; + conditions.isLFastOverMin = isLFastOverMin; + conditions.isLFastUnderMin = isLFastUnderMin; + conditions.isLFastCrossedOverMax = isLFastCrossedOverMax; + conditions.isLFastCrossedUnderMax = isLFastCrossedUnderMax; + conditions.isLFastCrossedOverMin = isLFastCrossedOverMin; + conditions.isLFastCrossedUnderMin = isLFastCrossedUnderMin; + conditions.isLSlowOverMax = isLSlowOverMax; + conditions.isLSlowUnderMax = isLSlowUnderMax; + conditions.isLSlowOverMin = isLSlowOverMin; + conditions.isLSlowUnderMin = isLSlowUnderMin; + conditions.isLSlowCrossedOverMax = isLSlowCrossedOverMax; + conditions.isLSlowCrossedUnderMax = isLSlowCrossedUnderMax; + conditions.isLSlowCrossedOverMin = isLSlowCrossedOverMin; + conditions.isLSlowCrossedUnderMin = isLSlowCrossedUnderMin; + + // + // Hind ... + conditions.isHFastOverSlow = isHFastOverSlow; + conditions.isHFastUnderSlow = isHFastUnderSlow; + conditions.isHFastCrossedOverSlow = isHFastCrossedOverSlow; + conditions.isHFastCrossedUnderSlow = isHFastCrossedUnderSlow; + conditions.isCLoseOverHFast = isCLoseOverHFast; + conditions.isCloseCrossedOverHFast = isCloseCrossedOverHFast; + conditions.isCloseUnderHFast = isCloseUnderHFast; + conditions.isCloseCrossedUnderHFast = isCloseCrossedUnderHFast; + conditions.isCloseOverHSlow = isCloseOverHSlow; + conditions.isCloseCrossedOverHSlow = isCloseCrossedOverHSlow; + conditions.isCloseUnderHSlow = isCloseUnderHSlow; + conditions.isCloseCrossedUnderHSlow = isCloseCrossedUnderHSlow; + conditions.isRetestHFastSlow = isRetestHFastSlow; + conditions.isHFastOverMax = isHFastOverMax; + conditions.isHFastUnderMax = isHFastUnderMax; + conditions.isHFastOverMin = isHFastOverMin; + conditions.isHFastUnderMin = isHFastUnderMin; + conditions.isHFastCrossedOverMax = isHFastCrossedOverMax; + conditions.isHFastCrossedUnderMax = isHFastCrossedUnderMax; + conditions.isHFastCrossedOverMin = isHFastCrossedOverMin; + conditions.isHFastCrossedUnderMin = isHFastCrossedUnderMin; + conditions.isHSlowOverMax = isHSlowOverMax; + conditions.isHSlowUnderMax = isHSlowUnderMax; + conditions.isHSlowOverMin = isHSlowOverMin; + conditions.isHSlowUnderMin = isHSlowUnderMin; + conditions.isHSlowCrossedOverMax = isHSlowCrossedOverMax; + conditions.isHSlowCrossedUnderMax = isHSlowCrossedUnderMax; + conditions.isHSlowCrossedOverMin = isHSlowCrossedOverMin; + conditions.isHSlowCrossedUnderMin = isHSlowCrossedUnderMin; + + // + return result; + } + + // + // Protected ... +protected: + // + // Private ... +private: + // + // Props ... + XCHMAInputs mInputs; // Inputs ... + + // + // Buffers ... + + // + // AVG ... + double fastBuffer[]; + double slowBuffer[]; + + // + // Current ... + double cFastBuffer[]; + double cSlowBuffer[]; + + // + // Short ... + double sFastBuffer[]; + double sSlowBuffer[]; + + // + // Medium ... + double mFastBuffer[]; + double mSlowBuffer[]; + + // + // Long ... + double lFastBuffer[]; + double lSlowBuffer[]; + + // + // Hind ... + double hFastBuffer[]; + double hSlowBuffer[]; + + // + // Tools ... + + // + // Calculate Values Until Now ... + void Calculate() + { + // + int totalBars = CountBars(); + if (totalBars > 1000) + { + totalBars = 1000; + } + + // + // Fast ... + CopyBuffer( + mHandler, + XCHMA_FAST_LINE, + 0, + totalBars, + fastBuffer + // + ); + + // + // Slow ... + CopyBuffer( + mHandler, + XCHMA_SLOW_LINE, + 0, + totalBars, + slowBuffer + // + ); + + // + // Current ... + + // + // Fast ... + CopyBuffer( + mHandler, + XCHMA_CFAST_LINE, + 0, + totalBars, + cFastBuffer + // + ); + + // + // Slow ... + CopyBuffer( + mHandler, + XCHMA_CSLOW_LINE, + 0, + totalBars, + cSlowBuffer + // + ); + + // + // Short ... + + // + // Fast ... + CopyBuffer( + mHandler, + XCHMA_SFAST_LINE, + 0, + totalBars, + sFastBuffer + // + ); + + // + // Slow ... + CopyBuffer( + mHandler, + XCHMA_SSLOW_LINE, + 0, + totalBars, + sSlowBuffer + // + ); + + // + // Medium ... + + // + // Fast ... + CopyBuffer( + mHandler, + XCHMA_MFAST_LINE, + 0, + totalBars, + mFastBuffer + // + ); + + // + // Slow ... + CopyBuffer( + mHandler, + XCHMA_MSLOW_LINE, + 0, + totalBars, + mSlowBuffer + // + ); + + // + // Long ... + + // + // Fast ... + CopyBuffer( + mHandler, + XCHMA_LFAST_LINE, + 0, + totalBars, + lFastBuffer + // + ); + + // + // Slow ... + CopyBuffer( + mHandler, + XCHMA_LSLOW_LINE, + 0, + totalBars, + lSlowBuffer + // + ); + + // + // Hind ... + + // + // Fast ... + CopyBuffer( + mHandler, + XCHMA_HFAST_LINE, + 0, + totalBars, + hFastBuffer + // + ); + + // + // Slow ... + CopyBuffer( + mHandler, + XCHMA_HSLOW_LINE, + 0, + totalBars, + hSlowBuffer + // + ); + } +}; + +// \ No newline at end of file diff --git a/Indicators/x-saherelm.xchma.mq5 b/Indicators/x-saherelm.xchma.mq5 new file mode 100644 index 00000000..85a9f071 --- /dev/null +++ b/Indicators/x-saherelm.xchma.mq5 @@ -0,0 +1,1086 @@ +/////////////////////////////////////////////////////// +// SaherElm IT Center MQL5 Indicator +// ------------------------------------------- +// Name: XCHMA +// Description: XCHMArend Detector ... +// +// Maintainer: +// ------------ +// Hadi Khazaee Asl (hadi_khazaee_asl@yahoo.com) +// +////////////////////////////////////////////////////// +// +// Global Properties ... +#property copyright "Copyright 2023, SaherElm IT Center" +#property link "https://saherelm.ir" +#property version "1.00" +#property description "SaherElm XCHMA Indicator" +#property strict + +// +#define ShortName "XCHMA" + +// +// Includes Common Library ... +#include "../Libraries/x-saherelm.common.lib.mq5" + +// +// Inputs ... + +// +// Market ... +input group "Market"; +input int fastLength = 9; // Fast Length +input int slowLength = 18; // Slow Length +input ENUM_MA_METHOD method = MODE_EMA; // Mode +input ENUM_APPLIED_PRICE appliedTo = PRICE_CLOSE; // Applied To + +// +input group "Cycles"; + +// +input group "Short"; +input ENUM_X_PERIOD_METHOD scMethod = X_PERIOD_AUTO; // How to Find Period +input ENUM_TIMEFRAMES scPeriod = NULL; // Time Period + +// +input group "Medium"; +input ENUM_X_PERIOD_METHOD mcMethod = X_PERIOD_AUTO; // How to Find Period +input ENUM_TIMEFRAMES mcPeriod = NULL; // Time Period + +// +input group "Long"; +input ENUM_X_PERIOD_METHOD lcMethod = X_PERIOD_AUTO; // How to Find Period +input ENUM_TIMEFRAMES lcPeriod = NULL; // Time Period + +// +input group "Hind"; +input ENUM_X_PERIOD_METHOD hcMethod = X_PERIOD_AUTO; // How to Find Period +input ENUM_TIMEFRAMES hcPeriod = NULL; // Time Period + +// +// Presentation ... +input group "Presentation"; + +// +// AVG ... +input bool showFast = true; // Show Fast +input bool showSlow = true; // Show Slow + +// +// Current ... +input bool showCCFast = true; // Show Current Cycle Fast +input bool showCCSlow = true; // Show Current Cycle Slow +// +// Short ... +input bool showSCFast = true; // Show Short Cycle Fast +input bool showSCSlow = true; // Show Short Cycle Slow +// +// Medium ... +input bool showMCFast = true; // Show Medium Cycle Fast +input bool showMCSlow = true; // Show Medium Cycle Slow +// +// Long ... +input bool showLCFast = true; // Show Long Cycle Fast +input bool showLCSlow = true; // Show Long Cycle Slow +// +// Hind ... +input bool showHCFast = true; // Show Hind Cycle Fast +input bool showHCSlow = true; // Show Hind Cycle Slow + +// +// Buffers ... + +// +#property indicator_chart_window + +// +#property indicator_buffers 12 +#property indicator_plots 12 + +// +// AVG ... + +// +// Fast ... +#define avgFastBufferIndex 0 +double avgFastBuffer[]; + +// +#property indicator_label1 "XCHMA AF" +#property indicator_type1 DRAW_LINE +#property indicator_color1 clrGreen +#property indicator_style1 STYLE_SOLID +#property indicator_width1 1 + +// +// Slow ... +#define avgSlowBufferIndex 1 +double avgSlowBuffer[]; + +// +#property indicator_label2 "XCHMA AS" +#property indicator_type2 DRAW_LINE +#property indicator_color2 clrRed +#property indicator_style2 STYLE_SOLID +#property indicator_width2 1 + +// +// Current ... + +// +// Fast ... +#define cFastBufferIndex 2 +double cFastBuffer[]; + +// +#property indicator_label3 "XCHMA CF" +#property indicator_type3 DRAW_LINE +#property indicator_color3 clrAqua +#property indicator_style3 STYLE_DOT +#property indicator_width3 1 + +// +// Slow ... +#define cSlowBufferIndex 3 +double cSlowBuffer[]; + +// +#property indicator_label4 "XCHMA CS" +#property indicator_type4 DRAW_LINE +#property indicator_color4 clrMagenta +#property indicator_style4 STYLE_DOT +#property indicator_width4 1 + +// +// Short ... + +// +// Fast ... +#define sFastBufferIndex 4 +double sFastBuffer[]; + +// +#property indicator_label5 "XCHMA SF" +#property indicator_type5 DRAW_LINE +#property indicator_color5 clrAqua +#property indicator_style5 STYLE_DOT +#property indicator_width5 1 + +// +// Slow ... +#define sSlowBufferIndex 5 +double sSlowBuffer[]; + +// +#property indicator_label6 "XCHMA SS" +#property indicator_type6 DRAW_LINE +#property indicator_color6 clrMagenta +#property indicator_style6 STYLE_DOT +#property indicator_width6 1 + +// +// Medium ... + +// +// Fast ... +#define mFastBufferIndex 6 +double mFastBuffer[]; + +// +#property indicator_label7 "XCHMA MF" +#property indicator_type7 DRAW_LINE +#property indicator_color7 clrAqua +#property indicator_style7 STYLE_DOT +#property indicator_width7 1 + +// +// Slow ... +#define mSlowBufferIndex 7 +double mSlowBuffer[]; + +// +#property indicator_label8 "XCHMA MS" +#property indicator_type8 DRAW_LINE +#property indicator_color8 clrMagenta +#property indicator_style8 STYLE_DOT +#property indicator_width8 1 + +// +// Long ... + +// +// Fast ... +#define lFastBufferIndex 8 +double lFastBuffer[]; + +// +#property indicator_label9 "XCHMA LF" +#property indicator_type9 DRAW_LINE +#property indicator_color9 clrAqua +#property indicator_style9 STYLE_DOT +#property indicator_width9 1 + +// +// Slow ... +#define lSlowBufferIndex 9 +double lSlowBuffer[]; + +// +#property indicator_label10 "XCHMA LS" +#property indicator_type10 DRAW_LINE +#property indicator_color10 clrMagenta +#property indicator_style10 STYLE_DOT +#property indicator_width10 1 + +// +// Hind ... + +// +// Fast ... +#define hFastBufferIndex 10 +double hFastBuffer[]; + +// +#property indicator_label11 "XCHMA HF" +#property indicator_type11 DRAW_LINE +#property indicator_color11 clrAqua +#property indicator_style11 STYLE_DOT +#property indicator_width11 1 + +// +// Slow ... +#define hSlowBufferIndex 11 +double hSlowBuffer[]; + +// +#property indicator_label12 "XCHMA HS" +#property indicator_type12 DRAW_LINE +#property indicator_color12 clrMagenta +#property indicator_style12 STYLE_DOT +#property indicator_width12 1 + +// +// Variables ... + +// +int maxLength; + +// +// Current ... +int cFastHandler = INVALID_HANDLE; +int cSlowHandler = INVALID_HANDLE; + +// +// Short ... +int mSCLength = 0; +int mSCFastLength = 0; +int mSCSlowLength = 0; +ENUM_TIMEFRAMES mSCPeriod = NULL; +int sFastHandler = INVALID_HANDLE; +int sSlowHandler = INVALID_HANDLE; + +// +// Medium ... +int mMCLength = 0; +int mMCFastLength = 0; +int mMCSlowLength = 0; +ENUM_TIMEFRAMES mMCPeriod = NULL; +int mFastHandler = INVALID_HANDLE; +int mSlowHandler = INVALID_HANDLE; + +// +// Long ... +int mLCLength = 0; +int mLCFastLength = 0; +int mLCSlowLength = 0; +ENUM_TIMEFRAMES mLCPeriod = NULL; +int lFastHandler = INVALID_HANDLE; +int lSlowHandler = INVALID_HANDLE; + +// +// Hind ... +int mHCLength = 0; +int mHCFastLength = 0; +int mHCSlowLength = 0; +ENUM_TIMEFRAMES mHCPeriod = NULL; +int hFastHandler = INVALID_HANDLE; +int hSlowHandler = INVALID_HANDLE; + +// +// EVENT Handlers ... + +// +// Initialization ... +int OnInit() +{ + // + // Validate Inputs ... + if (!ValidateInputs()) + { + return INIT_PARAMETERS_INCORRECT; + } + + // + if (!InitMarketCycles()) + { + return INIT_PARAMETERS_INCORRECT; + } + + // + // because in some cases we may have more than one input for + // calculation and we must prevent any calculation + // untill we pass the biggest input length, here we get max Input length + // and then wait until pass it ... + maxLength = ExtractMaxLengthOfInputs(); + + // + // Define Index Buffers ... + DefineBuffers(); + + // + // Set Indicator ShortName ... + SetIndicatorName(); + + // + // Init Succeed ... + return INIT_SUCCEEDED; +} + +// +// DeInitialization ... +void OnDeinit(const int reason) +{ + // + // REASON_PROGRAM 0 The EA has stopped working calling the ExpertRemove() function + // REASON_REMOVE 1 Program removed from a chart + // REASON_RECOMPILE 2 Program recompiled + // REASON_CHARTCHANGE 3 A symbol or a chart period is changed + // REASON_CHARTCLOSE 4 Chart closed + // REASON_PARAMETERS 5 Inputs changed by a user + // REASON_ACCOUNT 6 Another account has been activated or reconnection to the trade server has occurred due to changes in the account settings + // REASON_TEMPLATE 7 Another chart template applied + // REASON_INITFAILED 8 The OnInit() handler returned a non-zero value + // REASON_CLOSE 9 Terminal closed + + // + // Current ... + IndicatorRelease(cFastHandler); + IndicatorRelease(cSlowHandler); + + // + // Short ... + IndicatorRelease(sFastHandler); + IndicatorRelease(sSlowHandler); + + // + // Medium ... + IndicatorRelease(mFastHandler); + IndicatorRelease(mSlowHandler); + + // + // Long ... + IndicatorRelease(lFastHandler); + IndicatorRelease(lSlowHandler); + + // + // Hind ... + IndicatorRelease(hFastHandler); + IndicatorRelease(hSlowHandler); +} + +// +// Calculating what we want ... +int OnCalculate( + const int rates_total, // Total Bars on Chart ... + const int prev_calculated, // Total Calculated Bars on Charts ... + const datetime &time[], // History of Open Time ... + const double &open[], // History of Open Price ... + const double &high[], // History of High Price ... + const double &low[], // History of Low Price ... + const double &close[], // History of Close Price ... + const long &tick_volume[], // History of Tick Volumes on Bar ... + const long &volume[], // History of Trade Volumes ... + const int &spread[] // History of Spread Price ... +) +{ + // + ArraySetAsSeries(low, true); + ArraySetAsSeries(open, true); + ArraySetAsSeries(high, true); + ArraySetAsSeries(close, true); + + // + // this counts Available Bars ... + int limit; + + // + // Validate Calculated Bars ... + bool isPassedRequiredCalculatedBars = + // + // Current ... + BarsCalculated(cFastHandler) >= maxLength && + BarsCalculated(cSlowHandler) >= maxLength && + // + // Short ... + BarsCalculated(sFastHandler) >= maxLength && + BarsCalculated(sSlowHandler) >= maxLength && + // + // Medium ... + BarsCalculated(mFastHandler) >= maxLength && + BarsCalculated(mSlowHandler) >= maxLength && + // + // Long ... + BarsCalculated(lFastHandler) >= maxLength && + BarsCalculated(lSlowHandler) >= maxLength && + // + // Hind ... + BarsCalculated(hFastHandler) >= maxLength && + BarsCalculated(hSlowHandler) >= maxLength + // + ; + if (!isPassedRequiredCalculatedBars) + { + return prev_calculated; + } + + // + limit = + (prev_calculated > rates_total || prev_calculated <= 0) + ? rates_total + : (rates_total - prev_calculated) + 1; + + // + // Buffers Copy ... + + // + // Current ... + int copiedCFasts = CopyBuffer(cFastHandler, 0, 0, limit, cFastBuffer); + int copiedCSlows = CopyBuffer(cSlowHandler, 0, 0, limit, cSlowBuffer); + + // + // Short ... + int copiedSFasts = CopyBuffer(sFastHandler, 0, 0, limit, sFastBuffer); + int copiedSSlows = CopyBuffer(sSlowHandler, 0, 0, limit, sSlowBuffer); + + // + // Medium ... + int copiedMFasts = CopyBuffer(mFastHandler, 0, 0, limit, mFastBuffer); + int copiedMSlows = CopyBuffer(mSlowHandler, 0, 0, limit, mSlowBuffer); + + // + // Long ... + int copiedLFasts = CopyBuffer(lFastHandler, 0, 0, limit, lFastBuffer); + int copiedLSlows = CopyBuffer(lSlowHandler, 0, 0, limit, lSlowBuffer); + + // + // Hind ... + int copiedHFasts = CopyBuffer(hFastHandler, 0, 0, limit, hFastBuffer); + int copiedHSlows = CopyBuffer(hSlowHandler, 0, 0, limit, hSlowBuffer); + + // + // Validate Copied Items ... + bool isPassedRequiredCopiedItems = + // + // + // Current ... + copiedCFasts > 0 && + copiedCSlows > 0 && + // + // Short ... + copiedSFasts > 0 && + copiedSSlows > 0 && + // + // Medium ... + copiedMFasts > 0 && + copiedMSlows > 0 && + // + // Long ... + copiedLFasts > 0 && + copiedLSlows > 0 && + // + // Hind ... + copiedHFasts > 0 && + copiedHSlows > 0 + // + ; + if (!isPassedRequiredCopiedItems) + { + return prev_calculated; + } + + // + // Main Loop ... + for (int i = limit - 1; i >= 0 && !IsStopped(); i--) + { + CalculateBuffers(i); + } + + // + return rates_total; +} + +// +// CUSTOM Functions ... + +// +// Validate Input Args for Initialization ... +bool ValidateInputs() +{ + // + bool result = + // + fastLength > 2 && + slowLength > fastLength && + // + (IsValid(scMethod, scPeriod) && + IsValid(mcMethod, mcPeriod) && + IsValid(lcMethod, lcPeriod) && + IsValid(hcMethod, hcPeriod)) + // + ; + + // + return result; +} + +// +// Retrieve all Exists Input Max Length ... +// use for Start Of Drawing ... +int ExtractMaxLengthOfInputs() +{ + // + int result = 0; + + // + // Current ... + result = MathMax(fastLength, slowLength); + + // + // Short ... + result = MathMax(result, mSCFastLength); + result = MathMax(result, mSCSlowLength); + + // + // Medium ... + result = MathMax(result, mMCFastLength); + result = MathMax(result, mMCSlowLength); + + // + // Long ... + result = MathMax(result, mLCFastLength); + result = MathMax(result, mLCSlowLength); + + // + // Hind ... + result = MathMax(result, mHCFastLength); + result = MathMax(result, mHCSlowLength); + + // + return result; +} + +// +// Set Indicator Short Name and also we can define Buffers Labels ... +void SetIndicatorName() +{ + // + IndicatorSetInteger(INDICATOR_DIGITS, _Digits); + IndicatorSetString(INDICATOR_SHORTNAME, ShortName); +} + +// +// Define Indexes and Styles ... +void DefineBuffers() +{ + // + // AVG ... + + // + // Fast ... + ENUM_DRAW_TYPE avgFastDrawType = showFast ? DRAW_LINE : DRAW_NONE; + ArraySetAsSeries(avgFastBuffer, true); + SetIndexBuffer(avgFastBufferIndex, avgFastBuffer, INDICATOR_DATA); + PlotIndexSetDouble(avgFastBufferIndex, PLOT_EMPTY_VALUE, 0); + PlotIndexSetInteger(avgFastBufferIndex, PLOT_DRAW_BEGIN, maxLength); + PlotIndexSetInteger(avgFastBufferIndex, PLOT_SHOW_DATA, showFast); + PlotIndexSetInteger(avgFastBufferIndex, PLOT_DRAW_TYPE, avgFastDrawType); + + // + // Slow ... + ENUM_DRAW_TYPE avgSlowDrawType = showSlow ? DRAW_LINE : DRAW_NONE; + ArraySetAsSeries(avgSlowBuffer, true); + SetIndexBuffer(avgSlowBufferIndex, avgSlowBuffer, INDICATOR_DATA); + PlotIndexSetDouble(avgSlowBufferIndex, PLOT_EMPTY_VALUE, 0); + PlotIndexSetInteger(avgSlowBufferIndex, PLOT_DRAW_BEGIN, maxLength); + PlotIndexSetInteger(avgSlowBufferIndex, PLOT_SHOW_DATA, showSlow); + PlotIndexSetInteger(avgSlowBufferIndex, PLOT_DRAW_TYPE, avgSlowDrawType); + + // + // Current ... + + // + // Fast ... + ENUM_DRAW_TYPE cFastDrawType = showCCFast ? DRAW_LINE : DRAW_NONE; + ArraySetAsSeries(cFastBuffer, true); + SetIndexBuffer(cFastBufferIndex, cFastBuffer, INDICATOR_DATA); + PlotIndexSetDouble(cFastBufferIndex, PLOT_EMPTY_VALUE, 0); + PlotIndexSetInteger(cFastBufferIndex, PLOT_DRAW_BEGIN, maxLength); + PlotIndexSetInteger(cFastBufferIndex, PLOT_SHOW_DATA, showCCFast); + PlotIndexSetInteger(cFastBufferIndex, PLOT_DRAW_TYPE, cFastDrawType); + + // + // Slow ... + ENUM_DRAW_TYPE cSlowDrawType = showCCSlow ? DRAW_LINE : DRAW_NONE; + ArraySetAsSeries(cSlowBuffer, true); + SetIndexBuffer(cSlowBufferIndex, cSlowBuffer, INDICATOR_DATA); + PlotIndexSetDouble(cSlowBufferIndex, PLOT_EMPTY_VALUE, 0); + PlotIndexSetInteger(cSlowBufferIndex, PLOT_DRAW_BEGIN, maxLength); + PlotIndexSetInteger(cSlowBufferIndex, PLOT_SHOW_DATA, showCCSlow); + PlotIndexSetInteger(cSlowBufferIndex, PLOT_DRAW_TYPE, cSlowDrawType); + + // + // Short ... + + // + // Fast ... + ENUM_DRAW_TYPE sFastDrawType = showSCFast ? DRAW_LINE : DRAW_NONE; + ArraySetAsSeries(sFastBuffer, true); + SetIndexBuffer(sFastBufferIndex, sFastBuffer, INDICATOR_DATA); + PlotIndexSetDouble(sFastBufferIndex, PLOT_EMPTY_VALUE, 0); + PlotIndexSetInteger(sFastBufferIndex, PLOT_DRAW_BEGIN, maxLength); + PlotIndexSetInteger(sFastBufferIndex, PLOT_SHOW_DATA, showSCFast); + PlotIndexSetInteger(sFastBufferIndex, PLOT_DRAW_TYPE, sFastDrawType); + + // + // Slow ... + ENUM_DRAW_TYPE sSlowDrawType = showSCSlow ? DRAW_LINE : DRAW_NONE; + ArraySetAsSeries(sSlowBuffer, true); + SetIndexBuffer(sSlowBufferIndex, sSlowBuffer, INDICATOR_DATA); + PlotIndexSetDouble(sSlowBufferIndex, PLOT_EMPTY_VALUE, 0); + PlotIndexSetInteger(sSlowBufferIndex, PLOT_DRAW_BEGIN, maxLength); + PlotIndexSetInteger(sSlowBufferIndex, PLOT_SHOW_DATA, showSCSlow); + PlotIndexSetInteger(sSlowBufferIndex, PLOT_DRAW_TYPE, sSlowDrawType); + + // + // Medium ... + + // + // Fast ... + ENUM_DRAW_TYPE mFastDrawType = showMCFast ? DRAW_LINE : DRAW_NONE; + ArraySetAsSeries(mFastBuffer, true); + SetIndexBuffer(mFastBufferIndex, mFastBuffer, INDICATOR_DATA); + PlotIndexSetDouble(mFastBufferIndex, PLOT_EMPTY_VALUE, 0); + PlotIndexSetInteger(mFastBufferIndex, PLOT_DRAW_BEGIN, maxLength); + PlotIndexSetInteger(mFastBufferIndex, PLOT_SHOW_DATA, showMCFast); + PlotIndexSetInteger(mFastBufferIndex, PLOT_DRAW_TYPE, mFastDrawType); + + // + // Slow ... + ENUM_DRAW_TYPE mSlowDrawType = showMCSlow ? DRAW_LINE : DRAW_NONE; + ArraySetAsSeries(mSlowBuffer, true); + SetIndexBuffer(mSlowBufferIndex, mSlowBuffer, INDICATOR_DATA); + PlotIndexSetDouble(mSlowBufferIndex, PLOT_EMPTY_VALUE, 0); + PlotIndexSetInteger(mSlowBufferIndex, PLOT_DRAW_BEGIN, maxLength); + PlotIndexSetInteger(mSlowBufferIndex, PLOT_SHOW_DATA, showMCSlow); + PlotIndexSetInteger(mSlowBufferIndex, PLOT_DRAW_TYPE, mSlowDrawType); + + // + // Long ... + + // + // Fast ... + ENUM_DRAW_TYPE lFastDrawType = showLCFast ? DRAW_LINE : DRAW_NONE; + ArraySetAsSeries(lFastBuffer, true); + SetIndexBuffer(lFastBufferIndex, lFastBuffer, INDICATOR_DATA); + PlotIndexSetDouble(lFastBufferIndex, PLOT_EMPTY_VALUE, 0); + PlotIndexSetInteger(lFastBufferIndex, PLOT_DRAW_BEGIN, maxLength); + PlotIndexSetInteger(lFastBufferIndex, PLOT_SHOW_DATA, showLCFast); + PlotIndexSetInteger(lFastBufferIndex, PLOT_DRAW_TYPE, lFastDrawType); + + // + // Slow ... + ENUM_DRAW_TYPE lSlowDrawType = showLCSlow ? DRAW_LINE : DRAW_NONE; + ArraySetAsSeries(lSlowBuffer, true); + SetIndexBuffer(lSlowBufferIndex, lSlowBuffer, INDICATOR_DATA); + PlotIndexSetDouble(lSlowBufferIndex, PLOT_EMPTY_VALUE, 0); + PlotIndexSetInteger(lSlowBufferIndex, PLOT_DRAW_BEGIN, maxLength); + PlotIndexSetInteger(lSlowBufferIndex, PLOT_SHOW_DATA, showLCSlow); + PlotIndexSetInteger(lSlowBufferIndex, PLOT_DRAW_TYPE, lSlowDrawType); + + // + // Hind ... + + // + // Fast ... + ENUM_DRAW_TYPE hFastDrawType = showHCFast ? DRAW_LINE : DRAW_NONE; + ArraySetAsSeries(hFastBuffer, true); + SetIndexBuffer(hFastBufferIndex, hFastBuffer, INDICATOR_DATA); + PlotIndexSetDouble(hFastBufferIndex, PLOT_EMPTY_VALUE, 0); + PlotIndexSetInteger(hFastBufferIndex, PLOT_DRAW_BEGIN, maxLength); + PlotIndexSetInteger(hFastBufferIndex, PLOT_SHOW_DATA, showHCFast); + PlotIndexSetInteger(hFastBufferIndex, PLOT_DRAW_TYPE, hFastDrawType); + + // + // Slow ... + ENUM_DRAW_TYPE hSlowDrawType = showHCSlow ? DRAW_LINE : DRAW_NONE; + ArraySetAsSeries(hSlowBuffer, true); + SetIndexBuffer(hSlowBufferIndex, hSlowBuffer, INDICATOR_DATA); + PlotIndexSetDouble(hSlowBufferIndex, PLOT_EMPTY_VALUE, 0); + PlotIndexSetInteger(hSlowBufferIndex, PLOT_DRAW_BEGIN, maxLength); + PlotIndexSetInteger(hSlowBufferIndex, PLOT_SHOW_DATA, showHCSlow); + PlotIndexSetInteger(hSlowBufferIndex, PLOT_DRAW_TYPE, hSlowDrawType); +} + +// +// Initial Market Cycles ... +bool InitMarketCycles() +{ + // + bool result = false; + + // + // Current Cycle Initialization ... + + // + int cPeriodSeconds = PeriodSeconds(_Period); + + // + // Initialize Handlers ... + cFastHandler = iMA( + _Symbol, + _Period, + fastLength, + 0, + method, + appliedTo // + ); + cSlowHandler = iMA( + _Symbol, + _Period, + slowLength, + 0, + method, + appliedTo // + ); + result = + // + cFastHandler != INVALID_HANDLE && + cSlowHandler != INVALID_HANDLE + // + ; + if (!result) + { + return result; + } + + // + // Short Cycle Initialization ... + + // + // Find Cycle Period ... + if (scMethod == X_PERIOD_AUTO) + { + // + // Select Period ... + mSCPeriod = GetCyclePeriod( + X_MARKET_CYCLE_SHORT, + _Period // + ); + } + else + { + mSCPeriod = scPeriod; + } + + // + result = IsValid(mSCPeriod); + if (!result) + { + return result; + } + + // + mSCLength = PeriodSeconds(mSCPeriod) / cPeriodSeconds; + mSCFastLength = fastLength * mSCLength; + mSCSlowLength = slowLength * mSCLength; + + // + result = mSCLength > 0; + if (!result) + { + return result; + } + + // + // Initialize Handlers ... + sFastHandler = iMA( + _Symbol, + _Period, + mSCFastLength, + 0, + method, + appliedTo // + ); + sSlowHandler = iMA( + _Symbol, + _Period, + mSCSlowLength, + 0, + method, + appliedTo // + ); + result = + // + sFastHandler != INVALID_HANDLE && + sSlowHandler != INVALID_HANDLE + // + ; + if (!result) + { + return result; + } + + // + // Medium Cycle Initialization ... + + // + // Find Cycle Period ... + if (mcMethod == X_PERIOD_AUTO) + { + // + // Select Period ... + mMCPeriod = GetCyclePeriod( + X_MARKET_CYCLE_MEDIUM, + _Period // + ); + } + else + { + mMCPeriod = mcPeriod; + } + + // + result = IsValid(mMCPeriod); + if (!result) + { + return result; + } + + // + mMCLength = PeriodSeconds(mMCPeriod) / cPeriodSeconds; + mMCFastLength = fastLength * mMCLength; + mMCSlowLength = slowLength * mMCLength; + + // + result = mMCLength > 0; + if (!result) + { + return result; + } + + // + // Initialize Handlers ... + mFastHandler = iMA( + _Symbol, + _Period, + mMCFastLength, + 0, + method, + appliedTo // + ); + mSlowHandler = iMA( + _Symbol, + _Period, + mMCSlowLength, + 0, + method, + appliedTo // + ); + result = + // + mFastHandler != INVALID_HANDLE && + mSlowHandler != INVALID_HANDLE + // + ; + if (!result) + { + return result; + } + + // + // Long Cycle Initialization ... + + // + // Find Cycle Period ... + if (lcMethod == X_PERIOD_AUTO) + { + // + // Select Period ... + mLCPeriod = GetCyclePeriod( + X_MARKET_CYCLE_LONG, + _Period // + ); + } + else + { + mLCPeriod = lcPeriod; + } + + // + result = IsValid(mLCPeriod); + if (!result) + { + return result; + } + + // + mLCLength = PeriodSeconds(mLCPeriod) / cPeriodSeconds; + mLCFastLength = fastLength * mLCLength; + mLCSlowLength = slowLength * mLCLength; + + // + result = mLCLength > 0; + if (!result) + { + return result; + } + + // + // Initialize Handlers ... + lFastHandler = iMA( + _Symbol, + _Period, + mLCFastLength, + 0, + method, + appliedTo // + ); + lSlowHandler = iMA( + _Symbol, + _Period, + mLCSlowLength, + 0, + method, + appliedTo // + ); + result = + // + lFastHandler != INVALID_HANDLE && + lSlowHandler != INVALID_HANDLE + // + ; + if (!result) + { + return result; + } + + // + // Hind Cycle Initialization ... + + // + // Find Cycle Period ... + if (hcMethod == X_PERIOD_AUTO) + { + // + // Select Period ... + mHCPeriod = GetCyclePeriod( + X_MARKET_CYCLE_HIND, + _Period // + ); + } + else + { + mHCPeriod = hcPeriod; + } + + // + result = IsValid(mHCPeriod); + if (!result) + { + return result; + } + + // + mHCLength = PeriodSeconds(mHCPeriod) / cPeriodSeconds; + mHCFastLength = fastLength * mHCLength; + mHCSlowLength = slowLength * mHCLength; + + // + result = mHCLength > 0; + if (!result) + { + return result; + } + + // + // Initialize Handlers ... + hFastHandler = iMA( + _Symbol, + _Period, + mHCFastLength, + 0, + method, + appliedTo // + ); + hSlowHandler = iMA( + _Symbol, + _Period, + mHCSlowLength, + 0, + method, + appliedTo // + ); + result = + // + hFastHandler != INVALID_HANDLE && + hSlowHandler != INVALID_HANDLE + // + ; + if (!result) + { + return result; + } + + // + return result; +} + +// +// Do all Custom Calculations ... +void CalculateBuffers(int barIndex) +{ + // + double cFast = cFastBuffer[barIndex]; + double sFast = sFastBuffer[barIndex]; + double mFast = mFastBuffer[barIndex]; + double lFast = lFastBuffer[barIndex]; + double hFast = hFastBuffer[barIndex]; + + // + double fast = + cFast + + sFast + + mFast + + lFast + + hFast; + avgFastBuffer[barIndex] = fast / 5; + + // + double cSlow = cSlowBuffer[barIndex]; + double sSlow = sSlowBuffer[barIndex]; + double mSlow = mSlowBuffer[barIndex]; + double lSlow = lSlowBuffer[barIndex]; + double hSlow = hSlowBuffer[barIndex]; + + // + double slow = + cSlow + + sSlow + + mSlow + + lSlow + + hSlow; + avgSlowBuffer[barIndex] = slow / 5; +} + +// \ No newline at end of file