/////////////////////////////////////////////////////// // // SaherElm IT Center MQL5 Helper Class Library // ---------------------------------------------- // Name: XCX121XVOLUMESHelper // 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.x-helper.class.mq5" // // Definitions ... enum ENUM_X121_XVOLUME_BUFFERS { // X121_XVOLUME_BULLISH_LINE = 0, X121_XVOLUME_BULLISH_MA_LINE = 1, X121_XVOLUME_BEARISH_LINE = 2, X121_XVOLUME_BEARISH_MA_LINE = 3, }; // // Input Models ... struct X121XVOLUMEInputs { // // Props ... // // Makret ... int maLength; // Moving Averge Length ENUM_X_MA_METHOD maMethod; // Moving Averge Method // // Presentation ... int startCalculationForLastBars; // Calculate Last n Bars bool showBullishVolume; // Show Bullish Volume bool showBullishVolumeMa; // Show Bullish Volume Moving Average bool showBearishVolume; // Show Bearish Volume bool showBearishVolumeMa; // Show Bearish Volume Moving Average // // Constructor(s) ... X121XVOLUMEInputs() { Clean(); } // // Tools ... /** * Cleanup Model ... */ void Clean() { // // Makret ... maLength = 0; // Moving Averge Length maMethod = X_MA_MODE_NONE; // Moving Averge Method // // Presentation ... startCalculationForLastBars = 0; // Calculate Last n Bars showBullishVolume = false; // Show Bullish Volume showBullishVolumeMa = false; // Show Bullish Volume Moving Average showBearishVolume = false; // Show Bearish Volume showBearishVolumeMa = false; // Show Bearish Volume Moving Average // ZeroMemory(this); } /** * Default Inputs ... */ void Default() { // // Makret ... maLength = 14; // Moving Averge Length maMethod = X_MA_MODE_EMA; // Moving Averge Method // // Presentation ... startCalculationForLastBars = 1000; // Calculate Last n Bars showBullishVolume = true; // Show Bullish Volume showBullishVolumeMa = true; // Show Bullish Volume Moving Average showBearishVolume = true; // Show Bearish Volume showBearishVolumeMa = true; // Show Bearish Volume Moving Average } /** * Validate Model ... * * @return ( bool ) */ bool IsValid() { // bool result = false; // result = // maLength > 0 && IsValid(maMethod) // ; // return result; } /** * Retrieve Max Input Length ... * * @return ( int ) */ int Max() { // int result = 0; // result = MathMax(result, maLength); // return result; } // }; // // Conditions ... struct X121XVOLUMEConditions { // // Common ... string symbol; ENUM_TIMEFRAMES period; datetime time; // // Buffers ... double bullishVolumeBuffer[]; double bullishVolumeMaBuffer[]; double bearishVolumeBuffer[]; double bearishVolumeMaBuffer[]; // // Conditions ... // // Constructor ... X121XVOLUMEConditions() { Clean(); } // // Tools ... /** * Cleaning Up ... */ void Clean() { // // Commons ... time = NULL; symbol = NULL; period = NULL; // // Buffers ... // Clean(bullishVolumeBuffer); Clean(bullishVolumeMaBuffer); Clean(bearishVolumeBuffer); Clean(bearishVolumeMaBuffer); // ArraySetAsSeries(bullishVolumeBuffer, true); ArraySetAsSeries(bullishVolumeMaBuffer, true); ArraySetAsSeries(bearishVolumeBuffer, true); ArraySetAsSeries(bearishVolumeMaBuffer, true); // // Conditions ... // ZeroMemory(this); } /** * Generate Conditions Scores ... * * @param bullishScore: Double, Directional Scores Reference ... * @param bearishScore: Double, Directional Scores Reference ... */ void GenerateScore( double &bullishScore, double &bearishScore // ) { // bullishScore = 0; bearishScore = 0; // // TODO: Implement if Required ... } /** * Generate Summary String for Represent Conditions State ... * * @param onlyCommons: Boolean, Just Generate Only Commons Conditions ... * @param onlyConditions: Boolean, Just Generate Only Conditions ... * @param includeScores: Boolean, Attach Scores Representations on Result ... * @param ignoreFalseConditions: Boolean, Ignore False Conditions on Result ... * @param separator: String, Separate Lines ... * * @return ( string ) */ 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 = // // "" // ; // result = // "[" + GetTag() + "]" + separator + (onlyConditions ? "" : commonStr) + (!includeScores ? "" : scoresStr) + " " + separator + (onlyCommons ? "" : conditionsStr) + "" // ; // return result; } /** * Retrieve nique Tag Identifier ... * * @return ( string ) */ string GetTag() { return GetTypeName(this); } // }; // // Class ... class XCX121XVOLUMEHelper : public XCBaseHelper { // // Public ... public: // // Props ... // // Constructors ... XCX121XVOLUMEHelper() : XCBaseHelper(_Symbol, _Period) { } // // Deconstructor ... ~XCX121XVOLUMEHelper() { // mInputs.Clean(); // Clean(bullishVolumeBuffer); Clean(bullishVolumeMaBuffer); Clean(bearishVolumeBuffer); Clean(bearishVolumeMaBuffer); } // // Tools ... bool Init( string symbol, // Trading Symbol ENUM_TIMEFRAMES period, // Trading Period X121XVOLUMEInputs &inputs // Inputs ) { // bool result = false; // mSymbol = symbol; mPeriod = period; // result = inputs.IsValid(); if (!result) { return result; } // ArraySetAsSeries(bullishVolumeBuffer, true); ArraySetAsSeries(bullishVolumeMaBuffer, true); ArraySetAsSeries(bearishVolumeBuffer, true); ArraySetAsSeries(bearishVolumeMaBuffer, true); // mInputs = inputs; // mHandler = iCustom( mSymbol, mPeriod, "x-saherelm.x121.xvolume", // // Inputs ... // // Market ... "", mInputs.maLength, mInputs.maMethod, // // Presentation ... "", // mInputs.startCalculationForLastBars, mInputs.showBullishVolume, mInputs.showBullishVolumeMa, mInputs.showBearishVolume, mInputs.showBearishVolumeMa // ); result = mHandler != INVALID_HANDLE; if (!result) { return result; } // return result; } // // Inputs ... // X121XVOLUMEInputs GetInputs() { return mInputs; } // bool SetInputs( X121XVOLUMEInputs &inputs // Configs ) { // return Init( mSymbol, mPeriod, inputs // ); } // // Readers ... // // Bullish ... // double GetBullishVolume( int barIndex // Bar Index ) { // if (barIndex < 0) { barIndex = 0; } // Calculate(); // int count = ArraySize(bullishVolumeBuffer); if (barIndex >= count) { barIndex = count - 1; } // return bullishVolumeBuffer[barIndex]; } // int CopyBullishVolume( 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, bullishVolumeBuffer, buffer, forceClean // ); } // double GetBullishVolumeMa( int barIndex // Bar Index ) { // if (barIndex < 0) { barIndex = 0; } // Calculate(); // int count = ArraySize(bullishVolumeMaBuffer); if (barIndex >= count) { barIndex = count - 1; } // return bullishVolumeMaBuffer[barIndex]; } // int CopyBullishVolumeMa( 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, bullishVolumeMaBuffer, buffer, forceClean // ); } // // Bearish ... // double GetBearishVolume( int barIndex // Bar Index ) { // if (barIndex < 0) { barIndex = 0; } // Calculate(); // int count = ArraySize(bearishVolumeBuffer); if (barIndex >= count) { barIndex = count - 1; } // return bearishVolumeBuffer[barIndex]; } // int CopyBearishVolume( 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, bearishVolumeBuffer, buffer, forceClean // ); } // double GetBearishVolumeMa( int barIndex // Bar Index ) { // if (barIndex < 0) { barIndex = 0; } // Calculate(); // int count = ArraySize(bearishVolumeMaBuffer); if (barIndex >= count) { barIndex = count - 1; } // return bearishVolumeMaBuffer[barIndex]; } // int CopyBearishVolumeMa( 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, bearishVolumeMaBuffer, buffer, forceClean // ); } // bool GetConditions( X121XVOLUMEConditions &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; // XOHCL zBar; result = zBar.Init( mSymbol, mPeriod, zIndex // ); if (!result) { return result; } // XOHCL cBar; result = cBar.Init( mSymbol, mPeriod, cIndex // ); if (!result) { return result; } // XOHCL pBar; result = pBar.Init( mSymbol, mPeriod, pIndex // ); if (!result) { return result; } // // Buffers ... // CopyBullishVolume( zIndex, loopback, conditions.bullishVolumeBuffer // ); // CopyBullishVolumeMa( zIndex, loopback, conditions.bullishVolumeMaBuffer // ); // CopyBearishVolume( zIndex, loopback, conditions.bearishVolumeBuffer // ); // CopyBearishVolumeMa( zIndex, loopback, conditions.bearishVolumeMaBuffer // ); // // Conditions ... // int cIDX = 1; int pIDX = cIDX + 1; // // SAR ... // Cleanup(); // zBar.Clean(); cBar.Clean(); pBar.Clean(); // return result; } // // Protected ... protected: // // Private ... private: // // Props ... X121XVOLUMEInputs mInputs; // Inputs ... // // Buffers ... double bullishVolumeBuffer[]; double bullishVolumeMaBuffer[]; double bearishVolumeBuffer[]; double bearishVolumeMaBuffer[]; // void Calculate( int maxRequiredBars = 100 // ) { // // Buffers ... // CopyBuffer( mHandler, X121_XVOLUME_BULLISH_LINE, 0, maxRequiredBars, bullishVolumeBuffer // ); // CopyBuffer( mHandler, X121_XVOLUME_BULLISH_MA_LINE, 0, maxRequiredBars, bullishVolumeMaBuffer // ); // CopyBuffer( mHandler, X121_XVOLUME_BEARISH_LINE, 0, maxRequiredBars, bearishVolumeBuffer // ); // CopyBuffer( mHandler, X121_XVOLUME_BEARISH_MA_LINE, 0, maxRequiredBars, bearishVolumeMaBuffer // ); } // void Cleanup( int maxAllowed = 100 // ) { // CleanupArray( bullishVolumeBuffer, maxAllowed // ); // CleanupArray( bullishVolumeMaBuffer, maxAllowed // ); // CleanupArray( bearishVolumeBuffer, maxAllowed // ); // CleanupArray( bearishVolumeMaBuffer, maxAllowed // ); } // }; //