/////////////////////////////////////////////////////// // // SaherElm IT Center MQL5 Helper Class Library // ---------------------------------------------- // Name: XSCXCHVLMHelper // 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_XCHVLM_BUFFERS { // XCHVLM_C_LINE = 0, // XCHVLM_S_LINE = 2, // XCHVLM_M_LINE = 4, // XCHVLM_L_LINE = 6, // XCHVLM_H_LINE = 8, }; // enum ENUM_XCHVLM_STATES { // XCHVLM_BULLISH_STATE = 0, XCHVLM_BEARISH_STATE = 1, }; // // Input Models ... struct XCHVLMInputs { // // Props ... // // Market ... int length; // Length // // 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 showCurrent; // Show Current Cycle bool showShort; // Show Short Cycle bool showMedium; // Show Medium Cycle bool showLong; // Show Long Cycle bool showHind; // Show Hind Cycle // // Constructor(s) ... XCHVLMInputs() { // Clean(); } // // Tools ... // // Clean ... void Clean() { // length = 0; // scMethod = X_PERIOD_AUTO; scPeriod = NULL; mcMethod = X_PERIOD_AUTO; mcPeriod = NULL; lcMethod = X_PERIOD_AUTO; lcPeriod = NULL; hcMethod = X_PERIOD_AUTO; hcPeriod = NULL; // showCurrent = false; showShort = false; showMedium = false; showLong = false; showHind = false; } // // Default ... void Default() { // length = 14; // scMethod = X_PERIOD_AUTO; scPeriod = NULL; mcMethod = X_PERIOD_AUTO; mcPeriod = NULL; lcMethod = X_PERIOD_AUTO; lcPeriod = NULL; hcMethod = X_PERIOD_AUTO; hcPeriod = NULL; // showCurrent = true; showShort = true; showMedium = true; showLong = true; showHind = true; } // // Validate ... bool IsValid() { // bool result = false; // result = // length > 0 && // (IsValid(scMethod, scPeriod) && IsValid(mcMethod, mcPeriod) && IsValid(lcMethod, lcPeriod) && IsValid(hcMethod, hcPeriod)) // ; // return result; } // // Retrieve MAx Length ... int Max() { // int result = 0; // result = // MathMax(0, length) // ; // return result; } }; // // Define Conditions ... struct XCHVLMConditions { // // Common ... string symbol; ENUM_TIMEFRAMES period; datetime time; // // Buffers ... // // Current ... double cVolume[]; // // Short ... double sVolume[]; // // Medium ... double mVolume[]; // // Long ... double lVolume[]; // // Hind ... double hVolume[]; // // Conditions ... // // Power ... bool hasBullishPower; bool hasBearishPower; bool isBullishPowerUp; bool isBearishPowerUp; bool isBullishPowerIncreasing; bool isBullishPowerDecreasing; bool isBearishPowerIncreasing; bool isBearishPowerDecreasing; // // Current ... bool isCBullish; bool isCBearish; bool isCSwitchedToBullish; bool isCSwitchedToBearish; // // Short ... bool isSBullish; bool isSBearish; bool isSSwitchedToBullish; bool isSSwitchedToBearish; // // Medium ... bool isMBullish; bool isMBearish; bool isMSwitchedToBullish; bool isMSwitchedToBearish; // // Long ... bool isLBullish; bool isLBearish; bool isLSwitchedToBullish; bool isLSwitchedToBearish; // // Hind ... bool isHBullish; bool isHBearish; bool isHSwitchedToBullish; bool isHSwitchedToBearish; // void Clean() { // Clean(cVolume); Clean(sVolume); Clean(mVolume); Clean(lVolume); Clean(hVolume); // ArraySetAsSeries(cVolume, true); ArraySetAsSeries(sVolume, true); ArraySetAsSeries(mVolume, true); ArraySetAsSeries(lVolume, true); ArraySetAsSeries(hVolume, true); // // Conditions ... // // Power ... hasBullishPower = false; hasBearishPower = false; isBullishPowerUp = false; isBearishPowerUp = false; isBullishPowerIncreasing = false; isBullishPowerDecreasing = false; isBearishPowerIncreasing = false; isBearishPowerDecreasing = false; // // Current ... isCBullish = false; isCBearish = false; isCSwitchedToBullish = false; isCSwitchedToBearish = false; // // Short ... isSBullish = false; isSBearish = false; isSSwitchedToBullish = false; isSSwitchedToBearish = false; // // Medium ... isMBullish = false; isMBearish = false; isMSwitchedToBullish = false; isMSwitchedToBearish = false; // // Long ... isLBullish = false; isLBearish = false; isLSwitchedToBullish = false; isLSwitchedToBearish = false; // // Hind ... isHBullish = false; isHBearish = false; isHSwitchedToBullish = false; isHSwitchedToBearish = 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 ... // // Conditions ... // // Power ... if (hasBullishPower) { bullishScore++; } if (hasBearishPower) { bearishScore++; } if (isBullishPowerUp) { bullishScore++; } if (isBearishPowerUp) { bearishScore++; } if (isBullishPowerIncreasing) { bullishScore++; } if (isBullishPowerDecreasing) { bearishScore++; } if (isBearishPowerIncreasing) { bearishScore++; } if (isBearishPowerDecreasing) { bullishScore++; } // // Current ... if (isCBullish) { bullishScore++; } if (isCBearish) { bearishScore++; } if (isCSwitchedToBullish) { bullishScore++; } if (isCSwitchedToBearish) { bearishScore++; } // // Short ... if (isSBullish) { bullishScore++; } if (isSBearish) { bearishScore++; } if (isSSwitchedToBullish) { bullishScore++; } if (isSSwitchedToBearish) { bearishScore++; } // // Medium ... if (isMBullish) { bullishScore++; } if (isMBearish) { bearishScore++; } if (isMSwitchedToBullish) { bullishScore++; } if (isMSwitchedToBearish) { bearishScore++; } // // Long ... if (isLBullish) { bullishScore++; } if (isLBearish) { bearishScore++; } if (isLSwitchedToBullish) { bullishScore++; } if (isLSwitchedToBearish) { bearishScore++; } // // Hind ... if (isHBullish) { bullishScore++; } if (isHBearish) { bearishScore++; } if (isHSwitchedToBullish) { bullishScore++; } if (isHSwitchedToBearish) { 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 = // // Power ... ToString("hasBullishPower", hasBullishPower, ignoreFalseConditions, separator) + ToString("hasBearishPower", hasBearishPower, ignoreFalseConditions, separator) + ToString("isBullishPowerUp", isBullishPowerUp, ignoreFalseConditions, separator) + ToString("isBearishPowerUp", isBearishPowerUp, ignoreFalseConditions, separator) + ToString("isBullishPowerIncreasing", isBullishPowerIncreasing, ignoreFalseConditions, separator) + ToString("isBullishPowerDecreasing", isBullishPowerDecreasing, ignoreFalseConditions, separator) + ToString("isBearishPowerIncreasing", isBearishPowerIncreasing, ignoreFalseConditions, separator) + ToString("isBearishPowerDecreasing", isBearishPowerDecreasing, ignoreFalseConditions, separator) + // // Current ... ToString("isCBullish", isCBullish, ignoreFalseConditions, separator) + ToString("isCBearish", isCBearish, ignoreFalseConditions, separator) + ToString("isCSwitchedToBullish", isCSwitchedToBullish, ignoreFalseConditions, separator) + ToString("isCSwitchedToBearish", isCSwitchedToBearish, ignoreFalseConditions, separator) + // // Short ... ToString("isSBullish", isSBullish, ignoreFalseConditions, separator) + ToString("isSBearish", isSBearish, ignoreFalseConditions, separator) + ToString("isSSwitchedToBullish", isSSwitchedToBullish, ignoreFalseConditions, separator) + ToString("isSSwitchedToBearish", isSSwitchedToBearish, ignoreFalseConditions, separator) + // // Medium ... ToString("isMBullish", isMBullish, ignoreFalseConditions, separator) + ToString("isMBearish", isMBearish, ignoreFalseConditions, separator) + ToString("isMSwitchedToBullish", isMSwitchedToBullish, ignoreFalseConditions, separator) + ToString("isMSwitchedToBearish", isMSwitchedToBearish, ignoreFalseConditions, separator) + // // Long ... ToString("isLBullish", isLBullish, ignoreFalseConditions, separator) + ToString("isLBearish", isLBearish, ignoreFalseConditions, separator) + ToString("isLSwitchedToBullish", isLSwitchedToBullish, ignoreFalseConditions, separator) + ToString("isLSwitchedToBearish", isLSwitchedToBearish, ignoreFalseConditions, separator) + // // Hind ... ToString("isHBullish", isHBullish, ignoreFalseConditions, separator) + ToString("isHBearish", isHBearish, ignoreFalseConditions, separator) + ToString("isHSwitchedToBullish", isHSwitchedToBullish, ignoreFalseConditions, separator) + ToString("isHSwitchedToBearish", isHSwitchedToBearish, ignoreFalseConditions, separator) + // "" // ; // result = // "[" + GetTag() + "]" + separator + (onlyConditions ? "" : commonStr) + (!includeScores ? "" : scoresStr) + " " + separator + (onlyCommons ? "" : conditionsStr) + "" // ; // return result; } // string GetTag() { return "XCHVLM"; } }; // // Class ... class XSCXCHVLMHelper : public XSCBaseHelper { // // Public ... public: // // Props ... // // Constructors ... XSCXCHVLMHelper() : XSCBaseHelper(_Symbol, _Period) { } // // Deconstructor ... ~XSCXCHVLMHelper() { // Clean(cVolumeBuffer); Clean(sVolumeBuffer); Clean(mVolumeBuffer); Clean(lVolumeBuffer); Clean(hVolumeBuffer); } // // Tools ... bool Init( string symbol, // Trading Symbol ENUM_TIMEFRAMES period, // Trading Period XCHVLMInputs &inputs // Inputs ) { // bool result = false; // mSymbol = symbol; mPeriod = period; // result = inputs.IsValid(); if (!result) { return result; } // mInputs = inputs; // ArraySetAsSeries(cVolumeBuffer, true); ArraySetAsSeries(sVolumeBuffer, true); ArraySetAsSeries(mVolumeBuffer, true); ArraySetAsSeries(lVolumeBuffer, true); ArraySetAsSeries(hVolumeBuffer, true); // mHandler = iCustom( mSymbol, mPeriod, "x-saherelm.xchvlm", // // Inputs ... // // Market ... "", mInputs.length, // Length // // Cycles ... "", // // Short ... "", mInputs.scMethod, mInputs.scPeriod, // // Medium ... "", mInputs.mcMethod, mInputs.mcPeriod, // // Long ... "", mInputs.lcMethod, mInputs.lcPeriod, // // Hind ... "", mInputs.hcMethod, mInputs.hcPeriod, // // Presentation ... "", mInputs.showCurrent, mInputs.showShort, mInputs.showMedium, mInputs.showLong, mInputs.showHind // ); result = mHandler != INVALID_HANDLE; if (!result) { return result; } // return result; } // // Inputs ... // XCHVLMInputs GetInputs() { return mInputs; } // bool SetInputs( XCHVLMInputs &inputs // Configs ) { // return Init( mSymbol, mPeriod, inputs // ); } // // Buffers ... // // Current ... // double GetC( int barIndex // Bar Index ) { // if (barIndex < 0) { barIndex = 0; } // Calculate(); // return cVolumeBuffer[barIndex]; } // // Copy Required Buffer ... int CopyC( 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, cVolumeBuffer, buffer, forceClean // ); } // // Short ... // double GetS( int barIndex // Bar Index ) { // if (barIndex < 0) { barIndex = 0; } // Calculate(); // return sVolumeBuffer[barIndex]; } // // Copy Required Buffer ... int CopyS( 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, sVolumeBuffer, buffer, forceClean // ); } // // Medium ... // double GetM( int barIndex // Bar Index ) { // if (barIndex < 0) { barIndex = 0; } // Calculate(); // return mVolumeBuffer[barIndex]; } // // Copy Required Buffer ... int CopyM( 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, mVolumeBuffer, buffer, forceClean // ); } // // Long ... // double GetL( int barIndex // Bar Index ) { // if (barIndex < 0) { barIndex = 0; } // Calculate(); // return lVolumeBuffer[barIndex]; } // // Copy Required Buffer ... int CopyL( 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, lVolumeBuffer, buffer, forceClean // ); } // // Hind ... // double GetH( int barIndex // Bar Index ) { // if (barIndex < 0) { barIndex = 0; } // Calculate(); // return hVolumeBuffer[barIndex]; } // // Copy Required Buffer ... int CopyH( 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, hVolumeBuffer, buffer, forceClean // ); } // // Tools ... // ENUM_XCHVLM_STATES ToState(double value) { // ENUM_XCHVLM_STATES result = value >= 0 ? XCHVLM_BULLISH_STATE : XCHVLM_BEARISH_STATE; // return result; } // bool IsBullish(double value) { // bool result = false; // result = // ToState(value) == XCHVLM_BULLISH_STATE; // ; // return result; } // bool IsBearish(double value) { // bool result = false; // result = // ToState(value) == XCHVLM_BEARISH_STATE; // ; // return result; } // int GetValues( int barIndex, // Bar Index double &values[] // Result ) { // int result = 0; // Clean(values); // ENUM_X_MARKET_CYCLES cycles[]; int cyclesCount = GetAllMarketCycles(cycles); if (!IsValidSize(cyclesCount)) { return result; } // for (int i = 0; i < cyclesCount; i++) { // double iValue = GetCycleValue( barIndex, cycles[i] // ); // Add( iValue, values // ); } // result = ArraySize(values); // return result; } // double GetCycleValue( int barIndex, // Bar Index ENUM_X_MARKET_CYCLES cycle // Cycle ) { // double result = 0; // switch (cycle) { // // CURRENT ... case X_MARKET_CYCLE_UNKNOWN: result = GetC(barIndex); break; // // SHORT ... case X_MARKET_CYCLE_SHORT: result = GetS(barIndex); break; // // MEDIUM ... case X_MARKET_CYCLE_MEDIUM: result = GetM(barIndex); break; // // LONG ... case X_MARKET_CYCLE_LONG: result = GetL(barIndex); break; // // HIND ... case X_MARKET_CYCLE_HIND: result = GetH(barIndex); break; } // return result; } // int GetBullishCycles( int barIndex, // Bar Index ENUM_X_MARKET_CYCLES &cycles[] // Result ) { // int result = 0; // Clean(cycles); // ENUM_X_MARKET_CYCLES allCycles[]; int allCyclesCount = GetAllMarketCycles(allCycles); if (!IsValidSize(allCyclesCount)) { return result; } // for (int i = 0; i < allCyclesCount; i++) { // double cValue = GetCycleValue( barIndex, allCycles[i] // ); // if (IsBullish(cValue)) { // Add( allCycles[i], cycles // ); } } // result = ArraySize(cycles); // return result; } // int GetBearishCycles( int barIndex, // Bar Index ENUM_X_MARKET_CYCLES &cycles[] // Result ) { // int result = 0; // Clean(cycles); // ENUM_X_MARKET_CYCLES allCycles[]; int allCyclesCount = GetAllMarketCycles(allCycles); if (!IsValidSize(allCyclesCount)) { return result; } // for (int i = 0; i < allCyclesCount; i++) { // double cValue = GetCycleValue( barIndex, allCycles[i] // ); // if (IsBearish(cValue)) { // Add( allCycles[i], cycles // ); } } // result = ArraySize(cycles); // return result; } // int GetCyclesValues( int barIndex, // Bar Index double &values[], // Values ENUM_X_MARKET_CYCLES &cycles[] // Cycles ) { // int result = 0; // Clean(values); // int count = ArraySize(cycles); if (!IsValidSize(count)) { return result; } // for (int i = 0; i < count; i++) { // double iValue = GetCycleValue( barIndex, cycles[i] // ); // Add( iValue, values // ); } // result = ArraySize(values); // return result; } // int GetBullishCyclesValues( int barIndex, // Bar Index double &values[] // Values ) { // int result = 0; // Clean(values); // ENUM_X_MARKET_CYCLES cycles[]; int count = GetBullishCycles( barIndex, cycles // ); if (!IsValidSize(count)) { return result; } // result = GetCyclesValues( barIndex, values, cycles // ); // return result; } // int GetBearishCyclesValues( int barIndex, // Bar Index double &values[] // Values ) { // int result = 0; // Clean(values); // ENUM_X_MARKET_CYCLES cycles[]; int count = GetBearishCycles( barIndex, cycles // ); if (!IsValidSize(count)) { return result; } // result = GetCyclesValues( barIndex, values, cycles // ); // return result; } // double GetCyclesMax( int barIndex, // Bar Index ENUM_X_MARKET_CYCLES &cycles[] // Cycles ) { // double result = 0; // double values[]; int count = GetCyclesValues( barIndex, values, cycles // ); if (!IsValidSize(count)) { return result; } // result = GetSpecifiedMax(values); // return result; } // double GetCyclesMin( int barIndex, // Bar Index ENUM_X_MARKET_CYCLES &cycles[] // Cycles ) { // double result = 0; // double values[]; int count = GetCyclesValues( barIndex, values, cycles // ); if (!IsValidSize(count)) { return result; } // result = GetSpecifiedMin(values); // return result; } // double GetMax( int barIndex // Bar Index ) { // double result = 0; // double values[]; int valuesCount = GetValues( barIndex, values // ); if (!IsValidSize(valuesCount)) { return result; } // result = GetSpecifiedMax(values); // return result; } // double GetMin( int barIndex // Bar Index ) { // double result = 0; // double values[]; int valuesCount = GetValues( barIndex, values // ); if (!IsValidSize(valuesCount)) { return result; } // result = GetSpecifiedMin(values); // return result; } // double GetBullishPower( int barIndex // Bar Index ) { // double result = 0; // double values[]; int count = GetBullishCyclesValues( barIndex, values // ); if (!IsValidSize(count)) { return result; } // result = MathAbs(GetSum(values)); // return result; } // double GetBearishPower( int barIndex // Bar Index ) { // double result = 0; // double values[]; int count = GetBearishCyclesValues( barIndex, values // ); if (!IsValidSize(count)) { return result; } // result = MathAbs(GetSum(values)); // return result; } // double GetCyclesBullishPower( int barIndex, // Bar Index ENUM_X_MARKET_CYCLES &cycles[] // ) { // double result = 0; // int cyclesCount = ArraySize(cycles); if (!IsValidSize(cyclesCount)) { return result; } // for (int i = 0; i < cyclesCount; i++) { // double power = GetCycleValue( barIndex, cycles[i] // ); // if (IsBullish(power)) { result += MathAbs(power); } } // return result; } // double GetCyclesBearishPower( int barIndex, // Bar Index ENUM_X_MARKET_CYCLES &cycles[] // ) { // double result = 0; // int cyclesCount = ArraySize(cycles); if (!IsValidSize(cyclesCount)) { return result; } // for (int i = 0; i < cyclesCount; i++) { // double power = GetCycleValue( barIndex, cycles[i] // ); // if (IsBearish(power)) { result += MathAbs(power); } } // return result; } // bool HasBullishPower( int barIndex // Bar Index ) { // bool result = false; // double bullishPower = GetBullishPower(barIndex); double bearishPower = GetBearishPower(barIndex); // result = // bearishPower >= 0 && bullishPower > bearishPower // ; // return result; } // bool HasBearishPower( int barIndex // Bar Index ) { // bool result = false; // double bullishPower = GetBullishPower(barIndex); double bearishPower = GetBearishPower(barIndex); // result = // bullishPower >= 0 && bearishPower > bullishPower // ; // return result; } // bool HasCyclesBullishPower( int barIndex, // Bar Index ENUM_X_MARKET_CYCLES &cycles[] // ) { // bool result = false; // double bullishPower = GetCyclesBullishPower(barIndex, cycles); double bearishPower = GetCyclesBearishPower(barIndex, cycles); // result = // bearishPower >= 0 && bullishPower > bearishPower // ; // return result; } // bool HasCyclesBearishPower( int barIndex, // Bar Index ENUM_X_MARKET_CYCLES &cycles[] // ) { // bool result = false; // double bullishPower = GetCyclesBullishPower(barIndex, cycles); double bearishPower = GetCyclesBearishPower(barIndex, cycles); // result = // bullishPower >= 0 && bearishPower > bullishPower // ; // return result; } // // Check Bullish Power Increasing ... bool IsBullishPowerIncreasing( int barIndex, // Bar Index int loopback = 5 // Loopback ) { // bool result = false; // if (loopback <= 0) { loopback = 5; } // double firstPower = GetBullishPower(barIndex); double lastPower = firstPower; for (int i = barIndex + 1; i < barIndex + loopback; i++) { // double iPower = GetBullishPower(i); // result = // iPower > 0 && firstPower > 0 && lastPower > iPower // ; if (!result) { break; } // lastPower = iPower; } // if (result) { // result = // firstPower > lastPower // ; } // return result; } // // Check Bullish Power Decreasing ... bool IsBullishPowerDecreasing( int barIndex, // Bar Index int loopback = 5 // Loopback ) { // bool result = false; // if (loopback <= 0) { loopback = 5; } // double firstPower = GetBullishPower(barIndex); double lastPower = firstPower; for (int i = barIndex + 1; i < barIndex + loopback; i++) { // double iPower = GetBullishPower(i); // result = // iPower > 0 && firstPower > 0 && lastPower < iPower // ; if (!result) { break; } // lastPower = iPower; } // if (result) { // result = // firstPower < lastPower // ; } // return result; } // // Check Bearish Power Increasing ... bool IsBearishPowerIncreasing( int barIndex, // Bar Index int loopback = 5 // Loopback ) { // bool result = false; // if (loopback <= 0) { loopback = 5; } // double firstPower = GetBearishPower(barIndex); double lastPower = firstPower; for (int i = barIndex + 1; i < barIndex + loopback; i++) { // double iPower = GetBearishPower(i); // result = // iPower > 0 && firstPower > 0 && lastPower > iPower // ; if (!result) { break; } // lastPower = iPower; } // if (result) { // result = // firstPower > lastPower // ; } // return result; } // // Check Bearish Power Decreasing ... bool IsBearishPowerDecreasing( int barIndex, // Bar Index int loopback = 5 // Loopback ) { // bool result = false; // if (loopback <= 0) { loopback = 5; } // double firstPower = GetBearishPower(barIndex); double lastPower = firstPower; for (int i = barIndex + 1; i < barIndex + loopback; i++) { // double iPower = GetBearishPower(i); // result = // iPower > 0 && firstPower > 0 && lastPower < iPower // ; if (!result) { break; } // lastPower = iPower; } // if (result) { // result = // firstPower < lastPower // ; } // return result; } // // Check Bullish Power Increasing ... bool IsCyclesBullishPowerIncreasing( int barIndex, // Bar Index ENUM_X_MARKET_CYCLES &cycles[], // int loopback = 5 // Loopback ) { // bool result = false; // if (loopback <= 0) { loopback = 5; } // double firstPower = GetCyclesBullishPower(barIndex, cycles); double lastPower = firstPower; for (int i = barIndex + 1; i < barIndex + loopback; i++) { // double iPower = GetCyclesBullishPower(i, cycles); // result = // iPower > 0 && firstPower > 0 && lastPower > iPower // ; if (!result) { break; } // lastPower = iPower; } // if (result) { // result = // firstPower > lastPower // ; } // return result; } // // Check Bullish Power Decreasing ... bool IsCyclesBullishPowerDecreasing( int barIndex, // Bar Index ENUM_X_MARKET_CYCLES &cycles[], // int loopback = 5 // Loopback ) { // bool result = false; // if (loopback <= 0) { loopback = 5; } // double firstPower = GetCyclesBullishPower(barIndex, cycles); double lastPower = firstPower; for (int i = barIndex + 1; i < barIndex + loopback; i++) { // double iPower = GetCyclesBullishPower(i, cycles); // result = // iPower > 0 && firstPower > 0 && lastPower < iPower // ; if (!result) { break; } // lastPower = iPower; } // if (result) { // result = // firstPower < lastPower // ; } // return result; } // // Check Bearish Power Increasing ... bool IsCyclesBearishPowerIncreasing( int barIndex, // Bar Index ENUM_X_MARKET_CYCLES &cycles[], // int loopback = 5 // Loopback ) { // bool result = false; // if (loopback <= 0) { loopback = 5; } // double firstPower = GetCyclesBearishPower(barIndex, cycles); double lastPower = firstPower; for (int i = barIndex + 1; i < barIndex + loopback; i++) { // double iPower = GetCyclesBearishPower(i, cycles); // result = // iPower > 0 && firstPower > 0 && lastPower > iPower // ; if (!result) { break; } // lastPower = iPower; } // if (result) { // result = // firstPower > lastPower // ; } // return result; } // // Check Bearish Power Decreasing ... bool IsCyclesBearishPowerDecreasing( int barIndex, // Bar Index ENUM_X_MARKET_CYCLES &cycles[], // int loopback = 5 // Loopback ) { // bool result = false; // if (loopback <= 0) { loopback = 5; } // double firstPower = GetCyclesBearishPower(barIndex, cycles); double lastPower = firstPower; for (int i = barIndex + 1; i < barIndex + loopback; i++) { // double iPower = GetCyclesBearishPower(i, cycles); // result = // iPower > 0 && firstPower > 0 && lastPower < iPower // ; if (!result) { break; } // lastPower = iPower; } // if (result) { // result = // firstPower < lastPower // ; } // return result; } // // Conditions ... // bool GetConditions( XCHVLMConditions &conditions, // int barIndex = 0, // int loopback = 5 // ) { // bool result = true; // if (loopback < 5) { loopback = 5; } // 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 ... // // Current ... CopyC( zIndex, loopback, conditions.cVolume // ); // // Short ... CopyS( zIndex, loopback, conditions.sVolume // ); // // Medium ... CopyM( zIndex, loopback, conditions.mVolume // ); // // Long ... CopyL( zIndex, loopback, conditions.lVolume // ); // // Hind ... CopyH( zIndex, loopback, conditions.hVolume // ); // // 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; } // // Power ... // bool hasBullishPower = HasBullishPower(cIndex); bool hasBullishPowerPrev = HasBullishPower(pIndex); // bool hasBearishPower = HasBearishPower(cIndex); bool hasBearishPowerPrev = HasBearishPower(pIndex); // bool isBullishPowerUp = hasBullishPower && !hasBullishPowerPrev; bool isBearishPowerUp = hasBearishPower && !hasBearishPowerPrev; // bool isBullishPowerIncreasing = IsBullishPowerIncreasing(cIndex); bool isBullishPowerDecreasing = IsBullishPowerDecreasing(cIndex); bool isBearishPowerIncreasing = IsBearishPowerIncreasing(cIndex); bool isBearishPowerDecreasing = IsBearishPowerDecreasing(cIndex); // conditions.hasBullishPower = hasBullishPower; conditions.hasBearishPower = hasBearishPower; conditions.isBullishPowerUp = isBullishPowerUp; conditions.isBearishPowerUp = isBearishPowerUp; conditions.isBullishPowerIncreasing = isBullishPowerIncreasing; conditions.isBullishPowerDecreasing = isBullishPowerDecreasing; conditions.isBearishPowerIncreasing = isBearishPowerIncreasing; conditions.isBearishPowerDecreasing = isBearishPowerDecreasing; // // Current ... // bool isCBullish = IsBullish(conditions.cVolume[cIndex]); bool isCBullishPrev = IsBullish(conditions.cVolume[pIndex]); // bool isCBearish = IsBearish(conditions.cVolume[cIndex]); bool isCBearishPrev = IsBearish(conditions.cVolume[pIndex]); // bool isCSwitchedToBullish = isCBullish && !isCBullishPrev; bool isCSwitchedToBearish = isCBearish && !isCBearishPrev; // conditions.isCBullish = isCBullish; conditions.isCBearish = isCBearish; conditions.isCSwitchedToBullish = isCSwitchedToBullish; conditions.isCSwitchedToBearish = isCSwitchedToBearish; // // Short ... // bool isSBullish = IsBullish(conditions.sVolume[cIndex]); bool isSBullishPrev = IsBullish(conditions.sVolume[pIndex]); // bool isSBearish = IsBearish(conditions.sVolume[cIndex]); bool isSBearishPrev = IsBearish(conditions.sVolume[pIndex]); // bool isSSwitchedToBullish = isSBullish && !isSBullishPrev; bool isSSwitchedToBearish = isSBearish && !isSBearishPrev; // conditions.isSBullish = isSBullish; conditions.isSBearish = isSBearish; conditions.isSSwitchedToBullish = isSSwitchedToBullish; conditions.isSSwitchedToBearish = isSSwitchedToBearish; // // Medium ... // bool isMBullish = IsBullish(conditions.mVolume[cIndex]); bool isMBullishPrev = IsBullish(conditions.mVolume[pIndex]); // bool isMBearish = IsBearish(conditions.mVolume[cIndex]); bool isMBearishPrev = IsBearish(conditions.mVolume[pIndex]); // bool isMSwitchedToBullish = isMBullish && !isMBullishPrev; bool isMSwitchedToBearish = isMBearish && !isMBearishPrev; // conditions.isMBullish = isMBullish; conditions.isMBearish = isMBearish; conditions.isMSwitchedToBullish = isMSwitchedToBullish; conditions.isMSwitchedToBearish = isMSwitchedToBearish; // // Long ... // bool isLBullish = IsBullish(conditions.lVolume[cIndex]); bool isLBullishPrev = IsBullish(conditions.lVolume[pIndex]); // bool isLBearish = IsBearish(conditions.lVolume[cIndex]); bool isLBearishPrev = IsBearish(conditions.lVolume[pIndex]); // bool isLSwitchedToBullish = isLBullish && !isLBullishPrev; bool isLSwitchedToBearish = isLBearish && !isLBearishPrev; // conditions.isLBullish = isLBullish; conditions.isLBearish = isLBearish; conditions.isLSwitchedToBullish = isLSwitchedToBullish; conditions.isLSwitchedToBearish = isLSwitchedToBearish; // // Hind ... // bool isHBullish = IsBullish(conditions.hVolume[cIndex]); bool isHBullishPrev = IsBullish(conditions.hVolume[pIndex]); // bool isHBearish = IsBearish(conditions.hVolume[cIndex]); bool isHBearishPrev = IsBearish(conditions.hVolume[pIndex]); // bool isHSwitchedToBullish = isHBullish && !isHBullishPrev; bool isHSwitchedToBearish = isHBearish && !isHBearishPrev; // conditions.isHBullish = isHBullish; conditions.isHBearish = isHBearish; conditions.isHSwitchedToBullish = isHSwitchedToBullish; conditions.isHSwitchedToBearish = isHSwitchedToBearish; // return result; } // // Protected ... protected: // // Private ... private: // // Props ... XCHVLMInputs mInputs; // Inputs ... // // Buffers ... // // Current ... double cVolumeBuffer[]; // // Short ... double sVolumeBuffer[]; // // Medium ... double mVolumeBuffer[]; // // Long ... double lVolumeBuffer[]; // // Hind ... double hVolumeBuffer[]; // // Tools ... // // Calculate Values Until Now ... void Calculate() { // int totalBars = CountBars(); if (totalBars > 1000) { totalBars = 1000; } // // Current ... CopyBuffer( mHandler, XCHVLM_C_LINE, 0, totalBars, cVolumeBuffer // ); // // Short ... CopyBuffer( mHandler, XCHVLM_S_LINE, 0, totalBars, sVolumeBuffer // ); // // Medium ... CopyBuffer( mHandler, XCHVLM_M_LINE, 0, totalBars, mVolumeBuffer // ); // // Long ... CopyBuffer( mHandler, XCHVLM_L_LINE, 0, totalBars, lVolumeBuffer // ); // // Hind ... CopyBuffer( mHandler, XCHVLM_H_LINE, 0, totalBars, hVolumeBuffer // ); }; }; //