backup x121 setup ...

This commit is contained in:
2024-05-01 14:46:50 +03:30
parent 038dbc8fa8
commit 2804652f20
112 changed files with 50446 additions and 0 deletions
@@ -0,0 +1,187 @@
///////////////////////////////////////////////////////
//
// 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 ...
//
File diff suppressed because it is too large Load Diff
File diff suppressed because it is too large Load Diff
@@ -0,0 +1,177 @@
///////////////////////////////////////////////////////
//
// 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
@@ -0,0 +1,292 @@
///////////////////////////////////////////////////////
//
// SaherElm IT Center MQL5 Models Library
// ---------------------------------------
// Name: XModels
// Description: provides all required models ...
//
//
// 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 ...
//
//
// END Inputs ...
//
//
// START Global Definitions: Variables, Properties and etc ...
//
//
// END Global Definitions: Variables, Properties and etc ...
//
//
// START Provided Functions ...
//
//
// How To Calculate Static Volume ...
enum ENUM_STATIC_VOLUME_METHODS
{
//
// Based On Deposit ...
X_STATIC_VOLUME_BASED_ON_DEPOSIT,
//
// Based On Balance ...
X_STATIC_VOLUME_BASED_ON_BALANCE,
};
//
// START Model Definitions ...
//
//
// OHCL Candel Model ...
enum ENUM_X_PRICE
{
X_PRICE_HIGH,
X_PRICE_OPEN,
X_PRICE_CLOSE,
X_PRICE_LOW
};
//
// Swing Types Enum ...
enum ENUM_X_SWING_TYPE
{
X_NO_SWING = 0,
X_SWING_HIGH = 1,
X_SWING_LOW = -1,
};
//
// Select Positions Type ...
enum ENUM_X_POSITION_SELECT_METHODS
{
X_POSITION_SELECT_NONE, // None
X_POSITION_SELECT_MAX, // Max
X_POSITION_SELECT_MIN, // Min
X_POSITION_SELECT_ALL, // Min
};
//
// 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
};
//
// Model Guard Info ...
struct XGuard
{
string symbol;
string provider;
ENUM_TIMEFRAMES period;
ENUM_POSITION_TYPE type;
ENUM_X_GUARD_ACTIONS action;
//
double dblPayLoad;
string strPayload;
};
//
// Describe an Specific Candle ...
struct XOHCL
{
double high;
double open;
double close;
double low;
};
//
// Model Support and Resistance
// for Specific Bar ...
struct XOHCLSupRes
{
//
double res[];
//
double sup[];
};
//
// Available Order Modes ...
enum ENUM_X_ORDER_MODES
{
X_ORDER_MODE_MARKET = 0, // Market Order
X_ORDER_MODE_STOP = 1, // Pending Stop Order
X_ORDER_MODE_LIMIT = 2, // Pending Limit Order
X_ORDER_MODE_STOP_LIMIT = 3, // Pending Stop Limit Order
};
//
// Model a Signal ...
struct XSignal
{
//
string providers[];
//
string symbol;
//
ENUM_TIMEFRAMES period;
//
ENUM_POSITION_TYPE type;
//
ENUM_X_ORDER_MODES mode;
//
double entry;
//
double riskAmount;
//
double tp;
//
double sl;
//
double r2r;
//
double volume;
//
bool calculateTP;
//
bool ignoreSL;
bool ignoreTP;
//
bool useSupportAndResistance;
//
bool useRiskAmountAsVolume;
//
// Support Signals ...
XSignal supports[];
};
//
// EXTENSION Methods ...
//
// Clear an Specific Signal Item ...
void Clean(XSignal &item)
{
//
ArrayFree(item.providers);
ArrayResize(item.providers, 0);
//
ArrayFree(item.supports);
ArrayResize(item.supports, 0);
//
item.symbol = "";
item.type = NULL;
item.mode = NULL;
item.period = NULL;
//
item.tp = 0;
item.sl = 0;
item.r2r = 0;
item.entry = 0;
item.volume = 0;
item.riskAmount = 0;
//
item.ignoreSL = false;
item.ignoreTP = false;
item.calculateTP = false;
item.useRiskAmountAsVolume = false;
item.useSupportAndResistance = false;
}
template <typename T>
void Add(
T &item,
T &buffer[])
{
//
ArrayResize(
buffer,
ArraySize(buffer) + 1);
//
buffer[ArraySize(buffer) - 1] = item;
}
template <typename T>
void Clean(T &buffer[])
{
//
ArrayFree(buffer);
ArrayResize(buffer, 0);
}
template <typename T>
void Copy(
T &source[], // Source Buffer ...
T &dest[], // Dest Buffer ...
bool cleanDest = true // Force Clen Dest Buffer ...
)
{
//
if (cleanDest)
{
Clean(dest);
}
//
int sourceCount = ArraySize(source);
if (sourceCount <= 0)
{
return;
}
//
for (int i = 0; i < sourceCount; i++)
{
//
T iSource = source[i];
//
Add(
iSource,
dest);
}
}
//
// END Provided Functions ...
//
@@ -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 &params[] // 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;
}
@@ -0,0 +1,241 @@
///////////////////////////////////////////////////////
//
// SaherElm IT Center MQL5 X12 Draw Library
// ------------------------------------------
// Name: X121Draw
// Description: provides Draw Requirements ...
//
//
// 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.draw.lib.mq5"
#include "../Libraries/x-saherelm.common.lib.mq5"
#include "../Libraries/x-saherelm.models.lib.mq5"
//
// START Draw Functions ...
//
//
// Draw Signal ...
void DrawSignal(const ulong ticket, XSignal &signal)
{
//
bool isLong = IsLong(signal.type);
//
string prefix = (string)ticket + "_" + ToString(signal.period);
//
// Retrieve Time ...
datetime time = iTime(
signal.symbol,
signal.period,
0);
//
// Retrieve 3 Time ...
datetime time3 = iTime(
signal.symbol,
signal.period,
3);
//
color posColor = isLong
? clrSpringGreen
: clrTomato;
color tpColor = clrSpringGreen;
color slColor = clrTomato;
color entryColor = clrGold;
//
ENUM_LINE_STYLE vLineStyle = STYLE_DOT;
ENUM_LINE_STYLE tpLineStyle = STYLE_SOLID;
ENUM_LINE_STYLE slLineStyle = STYLE_SOLID;
ENUM_LINE_STYLE entryLineStyle = STYLE_SOLID;
//
int lineWidth = 2;
//
long chartID = ChartID();
//
// Vertical Line ...
string vlName = prefix + "_" + (string)time;
//
DrawVerticalLine(
chartID,
vlName,
0,
time,
posColor,
vLineStyle,
lineWidth);
//
// TP ...
double profit = (MathAbs(signal.tp - signal.entry)) * signal.volume;
string tpName = prefix + "_TP_" + (string)profit;
//
DrawTrendLine(
chartID,
tpName,
0,
time3,
signal.tp,
time,
signal.tp,
tpColor,
tpLineStyle,
lineWidth);
//
// SL ...
double lost = (MathAbs(signal.sl - signal.entry)) * signal.volume;
string slName = prefix + "_SL_" + (string)lost;
//
DrawTrendLine(
chartID,
slName,
0,
time3,
signal.sl,
time,
signal.sl,
slColor,
slLineStyle,
lineWidth);
//
// ENTRY ...
string entryName = prefix + "_ENTRY_" + (string)lost;
//
DrawTrendLine(
chartID,
entryName,
0,
time3,
signal.entry,
time,
signal.entry,
entryColor,
entryLineStyle,
lineWidth);
}
//
// Draw Support and Resistance ...
void DrawSupportResistance(
int bar_index,
XOHCLSupRes &data,
string prefix = "",
color supportColor = clrOrange,
color resistanceColor = clrOrange)
{
//
datetime barTime = GetCandleTime(
_Symbol,
_Period,
bar_index);
//
datetime prevBarTime = GetCandleTime(
_Symbol,
_Period,
bar_index + 5);
//
long chID = ChartID();
int subWindiw = 0;
int lineWidth = 1;
//
string mPrefix = prefix + "_" + (string)barTime + "_";
//
// SUPPORTS ...
//
int supCount = ArraySize(data.sup);
if (supCount > 0)
{
//
for (int i = 0; i < supCount; i++)
{
//
double iSup = data.sup[i];
//
string supTlName = mPrefix + "SUP[" + (string)(i + 1) + "]_(" + (string)iSup + ")";
//
// Draw Support ...
DrawTrendLine(
chID,
supTlName,
subWindiw,
prevBarTime,
iSup,
barTime,
iSup,
supportColor,
STYLE_DOT,
lineWidth,
true);
}
}
//
// RESISTANCES ...
//
int resCount = ArraySize(data.res);
if (resCount > 0)
{
//
for (int i = 0; i < resCount; i++)
{
//
double iRes = data.res[i];
//
string resTlName = mPrefix + "RES[" + (string)(i + 1) + "]_(" + (string)iRes + ")";
//
// Draw Support ...
DrawTrendLine(
chID,
resTlName,
subWindiw,
prevBarTime,
iRes,
barTime,
iRes,
resistanceColor,
STYLE_DOT,
lineWidth,
true);
}
}
}
//
// END Draw Functions ...
//
@@ -0,0 +1,245 @@
///////////////////////////////////////////////////////
//
// SaherElm IT Center MQL5 Seriallize Library
// ---------------------------------------
// Name: XSignal
// Description: provides Template Signalling ...
//
//
// 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.x121.support.lib.mq5"
#include "../Libraries/x-saherelm.draw.lib.mq5"
//
bool XTMPGetLongSignal(
X121MarketConditions &conditions, // Market Conditions, Result
XSCX121Provider *analyzer // Market Analyzer
)
{
//
bool result = false;
//
double entry = GetEntry(
conditions.symbol,
POSITION_TYPE_BUY);
//
// XCHE Breakout ...
//
double ll5 = GetLowestLow(
conditions.symbol,
conditions.period,
5,
0);
//
bool isXCHELongExitsExists =
//
conditions.xcheInfo.le1[1] != EMPTY_VALUE &&
conditions.xcheInfo.le2[1] != EMPTY_VALUE
//
;
//
bool isXCHELongSign =
//
conditions.xcheInfo.le1[2] != EMPTY_VALUE &&
conditions.xcheInfo.le2[2] == EMPTY_VALUE &&
//
isXCHELongExitsExists &&
//
!(ll5 > conditions.xcheInfo.le1[1] ||
ll5 > conditions.xcheInfo.le1[2])
//
;
//
bool isCandleBullish =
//
IsBullishCandle(conditions.candles[1])
//
;
//
result =
//
isXCHELongSign &&
isCandleBullish
//
;
//
if (result)
{
//
conditions.hasSignal = true;
//
Add(
"XTMP",
conditions.signal.providers);
//
conditions.signal.type = POSITION_TYPE_BUY;
conditions.signal.mode = X_ORDER_MODE_MARKET;
//
conditions.signal.symbol = conditions.symbol;
conditions.signal.period = conditions.period;
//
conditions.signal.r2r = 1;
conditions.signal.volume = 0.01;
conditions.signal.ignoreTP = false;
conditions.signal.ignoreSL = false;
conditions.signal.riskAmount = 0.01;
conditions.signal.calculateTP = false;
conditions.signal.useRiskAmountAsVolume = false;
conditions.signal.useSupportAndResistance = false;
//
Clean(
conditions.signal.supports);
//
double tp = 0;
double sl = 0;
//
// TODO:
// Calculate TP and SL ...
//
conditions.signal.tp = tp;
conditions.signal.sl = sl;
conditions.signal.entry = entry;
}
//
return result;
}
//
bool XTMPGetShortSignal(
X121MarketConditions &conditions, // Market Conditions, Result
XSCX121Provider *analyzer // Market Analyzer
)
{
//
bool result = false;
//
double entry = GetEntry(
conditions.symbol,
POSITION_TYPE_SELL);
//
result =
//
false
//
;
//
if (result)
{
//
conditions.hasSignal = true;
//
Add(
"XTMP",
conditions.signal.providers);
//
conditions.signal.type = POSITION_TYPE_BUY;
conditions.signal.mode = X_ORDER_MODE_MARKET;
//
conditions.signal.symbol = conditions.symbol;
conditions.signal.period = conditions.period;
//
conditions.signal.r2r = 1;
conditions.signal.volume = 0.01;
conditions.signal.ignoreTP = false;
conditions.signal.ignoreSL = false;
conditions.signal.riskAmount = 0.01;
conditions.signal.calculateTP = false;
conditions.signal.useRiskAmountAsVolume = false;
conditions.signal.useSupportAndResistance = false;
//
Clean(
conditions.signal.supports);
//
double tp = 0;
double sl = 0;
//
// TODO:
// Calculate TP and SL ...
//
conditions.signal.tp = tp;
conditions.signal.sl = sl;
conditions.signal.entry = entry;
}
//
return result;
}
//
bool XTMPProcessSignal(
X121MarketConditions &conditions, // Market Conditions, Result
XSCX121Provider *analyzer // Market Analyzer
)
{
//
bool result = false;
//
X121MarketConditions mConditions = analyzer.GetMarketConditions(0);
//
bool hasLong = XTMPGetLongSignal(
mConditions,
analyzer);
if (hasLong)
{
//
conditions = mConditions;
return true;
}
//
bool hasShort = XTMPGetShortSignal(
mConditions,
analyzer);
if (hasShort)
{
//
conditions = mConditions;
return true;
}
//
return result;
}
@@ -0,0 +1,584 @@
///////////////////////////////////////////////////////
//
// SaherElm IT Center MQL5 Seriallize Library
// ---------------------------------------
// Name: XSupportSignal
// 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"
#include "../Libraries/x-saherelm.seriallizer.lib.mq5"
#include "../Classes/x-saherelm.x121.provider.class.mq5"
//
// TODO: add this to Configurations ...
double supportVolumeMultiplier = 2;
int oldAgeSupportForReNewFactor = 35;
int oldAgePositionForSupportFactor = 17;
//
// Required Variables ...
double minProfitPerTrade = 0.15;
double minProfitPerVolumeFactor = 0.01;
//
double supportsSginalTpPoint = 30;
//
// NOTE:
// Define some tokens to Specify types of Supports ...
string XEQMSupportToken = "XEQM";
//
// Define Two Main Support Types of EQM ...
enum ENUM_X121EQM_SUPPORT_TYPES
{
//
XEQM_UNBOUND = 0, // Without TP ...
XEQM_INBOUND = 1, // With TP ...
};
//
// Generate Signal Period Comment Part ...
string GeneratePeriodComment(
ENUM_TIMEFRAMES period = NULL // Time Frame ...
)
{
//
string result = "";
//
if (period == NULL)
{
return result;
}
//
result = XPeriodToken + "(" + ToString(period) + ")";
//
return result;
}
//
// Generate String Tag for EQM Support Signals ...
string GenerateXEQMSupportComment(
ENUM_TIMEFRAMES period = NULL // Time Frame ...
)
{
//
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;
//
Clean(supports);
//
int ordersCount = ArraySize(orders);
if (ordersCount <= 0)
{
return result;
}
//
// Loop through Orders ...
for (int i = 0; i < ordersCount; i++)
{
//
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 Orders by Type ...
int GetEQMSupportsByType(
XOrder &supports[], // Hold Result ...
XOrder &orders[], // List of All Orders ...
ENUM_TIMEFRAMES period = NULL, // Specified Period ...
ENUM_X121EQM_SUPPORT_TYPES type = NULL // EQM Support Type ...
)
{
//
int result = 0;
//
XOrder mOrders[];
result = GetEQMSupportOrders(mOrders, orders, period);
if (result <= 0)
{
return result;
}
//
if (type == NULL)
{
//
Copy(
mOrders,
supports);
}
else
{
//
for (int i = 0; i < result; i++)
{
//
XOrder iOrder = mOrders[i];
//
if (iOrder.tp > 0 && type == XEQM_INBOUND)
{
//
Add(
iOrder,
supports);
}
else if (iOrder.tp == 0 && type == XEQM_UNBOUND)
{
//
Add(
iOrder,
supports);
}
}
}
//
result = ArraySize(supports);
//
return result;
}
//
// NOTE:
// here we add all Supporting Signals preparations ...
// 1- must have at least TWO Support Signal without tp ...
// 2- there are some signals by providing tp ...
// 3- Trend base and Conditional Supports by tp ...
//
// UNBOUND Support => Support Signals with TP ...
// INBOUND Support => Support Signals without TP ...
//
// in each time when there are an open positions in DrawDown and it's passed
// a certain candles ...
// we Have to Placed atleast 2 UNBOUND Support Signals ...
//
// LIFETIME of Supports ...
// Each Support Signal must be Cancel if their doesn't triggered
// for an specific Number of Candels ...
//
// SUPPORT GENERATORs ...
//
// Generate Supports Signal For Market ...
int GenerateMarketSupports(
XSignal &supports[], // Hold Result
string symbol, // Trading Symbol
ENUM_TIMEFRAMES period, // Trading Timeframe
XSCX121Provider *analyzer, // Market Analizer
double volume = 0.01 // Provided Volume
)
{
//
int result = 0;
//
// TODO: Variable ...
int numberOfItems = 10;
//
Clean(supports);
//
// Calculate Lng Exit Price ...
double longExit = GetExit(symbol, POSITION_TYPE_BUY);
//
// Generate Support and Resistances ...
XOHCLSupRes longSupRes = analyzer.GenerateSupportAndResistance(
longExit,
numberOfItems);
//
// Calculate Short Exit Price ...
double shortExit = GetExit(symbol, POSITION_TYPE_SELL);
//
// Generate Support and Resistances ...
XOHCLSupRes shortSupRes = analyzer.GenerateSupportAndResistance(
shortExit,
numberOfItems);
//
X121MarketConditions mConditions = analyzer.GetMarketConditions(1);
//
double tp = 0;
double sl = 0;
double max = 0;
double med = 0;
double min = 0;
double entry = 0;
double tpPointPrice = PointToPrice(
symbol,
supportsSginalTpPoint);
//
XSignal mSignal;
Clean(mSignal);
//
// 1- Breakout PEAK to UP ...
// 2- Breakout PEAK to Down ...
// 3- Breakeout VALE Down ...
//
mSignal.ignoreTP = false;
mSignal.ignoreSL = false;
mSignal.calculateTP = false;
mSignal.useRiskAmountAsVolume = true;
//
mSignal.symbol = symbol;
mSignal.period = period;
mSignal.riskAmount = volume;
//
// 1
//
mSignal.mode = X_ORDER_MODE_LIMIT;
mSignal.type = POSITION_TYPE_SELL;
//
entry = mConditions.xpvInfo.peak;
tp = entry - tpPointPrice;
//
mSignal.tp = tp;
mSignal.entry = entry;
//
Add(
mSignal,
supports);
//
Clean(mSignal);
//
mSignal.ignoreTP = false;
mSignal.ignoreSL = false;
mSignal.calculateTP = false;
mSignal.useRiskAmountAsVolume = true;
//
mSignal.symbol = symbol;
mSignal.period = period;
mSignal.riskAmount = volume;
//
// 2
//
mSignal.mode = X_ORDER_MODE_STOP;
mSignal.type = POSITION_TYPE_BUY;
//
entry = mConditions.xpvInfo.peak;
tp = entry + tpPointPrice;
//
mSignal.tp = tp;
mSignal.entry = entry;
//
Add(
mSignal,
supports);
//
Clean(mSignal);
//
mSignal.ignoreTP = false;
mSignal.ignoreSL = false;
mSignal.calculateTP = false;
mSignal.useRiskAmountAsVolume = true;
//
mSignal.symbol = symbol;
mSignal.period = period;
mSignal.riskAmount = volume;
//
// 3
//
mSignal.mode = X_ORDER_MODE_STOP;
mSignal.type = POSITION_TYPE_SELL;
//
entry = mConditions.xpvInfo.vale;
tp = entry + tpPointPrice;
//
mSignal.tp = tp;
mSignal.entry = entry;
//
Add(
mSignal,
supports);
//
Clean(mSignal);
//
result = ArraySize(supports);
//
return result;
}
//
// Generate Support Signal for Specific Signal ...
bool GenerateSignalSupports(
XSignal &signal, // Source Signal
XSCX121Provider *analyzer // Market Analizer
)
{
//
bool result = false;
//
Clean(signal.supports);
//
string providerStr = signal.providers[0];
if (StringLen(providerStr) == 0)
{
return result;
}
//
ENUM_X121_SIGNAL_PROVIDERS provider = ToProvider(providerStr);
bool isAllowed = analyzer.IsAllowdSignaller(provider);
if (!isAllowed)
{
return result;
}
//
bool isLong = IsLong(
signal.type);
bool isLongSupport = !isLong;
//
ENUM_POSITION_TYPE type =
isLong
? POSITION_TYPE_SELL
: POSITION_TYPE_BUY;
//
double tp = 0;
double sl = 0;
double volume = signal.volume * 2;
double entry = GetEntry(
type);
//
double tpPriceDistance = MathAbs(signal.entry - signal.tp);
double tpPoint = PriceToPoint(
signal.symbol,
tpPriceDistance);
//
double ll3 = GetLowestLow(
signal.symbol,
signal.period,
3,
0);
//
double hh3 = GetHighestHigh(
signal.symbol,
signal.period,
3,
0);
//
// XPV ...
double fl1 = analyzer.mXPVHelper.fl1Buffer[0];
double fl2 = analyzer.mXPVHelper.fl2Buffer[0];
double fl3 = analyzer.mXPVHelper.fl3Buffer[0];
double peak = analyzer.mXPVHelper.peaksBuffer[0];
double vales = analyzer.mXPVHelper.valesBuffer[0];
//
double distancePrice =
isLong
? MathAbs(signal.entry - ll3)
: MathAbs(signal.entry - hh3);
double distancePoint =
PriceToPoint(
signal.symbol,
distancePrice);
double supportTpPrice =
PointToPrice(
signal.symbol,
distancePoint + tpPoint);
entry =
isLongSupport
? hh3
: ll3;
tp =
isLongSupport
? entry + supportTpPrice
: entry - supportTpPrice;
//
XSignal tmpSignal;
Clean(tmpSignal);
//
tmpSignal.r2r = 0;
tmpSignal.volume = volume;
tmpSignal.ignoreTP = false;
tmpSignal.ignoreSL = false;
tmpSignal.riskAmount = volume;
tmpSignal.calculateTP = false;
tmpSignal.symbol = signal.symbol;
tmpSignal.period = signal.period;
tmpSignal.useRiskAmountAsVolume = true;
tmpSignal.useSupportAndResistance = false;
//
tmpSignal.type = type;
//
Add(
providerStr,
tmpSignal.providers);
//
switch (provider)
{
//
// X92 ...
case X92:
//
tmpSignal.tp = tp;
tmpSignal.sl = sl;
tmpSignal.entry = entry;
tmpSignal.mode = X_ORDER_MODE_STOP;
//
Add(
tmpSignal,
signal.supports);
//
break;
}
//
result = ArraySize(signal.supports) > 0;
//
return result;
}