add support for XHK, XSMHK and also Signal Bars in XCZone Indicator ...

This commit is contained in:
2025-05-22 07:25:04 +03:30
parent 7d6aeb0903
commit 5beb8d5115
+331 -4
View File
@@ -47,10 +47,14 @@ input int rsiLength = 14; // RSI Length
input double rsiOBLevel = 70.0; // RSI OB Level
input double rsiOSLevel = 30.0; // RSI OS Level
input ENUM_APPLIED_PRICE rsiAppliedTo = PRICE_CLOSE; // RSI Applied To
input int barsSignalLength = 14; // Bars Signal Length
input ENUM_X_MA_METHOD barsSignalMethod = X_MA_MODE_EMA; // Bars Signalling Method
input int deltaSignalLength = 14; // Delta Signal Length
input ENUM_X_MA_METHOD deltaSignalMethod = X_MA_MODE_EMA; // Delta Signalling Method
input int volumeSignalLength = 14; // Volume Signal Length
input ENUM_X_MA_METHOD volumeSignalMethod = X_MA_MODE_EMA; // Volume Signalling Method
input int hkSignalBarLength = 14; // Hiken Ashi Signal Length
input ENUM_X_MA_METHOD hkSignalBarMethod = X_MA_MODE_EMA; // Hiken Ashi Signal Method
//
// Validating ...
@@ -74,8 +78,11 @@ input bool filterBasedOnTrend = false; // Filter Pivots Based on Trend
// Presentation ...
input group "Presentation";
input bool showBars = true; // Show Bars
input bool showHKBars = false; // Show Hiken Ashi Bars
input bool showSar = false; // Show Sar
input bool showTrend = false; // Show Trend
input bool showSignalBars = false; // Show Signal Bars
input bool showHKSignalBars = false; // Show Hiken Ashi Signal Bars
input bool rayLeft = false; // Ray to Left
input bool drawZones = true; // Draw Detected Zones
input bool drawRRofZones = true; // Draw Zone's Risk Reward Ratios
@@ -119,8 +126,8 @@ input bool _terminalAlerts = true; // Terminal Alerts
#property indicator_chart_window
//
#property indicator_buffers 16
#property indicator_plots 2
#property indicator_buffers 31
#property indicator_plots 5
//
// Plot Buffers ...
@@ -162,10 +169,102 @@ double sarColorBuffer[];
#property indicator_color2 CLR_NONE, clrAqua, clrMagenta, clrGray
#property indicator_width2 2
//
// Signal Bar ...
//
#define openSignalBufferIndex 4
double openSignalBuffer[];
//
#define highSignalBufferIndex 5
double highSignalBuffer[];
//
#define lowSignalBufferIndex 6
double lowSignalBuffer[];
//
#define closeSignalBufferIndex 7
double closeSignalBuffer[];
//
#define signalBarColorBufferIndex 8
double signalBarColorBuffer[];
//
#define signalBarBufferIndex 2
#property indicator_label3 "X121 XSGB Open;X121 XSGB High;X121 XSGB Low;X121 XSGB Close"
#property indicator_type3 DRAW_COLOR_CANDLES
#property indicator_color3 CLR_NONE, clrLime, clrRed
//
// XHK ...
//
#define openHKBufferIndex 9
double openHKBuffer[];
//
#define highHKBufferIndex 10
double highHKBuffer[];
//
#define lowHKBufferIndex 11
double lowHKBuffer[];
//
#define closeHKBufferIndex 12
double closeHKBuffer[];
//
#define barHKColorBufferIndex 13
double barHKColorBuffer[];
//
#define barHKBufferIndex 3
#property indicator_label4 "X121 XHK Open;X121 XHK High;X121 XHK Low;X121 XHK Close"
#property indicator_type4 DRAW_COLOR_CANDLES
#property indicator_color4 CLR_NONE, clrDodgerBlue, clrDarkGoldenrod
//
// XHK SIGNAL ...
//
// Open ...
#define openHKSignalBufferIndex 14
double openHKSignalBuffer[];
//
// High ...
#define highHKSignalBufferIndex 15
double highHKSignalBuffer[];
//
// Low ...
#define lowHKSignalBufferIndex 16
double lowHKSignalBuffer[];
//
// Close ...
#define closeHKSignalBufferIndex 17
double closeHKSignalBuffer[];
//
// Candle Color ...
#define barHKSignalColorBufferIndex 18
double barHKSignalColorBuffer[];
//
#define barHKSignalBufferIndex 4
#property indicator_label5 "X121 XHKSM Open;X121 XHKSM High;X121 XHKSM Low;X121 XHKSM Close"
#property indicator_type5 DRAW_COLOR_CANDLES
#property indicator_color5 CLR_NONE, clrAqua, clrMagenta
//
// Data Buffers ...
#define mLastBufferIndex 3
#define mLastBufferIndex 18
//
// TREND State ...
@@ -642,9 +741,13 @@ bool ValidateInputs()
rsiOSLevel > 0 &&
sarMax > sarStep &&
minZoneLength > 2 &&
barsSignalLength > 2 &&
deltaSignalLength > 2 &&
hkSignalBarLength > 2 &&
volumeSignalLength > 2 &&
barsSignalMethod != X_MA_MODE_NONE &&
deltaSignalMethod != X_MA_MODE_NONE &&
hkSignalBarMethod != X_MA_MODE_NONE &&
volumeSignalMethod != X_MA_MODE_NONE &&
IsValid(trendPeriodMethod, trendPeriod)
//
@@ -715,6 +818,105 @@ void DefineBuffers()
ArraySetAsSeries(sarColorBuffer, true);
SetIndexBuffer(sarColorBufferIndex, sarColorBuffer, INDICATOR_COLOR_INDEX);
//
// SIGNAL Bar ...
//
// Signal Bars Color ...
ArraySetAsSeries(signalBarColorBuffer, true);
SetIndexBuffer(signalBarColorBufferIndex, signalBarColorBuffer, INDICATOR_COLOR_INDEX);
//
// Set EMPTY_VALUE on XHK Bar Buffer ...
PlotIndexSetDouble(signalBarBufferIndex, PLOT_EMPTY_VALUE, 0.0);
PlotIndexSetInteger(signalBarBufferIndex, PLOT_SHOW_DATA, false);
//
// Open ...
ArraySetAsSeries(openSignalBuffer, true);
SetIndexBuffer(openSignalBufferIndex, openSignalBuffer, INDICATOR_DATA);
//
// High ...
ArraySetAsSeries(highSignalBuffer, true);
SetIndexBuffer(highSignalBufferIndex, highSignalBuffer, INDICATOR_DATA);
//
// Close ...
ArraySetAsSeries(closeSignalBuffer, true);
SetIndexBuffer(closeSignalBufferIndex, closeSignalBuffer, INDICATOR_DATA);
//
// Low ...
ArraySetAsSeries(lowSignalBuffer, true);
SetIndexBuffer(lowSignalBufferIndex, lowSignalBuffer, INDICATOR_DATA);
//
// XHK ...
//
// HK Bars Color ...
ArraySetAsSeries(barHKColorBuffer, true);
SetIndexBuffer(barHKColorBufferIndex, barHKColorBuffer, INDICATOR_COLOR_INDEX);
//
// Set EMPTY_VALUE on XHK Bar Buffer ...
PlotIndexSetDouble(barHKBufferIndex, PLOT_EMPTY_VALUE, 0.0);
PlotIndexSetInteger(barHKBufferIndex, PLOT_SHOW_DATA, false);
//
// Open ...
ArraySetAsSeries(openHKBuffer, true);
SetIndexBuffer(openHKBufferIndex, openHKBuffer, INDICATOR_DATA);
//
// High ...
ArraySetAsSeries(highHKBuffer, true);
SetIndexBuffer(highHKBufferIndex, highHKBuffer, INDICATOR_DATA);
//
// Close ...
ArraySetAsSeries(closeHKBuffer, true);
SetIndexBuffer(closeHKBufferIndex, closeHKBuffer, INDICATOR_DATA);
//
// Low ...
ArraySetAsSeries(lowHKBuffer, true);
SetIndexBuffer(lowHKBufferIndex, lowHKBuffer, INDICATOR_DATA);
//
// XHK SIGNAL ...
//
// HK Bars Color ...
ArraySetAsSeries(barHKSignalColorBuffer, true);
SetIndexBuffer(barHKSignalColorBufferIndex, barHKSignalColorBuffer, INDICATOR_COLOR_INDEX);
//
// Set EMPTY_VALUE on XHK Bar Buffer ...
PlotIndexSetDouble(barHKSignalBufferIndex, PLOT_EMPTY_VALUE, 0.0);
PlotIndexSetInteger(barHKSignalBufferIndex, PLOT_SHOW_DATA, false);
//
// Open ...
ArraySetAsSeries(openHKSignalBuffer, true);
SetIndexBuffer(openHKSignalBufferIndex, openHKSignalBuffer, INDICATOR_DATA);
//
// High ...
ArraySetAsSeries(highHKSignalBuffer, true);
SetIndexBuffer(highHKSignalBufferIndex, highHKSignalBuffer, INDICATOR_DATA);
//
// Close ...
ArraySetAsSeries(closeHKSignalBuffer, true);
SetIndexBuffer(closeHKSignalBufferIndex, closeHKSignalBuffer, INDICATOR_DATA);
//
// Low ...
ArraySetAsSeries(lowHKSignalBuffer, true);
SetIndexBuffer(lowHKSignalBufferIndex, lowHKSignalBuffer, INDICATOR_DATA);
//
// Data Buffers ...
@@ -1030,6 +1232,132 @@ void CalculateValues(
volumeSignalMethod //
);
//
// SIGNAL Bar ...
//
// Open ...
iMAOnBuffer(
ratesTotal,
prevCalculated,
bar_index,
barsSignalLength,
open,
openSignalBuffer,
barsSignalMethod //
);
//
// Close ...
iMAOnBuffer(
ratesTotal,
prevCalculated,
bar_index,
barsSignalLength,
close,
closeSignalBuffer,
barsSignalMethod //
);
//
double min = MathMin(closeSignalBuffer[bar_index], openSignalBuffer[bar_index]);
double max = MathMin(closeSignalBuffer[bar_index], openSignalBuffer[bar_index]);
//
lowSignalBuffer[bar_index] = min;
highSignalBuffer[bar_index] = max;
//
// Calculate HK Signal Color ...
double iSignalColorValue =
openSignalBuffer[bar_index] < closeSignalBuffer[bar_index]
? bullishColorIDX
: bearishColorIDX;
signalBarColorBuffer[bar_index] =
showSignalBars
? iSignalColorValue
: hideColorIDX;
//
// XHK ...
//
double lastHKOpen =
isFirstBar
? emptyValue
: openHKBuffer[lastBarIndex];
double lastHKClose =
isFirstBar
? emptyValue
: closeHKBuffer[lastBarIndex];
//
double iHKOpenValue = (lastHKOpen + lastHKClose) / 2;
double iHKCloseValue = (open[bar_index] + high[bar_index] + close[bar_index] + low[bar_index]) / 4;
double iHKHighValue = MathMax(high[bar_index], MathMax(iHKOpenValue, iHKCloseValue));
double iHKLowValue = MathMin(low[bar_index], MathMin(iHKOpenValue, iHKCloseValue));
//
double iHKColorValue =
iHKOpenValue < iHKCloseValue
? bullishColorIDX
: bearishColorIDX;
//
// Raw HK Buffers ...
openHKBuffer[bar_index] = iHKOpenValue;
highHKBuffer[bar_index] = iHKHighValue;
lowHKBuffer[bar_index] = iHKLowValue;
closeHKBuffer[bar_index] = iHKCloseValue;
barHKColorBuffer[bar_index] = showHKBars ? iHKColorValue
: hideColorIDX;
//
// XHK Signal ...
//
// Open ...
iMAOnBuffer(
ratesTotal,
prevCalculated,
bar_index,
hkSignalBarLength,
openHKBuffer,
openHKSignalBuffer,
hkSignalBarMethod //
);
//
// Close ...
iMAOnBuffer(
ratesTotal,
prevCalculated,
bar_index,
hkSignalBarLength,
closeHKBuffer,
closeHKSignalBuffer,
hkSignalBarMethod //
);
//
min = MathMin(closeHKSignalBuffer[bar_index], openHKSignalBuffer[bar_index]);
max = MathMin(closeHKSignalBuffer[bar_index], openHKSignalBuffer[bar_index]);
//
lowHKSignalBuffer[bar_index] = min;
highHKSignalBuffer[bar_index] = max;
//
// Calculate HK Signal Color ...
double iHKSignalColorValue =
openHKSignalBuffer[bar_index] < closeHKSignalBuffer[bar_index]
? bullishColorIDX
: bearishColorIDX;
barHKSignalColorBuffer[bar_index] =
showHKSignalBars
? iHKSignalColorValue
: hideColorIDX;
//
// Detect Trigger Zone ...
DetectTriggerZone(
@@ -2516,5 +2844,4 @@ void HideBars()
SetChartBearishColor(CLR_NONE, chartId);
}
//