8021 lines
187 KiB
Plaintext
8021 lines
187 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);
|
|
}
|
|
}
|
|
|
|
/////////////////////////////////////////////////////////
|
|
|
|
// //
|
|
// XSignal tmpSignal;
|
|
// tmpSignal.Clean();
|
|
|
|
// //
|
|
// double longEntry = GetEntry(
|
|
// iPosition.symbol,
|
|
// POSITION_TYPE_BUY //
|
|
// );
|
|
// double shortEntry = GetEntry(
|
|
// iPosition.symbol,
|
|
// POSITION_TYPE_SELL //
|
|
// );
|
|
// double mVolume = iPosition.volume * 2;
|
|
// double mSL = 0;
|
|
// double mTP = 0;
|
|
|
|
// //
|
|
// bool isLong = IsLong(iPosition.type);
|
|
|
|
// //
|
|
// // Here we Can Start a Recovery Zone ...
|
|
// if (data[index].rLongEntry <= 0 &&
|
|
// data[index].rShortEntry <= 0 &&
|
|
// data[index].rVolume <= 0)
|
|
// {
|
|
// //
|
|
// data[index].PrepareNextRecovery(
|
|
// supportDistance,
|
|
// volumeMultiplier,
|
|
// iPosition.type //
|
|
// );
|
|
// }
|
|
// else
|
|
// {
|
|
// //
|
|
// bool hasRecovery = data[index].HasRecovery(
|
|
// tmpSignal,
|
|
// supportDistance,
|
|
// volumeMultiplier //
|
|
// );
|
|
// if (hasRecovery)
|
|
// {
|
|
// //
|
|
// // tmpSignal.sl = 0;
|
|
// // tmpSignal.tp = 0;
|
|
// string comment = GenerateEQMSupportTag(iPosition.ticket);
|
|
// tmpSignal.comment = comment;
|
|
|
|
// //
|
|
// AddRef(
|
|
// tmpSignal,
|
|
// signals //
|
|
// );
|
|
// }
|
|
// else if (priceDiffPoints >= supportDistance)
|
|
// {
|
|
// //
|
|
// // Reset
|
|
// if (longEntry > data[index].rZoneUpper || shortEntry < data[index].rZoneLower)
|
|
// {
|
|
// //
|
|
// // data[index].ResetRecovery();
|
|
|
|
// //
|
|
// }
|
|
// }
|
|
// }
|
|
|
|
///////////////////////////////////////////////////////////////
|
|
|
|
//
|
|
// Create an Instance of Signal Generator Structure ...
|
|
X121SignalGenerator signalGenerator;
|
|
|
|
//
|
|
int signalConditionsIDX = FindSignalConditionsIndex(
|
|
signal,
|
|
conditions //
|
|
);
|
|
if (!IsValidIndex(signalConditionsIDX))
|
|
{
|
|
return;
|
|
}
|
|
|
|
//
|
|
int longValidations = 0;
|
|
int shortValidations = 0;
|
|
|
|
//
|
|
bool isOSCValidForLong = signalGenerator
|
|
.IsOSCLongVerified(conditions[signalConditionsIDX]);
|
|
bool isOSCValidForShort = signalGenerator
|
|
.IsOSCShortVerified(conditions[signalConditionsIDX]);
|
|
|
|
//
|
|
// Calculate Long/Short Validations ...
|
|
for (int i = 0; i < ArraySize(conditions); i++)
|
|
{
|
|
//
|
|
int longValids = signalGenerator
|
|
.CountLongValidations(conditions[i]);
|
|
longValidations += longValids;
|
|
|
|
//
|
|
int shortValids = signalGenerator
|
|
.CountShortValidations(conditions[i]);
|
|
shortValidations += shortValids;
|
|
}
|
|
|
|
//
|
|
bool isLong = IsLong(signal.type);
|
|
|
|
//
|
|
// Reading Required Informations ...
|
|
XPosition positions[];
|
|
int positionsCount = mTrader.GetPositions(positions);
|
|
if (!IsValidSize(positionsCount))
|
|
{
|
|
return;
|
|
}
|
|
|
|
//
|
|
int longs = 0;
|
|
double longVolumes = 0;
|
|
double longProfits = 0;
|
|
|
|
//
|
|
int shorts = 0;
|
|
double shortVolumes = 0;
|
|
double shortProfits = 0;
|
|
|
|
//
|
|
// Retrieve Required Informations of Positions ...
|
|
CountPositions(
|
|
positions,
|
|
longs,
|
|
longProfits,
|
|
longVolumes,
|
|
shorts,
|
|
shortProfits,
|
|
shortVolumes //
|
|
);
|
|
|
|
//
|
|
longVolumes = NormalizeDouble(longVolumes, 2);
|
|
shortVolumes = NormalizeDouble(shortVolumes, 2);
|
|
|
|
//
|
|
// Select Signal for Execution ...
|
|
bool canSelect =
|
|
//
|
|
((isLong &&
|
|
longProfits > 0 &&
|
|
bullishScore > 20)
|
|
//
|
|
||
|
|
//
|
|
(!isLong &&
|
|
shortProfits > 0 &&
|
|
bearishScore > 0))
|
|
//
|
|
&&
|
|
//
|
|
longVolumes == shortVolumes
|
|
//
|
|
;
|
|
if (canSelect)
|
|
{
|
|
//
|
|
// Here we Can do Signals SL TP Manipulations ...
|
|
signal.tp = 0;
|
|
signal.sl = 0;
|
|
|
|
//
|
|
XSignal signals[];
|
|
AddRef(
|
|
signal,
|
|
signals //
|
|
);
|
|
|
|
//
|
|
// Add new Signal Info ...
|
|
mTradeHandler.Add(
|
|
signal,
|
|
pushers,
|
|
volumeOSC,
|
|
bullishSigns,
|
|
bearishSigns,
|
|
bullishScore,
|
|
bearishScore,
|
|
conditions[0],
|
|
conditions[1],
|
|
conditions[2],
|
|
conditions[3],
|
|
conditions[4] //
|
|
);
|
|
|
|
//
|
|
EQMExecuteSignals(signals);
|
|
|
|
//
|
|
return;
|
|
}
|
|
|
|
//
|
|
canSelect =
|
|
//
|
|
((isLong && shortProfits > 0) ||
|
|
(!isLong && longProfits > 0))
|
|
//
|
|
&&
|
|
//
|
|
longVolumes == shortVolumes
|
|
//
|
|
;
|
|
if (canSelect)
|
|
{
|
|
//
|
|
// Generate Opposit Signal ...
|
|
|
|
//
|
|
signal.tp = 0;
|
|
signal.sl = 0;
|
|
|
|
//
|
|
XSignal oppositSignal;
|
|
bool isGenerated = signal.GenerateOpposit(
|
|
oppositSignal //
|
|
);
|
|
|
|
//
|
|
if (isGenerated)
|
|
{
|
|
//
|
|
XSignal signals[];
|
|
AddRef(
|
|
oppositSignal,
|
|
signals //
|
|
);
|
|
|
|
//
|
|
// Add new Signal Info ...
|
|
mTradeHandler.Add(
|
|
oppositSignal,
|
|
pushers,
|
|
volumeOSC,
|
|
bullishSigns,
|
|
bearishSigns,
|
|
bullishScore,
|
|
bearishScore,
|
|
conditions[0],
|
|
conditions[1],
|
|
conditions[2],
|
|
conditions[3],
|
|
conditions[4] //
|
|
);
|
|
|
|
//
|
|
EQMExecuteSignals(signals);
|
|
|
|
//
|
|
return;
|
|
}
|
|
}
|
|
|
|
////////////////////////////////////////////////////////////////////////
|
|
|
|
//
|
|
XPosition positions[];
|
|
int positionsCount = mTrader.GetPositions(positions);
|
|
if (!IsValidSize(positionsCount))
|
|
{
|
|
return;
|
|
}
|
|
|
|
//
|
|
int longs = 0;
|
|
double longVolumes = 0;
|
|
double longProfits = 0;
|
|
|
|
//
|
|
int shorts = 0;
|
|
double shortVolumes = 0;
|
|
double shortProfits = 0;
|
|
|
|
//
|
|
// Retrieve Required Informations of Positions ...
|
|
CountPositions(
|
|
positions,
|
|
longs,
|
|
longProfits,
|
|
longVolumes,
|
|
shorts,
|
|
shortProfits,
|
|
shortVolumes //
|
|
);
|
|
|
|
//
|
|
longVolumes = NormalizeDouble(longVolumes, 2);
|
|
shortVolumes = NormalizeDouble(shortVolumes, 2);
|
|
|
|
//
|
|
if (isValid)
|
|
{
|
|
//
|
|
// Ignore Hind Time Frame Signals ...
|
|
|
|
//
|
|
signal.volume *= 1;
|
|
|
|
//
|
|
// Here we Can do Signals SL TP Manipulations ...
|
|
signal.tp = 0;
|
|
signal.sl = 0;
|
|
|
|
//
|
|
signal.provider = XEQMSupportToken;
|
|
signal.comment = GenerateEQMSupportTag(0);
|
|
|
|
//
|
|
bool isLong = IsLong(signal.type);
|
|
|
|
//
|
|
bool canDirect =
|
|
//
|
|
(isLong &&
|
|
longProfits > shortProfits)
|
|
//
|
|
||
|
|
//
|
|
(!isLong &&
|
|
shortProfits > longProfits)
|
|
//
|
|
;
|
|
bool canInDirect =
|
|
//
|
|
(isLong &&
|
|
shortProfits > longProfits)
|
|
//
|
|
||
|
|
//
|
|
(!isLong &&
|
|
longProfits > shortProfits)
|
|
//
|
|
;
|
|
|
|
//
|
|
XSignal tmpSignal;
|
|
if (canDirect)
|
|
{
|
|
tmpSignal = signal;
|
|
}
|
|
else
|
|
{
|
|
//
|
|
bool isGenerated = signal.GenerateOpposit(
|
|
tmpSignal //
|
|
);
|
|
|
|
//
|
|
if (!isGenerated)
|
|
{
|
|
tmpSignal.Clean();
|
|
}
|
|
}
|
|
|
|
//
|
|
if (tmpSignal.IsValid())
|
|
{
|
|
//
|
|
XSignal signals[];
|
|
AddRef(
|
|
signal,
|
|
signals //
|
|
);
|
|
|
|
//
|
|
// Add new Signal Info ...
|
|
mTradeHandler.Add(
|
|
signal,
|
|
pushers,
|
|
volumeOSC,
|
|
bullishSigns,
|
|
bearishSigns,
|
|
bullishScore,
|
|
bearishScore,
|
|
conditions[0],
|
|
conditions[1],
|
|
conditions[2],
|
|
conditions[3],
|
|
conditions[4] //
|
|
);
|
|
|
|
//
|
|
EQMExecuteSignals(signals);
|
|
}
|
|
return;
|
|
}
|
|
|
|
//////////////////////////////////////////////////////////////////////
|
|
|
|
// //
|
|
// // Check Signal Has TP and SL ...
|
|
// if (signal.tp > 0 && signal.sl > 0)
|
|
// {
|
|
// //
|
|
// // Here we Can Provide Orders based on Signal TP and SL ...
|
|
|
|
// //
|
|
// // Calculate TP/Entry Distance ...
|
|
// double tpDistance =
|
|
// isLong
|
|
// ? signal.tp - signal.entry
|
|
// : signal.entry - signal.tp;
|
|
|
|
// //
|
|
// // Calculate Recovery Zone Step ...
|
|
// double slDistance =
|
|
// isLong
|
|
// ? signal.entry - signal.sl
|
|
// : signal.sl - signal.entry;
|
|
// }
|
|
|
|
// //
|
|
// // Add Zone Based Signals ...
|
|
// if (canUseZones)
|
|
// {
|
|
// //
|
|
// // signal.zones.DrawZones();
|
|
|
|
// //
|
|
// // Try to Find a Hot Level based on Signal Direction
|
|
// // as Resistance ...
|
|
|
|
// //
|
|
// for (int i = 0; i < signal.zones.CountZones(); i++)
|
|
// {
|
|
// //
|
|
// // Retrieve Indexed Zone ...
|
|
// XSCZone *iZone = signal.zones.GetZone(i);
|
|
|
|
// //
|
|
// // Check Zone is Hot Zone or not ...
|
|
// bool isHotZone = false;
|
|
// for (int j = 0; j < ArraySize(hotLevels); j++)
|
|
// {
|
|
// //
|
|
// isHotZone = (iZone.percent / 100 >= hotLevels[j]);
|
|
// if (isHotZone)
|
|
// {
|
|
// break;
|
|
// }
|
|
// }
|
|
|
|
// //
|
|
// // Prevent Moving Forward if there isn't Hot Zone ...
|
|
// if (!isHotZone)
|
|
// {
|
|
// continue;
|
|
// }
|
|
|
|
// //
|
|
// if (iZone.high > signal.entry && iZone.low > signal.entry)
|
|
// {
|
|
// //
|
|
// // Here we can Use Resistance Zone as SL Recovery for
|
|
// // Short Positions ...
|
|
// if (!isLong &&
|
|
// (signal.sl <= 0
|
|
// ? true
|
|
// : iZone.high < signal.sl && iZone.low < signal.sl))
|
|
// {
|
|
// //
|
|
// // Opposit Support on Resistance Upper ...
|
|
|
|
// //
|
|
// // rTP = signal.sl <= 0
|
|
// // ? iZone.high - (onePointValue * 15)
|
|
// // : signal.sl;
|
|
// // rSL = signal.entry;
|
|
// rType = POSITION_TYPE_BUY;
|
|
// rEntry = iZone.high + (onePointValue * 2);
|
|
// rMode = X_ORDER_MODE_STOP;
|
|
|
|
// //
|
|
// isSignalPrepared = rSignal.Prepare(
|
|
// signal.symbol,
|
|
// signal.provider,
|
|
// signal.period,
|
|
// rType,
|
|
// rMode,
|
|
// rEntry,
|
|
// rVolume,
|
|
// rSL,
|
|
// rTP //
|
|
// );
|
|
// if (isSignalPrepared)
|
|
// {
|
|
// //
|
|
// AddRef(
|
|
// rSignal,
|
|
// signal.supports //
|
|
// );
|
|
|
|
// //
|
|
// rSignal.Clean();
|
|
|
|
// //
|
|
// rSL = 0;
|
|
// rTP = 0;
|
|
// rEntry = 0;
|
|
// isSignalPrepared = false;
|
|
// }
|
|
|
|
// //
|
|
// // Support Directional on Resistance Lower ...
|
|
|
|
// //
|
|
// // rTP = signal.entry;
|
|
// // rSL = signal.sl <= 0
|
|
// // ? signal.entry - (onePointValue * 15)
|
|
// // : signal.sl;
|
|
// rEntry = iZone.low - (onePointValue * 2);
|
|
// rVolume = signal.volume * 3;
|
|
// rType = POSITION_TYPE_SELL;
|
|
// rMode = X_ORDER_MODE_LIMIT;
|
|
|
|
// //
|
|
// isSignalPrepared = rSignal.Prepare(
|
|
// signal.symbol,
|
|
// signal.provider,
|
|
// signal.period,
|
|
// rType,
|
|
// rMode,
|
|
// rEntry,
|
|
// rVolume,
|
|
// rSL,
|
|
// rTP //
|
|
// );
|
|
// if (isSignalPrepared)
|
|
// {
|
|
// //
|
|
// AddRef(
|
|
// rSignal,
|
|
// signal.supports //
|
|
// );
|
|
|
|
// //
|
|
// rSignal.Clean();
|
|
|
|
// //
|
|
// rSL = 0;
|
|
// rTP = 0;
|
|
// rEntry = 0;
|
|
// isSignalPrepared = false;
|
|
// rVolume = signal.volume * 2;
|
|
// }
|
|
// }
|
|
// }
|
|
|
|
// //
|
|
// if (iZone.high < signal.entry && iZone.low < signal.entry)
|
|
// {
|
|
// //
|
|
// }
|
|
// }
|
|
// }
|
|
|
|
// //
|
|
// if (canUseTrend)
|
|
// {
|
|
// //
|
|
// // Check Ask and Bid Price ...
|
|
|
|
// //
|
|
// XOHCL fHighBar = signal.trend.GetFirstSwingHighBar();
|
|
// XOHCL sHighBar = signal.trend.GetSecondSwingHighBar();
|
|
|
|
// //
|
|
// XOHCL fLowBar = signal.trend.GetFirstSwingLowBar();
|
|
// XOHCL sLowBar = signal.trend.GetSecondSwingLowBar();
|
|
|
|
// //
|
|
// double twoPoint = onePointValue * 2;
|
|
// double fiftyPoint = onePointValue * 15;
|
|
|
|
// //
|
|
// // add resistance ...
|
|
// bool canAdd =
|
|
// isLong &&
|
|
// entryPrice < (sHighBar.high - fiftyPoint);
|
|
// if (canAdd)
|
|
// {
|
|
// //
|
|
// rSignal.Clean();
|
|
|
|
// //
|
|
// rEntry = sHighBar.high - fiftyPoint;
|
|
// rType = POSITION_TYPE_BUY;
|
|
// rMode = X_ORDER_MODE_STOP;
|
|
// rVolume = signal.volume * 2;
|
|
|
|
// //
|
|
// isSignalPrepared = rSignal.Prepare(
|
|
// signal.symbol,
|
|
// signal.provider,
|
|
// signal.period,
|
|
// rType,
|
|
// rMode,
|
|
// rEntry,
|
|
// rVolume,
|
|
// rSL,
|
|
// rTP //
|
|
// );
|
|
// if (isSignalPrepared)
|
|
// {
|
|
// //
|
|
// AddRef(
|
|
// rSignal,
|
|
// signal.supports //
|
|
// );
|
|
|
|
// //
|
|
// rSignal.Clean();
|
|
|
|
// //
|
|
// rSL = 0;
|
|
// rTP = 0;
|
|
// rEntry = 0;
|
|
// isSignalPrepared = false;
|
|
// }
|
|
|
|
// //
|
|
// rEntry = sHighBar.high - fiftyPoint;
|
|
// rType = POSITION_TYPE_SELL;
|
|
// rMode = X_ORDER_MODE_LIMIT;
|
|
// rVolume = signal.volume * 3;
|
|
|
|
// //
|
|
// isSignalPrepared = rSignal.Prepare(
|
|
// signal.symbol,
|
|
// signal.provider,
|
|
// signal.period,
|
|
// rType,
|
|
// rMode,
|
|
// rEntry,
|
|
// rVolume,
|
|
// rSL,
|
|
// rTP //
|
|
// );
|
|
// if (isSignalPrepared)
|
|
// {
|
|
// //
|
|
// AddRef(
|
|
// rSignal,
|
|
// signal.supports //
|
|
// );
|
|
|
|
// //
|
|
// rSignal.Clean();
|
|
|
|
// //
|
|
// rSL = 0;
|
|
// rTP = 0;
|
|
// rEntry = 0;
|
|
// isSignalPrepared = false;
|
|
// }
|
|
// }
|
|
|
|
// //
|
|
// canAdd =
|
|
// isLong &&
|
|
// entryPrice > (sLowBar.low + fiftyPoint);
|
|
// if (canAdd)
|
|
// {
|
|
// //
|
|
// rSignal.Clean();
|
|
|
|
// //
|
|
// rEntry = (sLowBar.low + fiftyPoint);
|
|
// rType = POSITION_TYPE_SELL;
|
|
// rMode = X_ORDER_MODE_STOP;
|
|
// rVolume = signal.volume * 2;
|
|
|
|
// //
|
|
// isSignalPrepared = rSignal.Prepare(
|
|
// signal.symbol,
|
|
// signal.provider,
|
|
// signal.period,
|
|
// rType,
|
|
// rMode,
|
|
// rEntry,
|
|
// rVolume,
|
|
// rSL,
|
|
// rTP //
|
|
// );
|
|
// if (isSignalPrepared)
|
|
// {
|
|
// //
|
|
// AddRef(
|
|
// rSignal,
|
|
// signal.supports //
|
|
// );
|
|
|
|
// //
|
|
// rSignal.Clean();
|
|
|
|
// //
|
|
// rSL = 0;
|
|
// rTP = 0;
|
|
// rEntry = 0;
|
|
// isSignalPrepared = false;
|
|
// }
|
|
|
|
// //
|
|
// rEntry = (sLowBar.low - fiftyPoint);
|
|
// rType = POSITION_TYPE_BUY;
|
|
// rMode = X_ORDER_MODE_LIMIT;
|
|
// rVolume = signal.volume * 3;
|
|
|
|
// //
|
|
// isSignalPrepared = rSignal.Prepare(
|
|
// signal.symbol,
|
|
// signal.provider,
|
|
// signal.period,
|
|
// rType,
|
|
// rMode,
|
|
// rEntry,
|
|
// rVolume,
|
|
// rSL,
|
|
// rTP //
|
|
// );
|
|
// if (isSignalPrepared)
|
|
// {
|
|
// //
|
|
// AddRef(
|
|
// rSignal,
|
|
// signal.supports //
|
|
// );
|
|
|
|
// //
|
|
// rSignal.Clean();
|
|
|
|
// //
|
|
// rSL = 0;
|
|
// rTP = 0;
|
|
// rEntry = 0;
|
|
// isSignalPrepared = false;
|
|
// }
|
|
// }
|
|
|
|
// //
|
|
// // add support ...
|
|
// canAdd =
|
|
// !isLong &&
|
|
// entryPrice > (sLowBar.low + fiftyPoint);
|
|
// if (canAdd)
|
|
// {
|
|
// //
|
|
// rSignal.Clean();
|
|
|
|
// //
|
|
// rEntry = sLowBar.low + fiftyPoint;
|
|
// rType = POSITION_TYPE_SELL;
|
|
// rMode = X_ORDER_MODE_STOP;
|
|
// rVolume = signal.volume * 2;
|
|
|
|
// //
|
|
// isSignalPrepared = rSignal.Prepare(
|
|
// signal.symbol,
|
|
// signal.provider,
|
|
// signal.period,
|
|
// rType,
|
|
// rMode,
|
|
// rEntry,
|
|
// rVolume,
|
|
// rSL,
|
|
// rTP //
|
|
// );
|
|
// if (isSignalPrepared)
|
|
// {
|
|
// //
|
|
// AddRef(
|
|
// rSignal,
|
|
// signal.supports //
|
|
// );
|
|
|
|
// //
|
|
// rSignal.Clean();
|
|
|
|
// //
|
|
// rSL = 0;
|
|
// rTP = 0;
|
|
// rEntry = 0;
|
|
// isSignalPrepared = false;
|
|
// }
|
|
|
|
// //
|
|
// rEntry = sLowBar.low + fiftyPoint;
|
|
// rType = POSITION_TYPE_BUY;
|
|
// rMode = X_ORDER_MODE_LIMIT;
|
|
// rVolume = signal.volume * 3;
|
|
|
|
// //
|
|
// isSignalPrepared = rSignal.Prepare(
|
|
// signal.symbol,
|
|
// signal.provider,
|
|
// signal.period,
|
|
// rType,
|
|
// rMode,
|
|
// rEntry,
|
|
// rVolume,
|
|
// rSL,
|
|
// rTP //
|
|
// );
|
|
// if (isSignalPrepared)
|
|
// {
|
|
// //
|
|
// AddRef(
|
|
// rSignal,
|
|
// signal.supports //
|
|
// );
|
|
|
|
// //
|
|
// rSignal.Clean();
|
|
|
|
// //
|
|
// rSL = 0;
|
|
// rTP = 0;
|
|
// rEntry = 0;
|
|
// isSignalPrepared = false;
|
|
// }
|
|
// }
|
|
|
|
// //
|
|
// canAdd =
|
|
// !isLong &&
|
|
// entryPrice < (sHighBar.high - fiftyPoint);
|
|
// if (canAdd)
|
|
// {
|
|
// //
|
|
// rSignal.Clean();
|
|
|
|
// //
|
|
// rEntry = (sHighBar.high - fiftyPoint);
|
|
// rType = POSITION_TYPE_BUY;
|
|
// rMode = X_ORDER_MODE_STOP;
|
|
// rVolume = signal.volume * 2;
|
|
|
|
// //
|
|
// isSignalPrepared = rSignal.Prepare(
|
|
// signal.symbol,
|
|
// signal.provider,
|
|
// signal.period,
|
|
// rType,
|
|
// rMode,
|
|
// rEntry,
|
|
// rVolume,
|
|
// rSL,
|
|
// rTP //
|
|
// );
|
|
// if (isSignalPrepared)
|
|
// {
|
|
// //
|
|
// AddRef(
|
|
// rSignal,
|
|
// signal.supports //
|
|
// );
|
|
|
|
// //
|
|
// rSignal.Clean();
|
|
|
|
// //
|
|
// rSL = 0;
|
|
// rTP = 0;
|
|
// rEntry = 0;
|
|
// isSignalPrepared = false;
|
|
// }
|
|
|
|
// //
|
|
// rEntry = (sHighBar.high - fiftyPoint);
|
|
// rType = POSITION_TYPE_SELL;
|
|
// rMode = X_ORDER_MODE_LIMIT;
|
|
// rVolume = signal.volume * 3;
|
|
|
|
// //
|
|
// isSignalPrepared = rSignal.Prepare(
|
|
// signal.symbol,
|
|
// signal.provider,
|
|
// signal.period,
|
|
// rType,
|
|
// rMode,
|
|
// rEntry,
|
|
// rVolume,
|
|
// rSL,
|
|
// rTP //
|
|
// );
|
|
// if (isSignalPrepared)
|
|
// {
|
|
// //
|
|
// AddRef(
|
|
// rSignal,
|
|
// signal.supports //
|
|
// );
|
|
|
|
// //
|
|
// rSignal.Clean();
|
|
|
|
// //
|
|
// rSL = 0;
|
|
// rTP = 0;
|
|
// rEntry = 0;
|
|
// isSignalPrepared = false;
|
|
// }
|
|
// }
|
|
// }
|
|
|
|
///////////////////////////////////////////////////////////////
|
|
|
|
//
|
|
// Directional ...
|
|
rEntry = signal.entry;
|
|
rType = POSITION_TYPE_SELL;
|
|
rMode = X_ORDER_MODE_LIMIT;
|
|
rVolume = signal.volume * directionalVolumeMultiplier;
|
|
|
|
//
|
|
isSignalPrepared = rSignal.Prepare(
|
|
signal.symbol,
|
|
XEQMSupportToken,
|
|
signal.period,
|
|
rType,
|
|
rMode,
|
|
rEntry,
|
|
rVolume,
|
|
rSL,
|
|
rTP //
|
|
);
|
|
if (isSignalPrepared)
|
|
{
|
|
//
|
|
AddRef(
|
|
rSignal,
|
|
signal.supports //
|
|
);
|
|
|
|
//
|
|
rSignal.Clean();
|
|
|
|
//
|
|
rSL = 0;
|
|
rTP = 0;
|
|
rEntry = 0;
|
|
isSignalPrepared = false;
|
|
}
|
|
|
|
//
|
|
// Directional ...
|
|
rEntry = signal.entry;
|
|
rType = POSITION_TYPE_SELL;
|
|
rMode = X_ORDER_MODE_STOP;
|
|
rVolume = signal.volume * directionalVolumeMultiplier;
|
|
|
|
//
|
|
isSignalPrepared = rSignal.Prepare(
|
|
signal.symbol,
|
|
XEQMSupportToken,
|
|
signal.period,
|
|
rType,
|
|
rMode,
|
|
rEntry,
|
|
rVolume,
|
|
rSL,
|
|
rTP //
|
|
);
|
|
if (isSignalPrepared)
|
|
{
|
|
//
|
|
AddRef(
|
|
rSignal,
|
|
signal.supports //
|
|
);
|
|
|
|
//
|
|
rSignal.Clean();
|
|
|
|
//
|
|
rSL = 0;
|
|
rTP = 0;
|
|
rEntry = 0;
|
|
isSignalPrepared = false;
|
|
}
|
|
|
|
///////////////////////////////////////////////////////////////////////
|
|
|
|
//
|
|
if (canUseCF)
|
|
{
|
|
//
|
|
signal.cf.Draw();
|
|
XOHCL cfBULLBar = signal.cf.GetBullishBar();
|
|
XOHCL cfBEARBar = signal.cf.GetBearishBar();
|
|
|
|
//
|
|
if (isLong)
|
|
{
|
|
//
|
|
// Supports For Longs ...
|
|
|
|
//
|
|
// CF Bullish ...
|
|
|
|
//
|
|
// HIGH ...
|
|
|
|
//
|
|
condition = entryPrice < cfBULLBar.high;
|
|
if (condition)
|
|
{
|
|
//
|
|
// InDirectional ...
|
|
rEntry = cfBULLBar.high;
|
|
rType = POSITION_TYPE_SELL;
|
|
rMode = X_ORDER_MODE_LIMIT;
|
|
rVolume = signal.volume * inDirectionalVolumeMultiplier;
|
|
|
|
//
|
|
isSignalPrepared = rSignal.Prepare(
|
|
signal.symbol,
|
|
XEQMSupportToken + XINDirectionalToken,
|
|
signal.period,
|
|
rType,
|
|
rMode,
|
|
rEntry,
|
|
rVolume,
|
|
rSL,
|
|
rTP //
|
|
);
|
|
if (isSignalPrepared)
|
|
{
|
|
//
|
|
AddRef(
|
|
rSignal,
|
|
signal.supports //
|
|
);
|
|
|
|
//
|
|
rSignal.Clean();
|
|
|
|
//
|
|
rSL = 0;
|
|
rTP = 0;
|
|
rEntry = 0;
|
|
isSignalPrepared = false;
|
|
}
|
|
}
|
|
|
|
//
|
|
condition = entryPrice > cfBULLBar.high;
|
|
if (condition)
|
|
{
|
|
//
|
|
// InDirectional ...
|
|
rEntry = cfBULLBar.high;
|
|
rType = POSITION_TYPE_SELL;
|
|
rMode = X_ORDER_MODE_STOP;
|
|
rVolume = signal.volume * inDirectionalVolumeMultiplier;
|
|
|
|
//
|
|
isSignalPrepared = rSignal.Prepare(
|
|
signal.symbol,
|
|
XEQMSupportToken + XINDirectionalToken,
|
|
signal.period,
|
|
rType,
|
|
rMode,
|
|
rEntry,
|
|
rVolume,
|
|
rSL,
|
|
rTP //
|
|
);
|
|
if (isSignalPrepared)
|
|
{
|
|
//
|
|
AddRef(
|
|
rSignal,
|
|
signal.supports //
|
|
);
|
|
|
|
//
|
|
rSignal.Clean();
|
|
|
|
//
|
|
rSL = 0;
|
|
rTP = 0;
|
|
rEntry = 0;
|
|
isSignalPrepared = false;
|
|
}
|
|
}
|
|
|
|
//
|
|
// LOW ...
|
|
|
|
//
|
|
condition = entryPrice > cfBULLBar.low;
|
|
if (condition)
|
|
{
|
|
//
|
|
// InDirectional ...
|
|
rEntry = cfBULLBar.low;
|
|
rType = POSITION_TYPE_SELL;
|
|
rMode = X_ORDER_MODE_STOP;
|
|
rVolume = signal.volume * inDirectionalVolumeMultiplier;
|
|
|
|
//
|
|
isSignalPrepared = rSignal.Prepare(
|
|
signal.symbol,
|
|
XEQMSupportToken + XINDirectionalToken,
|
|
signal.period,
|
|
rType,
|
|
rMode,
|
|
rEntry,
|
|
rVolume,
|
|
rSL,
|
|
rTP //
|
|
);
|
|
if (isSignalPrepared)
|
|
{
|
|
//
|
|
AddRef(
|
|
rSignal,
|
|
signal.supports //
|
|
);
|
|
|
|
//
|
|
rSignal.Clean();
|
|
|
|
//
|
|
rSL = 0;
|
|
rTP = 0;
|
|
rEntry = 0;
|
|
isSignalPrepared = false;
|
|
}
|
|
}
|
|
|
|
//
|
|
condition = entryPrice < cfBULLBar.low;
|
|
if (condition)
|
|
{
|
|
//
|
|
// InDirectional ...
|
|
rEntry = cfBULLBar.low;
|
|
rType = POSITION_TYPE_SELL;
|
|
rMode = X_ORDER_MODE_LIMIT;
|
|
rVolume = signal.volume * inDirectionalVolumeMultiplier;
|
|
|
|
//
|
|
isSignalPrepared = rSignal.Prepare(
|
|
signal.symbol,
|
|
XEQMSupportToken + XINDirectionalToken,
|
|
signal.period,
|
|
rType,
|
|
rMode,
|
|
rEntry,
|
|
rVolume,
|
|
rSL,
|
|
rTP //
|
|
);
|
|
if (isSignalPrepared)
|
|
{
|
|
//
|
|
AddRef(
|
|
rSignal,
|
|
signal.supports //
|
|
);
|
|
|
|
//
|
|
rSignal.Clean();
|
|
|
|
//
|
|
rSL = 0;
|
|
rTP = 0;
|
|
rEntry = 0;
|
|
isSignalPrepared = false;
|
|
}
|
|
}
|
|
|
|
//
|
|
// CF Bearish ...
|
|
|
|
//
|
|
// HIGH ...
|
|
|
|
//
|
|
condition = entryPrice < cfBEARBar.high;
|
|
if (condition)
|
|
{
|
|
//
|
|
// InDirectional ...
|
|
rEntry = cfBEARBar.high;
|
|
rType = POSITION_TYPE_SELL;
|
|
rMode = X_ORDER_MODE_LIMIT;
|
|
rVolume = signal.volume * inDirectionalVolumeMultiplier;
|
|
|
|
//
|
|
isSignalPrepared = rSignal.Prepare(
|
|
signal.symbol,
|
|
XEQMSupportToken + XINDirectionalToken,
|
|
signal.period,
|
|
rType,
|
|
rMode,
|
|
rEntry,
|
|
rVolume,
|
|
rSL,
|
|
rTP //
|
|
);
|
|
if (isSignalPrepared)
|
|
{
|
|
//
|
|
AddRef(
|
|
rSignal,
|
|
signal.supports //
|
|
);
|
|
|
|
//
|
|
rSignal.Clean();
|
|
|
|
//
|
|
rSL = 0;
|
|
rTP = 0;
|
|
rEntry = 0;
|
|
isSignalPrepared = false;
|
|
}
|
|
}
|
|
|
|
//
|
|
condition = entryPrice > cfBEARBar.high;
|
|
if (condition)
|
|
{
|
|
//
|
|
// InDirectional ...
|
|
rEntry = cfBEARBar.high;
|
|
rType = POSITION_TYPE_SELL;
|
|
rMode = X_ORDER_MODE_STOP;
|
|
rVolume = signal.volume * inDirectionalVolumeMultiplier;
|
|
|
|
//
|
|
isSignalPrepared = rSignal.Prepare(
|
|
signal.symbol,
|
|
XEQMSupportToken + XINDirectionalToken,
|
|
signal.period,
|
|
rType,
|
|
rMode,
|
|
rEntry,
|
|
rVolume,
|
|
rSL,
|
|
rTP //
|
|
);
|
|
if (isSignalPrepared)
|
|
{
|
|
//
|
|
AddRef(
|
|
rSignal,
|
|
signal.supports //
|
|
);
|
|
|
|
//
|
|
rSignal.Clean();
|
|
|
|
//
|
|
rSL = 0;
|
|
rTP = 0;
|
|
rEntry = 0;
|
|
isSignalPrepared = false;
|
|
}
|
|
}
|
|
|
|
//
|
|
// LOW ...
|
|
|
|
//
|
|
condition = entryPrice > cfBEARBar.low;
|
|
if (condition)
|
|
{
|
|
//
|
|
// InDirectional ...
|
|
rEntry = cfBEARBar.low;
|
|
rType = POSITION_TYPE_SELL;
|
|
rMode = X_ORDER_MODE_STOP;
|
|
rVolume = signal.volume * inDirectionalVolumeMultiplier;
|
|
|
|
//
|
|
isSignalPrepared = rSignal.Prepare(
|
|
signal.symbol,
|
|
XEQMSupportToken + XINDirectionalToken,
|
|
signal.period,
|
|
rType,
|
|
rMode,
|
|
rEntry,
|
|
rVolume,
|
|
rSL,
|
|
rTP //
|
|
);
|
|
if (isSignalPrepared)
|
|
{
|
|
//
|
|
AddRef(
|
|
rSignal,
|
|
signal.supports //
|
|
);
|
|
|
|
//
|
|
rSignal.Clean();
|
|
|
|
//
|
|
rSL = 0;
|
|
rTP = 0;
|
|
rEntry = 0;
|
|
isSignalPrepared = false;
|
|
}
|
|
}
|
|
|
|
//
|
|
condition = entryPrice < cfBEARBar.low;
|
|
if (condition)
|
|
{
|
|
//
|
|
// InDirectional ...
|
|
rEntry = cfBEARBar.low;
|
|
rType = POSITION_TYPE_SELL;
|
|
rMode = X_ORDER_MODE_LIMIT;
|
|
rVolume = signal.volume * inDirectionalVolumeMultiplier;
|
|
|
|
//
|
|
isSignalPrepared = rSignal.Prepare(
|
|
signal.symbol,
|
|
XEQMSupportToken + XINDirectionalToken,
|
|
signal.period,
|
|
rType,
|
|
rMode,
|
|
rEntry,
|
|
rVolume,
|
|
rSL,
|
|
rTP //
|
|
);
|
|
if (isSignalPrepared)
|
|
{
|
|
//
|
|
AddRef(
|
|
rSignal,
|
|
signal.supports //
|
|
);
|
|
|
|
//
|
|
rSignal.Clean();
|
|
|
|
//
|
|
rSL = 0;
|
|
rTP = 0;
|
|
rEntry = 0;
|
|
isSignalPrepared = false;
|
|
}
|
|
}
|
|
}
|
|
else
|
|
{
|
|
//
|
|
// Supports For Shorts ...
|
|
|
|
//
|
|
// CF Bullish ...
|
|
|
|
//
|
|
// HIGH ...
|
|
|
|
//
|
|
condition = entryPrice < cfBULLBar.high;
|
|
if (condition)
|
|
{
|
|
//
|
|
// InDirectional ...
|
|
rEntry = cfBULLBar.high;
|
|
rType = POSITION_TYPE_BUY;
|
|
rMode = X_ORDER_MODE_STOP;
|
|
rVolume = signal.volume * inDirectionalVolumeMultiplier;
|
|
|
|
//
|
|
isSignalPrepared = rSignal.Prepare(
|
|
signal.symbol,
|
|
XEQMSupportToken + XINDirectionalToken,
|
|
signal.period,
|
|
rType,
|
|
rMode,
|
|
rEntry,
|
|
rVolume,
|
|
rSL,
|
|
rTP //
|
|
);
|
|
if (isSignalPrepared)
|
|
{
|
|
//
|
|
AddRef(
|
|
rSignal,
|
|
signal.supports //
|
|
);
|
|
|
|
//
|
|
rSignal.Clean();
|
|
|
|
//
|
|
rSL = 0;
|
|
rTP = 0;
|
|
rEntry = 0;
|
|
isSignalPrepared = false;
|
|
}
|
|
}
|
|
|
|
//
|
|
condition = entryPrice > cfBULLBar.high;
|
|
if (condition)
|
|
{
|
|
//
|
|
// InDirectional ...
|
|
rEntry = cfBULLBar.high;
|
|
rType = POSITION_TYPE_BUY;
|
|
rMode = X_ORDER_MODE_LIMIT;
|
|
rVolume = signal.volume * inDirectionalVolumeMultiplier;
|
|
|
|
//
|
|
isSignalPrepared = rSignal.Prepare(
|
|
signal.symbol,
|
|
XEQMSupportToken + XINDirectionalToken,
|
|
signal.period,
|
|
rType,
|
|
rMode,
|
|
rEntry,
|
|
rVolume,
|
|
rSL,
|
|
rTP //
|
|
);
|
|
if (isSignalPrepared)
|
|
{
|
|
//
|
|
AddRef(
|
|
rSignal,
|
|
signal.supports //
|
|
);
|
|
|
|
//
|
|
rSignal.Clean();
|
|
|
|
//
|
|
rSL = 0;
|
|
rTP = 0;
|
|
rEntry = 0;
|
|
isSignalPrepared = false;
|
|
}
|
|
}
|
|
|
|
//
|
|
// LOW ...
|
|
|
|
//
|
|
condition = entryPrice > cfBULLBar.low;
|
|
if (condition)
|
|
{
|
|
//
|
|
// InDirectional ...
|
|
rEntry = cfBULLBar.low;
|
|
rType = POSITION_TYPE_BUY;
|
|
rMode = X_ORDER_MODE_LIMIT;
|
|
rVolume = signal.volume * inDirectionalVolumeMultiplier;
|
|
|
|
//
|
|
isSignalPrepared = rSignal.Prepare(
|
|
signal.symbol,
|
|
XEQMSupportToken + XINDirectionalToken,
|
|
signal.period,
|
|
rType,
|
|
rMode,
|
|
rEntry,
|
|
rVolume,
|
|
rSL,
|
|
rTP //
|
|
);
|
|
if (isSignalPrepared)
|
|
{
|
|
//
|
|
AddRef(
|
|
rSignal,
|
|
signal.supports //
|
|
);
|
|
|
|
//
|
|
rSignal.Clean();
|
|
|
|
//
|
|
rSL = 0;
|
|
rTP = 0;
|
|
rEntry = 0;
|
|
isSignalPrepared = false;
|
|
}
|
|
}
|
|
|
|
//
|
|
condition = entryPrice < cfBULLBar.low;
|
|
if (condition)
|
|
{
|
|
//
|
|
// InDirectional ...
|
|
rEntry = cfBULLBar.low;
|
|
rType = POSITION_TYPE_BUY;
|
|
rMode = X_ORDER_MODE_STOP;
|
|
rVolume = signal.volume * inDirectionalVolumeMultiplier;
|
|
|
|
//
|
|
isSignalPrepared = rSignal.Prepare(
|
|
signal.symbol,
|
|
XEQMSupportToken + XINDirectionalToken,
|
|
signal.period,
|
|
rType,
|
|
rMode,
|
|
rEntry,
|
|
rVolume,
|
|
rSL,
|
|
rTP //
|
|
);
|
|
if (isSignalPrepared)
|
|
{
|
|
//
|
|
AddRef(
|
|
rSignal,
|
|
signal.supports //
|
|
);
|
|
|
|
//
|
|
rSignal.Clean();
|
|
|
|
//
|
|
rSL = 0;
|
|
rTP = 0;
|
|
rEntry = 0;
|
|
isSignalPrepared = false;
|
|
}
|
|
}
|
|
|
|
//
|
|
// CF Bearish ...
|
|
|
|
//
|
|
// HIGH ...
|
|
|
|
//
|
|
condition = entryPrice < cfBEARBar.high;
|
|
if (condition)
|
|
{
|
|
//
|
|
// InDirectional ...
|
|
rEntry = cfBEARBar.high;
|
|
rType = POSITION_TYPE_BUY;
|
|
rMode = X_ORDER_MODE_STOP;
|
|
rVolume = signal.volume * inDirectionalVolumeMultiplier;
|
|
|
|
//
|
|
isSignalPrepared = rSignal.Prepare(
|
|
signal.symbol,
|
|
XEQMSupportToken + XINDirectionalToken,
|
|
signal.period,
|
|
rType,
|
|
rMode,
|
|
rEntry,
|
|
rVolume,
|
|
rSL,
|
|
rTP //
|
|
);
|
|
if (isSignalPrepared)
|
|
{
|
|
//
|
|
AddRef(
|
|
rSignal,
|
|
signal.supports //
|
|
);
|
|
|
|
//
|
|
rSignal.Clean();
|
|
|
|
//
|
|
rSL = 0;
|
|
rTP = 0;
|
|
rEntry = 0;
|
|
isSignalPrepared = false;
|
|
}
|
|
}
|
|
|
|
//
|
|
condition = entryPrice > cfBEARBar.high;
|
|
if (condition)
|
|
{
|
|
//
|
|
// InDirectional ...
|
|
rEntry = cfBEARBar.high;
|
|
rType = POSITION_TYPE_BUY;
|
|
rMode = X_ORDER_MODE_LIMIT;
|
|
rVolume = signal.volume * inDirectionalVolumeMultiplier;
|
|
|
|
//
|
|
isSignalPrepared = rSignal.Prepare(
|
|
signal.symbol,
|
|
XEQMSupportToken + XINDirectionalToken,
|
|
signal.period,
|
|
rType,
|
|
rMode,
|
|
rEntry,
|
|
rVolume,
|
|
rSL,
|
|
rTP //
|
|
);
|
|
if (isSignalPrepared)
|
|
{
|
|
//
|
|
AddRef(
|
|
rSignal,
|
|
signal.supports //
|
|
);
|
|
|
|
//
|
|
rSignal.Clean();
|
|
|
|
//
|
|
rSL = 0;
|
|
rTP = 0;
|
|
rEntry = 0;
|
|
isSignalPrepared = false;
|
|
}
|
|
}
|
|
|
|
//
|
|
// LOW ...
|
|
|
|
//
|
|
condition = entryPrice > cfBEARBar.low;
|
|
if (condition)
|
|
{
|
|
//
|
|
// InDirectional ...
|
|
rEntry = cfBEARBar.low;
|
|
rType = POSITION_TYPE_BUY;
|
|
rMode = X_ORDER_MODE_LIMIT;
|
|
rVolume = signal.volume * inDirectionalVolumeMultiplier;
|
|
|
|
//
|
|
isSignalPrepared = rSignal.Prepare(
|
|
signal.symbol,
|
|
XEQMSupportToken + XINDirectionalToken,
|
|
signal.period,
|
|
rType,
|
|
rMode,
|
|
rEntry,
|
|
rVolume,
|
|
rSL,
|
|
rTP //
|
|
);
|
|
if (isSignalPrepared)
|
|
{
|
|
//
|
|
AddRef(
|
|
rSignal,
|
|
signal.supports //
|
|
);
|
|
|
|
//
|
|
rSignal.Clean();
|
|
|
|
//
|
|
rSL = 0;
|
|
rTP = 0;
|
|
rEntry = 0;
|
|
isSignalPrepared = false;
|
|
}
|
|
}
|
|
|
|
//
|
|
condition = entryPrice < cfBEARBar.low;
|
|
if (condition)
|
|
{
|
|
//
|
|
// InDirectional ...
|
|
rEntry = cfBEARBar.low;
|
|
rType = POSITION_TYPE_BUY;
|
|
rMode = X_ORDER_MODE_STOP;
|
|
rVolume = signal.volume * inDirectionalVolumeMultiplier;
|
|
|
|
//
|
|
isSignalPrepared = rSignal.Prepare(
|
|
signal.symbol,
|
|
XEQMSupportToken + XINDirectionalToken,
|
|
signal.period,
|
|
rType,
|
|
rMode,
|
|
rEntry,
|
|
rVolume,
|
|
rSL,
|
|
rTP //
|
|
);
|
|
if (isSignalPrepared)
|
|
{
|
|
//
|
|
AddRef(
|
|
rSignal,
|
|
signal.supports //
|
|
);
|
|
|
|
//
|
|
rSignal.Clean();
|
|
|
|
//
|
|
rSL = 0;
|
|
rTP = 0;
|
|
rEntry = 0;
|
|
isSignalPrepared = false;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
////////////////////////////////////////////////////////////////////////
|
|
|
|
//
|
|
cPusher = 0;
|
|
sPusher = 0;
|
|
mPusher = 0;
|
|
lPusher = 0;
|
|
hPusher = 0;
|
|
|
|
//
|
|
cProvider = NULL;
|
|
sProvider = NULL;
|
|
mProvider = NULL;
|
|
lProvider = NULL;
|
|
hProvider = NULL;
|
|
|
|
//
|
|
cSignal.Clean();
|
|
sSignal.Clean();
|
|
mSignal.Clean();
|
|
lSignal.Clean();
|
|
hSignal.Clean();
|
|
|
|
//
|
|
cHasSignal = false;
|
|
sHasSignal = false;
|
|
mHasSignal = false;
|
|
lHasSignal = false;
|
|
hHasSignal = false;
|
|
|
|
//
|
|
cConditions.Clean();
|
|
sConditions.Clean();
|
|
mConditions.Clean();
|
|
lConditions.Clean();
|
|
hConditions.Clean();
|
|
|
|
//
|
|
datetime cTime = TimeCurrent();
|
|
|
|
//
|
|
// Current ...
|
|
bool canProcess = mSetups[i]
|
|
.CanProcessBar(
|
|
X_MARKET_CYCLE_UNKNOWN //
|
|
);
|
|
//
|
|
datetime next = mSetups[i].GetNextSignalTime(X_MARKET_CYCLE_UNKNOWN);
|
|
if (IsValid(next))
|
|
{
|
|
canProcess = canProcess && cTime >= next;
|
|
}
|
|
|
|
//
|
|
if (canProcess)
|
|
{
|
|
//
|
|
bool iHasConditions = mSetups[i].GetConditions(
|
|
cConditions,
|
|
X_MARKET_CYCLE_UNKNOWN, // Current Market ...
|
|
0, // Bar Index ...
|
|
5 // Loop Back ...
|
|
);
|
|
|
|
//
|
|
if (iHasConditions)
|
|
{
|
|
//
|
|
// Parse Conditions for Signal ...
|
|
cHasSignal = signalGenerator.HasSignal(
|
|
cConditions,
|
|
cSignal,
|
|
cPusher,
|
|
cProvider,
|
|
AllowSupport(),
|
|
mAllowLong,
|
|
mAllowShort,
|
|
mVolume,
|
|
mSLPoint,
|
|
mIgnoreSL,
|
|
mTPPoint,
|
|
mIgnoreTP //
|
|
);
|
|
|
|
//
|
|
if (cHasSignal)
|
|
{
|
|
//
|
|
mSetups[i].WaitsUntilNextBar(
|
|
X_MARKET_CYCLE_UNKNOWN //
|
|
);
|
|
}
|
|
}
|
|
}
|
|
|
|
//
|
|
// Short ...
|
|
canProcess = mSetups[i]
|
|
.CanProcessBar(
|
|
X_MARKET_CYCLE_SHORT //
|
|
);
|
|
//
|
|
next = mSetups[i].GetNextSignalTime(X_MARKET_CYCLE_SHORT);
|
|
if (IsValid(next))
|
|
{
|
|
sHasSignal = canProcess && cTime >= next;
|
|
}
|
|
|
|
//
|
|
if (canProcess)
|
|
{
|
|
//
|
|
bool iHasConditions = mSetups[i].GetConditions(
|
|
sConditions,
|
|
X_MARKET_CYCLE_SHORT, // Current Market ...
|
|
0, // Bar Index ...
|
|
5 // Loop Back ...
|
|
);
|
|
|
|
//
|
|
if (iHasConditions)
|
|
{
|
|
//
|
|
// Parse Conditions for Signal ...
|
|
sHasSignal = signalGenerator.HasSignal(
|
|
sConditions,
|
|
sSignal,
|
|
sPusher,
|
|
sProvider,
|
|
AllowSupport(),
|
|
mAllowLong,
|
|
mAllowShort,
|
|
mVolume,
|
|
mSLPoint,
|
|
mIgnoreSL,
|
|
mTPPoint,
|
|
mIgnoreTP //
|
|
);
|
|
|
|
//
|
|
if (sHasSignal)
|
|
{
|
|
//
|
|
mSetups[i].WaitsUntilNextBar(
|
|
X_MARKET_CYCLE_SHORT //
|
|
);
|
|
}
|
|
}
|
|
}
|
|
|
|
//
|
|
// Medium ...
|
|
canProcess = mSetups[i]
|
|
.CanProcessBar(
|
|
X_MARKET_CYCLE_MEDIUM //
|
|
);
|
|
//
|
|
next = mSetups[i].GetNextSignalTime(X_MARKET_CYCLE_MEDIUM);
|
|
if (IsValid(next))
|
|
{
|
|
mHasSignal = canProcess && cTime >= next;
|
|
}
|
|
|
|
//
|
|
if (canProcess)
|
|
{
|
|
//
|
|
bool iHasConditions = mSetups[i].GetConditions(
|
|
mConditions,
|
|
X_MARKET_CYCLE_MEDIUM, // Current Market ...
|
|
0, // Bar Index ...
|
|
5 // Loop Back ...
|
|
);
|
|
|
|
//
|
|
if (iHasConditions)
|
|
{
|
|
//
|
|
// Parse Conditions for Signal ...
|
|
mHasSignal = signalGenerator.HasSignal(
|
|
mConditions,
|
|
mSignal,
|
|
mPusher,
|
|
mProvider,
|
|
AllowSupport(),
|
|
mAllowLong,
|
|
mAllowShort,
|
|
mVolume,
|
|
mSLPoint,
|
|
mIgnoreSL,
|
|
mTPPoint,
|
|
mIgnoreTP //
|
|
);
|
|
|
|
//
|
|
if (mHasSignal)
|
|
{
|
|
//
|
|
mSetups[i].WaitsUntilNextBar(
|
|
X_MARKET_CYCLE_MEDIUM //
|
|
);
|
|
}
|
|
}
|
|
}
|
|
|
|
//
|
|
// Long ...
|
|
canProcess = mSetups[i]
|
|
.CanProcessBar(
|
|
X_MARKET_CYCLE_LONG //
|
|
);
|
|
//
|
|
next = mSetups[i].GetNextSignalTime(X_MARKET_CYCLE_LONG);
|
|
if (IsValid(next))
|
|
{
|
|
lHasSignal = canProcess && cTime >= next;
|
|
}
|
|
|
|
//
|
|
if (canProcess)
|
|
{
|
|
//
|
|
bool iHasConditions = mSetups[i].GetConditions(
|
|
lConditions,
|
|
X_MARKET_CYCLE_LONG, // Current Market ...
|
|
0, // Bar Index ...
|
|
5 // Loop Back ...
|
|
);
|
|
|
|
//
|
|
if (iHasConditions)
|
|
{
|
|
//
|
|
// Parse Conditions for Signal ...
|
|
lHasSignal = signalGenerator.HasSignal(
|
|
lConditions,
|
|
lSignal,
|
|
lPusher,
|
|
lProvider,
|
|
AllowSupport(),
|
|
mAllowLong,
|
|
mAllowShort,
|
|
mVolume,
|
|
mSLPoint,
|
|
mIgnoreSL,
|
|
mTPPoint,
|
|
mIgnoreTP //
|
|
);
|
|
|
|
//
|
|
if (lHasSignal)
|
|
{
|
|
//
|
|
mSetups[i].WaitsUntilNextBar(
|
|
X_MARKET_CYCLE_LONG //
|
|
);
|
|
}
|
|
}
|
|
}
|
|
|
|
//
|
|
// Hind ...
|
|
canProcess = mSetups[i]
|
|
.CanProcessBar(
|
|
X_MARKET_CYCLE_HIND //
|
|
);
|
|
//
|
|
next = mSetups[i].GetNextSignalTime(X_MARKET_CYCLE_HIND);
|
|
if (IsValid(next))
|
|
{
|
|
hHasSignal = canProcess && cTime >= next;
|
|
}
|
|
|
|
//
|
|
if (canProcess)
|
|
{
|
|
//
|
|
bool iHasConditions = mSetups[i].GetConditions(
|
|
hConditions,
|
|
X_MARKET_CYCLE_HIND, // Current Market ...
|
|
0, // Bar Index ...
|
|
5 // Loop Back ...
|
|
);
|
|
|
|
//
|
|
if (iHasConditions)
|
|
{
|
|
//
|
|
// Parse Conditions for Signal ...
|
|
hHasSignal = signalGenerator.HasSignal(
|
|
hConditions,
|
|
hSignal,
|
|
hPusher,
|
|
hProvider,
|
|
AllowSupport(),
|
|
mAllowLong,
|
|
mAllowShort,
|
|
mVolume,
|
|
mSLPoint,
|
|
mIgnoreSL,
|
|
mTPPoint,
|
|
mIgnoreTP //
|
|
);
|
|
|
|
//
|
|
if (hHasSignal)
|
|
{
|
|
//
|
|
mSetups[i].WaitsUntilNextBar(
|
|
X_MARKET_CYCLE_HIND //
|
|
);
|
|
}
|
|
}
|
|
}
|
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
|
|
//
|
|
// Handle Creating a new Signal Info ...
|
|
// XSignal signal;
|
|
// X121SetupConditions otherConditions[];
|
|
// if (hHasSignal)
|
|
// {
|
|
// //
|
|
// signal = hSignal;
|
|
|
|
// //
|
|
// AddRef(
|
|
// cConditions,
|
|
// otherConditions //
|
|
// );
|
|
// AddRef(
|
|
// sConditions,
|
|
// otherConditions //
|
|
// );
|
|
// }
|
|
// else if (lHasSignal)
|
|
// {
|
|
// //
|
|
// signal = lSignal;
|
|
|
|
// //
|
|
// AddRef(
|
|
// cConditions,
|
|
// otherConditions //
|
|
// );
|
|
// AddRef(
|
|
// sConditions,
|
|
// otherConditions //
|
|
// );
|
|
// AddRef(
|
|
// mConditions,
|
|
// otherConditions //
|
|
// );
|
|
// }
|
|
// else if (mHasSignal)
|
|
// {
|
|
// //
|
|
// signal = mSignal;
|
|
|
|
// //
|
|
// AddRef(
|
|
// cConditions,
|
|
// otherConditions //
|
|
// );
|
|
// AddRef(
|
|
// sConditions,
|
|
// otherConditions //
|
|
// );
|
|
// }
|
|
// else if (sHasSignal)
|
|
// {
|
|
// //
|
|
// signal = sSignal;
|
|
|
|
// //
|
|
// AddRef(
|
|
// cConditions,
|
|
// otherConditions //
|
|
// );
|
|
// AddRef(
|
|
// mConditions,
|
|
// otherConditions //
|
|
// );
|
|
// AddRef(
|
|
// lConditions,
|
|
// otherConditions //
|
|
// );
|
|
// AddRef(
|
|
// hConditions,
|
|
// otherConditions //
|
|
// );
|
|
// }
|
|
// else if (cHasSignal)
|
|
// {
|
|
// //
|
|
// signal = cSignal;
|
|
|
|
// //
|
|
// AddRef(
|
|
// sConditions,
|
|
// otherConditions //
|
|
// );
|
|
// AddRef(
|
|
// mConditions,
|
|
// otherConditions //
|
|
// );
|
|
// AddRef(
|
|
// lConditions,
|
|
// otherConditions //
|
|
// );
|
|
// AddRef(
|
|
// hConditions,
|
|
// otherConditions //
|
|
// );
|
|
// }
|
|
|
|
// //
|
|
// int pushers = cPusher + sPusher + mPusher + lPusher + hPusher;
|
|
|
|
// //
|
|
// bool isLong = IsLong(signal.type);
|
|
|
|
// //
|
|
// // Collecting Bullish/Bearish Signs ...
|
|
// if (isLong)
|
|
// {
|
|
// mBullishSigns += pushers;
|
|
// }
|
|
// else
|
|
// {
|
|
// mBearishSigns += pushers;
|
|
// }
|
|
|
|
// //
|
|
// // Validate Signal ...
|
|
// bool isValid =
|
|
// //
|
|
// // Handle Pusher Validations ...
|
|
// (mReuiredSignalVerifications <= 0
|
|
// ? true
|
|
// : pushers >= mReuiredSignalVerifications)
|
|
// //
|
|
// &&
|
|
// //
|
|
// // Handle Other Conditions Validations ...
|
|
// (!mGetVerificationFromOtherTimeFrames
|
|
// ? true
|
|
// : isLong
|
|
// ? signalGenerator.HasLongVerifications(otherConditions)
|
|
// : signalGenerator.HasShortVerifications(otherConditions))
|
|
// //
|
|
// ;
|
|
|
|
// //
|
|
// bool forceState = ForceState();
|
|
|
|
// //
|
|
// if (!isValid || (forceState && isValid))
|
|
// {
|
|
// //
|
|
// // Clear Other Conditions ...
|
|
// Clean(otherConditions);
|
|
|
|
// //
|
|
// // Fill All Conditions to Other Conditions ...
|
|
// AddRef(
|
|
// cConditions,
|
|
// otherConditions //
|
|
// );
|
|
// AddRef(
|
|
// sConditions,
|
|
// otherConditions //
|
|
// );
|
|
// AddRef(
|
|
// mConditions,
|
|
// otherConditions //
|
|
// );
|
|
// AddRef(
|
|
// lConditions,
|
|
// otherConditions //
|
|
// );
|
|
// AddRef(
|
|
// hConditions,
|
|
// otherConditions //
|
|
// );
|
|
|
|
// //
|
|
// // If Recieved Any Unverified Signal
|
|
// // we Passed it to EQM Manager ...
|
|
// EQMHandleInvalidSignal(
|
|
// signal,
|
|
// pushers,
|
|
// mVolumeOSC,
|
|
// mBullishScore,
|
|
// mBullishSigns,
|
|
// mBearishScore,
|
|
// mBearishSigns,
|
|
// otherConditions,
|
|
// isValid //
|
|
// );
|
|
// continue;
|
|
// }
|
|
|
|
// //
|
|
// if (!forceState)
|
|
// {
|
|
// //
|
|
// // Add Signal to Execution Result ...
|
|
// AddRef(
|
|
// signal,
|
|
// signals //
|
|
// );
|
|
|
|
// //
|
|
// // Add new Signal Info ...
|
|
// mTradeHandler.Add(
|
|
// signal,
|
|
// pushers,
|
|
// mVolumeOSC,
|
|
// mBullishSigns,
|
|
// mBearishSigns,
|
|
// mBullishScore,
|
|
// mBearishScore,
|
|
// cConditions,
|
|
// sConditions,
|
|
// mConditions,
|
|
// lConditions,
|
|
// hConditions //
|
|
// );
|
|
// }
|
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
|
|
// //
|
|
// double profits = SpecifiedCalculatePositionsProfit(positions);
|
|
|
|
// //
|
|
// // Checking Force Sate Conditions ...
|
|
// if (ForceState())
|
|
// {
|
|
// //
|
|
// // Check Force State Hedging ...
|
|
// bool isHedged = DoEQMForceClose();
|
|
// if (isHedged)
|
|
// {
|
|
// //
|
|
// ForceState(false);
|
|
// return;
|
|
// }
|
|
|
|
// //
|
|
// // Handle Act Based On Drawdow ...
|
|
// if (mMaxDrawdownForce > 0)
|
|
// {
|
|
// //
|
|
// double drawdown = CalculateMaxDrawdown();
|
|
// if (drawdown > mMaxDrawdownForce)
|
|
// {
|
|
// //
|
|
// // Try to Hedge ...
|
|
// if (profits > 0)
|
|
// {
|
|
// //
|
|
// bool isHedged = DoEQMForceClose(profits);
|
|
// if (isHedged)
|
|
// {
|
|
// //
|
|
// ForceState(false);
|
|
// return;
|
|
// }
|
|
// }
|
|
|
|
// //
|
|
// // Close Max In Drawdown Position ...
|
|
// int maxInDIDX = FindMaxDrawdownIndex(positions);
|
|
// if (IsValidIndex(maxInDIDX))
|
|
// {
|
|
// //
|
|
// string comment = XEQMSupportToken + " Max In D ...";
|
|
|
|
// //
|
|
// bool isClosed = mTrader.Close(
|
|
// positions[maxInDIDX].ticket,
|
|
// comment //
|
|
// );
|
|
// if (isClosed)
|
|
// {
|
|
// //
|
|
// string message = XEQMSupportToken + " Close " + ToString(positions[maxInDIDX].ticket) + " Due Max In Drawdown ...";
|
|
|
|
// //
|
|
// Alert(message);
|
|
// }
|
|
|
|
// //
|
|
// return;
|
|
// }
|
|
|
|
// //
|
|
// return;
|
|
// }
|
|
// }
|
|
|
|
// //
|
|
// // Handle Act Based on Positions Count ...
|
|
// if (mMaxPositionsForce > 0 && positionsCount > mMaxPositionsForce)
|
|
// {
|
|
// //
|
|
// double requiredProfit = SpecifiedCalculateRequiredProfitForHedge(
|
|
// positions,
|
|
// MinRequiredProfitPerTrade(),
|
|
// MinRequiredProfitPerVolumeFactor() //
|
|
// );
|
|
|
|
// //
|
|
// double halfProfit = requiredProfit / 2;
|
|
// if (halfProfit > 0 && profits > halfProfit)
|
|
// {
|
|
// //
|
|
// bool isHedged = DoEQMForceClose(halfProfit);
|
|
// if (isHedged)
|
|
// {
|
|
// //
|
|
// ForceState(false);
|
|
// return;
|
|
// }
|
|
// }
|
|
|
|
// //
|
|
// // Close Min In Profit Position ...
|
|
// int minInPIDX = FindMinProfitIndex(positions);
|
|
// if (IsValidIndex(minInPIDX))
|
|
// {
|
|
// //
|
|
// string comment = XEQMSupportToken + " Min In P ...";
|
|
|
|
// //
|
|
// bool isClosed = mTrader.Close(
|
|
// positions[minInPIDX].ticket,
|
|
// comment //
|
|
// );
|
|
// if (isClosed)
|
|
// {
|
|
// //
|
|
// string message = XEQMSupportToken + " Close " + ToString(positions[minInPIDX].ticket) + " Due Min In Profit ...";
|
|
|
|
// //
|
|
// Alert(message);
|
|
|
|
// //
|
|
// return;
|
|
// }
|
|
// }
|
|
|
|
// //
|
|
// // Close Max In Drawdown Position ...
|
|
// int maxInDIDX = FindMaxDrawdownIndex(positions);
|
|
// if (IsValidIndex(maxInDIDX))
|
|
// {
|
|
// //
|
|
// string comment = XEQMSupportToken + " Max In D ...";
|
|
|
|
// //
|
|
// bool isClosed = mTrader.Close(
|
|
// positions[maxInDIDX].ticket,
|
|
// comment //
|
|
// );
|
|
// if (isClosed)
|
|
// {
|
|
// //
|
|
// string message = XEQMSupportToken + "Close " + ToString(positions[maxInDIDX].ticket) + " Due Max In Drawdown ...";
|
|
|
|
// //
|
|
// Alert(message);
|
|
// }
|
|
|
|
// //
|
|
// return;
|
|
// }
|
|
|
|
// //
|
|
// return;
|
|
// }
|
|
|
|
// //
|
|
// return;
|
|
// }
|
|
|
|
// //
|
|
// int longs = 0;
|
|
// double longVolumes = 0;
|
|
// double longProfits = 0;
|
|
|
|
// //
|
|
// int shorts = 0;
|
|
// double shortVolumes = 0;
|
|
// double shortProfits = 0;
|
|
|
|
// //
|
|
// // Retrieve Required Informations of Positions ...
|
|
// CountPositions(
|
|
// positions,
|
|
// longs,
|
|
// longProfits,
|
|
// longVolumes,
|
|
// shorts,
|
|
// shortProfits,
|
|
// shortVolumes //
|
|
// );
|
|
|
|
// //
|
|
// // Retrieve Youngest Age ...
|
|
// XPosition youngest;
|
|
// int youngestAge = GetYoungest(
|
|
// youngest,
|
|
// positions //
|
|
// );
|
|
|
|
// //
|
|
// // Now Comparing items for enabling force State ...
|
|
// bool isForceState =
|
|
// //
|
|
// youngestAge >= 20 &&
|
|
// //
|
|
// (longProfits + shortProfits < 0)
|
|
// //
|
|
// ;
|
|
// if (isForceState)
|
|
// {
|
|
// //
|
|
// ForceState(true);
|
|
|
|
// //
|
|
// return;
|
|
// }
|
|
|
|
// //
|
|
// XPosition supports[];
|
|
// int supportsCount = ExtractSupports(
|
|
// positions,
|
|
// supports //
|
|
// );
|
|
// if (!IsValidSize(supportsCount))
|
|
// {
|
|
// return;
|
|
// }
|
|
|
|
// //
|
|
// int maxSupports = mTradeHandler.EnableSupport()
|
|
// ? MaxNumberOfSupports()
|
|
// : 0;
|
|
// int maxGrids = mTradeHandler.EnableGrid()
|
|
// ? MaxNumberOfGrids()
|
|
// : 0;
|
|
// int maxRecoveries = mTradeHandler.EnableRecovery()
|
|
// ? MaxNumberOfRecoveries()
|
|
// : 0;
|
|
|
|
// //
|
|
// // Supporting Force States ...
|
|
// bool isProtectionForce =
|
|
// supportsCount >= 1;
|
|
// if (isProtectionForce)
|
|
// {
|
|
// //
|
|
// ForceState(true);
|
|
|
|
// //
|
|
// return;
|
|
// }
|
|
|
|
//////////////////////////////////////////////////////////////////////////////////////////
|
|
|
|
double hotLevels[];
|
|
|
|
//
|
|
Add(
|
|
0.25,
|
|
hotLevels //
|
|
);
|
|
|
|
//
|
|
Add(
|
|
0.20,
|
|
hotLevels //
|
|
);
|
|
|
|
//
|
|
Add(
|
|
0.15,
|
|
hotLevels //
|
|
);
|
|
|
|
//
|
|
// Calculate Ticks Zone ...
|
|
XSCZones *zones = new XSCZones(
|
|
signal.symbol,
|
|
signal.period //
|
|
);
|
|
|
|
//
|
|
XSCZonesInput zonesInput;
|
|
zonesInput.length = 26;
|
|
zonesInput.numberOfZones = 10;
|
|
|
|
//
|
|
zonesInput.AddLevelColor(
|
|
hotLevels[0],
|
|
clrRed //
|
|
);
|
|
zonesInput.AddLevelColor(
|
|
hotLevels[1],
|
|
clrOrange //
|
|
);
|
|
zonesInput.AddLevelColor(
|
|
hotLevels[2],
|
|
clrLightCoral //
|
|
);
|
|
|
|
//
|
|
bool canUseZones = zones.Init(zonesInput);
|
|
if (canUseZones)
|
|
{
|
|
signal.zones = zones;
|
|
}
|
|
|
|
//
|
|
// Calculate Trend ...
|
|
XSCTrend *trend = new XSCTrend(
|
|
signal.symbol,
|
|
signal.period //
|
|
);
|
|
|
|
//
|
|
XSCTrendInput tInputs;
|
|
tInputs.Default();
|
|
bool canUseTrend = trend.Init(tInputs);
|
|
if (canUseTrend)
|
|
{
|
|
//
|
|
signal.trend = trend;
|
|
}
|
|
|
|
//
|
|
XSCCFInput cfInputs;
|
|
cfInputs.Default();
|
|
XSCCF *cf = new XSCCF(
|
|
signal.symbol,
|
|
signal.period //
|
|
);
|
|
bool canUseCF = cf.Init(cfInputs);
|
|
if (canUseCF)
|
|
{
|
|
signal.cf = cf;
|
|
}
|
|
|
|
//
|
|
void GenerateSupportSignals(
|
|
XSignal &signal // Source Signal for Support Generating ...
|
|
)
|
|
{
|
|
//
|
|
double pivots[];
|
|
int pivotsCount = GenerateSupportPivots(
|
|
signal,
|
|
pivots //
|
|
);
|
|
if (!IsValidSize(pivotsCount))
|
|
{
|
|
return;
|
|
}
|
|
|
|
//
|
|
XSignal supports[];
|
|
int indirectionalsCount =
|
|
PrepareInDirectionalSupportSignals(
|
|
supports,
|
|
signal,
|
|
pivots //
|
|
);
|
|
if (IsValidSize(indirectionalsCount))
|
|
{
|
|
//
|
|
Copy(
|
|
supports,
|
|
signal.supports //
|
|
);
|
|
|
|
//
|
|
Clean(supports);
|
|
}
|
|
}
|
|
|
|
//
|
|
int GenerateSupportPivots(
|
|
XSignal &signal, // Source Signal for Support Generating ...
|
|
double &pivots[] //
|
|
)
|
|
{
|
|
//
|
|
int result = 0;
|
|
|
|
//
|
|
// Validate Signal ...
|
|
if (!signal.IsValid())
|
|
{
|
|
return result;
|
|
}
|
|
|
|
//
|
|
// Retrieve Signal Direction ...
|
|
bool isLong = IsLong(signal.type);
|
|
|
|
//
|
|
bool canUseCF = signal.cf != NULL &&
|
|
signal.cf.IsValid();
|
|
bool canUseZones = signal.zones != NULL &&
|
|
signal.zones.IsValid();
|
|
bool canUseTrend = signal.trend != NULL &&
|
|
signal.trend.IsValid();
|
|
|
|
//
|
|
datetime prevTime = iTime(
|
|
signal.symbol,
|
|
signal.period,
|
|
1 //
|
|
);
|
|
|
|
//
|
|
datetime cTime = TimeCurrent();
|
|
|
|
//
|
|
string entryLineName = "sEntry" + signal.symbol;
|
|
DrawTrendLine(
|
|
0,
|
|
entryLineName,
|
|
0,
|
|
prevTime,
|
|
signal.entry,
|
|
cTime,
|
|
signal.entry,
|
|
clrYellow,
|
|
STYLE_SOLID,
|
|
2,
|
|
false,
|
|
false,
|
|
true //
|
|
);
|
|
|
|
//
|
|
Clean(pivots);
|
|
double tmpPivots[];
|
|
|
|
//
|
|
if (canUseCF)
|
|
{
|
|
//
|
|
signal.cf.Draw();
|
|
XOHCL cfBULLBar = signal.cf.GetBullishBar();
|
|
XOHCL cfBEARBar = signal.cf.GetBearishBar();
|
|
|
|
//
|
|
Add(
|
|
cfBULLBar.high,
|
|
tmpPivots //
|
|
);
|
|
Add(
|
|
cfBULLBar.low,
|
|
tmpPivots //
|
|
);
|
|
Add(
|
|
cfBEARBar.high,
|
|
tmpPivots //
|
|
);
|
|
Add(
|
|
cfBEARBar.low,
|
|
tmpPivots //
|
|
);
|
|
|
|
//
|
|
signal.cf.Remove();
|
|
}
|
|
|
|
//
|
|
if (canUseTrend)
|
|
{
|
|
//
|
|
signal.trend.Draw();
|
|
|
|
//
|
|
// Lows ...
|
|
Add(
|
|
signal.trend.GetLows(),
|
|
tmpPivots //
|
|
);
|
|
|
|
//
|
|
// Highs ...
|
|
Add(
|
|
signal.trend.GetHighs(),
|
|
tmpPivots //
|
|
);
|
|
|
|
//
|
|
// Support ...
|
|
Add(
|
|
signal.trend.GetSupport(),
|
|
tmpPivots //
|
|
);
|
|
|
|
//
|
|
// Resistance ...
|
|
Add(
|
|
signal.trend.GetResistance(),
|
|
tmpPivots //
|
|
);
|
|
|
|
//
|
|
signal.trend.Remove();
|
|
}
|
|
|
|
//
|
|
if (canUseZones)
|
|
{
|
|
//
|
|
signal.zones.Draw();
|
|
|
|
//
|
|
// Find Hot Zones ...
|
|
for (int i = 0; i < signal.zones.CountZones(); i++)
|
|
{
|
|
//
|
|
// Retrieve Indexed Zone ...
|
|
XSCZone *iZone = signal.zones.GetZone(i);
|
|
|
|
//
|
|
// Check Zone is Hot Zone or not ...
|
|
bool isHotZone = false;
|
|
for (int j = 0; j < ArraySize(hotLevels); j++)
|
|
{
|
|
//
|
|
isHotZone = (iZone.percent / 100) >= hotLevels[j];
|
|
if (isHotZone)
|
|
{
|
|
break;
|
|
}
|
|
}
|
|
|
|
//
|
|
// Prevent Moving Forward if there isn't Hot Zone ...
|
|
if (!isHotZone)
|
|
{
|
|
continue;
|
|
}
|
|
|
|
//
|
|
// Zone High ...
|
|
Add(
|
|
iZone.high,
|
|
tmpPivots //
|
|
);
|
|
|
|
//
|
|
// Zone Low ...
|
|
Add(
|
|
iZone.low,
|
|
tmpPivots //
|
|
);
|
|
}
|
|
|
|
//
|
|
signal.zones.Remove();
|
|
}
|
|
|
|
//
|
|
int tmpPivotsCount = ArraySize(tmpPivots);
|
|
if (!IsValidSize(tmpPivotsCount))
|
|
{
|
|
return result;
|
|
}
|
|
|
|
//
|
|
for (int i = 0; i < tmpPivotsCount; i++)
|
|
{
|
|
//
|
|
double iPivot = tmpPivots[i];
|
|
|
|
//
|
|
bool isValidPivot =
|
|
isLong
|
|
? signal.entry > iPivot
|
|
: signal.entry < iPivot;
|
|
if (isValidPivot)
|
|
{
|
|
//
|
|
Add(
|
|
iPivot,
|
|
pivots //
|
|
);
|
|
}
|
|
}
|
|
|
|
//
|
|
ArrayFree(tmpPivots);
|
|
|
|
//
|
|
RemoveDraws(entryLineName);
|
|
|
|
//
|
|
result = ArraySize(pivots);
|
|
|
|
//
|
|
return result;
|
|
}
|
|
|
|
//
|
|
bool PrepareDirectionalSupportSignals(
|
|
XPosition &support,
|
|
XPosition &parent,
|
|
XSignal &result //
|
|
)
|
|
{
|
|
//
|
|
bool mResult = false;
|
|
|
|
//
|
|
result.Clean();
|
|
|
|
//
|
|
mResult = support.IsValid() && parent.IsValid();
|
|
if (!mResult)
|
|
{
|
|
return mResult;
|
|
}
|
|
|
|
//
|
|
mResult = support.provider == XEQMSupportToken + XINDirectionalToken;
|
|
if (!mResult)
|
|
{
|
|
return mResult;
|
|
}
|
|
|
|
//
|
|
// Indirectional Supports Updated Using Directional ...
|
|
|
|
//
|
|
double entryPrice = GetEntry(
|
|
parent.symbol,
|
|
parent.type //
|
|
);
|
|
|
|
//
|
|
ENUM_X_ORDER_MODES rMode = X_ORDER_MODE_NOTHING;
|
|
bool isParentLong = IsLong(parent.type);
|
|
if (isParentLong)
|
|
{
|
|
//
|
|
if (entryPrice < parent.entry)
|
|
{
|
|
rMode = X_ORDER_MODE_STOP;
|
|
}
|
|
}
|
|
else
|
|
{
|
|
//
|
|
if (entryPrice > parent.entry)
|
|
{
|
|
rMode = X_ORDER_MODE_STOP;
|
|
}
|
|
}
|
|
|
|
//
|
|
mResult = rMode != X_ORDER_MODE_NOTHING;
|
|
if (!mResult)
|
|
{
|
|
return mResult;
|
|
}
|
|
|
|
//
|
|
mResult = result.Prepare(
|
|
parent.symbol,
|
|
XEQMSupportToken + XDirectionalToken,
|
|
parent.period,
|
|
parent.type,
|
|
rMode,
|
|
parent.entry,
|
|
parent.volume,
|
|
0,
|
|
0 //
|
|
);
|
|
|
|
//
|
|
if (mResult)
|
|
{
|
|
//
|
|
string comment = GenerateSupportTag(parent.ticket);
|
|
result.comment = comment;
|
|
}
|
|
else
|
|
{
|
|
result.Clean();
|
|
}
|
|
|
|
//
|
|
return mResult;
|
|
}
|
|
|
|
//
|
|
int PrepareInDirectionalSupportSignals(
|
|
XSignal &supports[],
|
|
XSignal &source,
|
|
double &pivots[] //
|
|
)
|
|
{
|
|
//
|
|
int result = 0;
|
|
|
|
//
|
|
Clean(supports);
|
|
|
|
//
|
|
int pivotsCount = ArraySize(pivots);
|
|
if (!IsValidSize(pivotsCount))
|
|
{
|
|
return result;
|
|
}
|
|
|
|
//
|
|
bool isLong = IsLong(source.type);
|
|
|
|
//
|
|
XSignal rSignal; // Recovery Signal ...
|
|
|
|
//
|
|
double rSL = 0; // Recovery Stop Loss ...
|
|
double rTP = 0; // Recovery Take Profit ...
|
|
double rEntry = 0; // Recovery Entry Point ...
|
|
double rVolume = 0; // Recovery Volume ...
|
|
ENUM_POSITION_TYPE rType; // Recovery Signal Type ...
|
|
ENUM_X_ORDER_MODES rMode; // Recovery Signal Mode ...
|
|
bool isSignalPrepared = false; // Check Signal Preparation Succeed ...
|
|
|
|
//
|
|
bool condition = false;
|
|
|
|
//
|
|
double onePointValue = PointToPrice(1, source.symbol);
|
|
|
|
//
|
|
double directionalVolumeMultiplier = 1;
|
|
double inDirectionalVolumeMultiplier = 2;
|
|
|
|
//
|
|
// if Long we are Looking for lower prices than
|
|
// entry price and vise verse ...
|
|
|
|
//
|
|
for (int i = 0; i < pivotsCount; i++)
|
|
{
|
|
//
|
|
double iPivot = pivots[i];
|
|
|
|
//
|
|
bool isValidPrice =
|
|
isLong
|
|
? source.entry > iPivot
|
|
: source.entry < iPivot;
|
|
if (!isValidPrice)
|
|
{
|
|
continue;
|
|
}
|
|
|
|
//
|
|
// InDirectional ...
|
|
if (isLong)
|
|
{
|
|
//
|
|
rType = POSITION_TYPE_SELL;
|
|
rMode = X_ORDER_MODE_STOP;
|
|
}
|
|
else
|
|
{
|
|
//
|
|
rType = POSITION_TYPE_BUY;
|
|
rMode = X_ORDER_MODE_STOP;
|
|
}
|
|
|
|
//
|
|
rEntry = iPivot;
|
|
rVolume = source.volume;
|
|
|
|
//
|
|
isSignalPrepared = rSignal.Prepare(
|
|
source.symbol,
|
|
XEQMSupportToken + XINDirectionalToken,
|
|
source.period,
|
|
rType,
|
|
rMode,
|
|
rEntry,
|
|
rVolume,
|
|
rSL,
|
|
rTP //
|
|
);
|
|
if (isSignalPrepared)
|
|
{
|
|
//
|
|
AddRef(
|
|
rSignal,
|
|
supports //
|
|
);
|
|
|
|
//
|
|
rSignal.Clean();
|
|
|
|
//
|
|
rSL = 0;
|
|
rTP = 0;
|
|
rEntry = 0;
|
|
isSignalPrepared = false;
|
|
}
|
|
}
|
|
|
|
//
|
|
result = ArraySize(supports);
|
|
|
|
//
|
|
return result;
|
|
}
|
|
|
|
/////////////////////////////////////////////////////////////////////////////////////////
|
|
|
|
double pivots[];
|
|
Clean(pivots);
|
|
|
|
//
|
|
X121SignalGenerator generator;
|
|
XSignal tSignal = _signal;
|
|
generator.GenerateSupportPivots(
|
|
tSignal,
|
|
pivots //
|
|
);
|
|
tSignal.Clean();
|
|
int pivotsCount = ArraySize(pivots);
|
|
|
|
//
|
|
// Retrieve Support Signal ...
|
|
bool HasSupport(
|
|
XSignal &support //
|
|
)
|
|
{
|
|
//
|
|
bool result = false;
|
|
|
|
//
|
|
result = IsValid();
|
|
if (!result)
|
|
{
|
|
return result;
|
|
}
|
|
|
|
//
|
|
int pivotsCount = ArraySize(pivots);
|
|
result = IsValidSize(pivotsCount);
|
|
if (!result)
|
|
{
|
|
return result;
|
|
}
|
|
|
|
//
|
|
support.Clean();
|
|
|
|
//
|
|
ENUM_POSITION_TYPE sType =
|
|
type == X_POSITION_TYPE_LONG
|
|
? POSITION_TYPE_BUY
|
|
: POSITION_TYPE_SELL;
|
|
|
|
//
|
|
bool isLong = IsLong(type);
|
|
|
|
//
|
|
ENUM_POSITION_TYPE cType = GetOpposit(sType);
|
|
double cEntry = GetEntry(
|
|
symbol,
|
|
cType //
|
|
);
|
|
|
|
//
|
|
double pivot = 0;
|
|
int pivotIndex = -1;
|
|
for (int i = 0; i < pivotsCount; i++)
|
|
{
|
|
//
|
|
double iPivot = pivots[i];
|
|
if (iPivot <= 0)
|
|
{
|
|
continue;
|
|
}
|
|
|
|
//
|
|
result =
|
|
isLong
|
|
? cEntry < entry && cEntry <= iPivot
|
|
: cEntry > entry && cEntry >= iPivot;
|
|
if (result)
|
|
{
|
|
//
|
|
pivot = iPivot;
|
|
pivotIndex = i;
|
|
break;
|
|
}
|
|
}
|
|
|
|
//
|
|
if (result)
|
|
{
|
|
//
|
|
result = support.Prepare(
|
|
symbol,
|
|
XEQMSupportToken + XINDirectionalToken,
|
|
period,
|
|
cType,
|
|
X_ORDER_MODE_MARKET,
|
|
cEntry,
|
|
volume * 2,
|
|
0,
|
|
0 //
|
|
);
|
|
if (result)
|
|
{
|
|
//
|
|
string comment = GenerateSupportTag(ticket);
|
|
support.comment = comment;
|
|
|
|
//
|
|
// Prepare Directional Support ...
|
|
XSignal mSup;
|
|
result = mSup.Prepare(
|
|
symbol,
|
|
XEQMSupportToken + XDirectionalToken,
|
|
period,
|
|
sType,
|
|
X_ORDER_MODE_STOP,
|
|
entry,
|
|
volume,
|
|
0,
|
|
0 //
|
|
);
|
|
if (result)
|
|
{
|
|
//
|
|
string comment = GenerateSupportTag(ticket);
|
|
mSup.comment = comment;
|
|
|
|
//
|
|
AddRef(
|
|
mSup,
|
|
support.supports //
|
|
);
|
|
|
|
//
|
|
result = ArrayRemove(
|
|
pivots,
|
|
pivotIndex,
|
|
1 //
|
|
);
|
|
}
|
|
}
|
|
}
|
|
|
|
//
|
|
if (!result)
|
|
{
|
|
support.Clean();
|
|
}
|
|
|
|
//
|
|
return result;
|
|
}
|
|
|
|
//
|
|
bool RemovePivot(
|
|
double pivot,
|
|
int index //
|
|
)
|
|
{
|
|
//
|
|
bool result = false;
|
|
|
|
//
|
|
result = IsValid() &&
|
|
IsValidIndex(index) &&
|
|
ArraySize(pivots) > index;
|
|
if (!result)
|
|
{
|
|
return result;
|
|
}
|
|
|
|
//
|
|
result = ArrayRemove(
|
|
pivots,
|
|
index,
|
|
1 //
|
|
);
|
|
|
|
//
|
|
return result;
|
|
}
|
|
|
|
///////////////////////////////////////////////////////////////////////////
|
|
|
|
// input double x121EAForceCloseProfit = 5; // Close All Positions Regardless of Policies when Profit Reached
|
|
// input double x121EAMaxDrawdownForce = 5; // Max Drawdown Force State for Handling Guards
|
|
// input int x121EAMaxPositionsForce = 10; // Max Number of Positions Force State for Handling Guards
|
|
// input double x121EAMinFreeMargingForHandleForce = 800; // Min Free Margin for Force States
|
|
// input bool x121EAAllowSymbolHedgeOnForce = false; // Allow Symbol Hedging on Force States
|
|
|
|
// x121EA.ForceCloseProfit(x121EAForceCloseProfit);
|
|
// x121EA.MaxDrawdownForce(x121EAMaxDrawdownForce);
|
|
// x121EA.MaxPositionsForce(x121EAMaxPositionsForce);
|
|
// x121EA.AllowSymbolHedgeOnForce(x121EAAllowSymbolHedgeOnForce);
|
|
// x121EA.MinFreeMargingForHandleForce(x121EAMinFreeMargingForHandleForce);
|
|
|
|
double mForceCloseProfit; // Close All Positions Regardless of Policies when Profit Reached
|
|
|
|
//
|
|
double ForceCloseProfit()
|
|
{
|
|
return mForceCloseProfit;
|
|
}
|
|
|
|
//
|
|
void ForceCloseProfit(double value)
|
|
{
|
|
//
|
|
if (value < 0)
|
|
{
|
|
value = 0;
|
|
}
|
|
|
|
//
|
|
mForceCloseProfit = value;
|
|
}
|
|
|
|
//
|
|
double MaxDrawdownForce()
|
|
{
|
|
return mMaxDrawdownForce;
|
|
}
|
|
|
|
//
|
|
void MaxDrawdownForce(double value)
|
|
{
|
|
//
|
|
if (value < 0)
|
|
{
|
|
value = 0;
|
|
}
|
|
|
|
//
|
|
mMaxDrawdownForce = value;
|
|
}
|
|
|
|
//
|
|
int MaxPositionsForce()
|
|
{
|
|
return mMaxPositionsForce;
|
|
}
|
|
|
|
//
|
|
void MaxPositionsForce(int value)
|
|
{
|
|
//
|
|
if (value < 0)
|
|
{
|
|
value = 0;
|
|
}
|
|
|
|
//
|
|
mMaxPositionsForce = value;
|
|
}
|
|
|
|
//
|
|
bool AllowSymbolHedgeOnForce()
|
|
{
|
|
return mAllowSymbolHedgeOnForce;
|
|
}
|
|
|
|
//
|
|
void AllowSymbolHedgeOnForce(bool value)
|
|
{
|
|
mAllowSymbolHedgeOnForce = value;
|
|
}
|
|
|
|
return;
|
|
|
|
//
|
|
if (!IsValidSize(setupsCount))
|
|
{
|
|
return;
|
|
}
|
|
|
|
//
|
|
// Here i Can Check what to do In Force State ...
|
|
|
|
//
|
|
// Handle Hedging Based On Positions ...
|
|
double drawdown = GetDrawdownPercent();
|
|
double forceDrawdown = MaxDrawdownForce();
|
|
int positionsForce = MaxPositionsForce();
|
|
double forceCloseProfit = ForceCloseProfit();
|
|
double minRequiredProfitPerTrade = MinRequiredProfitPerTrade();
|
|
double minRequiredProfitPerVolumeFactor = MinRequiredProfitPerVolumeFactor();
|
|
|
|
//
|
|
// Try To Force Hedging ...
|
|
bool canForceHedge =
|
|
(positionsForce <= 0
|
|
? true
|
|
: positionsCount > positionsForce)
|
|
//
|
|
||
|
|
//
|
|
(forceDrawdown > 0 &&
|
|
drawdown >= forceDrawdown);
|
|
if (canForceHedge)
|
|
{
|
|
//
|
|
// Check Required Profit ...
|
|
|
|
//
|
|
double profit = SpecifiedCalculatePositionsProfit(positions);
|
|
|
|
//
|
|
// Check Force Close Profit ...
|
|
if (forceCloseProfit > 0)
|
|
{
|
|
//
|
|
canForceHedge = profit >= forceCloseProfit;
|
|
if (canForceHedge)
|
|
{
|
|
//
|
|
bool isHedged = DoEQMForceClose();
|
|
if (isHedged)
|
|
{
|
|
return;
|
|
}
|
|
}
|
|
}
|
|
|
|
//
|
|
// Calculate Required Profit ...
|
|
double requiredProfit = SpecifiedCalculateRequiredProfitForHedge(
|
|
positions,
|
|
minRequiredProfitPerTrade,
|
|
minRequiredProfitPerVolumeFactor //
|
|
);
|
|
|
|
//
|
|
canForceHedge =
|
|
requiredProfit <= 0
|
|
? profit > 0
|
|
: profit >= (requiredProfit / 2);
|
|
if (canForceHedge)
|
|
{
|
|
//
|
|
bool isHedged = DoEQMForceClose();
|
|
if (isHedged)
|
|
{
|
|
return;
|
|
}
|
|
}
|
|
|
|
//
|
|
// At Least Hedgeing ...
|
|
// Minimal Hedge ...
|
|
|
|
//
|
|
// Check Symbol Hedging ...
|
|
bool allowSymbolHedge = AllowSymbolHedgeOnForce();
|
|
if (allowSymbolHedge)
|
|
{
|
|
for (int i = 0; i < setupsCount; i++)
|
|
{
|
|
//
|
|
string iSymbol = mSetups[i].GetSymbol();
|
|
|
|
//
|
|
XPosition iSymbolPositions[];
|
|
int iSymbolPositionsCount = mTrader.GetPositions(
|
|
iSymbolPositions,
|
|
//
|
|
iSymbol,
|
|
NULL, // All Providers ...
|
|
NULL, // All Periods ...
|
|
NULL, // All Types ...
|
|
true // Filter By Magic ...
|
|
);
|
|
if (!IsValidSize(iSymbolPositionsCount))
|
|
{
|
|
continue;
|
|
}
|
|
|
|
//
|
|
double profit = SpecifiedCalculatePositionsProfit(iSymbolPositions);
|
|
|
|
//
|
|
double requiredProfit = SpecifiedCalculateRequiredProfitForHedge(
|
|
iSymbolPositions,
|
|
minRequiredProfitPerTrade,
|
|
minRequiredProfitPerVolumeFactor //
|
|
);
|
|
|
|
//
|
|
bool canHedge =
|
|
requiredProfit <= 0
|
|
? profit > 0
|
|
: profit >= requiredProfit;
|
|
if (canHedge)
|
|
{
|
|
//
|
|
string comment = XEQMSupportToken + " Hedge Symbol ...";
|
|
|
|
//
|
|
int closed = mTrader.Close(
|
|
iSymbolPositions,
|
|
comment //
|
|
);
|
|
|
|
//
|
|
if (closed == iSymbolPositionsCount)
|
|
{
|
|
//
|
|
mSetups[i].ForceState(false);
|
|
|
|
//
|
|
string message = XEQMSupportToken + " Hedge Symbol (" + iSymbol + "): " + ToString(profit);
|
|
Alert(message);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
return;
|
|
}
|
|
|
|
//
|
|
// Implement Other Senarios ...
|
|
|
|
//
|
|
bool isMarginPassed = IsMarginPassed();
|
|
bool isMaxNumberPassed = IsNumberOfPositionsPassed();
|
|
bool canProtect = !isMarginPassed || !isMaxNumberPassed;
|
|
if (canProtect)
|
|
{
|
|
//
|
|
int maxInDIDX = FindMaxDrawdownIndex(
|
|
positions //
|
|
);
|
|
int setupIDX = FindSetupIndex(positions[maxInDIDX].symbol);
|
|
if (IsValidIndex(maxInDIDX) && IsValidIndex(setupIDX))
|
|
{
|
|
//
|
|
string iSymbol = positions[maxInDIDX].symbol;
|
|
ENUM_TIMEFRAMES iPeriod = mSetups[setupIDX].GetPeriod();
|
|
|
|
//
|
|
// Check Position Age ...
|
|
int age = GetAge(
|
|
positions[maxInDIDX],
|
|
iPeriod //
|
|
);
|
|
if (age >= 700)
|
|
{
|
|
//
|
|
// Calculate Trend ...
|
|
XSCTrend *trend = new XSCTrend(
|
|
iSymbol,
|
|
iPeriod //
|
|
);
|
|
|
|
//
|
|
XSCTrendInput tInputs;
|
|
tInputs.Default();
|
|
bool canUseTrend = trend.Init(tInputs);
|
|
if (canUseTrend)
|
|
{
|
|
//
|
|
trend.Draw();
|
|
Print("UseTrend");
|
|
trend.Remove();
|
|
}
|
|
|
|
// string comment = XEQMSupportToken + " Close Max In D ...";
|
|
// bool isClosed = mTrader.Close(
|
|
// positions[maxInDIDX].ticket,
|
|
// comment //
|
|
// );
|
|
// if (isClosed)
|
|
// {
|
|
// //
|
|
// string message = XEQMSupportToken + " Close Position (" + ToString(positions[maxInDIDX].ticket) + ") Due Max In Drawdown ...";
|
|
// Alert(message);
|
|
// }
|
|
}
|
|
}
|
|
}
|
|
|
|
////////////////////////////////////////////////////////////////////////////////////
|
|
|
|
void EQMHandleForceState()
|
|
{
|
|
//
|
|
XPosition positions[];
|
|
int positionsCount = mTrader.GetPositions(positions);
|
|
if (!IsValidSize(positionsCount) || positionsCount <= 4)
|
|
{
|
|
return;
|
|
}
|
|
|
|
//
|
|
double minRequiredProfitPerTrade = MinRequiredProfitPerTrade();
|
|
double minRequiredProfitPerVolumeFactor = MinRequiredProfitPerVolumeFactor();
|
|
|
|
//
|
|
double profit = SpecifiedCalculatePositionsProfit(positions);
|
|
double requiredProfit = SpecifiedCalculateRequiredProfitForHedge(
|
|
positions,
|
|
minRequiredProfitPerTrade,
|
|
minRequiredProfitPerVolumeFactor //
|
|
);
|
|
|
|
//
|
|
bool canClose =
|
|
profit > 0 &&
|
|
(profit == requiredProfit ||
|
|
profit >= requiredProfit / 2);
|
|
if (canClose)
|
|
{
|
|
DoEQMForceClose();
|
|
}
|
|
|
|
return;
|
|
|
|
// //
|
|
// XPosition positions[];
|
|
// int positionsCount = mTrader.GetPositions(positions);
|
|
// if (!IsValidSize(positionsCount))
|
|
// {
|
|
// //
|
|
// EQMClearAllForceStates();
|
|
|
|
// //
|
|
// return;
|
|
// }
|
|
|
|
// //
|
|
// // Search For Force State Per Each Setup ...
|
|
// //
|
|
// int forceCount = 0;
|
|
// int setupsCount = CountSetups();
|
|
// if (IsValidSize(setupsCount))
|
|
// {
|
|
// //
|
|
// int maxAllowed = MaxAllowedTrades();
|
|
// bool perDirection = UseMaxAllowedPerDirection();
|
|
|
|
// //
|
|
// for (int i = 0; i < setupsCount; i++)
|
|
// {
|
|
// //
|
|
// string iSymbol = mSetups[i].GetSymbol();
|
|
// ENUM_TIMEFRAMES iPeriod = mSetups[i].GetPeriod();
|
|
|
|
// //
|
|
// XPosition iPositions[];
|
|
// int iPositionsCount = mTrader.GetPositions(
|
|
// iPositions,
|
|
// iSymbol,
|
|
// NULL, // All Providers ...
|
|
// NULL, // All Periods ...
|
|
// NULL, // All Types ...
|
|
// true // Filter By Magic ...
|
|
// );
|
|
// if (!IsValidSize(iPositionsCount))
|
|
// {
|
|
// continue;
|
|
// }
|
|
|
|
// //
|
|
// // Counting Positions ...
|
|
// int longs;
|
|
// double longProfits;
|
|
// double longVolumes;
|
|
|
|
// //
|
|
// int shorts;
|
|
// double shortProfits;
|
|
// double shortVolumes;
|
|
|
|
// //
|
|
// CountPositions(
|
|
// iPositions,
|
|
// //
|
|
// longs,
|
|
// longProfits,
|
|
// longVolumes,
|
|
// //
|
|
// shorts,
|
|
// shortProfits,
|
|
// shortVolumes //
|
|
// );
|
|
|
|
// //
|
|
// bool isMaxReached =
|
|
// maxAllowed <= 0
|
|
// ? false
|
|
// : !perDirection
|
|
// ? longs + shorts >= maxAllowed
|
|
// : longs >= maxAllowed && shorts >= maxAllowed;
|
|
// double volumeSummary = longVolumes + shortVolumes;
|
|
// double profitsSummary = longProfits + shortProfits;
|
|
|
|
// //
|
|
// bool isIInForce =
|
|
// //
|
|
// maxAllowed <= 0
|
|
// ? profitsSummary < 0 &&
|
|
// longVolumes == shortVolumes
|
|
// : isMaxReached &&
|
|
// profitsSummary < 0 &&
|
|
// longVolumes == shortVolumes
|
|
// //
|
|
// ;
|
|
// if (isIInForce)
|
|
// {
|
|
// //
|
|
// forceCount++;
|
|
// mSetups[i].ForceState(true);
|
|
// }
|
|
// }
|
|
// }
|
|
|
|
// //
|
|
// bool isForce = forceCount >= 1;
|
|
// if (!isForce)
|
|
// {
|
|
// return;
|
|
// }
|
|
|
|
//
|
|
}
|
|
|
|
|
|
//
|
|
void EQMHandleForceSignals(
|
|
XSignal &signals[] //
|
|
)
|
|
{
|
|
//
|
|
// Validate Signals Count ...
|
|
int signalsCount = ArraySize(signals);
|
|
if (!IsValidSize(signalsCount))
|
|
{
|
|
return;
|
|
}
|
|
|
|
//
|
|
// Validate Force Marigin ...
|
|
double marigin = mTrader.mAccount.GetMargin();
|
|
double forceMargin = 100; // TODO: Make It Configurable
|
|
bool isInForceMarigin = marigin >= forceMargin;
|
|
if (!isInForceMarigin)
|
|
{
|
|
return;
|
|
}
|
|
|
|
//
|
|
// Now we are Sure we in Force State Margin amd we Have Signals ...
|
|
|
|
//
|
|
// here we Must Symbol Categorized Positions ...
|
|
int setupsCount = CountSetups();
|
|
if (!IsValidSize(setupsCount))
|
|
{
|
|
return;
|
|
}
|
|
|
|
//
|
|
// Retrieving Positions ...
|
|
XPosition positions[];
|
|
int positionsCount = mTrader.GetPositions(positions);
|
|
if (!IsValidSize(positionsCount))
|
|
{
|
|
return;
|
|
}
|
|
|
|
//
|
|
XSymbolPositions symbolPositions[];
|
|
int symbolPositionsCount = ExtractSymbolPositions(
|
|
positions,
|
|
symbolPositions //
|
|
);
|
|
if (!IsValidSize(symbolPositionsCount))
|
|
{
|
|
return;
|
|
}
|
|
|
|
//
|
|
Log("symbolPositionsCount: " + ToString(symbolPositionsCount));
|
|
|
|
//
|
|
}
|
|
|
|
/////////////////////////////////////////////////////////////
|
|
|
|
//
|
|
// Handle Force State Management ...
|
|
bool mForce;
|
|
void EQMHandleForceState(XSignal &forceSignals[])
|
|
{
|
|
//
|
|
// Validate Force Marigin ...
|
|
double marigin = mTrader.mAccount.GetMargin();
|
|
double minFreeMarigin = MinFreeMargingForOpenTrades();
|
|
double forceMargin = 2 * minFreeMarigin; // TODO: Make It Configurable
|
|
bool isMarginForce = marigin >= forceMargin;
|
|
|
|
//
|
|
// Retrieving Positions ...
|
|
XPosition positions[];
|
|
int positionsCount = mTrader.GetPositions(positions);
|
|
if (!IsValidSize(positionsCount))
|
|
{
|
|
//
|
|
mForce = false;
|
|
|
|
//
|
|
datetime cTime = TimeCurrent();
|
|
string message = "Exit From Force State: " + ToString(cTime);
|
|
|
|
//
|
|
// Log(message);
|
|
return;
|
|
}
|
|
|
|
//
|
|
XPosition oldest;
|
|
int oldestAge = GetOldest(
|
|
oldest,
|
|
positions //
|
|
);
|
|
|
|
//
|
|
// Check Force State ...
|
|
bool isForce = isMarginForce; // && oldestAge >= 288;
|
|
if (!isForce)
|
|
{
|
|
//
|
|
if (mForce)
|
|
{
|
|
//
|
|
mForce = false;
|
|
|
|
//
|
|
datetime cTime = TimeCurrent();
|
|
string message = "Exit From Force State: " + ToString(cTime);
|
|
|
|
//
|
|
// Log(message);
|
|
}
|
|
return;
|
|
}
|
|
else
|
|
{
|
|
mForce = true;
|
|
}
|
|
|
|
//
|
|
// Prevent Moving Forward From Non Force State ...
|
|
if (!mForce)
|
|
{
|
|
return;
|
|
}
|
|
|
|
//
|
|
int forceSignalsCount = ArraySize(forceSignals);
|
|
if (IsValidSize(forceSignalsCount))
|
|
{
|
|
//
|
|
Log("Force Signals Count: " + ToString(forceSignalsCount));
|
|
}
|
|
|
|
// //
|
|
// double minProfitPerTrade = MinProfitPerTrade();
|
|
// double minProfitPerVolumeFactor = MinProfitPerVolumeFactor();
|
|
|
|
// //
|
|
// double profit = SpecifiedCalculatePositionsProfit(positions);
|
|
// double requiredProfit = SpecifiedCalculateRequiredProfitForHedge(
|
|
// positions,
|
|
// minProfitPerTrade,
|
|
// minProfitPerVolumeFactor //
|
|
// );
|
|
|
|
// //
|
|
// XSymbolPositions symbolPositions[];
|
|
// int symbolPositionsCount = ExtractSymbolPositions(
|
|
// positions,
|
|
// symbolPositions,
|
|
// minProfitPerTrade,
|
|
// minProfitPerVolumeFactor //
|
|
// );
|
|
// if (!IsValidSize(symbolPositionsCount))
|
|
// {
|
|
// return;
|
|
// }
|
|
|
|
//
|
|
// Log("symbolPositionsCount: " + ToString(symbolPositionsCount));
|
|
}
|
|
|
|
|
|
/////////////////////////////////////////////////////////////////
|
|
|
|
//
|
|
// Handle any Invalid Signals ...
|
|
void EQMHandleInvalidSignal(
|
|
XSignal &signal, // Invalid Signal
|
|
int pushers, // Pushers
|
|
bool isValid, // IsValid Signal ...
|
|
X121SetupConditions &conditions[] // All Time Frames Conditions
|
|
)
|
|
{
|
|
//
|
|
// Check Force State ...
|
|
// if (!ForceState())
|
|
// {
|
|
// return;
|
|
// }
|
|
|
|
//
|
|
int setupIDX = FindSetupIndex(signal.symbol);
|
|
if (!IsValidIndex(setupIDX))
|
|
{
|
|
return;
|
|
}
|
|
|
|
//
|
|
bool isForce = mForce; // mSetups[setupIDX].ForceState();
|
|
if (!isForce)
|
|
{
|
|
return;
|
|
}
|
|
|
|
//
|
|
// Check Delay Between Two Signals ...
|
|
// bool isMarginPassed = IsMarginPassed();
|
|
// bool isDelayPassed = IsSignalDelayPassed(signal);
|
|
// bool isNumberOfPositionsPassed = IsNumberOfPositionsPassed();
|
|
// bool canUseSignal =
|
|
// isMarginPassed &&
|
|
// isDelayPassed &&
|
|
// isNumberOfPositionsPassed;
|
|
|
|
//
|
|
XSignal signals[];
|
|
|
|
//
|
|
if (isValid)
|
|
{
|
|
//
|
|
Log("IsValid Invalid Signal ...");
|
|
|
|
//
|
|
bool canSupport =
|
|
//
|
|
EnableSupport() &&
|
|
SupportOnlyForces()
|
|
//
|
|
;
|
|
bool canGrid =
|
|
//
|
|
EnableGrid() &&
|
|
GridOnlyForces()
|
|
//
|
|
;
|
|
bool canRecover =
|
|
//
|
|
EnableRecovery() &&
|
|
RecoverOnlyForces()
|
|
//
|
|
;
|
|
|
|
//
|
|
if (canUseSignal)
|
|
{
|
|
//
|
|
AddRef(
|
|
signal,
|
|
signals //
|
|
);
|
|
|
|
//
|
|
// Add new Signal Info ...
|
|
mTradeHandler.Add(
|
|
signal,
|
|
pushers,
|
|
canGrid,
|
|
canRecover,
|
|
canSupport,
|
|
conditions[0],
|
|
conditions[1],
|
|
conditions[2],
|
|
conditions[3],
|
|
conditions[4] //
|
|
);
|
|
}
|
|
}
|
|
else
|
|
{
|
|
Log("IsValid Invalid Signal INN ...");
|
|
}
|
|
|
|
//
|
|
// if (ArraySize(signals) > 0)
|
|
// {
|
|
// EQMExecuteSignals(signals);
|
|
// }
|
|
}
|
|
|
|
|
|
/////////////////////////////////////////////////////////
|
|
|
|
|
|
//
|
|
void EQMClearAllForceStates()
|
|
{
|
|
//
|
|
int setupsCount = CountSetups();
|
|
if (!IsValidSize(setupsCount))
|
|
{
|
|
return;
|
|
}
|
|
|
|
//
|
|
for (int i = 0; i < setupsCount; i++)
|
|
{
|
|
mSetups[i].ForceState(false);
|
|
}
|
|
}
|
|
|
|
|
|
///////////////////////////////////////////////////////////
|
|
|
|
// //
|
|
// result =
|
|
// //
|
|
// // Check Price Place ...
|
|
// (
|
|
// //
|
|
// (hh4 > resistance.low ||
|
|
// (MathAbs(hh4 - resistance.low) <= threshold))
|
|
// //
|
|
// &&
|
|
// //
|
|
// ll4 < resistance.low
|
|
// //
|
|
// )
|
|
// //
|
|
// &&
|
|
// //
|
|
// // Check Candlestick Pattern ...
|
|
// (
|
|
// //
|
|
// cBar.HasBearishTrend(
|
|
// tmpSWH,
|
|
// tmpSWL,
|
|
// true //
|
|
// )
|
|
// //
|
|
// &&
|
|
// //
|
|
// (
|
|
// //
|
|
// cBar.IsShootingStar()
|
|
// //
|
|
// ||
|
|
// //
|
|
// cBar.IsEveningStar()
|
|
// //
|
|
// ||
|
|
// //
|
|
// cBar.IsBearishEngulfing()
|
|
// //
|
|
// )
|
|
// //
|
|
// )
|
|
// //
|
|
// ;
|
|
|
|
|
|
|
|
// //
|
|
// result =
|
|
// //
|
|
// // Check Price Place ...
|
|
// (
|
|
// //
|
|
// (ll4 < support.high ||
|
|
// (MathAbs(ll4 - support.high) <= threshold))
|
|
// //
|
|
// &&
|
|
// //
|
|
// hh4 > support.high
|
|
// //
|
|
// )
|
|
// //
|
|
// &&
|
|
// //
|
|
// // Check Candlestick Pattern ...
|
|
// (
|
|
// //
|
|
// cBar.HasBullishTrend(
|
|
// tmpSWH,
|
|
// tmpSWL,
|
|
// true //
|
|
// )
|
|
// //
|
|
// &&
|
|
// //
|
|
// (
|
|
// //
|
|
// cBar.IsHammer()
|
|
// //
|
|
// ||
|
|
// //
|
|
// cBar.IsMorningStar()
|
|
// //
|
|
// ||
|
|
// //
|
|
// cBar.IsBullishEngulfing()
|
|
// //
|
|
// )
|
|
// //
|
|
// )
|
|
// //
|
|
// ;
|
|
|
|
|
|
/////////////////////////////////////////////////////////////////////
|
|
|
|
//
|
|
// Try to Detect and Order Block Inside this ...
|
|
// in Mediest ...
|
|
result = medBar.IsValid();
|
|
if (!result)
|
|
{
|
|
//
|
|
result = medBar.Init(
|
|
mSymbol,
|
|
mMediestPeriod,
|
|
1 //
|
|
);
|
|
if (!result)
|
|
{
|
|
//
|
|
medBar.Clean();
|
|
return result;
|
|
}
|
|
}
|
|
|
|
//
|
|
result = medBar.HasBullishOrderBlock(medBullishOrderBlock);
|
|
if (!result)
|
|
{
|
|
//
|
|
medBar.Clean();
|
|
return result;
|
|
}
|
|
|
|
//
|
|
DrawBullishOrderBlock(
|
|
medBullishOrderBlock,
|
|
ChartID() //
|
|
);
|
|
|
|
//
|
|
// Check Order Block Is Inside HINDOB ...
|
|
result =
|
|
//
|
|
(medBullishOrderBlock.low >= hindBullishOrderBlock.low &&
|
|
medBullishOrderBlock.low <= hindBullishOrderBlock.high)
|
|
//
|
|
||
|
|
//
|
|
(medBullishOrderBlock.high <= hindBullishOrderBlock.high &&
|
|
medBullishOrderBlock.high >= hindBullishOrderBlock.low)
|
|
//
|
|
;
|
|
|
|
//
|
|
if (result)
|
|
{
|
|
//
|
|
// Check Price ...
|
|
result =
|
|
//
|
|
ll3 < medBullishOrderBlock.high &&
|
|
ll3 > hindBullishOrderBlock.low
|
|
//
|
|
;
|
|
if (!result)
|
|
{
|
|
//
|
|
hindBar.Clean();
|
|
hindBullishOrderBlock.Clean();
|
|
hindBearishOrderBlock.Clean();
|
|
|
|
//
|
|
medBar.Clean();
|
|
medBullishOrderBlock.Clean();
|
|
medBearishOrderBlock.Clean();
|
|
|
|
//
|
|
fvgUpper = 0;
|
|
fvgLower = 0;
|
|
|
|
//
|
|
RemoveDraws();
|
|
|
|
//
|
|
return result;
|
|
}
|
|
|
|
//
|
|
hasLong = result;
|
|
}
|
|
else
|
|
{
|
|
//
|
|
// Detect and FVG Inside ...
|
|
result = medBar.HasBullishFVG(
|
|
fvgUpper,
|
|
fvgLower //
|
|
);
|
|
if (!result)
|
|
{
|
|
//
|
|
hindBar.Clean();
|
|
hindBullishOrderBlock.Clean();
|
|
hindBearishOrderBlock.Clean();
|
|
|
|
//
|
|
medBar.Clean();
|
|
medBullishOrderBlock.Clean();
|
|
medBearishOrderBlock.Clean();
|
|
|
|
//
|
|
fvgUpper = 0;
|
|
fvgLower = 0;
|
|
|
|
//
|
|
RemoveDraws();
|
|
|
|
//
|
|
return result;
|
|
}
|
|
|
|
//
|
|
DrawBullishFVG(
|
|
medBar,
|
|
fvgUpper,
|
|
fvgLower,
|
|
ChartID() //
|
|
);
|
|
|
|
//
|
|
result =
|
|
//
|
|
(fvgLower >= hindBullishOrderBlock.low &&
|
|
fvgLower <= hindBullishOrderBlock.high)
|
|
//
|
|
||
|
|
//
|
|
(fvgUpper <= hindBullishOrderBlock.high &&
|
|
fvgUpper >= hindBullishOrderBlock.low)
|
|
//
|
|
;
|
|
//
|
|
// Check Price ...
|
|
result =
|
|
//
|
|
ll3 < fvgUpper &&
|
|
ll3 > hindBullishOrderBlock.low
|
|
//
|
|
;
|
|
if (!result)
|
|
{
|
|
//
|
|
hindBar.Clean();
|
|
hindBullishOrderBlock.Clean();
|
|
hindBearishOrderBlock.Clean();
|
|
|
|
//
|
|
medBar.Clean();
|
|
medBullishOrderBlock.Clean();
|
|
medBearishOrderBlock.Clean();
|
|
|
|
//
|
|
fvgUpper = 0;
|
|
fvgLower = 0;
|
|
|
|
//
|
|
RemoveDraws();
|
|
|
|
//
|
|
return result;
|
|
}
|
|
|
|
//
|
|
hasLong = result;
|
|
}
|
|
|
|
|
|
////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
//
|
|
// Try to Detect and Order Block Inside this ...
|
|
// in Mediest ...
|
|
result = medBar.IsValid();
|
|
if (!result)
|
|
{
|
|
//
|
|
result = medBar.Init(
|
|
mSymbol,
|
|
mMediestPeriod,
|
|
1 //
|
|
);
|
|
if (!result)
|
|
{
|
|
//
|
|
medBar.Clean();
|
|
return result;
|
|
}
|
|
}
|
|
|
|
//
|
|
result = medBar.HasBearishOrderBlock(medBearishOrderBlock);
|
|
if (!result)
|
|
{
|
|
//
|
|
medBar.Clean();
|
|
return result;
|
|
}
|
|
|
|
//
|
|
DrawBearishOrderBlock(
|
|
medBearishOrderBlock,
|
|
ChartID() //
|
|
);
|
|
|
|
//
|
|
// Check Order Block Is Inside HINDOB ...
|
|
result =
|
|
//
|
|
(medBullishOrderBlock.low >= hindBearishOrderBlock.low &&
|
|
medBearishOrderBlock.low <= hindBearishOrderBlock.high)
|
|
//
|
|
||
|
|
//
|
|
(medBearishOrderBlock.high <= hindBearishOrderBlock.high &&
|
|
medBearishOrderBlock.high >= hindBearishOrderBlock.low)
|
|
//
|
|
;
|
|
if (!result)
|
|
{
|
|
//
|
|
// Detect and FVG Inside ...
|
|
result = medBar.HasBearishFVG(
|
|
fvgUpper,
|
|
fvgLower //
|
|
);
|
|
if (!result)
|
|
{
|
|
//
|
|
hindBar.Clean();
|
|
hindBullishOrderBlock.Clean();
|
|
hindBearishOrderBlock.Clean();
|
|
|
|
//
|
|
medBar.Clean();
|
|
medBullishOrderBlock.Clean();
|
|
medBearishOrderBlock.Clean();
|
|
|
|
//
|
|
fvgUpper = 0;
|
|
fvgLower = 0;
|
|
|
|
//
|
|
RemoveDraws();
|
|
|
|
//
|
|
return result;
|
|
}
|
|
|
|
//
|
|
DrawBearishFVG(
|
|
medBar,
|
|
fvgUpper,
|
|
fvgLower,
|
|
ChartID() //
|
|
);
|
|
|
|
//
|
|
result =
|
|
//
|
|
(fvgLower >= hindBearishOrderBlock.low &&
|
|
fvgLower <= hindBearishOrderBlock.high)
|
|
//
|
|
||
|
|
//
|
|
(fvgUpper <= hindBearishOrderBlock.high &&
|
|
fvgUpper >= hindBearishOrderBlock.low)
|
|
//
|
|
;
|
|
if (!result)
|
|
{
|
|
//
|
|
hindBar.Clean();
|
|
hindBullishOrderBlock.Clean();
|
|
hindBearishOrderBlock.Clean();
|
|
|
|
//
|
|
medBar.Clean();
|
|
medBullishOrderBlock.Clean();
|
|
medBearishOrderBlock.Clean();
|
|
|
|
//
|
|
fvgUpper = 0;
|
|
fvgLower = 0;
|
|
|
|
//
|
|
RemoveDraws();
|
|
|
|
//
|
|
return result;
|
|
}
|
|
}
|
|
|
|
//////////////////////////////////////////////////////////////////////////////////
|
|
|
|
//
|
|
result = hasLong || hasShort;
|
|
if (!result)
|
|
{
|
|
return result;
|
|
}
|
|
|
|
//
|
|
if (hasLong)
|
|
{
|
|
//
|
|
// Long ...
|
|
|
|
//
|
|
bool isHammer = !useHammer
|
|
? false
|
|
: cBar.IsHammer();
|
|
bool isMorningStar = !useMorningStar
|
|
? false
|
|
: cBar.IsMorningStar();
|
|
bool isBullishMarubozu = !useBullishEngulfing
|
|
? false
|
|
: cBar.IsBullishMarubozu();
|
|
bool isBullishEngulfing = !useBullishMaurubozu
|
|
? false
|
|
: cBar.IsBullishEngulfing();
|
|
|
|
//
|
|
bool isBullishTrend = cBar.HasBullishTrend(
|
|
tmpHSW,
|
|
tmpLSW,
|
|
true //
|
|
);
|
|
|
|
//
|
|
// Find Swing Low Above of EMA ...
|
|
// Find Swing High Above of EMA ...
|
|
// Fins Swing Low Below of EMA ...
|
|
// Detect Bullish Pattern ...
|
|
hasLong =
|
|
//
|
|
true
|
|
//
|
|
&&
|
|
//
|
|
(
|
|
//
|
|
isHammer
|
|
//
|
|
||
|
|
//
|
|
isMorningStar
|
|
//
|
|
||
|
|
//
|
|
isBullishMarubozu
|
|
//
|
|
||
|
|
//
|
|
isBullishEngulfing
|
|
//
|
|
)
|
|
//
|
|
;
|
|
if (hasLong)
|
|
{
|
|
//
|
|
type = POSITION_TYPE_BUY;
|
|
|
|
//
|
|
// sl = tmpLSW[ArraySize(tmpLSW) - 1].low;
|
|
}
|
|
}
|
|
|
|
//
|
|
if (hasShort)
|
|
{
|
|
//
|
|
// Short ...
|
|
bool isShootingStar = !useShootingStar
|
|
? false
|
|
: cBar.IsShootingStar();
|
|
bool isEveningStar = !useEveningStar
|
|
? false
|
|
: cBar.IsEveningStar();
|
|
bool isBearishEngulfing = !useBearishEngulfing
|
|
? false
|
|
: cBar.IsBearishEngulfing();
|
|
bool isBearishMaurubozu = !useBearishMaurubozu
|
|
? false
|
|
: cBar.IsBearishMarubozu();
|
|
|
|
//
|
|
bool isBearishTrend = cBar.HasBearishTrend(
|
|
tmpHSW,
|
|
tmpLSW,
|
|
true //
|
|
);
|
|
|
|
//
|
|
hasShort =
|
|
//
|
|
false
|
|
//
|
|
&&
|
|
//
|
|
(
|
|
//
|
|
isShootingStar
|
|
//
|
|
||
|
|
//
|
|
isEveningStar
|
|
//
|
|
||
|
|
//
|
|
isBearishEngulfing
|
|
//
|
|
||
|
|
//
|
|
isBearishMaurubozu
|
|
//
|
|
)
|
|
//
|
|
;
|
|
if (hasShort)
|
|
{
|
|
//
|
|
type = POSITION_TYPE_SELL;
|
|
|
|
//
|
|
// sl = tmpHSW[ArraySize(tmpHSW) - 1].high;
|
|
}
|
|
}
|
|
|
|
/////////////////////////////////////////////////////////////////////////////////////
|
|
|
|
// hasLong =
|
|
// //
|
|
// // Must in Bullish Trend ...
|
|
// // isBullishTrend
|
|
// // //
|
|
// // &&
|
|
// //
|
|
// // Check Bar Patterns ...
|
|
// // (
|
|
// // //
|
|
// // isHammer
|
|
// // //
|
|
// // ||
|
|
// // //
|
|
// // isMorningStar
|
|
// // //
|
|
// // ||
|
|
// // //
|
|
// // isBullishMarubozu
|
|
// // //
|
|
// // ||
|
|
// // //
|
|
// // isBullishEngulfing
|
|
// // //
|
|
// // )
|
|
// // //
|
|
// // &&
|
|
// //
|
|
// // Fib3 must below mc verifier ...
|
|
// pvConditions.fib3s[ppIndex] < mcConditions.verifier[ppIndex] &&
|
|
// pvConditions.fib3s[pIndex] < mcConditions.verifier[pIndex]
|
|
// //
|
|
// &&
|
|
// //
|
|
// // Sar Must be Bullish ...
|
|
// mcConditions.psar[ppIndex] < ppBar.low &&
|
|
// mcConditions.psar[pIndex] < pBar.low &&
|
|
// mcConditions.isSARBullish
|
|
// //
|
|
// &&
|
|
// //
|
|
// // Fib3 Crossed Over Verifier ...
|
|
// pvConditions.fib3s[cIndex] > mcConditions.verifier[cIndex] &&
|
|
// pvConditions.fib3s[pIndex] <= mcConditions.verifier[pIndex]
|
|
// //
|
|
// &&
|
|
// //
|
|
// // Fast Over Slow and Slow Over Verifier ...
|
|
// mcConditions.fast[cIndex] > mcConditions.slow[cIndex] &&
|
|
// mcConditions.slow[cIndex] > mcConditions.verifier[cIndex]
|
|
// //
|
|
// &&
|
|
// //
|
|
// // CBar and PBar Close over Fast ...
|
|
// cBar.close > mcConditions.verifier[cIndex] &&
|
|
// pBar.close > mcConditions.verifier[pIndex]
|
|
// //
|
|
// ;
|
|
|
|
//
|
|
// hasLong =
|
|
// //
|
|
// isBullishTrend
|
|
// //
|
|
// &&
|
|
// //
|
|
// mcConditions.fast[cIndex] > mcConditions.fast[pIndex] &&
|
|
// mcConditions.slow[cIndex] > mcConditions.slow[pIndex]
|
|
// //
|
|
// &&
|
|
// //
|
|
// mcConditions.fast[cIndex] > mcConditions.slow[cIndex] &&
|
|
// mcConditions.fast[pIndex] < mcConditions.slow[pIndex]
|
|
// //
|
|
// &&
|
|
// //
|
|
// mcConditions.fast[cIndex] > mcConditions.verifier[cIndex] &&
|
|
// mcConditions.fast[pIndex] > mcConditions.verifier[pIndex] &&
|
|
// mcConditions.slow[cIndex] > mcConditions.verifier[cIndex] &&
|
|
// mcConditions.slow[pIndex] > mcConditions.verifier[pIndex]
|
|
// //
|
|
// &&
|
|
// //
|
|
// cBar.close > mcConditions.fast[cIndex] &&
|
|
// cBar.close > mcConditions.slow[cIndex] &&
|
|
// cBar.close > mcConditions.fast[pIndex] &&
|
|
// cBar.close > mcConditions.slow[pIndex]
|
|
// //
|
|
// &&
|
|
// //
|
|
// mcConditions.psar[cIndex] < cBar.low
|
|
// //
|
|
// &&
|
|
// //
|
|
// pvConditions.peaks[cIndex] != EMPTY_VALUE &&
|
|
// pvConditions.peaks[pIndex] != EMPTY_VALUE &&
|
|
// pvConditions.peaks[cIndex] > pvConditions.peaks[pIndex]
|
|
// //
|
|
// &&
|
|
// //
|
|
// pvConditions.fib3s[cIndex] > mcConditions.verifier[cIndex] &&
|
|
// pvConditions.fib3s[cIndex] >= pvConditions.fib3s[pIndex]
|
|
// //
|
|
// ;
|
|
|
|
// //
|
|
// // Check Fib3 Crosses ...
|
|
// bool isFib3CrossedUnder = IsValid(fibs3CrossedUnderTime);
|
|
// bool isFib3CrossedOver = IsValid(fibs3CrossedOverTime);
|
|
|
|
// //
|
|
// // Check Fib3 Crossed Under ...
|
|
// if (!isFib3CrossedUnder)
|
|
// {
|
|
// //
|
|
// isFib3CrossedUnder =
|
|
// //
|
|
// cBar.high < pvConditions.fib3s[cIndex] &&
|
|
// pBar.high > pvConditions.fib3s[pIndex]
|
|
// //
|
|
// ;
|
|
// if (isFib3CrossedUnder)
|
|
// {
|
|
// fibs3CrossedUnderTime = cBar.time;
|
|
// }
|
|
// }
|
|
// else
|
|
// {
|
|
// //
|
|
// // Check Age ...
|
|
// int age = ((int)((int)cBar.time - (int)fibs3CrossedUnderTime) / PeriodSeconds(mPeriod));
|
|
// if (age >= 20)
|
|
// {
|
|
// fibs3CrossedUnderTime = NULL;
|
|
// }
|
|
// }
|
|
|
|
// //
|
|
// // Check Fib3 Crossed Over ...
|
|
// if (!isFib3CrossedOver)
|
|
// {
|
|
// //
|
|
// isFib3CrossedOver =
|
|
// //
|
|
// cBar.low > pvConditions.fib3s[cIndex] &&
|
|
// pBar.low < pvConditions.fib3s[pIndex]
|
|
// //
|
|
// ;
|
|
// if (isFib3CrossedOver)
|
|
// {
|
|
// fibs3CrossedOverTime = cBar.time;
|
|
// }
|
|
// }
|
|
// else
|
|
// {
|
|
// //
|
|
// // Check Age ...
|
|
// int age = ((int)((int)cBar.time - (int)fibs3CrossedOverTime) / PeriodSeconds(mPeriod));
|
|
// if (age >= 20)
|
|
// {
|
|
// fibs3CrossedOverTime = NULL;
|
|
// }
|
|
// }
|
|
|
|
// //
|
|
// result =
|
|
// //
|
|
// isFib3CrossedOver
|
|
// //
|
|
// ||
|
|
// //
|
|
// isFib3CrossedUnder
|
|
// //
|
|
// ;
|
|
// if (!result)
|
|
// {
|
|
// return result;
|
|
// }
|
|
|
|
|
|
// hasLong =
|
|
//
|
|
// // isBullishTrend
|
|
// // //
|
|
// // &&
|
|
// //
|
|
// hasBullishPattern
|
|
// //
|
|
// &&
|
|
//
|
|
// cBar.IsBullishTouched(pvConditions.fib3s[cIndex])
|
|
// //
|
|
// &&
|
|
// //
|
|
// cBar.close > mcConditions.verifier[cIndex]
|
|
// //
|
|
// &&
|
|
// //
|
|
// mcConditions.psar[cIndex] < cBar.low
|
|
// //
|
|
// &&
|
|
// //
|
|
// pvConditions.fib3s[cIndex] > mcConditions.verifier[cIndex]
|
|
// //
|
|
// &&
|
|
// //
|
|
// cBar.IsBullish()
|
|
//
|
|
// ;
|
|
|
|
/////////////////////////////////////////////////////////////////////////////////////
|
|
|
|
///////////////////////////////////////////////////////
|
|
//
|
|
// SaherElm IT Center XTest MQL5 Expert Advisor
|
|
// -------------------------------------------------
|
|
// Name: XSTestEA
|
|
// Description: an Exper Advisor which used XTestSetup
|
|
// to Analyse Market ...
|
|
//
|
|
// Maintainer:
|
|
// ------------
|
|
// Hadi Khazaee Asl (hadi_khazaee_asl@yahoo.com)
|
|
//
|
|
//////////////////////////////////////////////////////x
|
|
//
|
|
// Global Properties ...
|
|
#property copyright "Copyright 2023, SaherElm IT Center"
|
|
#property link "https://saherelm.ir"
|
|
#property version "1.00"
|
|
#property description "SaherElm XSTestEA"
|
|
#property strict
|
|
|
|
//
|
|
#define ShortName "XSTestEA"
|
|
|
|
//
|
|
// Imports ...
|
|
#include "../Helpers/x-saherelm.xct.helper.mq5"
|
|
#include "../Helpers/x-saherelm.xcc.helper.mq5"
|
|
|
|
//
|
|
#include "../Strategies/x-saherelm.xtest.strategy.mq5"
|
|
// #include "../Strategies/x-saherelm.xobvg.strategy.mq5"
|
|
// #include "../Strategies/x-saherelm.xsrbr.strategy.mq5"
|
|
// #include "../Strategies/x-saherelm.xpvfmc.strategy.mq5"
|
|
// #include "../Strategies/x-saherelm.xemrng.strategy.mq5"
|
|
|
|
//
|
|
// Inputs ...
|
|
long eaMagicNumber = 78692110; // Magic Number
|
|
int eaSlippage = 10; // Slippgae
|
|
|
|
//
|
|
double eaVolume = 0.01;
|
|
double eaAllowLong = true;
|
|
double eaAllowShort = true;
|
|
|
|
//
|
|
int eaMaxAllowedLongs = 0;
|
|
int eaMaxAllowedShorts = 0;
|
|
|
|
//
|
|
double eaTPPoint = 200;
|
|
double eaSLPoint = 100;
|
|
|
|
//
|
|
bool eaIgnoreTP = false;
|
|
bool eaIgnoreSL = false;
|
|
|
|
//
|
|
double eaR2R = 2;
|
|
|
|
//
|
|
// Variables ...
|
|
XSCXCTHelper *mCTHelper;
|
|
XSCXCCHelper *mCCHelper;
|
|
|
|
//
|
|
XSCBaseStrategy *strategies[];
|
|
|
|
//
|
|
// Event Handlers ...
|
|
|
|
//
|
|
// Initialization ...
|
|
int OnInit()
|
|
{
|
|
//
|
|
if (!ValidateInputs())
|
|
{
|
|
return INIT_PARAMETERS_INCORRECT;
|
|
}
|
|
|
|
//
|
|
if (!InitialEA())
|
|
{
|
|
return INIT_FAILED;
|
|
}
|
|
|
|
//
|
|
drawPrefix = ShortName;
|
|
|
|
//
|
|
// EventSetTimer(1);
|
|
// EventSetMillisecondTimer(100);
|
|
|
|
//
|
|
// Init Succeed ...
|
|
return INIT_SUCCEEDED;
|
|
}
|
|
|
|
//
|
|
// DeInitialization ...
|
|
void OnDeinit(const int reason)
|
|
{
|
|
//
|
|
// REASON_PROGRAM 0 The EA has stopped working calling the ExpertRemove() function
|
|
// REASON_REMOVE 1 Program removed from a chart
|
|
// REASON_RECOMPILE 2 Program recompiled
|
|
// REASON_CHARTCHANGE 3 A symbol or a chart period is changed
|
|
// REASON_CHARTCLOSE 4 Chart closed
|
|
// REASON_PARAMETERS 5 Inputs changed by a user
|
|
// REASON_ACCOUNT 6 Another account has been activated or reconnection to the trade server has occurred due to changes in the account settings
|
|
// REASON_TEMPLATE 7 Another chart template applied
|
|
// REASON_INITFAILED 8 The OnInit() handler returned a non-zero value
|
|
// REASON_CLOSE 9 Terminal closed
|
|
|
|
//
|
|
// De Initialize XSampleEA Providers ...
|
|
delete mCTHelper;
|
|
delete mCCHelper;
|
|
|
|
//
|
|
// EventKillTimer();
|
|
|
|
//
|
|
Clean(strategies);
|
|
}
|
|
|
|
//
|
|
// On Tick Handler ...
|
|
void OnTick()
|
|
{
|
|
HandleStrategiesOnTick();
|
|
}
|
|
|
|
//
|
|
// On Timer ...
|
|
void OnTimer()
|
|
{
|
|
//
|
|
// HandleStrategiesOnTick();
|
|
}
|
|
|
|
//
|
|
// Custom Functions ...
|
|
|
|
//
|
|
// Validate Inputs ...
|
|
bool ValidateInputs()
|
|
{
|
|
//
|
|
bool result = false;
|
|
|
|
//
|
|
result = true;
|
|
|
|
//
|
|
return result;
|
|
}
|
|
|
|
//
|
|
// Initialize all Requirements ...
|
|
bool InitialEA()
|
|
{
|
|
//
|
|
bool result = false;
|
|
|
|
//
|
|
// Bar Timer ...
|
|
XCTInputs ctInputs;
|
|
ctInputs.Default();
|
|
mCTHelper = new XSCXCTHelper();
|
|
result = mCTHelper.Init(
|
|
_Symbol,
|
|
_Period,
|
|
ctInputs //
|
|
);
|
|
if (!result)
|
|
{
|
|
return result;
|
|
}
|
|
|
|
//
|
|
// Bar Styles ...
|
|
XCCInputs ccInputs;
|
|
ccInputs.Default();
|
|
mCCHelper = new XSCXCCHelper();
|
|
result = mCCHelper.Init(
|
|
_Symbol,
|
|
_Period,
|
|
ccInputs //
|
|
);
|
|
if (!result)
|
|
{
|
|
return result;
|
|
}
|
|
|
|
//
|
|
XSymbolParser symbolParser;
|
|
|
|
//
|
|
bool drawAreas = false;
|
|
|
|
//
|
|
bool useEURUSD = true;
|
|
bool useUSDCHF = false;
|
|
bool useUSDJPY = false;
|
|
bool useGBPUSD = false;
|
|
bool useXAUUSD = false;
|
|
|
|
//
|
|
bool useXSRBR = false;
|
|
bool useXEMRNG = false;
|
|
bool useXOBVG = false;
|
|
bool useXPVFMC = false;
|
|
bool useXTest = true;
|
|
|
|
//
|
|
// EURUSD ...
|
|
string eurusdSymbol = "EURUSDb"; // symbolParser.GetEURUSDSymbol();
|
|
if (useEURUSD && IsValid(eurusdSymbol))
|
|
{
|
|
//
|
|
// MAGIC NUMBER ...
|
|
long magicNumber = eaMagicNumber + 1;
|
|
|
|
//
|
|
// XTest ...
|
|
if (useXTest)
|
|
{
|
|
//
|
|
XSCXTestStrategy *eurusdTestStrategy;
|
|
eurusdTestStrategy = new XSCXTestStrategy(
|
|
eurusdSymbol,
|
|
PERIOD_M5,
|
|
eaVolume,
|
|
eaR2R, // R2R ...
|
|
eaSlippage,
|
|
magicNumber,
|
|
false, // Use TP SL Point
|
|
false, // Use Max
|
|
eaTPPoint, // TP
|
|
eaSLPoint, // SL
|
|
eaIgnoreTP,
|
|
eaIgnoreSL,
|
|
eaAllowLong,
|
|
eaAllowShort,
|
|
eaMaxAllowedLongs, // Max Longs
|
|
eaMaxAllowedShorts // Max Shorts
|
|
);
|
|
eurusdTestStrategy.SetAlertLogAlerts(true);
|
|
eurusdTestStrategy.SetAlertEnableAlerts(true);
|
|
RegisterStrategy(eurusdTestStrategy);
|
|
}
|
|
|
|
// //
|
|
// // XSRBR ...
|
|
// if (useXSRBR)
|
|
// {
|
|
// //
|
|
// // Register XSRBR on EURUSD in M5 ...
|
|
// XSCXSRBRStrategy *eurusdM5SRBRStrategy;
|
|
// eurusdM5SRBRStrategy = new XSCXSRBRStrategy(
|
|
// eurusdSymbol,
|
|
// PERIOD_M5,
|
|
// PERIOD_H1,
|
|
// eaVolume,
|
|
// eaR2R, // R2R ...
|
|
// eaSlippage,
|
|
// magicNumber,
|
|
// true, // Use TP SL Point
|
|
// false, // Use Max
|
|
// eaTPPoint, // TP
|
|
// eaSLPoint, // SL
|
|
// eaAllowLong,
|
|
// eaAllowShort,
|
|
// 0, // Max Longs
|
|
// 0, // Max Shorts
|
|
// X_SIGNALLING_BOTH_DIRECTIONS // X_SIGNALIING_TREND_REVERSAL_DIRECTION // X_SIGNALLING_BOTH_DIRECTIONS //
|
|
// );
|
|
// eurusdM5SRBRStrategy.SetAlertLogAlerts(true);
|
|
// eurusdM5SRBRStrategy.SetAlertEnableAlerts(true);
|
|
// RegisterStrategy(eurusdM5SRBRStrategy);
|
|
|
|
// //
|
|
// // Register XSRBR on EURUSD in M5 ...
|
|
// XSCXSRBRStrategy *eurusdM15SRBRStrategy;
|
|
// eurusdM15SRBRStrategy = new XSCXSRBRStrategy(
|
|
// eurusdSymbol,
|
|
// PERIOD_M15,
|
|
// PERIOD_M30,
|
|
// eaVolume,
|
|
// eaR2R, // R2R ...
|
|
// eaSlippage,
|
|
// magicNumber,
|
|
// true, // Use TP SL Point
|
|
// false, // Use Max
|
|
// eaTPPoint, // TP
|
|
// eaSLPoint, // SL
|
|
// eaAllowLong,
|
|
// eaAllowShort,
|
|
// eaMaxAllowedLongs, // Max Longs
|
|
// eaMaxAllowedShorts, // Max Shorts
|
|
// X_SIGNALLING_BOTH_DIRECTIONS // X_SIGNALIING_TREND_REVERSAL_DIRECTION // X_SIGNALLING_BOTH_DIRECTIONS //
|
|
// );
|
|
// eurusdM15SRBRStrategy.SetAlertLogAlerts(true);
|
|
// eurusdM15SRBRStrategy.SetAlertEnableAlerts(true);
|
|
// RegisterStrategy(eurusdM15SRBRStrategy);
|
|
// }
|
|
|
|
// //
|
|
// // XEMRNG ...
|
|
// if (useXEMRNG)
|
|
// {
|
|
// //
|
|
// XSCXEMRNGStrategy *eurusdM5EMRNGStrategy;
|
|
// eurusdM5EMRNGStrategy = new XSCXEMRNGStrategy(
|
|
// eurusdSymbol,
|
|
// PERIOD_M5,
|
|
// eaVolume,
|
|
// eaR2R, // R2R ...
|
|
// eaSlippage,
|
|
// magicNumber,
|
|
// true, // Use TP SL Point
|
|
// false, // Use Max
|
|
// eaTPPoint, // TP
|
|
// eaSLPoint, // SL
|
|
// eaAllowLong,
|
|
// eaAllowShort,
|
|
// eaMaxAllowedLongs, // Max Longs
|
|
// eaMaxAllowedShorts // Max Shorts
|
|
// );
|
|
// eurusdM5EMRNGStrategy.SetAlertLogAlerts(true);
|
|
// eurusdM5EMRNGStrategy.SetAlertEnableAlerts(true);
|
|
// RegisterStrategy(eurusdM5EMRNGStrategy);
|
|
// }
|
|
|
|
// //
|
|
// // XOBVG ...
|
|
// if (useXOBVG)
|
|
// {
|
|
// //
|
|
// XSCXOBVGStrategy *eurusdM5OBVGStrategy;
|
|
// eurusdM5OBVGStrategy = new XSCXOBVGStrategy(
|
|
// eurusdSymbol,
|
|
// PERIOD_M5,
|
|
// PERIOD_H2, // Analyzing Period
|
|
// eaVolume,
|
|
// eaR2R, // R2R ...
|
|
// eaSlippage,
|
|
// magicNumber,
|
|
// false, // Use TP SL Point
|
|
// false, // Use Max
|
|
// eaTPPoint, // TP
|
|
// eaSLPoint, // SL
|
|
// eaAllowLong,
|
|
// eaAllowShort,
|
|
// eaMaxAllowedLongs, // Max Longs
|
|
// eaMaxAllowedShorts // Max Shorts
|
|
// );
|
|
// eurusdM5OBVGStrategy.SetAlertLogAlerts(true);
|
|
// eurusdM5OBVGStrategy.SetAlertEnableAlerts(true);
|
|
// RegisterStrategy(eurusdM5OBVGStrategy);
|
|
// }
|
|
|
|
// //
|
|
// // XPVFMC ...
|
|
// if (useXPVFMC)
|
|
// {
|
|
// //
|
|
// XSCXPVFMCStrategy *eurusdM5PVFMCStrategy;
|
|
// eurusdM5PVFMCStrategy = new XSCXPVFMCStrategy(
|
|
// eurusdSymbol,
|
|
// PERIOD_M5,
|
|
// eaVolume,
|
|
// eaR2R, // R2R ...
|
|
// eaSlippage,
|
|
// magicNumber,
|
|
// false, // Use TP SL Point
|
|
// false, // Use Max
|
|
// eaTPPoint, // TP
|
|
// eaSLPoint, // SL
|
|
// eaAllowLong,
|
|
// eaAllowShort,
|
|
// eaMaxAllowedLongs, // Max Longs
|
|
// eaMaxAllowedShorts // Max Shorts
|
|
// );
|
|
// eurusdM5PVFMCStrategy.SetAlertLogAlerts(true);
|
|
// eurusdM5PVFMCStrategy.SetAlertEnableAlerts(true);
|
|
// RegisterStrategy(eurusdM5PVFMCStrategy);
|
|
// }
|
|
}
|
|
|
|
//
|
|
// USDCHF ...
|
|
string usdchfSymbol = "USDCHFb";
|
|
if (useUSDCHF && IsValid(usdchfSymbol))
|
|
{
|
|
//
|
|
// MAGIC NUMBER ...
|
|
long magicNumber = eaMagicNumber + 2;
|
|
|
|
// //
|
|
// // XSRBR ...
|
|
// if (useXSRBR)
|
|
// {
|
|
// //
|
|
// // Register XSRBR on EURUSD in M5 ...
|
|
// XSCXSRBRStrategy *usdchfM5SRBRStrategy;
|
|
// usdchfM5SRBRStrategy = new XSCXSRBRStrategy(
|
|
// usdchfSymbol,
|
|
// PERIOD_M5,
|
|
// PERIOD_H1,
|
|
// eaVolume,
|
|
// eaR2R, // R2R ...
|
|
// eaSlippage,
|
|
// magicNumber,
|
|
// true, // Use TP SL Point
|
|
// false, // Use Max
|
|
// eaTPPoint, // TP
|
|
// eaSLPoint, // SL
|
|
// eaAllowLong,
|
|
// eaAllowShort,
|
|
// eaMaxAllowedLongs, // Max Longs
|
|
// eaMaxAllowedShorts, // Max Shorts
|
|
// X_SIGNALLING_BOTH_DIRECTIONS // X_SIGNALIING_TREND_REVERSAL_DIRECTION // X_SIGNALLING_BOTH_DIRECTIONS //
|
|
// );
|
|
// usdchfM5SRBRStrategy.SetAlertLogAlerts(true);
|
|
// usdchfM5SRBRStrategy.SetAlertEnableAlerts(true);
|
|
// RegisterStrategy(usdchfM5SRBRStrategy);
|
|
// }
|
|
|
|
// //
|
|
// // XEMRNG ...
|
|
// if (useXEMRNG)
|
|
// {
|
|
// //
|
|
// XSCXEMRNGStrategy *usdchfM5EMRNGStrategy;
|
|
// usdchfM5EMRNGStrategy = new XSCXEMRNGStrategy(
|
|
// usdchfSymbol,
|
|
// PERIOD_M5,
|
|
// eaVolume,
|
|
// eaR2R, // R2R ...
|
|
// eaSlippage,
|
|
// magicNumber,
|
|
// true, // Use TP SL Point
|
|
// false, // Use Max
|
|
// eaTPPoint, // TP
|
|
// eaSLPoint, // SL
|
|
// eaAllowLong,
|
|
// eaAllowShort,
|
|
// eaMaxAllowedLongs, // Max Longs
|
|
// eaMaxAllowedShorts // Max Shorts
|
|
// );
|
|
// usdchfM5EMRNGStrategy.SetAlertLogAlerts(true);
|
|
// usdchfM5EMRNGStrategy.SetAlertEnableAlerts(true);
|
|
// RegisterStrategy(usdchfM5EMRNGStrategy);
|
|
// }
|
|
}
|
|
|
|
//
|
|
// USDJPY ...
|
|
string usdjpySymbol = "USDJPYb";
|
|
if (useUSDJPY && IsValid(usdjpySymbol))
|
|
{
|
|
//
|
|
// MAGIC NUMBER ...
|
|
long magicNumber = eaMagicNumber + 3;
|
|
|
|
// //
|
|
// // XSRBR ...
|
|
// if (useXSRBR)
|
|
// {
|
|
// //
|
|
// // Register XSRBR on EURUSD in M5 ...
|
|
// XSCXSRBRStrategy *usdjpyM5SRBRStrategy;
|
|
// usdjpyM5SRBRStrategy = new XSCXSRBRStrategy(
|
|
// usdjpySymbol,
|
|
// PERIOD_M5,
|
|
// PERIOD_M30,
|
|
// eaVolume,
|
|
// eaR2R, // R2R ...
|
|
// eaSlippage,
|
|
// magicNumber,
|
|
// true, // Use TP SL Point
|
|
// false, // Use Max
|
|
// eaTPPoint, // TP
|
|
// eaSLPoint, // SL
|
|
// eaAllowLong,
|
|
// eaAllowShort,
|
|
// eaMaxAllowedLongs, // Max Longs
|
|
// eaMaxAllowedShorts, // Max Shorts
|
|
// X_SIGNALLING_BOTH_DIRECTIONS // X_SIGNALIING_TREND_REVERSAL_DIRECTION // X_SIGNALLING_BOTH_DIRECTIONS //
|
|
// );
|
|
// usdjpyM5SRBRStrategy.SetAlertLogAlerts(true);
|
|
// usdjpyM5SRBRStrategy.SetAlertEnableAlerts(true);
|
|
// RegisterStrategy(usdjpyM5SRBRStrategy);
|
|
// }
|
|
|
|
// //
|
|
// // XEMRNG ...
|
|
// if (useXEMRNG)
|
|
// {
|
|
// //
|
|
// XSCXEMRNGStrategy *usdjpyM5EMRNGStrategy;
|
|
// usdjpyM5EMRNGStrategy = new XSCXEMRNGStrategy(
|
|
// usdjpySymbol,
|
|
// PERIOD_M5,
|
|
// eaVolume,
|
|
// eaR2R, // R2R ...
|
|
// eaSlippage,
|
|
// magicNumber,
|
|
// true, // Use TP SL Point
|
|
// false, // Use Max
|
|
// eaTPPoint, // TP
|
|
// eaSLPoint, // SL
|
|
// eaAllowLong,
|
|
// eaAllowShort,
|
|
// eaMaxAllowedLongs, // Max Longs
|
|
// eaMaxAllowedShorts // Max Shorts
|
|
// );
|
|
// usdjpyM5EMRNGStrategy.SetAlertLogAlerts(true);
|
|
// usdjpyM5EMRNGStrategy.SetAlertEnableAlerts(true);
|
|
// RegisterStrategy(usdjpyM5EMRNGStrategy);
|
|
// }
|
|
}
|
|
|
|
//
|
|
// GBPUSD ...
|
|
string gbpusdSymbol = "GBPUSDb";
|
|
if (useGBPUSD && IsValid(gbpusdSymbol))
|
|
{
|
|
//
|
|
// MAGIC NUMBER ...
|
|
long magicNumber = eaMagicNumber + 4;
|
|
|
|
// //
|
|
// // XSRBR ...
|
|
// if (useXSRBR)
|
|
// {
|
|
// //
|
|
// // Register XSRBR on EURUSD in M5 ...
|
|
// XSCXSRBRStrategy *gbpusdM5SRBRStrategy;
|
|
// gbpusdM5SRBRStrategy = new XSCXSRBRStrategy(
|
|
// gbpusdSymbol,
|
|
// PERIOD_M5,
|
|
// PERIOD_H1,
|
|
// eaVolume,
|
|
// eaR2R, // R2R ...
|
|
// eaSlippage,
|
|
// magicNumber,
|
|
// true, // Use TP SL Point
|
|
// false, // Use Max
|
|
// eaTPPoint, // TP
|
|
// eaSLPoint, // SL
|
|
// eaAllowLong,
|
|
// eaAllowShort,
|
|
// eaMaxAllowedLongs, // Max Longs
|
|
// eaMaxAllowedShorts, // Max Shorts
|
|
// X_SIGNALLING_BOTH_DIRECTIONS // X_SIGNALIING_TREND_REVERSAL_DIRECTION // X_SIGNALLING_BOTH_DIRECTIONS //
|
|
// );
|
|
// gbpusdM5SRBRStrategy.SetAlertLogAlerts(true);
|
|
// gbpusdM5SRBRStrategy.SetAlertEnableAlerts(true);
|
|
// RegisterStrategy(gbpusdM5SRBRStrategy);
|
|
// }
|
|
|
|
// //
|
|
// // XEMRNG ...
|
|
// if (useXEMRNG)
|
|
// {
|
|
// //
|
|
// XSCXEMRNGStrategy *gbpusdM5EMRNGStrategy;
|
|
// gbpusdM5EMRNGStrategy = new XSCXEMRNGStrategy(
|
|
// gbpusdSymbol,
|
|
// PERIOD_M5,
|
|
// eaVolume,
|
|
// eaR2R, // R2R ...
|
|
// eaSlippage,
|
|
// magicNumber,
|
|
// true, // Use TP SL Point
|
|
// false, // Use Max
|
|
// eaTPPoint, // TP
|
|
// eaSLPoint, // SL
|
|
// eaAllowLong,
|
|
// eaAllowShort,
|
|
// eaMaxAllowedLongs, // Max Longs
|
|
// eaMaxAllowedShorts // Max Shorts
|
|
// );
|
|
// gbpusdM5EMRNGStrategy.SetAlertLogAlerts(true);
|
|
// gbpusdM5EMRNGStrategy.SetAlertEnableAlerts(true);
|
|
// RegisterStrategy(gbpusdM5EMRNGStrategy);
|
|
// }
|
|
}
|
|
|
|
//
|
|
// XAUUSD ...
|
|
string xauusdSymbol = "XAUUSDb";
|
|
if (useXAUUSD && IsValid(xauusdSymbol))
|
|
{
|
|
//
|
|
// MAGIC NUMBER ...
|
|
long magicNumber = eaMagicNumber + 5;
|
|
|
|
// //
|
|
// // XSRBR ...
|
|
// if (useXSRBR)
|
|
// {
|
|
// //
|
|
// // Register XSRBR on EURUSD in M5 ...
|
|
// XSCXSRBRStrategy *xauusdM5SRBRStrategy;
|
|
// xauusdM5SRBRStrategy = new XSCXSRBRStrategy(
|
|
// xauusdSymbol,
|
|
// PERIOD_M15,
|
|
// PERIOD_M30,
|
|
// eaVolume,
|
|
// eaR2R, // R2R ...
|
|
// eaSlippage,
|
|
// magicNumber,
|
|
// true, // Use TP SL Point
|
|
// false, // Use Max
|
|
// eaTPPoint, // TP
|
|
// eaSLPoint, // SL
|
|
// eaAllowLong,
|
|
// eaAllowShort,
|
|
// eaMaxAllowedLongs, // Max Longs
|
|
// eaMaxAllowedShorts, // Max Shorts
|
|
// X_SIGNALLING_BOTH_DIRECTIONS // X_SIGNALIING_TREND_REVERSAL_DIRECTION // X_SIGNALLING_BOTH_DIRECTIONS //
|
|
// );
|
|
// xauusdM5SRBRStrategy.SetAlertLogAlerts(true);
|
|
// xauusdM5SRBRStrategy.SetAlertEnableAlerts(true);
|
|
// RegisterStrategy(xauusdM5SRBRStrategy);
|
|
// }
|
|
|
|
// //
|
|
// // XEMRNG ...
|
|
// if (useXEMRNG)
|
|
// {
|
|
// //
|
|
// XSCXEMRNGStrategy *xauusdM5EMRNGStrategy;
|
|
// xauusdM5EMRNGStrategy = new XSCXEMRNGStrategy(
|
|
// xauusdSymbol,
|
|
// PERIOD_M5,
|
|
// eaVolume,
|
|
// eaR2R, // R2R ...
|
|
// eaSlippage,
|
|
// magicNumber,
|
|
// true, // Use TP SL Point
|
|
// false, // Use Max
|
|
// eaTPPoint, // TP
|
|
// eaSLPoint, // SL
|
|
// eaAllowLong,
|
|
// eaAllowShort,
|
|
// eaMaxAllowedLongs, // Max Longs
|
|
// eaMaxAllowedShorts // Max Shorts
|
|
// );
|
|
// xauusdM5EMRNGStrategy.SetAlertLogAlerts(true);
|
|
// xauusdM5EMRNGStrategy.SetAlertEnableAlerts(true);
|
|
// RegisterStrategy(xauusdM5EMRNGStrategy);
|
|
// }
|
|
}
|
|
|
|
//
|
|
return result;
|
|
}
|
|
|
|
//
|
|
// Register Strategy ...
|
|
void RegisterStrategy(XSCBaseStrategy *strategy)
|
|
{
|
|
//
|
|
if (strategy == NULL)
|
|
{
|
|
return;
|
|
}
|
|
|
|
//
|
|
ArrayResize(
|
|
strategies,
|
|
ArraySize(strategies) + 1 //
|
|
);
|
|
|
|
//
|
|
strategies[ArraySize(strategies) - 1] = strategy;
|
|
}
|
|
|
|
//
|
|
// Call All Registered Strategis Tick Handler Functions ...
|
|
void HandleStrategiesOnTick()
|
|
{
|
|
//
|
|
int count = ArraySize(strategies);
|
|
if (!IsValidSize(count))
|
|
{
|
|
return;
|
|
}
|
|
|
|
//
|
|
for (int i = 0; i < count; i++)
|
|
{
|
|
//
|
|
// Call Tick Handler Function ...
|
|
strategies[i].HandleTick();
|
|
}
|
|
}
|
|
|
|
//
|
|
// Custom Testing Functions ...
|
|
|
|
//
|
|
|
|
/////////////////////////////////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
//
|
|
bool isCHHKCBullishBreaked =
|
|
//
|
|
(
|
|
//
|
|
chhkConditions.isCBearish &&
|
|
chhkConditions.isSBullish &&
|
|
chhkConditions.isMBullish &&
|
|
chhkConditions.isLBullish &&
|
|
chhkConditions.isHBullish
|
|
//
|
|
)
|
|
//
|
|
;
|
|
|
|
//
|
|
bool isCHHKSBullishBreaked =
|
|
//
|
|
(
|
|
//
|
|
chhkConditions.isSBearish &&
|
|
chhkConditions.isCBullish &&
|
|
chhkConditions.isMBullish &&
|
|
chhkConditions.isLBullish &&
|
|
chhkConditions.isHBullish
|
|
//
|
|
)
|
|
//
|
|
;
|
|
|
|
//
|
|
bool isCHHKMBullishBreaked =
|
|
//
|
|
(
|
|
//
|
|
chhkConditions.isMBearish &&
|
|
chhkConditions.isCBullish &&
|
|
chhkConditions.isSBullish &&
|
|
chhkConditions.isLBullish &&
|
|
chhkConditions.isHBullish
|
|
//
|
|
)
|
|
//
|
|
;
|
|
|
|
//
|
|
bool isCHHKLBullishBreaked =
|
|
//
|
|
(
|
|
//
|
|
chhkConditions.isLBearish &&
|
|
chhkConditions.isCBullish &&
|
|
chhkConditions.isSBullish &&
|
|
chhkConditions.isMBullish &&
|
|
chhkConditions.isHBullish
|
|
//
|
|
)
|
|
//
|
|
;
|
|
|
|
//
|
|
bool isCHHKHBullishBreaked =
|
|
//
|
|
(
|
|
//
|
|
chhkConditions.isHBearish &&
|
|
chhkConditions.isCBullish &&
|
|
chhkConditions.isSBullish &&
|
|
chhkConditions.isMBullish &&
|
|
chhkConditions.isLBullish
|
|
//
|
|
)
|
|
//
|
|
;
|
|
|
|
|
|
//
|
|
bool isCHHKBullishBreaked =
|
|
//
|
|
isCHHKCBullishBreaked
|
|
//
|
|
||
|
|
//
|
|
isCHHKSBullishBreaked
|
|
//
|
|
||
|
|
//
|
|
isCHHKMBullishBreaked
|
|
//
|
|
||
|
|
//
|
|
isCHHKLBullishBreaked
|
|
//
|
|
||
|
|
//
|
|
isCHHKHBullishBreaked
|
|
//
|
|
;
|
|
|
|
|
|
|
|
//
|
|
bool isCHHKCBearishBreaked =
|
|
//
|
|
(
|
|
//
|
|
chhkConditions.isCBullish &&
|
|
chhkConditions.isSBearish &&
|
|
chhkConditions.isMBearish &&
|
|
chhkConditions.isLBearish &&
|
|
chhkConditions.isHBearish
|
|
//
|
|
)
|
|
//
|
|
;
|
|
|
|
//
|
|
bool isCHHKSBearishBreaked =
|
|
//
|
|
(
|
|
//
|
|
chhkConditions.isSBullish &&
|
|
chhkConditions.isCBearish &&
|
|
chhkConditions.isMBearish &&
|
|
chhkConditions.isLBearish &&
|
|
chhkConditions.isHBearish
|
|
//
|
|
)
|
|
//
|
|
;
|
|
|
|
//
|
|
bool isCHHKMBearishBreaked =
|
|
//
|
|
(
|
|
//
|
|
chhkConditions.isMBullish &&
|
|
chhkConditions.isCBearish &&
|
|
chhkConditions.isSBearish &&
|
|
chhkConditions.isLBearish &&
|
|
chhkConditions.isHBearish
|
|
//
|
|
)
|
|
//
|
|
;
|
|
|
|
//
|
|
bool isCHHKLBearishBreaked =
|
|
//
|
|
(
|
|
//
|
|
chhkConditions.isLBullish &&
|
|
chhkConditions.isCBearish &&
|
|
chhkConditions.isSBearish &&
|
|
chhkConditions.isMBearish &&
|
|
chhkConditions.isHBearish
|
|
//
|
|
)
|
|
//
|
|
;
|
|
|
|
//
|
|
bool isCHHKHBearishBreaked =
|
|
//
|
|
(
|
|
//
|
|
chhkConditions.isHBullish &&
|
|
chhkConditions.isCBearish &&
|
|
chhkConditions.isSBearish &&
|
|
chhkConditions.isMBearish &&
|
|
chhkConditions.isLBearish
|
|
//
|
|
)
|
|
//
|
|
;
|
|
|
|
|
|
//
|
|
bool isCHHKBearishBreaked =
|
|
//
|
|
isCHHKCBearishBreaked
|
|
//
|
|
||
|
|
//
|
|
isCHHKSBearishBreaked
|
|
//
|
|
||
|
|
//
|
|
isCHHKMBearishBreaked
|
|
//
|
|
||
|
|
//
|
|
isCHHKLBearishBreaked
|
|
//
|
|
||
|
|
//
|
|
isCHHKHBearishBreaked
|
|
//
|
|
;
|
|
|
|
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
//
|
|
// XCHM ...
|
|
// Detect XCHMbased Conditions ...
|
|
|
|
//
|
|
// Bullish ...
|
|
|
|
//
|
|
bool isCHMHSwithedToBullish =
|
|
//
|
|
(
|
|
//
|
|
chmConditions.isHFastCrossedOverSlow &&
|
|
chmConditions.isLFastOverSlow &&
|
|
chmConditions.isMFastOverSlow &&
|
|
chmConditions.isSFastOverSlow &&
|
|
chmConditions.isCFastOverSlow
|
|
//
|
|
)
|
|
//
|
|
;
|
|
|
|
//
|
|
bool isCHMLSwithedToBullish =
|
|
//
|
|
(
|
|
//
|
|
chmConditions.isLFastCrossedOverSlow &&
|
|
chmConditions.isHFastOverSlow &&
|
|
chmConditions.isMFastOverSlow &&
|
|
chmConditions.isSFastOverSlow &&
|
|
chmConditions.isCFastOverSlow
|
|
//
|
|
)
|
|
//
|
|
;
|
|
|
|
//
|
|
bool isCHMMSwithedToBullish =
|
|
//
|
|
(
|
|
//
|
|
chmConditions.isMFastCrossedOverSlow &&
|
|
chmConditions.isHFastOverSlow &&
|
|
chmConditions.isLFastOverSlow &&
|
|
chmConditions.isSFastOverSlow &&
|
|
chmConditions.isCFastOverSlow
|
|
//
|
|
)
|
|
//
|
|
;
|
|
|
|
//
|
|
bool isCHMSSwithedToBullish =
|
|
//
|
|
(
|
|
//
|
|
chmConditions.isSFastCrossedOverSlow &&
|
|
chmConditions.isHFastOverSlow &&
|
|
chmConditions.isLFastOverSlow &&
|
|
chmConditions.isMFastOverSlow &&
|
|
chmConditions.isCFastOverSlow
|
|
//
|
|
)
|
|
//
|
|
;
|
|
|
|
//
|
|
bool isCHMCSwithedToBullish =
|
|
//
|
|
(
|
|
//
|
|
chmConditions.isCFastCrossedOverSlow &&
|
|
chmConditions.isHFastOverSlow &&
|
|
chmConditions.isLFastOverSlow &&
|
|
chmConditions.isMFastOverSlow &&
|
|
chmConditions.isSFastOverSlow
|
|
//
|
|
)
|
|
//
|
|
;
|
|
|
|
//
|
|
// Bullish Conclusion ...
|
|
|
|
//
|
|
bool isCHMBullish =
|
|
//
|
|
(
|
|
//
|
|
chmConditions.isHFastOverSlow &&
|
|
chmConditions.isLFastOverSlow &&
|
|
chmConditions.isMFastOverSlow &&
|
|
chmConditions.isSFastOverSlow &&
|
|
chmConditions.isCFastOverSlow
|
|
//
|
|
)
|
|
//
|
|
;
|
|
|
|
//
|
|
bool isCHMSwitchedToBullish =
|
|
//
|
|
isCHMHSwithedToBullish
|
|
//
|
|
||
|
|
//
|
|
isCHMLSwithedToBullish
|
|
//
|
|
||
|
|
//
|
|
isCHMMSwithedToBullish
|
|
//
|
|
||
|
|
//
|
|
isCHMSSwithedToBullish
|
|
//
|
|
||
|
|
//
|
|
isCHMCSwithedToBullish
|
|
//
|
|
;
|
|
|
|
//
|
|
// Bearish ...
|
|
|
|
//
|
|
bool isCHMCHSwitchedToBearish =
|
|
//
|
|
(
|
|
//
|
|
chmConditions.isHFastCrossedUnderSlow &&
|
|
chmConditions.isLFastUnderSlow &&
|
|
chmConditions.isMFastUnderSlow &&
|
|
chmConditions.isSFastUnderSlow &&
|
|
chmConditions.isCFastUnderSlow
|
|
//
|
|
)
|
|
//
|
|
;
|
|
|
|
//
|
|
bool isCHMCLSwitchedToBearish =
|
|
//
|
|
(
|
|
//
|
|
chmConditions.isLFastCrossedUnderSlow &&
|
|
chmConditions.isHFastUnderSlow &&
|
|
chmConditions.isMFastUnderSlow &&
|
|
chmConditions.isSFastUnderSlow &&
|
|
chmConditions.isCFastUnderSlow
|
|
//
|
|
)
|
|
//
|
|
;
|
|
|
|
//
|
|
bool isCHMCMSwitchedToBearish =
|
|
//
|
|
(
|
|
//
|
|
chmConditions.isMFastCrossedUnderSlow &&
|
|
chmConditions.isHFastUnderSlow &&
|
|
chmConditions.isLFastUnderSlow &&
|
|
chmConditions.isSFastUnderSlow &&
|
|
chmConditions.isCFastUnderSlow
|
|
//
|
|
)
|
|
//
|
|
;
|
|
|
|
//
|
|
bool isCHMCSSwitchedToBearish =
|
|
//
|
|
(
|
|
//
|
|
chmConditions.isSFastCrossedUnderSlow &&
|
|
chmConditions.isHFastUnderSlow &&
|
|
chmConditions.isLFastUnderSlow &&
|
|
chmConditions.isMFastUnderSlow &&
|
|
chmConditions.isCFastUnderSlow
|
|
//
|
|
)
|
|
//
|
|
;
|
|
|
|
//
|
|
bool isCHMCCSwitchedToBearish =
|
|
//
|
|
(
|
|
//
|
|
chmConditions.isCFastCrossedUnderSlow &&
|
|
chmConditions.isHFastUnderSlow &&
|
|
chmConditions.isLFastUnderSlow &&
|
|
chmConditions.isMFastUnderSlow &&
|
|
chmConditions.isSFastUnderSlow
|
|
//
|
|
)
|
|
//
|
|
;
|
|
|
|
//
|
|
// Bearish Conclusion ...
|
|
|
|
//
|
|
bool isCHMBearish =
|
|
//
|
|
(
|
|
//
|
|
chmConditions.isHFastUnderSlow &&
|
|
chmConditions.isLFastUnderSlow &&
|
|
chmConditions.isMFastUnderSlow &&
|
|
chmConditions.isSFastUnderSlow &&
|
|
chmConditions.isCFastUnderSlow
|
|
//
|
|
)
|
|
//
|
|
;
|
|
|
|
//
|
|
bool isCHMSwitchedToBearish =
|
|
//
|
|
isCHMCHSwitchedToBearish
|
|
//
|
|
||
|
|
//
|
|
isCHMCLSwitchedToBearish
|
|
//
|
|
||
|
|
//
|
|
isCHMCMSwitchedToBearish
|
|
//
|
|
||
|
|
//
|
|
isCHMCSSwitchedToBearish
|
|
//
|
|
||
|
|
//
|
|
isCHMCCSwitchedToBearish
|
|
//
|
|
;
|
|
|
|
// //
|
|
// // Max ...
|
|
// double chmMax = MathMax(
|
|
// chmConditions.cFast[cIndex],
|
|
// chmConditions.cSlow[cIndex] //
|
|
// );
|
|
// chmMax = MathMax(
|
|
// chmMax,
|
|
// chmConditions.sFast[cIndex] //
|
|
// );
|
|
// chmMax = MathMax(
|
|
// chmMax,
|
|
// chmConditions.sSlow[cIndex] //
|
|
// );
|
|
// chmMax = MathMax(
|
|
// chmMax,
|
|
// chmConditions.mFast[cIndex] //
|
|
// );
|
|
// chmMax = MathMax(
|
|
// chmMax,
|
|
// chmConditions.mSlow[cIndex] //
|
|
// );
|
|
// chmMax = MathMax(
|
|
// chmMax,
|
|
// chmConditions.lFast[cIndex] //
|
|
// );
|
|
// chmMax = MathMax(
|
|
// chmMax,
|
|
// chmConditions.lSlow[cIndex] //
|
|
// );
|
|
// chmMax = MathMax(
|
|
// chmMax,
|
|
// chmConditions.hFast[cIndex] //
|
|
// );
|
|
// chmMax = MathMax(
|
|
// chmMax,
|
|
// chmConditions.hSlow[cIndex] //
|
|
// );
|
|
|
|
// //
|
|
// // Min ...
|
|
// double chmMin = MathMin(
|
|
// chmConditions.cFast[cIndex],
|
|
// chmConditions.cSlow[cIndex] //
|
|
// );
|
|
// chmMin = MathMin(
|
|
// chmMin,
|
|
// chmConditions.sFast[cIndex] //
|
|
// );
|
|
// chmMin = MathMin(
|
|
// chmMin,
|
|
// chmConditions.sSlow[cIndex] //
|
|
// );
|
|
// chmMin = MathMin(
|
|
// chmMin,
|
|
// chmConditions.mFast[cIndex] //
|
|
// );
|
|
// chmMin = MathMin(
|
|
// chmMin,
|
|
// chmConditions.mSlow[cIndex] //
|
|
// );
|
|
// chmMin = MathMin(
|
|
// chmMin,
|
|
// chmConditions.lFast[cIndex] //
|
|
// );
|
|
// chmMin = MathMin(
|
|
// chmMin,
|
|
// chmConditions.lSlow[cIndex] //
|
|
// );
|
|
// chmMin = MathMin(
|
|
// chmMin,
|
|
// chmConditions.hFast[cIndex] //
|
|
// );
|
|
// chmMin = MathMin(
|
|
// chmMin,
|
|
// chmConditions.hSlow[cIndex] //
|
|
// );
|
|
|
|
//
|
|
double chmDistanceDiffInPoint =
|
|
//
|
|
(chmMax - chmMin) / points
|
|
//
|
|
;
|
|
|
|
//
|
|
// XCHHK ...
|
|
// Detect XCHHK Conditions ...
|
|
|
|
//
|
|
// Bullish ...
|
|
|
|
//
|
|
bool isCHHKCSwitchedToBullish =
|
|
//
|
|
(
|
|
//
|
|
chhkConditions.isCSwitchedToBullish &&
|
|
chhkConditions.isSBullish &&
|
|
chhkConditions.isMBullish &&
|
|
chhkConditions.isLBullish &&
|
|
chhkConditions.isHBullish
|
|
//
|
|
)
|
|
//
|
|
;
|
|
|
|
//
|
|
bool isCHHKSSwitchedToBullish =
|
|
//
|
|
(
|
|
//
|
|
chhkConditions.isSSwitchedToBullish &&
|
|
chhkConditions.isCBullish &&
|
|
chhkConditions.isMBullish &&
|
|
chhkConditions.isLBullish &&
|
|
chhkConditions.isHBullish
|
|
//
|
|
)
|
|
//
|
|
;
|
|
|
|
//
|
|
bool isCHHKMSwitchedToBullish =
|
|
//
|
|
(
|
|
//
|
|
chhkConditions.isMSwitchedToBullish &&
|
|
chhkConditions.isCBullish &&
|
|
chhkConditions.isSBullish &&
|
|
chhkConditions.isLBullish &&
|
|
chhkConditions.isHBullish
|
|
//
|
|
)
|
|
//
|
|
;
|
|
|
|
//
|
|
bool isCHHKLSwitchedToBullish =
|
|
//
|
|
(
|
|
//
|
|
chhkConditions.isLSwitchedToBullish &&
|
|
chhkConditions.isCBullish &&
|
|
chhkConditions.isSBullish &&
|
|
chhkConditions.isMBullish &&
|
|
chhkConditions.isHBullish
|
|
//
|
|
)
|
|
//
|
|
;
|
|
|
|
//
|
|
bool isCHHKHSwitchedToBullish =
|
|
//
|
|
(
|
|
//
|
|
chhkConditions.isHSwitchedToBullish &&
|
|
chhkConditions.isCBullish &&
|
|
chhkConditions.isSBullish &&
|
|
chhkConditions.isMBullish &&
|
|
chhkConditions.isLBullish
|
|
//
|
|
)
|
|
//
|
|
;
|
|
|
|
//
|
|
// Bullish Conclusion ...
|
|
|
|
//
|
|
bool isCHHKBullish =
|
|
//
|
|
(
|
|
//
|
|
chhkConditions.isHBullish &&
|
|
chhkConditions.isCBullish &&
|
|
chhkConditions.isSBullish &&
|
|
chhkConditions.isMBullish &&
|
|
chhkConditions.isLBullish
|
|
//
|
|
)
|
|
//
|
|
;
|
|
|
|
//
|
|
bool isCHHKSwitchedBullish =
|
|
//
|
|
isCHHKCSwitchedToBullish
|
|
//
|
|
||
|
|
//
|
|
isCHHKSSwitchedToBullish
|
|
//
|
|
||
|
|
//
|
|
isCHHKMSwitchedToBullish
|
|
//
|
|
||
|
|
//
|
|
isCHHKLSwitchedToBullish
|
|
//
|
|
||
|
|
//
|
|
isCHHKHSwitchedToBullish
|
|
//
|
|
;
|
|
|
|
//
|
|
// Bearish ...
|
|
|
|
//
|
|
bool isCHHKCSwitchedToBearish =
|
|
//
|
|
(
|
|
//
|
|
chhkConditions.isCSwitchedToBearish &&
|
|
chhkConditions.isSBearish &&
|
|
chhkConditions.isMBearish &&
|
|
chhkConditions.isLBearish &&
|
|
chhkConditions.isHBearish
|
|
//
|
|
)
|
|
//
|
|
;
|
|
|
|
//
|
|
bool isCHHKSSwitchedToBearish =
|
|
//
|
|
(
|
|
//
|
|
chhkConditions.isSSwitchedToBearish &&
|
|
chhkConditions.isCBearish &&
|
|
chhkConditions.isMBearish &&
|
|
chhkConditions.isLBearish &&
|
|
chhkConditions.isHBearish
|
|
//
|
|
)
|
|
//
|
|
;
|
|
|
|
//
|
|
bool isCHHKMSwitchedToBearish =
|
|
//
|
|
(
|
|
//
|
|
chhkConditions.isMSwitchedToBearish &&
|
|
chhkConditions.isCBearish &&
|
|
chhkConditions.isSBearish &&
|
|
chhkConditions.isLBearish &&
|
|
chhkConditions.isHBearish
|
|
//
|
|
)
|
|
//
|
|
;
|
|
|
|
//
|
|
bool isCHHKLSwitchedToBearish =
|
|
//
|
|
(
|
|
//
|
|
chhkConditions.isLSwitchedToBearish &&
|
|
chhkConditions.isCBearish &&
|
|
chhkConditions.isSBearish &&
|
|
chhkConditions.isMBearish &&
|
|
chhkConditions.isHBearish
|
|
//
|
|
)
|
|
//
|
|
;
|
|
|
|
//
|
|
bool isCHHKHSwitchedToBearish =
|
|
//
|
|
(
|
|
//
|
|
chhkConditions.isHSwitchedToBearish &&
|
|
chhkConditions.isCBearish &&
|
|
chhkConditions.isSBearish &&
|
|
chhkConditions.isMBearish &&
|
|
chhkConditions.isLBearish
|
|
//
|
|
)
|
|
//
|
|
;
|
|
|
|
//
|
|
// Bearish Conclusion ...
|
|
|
|
//
|
|
bool isCHHKBearish =
|
|
//
|
|
(
|
|
//
|
|
chhkConditions.isHBearish &&
|
|
chhkConditions.isCBearish &&
|
|
chhkConditions.isSBearish &&
|
|
chhkConditions.isMBearish &&
|
|
chhkConditions.isLBearish
|
|
//
|
|
)
|
|
//
|
|
;
|
|
|
|
//
|
|
bool isCHHKSwitchedToBearish =
|
|
//
|
|
isCHHKCSwitchedToBearish
|
|
//
|
|
||
|
|
//
|
|
isCHHKSSwitchedToBearish
|
|
//
|
|
||
|
|
//
|
|
isCHHKMSwitchedToBearish
|
|
//
|
|
||
|
|
//
|
|
isCHHKLSwitchedToBearish
|
|
//
|
|
||
|
|
//
|
|
isCHHKHSwitchedToBearish
|
|
//
|
|
;
|
|
|
|
// //
|
|
// // Max High ...
|
|
// double chhkHighMax = MathMax(
|
|
// chhkConditions.cBars[cIndex].high,
|
|
// chhkConditions.sBars[cIndex].high //
|
|
// );
|
|
// chhkHighMax = MathMax(
|
|
// chhkHighMax,
|
|
// chhkConditions.mBars[cIndex].high //
|
|
// );
|
|
// chhkHighMax = MathMax(
|
|
// chhkHighMax,
|
|
// chhkConditions.lBars[cIndex].high //
|
|
// );
|
|
// chhkHighMax = MathMax(
|
|
// chhkHighMax,
|
|
// chhkConditions.hBars[cIndex].high //
|
|
// );
|
|
|
|
// //
|
|
// // Min High ...
|
|
// double chhkHighMin = MathMin(
|
|
// chhkConditions.cBars[cIndex].high,
|
|
// chhkConditions.sBars[cIndex].high //
|
|
// );
|
|
// chhkHighMin = MathMin(
|
|
// chhkHighMin,
|
|
// chhkConditions.mBars[cIndex].high //
|
|
// );
|
|
// chhkHighMin = MathMin(
|
|
// chhkHighMin,
|
|
// chhkConditions.lBars[cIndex].high //
|
|
// );
|
|
// chhkHighMin = MathMin(
|
|
// chhkHighMin,
|
|
// chhkConditions.hBars[cIndex].high //
|
|
// );
|
|
|
|
// //
|
|
// // Max Low ...
|
|
// double chhkLowMax = MathMax(
|
|
// chhkConditions.cBars[cIndex].low,
|
|
// chhkConditions.sBars[cIndex].low //
|
|
// );
|
|
// chhkLowMax = MathMax(
|
|
// chhkLowMax,
|
|
// chhkConditions.mBars[cIndex].low //
|
|
// );
|
|
// chhkLowMax = MathMax(
|
|
// chhkLowMax,
|
|
// chhkConditions.lBars[cIndex].low //
|
|
// );
|
|
// chhkLowMax = MathMax(
|
|
// chhkLowMax,
|
|
// chhkConditions.hBars[cIndex].low //
|
|
// );
|
|
|
|
// //
|
|
// // Min Low ...
|
|
// double chhkLowMin = MathMin(
|
|
// chhkConditions.cBars[cIndex].low,
|
|
// chhkConditions.sBars[cIndex].low //
|
|
// );
|
|
// chhkLowMin = MathMin(
|
|
// chhkLowMin,
|
|
// chhkConditions.mBars[cIndex].low //
|
|
// );
|
|
// chhkLowMin = MathMin(
|
|
// chhkLowMin,
|
|
// chhkConditions.lBars[cIndex].low //
|
|
// );
|
|
// chhkLowMin = MathMin(
|
|
// chhkLowMin,
|
|
// chhkConditions.hBars[cIndex].low //
|
|
// );
|
|
|
|
//
|
|
double chhkDistanceDiffInPoint =
|
|
//
|
|
(chhkHighMax - chhkLowMin) / points
|
|
//
|
|
;
|
|
|
|
//
|
|
// XCHSTR ...
|
|
// Detect XCHSTR Conditions ...
|
|
|
|
//
|
|
// Bullish ...
|
|
|
|
//
|
|
bool isCHSTRHSwitchedToBullish =
|
|
//
|
|
(
|
|
//
|
|
chstrConditions.isHSwitchedToBullish &&
|
|
chstrConditions.isLBullish &&
|
|
chstrConditions.isMBullish &&
|
|
chstrConditions.isSBullish &&
|
|
chstrConditions.isCBullish
|
|
//
|
|
)
|
|
//
|
|
;
|
|
|
|
//
|
|
bool isCHSTRLSwitchedToBullish =
|
|
//
|
|
(
|
|
//
|
|
chstrConditions.isLSwitchedToBullish &&
|
|
chstrConditions.isHBullish &&
|
|
chstrConditions.isMBullish &&
|
|
chstrConditions.isSBullish &&
|
|
chstrConditions.isCBullish
|
|
//
|
|
)
|
|
//
|
|
;
|
|
|
|
//
|
|
bool isCHSTRMSwitchedToBullish =
|
|
//
|
|
(
|
|
//
|
|
chstrConditions.isMSwitchedToBullish &&
|
|
chstrConditions.isHBullish &&
|
|
chstrConditions.isLBullish &&
|
|
chstrConditions.isSBullish &&
|
|
chstrConditions.isCBullish
|
|
//
|
|
)
|
|
//
|
|
;
|
|
|
|
//
|
|
bool isCHSTRSSwitchedToBullish =
|
|
//
|
|
(
|
|
//
|
|
chstrConditions.isSSwitchedToBullish &&
|
|
chstrConditions.isHBullish &&
|
|
chstrConditions.isLBullish &&
|
|
chstrConditions.isMBullish &&
|
|
chstrConditions.isCBullish
|
|
//
|
|
)
|
|
//
|
|
;
|
|
|
|
//
|
|
bool isCHSTRCSwitchedToBullish =
|
|
//
|
|
(
|
|
//
|
|
chstrConditions.isCSwitchedToBullish &&
|
|
chstrConditions.isHBullish &&
|
|
chstrConditions.isLBullish &&
|
|
chstrConditions.isMBullish &&
|
|
chstrConditions.isSBullish
|
|
//
|
|
)
|
|
//
|
|
;
|
|
|
|
//
|
|
// Bullish Conclusion ...
|
|
|
|
//
|
|
bool isCHSTRBullish =
|
|
//
|
|
(
|
|
//
|
|
chstrConditions.isCBullish &&
|
|
chstrConditions.isHBullish &&
|
|
chstrConditions.isLBullish &&
|
|
chstrConditions.isMBullish &&
|
|
chstrConditions.isSBullish
|
|
//
|
|
)
|
|
//
|
|
;
|
|
|
|
//
|
|
bool isCHMSTRBullish =
|
|
//
|
|
isCHSTRHSwitchedToBullish
|
|
//
|
|
||
|
|
//
|
|
isCHSTRLSwitchedToBullish
|
|
//
|
|
||
|
|
//
|
|
isCHSTRMSwitchedToBullish
|
|
//
|
|
||
|
|
//
|
|
isCHSTRSSwitchedToBullish
|
|
//
|
|
||
|
|
//
|
|
isCHSTRCSwitchedToBullish
|
|
//
|
|
;
|
|
|
|
//
|
|
// Bearish ...
|
|
|
|
//
|
|
bool isCHSTRHSwitchedToBearish =
|
|
//
|
|
(
|
|
//
|
|
chstrConditions.isHSwitchedToBearish &&
|
|
chstrConditions.isLBearish &&
|
|
chstrConditions.isMBearish &&
|
|
chstrConditions.isSBearish &&
|
|
chstrConditions.isCBearish
|
|
//
|
|
)
|
|
//
|
|
;
|
|
|
|
//
|
|
bool isCHSTRLSwitchedToBearish =
|
|
//
|
|
(
|
|
//
|
|
chstrConditions.isLSwitchedToBearish &&
|
|
chstrConditions.isHBearish &&
|
|
chstrConditions.isMBearish &&
|
|
chstrConditions.isSBearish &&
|
|
chstrConditions.isCBearish
|
|
//
|
|
)
|
|
//
|
|
;
|
|
|
|
//
|
|
bool isCHSTRMSwitchedToBearish =
|
|
//
|
|
(
|
|
//
|
|
chstrConditions.isMSwitchedToBearish &&
|
|
chstrConditions.isHBearish &&
|
|
chstrConditions.isLBearish &&
|
|
chstrConditions.isSBearish &&
|
|
chstrConditions.isCBearish
|
|
//
|
|
)
|
|
//
|
|
;
|
|
|
|
//
|
|
bool isCHSTRSSwitchedToBearish =
|
|
//
|
|
(
|
|
//
|
|
chstrConditions.isSSwitchedToBearish &&
|
|
chstrConditions.isHBearish &&
|
|
chstrConditions.isLBearish &&
|
|
chstrConditions.isMBearish &&
|
|
chstrConditions.isCBearish
|
|
//
|
|
)
|
|
//
|
|
;
|
|
|
|
//
|
|
bool isCHSTRCSwitchedToBearish =
|
|
//
|
|
(
|
|
//
|
|
chstrConditions.isCSwitchedToBearish &&
|
|
chstrConditions.isHBearish &&
|
|
chstrConditions.isLBearish &&
|
|
chstrConditions.isMBearish &&
|
|
chstrConditions.isSBearish
|
|
//
|
|
)
|
|
//
|
|
;
|
|
|
|
//
|
|
// Bearish Conclusion ...
|
|
|
|
//
|
|
bool isCHSTRBearish =
|
|
//
|
|
(
|
|
//
|
|
chstrConditions.isCBearish &&
|
|
chstrConditions.isHBearish &&
|
|
chstrConditions.isLBearish &&
|
|
chstrConditions.isMBearish &&
|
|
chstrConditions.isSBearish
|
|
//
|
|
)
|
|
//
|
|
;
|
|
|
|
//
|
|
bool isCHSTRSwitchedToBearish =
|
|
//
|
|
isCHSTRHSwitchedToBearish
|
|
//
|
|
||
|
|
//
|
|
isCHSTRLSwitchedToBearish
|
|
//
|
|
||
|
|
//
|
|
isCHSTRMSwitchedToBearish
|
|
//
|
|
||
|
|
//
|
|
isCHSTRSSwitchedToBearish
|
|
//
|
|
||
|
|
//
|
|
isCHSTRCSwitchedToBearish
|
|
//
|
|
;
|
|
|
|
// //
|
|
// // Max ...
|
|
// double chstrMax = MathMax(
|
|
// chstrConditions.cTrend[cIndex],
|
|
// chstrConditions.sTrend[cIndex] //
|
|
// );
|
|
// chstrMax = MathMax(
|
|
// chstrMax,
|
|
// chstrConditions.mTrend[cIndex] //
|
|
// );
|
|
// chstrMax = MathMax(
|
|
// chstrMax,
|
|
// chstrConditions.lTrend[cIndex] //
|
|
// );
|
|
// chstrMax = MathMax(
|
|
// chstrMax,
|
|
// chstrConditions.hTrend[cIndex] //
|
|
// );
|
|
|
|
// //
|
|
// // Min ...
|
|
// double chstrMin = MathMin(
|
|
// chstrConditions.cTrend[cIndex],
|
|
// chstrConditions.sTrend[cIndex] //
|
|
// );
|
|
// chstrMin = MathMin(
|
|
// chstrMin,
|
|
// chstrConditions.mTrend[cIndex] //
|
|
// );
|
|
// chstrMin = MathMin(
|
|
// chstrMin,
|
|
// chstrConditions.lTrend[cIndex] //
|
|
// );
|
|
// chstrMin = MathMin(
|
|
// chstrMin,
|
|
// chstrConditions.hTrend[cIndex] //
|
|
// );
|
|
|
|
//
|
|
double chstrDistanceDiffInPoint =
|
|
//
|
|
(chstrMax - chstrMin) / points
|
|
//
|
|
;
|
|
|
|
//
|
|
// Other Conditions ...
|
|
|
|
//
|
|
bool isPriceOveralBullish =
|
|
//
|
|
cBar.low > chhkConditions.hBars[cIndex].high
|
|
//
|
|
;
|
|
|
|
//
|
|
bool isPriceOveralBullishPrev =
|
|
//
|
|
pBar.low > chhkConditions.hBars[pIndex].high
|
|
//
|
|
;
|
|
|
|
//
|
|
bool isPriceOveralSwitchedToBullish =
|
|
//
|
|
isPriceOveralBullish &&
|
|
!isPriceOveralBullishPrev
|
|
//
|
|
;
|
|
|
|
//
|
|
bool isPriceOveralBearish =
|
|
//
|
|
cBar.high < chhkConditions.hBars[cIndex].low
|
|
//
|
|
;
|
|
|
|
//
|
|
bool isPriceOveralBearishPrev =
|
|
//
|
|
pBar.high < chhkConditions.hBars[pIndex].low
|
|
//
|
|
;
|
|
|
|
//
|
|
bool isPriceOveralSwitchedToBearish =
|
|
//
|
|
isPriceOveralBearish &&
|
|
!isPriceOveralBearishPrev
|
|
//
|
|
;
|
|
|
|
//
|
|
// Signalling ...
|
|
// Looking for Signals Based on Conditions ...
|
|
|
|
// //
|
|
// // Checking Long Conditions ...
|
|
// if (isPriceOveralSwitchedToBullish)
|
|
// {
|
|
// //
|
|
// hasLong =
|
|
// //
|
|
// hasBullishPower &&
|
|
// cBar.IsBullish() &&
|
|
// hasBullishPressure &&
|
|
// chhkConditions.isHBullish &&
|
|
// chstrConditions.isHBullish &&
|
|
// cheConditions.isStrongBullish &&
|
|
// cBar.low > pvConditions.fib2s[cIndex]
|
|
// //
|
|
// ;
|
|
|
|
// //
|
|
// if (hasLong)
|
|
// {
|
|
// //
|
|
// type = POSITION_TYPE_BUY;
|
|
// sl = pvConditions.fib2s[cIndex];
|
|
// }
|
|
// }
|
|
|
|
// //
|
|
// // Checking Short Conditions ...
|
|
// if (isPriceOveralSwitchedToBearish)
|
|
// {
|
|
// //
|
|
// hasShort =
|
|
// //
|
|
// hasBearishPower &&
|
|
// cBar.IsBearish() &&
|
|
// hasBearishPressure &&
|
|
// chhkConditions.isHBearish &&
|
|
// chstrConditions.isHBearish &&
|
|
// cheConditions.isStrongBearish &&
|
|
// cBar.high < pvConditions.fib4s[cIndex]
|
|
// //
|
|
// ;
|
|
|
|
// //
|
|
// if (hasShort)
|
|
// {
|
|
// //
|
|
// type = POSITION_TYPE_SELL;
|
|
// sl = pvConditions.fib4s[cIndex];
|
|
// }
|
|
// }
|