/////////////////////////////////////////////////////// // // SaherElm IT Center MQL5 Helper Class Library // ---------------------------------------------- // Name: XSCXCHEHelper // 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 XCHEInputs { // // Market ... int length; // Length int loopback; // Loopback double multiplier1; // 1st Multiplier double multiplier2; // 2nd Multiplier // // Calculation ... ENUM_APPLIED_PRICE upAppliedTo; // Up Zone Applied to ENUM_APPLIED_PRICE downAppliedTo; // Down Zone Applied to // // Presentation ... bool showLongExit1Line; // Show 1st Long Exit bool showShortExit1Line; // Show 1st Short Exit bool showLongExit2Line; // Show 2st Long Exit bool showShortExit2Line; // Show 2st Short Exit }; // // Index of Lines ... enum ENUM_XCHE_BUFFERS { // // Main Requirements ... XCHE_1ST_LONG_EXIT_LINE = 0, XCHE_1ST_SHORT_EXIT_LINE = 1, XCHE_2ND_LONG_EXIT_LINE = 2, XCHE_2ND_SHORT_EXIT_LINE = 3, }; // // Retrieve Info Model ... struct XCHEInfo { // // Symbol ... string symbol; // // Period ... ENUM_TIMEFRAMES period; // // Bar Time ... datetime barTime; // // Bar Index ... int barIndex; // // Values ... double longExit1; double longExit2; double shortExit1; double shortExit2; // // Conditions ... // bool isLongExit1Start; bool isShortExit1Start; // bool isLongExit2Start; bool isShortExit2Start; }; // // 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 XSCXCHEHelper : public XSCBaseHelper { // // Public ... public: // // Buffers ... double longExit1Buffer[]; double shortExit1Buffer[]; double longExit2Buffer[]; double shortExit2Buffer[]; // // Constructor ... void XSCXCHEHelper( string symbol, // Trading Symbol ENUM_TIMEFRAMES period // Trading Time Frame ) : XSCBaseHelper(symbol, period) { PrepareTag(); } // // Deconstructor ... void ~XSCXCHEHelper() { } // // START Properties ... // // // Show 1st Long Exit ... bool ShowLongExit1Line( bool show // Show or Hide ) { // bool result = false; // if (mShowLongExit1Line == show) { return true; } // mShowLongExit1Line = show; result = Init(); // return result; } // // Show 1st Short Exit ... bool ShowShortExit1Line( bool show // Show or Hide ) { // bool result = false; // if (mShowShortExit1Line == show) { return true; } // mShowShortExit1Line = show; result = Init(); // return result; } // // Show 2st Long Exit ... bool ShowLongExit2Line( bool show // Show or Hide ) { // bool result = false; // if (mShowLongExit2Line == show) { return true; } // mShowLongExit2Line = show; result = Init(); // return result; } // // Show 2st Short Exit ... bool ShowShortExit2Line( bool show // Show or Hide ) { // bool result = false; // if (mShowShortExit1Line == show) { return true; } // mShowShortExit1Line = show; result = Init(); // return result; } // // END Properties ... // // // START Provided Functions ... // // // Prepare Tag ... virtual void PrepareTag() { mTag = "XCHE" + GetTagPrefix(); } // virtual int GetMaxLength() { // int result = -1; // result = MathMax(mLength, mLoopback); // return result; } // // Initial Indicator Handler ... bool Init() { // bool result = false; // // Validate Inputs ... // // result = mLength >= 9 && mLoopback >= 0; if (!result) { return result; } // // Initialize Handler ... mHandler = iCustom( // mSymbol, mPeriod, "x-saherelm.x121.xche", // // Inputs ... // // Market ... "", // // Length ... mLength, // // Loopback ... mLoopback, // // 1st Multiplier ... mMultiplier1, // // 2nd Multiplier ... mMultiplier2, // // Calculation ... "", // // Up Zone Applied to ... mUpAppliedTo, // // Down Zone Applied to ... mDownAppliedTo, // // Presentation ... "", // // Show 1st Long Exit ... mShowLongExit1Line, // // Show 1st Short Exit ... mShowShortExit1Line, // // Show 2st Long Exit ... mShowLongExit2Line, // // Show 2st Short Exit ... mShowShortExit2Line // ); result = mHandler != INVALID_HANDLE; // return result; } // // Retrieve Current Config ... XCHEInputs GetConfig() { // XCHEInputs result; // result.length = mLength; result.loopback = mLoopback; result.multiplier1 = mMultiplier1; result.multiplier2 = mMultiplier2; result.upAppliedTo = mUpAppliedTo; result.downAppliedTo = mDownAppliedTo; result.showLongExit1Line = mShowLongExit1Line; result.showShortExit1Line = mShowShortExit1Line; result.showLongExit2Line = mShowLongExit2Line; result.showShortExit2Line = mShowShortExit2Line; // return result; } // // Set Config ... bool SetConfig(XCHEInputs &config) { // bool result = false; // mLength = config.length; mLoopback = config.loopback; mMultiplier1 = config.multiplier1; mMultiplier2 = config.multiplier2; mUpAppliedTo = config.upAppliedTo; mDownAppliedTo = config.downAppliedTo; mShowLongExit1Line = config.showLongExit1Line; mShowShortExit1Line = config.showShortExit1Line; mShowLongExit2Line = config.showLongExit2Line; mShowShortExit2Line = config.showShortExit2Line; // result = Init(); // return result; } // // Reading Buffers based on Given Bar Index ... virtual void Calculate( int barIndex // Given Bar Index ) { // // LEVEL 1 .. // // LONG Exit ... ArraySetAsSeries(longExit1Buffer, true); CopyBuffer( mHandler, XCHE_1ST_LONG_EXIT_LINE, barIndex, mLoopbackBars, longExit1Buffer); // // SHORT Exit ... ArraySetAsSeries(shortExit1Buffer, true); CopyBuffer( mHandler, XCHE_1ST_SHORT_EXIT_LINE, barIndex, mLoopbackBars, shortExit1Buffer); // // LEVEL 2 .. // // LONG Exit ... ArraySetAsSeries(longExit2Buffer, true); CopyBuffer( mHandler, XCHE_2ND_LONG_EXIT_LINE, barIndex, mLoopbackBars, longExit2Buffer); // // SHORT Exit ... ArraySetAsSeries(shortExit2Buffer, true); CopyBuffer( mHandler, XCHE_2ND_SHORT_EXIT_LINE, barIndex, mLoopbackBars, shortExit2Buffer); } // // Retrieve Info at Specific Bar Index ... XCHEInfo GetInfo( int barIndex // Given Bar Index ) { // XCHEInfo result; // if (barIndex < 0) { return result; } // barIndex--; 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 longExit1 = longExit1Buffer[barIndex]; double longExit1Prev = longExit1Buffer[barIndex + 1]; double shortExit1 = shortExit1Buffer[barIndex]; double shortExit1Prev = shortExit1Buffer[barIndex + 1]; // double longExit2 = longExit2Buffer[barIndex]; double longExit2Prev = longExit2Buffer[barIndex + 1]; double shortExit2 = shortExit2Buffer[barIndex]; double shortExit2Prev = shortExit2Buffer[barIndex + 1]; // result.longExit1 = longExit1; result.shortExit1 = shortExit1; result.longExit2 = longExit2; result.shortExit2 = shortExit2; // result.isLongExit1Start = longExit1 != EMPTY_VALUE && longExit1Prev == EMPTY_VALUE; // result.isShortExit1Start = shortExit1 != EMPTY_VALUE && shortExit1Prev == EMPTY_VALUE; // result.isLongExit2Start = longExit2 != EMPTY_VALUE && longExit2Prev == EMPTY_VALUE; // result.isShortExit2Start = shortExit2 != EMPTY_VALUE && shortExit2Prev == EMPTY_VALUE; // return result; } // // END Provided Functions ... // // // Protected ... protected: // // Private ... private: // // Indicator Properties ... // // Market ... // // Length ... int mLength; // // Loopback ... int mLoopback; // // 1st Multiplier ... double mMultiplier1; // // 2nd Multiplier ... double mMultiplier2; // // Calculation ... // // Up Zone Applied to ... ENUM_APPLIED_PRICE mUpAppliedTo; // // Down Zone Applied to ... ENUM_APPLIED_PRICE mDownAppliedTo; // // Presentation ... // // Show 1st Long Exit ... bool mShowLongExit1Line; // // Show 1st Short Exit ... bool mShowShortExit1Line; // // Show 2st Long Exit ... bool mShowLongExit2Line; // // Show 2st Short Exit ... bool mShowShortExit2Line; }; // // START Usefull Functions ... // // // END Usefull Functions ... //