last ...
This commit is contained in:
@@ -341,6 +341,9 @@ struct XZigZagPoint
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
// Logging Tools ...
|
||||
|
||||
/**
|
||||
* Extract Specified Token of Struct ...
|
||||
*
|
||||
@@ -368,7 +371,7 @@ struct XZigZagPoint
|
||||
}
|
||||
|
||||
//
|
||||
result = GetTag() + "_" + ToXString(dir) + "_" + ToXString(type) + "_" + ToXString(TimeToSeconds(time));
|
||||
result = GetTag() + "_" + symbol + "_" + ToXString(period) + "_" + ToXString(dir) + "_" + ToXString(type) + "_" + ToXString(TimeToSeconds(time));
|
||||
|
||||
//
|
||||
return result;
|
||||
@@ -403,6 +406,10 @@ struct XZigZagPoint
|
||||
//
|
||||
result =
|
||||
ToXString(dir) + spacer + GetTag() + ":" + spacer +
|
||||
"Symbol: " + symbol + spacer +
|
||||
"Period: " + ToXString(period) + spacer +
|
||||
"Type: " + ToXString(type) + spacer +
|
||||
"Direction: " + ToXString(dir) + spacer +
|
||||
"Value: " + ToXString(value) + spacer +
|
||||
"Time: " + ToXString(time) + spacer;
|
||||
|
||||
@@ -426,6 +433,17 @@ struct XZigZagAnalysis
|
||||
//
|
||||
ENUM_X_DIRECTION dir; // Direction ...
|
||||
|
||||
//
|
||||
// Pivots ...
|
||||
|
||||
//
|
||||
XZigZagPoint lastPeak;
|
||||
XZigZagPoint recentPeak;
|
||||
|
||||
//
|
||||
XZigZagPoint lastVale;
|
||||
XZigZagPoint recentVale;
|
||||
|
||||
//
|
||||
// Constructor ...
|
||||
XZigZagAnalysis()
|
||||
@@ -433,6 +451,253 @@ struct XZigZagAnalysis
|
||||
Clean();
|
||||
}
|
||||
|
||||
//
|
||||
// Initialize ...
|
||||
|
||||
/**
|
||||
* Analyse Market Structure ...
|
||||
*
|
||||
* @param bar: XOHCL, Specified Bar ...
|
||||
* @param points: XZigZagPoint, Specified ZigZag Points Collection ...
|
||||
*
|
||||
* @return ( bool )
|
||||
*/
|
||||
bool Analyse(
|
||||
XOHCL &bar,
|
||||
XZigZagPoint &points[] //
|
||||
)
|
||||
{
|
||||
//
|
||||
bool result = false;
|
||||
|
||||
//
|
||||
// Validate ...
|
||||
result = bar.IsValid() &&
|
||||
HasChild(points) &&
|
||||
bar.symbol == points[0].symbol;
|
||||
if (!result)
|
||||
{
|
||||
//
|
||||
Clean();
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// AssignSymbol and Period ...
|
||||
time = bar.time;
|
||||
symbol = bar.symbol;
|
||||
period = bar.period;
|
||||
|
||||
//
|
||||
// Detect At lease Two PEAK and Two Vale ...
|
||||
XZigZagPoint tmpPoints[];
|
||||
Copy(
|
||||
points,
|
||||
tmpPoints //
|
||||
);
|
||||
|
||||
//
|
||||
// Detect Highs ...
|
||||
|
||||
//
|
||||
// Highest High ...
|
||||
|
||||
//
|
||||
XZigZagPoint iZGPeak1;
|
||||
XZigZagPoint iZGPeak2;
|
||||
|
||||
//
|
||||
// First ...
|
||||
int idx = GetHighest(
|
||||
tmpPoints,
|
||||
X_ZIGZAG_POINT_TYPE_PEAK //
|
||||
);
|
||||
result = IsValidIndex(idx);
|
||||
if (!result)
|
||||
{
|
||||
//
|
||||
Clean();
|
||||
iZGPeak1.Clean();
|
||||
iZGPeak2.Clean();
|
||||
SpecifiedClean(tmpPoints);
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
iZGPeak1 = tmpPoints[idx];
|
||||
ArrayRemove(
|
||||
tmpPoints,
|
||||
idx,
|
||||
1 //
|
||||
);
|
||||
|
||||
//
|
||||
// Second ...
|
||||
idx = GetHighest(
|
||||
tmpPoints,
|
||||
X_ZIGZAG_POINT_TYPE_PEAK //
|
||||
);
|
||||
result = IsValidIndex(idx);
|
||||
if (!result)
|
||||
{
|
||||
//
|
||||
Clean();
|
||||
iZGPeak1.Clean();
|
||||
iZGPeak2.Clean();
|
||||
SpecifiedClean(tmpPoints);
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
iZGPeak2 = tmpPoints[idx];
|
||||
ArrayRemove(
|
||||
tmpPoints,
|
||||
idx,
|
||||
1 //
|
||||
);
|
||||
|
||||
//
|
||||
// Detect Lows ...
|
||||
|
||||
//
|
||||
XZigZagPoint iZGVale1;
|
||||
XZigZagPoint iZGVale2;
|
||||
|
||||
//
|
||||
// First ...
|
||||
idx = GetLowest(
|
||||
tmpPoints,
|
||||
X_ZIGZAG_POINT_TYPE_VALE //
|
||||
);
|
||||
result = IsValidIndex(idx);
|
||||
if (!result)
|
||||
{
|
||||
//
|
||||
Clean();
|
||||
iZGPeak1.Clean();
|
||||
iZGPeak2.Clean();
|
||||
iZGVale1.Clean();
|
||||
iZGVale2.Clean();
|
||||
SpecifiedClean(tmpPoints);
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
iZGVale1 = tmpPoints[idx];
|
||||
ArrayRemove(
|
||||
tmpPoints,
|
||||
idx,
|
||||
1 //
|
||||
);
|
||||
|
||||
//
|
||||
// Second ...
|
||||
idx = GetLowest(
|
||||
tmpPoints,
|
||||
X_ZIGZAG_POINT_TYPE_VALE //
|
||||
);
|
||||
result = IsValidIndex(idx);
|
||||
if (!result)
|
||||
{
|
||||
//
|
||||
Clean();
|
||||
iZGPeak1.Clean();
|
||||
iZGPeak2.Clean();
|
||||
iZGVale1.Clean();
|
||||
iZGVale2.Clean();
|
||||
SpecifiedClean(tmpPoints);
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
iZGVale2 = tmpPoints[idx];
|
||||
ArrayRemove(
|
||||
tmpPoints,
|
||||
idx,
|
||||
1 //
|
||||
);
|
||||
|
||||
//
|
||||
// Check Directions ...
|
||||
bool isBullish =
|
||||
//
|
||||
(iZGPeak1.time > iZGPeak2.time &&
|
||||
iZGVale1.time < iZGVale2.time)
|
||||
//
|
||||
;
|
||||
bool isBearish =
|
||||
//
|
||||
(iZGPeak1.time < iZGPeak2.time &&
|
||||
iZGVale1.time > iZGVale2.time)
|
||||
//
|
||||
;
|
||||
result =
|
||||
(isBullish && !isBearish) ||
|
||||
(isBearish && !isBullish);
|
||||
if (!result)
|
||||
{
|
||||
//
|
||||
Clean();
|
||||
iZGPeak1.Clean();
|
||||
iZGPeak2.Clean();
|
||||
iZGVale1.Clean();
|
||||
iZGVale2.Clean();
|
||||
SpecifiedClean(tmpPoints);
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Setting Direction ...
|
||||
dir =
|
||||
isBullish
|
||||
? X_DIRECTION_BULLISH
|
||||
: isBearish
|
||||
? X_DIRECTION_BEARISH
|
||||
: X_DIRECTION_NONE;
|
||||
|
||||
//
|
||||
// Setting Points ...
|
||||
Copy(
|
||||
points,
|
||||
pivots //
|
||||
);
|
||||
|
||||
//
|
||||
// Assigning Peaks and Vales ...
|
||||
if (result)
|
||||
{
|
||||
//
|
||||
lastPeak = iZGPeak1;
|
||||
lastVale = iZGVale1;
|
||||
recentPeak = iZGPeak2;
|
||||
recentVale = iZGVale2;
|
||||
}
|
||||
|
||||
//
|
||||
// Calculate Support and Resistance ...
|
||||
|
||||
//
|
||||
// Validate ...
|
||||
result = IsValid();
|
||||
if (!result)
|
||||
{
|
||||
Clean();
|
||||
}
|
||||
|
||||
//
|
||||
// Cleanup Resources ...
|
||||
iZGPeak1.Clean();
|
||||
iZGPeak2.Clean();
|
||||
iZGVale1.Clean();
|
||||
iZGVale2.Clean();
|
||||
SpecifiedClean(tmpPoints);
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Tools ...
|
||||
|
||||
@@ -448,6 +713,12 @@ struct XZigZagAnalysis
|
||||
dir = X_DIRECTION_NONE;
|
||||
SpecifiedClean(pivots);
|
||||
|
||||
//
|
||||
lastPeak.Clean();
|
||||
lastVale.Clean();
|
||||
recentPeak.Clean();
|
||||
recentVale.Clean();
|
||||
|
||||
//
|
||||
ZeroMemory(this);
|
||||
}
|
||||
@@ -464,11 +735,19 @@ struct XZigZagAnalysis
|
||||
|
||||
//
|
||||
result =
|
||||
//
|
||||
HasChild(pivots) &&
|
||||
HasDirection(dir) &&
|
||||
IsSpecifiedValid(time) &&
|
||||
IsSpecifiedValid(symbol) &&
|
||||
IsSpecifiedValid(period);
|
||||
IsSpecifiedValid(period) &&
|
||||
//
|
||||
lastPeak.IsValid() &&
|
||||
lastVale.IsValid() &&
|
||||
recentPeak.IsValid() &&
|
||||
recentVale.IsValid()
|
||||
//
|
||||
;
|
||||
|
||||
//
|
||||
return result;
|
||||
@@ -603,7 +882,269 @@ struct XZigZagAnalysis
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Check to model Has Same Direction ...
|
||||
*
|
||||
* @param item: XZigZagAnalysis, dest model for Checking ...
|
||||
*
|
||||
* @return ( bool )
|
||||
*/
|
||||
bool IsSameDirectionAs(XZigZagAnalysis &item)
|
||||
{
|
||||
//
|
||||
bool result = false;
|
||||
|
||||
//
|
||||
result =
|
||||
IsValid() &&
|
||||
item.IsValid() &&
|
||||
dir == item.dir;
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Check to model Has Analysis Trend ...
|
||||
*
|
||||
* @param item: XZigZagAnalysis, dest model for Checking ...
|
||||
*
|
||||
* @return ( bool )
|
||||
*/
|
||||
bool IsSameTrendAs(XZigZagAnalysis &item)
|
||||
{
|
||||
//
|
||||
bool result = false;
|
||||
|
||||
//
|
||||
result =
|
||||
IsValid() &&
|
||||
item.IsValid() &&
|
||||
IsSameMarketAs(item) &&
|
||||
IsSameDirectionAs(item);
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Loggint Tools ...
|
||||
|
||||
/**
|
||||
* Extract Specified Token of Struct ...
|
||||
*
|
||||
* @return ( string )
|
||||
*/
|
||||
string GetTag()
|
||||
{
|
||||
return GetToken(this);
|
||||
}
|
||||
|
||||
/**
|
||||
* Represent an String Unique Identifier for Chart Objects ...
|
||||
*
|
||||
* @return ( string )
|
||||
*/
|
||||
string GetObjectID()
|
||||
{
|
||||
//
|
||||
string result = "";
|
||||
|
||||
//
|
||||
if (!IsValid())
|
||||
{
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
result = GetTag() + "_" + symbol + "_" + ToXString(period) + "_" + ToXString(dir) + "_" + ToXString(TimeToSeconds(time));
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Represent a Point as String ...
|
||||
*
|
||||
* @param spacer: string, How to Represent Spaces ...
|
||||
*
|
||||
* @return ( string )
|
||||
*/
|
||||
string GetMessage(string spacer = NULL)
|
||||
{
|
||||
//
|
||||
string result = "";
|
||||
|
||||
//
|
||||
// Normalize Spacer ...
|
||||
if (!IsSpecifiedValid(spacer))
|
||||
{
|
||||
spacer = " ";
|
||||
}
|
||||
|
||||
//
|
||||
// Validate ...
|
||||
if (!IsValid())
|
||||
{
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
result =
|
||||
ToXString(dir) + spacer + GetTag() + ":" + spacer +
|
||||
"Symbol: " + symbol + spacer +
|
||||
"Period: " + ToXString(period) + spacer +
|
||||
"Direction: " + ToXString(dir) + spacer +
|
||||
"Time: " + ToXString(time) + spacer;
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
};
|
||||
|
||||
//
|
||||
// Extensions ...
|
||||
|
||||
/**
|
||||
* Get Highest ZigZagPoint Index in Specified Collection ...
|
||||
*
|
||||
* @param items: XZigZagPoint, Specified Points Collection to Search ...
|
||||
* @param type: ENUM_X_ZIGZAG_POINT_TYPE, Specified Points Type ...
|
||||
*
|
||||
* @return ( int )
|
||||
*/
|
||||
int GetHighest(
|
||||
XZigZagPoint &items[],
|
||||
ENUM_X_ZIGZAG_POINT_TYPE type = X_ZIGZAG_POINT_TYPE_NONE //
|
||||
)
|
||||
{
|
||||
//
|
||||
int result = -1;
|
||||
|
||||
//
|
||||
// Validate ...
|
||||
if (!HasChild(items))
|
||||
{
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
bool has = false;
|
||||
XZigZagPoint iPoint;
|
||||
int count = ArraySize(items);
|
||||
for (int i = 0; i < count; i++)
|
||||
{
|
||||
//
|
||||
// Passed Type ...
|
||||
has = !IsXValid(type)
|
||||
? true
|
||||
: type == items[i].type;
|
||||
|
||||
//
|
||||
// Check Can Assign ...
|
||||
has =
|
||||
has &&
|
||||
(!iPoint.IsValid() ||
|
||||
(iPoint.IsValid() &&
|
||||
items[i].value > iPoint.value));
|
||||
if (has)
|
||||
{
|
||||
//
|
||||
result = i;
|
||||
iPoint = items[i];
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
// Validate Result ...
|
||||
has =
|
||||
iPoint.IsValid() &&
|
||||
IsValidIndex(result);
|
||||
if (!has)
|
||||
{
|
||||
//
|
||||
result = -1;
|
||||
iPoint.Clean();
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
iPoint.Clean();
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get Lowest ZigZagPoint Index in Specified Collection ...
|
||||
*
|
||||
* @param items: XZigZagPoint, Specified Points Collection to Search ...
|
||||
* @param type: ENUM_X_ZIGZAG_POINT_TYPE, Specified Points Type ...
|
||||
*
|
||||
* @return ( int )
|
||||
*/
|
||||
int GetLowest(
|
||||
XZigZagPoint &items[],
|
||||
ENUM_X_ZIGZAG_POINT_TYPE type = X_ZIGZAG_POINT_TYPE_NONE //
|
||||
)
|
||||
{
|
||||
//
|
||||
int result = -1;
|
||||
|
||||
//
|
||||
// Validate ...
|
||||
if (!HasChild(items))
|
||||
{
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
bool has = false;
|
||||
XZigZagPoint iPoint;
|
||||
int count = ArraySize(items);
|
||||
for (int i = 0; i < count; i++)
|
||||
{
|
||||
//
|
||||
// Passed Type ...
|
||||
has = !IsXValid(type)
|
||||
? true
|
||||
: type == items[i].type;
|
||||
|
||||
//
|
||||
// Check Can Assign ...
|
||||
has =
|
||||
has &&
|
||||
(!iPoint.IsValid() ||
|
||||
(iPoint.IsValid() &&
|
||||
items[i].value < iPoint.value));
|
||||
if (has)
|
||||
{
|
||||
//
|
||||
result = i;
|
||||
iPoint = items[i];
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
// Validate Result ...
|
||||
has =
|
||||
iPoint.IsValid() &&
|
||||
IsValidIndex(result);
|
||||
if (!has)
|
||||
{
|
||||
//
|
||||
result = -1;
|
||||
iPoint.Clean();
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
iPoint.Clean();
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
Reference in New Issue
Block a user