Files
xEaPacks/EURUSD-5M-V0.1/MQ5/Libraries/x-saherelm.xrsi.oscillator.helper.lib.mq5
T
2024-01-25 04:08:38 +03:30

425 lines
7.4 KiB
Plaintext

/////////////////////////////////////////////////////////////////////////////
//
// 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 = 14; // Market Length
input ENUM_APPLIED_PRICE xRSIAppliedTo = PRICE_CLOSE; // 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 = clrFuchsia; // 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 = clrGreen; // 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 = clrAqua; // Long Exit Level Color
input ENUM_LINE_STYLE xRSILongExitLineStyle = STYLE_DOT; // Long Exit Style
//
// END Inputs ...
//
//
// START Definitions ...
//
int xRSIHandler = INVALID_HANDLE;
double xRSIBuffer[];
//
// END Definitions ...
//
//
// START Handler Functions ...
//
//
// 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 Signal Related Conditions ...
//
//
// XRSI Long Conditions ...
bool XRSIHasLongConditions(
int xRSIItemsPerTick // Number Of Reading Buffer Items Per Tick
)
{
//
bool result = false;
//
return result;
}
//
// XRSI Short Conditions ...
bool XRSIHasShortConditions(
int xRSIItemsPerTick // Number Of Reading Buffer Items Per Tick
)
{
//
bool result = false;
//
return result;
}
//
// END Signal Related Conditions ...
//
//
// START XRSI Custom Functions ...
//
//
// Check SC is Peak ...
bool XRSIIsPeak()
{
//
bool result = false;
//
bool isIncreasing = IsIncreasing(
11,
3,
xRSIBuffer);
//
bool isDecreasing = IsDecreasing(
3,
1,
xRSIBuffer);
//
// Generating Result ...
result =
//
isIncreasing
//
&&
//
isDecreasing
//
;
//
return result;
}
//
// Check SC is Vale ...
bool XRSIIsVale()
{
//
bool result = false;
//
bool isIncreasing = IsIncreasing(
3,
1,
xRSIBuffer);
//
bool isDecreasing = IsDecreasing(
11,
3,
xRSIBuffer);
//
// Generating Result ...
result =
//
isIncreasing
//
&&
//
isDecreasing
//
;
//
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 ...
//