last works on trend detector and try to test it inside x-test.ea.mq5 ...

This commit is contained in:
2024-07-10 16:01:33 +03:30
parent 6ba4fc1a70
commit 9ab980be84
3 changed files with 684 additions and 82 deletions
+259 -75
View File
@@ -1426,7 +1426,8 @@ struct XZone
//
// Check Zone Rejected ...
bool IsSupportRejected() {
bool IsSupportRejected()
{
//
bool result = false;
@@ -1434,17 +1435,17 @@ struct XZone
// Check is Full Support or Not ...
ENUM_XZONE_STATE state = GetState();
result = state == XZONE_STATE_FULL_SUPPORT;
if (!result) {
if (!result)
{
return result;
}
}
//
// First Check Price Rejection Above Upper Line ...
//
return result;
}
}
//
// Check Zone Breaked ...
@@ -1704,89 +1705,272 @@ struct XZone
// }
// };
// //
// // Detect Trends ...
// struct XTrendDetector
// {
// //
// string symbol;
// ENUM_TIMEFRAMES period;
//
// Detect Trends ...
struct XTrendDetector
{
//
string symbol;
ENUM_TIMEFRAMES period;
// //
// double higherHighs[];
// datetime higherHighTimes[];
//
double higherHighs[];
datetime higherHighTimes[];
// //
// double higherLows[];
// datetime higherLowTimes[];
//
double higherLows[];
datetime higherLowTimes[];
// //
// double lowerHighs[];
// datetime lowerHighTimes[];
//
double lowerHighs[];
datetime lowerHighTimes[];
// //
// double lowerLows[];
// datetime lowerLowTimes[];
//
double lowerLows[];
datetime lowerLowTimes[];
// //
// int _numberOfPivots;
// int _pivotShoulders;
//
int _numberOfPivots;
int _pivotShoulders;
// //
// // Constructor ...
// XTrendDetector()
// {
// Clean();
// }
//
// Constructor ...
XTrendDetector()
{
Clean();
}
// //
// // Tools ...
//
bool FindTrend(
string _symbol,
ENUM_TIMEFRAMES _period,
int barIndex = 0,
int _requiredPivots = 5,
int _requiredShoulders = 5 //
)
{
//
bool result = false;
// //
// // Cleanup ...
// void Clean()
// {
// //
// symbol = NULL;
// period = NULL;
//
if (barIndex < 0)
{
barIndex = 0;
}
// //
// _numberOfPivots = 0;
// _pivotShoulders = 0;
//
if (_requiredPivots < 5)
{
_requiredPivots = 5;
}
// //
// Clean(higherHighs);
// Clean(higherHighTimes);
//
if (_requiredShoulders < 5)
{
_requiredShoulders = 5;
}
// //
// Clean(higherLows);
// Clean(higherLowTimes);
//
result =
//
IsValid(_symbol) &&
IsValid(_period)
//
;
if (!result)
{
return result;
}
// //
// Clean(lowerHighs);
// Clean(lowerHighTimes);
//
// Find Swing Lows and Swing Highs ...
// //
// Clean(lowerLows);
// Clean(lowerLowTimes);
// }
//
int hhIndexes[];
datetime hhTimes[];
double hhs[];
// //
// // Validate ...
// bool IsValid()
// {
// //
// bool result = false;
//
int llIndexes[];
datetime llTimes[];
double lls[];
// //
// result =
// //
// IsValid(symbol) &&
// IsValid(period)
// //
// ;
//
bool isEnough = false;
int lastHHIndex = barIndex;
int lastLLIndex = barIndex;
while (!isEnough)
{
//
int hhSize = ArraySize(hhs);
if (hhSize < _requiredPivots)
{
//
lastHHIndex = FindSwing(
_symbol,
_period,
X_SWING_HIGH,
_requiredShoulders,
lastHHIndex + 1 //
);
if (lastHHIndex >= 0)
{
//
XOHCL hBar;
bool isInited = hBar.Init(
_symbol,
_period,
lastHHIndex //
);
if (isInited)
{
//
Add(
hBar.high,
hhs //
);
// //
// return result;
// }
// };
//
Add(
hBar.time,
hhTimes //
);
//
Add(
lastHHIndex,
hhIndexes //
);
}
}
}
//
int llSize = ArraySize(lls);
if (llSize < _requiredPivots)
{
//
lastLLIndex = FindSwing(
_symbol,
_period,
X_SWING_LOW,
_requiredShoulders,
lastLLIndex + 1 //
);
if (lastLLIndex >= 0)
{
//
XOHCL lBar;
bool isInited = lBar.Init(
_symbol,
_period,
lastLLIndex //
);
if (isInited)
{
//
Add(
lBar.low,
lls //
);
//
Add(
lBar.time,
llTimes //
);
//
Add(
lastHHIndex,
llIndexes //
);
}
}
}
//
hhSize = ArraySize(hhs);
llSize = ArraySize(lls);
isEnough =
//
hhSize == _requiredPivots &&
llSize == _requiredPivots
//
;
}
// //
// ArrayReverse(hhs);
// ArrayReverse(hhTimes);
// ArrayReverse(hhIndexes);
// //
// ArrayReverse(lls);
// ArrayReverse(llTimes);
// ArrayReverse(llIndexes);
//
symbol = _symbol;
period = _period;
_numberOfPivots = _requiredPivots;
_pivotShoulders = _requiredShoulders;
//
result = IsValid();
//
return result;
}
//
// Tools ...
//
// Cleanup ...
void Clean()
{
//
symbol = NULL;
period = NULL;
//
_numberOfPivots = 0;
_pivotShoulders = 0;
//
Clean(higherHighs);
Clean(higherHighTimes);
//
Clean(higherLows);
Clean(higherLowTimes);
//
Clean(lowerHighs);
Clean(lowerHighTimes);
//
Clean(lowerLows);
Clean(lowerLowTimes);
}
//
// Validate ...
bool IsValid()
{
//
bool result = false;
//
result =
//
IsValid(symbol) &&
IsValid(period)
//
;
//
return result;
}
};