last works on pattern detector ...

This commit is contained in:
2025-09-17 08:58:58 +03:30
parent 21fe832447
commit c1da10ba3a
4 changed files with 795 additions and 245 deletions
@@ -1268,6 +1268,194 @@ class XCMarketPatternDetector : public XCBase
return result;
}
bool HasSupport(
XOHCL &bar,
XOHCL &support,
int validationLength = 21,
int maxAllowedLoopback = 1500 //
)
{
//
bool result = false;
//
// Prepare ...
support.Clean();
//
// Normalizing ...
validationLength = NormalizeInt(validationLength, 7);
maxAllowedLoopback = NormalizeInt(maxAllowedLoopback, 21, 1500);
//
// Validate ...
result = bar.IsValid();
if (!result)
{
return result;
}
//
// Find Support Swing ...
int idx = -1;
bool has = false;
int lookupIDX = bar.Index();
while (!IsValidIndex(idx) &&
lookupIDX < maxAllowedLoopback)
{
//
// Detect Swing ...
idx = FindXSwing(
X_SWING_LOW,
bar.symbol,
bar.period,
lookupIDX,
validationLength //
);
has = IsValidIndex(idx);
if (!has)
{
//
lookupIDX++;
continue;
}
//
// Retrieve Swing Bar ...
has = support.Init(
bar.symbol,
bar.period,
idx //
);
if (!has)
{
//
idx = -1;
lookupIDX++;
support.Clean();
continue;
}
//
// Check Suppor Low Shadow ...
has = support.GetDown() < bar.low;
if (!has)
{
//
idx = -1;
lookupIDX++;
support.Clean();
continue;
}
//
if (IsValidIndex(idx))
{
break;
}
}
//
result = support.IsValid();
//
return result;
}
bool HasResistance(
XOHCL &bar,
XOHCL &resistence,
int validationLength = 21,
int maxAllowedLoopback = 1500 //
)
{
//
bool result = false;
//
// Prepare ...
resistence.Clean();
//
// Normalizing ...
validationLength = NormalizeInt(validationLength, 7);
maxAllowedLoopback = NormalizeInt(maxAllowedLoopback, 21, 1500);
//
// Validate ...
result = bar.IsValid();
if (!result)
{
return result;
}
//
// Find Support Swing ...
int idx = -1;
bool has = false;
int lookupIDX = bar.Index();
while (!IsValidIndex(idx) &&
lookupIDX < maxAllowedLoopback)
{
//
// Detect Swing ...
idx = FindXSwing(
X_SWING_HIGH,
bar.symbol,
bar.period,
lookupIDX,
validationLength //
);
has = IsValidIndex(idx);
if (!has)
{
//
lookupIDX++;
continue;
}
//
// Retrieve Swing Bar ...
has = resistence.Init(
bar.symbol,
bar.period,
idx //
);
if (!has)
{
//
idx = -1;
lookupIDX++;
resistence.Clean();
continue;
}
//
// Check Resistance High Shadow ...
has = resistence.GetUp() > bar.high;
if (!has)
{
//
idx = -1;
lookupIDX++;
resistence.Clean();
continue;
}
//
if (IsValidIndex(idx))
{
break;
}
}
//
result = resistence.IsValid();
//
return result;
}
//
// Protected ...
protected:
+90 -1
View File
@@ -889,6 +889,95 @@ class XCPOIDrawer : public XCBase
return result;
}
/**
* Draw Trend Line based on Swings Points ...
*
* @param swings: XOHCL, Specified Swings ...
* @param dir: ENUM_X_DIRECTION, Specified Trend Direction ...
* @param rayRight: Ray to Right ...
* @param rayLeft: Ray to Left ...
*
* @return ( bool )
*/
bool DrawSwingTrend(
XOHCL &swings[],
ENUM_X_DIRECTION dir,
CChartObjectTrend *&object,
bool rayRight = false,
bool rayLeft = false //
)
{
//
bool result = false;
//
int count = ArraySize(swings);
result = HasChild(swings) &&
count >= 2 &&
HasDirection(dir);
if (!result)
{
return result;
}
//
bool isBullish = IsSpecifiedBullish(dir);
//
double price1 =
isBullish
? swings[0].low
: swings[0].high;
datetime time1 = swings[0].time;
//
double price2 =
isBullish
? swings[count - 1].low
: swings[count - 1].high;
datetime time2 = swings[count - 1].time;
//
ulong chartId = ChartIdentification();
int subWindow = SubWindowIdentification();
string name = ToXString(dir) + "_Trend_" + ToXString(price1) + "_" + ToXString(price2);
//
object = new CChartObjectTrend();
result = object.Create(
chartId,
name,
subWindow,
time1,
price1,
time2,
price2 //
);
if (result)
{
//
ApplyStyle(
object,
dir //
);
//
if (rayRight)
{
object.RayRight(true);
}
//
if (rayLeft)
{
object.RayLeft(true);
}
}
//
return result;
}
/**
* Apply Specified Style to Object ...
*/
@@ -932,7 +1021,7 @@ class XCPOIDrawer : public XCBase
/**
* Apply Style to Specified Chart Object ...
*
*
* @param dir: Argument 2
*/
void ApplyStyle(