complete xea class ...

This commit is contained in:
2024-05-21 04:36:05 +03:30
parent 74ffc15d04
commit 57371b9343
15 changed files with 3227 additions and 1505 deletions
-187
View File
@@ -1,187 +0,0 @@
///////////////////////////////////////////////////////
//
// SaherElm IT Center MQL5 Alert Library
// --------------------------------------
// Name: XAlert
// Description: provides Alerts 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
//
// START Inputs ...
//
input group "Alerts";
input bool enableAlerts = true; // Enable Alerts
input bool logAlerts = true; // Log Alerts
input bool terminalAlerts = false; // Terminal Alerts
input bool mailAlerts = false; // Mail Alerts
input bool pushAlerts = false; // Push Alerts
//
// END Inputs ...
//
//
#include "x-saherelm.log.lib.mq5"
//
// START Global Definitions: Variables, Properties and etc ...
//
string alertPrefix = "X-Alert";
//
// END Global Definitions: Variables, Properties and etc ...
//
//
// START Provided Functions ...
//
//
// Initial Library if required ...
bool OnInInitAlertLibrary()
{
return false;
}
//
// DeInitial Library if required ...
void OnDeinitAlertLibrary()
{
}
//
// Attach Alert Prefix to Message ...
string PrepareAlertMessage(string message)
{
//
StringReplace(message, "\n", " | ");
//
StringConcatenate(message, alertPrefix, " > ", message);
//
return message;
}
//
// Logging an Alert ...
void LogAlert(string message)
{
//
// Validate Args ...
if (!enableAlerts || !logAlerts)
{
return;
}
//
LogMessage(alertPrefix, message);
}
//
// Terminal Alert ...
void TerminalAlert(string message)
{
//
// Validate Args ...
if (!enableAlerts || !terminalAlerts)
{
return;
}
//
// Prepare Message ...
message = PrepareAlertMessage(message);
// Send Terminal Alert ...
Alert(message);
}
//
// Mail Alert ...
void MailAlert(string message)
{
//
// Validate Args ...
if (!enableAlerts || !mailAlerts)
{
return;
}
//
// Send Mail Alert ...
SendMail(alertPrefix, message);
}
//
// Send Push Notification ...
void PushAlert(string message)
{
//
// Validate Args ...
if (!enableAlerts || !pushAlerts)
{
return;
}
//
// Prepare Message ...
message = PrepareAlertMessage(message);
//
// Send Push Notification Alert ...
SendNotification(message);
}
//
// Alert Sending ...
void SendAlert(string message)
{
//
// Validate Args ...
if (!enableAlerts)
{
return;
}
//
// Log ...
if (logAlerts)
{
LogAlert(message);
}
//
// Terminal ...
if (terminalAlerts)
{
TerminalAlert(message);
}
//
// Mail ...
if (mailAlerts)
{
MailAlert(message);
}
//
// Push ...
if (pushAlerts)
{
PushAlert(message);
}
}
//
// END Provided Functions ...
//
+61 -15
View File
@@ -1023,8 +1023,8 @@ struct XOHCL
//
ENUM_SERIESMODE mMode = swing == X_SWING_HIGH
? MODE_HIGH
: MODE_LOW;
? MODE_HIGH
: MODE_LOW;
//
result = swing == X_SWING_HIGH
@@ -1048,7 +1048,7 @@ struct XOHCL
//
// Find Lowest Bar Index ...
int FindHighestIndex(
int mLength, // Loopback ...
int mLength, // Loopback ...
ENUM_SERIESMODE mMode // Calculation mode
)
{
@@ -1082,7 +1082,7 @@ struct XOHCL
//
// Find Lowest ...
double FindHighest(
int mLength, // Loopback ...
int mLength, // Loopback ...
ENUM_SERIESMODE mMode // Calculation mode
)
{
@@ -1127,7 +1127,7 @@ struct XOHCL
//
// Find Lowest Bar Index ...
int FindLowestIndex(
int mLength, // Loopback ...
int mLength, // Loopback ...
ENUM_SERIESMODE mMode // Calculation mode
)
{
@@ -1161,7 +1161,7 @@ struct XOHCL
//
// Find Lowest ...
double FindLowest(
int mLength, // Loopback ...
int mLength, // Loopback ...
ENUM_SERIESMODE mMode // Calculation mode
)
{
@@ -3877,6 +3877,49 @@ string GetToken(T &item)
return result;
}
//
// Same as Get Token for Use in Classes ...
template <typename T>
string GetSpecificToken(T &item)
{
//
string mType = GetTypeName(item);
//
string result = mType;
//
string parts[];
int partsCount = SplitContent(
parts,
result,
" "
//
);
if (partsCount <= 0)
{
//
result = mType;
return result;
}
//
bool hasLastPart = GetLastItem(
result,
parts
//
);
if (!hasLastPart)
{
//
result = mType;
return result;
}
//
return result;
}
//
// Generate Unique Tags ...
template <typename T>
@@ -4855,14 +4898,14 @@ bool Contains(
//
result = queryIdx >= 0;
//
return result;
}
//
bool Contains(
string &mQueries[], // Search Strings
string &mQueries[], // Search Strings
string mContent, // Search Content
bool ignoreCase = true // Ignore Case
)
@@ -4874,29 +4917,32 @@ bool Contains(
// Validate Queries ...
int queriesCount = ArraySize(mQueries);
result = queriesCount > 0;
if (!result) {
if (!result)
{
return result;
}
//
// Validate Content ...
result = IsValid(mContent);
if (!result) {
if (!result)
{
return result;
}
//
int containsCount = 0;
for (int i = 0; i < queriesCount; i++) {
for (int i = 0; i < queriesCount; i++)
{
//
bool isContains = Contains(
mQueries[i],
mContent,
ignoreCase
);
ignoreCase);
//
if (!isContains) {
if (!isContains)
{
//
result = false;
break;
@@ -4908,7 +4954,7 @@ bool Contains(
//
result = containsCount == queriesCount;
//
return result;
}
-177
View File
@@ -1,177 +0,0 @@
///////////////////////////////////////////////////////
//
// SaherElm IT Center MQL5 Http Library
// ------------------------------------------
// Name: XHttp
// Description: provide http communication
// 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
//
// START Model Definition ...
//
enum X_HTTP_METHOD
{
X_HTTP_GET,
X_HTTP_POST
};
//
// END Model Definition ...
//
//
// START Inputs ...
//
//
// END Inputs ...
//
//
// START Global Definitions: Variables, Properties and etc ...
//
//
// END Global Definitions: Variables, Properties and etc ...
//
//
// START Provided Functions ...
//
//
// Initial Library if required ...
bool OnInInitHttpLibrary()
{
return false;
}
//
// DeInitial Library if required ...
void OnDeinitHttpLibrary()
{
}
//
// Convert enum to String ...
string ToString(X_HTTP_METHOD method)
{
//
string result = "";
//
switch (method)
{
//
case X_HTTP_GET:
result = "GET";
break;
//
case X_HTTP_POST:
result = "POST";
break;
}
//
return result;
}
//
// Send Global Request ...
int SendRequest(
X_HTTP_METHOD method, // Httm Request Method
const string url, // Server Address
const string headers, // Headers providing
const char &payload[], // the Data which needs to Send
char &response[], // Response of request
string responseHeaders, // Response Headers
int timeout = 500 // Timeout for response default is 500
)
{
//
int result = -1;
//
string strMethod = ToString(method);
if (StringLen(strMethod) == 0) {
return result;
}
//
result = WebRequest(
strMethod,
url,
headers,
timeout,
payload,
response,
responseHeaders
);
//
return result;
}
//
// Get Request ...
int GetRequest(
const string url, // Server Address
const string headers, // Headers providing
const char &payload[], // the Data which needs to Send
char &response[], // Response of request
string responseHeaders, // Response Headers
int timeout = 500 // Timeout for response default is 500
) {
//
int result = SendRequest(
X_HTTP_GET,
url,
headers,
payload,
response,
responseHeaders,
timeout
);
//
return result;
}
//
// Post Request ...
int PostRequest(
const string url, // Server Address
const string headers, // Headers providing
const char &payload[], // the Data which needs to Send
char &response[], // Response of request
string responseHeaders, // Response Headers
int timeout = 500 // Timeout for response default is 500
) {
//
int result = SendRequest(
X_HTTP_POST,
url,
headers,
payload,
response,
responseHeaders,
timeout
);
//
return result;
}
//
// END Provided Functions ...
//
File diff suppressed because it is too large Load Diff
+266
View File
@@ -53,6 +53,9 @@ string XSymbolToken = "SMBL";
string XSupportToken = "SP";
string XEQMSupportToken = "EQM";
//
string XSLTrailToken = "SLT";
//
string XActionToken = "A";
@@ -107,6 +110,19 @@ enum ENUM_X_SIGNAL_MANAGING_ACTIONS
X_SIGNAL_PARTIAL_TRAIL, // Use 0 index as SL and Trail Stop on TP Levels and also Partial Close on TP Levels
};
//
// Available Guard Action ...
enum ENUM_X_GUARD_ACTIONS
{
X_GUARD_ACTION_NOTHING, // Nothing
X_GUARD_ACTION_HEDGE, // Hedge
X_GUARD_PARTIAL_CLOSE, // Partial Close
X_GUARD_ACTION_TRAIL_STOP, // Trail StopLoss
X_GUARD_ACTION_FORCE_CLOSE, // Force Close
X_GUARD_ACTION_ADD_SUPPORT_SIGNAL, // Add Support Signal
X_GUARD_ACTION_CANCEL_PENDING_ORDERS, // Cancel Pending Orders
};
//
// Structs ...
@@ -2427,6 +2443,96 @@ struct XOnTradeHandlerState
}
};
//
// Model Guard Info ...
struct XGuard
{
//
string symbol; // Trading Symbol ...
string provider; // Signal Provider ...
ENUM_TIMEFRAMES period; // Trading Timeframe ...
ENUM_POSITION_TYPE type; // Position Type ...
ENUM_X_GUARD_ACTIONS action; // Which Action to Do ...
//
double dblPayLoad;
string strPayload;
//
// Constructor ...
XGuard()
{
Clean();
}
//
// Initialize ...
//
// Global Initializer ...
bool Init(
string mSymbol, // Trading Symbol ...
ENUM_TIMEFRAMES mPeriod, // Trading Timeframe ...
ENUM_X_GUARD_ACTIONS mAction, // Which Action to Do ...
ENUM_POSITION_TYPE mType = NULL, // Position Type ...
string mProvider = NULL, // Signal Provider ...
double mDblPayLoad = NULL,
string mStrPayload = NULL //
)
{
//
type = mType;
symbol = mSymbol;
period = mPeriod;
action = mAction;
provider = mProvider;
dblPayLoad = mDblPayLoad;
strPayload = mStrPayload;
//
bool result = IsValid();
//
return result;
}
//
// Tools ...
//
// Cleanup ...
void Clean()
{
//
symbol = NULL;
provider = NULL;
period = NULL;
action = X_GUARD_ACTION_NOTHING;
//
strPayload = NULL;
dblPayLoad = EMPTY_VALUE;
}
//
// Validate ...
bool IsValid()
{
//
bool result = false;
//
result =
//
action != X_GUARD_ACTION_NOTHING
//
;
//
return result;
}
};
//
// Model a Position with all of it's Supports ...
struct XPositionPack
@@ -3717,6 +3823,73 @@ int FindIndex(
return result;
}
//
// Retrieve String Representation ...
string ToString(ENUM_X_SIGNAL_EXECUTION_RESULT value)
{
//
string result = NULL;
//
switch (value)
{
//
case X_SIGNAL_EXECUTION_UNKNOWN:
result = "Unknown";
break;
//
case X_SIGNAL_EXECUTION_SUCCEED:
result = "Succed";
break;
//
case X_SIGNAL_EXECUTION_FAILED_SPREAD:
result = "Spread more than Max Allowed";
break;
//
case X_SIGNAL_EXECUTION_FAILED_NO_EQUITY:
result = "No Equity for Trade";
break;
//
case X_SIGNAL_EXECUTION_FAILED_PRICE_ERROR:
result = "Price Error";
break;
//
case X_SIGNAL_EXECUTION_FAILED_MAX_REACHED:
result = "Max Allowed Positions Reached";
break;
//
case X_SIGNAL_EXECUTION_FAILED_INVALID_PARAMS:
result = "Invalid Params";
break;
}
//
return result;
}
//
// Converts Position Type to Order Type ...
ENUM_ORDER_TYPE ToOrderType(ENUM_POSITION_TYPE value)
{
//
bool isLong = IsLong(value);
//
ENUM_ORDER_TYPE result =
isLong
? ORDER_TYPE_BUY
: ORDER_TYPE_SELL;
//
return result;
}
//
// Tagging ...
@@ -3830,3 +4003,96 @@ ulong ExtractEQMSupportedTicket(string value)
}
//
// SL Trails ...
//
// Extract SL Trail Level ...
int ExtractSLTrailLevel(string comment)
{
//
int result = 0;
//
if (!IsValid(comment))
{
return result;
}
//
result = ParseIntSurrounded(
comment,
XSLTrailToken
//
);
//
return result;
}
//
// Generate SL Trail Comment Tag ...
string GenerateSLTrailTag(int level)
{
//
string result = NULL;
//
if (level <= 0)
{
return result;
}
//
result = Surround(
XSLTrailToken,
level
//
);
//
return result;
}
//
// Prepare SL Trail Comment ...
string PrepareSLTrailTag(
const string comment // Original Position Comment ...
)
{
//
string result = NULL;
//
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 = GenerateSLTrailTag(lastTrailLevel);
StringReplace(
result,
lastLevelStr,
""
//
);
}
//
// Generate level Comment ...
string levelStr = GenerateSLTrailTag(level);
result += levelStr;
//
return result;
}
//