/////////////////////////////////////////////////////// // // SaherElm IT Center MQL5 Helper Class Library // ---------------------------------------------- // Name: XSCXSSLCHelper // 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 XSSLCInputs { // // Market ... int length; // Length // // Calculation ... ENUM_MA_METHOD method; // Method ENUM_APPLIED_PRICE upAppliedTo; // Up Applied To ENUM_APPLIED_PRICE downAppliedTo; // Down Applied To // // Presentation ... bool showUp; // Show Up bool showDown; // Show Down }; // // Index of Lines ... enum ENUM_XSSLC_BUFFERS { // // Main Requirements ... XSSLC_UP_LINE = 0, XSSLC_DOWN_LINE = 1, }; // // Retrieve Info Model ... struct XSSLCInfo { // // Symbol ... string symbol; // // Period ... ENUM_TIMEFRAMES period; // // Bar Time ... datetime barTime; // // Bar Index ... int barIndex; // // Values ... double up; double down; // double ups[]; double downs[]; // // Conditions ... // // Detect Trend is Bullish or not ... bool isBullish; // // Detect Trend is Switched to Bullish Or not ... bool isSwitchedBullish; // // Detect Trend is Bearish or not ... bool isBearish; // // Detect Trend is Switched to Bearish Or not ... bool isSwitchedBearish; }; // // 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 XSCXSSLCHelper : public XSCBaseHelper { // // Public ... public: // // Buffers ... double upBuffer[]; double downBuffer[]; // // Constructor ... void XSCXSSLCHelper( string symbol, // Trading Symbol ENUM_TIMEFRAMES period // Trading Time Frame ) : XSCBaseHelper(symbol, period) { PrepareTag(); } // // Deconstructor ... void ~XSCXSSLCHelper() { } // // START Properties ... // // // Show Up ... bool ShowUp( bool show // Show or Hide Line ) { // bool result = false; // if (mShowUp == show) { return true; } // mShowUp = show; result = Init(); // return result; } // // Show Down ... bool ShowDown( bool show // Show or Hide Line ) { // bool result = false; // if (mShowDown == show) { return true; } // mShowDown = show; result = Init(); // return result; } // // END Properties ... // // // START Provided Functions ... // // // Prepare Tag ... virtual void PrepareTag() { mTag = "XSSLC" + GetTagPrefix(); } // virtual int GetMaxLength() { // int result = -1; // result = mLength; // return result; } // // Initial Indicator Handler ... bool Init() { // bool result = false; // // Validate Args ... result = // (mLength >= 2) // ; if (!result) { return false; } // // Initialize Handler ... mHandler = iCustom( // mSymbol, mPeriod, "x-saherelm.x121.xsslc", // // Inputs ... // // Market ... "", // // Length ... mLength, // // Calculation ... "", // // Method ... mMethod, // // Up Applied To ... mUpAppliedTo, // // Down Applied To ... mDownAppliedTo, // // Presentation ... "", // // Show Up ... mShowUp, // // Show Down ... mShowDown // ); result = mHandler != INVALID_HANDLE; // return result; } // // Retrieve Current Config ... XSSLCInputs GetConfig() { // XSSLCInputs result; // result.length = mLength; result.method = mMethod; result.upAppliedTo = mUpAppliedTo; result.downAppliedTo = mDownAppliedTo; result.showUp = mShowUp; result.showDown = mShowDown; // return result; } // // Set Config ... bool SetConfig(XSSLCInputs &config) { // bool result = false; // mLength = config.length; mMethod = config.method; mUpAppliedTo = config.upAppliedTo; mDownAppliedTo = config.downAppliedTo; mShowUp = config.showUp; mShowDown = config.showDown; // 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, XSSLC_UP_LINE, barIndex, mLoopbackBars, upBuffer); // // DOWN ... ArraySetAsSeries(downBuffer, true); CopyBuffer( mHandler, XSSLC_DOWN_LINE, barIndex, mLoopbackBars, downBuffer); } // // Retrieve Info at Specific Bar Index ... XSSLCInfo GetInfo( int barIndex // Given Bar Index ) { // XSSLCInfo result; // if (barIndex < 0) { barIndex = 0; } // // Do Calculations ... Calculate(barIndex); // // 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]; double upPrev = upBuffer[barIndex + 1]; double down = downBuffer[barIndex]; double downPrev = downBuffer[barIndex + 1]; // Copy( upBuffer, result.ups ); Copy( downBuffer, result.downs ); // result.up = up; result.down = down; // result.isBullish = up > down; result.isBearish = up < down; // result.isSwitchedBullish = up > down && upPrev <= downPrev; result.isSwitchedBearish = up < down && upPrev >= downPrev; // return result; } // // END Provided Functions ... // // // Protected ... protected: // // Private ... private: // // Indicator Properties ... // // Market ... // // Length ... int mLength; // // Calculation ... // // Method ... ENUM_MA_METHOD mMethod; // // Up Applied To ... ENUM_APPLIED_PRICE mUpAppliedTo; // // Down Applied To ... ENUM_APPLIED_PRICE mDownAppliedTo; // // Presentation ... // // Show Up ... bool mShowUp; // // Show Down ... bool mShowDown; }; // // START Usefull Functions ... // // // END Usefull Functions ... //