apply fix on Hedging ...
add support for ignore recovery Close when hedging is enabled ...
This commit is contained in:
@@ -4553,6 +4553,9 @@ public:
|
|||||||
return drawdownPercent;
|
return drawdownPercent;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
// Trade Handling Functions ...
|
||||||
|
|
||||||
//
|
//
|
||||||
// First Step of Trade Handling ...
|
// First Step of Trade Handling ...
|
||||||
// Since Must Call when a Signal Executed ...
|
// Since Must Call when a Signal Executed ...
|
||||||
@@ -4813,19 +4816,37 @@ public:
|
|||||||
if (mAllowHedging)
|
if (mAllowHedging)
|
||||||
{
|
{
|
||||||
//
|
//
|
||||||
// Check Values Validation ...
|
// Retrieve Positions ...
|
||||||
if ((mMinTradesForHedge <= 0
|
XPosition positions[];
|
||||||
? count > 1
|
int positionsCount = mTrader.GetPositions(
|
||||||
: count >= mMinTradesForHedge) &&
|
positions //
|
||||||
|
);
|
||||||
|
|
||||||
|
//
|
||||||
|
bool isParamsValid =
|
||||||
mHedgeVolumeFactor > 0 &&
|
mHedgeVolumeFactor > 0 &&
|
||||||
mHedgeMinProfitPerVolumeFactor > 0)
|
mHedgeMinProfitPerVolumeFactor > 0;
|
||||||
|
|
||||||
|
//
|
||||||
|
bool isCountValid = mMinTradesForHedge <= 0
|
||||||
|
? positionsCount >= 1
|
||||||
|
: positionsCount >= mMinTradesForHedge;
|
||||||
|
|
||||||
|
//
|
||||||
|
// Validate State ...
|
||||||
|
if (isParamsValid && isCountValid)
|
||||||
{
|
{
|
||||||
//
|
//
|
||||||
|
double swaps = 0;
|
||||||
double profits = 0;
|
double profits = 0;
|
||||||
|
double volumes = 0;
|
||||||
double commissions = 0;
|
double commissions = 0;
|
||||||
double requiredProfitsForHedge = 0;
|
double requiredProfitsForHedge = 0;
|
||||||
CalculateHedgeData(
|
CalculateHedgeData(
|
||||||
|
positions,
|
||||||
|
swaps,
|
||||||
profits,
|
profits,
|
||||||
|
volumes,
|
||||||
commissions,
|
commissions,
|
||||||
requiredProfitsForHedge //
|
requiredProfitsForHedge //
|
||||||
);
|
);
|
||||||
@@ -4838,8 +4859,6 @@ public:
|
|||||||
string comment = "Hedging ...";
|
string comment = "Hedging ...";
|
||||||
|
|
||||||
//
|
//
|
||||||
XPosition positions[];
|
|
||||||
int positionsCount = mTrader.GetPositions(positions);
|
|
||||||
if (IsValidSize(positionsCount))
|
if (IsValidSize(positionsCount))
|
||||||
{
|
{
|
||||||
//
|
//
|
||||||
@@ -4932,7 +4951,7 @@ public:
|
|||||||
}
|
}
|
||||||
|
|
||||||
//
|
//
|
||||||
// Handle Recovery Break Event ...
|
// Handle Recovery Break Event if Hedging is Disabled ...
|
||||||
if (mData[i].allowRecover)
|
if (mData[i].allowRecover)
|
||||||
{
|
{
|
||||||
//
|
//
|
||||||
@@ -4965,7 +4984,7 @@ public:
|
|||||||
else
|
else
|
||||||
{
|
{
|
||||||
//
|
//
|
||||||
if (recoveriesCount > 0)
|
if (recoveriesCount > 0 && !mAllowHedging)
|
||||||
{
|
{
|
||||||
//
|
//
|
||||||
XPosition mustClose[];
|
XPosition mustClose[];
|
||||||
@@ -5940,6 +5959,62 @@ private:
|
|||||||
requiredProfitsForHedge -= commissions;
|
requiredProfitsForHedge -= commissions;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
// Calculate Required Data for Hedging ...
|
||||||
|
void CalculateHedgeData(
|
||||||
|
XPosition &positions[],
|
||||||
|
double &swaps,
|
||||||
|
double &profits,
|
||||||
|
double &volumes,
|
||||||
|
double &commissions,
|
||||||
|
double &requiredProfitsForHedge //
|
||||||
|
)
|
||||||
|
{
|
||||||
|
//
|
||||||
|
// Reset Values ...
|
||||||
|
swaps = 0;
|
||||||
|
profits = 0;
|
||||||
|
volumes = 0;
|
||||||
|
commissions = 0;
|
||||||
|
requiredProfitsForHedge = 0;
|
||||||
|
|
||||||
|
//
|
||||||
|
// Validate Configurations ...
|
||||||
|
if (mHedgeVolumeFactor <= 0 ||
|
||||||
|
mHedgeMinProfitPerVolumeFactor <= 0)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
// Check Positions Exists For Hedging ...
|
||||||
|
int count = ArraySize(positions);
|
||||||
|
if (!IsValidSize(count))
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
for (int i = 0; i < count; i++)
|
||||||
|
{
|
||||||
|
//
|
||||||
|
XPosition iPosition = positions[i];
|
||||||
|
double iCommission = mTrader.GetPositionCommission(iPosition.ticket);
|
||||||
|
|
||||||
|
//
|
||||||
|
swaps += iPosition.swap;
|
||||||
|
profits += iPosition.profit;
|
||||||
|
volumes += iPosition.volume;
|
||||||
|
commissions += MathAbs(iCommission);
|
||||||
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
// Calculate required Profits for Hedging ...
|
||||||
|
requiredProfitsForHedge = ((volumes / mHedgeVolumeFactor) * mHedgeMinProfitPerVolumeFactor);
|
||||||
|
requiredProfitsForHedge += commissions;
|
||||||
|
requiredProfitsForHedge += -1 * (swaps);
|
||||||
|
}
|
||||||
|
|
||||||
//
|
//
|
||||||
bool FixRecoveredPositionTPSL(XPosition &position)
|
bool FixRecoveredPositionTPSL(XPosition &position)
|
||||||
{
|
{
|
||||||
|
|||||||
Reference in New Issue
Block a user