last works and apply fix on ZigZag Reading ...

This commit is contained in:
2025-09-20 13:55:34 +03:30
parent 6788675c4a
commit becac9983d
5 changed files with 851 additions and 41 deletions
@@ -36,8 +36,8 @@ class XCXFIMAPOIDetector : public XCBase
public:
//
// Props ...
XCBarAnalyser *barAnalyser; // Bar Analyser ...
XCMarketPatternDetector *patternDetector; // Bar Analyser ...
XCBarAnalyser *barAnalyser; // Bar Analyser ...
XCMarketPatternDetector *patternDetector; // Pattern Detector ...
//
// Constructor ...
@@ -56,7 +56,198 @@ class XCXFIMAPOIDetector : public XCBase
}
//
// Implementing Parren Detector ...
// Actions and Tools ...
/**
* Get Specified Number of Recent ZigZag Points ...
*
* @param bar: XOHCL, Specified Bar for Start ...
* @param fimaHelper: XCXFIMAHelper, instance of XFIMA Helper ...
* @param zigzagPoints: XZigZagPoint, Array of Founded Points ...
* @param numberOfRequiredPoints: int, Specified Number of required ZigZag Points ...
*
* @return ( int )
*/
int GetZigZagPoint(
XOHCL &bar,
XCXFIMAHelper *&fimaHelper,
XZigZagPoint &zigzagPoints[],
int numberOfRequiredPoints = 5 //
)
{
//
int result = 0;
//
// Normalize ...
SpecifiedClean(zigzagPoints);
numberOfRequiredPoints = NormalizeInt(numberOfRequiredPoints, 3);
//
// Validate ...
result = bar.IsValid() &&
bar.symbol == fimaHelper.GetSymbol() &&
bar.period == fimaHelper.GetPeriod();
if (!result)
{
return result;
}
//
// Update Fima Helper ...
int index = bar.Index();
fimaHelper.Update(index);
//
// Start Reading ZigZag Values ...
double iZG = 0;
double iPZG = 0;
int iZGIdx = -1;
int iPZGIdx = -1;
bool has = false;
int start = index;
XZigZagPoint iZGPoint;
datetime iZGTime = NULL;
datetime iPZGTime = NULL;
int lastZGDetected = start;
ENUM_X_DIRECTION iDir = X_DIRECTION_NONE;
ENUM_X_ZIGZAG_POINT_TYPE iType = X_ZIGZAG_POINT_TYPE_NONE;
while (ArraySize(zigzagPoints) < numberOfRequiredPoints)
{
//
// Reading Last two ZigZag Value ...
//
// Detect Last ZG Value ...
has = GetZigZagValue(lastZGDetected, iZG, iZGIdx, iZGTime, fimaHelper);
if (!has)
{
//
iZG = 0;
iPZG = 0;
iZGIdx = -1;
iPZGIdx = -1;
iZGTime = NULL;
iPZGTime = NULL;
iZGPoint.Clean();
iDir = X_DIRECTION_NONE;
iType = X_ZIGZAG_POINT_TYPE_NONE;
//
start++;
lastZGDetected++;
//
continue;
}
//
// Detect Previous ZG Value ...
has = GetZigZagValue(lastZGDetected + 1, iPZG, iPZGIdx, iPZGTime, fimaHelper);
if (!has)
{
//
iZG = 0;
iPZG = 0;
iZGIdx = -1;
iPZGIdx = -1;
iZGTime = NULL;
iPZGTime = NULL;
iZGPoint.Clean();
iDir = X_DIRECTION_NONE;
iType = X_ZIGZAG_POINT_TYPE_NONE;
//
start++;
lastZGDetected++;
//
continue;
}
//
// Check Direction ...
iDir =
(iZG > iPZG)
? X_DIRECTION_BULLISH
: (iZG < iPZG)
? X_DIRECTION_BEARISH
: X_DIRECTION_NONE;
//
// Check Point Type ...
iType =
IsSpecifiedBullish(iDir)
? X_ZIGZAG_POINT_TYPE_PEAK
: IsSpecifiedBearish(iDir)
? X_ZIGZAG_POINT_TYPE_VALE
: X_ZIGZAG_POINT_TYPE_NONE;
has =
IsXValid(iType) &&
HasDirection(iDir);
if (!has)
{
//
iZG = 0;
iPZG = 0;
iZGIdx = -1;
iPZGIdx = -1;
iZGTime = NULL;
iPZGTime = NULL;
iZGPoint.Clean();
iDir = X_DIRECTION_NONE;
iType = X_ZIGZAG_POINT_TYPE_NONE;
//
start++;
lastZGDetected++;
//
continue;
}
//
// Initialize ZigZag Point ...
has = iZGPoint.Init(
iZG,
iZGTime,
bar.symbol,
iDir,
bar.period,
iType //
);
if (has)
{
//
iZGPoint.AddIfNotExists(zigzagPoints);
lastZGDetected = iZGIdx + 1;
}
//
// Reset Resources ...
iZG = 0;
iPZG = 0;
iZGIdx = -1;
iPZGIdx = -1;
iZGTime = NULL;
iPZGTime = NULL;
iZGPoint.Clean();
iDir = X_DIRECTION_NONE;
iType = X_ZIGZAG_POINT_TYPE_NONE;
//
start++;
}
//
result = ArraySize(zigzagPoints);
//
return result;
}
//
// Implementing Patrren Detector ...
/**
* Check Specified Bar is Momentum Bar or not ...
@@ -430,6 +621,106 @@ class XCXFIMAPOIDetector : public XCBase
// Protected ...
protected:
//
// Props ...
//
// Tools / Actions ...
/**
* Read Specified Value of ZigZag ...
*
* @param fromBarIndex: int, Specified Start Bar Index ...
* @param value: double, reference to Hold ZigZag Value ...
* @param index: int, reference to Hold ZigZag Value's Bar Index ...
* @param time: datetime, reference to Hold ZigZag Value's Time ...
* @param maxAllowedLoopback: int, Maximum Allowe Loopback to Detect Specified Point ...
*
* @return ( bool )
*/
bool GetZigZagValue(
int fromBarIndex,
double &value,
int &index,
datetime &time,
XCXFIMAHelper *&fimaHelper,
int maxAllowedLoopback = 100 //
)
{
//
bool result = false;
//
// Normalize ...
fromBarIndex = NormalizeInt(fromBarIndex, 0);
maxAllowedLoopback = NormalizeInt(maxAllowedLoopback, 10, 100);
//
// Prepare ...
value = 0;
index = -1;
time = NULL;
//
// Validate ...
result = fimaHelper != NULL;
if (!result)
{
return result;
}
//
int start = fromBarIndex;
int end = start + maxAllowedLoopback;
while (start < end)
{
//
fimaHelper.Update(start);
//
value = fimaHelper.GetZigZag(start);
result = value > 0 && value != EMPTY_VALUE;
if (result)
{
//
time = GetBarTime(
fimaHelper.GetSymbol(),
fimaHelper.GetPeriod(),
start //
);
//
index = start;
//
break;
}
//
value = 0;
index = -1;
time = NULL;
//
start++;
}
//
result =
value > 0 &&
IsValidIndex(index) &&
value != EMPTY_VALUE &&
IsSpecifiedValid(time);
if (!result)
{
//
value = 0;
index = -1;
time = NULL;
}
//
return result;
}
//
// Private ...
+176 -2
View File
@@ -82,7 +82,9 @@ struct XZigZagPoint
// Props ...
double value; // Value
datetime time; // Time
string symbol; // Symbol
ENUM_X_DIRECTION dir; // Direction
ENUM_TIMEFRAMES period; // Period
ENUM_X_ZIGZAG_POINT_TYPE type; // Type
//
@@ -92,6 +94,52 @@ struct XZigZagPoint
Clean();
}
//
// Init ...
/**
* Initialize Structure ...
*
* @param _value: double, value of point ...
* @param _time: datetime, time of point ...
* @param _symbol: string, Symbol ...
* @param _dir: ENUM_X_DIRECTION, direction of point ...
* @param _period: ENUM_TIMEFRAMES, period ...
* @param _type: ENUM_X_ZIGZAG_POINT_TYPE, point type ...
*
* @return ( bool )
*/
bool Init(
double _value,
datetime _time,
string _symbol,
ENUM_X_DIRECTION _dir,
ENUM_TIMEFRAMES _period,
ENUM_X_ZIGZAG_POINT_TYPE _type //
)
{
//
bool result = false;
//
dir = _dir;
time = _time;
type = _type;
value = _value;
symbol = _symbol;
period = _period;
//
result = IsValid();
if (!result)
{
Clean();
}
//
return result;
}
//
// Tools ...
@@ -103,6 +151,8 @@ struct XZigZagPoint
//
value = 0;
time = NULL;
symbol = NULL;
period = NULL;
dir = X_DIRECTION_NONE;
type = X_ZIGZAG_POINT_TYPE_NONE;
@@ -125,7 +175,9 @@ struct XZigZagPoint
value > 0 &&
IsXValid(type) &&
HasDirection(dir) &&
IsSpecifiedValid(time);
IsSpecifiedValid(time) &&
IsSpecifiedValid(symbol) &&
IsSpecifiedValid(period);
//
return result;
@@ -167,6 +219,128 @@ struct XZigZagPoint
return result;
}
/**
* Check two Struct are Same or not ...
*
* @param item: XZigZagPoint ...
*
* @return ( bool )
*/
bool IsSameAs(XZigZagPoint &item)
{
//
bool result = false;
//
result =
IsValid() &&
item.IsValid() &&
dir == item.dir &&
type == item.type &&
time == item.time &&
value == item.value &&
symbol == item.symbol &&
period == item.period;
//
return result;
}
/**
* Check Structure Exists in Specified Collection or not ...
*
* @param items: XZigZagPoint, reference Array ...
* @param index: int, reference to Holds Founded Index ...
*
* @return ( bool )
*/
bool IsExists(
XZigZagPoint &items[],
int &index //
)
{
//
bool result = false;
//
// Prepare ...
index = -1;
//
// Validate ...
result =
IsValid() &&
HasChild(items);
if (!result)
{
return result;
}
//
int count = ArraySize(items);
for (int i = 0; i < count; i++)
{
//
result = IsSameAs(items[i]);
if (result)
{
//
index = i;
//
break;
}
}
//
result =
result &&
IsValidIndex(index);
//
return result;
}
/**
* Add Structure to Specified Collection only if not Exists ...
*
* @param items: XZigZagPoint, reference Array ...
*/
void AddIfNotExists(XZigZagPoint &items[])
{
//
// Validate ...
if (!IsValid())
{
return;
}
//
if (!HasChild(items))
{
//
AddRef(
this,
items //
);
//
return;
}
//
int index = -1;
bool isExists = IsExists(items, index);
if (!isExists)
{
//
AddRef(
this,
items //
);
}
}
/**
* Extract Specified Token of Struct ...
*
@@ -179,7 +353,7 @@ struct XZigZagPoint
/**
* Represent an String Unique Identifier for Chart Objects ...
*
*
* @return ( string )
*/
string GetObjectID()