This commit is contained in:
2025-01-18 12:16:28 +03:30
parent 9cdd5b4c7d
commit e74f64c51e
10 changed files with 2111 additions and 1003 deletions
+426 -1
View File
@@ -270,6 +270,10 @@ struct X121XPVConditions
double hHHBuffer[];
double hLLBuffer[];
//
bool bullishTrendBuffer[];
bool bearishTrendBuffer[];
//
// Conditions ...
@@ -291,11 +295,15 @@ struct X121XPVConditions
bool isNewPeak;
bool isNewPeakOverLast;
bool isNewPeakUnderLast;
bool isRejectedPrevPeak;
bool isBreakedUpPrevPeak;
//
bool isNewVale;
bool isNewValeOverLast;
bool isNewValeUnderLast;
bool isRejectedPrevVale;
bool isBreakedDownPrevVale;
//
// Constructor ...
@@ -336,6 +344,10 @@ struct X121XPVConditions
Clean(hHHBuffer);
Clean(hLLBuffer);
//
Clean(bullishTrendBuffer);
Clean(bearishTrendBuffer);
//
ArraySetAsSeries(peaksBuffer, true);
ArraySetAsSeries(valesBuffer, true);
@@ -351,6 +363,10 @@ struct X121XPVConditions
ArraySetAsSeries(hHHBuffer, true);
ArraySetAsSeries(hLLBuffer, true);
//
ArraySetAsSeries(bullishTrendBuffer, true);
ArraySetAsSeries(bearishTrendBuffer, true);
//
// Conditions ...
@@ -366,11 +382,14 @@ struct X121XPVConditions
isNewPeak = false;
isNewPeakOverLast = false;
isNewPeakUnderLast = false;
isRejectedPrevPeak = false;
isBreakedUpPrevPeak = false;
//
isNewVale = false;
isNewValeOverLast = false;
isNewValeUnderLast = false;
isRejectedPrevVale = false;
isBreakedDownPrevVale = false;
}
/**
@@ -450,9 +469,13 @@ struct X121XPVConditions
ToString("isNewPeak", isNewPeak, ignoreFalseConditions, separator) +
ToString("isNewPeakOverLast", isNewPeakOverLast, ignoreFalseConditions, separator) +
ToString("isNewPeakUnderLast", isNewPeakUnderLast, ignoreFalseConditions, separator) +
ToString("isRejectedPrevPeak", isRejectedPrevPeak, ignoreFalseConditions, separator) +
ToString("isBreakedUpPrevPeak", isBreakedUpPrevPeak, ignoreFalseConditions, separator) +
ToString("isNewVale", isNewVale, ignoreFalseConditions, separator) +
ToString("isNewValeOverLast", isNewValeOverLast, ignoreFalseConditions, separator) +
ToString("isNewValeUnderLast", isNewValeUnderLast, ignoreFalseConditions, separator) +
ToString("isRejectedPrevVale", isRejectedPrevVale, ignoreFalseConditions, separator) +
ToString("isBreakedDownPrevVale", isBreakedDownPrevVale, ignoreFalseConditions, separator) +
//
""
//
@@ -1589,6 +1612,107 @@ class XCX121XPVHelper : public XCBaseHelper
);
}
//
// Trends ...
// //
// bool GetBullishTrend(
// int barIndex // Bar Index
// )
// {
// //
// if (barIndex < 0)
// {
// barIndex = 0;
// }
// //
// Calculate();
// //
// int count = ArraySize(bullishTrendBuffer);
// if (barIndex >= count)
// {
// barIndex = count - 1;
// }
// //
// return bullishTrendBuffer[barIndex];
// }
// //
// int CopyBullishTrend(
// int start, // Start
// int count, // Number of Items for read
// bool &buffer[], // Dest Buffer
// bool forceClean = true // Force To Clean buffer
// )
// {
// //
// // Update Calculations ...
// Calculate();
// //
// // Copy Items ...
// return Copy(
// start,
// count,
// bullishTrendBuffer,
// buffer,
// forceClean
// //
// );
// }
// //
// bool GetBearishTrend(
// int barIndex // Bar Index
// )
// {
// //
// if (barIndex < 0)
// {
// barIndex = 0;
// }
// //
// Calculate();
// //
// int count = ArraySize(bearishTrendBuffer);
// if (barIndex >= count)
// {
// barIndex = count - 1;
// }
// //
// return bearishTrendBuffer[barIndex];
// }
// //
// int CopyBearishTrend(
// int start, // Start
// int count, // Number of Items for read
// bool &buffer[], // Dest Buffer
// bool forceClean = true // Force To Clean buffer
// )
// {
// //
// // Update Calculations ...
// Calculate();
// //
// // Copy Items ...
// return Copy(
// start,
// count,
// bearishTrendBuffer,
// buffer,
// forceClean
// //
// );
// }
//
// Tools Function ...
@@ -1812,6 +1936,191 @@ class XCX121XPVHelper : public XCBaseHelper
return result;
}
/**
* Detect Market Structure Method 2 ...
*
* @param model: XMarketStructure instance Reference ...
*
* @return ( bool )
*/
bool DetectMarketStructure(
ENUM_X_DIRECTION &dir,
int pivotsCount = 3 //
)
{
//
bool result = false;
//
int barIndex = 0;
//
if (pivotsCount < 3)
{
pivotsCount = 3;
}
//
dir = X_DIRECTION_NONE;
string symbol = GetSymbol();
ENUM_TIMEFRAMES period = GetPeriod();
//
int hpIndex = -1;
int hpIndexes[];
double hpValues[];
//
int lvIndex = -1;
int lvIndexes[];
double lvValues[];
//
for (int i = 0; i < pivotsCount; i++)
{
//
hpIndex = barIndex;
lvIndex = barIndex;
//
double lastHP = 0;
double lastLV = 0;
//
int hpCount = ArraySize(hpIndexes);
int lvCount = ArraySize(lvIndexes);
//
if (IsValidSize(hpCount))
{
//
lastHP = hpValues[hpCount - 1];
hpIndex = hpIndexes[hpCount - 1];
}
//
if (IsValidSize(lvCount))
{
//
lastLV = lvValues[lvCount - 1];
lvIndex = lvIndexes[lvCount - 1];
}
//
if (lastHP == 0)
{
//
lastHP = GetPeak(hpIndex);
}
//
if (lastLV == 0)
{
//
lastLV = GetVale(lvIndex);
}
//
int highestPeakIndex = -1;
double highesrPeak =
GetHigherPeak(
highestPeakIndex,
lastHP,
hpIndex //
);
if (IsValidIndex(highestPeakIndex))
{
//
Add(
highestPeakIndex,
hpIndexes //
);
//
Add(
highesrPeak,
hpValues //
);
}
//
int lowestValeIndex = -1;
double lowestVale =
GetLowerVale(
lowestValeIndex,
lastLV,
lvIndex //
);
if (IsValidIndex(lowestValeIndex))
{
//
Add(
lowestValeIndex,
lvIndexes //
);
//
Add(
lowestVale,
lvValues //
);
}
//
bool canBreak = ArraySize(hpIndexes) >= pivotsCount ||
ArraySize(lvIndexes) >= pivotsCount;
if (canBreak)
{
break;
}
}
//
ArrayReverse(hpValues);
ArrayReverse(hpIndexes);
int countHPs = ArraySize(hpIndexes);
//
ArrayReverse(lvValues);
ArrayReverse(lvIndexes);
int countLVs = ArraySize(lvIndexes);
//
bool isValidHPs = countHPs >= pivotsCount;
bool isValidLVs = countLVs >= pivotsCount;
//
result = isValidHPs ||
isValidLVs;
if (!result)
{
return result;
}
//
if (isValidHPs && isValidLVs)
{
//
hpIndex = hpIndexes[countHPs - 1];
lvIndex = lvIndexes[countLVs - 1];
}
//
dir =
!isValidHPs && isValidLVs
? X_DIRECTION_BULLISH
: !isValidLVs && isValidHPs
? X_DIRECTION_BEARISH
: hpIndex < lvIndex
? X_DIRECTION_BEARISH
: lvIndex < hpIndex
? X_DIRECTION_BULLISH
: X_DIRECTION_ALL;
//
return result;
}
//
bool GetConditions(
X121XPVConditions &conditions, //
@@ -1972,6 +2281,48 @@ class XCX121XPVHelper : public XCBaseHelper
conditions.hLLBuffer //
);
// //
// CopyBullishTrend(
// zIndex,
// loopback,
// conditions.bullishTrendBuffer //
// );
// //
// CopyBearishTrend(
// zIndex,
// loopback,
// conditions.bearishTrendBuffer //
// );
//
for (int i = barIndex + 1; i < barIndex + 3; i++)
{
//
ENUM_X_DIRECTION iDirection;
bool iHasDirection = DetectMarketStructure(iDirection);
//
bool iHasBullishTrend = iHasDirection &&
IsBullish(iDirection);
//
bool iHasBearishTrend = iHasDirection &&
IsBearish(iDirection);
//
Add(
iHasBullishTrend,
conditions.bullishTrendBuffer //
);
//
Add(
iHasBearishTrend,
conditions.bearishTrendBuffer //
);
}
//
// Conditions ...
@@ -2005,6 +2356,16 @@ class XCX121XPVHelper : public XCBaseHelper
conditions.peaksBuffer[cIDX] > conditions.peaksBuffer[pIDX];
bool isNewPeakUnderLast = isNewPeak &&
conditions.peaksBuffer[cIDX] < conditions.peaksBuffer[pIDX];
bool isRejectedPrevPeak = IsBarReject(
conditions.peaksBuffer[pIDX],
X_DIRECTION_BEARISH,
cBar //
);
bool isBreakedUpPrevPeak = IsBarBreak(
conditions.peaksBuffer[pIDX],
X_DIRECTION_BULLISH,
cBar //
);
//
bool isNewVale = conditions.valesBuffer[cIDX] != conditions.valesBuffer[pIDX];
@@ -2012,6 +2373,16 @@ class XCX121XPVHelper : public XCBaseHelper
conditions.valesBuffer[cIDX] > conditions.valesBuffer[pIDX];
bool isNewValeUnderLast = isNewVale &&
conditions.valesBuffer[cIDX] < conditions.valesBuffer[pIDX];
bool isRejectedPrevVale = IsBarReject(
conditions.valesBuffer[pIDX],
X_DIRECTION_BULLISH,
cBar //
);
bool isBreakedDownPrevVale = IsBarBreak(
conditions.valesBuffer[pIDX],
X_DIRECTION_BEARISH,
cBar //
);
//
conditions.isSarBullish = isSarBullish;
@@ -2021,9 +2392,18 @@ class XCX121XPVHelper : public XCBaseHelper
conditions.isNewPeak = isNewPeak;
conditions.isNewPeakOverLast = isNewPeakOverLast;
conditions.isNewPeakUnderLast = isNewPeakUnderLast;
conditions.isRejectedPrevPeak = isRejectedPrevPeak;
conditions.isBreakedUpPrevPeak = isBreakedUpPrevPeak;
conditions.isNewVale = isNewVale;
conditions.isNewValeOverLast = isNewValeOverLast;
conditions.isNewValeUnderLast = isNewValeUnderLast;
conditions.isRejectedPrevVale = isRejectedPrevVale;
conditions.isBreakedDownPrevVale = isBreakedDownPrevVale;
// //
// if (isNewVale || isNewPeak) {
// CalculateTrend();
// }
//
return result;
@@ -2055,6 +2435,29 @@ class XCX121XPVHelper : public XCBaseHelper
double hHHBuffer[];
double hLLBuffer[];
//
// bool bullishTrendBuffer[];
// bool bearishTrendBuffer[];
//
// void AddTrend(
// bool isBullish,
// bool isBearish //
// )
// {
// //
// Add(
// isBullish,
// bullishTrendBuffer //
// );
// //
// Add(
// isBearish,
// bearishTrendBuffer //
// );
// }
//
void Calculate()
{
@@ -2229,6 +2632,28 @@ class XCX121XPVHelper : public XCBaseHelper
//
);
}
//
// void CalculateTrend()
// {
// //
// ENUM_X_DIRECTION iDirection;
// bool iHasDirection = DetectMarketStructure(iDirection);
// //
// bool iHasBullishTrend = iHasDirection &&
// IsBullish(iDirection);
// //
// bool iHasBearishTrend = iHasDirection &&
// IsBearish(iDirection);
// //
// AddTrend(
// iHasBullishTrend,
// iHasBearishTrend //
// );
// }
};
//