This commit is contained in:
2025-01-04 00:01:22 +03:30
parent 6e03d6d993
commit fbc232a2b7
4 changed files with 331 additions and 42 deletions
@@ -3311,6 +3311,79 @@ class XC121SMCTradeHandler : public XCBaseAlert
return result;
}
/**
* Force Close Specified Positions ...
*
* @param symbol: String ...
* @param provider: String ...
* @param period: ENUM_TIMEFRAMES member ...
* @param type: ENUM_X_POSITION_TYPES member ...
*
* @return ( bool )
*/
bool ForceClose(
string symbol = NULL,
string provider = NULL,
ENUM_TIMEFRAMES period = NULL,
ENUM_X_POSITION_TYPES type = NULL //
)
{
//
bool result = false;
//
XPosition positions[];
int count = mTrader.GetPositions(
positions,
symbol,
provider,
period,
type //
);
result = IsValidSize(count);
if (!result)
{
return result;
}
//
datetime cTime = TimeCurrent();
//
string comment = "Force Close (" + ToString(count) + ") Positions At: " + ToFormatString(cTime) + "...";
int closedPositionsCount = mTrader.Close(
positions,
comment //
);
result = IsValidSize(closedPositionsCount);
if (result)
{
//
// Finish Positions and Clear Data ...
for (int i = 0; i < ArraySize(positions); i++)
{
//
XPosition iPosition = positions[i];
Finish(
iPosition.ticket,
iPosition,
comment //
);
}
//
ResetProtections();
//
string message = "Force Close (" + ToString(count) + ") Positions At: " +
ToFormatString(cTime) + " Successfully ...";
Alert(message);
}
//
return result;
}
//
// Timing Actions ...