Add Supports for Consolidation Range Founder ...

- [] required to Complete Supply and Demand Zone Retrieve in XConsolidation Zone Struct ...
This commit is contained in:
2024-12-11 02:14:37 +03:30
parent b5cec1f52a
commit a64430a28c
6 changed files with 1256 additions and 151 deletions
+249 -58
View File
@@ -26,6 +26,200 @@
//
// Definitions ...
//
// Consolidation Zone ...
struct XConsolidationZone
{
//
// Props ...
//
string symbol; // Symbol ...
ENUM_TIMEFRAMES period; // Period ...
//
double upper; // Upper ...
double lower; // Lower ...
//
int loopback; // Loopback ...
//
ENUM_X_DIRECTION breakDirection; // Break Direction ...
XOHCL breakerBar; // Breaker Bar ...
//
// Constructor ...
XConsolidationZone()
{
Clean();
}
//
// Tools ...
/**
* Initialize Zone ...
*
* @param _symbol: String ...
* @param _period: ENUM_TIMEFRAMES member ...
* @param _upper: Double ...
* @param _lower: Double ...
* @param _loopback: Integer ...
*
* @return ( bool )
*/
bool Init(
string _symbol,
ENUM_TIMEFRAMES _period,
double _upper,
double _lower,
int _loopback //
)
{
//
bool result = false;
//
_symbol = NormalizeSymbol(_symbol);
_period = NormalizePeriod(_period);
//
result =
//
_upper > 0 &&
_lower > 0 &&
_loopback > 0
//
;
//
upper = _upper;
lower = _lower;
symbol = _symbol;
period = _period;
loopback = _loopback;
//
result = IsValid();
//
return result;
}
/**
* Cleanup ...
*/
void Clean()
{
//
symbol = NULL;
period = NULL;
upper = 0;
lower = 0;
loopback = 0;
breakerBar.Clean();
breakDirection = X_DIRECTION_NONE;
}
/**
* Validate ...
*
* @return ( bool )
*/
bool IsValid()
{
//
bool result = false;
//
result =
//
IsValid(symbol) &&
IsValid(period) &&
upper > 0 &&
lower > 0 &&
loopback > 0
//
;
//
return result;
}
/**
* Check Zone is Breaked or not ...
*
* @return ( bool )
*/
bool IsBreaked()
{
//
bool result = false;
//
result = breakerBar.IsValid() &&
HasDirection(breakDirection);
//
return result;
}
/**
* Detect Supply Zone if Exists ...
*
* @return ( bool )
*/
bool DetectSupplyZone(
XCSupplyZone *&zone //
)
{
//
bool result = false;
//
result = IsBreaked();
if (!result)
{
return result;
}
//
// Implment Zone Finding ...
//
return result;
}
/**
* Detect Demand Zone if Exists ...
*
* @return ( bool )
*/
bool DetectDemandZone(
XCDemandZone *&zone //
)
{
//
bool result = false;
//
result = IsBreaked();
if (!result)
{
return result;
}
//
// Implment Zone Finding ...
//
return result;
}
//
};
//
// Implementations ...
class XCBarAnalyser : public XCBase
@@ -359,91 +553,88 @@ class XCBarAnalyser : public XCBase
}
/**
* Detect Consolidation Range ...
* Detect Price Consolidation ...
*
* @param index: Integer, Start Bar Index ...
* @param range: Integer, Range of Bars ...
* @param maxRange: Consolidation Price Range in Points ...
* @param symbol: String, Symbol ...
* @param period: ENUM_TIMEFRAMES member, Period ...
* @param bar: XOHCL instance Reference, Start Bar ...
* @param loopback: Integer, Consolidation Range Finder ...
* @param upper: Double Reference ...
* @param lower: Double Reference ...
* @param upperAppliedTo: ENUM_APPLIED_PRICE member, Upper Price ...
* @param lowerAppliedTo: ENUM_APPLIED_PRICE member, Lower Price ...
*
* @return ( bool )
*/
bool IsConsolidating(
int index,
int range,
double maxRange,
string symbol = NULL,
ENUM_TIMEFRAMES period = NULL //
bool IsConsolidate(
XOHCL &bar,
double &upper,
double &lower,
int loopback = 30,
ENUM_APPLIED_PRICE upperAppliedTo = PRICE_HIGH,
ENUM_APPLIED_PRICE lowerAppliedTo = PRICE_LOW //
)
{
//
bool result = false;
//
if (index < 0)
upper = 0;
lower = 0;
//
if (loopback < 7)
{
index = 0;
loopback = 7;
}
//
if (range < 1)
result = bar.IsValid();
if (!result)
{
range = 1;
return result;
}
//
if (maxRange < 1)
{
maxRange = 1;
}
int consolidationRange = 30;
double points = GetPoints(bar.symbol);
int index = bar.Index();
//
// Normalize ...
symbol = NormalizeSymbol(symbol);
period = NormalizePeriod(period);
//
// Point Value ...
double point = GetPoints(symbol);
//
double high = iHigh(
symbol,
period,
index //
);
double low = iLow(
symbol,
period,
index //
double upperPrice[];
int upperPriceCount = FillPrice(
upperPrice,
upperAppliedTo,
bar.symbol,
bar.period,
index,
loopback //
);
//
// Detect Range High and Low ...
for (int i = 1; i < range; i++)
double lowerPrice[];
int lowerPriceCount = FillPrice(
lowerPrice,
lowerAppliedTo,
bar.symbol,
bar.period,
index,
loopback //
);
//
result = upperPriceCount == lowerPriceCount &&
lowerPriceCount == loopback;
if (!result)
{
//
double iH = iHigh(
symbol,
period,
index + i //
);
//
double iL = iLow(
symbol,
period,
index + i //
);
//
high = MathMax(high, iH);
low = MathMin(low, iL);
return result;
}
//
result = (high - low) <= (maxRange * point);
upper = upperPrice[ArrayMaximum(upperPrice)];
lower = lowerPrice[ArrayMinimum(lowerPrice)];
//
double range = upper - lower;
result = range <= consolidationRange * points;
//
return result;