complete supply and demand zones ...
This commit is contained in:
@@ -1134,4 +1134,132 @@ class XCResistanceZoneObject : public XCZoneObject
|
||||
}
|
||||
};
|
||||
|
||||
//
|
||||
// Supply Zone ...
|
||||
class XCSupplyZoneObject : public XCZoneObject {
|
||||
//
|
||||
public:
|
||||
//
|
||||
|
||||
/**
|
||||
* Creator ...
|
||||
*
|
||||
* @param chart_id: Long, Specified Chart ID ...
|
||||
* @param window: Integer, Specified Chart Window ID ...
|
||||
* @param zone: XCSupplyZone instance ...
|
||||
* @param prefix: String ...
|
||||
*
|
||||
* @return ( bool )
|
||||
*/
|
||||
bool Create(
|
||||
long chart_id,
|
||||
int window,
|
||||
XCSupplyZone &zone,
|
||||
string prefix = NULL //
|
||||
)
|
||||
{
|
||||
//
|
||||
bool result = false;
|
||||
|
||||
//
|
||||
result = zone.IsValid();
|
||||
if (!result)
|
||||
{
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
string name = zone.GetTag();
|
||||
|
||||
//
|
||||
result = CreateByZone(
|
||||
chart_id,
|
||||
name,
|
||||
window,
|
||||
zone,
|
||||
prefix //
|
||||
);
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Virtual ...
|
||||
|
||||
/**
|
||||
* Retrieve Object Type ...
|
||||
*
|
||||
* @return ( ENUM_XCHARTOBJECTS )
|
||||
*/
|
||||
virtual ENUM_XCHARTOBJECTS Type()
|
||||
{
|
||||
return X_SUPPLY_ZONE_OBJ;
|
||||
}
|
||||
};
|
||||
|
||||
//
|
||||
// Demand Zone ...
|
||||
class XCDemandZoneObject : public XCZoneObject {
|
||||
//
|
||||
public:
|
||||
//
|
||||
|
||||
/**
|
||||
* Creator ...
|
||||
*
|
||||
* @param chart_id: Long, Specified Chart ID ...
|
||||
* @param window: Integer, Specified Chart Window ID ...
|
||||
* @param zone: XCDemandZone instance ...
|
||||
* @param prefix: String ...
|
||||
*
|
||||
* @return ( bool )
|
||||
*/
|
||||
bool Create(
|
||||
long chart_id,
|
||||
int window,
|
||||
XCDemandZone &zone,
|
||||
string prefix = NULL //
|
||||
)
|
||||
{
|
||||
//
|
||||
bool result = false;
|
||||
|
||||
//
|
||||
result = zone.IsValid();
|
||||
if (!result)
|
||||
{
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
string name = zone.GetTag();
|
||||
|
||||
//
|
||||
result = CreateByZone(
|
||||
chart_id,
|
||||
name,
|
||||
window,
|
||||
zone,
|
||||
prefix //
|
||||
);
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Virtual ...
|
||||
|
||||
/**
|
||||
* Retrieve Object Type ...
|
||||
*
|
||||
* @return ( ENUM_XCHARTOBJECTS )
|
||||
*/
|
||||
virtual ENUM_XCHARTOBJECTS Type()
|
||||
{
|
||||
return X_SUPPLY_ZONE_OBJ;
|
||||
}
|
||||
};
|
||||
|
||||
//
|
||||
@@ -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 ...
|
||||
|
||||
@@ -1788,6 +1788,135 @@ class XCPOIDrawer : public XCBase
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Supply and Demand Zones ...
|
||||
|
||||
/**
|
||||
* Create Supply Object ...
|
||||
*
|
||||
* @param zone: XCSupplyZone instance ...
|
||||
* @param object: XCSupplyZoneObject pointer ...
|
||||
*
|
||||
* @return ( bool )
|
||||
*/
|
||||
bool CreateSupplyZone(
|
||||
XCSupplyZone &zone,
|
||||
XCSupplyZoneObject *&object //
|
||||
)
|
||||
{
|
||||
//
|
||||
bool result = false;
|
||||
|
||||
//
|
||||
object = NULL;
|
||||
|
||||
//
|
||||
result =
|
||||
zone.IsValid();
|
||||
if (!result)
|
||||
{
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
string prefix = Prefix();
|
||||
long chartID = ChartIdentification();
|
||||
int window = SubWindowIdentification();
|
||||
|
||||
//
|
||||
bool fill = SupplyZoneFill();
|
||||
int width = SupplyZoneWidth();
|
||||
color crl = SupplyZoneColor();
|
||||
ENUM_LINE_STYLE style = SupplyZoneStyle();
|
||||
|
||||
//
|
||||
object = new XCSupplyZoneObject();
|
||||
result = object.Create(
|
||||
chartID,
|
||||
window,
|
||||
zone,
|
||||
prefix //
|
||||
);
|
||||
|
||||
//
|
||||
if (!result)
|
||||
{
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
object.ZoneFill(fill);
|
||||
object.ZoneColor(crl);
|
||||
object.ZoneWidth(width);
|
||||
object.ZoneStyle(style);
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Create Demand Object ...
|
||||
*
|
||||
* @param zone: XCDemandZone instance ...
|
||||
* @param object: XCDemandZoneObject pointer ...
|
||||
*
|
||||
* @return ( bool )
|
||||
*/
|
||||
bool CreateDemandZone(
|
||||
XCDemandZone &zone,
|
||||
XCDemandZoneObject *&object //
|
||||
)
|
||||
{
|
||||
//
|
||||
bool result = false;
|
||||
|
||||
//
|
||||
object = NULL;
|
||||
|
||||
//
|
||||
result =
|
||||
zone.IsValid();
|
||||
if (!result)
|
||||
{
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
string prefix = Prefix();
|
||||
long chartID = ChartIdentification();
|
||||
int window = SubWindowIdentification();
|
||||
|
||||
//
|
||||
bool fill = DemandZoneFill();
|
||||
int width = DemandZoneWidth();
|
||||
color crl = DemandZoneColor();
|
||||
ENUM_LINE_STYLE style = DemandZoneStyle();
|
||||
|
||||
//
|
||||
object = new XCDemandZoneObject();
|
||||
result = object.Create(
|
||||
chartID,
|
||||
window,
|
||||
zone,
|
||||
prefix //
|
||||
);
|
||||
|
||||
//
|
||||
if (!result)
|
||||
{
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
object.ZoneFill(fill);
|
||||
object.ZoneColor(crl);
|
||||
object.ZoneWidth(width);
|
||||
object.ZoneStyle(style);
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
protected:
|
||||
//
|
||||
@@ -1846,16 +1975,16 @@ class XCPOIDrawer : public XCBase
|
||||
ResistanceZoneColor(clrRed);
|
||||
|
||||
//
|
||||
SupplyZoneFill(true);
|
||||
SupplyZoneFill(false);
|
||||
SupplyZoneWidth(1);
|
||||
SupplyZoneStyle(STYLE_DOT);
|
||||
SupplyZoneColor(clrMagenta);
|
||||
SupplyZoneColor(clrRed);
|
||||
|
||||
//
|
||||
DemandZoneFill(true);
|
||||
DemandZoneFill(false);
|
||||
DemandZoneWidth(1);
|
||||
DemandZoneStyle(STYLE_DOT);
|
||||
DemandZoneColor(clrAqua);
|
||||
DemandZoneColor(clrGreen);
|
||||
|
||||
//
|
||||
BullishOrderBlockFill(true);
|
||||
|
||||
Reference in New Issue
Block a user