update workspace ...
This commit is contained in:
File diff suppressed because it is too large
Load Diff
+603
@@ -0,0 +1,603 @@
|
||||
///////////////////////////////////////////////////////
|
||||
//
|
||||
// SaherElm IT Center MQL5 Seriallize Library
|
||||
// ---------------------------------------
|
||||
// Name: XSeriallizer
|
||||
// Description: provides Seriallizing EA abilities ...
|
||||
//
|
||||
//
|
||||
// Maintainer:
|
||||
// ------------
|
||||
// Hadi Khazaee Asl (hadi_khazaee_asl@yahoo.com)
|
||||
//
|
||||
//////////////////////////////////////////////////////
|
||||
//
|
||||
// Global Properties ...
|
||||
#property library
|
||||
#property copyright "Copyright 2023, SaherElm IT Center"
|
||||
#property link "https://www.saherelm.ir"
|
||||
#property version "1.00"
|
||||
#property strict
|
||||
|
||||
//
|
||||
#include "../Libraries/x-saherelm.models.lib.mq5"
|
||||
#include "../Libraries/x-saherelm.common.lib.mq5"
|
||||
#include "../Classes/x-saherelm.xtrade.class.mq5"
|
||||
|
||||
//
|
||||
string XProviderToken = "PRV";
|
||||
string XSupportToken = "SP";
|
||||
string XSLTrailToken = "SLT";
|
||||
string XPeriodToken = "PR";
|
||||
|
||||
//
|
||||
string XConfigToken = "XPV";
|
||||
string XItemSeparator = "|";
|
||||
string XItemContentSeparator = ",";
|
||||
|
||||
//
|
||||
string XFirstGenToken = "0";
|
||||
|
||||
//
|
||||
// PERIOD ...
|
||||
|
||||
//
|
||||
// Detect a Comment has period or not ...
|
||||
bool HasPeriod(string comment)
|
||||
{
|
||||
//
|
||||
bool result = false;
|
||||
|
||||
//
|
||||
if (StringLen(comment) == 0)
|
||||
{
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
int tokenPos = StringFind(
|
||||
comment,
|
||||
XPeriodToken);
|
||||
result = tokenPos >= 0;
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Extract Period String ...
|
||||
string ExtractPeriodString(string comment)
|
||||
{
|
||||
//
|
||||
string result = "";
|
||||
|
||||
//
|
||||
bool hasPeriod = HasPeriod(comment);
|
||||
if (!hasPeriod)
|
||||
{
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
result = ExtractString(
|
||||
comment,
|
||||
XPeriodToken + "(",
|
||||
")");
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Extract Time Frame From Comment ...
|
||||
ENUM_TIMEFRAMES ExtractPeriod(string comment)
|
||||
{
|
||||
//
|
||||
ENUM_TIMEFRAMES result = NULL;
|
||||
|
||||
//
|
||||
if (StringLen(comment) <= 0)
|
||||
{
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
string periodStr = ExtractPeriodString(comment);
|
||||
if (StringLen(periodStr) <= 0)
|
||||
{
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
result = ToPeriod(periodStr);
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// PROVIDER ...
|
||||
|
||||
//
|
||||
// Extract a Provider name if exists from a Comment ...
|
||||
string ExtractProvider(string comment)
|
||||
{
|
||||
//
|
||||
string result = "";
|
||||
if (StringLen(comment) <= 0)
|
||||
{
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
result = ExtractString(
|
||||
comment,
|
||||
XProviderToken + "(",
|
||||
")");
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Generate Provider String for Using in Positions Comment ...
|
||||
// NOTE: if there is more than One Provider, it takes first
|
||||
// provider as main and the others used to increase volume ...
|
||||
string GenerateProvidersString(XSignal &signal)
|
||||
{
|
||||
//
|
||||
string result = "";
|
||||
|
||||
//
|
||||
int providersCount = ArraySize(signal.providers);
|
||||
if (providersCount <= 0)
|
||||
{
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
result = XProviderToken + "(" + signal.providers[0] + ")";
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// SLTRAIL ...
|
||||
|
||||
//
|
||||
string GenerateSLTrailComment(int level)
|
||||
{
|
||||
//
|
||||
string result = "";
|
||||
|
||||
//
|
||||
if (level <= 0)
|
||||
{
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
result = XSLTrailToken + "(" + ToString(level) + ")";
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
int ExtractSLTrailLevel(string comment)
|
||||
{
|
||||
//
|
||||
int result = 0;
|
||||
|
||||
//
|
||||
if (StringLen(comment) == 0)
|
||||
{
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
string levelStr = ExtractString(
|
||||
comment,
|
||||
XSLTrailToken + "(",
|
||||
")");
|
||||
if (StringLen(levelStr) == 0)
|
||||
{
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
result = (int)levelStr;
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
string PrepareSLTrailComment(
|
||||
const string comment // Original Position Comment ...
|
||||
)
|
||||
{
|
||||
//
|
||||
string result = "";
|
||||
|
||||
//
|
||||
if (StringLen(comment) == 0)
|
||||
{
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
int level = 0;
|
||||
result = comment;
|
||||
|
||||
//
|
||||
// Check Comment Contains SL Trailing or not ...
|
||||
int lastTrailLevel = ExtractSLTrailLevel(comment);
|
||||
if (lastTrailLevel <= 0)
|
||||
{
|
||||
level++;
|
||||
}
|
||||
else
|
||||
{
|
||||
//
|
||||
level = lastTrailLevel + 1;
|
||||
string lastLevelStr = GenerateSLTrailComment(lastTrailLevel);
|
||||
StringReplace(
|
||||
result,
|
||||
lastLevelStr,
|
||||
"");
|
||||
}
|
||||
|
||||
//
|
||||
// Generate level Comment ...
|
||||
string levelStr = GenerateSLTrailComment(level);
|
||||
result += levelStr;
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// SUPPORT ...
|
||||
|
||||
//
|
||||
// Generate Specific Position's Support Comment
|
||||
// index is number of Supports ...
|
||||
string GenerateSupportSignalComment(
|
||||
ulong ticket, // Position/Order Ticket
|
||||
int index // Support Index ...
|
||||
)
|
||||
{
|
||||
//
|
||||
string result = "";
|
||||
|
||||
//
|
||||
result = XSupportToken + "(" + (string)ticket + "," + ToString(index) + ")";
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Extract Support Parameters String from specified Comment ...
|
||||
string ExtractSupportParam(string comment)
|
||||
{
|
||||
//
|
||||
string result = "";
|
||||
if (StringLen(comment) <= 0)
|
||||
{
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
result = ExtractString(
|
||||
comment,
|
||||
XSupportToken + "(",
|
||||
")");
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Extract Support Info as String array for Specific Comment ...
|
||||
bool ExtractSupportParams(
|
||||
string comment, // Specified Comment ...
|
||||
string ¶ms[] // Hold Result ...
|
||||
)
|
||||
{
|
||||
//
|
||||
bool result = false;
|
||||
|
||||
//
|
||||
string supParam = ExtractSupportParam(comment);
|
||||
if (StringLen(supParam) == 0)
|
||||
{
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
SplitContent(
|
||||
params,
|
||||
supParam);
|
||||
int paramsCount = ArraySize(params);
|
||||
|
||||
//
|
||||
result = paramsCount == 2;
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Extract Support Parent Ticket ...
|
||||
ulong ExtractParentTicket(string comment)
|
||||
{
|
||||
//
|
||||
ulong result = 0;
|
||||
|
||||
//
|
||||
string params[];
|
||||
bool isSupport = ExtractSupportParams(
|
||||
comment,
|
||||
params);
|
||||
if (!isSupport)
|
||||
{
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
result = (ulong)params[0];
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Extract Support Index ...
|
||||
int ExtractSupportIndex(string comment)
|
||||
{
|
||||
//
|
||||
int result = -1;
|
||||
|
||||
//
|
||||
string params[];
|
||||
bool isSupport = ExtractSupportParams(
|
||||
comment,
|
||||
params);
|
||||
if (!isSupport)
|
||||
{
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
result = (int)params[1];
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// START XEQM Support ...
|
||||
//
|
||||
|
||||
//
|
||||
string XEQMSupportToken = "XEQM";
|
||||
|
||||
//
|
||||
// Generate String Tag for EQM Support Signals ...
|
||||
string GenerateXEQMSupportComment()
|
||||
{
|
||||
//
|
||||
string result = XEQMSupportToken;
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Check a Comment belongs to a EQM Support or not ...
|
||||
bool IsEQMSupport(string comment)
|
||||
{
|
||||
//
|
||||
bool result = false;
|
||||
|
||||
//
|
||||
if (StringLen(comment) <= 0)
|
||||
{
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
int tokenPosition = StringFind(
|
||||
comment,
|
||||
XEQMSupportToken);
|
||||
result = tokenPosition >= 0;
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Select EQM Support Orders ...
|
||||
int GetEQMSupportOrders(
|
||||
XOrder &supports[], // Hold Result ...
|
||||
XOrder &orders[], // List of All Orders ...
|
||||
ENUM_TIMEFRAMES period = NULL // Specified Period ...
|
||||
)
|
||||
{
|
||||
//
|
||||
int result = 0;
|
||||
|
||||
//
|
||||
// Cleanup Array ...
|
||||
Clean(supports);
|
||||
|
||||
//
|
||||
// Count Orders ...
|
||||
int ordersCount = ArraySize(orders);
|
||||
if (ordersCount <= 0)
|
||||
{
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Loop through Orders ...
|
||||
for (int i = 0; i < ordersCount; i++)
|
||||
{
|
||||
//
|
||||
// Select Indexed Order ...
|
||||
XOrder iOrder = orders[i];
|
||||
|
||||
//
|
||||
// Check Order is Support or not ...
|
||||
bool isSupport = IsEQMSupport(iOrder.comment);
|
||||
if (!isSupport)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
//
|
||||
// Check Order is not Triggered ...
|
||||
if (iOrder.state != ORDER_STATE_PLACED)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
//
|
||||
// Check Period ...
|
||||
if (period != NULL && iOrder.period != period)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
//
|
||||
// we now sure this order is EQM Support ...
|
||||
Add(
|
||||
iOrder,
|
||||
supports);
|
||||
}
|
||||
|
||||
//
|
||||
// Count Result ...
|
||||
result = ArraySize(supports);
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Select EQM Support Positions ...
|
||||
int GetEQMSupportPositions(
|
||||
XPosition &supports[], // Hold Result ...
|
||||
XPosition &positions[], // List of All Positions ...
|
||||
ENUM_TIMEFRAMES period = NULL // Specified Period ...
|
||||
)
|
||||
{
|
||||
//
|
||||
int result = 0;
|
||||
|
||||
//
|
||||
// Cleanup Array ...
|
||||
Clean(supports);
|
||||
|
||||
//
|
||||
// Count Positions ...
|
||||
int positionsCount = ArraySize(positions);
|
||||
if (positionsCount <= 0)
|
||||
{
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Loop through Positions ...
|
||||
for (int i = 0; i < positionsCount; i++)
|
||||
{
|
||||
//
|
||||
// Select Indexed Position ...
|
||||
XPosition iPosition = positions[i];
|
||||
|
||||
//
|
||||
// Check Position is Support or not ...
|
||||
bool isSupport = IsEQMSupport(iPosition.comment);
|
||||
if (!isSupport)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
//
|
||||
// Check Period ...
|
||||
if (period != NULL && iPosition.period != period)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
//
|
||||
// we now sure this order is EQM Support ...
|
||||
Add(
|
||||
iPosition,
|
||||
supports);
|
||||
}
|
||||
|
||||
//
|
||||
// Count Result ...
|
||||
result = ArraySize(supports);
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// END XEQM Support ...
|
||||
//
|
||||
|
||||
//
|
||||
// START FirstGen ...
|
||||
//
|
||||
|
||||
//
|
||||
string GenerateFirstGenIdentifier(const string signaller)
|
||||
{
|
||||
//
|
||||
string result = "";
|
||||
|
||||
//
|
||||
if (StringLen(signaller) <= 0)
|
||||
{
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
return signaller + XFirstGenToken;
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
bool IsFirstGenOf(
|
||||
const string signaller, // Specified Signaller
|
||||
const string comment // Comment
|
||||
)
|
||||
{
|
||||
//
|
||||
bool result = false;
|
||||
|
||||
//
|
||||
string id = GenerateFirstGenIdentifier(signaller);
|
||||
|
||||
//
|
||||
int idPos = StringFind(
|
||||
comment,
|
||||
id
|
||||
);
|
||||
result = idPos >= 0;
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// END FirstGen ...
|
||||
//
|
||||
Reference in New Issue
Block a user