From 55e706c30fa5fee31729019f109fe96f573d2562 Mon Sep 17 00:00:00 2001 From: Hadi Khazaee Asl Date: Thu, 25 Jul 2024 16:29:14 +0330 Subject: [PATCH] complete helpers for new indicators ... --- Helpers/x-saherelm.xchm.helper.mq5 | 2205 ++++++++++++++++++++++++++ Helpers/x-saherelm.xchstr.helper.mq5 | 2009 ++++------------------- 2 files changed, 2534 insertions(+), 1680 deletions(-) create mode 100644 Helpers/x-saherelm.xchm.helper.mq5 diff --git a/Helpers/x-saherelm.xchm.helper.mq5 b/Helpers/x-saherelm.xchm.helper.mq5 new file mode 100644 index 00000000..fe8dc553 --- /dev/null +++ b/Helpers/x-saherelm.xchm.helper.mq5 @@ -0,0 +1,2205 @@ +/////////////////////////////////////////////////////// +// +// SaherElm IT Center MQL5 Helper Class Library +// ---------------------------------------------- +// Name: XSCXCHMHelper +// 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_XCHM_BUFFERS +{ + // + // Main ... + XCHM_FAST_LINE = 0, + XCHM_SLOW_LINE = 1, + // + // Current ... + XCHM_CFAST_LINE = 2, + XCHM_CSLOW_LINE = 3, + // + // Short ... + XCHM_SFAST_LINE = 4, + XCHM_SSLOW_LINE = 5, + // + // Medium ... + XCHM_MFAST_LINE = 6, + XCHM_MSLOW_LINE = 7, + // + // Long ... + XCHM_LFAST_LINE = 8, + XCHM_LSLOW_LINE = 9, + // + // Hind ... + XCHM_HFAST_LINE = 10, + XCHM_HSLOW_LINE = 11, +}; + +// +// Input Models ... +struct XCHMInputs +{ + // + // 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) ... + XCHMInputs() + { + // + 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 XCHMConditions +{ + // + // 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 isClosedOverFast; + bool isClosedUnderFast; + + // + // Current ... + + // + bool isCFastOverSlow; + bool isCFastUnderSlow; + + // + bool isCFastCrossedOverSlow; + bool isCFastCrossedUnderSlow; + + // + bool isClosedOverCFast; + bool isClosedUnderCFast; + + // + // Short ... + + // + bool isSFastOverSlow; + bool isSFastUnderSlow; + + // + bool isSFastCrossedOverSlow; + bool isSFastCrossedUnderSlow; + + // + bool isClosedOverSFast; + bool isClosedUnderSFast; + + // + // Medium ... + + // + bool isMFastOverSlow; + bool isMFastUnderSlow; + + // + bool isMFastCrossedOverSlow; + bool isMFastCrossedUnderSlow; + + // + bool isClosedOverMFast; + bool isClosedUnderMFast; + + // + // Long ... + + // + bool isLFastOverSlow; + bool isLFastUnderSlow; + + // + bool isLFastCrossedOverSlow; + bool isLFastCrossedUnderSlow; + + // + bool isClosedOverLFast; + bool isClosedUnderLFast; + + // + // Hind ... + + // + bool isHFastOverSlow; + bool isHFastUnderSlow; + + // + bool isHFastCrossedOverSlow; + bool isHFastCrossedUnderSlow; + + // + bool isClosedOverHFast; + bool isClosedUnderHFast; + + // + 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; + + // + isClosedOverFast = false; + isClosedUnderFast = false; + + // + // Current ... + + // + isCFastOverSlow = false; + isCFastUnderSlow = false; + + // + isCFastCrossedOverSlow = false; + isCFastCrossedUnderSlow = false; + + // + isClosedOverCFast = false; + isClosedUnderCFast = false; + + // + // Short ... + + // + isSFastOverSlow = false; + isSFastUnderSlow = false; + + // + isSFastCrossedOverSlow = false; + isSFastCrossedUnderSlow = false; + + // + isClosedOverSFast = false; + isClosedUnderSFast = false; + + // + // Medium ... + + // + isMFastOverSlow = false; + isMFastUnderSlow = false; + + // + isMFastCrossedOverSlow = false; + isMFastCrossedUnderSlow = false; + + // + isClosedOverMFast = false; + isClosedUnderMFast = false; + + // + // Long ... + + // + isLFastOverSlow = false; + isLFastUnderSlow = false; + + // + isLFastCrossedOverSlow = false; + isLFastCrossedUnderSlow = false; + + // + isClosedOverLFast = false; + isClosedUnderLFast = false; + + // + // Hind ... + + // + isHFastOverSlow = false; + isHFastUnderSlow = false; + + // + isHFastCrossedOverSlow = false; + isHFastCrossedUnderSlow = false; + + // + isClosedOverHFast = false; + isClosedUnderHFast = 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) + { + bullishScore++; + } + if (isFastUnderSlow) + { + bearishScore++; + } + if (isFastCrossedOverSlow) + { + bullishScore++; + } + if (isFastCrossedUnderSlow) + { + bearishScore++; + } + if (isClosedOverFast) + { + bullishScore++; + } + if (isClosedUnderFast) + { + bearishScore++; + } + + // + // Current ... + + // + if (isCFastOverSlow) + { + bullishScore++; + } + if (isCFastUnderSlow) + { + bearishScore++; + } + if (isCFastCrossedOverSlow) + { + bullishScore++; + } + if (isCFastCrossedUnderSlow) + { + bearishScore++; + } + if (isClosedOverCFast) + { + bullishScore++; + } + if (isClosedUnderCFast) + { + bearishScore++; + } + + // + // Short ... + + // + if (isSFastOverSlow) + { + bullishScore++; + } + if (isSFastUnderSlow) + { + bearishScore++; + } + if (isSFastCrossedOverSlow) + { + bullishScore++; + } + if (isSFastCrossedUnderSlow) + { + bearishScore++; + } + if (isClosedOverSFast) + { + bullishScore++; + } + if (isClosedUnderSFast) + { + bearishScore++; + } + + // + // Medium ... + + // + if (isMFastOverSlow) + { + bullishScore++; + } + if (isMFastUnderSlow) + { + bearishScore++; + } + if (isMFastCrossedOverSlow) + { + bullishScore++; + } + if (isMFastCrossedUnderSlow) + { + bearishScore++; + } + if (isClosedOverMFast) + { + bullishScore++; + } + if (isClosedUnderMFast) + { + bearishScore++; + } + + // + // Long ... + + // + if (isLFastOverSlow) + { + bullishScore++; + } + if (isLFastUnderSlow) + { + bearishScore++; + } + if (isLFastCrossedOverSlow) + { + bullishScore++; + } + if (isLFastCrossedUnderSlow) + { + bearishScore++; + } + if (isClosedOverLFast) + { + bullishScore++; + } + if (isClosedUnderLFast) + { + bearishScore++; + } + + // + // Hind ... + + // + if (isHFastOverSlow) + { + bullishScore++; + } + if (isHFastUnderSlow) + { + bearishScore++; + } + if (isHFastCrossedOverSlow) + { + bullishScore++; + } + if (isHFastCrossedUnderSlow) + { + bearishScore++; + } + if (isClosedOverHFast) + { + bullishScore++; + } + if (isClosedUnderHFast) + { + bearishScore++; + } + } + + // + 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("isClosedOverFast", isClosedOverFast, ignoreFalseConditions, separator) + + ToString("isClosedUnderFast", isClosedUnderFast, ignoreFalseConditions, separator) + + // + // Current ... + ToString("isCFastOverSlow", isCFastOverSlow, ignoreFalseConditions, separator) + + ToString("isCFastUnderSlow", isCFastUnderSlow, ignoreFalseConditions, separator) + + ToString("isCFastCrossedOverSlow", isCFastCrossedOverSlow, ignoreFalseConditions, separator) + + ToString("isCFastCrossedUnderSlow", isCFastCrossedUnderSlow, ignoreFalseConditions, separator) + + ToString("isClosedOverCFast", isClosedOverCFast, ignoreFalseConditions, separator) + + ToString("isClosedUnderCFast", isClosedUnderCFast, ignoreFalseConditions, separator) + + // + // Short ... + ToString("isSFastOverSlow", isSFastOverSlow, ignoreFalseConditions, separator) + + ToString("isSFastUnderSlow", isSFastUnderSlow, ignoreFalseConditions, separator) + + ToString("isSFastCrossedOverSlow", isSFastCrossedOverSlow, ignoreFalseConditions, separator) + + ToString("isSFastCrossedUnderSlow", isSFastCrossedUnderSlow, ignoreFalseConditions, separator) + + ToString("isClosedOverSFast", isClosedOverSFast, ignoreFalseConditions, separator) + + ToString("isClosedUnderSFast", isClosedUnderSFast, ignoreFalseConditions, separator) + + // + // Medium ... + ToString("isMFastOverSlow", isMFastOverSlow, ignoreFalseConditions, separator) + + ToString("isMFastUnderSlow", isMFastUnderSlow, ignoreFalseConditions, separator) + + ToString("isMFastCrossedOverSlow", isMFastCrossedOverSlow, ignoreFalseConditions, separator) + + ToString("isMFastCrossedUnderSlow", isMFastCrossedUnderSlow, ignoreFalseConditions, separator) + + ToString("isClosedOverMFast", isClosedOverMFast, ignoreFalseConditions, separator) + + ToString("isClosedUnderMFast", isClosedUnderMFast, ignoreFalseConditions, separator) + + // + // Long ... + ToString("isLFastOverSlow", isLFastOverSlow, ignoreFalseConditions, separator) + + ToString("isLFastUnderSlow", isLFastUnderSlow, ignoreFalseConditions, separator) + + ToString("isLFastCrossedOverSlow", isLFastCrossedOverSlow, ignoreFalseConditions, separator) + + ToString("isLFastCrossedUnderSlow", isLFastCrossedUnderSlow, ignoreFalseConditions, separator) + + ToString("isClosedOverLFast", isClosedOverLFast, ignoreFalseConditions, separator) + + ToString("isClosedUnderLFast", isClosedUnderLFast, ignoreFalseConditions, separator) + + // + // Hind ... + ToString("isHFastOverSlow", isHFastOverSlow, ignoreFalseConditions, separator) + + ToString("isHFastUnderSlow", isHFastUnderSlow, ignoreFalseConditions, separator) + + ToString("isHFastCrossedOverSlow", isHFastCrossedOverSlow, ignoreFalseConditions, separator) + + ToString("isHFastCrossedUnderSlow", isHFastCrossedUnderSlow, ignoreFalseConditions, separator) + + ToString("isClosedOverHFast", isClosedOverHFast, ignoreFalseConditions, separator) + + ToString("isClosedUnderHFast", isClosedUnderHFast, ignoreFalseConditions, separator) + + // + "" + // + ; + + // + result = + // + "[" + GetTag() + "]" + separator + + (onlyConditions + ? "" + : commonStr) + + (!includeScores + ? "" + : scoresStr) + + " " + separator + + (onlyCommons + ? "" + : conditionsStr) + + "" + // + ; + + // + return result; + } + + // + string GetTag() + { + return "XCHM"; + } +}; + +// +// Class ... +class XSCXCHMHelper : public XSCBaseHelper +{ + // + // Public ... +public: + // + // Props ... + + // + // Constructors ... + XSCXCHMHelper() : XSCBaseHelper(_Symbol, _Period) + { + } + + // + // Deconstructor ... + ~XSCXCHMHelper() + { + // + Clean(fastBuffer); + Clean(slowBuffer); + Clean(cFastBuffer); + Clean(cSlowBuffer); + Clean(sFastBuffer); + Clean(sSlowBuffer); + Clean(mFastBuffer); + Clean(mSlowBuffer); + Clean(lFastBuffer); + Clean(lSlowBuffer); + Clean(hFastBuffer); + Clean(hSlowBuffer); + } + + // + // Tools ... + bool Init( + string symbol, // Trading Symbol + ENUM_TIMEFRAMES period, // Trading Period + XCHMInputs &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.xchm", + // + // 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 ... + + // + XCHMInputs GetInputs() + { + return mInputs; + } + + // + bool SetInputs( + XCHMInputs &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( + XCHMConditions &conditions, // + int barIndex = 0, // + int loopback = 5 // + ) + { + // + 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 // + ); + + // + XOHCL ppBar; + result = ppBar.Init( + mSymbol, + mPeriod, + ppIndex // + ); + if (!result) + { + return result; + } + double phhValue = ppBar.FindHighest( + loopback * 2, + MODE_HIGH // + ); + double pllValue = ppBar.FindLowest( + loopback * 2, + MODE_LOW // + ); + + // + double allValues[]; + double maxValue = 0; + double minValue = 0; + double maxValuePrev = 0; + double minValuePrev = 0; + + // + // AVG ... + + // + bool isFastOverSlow = conditions.fast[cIndex] > conditions.slow[cIndex]; + bool isFastOverSlowPrev = conditions.fast[pIndex] > conditions.slow[pIndex]; + + // + bool isFastUnderSlow = conditions.fast[cIndex] < conditions.slow[cIndex]; + bool isFastUnderSlowPrev = conditions.fast[pIndex] < conditions.slow[pIndex]; + + // + bool isFastCrossedOverSlow = isFastOverSlow && + !isFastOverSlowPrev; + bool isFastCrossedUnderSlow = isFastUnderSlow && + !isFastUnderSlowPrev; + + // + bool isClosedOverFast = cBar.close > conditions.fast[cIndex]; + bool isClosedUnderFast = cBar.close < conditions.fast[cIndex]; + + // + conditions.isFastOverSlow = isFastOverSlow; + conditions.isFastUnderSlow = isFastUnderSlow; + + // + conditions.isFastCrossedOverSlow = isFastCrossedOverSlow; + conditions.isFastCrossedUnderSlow = isFastCrossedUnderSlow; + + // + conditions.isClosedOverFast = isClosedOverFast; + conditions.isClosedUnderFast = isClosedUnderFast; + + // + // Current ... + + // + bool isCFastOverSlow = conditions.cFast[cIndex] > conditions.cSlow[cIndex]; + bool isCFastOverSlowPrev = conditions.cFast[pIndex] > conditions.cSlow[pIndex]; + + // + bool isCFastUnderSlow = conditions.cFast[cIndex] < conditions.cSlow[cIndex]; + bool isCFastUnderSlowPrev = conditions.cFast[pIndex] < conditions.cSlow[pIndex]; + + // + bool isCFastCrossedOverSlow = isCFastOverSlow && + !isCFastOverSlowPrev; + bool isCFastCrossedUnderSlow = isCFastUnderSlow && + !isCFastUnderSlowPrev; + + // + bool isClosedOverCFast = cBar.close > conditions.cFast[cIndex]; + bool isClosedUnderCFast = cBar.close < conditions.cFast[cIndex]; + + // + conditions.isCFastOverSlow = isCFastOverSlow; + conditions.isCFastUnderSlow = isCFastUnderSlow; + + // + conditions.isCFastCrossedOverSlow = isCFastCrossedOverSlow; + conditions.isCFastCrossedUnderSlow = isCFastCrossedUnderSlow; + + // + conditions.isClosedOverCFast = isClosedOverCFast; + conditions.isClosedUnderCFast = isClosedUnderCFast; + + // + // Short ... + + // + bool isSFastOverSlow = conditions.sFast[cIndex] > conditions.sSlow[cIndex]; + bool isSFastOverSlowPrev = conditions.sFast[pIndex] > conditions.sSlow[pIndex]; + + // + bool isSFastUnderSlow = conditions.sFast[cIndex] < conditions.sSlow[cIndex]; + bool isSFastUnderSlowPrev = conditions.sFast[pIndex] < conditions.sSlow[pIndex]; + + // + bool isSFastCrossedOverSlow = isSFastOverSlow && + !isSFastOverSlowPrev; + bool isSFastCrossedUnderSlow = isSFastUnderSlow && + !isSFastUnderSlowPrev; + + // + bool isClosedOverSFast = cBar.close > conditions.sFast[cIndex]; + bool isClosedUnderSFast = cBar.close < conditions.sFast[cIndex]; + + // + conditions.isSFastOverSlow = isSFastOverSlow; + conditions.isSFastUnderSlow = isSFastUnderSlow; + + // + conditions.isSFastCrossedOverSlow = isSFastCrossedOverSlow; + conditions.isSFastCrossedUnderSlow = isSFastCrossedUnderSlow; + + // + conditions.isClosedOverSFast = isClosedOverSFast; + conditions.isClosedUnderSFast = isClosedUnderSFast; + + // + // Medium ... + + // + bool isMFastOverSlow = conditions.mFast[cIndex] > conditions.mSlow[cIndex]; + bool isMFastOverSlowPrev = conditions.mFast[pIndex] > conditions.mSlow[pIndex]; + + // + bool isMFastUnderSlow = conditions.mFast[cIndex] < conditions.mSlow[cIndex]; + bool isMFastUnderSlowPrev = conditions.mFast[pIndex] < conditions.mSlow[pIndex]; + + // + bool isMFastCrossedOverSlow = isMFastOverSlow && + !isMFastOverSlowPrev; + bool isMFastCrossedUnderSlow = isMFastUnderSlow && + !isMFastUnderSlowPrev; + + // + bool isClosedOverMFast = cBar.close > conditions.mFast[cIndex]; + bool isClosedUnderMFast = cBar.close < conditions.mFast[cIndex]; + + // + conditions.isMFastOverSlow = isMFastOverSlow; + conditions.isMFastUnderSlow = isMFastUnderSlow; + + // + conditions.isMFastCrossedOverSlow = isMFastCrossedOverSlow; + conditions.isMFastCrossedUnderSlow = isMFastCrossedUnderSlow; + + // + conditions.isClosedOverMFast = isClosedOverMFast; + conditions.isClosedUnderMFast = isClosedUnderMFast; + + // + // Long ... + + // + bool isLFastOverSlow = conditions.lFast[cIndex] > conditions.lSlow[cIndex]; + bool isLFastOverSlowPrev = conditions.lFast[pIndex] > conditions.lSlow[pIndex]; + + // + bool isLFastUnderSlow = conditions.lFast[cIndex] < conditions.lSlow[cIndex]; + bool isLFastUnderSlowPrev = conditions.lFast[pIndex] < conditions.lSlow[pIndex]; + + // + bool isLFastCrossedOverSlow = isLFastOverSlow && + !isLFastOverSlowPrev; + bool isLFastCrossedUnderSlow = isLFastUnderSlow && + !isLFastUnderSlowPrev; + + // + bool isClosedOverLFast = cBar.close > conditions.lFast[cIndex]; + bool isClosedUnderLFast = cBar.close < conditions.lFast[cIndex]; + + // + conditions.isLFastOverSlow = isLFastOverSlow; + conditions.isLFastUnderSlow = isLFastUnderSlow; + + // + conditions.isLFastCrossedOverSlow = isLFastCrossedOverSlow; + conditions.isLFastCrossedUnderSlow = isLFastCrossedUnderSlow; + + // + conditions.isClosedOverLFast = isClosedOverLFast; + conditions.isClosedUnderLFast = isClosedUnderLFast; + + // + // Hind ... + + // + bool isHFastOverSlow = conditions.hFast[cIndex] > conditions.hSlow[cIndex]; + bool isHFastOverSlowPrev = conditions.hFast[pIndex] > conditions.hSlow[pIndex]; + + // + bool isHFastUnderSlow = conditions.hFast[cIndex] < conditions.hSlow[cIndex]; + bool isHFastUnderSlowPrev = conditions.hFast[pIndex] < conditions.hSlow[pIndex]; + + // + bool isHFastCrossedOverSlow = isHFastOverSlow && + !isHFastOverSlowPrev; + bool isHFastCrossedUnderSlow = isHFastUnderSlow && + !isHFastUnderSlowPrev; + + // + bool isClosedOverHFast = cBar.close > conditions.hFast[cIndex]; + bool isClosedUnderHFast = cBar.close < conditions.hFast[cIndex]; + + // + conditions.isHFastOverSlow = isHFastOverSlow; + conditions.isHFastUnderSlow = isHFastUnderSlow; + + // + conditions.isHFastCrossedOverSlow = isHFastCrossedOverSlow; + conditions.isHFastCrossedUnderSlow = isHFastCrossedUnderSlow; + + // + conditions.isClosedOverHFast = isClosedOverHFast; + conditions.isClosedUnderHFast = isClosedUnderHFast; + + // + return result; + } + + // + // Protected ... +protected: + // + // Private ... +private: + // + // Props ... + XCHMInputs 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, + XCHM_FAST_LINE, + 0, + totalBars, + fastBuffer + // + ); + + // + // Slow ... + CopyBuffer( + mHandler, + XCHM_SLOW_LINE, + 0, + totalBars, + slowBuffer + // + ); + + // + // Current ... + + // + // Fast ... + CopyBuffer( + mHandler, + XCHM_CFAST_LINE, + 0, + totalBars, + cFastBuffer + // + ); + + // + // Slow ... + CopyBuffer( + mHandler, + XCHM_CSLOW_LINE, + 0, + totalBars, + cSlowBuffer + // + ); + + // + // Short ... + + // + // Fast ... + CopyBuffer( + mHandler, + XCHM_SFAST_LINE, + 0, + totalBars, + sFastBuffer + // + ); + + // + // Slow ... + CopyBuffer( + mHandler, + XCHM_SSLOW_LINE, + 0, + totalBars, + sSlowBuffer + // + ); + + // + // Medium ... + + // + // Fast ... + CopyBuffer( + mHandler, + XCHM_MFAST_LINE, + 0, + totalBars, + mFastBuffer + // + ); + + // + // Slow ... + CopyBuffer( + mHandler, + XCHM_MSLOW_LINE, + 0, + totalBars, + mSlowBuffer + // + ); + + // + // Long ... + + // + // Fast ... + CopyBuffer( + mHandler, + XCHM_LFAST_LINE, + 0, + totalBars, + lFastBuffer + // + ); + + // + // Slow ... + CopyBuffer( + mHandler, + XCHM_LSLOW_LINE, + 0, + totalBars, + lSlowBuffer + // + ); + + // + // Hind ... + + // + // Fast ... + CopyBuffer( + mHandler, + XCHM_HFAST_LINE, + 0, + totalBars, + hFastBuffer + // + ); + + // + // Slow ... + CopyBuffer( + mHandler, + XCHM_HSLOW_LINE, + 0, + totalBars, + hSlowBuffer + // + ); + } +}; + +// \ No newline at end of file diff --git a/Helpers/x-saherelm.xchstr.helper.mq5 b/Helpers/x-saherelm.xchstr.helper.mq5 index 1a384ab8..581a725e 100644 --- a/Helpers/x-saherelm.xchstr.helper.mq5 +++ b/Helpers/x-saherelm.xchstr.helper.mq5 @@ -2,7 +2,7 @@ // // SaherElm IT Center MQL5 Helper Class Library // ---------------------------------------------- -// Name: XSCXCHHKHelper +// Name: XSCXCHSTRHelper // Description: provides all Indicator // Helper requirements ... // @@ -28,50 +28,44 @@ // Definitions ... // -enum ENUM_XCHHK_BUFFERS +enum ENUM_XCHSTR_BUFFERS { // - // Current ... - XCHHK_CO_LINE = 0, - XCHHK_CH_LINE = 1, - XCHHK_CL_LINE = 2, - XCHHK_CC_LINE = 3, + XCHSTR_C_LINE = 0, + XCHSTR_C_STATE_LINE = 11, // - // Short ... - XCHHK_SO_LINE = 5, - XCHHK_SH_LINE = 6, - XCHHK_SL_LINE = 7, - XCHHK_SC_LINE = 8, + XCHSTR_S_LINE = 2, + XCHSTR_S_STATE_LINE = 16, // - // Medium ... - XCHHK_MO_LINE = 10, - XCHHK_MH_LINE = 11, - XCHHK_ML_LINE = 12, - XCHHK_MC_LINE = 13, + XCHSTR_M_LINE = 4, + XCHSTR_M_STATE_LINE = 21, // - // Long ... - XCHHK_LO_LINE = 15, - XCHHK_LH_LINE = 16, - XCHHK_LL_LINE = 17, - XCHHK_LC_LINE = 18, + XCHSTR_L_LINE = 6, + XCHSTR_L_STATE_LINE = 26, // - // Hind ... - XCHHK_HO_LINE = 20, - XCHHK_HH_LINE = 21, - XCHHK_HL_LINE = 22, - XCHHK_HC_LINE = 23, + XCHSTR_H_LINE = 8, + XCHSTR_H_STATE_LINE = 31, +}; + +// +enum ENUM_XCHSTR_TREND_STATES +{ + X_STR_BULLISH = 1, // Bullish + X_STR_BEARISH = -1, // Bearish }; // // Input Models ... -struct XCHHKInputs +struct XCHSTRInputs { // // Props ... // // Market ... - int cSmoothingLength; // Smoothing Length + int length; // Length + double multiplier; // Multiplier + ENUM_APPLIED_PRICE appliedTo; // Applied To // // Cycles ... @@ -106,7 +100,7 @@ struct XCHHKInputs // // Constructor(s) ... - XCHHKInputs() + XCHSTRInputs() { // Clean(); @@ -120,7 +114,9 @@ struct XCHHKInputs void Clean() { // - cSmoothingLength = 0; + length = 0; + multiplier = 0; + appliedTo = PRICE_CLOSE; // scMethod = X_PERIOD_AUTO; @@ -145,7 +141,9 @@ struct XCHHKInputs void Default() { // - cSmoothingLength = 14; + length = 14; + multiplier = 3.5; + appliedTo = PRICE_MEDIAN; // scMethod = X_PERIOD_AUTO; @@ -175,7 +173,8 @@ struct XCHHKInputs // result = // - cSmoothingLength > 2 && + length > 0 && + multiplier > 0 && // (IsValid(scMethod, scPeriod) && IsValid(mcMethod, mcPeriod) && @@ -198,7 +197,7 @@ struct XCHHKInputs // result = // - MathMax(0, cSmoothingLength) + MathMax(0, length) // ; @@ -209,7 +208,7 @@ struct XCHHKInputs // // Define Conditions ... -struct XCHHKConditions +struct XCHSTRConditions { // // Common ... @@ -222,176 +221,131 @@ struct XCHHKConditions // // Current ... - XOHCL cBars[]; + double cTrend[]; + double cState[]; // // Short ... - XOHCL sBars[]; + double sTrend[]; + double sState[]; // // Medium ... - XOHCL mBars[]; + double mTrend[]; + double mState[]; // // Long ... - XOHCL lBars[]; + double lTrend[]; + double lState[]; // // Hind ... - XOHCL hBars[]; + double hTrend[]; + double hState[]; // // Conditions ... // // Current ... - - // bool isCBullish; - bool isCSwitchedToBullish; bool isCBearish; + bool isCSwitchedToBullish; bool isCSwitchedToBearish; - // - bool isCloseOverCHigh; - bool isCloseUnderCLow; - // // Short ... - - // bool isSBullish; - bool isSSwitchedToBullish; bool isSBearish; + bool isSSwitchedToBullish; bool isSSwitchedToBearish; - // - bool isCloseOverSHigh; - bool isCloseUnderSLow; - // // Medium ... - - // bool isMBullish; - bool isMSwitchedToBullish; bool isMBearish; + bool isMSwitchedToBullish; bool isMSwitchedToBearish; - // - bool isCloseOverMHigh; - bool isCloseUnderMLow; - // // Long ... - - // bool isLBullish; - bool isLSwitchedToBullish; bool isLBearish; + bool isLSwitchedToBullish; bool isLSwitchedToBearish; - // - bool isCloseOverLHigh; - bool isCloseUnderLLow; - // // Hind ... - - // bool isHBullish; - bool isHSwitchedToBullish; bool isHBearish; + bool isHSwitchedToBullish; bool isHSwitchedToBearish; - // - bool isCloseOverHHigh; - bool isCloseUnderHLow; - // void Clean() { // - Clean(cBars); - Clean(sBars); - Clean(mBars); - Clean(lBars); - Clean(hBars); + Clean(cTrend); + Clean(cState); + Clean(sTrend); + Clean(sState); + Clean(mTrend); + Clean(mState); + Clean(lTrend); + Clean(lState); + Clean(hTrend); + Clean(hState); // - ArraySetAsSeries(cBars, true); - ArraySetAsSeries(sBars, true); - ArraySetAsSeries(mBars, true); - ArraySetAsSeries(lBars, true); - ArraySetAsSeries(hBars, true); + ArraySetAsSeries(cTrend, true); + ArraySetAsSeries(cState, true); + ArraySetAsSeries(sTrend, true); + ArraySetAsSeries(sState, true); + ArraySetAsSeries(mTrend, true); + ArraySetAsSeries(mState, true); + ArraySetAsSeries(lTrend, true); + ArraySetAsSeries(lState, true); + ArraySetAsSeries(hTrend, true); + ArraySetAsSeries(hState, true); // // Conditions ... // // Current ... - - // isCBullish = false; - isCSwitchedToBullish = false; isCBearish = false; + isCSwitchedToBullish = false; isCSwitchedToBearish = false; - // - isCloseOverCHigh = false; - isCloseUnderCLow = false; - // // Short ... - - // isSBullish = false; - isSSwitchedToBullish = false; isSBearish = false; + isSSwitchedToBullish = false; isSSwitchedToBearish = false; - // - isCloseOverSHigh = false; - isCloseUnderSLow = false; - // // Medium ... - - // isMBullish = false; - isMSwitchedToBullish = false; isMBearish = false; + isMSwitchedToBullish = false; isMSwitchedToBearish = false; - // - isCloseOverMHigh = false; - isCloseUnderMLow = false; - // // Long ... - - // isLBullish = false; - isLSwitchedToBullish = false; isLBearish = false; + isLSwitchedToBullish = false; isLSwitchedToBearish = false; - // - isCloseOverLHigh = false; - isCloseUnderLLow = false; - // // Hind ... - - // isHBullish = false; - isHSwitchedToBullish = false; isHBearish = false; + isHSwitchedToBullish = false; isHSwitchedToBearish = false; - - // - isCloseOverHHigh = false; - isCloseUnderHLow = false; } // @@ -419,23 +373,15 @@ struct XCHHKConditions { bullishScore++; } - if (isCSwitchedToBullish) - { - bullishScore++; - } if (isCBearish) { bearishScore++; } - if (isCSwitchedToBearish) - { - bearishScore++; - } - if (isCloseOverCHigh) + if (isCSwitchedToBullish) { bullishScore++; } - if (isCloseUnderCLow) + if (isCSwitchedToBearish) { bearishScore++; } @@ -446,23 +392,15 @@ struct XCHHKConditions { bullishScore++; } - if (isSSwitchedToBullish) - { - bullishScore++; - } if (isSBearish) { bearishScore++; } - if (isSSwitchedToBearish) - { - bearishScore++; - } - if (isCloseOverSHigh) + if (isSSwitchedToBullish) { bullishScore++; } - if (isCloseUnderSLow) + if (isSSwitchedToBearish) { bearishScore++; } @@ -473,23 +411,15 @@ struct XCHHKConditions { bullishScore++; } - if (isMSwitchedToBullish) - { - bullishScore++; - } if (isMBearish) { bearishScore++; } - if (isMSwitchedToBearish) - { - bearishScore++; - } - if (isCloseOverMHigh) + if (isMSwitchedToBullish) { bullishScore++; } - if (isCloseUnderMLow) + if (isMSwitchedToBearish) { bearishScore++; } @@ -500,23 +430,15 @@ struct XCHHKConditions { bullishScore++; } - if (isLSwitchedToBullish) - { - bullishScore++; - } if (isLBearish) { bearishScore++; } - if (isLSwitchedToBearish) - { - bearishScore++; - } - if (isCloseOverLHigh) + if (isLSwitchedToBullish) { bullishScore++; } - if (isCloseUnderLLow) + if (isLSwitchedToBearish) { bearishScore++; } @@ -527,23 +449,15 @@ struct XCHHKConditions { bullishScore++; } - if (isHSwitchedToBullish) - { - bullishScore++; - } if (isHBearish) { bearishScore++; } - if (isHSwitchedToBearish) - { - bearishScore++; - } - if (isCloseOverHHigh) + if (isHSwitchedToBullish) { bullishScore++; } - if (isCloseUnderHLow) + if (isHSwitchedToBearish) { bearishScore++; } @@ -592,43 +506,33 @@ struct XCHHKConditions // // Current ... ToString("isCBullish", isCBullish, ignoreFalseConditions, separator) + - ToString("isCSwitchedToBullish", isCSwitchedToBullish, ignoreFalseConditions, separator) + ToString("isCBearish", isCBearish, ignoreFalseConditions, separator) + + ToString("isCSwitchedToBullish", isCSwitchedToBullish, ignoreFalseConditions, separator) + ToString("isCSwitchedToBearish", isCSwitchedToBearish, ignoreFalseConditions, separator) + - ToString("isCloseOverCHigh", isCloseOverCHigh, ignoreFalseConditions, separator) + - ToString("isCloseUnderCLow", isCloseUnderCLow, ignoreFalseConditions, separator) + // // Short ... ToString("isSBullish", isSBullish, ignoreFalseConditions, separator) + - ToString("isSSwitchedToBullish", isSSwitchedToBullish, ignoreFalseConditions, separator) + ToString("isSBearish", isSBearish, ignoreFalseConditions, separator) + + ToString("isSSwitchedToBullish", isSSwitchedToBullish, ignoreFalseConditions, separator) + ToString("isSSwitchedToBearish", isSSwitchedToBearish, ignoreFalseConditions, separator) + - ToString("isCloseOverSHigh", isCloseOverSHigh, ignoreFalseConditions, separator) + - ToString("isCloseUnderSLow", isCloseUnderSLow, ignoreFalseConditions, separator) + // // Medium ... ToString("isMBullish", isMBullish, ignoreFalseConditions, separator) + - ToString("isMSwitchedToBullish", isMSwitchedToBullish, ignoreFalseConditions, separator) + ToString("isMBearish", isMBearish, ignoreFalseConditions, separator) + + ToString("isMSwitchedToBullish", isMSwitchedToBullish, ignoreFalseConditions, separator) + ToString("isMSwitchedToBearish", isMSwitchedToBearish, ignoreFalseConditions, separator) + - ToString("isCloseOverMHigh", isCloseOverMHigh, ignoreFalseConditions, separator) + - ToString("isCloseUnderMLow", isCloseUnderMLow, ignoreFalseConditions, separator) + // // Long ... ToString("isLBullish", isLBullish, ignoreFalseConditions, separator) + - ToString("isLSwitchedToBullish", isLSwitchedToBullish, ignoreFalseConditions, separator) + ToString("isLBearish", isLBearish, ignoreFalseConditions, separator) + + ToString("isLSwitchedToBullish", isLSwitchedToBullish, ignoreFalseConditions, separator) + ToString("isLSwitchedToBearish", isLSwitchedToBearish, ignoreFalseConditions, separator) + - ToString("isCloseOverLHigh", isCloseOverLHigh, ignoreFalseConditions, separator) + - ToString("isCloseUnderLLow", isCloseUnderLLow, ignoreFalseConditions, separator) + // // Hind ... ToString("isHBullish", isHBullish, ignoreFalseConditions, separator) + - ToString("isHSwitchedToBullish", isHSwitchedToBullish, ignoreFalseConditions, separator) + ToString("isHBearish", isHBearish, ignoreFalseConditions, separator) + + ToString("isHSwitchedToBullish", isHSwitchedToBullish, ignoreFalseConditions, separator) + ToString("isHSwitchedToBearish", isHSwitchedToBearish, ignoreFalseConditions, separator) + - ToString("isCloseOverHHigh", isCloseOverHHigh, ignoreFalseConditions, separator) + - ToString("isCloseUnderHLow", isCloseUnderHLow, ignoreFalseConditions, separator) + // "" // @@ -659,13 +563,13 @@ struct XCHHKConditions // string GetTag() { - return "XCHHK"; + return "XCHSTR"; } }; // // Class ... -class XSCXCHHKHelper : public XSCBaseHelper +class XSCXCHSTRHelper : public XSCBaseHelper { // // Public ... @@ -675,35 +579,25 @@ public: // // Constructors ... - XSCXCHHKHelper() : XSCBaseHelper(_Symbol, _Period) + XSCXCHSTRHelper() : XSCBaseHelper(_Symbol, _Period) { } // // Deconstructor ... - ~XSCXCHHKHelper() + ~XSCXCHSTRHelper() { // - Clean(cOpenBuffer); - Clean(cHighBuffer); - Clean(cLowBuffer); - Clean(cCloseBuffer); - Clean(sOpenBuffer); - Clean(sHighBuffer); - Clean(sLowBuffer); - Clean(sCloseBuffer); - Clean(mOpenBuffer); - Clean(mHighBuffer); - Clean(mLowBuffer); - Clean(mCloseBuffer); - Clean(lOpenBuffer); - Clean(lHighBuffer); - Clean(lLowBuffer); - Clean(lCloseBuffer); - Clean(hOpenBuffer); - Clean(hHighBuffer); - Clean(hLowBuffer); - Clean(hCloseBuffer); + Clean(cTrendBuffer); + Clean(cStateBuffer); + Clean(sTrendBuffer); + Clean(sStateBuffer); + Clean(mTrendBuffer); + Clean(mStateBuffer); + Clean(lTrendBuffer); + Clean(lStateBuffer); + Clean(hTrendBuffer); + Clean(hStateBuffer); } // @@ -711,7 +605,7 @@ public: bool Init( string symbol, // Trading Symbol ENUM_TIMEFRAMES period, // Trading Period - XCHHKInputs &inputs // Inputs + XCHSTRInputs &inputs // Inputs ) { // @@ -732,38 +626,30 @@ public: mInputs = inputs; // - ArraySetAsSeries(cOpenBuffer, true); - ArraySetAsSeries(cHighBuffer, true); - ArraySetAsSeries(cLowBuffer, true); - ArraySetAsSeries(cCloseBuffer, true); - ArraySetAsSeries(sOpenBuffer, true); - ArraySetAsSeries(sHighBuffer, true); - ArraySetAsSeries(sLowBuffer, true); - ArraySetAsSeries(sCloseBuffer, true); - ArraySetAsSeries(mOpenBuffer, true); - ArraySetAsSeries(mHighBuffer, true); - ArraySetAsSeries(mLowBuffer, true); - ArraySetAsSeries(mCloseBuffer, true); - ArraySetAsSeries(lOpenBuffer, true); - ArraySetAsSeries(lHighBuffer, true); - ArraySetAsSeries(lLowBuffer, true); - ArraySetAsSeries(lCloseBuffer, true); - ArraySetAsSeries(hOpenBuffer, true); - ArraySetAsSeries(hHighBuffer, true); - ArraySetAsSeries(hLowBuffer, true); - ArraySetAsSeries(hCloseBuffer, true); + ArraySetAsSeries(cTrendBuffer, true); + ArraySetAsSeries(cStateBuffer, true); + ArraySetAsSeries(sTrendBuffer, true); + ArraySetAsSeries(sStateBuffer, true); + ArraySetAsSeries(mTrendBuffer, true); + ArraySetAsSeries(mStateBuffer, true); + ArraySetAsSeries(lTrendBuffer, true); + ArraySetAsSeries(lStateBuffer, true); + ArraySetAsSeries(hTrendBuffer, true); + ArraySetAsSeries(hStateBuffer, true); // mHandler = iCustom( mSymbol, mPeriod, - "x-saherelm.xchhk", + "x-saherelm.xchstr", // // Inputs ... // // Market ... "", - mInputs.cSmoothingLength, + mInputs.length, // Length + mInputs.multiplier, // Multiplier + mInputs.appliedTo, // Applied To // // Cycles ... "", @@ -811,14 +697,14 @@ public: // Inputs ... // - XCHHKInputs GetInputs() + XCHSTRInputs GetInputs() { return mInputs; } // bool SetInputs( - XCHHKInputs &inputs // Configs + XCHSTRInputs &inputs // Configs ) { // @@ -837,7 +723,10 @@ public: // Current ... // - double GetCOpen( + // Trend ... + + // + double GetCTrend( int barIndex // Bar Index ) { @@ -851,19 +740,12 @@ public: Calculate(); // - int count = ArraySize(cOpenBuffer); - if (barIndex >= count) - { - barIndex = count - 1; - } - - // - return cOpenBuffer[barIndex]; + return cTrendBuffer[barIndex]; } // - // Copy Required Items ... - int CopyCOpen( + // Copy Required Buffer ... + int CopyCTrend( int start, // Start int count, // Number of Items for read double &buffer[], // Dest Buffer @@ -879,7 +761,7 @@ public: return Copy( start, count, - cOpenBuffer, + cTrendBuffer, buffer, forceClean // @@ -887,7 +769,10 @@ public: } // - double GetCHigh( + // State ... + + // + ENUM_XCHSTR_TREND_STATES GetCState( int barIndex // Bar Index ) { @@ -901,19 +786,12 @@ public: Calculate(); // - int count = ArraySize(cHighBuffer); - if (barIndex >= count) - { - barIndex = count - 1; - } - - // - return cHighBuffer[barIndex]; + return (ENUM_XCHSTR_TREND_STATES)((int)cStateBuffer[barIndex]); } // - // Copy Required Items ... - int CopyCHigh( + // Copy Required Buffer ... + int CopyCState( int start, // Start int count, // Number of Items for read double &buffer[], // Dest Buffer @@ -929,239 +807,21 @@ public: return Copy( start, count, - cHighBuffer, + cStateBuffer, buffer, forceClean // ); } - // - double GetCLow( - int barIndex // Bar Index - ) - { - // - if (barIndex < 0) - { - barIndex = 0; - } - - // - Calculate(); - - // - int count = ArraySize(cLowBuffer); - if (barIndex >= count) - { - barIndex = count - 1; - } - - // - return cLowBuffer[barIndex]; - } - - // - // Copy Required Items ... - int CopyCLow( - 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, - cLowBuffer, - buffer, - forceClean - // - ); - } - - // - double GetCClose( - int barIndex // Bar Index - ) - { - // - if (barIndex < 0) - { - barIndex = 0; - } - - // - Calculate(); - - // - int count = ArraySize(cCloseBuffer); - if (barIndex >= count) - { - barIndex = count - 1; - } - - // - return cCloseBuffer[barIndex]; - } - - // - // Copy Required Items ... - int CopyCClose( - 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, - cCloseBuffer, - buffer, - forceClean - // - ); - } - - // - // Get XOHCL ... - bool CAsOHCL( - XOHCL &bar, // Holds Result - int barIndex // Bar Index - ) - { - // - bool result = false; - - // - if (barIndex < 0) - { - barIndex = 0; - } - - // - Calculate(); - - // - int count = ArraySize(cOpenBuffer); - if (barIndex >= count) - { - barIndex = count - 1; - } - - // - double open = GetCOpen(barIndex); - double high = GetCHigh(barIndex); - double close = GetCClose(barIndex); - double low = GetCLow(barIndex); - - // - result = bar.Init( - mSymbol, - mPeriod, - open, - high, - close, - low, - barIndex - // - ); - - // - return result; - } - - // - // Copy Required Items ... - int CopyCAsOHCL( - int start, // Start - int count, // Number of Items for read - XOHCL &buffer[], // Dest Buffer - bool forceClean = true // Force To Clean buffer - ) - { - // - int result = 0; - - // - // Update Calculations ... - Calculate(); - - // - if (forceClean) - { - Clean(buffer); - } - - // - int before = ArraySize(buffer); - - // - if (start < 0) - { - start = 0; - } - - // - if (start >= ArraySize(cOpenBuffer)) - { - start = ArraySize(cOpenBuffer) - 1; - } - - // - bool asSeriesBuffer = ArrayGetAsSeries(buffer); - ArraySetAsSeries(buffer, true); - - // - for (int i = start; i < start + count; i++) - { - // - XOHCL iBar; - bool isInit = CAsOHCL(iBar, i); - - // - if (isInit) - { - // - AddRef( - iBar, - buffer - // - ); - } - } - - // - ArraySetAsSeries(buffer, asSeriesBuffer); - - // - int after = ArraySize(buffer); - - // - result = after - before; - - // - return result; - } - // // Short ... // - double GetSOpen( + // Trend ... + + // + double GetSTrend( int barIndex // Bar Index ) { @@ -1175,19 +835,12 @@ public: Calculate(); // - int count = ArraySize(sOpenBuffer); - if (barIndex >= count) - { - barIndex = count - 1; - } - - // - return sOpenBuffer[barIndex]; + return sTrendBuffer[barIndex]; } // - // Copy Required Items ... - int CopySOpen( + // Copy Required Buffer ... + int CopySTrend( int start, // Start int count, // Number of Items for read double &buffer[], // Dest Buffer @@ -1203,7 +856,7 @@ public: return Copy( start, count, - sOpenBuffer, + sTrendBuffer, buffer, forceClean // @@ -1211,7 +864,10 @@ public: } // - double GetSHigh( + // State ... + + // + ENUM_XCHSTR_TREND_STATES GetSState( int barIndex // Bar Index ) { @@ -1225,19 +881,12 @@ public: Calculate(); // - int count = ArraySize(sHighBuffer); - if (barIndex >= count) - { - barIndex = count - 1; - } - - // - return sHighBuffer[barIndex]; + return (ENUM_XCHSTR_TREND_STATES)((int)sStateBuffer[barIndex]); } // - // Copy Required Items ... - int CopySHigh( + // Copy Required Buffer ... + int CopySState( int start, // Start int count, // Number of Items for read double &buffer[], // Dest Buffer @@ -1253,239 +902,21 @@ public: return Copy( start, count, - sHighBuffer, + sStateBuffer, 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 - // - ); - } - - // - double GetSClose( - int barIndex // Bar Index - ) - { - // - if (barIndex < 0) - { - barIndex = 0; - } - - // - Calculate(); - - // - int count = ArraySize(sCloseBuffer); - if (barIndex >= count) - { - barIndex = count - 1; - } - - // - return sCloseBuffer[barIndex]; - } - - // - // Copy Required Items ... - int CopySClose( - 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, - sCloseBuffer, - buffer, - forceClean - // - ); - } - - // - // Get XOHCL ... - bool SAsOHCL( - XOHCL &bar, // Holds Result - int barIndex // Bar Index - ) - { - // - bool result = false; - - // - if (barIndex < 0) - { - barIndex = 0; - } - - // - Calculate(); - - // - int count = ArraySize(sOpenBuffer); - if (barIndex >= count) - { - barIndex = count - 1; - } - - // - double open = GetSOpen(barIndex); - double high = GetSHigh(barIndex); - double close = GetSClose(barIndex); - double low = GetSLow(barIndex); - - // - result = bar.Init( - mSymbol, - mPeriod, - open, - high, - close, - low, - barIndex - // - ); - - // - return result; - } - - // - // Copy Required Items ... - int CopySAsOHCL( - int start, // Start - int count, // Number of Items for read - XOHCL &buffer[], // Dest Buffer - bool forceClean = true // Force To Clean buffer - ) - { - // - int result = 0; - - // - // Update Calculations ... - Calculate(); - - // - if (forceClean) - { - Clean(buffer); - } - - // - int before = ArraySize(buffer); - - // - if (start < 0) - { - start = 0; - } - - // - if (start >= ArraySize(sOpenBuffer)) - { - start = ArraySize(sOpenBuffer) - 1; - } - - // - bool asSeriesBuffer = ArrayGetAsSeries(buffer); - ArraySetAsSeries(buffer, true); - - // - for (int i = start; i < start + count; i++) - { - // - XOHCL iBar; - bool isInit = SAsOHCL(iBar, i); - - // - if (isInit) - { - // - AddRef( - iBar, - buffer - // - ); - } - } - - // - ArraySetAsSeries(buffer, asSeriesBuffer); - - // - int after = ArraySize(buffer); - - // - result = after - before; - - // - return result; - } - // // Medium ... // - double GetMOpen( + // Trend ... + + // + double GetMTrend( int barIndex // Bar Index ) { @@ -1499,19 +930,12 @@ public: Calculate(); // - int count = ArraySize(mOpenBuffer); - if (barIndex >= count) - { - barIndex = count - 1; - } - - // - return mOpenBuffer[barIndex]; + return mTrendBuffer[barIndex]; } // - // Copy Required Items ... - int CopyMOpen( + // Copy Required Buffer ... + int CopyMTrend( int start, // Start int count, // Number of Items for read double &buffer[], // Dest Buffer @@ -1527,7 +951,7 @@ public: return Copy( start, count, - mOpenBuffer, + mTrendBuffer, buffer, forceClean // @@ -1535,7 +959,10 @@ public: } // - double GetMHigh( + // State ... + + // + ENUM_XCHSTR_TREND_STATES GetMState( int barIndex // Bar Index ) { @@ -1549,19 +976,12 @@ public: Calculate(); // - int count = ArraySize(mHighBuffer); - if (barIndex >= count) - { - barIndex = count - 1; - } - - // - return mHighBuffer[barIndex]; + return (ENUM_XCHSTR_TREND_STATES)((int)mStateBuffer[barIndex]); } // - // Copy Required Items ... - int CopyMHigh( + // Copy Required Buffer ... + int CopyMState( int start, // Start int count, // Number of Items for read double &buffer[], // Dest Buffer @@ -1577,239 +997,21 @@ public: return Copy( start, count, - mHighBuffer, + mStateBuffer, buffer, forceClean // ); } - // - double GetMLow( - int barIndex // Bar Index - ) - { - // - if (barIndex < 0) - { - barIndex = 0; - } - - // - Calculate(); - - // - int count = ArraySize(mLowBuffer); - if (barIndex >= count) - { - barIndex = count - 1; - } - - // - return mLowBuffer[barIndex]; - } - - // - // Copy Required Items ... - int CopyMLow( - 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, - mLowBuffer, - buffer, - forceClean - // - ); - } - - // - double GetMClose( - int barIndex // Bar Index - ) - { - // - if (barIndex < 0) - { - barIndex = 0; - } - - // - Calculate(); - - // - int count = ArraySize(mCloseBuffer); - if (barIndex >= count) - { - barIndex = count - 1; - } - - // - return mCloseBuffer[barIndex]; - } - - // - // Copy Required Items ... - int CopyMClose( - 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, - mCloseBuffer, - buffer, - forceClean - // - ); - } - - // - // Get XOHCL ... - bool MAsOHCL( - XOHCL &bar, // Holds Result - int barIndex // Bar Index - ) - { - // - bool result = false; - - // - if (barIndex < 0) - { - barIndex = 0; - } - - // - Calculate(); - - // - int count = ArraySize(mOpenBuffer); - if (barIndex >= count) - { - barIndex = count - 1; - } - - // - double open = GetMOpen(barIndex); - double high = GetMHigh(barIndex); - double close = GetMClose(barIndex); - double low = GetMLow(barIndex); - - // - result = bar.Init( - mSymbol, - mPeriod, - open, - high, - close, - low, - barIndex - // - ); - - // - return result; - } - - // - // Copy Required Items ... - int CopyMAsOHCL( - int start, // Start - int count, // Number of Items for read - XOHCL &buffer[], // Dest Buffer - bool forceClean = true // Force To Clean buffer - ) - { - // - int result = 0; - - // - // Update Calculations ... - Calculate(); - - // - if (forceClean) - { - Clean(buffer); - } - - // - int before = ArraySize(buffer); - - // - if (start < 0) - { - start = 0; - } - - // - if (start >= ArraySize(mOpenBuffer)) - { - start = ArraySize(mOpenBuffer) - 1; - } - - // - bool asSeriesBuffer = ArrayGetAsSeries(buffer); - ArraySetAsSeries(buffer, true); - - // - for (int i = start; i < start + count; i++) - { - // - XOHCL iBar; - bool isInit = MAsOHCL(iBar, i); - - // - if (isInit) - { - // - AddRef( - iBar, - buffer - // - ); - } - } - - // - ArraySetAsSeries(buffer, asSeriesBuffer); - - // - int after = ArraySize(buffer); - - // - result = after - before; - - // - return result; - } - // // Long ... // - double GetLOpen( + // Trend ... + + // + double GetLTrend( int barIndex // Bar Index ) { @@ -1823,19 +1025,12 @@ public: Calculate(); // - int count = ArraySize(lOpenBuffer); - if (barIndex >= count) - { - barIndex = count - 1; - } - - // - return lOpenBuffer[barIndex]; + return lTrendBuffer[barIndex]; } // - // Copy Required Items ... - int CopyLOpen( + // Copy Required Buffer ... + int CopyLTrend( int start, // Start int count, // Number of Items for read double &buffer[], // Dest Buffer @@ -1851,7 +1046,7 @@ public: return Copy( start, count, - lOpenBuffer, + lTrendBuffer, buffer, forceClean // @@ -1859,7 +1054,10 @@ public: } // - double GetLHigh( + // State ... + + // + ENUM_XCHSTR_TREND_STATES GetLState( int barIndex // Bar Index ) { @@ -1873,19 +1071,12 @@ public: Calculate(); // - int count = ArraySize(lHighBuffer); - if (barIndex >= count) - { - barIndex = count - 1; - } - - // - return lHighBuffer[barIndex]; + return (ENUM_XCHSTR_TREND_STATES)((int)lStateBuffer[barIndex]); } // - // Copy Required Items ... - int CopyLHigh( + // Copy Required Buffer ... + int CopyLState( int start, // Start int count, // Number of Items for read double &buffer[], // Dest Buffer @@ -1901,239 +1092,21 @@ public: return Copy( start, count, - lHighBuffer, + lStateBuffer, buffer, forceClean // ); } - // - double GetLLow( - int barIndex // Bar Index - ) - { - // - if (barIndex < 0) - { - barIndex = 0; - } - - // - Calculate(); - - // - int count = ArraySize(lLowBuffer); - if (barIndex >= count) - { - barIndex = count - 1; - } - - // - return lLowBuffer[barIndex]; - } - - // - // Copy Required Items ... - int CopyLLow( - 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, - lLowBuffer, - buffer, - forceClean - // - ); - } - - // - double GetLClose( - int barIndex // Bar Index - ) - { - // - if (barIndex < 0) - { - barIndex = 0; - } - - // - Calculate(); - - // - int count = ArraySize(lCloseBuffer); - if (barIndex >= count) - { - barIndex = count - 1; - } - - // - return lCloseBuffer[barIndex]; - } - - // - // Copy Required Items ... - int CopyLClose( - 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, - lCloseBuffer, - buffer, - forceClean - // - ); - } - - // - // Get XOHCL ... - bool LAsOHCL( - XOHCL &bar, // Holds Result - int barIndex // Bar Index - ) - { - // - bool result = false; - - // - if (barIndex < 0) - { - barIndex = 0; - } - - // - Calculate(); - - // - int count = ArraySize(lOpenBuffer); - if (barIndex >= count) - { - barIndex = count - 1; - } - - // - double open = GetLOpen(barIndex); - double high = GetLHigh(barIndex); - double close = GetLClose(barIndex); - double low = GetLLow(barIndex); - - // - result = bar.Init( - mSymbol, - mPeriod, - open, - high, - close, - low, - barIndex - // - ); - - // - return result; - } - - // - // Copy Required Items ... - int CopyLAsOHCL( - int start, // Start - int count, // Number of Items for read - XOHCL &buffer[], // Dest Buffer - bool forceClean = true // Force To Clean buffer - ) - { - // - int result = 0; - - // - // Update Calculations ... - Calculate(); - - // - if (forceClean) - { - Clean(buffer); - } - - // - int before = ArraySize(buffer); - - // - if (start < 0) - { - start = 0; - } - - // - if (start >= ArraySize(lOpenBuffer)) - { - start = ArraySize(lOpenBuffer) - 1; - } - - // - bool asSeriesBuffer = ArrayGetAsSeries(buffer); - ArraySetAsSeries(buffer, true); - - // - for (int i = start; i < start + count; i++) - { - // - XOHCL iBar; - bool isInit = LAsOHCL(iBar, i); - - // - if (isInit) - { - // - AddRef( - iBar, - buffer - // - ); - } - } - - // - ArraySetAsSeries(buffer, asSeriesBuffer); - - // - int after = ArraySize(buffer); - - // - result = after - before; - - // - return result; - } - // // Hind ... // - double GetHOpen( + // Trend ... + + // + double GetHTrend( int barIndex // Bar Index ) { @@ -2147,19 +1120,12 @@ public: Calculate(); // - int count = ArraySize(hOpenBuffer); - if (barIndex >= count) - { - barIndex = count - 1; - } - - // - return hOpenBuffer[barIndex]; + return hTrendBuffer[barIndex]; } // - // Copy Required Items ... - int CopyHOpen( + // Copy Required Buffer ... + int CopyHTrend( int start, // Start int count, // Number of Items for read double &buffer[], // Dest Buffer @@ -2175,7 +1141,7 @@ public: return Copy( start, count, - hOpenBuffer, + hTrendBuffer, buffer, forceClean // @@ -2183,7 +1149,10 @@ public: } // - double GetHHigh( + // State ... + + // + ENUM_XCHSTR_TREND_STATES GetHState( int barIndex // Bar Index ) { @@ -2197,19 +1166,12 @@ public: Calculate(); // - int count = ArraySize(hHighBuffer); - if (barIndex >= count) - { - barIndex = count - 1; - } - - // - return hHighBuffer[barIndex]; + return (ENUM_XCHSTR_TREND_STATES)((int)hStateBuffer[barIndex]); } // - // Copy Required Items ... - int CopyHHigh( + // Copy Required Buffer ... + int CopyHState( int start, // Start int count, // Number of Items for read double &buffer[], // Dest Buffer @@ -2225,7 +1187,7 @@ public: return Copy( start, count, - hHighBuffer, + hStateBuffer, buffer, forceClean // @@ -2233,221 +1195,43 @@ public: } // - double GetHLow( - int barIndex // Bar Index - ) + // Tools ... + + // + ENUM_XCHSTR_TREND_STATES ToState(double state) { - // - if (barIndex < 0) - { - barIndex = 0; - } - - // - Calculate(); - - // - int count = ArraySize(hLowBuffer); - if (barIndex >= count) - { - barIndex = count - 1; - } - - // - return hLowBuffer[barIndex]; + return (ENUM_XCHSTR_TREND_STATES)((int)state); } // - // Copy Required Items ... - int CopyHLow( - 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, - hLowBuffer, - buffer, - forceClean - // - ); - } - - // - double GetHClose( - int barIndex // Bar Index - ) - { - // - if (barIndex < 0) - { - barIndex = 0; - } - - // - Calculate(); - - // - int count = ArraySize(hCloseBuffer); - if (barIndex >= count) - { - barIndex = count - 1; - } - - // - return hCloseBuffer[barIndex]; - } - - // - // Copy Required Items ... - int CopyHClose( - 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, - hCloseBuffer, - buffer, - forceClean - // - ); - } - - // - // Get XOHCL ... - bool HAsOHCL( - XOHCL &bar, // Holds Result - int barIndex // Bar Index - ) + bool IsBullish(double state) { // bool result = false; // - if (barIndex < 0) - { - barIndex = 0; - } - - // - Calculate(); - - // - int count = ArraySize(hOpenBuffer); - if (barIndex >= count) - { - barIndex = count - 1; - } - - // - double open = GetHOpen(barIndex); - double high = GetHHigh(barIndex); - double close = GetHClose(barIndex); - double low = GetHLow(barIndex); - - // - result = bar.Init( - mSymbol, - mPeriod, - open, - high, - close, - low, - barIndex + result = // - ); + ToState(state) == X_STR_BULLISH; + // + ; // return result; } // - // Copy Required Items ... - int CopyHAsOHCL( - int start, // Start - int count, // Number of Items for read - XOHCL &buffer[], // Dest Buffer - bool forceClean = true // Force To Clean buffer - ) + bool IsBearish(double state) { // - int result = 0; + bool result = false; // - // Update Calculations ... - Calculate(); - - // - if (forceClean) - { - Clean(buffer); - } - - // - int before = ArraySize(buffer); - - // - if (start < 0) - { - start = 0; - } - - // - if (start >= ArraySize(hOpenBuffer)) - { - start = ArraySize(hOpenBuffer) - 1; - } - - // - bool asSeriesBuffer = ArrayGetAsSeries(buffer); - ArraySetAsSeries(buffer, true); - - // - for (int i = start; i < start + count; i++) - { + result = // - XOHCL iBar; - bool isInit = HAsOHCL(iBar, i); - - // - if (isInit) - { - // - AddRef( - iBar, - buffer - // - ); - } - } - + ToState(state) == X_STR_BEARISH; // - ArraySetAsSeries(buffer, asSeriesBuffer); - - // - int after = ArraySize(buffer); - - // - result = after - before; + ; // return result; @@ -2458,9 +1242,9 @@ public: // bool GetConditions( - XCHHKConditions &conditions, // - int barIndex = 0, // - int loopback = 5 // + XCHSTRConditions &conditions, // + int barIndex = 0, // + int loopback = 5 // ) { // @@ -2491,42 +1275,67 @@ public: // // Current ... - CopyCAsOHCL( + CopyCTrend( zIndex, loopback, - conditions.cBars // + conditions.cTrend // + ); + CopyCState( + zIndex, + loopback, + conditions.cState // ); // // Short ... - CopySAsOHCL( + CopyCTrend( zIndex, loopback, - conditions.sBars // + conditions.sTrend // + ); + CopyCState( + zIndex, + loopback, + conditions.sState // ); // // Medium ... - CopyMAsOHCL( + CopyCTrend( zIndex, loopback, - conditions.mBars // + conditions.mTrend // + ); + CopyCState( + zIndex, + loopback, + conditions.mState // ); // // Long ... - CopyLAsOHCL( + CopyCTrend( zIndex, loopback, - conditions.lBars // + conditions.lTrend // + ); + CopyCState( + zIndex, + loopback, + conditions.lState // ); // // Hind ... - CopyHAsOHCL( + CopyCTrend( zIndex, loopback, - conditions.hBars // + conditions.hTrend // + ); + CopyCState( + zIndex, + loopback, + conditions.hState // ); // @@ -2560,157 +1369,117 @@ public: // Current ... // - bool isCBullish = conditions.cBars[cIndex].IsBullish(); - bool isCBullishPrev = conditions.cBars[pIndex].IsBullish(); + bool isCBullish = IsBullish(conditions.cState[cIndex]); + bool isCBullishPrev = IsBullish(conditions.cState[pIndex]); // - bool isCBearish = conditions.cBars[cIndex].IsBearish(); - bool isCBearishPrev = conditions.cBars[pIndex].IsBearish(); + bool isCBearish = IsBearish(conditions.cState[cIndex]); + bool isCBearishPrev = IsBearish(conditions.cState[pIndex]); // bool isCSwitchedToBullish = isCBullish && - !isCBullishPrev; + !isCBullishPrev; bool isCSwitchedToBearish = isCBearish && - !isCBearishPrev; - - // - bool isCloseOverCHigh = cBar.close > conditions.cBars[cIndex].high; - bool isCloseUnderCLow = cBar.close < conditions.cBars[cIndex].low; + !isCBearishPrev; // conditions.isCBullish = isCBullish; - conditions.isCSwitchedToBullish = isCSwitchedToBullish; conditions.isCBearish = isCBearish; + conditions.isCSwitchedToBullish = isCSwitchedToBullish; conditions.isCSwitchedToBearish = isCSwitchedToBearish; - // - conditions.isCloseOverCHigh = isCloseOverCHigh; - conditions.isCloseUnderCLow = isCloseUnderCLow; - // // Short ... // - bool isSBullish = conditions.sBars[cIndex].IsBullish(); - bool isSBullishPrev = conditions.sBars[pIndex].IsBullish(); + bool isSBullish = IsBullish(conditions.sState[cIndex]); + bool isSBullishPrev = IsBullish(conditions.sState[pIndex]); // - bool isSBearish = conditions.sBars[cIndex].IsBearish(); - bool isSBearishPrev = conditions.sBars[pIndex].IsBearish(); + bool isSBearish = IsBearish(conditions.sState[cIndex]); + bool isSBearishPrev = IsBearish(conditions.sState[pIndex]); // bool isSSwitchedToBullish = isSBullish && - !isSBullishPrev; + !isSBullishPrev; bool isSSwitchedToBearish = isSBearish && - !isSBearishPrev; - - // - bool isCloseOverSHigh = cBar.close > conditions.sBars[cIndex].high; - bool isCloseUnderSLow = cBar.close < conditions.sBars[cIndex].low; + !isSBearishPrev; // conditions.isSBullish = isSBullish; - conditions.isSSwitchedToBullish = isSSwitchedToBullish; conditions.isSBearish = isSBearish; + conditions.isSSwitchedToBullish = isSSwitchedToBullish; conditions.isSSwitchedToBearish = isSSwitchedToBearish; - // - conditions.isCloseOverSHigh = isCloseOverSHigh; - conditions.isCloseUnderSLow = isCloseUnderSLow; - // // Medium ... // - bool isMBullish = conditions.mBars[cIndex].IsBullish(); - bool isMBullishPrev = conditions.mBars[pIndex].IsBullish(); + bool isMBullish = IsBullish(conditions.mState[cIndex]); + bool isMBullishPrev = IsBullish(conditions.mState[pIndex]); // - bool isMBearish = conditions.mBars[cIndex].IsBearish(); - bool isMBearishPrev = conditions.mBars[pIndex].IsBearish(); + bool isMBearish = IsBearish(conditions.mState[cIndex]); + bool isMBearishPrev = IsBearish(conditions.mState[pIndex]); // bool isMSwitchedToBullish = isMBullish && - !isMBullishPrev; + !isMBullishPrev; bool isMSwitchedToBearish = isMBearish && - !isMBearishPrev; - - // - bool isCloseOverMHigh = cBar.close > conditions.mBars[cIndex].high; - bool isCloseUnderMLow = cBar.close < conditions.mBars[cIndex].low; + !isMBearishPrev; // conditions.isMBullish = isMBullish; - conditions.isMSwitchedToBullish = isMSwitchedToBullish; conditions.isMBearish = isMBearish; + conditions.isMSwitchedToBullish = isMSwitchedToBullish; conditions.isMSwitchedToBearish = isMSwitchedToBearish; - // - conditions.isCloseOverMHigh = isCloseOverMHigh; - conditions.isCloseUnderMLow = isCloseUnderMLow; - // // Long ... // - bool isLBullish = conditions.lBars[cIndex].IsBullish(); - bool isLBullishPrev = conditions.lBars[pIndex].IsBullish(); + bool isLBullish = IsBullish(conditions.lState[cIndex]); + bool isLBullishPrev = IsBullish(conditions.lState[pIndex]); // - bool isLBearish = conditions.lBars[cIndex].IsBearish(); - bool isLBearishPrev = conditions.lBars[pIndex].IsBearish(); + bool isLBearish = IsBearish(conditions.lState[cIndex]); + bool isLBearishPrev = IsBearish(conditions.lState[pIndex]); // bool isLSwitchedToBullish = isLBullish && - !isLBullishPrev; + !isLBullishPrev; bool isLSwitchedToBearish = isLBearish && - !isLBearishPrev; - - // - bool isCloseOverLHigh = cBar.close > conditions.lBars[cIndex].high; - bool isCloseUnderLLow = cBar.close < conditions.lBars[cIndex].low; + !isLBearishPrev; // conditions.isLBullish = isLBullish; - conditions.isLSwitchedToBullish = isLSwitchedToBullish; conditions.isLBearish = isLBearish; + conditions.isLSwitchedToBullish = isLSwitchedToBullish; conditions.isLSwitchedToBearish = isLSwitchedToBearish; - // - conditions.isCloseOverLHigh = isCloseOverLHigh; - conditions.isCloseUnderLLow = isCloseUnderLLow; - // // Hind ... // - bool isHBullish = conditions.hBars[cIndex].IsBullish(); - bool isHBullishPrev = conditions.hBars[pIndex].IsBullish(); + bool isHBullish = IsBullish(conditions.hState[cIndex]); + bool isHBullishPrev = IsBullish(conditions.hState[pIndex]); // - bool isHBearish = conditions.hBars[cIndex].IsBearish(); - bool isHBearishPrev = conditions.hBars[pIndex].IsBearish(); + bool isHBearish = IsBearish(conditions.hState[cIndex]); + bool isHBearishPrev = IsBearish(conditions.hState[pIndex]); // bool isHSwitchedToBullish = isHBullish && - !isHBullishPrev; + !isHBullishPrev; bool isHSwitchedToBearish = isHBearish && - !isHBearishPrev; - - // - bool isCloseOverHHigh = cBar.close > conditions.hBars[cIndex].high; - bool isCloseUnderHLow = cBar.close < conditions.hBars[cIndex].low; + !isHBearishPrev; // conditions.isHBullish = isHBullish; - conditions.isHSwitchedToBullish = isHSwitchedToBullish; conditions.isHBearish = isHBearish; + conditions.isHSwitchedToBullish = isHSwitchedToBullish; conditions.isHSwitchedToBearish = isHSwitchedToBearish; - // - conditions.isCloseOverHHigh = isCloseOverHHigh; - conditions.isCloseUnderHLow = isCloseUnderHLow; - // return result; } @@ -2723,45 +1492,35 @@ protected: private: // // Props ... - XCHHKInputs mInputs; // Inputs ... + XCHSTRInputs mInputs; // Inputs ... // // Buffers ... // // Current ... - double cOpenBuffer[]; - double cHighBuffer[]; - double cLowBuffer[]; - double cCloseBuffer[]; + double cTrendBuffer[]; + double cStateBuffer[]; // // Short ... - double sOpenBuffer[]; - double sHighBuffer[]; - double sLowBuffer[]; - double sCloseBuffer[]; + double sTrendBuffer[]; + double sStateBuffer[]; // // Medium ... - double mOpenBuffer[]; - double mHighBuffer[]; - double mLowBuffer[]; - double mCloseBuffer[]; + double mTrendBuffer[]; + double mStateBuffer[]; // // Long ... - double lOpenBuffer[]; - double lHighBuffer[]; - double lLowBuffer[]; - double lCloseBuffer[]; + double lTrendBuffer[]; + double lStateBuffer[]; // // Hind ... - double hOpenBuffer[]; - double hHighBuffer[]; - double hLowBuffer[]; - double hCloseBuffer[]; + double hTrendBuffer[]; + double hStateBuffer[]; // // Tools ... @@ -2781,46 +1540,24 @@ private: // Current ... // - // Open ... + // Trend ... CopyBuffer( mHandler, - XCHHK_CO_LINE, + XCHSTR_C_LINE, 0, totalBars, - cOpenBuffer + cTrendBuffer // ); // - // High ... + // State ... CopyBuffer( mHandler, - XCHHK_CH_LINE, + XCHSTR_C_STATE_LINE, 0, totalBars, - cHighBuffer - // - ); - - // - // Low ... - CopyBuffer( - mHandler, - XCHHK_CL_LINE, - 0, - totalBars, - cLowBuffer - // - ); - - // - // Close ... - CopyBuffer( - mHandler, - XCHHK_CC_LINE, - 0, - totalBars, - cCloseBuffer + cStateBuffer // ); @@ -2828,46 +1565,24 @@ private: // Short ... // - // Open ... + // Trend ... CopyBuffer( mHandler, - XCHHK_SO_LINE, + XCHSTR_S_LINE, 0, totalBars, - sOpenBuffer + sTrendBuffer // ); // - // High ... + // State ... CopyBuffer( mHandler, - XCHHK_SH_LINE, + XCHSTR_S_STATE_LINE, 0, totalBars, - sHighBuffer - // - ); - - // - // Low ... - CopyBuffer( - mHandler, - XCHHK_SL_LINE, - 0, - totalBars, - sLowBuffer - // - ); - - // - // Close ... - CopyBuffer( - mHandler, - XCHHK_SC_LINE, - 0, - totalBars, - sCloseBuffer + sStateBuffer // ); @@ -2875,46 +1590,24 @@ private: // Medium ... // - // Open ... + // Trend ... CopyBuffer( mHandler, - XCHHK_MO_LINE, + XCHSTR_M_LINE, 0, totalBars, - mOpenBuffer + mTrendBuffer // ); // - // High ... + // State ... CopyBuffer( mHandler, - XCHHK_MH_LINE, + XCHSTR_M_STATE_LINE, 0, totalBars, - mHighBuffer - // - ); - - // - // Low ... - CopyBuffer( - mHandler, - XCHHK_ML_LINE, - 0, - totalBars, - mLowBuffer - // - ); - - // - // Close ... - CopyBuffer( - mHandler, - XCHHK_MC_LINE, - 0, - totalBars, - mCloseBuffer + mStateBuffer // ); @@ -2922,46 +1615,24 @@ private: // Long ... // - // Open ... + // Trend ... CopyBuffer( mHandler, - XCHHK_LO_LINE, + XCHSTR_L_LINE, 0, totalBars, - lOpenBuffer + lTrendBuffer // ); // - // High ... + // State ... CopyBuffer( mHandler, - XCHHK_LH_LINE, + XCHSTR_L_STATE_LINE, 0, totalBars, - lHighBuffer - // - ); - - // - // Low ... - CopyBuffer( - mHandler, - XCHHK_LL_LINE, - 0, - totalBars, - lLowBuffer - // - ); - - // - // Close ... - CopyBuffer( - mHandler, - XCHHK_LC_LINE, - 0, - totalBars, - lCloseBuffer + lStateBuffer // ); @@ -2969,46 +1640,24 @@ private: // Hind ... // - // Open ... + // Trend ... CopyBuffer( mHandler, - XCHHK_HO_LINE, + XCHSTR_H_LINE, 0, totalBars, - hOpenBuffer + hTrendBuffer // ); // - // High ... + // State ... CopyBuffer( mHandler, - XCHHK_HH_LINE, + XCHSTR_H_STATE_LINE, 0, totalBars, - hHighBuffer - // - ); - - // - // Low ... - CopyBuffer( - mHandler, - XCHHK_HL_LINE, - 0, - totalBars, - hLowBuffer - // - ); - - // - // Close ... - CopyBuffer( - mHandler, - XCHHK_HC_LINE, - 0, - totalBars, - hCloseBuffer + hStateBuffer // ); };