///////////////////////////////////////////////////////////////////////////// // // SaherElm IT Center MQL5 XTM Indicator Helper for Signal Providers // -------------------------------------------------------------------------- // // // 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 // // Includes ... #include "..\Libraries\x-saherelm.log.lib.mq5" #include "..\Libraries\x-saherelm.common.lib.mq5" #include "x-saherelm.xmap.provider.inputs.lib.mq5" // // START Enum Definitions ... // // // XTM Indicator States ... enum ENUM_X_XTM_STATES { X_XTM_BULLISH = 1, X_XTM_BEARISH = -1, X_XTM_NEUTURAL = 0, }; // // XTM Indicator Buffer Lines ... enum ENUM_X_XTM_BUFFER_LINES { X_XTM_MA_LINE = 0, X_XTM_MC_COLOR_LINE = 1, X_XTM_STATE_LINE = 2, }; // // END Enum Definitions ... // // // START Inputs ... // input group "XTM Indicator"; input int xTMMaPeriod = 14; // Period input int xTMMaShift = 0; // Shift input ENUM_MA_METHOD xTMMaMethod = MODE_SMA; // Method input ENUM_APPLIED_PRICE xTMMaAppliedTo = PRICE_WEIGHTED; // Applied To // // END Inputs ... // // // START Definitions ... int xTMHandler = INVALID_HANDLE; double xTMMaBuffer[]; double xTMStateBuffer[]; // // END Definitions ... // // // START Handler Functions ... // // // Init Indicators ... bool XTMInitHandlers() { // bool result = false; // // Initialize Indicator/Oscillator Handlers ... ResetLastError(); // // XTM Handler ... ArraySetAsSeries(xTMMaBuffer, true); ArraySetAsSeries(xTMStateBuffer, true); xTMHandler = iCustom( _Symbol, _Period, "x-saherelm.xtm.indicator", // // Inputs ... xTMMaPeriod, xTMMaShift, xTMMaMethod, xTMMaAppliedTo); if (xTMHandler == INVALID_HANDLE) { // LogMessage("failed to Initialize XTM Indicator: " + (string)GetLastError()); return result; } // result = true; // return result; } // // Release Indicators ... void XTMReleaseHandlers() { IndicatorRelease(xTMHandler); } // // Handle Reading Buffers ... void XTMReadBuffers() { // // Ma Buffer ... CopyBuffer( xTMHandler, X_XTM_MA_LINE, 0, xMAPNumberOfItemsPerTick, xTMMaBuffer); // // State Buffer ... CopyBuffer( xTMHandler, X_XTM_STATE_LINE, 0, xMAPNumberOfItemsPerTick, xTMStateBuffer); } // // END Handler Funcions ... // // // START Signal Related Conditions ... // // // XTM Long Conditions ... bool XTMCanOpenLongTrades() { // bool result = false; // bool isValue = XTMIsVale(); // double minValue = GetMinValue( xMAPNumberOfItemsPerTick, xTMMaBuffer); double maxValue = GetMaxValue( xMAPNumberOfItemsPerTick, xTMMaBuffer); double currentValue = xTMMaBuffer[1]; bool isTMMinMaxPassed = currentValue < maxValue && currentValue > minValue; // bool isInPeak = IsInPeak( 14, xTMMaBuffer); // bool isSharpChanged = IsSharpChanged( 14, 1, xTMMaBuffer); bool isCandleSharpChanged = IsSharpChanged( 14, 1, PRICE_CLOSE); // result = // isValue // && // !isInPeak // && // !isSharpChanged // && // !isCandleSharpChanged // && // isTMMinMaxPassed; // return result; } // // XTM Close Long ... bool XTMCanCloseLongTrades() { // bool result = false; // // result = XTMCanOpenLongTrades(); // return result; } // // END Signal Related Conditions ... // // // START XTM Custom Functions ... // // // Find Peak based On this Indicator ... bool XTMIsPeak() { // bool result = false; // // Check Is Peak ... // // Must Increasing ... bool isDecreasing = IsDecreasing( 1, 3, xTMMaBuffer); // // Must Decreasing ... bool isIncreasing = IsIncreasing( 3, 10, xTMMaBuffer); // // Find State of First and Last ... double stateValue1 = xTMStateBuffer[1]; double stateValue2 = xTMStateBuffer[2]; bool isStatePassed = stateValue2 == X_XTM_NEUTURAL && stateValue1 == X_XTM_BEARISH; // // Calculate Result ... result = // isIncreasing // && // isDecreasing // && // isStatePassed // ; // return result; } // // Find Vale based On this Indicator ... bool XTMIsVale() { // bool result = false; // // Check Is Vale ... // // // // Retrieve Min Value ... // double minValue = GetMinValue( // loopback, // xTMMaBuffer); // // // // Retrieve Max Value ... // double maxValue = GetMinValue( // loopback, // xTMMaBuffer); // // // // Calculate Delta ... // double delta = maxValue - minValue; // bool isDeltaPassed = delta >= (xMAPNumberOfItemsPerTick * _Point); // // Must Decreasing ... bool isIncreasing = IsIncreasing( 3, 1, xTMMaBuffer); // // Must Increasing ... bool isDecreasing = IsDecreasing( 10, 3, xTMMaBuffer); // // Find State of First and Last ... double stateValue1 = xTMStateBuffer[1]; double stateValue2 = xTMStateBuffer[2]; bool isStatePassed = stateValue2 == X_XTM_NEUTURAL && stateValue1 == X_XTM_BULLISH; // // Calculate Result ... result = // // isDeltaPassed // // // && // isIncreasing // && // isDecreasing // // && // // // isStatePassed // ; // return result; } // // END XTM Custom Functions ... //