last ...
This commit is contained in:
@@ -191,6 +191,101 @@ enum ENUM_X_MARKET_CYCLES
|
||||
//
|
||||
// Structs ...
|
||||
|
||||
//
|
||||
// Model Specified Ticks Info ...
|
||||
struct XTick
|
||||
{
|
||||
//
|
||||
string symbol; // Symbol ...
|
||||
datetime time; // Time ...
|
||||
double bid; // Bid ...
|
||||
double ask; // Ask ...
|
||||
|
||||
//
|
||||
// Constructor ...
|
||||
void XTick()
|
||||
{
|
||||
Clean();
|
||||
}
|
||||
|
||||
//
|
||||
// Tools Functions ...
|
||||
|
||||
/**
|
||||
* Initial ...
|
||||
*
|
||||
* @param _symbol: Symbol ...
|
||||
* @param _time: Time ...
|
||||
* @param _bid: Bid Price ...
|
||||
* @param _ask: Ask Price ...
|
||||
*/
|
||||
bool Init(
|
||||
string _symbol,
|
||||
datetime _time,
|
||||
double _bid,
|
||||
double _ask //
|
||||
)
|
||||
{
|
||||
//
|
||||
bool result = false;
|
||||
|
||||
//
|
||||
result = IsValid(_symbol) &&
|
||||
IsValid(_time) &&
|
||||
_bid > 0 &&
|
||||
_ask > 0;
|
||||
if (!result) {
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
symbol = _symbol;
|
||||
time = _time;
|
||||
bid = _bid;
|
||||
ask = _ask;
|
||||
|
||||
//
|
||||
result = IsValid();
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Cleanup ...
|
||||
*/
|
||||
void Clean()
|
||||
{
|
||||
//
|
||||
bid = 0;
|
||||
ask = 0;
|
||||
time = NULL;
|
||||
symbol = NULL;
|
||||
}
|
||||
|
||||
/**
|
||||
* Validate ...
|
||||
*
|
||||
* @return ( bool )
|
||||
*/
|
||||
bool IsValid()
|
||||
{
|
||||
//
|
||||
bool result = false;
|
||||
|
||||
//
|
||||
result = IsValid(symbol) &&
|
||||
IsValid(time) &&
|
||||
bid > 0 &&
|
||||
ask > 0;
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
};
|
||||
|
||||
//
|
||||
// Model a Bar Remains Time ...
|
||||
struct XBarRemainsTime
|
||||
@@ -1125,6 +1220,8 @@ struct XOHCL
|
||||
int destSeconds = PeriodSeconds(smallerPeriod);
|
||||
if (destSeconds >= sourceSeconds)
|
||||
{
|
||||
//
|
||||
result = time;
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
@@ -1358,4 +1358,290 @@ string ToString(ENUM_XPOI_EVENTS value)
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
// XOHCL Extensions ...
|
||||
|
||||
/**
|
||||
* Check two Bar is Same or not ...
|
||||
*
|
||||
* @param source: XOHCL instance ...
|
||||
* @param dest: XOHCL instance ...
|
||||
* @param force: Check also it's Dates ...
|
||||
*
|
||||
* @return ( bool )
|
||||
*/
|
||||
bool IsSame(
|
||||
XOHCL &source,
|
||||
XOHCL &dest //
|
||||
)
|
||||
{
|
||||
//
|
||||
bool result = false;
|
||||
|
||||
//
|
||||
result = source.IsValid() &&
|
||||
dest.IsValid();
|
||||
if (!result)
|
||||
{
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
result =
|
||||
source.open == dest.open &&
|
||||
source.close == dest.close &&
|
||||
source.high == dest.high &&
|
||||
source.low == dest.low;
|
||||
if (!result)
|
||||
{
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Find Specific Items Index inside a Collection ...
|
||||
*
|
||||
* @param source: XOHCL instance ...
|
||||
* @param dest: XOHCL instance Collection ...
|
||||
*
|
||||
* @return ( int )
|
||||
*/
|
||||
int FindIndex(
|
||||
XOHCL &source,
|
||||
XOHCL &dest[] //
|
||||
)
|
||||
{
|
||||
//
|
||||
int result = -1;
|
||||
|
||||
//
|
||||
if (!source.IsValid())
|
||||
{
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
int count = ArraySize(dest);
|
||||
if (!IsValidSize(count))
|
||||
{
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
for (int i = 0; i < count; i++)
|
||||
{
|
||||
//
|
||||
XOHCL iBar = dest[i];
|
||||
|
||||
//
|
||||
bool isSame = IsSame(
|
||||
source,
|
||||
iBar //
|
||||
);
|
||||
if (isSame)
|
||||
{
|
||||
//
|
||||
result = i;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Add Specific Bar to List only if Not Exists ...
|
||||
*
|
||||
* @param source: XOHCL instance ...
|
||||
* @param dest: XOHCL instance Collection ...
|
||||
*
|
||||
* @return ( bool )
|
||||
*/
|
||||
bool AddIfNotExists(
|
||||
XOHCL &source,
|
||||
XOHCL &dest[] //
|
||||
)
|
||||
{
|
||||
//
|
||||
bool result = false;
|
||||
|
||||
//
|
||||
int count = ArraySize(dest);
|
||||
result = source.IsValid();
|
||||
if (!result)
|
||||
{
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
int idx = FindIndex(source, dest);
|
||||
bool isExists = IsValidIndex(idx);
|
||||
if (isExists)
|
||||
{
|
||||
//
|
||||
AddRef(
|
||||
source,
|
||||
dest //
|
||||
);
|
||||
|
||||
//
|
||||
result = isExists;
|
||||
}
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// XZone Extensions ...
|
||||
|
||||
/**
|
||||
* Check two Zone is Same or not ...
|
||||
*
|
||||
* @param source: XZone instance ...
|
||||
* @param dest: XZone instance ...
|
||||
* @param force: Check also it's Dates ...
|
||||
*
|
||||
* @return ( bool )
|
||||
*/
|
||||
bool IsSame(
|
||||
XZone &source,
|
||||
XZone &dest,
|
||||
bool force = false //
|
||||
)
|
||||
{
|
||||
//
|
||||
bool result = false;
|
||||
|
||||
//
|
||||
result = source.IsValid() &&
|
||||
dest.IsValid();
|
||||
if (!result)
|
||||
{
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
result =
|
||||
source.upper == dest.upper &&
|
||||
source.lower == dest.lower;
|
||||
if (!result)
|
||||
{
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
if (force)
|
||||
{
|
||||
//
|
||||
result =
|
||||
source.from == dest.from &&
|
||||
source.to == dest.to;
|
||||
}
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Find Specific Items Index inside a Collection ...
|
||||
*
|
||||
* @param source: XZone instance ...
|
||||
* @param dest: XZone instance Collection ...
|
||||
*
|
||||
* @return ( int )
|
||||
*/
|
||||
int FindIndex(
|
||||
XZone &source,
|
||||
XZone &dest[] //
|
||||
)
|
||||
{
|
||||
//
|
||||
int result = -1;
|
||||
|
||||
//
|
||||
if (!source.IsValid())
|
||||
{
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
int count = ArraySize(dest);
|
||||
if (!IsValidSize(count))
|
||||
{
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
for (int i = 0; i < count; i++)
|
||||
{
|
||||
//
|
||||
XZone iZone = dest[i];
|
||||
|
||||
//
|
||||
bool isSame = IsSame(
|
||||
source,
|
||||
iZone //
|
||||
);
|
||||
if (isSame)
|
||||
{
|
||||
//
|
||||
result = i;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Add Specific Zone to List only if Not Exists ...
|
||||
*
|
||||
* @param source: XZone instance ...
|
||||
* @param dest: XZone instance Collection ...
|
||||
*
|
||||
* @return ( bool )
|
||||
*/
|
||||
bool AddIfNotExists(
|
||||
XZone &source,
|
||||
XZone &dest[] //
|
||||
)
|
||||
{
|
||||
//
|
||||
bool result = false;
|
||||
|
||||
//
|
||||
int count = ArraySize(dest);
|
||||
result = source.IsValid();
|
||||
if (!result)
|
||||
{
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
int idx = FindIndex(source, dest);
|
||||
bool isExists = IsValidIndex(idx);
|
||||
if (isExists)
|
||||
{
|
||||
//
|
||||
AddRef(
|
||||
source,
|
||||
dest //
|
||||
);
|
||||
|
||||
//
|
||||
result = isExists;
|
||||
}
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
Reference in New Issue
Block a user