Adding Support of XHK to XFIMA ...

This commit is contained in:
2025-09-29 17:23:48 +03:30
parent fd82d07995
commit 7b27a4ad2f
4 changed files with 601 additions and 25 deletions
@@ -118,6 +118,7 @@ input ENUM_BASE_CORNER barTimeCorner = CORNER_RIGHT_LOWER; // Text Position
// Presentation ... // Presentation ...
input group "Presentation"; input group "Presentation";
input bool showPV = true; // Show PV input bool showPV = true; // Show PV
input bool showHK = true; // Show HK
input bool showSAR = true; // Show Sar input bool showSAR = true; // Show Sar
input bool showMAFast = true; // Show MA Fast input bool showMAFast = true; // Show MA Fast
input bool showMASlow = true; // Show MA Slow input bool showMASlow = true; // Show MA Slow
@@ -293,6 +294,7 @@ int OnInit()
fimaInputs.zigzagUppersMode = zigzagUppersMode; fimaInputs.zigzagUppersMode = zigzagUppersMode;
fimaInputs.zigzagLowersMode = zigzagLowersMode; fimaInputs.zigzagLowersMode = zigzagLowersMode;
fimaInputs.showPV = showPV; fimaInputs.showPV = showPV;
fimaInputs.showHK = showHK;
fimaInputs.showSAR = showSAR; fimaInputs.showSAR = showSAR;
fimaInputs.showMAFast = showMAFast; fimaInputs.showMAFast = showMAFast;
fimaInputs.showMASlow = showMASlow; fimaInputs.showMASlow = showMASlow;
+430 -22
View File
@@ -35,13 +35,13 @@ enum ENUM_XFIMA_BUFFERS
{ {
XFIMA_MA_FAST_LINE = 0, XFIMA_MA_FAST_LINE = 0,
XFIMA_MA_FAST_COLOR_LINE = 1, XFIMA_MA_FAST_COLOR_LINE = 1,
XFIMA_MA_FAST_STATE_LINE = 12, XFIMA_MA_FAST_STATE_LINE = 19,
XFIMA_MA_SLOW_LINE = 2, XFIMA_MA_SLOW_LINE = 2,
XFIMA_MA_SLOW_COLOR_LINE = 3, XFIMA_MA_SLOW_COLOR_LINE = 3,
XFIMA_MA_SLOW_STATE_LINE = 13, XFIMA_MA_SLOW_STATE_LINE = 20,
XFIMA_SAR_LINE = 4, XFIMA_SAR_LINE = 4,
XFIMA_SAR_COLOR_LINE = 5, XFIMA_SAR_COLOR_LINE = 5,
XFIMA_SAR_STATE_LINE = 14, XFIMA_SAR_STATE_LINE = 21,
XFIMA_PEAK_LINE = 6, XFIMA_PEAK_LINE = 6,
XFIMA_VALE_LINE = 7, XFIMA_VALE_LINE = 7,
XFIMA_FIBO_UPPER_LINE = 8, XFIMA_FIBO_UPPER_LINE = 8,
@@ -50,25 +50,31 @@ enum ENUM_XFIMA_BUFFERS
XFIMA_ZIGZAG_LINE = 11, XFIMA_ZIGZAG_LINE = 11,
XFIMA_MA_BAND_UPPER_LINE = 12, XFIMA_MA_BAND_UPPER_LINE = 12,
XFIMA_MA_BAND_LOWER_LINE = 13, XFIMA_MA_BAND_LOWER_LINE = 13,
XFIMA_ZIGZAG_HIGHS_LINE = 25, XFIMA_ZIGZAG_HIGHS_LINE = 30,
XFIMA_ZIGZAG_HIGHS_TIME_LINE = 26, XFIMA_ZIGZAG_HIGHS_TIME_LINE = 31,
XFIMA_ZIGZAG_LOWS_LINE = 27, XFIMA_ZIGZAG_LOWS_LINE = 32,
XFIMA_ZIGZAG_LOWS_TIME_LINE = 28, XFIMA_ZIGZAG_LOWS_TIME_LINE = 33,
// 14 Ma Fast State //
// 15 Ma Slow State XFIMA_HK_OPEN_LINE = 14,
// 16 Sar State XFIMA_HK_HIGH_LINE = 15,
XFIMA_SC_HH_LINE = 17, XFIMA_HK_LOW_LINE = 16,
XFIMA_SC_LL_LINE = 18, XFIMA_HK_CLOSE_LINE = 17,
XFIMA_MC_HH_LINE = 19, XFIMA_HK_COLOR_LINE = 18,
XFIMA_MC_LL_LINE = 20, // 19 Ma Fast State
XFIMA_LC_HH_LINE = 21, // 20 Ma Slow State
XFIMA_LC_LL_LINE = 22, // 21 Sar State
XFIMA_HC_HH_LINE = 23, XFIMA_SC_HH_LINE = 22,
XFIMA_HC_LL_LINE = 24, XFIMA_SC_LL_LINE = 23,
// 25 ZigZag Highs XFIMA_MC_HH_LINE = 24,
// 26 ZigZag Highs Time XFIMA_MC_LL_LINE = 25,
// 27 ZigZag Lows XFIMA_LC_HH_LINE = 26,
// 28 ZigZag Lows Time 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
}; };
// //
@@ -109,6 +115,7 @@ struct XFIMAInputs
// //
// Presentation ... // Presentation ...
bool showPV; // Show PV bool showPV; // Show PV
bool showHK; // Show HK
bool showSAR; // Show Sar bool showSAR; // Show Sar
bool showMAFast; // Show MA Fast bool showMAFast; // Show MA Fast
bool showMASlow; // Show MA Slow bool showMASlow; // Show MA Slow
@@ -172,6 +179,7 @@ struct XFIMAInputs
// //
// Presentation ... // Presentation ...
showPV = true; // Show PV showPV = true; // Show PV
showHK = true; // Show HK
showSAR = true; // Show Sar showSAR = true; // Show Sar
showMAFast = true; // Show MA Fast showMAFast = true; // Show MA Fast
showMASlow = true; // Show MA Slow showMASlow = true; // Show MA Slow
@@ -190,6 +198,7 @@ struct XFIMAInputs
{ {
// //
showPV = false; showPV = false;
showHK = false;
showSAR = false; showSAR = false;
showMAFast = false; showMAFast = false;
showMASlow = false; showMASlow = false;
@@ -289,6 +298,11 @@ struct XFIMAConditions
double highsTimeBuffer[]; double highsTimeBuffer[];
double lowsBuffer[]; double lowsBuffer[];
double lowsTimeBuffer[]; double lowsTimeBuffer[];
double hkOpenBuffer[];
double hkHighBuffer[];
double hkLowBuffer[];
double hkCloseBuffer[];
double hkColorBuffer[];
// //
// Conditions ... // Conditions ...
@@ -352,6 +366,11 @@ struct XFIMAConditions
SpecifiedClean(highsTimeBuffer); SpecifiedClean(highsTimeBuffer);
SpecifiedClean(lowsBuffer); SpecifiedClean(lowsBuffer);
SpecifiedClean(lowsTimeBuffer); SpecifiedClean(lowsTimeBuffer);
SpecifiedClean(hkOpenBuffer);
SpecifiedClean(hkHighBuffer);
SpecifiedClean(hkLowBuffer);
SpecifiedClean(hkCloseBuffer);
SpecifiedClean(hkColorBuffer);
// //
// Conditions ... // Conditions ...
@@ -389,6 +408,11 @@ struct XFIMAConditions
ArraySetAsSeries(highsTimeBuffer, true); ArraySetAsSeries(highsTimeBuffer, true);
ArraySetAsSeries(lowsBuffer, true); ArraySetAsSeries(lowsBuffer, true);
ArraySetAsSeries(lowsTimeBuffer, true); ArraySetAsSeries(lowsTimeBuffer, true);
ArraySetAsSeries(hkOpenBuffer, true);
ArraySetAsSeries(hkHighBuffer, true);
ArraySetAsSeries(hkLowBuffer, true);
ArraySetAsSeries(hkCloseBuffer, true);
ArraySetAsSeries(hkColorBuffer, true);
// //
ZeroMemory(this); ZeroMemory(this);
@@ -481,6 +505,11 @@ class XCXFIMAHelper : public XCBaseHelper
double highsTimeBuffer[]; double highsTimeBuffer[];
double lowsBuffer[]; double lowsBuffer[];
double lowsTimeBuffer[]; double lowsTimeBuffer[];
double hkOpenBuffer[];
double hkHighBuffer[];
double hkLowBuffer[];
double hkCloseBuffer[];
double hkColorBuffer[];
// //
// Constructors ... // Constructors ...
@@ -550,6 +579,11 @@ class XCXFIMAHelper : public XCBaseHelper
ArraySetAsSeries(highsTimeBuffer, true); ArraySetAsSeries(highsTimeBuffer, true);
ArraySetAsSeries(lowsBuffer, true); ArraySetAsSeries(lowsBuffer, true);
ArraySetAsSeries(lowsTimeBuffer, true); ArraySetAsSeries(lowsTimeBuffer, true);
ArraySetAsSeries(hkOpenBuffer, true);
ArraySetAsSeries(hkHighBuffer, true);
ArraySetAsSeries(hkLowBuffer, true);
ArraySetAsSeries(hkCloseBuffer, true);
ArraySetAsSeries(hkColorBuffer, true);
// //
mInputs = inputs; mInputs = inputs;
@@ -587,6 +621,7 @@ class XCXFIMAHelper : public XCBaseHelper
mInputs.zigzagLowersMode, mInputs.zigzagLowersMode,
"", // Presentation ... "", // Presentation ...
mInputs.showPV, mInputs.showPV,
mInputs.showHK,
mInputs.showSAR, mInputs.showSAR,
mInputs.showMAFast, mInputs.showMAFast,
mInputs.showMASlow, mInputs.showMASlow,
@@ -863,6 +898,41 @@ class XCXFIMAHelper : public XCBaseHelper
conditions.hLLBuffer // conditions.hLLBuffer //
); );
//
CopyHKOpen(
zIndex,
loopback,
conditions.hkOpenBuffer //
);
//
CopyHKHigh(
zIndex,
loopback,
conditions.hkHighBuffer //
);
//
CopyHKLow(
zIndex,
loopback,
conditions.hkLowBuffer //
);
//
CopyHKClose(
zIndex,
loopback,
conditions.hkCloseBuffer //
);
//
CopyHKColor(
zIndex,
loopback,
conditions.hkColorBuffer //
);
// //
// Conditions ... // Conditions ...
@@ -3081,6 +3151,269 @@ class XCXFIMAHelper : public XCBaseHelper
); );
} }
//
// XHK ...
//
// XHK Open ...
//
double GetHKOpen(
int barIndex // Bar Index
)
{
//
if (barIndex < 0)
{
barIndex = 0;
}
//
Calculate(barIndex);
//
int count = ArraySize(hkOpenBuffer);
if (barIndex >= count)
{
barIndex = count - 1;
}
//
return hkOpenBuffer[barIndex];
}
//
int CopyHKOpen(
int start, // Start
int count, // Number of Items for read
double &buffer[], // Dest Buffer
bool forceClean = true // Force To Clean buffer
)
{
//
// Update Calculations ...
Calculate(start);
//
// Copy Items ...
return Copy(
0,
count,
hkOpenBuffer,
buffer,
forceClean
//
);
}
//
// XHK High ...
//
double GetHKHigh(
int barIndex // Bar Index
)
{
//
if (barIndex < 0)
{
barIndex = 0;
}
//
Calculate(barIndex);
//
int count = ArraySize(hkHighBuffer);
if (barIndex >= count)
{
barIndex = count - 1;
}
//
return hkHighBuffer[barIndex];
}
//
int CopyHKHigh(
int start, // Start
int count, // Number of Items for read
double &buffer[], // Dest Buffer
bool forceClean = true // Force To Clean buffer
)
{
//
// Update Calculations ...
Calculate(start);
//
// Copy Items ...
return Copy(
0,
count,
hkHighBuffer,
buffer,
forceClean
//
);
}
//
// XHK Low ...
//
double GetHKLow(
int barIndex // Bar Index
)
{
//
if (barIndex < 0)
{
barIndex = 0;
}
//
Calculate(barIndex);
//
int count = ArraySize(hkLowBuffer);
if (barIndex >= count)
{
barIndex = count - 1;
}
//
return hkLowBuffer[barIndex];
}
//
int CopyHKLow(
int start, // Start
int count, // Number of Items for read
double &buffer[], // Dest Buffer
bool forceClean = true // Force To Clean buffer
)
{
//
// Update Calculations ...
Calculate(start);
//
// Copy Items ...
return Copy(
0,
count,
hkLowBuffer,
buffer,
forceClean
//
);
}
//
// XHK Close ...
//
double GetHKClose(
int barIndex // Bar Index
)
{
//
if (barIndex < 0)
{
barIndex = 0;
}
//
Calculate(barIndex);
//
int count = ArraySize(hkCloseBuffer);
if (barIndex >= count)
{
barIndex = count - 1;
}
//
return hkCloseBuffer[barIndex];
}
//
int CopyHKClose(
int start, // Start
int count, // Number of Items for read
double &buffer[], // Dest Buffer
bool forceClean = true // Force To Clean buffer
)
{
//
// Update Calculations ...
Calculate(start);
//
// Copy Items ...
return Copy(
0,
count,
hkCloseBuffer,
buffer,
forceClean
//
);
}
//
// XHK Color ...
//
double GetHKColor(
int barIndex // Bar Index
)
{
//
if (barIndex < 0)
{
barIndex = 0;
}
//
Calculate(barIndex);
//
int count = ArraySize(hkColorBuffer);
if (barIndex >= count)
{
barIndex = count - 1;
}
//
return hkColorBuffer[barIndex];
}
//
int CopyHKColor(
int start, // Start
int count, // Number of Items for read
double &buffer[], // Dest Buffer
bool forceClean = true // Force To Clean buffer
)
{
//
// Update Calculations ...
Calculate(start);
//
// Copy Items ...
return Copy(
0,
count,
hkColorBuffer,
buffer,
forceClean
//
);
}
// //
// Protected ... // Protected ...
protected: protected:
@@ -3368,6 +3701,51 @@ class XCXFIMAHelper : public XCBaseHelper
maxRequiredBars, maxRequiredBars,
lowsTimeBuffer // lowsTimeBuffer //
); );
//
CopyBuffer(
mHandler,
XFIMA_HK_OPEN_LINE,
barIndex,
maxRequiredBars,
hkOpenBuffer //
);
//
CopyBuffer(
mHandler,
XFIMA_HK_HIGH_LINE,
barIndex,
maxRequiredBars,
hkHighBuffer //
);
//
CopyBuffer(
mHandler,
XFIMA_HK_LOW_LINE,
barIndex,
maxRequiredBars,
hkLowBuffer //
);
//
CopyBuffer(
mHandler,
XFIMA_HK_CLOSE_LINE,
barIndex,
maxRequiredBars,
hkCloseBuffer //
);
//
CopyBuffer(
mHandler,
XFIMA_HK_COLOR_LINE,
barIndex,
maxRequiredBars,
hkColorBuffer //
);
} }
// //
@@ -3548,6 +3926,36 @@ class XCXFIMAHelper : public XCBaseHelper
lowsTimeBuffer, lowsTimeBuffer,
maxAllowed // maxAllowed //
); );
//
CleanupArray(
hkOpenBuffer,
maxAllowed //
);
//
CleanupArray(
hkHighBuffer,
maxAllowed //
);
//
CleanupArray(
hkLowBuffer,
maxAllowed //
);
//
CleanupArray(
hkCloseBuffer,
maxAllowed //
);
//
CleanupArray(
hkColorBuffer,
maxAllowed //
);
} }
}; };
+133 -3
View File
@@ -94,6 +94,7 @@ input ENUM_X_PRICE zigzagLowersMode = X_PRICE_LOW; // ZigZag Low D
// Presentation ... // Presentation ...
input group "Presentation"; input group "Presentation";
input bool showPV = true; // Show PV input bool showPV = true; // Show PV
input bool showHK = true; // Show HK
input bool showSAR = true; // Show Sar input bool showSAR = true; // Show Sar
input bool showMAFast = true; // Show MA Fast input bool showMAFast = true; // Show MA Fast
input bool showMASlow = true; // Show MA Slow input bool showMASlow = true; // Show MA Slow
@@ -133,8 +134,8 @@ input int valeArrowCode = 159; // Vales Arrow Code
#property indicator_chart_window #property indicator_chart_window
// //
#property indicator_buffers 29 #property indicator_buffers 34
#property indicator_plots 11 #property indicator_plots 12
// //
// Plot Buffers ... // Plot Buffers ...
@@ -305,11 +306,40 @@ double maLowerBuffer[];
#property indicator_color11 clrMagenta #property indicator_color11 clrMagenta
#property indicator_width11 3 #property indicator_width11 3
//
// XHK ...
//
#define hkOpenBufferIndex 14
double hkOpenBuffer[];
//
#define hkHighBufferIndex 15
double hkHighBuffer[];
//
#define hkLowBufferIndex 16
double hkLowBuffer[];
//
#define hkCloseBufferIndex 17
double hkCloseBuffer[];
//
#define hkColorBufferIndex 18
double hkColorBuffer[];
//
#define hkBufferPlotIndex 11
#property indicator_label12 "XHK Open;XHK High;XHK Low;XHK Close"
#property indicator_type12 DRAW_COLOR_CANDLES
#property indicator_color12 CLR_NONE, clrAqua, clrMagenta
// //
// Data Buffers ... // Data Buffers ...
// //
#define mLastBufferIndex 13 #define mLastBufferIndex 18
// //
// MA ... // MA ...
@@ -963,6 +993,39 @@ void DefineBuffers()
PlotIndexSetInteger(maLowerBufferPlotIndex, PLOT_DRAW_BEGIN, 0); PlotIndexSetInteger(maLowerBufferPlotIndex, PLOT_DRAW_BEGIN, 0);
PlotIndexSetDouble(maLowerBufferPlotIndex, PLOT_EMPTY_VALUE, 0); PlotIndexSetDouble(maLowerBufferPlotIndex, PLOT_EMPTY_VALUE, 0);
//
// XHK ...
//
// XHK Color ...
ArraySetAsSeries(hkColorBuffer, true);
SetIndexBuffer(hkColorBufferIndex, hkColorBuffer, INDICATOR_COLOR_INDEX);
//
// Set EMPTY_VALUE on XHK Bar Buffer ...
PlotIndexSetDouble(hkBufferPlotIndex, PLOT_EMPTY_VALUE, emptyValue);
PlotIndexSetInteger(hkBufferPlotIndex, PLOT_SHOW_DATA, false);
//
// Open ...
ArraySetAsSeries(hkOpenBuffer, true);
SetIndexBuffer(hkOpenBufferIndex, hkOpenBuffer, INDICATOR_DATA);
//
// High ...
ArraySetAsSeries(hkHighBuffer, true);
SetIndexBuffer(hkHighBufferIndex, hkHighBuffer, INDICATOR_DATA);
//
// Low ...
ArraySetAsSeries(hkLowBuffer, true);
SetIndexBuffer(hkLowBufferIndex, hkLowBuffer, INDICATOR_DATA);
//
// Close ...
ArraySetAsSeries(hkCloseBuffer, true);
SetIndexBuffer(hkCloseBufferIndex, hkCloseBuffer, INDICATOR_DATA);
// //
// Data Buffers ... // Data Buffers ...
@@ -1373,6 +1436,19 @@ void CalculateValues(
tickVolume // tickVolume //
); );
//
// XHK ...
CalculateHKBar(
barIndex,
prevCalculated,
ratesTotal,
open,
high,
close,
low,
tickVolume //
);
// //
// Fast MA ... // Fast MA ...
double iFastMa = maFastBuffer[barIndex]; double iFastMa = maFastBuffer[barIndex];
@@ -1920,6 +1996,60 @@ int CalculateZigZag(
return result; return result;
} }
//
void CalculateHKBar(
int barIndex,
const int prevCalculated,
const int ratesTotal,
const double &open[],
const double &high[],
const double &close[],
const double &low[],
const long &tickVolume[] //
)
{
//
int lastBarIndex = barIndex + 1;
bool isFirstBar =
startCalculationForLastBars > 0
? barIndex == startCalculationForLastBars
: barIndex == firstBarIndex;
//
double lastHKOpen =
isFirstBar
? emptyValue
: hkOpenBuffer[lastBarIndex];
double lastHKClose =
isFirstBar
? emptyValue
: hkCloseBuffer[lastBarIndex];
//
double iHKOpenValue = (lastHKOpen + lastHKClose) / 2;
double iHKCloseValue = (open[barIndex] + high[barIndex] + close[barIndex] + low[barIndex]) / 4;
double iHKHighValue = MathMax(high[barIndex], MathMax(iHKOpenValue, iHKCloseValue));
double iHKLowValue = MathMin(low[barIndex], MathMin(iHKOpenValue, iHKCloseValue));
//
// Raw HK Buffers ...
hkOpenBuffer[barIndex] = iHKOpenValue;
hkHighBuffer[barIndex] = iHKHighValue;
hkLowBuffer[barIndex] = iHKLowValue;
hkCloseBuffer[barIndex] = iHKCloseValue;
//
// Calculate HK Color ...
double iHKColorValue =
hkOpenBuffer[barIndex] < hkCloseBuffer[barIndex]
? bullishColorIDX
: bearishColorIDX;
hkColorBuffer[barIndex] =
showHK
? iHKColorValue
: hideColorIDX;
}
// //
void CalculateCycleRanges( void CalculateCycleRanges(
int barIndex, int barIndex,
@@ -631,6 +631,7 @@ class XCXFIMAStrategy2Signaller : public XCXFIMABaseSignaller
ENUM_X_PRICE iPriceType = X_PRICE_NONE; ENUM_X_PRICE iPriceType = X_PRICE_NONE;
ENUM_X_DIRECTION iDir = X_DIRECTION_NONE; ENUM_X_DIRECTION iDir = X_DIRECTION_NONE;
ENUM_X_PRICE iPriceEdgeType = X_PRICE_NONE; ENUM_X_PRICE iPriceEdgeType = X_PRICE_NONE;
ENUM_X_DIRECTION iHKSwitchedDir = X_DIRECTION_NONE;
// //
XPivot pvPivots[]; XPivot pvPivots[];
@@ -683,6 +684,41 @@ class XCXFIMAStrategy2Signaller : public XCXFIMABaseSignaller
analyserConfig // analyserConfig //
); );
//
// TODO: Testing ...
//
double cHKO = fimaConditions.hkOpenBuffer[0];
double cHKH = fimaConditions.hkHighBuffer[0];
double cHKL = fimaConditions.hkLowBuffer[0];
double cHKC = fimaConditions.hkCloseBuffer[0];
//
double pHKO = fimaConditions.hkOpenBuffer[1];
double pHKH = fimaConditions.hkHighBuffer[1];
double pHKL = fimaConditions.hkLowBuffer[1];
double pHKC = fimaConditions.hkCloseBuffer[1];
//
bool isCHKBullish = cHKO < cHKC;
bool isCHKBearish = cHKO > cHKC;
//
bool isPHKBullish = pHKO < pHKC;
bool isPHKBearish = pHKO > pHKC;
//
bool isCHKSwitchedToBullish = isCHKBullish && !isPHKBullish;
bool isCHKSwitchedToBearish = isCHKBearish && !isPHKBearish;
//
// Add this as Param in Strategy Finders for Using it ...
iHKSwitchedDir = isCHKSwitchedToBullish
? X_DIRECTION_BULLISH
: isCHKSwitchedToBullish
? X_DIRECTION_BEARISH
: X_DIRECTION_NONE;
// //
// Collect Support and Resistance Zones and Validate by them ... // Collect Support and Resistance Zones and Validate by them ...