update tasks and add multi asset ...
This commit is contained in:
@@ -4305,6 +4305,25 @@ public:
|
||||
mMaxAllowedRecover = value;
|
||||
}
|
||||
|
||||
//
|
||||
double MaxAllowedRecoveryVolume()
|
||||
{
|
||||
return mMaxAllowedRecoveryVolume;
|
||||
}
|
||||
|
||||
//
|
||||
void MaxAllowedRecoveryVolume(double value)
|
||||
{
|
||||
//
|
||||
if (value < 0)
|
||||
{
|
||||
value = 0;
|
||||
}
|
||||
|
||||
//
|
||||
mMaxAllowedRecoveryVolume = value;
|
||||
}
|
||||
|
||||
//
|
||||
double RecoveryVolumeMultiplier()
|
||||
{
|
||||
@@ -4324,6 +4343,18 @@ public:
|
||||
mRecoveryVolumeMultiplier = value;
|
||||
}
|
||||
|
||||
//
|
||||
bool ForcePressuresInRecovery()
|
||||
{
|
||||
return mForcePressuresInRecovery;
|
||||
}
|
||||
|
||||
//
|
||||
void ForcePressuresInRecovery(bool value)
|
||||
{
|
||||
mForcePressuresInRecovery = value;
|
||||
}
|
||||
|
||||
//
|
||||
// Hedging ...
|
||||
|
||||
@@ -4409,6 +4440,11 @@ public:
|
||||
return;
|
||||
}
|
||||
|
||||
//
|
||||
// Check Signal Support or Recovery ...
|
||||
bool isSupport = IsSupport(signal.comment);
|
||||
bool isRecovery = ExtractRecoveredTicket(signal.comment) > 0;
|
||||
|
||||
//
|
||||
XTradeData item;
|
||||
bool isFilled = item.Fill(signal);
|
||||
@@ -4429,7 +4465,10 @@ public:
|
||||
if (mAllowTrailStops || forceTrail)
|
||||
{
|
||||
//
|
||||
item.allowTrailStop = true;
|
||||
if (!isSupport && !isRecovery)
|
||||
{
|
||||
item.allowTrailStop = true;
|
||||
}
|
||||
|
||||
//
|
||||
item.ignoreTPOnTrail = mIgnoreTPOnTrail;
|
||||
@@ -4447,7 +4486,10 @@ public:
|
||||
if (mAllowRecover || forceRecover)
|
||||
{
|
||||
//
|
||||
item.allowRecover = true;
|
||||
if (!isSupport && !isRecovery)
|
||||
{
|
||||
item.allowRecover = true;
|
||||
}
|
||||
|
||||
//
|
||||
item.recoveryTPPoint = mRecoveryTPPoint;
|
||||
@@ -4800,31 +4842,50 @@ public:
|
||||
);
|
||||
|
||||
//
|
||||
double requiredProfitPoints = (mData[i].recoveryLevel + 1) * recoveryTPPoint;
|
||||
|
||||
//
|
||||
double rSwap = mData[i].swap;
|
||||
// Summary Calculations ...
|
||||
double rVolume = volume;
|
||||
double rProfit = profit;
|
||||
bool hasMaxVolume = false;
|
||||
double rSwap = mData[i].swap;
|
||||
double rCommission = mData[i].commission;
|
||||
for (int i = 0; i < recoveriesCount; i++)
|
||||
for (int j = 0; j < recoveriesCount; j++)
|
||||
{
|
||||
//
|
||||
rSwap += recoveries[i].swap;
|
||||
rProfit += recoveries[i].profit;
|
||||
rVolume += recoveries[i].volume;
|
||||
rCommission += mTrader.GetPositionCommission(recoveries[i].ticket);
|
||||
rSwap += recoveries[j].swap;
|
||||
rProfit += recoveries[j].profit;
|
||||
rVolume += recoveries[j].volume;
|
||||
rCommission += mTrader.GetPositionCommission(recoveries[j].ticket);
|
||||
|
||||
//
|
||||
if (!hasMaxVolume &&
|
||||
mMaxAllowedRecoveryVolume > 0 &&
|
||||
recoveries[j].volume >= mMaxAllowedRecoveryVolume)
|
||||
{
|
||||
hasMaxVolume = true;
|
||||
}
|
||||
|
||||
//
|
||||
AddRef(
|
||||
recoveries[i],
|
||||
recoveries[j],
|
||||
mustClose //
|
||||
);
|
||||
}
|
||||
|
||||
//
|
||||
double profitSummary =
|
||||
rProfit + (-1 * rSwap) - MathAbs(rCommission);
|
||||
|
||||
//
|
||||
double requiredProfitPoints = recoveriesCount * recoveryTPPoint;
|
||||
// if (mData[i].recoveryLevel >= 2)
|
||||
// {
|
||||
// //
|
||||
// requiredProfitPoints /= mData[i].recoveryLevel;
|
||||
// if (requiredProfitPoints < recoveryTPPoint)
|
||||
// {
|
||||
// requiredProfitPoints = recoveryTPPoint;
|
||||
// }
|
||||
// }
|
||||
|
||||
//
|
||||
if (profitSummary > 0)
|
||||
{
|
||||
//
|
||||
@@ -4856,12 +4917,12 @@ public:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
Clean(mustClose);
|
||||
Clean(positions);
|
||||
Clean(recoveries);
|
||||
}
|
||||
|
||||
//
|
||||
Clean(mustClose);
|
||||
Clean(positions);
|
||||
Clean(recoveries);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -4897,12 +4958,13 @@ public:
|
||||
tmpLSW,
|
||||
true //
|
||||
);
|
||||
bool isBullishSigns =
|
||||
bool hasBullishSigns =
|
||||
//
|
||||
isBullishTrend &&
|
||||
hasBullishPower &&
|
||||
// isBullishTrend &&
|
||||
cBar.IsBullish() &&
|
||||
hasBullishPattern &&
|
||||
hasBullishPressure
|
||||
(hasBullishPower &&
|
||||
hasBullishPressure)
|
||||
//
|
||||
;
|
||||
|
||||
@@ -4916,12 +4978,13 @@ public:
|
||||
tmpLSW,
|
||||
true //
|
||||
);
|
||||
bool isBearishSigns =
|
||||
bool hasBearishSigns =
|
||||
//
|
||||
isBearishTrend &&
|
||||
hasBearishPower &&
|
||||
hasBearishPattern &&
|
||||
hasBearishPressure
|
||||
// isBearishTrend &&
|
||||
cBar.IsBearish() &&
|
||||
hasBearishPressure &&
|
||||
(hasBearishPower &&
|
||||
hasBearishPattern)
|
||||
//
|
||||
;
|
||||
|
||||
@@ -5103,7 +5166,35 @@ public:
|
||||
// Do Recovery ...
|
||||
|
||||
//
|
||||
// Profit Must be Negative ...
|
||||
// Check Looking for Direction ...
|
||||
ENUM_X_POSITION_TYPES recoveryLookingType = mData[i].recoveryLookingType;
|
||||
if (recoveryLookingType == X_POSITION_TYPE_ALL ||
|
||||
recoveryLookingType == X_POSITION_TYPE_NONE)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
//
|
||||
bool isDirectional = recoveryLookingType == mData[i].type;
|
||||
|
||||
//
|
||||
bool hasPressure =
|
||||
!mForcePressuresInRecovery
|
||||
? true
|
||||
: isDirectional
|
||||
//
|
||||
// Looking For Directional Pressure ...
|
||||
? isLong
|
||||
? hasBullishSigns
|
||||
: hasBearishSigns
|
||||
//
|
||||
// Looking For InDirectional Pressure ...
|
||||
: isLong
|
||||
? hasBearishSigns
|
||||
: hasBullishSigns;
|
||||
|
||||
//
|
||||
// Check Required Properties Validation ...
|
||||
if (
|
||||
recoveryTPPoint > 0 &&
|
||||
recoverySLPoint > 0 &&
|
||||
@@ -5112,78 +5203,45 @@ public:
|
||||
: mData[i].recoveryLevel < maxAllowedRecover))
|
||||
{
|
||||
//
|
||||
// Current Profit ...
|
||||
// Calculate requirements ...
|
||||
double distanceInPoints = (MathAbs(profit) / volume);
|
||||
double _volumeMultiplier = ((mData[i].recoveryLevel + 1) * recoveryVolumeMultiplier);
|
||||
double _volume = volume * (_volumeMultiplier <= 0 ? 1 : _volumeMultiplier);
|
||||
// double _volumeMultiplier = ((mData[i].recoveryLevel + 1) * recoveryVolumeMultiplier);
|
||||
// double _volume =
|
||||
// volume * (_volumeMultiplier <= 0 ? 1 : _volumeMultiplier);
|
||||
double _volume =
|
||||
mData[i].recoveryVolume <= 0
|
||||
? volume * recoveryVolumeMultiplier
|
||||
: mData[i].recoveryVolume;
|
||||
if (mMaxAllowedRecoveryVolume > 0 && _volume > mMaxAllowedRecoveryVolume)
|
||||
{
|
||||
_volume = mMaxAllowedRecoveryVolume;
|
||||
}
|
||||
|
||||
//
|
||||
string _comment = GenerateRecoveryTag(ticket);
|
||||
|
||||
//
|
||||
if (profit < 0)
|
||||
XSignal rSignal;
|
||||
bool isPrepared = false;
|
||||
|
||||
//
|
||||
if (profit < 0 &&
|
||||
hasPressure &&
|
||||
!isDirectional &&
|
||||
distanceInPoints >= recoverySLPoint)
|
||||
{
|
||||
//
|
||||
bool canRecover =
|
||||
distanceInPoints >= recoverySLPoint &&
|
||||
(mData[i].recoveryLevel == 0 ||
|
||||
(mData[i].recoveryLevel >= 2 &&
|
||||
mData[i].recoveryLevel / 2 == 0));
|
||||
if (canRecover)
|
||||
{
|
||||
//
|
||||
RemovePositionTPSL(iPosition);
|
||||
|
||||
//
|
||||
ENUM_POSITION_TYPE _type =
|
||||
isLong
|
||||
? POSITION_TYPE_SELL
|
||||
: POSITION_TYPE_BUY;
|
||||
double _entry = GetEntry(symbol, _type);
|
||||
|
||||
//
|
||||
XSignal rSignal;
|
||||
bool isPrepared = rSignal.Prepare(
|
||||
symbol,
|
||||
provider,
|
||||
period,
|
||||
_type,
|
||||
X_ORDER_MODE_MARKET,
|
||||
_entry,
|
||||
_volume,
|
||||
0,
|
||||
0 //
|
||||
);
|
||||
if (isPrepared)
|
||||
{
|
||||
//
|
||||
rSignal.comment = _comment;
|
||||
|
||||
//
|
||||
bool isExecuted = ExecuteRecoverySignal(rSignal);
|
||||
if (isExecuted)
|
||||
{
|
||||
mData[i].recoveryLevel++;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
else if (profit >= 0 &&
|
||||
(mData[i].recoveryLevel == 1 ||
|
||||
(mData[i].recoveryLevel >= 2 &&
|
||||
mData[i].recoveryLevel / 2 == 1)))
|
||||
{
|
||||
//
|
||||
RemovePositionTPSL(iPosition);
|
||||
FixRecoveredPositionTPSL(iPosition);
|
||||
|
||||
//
|
||||
ENUM_POSITION_TYPE _type =
|
||||
isLong
|
||||
? POSITION_TYPE_BUY
|
||||
: POSITION_TYPE_SELL;
|
||||
? POSITION_TYPE_SELL
|
||||
: POSITION_TYPE_BUY;
|
||||
double _entry = GetEntry(symbol, _type);
|
||||
|
||||
//
|
||||
XSignal rSignal;
|
||||
bool isPrepared = rSignal.Prepare(
|
||||
isPrepared = rSignal.Prepare(
|
||||
symbol,
|
||||
provider,
|
||||
period,
|
||||
@@ -5194,16 +5252,63 @@ public:
|
||||
0,
|
||||
0 //
|
||||
);
|
||||
if (isPrepared)
|
||||
}
|
||||
else if (profit >= 0 &&
|
||||
hasPressure &&
|
||||
isDirectional)
|
||||
{
|
||||
//
|
||||
FixRecoveredPositionTPSL(iPosition);
|
||||
|
||||
//
|
||||
ENUM_POSITION_TYPE _type =
|
||||
isLong
|
||||
? POSITION_TYPE_BUY
|
||||
: POSITION_TYPE_SELL;
|
||||
double _entry = GetEntry(symbol, _type);
|
||||
|
||||
//
|
||||
isPrepared = rSignal.Prepare(
|
||||
symbol,
|
||||
provider,
|
||||
period,
|
||||
_type,
|
||||
X_ORDER_MODE_MARKET,
|
||||
_entry,
|
||||
_volume,
|
||||
0,
|
||||
0 //
|
||||
);
|
||||
}
|
||||
|
||||
//
|
||||
if (isPrepared && rSignal.IsValid())
|
||||
{
|
||||
//
|
||||
// Attach Recovery Tag ...
|
||||
rSignal.comment = _comment;
|
||||
|
||||
//
|
||||
// Execute Recovery Signal ...
|
||||
bool isExecuted = ExecuteRecoverySignal(rSignal);
|
||||
if (isExecuted)
|
||||
{
|
||||
//
|
||||
rSignal.comment = _comment;
|
||||
// Increase Recovery Level ...
|
||||
mData[i].recoveryLevel++;
|
||||
mData[i].recoveryVolume = _volume * recoveryVolumeMultiplier;
|
||||
|
||||
//
|
||||
bool isExecuted = ExecuteRecoverySignal(rSignal);
|
||||
if (isExecuted)
|
||||
// Try to Reverse Looking for Next Recovery
|
||||
// Position Type ...
|
||||
ENUM_POSITION_TYPE _type;
|
||||
bool isConverted = ToPositionType(
|
||||
_type,
|
||||
recoveryLookingType //
|
||||
);
|
||||
if (isConverted)
|
||||
{
|
||||
mData[i].recoveryLevel++;
|
||||
mData[i].recoveryLookingType = GetOppositPositionType(_type);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -5265,7 +5370,9 @@ protected:
|
||||
int mMaxAllowedRecover; // Max Allowed Recovery
|
||||
double mRecoveryTPPoint; // Recovery TP in Points
|
||||
double mRecoverySLPoint; // Recovery SL in Points
|
||||
bool mForcePressuresInRecovery; // Use Direction Pressures In Recovery
|
||||
double mRecoveryVolumeMultiplier; // Recovery Volume Multiplier
|
||||
double mMaxAllowedRecoveryVolume; // Max Allowed Recovery Volume
|
||||
|
||||
//
|
||||
// Hedging ...
|
||||
@@ -5533,7 +5640,7 @@ private:
|
||||
}
|
||||
|
||||
//
|
||||
bool RemovePositionTPSL(XPosition &osition)
|
||||
bool FixRecoveredPositionTPSL(XPosition &osition)
|
||||
{
|
||||
//
|
||||
bool result = false;
|
||||
|
||||
Reference in New Issue
Block a user