Files
MQL5Data/Documents/BKP/X121XKI/tmps.bkp.mq5
T
2026-01-01 06:22:05 +03:30

964 lines
24 KiB
Plaintext
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
/**
* 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;
}