add MQL5Test Workspace Content as BKP Solution ...
This commit is contained in:
@@ -0,0 +1,227 @@
|
||||
|
||||
//
|
||||
// Close All Open Positions when Profit Summary is Reached ...
|
||||
void HandleGridHedge()
|
||||
{
|
||||
//
|
||||
int openPositionsCount = xEATrade.PositionsCount();
|
||||
if (openPositionsCount <= 1 ||
|
||||
xEAMinProfitPerOpenPositionForHedging <= 0)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
//
|
||||
double requiredProfitForHedging = xEAMinProfitPerOpenPositionForHedging * openPositionsCount;
|
||||
double accountProfit = xEATrade.GetPositionsProfit();
|
||||
if (accountProfit > 0 || MathAbs(accountProfit) < requiredProfitForHedging)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
//
|
||||
string comment = "Close since Grid Hedging ...";
|
||||
xEATrade.CloseAllPositions(comment);
|
||||
|
||||
//
|
||||
string msg = "Grid Hedging in Loss: " + (string)accountProfit;
|
||||
LogMessage(msg);
|
||||
}
|
||||
|
||||
//
|
||||
// Close All Open Positions when Profit Summary is Reached ...
|
||||
void HandlePyramidHedge()
|
||||
{
|
||||
//
|
||||
int openPositionsCount = xEATrade.PositionsCount();
|
||||
if (openPositionsCount <= 1 ||
|
||||
xEAMinProfitPerOpenPositionForHedging <= 0)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
//
|
||||
double requiredProfitForHedging = xEAMinProfitPerOpenPositionForHedging * openPositionsCount;
|
||||
double accountProfit = xEATrade.GetPositionsProfit();
|
||||
if (accountProfit < requiredProfitForHedging)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
//
|
||||
string comment = "Close since Pyramid Hedging ...";
|
||||
xEATrade.CloseAllPositions(comment);
|
||||
|
||||
//
|
||||
string msg = "Pyramid Hedging in Profit: " + (string)accountProfit;
|
||||
LogMessage(msg);
|
||||
}
|
||||
|
||||
//
|
||||
// Force Close Signals ...
|
||||
void HandleForceClosing()
|
||||
{
|
||||
//
|
||||
int positionsCount = xEATrade.PositionsCount();
|
||||
int ordersCount = xEATrade.OrdersCount();
|
||||
if (positionsCount <= 0 || ordersCount <= 0)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
//
|
||||
X121ForceClose results[];
|
||||
xEAProvider.CanForceCloseShortSignals(results);
|
||||
int resultsCount = ArraySize(results);
|
||||
if (resultsCount <= 0)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
//
|
||||
for (int i = 0; i < resultsCount; i++)
|
||||
{
|
||||
//
|
||||
X121ForceClose iForceClose = results[i];
|
||||
if (!iForceClose.force)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
//
|
||||
XPosition iPositions[];
|
||||
xEATrade.GetPositions(
|
||||
iPositions,
|
||||
iForceClose.symbol,
|
||||
iForceClose.period);
|
||||
int iPositionsCount = ArraySize(iPositions);
|
||||
if (iPositionsCount > 0)
|
||||
{
|
||||
//
|
||||
for (int j = 0; j < iPositionsCount; j++)
|
||||
{
|
||||
//
|
||||
XPosition jPosition = iPositions[j];
|
||||
bool isLong = IsLong(jPosition.type);
|
||||
if (isLong)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
//
|
||||
ENUM_X121_SIGNAL_PROVIDERS jProvider = ExtractProvider(jPosition);
|
||||
string jProviderStr = ToString(jProvider);
|
||||
if (jProviderStr != iForceClose.provider)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
//
|
||||
string comment = "Force Close Signals ...";
|
||||
bool isClosed = xEATrade.Close(jPosition.ticket, comment);
|
||||
if (isClosed)
|
||||
{
|
||||
//
|
||||
string msg = "Position (" + (string)jPosition.ticket + ") Closed Due Force Event ...";
|
||||
LogMessage(msg);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
XOrder iOrders[];
|
||||
xEATrade.GetOrders(
|
||||
iOrders,
|
||||
iForceClose.symbol,
|
||||
iForceClose.period,
|
||||
ORDER_STATE_PLACED);
|
||||
int iOrdersCount = ArraySize(iOrders);
|
||||
if (iOrdersCount > 0)
|
||||
{
|
||||
//
|
||||
bool isCanceled = xEATrade.CancelOrders(iOrders);
|
||||
if (isCanceled)
|
||||
{
|
||||
//
|
||||
string msg = "(" + (string)ordersCount + ") Canceled due Cycle Change ...";
|
||||
|
||||
//
|
||||
LogMessage(msg);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
// Close a Position and it's Support Due to Profit ...
|
||||
void HandleHedgeSupports()
|
||||
{
|
||||
//
|
||||
int positionsCount = xEATrade.PositionsCount();
|
||||
if (positionsCount <= 0)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
//
|
||||
XPosition positions[];
|
||||
xEATrade.GetPositions(
|
||||
positions);
|
||||
positionsCount = ArraySize(positions);
|
||||
if (positionsCount <= 0)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
//
|
||||
for (int i = 0; i < positionsCount; i++)
|
||||
{
|
||||
//
|
||||
XPosition iPosition = positions[i];
|
||||
|
||||
//
|
||||
bool hasSupport = xEATrade.HasSupport(iPosition.ticket);
|
||||
if (!hasSupport)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
//
|
||||
bool isClosed = xEATrade.ClosePositionAndSupports(
|
||||
iPosition.ticket);
|
||||
if (isClosed)
|
||||
{
|
||||
//
|
||||
string msg = "Position and Supports Closed ...";
|
||||
LogMessage(msg);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
//
|
||||
// Delete Specific Order of Support if Exists ...
|
||||
ulong positionId = deal.positionId;
|
||||
|
||||
//
|
||||
XOrder supports[];
|
||||
bool hasSupport = xEATrade.GetSupportOrders(
|
||||
positionId,
|
||||
supports,
|
||||
NULL,
|
||||
NULL,
|
||||
ORDER_STATE_PLACED);
|
||||
if (hasSupport)
|
||||
{
|
||||
//
|
||||
bool isCanceled = xEATrade.CancelOrders(supports);
|
||||
|
||||
//
|
||||
if (isCanceled)
|
||||
{
|
||||
//
|
||||
string msg = "Close all Supports of (" + (string)positionId + ") Due to it's TakeProfit Event ...";
|
||||
LogMessage(msg);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user