last works on recovery ...
This commit is contained in:
+131
-260
@@ -4286,18 +4286,6 @@ public:
|
|||||||
mRecoverySLPoint = value;
|
mRecoverySLPoint = value;
|
||||||
}
|
}
|
||||||
|
|
||||||
//
|
|
||||||
bool RecoverBasedOnPressures()
|
|
||||||
{
|
|
||||||
return mRecoverBasedOnPressures;
|
|
||||||
}
|
|
||||||
|
|
||||||
//
|
|
||||||
void RecoverBasedOnPressures(bool value)
|
|
||||||
{
|
|
||||||
mRecoverBasedOnPressures = value;
|
|
||||||
}
|
|
||||||
|
|
||||||
//
|
//
|
||||||
int MaxAllowedRecover()
|
int MaxAllowedRecover()
|
||||||
{
|
{
|
||||||
@@ -4466,6 +4454,17 @@ public:
|
|||||||
item.recoverySLPoint = mRecoverySLPoint;
|
item.recoverySLPoint = mRecoverySLPoint;
|
||||||
item.maxAllowedRecover = mMaxAllowedRecover;
|
item.maxAllowedRecover = mMaxAllowedRecover;
|
||||||
item.recoveryVolumeMultiplier = mRecoveryVolumeMultiplier;
|
item.recoveryVolumeMultiplier = mRecoveryVolumeMultiplier;
|
||||||
|
|
||||||
|
//
|
||||||
|
ENUM_POSITION_TYPE _type;
|
||||||
|
bool isConverted = ToPositionType(
|
||||||
|
_type,
|
||||||
|
item.type //
|
||||||
|
);
|
||||||
|
if (isConverted)
|
||||||
|
{
|
||||||
|
item.recoveryLookingType = GetOppositPositionType(_type);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
//
|
//
|
||||||
@@ -4734,6 +4733,29 @@ public:
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
// Try to Detect Recovered Positions ...
|
||||||
|
|
||||||
|
//
|
||||||
|
XPosition positions[];
|
||||||
|
XPosition recoveries[];
|
||||||
|
int recoveriesCount = 0;
|
||||||
|
int positionsCount = mTrader.GetPositions(
|
||||||
|
positions,
|
||||||
|
symbol,
|
||||||
|
provider,
|
||||||
|
period //
|
||||||
|
);
|
||||||
|
if (positionsCount > 0)
|
||||||
|
{
|
||||||
|
//
|
||||||
|
recoveriesCount = ExtractRecoveries(
|
||||||
|
ticket,
|
||||||
|
positions,
|
||||||
|
recoveries //
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
//
|
//
|
||||||
// Handle Recovery Break Event ...
|
// Handle Recovery Break Event ...
|
||||||
if (mData[i].allowRecover)
|
if (mData[i].allowRecover)
|
||||||
@@ -4768,96 +4790,77 @@ public:
|
|||||||
else
|
else
|
||||||
{
|
{
|
||||||
//
|
//
|
||||||
XPosition positions[];
|
if (recoveriesCount > 0)
|
||||||
int positionsCount = mTrader.GetPositions(
|
|
||||||
positions,
|
|
||||||
symbol,
|
|
||||||
provider,
|
|
||||||
period //
|
|
||||||
);
|
|
||||||
if (positionsCount > 0)
|
|
||||||
{
|
{
|
||||||
//
|
//
|
||||||
XPosition recoveries[];
|
XPosition mustClose[];
|
||||||
int recoveriesCount = ExtractRecoveries(
|
AddRef(
|
||||||
ticket,
|
iPosition,
|
||||||
positions,
|
mustClose //
|
||||||
recoveries //
|
|
||||||
);
|
);
|
||||||
|
|
||||||
//
|
//
|
||||||
if (recoveriesCount > 0)
|
double requiredProfitPoints = (mData[i].recoveryLevel + 1) * recoveryTPPoint;
|
||||||
|
|
||||||
|
//
|
||||||
|
double rSwap = mData[i].swap;
|
||||||
|
double rVolume = volume;
|
||||||
|
double rProfit = profit;
|
||||||
|
double rCommission = mData[i].commission;
|
||||||
|
for (int i = 0; i < recoveriesCount; i++)
|
||||||
{
|
{
|
||||||
//
|
//
|
||||||
XPosition mustClose[];
|
rSwap += recoveries[i].swap;
|
||||||
|
rProfit += recoveries[i].profit;
|
||||||
|
rVolume += recoveries[i].volume;
|
||||||
|
rCommission += mTrader.GetPositionCommission(recoveries[i].ticket);
|
||||||
|
|
||||||
|
//
|
||||||
AddRef(
|
AddRef(
|
||||||
iPosition,
|
recoveries[i],
|
||||||
mustClose //
|
mustClose //
|
||||||
);
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
double profitSummary =
|
||||||
|
rProfit + (-1 * rSwap) - MathAbs(rCommission);
|
||||||
|
if (profitSummary > 0)
|
||||||
|
{
|
||||||
|
//
|
||||||
|
double rProfitInPoints = profitSummary / volume;
|
||||||
|
|
||||||
//
|
//
|
||||||
double requiredProfitPoints = (mData[i].recoveryLevel + 1) * recoveryTPPoint;
|
bool canFinishRecovery = rProfitInPoints >= requiredProfitPoints;
|
||||||
|
if (canFinishRecovery)
|
||||||
//
|
|
||||||
double rSwap = mData[i].swap;
|
|
||||||
double rVolume = volume;
|
|
||||||
double rProfit = profit;
|
|
||||||
double rCommission = mData[i].commission;
|
|
||||||
for (int i = 0; i < recoveriesCount; i++)
|
|
||||||
{
|
{
|
||||||
//
|
//
|
||||||
rSwap += recoveries[i].swap;
|
// Here we Have to close All Recoveries
|
||||||
rProfit += recoveries[i].profit;
|
// and Position it Self ...
|
||||||
rVolume += recoveries[i].volume;
|
|
||||||
rCommission += mTrader.GetPositionCommission(recoveries[i].ticket);
|
|
||||||
|
|
||||||
//
|
//
|
||||||
AddRef(
|
string comment = "Recovery Done ...";
|
||||||
recoveries[i],
|
|
||||||
mustClose //
|
//
|
||||||
|
int closeds = mTrader.Close(
|
||||||
|
mustClose,
|
||||||
|
comment //
|
||||||
);
|
);
|
||||||
}
|
if (closeds > 0)
|
||||||
|
|
||||||
//
|
|
||||||
double profitSummary =
|
|
||||||
rProfit + (-1 * rSwap) - MathAbs(rCommission);
|
|
||||||
if (profitSummary > 0)
|
|
||||||
{
|
|
||||||
//
|
|
||||||
double rProfitInPoints = profitSummary / volume;
|
|
||||||
|
|
||||||
//
|
|
||||||
bool canFinishRecovery = rProfitInPoints >= requiredProfitPoints;
|
|
||||||
if (canFinishRecovery)
|
|
||||||
{
|
{
|
||||||
//
|
//
|
||||||
// Here we Have to close All Recoveries
|
string msg = "EQM Done Recovery (" + ToString(closeds) + ") Positions ...";
|
||||||
// and Position it Self ...
|
Alert(msg);
|
||||||
|
|
||||||
//
|
//
|
||||||
string comment = "Recovery Done ...";
|
break;
|
||||||
|
|
||||||
//
|
|
||||||
int closeds = mTrader.Close(
|
|
||||||
mustClose,
|
|
||||||
comment //
|
|
||||||
);
|
|
||||||
if (closeds > 0)
|
|
||||||
{
|
|
||||||
//
|
|
||||||
string msg = "EQM Done Recovery (" + ToString(closeds) + ") Positions ...";
|
|
||||||
Alert(msg);
|
|
||||||
|
|
||||||
//
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
//
|
|
||||||
Clean(mustClose);
|
|
||||||
Clean(positions);
|
|
||||||
Clean(recoveries);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
Clean(mustClose);
|
||||||
|
Clean(positions);
|
||||||
|
Clean(recoveries);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -5119,184 +5122,12 @@ public:
|
|||||||
if (profit < 0)
|
if (profit < 0)
|
||||||
{
|
{
|
||||||
//
|
//
|
||||||
if (mRecoverBasedOnPressures)
|
bool canRecover =
|
||||||
{
|
distanceInPoints >= recoverySLPoint &&
|
||||||
//
|
(mData[i].recoveryLevel == 0 ||
|
||||||
bool canRecover = distanceInPoints >= recoverySLPoint * 0.75;
|
(mData[i].recoveryLevel >= 2 &&
|
||||||
if (canRecover)
|
mData[i].recoveryLevel / 2 == 0));
|
||||||
{
|
if (canRecover)
|
||||||
//
|
|
||||||
XSignal rSignal;
|
|
||||||
bool isPrepared = false;
|
|
||||||
double longEntry = GetEntry(symbol, POSITION_TYPE_BUY);
|
|
||||||
double shortEntry = GetEntry(symbol, POSITION_TYPE_SELL);
|
|
||||||
|
|
||||||
//
|
|
||||||
if (isBullishSigns)
|
|
||||||
{
|
|
||||||
//
|
|
||||||
rSignal.Clean();
|
|
||||||
isPrepared = rSignal.Prepare(
|
|
||||||
symbol,
|
|
||||||
provider,
|
|
||||||
period,
|
|
||||||
POSITION_TYPE_BUY,
|
|
||||||
X_ORDER_MODE_MARKET,
|
|
||||||
longEntry,
|
|
||||||
_volume,
|
|
||||||
0,
|
|
||||||
0 //
|
|
||||||
);
|
|
||||||
}
|
|
||||||
else if (isBearishSigns)
|
|
||||||
{
|
|
||||||
//
|
|
||||||
rSignal.Clean();
|
|
||||||
isPrepared = rSignal.Prepare(
|
|
||||||
symbol,
|
|
||||||
provider,
|
|
||||||
period,
|
|
||||||
POSITION_TYPE_SELL,
|
|
||||||
X_ORDER_MODE_MARKET,
|
|
||||||
shortEntry,
|
|
||||||
_volume,
|
|
||||||
0,
|
|
||||||
0 //
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
//
|
|
||||||
if (isPrepared)
|
|
||||||
{
|
|
||||||
//
|
|
||||||
RemovePositionTPSL(iPosition);
|
|
||||||
|
|
||||||
//
|
|
||||||
rSignal.comment = _comment;
|
|
||||||
|
|
||||||
//
|
|
||||||
bool isExecuted = ExecuteRecoverySignal(rSignal);
|
|
||||||
if (isExecuted)
|
|
||||||
{
|
|
||||||
mData[i].recoveryLevel++;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
//
|
|
||||||
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)))
|
|
||||||
{
|
|
||||||
//
|
|
||||||
if (mRecoverBasedOnPressures)
|
|
||||||
{
|
|
||||||
//
|
|
||||||
XSignal rSignal;
|
|
||||||
bool isPrepared = false;
|
|
||||||
double longEntry = GetEntry(symbol, POSITION_TYPE_BUY);
|
|
||||||
double shortEntry = GetEntry(symbol, POSITION_TYPE_SELL);
|
|
||||||
|
|
||||||
//
|
|
||||||
if (isBullishSigns)
|
|
||||||
{
|
|
||||||
//
|
|
||||||
rSignal.Clean();
|
|
||||||
isPrepared = rSignal.Prepare(
|
|
||||||
symbol,
|
|
||||||
provider,
|
|
||||||
period,
|
|
||||||
POSITION_TYPE_BUY,
|
|
||||||
X_ORDER_MODE_MARKET,
|
|
||||||
longEntry,
|
|
||||||
_volume,
|
|
||||||
0,
|
|
||||||
0 //
|
|
||||||
);
|
|
||||||
}
|
|
||||||
else if (isBearishSigns)
|
|
||||||
{
|
|
||||||
//
|
|
||||||
rSignal.Clean();
|
|
||||||
isPrepared = rSignal.Prepare(
|
|
||||||
symbol,
|
|
||||||
provider,
|
|
||||||
period,
|
|
||||||
POSITION_TYPE_SELL,
|
|
||||||
X_ORDER_MODE_MARKET,
|
|
||||||
shortEntry,
|
|
||||||
_volume,
|
|
||||||
0,
|
|
||||||
0 //
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
//
|
|
||||||
if (isPrepared)
|
|
||||||
{
|
|
||||||
//
|
|
||||||
RemovePositionTPSL(iPosition);
|
|
||||||
|
|
||||||
//
|
|
||||||
rSignal.comment = _comment;
|
|
||||||
|
|
||||||
//
|
|
||||||
bool isExecuted = ExecuteRecoverySignal(rSignal);
|
|
||||||
if (isExecuted)
|
|
||||||
{
|
|
||||||
mData[i].recoveryLevel++;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
{
|
||||||
//
|
//
|
||||||
RemovePositionTPSL(iPosition);
|
RemovePositionTPSL(iPosition);
|
||||||
@@ -5304,8 +5135,8 @@ public:
|
|||||||
//
|
//
|
||||||
ENUM_POSITION_TYPE _type =
|
ENUM_POSITION_TYPE _type =
|
||||||
isLong
|
isLong
|
||||||
? POSITION_TYPE_BUY
|
? POSITION_TYPE_SELL
|
||||||
: POSITION_TYPE_SELL;
|
: POSITION_TYPE_BUY;
|
||||||
double _entry = GetEntry(symbol, _type);
|
double _entry = GetEntry(symbol, _type);
|
||||||
|
|
||||||
//
|
//
|
||||||
@@ -5335,6 +5166,47 @@ public:
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
else if (profit >= 0 &&
|
||||||
|
(mData[i].recoveryLevel == 1 ||
|
||||||
|
(mData[i].recoveryLevel >= 2 &&
|
||||||
|
mData[i].recoveryLevel / 2 == 1)))
|
||||||
|
{
|
||||||
|
//
|
||||||
|
RemovePositionTPSL(iPosition);
|
||||||
|
|
||||||
|
//
|
||||||
|
ENUM_POSITION_TYPE _type =
|
||||||
|
isLong
|
||||||
|
? POSITION_TYPE_BUY
|
||||||
|
: POSITION_TYPE_SELL;
|
||||||
|
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++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -5393,7 +5265,6 @@ protected:
|
|||||||
int mMaxAllowedRecover; // Max Allowed Recovery
|
int mMaxAllowedRecover; // Max Allowed Recovery
|
||||||
double mRecoveryTPPoint; // Recovery TP in Points
|
double mRecoveryTPPoint; // Recovery TP in Points
|
||||||
double mRecoverySLPoint; // Recovery SL in Points
|
double mRecoverySLPoint; // Recovery SL in Points
|
||||||
bool mRecoverBasedOnPressures; // Do Recovery based on Market Pressures
|
|
||||||
double mRecoveryVolumeMultiplier; // Recovery Volume Multiplier
|
double mRecoveryVolumeMultiplier; // Recovery Volume Multiplier
|
||||||
|
|
||||||
//
|
//
|
||||||
|
|||||||
@@ -286,7 +286,6 @@ bool InitialEA()
|
|||||||
eaTradeHandler.RecoveryTPPoint(50);
|
eaTradeHandler.RecoveryTPPoint(50);
|
||||||
eaTradeHandler.RecoverySLPoint(eaSLPoint);
|
eaTradeHandler.RecoverySLPoint(eaSLPoint);
|
||||||
eaTradeHandler.RecoveryVolumeMultiplier(2);
|
eaTradeHandler.RecoveryVolumeMultiplier(2);
|
||||||
eaTradeHandler.RecoverBasedOnPressures(false);
|
|
||||||
|
|
||||||
//
|
//
|
||||||
XSymbolParser symbolParser;
|
XSymbolParser symbolParser;
|
||||||
|
|||||||
@@ -3785,12 +3785,13 @@ struct XTradeData
|
|||||||
// Recovery ...
|
// Recovery ...
|
||||||
|
|
||||||
//
|
//
|
||||||
bool allowRecover; // Allow Recover Specified Position
|
bool allowRecover; // Allow Recover Specified Position
|
||||||
double recoveryTPPoint; // Recovery TP Point
|
double recoveryTPPoint; // Recovery TP Point
|
||||||
double recoverySLPoint; // Recovery SL Point
|
double recoverySLPoint; // Recovery SL Point
|
||||||
int maxAllowedRecover; // Max Allowed Recovery
|
int maxAllowedRecover; // Max Allowed Recovery
|
||||||
int recoveryLevel; // Number of Recovery Signals
|
int recoveryLevel; // Number of Recovery Signals
|
||||||
double recoveryVolumeMultiplier; // Recovery Volume Multiplier
|
double recoveryVolumeMultiplier; // Recovery Volume Multiplier
|
||||||
|
ENUM_X_POSITION_TYPES recoveryLookingType; // Looking for Next Recovery Type
|
||||||
|
|
||||||
//
|
//
|
||||||
void ResetRecovery()
|
void ResetRecovery()
|
||||||
@@ -3801,6 +3802,7 @@ struct XTradeData
|
|||||||
recoveryTPPoint = 0;
|
recoveryTPPoint = 0;
|
||||||
recoverySLPoint = 0;
|
recoverySLPoint = 0;
|
||||||
recoveryVolumeMultiplier = 0;
|
recoveryVolumeMultiplier = 0;
|
||||||
|
recoveryLookingType = X_POSITION_TYPE_NONE;
|
||||||
}
|
}
|
||||||
|
|
||||||
//
|
//
|
||||||
|
|||||||
Reference in New Issue
Block a user