This commit is contained in:
2025-02-12 00:50:56 +03:30
parent 4a70a3ef4f
commit 44f2a9baba
4 changed files with 112 additions and 28 deletions
@@ -36,19 +36,20 @@
struct X121SMCTradeData
{
//
double ask; // Ask Price on Start Time
double bid; // bid Price on Start Time
ulong ticket; // Position Ticket
double swap; // Swap
double profit; // Profit on Close
XSignal signal; // Signal Object
string message; // Message
datetime endTime; // End Time
datetime startTime; // Start Time
double commission; // Commission
string conditions; // Signal Conditions
double maxDrawdown; // Max Position Drawdown
bool isTargeted; // Check Targetted Before Or Not
double ask; // Ask Price on Start Time
double bid; // bid Price on Start Time
ulong ticket; // Position Ticket
double swap; // Swap
double profit; // Profit on Close
XSignal signal; // Signal Object
string message; // Message
datetime endTime; // End Time
datetime startTime; // Start Time
double commission; // Commission
string conditions; // Signal Conditions
double maxDrawdown; // Max Position Drawdown
bool isTargeted; // Check Targetted Before Or Not
double lastTrailedTPLevel; // Hold Last Trailed TP Level
//
// Constructor ...
@@ -105,6 +106,7 @@ struct X121SMCTradeData
ticket = 0;
commission = 0;
maxDrawdown = 0;
lastTrailedTPLevel = 0;
//
endTime = NULL;
@@ -3453,6 +3455,9 @@ class XC121SMCTradeHandler : public XCBaseAlert
*/
void HandleProtection()
{
//
string prefix = "Protector: ";
//
// Implement Protection Senario Here ...
int count = Count();
@@ -3476,6 +3481,7 @@ class XC121SMCTradeHandler : public XCBaseAlert
double volumeSummary = 0;
double profitSummary = 0;
XPosition positions[];
bool isProtected = false;
//
// Loop through Open Positions ...
@@ -3514,13 +3520,22 @@ class XC121SMCTradeHandler : public XCBaseAlert
//
double tps[];
double reachedTPLevel = -1;
int reachedTPIndex = -1;
double reachedTPPrice = 0;
double reachedTPLevel = -1;
int tpLevelsCount = iPosition.CalculateTPLevels(tps);
iPosition.CalculateReahedTP(
reachedTPLevel,
reachedTPPrice //
);
if (reachedTPLevel > 0)
{
//
reachedTPIndex = FindIndex(
reachedTPPrice,
tps //
);
}
//
bepSummary += bep;
@@ -3558,7 +3573,11 @@ class XC121SMCTradeHandler : public XCBaseAlert
if (isModified)
{
//
string message = ToString(iData.Type()) +
isProtected = true;
//
string message = prefix +
ToString(iData.Type()) +
" Position: " +
ToString(iData.ticket) +
" RF On BEP Successfully ...";
@@ -3594,7 +3613,11 @@ class XC121SMCTradeHandler : public XCBaseAlert
if (isModified)
{
//
string message = ToString(iData.Type()) +
isProtected = true;
//
string message = prefix +
ToString(iData.Type()) +
" Position: " +
ToString(iData.ticket) +
" PC (" + ToString(closeVolume) + ") On TP Level: " +
@@ -3624,15 +3647,46 @@ class XC121SMCTradeHandler : public XCBaseAlert
bool canTrailSL = iData.CanTrailSL();
if (canTrailSL && reachedTPLevel > 0)
{
//
double tSLTPPrice = 0;
//
double startTrailTPLevel = iData.TrailSLStartOnReachTPLevel();
int tSLTPIndex = (int)reachedTPLevel - 1;
double tSLTPPrice = tps[tSLTPIndex];
canTrailSL =
reachedTPLevel >= startTrailTPLevel &&
(isLong
? iPosition.sl < tSLTPPrice
: iPosition.sl > tSLTPPrice);
if (iData.lastTrailedTPLevel > 0)
{
startTrailTPLevel = iData.lastTrailedTPLevel + 1;
}
//
canTrailSL = IsValidIndex(reachedTPIndex) &&
reachedTPLevel >= startTrailTPLevel;
if (canTrailSL)
{
//
tSLTPPrice =
reachedTPIndex == 0
? tps[reachedTPIndex]
: tps[reachedTPIndex - 1];
//
canTrailSL =
tSLTPPrice > 0 &&
iPosition.sl == 0
? (isLong
? tSLTPPrice > iPosition.entry &&
tSLTPPrice < iPosition.price
: tSLTPPrice < iPosition.entry &&
tSLTPPrice > iPosition.price)
: (isLong
? tSLTPPrice > iPosition.sl &&
tSLTPPrice > iPosition.entry &&
tSLTPPrice < iPosition.price
: tSLTPPrice < iPosition.sl &&
tSLTPPrice < iPosition.entry &&
tSLTPPrice > iPosition.price);
}
//
if (canTrailSL)
{
//
@@ -3648,7 +3702,15 @@ class XC121SMCTradeHandler : public XCBaseAlert
if (isModified)
{
//
string message = ToString(iData.Type()) +
isProtected = true;
//
// Update Last Trailed TP Level ...
mData[i].lastTrailedTPLevel = reachedTPLevel;
//
string message = prefix +
ToString(iData.Type()) +
" Position: " +
ToString(iData.ticket) +
" Trailed SL On Reached TP: " + ToString(reachedTPLevel) +
@@ -3690,10 +3752,15 @@ class XC121SMCTradeHandler : public XCBaseAlert
if (isModified)
{
//
isProtected = true;
//
// Update mData ...
mData[i].isTargeted = true;
//
string message = ToString(iData.Type()) +
string message = prefix +
ToString(iData.Type()) +
" Position: " +
ToString(iData.ticket) +
" RF On Traget: " + ToString(target) +
@@ -3722,7 +3789,8 @@ class XC121SMCTradeHandler : public XCBaseAlert
//
// Checking Hedge ...
bool allowHedge = AllowHedging();
bool allowHedge = AllowHedging() &&
!isProtected;
if (allowHedge)
{
//