/////////////////////////////////////////////////////// // // SaherElm IT Center MQL5 Helper Class Library // ---------------------------------------------- // Name: XSCXPVHelper // 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 XPVInputs { // // Makret Cycles ... int shortLength; // Short Length int mediumLength; // Medium Length int longLength; // Long Length int hindLength; // Hind Length double fiboLevel1; // Fibio 1st Level double fiboLevel2; // Fibio 2st Level double fiboLevel3; // Fibio 3rd Level // // Detection Modes ... ENUM_SERIESMODE hhMode; // Highest High Calculation Method ENUM_SERIESMODE llMode; // Lowest Low Calculation Method // // Presentation ... bool showPeaksAndVales; // Show Peaks and Vales bool showLevels; // Show Levels bool showFibo1Levels; // Show Fibo 1st Level bool showFibo2Levels; // Show Fibo 2nd Level bool showFibo3Levels; // Show Fibo 3rd Level }; // // Index of Lines ... enum ENUM_XPV_BUFFERS { // // Main Requirements ... XPV_PEAKS_LINE = 0, XPV_VALES_LINE = 1, // XPV_RESISTANCE_LINE = 2, XPV_RESISTANCE_STATE_LINE = 3, // XPV_SUPPORT_LINE = 4, XPV_SUPPORT_STATE_LINE = 5, // XPV_FL1_LINE = 6, XPV_FL2_LINE = 8, XPV_FL3_LINE = 10, // // SHORT ... XPV_SHORT_HIGH_LINE = 12, XPV_SHORT_LOW_LINE = 13, // // MEDIUM ... XPV_MEDIUM_HIGH_LINE = 14, XPV_MEDIUM_LOW_LINE = 15, // // LONG ... XPV_LONG_HIGH_LINE = 16, XPV_LONG_LOW_LINE = 17, // // HIND ... XPV_HIND_HIGH_LINE = 18, XPV_HIND_LOW_LINE = 19, }; // // Retrieve Info Model ... struct XPVInfo { // // Symbol ... string symbol; // // Period ... ENUM_TIMEFRAMES period; // // Bar Time ... datetime barTime; // // Bar Index ... int barIndex; // // Values ... double peak; double vale; double fl1; double fl2; double fl3; // double r; double rState; double s; double sSate; // // SHORT ... double sl; double sh; // // MEDIUM ... double ml; double mh; // // LONG ... double ll; double lh; // // HIND ... double hl; double hh; // double peakss[]; double valess[]; double fl1s[]; double fl2s[]; double fl3s[]; double rs[]; double rStates[]; double ss[]; double sStates[]; double sls[]; double shs[]; double mls[]; double mhs[]; double lls[]; double lhs[]; double hls[]; double hhs[]; // // Conditions ... // // Determines New Peaks Happens ... bool isNewPeak; // // Determines New Vales Happens ... bool isNewVale; }; // // 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 XSCXPVHelper : public XSCBaseHelper { // // Public ... public: // // Buffers ... double peaksBuffer[]; double valesBuffer[]; double fl1Buffer[]; double fl2Buffer[]; double fl3Buffer[]; // // Support and Resistance ... double rBuffer[]; double rStateBuffer[]; // double sBuffer[]; double sStateBuffer[]; // // SHORT ... double slBuffer[]; double shBuffer[]; // // MEDIUM ... double mlBuffer[]; double mhBuffer[]; // // LONG ... double llBuffer[]; double lhBuffer[]; // // HIND ... double hlBuffer[]; double hhBuffer[]; // // Constructor ... void XSCXPVHelper( string symbol, // Trading Symbol ENUM_TIMEFRAMES period // Trading Time Frame ) : XSCBaseHelper(symbol, period) { PrepareTag(); } // // Deconstructor ... void ~XSCXPVHelper() { } // // START Properties ... // // // Show Levels ... bool ShowLevels( bool show // Show or Hide Levels ) { // bool result = false; // if (mShowLevels == show) { return true; } // mShowLevels = show; result = Init(); // return result; } // // Show Peaks and Vales ... bool ShowPeaksAnVales( bool show // Show or Hide Levels ) { // bool result = false; // if (mShowPeaksAndVales == show) { return true; } // mShowPeaksAndVales = show; result = Init(); // return result; } // // Show Fibo 1st Level ... bool ShowFibo1Levels( bool show // Show or Hide Levels ) { // bool result = false; // if (mShowFibo1Levels == show) { return true; } // mShowFibo1Levels = show; result = Init(); // return result; } // // Show Fibo 2nd Level ... bool ShowFibo2Levels( bool show // Show or Hide Levels ) { // bool result = false; // if (mShowFibo2Levels == show) { return true; } // mShowFibo2Levels = show; result = Init(); // return result; } // // Show Fibo 3rd Level ... bool ShowFibo3Levels( bool show // Show or Hide Levels ) { // bool result = false; // if (mShowFibo3Levels == show) { return true; } // mShowFibo3Levels = show; result = Init(); // return result; } // // END Properties ... // // // START Provided Functions ... // // // Prepare Tag ... virtual void PrepareTag() { mTag = "XPV" + GetTagPrefix(); } // virtual int GetMaxLength() { // int result = -1; // result = MathMax(mShortLength, mMediumLength); result = MathMax(result, mLongLength); result = MathMax(result, mHindLength); // return result; } // // Initial Indicator Handler ... bool Init() { // bool result = false; // // Validate Args ... result = // (mShortLength > 2 && mMediumLength > mShortLength && mLongLength > mMediumLength && mHindLength > mLongLength) // ; if (!result) { return false; } // // Initialize Handler ... mHandler = iCustom( // mSymbol, mPeriod, "x-saherelm.x121.xpv", // // Inputs ... // // Market ... "", // // Short Length ... mShortLength, // // Medium Length mMediumLength, // // Long Length ... mLongLength, // // Hind Length ... mHindLength, // // Fibio 1st Level ... mFiboLevel1, // // Fibio 2st Level ... mFiboLevel2, // // Fibio 3rd Level ... mFiboLevel3, // // Detection Mode ... "", // // Highest High Calculation Method ... mHHMode, // // Lowest Low Calculation Method ... mLLMode, // // Presentations ... "", // // Show Peaks and Vales ... mShowPeaksAndVales, // // Show Levels ... mShowLevels, // // Show Fibo 1st Level ... mShowFibo1Levels, // // Show Fibo 2nd Level ... mShowFibo2Levels, // // Show Fibo 3rd Level ... mShowFibo3Levels // ); result = mHandler != INVALID_HANDLE; // return result; } // // Retrieve Current Config ... XPVInputs GetConfig() { // XPVInputs result; // result.shortLength = mShortLength; result.mediumLength = mMediumLength; result.longLength = mLongLength; result.hindLength = mHindLength; result.fiboLevel1 = mFiboLevel1; result.fiboLevel2 = mFiboLevel2; result.fiboLevel3 = mFiboLevel3; result.hhMode = mHHMode; result.llMode = mLLMode; result.showPeaksAndVales = mShowPeaksAndVales; result.showLevels = mShowLevels; result.showFibo1Levels = mShowFibo1Levels; result.showFibo2Levels = mShowFibo2Levels; result.showFibo3Levels = mShowFibo3Levels; // return result; } // // Set Config ... bool SetConfig(XPVInputs &config) { // bool result = false; // mShortLength = config.shortLength; mMediumLength = config.mediumLength; mLongLength = config.longLength; mHindLength = config.hindLength; mFiboLevel1 = config.fiboLevel1; mFiboLevel2 = config.fiboLevel2; mFiboLevel3 = config.fiboLevel3; mHHMode = config.hhMode; mLLMode = config.llMode; mShowPeaksAndVales = config.showPeaksAndVales; mShowLevels = config.showLevels; mShowFibo1Levels = config.showFibo1Levels; mShowFibo2Levels = config.showFibo2Levels; mShowFibo3Levels = config.showFibo3Levels; // result = Init(); // return result; } // // Reading Buffers based on Given Bar Index ... virtual void Calculate( int barIndex // Given Bar Index ) { // // PEAKS ... ArraySetAsSeries(peaksBuffer, true); CopyBuffer( mHandler, XPV_PEAKS_LINE, barIndex, mLoopbackBars, peaksBuffer); // // VALES ... ArraySetAsSeries(valesBuffer, true); CopyBuffer( mHandler, XPV_VALES_LINE, barIndex, mLoopbackBars, valesBuffer); // // FIBBO LEVELS ... // // LEVEL 1 ... ArraySetAsSeries(fl1Buffer, true); CopyBuffer( mHandler, XPV_FL1_LINE, barIndex, mLoopbackBars, fl1Buffer); // // LEVEL 2 ... ArraySetAsSeries(fl2Buffer, true); CopyBuffer( mHandler, XPV_FL2_LINE, barIndex, mLoopbackBars, fl2Buffer); // // LEVEL 3 ... ArraySetAsSeries(fl3Buffer, true); CopyBuffer( mHandler, XPV_FL3_LINE, barIndex, mLoopbackBars, fl3Buffer); // // Support and Resistance ... // // Resistance ... ArraySetAsSeries(rBuffer, true); ArraySetAsSeries(rStateBuffer, true); CopyBuffer( mHandler, XPV_RESISTANCE_LINE, barIndex, mLoopbackBars, rBuffer); CopyBuffer( mHandler, XPV_RESISTANCE_STATE_LINE, barIndex, mLoopbackBars, rStateBuffer); // // Support ... ArraySetAsSeries(sBuffer, true); ArraySetAsSeries(sStateBuffer, true); CopyBuffer( mHandler, XPV_SUPPORT_LINE, barIndex, mLoopbackBars, sBuffer); CopyBuffer( mHandler, XPV_SUPPORT_STATE_LINE, barIndex, mLoopbackBars, sStateBuffer); // // CYCLES ... // // SHORT ... // // HIGH ... ArraySetAsSeries(shBuffer, true); CopyBuffer( mHandler, XPV_SHORT_HIGH_LINE, barIndex, mLoopbackBars, shBuffer); // // LOW ... ArraySetAsSeries(slBuffer, true); CopyBuffer( mHandler, XPV_SHORT_LOW_LINE, barIndex, mLoopbackBars, slBuffer); // // MEDIUM ... // // HIGH ... ArraySetAsSeries(mhBuffer, true); CopyBuffer( mHandler, XPV_MEDIUM_HIGH_LINE, barIndex, mLoopbackBars, mhBuffer); // // LOW ... ArraySetAsSeries(mlBuffer, true); CopyBuffer( mHandler, XPV_MEDIUM_LOW_LINE, barIndex, mLoopbackBars, mlBuffer); // // LONG ... // // HIGH ... ArraySetAsSeries(lhBuffer, true); CopyBuffer( mHandler, XPV_LONG_HIGH_LINE, barIndex, mLoopbackBars, lhBuffer); // // LOW ... ArraySetAsSeries(llBuffer, true); CopyBuffer( mHandler, XPV_LONG_LOW_LINE, barIndex, mLoopbackBars, llBuffer); // // HIND ... // // HIGH ... ArraySetAsSeries(hhBuffer, true); CopyBuffer( mHandler, XPV_HIND_HIGH_LINE, barIndex, mLoopbackBars, hhBuffer); // // LOW ... ArraySetAsSeries(hlBuffer, true); CopyBuffer( mHandler, XPV_HIND_LOW_LINE, barIndex, mLoopbackBars, hlBuffer); } // // Retrieve Info at Specific Bar Index ... XPVInfo GetInfo( int barIndex // Given Bar Index ) { // XPVInfo 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; // result.peak = peaksBuffer[barIndex]; result.vale = valesBuffer[barIndex]; result.fl1 = fl1Buffer[barIndex]; result.fl2 = fl2Buffer[barIndex]; result.fl3 = fl3Buffer[barIndex]; // result.r = rBuffer[barIndex]; result.rState = rStateBuffer[barIndex]; result.s = sBuffer[barIndex]; result.sSate = sStateBuffer[barIndex]; // // SHORT ... result.sl = slBuffer[barIndex]; result.sh = shBuffer[barIndex]; // // MEDIUM ... result.ml = mlBuffer[barIndex]; result.mh = mhBuffer[barIndex]; // // LONG ... result.ll = llBuffer[barIndex]; result.lh = lhBuffer[barIndex]; // // HIND ... result.hl = hlBuffer[barIndex]; result.hh = hhBuffer[barIndex]; // Copy( peaksBuffer, result.peakss); Copy( valesBuffer, result.valess); Copy( fl1Buffer, result.fl1s); Copy( fl2Buffer, result.fl2s); Copy( fl3Buffer, result.fl3s); Copy( rBuffer, result.rs); Copy( rStateBuffer, result.rStates); Copy( sBuffer, result.ss); Copy( sStateBuffer, result.sStates); Copy( slBuffer, result.sls); Copy( shBuffer, result.shs); Copy( mlBuffer, result.mls); Copy( mhBuffer, result.mhs); Copy( llBuffer, result.lls); Copy( lhBuffer, result.lhs); Copy( hlBuffer, result.hls); Copy( hhBuffer, result.hhs); // result.isNewPeak = peaksBuffer[barIndex] != peaksBuffer[barIndex + 1]; result.isNewVale = valesBuffer[barIndex] != valesBuffer[barIndex + 1]; // return result; } // // END Provided Functions ... // // // Protected ... protected: // // Private ... private: // // Indicator Properties ... // // Market ... // // Short Length ... int mShortLength; // // Medium Length int mMediumLength; // // Long Length ... int mLongLength; // // Hind Length ... int mHindLength; // // Fibio 1st Level ... double mFiboLevel1; // // Fibio 2st Level ... double mFiboLevel2; // // Fibio 3rd Level ... double mFiboLevel3; // // Detection Mode ... // // Highest High Calculation Method ... ENUM_SERIESMODE mHHMode; // // Lowest Low Calculation Method ... ENUM_SERIESMODE mLLMode; // // Presentations ... // // Show Peaks and Vales ... bool mShowPeaksAndVales; // // Show Levels ... bool mShowLevels; // // Show Fibo 1st Level ... bool mShowFibo1Levels; // // Show Fibo 2nd Level ... bool mShowFibo2Levels; // // Show Fibo 3rd Level ... bool mShowFibo3Levels; }; // // START Usefull Functions ... // // // END Usefull Functions ... //