last ...
This commit is contained in:
@@ -1863,6 +1863,64 @@ class XCX121XKIPOIDetector : public XCMarketPatternDetector
|
||||
XClean(tmpResistances);
|
||||
}
|
||||
|
||||
bool HasStructure(
|
||||
int barIndex = 0,
|
||||
string forSymbol = NULL,
|
||||
ENUM_TIMEFRAMES forMinorPeriod = NULL,
|
||||
ENUM_TIMEFRAMES forMajorPeriod = NULL,
|
||||
int loopback = 50,
|
||||
int minorValidation = 7,
|
||||
int majorValidation = 14,
|
||||
int minimumRetests = 2,
|
||||
double retestThreshold = 10,
|
||||
int retestLoopback = 100 //
|
||||
)
|
||||
{
|
||||
//
|
||||
XBoxZone supports[];
|
||||
XBoxZone resistances[];
|
||||
XBoxZone minorSupport;
|
||||
XBoxZone majorSupport;
|
||||
XBoxZone minorResistance;
|
||||
XBoxZone majorResistance;
|
||||
|
||||
//
|
||||
GetCurrentStructure(
|
||||
supports,
|
||||
resistances,
|
||||
minorSupport,
|
||||
majorSupport,
|
||||
minorResistance,
|
||||
majorResistance,
|
||||
barIndex,
|
||||
forSymbol,
|
||||
forMinorPeriod,
|
||||
forMajorPeriod,
|
||||
loopback,
|
||||
minorValidation,
|
||||
majorValidation,
|
||||
minimumRetests,
|
||||
retestThreshold,
|
||||
retestLoopback //
|
||||
);
|
||||
|
||||
//
|
||||
bool result =
|
||||
majorSupport.IsValid() &&
|
||||
majorResistance.IsValid();
|
||||
|
||||
//
|
||||
XClean(supports);
|
||||
XClean(resistances);
|
||||
minorSupport.Clean();
|
||||
majorSupport.Clean();
|
||||
minorResistance.Clean();
|
||||
majorResistance.Clean();
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
void RefineStructure(
|
||||
XBoxZone &supports[],
|
||||
XBoxZone &resistances[],
|
||||
@@ -2164,6 +2222,427 @@ class XCX121XKIPOIDetector : public XCMarketPatternDetector
|
||||
zone.from = zone.breakAt;
|
||||
}
|
||||
}
|
||||
|
||||
bool DetectRecentSwings(
|
||||
XBoxZone &swingHigh,
|
||||
XBoxZone &swingLow,
|
||||
int barIndex = 0,
|
||||
int swingsValidationLength = 50,
|
||||
int loopback = 500,
|
||||
ENUM_TIMEFRAMES forPeriod = NULL,
|
||||
bool forceRefineZones = true //
|
||||
)
|
||||
{
|
||||
//
|
||||
swingLow.Clean();
|
||||
swingHigh.Clean();
|
||||
|
||||
//
|
||||
loopback = NormalizeInt(loopback, 5);
|
||||
barIndex = kiParser.NormalizeBarIndex(barIndex);
|
||||
swingsValidationLength = NormalizeInt(swingsValidationLength, 5);
|
||||
if (!IsXValid(forPeriod))
|
||||
{
|
||||
forPeriod = period;
|
||||
}
|
||||
|
||||
//
|
||||
XOHCL iBar;
|
||||
int iIDX = -1;
|
||||
double low = 0;
|
||||
double high = 0;
|
||||
int lowIDX = -1;
|
||||
int highIDX = -1;
|
||||
bool has = false;
|
||||
double iValue = 0;
|
||||
datetime lowAt = NULL;
|
||||
datetime highAt = NULL;
|
||||
for (int i = barIndex; i < barIndex + loopback; i++)
|
||||
{
|
||||
//
|
||||
has = iBar.Init(symbol, forPeriod, i);
|
||||
if (!has)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
//
|
||||
iIDX = iBar.FindLowestIndex(swingsValidationLength, MODE_LOW);
|
||||
has = IsValidIndex(iIDX);
|
||||
if (has)
|
||||
{
|
||||
//
|
||||
iValue = iLow(iBar.symbol, iBar.period, iIDX);
|
||||
|
||||
//
|
||||
// Check Can Set Low ...
|
||||
has = (!NotEmptyZero(low) ||
|
||||
(NotEmptyZero(low) && iValue < low)) &&
|
||||
IsValidSwing(
|
||||
iValue,
|
||||
iIDX,
|
||||
barIndex,
|
||||
iBar.symbol,
|
||||
iBar.period,
|
||||
X_SWING_LOW //
|
||||
);
|
||||
if (has)
|
||||
{
|
||||
//
|
||||
low = iValue;
|
||||
lowIDX = iIDX;
|
||||
lowAt = iBar.time;
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
iIDX = iBar.FindHighestIndex(swingsValidationLength, MODE_HIGH);
|
||||
has = IsValidIndex(iIDX);
|
||||
if (has)
|
||||
{
|
||||
//
|
||||
iValue = iHigh(iBar.symbol, iBar.period, iIDX);
|
||||
|
||||
//
|
||||
// Check Can Set High ...
|
||||
has = (!NotEmptyZero(high) ||
|
||||
(NotEmptyZero(high) && iValue > high)) &&
|
||||
IsValidSwing(
|
||||
iValue,
|
||||
iIDX,
|
||||
barIndex,
|
||||
iBar.symbol,
|
||||
iBar.period,
|
||||
X_SWING_HIGH //
|
||||
);
|
||||
if (has)
|
||||
{
|
||||
//
|
||||
high = iValue;
|
||||
highIDX = iIDX;
|
||||
highAt = iBar.time;
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
iBar.Clean();
|
||||
}
|
||||
|
||||
//
|
||||
// Recent Low Swing ...
|
||||
has =
|
||||
IsXValid(lowAt) &&
|
||||
NotEmptyZero(low) &&
|
||||
IsValidIndex(lowIDX);
|
||||
if (has)
|
||||
{
|
||||
//
|
||||
has = iBar.Init(symbol, forPeriod, lowIDX);
|
||||
has = has &&
|
||||
swingLow.Init(
|
||||
iBar.symbol,
|
||||
iBar.period,
|
||||
iBar.GetDown(),
|
||||
low,
|
||||
GetBarTime(iBar.symbol, iBar.period, lowIDX + swingsValidationLength - 1),
|
||||
GetBarTime(iBar.symbol, iBar.period, barIndex),
|
||||
X_DIRECTION_BULLISH,
|
||||
ToXString(X_BAR_PATTERN_LOW),
|
||||
lowAt //
|
||||
);
|
||||
if (has && forceRefineZones)
|
||||
{
|
||||
RefineZone(swingLow, 500, 5, X_PRICE_CLOSE);
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
// Recent High Swing ...
|
||||
has =
|
||||
IsXValid(highAt) &&
|
||||
NotEmptyZero(high) &&
|
||||
IsValidIndex(highIDX);
|
||||
if (has)
|
||||
{
|
||||
//
|
||||
has = iBar.Init(symbol, forPeriod, highIDX);
|
||||
has = has &&
|
||||
swingHigh.Init(
|
||||
iBar.symbol,
|
||||
iBar.period,
|
||||
high,
|
||||
iBar.GetUp(),
|
||||
GetBarTime(iBar.symbol, iBar.period, lowIDX + swingsValidationLength - 1),
|
||||
GetBarTime(iBar.symbol, iBar.period, barIndex),
|
||||
X_DIRECTION_BEARISH,
|
||||
ToXString(X_BAR_PATTERN_HIGH),
|
||||
highAt //
|
||||
);
|
||||
if (has && forceRefineZones)
|
||||
{
|
||||
RefineZone(swingHigh, 500, 5, X_PRICE_CLOSE);
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
bool result = swingLow.IsValid() &&
|
||||
swingHigh.IsValid();
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
bool HasOrderFlow(
|
||||
XBoxZone &flow[],
|
||||
int barIndex = 0,
|
||||
int flowValidationLength = 5,
|
||||
ENUM_X_DIRECTION flowDir = X_DIRECTION_NONE,
|
||||
int loopback = 50,
|
||||
string forSymbol = NULL,
|
||||
ENUM_TIMEFRAMES forPeriod = NULL,
|
||||
ENUM_X_BOUNDARY_PRICE priceType = X_BOUNDARY_PRICE_HIGH_LOW //
|
||||
)
|
||||
{
|
||||
//
|
||||
bool result = false;
|
||||
|
||||
//
|
||||
XClean(flow);
|
||||
|
||||
//
|
||||
// Validate ...
|
||||
result =
|
||||
IsXValid(priceType);
|
||||
if (!result)
|
||||
{
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Normalizing Data ...
|
||||
if (!IsXValid(forSymbol))
|
||||
{
|
||||
forSymbol = symbol;
|
||||
}
|
||||
if (!IsXValid(forPeriod))
|
||||
{
|
||||
forPeriod = period;
|
||||
}
|
||||
loopback = NormalizeInt(loopback, 5);
|
||||
barIndex = kiParser.NormalizeBarIndex(barIndex);
|
||||
flowValidationLength = NormalizeInt(flowValidationLength, 2);
|
||||
|
||||
//
|
||||
// Handle Works ...
|
||||
|
||||
//
|
||||
XOHCL iBar;
|
||||
int iIndex = -1;
|
||||
bool has = false;
|
||||
XBoxZone tmpZone;
|
||||
double iPrice = 0;
|
||||
ENUM_X_PRICE iPriceType;
|
||||
bool isBullish = !HasDirection(flowDir) || IsXBullish(flowDir);
|
||||
bool isBearish = !HasDirection(flowDir) || IsXBearish(flowDir);
|
||||
|
||||
//
|
||||
// Looping Reversal ...
|
||||
int start = barIndex + loopback;
|
||||
int end = barIndex;
|
||||
for (int i = start; i > end; i--)
|
||||
{
|
||||
//
|
||||
has = iBar.Init(forSymbol, forPeriod, i);
|
||||
if (!has)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
//
|
||||
// Check iBar is Low Swing ...
|
||||
if (isBullish)
|
||||
{
|
||||
//
|
||||
iPriceType = priceType == X_BOUNDARY_PRICE_HIGH_LOW
|
||||
? X_PRICE_LOW
|
||||
: X_PRICE_DOWN;
|
||||
iPrice = iBar.GetPrice(iPriceType);
|
||||
has = iPrice == iBar.FindLowest(iIndex, flowValidationLength, iPriceType);
|
||||
has = has &&
|
||||
IsValidSwing(
|
||||
iPrice,
|
||||
iBar.Index(),
|
||||
barIndex,
|
||||
iBar.symbol,
|
||||
iBar.period,
|
||||
X_SWING_LOW //
|
||||
);
|
||||
if (has)
|
||||
{
|
||||
//
|
||||
// Flow Detected ...
|
||||
tmpZone.Clean();
|
||||
iPriceType = priceType == X_BOUNDARY_PRICE_HIGH_LOW
|
||||
? X_PRICE_DOWN
|
||||
: X_PRICE_UP;
|
||||
has = tmpZone.Init(
|
||||
iBar.symbol,
|
||||
iBar.period,
|
||||
iBar.GetPrice(iPriceType),
|
||||
iPrice,
|
||||
iBar.time,
|
||||
GetBarTime(iBar.symbol, iBar.period, barIndex),
|
||||
X_DIRECTION_BULLISH,
|
||||
ToXString(X_BAR_PATTERN_LOW) //
|
||||
);
|
||||
if (has)
|
||||
{
|
||||
//
|
||||
AddIfNotExists(
|
||||
tmpZone,
|
||||
flow //
|
||||
);
|
||||
|
||||
//
|
||||
tmpZone.Clean();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
// Check iBar is High Swing ...
|
||||
if (isBearish)
|
||||
{
|
||||
//
|
||||
iPriceType = priceType == X_BOUNDARY_PRICE_HIGH_LOW
|
||||
? X_PRICE_HIGH
|
||||
: X_PRICE_UP;
|
||||
iPrice = iBar.GetPrice(iPriceType);
|
||||
has = iPrice == iBar.FindHighest(iIndex, flowValidationLength, iPriceType);
|
||||
has = has &&
|
||||
IsValidSwing(
|
||||
iPrice,
|
||||
iBar.Index(),
|
||||
barIndex,
|
||||
iBar.symbol,
|
||||
iBar.period,
|
||||
X_SWING_HIGH //
|
||||
);
|
||||
if (has)
|
||||
{
|
||||
//
|
||||
// Flow Detected ...
|
||||
tmpZone.Clean();
|
||||
iPriceType = priceType == X_BOUNDARY_PRICE_HIGH_LOW
|
||||
? X_PRICE_UP
|
||||
: X_PRICE_DOWN;
|
||||
has = tmpZone.Init(
|
||||
iBar.symbol,
|
||||
iBar.period,
|
||||
iPrice,
|
||||
iBar.GetPrice(iPriceType),
|
||||
iBar.time,
|
||||
GetBarTime(iBar.symbol, iBar.period, barIndex),
|
||||
X_DIRECTION_BEARISH,
|
||||
ToXString(X_BAR_PATTERN_HIGH) //
|
||||
);
|
||||
if (has)
|
||||
{
|
||||
//
|
||||
AddIfNotExists(
|
||||
tmpZone,
|
||||
flow //
|
||||
);
|
||||
|
||||
//
|
||||
tmpZone.Clean();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
iBar.Clean();
|
||||
tmpZone.Clean();
|
||||
}
|
||||
|
||||
//
|
||||
result = HasChild(flow);
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
bool IsValidSwing(
|
||||
double price,
|
||||
int swingIDX,
|
||||
int barIndex = 0,
|
||||
string forSymbol = NULL,
|
||||
ENUM_TIMEFRAMES forPeriod = NULL,
|
||||
ENUM_X_SWING_TYPE swingType = X_SWING_NONE //
|
||||
)
|
||||
{
|
||||
//
|
||||
bool result = false;
|
||||
|
||||
//
|
||||
result =
|
||||
NotEmptyZero(price) &&
|
||||
IsXValid(swingType) &&
|
||||
IsValidIndex(swingIDX) &&
|
||||
swingIDX >= barIndex;
|
||||
if (!result)
|
||||
{
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
if (!IsXValid(forSymbol))
|
||||
{
|
||||
forSymbol = symbol;
|
||||
}
|
||||
if (!IsXValid(forPeriod))
|
||||
{
|
||||
forPeriod = period;
|
||||
}
|
||||
barIndex = kiParser.NormalizeBarIndex(barIndex);
|
||||
|
||||
//
|
||||
XOHCL iBar;
|
||||
bool has = false;
|
||||
for (int i = barIndex; i <= (swingIDX - barIndex); i++)
|
||||
{
|
||||
//
|
||||
has = iBar.Init(forSymbol, forPeriod, i);
|
||||
if (!has)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
//
|
||||
// Check Price Break ...
|
||||
has =
|
||||
(swingType == X_SWING_LOW &&
|
||||
iBar.low < price) ||
|
||||
(swingType == X_SWING_HIGH &&
|
||||
iBar.high > price);
|
||||
if (has)
|
||||
{
|
||||
break;
|
||||
}
|
||||
|
||||
//
|
||||
iBar.Clean();
|
||||
}
|
||||
|
||||
//
|
||||
result = !has && !iBar.IsValid();
|
||||
|
||||
//
|
||||
iBar.Clean();
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
// #endregion
|
||||
|
||||
// #region VolatilitySwitchedHigh ...
|
||||
@@ -2196,12 +2675,29 @@ class XCX121XKIPOIDetector : public XCMarketPatternDetector
|
||||
// #endregion
|
||||
|
||||
// #region Bar Patterns ...
|
||||
/*
|
||||
* Check Recently Pattern Zone is Touched or not ...
|
||||
*
|
||||
* @param zone: XBoxZone, Touched Zone ...
|
||||
* @param patterns: ENUM_X_BAR_PATTERN, Allowed to Check Patterns ...
|
||||
* @param patternsDir: ENUM_X_DIRECTION, Allowed Directions ...
|
||||
* @param price: double, a Price to Check Toch or Reject ...
|
||||
* @param barIndex: int, Bar Index to Start Checking ...
|
||||
* @param loopback: int, Loopback for Pattern Formations ...
|
||||
* @param threshold: double, threshold for Pattern touch ...
|
||||
* @param forPeriod: ENUM_TIMEFRAMES, Time Frame to Check Patterns ...
|
||||
* @param forDir: ENUM_X_DIRECTION, Directions for Pattern's Formation Check ...
|
||||
*
|
||||
* @return ( bool )
|
||||
*/
|
||||
bool HasRecentPatternTouched(
|
||||
XBoxZone &zone,
|
||||
ENUM_X_BAR_PATTERN &patterns[],
|
||||
ENUM_X_DIRECTION &patternsDir[],
|
||||
double price,
|
||||
int barIndex = 0,
|
||||
int loopback = 5,
|
||||
int threshold = 5,
|
||||
double threshold = 5,
|
||||
ENUM_TIMEFRAMES forPeriod = NULL,
|
||||
ENUM_X_DIRECTION forDir = X_DIRECTION_NONE //
|
||||
)
|
||||
@@ -2214,7 +2710,11 @@ class XCX121XKIPOIDetector : public XCMarketPatternDetector
|
||||
|
||||
//
|
||||
// Validate ...
|
||||
result = NotEmptyZero(price);
|
||||
result =
|
||||
HasChild(patterns) &&
|
||||
NotEmptyZero(price) &&
|
||||
HasChild(patternsDir) &&
|
||||
ArraySize(patterns) == ArraySize(patternsDir);
|
||||
if (!result)
|
||||
{
|
||||
return result;
|
||||
@@ -2244,7 +2744,21 @@ class XCX121XKIPOIDetector : public XCMarketPatternDetector
|
||||
//
|
||||
// Preparing Pattern Analysis Config ...
|
||||
iConfig.Default();
|
||||
iConfig.FullPattern();
|
||||
|
||||
//
|
||||
Copy(
|
||||
patterns,
|
||||
iConfig.allowedPatterns //
|
||||
);
|
||||
Copy(
|
||||
patternsDir,
|
||||
iConfig.allowedDirs //
|
||||
);
|
||||
|
||||
//
|
||||
// XAUUSD ...
|
||||
iConfig.AddPattern(X_BAR_PATTERN_FVG);
|
||||
iConfig.AddPattern(X_BAR_PATTERN_PIERCING);
|
||||
|
||||
//
|
||||
// Looping Back ...
|
||||
|
||||
Reference in New Issue
Block a user