complete supply and demand zones ...

This commit is contained in:
2024-11-13 18:42:16 +03:30
parent 797917e30a
commit a4fb541557
4 changed files with 794 additions and 28 deletions
+497 -22
View File
@@ -347,6 +347,36 @@ class XCPOIDetector : public XCBaseAlert
mSupportAndResistanceRange = value;
}
//
// Supply and Demand Zone(s) ...
/**
* Get Supply and Demand Range Verifications ...
*
* @return ( int )
*/
int SupplyAndDemandRange()
{
return mSupplyAndDemandRange;
}
/**
* Set Supply and Demand Range Verifications ...
*
* @param value: Integer ...
*/
void SupplyAndDemandRange(int value)
{
//
if (value < 2)
{
value = 2;
}
//
mSupplyAndDemandRange = value;
}
//
// Actions ...
@@ -676,6 +706,71 @@ class XCPOIDetector : public XCBaseAlert
}
}
//
// Supply And Demand Zones ...
int supDemRange = SupplyAndDemandRange();
if (supDemRange > 0)
{
//
// Supply Zone ...
isDetected = DetectSupplyZone(cBar);
if (isDetected)
{
//
ENUM_XPOI_EVENTS event = X_SUPPLY_ZONE_DETECTED;
XCSupplyZone *param;
bool hasItem = GetLastItem(
param,
mSupplyZones //
);
if (hasItem)
{
//
NotifyEventListeners(
event,
param //
);
}
//
Add(
event,
state //
);
}
//
// Demand Zone ...
isDetected = DetectDemandZone(cBar);
if (isDetected)
{
//
ENUM_XPOI_EVENTS event = X_DEMAND_ZONE_DETECTED;
XCDemandZone *param;
bool hasItem = GetLastItem(
param,
mDemandZones //
);
if (hasItem)
{
//
NotifyEventListeners(
event,
param //
);
}
//
Add(
event,
state //
);
}
}
//
ValidatePOIs(cBar);
//
CleanupUnusedPOIs();
@@ -764,6 +859,10 @@ class XCPOIDetector : public XCBaseAlert
//
Clean(mSupportZones);
Clean(mResistanceZones);
//
Clean(mSupplyZones);
Clean(mDemandZones);
}
/**
@@ -809,6 +908,9 @@ class XCPOIDetector : public XCBaseAlert
//
SupportAndResistanceRange(7);
//
SupplyAndDemandRange(144);
}
//
@@ -877,6 +979,10 @@ class XCPOIDetector : public XCBaseAlert
int supportZonesCount = 0;
int resistanceZonesCount = 0;
//
int supplyZonesCount = 0;
int demandZonesCount = 0;
//
bool canContinue = true;
@@ -947,6 +1053,20 @@ class XCPOIDetector : public XCBaseAlert
ArrayReverse(mResistanceZones);
}
//
supplyZonesCount = DetectRequiredSupplyZones(barIndex);
if (supplyZonesCount == requiredPOIs)
{
ArrayReverse(mSupplyZones);
}
//
demandZonesCount = DetectRequiredDemandZones(barIndex);
if (demandZonesCount == requiredPOIs)
{
ArrayReverse(mDemandZones);
}
//
canContinue =
//
@@ -988,6 +1108,16 @@ class XCPOIDetector : public XCBaseAlert
// Resistance Zones ...
resistanceZonesCount < requiredPOIs
//
||
//
// Supply Zones ...
supplyZonesCount < requiredPOIs
//
||
//
// Demand Zones ...
demandZonesCount < requiredPOIs
//
;
if (canContinue)
{
@@ -1000,6 +1130,15 @@ class XCPOIDetector : public XCBaseAlert
Unlock();
}
/**
* Validate Founded POI(s) ...
*
* @param bar: XOHCL instance ...
*/
void ValidatePOIs(XOHCL &bar)
{
}
/**
* Cleanup Unused Objects ...
*/
@@ -1037,29 +1176,29 @@ class XCPOIDetector : public XCBaseAlert
//
// Swings ...
//
// Swing Highs ...
if (swingHighsCount >= maxAllowed)
{
//
ArrayRemove(
mSwingHighs,
from,
count //
);
}
// //
// // Swing Highs ...
// if (swingHighsCount >= maxAllowed)
// {
// //
// ArrayRemove(
// mSwingHighs,
// from,
// count //
// );
// }
//
// Swing Lows ...
if (swingLowsCount >= maxAllowed)
{
//
ArrayRemove(
mSwingLows,
from,
count //
);
}
// //
// // Swing Lows ...
// if (swingLowsCount >= maxAllowed)
// {
// //
// ArrayRemove(
// mSwingLows,
// from,
// count //
// );
// }
// //
// // Trading Days ...
@@ -2503,11 +2642,347 @@ class XCPOIDetector : public XCBaseAlert
return result;
}
//
// Supply and Demand Zones ...
int mSupplyAndDemandRange; // Supply and Demand Range Verifications ...
//
// Supply Zone(s) ...
XCSupplyZone *mSupplyZones[];
/**
* Detect Supply Zone ...
*
* @param bar: XOHCL instance ...
*
* @return ( bool )
*/
bool DetectSupplyZone(XOHCL &bar)
{
//
bool result = false;
//
result = bar.IsValid();
if (!result)
{
return result;
}
//
int range = SupplyAndDemandRange();
result = range > 0;
if (!result)
{
return result;
}
//
int hhIDX = -1;
double hh = -1;
//
int llIDX = -1;
double ll = -1;
//
result = mBarAnalyser
.CalculateLoopbackHLData(
hhIDX,
hh,
llIDX,
ll,
bar,
range //
);
if (!result)
{
return result;
}
//
XOHCL supplyBar;
result = supplyBar.Init(
bar.symbol,
bar.period,
hhIDX //
);
if (result)
{
//
XCSupplyZone *supply;
supply = new XCSupplyZone();
result = supply.Init(
supplyBar,
range //
);
//
if (result)
{
//
datetime cTime = TimeCurrent();
supply.To(cTime);
//
Add(
supply,
mSupplyZones //
);
// //
// XCSupplyZoneObject *iObj;
// bool isCreated = mDrawer.CreateSupplyZone(
// supply,
// iObj //
// );
// if (isCreated)
// {
// AddObjectIfNotExists(iObj);
// }
}
}
//
return result;
}
/**
* Detect Required Supply Zones ...
*
* @param barIndex: Integer Start bar index ...
* 0 is Default ...
*
* @return ( int )
*/
int DetectRequiredSupplyZones(int barIndex)
{
//
int result = 0;
//
if (barIndex < 0)
{
barIndex = 0;
}
//
int required = MaxNumberOfRequiredPOIs();
if (required <= 0)
{
return result;
}
//
int count = ArraySize(mSupplyZones);
if (count >= required)
{
//
result = count;
return result;
}
//
int range = SupplyAndDemandRange();
if (range < 0)
{
return result;
}
//
string symbol = GetSymbol();
ENUM_TIMEFRAMES period = GetPeriod();
//
XOHCL bar;
bool isInited = bar.Init(
symbol,
period,
barIndex //
);
if (!isInited)
{
return result;
}
//
DetectSupplyZone(bar);
//
result = ArraySize(mSupplyZones);
//
return result;
}
//
// Demand Zone(s) ...
XCDemandZone *mDemandZones[];
/**
* Detect Demand Zone ...
*
* @param bar: XOHCL instance ...
*
* @return ( bool )
*/
bool DetectDemandZone(XOHCL &bar)
{
//
bool result = false;
//
result = bar.IsValid();
if (!result)
{
return result;
}
//
int range = SupplyAndDemandRange();
result = range > 0;
if (!result)
{
return result;
}
//
int hhIDX = -1;
double hh = -1;
//
int llIDX = -1;
double ll = -1;
//
result = mBarAnalyser
.CalculateLoopbackHLData(
hhIDX,
hh,
llIDX,
ll,
bar,
range //
);
if (!result)
{
return result;
}
//
XOHCL demandBar;
result = demandBar.Init(
bar.symbol,
bar.period,
llIDX //
);
if (result)
{
//
XCDemandZone *demand;
demand = new XCDemandZone();
result = demand.Init(
demandBar,
range //
);
//
if (result)
{
//
datetime cTime = TimeCurrent();
demand.To(cTime);
//
Add(
demand,
mDemandZones //
);
// //
// XCDemandZoneObject *iObj;
// bool isCreated = mDrawer.CreateDemandZone(
// demand,
// iObj //
// );
// if (isCreated)
// {
// AddObjectIfNotExists(iObj);
// }
}
}
//
return result;
}
/**
* Detect Required Demand Zones ...
*
* @param barIndex: Integer Start bar index ...
* 0 is Default ...
*
* @return ( int )
*/
int DetectRequiredDemandZones(int barIndex)
{
//
int result = 0;
//
if (barIndex < 0)
{
barIndex = 0;
}
//
int required = MaxNumberOfRequiredPOIs();
if (required <= 0)
{
return result;
}
//
int count = ArraySize(mDemandZones);
if (count >= required)
{
//
result = count;
return result;
}
//
int range = SupplyAndDemandRange();
if (range < 0)
{
return result;
}
//
string symbol = GetSymbol();
ENUM_TIMEFRAMES period = GetPeriod();
//
XOHCL bar;
bool isInited = bar.Init(
symbol,
period,
barIndex //
);
if (!isInited)
{
return result;
}
//
DetectDemandZone(bar);
//
result = ArraySize(mDemandZones);
//
return result;
}
//
// Order Blocks ...