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
+133 -3
View File
@@ -94,6 +94,7 @@ input ENUM_X_PRICE zigzagLowersMode = X_PRICE_LOW; // ZigZag Low D
// Presentation ...
input group "Presentation";
input bool showPV = true; // Show PV
input bool showHK = true; // Show HK
input bool showSAR = true; // Show Sar
input bool showMAFast = true; // Show MA Fast
input bool showMASlow = true; // Show MA Slow
@@ -133,8 +134,8 @@ input int valeArrowCode = 159; // Vales Arrow Code
#property indicator_chart_window
//
#property indicator_buffers 29
#property indicator_plots 11
#property indicator_buffers 34
#property indicator_plots 12
//
// Plot Buffers ...
@@ -305,11 +306,40 @@ double maLowerBuffer[];
#property indicator_color11 clrMagenta
#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 ...
//
#define mLastBufferIndex 13
#define mLastBufferIndex 18
//
// MA ...
@@ -963,6 +993,39 @@ void DefineBuffers()
PlotIndexSetInteger(maLowerBufferPlotIndex, PLOT_DRAW_BEGIN, 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 ...
@@ -1373,6 +1436,19 @@ void CalculateValues(
tickVolume //
);
//
// XHK ...
CalculateHKBar(
barIndex,
prevCalculated,
ratesTotal,
open,
high,
close,
low,
tickVolume //
);
//
// Fast MA ...
double iFastMa = maFastBuffer[barIndex];
@@ -1920,6 +1996,60 @@ int CalculateZigZag(
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(
int barIndex,