add support for xtrend indicator in x121 setup helper ...

This commit is contained in:
2025-02-09 22:51:56 +03:30
parent c79ee42d7c
commit 714a905a2a
5 changed files with 1416 additions and 71 deletions
+163 -51
View File
@@ -23,13 +23,12 @@
//
// Imports ...
#include "../Helpers/x-saherelm.x121.xatr.helper.mq5"
#include "../Helpers/x-saherelm.x121.xcc.helper.mq5"
#include "../Helpers/x-saherelm.x121.xche.helper.mq5"
#include "../Helpers/x-saherelm.x121.xct.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.xtrend.helper.mq5"
#include "../Helpers/x-saherelm.x121.xvwap.helper.mq5"
//
@@ -39,8 +38,6 @@ struct X121Inputs
//
// Props ...
bool showRSI;
X121XCCInputs xccInputs;
X121XCTInputs xctInputs;
X121XPVInputs xpvInputs;
X121XHKInputs xhkInputs;
X121XATRInputs xatrInputs;
@@ -48,6 +45,7 @@ struct X121Inputs
X121XCHEInputs xcheInputs;
X121XDONInputs xdonInputs;
X121XVWAPInputs xvwapInputs;
X121XTRENDInputs xtrendInputs;
//
// Constructor ...
@@ -65,8 +63,6 @@ struct X121Inputs
void Clean()
{
//
xccInputs.Clean();
xctInputs.Clean();
xpvInputs.Clean();
xhkInputs.Clean();
xatrInputs.Clean();
@@ -74,6 +70,7 @@ struct X121Inputs
xcheInputs.Clean();
xdonInputs.Clean();
xvwapInputs.Clean();
xtrendInputs.Clean();
//
ZeroMemory(this);
@@ -85,8 +82,6 @@ struct X121Inputs
void Default()
{
//
xccInputs.Default();
xctInputs.Default();
xpvInputs.Default();
xhkInputs.Default();
xatrInputs.Default();
@@ -94,6 +89,7 @@ struct X121Inputs
xcheInputs.Default();
xdonInputs.Default();
xvwapInputs.Default();
xtrendInputs.Default();
}
/**
@@ -109,15 +105,14 @@ struct X121Inputs
//
result =
//
xccInputs.IsValid() &&
xctInputs.IsValid() &&
xpvInputs.IsValid() &&
xhkInputs.IsValid() &&
xatrInputs.IsValid() &&
xstrInputs.IsValid() &&
xcheInputs.IsValid() &&
xdonInputs.IsValid() &&
xvwapInputs.IsValid()
xvwapInputs.IsValid() &&
xtrendInputs.IsValid()
//
;
@@ -136,8 +131,6 @@ struct X121Inputs
int result = 0;
//
int xccMax = xccInputs.Max();
int xctMax = xctInputs.Max();
int xpvMax = xpvInputs.Max();
int xhkMax = xpvInputs.Max();
int xatrMax = xatrInputs.Max();
@@ -145,15 +138,16 @@ struct X121Inputs
int xcheMax = xcheInputs.Max();
int xdonMax = xdonInputs.Max();
int xvwapMax = xvwapInputs.Max();
int xtrendMax = xtrendInputs.Max();
//
result = MathMax(xccMax, xctMax);
result = MathMax(result, xpvMax);
result = MathMax(xpvMax, xhkMax);
result = MathMax(result, xatrMax);
result = MathMax(result, xstrMax);
result = MathMax(result, xcheMax);
result = MathMax(result, xdonMax);
result = MathMax(result, xvwapMax);
result = MathMax(result, xtrendMax);
//
return result;
@@ -172,6 +166,7 @@ struct X121Conditions
//
// Buffers ...
double maBuffer[];
double rsiBuffer[];
double atrBuffer[];
double strBuffer[];
@@ -190,12 +185,18 @@ struct X121Conditions
double lLLBuffer[];
double hHHBuffer[];
double hLLBuffer[];
double upTBuffer[];
double adxBuffer[];
double adxPBuffer[];
double adxMBuffer[];
long volumeBuffer[];
double peaksBuffer[];
double valesBuffer[];
double strUpBuffer[];
double downTBuffer[];
double strDownBuffer[];
double vwapMidBuffer[];
double upTrendBuffer[];
double le1StartBuffer[];
double se1StartBuffer[];
double le2StartBuffer[];
@@ -207,6 +208,7 @@ struct X121Conditions
double vwapFastBuffer[];
double vwapSlowBuffer[];
double xhkSMLowBuffer[];
double downTrendBuffer[];
double vwapPriceBuffer[];
double xhkRawLowBuffer[];
double xhkSMOpenBuffer[];
@@ -242,6 +244,15 @@ struct X121Conditions
//
// Conditions ...
//
// XTrend ...
//
bool isTrendBullish;
bool isTrendBearish;
bool isTrendSwitchedToBullish;
bool isTrendSwitchedToBearish;
//
bool isRsiSlopeBullish;
bool isStrSlopeBullish;
@@ -601,6 +612,7 @@ struct X121Conditions
// Buffers ...
//
Clean(maBuffer);
Clean(rsiBuffer);
Clean(atrBuffer);
Clean(strBuffer);
@@ -619,12 +631,18 @@ struct X121Conditions
Clean(lLLBuffer);
Clean(hHHBuffer);
Clean(hLLBuffer);
Clean(upTBuffer);
Clean(adxBuffer);
Clean(adxPBuffer);
Clean(adxMBuffer);
Clean(volumeBuffer);
Clean(peaksBuffer);
Clean(valesBuffer);
Clean(strUpBuffer);
Clean(downTBuffer);
Clean(strDownBuffer);
Clean(vwapMidBuffer);
Clean(upTrendBuffer);
Clean(le1StartBuffer);
Clean(se1StartBuffer);
Clean(le2StartBuffer);
@@ -636,6 +654,7 @@ struct X121Conditions
Clean(vwapFastBuffer);
Clean(vwapSlowBuffer);
Clean(xhkSMLowBuffer);
Clean(downTrendBuffer);
Clean(vwapPriceBuffer);
Clean(xhkRawLowBuffer);
Clean(xhkSMOpenBuffer);
@@ -660,6 +679,7 @@ struct X121Conditions
Clean(donCloseLowerBuffer);
//
ArraySetAsSeries(maBuffer, true);
ArraySetAsSeries(rsiBuffer, true);
ArraySetAsSeries(atrBuffer, true);
ArraySetAsSeries(strBuffer, true);
@@ -678,12 +698,18 @@ struct X121Conditions
ArraySetAsSeries(lLLBuffer, true);
ArraySetAsSeries(hHHBuffer, true);
ArraySetAsSeries(hLLBuffer, true);
ArraySetAsSeries(upTBuffer, true);
ArraySetAsSeries(adxBuffer, true);
ArraySetAsSeries(adxPBuffer, true);
ArraySetAsSeries(adxMBuffer, true);
ArraySetAsSeries(volumeBuffer, true);
ArraySetAsSeries(peaksBuffer, true);
ArraySetAsSeries(valesBuffer, true);
ArraySetAsSeries(strUpBuffer, true);
ArraySetAsSeries(downTBuffer, true);
ArraySetAsSeries(strDownBuffer, true);
ArraySetAsSeries(vwapMidBuffer, true);
ArraySetAsSeries(upTrendBuffer, true);
ArraySetAsSeries(le1StartBuffer, true);
ArraySetAsSeries(se1StartBuffer, true);
ArraySetAsSeries(le2StartBuffer, true);
@@ -695,6 +721,7 @@ struct X121Conditions
ArraySetAsSeries(vwapFastBuffer, true);
ArraySetAsSeries(vwapSlowBuffer, true);
ArraySetAsSeries(xhkSMLowBuffer, true);
ArraySetAsSeries(downTrendBuffer, true);
ArraySetAsSeries(vwapPriceBuffer, true);
ArraySetAsSeries(xhkRawLowBuffer, true);
ArraySetAsSeries(xhkSMOpenBuffer, true);
@@ -1205,6 +1232,14 @@ struct X121Conditions
ToString("isSarSwitchedToBearish", isSarSwitchedToBearish, ignoreFalseConditions, separator) +
//
"-----------------------" + separator +
"Trend ..." + separator +
"-----------------------" + separator +
ToString("isTrendBullish", isTrendBullish, ignoreFalseConditions, separator) +
ToString("isTrendBearish", isTrendBearish, ignoreFalseConditions, separator) +
ToString("isTrendSwitchedToBullish", isTrendSwitchedToBullish, ignoreFalseConditions, separator) +
ToString("isTrendSwitchedToBearish", isTrendSwitchedToBearish, ignoreFalseConditions, separator) +
//
"-----------------------" + separator +
"STR ..." + separator +
"-----------------------" + separator +
ToString("isStrBullish", isStrBullish, ignoreFalseConditions, separator) +
@@ -1502,8 +1537,6 @@ class XCX121Helper : public XCBase
//
// Helpers ...
XCX121XCCHelper *xccHelper;
XCX121XCTHelper *xctHelper;
XCX121XPVHelper *xpvHelper;
XCX121XHKHelper *xhkHelper;
XCX121XATRHelper *xatrHelper;
@@ -1511,6 +1544,7 @@ class XCX121Helper : public XCBase
XCX121XCHEHelper *xcheHelper;
XCX121XDONHelper *xdonHelper;
XCX121XVWAPHelper *xvwapHelper;
XCX121XTRENDHelper *xtrendHelper;
//
// Constructors ...
@@ -1523,8 +1557,6 @@ class XCX121Helper : public XCBase
~XCX121Helper()
{
//
delete xccHelper;
delete xctHelper;
delete xpvHelper;
delete xhkHelper;
delete xatrHelper;
@@ -1532,10 +1564,9 @@ class XCX121Helper : public XCBase
delete xcheHelper;
delete xdonHelper;
delete xvwapHelper;
delete xtrendHelper;
//
ZeroMemory(xccHelper);
ZeroMemory(xctHelper);
ZeroMemory(xpvHelper);
ZeroMemory(xhkHelper);
ZeroMemory(xatrHelper);
@@ -1543,6 +1574,7 @@ class XCX121Helper : public XCBase
ZeroMemory(xcheHelper);
ZeroMemory(xdonHelper);
ZeroMemory(xvwapHelper);
ZeroMemory(xtrendHelper);
}
//
@@ -1597,8 +1629,6 @@ class XCX121Helper : public XCBase
//
mInputs = inputs;
xccInputs = inputs.xccInputs;
xctInputs = inputs.xctInputs;
xpvInputs = inputs.xpvInputs;
xhkInputs = inputs.xhkInputs;
xatrInputs = inputs.xatrInputs;
@@ -1606,36 +1636,11 @@ class XCX121Helper : public XCBase
xcheInputs = inputs.xcheInputs;
xdonInputs = inputs.xdonInputs;
xvwapInputs = inputs.xvwapInputs;
xtrendInputs = inputs.xtrendInputs;
//
// Initial Helpers ...
//
// XCC ...
xccHelper = new XCX121XCCHelper();
result = xccHelper.Init(
symbol,
period,
xccInputs //
);
if (!result)
{
return result;
}
//
// XCT ...
xctHelper = new XCX121XCTHelper();
result = xctHelper.Init(
symbol,
period,
xctInputs //
);
if (!result)
{
return result;
}
//
// XPV ...
xpvHelper = new XCX121XPVHelper();
@@ -1727,6 +1732,19 @@ class XCX121Helper : public XCBase
return result;
}
//
// XTREND ...
xtrendHelper = new XCX121XTRENDHelper();
result = xtrendHelper.Init(
symbol,
period,
xtrendInputs //
);
if (!result)
{
return result;
}
//
if (inputs.showRSI)
{
@@ -1907,6 +1925,28 @@ class XCX121Helper : public XCBase
return result;
}
//
// XTREND ...
bool GetTrendConditions(
X121XTRENDConditions &conditions, //
int barIndex = 0, //
int loopback = 5 //
)
{
//
bool result = false;
//
result = xtrendHelper.GetConditions(
conditions,
barIndex,
loopback //
);
//
return result;
}
//
bool GetConditions(
X121Conditions &conditions, //
@@ -2064,6 +2104,19 @@ class XCX121Helper : public XCBase
return result;
}
//
// XTREND ...
X121XTRENDConditions xtrendConditions;
result = GetTrendConditions(
xtrendConditions,
barIndex,
loopback //
);
if (!result)
{
return result;
}
//
// Fill Volume Buffer ...
for (int i = barIndex; i < barIndex + loopback; i++)
@@ -2275,6 +2328,66 @@ class XCX121Helper : public XCBase
conditions.isSMHKSwitchedToBullish = xhkConditions.isSMHKSwitchedToBullish;
conditions.isRawHKSwitchedToBullish = xhkConditions.isRawHKSwitchedToBullish;
//
// XTREND ...
//
// Buffers ...
//
Copy(
xtrendConditions.upTrendBuffer,
conditions.upTrendBuffer //
);
//
Copy(
xtrendConditions.downTrendBuffer,
conditions.downTrendBuffer //
);
//
Copy(
xtrendConditions.maBuffer,
conditions.maBuffer //
);
//
Copy(
xtrendConditions.adxBuffer,
conditions.adxBuffer //
);
//
Copy(
xtrendConditions.adxPBuffer,
conditions.adxPBuffer //
);
//
Copy(
xtrendConditions.adxMBuffer,
conditions.adxMBuffer //
);
//
Copy(
xtrendConditions.upTBuffer,
conditions.upTBuffer //
);
//
Copy(
xtrendConditions.downTBuffer,
conditions.downTBuffer //
);
//
conditions.isTrendBullish = xtrendConditions.isTrendBullish;
conditions.isTrendBearish = xtrendConditions.isTrendBearish;
conditions.isTrendSwitchedToBullish = xtrendConditions.isTrendSwitchedToBullish;
conditions.isTrendSwitchedToBearish = xtrendConditions.isTrendSwitchedToBearish;
//
// XATR ...
@@ -3224,8 +3337,6 @@ class XCX121Helper : public XCBase
//
// Inputs ...
X121Inputs mInputs;
X121XCCInputs xccInputs;
X121XCTInputs xctInputs;
X121XPVInputs xpvInputs;
X121XHKInputs xhkInputs;
X121XATRInputs xatrInputs;
@@ -3233,6 +3344,7 @@ class XCX121Helper : public XCBase
X121XSTRInputs xstrInputs;
X121XCHEInputs xcheInputs;
X121XVWAPInputs xvwapInputs;
X121XTRENDInputs xtrendInputs;
//
int mRSIHandler;
File diff suppressed because it is too large Load Diff
+32 -8
View File
@@ -41,7 +41,7 @@ input ENUM_APPLIED_PRICE trendPriceType = PRICE_CLOSE; // Detect Trend Price Typ
input group "MA Detection";
input int maLength = 50; // MA Length
input ENUM_MA_METHOD maMethod = MODE_EMA; // MA Method
input ENUM_APPLIED_PRICE maAppliedTo; // MA Applied To
input ENUM_APPLIED_PRICE maAppliedTo = PRICE_CLOSE; // MA Applied To
input group "ADX Detection";
input int adxLength = 14; // ADX Length
@@ -65,7 +65,7 @@ input bool showDownTrend = true; // Show Down Trend
#property indicator_chart_window
//
#property indicator_buffers 6
#property indicator_buffers 8
#property indicator_plots 2
//
@@ -113,6 +113,14 @@ double adxPBuffer[];
#define adxMBufferIndex mLastBufferIndex + 4
double adxMBuffer[];
//
#define upTBufferIndex mLastBufferIndex + 5
double upTBuffer[];
//
#define downTBufferIndex mLastBufferIndex + 6
double downTBuffer[];
//
// Variables, Properties and etc ...
@@ -469,6 +477,14 @@ void DefineBuffers()
//
ArraySetAsSeries(adxMBuffer, true);
SetIndexBuffer(adxMBufferIndex, adxMBuffer, INDICATOR_CALCULATIONS);
//
ArraySetAsSeries(upTBuffer, true);
SetIndexBuffer(upTBufferIndex, upTBuffer, INDICATOR_CALCULATIONS);
//
ArraySetAsSeries(downTBuffer, true);
SetIndexBuffer(downTBufferIndex, downTBuffer, INDICATOR_CALCULATIONS);
}
/**
@@ -602,18 +618,21 @@ void CalculateTrend(
// iValue = iLastValue;
// }
// //
// double iValue = low[bar_index] - points10;
//
double selectedValue = low[bar_index] - points10;
//
double iValue =
!IsBullish(lastTrendDir) ? low[bar_index] - points10
!IsBullish(lastTrendDir) ? selectedValue
: !showOnlyTrendStart
? lastValue
: 0;
//
upTrendBuffer[bar_index] = iValue;
upTBuffer[bar_index] = selectedValue;
//
downTrendBuffer[bar_index] = 0;
//
@@ -633,12 +652,12 @@ void CalculateTrend(
// iValue = iLastValue;
// }
// //
// double iValue = high[bar_index] + points10;
//
double selectedValue = high[bar_index] + points10;
//
double iValue =
!IsBearish(lastTrendDir) ? high[bar_index] + points10
!IsBearish(lastTrendDir) ? selectedValue
: !showOnlyTrendStart
? lastValue
: 0;
@@ -646,6 +665,7 @@ void CalculateTrend(
//
upTrendBuffer[bar_index] = 0;
downTrendBuffer[bar_index] = iValue;
downTBuffer[bar_index] = selectedValue;
//
lastValue = iValue;
@@ -669,6 +689,10 @@ void CalculateTrend(
upTrendBuffer[bar_index] = 0;
downTrendBuffer[bar_index] = 0;
//
upTBuffer[bar_index] = 0;
downTBuffer[bar_index] = 0;
//
lastValue = 0;
lastTrendDir = X_DIRECTION_NONE;
+3 -3
View File
@@ -22,7 +22,7 @@
//
// Imports ...
#include "../../Classes/x-saherelm.x-expert.class.mq5"
#include "../../Helpers/x-saherelm.x121.xatr.helper.mq5"
#include "../../Helpers/x-saherelm.x121.xct.helper.mq5"
#include "../../Helpers/x-saherelm.x121.xcc.helper.mq5"
#include "../Classes/x-121.smc.x-tradehandler.class.mq5"
#include "../Libraries/x-121.smc.lib.mq5"
@@ -1341,8 +1341,8 @@ class XC121SMCExpert : public XCBaseExpert
ZeroMemory(mTradeHandler);
//
delet xccHelper;
delet xctHelper;
delete xccHelper;
delete xctHelper;
delete mTradeHandler;
//
@@ -758,13 +758,10 @@ class XCX121SMCStrategy : public XCX121SMCBaseStrategy
x121Inputs.xatrInputs.atrSmoothingMode = X_MA_MODE_EMA;
//
// XCC ...
x121Inputs.xccInputs.showCandles = false; // false;
//
// XCT ...
x121Inputs.xctInputs.clr = clrBlueViolet;
x121Inputs.xctInputs.showCandleTime = false; // false;
// XTREND ...
x121Inputs.xtrendInputs.showUpTrend = showAll || false;
x121Inputs.xtrendInputs.showDownTrend = showAll || false;
x121Inputs.xtrendInputs.showOnlyTrendStart = showAll || false;
//
// XPV ...