/////////////////////////////////////////////////////// // // SaherElm IT Center MQL4 Indicator Global Library // --------------------------------------------------- // saherelm useful tools and definitions ... // // // Maintainer: // ------------ // Hadi Khazaee Asl (hadi_khazaee_asl@yahoo.com) // ////////////////////////////////////////////////////// #property library #property copyright "Copyright 2023, SaherElm IT Center" #property link "https://www.saherelm.ir" #property version "1.00" #property strict // // Includes library ... #include "../Libraries/x-saherelm.lib.mq4" // // Includes Models library ... #include "../Libraries/x-saherelm.models.lib.mq4" // // START Global Requirement Functions ... // static double zigZags[]; // // END Global Requirement Functions ... // // // START Indicator Reading Data ... // // // START XMKT Data ... // XMKTState GetXMKT( const int bar_index, const int marketLen, // const bool showHighestHigh = true, const bool showHighestLow = true, const bool showHighestOpen = true, const bool showHighestClose = true, const bool showLowestHigh = true, const bool showLowestLow = true, const bool showLowestOpen = true, const bool showLowestClose = true, const color highestHighColor = clrDeepPink, const color highestLowColor = clrDarkOrange, const color highestOpenColor = clrDodgerBlue, const color highestCloseColor = clrOrchid, const color lowestHighColor = clrHotPink, const color lowestLowColor = clrOrange, const color lowestOpenColor = clrPowderBlue, const color lowestCloseColor = clrMediumOrchid, const ENUM_LINE_STYLE highestHighStyle = STYLE_DOT, const ENUM_LINE_STYLE highestLowStyle = STYLE_DOT, const ENUM_LINE_STYLE highestOpenStyle = STYLE_DOT, const ENUM_LINE_STYLE highestCloseStyle = STYLE_DOT, const ENUM_LINE_STYLE lowestHighStyle = STYLE_DOT, const ENUM_LINE_STYLE lowestLowStyle = STYLE_DOT, const ENUM_LINE_STYLE lowestOpenStyle = STYLE_DOT, const ENUM_LINE_STYLE lowestCloseStyle = STYLE_DOT ) { // XMKTState result = {}; // string xmktIndName = "x-saherelm.xmarket"; // int highestHighBufferIndex = 0; int highestLowBufferIndex = 1; int highestOpenBufferIndex = 2; int highestCloseBufferIndex = 3; int lowestHighBufferIndex = 4; int lowestLowBufferIndex = 5; int lowestOpenBufferIndex = 6; int lowestCloseBufferIndex = 7; // // Highest High ... double highestHigh = iCustom( _Symbol, _Period, xmktIndName, // // Inputs ... marketLen, showHighestHigh, showHighestLow, showHighestOpen, showHighestClose, showLowestHigh, showLowestLow, showLowestOpen, showLowestClose, highestHighColor, highestLowColor, highestOpenColor, highestCloseColor, lowestHighColor, lowestLowColor, lowestOpenColor, lowestCloseColor, highestHighStyle, highestLowStyle, highestOpenStyle, highestCloseStyle, lowestHighStyle, lowestLowStyle, lowestOpenStyle, lowestCloseStyle, // highestHighBufferIndex, // Buffer Index ... bar_index ); result.highestHigh = highestHigh; // // Highest Low ... double highestLow = iCustom( _Symbol, _Period, xmktIndName, // // Inputs ... marketLen, showHighestHigh, showHighestLow, showHighestOpen, showHighestClose, showLowestHigh, showLowestLow, showLowestOpen, showLowestClose, highestHighColor, highestLowColor, highestOpenColor, highestCloseColor, lowestHighColor, lowestLowColor, lowestOpenColor, lowestCloseColor, highestHighStyle, highestLowStyle, highestOpenStyle, highestCloseStyle, lowestHighStyle, lowestLowStyle, lowestOpenStyle, lowestCloseStyle, // highestLowBufferIndex, // Buffer Index ... bar_index ); result.highestLow = highestLow; // // Highest Open ... double highestOpen = iCustom( _Symbol, _Period, xmktIndName, // // Inputs ... marketLen, showHighestHigh, showHighestLow, showHighestOpen, showHighestClose, showLowestHigh, showLowestLow, showLowestOpen, showLowestClose, highestHighColor, highestLowColor, highestOpenColor, highestCloseColor, lowestHighColor, lowestLowColor, lowestOpenColor, lowestCloseColor, highestHighStyle, highestLowStyle, highestOpenStyle, highestCloseStyle, lowestHighStyle, lowestLowStyle, lowestOpenStyle, lowestCloseStyle, // highestOpenBufferIndex, // Buffer Index ... bar_index ); result.highestOpen = highestOpen; // // Highest Close ... double highestClose = iCustom( _Symbol, _Period, xmktIndName, // // Inputs ... marketLen, showHighestHigh, showHighestLow, showHighestOpen, showHighestClose, showLowestHigh, showLowestLow, showLowestOpen, showLowestClose, highestHighColor, highestLowColor, highestOpenColor, highestCloseColor, lowestHighColor, lowestLowColor, lowestOpenColor, lowestCloseColor, highestHighStyle, highestLowStyle, highestOpenStyle, highestCloseStyle, lowestHighStyle, lowestLowStyle, lowestOpenStyle, lowestCloseStyle, // highestCloseBufferIndex, // Buffer Index ... bar_index ); result.highestClose = highestClose; // // Lowest High ... double lowestHigh = iCustom( _Symbol, _Period, xmktIndName, // // Inputs ... marketLen, showHighestHigh, showHighestLow, showHighestOpen, showHighestClose, showLowestHigh, showLowestLow, showLowestOpen, showLowestClose, highestHighColor, highestLowColor, highestOpenColor, highestCloseColor, lowestHighColor, lowestLowColor, lowestOpenColor, lowestCloseColor, highestHighStyle, highestLowStyle, highestOpenStyle, highestCloseStyle, lowestHighStyle, lowestLowStyle, lowestOpenStyle, lowestCloseStyle, // lowestHighBufferIndex, // Buffer Index ... bar_index ); result.lowestHigh = lowestHigh; // // Lowest Low ... double lowestLow = iCustom( _Symbol, _Period, xmktIndName, // // Inputs ... marketLen, showHighestHigh, showHighestLow, showHighestOpen, showHighestClose, showLowestHigh, showLowestLow, showLowestOpen, showLowestClose, highestHighColor, highestLowColor, highestOpenColor, highestCloseColor, lowestHighColor, lowestLowColor, lowestOpenColor, lowestCloseColor, highestHighStyle, highestLowStyle, highestOpenStyle, highestCloseStyle, lowestHighStyle, lowestLowStyle, lowestOpenStyle, lowestCloseStyle, // lowestLowBufferIndex, // Buffer Index ... bar_index ); result.lowestLow = lowestLow; // // Lowest Open ... double lowestOpen = iCustom( _Symbol, _Period, xmktIndName, // // Inputs ... marketLen, showHighestHigh, showHighestLow, showHighestOpen, showHighestClose, showLowestHigh, showLowestLow, showLowestOpen, showLowestClose, highestHighColor, highestLowColor, highestOpenColor, highestCloseColor, lowestHighColor, lowestLowColor, lowestOpenColor, lowestCloseColor, highestHighStyle, highestLowStyle, highestOpenStyle, highestCloseStyle, lowestHighStyle, lowestLowStyle, lowestOpenStyle, lowestCloseStyle, // lowestOpenBufferIndex, // Buffer Index ... bar_index ); result.lowestOpen = lowestOpen; // // Lowest Close ... double lowestClose = iCustom( _Symbol, _Period, xmktIndName, // // Inputs ... marketLen, showHighestHigh, showHighestLow, showHighestOpen, showHighestClose, showLowestHigh, showLowestLow, showLowestOpen, showLowestClose, highestHighColor, highestLowColor, highestOpenColor, highestCloseColor, lowestHighColor, lowestLowColor, lowestOpenColor, lowestCloseColor, highestHighStyle, highestLowStyle, highestOpenStyle, highestCloseStyle, lowestHighStyle, lowestLowStyle, lowestOpenStyle, lowestCloseStyle, // lowestCloseBufferIndex, // Buffer Index ... bar_index ); result.lowestClose = lowestClose; // return result; } // // END XMKT Data ... // // // START XOSC Data ... // XCycleState GetXOSC( const int bar_index, const int marketLen, // const int fastMult, const int slowMult, // const double fastMMul = 1.0, const double slowMMul = 3.0 ) { // XCycleState result = {}; // string oscIndName = "x-saherelm.osc"; // // Prepare OSC Inputs ... // int fastLength = fastMult * marketLen; int slowLength = slowMult * marketLen; // // Fast ... double fast = iCustom( _Symbol, _Period, oscIndName, // // Inputs ... fastLength, fastMMul, slowLength, slowMMul, // 0, // Buffer Index ... bar_index ); result.fast = fast; // // Slow ... double slow = iCustom( _Symbol, _Period, oscIndName, // // Inputs ... fastLength, fastMMul, slowLength, slowMMul, // 1, // Buffer Index ... bar_index ); result.slow = slow; // return result; } // // END XOSC Data ... // // // START XBND Data ... // XBndState GetXBND( const int bar_index, // const int marketLen = 10, // Market Length ... const int shift = 0, // MA Shift ... const ENUM_MA_METHOD method = MODE_SMA // MA Method ... ) { // XBndState result = {}; // double high = GetMA( bar_index, marketLen, shift, method, PRICE_HIGH ); result.high = high; // double open = GetMA( bar_index, marketLen, shift, method, PRICE_OPEN ); result.open = open; // double close = GetMA( bar_index, marketLen, shift, method, PRICE_CLOSE ); result.close = close; // double low = GetMA( bar_index, marketLen, shift, method, PRICE_LOW ); result.low = low; // return result; } // // END XBND Data ... // // // START ZigZag Data ... // void PrepareZigZagState( const int bar_index, // const int depth = 12, const int deviation = 5, const int backStep = 3 ) { // string zigzagIndName = "x-saherelm.zigzag"; // ArrayFree(zigZags); ArrayResize( zigZags, 3 ); // double zigZag = 0; int index = 0; int i = bar_index; while (index < 3) { // zigZag = iCustom( _Symbol, _Period, zigzagIndName, // // Inputs ... depth, deviation, backStep, // 0, // Buffer Index ... i ); // if (zigZag > 0) { // zigZags[index] = zigZag; index++; } // i++; } } // // END ZigZag Data ... // // // START XMA Data ... // // // Retrieve Short Cycle ... XCycleState GetXMASC( const int bar_index, const int marketLen, const int fastMultiplier, const int slowMultiplier, // const int shift = 0, const ENUM_MA_METHOD method = MODE_SMA, const ENUM_APPLIED_PRICE appliedPrice = PRICE_CLOSE ) { // XCycleState result = {}; // int fastLength = marketLen * fastMultiplier; int slowLength = marketLen * slowMultiplier; // double fast = iMA( _Symbol, _Period, fastLength, shift, method, appliedPrice, bar_index ); result.fast = fast; // double slow = iMA( _Symbol, _Period, slowLength, shift, method, appliedPrice, bar_index ); result.slow= slow; // return result; } // // Retrieve Medium Cycle ... XCycleState GetXMAMC( const int bar_index, const int marketLen, const int fastMultiplier, const int slowMultiplier, // const int shift = 0, const ENUM_MA_METHOD method = MODE_SMA, const ENUM_APPLIED_PRICE appliedPrice = PRICE_CLOSE ) { // XCycleState result = {}; // int fastLength = marketLen * fastMultiplier; int slowLength = marketLen * slowMultiplier; // double fast = iMA( _Symbol, _Period, fastLength, shift, method, appliedPrice, bar_index ); result.fast = fast; // double slow = iMA( _Symbol, _Period, slowLength, shift, method, appliedPrice, bar_index ); result.slow= slow; // return result; } // // Retrieve Long Cycle ... XCycleState GetXMALC( const int bar_index, const int marketLen, const int fastMultiplier, const int slowMultiplier, // const int shift = 0, const ENUM_MA_METHOD method = MODE_SMA, const ENUM_APPLIED_PRICE appliedPrice = PRICE_CLOSE ) { // XCycleState result = {}; // int fastLength = marketLen * fastMultiplier; int slowLength = marketLen * slowMultiplier; // double fast = iMA( _Symbol, _Period, fastLength, shift, method, appliedPrice, bar_index ); result.fast = fast; // double slow = iMA( _Symbol, _Period, slowLength, shift, method, appliedPrice, bar_index ); result.slow = slow; // return result; } // // Retrieve Long Cycle ... XCycleState GetXMANN( const int bar_index, // const int shift = 0, const ENUM_MA_METHOD method = MODE_SMA, const ENUM_APPLIED_PRICE appliedPrice = PRICE_CLOSE ) { // XCycleState result = {}; // int fastLength = 10; int slowLength = 50; // double fast = iMA( _Symbol, _Period, fastLength, shift, method, appliedPrice, bar_index ); result.fast = fast; // double slow = iMA( _Symbol, _Period, slowLength, shift, method, appliedPrice, bar_index ); result.slow = slow; // return result; } // // Retrieve Middle ... double GetXMAMM( const int bar_index, const int marketLen, const double multiplier, // const int shift = 0, const ENUM_MA_METHOD method = MODE_EMA, const ENUM_APPLIED_PRICE appliedPrice = PRICE_MEDIAN ) { // double result = 0; // int length = (int)(marketLen * multiplier); // double middle = iMA( _Symbol, _Period, length, shift, method, appliedPrice, bar_index ); result = middle; // return result; } // // Retrieve XMA Parabolic SAR ... double GetXMAPSAR( const int bar_index, // double stp = 0.02, double mxm = 0.2 ) { // double result = 0; // double pSar = iSAR( _Symbol, _Period, stp, mxm, bar_index ); result = pSar; // return result; } // XState GetXState( const int bar_index, const int marketLen, // const double stp, const double mxm, // const int shortCycleFastMult, const int shortCycleSlowMult, const int mediumCycleFastMult, const int mediumCycleSlowMult, const int longCycleFastMult, const int longCycleSlowMult ) { // XState result = {}; // // Short Cycle ... XCycleState sc = GetXMASC( bar_index, marketLen, shortCycleFastMult, shortCycleSlowMult ); result.sc = sc; // // Medium Cycle ... XCycleState mc = GetXMAMC( bar_index, marketLen, mediumCycleFastMult, mediumCycleSlowMult ); result.mc = mc; // // Long Cycle ... XCycleState lc = GetXMALC( bar_index, marketLen, longCycleFastMult, longCycleSlowMult ); result.lc = lc; // // OSC ... XCycleState osc = GetXOSC( // bar_index, marketLen, // shortCycleFastMult, shortCycleSlowMult ); result.osc = osc; // // Parabolic SAR ... double parabolicSAR = GetXMAPSAR( bar_index, stp, mxm ); result.parabolicSAR = parabolicSAR; // // Market Middleage ... double marketMiddleage = GetXMAMM( bar_index, marketLen, 1.5 ); result.marketMiddleage = marketMiddleage; // // // int cciMarketLength = longCycleSlowMult * marketLen; // double cci = GetMarketCCI( // bar_index, // cciMarketLength // ); // result.cci = cci; // XBndState bnd = GetXBND( bar_index ); result.bnd = bnd; // XMKTState mkt = GetXMKT( bar_index, marketLen ); result.mkt = mkt; // return result; } // // END XMA Data ... // // // END Indicator Reading Data ... //