This commit is contained in:
2025-05-09 11:51:37 +03:30
parent b3be1b4596
commit bffe99a008
4 changed files with 162 additions and 21 deletions
+87 -3
View File
@@ -613,6 +613,10 @@ class XCXCAEATradeManager : public XCBaseAlert
allowLongs = true;
allowShorts = true;
//
forceCloseAt = NULL;
isForceCloseAtTime = false;
//
maxAllowedTPs = 0;
maxAllowedSLs = 0;
@@ -671,6 +675,14 @@ class XCXCAEATradeManager : public XCBaseAlert
mSaveTrades = value;
}
//
void SetForceCloseTradesAt(
string _forceCloseAt //
)
{
forceCloseAt = _forceCloseAt;
}
//
void SetTradeSession(
string symbol,
@@ -955,7 +967,28 @@ class XCXCAEATradeManager : public XCBaseAlert
//
// Do Collection Protectiong ...
// TODO: Implement this ...
//
// Check Force Close ...
if (IsValid(forceCloseAt))
{
//
datetime forceCloseTime = ParseDateTimeFromTimeString(forceCloseAt);
bool canForceClose = IsTimeInRange(
TimeCurrent(),
forceCloseTime //
) &&
!isForceCloseAtTime;
if (canForceClose)
{
//
isForceCloseAtTime = HandleForceCloseTrades(ownPosition);
//
// Prevent Moving Forward ...
return;
}
}
//
// Do Signle Protections ...
@@ -1224,10 +1257,12 @@ class XCXCAEATradeManager : public XCBaseAlert
//
// Chack Trade Session Validating ...
if (isSymbolSessionExists) {
if (isSymbolSessionExists)
{
//
result = sessions[symbolSessionIDX].CanTrade();
if (!result) {
if (!result)
{
//
executionResult = X_SIGNAL_EXECUTION_FAILED_DELAY_NOT_PASSED;
@@ -1620,6 +1655,44 @@ class XCXCAEATradeManager : public XCBaseAlert
RemoveTrade(idx);
}
/**
* Handle Force Close Trades ...
*/
bool HandleForceCloseTrades(
XPosition &positions[] //
)
{
//
bool result = false;
//
result = HasChild(positions);
if (!result)
{
return result;
}
//
string prefix = "Protector: ";
string comment = "Force Close ...";
//
int closedsCount = trader.Close(
positions,
comment //
);
result = IsValidSize(closedsCount);
if (result)
{
//
string message = prefix + "Force Close (" + ToString(closedsCount) + ") Trades at Specified Time ...";
HandleReportProtector(message);
}
//
return result;
}
//
// TODO: Complete this ...
void HandleGuard()
@@ -2040,6 +2113,13 @@ class XCXCAEATradeManager : public XCBaseAlert
bool isNewWeek = timeTracker.IsNewWeek();
bool isNewMonth = timeTracker.IsNewMonth();
//
// Reset Force Closed Flag on new Day Starts ...
if (isNewDay)
{
isForceCloseAtTime = false;
}
//
bool canResetRestrictions =
(
@@ -2174,6 +2254,10 @@ class XCXCAEATradeManager : public XCBaseAlert
bool allowLongs;
bool allowShorts;
//
string forceCloseAt;
bool isForceCloseAtTime;
//
int maxAllowedTPs;
int maxAllowedSLs;