Add Support to Draw Rect on XZoneChart Object ...

This commit is contained in:
2024-10-22 15:44:45 +03:30
parent a6e4d625e4
commit eab3888c88
3 changed files with 313 additions and 50 deletions
+117 -11
View File
@@ -25,6 +25,7 @@
//
#include <ChartObjects/ChartObject.mqh>
#include <ChartObjects/ChartObjectsLines.mqh>
#include <ChartObjects/ChartObjectsShapes.mqh>
//
// Definitions ...
@@ -272,6 +273,8 @@ class XCZoneObject : public CChartObject
* @param lowerPrice1: Double ...
* @param lowerPrice2: Double ...
* @param objprefix: String ...
* @param forceRect: Boolean ...
*
* @return ( bool )
*/
bool Create(
@@ -284,7 +287,8 @@ class XCZoneObject : public CChartObject
const double upperPrice2,
const double lowerPrice1,
const double lowerPrice2,
const string objprefix = NULL //
const string objprefix = NULL,
const bool forceRect = false //
)
{
//
@@ -314,6 +318,32 @@ class XCZoneObject : public CChartObject
? ""
: objprefix + "_";
//
// Check Params For Rectangle ...
bool canDrawRect =
forceRect &&
upperPrice1 == upperPrice2 &&
lowerPrice1 == lowerPrice1;
//
// Draw Rectangle ...
if (canDrawRect)
{
//
result = mRect.Create(
chart_id,
name,
window,
time1,
upperPrice1,
time2,
lowerPrice1 //
);
}
//
// Draw as Trend Line ...
else
{
//
// Upper Bound ...
@@ -357,6 +387,68 @@ class XCZoneObject : public CChartObject
mUpperTrend.Delete();
return result;
}
}
//
return result;
}
/**
* Create XCZoneObject by Providing a XZone ...
*
* @param chart_id: Long ...
* @param name: String ...
* @param window: Integer ...
* @param time1: DateTime ...
* @param time2: DateTime ...
* @param zone: XZone instance ...
* @param objprefix: String ...
* @param forceRect: Boolean ...
*
* @return ( bool )
*/
bool CreateByZone(
long chart_id,
const string name,
const int window,
const datetime time1,
const datetime time2,
const XZone &zone,
const string objprefix = NULL,
const bool forceRect = false //
)
{
//
bool result = false;
//
NormalizeTime(time2);
//
XZone tmpZone = zone;
result =
time1 < time2 &&
IsValid(time1) &&
IsValid(name) &&
tmpZone.IsValid();
if (!result)
{
return result;
}
//
result = Create(
chart_id,
name,
window,
time1,
time2,
zone.upper,
zone.upper,
zone.lower,
zone.lower,
objprefix //
);
//
return result;
@@ -386,6 +478,7 @@ class XCZoneObject : public CChartObject
}
//
mRect.Width(value);
mUpperTrend.Width(value);
mLowerTrend.Width(value);
}
@@ -398,6 +491,7 @@ class XCZoneObject : public CChartObject
void ZoneColor(color value)
{
//
mRect.Color(value);
mUpperTrend.Color(value);
mLowerTrend.Color(value);
}
@@ -410,6 +504,7 @@ class XCZoneObject : public CChartObject
void ZoneStyle(ENUM_LINE_STYLE value)
{
//
mRect.Style(value);
mUpperTrend.Style(value);
mLowerTrend.Style(value);
}
@@ -423,6 +518,7 @@ class XCZoneObject : public CChartObject
//
CChartObjectTrend mUpperTrend;
CChartObjectTrend mLowerTrend;
CChartObjectRectangle mRect;
//
};
@@ -607,6 +703,7 @@ class XCSupportZoneObject : public XCZoneObject
* @param window: Integer ...
* @param support: XOHCL instance ...
* @param time2: DateTime ...
* @param forceRect: Boolean ...
*
* @return ( bool )
*/
@@ -614,22 +711,24 @@ class XCSupportZoneObject : public XCZoneObject
long chart_id,
const string name,
const int window,
XOHCL &support,
datetime time2 //
const XOHCL &support,
const datetime time2,
const bool forceRect = false //
)
{
//
bool result = false;
//
result = support.IsValid();
XOHCL tmpSupport = support;
result = tmpSupport.IsValid();
if (!result)
{
return result;
}
//
double bottom = support.GetDown();
double bottom = tmpSupport.GetDown();
//
result = Create(
@@ -641,7 +740,9 @@ class XCSupportZoneObject : public XCZoneObject
bottom,
bottom,
support.low,
support.low //
support.low,
NULL,
forceRect //
);
//
@@ -689,6 +790,7 @@ class XCResistanceZoneObject : public XCZoneObject
* @param window: Integer ...
* @param resistance: XOHCL instance ...
* @param time2: DateTime ...
* @param forceRect: Boolean ...
*
* @return ( bool )
*/
@@ -696,22 +798,24 @@ class XCResistanceZoneObject : public XCZoneObject
long chart_id,
const string name,
const int window,
XOHCL &resistance,
datetime time2 //
const XOHCL &resistance,
const datetime time2,
const bool forceRect = false //
)
{
//
bool result = false;
//
result = resistance.IsValid();
XOHCL tmpResistance = resistance;
result = tmpResistance.IsValid();
if (!result)
{
return result;
}
//
double up = resistance.GetUp();
double up = tmpResistance.GetUp();
//
result = Create(
@@ -723,7 +827,9 @@ class XCResistanceZoneObject : public XCZoneObject
resistance.high,
resistance.high,
up,
up //
up,
NULL,
forceRect //
);
//
+4 -2
View File
@@ -4383,7 +4383,8 @@ class XCPOI : public XSCBaseAlert
name,
Window(),
bar,
cBarTime //
cBarTime,
true // Force Draw Rect ...
);
if (!isCreated)
{
@@ -4450,7 +4451,8 @@ class XCPOI : public XSCBaseAlert
name,
Window(),
bar,
cBarTime //
cBarTime,
true // Force Draw Rect ...
);
if (!isCreated)
{
+156 -1
View File
@@ -47,6 +47,18 @@ enum ENUM_XPOIS
// Support nad Resistance ...
X_POI_SUPPORT, // Support Zone ...
X_POI_RESISTANCE, // Resistance Zone ...
//
// Supply and Demand Zones ...
X_POI_SUPPLY_ZONE, // Supply Zone ...
X_POI_DEMAND_ZONE, // Demand Zone ...
//
// Order Blocks ...
X_POI_BULLISH_ORDERBLOCK, // Bullish Order Block ...
X_POI_BEARISH_ORDERBLOCK, // Bearish Order Block ...
//
// Fair Value Gaps ...
X_POI_BULLISH_FVG, // Bullish Order Block ...
X_POI_BEARISH_FVG, // Bearish Order Block ...
};
//
@@ -75,6 +87,18 @@ enum ENUM_XPOI_EVENTS
// Support nad Resistance ...
X_SUPPORT_ZONE_DETECTED, // Support Zone ...
X_RESISTANCE_ZONE_DETECTED, // Resistance Zone ...
//
// Supply nad Demand ...
X_SUPPLY_ZONE_DETECTED, // Supply Zone ...
X_DEMAND_ZONE_DETECTED, // Demand Zone ...
//
// Order Blocks ...
X_BULLISH_ORDERBLOCK_DETECTED, // Bullish Order Block ...
X_BEARISH_ORDERBLOCK_DETECTED, // Bearish Order Block ...
//
// Fair Value Gaps ...
X_BULLISH_FVG_DETECTED, // Bullish Fair Value Gapّ ...
X_BEARISH_FVG_DETECTED, // Bearish Fair Value Gapّ ...
};
//
@@ -84,7 +108,8 @@ enum ENUM_XSESSION
X_TOKYO,
X_SYDNEY,
X_LONDON,
X_NEW_YORK
X_NEW_YORK,
X_FRANKFORT,
};
//
@@ -303,6 +328,100 @@ struct XMarketSession
}
};
//
// Zone Struct ...
struct XZone
{
//
// Props ...
double upper;
double lower;
string prefix;
//
// Constructor ...
void XZone()
{
Clean();
}
//
bool Init(
double _upper,
double _lower,
string _prefix //
)
{
//
bool result = false;
//
result =
_upper > 0 &&
_lower > 0 &&
_upper > _lower &&
IsValid(_prefix);
if (!result)
{
return result;
}
//
upper = _upper;
lower = _lower;
prefix = _prefix;
//
result = IsValid();
//
return result;
}
//
void Clean()
{
//
upper = 0;
lower = 0;
//
prefix = NULL;
}
//
bool IsValid()
{
//
bool result = false;
//
result = upper > 0 &&
lower > 0 &&
upper > lower &&
IsValid(prefix);
//
return result;
}
//
string GetTag()
{
//
string result = NULL;
//
result = prefix +
"_XZone_" +
ToString(upper) + "_" +
ToString(lower);
//
return result;
}
};
//
// XOHCL Event Handler ...
typedef void (*TXOHCLEventHandler)(
@@ -322,6 +441,12 @@ typedef void (*TXSessionEventHandler)(
ENUM_XPOI_EVENTS event //
);
//
// Zone Handler ...
typedef void (*TXZoneEventHandler)(
ENUM_XPOI_EVENTS event //
);
//
// Extensions ...
@@ -369,6 +494,36 @@ string ToString(ENUM_XPOIS value)
case X_POI_RESISTANCE:
result = "XRES";
break;
//
case X_POI_SUPPLY_ZONE:
result = "XSUPPLY";
break;
//
case X_POI_DEMAND_ZONE:
result = "XDEMAND";
break;
//
case X_POI_BULLISH_ORDERBLOCK:
result = "XBULLOB";
break;
//
case X_POI_BEARISH_ORDERBLOCK:
result = "XBEAROB";
break;
//
case X_POI_BULLISH_FVG:
result = "XBULLFVG";
break;
//
case X_POI_BEARISH_FVG:
result = "XBEARFVG";
break;
}
//