1340 lines
36 KiB
Plaintext
1340 lines
36 KiB
Plaintext
|
|
//
|
|
XSCZones *mLastHindZones;
|
|
XSCZones *mLastLongZones;
|
|
XSCZones *mLastMediumZones;
|
|
|
|
//
|
|
bool DoEQMProtectOfSupports()
|
|
{
|
|
//
|
|
bool result = false;
|
|
|
|
//
|
|
// The Senario is When all Signals are Support and Account in Drawdown
|
|
// here we have to Do some Support Actions ...
|
|
|
|
//
|
|
XPosition positions[];
|
|
int positionsCount = mTrader.GetPositions(positions);
|
|
result = IsValidSize(positionsCount);
|
|
if (!result)
|
|
{
|
|
return result;
|
|
}
|
|
|
|
//
|
|
// Noe We Have to Separate Support Positions ...
|
|
XPosition supports[];
|
|
int supportsCount = ExtractSupportPositions(
|
|
positions,
|
|
supports //
|
|
);
|
|
result = IsValidSize(supportsCount);
|
|
if (!result)
|
|
{
|
|
return result;
|
|
}
|
|
|
|
//
|
|
// Now We Are sure we have Support Positions ...
|
|
// then we must Check the Supports are Long enough to make the Support ...
|
|
XPosition youngest;
|
|
int youngestAge = GetYoungest(
|
|
youngest,
|
|
supports //
|
|
);
|
|
result = youngestAge > 2;
|
|
if (!result)
|
|
{
|
|
return result;
|
|
}
|
|
|
|
//
|
|
// Try to Find Youngest Support's Setup ...
|
|
int setupIDX = FindSetupIndex(
|
|
youngest.symbol //
|
|
);
|
|
result = IsValidIndex(setupIDX);
|
|
if (!result)
|
|
{
|
|
return result;
|
|
}
|
|
|
|
//
|
|
// Now we can Implememnt Support of Supports based on
|
|
// Several Senarios ...
|
|
// 1. Recieve Market Conditions;
|
|
// 2. Recieve Summary of Long Verifications and Short Verifications;
|
|
// 3. Collect VolumeOSC and also Bullish and Bearish Scores;
|
|
// 4. Collect XSCZones of Last HIND Market;
|
|
|
|
//
|
|
// Hind Zone ...
|
|
if (mLastHindZones == NULL)
|
|
{
|
|
//
|
|
mLastHindZones = mSetups[setupIDX].GetZones(
|
|
X_MARKET_CYCLE_HIND //
|
|
);
|
|
result = mLastHindZones != NULL;
|
|
if (!result)
|
|
{
|
|
return result;
|
|
}
|
|
|
|
//
|
|
result = mLastHindZones.DrawZones(0, "HIN");
|
|
if (result)
|
|
{
|
|
Print("Zone Drawn ...");
|
|
}
|
|
}
|
|
|
|
//
|
|
// Long Zone ...
|
|
if (mLastLongZones == NULL)
|
|
{
|
|
//
|
|
mLastLongZones = mSetups[setupIDX].GetZones(
|
|
X_MARKET_CYCLE_LONG //
|
|
);
|
|
result = mLastLongZones != NULL;
|
|
if (!result)
|
|
{
|
|
return result;
|
|
}
|
|
|
|
//
|
|
result = mLastLongZones.DrawZones(0, "LON");
|
|
if (result)
|
|
{
|
|
Print("Zone Drawn ...");
|
|
}
|
|
}
|
|
|
|
//
|
|
// Medium Zone ...
|
|
if (mLastMediumZones == NULL)
|
|
{
|
|
//
|
|
mLastMediumZones = mSetups[setupIDX].GetZones(
|
|
X_MARKET_CYCLE_MEDIUM //
|
|
);
|
|
result = mLastMediumZones != NULL;
|
|
if (!result)
|
|
{
|
|
return result;
|
|
}
|
|
|
|
//
|
|
result = mLastMediumZones.DrawZones(0, "MED");
|
|
if (result)
|
|
{
|
|
Print("Zone Drawn ...");
|
|
}
|
|
}
|
|
|
|
//
|
|
return result;
|
|
}
|
|
|
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
//
|
|
// XPosition Pack ...
|
|
|
|
//
|
|
// Extract specific Positions Pack ...
|
|
// in this senario there is no need to Position exists itself ...
|
|
bool GetPositionPack(
|
|
ulong ticket, // Specified Positions Ticket
|
|
string symbol, // Specified Position Symbol
|
|
ENUM_TIMEFRAMES period, // Specified Position Period
|
|
XPositionPack &pack // Hold Result
|
|
)
|
|
{
|
|
//
|
|
bool result = false;
|
|
|
|
//
|
|
pack.Clean();
|
|
|
|
//
|
|
XPosition position;
|
|
bool hasPosition = GetPosition(
|
|
ticket,
|
|
position
|
|
//
|
|
);
|
|
if (hasPosition)
|
|
{
|
|
pack.position = position;
|
|
}
|
|
|
|
//
|
|
XOrder supportOrders[];
|
|
XPosition supportPositions[];
|
|
|
|
//
|
|
XOrder orders[];
|
|
GetOrders(
|
|
orders,
|
|
symbol, // Specified Symbol
|
|
NULL, // All Providers
|
|
period, // Specified Period
|
|
NULL, // All Types
|
|
ORDER_STATE_PLACED, // Just UnTriggered Orders
|
|
true // Filter by Magic
|
|
);
|
|
int ordersCount = ArraySize(orders);
|
|
|
|
//
|
|
// Select Orders ...
|
|
if (ordersCount > 0)
|
|
{
|
|
//
|
|
for (int i = 0; i < ordersCount; i++)
|
|
{
|
|
//
|
|
XOrder iOrder = orders[i];
|
|
|
|
//
|
|
// Retrieve Order Supported Ticket ...
|
|
ulong parentTicket = ExtractSupportedTicket(iOrder.comment);
|
|
if (NotEmpty(parentTicket) && parentTicket == ticket)
|
|
{
|
|
//
|
|
AddRef(
|
|
iOrder,
|
|
supportOrders
|
|
//
|
|
);
|
|
}
|
|
}
|
|
}
|
|
|
|
//
|
|
int supportOrdersCount = ArraySize(supportOrders);
|
|
if (supportOrdersCount > 0)
|
|
{
|
|
//
|
|
pack.supportOrdersCount = supportOrdersCount;
|
|
|
|
//
|
|
Copy(
|
|
supportOrders,
|
|
pack.supportOrders);
|
|
}
|
|
|
|
//
|
|
XPosition positions[];
|
|
GetPositions(
|
|
positions,
|
|
symbol, // Specified Symbol ...
|
|
NULL, // All Providers ...
|
|
period // Specified Period ...
|
|
);
|
|
int positionsCount = ArraySize(positions);
|
|
|
|
//
|
|
// Select Positions ...
|
|
if (positionsCount > 0)
|
|
{
|
|
//
|
|
for (int i = 0; i < positionsCount; i++)
|
|
{
|
|
//
|
|
XPosition iPosition = positions[i];
|
|
|
|
//
|
|
ulong parentTicket = ExtractSupportedTicket(iPosition.comment);
|
|
if (NotEmpty(parentTicket) && parentTicket == ticket)
|
|
{
|
|
//
|
|
AddRef(
|
|
iPosition,
|
|
supportPositions
|
|
//
|
|
);
|
|
}
|
|
}
|
|
}
|
|
|
|
//
|
|
int supportPositionsCount = ArraySize(supportPositions);
|
|
if (supportPositionsCount > 0)
|
|
{
|
|
//
|
|
pack.supportPositionsCount = supportPositionsCount;
|
|
|
|
//
|
|
Copy(
|
|
supportPositions,
|
|
pack.supportPositions);
|
|
}
|
|
|
|
//
|
|
result = pack.IsValid();
|
|
|
|
//
|
|
return result;
|
|
}
|
|
|
|
//
|
|
// Close Position Pack ...
|
|
bool ClosePositionPack(
|
|
XPositionPack &pack, // Specified Position Pack
|
|
string comment, // Specified Close Comment
|
|
bool inProfit = false, // if it's true only close Pack if in profit
|
|
double minProfitPerTrade = 0, // Min Profit based On Volume Factor ...
|
|
double minProfitPerVolumeFactor = 0 // Min Volume Factor ...
|
|
)
|
|
{
|
|
//
|
|
bool result = false;
|
|
|
|
//
|
|
ulong ticket = pack.ticket;
|
|
|
|
//
|
|
XPosition positions[];
|
|
|
|
//
|
|
XPosition pPosition;
|
|
result = GetPosition(
|
|
ticket,
|
|
pPosition //
|
|
);
|
|
if (result)
|
|
{
|
|
//
|
|
AddRef(
|
|
pPosition,
|
|
positions //
|
|
);
|
|
}
|
|
|
|
//
|
|
if (pack.supportPositionsCount > 0)
|
|
{
|
|
//
|
|
for (int i = 0; i < pack.supportPositionsCount; i++)
|
|
{
|
|
//
|
|
XPosition iPosition = pack.supportPositions[i];
|
|
|
|
//
|
|
AddRef(
|
|
iPosition,
|
|
positions //
|
|
);
|
|
}
|
|
}
|
|
|
|
//
|
|
// Force Close ...
|
|
if (!inProfit)
|
|
{
|
|
//
|
|
int closed = Close(
|
|
positions,
|
|
comment //
|
|
);
|
|
|
|
//
|
|
int cancelled = 0;
|
|
if (pack.supportOrdersCount > 0)
|
|
{
|
|
cancelled = CancelOrders(pack.supportOrders);
|
|
}
|
|
|
|
//
|
|
result = (closed + cancelled) == (pack.supportPositionsCount + pack.supportOrdersCount + 1);
|
|
}
|
|
else
|
|
{
|
|
//
|
|
bool canHedge = SpecifiedIsPositionsReadyForHedge(
|
|
positions,
|
|
minProfitPerTrade,
|
|
minProfitPerVolumeFactor //
|
|
);
|
|
if (canHedge)
|
|
{
|
|
//
|
|
int closed = Close(
|
|
positions,
|
|
comment //
|
|
);
|
|
|
|
//
|
|
int cancelled = 0;
|
|
if (pack.supportOrdersCount > 0)
|
|
{
|
|
cancelled = CancelOrders(pack.supportOrders);
|
|
}
|
|
|
|
//
|
|
result = (closed + cancelled) == (pack.supportPositionsCount + pack.supportOrdersCount + 1);
|
|
}
|
|
else
|
|
{
|
|
result = false;
|
|
}
|
|
}
|
|
|
|
//
|
|
return result;
|
|
}
|
|
bool ClosePositionPack(
|
|
ulong ticket, // Specified Position Pack
|
|
string symbol, // Specified Position Symbol
|
|
ENUM_TIMEFRAMES period, // Specified Position Period
|
|
string comment, // Specified Close Comment
|
|
bool inProfit = false, // if it's true only close Pack if in profit
|
|
double minProfitPerTrade = 0, // Min Profit based On Volume Factor ...
|
|
double minProfitPerVolumeFactor = 0 // Min Volume Factor ...
|
|
)
|
|
{
|
|
//
|
|
bool result = false;
|
|
|
|
//
|
|
XPositionPack pack;
|
|
result = GetPositionPack(
|
|
ticket,
|
|
symbol,
|
|
period,
|
|
pack //
|
|
);
|
|
if (!result)
|
|
{
|
|
return result;
|
|
}
|
|
|
|
//
|
|
result = ClosePositionPack(
|
|
pack,
|
|
comment,
|
|
inProfit,
|
|
minProfitPerTrade,
|
|
minProfitPerVolumeFactor //
|
|
);
|
|
|
|
//
|
|
return result;
|
|
}
|
|
|
|
//
|
|
// Close Positions Pack ...
|
|
int ClosePositionsPack(
|
|
XPosition &positions[], // Positions ...
|
|
string comment, // Specified Close Comment
|
|
bool inProfit = false, // if it's true only close Pack if in profit
|
|
double minProfitPerTrade = 0, // Min Profit based On Volume Factor ...
|
|
double minProfitPerVolumeFactor = 0 // Min Volume Factor ...
|
|
)
|
|
{
|
|
//
|
|
int result = 0;
|
|
|
|
//
|
|
int positionsCount = ArraySize(positions);
|
|
if (positionsCount <= 0)
|
|
{
|
|
return result;
|
|
}
|
|
|
|
//
|
|
for (int i = 0; i < positionsCount; i++)
|
|
{
|
|
//
|
|
XPosition iPosition = positions[i];
|
|
|
|
//
|
|
bool isClosed = ClosePositionPack(
|
|
iPosition.ticket,
|
|
iPosition.symbol,
|
|
iPosition.period,
|
|
comment,
|
|
inProfit,
|
|
minProfitPerTrade,
|
|
minProfitPerVolumeFactor //
|
|
);
|
|
if (isClosed)
|
|
{
|
|
result++;
|
|
}
|
|
}
|
|
|
|
//
|
|
return result;
|
|
}
|
|
|
|
|
|
|
|
/////////////////////////////////////////////////////////////
|
|
|
|
|
|
//
|
|
// Long Support ...
|
|
bool canLongSupport =
|
|
//
|
|
volumeOSC > 5 &&
|
|
bullishScore > bearishScore &&
|
|
ArraySize(longProviders) >= 2 &&
|
|
bearishScore < bullishScore / 3.5 &&
|
|
longVerifications > reqValidation * 3
|
|
//
|
|
;
|
|
if (canLongSupport)
|
|
{
|
|
//
|
|
bool isPrepared = tmpSignal.Prepare(
|
|
iPosition.symbol,
|
|
iPosition.provider,
|
|
iPosition.period,
|
|
POSITION_TYPE_BUY,
|
|
X_ORDER_MODE_MARKET,
|
|
longEntry,
|
|
mVolume //
|
|
);
|
|
|
|
//
|
|
if (isPrepared)
|
|
{
|
|
//
|
|
tmpSignal.positionId = iPosition.ticket;
|
|
string comment = GenerateSupportTag(iPosition.ticket);
|
|
tmpSignal.comment = comment;
|
|
|
|
//
|
|
AddRef(
|
|
tmpSignal,
|
|
signals //
|
|
);
|
|
|
|
//
|
|
tmpSignal.Clean();
|
|
}
|
|
|
|
//
|
|
isPrepared = tmpSignal.Prepare(
|
|
iPosition.symbol,
|
|
iPosition.provider,
|
|
iPosition.period,
|
|
POSITION_TYPE_SELL,
|
|
X_ORDER_MODE_MARKET,
|
|
shortEntry,
|
|
mVolume //
|
|
);
|
|
|
|
//
|
|
if (isPrepared)
|
|
{
|
|
//
|
|
tmpSignal.positionId = iPosition.ticket;
|
|
string comment = GenerateSupportTag(iPosition.ticket);
|
|
tmpSignal.comment = comment;
|
|
|
|
//
|
|
AddRef(
|
|
tmpSignal,
|
|
signals //
|
|
);
|
|
|
|
//
|
|
tmpSignal.Clean();
|
|
}
|
|
}
|
|
|
|
//
|
|
// Short Support ...
|
|
bool canShortSupport =
|
|
//
|
|
volumeOSC < -5 &&
|
|
bearishScore > bullishScore &&
|
|
ArraySize(shortProviders) >= 2 &&
|
|
bullishScore < bearishScore / 3.5 &&
|
|
shortVerifications > reqValidation * 3
|
|
//
|
|
;
|
|
if (canShortSupport)
|
|
{
|
|
//
|
|
bool isPrepared = tmpSignal.Prepare(
|
|
iPosition.symbol,
|
|
iPosition.provider,
|
|
iPosition.period,
|
|
POSITION_TYPE_SELL,
|
|
X_ORDER_MODE_MARKET,
|
|
shortEntry,
|
|
mVolume //
|
|
);
|
|
|
|
//
|
|
if (isPrepared)
|
|
{
|
|
//
|
|
tmpSignal.positionId = iPosition.ticket;
|
|
string comment = GenerateSupportTag(iPosition.ticket);
|
|
tmpSignal.comment = comment;
|
|
|
|
//
|
|
AddRef(
|
|
tmpSignal,
|
|
signals //
|
|
);
|
|
|
|
//
|
|
tmpSignal.Clean();
|
|
}
|
|
|
|
//
|
|
isPrepared = tmpSignal.Prepare(
|
|
iPosition.symbol,
|
|
iPosition.provider,
|
|
iPosition.period,
|
|
POSITION_TYPE_BUY,
|
|
X_ORDER_MODE_MARKET,
|
|
longEntry,
|
|
mVolume //
|
|
);
|
|
|
|
//
|
|
if (isPrepared)
|
|
{
|
|
//
|
|
tmpSignal.positionId = iPosition.ticket;
|
|
string comment = GenerateSupportTag(iPosition.ticket);
|
|
tmpSignal.comment = comment;
|
|
|
|
//
|
|
AddRef(
|
|
tmpSignal,
|
|
signals //
|
|
);
|
|
|
|
//
|
|
tmpSignal.Clean();
|
|
}
|
|
}
|
|
|
|
//
|
|
// If no Support Presents ...
|
|
if (!canLongSupport && !canShortSupport)
|
|
{
|
|
//
|
|
// RemoveDraws("MED");
|
|
// RemoveDraws("LON");
|
|
// RemoveDraws("HND");
|
|
AddHotLevelsToZones(mZones);
|
|
AddHotLevelsToZones(lZones);
|
|
AddHotLevelsToZones(hZones);
|
|
|
|
//
|
|
bool isPrepared = tmpSignal.Prepare(
|
|
iPosition.symbol,
|
|
iPosition.provider,
|
|
iPosition.period,
|
|
POSITION_TYPE_BUY,
|
|
X_ORDER_MODE_MARKET,
|
|
longEntry,
|
|
iPosition.volume //
|
|
);
|
|
if (isPrepared)
|
|
{
|
|
//
|
|
tmpSignal.positionId = iPosition.ticket;
|
|
string comment = GenerateSupportTag(iPosition.ticket);
|
|
tmpSignal.comment = comment;
|
|
|
|
//
|
|
AddRef(
|
|
tmpSignal,
|
|
signals //
|
|
);
|
|
|
|
//
|
|
tmpSignal.Clean();
|
|
}
|
|
|
|
//
|
|
isPrepared = tmpSignal.Prepare(
|
|
iPosition.symbol,
|
|
iPosition.provider,
|
|
iPosition.period,
|
|
POSITION_TYPE_SELL,
|
|
X_ORDER_MODE_MARKET,
|
|
shortEntry,
|
|
iPosition.volume //
|
|
);
|
|
if (isPrepared)
|
|
{
|
|
//
|
|
tmpSignal.positionId = iPosition.ticket;
|
|
string comment = GenerateSupportTag(iPosition.ticket);
|
|
tmpSignal.comment = comment;
|
|
|
|
//
|
|
AddRef(
|
|
tmpSignal,
|
|
signals //
|
|
);
|
|
|
|
//
|
|
tmpSignal.Clean();
|
|
}
|
|
|
|
//
|
|
// bool isDrawn = mZones.DrawZones(0, "MED");
|
|
// if (isDrawn)
|
|
// {
|
|
// //
|
|
// isDrawn = false;
|
|
// RemoveDraws("MED");
|
|
// }
|
|
|
|
// //
|
|
// isDrawn = lZones.DrawZones(0, "LON");
|
|
// if (isDrawn)
|
|
// {
|
|
// //
|
|
// isDrawn = false;
|
|
// RemoveDraws("LON");
|
|
// }
|
|
|
|
// //
|
|
// isDrawn = hZones.DrawZones(0, "HND");
|
|
// if (isDrawn)
|
|
// {
|
|
// //
|
|
// isDrawn = false;
|
|
// RemoveDraws("HND");
|
|
// }
|
|
|
|
// //
|
|
// isDrawn = mZones.DrawZones(0, "MED");
|
|
// isDrawn = lZones.DrawZones(0, "LON");
|
|
// isDrawn = hZones.DrawZones(0, "HND");
|
|
// if (isDrawn)
|
|
// {
|
|
// //
|
|
// isDrawn = false;
|
|
// // RemoveDraws("MED");
|
|
// // RemoveDraws("LON");
|
|
// // RemoveDraws("HND");
|
|
// }
|
|
}
|
|
|
|
|
|
//
|
|
// Now Check Position SUpports ...
|
|
XPosition iSupports[];
|
|
int iSupportsCount = mTrader.GetSupports(
|
|
iPosition.ticket,
|
|
iSupports //
|
|
);
|
|
bool isFirst = !IsValidSize(iSupportsCount);
|
|
bool canSupport = isFirst || iSupportsCount < 3;
|
|
if (!canSupport)
|
|
{
|
|
continue;
|
|
}
|
|
|
|
//
|
|
// Now Check Signals For not Exists ...
|
|
int signalsCount = ArraySize(signals);
|
|
if (IsValidSize(signalsCount))
|
|
{
|
|
//
|
|
bool isInserted = false;
|
|
for (int j = 0; j < signalsCount; j++)
|
|
{
|
|
//
|
|
isInserted = signals[j].positionId == iPosition.ticket;
|
|
if (isInserted)
|
|
{
|
|
break;
|
|
}
|
|
}
|
|
|
|
//
|
|
if (isInserted)
|
|
{
|
|
continue;
|
|
}
|
|
}
|
|
|
|
//
|
|
// First Try to Get Market State ...
|
|
|
|
//
|
|
double bullishScore = 0;
|
|
double bearishScore = 0;
|
|
double tmpBullishScore = 0;
|
|
double tmpBearishScore = 0;
|
|
|
|
//
|
|
// Max Verifications is 11 ...
|
|
int reqValidation = 6;
|
|
int longVerifications = 0;
|
|
int shortVerifications = 0;
|
|
|
|
//
|
|
// Pushers ...
|
|
int longPushers = 0;
|
|
int shortPushers = 0;
|
|
int tmpLongPushers = 0;
|
|
int tmpShortPushers = 0;
|
|
|
|
//
|
|
string tmpProvider;
|
|
string longProviders[];
|
|
string shortProviders[];
|
|
|
|
//
|
|
double volumeOSC = 0;
|
|
|
|
//
|
|
// Current ...
|
|
X121SetupConditions cConditions;
|
|
bool cHasConditions = setups[idx].GetConditions(
|
|
cConditions,
|
|
X_MARKET_CYCLE_UNKNOWN //
|
|
);
|
|
if (!cHasConditions)
|
|
{
|
|
continue;
|
|
}
|
|
bool isCValidForLong = signalGenerator.IsConditionsValidForLong(
|
|
cConditions,
|
|
reqValidation //
|
|
);
|
|
if (isCValidForLong)
|
|
{
|
|
longVerifications += reqValidation;
|
|
}
|
|
bool isCValidForShort = signalGenerator.IsConditionsValidForShort(
|
|
cConditions,
|
|
reqValidation //
|
|
);
|
|
if (isCValidForShort)
|
|
{
|
|
shortVerifications += reqValidation;
|
|
}
|
|
bool cHasLongConditions = signalGenerator.HasLongConditions(
|
|
cConditions,
|
|
tmpLongPushers,
|
|
tmpProvider //
|
|
);
|
|
if (cHasLongConditions)
|
|
{
|
|
//
|
|
AddSpecific(
|
|
tmpProvider,
|
|
longProviders //
|
|
);
|
|
|
|
//
|
|
longPushers += tmpLongPushers;
|
|
}
|
|
bool cHasShortConditions = signalGenerator.HasShortConditions(
|
|
cConditions,
|
|
tmpShortPushers,
|
|
tmpProvider //
|
|
);
|
|
if (cHasShortConditions)
|
|
{
|
|
//
|
|
AddSpecific(
|
|
tmpProvider,
|
|
shortProviders //
|
|
);
|
|
|
|
//
|
|
shortPushers += tmpShortPushers;
|
|
}
|
|
volumeOSC += cConditions.vlmConditions.volume[1];
|
|
cConditions.GenerateScore(
|
|
tmpBullishScore,
|
|
tmpBearishScore //
|
|
);
|
|
bullishScore += tmpBullishScore;
|
|
bearishScore += tmpBearishScore;
|
|
|
|
//
|
|
// Short ...
|
|
X121SetupConditions sConditions;
|
|
bool sHasConditions = setups[idx].GetConditions(
|
|
sConditions,
|
|
X_MARKET_CYCLE_SHORT //
|
|
);
|
|
if (!sHasConditions)
|
|
{
|
|
continue;
|
|
}
|
|
bool isSValidForLong = signalGenerator.IsConditionsValidForLong(
|
|
sConditions,
|
|
reqValidation //
|
|
);
|
|
if (isSValidForLong)
|
|
{
|
|
longVerifications += reqValidation;
|
|
}
|
|
bool isSValidForShort = signalGenerator.IsConditionsValidForShort(
|
|
sConditions,
|
|
reqValidation //
|
|
);
|
|
if (isSValidForShort)
|
|
{
|
|
shortVerifications += reqValidation;
|
|
}
|
|
bool sHasLongConditions = signalGenerator.HasLongConditions(
|
|
sConditions,
|
|
tmpLongPushers,
|
|
tmpProvider //
|
|
);
|
|
if (sHasLongConditions)
|
|
{
|
|
//
|
|
AddSpecific(
|
|
tmpProvider,
|
|
longProviders //
|
|
);
|
|
|
|
//
|
|
longPushers += tmpLongPushers;
|
|
}
|
|
bool sHasShortConditions = signalGenerator.HasShortConditions(
|
|
sConditions,
|
|
tmpShortPushers,
|
|
tmpProvider //
|
|
);
|
|
if (sHasShortConditions)
|
|
{
|
|
//
|
|
AddSpecific(
|
|
tmpProvider,
|
|
shortProviders //
|
|
);
|
|
|
|
//
|
|
shortPushers += tmpShortPushers;
|
|
}
|
|
volumeOSC += sConditions.vlmConditions.volume[1];
|
|
sConditions.GenerateScore(
|
|
tmpBullishScore,
|
|
tmpBearishScore //
|
|
);
|
|
bullishScore += tmpBullishScore;
|
|
bearishScore += tmpBearishScore;
|
|
|
|
//
|
|
// Medium ...
|
|
X121SetupConditions mConditions;
|
|
bool mHasConditions = setups[idx].GetConditions(
|
|
mConditions,
|
|
X_MARKET_CYCLE_MEDIUM //
|
|
);
|
|
if (!mHasConditions)
|
|
{
|
|
continue;
|
|
}
|
|
XSCZones *mZones = setups[idx].GetZones(
|
|
X_MARKET_CYCLE_MEDIUM //
|
|
);
|
|
bool isMValidForLong = signalGenerator.IsConditionsValidForLong(
|
|
mConditions,
|
|
reqValidation //
|
|
);
|
|
if (isMValidForLong)
|
|
{
|
|
longVerifications += reqValidation;
|
|
}
|
|
bool isMValidForShort = signalGenerator.IsConditionsValidForShort(
|
|
mConditions,
|
|
reqValidation //
|
|
);
|
|
if (isMValidForShort)
|
|
{
|
|
shortVerifications += reqValidation;
|
|
}
|
|
bool mHasLongConditions = signalGenerator.HasLongConditions(
|
|
mConditions,
|
|
tmpLongPushers,
|
|
tmpProvider //
|
|
);
|
|
if (mHasLongConditions)
|
|
{
|
|
//
|
|
AddSpecific(
|
|
tmpProvider,
|
|
longProviders //
|
|
);
|
|
|
|
//
|
|
longPushers += tmpLongPushers;
|
|
}
|
|
bool mHasShortConditions = signalGenerator.HasShortConditions(
|
|
mConditions,
|
|
tmpShortPushers,
|
|
tmpProvider //
|
|
);
|
|
if (mHasShortConditions)
|
|
{
|
|
//
|
|
AddSpecific(
|
|
tmpProvider,
|
|
shortProviders //
|
|
);
|
|
|
|
//
|
|
shortPushers += tmpShortPushers;
|
|
}
|
|
volumeOSC += mConditions.vlmConditions.volume[1];
|
|
mConditions.GenerateScore(
|
|
tmpBullishScore,
|
|
tmpBearishScore //
|
|
);
|
|
bullishScore += tmpBullishScore;
|
|
bearishScore += tmpBearishScore;
|
|
|
|
//
|
|
// Long ...
|
|
X121SetupConditions lConditions;
|
|
bool lHasConditions = setups[idx].GetConditions(
|
|
lConditions,
|
|
X_MARKET_CYCLE_LONG //
|
|
);
|
|
if (!lHasConditions)
|
|
{
|
|
continue;
|
|
}
|
|
XSCZones *lZones = setups[idx].GetZones(
|
|
X_MARKET_CYCLE_LONG //
|
|
);
|
|
bool isLValidForLong = signalGenerator.IsConditionsValidForLong(
|
|
lConditions,
|
|
reqValidation //
|
|
);
|
|
if (isLValidForLong)
|
|
{
|
|
longVerifications += reqValidation;
|
|
}
|
|
bool isLValidForShort = signalGenerator.IsConditionsValidForShort(
|
|
lConditions,
|
|
reqValidation //
|
|
);
|
|
if (isLValidForShort)
|
|
{
|
|
shortVerifications += reqValidation;
|
|
}
|
|
bool lHasLongConditions = signalGenerator.HasLongConditions(
|
|
lConditions,
|
|
tmpLongPushers,
|
|
tmpProvider //
|
|
);
|
|
if (lHasLongConditions)
|
|
{
|
|
//
|
|
AddSpecific(
|
|
tmpProvider,
|
|
longProviders //
|
|
);
|
|
|
|
//
|
|
longPushers += tmpLongPushers;
|
|
}
|
|
bool lHasShortConditions = signalGenerator.HasShortConditions(
|
|
lConditions,
|
|
tmpShortPushers,
|
|
tmpProvider //
|
|
);
|
|
if (lHasShortConditions)
|
|
{
|
|
//
|
|
AddSpecific(
|
|
tmpProvider,
|
|
shortProviders //
|
|
);
|
|
|
|
//
|
|
shortPushers += tmpShortPushers;
|
|
}
|
|
volumeOSC += lConditions.vlmConditions.volume[1];
|
|
lConditions.GenerateScore(
|
|
tmpBullishScore,
|
|
tmpBearishScore //
|
|
);
|
|
bullishScore += tmpBullishScore;
|
|
bearishScore += tmpBearishScore;
|
|
|
|
//
|
|
// Hind ...
|
|
X121SetupConditions hConditions;
|
|
bool hHasConditions = setups[idx].GetConditions(
|
|
hConditions,
|
|
X_MARKET_CYCLE_HIND //
|
|
);
|
|
if (!hHasConditions)
|
|
{
|
|
continue;
|
|
}
|
|
XSCZones *hZones = setups[idx].GetZones(
|
|
X_MARKET_CYCLE_HIND //
|
|
);
|
|
bool isHValidForLong = signalGenerator.IsConditionsValidForLong(
|
|
hConditions,
|
|
reqValidation //
|
|
);
|
|
if (isHValidForLong)
|
|
{
|
|
longVerifications += reqValidation;
|
|
}
|
|
bool isHValidForShort = signalGenerator.IsConditionsValidForShort(
|
|
hConditions,
|
|
reqValidation //
|
|
);
|
|
if (isHValidForShort)
|
|
{
|
|
shortVerifications += reqValidation;
|
|
}
|
|
bool hHasLongConditions = signalGenerator.HasLongConditions(
|
|
hConditions,
|
|
tmpLongPushers,
|
|
tmpProvider //
|
|
);
|
|
if (hHasLongConditions)
|
|
{
|
|
//
|
|
AddSpecific(
|
|
tmpProvider,
|
|
longProviders //
|
|
);
|
|
|
|
//
|
|
longPushers += tmpLongPushers;
|
|
}
|
|
bool hHasShortConditions = signalGenerator.HasShortConditions(
|
|
hConditions,
|
|
tmpShortPushers,
|
|
tmpProvider //
|
|
);
|
|
if (hHasShortConditions)
|
|
{
|
|
//
|
|
AddSpecific(
|
|
tmpProvider,
|
|
shortProviders //
|
|
);
|
|
|
|
//
|
|
shortPushers += tmpShortPushers;
|
|
}
|
|
volumeOSC += hConditions.vlmConditions.volume[1];
|
|
hConditions.GenerateScore(
|
|
tmpBullishScore,
|
|
tmpBearishScore //
|
|
);
|
|
bullishScore += tmpBullishScore;
|
|
bearishScore += tmpBearishScore;
|
|
|
|
|
|
|
|
////////////////////////////////////////////////////////
|
|
|
|
|
|
//
|
|
// Place EQM Orders ...
|
|
void PlaceEQMOrders()
|
|
{
|
|
//
|
|
int count = CountSetups();
|
|
if (!IsValidSize(count))
|
|
{
|
|
return;
|
|
}
|
|
|
|
//
|
|
XSignal supports[];
|
|
|
|
//
|
|
for (int i = 0; i < count; i++)
|
|
{
|
|
//
|
|
string iSymbol = mSetups[i].GetSymbol();
|
|
ENUM_TIMEFRAMES iPeriod = NULL; // All Periods ...
|
|
string iProvider = NULL; // All Providers ...
|
|
|
|
//
|
|
XPosition iPositions[];
|
|
int iPositionsCount = mTrader.GetPositions(
|
|
iPositions,
|
|
iSymbol,
|
|
iProvider,
|
|
iPeriod,
|
|
X_POSITION_TYPE_ALL //
|
|
);
|
|
if (!IsValidSize(iPositionsCount))
|
|
{
|
|
continue;
|
|
}
|
|
|
|
//
|
|
int maxInDIDX = FindMaxDrawdownIndex(
|
|
iPositions //
|
|
);
|
|
if (!IsValidIndex(maxInDIDX))
|
|
{
|
|
continue;
|
|
}
|
|
|
|
//
|
|
XPosition maxInDP = iPositions[maxInDIDX];
|
|
bool isLong = IsLong(maxInDP.type);
|
|
|
|
//
|
|
XOHCL iZBar;
|
|
bool isInited = iZBar.Init(
|
|
iSymbol,
|
|
iPeriod,
|
|
0 //
|
|
);
|
|
if (!isInited)
|
|
{
|
|
continue;
|
|
}
|
|
|
|
//
|
|
double iSupport = 0;
|
|
double iResistance = 0;
|
|
bool isDrawn = DrawTrendState(
|
|
ChartID(),
|
|
"XTRND",
|
|
iZBar,
|
|
iSupport,
|
|
iResistance //
|
|
);
|
|
if (isDrawn)
|
|
{
|
|
//
|
|
XSignal iSignal;
|
|
|
|
//
|
|
double iSL = 0;
|
|
double iTP = 0;
|
|
double iEntry = 0;
|
|
ENUM_POSITION_TYPE iType;
|
|
ENUM_X_ORDER_MODES iMode;
|
|
double iVolume = maxInDP.volume * 3;
|
|
|
|
//
|
|
if (iSupport > 0 && isLong && iSupport > maxInDP.sl && maxInDP.sl > 0)
|
|
{
|
|
//
|
|
// Add Short Support for Long ...
|
|
iEntry = iSupport;
|
|
iSL = maxInDP.tp;
|
|
iTP = maxInDP.sl;
|
|
iMode = X_ORDER_MODE_STOP;
|
|
iType = POSITION_TYPE_SELL;
|
|
|
|
//
|
|
bool isPrepared = iSignal.Prepare(
|
|
iSymbol,
|
|
XEQMSupportToken,
|
|
iPeriod,
|
|
iType,
|
|
iMode,
|
|
iEntry,
|
|
iVolume,
|
|
iSL,
|
|
iTP //
|
|
);
|
|
if (isPrepared)
|
|
{
|
|
//
|
|
iSignal.comment = GenerateSupportTag(maxInDP.ticket);
|
|
|
|
//
|
|
AddRef(
|
|
iSignal,
|
|
supports ///
|
|
);
|
|
|
|
//
|
|
iSignal.Clean();
|
|
}
|
|
}
|
|
|
|
//
|
|
if (iResistance > 0 && !isLong && iResistance < maxInDP.sl && maxInDP.sl > 0)
|
|
{
|
|
//
|
|
// Add Long Support for Short ...
|
|
iEntry = iResistance;
|
|
iSL = maxInDP.tp;
|
|
iTP = maxInDP.sl;
|
|
iMode = X_ORDER_MODE_STOP;
|
|
iType = POSITION_TYPE_BUY;
|
|
|
|
//
|
|
bool isPrepared = iSignal.Prepare(
|
|
iSymbol,
|
|
XEQMSupportToken,
|
|
iPeriod,
|
|
iType,
|
|
iMode,
|
|
iEntry,
|
|
iVolume,
|
|
iSL,
|
|
iTP //
|
|
);
|
|
if (isPrepared)
|
|
{
|
|
//
|
|
iSignal.comment = GenerateSupportTag(maxInDP.ticket);
|
|
|
|
//
|
|
AddRef(
|
|
iSignal,
|
|
supports ///
|
|
);
|
|
|
|
//
|
|
iSignal.Clean();
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
//
|
|
int supportsCount = ArraySize(supports);
|
|
if (!IsValidSize(supportsCount))
|
|
{
|
|
return;
|
|
}
|
|
|
|
//
|
|
ENUM_X_SIGNAL_EXECUTION_RESULT states[];
|
|
int executeds = mTrader.ExecuteSignals(
|
|
supports,
|
|
states,
|
|
ORDER_TIME_GTC,
|
|
false,
|
|
false // Ignore Policies
|
|
);
|
|
if (IsValidSize(executeds))
|
|
{
|
|
//
|
|
string message = XEQMSupportToken + " Execute " + ToString(executeds) + " Supports ...";
|
|
|
|
//
|
|
Alert(message);
|
|
}
|
|
}
|