last ...
This commit is contained in:
@@ -1221,6 +1221,229 @@ class XCXFIMAHelper : public XCBaseHelper
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Check Specified Bar has HK Bond Based Trend or not ...
|
||||
*
|
||||
* @param dir: ENUM_X_DIRECTION, reference to holds trend direction, if exists ...
|
||||
* @param barIndex: int, Specified Bar Index ...
|
||||
* @param validationLength: int, validation of trend ...
|
||||
*
|
||||
* @return ( bool )
|
||||
*/
|
||||
bool HasHKBasedTrend(
|
||||
ENUM_X_DIRECTION &dir,
|
||||
int barIndex = 0,
|
||||
int validationLength = 5 //
|
||||
)
|
||||
{
|
||||
//
|
||||
bool result = false;
|
||||
|
||||
//
|
||||
// Prepare ...
|
||||
dir = X_DIRECTION_NONE;
|
||||
|
||||
//
|
||||
// Normalize ...
|
||||
barIndex = NormalizeBarIndex(barIndex);
|
||||
validationLength = NormalizeInt(validationLength, 1);
|
||||
|
||||
//
|
||||
// Validate ...
|
||||
result = IsValid();
|
||||
if (!result)
|
||||
{
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Do ...
|
||||
|
||||
//
|
||||
// Define Requirements ...
|
||||
XOHCL iBar;
|
||||
double hkUpper;
|
||||
double hkLower;
|
||||
bool has = false;
|
||||
int bullishCount = 0;
|
||||
int bearishCount = 0;
|
||||
bool isBullish = false;
|
||||
bool isBearish = false;
|
||||
|
||||
//
|
||||
// Count Bullish/Bearish Directions ...
|
||||
int start = barIndex + 1;
|
||||
int end = start + validationLength;
|
||||
for (int i = start; i < end; i++)
|
||||
{
|
||||
//
|
||||
// Reading Requirements ...
|
||||
|
||||
//
|
||||
// Read Indexed Bar ...
|
||||
iBar.Clean();
|
||||
result = iBar.Init(
|
||||
mSymbol,
|
||||
mPeriod,
|
||||
i //
|
||||
);
|
||||
if (!result)
|
||||
{
|
||||
break;
|
||||
}
|
||||
|
||||
//
|
||||
// Reading Values ...
|
||||
hkUpper = GetHKBondUpper(i);
|
||||
hkLower = GetHKBondLower(i);
|
||||
result = NotEmptyZero(hkUpper) &&
|
||||
NotEmptyZero(hkLower);
|
||||
if (!result)
|
||||
{
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Check Trend ...
|
||||
|
||||
//
|
||||
// Bullish ...
|
||||
isBullish = iBar.low > hkLower;
|
||||
if (isBullish)
|
||||
{
|
||||
bullishCount++;
|
||||
}
|
||||
|
||||
//
|
||||
// Bearish ...
|
||||
isBearish = iBar.high < hkUpper;
|
||||
if (isBearish)
|
||||
{
|
||||
bearishCount++;
|
||||
}
|
||||
|
||||
//
|
||||
iBar.Clean();
|
||||
|
||||
//
|
||||
}
|
||||
|
||||
//
|
||||
// Validate Results ...
|
||||
isBullish =
|
||||
bullishCount >= validationLength;
|
||||
isBearish =
|
||||
bearishCount >= validationLength;
|
||||
|
||||
//
|
||||
result = (isBullish && !isBearish) ||
|
||||
(isBearish && !isBullish);
|
||||
|
||||
//
|
||||
// Setting Direction if Has Trend ...
|
||||
if (result)
|
||||
{
|
||||
//
|
||||
dir = isBullish
|
||||
? X_DIRECTION_BULLISH
|
||||
: X_DIRECTION_BEARISH;
|
||||
}
|
||||
|
||||
//
|
||||
// Cleanup ...
|
||||
iBar.Clean();
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Check Specified Bar has HK Bond Based Trend Switch or not ...
|
||||
*
|
||||
* @param dir: ENUM_X_DIRECTION, reference to holds trend direction, if exists ...
|
||||
* @param barIndex: int, Specified Bar Index ...
|
||||
* @param validationLength: int, validation of trend ...
|
||||
*
|
||||
* @return ( bool )
|
||||
*/
|
||||
bool IsHKBasedTrendSwitch(
|
||||
ENUM_X_DIRECTION &dir,
|
||||
int barIndex = 0,
|
||||
int validationLength = 5 //
|
||||
)
|
||||
{
|
||||
//
|
||||
bool result = false;
|
||||
|
||||
//
|
||||
// Prepare ...
|
||||
dir = X_DIRECTION_NONE;
|
||||
|
||||
//
|
||||
// Normalize ...
|
||||
barIndex = NormalizeBarIndex(barIndex);
|
||||
validationLength = NormalizeInt(validationLength, 1);
|
||||
|
||||
//
|
||||
// Validate ...
|
||||
result = IsValid();
|
||||
if (!result)
|
||||
{
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Do ...
|
||||
|
||||
//
|
||||
bool hasTrend = HasHKBasedTrend(
|
||||
dir,
|
||||
barIndex,
|
||||
validationLength //
|
||||
);
|
||||
bool isBullish = hasTrend &&
|
||||
IsXBullish(dir);
|
||||
bool isBearish = hasTrend &&
|
||||
IsXBearish(dir);
|
||||
|
||||
//
|
||||
bool hasPTrend = HasHKBasedTrend(
|
||||
dir,
|
||||
barIndex + 1,
|
||||
validationLength //
|
||||
);
|
||||
bool isPBullish = hasPTrend &&
|
||||
IsXBullish(dir);
|
||||
bool isPBearish = hasPTrend &&
|
||||
IsXBearish(dir);
|
||||
|
||||
//
|
||||
dir = X_DIRECTION_NONE;
|
||||
|
||||
//
|
||||
// Checking Result ...
|
||||
isBullish = isBullish && !isPBullish;
|
||||
isBearish = isBearish && !isPBearish;
|
||||
|
||||
//
|
||||
result =
|
||||
(isBullish && !isBearish) ||
|
||||
(isBearish && !isBullish);
|
||||
if (result)
|
||||
{
|
||||
//
|
||||
dir = isBullish
|
||||
? X_DIRECTION_BULLISH
|
||||
: X_DIRECTION_BEARISH;
|
||||
}
|
||||
|
||||
//
|
||||
// Cleanup ...
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Check Specified Bar has SAR Switch or not ...
|
||||
*
|
||||
|
||||
Reference in New Issue
Block a user