add support of Consolidation Zone ibside XPOIDetector and XPOIState ...
This commit is contained in:
@@ -447,6 +447,191 @@ class XCBarAnalyser : public XCBase
|
||||
return result;
|
||||
}
|
||||
|
||||
bool HasConsolidationZone(
|
||||
XOHCL &bar,
|
||||
XConsolidationZone &zone,
|
||||
int minLoopback = 3,
|
||||
double range = 50,
|
||||
ENUM_APPLIED_PRICE upperAppliedTo = PRICE_HIGH,
|
||||
ENUM_APPLIED_PRICE lowerAppliedTo = PRICE_LOW //
|
||||
)
|
||||
{
|
||||
//
|
||||
bool result = false;
|
||||
|
||||
//
|
||||
zone.Clean();
|
||||
|
||||
//
|
||||
result = bar.IsValid() &&
|
||||
minLoopback > 0 &&
|
||||
range > 0;
|
||||
if (!result)
|
||||
{
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
double points = GetPoints(bar.symbol);
|
||||
int index = bar.Index() + 1;
|
||||
int length = minLoopback;
|
||||
|
||||
//
|
||||
double upperPrice[];
|
||||
int upperPriceCount = FillPrice(
|
||||
upperPrice,
|
||||
upperAppliedTo,
|
||||
bar.symbol,
|
||||
bar.period,
|
||||
index,
|
||||
length //
|
||||
);
|
||||
|
||||
//
|
||||
double lowerPrice[];
|
||||
int lowerPriceCount = FillPrice(
|
||||
lowerPrice,
|
||||
lowerAppliedTo,
|
||||
bar.symbol,
|
||||
bar.period,
|
||||
index,
|
||||
length //
|
||||
);
|
||||
|
||||
//
|
||||
result = upperPriceCount == lowerPriceCount &&
|
||||
lowerPriceCount == length;
|
||||
if (!result)
|
||||
{
|
||||
//
|
||||
Clean(upperPrice);
|
||||
Clean(lowerPrice);
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
double upper = upperPrice[ArrayMaximum(upperPrice)];
|
||||
double lower = lowerPrice[ArrayMinimum(lowerPrice)];
|
||||
|
||||
//
|
||||
bool isBullishBreake =
|
||||
bar.low > lower &&
|
||||
bar.high > upper &&
|
||||
bar.GetUp() > upper;
|
||||
bool isBearishBreake =
|
||||
bar.high < upper &&
|
||||
bar.low < lower &&
|
||||
bar.GetDown() < lower;
|
||||
result = isBullishBreake ||
|
||||
isBearishBreake;
|
||||
if (!result)
|
||||
{
|
||||
//
|
||||
Clean(upperPrice);
|
||||
Clean(lowerPrice);
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
double delta = upper - lower;
|
||||
result = delta <= range * points;
|
||||
if (!result)
|
||||
{
|
||||
//
|
||||
Clean(upperPrice);
|
||||
Clean(lowerPrice);
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
while (delta <= range * points)
|
||||
{
|
||||
//
|
||||
length++;
|
||||
|
||||
//
|
||||
upperPriceCount = FillPrice(
|
||||
upperPrice,
|
||||
upperAppliedTo,
|
||||
bar.symbol,
|
||||
bar.period,
|
||||
index,
|
||||
length //
|
||||
);
|
||||
|
||||
//
|
||||
lowerPriceCount = FillPrice(
|
||||
lowerPrice,
|
||||
lowerAppliedTo,
|
||||
bar.symbol,
|
||||
bar.period,
|
||||
index,
|
||||
length //
|
||||
);
|
||||
|
||||
//
|
||||
bool isValid = upperPriceCount == lowerPriceCount &&
|
||||
lowerPriceCount == length;
|
||||
if (!isValid)
|
||||
{
|
||||
break;
|
||||
}
|
||||
|
||||
//
|
||||
double iUpper = upperPrice[ArrayMaximum(upperPrice)];
|
||||
double iLower = lowerPrice[ArrayMinimum(lowerPrice)];
|
||||
|
||||
//
|
||||
delta = iUpper - iLower;
|
||||
if (delta <= range * points)
|
||||
{
|
||||
//
|
||||
upper = iUpper;
|
||||
lower = iLower;
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
Clean(upperPrice);
|
||||
Clean(lowerPrice);
|
||||
|
||||
//
|
||||
// Filling Zone ...
|
||||
zone.upper = upper;
|
||||
zone.lower = lower;
|
||||
zone.symbol = bar.symbol;
|
||||
zone.period = bar.period;
|
||||
zone.to = iTime(
|
||||
bar.symbol,
|
||||
bar.period,
|
||||
bar.Index() + 1 //
|
||||
);
|
||||
zone.from = iTime(
|
||||
bar.symbol,
|
||||
bar.period,
|
||||
bar.Index() + length //
|
||||
);
|
||||
zone.dir = isBullishBreake
|
||||
? X_DIRECTION_BULLISH
|
||||
: X_DIRECTION_BEARISH;
|
||||
|
||||
//
|
||||
result = zone.IsValid();
|
||||
if (!result)
|
||||
{
|
||||
zone.Clean();
|
||||
}
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Check Bar Has Bullish Trend or not ...
|
||||
*
|
||||
|
||||
Reference in New Issue
Block a user