/////////////////////////////////////////////////////// // // SaherElm IT Center MQL5 Helper Class Library // ---------------------------------------------- // Name: XSCXOSCHelper // 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 XOSCInputs { // // ATR ... int atrLength; // // RVI ... int rviLength; // // BULLPOWER ... int bullpLength; // // BEARPOWER ... int bearpLength; // // VOLUME ... ENUM_APPLIED_VOLUME volumeAppliedTo; // // RSI ... int rsiLength; ENUM_APPLIED_PRICE rsiAppliedTo; // // CCI ... int cciLength; ENUM_APPLIED_PRICE cciAppliedTo; // // MOMENTUM ... int momentumLength; ENUM_APPLIED_PRICE momentumAppliedTo; // // SAR ... double sarStep; double sarMaximum; // // MACD ... int macdFastLength; int macdSlowLength; int macdSignaLength; ENUM_APPLIED_PRICE macdAppliedTo; // // STOCHASTIC ... int stochKLength; int stochDLength; int stochSlowing; ENUM_MA_METHOD stochMaMethod; ENUM_STO_PRICE stochMode; // // STANDARDDEVIATION ... int stddevLength; int stddevShift; ENUM_MA_METHOD stddevMethod; ENUM_APPLIED_PRICE stddevAppliedTo; }; // // Index of Lines ... enum ENUM_XOSC_BUFFERS { // // Main Requirements ... XOSC_ATR_LINE = 0, XOSC_RVI_MAIN_LINE = 1, XOSC_RVI_SIGNAL_LINE = 2, XOSC_BULLP_LINE = 3, XOSC_BEARP_LINE = 4, XOSC_VOLUME_LINE = 5, XOSC_RSI_LINE = 6, XOSC_CCI_LINE = 7, XOSC_MOMENTUM_LINE = 8, XOSC_SAR_LINE = 9, XOSC_MACD_MAIN_LINE = 10, XOSC_MACD_SIGNAL_LINE = 11, XOSC_STOCH_MAIN_LINE = 12, XOSC_STOCH_SIGNAL_LINE = 13, XOSC_STDDEV_LINE = 14, }; // // Retrieve Info Model ... struct XOSCInfo { // // Symbol ... string symbol; // // Period ... ENUM_TIMEFRAMES period; // // Bar Time ... datetime barTime; // // Bar Index ... int barIndex; // // Values ... double atr; double rviMain; double rviSignal; double bullPower; double bearPower; double volume; double rsi; double cci; double momentum; double sar; double macdMain; double macdSignal; double stochMain; double stochSignal; double stddev; // double atrs[]; double rviMains[]; double rviSignals[]; double bullPs[]; double bearPs[]; double volumes[]; double rsis[]; double ccis[]; double momentums[]; double sars[]; double macdMains[]; double macdSignals[]; double stochMains[]; double stochSignals[]; double stddevs[]; // // Conditions ... // TODO: Implement it Later ... }; // // 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 XSCXOSCHelper : public XSCBaseHelper { // // Public ... public: // // Buffers ... double atrBuffer[]; double rviMainBuffer[]; double rviSignalBuffer[]; double bullPBuffer[]; double bearPBuffer[]; double volumeBuffer[]; double rsiBuffer[]; double cciBuffer[]; double momentumBuffer[]; double sarBuffer[]; double macdMainBuffer[]; double macdSignalBuffer[]; double stochMainBuffer[]; double stochSignalBuffer[]; double stddevBuffer[]; // // Constructor ... void XSCXOSCHelper( string symbol, // Trading Symbol ENUM_TIMEFRAMES period // Trading Time Frame ) : XSCBaseHelper(symbol, period) { PrepareTag(); } // // Deconstructor ... void ~XSCXOSCHelper() { } // // START Properties ... // // // END Properties ... // // // START Provided Functions ... // // // Prepare Tag ... virtual void PrepareTag() { mTag = "XOSC" + GetTagPrefix(); } // virtual int GetMaxLength() { // int result = -1; // result = MathMax(mAtrLength, mRviLength); result = MathMax(result, mBullpLength); result = MathMax(result, mBearpLength); result = MathMax(result, mRsiLength); result = MathMax(result, mCciLength); result = MathMax(result, mMomentumLength); result = MathMax(result, mMacdFastLength); result = MathMax(result, mMacdSlowLength); result = MathMax(result, mMacdSignaLength); result = MathMax(result, mStochKLength); result = MathMax(result, mStochDLength); result = MathMax(result, mStochSlowing); result = MathMax(result, mStddevLength); // return result; } // // Initial Indicator Handler ... bool Init() { // bool result = false; // // Validate Args ... result = // mAtrLength >= 2 && mRviLength >= 2 && mBullpLength >= 2 && mBearpLength >= 2 && mRsiLength >= 2 && mCciLength >= 2 && mMomentumLength >= 2 && mSarStep > 0 && mSarStep < mSarMaximum && mMacdFastLength >= 2 && mMacdSlowLength > mMacdFastLength && mMacdSignaLength >= 2 && mStochKLength >= 2 && mStochDLength >= 2 && mStochSlowing >= 2 && mStddevLength >= 2 && mStddevShift >= 0 // ; if (!result) { return false; } // // Initialize Handler ... mHandler = iCustom( // mSymbol, mPeriod, "x-saherelm.x121.xosc", // // Inputs ... // // ATR ... "", mAtrLength, // // RVI ... "", mRviLength, // // BULLPOWER ... "", mBullpLength, // // BEARPOWER ... "", mBearpLength, // // VOLUME ... "", mVolumeAppliedTo, // // RSI ... "", mRsiLength, mRsiAppliedTo, // // CCI ... "", mCciLength, mCciAppliedTo, // // STANDARDDEVIATION ... "", mStddevLength, mStddevShift, mStddevMethod, mStddevAppliedTo, // // MOMENTUM ... "", mMomentumLength, mMomentumAppliedTo, // // SAR ... "", mSarStep, mSarMaximum, // // MACD ... "", mMacdFastLength, mMacdSlowLength, mMacdSignaLength, mMacdAppliedTo, // // STOCHASTIC ... "", mStochKLength, mStochDLength, mStochSlowing, mStochMaMethod, mStochMode // ); result = mHandler != INVALID_HANDLE; // return result; } // // Retrieve Current Config ... XOSCInputs GetConfig() { // XOSCInputs result; // result.atrLength = mAtrLength; result.rviLength = mRviLength; result.bullpLength = mBullpLength; result.bearpLength = mBearpLength; result.volumeAppliedTo = mVolumeAppliedTo; result.rsiLength = mRsiLength; result.rsiAppliedTo = mRsiAppliedTo; result.cciLength = mCciLength; result.cciAppliedTo = mCciAppliedTo; result.momentumLength = mMomentumLength; result.momentumAppliedTo = mMomentumAppliedTo; result.sarStep = mSarStep; result.sarMaximum = mSarMaximum; result.macdFastLength = mMacdFastLength; result.macdSlowLength = mMacdSlowLength; result.macdSignaLength = mMacdSignaLength; result.macdAppliedTo = mMacdAppliedTo; result.stochKLength = mStochKLength; result.stochDLength = mStochDLength; result.stochSlowing = mStochSlowing; result.stochMaMethod = mStochMaMethod; result.stochMode = mStochMode; result.stddevLength = mStddevLength; result.stddevShift = mStddevShift; result.stddevMethod = mStddevMethod; result.stddevAppliedTo = mStddevAppliedTo; // return result; } // // Set Config ... bool SetConfig(XOSCInputs &config) { // bool result = false; // mAtrLength = config.atrLength; mRviLength = config.rviLength; mBullpLength = config.bullpLength; mBearpLength = config.bearpLength; mVolumeAppliedTo = config.volumeAppliedTo; mRsiLength = config.rsiLength; mRsiAppliedTo = config.rsiAppliedTo; mCciLength = config.cciLength; mCciAppliedTo = config.cciAppliedTo; mMomentumLength = config.momentumLength; mMomentumAppliedTo = config.momentumAppliedTo; mSarStep = config.sarStep; mSarMaximum = config.sarMaximum; mMacdFastLength = config.macdFastLength; mMacdSlowLength = config.macdSlowLength; mMacdSignaLength = config.macdSignaLength; mMacdAppliedTo = config.macdAppliedTo; mStochKLength = config.stochKLength; mStochDLength = config.stochDLength; mStochSlowing = config.stochSlowing; mStochMaMethod = config.stochMaMethod; mStochMode = config.stochMode; mStddevLength = config.stddevLength; mStddevShift = config.stddevShift; mStddevMethod = config.stddevMethod; mStddevAppliedTo = config.stddevAppliedTo; // result = Init(); // return result; } // // Reading Buffers based on Given Bar Index ... virtual void Calculate( int barIndex // Given Bar Index ) { // // ATR ... ArraySetAsSeries(atrBuffer, true); CopyBuffer( mHandler, XOSC_ATR_LINE, barIndex, mLoopbackBars, atrBuffer); // // RVI ... // // MAIN ... ArraySetAsSeries(rviMainBuffer, true); CopyBuffer( mHandler, XOSC_RVI_MAIN_LINE, barIndex, mLoopbackBars, rviMainBuffer); // // SIGNAL ... ArraySetAsSeries(rviSignalBuffer, true); CopyBuffer( mHandler, XOSC_RVI_SIGNAL_LINE, barIndex, mLoopbackBars, rviSignalBuffer); // // BULLPOWER ... ArraySetAsSeries(bullPBuffer, true); CopyBuffer( mHandler, XOSC_BULLP_LINE, barIndex, mLoopbackBars, bullPBuffer); // // BEARPOWER ... ArraySetAsSeries(bearPBuffer, true); CopyBuffer( mHandler, XOSC_BEARP_LINE, barIndex, mLoopbackBars, bearPBuffer); // // VOLUME ... ArraySetAsSeries(volumeBuffer, true); CopyBuffer( mHandler, XOSC_BEARP_LINE, barIndex, mLoopbackBars, volumeBuffer); // // RSI ... ArraySetAsSeries(rsiBuffer, true); CopyBuffer( mHandler, XOSC_VOLUME_LINE, barIndex, mLoopbackBars, rsiBuffer); // // CCI ... ArraySetAsSeries(cciBuffer, true); CopyBuffer( mHandler, XOSC_CCI_LINE, barIndex, mLoopbackBars, cciBuffer); // // MOMENTUM ... ArraySetAsSeries(momentumBuffer, true); CopyBuffer( mHandler, XOSC_MOMENTUM_LINE, barIndex, mLoopbackBars, momentumBuffer); // // SAR ... ArraySetAsSeries(sarBuffer, true); CopyBuffer( mHandler, XOSC_SAR_LINE, barIndex, mLoopbackBars, sarBuffer); // // MACD ... // // MAIN ... ArraySetAsSeries(macdMainBuffer, true); CopyBuffer( mHandler, XOSC_MACD_MAIN_LINE, barIndex, mLoopbackBars, macdMainBuffer); // // SIGNAL ... ArraySetAsSeries(macdSignalBuffer, true); CopyBuffer( mHandler, XOSC_MACD_SIGNAL_LINE, barIndex, mLoopbackBars, macdSignalBuffer); // // STOCHASTIC ... // // MAIN ... ArraySetAsSeries(stochMainBuffer, true); CopyBuffer( mHandler, XOSC_STOCH_MAIN_LINE, barIndex, mLoopbackBars, stochMainBuffer); // // SIGNAL ... ArraySetAsSeries(stochSignalBuffer, true); CopyBuffer( mHandler, XOSC_STOCH_SIGNAL_LINE, barIndex, mLoopbackBars, stochSignalBuffer); // // STANDARDDEVIATION ... ArraySetAsSeries(stddevBuffer, true); CopyBuffer( mHandler, XOSC_STDDEV_LINE, barIndex, mLoopbackBars, stddevBuffer); } // // Retrieve Info at Specific Bar Index ... XOSCInfo GetInfo( int barIndex // Given Bar Index ) { // XOSCInfo 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.atr = atrBuffer[barIndex]; result.rviMain = rviMainBuffer[barIndex]; result.rviSignal = rviSignalBuffer[barIndex]; result.bullPower = bullPBuffer[barIndex]; result.bearPower = bearPBuffer[barIndex]; result.volume = volumeBuffer[barIndex]; result.rsi = rsiBuffer[barIndex]; result.cci = cciBuffer[barIndex]; result.momentum = momentumBuffer[barIndex]; result.sar = sarBuffer[barIndex]; result.macdMain = macdMainBuffer[barIndex]; result.macdSignal = macdMainBuffer[barIndex]; result.stochMain = stochMainBuffer[barIndex]; result.stochSignal = stochSignalBuffer[barIndex]; result.stddev = stddevBuffer[barIndex]; // Copy( atrBuffer, result.atrs); Copy( rviMainBuffer, result.rviMains); Copy( rviSignalBuffer, result.rviSignals); Copy( bullPBuffer, result.bullPs); Copy( bearPBuffer, result.bearPs); Copy( volumeBuffer, result.volumes); Copy( rsiBuffer, result.rsis); Copy( cciBuffer, result.ccis); Copy( momentumBuffer, result.momentums); Copy( sarBuffer, result.sars); Copy( macdMainBuffer, result.macdMains); Copy( macdSignalBuffer, result.macdSignals); Copy( stochMainBuffer, result.stochMains); Copy( stochSignalBuffer, result.stochSignals); Copy( stddevBuffer, result.stddevs); // return result; } // // END Provided Functions ... // // // Protected ... protected: // // Private ... private: // // Indicator Properties ... // // ATR ... int mAtrLength; // // RVI ... int mRviLength; // // BULLPOWER ... int mBullpLength; // // BEARPOWER ... int mBearpLength; // // VOLUME ... ENUM_APPLIED_VOLUME mVolumeAppliedTo; // // RSI ... int mRsiLength; ENUM_APPLIED_PRICE mRsiAppliedTo; // // CCI ... int mCciLength; ENUM_APPLIED_PRICE mCciAppliedTo; // // MOMENTUM ... int mMomentumLength; ENUM_APPLIED_PRICE mMomentumAppliedTo; // // SAR ... double mSarStep; double mSarMaximum; // // MACD ... int mMacdFastLength; int mMacdSlowLength; int mMacdSignaLength; ENUM_APPLIED_PRICE mMacdAppliedTo; // // STOCHASTIC ... int mStochKLength; int mStochDLength; int mStochSlowing; ENUM_MA_METHOD mStochMaMethod; ENUM_STO_PRICE mStochMode; // // STANDARDDEVIATION ... int mStddevLength; int mStddevShift; ENUM_MA_METHOD mStddevMethod; ENUM_APPLIED_PRICE mStddevAppliedTo; }; // // START Usefull Functions ... // // // END Usefull Functions ... //