This commit is contained in:
2025-09-30 03:53:35 +03:30
parent ab38b28fab
commit 32b218afbc
7 changed files with 674 additions and 254 deletions
+227 -146
View File
@@ -1260,8 +1260,8 @@ class XCXFIMAHelper : public XCBaseHelper
* @param pivots: XPivot, refrence Collection to hold Extracted pivots ...
* @param barIndex: int, Specified Bar Index ...
* @param requiredNumberOFPivots: int, Specified which Number of Pivots must be Extracted ...
* @param maxAllowedLoopbackLength: int, Specified Maximum Loopback Length for Pivot Extraction ...
* @param validationLength: int, Specified Pivots Validation Length ignore if <= 0 ...
* @param maxAllowedLoopbackLength: int, Specified Maximum Loopback Length for Pivot Extraction ...
*
* @return ( int )
*/
@@ -1269,8 +1269,8 @@ class XCXFIMAHelper : public XCBaseHelper
XPivot &pivots[],
int barIndex = 0,
int requiredNumberOFPivots = 50,
int maxAllowedLoopbackLength = 1500,
int validationLength = 0 //
int validationLength = 0,
int maxAllowedLoopbackLength = 1500 //
)
{
//
@@ -1295,13 +1295,15 @@ class XCXFIMAHelper : public XCBaseHelper
}
//
XOHCL iBar;
XOHCL pBar;
double fast[];
double slow[];
XPivot iPivot;
int count = 0;
double upper[];
double lower[];
bool has = false;
double tmpFastMaBuffer[];
double tmpSlowMaBuffer[];
int idx = barIndex - 1;
datetime iPivotTime = NULL;
string symbol = GetSymbol();
double iFValue = EMPTY_VALUE;
double pFValue = EMPTY_VALUE;
@@ -1322,11 +1324,11 @@ class XCXFIMAHelper : public XCBaseHelper
//
// Prepare ...
iBar.Clean();
pBar.Clean();
iPivot.Clean();
SpecifiedClean(tmpFastMaBuffer);
SpecifiedClean(tmpSlowMaBuffer);
SpecifiedClean(fast);
SpecifiedClean(slow);
SpecifiedClean(upper);
SpecifiedClean(lower);
//
// Ignore First Item ...
@@ -1335,56 +1337,28 @@ class XCXFIMAHelper : public XCBaseHelper
continue;
}
//
// Initialize Bar ...
has = iBar.Init(
symbol,
period,
idx //
);
has =
has &&
iBar.GetPreviousBar(pBar);
if (!has)
{
continue;
}
//
// Reading Buffer ...
//
// FAST ...
CopyBuffer(
mHandler, // Handler ...
XFIMA_MA_FAST_LINE, // Handler Buffer Number ...
idx, // Bar Index ...
2, // Number of Requirements ...
tmpFastMaBuffer // Buffer ...
count = ReadMAValues(
fast,
slow,
upper,
lower,
idx,
2 //
);
ArraySetAsSeries(tmpFastMaBuffer, true);
//
// SLOW ...
CopyBuffer(
mHandler, // Handler ...
XFIMA_MA_SLOW_LINE, // Handler Buffer Number ...
idx, // Bar Index ...
2, // Number of Requirements ...
tmpSlowMaBuffer // Buffer ...
);
ArraySetAsSeries(tmpSlowMaBuffer, true);
has = IsValidSize(count);
//
// Reading Values ...
//
iFValue = tmpFastMaBuffer[0];
pFValue = tmpFastMaBuffer[1];
iFValue = fast[0];
pFValue = fast[1];
//
iSValue = tmpSlowMaBuffer[0];
pSValue = tmpSlowMaBuffer[1];
iSValue = slow[0];
pSValue = slow[1];
//
// Validate Value ...
@@ -1432,81 +1406,19 @@ class XCXFIMAHelper : public XCBaseHelper
validationLength > 0)
{
//
// Looping to Validate ...
double tmp[];
bool isValid = false;
int start = pBar.Index();
double iFast = EMPTY_VALUE;
double iSlow = EMPTY_VALUE;
int end = start + validationLength;
for (int i = start; i < end; i++)
{
//
// Initialize iBar ...
isValid = iBar.Init(
symbol,
period,
i //
);
if (!isValid)
{
break;
}
//
// Reading Fast and Slow Values ...
//
SpecifiedClean(tmp);
CopyBuffer(
mHandler, // Handler ...
XFIMA_MA_FAST_LINE, // Handler Buffer Number ...
i, // Bar Index ...
1, // Number of Requirements ...
tmp // Buffer ...
);
ArraySetAsSeries(tmp, true);
iFast = tmp[0];
//
SpecifiedClean(tmp);
CopyBuffer(
mHandler, // Handler ...
XFIMA_MA_SLOW_LINE, // Handler Buffer Number ...
i, // Bar Index ...
1, // Number of Requirements ...
tmp // Buffer ...
);
ArraySetAsSeries(tmp, true);
iSlow = tmp[0];
//
// Validate ...
isValid =
IsXPeak(iType)
? (iBar.low > MathMin(iFast, iSlow) ||
iBar.GetDown() > MathMin(iFast, iSlow))
: (iBar.high < MathMax(iFast, iSlow) ||
iBar.GetUp() < MathMax(iFast, iSlow));
if (!isValid)
{
break;
}
//
// Cleanup Resources ...
SpecifiedClean(tmp);
}
//
// Cleanup Resources ...
iBar.Clean();
SpecifiedClean(tmp);
// Validate ...
}
//
if (has)
{
//
iPivotTime = GetBarTime(
symbol,
period,
idx //
);
//
// Select Value based on Pivot Type ...
iSelectedValue = IsXPeak(iType)
@@ -1517,7 +1429,7 @@ class XCXFIMAHelper : public XCBaseHelper
// Initialize and Validate Pivot ...
has = iPivot.Init(
iSelectedValue,
iBar.time,
iPivotTime,
symbol,
iDir,
period,
@@ -1542,11 +1454,11 @@ class XCXFIMAHelper : public XCBaseHelper
//
// Cleanup Resources ...
iBar.Clean();
pBar.Clean();
iPivot.Clean();
SpecifiedClean(tmpFastMaBuffer);
SpecifiedClean(tmpSlowMaBuffer);
SpecifiedClean(fast);
SpecifiedClean(slow);
SpecifiedClean(upper);
SpecifiedClean(lower);
//
// Check Moving Forward Condition ...
@@ -1564,11 +1476,11 @@ class XCXFIMAHelper : public XCBaseHelper
//
// Cleanup Resources ...
iBar.Clean();
pBar.Clean();
iPivot.Clean();
SpecifiedClean(tmpFastMaBuffer);
SpecifiedClean(tmpSlowMaBuffer);
SpecifiedClean(fast);
SpecifiedClean(slow);
SpecifiedClean(upper);
SpecifiedClean(lower);
//
return result;
@@ -1972,6 +1884,8 @@ class XCXFIMAHelper : public XCBaseHelper
* @param zones: XBoxZone, collection reference to holds results ...
* @param barIndex: int, Specified Bar Index ...
* @param requiredNumberOFZones: int, required Number of Zones ...
* @param breakValidLength: int, Breake Validation Length of Zones ...
* @param validateFakeBreakes: bool, Validation Fake Breaked Zones ...
* @param shadowMultiplier: double a Shadow Multiplier for Validation ...
* @param validationStrength: double, Minimum Strngth Multiplier in Point to Validate ...
* @param validationLength: int, Validation Length of Zones ...
@@ -1983,6 +1897,8 @@ class XCXFIMAHelper : public XCBaseHelper
XBoxZone &zones[],
int barIndex = 0,
int requiredNumberOFZones = 50,
int breakValidLength = 3,
bool validateFakeBreakes = true,
double shadowMultiplier = 3,
double validationStrength = 1,
int validationLength = 21,
@@ -2022,6 +1938,8 @@ class XCXFIMAHelper : public XCBaseHelper
double hkHighs[];
double hkCloses[];
int start = barIndex;
bool isBullish = false;
bool isBearish = false;
double up = EMPTY_VALUE;
double down = EMPTY_VALUE;
double body = EMPTY_VALUE;
@@ -2060,6 +1978,7 @@ class XCXFIMAHelper : public XCBaseHelper
}
//
// Initialized Start Bar ...
if (i == start)
{
//
@@ -2071,8 +1990,8 @@ class XCXFIMAHelper : public XCBaseHelper
//
// Check Direction ...
bool isBullish = hkOpens[0] < hkCloses[0];
bool isBearish = hkOpens[0] > hkCloses[0];
isBullish = hkOpens[0] < hkCloses[0];
isBearish = hkOpens[0] > hkCloses[0];
dir =
(isBullish && !isBearish)
? X_DIRECTION_BULLISH
@@ -2086,7 +2005,7 @@ class XCXFIMAHelper : public XCBaseHelper
}
//
// Check High Shadows and Low Shadows ...
// Calculate Requirements for Processing ...
up = isBullish
? hkCloses[0]
: hkOpens[0];
@@ -2166,8 +2085,8 @@ class XCXFIMAHelper : public XCBaseHelper
(zone.IsBullish()
? startHKLow > zone.upper
: startHKHigh < zone.lower) &&
ValidateHKZone(zone, validationLength) &&
(zone.upper - zone.lower) >= minAllowedStrength;
(zone.upper - zone.lower) >= minAllowedStrength &&
ValidateHKZone(zone, validationLength, breakValidLength, validateFakeBreakes);
if (has)
{
//
@@ -2185,7 +2104,7 @@ class XCXFIMAHelper : public XCBaseHelper
// Validating ...
result = ArraySize(zones);
has = IsValidSize(result) &&
count >= requiredNumberOFZones;
result >= requiredNumberOFZones;
if (has)
{
break;
@@ -4212,11 +4131,25 @@ class XCXFIMAHelper : public XCBaseHelper
//
int result = 0;
//
// Prepare ...
SpecifiedClean(low);
SpecifiedClean(open);
SpecifiedClean(high);
SpecifiedClean(close);
//
// Normalize ...
count = NormalizeInt(count, 1);
barIndex = NormalizeInt(barIndex, 0);
//
// Validate ...
if (mHandler == INVALID_HANDLE)
{
return result;
}
//
// Open ...
CopyBuffer(
@@ -4257,6 +4190,12 @@ class XCXFIMAHelper : public XCBaseHelper
close //
);
//
ArraySetAsSeries(low, true);
ArraySetAsSeries(open, true);
ArraySetAsSeries(high, true);
ArraySetAsSeries(close, true);
//
// Min Number of Array Sizes ...
result = MathMin(ArraySize(open), ArraySize(high));
@@ -4267,10 +4206,21 @@ class XCXFIMAHelper : public XCBaseHelper
return result;
}
//
/**
* Validate HK Zone ...
*
* @param zone: XBoxZone, reference to Specified Zone ...
* @param validationLength: int, Validation Length of Zones ...
* @param breakValidLength: int, Break Validation Length of Zones ...
* @param validateFakeBreakes: bool, Validation Fake Breaked Zones ...
*
* @return ( bool )
*/
bool ValidateHKZone(
XBoxZone &zone,
int validationLength = 1 //
int validationLength = 1,
int breakValidLength = 3,
bool validateFakeBreakes = true //
)
{
//
@@ -4279,6 +4229,7 @@ class XCXFIMAHelper : public XCBaseHelper
//
// Normalize ...
validationLength = NormalizeInt(validationLength, 1);
breakValidLength = NormalizeInt(breakValidLength, 2);
//
// Validate ...
@@ -4289,6 +4240,7 @@ class XCXFIMAHelper : public XCBaseHelper
}
//
// Requirements ...
double low[];
double open[];
double high[];
@@ -4296,9 +4248,11 @@ class XCXFIMAHelper : public XCBaseHelper
double close[];
//
// Validating Before ...
int start = zone.FromIndex() + 1;
int end = start + validationLength;
//
// Validate Before ...
for (int i = start; i < end; i++)
{
//
@@ -4311,8 +4265,6 @@ class XCXFIMAHelper : public XCBaseHelper
i,
1 //
);
//
result = IsValidSize(count);
if (!result)
{
@@ -4321,8 +4273,8 @@ class XCXFIMAHelper : public XCBaseHelper
//
result = zone.IsBullish()
? low[0] > zone.upper
: high[0] < zone.lower;
? low[0] > zone.lower
: high[0] < zone.upper;
if (!result)
{
break;
@@ -4349,8 +4301,6 @@ class XCXFIMAHelper : public XCBaseHelper
i,
1 //
);
//
result = IsValidSize(count);
if (!result)
{
@@ -4363,7 +4313,55 @@ class XCXFIMAHelper : public XCBaseHelper
: high[0] < zone.upper;
if (!result)
{
break;
//
// Check For Fake Breake ...
if (validateFakeBreakes && breakValidLength > 0)
{
//
result = i - 1 >= 0;
if (result)
{
//
for (int j = i - 1; j >= zone.ToIndex(); j--)
{
//
// Reading HK ...
count = ReadHKBars(
open,
high,
low,
close,
j,
1 //
);
result = IsValidSize(count);
if (!result)
{
break;
}
//
result = zone.IsBullish()
? close[0] > zone.upper
: close[0] < zone.lower;
if (result)
{
//
result = MathAbs(j - i) <= breakValidLength;
if (result)
{
break;
}
}
}
}
}
//
if (!result)
{
break;
}
}
}
}
@@ -4379,6 +4377,89 @@ class XCXFIMAHelper : public XCBaseHelper
return result;
}
//
int ReadMAValues(
double &fast[],
double &slow[],
double &upper[],
double &lower[],
int barIndex = 0,
int count = 0 //
)
{
//
int result = 0;
//
// Prepare ...
SpecifiedClean(fast);
SpecifiedClean(slow);
SpecifiedClean(upper);
SpecifiedClean(lower);
//
// Normalize ...
count = NormalizeInt(count, 1);
barIndex = NormalizeInt(barIndex, 0);
//
// Validate ...
if (mHandler == INVALID_HANDLE)
{
return result;
}
//
CopyBuffer(
mHandler,
XFIMA_MA_FAST_LINE,
barIndex,
count,
fast //
);
//
CopyBuffer(
mHandler,
XFIMA_MA_SLOW_LINE,
barIndex,
count,
slow //
);
//
CopyBuffer(
mHandler,
XFIMA_MA_BAND_UPPER_LINE,
barIndex,
count,
upper //
);
//
CopyBuffer(
mHandler,
XFIMA_MA_BAND_LOWER_LINE,
barIndex,
count,
lower //
);
//
ArraySetAsSeries(fast, true);
ArraySetAsSeries(slow, true);
ArraySetAsSeries(upper, true);
ArraySetAsSeries(lower, true);
//
result = MathMin(ArraySize(fast), ArraySize(slow));
result = MathMin(result, ArraySize(upper));
result = MathMin(result, ArraySize(lower));
//
return result;
}
//
};