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 ...
|
||||
*
|
||||
|
||||
@@ -1594,9 +1594,9 @@ class XCConsolidationZoneObject : public XCBaseObject
|
||||
chart_id,
|
||||
name,
|
||||
window,
|
||||
zone.From(),
|
||||
zone.from,
|
||||
zone.upper,
|
||||
TimeCurrent(),
|
||||
zone.to,
|
||||
zone.lower //
|
||||
);
|
||||
|
||||
|
||||
@@ -405,6 +405,100 @@ class XCPOIDetector : public XCBaseAlert
|
||||
mFairValueGapSameBars = value;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get Minimum Length of Cnsolidation Zone ...
|
||||
*
|
||||
* @return ( int )
|
||||
*/
|
||||
int ConsolidationZoneMinLoopback()
|
||||
{
|
||||
return mConsolidationZoneMinLoopback;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set Minimum Length of Cnsolidation Zone ...
|
||||
*
|
||||
* @param value: int ...
|
||||
*/
|
||||
void ConsolidationZoneMinLoopback(int value)
|
||||
{
|
||||
//
|
||||
if (value < 1)
|
||||
{
|
||||
value = 1;
|
||||
}
|
||||
|
||||
//
|
||||
mConsolidationZoneMinLoopback = value;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get Consolidation Zone Range in Point ...
|
||||
*
|
||||
* @return ( double )
|
||||
*/
|
||||
double ConsolidationZoneRangeInPoint()
|
||||
{
|
||||
return mConsolidationZoneRangeInPoint;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set Consolidation Zone Range in Point ...
|
||||
*
|
||||
* @param value: double
|
||||
*/
|
||||
void ConsolidationZoneRangeInPoint(double value)
|
||||
{
|
||||
//
|
||||
if (value < 50)
|
||||
{
|
||||
value = 50;
|
||||
}
|
||||
|
||||
//
|
||||
mConsolidationZoneRangeInPoint = value;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get Consolidation Zone Upper Applied To ...
|
||||
*
|
||||
* @return ( ENUM_APPLIED_PRICE )
|
||||
*/
|
||||
ENUM_APPLIED_PRICE ConsolidationZonesLowerAppliedTo()
|
||||
{
|
||||
return mConsolidationZonesLowerAppliedTo;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set Consolidation Zone Upper Applied To ...
|
||||
*
|
||||
* @param value: ENUM_APPLIED_PRICE
|
||||
*/
|
||||
void ConsolidationZonesLowerAppliedTo(ENUM_APPLIED_PRICE value = PRICE_LOW)
|
||||
{
|
||||
mConsolidationZonesLowerAppliedTo = value;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get Consolidation Zone Lower Applied To ...
|
||||
*
|
||||
* @return ( ENUM_APPLIED_PRICE )
|
||||
*/
|
||||
ENUM_APPLIED_PRICE ConsolidationZonesUpperAppliedTo()
|
||||
{
|
||||
return mConsolidationZonesUpperAppliedTo;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set Consolidation Zone Lower Applied To ...
|
||||
*
|
||||
* @param value: ENUM_APPLIED_PRICE
|
||||
*/
|
||||
void ConsolidationZonesUpperAppliedTo(ENUM_APPLIED_PRICE value = PRICE_HIGH)
|
||||
{
|
||||
mConsolidationZonesUpperAppliedTo = value;
|
||||
}
|
||||
|
||||
//
|
||||
// Actions ...
|
||||
|
||||
@@ -426,6 +520,10 @@ class XCPOIDetector : public XCBaseAlert
|
||||
SupResRangeAsStart(true);
|
||||
RejectionShadowPercent(70);
|
||||
MaxAllowedLoopbackForInit(578);
|
||||
ConsolidationZoneMinLoopback(5);
|
||||
ConsolidationZoneRangeInPoint(50);
|
||||
ConsolidationZonesLowerAppliedTo(PRICE_LOW);
|
||||
ConsolidationZonesUpperAppliedTo(PRICE_HIGH);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -560,6 +658,14 @@ class XCPOIDetector : public XCBaseAlert
|
||||
false //
|
||||
);
|
||||
|
||||
//
|
||||
// Consolidation Zone ...
|
||||
DetectConsolidationZone(
|
||||
iBar,
|
||||
iEvent,
|
||||
false //
|
||||
);
|
||||
|
||||
//
|
||||
canContinue =
|
||||
has &&
|
||||
@@ -1027,6 +1133,20 @@ class XCPOIDetector : public XCBaseAlert
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
has = DetectConsolidationZone(
|
||||
iBar,
|
||||
iEvent //
|
||||
);
|
||||
if (has)
|
||||
{
|
||||
//
|
||||
Add(
|
||||
iEvent,
|
||||
events //
|
||||
);
|
||||
}
|
||||
|
||||
//
|
||||
iBar.Clean();
|
||||
mLock = false;
|
||||
@@ -1169,6 +1289,24 @@ class XCPOIDetector : public XCBaseAlert
|
||||
state.bearishFairValueGaps //
|
||||
);
|
||||
|
||||
//
|
||||
Copy(
|
||||
mConsolidationZones,
|
||||
state.consolidationZones //
|
||||
);
|
||||
|
||||
//
|
||||
Copy(
|
||||
mBullishConsolidationZones,
|
||||
state.bullishConsolidationZones //
|
||||
);
|
||||
|
||||
//
|
||||
Copy(
|
||||
mBearishConsolidationZones,
|
||||
state.bearishConsolidationZones //
|
||||
);
|
||||
|
||||
//
|
||||
}
|
||||
|
||||
@@ -1193,51 +1331,58 @@ class XCPOIDetector : public XCBaseAlert
|
||||
void CleanCollections()
|
||||
{
|
||||
//
|
||||
Clean(mEventListeners);
|
||||
Clean(mSwings);
|
||||
Clean(mSwingLows);
|
||||
Clean(mSwingHighs);
|
||||
Clean(mMomentumBars);
|
||||
Clean(mBullishMomentumBars);
|
||||
Clean(mBearishMomentumBars);
|
||||
Clean(mRejectionBars);
|
||||
Clean(mBullishRejectionBars);
|
||||
Clean(mBearishRejectionBars);
|
||||
Clean(mSupportZones);
|
||||
Clean(mDemandZones);
|
||||
Clean(mSupplyZones);
|
||||
Clean(mResistanceZones);
|
||||
Clean(mFairValueGaps);
|
||||
Clean(mBullishFairValueGaps);
|
||||
Clean(mBearishFairValueGaps);
|
||||
Clean(mOrderBlocks);
|
||||
Clean(mMomentumBars);
|
||||
Clean(mSupportZones);
|
||||
Clean(mRejectionBars);
|
||||
Clean(mFairValueGaps);
|
||||
Clean(mEventListeners);
|
||||
Clean(mResistanceZones);
|
||||
Clean(mBullishOrderBlocks);
|
||||
Clean(mBearishOrderBlocks);
|
||||
Clean(mConsolidationZones);
|
||||
Clean(mBullishMomentumBars);
|
||||
Clean(mBearishMomentumBars);
|
||||
Clean(mBullishRejectionBars);
|
||||
Clean(mBearishRejectionBars);
|
||||
Clean(mBullishFairValueGaps);
|
||||
Clean(mBearishFairValueGaps);
|
||||
Clean(mBullishConsolidationZones);
|
||||
Clean(mBearishConsolidationZones);
|
||||
}
|
||||
|
||||
//
|
||||
void ReverseCollections() {
|
||||
void ReverseCollections()
|
||||
{
|
||||
//
|
||||
ArrayReverse(mEventListeners);
|
||||
ArrayReverse(mSwings);
|
||||
ArrayReverse(mSwingLows);
|
||||
ArrayReverse(mSwingHighs);
|
||||
ArrayReverse(mMomentumBars);
|
||||
ArrayReverse(mBullishMomentumBars);
|
||||
ArrayReverse(mBearishMomentumBars);
|
||||
ArrayReverse(mRejectionBars);
|
||||
ArrayReverse(mBullishRejectionBars);
|
||||
ArrayReverse(mBearishRejectionBars);
|
||||
ArrayReverse(mSupportZones);
|
||||
ArrayReverse(mDemandZones);
|
||||
ArrayReverse(mSupplyZones);
|
||||
ArrayReverse(mResistanceZones);
|
||||
ArrayReverse(mFairValueGaps);
|
||||
ArrayReverse(mBullishFairValueGaps);
|
||||
ArrayReverse(mBearishFairValueGaps);
|
||||
ArrayReverse(mOrderBlocks);
|
||||
ArrayReverse(mMomentumBars);
|
||||
ArrayReverse(mSupportZones);
|
||||
ArrayReverse(mRejectionBars);
|
||||
ArrayReverse(mFairValueGaps);
|
||||
ArrayReverse(mEventListeners);
|
||||
ArrayReverse(mResistanceZones);
|
||||
ArrayReverse(mBullishOrderBlocks);
|
||||
ArrayReverse(mBearishOrderBlocks);
|
||||
ArrayReverse(mConsolidationZones);
|
||||
ArrayReverse(mBullishMomentumBars);
|
||||
ArrayReverse(mBearishMomentumBars);
|
||||
ArrayReverse(mBullishRejectionBars);
|
||||
ArrayReverse(mBearishRejectionBars);
|
||||
ArrayReverse(mBullishFairValueGaps);
|
||||
ArrayReverse(mBearishFairValueGaps);
|
||||
ArrayReverse(mBullishConsolidationZones);
|
||||
ArrayReverse(mBearishConsolidationZones);
|
||||
}
|
||||
|
||||
//
|
||||
@@ -1374,6 +1519,24 @@ class XCPOIDetector : public XCBaseAlert
|
||||
maxAllowed //
|
||||
);
|
||||
|
||||
//
|
||||
CleanupArray(
|
||||
mConsolidationZones,
|
||||
maxAllowed //
|
||||
);
|
||||
|
||||
//
|
||||
CleanupArray(
|
||||
mBullishConsolidationZones,
|
||||
maxAllowed //
|
||||
);
|
||||
|
||||
//
|
||||
CleanupArray(
|
||||
mBearishConsolidationZones,
|
||||
maxAllowed //
|
||||
);
|
||||
|
||||
//
|
||||
}
|
||||
|
||||
@@ -2928,6 +3091,160 @@ class XCPOIDetector : public XCBaseAlert
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Detect Consolidation Zones ...
|
||||
*
|
||||
* @param bar: XOHCL instance ...
|
||||
* @param reversal: boolean reversal add to collection ...
|
||||
*
|
||||
* @return ( bool )
|
||||
*/
|
||||
bool DetectConsolidationZone(
|
||||
XOHCL &bar,
|
||||
ENUM_XPOI_EVENTS &state,
|
||||
bool reversal = false //
|
||||
)
|
||||
{
|
||||
//
|
||||
bool result = false;
|
||||
|
||||
//
|
||||
state = X_POI_EVENT_NONE;
|
||||
|
||||
//
|
||||
XConsolidationZone cZone;
|
||||
result = mBarAnalyser.HasConsolidationZone(
|
||||
bar,
|
||||
cZone,
|
||||
mConsolidationZoneMinLoopback,
|
||||
mConsolidationZoneRangeInPoint,
|
||||
mConsolidationZonesUpperAppliedTo,
|
||||
mConsolidationZonesLowerAppliedTo //
|
||||
);
|
||||
if (!result)
|
||||
{
|
||||
//
|
||||
cZone.Clean();
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Add ...
|
||||
|
||||
//
|
||||
bool isBullish = IsBullish(cZone.dir);
|
||||
bool isBearish = IsBearish(cZone.dir);
|
||||
|
||||
//
|
||||
int idx = FindIndex(
|
||||
cZone,
|
||||
mConsolidationZones //
|
||||
);
|
||||
result = !IsValidIndex(idx);
|
||||
if (!result)
|
||||
{
|
||||
//
|
||||
cZone.Clean();
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
if (reversal)
|
||||
{
|
||||
//
|
||||
ArrayReverse(mConsolidationZones);
|
||||
|
||||
//
|
||||
AddRef(
|
||||
cZone,
|
||||
mConsolidationZones //
|
||||
);
|
||||
|
||||
//
|
||||
ArrayReverse(mConsolidationZones);
|
||||
}
|
||||
else
|
||||
{
|
||||
//
|
||||
AddRef(
|
||||
cZone,
|
||||
mConsolidationZones //
|
||||
);
|
||||
}
|
||||
|
||||
//
|
||||
if (isBullish)
|
||||
{
|
||||
//
|
||||
// Add Swings ...
|
||||
if (reversal)
|
||||
{
|
||||
//
|
||||
ArrayReverse(mBullishConsolidationZones);
|
||||
|
||||
//
|
||||
AddRef(
|
||||
cZone,
|
||||
mBullishConsolidationZones //
|
||||
);
|
||||
|
||||
//
|
||||
ArrayReverse(mBullishConsolidationZones);
|
||||
}
|
||||
else
|
||||
{
|
||||
//
|
||||
AddRef(
|
||||
cZone,
|
||||
mBullishConsolidationZones //
|
||||
);
|
||||
}
|
||||
}
|
||||
else if (isBearish)
|
||||
{
|
||||
//
|
||||
// Add Swings ...
|
||||
if (reversal)
|
||||
{
|
||||
//
|
||||
ArrayReverse(mBearishConsolidationZones);
|
||||
|
||||
//
|
||||
AddRef(
|
||||
cZone,
|
||||
mBearishConsolidationZones //
|
||||
);
|
||||
|
||||
//
|
||||
ArrayReverse(mBearishConsolidationZones);
|
||||
}
|
||||
else
|
||||
{
|
||||
//
|
||||
AddRef(
|
||||
cZone,
|
||||
mBearishConsolidationZones //
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
state =
|
||||
IsBullish(cZone.dir)
|
||||
? X_BULLISH_CONSOLIDATION_ZONE_DETECTED
|
||||
: X_BEARISH_CONSOLIDATION_ZONE_DETECTED;
|
||||
|
||||
//
|
||||
cZone.Clean();
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
private:
|
||||
//
|
||||
@@ -2991,6 +3308,15 @@ class XCPOIDetector : public XCBaseAlert
|
||||
XCOrderBlock *mBearishOrderBlocks[]; // Holds Founded Bearish OrderBlocks ...
|
||||
int mOrderBlockSameBars; // OrderBlock Detection Same Bars ...
|
||||
|
||||
//
|
||||
int mConsolidationZoneMinLoopback; // Minimum Length of Cnsolidation Zone ...
|
||||
double mConsolidationZoneRangeInPoint; // Consolidation Zone Range in Point ...
|
||||
XConsolidationZone mConsolidationZones[]; // Holds Founded Consolidation Zones ...
|
||||
XConsolidationZone mBullishConsolidationZones[]; // Holds Founded Bullish Consolidation Zones ...
|
||||
XConsolidationZone mBearishConsolidationZones[]; // Holds Founded Bearish Consolidation Zones ...
|
||||
ENUM_APPLIED_PRICE mConsolidationZonesLowerAppliedTo; // Consolidation Zone Upper Applied To ...
|
||||
ENUM_APPLIED_PRICE mConsolidationZonesUpperAppliedTo; // Consolidation Zone Lower Applied To ...
|
||||
|
||||
//
|
||||
};
|
||||
|
||||
|
||||
@@ -2964,7 +2964,7 @@ class XCPOIDrawer : public XCBase
|
||||
int window = SubWindowIdentification();
|
||||
|
||||
//
|
||||
color czColor = IsBullish(zone.breakDir)
|
||||
color czColor = IsBullish(zone.dir)
|
||||
? BarBullishColor()
|
||||
: BarBearishColor();
|
||||
|
||||
@@ -3460,7 +3460,9 @@ class XCPOIDrawer : public XCBase
|
||||
bool ignoreBullishRejectionBars = false,
|
||||
bool ignoreBearishRejectionBars = false,
|
||||
bool ignoreBullishMomentumBars = false,
|
||||
bool ignoreBearishMomentumBars = false //
|
||||
bool ignoreBearishMomentumBars = false,
|
||||
bool ignoreBullishConsolidationZones = false,
|
||||
bool ignoreBearishConsolidationZones = false //
|
||||
)
|
||||
{
|
||||
//
|
||||
@@ -3924,6 +3926,64 @@ class XCPOIDrawer : public XCBase
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
// Bullish Consolidation Zones ...
|
||||
if (!ignoreBullishConsolidationZones)
|
||||
{
|
||||
//
|
||||
int count = state.CountBullishConsolidationZones();
|
||||
if (IsValidSize(count))
|
||||
{
|
||||
//
|
||||
for (int i = 0; i < count; i++)
|
||||
{
|
||||
//
|
||||
XCConsolidationZoneObject *iObj;
|
||||
bool isCreated = CreateConsolidationZone(
|
||||
state.bullishConsolidationZones[i],
|
||||
iObj //
|
||||
);
|
||||
if (isCreated)
|
||||
{
|
||||
//
|
||||
Add(
|
||||
(XCBaseObject *)iObj,
|
||||
drawnObjects //
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
// Bearish Consolidation Zones ...
|
||||
if (!ignoreBearishConsolidationZones)
|
||||
{
|
||||
//
|
||||
int count = state.CountBearishConsolidationZones();
|
||||
if (IsValidSize(count))
|
||||
{
|
||||
//
|
||||
for (int i = 0; i < count; i++)
|
||||
{
|
||||
//
|
||||
XCConsolidationZoneObject *iObj;
|
||||
bool isCreated = CreateConsolidationZone(
|
||||
state.bearishConsolidationZones[i],
|
||||
iObj //
|
||||
);
|
||||
if (isCreated)
|
||||
{
|
||||
//
|
||||
Add(
|
||||
(XCBaseObject *)iObj,
|
||||
drawnObjects //
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
result = ArraySize(drawnObjects);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user