/////////////////////////////////////////////////////// // // SaherElm IT Center MQL5 Helper Class Library // ---------------------------------------------- // Name: XSCXHULLHelper // 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 // // START Definitions ... // // // Inputs ... struct XHULLInputs { // // Market ... int length; // Length double divisor; // Divisor (Speed) // // Calculation ... ENUM_APPLIED_PRICE upAppliedTo; // Up Zone Applied to ENUM_APPLIED_PRICE downAppliedTo; // Down Zone Applied to // // Presentation ... bool showUpZone; // Show Up Zone bool showDownZone; // Show Down Zone }; // // Index of Lines ... enum ENUM_XHULL_BUFFERS { // // Main Requirements ... XHULL_UP_ZONE_LINE = 0, XHULL_UP_ZONE_STATE_LINE = 1, XHULL_DOWN_ZONE_LINE = 2, XHULL_DOWN_ZONE_STATE_LINE = 3, }; // // Hull States ... enum XHULL_ZONE_STATES { XHULL_STATE_NEUTURAL = 0, XHULL_STATE_BULLISH = 1, XHULL_STATE_BEARISH = 2 }; // // Retrieve Info Model ... struct XHULLInfo { // // Symbol ... string symbol; // // Period ... ENUM_TIMEFRAMES period; // // Bar Time ... datetime barTime; // // Bar Index ... int barIndex; // // Values ... double up; XHULL_ZONE_STATES upState; double down; XHULL_ZONE_STATES downState; // // Conditions ... // bool isUpBullish; bool isUpNeutural; bool isUpBearish; // bool isUpSwitchedToBullish; bool isUpSwitchedToBearish; bool isUpSwitchedToNeutural; // bool isDownBullish; bool isDownBearish; bool isDownNeutural; // bool isDownSwitchedToBullish; bool isDownSwitchedToBearish; bool isDownSwitchedToNeutural; }; // // END Definitions ... // // // START Import and Inclused requirements ... // // // Includes ... #include "../Libraries/x-saherelm.common.lib.mq5" #include "../Classes/x-saherelm.xhelper.class.mq5" // // END Import and Inclused requirements ... // // // START Overrides ... // // // END Overrides ... // // // a Class for Helping Indicators Requirements ... class XSCXHULLHelper : public XSCBaseHelper { // // Public ... public: // // Buffers ... double upBuffer[]; double upStateBuffer[]; double downBuffer[]; double downStateBuffer[]; // // Constructor ... void XSCXHULLHelper( string symbol, // Trading Symbol ENUM_TIMEFRAMES period // Trading Time Frame ) : XSCBaseHelper(symbol, period) { PrepareTag(); } // // Deconstructor ... void ~XSCXHULLHelper() { } // // START Properties ... // // // Show Up Zone ... bool ShowUpZone( bool show // Show or Hide ) { // bool result = false; // if (mShowUpZone == show) { return true; } // mShowUpZone = show; result = Init(); // return result; } // // Show Down Zone ... bool ShowDownZone( bool show // Show or Hide ) { // bool result = false; // if (mShowDownZone == show) { return true; } // mShowDownZone = show; result = Init(); // return result; } // // END Properties ... // // // START Provided Functions ... // // // Prepare Tag ... virtual void PrepareTag() { mTag = "XHULL" + GetTagPrefix(); } // virtual int GetMaxLength() { // int result = -1; // result = mLength; // return result; } // // Initial Indicator Handler ... bool Init() { // bool result = false; // // Validate Inputs ... // result = mLength >= 9 && mDivisor >= 0.5; if (!result) { return result; } // // Initialize Handler ... mHandler = iCustom( // mSymbol, mPeriod, "x-saherelm.x121.xhull", // // Inputs ... // // Market ... "", // // Length ... mLength, // // Divisor (Speed) ... mDivisor, // // Calculation ... "", // // Up Zone Applied to ... mUpAppliedTo, // // Down Zone Applied to ... mDownAppliedTo, // // Presentation ... "", // // Show Up Zone ... mShowUpZone, // // Show Down Zone ... mShowDownZone // ); result = mHandler != INVALID_HANDLE; // return result; } // // Retrieve Current Config ... XHULLInputs GetConfig() { // XHULLInputs result; // result.length = mLength; result.divisor = mDivisor; result.upAppliedTo = mUpAppliedTo; result.downAppliedTo = mDownAppliedTo; result.showUpZone = mShowUpZone; result.showDownZone = mShowDownZone; // return result; } // // Set Config ... bool SetConfig(XHULLInputs &config) { // bool result = false; // mLength = config.length; mDivisor = config.divisor; mUpAppliedTo = config.upAppliedTo; mDownAppliedTo = config.downAppliedTo; mShowUpZone = config.showUpZone; mShowDownZone = config.showDownZone; // result = Init(); // return result; } // // Reading Buffers based on Given Bar Index ... virtual void Calculate( int barIndex // Given Bar Index ) { // // UP ... ArraySetAsSeries(upBuffer, true); CopyBuffer( mHandler, XHULL_UP_ZONE_LINE, barIndex, mLoopbackBars, upBuffer); // // UP State ... ArraySetAsSeries(upStateBuffer, true); CopyBuffer( mHandler, XHULL_UP_ZONE_STATE_LINE, barIndex, mLoopbackBars, upStateBuffer); // // DOWN ... ArraySetAsSeries(downBuffer, true); CopyBuffer( mHandler, XHULL_DOWN_ZONE_LINE, barIndex, mLoopbackBars, downBuffer); // // DOWN State ... ArraySetAsSeries(downStateBuffer, true); CopyBuffer( mHandler, XHULL_DOWN_ZONE_STATE_LINE, barIndex, mLoopbackBars, downStateBuffer); } // // Retrieve Info at Specific Bar Index ... XHULLInfo GetInfo( int barIndex // Given Bar Index ) { // XHULLInfo result; // if (barIndex < 0) { return result; } // // Do Calculations ... Calculate(barIndex); // barIndex--; if (barIndex < 0) { barIndex = 0; } // // Generate Candle Time ... datetime barTime = GetCandleTime( mSymbol, mPeriod, barIndex); // // Fill Result ... result.symbol = mSymbol; result.period = mPeriod; result.barTime = barTime; result.barIndex = barIndex; // double up = upBuffer[barIndex]; XHULL_ZONE_STATES upState = (XHULL_ZONE_STATES)upStateBuffer[barIndex]; XHULL_ZONE_STATES upStatePrev = (XHULL_ZONE_STATES)upStateBuffer[barIndex + 1]; // double down = downBuffer[barIndex]; XHULL_ZONE_STATES downState = (XHULL_ZONE_STATES)downStateBuffer[barIndex]; XHULL_ZONE_STATES downStatePrev = (XHULL_ZONE_STATES)downStateBuffer[barIndex + 1]; // result.up = up; result.upState = upState; result.down = down; result.downState = downState; // result.isUpBullish = upState = XHULL_STATE_BULLISH; result.isUpBearish = upState = XHULL_STATE_BEARISH; result.isUpNeutural = upState = XHULL_STATE_NEUTURAL; // result.isUpSwitchedToBullish = upState == XHULL_STATE_BULLISH && upStatePrev != XHULL_STATE_BULLISH; result.isUpSwitchedToBearish = upState == XHULL_STATE_BEARISH && upStatePrev != XHULL_STATE_BEARISH; result.isUpSwitchedToNeutural = upState == XHULL_STATE_NEUTURAL && upStatePrev != XHULL_STATE_NEUTURAL; // result.isDownBullish = downState = XHULL_STATE_BULLISH; result.isDownBearish = downState = XHULL_STATE_BEARISH; result.isDownNeutural = downState = XHULL_STATE_NEUTURAL; // result.isDownSwitchedToBullish = downState == XHULL_STATE_BULLISH && downStatePrev != XHULL_STATE_BULLISH; result.isDownSwitchedToBearish = downState == XHULL_STATE_BEARISH && downStatePrev != XHULL_STATE_BEARISH; result.isDownSwitchedToNeutural = downState == XHULL_STATE_NEUTURAL && downStatePrev != XHULL_STATE_NEUTURAL; // return result; } // // END Provided Functions ... // // // Protected ... protected: // // Private ... private: // // Indicator Properties ... // // Market ... // // Length ... int mLength; // // Divisor (Speed) ... double mDivisor; // // Calculation ... // // Up Zone Applied to ... ENUM_APPLIED_PRICE mUpAppliedTo; // // Down Zone Applied to ... ENUM_APPLIED_PRICE mDownAppliedTo; // // Presentation ... // // Show Up Zone ... bool mShowUpZone; // // Show Down Zone ... bool mShowDownZone; }; // // START Usefull Functions ... // // // END Usefull Functions ... //