///////////////////////////////////////////////////////////////////////////// // // SaherElm IT Center MQL5 XRSI Oscillator 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" // // START Enum Definitions ... // // // XRSI Oscillator Buffer Lines ... // // // END Enum Definitions ... // // // START Inputs ... // // input group "XRSI Oscillator"; // // // input group "XRSI Market"; // input int xRSILength = 18; // Market Length // input ENUM_APPLIED_PRICE xRSIAppliedTo = PRICE_OPEN; // Applied To // // // input group "XRSI Short Entry"; // input double xRSIShortEntryValue = 70; // Short Entry Level // input color xRSIShortEntryColor = clrRed; // Short Entry Level Color // input ENUM_LINE_STYLE xRSIShortEntryLineStyle = STYLE_SOLID; // Short Entry Style // // // input group "XRSI Short Exit"; // input double xRSIShortExitValue = 40; // Short Exit Level // input color xRSIShortExitColor = clrRed; // Short Exit Level Color // input ENUM_LINE_STYLE xRSIShortExitLineStyle = STYLE_DOT; // Short Exit Style // // // input group "XRSI Long Entry"; // input double xRSILongEntryValue = 30; // Long Entry Level // input color xRSILongEntryColor = clrRed; // Long Entry Level Color // input ENUM_LINE_STYLE xRSILongEntryLineStyle = STYLE_SOLID; // Long Entry Style // // // input group "XRSI Long Exit"; // input double xRSILongExitValue = 60; // Long Exit Level // input color xRSILongExitColor = clrRed; // Long Exit Level Color // input ENUM_LINE_STYLE xRSILongExitLineStyle = STYLE_DOT; // Long Exit Style // // Configurations ... int xRSILength = 18; // Market Length ENUM_APPLIED_PRICE xRSIAppliedTo = PRICE_OPEN; // Applied To // double xRSIShortEntryValue = 70; // Short Entry Level color xRSIShortEntryColor = clrRed; // Short Entry Level Color ENUM_LINE_STYLE xRSIShortEntryLineStyle = STYLE_SOLID; // Short Entry Style // double xRSIShortExitValue = 40; // Short Exit Level color xRSIShortExitColor = clrRed; // Short Exit Level Color ENUM_LINE_STYLE xRSIShortExitLineStyle = STYLE_DOT; // Short Exit Style // double xRSILongEntryValue = 30; // Long Entry Level color xRSILongEntryColor = clrRed; // Long Entry Level Color ENUM_LINE_STYLE xRSILongEntryLineStyle = STYLE_SOLID; // Long Entry Style // double xRSILongExitValue = 60; // Long Exit Level color xRSILongExitColor = clrRed; // Long Exit Level Color ENUM_LINE_STYLE xRSILongExitLineStyle = STYLE_DOT; // Long Exit Style // // END Inputs ... // // // START Definitions ... // int xRSIHandler = INVALID_HANDLE; double xRSIBuffer[]; // // END Definitions ... // // // START Handler Functions ... // // // Validate Inputs ... bool XRSIValidateInputs() { // bool result = false; // result = xRSILongEntryValue < xRSILongExitValue && xRSIShortEntryValue > xRSIShortExitValue && xRSIShortEntryValue > xRSILongExitValue && xRSIShortExitValue < xRSILongExitValue; // if (!result) { // LogMessage("XRSI Oscillator Inputs Validation Failed ..."); } // return result; } // // Init Oscillators ... bool XRSIInitHandlers() { // bool result = false; // // Initialize Indicator/Oscillator Handlers ... ResetLastError(); // // XRSI Handler ... ArraySetAsSeries(xRSIBuffer, true); xRSIHandler = iCustom( _Symbol, _Period, "x-saherelm.xrsi.oscillator", // // Inputs ... // // Market ... "", xRSILength, xRSIAppliedTo, // // Short Entry ... "", xRSIShortEntryValue, xRSIShortEntryColor, xRSIShortEntryLineStyle, // // Short Exit ... "", xRSIShortExitValue, xRSIShortExitColor, xRSIShortExitLineStyle, // // Long Entry ... "", xRSILongEntryValue, xRSILongEntryColor, xRSILongEntryLineStyle, // // Long Exit ... "", xRSILongExitValue, xRSILongExitColor, xRSILongExitLineStyle // ); if (xRSIHandler == INVALID_HANDLE) { // LogMessage("failed to Initialize XRSI Oscillator: " + (string)GetLastError()); return result; } // result = true; // return result; } // // Release Oscillators ... void XRSIReleaseHandlers() { IndicatorRelease(xRSIHandler); } // // Handle Reading Buffers ... void XRSIReadBuffers( int xRSIItemsPerTick // Number Of Reading Buffer Items Per Tick ) { // // XRSI Signal ... CopyBuffer( xRSIHandler, 0, 0, xRSIItemsPerTick, xRSIBuffer); } // // END Handler Funcions ... // // // START XRSI Custom Functions ... // // // Check SC is Peak ... bool XRSIIsPeak( int bar_index, // Specified Index ... int length = 10 // Specified Length ... ) { // bool result = false; // if ( length <= 0 || bar_index <= 0 || !XRSIIsValidBuffersSize(bar_index + length + 1)) { return result; } // // Must Decreasing ... bool isIncreasing = IsIncreasing( bar_index + length, bar_index, xRSIBuffer // ); // return result; } // // Check SC is Vale ... bool XRSIIsVale( int bar_index, // Specified Index ... int length = 10 // Specified Length ... ) { // bool result = false; // if ( length <= 0 || bar_index <= 0 || !XRSIIsValidBuffersSize(bar_index + length + 1)) { return result; } // result = IsDecreasing( bar_index + length, bar_index, xRSIBuffer // ); // return result; } // // RSI Value GO Up from Long Entry ... bool XRSIIsCrossedOverLongEntry( int bar_index // Specified Index ... ) { // bool result = false; // if ( bar_index <= 0 || !XRSIIsValidBuffersSize(bar_index + 2)) { return result; } // result = xRSIBuffer[bar_index + 1] > xRSILongEntryValue && xRSIBuffer[bar_index + 2] <= xRSILongEntryValue; // return result; } // // RSI Value GO Up from Long Exit ... bool XRSIIsCrossedOverLongExit( int bar_index // Specified Index ... ) { // bool result = false; // if ( bar_index <= 0 || !XRSIIsValidBuffersSize(bar_index + 2)) { return result; } // result = xRSIBuffer[bar_index + 1] > xRSILongExitValue && xRSIBuffer[bar_index + 2] <= xRSILongExitValue; // return result; } // // RSI Value Go Down Short Entry ... bool XRSIIsCrossedUnderShortEntry( int bar_index // Specified Index ... ) { // bool result = false; // if ( bar_index <= 0 || !XRSIIsValidBuffersSize(bar_index + 2)) { return result; } // result = xRSIBuffer[bar_index + 1] < xRSIShortEntryValue && xRSIBuffer[bar_index + 2] >= xRSIShortEntryValue; // return result; } // // RSI Value Go Down Short Exit ... bool XRSIIsCrossedUnderShortExit( int bar_index // Specified Index ... ) { // bool result = false; // if ( bar_index <= 0 || !XRSIIsValidBuffersSize(bar_index + 2)) { return result; } // result = xRSIBuffer[bar_index + 1] < xRSIShortExitValue && xRSIBuffer[bar_index + 2] >= xRSIShortExitValue; // return result; } // // Check all Buffers has valid Size ... bool XRSIIsValidBuffersSize( int size // the size of buffers which min size for requirements ) { // bool result = false; // if ( size <= 0 || // ArraySize(xRSIBuffer) < size // ) { result = false; } else { result = true; } // return result; } // // END XRSI Custom Functions ... //