add MQL5Test Workspace Content as BKP Solution ...
This commit is contained in:
@@ -0,0 +1,181 @@
|
||||
|
||||
//
|
||||
// Find Reversal Position Type ...
|
||||
ENUM_POSITION_TYPE GetSupportPositionType(ENUM_POSITION_TYPE type)
|
||||
{
|
||||
//
|
||||
ENUM_POSITION_TYPE result = POSITION_TYPE_BUY;
|
||||
|
||||
//
|
||||
if (type == POSITION_TYPE_BUY)
|
||||
{
|
||||
result = POSITION_TYPE_SELL;
|
||||
}
|
||||
else
|
||||
{
|
||||
result = POSITION_TYPE_BUY;
|
||||
}
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Check a Position Has Supportable or not ...
|
||||
bool IsSupportablePosition(XPosition &position)
|
||||
{
|
||||
//
|
||||
bool result = false;
|
||||
|
||||
//
|
||||
if (StringLen(position.comment) <= 0)
|
||||
{
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
int supStrPos = StringFind(
|
||||
position.comment,
|
||||
mSupportPrefix + "(");
|
||||
|
||||
//
|
||||
result = supStrPos < 0;
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Check a Position has Support Position or not ...
|
||||
bool HasSupportPosition(XPosition &position)
|
||||
{
|
||||
//
|
||||
bool result = false;
|
||||
|
||||
//
|
||||
int positionsCount = xEATrade.PositionsCount();
|
||||
|
||||
//
|
||||
if (positionsCount <= 0 ||
|
||||
position.ticket == 0 ||
|
||||
StringLen(position.comment) <= 0)
|
||||
{
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
string supCommentStr = mSupportPrefix + "(" + (string)position.ticket + ")";
|
||||
|
||||
//
|
||||
XPosition positions[];
|
||||
xEATrade.GetPositions(positions);
|
||||
|
||||
//
|
||||
for (int i = 0; i < positionsCount; i++)
|
||||
{
|
||||
//
|
||||
XPosition iPosition = positions[i];
|
||||
|
||||
//
|
||||
int supCommentPos = StringFind(
|
||||
iPosition.comment,
|
||||
supCommentStr);
|
||||
|
||||
//
|
||||
result = supCommentPos >= 0;
|
||||
if (result)
|
||||
{
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Open a Support Position based on Exists ...
|
||||
void OpenSupportPosition(XPosition &position)
|
||||
{
|
||||
//
|
||||
bool isSupportable = IsSupportablePosition(position);
|
||||
if (!isSupportable)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
//
|
||||
bool hasSupport = HasSupportPosition(position);
|
||||
if (hasSupport)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
//
|
||||
ENUM_POSITION_TYPE type = GetSupportPositionType(position.type);
|
||||
double entry = GetEntry(
|
||||
position.symbol,
|
||||
type);
|
||||
|
||||
//
|
||||
bool isLong = IsLong(type);
|
||||
|
||||
//
|
||||
double tpPrice = PipsToPrice(
|
||||
position.symbol,
|
||||
10);
|
||||
double slPrice = PipsToPrice(
|
||||
position.symbol,
|
||||
5);
|
||||
|
||||
//
|
||||
double tp = 0;
|
||||
// isLong
|
||||
// ? entry + tpPrice
|
||||
// : entry - tpPrice;
|
||||
|
||||
//
|
||||
double sl = 0;
|
||||
// isLong
|
||||
// ? entry - slPrice
|
||||
// : entry + slPrice;
|
||||
|
||||
//
|
||||
string comment = mSupportPrefix + "(" + (string)position.ticket + ")";
|
||||
|
||||
//
|
||||
bool isPositionOpen = false;
|
||||
//
|
||||
// Open Signal Position ...
|
||||
if (isLong)
|
||||
{
|
||||
//
|
||||
isPositionOpen = xEATrade.Buy(
|
||||
position.symbol,
|
||||
position.period,
|
||||
position.volume,
|
||||
entry,
|
||||
sl,
|
||||
tp,
|
||||
comment);
|
||||
}
|
||||
else
|
||||
{
|
||||
//
|
||||
isPositionOpen = xEATrade.Sell(
|
||||
position.symbol,
|
||||
position.period,
|
||||
position.volume,
|
||||
entry,
|
||||
sl,
|
||||
tp,
|
||||
comment);
|
||||
}
|
||||
|
||||
//
|
||||
if (isPositionOpen)
|
||||
{
|
||||
//
|
||||
LogMessage("Open Support Psition for: " + position.comment);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user