complete XHK Indicator and it's related Helper and also Attached it to x121 Helper ...
This commit is contained in:
@@ -25,6 +25,7 @@
|
||||
#include "../Helpers/x-saherelm.x121.xatr.helper.mq5"
|
||||
#include "../Helpers/x-saherelm.x121.xche.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.xstr.helper.mq5"
|
||||
#include "../Helpers/x-saherelm.x121.xvwap.helper.mq5"
|
||||
@@ -37,6 +38,7 @@ struct X121Inputs
|
||||
// Props ...
|
||||
bool showRSI;
|
||||
X121XPVInputs xpvInputs;
|
||||
X121XHKInputs xhkInputs;
|
||||
X121XATRInputs xatrInputs;
|
||||
X121XSTRInputs xstrInputs;
|
||||
X121XCHEInputs xcheInputs;
|
||||
@@ -60,6 +62,7 @@ struct X121Inputs
|
||||
{
|
||||
//
|
||||
xpvInputs.Clean();
|
||||
xhkInputs.Clean();
|
||||
xatrInputs.Clean();
|
||||
xstrInputs.Clean();
|
||||
xcheInputs.Clean();
|
||||
@@ -74,6 +77,7 @@ struct X121Inputs
|
||||
{
|
||||
//
|
||||
xpvInputs.Default();
|
||||
xhkInputs.Default();
|
||||
xatrInputs.Default();
|
||||
xstrInputs.Default();
|
||||
xcheInputs.Default();
|
||||
@@ -95,6 +99,7 @@ struct X121Inputs
|
||||
result =
|
||||
//
|
||||
xpvInputs.IsValid() &&
|
||||
xhkInputs.IsValid() &&
|
||||
xatrInputs.IsValid() &&
|
||||
xstrInputs.IsValid() &&
|
||||
xcheInputs.IsValid() &&
|
||||
@@ -119,6 +124,7 @@ struct X121Inputs
|
||||
|
||||
//
|
||||
int xpvMax = xpvInputs.Max();
|
||||
int xhkMax = xpvInputs.Max();
|
||||
int xatrMax = xatrInputs.Max();
|
||||
int xstrMax = xstrInputs.Max();
|
||||
int xcheMax = xcheInputs.Max();
|
||||
@@ -126,7 +132,8 @@ struct X121Inputs
|
||||
int xvwapMax = xvwapInputs.Max();
|
||||
|
||||
//
|
||||
result = MathMax(xpvMax, xatrMax);
|
||||
result = MathMax(xpvMax, xpvMax);
|
||||
result = MathMax(result, xatrMax);
|
||||
result = MathMax(result, xstrMax);
|
||||
result = MathMax(result, xcheMax);
|
||||
result = MathMax(result, xdonMax);
|
||||
@@ -183,8 +190,16 @@ struct X121Conditions
|
||||
double strStateBuffer[];
|
||||
double vwapFastBuffer[];
|
||||
double vwapSlowBuffer[];
|
||||
double xhkSMLowBuffer[];
|
||||
double vwapPriceBuffer[];
|
||||
double xhkRawLowBuffer[];
|
||||
double xhkSMOpenBuffer[];
|
||||
double xhkSMHighBuffer[];
|
||||
double xhkRawOpenBuffer[];
|
||||
double xhkRawHighBuffer[];
|
||||
double xhkSMCloseBuffer[];
|
||||
double vwapVolumeBuffer[];
|
||||
double xhkRawCloseBuffer[];
|
||||
double atrUpperRawBuffer[];
|
||||
double atrLowerRawBuffer[];
|
||||
double donLowUpperBuffer[];
|
||||
@@ -352,6 +367,32 @@ struct X121Conditions
|
||||
bool isVWapSwitchedToBullishOrdered;
|
||||
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 ...
|
||||
double cheMin;
|
||||
@@ -562,10 +603,10 @@ struct X121Conditions
|
||||
Clean(lLLBuffer);
|
||||
Clean(hHHBuffer);
|
||||
Clean(hLLBuffer);
|
||||
Clean(volumeBuffer);
|
||||
Clean(peaksBuffer);
|
||||
Clean(valesBuffer);
|
||||
Clean(strUpBuffer);
|
||||
Clean(volumeBuffer);
|
||||
Clean(strDownBuffer);
|
||||
Clean(vwapMidBuffer);
|
||||
Clean(le1StartBuffer);
|
||||
@@ -578,8 +619,16 @@ struct X121Conditions
|
||||
Clean(strStateBuffer);
|
||||
Clean(vwapFastBuffer);
|
||||
Clean(vwapSlowBuffer);
|
||||
Clean(xhkSMLowBuffer);
|
||||
Clean(vwapPriceBuffer);
|
||||
Clean(xhkRawLowBuffer);
|
||||
Clean(xhkSMOpenBuffer);
|
||||
Clean(xhkSMHighBuffer);
|
||||
Clean(xhkRawOpenBuffer);
|
||||
Clean(xhkRawHighBuffer);
|
||||
Clean(xhkSMCloseBuffer);
|
||||
Clean(vwapVolumeBuffer);
|
||||
Clean(xhkRawCloseBuffer);
|
||||
Clean(atrUpperRawBuffer);
|
||||
Clean(atrLowerRawBuffer);
|
||||
Clean(donLowUpperBuffer);
|
||||
@@ -613,10 +662,10 @@ struct X121Conditions
|
||||
ArraySetAsSeries(lLLBuffer, true);
|
||||
ArraySetAsSeries(hHHBuffer, true);
|
||||
ArraySetAsSeries(hLLBuffer, true);
|
||||
ArraySetAsSeries(volumeBuffer, true);
|
||||
ArraySetAsSeries(peaksBuffer, true);
|
||||
ArraySetAsSeries(valesBuffer, true);
|
||||
ArraySetAsSeries(strUpBuffer, true);
|
||||
ArraySetAsSeries(volumeBuffer, true);
|
||||
ArraySetAsSeries(strDownBuffer, true);
|
||||
ArraySetAsSeries(vwapMidBuffer, true);
|
||||
ArraySetAsSeries(le1StartBuffer, true);
|
||||
@@ -629,8 +678,16 @@ struct X121Conditions
|
||||
ArraySetAsSeries(strStateBuffer, true);
|
||||
ArraySetAsSeries(vwapFastBuffer, true);
|
||||
ArraySetAsSeries(vwapSlowBuffer, true);
|
||||
ArraySetAsSeries(xhkSMLowBuffer, 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(xhkRawCloseBuffer, true);
|
||||
ArraySetAsSeries(atrUpperRawBuffer, true);
|
||||
ArraySetAsSeries(atrLowerRawBuffer, true);
|
||||
ArraySetAsSeries(donLowUpperBuffer, true);
|
||||
@@ -868,6 +925,33 @@ struct X121Conditions
|
||||
isClosedUnderCheMin = 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 ...
|
||||
|
||||
@@ -1217,6 +1301,34 @@ struct X121Conditions
|
||||
ToString("isClosedUnderCheMax", isClosedUnderCheMax, ignoreFalseConditions, 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 +
|
||||
"-----------------------" + separator +
|
||||
ToString("isRsiSlopeBullish", isRsiSlopeBullish, ignoreFalseConditions, separator) +
|
||||
@@ -1372,6 +1484,7 @@ class XCX121Helper : public XCBase
|
||||
//
|
||||
// Helpers ...
|
||||
XCX121XPVHelper *xpvHelper;
|
||||
XCX121XHKHelper *xhkHelper;
|
||||
XCX121XATRHelper *xatrHelper;
|
||||
XCX121XSTRHelper *xstrHelper;
|
||||
XCX121XCHEHelper *xcheHelper;
|
||||
@@ -1390,6 +1503,7 @@ class XCX121Helper : public XCBase
|
||||
{
|
||||
//
|
||||
delete xpvHelper;
|
||||
delete xhkHelper;
|
||||
delete xatrHelper;
|
||||
delete xstrHelper;
|
||||
delete xcheHelper;
|
||||
@@ -1450,6 +1564,7 @@ class XCX121Helper : public XCBase
|
||||
//
|
||||
mInputs = inputs;
|
||||
xpvInputs = inputs.xpvInputs;
|
||||
xhkInputs = inputs.xhkInputs;
|
||||
xatrInputs = inputs.xatrInputs;
|
||||
xstrInputs = inputs.xstrInputs;
|
||||
xcheInputs = inputs.xcheInputs;
|
||||
@@ -1472,6 +1587,19 @@ class XCX121Helper : public XCBase
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// XHK ...
|
||||
xhkHelper = new XCX121XHKHelper();
|
||||
result = xhkHelper.Init(
|
||||
symbol,
|
||||
period,
|
||||
xhkInputs //
|
||||
);
|
||||
if (!result)
|
||||
{
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// XATR ...
|
||||
xatrHelper = new XCX121XATRHelper();
|
||||
@@ -1585,6 +1713,28 @@ class XCX121Helper : public XCBase
|
||||
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 ...
|
||||
bool GetATRConditions(
|
||||
@@ -1774,6 +1924,19 @@ class XCX121Helper : public XCBase
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// XHK ...
|
||||
X121XHKConditions xhkConditions;
|
||||
result = GetHKConditions(
|
||||
xhkConditions,
|
||||
barIndex,
|
||||
loopback //
|
||||
);
|
||||
if (!result)
|
||||
{
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// XATR ...
|
||||
X121XATRConditions xatrConditions;
|
||||
@@ -1969,6 +2132,87 @@ class XCX121Helper : public XCBase
|
||||
conditions.isSarSwitchedToBullish = xpvConditions.isSarSwitchedToBullish;
|
||||
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 ...
|
||||
|
||||
@@ -2919,6 +3163,7 @@ class XCX121Helper : public XCBase
|
||||
// Inputs ...
|
||||
X121Inputs mInputs;
|
||||
X121XPVInputs xpvInputs;
|
||||
X121XHKInputs xhkInputs;
|
||||
X121XATRInputs xatrInputs;
|
||||
X121XDONInputs xdonInputs;
|
||||
X121XSTRInputs xstrInputs;
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
+226
-258
@@ -35,19 +35,9 @@
|
||||
//
|
||||
// Market ...
|
||||
input group "Market";
|
||||
|
||||
//
|
||||
input group "RSI Detection";
|
||||
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 int xhkSmoothingLength = 14; // Length
|
||||
input ENUM_X_MA_METHOD xhkSmoothingMode = X_MA_MODE_EMA; // Smoothing Method
|
||||
input bool xhkIgnoreSmoothingShadows = false; // Ignore Smoothed Bar Shadows
|
||||
|
||||
//
|
||||
input group "Presentation";
|
||||
@@ -56,12 +46,19 @@ input group "Presentation";
|
||||
input int startCalculationForLastBars = 1000; // Calculate Last n Bars
|
||||
|
||||
//
|
||||
input bool showAtrUpper = true; // Show Upper Zone
|
||||
input bool showAtrLower = true; // Show Lower Zone
|
||||
input bool drawRawXHKCandles = true; // Draw Raw Candle
|
||||
input bool drawSmoothedXHKCandles = true; // Draw Smoothed Candle
|
||||
|
||||
//
|
||||
// Buffers ...
|
||||
|
||||
//
|
||||
#property indicator_chart_window
|
||||
|
||||
//
|
||||
#property indicator_buffers 10
|
||||
#property indicator_plots 2
|
||||
|
||||
//
|
||||
#define hideColorIDX 0
|
||||
#define bullishColorIDX 1
|
||||
@@ -69,63 +66,64 @@ input bool showAtrLower = true; // Show Lower Zone
|
||||
#define neuturalColorIDX 3
|
||||
|
||||
//
|
||||
#property indicator_chart_window
|
||||
// PLOTTED Buffers ...
|
||||
|
||||
//
|
||||
#property indicator_buffers 6
|
||||
#property indicator_plots 2
|
||||
#define openHKBufferIndex 0
|
||||
double openHKBuffer[];
|
||||
|
||||
//
|
||||
// ATR ...
|
||||
#define highHKBufferIndex 1
|
||||
double highHKBuffer[];
|
||||
|
||||
//
|
||||
// Upper ...
|
||||
#define lowHKBufferIndex 2
|
||||
double lowHKBuffer[];
|
||||
|
||||
//
|
||||
#define atrUpperBufferIndex 0
|
||||
double atrUpperBuffer[];
|
||||
|
||||
#property indicator_label1 "X121 ATRU"
|
||||
#property indicator_type1 DRAW_LINE
|
||||
#property indicator_color1 clrYellow
|
||||
#property indicator_style1 STYLE_SOLID
|
||||
#property indicator_width1 2
|
||||
#define closeHKBufferIndex 3
|
||||
double closeHKBuffer[];
|
||||
|
||||
//
|
||||
// Lower ...
|
||||
#define rawHKColorBufferIndex 4
|
||||
double rawHKColorBuffer[];
|
||||
|
||||
//
|
||||
#define atrLowerBufferIndex 1
|
||||
double atrLowerBuffer[];
|
||||
|
||||
#property indicator_label2 "X121 ATRL"
|
||||
#property indicator_type2 DRAW_LINE
|
||||
#property indicator_color2 clrYellow
|
||||
#property indicator_style2 STYLE_SOLID
|
||||
#property indicator_width2 2
|
||||
#define rawHKBufferIndex 0
|
||||
#property indicator_label1 "X121 XHK Open;X121 XHK High;X121 XHK Low;X121 XHK Close"
|
||||
#property indicator_type1 DRAW_COLOR_CANDLES
|
||||
#property indicator_color1 CLR_NONE, clrDodgerBlue, clrDarkGoldenrod
|
||||
|
||||
//
|
||||
// Data Buffers ...
|
||||
// Open ...
|
||||
#define openBufferIndex 5
|
||||
double openBuffer[];
|
||||
|
||||
//
|
||||
int mLastBufferIndex = 1;
|
||||
// High ...
|
||||
#define highBufferIndex 6
|
||||
double highBuffer[];
|
||||
|
||||
//
|
||||
// ATR ...
|
||||
|
||||
#define atrBufferIndex mLastBufferIndex + 1
|
||||
double atrBuffer[];
|
||||
|
||||
#define atrUpperRawBufferIndex mLastBufferIndex + 2
|
||||
double atrUpperRawBuffer[];
|
||||
|
||||
#define atrLowerRawBufferIndex mLastBufferIndex + 3
|
||||
double atrLowerRawBuffer[];
|
||||
// Low ...
|
||||
#define lowBufferIndex 7
|
||||
double lowBuffer[];
|
||||
|
||||
//
|
||||
// RSI ...
|
||||
#define rsiBufferIndex mLastBufferIndex + 4
|
||||
double rsiBuffer[];
|
||||
// Close ...
|
||||
#define closeBufferIndex 8
|
||||
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 ...
|
||||
@@ -138,17 +136,6 @@ int limit;
|
||||
int maxLength;
|
||||
|
||||
//
|
||||
// RSI Handler ...
|
||||
int rsiHandler = INVALID_HANDLE;
|
||||
|
||||
//
|
||||
// ATR Handler ...
|
||||
int atrHandler = INVALID_HANDLE;
|
||||
|
||||
//
|
||||
bool isStrTrendChanged;
|
||||
bool isStrStartBearishTrend;
|
||||
bool isStrStartBullishTrend;
|
||||
|
||||
//
|
||||
// Event Handlers ...
|
||||
@@ -170,33 +157,6 @@ int OnInit()
|
||||
//
|
||||
// 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
|
||||
// calculation and we must prevent any calculation
|
||||
@@ -237,8 +197,6 @@ void OnDeinit(const int reason)
|
||||
// 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)
|
||||
? rates_total
|
||||
: (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 ...
|
||||
for (int i = limit - 1; i >= 0 && !IsStopped(); i--)
|
||||
@@ -381,12 +285,7 @@ bool ValidateInputs()
|
||||
//
|
||||
bool result =
|
||||
//
|
||||
// RSI ...
|
||||
rsiLength > 0 &&
|
||||
//
|
||||
// ATR ...
|
||||
atrLength > 0 &&
|
||||
atrMultiplier > 0
|
||||
true
|
||||
//
|
||||
;
|
||||
|
||||
@@ -405,7 +304,7 @@ int ExtractMaxLengthOfInputs()
|
||||
int result = 0;
|
||||
|
||||
//
|
||||
result = MathMax(rsiLength, atrLength);
|
||||
result = MathMax(0, xhkSmoothingLength);
|
||||
|
||||
//
|
||||
return result;
|
||||
@@ -416,53 +315,72 @@ int ExtractMaxLengthOfInputs()
|
||||
*/
|
||||
void DefineBuffers()
|
||||
{
|
||||
//
|
||||
// ATR ...
|
||||
|
||||
//
|
||||
// UPPER ...
|
||||
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);
|
||||
// RAW ...
|
||||
|
||||
//
|
||||
// LOWER ...
|
||||
bool canShowAtrLower = showAtrLower;
|
||||
ENUM_DRAW_TYPE atrLowerDrawType = canShowAtrLower ? DRAW_LINE : DRAW_NONE;
|
||||
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);
|
||||
// Raw Candles Color ...
|
||||
ArraySetAsSeries(rawHKColorBuffer, true);
|
||||
SetIndexBuffer(rawHKColorBufferIndex, rawHKColorBuffer, INDICATOR_COLOR_INDEX);
|
||||
|
||||
//
|
||||
// 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);
|
||||
SetIndexBuffer(atrBufferIndex, atrBuffer, INDICATOR_CALCULATIONS);
|
||||
// High ...
|
||||
ArraySetAsSeries(highHKBuffer, true);
|
||||
SetIndexBuffer(highHKBufferIndex, highHKBuffer, INDICATOR_DATA);
|
||||
|
||||
//
|
||||
ArraySetAsSeries(atrUpperRawBuffer, true);
|
||||
SetIndexBuffer(atrUpperRawBufferIndex, atrUpperRawBuffer, INDICATOR_CALCULATIONS);
|
||||
// Close ...
|
||||
ArraySetAsSeries(closeHKBuffer, true);
|
||||
SetIndexBuffer(closeHKBufferIndex, closeHKBuffer, INDICATOR_DATA);
|
||||
|
||||
//
|
||||
ArraySetAsSeries(atrLowerRawBuffer, true);
|
||||
SetIndexBuffer(atrLowerRawBufferIndex, atrLowerRawBuffer, INDICATOR_CALCULATIONS);
|
||||
// Low ...
|
||||
ArraySetAsSeries(lowHKBuffer, true);
|
||||
SetIndexBuffer(lowHKBufferIndex, lowHKBuffer, INDICATOR_DATA);
|
||||
|
||||
//
|
||||
// RSI ...
|
||||
// SMOOTHED ...
|
||||
|
||||
//
|
||||
ArraySetAsSeries(rsiBuffer, true);
|
||||
SetIndexBuffer(rsiBufferIndex, rsiBuffer, INDICATOR_CALCULATIONS);
|
||||
// Candles Color ...
|
||||
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
|
||||
: 0;
|
||||
//
|
||||
// bool canCalculate = true;
|
||||
bool canCalculate =
|
||||
barsLimit == 0 ||
|
||||
bar_index <= barsLimit;
|
||||
if (canCalculate)
|
||||
{
|
||||
//
|
||||
CalculateAtrZones(
|
||||
CalculateXHK(
|
||||
bar_index,
|
||||
prevCalculated,
|
||||
ratesTotal,
|
||||
@@ -535,16 +452,18 @@ void CalculateBuffers(
|
||||
void FillBuffersZero(int barIndex)
|
||||
{
|
||||
//
|
||||
// RSIS ...
|
||||
rsiBuffer[barIndex] = 0;
|
||||
lowHKBuffer[barIndex] = 0.0;
|
||||
openHKBuffer[barIndex] = 0.0;
|
||||
highHKBuffer[barIndex] = 0.0;
|
||||
closeHKBuffer[barIndex] = 0.0;
|
||||
rawHKColorBuffer[barIndex] = hideColorIDX;
|
||||
|
||||
//
|
||||
// ATRS ...
|
||||
atrBuffer[barIndex] = 0;
|
||||
atrUpperBuffer[barIndex] = 0;
|
||||
atrUpperRawBuffer[barIndex] = 0;
|
||||
atrUpperBuffer[barIndex] = 0;
|
||||
atrLowerRawBuffer[barIndex] = 0;
|
||||
lowBuffer[barIndex] = 0.0;
|
||||
openBuffer[barIndex] = 0.0;
|
||||
highBuffer[barIndex] = 0.0;
|
||||
closeBuffer[barIndex] = 0.0;
|
||||
candleColorBuffer[barIndex] = hideColorIDX;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -558,7 +477,7 @@ void FillBuffersZero(int barIndex)
|
||||
* @param close: Double Array, History of Close Prices ...
|
||||
* @param low: Double Array, History of Low Prices ...
|
||||
*/
|
||||
void CalculateAtrZones(
|
||||
void CalculateXHK(
|
||||
int bar_index, // Selected Bar Index
|
||||
const int prevCalculated,
|
||||
const int ratesTotal,
|
||||
@@ -569,79 +488,128 @@ void CalculateAtrZones(
|
||||
)
|
||||
{
|
||||
//
|
||||
// Select ATr Value ...
|
||||
double atrValue = atrBuffer[bar_index];
|
||||
double appliedAtrMultiplierValue = atrValue * atrMultiplier;
|
||||
double mPrevHKOpenValue;
|
||||
double mPrevHKCloseValue;
|
||||
|
||||
//
|
||||
// Select Upper Price ...
|
||||
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)
|
||||
if (ArraySize(open) <= bar_index + 1)
|
||||
{
|
||||
//
|
||||
// Upper ...
|
||||
iMAOnBuffer(
|
||||
ratesTotal,
|
||||
prevCalculated,
|
||||
bar_index,
|
||||
atrLength,
|
||||
atrUpperRawBuffer,
|
||||
atrUpperBuffer,
|
||||
atrSmoothingMode //
|
||||
);
|
||||
|
||||
//
|
||||
// Lower ...
|
||||
iMAOnBuffer(
|
||||
ratesTotal,
|
||||
prevCalculated,
|
||||
bar_index,
|
||||
atrLength,
|
||||
atrLowerRawBuffer,
|
||||
atrLowerBuffer,
|
||||
atrSmoothingMode //
|
||||
);
|
||||
mPrevHKOpenValue = 0;
|
||||
mPrevHKCloseValue = 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
//
|
||||
// Use Raw Values ...
|
||||
atrUpperBuffer[bar_index] = atrUpperRawValue;
|
||||
atrLowerBuffer[bar_index] = atrLowerRawValue;
|
||||
mPrevHKOpenValue = openHKBuffer[bar_index + 1];
|
||||
mPrevHKCloseValue = closeHKBuffer[bar_index + 1];
|
||||
}
|
||||
|
||||
//
|
||||
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 "../Classes/x-121.smc.market.cycle.helper.class.mq5"
|
||||
#include "../Libraries/x-121.smc.lib.mq5"
|
||||
#include "../Libraries/x-121.smc.guard.lib.mq5"
|
||||
|
||||
//
|
||||
// Definitions ...
|
||||
|
||||
Reference in New Issue
Block a user