/////////////////////////////////////////////////////// // // SaherElm IT Center MQL5 Class Library // -------------------------------------- // Name: XTRND Indicator Provider // Description: Trend Finder ... // // // 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 // // START Import and Inclused requirements ... // // // Includes ... #include "../Libraries/x-saherelm.alert.lib.mq5" #include "../Libraries/x-saherelm.models.lib.mq5" #include "../Libraries/x-saherelm.common.lib.mq5" // // END Import and Inclused requirements ... // // // START Definitions ... // // // XPeaksAndVales Exported Buffers ... enum ENUM_X_XTRND_BUFFERS { // X_TRND_UP_LINE = 0, X_TRND_UP_STATE_LINE = 1, // X_TRND_DOWN_LINE = 2, X_TRND_DOWN_STATE_LINE = 3, }; // // Trend State at unique Bar ... enum ENUM_X_XTRND_STATE { X_TRND_STATE_RANGE = 0, X_TRND_STATE_CONSOLIDATION = 1, X_TRND_STATE_UP = 2, X_TRND_STATE_DOWN = 3, }; // // END Definitions ... // // // START Overrides ... // // // END Overrides ... // class XSCXTRNDHelper { // public: // // Properties ... double upBuffer[]; double upStateBuffer[]; double downBuffer[]; double downStateBuffer[]; // // Constructor ... void XSCXTRNDHelper() { mSymbol = _Symbol; mPeriod = _Period; } void XSCXTRNDHelper( // // Symbol ... string symbol, // // Period ... ENUM_TIMEFRAMES period, // // Buffer Reading ... int numberOfItemsReadPerTick = 52, // // MARKET ... int cycleLength = 2, // Cycle Length to Check int numberOfVerifications = 2, // Number of Verifications // // CALCULATION ... ENUM_SERIESMODE hhMode = MODE_HIGH, // Detect Up ENUM_SERIESMODE llMode = MODE_LOW // Detect Low // ) { // // Setting Requirements ... // // Symbol ... mSymbol = symbol; // // Period ... mPeriod = period; // // Number of Reading Buffer Items per Tick ... mNumberOfItemsReadPerTick = numberOfItemsReadPerTick; // // MARKET ... mCycleLength = cycleLength; mNumberOfVerifications = numberOfVerifications; // // CALCULATIONS ... mHHMode = hhMode; mLLMode = llMode; // mTag = "XTRND " + mSymbol + ", " + ToString(mPeriod); // // Initial Handler ... mHandler = iCustom( mSymbol, mPeriod, "x-saherelm.x121.xtrnd", // // Inputs ... // // MARKET ... "", mCycleLength, mNumberOfVerifications, // // CALCULATIONS ... "", mHHMode, mLLMode, // // PRESENTATION ... "", false, false // ); if (mHandler == INVALID_HANDLE) { LogMessage("failed to Initialize Indicator: " + (string)GetLastError()); } // ArraySetAsSeries(upBuffer, true); ArraySetAsSeries(upStateBuffer, true); ArraySetAsSeries(downBuffer, true); ArraySetAsSeries(downStateBuffer, true); } // // DeConstructor ... void ~XSCXTRNDHelper() { // // Release Indicators ... IndicatorRelease(mHandler); } // // Reading Buffers ... void ReadBuffers() { // // UP ... CopyBuffer( mHandler, X_TRND_UP_LINE, 0, mNumberOfItemsReadPerTick, upBuffer); // // UP STATE ... CopyBuffer( mHandler, X_TRND_UP_STATE_LINE, 0, mNumberOfItemsReadPerTick, upStateBuffer); // // DOWN ... CopyBuffer( mHandler, X_TRND_DOWN_LINE, 0, mNumberOfItemsReadPerTick, downBuffer); // // DOWN STATE ... CopyBuffer( mHandler, X_TRND_DOWN_STATE_LINE, 0, mNumberOfItemsReadPerTick, downStateBuffer); } // // START Tools Functions ... // // // Detect Trend Up ... bool IsTrendBullish( int bar_index // Bar Index ... ) { // bool result = false; // if (!IsValidArraySize(bar_index)) { return result; } // result = // upStateBuffer[bar_index] == X_TRND_STATE_UP && downStateBuffer[bar_index] == X_TRND_STATE_UP // ; // return result; } // // Detect Trend Switched Up ... bool IsTrendSwitchedBullish( int bar_index // Bar Index ... ) { // bool result = false; // if (!IsValidArraySize(bar_index + 1)) { return result; } // result = // IsTrendBullish(bar_index) && !IsTrendBullish(bar_index + 1) // ; // return result; } // // Detect Trend Down ... bool IsTrendBearish( int bar_index // Bar Index ... ) { // bool result = false; // if (!IsValidArraySize(bar_index)) { return result; } // result = // upStateBuffer[bar_index] == X_TRND_STATE_DOWN && downStateBuffer[bar_index] == X_TRND_STATE_DOWN // ; // return result; } // // Detect Trend Switched Down ... bool IsTrendSwitchedBearish( int bar_index // Bar Index ... ) { // bool result = false; // if (!IsValidArraySize(bar_index + 1)) { return result; } // result = // IsTrendBearish(bar_index) && !IsTrendBearish(bar_index + 1) // ; // return result; } // // Detect Trend Consolidation ... bool IsTrendConsolidation( int bar_index // Bar Index ... ) { // bool result = false; // if (!IsValidArraySize(bar_index)) { return result; } // result = // (upStateBuffer[bar_index] == X_TRND_STATE_RANGE || upStateBuffer[bar_index] == X_TRND_STATE_CONSOLIDATION) // && // (downStateBuffer[bar_index] == X_TRND_STATE_RANGE || downStateBuffer[bar_index] == X_TRND_STATE_CONSOLIDATION) // ; // return result; } // // Detect Trend Switched Consolidation ... bool IsTrendSwitchedConsolidation( int bar_index // Bar Index ... ) { // bool result = false; // if (!IsValidArraySize(bar_index + 1)) { return result; } // result = // IsTrendConsolidation(bar_index) && !IsTrendConsolidation(bar_index + 1) // ; // return result; } // // END Tools Functions ... // // protected: // private: // // Symbol ... string mSymbol; // // Period ... ENUM_TIMEFRAMES mPeriod; // // Buffer Reading ... int mNumberOfItemsReadPerTick; // string mTag; // int mHandler; // // INPUTS ... // // MARKET ... // // Cycle Length to Check ... int mCycleLength; // // Number of Verifications ... int mNumberOfVerifications; // // CALCULATIONS ... // // Detect Up ... ENUM_SERIESMODE mHHMode; // // Detect Low ... ENUM_SERIESMODE mLLMode; // bool IsValidArraySize(int bar_index) { // bool result = false; // if (bar_index < 0) { return result; } // int rCount = ArraySize(upBuffer); result = rCount > bar_index + 1; // return result; } };