This commit is contained in:
2024-05-25 08:43:32 +03:30
parent da63c4cb71
commit b8515c9d05
5 changed files with 1307 additions and 374 deletions
+207 -109
View File
@@ -288,14 +288,6 @@ public:
//
bool result = false;
//
// TODO:
// Make them Configurable ...
int numberOfPositionsForHege = 4;
int levelsOnClose = 6;
int requiredAgeForSLTrail = 3;
int requiredDistanceForSLTrail = 10;
//
XPosition positions[];
int positionsCount = mTrader.GetPositions(positions);
@@ -304,6 +296,109 @@ public:
return result;
}
//
HandleEQMState();
//
HandleHedging(positions);
//
HandleTrailManagement(positions);
//
// Must false ...
return result;
}
//
void HandleHedging(XPosition &positions[])
{
//
// TODO:
// Make them Configurable ...
int numberOfPositionsForHege = 3;
//
int positionsCount = ArraySize(positions);
if (positionsCount <= 0)
{
return;
}
//
// Hedge ...
if (positionsCount >= numberOfPositionsForHege)
{
//
double profit = CalculatePositionsProfit(positions);
double requiredProfit = CalculateRequiredProfitForHedge(positions);
//
bool isReadyForHedge = profit >= requiredProfit;
if (!isReadyForHedge)
{
return;
}
//
string comment = "EQM Hedge ...";
int closed = mTrader.Close(
positions,
comment
//
);
if (closed > 0)
{
//
string message = "EQM Hedge Positions on Profit: " + ToString(profit);
//
mAlert.Alert(message);
//
for (int i = 0; i < positionsCount; i++)
{
RemoveSLTrail(positions[i].ticket);
}
}
}
}
//
void HandleEQMState()
{
//
bool equityReached = !mTrader.CheckEquityForTrade();
bool maxAllowedReached = !mTrader.CheckPositionsForTrade();
bool enableEQM = equityReached || maxAllowedReached;
if (!enableEQM)
{
//
return;
}
//
Print("EQM Enabled: " + (equityReached ? "Max Equity Reached ..." : maxAllowedReached ? "Max Allowed Positions Reached ..."
: ""));
}
//
void HandleTrailManagement(XPosition &positions[])
{
//
// TODO:
// Make them Configurable ...
int levelsOnClose = 6;
int requiredAgeForSLTrail = 3;
int requiredDistanceForSLTrail = 10;
//
int positionsCount = ArraySize(positions);
if (positionsCount <= 0)
{
return;
}
//
// Trail Positions Stop ...
for (int i = 0; i < positionsCount; i++)
@@ -316,6 +411,7 @@ public:
//
iPosition.provider == ToString(X786) ||
iPosition.provider == ToString(X121) ||
iPosition.provider == ToString(X110) ||
iPosition.provider == ToString(X92)
//
;
@@ -496,48 +592,6 @@ public:
}
}
}
//
// Hedge ...
if (positionsCount >= numberOfPositionsForHege)
{
//
double profit = CalculatePositionsProfit(positions);
double requiredProfit = CalculateRequiredProfitForHedge(positions);
//
bool isReadyForHedge = profit >= requiredProfit;
if (!isReadyForHedge)
{
return result;
}
//
string comment = "EQM Hedge ...";
int closed = mTrader.Close(
positions,
comment
//
);
if (closed > 0)
{
//
string message = "EQM Hedge Positions on Profit: " + ToString(profit);
//
mAlert.Alert(message);
//
for (int i = 0; i < positionsCount; i++)
{
RemoveSLTrail(positions[i].ticket);
}
}
}
//
// Must false ...
return result;
}
//
@@ -598,7 +652,7 @@ public:
NULL, // All Periods ...
iSignal.type //
);
if (positionsCount <= 5)
if (positionsCount < 2)
{
//
// First Signal in a While of Specific Provider ...
@@ -610,71 +664,112 @@ public:
//
continue;
}
else
{
//
// not First Signal ...
// else
// {
// //
// // not First Signal ...
//
// Calculate Provider Specified Open Positions Profit ...
double profits = CalculatePositionsProfit(positions);
if (profits > 0)
{
//
AddRef(
iSignal,
signals //
);
// //
// // Calculate Provider Specified Open Positions Profit ...
// double profits = CalculatePositionsProfit(positions);
// if (profits > 0)
// {
//
continue;
}
else
{
//
// Find Max In Profit of Same Position ...
Clean(positions);
positionsCount = mTrader.GetInProfitPositions(
positions,
iSignal.symbol,
iSignal.provider,
NULL, // All Periods ...
iSignal.type,
X_POSITION_SELECT_MAX // Max In Profit ...
);
if (positionsCount <= 0)
{
continue;
}
// //
// AddRef(
// iSignal,
// signals //
// );
//
string comment = "EQM Close Max Profit ...";
bool isClosed = mTrader.Close(
positions[0].ticket,
comment //
);
if (isClosed)
{
//
RemoveTrail(positions[0].ticket);
// // //
// // // Find Max In Profit of Same Position ...
// // Clean(positions);
// // positionsCount = mTrader.GetInProfitPositions(
// // positions,
// // iSignal.symbol,
// // iSignal.provider,
// // NULL, // All Periods ...
// // iSignal.type,
// // X_POSITION_SELECT_MAX // Max In Profit ...
// // );
// // if (positionsCount <= 0)
// // {
// // continue;
// // }
//
string message = "EQM Close Max In Profit (" + ToString(positions[0].ticket) + ") for new Signal ...";
// // //
// // string comment = "EQM Close Max Profit ...";
// // bool isClosed = mTrader.Close(
// // positions[0].ticket,
// // comment //
// // );
// // if (isClosed)
// // {
// // //
// // RemoveTrail(positions[0].ticket);
//
mAlert.Alert(message);
// // //
// // string message = "EQM Close Max In Profit (" + ToString(positions[0].ticket) + ") for new Signal ...";
//
AddRef(
iSignal,
signals //
);
// // //
// // mAlert.Alert(message);
//
continue;
}
}
}
// // //
// // AddRef(
// // iSignal,
// // signals //
// // );
// // //
// // continue;
// // }
// }
// else
// {
// // //
// // // Find Max In Profit of Same Position ...
// // Clean(positions);
// // positionsCount = mTrader.GetInProfitPositions(
// // positions,
// // iSignal.symbol,
// // iSignal.provider,
// // NULL, // All Periods ...
// // iSignal.type,
// // X_POSITION_SELECT_MAX // Max In Profit ...
// // );
// // if (positionsCount <= 0)
// // {
// // continue;
// // }
// // //
// // string comment = "EQM Close Max Profit ...";
// // bool isClosed = mTrader.Close(
// // positions[0].ticket,
// // comment //
// // );
// // if (isClosed)
// // {
// // //
// // RemoveTrail(positions[0].ticket);
// // //
// // string message = "EQM Close Max In Profit (" + ToString(positions[0].ticket) + ") for new Signal ...";
// // //
// // mAlert.Alert(message);
// // //
// // AddRef(
// // iSignal,
// // signals //
// // );
// // //
// // continue;
// // }
// }
// }
}
//
@@ -705,6 +800,9 @@ public:
return false;
}
//
// Profit Management ...
//
// Tools ...