This commit is contained in:
2025-05-07 23:53:37 +03:30
parent 32f895407f
commit 2ba019e1f0
5 changed files with 746 additions and 49 deletions
+278 -4
View File
@@ -319,6 +319,17 @@ class XCXCAEATradeManager : public XCBaseAlert
drawSignal = true;
drawer = new XCPOIDrawer();
//
allowTrade = true;
allowLongs = true;
allowShorts = true;
//
reportTrades = true;
reportSignals = true;
reportProtector = true;
reportAfterTradesBalance = true;
//
SaveTrades(false);
@@ -362,6 +373,52 @@ class XCXCAEATradeManager : public XCBaseAlert
mSaveTrades = value;
}
//
// TODO: Implement this ...
void SetTradeSession(
string start,
string end //
)
{
//
bool has = IsValid(start) ||
IsValid(end);
if (!has)
{
return;
}
//
}
//
void SetTradeReports(
bool _reportTrades,
bool _reportSignals,
bool _reportProtector,
bool _reportAfterTradesBalance //
)
{
//
reportTrades = _reportTrades;
reportSignals = _reportSignals;
reportProtector = _reportProtector;
reportAfterTradesBalance = _reportAfterTradesBalance;
}
//
void SetTradePermissions(
bool _allowTrade,
bool _allowLongs,
bool _allowShorts //
)
{
//
allowTrade = _allowTrade;
allowLongs = _allowLongs;
allowShorts = _allowShorts;
}
//
// Tools ...
@@ -543,6 +600,7 @@ class XCXCAEATradeManager : public XCBaseAlert
if (iPosition.profit > 0)
{
//
// Handle Risk Free On Targets ...
double targets[];
Copy(
trades[idx].signal.targets,
@@ -624,7 +682,55 @@ class XCXCAEATradeManager : public XCBaseAlert
ToString(iPosition.ticket) +
" RF On Traget: " + ToString(jTarget) +
" Successfully ...";
Alert(message);
HandleReportProtector(message);
}
}
}
}
//
// Handle Partial Close on Specified Targets ...
has = !trades[idx].signal.isPartiallyClosed &&
trades[idx].signal.partialCloseOnTPLevel > 0 &&
trades[idx].signal.partialCloseMultiplier > 0;
if (has)
{
//
// Check Reward Touched ...
double iCurrReward = iPosition.CalculateTouchedReward();
has = iCurrReward >= trades[idx].signal.partialCloseOnTPLevel;
if (has)
{
//
// Check Volume Multiplier ...
double volumeMultiplier = trades[idx].signal.partialCloseMultiplier;
has = volumeMultiplier > 0 &&
volumeMultiplier <= 1;
if (has)
{
//
// Do Partial Closing ...
double volume = iPosition.volume * volumeMultiplier;
string comment = "PC On Target ...";
has = trader.ClosePartial(
iPosition.ticket,
volume,
comment //
);
if (has)
{
//
// Update Model ...
trades[idx].signal.isPartiallyClosed = true;
//
string message = prefix +
ToString(iPosition.type) +
" Position: " +
ToString(iPosition.ticket) +
" PC (" + ToString(volume) + ") On Traget: " + ToString(iCurrReward) +
" Successfully ...";
HandleReportProtector(message);
}
}
}
@@ -633,6 +739,93 @@ class XCXCAEATradeManager : public XCBaseAlert
}
}
/**
* Check Signal Execution Conditions ...
*
* @param signal: XSignal instance reference ...
* @param executionResult: ENUM_X_SIGNAL_EXECUTION_RESULT member reference ...
*
* @return ( bool )
*/
bool CheckSignal(
XSignal &signal,
ENUM_X_SIGNAL_EXECUTION_RESULT &executionResult //
)
{
//
bool result = false;
//
// Cleanup ...
executionResult = X_SIGNAL_EXECUTION_UNKNOWN;
//
// Validate Signal ...
result = signal.IsValid();
if (!result)
{
return result;
}
//
// Reporting Signal ...
if (reportSignals)
{
//
string message = signal.GetMessage();
Alert(message);
}
//
// Check Trade Permission ...
if (!allowTrade)
{
//
result = false;
executionResult = X_SIGNAL_EXECUTION_FAILED_NOT_ALLOWED;
//
return result;
}
//
bool isLong = IsLong(signal.type);
bool isShort = IsShort(signal.type);
//
bool isLongAndAllowed =
isLong &&
allowLongs;
//
bool isShortAndAllowed =
isShort &&
allowShorts;
//
result = isLongAndAllowed ||
isShortAndAllowed;
if (!result)
{
//
executionResult = X_SIGNAL_EXECUTION_FAILED_NOT_ALLOWED;
//
return result;
}
//
// TODO: Complete this ...
// Implementing Trade Session Validating ...
//
// TODO: Complete this ...
// Implementing Trade Permissions Based on SL(s) Count ...
//
return result;
}
/**
* Execute Specified Signal ...
*
@@ -670,15 +863,30 @@ class XCXCAEATradeManager : public XCBaseAlert
//
ENUM_X_SIGNAL_EXECUTION_RESULT executionResult;
result = trader.ExecuteSignal(
//
// Checking Signal For Execution ...
result = CheckSignal(
signal,
executionResult //
);
if (result)
{
//
result = trader.ExecuteSignal(
signal,
executionResult //
);
}
//
// Alert Signal Execution ...
string executionMessage = ToString(executionResult);
Alert(executionMessage);
if (reportTrades)
{
//
string executionMessage = ToString(executionResult);
Alert(executionMessage);
}
//
if (result)
@@ -762,6 +970,11 @@ class XCXCAEATradeManager : public XCBaseAlert
// Save Trade ...
Save(trades[idx]);
//
// Handle Balance Reporting ...
string prefix = "TP: " + ToString(trades[idx].profit);
HandleReportBalance(prefix);
//
RemoveTrade(idx);
}
@@ -800,6 +1013,11 @@ class XCXCAEATradeManager : public XCBaseAlert
// Save Trade ...
Save(trades[idx]);
//
// Handle Balance Reporting ...
string prefix = "SL: " + ToString(trades[idx].profit);
HandleReportBalance(prefix);
//
RemoveTrade(idx);
}
@@ -854,6 +1072,16 @@ class XCXCAEATradeManager : public XCBaseAlert
// Save Trade ...
Save(trades[idx]);
//
// Handle Balance Reporting ...
string prefix = "Force Close " +
(isInProfit
? "Profit"
: "Loss") +
": " +
ToString(trades[idx].profit);
HandleReportBalance(prefix);
//
RemoveTrade(idx);
}
@@ -1045,6 +1273,41 @@ class XCXCAEATradeManager : public XCBaseAlert
return result;
}
//
void HandleReportBalance(string prefix = NULL)
{
//
if (!reportAfterTradesBalance)
{
return;
}
//
double balance = trader.mAccount.GetBalance();
string currency = trader.mAccount.GetCurrency();
//
string message =
(IsValid(prefix)
? prefix + "\n"
: "") +
"Account Balance: " + ToString(balance) + currency;
Alert(message);
}
//
void HandleReportProtector(string message = NULL)
{
//
if (!reportProtector)
{
return;
}
//
Alert(message);
}
//
bool Save(
XCAEATrade &trade,
@@ -1093,6 +1356,11 @@ class XCXCAEATradeManager : public XCBaseAlert
//
// Props ...
//
bool allowTrade;
bool allowLongs;
bool allowShorts;
//
bool mSaveTrades;
@@ -1104,6 +1372,12 @@ class XCXCAEATradeManager : public XCBaseAlert
int managedSLCount;
int managedTPCount;
//
bool reportTrades;
bool reportSignals;
bool reportProtector;
bool reportAfterTradesBalance;
//
CArrayObj mObjects;