last ...
This commit is contained in:
@@ -3722,6 +3722,125 @@ bool IsBoxValid(
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Validate a Box based on Price ...
|
||||
*
|
||||
* @param box: XBoxZone instance, box to Validate ...
|
||||
* @param barIndex: int, Start Validating Bar's Index ...
|
||||
* @param pType: ENUM_X_BOUNDARY_PRICE, Price Type for Validation ...
|
||||
*
|
||||
* @return ( bool )
|
||||
*/
|
||||
bool IsBoxValid(
|
||||
XBoxZone &box,
|
||||
int barIndex = 0,
|
||||
ENUM_X_BOUNDARY_PRICE pType = X_BOUNDARY_PRICE_UP_DOWN //
|
||||
)
|
||||
{
|
||||
//
|
||||
bool result = false;
|
||||
|
||||
//
|
||||
// Normalize Bar Index ...
|
||||
barIndex = NormalizeInt(barIndex, 0);
|
||||
|
||||
//
|
||||
// Validaet ...
|
||||
result =
|
||||
box.IsValid() &&
|
||||
IsXValid(pType);
|
||||
if (!result)
|
||||
{
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
bool isBullish = box.IsBullish();
|
||||
|
||||
//
|
||||
int fromIDX = box.FromIndex();
|
||||
result =
|
||||
IsValidIndex(fromIDX) &&
|
||||
barIndex < fromIDX;
|
||||
if (!result)
|
||||
{
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Loop through ...
|
||||
XOHCL iBar;
|
||||
bool has = false;
|
||||
double appliedPrice = EMPTY_VALUE;
|
||||
for (int i = barIndex; i < fromIDX; i++)
|
||||
{
|
||||
//
|
||||
// Initialize Bar ...
|
||||
iBar.Clean();
|
||||
has = iBar.Init(box.symbol, box.period, i);
|
||||
if (!has)
|
||||
{
|
||||
//
|
||||
result = false;
|
||||
break;
|
||||
}
|
||||
|
||||
//
|
||||
// Calculate Applied Price ...
|
||||
switch (pType)
|
||||
{
|
||||
//
|
||||
case X_BOUNDARY_PRICE_UP_DOWN:
|
||||
//
|
||||
appliedPrice =
|
||||
isBullish
|
||||
? iBar.GetDown()
|
||||
: iBar.GetUp();
|
||||
break;
|
||||
|
||||
//
|
||||
case X_BOUNDARY_PRICE_HIGH_LOW:
|
||||
//
|
||||
appliedPrice =
|
||||
isBullish
|
||||
? iBar.low
|
||||
: iBar.high;
|
||||
break;
|
||||
|
||||
//
|
||||
default:
|
||||
appliedPrice = EMPTY_VALUE;
|
||||
break;
|
||||
}
|
||||
has = NotEmptyZero(appliedPrice);
|
||||
if (!has)
|
||||
{
|
||||
//
|
||||
result = false;
|
||||
break;
|
||||
}
|
||||
|
||||
//
|
||||
has =
|
||||
has &&
|
||||
result &&
|
||||
(isBullish
|
||||
? appliedPrice >= box.lower
|
||||
: appliedPrice <= box.upper);
|
||||
if (!has) {
|
||||
//
|
||||
result = false;
|
||||
break;
|
||||
}
|
||||
|
||||
//
|
||||
iBar.Clean();
|
||||
}
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
void SortBoxes(
|
||||
XBoxZone &items[],
|
||||
|
||||
Reference in New Issue
Block a user