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
+12 -1
View File
@@ -5471,4 +5471,15 @@ else if (isPriceInsideDemandZone)
{ {
} }
///////////////////////////////////////////////////////// /////////////////////////////////////////////////////////
int tSLTPIndex = (int)reachedTPLevel - 1;
double tSLTPPrice = tps[tSLTPIndex];
canTrailSL =
reachedTPLevel >= startTrailTPLevel &&
(isLong
? iPosition.sl < tSLTPPrice
: iPosition.sl > tSLTPPrice);
/////////////////////////////////////////////////////////
@@ -36,19 +36,20 @@
struct X121SMCTradeData struct X121SMCTradeData
{ {
// //
double ask; // Ask Price on Start Time double ask; // Ask Price on Start Time
double bid; // bid Price on Start Time double bid; // bid Price on Start Time
ulong ticket; // Position Ticket ulong ticket; // Position Ticket
double swap; // Swap double swap; // Swap
double profit; // Profit on Close double profit; // Profit on Close
XSignal signal; // Signal Object XSignal signal; // Signal Object
string message; // Message string message; // Message
datetime endTime; // End Time datetime endTime; // End Time
datetime startTime; // Start Time datetime startTime; // Start Time
double commission; // Commission double commission; // Commission
string conditions; // Signal Conditions string conditions; // Signal Conditions
double maxDrawdown; // Max Position Drawdown double maxDrawdown; // Max Position Drawdown
bool isTargeted; // Check Targetted Before Or Not bool isTargeted; // Check Targetted Before Or Not
double lastTrailedTPLevel; // Hold Last Trailed TP Level
// //
// Constructor ... // Constructor ...
@@ -105,6 +106,7 @@ struct X121SMCTradeData
ticket = 0; ticket = 0;
commission = 0; commission = 0;
maxDrawdown = 0; maxDrawdown = 0;
lastTrailedTPLevel = 0;
// //
endTime = NULL; endTime = NULL;
@@ -3453,6 +3455,9 @@ class XC121SMCTradeHandler : public XCBaseAlert
*/ */
void HandleProtection() void HandleProtection()
{ {
//
string prefix = "Protector: ";
// //
// Implement Protection Senario Here ... // Implement Protection Senario Here ...
int count = Count(); int count = Count();
@@ -3476,6 +3481,7 @@ class XC121SMCTradeHandler : public XCBaseAlert
double volumeSummary = 0; double volumeSummary = 0;
double profitSummary = 0; double profitSummary = 0;
XPosition positions[]; XPosition positions[];
bool isProtected = false;
// //
// Loop through Open Positions ... // Loop through Open Positions ...
@@ -3514,13 +3520,22 @@ class XC121SMCTradeHandler : public XCBaseAlert
// //
double tps[]; double tps[];
double reachedTPLevel = -1; int reachedTPIndex = -1;
double reachedTPPrice = 0; double reachedTPPrice = 0;
double reachedTPLevel = -1;
int tpLevelsCount = iPosition.CalculateTPLevels(tps); int tpLevelsCount = iPosition.CalculateTPLevels(tps);
iPosition.CalculateReahedTP( iPosition.CalculateReahedTP(
reachedTPLevel, reachedTPLevel,
reachedTPPrice // reachedTPPrice //
); );
if (reachedTPLevel > 0)
{
//
reachedTPIndex = FindIndex(
reachedTPPrice,
tps //
);
}
// //
bepSummary += bep; bepSummary += bep;
@@ -3558,7 +3573,11 @@ class XC121SMCTradeHandler : public XCBaseAlert
if (isModified) if (isModified)
{ {
// //
string message = ToString(iData.Type()) + isProtected = true;
//
string message = prefix +
ToString(iData.Type()) +
" Position: " + " Position: " +
ToString(iData.ticket) + ToString(iData.ticket) +
" RF On BEP Successfully ..."; " RF On BEP Successfully ...";
@@ -3594,7 +3613,11 @@ class XC121SMCTradeHandler : public XCBaseAlert
if (isModified) if (isModified)
{ {
// //
string message = ToString(iData.Type()) + isProtected = true;
//
string message = prefix +
ToString(iData.Type()) +
" Position: " + " Position: " +
ToString(iData.ticket) + ToString(iData.ticket) +
" PC (" + ToString(closeVolume) + ") On TP Level: " + " PC (" + ToString(closeVolume) + ") On TP Level: " +
@@ -3624,15 +3647,46 @@ class XC121SMCTradeHandler : public XCBaseAlert
bool canTrailSL = iData.CanTrailSL(); bool canTrailSL = iData.CanTrailSL();
if (canTrailSL && reachedTPLevel > 0) if (canTrailSL && reachedTPLevel > 0)
{ {
//
double tSLTPPrice = 0;
// //
double startTrailTPLevel = iData.TrailSLStartOnReachTPLevel(); double startTrailTPLevel = iData.TrailSLStartOnReachTPLevel();
int tSLTPIndex = (int)reachedTPLevel - 1; if (iData.lastTrailedTPLevel > 0)
double tSLTPPrice = tps[tSLTPIndex]; {
canTrailSL = startTrailTPLevel = iData.lastTrailedTPLevel + 1;
reachedTPLevel >= startTrailTPLevel && }
(isLong
? iPosition.sl < tSLTPPrice //
: iPosition.sl > tSLTPPrice); 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) if (canTrailSL)
{ {
// //
@@ -3648,7 +3702,15 @@ class XC121SMCTradeHandler : public XCBaseAlert
if (isModified) 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: " + " Position: " +
ToString(iData.ticket) + ToString(iData.ticket) +
" Trailed SL On Reached TP: " + ToString(reachedTPLevel) + " Trailed SL On Reached TP: " + ToString(reachedTPLevel) +
@@ -3690,10 +3752,15 @@ class XC121SMCTradeHandler : public XCBaseAlert
if (isModified) if (isModified)
{ {
// //
isProtected = true;
//
// Update mData ...
mData[i].isTargeted = true; mData[i].isTargeted = true;
// //
string message = ToString(iData.Type()) + string message = prefix +
ToString(iData.Type()) +
" Position: " + " Position: " +
ToString(iData.ticket) + ToString(iData.ticket) +
" RF On Traget: " + ToString(target) + " RF On Traget: " + ToString(target) +
@@ -3722,7 +3789,8 @@ class XC121SMCTradeHandler : public XCBaseAlert
// //
// Checking Hedge ... // Checking Hedge ...
bool allowHedge = AllowHedging(); bool allowHedge = AllowHedging() &&
!isProtected;
if (allowHedge) if (allowHedge)
{ {
// //
@@ -27,6 +27,7 @@
// //
XConsolidationZone x121SMCConsolidationZone; XConsolidationZone x121SMCConsolidationZone;
bool DetectX121SMCGuards( bool DetectX121SMCGuards(
//
string provider, // Provider ... string provider, // Provider ...
X121SMCGuard &guards[], X121SMCGuard &guards[],
const XPosition &positions[], const XPosition &positions[],
@@ -1698,6 +1698,7 @@ CArrayObj mX121SMCXSupDemOBSWorkingZoneObjects;
// //
// Detect Setup Conditions ... // Detect Setup Conditions ...
bool DetectX121SMCXSupDemOBSSignalSetup( bool DetectX121SMCXSupDemOBSSignalSetup(
//
string _symbol, string _symbol,
ENUM_TIMEFRAMES _period, ENUM_TIMEFRAMES _period,
// //
@@ -4028,6 +4029,7 @@ bool DetectX121SMCXSupDemOBSSignalTrigger(
// //
// Detect Guards ... // Detect Guards ...
bool DetectX121SMCXSupDemOBSGuards( bool DetectX121SMCXSupDemOBSGuards(
//
X121SMCGuard &guards[], X121SMCGuard &guards[],
const XPosition &positions[], const XPosition &positions[],
// //
@@ -4151,7 +4153,9 @@ bool DetectX121SMCXSupDemOBSGuards(
// Get Global and Common Guards ... // Get Global and Common Guards ...
// //
ENUM_X_121_SMC_GUARD_ACTIONS ignoreGuards[]; ENUM_X_121_SMC_GUARD_ACTIONS ignoreGuards[1] = {
X_121_SMC_GUARD_ACTION_TRAIL_STOP
};
result = DetectX121SMCGuards( result = DetectX121SMCGuards(
provider, provider,
guards, guards,