last works ...
This commit is contained in:
@@ -3482,6 +3482,172 @@ int GetYoungest(
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
int FindMaxProfitIndex(
|
||||
XPosition &positions[] // Position Collection
|
||||
)
|
||||
{
|
||||
//
|
||||
int result = -1;
|
||||
|
||||
//
|
||||
int positionsCount = ArraySize(positions);
|
||||
if (!IsValidSize(positionsCount))
|
||||
{
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
double max = 0;
|
||||
for (int i = 0; i < positionsCount; i++)
|
||||
{
|
||||
//
|
||||
XPosition iPosition = positions[i];
|
||||
if (iPosition.profit <= 0)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
//
|
||||
if (max == 0 ||
|
||||
max < iPosition.profit)
|
||||
{
|
||||
//
|
||||
result = i;
|
||||
max = iPosition.profit;
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
int ExtractInProfitPositions(
|
||||
XPosition &positions[], // Position Collection
|
||||
XPosition &inProfits[] // Result
|
||||
)
|
||||
{
|
||||
//
|
||||
int result = 0;
|
||||
|
||||
//
|
||||
Clean(inProfits);
|
||||
|
||||
//
|
||||
int positionsCount = ArraySize(positions);
|
||||
if (!IsValidSize(positionsCount))
|
||||
{
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
for (int i = 0; i < positionsCount; i++)
|
||||
{
|
||||
//
|
||||
XPosition iPosition = positions[i];
|
||||
|
||||
//
|
||||
if (iPosition.profit > 0)
|
||||
{
|
||||
//
|
||||
AddRef(
|
||||
iPosition,
|
||||
inProfits //
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
result = ArraySize(inProfits);
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
int FindMaxDrawdownIndex(
|
||||
XPosition &positions[] // Position Collection
|
||||
)
|
||||
{
|
||||
//
|
||||
int result = -1;
|
||||
|
||||
//
|
||||
int positionsCount = ArraySize(positions);
|
||||
if (!IsValidSize(positionsCount))
|
||||
{
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
double min = 0;
|
||||
for (int i = 0; i < positionsCount; i++)
|
||||
{
|
||||
//
|
||||
XPosition iPosition = positions[i];
|
||||
if (iPosition.profit >= 0)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
//
|
||||
if (min == 0 ||
|
||||
min > iPosition.profit)
|
||||
{
|
||||
//
|
||||
result = i;
|
||||
min = iPosition.profit;
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
int ExtractInDrawdownPositions(
|
||||
XPosition &positions[], // Position Collection
|
||||
XPosition &inDradowns[] // Result
|
||||
)
|
||||
{
|
||||
//
|
||||
int result = 0;
|
||||
|
||||
//
|
||||
Clean(inDradowns);
|
||||
|
||||
//
|
||||
int positionsCount = ArraySize(positions);
|
||||
if (!IsValidSize(positionsCount))
|
||||
{
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
for (int i = 0; i < positionsCount; i++)
|
||||
{
|
||||
//
|
||||
XPosition iPosition = positions[i];
|
||||
|
||||
//
|
||||
if (iPosition.profit < 0)
|
||||
{
|
||||
//
|
||||
AddRef(
|
||||
iPosition,
|
||||
inDradowns //
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
result = ArraySize(inDradowns);
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Check Filters ...
|
||||
|
||||
@@ -3819,6 +3985,107 @@ bool SpecifiedIsPositionsReadyForHedge(
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
int FindCoverageDrawdownPosition(
|
||||
XPosition &position, // In Drawdown Position
|
||||
XPosition &inProfits[], // In Profit Positions
|
||||
XPosition &coverage[], // Coverage Positons
|
||||
double mMinProfitPerTrade,
|
||||
double mMinProfitPerVolumeFactor //
|
||||
)
|
||||
{
|
||||
//
|
||||
int result = 0;
|
||||
|
||||
//
|
||||
Clean(coverage);
|
||||
|
||||
//
|
||||
if (!position.IsValid() || position.profit >= 0)
|
||||
{
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
int inProfitsCount = ArraySize(inProfits);
|
||||
if (!IsValidSize(inProfitsCount))
|
||||
{
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Copy in Profits to TMP ...
|
||||
XPosition tmp[];
|
||||
Copy(
|
||||
inProfits,
|
||||
tmp //
|
||||
);
|
||||
|
||||
//
|
||||
bool isCoverPassed = false;
|
||||
while (!isCoverPassed || ArraySize(tmp) > 0)
|
||||
{
|
||||
//
|
||||
XPosition max;
|
||||
int idx = FindMaxProfitIndex(tmp);
|
||||
if (idx >= 0)
|
||||
{
|
||||
//
|
||||
if (tmp[idx].profit > 0)
|
||||
{
|
||||
AddRef(
|
||||
tmp[idx],
|
||||
coverage //
|
||||
);
|
||||
|
||||
//
|
||||
ArrayRemove(
|
||||
tmp,
|
||||
idx,
|
||||
1 //
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
// Check Cover Passed ...
|
||||
XPosition tmpPositions[];
|
||||
Copy(
|
||||
coverage,
|
||||
tmpPositions //
|
||||
);
|
||||
AddRef(
|
||||
position,
|
||||
tmpPositions //
|
||||
);
|
||||
|
||||
//
|
||||
double profits = SpecifiedCalculatePositionsProfit(tmpPositions);
|
||||
double requiredProfit = SpecifiedCalculateRequiredProfitForHedge(
|
||||
tmpPositions,
|
||||
mMinProfitPerTrade,
|
||||
mMinProfitPerVolumeFactor //
|
||||
);
|
||||
isCoverPassed = profits >= requiredProfit;
|
||||
if (isCoverPassed)
|
||||
{
|
||||
break;
|
||||
}
|
||||
|
||||
//
|
||||
if (!isCoverPassed && ArraySize(tmp) == 0)
|
||||
{
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
result = ArraySize(coverage);
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Extract a Collection of Positions SL ...
|
||||
int ExtractSLs(
|
||||
|
||||
Reference in New Issue
Block a user