This commit is contained in:
2025-10-05 03:42:17 +03:30
parent 30ca89c367
commit 8298759c8d
2 changed files with 263 additions and 190 deletions
+42 -104
View File
@@ -232,60 +232,6 @@ class XCMarketPatternDetector : public XCBase
//
// Detectors ...
bool IsPeak(
XOHCL &bar,
int validationLength = 7 //
) {
//
bool result = false;
//
// Normalize ...
validationLength = NormalizeInt(validationLength, 2);
//
// Validate ...
result = bar.IsValid();
if (!result)
{
return result;
}
//
// Define Requirements ...
result = bar.FindHighest(validationLength, MODE_HIGH) <= bar.high;
//
return result;
}
bool IsVale(
XOHCL &bar,
int validationLength = 7 //
) {
//
bool result = false;
//
// Normalize ...
validationLength = NormalizeInt(validationLength, 2);
//
// Validate ...
result = bar.IsValid();
if (!result)
{
return result;
}
//
// Define Requirements ...
result = bar.FindLowest(validationLength, MODE_LOW) >= bar.low;
//
return result;
}
/**
* Check Specified Bar is Peak or Vale ...
*
@@ -298,7 +244,9 @@ class XCMarketPatternDetector : public XCBase
bool IsPV(
XOHCL &bar,
ENUM_X_DIRECTION &dir,
int validationLength = 7 //
int validationLength = 7,
ENUM_X_PRICE peakPriceType = X_PRICE_HIGH, //
ENUM_X_PRICE valePriceType = X_PRICE_LOW //
)
{
//
@@ -314,64 +262,55 @@ class XCMarketPatternDetector : public XCBase
//
// Validate ...
result = bar.IsValid();
result = bar.IsValid() &&
IsXValid(peakPriceType) &&
IsXValid(valePriceType);
if (!result)
{
return result;
}
//
// Define Requirements ...
XOHCL iBar;
bool isPeak = true;
bool isVale = true;
int start = bar.Index();
int end = start + validationLength;
for (int i = start; i < end; i++)
{
//
iBar.Clean();
result = bar.BarAt(i, iBar);
if (!result)
{
//
isVale = false;
isPeak = false;
//
break;
}
//
isPeak =
isPeak &&
iBar.high <= bar.high;
//
isVale =
isVale &&
iBar.low >= bar.low;
//
if (!isPeak && !isVale)
{
break;
}
}
int valeIndex = -1;
double vale = bar.FindLowest(
valeIndex,
validationLength,
valePriceType //
);
double barVale = bar.GetPrice(valePriceType);
bool isVale =
NotEmptyZero(vale) &&
NotEmptyZero(barVale) &&
IsValidIndex(valeIndex) &&
vale >= barVale;
//
result =
(isPeak && !isVale) ||
(isVale && !isPeak);
if (!result)
{
return result;
}
int peakIndex = -1;
double peak = bar.FindHighest(
peakIndex,
validationLength,
peakPriceType //
);
double barPeak = bar.GetPrice(peakPriceType);
bool isPeak =
NotEmptyZero(peak) &&
NotEmptyZero(barPeak) &&
IsValidIndex(peakIndex) &&
peak <= barPeak;
//
dir = isVale
? X_DIRECTION_BULLISH
: X_DIRECTION_BEARISH;
result = (isVale && !isPeak) ||
(isPeak && !isVale);
if (result)
{
//
dir =
isVale
? X_DIRECTION_BULLISH
: isPeak
? X_DIRECTION_BEARISH
: X_DIRECTION_NONE;
}
//
// Get Result ...
@@ -379,7 +318,6 @@ class XCMarketPatternDetector : public XCBase
//
// Cleanup Resources ...
iBar.Clean();
//
return result;