preparing Strategy 2 of Signaller 2 of XFIMA ...

This commit is contained in:
2025-10-01 01:55:40 +03:30
parent cfba2b3e3a
commit 7ea0128540
5 changed files with 1338 additions and 626 deletions
+513 -115
View File
@@ -943,6 +943,311 @@ class XCXFIMAHelper : public XCBaseHelper
//
// Pivot Actions ...
/**
* Check Specified Bar has MA Cross or not ...
*
* @param dir: reference for holds cross Direction ...
* @param barIndex: int, Specified Bar Index ...
* @param validCrossDiffMultiplier: double, validate diff between MAs on Cross happens ...
*
* @return ( bool )
*/
bool HasMACross(
ENUM_X_DIRECTION &dir,
int barIndex = 0,
double validCrossDiffMultiplier = 1 //
)
{
//
bool result = false;
//
// Prepare ...
dir = X_DIRECTION_NONE;
//
// Normalize ...
barIndex = NormalizeInt(barIndex, 0);
validCrossDiffMultiplier = NormalizeDouble(validCrossDiffMultiplier, 0);
//
double fast[];
double slow[];
double upper[];
double lower[];
int count = ReadMAValues(
fast,
slow,
upper,
lower,
barIndex,
2 //
);
//
bool isBullish = false;
bool isBearish = false;
//
// Validate Readed Values ...
result = IsValidSize(count) && count >= 2;
if (result)
{
//
// Detect Direction Change ...
//
bool notEmpty =
NotEmptyZero(fast[0]) &&
NotEmptyZero(fast[1]) &&
NotEmptyZero(slow[0]) &&
NotEmptyZero(slow[1]);
//
isBullish =
notEmpty &&
fast[0] > slow[0] &&
fast[1] < slow[1];
//
isBearish =
notEmpty &&
fast[0] < slow[0] &&
fast[1] > slow[1];
//
result =
isBullish ||
isBearish;
//
// Validate Direction Change ...
if (result &&
validCrossDiffMultiplier > 0)
{
//
double _points = GetPoints(GetSymbol());
double diff = MathAbs(fast[0] - slow[0]);
//
result = diff >= (validCrossDiffMultiplier * _points);
}
}
//
if (result)
{
//
// Setting Direction ...
dir =
isBullish
? X_DIRECTION_BULLISH
: isBearish
? X_DIRECTION_BEARISH
: X_DIRECTION_NONE;
}
//
// Cleanup Resources ...
XClean(fast);
XClean(slow);
XClean(upper);
XClean(lower);
//
return result;
}
/**
* Check Specified Bar has HK Switch or not ...
*
* @param dir: reference for holds cross Direction ...
* @param barIndex: int, Specified Bar Index ...
*
* @return ( bool )
*/
bool HasHKSwitch(
ENUM_X_DIRECTION &dir,
int barIndex = 0 //
)
{
//
bool result = false;
//
// Prepare ...
dir = X_DIRECTION_NONE;
//
// Normalize ...
barIndex = NormalizeInt(barIndex, 0);
//
double low[];
double open[];
double high[];
double close[];
int count = ReadHKBars(
open,
high,
low,
close,
barIndex,
2 //
);
//
bool isBullish = false;
bool isBearish = false;
//
// Validate Readed Values ...
result = IsValidSize(count) && count >= 2;
if (result)
{
//
// Detect Direction Change ...
//
bool notEmpty =
NotEmptyZero(open[0]) &&
NotEmptyZero(open[1]) &&
NotEmptyZero(close[0]) &&
NotEmptyZero(close[1]);
//
isBullish =
notEmpty &&
open[0] < close[0] &&
open[1] > close[1];
//
isBearish =
notEmpty &&
open[0] > close[0] &&
open[1] < close[1];
//
result =
isBullish ||
isBearish;
}
//
if (result)
{
//
// Setting Direction ...
dir =
isBullish
? X_DIRECTION_BULLISH
: isBearish
? X_DIRECTION_BEARISH
: X_DIRECTION_NONE;
}
//
// Cleanup Resources ...
XClean(low);
XClean(open);
XClean(high);
XClean(close);
//
return result;
}
/**
* Check Specified Bar has SAR Switch or not ...
*
* @param dir: reference for holds cross Direction ...
* @param barIndex: int, Specified Bar Index ...
*
* @return ( bool )
*/
bool HasSARSwitch(
ENUM_X_DIRECTION &dir,
int barIndex = 0 //
)
{
//
bool result = false;
//
// Prepare ...
dir = X_DIRECTION_NONE;
//
// Normalize ...
barIndex = NormalizeInt(barIndex, 0);
//
// Validate ...
result = mHandler != INVALID_HANDLE;
if (!result)
{
return result;
}
//
double sars[];
int count = CopyBuffer(
mHandler,
XFIMA_SAR_STATE_LINE,
barIndex,
2,
sars //
);
//
bool isBullish = false;
bool isBearish = false;
//
// Validate Readed Values ...
result = IsValidSize(count) && count >= 2;
if (result)
{
//
// Detect Direction Change ...
//
isBullish =
sars[0] >= 1 &&
sars[1] <= -1;
//
isBearish =
sars[0] <= -1 &&
sars[1] >= 1;
//
result =
isBullish ||
isBearish;
}
//
if (result)
{
//
// Setting Direction ...
dir =
isBullish
? X_DIRECTION_BULLISH
: isBearish
? X_DIRECTION_BEARISH
: X_DIRECTION_NONE;
}
//
// Cleanup Resources ...
XClean(sars);
//
return result;
}
/**
* Extract Specified Kind of Pivots ...
*
@@ -1254,121 +1559,6 @@ class XCXFIMAHelper : public XCBaseHelper
return result;
}
/**
* Check Specified Bar has MA Cross or not ...
*
* @param dir: reference for holds cross Direction ...
* @param barIndex: int, Specified Bar Index ...
* @param validCrossDiffMultiplier: double, validate diff between MAs on Cross happens ...
*
* @return ( bool )
*/
bool HasMACross(
ENUM_X_DIRECTION &dir,
int barIndex = 0,
double validCrossDiffMultiplier = 1 //
)
{
//
bool result = false;
//
// Prepare ...
dir = X_DIRECTION_NONE;
//
// Normalize ...
barIndex = NormalizeInt(barIndex, 0);
validCrossDiffMultiplier = NormalizeDouble(validCrossDiffMultiplier, 0);
//
double fast[];
double slow[];
double upper[];
double lower[];
int count = ReadMAValues(
fast,
slow,
upper,
lower,
barIndex,
2 //
);
//
bool isBullish = false;
bool isBearish = false;
//
// Validate Readed Values ...
result = IsValidSize(count) && count >= 2;
if (result)
{
//
// Detect Direction Change ...
//
bool notEmpty =
NotEmptyZero(fast[0]) &&
NotEmptyZero(fast[1]) &&
NotEmptyZero(slow[0]) &&
NotEmptyZero(slow[1]);
//
isBullish =
notEmpty &&
fast[0] > slow[0] &&
fast[1] < slow[1];
//
isBearish =
notEmpty &&
fast[0] < slow[0] &&
fast[1] > slow[1];
//
result =
isBullish ||
isBearish;
//
// Validate Direction Change ...
if (result &&
validCrossDiffMultiplier > 0)
{
//
double _points = GetPoints(GetSymbol());
double diff = MathAbs(fast[0] - slow[0]);
//
result = diff >= (validCrossDiffMultiplier * _points);
}
}
//
if (result)
{
//
// Setting Direction ...
dir =
isBullish
? X_DIRECTION_BULLISH
: isBearish
? X_DIRECTION_BEARISH
: X_DIRECTION_NONE;
}
//
// Cleanup Resources ...
XClean(fast);
XClean(slow);
XClean(upper);
XClean(lower);
//
return result;
}
/**
* Extract Specified Kind of Pivots ...
*
@@ -1596,6 +1786,214 @@ class XCXFIMAHelper : public XCBaseHelper
return result;
}
/**
* Extract Specified Kind of Pivots ...
*
* @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 ...
*
* @return ( int )
*/
int ExtractHKPivots(
XPivot &pivots[],
int barIndex = 0,
int requiredNumberOFPivots = 50,
int maxAllowedLoopbackLength = 1500 //
)
{
//
int result = 0;
//
// Prepare ...
SpecifiedClean(pivots);
//
// Normalize ...
barIndex = NormalizeInt(barIndex, 0);
requiredNumberOFPivots = NormalizeInt(requiredNumberOFPivots, 2);
maxAllowedLoopbackLength = NormalizeInt(maxAllowedLoopbackLength, 50);
//
// Validate ...
if (mHandler == INVALID_HANDLE)
{
return result;
}
//
double low[];
double open[];
XPivot iPivot;
int count = 0;
double high[];
double close[];
bool has = false;
int idx = barIndex - 1;
datetime iPivotTime = NULL;
string symbol = GetSymbol();
bool isSwitchedToBullish = false;
bool isSwitchedToBearish = false;
double iSelectedValue = EMPTY_VALUE;
ENUM_TIMEFRAMES period = GetPeriod();
ENUM_X_DIRECTION iDir = X_DIRECTION_NONE;
ENUM_X_PIVOT_TYPE iType = X_PIVOT_TYPE_NONE;
int maxAllowed = barIndex + maxAllowedLoopbackLength - 1;
while (idx < maxAllowed &&
ArraySize(pivots) < requiredNumberOFPivots)
{
//
idx++;
//
// Prepare ...
iPivot.Clean();
SpecifiedClean(low);
SpecifiedClean(open);
SpecifiedClean(high);
SpecifiedClean(close);
//
// Ignore First Item ...
if (idx == barIndex)
{
continue;
}
//
// Reading Buffer ...
count = ReadHKBars(
open,
high,
low,
close,
idx,
2 //
);
has = IsValidSize(count);
//
// Validate Value ...
has =
HasHKSwitch(
iDir,
idx //
) &&
NotEmptyZero(open[0]) &&
NotEmptyZero(open[1]) &&
NotEmptyZero(close[0]) &&
NotEmptyZero(close[1]);
if (has)
{
//
// Check Direction Changed ...
isSwitchedToBullish = IsXBullish(iDir);
isSwitchedToBearish = IsXBearish(iDir);
has =
isSwitchedToBullish ||
isSwitchedToBearish;
if (has)
{
//
// Calculate and Validate Type ...
// Peaks Only Valid when Confirmed by Bar High ...
iType =
isSwitchedToBearish
? X_PIVOT_TYPE_PEAK
: isSwitchedToBullish
? X_PIVOT_TYPE_VALE
: X_PIVOT_TYPE_NONE;
has = IsXValid(iType);
//
// Calculate and Validate Dir ...
iDir = IsXPeak(iType)
? X_DIRECTION_BEARISH
: IsXVale(iType)
? X_DIRECTION_BULLISH
: X_DIRECTION_NONE;
has = has &&
HasDirection(iDir);
//
if (has)
{
//
iPivotTime = GetBarTime(
symbol,
period,
idx //
);
//
// Select Value based on Pivot Type ...
iSelectedValue = IsXPeak(iType)
? MathMax(open[0], close[0])
: MathMin(open[0], close[0]);
//
// Initialize and Validate Pivot ...
has = iPivot.Init(
iSelectedValue,
iPivotTime,
symbol,
iDir,
period,
iType //
);
if (has)
{
//
// Add Pivot to Collection only if not Exists ...
AddIfNotExists(
iPivot,
pivots //
);
}
}
//
// Cleanup Resources ...
iPivot.Clean();
}
}
//
// Cleanup Resources ...
iPivot.Clean();
SpecifiedClean(low);
SpecifiedClean(open);
SpecifiedClean(high);
SpecifiedClean(close);
//
// Check Moving Forward Condition ...
has =
idx < maxAllowed &&
ArraySize(pivots) < requiredNumberOFPivots;
if (!has)
{
break;
}
}
//
result = ArraySize(pivots);
//
// Cleanup Resources ...
iPivot.Clean();
SpecifiedClean(low);
SpecifiedClean(open);
SpecifiedClean(high);
SpecifiedClean(close);
//
return result;
}
/**
* Extract Specified Kind of Pivots ...
*