add Guard Event and Attached it to all Realted Classes till Final Handler in eaTradeManager ...

This commit is contained in:
2025-09-11 14:54:31 +03:30
parent 07d56d4f8b
commit 5eaeb13087
4 changed files with 452 additions and 246 deletions
+128 -1
View File
@@ -160,6 +160,12 @@ struct XGuard
}
};
//
// an Event Type for Notify Guard Triggered ...
typedef void (*TOnGuarded)(
ENUM_X_GUARD_ACTIONS guard,
XPosition &positions[]);
//
// Extensions ...
@@ -226,6 +232,7 @@ class XCGuard : public XCBase
// Props ...
double minVolumeFactorForHedge; // Minimum Volume Factor for Hedge Profit Calculation ...
double minProfitPerVolumeFactorForHedge; // Minimum Required Profit per Volume Factor for Hedg ...
TOnGuarded onGuardEventListener; // On Guard Event Listener ...
//
// Constructor(s) ...
@@ -1005,6 +1012,9 @@ class XCGuard : public XCBase
);
if (has)
{
//
HandleNotifyPositionGuard(guard.action, position);
//
string message =
"Guard Closed " +
@@ -1070,6 +1080,9 @@ class XCGuard : public XCBase
);
if (has)
{
//
HandleNotifyPositionsGuard(guard.action, positions);
//
string message =
"Guard Closed " +
@@ -1135,6 +1148,9 @@ class XCGuard : public XCBase
);
if (has)
{
//
HandleNotifyPositionsGuard(guard.action, positions);
//
string message =
"Guard Closed " +
@@ -1200,6 +1216,9 @@ class XCGuard : public XCBase
);
if (has)
{
//
HandleNotifyPositionsGuard(guard.action, positions);
//
string message =
"Guard Closed " +
@@ -1265,6 +1284,9 @@ class XCGuard : public XCBase
);
if (has)
{
//
HandleNotifyPositionsGuard(guard.action, positions);
//
string message =
"Guard Closed " +
@@ -1330,6 +1352,9 @@ class XCGuard : public XCBase
);
if (has)
{
//
HandleNotifyPositionsGuard(guard.action, positions);
//
string message =
"Guard Closed " +
@@ -1395,6 +1420,9 @@ class XCGuard : public XCBase
);
if (has)
{
//
HandleNotifyPositionsGuard(guard.action, positions);
//
string message =
"Guard Closed " +
@@ -1426,7 +1454,50 @@ class XCGuard : public XCBase
}
//
// Do What we want ...
// Retrieve Positions ...
XPosition positions[];
int count = GetShortPositions(
positions,
guard //
);
has = IsValidSize(count);
if (!has)
{
//
Clean(positions);
//
return;
}
//
string comment = "Guard Close Shorts ...";
//
has = trader.Close(
positions,
comment //
);
if (has)
{
//
HandleNotifyPositionsGuard(guard.action, positions);
//
string message =
"Guard Closed " +
ToXString(count) +
" Long Positions Successfully ...";
//
alert.SendAlert(message);
}
//
// Cleanup Resources ...
//
Clean(positions);
}
//
@@ -1477,6 +1548,9 @@ class XCGuard : public XCBase
);
if (has)
{
//
HandleNotifyPositionsGuard(guard.action, positions);
//
string message =
"Guard Closed " +
@@ -1542,6 +1616,10 @@ class XCGuard : public XCBase
);
if (has)
{
//
HandleNotifyPositionsGuard(guard.action, positions);
//
//
string message =
"Guard Closed " +
@@ -1633,6 +1711,9 @@ class XCGuard : public XCBase
);
if (has)
{
//
HandleNotifyPositionGuard(guard.action, position);
//
string message =
"Guard Closed Partially " +
@@ -1736,6 +1817,9 @@ class XCGuard : public XCBase
);
if (has)
{
//
HandleNotifyPositionGuard(guard.action, position);
//
double before = NormalizePrice(position.sl, position.symbol);
double after = NormalizePrice(guard.sl, position.symbol);
@@ -1841,6 +1925,9 @@ class XCGuard : public XCBase
);
if (has)
{
//
HandleNotifyPositionGuard(guard.action, position);
//
double before = NormalizePrice(position.tp, position.symbol);
double after = NormalizePrice(guard.tp, position.symbol);
@@ -1981,6 +2068,9 @@ class XCGuard : public XCBase
has = IsValidSize(closedCount);
if (has)
{
//
HandleNotifyPositionsGuard(guard.action, positions);
//
string message =
"Guard Hedge " +
@@ -2007,6 +2097,43 @@ class XCGuard : public XCBase
XCTrade *trader;
XCAlert *alert;
//
void HandleNotifyPositionGuard(
ENUM_X_GUARD_ACTIONS action,
XPosition &position //
)
{
//
if (!IsSpecifiedValid(action) || !position.IsValid() || onGuardEventListener == NULL)
{
return;
}
//
XPosition positions[];
AddRef(
position,
positions //
);
HandleNotifyPositionsGuard(action, positions);
}
//
void HandleNotifyPositionsGuard(
ENUM_X_GUARD_ACTIONS action,
XPosition &positions[] //
)
{
//
if (!IsSpecifiedValid(action) || !HasChild(positions) || onGuardEventListener == NULL)
{
return;
}
//
onGuardEventListener(action, positions);
}
//
};