Files
MQL5Data/Documents/BKP/X121XKI/tmps.bkp.mq5
T
2026-01-08 20:45:23 +03:30

4782 lines
106 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;
}
///
//
//
///
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;
}
/**
* 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 = true;
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;
}
// //
// isBullish =
// // majorSupport.IsValid() &&
// minorSupport.IsValid() &&
// poiDetector.IsKIBullishPOI(barIndex) &&
// poiDetector.HasCandlestickDirection(
// iBar,
// X_DIRECTION_BULLISH //
// ) &&
// IsTFBullishPattern(barIndex, PERIOD_M5) &&
// // minorSupport.lower <= majorSupport.upper &&
// poiDetector.IsNearZone(iBar.close, minorSupport, 10);
// //
// isBearish =
// // majorResistance.IsValid() &&
// minorResistance.IsValid() &&
// poiDetector.IsKIBearishPOI(barIndex) &&
// poiDetector.HasCandlestickDirection(
// iBar,
// X_DIRECTION_BEARISH //
// ) &&
// IsTFBearishPattern(barIndex, PERIOD_M5) &&
// // minorResistance.upper >= majorResistance.lower &&
// poiDetector.IsNearZone(iBar.close, minorResistance, 10);
//
// Retrieve Base Conditions ...
// isBullish =
// isBullish &&
// IsBullishPOILongEntry(barIndex);
// isBearish =
// isBearish &&
// IsBearishPOIShortEntry(barIndex);
// //
// // 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 = true;
// 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;
// }
// }
//
// Recent Support ...
// else if (HasChild(supports))
// {
// //
// tmpSupportIDX = GetYoungestBelow(iBar.close, supports);
// if (IsValidIndex(tmpSupportIDX))
// {
// zone = supports[tmpSupportIDX];
// }
// }
//
// Recent Resistance ...
// else if (HasChild(resistances))
// {
// //
// tmpResistanceIDX = GetYoungestAbove(iBar.close, resistances);
// if (IsValidIndex(tmpResistanceIDX))
// {
// zone = resistances[tmpResistanceIDX];
// }
// }
//
//
//
// #region Market Structure ...
XBoxZone supports[];
XBoxZone resistances[];
XBoxZone minorSupport;
XBoxZone majorSupport;
XBoxZone minorResistance;
XBoxZone majorResistance;
poiDetector.GetCurrentStructure(
supports,
resistances,
minorSupport,
majorSupport,
minorResistance,
majorResistance,
barIndex,
bar.symbol,
iBar.period, // Minor ...
PERIOD_H1, // Major ...
50,
14,
21,
0 //
);
//
// Refining Zones ...
int refineLoopback = 500;
double refineBreakThreshold = 10;
ENUM_X_PRICE refineBreakBy = X_PRICE_CLOSE;
poiDetector.RefineStructure(
supports,
resistances,
minorSupport,
majorSupport,
minorResistance,
majorResistance,
refineLoopback,
refineBreakThreshold,
refineBreakBy //
);
// #endregion
// #region NearInside Support/Resistance ...
//
int tmpSupportIDX = -1;
bool isNearSupport = poiDetector.HasNearZone(tmpSupportIDX, iBar.close, 5, supports);
if (isNearSupport)
{
scoreBullish++;
}
//
int tmpResistanceIDX = -1;
bool isNearResistance = poiDetector.HasNearZone(tmpResistanceIDX, iBar.close, 5, resistances);
if (isNearResistance)
{
scoreBearish++;
}
// #endregion
//
// Cleanup Resources ...
iBar.Clean();
XClean(supports);
XClean(resistances);
minorSupport.Clean();
majorSupport.Clean();
minorResistance.Clean();
majorResistance.Clean();
//
// Draws ...
bool draw = true;
if (draw && result)
{
//
int drawn = 0;
//
XPOIDrawConfig config;
config.Default();
//
if (zone.IsValid())
{
//
drawn++;
//
config.zonesWidth = 3;
config.bullishColor = clrYellow;
config.bearishColor = clrOrange;
//
poiDrawer.DrawZone(zone, config);
//
config.Default();
}
//
// Minors ...
if (minorSupport.IsValid())
{
//
drawn++;
poiDrawer.DrawZone(minorSupport, config);
}
if (minorResistance.IsValid())
{
//
drawn++;
poiDrawer.DrawZone(minorResistance, config);
}
//
// Majors ...
config.bullishColor = clrLime;
config.bearishColor = clrRed;
config.zonesWidth = 4;
//
if (majorSupport.IsValid())
{
//
drawn++;
poiDrawer.DrawZone(majorSupport, config);
}
if (majorResistance.IsValid())
{
//
drawn++;
poiDrawer.DrawZone(majorResistance, config);
}
//
config.Clean();
//
if (drawn > 0)
{
DebugBreak();
}
}
int CountSameVales(
int barIndex = 0,
int loopback = 10 //
)
{
//
int result = 0;
//
if (!IsValid())
{
return result;
}
//
loopback = NormalizeInt(loopback, 2);
barIndex = NormalizeBarIndex(barIndex);
//
for (int i = barIndex; i < barIndex + loopback; i++)
{
//
if (IsValeSameAsLast(i))
{
result++;
}
}
//
return result;
}
int CountSamePeaks(
int barIndex = 0,
int loopback = 10 //
)
{
//
int result = 0;
//
if (!IsValid())
{
return result;
}
//
loopback = NormalizeInt(loopback, 2);
barIndex = NormalizeBarIndex(barIndex);
//
for (int i = barIndex; i < barIndex + loopback; i++)
{
//
if (IsPeakSameAsLast(i))
{
result++;
}
}
//
return result;
}
// #region KI Fast ...
// bool IsKIFastBullish(int barIndex = 0)
// {
// //
// bool result = false;
// //
// // Normalize ...
// barIndex = NormalizeBarIndex(barIndex);
// //
// // Validate ...
// result = IsValid();
// if (!result)
// {
// return result;
// }
// //
// double state = helper.GetKIFastState(barIndex);
// result = state >= 1;
// //
// return result;
// }
// bool IsKIFastBearish(int barIndex = 0)
// {
// //
// bool result = false;
// //
// // Normalize ...
// barIndex = NormalizeBarIndex(barIndex);
// //
// // Validate ...
// result = IsValid();
// if (!result)
// {
// return result;
// }
// //
// double state = helper.GetKIFastState(barIndex);
// result = state <= -1;
// //
// return result;
// }
// bool IsKIFastSwitchedToBullish(int barIndex = 0)
// {
// //
// bool result = false;
// //
// // Normalize ...
// barIndex = NormalizeBarIndex(barIndex);
// //
// // Validate ...
// result = IsValid();
// if (!result)
// {
// return result;
// }
// //
// result = IsKIFastBullish(barIndex) &&
// !IsKIFastBullish(barIndex + 1);
// //
// return result;
// }
// bool IsKIFastSwitchedToBearish(int barIndex = 0)
// {
// //
// bool result = false;
// //
// // Normalize ...
// barIndex = NormalizeBarIndex(barIndex);
// //
// // Validate ...
// result = IsValid();
// if (!result)
// {
// return result;
// }
// //
// result = IsKIFastBearish(barIndex) &&
// !IsKIFastBearish(barIndex + 1);
// //
// return result;
// }
// bool IsKIFastOverLast(
// int barIndex = 0,
// double tolerance = 2 //
// )
// {
// //
// bool result = false;
// //
// // Normalize ...
// barIndex = NormalizeBarIndex(barIndex);
// //
// // Validate ...
// result = IsValid();
// if (!result)
// {
// return result;
// }
// //
// result = IsOver(
// helper.GetKIFast(barIndex),
// helper.GetKIFast(barIndex + 1),
// GetPoints(symbol) * tolerance //
// );
// //
// return result;
// }
// bool IsKIFastUnderLast(
// int barIndex = 0,
// double tolerance = 2 //
// )
// {
// //
// bool result = false;
// //
// // Normalize ...
// barIndex = NormalizeBarIndex(barIndex);
// //
// // Validate ...
// result = IsValid();
// if (!result)
// {
// return result;
// }
// //
// result = IsUnder(
// helper.GetKIFast(barIndex),
// helper.GetKIFast(barIndex + 1),
// GetPoints(symbol) * tolerance //
// );
// //
// return result;
// }
// bool IsKIFastSameAsLast(
// int barIndex = 0,
// double tolerance = 2 //
// )
// {
// //
// bool result = false;
// //
// barIndex = NormalizeBarIndex(barIndex);
// //
// result = IsValid() &&
// IsSame(
// helper.GetKIFast(barIndex),
// helper.GetKIFast(barIndex + 1),
// GetPoints(symbol) * tolerance //
// );
// //
// return result;
// }
// bool IsKIFastSwitchedOverLast(
// int barIndex = 0,
// double tolerance = 2 //
// )
// {
// //
// bool result = false;
// //
// barIndex = NormalizeBarIndex(barIndex);
// //
// result =
// IsValid() &&
// IsKIFastOverLast(barIndex, tolerance) &&
// !IsKIFastOverLast(barIndex + 1, tolerance);
// if (!result)
// {
// return result;
// }
// //
// return result;
// }
// bool IsKIFastSwitchedUnderLast(
// int barIndex = 0,
// double tolerance = 2 //
// )
// {
// //
// bool result = false;
// //
// barIndex = NormalizeBarIndex(barIndex);
// //
// result =
// IsValid() &&
// IsKIFastUnderLast(barIndex, tolerance) &&
// !IsKIFastUnderLast(barIndex + 1, tolerance);
// if (!result)
// {
// return result;
// }
// //
// return result;
// }
// #endregion
// #region KI Slow ...
bool IsKISlowBullish(int barIndex = 0)
{
//
bool result = false;
//
// Normalize ...
barIndex = NormalizeBarIndex(barIndex);
//
// Validate ...
result = IsValid();
if (!result)
{
return result;
}
//
double state = helper.GetKISlowState(barIndex);
result = state >= 1;
//
return result;
}
bool IsKISlowBearish(int barIndex = 0)
{
//
bool result = false;
//
// Normalize ...
barIndex = NormalizeBarIndex(barIndex);
//
// Validate ...
result = IsValid();
if (!result)
{
return result;
}
//
double state = helper.GetKISlowState(barIndex);
result = state <= -1;
//
return result;
}
bool IsKISlowSwitchedToBullish(int barIndex = 0)
{
//
bool result = false;
//
// Normalize ...
barIndex = NormalizeBarIndex(barIndex);
//
// Validate ...
result = IsValid();
if (!result)
{
return result;
}
//
result = IsKISlowBullish(barIndex) &&
!IsKISlowBullish(barIndex + 1);
//
return result;
}
bool IsKISlowSwitchedToBearish(int barIndex = 0)
{
//
bool result = false;
//
// Normalize ...
barIndex = NormalizeBarIndex(barIndex);
//
// Validate ...
result = IsValid();
if (!result)
{
return result;
}
//
result = IsKISlowBearish(barIndex) &&
!IsKISlowBearish(barIndex + 1);
//
return result;
}
bool IsKISlowOverLast(
int barIndex = 0,
double tolerance = 2 //
)
{
//
bool result = false;
//
// Normalize ...
barIndex = NormalizeBarIndex(barIndex);
//
// Validate ...
result = IsValid();
if (!result)
{
return result;
}
//
result = IsOver(
helper.GetKISlow(barIndex),
helper.GetKISlow(barIndex + 1),
GetPoints(symbol) * tolerance //
);
//
return result;
}
bool IsKISlowUnderLast(
int barIndex = 0,
double tolerance = 2 //
)
{
//
bool result = false;
//
// Normalize ...
barIndex = NormalizeBarIndex(barIndex);
//
// Validate ...
result = IsValid();
if (!result)
{
return result;
}
//
result = IsUnder(
helper.GetKISlow(barIndex),
helper.GetKISlow(barIndex + 1),
GetPoints(symbol) * tolerance //
);
//
return result;
}
bool IsKISlowSameAsLast(
int barIndex = 0,
double tolerance = 2 //
)
{
//
bool result = false;
//
barIndex = NormalizeBarIndex(barIndex);
//
result = IsSame(
helper.GetKISlow(barIndex),
helper.GetKISlow(barIndex + 1),
GetPoints(symbol) * tolerance //
);
//
return result;
}
bool IsKISlowSwitchedOverLast(
int barIndex = 0,
double tolerance = 2 //
)
{
//
bool result = false;
//
barIndex = NormalizeBarIndex(barIndex);
//
result =
IsValid() &&
IsKISlowOverLast(barIndex, tolerance) &&
!IsKISlowOverLast(barIndex + 1, tolerance);
if (!result)
{
return result;
}
//
return result;
}
bool IsKISlowSwitchedUnderLast(
int barIndex = 0,
double tolerance = 2 //
)
{
//
bool result = false;
//
barIndex = NormalizeBarIndex(barIndex);
//
result =
IsValid() &&
IsKISlowUnderLast(barIndex, tolerance) &&
!IsKISlowUnderLast(barIndex + 1, tolerance);
if (!result)
{
return result;
}
//
return result;
}
// #endregion
// #region KI Super Slow ...
bool IsKISuperSlowBullish(int barIndex = 0)
{
//
bool result = false;
//
// Normalize ...
barIndex = NormalizeBarIndex(barIndex);
//
// Validate ...
result = IsValid();
if (!result)
{
return result;
}
//
double state = helper.GetKISuperSlowState(barIndex);
result = state >= 1;
//
return result;
}
bool IsKISuperSlowBearish(int barIndex = 0)
{
//
bool result = false;
//
// Normalize ...
barIndex = NormalizeBarIndex(barIndex);
//
// Validate ...
result = IsValid();
if (!result)
{
return result;
}
//
double state = helper.GetKISuperSlowState(barIndex);
result = state <= -1;
//
return result;
}
bool IsKISuperSlowSwitchedToBullish(int barIndex = 0)
{
//
bool result = false;
//
// Normalize ...
barIndex = NormalizeBarIndex(barIndex);
//
// Validate ...
result = IsValid();
if (!result)
{
return result;
}
//
result = IsKISuperSlowBullish(barIndex) &&
!IsKISuperSlowBullish(barIndex + 1);
//
return result;
}
bool IsKISuperSlowSwitchedToBearish(int barIndex = 0)
{
//
bool result = false;
//
// Normalize ...
barIndex = NormalizeBarIndex(barIndex);
//
// Validate ...
result = IsValid();
if (!result)
{
return result;
}
//
result = IsKISuperSlowBearish(barIndex) &&
!IsKISuperSlowBearish(barIndex + 1);
//
return result;
}
bool IsKISuperSlowOverLast(
int barIndex = 0,
double tolerance = 2 //
)
{
//
bool result = false;
//
// Normalize ...
barIndex = NormalizeBarIndex(barIndex);
//
// Validate ...
result = IsValid();
if (!result)
{
return result;
}
//
result = IsOver(
helper.GetKISuperSlow(barIndex),
helper.GetKISuperSlow(barIndex + 1),
GetPoints(symbol) * tolerance //
);
//
return result;
}
bool IsKISuperSlowUnderLast(
int barIndex = 0,
double tolerance = 2 //
)
{
//
bool result = false;
//
// Normalize ...
barIndex = NormalizeBarIndex(barIndex);
//
// Validate ...
result = IsValid();
if (!result)
{
return result;
}
//
result = IsUnder(
helper.GetKISuperSlow(barIndex),
helper.GetKISuperSlow(barIndex + 1),
GetPoints(symbol) * tolerance //
);
//
return result;
}
bool IsKISuperSlowSameAsLast(
int barIndex = 0,
double tolerance = 2 //
)
{
//
bool result = false;
//
barIndex = NormalizeBarIndex(barIndex);
//
result = IsSame(
helper.GetKISuperSlow(barIndex),
helper.GetKISuperSlow(barIndex + 1),
GetPoints(symbol) * tolerance //
);
//
return result;
}
bool IsKISuperSlowSwitchedOverLast(
int barIndex = 0,
double tolerance = 2 //
)
{
//
bool result = false;
//
barIndex = NormalizeBarIndex(barIndex);
//
result =
IsValid() &&
IsKISuperSlowOverLast(barIndex, tolerance) &&
!IsKISuperSlowOverLast(barIndex + 1, tolerance);
if (!result)
{
return result;
}
//
return result;
}
bool IsKISuperSlowSwitchedUnderLast(
int barIndex = 0,
double tolerance = 2 //
)
{
//
bool result = false;
//
barIndex = NormalizeBarIndex(barIndex);
//
result =
IsValid() &&
IsKISuperSlowUnderLast(barIndex, tolerance) &&
!IsKISuperSlowUnderLast(barIndex + 1, tolerance);
if (!result)
{
return result;
}
//
return result;
}
// #endregion
// #region KI Wave ...
bool IsKIWaveBullish(int barIndex = 0)
{
//
bool result = false;
//
// Normalize ...
barIndex = NormalizeBarIndex(barIndex);
//
// Validate ...
result = IsValid();
if (!result)
{
return result;
}
//
result = helper.GetKIWaveState(barIndex) >= 1;
//
return result;
}
bool IsKIWaveBearish(int barIndex = 0)
{
//
bool result = false;
//
// Normalize ...
barIndex = NormalizeBarIndex(barIndex);
//
// Validate ...
result = IsValid();
if (!result)
{
return result;
}
//
result = helper.GetKIWaveState(barIndex) <= -1;
//
return result;
}
bool IsKIWaveSwitchedToBullish(int barIndex = 0)
{
//
bool result = false;
//
// Normalize ...
barIndex = NormalizeBarIndex(barIndex);
//
// Validate ...
result = IsValid();
if (!result)
{
return result;
}
//
result = IsKIWaveBullish(barIndex) &&
!IsKIWaveBullish(barIndex + 1);
//
return result;
}
bool IsKIWaveSwitchedToBearish(int barIndex = 0)
{
//
bool result = false;
//
// Normalize ...
barIndex = NormalizeBarIndex(barIndex);
//
// Validate ...
result = IsValid();
if (!result)
{
return result;
}
//
result = IsKIWaveBearish(barIndex) &&
!IsKIWaveBearish(barIndex + 1);
//
return result;
}
bool IsKIWaveOverLast(
int barIndex = 0,
double tolerance = 2 //
)
{
//
bool result = false;
//
barIndex = NormalizeBarIndex(barIndex);
//
result = IsValid() &&
helper.GetKIWave(barIndex) > helper.GetKIWave(barIndex + 1);
//
return result;
}
bool IsKIWaveUnderLast(
int barIndex = 0,
double tolerance = 2 //
)
{
//
bool result = false;
//
barIndex = NormalizeBarIndex(barIndex);
//
result = IsValid() &&
helper.GetKIWave(barIndex) < helper.GetKIWave(barIndex + 1);
//
return result;
}
bool IsKIWaveSwitchedOverLast(
int barIndex = 0,
double tolerance = 2 //
)
{
//
bool result = false;
//
barIndex = NormalizeBarIndex(barIndex);
//
result =
IsValid() &&
IsKIWaveOverLast(barIndex) &&
!IsKIWaveOverLast(barIndex + 1);
//
return result;
}
bool IsKIWaveSwitchedUnderLast(
int barIndex = 0,
double tolerance = 2 //
)
{
//
bool result = false;
//
barIndex = NormalizeBarIndex(barIndex);
//
result =
IsValid() &&
IsKIWaveUnderLast(barIndex) &&
!IsKIWaveUnderLast(barIndex + 1);
//
return result;
}
// #endregion
// #region KI Band ...
bool IsPriceOverKIUpper(
int barIndex = 0,
ENUM_X_PRICE priceType = X_PRICE_CLOSE //
)
{
//
bool result = false;
//
// Normalize ...
barIndex = NormalizeBarIndex(barIndex);
//
// Validate ...
result = IsValid() &&
IsXValid(priceType);
if (!result)
{
return result;
}
//
XOHCL bar;
result = bar.Init(symbol, period, barIndex);
if (!result)
{
return result;
}
//
double price = bar.GetPrice(priceType);
result = price > helper.GetKIUpper(barIndex);
bar.Clean();
//
return result;
}
bool IsPriceUnderKIUpper(
int barIndex = 0,
ENUM_X_PRICE priceType = X_PRICE_CLOSE //
)
{
//
bool result = false;
//
// Normalize ...
barIndex = NormalizeBarIndex(barIndex);
//
// Validate ...
result = IsValid() &&
IsXValid(priceType);
if (!result)
{
return result;
}
//
XOHCL bar;
result = bar.Init(symbol, period, barIndex);
if (!result)
{
return result;
}
//
double price = bar.GetPrice(priceType);
result = price < helper.GetKIUpper(barIndex);
bar.Clean();
//
return result;
}
bool IsPriceOverKILower(
int barIndex = 0,
ENUM_X_PRICE priceType = X_PRICE_CLOSE //
)
{
//
bool result = false;
//
// Normalize ...
barIndex = NormalizeBarIndex(barIndex);
//
// Validate ...
result = IsValid() &&
IsXValid(priceType);
if (!result)
{
return result;
}
//
XOHCL bar;
result = bar.Init(symbol, period, barIndex);
if (!result)
{
return result;
}
//
double price = bar.GetPrice(priceType);
result = price > helper.GetKILower(barIndex);
bar.Clean();
//
return result;
}
bool IsPriceUnderKILower(
int barIndex = 0,
ENUM_X_PRICE priceType = X_PRICE_CLOSE //
)
{
//
bool result = false;
//
// Normalize ...
barIndex = NormalizeBarIndex(barIndex);
//
// Validate ...
result = IsValid() &&
IsXValid(priceType);
if (!result)
{
return result;
}
//
XOHCL bar;
result = bar.Init(symbol, period, barIndex);
if (!result)
{
return result;
}
//
double price = bar.GetPrice(priceType);
result = price < helper.GetKILower(barIndex);
bar.Clean();
//
return result;
}
bool IsPriceInsideKIBands(
int barIndex = 0,
ENUM_X_PRICE priceType = X_PRICE_CLOSE //
)
{
//
bool result = false;
//
// Normalize ...
barIndex = NormalizeBarIndex(barIndex);
//
// Validate ...
result = IsValid() &&
IsXValid(priceType);
if (!result)
{
return result;
}
//
XOHCL bar;
result = bar.Init(symbol, period, barIndex);
if (!result)
{
return result;
}
//
double price = bar.GetPrice(priceType);
result = price < helper.GetKIUpper(barIndex) &&
price > helper.GetKILower(barIndex);
bar.Clean();
//
return result;
}
bool IsPriceSwitchedOverKIUpper(
int barIndex = 0,
ENUM_X_PRICE priceType = X_PRICE_CLOSE //
)
{
//
bool result = false;
//
barIndex = NormalizeBarIndex(barIndex);
//
result =
IsValid() &&
IsPriceOverKIUpper(barIndex, priceType) &&
!IsPriceOverKIUpper(barIndex + 1, priceType);
//
return result;
}
bool IsPriceSwitchedUnderKIUpper(
int barIndex = 0,
ENUM_X_PRICE priceType = X_PRICE_CLOSE //
)
{
//
bool result = false;
//
barIndex = NormalizeBarIndex(barIndex);
//
result =
IsValid() &&
IsPriceUnderKIUpper(barIndex, priceType) &&
!IsPriceUnderKIUpper(barIndex + 1, priceType);
//
return result;
}
bool IsPriceSwitchedOverKILower(
int barIndex = 0,
ENUM_X_PRICE priceType = X_PRICE_CLOSE //
)
{
//
bool result = false;
//
barIndex = NormalizeBarIndex(barIndex);
//
result =
IsValid() &&
IsPriceOverKILower(barIndex, priceType) &&
!IsPriceOverKILower(barIndex + 1, priceType);
//
return result;
}
bool IsPriceSwitchedUnderKILower(
int barIndex = 0,
ENUM_X_PRICE priceType = X_PRICE_CLOSE //
)
{
//
bool result = false;
//
barIndex = NormalizeBarIndex(barIndex);
//
result =
IsValid() &&
IsPriceUnderKILower(barIndex, priceType) &&
!IsPriceUnderKILower(barIndex + 1, priceType);
//
return result;
}
// #endregion
// #region MA Fast ...
bool IsMAFastBullish(
int barIndex = 0,
ENUM_X_PRICE priceType = X_PRICE_CLOSE //
)
{
//
bool result = false;
//
// Normalize ...
barIndex = NormalizeBarIndex(barIndex);
//
// Validate ...
XOHCL iBar;
result = IsValid() &&
iBar.Init(symbol, period, barIndex);
if (!result)
{
return result;
}
//
result = iBar.GetPrice(priceType) > helper.GetMAFast(barIndex);
//
iBar.Clean();
//
return result;
}
bool IsMAFastBearish(
int barIndex = 0,
ENUM_X_PRICE priceType = X_PRICE_CLOSE //
)
{
//
bool result = false;
//
// Normalize ...
barIndex = NormalizeBarIndex(barIndex);
//
// Validate ...
XOHCL iBar;
result = IsValid() &&
iBar.Init(symbol, period, barIndex);
if (!result)
{
return result;
}
//
result = iBar.GetPrice(priceType) < helper.GetMAFast(barIndex);
//
iBar.Clean();
//
return result;
}
bool IsMAFastOverLast(
int barIndex = 0,
double tolerance = 2 //
)
{
//
bool result = false;
//
barIndex = NormalizeBarIndex(barIndex);
//
result =
IsValid() &&
IsOver(
helper.GetMAFast(barIndex),
helper.GetMAFast(barIndex + 1),
GetPoints(symbol) * tolerance //
);
//
return result;
}
bool IsMAFastUnderLast(
int barIndex = 0,
double tolerance = 2 //
)
{
//
bool result = false;
//
barIndex = NormalizeBarIndex(barIndex);
//
result =
IsValid() &&
IsUnder(
helper.GetMAFast(barIndex),
helper.GetMAFast(barIndex + 1),
GetPoints(symbol) * tolerance //
);
//
return result;
}
bool IsMAFastSwitchedOverLast(
int barIndex = 0,
double tolerance = 2 //
)
{
//
bool result = false;
//
barIndex = NormalizeBarIndex(barIndex);
//
result =
IsValid() &&
IsMAFastOverLast(barIndex, tolerance) &&
!IsMAFastOverLast(barIndex + 1, tolerance);
//
return result;
}
bool IsMAFastSwitchedUnderLast(
int barIndex = 0,
double tolerance = 2 //
)
{
//
bool result = false;
//
barIndex = NormalizeBarIndex(barIndex);
//
result =
IsValid() &&
IsMAFastUnderLast(barIndex, tolerance) &&
!IsMAFastUnderLast(barIndex + 1, tolerance);
//
return result;
}
bool IsMAFastSwitchedToBullish(
int barIndex = 0,
ENUM_X_PRICE priceType = X_PRICE_CLOSE //
)
{
//
bool result = false;
//
barIndex = NormalizeBarIndex(barIndex);
//
result = IsValid() &&
IsMAFastBullish(barIndex) &&
!IsMAFastBullish(barIndex + 1);
//
return result;
}
bool IsMAFastSwitchedToBearish(
int barIndex = 0,
ENUM_X_PRICE priceType = X_PRICE_CLOSE //
)
{
//
bool result = false;
//
barIndex = NormalizeBarIndex(barIndex);
//
result = IsValid() &&
IsMAFastBearish(barIndex) &&
!IsMAFastBearish(barIndex + 1);
//
return result;
}
// #endregion
// #region MA Slow ...
bool IsMASlowBullish(
int barIndex = 0,
ENUM_X_PRICE priceType = X_PRICE_CLOSE //
)
{
//
bool result = false;
//
// Normalize ...
barIndex = NormalizeBarIndex(barIndex);
//
// Validate ...
XOHCL iBar;
result = IsValid() &&
iBar.Init(symbol, period, barIndex);
if (!result)
{
return result;
}
//
result = iBar.GetPrice(priceType) > helper.GetMASlow(barIndex);
//
iBar.Clean();
//
return result;
}
bool IsMASlowBearish(
int barIndex = 0,
ENUM_X_PRICE priceType = X_PRICE_CLOSE //
)
{
//
bool result = false;
//
// Normalize ...
barIndex = NormalizeBarIndex(barIndex);
//
// Validate ...
XOHCL iBar;
result = IsValid() &&
iBar.Init(symbol, period, barIndex);
if (!result)
{
return result;
}
//
result = iBar.GetPrice(priceType) < helper.GetMASlow(barIndex);
//
iBar.Clean();
//
return result;
}
bool IsMASlowOverLast(
int barIndex = 0,
double tolerance = 2 //
)
{
//
bool result = false;
//
barIndex = NormalizeBarIndex(barIndex);
//
result =
IsValid() &&
IsOver(
helper.GetMASlow(barIndex),
helper.GetMASlow(barIndex + 1),
GetPoints(symbol) * tolerance //
);
//
return result;
}
bool IsMASlowUnderLast(
int barIndex = 0,
double tolerance = 2 //
)
{
//
bool result = false;
//
barIndex = NormalizeBarIndex(barIndex);
//
result =
IsValid() &&
IsUnder(
helper.GetMASlow(barIndex),
helper.GetMASlow(barIndex + 1),
GetPoints(symbol) * tolerance //
);
//
return result;
}
bool IsMASlowSwitchedOverLast(
int barIndex = 0,
double tolerance = 2 //
)
{
//
bool result = false;
//
barIndex = NormalizeBarIndex(barIndex);
//
result =
IsValid() &&
IsMASlowOverLast(barIndex, tolerance) &&
!IsMASlowOverLast(barIndex + 1, tolerance);
//
return result;
}
bool IsMASlowSwitchedUnderLast(
int barIndex = 0,
double tolerance = 2 //
)
{
//
bool result = false;
//
barIndex = NormalizeBarIndex(barIndex);
//
result =
IsValid() &&
IsMASlowUnderLast(barIndex, tolerance) &&
!IsMASlowUnderLast(barIndex + 1, tolerance);
//
return result;
}
bool IsMASlowSwitchedToBullish(
int barIndex = 0,
ENUM_X_PRICE priceType = X_PRICE_CLOSE //
)
{
//
bool result = false;
//
barIndex = NormalizeBarIndex(barIndex);
//
result = IsValid() &&
IsMASlowBullish(barIndex) &&
!IsMASlowBullish(barIndex + 1);
//
return result;
}
bool IsMASlowSwitchedToBearish(
int barIndex = 0,
ENUM_X_PRICE priceType = X_PRICE_CLOSE //
)
{
//
bool result = false;
//
barIndex = NormalizeBarIndex(barIndex);
//
result = IsValid() &&
IsMASlowBearish(barIndex) &&
!IsMASlowBearish(barIndex + 1);
//
return result;
}
// #endregion
// #region MA Super Slow ...
bool IsMASuperSlowBullish(
int barIndex = 0,
ENUM_X_PRICE priceType = X_PRICE_CLOSE //
)
{
//
bool result = false;
//
// Normalize ...
barIndex = NormalizeBarIndex(barIndex);
//
// Validate ...
XOHCL iBar;
result = IsValid() &&
iBar.Init(symbol, period, barIndex);
if (!result)
{
return result;
}
//
result = iBar.GetPrice(priceType) > helper.GetMASuperSlow(barIndex);
//
iBar.Clean();
//
return result;
}
bool IsMASuperSlowBearish(
int barIndex = 0,
ENUM_X_PRICE priceType = X_PRICE_CLOSE //
)
{
//
bool result = false;
//
// Normalize ...
barIndex = NormalizeBarIndex(barIndex);
//
// Validate ...
XOHCL iBar;
result = IsValid() &&
iBar.Init(symbol, period, barIndex);
if (!result)
{
return result;
}
//
result = iBar.GetPrice(priceType) < helper.GetMASuperSlow(barIndex);
//
iBar.Clean();
//
return result;
}
bool IsMASuperSlowOverLast(
int barIndex = 0,
double tolerance = 2 //
)
{
//
bool result = false;
//
barIndex = NormalizeBarIndex(barIndex);
//
result =
IsValid() &&
IsOver(
helper.GetMASuperSlow(barIndex),
helper.GetMASuperSlow(barIndex + 1),
GetPoints(symbol) * tolerance //
);
//
return result;
}
bool IsMASuperSlowUnderLast(
int barIndex = 0,
double tolerance = 2 //
)
{
//
bool result = false;
//
barIndex = NormalizeBarIndex(barIndex);
//
result =
IsValid() &&
IsUnder(
helper.GetMASuperSlow(barIndex),
helper.GetMASuperSlow(barIndex + 1),
GetPoints(symbol) * tolerance //
);
//
return result;
}
bool IsMASuperSlowSwitchedOverLast(
int barIndex = 0,
double tolerance = 2 //
)
{
//
bool result = false;
//
barIndex = NormalizeBarIndex(barIndex);
//
result =
IsValid() &&
IsMASuperSlowOverLast(barIndex, tolerance) &&
!IsMASuperSlowOverLast(barIndex + 1, tolerance);
//
return result;
}
bool IsMASuperSlowSwitchedUnderLast(
int barIndex = 0,
double tolerance = 2 //
)
{
//
bool result = false;
//
barIndex = NormalizeBarIndex(barIndex);
//
result =
IsValid() &&
IsMASuperSlowUnderLast(barIndex, tolerance) &&
!IsMASuperSlowUnderLast(barIndex + 1, tolerance);
//
return result;
}
bool IsMASuperSlowSwitchedToBullish(
int barIndex = 0,
ENUM_X_PRICE priceType = X_PRICE_CLOSE //
)
{
//
bool result = false;
//
barIndex = NormalizeBarIndex(barIndex);
//
result = IsValid() &&
IsMASuperSlowBullish(barIndex) &&
!IsMASuperSlowBullish(barIndex + 1);
//
return result;
}
bool IsMASuperSlowSwitchedToBearish(
int barIndex = 0,
ENUM_X_PRICE priceType = X_PRICE_CLOSE //
)
{
//
bool result = false;
//
barIndex = NormalizeBarIndex(barIndex);
//
result = IsValid() &&
IsMASuperSlowBearish(barIndex) &&
!IsMASuperSlowBearish(barIndex + 1);
//
return result;
}
// #endregion
// #region MA Fast/Slow/SuperSlow ...
bool IsMACrossoverBullish(int barIndex = 0)
{
//
bool result = false;
//
// Normalize ...
barIndex = NormalizeBarIndex(barIndex);
//
// Validate ...
result = IsValid();
if (!result)
{
return result;
}
//
result = helper.GetMAFast(barIndex) > helper.GetMASlow(barIndex);
return result;
}
bool IsMACrossoverBearish(int barIndex = 0)
{
//
bool result = false;
//
// Normalize ...
barIndex = NormalizeBarIndex(barIndex);
//
// Validate ...
result = IsValid();
if (!result)
{
return result;
}
//
result = helper.GetMAFast(barIndex) < helper.GetMASlow(barIndex);
return result;
}
bool IsMACrossoverSwitchedToBullish(int barIndex = 0)
{
//
bool result = false;
//
// Normalize ...
barIndex = NormalizeBarIndex(barIndex);
//
// Validate ...
result = IsValid();
if (!result)
{
return result;
}
//
result = IsMACrossoverBullish(barIndex) &&
!IsMACrossoverBullish(barIndex + 1);
return result;
}
bool IsMACrossoverSwitchedToBearish(int barIndex = 0)
{
//
bool result = false;
//
// Normalize ...
barIndex = NormalizeBarIndex(barIndex);
//
// Validate ...
result = IsValid();
if (!result)
{
return result;
}
//
result = IsMACrossoverBearish(barIndex) &&
!IsMACrossoverBearish(barIndex + 1);
return result;
}
// #endregion
// #region Composite ...
bool IsKIHasTrend(
double &score,
ENUM_X_DIRECTION &dir,
int barIndex = 0,
double requiredScore = 0,
double tolerance = 2 //
)
{
//
bool result = false;
//
score = 0;
dir = X_DIRECTION_NONE;
if (requiredScore < 0)
{
requiredScore = 0;
}
barIndex = NormalizeBarIndex(barIndex);
result = IsValid();
if (!result)
{
return result;
}
//
bool isBullish = IsKIFastBullish(barIndex) && IsKISlowBullish(barIndex);
bool isBearish = IsKIFastBearish(barIndex) && IsKISlowBearish(barIndex);
//
// Scoring ...
if (isBullish)
{
//
if (IsKIFastSwitchedToBullish(barIndex))
{
score += X_SCORE_MAX;
}
//
if (IsKISlowSwitchedToBullish(barIndex))
{
score += X_SCORE_NORMAL;
}
//
if (IsKIFastSwitchedOverLast(barIndex, tolerance))
{
score += X_SCORE_NORMAL;
}
else if (IsKIFastOverLast(barIndex, tolerance))
{
score += X_SCORE_MIN;
}
//
if (IsKISlowSwitchedOverLast(barIndex, tolerance))
{
score += X_SCORE_NORMAL;
}
else if (IsKISlowOverLast(barIndex, tolerance))
{
score += X_SCORE_MIN;
}
//
if (IsKISuperSlowSwitchedToBullish(barIndex))
{
score += X_SCORE_NORMAL;
}
else if (IsKISuperSlowBullish(barIndex))
{
score += X_SCORE_MIN;
}
//
if (IsKISuperSlowSwitchedOverLast(barIndex, tolerance))
{
score += X_SCORE_NORMAL;
}
else if (IsKISuperSlowOverLast(barIndex, tolerance))
{
score += X_SCORE_MIN;
}
}
else if (isBearish)
{
//
if (IsKIFastSwitchedToBearish(barIndex))
{
score += X_SCORE_MAX;
}
//
if (IsKISlowSwitchedToBearish(barIndex))
{
score += X_SCORE_NORMAL;
}
//
if (IsKIFastSwitchedUnderLast(barIndex, tolerance))
{
score += X_SCORE_NORMAL;
}
else if (IsKIFastUnderLast(barIndex, tolerance))
{
score += X_SCORE_MIN;
}
//
if (IsKISlowSwitchedUnderLast(barIndex, tolerance))
{
score += X_SCORE_NORMAL;
}
else if (IsKISlowUnderLast(barIndex, tolerance))
{
score += X_SCORE_MIN;
}
//
if (IsKISuperSlowSwitchedToBearish(barIndex))
{
score += X_SCORE_NORMAL;
}
else if (IsKISuperSlowBearish(barIndex))
{
score += X_SCORE_MIN;
}
//
if (IsKISuperSlowSwitchedUnderLast(barIndex, tolerance))
{
score += X_SCORE_NORMAL;
}
else if (IsKISuperSlowUnderLast(barIndex, tolerance))
{
score += X_SCORE_MIN;
}
}
//
dir = isBullish
? X_DIRECTION_BULLISH
: isBearish
? X_DIRECTION_BEARISH
: X_DIRECTION_NONE;
//
result = HasDirection(dir) &&
score >= requiredScore;
//
return result;
}
bool IsMAHasTrend(
double &score,
ENUM_X_DIRECTION &dir,
int barIndex = 0,
double requiredScore = 0,
double tolerance = 2 //
)
{
//
bool result = false;
//
score = 0;
dir = X_DIRECTION_NONE;
if (requiredScore < 0)
{
requiredScore = 0;
}
barIndex = NormalizeBarIndex(barIndex);
//
result = IsValid();
if (!result)
{
return result;
}
//
bool isBullish = IsMACrossoverBullish(barIndex);
bool isBearish = IsMACrossoverBearish(barIndex);
//
if (isBullish)
{
//
if (IsMACrossoverSwitchedToBullish(barIndex))
{
score += X_SCORE_MAX;
}
//
if (IsMAFastSwitchedToBullish(barIndex))
{
score += X_SCORE_MAX;
}
else if (IsMAFastBullish(barIndex))
{
score += X_SCORE_NORMAL;
}
//
if (IsMAFastSwitchedOverLast(barIndex, tolerance))
{
score += X_SCORE_NORMAL;
}
else if (IsMAFastOverLast(barIndex, tolerance))
{
score += X_SCORE_MIN;
}
//
if (IsMASlowSwitchedToBullish(barIndex))
{
score += X_SCORE_NORMAL;
}
else if (IsMASlowBullish(barIndex))
{
score += X_SCORE_MIN;
}
//
if (IsMASlowSwitchedOverLast(barIndex, tolerance))
{
score += X_SCORE_NORMAL;
}
else if (IsMASlowOverLast(barIndex, tolerance))
{
score += X_SCORE_MIN;
}
//
if (IsMASuperSlowSwitchedToBullish(barIndex))
{
score += X_SCORE_NORMAL;
}
else if (IsMASuperSlowBullish(barIndex))
{
score += X_SCORE_MIN;
}
//
if (IsMASuperSlowSwitchedOverLast(barIndex, tolerance))
{
score += X_SCORE_NORMAL;
}
else if (IsMASuperSlowOverLast(barIndex, tolerance))
{
score += X_SCORE_MIN;
}
}
else if (isBearish)
{
//
if (IsMACrossoverSwitchedToBearish(barIndex))
{
score += X_SCORE_MAX;
}
//
if (IsMAFastSwitchedToBearish(barIndex))
{
score += X_SCORE_MAX;
}
else if (IsMAFastBearish(barIndex))
{
score += X_SCORE_NORMAL;
}
//
if (IsMAFastSwitchedUnderLast(barIndex, tolerance))
{
score += X_SCORE_NORMAL;
}
else if (IsMAFastUnderLast(barIndex, tolerance))
{
score += X_SCORE_MIN;
}
//
if (IsMASlowSwitchedToBearish(barIndex))
{
score += X_SCORE_NORMAL;
}
else if (IsMASlowBullish(barIndex))
{
score += X_SCORE_MIN;
}
//
if (IsMASlowSwitchedUnderLast(barIndex, tolerance))
{
score += X_SCORE_NORMAL;
}
else if (IsMASlowUnderLast(barIndex, tolerance))
{
score += X_SCORE_MIN;
}
//
if (IsMASuperSlowSwitchedToBearish(barIndex))
{
score += X_SCORE_NORMAL;
}
else if (IsMASuperSlowBearish(barIndex))
{
score += X_SCORE_MIN;
}
//
if (IsMASuperSlowSwitchedUnderLast(barIndex, tolerance))
{
score += X_SCORE_NORMAL;
}
else if (IsMASuperSlowUnderLast(barIndex, tolerance))
{
score += X_SCORE_MIN;
}
}
//
dir = isBullish
? X_DIRECTION_BULLISH
: isBearish
? X_DIRECTION_BEARISH
: X_DIRECTION_NONE;
//
result = HasDirection(dir) &&
score >= requiredScore;
//
return result;
}
bool IsMomentumExists(
double &score,
ENUM_X_DIRECTION &dir,
int barIndex = 0,
double requiredScore = 0,
double tolerance = 2,
double bullishThreshold = 55,
double bearishThreshold = 45,
double overboughtThreshold = 70,
double oversoldThreshold = 30 //
)
{
//
bool result = false;
//
score = 0;
dir = X_DIRECTION_NONE;
if (requiredScore < 0)
{
requiredScore = 0;
}
barIndex = NormalizeBarIndex(barIndex);
bullishThreshold = NormalizeXDouble(bullishThreshold, 0, 100);
bearishThreshold = NormalizeXDouble(bearishThreshold, 0, 100);
oversoldThreshold = NormalizeXDouble(oversoldThreshold, 0, 100);
overboughtThreshold = NormalizeXDouble(overboughtThreshold, 0, 100);
//
result = IsValid();
if (!result)
{
return result;
}
//
bool isBullish = IsRSIBullish(barIndex, bullishThreshold, tolerance);
bool isBearish = IsRSIBearish(barIndex, bearishThreshold, tolerance);
//
if (isBullish)
{
//
if (!IsRSIOverbought(barIndex, overboughtThreshold, tolerance))
{
score += X_SCORE_NORMAL;
}
//
if (IsRSIOversold(barIndex, oversoldThreshold, tolerance))
{
score += X_SCORE_NORMAL;
}
//
if (IsRSISwitchedFromOversold(barIndex, oversoldThreshold, tolerance))
{
score += X_SCORE_NORMAL;
}
//
if (IsRSISwitchedToBullish(barIndex, bullishThreshold, tolerance))
{
score += X_SCORE_NORMAL;
}
//
if (IsRSISwitchedToRising(barIndex))
{
score += X_SCORE_NORMAL;
}
else if (IsRSIRising(barIndex))
{
score += X_SCORE_MIN;
}
//
if (IsRSISwitchedOverLast(barIndex, tolerance))
{
score += X_SCORE_NORMAL;
}
else if (IsRSIOverLast(barIndex, tolerance))
{
score += X_SCORE_MIN;
}
}
else if (isBearish)
{
//
if (!IsRSIOversold(barIndex, oversoldThreshold, tolerance))
{
score += X_SCORE_NORMAL;
}
//
if (IsRSIOverbought(barIndex, overboughtThreshold, tolerance))
{
score += X_SCORE_NORMAL;
}
//
if (IsRSISwitchedFromOverbought(barIndex, overboughtThreshold, tolerance))
{
score += X_SCORE_NORMAL;
}
//
if (IsRSISwitchedToBearish(barIndex, bearishThreshold, tolerance))
{
score += X_SCORE_NORMAL;
}
//
if (IsRSISwitchedToFalling(barIndex))
{
score += X_SCORE_NORMAL;
}
else if (IsRSIFalling(barIndex))
{
score += X_SCORE_MIN;
}
//
if (IsRSISwitchedUnderLast(barIndex, tolerance))
{
score += X_SCORE_NORMAL;
}
else if (IsRSIUnderLast(barIndex, tolerance))
{
score += X_SCORE_MIN;
}
}
//
dir = isBullish
? X_DIRECTION_BULLISH
: isBearish
? X_DIRECTION_BEARISH
: X_DIRECTION_NONE;
//
result = HasDirection(dir) &&
score >= requiredScore;
//
return result;
}
bool IsVolatilityExists(
double &score,
ENUM_X_DIRECTION &dir,
int barIndex = 0,
double requiredScore = 0,
double tolerance = 2,
ENUM_X_PRICE priceType = X_PRICE_CLOSE //
)
{
//
bool result = false;
//
score = 0;
dir = X_DIRECTION_NONE;
if (requiredScore < 0)
{
requiredScore = 0;
}
barIndex = NormalizeBarIndex(barIndex);
//
result = IsValid();
if (!result)
{
return result;
}
//
bool isBullish = IsATROverLast(barIndex, tolerance) || IsATRSmoothedOverLast(barIndex, tolerance);
bool isBearish = IsATRUnderLast(barIndex, tolerance) || IsATRSmoothedUnderLast(barIndex, tolerance);
//
if (isBullish)
{
//
if (IsATRBreakoutDown(barIndex, priceType))
{
score += X_SCORE_NORMAL;
}
//
if (!IsATRBreakoutUp(barIndex, priceType))
{
score += X_SCORE_MIN;
}
//
if (IsATRSwitchedOverLast(barIndex, tolerance))
{
score += X_SCORE_NORMAL;
}
else if (IsATROverLast(barIndex, tolerance))
{
score += X_SCORE_MIN;
}
//
if (IsATRSmoothedSwitchedOverLast(barIndex, tolerance))
{
score += X_SCORE_NORMAL;
}
else if (IsATRSmoothedOverLast(barIndex, tolerance))
{
score += X_SCORE_MIN;
}
//
if (IsVolatilitySwitchdToHigh(barIndex))
{
score += X_SCORE_NORMAL;
}
else if (IsVolatilityHigh(barIndex))
{
score += X_SCORE_MIN;
}
}
else if (isBearish)
{
//
if (!IsATRBreakoutDown(barIndex, priceType))
{
score += X_SCORE_NORMAL;
}
//
if (IsATRBreakoutUp(barIndex, priceType))
{
score += X_SCORE_MIN;
}
//
if (IsATRSwitchedUnderLast(barIndex, tolerance))
{
score += X_SCORE_NORMAL;
}
else if (IsATRUnderLast(barIndex, tolerance))
{
score += X_SCORE_MIN;
}
//
if (IsATRSmoothedSwitchedUnderLast(barIndex, tolerance))
{
score += X_SCORE_NORMAL;
}
else if (IsATRSmoothedUnderLast(barIndex, tolerance))
{
score += X_SCORE_MIN;
}
//
if (IsVolatilitySwitchdToLow(barIndex))
{
score += X_SCORE_NORMAL;
}
else if (IsVolatilityLow(barIndex))
{
score += X_SCORE_MIN;
}
}
//
dir = isBullish
? X_DIRECTION_BULLISH
: isBearish
? X_DIRECTION_BEARISH
: X_DIRECTION_NONE;
//
result = HasDirection(dir) &&
score >= requiredScore;
//
return result;
}
// #endregion
// #region Signalling Conditions ...
bool HasCompositeTrend(
double &score,
ENUM_X_DIRECTION &dir,
int barIndex = 0,
double requiredScore = 0,
double tolerance = 2,
ENUM_X_PRICE priceType = X_PRICE_CLOSE,
double bullishThreshold = 55,
double bearishThreshold = 45,
double overboughtThreshold = 70,
double oversoldThreshold = 30 //
)
{
//
bool result = false;
//
score = 0;
dir = X_DIRECTION_NONE;
barIndex = NormalizeBarIndex(barIndex);
//
result = IsValid();
if (!result)
{
return result;
}
//
bool hasKI, hasMa, hasMomentum, hasVolatility;
double kiScore, maScore, momentumScore, volatilityScore;
ENUM_X_DIRECTION kiDir, maDir, momentumDir, volatilityDdir;
//
hasKI = IsKIHasTrend(
kiScore,
kiDir,
barIndex,
1,
tolerance //
);
hasMa = IsMAHasTrend(
maScore,
maDir,
barIndex,
1,
tolerance //
);
hasVolatility = IsVolatilityExists(
volatilityScore,
volatilityDdir,
barIndex,
1,
tolerance,
priceType //
);
hasMomentum = IsMomentumExists(
momentumScore,
momentumDir,
barIndex,
1,
tolerance,
bullishThreshold,
bearishThreshold,
overboughtThreshold,
oversoldThreshold //
);
//
bool isBullish =
hasKI && IsXBullish(kiDir) &&
hasMa && IsXBullish(maDir) &&
hasMomentum && IsXBullish(momentumDir) &&
hasVolatility && IsXBullish(volatilityDdir);
//
bool isBearish =
hasKI && IsXBearish(kiDir) &&
hasMa && IsXBearish(maDir) &&
hasMomentum && IsXBearish(momentumDir) &&
hasVolatility && IsXBullish(volatilityDdir);
//
result = isBullish || isBearish;
if (!result)
{
return result;
}
//
// Summarizing Scores ...
score = (kiScore + maScore + momentumScore + volatilityScore);
result =
result &&
score >= requiredScore;
if (result)
{
//
dir = isBullish
? X_DIRECTION_BULLISH
: isBearish
? X_DIRECTION_BEARISH
: X_DIRECTION_NONE;
}
//
result = result &&
HasDirection(dir);
//
return result;
}
// #endregion