last works on Peak and Vales ...
This commit is contained in:
@@ -2441,4 +2441,609 @@ int GetBars(
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove Specified Item from a Collection ...
|
||||
*
|
||||
* @param item: Specified Item ...
|
||||
* @param source: Specified Collection for Remove item from it ...
|
||||
*
|
||||
* @return ( bool )
|
||||
*/
|
||||
bool Remove(
|
||||
XOHCL &item,
|
||||
XOHCL &source[] //
|
||||
)
|
||||
{
|
||||
//
|
||||
bool result = false;
|
||||
|
||||
//
|
||||
result =
|
||||
item.IsValid() &&
|
||||
HasChild(source);
|
||||
if (!result)
|
||||
{
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
int idx = -1;
|
||||
result = FindIndex(
|
||||
idx,
|
||||
item,
|
||||
source //
|
||||
);
|
||||
if (!result)
|
||||
{
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
result = ArrayRemove(
|
||||
source,
|
||||
idx,
|
||||
1 //
|
||||
);
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove Specified items from a Collection ...
|
||||
*
|
||||
* @param items: Specified Items to Remove ...
|
||||
* @param sources: Sepcified Collection for Removing items from it ...
|
||||
*
|
||||
* @return ( int )
|
||||
*/
|
||||
int Removes(
|
||||
XOHCL &items[],
|
||||
XOHCL &sources[] //
|
||||
)
|
||||
{
|
||||
//
|
||||
int result = 0;
|
||||
|
||||
//
|
||||
bool has = HasChild(items) &&
|
||||
HasChild(sources);
|
||||
if (!has)
|
||||
{
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
int idx = -1;
|
||||
has = false;
|
||||
int count = ArraySize(items);
|
||||
for (int i = 0; i < count; i++)
|
||||
{
|
||||
//
|
||||
// Detect Item Index in Collection ...
|
||||
has = FindIndex(
|
||||
idx,
|
||||
items[i],
|
||||
sources //
|
||||
);
|
||||
if (has)
|
||||
{
|
||||
//
|
||||
// Remove Detected Index from Collection ...
|
||||
has = ArrayRemove(
|
||||
sources,
|
||||
idx,
|
||||
1 //
|
||||
);
|
||||
|
||||
//
|
||||
if (has)
|
||||
{
|
||||
//
|
||||
// Count Removed Items ...
|
||||
result++;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Find Specified Item index in a Collection ...
|
||||
*
|
||||
* @param index: int, reference to Hold Index if Exists ...
|
||||
* @param item: Specified item to Detect ...
|
||||
* @param source: Collection to Search for item ...
|
||||
*
|
||||
* @return ( bool )
|
||||
*/
|
||||
bool FindIndex(
|
||||
int &index,
|
||||
XOHCL &item,
|
||||
XOHCL &source[] //
|
||||
)
|
||||
{
|
||||
//
|
||||
bool result = false;
|
||||
|
||||
//
|
||||
index = -1;
|
||||
|
||||
//
|
||||
int count = ArraySize(source);
|
||||
result = item.IsValid() &&
|
||||
IsValidSize(count);
|
||||
if (!result)
|
||||
{
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
for (int i = 0; i < count; i++)
|
||||
{
|
||||
//
|
||||
bool isSame = item.IsSameAs(source[i]);
|
||||
if (isSame)
|
||||
{
|
||||
//
|
||||
index = i;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
result = IsValidIndex(index);
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Add Specified Item to Specified Collection, if not Exists ...
|
||||
*
|
||||
* @param item: Item to Add ...
|
||||
* @param sources: Collection to Add item ...
|
||||
* @param maxAllowed: int, Max Allowed Collection Size ...
|
||||
*
|
||||
* @return ( bool )
|
||||
*/
|
||||
bool AddIfNotExists(
|
||||
XOHCL &item,
|
||||
XOHCL &sources[],
|
||||
int maxAllowed = 0 //
|
||||
)
|
||||
{
|
||||
//
|
||||
bool result = false;
|
||||
|
||||
//
|
||||
// Validate Args ...
|
||||
result = item.IsValid();
|
||||
if (!result)
|
||||
{
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Check Item Exists or not ...
|
||||
int idx = -1;
|
||||
bool isExists = FindIndex(
|
||||
idx,
|
||||
item,
|
||||
sources //
|
||||
);
|
||||
result = !isExists;
|
||||
if (!result)
|
||||
{
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
AddRef(
|
||||
item,
|
||||
sources //
|
||||
);
|
||||
|
||||
//
|
||||
// Handle Cleanup Collection
|
||||
// if Max Reached ...
|
||||
if (result &&
|
||||
maxAllowed > 0)
|
||||
{
|
||||
//
|
||||
CleanupArray(
|
||||
sources,
|
||||
maxAllowed //
|
||||
);
|
||||
}
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get Oldest Index of Specified Collection ...
|
||||
*
|
||||
* @param source: Specified Collection ...
|
||||
*
|
||||
* @return ( int )
|
||||
*/
|
||||
int GetOldest(
|
||||
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 ...
|
||||
*
|
||||
* @param source: Specified Collection ...
|
||||
*
|
||||
* @return ( int )
|
||||
*/
|
||||
int GetYoungest(
|
||||
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 Lowest Index of Specified Collection ...
|
||||
*
|
||||
* @param source: Specified Collection ...
|
||||
*
|
||||
* @return ( int )
|
||||
*/
|
||||
int GetLowest(
|
||||
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 Highest Index of Specified Collection ...
|
||||
*
|
||||
* @param source: Specified Collection ...
|
||||
* @param _priceType: Specified Price type ...
|
||||
*
|
||||
* @return ( int )
|
||||
*/
|
||||
int GetHighest(
|
||||
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 Nearest Directional Bar ...
|
||||
*
|
||||
* @param bar: XOHCL, reference to Specified Start Bar ...
|
||||
* @param directionalBar: XOHCL, reference to hold Detected Bar ...
|
||||
* @param forDir: ENUM_X_DIRECTION, Specified Which Directional Bar looking for ...
|
||||
* @param loopback: int, Loopback Length ...
|
||||
*
|
||||
* @return ( bool )
|
||||
*/
|
||||
bool GetDirectionalBar(
|
||||
XOHCL &bar,
|
||||
XOHCL &directionalBar,
|
||||
ENUM_X_DIRECTION forDir,
|
||||
int loopback = 1500 //
|
||||
)
|
||||
{
|
||||
//
|
||||
bool result = false;
|
||||
|
||||
//
|
||||
// Prepare ...
|
||||
directionalBar.Clean();
|
||||
|
||||
//
|
||||
// Normalize ...
|
||||
loopback = NormalizeInt(loopback, 1);
|
||||
|
||||
//
|
||||
// Validate ...
|
||||
result = bar.IsValid() &&
|
||||
HasDirection(forDir);
|
||||
if (!result)
|
||||
{
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
int start = bar.Index() + 1;
|
||||
int end = start + loopback;
|
||||
for (int i = start; i < end; i++)
|
||||
{
|
||||
//
|
||||
directionalBar.Clean();
|
||||
result = bar.BarAt(i, directionalBar);
|
||||
result = result &&
|
||||
directionalBar.GetDirection() == forDir;
|
||||
if (result)
|
||||
{
|
||||
break;
|
||||
}
|
||||
|
||||
//
|
||||
directionalBar.Clean();
|
||||
}
|
||||
|
||||
//
|
||||
result = directionalBar.IsValid() &&
|
||||
forDir == directionalBar.GetDirection();
|
||||
|
||||
//
|
||||
// Cleanup Resources ...
|
||||
if (!result)
|
||||
{
|
||||
directionalBar.Clean();
|
||||
}
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get Nearest Breaker Bar of Specified Bar's Price ...
|
||||
*
|
||||
* @param bar: XOHCL, reference to Specified Bar ...
|
||||
* @param breaker: XOHCL, reference to hold Detected Breaker Bar ...
|
||||
* @param priceType: ENUM_X_PRICE, which price type of Bar to Check to Break ...
|
||||
* @param breakType: ENUM_X_PRICE, which price of Breaker Bar must Breke price ...
|
||||
* @param breakDir: ENUM_X_DIRECTION, Specified Break Direction ...
|
||||
* @param loopback: int, Max Allowed Loopback to Detect Breaker Bar ...
|
||||
*
|
||||
* @return ( bool )
|
||||
*/
|
||||
bool GetBreakerBar(
|
||||
XOHCL &bar,
|
||||
XOHCL &breaker,
|
||||
ENUM_X_PRICE priceType,
|
||||
ENUM_X_PRICE breakType,
|
||||
ENUM_X_DIRECTION breakDir,
|
||||
int loopback = 1500 //
|
||||
)
|
||||
{
|
||||
//
|
||||
// PriceType: which Applied Price of Specified Bar must to Check for Break ...
|
||||
|
||||
//
|
||||
// BreakType: which Applied Price of breakerBar must Break price ...
|
||||
|
||||
//
|
||||
// BreakDir:
|
||||
// -----------
|
||||
// Bullish: Price Must Break Applied Price from Down to Top ...
|
||||
// Bearish: Price must Break Applied Price from Top to Down ...
|
||||
|
||||
//
|
||||
bool result = false;
|
||||
|
||||
//
|
||||
// Prepare ...
|
||||
breaker.Clean();
|
||||
|
||||
//
|
||||
// Normalize ...
|
||||
loopback = NormalizeInt(loopback, 1);
|
||||
|
||||
//
|
||||
// Validate ...
|
||||
result = bar.IsValid() &&
|
||||
IsXValid(priceType) &&
|
||||
IsXValid(breakType) &&
|
||||
HasDirection(breakDir);
|
||||
if (!result)
|
||||
{
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
double iPrice = EMPTY_VALUE;
|
||||
bool isBullish = IsXBullish(breakDir);
|
||||
double price = bar.GetPrice(priceType);
|
||||
|
||||
//
|
||||
int start = bar.Index();
|
||||
int end = start + loopback;
|
||||
for (int i = start; i < end; i++)
|
||||
{
|
||||
//
|
||||
breaker.Clean();
|
||||
iPrice = EMPTY_VALUE;
|
||||
|
||||
//
|
||||
// Initialize Indexed Bar ...
|
||||
result = bar.BarAt(i, breaker);
|
||||
if (!result)
|
||||
{
|
||||
breaker.Clean();
|
||||
break;
|
||||
}
|
||||
|
||||
//
|
||||
// Check Breake ...
|
||||
iPrice = breaker.GetPrice(breakType);
|
||||
result =
|
||||
isBullish
|
||||
? iPrice > price
|
||||
: iPrice < price;
|
||||
if (result)
|
||||
{
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
result = breaker.IsValid();
|
||||
|
||||
//
|
||||
// Cleanup Resources ...
|
||||
if (!result)
|
||||
{
|
||||
breaker.Clean();
|
||||
}
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
Reference in New Issue
Block a user