add support of Consolidation Zone ibside XPOIDetector and XPOIState ...
This commit is contained in:
@@ -3754,6 +3754,132 @@ int ExtractSwings(
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Consolidation Zone ...
|
||||
struct XConsolidationZone
|
||||
{
|
||||
//
|
||||
// Props ...
|
||||
|
||||
//
|
||||
string symbol; // Symbol ...
|
||||
ENUM_TIMEFRAMES period; // Period ...
|
||||
|
||||
//
|
||||
double upper; // Upper ...
|
||||
double lower; // Lower ...
|
||||
|
||||
//
|
||||
datetime from; // Start Date
|
||||
datetime to; // Breake Date
|
||||
|
||||
//
|
||||
ENUM_X_DIRECTION dir; // Break Direction ...
|
||||
|
||||
//
|
||||
// Constructor ...
|
||||
XConsolidationZone()
|
||||
{
|
||||
Clean();
|
||||
}
|
||||
|
||||
//
|
||||
// Tools ...
|
||||
|
||||
/**
|
||||
* Cleanup ...
|
||||
*/
|
||||
void Clean()
|
||||
{
|
||||
//
|
||||
upper = 0;
|
||||
lower = 0;
|
||||
|
||||
//
|
||||
to = NULL;
|
||||
from = NULL;
|
||||
symbol = NULL;
|
||||
period = NULL;
|
||||
dir = X_DIRECTION_NONE;
|
||||
|
||||
//
|
||||
ZeroMemory(this);
|
||||
}
|
||||
|
||||
/**
|
||||
* Validate ...
|
||||
*
|
||||
* @return ( bool )
|
||||
*/
|
||||
bool IsValid()
|
||||
{
|
||||
//
|
||||
bool result = false;
|
||||
|
||||
//
|
||||
result =
|
||||
//
|
||||
upper > 0 &&
|
||||
lower > 0 &&
|
||||
IsValid(to) &&
|
||||
IsValid(from) &&
|
||||
IsValid(symbol) &&
|
||||
IsValid(period) &&
|
||||
HasDirection(dir)
|
||||
//
|
||||
;
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
bool IsSameAs(
|
||||
XConsolidationZone &item //
|
||||
)
|
||||
{
|
||||
//
|
||||
bool result = false;
|
||||
|
||||
//
|
||||
result = IsValid() &&
|
||||
item.IsValid() &&
|
||||
dir == item.dir &&
|
||||
from == item.from &&
|
||||
upper == item.upper &&
|
||||
lower == item.lower &&
|
||||
symbol == item.symbol &&
|
||||
period == item.period;
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieve Unique Identifier ...
|
||||
*
|
||||
* @return ( string )
|
||||
*/
|
||||
string GetTag()
|
||||
{
|
||||
//
|
||||
string result =
|
||||
//
|
||||
"XCZONE" + "_" +
|
||||
ToString(dir) + "_" +
|
||||
symbol + "_" +
|
||||
ToString(period) + "_" +
|
||||
ToString(upper) + "_" +
|
||||
ToString(lower)
|
||||
//
|
||||
;
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
};
|
||||
|
||||
//
|
||||
// Functions ...
|
||||
|
||||
@@ -5255,9 +5381,9 @@ int FillPrice(
|
||||
}
|
||||
|
||||
//
|
||||
if (_mLoopback < 7)
|
||||
if (_mLoopback < 1)
|
||||
{
|
||||
_mLoopback = 7;
|
||||
_mLoopback = 1;
|
||||
}
|
||||
|
||||
//
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -67,6 +67,9 @@ enum ENUM_XPOIS
|
||||
// Fair Value Gaps ...
|
||||
X_POI_BULLISH_FVG, // Bullish Order Block ...
|
||||
X_POI_BEARISH_FVG, // Bearish Order Block ...
|
||||
//
|
||||
X_BULLISH_CONSOLIDATION_ZONE,
|
||||
X_BEARISH_CONSOLIDATION_ZONE,
|
||||
};
|
||||
|
||||
//
|
||||
@@ -111,6 +114,8 @@ enum ENUM_XPOI_EVENTS
|
||||
// Fair Value Gaps ...
|
||||
X_BULLISH_FVG_DETECTED, // Bullish Fair Value Gapّ ...
|
||||
X_BEARISH_FVG_DETECTED, // Bearish Fair Value Gapّ ...
|
||||
X_BULLISH_CONSOLIDATION_ZONE_DETECTED,
|
||||
X_BEARISH_CONSOLIDATION_ZONE_DETECTED,
|
||||
};
|
||||
|
||||
//
|
||||
@@ -222,6 +227,16 @@ string ToString(ENUM_XPOIS value)
|
||||
case X_POI_TICKS_ZONES:
|
||||
result = "XTKSZ";
|
||||
break;
|
||||
|
||||
//
|
||||
case X_BULLISH_CONSOLIDATION_ZONE:
|
||||
result = "XBULLCZ";
|
||||
break;
|
||||
|
||||
//
|
||||
case X_BEARISH_CONSOLIDATION_ZONE:
|
||||
result = "XBEARCZ";
|
||||
break;
|
||||
}
|
||||
|
||||
//
|
||||
@@ -5175,427 +5190,6 @@ class XCSession : public XCFromToZone
|
||||
//
|
||||
};
|
||||
|
||||
//
|
||||
// Consolidation Zone ...
|
||||
struct XConsolidationZone
|
||||
{
|
||||
//
|
||||
// Props ...
|
||||
|
||||
//
|
||||
string symbol; // Symbol ...
|
||||
ENUM_TIMEFRAMES period; // Period ...
|
||||
|
||||
//
|
||||
double upper; // Upper ...
|
||||
double lower; // Lower ...
|
||||
|
||||
//
|
||||
datetime initTime;
|
||||
int loopback; // Loopback ...
|
||||
|
||||
//
|
||||
ENUM_X_DIRECTION breakDir; // 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
|
||||
//
|
||||
;
|
||||
if (!result)
|
||||
{
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
upper = _upper;
|
||||
lower = _lower;
|
||||
symbol = _symbol;
|
||||
period = _period;
|
||||
loopback = _loopback;
|
||||
|
||||
//
|
||||
result = IsValid();
|
||||
if (result)
|
||||
{
|
||||
initTime = TimeCurrent();
|
||||
}
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Update Breaked State ...
|
||||
*/
|
||||
void Update()
|
||||
{
|
||||
//
|
||||
if (!IsValid())
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
//
|
||||
if (IsBreaked())
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
//
|
||||
XOHCL cBar;
|
||||
bool isInited = cBar.Init(
|
||||
symbol,
|
||||
period,
|
||||
0 //
|
||||
);
|
||||
if (!isInited)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
//
|
||||
XOHCL pBar;
|
||||
isInited = cBar.GetPreviousBar(pBar);
|
||||
if (!isInited)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
//
|
||||
// Check Consolidation Hounts ...
|
||||
bool isHountTop = cBar.high > upper &&
|
||||
cBar.low < upper &&
|
||||
cBar.GetUp() < upper;
|
||||
bool isHountBottom = cBar.low < lower &&
|
||||
cBar.high > lower &&
|
||||
cBar.GetDown() > lower;
|
||||
bool isHounted = isHountTop ||
|
||||
isHountBottom;
|
||||
if (isHounted)
|
||||
{
|
||||
//
|
||||
if (isHountTop)
|
||||
{
|
||||
upper = cBar.high;
|
||||
}
|
||||
|
||||
//
|
||||
if (isHountBottom)
|
||||
{
|
||||
lower = cBar.low;
|
||||
}
|
||||
|
||||
//
|
||||
return;
|
||||
}
|
||||
|
||||
//
|
||||
// Check Consolidation Breaks ...
|
||||
bool isBreakTop = (cBar.GetUp() > upper &&
|
||||
cBar.GetDown() < upper) ||
|
||||
(cBar.low > upper &&
|
||||
cBar.high > upper);
|
||||
bool isBreakBottom = (cBar.GetDown() < lower &&
|
||||
cBar.GetUp() > lower) ||
|
||||
(cBar.high < lower &&
|
||||
cBar.low < lower);
|
||||
bool isBreaked = isBreakTop ||
|
||||
isBreakBottom;
|
||||
if (!isBreaked)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
//
|
||||
// Calculate Break Direction ...
|
||||
breakerBar = cBar;
|
||||
breakDir = isBreakTop
|
||||
? X_DIRECTION_BULLISH
|
||||
: isBreakBottom
|
||||
? X_DIRECTION_BEARISH
|
||||
: X_DIRECTION_NONE;
|
||||
}
|
||||
|
||||
/**
|
||||
* Cleanup ...
|
||||
*/
|
||||
void Clean()
|
||||
{
|
||||
//
|
||||
upper = 0;
|
||||
lower = 0;
|
||||
loopback = 0;
|
||||
symbol = NULL;
|
||||
period = NULL;
|
||||
initTime = NULL;
|
||||
breakerBar.Clean();
|
||||
breakDir = X_DIRECTION_NONE;
|
||||
|
||||
//
|
||||
ZeroMemory(this);
|
||||
}
|
||||
|
||||
/**
|
||||
* 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(breakDir);
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Detect Supply Zone if Exists ...
|
||||
*
|
||||
* @return ( bool )
|
||||
*/
|
||||
bool HasSupplyZone(
|
||||
XCSupplyZone *&zone //
|
||||
)
|
||||
{
|
||||
//
|
||||
bool result = false;
|
||||
|
||||
//
|
||||
result = IsBreaked() &&
|
||||
breakDir == X_DIRECTION_BEARISH;
|
||||
if (!result)
|
||||
{
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Implment Zone Finding ...
|
||||
int index = breakerBar.Index();
|
||||
int hhIDX = iHighest(
|
||||
symbol,
|
||||
period,
|
||||
MODE_HIGH,
|
||||
loopback,
|
||||
index //
|
||||
);
|
||||
result = IsValidIndex(hhIDX);
|
||||
if (!result)
|
||||
{
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
XOHCL hhBar;
|
||||
result = hhBar.Init(
|
||||
symbol,
|
||||
period,
|
||||
hhIDX //
|
||||
);
|
||||
if (!result)
|
||||
{
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
zone = new XCSupplyZone();
|
||||
result = zone.Init(
|
||||
hhBar,
|
||||
loopback //
|
||||
);
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Detect Demand Zone if Exists ...
|
||||
*
|
||||
* @return ( bool )
|
||||
*/
|
||||
bool HasDemandZone(
|
||||
XCDemandZone *&zone //
|
||||
)
|
||||
{
|
||||
//
|
||||
bool result = false;
|
||||
|
||||
//
|
||||
result = IsBreaked() &&
|
||||
breakDir == X_DIRECTION_BULLISH;
|
||||
if (!result)
|
||||
{
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Implment Zone Finding ...
|
||||
int index = breakerBar.Index();
|
||||
int llIDX = iLowest(
|
||||
symbol,
|
||||
period,
|
||||
MODE_LOW,
|
||||
loopback,
|
||||
index //
|
||||
);
|
||||
result = IsValidIndex(llIDX);
|
||||
if (!result)
|
||||
{
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
XOHCL llBar;
|
||||
result = llBar.Init(
|
||||
symbol,
|
||||
period,
|
||||
llIDX //
|
||||
);
|
||||
if (!result)
|
||||
{
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
zone = new XCDemandZone();
|
||||
result = zone.Init(
|
||||
llBar,
|
||||
loopback //
|
||||
);
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieve Start Time ...
|
||||
*
|
||||
* @return ( datetime )
|
||||
*/
|
||||
datetime From()
|
||||
{
|
||||
//
|
||||
datetime result = NULL;
|
||||
|
||||
//
|
||||
if (!IsValid())
|
||||
{
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
int startIndex = iBarShift(
|
||||
symbol,
|
||||
period,
|
||||
initTime //
|
||||
);
|
||||
|
||||
//
|
||||
result = iTime(
|
||||
symbol,
|
||||
period,
|
||||
loopback + startIndex //
|
||||
);
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieve Unique Identifier ...
|
||||
*
|
||||
* @return ( string )
|
||||
*/
|
||||
string GetTag()
|
||||
{
|
||||
//
|
||||
string result =
|
||||
//
|
||||
"ConsolidationZone" + "_" +
|
||||
symbol + "_" +
|
||||
ToString(period) + "_" +
|
||||
ToString(upper) + "_" +
|
||||
ToString(lower)
|
||||
//
|
||||
;
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
};
|
||||
|
||||
//
|
||||
struct XBoxZone
|
||||
{
|
||||
|
||||
@@ -384,6 +384,11 @@ struct XPOIState
|
||||
XCFVG *bullishFairValueGaps[]; // Holds Founded Bullish Fair Value Gaps ...
|
||||
XCFVG *bearishFairValueGaps[]; // Holds Founded Bearish Fair Value Gaps ...
|
||||
|
||||
//
|
||||
XConsolidationZone consolidationZones[]; // Holds Founded Consolidation Zones ...
|
||||
XConsolidationZone bullishConsolidationZones[]; // Holds Founded Bullish Consolidation Zones ...
|
||||
XConsolidationZone bearishConsolidationZones[]; // Holds Founded Bearih Consolidation Zones ...
|
||||
|
||||
//
|
||||
// Constructor ...
|
||||
void XPOIState()
|
||||
@@ -437,6 +442,11 @@ struct XPOIState
|
||||
Clean(bullishFairValueGaps);
|
||||
Clean(bearishFairValueGaps);
|
||||
|
||||
//
|
||||
Clean(consolidationZones);
|
||||
Clean(bullishConsolidationZones);
|
||||
Clean(bearishConsolidationZones);
|
||||
|
||||
//
|
||||
ZeroMemory(this);
|
||||
}
|
||||
@@ -474,20 +484,22 @@ struct XPOIState
|
||||
//
|
||||
result =
|
||||
//
|
||||
IsValidSize(CountSwingHighs()) ||
|
||||
IsValidSize(CountSwingLows()) ||
|
||||
IsValidSize(CountBullishMomentumBars()) ||
|
||||
IsValidSize(CountBearishMomentumBars()) ||
|
||||
IsValidSize(CountBullishRejectionBars()) ||
|
||||
IsValidSize(CountBearishRejectionBars()) ||
|
||||
IsValidSize(CountSupportZones()) ||
|
||||
IsValidSize(CountResistanceZones()) ||
|
||||
IsValidSize(CountSupplyZones()) ||
|
||||
IsValidSize(CountDemandZones()) ||
|
||||
IsValidSize(CountBullishOrderBlocks()) ||
|
||||
IsValidSize(CountBearishOrderBlocks()) ||
|
||||
IsValidSize(CountBullishFairValueGaps()) ||
|
||||
IsValidSize(CountBearishFairValueGaps())
|
||||
HasSwingLows() ||
|
||||
HasSwingHighs() ||
|
||||
HasSupplyZones() ||
|
||||
HasDemandZones() ||
|
||||
HasSupportZones() ||
|
||||
HasResistanceZones() ||
|
||||
HasBullishOrderBlocks() ||
|
||||
HasBearishOrderBlocks() ||
|
||||
HasBullishMomentumBars() ||
|
||||
HasBearishMomentumBars() ||
|
||||
HasBullishRejectionBars() ||
|
||||
HasBearishRejectionBars() ||
|
||||
HasBullishFairValueGaps() ||
|
||||
HasBearishFairValueGaps() ||
|
||||
HasBullishConsolidationZones() ||
|
||||
HasBearishConsolidationZones()
|
||||
//
|
||||
;
|
||||
|
||||
@@ -495,101 +507,6 @@ struct XPOIState
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Fill Dest State by Current State's Data ...
|
||||
*
|
||||
* @param dest: XPOIState instance, reference to specified dest ...
|
||||
*
|
||||
*/
|
||||
void Fill(XPOIState &dest)
|
||||
{
|
||||
//
|
||||
if (!IsValid() ||
|
||||
!HasChild())
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
//
|
||||
dest.symbol = symbol;
|
||||
dest.period = period;
|
||||
dest.time = time;
|
||||
|
||||
//
|
||||
Copy(
|
||||
swingHighs,
|
||||
dest.swingHighs,
|
||||
false //
|
||||
);
|
||||
Copy(
|
||||
swingLows,
|
||||
dest.swingLows,
|
||||
false //
|
||||
);
|
||||
Copy(
|
||||
bullishMomentumBars,
|
||||
dest.bullishMomentumBars,
|
||||
false //
|
||||
);
|
||||
Copy(
|
||||
bearishMomentumBars,
|
||||
dest.bearishMomentumBars,
|
||||
false //
|
||||
);
|
||||
Copy(
|
||||
bullishRejectionBars,
|
||||
dest.bullishRejectionBars,
|
||||
false //
|
||||
);
|
||||
Copy(
|
||||
bearishRejectionBars,
|
||||
dest.bearishRejectionBars,
|
||||
false //
|
||||
);
|
||||
Copy(
|
||||
supportZones,
|
||||
dest.supportZones,
|
||||
false //
|
||||
);
|
||||
Copy(
|
||||
resistanceZones,
|
||||
dest.resistanceZones,
|
||||
false //
|
||||
);
|
||||
Copy(
|
||||
supplyZones,
|
||||
dest.supplyZones,
|
||||
false //
|
||||
);
|
||||
Copy(
|
||||
demandZones,
|
||||
dest.demandZones,
|
||||
false //
|
||||
);
|
||||
Copy(
|
||||
bullishOrderBlocks,
|
||||
dest.bullishOrderBlocks,
|
||||
false //
|
||||
);
|
||||
Copy(
|
||||
bearishOrderBlocks,
|
||||
dest.bearishOrderBlocks,
|
||||
false //
|
||||
);
|
||||
Copy(
|
||||
bullishFairValueGaps,
|
||||
dest.bullishFairValueGaps,
|
||||
false //
|
||||
);
|
||||
Copy(
|
||||
bearishFairValueGaps,
|
||||
dest.bearishFairValueGaps,
|
||||
false //
|
||||
);
|
||||
|
||||
//
|
||||
}
|
||||
|
||||
//
|
||||
// Counters ...
|
||||
|
||||
@@ -1068,6 +985,42 @@ struct XPOIState
|
||||
return IsValidSize(CountBearishFairValueGaps());
|
||||
}
|
||||
|
||||
//
|
||||
bool HasConsolidationZones()
|
||||
{
|
||||
return HasChild(consolidationZones);
|
||||
}
|
||||
|
||||
//
|
||||
int CountConsolidationZones()
|
||||
{
|
||||
return ArraySize(consolidationZones);
|
||||
}
|
||||
|
||||
//
|
||||
bool HasBullishConsolidationZones()
|
||||
{
|
||||
return HasChild(bullishConsolidationZones);
|
||||
}
|
||||
|
||||
//
|
||||
int CountBullishConsolidationZones()
|
||||
{
|
||||
return ArraySize(bullishConsolidationZones);
|
||||
}
|
||||
|
||||
//
|
||||
bool HasBearishConsolidationZones()
|
||||
{
|
||||
return HasChild(bearishConsolidationZones);
|
||||
}
|
||||
|
||||
//
|
||||
int CountBearishConsolidationZones()
|
||||
{
|
||||
return ArraySize(bearishConsolidationZones);
|
||||
}
|
||||
|
||||
//
|
||||
void UpdateTo(datetime value = NULL)
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user