backup x121 setup ...
This commit is contained in:
@@ -0,0 +1,371 @@
|
||||
///////////////////////////////////////////////////////
|
||||
//
|
||||
// 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";
|
||||
|
||||
//
|
||||
// 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;
|
||||
}
|
||||
Reference in New Issue
Block a user