298 lines
5.9 KiB
Plaintext
298 lines
5.9 KiB
Plaintext
|
|
//
|
|
// Find a Support or Resistance Zone ...
|
|
|
|
// //
|
|
// // Support Zone ...
|
|
// bool hasSupportZone = conditions.HasSupportZone();
|
|
// if (isLowEqualsToVale && !hasSupportZone)
|
|
// {
|
|
// //
|
|
// int count = state.CountSupportZones();
|
|
// if (IsValidSize(count))
|
|
// {
|
|
// //
|
|
// for (int i = count - 1; i >= 0; i--)
|
|
// {
|
|
// //
|
|
// XCSupportZone *iZone = state.supportZones[i];
|
|
|
|
// //
|
|
// bool isValid =
|
|
// vale >= iZone.Lower() &&
|
|
// vale <= iZone.Upper();
|
|
// if (isValid)
|
|
// {
|
|
// //
|
|
// conditions.supportZone = iZone;
|
|
// break;
|
|
// }
|
|
// }
|
|
|
|
// //
|
|
// hasSupportZone = conditions.HasSupportZone();
|
|
// }
|
|
// }
|
|
|
|
// //
|
|
// // Resistance Zone ...
|
|
// bool hasResistanceZone = conditions.HasResistanceZone();
|
|
// if (isHighEqualsToPeak && !hasResistanceZone)
|
|
// {
|
|
// //
|
|
// int count = state.CountResistanceZones();
|
|
// if (IsValidSize(count))
|
|
// {
|
|
// //
|
|
// for (int i = count - 1; i >= 0; i--)
|
|
// {
|
|
// //
|
|
// XCResistanceZone *iZone = state.resistanceZones[i];
|
|
|
|
// //
|
|
// bool isValid =
|
|
// peak >= iZone.Lower() &&
|
|
// peak <= iZone.Upper();
|
|
// if (isValid)
|
|
// {
|
|
// //
|
|
// conditions.resistanceZone = iZone;
|
|
// break;
|
|
// }
|
|
// }
|
|
|
|
// //
|
|
// hasResistanceZone = conditions.HasResistanceZone();
|
|
// }
|
|
// }
|
|
|
|
// //
|
|
// isBullish =
|
|
// isLowEqualsToVale &&
|
|
// hasSupportZone;
|
|
|
|
// //
|
|
// isBearish =
|
|
// isHighEqualsToPeak &&
|
|
// hasResistanceZone;
|
|
|
|
// //
|
|
// result = isBullish ||
|
|
// isBearish;
|
|
// if (!result)
|
|
// {
|
|
// return result;
|
|
// }
|
|
|
|
// //
|
|
// // Retrieve Active Zone ...
|
|
// XCBarZone *activeZone;
|
|
// result = conditions.HasActiveZone(activeZone);
|
|
// if (!result)
|
|
// {
|
|
// return result;
|
|
// }
|
|
|
|
// //
|
|
// // Draw ...
|
|
// if (hasSupportZone)
|
|
// {
|
|
// //
|
|
// XCSupportZoneObject *iObj;
|
|
// bool isCreated = drawer.CreateSupportZone(
|
|
// conditions.supportZone,
|
|
// iObj //
|
|
// );
|
|
// }
|
|
|
|
// //
|
|
// if (hasResistanceZone)
|
|
// {
|
|
// //
|
|
// XCResistanceZoneObject *iObj;
|
|
// bool isCreated = drawer.CreateResistanceZone(
|
|
// conditions.resistanceZone,
|
|
// iObj //
|
|
// );
|
|
// }
|
|
|
|
//
|
|
XCSupportZone *supportZone;
|
|
XCResistanceZone *resistanceZone;
|
|
datetime activeZoneFoundedAt;
|
|
|
|
//
|
|
supportZone = NULL;
|
|
resistanceZone = NULL;
|
|
activeZoneFoundedAt = NULL;
|
|
|
|
bool HasSupportZone()
|
|
{
|
|
//
|
|
bool result = false;
|
|
|
|
//
|
|
result =
|
|
supportZone != NULL &&
|
|
supportZone.IsValid();
|
|
|
|
//
|
|
return result;
|
|
}
|
|
|
|
bool HasResistanceZone()
|
|
{
|
|
//
|
|
bool result = false;
|
|
|
|
//
|
|
result =
|
|
resistanceZone != NULL &&
|
|
resistanceZone.IsValid();
|
|
|
|
//
|
|
return result;
|
|
}
|
|
|
|
bool HasActiveZone(XCBarZone *&zone)
|
|
{
|
|
//
|
|
bool result = false;
|
|
|
|
//
|
|
zone = NULL;
|
|
|
|
//
|
|
bool hasSupportZone = HasSupportZone();
|
|
bool hasResistanceZone = HasResistanceZone();
|
|
|
|
//
|
|
result = hasSupportZone ||
|
|
hasResistanceZone;
|
|
if (!result)
|
|
{
|
|
return result;
|
|
}
|
|
|
|
//
|
|
if (hasSupportZone)
|
|
{
|
|
//
|
|
supportZone.To(TimeCurrent());
|
|
zone = supportZone;
|
|
}
|
|
|
|
//
|
|
if (hasResistanceZone)
|
|
{
|
|
//
|
|
resistanceZone.To(TimeCurrent());
|
|
zone = resistanceZone;
|
|
}
|
|
|
|
//
|
|
return result;
|
|
}
|
|
|
|
|
|
////////////////////////////////////////////////////////////////////////////
|
|
|
|
/**
|
|
* Detect Cycle Trend Based On Pivots ...
|
|
*
|
|
* @param dir: ENUM_X_DIRECTION member Reference ...
|
|
* @param numberOfPivots: Integer ...
|
|
*
|
|
* @return ( bool )
|
|
*/
|
|
bool DetectTrend(
|
|
ENUM_X_DIRECTION &dir,
|
|
int numberOfPivots = 3 //
|
|
)
|
|
{
|
|
//
|
|
bool result = false;
|
|
|
|
//
|
|
dir = X_DIRECTION_NONE;
|
|
|
|
//
|
|
if (numberOfPivots < 2)
|
|
{
|
|
numberOfPivots = 2;
|
|
}
|
|
|
|
//
|
|
int verifications = 0;
|
|
XValueChange changes[];
|
|
|
|
//
|
|
// Bearish Trend ...
|
|
int peaksChangesCount = CountPeaksChanges();
|
|
if (!result &&
|
|
peaksChangesCount > numberOfPivots)
|
|
{
|
|
//
|
|
Clean(changes);
|
|
FillPeaksChanges(changes);
|
|
|
|
//
|
|
verifications = 0;
|
|
for (int i = peaksChangesCount - 1 - numberOfPivots; i < peaksChangesCount - 2; i++)
|
|
{
|
|
//
|
|
XValueChange cChange = changes[i];
|
|
XValueChange nChange = changes[i + 1];
|
|
|
|
//
|
|
if (cChange.after > nChange.after)
|
|
{
|
|
verifications++;
|
|
}
|
|
}
|
|
|
|
//
|
|
result = verifications == numberOfPivots - 1;
|
|
if (result)
|
|
{
|
|
dir = X_DIRECTION_BEARISH;
|
|
}
|
|
}
|
|
|
|
//
|
|
// Bullish Trend ...
|
|
int valesChangesCount = CountValesChanges();
|
|
if (!result &&
|
|
valesChangesCount > numberOfPivots)
|
|
{
|
|
//
|
|
Clean(changes);
|
|
FillValesChanges(changes);
|
|
|
|
//
|
|
verifications = 0;
|
|
for (int i = valesChangesCount - 1 - numberOfPivots; i < valesChangesCount - 2; i++)
|
|
{
|
|
//
|
|
XValueChange cChange = changes[i];
|
|
XValueChange nChange = changes[i + 1];
|
|
|
|
//
|
|
if (cChange.after < nChange.after)
|
|
{
|
|
verifications++;
|
|
}
|
|
}
|
|
|
|
//
|
|
result = verifications == numberOfPivots - 1;
|
|
if (result)
|
|
{
|
|
dir = X_DIRECTION_BULLISH;
|
|
}
|
|
}
|
|
|
|
//
|
|
return result;
|
|
}
|