complete XHK Indicator and it's related Helper and also Attached it to x121 Helper ...

This commit is contained in:
2025-01-25 21:42:37 +03:30
parent 6959bc83db
commit 8e502953a3
4 changed files with 1923 additions and 261 deletions
+248 -3
View File
@@ -25,6 +25,7 @@
#include "../Helpers/x-saherelm.x121.xatr.helper.mq5" #include "../Helpers/x-saherelm.x121.xatr.helper.mq5"
#include "../Helpers/x-saherelm.x121.xche.helper.mq5" #include "../Helpers/x-saherelm.x121.xche.helper.mq5"
#include "../Helpers/x-saherelm.x121.xdon.helper.mq5" #include "../Helpers/x-saherelm.x121.xdon.helper.mq5"
#include "../Helpers/x-saherelm.x121.xhk.helper.mq5"
#include "../Helpers/x-saherelm.x121.xpv.helper.mq5" #include "../Helpers/x-saherelm.x121.xpv.helper.mq5"
#include "../Helpers/x-saherelm.x121.xstr.helper.mq5" #include "../Helpers/x-saherelm.x121.xstr.helper.mq5"
#include "../Helpers/x-saherelm.x121.xvwap.helper.mq5" #include "../Helpers/x-saherelm.x121.xvwap.helper.mq5"
@@ -37,6 +38,7 @@ struct X121Inputs
// Props ... // Props ...
bool showRSI; bool showRSI;
X121XPVInputs xpvInputs; X121XPVInputs xpvInputs;
X121XHKInputs xhkInputs;
X121XATRInputs xatrInputs; X121XATRInputs xatrInputs;
X121XSTRInputs xstrInputs; X121XSTRInputs xstrInputs;
X121XCHEInputs xcheInputs; X121XCHEInputs xcheInputs;
@@ -60,6 +62,7 @@ struct X121Inputs
{ {
// //
xpvInputs.Clean(); xpvInputs.Clean();
xhkInputs.Clean();
xatrInputs.Clean(); xatrInputs.Clean();
xstrInputs.Clean(); xstrInputs.Clean();
xcheInputs.Clean(); xcheInputs.Clean();
@@ -74,6 +77,7 @@ struct X121Inputs
{ {
// //
xpvInputs.Default(); xpvInputs.Default();
xhkInputs.Default();
xatrInputs.Default(); xatrInputs.Default();
xstrInputs.Default(); xstrInputs.Default();
xcheInputs.Default(); xcheInputs.Default();
@@ -95,6 +99,7 @@ struct X121Inputs
result = result =
// //
xpvInputs.IsValid() && xpvInputs.IsValid() &&
xhkInputs.IsValid() &&
xatrInputs.IsValid() && xatrInputs.IsValid() &&
xstrInputs.IsValid() && xstrInputs.IsValid() &&
xcheInputs.IsValid() && xcheInputs.IsValid() &&
@@ -119,6 +124,7 @@ struct X121Inputs
// //
int xpvMax = xpvInputs.Max(); int xpvMax = xpvInputs.Max();
int xhkMax = xpvInputs.Max();
int xatrMax = xatrInputs.Max(); int xatrMax = xatrInputs.Max();
int xstrMax = xstrInputs.Max(); int xstrMax = xstrInputs.Max();
int xcheMax = xcheInputs.Max(); int xcheMax = xcheInputs.Max();
@@ -126,7 +132,8 @@ struct X121Inputs
int xvwapMax = xvwapInputs.Max(); int xvwapMax = xvwapInputs.Max();
// //
result = MathMax(xpvMax, xatrMax); result = MathMax(xpvMax, xpvMax);
result = MathMax(result, xatrMax);
result = MathMax(result, xstrMax); result = MathMax(result, xstrMax);
result = MathMax(result, xcheMax); result = MathMax(result, xcheMax);
result = MathMax(result, xdonMax); result = MathMax(result, xdonMax);
@@ -183,8 +190,16 @@ struct X121Conditions
double strStateBuffer[]; double strStateBuffer[];
double vwapFastBuffer[]; double vwapFastBuffer[];
double vwapSlowBuffer[]; double vwapSlowBuffer[];
double xhkSMLowBuffer[];
double vwapPriceBuffer[]; double vwapPriceBuffer[];
double xhkRawLowBuffer[];
double xhkSMOpenBuffer[];
double xhkSMHighBuffer[];
double xhkRawOpenBuffer[];
double xhkRawHighBuffer[];
double xhkSMCloseBuffer[];
double vwapVolumeBuffer[]; double vwapVolumeBuffer[];
double xhkRawCloseBuffer[];
double atrUpperRawBuffer[]; double atrUpperRawBuffer[];
double atrLowerRawBuffer[]; double atrLowerRawBuffer[];
double donLowUpperBuffer[]; double donLowUpperBuffer[];
@@ -352,6 +367,32 @@ struct X121Conditions
bool isVWapSwitchedToBullishOrdered; bool isVWapSwitchedToBullishOrdered;
bool isVWapSwitchedToBearishOrdered; bool isVWapSwitchedToBearishOrdered;
//
bool isSMHKBullish;
bool isRawHKBullish;
bool isSMHKBearish;
bool isRawHKBearish;
bool isBreakedUpSMHK;
bool isBreakedUpRawHK;
bool isRejectedUpSMHK;
bool isClosedOverSMHK;
bool isRejectedUpRawHK;
bool isBreakedDownSMHK;
bool isClosedUnderSMHK;
bool isClosedOverRawHK;
bool isClosedUnderRawHK;
bool isBreakedDownRawHK;
bool isRejectedDownSMHK;
bool isRejectedDownRawHK;
bool isRawHKBreakedUpSMHK;
bool isRawHKClosedOverSMHK;
bool isSMHKSwitchedBearish;
bool isRawHKSwitchedBearish;
bool isRawHKClosedUnderSMHK;
bool isRawHKBreakedDownSMHK;
bool isSMHKSwitchedToBullish;
bool isRawHKSwitchedToBullish;
// //
// Complex Conditions ... // Complex Conditions ...
double cheMin; double cheMin;
@@ -562,10 +603,10 @@ struct X121Conditions
Clean(lLLBuffer); Clean(lLLBuffer);
Clean(hHHBuffer); Clean(hHHBuffer);
Clean(hLLBuffer); Clean(hLLBuffer);
Clean(volumeBuffer);
Clean(peaksBuffer); Clean(peaksBuffer);
Clean(valesBuffer); Clean(valesBuffer);
Clean(strUpBuffer); Clean(strUpBuffer);
Clean(volumeBuffer);
Clean(strDownBuffer); Clean(strDownBuffer);
Clean(vwapMidBuffer); Clean(vwapMidBuffer);
Clean(le1StartBuffer); Clean(le1StartBuffer);
@@ -578,8 +619,16 @@ struct X121Conditions
Clean(strStateBuffer); Clean(strStateBuffer);
Clean(vwapFastBuffer); Clean(vwapFastBuffer);
Clean(vwapSlowBuffer); Clean(vwapSlowBuffer);
Clean(xhkSMLowBuffer);
Clean(vwapPriceBuffer); Clean(vwapPriceBuffer);
Clean(xhkRawLowBuffer);
Clean(xhkSMOpenBuffer);
Clean(xhkSMHighBuffer);
Clean(xhkRawOpenBuffer);
Clean(xhkRawHighBuffer);
Clean(xhkSMCloseBuffer);
Clean(vwapVolumeBuffer); Clean(vwapVolumeBuffer);
Clean(xhkRawCloseBuffer);
Clean(atrUpperRawBuffer); Clean(atrUpperRawBuffer);
Clean(atrLowerRawBuffer); Clean(atrLowerRawBuffer);
Clean(donLowUpperBuffer); Clean(donLowUpperBuffer);
@@ -613,10 +662,10 @@ struct X121Conditions
ArraySetAsSeries(lLLBuffer, true); ArraySetAsSeries(lLLBuffer, true);
ArraySetAsSeries(hHHBuffer, true); ArraySetAsSeries(hHHBuffer, true);
ArraySetAsSeries(hLLBuffer, true); ArraySetAsSeries(hLLBuffer, true);
ArraySetAsSeries(volumeBuffer, true);
ArraySetAsSeries(peaksBuffer, true); ArraySetAsSeries(peaksBuffer, true);
ArraySetAsSeries(valesBuffer, true); ArraySetAsSeries(valesBuffer, true);
ArraySetAsSeries(strUpBuffer, true); ArraySetAsSeries(strUpBuffer, true);
ArraySetAsSeries(volumeBuffer, true);
ArraySetAsSeries(strDownBuffer, true); ArraySetAsSeries(strDownBuffer, true);
ArraySetAsSeries(vwapMidBuffer, true); ArraySetAsSeries(vwapMidBuffer, true);
ArraySetAsSeries(le1StartBuffer, true); ArraySetAsSeries(le1StartBuffer, true);
@@ -629,8 +678,16 @@ struct X121Conditions
ArraySetAsSeries(strStateBuffer, true); ArraySetAsSeries(strStateBuffer, true);
ArraySetAsSeries(vwapFastBuffer, true); ArraySetAsSeries(vwapFastBuffer, true);
ArraySetAsSeries(vwapSlowBuffer, true); ArraySetAsSeries(vwapSlowBuffer, true);
ArraySetAsSeries(xhkSMLowBuffer, true);
ArraySetAsSeries(vwapPriceBuffer, true); ArraySetAsSeries(vwapPriceBuffer, true);
ArraySetAsSeries(xhkRawLowBuffer, true);
ArraySetAsSeries(xhkSMOpenBuffer, true);
ArraySetAsSeries(xhkSMHighBuffer, true);
ArraySetAsSeries(xhkRawOpenBuffer, true);
ArraySetAsSeries(xhkRawHighBuffer, true);
ArraySetAsSeries(xhkSMCloseBuffer, true);
ArraySetAsSeries(vwapVolumeBuffer, true); ArraySetAsSeries(vwapVolumeBuffer, true);
ArraySetAsSeries(xhkRawCloseBuffer, true);
ArraySetAsSeries(atrUpperRawBuffer, true); ArraySetAsSeries(atrUpperRawBuffer, true);
ArraySetAsSeries(atrLowerRawBuffer, true); ArraySetAsSeries(atrLowerRawBuffer, true);
ArraySetAsSeries(donLowUpperBuffer, true); ArraySetAsSeries(donLowUpperBuffer, true);
@@ -868,6 +925,33 @@ struct X121Conditions
isClosedUnderCheMin = false; isClosedUnderCheMin = false;
isClosedUnderCheMax = false; isClosedUnderCheMax = false;
//
// XHK ...
isSMHKBullish = false;
isRawHKBullish = false;
isSMHKBearish = false;
isRawHKBearish = false;
isBreakedUpSMHK = false;
isBreakedUpRawHK = false;
isRejectedUpSMHK = false;
isClosedOverSMHK = false;
isRejectedUpRawHK = false;
isBreakedDownSMHK = false;
isClosedUnderSMHK = false;
isClosedOverRawHK = false;
isClosedUnderRawHK = false;
isBreakedDownRawHK = false;
isRejectedDownSMHK = false;
isRejectedDownRawHK = false;
isRawHKBreakedUpSMHK = false;
isRawHKClosedOverSMHK = false;
isSMHKSwitchedBearish = false;
isRawHKSwitchedBearish = false;
isRawHKClosedUnderSMHK = false;
isRawHKBreakedDownSMHK = false;
isSMHKSwitchedToBullish = false;
isRawHKSwitchedToBullish = false;
// //
// Complex Conditions ... // Complex Conditions ...
@@ -1217,6 +1301,34 @@ struct X121Conditions
ToString("isClosedUnderCheMax", isClosedUnderCheMax, ignoreFalseConditions, separator) + ToString("isClosedUnderCheMax", isClosedUnderCheMax, ignoreFalseConditions, separator) +
// //
"-----------------------" + separator + "-----------------------" + separator +
"HK ..." + separator +
"-----------------------" + separator +
ToString("isSMHKBullish", isSMHKBullish, ignoreFalseConditions, separator) +
ToString("isRawHKBullish", isRawHKBullish, ignoreFalseConditions, separator) +
ToString("isSMHKBearish", isSMHKBearish, ignoreFalseConditions, separator) +
ToString("isRawHKBearish", isRawHKBearish, ignoreFalseConditions, separator) +
ToString("isBreakedUpSMHK", isBreakedUpSMHK, ignoreFalseConditions, separator) +
ToString("isBreakedUpRawHK", isBreakedUpRawHK, ignoreFalseConditions, separator) +
ToString("isRejectedUpSMHK", isRejectedUpSMHK, ignoreFalseConditions, separator) +
ToString("isClosedOverSMHK", isClosedOverSMHK, ignoreFalseConditions, separator) +
ToString("isRejectedUpRawHK", isRejectedUpRawHK, ignoreFalseConditions, separator) +
ToString("isBreakedDownSMHK", isBreakedDownSMHK, ignoreFalseConditions, separator) +
ToString("isClosedUnderSMHK", isClosedUnderSMHK, ignoreFalseConditions, separator) +
ToString("isClosedOverRawHK", isClosedOverRawHK, ignoreFalseConditions, separator) +
ToString("isClosedUnderRawHK", isClosedUnderRawHK, ignoreFalseConditions, separator) +
ToString("isBreakedDownRawHK", isBreakedDownRawHK, ignoreFalseConditions, separator) +
ToString("isRejectedDownSMHK", isRejectedDownSMHK, ignoreFalseConditions, separator) +
ToString("isRejectedDownRawHK", isRejectedDownRawHK, ignoreFalseConditions, separator) +
ToString("isRawHKBreakedUpSMHK", isRawHKBreakedUpSMHK, ignoreFalseConditions, separator) +
ToString("isRawHKClosedOverSMHK", isRawHKClosedOverSMHK, ignoreFalseConditions, separator) +
ToString("isSMHKSwitchedBearish", isSMHKSwitchedBearish, ignoreFalseConditions, separator) +
ToString("isRawHKSwitchedBearish", isRawHKSwitchedBearish, ignoreFalseConditions, separator) +
ToString("isRawHKClosedUnderSMHK", isRawHKClosedUnderSMHK, ignoreFalseConditions, separator) +
ToString("isRawHKBreakedDownSMHK", isRawHKBreakedDownSMHK, ignoreFalseConditions, separator) +
ToString("isSMHKSwitchedToBullish", isSMHKSwitchedToBullish, ignoreFalseConditions, separator) +
ToString("isRawHKSwitchedToBullish", isRawHKSwitchedToBullish, ignoreFalseConditions, separator) +
//
"-----------------------" + separator +
"Slopes ..." + separator + "Slopes ..." + separator +
"-----------------------" + separator + "-----------------------" + separator +
ToString("isRsiSlopeBullish", isRsiSlopeBullish, ignoreFalseConditions, separator) + ToString("isRsiSlopeBullish", isRsiSlopeBullish, ignoreFalseConditions, separator) +
@@ -1372,6 +1484,7 @@ class XCX121Helper : public XCBase
// //
// Helpers ... // Helpers ...
XCX121XPVHelper *xpvHelper; XCX121XPVHelper *xpvHelper;
XCX121XHKHelper *xhkHelper;
XCX121XATRHelper *xatrHelper; XCX121XATRHelper *xatrHelper;
XCX121XSTRHelper *xstrHelper; XCX121XSTRHelper *xstrHelper;
XCX121XCHEHelper *xcheHelper; XCX121XCHEHelper *xcheHelper;
@@ -1390,6 +1503,7 @@ class XCX121Helper : public XCBase
{ {
// //
delete xpvHelper; delete xpvHelper;
delete xhkHelper;
delete xatrHelper; delete xatrHelper;
delete xstrHelper; delete xstrHelper;
delete xcheHelper; delete xcheHelper;
@@ -1450,6 +1564,7 @@ class XCX121Helper : public XCBase
// //
mInputs = inputs; mInputs = inputs;
xpvInputs = inputs.xpvInputs; xpvInputs = inputs.xpvInputs;
xhkInputs = inputs.xhkInputs;
xatrInputs = inputs.xatrInputs; xatrInputs = inputs.xatrInputs;
xstrInputs = inputs.xstrInputs; xstrInputs = inputs.xstrInputs;
xcheInputs = inputs.xcheInputs; xcheInputs = inputs.xcheInputs;
@@ -1472,6 +1587,19 @@ class XCX121Helper : public XCBase
return result; return result;
} }
//
// XHK ...
xhkHelper = new XCX121XHKHelper();
result = xhkHelper.Init(
symbol,
period,
xhkInputs //
);
if (!result)
{
return result;
}
// //
// XATR ... // XATR ...
xatrHelper = new XCX121XATRHelper(); xatrHelper = new XCX121XATRHelper();
@@ -1585,6 +1713,28 @@ class XCX121Helper : public XCBase
return result; return result;
} }
//
// XHK ...
bool GetHKConditions(
X121XHKConditions &conditions, //
int barIndex = 0, //
int loopback = 5 //
)
{
//
bool result = false;
//
result = xhkHelper.GetConditions(
conditions,
barIndex,
loopback //
);
//
return result;
}
// //
// XATR ... // XATR ...
bool GetATRConditions( bool GetATRConditions(
@@ -1774,6 +1924,19 @@ class XCX121Helper : public XCBase
return result; return result;
} }
//
// XHK ...
X121XHKConditions xhkConditions;
result = GetHKConditions(
xhkConditions,
barIndex,
loopback //
);
if (!result)
{
return result;
}
// //
// XATR ... // XATR ...
X121XATRConditions xatrConditions; X121XATRConditions xatrConditions;
@@ -1969,6 +2132,87 @@ class XCX121Helper : public XCBase
conditions.isSarSwitchedToBullish = xpvConditions.isSarSwitchedToBullish; conditions.isSarSwitchedToBullish = xpvConditions.isSarSwitchedToBullish;
conditions.isSarSwitchedToBearish = xpvConditions.isSarSwitchedToBearish; conditions.isSarSwitchedToBearish = xpvConditions.isSarSwitchedToBearish;
//
// XHK ...
//
// Buffers ...
//
Copy(
xhkConditions.xhkRawOpenBuffer,
conditions.xhkRawOpenBuffer //
);
//
Copy(
xhkConditions.xhkRawHighBuffer,
conditions.xhkRawHighBuffer //
);
//
Copy(
xhkConditions.xhkRawLowBuffer,
conditions.xhkRawLowBuffer //
);
//
Copy(
xhkConditions.xhkRawCloseBuffer,
conditions.xhkRawCloseBuffer //
);
//
Copy(
xhkConditions.xhkSMOpenBuffer,
conditions.xhkSMOpenBuffer //
);
//
Copy(
xhkConditions.xhkSMHighBuffer,
conditions.xhkSMHighBuffer //
);
//
Copy(
xhkConditions.xhkSMLowBuffer,
conditions.xhkSMLowBuffer //
);
//
Copy(
xhkConditions.xhkSMCloseBuffer,
conditions.xhkSMCloseBuffer //
);
//
// Conditions ...
conditions.isSMHKBullish = xhkConditions.isSMHKBullish;
conditions.isRawHKBullish = xhkConditions.isRawHKBullish;
conditions.isSMHKBearish = xhkConditions.isSMHKBearish;
conditions.isRawHKBearish = xhkConditions.isRawHKBearish;
conditions.isBreakedUpSMHK = xhkConditions.isBreakedUpSMHK;
conditions.isBreakedUpRawHK = xhkConditions.isBreakedUpRawHK;
conditions.isRejectedUpSMHK = xhkConditions.isRejectedUpSMHK;
conditions.isClosedOverSMHK = xhkConditions.isClosedOverSMHK;
conditions.isRejectedUpRawHK = xhkConditions.isRejectedUpRawHK;
conditions.isBreakedDownSMHK = xhkConditions.isBreakedDownSMHK;
conditions.isClosedUnderSMHK = xhkConditions.isClosedUnderSMHK;
conditions.isClosedOverRawHK = xhkConditions.isClosedOverRawHK;
conditions.isClosedUnderRawHK = xhkConditions.isClosedUnderRawHK;
conditions.isBreakedDownRawHK = xhkConditions.isBreakedDownRawHK;
conditions.isRejectedDownSMHK = xhkConditions.isRejectedDownSMHK;
conditions.isRejectedDownRawHK = xhkConditions.isRejectedDownRawHK;
conditions.isRawHKBreakedUpSMHK = xhkConditions.isRawHKBreakedUpSMHK;
conditions.isRawHKClosedOverSMHK = xhkConditions.isRawHKClosedOverSMHK;
conditions.isSMHKSwitchedBearish = xhkConditions.isSMHKSwitchedBearish;
conditions.isRawHKSwitchedBearish = xhkConditions.isRawHKSwitchedBearish;
conditions.isRawHKClosedUnderSMHK = xhkConditions.isRawHKClosedUnderSMHK;
conditions.isRawHKBreakedDownSMHK = xhkConditions.isRawHKBreakedDownSMHK;
conditions.isSMHKSwitchedToBullish = xhkConditions.isSMHKSwitchedToBullish;
conditions.isRawHKSwitchedToBullish = xhkConditions.isRawHKSwitchedToBullish;
// //
// XATR ... // XATR ...
@@ -2919,6 +3163,7 @@ class XCX121Helper : public XCBase
// Inputs ... // Inputs ...
X121Inputs mInputs; X121Inputs mInputs;
X121XPVInputs xpvInputs; X121XPVInputs xpvInputs;
X121XHKInputs xhkInputs;
X121XATRInputs xatrInputs; X121XATRInputs xatrInputs;
X121XDONInputs xdonInputs; X121XDONInputs xdonInputs;
X121XSTRInputs xstrInputs; X121XSTRInputs xstrInputs;
File diff suppressed because it is too large Load Diff
+226 -258
View File
@@ -35,19 +35,9 @@
// //
// Market ... // Market ...
input group "Market"; input group "Market";
input int xhkSmoothingLength = 14; // Length
// input ENUM_X_MA_METHOD xhkSmoothingMode = X_MA_MODE_EMA; // Smoothing Method
input group "RSI Detection"; input bool xhkIgnoreSmoothingShadows = false; // Ignore Smoothed Bar Shadows
input int rsiLength = 14; // Length
input ENUM_APPLIED_PRICE rsiAppliedTo = PRICE_CLOSE; // Applied To
//
input group "ATR Detection";
input int atrLength = 14; // Length
input double atrMultiplier = 1; // Multiplier
input ENUM_APPLIED_PRICE atrUpperAppliedTo = PRICE_HIGH; // Upper Zone Applied To
input ENUM_APPLIED_PRICE atrLowerAppliedTo = PRICE_LOW; // Lower Zone Applied To
input ENUM_X_MA_METHOD atrSmoothingMode = X_MA_MODE_EMA; // Smoothing Method
// //
input group "Presentation"; input group "Presentation";
@@ -56,12 +46,19 @@ input group "Presentation";
input int startCalculationForLastBars = 1000; // Calculate Last n Bars input int startCalculationForLastBars = 1000; // Calculate Last n Bars
// //
input bool showAtrUpper = true; // Show Upper Zone input bool drawRawXHKCandles = true; // Draw Raw Candle
input bool showAtrLower = true; // Show Lower Zone input bool drawSmoothedXHKCandles = true; // Draw Smoothed Candle
// //
// Buffers ... // Buffers ...
//
#property indicator_chart_window
//
#property indicator_buffers 10
#property indicator_plots 2
// //
#define hideColorIDX 0 #define hideColorIDX 0
#define bullishColorIDX 1 #define bullishColorIDX 1
@@ -69,63 +66,64 @@ input bool showAtrLower = true; // Show Lower Zone
#define neuturalColorIDX 3 #define neuturalColorIDX 3
// //
#property indicator_chart_window // PLOTTED Buffers ...
// //
#property indicator_buffers 6 #define openHKBufferIndex 0
#property indicator_plots 2 double openHKBuffer[];
// //
// ATR ... #define highHKBufferIndex 1
double highHKBuffer[];
// //
// Upper ... #define lowHKBufferIndex 2
double lowHKBuffer[];
// //
#define atrUpperBufferIndex 0 #define closeHKBufferIndex 3
double atrUpperBuffer[]; double closeHKBuffer[];
#property indicator_label1 "X121 ATRU"
#property indicator_type1 DRAW_LINE
#property indicator_color1 clrYellow
#property indicator_style1 STYLE_SOLID
#property indicator_width1 2
// //
// Lower ... #define rawHKColorBufferIndex 4
double rawHKColorBuffer[];
// //
#define atrLowerBufferIndex 1 #define rawHKBufferIndex 0
double atrLowerBuffer[]; #property indicator_label1 "X121 XHK Open;X121 XHK High;X121 XHK Low;X121 XHK Close"
#property indicator_type1 DRAW_COLOR_CANDLES
#property indicator_label2 "X121 ATRL" #property indicator_color1 CLR_NONE, clrDodgerBlue, clrDarkGoldenrod
#property indicator_type2 DRAW_LINE
#property indicator_color2 clrYellow
#property indicator_style2 STYLE_SOLID
#property indicator_width2 2
// //
// Data Buffers ... // Open ...
#define openBufferIndex 5
double openBuffer[];
// //
int mLastBufferIndex = 1; // High ...
#define highBufferIndex 6
double highBuffer[];
// //
// ATR ... // Low ...
#define lowBufferIndex 7
#define atrBufferIndex mLastBufferIndex + 1 double lowBuffer[];
double atrBuffer[];
#define atrUpperRawBufferIndex mLastBufferIndex + 2
double atrUpperRawBuffer[];
#define atrLowerRawBufferIndex mLastBufferIndex + 3
double atrLowerRawBuffer[];
// //
// RSI ... // Close ...
#define rsiBufferIndex mLastBufferIndex + 4 #define closeBufferIndex 8
double rsiBuffer[]; double closeBuffer[];
//
// Candle Color ...
#define candleColorBufferIndex 9
double candleColorBuffer[];
//
#define candlesBufferIndex 1
#property indicator_label2 "X121 XHKSM Open;X121 XHKSM High;X121 XHKSM Low;X121 XHKSM Close"
#property indicator_type2 DRAW_COLOR_CANDLES
#property indicator_color2 CLR_NONE, clrAqua, clrMagenta
// //
// Variables, Properties and etc ... // Variables, Properties and etc ...
@@ -138,17 +136,6 @@ int limit;
int maxLength; int maxLength;
// //
// RSI Handler ...
int rsiHandler = INVALID_HANDLE;
//
// ATR Handler ...
int atrHandler = INVALID_HANDLE;
//
bool isStrTrendChanged;
bool isStrStartBearishTrend;
bool isStrStartBullishTrend;
// //
// Event Handlers ... // Event Handlers ...
@@ -170,33 +157,6 @@ int OnInit()
// //
// Initialize Indicator Handlers ... // Initialize Indicator Handlers ...
//
// RSI ...
rsiHandler = iRSI(
_Symbol,
_Period,
rsiLength,
rsiAppliedTo //
);
bool isInited = rsiHandler != INVALID_HANDLE;
if (!isInited)
{
return INIT_FAILED;
}
//
// ATR ...
atrHandler = iATR(
_Symbol,
_Period,
atrLength //
);
isInited = atrHandler != INVALID_HANDLE;
if (!isInited)
{
return INIT_FAILED;
}
// //
// because in some cases we may have more than one input for // because in some cases we may have more than one input for
// calculation and we must prevent any calculation // calculation and we must prevent any calculation
@@ -237,8 +197,6 @@ void OnDeinit(const int reason)
// REASON_CLOSE 9 Terminal closed // REASON_CLOSE 9 Terminal closed
// //
IndicatorRelease(rsiHandler);
IndicatorRelease(atrHandler);
} }
/** /**
@@ -287,65 +245,11 @@ int OnCalculate(
{ {
} }
//
// Validate Calculated Bars ...
//
// RSI ...
int rsiCalculatedBars = BarsCalculated(rsiHandler);
//
// ATR ...
int atrCalculatedBars = BarsCalculated(atrHandler);
//
bool isPassedRequiredCalculatedBars =
//
// RSI ...
rsiCalculatedBars >= maxLength &&
//
// ATR ...
atrCalculatedBars >= maxLength
//
;
if (!isPassedRequiredCalculatedBars)
{
return prev_calculated;
}
// //
limit = (prev_calculated > rates_total || prev_calculated <= 0) limit = (prev_calculated > rates_total || prev_calculated <= 0)
? rates_total ? rates_total
: (rates_total - prev_calculated) + 1; : (rates_total - prev_calculated) + 1;
//
// Buffers Copy ...
//
// RSI ...
int copiedRsis = CopyBuffer(rsiHandler, 0, 0, limit, rsiBuffer);
//
// ATR ...
int copiedAtrs = CopyBuffer(atrHandler, 0, 0, limit, atrBuffer);
//
// Validate Copied Items ...
bool isPassedRequiredCopiedItems =
//
//
// RSI ...
copiedRsis > 0 &&
//
// ATR ...
copiedAtrs > 0
//
;
if (!isPassedRequiredCopiedItems)
{
return prev_calculated;
}
// //
// Main Loop ... // Main Loop ...
for (int i = limit - 1; i >= 0 && !IsStopped(); i--) for (int i = limit - 1; i >= 0 && !IsStopped(); i--)
@@ -381,12 +285,7 @@ bool ValidateInputs()
// //
bool result = bool result =
// //
// RSI ... true
rsiLength > 0 &&
//
// ATR ...
atrLength > 0 &&
atrMultiplier > 0
// //
; ;
@@ -405,7 +304,7 @@ int ExtractMaxLengthOfInputs()
int result = 0; int result = 0;
// //
result = MathMax(rsiLength, atrLength); result = MathMax(0, xhkSmoothingLength);
// //
return result; return result;
@@ -416,53 +315,72 @@ int ExtractMaxLengthOfInputs()
*/ */
void DefineBuffers() void DefineBuffers()
{ {
//
// ATR ...
// //
// UPPER ... // RAW ...
bool canShowAtrUpper = showAtrUpper;
ENUM_DRAW_TYPE atrUpperDrawType = canShowAtrUpper ? DRAW_LINE : DRAW_NONE;
ArraySetAsSeries(atrUpperBuffer, true);
SetIndexBuffer(atrUpperBufferIndex, atrUpperBuffer, INDICATOR_DATA);
PlotIndexSetDouble(atrUpperBufferIndex, PLOT_EMPTY_VALUE, EMPTY_VALUE);
PlotIndexSetInteger(atrUpperBufferIndex, PLOT_SHOW_DATA, canShowAtrUpper);
PlotIndexSetInteger(atrUpperBufferIndex, PLOT_DRAW_TYPE, atrUpperDrawType);
// //
// LOWER ... // Raw Candles Color ...
bool canShowAtrLower = showAtrLower; ArraySetAsSeries(rawHKColorBuffer, true);
ENUM_DRAW_TYPE atrLowerDrawType = canShowAtrLower ? DRAW_LINE : DRAW_NONE; SetIndexBuffer(rawHKColorBufferIndex, rawHKColorBuffer, INDICATOR_COLOR_INDEX);
ArraySetAsSeries(atrLowerBuffer, true);
SetIndexBuffer(atrLowerBufferIndex, atrLowerBuffer, INDICATOR_DATA);
PlotIndexSetDouble(atrLowerBufferIndex, PLOT_EMPTY_VALUE, EMPTY_VALUE);
PlotIndexSetInteger(atrLowerBufferIndex, PLOT_SHOW_DATA, canShowAtrLower);
PlotIndexSetInteger(atrLowerBufferIndex, PLOT_DRAW_TYPE, atrLowerDrawType);
// //
// Data Buffers ... // Set EMPTY_VALUE on Candles Buffer ...
PlotIndexSetDouble(rawHKBufferIndex, PLOT_EMPTY_VALUE, 0.0);
PlotIndexSetInteger(rawHKBufferIndex, PLOT_SHOW_DATA, false);
// //
// ATR ... // Open ...
ArraySetAsSeries(openHKBuffer, true);
SetIndexBuffer(openHKBufferIndex, openHKBuffer, INDICATOR_DATA);
// //
ArraySetAsSeries(atrBuffer, true); // High ...
SetIndexBuffer(atrBufferIndex, atrBuffer, INDICATOR_CALCULATIONS); ArraySetAsSeries(highHKBuffer, true);
SetIndexBuffer(highHKBufferIndex, highHKBuffer, INDICATOR_DATA);
// //
ArraySetAsSeries(atrUpperRawBuffer, true); // Close ...
SetIndexBuffer(atrUpperRawBufferIndex, atrUpperRawBuffer, INDICATOR_CALCULATIONS); ArraySetAsSeries(closeHKBuffer, true);
SetIndexBuffer(closeHKBufferIndex, closeHKBuffer, INDICATOR_DATA);
// //
ArraySetAsSeries(atrLowerRawBuffer, true); // Low ...
SetIndexBuffer(atrLowerRawBufferIndex, atrLowerRawBuffer, INDICATOR_CALCULATIONS); ArraySetAsSeries(lowHKBuffer, true);
SetIndexBuffer(lowHKBufferIndex, lowHKBuffer, INDICATOR_DATA);
// //
// RSI ... // SMOOTHED ...
// //
ArraySetAsSeries(rsiBuffer, true); // Candles Color ...
SetIndexBuffer(rsiBufferIndex, rsiBuffer, INDICATOR_CALCULATIONS); ArraySetAsSeries(candleColorBuffer, true);
SetIndexBuffer(candleColorBufferIndex, candleColorBuffer, INDICATOR_COLOR_INDEX);
//
// Set EMPTY_VALUE on Candles Buffer ...
PlotIndexSetDouble(candlesBufferIndex, PLOT_EMPTY_VALUE, 0.0);
PlotIndexSetInteger(candlesBufferIndex, PLOT_SHOW_DATA, false);
//
// Open ...
ArraySetAsSeries(openBuffer, true);
SetIndexBuffer(openBufferIndex, openBuffer, INDICATOR_DATA);
//
// High ...
ArraySetAsSeries(highBuffer, true);
SetIndexBuffer(highBufferIndex, highBuffer, INDICATOR_DATA);
//
// Close ...
ArraySetAsSeries(closeBuffer, true);
SetIndexBuffer(closeBufferIndex, closeBuffer, INDICATOR_DATA);
//
// Low ...
ArraySetAsSeries(lowBuffer, true);
SetIndexBuffer(lowBufferIndex, lowBuffer, INDICATOR_DATA);
} }
/** /**
@@ -501,14 +419,13 @@ void CalculateBuffers(
? startCalculationForLastBars ? startCalculationForLastBars
: 0; : 0;
// //
// bool canCalculate = true;
bool canCalculate = bool canCalculate =
barsLimit == 0 || barsLimit == 0 ||
bar_index <= barsLimit; bar_index <= barsLimit;
if (canCalculate) if (canCalculate)
{ {
// //
CalculateAtrZones( CalculateXHK(
bar_index, bar_index,
prevCalculated, prevCalculated,
ratesTotal, ratesTotal,
@@ -535,16 +452,18 @@ void CalculateBuffers(
void FillBuffersZero(int barIndex) void FillBuffersZero(int barIndex)
{ {
// //
// RSIS ... lowHKBuffer[barIndex] = 0.0;
rsiBuffer[barIndex] = 0; openHKBuffer[barIndex] = 0.0;
highHKBuffer[barIndex] = 0.0;
closeHKBuffer[barIndex] = 0.0;
rawHKColorBuffer[barIndex] = hideColorIDX;
// //
// ATRS ... lowBuffer[barIndex] = 0.0;
atrBuffer[barIndex] = 0; openBuffer[barIndex] = 0.0;
atrUpperBuffer[barIndex] = 0; highBuffer[barIndex] = 0.0;
atrUpperRawBuffer[barIndex] = 0; closeBuffer[barIndex] = 0.0;
atrUpperBuffer[barIndex] = 0; candleColorBuffer[barIndex] = hideColorIDX;
atrLowerRawBuffer[barIndex] = 0;
} }
/** /**
@@ -558,7 +477,7 @@ void FillBuffersZero(int barIndex)
* @param close: Double Array, History of Close Prices ... * @param close: Double Array, History of Close Prices ...
* @param low: Double Array, History of Low Prices ... * @param low: Double Array, History of Low Prices ...
*/ */
void CalculateAtrZones( void CalculateXHK(
int bar_index, // Selected Bar Index int bar_index, // Selected Bar Index
const int prevCalculated, const int prevCalculated,
const int ratesTotal, const int ratesTotal,
@@ -569,79 +488,128 @@ void CalculateAtrZones(
) )
{ {
// //
// Select ATr Value ... double mPrevHKOpenValue;
double atrValue = atrBuffer[bar_index]; double mPrevHKCloseValue;
double appliedAtrMultiplierValue = atrValue * atrMultiplier;
// //
// Select Upper Price ... if (ArraySize(open) <= bar_index + 1)
double upperPrice = GetAppliedPrice(
atrUpperAppliedTo,
open,
high,
low,
close,
bar_index //
);
//
// Select Lower Price ...
double lowerPrice = GetAppliedPrice(
atrLowerAppliedTo,
open,
high,
low,
close,
bar_index //
);
//
// Calculate Raw Atrs ...
//
// Upper ...
double atrUpperRawValue = upperPrice + appliedAtrMultiplierValue;
atrUpperRawBuffer[bar_index] = atrUpperRawValue;
//
// Lower ...
double atrLowerRawValue = lowerPrice - appliedAtrMultiplierValue;
atrLowerRawBuffer[bar_index] = atrLowerRawValue;
//
bool canSmooth = atrSmoothingMode != X_MA_MODE_NONE;
if (canSmooth)
{ {
// //
// Upper ... mPrevHKOpenValue = 0;
iMAOnBuffer( mPrevHKCloseValue = 0;
ratesTotal,
prevCalculated,
bar_index,
atrLength,
atrUpperRawBuffer,
atrUpperBuffer,
atrSmoothingMode //
);
//
// Lower ...
iMAOnBuffer(
ratesTotal,
prevCalculated,
bar_index,
atrLength,
atrLowerRawBuffer,
atrLowerBuffer,
atrSmoothingMode //
);
} }
else else
{ {
// //
// Use Raw Values ... mPrevHKOpenValue = openHKBuffer[bar_index + 1];
atrUpperBuffer[bar_index] = atrUpperRawValue; mPrevHKCloseValue = closeHKBuffer[bar_index + 1];
atrLowerBuffer[bar_index] = atrLowerRawValue; }
//
double mHKOpenValue = (mPrevHKOpenValue + mPrevHKCloseValue) / 2;
double mHKCloseValue = (open[bar_index] + high[bar_index] + close[bar_index] + low[bar_index]) / 4;
double mHKHighValue = MathMax(high[bar_index], MathMax(mHKOpenValue, mHKCloseValue));
double mHKLowValue = MathMin(low[bar_index], MathMin(mHKOpenValue, mHKCloseValue));
//
double candleColorValue =
mHKOpenValue < mHKCloseValue ? bullishColorIDX : bearishColorIDX;
//
// Raw HK Buffers ...
openHKBuffer[bar_index] = mHKOpenValue;
highHKBuffer[bar_index] = mHKHighValue;
lowHKBuffer[bar_index] = mHKLowValue;
closeHKBuffer[bar_index] = mHKCloseValue;
rawHKColorBuffer[bar_index] = drawRawXHKCandles ? candleColorValue : hideColorIDX;
//
// Apply Smoothing ...
bool canSmooth = xhkSmoothingLength > 0 &&
xhkSmoothingMode != X_MA_MODE_NONE;
if (!canSmooth)
{
//
double min = MathMin(mHKOpenValue, mHKCloseValue);
double max = MathMax(mHKOpenValue, mHKCloseValue);
//
openBuffer[bar_index] = mHKOpenValue;
highBuffer[bar_index] = xhkIgnoreSmoothingShadows ? max : mHKHighValue;
lowBuffer[bar_index] = xhkIgnoreSmoothingShadows ? min : mHKLowValue;
closeBuffer[bar_index] = mHKCloseValue;
candleColorBuffer[bar_index] = drawSmoothedXHKCandles ? candleColorValue : hideColorIDX;
}
else
{
//
// Open ...
iMAOnBuffer(
ratesTotal,
prevCalculated,
bar_index,
xhkSmoothingLength,
openHKBuffer,
openBuffer,
xhkSmoothingMode //
);
//
// Close ...
iMAOnBuffer(
ratesTotal,
prevCalculated,
bar_index,
xhkSmoothingLength,
closeHKBuffer,
closeBuffer,
xhkSmoothingMode //
);
//
// Ignoring Shadows ...
if (!xhkIgnoreSmoothingShadows)
{
//
// High ...
iMAOnBuffer(
ratesTotal,
prevCalculated,
bar_index,
xhkSmoothingLength,
highHKBuffer,
highBuffer,
xhkSmoothingMode //
);
//
// Low ...
iMAOnBuffer(
ratesTotal,
prevCalculated,
bar_index,
xhkSmoothingLength,
lowHKBuffer,
lowBuffer,
xhkSmoothingMode //
);
}
else
{
//
double min = MathMin(closeBuffer[bar_index], openBuffer[bar_index]);
double max = MathMin(closeBuffer[bar_index], openBuffer[bar_index]);
//
lowBuffer[bar_index] = min;
highBuffer[bar_index] = max;
}
//
// Calculate Smoothed Color ...
candleColorValue =
openBuffer[bar_index] < closeBuffer[bar_index] ? bullishColorIDX : bearishColorIDX;
candleColorBuffer[bar_index] = drawSmoothedXHKCandles ? candleColorValue : hideColorIDX;
} }
} }
@@ -24,6 +24,7 @@
// #include "../../Libraries/x-trade.lib" // #include "../../Libraries/x-trade.lib"
#include "../Classes/x-121.smc.market.cycle.helper.class.mq5" #include "../Classes/x-121.smc.market.cycle.helper.class.mq5"
#include "../Libraries/x-121.smc.lib.mq5" #include "../Libraries/x-121.smc.lib.mq5"
#include "../Libraries/x-121.smc.guard.lib.mq5"
// //
// Definitions ... // Definitions ...