Files
xMQL5/Libraries/x-saherelm.xtm.indicator.helper.lib.mq5
T
2024-01-25 04:09:42 +03:30

476 lines
8.3 KiB
Plaintext

/////////////////////////////////////////////////////////////////////////////
//
// 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"
//
// 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;
}
//
// xTMOHandler ...
// ArraySetAsSeries(xTMOBuffer, true);
// xTMOHandler = iCustom(
// _Symbol,
// _Period,
// "x-saherelm.xma.indicator",
// //
// // Inputs ...
// xTMMaPeriod,
// xTMMaShift,
// MODE_SMA,
// PRICE_OPEN);
// if (xTMOHandler == INVALID_HANDLE)
// {
// //
// LogMessage("failed to Initialize XMA Indicator: " + (string)GetLastError());
// return result;
// }
//
result = true;
//
return result;
}
//
// Release Indicators ...
void XTMReleaseHandlers()
{
IndicatorRelease(xTMHandler);
// IndicatorRelease(xTMOHandler);
}
//
// Handle Reading Buffers ...
void XTMReadBuffers(
int xTMItemsPerTick // Number Of Reading Buffer Items Per Tick
)
{
//
// Ma Buffer ...
CopyBuffer(
xTMHandler,
X_XTM_MA_LINE,
0,
xTMItemsPerTick,
xTMMaBuffer);
//
// State Buffer ...
CopyBuffer(
xTMHandler,
X_XTM_STATE_LINE,
0,
xTMItemsPerTick,
xTMStateBuffer);
//
// XTMO Buffer ...
// CopyBuffer(
// xTMOHandler,
// 0,
// 0,
// xTMItemsPerTick,
// xTMOBuffer);
}
//
// END Handler Funcions ...
//
//
// START Signal Related Conditions ...
//
//
// XTM Long Conditions ...
bool XTMHasLongConditions(
int xTMItemsPerTick // Number Of Reading Buffer Items Per Tick
)
{
//
bool result = false;
//
bool isPeak = XTMIsPeak();
bool isVale = XTMIsVale();
//
double minValue = GetMinValue(
xTMItemsPerTick,
xTMMaBuffer);
double maxValue = GetMaxValue(
xTMItemsPerTick,
xTMMaBuffer);
double currentValue = xTMMaBuffer[1];
bool isTMMinMaxPassed =
currentValue < maxValue && currentValue > minValue;
//
bool isInPeak = IsInPeak(
15,
xTMMaBuffer);
//
bool isSharpChanged = IsSharpChanged(
15,
1,
xTMMaBuffer);
bool isCandleSharpChanged = IsSharpChanged(
15,
1,
PRICE_CLOSE);
//
double entry = GetEntry(X_SIGNAL_LONG);
double maxPrice = GetHighestHigh(
7,
0);
double minPrice = GetLowestLow(
7,
0);
double priceDelta = maxPrice - minPrice;
double priceStep = priceDelta / 7;
//
bool isPricePassed =
entry < maxPrice &&
maxPrice - entry < (priceDelta / 4) * 3;
//
result =
//
isVale
//
&&
//
!isInPeak
//
&&
//
!isSharpChanged
//
&&
//
isPricePassed
//
&&
//
!isCandleSharpChanged
//
;
//
return result;
}
//
// XTM Short Conditions ...
bool XTMHasShortConditions(
int xTMItemsPerTick // Number Of Reading Buffer Items Per Tick
)
{
//
bool result = false;
//
bool isPeak = XTMIsPeak();
bool isValue = XTMIsVale();
//
double minValue = GetMinValue(
xTMItemsPerTick,
xTMMaBuffer);
double maxValue = GetMaxValue(
xTMItemsPerTick,
xTMMaBuffer);
double currentValue = xTMMaBuffer[1];
bool isTMMinMaxPassed =
currentValue < maxValue && currentValue > minValue;
//
bool isInPeak = IsInPeak(
15,
xTMMaBuffer);
bool isInVale = IsInVale(
15,
xTMMaBuffer);
//
bool isSharpChanged = IsSharpChanged(
15,
1,
xTMMaBuffer);
bool isCandleSharpChanged = IsSharpChanged(
15,
1,
PRICE_CLOSE);
//
double entry = GetEntry(X_SIGNAL_SHORT);
double maxPrice = GetHighestHigh(
7,
0);
double minPrice = GetLowestLow(
7,
0);
double priceDelta = maxPrice - minPrice;
double priceStep = priceDelta / 7;
//
bool isPricePassed =
entry > minPrice &&
minPrice + entry > (priceDelta / 4);
//
result =
//
isPeak
//
&&
//
!isInVale
//
&&
//
!isSharpChanged
//
&&
//
isPricePassed
//
&&
//
!isCandleSharpChanged
;
//
return result;
}
//
// END Signal Related Conditions ...
//
//
// START XTM Custom Functions ...
//
//
// Find Peak based On this Indicator ...
bool XTMIsPeak()
{
//
bool result = false;
//
// Check Is Vale ...
//
double currentValue = xTMMaBuffer[1];
//
// Must Decreasing ...
bool isIncreasing = IsIncreasing(
15,
3,
xTMMaBuffer);
//
// Must Increasing ...
bool isDecreasing = IsDecreasing(
3,
1,
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 ...
//
double currentValue = xTMMaBuffer[1];
//
// Must Decreasing ...
bool isIncreasing = IsIncreasing(
3,
1,
xTMMaBuffer);
//
// Must Increasing ...
bool isDecreasing = IsDecreasing(
15,
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 =
//
isIncreasing
//
&&
//
isDecreasing
//
&&
//
isStatePassed
//
;
//
return result;
}
//
// END XTM Custom Functions ...
//