////////////////////////////////////////////////////// // // SaherElm IT Center MQL5 Indicator // --------------------------------------------- // Name: X121_XOSC // Description: provides some oscillator values // as empty Indicator ... // // // Maintainer: // ------------ // Hadi Khazaee Asl (hadi_khazaee_asl@yahoo.com) // ////////////////////////////////////////////////////// // // Global Properties ... #property copyright "Copyright 2023, SaherElm IT Center" #property link "https://saherelm.ir" #property version "1.00" #property description "SaherElm X121_XAMA Indicator" #property strict // // START Constants ... // #define ShortName "X121_XOSC" // // END Constants ... // // // START Inputs ... // // // ATR ... input group "ATR"; input int atrLength = 14; // Length // // RVI ... // The buffer numbers are the following: 0 - MAIN_LINE, 1 - SIGNAL_LINE. input group "RVI"; input int rviLength = 10; // Length // // BULLPOWER ... input group "Bulls Power"; input int bullpLength = 13; // Length // // BEARPOWER ... input group "Bears Power"; input int bearpLength = 13; // Length // // VOLUME ... input group "Volumes"; input ENUM_APPLIED_VOLUME volumeAppliedTo = VOLUME_TICK; // Applied To // // RSI ... input group "RSI"; input int rsiLength = 14; // Length input ENUM_APPLIED_PRICE rsiAppliedTo = PRICE_CLOSE; // Applied To // // CCI ... input group "CCI"; input int cciLength = 14; // Length input ENUM_APPLIED_PRICE cciAppliedTo = PRICE_TYPICAL; // Applied To // // STDDEV ... input group "Standard Deviation"; input int stddevLength = 20; // Length input int stddevShift = 0; // Shift input ENUM_MA_METHOD stddevMethod = MODE_SMA; // Mode input ENUM_APPLIED_PRICE stddevAppliedTo = PRICE_CLOSE; // AppliedTo // // MOMENTUM ... input group "Momentum"; input int momentumLength = 14; // Length input ENUM_APPLIED_PRICE momentumAppliedTo = PRICE_CLOSE; // Applied To // // SAR ... input group "SAR"; input double sarStep = 0.02; // Step input double sarMaximum = 0.2; // Maximum // // MACD ... // The buffer numbers are the following: 0 - MAIN_LINE, 1 - SIGNAL_LINE. input group "MACD"; input int macdFastLength = 12; // Fast Length input int macdSlowLength = 26; // Slow Length input int macdSignaLength = 9; // Signal Length input ENUM_APPLIED_PRICE macdAppliedTo = PRICE_CLOSE; // Applied To // // STOCHASTIC ... // The buffer numbers: 0 - MAIN_LINE, 1 - SIGNAL_LINE. input group "Stochastic"; input int stochKLength = 5; // K Length input int stochDLength = 3; // D Length input int stochSlowing = 3; // Slowing input ENUM_MA_METHOD stochMaMethod = MODE_SMA; // Ma Method input ENUM_STO_PRICE stochMode = STO_LOWHIGH; // Calculation Mode // // END Inputs ... // // // Includes Common Library ... #include "../Libraries/x-saherelm.common.lib.mq5" // // START Buffers ... // // #property indicator_chart_window // #property indicator_buffers 15 #property indicator_plots 0 // // ATR ... #define atrBufferIndex 0 double atrBuffer[]; // // RVI ... #define rviMainBufferIndex 1 #define rviSignalBufferIndex 2 double rviMainBuffer[]; double rviSignalBuffer[]; // // BULLPOWER ... #define bullPBufferIndex 3 double bullPBuffer[]; // // BEARPOWER ... #define bearPBufferIndex 4 double bearPBuffer[]; // // VOLUME ... #define volumeBufferIndex 5 double volumeBuffer[]; // // RSI ... #define rsiBufferIndex 6 double rsiBuffer[]; // // CCI ... #define cciBufferIndex 7 double cciBuffer[]; // // MOMENTUM ... #define momentumBufferIndex 8 double momentumBuffer[]; // // SAR ... #define sarBufferIndex 9 double sarBuffer[]; // // MACD ... #define macdMainBufferIndex 10 #define macdSignalBufferIndex 11 double macdMainBuffer[]; double macdSignalBuffer[]; // // STOCHASTIC ... #define stochMainBufferIndex 12 #define stochSignalBufferIndex 13 double stochMainBuffer[]; double stochSignalBuffer[]; // // STANDARDDEVIATION ... #define stddevBufferIndex 14 double stddevBuffer[]; // // END Buffers ... // // // START Global Definitions: Variables, Properties and etc ... // // int maxLength; // int atrHandler = INVALID_HANDLE; int rviHandler = INVALID_HANDLE; int bullPHandler = INVALID_HANDLE; int bearPHandler = INVALID_HANDLE; int volumeHandler = INVALID_HANDLE; int rsiHandler = INVALID_HANDLE; int cciHandler = INVALID_HANDLE; int momentumHandler = INVALID_HANDLE; int sarHandler = INVALID_HANDLE; int macdHandler = INVALID_HANDLE; int stochHandler = INVALID_HANDLE; int stddevHandler = INVALID_HANDLE; // // END Global Definitions: Variables, Properties and etc ... // // // START Event Handlers ... // // // Initialization ... int OnInit() { // // Validate Inputs ... if (!ValidateInputs()) { return INIT_PARAMETERS_INCORRECT; } // // because in some cases we may have more than one input for // calculation and we must prevent any calculation // untill we pass the biggest input length, here we get max Input length // and then wait until pass it ... maxLength = ExtractMaxLengthOfInputs(); // // Initializing Handlers ... // // ATR ... atrHandler = iATR( _Symbol, _Period, atrLength); // // RVI ... rviHandler = iRVI( _Symbol, _Period, rviLength); // // BULLSPOWER ... bullPHandler = iBullsPower( _Symbol, _Period, bullpLength); // // BEARSPOWER ... bearPHandler = iBearsPower( _Symbol, _Period, bullpLength); // // VOLUMES ... volumeHandler = iVolumes( _Symbol, _Period, volumeAppliedTo); // // RSI ... rsiHandler = iRSI( _Symbol, _Period, rsiLength, rsiAppliedTo); // // CCI ... cciHandler = iCCI( _Symbol, _Period, cciLength, cciAppliedTo); // // MOMENTUM ... momentumHandler = iMomentum( _Symbol, _Period, momentumLength, momentumAppliedTo); // // SAR ... sarHandler = iSAR( _Symbol, _Period, sarStep, sarMaximum); // // MACD ... macdHandler = iMACD( _Symbol, _Period, macdFastLength, macdSlowLength, macdSignaLength, macdAppliedTo); // // STOCHASTIC ... stochHandler = iStochastic( _Symbol, _Period, stochKLength, stochDLength, stochSlowing, stochMaMethod, stochMode); // // STANDARDDEVIATION ... stddevHandler = iStdDev( _Symbol, _Period, stddevLength, stddevShift, stddevMethod, stddevAppliedTo); // bool isAllHandlersInit = // atrHandler != INVALID_HANDLE && rviHandler != INVALID_HANDLE && bullPHandler != INVALID_HANDLE && bearPHandler != INVALID_HANDLE && volumeHandler != INVALID_HANDLE && rsiHandler != INVALID_HANDLE && cciHandler != INVALID_HANDLE && momentumHandler != INVALID_HANDLE && sarHandler != INVALID_HANDLE && macdHandler != INVALID_HANDLE && stochHandler != INVALID_HANDLE && stddevHandler != INVALID_HANDLE // ; if (!isAllHandlersInit) { return INIT_FAILED; } // // Define Index Buffers ... DefineBuffers(); // // Set Indicator ShortName ... SetIndicatorName(); // // Init Succeed ... return INIT_SUCCEEDED; } // // DeInitialization ... void OnDeinit(const int reason) { // // REASON_PROGRAM 0 The EA has stopped working calling the ExpertRemove() function // REASON_REMOVE 1 Program removed from a chart // REASON_RECOMPILE 2 Program recompiled // REASON_CHARTCHANGE 3 A symbol or a chart period is changed // REASON_CHARTCLOSE 4 Chart closed // REASON_PARAMETERS 5 Inputs changed by a user // REASON_ACCOUNT 6 Another account has been activated or reconnection to the trade server has occurred due to changes in the account settings // REASON_TEMPLATE 7 Another chart template applied // REASON_INITFAILED 8 The OnInit() handler returned a non-zero value // REASON_CLOSE 9 Terminal closed // // Here we can handle De Initialization Reasons ... IndicatorRelease(atrHandler); IndicatorRelease(rviHandler); IndicatorRelease(bullPHandler); IndicatorRelease(bearPHandler); IndicatorRelease(volumeHandler); IndicatorRelease(rsiHandler); IndicatorRelease(cciHandler); IndicatorRelease(momentumHandler); IndicatorRelease(sarHandler); IndicatorRelease(macdHandler); IndicatorRelease(stochHandler); IndicatorRelease(stddevHandler); } // // Calculating what we want ... int OnCalculate( // // total Candles on chart ... const int rates_total, // // total calculated Candles on charts ... const int prev_calculated, // // history of Candles Open Time ... const datetime &time[], // // history of Candles Open Price ... const double &open[], // // history of Candles High Price ... const double &high[], // // history of Candles Low Price ... const double &low[], // // history of Candles Close Price ... const double &close[], // // history of Tick Volumes on Candle ... const long &tick_volume[], // // history of Trade Volumes ... const long &volume[], // // history of Candles Spread Price ... const int &spread[]) { // // Prepare Buffers ... ArraySetAsSeries(time, true); ArraySetAsSeries(open, true); ArraySetAsSeries(high, true); ArraySetAsSeries(low, true); ArraySetAsSeries(close, true); ArraySetAsSeries(tick_volume, true); ArraySetAsSeries(volume, true); ArraySetAsSeries(spread, true); // // this counts Available Bars ... int limit; // // Check Calculated Bars ... int atrCalculatedBars = BarsCalculated(atrHandler); int rviCalculatedBars = BarsCalculated(rviHandler); int bullPCalculatedBars = BarsCalculated(bullPHandler); int bearPCalculatedBars = BarsCalculated(bearPHandler); int volumeCalculatedBars = BarsCalculated(volumeHandler); int rsiCalculatedBars = BarsCalculated(rsiHandler); int cciCalculatedBars = BarsCalculated(cciHandler); int momentumCalculatedBars = BarsCalculated(momentumHandler); int sarCalculatedBars = BarsCalculated(sarHandler); int macdCalculatedBars = BarsCalculated(macdHandler); int stochCalculatedBars = BarsCalculated(stochHandler); int stddevCalculatedBars = BarsCalculated(stddevHandler); // bool isCalculatedBarsPassed = // atrCalculatedBars >= maxLength && rviCalculatedBars >= maxLength && bullPCalculatedBars >= maxLength && bearPCalculatedBars >= maxLength && volumeCalculatedBars >= maxLength && rsiCalculatedBars >= maxLength && cciCalculatedBars >= maxLength && momentumCalculatedBars >= maxLength && sarCalculatedBars >= maxLength && macdCalculatedBars >= maxLength && stochCalculatedBars >= maxLength && stddevCalculatedBars >= maxLength // ; if (!isCalculatedBarsPassed) { return prev_calculated; } // limit = (prev_calculated > rates_total || prev_calculated <= 0) ? rates_total : (rates_total - prev_calculated) + 1; // // Buffers Copy ... int atrCopiedItems = CopyBuffer(atrHandler, 0, 0, limit, atrBuffer); int rviMainCopiedItems = CopyBuffer(rviHandler, MAIN_LINE, 0, limit, rviMainBuffer); int rviSignalCopiedItems = CopyBuffer(rviHandler, SIGNAL_LINE, 0, limit, rviSignalBuffer); int bullPCopiedItems = CopyBuffer(bullPHandler, 0, 0, limit, bullPBuffer); int bearPCopiedItems = CopyBuffer(bearPHandler, 0, 0, limit, bearPBuffer); int volumeCopiedItems = CopyBuffer(volumeHandler, 0, 0, limit, volumeBuffer); int rsiCopiedItems = CopyBuffer(rsiHandler, 0, 0, limit, rsiBuffer); int cciCopiedItems = CopyBuffer(cciHandler, 0, 0, limit, cciBuffer); int momentumCopiedItems = CopyBuffer(momentumHandler, 0, 0, limit, momentumBuffer); int sarCopiedItems = CopyBuffer(sarHandler, 0, 0, limit, sarBuffer); int macdMainCopiedItems = CopyBuffer(macdHandler, MAIN_LINE, 0, limit, macdMainBuffer); int macdSignalCopiedItems = CopyBuffer(macdHandler, SIGNAL_LINE, 0, limit, macdSignalBuffer); int stochMainCopiedItems = CopyBuffer(stochHandler, MAIN_LINE, 0, limit, stochMainBuffer); int stocSignalhCopiedItems = CopyBuffer(stochHandler, SIGNAL_LINE, 0, limit, stochSignalBuffer); int stddevCopiedItems = CopyBuffer(stddevHandler, 0, 0, limit, stddevBuffer); // bool isCopiedBarsPassed = // atrCopiedItems > 0 && rviMainCopiedItems > 0 && rviSignalCopiedItems > 0 && bullPCopiedItems > 0 && bearPCopiedItems > 0 && volumeCopiedItems > 0 && rsiCopiedItems > 0 && cciCopiedItems > 0 && momentumCopiedItems > 0 && sarCopiedItems > 0 && macdMainCopiedItems > 0 && macdSignalCopiedItems > 0 && stochMainCopiedItems > 0 && stocSignalhCopiedItems > 0 && stddevCopiedItems > 0 // ; if (!isCopiedBarsPassed) { return prev_calculated; } // // Main Loop ... for (int i = limit - 1; i >= 0 && !IsStopped(); i--) { // // Do Buffers Calculation ... // HERE We Do Not anything ... } // return rates_total; } // // END Event Handlers ... // // // START Functions ... // // // Validate Input Args for Initialization ... bool ValidateInputs() { // bool result = false; // // Validate Args ... result = // atrLength >= 2 && rviLength >= 2 && bullpLength >= 2 && bearpLength >= 2 && rsiLength >= 2 && cciLength >= 2 && momentumLength >= 2 && sarStep > 0 && sarStep < sarMaximum && macdFastLength >= 2 && macdSlowLength > macdFastLength && macdSignaLength >= 2 && stochKLength >= 2 && stochDLength >= 2 && stochSlowing >= 2 && stddevLength >= 2 && stddevShift >= 0 // ; // return result; } // // Retrieve all Exists Input Max Length ... // use for Start Of Drawing ... int ExtractMaxLengthOfInputs() { // int result = 0; // result = MathMax(atrLength, rviLength); result = MathMax(result, bullpLength); result = MathMax(result, bearpLength); result = MathMax(result, rsiLength); result = MathMax(result, cciLength); result = MathMax(result, momentumLength); result = MathMax(result, macdFastLength); result = MathMax(result, macdSlowLength); result = MathMax(result, macdSignaLength); result = MathMax(result, stochKLength); result = MathMax(result, stochDLength); result = MathMax(result, stochSlowing); result = MathMax(result, stddevLength); // return result; } // // Set Indicator Short Name and also we can define Buffers Labels ... void SetIndicatorName() { IndicatorSetString(INDICATOR_SHORTNAME, ShortName); } // // Define Indexes and Styles ... void DefineBuffers() { // // DATA Buffers ... // // ATR ... ArraySetAsSeries(atrBuffer, true); SetIndexBuffer(atrBufferIndex, atrBuffer, INDICATOR_CALCULATIONS); // // RVI ... // // Main ... ArraySetAsSeries(rviMainBuffer, true); SetIndexBuffer(rviMainBufferIndex, rviMainBuffer, INDICATOR_CALCULATIONS); // // Signal ... ArraySetAsSeries(rviSignalBuffer, true); SetIndexBuffer(rviSignalBufferIndex, rviSignalBuffer, INDICATOR_CALCULATIONS); // // BULLPOWER ... ArraySetAsSeries(bullPBuffer, true); SetIndexBuffer(bullPBufferIndex, bullPBuffer, INDICATOR_CALCULATIONS); // // BEARPOWER ... ArraySetAsSeries(bearPBuffer, true); SetIndexBuffer(bearPBufferIndex, bearPBuffer, INDICATOR_CALCULATIONS); // // VOLUME ... ArraySetAsSeries(volumeBuffer, true); SetIndexBuffer(volumeBufferIndex, volumeBuffer, INDICATOR_CALCULATIONS); // // RSI ... ArraySetAsSeries(rsiBuffer, true); SetIndexBuffer(rsiBufferIndex, rsiBuffer, INDICATOR_CALCULATIONS); // // CCI ... ArraySetAsSeries(cciBuffer, true); SetIndexBuffer(cciBufferIndex, cciBuffer, INDICATOR_CALCULATIONS); // // MOMENTUM ... ArraySetAsSeries(momentumBuffer, true); SetIndexBuffer(momentumBufferIndex, momentumBuffer, INDICATOR_CALCULATIONS); // // SAR ... ArraySetAsSeries(sarBuffer, true); SetIndexBuffer(sarBufferIndex, sarBuffer, INDICATOR_CALCULATIONS); // // STANDARDDEVIATION ... ArraySetAsSeries(stddevBuffer, true); SetIndexBuffer(stddevBufferIndex, stddevBuffer, INDICATOR_CALCULATIONS); // // MACD ... // // Main ... ArraySetAsSeries(macdMainBuffer, true); SetIndexBuffer(macdMainBufferIndex, macdMainBuffer, INDICATOR_CALCULATIONS); // // Signal ... ArraySetAsSeries(macdSignalBuffer, true); SetIndexBuffer(macdSignalBufferIndex, macdSignalBuffer, INDICATOR_CALCULATIONS); } // // END Functions ... //