This commit is contained in:
2025-10-04 16:12:32 +03:30
parent cc4ccdd1fa
commit a185fb3c8a
5 changed files with 1429 additions and 22 deletions
+526 -1
View File
@@ -23,6 +23,7 @@
//
// Imports ...
#include "../Classes/x-saherelm.x-helper.class.mq5"
#include "../Classes/x-saherelm.x-market.pattern.class.mq5"
#include "../Libraries/x-saherelm.x-poi.extensions.lib.mq5"
#include "../Libraries/x-saherelm.x-poi.lib.mq5"
@@ -488,18 +489,23 @@ class XCXFIMAHelper : public XCBaseHelper
public:
//
// Props ...
XCMarketPatternDetector *patternDetector;
//
// Constructors ...
XCXFIMAHelper()
: XCBaseHelper(_Symbol, _Period)
{
patternDetector = new XCMarketPatternDetector();
}
//
// Deconstructor ...
~XCXFIMAHelper()
{
//
delete patternDetector;
ZeroMemory(patternDetector);
}
//
@@ -1519,6 +1525,98 @@ class XCXFIMAHelper : public XCBaseHelper
return result;
}
bool GetBoundaryValues(
double &min,
double &max,
int barIndex = 0 //
)
{
//
bool result = false;
//
// Prepare ...
min = EMPTY_VALUE;
max = EMPTY_VALUE;
//
// Normalize ...
barIndex = NormalizeBarIndex(barIndex);
//
// Validate ...
result = IsValid();
if (!result)
{
return result;
}
//
double fast = GetMAFast(barIndex);
double slow = GetMASlow(barIndex);
//
double maBondUpper = GetMABondUpper(barIndex);
double maBondLower = GetMABondLower(barIndex);
//
double pbBondUpper = GetPBBondUpper(barIndex);
double pbBondLower = GetPBBondLower(barIndex);
//
double hkBondUpper = GetHKBondUpper(barIndex);
double hkBondLower = GetHKBondLower(barIndex);
//
double fiboUpper = GetFiboUpper(barIndex);
double fiboLower = GetFiboLower(barIndex);
double fiboMiddle = GetFiboMiddle(barIndex);
//
result =
NotEmptyZero(fast) &&
NotEmptyZero(slow) &&
NotEmptyZero(fiboLower) &&
NotEmptyZero(fiboUpper) &&
NotEmptyZero(fiboMiddle) &&
NotEmptyZero(maBondUpper) &&
NotEmptyZero(maBondLower) &&
NotEmptyZero(pbBondUpper) &&
NotEmptyZero(pbBondLower) &&
NotEmptyZero(hkBondUpper) &&
NotEmptyZero(hkBondLower);
if (!result)
{
return result;
}
//
double values[11] = {
fast,
slow,
fiboLower,
fiboUpper,
fiboMiddle,
maBondUpper,
maBondLower,
pbBondUpper,
pbBondLower,
hkBondUpper,
hkBondLower //
};
min = GetMin(values);
max = GetMax(values);
//
result =
NotEmptyZero(min) &&
NotEmptyZero(max) &&
min < max;
//
return result;
}
//
// Tools ...
@@ -2956,8 +3054,11 @@ class XCXFIMAHelper : public XCBaseHelper
*
* @param zones: XBoxZone, reference to Collection for holding Detected Zones ...
* @param barIndex: int, Specified Start Looking Bar Index ...
* @param onlyValidZones: bool, Only Validation Zones ...
* @param requiredNumberOfZones: int, Specified how many zones looking for ...
* @param shadowMultiplier: double, a valid zone's Shadow side multiplier ...
* @param validationStrength: double, Validation Strength ...
* @param validationLength: int, Validation Length ...
* @param maxAllowedLoopbackLength: int, Specified Max Allowed Looping back trhough Bars for Detection ...
*
* @return ( int )
@@ -2968,6 +3069,7 @@ class XCXFIMAHelper : public XCBaseHelper
bool onlyValidZones = false,
int requiredNumberOfZones = 50,
double shadowMultiplier = 4,
double validationStrength = 1,
int validationLength = 7,
int maxAllowedLoopbackLength = 1500 //
)
@@ -2984,6 +3086,7 @@ class XCXFIMAHelper : public XCBaseHelper
barIndex = NormalizeBarIndex(barIndex);
validationLength = NormalizeInt(validationLength, 3);
shadowMultiplier = NormalizeDouble(shadowMultiplier, 2);
validationStrength = NormalizeDouble(validationStrength, 1);
requiredNumberOfZones = NormalizeInt(requiredNumberOfZones, 5);
maxAllowedLoopbackLength = NormalizeInt(maxAllowedLoopbackLength, 50);
@@ -3101,7 +3204,7 @@ class XCXFIMAHelper : public XCBaseHelper
? iBar.low
: iBar.GetUp();
iBox.type =
(isBullish ? "XFIMSup" : "XFIMARes") + "_" +
(isBullish ? "XFIMA_Support" : "XFIMA_Resistance") + "_" +
ToXString(NormalizePrice(iBox.upper, iBox.symbol)) + "_" +
ToXString(NormalizePrice(iBox.lower, iBox.symbol));
@@ -3148,7 +3251,45 @@ class XCXFIMAHelper : public XCBaseHelper
//
// Validate Zone Length ...
has = iBox.IsValid() &&
(validationStrength >= 1
? iBox.GetRange() >= validationStrength * GetPoints(iBox.symbol)
: true) &&
(iBox.FromIndex() - iBox.AtIndex() >= validationLength);
//
// Validate Zone State ...
if (has)
{
//
// Cleanup Bar ...
iBar.Clean();
//
// Loopingh through At Index ...
for (int i = iBox.ToIndex(); i < iBox.AtIndex(); i++)
{
//
// Initialized Indexed Bar ...
has = bar.BarAt(i, iBar);
if (!has)
{
break;
}
//
// Validate Bar ...
has =
iBox.IsBullish()
? iBar.low > iBox.lower
: iBar.high < iBox.upper;
if (!has)
{
break;
}
}
}
//
if (has)
{
//
@@ -3174,6 +3315,7 @@ class XCXFIMAHelper : public XCBaseHelper
{
XClean(zones);
}
bar.Clean();
iBar.Clean();
iBox.Clean();
@@ -3181,6 +3323,389 @@ class XCXFIMAHelper : public XCBaseHelper
return result;
}
int DetecteXFIMAPivots(
XPivot &pivots[],
int barIndex = 0,
int requiredNumberOfPivots = 50,
int validationLength = 7,
int maxAllowedLoopbackLength = 1500, //
//
// PV ...
int pvValidationLength = 7,
//
// Momentum ...
int momentumBarValidationLength = 3,
double momentumBarApprovedMultiplier = 3,
//
// TrueGap ...
double trueGapApprovedStrength = 2,
//
// Pin ...
double pinBarShadowApprovedMultiplier = 3,
double pinBarRangeMultiplier = 4,
bool pinBarForceDirection = false,
//
// Flag ...
int flagPatternPullbackLength = 3 //
)
{
//
int result = 0;
//
// Prepare ...
XClean(pivots);
//
// Normalize ...
barIndex = NormalizeBarIndex(barIndex);
validationLength = NormalizeInt(validationLength, 1);
requiredNumberOfPivots = NormalizeInt(requiredNumberOfPivots, 5);
maxAllowedLoopbackLength = NormalizeInt(maxAllowedLoopbackLength, 50);
//
pvValidationLength = NormalizeInt(pvValidationLength, 2);
//
momentumBarValidationLength = NormalizeInt(momentumBarValidationLength, 2);
momentumBarApprovedMultiplier = NormalizeDouble(momentumBarApprovedMultiplier, 1);
//
trueGapApprovedStrength = NormalizeDouble(trueGapApprovedStrength, 1);
//
pinBarRangeMultiplier = NormalizeDouble(pinBarRangeMultiplier, 4);
pinBarShadowApprovedMultiplier = NormalizeDouble(pinBarShadowApprovedMultiplier, 3);
//
flagPatternPullbackLength = NormalizeInt(flagPatternPullbackLength, 3);
//
// Validate ...
bool has = IsValid();
if (!has)
{
return result;
}
//
XOHCL iBar;
XOHCL tmpBar;
XPivot iPivot;
string iPrefix = NULL;
ENUM_X_DIRECTION iDir;
int idx = barIndex - 1;
double iMin = EMPTY_VALUE;
double iMax = EMPTY_VALUE;
double iValue = EMPTY_VALUE;
ENUM_X_PIVOT_TYPE iType = X_PIVOT_TYPE_NONE;
int end = barIndex + maxAllowedLoopbackLength;
while (
idx < end &&
ArraySize(pivots) < requiredNumberOfPivots)
{
//
idx++;
//
iBar.Clean();
iPivot.Clean();
tmpBar.Clean();
iPrefix = NULL;
iDir = X_DIRECTION_NONE;
//
has = iBar.Init(
mSymbol,
mPeriod,
idx //
);
if (!has)
{
break;
}
//
// Pivots List ...
//
// PV ...
has = patternDetector.IsPV(
iBar,
iDir,
pvValidationLength //
);
if (has)
{
//
iPrefix =
IsXBullish(iDir)
? "XLow"
: "XHigh";
}
//
// Momentum Bar ...
if (!has)
{
//
has = patternDetector.IsMomentumBar(
iBar,
iDir,
momentumBarValidationLength,
momentumBarApprovedMultiplier //
);
if (has)
{
iPrefix = "XMomentum";
}
}
//
// Engulf Bar ...
if (!has)
{
//
has = patternDetector.IsEngulfedBar(
iBar,
iDir //
);
if (has)
{
iPrefix = "XEngulfed";
}
}
//
// True Gap ...
if (!has)
{
//
has = patternDetector.IsTrueGapedBar(
iBar,
iDir,
trueGapApprovedStrength //
);
if (has)
{
iPrefix = "XTrueGap";
}
}
//
// Pin Bar ...
if (!has)
{
//
has = patternDetector.IsPinnedBar(
iBar,
iDir,
pinBarShadowApprovedMultiplier,
pinBarRangeMultiplier,
pinBarForceDirection //
);
if (has)
{
iPrefix = "XPinned";
}
}
//
// Patterns ...
//
// Star Pattern ...
if (!has)
{
//
has = patternDetector.IsStartPattern(
iBar,
iDir //
);
if (has)
{
iPrefix = "XStar";
}
}
//
// Piercing Pattern ...
if (!has)
{
//
has = patternDetector.IsPiercingPattern(
iBar,
iDir //
);
if (has)
{
iPrefix = "XPiercing";
}
}
//
// Rising Pattern ...
if (!has)
{
//
has = patternDetector.IsRisingPattern(
iBar,
iDir //
);
if (has)
{
iPrefix = "XRising";
}
}
//
// Flag Pattern ...
if (!has)
{
//
has = patternDetector.IsFlagPattern(
iBar,
iDir,
tmpBar,
flagPatternPullbackLength //
);
if (has)
{
iPrefix = "XFlag";
}
}
//
// Signal Key Pattern ...
if (!has)
{
//
has = patternDetector.IsSignalKeyBarPattern(
iBar,
iDir,
pinBarShadowApprovedMultiplier,
pinBarRangeMultiplier,
pinBarForceDirection //
);
if (has)
{
iPrefix = "XSignalKey";
}
}
//
if (!has)
{
continue;
}
// //
// // Validate Pivot Length ...
// // Validate Pivot vs XFIMA Values ...
// for (int i = iBar.Index(); i < iBar.Index() + validationLength; i++)
// {
// //
// tmpBar.Clean();
// has = iBar.BarAt(i, tmpBar);
// if (!has)
// {
// break;
// }
// //
// iMin = EMPTY_VALUE;
// iMax = EMPTY_VALUE;
// has = GetBoundaryValues(
// iMin,
// iMax,
// i //
// );
// //
// // Validate Bar vs TmpBar and Also Boundary Values ...
// has =
// has &&
// (IsXBullish(iDir)
// ?
// // tmpBar.low < iMin &&
// (tmpBar.low > iBar.low ||
// tmpBar.GetDown() || iBar.GetDown())
// :
// // tmpBar.high > iMax &&
// (tmpBar.high < iBar.high ||
// tmpBar.GetUp() < iBar.GetUp()));
// if (!has)
// {
// break;
// }
// //
// iValue = IsXBullish(iDir)
// ? iBar.low
// : iBar.high;
// //
// iType = IsXBullish(iDir)
// ? X_PIVOT_TYPE_VALE
// : X_PIVOT_TYPE_PEAK;
// //
// tmpBar.Clean();
// }
//
has = IsXValid(iPrefix);
if (has)
{
//
iValue = IsXBullish(iDir)
? iBar.low
: iBar.high;
//
iType = IsXBullish(iDir)
? X_PIVOT_TYPE_VALE
: X_PIVOT_TYPE_PEAK;
//
// Preparing Pivot ...
has = iPivot.Init(
iValue,
iBar.time,
iBar.symbol,
iDir,
iBar.period,
iType //
);
if (has)
{
//
iPivot.prefix = iPrefix;
//
AddIfNotExists(
iPivot,
pivots //
);
}
}
//
}
//
// Cleanup Resources ...
iBar.Clean();
iPivot.Clean();
tmpBar.Clean();
//
result = ArraySize(pivots);
//
return result;
}
//
// Values Retrievers ...