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;
|
||||
}
|
||||
|
||||
//
|
||||
// Trade Handling Functions ...
|
||||
|
||||
//
|
||||
// First Step of Trade Handling ...
|
||||
// Since Must Call when a Signal Executed ...
|
||||
@@ -4813,19 +4816,37 @@ public:
|
||||
if (mAllowHedging)
|
||||
{
|
||||
//
|
||||
// Check Values Validation ...
|
||||
if ((mMinTradesForHedge <= 0
|
||||
? count > 1
|
||||
: count >= mMinTradesForHedge) &&
|
||||
// Retrieve Positions ...
|
||||
XPosition positions[];
|
||||
int positionsCount = mTrader.GetPositions(
|
||||
positions //
|
||||
);
|
||||
|
||||
//
|
||||
bool isParamsValid =
|
||||
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 volumes = 0;
|
||||
double commissions = 0;
|
||||
double requiredProfitsForHedge = 0;
|
||||
CalculateHedgeData(
|
||||
positions,
|
||||
swaps,
|
||||
profits,
|
||||
volumes,
|
||||
commissions,
|
||||
requiredProfitsForHedge //
|
||||
);
|
||||
@@ -4838,8 +4859,6 @@ public:
|
||||
string comment = "Hedging ...";
|
||||
|
||||
//
|
||||
XPosition positions[];
|
||||
int positionsCount = mTrader.GetPositions(positions);
|
||||
if (IsValidSize(positionsCount))
|
||||
{
|
||||
//
|
||||
@@ -4932,7 +4951,7 @@ public:
|
||||
}
|
||||
|
||||
//
|
||||
// Handle Recovery Break Event ...
|
||||
// Handle Recovery Break Event if Hedging is Disabled ...
|
||||
if (mData[i].allowRecover)
|
||||
{
|
||||
//
|
||||
@@ -4965,7 +4984,7 @@ public:
|
||||
else
|
||||
{
|
||||
//
|
||||
if (recoveriesCount > 0)
|
||||
if (recoveriesCount > 0 && !mAllowHedging)
|
||||
{
|
||||
//
|
||||
XPosition mustClose[];
|
||||
@@ -5940,6 +5959,62 @@ private:
|
||||
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)
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user