Files
xMQL5/MQLTestWorkspace/BKPS/BKP/x121 old style indicators/Helpers/x-saherelm.x121.xpv.helper.mq5
T

707 lines
14 KiB
Plaintext

///////////////////////////////////////////////////////
//
// SaherElm IT Center MQL5 Class Library
// --------------------------------------
// Name: XPV Indicator Provider
// Description: Peaks and Vales ...
//
//
// 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
//
// START Import and Inclused requirements ...
//
//
// Includes ...
#include "../Libraries/x-saherelm.alert.lib.mq5"
#include "../Libraries/x-saherelm.models.lib.mq5"
#include "../Libraries/x-saherelm.common.lib.mq5"
//
// END Import and Inclused requirements ...
//
//
// START Definitions ...
//
//
// XPeaksAndVales Exported Buffers ...
enum ENUM_X_XPV_BUFFERS
{
//
// PEAKSANDVALES ...
X_PV_P_LINE = 0,
X_PV_V_LINE = 1,
//
// SUPPORTRESISTANCE ...
X_PV_R_LINE = 2,
X_PV_S_LINE = 4,
//
// SHORT ...
X_PV_SHH_LINE = 6,
X_PV_SLL_LINE = 7,
//
// MEDIUM ...
X_PV_MHH_LINE = 8,
X_PV_MLL_LINE = 9,
//
// LONG ...
X_PV_LHH_LINE = 10,
X_PV_LLL_LINE = 11,
//
// HIND ...
X_PV_HHH_LINE = 12,
X_PV_HLL_LINE = 13,
};
//
// END Definitions ...
//
//
// START Overrides ...
//
//
// END Overrides ...
//
class XSCXPVHelper
{
//
public:
//
// Properties ...
double pBuffer[];
double vBuffer[];
double rBuffer[];
double sBuffer[];
double sHHBuffer[];
double sLLBuffer[];
double mHHBuffer[];
double mLLBuffer[];
double lHHBuffer[];
double lLLBuffer[];
double hHHBuffer[];
double hLLBuffer[];
//
// Constructor ...
void XSCXPVHelper()
{
mSymbol = _Symbol;
mPeriod = _Period;
}
void XSCXPVHelper(
//
// Symbol ...
string symbol,
//
// Period ...
ENUM_TIMEFRAMES period,
//
// Buffer Reading ...
int numberOfItemsReadPerTick = 52,
//
// MARKET ...
int shortLength = 9,
int mediumLength = 17,
int longLength = 26,
int hindLength = 35,
//
// TREND ...
int numOfShoulder = 10,
//
// DETECTION ...
ENUM_SERIESMODE hhMode = MODE_HIGH,
ENUM_SERIESMODE llMode = MODE_LOW
//
)
{
//
// Setting Requirements ...
//
// Symbol ...
mSymbol = symbol;
//
// Period ...
mPeriod = period;
//
// Number of Reading Buffer Items per Tick ...
mNumberOfItemsReadPerTick = numberOfItemsReadPerTick;
//
// MARKET ...
mShortLength = shortLength;
mMediumLength = mediumLength;
mLongLength = longLength;
mHindLength = hindLength;
//
// TREND ...
mNumOfShoulder = numOfShoulder;
//
// DETECTION ...
mHhMode = hhMode;
mLlMode = llMode;
//
mTag = "XPV " + mSymbol + ", " + ToString(mPeriod);
//
// Initial Handler ...
mHandler = iCustom(
mSymbol,
mPeriod,
"x-saherelm.x121.xpv",
//
// Inputs ...
//
// MARKET ...
"",
mShortLength,
mMediumLength,
mLongLength,
mHindLength,
//
// TREND ...
"",
mNumOfShoulder,
//
// DETECTION ...
"",
mHhMode,
mLlMode,
//
"",
false,
false,
false,
false
//
);
if (mHandler == INVALID_HANDLE)
{
LogMessage("failed to Initialize Indicator: " + (string)GetLastError());
}
//
// PEAKSANDVALES ...
ArraySetAsSeries(pBuffer, true);
ArraySetAsSeries(vBuffer, true);
//
// RESISTANCESUPPORT ...
ArraySetAsSeries(rBuffer, true);
ArraySetAsSeries(sBuffer, true);
//
// SHORT ...
ArraySetAsSeries(sHHBuffer, true);
ArraySetAsSeries(sLLBuffer, true);
//
// MEDIUM ...
ArraySetAsSeries(mHHBuffer, true);
ArraySetAsSeries(mLLBuffer, true);
//
// LONG ...
ArraySetAsSeries(lHHBuffer, true);
ArraySetAsSeries(lLLBuffer, true);
//
// HIND ...
ArraySetAsSeries(lHHBuffer, true);
ArraySetAsSeries(lLLBuffer, true);
}
//
// DeConstructor ...
void ~XSCXPVHelper()
{
//
// Release Indicators ...
IndicatorRelease(mHandler);
}
//
// Reading Buffers ...
void ReadBuffers()
{
//
// PEAKS ...
CopyBuffer(
mHandler,
X_PV_P_LINE,
0,
mNumberOfItemsReadPerTick,
pBuffer);
//
// VALES ...
CopyBuffer(
mHandler,
X_PV_V_LINE,
0,
mNumberOfItemsReadPerTick,
vBuffer);
//
// R ...
CopyBuffer(
mHandler,
X_PV_R_LINE,
0,
mNumberOfItemsReadPerTick,
rBuffer);
//
// S ...
CopyBuffer(
mHandler,
X_PV_S_LINE,
0,
mNumberOfItemsReadPerTick,
sBuffer);
//
// SHORT ...
//
// HIGH ...
CopyBuffer(
mHandler,
X_PV_SHH_LINE,
0,
mNumberOfItemsReadPerTick,
sHHBuffer);
//
// LOW ...
CopyBuffer(
mHandler,
X_PV_SLL_LINE,
0,
mNumberOfItemsReadPerTick,
sLLBuffer);
//
// MEIUM ...
//
// HIGH ...
CopyBuffer(
mHandler,
X_PV_MHH_LINE,
0,
mNumberOfItemsReadPerTick,
mHHBuffer);
//
// LOW ...
CopyBuffer(
mHandler,
X_PV_MLL_LINE,
0,
mNumberOfItemsReadPerTick,
mLLBuffer);
//
// LONG ...
//
// HIGH ...
CopyBuffer(
mHandler,
X_PV_LHH_LINE,
0,
mNumberOfItemsReadPerTick,
lHHBuffer);
//
// LOW ...
CopyBuffer(
mHandler,
X_PV_LLL_LINE,
0,
mNumberOfItemsReadPerTick,
lLLBuffer);
//
// HIND ...
//
// HIGH ...
CopyBuffer(
mHandler,
X_PV_HHH_LINE,
0,
mNumberOfItemsReadPerTick,
hHHBuffer);
//
// LOW ...
CopyBuffer(
mHandler,
X_PV_HLL_LINE,
0,
mNumberOfItemsReadPerTick,
hLLBuffer);
}
//
// START Tools Functions ...
//
//
// Check isPeak ...
bool IsPeak(int bar_index)
{
//
bool result = false;
//
if (!IsValidArraySize(bar_index))
{
return result;
}
//
result = rBuffer[bar_index] == hHHBuffer[bar_index] &&
hHHBuffer[bar_index] == lHHBuffer[bar_index] &&
lHHBuffer[bar_index] == mHHBuffer[bar_index] &&
mHHBuffer[bar_index] == sHHBuffer[bar_index];
//
return result;
}
//
// Check isVale ...
bool IsVale(int bar_index)
{
//
bool result = false;
//
if (!IsValidArraySize(bar_index))
{
return result;
}
//
result = sBuffer[bar_index] == hLLBuffer[bar_index] &&
hLLBuffer[bar_index] == lLLBuffer[bar_index] &&
lLLBuffer[bar_index] == mLLBuffer[bar_index] &&
mLLBuffer[bar_index] == sLLBuffer[bar_index];
//
return result;
}
//
// Is Strong Support ...
bool IsStrongSupport(int bar_index)
{
//
bool result = false;
//
if (!IsValidArraySize(bar_index + 3))
{
return result;
}
//
result =
//
hLLBuffer[bar_index + 1] == hLLBuffer[bar_index + 2] &&
hLLBuffer[bar_index + 2] == hLLBuffer[bar_index + 3] &&
//
lLLBuffer[bar_index + 1] == lLLBuffer[bar_index + 2] &&
lLLBuffer[bar_index + 2] == lLLBuffer[bar_index + 3] &&
//
mLLBuffer[bar_index + 1] == mLLBuffer[bar_index + 2] &&
mLLBuffer[bar_index + 2] == mLLBuffer[bar_index + 3] &&
//
sLLBuffer[bar_index + 1] == sLLBuffer[bar_index + 2] &&
sLLBuffer[bar_index + 2] == sLLBuffer[bar_index + 3]
//
;
//
return result;
}
//
// Is Strong Resistance ...
bool IsStrongResistance(int bar_index)
{
//
bool result = false;
//
if (!IsValidArraySize(bar_index + 2))
{
return result;
}
//
result =
//
hHHBuffer[bar_index + 1] == hHHBuffer[bar_index + 2] &&
hHHBuffer[bar_index + 2] == hHHBuffer[bar_index + 3] &&
//
lHHBuffer[bar_index + 1] == lHHBuffer[bar_index + 2] &&
lHHBuffer[bar_index + 2] == lHHBuffer[bar_index + 3] &&
//
mHHBuffer[bar_index + 1] == mHHBuffer[bar_index + 2] &&
mHHBuffer[bar_index + 2] == mHHBuffer[bar_index + 3] &&
//
sHHBuffer[bar_index + 1] == sHHBuffer[bar_index + 2] &&
sHHBuffer[bar_index + 2] == sHHBuffer[bar_index + 3]
//
;
//
return result;
}
//
// Find Last Strong Support ...
double GetLastStrongSupport(
int bar_index, // Bar Index ...
int length // LoopBack ...
)
{
//
double result = 0;
//
bool isBarIndexSupport = IsStrongSupport(bar_index);
if (isBarIndexSupport)
{
length += bar_index;
}
//
if (!IsValidArraySize(bar_index + length + 1))
{
return result;
}
//
for (int i = bar_index; i < bar_index + length; i++)
{
//
if (IsStrongSupport(i))
{
//
result = sLLBuffer[i];
break;
}
}
//
return result;
}
//
// Find Last Strong Resistance ...
double GetLastStrongResistance(
int bar_index, // Bar Index ...
int length // LoopBack ...
)
{
//
double result = 0;
//
bool isBarIndexResistance = IsStrongResistance(bar_index);
if (isBarIndexResistance)
{
length += bar_index;
}
//
if (!IsValidArraySize(bar_index + length + 1))
{
return result;
}
//
for (int i = bar_index; i < bar_index + length; i++)
{
//
if (IsStrongResistance(i))
{
//
result = sHHBuffer[i];
break;
}
}
//
return result;
}
//
// Find Strong Support Break Stop ...
bool IsSupportBreakedStop(
int bar_index, // Bar Index ...
int length // LoopBack ...
)
{
//
bool result = false;
//
bool isBaIndexSupport = IsStrongSupport(bar_index);
if (isBaIndexSupport)
{
return result;
}
//
if (!IsValidArraySize(bar_index + length + 1))
{
return result;
}
//
bool isAllStrongSupport = true;
for (int i = bar_index; i < bar_index + length; i++)
{
//
if (!IsStrongSupport(i) && isAllStrongSupport)
{
//
isAllStrongSupport = false;
break;
}
}
//
result = !isBaIndexSupport && isAllStrongSupport;
//
return result;
}
//
// Find Strong Resistance Break Stop ...
bool IsResistanceBreakedStop(
int bar_index, // Bar Index ...
int length // LoopBack ...
)
{
//
bool result = false;
//
bool isBaIndexResistance = IsStrongResistance(bar_index);
if (isBaIndexResistance)
{
return result;
}
//
if (!IsValidArraySize(bar_index + length + 1))
{
return result;
}
//
bool isAllStrongResistance = true;
for (int i = bar_index; i < bar_index + length; i++)
{
//
if (!IsStrongResistance(i) && isAllStrongResistance)
{
//
isAllStrongResistance = false;
break;
}
}
//
result = !isBaIndexResistance && isAllStrongResistance;
//
return result;
}
//
// END Tools Functions ...
//
//
protected:
//
private:
//
// Symbol ...
string mSymbol;
//
// Period ...
ENUM_TIMEFRAMES mPeriod;
//
// Buffer Reading ...
int mNumberOfItemsReadPerTick;
//
// MARKET ...
int mShortLength;
int mMediumLength;
int mLongLength;
int mHindLength;
//
// TREND ...
int mNumOfShoulder;
//
// DETECTION ...
ENUM_SERIESMODE mHhMode;
ENUM_SERIESMODE mLlMode;
//
string mTag;
//
int mHandler;
//
bool IsValidArraySize(int bar_index)
{
//
bool result = false;
//
if (bar_index < 0)
{
return result;
}
//
int rCount = ArraySize(rBuffer);
result = rCount > bar_index + 1;
//
return result;
}
};