Files
MQL5Data/X121XKIEA/Classes/x-saherelm.x121.xki.parser.class.mq5
T

1435 lines
28 KiB
Plaintext

///////////////////////////////////////////////////////
//
// SaherElm IT Center MQL5 Helper Parser Class Library
// ----------------------------------------------------
// Name: XCX121XKIHelperParser
// Description: provides all Indicator
// Helper Parse requirements ...
//
//
// 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
//
// Imports ...
#include "../../Helpers/x-saherelm.x121.xki.helper.mq5"
//
// Definitions ...
//
// Implementation ...
class XCX121XKIHelperParser : XCBase
{
//
// Public ...
public:
//
string symbol;
ENUM_TIMEFRAMES period;
//
// Constructor ...
XCX121XKIHelperParser(XCX121XKIHelper *_helper)
{
//
helper = _helper;
symbol = _helper.GetSymbol();
period = _helper.GetPeriod();
}
//
// Deconstructor ...
~XCX121XKIHelperParser()
{
ZeroMemory(helper);
}
//
// Tools ...
/**
* Validate ...
*
* @return ( bool )
*/
bool IsValid()
{
//
bool result = false;
//
result = helper != NULL &&
helper.IsValid() &&
IsXValid(symbol) &&
IsXValid(period);
//
return result;
}
/**
* Normalize Bar Index ...
*
* @param barIndex: int, Provided Bar Index ...
*
* @return ( int )
*/
int NormalizeBarIndex(int barIndex = 0)
{
//
int result = -1;
//
if (!IsValid())
{
return result;
}
//
result = helper.NormalizeBarIndex(barIndex);
//
return result;
}
//
// Parsers ...
// Indicators Base Conditions ...
// #region KI Fast ...
bool IsKIFastBullish(int barIndex = 0)
{
//
bool result = false;
//
// Normalize ...
barIndex = NormalizeBarIndex(barIndex);
//
// Validate ...
result = IsValid();
if (!result)
{
return result;
}
//
double state = helper.GetKIFastState(barIndex);
result = state >= 1;
//
return result;
}
bool IsKIFastBearish(int barIndex = 0)
{
//
bool result = false;
//
// Normalize ...
barIndex = NormalizeBarIndex(barIndex);
//
// Validate ...
result = IsValid();
if (!result)
{
return result;
}
//
double state = helper.GetKIFastState(barIndex);
result = state <= -1;
//
return result;
}
bool IsKIFastSwitchedToBullish(int barIndex = 0)
{
//
bool result = false;
//
// Normalize ...
barIndex = NormalizeBarIndex(barIndex);
//
// Validate ...
result = IsValid();
if (!result)
{
return result;
}
//
result = IsKIFastBullish(barIndex) &&
!IsKIFastBullish(barIndex + 1);
//
return result;
}
bool IsKIFastSwitchedToBearish(int barIndex = 0)
{
//
bool result = false;
//
// Normalize ...
barIndex = NormalizeBarIndex(barIndex);
//
// Validate ...
result = IsValid();
if (!result)
{
return result;
}
//
result = IsKIFastBearish(barIndex) &&
!IsKIFastBearish(barIndex + 1);
//
return result;
}
bool IsKIFastOverLast(
int barIndex = 0,
double distancePoint = 5 //
)
{
//
bool result = false;
//
// Normalize ...
barIndex = NormalizeBarIndex(barIndex);
//
// Validate ...
result = IsValid();
if (!result)
{
return result;
}
//
double value = helper.GetKIFast(barIndex);
double pValue = helper.GetKIFast(barIndex + 1);
double point = GetPoints(symbol);
double distance = point * distancePoint;
//
result = value >= pValue + distance;
//
return result;
}
bool IsKIFastUnderLast(
int barIndex = 0,
double distancePoint = 5 //
)
{
//
bool result = false;
//
// Normalize ...
barIndex = NormalizeBarIndex(barIndex);
//
// Validate ...
result = IsValid();
if (!result)
{
return result;
}
//
double value = helper.GetKIFast(barIndex);
double pValue = helper.GetKIFast(barIndex + 1);
double point = GetPoints(symbol);
double distance = point * distancePoint;
//
result = value <= pValue - distance;
//
return result;
}
// #endregion
// #region KI Slow ...
bool IsKISlowBullish(int barIndex = 0)
{
//
bool result = false;
//
// Normalize ...
barIndex = NormalizeBarIndex(barIndex);
//
// Validate ...
result = IsValid();
if (!result)
{
return result;
}
//
double state = helper.GetKISlowState(barIndex);
result = state >= 1;
//
return result;
}
bool IsKISlowBearish(int barIndex = 0)
{
//
bool result = false;
//
// Normalize ...
barIndex = NormalizeBarIndex(barIndex);
//
// Validate ...
result = IsValid();
if (!result)
{
return result;
}
//
double state = helper.GetKISlowState(barIndex);
result = state <= -1;
//
return result;
}
bool IsKISlowSwitchedToBullish(int barIndex = 0)
{
//
bool result = false;
//
// Normalize ...
barIndex = NormalizeBarIndex(barIndex);
//
// Validate ...
result = IsValid();
if (!result)
{
return result;
}
//
result = IsKISlowBullish(barIndex) &&
!IsKISlowBullish(barIndex + 1);
//
return result;
}
bool IsKISlowSwitchedToBearish(int barIndex = 0)
{
//
bool result = false;
//
// Normalize ...
barIndex = NormalizeBarIndex(barIndex);
//
// Validate ...
result = IsValid();
if (!result)
{
return result;
}
//
result = IsKISlowBearish(barIndex) &&
!IsKISlowBearish(barIndex + 1);
//
return result;
}
bool IsKISlowOverLast(
int barIndex = 0,
double distancePoint = 5 //
)
{
//
bool result = false;
//
// Normalize ...
barIndex = NormalizeBarIndex(barIndex);
//
// Validate ...
result = IsValid();
if (!result)
{
return result;
}
//
double value = helper.GetKISlow(barIndex);
double pValue = helper.GetKISlow(barIndex + 1);
double point = GetPoints(symbol);
double distance = point * distancePoint;
//
result = value >= pValue + distance;
//
return result;
}
bool IsKISlowUnderLast(
int barIndex = 0,
double distancePoint = 5 //
)
{
//
bool result = false;
//
// Normalize ...
barIndex = NormalizeBarIndex(barIndex);
//
// Validate ...
result = IsValid();
if (!result)
{
return result;
}
//
double value = helper.GetKISlow(barIndex);
double pValue = helper.GetKISlow(barIndex + 1);
double point = GetPoints(symbol);
double distance = point * distancePoint;
//
result = value <= pValue - distance;
//
return result;
}
// #endregion
// #region KI Wave ...
bool IsKIWaveBullish(int barIndex = 0)
{
//
bool result = false;
//
// Normalize ...
barIndex = NormalizeBarIndex(barIndex);
//
// Validate ...
result = IsValid();
if (!result)
{
return result;
}
//
result = helper.GetKIWaveState(barIndex) >= 1;
//
return result;
}
bool IsKIWaveBearish(int barIndex = 0)
{
//
bool result = false;
//
// Normalize ...
barIndex = NormalizeBarIndex(barIndex);
//
// Validate ...
result = IsValid();
if (!result)
{
return result;
}
//
result = helper.GetKIWaveState(barIndex) <= -1;
//
return result;
}
bool IsKIWaveSwitchedToBullish(int barIndex = 0)
{
//
bool result = false;
//
// Normalize ...
barIndex = NormalizeBarIndex(barIndex);
//
// Validate ...
result = IsValid();
if (!result)
{
return result;
}
//
result = IsKIWaveBullish(barIndex) &&
!IsKIWaveBullish(barIndex + 1);
//
return result;
}
bool IsKIWaveSwitchedToBearish(int barIndex = 0)
{
//
bool result = false;
//
// Normalize ...
barIndex = NormalizeBarIndex(barIndex);
//
// Validate ...
result = IsValid();
if (!result)
{
return result;
}
//
result = IsKIWaveBearish(barIndex) &&
!IsKIWaveBearish(barIndex + 1);
//
return result;
}
// #endregion
// #region KI Band ...
bool IsPriceAboveKIUpper(
int barIndex = 0,
ENUM_X_PRICE priceType = X_PRICE_CLOSE //
)
{
//
bool result = false;
//
// Normalize ...
barIndex = NormalizeBarIndex(barIndex);
//
// Validate ...
result = IsValid() &&
IsXValid(priceType);
if (!result)
{
return result;
}
//
XOHCL bar;
result = bar.Init(symbol, period, barIndex);
if (!result)
{
return result;
}
//
double price = bar.GetPrice(priceType);
result = price > helper.GetKIUpper(barIndex);
bar.Clean();
//
return result;
}
bool IsPriceBelowKILower(
int barIndex = 0,
ENUM_X_PRICE priceType = X_PRICE_CLOSE //
)
{
//
bool result = false;
//
// Normalize ...
barIndex = NormalizeBarIndex(barIndex);
//
// Validate ...
result = IsValid() &&
IsXValid(priceType);
if (!result)
{
return result;
}
//
XOHCL bar;
result = bar.Init(symbol, period, barIndex);
if (!result)
{
return result;
}
//
double price = bar.GetPrice(priceType);
result = price < helper.GetKILower(barIndex);
bar.Clean();
//
return result;
}
bool IsPriceInsideKIBands(
int barIndex = 0,
ENUM_X_PRICE priceType = X_PRICE_CLOSE //
)
{
//
bool result = false;
//
// Normalize ...
barIndex = NormalizeBarIndex(barIndex);
//
// Validate ...
result = IsValid() &&
IsXValid(priceType);
if (!result)
{
return result;
}
//
XOHCL bar;
result = bar.Init(symbol, period, barIndex);
if (!result)
{
return result;
}
//
double price = bar.GetPrice(priceType);
result = price < helper.GetKIUpper(barIndex) &&
price > helper.GetKILower(barIndex);
bar.Clean();
//
return result;
}
// #endregion
// #region MA Fast/Slow ...
bool IsMACrossoverBullish(int barIndex = 0)
{
//
bool result = false;
//
// Normalize ...
barIndex = NormalizeBarIndex(barIndex);
//
// Validate ...
result = IsValid();
if (!result)
{
return result;
}
//
result = helper.GetMAFast(barIndex) > helper.GetMASlow(barIndex);
return result;
}
bool IsMACrossoverBearish(int barIndex = 0)
{
//
bool result = false;
//
// Normalize ...
barIndex = NormalizeBarIndex(barIndex);
//
// Validate ...
result = IsValid();
if (!result)
{
return result;
}
//
result = helper.GetMAFast(barIndex) < helper.GetMASlow(barIndex);
return result;
}
bool IsMACrossoverSwitchedToBullish(int barIndex = 0)
{
//
bool result = false;
//
// Normalize ...
barIndex = NormalizeBarIndex(barIndex);
//
// Validate ...
result = IsValid();
if (!result)
{
return result;
}
//
result = IsMACrossoverBullish(barIndex) &&
!IsMACrossoverBullish(barIndex + 1);
return result;
}
bool IsMACrossoverSwitchedToBearish(int barIndex = 0)
{
//
bool result = false;
//
// Normalize ...
barIndex = NormalizeBarIndex(barIndex);
//
// Validate ...
result = IsValid();
if (!result)
{
return result;
}
//
result = IsMACrossoverBearish(barIndex) &&
!IsMACrossoverBearish(barIndex + 1);
return result;
}
bool IsMAFastAboveKI(int barIndex = 0)
{
//
bool result = false;
//
// Normalize ...
barIndex = NormalizeBarIndex(barIndex);
//
// Validate ...
result = IsValid();
if (!result)
{
return result;
}
//
result = helper.GetMAFast(barIndex) > helper.GetKIFast(barIndex);
return result;
}
bool IsMASlowAboveKI(int barIndex = 0)
{
//
bool result = false;
//
// Normalize ...
barIndex = NormalizeBarIndex(barIndex);
//
// Validate ...
result = IsValid();
if (!result)
{
return result;
}
//
result = helper.GetMASlow(barIndex) > helper.GetKISlow(barIndex);
return result;
}
// #endregion
// #region ATR ...
bool IsATRBreakoutUp(
int barIndex = 0,
ENUM_X_PRICE priceType = X_PRICE_CLOSE //
)
{
//
bool result = false;
//
// Normalize ...
barIndex = NormalizeBarIndex(barIndex);
//
// Validate ...
result = IsValid() &&
IsXValid(priceType);
if (!result)
{
return result;
}
//
XOHCL bar;
result = bar.Init(symbol, period, barIndex);
if (!result)
{
return result;
}
//
double price = bar.GetPrice(priceType);
result = price > helper.GetATRRawUpper(barIndex);
bar.Clean();
//
return result;
}
bool IsATRBreakoutDown(
int barIndex = 0,
ENUM_X_PRICE priceType = X_PRICE_CLOSE //
)
{
//
bool result = false;
//
// Normalize ...
barIndex = NormalizeBarIndex(barIndex);
//
// Validate ...
result = IsValid() &&
IsXValid(priceType);
if (!result)
{
return result;
}
//
XOHCL bar;
result = bar.Init(symbol, period, barIndex);
if (!result)
{
return result;
}
//
double price = bar.GetPrice(priceType);
result = price < helper.GetATRRawLower(barIndex);
bar.Clean();
//
return result;
}
bool IsVolatilityHigh(int barIndex = 0)
{
//
bool result = false;
//
// Normalize ...
barIndex = NormalizeBarIndex(barIndex);
//
// Validate ...
result = IsValid();
if (!result)
{
return result;
}
//
double atr = helper.GetATR(barIndex);
double atrMa = helper.GetATRSmoothed(barIndex);
result = atr > atrMa;
//
return result;
}
bool IsVolatilityLow(int barIndex = 0)
{
//
bool result = false;
//
// Normalize ...
barIndex = NormalizeBarIndex(barIndex);
//
// Validate ...
result = IsValid();
if (!result)
{
return result;
}
//
double atr = helper.GetATR(barIndex);
double atrMa = helper.GetATRSmoothed(barIndex);
result = atr < atrMa;
//
return result;
}
// #endregion
// #region RSI ...
bool IsRSIBullish(int barIndex = 0)
{
//
bool result = false;
//
// Normalize ...
barIndex = NormalizeBarIndex(barIndex);
//
// Validate ...
result = IsValid();
if (!result)
{
return result;
}
//
result = helper.GetRSI(barIndex) > 50;
return result;
}
bool IsRSIBearish(int barIndex = 0)
{
//
bool result = false;
//
// Normalize ...
barIndex = NormalizeBarIndex(barIndex);
//
// Validate ...
result = IsValid();
if (!result)
{
return result;
}
//
result = helper.GetRSI(barIndex) < 50;
return result;
}
bool IsRSIOverbought(int barIndex = 0)
{
//
bool result = false;
//
// Normalize ...
barIndex = NormalizeBarIndex(barIndex);
//
// Validate ...
result = IsValid();
if (!result)
{
return result;
}
//
result = helper.GetRSI(barIndex) > 70;
return result;
}
bool IsRSIOversold(int barIndex = 0)
{
//
bool result = false;
//
// Normalize ...
barIndex = NormalizeBarIndex(barIndex);
//
// Validate ...
result = IsValid();
if (!result)
{
return result;
}
//
result = helper.GetRSI(barIndex) < 30;
return result;
}
bool IsRSISwitchedToBullish(int barIndex = 0)
{
//
bool result = false;
//
// Normalize ...
barIndex = NormalizeBarIndex(barIndex);
//
// Validate ...
result = IsValid();
if (!result)
{
return result;
}
//
result = IsRSIBullish(barIndex) && !IsRSIBullish(barIndex + 1);
return result;
}
bool IsRSISwitchedToBearish(int barIndex = 0)
{
//
bool result = false;
//
// Normalize ...
barIndex = NormalizeBarIndex(barIndex);
//
// Validate ...
result = IsValid();
if (!result)
{
return result;
}
//
result = IsRSIBearish(barIndex) && !IsRSIBearish(barIndex + 1);
return result;
}
// #endregion
// #region Composite ...
bool IsTrendBullish(int barIndex = 0)
{
//
bool result = false;
//
// Normalize ...
barIndex = NormalizeBarIndex(barIndex);
//
// Validate ...
result = IsValid();
if (!result)
{
return result;
}
//
result = IsKIFastBullish(barIndex) &&
IsKISlowBullish(barIndex) &&
IsMACrossoverBullish(barIndex);
//
return result;
}
bool IsTrendBearish(int barIndex = 0)
{
//
bool result = false;
//
// Normalize ...
barIndex = NormalizeBarIndex(barIndex);
//
// Validate ...
result = IsValid();
if (!result)
{
return result;
}
//
result = IsKIFastBearish(barIndex) &&
IsKISlowBearish(barIndex) &&
IsMACrossoverBearish(barIndex);
//
return result;
}
bool IsBullishMomentumTrend(int barIndex = 0)
{
//
bool result = false;
//
// Normalize ...
barIndex = NormalizeBarIndex(barIndex);
//
// Validate ...
result = IsValid();
if (!result)
{
return result;
}
//
result = IsTrendBullish(barIndex) &&
IsRSIBullish(barIndex);
//
return result;
}
bool IsBearishMomentumTrend(int barIndex = 0)
{
//
bool result = false;
//
// Normalize ...
barIndex = NormalizeBarIndex(barIndex);
//
// Validate ...
result = IsValid();
if (!result)
{
return result;
}
//
result = IsTrendBearish(barIndex) &&
IsRSIBearish(barIndex);
//
return result;
}
bool IsBullishBreakout(int barIndex = 0)
{
//
bool result = false;
//
// Normalize ...
barIndex = NormalizeBarIndex(barIndex);
//
// Validate ...
result = IsValid();
if (!result)
{
return result;
}
//
result =
IsPriceAboveKIUpper(barIndex) &&
IsATRBreakoutUp(barIndex) &&
IsVolatilityHigh(barIndex);
//
return result;
}
bool IsBearishBreakout(int barIndex = 0)
{
//
bool result = false;
//
// Normalize ...
barIndex = NormalizeBarIndex(barIndex);
//
// Validate ...
result = IsValid();
if (!result)
{
return result;
}
//
result =
IsPriceBelowKILower(barIndex) &&
IsATRBreakoutDown(barIndex) &&
IsVolatilityHigh(barIndex);
return result;
}
bool IsBullishReversal(int barIndex = 0)
{
//
bool result = false;
//
// Normalize ...
barIndex = NormalizeBarIndex(barIndex);
//
// Validate ...
result = IsValid();
if (!result)
{
return result;
}
//
// RSI oversold and turning upward ...
double rsiNow = helper.GetRSI(barIndex);
double rsiPrev = helper.GetRSI(barIndex + 1);
bool rsiFlip = (rsiNow > rsiPrev) && (rsiPrev < 30);
//
// ATR check (volatility supportive) ...
double atrNow = helper.GetATR(barIndex);
double atrPrev = helper.GetATR(barIndex + 1);
double atrMaNow = helper.GetATRSmoothed(barIndex);
double atrMaPrev = helper.GetATRSmoothed(barIndex + 1);
bool atrOk = atrNow > atrMaNow || atrNow > atrPrev || atrMaNow > atrMaPrev;
//
// MA crossover bullish ...
double maFastNow = helper.GetMAFast(barIndex);
double maSlowNow = helper.GetMASlow(barIndex);
bool maOk = maFastNow > maSlowNow;
//
result = rsiFlip && (atrOk || maOk);
//
return result;
}
bool IsBearishReversal(int barIndex = 0)
{
//
bool result = false;
//
// Normalize ...
barIndex = NormalizeBarIndex(barIndex);
//
// Validate ...
result = IsValid();
if (!result)
{
return result;
}
//
// RSI overbought and turning downward ...
double rsiNow = helper.GetRSI(barIndex);
double rsiPrev = helper.GetRSI(barIndex + 1);
bool rsiFlip = (rsiNow < rsiPrev) && (rsiPrev > 70);
//
// ATR check (volatility supportive) ...
double atrNow = helper.GetATR(barIndex);
double atrPrev = helper.GetATR(barIndex + 1);
double atrMaNow = helper.GetATRSmoothed(barIndex);
double atrMaPrev = helper.GetATRSmoothed(barIndex + 1);
bool atrOk = atrNow > atrMaNow || atrNow > atrPrev || atrMaNow > atrMaPrev;
//
// MA crossover bearish ...
double maFastNow = helper.GetMAFast(barIndex);
double maSlowNow = helper.GetMASlow(barIndex);
bool maOk = maFastNow < maSlowNow;
//
result = rsiFlip && (atrOk || maOk);
//
return result;
}
bool IsSafeBullishEntry(int barIndex = 0)
{
//
bool result = false;
//
// Normalize ...
barIndex = NormalizeBarIndex(barIndex);
//
// Validate ...
result = IsValid();
if (!result)
{
return result;
}
//
result = IsBullishMomentumTrend(barIndex) && !IsRSIOverbought(barIndex);
return result;
}
bool IsSafeBearishEntry(int barIndex = 0)
{
//
bool result = false;
//
// Normalize ...
barIndex = NormalizeBarIndex(barIndex);
//
// Validate ...
result = IsValid();
if (!result)
{
return result;
}
//
result = IsBearishMomentumTrend(barIndex) && !IsRSIOversold(barIndex);
return result;
}
bool IsTrendStrongBullish(int barIndex = 0)
{
//
bool result = false;
//
// Normalize ...
barIndex = NormalizeBarIndex(barIndex);
//
// Validate ...
result = IsValid();
if (!result)
{
return result;
}
//
// Strong bullish trend requires:
// - KI Fast bullish
// - KI Slow bullish
// - MA crossover bullish
// - RSI > 60
// - Volatility high
result = IsKIFastBullish(barIndex) &&
IsKISlowBullish(barIndex) &&
IsMACrossoverBullish(barIndex) &&
(helper.GetRSI(barIndex) > 60) &&
IsVolatilityHigh(barIndex);
//
return result;
}
bool IsTrendStrongBearish(int barIndex = 0)
{
//
bool result = false;
//
// Normalize ...
barIndex = NormalizeBarIndex(barIndex);
//
// Validate ...
result = IsValid();
if (!result)
{
return result;
}
//
// Strong bearish trend requires:
// - KI Fast bearish
// - KI Slow bearish
// - MA crossover bearish
// - RSI < 40
// - Volatility high
result = IsKIFastBearish(barIndex) &&
IsKISlowBearish(barIndex) &&
IsMACrossoverBearish(barIndex) &&
(helper.GetRSI(barIndex) < 40) &&
IsVolatilityHigh(barIndex);
//
return result;
}
// #endregion
//
// Protected ...
protected:
//
//
// Private ...
private:
//
XCX121XKIHelper *helper;
//
};
//