complete conditions Calculation ...

This commit is contained in:
2024-05-19 13:55:02 +03:30
parent 4eba93231a
commit d70845c664
4 changed files with 1736 additions and 6 deletions
+356
View File
@@ -2195,6 +2195,125 @@ struct XMarketCycle
return result;
}
//
// Extract Specific Range of Bars ...
// using Start Bar Index ...
int GetBars(
XOHCL &result[], // Hold Result
int from = 0, // Start Bar Index
int count = 1, // Number of Bars
bool forceClean = true // Clean Result Array
)
{
//
int mResult = 0;
//
if (from < 0)
{
from = 0;
}
//
int total = Bars(
symbol,
period);
if (from > total - 2)
{
from = total - 2;
}
//
if (count < 0)
{
count = 1;
}
//
int start = from;
int end = start + count;
if (end > total - 1)
{
end = total - 1;
}
//
if (forceClean)
{
Clean(result);
}
//
int beforeSize = ArraySize(result);
//
for (int i = start; i < end; i++)
{
//
XOHCL iBar;
bool isValid = iBar.Init(
symbol,
period,
i
//
);
//
if (isValid)
{
//
AddRef(
iBar,
result
//
);
}
}
//
int afterSize = ArraySize(result);
//
mResult = afterSize - beforeSize;
//
return mResult;
}
//
// Extract Specific Range of Bars ...
// using Start Bar Time ...
int GetBars(
XOHCL &result[], // Hold Result
datetime from = NULL, // Start Bar Time
int count = 1, // Number of Bars
bool forceClean = true // Clean Result Array
)
{
//
from = NormalizeTime(from);
//
int barIndex = iBarShift(
symbol,
period,
from,
false
//
);
//
return GetBars(
result,
symbol,
period,
barIndex,
count,
forceClean
//
);
}
//
// Retrieve Bar Time ...
datetime GetBarTime(int barIndex)
@@ -3296,6 +3415,49 @@ MqlDateTime GetBarTimeStruct(
//
// Other Tools ...
//
template <typename T>
bool IsSame(
T &buffer[], // Search Buffer
int count = 5 // Number of Searchs
)
{
//
bool result = false;
//
int bufferSize = ArraySize(buffer);
result = bufferSize > 0;
if (!result) {
return result;
}
//
// Validate Count ...
result = count < bufferSize;
if (!result) {
return result;
}
//
T iTem = buffer[0];
for (int i = 0; i < count; i++) {
//
if (iTem != buffer[i]) {
result = false;
break;
}
//
if (!result) {
result = true;
}
}
//
return result;
}
//
// Check first Cross Over second at index ...
bool IsCrossedOver(
@@ -3400,6 +3562,200 @@ bool IsUnder(
return result;
}
//
// Check if a Value Increasing in Loopback ...
bool IsIncreasing(
const int from, // Last Time Index
const int to, // Fisr Tima Index
const double &buffer[] // the Buffer which required to search
)
{
//
bool result = false;
//
// Validate Args ...
if (
from <= to ||
ArraySize(buffer) < from + 1)
{
return result;
}
//
// Loop through Items ...
double toValue = buffer[to];
double fromValue = buffer[from];
result = toValue > fromValue;
for (int i = to + 1; i <= from - 1; i++)
{
//
double iValue = buffer[i];
bool isPassed = toValue >= iValue;
//
bool isIIncreasing = IsIncreasing(
from,
i,
buffer);
//
// Check Result ...
result = result && isPassed && isIIncreasing;
if (!result)
{
break;
}
}
//
return result;
}
//
// Check if a Value Decreasing in Loopback ...
bool IsDecreasing(
const int from, // Last Time Index
const int to, // Fisr Tima Index
const double &buffer[] // the Buffer which required to search
)
{
//
bool result = false;
//
// Validate Args ...
if (
from <= to ||
ArraySize(buffer) < from + 1)
{
return result;
}
//
// Loop through Items ...
double toValue = buffer[to];
double fromValue = buffer[from];
result = toValue < fromValue;
for (int i = to + 1; i <= from - 1; i++)
{
//
double iValue = buffer[i];
bool isPassed = toValue <= iValue;
//
bool isIDecreasing = IsDecreasing(
from,
i,
buffer);
//
// Check Result ...
result = result && isPassed && isIDecreasing;
if (!result)
{
break;
}
}
//
return result;
}
//
bool IsTrendingUp(
const double &buffer1[], // First Buffer
const double &buffer2[] // Seccend Buffer
) {
//
bool result = false;
//
int buffer1Count = ArraySize(buffer1);
int buffer2Count = ArraySize(buffer2);
if (buffer1Count <= 0 || buffer2Count <= 0) {
return result;
}
//
int count = MathMin(buffer1Count, buffer2Count);
if (count <= 1) {
return result;
}
//
int upCounts = 0;
int downCounts = 0;
double value = MathAbs(buffer1[0] - buffer2[0]);
for (int i = 1; i < count; i++) {
//
double iValue = MathAbs(buffer1[i] - buffer2[i]);
//
if (value > iValue) {
upCounts++;
}
//
if (value < iValue) {
downCounts++;
}
}
//
result = upCounts > 1 && upCounts > downCounts;
//
return result;
}
//
bool IsTrendingDown(
const double &buffer1[], // First Buffer
const double &buffer2[] // Seccend Buffer
) {
//
bool result = false;
//
int buffer1Count = ArraySize(buffer1);
int buffer2Count = ArraySize(buffer2);
if (buffer1Count <= 0 || buffer2Count <= 0) {
return result;
}
//
int count = MathMin(buffer1Count, buffer2Count);
if (count <= 1) {
return result;
}
//
int upCounts = 0;
int downCounts = 0;
double value = MathAbs(buffer1[0] - buffer2[0]);
for (int i = 1; i < count; i++) {
//
double iValue = MathAbs(buffer1[i] - buffer2[i]);
//
if (value > iValue) {
upCounts++;
}
//
if (value < iValue) {
downCounts++;
}
}
//
result = downCounts > 1 && downCounts > upCounts;
//
return result;
}
//
// Calculate Slope of Specified Buffer at Specified Index ...
double GetSlope(