2585 lines
48 KiB
Plaintext
2585 lines
48 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;
|
|
}
|
|
|
|
bool IsKIFastSameAsLast(int barIndex = 0)
|
|
{
|
|
//
|
|
bool result = false;
|
|
|
|
//
|
|
barIndex = NormalizeBarIndex(barIndex);
|
|
|
|
//
|
|
result = IsValid() &&
|
|
helper.GetKIFast(barIndex) == helper.GetKIFast(barIndex + 1);
|
|
|
|
//
|
|
return result;
|
|
}
|
|
|
|
bool IsKIFastSwitchedOverLast(int barIndex = 0)
|
|
{
|
|
//
|
|
bool result = false;
|
|
|
|
//
|
|
barIndex = NormalizeBarIndex(barIndex);
|
|
|
|
//
|
|
result =
|
|
IsValid() &&
|
|
IsKIFastOverLast(barIndex) &&
|
|
!IsKIFastOverLast(barIndex + 1);
|
|
if (!result)
|
|
{
|
|
return result;
|
|
}
|
|
|
|
//
|
|
return result;
|
|
}
|
|
|
|
bool IsKIFastSwitchedUnderLast(int barIndex = 0)
|
|
{
|
|
//
|
|
bool result = false;
|
|
|
|
//
|
|
barIndex = NormalizeBarIndex(barIndex);
|
|
|
|
//
|
|
result =
|
|
IsValid() &&
|
|
IsKIFastUnderLast(barIndex) &&
|
|
!IsKIFastUnderLast(barIndex + 1);
|
|
if (!result)
|
|
{
|
|
return result;
|
|
}
|
|
|
|
//
|
|
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;
|
|
}
|
|
|
|
bool IsKISlowSameAsLast(int barIndex = 0)
|
|
{
|
|
//
|
|
bool result = false;
|
|
|
|
//
|
|
barIndex = NormalizeBarIndex(barIndex);
|
|
|
|
//
|
|
result = IsValid() &&
|
|
helper.GetKISlow(barIndex) == helper.GetKISlow(barIndex + 1);
|
|
|
|
//
|
|
return result;
|
|
}
|
|
|
|
bool IsKISlowSwitchedOverLast(int barIndex = 0)
|
|
{
|
|
//
|
|
bool result = false;
|
|
|
|
//
|
|
barIndex = NormalizeBarIndex(barIndex);
|
|
|
|
//
|
|
result =
|
|
IsValid() &&
|
|
IsKISlowOverLast(barIndex) &&
|
|
!IsKISlowOverLast(barIndex + 1);
|
|
if (!result)
|
|
{
|
|
return result;
|
|
}
|
|
|
|
//
|
|
return result;
|
|
}
|
|
|
|
bool IsKISlowSwitchedUnderLast(int barIndex = 0)
|
|
{
|
|
//
|
|
bool result = false;
|
|
|
|
//
|
|
barIndex = NormalizeBarIndex(barIndex);
|
|
|
|
//
|
|
result =
|
|
IsValid() &&
|
|
IsKISlowUnderLast(barIndex) &&
|
|
!IsKISlowUnderLast(barIndex + 1);
|
|
if (!result)
|
|
{
|
|
return result;
|
|
}
|
|
|
|
//
|
|
return result;
|
|
}
|
|
// #endregion
|
|
|
|
// #region KI Super Slow ...
|
|
bool IsKISuperSlowBullish(int barIndex = 0)
|
|
{
|
|
//
|
|
bool result = false;
|
|
|
|
//
|
|
// Normalize ...
|
|
barIndex = NormalizeBarIndex(barIndex);
|
|
|
|
//
|
|
// Validate ...
|
|
result = IsValid();
|
|
if (!result)
|
|
{
|
|
return result;
|
|
}
|
|
|
|
//
|
|
double state = helper.GetKISuperSlowState(barIndex);
|
|
result = state >= 1;
|
|
|
|
//
|
|
return result;
|
|
}
|
|
|
|
bool IsKISuperSlowBearish(int barIndex = 0)
|
|
{
|
|
//
|
|
bool result = false;
|
|
|
|
//
|
|
// Normalize ...
|
|
barIndex = NormalizeBarIndex(barIndex);
|
|
|
|
//
|
|
// Validate ...
|
|
result = IsValid();
|
|
if (!result)
|
|
{
|
|
return result;
|
|
}
|
|
|
|
//
|
|
double state = helper.GetKISuperSlowState(barIndex);
|
|
result = state <= -1;
|
|
|
|
//
|
|
return result;
|
|
}
|
|
|
|
bool IsKISuperSlowSwitchedToBullish(int barIndex = 0)
|
|
{
|
|
//
|
|
bool result = false;
|
|
|
|
//
|
|
// Normalize ...
|
|
barIndex = NormalizeBarIndex(barIndex);
|
|
|
|
//
|
|
// Validate ...
|
|
result = IsValid();
|
|
if (!result)
|
|
{
|
|
return result;
|
|
}
|
|
|
|
//
|
|
result = IsKISuperSlowBullish(barIndex) &&
|
|
!IsKISuperSlowBullish(barIndex + 1);
|
|
|
|
//
|
|
return result;
|
|
}
|
|
|
|
bool IsKISuperSlowSwitchedToBearish(int barIndex = 0)
|
|
{
|
|
//
|
|
bool result = false;
|
|
|
|
//
|
|
// Normalize ...
|
|
barIndex = NormalizeBarIndex(barIndex);
|
|
|
|
//
|
|
// Validate ...
|
|
result = IsValid();
|
|
if (!result)
|
|
{
|
|
return result;
|
|
}
|
|
|
|
//
|
|
result = IsKISuperSlowBearish(barIndex) &&
|
|
!IsKISuperSlowBearish(barIndex + 1);
|
|
|
|
//
|
|
return result;
|
|
}
|
|
|
|
bool IsKISuperSlowOverLast(
|
|
int barIndex = 0,
|
|
double distancePoint = 5 //
|
|
)
|
|
{
|
|
//
|
|
bool result = false;
|
|
|
|
//
|
|
// Normalize ...
|
|
barIndex = NormalizeBarIndex(barIndex);
|
|
|
|
//
|
|
// Validate ...
|
|
result = IsValid();
|
|
if (!result)
|
|
{
|
|
return result;
|
|
}
|
|
|
|
//
|
|
double value = helper.GetKISuperSlow(barIndex);
|
|
double pValue = helper.GetKISuperSlow(barIndex + 1);
|
|
double point = GetPoints(symbol);
|
|
double distance = point * distancePoint;
|
|
|
|
//
|
|
result = value >= pValue + distance;
|
|
|
|
//
|
|
return result;
|
|
}
|
|
|
|
bool IsKISuperSlowUnderLast(
|
|
int barIndex = 0,
|
|
double distancePoint = 5 //
|
|
)
|
|
{
|
|
//
|
|
bool result = false;
|
|
|
|
//
|
|
// Normalize ...
|
|
barIndex = NormalizeBarIndex(barIndex);
|
|
|
|
//
|
|
// Validate ...
|
|
result = IsValid();
|
|
if (!result)
|
|
{
|
|
return result;
|
|
}
|
|
|
|
//
|
|
double value = helper.GetKISuperSlow(barIndex);
|
|
double pValue = helper.GetKISuperSlow(barIndex + 1);
|
|
double point = GetPoints(symbol);
|
|
double distance = point * distancePoint;
|
|
|
|
//
|
|
result = value <= pValue - distance;
|
|
|
|
//
|
|
return result;
|
|
}
|
|
|
|
bool IsKISuperSlowSameAsLast(int barIndex = 0)
|
|
{
|
|
//
|
|
bool result = false;
|
|
|
|
//
|
|
barIndex = NormalizeBarIndex(barIndex);
|
|
|
|
//
|
|
result = IsValid() &&
|
|
helper.GetKISuperSlow(barIndex) == helper.GetKISuperSlow(barIndex + 1);
|
|
|
|
//
|
|
return result;
|
|
}
|
|
|
|
bool IsKISuperSlowSwitchedOverLast(int barIndex = 0)
|
|
{
|
|
//
|
|
bool result = false;
|
|
|
|
//
|
|
barIndex = NormalizeBarIndex(barIndex);
|
|
|
|
//
|
|
result =
|
|
IsValid() &&
|
|
IsKISuperSlowOverLast(barIndex) &&
|
|
!IsKISuperSlowOverLast(barIndex + 1);
|
|
if (!result)
|
|
{
|
|
return result;
|
|
}
|
|
|
|
//
|
|
return result;
|
|
}
|
|
|
|
bool IsKISuperSlowSwitchedUnderLast(int barIndex = 0)
|
|
{
|
|
//
|
|
bool result = false;
|
|
|
|
//
|
|
barIndex = NormalizeBarIndex(barIndex);
|
|
|
|
//
|
|
result =
|
|
IsValid() &&
|
|
IsKISuperSlowUnderLast(barIndex) &&
|
|
!IsKISuperSlowUnderLast(barIndex + 1);
|
|
if (!result)
|
|
{
|
|
return result;
|
|
}
|
|
|
|
//
|
|
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;
|
|
}
|
|
|
|
bool IsKIWaveOverLast(int barIndex = 0)
|
|
{
|
|
//
|
|
bool result = false;
|
|
|
|
//
|
|
barIndex = NormalizeBarIndex(barIndex);
|
|
|
|
//
|
|
result = IsValid() &&
|
|
helper.GetKIWave(barIndex) > helper.GetKIWave(barIndex + 1);
|
|
|
|
//
|
|
return result;
|
|
}
|
|
|
|
bool IsKIWaveUnderLast(int barIndex = 0)
|
|
{
|
|
//
|
|
bool result = false;
|
|
|
|
//
|
|
barIndex = NormalizeBarIndex(barIndex);
|
|
|
|
//
|
|
result = IsValid() &&
|
|
helper.GetKIWave(barIndex) < helper.GetKIWave(barIndex + 1);
|
|
|
|
//
|
|
return result;
|
|
}
|
|
|
|
bool IsKIWaveSwitchedOverLast(int barIndex = 0)
|
|
{
|
|
//
|
|
bool result = false;
|
|
|
|
//
|
|
barIndex = NormalizeBarIndex(barIndex);
|
|
|
|
//
|
|
result =
|
|
IsValid() &&
|
|
IsKIWaveOverLast(barIndex) &&
|
|
!IsKIWaveOverLast(barIndex + 1);
|
|
|
|
//
|
|
return result;
|
|
}
|
|
|
|
bool IsKIWaveSwitchedUnderLast(int barIndex = 0)
|
|
{
|
|
//
|
|
bool result = false;
|
|
|
|
//
|
|
barIndex = NormalizeBarIndex(barIndex);
|
|
|
|
//
|
|
result =
|
|
IsValid() &&
|
|
IsKIWaveUnderLast(barIndex) &&
|
|
!IsKIWaveUnderLast(barIndex + 1);
|
|
|
|
//
|
|
return result;
|
|
}
|
|
// #endregion
|
|
|
|
// #region KI Band ...
|
|
bool IsPriceOverKIUpper(
|
|
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 IsPriceUnderKIUpper(
|
|
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 IsPriceOverKILower(
|
|
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 IsPriceUnderKILower(
|
|
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;
|
|
}
|
|
|
|
bool IsPriceSwitchedOverKIUpper(
|
|
int barIndex = 0,
|
|
ENUM_X_PRICE priceType = X_PRICE_CLOSE //
|
|
)
|
|
{
|
|
//
|
|
bool result = false;
|
|
|
|
//
|
|
barIndex = NormalizeBarIndex(barIndex);
|
|
|
|
//
|
|
result =
|
|
IsValid() &&
|
|
IsPriceOverKIUpper(barIndex, priceType) &&
|
|
!IsPriceOverKIUpper(barIndex + 1, priceType);
|
|
|
|
//
|
|
return result;
|
|
}
|
|
|
|
bool IsPriceSwitchedUnderKIUpper(
|
|
int barIndex = 0,
|
|
ENUM_X_PRICE priceType = X_PRICE_CLOSE //
|
|
)
|
|
{
|
|
//
|
|
bool result = false;
|
|
|
|
//
|
|
barIndex = NormalizeBarIndex(barIndex);
|
|
|
|
//
|
|
result =
|
|
IsValid() &&
|
|
IsPriceUnderKIUpper(barIndex, priceType) &&
|
|
!IsPriceUnderKIUpper(barIndex + 1, priceType);
|
|
|
|
//
|
|
return result;
|
|
}
|
|
|
|
bool IsPriceSwitchedOverKILower(
|
|
int barIndex = 0,
|
|
ENUM_X_PRICE priceType = X_PRICE_CLOSE //
|
|
)
|
|
{
|
|
//
|
|
bool result = false;
|
|
|
|
//
|
|
barIndex = NormalizeBarIndex(barIndex);
|
|
|
|
//
|
|
result =
|
|
IsValid() &&
|
|
IsPriceOverKILower(barIndex, priceType) &&
|
|
!IsPriceOverKILower(barIndex + 1, priceType);
|
|
|
|
//
|
|
return result;
|
|
}
|
|
|
|
bool IsPriceSwitchedUnderKILower(
|
|
int barIndex = 0,
|
|
ENUM_X_PRICE priceType = X_PRICE_CLOSE //
|
|
)
|
|
{
|
|
//
|
|
bool result = false;
|
|
|
|
//
|
|
barIndex = NormalizeBarIndex(barIndex);
|
|
|
|
//
|
|
result =
|
|
IsValid() &&
|
|
IsPriceUnderKILower(barIndex, priceType) &&
|
|
!IsPriceUnderKILower(barIndex + 1, priceType);
|
|
|
|
//
|
|
return result;
|
|
}
|
|
// #endregion
|
|
|
|
// #region MA Fast/Slow/SuperSlow ...
|
|
|
|
// #region MA Fast ...
|
|
bool IsMAFastBullish(
|
|
int barIndex = 0,
|
|
ENUM_X_PRICE priceType = X_PRICE_CLOSE //
|
|
)
|
|
{
|
|
//
|
|
bool result = false;
|
|
|
|
//
|
|
// Normalize ...
|
|
barIndex = NormalizeBarIndex(barIndex);
|
|
|
|
//
|
|
// Validate ...
|
|
XOHCL iBar;
|
|
result = IsValid() &&
|
|
iBar.Init(symbol, period, barIndex);
|
|
if (!result)
|
|
{
|
|
return result;
|
|
}
|
|
|
|
//
|
|
result = iBar.GetPrice(priceType) > helper.GetMAFast(barIndex);
|
|
|
|
//
|
|
iBar.Clean();
|
|
|
|
//
|
|
return result;
|
|
}
|
|
|
|
bool IsMAFastBearish(
|
|
int barIndex = 0,
|
|
ENUM_X_PRICE priceType = X_PRICE_CLOSE //
|
|
)
|
|
{
|
|
//
|
|
bool result = false;
|
|
|
|
//
|
|
// Normalize ...
|
|
barIndex = NormalizeBarIndex(barIndex);
|
|
|
|
//
|
|
// Validate ...
|
|
XOHCL iBar;
|
|
result = IsValid() &&
|
|
iBar.Init(symbol, period, barIndex);
|
|
if (!result)
|
|
{
|
|
return result;
|
|
}
|
|
|
|
//
|
|
result = iBar.GetPrice(priceType) < helper.GetMAFast(barIndex);
|
|
|
|
//
|
|
iBar.Clean();
|
|
|
|
//
|
|
return result;
|
|
}
|
|
|
|
bool IsMAFastOverLast(int barIndex = 0)
|
|
{
|
|
//
|
|
bool result = false;
|
|
|
|
//
|
|
barIndex = NormalizeBarIndex(barIndex);
|
|
|
|
//
|
|
result =
|
|
IsValid() &&
|
|
helper.GetMAFast(barIndex) > helper.GetMAFast(barIndex + 1);
|
|
|
|
//
|
|
return result;
|
|
}
|
|
|
|
bool IsMAFastUnderLast(int barIndex = 0)
|
|
{
|
|
//
|
|
bool result = false;
|
|
|
|
//
|
|
barIndex = NormalizeBarIndex(barIndex);
|
|
|
|
//
|
|
result =
|
|
IsValid() &&
|
|
helper.GetMAFast(barIndex) < helper.GetMAFast(barIndex + 1);
|
|
|
|
//
|
|
return result;
|
|
}
|
|
|
|
bool IsMAFastSwitchedOverLast(int barIndex = 0)
|
|
{
|
|
//
|
|
bool result = false;
|
|
|
|
//
|
|
barIndex = NormalizeBarIndex(barIndex);
|
|
|
|
//
|
|
result =
|
|
IsValid() &&
|
|
IsMAFastOverLast(barIndex) &&
|
|
!IsMAFastOverLast(barIndex + 1);
|
|
|
|
//
|
|
return result;
|
|
}
|
|
|
|
bool IsMAFastSwitchedUnderLast(int barIndex = 0)
|
|
{
|
|
//
|
|
bool result = false;
|
|
|
|
//
|
|
barIndex = NormalizeBarIndex(barIndex);
|
|
|
|
//
|
|
result =
|
|
IsValid() &&
|
|
IsMAFastUnderLast(barIndex) &&
|
|
!IsMAFastUnderLast(barIndex + 1);
|
|
|
|
//
|
|
return result;
|
|
}
|
|
|
|
bool IsMAFastSwitchedToBullish(
|
|
int barIndex = 0,
|
|
ENUM_X_PRICE priceType = X_PRICE_CLOSE //
|
|
)
|
|
{
|
|
//
|
|
bool result = false;
|
|
|
|
//
|
|
barIndex = NormalizeBarIndex(barIndex);
|
|
|
|
//
|
|
result = IsValid() &&
|
|
IsMAFastBullish(barIndex) &&
|
|
!IsMAFastBullish(barIndex + 1);
|
|
|
|
//
|
|
return result;
|
|
}
|
|
|
|
bool IsMAFastSwitchedToBearish(
|
|
int barIndex = 0,
|
|
ENUM_X_PRICE priceType = X_PRICE_CLOSE //
|
|
)
|
|
{
|
|
//
|
|
bool result = false;
|
|
|
|
//
|
|
barIndex = NormalizeBarIndex(barIndex);
|
|
|
|
//
|
|
result = IsValid() &&
|
|
IsMAFastBearish(barIndex) &&
|
|
!IsMAFastBearish(barIndex + 1);
|
|
|
|
//
|
|
return result;
|
|
}
|
|
// #endregion
|
|
|
|
// #region MA Slow ...
|
|
bool IsMASlowBullish(
|
|
int barIndex = 0,
|
|
ENUM_X_PRICE priceType = X_PRICE_CLOSE //
|
|
)
|
|
{
|
|
//
|
|
bool result = false;
|
|
|
|
//
|
|
// Normalize ...
|
|
barIndex = NormalizeBarIndex(barIndex);
|
|
|
|
//
|
|
// Validate ...
|
|
XOHCL iBar;
|
|
result = IsValid() &&
|
|
iBar.Init(symbol, period, barIndex);
|
|
if (!result)
|
|
{
|
|
return result;
|
|
}
|
|
|
|
//
|
|
result = iBar.GetPrice(priceType) > helper.GetMASlow(barIndex);
|
|
|
|
//
|
|
iBar.Clean();
|
|
|
|
//
|
|
return result;
|
|
}
|
|
|
|
bool IsMASlowBearish(
|
|
int barIndex = 0,
|
|
ENUM_X_PRICE priceType = X_PRICE_CLOSE //
|
|
)
|
|
{
|
|
//
|
|
bool result = false;
|
|
|
|
//
|
|
// Normalize ...
|
|
barIndex = NormalizeBarIndex(barIndex);
|
|
|
|
//
|
|
// Validate ...
|
|
XOHCL iBar;
|
|
result = IsValid() &&
|
|
iBar.Init(symbol, period, barIndex);
|
|
if (!result)
|
|
{
|
|
return result;
|
|
}
|
|
|
|
//
|
|
result = iBar.GetPrice(priceType) < helper.GetMASlow(barIndex);
|
|
|
|
//
|
|
iBar.Clean();
|
|
|
|
//
|
|
return result;
|
|
}
|
|
|
|
bool IsMASlowOverLast(int barIndex = 0)
|
|
{
|
|
//
|
|
bool result = false;
|
|
|
|
//
|
|
barIndex = NormalizeBarIndex(barIndex);
|
|
|
|
//
|
|
result =
|
|
IsValid() &&
|
|
helper.GetMASlow(barIndex) > helper.GetMASlow(barIndex + 1);
|
|
|
|
//
|
|
return result;
|
|
}
|
|
|
|
bool IsMASlowUnderLast(int barIndex = 0)
|
|
{
|
|
//
|
|
bool result = false;
|
|
|
|
//
|
|
barIndex = NormalizeBarIndex(barIndex);
|
|
|
|
//
|
|
result =
|
|
IsValid() &&
|
|
helper.GetMASlow(barIndex) < helper.GetMASlow(barIndex + 1);
|
|
|
|
//
|
|
return result;
|
|
}
|
|
|
|
bool IsMASlowSwitchedOverLast(int barIndex = 0)
|
|
{
|
|
//
|
|
bool result = false;
|
|
|
|
//
|
|
barIndex = NormalizeBarIndex(barIndex);
|
|
|
|
//
|
|
result =
|
|
IsValid() &&
|
|
IsMASlowOverLast(barIndex) &&
|
|
!IsMASlowOverLast(barIndex + 1);
|
|
|
|
//
|
|
return result;
|
|
}
|
|
|
|
bool IsMASlowSwitchedUnderLast(int barIndex = 0)
|
|
{
|
|
//
|
|
bool result = false;
|
|
|
|
//
|
|
barIndex = NormalizeBarIndex(barIndex);
|
|
|
|
//
|
|
result =
|
|
IsValid() &&
|
|
IsMASlowUnderLast(barIndex) &&
|
|
!IsMASlowUnderLast(barIndex + 1);
|
|
|
|
//
|
|
return result;
|
|
}
|
|
|
|
bool IsMASlowSwitchedToBullish(
|
|
int barIndex = 0,
|
|
ENUM_X_PRICE priceType = X_PRICE_CLOSE //
|
|
)
|
|
{
|
|
//
|
|
bool result = false;
|
|
|
|
//
|
|
barIndex = NormalizeBarIndex(barIndex);
|
|
|
|
//
|
|
result = IsValid() &&
|
|
IsMASlowBullish(barIndex) &&
|
|
!IsMASlowBullish(barIndex + 1);
|
|
|
|
//
|
|
return result;
|
|
}
|
|
|
|
bool IsMASlowSwitchedToBearish(
|
|
int barIndex = 0,
|
|
ENUM_X_PRICE priceType = X_PRICE_CLOSE //
|
|
)
|
|
{
|
|
//
|
|
bool result = false;
|
|
|
|
//
|
|
barIndex = NormalizeBarIndex(barIndex);
|
|
|
|
//
|
|
result = IsValid() &&
|
|
IsMASlowBearish(barIndex) &&
|
|
!IsMASlowBearish(barIndex + 1);
|
|
|
|
//
|
|
return result;
|
|
}
|
|
// #endregion
|
|
|
|
// #region MA Super Slow ...
|
|
bool IsMASuperSlowBullish(
|
|
int barIndex = 0,
|
|
ENUM_X_PRICE priceType = X_PRICE_CLOSE //
|
|
)
|
|
{
|
|
//
|
|
bool result = false;
|
|
|
|
//
|
|
// Normalize ...
|
|
barIndex = NormalizeBarIndex(barIndex);
|
|
|
|
//
|
|
// Validate ...
|
|
XOHCL iBar;
|
|
result = IsValid() &&
|
|
iBar.Init(symbol, period, barIndex);
|
|
if (!result)
|
|
{
|
|
return result;
|
|
}
|
|
|
|
//
|
|
result = iBar.GetPrice(priceType) > helper.GetMASuperSlow(barIndex);
|
|
|
|
//
|
|
iBar.Clean();
|
|
|
|
//
|
|
return result;
|
|
}
|
|
|
|
bool IsMASuperSlowBearish(
|
|
int barIndex = 0,
|
|
ENUM_X_PRICE priceType = X_PRICE_CLOSE //
|
|
)
|
|
{
|
|
//
|
|
bool result = false;
|
|
|
|
//
|
|
// Normalize ...
|
|
barIndex = NormalizeBarIndex(barIndex);
|
|
|
|
//
|
|
// Validate ...
|
|
XOHCL iBar;
|
|
result = IsValid() &&
|
|
iBar.Init(symbol, period, barIndex);
|
|
if (!result)
|
|
{
|
|
return result;
|
|
}
|
|
|
|
//
|
|
result = iBar.GetPrice(priceType) < helper.GetMASuperSlow(barIndex);
|
|
|
|
//
|
|
iBar.Clean();
|
|
|
|
//
|
|
return result;
|
|
}
|
|
|
|
bool IsMASuperSlowOverLast(int barIndex = 0)
|
|
{
|
|
//
|
|
bool result = false;
|
|
|
|
//
|
|
barIndex = NormalizeBarIndex(barIndex);
|
|
|
|
//
|
|
result =
|
|
IsValid() &&
|
|
helper.GetMASuperSlow(barIndex) > helper.GetMASuperSlow(barIndex + 1);
|
|
|
|
//
|
|
return result;
|
|
}
|
|
|
|
bool IsMASuperSlowUnderLast(int barIndex = 0)
|
|
{
|
|
//
|
|
bool result = false;
|
|
|
|
//
|
|
barIndex = NormalizeBarIndex(barIndex);
|
|
|
|
//
|
|
result =
|
|
IsValid() &&
|
|
helper.GetMASuperSlow(barIndex) < helper.GetMASuperSlow(barIndex + 1);
|
|
|
|
//
|
|
return result;
|
|
}
|
|
|
|
bool IsMASuperSlowSwitchedOverLast(int barIndex = 0)
|
|
{
|
|
//
|
|
bool result = false;
|
|
|
|
//
|
|
barIndex = NormalizeBarIndex(barIndex);
|
|
|
|
//
|
|
result =
|
|
IsValid() &&
|
|
IsMASuperSlowOverLast(barIndex) &&
|
|
!IsMASuperSlowOverLast(barIndex + 1);
|
|
|
|
//
|
|
return result;
|
|
}
|
|
|
|
bool IsMASuperSlowSwitchedUnderLast(int barIndex = 0)
|
|
{
|
|
//
|
|
bool result = false;
|
|
|
|
//
|
|
barIndex = NormalizeBarIndex(barIndex);
|
|
|
|
//
|
|
result =
|
|
IsValid() &&
|
|
IsMASuperSlowUnderLast(barIndex) &&
|
|
!IsMASuperSlowUnderLast(barIndex + 1);
|
|
|
|
//
|
|
return result;
|
|
}
|
|
|
|
bool IsMASuperSlowSwitchedToBullish(
|
|
int barIndex = 0,
|
|
ENUM_X_PRICE priceType = X_PRICE_CLOSE //
|
|
)
|
|
{
|
|
//
|
|
bool result = false;
|
|
|
|
//
|
|
barIndex = NormalizeBarIndex(barIndex);
|
|
|
|
//
|
|
result = IsValid() &&
|
|
IsMASuperSlowBullish(barIndex) &&
|
|
!IsMASuperSlowBullish(barIndex + 1);
|
|
|
|
//
|
|
return result;
|
|
}
|
|
|
|
bool IsMASuperSlowSwitchedToBearish(
|
|
int barIndex = 0,
|
|
ENUM_X_PRICE priceType = X_PRICE_CLOSE //
|
|
)
|
|
{
|
|
//
|
|
bool result = false;
|
|
|
|
//
|
|
barIndex = NormalizeBarIndex(barIndex);
|
|
|
|
//
|
|
result = IsValid() &&
|
|
IsMASuperSlowBearish(barIndex) &&
|
|
!IsMASuperSlowBearish(barIndex + 1);
|
|
|
|
//
|
|
return result;
|
|
}
|
|
// #endregion
|
|
|
|
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;
|
|
}
|
|
// #endregion
|
|
|
|
// #region PV ...
|
|
bool IsPeakSameAsLast(int barIndex = 0)
|
|
{
|
|
//
|
|
bool result = false;
|
|
|
|
//
|
|
barIndex = NormalizeBarIndex(barIndex);
|
|
|
|
//
|
|
result = IsValid();
|
|
if (!result)
|
|
{
|
|
return result;
|
|
}
|
|
|
|
//
|
|
result = helper.GetPeak(barIndex) == helper.GetPeak(barIndex + 1);
|
|
|
|
//
|
|
return result;
|
|
}
|
|
|
|
bool IsPeakOverLast(int barIndex = 0)
|
|
{
|
|
//
|
|
bool result = false;
|
|
|
|
//
|
|
barIndex = NormalizeBarIndex(barIndex);
|
|
|
|
//
|
|
result = IsValid();
|
|
if (!result)
|
|
{
|
|
return result;
|
|
}
|
|
|
|
//
|
|
result = helper.GetPeak(barIndex) > helper.GetPeak(barIndex + 1);
|
|
|
|
//
|
|
return result;
|
|
}
|
|
|
|
bool IsPeakUnderLast(int barIndex = 0)
|
|
{
|
|
//
|
|
bool result = false;
|
|
|
|
//
|
|
barIndex = NormalizeBarIndex(barIndex);
|
|
|
|
//
|
|
result = IsValid();
|
|
if (!result)
|
|
{
|
|
return result;
|
|
}
|
|
|
|
//
|
|
result = helper.GetPeak(barIndex) < helper.GetPeak(barIndex + 1);
|
|
|
|
//
|
|
return result;
|
|
}
|
|
|
|
int CountSamePeaks(
|
|
int barIndex = 0,
|
|
int loopback = 10 //
|
|
)
|
|
{
|
|
//
|
|
int result = 0;
|
|
|
|
//
|
|
if (!IsValid())
|
|
{
|
|
return result;
|
|
}
|
|
|
|
//
|
|
loopback = NormalizeInt(loopback, 2);
|
|
barIndex = NormalizeBarIndex(barIndex);
|
|
|
|
//
|
|
for (int i = barIndex; i < barIndex + loopback; i++)
|
|
{
|
|
//
|
|
if (IsPeakSameAsLast(i))
|
|
{
|
|
result++;
|
|
}
|
|
}
|
|
|
|
//
|
|
return result;
|
|
}
|
|
|
|
bool IsValeSameAsLast(int barIndex = 0)
|
|
{
|
|
//
|
|
bool result = false;
|
|
|
|
//
|
|
barIndex = NormalizeBarIndex(barIndex);
|
|
|
|
//
|
|
result = IsValid();
|
|
if (!result)
|
|
{
|
|
return result;
|
|
}
|
|
|
|
//
|
|
result = helper.GetVale(barIndex) == helper.GetVale(barIndex + 1);
|
|
|
|
//
|
|
return result;
|
|
}
|
|
|
|
bool IsValeOverLast(int barIndex = 0)
|
|
{
|
|
//
|
|
bool result = false;
|
|
|
|
//
|
|
barIndex = NormalizeBarIndex(barIndex);
|
|
|
|
//
|
|
result = IsValid();
|
|
if (!result)
|
|
{
|
|
return result;
|
|
}
|
|
|
|
//
|
|
result = helper.GetVale(barIndex) > helper.GetVale(barIndex + 1);
|
|
|
|
//
|
|
return result;
|
|
}
|
|
|
|
bool IsValeUnderLast(int barIndex = 0)
|
|
{
|
|
//
|
|
bool result = false;
|
|
|
|
//
|
|
barIndex = NormalizeBarIndex(barIndex);
|
|
|
|
//
|
|
result = IsValid();
|
|
if (!result)
|
|
{
|
|
return result;
|
|
}
|
|
|
|
//
|
|
result = helper.GetVale(barIndex) < helper.GetVale(barIndex + 1);
|
|
|
|
//
|
|
return result;
|
|
}
|
|
|
|
int CountSameVales(
|
|
int barIndex = 0,
|
|
int loopback = 10 //
|
|
)
|
|
{
|
|
//
|
|
int result = 0;
|
|
|
|
//
|
|
if (!IsValid())
|
|
{
|
|
return result;
|
|
}
|
|
|
|
//
|
|
loopback = NormalizeInt(loopback, 2);
|
|
barIndex = NormalizeBarIndex(barIndex);
|
|
|
|
//
|
|
for (int i = barIndex; i < barIndex + loopback; i++)
|
|
{
|
|
//
|
|
if (IsValeSameAsLast(i))
|
|
{
|
|
result++;
|
|
}
|
|
}
|
|
|
|
//
|
|
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 IsATROverLast(int barIndex = 0)
|
|
{
|
|
//
|
|
bool result = false;
|
|
|
|
//
|
|
barIndex = NormalizeBarIndex(barIndex);
|
|
|
|
//
|
|
result =
|
|
IsValid() &&
|
|
helper.GetATR(barIndex) > helper.GetATR(barIndex + 1);
|
|
|
|
//
|
|
return result;
|
|
}
|
|
|
|
bool IsATRUnderLast(int barIndex = 0)
|
|
{
|
|
//
|
|
bool result = false;
|
|
|
|
//
|
|
barIndex = NormalizeBarIndex(barIndex);
|
|
|
|
//
|
|
result =
|
|
IsValid() &&
|
|
helper.GetATR(barIndex) < helper.GetATR(barIndex + 1);
|
|
|
|
//
|
|
return result;
|
|
}
|
|
|
|
bool IsATRSwitchedOverLast(int barIndex = 0)
|
|
{
|
|
//
|
|
bool result = false;
|
|
|
|
//
|
|
barIndex = NormalizeBarIndex(barIndex);
|
|
|
|
//
|
|
result =
|
|
IsValid() &&
|
|
IsATROverLast(barIndex) &&
|
|
!IsATROverLast(barIndex + 1);
|
|
|
|
//
|
|
return result;
|
|
}
|
|
|
|
bool IsATRSwitchedUnderLast(int barIndex = 0)
|
|
{
|
|
//
|
|
bool result = false;
|
|
|
|
//
|
|
barIndex = NormalizeBarIndex(barIndex);
|
|
|
|
//
|
|
result =
|
|
IsValid() &&
|
|
IsATRUnderLast(barIndex) &&
|
|
!IsATRUnderLast(barIndex + 1);
|
|
|
|
//
|
|
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;
|
|
}
|
|
|
|
bool IsVolatilitySwitchdToHigh(int barIndex = 0)
|
|
{
|
|
//
|
|
bool result = false;
|
|
|
|
//
|
|
// Normalize ...
|
|
barIndex = NormalizeBarIndex(barIndex);
|
|
|
|
//
|
|
// Validate ...
|
|
result = IsValid();
|
|
if (!result)
|
|
{
|
|
return result;
|
|
}
|
|
|
|
//
|
|
double atr = helper.GetATR(barIndex);
|
|
double atrPrev = helper.GetATR(barIndex + 1);
|
|
double atrMa = helper.GetATRSmoothed(barIndex);
|
|
double atrMaPrev = helper.GetATRSmoothed(barIndex + 1);
|
|
|
|
//
|
|
result =
|
|
atr > atrMa &&
|
|
atrPrev <= atrMaPrev;
|
|
|
|
//
|
|
return result;
|
|
}
|
|
|
|
bool IsVolatilitySwitchdToLow(int barIndex = 0)
|
|
{
|
|
//
|
|
bool result = false;
|
|
|
|
//
|
|
// Normalize ...
|
|
barIndex = NormalizeBarIndex(barIndex);
|
|
|
|
//
|
|
// Validate ...
|
|
result = IsValid();
|
|
if (!result)
|
|
{
|
|
return result;
|
|
}
|
|
|
|
//
|
|
double atr = helper.GetATR(barIndex);
|
|
double atrPrev = helper.GetATR(barIndex + 1);
|
|
double atrMa = helper.GetATRSmoothed(barIndex);
|
|
double atrMaPrev = helper.GetATRSmoothed(barIndex + 1);
|
|
|
|
//
|
|
result =
|
|
atr < atrMa &&
|
|
atrPrev >= atrMaPrev;
|
|
|
|
//
|
|
return result;
|
|
}
|
|
// #endregion
|
|
|
|
// #region RSI ...
|
|
bool IsRSIBullish(
|
|
int barIndex = 0,
|
|
double threshold = 50 //
|
|
)
|
|
{
|
|
//
|
|
bool result = false;
|
|
|
|
//
|
|
// Normalize ...
|
|
barIndex = NormalizeBarIndex(barIndex);
|
|
|
|
//
|
|
// Validate ...
|
|
result = IsValid();
|
|
if (!result)
|
|
{
|
|
return result;
|
|
}
|
|
|
|
//
|
|
result = helper.GetRSI(barIndex) > threshold;
|
|
return result;
|
|
}
|
|
|
|
bool IsRSIBearish(
|
|
int barIndex = 0,
|
|
double threshold = 50 //
|
|
)
|
|
{
|
|
//
|
|
bool result = false;
|
|
|
|
//
|
|
// Normalize ...
|
|
barIndex = NormalizeBarIndex(barIndex);
|
|
|
|
//
|
|
// Validate ...
|
|
result = IsValid();
|
|
if (!result)
|
|
{
|
|
return result;
|
|
}
|
|
|
|
//
|
|
result = helper.GetRSI(barIndex) < threshold;
|
|
return result;
|
|
}
|
|
|
|
bool IsRSIOverbought(
|
|
int barIndex = 0,
|
|
double threshold = 70 //
|
|
)
|
|
{
|
|
//
|
|
bool result = false;
|
|
|
|
//
|
|
// Normalize ...
|
|
barIndex = NormalizeBarIndex(barIndex);
|
|
|
|
//
|
|
// Validate ...
|
|
result = IsValid();
|
|
if (!result)
|
|
{
|
|
return result;
|
|
}
|
|
|
|
//
|
|
result = helper.GetRSI(barIndex) > threshold;
|
|
return result;
|
|
}
|
|
|
|
bool IsRSIOversold(
|
|
int barIndex = 0,
|
|
double threshold = 30 //
|
|
)
|
|
{
|
|
//
|
|
bool result = false;
|
|
|
|
//
|
|
// Normalize ...
|
|
barIndex = NormalizeBarIndex(barIndex);
|
|
|
|
//
|
|
// Validate ...
|
|
result = IsValid();
|
|
if (!result)
|
|
{
|
|
return result;
|
|
}
|
|
|
|
//
|
|
result = helper.GetRSI(barIndex) < threshold;
|
|
return result;
|
|
}
|
|
|
|
bool IsRSISwitchedToOverSold(
|
|
int barIndex = 0,
|
|
double threshold = 30 //
|
|
)
|
|
{
|
|
//
|
|
bool result = false;
|
|
|
|
//
|
|
barIndex = NormalizeBarIndex(barIndex);
|
|
|
|
//
|
|
result =
|
|
IsValid() &&
|
|
IsRSIOversold(barIndex, threshold) &&
|
|
!IsRSIOversold(barIndex + 1, threshold);
|
|
|
|
//
|
|
return result;
|
|
}
|
|
|
|
bool IsRSISwitchedFromOverSold(
|
|
int barIndex = 0,
|
|
double threshold = 30 //
|
|
)
|
|
{
|
|
//
|
|
bool result = false;
|
|
|
|
//
|
|
barIndex = NormalizeBarIndex(barIndex);
|
|
|
|
//
|
|
result =
|
|
IsValid() &&
|
|
!IsRSIOversold(barIndex, threshold) &&
|
|
IsRSIOversold(barIndex + 1, threshold);
|
|
|
|
//
|
|
return result;
|
|
}
|
|
|
|
bool IsRSISwitchedToOverbought(
|
|
int barIndex = 0,
|
|
double threshold = 70 //
|
|
)
|
|
{
|
|
//
|
|
bool result = false;
|
|
|
|
//
|
|
barIndex = NormalizeBarIndex(barIndex);
|
|
|
|
//
|
|
result =
|
|
IsValid() &&
|
|
IsRSIOverbought(barIndex, threshold) &&
|
|
!IsRSIOverbought(barIndex + 1, threshold);
|
|
|
|
//
|
|
return result;
|
|
}
|
|
|
|
bool IsRSISwitchedFromOverbought(
|
|
int barIndex = 0,
|
|
double threshold = 70 //
|
|
)
|
|
{
|
|
//
|
|
bool result = false;
|
|
|
|
//
|
|
barIndex = NormalizeBarIndex(barIndex);
|
|
|
|
//
|
|
result =
|
|
IsValid() &&
|
|
!IsRSIOverbought(barIndex, threshold) &&
|
|
IsRSIOverbought(barIndex + 1, threshold);
|
|
|
|
//
|
|
return result;
|
|
}
|
|
|
|
bool IsRSISwitchedToBullish(
|
|
int barIndex = 0,
|
|
double threshold = 50 //
|
|
)
|
|
{
|
|
//
|
|
bool result = false;
|
|
|
|
//
|
|
// Normalize ...
|
|
barIndex = NormalizeBarIndex(barIndex);
|
|
|
|
//
|
|
// Validate ...
|
|
result = IsValid();
|
|
if (!result)
|
|
{
|
|
return result;
|
|
}
|
|
|
|
//
|
|
result =
|
|
IsRSIBullish(barIndex, threshold) &&
|
|
!IsRSIBullish(barIndex + 1, threshold);
|
|
|
|
//
|
|
return result;
|
|
}
|
|
|
|
bool IsRSISwitchedToBearish(
|
|
int barIndex = 0,
|
|
double threshold = 50 //
|
|
)
|
|
{
|
|
//
|
|
bool result = false;
|
|
|
|
//
|
|
// Normalize ...
|
|
barIndex = NormalizeBarIndex(barIndex);
|
|
|
|
//
|
|
// Validate ...
|
|
result = IsValid();
|
|
if (!result)
|
|
{
|
|
return result;
|
|
}
|
|
|
|
//
|
|
result =
|
|
IsRSIBearish(barIndex, threshold) &&
|
|
!IsRSIBearish(barIndex + 1, threshold);
|
|
|
|
//
|
|
return result;
|
|
}
|
|
// #endregion
|
|
|
|
// #region Composite ...
|
|
// #endregion
|
|
|
|
//
|
|
// Protected ...
|
|
protected:
|
|
//
|
|
|
|
//
|
|
// Private ...
|
|
private:
|
|
//
|
|
XCX121XKIHelper *helper;
|
|
|
|
//
|
|
};
|
|
|
|
//
|