last works ...

This commit is contained in:
2025-10-02 20:23:31 +03:30
parent bb8ab13739
commit b77771b2fc
8 changed files with 3537 additions and 87 deletions
+706 -58
View File
@@ -35,54 +35,56 @@ enum ENUM_XFIMA_BUFFERS
{
XFIMA_MA_FAST_LINE = 0,
XFIMA_MA_FAST_COLOR_LINE = 1,
XFIMA_MA_FAST_STATE_LINE = 19,
XFIMA_MA_FAST_STATE_LINE = 21,
XFIMA_MA_SLOW_LINE = 2,
XFIMA_MA_SLOW_COLOR_LINE = 3,
XFIMA_MA_SLOW_STATE_LINE = 20,
XFIMA_MA_SLOW_STATE_LINE = 22,
XFIMA_SAR_LINE = 4,
XFIMA_SAR_COLOR_LINE = 5,
XFIMA_SAR_STATE_LINE = 21,
XFIMA_SAR_STATE_LINE = 23,
XFIMA_PEAK_LINE = 6,
XFIMA_VALE_LINE = 7,
XFIMA_FIBO_UPPER_LINE = 8,
XFIMA_FIBO_MIDDLE_LINE = 9,
XFIMA_FIBO_LOWER_LINE = 10,
XFIMA_ZIGZAG_LINE = 11,
XFIMA_MA_BAND_UPPER_LINE = 12,
XFIMA_MA_BAND_LOWER_LINE = 13,
XFIMA_ZIGZAG_HIGHS_LINE = 30,
XFIMA_ZIGZAG_HIGHS_TIME_LINE = 31,
XFIMA_ZIGZAG_LOWS_LINE = 32,
XFIMA_ZIGZAG_LOWS_TIME_LINE = 33,
XFIMA_MA_BOND_UPPER_LINE = 12,
XFIMA_MA_BOND_LOWER_LINE = 13,
XFIMA_ZIGZAG_HIGHS_LINE = 32,
XFIMA_ZIGZAG_HIGHS_TIME_LINE = 33,
XFIMA_ZIGZAG_LOWS_LINE = 34,
XFIMA_ZIGZAG_LOWS_TIME_LINE = 35,
//
XFIMA_HK_OPEN_LINE = 14,
XFIMA_HK_HIGH_LINE = 15,
XFIMA_HK_LOW_LINE = 16,
XFIMA_HK_CLOSE_LINE = 17,
XFIMA_HK_COLOR_LINE = 18,
XFIMA_HK_RAW_OPEN_LINE = 34,
XFIMA_HK_RAW_HIGH_LINE = 35,
XFIMA_HK_RAW_LOW_LINE = 36,
XFIMA_HK_RAW_CLOSE_LINE = 37,
// 19 Ma Fast State
// 20 Ma Slow State
// 21 Sar State
XFIMA_SC_HH_LINE = 22,
XFIMA_SC_LL_LINE = 23,
XFIMA_MC_HH_LINE = 24,
XFIMA_MC_LL_LINE = 25,
XFIMA_LC_HH_LINE = 26,
XFIMA_LC_LL_LINE = 27,
XFIMA_HC_HH_LINE = 28,
XFIMA_HC_LL_LINE = 29,
// 30 ZigZag Highs
// 31 ZigZag Highs Time
// 32 ZigZag Lows
// 33 ZigZag Lows Time
// 34 HK Raw Open
// 35 HK Raw High
// 36 HK Raw Low
// 37 HK Raw Close
XFIMA_HK_BOND_UPPER_LINE = 19,
XFIMA_HK_BOND_LOWER_LINE = 20,
XFIMA_HK_RAW_OPEN_LINE = 36,
XFIMA_HK_RAW_HIGH_LINE = 37,
XFIMA_HK_RAW_LOW_LINE = 38,
XFIMA_HK_RAW_CLOSE_LINE = 39,
// 21 Ma Fast State
// 22 Ma Slow State
// 23 Sar State
XFIMA_SC_HH_LINE = 24,
XFIMA_SC_LL_LINE = 25,
XFIMA_MC_HH_LINE = 26,
XFIMA_MC_LL_LINE = 27,
XFIMA_LC_HH_LINE = 28,
XFIMA_LC_LL_LINE = 29,
XFIMA_HC_HH_LINE = 30,
XFIMA_HC_LL_LINE = 31,
// 32 ZigZag Highs
// 33 ZigZag Highs Time
// 34 ZigZag Lows
// 35 ZigZag Lows Time
// 36 HK Raw Open
// 37 HK Raw High
// 38 HK Raw Low
// 39 HK Raw Close
};
//
@@ -113,7 +115,7 @@ struct XFIMAInputs
ENUM_APPLIED_PRICE maAppliedTo; // MA Applied To
int maFastLength; // Fast MA Length
int maSlowLength; // Slow MA Length
int maBandLength; // MA Band Length
int maBondLength; // MA Bond Length
int zigzagDepth; // ZigZag Depth
int zigzagDeviation; // ZigZag Deviation
int zigzagBackStep; // ZigZag Back Step
@@ -130,7 +132,8 @@ struct XFIMAInputs
bool showSAR; // Show Sar
bool showMAFast; // Show MA Fast
bool showMASlow; // Show MA Slow
bool showMABand; // Show MA Band
bool showMABond; // Show MA Bond
bool showHKBond; // Show HK Bond
bool showZigZag; // Show ZigZag
bool showFiboZone; // Show Fibo Zone
int startCalculationForLastBars; // Calculate Last n Bars
@@ -180,7 +183,7 @@ struct XFIMAInputs
maAppliedTo = PRICE_CLOSE; // MA Applied To
maFastLength = 7; // Fast MA Length
maSlowLength = 20; // Slow MA Length
maBandLength = 7; // MA Band Length
maBondLength = 7; // MA Bond Length
zigzagDepth = 12; // ZigZag Depth
zigzagDeviation = 5; // ZigZag Deviation
zigzagBackStep = 3; // ZigZag Back Step
@@ -197,7 +200,8 @@ struct XFIMAInputs
showSAR = true; // Show Sar
showMAFast = true; // Show MA Fast
showMASlow = true; // Show MA Slow
showMABand = true; // Show MA Band
showMABond = true; // Show MA Bond
showHKBond = true; // Show HK Bond
showZigZag = true; // Show ZigZag
showFiboZone = true; // Show Fibo Zone
startCalculationForLastBars = 1500; // Calculate Last n Bars
@@ -216,7 +220,8 @@ struct XFIMAInputs
showSAR = false;
showMAFast = false;
showMASlow = false;
showMABand = false;
showMABond = false;
showHKBond = false;
showZigZag = false;
showFiboZone = false;
}
@@ -234,7 +239,7 @@ struct XFIMAInputs
// MA ...
maFastLength >= 2 &&
maSlowLength >= 2 &&
maBandLength >= 2 &&
maBondLength >= 2 &&
maSlowLength > maFastLength &&
//
// SAR ...
@@ -289,8 +294,8 @@ struct XFIMAConditions
double maSlowBuffer[];
double maSlowColorBuffer[];
double maSlowStateBuffer[];
double maBandUpperBuffer[];
double maBandLowerBuffer[];
double maBondUpperBuffer[];
double maBondLowerBuffer[];
double sarBuffer[];
double sarColorBuffer[];
double sarStateBuffer[];
@@ -357,8 +362,8 @@ struct XFIMAConditions
SpecifiedClean(maSlowBuffer);
SpecifiedClean(maSlowColorBuffer);
SpecifiedClean(maSlowStateBuffer);
SpecifiedClean(maBandUpperBuffer);
SpecifiedClean(maBandLowerBuffer);
SpecifiedClean(maBondUpperBuffer);
SpecifiedClean(maBondLowerBuffer);
SpecifiedClean(sarBuffer);
SpecifiedClean(sarColorBuffer);
SpecifiedClean(sarStateBuffer);
@@ -399,8 +404,8 @@ struct XFIMAConditions
ArraySetAsSeries(maSlowBuffer, true);
ArraySetAsSeries(maSlowColorBuffer, true);
ArraySetAsSeries(maSlowStateBuffer, true);
ArraySetAsSeries(maBandUpperBuffer, true);
ArraySetAsSeries(maBandLowerBuffer, true);
ArraySetAsSeries(maBondUpperBuffer, true);
ArraySetAsSeries(maBondLowerBuffer, true);
ArraySetAsSeries(sarBuffer, true);
ArraySetAsSeries(sarColorBuffer, true);
ArraySetAsSeries(sarStateBuffer, true);
@@ -554,7 +559,7 @@ class XCXFIMAHelper : public XCBaseHelper
mInputs.maAppliedTo,
mInputs.maFastLength,
mInputs.maSlowLength,
mInputs.maBandLength,
mInputs.maBondLength,
mInputs.zigzagDepth,
mInputs.zigzagDeviation,
mInputs.zigzagBackStep,
@@ -569,7 +574,8 @@ class XCXFIMAHelper : public XCBaseHelper
mInputs.showSAR,
mInputs.showMAFast,
mInputs.showMASlow,
mInputs.showMABand,
mInputs.showMABond,
mInputs.showHKBond,
mInputs.showZigZag,
mInputs.showFiboZone,
mInputs.startCalculationForLastBars,
@@ -703,17 +709,17 @@ class XCXFIMAHelper : public XCBaseHelper
);
//
CopyMABandUpper(
CopyMABondUpper(
zIndex,
loopback,
conditions.maBandUpperBuffer //
conditions.maBondUpperBuffer //
);
//
CopyMABandLower(
CopyMABondLower(
zIndex,
loopback,
conditions.maBandLowerBuffer //
conditions.maBondLowerBuffer //
);
//
@@ -1158,6 +1164,444 @@ class XCXFIMAHelper : public XCBaseHelper
return result;
}
/**
* Check Peak Happens over Last ...
*
* @param barIndex: int, Specified Bar Index ...
*
* @return ( bool )
*/
bool IsPeakOverLast(int barIndex = 0)
{
//
bool result = false;
//
// Normalize ...
barIndex = NormalizeBarIndex(barIndex);
//
// Validate ...
result = IsValid();
if (!result)
{
return result;
}
//
// Reading Values ...
//
double iPeak = GetPeak(barIndex);
double pPeak = GetPeak(barIndex + 1);
//
result = NotEmptyZero(iPeak) &&
iPeak > pPeak;
//
return result;
}
/**
* Check Vale Happens over Last ...
*
* @param barIndex: int, Specified Bar Index ...
*
* @return ( bool )
*/
bool IsValeOverLast(int barIndex = 0)
{
//
bool result = false;
//
// Normalize ...
barIndex = NormalizeBarIndex(barIndex);
//
// Validate ...
result = IsValid();
if (!result)
{
return result;
}
//
// Reading Values ...
//
double iVale = GetVale(barIndex);
double pVale = GetVale(barIndex + 1);
//
result = NotEmptyZero(iVale) &&
iVale > pVale;
//
return result;
}
/**
* Check Peak Happens under Last ...
*
* @param barIndex: int, Specified Bar Index ...
*
* @return ( bool )
*/
bool IsPeakUnderLast(int barIndex = 0)
{
//
bool result = false;
//
// Normalize ...
barIndex = NormalizeBarIndex(barIndex);
//
// Validate ...
result = IsValid();
if (!result)
{
return result;
}
//
// Reading Values ...
//
double iPeak = GetPeak(barIndex);
double pPeak = GetPeak(barIndex + 1);
//
result = NotEmptyZero(iPeak) &&
iPeak < pPeak;
//
return result;
}
/**
* Check Vale Happens under Last ...
*
* @param barIndex: int, Specified Bar Index ...
*
* @return ( bool )
*/
bool IsValeUnderLast(int barIndex = 0)
{
//
bool result = false;
//
// Normalize ...
barIndex = NormalizeBarIndex(barIndex);
//
// Validate ...
result = IsValid();
if (!result)
{
return result;
}
//
// Reading Values ...
//
double iVale = GetVale(barIndex);
double pVale = GetVale(barIndex + 1);
//
result = NotEmptyZero(iVale) &&
iVale < pVale;
//
return result;
}
/**
* Check Fibo Section is Changed or not ...
*
* @param dir: reference to hold section change direction ...
* @param barIndex: int, Specified Bar Index ...
*
* @return ( bool )
*/
bool IsFiboSectionChanged(
ENUM_X_DIRECTION &dir,
int barIndex = 0 //
)
{
//
bool result = false;
//
// Prepare ...
dir = X_DIRECTION_NONE;
//
// Normalize ...
barIndex = NormalizeBarIndex(barIndex);
//
// Validate ...
result = IsValid();
if (!result)
{
return result;
}
//
bool isBullish = false;
bool isBearish = false;
//
// Reading Values ...
//
double iFiboUpper = GetFiboUpper(barIndex);
double pFiboUpper = GetFiboUpper(barIndex + 1);
//
double iFiboMiddle = GetFiboMiddle(barIndex);
double pFiboMiddle = GetFiboMiddle(barIndex + 1);
//
double iFiboLower = GetFiboLower(barIndex);
double pFiboLower = GetFiboLower(barIndex + 1);
//
isBullish = iFiboLower >= pFiboMiddle &&
iFiboMiddle >= pFiboUpper;
isBearish = iFiboUpper <= pFiboMiddle &&
iFiboMiddle <= pFiboLower;
result = (isBullish && !isBearish) ||
(isBearish && !isBullish);
if (!result)
{
return result;
}
//
dir =
isBullish
? X_DIRECTION_BULLISH
: X_DIRECTION_BEARISH;
//
return result;
}
bool HasFiboPush(
ENUM_X_DIRECTION &dir,
int barIndex = 0,
int validationLength = 5 //
)
{
//
bool result = false;
//
// Prepare ...
dir = X_DIRECTION_NONE;
//
// Normalize ...
barIndex = NormalizeBarIndex(barIndex);
validationLength = NormalizeInt(validationLength, 3);
//
// Validate ...
result = IsValid();
if (!result)
{
return result;
}
//
// Define Requirements ...
//
XOHCL iBar;
bool isBullish = false;
bool isBearish = false;
//
double iFiboUpper = EMPTY_VALUE;
double pFiboUpper = EMPTY_VALUE;
//
double iFiboMiddle = EMPTY_VALUE;
double pFiboMiddle = EMPTY_VALUE;
//
double iFiboLower = EMPTY_VALUE;
double pFiboLower = EMPTY_VALUE;
//
// Check Zone Validation ...
int start = barIndex;
int end = start + validationLength;
for (int i = start; i < end; i++)
{
//
// Reading Values ...
//
iFiboUpper = GetFiboUpper(i);
pFiboUpper = GetFiboUpper(i + 1);
//
iFiboMiddle = GetFiboMiddle(i);
pFiboMiddle = GetFiboMiddle(i + 1);
//
iFiboLower = GetFiboLower(i);
pFiboLower = GetFiboLower(i + 1);
//
result = iFiboUpper == pFiboUpper;
if (!result)
{
break;
}
}
//
if (result)
{
//
result = iBar.Init(
mSymbol,
mPeriod,
barIndex //
);
//
if (result)
{
//
iFiboUpper = GetFiboUpper(barIndex);
iFiboMiddle = GetFiboMiddle(barIndex);
iFiboLower = GetFiboLower(barIndex);
//
isBullish = iBar.IsBullish() &&
iBar.close > iFiboLower &&
iBar.low < iFiboLower;
isBearish = iBar.IsBearish() &&
iBar.close < iFiboUpper &&
iBar.high > iFiboUpper;
result = (isBullish && !isBearish) ||
(isBearish && !isBullish);
if (result)
{
//
dir =
isBullish
? X_DIRECTION_BULLISH
: X_DIRECTION_BEARISH;
}
}
}
//
// Cleanup Resources ...
iBar.Clean();
//
return result;
}
//
// Tools ...
/**
* Detect Last Fibo Section Changed till Loopback Length ...
*
* @param lastBarIndex: int, reference to hold Detected Bar Index ...
* @param dir: ENUM_X_DIRECTION, reference to detected Direction ...
* @param barIndex: int, Specified Bar Index ...
* @param maxAllowedLoopbackLength: int, Max Allowed Loopback Bars ...
* @param forDir: ENUM_X_DIRECTION, Specified Section Change Direction Looking for ...
*
* @return ( bool )
*/
bool GetLastFiboSectionChanged(
int &lastBarIndex,
ENUM_X_DIRECTION &dir,
int barIndex = 0,
int maxAllowedLoopbackLength = 100,
ENUM_X_DIRECTION forDir = X_DIRECTION_NONE //
)
{
//
bool result = false;
//
// Prepare ...
lastBarIndex = -1;
dir = X_DIRECTION_NONE;
//
// Normalize ...
barIndex = NormalizeBarIndex(barIndex);
maxAllowedLoopbackLength = NormalizeInt(maxAllowedLoopbackLength, 50);
//
// Validate ...
result = IsValid();
if (!result)
{
return result;
}
//
int start = barIndex + 1;
int end = start + maxAllowedLoopbackLength;
for (int i = start; i < end; i++)
{
//
result = IsFiboSectionChanged(dir, i);
if (result)
{
//
// Validate By forDir ...
if (HasDirection(forDir))
{
result = dir == forDir;
}
//
if (!result)
{
//
lastBarIndex = -1;
dir = X_DIRECTION_NONE;
}
//
if (result)
{
//
lastBarIndex = i;
break;
}
}
}
//
result = HasDirection(dir) &&
IsValidIndex(lastBarIndex);
//
return result;
}
//
// Extractions ...
/**
* Extract Specified Kind of Pivots ...
*
@@ -2641,19 +3085,19 @@ class XCXFIMAHelper : public XCBaseHelper
// Upper MA ...
//
double GetMABandUpper(
double GetMABondUpper(
int barIndex // Bar Index
)
{
//
return ReadValue(
(int)XFIMA_MA_BAND_UPPER_LINE,
(int)XFIMA_MA_BOND_UPPER_LINE,
barIndex //
);
}
//
int CopyMABandUpper(
int CopyMABondUpper(
int start, // Start
int count, // Number of Items for read
double &buffer[], // Dest Buffer
@@ -2663,7 +3107,7 @@ class XCXFIMAHelper : public XCBaseHelper
//
return ReadValues(
buffer,
(int)XFIMA_MA_BAND_UPPER_LINE,
(int)XFIMA_MA_BOND_UPPER_LINE,
start,
count,
asSeries //
@@ -2674,19 +3118,19 @@ class XCXFIMAHelper : public XCBaseHelper
// Lower MA ...
//
double GetMABandLower(
double GetMABondLower(
int barIndex // Bar Index
)
{
//
return ReadValue(
(int)XFIMA_MA_BAND_LOWER_LINE,
(int)XFIMA_MA_BOND_LOWER_LINE,
barIndex //
);
}
//
int CopyMABandLower(
int CopyMABondLower(
int start, // Start
int count, // Number of Items for read
double &buffer[], // Dest Buffer
@@ -2696,7 +3140,7 @@ class XCXFIMAHelper : public XCBaseHelper
//
return ReadValues(
buffer,
(int)XFIMA_MA_BAND_LOWER_LINE,
(int)XFIMA_MA_BOND_LOWER_LINE,
start,
count,
asSeries //
@@ -3417,6 +3861,210 @@ class XCXFIMAHelper : public XCBaseHelper
);
}
//
// XHK Raw ...
//
// XHK Raw Open ...
//
double GetHKRawOpen(
int barIndex // Bar Index
)
{
//
return ReadValue(
(int)XFIMA_HK_RAW_OPEN_LINE,
barIndex //
);
}
//
int CopyHKRawOpen(
int start, // Start
int count, // Number of Items for read
double &buffer[], // Dest Buffer
bool asSeries = true // As Series Flag
)
{
//
return ReadValues(
buffer,
(int)XFIMA_HK_RAW_OPEN_LINE,
start,
count,
asSeries //
);
}
//
// XHK Raw High ...
//
double GetHKRawHigh(
int barIndex // Bar Index
)
{
//
return ReadValue(
(int)XFIMA_HK_RAW_HIGH_LINE,
barIndex //
);
}
//
int CopyHKRawHigh(
int start, // Start
int count, // Number of Items for read
double &buffer[], // Dest Buffer
bool asSeries = true // As Series Flag
)
{
//
return ReadValues(
buffer,
(int)XFIMA_HK_RAW_HIGH_LINE,
start,
count,
asSeries //
);
}
//
// XHK Raw Low ...
//
double GetHKRawLow(
int barIndex // Bar Index
)
{
//
return ReadValue(
(int)XFIMA_HK_RAW_LOW_LINE,
barIndex //
);
}
//
int CopyHKRawLow(
int start, // Start
int count, // Number of Items for read
double &buffer[], // Dest Buffer
bool asSeries = true // As Series Flag
)
{
//
return ReadValues(
buffer,
(int)XFIMA_HK_RAW_LOW_LINE,
start,
count,
asSeries //
);
}
//
// XHK Raw Close ...
//
double GetHKRawClose(
int barIndex // Bar Index
)
{
//
return ReadValue(
(int)XFIMA_HK_RAW_CLOSE_LINE,
barIndex //
);
}
//
int CopyHKRawClose(
int start, // Start
int count, // Number of Items for read
double &buffer[], // Dest Buffer
bool asSeries = true // As Series Flag
)
{
//
return ReadValues(
buffer,
(int)XFIMA_HK_RAW_CLOSE_LINE,
start,
count,
asSeries //
);
}
//
// XHK Bond ...
//
// XHK Bond Upper ...
//
double GetHKBondUpper(
int barIndex // Bar Index
)
{
//
return ReadValue(
(int)XFIMA_HK_BOND_UPPER_LINE,
barIndex //
);
}
//
int CopyHKBondUpper(
int start, // Start
int count, // Number of Items for read
double &buffer[], // Dest Buffer
bool asSeries = true // As Series Flag
)
{
//
return ReadValues(
buffer,
(int)XFIMA_HK_BOND_UPPER_LINE,
start,
count,
asSeries //
);
}
//
// XHK Bond Lower ...
//
double GetHKBondLower(
int barIndex // Bar Index
)
{
//
return ReadValue(
(int)XFIMA_HK_BOND_LOWER_LINE,
barIndex //
);
}
//
int CopyHKBondLower(
int start, // Start
int count, // Number of Items for read
double &buffer[], // Dest Buffer
bool asSeries = true // As Series Flag
)
{
//
return ReadValues(
buffer,
(int)XFIMA_HK_BOND_LOWER_LINE,
start,
count,
asSeries //
);
}
//
// Protected ...
protected: