last ...
This commit is contained in:
@@ -1238,9 +1238,9 @@ class X121SCTradeHandler : public XSCBaseAlert
|
||||
void ProtectionVolumeMultiplier(double value)
|
||||
{
|
||||
//
|
||||
if (value < 0)
|
||||
if (value < 1)
|
||||
{
|
||||
value = 0;
|
||||
value = 1;
|
||||
}
|
||||
|
||||
//
|
||||
@@ -1259,6 +1259,18 @@ class X121SCTradeHandler : public XSCBaseAlert
|
||||
mProtectOnConditions = value;
|
||||
}
|
||||
|
||||
//
|
||||
bool AllowDirectionProtct()
|
||||
{
|
||||
return mAllowDirectionProtct;
|
||||
}
|
||||
|
||||
//
|
||||
void AllowDirectionProtct(bool value)
|
||||
{
|
||||
mAllowDirectionProtct = value;
|
||||
}
|
||||
|
||||
// //
|
||||
// // Freeze ...
|
||||
// bool AllowFreeze()
|
||||
@@ -2719,14 +2731,14 @@ class X121SCTradeHandler : public XSCBaseAlert
|
||||
bool allowProtect = AllowProtect();
|
||||
bool protectOnConditions = ProtectOnConditions();
|
||||
double protectDistance = ProtectionStartDistance();
|
||||
bool allowDirectionProtect = AllowDirectionProtct();
|
||||
double protectVolumeMultiplier = ProtectionVolumeMultiplier();
|
||||
bool canProtect =
|
||||
!isInProfit &&
|
||||
allowProtect &&
|
||||
supportsCount == 0 &&
|
||||
protectDistance > 0 &&
|
||||
protectVolumeMultiplier > 0 &&
|
||||
MathAbs(profitInPoint) >= Mathbs(protectDistance);
|
||||
protectVolumeMultiplier > 1 &&
|
||||
MathAbs(profitInPoint) >= MathAbs(protectDistance);
|
||||
|
||||
//
|
||||
// bool allowFreeze = AllowFreeze();
|
||||
@@ -3273,18 +3285,93 @@ class X121SCTradeHandler : public XSCBaseAlert
|
||||
//
|
||||
// Protect ...
|
||||
bool isProtected = false;
|
||||
if (canProtected)
|
||||
if (canProtect)
|
||||
{
|
||||
//
|
||||
bool hasLongProtectConditions = isTicksBullishForLong &&
|
||||
hasBullishConditions;
|
||||
bool hasShortProtectConditions = isTicksBearishForShort &&
|
||||
hasBearishConditions;
|
||||
bool hasProtectConditions = hasLongProtectConditions ||
|
||||
hasShortProtectConditions;
|
||||
if (hasSupportConditions) {
|
||||
bool hasProtectConditions = !protectOnConditions
|
||||
? true
|
||||
: allowDirectionProtect
|
||||
? (hasLongProtectConditions ||
|
||||
hasShortProtectConditions)
|
||||
: isLong
|
||||
? hasShortProtectConditions
|
||||
: hasLongProtectConditions;
|
||||
|
||||
//
|
||||
// Check Protection Conditions Happens ...
|
||||
if (hasProtectConditions)
|
||||
{
|
||||
//
|
||||
|
||||
bool isInDirectProtection =
|
||||
!protectOnConditions
|
||||
? true
|
||||
: isLong
|
||||
? hasShortProtectConditions
|
||||
: hasLongProtectConditions;
|
||||
|
||||
//
|
||||
double sl =
|
||||
!isInDirectProtection
|
||||
? position.sl
|
||||
: position.tp;
|
||||
double tp =
|
||||
!isInDirectProtection
|
||||
? position.tp
|
||||
: position.sl;
|
||||
double volume = protectVolumeMultiplier * position.volume;
|
||||
ENUM_POSITION_TYPE type =
|
||||
!isInDirectProtection
|
||||
? position.type
|
||||
: GetOpposit(position.type);
|
||||
double entry = GetEntry(
|
||||
position.symbol,
|
||||
type //
|
||||
);
|
||||
ENUM_X_ORDER_MODES mode = X_ORDER_MODE_MARKET;
|
||||
|
||||
//
|
||||
// Prepare Signal ...
|
||||
XSignal signal;
|
||||
bool isPrepared = signal.Prepare(
|
||||
position.symbol,
|
||||
position.provider,
|
||||
position.period,
|
||||
type,
|
||||
mode,
|
||||
entry,
|
||||
volume,
|
||||
sl,
|
||||
tp //
|
||||
);
|
||||
|
||||
//
|
||||
if (isPrepared)
|
||||
{
|
||||
//
|
||||
// Generate Comment for Recover and Support ...
|
||||
string comment = GenerateSupportTag(position.ticket);
|
||||
|
||||
//
|
||||
signal.comment = comment;
|
||||
|
||||
//
|
||||
ENUM_X_SIGNAL_EXECUTION_RESULT state;
|
||||
isProtected = ExecuteSignal(
|
||||
signal,
|
||||
state,
|
||||
true // Support Signal need to Ignore Policies ...
|
||||
);
|
||||
if (isProtected)
|
||||
{
|
||||
//
|
||||
string message = "EQM Open " + (IsLong(type) ? "Long" : "Short") + " Protect Position for (" + ToString(position.ticket) + ") ...";
|
||||
Alert(message);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3353,6 +3440,7 @@ class X121SCTradeHandler : public XSCBaseAlert
|
||||
bool mAllowProtect; // Allow Proptecting
|
||||
double mProtectionStartDistance; // Protection Start Drawdown in Profit
|
||||
double mProtectionVolumeMultiplier; // Protection Volume Multiplier
|
||||
bool mAllowDirectionProtct; // Allow also Directional Protect
|
||||
bool mProtectOnConditions; // Do Protection only when Conditions happens
|
||||
|
||||
//
|
||||
|
||||
@@ -140,6 +140,15 @@ input group "In Drawdown Positions Protecting";
|
||||
// input bool eaDoSupportOnConditions = true; // Do Support on Conditions
|
||||
// input int eaDelayBetweenTwoSupport = 60; // Delay Between To Support in Second
|
||||
|
||||
//
|
||||
// Protect ...
|
||||
input group "Protect";
|
||||
input bool eaAllowProtect = true; // Allow Proptecting
|
||||
input bool eaProtectOnConditions = true; // Do Protection only when Conditions happens
|
||||
input bool eaAllowDirectionProtct = false; // Allow also Directional Protect
|
||||
input double eaProtectionStartDistance = 50; // Protection Start Drawdown in Profit
|
||||
input double eaProtectionVolumeMultiplier = 2; // Protection Volume Multiplier
|
||||
|
||||
//
|
||||
// Partial Close (In Drawdown) ...
|
||||
input group "Partial Close";
|
||||
@@ -625,6 +634,14 @@ bool InitialEA()
|
||||
// eaTradeHandler.DoSupportOnConditions(eaDoSupportOnConditions);
|
||||
// eaTradeHandler.DelayBetweenTwoSupport(eaDelayBetweenTwoSupport);
|
||||
|
||||
//
|
||||
// Protect ...
|
||||
eaTradeHandler.AllowProtect(eaAllowProtect);
|
||||
eaTradeHandler.ProtectOnConditions(eaProtectOnConditions);
|
||||
eaTradeHandler.AllowDirectionProtct(eaAllowDirectionProtct);
|
||||
eaTradeHandler.ProtectionStartDistance(eaProtectionStartDistance);
|
||||
eaTradeHandler.ProtectionVolumeMultiplier(eaProtectionVolumeMultiplier);
|
||||
|
||||
//
|
||||
// Partial Close (In Profit) ...
|
||||
eaTradeHandler.PartialCloseInDrawdownDistance(eaPartialCloseInDrawdownDistance);
|
||||
|
||||
Reference in New Issue
Block a user