add support for freezeing in drawdown positions ...
This commit is contained in:
@@ -55,6 +55,7 @@ struct X121TradeData
|
||||
|
||||
//
|
||||
int trailStep; // Trail Step
|
||||
bool freezed; // Position Freezed or not
|
||||
int protectionStep; // Protection Step
|
||||
datetime lastProtectedOn; // Last Protection Date
|
||||
double lastProtectedInProfit; // Last Protection In Profit
|
||||
@@ -199,6 +200,7 @@ struct X121TradeData
|
||||
|
||||
//
|
||||
trailStep = 0;
|
||||
freezed = false;
|
||||
protectionStep = 0;
|
||||
partiallyClosed = false;
|
||||
lastProtectedOn = NULL;
|
||||
@@ -1206,6 +1208,68 @@ class X121SCTradeHandler : public XSCBaseAlert
|
||||
//
|
||||
// In Drawdown Positions Protecting ...
|
||||
|
||||
//
|
||||
bool FreezeInDrawdon()
|
||||
{
|
||||
return mFreezeInDrawdon;
|
||||
}
|
||||
|
||||
//
|
||||
void FreezeInDrawdon(bool value)
|
||||
{
|
||||
mFreezeInDrawdon = value;
|
||||
}
|
||||
|
||||
//
|
||||
double FreezePoint()
|
||||
{
|
||||
return mFreezePoint;
|
||||
}
|
||||
|
||||
//
|
||||
void FreezePoint(double value)
|
||||
{
|
||||
//
|
||||
if (value < 0)
|
||||
{
|
||||
value = 0;
|
||||
}
|
||||
|
||||
//
|
||||
mFreezePoint = value;
|
||||
}
|
||||
|
||||
//
|
||||
double FreezeVolume()
|
||||
{
|
||||
return mFreezeVolume;
|
||||
}
|
||||
|
||||
//
|
||||
void FreezeVolume(double value)
|
||||
{
|
||||
//
|
||||
if (value < 0)
|
||||
{
|
||||
value = 0;
|
||||
}
|
||||
|
||||
//
|
||||
mFreezeVolume = value;
|
||||
}
|
||||
|
||||
//
|
||||
bool RemoveFreezedPositionsTPSL()
|
||||
{
|
||||
return mRemoveFreezedPositionsTPSL;
|
||||
}
|
||||
|
||||
//
|
||||
void RemoveFreezedPositionsTPSL(bool value)
|
||||
{
|
||||
mRemoveFreezedPositionsTPSL = value;
|
||||
}
|
||||
|
||||
//
|
||||
bool AllowRecoverInDrawdowns()
|
||||
{
|
||||
@@ -2482,6 +2546,7 @@ class X121SCTradeHandler : public XSCBaseAlert
|
||||
|
||||
//
|
||||
int supportsCount = ArraySize(supports);
|
||||
double profitInPoint = position.GetProfitInPoint();
|
||||
|
||||
//
|
||||
int zIndex = 0;
|
||||
@@ -2684,6 +2749,14 @@ class X121SCTradeHandler : public XSCBaseAlert
|
||||
//
|
||||
;
|
||||
|
||||
//
|
||||
bool allowFreeze = FreezeInDrawdon();
|
||||
double freezePoint = FreezePoint();
|
||||
double freezeVolumeMultiplier = FreezeVolume();
|
||||
bool canFreeze = allowFreeze &&
|
||||
freezePoint > 0 &&
|
||||
freezeVolumeMultiplier > 0;
|
||||
|
||||
//
|
||||
// In Profit ...
|
||||
// When a Position running in Profit, we have to look pressures by Same Direction
|
||||
@@ -2815,7 +2888,7 @@ class X121SCTradeHandler : public XSCBaseAlert
|
||||
//
|
||||
bool allowRecover = AllowRecoverInDrawdowns();
|
||||
double volumeMultiplier = RecoveryMultiplier();
|
||||
if (allowRecover && volumeMultiplier > 0 && supportsCount > 0)
|
||||
if (allowRecover && !canFreeze && volumeMultiplier > 0 && supportsCount > 0)
|
||||
{
|
||||
//
|
||||
bool canRecover = false;
|
||||
@@ -3011,7 +3084,7 @@ class X121SCTradeHandler : public XSCBaseAlert
|
||||
//
|
||||
bool allowRecover = AllowRecoverInDrawdowns();
|
||||
double volumeMultiplier = RecoveryMultiplier();
|
||||
if (allowRecover && volumeMultiplier > 0)
|
||||
if (allowRecover && !canFreeze && volumeMultiplier > 0)
|
||||
{
|
||||
//
|
||||
bool canRecover = false;
|
||||
@@ -3166,6 +3239,88 @@ class X121SCTradeHandler : public XSCBaseAlert
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
if (canFreeze && position.profit < 0 && supportsCount <= 0 && profitInPoint >= freezePoint && !mData[iDX].freezed)
|
||||
{
|
||||
//
|
||||
bool removeTPSL = RemoveFreezedPositionsTPSL();
|
||||
//
|
||||
// Temparory Requirement for Recover Signal ...
|
||||
double sl = removeTPSL ? 0 : position.tp;
|
||||
double tp = removeTPSL ? 0 : position.sl;
|
||||
ENUM_POSITION_TYPE type = IsLong
|
||||
? POSITION_TYPE_SELL
|
||||
: POSITION_TYPE_BUY;
|
||||
double entry = GetEntry(
|
||||
position.symbol,
|
||||
type //
|
||||
);
|
||||
ENUM_X_ORDER_MODES mode = X_ORDER_MODE_MARKET;
|
||||
double volume = position.volume * freezeVolumeMultiplier;
|
||||
|
||||
//
|
||||
XSignal signal;
|
||||
|
||||
//
|
||||
// Prepare Signal ...
|
||||
result = signal.Prepare(
|
||||
position.symbol,
|
||||
position.provider,
|
||||
position.period,
|
||||
type,
|
||||
mode,
|
||||
entry,
|
||||
volume,
|
||||
sl,
|
||||
tp //
|
||||
);
|
||||
|
||||
//
|
||||
if (result)
|
||||
{
|
||||
//
|
||||
// Generate Comment for Recover and Support ...
|
||||
string comment = GenerateSupportTag(position.ticket);
|
||||
|
||||
//
|
||||
signal.comment = comment;
|
||||
|
||||
//
|
||||
ENUM_X_SIGNAL_EXECUTION_RESULT state;
|
||||
result = ExecuteSignal(
|
||||
signal,
|
||||
state,
|
||||
true // Support Signal need to Ignore Policies ...
|
||||
);
|
||||
if (result)
|
||||
{
|
||||
//
|
||||
mData[iDX].freezed = true;
|
||||
|
||||
//
|
||||
string message = "EQM Open " + (IsLong(type) ? "Long" : "Short") + " Freeze Position for (" + ToString(position.ticket) + ")";
|
||||
Alert(message);
|
||||
|
||||
//
|
||||
string comment = "EQM Removes Freezed TP/SL ...";
|
||||
result = mTrader.Modify(
|
||||
position.ticket,
|
||||
0,
|
||||
0,
|
||||
comment //
|
||||
);
|
||||
|
||||
//
|
||||
if (result)
|
||||
{
|
||||
//
|
||||
string message = "EQM Remove Freezed Position (" + ToString(position.ticket) + ") TP/SL ..";
|
||||
Alert(message);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
// Check Points of Drawdown and Do Partial Closing ...
|
||||
double partialCloseVolume = PartialCloseVolumeInDrawdown();
|
||||
@@ -3244,6 +3399,10 @@ class X121SCTradeHandler : public XSCBaseAlert
|
||||
|
||||
//
|
||||
// In Drawdown Positions Protecting ...
|
||||
bool mFreezeInDrawdon; // Freeze In Drawdown Position by Lock it
|
||||
double mFreezePoint; // Freezing Drawdown Point
|
||||
double mFreezeVolume; // Freezing Volume Multiplier
|
||||
bool mRemoveFreezedPositionsTPSL; // Removes Freezed Positions TP and SL
|
||||
bool mAllowRecoverInDrawdowns; // Allow Recovery For In Drawdown Positions
|
||||
double mRecoveryMultiplier; // Recovery Volume Multiplier
|
||||
bool mApplyRecoveryLevelOnVolume; // Apply Recovery Level on Volume Calculation
|
||||
|
||||
@@ -110,7 +110,11 @@ input double eaPartialCloseVolumeInProfit = 0; // Partial Close Volume
|
||||
//
|
||||
// Protector > In Drawdown Positions Protecting ...
|
||||
input group "In Drawdown Positions Protecting";
|
||||
input bool eaAllowRecoverInDrawdowns = true; // Allow Recovery For In Drawdown Positions
|
||||
input bool eaFreezeInDrawdon = true; // Freeze In Drawdown Position by Lock it
|
||||
input double eaFreezePoint = 100; // Freezing Drawdown Point
|
||||
input double eaFreezeVolume = 2; // Freezing Volume Multiplier
|
||||
input bool eaRemoveFreezedPositionsTPSL = true; // Removes Freezed Positions TP and SL
|
||||
input bool eaAllowRecoverInDrawdowns = false; // Allow Recovery For In Drawdown Positions
|
||||
input double eaRecoveryMultiplier = 1; // Recovery Volume Multiplier
|
||||
input bool eaApplyRecoveryLevelOnVolume = true; // Apply Recovery Level on Volume Calculation
|
||||
input int eaRecoveryDelayInMinute = 1; // Delay Between Two Recovery in Minutes
|
||||
@@ -500,6 +504,10 @@ bool InitialEA()
|
||||
|
||||
//
|
||||
// Protector > In Drawdown Positions Protecting ...
|
||||
eaTradeHandler.FreezeInDrawdon(eaFreezeInDrawdon);
|
||||
eaTradeHandler.FreezePoint(eaFreezePoint);
|
||||
eaTradeHandler.FreezeVolume(eaFreezeVolume);
|
||||
eaTradeHandler.RemoveFreezedPositionsTPSL(eaRemoveFreezedPositionsTPSL);
|
||||
eaTradeHandler.AllowRecoverInDrawdowns(eaAllowRecoverInDrawdowns);
|
||||
eaTradeHandler.RecoveryMultiplier(eaRecoveryMultiplier);
|
||||
eaTradeHandler.ApplyRecoveryLevelOnVolume(eaApplyRecoveryLevelOnVolume);
|
||||
|
||||
Reference in New Issue
Block a user