fix trending draw issues ...

This commit is contained in:
2025-09-24 16:25:07 +03:30
parent e2b05b6455
commit 7d00ab69cb
6 changed files with 563 additions and 82 deletions
+405 -50
View File
@@ -21,6 +21,7 @@
//
// Imports ...
#include "../Libraries/x-saherelm.x-ohcl.lib.mq5"
#include "../Libraries/x-saherelm.x-poi.lib.mq5"
//
@@ -29,6 +30,51 @@
//+------------------------------------------------------------------+
//| Oldest Detection |
//+------------------------------------------------------------------+
/**
* Get Oldest Index of Specified Collection ...
*
* @param source: Specified Collection ...
*
* @return ( int )
*/
int GetOldestBar(
XOHCL &source[] //
)
{
//
int result = -1;
//
int count = ArraySize(source);
if (!IsValidSize(count))
{
return result;
}
//
XOHCL selected;
for (int i = 0; i < count; i++)
{
//
bool canSet =
!selected.IsValid()
? true
: selected.time > source[i].time;
if (canSet)
{
//
result = i;
selected = source[i];
}
}
//
selected.Clean();
//
return result;
}
/**
* Get Oldest Index of Specified Collection ...
*
@@ -54,23 +100,17 @@ int GetOldest(
XBoxZone selected;
for (int i = 0; i < count; i++)
{
//
XBoxZone iBox = source[i];
//
bool canSet =
!selected.IsValid()
? true
: selected.from > iBox.from;
: selected.from > source[i].from;
if (canSet)
{
//
result = i;
selected = iBox;
selected = source[i];
}
//
iBox.Clean();
}
//
@@ -114,16 +154,9 @@ int GetOldestByBar(
for (int i = 0; i < count; i++)
{
//
XBoxZone iBox = source[i];
//
bool isBoxValidForBar = IsBoxPlaceValidForBar(bar, iBox);
bool isBoxValidForBar = IsBoxPlaceValidForBar(bar, source[i]);
if (!isBoxValidForBar)
{
//
iBox.Clean();
//
continue;
}
@@ -131,16 +164,13 @@ int GetOldestByBar(
bool canSet =
!selected.IsValid()
? true
: selected.from > iBox.from;
: selected.from > source[i].from;
if (canSet)
{
//
result = i;
selected = iBox;
selected = source[i];
}
//
iBox.Clean();
}
//
@@ -224,6 +254,51 @@ int GetOldest(
//+------------------------------------------------------------------+
//| Youngest Detection |
//+------------------------------------------------------------------+
/**
* Get Youngest Index of Specified Collection ...
*
* @param source: Specified Collection ...
*
* @return ( int )
*/
int GetYoungestBar(
XOHCL &source[] //
)
{
//
int result = -1;
//
int count = ArraySize(source);
if (!IsValidSize(count))
{
return result;
}
//
XOHCL selected;
for (int i = 0; i < count; i++)
{
//
bool canSet =
!selected.IsValid()
? true
: selected.time < source[i].time;
if (canSet)
{
//
result = i;
selected = source[i];
}
}
//
selected.Clean();
//
return result;
}
/**
* Get Youngest Index of Specified Collection ...
*
@@ -249,23 +324,17 @@ int GetYoungest(
XBoxZone selected;
for (int i = 0; i < count; i++)
{
//
XBoxZone iBox = source[i];
//
bool canSet =
!selected.IsValid()
? true
: selected.from < iBox.from;
: selected.from < source[i].from;
if (canSet)
{
//
result = i;
selected = iBox;
selected = source[i];
}
//
iBox.Clean();
}
//
@@ -309,16 +378,9 @@ int GetYoungestByBar(
for (int i = 0; i < count; i++)
{
//
XBoxZone iBox = source[i];
//
bool isBoxValidForBar = IsBoxPlaceValidForBar(bar, iBox);
bool isBoxValidForBar = IsBoxPlaceValidForBar(bar, source[i]);
if (!isBoxValidForBar)
{
//
iBox.Clean();
//
continue;
}
@@ -326,16 +388,13 @@ int GetYoungestByBar(
bool canSet =
!selected.IsValid()
? true
: selected.from < iBox.from;
: selected.from < source[i].from;
if (canSet)
{
//
result = i;
selected = iBox;
selected = source[i];
}
//
iBox.Clean();
}
//
@@ -419,6 +478,65 @@ int GetYoungest(
//+------------------------------------------------------------------+
//| Highest Detection |
//+------------------------------------------------------------------+
/**
* Get Highest Index of Specified Collection ...
*
* @param source: Specified Collection ...
* @param _priceType: Specified Price type ...
*
* @return ( int )
*/
int GetHighestBar(
XOHCL &source[],
ENUM_X_PRICE _priceType = X_PRICE_HIGH //
)
{
//
int result = -1;
//
if (!IsXValid(_priceType))
{
_priceType = X_PRICE_HIGH;
}
//
int count = ArraySize(source);
if (!IsValidSize(count))
{
return result;
}
//
XOHCL selected;
double iPrice = EMPTY_VALUE;
double selectedPrice = EMPTY_VALUE;
for (int i = 0; i < count; i++)
{
//
iPrice = source[i].GetPrice(_priceType);
selectedPrice = selected.GetPrice(_priceType);
//
bool canSet =
!selected.IsValid()
? true
: selectedPrice < iPrice;
if (canSet)
{
//
result = i;
selected = source[i];
}
}
//
selected.Clean();
//
return result;
}
/**
* Get Highest Index of Specified Collection ...
*
@@ -444,23 +562,17 @@ int GetHighest(
XBoxZone selected;
for (int i = 0; i < count; i++)
{
//
XBoxZone iBox = source[i];
//
bool canSet =
!selected.IsValid()
? true
: selected.upper < iBox.upper;
: selected.upper < source[i].upper;
if (canSet)
{
//
result = i;
selected = iBox;
selected = source[i];
}
//
iBox.Clean();
}
//
@@ -614,6 +726,64 @@ int GetHighest(
//+------------------------------------------------------------------+
//| Loest Detection |
//+------------------------------------------------------------------+
/**
* Get Lowest Index of Specified Collection ...
*
* @param source: Specified Collection ...
*
* @return ( int )
*/
int GetLowestBar(
XOHCL &source[],
ENUM_X_PRICE _priceType = X_PRICE_LOW //
)
{
//
int result = -1;
//
if (!IsXValid(_priceType))
{
_priceType = X_PRICE_LOW;
}
//
int count = ArraySize(source);
if (!IsValidSize(count))
{
return result;
}
//
XOHCL selected;
double iPrice = EMPTY_VALUE;
double selectedPrice = EMPTY_VALUE;
for (int i = 0; i < count; i++)
{
//
iPrice = source[i].GetPrice(_priceType);
selectedPrice = selected.GetPrice(_priceType);
//
bool canSet =
!selected.IsValid()
? true
: selectedPrice > iPrice;
if (canSet)
{
//
result = i;
selected = source[i];
}
}
//
selected.Clean();
//
return result;
}
/**
* Get Lowest Index of Specified Collection ...
*
@@ -920,6 +1090,94 @@ int SelectItemForSorting(
return result;
}
/**
* Select Specified Index of a Collection by Sort Params ...
*
* @param source: Collection for Search ...
* @param sortBy: ENUM_X_SORT_BY, Specified Sort Param ...
* @param sortDir: ENUM_X_DIRECTION, Specified Sort Direction ...
*
* @return ( int )
*/
int SelectBarForSorting(
XOHCL &source[],
ENUM_X_SORT_BY sortBy = X_SORT_BY_DATE,
ENUM_X_DIRECTION sortDir = X_DIRECTION_BULLISH,
ENUM_X_PRICE priceType = X_PRICE_NONE //
)
{
//
int result = -1;
//
// Validate ...
if (!HasChild(source) ||
!IsXValid(sortBy) ||
!HasDirection(sortDir))
{
return result;
}
//
// Sort By Date ...
if (sortBy == X_SORT_BY_DATE)
{
//
// Select Based on Sorting Direction ...
//
// form Oldest to Youngest ...
if (sortDir == X_DIRECTION_BULLISH)
{
result = GetOldestBar(source);
}
//
// form Youngest to Oldest ...
else if (sortDir == X_DIRECTION_BEARISH)
{
result = GetYoungestBar(source);
}
//
// Not Valid ...
else
{
result = -1;
}
}
//
// Sort By Value ...
else if (sortBy == X_SORT_BY_VALUE)
{
//
// form Lowst to Highest ...
if (sortDir == X_DIRECTION_BULLISH)
{
result = GetLowestBar(source, priceType);
}
//
// form Highest to Lowest ...
else if (sortDir == X_DIRECTION_BEARISH)
{
result = GetHighestBar(source, priceType);
}
//
// Not Valid ...
else
{
result = -1;
}
}
//
// Not Valid ...
else
{
result = -1;
}
//
return result;
}
/**
* Apply Sort on Specified Collection ...
*
@@ -1014,6 +1272,103 @@ void Sort(
// Cleanup Resources ...
SpecifiedClean(tmps);
}
/**
* Apply Sort on Specified Collection ...
*
* @param source: Collection Reference to Sort ...
* @param sortBy: ENUM_X_SORT_BY, Specified Sort Param ...
* @param sortDir: ENUM_X_DIRECTION, Specified Sort Direction ...
* @param priceType: ENUM_X_PRICE, Price Selecting Method ...
* @param maxAllowed: int, Max Allowed Collection Size ...
*/
void SortBar(
XOHCL &source[],
ENUM_X_SORT_BY sortBy = X_SORT_BY_DATE,
ENUM_X_DIRECTION sortDir = X_DIRECTION_BULLISH,
ENUM_X_PRICE priceType = X_PRICE_NONE,
int maxAllowed = 0 //
)
{
//
int idx = -1;
bool has = false;
//
// Validate ...
has =
IsXValid(sortBy) &&
HasChild(source) &&
HasDirection(sortDir);
if (!has)
{
return;
}
//
// Copy source for Manipulating ...
XOHCL tmps[];
Copy(
source,
tmps //
);
//
// Clean Source Collection for Adding Sorted Items ...
Clean(source);
//
// Loop Through Temp Collection Has Child ...
while (HasChild(tmps))
{
//
// Select Based on Sorting Parameter ...
idx = SelectBarForSorting(
tmps,
sortBy,
sortDir,
priceType //
);
//
// Validate Detected Index ...
has = IsValidIndex(idx);
if (!has)
{
break;
}
//
// Add Detected Indexed Item to Source ...
AddRef(
tmps[idx],
source //
);
//
// Remove Item From Temp Collection ...
ArrayRemove(
tmps,
idx,
1 //
);
}
//
// Cleanup Collection if Max Items Reached ...
if (maxAllowed > 0)
{
//
CleanupArray(
source,
maxAllowed //
);
}
//
// Cleanup Resources ...
SpecifiedClean(tmps);
}
//+------------------------------------------------------------------+
//+------------------------------------------------------------------+