last works on XOBS ...

This commit is contained in:
2025-02-07 02:22:19 +03:30
parent 114f327efe
commit 58c59f5514
11 changed files with 6802 additions and 1396 deletions
+458 -4
View File
@@ -135,6 +135,35 @@ enum ENUM_X_SWING_TYPE
X_SWING_LOW = -1,
};
//
string ToString(ENUM_X_SWING_TYPE value)
{
//
string result = NULL;
//
switch (value)
{
//
case X_NO_SWING:
result = "NO_SWING";
break;
//
case X_SWING_LOW:
result = "SWING_LOW";
break;
//
case X_SWING_HIGH:
result = "SWING_HIGH";
break;
}
//
return result;
}
//
ENUM_SERIESMODE ToSeriesMode(ENUM_X_SWING_TYPE value)
{
@@ -1163,6 +1192,34 @@ struct XOHCL
return result;
}
//
// Retrieve Required Price for Zone Checking ...
// For Bullish Zones => low;
// For Bearish Zones => high;
double GetZoneCheckValue(ENUM_X_DIRECTION forDir)
{
//
double result = 0;
//
if (!IsValid() ||
!HasDirection(forDir))
{
return result;
}
//
bool isBullish = IsBullish(forDir);
//
result =
isBullish
? low
: high;
return result;
}
//
// Calculate Bar Body ...
double GetBody()
@@ -3522,6 +3579,133 @@ struct XMarketParser
//
};
//
// Specified Swing Point ...
struct XSwingPoint
{
//
// Props ...
string symbol;
ENUM_TIMEFRAMES period;
//
double swing;
datetime time;
ENUM_X_SWING_TYPE type;
//
// Constructor ...
XSwingPoint()
{
Clean();
}
//
// Tools ...
/**
* Cleanup Model ...
*/
void Clean()
{
//
swing = 0;
time = NULL;
//
symbol = NULL;
period = NULL;
//
type = X_NO_SWING;
}
/**
* Validate Model ...
*
* @return ( bool )
*/
bool IsValid()
{
//
bool result = false;
//
result =
swing > 0 &&
IsValid(time) &&
IsValid(symbol) &&
IsValid(period) &&
type != X_NO_SWING;
//
return result;
}
/**
* Check Swing is Low or not ...
*
* @return ( bool )
*/
bool IsSwingLow()
{
return type == X_SWING_LOW;
}
/**
* Check Swing is High or not ...
*
* @return ( bool )
*/
bool IsSwingHigh()
{
return type == X_SWING_HIGH;
}
};
/**
* Extract values of swings from specified Collection ...
*
* @param swings: XSwingPoint instance Collection ...
* @param values: double Collection ...
*
* @return ( int )
*/
int ExtractSwings(
XSwingPoint &swings[],
double &values[] //
)
{
//
int result = 0;
//
Clean(values);
//
int count = ArraySize(swings);
if (!IsValidSize(count))
{
return result;
}
//
for (int i = 0; i < count; i++)
{
//
Add(
swings[i].swing,
values //
);
}
//
result = ArraySize(values);
//
return result;
}
//
// Functions ...
@@ -7544,6 +7728,61 @@ T GetMax(
return result;
}
template <typename T>
T GetMax(
T &buffer[], // the Buffer which required to search
int &index, // Item Index ...
int start = 0, // Start Index
int count = 0 // Count for Search
)
{
//
T result = 0;
index = -1;
//
if (count <= 0)
{
count = ArraySize(buffer);
}
//
T tmp[];
int tmpCount = Copy(
start,
count,
buffer,
tmp
//
);
if (tmpCount <= 0)
{
return result;
}
//
// Loop Through LoopBack ...
for (int i = 0; i < tmpCount; i++)
{
//
T iValue = tmp[i];
//
bool isNew = result == 0;
bool canSet = isNew ||
(!isNew &&
result < iValue);
if (canSet)
{
//
index = i;
result = iValue;
}
}
//
return result;
}
template <typename T>
T GetSpecifiedMax(
T &buffer[], // the Buffer which required to search
int start = 0, // Start Index
@@ -7556,6 +7795,21 @@ T GetSpecifiedMax(
count //
);
}
template <typename T>
T GetSpecifiedMax(
T &buffer[], // the Buffer which required to search
int &index, // Item Index ...
int start = 0, // Start Index
int count = 0 // Count for Search
)
{
return GetMax(
buffer,
index,
start,
count //
);
}
//
// Get Min of Specific Loopback of a Buffer ...
@@ -7612,6 +7866,61 @@ T GetMin(
return result;
}
template <typename T>
T GetMin(
T &buffer[], // the Buffer which required to search
int &index, // Item Index ...
int start = 0, // Start Index
int count = 0 // Count for Search
)
{
//
T result = 0;
index = -1;
//
if (count <= 0)
{
count = ArraySize(buffer);
}
//
T tmp[];
int tmpCount = Copy(
start,
count,
buffer,
tmp
//
);
if (tmpCount <= 0)
{
return result;
}
//
// Loop Through LoopBack ...
for (int i = 0; i < tmpCount; i++)
{
//
T iValue = tmp[i];
//
bool isNew = result == 0;
bool canSet = isNew ||
(!isNew &&
result > iValue);
if (canSet)
{
//
index = i;
result = iValue;
}
}
//
return result;
}
template <typename T>
T GetSpecifiedMin(
T &buffer[], // the Buffer which required to search
int start = 0, // Start Index
@@ -7624,6 +7933,21 @@ T GetSpecifiedMin(
count //
);
}
template <typename T>
T GetSpecifiedMin(
T &buffer[], // the Buffer which required to search
int &index, // Item Index ...
int start = 0, // Start Index
int count = 0 // Count for Search
)
{
return GetMin(
buffer,
index,
start,
count //
);
}
//
// Find a Value less than Specified ...
@@ -7651,12 +7975,14 @@ T FindLesserThan(
//
ArrayResize(
tmp,
ArraySize(source));
ArraySize(source) //
);
//
ArrayCopy(
tmp,
source);
source //
);
//
// Sort Temp Buffer ...
@@ -7685,6 +8011,69 @@ T FindLesserThan(
//
return result;
}
template <typename T>
T FindLesserThan(
T value, // Specified Value ...
int &index, // Item Index ...
const T &source[], // Source ...
bool isDescend = false // Find Biggest Lesser Value ...
)
{
//
T result = -1;
index = -1;
//
int itemsCount = ArraySize(source);
if (itemsCount <= 0)
{
return result;
}
//
// Make a Copy of source ...
T tmp[];
//
ArrayResize(
tmp,
ArraySize(source) //
);
//
ArrayCopy(
tmp,
source //
);
//
// Sort Temp Buffer ...
ArraySort(tmp);
if (isDescend)
{
ArrayReverse(tmp);
}
//
int tmpCount = ArraySize(tmp);
for (int i = 0; i < tmpCount; i++)
{
//
T iValue = tmp[i];
//
if (iValue < value)
{
//
index = i;
result = iValue;
break;
}
}
//
return result;
}
//
// Find a Value less than Specified ...
@@ -7712,12 +8101,14 @@ T FindBiggerThan(
//
ArrayResize(
tmp,
ArraySize(source));
ArraySize(source) //
);
//
ArrayCopy(
tmp,
source);
source //
);
//
// Sort Temp Buffer ...
@@ -7746,6 +8137,69 @@ T FindBiggerThan(
//
return result;
}
template <typename T>
T FindBiggerThan(
T value, // Specified Value ...
int &index, // Item Index ...
const T &source[], // Source ...
bool isDescend = false // Find Smallest Bigger Value ...
)
{
//
T result = -1;
index = -1;
//
int itemsCount = ArraySize(source);
if (itemsCount <= 0)
{
return result;
}
//
// Make a Copy of source ...
T tmp[];
//
ArrayResize(
tmp,
ArraySize(source) //
);
//
ArrayCopy(
tmp,
source //
);
//
// Sort Temp Buffer ...
ArraySort(tmp);
if (!isDescend)
{
ArrayReverse(tmp);
}
//
int tmpCount = ArraySize(tmp);
for (int i = 0; i < tmpCount; i++)
{
//
T iValue = tmp[i];
//
if (iValue > value)
{
//
index = i;
result = iValue;
break;
}
}
//
return result;
}
//
// Find Same Values in Array ...
File diff suppressed because it is too large Load Diff
+183
View File
@@ -300,6 +300,189 @@ ENUM_X_DIRECTION ToDirection(ENUM_X_POSITION_TYPES value)
//
// Structs ...
//
struct XRR
{
//
double tps[];
//
double sl;
double entry;
//
string prefix;
string symbol;
datetime time;
ENUM_TIMEFRAMES period;
//
ENUM_X_POSITION_TYPES type;
//
// Constructor ...
XRR()
{
Clean();
}
//
// Tools ...
//
void Clean()
{
//
sl = 0;
entry = 0;
//
time = NULL;
prefix = NULL;
period = NULL;
symbol = NULL;
//
type = X_POSITION_TYPE_NONE;
//
Clean(tps);
}
//
bool Init(
string _symbol,
ENUM_TIMEFRAMES _period,
double _sl,
double _entry,
ENUM_X_POSITION_TYPES _type,
string _prefix = NULL //
)
{
//
bool result = false;
//
result =
_sl > 0 &&
_entry > 0 &&
IsValid(_symbol) &&
IsValid(_period) &&
_type != X_POSITION_TYPE_ALL &&
_type != X_POSITION_TYPE_NONE &&
(_type == X_POSITION_TYPE_LONG
? _entry > _sl
: _entry < _sl);
if (!result)
{
return result;
}
//
Default();
//
sl = _sl;
type = _type;
entry = _entry;
symbol = _symbol;
period = _period;
prefix = _prefix;
//
time = TimeCurrent();
//
result = IsValid();
//
return result;
}
//
void Default()
{
//
Add(
1.0,
tps //
);
Add(
1.5,
tps //
);
Add(
2.0,
tps //
);
Add(
3.0,
tps //
);
Add(
4.0,
tps //
);
Add(
5.0,
tps //
);
Add(
6.0,
tps //
);
}
//
bool IsValid()
{
//
bool result = false;
//
result =
sl > 0 &&
entry > 0 &&
IsValid(time) &&
IsValid(symbol) &&
IsValid(period) &&
IsValidSize(ArraySize(tps)) &&
type != X_POSITION_TYPE_ALL &&
type != X_POSITION_TYPE_NONE &&
(type == X_POSITION_TYPE_LONG
? entry > 0
: entry < sl);
//
return result;
}
//
string GetTag()
{
//
string result = NULL;
//
if (!IsValid())
{
//
result = GetTypeName(this);
return result;
}
//
string sep = "_";
//
result =
GetTypeName(this) + sep + (IsValid(prefix) ? prefix + sep : "") + symbol + sep + ToString(period) + sep + ToFormatString(time) + sep + ToString(type);
//
return result;
}
};
//
// Model an Open Position ...
struct XPosition