1335 lines
31 KiB
Plaintext
1335 lines
31 KiB
Plaintext
/**
|
||
* Check Bar Has Signal Based on Strategy 1 ...
|
||
*
|
||
* Pattern‑based reversal:
|
||
* - Detects Pin Bar or Signal Key Bar.
|
||
* - Confirms with POI detector.
|
||
* - Good for reversals at support/resistance.
|
||
*
|
||
* @param bar: XOHCL, reference to Bar ...
|
||
* @param zone: XBoxZone, reference to holds affected zone ...
|
||
* @param targets: XTarget, reference to detected Signal's Targets collections ...
|
||
* @param dir: ENUM_X_DIRECTION, detected Signal's direction ...
|
||
*
|
||
* @return ( bool )
|
||
*/
|
||
bool Strategy1HasSignal(
|
||
XOHCL &bar,
|
||
XBoxZone &zone,
|
||
XTarget &targets[],
|
||
ENUM_X_DIRECTION &dir //
|
||
)
|
||
{
|
||
//
|
||
bool result = false;
|
||
|
||
//
|
||
zone.Clean();
|
||
XClean(targets);
|
||
dir = X_DIRECTION_NONE;
|
||
|
||
//
|
||
result = bar.IsValid();
|
||
if (!result)
|
||
{
|
||
return result;
|
||
}
|
||
|
||
//
|
||
result = poiDetector.IsKISignal(
|
||
dir,
|
||
bar.Index() //
|
||
);
|
||
bool isBullish = result &&
|
||
IsXBullish(dir);
|
||
bool isBearish = result &&
|
||
IsXBearish(dir);
|
||
result = isBullish ||
|
||
isBearish;
|
||
if (!result)
|
||
{
|
||
return result;
|
||
}
|
||
|
||
//
|
||
// Detect Nearest Directional ...
|
||
int nearestDirectionalSwitchIndex = -1;
|
||
if (isBullish)
|
||
{
|
||
//
|
||
isBullish = poiDetector.NearestKIFastSwitchedToBullish(
|
||
nearestDirectionalSwitchIndex,
|
||
bar.Index() + 2 //
|
||
);
|
||
}
|
||
else
|
||
{
|
||
//
|
||
isBearish = poiDetector.NearestKIFastSwitchedToBearish(
|
||
nearestDirectionalSwitchIndex,
|
||
bar.Index() + 2 //
|
||
);
|
||
}
|
||
result =
|
||
IsValidIndex(nearestDirectionalSwitchIndex) &&
|
||
(isBullish ||
|
||
isBearish);
|
||
if (!result)
|
||
{
|
||
//
|
||
bar.Clean();
|
||
return result;
|
||
}
|
||
|
||
//
|
||
// Preparing Zone ...
|
||
double upper = bar.FindHighest(nearestDirectionalSwitchIndex - bar.Index(), MODE_HIGH);
|
||
double lower = bar.FindLowest(nearestDirectionalSwitchIndex - bar.Index(), MODE_LOW);
|
||
|
||
//
|
||
result = zone.Init(
|
||
symbol,
|
||
period,
|
||
upper,
|
||
lower,
|
||
GetBarTime(symbol, period, nearestDirectionalSwitchIndex),
|
||
bar.time,
|
||
dir,
|
||
"XKI1" //
|
||
);
|
||
|
||
//
|
||
// Support and Resistance ...
|
||
XBoxZone supports[];
|
||
XBoxZone resistances[];
|
||
if (result)
|
||
{
|
||
//
|
||
// Supports ...
|
||
poiDetector.DetectSupports(
|
||
supports,
|
||
bar.Index(),
|
||
50, // Loopback ...
|
||
true, // Force Validation ...
|
||
7, // Validation Length ...
|
||
symbol, // For Symbol ...
|
||
period // For Period ...
|
||
);
|
||
|
||
//
|
||
// Resistances ...
|
||
poiDetector.DetectResistances(
|
||
resistances,
|
||
bar.Index(),
|
||
50, // Loopback ...
|
||
true, // Force Validation ...
|
||
7, // Validation Length ...
|
||
symbol, // For Symbol ...
|
||
period // For Period ...
|
||
);
|
||
}
|
||
|
||
//
|
||
// TODO: Rempve ...
|
||
if (result)
|
||
{
|
||
//
|
||
// Other Drawing Materials ...
|
||
XPOIDrawConfig drawConfig;
|
||
drawConfig.Default();
|
||
|
||
//
|
||
// this for Selected Zone ...
|
||
poiDrawer.DrawZone(zone, drawConfig);
|
||
|
||
//
|
||
// Drawing Supports and Resistances ...
|
||
drawConfig.bearishColor = clrRed;
|
||
drawConfig.bullishColor = clrLime;
|
||
|
||
//
|
||
if (HasChild(supports))
|
||
{
|
||
poiDrawer.DrawZones(supports, drawConfig);
|
||
}
|
||
|
||
//
|
||
if (HasChild(resistances))
|
||
{
|
||
poiDrawer.DrawZones(resistances, drawConfig);
|
||
}
|
||
|
||
//
|
||
drawConfig.Clean();
|
||
|
||
//
|
||
DebugBreak();
|
||
}
|
||
|
||
//
|
||
result =
|
||
result &&
|
||
zone.IsValid() &&
|
||
HasDirection(dir);
|
||
|
||
//
|
||
return result;
|
||
}
|
||
|
||
/**
|
||
* Check Bar Has Signal Based on Strategy 1 ...
|
||
*
|
||
* Pattern‑based reversal:
|
||
* - Detects Pin Bar or Signal Key Bar.
|
||
* - Confirms with POI detector.
|
||
* - Good for reversals at support/resistance.
|
||
*
|
||
* @param bar: XOHCL, reference to Bar ...
|
||
* @param zone: XBoxZone, reference to holds affected zone ...
|
||
* @param targets: XTarget, reference to detected Signal's Targets collections ...
|
||
* @param dir: ENUM_X_DIRECTION, detected Signal's direction ...
|
||
*
|
||
* @return ( bool )
|
||
*/
|
||
bool Strategy1HasSignal(
|
||
XOHCL &bar,
|
||
XBoxZone &zone,
|
||
XTarget &targets[],
|
||
ENUM_X_DIRECTION &dir //
|
||
)
|
||
{
|
||
//
|
||
bool result = false;
|
||
|
||
//
|
||
zone.Clean();
|
||
XClean(targets);
|
||
dir = X_DIRECTION_NONE;
|
||
|
||
//
|
||
result = bar.IsValid();
|
||
if (!result)
|
||
{
|
||
return result;
|
||
}
|
||
|
||
//
|
||
result = poiDetector.IsKISignal(
|
||
dir,
|
||
bar.Index() //
|
||
);
|
||
bool isBullish = result &&
|
||
IsXBullish(dir);
|
||
bool isBearish = result &&
|
||
IsXBearish(dir);
|
||
result = isBullish ||
|
||
isBearish;
|
||
if (!result)
|
||
{
|
||
return result;
|
||
}
|
||
|
||
//
|
||
// Detect Nearest Directional ...
|
||
int nearestDirectionalSwitchIndex = -1;
|
||
if (isBullish)
|
||
{
|
||
//
|
||
isBullish = poiDetector.NearestKIFastSwitchedToBullish(
|
||
nearestDirectionalSwitchIndex,
|
||
bar.Index() + 2 //
|
||
);
|
||
}
|
||
else
|
||
{
|
||
//
|
||
isBearish = poiDetector.NearestKIFastSwitchedToBearish(
|
||
nearestDirectionalSwitchIndex,
|
||
bar.Index() + 2 //
|
||
);
|
||
}
|
||
result =
|
||
IsValidIndex(nearestDirectionalSwitchIndex) &&
|
||
(isBullish ||
|
||
isBearish);
|
||
if (!result)
|
||
{
|
||
//
|
||
bar.Clean();
|
||
return result;
|
||
}
|
||
|
||
//
|
||
// Preparing Zone ...
|
||
double upper = bar.FindHighest(nearestDirectionalSwitchIndex - bar.Index(), MODE_HIGH);
|
||
double lower = bar.FindLowest(nearestDirectionalSwitchIndex - bar.Index(), MODE_LOW);
|
||
|
||
//
|
||
result = zone.Init(
|
||
symbol,
|
||
period,
|
||
upper,
|
||
lower,
|
||
GetBarTime(symbol, period, nearestDirectionalSwitchIndex),
|
||
bar.time,
|
||
dir,
|
||
"XKI1" //
|
||
);
|
||
|
||
//
|
||
// Support and Resistance ...
|
||
XBoxZone supports[];
|
||
XBoxZone resistances[];
|
||
XBoxZone minorSupport;
|
||
XBoxZone majorSupport;
|
||
XBoxZone minorResistance;
|
||
XBoxZone majorResistance;
|
||
if (result)
|
||
{
|
||
//
|
||
// Supports ...
|
||
poiDetector.GetCurrentStructure(
|
||
supports,
|
||
resistances,
|
||
minorSupport,
|
||
majorSupport,
|
||
minorResistance,
|
||
majorResistance,
|
||
bar.Index(),
|
||
symbol, // For Symbol ...
|
||
period, // For Period ...
|
||
50, // Loopback ...
|
||
7, // Minor Validation Length ...
|
||
14 // Major Validation Length ...
|
||
);
|
||
}
|
||
|
||
//
|
||
// TODO: Rempve ...
|
||
if (result)
|
||
{
|
||
//
|
||
// Other Drawing Materials ...
|
||
XPOIDrawConfig drawConfig;
|
||
drawConfig.Default();
|
||
|
||
//
|
||
// this for Selected Zone ...
|
||
poiDrawer.DrawZone(zone, drawConfig);
|
||
|
||
//
|
||
// Drawing Supports and Resistances ...
|
||
drawConfig.bearishColor = clrRed;
|
||
drawConfig.bullishColor = clrLime;
|
||
|
||
//
|
||
// Minors ...
|
||
|
||
//
|
||
drawConfig.zonesStyle = STYLE_DOT;
|
||
if (minorSupport.IsValid())
|
||
{
|
||
poiDrawer.DrawZone(minorSupport, drawConfig);
|
||
}
|
||
if (minorResistance.IsValid())
|
||
{
|
||
poiDrawer.DrawZone(minorResistance, drawConfig);
|
||
}
|
||
|
||
//
|
||
// Majors ...
|
||
|
||
//
|
||
drawConfig.zonesStyle = STYLE_DASH;
|
||
if (majorSupport.IsValid())
|
||
{
|
||
poiDrawer.DrawZone(majorSupport, drawConfig);
|
||
}
|
||
if (majorResistance.IsValid())
|
||
{
|
||
poiDrawer.DrawZone(majorResistance, drawConfig);
|
||
}
|
||
|
||
// //
|
||
// if (HasChild(supports))
|
||
// {
|
||
// poiDrawer.DrawZones(supports, drawConfig);
|
||
// }
|
||
|
||
// //
|
||
// if (HasChild(resistances))
|
||
// {
|
||
// poiDrawer.DrawZones(resistances, drawConfig);
|
||
// }
|
||
|
||
//
|
||
drawConfig.Clean();
|
||
|
||
//
|
||
DebugBreak();
|
||
}
|
||
|
||
//
|
||
result =
|
||
result &&
|
||
zone.IsValid() &&
|
||
HasDirection(dir);
|
||
|
||
//
|
||
return result;
|
||
}
|
||
|
||
/**
|
||
* Check Bar Has Signal Based on Strategy 1 ...
|
||
*
|
||
* Pattern‑based reversal:
|
||
* - Detects Pin Bar or Signal Key Bar.
|
||
* - Confirms with POI detector.
|
||
* - Good for reversals at support/resistance.
|
||
*
|
||
* @param bar: XOHCL, reference to Bar ...
|
||
* @param zone: XBoxZone, reference to holds affected zone ...
|
||
* @param targets: XTarget, reference to detected Signal's Targets collections ...
|
||
* @param dir: ENUM_X_DIRECTION, detected Signal's direction ...
|
||
*
|
||
* @return ( bool )
|
||
*/
|
||
bool Strategy1HasSignal(
|
||
XOHCL &bar,
|
||
XBoxZone &zone,
|
||
XTarget &targets[],
|
||
ENUM_X_DIRECTION &dir //
|
||
)
|
||
{
|
||
//
|
||
bool result = false;
|
||
|
||
//
|
||
zone.Clean();
|
||
XClean(targets);
|
||
dir = X_DIRECTION_NONE;
|
||
|
||
//
|
||
result = bar.IsValid();
|
||
if (!result)
|
||
{
|
||
return result;
|
||
}
|
||
|
||
//
|
||
result = poiDetector.IsKISignal(
|
||
dir,
|
||
bar.Index() //
|
||
);
|
||
bool isBullish = result &&
|
||
IsXBullish(dir);
|
||
bool isBearish = result &&
|
||
IsXBearish(dir);
|
||
result = isBullish ||
|
||
isBearish;
|
||
if (!result)
|
||
{
|
||
return result;
|
||
}
|
||
|
||
//
|
||
// Detect Nearest Directional ...
|
||
int nearestDirectionalSwitchIndex = -1;
|
||
if (isBullish)
|
||
{
|
||
//
|
||
isBullish = poiDetector.NearestKIFastSwitchedToBullish(
|
||
nearestDirectionalSwitchIndex,
|
||
bar.Index() + 2 //
|
||
);
|
||
}
|
||
else
|
||
{
|
||
//
|
||
isBearish = poiDetector.NearestKIFastSwitchedToBearish(
|
||
nearestDirectionalSwitchIndex,
|
||
bar.Index() + 2 //
|
||
);
|
||
}
|
||
result =
|
||
IsValidIndex(nearestDirectionalSwitchIndex) &&
|
||
(isBullish ||
|
||
isBearish);
|
||
if (!result)
|
||
{
|
||
//
|
||
bar.Clean();
|
||
return result;
|
||
}
|
||
|
||
//
|
||
// Preparing Zone ...
|
||
double upper = bar.FindHighest(nearestDirectionalSwitchIndex - bar.Index(), MODE_HIGH);
|
||
double lower = bar.FindLowest(nearestDirectionalSwitchIndex - bar.Index(), MODE_LOW);
|
||
|
||
//
|
||
result = zone.Init(
|
||
symbol,
|
||
period,
|
||
upper,
|
||
lower,
|
||
GetBarTime(symbol, period, nearestDirectionalSwitchIndex),
|
||
bar.time,
|
||
dir,
|
||
"XKI1" //
|
||
);
|
||
|
||
//
|
||
// Support and Resistance ...
|
||
XBoxZone supports[];
|
||
XBoxZone resistances[];
|
||
XBoxZone minorSupport;
|
||
XBoxZone majorSupport;
|
||
XBoxZone minorResistance;
|
||
XBoxZone majorResistance;
|
||
if (result)
|
||
{
|
||
//
|
||
// Supports ...
|
||
poiDetector.GetCurrentStructure(
|
||
supports,
|
||
resistances,
|
||
minorSupport,
|
||
majorSupport,
|
||
minorResistance,
|
||
majorResistance,
|
||
bar.Index(),
|
||
symbol, // For Symbol ...
|
||
period, // For Period ...
|
||
50, // Loopback ...
|
||
7, // Minor Validation Length ...
|
||
14 // Major Validation Length ...
|
||
);
|
||
}
|
||
|
||
//
|
||
// TODO: Rempve ...
|
||
if (result)
|
||
{
|
||
//
|
||
// Other Drawing Materials ...
|
||
XPOIDrawConfig drawConfig;
|
||
drawConfig.Default();
|
||
|
||
//
|
||
// this for Selected Zone ...
|
||
poiDrawer.DrawZone(zone, drawConfig);
|
||
|
||
//
|
||
// Drawing Supports and Resistances ...
|
||
drawConfig.bearishColor = clrRed;
|
||
drawConfig.bullishColor = clrLime;
|
||
|
||
//
|
||
// Minors ...
|
||
|
||
//
|
||
drawConfig.zonesStyle = STYLE_DOT;
|
||
if (minorSupport.IsValid())
|
||
{
|
||
poiDrawer.DrawZone(minorSupport, drawConfig);
|
||
}
|
||
if (minorResistance.IsValid())
|
||
{
|
||
poiDrawer.DrawZone(minorResistance, drawConfig);
|
||
}
|
||
|
||
//
|
||
// Majors ...
|
||
|
||
//
|
||
drawConfig.zonesStyle = STYLE_DASH;
|
||
if (majorSupport.IsValid())
|
||
{
|
||
poiDrawer.DrawZone(majorSupport, drawConfig);
|
||
}
|
||
if (majorResistance.IsValid())
|
||
{
|
||
poiDrawer.DrawZone(majorResistance, drawConfig);
|
||
}
|
||
|
||
// //
|
||
// if (HasChild(supports))
|
||
// {
|
||
// poiDrawer.DrawZones(supports, drawConfig);
|
||
// }
|
||
|
||
// //
|
||
// if (HasChild(resistances))
|
||
// {
|
||
// poiDrawer.DrawZones(resistances, drawConfig);
|
||
// }
|
||
|
||
//
|
||
drawConfig.Clean();
|
||
|
||
//
|
||
DebugBreak();
|
||
}
|
||
|
||
//
|
||
result =
|
||
result &&
|
||
zone.IsValid() &&
|
||
HasDirection(dir);
|
||
|
||
//
|
||
return result;
|
||
}
|
||
|
||
/**
|
||
* Check Bar Has Signal Based on Strategy 1 ...
|
||
*
|
||
* Pattern‑based reversal:
|
||
* - Detects Pin Bar or Signal Key Bar.
|
||
* - Confirms with POI detector.
|
||
* - Good for reversals at support/resistance.
|
||
*
|
||
* @param bar: XOHCL, reference to Bar ...
|
||
* @param zone: XBoxZone, reference to holds affected zone ...
|
||
* @param targets: XTarget, reference to detected Signal's Targets collections ...
|
||
* @param dir: ENUM_X_DIRECTION, detected Signal's direction ...
|
||
*
|
||
* @return ( bool )
|
||
*/
|
||
bool Strategy1HasSignal(
|
||
XOHCL &bar,
|
||
XBoxZone &zone,
|
||
XTarget &targets[],
|
||
ENUM_X_DIRECTION &dir //
|
||
)
|
||
{
|
||
//
|
||
bool result = false;
|
||
|
||
//
|
||
zone.Clean();
|
||
XClean(targets);
|
||
dir = X_DIRECTION_NONE;
|
||
|
||
//
|
||
result = bar.IsValid();
|
||
if (!result)
|
||
{
|
||
return result;
|
||
}
|
||
|
||
//
|
||
int barIndex = bar.Index() + 1;
|
||
|
||
//
|
||
// Safe for Entry ...
|
||
bool isSafeForBullishEntry = kiParser.IsSafeBullishEntry(barIndex);
|
||
bool isSafeForBearishEntry = kiParser.IsSafeBearishEntry(barIndex);
|
||
|
||
//
|
||
// POI ...
|
||
bool isPOI = poiDetector.IsPOI(dir, barIndex);
|
||
bool isBullishPOI = isPOI &&
|
||
IsXBullish(dir);
|
||
bool isBearishPOI = isPOI &&
|
||
IsXBearish(dir);
|
||
if (isPOI)
|
||
{
|
||
//
|
||
// Print("isPOI: ", ToXString(dir));
|
||
// DebugBreak();
|
||
}
|
||
|
||
//
|
||
// Breakout POI ...
|
||
bool isBreakoutPOI = poiDetector.IsBreakoutPOI(dir, barIndex);
|
||
bool isBullishBreakoutPOI = isBreakoutPOI &&
|
||
IsXBullish(dir);
|
||
bool isBearishBreakoutPOI = isBreakoutPOI &&
|
||
IsXBearish(dir);
|
||
if (isBreakoutPOI)
|
||
{
|
||
//
|
||
// Print("isBreakoutPOI: ", ToXString(dir));
|
||
// DebugBreak();
|
||
}
|
||
|
||
//
|
||
// Reversal POI ...
|
||
bool isReversalPOI = poiDetector.IsReversalPOI(dir, barIndex);
|
||
bool isBullishReversalPOI = isReversalPOI &&
|
||
IsXBullish(dir);
|
||
bool isBearishReversalPOI = isReversalPOI &&
|
||
IsXBearish(dir);
|
||
if (isReversalPOI)
|
||
{
|
||
// //
|
||
// Print("isReversalPOI: ", ToXString(dir));
|
||
// DebugBreak();
|
||
}
|
||
|
||
//
|
||
// Continuation POI ...
|
||
bool isContinuationPOI = poiDetector.IsContinuationPOI(dir, barIndex);
|
||
bool isBullishContinuationPOI = isContinuationPOI &&
|
||
IsXBullish(dir);
|
||
bool isBearishContinuationPOI = isContinuationPOI &&
|
||
IsXBearish(dir);
|
||
if (isContinuationPOI)
|
||
{
|
||
//
|
||
// Print("isContinuationPOI: ", ToXString(dir));
|
||
// DebugBreak();
|
||
}
|
||
|
||
//
|
||
// Exhaustion POI ...
|
||
bool isExhaustionPOI = poiDetector.IsExhaustionPOI(dir, barIndex);
|
||
bool isBullishExhaustionPOI = isExhaustionPOI &&
|
||
IsXBullish(dir);
|
||
bool isBearishExhaustionPOI = isExhaustionPOI &&
|
||
IsXBearish(dir);
|
||
if (isExhaustionPOI)
|
||
{
|
||
//
|
||
// Print("isExhaustionPOI: ", ToXString(dir));
|
||
// DebugBreak();
|
||
}
|
||
|
||
//
|
||
// TrendExhausted POI ...
|
||
bool isTrendExhaustedPOI = poiDetector.IsTrendExhaustedPOI(dir, barIndex);
|
||
bool isBullishTrendExhaustedPOI = isTrendExhaustedPOI &&
|
||
IsXBullish(dir);
|
||
bool isBearishTrendExhaustedPOI = isTrendExhaustedPOI &&
|
||
IsXBearish(dir);
|
||
if (isTrendExhaustedPOI)
|
||
{
|
||
//
|
||
Print("isTrendExhaustedPOI: ", ToXString(dir));
|
||
DebugBreak();
|
||
}
|
||
|
||
/**
|
||
* Check Bar Has Signal Based on Strategy 2 ...
|
||
*
|
||
* Trend‑following:
|
||
* - Requires KI Fast + KI Slow alignment.
|
||
* - Confirms with MA crossover.
|
||
* - RSI filter to avoid false signals.
|
||
*
|
||
* @return ( bool )
|
||
*/
|
||
bool Strategy2HasSignal(
|
||
XOHCL & bar,
|
||
XBoxZone & zone,
|
||
XTarget & targets[],
|
||
ENUM_X_DIRECTION & dir //
|
||
)
|
||
{
|
||
//
|
||
bool result = false;
|
||
|
||
//
|
||
zone.Clean();
|
||
XClean(targets);
|
||
dir = X_DIRECTION_NONE;
|
||
|
||
//
|
||
result = bar.IsValid();
|
||
if (!result)
|
||
{
|
||
return result;
|
||
}
|
||
|
||
//
|
||
int barIndex = bar.Index() + 1;
|
||
|
||
//
|
||
bool isBullish = kiParser.IsBullishMomentumTrend(bar.Index());
|
||
bool isBearish = kiParser.IsBearishMomentumTrend(bar.Index());
|
||
result = isBullish ||
|
||
isBearish;
|
||
if (!result)
|
||
{
|
||
return result;
|
||
}
|
||
|
||
//
|
||
dir = isBullish
|
||
? X_DIRECTION_BULLISH
|
||
: isBearish
|
||
? X_DIRECTION_BEARISH
|
||
: X_DIRECTION_NONE;
|
||
result = ToBox(bar, zone, dir, X_BAR_PATTERN_MOMENTUM);
|
||
result =
|
||
result &&
|
||
zone.IsValid() &&
|
||
HasDirection(dir);
|
||
|
||
//
|
||
return result;
|
||
}
|
||
|
||
/**
|
||
* Check Bar Has Signal Based on Strategy 3 ...
|
||
*
|
||
* Breakout:
|
||
* - Detects price breaking KI bands with ATR confirmation.
|
||
* - Confirms with Momentum Bar pattern.
|
||
*
|
||
* @return ( bool )
|
||
*/
|
||
bool Strategy3HasSignal(
|
||
XOHCL & bar,
|
||
XBoxZone & zone,
|
||
XTarget & targets[],
|
||
ENUM_X_DIRECTION & dir //
|
||
)
|
||
{
|
||
//
|
||
bool result = false;
|
||
|
||
//
|
||
zone.Clean();
|
||
XClean(targets);
|
||
dir = X_DIRECTION_NONE;
|
||
|
||
//
|
||
result = bar.IsValid();
|
||
if (!result)
|
||
{
|
||
return result;
|
||
}
|
||
|
||
//
|
||
bool isBullish = poiDetector.IsBullishBreakoutPOI(bar.Index());
|
||
bool isBearish = poiDetector.IsBearishBreakoutPOI(bar.Index());
|
||
result = isBullish ||
|
||
isBearish;
|
||
if (!result)
|
||
{
|
||
return result;
|
||
}
|
||
|
||
//
|
||
dir = isBullish
|
||
? X_DIRECTION_BULLISH
|
||
: isBearish
|
||
? X_DIRECTION_BEARISH
|
||
: X_DIRECTION_NONE;
|
||
result = ToBox(bar, zone, dir, X_BAR_PATTERN_TRUE_GAPED);
|
||
result =
|
||
result &&
|
||
zone.IsValid() &&
|
||
HasDirection(dir);
|
||
|
||
//
|
||
return result;
|
||
}
|
||
|
||
/**
|
||
* Check Bar Has Signal Based on Strategy 4 ...
|
||
*
|
||
* Exhaustion:
|
||
* - Strong trend + RSI extreme + volatility low.
|
||
* - Confirms with Piercing/Dark Cloud Cover candlestick.
|
||
*
|
||
* @return ( bool )
|
||
*/
|
||
bool Strategy4HasSignal(
|
||
XOHCL & bar,
|
||
XBoxZone & zone,
|
||
XTarget & targets[],
|
||
ENUM_X_DIRECTION & dir //
|
||
)
|
||
{
|
||
//
|
||
bool result = false;
|
||
|
||
//
|
||
zone.Clean();
|
||
XClean(targets);
|
||
dir = X_DIRECTION_NONE;
|
||
|
||
//
|
||
result = bar.IsValid();
|
||
if (!result)
|
||
{
|
||
return result;
|
||
}
|
||
|
||
//
|
||
bool isBullish = poiDetector.IsBullishTrendExhaustedPOI(bar.Index());
|
||
bool isBearish = poiDetector.IsBearishTrendExhaustedPOI(bar.Index());
|
||
result = isBullish ||
|
||
isBearish;
|
||
if (!result)
|
||
{
|
||
return result;
|
||
}
|
||
|
||
//
|
||
dir = isBullish
|
||
? X_DIRECTION_BULLISH
|
||
: isBearish
|
||
? X_DIRECTION_BEARISH
|
||
: X_DIRECTION_NONE;
|
||
result = ToBox(bar, zone, dir, X_BAR_PATTERN_PIERCING);
|
||
result =
|
||
result &&
|
||
zone.IsValid() &&
|
||
HasDirection(dir);
|
||
|
||
//
|
||
return result;
|
||
}
|
||
|
||
/**
|
||
* Check Bar Has Signal Based on Strategy 5 ...
|
||
*
|
||
* Continuation:
|
||
* - Requires strong trend confirmation (KI fast/slow + MA crossover + RSI filter).
|
||
* - Confirms with continuation candlestick patterns (Flag or Rising pattern).
|
||
* - Ensures zone validity for entry.
|
||
*
|
||
* @return ( bool )
|
||
*/
|
||
bool Strategy5HasSignal(
|
||
XOHCL & bar,
|
||
XBoxZone & zone,
|
||
XTarget & targets[],
|
||
ENUM_X_DIRECTION & dir //
|
||
)
|
||
{
|
||
//
|
||
bool result = false;
|
||
|
||
//
|
||
zone.Clean();
|
||
XClean(targets);
|
||
dir = X_DIRECTION_NONE;
|
||
|
||
//
|
||
result = bar.IsValid();
|
||
if (!result)
|
||
{
|
||
return result;
|
||
}
|
||
|
||
//
|
||
bool isBullish = kiParser.IsTrendStrongBullish(bar.Index());
|
||
bool isBearish = kiParser.IsTrendStrongBearish(bar.Index());
|
||
result = isBullish ||
|
||
isBearish;
|
||
if (!result)
|
||
{
|
||
return result;
|
||
}
|
||
|
||
//
|
||
// Confirm Direction by Candlestick Continuation Patterns ...
|
||
isBullish =
|
||
isBullish &&
|
||
poiDetector.IsBullishContinuationPOI(bar.Index());
|
||
isBearish =
|
||
isBearish &&
|
||
poiDetector.IsBearishContinuationPOI(bar.Index());
|
||
result = isBullish ||
|
||
isBearish;
|
||
if (!result)
|
||
{
|
||
return result;
|
||
}
|
||
|
||
//
|
||
dir = isBullish
|
||
? X_DIRECTION_BULLISH
|
||
: isBearish
|
||
? X_DIRECTION_BEARISH
|
||
: X_DIRECTION_NONE;
|
||
result = ToBox(bar, zone, dir, X_BAR_PATTERN_PIERCING);
|
||
result =
|
||
result &&
|
||
zone.IsValid() &&
|
||
HasDirection(dir);
|
||
|
||
//
|
||
return result;
|
||
}
|
||
|
||
///
|
||
//
|
||
//
|
||
///
|
||
|
||
result =
|
||
isBullish
|
||
? // entry > iBar.low &&
|
||
entry < iBar.high
|
||
// &&
|
||
// iBar.GetLowShadow() > iBar.GetHighShadow()
|
||
: // entry < iBar.high &&
|
||
entry > iBar.low
|
||
// &&
|
||
// iBar.GetHighShadow() > iBar.GetLowShadow()
|
||
;
|
||
|
||
///
|
||
///
|
||
|
||
/**
|
||
* Check Bar Has Signal Based on Strategy 1 ...
|
||
* POI ...
|
||
*
|
||
* @param bar: XOHCL, reference to Bar ...
|
||
* @param zone: XBoxZone, reference to holds affected zone ...
|
||
* @param targets: XTarget, reference to detected Signal's Targets collections ...
|
||
* @param dir: ENUM_X_DIRECTION, detected Signal's direction ...
|
||
*
|
||
* @return ( bool )
|
||
*/
|
||
bool Strategy1HasSignal(
|
||
XOHCL & bar,
|
||
XBoxZone & zone,
|
||
XTarget & targets[],
|
||
ENUM_X_DIRECTION & dir //
|
||
)
|
||
{
|
||
//
|
||
bool result = false;
|
||
|
||
//
|
||
zone.Clean();
|
||
XClean(targets);
|
||
dir = X_DIRECTION_NONE;
|
||
|
||
//
|
||
result = bar.IsValid();
|
||
if (!result)
|
||
{
|
||
return result;
|
||
}
|
||
|
||
//
|
||
int barIndex = bar.Index() + 1;
|
||
|
||
//
|
||
// Retrieve Base Conditions ...
|
||
bool isBullish = IsBullishPOILongEntry(barIndex);
|
||
bool isBearish = IsBearishPOIShortEntry(barIndex);
|
||
|
||
//
|
||
// Validate Conditions ...
|
||
result = isBullish || isBearish;
|
||
if (!result)
|
||
{
|
||
return result;
|
||
}
|
||
|
||
//
|
||
XOHCL iBar;
|
||
result = iBar.Init(bar.symbol, bar.period, barIndex);
|
||
if (!result)
|
||
{
|
||
return result;
|
||
}
|
||
|
||
//
|
||
// Do Validation and Filtering Market Structure if required ...
|
||
|
||
//
|
||
// Validate near Support / Resistance Zones ...
|
||
bool validateNearSupRes = true;
|
||
if (result && validateNearSupRes)
|
||
{
|
||
//
|
||
// Configs ...
|
||
int loopback = 100;
|
||
int validationLength = 7;
|
||
double nearThreshold = 5;
|
||
int validationRetests = 0;
|
||
int validationLoopback = 100;
|
||
double validationThreshold = 5;
|
||
|
||
//
|
||
// Filling Zones ...
|
||
XBoxZone zones[];
|
||
if (isBullish)
|
||
{
|
||
//
|
||
// Detect Supports ...
|
||
poiDetector.DetectSupports(
|
||
zones,
|
||
barIndex,
|
||
loopback,
|
||
true,
|
||
validationLength, // Validation Length ...
|
||
validationRetests, // Min Retest ...
|
||
validationThreshold, // Retest Threshold ...
|
||
validationLoopback, // Retest Loopback ...
|
||
symbol,
|
||
period //
|
||
);
|
||
}
|
||
else if (isBearish)
|
||
{
|
||
//
|
||
// Detect Resistances ...
|
||
poiDetector.DetectResistances(
|
||
zones,
|
||
barIndex,
|
||
loopback,
|
||
true,
|
||
validationLength, // Validation Length ...
|
||
validationRetests, // Min Retest ...
|
||
validationThreshold, // Retest Threshold ...
|
||
validationLoopback, // Retest Loopback ...
|
||
symbol,
|
||
period //
|
||
);
|
||
}
|
||
|
||
//
|
||
if (HasChild(zones))
|
||
{
|
||
//
|
||
XPOIDrawConfig iConfig;
|
||
iConfig.Default();
|
||
|
||
//
|
||
poiDrawer.DrawZones(zones, iConfig);
|
||
iConfig.Clean();
|
||
DebugBreak();
|
||
}
|
||
|
||
//
|
||
// Check Has Nearest ...
|
||
int nearIDX = -1;
|
||
result = poiDetector.HasNearZone(
|
||
nearIDX,
|
||
bar.close,
|
||
nearThreshold,
|
||
zones //
|
||
);
|
||
|
||
//
|
||
// Validate ...
|
||
if (!result)
|
||
{
|
||
//
|
||
isBullish = false;
|
||
isBearish = false;
|
||
}
|
||
}
|
||
|
||
//
|
||
// Validate by ATR Rising/Falling ...
|
||
bool validateByATRRaisFalling = false;
|
||
if (result && validateByATRRaisFalling)
|
||
{
|
||
//
|
||
// Bullish:
|
||
// - ATR Lower Rising ...
|
||
// - ATR Over ATR Ma ...
|
||
// Bearsih:
|
||
// - ATR Upper Falling ...
|
||
// - ATR Over ATR Ma ...
|
||
|
||
//
|
||
isBullish =
|
||
isBullish &&
|
||
// kiHelper.GetATR(barIndex) > kiHelper.GetATRSmoothed(barIndex) &&
|
||
kiHelper.GetKILower(barIndex) > kiHelper.GetKILower(barIndex + 1);
|
||
isBearish =
|
||
isBearish &&
|
||
// kiHelper.GetATR(barIndex) > kiHelper.GetATRSmoothed(barIndex) &&
|
||
kiHelper.GetKIUpper(barIndex) < kiHelper.GetKIUpper(barIndex + 1);
|
||
result = isBullish || isBearish;
|
||
|
||
//
|
||
if (!result)
|
||
{
|
||
//
|
||
isBullish = false;
|
||
isBearish = false;
|
||
}
|
||
}
|
||
|
||
//
|
||
// Validate by RSI ...
|
||
bool validatebyRSI = false;
|
||
if (result && validatebyRSI)
|
||
{
|
||
//
|
||
// Bullish:
|
||
// - Not in Over Baught;
|
||
// - Rising;
|
||
// Bearish :
|
||
// - Not in Over Sold;
|
||
// - Falling;
|
||
|
||
//
|
||
isBullish =
|
||
isBullish &&
|
||
!kiParser.IsRSIOverbought(barIndex) &&
|
||
kiHelper.GetRSI(barIndex) > kiHelper.GetRSI(barIndex + 1);
|
||
isBearish =
|
||
isBearish &&
|
||
!kiParser.IsRSIOversold(barIndex) &&
|
||
kiHelper.GetRSI(barIndex) < kiHelper.GetRSI(barIndex + 1);
|
||
result = isBullish || isBearish;
|
||
|
||
//
|
||
if (!result)
|
||
{
|
||
//
|
||
isBullish = false;
|
||
isBearish = false;
|
||
}
|
||
}
|
||
|
||
//
|
||
// Validate by iBar Pattern ...
|
||
// in this Strategy we have PinBar or SignalKeyBar ...
|
||
bool validateByBarPatterns = false;
|
||
if (result && validateByBarPatterns)
|
||
{
|
||
//
|
||
// Pin ...
|
||
bool isPinBar = poiDetector.IsPinnedBar(
|
||
iBar,
|
||
dir //
|
||
);
|
||
bool isPinBarBullish =
|
||
isPinBar &&
|
||
IsXBullish(dir);
|
||
bool isPinBarBearish =
|
||
isPinBar &&
|
||
IsXBearish(dir);
|
||
|
||
//
|
||
// Engulfe ...
|
||
bool isEngulfed = poiDetector.IsEngulfedBar(
|
||
iBar,
|
||
dir //
|
||
);
|
||
bool isEngulfedBullish =
|
||
isEngulfed &&
|
||
IsXBullish(dir);
|
||
bool isEngulfedBearish =
|
||
isEngulfed &&
|
||
IsXBearish(dir);
|
||
|
||
//
|
||
// Signal Key Bar ...
|
||
bool isSignalKeyBar = poiDetector.IsSignalKeyBarPattern(
|
||
iBar,
|
||
dir //
|
||
);
|
||
bool isSignalKeyBarBullish =
|
||
isSignalKeyBar &&
|
||
IsXBullish(dir);
|
||
bool isSignalKeyBarBearish =
|
||
isSignalKeyBar &&
|
||
IsXBearish(dir);
|
||
|
||
//
|
||
isBullish =
|
||
isBullish &&
|
||
(isEngulfedBullish);
|
||
isBearish =
|
||
isBearish &&
|
||
(isEngulfedBearish);
|
||
|
||
// //
|
||
// isBullish =
|
||
// isBullish &&
|
||
// (isPinBarBullish ||
|
||
// isEngulfedBullish ||
|
||
// isSignalKeyBarBullish);
|
||
// isBearish =
|
||
// isBearish &&
|
||
// (isPinBarBearish ||
|
||
// isEngulfedBearish ||
|
||
// isSignalKeyBarBearish);
|
||
|
||
//
|
||
result = isBullish || isBearish;
|
||
|
||
//
|
||
if (!result)
|
||
{
|
||
//
|
||
isBullish = false;
|
||
isBearish = false;
|
||
}
|
||
}
|
||
|
||
//
|
||
// Check and Prepare Direction ...
|
||
dir =
|
||
isBullish
|
||
? X_DIRECTION_BULLISH
|
||
: isBearish ? X_DIRECTION_BEARISH
|
||
: X_DIRECTION_NONE;
|
||
result = HasDirection(dir);
|
||
if (!result)
|
||
{
|
||
//
|
||
iBar.Clean();
|
||
return result;
|
||
}
|
||
|
||
//
|
||
// Prepare Zone ...
|
||
double entry = GetEntry(iBar.symbol, dir);
|
||
if (result)
|
||
{
|
||
//
|
||
double upper = isBullish
|
||
? entry
|
||
: iBar.high;
|
||
double lower = isBullish
|
||
? iBar.low
|
||
: entry;
|
||
datetime to = bar.time;
|
||
datetime from = iBar.BeforeOn();
|
||
result = zone.Init(
|
||
iBar.symbol,
|
||
iBar.period,
|
||
upper,
|
||
lower,
|
||
from,
|
||
to,
|
||
dir,
|
||
"XS1" //
|
||
);
|
||
if (result)
|
||
{
|
||
//
|
||
XPOIDrawConfig iConfig;
|
||
iConfig.Default();
|
||
|
||
//
|
||
poiDrawer.DrawZone(zone, iConfig);
|
||
|
||
//
|
||
// DebugBreak();
|
||
}
|
||
}
|
||
|
||
//
|
||
iBar.Clean();
|
||
|
||
//
|
||
result =
|
||
result &&
|
||
zone.IsValid() &&
|
||
HasDirection(dir);
|
||
|
||
//
|
||
return result;
|
||
}
|